| | |
| | | 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.wm.productsales.MesWmProductSalesDO; |
| | | import cn.iocoder.yudao.module.mes.dal.dataobject.wm.productsales.MesWmProductSalesLineDO; |
| | | import cn.iocoder.yudao.module.mes.dal.dataobject.wm.salesnotice.MesWmSalesNoticeDO; |
| | | import cn.iocoder.yudao.module.mes.service.wm.document.MesWmDocumentRenderer; |
| | | import cn.iocoder.yudao.module.mes.service.wm.productsales.MesWmProductSalesLineService; |
| | | import cn.iocoder.yudao.module.mes.service.wm.productsales.MesWmProductSalesService; |
| | | import cn.iocoder.yudao.module.mes.service.wm.salesnotice.MesWmSalesNoticeService; |
| | | import cn.iocoder.yudao.module.mdm.api.item.MdmItemApi; |
| | | import cn.iocoder.yudao.module.mdm.api.item.dto.MdmItemRespDTO; |
| | | import cn.iocoder.yudao.module.mdm.api.unit.MdmUnitMeasureApi; |
| | | import cn.iocoder.yudao.module.mdm.api.unit.dto.MdmUnitMeasureRespDTO; |
| | | import cn.iocoder.yudao.module.system.service.companyconfig.SystemCompanyConfigService; |
| | | 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.net.URLEncoder; |
| | | import java.nio.charset.StandardCharsets; |
| | | import java.time.format.DateTimeFormatter; |
| | | import java.util.*; |
| | | |
| | | import static cn.iocoder.yudao.framework.apilog.core.enums.OperateTypeEnum.EXPORT; |
| | | import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception; |
| | | import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success; |
| | | import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertSet; |
| | | import static cn.iocoder.yudao.module.mes.enums.ErrorCodeConstants.WM_PRODUCT_SALES_NOT_EXISTS; |
| | | |
| | | @Tag(name = "管理后台 - MES 销售出库单") |
| | | @RestController |
| | |
| | | @Resource |
| | | private MesWmProductSalesService productSalesService; |
| | | @Resource |
| | | private MesWmProductSalesLineService productSalesLineService; |
| | | @Resource |
| | | private CrmCustomerApi crmCustomerApi; |
| | | @Resource |
| | | private MesWmSalesNoticeService salesNoticeService; |
| | | @Resource |
| | | private MdmItemApi mdmItemApi; |
| | | @Resource |
| | | private MdmUnitMeasureApi mdmUnitMeasureApi; |
| | | @Resource |
| | | private SystemCompanyConfigService companyConfigService; |
| | | |
| | | @PostMapping("/create") |
| | | @Operation(summary = "创建销售出库单") |
| | |
| | | buildRespVOList(pageResult.getList())); |
| | | } |
| | | |
| | | @GetMapping("/export-word") |
| | | @Operation(summary = "导出成品出库单 Word(带电子章,可手填签字后归档)") |
| | | @Parameter(name = "id", description = "销售出库单编号", required = true) |
| | | @PreAuthorize("@ss.hasPermission('mes:wm-product-sales:export')") |
| | | @ApiAccessLog(operateType = EXPORT) |
| | | public void exportProductSalesWord(@RequestParam("id") Long id, |
| | | HttpServletResponse response) throws IOException { |
| | | MesWmProductSalesDO sales = productSalesService.getProductSales(id); |
| | | if (sales == null) { |
| | | throw exception(WM_PRODUCT_SALES_NOT_EXISTS); |
| | | } |
| | | List<MesWmProductSalesLineDO> lines = productSalesLineService.getProductSalesLineListBySalesId(id); |
| | | Map<Long, MdmItemRespDTO> itemMap = mdmItemApi.getItemMap( |
| | | convertSet(lines, MesWmProductSalesLineDO::getItemId)); |
| | | Map<Long, MdmUnitMeasureRespDTO> unitMap = mdmUnitMeasureApi |
| | | .getUnitMeasureList(convertSet(itemMap.values(), MdmItemRespDTO::getUnitMeasureId)) |
| | | .getCheckedData().stream() |
| | | .collect(java.util.stream.Collectors.toMap(MdmUnitMeasureRespDTO::getId, e -> e)); |
| | | |
| | | Map<String, String> fields = new LinkedHashMap<>(); |
| | | fields.put("clientName", resolveClientName(sales.getClientId())); |
| | | fields.put("code", sales.getCode()); |
| | | fields.put("salesDate", sales.getSalesDate() == null ? null |
| | | : sales.getSalesDate().format(DateTimeFormatter.ofPattern("yyyy-MM-dd"))); |
| | | fields.put("saleOrderCode", sales.getSalesOrderCode()); |
| | | fields.put("noticeCode", resolveNoticeCode(sales.getNoticeId())); |
| | | fields.put("contactName", sales.getContactName()); |
| | | fields.put("contactTelephone", sales.getContactTelephone()); |
| | | fields.put("contactAddress", sales.getContactAddress()); |
| | | fields.put("carrier", sales.getCarrier()); |
| | | fields.put("shippingNumber", sales.getShippingNumber()); |
| | | fields.put("remark", sales.getRemark()); |
| | | |
| | | List<Map<String, String>> items = new ArrayList<>(); |
| | | for (MesWmProductSalesLineDO line : lines) { |
| | | MdmItemRespDTO item = itemMap.get(line.getItemId()); |
| | | Map<String, String> row = new LinkedHashMap<>(); |
| | | row.put("itemName", item != null ? item.getName() : null); |
| | | row.put("itemSpecification", item != null ? item.getSpecification() : null); |
| | | MdmUnitMeasureRespDTO unit = item != null ? unitMap.get(item.getUnitMeasureId()) : null; |
| | | row.put("unitName", unit != null ? unit.getName() : null); |
| | | row.put("quantity", line.getQuantity() == null ? null : line.getQuantity().toPlainString()); |
| | | row.put("price", line.getPrice() == null ? null : line.getPrice().toPlainString()); |
| | | row.put("amount", line.getTotalPrice() == null ? null : line.getTotalPrice().toPlainString()); |
| | | row.put("batchCode", line.getBatchCode()); |
| | | items.add(row); |
| | | } |
| | | |
| | | var companyConfig = companyConfigService.getCompanyConfig(); |
| | | byte[] content = MesWmDocumentRenderer.renderProductOutbound(fields, items, |
| | | companyConfig != null ? companyConfig.getCompanyName() : null); |
| | | writeWord(response, "成品出库单-" + sales.getCode() + ".docx", content); |
| | | } |
| | | |
| | | private String resolveClientName(Long clientId) { |
| | | if (clientId == null) { |
| | | return null; |
| | | } |
| | | CrmCustomerRespDTO customer = crmCustomerApi.getCustomer(clientId); |
| | | return customer != null ? customer.getName() : null; |
| | | } |
| | | |
| | | private String resolveNoticeCode(Long noticeId) { |
| | | if (noticeId == null) { |
| | | return null; |
| | | } |
| | | MesWmSalesNoticeDO notice = salesNoticeService.getSalesNotice(noticeId); |
| | | return notice != null ? notice.getCode() : null; |
| | | } |
| | | |
| | | private static void writeWord(HttpServletResponse response, String filename, byte[] content) throws IOException { |
| | | String encoded = URLEncoder.encode(filename, StandardCharsets.UTF_8).replace("+", "%20"); |
| | | response.setContentType("application/vnd.openxmlformats-officedocument.wordprocessingml.document"); |
| | | response.setHeader("Content-Disposition", "attachment;filename*=UTF-8''" + encoded); |
| | | response.getOutputStream().write(content); |
| | | } |
| | | |
| | | @PutMapping("/submit") |
| | | @Operation(summary = "提交销售出库单") |
| | | @Parameter(name = "id", description = "编号", required = true) |