package org.jeecg.modules.lsw.service.impl; import com.baomidou.mybatisplus.core.metadata.IPage; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import org.apache.commons.lang.StringUtils; import org.jeecg.common.constant.CommonConstant; import org.jeecg.common.exception.JeecgBootException; import org.jeecg.modules.base.entity.LineSideWarehouse; import org.jeecg.modules.base.service.ILineSideWarehouseService; import org.jeecg.modules.lsw.entity.LswMaterial; import org.jeecg.modules.lsw.entity.LswMaterialInbound; import org.jeecg.modules.lsw.entity.LswMaterialInventory; import org.jeecg.modules.lsw.entity.LswMaterialOutbound; import org.jeecg.modules.lsw.enums.MaterialInboundCategory; import org.jeecg.modules.lsw.enums.MaterialInventoryCategoryEnum; import org.jeecg.modules.lsw.enums.MaterialOutboundCategory; import org.jeecg.modules.lsw.mapper.LswMaterialInboundMapper; import org.jeecg.modules.lsw.service.ILswMaterialInboundService; import org.jeecg.modules.lsw.service.ILswMaterialInventoryService; import org.jeecg.modules.lsw.service.ILswMaterialOutboundService; import org.jeecg.modules.lsw.service.ILswMaterialService; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; import javax.servlet.http.HttpServletRequest; import java.util.Date; import java.util.HashMap; import java.util.Map; /** * @Description: 物料入库单 * @Author: jeecg-boot * @Date: 2025-06-30 * @Version: V1.0 */ @Service public class LswMaterialInboundServiceImpl extends ServiceImpl implements ILswMaterialInboundService { @Autowired private ILswMaterialInventoryService inventoryService; @Autowired private ILswMaterialService materialService; @Autowired private ILineSideWarehouseService lineSideWarehouseService; @Autowired private ILswMaterialOutboundService materialOutboundService; @Override public IPage> getlswMaterialInboundListData(Integer pageNo, Integer pageSize, HttpServletRequest req) { IPage pageData = new Page(pageNo, pageSize); Map paramMap = new HashMap(); Map parameterMap = req.getParameterMap(); if (null != parameterMap) { if (parameterMap.containsKey("materialNumber") && StringUtils.isNotBlank(parameterMap.get("materialNumber")[0])) { paramMap.put("materialNumber", parameterMap.get("materialNumber")[0]); } if (parameterMap.containsKey("materialName") && StringUtils.isNotBlank(parameterMap.get("materialName")[0])) { paramMap.put("materialName", parameterMap.get("materialName")[0].trim()); } if (parameterMap.containsKey("batchNumber") && StringUtils.isNotBlank(parameterMap.get("batchNumber")[0])) { paramMap.put("batchNumber", parameterMap.get("batchNumber")[0].trim()); } } return super.getBaseMapper().getlswMaterialInboundListData(pageData, paramMap); } @Override @Transactional(rollbackFor = Exception.class) public boolean inboundMaterial(LswMaterialInbound materialInbound) { if (StringUtils.isBlank(materialInbound.getMaterialNumber()) || StringUtils.isBlank(materialInbound.getFactoryId()) || StringUtils.isBlank(materialInbound.getWarehouseId()) || materialInbound.getQuantity() == null || materialInbound.getQuantity().intValue() < 1 || StringUtils.isBlank(materialInbound.getBatchNumber()) || StringUtils.isBlank(materialInbound.getOriginalCode()) || StringUtils.isBlank(materialInbound.getOriginalName()) || StringUtils.isBlank(materialInbound.getInboundCategory())) { throw new JeecgBootException("参数错误!"); } LswMaterial material = materialService.queryByMaterialNumber(materialInbound.getMaterialNumber()); if (material == null) { throw new JeecgBootException("物料编号不存在!"); } LineSideWarehouse warehouse = lineSideWarehouseService.getById(materialInbound.getWarehouseId()); if (warehouse == null) { throw new JeecgBootException("线边库不存在!"); } String heatTreatmentFlag = CommonConstant.STATUS_0; if (materialInbound.getInboundCategory().equals(MaterialInboundCategory.HEAT_TREATMENT_INBOUND.name())) { heatTreatmentFlag = CommonConstant.STATUS_1; } //库存类型 String inventoryCategory = MaterialInventoryCategoryEnum.INBOUND.name(); if (materialInbound.getInboundCategory().equals(MaterialInboundCategory.MATERIAL_INNER_TRANSFER.name())) { inventoryCategory = MaterialInventoryCategoryEnum.TRANSFER.name(); //查询来源线边库 LineSideWarehouse lineSideWarehouse = lineSideWarehouseService.queryByWarehouseCode(materialInbound.getOriginalCode()); if (lineSideWarehouse == null) { throw new JeecgBootException("未找到来源线边库!"); } //调拨 出库原始库存 LswMaterialInventory originalInventory = inventoryService.queryByMaterialNumberAndBatchNumber(materialInbound.getMaterialNumber(), materialInbound.getBatchNumber(), lineSideWarehouse.getId()); if (originalInventory == null) { throw new JeecgBootException("未找到来源线边库库存!"); } if (materialInbound.getQuantity().compareTo(originalInventory.getQuantity()) != 0) { throw new JeecgBootException("调拨数量需要等于来源库存数量!"); } //出库信息 LswMaterialOutbound outbound = new LswMaterialOutbound(); outbound.setWarehouseId(lineSideWarehouse.getId()); outbound.setFactoryId(lineSideWarehouse.getFactoryId()); outbound.setOutboundStaff(materialInbound.getReceiver()); outbound.setMaterialName(materialInbound.getMaterialName()); outbound.setMaterialNumber(materialInbound.getMaterialNumber()); outbound.setQuantity(originalInventory.getQuantity()); outbound.setBatchNumber(originalInventory.getBatchNumber()); outbound.setInventoryId(originalInventory.getId()); outbound.setOutboundCategory(MaterialOutboundCategory.MATERIAL_INNER_TRANSFER.name()); //调拨出库 boolean b = materialOutboundService.outboundMaterial(outbound); if (!b) { throw new JeecgBootException("调拨出库失败!"); } } else if (materialInbound.getInboundCategory().equals(MaterialInboundCategory.PRODUCTION_UNLOADING.name())) { inventoryCategory = MaterialInventoryCategoryEnum.UNLOADING.name(); } //保存入库信息 materialInbound.setDelFlag(CommonConstant.DEL_FLAG_0); materialInbound.setReceiveTime(new Date()); super.save(materialInbound); //保存库存信息 LswMaterialInventory lswMaterialInventory = new LswMaterialInventory(materialInbound, material.getId(), inventoryCategory, heatTreatmentFlag); inventoryService.save(lswMaterialInventory); return true; } }