123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998 |
- 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<String, Object> getRecommend(String wllbCode, String suppId, String num, String unique, String producDate, String warehouseWhere) {
- Map<String, Object> 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<String, Object> 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<StorageLocation> list1 = warehousingMapper.getIsNotSisableLocation("1");
- map.put("data", list1);
- map.put("msg", "200");
- return map;
- }
- List<MaterialClass> 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<String, Object> listMap = new HashMap<>();
- for (int i = 0; i < listMaterialClass.size(); i++) {
- Map<String, Object> 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<String> 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<StorageLocation> 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<String, Object> addWarehousingVirtual(WarehousingVirtual warehousingVirtual) {
- Map<String, Object> 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<String, Object> delWarehousingVirtual(WarehousingVirtual warehousingVirtual) {
- Map<String, Object> 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<String, Object> warehousing(String uniqueCode, String type, String warehouseTransferId) {
- Map<String, Object> map = new HashMap<>();
- try {
- //入库信息
- List<WarehousingVirtual> 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<User> 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<JSONObject> list = new LinkedList<>();
- list.add(BillItems);
- strJson.put("BillItems", list);
- returnData.put("strJson", JSON.toJSONString(strJson));
- HttpClientUtil httpClientUtil1 = new HttpClientUtil();
- Map<String, Object> 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<String, Object> warehousingFlowing(Storage storage) {
- Map<String, Object> map = new HashMap<>();
- try {
- PageHelper.startPage(storage.getPage(), storage.getLimit());
- PageInfo<Storage> 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<String, Object> getWarehousingVirtual(String uniqueCode, String type, String warehouseTransferId) {
- Map<String, Object> map = new HashMap<>();
- try {
- List<WarehousingVirtual> 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<List<Object>> sheetDataList = new ArrayList<>();
- //表头数据
- List<Object> head = Arrays.asList("物料名称", "物料编号", "供应商名称", "连番号", "生产日期", "生产批次", "容量", "序列号", "类型", "用户名称", "部门", "库位名称", "入库日期", "采购单号", "WBS","真实姓名","采购订单号", "公司名称", "采购数量");
- //查询数据
- List<Map<String, Object>> list = new ArrayList<>(warehousingMapper.export(storage));
- sheetDataList.add(head);
- for (Map<String, Object> userMap : list) {
- List<Object> 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<String, Object> getNotice(Notice notice) {
- Map<String, Object> map = new HashMap<>();
- try {
- Map<String, Object> sumScanNum = new HashMap<>();
- PageHelper.startPage(notice.getPage(), notice.getLimit());
- PageInfo<Notice> 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<String, Object> addInventoryNotice(Notice notice) {
- Map<String, Object> 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<String, Object> updateInventoryNotice(Notice notice) {
- Map<String, Object> 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<String, Object> getProduct(Notice notice) {
- Map<String, Object> map = new HashMap<>();
- try {
- PageHelper.startPage(notice.getPage(), notice.getLimit());
- PageInfo<Notice> 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<List<Object>> sheetDataList = new ArrayList<>();
- //表头数据
- List<Object> head = Arrays.asList("物料名称", "物料编号", "生产时间", "数量", "用户名称", "入库时间", "入库单编号", "WBS","真实姓名","生产订单号","公司名称");
- //查询数据
- List<Map<String, Object>> list = warehousingMapper.productExcel(notice);
- sheetDataList.add(head);
- for (Map<String, Object> userMap : list) {
- List<Object> 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<String, Object> getProductWarehousing(Notice notice) {
- Map<String, Object> map = new HashMap<>();
- try {
- MaterialClass material = warehousingMapper.getMaterial(notice);
- if (material == null) {
- map.put("msg", "500");
- map.put("errMsg", "物料信息未录入,请联系管理员");
- return map;
- }
- Map<String, Object> 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<StorageLocation> list = warehousingMapper.recommend(stringBuffer.toString());
- map.put("data", list);
- map.put("msg", "210");
- return map;
- }
- }
- }
- //查询产成品库位
- List<StorageLocation> storageLocations = storageLocationMapper.getStorage(storageLocation);
- for(StorageLocation storageLocation1 : storageLocations) {
- Inventory inventory = warehousingMapper.getInventoryInfo(storageLocation1);//查询库存信息
- if(inventory == null) {
- stringBuffer.append(storageLocation1.getStorageLocationCode() + ",");
- break;
- }
- }
- List<StorageLocation> 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<String, Object> getProductWarehousingRecommend(String uniqueCode, String type, String noticeId) {
- Map<String, Object> 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<String, Object> getHalf(Notice notice) {
- Map<String, Object> map = new HashMap<>();
- try {
- PageHelper.startPage(notice.getPage(), notice.getLimit());
- PageInfo<Notice> 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<List<Object>> sheetDataList = new ArrayList<>();
- //表头数据
- List<Object> head = Arrays.asList("物料名称", "物料编号", "生产批次", "数量", "用户名称", "库位编号", "入库时间", "连番号", "序列号", "属性", "入库单编号", "WBS","真实姓名","生产订单号","公司名称");
- //查询数据
- List<Map<String, Object>> list = warehousingMapper.getHalfExcel(notice);
- sheetDataList.add(head);
- for (Map<String, Object> userMap : list) {
- List<Object> 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<String, Object> delInventoryNotice(String id, HttpServletRequest request) {
- Map<String, Object> map = new HashMap<>();
- try {
- String userId = request.getHeader("userId");
- Map<String, Object> 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<String, Object> otherWarehousing(AskGoods askGoods) {
- Map<String, Object> map = new HashMap<>();
- try {
- //判断物料是否录入
- MaterialClass materialClass = warehousingMapper.getMateriaIsExist(askGoods.getWllbCode());
- askGoods.setMaterialId(materialClass.getTldId());
- //查询库存
- List<Inventory> 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<String, Object> otherWarehou(Inventory inventory, HttpServletRequest request) {
- Map<String, Object> 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<WarehousingVirtual> 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<String, Object> getMing(String code) {
- Map<String, Object> 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<String, Object> addWarehousingVirtualTwo(WarehousingVirtual warehousingVirtual) {
- Map<String, Object> map = new HashMap<>();
- try{
- Map<String, Object> 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<String, Object> addWarehouseTransferVirtual(WarehousingVirtual warehousingVirtual) {
- Map<String, Object> map = new HashMap<>();
- try{
- Map<String, Object> 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();
- }
- }
|