| | |
| | | import cn.iocoder.yudao.framework.common.util.object.BeanUtils; |
| | | import cn.iocoder.yudao.framework.excel.core.util.ExcelUtils; |
| | | import cn.iocoder.yudao.module.mes.controller.admin.pro.mps.vo.MesProMpsPageReqVO; |
| | | import cn.iocoder.yudao.module.mes.controller.admin.pro.mps.vo.MesProMpsPreparationCheckRespVO; |
| | | import cn.iocoder.yudao.module.mes.controller.admin.pro.mps.vo.MesProMpsRespVO; |
| | | import cn.iocoder.yudao.module.mes.controller.admin.pro.mps.vo.MesProMpsSaveReqVO; |
| | | import cn.iocoder.yudao.module.mes.controller.admin.pro.workorder.vo.MesProWorkOrderItemRespVO; |
| | | 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.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.enums.pro.MesProMpsStatusEnum; |
| | | 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.system.api.user.AdminUserApi; |
| | | import cn.iocoder.yudao.module.system.api.user.dto.AdminUserRespDTO; |
| | | 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.math.BigDecimal; |
| | | import java.math.RoundingMode; |
| | | import java.time.Duration; |
| | | import java.time.LocalDateTime; |
| | | import java.util.Collections; |
| | | import java.util.List; |
| | | import java.util.Map; |
| | |
| | | @Resource |
| | | private MesMdItemService itemService; |
| | | @Resource |
| | | private MesMdUnitMeasureService unitMeasureService; |
| | | @Resource |
| | | private CrmCustomerApi customerApi; |
| | | @Resource |
| | | private AdminUserApi adminUserApi; |
| | | |
| | | @PostMapping("/create") |
| | | @Operation(summary = "创建生产主计划") |
| | |
| | | @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())); |
| | |
| | | return success(true); |
| | | } |
| | | |
| | | @PostMapping("/submit") |
| | | @Operation(summary = "提交生产主计划审核") |
| | | @Parameter(name = "id", description = "MPS 编号", required = true) |
| | | @PreAuthorize("@ss.hasPermission('mes:pro-mps:submit')") |
| | | public CommonResult<Boolean> submitMps(@RequestParam("id") Long id) { |
| | | mpsService.submitMps(id); |
| | | return success(true); |
| | | } |
| | | |
| | | @GetMapping("/item-list") |
| | | @Operation(summary = "获得生产主计划辅料需求列表") |
| | | @Parameter(name = "id", description = "MPS 编号", required = true) |
| | | public CommonResult<List<MesProWorkOrderItemRespVO>> getMpsItemList(@RequestParam("id") Long id) { |
| | | return success(mpsService.getMpsItemList(id)); |
| | | } |
| | | |
| | | @GetMapping("/preparation-check") |
| | | @Operation(summary = "生产准备检查(物料、设备)") |
| | | @Parameter(name = "id", description = "MPS 编号", required = true) |
| | | @PreAuthorize("@ss.hasPermission('mes:pro-mps:query')") |
| | | public CommonResult<MesProMpsPreparationCheckRespVO> getPreparationCheck(@RequestParam("id") Long id) { |
| | | return success(mpsService.getPreparationCheck(id)); |
| | | } |
| | | |
| | | @PostMapping("/generate-purchase-request") |
| | | @Operation(summary = "根据生产主计划辅料缺口生成采购申请单") |
| | | @Parameter(name = "id", description = "MPS 编号", required = true) |
| | | @PreAuthorize("@ss.hasPermission('mes:pro-mps:generate-purchase')") |
| | | public CommonResult<Long> generatePurchaseRequest(@RequestParam("id") Long id) { |
| | | return success(mpsService.generatePurchaseRequest(id)); |
| | | } |
| | | |
| | | // ==================== 拼接 VO ==================== |
| | | |
| | | private List<MesProMpsRespVO> buildMpsRespVOList(List<MesProMpsDO> list) { |
| | |
| | | // 1. 批量获取关联数据 |
| | | Map<Long, MesMdItemDO> itemMap = itemService.getItemMap( |
| | | convertSet(list, MesProMpsDO::getProductId)); |
| | | Map<Long, MesMdUnitMeasureDO> unitMap = unitMeasureService.getUnitMeasureMap( |
| | | convertSet(itemMap.values(), MesMdItemDO::getUnitMeasureId)); |
| | | Map<Long, CrmCustomerRespDTO> clientMap = customerApi.getCustomerMap( |
| | | convertSet(list, MesProMpsDO::getClientId)); |
| | | Map<Long, AdminUserRespDTO> auditUserMap = adminUserApi.getUserMap( |
| | | convertSet(list, MesProMpsDO::getAuditUserId)); |
| | | // 2. 拼接 VO |
| | | return BeanUtils.toBean(list, MesProMpsRespVO.class, vo -> { |
| | | MapUtils.findAndThen(itemMap, vo.getProductId(), item -> { |
| | | vo.setProductName(item.getName()) |
| | | .setProductCode(item.getCode()) |
| | | .setProductSpecification(item.getSpecification()); |
| | | MapUtils.findAndThen(unitMap, item.getUnitMeasureId(), |
| | | unit -> vo.setUnitMeasureName(unit.getName())); |
| | | }); |
| | | MapUtils.findAndThen(clientMap, vo.getClientId(), |
| | | client -> vo.setClientName(client.getName())); |
| | | MapUtils.findAndThen(auditUserMap, vo.getAuditUserId(), |
| | | user -> vo.setAuditUserName(user.getNickname())); |
| | | vo.setProgressWarning(buildProgressWarning(vo)); |
| | | }); |
| | | } |
| | | |
| | | /** |
| | | * 计算执行进度预警:已下发计划按“工期已过比例 - 实际完成比例”判断,偏差达到 20% 提示 |
| | | */ |
| | | private String buildProgressWarning(MesProMpsRespVO vo) { |
| | | if (!MesProMpsStatusEnum.ISSUED.getStatus().equals(vo.getStatus())) { |
| | | return null; |
| | | } |
| | | LocalDateTime start = vo.getIssueDate() != null ? vo.getIssueDate() : vo.getPlanStartDate(); |
| | | LocalDateTime end = vo.getRequestDate(); |
| | | if (start == null || end == null || !end.isAfter(start)) { |
| | | return null; |
| | | } |
| | | long totalMinutes = Duration.between(start, end).toMinutes(); |
| | | long elapsedMinutes = Duration.between(start, LocalDateTime.now()).toMinutes(); |
| | | double plannedRatio = Math.min(1D, Math.max(0D, (double) elapsedMinutes / totalMinutes)); |
| | | BigDecimal quantity = vo.getQuantity() != null ? vo.getQuantity() : BigDecimal.ZERO; |
| | | BigDecimal produced = vo.getQuantityProduced() != null ? vo.getQuantityProduced() : BigDecimal.ZERO; |
| | | double producedRatio = quantity.compareTo(BigDecimal.ZERO) > 0 |
| | | ? Math.min(1D, produced.divide(quantity, 4, RoundingMode.HALF_UP).doubleValue()) |
| | | : 0D; |
| | | if (plannedRatio - producedRatio < 0.2D) { |
| | | return null; |
| | | } |
| | | return String.format("工期已过 %d%%,实际完成 %d%%,存在进度偏差,请排查瓶颈工序", |
| | | Math.round(plannedRatio * 100), Math.round(producedRatio * 100)); |
| | | } |
| | | |
| | | } |