package com.huaheng.mobile.invenory; import com.alibaba.fastjson.JSONException; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.core.toolkit.Wrappers; import com.huaheng.api.wcs.domain.WcsTask; import com.huaheng.common.support.Convert; import com.huaheng.common.utils.DataUtils; import com.huaheng.common.utils.StringUtils; import com.huaheng.common.utils.security.ShiroUtils; import com.huaheng.framework.aspectj.lang.annotation.Log; import com.huaheng.framework.aspectj.lang.constant.BusinessType; import com.huaheng.framework.web.domain.AjaxResult; import com.huaheng.mobile.task.TaskDomain; import com.huaheng.pc.config.container.domain.Container; import com.huaheng.pc.config.container.service.ContainerService; import com.huaheng.pc.config.location.domain.Location; import com.huaheng.pc.config.location.service.LocationService; import com.huaheng.pc.inventory.cycleCountDetail.service.CycleCountDetailService; import com.huaheng.pc.inventory.inventoryDetail.domain.InventoryDetail; import com.huaheng.pc.inventory.inventoryDetail.service.InventoryDetailService; import com.huaheng.pc.inventory.inventoryHeader.service.InventoryHeaderService; import com.huaheng.pc.inventory.inventoryTransaction.domain.InventoryTransaction; import com.huaheng.pc.inventory.inventoryTransaction.service.InventoryTransactionService; import com.huaheng.pc.receipt.receiptHeader.domain.ReceiptHeader; import com.huaheng.pc.report.excelReport.mapper.ExcelReportMapper; import com.huaheng.pc.task.taskHeader.service.TaskHeaderService; import com.huaheng.pc.task.taskHeader.service.TransferTaskService; import com.huaheng.pc.task.taskHeader.service.WorkTaskService; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; import io.swagger.annotations.ApiParam; import org.springframework.web.bind.annotation.*; import javax.annotation.Resource; import java.math.BigDecimal; import java.text.SimpleDateFormat; import java.util.*; /** * * @author Enzo Cotter * @date 2019/12/15 */ @CrossOrigin @RestController @RequestMapping("/mobile/inventory") @Api(tags = {"手机立体库库存相关"}, value = "手机立体库库存相关MobileInventoryController") public class MobileInventoryController { @Resource private InventoryHeaderService inventoryService; @Resource private InventoryDetailService inventoryDetailService; @Resource private InventoryTransactionService inventoryTransactionService; @Resource private TaskHeaderService taskService; @Resource private TransferTaskService transferTaskService; @Resource private WorkTaskService workTaskService; @Resource private LocationService locationService; @Resource ExcelReportMapper mapper; @Resource private CycleCountDetailService cycleCountDetailService; @Resource private ContainerService containerService; @PostMapping("/getInventoryInfo") @ApiOperation("移动端获得库存详情") @Log(title = "移动端获得库存详情", action = BusinessType.OTHER) public AjaxResult getInventoryInfo(@RequestBody @ApiParam(value="物料编码或者库位号") Map<String, String> param) { if (param.get("code") == null || param.get("code").trim().length() < 1) { throw new JSONException("查询码(code)不能为空"); } if (param.get("companyCode") == null || param.get("companyCode").trim().length() < 1) { throw new JSONException("(companyCode)不能为空"); } return inventoryService.getInventory(param.get("code"), param.get("companyCode")); } @PostMapping("/createCheckOutTask") @ApiOperation("移动端创建出库查看任务") @ResponseBody public AjaxResult createCheckOutTask(@RequestBody @ApiParam(value="库存ids") Map<String, String> param){ String ids = param.get("ids"); Integer companyId = DataUtils.getInteger(param.get("companyId")) ; String companyCode = param.get("companyCode"); if(StringUtils.isEmpty(ids)){ return AjaxResult.error("ids不能为空"); } return workTaskService.createCheckOutTaskByIds(Arrays.asList(Convert.toIntArray(ids))); } @PostMapping("/transfer") @ApiOperation("移动端创建移库任务") @ResponseBody public AjaxResult transfer(@RequestBody @ApiParam(value="库位情况") Map<String, String> param){ String sourceLocation = param.get("sourceLocation"); String destinationLocation = param.get("destinationLocation"); return transferTaskService.createTransferTask(sourceLocation, destinationLocation); } @PostMapping( "/execute") @ApiOperation("执行立库任务") @ResponseBody public AjaxResult execute(@RequestBody @ApiParam(value="任务id") Map<String, String> param) { String taskId = param.get("taskId"); if (StringUtils.isEmpty(taskId)) { return AjaxResult.error("taskId不能为空"); } AjaxResult ajaxResult = taskService.sendTaskToWcs(Convert.toIntArray(taskId)); if(ajaxResult.hasErr()) { AjaxResult.success("执行失败"); } return AjaxResult.success("下发执行成功"); } @PostMapping( "/executeList") @ApiOperation("执行立库任务") @Log(title = "执行立库任务", action = BusinessType.OTHER) public AjaxResult executeList(@RequestBody List<TaskIds> taskDetails) { Integer[] taskIds = new Integer[taskDetails.size()]; for(int i=0; i<taskDetails.size() ; i++) { TaskIds taskDetail = taskDetails.get(i); taskIds[i] = taskDetail.getTaskId(); } AjaxResult ajaxResult = taskService.sendTaskToWcs(taskIds); return ajaxResult; } @PostMapping( "/completeTaskByWMS") @ApiOperation("完成立库任务") @ResponseBody public AjaxResult completeTaskByWMS(@RequestBody @ApiParam(value="任务id") Map<String, String> param) throws Exception { String taskId = param.get("taskId"); if (StringUtils.isEmpty(taskId)) { return AjaxResult.error("taskId不能为空"); } AjaxResult ajaxResult = taskService.completeTaskByWMS(Convert.toIntArray(taskId), null); return ajaxResult; } @PostMapping( "/completeTaskListByWMS") @ApiOperation("完成立库任务") @ResponseBody public AjaxResult completeTaskListByWMS(@RequestBody List<TaskIds> taskDetails) throws Exception { Integer[] taskIds = new Integer[taskDetails.size()]; for(int i=0; i<taskDetails.size() ; i++) { TaskIds taskDetail = taskDetails.get(i); taskIds[i] = taskDetail.getTaskId(); } AjaxResult ajaxResult = taskService.completeTaskByWMS(taskIds, null); return ajaxResult; } @PostMapping( "/isLocation") @ApiOperation("判断是不是库位") @ResponseBody public AjaxResult isLocation(@RequestBody @ApiParam(value="任务id") Map<String, String> param) { String code = param.get("code"); if (StringUtils.isEmpty(code)) { return AjaxResult.error("location不能为空"); } LambdaQueryWrapper<Location> queryWrapper = Wrappers.lambdaQuery(); queryWrapper.eq(Location::getCode, code); Location location = locationService.getOne(queryWrapper); if(location == null) { return AjaxResult.error("没有这个库位"); } return AjaxResult.success("库位存在").setData(code); } @PostMapping( "/isContainer") @ApiOperation("判断是不是库位") @ResponseBody public AjaxResult isContainer(@RequestBody @ApiParam(value="任务id") Map<String, String> param) { String code = param.get("code"); if (StringUtils.isEmpty(code)) { return AjaxResult.error("location不能为空"); } LambdaQueryWrapper<Container> queryWrapper = Wrappers.lambdaQuery(); queryWrapper.eq(Container::getCode, code); Container container = containerService.getOne(queryWrapper); if(container == null) { return AjaxResult.error("没有这个容器"); } return AjaxResult.success("容器存在").setData(code); } @PostMapping("/getLocationCode") @ApiOperation("移动端获得库位联想词") @Log(title = "移动端获得库位联想词", action = BusinessType.OTHER) public AjaxResult getLocationCode(@RequestBody @ApiParam(value="库位号") Map<String, String> param) { if (param.get("code") == null || param.get("code").trim().length() < 1) { throw new JSONException("查询码(code)不能为空"); } String type = param.get("type"); if (type == null || type.trim().length() < 1) { throw new JSONException("type不能为空"); } return inventoryService.getLocationForecast(param.get("code"), Integer.parseInt(type)); } @PostMapping("/createEmptyIn") @ApiOperation("移动端空托入库") @Log(title = "移动端空托入库", action = BusinessType.OTHER) public AjaxResult createEmptyIn(@RequestBody Map<String, String> param) { if (param.get("containerCode") == null || param.get("containerCode").trim().length() < 1) { throw new JSONException("容器号不能为空"); } // if (param.get("destinationLocation") == null || param.get("destinationLocation").trim().length() < 1) { // throw new JSONException("目的库位不能为空"); // } String containerCode = param.get("containerCode"); String destinationLocation = param.get("destinationLocation"); String companyCode = param.get("companyCode"); return inventoryService.createEmptyIn(containerCode, destinationLocation); } @PostMapping("/createEmptyOut") @ApiOperation("移动端空托出库") @Log(title = "移动端空托出库", action = BusinessType.OTHER) public AjaxResult createEmptyOut(@RequestBody Map<String, String> param) { if (param.get("containerCode") == null || param.get("containerCode").trim().length() < 1){ throw new JSONException("容器号不能为空"); } if (param.get("sourceLocation") == null || param.get("sourceLocation").trim().length() < 1) { throw new JSONException("源库位不能为空"); } String containerCode = param.get("containerCode"); String sourceLocation = param.get("sourceLocation"); return inventoryService.createEmptyOut(containerCode, sourceLocation); } @PostMapping("/get7daysShipment") @ApiOperation("移动端获取7天收货和出货量") @Log(title = "移动端获取7天收货和出货量", action = BusinessType.OTHER) public AjaxResult get7daysShipment(@RequestBody Map<String, String> param) { String sql = "select a.click_date as date,ifnull(b.taskQty,0) as qty\n" + "from (\n" + " SELECT curdate() as click_date\n" + " union all\n" + " SELECT date_sub(curdate(), interval 1 day) as click_date\n" + " union all\n" + " SELECT date_sub(curdate(), interval 2 day) as click_date\n" + " union all\n" + " SELECT date_sub(curdate(), interval 3 day) as click_date\n" + " union all\n" + " SELECT date_sub(curdate(), interval 4 day) as click_date\n" + " union all\n" + " SELECT date_sub(curdate(), interval 5 day) as click_date\n" + " union all\n" + " SELECT date_sub(curdate(), interval 6 day) as click_date\n" + ") a left join (\n" + "SELECT DATE(h.created) AS created , SUM(d.qty) AS taskQty from shipment_container_detail d join shipment_container_header h on d.shippingContainerId = h.id and h.warehouseCode='"+ShiroUtils.getWarehouseCode()+"' WHERE h.created >= DATE_SUB(CURDATE(), INTERVAL 7 DAY) AND h.status=30 GROUP BY DATE(h.created)\n" + ") b on a.click_date = b.created ORDER BY a.click_date;"; List<LinkedHashMap<String, Object>> list = mapper.selectCommon(sql); sql = "select a.click_date as date,ifnull(b.taskQty,0) as qty\n" + "from (\n" + " SELECT curdate() as click_date\n" + " union all\n" + " SELECT date_sub(curdate(), interval 1 day) as click_date\n" + " union all\n" + " SELECT date_sub(curdate(), interval 2 day) as click_date\n" + " union all\n" + " SELECT date_sub(curdate(), interval 3 day) as click_date\n" + " union all\n" + " SELECT date_sub(curdate(), interval 4 day) as click_date\n" + " union all\n" + " SELECT date_sub(curdate(), interval 5 day) as click_date\n" + " union all\n" + " SELECT date_sub(curdate(), interval 6 day) as click_date\n" + ") a left join (\n" + "SELECT DATE(h.created) AS created , SUM(d.qty) AS taskQty from receipt_container_detail d join receipt_container_header h on d.receiptContainerId = h.id and h.warehouseCode='"+ShiroUtils.getWarehouseCode()+"' WHERE h.created >= DATE_SUB(CURDATE(), INTERVAL 7 DAY) AND d.status=30 GROUP BY DATE(h.created)\n" + ") b on a.click_date = b.created ORDER BY a.click_date;"; List<LinkedHashMap<String, Object>> list2 = mapper.selectCommon(sql); List<LinkedHashMap<String, Object>> result = new ArrayList<>(); result.addAll(list); result.addAll(list2); List<InventoryDetails> inventoryDetailList = new ArrayList<>(); for(LinkedHashMap<String, Object> map : result) { Iterator iter = map.entrySet().iterator(); String date = null; BigDecimal qty = new BigDecimal(0); while (iter.hasNext()) { Map.Entry entry = (Map.Entry) iter.next(); Object key = entry.getKey(); Object val = entry.getValue(); if(date == null) { date = val.toString(); } else { qty = (BigDecimal) val; } } inventoryDetailList.add(newInventoryDetail(date, qty)); } return AjaxResult.success(inventoryDetailList); } private InventoryDetails newInventoryDetail(String date, BigDecimal qty) { InventoryDetails inventoryDetail = new InventoryDetails(); inventoryDetail.setDate(date); inventoryDetail.setQty(qty); return inventoryDetail; } @PostMapping("/getTodayShipmentDetail") @ApiOperation("移动端获得今天发货详情") @Log(title = "移动端获得今天发货详情", action = BusinessType.OTHER) public AjaxResult getTodayShipmentDetail(@RequestBody Map<String, String> param) { String sql = "select d.materialName, SUM(d.qty) as qty " + "from shipment_container_header h join shipment_container_detail d " + "on d.shippingContainerId = h.id WHERE h.created >= CURDATE() AND h.`status`>19 GROUP BY d.materialName"; List<LinkedHashMap<String, Object>> list = mapper.selectCommon(sql); sql = "select m.name, b.taskQty as qty \n" + "from material m \n" + "join (\n" + "select d.materialCode as material, SUM(d.qty) " + "as taskQty from receipt_container_header h join receipt_container_detail d " + "on d.receiptContainerId = h.id WHERE h.created >= CURDATE() AND h.`status`>19 GROUP BY d.materialCode\n" + ") b on m.`code` = b.material ORDER BY m.name"; List<LinkedHashMap<String, Object>> list2 = mapper.selectCommon(sql); List<com.huaheng.mobile.invenory.ShipmentDetail> shipmentDetails = getShipmentDetails(list); shipmentDetails.add(newShipmentDetail("delete", new BigDecimal(0))); shipmentDetails.addAll(getShipmentDetails(list2)); return AjaxResult.success(shipmentDetails); } private List<com.huaheng.mobile.invenory.ShipmentDetail> getShipmentDetails(List<LinkedHashMap<String, Object>> list) { List<com.huaheng.mobile.invenory.ShipmentDetail> shipmentDetails = new ArrayList<>(); for (LinkedHashMap<String, Object> map : list) { Iterator iter = map.entrySet().iterator(); String materialName = null; BigDecimal qty = new BigDecimal(0); while (iter.hasNext()) { Map.Entry entry = (Map.Entry) iter.next(); Object key = entry.getKey(); Object val = entry.getValue(); if (materialName == null) { materialName = val.toString(); } else { qty = (BigDecimal) val; } } shipmentDetails.add(newShipmentDetail(materialName, qty)); } return shipmentDetails; } private com.huaheng.mobile.invenory.ShipmentDetail newShipmentDetail(String materialName, BigDecimal qty){ com.huaheng.mobile.invenory.ShipmentDetail shipmentDetail = new com.huaheng.mobile.invenory.ShipmentDetail(); shipmentDetail.setMaterialName(materialName); shipmentDetail.setQty(qty); return shipmentDetail; } /** * 移动端根据容器编码获取盘点任务 * @param param * @return */ @ResponseBody @PostMapping("/findTransferByContainerCode") public AjaxResult findTransferByContainerCode(@RequestBody Map<String, String> param) { String containCode = param.get("containCode"); if (StringUtils.isEmpty(containCode)){ return AjaxResult.error("容器编码为空"); } else { return AjaxResult.success(taskService.mobileFindTransferTask(containCode)); } } /** * 移动端实盘登记 * @param param * @return */ @ResponseBody @PostMapping("/confirmGapQty") public AjaxResult confirmGapQty(@RequestBody Map<String, String> param) { int detailId = Integer.parseInt(param.get("detailId")); BigDecimal qty = new BigDecimal(param.get("qty")); return cycleCountDetailService.confirmGapQty(detailId, qty); } @PostMapping("/getEmptyContainerInLocation") @ApiOperation("选取空托出库的库位") @Log(title = "选取空托出库的库位", action = BusinessType.OTHER) public AjaxResult getEmptyContainerInLocation(@RequestBody Map<String, String> param) { String warehouCOde = ShiroUtils.getWarehouseCode(); List<Location> list = containerService.getEmptyContainerInLocation(null,null,ShiroUtils.getWarehouseCode()); return AjaxResult.success(list); } @PostMapping("/pickLocation") @ApiOperation("选取补充入库的库位") @Log(title = "选取补充入库的库位", action = BusinessType.OTHER) public AjaxResult pickLocation(@RequestBody Map<String, String> param) { List<Location> locations = locationService.pickLocation(); Container condition = new Container(); condition.setWarehouseCode(ShiroUtils.getWarehouseCode()); LambdaQueryWrapper lambda3 = Wrappers.lambdaQuery(condition); List<Container> containers = containerService.list(lambda3); for(Location location : locations) { for(Container container : containers) { if(container.getCode().equals(location.getContainerCode())) { if("some".equals(container.getStatus())) { location.setStatus("some"); } } } } return AjaxResult.success(locations); } @PostMapping("/searchInventory") @ApiOperation("移动端查询库存") @Log(title = "移动端查询库存", action = BusinessType.OTHER) public AjaxResult searchInventory(@RequestBody @ApiParam(value = "物料号") Map<String, String> param){ String companyCode = param.get("companyCode"); SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); String now = df.format(new Date()); Calendar c = Calendar.getInstance(); c.setTime(new Date()); c.add(Calendar.DATE, -7); Date first = c.getTime(); String start = df.format(first);//前一天 LambdaQueryWrapper<InventoryDetail> inventoryQueryWrapper = Wrappers.lambdaQuery(); inventoryQueryWrapper.eq(InventoryDetail::getCompanyCode, companyCode) .eq(InventoryDetail::getWarehouseCode, ShiroUtils.getWarehouseCode()) .orderByDesc(InventoryDetail::getCreated); List<InventoryDetail> inventoryDetailList = inventoryDetailService.list(inventoryQueryWrapper); return AjaxResult.success(inventoryDetailList); } @PostMapping("/searchInventoryInCondition") @ApiOperation("移动端查询库存") @Log(title = "移动端查询库存", action = BusinessType.OTHER) public AjaxResult searchInventoryInCondition(@RequestBody @ApiParam(value = "物料号") Map<String, String> param){ String companyCode = param.get("companyCode"); String containerCode = param.get("containerCode"); String materialCode = param.get("materialCode"); String materialName = param.get("materialName"); String materialSpec = param.get("materialSpec"); String startTime = param.get("startTime"); String endTime = param.get("endTime"); LambdaQueryWrapper<InventoryDetail> inventoryQueryWrapper = Wrappers.lambdaQuery(); inventoryQueryWrapper.eq(InventoryDetail::getCompanyCode, companyCode) .eq(InventoryDetail::getWarehouseCode, ShiroUtils.getWarehouseCode()) .eq(StringUtils.isNotEmpty(containerCode), InventoryDetail::getContainerCode, containerCode) .like(StringUtils.isNotEmpty(materialCode), InventoryDetail::getMaterialCode, materialCode) .like(StringUtils.isNotEmpty(materialName), InventoryDetail::getMaterialName, materialName) .like(StringUtils.isNotEmpty(materialSpec), InventoryDetail::getMaterialSpec, materialSpec) .gt(StringUtils.isNotEmpty(startTime), InventoryDetail::getCreated, startTime) .le(StringUtils.isNotEmpty(endTime), InventoryDetail::getCreated, endTime) .orderByDesc(InventoryDetail::getCreated); List<InventoryDetail> inventoryDetailList = inventoryDetailService.list(inventoryQueryWrapper); return AjaxResult.success(inventoryDetailList); } @PostMapping("/findInventory") @ApiOperation("移动端查询库存详情") @Log(title = "移动端查询库存详情", action = BusinessType.OTHER) public AjaxResult findInventory(@RequestBody @ApiParam(value = "物料号") Map<String, String> param){ String inventoryDetailId = param.get("inventoryDetailId"); String companyCode = param.get("companyCode"); if (StringUtils.isNull(inventoryDetailId)){ return AjaxResult.error("任务id为空"); } else if (StringUtils.isNull(companyCode)){ return AjaxResult.error("公司编码为空"); } /* 查询入库单,如果数据库中不存在,则调用ERP接口拉取单据,成功后再次查询返回结果*/ LambdaQueryWrapper<InventoryDetail> inventoryQueryWrapper = Wrappers.lambdaQuery(); inventoryQueryWrapper.eq(InventoryDetail::getId, inventoryDetailId) .eq(InventoryDetail::getCompanyCode, companyCode); InventoryDetail inventoryDetail = inventoryDetailService.getOne(inventoryQueryWrapper); if(inventoryDetail == null) { return AjaxResult.error("没有找到库存详情"); } return AjaxResult.success(inventoryDetail); } @PostMapping("/searchInventoryTransactionInCondition") @ApiOperation("移动端查询库存交易记录") @Log(title = "移动端查询库存交易记录", action = BusinessType.OTHER) public AjaxResult searchInventoryTransactionInCondition(@RequestBody @ApiParam(value = "物料号") Map<String, String> param){ String companyCode = param.get("companyCode"); String transactionType = param.get("transactionType"); String containerCode = param.get("containerCode"); String materialCode = param.get("materialCode"); String materialName = param.get("materialName"); String materialSpec = param.get("materialSpec"); String startTime = param.get("startTime"); String endTime = param.get("endTime"); LambdaQueryWrapper<InventoryTransaction> inventoryTransactionLambdaQueryWrapper = Wrappers.lambdaQuery(); inventoryTransactionLambdaQueryWrapper.eq(InventoryTransaction::getCompanyCode, companyCode) .eq(InventoryTransaction::getWarehouseCode, ShiroUtils.getWarehouseCode()) .eq(StringUtils.isNotEmpty(transactionType), InventoryTransaction::getTransactionType, transactionType) .eq(StringUtils.isNotEmpty(containerCode), InventoryTransaction::getContainerCode, containerCode) .like(StringUtils.isNotEmpty(materialCode), InventoryTransaction::getMaterialCode, materialCode) .like(StringUtils.isNotEmpty(materialName), InventoryTransaction::getMaterialName, materialName) .like(StringUtils.isNotEmpty(materialSpec), InventoryTransaction::getMaterialSpec, materialSpec) .gt(StringUtils.isNotEmpty(startTime), InventoryTransaction::getCreated, startTime) .le(StringUtils.isNotEmpty(endTime), InventoryTransaction::getCreated, endTime) .orderByDesc(InventoryTransaction::getCreated); List<InventoryTransaction> inventoryDetailList = inventoryTransactionService.list(inventoryTransactionLambdaQueryWrapper); return AjaxResult.success(inventoryDetailList); } }