package com.steerinfo.dil.service.impl; import com.steerinfo.dil.mapper.WmshGridMaterialMapper; import com.steerinfo.dil.mapper.WmshInboundResultMapper; import com.steerinfo.dil.mapper.WmshOutboundResultMapper; import com.steerinfo.dil.model.WmshGridMaterial; import com.steerinfo.dil.model.WmshOutboundResult; import com.steerinfo.dil.service.IWmshGridMaterialService; 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.util.Date; import java.util.HashMap; import java.util.List; import java.util.Map; /** * WmshGridMaterial服务实现: * @author generator * @version 1.0-SNAPSHORT 2021-10-09 07:25 * 类描述 * 修订历史: * 日期:2021-10-09 * 作者:generator * 参考: * 描述:WmshGridMaterial服务实现 * @see null * @Copyright 湖南视拓信息技术股份有限公司. All rights reserved. */ @Service(value = "wmshGridMaterialService") public class WmshGridMaterialServiceImpl implements IWmshGridMaterialService { @Autowired private WmshGridMaterialMapper wmshGridMaterialMapper; @Autowired private WmshOutboundResultMapper wmshOutboundResultMapper; @Autowired private WmshInboundResultMapper wmshInboundResultMapper; /** * 展示下游港口实时库存 * @param mapVal * @return */ @Override public List> getUnloadPortStockList(Map mapVal) { return wmshGridMaterialMapper.getUnloadPortStockList(mapVal); } /** * 展示万州港实时库存 * @param mapVal * @return */ @Override public List> getLoadPortStockList(Map mapVal) { return wmshGridMaterialMapper.getLoadPortStockList(mapVal); } @Override public List> getDownPortStockList(Map mapVal) { return wmshGridMaterialMapper.getDownPortStockList(mapVal); } @Override public List> getRunStockList(Map mapVal) { return wmshGridMaterialMapper.getRunStockList(mapVal); } /** * 修改实时库存 * @param map * @return */ @Override public int updatePortStock(Map map) { BigDecimal tonnage=null; BigDecimal portId = DataChange.dataToBigDecimal(map.get("portId")); BigDecimal batchId = DataChange.dataToBigDecimal(map.get("batchId")); tonnage = DataChange.dataToBigDecimal(map.get("resultMaterialNumber")); if (map.get("resultMaterialNumber")==null){ tonnage =DataChange.dataToBigDecimal(map.get("resultTonnage")); } BigDecimal status = DataChange.dataToBigDecimal(map.get("status")); Map selectMap = new HashMap<>(); selectMap.put("portId",portId); selectMap.put("batchId",batchId); //查找是否有港存库实时库存 List> wmshGridMaterials = wmshGridMaterialMapper.getGridId(map); if (wmshGridMaterials.size() == 0) { WmshGridMaterial wmshGridMaterial = new WmshGridMaterial(); BigDecimal gmId = wmshGridMaterialMapper.selectMaxId(); wmshGridMaterial.setGmId(gmId); wmshGridMaterial.setBatchId(batchId); wmshGridMaterial.setPortId(portId); wmshGridMaterial.setGmTonnage(tonnage); wmshGridMaterial.setDeleted(new BigDecimal(0)); return wmshGridMaterialMapper.insertSelective(wmshGridMaterial); } Map map1 = wmshGridMaterials.get(0); BigDecimal oldGmsTonnage = DataChange.dataToBigDecimal(map1.get("gmTonnage")); BigDecimal gmId =DataChange.dataToBigDecimal(map1.get("gmId")); WmshGridMaterial wmshGridMaterial=new WmshGridMaterial(); wmshGridMaterial.setGmId(gmId); BigDecimal gmsTonnage; if (status.intValue() == 0) { //gmsTonnage = new BigDecimal(oldGmsTonnage.doubleValue() - tonnage.doubleValue()); gmsTonnage = oldGmsTonnage.subtract(tonnage); } else { //gmsTonnage = new BigDecimal(tonnage.doubleValue() + oldGmsTonnage.doubleValue()); gmsTonnage = tonnage.add(oldGmsTonnage); } if (gmsTonnage.intValue()>=0) { wmshGridMaterial.setGmTonnage(gmsTonnage); }else { return -1; } wmshGridMaterial.setUpdateTime(new Date()); int i = wmshGridMaterialMapper.updateByPrimaryKeySelective(wmshGridMaterial); return i; } @Override @Transactional(rollbackFor = Exception.class) public int clearWmshGridMaterial(Map map) { int i=0; BigDecimal gmId =DataChange.dataToBigDecimal(map.get("gmId")); WmshGridMaterial wmshGridMaterial=wmshGridMaterialMapper.selectByPrimaryKey(gmId); BigDecimal surplus=wmshGridMaterial.getGmTonnage(); wmshGridMaterial.setGmTonnage(new BigDecimal(0)); i = wmshGridMaterialMapper.updateByPrimaryKeySelective(wmshGridMaterial); //实时库存 String isClear =(String) map.get("isClean"); WmshOutboundResult wmshOutboundResult =new WmshOutboundResult(); BigDecimal id = DataChange.dataToBigDecimal(wmshGridMaterialMapper.selectMaxId()); wmshOutboundResult.setResultId(id); String gckd = DataChange.generateEightDigitsNumber("GCKD", id.intValue()); wmshOutboundResult.setResultNumber(gckd); wmshOutboundResult.setResultClearing(isClear); wmshOutboundResult.setInsertTime(new Date()); wmshOutboundResult.setResultTonnage(surplus); wmshOutboundResult.setBatchId(DataChange.dataToBigDecimal(map.get("batchId"))); BigDecimal portId = DataChange.dataToBigDecimal(map.get("portId")); wmshOutboundResult.setHarborId(portId); //并按照装船时间作为下游港口出库作业时间 if (map.get("resultLoadShipDate") != null) { long resultLoadShipDate =(long) map.get("resultLoadShipDate"); wmshOutboundResult.setWorkTime(new Date(resultLoadShipDate)); } //按照出库时间作为万州港出库作业时间 if (map.get("resultLoadingDate") != null) { long resultLoadingDate =(long) map.get("resultLoadingDate"); wmshOutboundResult.setWorkTime(new Date(resultLoadingDate)); } i = wmshOutboundResultMapper.insertSelective(wmshOutboundResult); return id.intValue(); } //展示港存库目前品种对应的库存 @Override public List> getLoadPortStockByMaterialName(Map mapVal) { return wmshGridMaterialMapper.getLoadPortStockByMaterialName(mapVal); } //展示出库总吨位 @Override public List> getUnLockPortStock(Map mapVal) { return wmshGridMaterialMapper.getUnLockPortStock(mapVal); } @Override @Transactional(rollbackFor = Exception.class) public int updateWmshGridMaterial(Map map) { BigDecimal batchId = DataChange.dataToBigDecimal(map.get("batchId")); String userId = map.get("userId")+""; //查询旧的批次所有的港存库 Map batchIdOld = new HashMap<>(); batchIdOld.put("batchId",map.get("batchIdOld")); List> oldGrids = wmshGridMaterialMapper.getAllGridOfBatch(batchIdOld); for(Map oldGrid:oldGrids){ WmshGridMaterial wmshGridMaterial=new WmshGridMaterial(); BigDecimal gmId = DataChange.dataToBigDecimal(oldGrid.get("gmId")); BigDecimal oldGmsTonnage = DataChange.dataToBigDecimal(oldGrid.get("gmTonnage")); BigDecimal portId =DataChange.dataToBigDecimal(oldGrid.get("portId")); Map temp=new HashMap<>(); temp.put("batchId",batchId); temp.put("portId",portId); //查询对应的新批次港存库 List> nowGrids=wmshGridMaterialMapper.getGridId(temp); if(nowGrids!=null && nowGrids.size()>0){ Map nowGrid=nowGrids.get(0); BigDecimal nowGmsTonnage = DataChange.dataToBigDecimal(nowGrid.get("gmTonnage")); //增加库存 wmshGridMaterial.setGmId(DataChange.dataToBigDecimal(nowGrid.get("gmId"))); wmshGridMaterial.setGmTonnage(nowGmsTonnage.add(oldGmsTonnage)); wmshGridMaterial.setUpdateUsername(userId); //将旧的港存库置为0 WmshGridMaterial oldGridMaterial=new WmshGridMaterial(); oldGridMaterial.setGmId(DataChange.dataToBigDecimal(oldGrid.get("gmId"))); oldGridMaterial.setGmTonnage(new BigDecimal(0)); oldGridMaterial.setUpdateUsername(userId); oldGridMaterial.setDeleted(new BigDecimal(1)); wmshGridMaterialMapper.updateByPrimaryKeySelective(oldGridMaterial); }else{ //如果没有新批次的港存库,就直接修改当前港存库批次为该港存库 wmshGridMaterial.setGmId(gmId); wmshGridMaterial.setBatchId(batchId); wmshGridMaterial.setUpdateUsername(userId); } wmshGridMaterialMapper.updateByPrimaryKeySelective(wmshGridMaterial); } //修改入库和出库实绩绑定的批次 wmshInboundResultMapper.updateForBind(map); wmshOutboundResultMapper.updateForBind(map); return 1; } }