123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167 |
- package com.steerinfo.dil.service.impl;
- import com.steerinfo.dil.mapper.TmstruckWeightResultMapper;
- import com.steerinfo.dil.util.DataChange;
- import com.steerinfo.framework.mapper.IBaseMapper;
- import com.steerinfo.framework.service.impl.BaseServiceImpl;
- import com.steerinfo.dil.model.TmstrainWeightResult;
- import com.steerinfo.dil.mapper.TmstrainWeightResultMapper;
- import com.steerinfo.dil.service.ITmstrainWeightResultService;
- import org.springframework.beans.factory.annotation.Autowired;
- import org.springframework.stereotype.Service;
- import java.text.SimpleDateFormat;
- import java.util.Date;
- import java.math.BigDecimal;
- import java.util.Map;
- /**
- * TmstrainWeightResult服务实现:
- * @author generator
- * @version 1.0-SNAPSHORT 2021-12-08 04:34
- * 类描述
- * 修订历史:
- * 日期:2021-12-08
- * 作者:generator
- * 参考:
- * 描述:TmstrainWeightResult服务实现
- * @see null
- * @Copyright 湖南视拓信息技术股份有限公司. All rights reserved.
- */
- @Service(value = "tmstrainWeightResultService")
- public class TmstrainWeightResultServiceImpl implements ITmstrainWeightResultService {
- @Autowired
- private TmstrainWeightResultMapper tmstrainWeightResultMapper;
- @Autowired
- private TmstruckWeightResultMapper tmstruckWeightResultMapper;
- final private SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
- /**
- * 添加火车计量实绩
- * @param map
- * @return
- */
- public String addTrainWeightResult(Map<String, Object> map){
- String transportNum = String.valueOf(map.get("orderNumber"));
- Map<String, Object> mesMap = tmstrainWeightResultMapper.getTrainResultTotalMes(transportNum);
- if(mesMap == null){
- return "错误";
- }
- map.putAll(mesMap);
- TmstrainWeightResult tmstrainWeightResult = null;
- try {
- tmstrainWeightResult = generateTrainWeightResult(map);
- } catch (Exception e) {
- return e.getMessage(); //捕获异常信息
- }
- Object resultCrossWeightTime = map.get("resultCrossWeightTime");
- if(resultCrossWeightTime == null || "".equals(resultCrossWeightTime)){
- //如果没有毛重时间 则进行新增
- tmstrainWeightResultMapper.insertSelective(tmstrainWeightResult);
- }else {
- //反之则进行更新 根据总实绩ID进行更新
- tmstrainWeightResultMapper.updateByResultTotalIdSelective(tmstrainWeightResult);
- }
- return "成功";
- }
- /**
- * 生成火运计量实体
- * @param map
- * @return
- */
- public TmstrainWeightResult generateTrainWeightResult(Map<String, Object> map) throws Exception {
- TmstrainWeightResult tmstrainWeightResult = new TmstrainWeightResult();
- //磅单号
- tmstrainWeightResult.setResultPoundNo((String) map.get("resultPoundNo"));
- //添加火运总实绩ID
- tmstrainWeightResult.setResultTotalId(DataChange.dataToBigDecimal(map.get("resultTotalId")));
- //设置物资ID
- Object materialId = map.get("materialId");
- if(materialId != null && !"".equals(materialId)){
- tmstrainWeightResult.setMaterialId(DataChange.dataToBigDecimal(materialId));
- }
- //如果没有计毛时间 则是第一次计量
- String resultCrossWeightTime = (String) map.get("resultCrossWeightTime");
- if(resultCrossWeightTime == null || resultCrossWeightTime.length() == 0){
- //执行新增主键
- tmstrainWeightResult.setResultId(tmstrainWeightResultMapper.selectMaxId());
- //设置毛重时间
- tmstrainWeightResult.setResultGrossWeightTime(DataChange.dataToDate(map.get("resultTareWeightTime")));
- //添加毛重轨道衡
- Integer tareId = tmstruckWeightResultMapper.selectTruckCalculateId(String.valueOf(map.get("resultTareCalculateNumber")));
- if(tareId == null){
- throw new Exception("没有此计量衡:" + map.get("resultTareCalculateNumber"));
- }
- tmstrainWeightResult.setResultGrossPlaceId(new BigDecimal(tareId));
- //设置毛重
- tmstrainWeightResult.setResultGrossWeight(DataChange.dataToBigDecimal(map.get("resultTareWeight")));
- tmstrainWeightResult.setInsertTime(new Date());
- tmstrainWeightResult.setInsertUsername("admin");
- }else {
- //设置皮重汽车衡
- String resultTareCalculateNumber = (String) map.get("resultTareCalculateNumber");
- if(resultTareCalculateNumber != null){
- if(!"".equals(resultTareCalculateNumber)){
- Integer tareId = tmstruckWeightResultMapper.selectTruckCalculateId(resultTareCalculateNumber);
- if(tareId == null){
- throw new Exception("没有此皮重汽车衡:" + map.get("resultTareCalculateNumber"));
- }
- tmstrainWeightResult.setResultTarePlaceId(new BigDecimal(tareId));
- }
- }
- //设置毛重汽车衡
- String resultCrossCalculateNumber = (String) map.get("resultCrossCalculateNumber");
- if(resultCrossCalculateNumber != null){
- if(!"".equals(resultCrossCalculateNumber)){
- Integer crossId = tmstruckWeightResultMapper.selectTruckCalculateId(resultCrossCalculateNumber);
- if(crossId == null){
- throw new Exception("没有此毛重汽车衡:" + map.get("resultCrossCalculateNumber"));
- }
- tmstrainWeightResult.setResultGrossPlaceId(new BigDecimal(crossId));
- }
- }
- //毛重
- if(map.get("resultCrossWeight") != null){
- String resultCrossWeight = String.valueOf(map.get("resultCrossWeight"));
- if(!"".equals(resultCrossWeight))
- tmstrainWeightResult.setResultGrossWeight(DataChange.dataToBigDecimal(resultCrossWeight));
- }
- //皮重
- if(map.get("resultTareWeight") != null){
- String resultTareWeight = String.valueOf(map.get("resultTareWeight"));
- if(!"".equals(resultTareWeight))
- tmstrainWeightResult.setResultTareWeight(DataChange.dataToBigDecimal(resultTareWeight));
- }
- //净重
- if(map.get("resultNetWeight") != null){
- String resultNetWeight = String.valueOf(map.get("resultNetWeight"));
- if(!"".equals(resultNetWeight)){
- tmstrainWeightResult.setResultNetWeight(DataChange.dataToBigDecimal(resultNetWeight));
- }
- }
- //设置皮重时间
- if(map.get("resultTareWeightTime") != null){
- String resultTareWeightTime = (String) map.get("resultTareWeightTime");
- if(!"".equals(resultTareWeightTime)){
- tmstrainWeightResult.setResultTareWeightTime(sdf.parse(resultTareWeightTime));
- }
- }
- //设置毛重时间
- if(map.get("resultCrossWeightTime") != null){
- String resultGrossWeightTime = (String) map.get("resultCrossWeightTime");
- if(!"".equals(resultGrossWeightTime)){
- tmstrainWeightResult.setResultGrossWeightTime(sdf.parse(resultGrossWeightTime));
- }
- }
- tmstrainWeightResult.setUpdateTime(new Date());
- tmstrainWeightResult.setUpdateUsername("admin");
- }
- return tmstrainWeightResult;
- }
- }
|