package com.steerinfo.dil.service.impl; import com.steerinfo.dil.mapper.RmsWarehouseMapper; import com.steerinfo.dil.mapper.WmspInventoryCloseMapper; import com.steerinfo.dil.model.WmspInventoryClose; import com.steerinfo.dil.service.IWmspInventoryCloseService; import com.steerinfo.dil.util.DataChange; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.scheduling.annotation.Async; import org.springframework.scheduling.annotation.Scheduled; import org.springframework.stereotype.Service; import java.math.BigDecimal; import java.util.Date; import java.util.List; import java.util.Map; /** * @author luobang * @create 2021-09-08 14:42 */ @Service public class WmspInventoryCloseServiceImpl implements IWmspInventoryCloseService { @Autowired WmspInventoryCloseMapper wmspInventoryCloseMapper; @Autowired RmsWarehouseMapper rmsWarehouseMapper; @Override public List> getWmspInventoryClose(Map mapValue) { List> maps = wmspInventoryCloseMapper.selectWmspInventoryClose(mapValue); return maps; } @Override @Scheduled(cron = "1 45 23 * * ? ") @Async("threadPoolTaskExecutor") public int addInventoryClose() { int i = 0; // int count = wmspInventoryCloseMapper.getClose(); // if(count == 0){ //高线库,一棒库,二棒库,配送库 List> mapList = rmsWarehouseMapper.getWarehouseName(); //遍历四个仓库 for(Map map:mapList) { BigDecimal warehouseId = DataChange.dataToBigDecimal(map.get("id")); //先获取收发存中的物资 List> materialList = wmspInventoryCloseMapper.selectSendReceive(warehouseId); for(Map map1:materialList){ WmspInventoryClose wmspInventoryClose = new WmspInventoryClose(); //主键自增 BigDecimal inventoryCloseId = wmspInventoryCloseMapper.addInventoryCloseId(); wmspInventoryClose.setCloseId(inventoryCloseId); //增加仓库id wmspInventoryClose.setWarehouseId(warehouseId); //增加物资id BigDecimal materialId = DataChange.dataToBigDecimal(map1.get("materialId")); wmspInventoryClose.setMaterialId(materialId); //获取一个仓库中的一种物资一个月之内的入库数据 BigDecimal closeThismonthInbound = wmspInventoryCloseMapper.selectCloseThismonthInbound(warehouseId,materialId); if(closeThismonthInbound == null){ wmspInventoryClose.setCloseThismonthInbound(new BigDecimal(0)); }else { wmspInventoryClose.setCloseThismonthInbound(closeThismonthInbound); } BigDecimal closeThismonthInbound1 = wmspInventoryClose.getCloseThismonthInbound(); //获取一个仓库的一种物资一个月之内的出库数据 BigDecimal closeThismonthOutbound = wmspInventoryCloseMapper.selectCloseThismonthOutbound(warehouseId,materialId); if(closeThismonthOutbound == null){ wmspInventoryClose.setCloseThismonthOutbound(new BigDecimal(0)); }else { wmspInventoryClose.setCloseThismonthOutbound(closeThismonthOutbound); } BigDecimal closeThismonthOutbound1 = wmspInventoryClose.getCloseThismonthOutbound(); //获取上一个月的一种物资的库存数据 BigDecimal closeLastmonthInventory = wmspInventoryCloseMapper.selectCloseLastmonthInventory(warehouseId,materialId); if(closeLastmonthInventory==null){ wmspInventoryClose.setCloseLastmonthInventory(new BigDecimal(0)); }else { wmspInventoryClose.setCloseLastmonthInventory(closeLastmonthInventory); } //获取一个仓库的一种物资一个月之内的总库存数据 BigDecimal closeLastmonthInventory1 = wmspInventoryClose.getCloseLastmonthInventory(); BigDecimal closeThismonthInventory = new BigDecimal(closeThismonthInbound1.intValue() - closeThismonthOutbound1.intValue() + closeLastmonthInventory1.intValue()); wmspInventoryClose.setCloseThismonthInventory(closeThismonthInventory); wmspInventoryClose.setInsertTime(new Date()); wmspInventoryClose.setInsertUsername("admin"); wmspInventoryClose.setDeleted(new BigDecimal(1)); i+=wmspInventoryCloseMapper.insertSelective(wmspInventoryClose); } } //} return i; } @Override public int getClose() { return wmspInventoryCloseMapper.getClose(); } }