package com.steerinfo.dil.service.impl; import com.alibaba.fastjson.JSONObject; import com.steerinfo.dil.feign.DzFeign; import com.steerinfo.dil.feign.WmsFeign; import com.steerinfo.dil.mapper.*; import com.steerinfo.dil.model.*; import com.steerinfo.dil.util.DaZongUtil; import com.steerinfo.dil.util.DataChange; import com.steerinfo.dil.util.EntityDispose; import com.steerinfo.framework.controller.RESTfulResult; import com.steerinfo.framework.mapper.IBaseMapper; import com.steerinfo.framework.service.impl.BaseServiceImpl; import org.apache.log4j.Logger; import org.checkerframework.checker.units.qual.A; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Required; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; import org.springframework.web.bind.annotation.RequestParam; import java.text.DateFormat; import java.text.SimpleDateFormat; import java.util.*; import java.math.BigDecimal; import java.util.concurrent.*; /** * TmsWeightResult服务实现: * @author generator * @version 1.0-SNAPSHORT 2023-10-30 10:06 * 类描述 * 修订历史: * 日期:2023-10-30 * 作者:generator * 参考: * 描述:TmsWeightResult服务实现 * @see null * @Copyright 湖南视拓信息技术股份有限公司. All rights reserved. */ @Service(value = "tmsWeightResultService") public class TmsWeightResultServiceImpl { static final Logger log = Logger.getLogger(TmsWeightResultServiceImpl.class); @Autowired private TmsWeightResultMapper tmsWeightResultMapper; @Autowired OmsTransOrderServiceImpl omsTransOrderService; @Autowired private OmsTransOrderMapper omsTransOrderMapper; @Autowired private RmsOperationPointMapper rmsOperationPointMapper; @Autowired private AmsTransPlanMapper amsTransPlanMapper; @Autowired private AmsPlanChildMapper amsPlanChildMapper; @Autowired private OmsOrderChildMapper omsOrderChildMapper; @Autowired OmsOrderChildServiceImpl omsOrderChildService; @Autowired private WmsFeign wmsFeign; @Autowired EntityDispose entityDispose; @Autowired DaZongUtil daZongUtil; @Autowired DzFeign dzFeign; DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); @Transactional(rollbackFor = Exception.class) public String syncWeightResult(Map map) throws Exception { JSONObject jsonObject = new JSONObject(map); //查询运输订单 List transOrderIds = omsTransOrderMapper.getTransOrderIdByNumber(map); if(transOrderIds.size() != 1){ omsTransOrderService.reGenerateTransOrder(map); throw new Exception("运输订单异常!不能同步!"); } //物资分录 BigDecimal transOrderChildId = DataChange.dataToBigDecimal(map.get("transOrderChildId").toString()); //查询运输订单下的计量实绩 Map searchMap = new HashMap<>(); searchMap.put("transOrderId",transOrderIds.get(0)); searchMap.put("deleted",0); Map transOrder = omsTransOrderMapper.getTransOrder(searchMap); List list = tmsWeightResultMapper.selectByParametersSt(searchMap); log.debug(list.toString()); String poundNo = map.get("poundNo").toString(); String weightBz = DataChange.getString(map.get("weightBz")); String url = map.get("url") == null ? "" : map.get("url").toString(); if("新增".equals(map.get("operationType"))){ // 判断该运单子表是否有净重 List netWeightIds = tmsWeightResultMapper.selectNetWeightId(transOrderChildId); if (netWeightIds.size() > 0 && netWeightIds.get(0) != null) { return "该运单子实绩已有净重"; } //根据运单获取运单子表的数量 //if(tmsWeightResultMapper.getTransOrderChildNotWeight(transOrderIds.get(0),transOrderChildId).size() < 1) { // //如果实绩ID是运单子表数量的两倍,则说明存在复磅的情况 // List transOrderChildIds = tmsWeightResultMapper.getTransOrderChildId(transOrderIds.get(0)); // if(transOrderChildIds.size() == 1 && transOrderChildIds.get(0) != null) { // }else{ // throw new Exception("该分录不可用,请检查是否正确。"); // } //} if(map.get("tarePointName")!=null && !"".equals(map.get("tarePointName").toString())){ BigDecimal tarePlaceId = omsTransOrderMapper.getOperationPointId(map.get("tarePointName").toString(), "" + map.get("tarePointCode")); if(tarePlaceId == null){ //没有就新增 tarePlaceId = rmsOperationPointMapper.nextPlaceId(); RmsOperationPoint rmsOperationPoint = new RmsOperationPoint(); rmsOperationPoint.setOperationPointId(tarePlaceId); rmsOperationPoint.setOperationPointName(map.get("tarePointName").toString()); rmsOperationPoint.setOperationPointCode(map.get("tarePointCode").toString()); rmsOperationPoint.setOperationPointType("汽车衡"); rmsOperationPoint.setOperationPointStatus("正常"); rmsOperationPoint.setRemark("自动新增"); rmsOperationPoint.setDeleted(0); rmsOperationPointMapper.insertSelective(rmsOperationPoint); } BigDecimal tareWeight = DataChange.dataToBigDecimal(map.get("tareWeight").toString()); Date tareWeightTime = DataChange.dataToDate(map.get("tareWeightTime").toString()); String actualWeight = map.get("actualWeight") == null ? "0" : map.get("actualWeight").toString(); //皮重 for(int i =0;i 0){ item.setNetWeight(netWeight); }else{ item.setNetWeight(item.getGrossWeight().subtract(item.getTareWeight())); } item.setAlternateFields13(bzw.toString()); item.setNetWeightTime(tareWeightTime); if("是".equals(transOrder.get("isMultiple"))){ try { //查询运单 OmsTransOrder omsTransOrder = omsTransOrderMapper.selectByPrimaryKey(transOrderIds.get(0)); List omsOrderChildList = omsOrderChildMapper.selectByParameters(searchMap); Map objectObjectHashMap = new HashMap<>(); BigDecimal nineTransOrderId = null; if("销售".equals(omsTransOrder.getBusinessScene())) { //查询有没有采购状态为9的运单 objectObjectHashMap.put("scene","采购"); objectObjectHashMap.put("capacityId",omsTransOrder.getCapacityId()); objectObjectHashMap.put("driverId",omsTransOrder.getDriverId()); objectObjectHashMap.put("materialId",omsOrderChildList.get(0).getMaterialId()); nineTransOrderId = omsTransOrderMapper.getNineTransOrder(objectObjectHashMap); }else{ //查询有没有销售状态为9的运单 objectObjectHashMap.put("scene","销售"); objectObjectHashMap.put("capacityId",omsTransOrder.getCapacityId()); objectObjectHashMap.put("driverId",omsTransOrder.getDriverId()); objectObjectHashMap.put("materialId",omsOrderChildList.get(0).getMaterialId()); nineTransOrderId = omsTransOrderMapper.getNineTransOrder(objectObjectHashMap); } if(nineTransOrderId != null) { omsTransOrderMapper.updateNineOrder(nineTransOrderId); } } catch (Exception e) { e.printStackTrace(); } //判断是否一车多趟 try{ omsTransOrderService.reDispatchOrder(transOrderIds.get(0)); }catch (Exception e){ e.printStackTrace(); log.error("一车多趟重复派车失败:"+e.getMessage()); } } //迁移库存 transGridMaterial(transOrderChildId,item.getNetWeight(),""+map.get("userId"),""+map.get("userName"),item.getNetWeightTime()); } if("9".equals(weightBz)){ //冲减,净重为0 item.setNetWeight(BigDecimal.ZERO); } tmsWeightResultMapper.updateByPrimaryKeySelective(item); if(item.getNetWeightTime() != null) { omsTransOrderService.updateOrderStatus(transOrderIds.get(0),item.getTareSegmentSqe(),"出厂",item.getUpdateUsername(),item.getPoundNo()); }else{ omsTransOrderService.updateOrderStatus(transOrderIds.get(0),item.getTareSegmentSqe(),"计皮",item.getUpdateUsername(),item.getPoundNo()); } omsOrderChildService.updateOrderChildInfo(transOrderIds.get(0),item.getTransOrderChildId(),item.getTareWeightTime(),"计皮"); omsOrderChildService.updateOrderChildInfo(transOrderIds.get(0),item.getTransOrderChildId(),item.getNetWeightTime(),"净重"); OmsOrderChild omsOrderChild = omsOrderChildMapper.selectByPrimaryKey(transOrderChildId); omsOrderChild.setNetWeight(item.getNetWeight()); omsOrderChild.setActualWeight(DataChange.dataToBigDecimal(item.getAlternateFields11()).compareTo(BigDecimal.ZERO) == 0 ? item.getNetWeight() : DataChange.dataToBigDecimal(item.getAlternateFields11())); omsOrderChildMapper.updateByPrimaryKeySelective(omsOrderChild); map.put("resultId",item.getResultId());//返回给日志记录 threadPool.execute(()->{ try { Thread.sleep(500); AmsPlanChild amsPlanChild = amsPlanChildMapper.selectByPrimaryKey(omsOrderChild.getPlanChildId()); omsTransOrderService.sumWeight(amsPlanChild.getRequirementChildId()); omsTransOrderService.sumWeightPlan(amsPlanChild.getPlanChildId()); } catch (InterruptedException e) { e.printStackTrace(); } }); return "同步成功!"; } } }else if(map.get("grossPointName")!=null && !"".equals(map.get("grossPointName").toString())){ BigDecimal grossPlaceId = omsTransOrderMapper.getOperationPointId(map.get("grossPointName").toString(), "" + map.get("grossPointCode")); if(grossPlaceId == null){ //没有就新增 grossPlaceId = rmsOperationPointMapper.nextPlaceId(); RmsOperationPoint rmsOperationPoint = new RmsOperationPoint(); rmsOperationPoint.setOperationPointId(grossPlaceId); rmsOperationPoint.setOperationPointName(map.get("grossPointName").toString()); rmsOperationPoint.setOperationPointCode(map.get("grossPointCode").toString()); rmsOperationPoint.setOperationPointType("汽车衡"); rmsOperationPoint.setOperationPointStatus("正常"); rmsOperationPoint.setRemark("自动新增"); rmsOperationPoint.setDeleted(0); rmsOperationPointMapper.insertSelective(rmsOperationPoint); } BigDecimal grossWeight = DataChange.dataToBigDecimal(map.get("grossWeight").toString()); Date grossWeightTime = DataChange.dataToDate(map.get("grossWeightTime").toString()); String actualWeight = map.get("actualWeight") == null ? "0" : map.get("actualWeight").toString(); //毛重 for(int i =0;i 0){ item.setNetWeight(netWeight); }else{ item.setNetWeight(item.getGrossWeight().subtract(item.getTareWeight())); } item.setAlternateFields13(bzw.toString()); item.setNetWeightTime(grossWeightTime); //迁移库存 transGridMaterial(transOrderChildId,item.getNetWeight(),""+map.get("userId"),""+map.get("userName"),item.getNetWeightTime()); if("是".equals(transOrder.get("isMultiple"))){ try { //查询运单 OmsTransOrder omsTransOrder = omsTransOrderMapper.selectByPrimaryKey(transOrderIds.get(0)); List omsOrderChildList = omsOrderChildMapper.selectByParameters(searchMap); Map objectObjectHashMap = new HashMap<>(); BigDecimal nineTransOrderId = null; if("销售".equals(omsTransOrder.getBusinessScene())) { //查询有没有采购状态为9的运单 objectObjectHashMap.put("scene","采购"); objectObjectHashMap.put("capacityId",omsTransOrder.getCapacityId()); objectObjectHashMap.put("driverId",omsTransOrder.getDriverId()); objectObjectHashMap.put("materialId",omsOrderChildList.get(0).getMaterialId()); nineTransOrderId = omsTransOrderMapper.getNineTransOrder(objectObjectHashMap); }else{ //查询有没有销售状态为9的运单 objectObjectHashMap.put("scene","销售"); objectObjectHashMap.put("capacityId",omsTransOrder.getCapacityId()); objectObjectHashMap.put("driverId",omsTransOrder.getDriverId()); objectObjectHashMap.put("materialId",omsOrderChildList.get(0).getMaterialId()); nineTransOrderId = omsTransOrderMapper.getNineTransOrder(objectObjectHashMap); } if(nineTransOrderId != null) { omsTransOrderMapper.updateNineOrder(nineTransOrderId); } } catch (Exception e) { e.printStackTrace(); } //判断是否一车多趟 try{ omsTransOrderService.reDispatchOrder(transOrderIds.get(0)); }catch (Exception e){ e.printStackTrace(); log.error("一车多趟重复派车失败:"+e.getMessage()); } } //判断是否还有下一拼,有则提前设置皮重信息 // if(i != list.size()-1){ // list.get(i+1).setTarePlaceId(grossPlaceId); // list.get(i+1).setTareWeight(grossWeight); // list.get(i+1).setTareWeightTime(grossWeightTime); //// list.get(i+1).setUpdateUsername(map.get("userName").toString()); //// list.get(i+1).setUpdateTime(new Date()); // tmsWeightResultMapper.updateByPrimaryKeySelective(list.get(i+1)); // } } if("9".equals(weightBz)){ //冲减,净重为0 item.setNetWeight(BigDecimal.ZERO); } tmsWeightResultMapper.updateByPrimaryKeySelective(item); if(item.getNetWeightTime() != null) { omsTransOrderService.updateOrderStatus(transOrderIds.get(0),item.getTareSegmentSqe(),"出厂",item.getUpdateUsername(),item.getPoundNo()); }else{ omsTransOrderService.updateOrderStatus(transOrderIds.get(0),item.getTareSegmentSqe(),"计毛",item.getUpdateUsername(),item.getPoundNo()); } omsOrderChildService.updateOrderChildInfo(transOrderIds.get(0),item.getTransOrderChildId(),item.getGrossWeightTime(),"计毛"); omsOrderChildService.updateOrderChildInfo(transOrderIds.get(0),item.getTransOrderChildId(),item.getNetWeightTime(),"净重"); OmsOrderChild omsOrderChild = omsOrderChildMapper.selectByPrimaryKey(transOrderChildId); omsOrderChild.setNetWeight(item.getNetWeight()); omsOrderChild.setActualWeight(DataChange.dataToBigDecimal(item.getAlternateFields11()).compareTo(BigDecimal.ZERO) == 0 ? item.getNetWeight() : DataChange.dataToBigDecimal(item.getAlternateFields11())); omsOrderChildMapper.updateByPrimaryKeySelective(omsOrderChild); map.put("resultId",item.getResultId());//返回给日志记录 threadPool.execute(()->{ try { Thread.sleep(500); AmsPlanChild amsPlanChild = amsPlanChildMapper.selectByPrimaryKey(omsOrderChild.getPlanChildId()); omsTransOrderService.sumWeight(amsPlanChild.getRequirementChildId()); omsTransOrderService.sumWeightPlan(amsPlanChild.getPlanChildId()); } catch (InterruptedException e) { e.printStackTrace(); } }); return "同步成功!"; } } }else { throw new Exception("tarePointName或grossPointName不能为空!"); } }else if ("修改".equals(map.get("operationType"))){ if(map.get("tarePointName")!=null && !"".equals(map.get("tarePointName").toString())){ BigDecimal tarePlaceId = omsTransOrderMapper.getOperationPointId(map.get("tarePointName").toString(), "" + map.get("tarePointCode")); if(tarePlaceId == null){ //没有就新增 tarePlaceId = rmsOperationPointMapper.nextPlaceId(); RmsOperationPoint rmsOperationPoint = new RmsOperationPoint(); rmsOperationPoint.setOperationPointId(tarePlaceId); rmsOperationPoint.setOperationPointName(map.get("tarePointName").toString()); rmsOperationPoint.setOperationPointCode(map.get("tarePointCode").toString()); rmsOperationPoint.setOperationPointType("汽车衡"); rmsOperationPoint.setOperationPointStatus("正常"); rmsOperationPoint.setRemark("自动新增"); rmsOperationPoint.setDeleted(0); rmsOperationPointMapper.insertSelective(rmsOperationPoint); } BigDecimal tareWeight = DataChange.dataToBigDecimal(map.get("tareWeight").toString()); Date tareWeightTime = DataChange.dataToDate(map.get("tareWeightTime").toString()); String actualWeight = map.get("actualWeight") == null ? "0" : map.get("actualWeight").toString(); //皮重 for(int i =0;i 0){ item.setNetWeight(netWeight); }else{ item.setNetWeight(item.getGrossWeight().subtract(item.getTareWeight())); } item.setAlternateFields13(bzw.toString()); item.setNetWeightTime(tareWeightTime); //迁移库存 transGridMaterial(transOrderChildId,item.getNetWeight(),""+map.get("userId"),""+map.get("userName"),item.getNetWeightTime()); } if("9".equals(weightBz)){ //冲减,净重为0 item.setNetWeight(BigDecimal.ZERO); } tmsWeightResultMapper.updateByPrimaryKeySelective(item); OmsOrderChild omsOrderChild = omsOrderChildMapper.selectByPrimaryKey(transOrderChildId); omsOrderChild.setNetWeight(item.getNetWeight()); omsOrderChild.setActualWeight(DataChange.dataToBigDecimal(item.getAlternateFields11()).compareTo(BigDecimal.ZERO) == 0 ? item.getNetWeight() : DataChange.dataToBigDecimal(item.getAlternateFields11())); omsOrderChildMapper.updateByPrimaryKeySelective(omsOrderChild); map.put("resultId",item.getResultId());//返回给日志记录 try{ if(item.getNetWeightTime() != null) { omsTransOrderService.updateOrderStatus(transOrderIds.get(0),item.getTareSegmentSqe(),"出厂",item.getUpdateUsername(),item.getPoundNo()); }else{ omsTransOrderService.updateOrderStatus(transOrderIds.get(0),item.getTareSegmentSqe(),"计皮",item.getUpdateUsername(),item.getPoundNo()); } omsOrderChildService.updateOrderChildInfo(transOrderIds.get(0),item.getTransOrderChildId(),item.getTareWeightTime(),"计皮"); omsOrderChildService.updateOrderChildInfo(transOrderIds.get(0),item.getTransOrderChildId(),item.getNetWeightTime(),"净重"); }catch (Exception e){} threadPool.execute(()->{ try { Thread.sleep(500); AmsPlanChild amsPlanChild = amsPlanChildMapper.selectByPrimaryKey(omsOrderChild.getPlanChildId()); omsTransOrderService.sumWeight(amsPlanChild.getRequirementChildId()); omsTransOrderService.sumWeightPlan(amsPlanChild.getPlanChildId()); } catch (InterruptedException e) { e.printStackTrace(); } }); return "同步成功!"; } } }else if(map.get("grossPointName")!=null && !"".equals(map.get("grossPointName").toString())){ BigDecimal grossPlaceId = omsTransOrderMapper.getOperationPointId(map.get("grossPointName").toString(), "" + map.get("grossPointCode")); if(grossPlaceId == null){ //没有就新增 grossPlaceId = rmsOperationPointMapper.nextPlaceId(); RmsOperationPoint rmsOperationPoint = new RmsOperationPoint(); rmsOperationPoint.setOperationPointId(grossPlaceId); rmsOperationPoint.setOperationPointName(map.get("grossPointName").toString()); rmsOperationPoint.setOperationPointCode(map.get("grossPointCode").toString()); rmsOperationPoint.setOperationPointType("汽车衡"); rmsOperationPoint.setOperationPointStatus("正常"); rmsOperationPoint.setRemark("自动新增"); rmsOperationPoint.setDeleted(0); rmsOperationPointMapper.insertSelective(rmsOperationPoint); } BigDecimal grossWeight = DataChange.dataToBigDecimal(map.get("grossWeight").toString()); Date grossWeightTime = DataChange.dataToDate(map.get("grossWeightTime").toString()); String actualWeight = map.get("actualWeight") == null ? "0" : map.get("actualWeight").toString(); //毛重 for(int i =0;i 0){ item.setNetWeight(netWeight); }else{ item.setNetWeight(item.getGrossWeight().subtract(item.getTareWeight())); } item.setAlternateFields13(bzw.toString()); item.setNetWeightTime(grossWeightTime); //迁移库存 transGridMaterial(transOrderChildId,item.getNetWeight(),""+map.get("userId"),""+map.get("userName"),item.getNetWeightTime()); ////判断是否还有下一拼,有则提前设置皮重信息 //if(i != list.size()-1){ // list.get(i+1).setTarePlaceId(grossPlaceId); // list.get(i+1).setTareWeight(grossWeight); // list.get(i+1).setTareWeightTime(grossWeightTime); // list.get(i+1).setUpdateUsername(map.get("userId").toString()); // list.get(i+1).setUpdateTime(new Date()); // tmsWeightResultMapper.updateByPrimaryKeySelective(list.get(i+1)); //} } if("9".equals(weightBz)){ //冲减,净重为0 item.setNetWeight(BigDecimal.ZERO); } tmsWeightResultMapper.updateByPrimaryKeySelective(item); OmsOrderChild omsOrderChild = omsOrderChildMapper.selectByPrimaryKey(transOrderChildId); omsOrderChild.setNetWeight(item.getNetWeight()); omsOrderChild.setActualWeight(DataChange.dataToBigDecimal(item.getAlternateFields11()).compareTo(BigDecimal.ZERO) == 0 ? item.getNetWeight() : DataChange.dataToBigDecimal(item.getAlternateFields11())); omsOrderChildMapper.updateByPrimaryKeySelective(omsOrderChild); map.put("resultId",item.getResultId());//返回给日志记录 try{ if(item.getNetWeightTime() != null) { omsTransOrderService.updateOrderStatus(transOrderIds.get(0),item.getTareSegmentSqe(),"出厂",item.getUpdateUsername(),item.getPoundNo()); }else{ omsTransOrderService.updateOrderStatus(transOrderIds.get(0),item.getTareSegmentSqe(),"计毛",item.getUpdateUsername(),item.getPoundNo()); } omsOrderChildService.updateOrderChildInfo(transOrderIds.get(0),item.getTransOrderChildId(),item.getGrossWeightTime(),"计毛"); omsOrderChildService.updateOrderChildInfo(transOrderIds.get(0),item.getTransOrderChildId(),item.getNetWeightTime(),"净重"); }catch (Exception e){} threadPool.execute(()->{ try { Thread.sleep(500); AmsPlanChild amsPlanChild = amsPlanChildMapper.selectByPrimaryKey(omsOrderChild.getPlanChildId()); omsTransOrderService.sumWeight(amsPlanChild.getRequirementChildId()); omsTransOrderService.sumWeightPlan(amsPlanChild.getPlanChildId()); } catch (InterruptedException e) { e.printStackTrace(); } }); return "同步成功!"; } } }else{ throw new Exception("tarePointName或grossPointName不能为空!"); } }else{ throw new Exception("未知的操作类型:"+map.get("operationType")); } return "同步成功!实绩已存在!"; } public List> getWeightResultList(Map map) { return tmsWeightResultMapper.getTmsWeightResultList(map); } public List> purchaseTrainWeightList(Map map) { return tmsWeightResultMapper.purchaseTrainWeightList(map); } public String purchaseTrainWeight(Map map) throws Exception { List> orderList = (ArrayList) map.get("orderList"); if(orderList.size() < 1){ throw new Exception("没有数据!无法计量!"); } DateFormat format = new SimpleDateFormat("yyyyMMdd"); DateFormat format2 = new SimpleDateFormat("yyyy-MM-dd"); String userId ="" + map.get("userId"); String userName ="" + map.get("userName"); List insertList = new ArrayList<>();//新增数组 List updateList = new ArrayList<>();//更新数组 List> paramList = new ArrayList<>();//推送大宗数据 //遍历,有实绩的修改,无实绩的新增 for(Map item :orderList){ BigDecimal resultId = DataChange.dataToBigDecimal(item.get("resultId")); BigDecimal transOrderId = DataChange.dataToBigDecimal(item.get("transOrderId")); BigDecimal transOrderChildId = DataChange.dataToBigDecimal(item.get("transOrderChildId")); BigDecimal netWeight = DataChange.dataToBigDecimal(item.get("netWeight")); BigDecimal tareWeight = DataChange.dataToBigDecimal(item.get("tareWeight")); BigDecimal grossWeight = DataChange.dataToBigDecimal(item.get("grossWeight")); Date weightTime = format.parse(item.get("weightTime").toString()); String requireNumber = item.get("requireNumber").toString(); String poundNo = item.get("poundNo").toString(); String trainSeq = item.get("trainSeq").toString(); String capacityId = item.get("capacityId").toString(); Date loadTime = format.parse(item.get("loadTime").toString()); String sendStation = item.get("sendStation").toString(); String endStation = item.get("endStation").toString(); String tdls = item.get("tdls").toString(); String tdfl = item.get("tdfl").toString(); if(resultId.compareTo(BigDecimal.ZERO) == 0){ //新增 TmsWeightResult tmsWeightResult = new TmsWeightResult(); tmsWeightResult.setResultId(tmsWeightResultMapper.nextId()); tmsWeightResult.setTransOrderId(transOrderId); tmsWeightResult.setTransOrderChildId(transOrderChildId); tmsWeightResult.setPoundNo(poundNo); tmsWeightResult.setNetWeight(netWeight); tmsWeightResult.setTareWeight(tareWeight); tmsWeightResult.setGrossWeight(grossWeight); tmsWeightResult.setNetWeightTime(weightTime); tmsWeightResult.setDeleted(BigDecimal.ZERO); tmsWeightResult.setInsertTime(new Date()); tmsWeightResult.setInsertUsername(userId); insertList.add(tmsWeightResult); //大宗新增 Map params =new HashMap<>(); params.put("ywlx",0);//0 -收货 1-发货 params.put("czbz",1);//1-新增 2-修改 3-删除 params.put("djbh",tmsWeightResult.getPoundNo()); params.put("hccc",trainSeq); params.put("clbh",capacityId); params.put("cllx",""); params.put("gbsj",format2.format(weightTime)); params.put("sfsj",format2.format(loadTime)); params.put("fhdd",sendStation); params.put("shdd",endStation); params.put("mz",tmsWeightResult.getGrossWeight()); params.put("pz",tmsWeightResult.getTareWeight()); params.put("jz",tmsWeightResult.getNetWeight()); params.put("tzdh",requireNumber); params.put("tdls",tdls); params.put("tdfl",tdfl); params.put("username",userName); params.put("note",""); paramList.add(params); }else{ //修改 TmsWeightResult tmsWeightResult = tmsWeightResultMapper.selectByPrimaryKey(resultId); tmsWeightResult.setNetWeight(netWeight); tmsWeightResult.setTareWeight(tareWeight); tmsWeightResult.setGrossWeight(grossWeight); tmsWeightResult.setUpdateTime(new Date()); tmsWeightResult.setUpdateUsername(userId); updateList.add(tmsWeightResult); //大宗修改 Map params =new HashMap<>(); params.put("ywlx",0);//0 -收货 1-发货 params.put("czbz",2);//1-新增 2-修改 3-删除 params.put("djbh",tmsWeightResult.getPoundNo()); params.put("hccc",trainSeq); params.put("clbh",capacityId); params.put("cllx",""); params.put("gbsj",format2.format(weightTime)); params.put("sfsj",format2.format(loadTime)); params.put("fhdd",sendStation); params.put("shdd",endStation); params.put("mz",tmsWeightResult.getGrossWeight()); params.put("pz",tmsWeightResult.getTareWeight()); params.put("jz",tmsWeightResult.getNetWeight()); params.put("tzdh",requireNumber); params.put("tdls",tdls); params.put("tdfl",tdfl); params.put("username",userName); params.put("note",""); paramList.add(params); } } //数据更新之前先修改入库(自动更新库存) // Map inboundMap = new HashMap<>(); // inboundMap.put("transPlanId",map.get("transPlanId")); // inboundMap.put("inboundNumber",map.get("weight")); // inboundMap.put("gridName","原料在途库"); // inboundMap.put("materialId",map.get("materialId")); // inboundMap.put("userId",userId); // inboundMap.put("userName",userName); // RESTfulResult inbountResult = wmsFeign.updateInbound(inboundMap); // if(!"succeed".equals(inbountResult.getStatus())){ // throw new Exception(inbountResult.getMessage()); // } if(insertList.size() > 0){ tmsWeightResultMapper.batchInsert(insertList); } if(updateList.size() > 0){ tmsWeightResultMapper.batchUpdate(updateList); } //推送大宗 // Map[] paramArray = paramList.toArray(new Map[paramList.size()]); // daZongUtil.execute("30010000060", paramArray); return "上传成功!"; } public String checkWeightResult(Map map) throws Exception { //初始化 List> list = (List) map.get("list"); List tmsWeightResults = new ArrayList<>(); String checkStr = map.get("checkStr").toString(); List poundNoList = new ArrayList<>();//磅单数组 //校验并赋值 for(Map item : list){ TmsWeightResult tmsWeightResult = tmsWeightResultMapper.selectByPrimaryKey(DataChange.dataToBigDecimal(item.get("resultId"))); if(checkStr.contains("已审核")){ tmsWeightResult.setAlternateFields3("已审核"); }else{ tmsWeightResult.setAlternateFields3("已弃审"); } tmsWeightResult.setAlternateFields4(map.get("userName").toString()); tmsWeightResult.setAlternateFields5(dateFormat.format(new Date())); tmsWeightResults.add(tmsWeightResult); poundNoList.add(tmsWeightResult.getPoundNo()); } map.put("poundNoList",poundNoList); //批量更新 if(tmsWeightResults.size() > 0){ tmsWeightResultMapper.batchUpdate(tmsWeightResults); //推送大宗 if(checkStr.contains("已审核")){ dzFeign.updWeightStatus(map); } return "操作成功:"+checkStr; }else{ return "没有能审批的数据!"; } } //根据运单id返回过磅重量到通知单 public void netWeightToRequirement(BigDecimal transOrderId, BigDecimal netWeight) { //根据运单id获取通知单 //omsTransOrderMapper.select } //补单,生成计量实绩与子表实绩 @Transactional(rollbackFor = Exception.class) public List> addOrderWeight(Map map) { List> mapList = new ArrayList<>(); if(!map.containsKey("gross")) { mapList.add(map); return mapList; } List> grossList = (List>) map.get("gross"); if(grossList.size() == 0) { mapList.add(map); return mapList; } //根据运单子表Id,查询计划子表ID,需求子表ID BigDecimal transOrderChildId = DataChange.dataToBigDecimal(map.get("transOrderChildId")); Map mesInfo = tmsWeightResultMapper.selectMesInfo(transOrderChildId); BigDecimal transPlanId = DataChange.dataToBigDecimal(mesInfo.get("transPlanId")); BigDecimal planChildId = DataChange.dataToBigDecimal(mesInfo.get("planChildId")); BigDecimal requirementChildId = DataChange.dataToBigDecimal(mesInfo.get("requirementChildId")); Map firstWeightMap = new HashMap<>(); Map secondTareWeightMap = new HashMap<>(); Map secondGrossWeightMap = new HashMap<>(); for (Map stringObjectMap : grossList) { Map weightMap = new HashMap<>(); String tdls = stringObjectMap.get("tdls").toString(); String tdfl = stringObjectMap.get("tdfl").toString(); // 防止该通知单数据来自大宗,去查一遍 BigDecimal stTdfl = tmsWeightResultMapper.selectStTdfl(tdls,tdfl); BigDecimal mz = DataChange.dataToBigDecimal(stringObjectMap.get("mz")); BigDecimal jz = DataChange.dataToBigDecimal(stringObjectMap.get("netWeight")); BigDecimal bzw = DataChange.dataToBigDecimal(stringObjectMap.get("bzw")); if (requirementChildId.compareTo(stTdfl) == 0) { weightMap.putAll(map); weightMap.remove("gross"); weightMap.put("grossWeight",mz); weightMap.put("netWeight",jz); weightMap.put("bzw",bzw); firstWeightMap.putAll(weightMap); //mapList.add(weightMap); continue; } //根据sttdfl去寻找计划子表与计划 BigDecimal newPlanChildId = amsPlanChildMapper.selectPlanChildId(stTdfl); AmsPlanChild amsPlanChild = new AmsPlanChild(); if (newPlanChildId == null) { //需要补录计划表、计划子表、运单子表 AmsTransPlan amsTransPlan = amsTransPlanMapper.selectByPrimaryKey(transPlanId); amsTransPlan.setTransPlanId(amsTransPlanMapper.nextId()); amsTransPlan.setInsertTime(new Date()); amsTransPlanMapper.insertSelective(amsTransPlan); amsPlanChild = amsPlanChildMapper.selectByPrimaryKey(planChildId); amsPlanChild.setPlanChildId(amsPlanChildMapper.nextId()); amsPlanChild.setTransPlanId(amsTransPlan.getTransPlanId()); amsPlanChild.setRequirementChildId(stTdfl); amsPlanChild.setInsertTime(new Date()); // 查询通知单数量 BigDecimal stTdflMaterialWeight = amsPlanChildMapper.selectMaterialWeight(stTdfl); amsPlanChild.setMaterialNumber(stTdflMaterialWeight); //修改通知单状态 amsPlanChildMapper.updateRequirementStatus(stTdfl); amsPlanChildMapper.insertSelective(amsPlanChild); }else { amsPlanChild = amsPlanChildMapper.selectByPrimaryKey(newPlanChildId); } //运单子表 OmsOrderChild omsOrderChild = omsOrderChildMapper.selectByPrimaryKey(transOrderChildId); // 根据运单id去找下面有没有补单的 BigDecimal newOrderChildId = omsOrderChildMapper.selectNewOrderChildId(omsOrderChild.getTransOrderId()); if (newOrderChildId == null) { omsOrderChild.setOrderChildId(omsOrderChildMapper.nextId()); omsOrderChild.setPlanChildId(amsPlanChild.getPlanChildId()); omsOrderChild.setMaterialNumber(new BigDecimal(0)); omsOrderChild.setInsertUpdateRemark("补单自动生成运单子表"); omsOrderChild.setAlternateFields7("0"); entityDispose.disposeOrderChild(omsOrderChild); omsOrderChildMapper.insertSelective(omsOrderChild); }else{ omsOrderChild.setOrderChildId(newOrderChildId); omsOrderChild.setPlanChildId(amsPlanChild.getPlanChildId()); omsOrderChild.setMaterialNumber(new BigDecimal(0)); omsOrderChild.setInsertUpdateRemark("补单自动生成运单子表"); omsOrderChild.setAlternateFields7("0"); omsOrderChildMapper.updateByPrimaryKeySelective(omsOrderChild); } //生成计量实绩皮重报文 Map tareWeightMap = tmsWeightResultMapper.selectTareWeightMap(omsOrderChild.getTransOrderId()); if (tareWeightMap != null) { tareWeightMap.put("operationType",map.get("operationType")); tareWeightMap.put("transOrderNumber",map.get("transOrderNumber")); tareWeightMap.put("transOrderChildId",omsOrderChild.getOrderChildId()); secondTareWeightMap.putAll(tareWeightMap); //mapList.add(tareWeightMap); } //生成计量实绩毛重报文 weightMap.putAll(map); weightMap.remove("gross"); weightMap.put("grossWeight",mz); weightMap.put("netWeight",jz); weightMap.put("bzw",bzw); weightMap.put("transOrderChildId",omsOrderChild.getOrderChildId()); secondGrossWeightMap.putAll(weightMap); //mapList.add(weightMap); } mapList.add(firstWeightMap); if(secondTareWeightMap.get("transOrderChildId") != null) { mapList.add(secondTareWeightMap); } if(secondGrossWeightMap.get("transOrderChildId") != null) { mapList.add(secondGrossWeightMap); } return mapList; } /** * 迁移库存 * @param transOrderChildId * @param netWeight * @param userId * @param userName */ public void transGridMaterial(BigDecimal transOrderChildId,BigDecimal netWeight,String userId,String userName,@RequestParam(required = false) Date netWeightTime) { return; // try{ // Map boundResult = tmsWeightResultMapper.getBoundResult(transOrderChildId); // String businessScene = boundResult.get("businessScene").toString(); // BigDecimal loadPointId = DataChange.dataToBigDecimal(boundResult.get("loadPointId")); // BigDecimal unloadPointId = DataChange.dataToBigDecimal(boundResult.get("unloadPointId")); // switch (businessScene){ // case "采购": // //汽车入厂,不入库厂内,出库在途; // //boundResult.put("gridId",boundResult.get("unloadPointId")); // //boundResult.put("inboundNumber",netWeight); // //boundResult.put("inboundType","采购汽运计量入库"); // //boundResult.put("inboundTime",netWeightTime); // //boundResult.put("model","汽运"); // //boundResult.put("userId",userId); // //boundResult.put("userName",userName); // //RESTfulResult inbountResult = wmsFeign.inbound(boundResult); // //if(!"succeed".equals(inbountResult.getStatus())){ // // throw new Exception(inbountResult.getMessage()); // //} // boundResult.put("gridId",boundResult.get("loadPointId")); // boundResult.put("outboundNumber",netWeight); // boundResult.put("outboundType","采购汽运在途出库"); // boundResult.put("userId",userId); // boundResult.put("cgjh","原料在途库"); // boundResult.put("model","汽运"); // boundResult.put("userName",userName); // boundResult.put("outboundTime",netWeightTime); // RESTfulResult outbountResult = wmsFeign.outbound(boundResult); // if(!"succeed".equals(outbountResult.getStatus())){ // throw new Exception(outbountResult.getMessage()); // } // break; // case "销售": // //boundResult.put("gridId",boundResult.get("loadPointId")); // //boundResult.put("outboundNumber",netWeight); // //boundResult.put("outboundType","销售汽运计量出库"); // //boundResult.put("userId",userId); // //boundResult.put("model","汽运"); // //boundResult.put("userName",userName); // //boundResult.put("outboundTime",netWeightTime); // //RESTfulResult outbountResult = wmsFeign.outbound(boundResult); // //if(!"succeed".equals(outbountResult.getStatus())){ // // throw new Exception(outbountResult.getMessage()); // //} // //break; // case "生产": //// if(loadPointId.compareTo(unloadPointId) == 0){ //// //装卸货点相同,则不进行迁移库存 //// return; //// } //// //先出库 //// Map outBoundMap = JSONObject.parseObject(JSONObject.toJSONString(boundResult),Map.class); //// outBoundMap.put("gridId",boundResult.get("loadPointId")); //// outBoundMap.put("outboundNumber",netWeight); //// outBoundMap.put("outboundType","生产汽运计量出库"); //// outBoundMap.put("userId",userId); //// outBoundMap.put("outboundTime",netWeightTime); //// outBoundMap.put("userName",userName); //// RESTfulResult outbountResult2 = wmsFeign.outbound(outBoundMap); ////// if(!"succeed".equals(outbountResult2.getStatus())){ ////// throw new Exception(outbountResult2.getMessage()); ////// } //// //再入库 //// Map inBoundMap = JSONObject.parseObject(JSONObject.toJSONString(boundResult),Map.class); //// inBoundMap.put("gridId",inBoundMap.get("unloadPointId")); //// inBoundMap.put("inboundNumber",netWeight); //// inBoundMap.put("inboundType","生产汽运计量入库"); //// inBoundMap.put("userId",userId); //// inBoundMap.put("userName",userName); //// inBoundMap.put("inboundTime",netWeightTime); //// RESTfulResult inbountResult2 = wmsFeign.inbound(inBoundMap); //// if(!"succeed".equals(inbountResult2.getStatus())){ //// throw new Exception(inbountResult2.getMessage()); //// } // break; // default: // throw new Exception("未知的业务类型!"); // } // }catch (Exception e){ // e.printStackTrace(); // log.error("转移库存失败:"+e.getMessage()); // } } @Transactional(rollbackFor = Exception.class) public String syncTheoryWeight(Map map) { //获取需要同步的订单编码 List> mapList = tmsWeightResultMapper.syncTheoryWeight(map); for (Map objectMap : mapList) { //获取大宗理论重量 Map dzMap = dzFeign.syncTheoryWeight(objectMap); TmsWeightResult tmsWeightResult = tmsWeightResultMapper.selectByPrimaryKey(DataChange.dataToBigDecimal(objectMap.get("resultId"))); tmsWeightResult.setAlternateFields11(dzMap.get("theoryWeight").toString()); tmsWeightResultMapper.updateByPrimaryKey(tmsWeightResult); } return "OK"; } public String buluBzwWeight() { List list = tmsWeightResultMapper.selectForBzw(); while(list.size() > 0){ Map searchMap = new HashMap<>(); searchMap.put("list",list); List> resultList = dzFeign.getTransOrderBzw(searchMap); for(Map item : resultList){ TmsWeightResult tmsWeightResult = new TmsWeightResult(); tmsWeightResult.setResultId(DataChange.dataToBigDecimal(item.get("resultId"))); tmsWeightResult.setGrossWeight(DataChange.dataToBigDecimal(item.get("grossWeight"))); tmsWeightResult.setTareWeight(DataChange.dataToBigDecimal(item.get("tareWeight"))); tmsWeightResult.setNetWeight(DataChange.dataToBigDecimal(item.get("netWeight"))); tmsWeightResult.setAlternateFields13(DataChange.dataToBigDecimal(item.get("bzw")).toString()); tmsWeightResultMapper.updateByPrimaryKeySelective(tmsWeightResult); } //继续查询,直到查不到为止 list = tmsWeightResultMapper.selectForBzw(); } return "操作成功!"; } ExecutorService threadPool = new ThreadPoolExecutor(2,5, 1L, TimeUnit.SECONDS, new LinkedBlockingQueue<>(3), Executors.defaultThreadFactory(), new ThreadPoolExecutor.AbortPolicy()); }