123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419 |
- 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<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")));
- // 添加计皮计毛作业点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<Integer> calculateIdList = tmstruckWeightResultMapper.getCalculateIdByMaterial(materialId);
- return calculateIdList.get((int)(Math.random()*calculateIdList.size()));
- }
- /**
- * 更新计毛实绩 采集需要的数据
- * 运输订单号
- * 汽车衡编号
- * //物资名称
- * 毛重
- * 毛重时间
- * 磅单号
- * @return
- */
- @Override
- @Transactional
- public int addJiMaoResult(Map<String, Object> 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<String, Object> 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<String,BigDecimal> map = tmstruckWeightResultMapper.selectByOrderId(orderId);
- //通过运输订单id获取物资的类型
- BigDecimal materialTypeId = DataChange.dataToBigDecimal(map.get("materialTypeId"));
- //获取路段顺序号
- BigDecimal orderLineSequence = DataChange.dataToBigDecimal(map.get("orderLineSequence"));
- //计量实绩主键
- BigDecimal weightTaskResultId = DataChange.dataToBigDecimal(map.get("weightTaskResultId"));
- //line_id
- BigDecimal lineId=new BigDecimal(map.get("lineId").toString());
- //通过运输线路判断下一步是否为计量,当前是啥,下下一步是啥
- //如果下一步为计量,且当前步为进厂,则选择进厂称,如果下下步为出厂则选择出厂称,其他则选择中转称
- List<BigDecimal> 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<BigDecimal> getNextStep(BigDecimal lineId, int orderLineSequence) {
- return tmstruckWeightResultMapper.getNextStep(lineId,orderLineSequence);
- }
- }
|