fix:调整物料批次接口

This commit is contained in:
shusir
2026-01-29 15:39:16 +08:00
parent 2111c8b3ad
commit 1c5588a05a
10 changed files with 144 additions and 17 deletions

View File

@@ -93,8 +93,9 @@ public class MaterialBatchController implements BusinessControllerMarker {
@Operation(summary = "获得物料批次分页")
// @PreAuthorize("@ss.hasPermission('qms:material-batch:query')")
public CommonResult<PageResult<MaterialBatchRespVO>> getMaterialBatchPage(@Valid MaterialBatchPageReqVO pageReqVO) {
PageResult<MaterialBatchDO> pageResult = materialBatchService.getMaterialBatchPage(pageReqVO);
return success(BeanUtils.toBean(pageResult, MaterialBatchRespVO.class));
PageResult<MaterialBatchRespVO> pageResult = materialBatchService.getMaterialBatchPageWithPdtInfo(pageReqVO);
// return success(BeanUtils.toBean(pageResult, MaterialBatchRespVO.class));
return success(pageResult);
}
@GetMapping("/export-excel")
@@ -117,6 +118,14 @@ public class MaterialBatchController implements BusinessControllerMarker {
return success(materialBatchService.assignMaterialBatchGongduan(createReqVOs));
}
@PutMapping("/submit")
@Operation(summary = "提交物料批次")
@Parameter(name = "id", required = true)
public CommonResult<Boolean> submitMaterialBatch(@RequestParam("id") Long id) {
// return success(materialBatchService.submitMaterialBatch(id));
return null;
}
@GetMapping("gongduan-page")
@Operation(summary = "获取工段列表")
@Parameter(name = "id", description = "物料批次 id", required = true, example = "1054")

View File

@@ -19,6 +19,9 @@ public class MaterialBatchPageReqVO extends PageParam {
@Schema(description = "物料大类id", example = "9381")
private Long productId;
@Schema(description = "是否需要组装 children")
private Boolean children = false;
@Schema(description = "批次编号")
private String batchNo;

View File

@@ -7,6 +7,8 @@ import org.springframework.format.annotation.DateTimeFormat;
import java.math.BigDecimal;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.util.List;
import com.alibaba.excel.annotation.*;
@Schema(description = "管理后台 - 物料批次 Response VO")
@@ -26,6 +28,18 @@ public class MaterialBatchRespVO {
@ExcelProperty("物料大类id")
private Long productId;
@Schema(description = "物料大类名称")
@ExcelProperty("物料大类名称")
private String productName;
@Schema(description = "物料大类编码")
@ExcelProperty("物料大类编码")
private String productCode;
@Schema(description = "物料大类型号")
@ExcelProperty("物料大类型号")
private String productModelNo;
@Schema(description = "批次编号")
@ExcelProperty("批次编号")
private String batchNo;
@@ -44,11 +58,11 @@ public class MaterialBatchRespVO {
@Schema(description = "生产日期")
@ExcelProperty("生产日期")
private LocalDate manufacturerDate;
private LocalDateTime manufacturerDate;
@Schema(description = "到期日期")
@ExcelProperty("到期日期")
private LocalDate dueDate;
private LocalDateTime dueDate;
@Schema(description = "分配部门id")
@ExcelProperty("分配部门id")
@@ -90,4 +104,7 @@ public class MaterialBatchRespVO {
@ExcelProperty("创建时间")
private LocalDateTime createTime;
@Schema(description = "子批次-工段")
private List<MaterialBatchRespVO> children;
}

View File

@@ -1,5 +1,6 @@
package com.zt.plat.module.qms.resource.material.controller.vo;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.zt.plat.module.qms.resource.material.valid.AddGroup;
import com.zt.plat.module.qms.resource.material.valid.UpdateGroup;
import io.swagger.v3.oas.annotations.media.Schema;
@@ -10,6 +11,7 @@ import lombok.Data;
import java.math.BigDecimal;
import java.time.LocalDate;
import java.time.LocalDateTime;
@Schema(description = "管理后台 - 物料批次新增/修改 Request VO")
@Data
@@ -43,10 +45,10 @@ public class MaterialBatchSaveReqVO {
@Schema(description = "生产日期")
@NotNull(groups = AddGroup.class, message = "生产日期不能为空")
private LocalDate manufacturerDate;
private LocalDateTime manufacturerDate;
@Schema(description = "到期日期")
private LocalDate dueDate;
private LocalDateTime dueDate;
@Schema(description = "分配部门id")
private Long assignDepartmentId;

View File

@@ -1,19 +1,18 @@
package com.zt.plat.module.qms.resource.material.dal.mapper;
import cn.hutool.core.collection.CollUtil;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.github.yulichang.base.MPJBaseMapper;
import com.github.yulichang.wrapper.MPJLambdaWrapper;
import com.zt.plat.framework.common.pojo.PageResult;
import com.zt.plat.framework.mybatis.core.mapper.BaseMapperX;
import com.zt.plat.framework.mybatis.core.query.LambdaQueryWrapperX;
import com.zt.plat.framework.mybatis.core.query.MPJLambdaWrapperX;
import com.zt.plat.module.qms.resource.material.controller.vo.MaterialBatchPageReqVO;
import com.zt.plat.module.qms.resource.material.controller.vo.MaterialBatchRespVO;
import com.zt.plat.module.qms.resource.material.dal.dataobject.MaterialBatchDO;
import com.zt.plat.module.qms.resource.material.dal.dataobject.MaterialProductDO;
import org.apache.ibatis.annotations.Mapper;
import java.util.Arrays;
import java.util.List;
/**
@@ -25,7 +24,6 @@ import java.util.List;
public interface MaterialBatchMapper extends BaseMapperX<MaterialBatchDO> {
default PageResult<MaterialBatchDO> selectPage(MaterialBatchPageReqVO reqVO) {
// TODO 需要层级穿透 分类-物料sku-批次
return selectPage(reqVO, new LambdaQueryWrapperX<MaterialBatchDO>()
.eqIfPresent(MaterialBatchDO::getProductId, reqVO.getProductId())
.likeIfPresent(MaterialBatchDO::getBatchNo, reqVO.getBatchNo())
@@ -45,4 +43,30 @@ public interface MaterialBatchMapper extends BaseMapperX<MaterialBatchDO> {
.orderByDesc(MaterialBatchDO::getId));
}
default PageResult<MaterialBatchRespVO> selectPage(MaterialBatchPageReqVO reqVO, List<Long> pdtIds) {
MPJLambdaWrapper<MaterialBatchDO> wrapper = new MPJLambdaWrapperX<MaterialBatchDO>()
.selectAll(MaterialBatchDO.class)
.selectAs(MaterialProductDO::getName, MaterialBatchRespVO::getProductName)
.selectAs(MaterialProductDO::getCode, MaterialBatchRespVO::getProductCode)
.selectAs(MaterialProductDO::getModelNo, MaterialBatchRespVO::getProductModelNo)
.leftJoin(MaterialProductDO.class, MaterialProductDO::getId, MaterialBatchDO::getProductId)
.in(CollUtil.isNotEmpty(pdtIds), MaterialBatchDO::getProductId, pdtIds)
.eq(CollUtil.isEmpty(pdtIds) && reqVO.getProductId() != null, MaterialBatchDO::getProductId, reqVO.getProductId())
.likeIfExists(MaterialBatchDO::getBatchNo, reqVO.getBatchNo())
.likeIfExists(MaterialBatchDO::getLocation, reqVO.getLocation())
.likeIfExists(MaterialBatchDO::getSupplierId, reqVO.getSupplierId())
// .betweenIfPresent(MaterialBatchDO::getManufacturerDate, reqVO.getManufacturerDate())
// .betweenIfPresent(MaterialBatchDO::getDueDate, reqVO.getDueDate())
.eqIfExists(MaterialBatchDO::getAssignDepartmentId, reqVO.getAssignDepartmentId())
.likeIfExists(MaterialBatchDO::getAssignDepartmentName, reqVO.getAssignDepartmentName())
.eqIfExists(MaterialBatchDO::getAcceptanceStatus, reqVO.getAcceptanceStatus())
.eqIfExists(MaterialBatchDO::getAssayFlag, reqVO.getAssayFlag())
.eqIfExists(MaterialBatchDO::getAssayStatus, reqVO.getAssayStatus())
.eqIfExists(MaterialBatchDO::getSystemDepartmentCode, reqVO.getSystemDepartmentCode())
.eqIfExists(MaterialBatchDO::getRemark, reqVO.getRemark())
// .betweenIfPresent(MaterialBatchDO::getCreateTime, reqVO.getCreateTime())
.orderByDesc(MaterialBatchDO::getId);
return selectJoinPage(reqVO, MaterialBatchRespVO.class, wrapper);
}
}

View File

@@ -61,6 +61,14 @@ public interface MaterialBatchService {
*/
PageResult<MaterialBatchDO> getMaterialBatchPage(MaterialBatchPageReqVO pageReqVO);
/**
* 获得物料批次分页-可根据物料分类和大类级联查询
*
* @param pageReqVO 分页查询
* @return 物料批次分页
*/
PageResult<MaterialBatchRespVO> getMaterialBatchPageWithPdtInfo(MaterialBatchPageReqVO pageReqVO);
/**
* 批次工段拆分
*

View File

@@ -11,6 +11,7 @@ import com.zt.plat.module.qms.core.code.SequenceUtil;
import com.zt.plat.module.qms.resource.material.controller.vo.MaterialBatchPageReqVO;
import com.zt.plat.module.qms.resource.material.controller.vo.MaterialBatchRespVO;
import com.zt.plat.module.qms.resource.material.controller.vo.MaterialBatchSaveReqVO;
import com.zt.plat.module.qms.resource.material.controller.vo.MaterialProductRespVO;
import com.zt.plat.module.qms.resource.material.dal.dataobject.MaterialBatchDO;
import com.zt.plat.module.qms.resource.material.dal.dataobject.MaterialInfomationDO;
import com.zt.plat.module.qms.resource.material.dal.dataobject.MaterialProductDO;
@@ -44,6 +45,9 @@ public class MaterialBatchServiceImpl implements MaterialBatchService {
@Autowired
private SequenceUtil sequenceUtil;
@Autowired
private MaterialProductService materialProductService;
private final String sequenceKey = "QMS_MATERIAL_BATCH_NO";
@Override
@@ -126,6 +130,32 @@ public class MaterialBatchServiceImpl implements MaterialBatchService {
return materialBatchMapper.selectPage(pageReqVO);
}
@Override
public PageResult<MaterialBatchRespVO> getMaterialBatchPageWithPdtInfo(MaterialBatchPageReqVO pageReqVO) {
Long pdtId = pageReqVO.getProductId();
PageResult<MaterialBatchRespVO> pageResult;
if (pdtId == null) {
pageResult = materialBatchMapper.selectPage(pageReqVO, List.of());
} else {
List<MaterialProductDO> mtrlDos = materialProductService.getMaterialProductsByLikeIdPath(pdtId);
if (CollUtil.isEmpty(mtrlDos)) {
pageResult = materialBatchMapper.selectPage(pageReqVO, List.of());
} else {
List<Long> pdtIds = mtrlDos.stream().map(MaterialProductDO::getId).toList();
pageResult = materialBatchMapper.selectPage(pageReqVO, pdtIds);
}
}
if (!pageReqVO.getChildren()) return pageResult;
List<MaterialBatchRespVO> voList = pageResult.getList();
if (CollUtil.isNotEmpty(voList)) {
List<MaterialBatchRespVO> treeVos = this.listTransTree(voList, 0L);
pageResult.setList(treeVos);
}
return pageResult;
}
/**
* 批次工段拆分
*
@@ -148,7 +178,7 @@ public class MaterialBatchServiceImpl implements MaterialBatchService {
for (MaterialBatchSaveReqVO batAsn : createReqVOs) {
total = total.add(batAsn.getInboundQuantity());
}
if (!total.equals(mtrlBat.getInboundQuantity()))
if (total.compareTo(mtrlBat.getInboundQuantity()) != 0)
throw exception(GONGDUAN_QUANTITY_MATERIAL_BATCH_NOT_EQUAL);
// 修改工段
if (CollUtil.isNotEmpty(asnDOs)) {
@@ -194,4 +224,19 @@ public class MaterialBatchServiceImpl implements MaterialBatchService {
.ne(MaterialBatchDO::getParentId, 0));
}
/**
* 组装物料批次树
*
*/
private List<MaterialBatchRespVO> listTransTree(List<MaterialBatchRespVO> voList, Long parentId) {
// 获取父级节点
List<MaterialBatchRespVO> parentVOs = voList.stream().filter(vo ->
vo.getParentId().equals(parentId)).collect(Collectors.toList());
// 设置响应的子节点
parentVOs.forEach(vo -> vo.setChildren(listTransTree(voList, vo.getId())));
return parentVOs;
}
}

View File

@@ -99,4 +99,11 @@ public interface MaterialProductService {
* @return 物料大类分页
*/
PageResult<MaterialProductRespVO> getMaterialInventoryPage(@Valid MaterialProductPageReqVO pageReqVO);
/**
* 获取id在 idPath中的全部数据
* @param pdtId id
* @return 物料数据
*/
List<MaterialProductDO> getMaterialProductsByLikeIdPath(Long pdtId);
}

View File

@@ -40,8 +40,8 @@ public class MaterialProductServiceImpl implements MaterialProductService {
@Resource
private MaterialProductMapper materialProductMapper;
@Autowired
private MaterialBatchService materialBatchService;
// @Autowired
// private MaterialBatchService materialBatchService;
@Autowired
private MaterialInfomationService materialInfomationService;
@@ -249,8 +249,8 @@ public class MaterialProductServiceImpl implements MaterialProductService {
else {
// 大类下有批次时不可删除
// TODO 以及其他不可删除的情况,如库存记录、物料实例、使用记录等
boolean exists = materialBatchService.checkIsExistsDataByPdt(id);
if (exists) throw exception(MATERIAL_PRODUCT_EXISTS_BATCH);
// boolean exists = materialBatchService.checkIsExistsDataByPdt(id);
// if (exists) throw exception(MATERIAL_PRODUCT_EXISTS_BATCH);
}
materialProductMapper.deleteById(id);
}
@@ -267,8 +267,8 @@ public class MaterialProductServiceImpl implements MaterialProductService {
if (CollUtil.isNotEmpty(mtCtgList)) throw exception(MATERIAL_PRODUCTS_EXISTS_CATEGORY);
// 检查是否可删除 大类下有批次时不可删除
// TODO 以及其他不可删除的情况,如库存记录、物料实例、使用记录等
boolean exists = materialBatchService.checkIsExistsDataByPdts(ids);
if (exists) throw exception(MATERIAL_PRODUCT_EXISTS_BATCH);
// boolean exists = materialBatchService.checkIsExistsDataByPdts(ids);
// if (exists) throw exception(MATERIAL_PRODUCT_EXISTS_BATCH);
// 删除
materialProductMapper.deleteByIds(ids);
}
@@ -339,4 +339,12 @@ public class MaterialProductServiceImpl implements MaterialProductService {
return new PageResult<>(voList, pageResult.getTotal());
}
@Override
public List<MaterialProductDO> getMaterialProductsByLikeIdPath(Long pdtId) {
return materialProductMapper.selectList(Wrappers.lambdaQuery(MaterialProductDO.class)
.like(MaterialProductDO::getIdPath, "/" + pdtId + "/")
.eq(MaterialProductDO::getNodeType, DataTypeConstant.DATA_TYPE_DATA));
}
}

View File

@@ -0,0 +1,4 @@
package com.zt.plat.module.qms.resource.material.service.assist;
public class MaterialProductBatchService {
}