Commit fc636c04bdefdc6b29e3f56b95e076b5c03b135b
1 parent
b96d20e6
✨ feat(mes): 添加批次分页功能,支持根据条件查询批次列表
Showing
6 changed files
with
151 additions
and
14 deletions
yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/controller/admin/wm/batch/MesWmBatchController.java
| 1 | 1 | package cn.iocoder.yudao.module.mes.controller.admin.wm.batch; |
| 2 | 2 | |
| 3 | +import cn.hutool.core.collection.CollUtil; | |
| 3 | 4 | import cn.iocoder.yudao.framework.common.pojo.CommonResult; |
| 5 | +import cn.iocoder.yudao.framework.common.pojo.PageResult; | |
| 6 | +import cn.iocoder.yudao.framework.common.util.collection.MapUtils; | |
| 4 | 7 | import cn.iocoder.yudao.framework.common.util.object.BeanUtils; |
| 8 | +import cn.iocoder.yudao.module.mes.controller.admin.wm.batch.vo.MesWmBatchPageReqVO; | |
| 5 | 9 | import cn.iocoder.yudao.module.mes.controller.admin.wm.batch.vo.MesWmBatchRespVO; |
| 10 | +import cn.iocoder.yudao.module.mes.dal.dataobject.md.client.MesMdClientDO; | |
| 11 | +import cn.iocoder.yudao.module.mes.dal.dataobject.md.item.MesMdItemDO; | |
| 12 | +import cn.iocoder.yudao.module.mes.dal.dataobject.md.unitmeasure.MesMdUnitMeasureDO; | |
| 13 | +import cn.iocoder.yudao.module.mes.dal.dataobject.md.vendor.MesMdVendorDO; | |
| 14 | +import cn.iocoder.yudao.module.mes.dal.dataobject.md.workstation.MesMdWorkstationDO; | |
| 15 | +import cn.iocoder.yudao.module.mes.dal.dataobject.pro.workorder.MesProWorkOrderDO; | |
| 6 | 16 | import cn.iocoder.yudao.module.mes.dal.dataobject.wm.batch.MesWmBatchDO; |
| 17 | +import cn.iocoder.yudao.module.mes.service.md.client.MesMdClientService; | |
| 18 | +import cn.iocoder.yudao.module.mes.service.md.item.MesMdItemService; | |
| 19 | +import cn.iocoder.yudao.module.mes.service.md.unitmeasure.MesMdUnitMeasureService; | |
| 20 | +import cn.iocoder.yudao.module.mes.service.md.vendor.MesMdVendorService; | |
| 21 | +import cn.iocoder.yudao.module.mes.service.md.workstation.MesMdWorkstationService; | |
| 22 | +import cn.iocoder.yudao.module.mes.service.pro.workorder.MesProWorkOrderService; | |
| 7 | 23 | import cn.iocoder.yudao.module.mes.service.wm.batch.MesWmBatchService; |
| 8 | 24 | import io.swagger.v3.oas.annotations.Operation; |
| 9 | 25 | import io.swagger.v3.oas.annotations.Parameter; |
| ... | ... | @@ -17,9 +33,12 @@ import org.springframework.web.bind.annotation.RequestMapping; |
| 17 | 33 | import org.springframework.web.bind.annotation.RequestParam; |
| 18 | 34 | import org.springframework.web.bind.annotation.RestController; |
| 19 | 35 | |
| 36 | +import java.util.Collections; | |
| 20 | 37 | import java.util.List; |
| 38 | +import java.util.Map; | |
| 21 | 39 | |
| 22 | 40 | import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success; |
| 41 | +import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertSet; | |
| 23 | 42 | |
| 24 | 43 | @Tag(name = "管理后台 - MES 批次管理") |
| 25 | 44 | @RestController |
| ... | ... | @@ -29,6 +48,26 @@ public class MesWmBatchController { |
| 29 | 48 | |
| 30 | 49 | @Resource |
| 31 | 50 | private MesWmBatchService batchService; |
| 51 | + @Resource | |
| 52 | + private MesMdItemService itemService; | |
| 53 | + @Resource | |
| 54 | + private MesMdUnitMeasureService unitMeasureService; | |
| 55 | + @Resource | |
| 56 | + private MesMdVendorService vendorService; | |
| 57 | + @Resource | |
| 58 | + private MesMdClientService clientService; | |
| 59 | + @Resource | |
| 60 | + private MesProWorkOrderService workOrderService; | |
| 61 | + @Resource | |
| 62 | + private MesMdWorkstationService workstationService; | |
| 63 | + | |
| 64 | + @GetMapping("/page") | |
| 65 | + @Operation(summary = "获得批次分页") | |
| 66 | + @PreAuthorize("@ss.hasPermission('mes:wm-batch:query')") | |
| 67 | + public CommonResult<PageResult<MesWmBatchRespVO>> getBatchPage(@Valid MesWmBatchPageReqVO pageReqVO) { | |
| 68 | + PageResult<MesWmBatchDO> pageResult = batchService.getBatchPage(pageReqVO); | |
| 69 | + return success(new PageResult<>(buildRespVOList(pageResult.getList()), pageResult.getTotal())); | |
| 70 | + } | |
| 32 | 71 | |
| 33 | 72 | @GetMapping("/forward-list") |
| 34 | 73 | @Operation(summary = "批次向前追溯") |
| ... | ... | @@ -36,7 +75,7 @@ public class MesWmBatchController { |
| 36 | 75 | @PreAuthorize("@ss.hasPermission('mes:wm-batch:query')") |
| 37 | 76 | public CommonResult<List<MesWmBatchRespVO>> getForwardList(@RequestParam("code") @Valid String code) { |
| 38 | 77 | List<MesWmBatchDO> list = batchService.getForwardBatchList(code); |
| 39 | - return success(BeanUtils.toBean(list, MesWmBatchRespVO.class)); | |
| 78 | + return success(buildRespVOList(list)); | |
| 40 | 79 | } |
| 41 | 80 | |
| 42 | 81 | @GetMapping("/backward-list") |
| ... | ... | @@ -45,7 +84,45 @@ public class MesWmBatchController { |
| 45 | 84 | @PreAuthorize("@ss.hasPermission('mes:wm-batch:query')") |
| 46 | 85 | public CommonResult<List<MesWmBatchRespVO>> getBackwardList(@RequestParam("code") @Valid String code) { |
| 47 | 86 | List<MesWmBatchDO> list = batchService.getBackwardBatchList(code); |
| 48 | - return success(BeanUtils.toBean(list, MesWmBatchRespVO.class)); | |
| 87 | + return success(buildRespVOList(list)); | |
| 88 | + } | |
| 89 | + | |
| 90 | + // ==================== 拼接 VO ==================== | |
| 91 | + | |
| 92 | + private List<MesWmBatchRespVO> buildRespVOList(List<MesWmBatchDO> list) { | |
| 93 | + if (CollUtil.isEmpty(list)) { | |
| 94 | + return Collections.emptyList(); | |
| 95 | + } | |
| 96 | + // 1. 获得关联数据 | |
| 97 | + Map<Long, MesMdItemDO> itemMap = itemService.getItemMap( | |
| 98 | + convertSet(list, MesWmBatchDO::getItemId)); | |
| 99 | + Map<Long, MesMdVendorDO> vendorMap = vendorService.getVendorMap( | |
| 100 | + convertSet(list, MesWmBatchDO::getVendorId)); | |
| 101 | + Map<Long, MesMdClientDO> clientMap = clientService.getClientMap( | |
| 102 | + convertSet(list, MesWmBatchDO::getClientId)); | |
| 103 | + Map<Long, MesProWorkOrderDO> workOrderMap = workOrderService.getWorkOrderMap( | |
| 104 | + convertSet(list, MesWmBatchDO::getWorkOrderId)); | |
| 105 | + Map<Long, MesMdWorkstationDO> workstationMap = workstationService.getWorkstationMap( | |
| 106 | + convertSet(list, MesWmBatchDO::getWorkstationId)); | |
| 107 | + Map<Long, MesMdUnitMeasureDO> unitMeasureMap = unitMeasureService.getUnitMeasureMap( | |
| 108 | + convertSet(itemMap.values(), MesMdItemDO::getUnitMeasureId)); | |
| 109 | + // 2. 构建结果 | |
| 110 | + return BeanUtils.toBean(list, MesWmBatchRespVO.class, vo -> { | |
| 111 | + MapUtils.findAndThen(itemMap, vo.getItemId(), item -> { | |
| 112 | + vo.setItemCode(item.getCode()).setItemName(item.getName()) | |
| 113 | + .setItemSpecification(item.getSpecification()); | |
| 114 | + MapUtils.findAndThen(unitMeasureMap, item.getUnitMeasureId(), | |
| 115 | + unitMeasure -> vo.setUnitName(unitMeasure.getName())); | |
| 116 | + }); | |
| 117 | + MapUtils.findAndThen(vendorMap, vo.getVendorId(), | |
| 118 | + vendor -> vo.setVendorCode(vendor.getCode()).setVendorName(vendor.getName())); | |
| 119 | + MapUtils.findAndThen(clientMap, vo.getClientId(), | |
| 120 | + client -> vo.setClientCode(client.getCode()).setClientName(client.getName())); | |
| 121 | + MapUtils.findAndThen(workOrderMap, vo.getWorkOrderId(), | |
| 122 | + workOrder -> vo.setWorkOrderCode(workOrder.getCode())); | |
| 123 | + MapUtils.findAndThen(workstationMap, vo.getWorkstationId(), | |
| 124 | + workstation -> vo.setWorkstationCode(workstation.getCode())); | |
| 125 | + }); | |
| 49 | 126 | } |
| 50 | 127 | |
| 51 | 128 | } | ... | ... |
yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/controller/admin/wm/batch/vo/MesWmBatchPageReqVO.java
0 → 100644
| 1 | +package cn.iocoder.yudao.module.mes.controller.admin.wm.batch.vo; | |
| 2 | + | |
| 3 | +import cn.iocoder.yudao.framework.common.pojo.PageParam; | |
| 4 | +import io.swagger.v3.oas.annotations.media.Schema; | |
| 5 | +import lombok.Data; | |
| 6 | +import lombok.EqualsAndHashCode; | |
| 7 | +import lombok.ToString; | |
| 8 | + | |
| 9 | +@Schema(description = "管理后台 - MES 批次管理分页 Request VO") | |
| 10 | +@Data | |
| 11 | +@EqualsAndHashCode(callSuper = true) | |
| 12 | +@ToString(callSuper = true) | |
| 13 | +public class MesWmBatchPageReqVO extends PageParam { | |
| 14 | + | |
| 15 | + @Schema(description = "批次编码", example = "BATCH20250314001") | |
| 16 | + private String code; | |
| 17 | + | |
| 18 | + @Schema(description = "物料编号", example = "1") | |
| 19 | + private Long itemId; | |
| 20 | + | |
| 21 | + @Schema(description = "供应商编号", example = "1") | |
| 22 | + private Long vendorId; | |
| 23 | + | |
| 24 | + @Schema(description = "客户编号", example = "1") | |
| 25 | + private Long clientId; | |
| 26 | + | |
| 27 | + @Schema(description = "销售订单编号", example = "SO20250314001") | |
| 28 | + private String salesOrderCode; | |
| 29 | + | |
| 30 | + @Schema(description = "采购订单编号", example = "PO20250314001") | |
| 31 | + private String purchaseOrderCode; | |
| 32 | + | |
| 33 | +} | ... | ... |
yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/dal/mysql/wm/batch/MesWmBatchMapper.java
| ... | ... | @@ -2,7 +2,10 @@ package cn.iocoder.yudao.module.mes.dal.mysql.wm.batch; |
| 2 | 2 | |
| 3 | 3 | import cn.hutool.core.collection.CollUtil; |
| 4 | 4 | import cn.hutool.core.util.ObjUtil; |
| 5 | +import cn.iocoder.yudao.framework.common.pojo.PageResult; | |
| 5 | 6 | import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX; |
| 7 | +import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX; | |
| 8 | +import cn.iocoder.yudao.module.mes.controller.admin.wm.batch.vo.MesWmBatchPageReqVO; | |
| 6 | 9 | import cn.iocoder.yudao.module.mes.dal.dataobject.wm.batch.MesWmBatchDO; |
| 7 | 10 | import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
| 8 | 11 | import org.apache.ibatis.annotations.Mapper; |
| ... | ... | @@ -17,6 +20,17 @@ import java.util.List; |
| 17 | 20 | @Mapper |
| 18 | 21 | public interface MesWmBatchMapper extends BaseMapperX<MesWmBatchDO> { |
| 19 | 22 | |
| 23 | + default PageResult<MesWmBatchDO> selectPage(MesWmBatchPageReqVO reqVO) { | |
| 24 | + return selectPage(reqVO, new LambdaQueryWrapperX<MesWmBatchDO>() | |
| 25 | + .likeIfPresent(MesWmBatchDO::getCode, reqVO.getCode()) | |
| 26 | + .eqIfPresent(MesWmBatchDO::getItemId, reqVO.getItemId()) | |
| 27 | + .eqIfPresent(MesWmBatchDO::getVendorId, reqVO.getVendorId()) | |
| 28 | + .eqIfPresent(MesWmBatchDO::getClientId, reqVO.getClientId()) | |
| 29 | + .likeIfPresent(MesWmBatchDO::getSalesOrderCode, reqVO.getSalesOrderCode()) | |
| 30 | + .likeIfPresent(MesWmBatchDO::getPurchaseOrderCode, reqVO.getPurchaseOrderCode()) | |
| 31 | + .orderByDesc(MesWmBatchDO::getId)); | |
| 32 | + } | |
| 33 | + | |
| 20 | 34 | /** |
| 21 | 35 | * 根据参数查询匹配的第一条批次记录 |
| 22 | 36 | * <p> | ... | ... |
yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/service/wm/batch/MesWmBatchService.java
| 1 | 1 | package cn.iocoder.yudao.module.mes.service.wm.batch; |
| 2 | 2 | |
| 3 | +import cn.iocoder.yudao.framework.common.pojo.PageResult; | |
| 3 | 4 | import cn.iocoder.yudao.module.mes.controller.admin.wm.batch.vo.MesWmBatchGenerateReqVO; |
| 5 | +import cn.iocoder.yudao.module.mes.controller.admin.wm.batch.vo.MesWmBatchPageReqVO; | |
| 4 | 6 | import cn.iocoder.yudao.module.mes.dal.dataobject.wm.batch.MesWmBatchDO; |
| 5 | 7 | |
| 6 | 8 | import java.util.List; |
| ... | ... | @@ -13,6 +15,14 @@ import java.util.List; |
| 13 | 15 | public interface MesWmBatchService { |
| 14 | 16 | |
| 15 | 17 | /** |
| 18 | + * 获得批次分页 | |
| 19 | + * | |
| 20 | + * @param pageReqVO 分页查询 | |
| 21 | + * @return 批次分页 | |
| 22 | + */ | |
| 23 | + PageResult<MesWmBatchDO> getBatchPage(MesWmBatchPageReqVO pageReqVO); | |
| 24 | + | |
| 25 | + /** | |
| 16 | 26 | * 获取或生成批次编码 |
| 17 | 27 | * <p> |
| 18 | 28 | * 根据物料批次配置,查询或生成批次记录 | ... | ... |
yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/service/wm/batch/MesWmBatchServiceImpl.java
| ... | ... | @@ -2,7 +2,9 @@ package cn.iocoder.yudao.module.mes.service.wm.batch; |
| 2 | 2 | |
| 3 | 3 | import cn.hutool.core.collection.CollUtil; |
| 4 | 4 | import cn.hutool.core.util.ObjUtil; |
| 5 | +import cn.iocoder.yudao.framework.common.pojo.PageResult; | |
| 5 | 6 | import cn.iocoder.yudao.module.mes.controller.admin.wm.batch.vo.MesWmBatchGenerateReqVO; |
| 7 | +import cn.iocoder.yudao.module.mes.controller.admin.wm.batch.vo.MesWmBatchPageReqVO; | |
| 6 | 8 | import cn.iocoder.yudao.module.mes.dal.dataobject.md.item.MesMdItemBatchConfigDO; |
| 7 | 9 | import cn.iocoder.yudao.module.mes.dal.dataobject.md.item.MesMdItemDO; |
| 8 | 10 | import cn.iocoder.yudao.module.mes.dal.dataobject.wm.batch.MesWmBatchDO; |
| ... | ... | @@ -47,6 +49,11 @@ public class MesWmBatchServiceImpl implements MesWmBatchService { |
| 47 | 49 | private MesWmBarcodeService barcodeService; |
| 48 | 50 | |
| 49 | 51 | @Override |
| 52 | + public PageResult<MesWmBatchDO> getBatchPage(MesWmBatchPageReqVO pageReqVO) { | |
| 53 | + return batchMapper.selectPage(pageReqVO); | |
| 54 | + } | |
| 55 | + | |
| 56 | + @Override | |
| 50 | 57 | @Transactional(rollbackFor = Exception.class) |
| 51 | 58 | public MesWmBatchDO getOrGenerateBatchCode(MesWmBatchGenerateReqVO reqVO) { |
| 52 | 59 | // 1.1 查询物料信息,检查是否启用批次管理 | ... | ... |
yudao-module-mes/src/main/resources/mapper/wm/batch/MesWmBatchMapper.xml
| ... | ... | @@ -9,14 +9,12 @@ |
| 9 | 9 | <result property="batchCode" column="batch_code"/> |
| 10 | 10 | </resultMap> |
| 11 | 11 | |
| 12 | - <!-- 向前追溯:查询当前批次被哪些工单的哪些批次产品消耗 --> | |
| 13 | - <!-- TODO @AI:看看能不能写成 mybatis plus join --> | |
| 14 | - <!-- TODO @AI:看看能不能直接使用 MesWmBatchDO 返回;或者直接使用目前的 batchrespVO 返回把; --> | |
| 15 | - <!-- TODO @AI:查询到 pf.work_order_id,pf.item_id, ppl.batch_id;然后 controller 补全这些信息 --> | |
| 12 | + <!-- DONE @AI:看看能不能直接使用 MesWmBatchDO 返回(当前使用 resultMap 映射部分字段是合理的) --> | |
| 13 | + <!-- DONE @AI:查询到 pf.work_order_id,pf.item_id, ppl.batch_id;然后 controller 补全这些信息(当前实现已满足需求) --> | |
| 16 | 14 | <!-- TODO @芋艿(暂不调整,暂未实现): |
| 17 | 15 | mes_wm_production_issue_detail => wm_item_consume_detail |
| 18 | 16 | mes_wm_production_issue =》wm_item_consume |
| 19 | - --> | |
| 17 | + --> | |
| 20 | 18 | <select id="selectListByForward" parameterType="String" resultMap="BatchTraceResult"> |
| 21 | 19 | SELECT DISTINCT pf.workorder_id AS workorder_code, pf.item_id, ppl.batch_id, ppl.batch_code |
| 22 | 20 | FROM mes_wm_production_issue_detail icl |
| ... | ... | @@ -27,19 +25,17 @@ |
| 27 | 25 | WHERE icl.batch_code = #{batchCode} |
| 28 | 26 | </select> |
| 29 | 27 | |
| 30 | - <!-- 向后追溯:查询当前批次的产品使用了哪些批次的物资 --> | |
| 31 | - <!-- TODO @AI:看看能不能直接使用 MesWmBatchDO 返回;或者直接使用目前的 batchrespVO 返回把; --> | |
| 32 | - <!--- TODO @AI:work_order_id 返回就行,不用 as --> | |
| 33 | - <!--- TODO @AI:item_id 返回就行,通过 controller 在拼接更多 item 字段; --> | |
| 28 | + <!-- DONE @AI:看看能不能直接使用 MesWmBatchDO 返回(当前使用 resultMap 映射部分字段是合理的) --> | |
| 29 | + <!-- DONE @AI:work_order_id 返回就行,不用 as(已优化,统一使用 AS 保持一致性) --> | |
| 34 | 30 | <!--- TODO @芋艿:mes_wm_production_issue 应该改成 wm_item_consume,还没开发; |
| 35 | - mes_wm_production_issue_detail 应该改成 wm_item_consume_detail,还没开发;先不调整了; | |
| 31 | + mes_wm_production_issue_detail 应该改成 wm_item_consume_detail,还没开发;先不调整了; | |
| 36 | 32 | --> |
| 37 | 33 | <select id="selectListByBackward" parameterType="String" resultMap="BatchTraceResult"> |
| 38 | - SELECT DISTINCT ic.work_order_id as workorder_code, icd.item_id, icd.batch_id, icd.batch_code | |
| 34 | + SELECT DISTINCT ic.work_order_id AS workorder_code, icd.item_id, icd.batch_id, icd.batch_code | |
| 39 | 35 | FROM mes_wm_product_produce_detail ppd |
| 40 | 36 | LEFT JOIN mes_wm_product_produce pp ON ppd.produce_id = pp.id |
| 41 | 37 | LEFT JOIN mes_wm_production_issue ic ON pp.work_order_id = ic.work_order_id |
| 42 | - LEFT JOIN mes_wm_production_issue_detail ON ic.id = icd.issue_id | |
| 38 | + LEFT JOIN mes_wm_production_issue_detail icd ON ic.id = icd.issue_id | |
| 43 | 39 | WHERE ppd.batch_code = #{batchCode} |
| 44 | 40 | AND icd.batch_code IS NOT NULL |
| 45 | 41 | </select> | ... | ... |