WMS入库单修改

This commit is contained in:
秦鸿展
2026-01-22 12:38:50 +08:00
parent db28bab895
commit 5cae9b8fa7
8 changed files with 268 additions and 0 deletions
@@ -139,6 +139,9 @@ public class NoticeOrderApplicationService {
* @param noticeOrderDO * @param noticeOrderDO
*/ */
private void setWarehouseInfo(NoticeOrderDO noticeOrderDO) { private void setWarehouseInfo(NoticeOrderDO noticeOrderDO) {
if (noticeOrderDO.getWarehouseId() == null) {
throw new ServiceException("仓库ID不能为空");
}
AjaxResult ajaxResult = systemServiceFeign.getWarehouseInfoByWarehouseId(noticeOrderDO.getWarehouseId()); AjaxResult ajaxResult = systemServiceFeign.getWarehouseInfoByWarehouseId(noticeOrderDO.getWarehouseId());
if(!"200".equals(String.valueOf(ajaxResult.get("code")))){ if(!"200".equals(String.valueOf(ajaxResult.get("code")))){
throw new ServiceException("获取仓库信息失败"); throw new ServiceException("获取仓库信息失败");
@@ -339,6 +339,9 @@ public class ShiftManageApplicationService {
* @param shiftManageDO * @param shiftManageDO
*/ */
private void setWarehouseInfo(ShiftManageDO shiftManageDO) { private void setWarehouseInfo(ShiftManageDO shiftManageDO) {
if (shiftManageDO.getWarehouseId() == null) {
throw new ServiceException("仓库ID不能为空");
}
AjaxResult ajaxResult = systemServiceFeign.getWarehouseInfoByWarehouseId(shiftManageDO.getWarehouseId()); AjaxResult ajaxResult = systemServiceFeign.getWarehouseInfoByWarehouseId(shiftManageDO.getWarehouseId());
if(!"200".equals(String.valueOf(ajaxResult.get("code")))){ if(!"200".equals(String.valueOf(ajaxResult.get("code")))){
throw new ServiceException("获取仓库信息失败"); throw new ServiceException("获取仓库信息失败");
@@ -17,14 +17,26 @@ import com.mhd.system.api.domain.WarehouseFeignPO;
import com.mhd.system.api.domain.cache.AssociationWarehouseCacheDO; import com.mhd.system.api.domain.cache.AssociationWarehouseCacheDO;
import com.mhd.system.api.domain.cache.SystemServiceCacheUtil; import com.mhd.system.api.domain.cache.SystemServiceCacheUtil;
import com.mhd.system.api.model.LoginUser; import com.mhd.system.api.model.LoginUser;
import com.mhd.common.core.utils.poi.ExcelUtil;
import com.mhd.wms.domain.stockInOrder.repository.po.StockInOrderPO; import com.mhd.wms.domain.stockInOrder.repository.po.StockInOrderPO;
import com.mhd.wms.domain.stockInOrder.repository.todo.StockInOrderDO; import com.mhd.wms.domain.stockInOrder.repository.todo.StockInOrderDO;
import com.mhd.wms.domain.inMaterialDetail.repository.todo.InMaterialDetailDO;
import com.mhd.wms.domain.stockInOrder.service.StockInOrderDomainService; import com.mhd.wms.domain.stockInOrder.service.StockInOrderDomainService;
import com.mhd.wms.domain.materialBaseInfo.repository.facade.IMaterialBaseInfoService;
import com.mhd.wms.domain.materialBaseInfo.repository.todo.MaterialBaseInfoDO;
import com.mhd.wms.domain.materialBaseInfo.repository.po.MaterialBaseInfoPO;
import com.mhd.wms.interfaces.dto.stockInOrder.StockInOrderImportRowDTO;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.web.multipart.MultipartFile;
import java.io.InputStream;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
/** /**
* 入库单ApplicationService * 入库单ApplicationService
@@ -41,6 +53,8 @@ public class StockInOrderApplicationService {
private UserServiceFeign userServiceFeign; private UserServiceFeign userServiceFeign;
@Autowired @Autowired
private SystemServiceFeign systemServiceFeign; private SystemServiceFeign systemServiceFeign;
@Autowired
private IMaterialBaseInfoService materialBaseInfoService;
/** /**
@@ -106,6 +120,161 @@ public class StockInOrderApplicationService {
return stockInOrderDomainService.getInfo(inOrderId); return stockInOrderDomainService.getInfo(inOrderId);
} }
/**
* 导入入库单(Excel:一行=一个物料明细;以【委托编号NO】分组为一张入库单)
*/
public Boolean importData(MultipartFile file) {
if (file == null || file.isEmpty()) {
throw new ServiceException("导入文件不能为空");
}
LoginUser loginUser = SecurityUtils.getLoginUser();
if (loginUser == null) {
throw new ServiceException("登录已失效,请重新登录");
}
try (InputStream is = file.getInputStream()) {
ExcelUtil<StockInOrderImportRowDTO> util = new ExcelUtil<>(StockInOrderImportRowDTO.class);
List<StockInOrderImportRowDTO> rows = util.importExcel(is, 1);
if (rows == null || rows.isEmpty()) {
throw new ServiceException("导入数据为空");
}
// 过滤掉关键字段都为空的空行
List<StockInOrderImportRowDTO> validRows = rows.stream()
.filter(r -> ObjectUtil.isNotNull(r.getMaterialBaseInfoId()) || ObjectUtil.isNotNull(r.getShipperId()) || StringUtils.isNotBlank(r.getConsignmentNo()))
.collect(Collectors.toList());
if (validRows.isEmpty()) {
throw new ServiceException("导入数据为空(可能全为空行)");
}
// 以委托编号NO分组;若为空则归到同一组(不推荐)
Map<String, List<StockInOrderImportRowDTO>> groupMap = validRows.stream()
.collect(Collectors.groupingBy(r -> StringUtils.isBlank(r.getConsignmentNo()) ? "__EMPTY_CONSIGNMENT__" : r.getConsignmentNo()));
List<StockInOrderDO> orderList = new ArrayList<>();
for (Map.Entry<String, List<StockInOrderImportRowDTO>> entry : groupMap.entrySet()) {
List<StockInOrderImportRowDTO> groupRows = entry.getValue();
StockInOrderImportRowDTO h = groupRows.get(0);
if (ObjectUtil.isNull(h.getWarehouseId())) {
// 兜底:使用登录人当前关联仓库
AssociationWarehouseCacheDO associationWarehouseCacheDO = SystemServiceCacheUtil.getAssociationWarehouseCache(loginUser.getUserid());
if (associationWarehouseCacheDO == null || associationWarehouseCacheDO.getWarehouseId() == null) {
throw new ServiceException("导入失败:仓库ID为空,且未配置用户关联仓库");
}
h.setWarehouseId(associationWarehouseCacheDO.getWarehouseId());
}
if (ObjectUtil.isNull(h.getShipperId())) {
throw new ServiceException("导入失败:货主ID不能为空(委托编号NO=" + h.getConsignmentNo() + "");
}
if (StringUtils.isBlank(h.getOrderTypeCode())) {
throw new ServiceException("导入失败:入库单据类型不能为空(委托编号NO=" + h.getConsignmentNo() + "");
}
StockInOrderDO order = new StockInOrderDO();
// 组织/审计字段
order.setOrganizationId(loginUser.getUserPo().getOrganizationId());
order.setOrganizationName(loginUser.getUserPo().getOrganizationName());
order.setTopOrganizationId(loginUser.getUserPo().getTopOrganizationId());
order.setCreateBy(loginUser.getUserid());
order.setCreateByName(loginUser.getUsername());
// 必填/基础字段
order.setWarehouseId(h.getWarehouseId());
order.setShipperId(h.getShipperId());
order.setSupplierId(h.getSupplierId());
order.setOrderTypeCode(h.getOrderTypeCode());
order.setConsignmentNo(h.getConsignmentNo());
order.setRemark(h.getRemark());
// 报关表头字段
order.setTo(h.getTo());
order.setContactPerson(h.getContactPerson());
order.setVehicleInfo(h.getVehicleInfo());
order.setTel(h.getTel());
order.setDriverSignature(h.getDriverSignature());
order.setFax(h.getFax());
order.setDeclarationArea(h.getDeclarationArea());
order.setManufacturer(h.getManufacturer());
order.setCustomsBrokerInfo(h.getCustomsBrokerInfo());
order.setDeliveryAddress(h.getDeliveryAddress());
order.setEntryExitCustoms(h.getEntryExitCustoms());
order.setOriginDestinationCountry(h.getOriginDestinationCountry());
order.setCarrier(h.getCarrier());
order.setContainerNo(h.getContainerNo());
order.setTransportMethod(h.getTransportMethod());
order.setSupervisionMethod(h.getSupervisionMethod());
order.setCustomsInspection(h.getCustomsInspection());
order.setNeedCustomsDeclaration(h.getNeedCustomsDeclaration());
order.setNeedTransport(h.getNeedTransport());
// 日期字段:此处暂不做字符串转Date,避免格式不一致导致导入失败(如需强校验可再扩展)
// 明细
List<InMaterialDetailDO> details = new ArrayList<>();
for (StockInOrderImportRowDTO r : groupRows) {
// 如果物料基础信息ID为空,尝试根据商品名称查询
Long materialBaseInfoId = r.getMaterialBaseInfoId();
if (ObjectUtil.isNull(materialBaseInfoId) && StringUtils.isNotBlank(r.getMaterialName())) {
MaterialBaseInfoDO materialBaseInfoDO = new MaterialBaseInfoDO();
materialBaseInfoDO.setMaterialName(r.getMaterialName());
materialBaseInfoDO.setShipperId(h.getShipperId());
List<MaterialBaseInfoPO> materialList = materialBaseInfoService.queryList(materialBaseInfoDO);
if (materialList == null || materialList.isEmpty()) {
throw new ServiceException("导入失败:根据商品名称【" + r.getMaterialName() + "】未找到物料基础信息(委托编号NO=" + h.getConsignmentNo() + "");
}
if (materialList.size() > 1) {
throw new ServiceException("导入失败:商品名称【" + r.getMaterialName() + "】匹配到多条物料基础信息,请使用物料基础信息ID(委托编号NO=" + h.getConsignmentNo() + "");
}
materialBaseInfoId = materialList.get(0).getMaterialBaseInfoId();
}
if (ObjectUtil.isNull(materialBaseInfoId)) {
throw new ServiceException("导入失败:物料基础信息ID不能为空,且商品名称未匹配到物料(委托编号NO=" + h.getConsignmentNo() + "");
}
// 优先使用仓库数量,如果为空则使用计划数量
BigDecimal quantity = r.getWarehouseQuantity() != null ? r.getWarehouseQuantity() : r.getQuantity();
if (quantity == null) {
throw new ServiceException("导入失败:计划数量或仓库数量不能为空(委托编号NO=" + h.getConsignmentNo() + ",物料基础信息ID=" + materialBaseInfoId + "");
}
InMaterialDetailDO d = new InMaterialDetailDO();
d.setMaterialBaseInfoId(materialBaseInfoId);
d.setQuantity(quantity);
d.setSpecification(r.getSpecification());
d.setSkuCode(r.getSkuCode());
d.setInvoiceNo(r.getInvoiceNo());
d.setDeclaredQuantity(r.getDeclaredQuantity());
d.setDeclaredUnit(r.getDeclaredUnit());
d.setLiter(r.getLiter());
d.setBoxCount(r.getBoxCount());
d.setPieceCount(r.getPieceCount());
d.setDimensions(r.getDimensions());
d.setOutboundQuantity(r.getOutboundQuantity());
d.setUnit(r.getUnit());
d.setTotalNetWeight(r.getTotalNetWeight());
d.setTotalGrossWeight(r.getTotalGrossWeight());
d.setTotalVolume(r.getTotalVolume());
d.setTotalArea(r.getTotalArea());
d.setBatchRefNo(r.getBatchRefNo());
d.setSheetRefNo(r.getSheetRefNo());
d.setCountryOfOrigin(r.getCountryOfOrigin());
d.setBoxPalletNo(r.getBoxPalletNo());
d.setTotalPrice(r.getTotalPrice());
d.setCurrency(r.getCurrency());
d.setRemark(r.getDetailRemark());
details.add(d);
}
order.setMaterialDetailList(details);
orderList.add(order);
}
return stockInOrderDomainService.batchInsert(orderList);
} catch (ServiceException e) {
throw e;
} catch (Exception e) {
log.error("导入入库单失败", e);
throw new ServiceException("导入入库单失败:" + e.getMessage());
}
}
/** /**
* @description 审核入库单 * @description 审核入库单
@@ -148,6 +317,9 @@ public class StockInOrderApplicationService {
* @param stockInOrderDO * @param stockInOrderDO
*/ */
private void setWarehouseInfo(StockInOrderDO stockInOrderDO) { private void setWarehouseInfo(StockInOrderDO stockInOrderDO) {
if (stockInOrderDO.getWarehouseId() == null) {
throw new ServiceException("仓库ID不能为空");
}
AjaxResult ajaxResult = systemServiceFeign.getWarehouseInfoByWarehouseId(stockInOrderDO.getWarehouseId()); AjaxResult ajaxResult = systemServiceFeign.getWarehouseInfoByWarehouseId(stockInOrderDO.getWarehouseId());
if(!"200".equals(String.valueOf(ajaxResult.get("code")))){ if(!"200".equals(String.valueOf(ajaxResult.get("code")))){
throw new ServiceException("获取仓库信息失败"); throw new ServiceException("获取仓库信息失败");
@@ -384,6 +384,9 @@ public class StockOutOrderApplicationService {
* @param stockOutOrderDO * @param stockOutOrderDO
*/ */
private void setWarehouseInfo(StockOutOrderDO stockOutOrderDO) { private void setWarehouseInfo(StockOutOrderDO stockOutOrderDO) {
if (stockOutOrderDO.getWarehouseId() == null) {
throw new ServiceException("仓库ID不能为空");
}
AjaxResult ajaxResult = systemServiceFeign.getWarehouseInfoByWarehouseId(stockOutOrderDO.getWarehouseId()); AjaxResult ajaxResult = systemServiceFeign.getWarehouseInfoByWarehouseId(stockOutOrderDO.getWarehouseId());
if(!"200".equals(String.valueOf(ajaxResult.get("code")))){ if(!"200".equals(String.valueOf(ajaxResult.get("code")))){
throw new ServiceException("获取仓库信息失败"); throw new ServiceException("获取仓库信息失败");
@@ -645,6 +645,9 @@ public class StockReceiptOrderApplicationService {
* @param stockReceiptOrderDO * @param stockReceiptOrderDO
*/ */
private void setWarehouseInfo(StockReceiptOrderDO stockReceiptOrderDO) { private void setWarehouseInfo(StockReceiptOrderDO stockReceiptOrderDO) {
if (stockReceiptOrderDO.getWarehouseId() == null) {
throw new ServiceException("仓库ID不能为空");
}
AjaxResult ajaxResult = systemServiceFeign.getWarehouseInfoByWarehouseId(stockReceiptOrderDO.getWarehouseId()); AjaxResult ajaxResult = systemServiceFeign.getWarehouseInfoByWarehouseId(stockReceiptOrderDO.getWarehouseId());
if(!"200".equals(String.valueOf(ajaxResult.get("code")))){ if(!"200".equals(String.valueOf(ajaxResult.get("code")))){
throw new ServiceException("获取仓库信息失败"); throw new ServiceException("获取仓库信息失败");
@@ -271,6 +271,7 @@ public class StockInOrderDTO extends StockInOrderBaseDTO {
@Excel(name = "申报地关区") @Excel(name = "申报地关区")
private String declarationArea; private String declarationArea;
@ApiModelProperty("生产商") @ApiModelProperty("生产商")
@Excel(name = "生产商") @Excel(name = "生产商")
private String manufacturer; private String manufacturer;
@@ -3,6 +3,8 @@ package com.mhd.wms.interfaces.facadeApi.stockInOrder;
import com.mhd.common.core.web.controller.BaseController; import com.mhd.common.core.web.controller.BaseController;
import com.mhd.common.core.web.domain.AjaxResult; import com.mhd.common.core.web.domain.AjaxResult;
import com.mhd.common.core.web.page.TableDataInfo; import com.mhd.common.core.web.page.TableDataInfo;
import com.mhd.common.core.exception.ServiceException;
import com.mhd.common.core.utils.StringUtils;
import com.mhd.wms.application.service.stockInOrder.StockInOrderApplicationService; import com.mhd.wms.application.service.stockInOrder.StockInOrderApplicationService;
import com.mhd.wms.domain.stockInOrder.repository.po.StockInOrderPO; import com.mhd.wms.domain.stockInOrder.repository.po.StockInOrderPO;
import com.mhd.wms.domain.stockInOrder.repository.todo.StockInOrderDO; import com.mhd.wms.domain.stockInOrder.repository.todo.StockInOrderDO;
@@ -11,6 +13,7 @@ import com.mhd.wms.interfaces.dto.stockInOrder.StockInOrderDTO;
import io.swagger.annotations.ApiOperation; import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import javax.annotation.Resource; import javax.annotation.Resource;
import java.util.List; import java.util.List;
@@ -80,6 +83,16 @@ public class StockInOrderApi extends BaseController {
return AjaxResult.success(stockInOrderApplicationService.getInfo(inOrderId)); return AjaxResult.success(stockInOrderApplicationService.getInfo(inOrderId));
} }
/**
* 导入入库单
*/
@ApiOperation("导入入库单")
@PostMapping("/importData")
public AjaxResult importData(MultipartFile file)
{
return AjaxResult.success(stockInOrderApplicationService.importData(file));
}
/** /**
* 审核入库单 * 审核入库单
@@ -293,6 +293,76 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
#{item} #{item}
</foreach> </foreach>
</if> </if>
<!-- 报关相关字段查询条件 -->
<if test="to != null and to != ''">
and a."TO" like concat('%', #{to}, '%')
</if>
<if test="contactPerson != null and contactPerson != ''">
and a.CONTACT_PERSON like concat('%', #{contactPerson}, '%')
</if>
<if test="vehicleInfo != null and vehicleInfo != ''">
and a.VEHICLE_INFO like concat('%', #{vehicleInfo}, '%')
</if>
<if test="consignmentNo != null and consignmentNo != ''">
and a.CONSIGNMENT_NO like concat('%', #{consignmentNo}, '%')
</if>
<if test="tel != null and tel != ''">
and a.TEL like concat('%', #{tel}, '%')
</if>
<if test="driverSignature != null and driverSignature != ''">
and a.DRIVER_SIGNATURE like concat('%', #{driverSignature}, '%')
</if>
<if test="fax != null and fax != ''">
and a.FAX like concat('%', #{fax}, '%')
</if>
<if test="declarationArea != null and declarationArea != ''">
and a.DECLARATION_AREA like concat('%', #{declarationArea}, '%')
</if>
<if test="manufacturer != null and manufacturer != ''">
and a.MANUFACTURER like concat('%', #{manufacturer}, '%')
</if>
<if test="customsBrokerInfo != null and customsBrokerInfo != ''">
and a.CUSTOMS_BROKER_INFO like concat('%', #{customsBrokerInfo}, '%')
</if>
<if test="deliveryAddress != null and deliveryAddress != ''">
and a.DELIVERY_ADDRESS like concat('%', #{deliveryAddress}, '%')
</if>
<if test="entryExitCustoms != null and entryExitCustoms != ''">
and a.ENTRY_EXIT_CUSTOMS like concat('%', #{entryExitCustoms}, '%')
</if>
<if test="originDestinationCountry != null and originDestinationCountry != ''">
and a.ORIGIN_DESTINATION_COUNTRY like concat('%', #{originDestinationCountry}, '%')
</if>
<if test="carrier != null and carrier != ''">
and a.CARRIER like concat('%', #{carrier}, '%')
</if>
<if test="containerNo != null and containerNo != ''">
and a.CONTAINER_NO = #{containerNo}
</if>
<if test="transportMethod != null and transportMethod != ''">
and a.TRANSPORT_METHOD = #{transportMethod}
</if>
<if test="supervisionMethod != null and supervisionMethod != ''">
and a.SUPERVISION_METHOD = #{supervisionMethod}
</if>
<if test="customsInspection != null and customsInspection != ''">
and a.CUSTOMS_INSPECTION = #{customsInspection}
</if>
<if test="needCustomsDeclaration != null and needCustomsDeclaration != ''">
and a.NEED_CUSTOMS_DECLARATION = #{needCustomsDeclaration}
</if>
<if test="needTransport != null and needTransport != ''">
and a.NEED_TRANSPORT = #{needTransport}
</if>
<if test="warehouseDate != null">
and a.WAREHOUSE_DATE = #{warehouseDate}
</if>
<if test="completionTime != null">
and a.COMPLETION_TIME = #{completionTime}
</if>
<if test="orderDate != null">
and a.ORDER_DATE = #{orderDate}
</if>
<choose> <choose>
<when test="delFlag != null"> and a.del_flag = #{delFlag} </when> <when test="delFlag != null"> and a.del_flag = #{delFlag} </when>
<otherwise> and a.del_flag = 1 </otherwise> <otherwise> and a.del_flag = 1 </otherwise>