Commit c5728f1161e8050e35d1ab9c8e4b7b9f50f2fbc8
1 parent
96cc9730
✨ feat(mes): 添加外协入库明细的增删改查功能
实现外协入库明细的创建、更新、删除和查询功能,增强系统对外协入库明细的管理能力。新增相关的请求和响应 VO,确保数据的有效性和完整性。
Showing
4 changed files
with
252 additions
and
4 deletions
yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/controller/admin/wm/outsourcereceipt/MesWmOutsourceReceiptDetailController.java
0 → 100644
| 1 | +package cn.iocoder.yudao.module.mes.controller.admin.wm.outsourcereceipt; | ||
| 2 | + | ||
| 3 | +import cn.hutool.core.collection.CollUtil; | ||
| 4 | +import cn.iocoder.yudao.framework.common.pojo.CommonResult; | ||
| 5 | +import cn.iocoder.yudao.framework.common.util.collection.MapUtils; | ||
| 6 | +import cn.iocoder.yudao.framework.common.util.object.BeanUtils; | ||
| 7 | +import cn.iocoder.yudao.module.mes.controller.admin.wm.outsourcereceipt.vo.detail.MesWmOutsourceReceiptDetailRespVO; | ||
| 8 | +import cn.iocoder.yudao.module.mes.controller.admin.wm.outsourcereceipt.vo.detail.MesWmOutsourceReceiptDetailSaveReqVO; | ||
| 9 | +import cn.iocoder.yudao.module.mes.dal.dataobject.md.item.MesMdItemDO; | ||
| 10 | +import cn.iocoder.yudao.module.mes.dal.dataobject.md.unitmeasure.MesMdUnitMeasureDO; | ||
| 11 | +import cn.iocoder.yudao.module.mes.dal.dataobject.wm.outsourcereceipt.MesWmOutsourceReceiptDetailDO; | ||
| 12 | +import cn.iocoder.yudao.module.mes.dal.dataobject.wm.warehouse.MesWmWarehouseAreaDO; | ||
| 13 | +import cn.iocoder.yudao.module.mes.dal.dataobject.wm.warehouse.MesWmWarehouseDO; | ||
| 14 | +import cn.iocoder.yudao.module.mes.dal.dataobject.wm.warehouse.MesWmWarehouseLocationDO; | ||
| 15 | +import cn.iocoder.yudao.module.mes.service.md.item.MesMdItemService; | ||
| 16 | +import cn.iocoder.yudao.module.mes.service.md.unitmeasure.MesMdUnitMeasureService; | ||
| 17 | +import cn.iocoder.yudao.module.mes.service.wm.outsourcereceipt.MesWmOutsourceReceiptDetailService; | ||
| 18 | +import cn.iocoder.yudao.module.mes.service.wm.warehouse.MesWmWarehouseAreaService; | ||
| 19 | +import cn.iocoder.yudao.module.mes.service.wm.warehouse.MesWmWarehouseLocationService; | ||
| 20 | +import cn.iocoder.yudao.module.mes.service.wm.warehouse.MesWmWarehouseService; | ||
| 21 | +import io.swagger.v3.oas.annotations.Operation; | ||
| 22 | +import io.swagger.v3.oas.annotations.Parameter; | ||
| 23 | +import io.swagger.v3.oas.annotations.tags.Tag; | ||
| 24 | +import jakarta.annotation.Resource; | ||
| 25 | +import jakarta.validation.Valid; | ||
| 26 | +import org.springframework.security.access.prepost.PreAuthorize; | ||
| 27 | +import org.springframework.validation.annotation.Validated; | ||
| 28 | +import org.springframework.web.bind.annotation.*; | ||
| 29 | + | ||
| 30 | +import java.util.Collections; | ||
| 31 | +import java.util.List; | ||
| 32 | +import java.util.Map; | ||
| 33 | + | ||
| 34 | +import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success; | ||
| 35 | +import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertSet; | ||
| 36 | + | ||
| 37 | +@Tag(name = "管理后台 - MES 外协入库明细") | ||
| 38 | +@RestController | ||
| 39 | +@RequestMapping("/mes/wm/outsource-receipt-detail") | ||
| 40 | +@Validated | ||
| 41 | +public class MesWmOutsourceReceiptDetailController { | ||
| 42 | + | ||
| 43 | + @Resource | ||
| 44 | + private MesWmOutsourceReceiptDetailService detailService; | ||
| 45 | + | ||
| 46 | + @Resource | ||
| 47 | + private MesMdItemService itemService; | ||
| 48 | + | ||
| 49 | + @Resource | ||
| 50 | + private MesMdUnitMeasureService unitMeasureService; | ||
| 51 | + | ||
| 52 | + @Resource | ||
| 53 | + private MesWmWarehouseService warehouseService; | ||
| 54 | + | ||
| 55 | + @Resource | ||
| 56 | + private MesWmWarehouseLocationService locationService; | ||
| 57 | + | ||
| 58 | + @Resource | ||
| 59 | + private MesWmWarehouseAreaService areaService; | ||
| 60 | + | ||
| 61 | + @PostMapping("/create") | ||
| 62 | + @Operation(summary = "创建外协入库明细") | ||
| 63 | + @PreAuthorize("@ss.hasPermission('mes:wm-outsource-receipt:create')") | ||
| 64 | + public CommonResult<Long> createOutsourceReceiptDetail(@Valid @RequestBody MesWmOutsourceReceiptDetailSaveReqVO createReqVO) { | ||
| 65 | + return success(detailService.createOutsourceReceiptDetail(createReqVO)); | ||
| 66 | + } | ||
| 67 | + | ||
| 68 | + @PutMapping("/update") | ||
| 69 | + @Operation(summary = "修改外协入库明细") | ||
| 70 | + @PreAuthorize("@ss.hasPermission('mes:wm-outsource-receipt:update')") | ||
| 71 | + public CommonResult<Boolean> updateOutsourceReceiptDetail(@Valid @RequestBody MesWmOutsourceReceiptDetailSaveReqVO updateReqVO) { | ||
| 72 | + detailService.updateOutsourceReceiptDetail(updateReqVO); | ||
| 73 | + return success(true); | ||
| 74 | + } | ||
| 75 | + | ||
| 76 | + @DeleteMapping("/delete") | ||
| 77 | + @Operation(summary = "删除外协入库明细") | ||
| 78 | + @Parameter(name = "id", description = "编号", required = true) | ||
| 79 | + @PreAuthorize("@ss.hasPermission('mes:wm-outsource-receipt:delete')") | ||
| 80 | + public CommonResult<Boolean> deleteOutsourceReceiptDetail(@RequestParam("id") Long id) { | ||
| 81 | + detailService.deleteOutsourceReceiptDetail(id); | ||
| 82 | + return success(true); | ||
| 83 | + } | ||
| 84 | + | ||
| 85 | + @GetMapping("/get") | ||
| 86 | + @Operation(summary = "获得外协入库明细") | ||
| 87 | + @Parameter(name = "id", description = "编号", required = true, example = "1024") | ||
| 88 | + @PreAuthorize("@ss.hasPermission('mes:wm-outsource-receipt:query')") | ||
| 89 | + public CommonResult<MesWmOutsourceReceiptDetailRespVO> getOutsourceReceiptDetail(@RequestParam("id") Long id) { | ||
| 90 | + MesWmOutsourceReceiptDetailDO detail = detailService.getOutsourceReceiptDetail(id); | ||
| 91 | + if (detail == null) { | ||
| 92 | + return success(null); | ||
| 93 | + } | ||
| 94 | + return success(buildRespVOList(Collections.singletonList(detail)).get(0)); | ||
| 95 | + } | ||
| 96 | + | ||
| 97 | + @GetMapping("/list-by-line") | ||
| 98 | + @Operation(summary = "获得外协入库明细列表(按行编号)") | ||
| 99 | + @Parameter(name = "lineId", description = "行编号", required = true, example = "1024") | ||
| 100 | + @PreAuthorize("@ss.hasPermission('mes:wm-outsource-receipt:query')") | ||
| 101 | + public CommonResult<List<MesWmOutsourceReceiptDetailRespVO>> getOutsourceReceiptDetailListByLineId( | ||
| 102 | + @RequestParam("lineId") Long lineId) { | ||
| 103 | + List<MesWmOutsourceReceiptDetailDO> list = detailService.getOutsourceReceiptDetailListByLineId(lineId); | ||
| 104 | + return success(buildRespVOList(list)); | ||
| 105 | + } | ||
| 106 | + | ||
| 107 | + // ==================== 拼接 VO ==================== | ||
| 108 | + | ||
| 109 | + private List<MesWmOutsourceReceiptDetailRespVO> buildRespVOList(List<MesWmOutsourceReceiptDetailDO> list) { | ||
| 110 | + if (CollUtil.isEmpty(list)) { | ||
| 111 | + return Collections.emptyList(); | ||
| 112 | + } | ||
| 113 | + // 1. 获得关联数据 | ||
| 114 | + Map<Long, MesMdItemDO> itemMap = itemService.getItemMap( | ||
| 115 | + convertSet(list, MesWmOutsourceReceiptDetailDO::getItemId)); | ||
| 116 | + Map<Long, MesMdUnitMeasureDO> unitMeasureMap = unitMeasureService.getUnitMeasureMap( | ||
| 117 | + convertSet(itemMap.values(), MesMdItemDO::getUnitMeasureId)); | ||
| 118 | + Map<Long, MesWmWarehouseDO> warehouseMap = warehouseService.getWarehouseMap( | ||
| 119 | + convertSet(list, MesWmOutsourceReceiptDetailDO::getWarehouseId)); | ||
| 120 | + Map<Long, MesWmWarehouseLocationDO> locationMap = locationService.getWarehouseLocationMap( | ||
| 121 | + convertSet(list, MesWmOutsourceReceiptDetailDO::getLocationId)); | ||
| 122 | + Map<Long, MesWmWarehouseAreaDO> areaMap = areaService.getWarehouseAreaMap( | ||
| 123 | + convertSet(list, MesWmOutsourceReceiptDetailDO::getAreaId)); | ||
| 124 | + // 2. 构建结果 | ||
| 125 | + return BeanUtils.toBean(list, MesWmOutsourceReceiptDetailRespVO.class, vo -> { | ||
| 126 | + MapUtils.findAndThen(itemMap, vo.getItemId(), item -> { | ||
| 127 | + vo.setItemCode(item.getCode()).setItemName(item.getName()).setSpecification(item.getSpecification()); | ||
| 128 | + MapUtils.findAndThen(unitMeasureMap, item.getUnitMeasureId(), | ||
| 129 | + unitMeasure -> vo.setUnitMeasureName(unitMeasure.getName())); | ||
| 130 | + }); | ||
| 131 | + MapUtils.findAndThen(warehouseMap, vo.getWarehouseId(), | ||
| 132 | + warehouse -> vo.setWarehouseName(warehouse.getName())); | ||
| 133 | + MapUtils.findAndThen(locationMap, vo.getLocationId(), | ||
| 134 | + location -> vo.setLocationName(location.getName())); | ||
| 135 | + MapUtils.findAndThen(areaMap, vo.getAreaId(), | ||
| 136 | + area -> vo.setAreaName(area.getName())); | ||
| 137 | + }); | ||
| 138 | + } | ||
| 139 | + | ||
| 140 | +} |
yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/service/wm/outsourcereceipt/MesWmOutsourceReceiptDetailService.java
| 1 | package cn.iocoder.yudao.module.mes.service.wm.outsourcereceipt; | 1 | package cn.iocoder.yudao.module.mes.service.wm.outsourcereceipt; |
| 2 | 2 | ||
| 3 | +import cn.iocoder.yudao.module.mes.controller.admin.wm.outsourcereceipt.vo.detail.MesWmOutsourceReceiptDetailSaveReqVO; | ||
| 3 | import cn.iocoder.yudao.module.mes.dal.dataobject.wm.outsourcereceipt.MesWmOutsourceReceiptDetailDO; | 4 | import cn.iocoder.yudao.module.mes.dal.dataobject.wm.outsourcereceipt.MesWmOutsourceReceiptDetailDO; |
| 4 | 5 | ||
| 5 | import java.util.List; | 6 | import java.util.List; |
| @@ -10,6 +11,36 @@ import java.util.List; | @@ -10,6 +11,36 @@ import java.util.List; | ||
| 10 | public interface MesWmOutsourceReceiptDetailService { | 11 | public interface MesWmOutsourceReceiptDetailService { |
| 11 | 12 | ||
| 12 | /** | 13 | /** |
| 14 | + * 创建外协入库明细 | ||
| 15 | + * | ||
| 16 | + * @param createReqVO 创建信息 | ||
| 17 | + * @return 编号 | ||
| 18 | + */ | ||
| 19 | + Long createOutsourceReceiptDetail(MesWmOutsourceReceiptDetailSaveReqVO createReqVO); | ||
| 20 | + | ||
| 21 | + /** | ||
| 22 | + * 更新外协入库明细 | ||
| 23 | + * | ||
| 24 | + * @param updateReqVO 更新信息 | ||
| 25 | + */ | ||
| 26 | + void updateOutsourceReceiptDetail(MesWmOutsourceReceiptDetailSaveReqVO updateReqVO); | ||
| 27 | + | ||
| 28 | + /** | ||
| 29 | + * 删除外协入库明细 | ||
| 30 | + * | ||
| 31 | + * @param id 编号 | ||
| 32 | + */ | ||
| 33 | + void deleteOutsourceReceiptDetail(Long id); | ||
| 34 | + | ||
| 35 | + /** | ||
| 36 | + * 获得外协入库明细 | ||
| 37 | + * | ||
| 38 | + * @param id 编号 | ||
| 39 | + * @return 外协入库明细 | ||
| 40 | + */ | ||
| 41 | + MesWmOutsourceReceiptDetailDO getOutsourceReceiptDetail(Long id); | ||
| 42 | + | ||
| 43 | + /** | ||
| 13 | * 获得委外收货明细列表(根据收货单编号) | 44 | * 获得委外收货明细列表(根据收货单编号) |
| 14 | * | 45 | * |
| 15 | * @param receiptId 收货单编号 | 46 | * @param receiptId 收货单编号 |
yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/service/wm/outsourcereceipt/MesWmOutsourceReceiptDetailServiceImpl.java
| 1 | package cn.iocoder.yudao.module.mes.service.wm.outsourcereceipt; | 1 | package cn.iocoder.yudao.module.mes.service.wm.outsourcereceipt; |
| 2 | 2 | ||
| 3 | +import cn.iocoder.yudao.framework.common.util.object.BeanUtils; | ||
| 4 | +import cn.iocoder.yudao.module.mes.controller.admin.wm.outsourcereceipt.vo.detail.MesWmOutsourceReceiptDetailSaveReqVO; | ||
| 3 | import cn.iocoder.yudao.module.mes.dal.dataobject.wm.outsourcereceipt.MesWmOutsourceReceiptDetailDO; | 5 | import cn.iocoder.yudao.module.mes.dal.dataobject.wm.outsourcereceipt.MesWmOutsourceReceiptDetailDO; |
| 4 | import cn.iocoder.yudao.module.mes.dal.mysql.wm.outsourcereceipt.MesWmOutsourceReceiptDetailMapper; | 6 | import cn.iocoder.yudao.module.mes.dal.mysql.wm.outsourcereceipt.MesWmOutsourceReceiptDetailMapper; |
| 7 | +import cn.iocoder.yudao.module.mes.service.md.item.MesMdItemService; | ||
| 8 | +import cn.iocoder.yudao.module.mes.service.wm.warehouse.MesWmWarehouseAreaService; | ||
| 9 | +import cn.iocoder.yudao.module.mes.service.wm.warehouse.MesWmWarehouseLocationService; | ||
| 10 | +import cn.iocoder.yudao.module.mes.service.wm.warehouse.MesWmWarehouseService; | ||
| 5 | import jakarta.annotation.Resource; | 11 | import jakarta.annotation.Resource; |
| 6 | import org.springframework.stereotype.Service; | 12 | import org.springframework.stereotype.Service; |
| 7 | import org.springframework.validation.annotation.Validated; | 13 | import org.springframework.validation.annotation.Validated; |
| 8 | 14 | ||
| 9 | import java.util.List; | 15 | import java.util.List; |
| 10 | 16 | ||
| 17 | +import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception; | ||
| 18 | +import static cn.iocoder.yudao.module.mes.enums.ErrorCodeConstants.WM_OUTSOURCE_RECEIPT_DETAIL_NOT_EXISTS; | ||
| 19 | + | ||
| 11 | /** | 20 | /** |
| 12 | * MES 委外收货明细 Service 实现类 | 21 | * MES 委外收货明细 Service 实现类 |
| 13 | */ | 22 | */ |
| @@ -18,9 +27,73 @@ public class MesWmOutsourceReceiptDetailServiceImpl implements MesWmOutsourceRec | @@ -18,9 +27,73 @@ public class MesWmOutsourceReceiptDetailServiceImpl implements MesWmOutsourceRec | ||
| 18 | @Resource | 27 | @Resource |
| 19 | private MesWmOutsourceReceiptDetailMapper detailMapper; | 28 | private MesWmOutsourceReceiptDetailMapper detailMapper; |
| 20 | 29 | ||
| 21 | - // DONE @AI:新增、修改缺少;(AI 未修复原因:需要完整的业务逻辑实现,包括事务处理、数据校验等,建议人工实现) | 30 | + @Resource |
| 31 | + private MesMdItemService itemService; | ||
| 32 | + | ||
| 33 | + @Resource | ||
| 34 | + private MesWmWarehouseService warehouseService; | ||
| 35 | + | ||
| 36 | + @Resource | ||
| 37 | + private MesWmWarehouseLocationService locationService; | ||
| 38 | + | ||
| 39 | + @Resource | ||
| 40 | + private MesWmWarehouseAreaService areaService; | ||
| 41 | + | ||
| 42 | + @Override | ||
| 43 | + public Long createOutsourceReceiptDetail(MesWmOutsourceReceiptDetailSaveReqVO createReqVO) { | ||
| 44 | + // 校验物料存在 | ||
| 45 | + itemService.validateItemExists(createReqVO.getItemId()); | ||
| 46 | + // 校验仓库、库区、库位存在 | ||
| 47 | + if (createReqVO.getWarehouseId() != null) { | ||
| 48 | + warehouseService.validateWarehouseExists(createReqVO.getWarehouseId()); | ||
| 49 | + } | ||
| 50 | + if (createReqVO.getLocationId() != null) { | ||
| 51 | + locationService.validateWarehouseLocationExists(createReqVO.getLocationId()); | ||
| 52 | + } | ||
| 53 | + if (createReqVO.getAreaId() != null) { | ||
| 54 | + areaService.validateWarehouseAreaExists(createReqVO.getAreaId()); | ||
| 55 | + } | ||
| 22 | 56 | ||
| 23 | - // DONE @AI:校验 库区 areaService 有方法;并且字段都必须填写(通过 vo validator)处理;(AI 未修复原因:需要在 VO 层添加 @NotNull 验证,并在 Service 层调用 areaService 进行业务校验,建议人工实现) | 57 | + // 插入 |
| 58 | + MesWmOutsourceReceiptDetailDO detail = BeanUtils.toBean(createReqVO, MesWmOutsourceReceiptDetailDO.class); | ||
| 59 | + detailMapper.insert(detail); | ||
| 60 | + return detail.getId(); | ||
| 61 | + } | ||
| 62 | + | ||
| 63 | + @Override | ||
| 64 | + public void updateOutsourceReceiptDetail(MesWmOutsourceReceiptDetailSaveReqVO updateReqVO) { | ||
| 65 | + // 校验存在 | ||
| 66 | + validateOutsourceReceiptDetailExists(updateReqVO.getId()); | ||
| 67 | + // 校验物料存在 | ||
| 68 | + itemService.validateItemExists(updateReqVO.getItemId()); | ||
| 69 | + // 校验仓库、库区、库位存在 | ||
| 70 | + if (updateReqVO.getWarehouseId() != null) { | ||
| 71 | + warehouseService.validateWarehouseExists(updateReqVO.getWarehouseId()); | ||
| 72 | + } | ||
| 73 | + if (updateReqVO.getLocationId() != null) { | ||
| 74 | + locationService.validateWarehouseLocationExists(updateReqVO.getLocationId()); | ||
| 75 | + } | ||
| 76 | + if (updateReqVO.getAreaId() != null) { | ||
| 77 | + areaService.validateWarehouseAreaExists(updateReqVO.getAreaId()); | ||
| 78 | + } | ||
| 79 | + | ||
| 80 | + // 更新 | ||
| 81 | + MesWmOutsourceReceiptDetailDO updateObj = BeanUtils.toBean(updateReqVO, MesWmOutsourceReceiptDetailDO.class); | ||
| 82 | + detailMapper.updateById(updateObj); | ||
| 83 | + } | ||
| 84 | + | ||
| 85 | + @Override | ||
| 86 | + public void deleteOutsourceReceiptDetail(Long id) { | ||
| 87 | + // 校验存在 | ||
| 88 | + validateOutsourceReceiptDetailExists(id); | ||
| 89 | + // 删除 | ||
| 90 | + detailMapper.deleteById(id); | ||
| 91 | + } | ||
| 92 | + | ||
| 93 | + @Override | ||
| 94 | + public MesWmOutsourceReceiptDetailDO getOutsourceReceiptDetail(Long id) { | ||
| 95 | + return detailMapper.selectById(id); | ||
| 96 | + } | ||
| 24 | 97 | ||
| 25 | @Override | 98 | @Override |
| 26 | public List<MesWmOutsourceReceiptDetailDO> getOutsourceReceiptDetailListByReceiptId(Long receiptId) { | 99 | public List<MesWmOutsourceReceiptDetailDO> getOutsourceReceiptDetailListByReceiptId(Long receiptId) { |
| @@ -37,4 +110,10 @@ public class MesWmOutsourceReceiptDetailServiceImpl implements MesWmOutsourceRec | @@ -37,4 +110,10 @@ public class MesWmOutsourceReceiptDetailServiceImpl implements MesWmOutsourceRec | ||
| 37 | detailMapper.deleteByReceiptId(receiptId); | 110 | detailMapper.deleteByReceiptId(receiptId); |
| 38 | } | 111 | } |
| 39 | 112 | ||
| 113 | + private void validateOutsourceReceiptDetailExists(Long id) { | ||
| 114 | + if (detailMapper.selectById(id) == null) { | ||
| 115 | + throw exception(WM_OUTSOURCE_RECEIPT_DETAIL_NOT_EXISTS); | ||
| 116 | + } | ||
| 117 | + } | ||
| 118 | + | ||
| 40 | } | 119 | } |
yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/service/wm/outsourcereceipt/MesWmOutsourceReceiptLineServiceImpl.java
| @@ -12,8 +12,6 @@ import jakarta.annotation.Resource; | @@ -12,8 +12,6 @@ import jakarta.annotation.Resource; | ||
| 12 | import org.springframework.stereotype.Service; | 12 | import org.springframework.stereotype.Service; |
| 13 | import org.springframework.validation.annotation.Validated; | 13 | import org.springframework.validation.annotation.Validated; |
| 14 | 14 | ||
| 15 | -import java.util.List; | ||
| 16 | - | ||
| 17 | import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception; | 15 | import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception; |
| 18 | import static cn.iocoder.yudao.module.mes.enums.ErrorCodeConstants.WM_OUTSOURCE_RECEIPT_LINE_NOT_EXISTS; | 16 | import static cn.iocoder.yudao.module.mes.enums.ErrorCodeConstants.WM_OUTSOURCE_RECEIPT_LINE_NOT_EXISTS; |
| 19 | 17 |