基础数据物料管理批次为空可以新增

This commit is contained in:
秦鸿展
2026-04-02 16:42:35 +08:00
parent ebb3d7c019
commit 4541ce287b
3 changed files with 36 additions and 5 deletions
@@ -45,6 +45,7 @@ import org.springframework.web.multipart.MultipartFile;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
@@ -207,6 +208,30 @@ public class MaterialBaseInfoApplicationService {
*/
@Transactional(rollbackFor = Exception.class)
public Boolean insert(MaterialBaseInfoDO materialBaseInfoDO) {
// 新增时如果前端未传 organizationName,则使用当前登录用户的组织名称补齐
if (materialBaseInfoDO != null && StringUtils.isBlank(materialBaseInfoDO.getOrganizationName())) {
LoginUser loginUser = SecurityUtils.getLoginUser();
if (loginUser != null && loginUser.getUserPo() != null
&& StringUtils.isNotBlank(loginUser.getUserPo().getOrganizationName())) {
materialBaseInfoDO.setOrganizationName(loginUser.getUserPo().getOrganizationName());
}
}
// 新增时如果前端未传创建人/创建时间,则使用当前登录用户补齐
if (materialBaseInfoDO != null
&& (materialBaseInfoDO.getCreateBy() == null || materialBaseInfoDO.getCreateTime() == null)) {
LoginUser loginUser = SecurityUtils.getLoginUser();
if (loginUser != null) {
if (materialBaseInfoDO.getCreateBy() == null) {
materialBaseInfoDO.setCreateBy(loginUser.getUserid());
}
if (StringUtils.isBlank(materialBaseInfoDO.getCreateByName())) {
materialBaseInfoDO.setCreateByName(loginUser.getUsername());
}
if (materialBaseInfoDO.getCreateTime() == null) {
materialBaseInfoDO.setCreateTime(new Date());
}
}
}
Long materialBaseInfoId = materialBaseInfoDomainService.insert(materialBaseInfoDO);
materialBaseInfoDO.setMaterialBaseInfoId(materialBaseInfoId);
//商品规则
@@ -111,10 +111,12 @@ public class MaterialGoodsRuleDomainService {
* @param materialGoodsRuleDO
*/
private void batchParam(MaterialGoodsRuleDO materialGoodsRuleDO){
if (ObjectUtil.isNull(materialGoodsRuleDO.getBatchId())){
throw new ServiceException("批次信息不能为空");
// 批次信息允许为空:batchId 为空时不做封装,直接跳过即可
Long batchId = materialGoodsRuleDO.getBatchId();
if (ObjectUtil.isNull(batchId) || batchId <= 0) {
return;
}
AjaxResult ajaxResult = systemServiceFeign.getBatchInfoByBatchId(materialGoodsRuleDO.getBatchId());
AjaxResult ajaxResult = systemServiceFeign.getBatchInfoByBatchId(batchId);
if(!"200".equals(String.valueOf(ajaxResult.get("code")))){
throw new ServiceException("获取批次信息失败");
}
@@ -1,6 +1,7 @@
package com.mhd.wms.interfaces.facadeApi.materialBaseInfo;
import com.mhd.common.core.domain.entity.R;
import com.mhd.common.core.exception.ServiceException;
import com.mhd.common.core.web.controller.BaseController;
import com.mhd.common.core.web.domain.AjaxResult;
import com.mhd.common.core.web.page.TableDataInfo;
@@ -54,11 +55,14 @@ public class MaterialBaseInfoApi extends BaseController {
@PostMapping("/edit")
public AjaxResult edit(@RequestBody MaterialBaseInfoFeign materialBaseInfoDTO)
{
if (materialBaseInfoDTO == null) {
throw new ServiceException("请求参数不能为空");
}
//转换实体
MaterialBaseInfoDO materialBaseInfoDO = materialBaseInfoAssembler.toDO2(materialBaseInfoDTO);
if(1 == materialBaseInfoDTO.getUpdateFeign()){
if (Integer.valueOf(1).equals(materialBaseInfoDTO.getUpdateFeign())) {
return toAjax(materialBaseInfoApplicationService.update(materialBaseInfoDO));
}else {
} else {
return toAjax(materialBaseInfoApplicationService.insert(materialBaseInfoDO));
}
}