| | |
| | | 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 io.swagger.v3.oas.annotations.Parameter; |
| | | import io.swagger.v3.oas.annotations.Parameters; |
| | | import io.swagger.v3.oas.annotations.tags.Tag; |
| | | import jakarta.annotation.Resource; |
| | | import jakarta.servlet.http.HttpServletResponse; |
| | |
| | | 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.util.*; |
| | |
| | | @Resource |
| | | private MesWmProductSalesService productSalesService; |
| | | @Resource |
| | | private MesMdClientService clientService; |
| | | private CrmCustomerApi crmCustomerApi; |
| | | @Resource |
| | | private MesWmSalesNoticeService salesNoticeService; |
| | | |
| | |
| | | return success(true); |
| | | } |
| | | |
| | | @GetMapping("/get-import-template") |
| | | @Operation(summary = "获得销售出库单导入模板") |
| | | public void importTemplate(HttpServletResponse response) throws IOException { |
| | | // 手动创建导出 demo |
| | | List<MesWmProductSalesImportExcelVO> list = Collections.singletonList( |
| | | MesWmProductSalesImportExcelVO.builder() |
| | | .code("XS001").name("示例销售出库单") |
| | | .salesDate(java.time.LocalDateTime.now()).salesOrderCode("SO001") |
| | | .contactName("张三").remark("").build() |
| | | ); |
| | | // 输出 |
| | | ExcelUtils.write(response, "销售出库单导入模板.xls", "销售出库单列表", MesWmProductSalesImportExcelVO.class, list); |
| | | } |
| | | |
| | | @PostMapping("/import") |
| | | @Operation(summary = "导入销售出库单") |
| | | @Parameters({ |
| | | @Parameter(name = "file", description = "Excel 文件", required = true), |
| | | @Parameter(name = "updateSupport", description = "是否支持更新,默认为 false", example = "true") |
| | | }) |
| | | @PreAuthorize("@ss.hasPermission('mes:wm-product-sales:import')") |
| | | public CommonResult<MesWmProductSalesImportRespVO> importExcel(@RequestParam("file") MultipartFile file, |
| | | @RequestParam(value = "updateSupport", required = false, |
| | | defaultValue = "false") Boolean updateSupport) throws Exception { |
| | | List<MesWmProductSalesImportExcelVO> list = ExcelUtils.read(file, MesWmProductSalesImportExcelVO.class); |
| | | return success(productSalesService.importProductSalesList(list, updateSupport)); |
| | | } |
| | | |
| | | // ==================== 拼接 VO ==================== |
| | | |
| | | private List<MesWmProductSalesRespVO> buildRespVOList(List<MesWmProductSalesDO> list) { |
| | |
| | | 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())); |
| | | }); |
| | | } |
| | | |
| | | } |
| | | } |