| | |
| | | import cn.iocoder.yudao.module.mes.controller.admin.wm.returnvendor.vo.MesWmReturnVendorSaveReqVO; |
| | | import cn.iocoder.yudao.module.srm.api.supplier.SrmSupplierApi; |
| | | import cn.iocoder.yudao.module.srm.api.supplier.dto.SrmSupplierRespDTO; |
| | | import cn.iocoder.yudao.module.erp.api.finance.ErpFinancePaymentApi; |
| | | import cn.iocoder.yudao.module.erp.api.finance.dto.ErpFinancePaymentRespDTO; |
| | | import cn.iocoder.yudao.module.mes.dal.dataobject.wm.arrivalnotice.MesWmArrivalNoticeDO; |
| | | import cn.iocoder.yudao.module.mes.dal.dataobject.wm.returnvendor.MesWmReturnVendorDO; |
| | | import cn.iocoder.yudao.module.mes.enums.wm.MesWmReturnVendorStatusEnum; |
| | | import cn.iocoder.yudao.module.mes.service.wm.arrivalnotice.MesWmArrivalNoticeService; |
| | | import cn.iocoder.yudao.module.mes.service.wm.returnvendor.MesWmReturnVendorService; |
| | | import cn.iocoder.yudao.module.mes.service.wm.returnvendor.MesWmReturnVendorServiceImpl; |
| | | import cn.iocoder.yudao.module.system.api.storage.StorageAttachmentApi; |
| | | import cn.iocoder.yudao.module.system.api.storage.dto.StorageBlobRespDTO; |
| | | import io.swagger.v3.oas.annotations.Operation; |
| | | import io.swagger.v3.oas.annotations.Parameter; |
| | | import io.swagger.v3.oas.annotations.tags.Tag; |
| | |
| | | import org.springframework.web.bind.annotation.*; |
| | | |
| | | import java.io.IOException; |
| | | import java.util.Arrays; |
| | | import java.util.Collections; |
| | | import java.util.List; |
| | | import java.util.Map; |
| | |
| | | private MesWmReturnVendorService returnVendorService; |
| | | @Resource |
| | | private SrmSupplierApi srmSupplierApi; |
| | | @Resource |
| | | private StorageAttachmentApi storageAttachmentApi; |
| | | @Resource |
| | | private ErpFinancePaymentApi financePaymentApi; |
| | | @Resource |
| | | private MesWmArrivalNoticeService arrivalNoticeService; |
| | | |
| | | @PostMapping("/create") |
| | | @Operation(summary = "创建供应商退货单") |
| | |
| | | @GetMapping("/get") |
| | | @Operation(summary = "获得供应商退货单") |
| | | @Parameter(name = "id", description = "编号", required = true, example = "1024") |
| | | @PreAuthorize("@ss.hasPermission('mes:wm-return-vendor:query')") |
| | | public CommonResult<MesWmReturnVendorRespVO> getReturnVendor(@RequestParam("id") Long id) { |
| | | MesWmReturnVendorDO returnVendor = returnVendorService.getReturnVendor(id); |
| | | if (returnVendor == null) { |
| | |
| | | |
| | | @GetMapping("/page") |
| | | @Operation(summary = "获得供应商退货单分页") |
| | | @PreAuthorize("@ss.hasPermission('mes:wm-return-vendor:query')") |
| | | public CommonResult<PageResult<MesWmReturnVendorRespVO>> getReturnVendorPage( |
| | | @Valid MesWmReturnVendorPageReqVO pageReqVO) { |
| | | PageResult<MesWmReturnVendorDO> pageResult = returnVendorService.getReturnVendorPage(pageReqVO); |
| | |
| | | public CommonResult<Boolean> submitReturnVendor(@RequestParam("id") Long id) { |
| | | returnVendorService.submitReturnVendor(id); |
| | | return success(true); |
| | | } |
| | | |
| | | @PutMapping("/submit-approval") |
| | | @Operation(summary = "提交供应商退货单审批", description = "走 BPM 流程:采购 -> 质量 -> 仓库") |
| | | @Parameter(name = "id", description = "编号", required = true) |
| | | @Parameter(name = "processDefinitionKey", description = "流程定义 Key", required = true, example = "purchase_return_vendor_approve") |
| | | @PreAuthorize("@ss.hasPermission('mes:wm-return-vendor:submit-approval')") |
| | | public CommonResult<Boolean> submitReturnVendorApproval(@RequestParam("id") Long id, |
| | | @RequestParam("processDefinitionKey") String processDefinitionKey) { |
| | | returnVendorService.submitReturnVendorApproval(id, processDefinitionKey); |
| | | return success(true); |
| | | } |
| | | |
| | | @GetMapping("/attachments") |
| | | @Operation(summary = "获得供应商退货单附件列表") |
| | | @Parameter(name = "id", description = "编号", required = true) |
| | | public CommonResult<List<StorageBlobRespDTO>> getReturnVendorAttachments(@RequestParam("id") Long id) { |
| | | return success(storageAttachmentApi.listAttachments( |
| | | MesWmReturnVendorServiceImpl.RETURN_VENDOR_RECORD_TYPE, id)); |
| | | } |
| | | |
| | | @PostMapping("/red-flush") |
| | | @Operation(summary = "生成采购退货负数冲红付款单", description = "幂等:已生成则直接返回已有冲红单编号") |
| | | @Parameter(name = "id", description = "编号", required = true) |
| | | @PreAuthorize("@ss.hasPermission('mes:wm-return-vendor:finish')") |
| | | public CommonResult<Long> createRedFlushPayment(@RequestParam("id") Long id) { |
| | | return success(returnVendorService.createRedFlushPayment(id)); |
| | | } |
| | | |
| | | @PostMapping("/replacement-notice") |
| | | @Operation(summary = "生成换货到货通知单", description = "幂等:已生成则直接返回已有到货通知单编号") |
| | | @Parameter(name = "id", description = "编号", required = true) |
| | | @PreAuthorize("@ss.hasPermission('mes:wm-return-vendor:finish')") |
| | | public CommonResult<Long> createReplacementNotice(@RequestParam("id") Long id) { |
| | | return success(returnVendorService.createReplacementNotice(id)); |
| | | } |
| | | |
| | | @PutMapping("/stock") |
| | |
| | | @GetMapping("/check-quantity") |
| | | @Operation(summary = "校验供应商退货单数量", description = "校验每行明细数量之和是否等于行退货数量") |
| | | @Parameter(name = "id", description = "编号", required = true) |
| | | @PreAuthorize("@ss.hasPermission('mes:wm-return-vendor:query')") |
| | | public CommonResult<Boolean> checkReturnVendorQuantity(@RequestParam("id") Long id) { |
| | | return success(returnVendorService.checkReturnVendorQuantity(id)); |
| | | } |
| | |
| | | convertSet(list, MesWmReturnVendorDO::getVendorId)).getCheckedData().stream() |
| | | .collect(java.util.stream.Collectors.toMap(SrmSupplierRespDTO::getId, s -> s)); |
| | | // 2. 构建结果 |
| | | return BeanUtils.toBean(list, MesWmReturnVendorRespVO.class, vo -> |
| | | MapUtils.findAndThen(vendorMap, vo.getVendorId(), vendor -> { |
| | | vo.setVendorName(vendor.getName()); |
| | | vo.setVendorCode(vendor.getCode()); |
| | | })); |
| | | return BeanUtils.toBean(list, MesWmReturnVendorRespVO.class, vo -> { |
| | | MapUtils.findAndThen(vendorMap, vo.getVendorId(), vendor -> { |
| | | vo.setVendorName(vendor.getName()); |
| | | vo.setVendorCode(vendor.getCode()); |
| | | }); |
| | | vo.setStatusName(resolveStatusName(vo.getStatus())); |
| | | vo.setAttachmentList(storageAttachmentApi.listAttachments( |
| | | MesWmReturnVendorServiceImpl.RETURN_VENDOR_RECORD_TYPE, vo.getId())); |
| | | // 冲红单号 / 换货到货单号(仅在已生成时查询) |
| | | if (vo.getRedFlushPaymentId() != null) { |
| | | ErpFinancePaymentRespDTO payment = financePaymentApi |
| | | .getFinancePayment(vo.getRedFlushPaymentId()).getCheckedData(); |
| | | if (payment != null) { |
| | | vo.setRedFlushPaymentNo(payment.getNo()); |
| | | } |
| | | } |
| | | if (vo.getReplacementNoticeId() != null) { |
| | | MesWmArrivalNoticeDO notice = arrivalNoticeService.getArrivalNotice(vo.getReplacementNoticeId()); |
| | | if (notice != null) { |
| | | vo.setReplacementNoticeCode(notice.getCode()); |
| | | } |
| | | } |
| | | }); |
| | | } |
| | | |
| | | private String resolveStatusName(Integer status) { |
| | | MesWmReturnVendorStatusEnum statusEnum = Arrays.stream(MesWmReturnVendorStatusEnum.values()) |
| | | .filter(item -> item.getStatus().equals(status)).findFirst().orElse(null); |
| | | return statusEnum != null ? statusEnum.getName() : null; |
| | | } |
| | | |
| | | } |