| | |
| | | import cn.iocoder.yudao.framework.common.util.collection.MapUtils; |
| | | import cn.iocoder.yudao.framework.common.util.object.BeanUtils; |
| | | import cn.iocoder.yudao.module.mes.controller.admin.wm.batch.vo.MesWmBatchPageReqVO; |
| | | import cn.iocoder.yudao.module.mes.controller.admin.wm.batch.vo.MesWmBatchProcessTraceRespVO; |
| | | import cn.iocoder.yudao.module.mes.controller.admin.wm.batch.vo.MesWmBatchPurchaseSourceRespVO; |
| | | import cn.iocoder.yudao.module.mes.controller.admin.wm.batch.vo.MesWmBatchRespVO; |
| | | import cn.iocoder.yudao.module.mes.controller.admin.wm.batch.vo.MesWmBatchSalesTargetRespVO; |
| | | import cn.iocoder.yudao.module.crm.api.customer.CrmCustomerApi; |
| | | import cn.iocoder.yudao.module.crm.api.customer.dto.CrmCustomerRespDTO; |
| | | import cn.iocoder.yudao.module.srm.api.supplier.SrmSupplierApi; |
| | |
| | | import cn.iocoder.yudao.module.mdm.api.item.dto.MdmItemRespDTO; |
| | | |
| | | import cn.iocoder.yudao.module.mes.dal.dataobject.md.workstation.MesMdWorkstationDO; |
| | | import cn.iocoder.yudao.module.mes.dal.dataobject.pro.process.MesProProcessDO; |
| | | import cn.iocoder.yudao.module.mes.dal.dataobject.pro.task.MesProTaskDO; |
| | | import cn.iocoder.yudao.module.mes.dal.dataobject.pro.workorder.MesProWorkOrderDO; |
| | | import cn.iocoder.yudao.module.mes.dal.dataobject.tm.tool.MesTmToolDO; |
| | |
| | | import cn.iocoder.yudao.module.mdm.api.unit.dto.MdmUnitMeasureRespDTO; |
| | | |
| | | import cn.iocoder.yudao.module.mes.service.md.workstation.MesMdWorkstationService; |
| | | import cn.iocoder.yudao.module.mes.service.pro.process.MesProProcessService; |
| | | import cn.iocoder.yudao.module.mes.service.pro.task.MesProTaskService; |
| | | import cn.iocoder.yudao.module.mes.service.pro.workorder.MesProWorkOrderService; |
| | | import cn.iocoder.yudao.module.mes.service.tm.tool.MesTmToolService; |
| | |
| | | private MesMdWorkstationService workstationService; |
| | | @Resource |
| | | private MesTmToolService toolService; |
| | | @Resource |
| | | private MesProProcessService processService; |
| | | |
| | | @GetMapping("/get") |
| | | @Operation(summary = "获得批次详情") |
| | |
| | | public CommonResult<List<MesWmBatchRespVO>> getBackwardList(@RequestParam("code") @Valid String code) { |
| | | List<MesWmBatchDO> list = batchService.getBackwardBatchList(code); |
| | | return success(buildBatchRespVOList(list)); |
| | | } |
| | | |
| | | @GetMapping("/purchase-sources") |
| | | @Operation(summary = "批次采购来源(采购入库单 + IQC)") |
| | | @Parameter(name = "code", description = "批次编码", required = true, example = "BATCH20250314001") |
| | | @PreAuthorize("@ss.hasPermission('mes:wm-batch:query')") |
| | | public CommonResult<List<MesWmBatchPurchaseSourceRespVO>> getPurchaseSourceList(@RequestParam("code") @Valid String code) { |
| | | List<MesWmBatchPurchaseSourceRespVO> list = batchService.getPurchaseSourceList(code); |
| | | return success(buildPurchaseSourceRespVOList(list)); |
| | | } |
| | | |
| | | @GetMapping("/sales-targets") |
| | | @Operation(summary = "批次销售去向(销售出库单 + OQC)") |
| | | @Parameter(name = "code", description = "批次编码", required = true, example = "BATCH20250314001") |
| | | @PreAuthorize("@ss.hasPermission('mes:wm-batch:query')") |
| | | public CommonResult<List<MesWmBatchSalesTargetRespVO>> getSalesTargetList(@RequestParam("code") @Valid String code) { |
| | | List<MesWmBatchSalesTargetRespVO> list = batchService.getSalesTargetList(code); |
| | | return success(buildSalesTargetRespVOList(list)); |
| | | } |
| | | |
| | | @GetMapping("/process-trace") |
| | | @Operation(summary = "批次工序流转(产出/投入事件)") |
| | | @Parameter(name = "code", description = "批次编码", required = true, example = "BATCH20250314001") |
| | | @PreAuthorize("@ss.hasPermission('mes:wm-batch:query')") |
| | | public CommonResult<List<MesWmBatchProcessTraceRespVO>> getProcessTraceList(@RequestParam("code") @Valid String code) { |
| | | List<MesWmBatchProcessTraceRespVO> list = batchService.getProcessTraceList(code); |
| | | return success(buildProcessTraceRespVOList(list)); |
| | | } |
| | | |
| | | @GetMapping("/get-by-sn") |
| | | @Operation(summary = "根据 SN 码反查批次") |
| | | @Parameter(name = "sn", description = "SN 序列号", required = true, example = "SN20250314001") |
| | | @PreAuthorize("@ss.hasPermission('mes:wm-batch:query')") |
| | | public CommonResult<MesWmBatchRespVO> getBatchBySn(@RequestParam("sn") @Valid String sn) { |
| | | MesWmBatchDO batch = batchService.getBatchBySn(sn); |
| | | return success(buildBatchRespVO(batch)); |
| | | } |
| | | |
| | | // ==================== 拼接 VO ==================== |
| | |
| | | return buildBatchRespVOList(Collections.singletonList(batch)).get(0); |
| | | } |
| | | |
| | | private List<MesWmBatchPurchaseSourceRespVO> buildPurchaseSourceRespVOList(List<MesWmBatchPurchaseSourceRespVO> list) { |
| | | if (CollUtil.isEmpty(list)) { |
| | | return Collections.emptyList(); |
| | | } |
| | | Map<Long, MdmItemRespDTO> itemMap = mdmItemApi.getItemMap( |
| | | convertSet(list, MesWmBatchPurchaseSourceRespVO::getItemId)); |
| | | Map<Long, SrmSupplierRespDTO> vendorMap = srmSupplierApi.getSupplierList( |
| | | convertSet(list, MesWmBatchPurchaseSourceRespVO::getVendorId)).getCheckedData().stream() |
| | | .collect(Collectors.toMap(SrmSupplierRespDTO::getId, s -> s)); |
| | | list.forEach(vo -> { |
| | | MapUtils.findAndThen(itemMap, vo.getItemId(), item -> { |
| | | vo.setItemCode(item.getCode()).setItemName(item.getName()); |
| | | }); |
| | | MapUtils.findAndThen(vendorMap, vo.getVendorId(), |
| | | vendor -> vo.setVendorCode(vendor.getCode()).setVendorName(vendor.getName())); |
| | | }); |
| | | return list; |
| | | } |
| | | |
| | | private List<MesWmBatchSalesTargetRespVO> buildSalesTargetRespVOList(List<MesWmBatchSalesTargetRespVO> list) { |
| | | if (CollUtil.isEmpty(list)) { |
| | | return Collections.emptyList(); |
| | | } |
| | | Map<Long, MdmItemRespDTO> itemMap = mdmItemApi.getItemMap( |
| | | convertSet(list, MesWmBatchSalesTargetRespVO::getItemId)); |
| | | Map<Long, CrmCustomerRespDTO> clientMap = customerApi.getCustomerMap( |
| | | convertSet(list, MesWmBatchSalesTargetRespVO::getClientId)); |
| | | list.forEach(vo -> { |
| | | MapUtils.findAndThen(itemMap, vo.getItemId(), item -> { |
| | | vo.setItemCode(item.getCode()).setItemName(item.getName()); |
| | | }); |
| | | MapUtils.findAndThen(clientMap, vo.getClientId(), |
| | | client -> vo.setClientName(client.getName())); |
| | | }); |
| | | return list; |
| | | } |
| | | |
| | | private List<MesWmBatchProcessTraceRespVO> buildProcessTraceRespVOList(List<MesWmBatchProcessTraceRespVO> list) { |
| | | if (CollUtil.isEmpty(list)) { |
| | | return Collections.emptyList(); |
| | | } |
| | | Map<Long, MesProWorkOrderDO> workOrderMap = workOrderService.getWorkOrderMap( |
| | | convertSet(list, MesWmBatchProcessTraceRespVO::getWorkOrderId)); |
| | | Map<Long, MesProProcessDO> processMap = processService.getProcessMap( |
| | | convertSet(list, MesWmBatchProcessTraceRespVO::getProcessId)); |
| | | list.forEach(vo -> { |
| | | MapUtils.findAndThen(workOrderMap, vo.getWorkOrderId(), |
| | | workOrder -> vo.setWorkOrderCode(workOrder.getCode())); |
| | | MapUtils.findAndThen(processMap, vo.getProcessId(), |
| | | process -> vo.setProcessCode(process.getCode()).setProcessName(process.getName())); |
| | | }); |
| | | return list; |
| | | } |
| | | |
| | | } |