| | |
| | | import cn.iocoder.yudao.framework.common.util.collection.MapUtils; |
| | | import cn.iocoder.yudao.framework.common.util.object.BeanUtils; |
| | | import cn.iocoder.yudao.framework.excel.core.util.ExcelUtils; |
| | | import cn.iocoder.yudao.module.crm.api.customer.CrmCustomerApi; |
| | | import cn.iocoder.yudao.module.crm.api.customer.dto.CrmCustomerRespDTO; |
| | | import cn.iocoder.yudao.module.mes.controller.admin.wm.productsales.vo.MesWmProductSalesImportExcelVO; |
| | | import cn.iocoder.yudao.module.mes.controller.admin.wm.productsales.vo.MesWmProductSalesImportRespVO; |
| | | import cn.iocoder.yudao.module.mes.controller.admin.wm.productsales.vo.MesWmProductSalesPageReqVO; |
| | | import cn.iocoder.yudao.module.mes.controller.admin.wm.productsales.vo.MesWmProductSalesRespVO; |
| | | import cn.iocoder.yudao.module.mes.controller.admin.wm.productsales.vo.MesWmProductSalesSaveReqVO; |
| | | import cn.iocoder.yudao.module.mes.controller.admin.wm.productsales.vo.MesWmProductSalesShippingReqVO; |
| | | import cn.iocoder.yudao.module.mes.dal.dataobject.md.client.MesMdClientDO; |
| | | import cn.iocoder.yudao.module.mes.dal.dataobject.wm.productsales.MesWmProductSalesDO; |
| | | import cn.iocoder.yudao.module.mes.dal.dataobject.wm.salesnotice.MesWmSalesNoticeDO; |
| | | import cn.iocoder.yudao.module.mes.service.md.client.MesMdClientService; |
| | | import cn.iocoder.yudao.module.mes.service.wm.productsales.MesWmProductSalesService; |
| | | import cn.iocoder.yudao.module.mes.service.wm.salesnotice.MesWmSalesNoticeService; |
| | | import io.swagger.v3.oas.annotations.Operation; |
| | |
| | | import org.springframework.security.access.prepost.PreAuthorize; |
| | | import org.springframework.validation.annotation.Validated; |
| | | import org.springframework.web.bind.annotation.*; |
| | | import org.springframework.web.multipart.MultipartFile; |
| | | |
| | | import java.io.IOException; |
| | | import java.math.BigDecimal; |
| | | import java.util.*; |
| | | |
| | | import static cn.iocoder.yudao.framework.apilog.core.enums.OperateTypeEnum.EXPORT; |
| | |
| | | @Resource |
| | | private MesWmProductSalesService productSalesService; |
| | | @Resource |
| | | private MesMdClientService clientService; |
| | | private CrmCustomerApi crmCustomerApi; |
| | | @Resource |
| | | private MesWmSalesNoticeService salesNoticeService; |
| | | |
| | |
| | | PageResult<MesWmProductSalesDO> pageResult = productSalesService.getProductSalesPage(pageReqVO); |
| | | ExcelUtils.write(response, "销售出库单.xls", "数据", MesWmProductSalesRespVO.class, |
| | | buildRespVOList(pageResult.getList())); |
| | | } |
| | | |
| | | @GetMapping("/get-import-template") |
| | | @Operation(summary = "获得销售出库单导入模板") |
| | | @PreAuthorize("@ss.hasPermission('mes:wm-product-sales:import')") |
| | | public void importTemplate(HttpServletResponse response) throws IOException { |
| | | List<MesWmProductSalesImportExcelVO> list = Arrays.asList( |
| | | // 同一出库单号的两行 = 同一张出库单的两条明细 |
| | | MesWmProductSalesImportExcelVO.builder() |
| | | .code("PS202610310001").clientName("示例客户").name("示例客户-2026-10-31 出库") |
| | | .salesDate("2026-10-31").salesOrderCode("").contactName("张三") |
| | | .contactTelephone("13800138000").contactAddress("示例收货地址") |
| | | .itemCode("ITEM001").batchCode("").quantity(new BigDecimal("10")) |
| | | .oqcCheckFlag("否").remark("示例数据,导入前请替换").build(), |
| | | MesWmProductSalesImportExcelVO.builder() |
| | | .code("PS202610310001").clientName("示例客户").name("示例客户-2026-10-31 出库") |
| | | .salesDate("2026-10-31").salesOrderCode("").contactName("张三") |
| | | .contactTelephone("13800138000").contactAddress("示例收货地址") |
| | | .itemCode("ITEM002").batchCode("").quantity(new BigDecimal("5")) |
| | | .oqcCheckFlag("否").remark("示例数据,导入前请替换").build()); |
| | | ExcelUtils.write(response, "销售出库单导入模板.xls", "销售出库单", MesWmProductSalesImportExcelVO.class, list); |
| | | } |
| | | |
| | | @PostMapping("/import") |
| | | @Operation(summary = "导入销售出库单", description = "导入后生成草稿状态的出库单,不提交、不占用库存") |
| | | @PreAuthorize("@ss.hasPermission('mes:wm-product-sales:import')") |
| | | public CommonResult<MesWmProductSalesImportRespVO> importProductSalesExcel( |
| | | @RequestParam("file") MultipartFile file) throws Exception { |
| | | List<MesWmProductSalesImportExcelVO> list = ExcelUtils.read(file, MesWmProductSalesImportExcelVO.class); |
| | | return success(productSalesService.importProductSalesList(list)); |
| | | } |
| | | |
| | | @PutMapping("/submit") |
| | |
| | | return Collections.emptyList(); |
| | | } |
| | | // 1. 获得关联数据 |
| | | Map<Long, MesMdClientDO> clientMap = clientService.getClientMap( |
| | | Map<Long, CrmCustomerRespDTO> customerMap = crmCustomerApi.getCustomerMap( |
| | | convertSet(list, MesWmProductSalesDO::getClientId)); |
| | | Map<Long, MesWmSalesNoticeDO> noticeMap = salesNoticeService.getSalesNoticeMap( |
| | | convertSet(list, MesWmProductSalesDO::getNoticeId)); |
| | | // 2. 构建结果 |
| | | return BeanUtils.toBean(list, MesWmProductSalesRespVO.class, vo -> { |
| | | MapUtils.findAndThen(clientMap, vo.getClientId(), client -> |
| | | vo.setClientName(client.getName()).setClientCode(client.getCode())); |
| | | MapUtils.findAndThen(customerMap, vo.getClientId(), customer -> |
| | | vo.setClientName(customer.getName())); |
| | | MapUtils.findAndThen(noticeMap, vo.getNoticeId(), |
| | | notice -> vo.setNoticeCode(notice.getCode())); |
| | | }); |
| | | } |
| | | |
| | | } |
| | | } |