package com.steerinfo.dil.service.impl; import com.steerinfo.dil.mapper.TmstruckReceiptResultMapper; import com.steerinfo.dil.mapper.TmstruckWeightResultMapper; 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.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; /** * 查询所有计毛实绩 * @param map * @return */ @Override public List> getAllJiMaoResult(Map 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> getAllJiPiResult(Map 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 map) { TmstruckWeightResult tmstruckWeightResult = new TmstruckWeightResult(); //生成最大主键ID tmstruckWeightResult.setWeightTaskResultId(tmstruckWeightResultMapper.selectMaxId()); tmstruckWeightResult.setResultTotalId(DataChange.dataToBigDecimal(map.get("resultTotalId"))); // 添加计皮计毛作业点ID tmstruckWeightResult.setResultGrossPlaceId(DataChange.dataToBigDecimal(map.get("truckCalculateIdMao"))); tmstruckWeightResult.setResultTarePlaceId(DataChange.dataToBigDecimal(map.get("truckCalculateIdPi"))); return tmstruckWeightResultMapper.insertSelective(tmstruckWeightResult); } /** * 通过物资ID获取对应汽车衡 如果有多个汽车衡中随机选择 * @param materialId * @return */ @Override public int getCalculateIdByMaterial(BigDecimal materialId) { List calculateIdList = tmstruckWeightResultMapper.getCalculateIdByMaterial(materialId); return calculateIdList.get((int)(Math.random()*calculateIdList.size())); } /** * 更新计毛实绩 采集需要的数据 * 运输订单号 * 汽车衡编号 * //物资名称 * 毛重 * 毛重时间 * 磅单号 * @return */ @Override @Transactional public int addJiMaoResult(Map map) { TmstruckWeightResult tmstruckWeightResult = new TmstruckWeightResult(); //通过传来的运输订单号查询计重实绩 map.putAll(tmstruckWeightResultMapper.selectTotalIdByOrderNo((String) map.get("orderNumber"))); 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)); //通过汽车衡编号查询汽车衡ID Integer calculateId = tmstruckWeightResultMapper.selectTruckCalculateId((String) map.get("truckCalculateNumber")); //添加计毛汽车衡 if(calculateId != null){ tmstruckWeightResult.setResultGrossPlaceId(new BigDecimal(calculateId)); } Integer lineSequence = null; //路段顺序号 BigDecimal orderType = DataChange.dataToBigDecimal(map.get("orderTypee")); switch (orderType.intValue()){ //如果订单类型为销售订单 则执行销售订单计皮规则 resultTareWeight case 1: //计算净重 从map中获取皮重 tareWeight double netWeight = ((BigDecimal) map.get("resultGrossWeight")).doubleValue() - ((Double) map.get("tareWeight")); String resultNetWeight = df.format(netWeight); tmstruckWeightResult.setResultNetWeight(new BigDecimal(resultNetWeight)); addUpdateRegularField(tmstruckWeightResult); //插入第二次计重时间 lineSequence = 5; //设置路段顺序号为5:出厂 break; case 2: break; case 3: break; case 4: break; case 5: case 6: case 7: case 8: //采购订单记录计毛为第一次计重 添加磅单号 tmstruckWeightResult.setResultPoundNo((String) map.get("resultPoundNo")); addInsertRegularField(tmstruckWeightResult); //插入第一次计重时间常规字段 lineSequence = 5; //设置路段顺序号为3:卸货 break; case 9: break; case 10: break; case 11: break; } int i = tmstruckWeightResultMapper.updateByPrimaryKeySelective(tmstruckWeightResult); //更新订单路段顺序号 int i2 = utilsService.updateOrderLineSequence(map, lineSequence); return i +i2; } /** * 更新计皮实绩 需要采集的数据 * 运输订单号 orderNumber * 汽车衡编号 truckCalculateNumber * 皮重 resultTareWeight * 皮重时间 resultTareWeightTime * 净重 * @param map * @return */ @Override @Transactional public int addJiPiResult(Map map) { TmstruckWeightResult tmstruckWeightResult = new TmstruckWeightResult(); //通过传来的运输订单号查询计重实绩 map.putAll(tmstruckWeightResultMapper.selectTotalIdByOrderNo((String) map.get("orderNumber"))); 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)); //通过汽车衡编号查询汽车衡ID 添加计皮汽车衡 Integer calculateId = tmstruckWeightResultMapper.selectTruckCalculateId((String) map.get("truckCalculateNumber")); if(calculateId != null){ tmstruckWeightResult.setResultTarePlaceId(new BigDecimal(calculateId)); } int i1 = 0; Integer lineSequence = null; //路段顺序号 BigDecimal orderType = DataChange.dataToBigDecimal(map.get("orderTypee")); switch (orderType.intValue()){ case 1: //销售订单计皮为第一次计重 tmstruckWeightResult.setResultPoundNo((String) map.get("resultPoundNo")); addInsertRegularField(tmstruckWeightResult);// 添加插入常规字段 就是第一次计重时间 break; case 2: break; case 3: break; case 4: break; case 5: case 6: case 7: case 8: //如果订单类型为采购订单 则执行采购订单计皮规则 //计算净重 先从map中获取毛重 grossWeight double netWeight = ((BigDecimal) map.get("grossWeight")).doubleValue() - ((Double) map.get("resultTareWeight")); String resultNetWeight = df.format(netWeight); tmstruckWeightResult.setResultNetWeight(new BigDecimal(resultNetWeight)); addUpdateRegularField(tmstruckWeightResult); // 添加更新常规字段 就是第二次计重时间 //计皮作业完成后自动完成签收 TmstruckReceiptResult tmstruckReceiptResult = new TmstruckReceiptResult(); tmstruckReceiptResult.setResultTotalId(DataChange.dataToBigDecimal(map.get("resultTotalId"))); tmstruckReceiptResult.setStatus(new BigDecimal(1)); tmstruckReceiptResult.setInsertUsername("admin"); tmstruckReceiptResult.setInsertTime(new Date()); i1 = tmstruckReceiptResultMapper.updateByTotalResultId(tmstruckReceiptResult); lineSequence = 5; // 出厂 break; case 9: break; case 10: break; case 11: break; } int i = tmstruckWeightResultMapper.updateByPrimaryKeySelective(tmstruckWeightResult); //更新订单路段顺序号 int i2 = utilsService.updateOrderLineSequence(map, lineSequence); return i + i1 + i2; } /** * 添加首次计重时的常规字段 * @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"); } /** *通过运输订单判断下一步是否需要计量,更新汽车衡到计量实绩中 */ @Override public int isNextNeedJl(BigDecimal orderId) { //通过运输订单id获取路段顺序号、物资类型、计量实绩主键、line_id Map map=tmstruckWeightResultMapper.selectByOrderId(orderId); //通过运输订单id获取物资的类型 BigDecimal materialTypeId=new BigDecimal(map.get("materialTypeId").toString()); //获取路段顺序号 BigDecimal orderLineSequence=new BigDecimal(map.get("orderLineSequence").toString()); //计量实绩主键 BigDecimal weightTaskResultId=new BigDecimal(map.get("weightTaskResultId").toString()); //line_id BigDecimal lineId=new BigDecimal(map.get("lineId").toString()); //通过运输线路判断下一步是否为计量,当前是啥,下下一步是啥 //如果下一步为计量,且当前步为进厂,则选择进厂称,如果下下步为出厂则选择出厂称,其他则选择中转称 List list=getNextStep(lineId,orderLineSequence.intValue()); if(list.size()==3){ //0:进厂;1:计毛;2:计皮;3:卸货;4:装货;5:出厂 if(list.get(1).intValue()==1 || list.get(1).intValue()==2){ //如果当前为进厂 if(list.get(0).intValue()==0){ //获取到汽车衡id BigDecimal truckCalculateId =tmstruckWeightResultMapper.getTruckCalculateNumber(materialTypeId,new BigDecimal(1)); //将获取到的汽车衡id更新到计量实绩表中 //如果下一步为计毛作业 if(list.get(1).intValue()==1){ //通过订单号获取计量实绩主键,并更新 TmstruckWeightResult tmstruckWeightResult=new TmstruckWeightResult(); tmstruckWeightResult.setWeightTaskResultId(weightTaskResultId); tmstruckWeightResult.setResultGrossPlaceId(truckCalculateId); tmstruckWeightResult.setUpdateTime(new Date()); tmstruckWeightResult.setUpdateUsername("admin"); tmstruckWeightResultMapper.updateByPrimaryKeySelective(tmstruckWeightResult); } //如果下一步为计皮作业 if(list.get(1).intValue()==2){ //通过订单号获取计量实绩主键,并更新 TmstruckWeightResult tmstruckWeightResult=new TmstruckWeightResult(); tmstruckWeightResult.setWeightTaskResultId(weightTaskResultId); tmstruckWeightResult.setResultTarePlaceId(truckCalculateId); tmstruckWeightResult.setUpdateTime(new Date()); tmstruckWeightResult.setUpdateUsername("admin"); tmstruckWeightResultMapper.updateByPrimaryKeySelective(tmstruckWeightResult); } } //如果计量后一步为出厂 else if(list.get(2).intValue()==5){ //获取到汽车衡id BigDecimal truckCalculateId =tmstruckWeightResultMapper.getTruckCalculateNumber(materialTypeId,new BigDecimal(2)); //将获取到的汽车衡id更新到计量实绩表中 //如果下一步为计毛作业 if(list.get(1).intValue()==1){ //通过订单号获取计量实绩主键,并更新 TmstruckWeightResult tmstruckWeightResult=new TmstruckWeightResult(); tmstruckWeightResult.setWeightTaskResultId(weightTaskResultId); tmstruckWeightResult.setResultGrossPlaceId(truckCalculateId); tmstruckWeightResult.setUpdateTime(new Date()); tmstruckWeightResult.setUpdateUsername("admin"); tmstruckWeightResultMapper.updateByPrimaryKeySelective(tmstruckWeightResult); } //如果下一步为计皮作业 if(list.get(1).intValue()==2){ //通过订单号获取计量实绩主键,并更新 TmstruckWeightResult tmstruckWeightResult=new TmstruckWeightResult(); tmstruckWeightResult.setWeightTaskResultId(weightTaskResultId); tmstruckWeightResult.setResultTarePlaceId(truckCalculateId); tmstruckWeightResult.setUpdateTime(new Date()); tmstruckWeightResult.setUpdateUsername("admin"); tmstruckWeightResultMapper.updateByPrimaryKeySelective(tmstruckWeightResult); } }else{ //获取到汽车衡id BigDecimal truckCalculateId =tmstruckWeightResultMapper.getTruckCalculateNumber(materialTypeId,new BigDecimal(3)); //将获取到的汽车衡id更新到计量实绩表中 //如果下一步为计毛作业 if(list.get(1).intValue()==1){ //通过订单号获取计量实绩主键,并更新 TmstruckWeightResult tmstruckWeightResult=new TmstruckWeightResult(); tmstruckWeightResult.setWeightTaskResultId(weightTaskResultId); tmstruckWeightResult.setResultGrossPlaceId(truckCalculateId); tmstruckWeightResult.setUpdateTime(new Date()); tmstruckWeightResult.setUpdateUsername("admin"); tmstruckWeightResultMapper.updateByPrimaryKeySelective(tmstruckWeightResult); } //如果下一步为计皮作业 if(list.get(1).intValue()==2){ //通过订单号获取计量实绩主键,并更新 TmstruckWeightResult tmstruckWeightResult=new TmstruckWeightResult(); tmstruckWeightResult.setWeightTaskResultId(weightTaskResultId); tmstruckWeightResult.setResultTarePlaceId(truckCalculateId); tmstruckWeightResult.setUpdateTime(new Date()); tmstruckWeightResult.setUpdateUsername("admin"); tmstruckWeightResultMapper.updateByPrimaryKeySelective(tmstruckWeightResult); } } } }else { return 0; } return 0; } public List getNextStep(BigDecimal lineId, int orderLineSequence) { return tmstruckWeightResultMapper.getNextStep(lineId,orderLineSequence); } }