| | |
| | | import cn.iocoder.yudao.module.mes.dal.dataobject.md.item.MesMdItemDO; |
| | | import cn.iocoder.yudao.module.mes.dal.dataobject.md.unitmeasure.MesMdUnitMeasureDO; |
| | | import cn.iocoder.yudao.module.mes.dal.dataobject.pro.mps.MesProMpsDO; |
| | | import cn.iocoder.yudao.module.mes.dal.dataobject.pro.workorder.MesProWorkOrderDO; |
| | | import cn.iocoder.yudao.module.mes.service.md.item.MesMdItemService; |
| | | import cn.iocoder.yudao.module.mes.service.md.unitmeasure.MesMdUnitMeasureService; |
| | | import cn.iocoder.yudao.module.mes.service.pro.mps.MesProMpsService; |
| | | import cn.iocoder.yudao.module.mes.service.pro.workorder.MesProWorkOrderService; |
| | | import io.swagger.v3.oas.annotations.Operation; |
| | | import io.swagger.v3.oas.annotations.Parameter; |
| | | import io.swagger.v3.oas.annotations.tags.Tag; |
| | |
| | | @Resource |
| | | private MesMdUnitMeasureService unitMeasureService; |
| | | @Resource |
| | | private MesProWorkOrderService workOrderService; |
| | | @Resource |
| | | private CrmCustomerApi customerApi; |
| | | |
| | | @PostMapping("/create") |
| | |
| | | @GetMapping("/get") |
| | | @Operation(summary = "获得生产主计划") |
| | | @Parameter(name = "id", description = "编号", required = true, example = "1024") |
| | | @PreAuthorize("@ss.hasPermission('mes:pro-mps:query')") |
| | | public CommonResult<MesProMpsRespVO> getMps(@RequestParam("id") Long id) { |
| | | MesProMpsDO mps = mpsService.getMps(id); |
| | | if (mps == null) { |
| | |
| | | |
| | | @GetMapping("/page") |
| | | @Operation(summary = "获得生产主计划分页") |
| | | @PreAuthorize("@ss.hasPermission('mes:pro-mps:query')") |
| | | public CommonResult<PageResult<MesProMpsRespVO>> getMpsPage(@Valid MesProMpsPageReqVO pageReqVO) { |
| | | PageResult<MesProMpsDO> pageResult = mpsService.getMpsPage(pageReqVO); |
| | | return success(new PageResult<>(buildMpsRespVOList(pageResult.getList()), pageResult.getTotal())); |
| | |
| | | convertSet(itemMap.values(), MesMdItemDO::getUnitMeasureId)); |
| | | Map<Long, CrmCustomerRespDTO> clientMap = customerApi.getCustomerMap( |
| | | convertSet(list, MesProMpsDO::getClientId)); |
| | | Map<Long, MesProWorkOrderDO> workOrderMap = workOrderService.getWorkOrderMap( |
| | | convertSet(list, MesProMpsDO::getWorkOrderId)); |
| | | // 2. 拼接 VO |
| | | return BeanUtils.toBean(list, MesProMpsRespVO.class, vo -> { |
| | | MapUtils.findAndThen(itemMap, vo.getProductId(), item -> { |
| | |
| | | }); |
| | | MapUtils.findAndThen(clientMap, vo.getClientId(), |
| | | client -> vo.setClientName(client.getName())); |
| | | // 成本按 MPS 计划数量占工单数量比例分摊(合并下发时多条 MPS 共享同一工单) |
| | | MapUtils.findAndThen(workOrderMap, vo.getWorkOrderId(), workOrder -> { |
| | | if (workOrder.getQuantity() == null || workOrder.getQuantity().compareTo(java.math.BigDecimal.ZERO) <= 0) { |
| | | return; |
| | | } |
| | | java.math.BigDecimal ratio = vo.getQuantity().divide(workOrder.getQuantity(), 8, |
| | | java.math.RoundingMode.HALF_UP); |
| | | vo.setStandardMaterialCost(apportion(workOrder.getStandardMaterialCost(), ratio)); |
| | | vo.setActualMaterialCost(apportion(workOrder.getActualMaterialCost(), ratio)); |
| | | vo.setOverConsumeCost(apportion(workOrder.getOverConsumeCost(), ratio)); |
| | | vo.setMaterialUnitCost(workOrder.getMaterialUnitCost()); |
| | | }); |
| | | }); |
| | | } |
| | | |
| | | private static java.math.BigDecimal apportion(java.math.BigDecimal amount, java.math.BigDecimal ratio) { |
| | | return amount != null ? amount.multiply(ratio).setScale(6, java.math.RoundingMode.HALF_UP) : null; |
| | | } |
| | | |
| | | } |