| | |
| | | package cn.iocoder.yudao.module.erp.controller.admin.sale; |
| | | |
| | | import cn.hutool.core.collection.CollUtil; |
| | | import cn.hutool.core.util.ObjectUtil; |
| | | import cn.iocoder.yudao.framework.apilog.core.annotation.ApiAccessLog; |
| | | import cn.iocoder.yudao.framework.common.pojo.CommonResult; |
| | | import cn.iocoder.yudao.framework.common.pojo.PageParam; |
| | |
| | | import cn.iocoder.yudao.module.mdm.api.unit.MdmUnitMeasureApi; |
| | | import cn.iocoder.yudao.module.mdm.api.unit.dto.MdmUnitMeasureRespDTO; |
| | | import cn.iocoder.yudao.module.mes.api.mps.MesProMpsApi; |
| | | import cn.iocoder.yudao.module.mes.api.mps.dto.MesProMpsRespDTO; |
| | | import cn.iocoder.yudao.module.mes.api.productsales.MesWmProductSalesLineApi; |
| | | import cn.iocoder.yudao.module.mes.api.salesnotice.MesWmSalesNoticeApi; |
| | | import cn.iocoder.yudao.module.mes.api.wms.MesWmStockApi; |
| | |
| | | |
| | | @GetMapping("/approve-process-list") |
| | | @Operation(summary = "获取销售订单审批流程列表") |
| | | @PreAuthorize("@ss.hasPermission('erp:sale-order:query')") |
| | | public CommonResult<List<Map<String, Object>>> getApproveProcessList() { |
| | | return success(saleOrderService.getSaleOrderApproveProcessDefinitionList()); |
| | | } |
| | |
| | | @GetMapping("/item/list-by-order-id") |
| | | @Operation(summary = "查询销售订单的物料明细列表(用于发货通知单创建)") |
| | | @Parameter(name = "orderId", description = "销售订单编号", required = true, example = "1") |
| | | @PreAuthorize("@ss.hasPermission('erp:sale-order:query')") |
| | | public CommonResult<List<ErpSaleOrderItemRespVO>> getSaleOrderItemListByOrderId(@RequestParam("orderId") Long orderId) { |
| | | List<ErpSaleOrderItemDO> itemList = saleOrderService.getSaleOrderItemListByOrderId(orderId); |
| | | Map<Long, MdmItemRespDTO> itemMap = mdmItemApi.getItemMap( |
| | |
| | | @GetMapping("/get") |
| | | @Operation(summary = "获得销售订单") |
| | | @Parameter(name = "id", description = "编号", required = true, example = "1024") |
| | | @PreAuthorize("@ss.hasPermission('erp:sale-order:query')") |
| | | public CommonResult<ErpSaleOrderRespVO> getSaleOrder(@RequestParam("id") Long id) { |
| | | ErpSaleOrderDO saleOrder = saleOrderService.getSaleOrder(id); |
| | | if (saleOrder == null) { |
| | |
| | | convertSet(saleOrderItemList, ErpSaleOrderItemDO::getId)); |
| | | Map<Long, MdmUnitMeasureRespDTO> unitMeasureMap = mdmUnitMeasureApi.getUnitMeasureMap( |
| | | convertSet(saleOrderItemList, ErpSaleOrderItemDO::getProductUnitId)); |
| | | Map<Long, MesProMpsRespDTO> mpsMap = getMpsMap(saleOrderItemList); |
| | | // 3. 转换订单项 |
| | | List<ErpSaleOrderRespVO.Item> itemVOList = BeanUtils.toBean(saleOrderItemList, ErpSaleOrderRespVO.Item.class, item -> { |
| | | fillItemPrice(item); |
| | |
| | | item.setBatchCode(batchCodeMap.get(item.getId())); |
| | | MapUtils.findAndThen(itemMap, item.getProductId(), mdmItem -> |
| | | item.setProductName(mdmItem.getName()).setProductBarCode(mdmItem.getBarCode()) |
| | | .setProductCode(mdmItem.getCode()) |
| | | .setProductSpecification(mdmItem.getSpecification())); |
| | | MapUtils.findAndThen(unitMeasureMap, item.getProductUnitId(), unit -> |
| | | item.setProductUnitName(unit.getName())); |
| | | MesProMpsRespDTO mps = mpsMap.get(item.getId()); |
| | | if (mps != null) { |
| | | item.setQuantityProduced(mps.getQuantityProduced()); |
| | | } |
| | | }); |
| | | // 4. 组装响应 |
| | | ErpSaleOrderRespVO saleOrderVO = BeanUtils.toBean(saleOrder, ErpSaleOrderRespVO.class); |
| | | saleOrderVO.setItems(itemVOList); |
| | | saleOrderVO.setProductCodes(CollUtil.join(itemVOList, ",", ErpSaleOrderRespVO.Item::getProductCode)); |
| | | saleOrderVO.setProducedCount(itemVOList.stream() |
| | | .map(item -> ObjectUtil.defaultIfNull(item.getQuantityProduced(), BigDecimal.ZERO)) |
| | | .reduce(BigDecimal.ZERO, BigDecimal::add)); |
| | | saleOrderVO.setNeedProduction(itemVOList.stream() |
| | | .anyMatch(item -> Integer.valueOf(1).equals(item.getNeedProduction())) ? 1 : 0); |
| | | if (saleOrder.getCustomerId() != null) { |
| | | MapUtils.findAndThen(customerApi.getCustomerMap(List.of(saleOrder.getCustomerId())), |
| | | saleOrder.getCustomerId(), customer -> saleOrderVO.setCustomerName(customer.getName())); |
| | | } |
| | | if (saleOrder.getCreator() != null && saleOrder.getCreator().matches("\\d+")) { |
| | | AdminUserRespDTO creator = adminUserApi.getUser(Long.valueOf(saleOrder.getCreator())); |
| | | if (creator != null) { |
| | | saleOrderVO.setCreatorName(creator.getNickname()); |
| | | } |
| | | } |
| | | saleOrderVO.setAttachmentList(storageAttachmentApi.listAttachments("erp_sale_order", id)); |
| | | return success(saleOrderVO); |
| | | } |
| | | |
| | | @GetMapping("/page") |
| | | @Operation(summary = "获得销售订单分页") |
| | | @PreAuthorize("@ss.hasPermission('erp:sale-order:query')") |
| | | public CommonResult<PageResult<ErpSaleOrderRespVO>> getSaleOrderPage(@Valid ErpSaleOrderPageReqVO pageReqVO) { |
| | | PageResult<ErpSaleOrderDO> pageResult = saleOrderService.getSaleOrderPage(pageReqVO); |
| | | return success(buildSaleOrderVOPageResult(pageResult)); |
| | |
| | | // 1.7 计量单位 |
| | | Map<Long, MdmUnitMeasureRespDTO> unitMeasureMap = mdmUnitMeasureApi.getUnitMeasureMap( |
| | | convertSet(saleOrderItemList, ErpSaleOrderItemDO::getProductUnitId)); |
| | | Map<Long, MesProMpsRespDTO> mpsMap = getMpsMap(saleOrderItemList); |
| | | // 1.8 检查是否可以生成发货通知单(需要生产的明细对应的 MPS 是否已完成) |
| | | // 筛选出需要生产的明细ID |
| | | List<Long> needProductionItemIds = saleOrderItemList.stream() |
| | |
| | | item.setBatchCode(batchCodeMap.get(item.getId())); |
| | | MapUtils.findAndThen(itemMap, item.getProductId(), mdmItem -> |
| | | item.setProductName(mdmItem.getName()).setProductBarCode(mdmItem.getBarCode()) |
| | | .setProductCode(mdmItem.getCode()) |
| | | .setProductSpecification(mdmItem.getSpecification())); |
| | | MapUtils.findAndThen(unitMeasureMap, item.getProductUnitId(), unit -> |
| | | item.setProductUnitName(unit.getName())); |
| | | MesProMpsRespDTO mps = mpsMap.get(item.getId()); |
| | | if (mps != null) { |
| | | item.setQuantityProduced(mps.getQuantityProduced()); |
| | | } |
| | | })); |
| | | saleOrder.setProductNames(CollUtil.join(saleOrder.getItems(), ",", ErpSaleOrderRespVO.Item::getProductName)); |
| | | saleOrder.setProductCodes(CollUtil.join(saleOrder.getItems(), ",", ErpSaleOrderRespVO.Item::getProductCode)); |
| | | saleOrder.setProducedCount(saleOrder.getItems().stream() |
| | | .map(item -> ObjectUtil.defaultIfNull(item.getQuantityProduced(), BigDecimal.ZERO)) |
| | | .reduce(BigDecimal.ZERO, BigDecimal::add)); |
| | | MapUtils.findAndThen(customerMap, saleOrder.getCustomerId(), supplier -> saleOrder.setCustomerName(supplier.getName())); |
| | | MapUtils.findAndThen(userMap, Long.parseLong(saleOrder.getCreator()), user -> saleOrder.setCreatorName(user.getNickname())); |
| | | // 设置是否已生成发货通知单 |
| | |
| | | }); |
| | | } |
| | | |
| | | private Map<Long, MesProMpsRespDTO> getMpsMap(List<ErpSaleOrderItemDO> items) { |
| | | if (CollUtil.isEmpty(items)) { |
| | | return java.util.Collections.emptyMap(); |
| | | } |
| | | List<MesProMpsRespDTO> mpsList = mpsApi.getMpsListBySaleOrderItemIds( |
| | | items.stream().map(ErpSaleOrderItemDO::getId).toList()); |
| | | if (CollUtil.isEmpty(mpsList)) { |
| | | return java.util.Collections.emptyMap(); |
| | | } |
| | | return mpsList.stream().filter(mps -> mps.getSaleOrderItemId() != null) |
| | | .collect(java.util.stream.Collectors.toMap(MesProMpsRespDTO::getSaleOrderItemId, |
| | | mps -> mps, (a, b) -> a)); |
| | | } |
| | | |
| | | /** |
| | | * 填充订单项的金额字段 |
| | | * |