package com.tld.service.impl; import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSONObject; import com.github.pagehelper.PageHelper; import com.github.pagehelper.PageInfo; import com.mysql.cj.xdevapi.JsonString; import com.tld.excel.ExcelUtils; import com.tld.mapper.*; import com.tld.model.*; import com.tld.model.Dictionary; import com.tld.model.Error; import com.tld.service.WarehousingService; import com.tld.util.DateUtil; import com.tld.util.HttpClientUtil; import org.apache.http.ParseException; import org.redisson.api.RLock; import org.redisson.api.RedissonClient; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; import javax.annotation.Resource; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import java.text.SimpleDateFormat; import java.util.*; @Service public class WarehousingServiceImpl implements WarehousingService { //入库 @Autowired private WarehousingMapper warehousingMapper; //用户` @Autowired private UserMapper userMapper; //错误日志表 @Autowired private ErrorMapper errorMapper; //redis锁 @Autowired private RedissonClient redissonClient; //出库 @Autowired private AskGoodsMapper askGoodsMapper; //库存 @Autowired private StorageLocationMapper storageLocationMapper; //库存 @Autowired private DictionaryMapper dictionaryMapper; //质检单 @Autowired private ReceiveGoodsMapper receiveGoodsMapper; @Override public Map getRecommend(String wllbCode, String suppId, String num, String unique, String producDate, String warehouseWhere) { Map map = new HashMap<>(); try { //判断物料是否录入 MaterialClass materialClass = warehousingMapper.getMateriaIsExist(wllbCode); if (materialClass == null) { map.put("msg", "500"); map.put("errMsg", "物料信息未录入,请联系管理员"); return map; } if (materialClass.getPartType().equals("半成品") || materialClass.getPartType().equals("产成品")) { map.put("msg", "500"); map.put("errMsg", "此物料是" + materialClass.getPartType()); return map; } Map mapVal = warehousingMapper.getScanIsNot(wllbCode, suppId, unique, producDate, warehouseWhere); if (Integer.parseInt(mapVal.get("inventoryCount").toString()) != 0 || Integer.parseInt(mapVal.get("virtualCount").toString()) != 0) { map.put("msg", "500"); map.put("errMsg", "已被扫描"); return map; } //判断如果是混合则走单独逻辑 String isNotSisable = warehousingMapper.getIsNotSisable(wllbCode); if (isNotSisable.equals("1")) { List list1 = warehousingMapper.getIsNotSisableLocation("1"); map.put("data", list1); map.put("msg", "200"); return map; } List listMaterialClass = warehousingMapper.getMaterialClass(wllbCode); if (listMaterialClass.size() == 0) { listMaterialClass = warehousingMapper.getMaterialClassType(wllbCode); } if (listMaterialClass.size() == 0) { map.put("msg", "500"); map.put("errMsg", "该物料未绑定库位"); return map; } StringBuffer stringBuffer = new StringBuffer(); Map listMap = new HashMap<>(); for (int i = 0; i < listMaterialClass.size(); i++) { Map map1 = warehousingMapper.getScanNum(listMaterialClass.get(i).getStorageLocationCode(), num); if ( Double.doubleToLongBits(Double.parseDouble(String.valueOf(map1.get("scanNum")))) <= Double.doubleToLongBits(Double.parseDouble(String.valueOf(materialClass.getSize()))) ) { //查询库存是否同物料同批次存在 List countProduc = warehousingMapper.getInventoryProduc(listMaterialClass.get(i).getWllbCode(), producDate, listMaterialClass.get(i).getStorageLocationCode()); if (countProduc.size() == 0) { stringBuffer.append(listMaterialClass.get(i).getStorageLocationCode() + ","); int surplusNum = (int) (Double.parseDouble(String.valueOf(materialClass.getSize())) - Double.parseDouble(String.valueOf(map1.get("scanNum"))) + Double.parseDouble(num)); listMap.put(listMaterialClass.get(i).getStorageLocationCode(), surplusNum); } else { if (String.valueOf(countProduc.get(0)).equals(producDate)) { stringBuffer.append(listMaterialClass.get(i).getStorageLocationCode() + ","); int surplusNum = (int) (Double.parseDouble(String.valueOf(materialClass.getSize())) - Double.parseDouble(String.valueOf(map1.get("scanNum"))) + Double.parseDouble(num)); listMap.put(listMaterialClass.get(i).getStorageLocationCode(), surplusNum); } } } } List list = warehousingMapper.recommend(stringBuffer.toString()); map.put("data", list); map.put("listString", listMap);//返回库位剩余数量 map.put("msg", "200"); } catch (Exception e) { e.printStackTrace(); map.put("msg", "500"); map.put("errMsg", "服务器请求异常,请稍后再试"); } return map; } @Override @Transactional(rollbackFor = Exception.class) public Map addWarehousingVirtual(WarehousingVirtual warehousingVirtual) { Map map = new HashMap<>(); try { warehousingMapper.addWarehousingVirtual(warehousingVirtual); map.put("msg", "200"); } catch (Exception e) { e.printStackTrace(); map.put("msg", "500"); map.put("errMsg", "服务器请求异常,请稍后再试"); } return map; } @Override @Transactional(rollbackFor = Exception.class) public Map delWarehousingVirtual(WarehousingVirtual warehousingVirtual) { Map map = new HashMap<>(); try { warehousingMapper.delWarehousingVirtual(warehousingVirtual); map.put("msg", "200"); } catch (Exception e) { e.printStackTrace(); map.put("msg", "500"); map.put("errMsg", "服务器请求异常,请稍后再试"); } return map; } @Override @Transactional(rollbackFor = Exception.class) public Map warehousing(String uniqueCode, String type, String warehouseTransferId) { Map map = new HashMap<>(); try { //入库信息 List list = new LinkedList<>(); //返回采购单id StringBuilder stringBuilder = new StringBuilder(); //查询入库所需要的信息 for(WarehousingVirtual warehousingVirtual : warehousingMapper.getVirtual(uniqueCode, type, warehouseTransferId)){ //查询采购单信息 ReceiveGoods receiveGoods1 = receiveGoodsMapper.getReceiveGoodsCode(warehousingVirtual.getReceiveGoodsId()); //存入给gs的返回数据 String code = codeGenerateRk(); warehousingVirtual.setStorageCode(code); //查询部门编号 List listUser = userMapper.getAllUser(new User().setId(warehousingVirtual.getUserId())); warehousingVirtual.setDepartmentId(listUser.get(0).getDepartmentId()); //查询物料分类 WarehousingVirtual warehousingVirtual1 = warehousingMapper.getWlClass(warehousingVirtual); warehousingVirtual.setWllbClass(warehousingVirtual1.getWllbClass()); warehousingVirtual.setMaterialId(warehousingVirtual1.getMaterialId()); warehousingVirtual.setPurchaseNum(receiveGoods1.getPurchaseNum()); list.add(warehousingVirtual); if(Integer.parseInt(warehousingVirtual.getNum()) <= 0){ break; } receiveGoods1.setWarehousingNum(warehousingVirtual.getNum()); warehousingMapper.updateReceiveGood(receiveGoods1); ReturnWarehousing returnWarehousing = new ReturnWarehousing() .setWarehousingNum(receiveGoods1.getWarehousingNum()) .setGsCk(warehousingVirtual.getGsCk()) .setSourceType(receiveGoods1.getSourceType()) .setMoveType(receiveGoods1.getMoveType()) .setEntryNumber(receiveGoods1.getEntryNumber()) .setWbs(receiveGoods1.getWbs()) .setId(receiveGoods1.getId()) .setMaterialId(receiveGoods1.getMaterialId()) .setStorageCode(warehousingVirtual.getStorageCode()) .setOrderNumber(receiveGoods1.getOrderNumber()) .setUserName(warehousingVirtual.getUserName()) .setStorageLocationCode(warehousingVirtual.getStorageLocationCode()); warehousingMapper.addReturnWarehousing(returnWarehousing); warehousingMapper.updateStorage(warehousingVirtual1);//增加入库编号 //判断是否有已存在的采购单号 if(!stringBuilder.toString().contains(receiveGoods1.getOrderNumber() + ",")){ stringBuilder.append(receiveGoods1.getOrderNumber() + ","); } } //入库 warehousingMapper.addStorage(list);//入库流水 warehousingMapper.addInventory(list);//库存 warehousingMapper.delVirtual(uniqueCode);//删除临时表数据 map.put("data", stringBuilder.toString()); map.put("msg", "200"); } catch (Exception e) { e.printStackTrace(); map.put("msg", "500"); map.put("errMsg", "服务器请求异常,请稍后再试"); } return map; } @Override public void plugOutWarehousing(String orderNumber) { try { for (ReturnWarehousing returnWarehousing : warehousingMapper.getPlugOutWarehousing(orderNumber)) { JSONObject returnData = new JSONObject(); JSONObject BillItems = new JSONObject(); JSONObject strJson = new JSONObject(); strJson.put("PurOrderID", returnWarehousing.getOrderNumber());//采购单id strJson.put("WMSID", returnWarehousing.getId());//入库单id strJson.put("WMSCode", returnWarehousing.getStorageCode());//入库单编号 strJson.put("WareHouse", dictionaryMapper.getWarehouse(returnWarehousing.getStorageLocationCode()));//仓库id strJson.put("SourceBillDate", DateUtil.dateConversion(returnWarehousing.getScrq()));//业务日期 strJson.put("SourceType", returnWarehousing.getSourceType());//来源类型 strJson.put("MoveType", returnWarehousing.getMoveType());//移动类型 strJson.put("Creator", "测试");//制单人姓名 BillItems.put("WMSItemID", returnWarehousing.getReceiveGoodsId());//利道WMS入库单分录ID BillItems.put("PurOrderID", returnWarehousing.getOrderNumber());//采购单id BillItems.put("PurOrderItemID", returnWarehousing.getEntryNumber());//采购订单明细ID BillItems.put("Material", returnWarehousing.getMaterialId());//物料id BillItems.put("Quantity", returnWarehousing.getWarehousingNum());//入库数量 BillItems.put("FlexField1", returnWarehousing.getWbs());//wbs BillItems.put("FlexField1Code", returnWarehousing.getWbsCode());//WBS编号 BillItems.put("FlexField1Name", returnWarehousing.getWbsName());//WBS名称 List list = new LinkedList<>(); list.add(BillItems); strJson.put("BillItems", list); returnData.put("strJson", JSON.toJSONString(strJson)); HttpClientUtil httpClientUtil1 = new HttpClientUtil(); Map result = httpClientUtil1.doPost("http://42.159.85.29:52480/cwbase/sg/V1/ERP/TELD/DEVTEST/API_WMS_PurInStock/CreateProductiveOutStock", returnData); Error error = new Error(); int type = 0; if (Integer.parseInt(result.get("msg").toString()) != 200) { //如果失败存入报错信息跟数据 error.setErrorInfo(result.get("data").toString()); error.setUrl("http://42.159.85.29:52480/cwbase/sg/V1/ERP/TELD/DEVTEST/API_WMS_PurInStock/CreateProductiveOutStock"); error.setDataVal(returnData.toJSONString()); errorMapper.addError(error); type = 1; } else { JSONObject jsonObject = JSONObject.parseObject(JSON.parseObject((String) result.get("data")).get("result").toString()); if (jsonObject.get("State").toString().equals("0")) { //如果失败存入报错信息跟数据 error.setErrorInfo(jsonObject.get("Msg").toString()); error.setUrl("http://42.159.85.29:52480/cwbase/sg/V1/ERP/TELD/DEVTEST/API_WMS_PurInStock/CreateProductiveOutStock"); error.setDataVal(returnData.toJSONString()); errorMapper.addError(error); type = 1; } } //删除父子表信息 askGoodsMapper.delPlugOutWarehousing(orderNumber); //添加记录到tld_access String names = "入库回传"; String accessType = "1"; String returnGsRemoval = returnData.toString(); askGoodsMapper.addAccess(names, returnGsRemoval, accessType); //增加流水传输状态 warehousingMapper.updateWarehousingType(returnWarehousing.getStorageCode(), type); } } catch (Exception e) { e.printStackTrace(); } } @Override public Map warehousingFlowing(Storage storage) { Map map = new HashMap<>(); try { PageHelper.startPage(storage.getPage(), storage.getLimit()); PageInfo list = new PageInfo<>(warehousingMapper.warehousingFlowing(storage)); map.put("data", list); map.put("msg", "200"); } catch (Exception e) { e.printStackTrace(); map.put("msg", "500"); map.put("errMsg", "服务器请求异常,请稍后再试"); } return map; } @Override public Map getWarehousingVirtual(String uniqueCode, String type, String warehouseTransferId) { Map map = new HashMap<>(); try { List list = warehousingMapper.getWarehousingVirtual(uniqueCode, type, warehouseTransferId); map.put("data", list); map.put("msg", "200"); } catch (Exception e) { e.printStackTrace(); map.put("msg", "500"); map.put("errMsg", "服务器请求异常,请稍后再试"); } return map; } @Override public void export(Storage storage, HttpServletResponse response) { try { //导出数据汇总 List> sheetDataList = new ArrayList<>(); //表头数据 List head = Arrays.asList("物料名称", "物料编号", "供应商名称", "连番号", "生产日期", "生产批次", "容量", "序列号", "类型", "用户名称", "部门", "库位名称", "入库日期", "采购单号", "WBS","真实姓名","采购订单号", "公司名称", "采购数量"); //查询数据 List> list = new ArrayList<>(warehousingMapper.export(storage)); sheetDataList.add(head); for (Map userMap : list) { List listSheet = new ArrayList<>(); for (String key : userMap.keySet()) { listSheet.add(userMap.get(key)); } sheetDataList.add(listSheet); } //当前时间 Date time = new Date(); SimpleDateFormat sdf = new SimpleDateFormat("yyyyMddHHmmss"); ExcelUtils.export(response, "入库流水数据导出" + sdf.format(time), sheetDataList); } catch (Exception e) { e.printStackTrace(); } } @Override public Map getNotice(Notice notice) { Map map = new HashMap<>(); try { Map sumScanNum = new HashMap<>(); PageHelper.startPage(notice.getPage(), notice.getLimit()); PageInfo list = new PageInfo<>(warehousingMapper.getNotice(notice)); for (Notice notice1 : list.getList()) { int sumScanNumVal = warehousingMapper.getSumScanNumVal(notice1); sumScanNum.put(notice1.getNoticeId() + "-" + notice1.getMaterialId(), sumScanNumVal); } map.put("data", list); map.put("msg", "200"); map.put("sumScanNum", sumScanNum); } catch (Exception e) { e.printStackTrace(); map.put("msg", "500"); map.put("errMsg", "服务器请求异常,请稍后再试"); } return map; } @Override @Transactional(rollbackFor = Exception.class) public Map addInventoryNotice(Notice notice) { Map map = new HashMap<>(); try { Notice notice1 = warehousingMapper.getNoticeId(notice); if (notice1.getType().equals("1")) { map.put("msg", "500"); map.put("errMsg", "此通知单已入库!"); return map; } // if(Double.parseDouble(notice1.getNum()) < Double.parseDouble(notice.getNum())){ // map.put("msg", "500"); // map.put("errMsg", "入库数量大于通知单数量!"); // return map; // } if (warehousingMapper.getInventoryNotice(notice) != 0) { warehousingMapper.updateInventoryNotice(notice); } else { warehousingMapper.addInventoryNotice(notice); } notice.setType("1"); warehousingMapper.updateNotice(notice);//修改报工单数量 //存入给gs的返回数据 String storageCode = codeGenerateRk(); //入库流水 WarehousingVirtual warehousingVirtual = new WarehousingVirtual() .setWllbCode(notice1.getMaterialCode()) .setUserId(notice.getUserId()) .setStorageLocationCode(notice.getStorageLocationCode()) .setProducDate(notice1.getNoticeTime()) .setNum(notice.getWarehousingNum()) .setStorageCode(storageCode) .setWbs(notice.getWbs()) .setProductionCode(notice1.getProductionCode()) .setAccountSleeve(notice.getCompanyNumber()); warehousingMapper.addProduct(warehousingVirtual);//入库流水 半成品 ReturnWarehousing returnWarehousing = new ReturnWarehousing() .setStorageCode(storageCode)//入库编号 .setSourceType(notice1.getSourceType())//来源类型 .setMoveType(notice1.getMoveType())//移动类型 .setOrderNumber(notice1.getNoticeId())//通知单id .setWbs(notice1.getWbs())//wbs .setEntryNumber(notice1.getEntryNumber())//gs分录号 .setMaterialId(notice1.getMaterialId())//物料id .setId(notice1.getId())//分录单id .setWarehousingNum(notice.getWarehousingNum())//入库数量 .setStorageLocationCode(notice.getStorageLocationCode())//库位编号 .setUserName(notice.getUserName());//用户名称 warehousingMapper.addReturnWarehousing(returnWarehousing); map.put("data", storageCode); map.put("msg", "200"); } catch (Exception e) { e.printStackTrace(); map.put("msg", "500"); map.put("errMsg", "服务器请求异常,请稍后再试"); } return map; } @Override @Transactional(rollbackFor = Exception.class) public Map updateInventoryNotice(Notice notice) { Map map = new HashMap<>(); //redis并发锁 RLock lock = redissonClient.getLock(notice.getMaterialId()); lock.lock(); try { Inventory inventory = warehousingMapper.getHalfInventory(notice);//库存信息 AskGoods askGoods = warehousingMapper.getAskGoodsHalf(notice);//要货单信息 if (askGoods.getType().equals("1")) { map.put("msg", "500"); map.put("errMsg", "订单已出库"); return map; } if (Double.doubleToLongBits(Double.parseDouble(askGoods.getNum())) < Double.doubleToLongBits(Double.parseDouble(notice.getWarehousingNum()) + Double.parseDouble(askGoods.getOutNum()))) { map.put("msg", "500"); map.put("errMsg", "出库数量大于剩余要货单数量"); return map; } if (inventory == null) { map.put("msg", "500"); map.put("errMsg", "没有查询到此半成品物料的库存"); return map; } if (Double.doubleToLongBits(Double.parseDouble(notice.getWarehousingNum())) > Double.doubleToLongBits(Double.parseDouble(inventory.getAmount()))) { map.put("msg", "500"); map.put("errMsg", "库存不足"); return map; } if (Double.doubleToLongBits(Double.parseDouble(notice.getWarehousingNum())) == Double.doubleToLongBits(Double.parseDouble(inventory.getAmount()))) { warehousingMapper.delInventoryNotice(notice); } else { warehousingMapper.updateInventoryNoticeNum(notice); } //出库数量 + 已经出库的数量 如果相等 则改变单据状态 Double num = Double.parseDouble(notice.getWarehousingNum()) + Double.parseDouble(askGoods.getOutNum()); String type = null; if(Double.doubleToLongBits(Double.parseDouble(askGoods.getNum())) == Double.doubleToLongBits(num)){ type = "1"; } warehousingMapper.updateAskGoodsHalf(askGoods.getId(), notice.getWarehousingNum(), type);//修改要货单出库数量 //新增返回gs信息 String removalCode = codeGenerateCk(); //新增半成品出库流水 AskGoods askGoods1 = new AskGoods() .setWllbCode(notice.getWllbCode()) .setNum(notice.getWarehousingNum()) .setUserId(notice.getUserId()) .setAskGoodsId(askGoods.getAskGoodsId()) .setDepartment(askGoods.getDepartment()) .setStorageCode(removalCode) .setWbs(notice.getWbs()) .setCompanyNumber(notice.getCompanyNumber());//新增出库流水 warehousingMapper.addRemovalHalfProduct(askGoods1); ReturRemoval returRemoval = new ReturRemoval() .setMaterialId(notice.getMaterialId()) .setDocumentId(notice.getAskGoodsId()) .setWbs(askGoods.getWbs()) .setNum(notice.getWarehousingNum()) .setEntryNumber(askGoods.getEntryNumber()) .setDocumentPointsId(askGoods.getId()) .setStorageLocationCode(inventory.getStorageLocationCode()) .setRemovalCode(removalCode) .setSourceType(askGoods.getSourceType()) .setMoveType(askGoods.getMoveType()); askGoodsMapper.addReturnGsRemovalF(returRemoval);//新增返回gs数据父表信息 askGoodsMapper.addReturnGsRemoval(returRemoval);//新增返回gs数据子表信息 map.put("data", notice.getAskGoodsId()); map.put("msg", "200"); } catch (Exception e) { e.printStackTrace(); map.put("msg", "500"); map.put("errMsg", "服务器请求异常,请稍后再试"); } finally { //判断要解锁的key是否已被锁定;判断要解锁的key是否被当前线程持有 if (lock.isLocked() && lock.isHeldByCurrentThread()) { //释放锁 lock.unlock(); } } return map; } @Override public Map getProduct(Notice notice) { Map map = new HashMap<>(); try { PageHelper.startPage(notice.getPage(), notice.getLimit()); PageInfo list = new PageInfo<>(warehousingMapper.getProduct(notice)); map.put("data", list); map.put("msg", "200"); } catch (Exception e) { e.printStackTrace(); map.put("msg", "500"); map.put("errMsg", "服务器请求异常,请稍后再试"); } return map; } @Override public void productExcel(Notice notice, HttpServletResponse response) { try { //导出数据汇总 List> sheetDataList = new ArrayList<>(); //表头数据 List head = Arrays.asList("物料名称", "物料编号", "生产时间", "数量", "用户名称", "入库时间", "入库单编号", "WBS","真实姓名","生产订单号","公司名称"); //查询数据 List> list = warehousingMapper.productExcel(notice); sheetDataList.add(head); for (Map userMap : list) { List listSheet = new ArrayList<>(); for (String key : userMap.keySet()) { listSheet.add(userMap.get(key)); } sheetDataList.add(listSheet); } //当前时间 Date time = new Date(); SimpleDateFormat sdf = new SimpleDateFormat("yyyyMddHHmmss"); ExcelUtils.export(response, "入库流水数据导出" + sdf.format(time), sheetDataList); } catch (Exception e) { e.printStackTrace(); } } @Override public Map getProductWarehousing(Notice notice) { Map map = new HashMap<>(); try { MaterialClass material = warehousingMapper.getMaterial(notice); if (material == null) { map.put("msg", "500"); map.put("errMsg", "物料信息未录入,请联系管理员"); return map; } Map mapVal = warehousingMapper.getScanIsNotProduct(notice); if (Integer.parseInt(mapVal.get("inventoryCount").toString()) != 0 || Integer.parseInt(mapVal.get("virtualCount").toString()) != 0) { map.put("msg", "500"); map.put("errMsg", "已被扫描"); return map; } int num = 0; if (notice.getType().equals("0")) { num = warehousingMapper.getNumUtil("产成品库位托盘定义"); } else { num = Integer.parseInt(material.getSize()); } int scanNum = Integer.parseInt(mapVal.get("inventoryCount").toString()) + Integer.parseInt(mapVal.get("virtualCount").toString()); if(scanNum == num){ map.put("msg", "500"); map.put("errMsg", "库位已满"); return map; } Notice notice1 = warehousingMapper.getNoticeId(new Notice().setNoticeId(notice.getNoticeId()).setMaterialId(notice.getMaterialId())); Double contrast = Double.parseDouble(notice1.getWarehousingNum()) + Double.parseDouble(notice.getWarehousingNum()); if(Double.doubleToLongBits(contrast) > Double.doubleToLongBits(Double.parseDouble(notice1.getNum()))){ map.put("msg", "500"); map.put("errMsg", "扫描数量超出报工单数量"); return map; } notice.setWllbClass(material.getWllbClass()); StringBuffer stringBuffer = new StringBuffer();//库位编号 if (material.getPartType().equals("产成品")) { if (material.getIsRecommend().equals("1")) { StorageLocation storageLocation = new StorageLocation().setIsProduct("1"); String[] symbol = {"<", "="}; for(int i = 0; i < symbol.length; i++){ String producBatch = null; if(symbol[i].equals("=")){ producBatch = notice.getProducBatch(); } String storageLocationCode = warehousingMapper.getStorageLocationCode(notice.getAttribute(), symbol[i], producBatch, material.getTldId(), notice.getCompanyNumber()); //查询昨天没满的库位 if(!storageLocationCode.equals("0")) { int countStorage = warehousingMapper.getCountStorage(notice.getAttribute(), storageLocationCode, symbol[i], producBatch, material.getTldId()); if (countStorage < num) { stringBuffer.append(storageLocationCode + ","); List list = warehousingMapper.recommend(stringBuffer.toString()); map.put("data", list); map.put("msg", "210"); return map; } } } //查询产成品库位 List storageLocations = storageLocationMapper.getStorage(storageLocation); for(StorageLocation storageLocation1 : storageLocations) { Inventory inventory = warehousingMapper.getInventoryInfo(storageLocation1);//查询库存信息 if(inventory == null) { stringBuffer.append(storageLocation1.getStorageLocationCode() + ","); break; } } List list = warehousingMapper.recommend(stringBuffer.toString()); map.put("data", list); map.put("msg", "210"); } else { map.put("msg", "220"); // if(warehousingMapper.getInventoryNotice(notice) != 0){ // warehousingMapper.updateInventoryNotice(notice); // } else { // warehousingMapper.addInventoryNotice(notice); // } // warehousingMapper.updateNotice(notice);//修改报工单数量 // String storageCode = codeGenerateRk(); // //入库流水 // Notice notice1 = warehousingMapper.getNoticeId(notice); // WarehousingVirtual warehousingVirtual = new WarehousingVirtual() // .setWllbCode(material.getWllbCode()) // .setUserId(notice.getUserId()) // .setStorageLocationCode(notice.getStorageLocationCode()) // .setProducDate(notice.getProducBatch()) // .setNum(notice.getWarehousingNum()) // .setSerial(notice.getSerial()) // .setSeq(notice.getSeq()) // .setAttribute(notice.getAttribute()) // .setStorageCode(storageCode) // .setWbs(notice.getWbs()) // .setProductionCode(notice1.getProductionCode()); // warehousingMapper.addHalf(warehousingVirtual);//入库流水 产成品 // //存入给gs的返回数据 // ReturnWarehousing returnWarehousing = new ReturnWarehousing() // .setStorageCode(storageCode)//入库编号 // .setSourceType(notice1.getSourceType())//来源类型 // .setMoveType(notice1.getMoveType())//移动类型 // .setOrderNumber(notice1.getNoticeId())//通知单id // .setWbs(notice1.getWbs())//wbs // .setEntryNumber(notice1.getEntryNumber())//gs分录号 // .setMaterialId(notice1.getMaterialId())//物料id // .setId(notice1.getId())//分录单id // .setWarehousingNum(notice.getWarehousingNum());//入库数量 // warehousingMapper.addReturnWarehousing(returnWarehousing); // map.put("msg", "200"); // map.put("data", notice1.getNoticeId() + ","); } } } catch (Exception e) { e.printStackTrace(); map.put("msg", "500"); map.put("errMsg", "服务器请求异常,请稍后再试"); } return map; } @Override public Map getProductWarehousingRecommend(String uniqueCode, String type, String noticeId) { Map map = new HashMap<>(); try { //返回采购单id StringBuilder stringBuilder = new StringBuilder(); //查询入库所需要的信息 for (WarehousingVirtual warehousingVirtual : warehousingMapper.getVirtualNotice(uniqueCode, type, noticeId)) { //查询物料信息 Notice notice = new Notice().setMaterialCode(warehousingVirtual.getWllbCode()); MaterialClass material = warehousingMapper.getMaterial(notice); Notice notice1 = warehousingMapper.getNoticeId(new Notice().setNoticeId(noticeId).setMaterialId(material.getTldId())); Notice notice2 = new Notice() .setMaterialId(material.getTldId()) .setStorageLocationCode(warehousingVirtual.getStorageLocationCode()) .setNoticeId(noticeId) .setWarehousingNum(warehousingVirtual.getNum()) .setAttribute(warehousingVirtual.getAttribute()) .setProducBatch(warehousingVirtual.getProducDate()) .setWllbClass(material.getWllbClass()) .setWbs(notice1.getWbs()) .setCompanyNumber(notice1.getCompanyNumber()) .setSupplierId(warehousingVirtual.getSuppId()) .setSerial(warehousingVirtual.getSerial()) .setWllbCode(material.getWllbCode()) .setCompanyNumber(notice1.getCompanyNumber()); Double num = Double.parseDouble(notice1.getWarehousingNum()) + Double.parseDouble(warehousingVirtual.getNum()); if(Double.doubleToLongBits(num) == Double.doubleToLongBits(Double.parseDouble(notice1.getNum()))){ notice2.setType("1"); } warehousingMapper.addInventoryNotice(notice2);//入库存 warehousingMapper.updateNotice(notice2);//修改报工单数量 //入库流水 String storageCode = codeGenerateRk(); WarehousingVirtual warehousingVirtual1 = new WarehousingVirtual() .setWllbCode(material.getWllbCode()) .setUserId(warehousingVirtual.getUserId()) .setStorageLocationCode(warehousingVirtual.getStorageLocationCode()) .setProducDate(warehousingVirtual.getProducDate()) .setNum(warehousingVirtual.getNum()) .setSerial(warehousingVirtual.getSerial()) .setSeq(warehousingVirtual.getSeq()) .setAttribute(warehousingVirtual.getAttribute()) .setStorageCode(storageCode) .setWbs(notice1.getWbs()) .setProductionCode(notice1.getProductionCode()) .setAccountSleeve(warehousingVirtual.getAccountSleeve()); warehousingMapper.addHalf(warehousingVirtual1);//入库流水 产成品 //存入给gs的返回数据 ReturnWarehousing returnWarehousing = new ReturnWarehousing() .setStorageCode(storageCode)//入库编号 .setSourceType(notice1.getSourceType())//来源类型 .setMoveType(notice1.getMoveType())//移动类型 .setOrderNumber(notice1.getNoticeId())//通知单id .setWbs(notice1.getWbs())//wbs .setEntryNumber(notice1.getEntryNumber())//gs分录号 .setMaterialId(notice1.getMaterialId())//物料id .setId(notice1.getId())//分录单id .setWarehousingNum(warehousingVirtual.getNum());//入库数量 warehousingMapper.addReturnWarehousing(returnWarehousing); if (!stringBuilder.toString().contains(notice1.getNoticeId() + ",")) { stringBuilder.append(notice1.getNoticeId() + ","); } warehousingMapper.delVirtual(uniqueCode);//删除临时表数据 } map.put("msg", "200"); map.put("data", stringBuilder.toString()); } catch (Exception e) { e.printStackTrace(); map.put("msg", "500"); map.put("errMsg", "服务器请求异常,请稍后再试"); } return map; } @Override public Map getHalf(Notice notice) { Map map = new HashMap<>(); try { PageHelper.startPage(notice.getPage(), notice.getLimit()); PageInfo list = new PageInfo<>(warehousingMapper.getHalf(notice)); map.put("data", list); map.put("msg", "200"); } catch (Exception e) { e.printStackTrace(); map.put("msg", "500"); map.put("errMsg", "服务器请求异常,请稍后再试"); } return map; } @Override public void getHalfExcel(Notice notice, HttpServletResponse response) { try { //导出数据汇总 List> sheetDataList = new ArrayList<>(); //表头数据 List head = Arrays.asList("物料名称", "物料编号", "生产批次", "数量", "用户名称", "库位编号", "入库时间", "连番号", "序列号", "属性", "入库单编号", "WBS","真实姓名","生产订单号","公司名称"); //查询数据 List> list = warehousingMapper.getHalfExcel(notice); sheetDataList.add(head); for (Map userMap : list) { List listSheet = new ArrayList<>(); for (String key : userMap.keySet()) { listSheet.add(userMap.get(key)); } sheetDataList.add(listSheet); } //当前时间 Date time = new Date(); SimpleDateFormat sdf = new SimpleDateFormat("yyyyMddHHmmss"); ExcelUtils.export(response, "入库流水数据导出" + sdf.format(time), sheetDataList); } catch (Exception e) { e.printStackTrace(); } } /** * 删除半成品 * * @return */ @Override @Transactional(rollbackFor = Exception.class) public Map delInventoryNotice(String id, HttpServletRequest request) { Map map = new HashMap<>(); try { String userId = request.getHeader("userId"); Map mapVal = askGoodsMapper.getInventoryNotice(id); if (mapVal.get("type").toString().equals("1")) { map.put("msg", "500"); map.put("errMsg", "报工单已报工"); return map; } LogData logData = new LogData() .setUserId(userId) .setData(mapVal.toString()) .setType("0") .setDocumentType("报工单"); dictionaryMapper.addLogdata(logData); askGoodsMapper.delInventoryNotice(id); map.put("msg", "200"); } catch (Exception e) { e.printStackTrace(); map.put("msg", "500"); map.put("errMsg", "服务器请求异常,请稍后再试"); } return map; } @Override public Map otherWarehousing(AskGoods askGoods) { Map map = new HashMap<>(); try { //判断物料是否录入 MaterialClass materialClass = warehousingMapper.getMateriaIsExist(askGoods.getWllbCode()); askGoods.setMaterialId(materialClass.getTldId()); //查询库存 List inventory = askGoodsMapper.getInventoryInfoOther(askGoods); map.put("list", inventory); map.put("data", materialClass); map.put("msg", "200"); } catch (Exception e) { e.printStackTrace(); map.put("msg", "500"); map.put("errMsg", "服务器请求异常,请稍后再试"); } return map; } @Override public Map otherWarehou(Inventory inventory, HttpServletRequest request) { Map map = new HashMap<>(); try { //判断物料是否录入 MaterialClass materialClass = warehousingMapper.getMateriaIsExist(inventory.getWllbCode()); String userId = request.getHeader("userId"); inventory.setWllbClass(materialClass.getWllbClass()).setMaterialId(materialClass.getTldId()).setUserId(userId); if(inventory.getId() != null){ warehousingMapper.updateInventoryOther(inventory); } else { warehousingMapper.addInventoryOther(inventory); } List list = new LinkedList<>(); String storageCode = codeGenerateRk();//入库单 WarehousingVirtual warehousingVirtual = new WarehousingVirtual() .setStorageCode(storageCode) .setWllbCode(materialClass.getCode()) .setSuppId(inventory.getSupplierId()) .setSerial(inventory.getSerial()) .setProducDate(inventory.getProducDate()) .setCapacity(inventory.getNum()) .setType("其他入库") .setUserId(userId) .setDepartmentId(inventory.getDepartmentId()) .setStorageLocationCode(inventory.getStorageLocationCode()) .setWbs(inventory.getWbs()) .setAccountSleeve(inventory.getAccountSleeve()) .setMaterialId(materialClass.getTldId()) .setNum(inventory.getAmount()) .setAttribute(inventory.getAttribute()); list.add(warehousingVirtual); if(materialClass.getPartType().equals("原材料")){ warehousingMapper.addStorage(list);//入库流水 } else if(materialClass.getPartType().equals("半成品")){ SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd"); warehousingVirtual.setProducDate(simpleDateFormat.format(new Date()).toString()); warehousingMapper.addProduct(warehousingVirtual);//入库流水 半成品 } else { warehousingMapper.addHalf(warehousingVirtual);//入库流水 产成品 } warehousingMapper.addReturnWarehousingOther(warehousingVirtual);//其他入库返回信息 map.put("data", storageCode); map.put("msg", "200"); } catch (Exception e) { e.printStackTrace(); map.put("msg", "500"); map.put("errMsg", "服务器请求异常,请稍后再试"); } return map; } @Override public Map getMing(String code) { Map map = new HashMap<>(); try { //查询库存 String wllbCode = askGoodsMapper.getMing(code); //判断物料是否录入 MaterialClass materialClass = warehousingMapper.getMateriaIsExist(wllbCode); if(materialClass != null){ if(materialClass.getWllbClass().equals("圆柱终端")){ map.put("msg", "500"); map.put("errMsg", "请扫描托码"); return map; } } map.put("data", materialClass); map.put("msg", "200"); } catch (Exception e) { e.printStackTrace(); map.put("msg", "500"); map.put("errMsg", "服务器请求异常,请稍后再试"); } return map; } @Override public Map addWarehousingVirtualTwo(WarehousingVirtual warehousingVirtual) { Map map = new HashMap<>(); try{ Map mapVal = warehousingMapper.getSumWarehousingVirtual(warehousingVirtual); Double num = Double.parseDouble(warehousingVirtual.getNum()) + Double.parseDouble(mapVal.get("scanNum").toString()); if(Double.doubleToLongBits(Double.parseDouble(mapVal.get("num").toString())) < Double.doubleToLongBits(num)){ String surplus = String.valueOf(Double.parseDouble(mapVal.get("num").toString()) - Double.parseDouble(mapVal.get("scanNum").toString())); map.put("msg", "500"); map.put("errMsg", "扫描数量超过单据数量,剩余要扫数量" + surplus); return map; } warehousingMapper.addWarehousingVirtual(warehousingVirtual); map.put("msg", "200"); } catch (Exception e){ e.printStackTrace(); map.put("msg", "500"); map.put("errMsg", "服务器请求异常,请稍后再试"); } return map; } @Override public Map addWarehouseTransferVirtual(WarehousingVirtual warehousingVirtual) { Map map = new HashMap<>(); try{ Map mapVal = warehousingMapper.getWarehouseTransferVirtual(warehousingVirtual); Double num = Double.parseDouble(warehousingVirtual.getNum()) + Double.parseDouble(mapVal.get("scanNum").toString()); if(Double.doubleToLongBits(Double.parseDouble(mapVal.get("num").toString())) < Double.doubleToLongBits(num)){ String surplus = String.valueOf(Double.parseDouble(mapVal.get("num").toString()) - Double.parseDouble(mapVal.get("scanNum").toString())); map.put("msg", "500"); map.put("errMsg", "扫描数量超过单据数量,剩余要扫数量" + surplus); return map; } warehousingMapper.addWarehousingVirtual(warehousingVirtual); map.put("msg", "200"); } catch (Exception e){ e.printStackTrace(); map.put("msg", "500"); map.put("errMsg", "服务器请求异常,请稍后再试"); } return map; } /** * 入库单生成 * * @return */ public String codeGenerateRk() { StringBuilder stringBuilder = new StringBuilder("RK"); Date date = new Date(); SimpleDateFormat sdf = new SimpleDateFormat("yyMMdd"); stringBuilder.append(sdf.format(date)); int count = warehousingMapper.getWarehousingCount(); for (int i = 0; i < 4 - (count + "").length(); i++) { stringBuilder.append("0"); } return (stringBuilder.append(count + 1)).toString(); } /** * 出库单id * * @return */ public String codeGenerateCk() { StringBuilder stringBuilder = new StringBuilder("CK"); Date date = new Date(); SimpleDateFormat sdf = new SimpleDateFormat("yyMMdd"); stringBuilder.append(sdf.format(date)); int count = askGoodsMapper.getReturnRemovalCount(); for (int i = 0; i < 4 - (count + "").length(); i++) { stringBuilder.append("0"); } return (stringBuilder.append(count + 1)).toString(); } }