| | |
| | | import cn.iocoder.yudao.module.mes.controller.admin.pro.mps.vo.MesProMpsSaveReqVO; |
| | | import cn.iocoder.yudao.module.crm.api.customer.CrmCustomerApi; |
| | | import cn.iocoder.yudao.module.crm.api.customer.dto.CrmCustomerRespDTO; |
| | | import cn.iocoder.yudao.framework.security.core.util.SecurityFrameworkUtils; |
| | | import cn.iocoder.yudao.module.erp.api.sale.ErpSaleOrderApi; |
| | | import cn.iocoder.yudao.module.system.api.permission.PermissionApi; |
| | | 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; |
| | |
| | | private MesMdUnitMeasureService unitMeasureService; |
| | | @Resource |
| | | private CrmCustomerApi customerApi; |
| | | @Resource |
| | | private ErpSaleOrderApi saleOrderApi; |
| | | @Resource |
| | | private PermissionApi permissionApi; |
| | | |
| | | @PostMapping("/create") |
| | | @Operation(summary = "创建生产主计划") |
| | |
| | | convertSet(itemMap.values(), MesMdItemDO::getUnitMeasureId)); |
| | | Map<Long, CrmCustomerRespDTO> clientMap = customerApi.getCustomerMap( |
| | | convertSet(list, MesProMpsDO::getClientId)); |
| | | // 2. 拼接 VO |
| | | // 2. 下发权限:与 MesProMpsServiceImpl#validateIssuePermission 保持一致 |
| | | Long loginUserId = SecurityFrameworkUtils.getLoginUserId(); |
| | | boolean superAdmin = loginUserId != null && permissionApi.hasAnyRoles(loginUserId, "super_admin"); |
| | | Map<Long, MesProMpsDO> mpsMap = list.stream() |
| | | .collect(java.util.stream.Collectors.toMap(MesProMpsDO::getId, mps -> mps)); |
| | | Map<Long, String> saleOrderCreatorMap = new java.util.HashMap<>(); |
| | | // 3. 拼接 VO |
| | | return BeanUtils.toBean(list, MesProMpsRespVO.class, vo -> { |
| | | MapUtils.findAndThen(itemMap, vo.getProductId(), item -> { |
| | | vo.setProductName(item.getName()) |
| | |
| | | }); |
| | | MapUtils.findAndThen(clientMap, vo.getClientId(), |
| | | client -> vo.setClientName(client.getName())); |
| | | MesProMpsDO mps = mpsMap.get(vo.getId()); |
| | | if (mps != null) { |
| | | String creator = mps.getCreator(); |
| | | if (mps.getSaleOrderId() != null) { |
| | | creator = saleOrderCreatorMap.computeIfAbsent(mps.getSaleOrderId(), orderId -> { |
| | | var order = saleOrderApi.getSaleOrder(orderId).getCheckedData(); |
| | | return order != null ? order.getCreator() : null; |
| | | }); |
| | | } |
| | | vo.setCreator(creator); |
| | | vo.setCanIssue(superAdmin || (loginUserId != null && String.valueOf(loginUserId).equals(creator))); |
| | | } |
| | | }); |
| | | } |
| | | |