package com.steerinfo.dil.service.impl; import com.steerinfo.dil.feign.WmshboundFeign; import com.steerinfo.dil.mapper.DilBatchInfacotryMapper; import com.steerinfo.dil.mapper.DilBatchMapper; import com.steerinfo.dil.model.DilBatch; import com.steerinfo.dil.model.DilBatchInfacotry; import com.steerinfo.dil.service.IDilBatchService; 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.util.Date; import java.math.BigDecimal; import java.util.List; import java.util.Map; /** * DilBatch服务实现: * @author generator * @version 1.0-SNAPSHORT 2021-11-06 10:22 * 类描述 * 修订历史: * 日期:2021-11-06 * 作者:generator * 参考: * 描述:DilBatch服务实现 * @see null * @Copyright 湖南视拓信息技术股份有限公司. All rights reserved. */ @Service(value = "dilBatchService") public class DilBatchServiceImpl implements IDilBatchService { @Autowired private DilBatchMapper dilBatchMapper; @Autowired private DilBatchInfacotryMapper dilBatchInfacotryMapper; @Autowired private WmshboundFeign wmshboundFeign; @Override public List> getBatchList(Map map) { return dilBatchMapper.getBatchList(map); } @Override public List> getBatchListFortTransfer(Map map) { return dilBatchMapper.getBatchListFortTransfer(map); } @Override public List> getBatchListForInstruction(Map map) { return dilBatchMapper.getBatchListForInstruction(map); } @Override public List> getShipNameList(String state) { state = "%"+state+"%"; return dilBatchMapper.getShipNameList(state); } @Override public Map getPersonByName(String personName) { return dilBatchMapper.getPersonByName(personName); } //新增批次 @Transactional @Override public Map insertBatchId(Map map) { String inFactoryShipName = (String) map.get("inFactoryShipName"); String foreignShipName = (String) map.get("foreignShipName"); BigDecimal materialId = DataChange.dataToBigDecimal(map.get("materialId")); String userId = (String) map.get("userId"); BigDecimal batchId1=null; BigDecimal batchIds =DataChange.dataToBigDecimal(map.get("batchIds")); DilBatchInfacotry dilBatchInfacotry=new DilBatchInfacotry(); //首先根据外轮船名和批次查找批次主表id是否存在 List> BatchId = dilBatchMapper.selectBatchIdByForeign(map); if (BatchId.size()!=0){ if(batchIds==null || batchIds.compareTo(new BigDecimal(0))==0){ //如果录入的批次已经存在,则采用之前的批次 batchId1=DataChange.dataToBigDecimal(BatchId.get(0).get("batchId")); dilBatchInfacotry.setBatchId(batchId1); }else{ dilBatchInfacotry.setBatchId(batchIds); } }else { DilBatch dilBatch = new DilBatch(); batchId1 = dilBatchMapper.selectBatchId(); dilBatch.setBatchId(batchId1); dilBatch.setResultForeignShipName(foreignShipName); dilBatch.setMaterialId(materialId); //新增次表 dilBatchInfacotry.setBatchId(batchId1); dilBatch.setInsertTime(new Date()); dilBatch.setInsertUsername(userId); dilBatch.setInsertUpdateRemark("人工录入"); int i = dilBatchMapper.insertSelective(dilBatch); if (i==0){ System.out.println("新增批次主表失败!!!"); } } BigDecimal batchIdInfacotryId = dilBatchInfacotryMapper.selectDilBatchId(); dilBatchInfacotry.setBatchInfacotryId(batchIdInfacotryId); dilBatchInfacotry.setInfactoryShipName(inFactoryShipName); dilBatchInfacotry.setInsertUsername(userId); dilBatchInfacotry.setInsertTime(new Date()); map.put("batchIdInfacotryId",batchIdInfacotryId); map.put("batchId",batchId1); int j= dilBatchInfacotryMapper.insertSelective(dilBatchInfacotry); if (j==0){ System.out.println("新增批次中间表失败!!!"); } return map; } @Override public List> getBatchIdByForeign(Map mapValue) { return dilBatchMapper.getBatchIdByForeign(mapValue); } @Override public Map getNoticeContactNumberByPerson(String personName) { return dilBatchMapper.getNoticeContactNumberByPerson(personName); } @Override public List> findBatchForBind(Map map) { return dilBatchMapper.findBatchForBind(map); } @Override @Transactional(rollbackFor = Exception.class) public int bindBatch(Map map) throws Exception { int i=0; //校验 if( map.get("batchIdOld")==null || map.get("batchId") ==null || map.get("userId") ==null){ throw new Exception("数据异常,请检查是否输入正确数据!"); } if(dilBatchInfacotryMapper.checkForBind(map)==null){ throw new Exception("外轮船名不相等,请检查批次是否正确!"); } //更新批次中间表的所有关联批次 i+=dilBatchInfacotryMapper.updateForBind(map); //更新港存库、入库、出库的批次id wmshboundFeign.updateWmshGridMaterial(map); return i; } @Override public BigDecimal getPortId(String portName) { return dilBatchMapper.getPortId(portName); } }