123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479 |
- package com.steerinfo.dil.service.impl;
- import com.steerinfo.dil.feign.QmsFeign;
- import com.steerinfo.dil.mapper.RulesMapper;
- import com.steerinfo.dil.mapper.TmstruckReceiptResultMapper;
- import com.steerinfo.dil.mapper.TmstruckWeightResultMapper;
- import com.steerinfo.dil.mapper.UtilsMapper;
- import com.steerinfo.dil.model.TmstruckReceiptResult;
- import com.steerinfo.dil.model.TmstruckWeightResult;
- import com.steerinfo.dil.service.ITmstruckWeightResultService;
- import com.steerinfo.dil.util.DataChange;
- import org.springframework.beans.factory.annotation.Autowired;
- import org.springframework.stereotype.Service;
- import org.springframework.transaction.annotation.Transactional;
- import java.math.BigDecimal;
- import java.text.DecimalFormat;
- import java.util.Date;
- import java.util.HashMap;
- import java.util.List;
- import java.util.Map;
- /**
- * TmstruckWeightResult服务实现:
- * @author generator
- * @version 1.0-SNAPSHORT 2021-09-09 02:21
- * 类描述
- * 修订历史:
- * 日期:2021-09-09
- * 作者:generator
- * 参考:
- * 描述:TmstruckWeightResult服务实现
- * @see null
- * @Copyright 湖南视拓信息技术股份有限公司. All rights reserved.
- */
- @Service(value = "tmstruckWeightResultService")
- public class TmstruckWeightResultServiceImpl implements ITmstruckWeightResultService {
- @Autowired
- private TmstruckWeightResultMapper tmstruckWeightResultMapper;
- @Autowired
- private TmstruckReceiptResultMapper tmstruckReceiptResultMapper;
- @Autowired
- private UtilsServiceImpl utilsService;
- @Autowired
- private UtilsMapper utilsMapper;
- @Autowired
- private QmsFeign qmsFeign;
- @Autowired
- private RulesServiceImpl rulesService;
- @Autowired
- private RulesMapper rulesMapper;
- @Autowired
- private TmstruckLoadResultServiceImpl tmstruckLoadResultService;
- @Autowired
- private TmstruckLeaveFactoryResultServiceImpl tmstruckLeaveFactoryResultService;
- /**
- * 查询所有计毛实绩
- * @param map
- * @return
- */
- @Override
- public List<Map<String, Object>> getAllJiMaoResult(Map<String, Object> map) {
- Integer orderType = (Integer) map.get("orderTypee");
- switch (orderType){
- case 1:
- return tmstruckWeightResultMapper.getXSAllJiMaoResult(map); // apiID:212
- case 2:
- break;
- case 3:
- break;
- case 4:
- break;
- case 5:
- case 6:
- case 7:
- case 8:
- return tmstruckWeightResultMapper.getCGAllJiMaoResult(map);
- case 9:
- break;
- case 10:
- break;
- case 11:
- }
- return null;
- }
- /**
- * 查询所有计皮实绩
- * @param map
- * @return
- */
- @Override
- public List<Map<String, Object>> getAllJiPiResult(Map<String, Object> map) {
- Integer orderType = (Integer) map.get("orderTypee");
- switch (orderType){
- case 1:
- return tmstruckWeightResultMapper.getXSAllJiPiResult(map); //apiId:211
- case 2:
- break;
- case 3:
- break;
- case 4:
- break;
- case 5:
- case 6:
- case 7:
- case 8:
- return tmstruckWeightResultMapper.getCGAllJiPiResult(map); // apiId: 104
- case 9:
- break;
- case 10:
- break;
- case 11:
- }
- return null;
- }
- /**
- * 派单时新增计重实绩
- * 总实绩ID、计皮点、计毛点
- * @return
- */
- @Override
- public int addWeightResult(Map<String, Object> map) {
- TmstruckWeightResult tmstruckWeightResult = new TmstruckWeightResult();
- //生成最大主键ID
- tmstruckWeightResult.setWeightTaskResultId(tmstruckWeightResultMapper.selectMaxId());
- tmstruckWeightResult.setResultTotalId(DataChange.dataToBigDecimal(map.get("resultTotalId")));
- //添加是否需要扣水扣杂
- tmstruckWeightResult.setIsdeduct(DataChange.dataToBigDecimal(map.get("isdeduct")));
- // 添加物资Id (销售、内转到异地库)
- tmstruckWeightResult.setMaterialId(DataChange.dataToBigDecimal(map.get("materialId")));
- return tmstruckWeightResultMapper.insertSelective(tmstruckWeightResult);
- }
- /**
- * 更新计毛实绩 采集需要的数据
- * 运输订单号
- * 汽车衡编号
- * 物资名称
- * 毛重
- * 毛重时间
- * 磅单号
- * @return
- */
- @Override
- @Transactional
- public int addJiMaoResult(Map<String, Object> map) {
- TmstruckWeightResult tmstruckWeightResult = new TmstruckWeightResult();
- //通过物资名称和物资规格查询物资Id
- int materialId = tmstruckWeightResultMapper.getMaterialIdByMaterialNameAndSpe(map);
- map.put("materialId", materialId);
- //通过传来的运输订单号与物资ID查询计重实绩
- map.putAll(tmstruckWeightResultMapper.selectTotalIdByOrderNo(map));
- generateMaoWeightResult(map, tmstruckWeightResult);
- BigDecimal orderId = DataChange.dataToBigDecimal(map.get("orderId"));
- BigDecimal orderType = DataChange.dataToBigDecimal(map.get("orderTypee"));
- int i = 0;
- switch (orderType.intValue()){
- case 1:
- //添加第二次计量常规字段
- addUpdateRegularField(tmstruckWeightResult);
- //查询当前计毛是否为最后一拼(针对多拼) (查询是否还有装车实绩没有数据)
- List<Map<String, Object>> list = rulesMapper.judgeLastMaterial(orderId);
- if(list.size() == 0){
- //如果没有未装车的装车实绩则计算出厂门岗并更新出厂实绩
- BigDecimal resultTotalId = DataChange.dataToBigDecimal(map.get("resultTotalId"));
- //计算出厂门岗 更新出厂门岗
- int gatepostId = rulesService.calculateGatepost(map);
- i += tmstruckLeaveFactoryResultService.updateLeaveFactoryGatepostId(resultTotalId.intValue(), gatepostId);
- }else {
- //如果还有未装车的实绩 则代表还有未装车的物资 计算各个物资装车点 并更新到装车实绩中
- //如果是多拼 使用多种物资计算第一个装货的物资和装车点
- Map<String, Object> platIdMap = rulesService.calculateMaterial(list); //获得materialId loadingId
- platIdMap.put("orderId", map.get("orderId"));
- i += tmstruckLoadResultService.updateLoadingId(platIdMap); //更新装货点
- //更新下一计量实绩以当前毛重为皮重
- platIdMap.put("resultTareWeight", map.get("resultGrossWeight"));
- i += updateWeightResult(platIdMap);
- //添加仓库排队
- platIdMap.put("orderNumber", map.get("orderNumber"));
- qmsFeign.addQueueResultByCk(platIdMap);
- }
- break;
- case 2:
- case 3:
- break;
- case 4:
- break;
- case 5:
- case 6:
- case 7:
- case 8: //采购订单记录计毛为第一次计重 添加磅单号
- addInsertRegularField(tmstruckWeightResult); //插入第一次计重时间常规字段
- break;
- case 9:
- break;
- case 10:
- break;
- case 11:
- break;
- }
- i += tmstruckWeightResultMapper.updateByPrimaryKeySelective(tmstruckWeightResult);
- //路段顺序号 + 1
- i += utilsService.updateOrderLineSequence(map);
- return i;
- }
- /**
- * 生成计毛实体类
- * @param map
- * @return
- */
- public void generateMaoWeightResult(Map<String, Object> map, TmstruckWeightResult tmstruckWeightResult){
- //添加磅单号
- tmstruckWeightResult.setResultPoundNo((String) map.get("resultPoundNo"));
- //添加查询出来的主键
- BigDecimal weightTaskResultId = DataChange.dataToBigDecimal(map.get("weightTaskResultId"));
- tmstruckWeightResult.setWeightTaskResultId(weightTaskResultId);
- //添加毛重
- DecimalFormat df = new DecimalFormat("0.00");
- String resultGrossWeight = df.format((double) map.get("resultGrossWeight"));
- tmstruckWeightResult.setResultGrossWeight(new BigDecimal(resultGrossWeight));
- //添加毛重时间
- long resultGrossWeightTime = (long) map.get("resultGrossWeightTime");
- tmstruckWeightResult.setResultGrossWeightTime(new Date(resultGrossWeightTime));
- //添加净重 (如果传入的净重不为0)
- BigDecimal resultNetWeight = DataChange.dataToBigDecimal(map.get("resultNetWeight"));
- if(resultNetWeight.intValue() != 0){
- tmstruckWeightResult.setResultNetWeight(resultNetWeight);
- }
- //通过汽车衡编号查询汽车衡ID
- Integer calculateId = tmstruckWeightResultMapper.selectTruckCalculateId((String) map.get("truckCalculateNumber"));
- //添加计毛汽车衡
- if(calculateId != null){
- tmstruckWeightResult.setResultGrossPlaceId(new BigDecimal(calculateId));
- }
- }
- /**
- * 更新计皮实绩 需要采集的数据
- * 运输订单号 orderNumber
- * 汽车衡编号 truckCalculateNumber
- * 皮重 resultTareWeight
- * 皮重时间 resultTareWeightTime
- * 净重
- * 物资名称:materialName 物资规格:materialSpecification 型号:materialModel
- * @param map
- * @return
- */
- @Override
- @Transactional
- public int addJiPiResult(Map<String, Object> map) {
- TmstruckWeightResult tmstruckWeightResult = new TmstruckWeightResult();
- //通过物资名称和物资规格查询物资Id
- int materialId = tmstruckWeightResultMapper.getMaterialIdByMaterialNameAndSpe(map);
- map.put("materialId", materialId);
- //通过传来的运输订单号 与 物资ID查询计重实绩ID
- map.putAll(tmstruckWeightResultMapper.selectTotalIdByOrderNo(map));
- generatePiWeightResult(map, tmstruckWeightResult);
- int i = 0;
- BigDecimal orderType = DataChange.dataToBigDecimal(map.get("orderTypee"));
- switch (orderType.intValue()){
- case 1:
- //销售订单计皮为第一次计重
- addInsertRegularField(tmstruckWeightResult);// 添加插入常规字段 就是第一次计重时间;
- //查询还未装车的物资
- List<Map<String, Object>> mapList = rulesService.judgeLastMaterial(DataChange.dataToBigDecimal(map.get("orderId")));
- if(mapList.size() == 1){
- //如果是单拼 则直接
- Map<String, Object> mesMap = mapList.get(0);
- i += tmstruckLoadResultService.updateLoadingId(mesMap); //更新装货点
- //添加仓库排队
- mesMap.put("orderNumber", map.get("orderNumber"));
- qmsFeign.addQueueResultByCk(mesMap);
- }else {
- //如果是多拼 使用多种物资计算第一个装货的物资和装车点
- Map<String, Object> platIdMap = rulesService.calculateMaterial(mapList); //获得materialId loadingId
- platIdMap.put("orderId", map.get("orderId"));
- i += tmstruckLoadResultService.updateLoadingId(platIdMap); //更新装货点
- //添加仓库排队
- platIdMap.put("orderNumber", map.get("orderNumber"));
- qmsFeign.addQueueResultByCk(platIdMap);
- }
- break;
- case 2:
- case 3:
- //销售订单计皮为第一次计重
- addInsertRegularField(tmstruckWeightResult);// 添加插入常规字段 就是第一次计重时间;
- //焦炭、水渣只有一种物资 装货点是通过发运计划的时候填写的
- break;
- case 4:
- break;
- case 5:
- case 6:
- case 7:
- case 8:
- //如果订单类型为采购订单 则执行采购订单计皮规则
- addUpdateRegularField(tmstruckWeightResult); // 添加更新常规字段 就是第二次计重时间
- //计皮作业完成后自动完成签收
- i += autoReceipt(DataChange.dataToBigDecimal(map.get("resultTotalId")));
- //计皮完成后计算出厂门岗并更新实绩出厂门岗ID
- i += rulesService.calculateGatepost(map);
- break;
- case 9:
- break;
- case 10:
- break;
- case 11:
- break;
- }
- i += tmstruckWeightResultMapper.updateByPrimaryKeySelective(tmstruckWeightResult);
- //路段顺序号 + 1
- i += utilsService.updateOrderLineSequence(map);
- return i;
- }
- /**
- * 生成计皮实绩
- * @param tmstruckWeightResult
- * @return
- */
- public void generatePiWeightResult(Map<String, Object> map, TmstruckWeightResult tmstruckWeightResult){
- //添加磅单号
- tmstruckWeightResult.setResultPoundNo((String) map.get("resultPoundNo"));
- //添加查询出来的主键
- BigDecimal resultId = (BigDecimal) map.get("weightTaskResultId");
- tmstruckWeightResult.setWeightTaskResultId(resultId);
- //添加皮重
- DecimalFormat df = new DecimalFormat("0.00");
- String resultTareWeight = df.format((double) map.get("resultTareWeight"));
- tmstruckWeightResult.setResultTareWeight(new BigDecimal(resultTareWeight));
- //添加皮重时间
- long resultTareWeightTime = (long) map.get("resultTareWeightTime");
- tmstruckWeightResult.setResultTareWeightTime(new Date(resultTareWeightTime));
- //添加净重 (如果传入的净重不为0)
- BigDecimal resultNetWeight = DataChange.dataToBigDecimal(map.get("resultNetWeight"));
- if(resultNetWeight.intValue() != 0){
- tmstruckWeightResult.setResultNetWeight(resultNetWeight);
- }
- //通过汽车衡编号查询汽车衡ID 添加计皮汽车衡
- Integer calculateId = tmstruckWeightResultMapper.selectTruckCalculateId((String) map.get("truckCalculateNumber"));
- if(calculateId != null){
- tmstruckWeightResult.setResultTarePlaceId(new BigDecimal(calculateId));
- }
- }
- /**
- * 更新计量实绩 计皮点 计毛点 皮重
- * @param map
- */
- public int updateWeightResult(Map<String, Object> map){
- TmstruckWeightResult tmstruckWeightResult = new TmstruckWeightResult();
- //通过物资ID和运输订单Id修改查找计量实绩ID
- Integer id = tmstruckWeightResultMapper.getWeightIdByMaterialIdAndOrderId(map);
- tmstruckWeightResult.setId(new BigDecimal(id));
- if(map.get("tarePlaceId") != null){ //如果皮重汽车衡不为空 更新皮重汽车衡
- tmstruckWeightResult.setResultTarePlaceId(DataChange.dataToBigDecimal(map.get("tarePlaceId")));
- }
- if(map.get("grossPlaceId") != null){//如果毛重汽车衡不为空 更新毛重汽车衡
- tmstruckWeightResult.setResultGrossPlaceId(DataChange.dataToBigDecimal(map.get("grossPlaceId")));
- }
- if(map.get("resultTareWeight")!= null){ //如果皮重不为空 更新皮重
- tmstruckWeightResult.setResultTareWeight(DataChange.dataToBigDecimal(map.get("resultTareWeight")));
- }
- return tmstruckWeightResultMapper.updateByPrimaryKeySelective(tmstruckWeightResult);
- }
- /**
- * 自动签收
- * @return
- */
- public int autoReceipt(BigDecimal resultTotalId){
- TmstruckReceiptResult tmstruckReceiptResult = new TmstruckReceiptResult();
- tmstruckReceiptResult.setResultTotalId(resultTotalId);
- tmstruckReceiptResult.setStatus(new BigDecimal(1));
- tmstruckReceiptResult.setInsertUsername("admin");
- tmstruckReceiptResult.setInsertTime(new Date());
- return tmstruckReceiptResultMapper.updateByTotalResultId(tmstruckReceiptResult);
- }
- /**
- * 添加首次计重时的常规字段
- * @param tmstruckWeightResult
- */
- public void addInsertRegularField(TmstruckWeightResult tmstruckWeightResult){
- tmstruckWeightResult.setInsertTime(new Date());
- tmstruckWeightResult.setInsertUsername("admin");
- tmstruckWeightResult.setInsertUpdateRemark("无");
- }
- /**
- * 添加第二次计重时的常规字段
- * @param tmstruckWeightResult
- */
- public void addUpdateRegularField(TmstruckWeightResult tmstruckWeightResult){
- tmstruckWeightResult.setUpdateTime(new Date());
- tmstruckWeightResult.setUpdateUsername("admin");
- }
- /**
- * 多拼计算计毛汽车衡
- * @param map
- */
- public int calculateTruckCalculate(Map<String, Object> map, Integer resultTotalId){
- //通过总实绩ID查询订单Id
- Integer orderId = utilsService.getOrderIdByTotalId(resultTotalId);
- //查询未装车的装车实绩
- List<Map<String, Object>> list = rulesService.judgeLastMaterial(new BigDecimal(orderId));
- Map<String, Object> mesMap = new HashMap<>(); //用于查询更新存放数据map
- mesMap.put("orderId", orderId);
- int i = 0;
- if(list.size() == 0){
- //如果是最后一拼则走出厂称 计算出厂称
- mesMap.put("materialId", map.get("materialId"));
- mesMap.put("nature", 1);
- Integer calculate = rulesService.calculateWeighbridge(mesMap);
- //更新汽车衡
- mesMap.put("grossPlaceId", calculate);
- i += updateWeightResult(mesMap);
- }else {
- //如果后面还有物资未装车 则走拼装秤 10号秤 (固定数据)
- mesMap.put("materialId", map.get("materialId"));
- mesMap.put("grossPlaceId", 10);
- i += updateWeightResult(mesMap);
- }
- return i;
- }
- /**
- * 单拼销售计算汽车衡
- * @return
- */
- public int calculateTruckCalculateByOne(Map<String, Object> map, Integer type){
- String orderNumber = (String) map.get("orderNumber");
- //通过运输订单号查找物资ID、订单ID
- Map<String, Object> oIdAndMidMap = tmstruckWeightResultMapper.getOrderIdAndMaterialIdByOrderNum(orderNumber);
- //通过物资ID计算汽车衡
- if(type == 1){
- //1:进厂
- oIdAndMidMap.put("nature", type); //1: 进厂秤
- int calculateId = rulesService.calculateWeighbridge(oIdAndMidMap);
- oIdAndMidMap.put("tarePlaceId", calculateId);
- }else if(type == 2){
- //2:出厂
- oIdAndMidMap.put("nature", type); //2: 出厂称
- int calculateId = rulesService.calculateWeighbridge(oIdAndMidMap);
- oIdAndMidMap.put("grossPlaceId", calculateId);
- }
- return updateWeightResult(oIdAndMidMap);
- }
- public List<BigDecimal> getNextStep(BigDecimal lineId, int orderLineSequence) {
- return tmstruckWeightResultMapper.getNextStep(lineId,orderLineSequence);
- }
- }
|