package com.steerinfo.dil.service.impl; import com.steerinfo.dil.mapper.*; import com.steerinfo.dil.model.WmspCheckWarehouse; import com.steerinfo.dil.model.WmspGridMaterial; import com.steerinfo.dil.model.WmspRestackMakeResult; import com.steerinfo.dil.model.WmspRestackScanResult; import com.steerinfo.dil.service.IWmspGridMaterialService; import com.steerinfo.dil.util.DataChange; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import java.math.BigDecimal; import java.util.*; /** * WmspGridMaterial服务实现: * @author generator * @version 1.0-SNAPSHORT 2021-09-08 06:02 * 类描述 * 修订历史: * 日期:2021-09-08 * 作者:generator * 参考: * 描述:WmspGridMaterial服务实现 * @see null * @Copyright 湖南视拓信息技术股份有限公司. All rights reserved. */ @Service public class WmspGridMaterialServiceImpl implements IWmspGridMaterialService { @Autowired private WmspGridMaterialMapper wmspGridMaterialMapper; @Autowired private RmsStackingMapper rmsStackingMapper; @Autowired private RmsPwarehouseGridMapper rmsPwarehouseGridMapper; @Autowired private WmspRestackScanResultMapper wmspRestackScanResultMapper; @Autowired private WmspRestackMakeResultMapper wmspRestackMakeResultMapper; @Autowired private WmspCheckWarehouseMapper wmspCheckWarehouseMapper; //新增 @Override public int insertSelective(WmspGridMaterial wmspGridMaterial) { // long id; // BigDecimal MAXid=wmspGridMaterial.getGmId(); // if (MAXid==null){ // id=1; // }else { // id=MAXid.longValue()+1; // } // wmspGridMaterial.setGmId(new BigDecimal(id)); return wmspGridMaterialMapper.insertSelective(wmspGridMaterial); } //更新 @Override public int updateByPrimaryKeySelective(WmspGridMaterial wmspGridMaterial) { return wmspGridMaterialMapper.updateByPrimaryKeySelective(wmspGridMaterial); } //查询实时库存数据 @Override public List> selectGridMaterial(Map mapval) { return wmspGridMaterialMapper.selectGridMaterial(mapval); } //根据仓储网格统计数据 @Override public Long countByGmId() { return wmspGridMaterialMapper.countByGmId(); } @Override public List> selectInboundTimeAndThreshold(BigDecimal gridId) { return wmspGridMaterialMapper.selectInboundTimeAndThreshold(gridId); } @Override public Integer insertWmspGridMaterial(WmspGridMaterial wmspGridMaterial) { return wmspGridMaterialMapper.insertSelective(wmspGridMaterial); } @Override public List> selectGridMaterialListByGridId(Map mapval) { return wmspGridMaterialMapper.selectGridMaterialListByGridId(mapval); } @Override public int updateRmsMaterialSteelDemotion(Map map) { String gridId = map.get("gridId").toString(); BigDecimal materialSteelId = wmspGridMaterialMapper.selectMaterialSteelIdByGridId(new BigDecimal(gridId)); map.put("materialSteelId",materialSteelId); //逻辑删除物资钢材表的这个钢材数据并修改其质量是否合格状态 wmspGridMaterialMapper.updateRmsMaterialSteelDemotion(map); //逻辑删除物资为当前钢材的钢材仓库网格物资存放关系表数据(用对象) WmspGridMaterial wmspGridMaterial = new WmspGridMaterial(); wmspGridMaterial.setGridId(new BigDecimal(gridId)); wmspGridMaterial.setDeleted(new BigDecimal(0)); wmspGridMaterialMapper.updateByPrimaryKeySelective(wmspGridMaterial); //逻辑删除入库作业实绩以及相关联的所有表数据 //通过钢材Id获取入库作业实绩Id BigDecimal inboundId = wmspGridMaterialMapper.selectInboundIdByMaterialSteelId(materialSteelId); //通过入库实绩ID逻辑删除库管员纠正吊牌实绩数据 wmspGridMaterialMapper.updateInboundCorrectByInboundId(inboundId); //通过入库实绩ID逻辑删除行车工吊装入库实绩数据 wmspGridMaterialMapper.updateInboundDrivingByInboundId(inboundId); //通过入库实绩ID逻辑删除吊钢工扫描吊牌实绩数据 wmspGridMaterialMapper.updateInboundScanByInboundId(inboundId); //通过入库实绩ID逻辑删除系统/库管员选择垛位实绩数据 return wmspGridMaterialMapper.updateInboundStackByInboundId(inboundId); } /** * 创建实时库存 * @param item * @param houseGrid */ @Override public void initInsertWmspGridMaterial(Map item, BigDecimal houseGrid) { /* 插入一条网格物资中间表 */ WmspGridMaterial wmspGridMaterial = new WmspGridMaterial(); //设置主键ID wmspGridMaterial.setGmId(wmspGridMaterialMapper.getCount()); wmspGridMaterial.setGridId(houseGrid); wmspGridMaterial.setGmNumber(new BigDecimal(1)); wmspGridMaterial.setStandardDataId(new BigDecimal(1)); //设置网格物资表里面的物资ID BigDecimal materialId= DataChange.dataToBigDecimal(item.get("materialId")); wmspGridMaterial.setMaterialId(materialId); //设置逻辑删除字段 wmspGridMaterial.setDeleted(new BigDecimal(0)); //设置常规字段 wmspGridMaterial.setInsertUsername("admin"); wmspGridMaterial.setInsertTime(new Date()); wmspGridMaterial.setUpdateUsername("admin"); wmspGridMaterial.setInsertUpdateRemark("无"); wmspGridMaterial.setStatus(new BigDecimal(2)); insertWmspGridMaterial(wmspGridMaterial); } @Override public Map getReboundScanResultByResultMaterial(String material,String materialOnlyCode) { return wmspGridMaterialMapper.getReboundScanResultByResultMaterial(material,materialOnlyCode); } //修改实时库存(倒垛) /** * 所需要参数:原来的仓储网格id,修改后的垛位 * @param map * @return */ @Override public int updateWmspGridMaterial(List> map,String restackMake) { int CC=0; int MN=0; int CX=0; int i =0; //获取物资唯一编码 // List> contents=(List>) map.get("contents"); for (Map map1:map) { String content =(String) map1.get("contents"); //截取 String[] split = content.split("-"); String materialOnlyCode = split[7]; //获取原来的垛位,修改垛位剩余物资数量 //根据物资唯一编码查找原来垛位的仓储网格id BigDecimal GirdId = wmspGridMaterialMapper.slelectGridIdByMaterialOnlyCode(materialOnlyCode); //根据物资唯一编码和物资编码去查找物资现存仓存网格 Map stringObjectMap = wmspGridMaterialMapper.selectGmIdByMaterialOnlyCode(GirdId); BigDecimal gmId = DataChange.dataToBigDecimal(stringObjectMap.get("gmId")); WmspGridMaterial wmspGridMaterial=new WmspGridMaterial(); wmspGridMaterial.setGmId(gmId); //设置为删除且锁定的状态 wmspGridMaterial.setDeleted(new BigDecimal(1)); wmspGridMaterial.setStatus(new BigDecimal(1)); wmspGridMaterialMapper.updateByPrimaryKeySelective(wmspGridMaterial); //获取垛位id BigDecimal stackingId = DataChange.dataToBigDecimal(map1.get("stackingId")); //根据最新的垛位 //计算仓储网格id //获取物资数 MN=rmsStackingMapper.selectMaterialNumber(map1); //计算层次号 CC=(MN)/24+1; //计算层序号 CX=(MN)%24+1; //根据原来的仓储网格id查询仓库id BigDecimal warehouseId = DataChange.dataToBigDecimal(stringObjectMap.get("warehouseId")); Map map2=new HashMap<>(); map2.put("gradationNumber",CC); map2.put("sequenceNumber",CX); map2.put("stackingID",stackingId); map2.put("warehouseId",warehouseId); BigDecimal GridId = rmsPwarehouseGridMapper.selectGridId(map2); BigDecimal gmNumber =(BigDecimal) stringObjectMap.get("gmNumber"); BigDecimal weight = (BigDecimal) stringObjectMap.get("weight"); BigDecimal materialId =(BigDecimal) stringObjectMap.get("materialId"); //新增实时库存 wmspGridMaterial.setGmId(wmspGridMaterialMapper.getCount()); wmspGridMaterial.setGridId(GridId); wmspGridMaterial.setMaterialId(materialId); wmspGridMaterial.setGmNumber(gmNumber); wmspGridMaterial.setGmWeight(weight); wmspGridMaterial.setInsertTime(new Date()); wmspGridMaterial.setInsertUsername("admin"); wmspGridMaterial.setDeleted(new BigDecimal(0)); wmspGridMaterial.setStatus(new BigDecimal(2)); wmspGridMaterial.setStandardDataId(new BigDecimal(1)); wmspGridMaterialMapper.insertSelective(wmspGridMaterial); // 4、改变当前订单中已经稽核的吊牌的状态,改为已倒垛 // 根据吊牌扫描结果查找对应的吊牌扫描实绩Id BigDecimal resultId=wmspRestackScanResultMapper.getResultId(content); WmspRestackScanResult wmspRestackScanResult = new WmspRestackScanResult(); wmspRestackScanResult.setResultId(resultId); wmspRestackScanResult.setStatus(new BigDecimal(1)); i += wmspRestackScanResultMapper.updateByPrimaryKeySelective(wmspRestackScanResult); // 3、将当前订单的总数量减去上面当前订单中已经稽核的吊牌 WmspRestackMakeResult wmspRestackMakeResult = new WmspRestackMakeResult(); wmspRestackMakeResult.setResultId(new BigDecimal(restackMake)); BigDecimal quantity=wmspRestackMakeResultMapper.getQuantity(restackMake); // 判断当前订单的总数量是否小于或等于0 if (quantity.compareTo(new BigDecimal(1))==-1){ // 当存在时直接结束当前循环 break; } // 将当前订单的总数量减一 wmspRestackMakeResult.setQuantity(quantity.subtract(new BigDecimal(1))); i += wmspRestackMakeResultMapper.updateByPrimaryKeySelective(wmspRestackMakeResult); } return i; } public List> getMaterialTypeList(String warehouseid, BigDecimal stackingId, BigDecimal gradtionNumber) { return wmspGridMaterialMapper.getMaterialTypeList(warehouseid,stackingId,gradtionNumber); } // 新增库存盘点实绩 @Override public int insertStockTaking(String warehouseId, String materialCode, Integer quantity) { // 根据仓库id和物资类型编码,查询当前的今日库存以及今天入库和出库数量 int count = wmspGridMaterialMapper.getStockTakingList(warehouseId,materialCode); // 调用插入库存盘点实绩接口 // 创建库存盘点实绩类 WmspCheckWarehouse wmspCheckWarehouse = new WmspCheckWarehouse(); // 添加仓库id wmspCheckWarehouse.setWarehouseId(new BigDecimal(warehouseId)); // 添加物资ID BigDecimal materialId = wmspGridMaterialMapper.getMaterialIds(materialCode); wmspCheckWarehouse.setMaterialId(materialId); // 添加实际数量 wmspCheckWarehouse.setElectronicsMaterialAmount(new BigDecimal(count)); // 添加盘点数量 wmspCheckWarehouse.setRealMaterialAmount(new BigDecimal(quantity)); // 添加盈亏数 Integer checkProfitloss = count - quantity; wmspCheckWarehouse.setCheckProfitloss(new BigDecimal(checkProfitloss)); wmspCheckWarehouse.setInsertTime(new Date()); wmspCheckWarehouse.setInsertUsername("admin"); // 查找当前盘点库存实绩表的最大Id BigDecimal checkId = wmspCheckWarehouseMapper.getMaxId(); if (checkId==null){ checkId=new BigDecimal(1); }else{ checkId.add(new BigDecimal(1)); } wmspCheckWarehouse.setCheckId(checkId); int result = wmspCheckWarehouseMapper.insertSelective(wmspCheckWarehouse); return result; } @Override public List> getStockTakingList() { return wmspCheckWarehouseMapper.getStockTakingList(); } }