package com.steerinfo.dil.service.impl; import com.steerinfo.dil.feign.OmsFeign; 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.text.ParseException; import java.text.SimpleDateFormat; import java.util.*; /** * 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 RulesServiceImpl rulesService; @Autowired OmsFeign omsFeign; /** * 派单时新增计重实绩 * 总实绩ID、计皮点、计毛点 * @return */ @Override public int addWeightResult(Map map) { TmstruckWeightResult tmstruckWeightResult = new TmstruckWeightResult(); //生成最大主键ID tmstruckWeightResult.setWeightTaskResultId(tmstruckWeightResultMapper.selectMaxId()); BigDecimal resultTotalId = DataChange.dataToBigDecimal(map.get("resultTotalId")); tmstruckWeightResult.setResultTotalId(resultTotalId); // 添加路段顺序号以及汽车衡 List calculateList = null; Integer calculateId = 0; Object grossSegmentSqe = map.get("grossSegmentSqe"); //获取毛重汽车衡 if(grossSegmentSqe != null){ tmstruckWeightResult.setGrossSegmentSqe(DataChange.dataToBigDecimal(grossSegmentSqe)); map.put("segmentSqe", grossSegmentSqe); calculateList = utilsMapper.getLineSegmentGateCalcId(map); //取汽车衡的Id calculateList.remove(null); calculateId = utilsService.randomGetValue(calculateList); tmstruckWeightResult.setResultGrossPlaceId(new BigDecimal(calculateId)); } Object tareSegmentSqe = map.get("tareSegmentSqe"); if(tareSegmentSqe != null){ tmstruckWeightResult.setTareSegmentSqe(DataChange.dataToBigDecimal(tareSegmentSqe)); map.put("segmentSqe", tareSegmentSqe); calculateList = utilsMapper.getLineSegmentGateCalcId(map); calculateList.remove(null); calculateId = utilsService.randomGetValue(calculateList); tmstruckWeightResult.setResultTarePlaceId(new BigDecimal(calculateId)); } if(map.get("isdeduct") == null){ //添加是否需要扣水扣杂 //通过总实绩ID查询订单类型 Integer orderType = tmstruckWeightResultMapper.getOrderTypeByTotalId(resultTotalId); if("67".contains(orderType.toString()) || orderType == 10){ tmstruckWeightResult.setIsdeduct(new BigDecimal(1)); } }else { tmstruckWeightResult.setIsdeduct(DataChange.dataToBigDecimal(map.get("isdeduct"))); } return tmstruckWeightResultMapper.insertSelective(tmstruckWeightResult); } /** * 查询所有计毛实绩 * @param map * @return */ @Override public List> getAllJiMaoResult(Map map) { Integer orderType = (Integer) map.get("orderTypee"); switch (orderType){ case 1: case 2: case 3: return tmstruckWeightResultMapper.getXSAllJiMaoResult(map); // apiID:212 case 4: return tmstruckWeightResultMapper.getSteelNzJiMaoResult(map); //apiId:264 case 5: case 6: case 7: case 8: case 17: case 18: return tmstruckWeightResultMapper.getCGAllJiMaoResult(map); //apiId:102 case 9: return tmstruckWeightResultMapper.getImportedDomesticNzJiMaoResult(map); // apiID:354 case 10: return tmstruckWeightResultMapper.getImportedDomesticNzJiMao2Result(map); // apiID:354 case 11: return tmstruckWeightResultMapper.getInFactoryJiLiangResult(map); //apiId: 358 case 12: case 13: case 15: case 16: return tmstruckWeightResultMapper.getSporadicSuppliesJiMiaoResult(map); //apiId:405 } return null; } /** * 查询所有计皮实绩 * @param map * @return */ @Override public List> getAllJiPiResult(Map map) { Integer orderType = (Integer) map.get("orderTypee"); switch (orderType){ case 1: case 2: case 3: return tmstruckWeightResultMapper.getXSAllJiPiResult(map); //apiId:211 case 4: return tmstruckWeightResultMapper.getSteelNzJiPiResult(map); //apiId:262 case 5: case 6: case 7: case 8: case 17: case 18: return tmstruckWeightResultMapper.getCGAllJiPiResult(map); // apiId: 104 case 9: return tmstruckWeightResultMapper.getImportedDomesticNzJiPiResult(map);// apiId: 104 case 10: return tmstruckWeightResultMapper.getImportedDomesticNzJiPi2Result(map);// apiId: 104 case 11: break; case 12: // return tmstruckWeightResultMapper.getSporadicSuppliesJiPiResult(map);//apiId:392 case 13: // return tmstruckWeightResultMapper.getFactorySkinSporadicJIPi(map); //apiId=401 case 15: case 16: return tmstruckWeightResultMapper.getFactorySkinSporadicWeight(map); //apiId=401 } return null; } /** * 更新计量实绩 计皮点 计毛点 皮重 * @param map */ public int updateWeightResult(Map map){ TmstruckWeightResult tmstruckWeightResult = new TmstruckWeightResult(); //通过订单Id 查询路段顺序号为最小的 且没有净重的计量实绩ID BigDecimal id = tmstruckWeightResultMapper.getWeightIdBySQEAndOrderId(map); tmstruckWeightResult.setId(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 map */ public int calculateTruckCalculate(Map map, Integer resultTotalId){ //通过总实绩ID查询订单Id Integer orderId = utilsService.getOrderIdByTotalId(resultTotalId); //查询未装车的装车实绩 List> list = rulesService.judgeLastMaterial(new BigDecimal(orderId)); Map 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 map, Integer type){ String orderNumber = (String) map.get("orderNumber"); //通过运输订单号查找物资ID、订单ID Map 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); } }