From 1c38849eebe0179b7ebad1db30b3335a41cc47e9 Mon Sep 17 00:00:00 2001 From: zhangherong <571457620@qq.com> Date: 星期六, 16 八月 2025 12:30:22 +0800 Subject: [PATCH] art: WebService服务端相关代码修改 --- src/main/java/org/jeecg/modules/mes/service/impl/MesProductionWorkOrderServiceImpl.java | 200 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 files changed, 200 insertions(+), 0 deletions(-) diff --git a/src/main/java/org/jeecg/modules/mes/service/impl/MesProductionWorkOrderServiceImpl.java b/src/main/java/org/jeecg/modules/mes/service/impl/MesProductionWorkOrderServiceImpl.java index 0bfbfb8..2b407ff 100644 --- a/src/main/java/org/jeecg/modules/mes/service/impl/MesProductionWorkOrderServiceImpl.java +++ b/src/main/java/org/jeecg/modules/mes/service/impl/MesProductionWorkOrderServiceImpl.java @@ -1,10 +1,48 @@ package org.jeecg.modules.mes.service.impl; +import cn.hutool.core.collection.CollectionUtil; +import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; +import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; +import com.baomidou.mybatisplus.core.metadata.IPage; +import com.baomidou.mybatisplus.core.toolkit.Wrappers; +import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; +import org.jeecg.common.constant.CommonConstant; +import org.jeecg.common.exception.JeecgBootException; +import org.jeecg.modules.base.entity.Factory; +import org.jeecg.modules.base.entity.LineSideWarehouse; +import org.jeecg.modules.base.entity.Shift; +import org.jeecg.modules.base.entity.ShiftGroup; +import org.jeecg.modules.base.service.IFactoryService; +import org.jeecg.modules.base.service.ILineSideWarehouseService; +import org.jeecg.modules.base.service.IShiftGroupService; +import org.jeecg.modules.base.service.IShiftService; +import org.jeecg.modules.lsw.entity.LswMaterialInventory; +import org.jeecg.modules.lsw.service.ILswMaterialInventoryService; +import org.jeecg.modules.lsw.vo.LswMaterialInventoryVo; +import org.jeecg.modules.mes.dto.MesProductionWorkScheduleRequest; +import org.jeecg.modules.mes.entity.MesKittingCompletenessCheck; +import org.jeecg.modules.mes.entity.MesProductionOrder; +import org.jeecg.modules.mes.enums.ProductionOrderStatus; +import org.jeecg.modules.mes.service.IMesProductionOrderService; import org.jeecg.modules.mes.service.IMesProductionWorkOrderService; import org.jeecg.modules.mes.entity.MesProductionWorkOrder; import org.jeecg.modules.mes.mapper.MesProductionWorkOrderMapper; +import org.jeecg.modules.pms.entity.PmsProcessBillMaterials; +import org.jeecg.modules.pms.entity.PmsProcessBillMaterialsDetail; +import org.jeecg.modules.pms.service.IPmsProcessBillMaterialsDetailService; +import org.jeecg.modules.pms.service.IPmsProcessBillMaterialsService; +import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; + +import java.math.BigDecimal; +import java.math.RoundingMode; +import java.time.LocalDate; +import java.time.ZoneId; +import java.time.temporal.ChronoUnit; +import java.util.*; +import java.util.stream.Collectors; +import java.util.stream.Stream; /** * @Description: 鎺掍骇宸ュ崟 @@ -14,5 +52,167 @@ */ @Service public class MesProductionWorkOrderServiceImpl extends ServiceImpl<MesProductionWorkOrderMapper, MesProductionWorkOrder> implements IMesProductionWorkOrderService { + @Autowired + private IShiftService shiftService; + @Autowired + private IShiftGroupService shiftGroupService; + @Autowired + private IFactoryService factoryService; + @Autowired + private IMesProductionOrderService mesProductionOrderService; + @Autowired + private IPmsProcessBillMaterialsService pmsProcessBillMaterialsService; + @Autowired + private IPmsProcessBillMaterialsDetailService pmsProcessBillMaterialsDetailService; + @Autowired + private ILswMaterialInventoryService lswMaterialInventoryService; + @Autowired + private ILineSideWarehouseService lineSideWarehouseService; + @Override + public List<MesProductionWorkOrder> schedule(MesProductionWorkScheduleRequest request) { + //鏌ヨ璧锋鏃ユ湡鑼冨洿鍐呯殑鎺掍骇璁″垝锛屽厛鎺掗櫎 + //鏌ヨ璇ヤ骇绾夸笅鎵�鏈夌殑鐝 + Map<String, ShiftGroup> shiftGroupMap = shiftGroupService.list(new LambdaQueryWrapper<ShiftGroup>() + .eq(ShiftGroup::getFactoryId, request.getFactoryId()) + .eq(ShiftGroup::getDelFlag, CommonConstant.DEL_FLAG_0)) + .stream().collect(Collectors.toMap(ShiftGroup::getShiftId, v1 -> v1, (v1, v2) -> v1)); + Factory factory = factoryService.getById(request.getFactoryId()); + Map<String, Shift> shiftNameMap = new HashMap<>(); + List<Shift> shifts = shiftService.list(new LambdaQueryWrapper<Shift>() + .in(Shift::getId, shiftGroupMap.keySet())); + shifts.forEach(shift -> shiftNameMap.put(shift.getId(), shift)); + + LocalDate startDate = request.getStartDate().toInstant().atZone(ZoneId.systemDefault()).toLocalDate(); + LocalDate endDate = request.getEndDate().toInstant().atZone(ZoneId.systemDefault()).toLocalDate(); + // 浣跨敤鏃ユ湡鑼冨洿杩涜閬嶅巻澶勭悊 + List<LocalDate> dateRange = Stream.iterate(startDate, date -> date.plusDays(1)) + .limit(ChronoUnit.DAYS.between(startDate, endDate) + 1) + .collect(Collectors.toList()); + List<MesProductionWorkOrder> newProductionWorkOrderList = CollectionUtil.newArrayList(); + + for (LocalDate date : dateRange) { + for (String shiftId : shiftGroupMap.keySet()) { + Date workOrderDate = Date.from(date.atStartOfDay(ZoneId.systemDefault()).toInstant()); + //鏌ヨ璇ヤ骇绾裤�佺彮娆″湪璇ユ棩鏈熶笅鏄惁鏈夋帓浜ц鍒� + Optional<MesProductionWorkOrder> optional = list(new LambdaQueryWrapper<MesProductionWorkOrder>() + .eq(MesProductionWorkOrder::getWorkOrderDate, workOrderDate) + .eq(MesProductionWorkOrder::getFactoryId, request.getFactoryId()) + .eq(MesProductionWorkOrder::getShiftId, shiftId)) + .stream().findAny(); + if (!optional.isPresent()) { + ShiftGroup shiftGroup = shiftGroupMap.get(shiftId); + //娌℃湁锛岀敓鎴愭柊鎺掍骇璁″垝 + MesProductionWorkOrder mesProductionWorkOrder = new MesProductionWorkOrder() + .setFactoryId(factory.getId()) + .setFactoryCode(factory.getFactoryCode()) + .setFactoryName(factory.getFactoryName()) + .setShiftId(shiftId) + .setShiftCode(shiftNameMap.get(shiftId).getShiftCode()) + .setShiftName(shiftNameMap.get(shiftId).getShiftName()) + .setGroupId(shiftGroup.getId()) + .setGroupName(shiftGroup.getGroupName()) + .setWorkOrderDate(workOrderDate); + + newProductionWorkOrderList.add(mesProductionWorkOrder); + } + } + } + //濡傛灉涓虹┖锛岄粯璁ょ粰涓�鏉★紝鐢ㄤ簬鎵嬪姩鏂板鏃惰〃鏍肩殑鍒濆鍖� + if (newProductionWorkOrderList.isEmpty()) { + MesProductionWorkOrder mesProductionWorkOrder = new MesProductionWorkOrder() + .setFactoryId(factory.getId()) + .setFactoryCode(factory.getFactoryCode()) + .setFactoryName(factory.getFactoryName()); + newProductionWorkOrderList.add(mesProductionWorkOrder); + } + return newProductionWorkOrderList; + } + + @Override + public IPage<MesProductionWorkOrder> queryPageList(Page<MesProductionWorkOrder> page, Map<String, String[]> parameterMap) { + QueryWrapper<MesProductionWorkOrder> queryWrapper = Wrappers.query(); + String[] factoryIds = parameterMap.get("factoryId"); + if (factoryIds != null && factoryIds.length > 0) { + queryWrapper.eq("t1.factory_id", factoryIds[0]); + } + String[] startDates = parameterMap.get("startDate"); + String[] endDates = parameterMap.get("endDate"); + if (startDates != null && startDates.length > 0) { + queryWrapper.ge("t1.work_order_date", startDates[0]); + } + if (endDates != null && endDates.length > 0) { + queryWrapper.le("t1.work_order_date", endDates[0]); + } + String[] workOrderStatuses = parameterMap.get("workOrderStatus"); + if (workOrderStatuses != null && workOrderStatuses.length > 0) { + queryWrapper.eq("t1.work_order_status", workOrderStatuses[0]); + } + queryWrapper.eq("t1.del_flag", CommonConstant.DEL_FLAG_0); + queryWrapper.orderByAsc("t1.work_order_date"); + return this.baseMapper.queryPageList(page, queryWrapper); + } + + @Override + public List<MesKittingCompletenessCheck> workOrderCompletenessCheck(MesProductionWorkOrder workOrder) { + //鏍规嵁褰撳墠鎺掍骇宸ュ崟纭畾鐢熶骇璁㈠崟 + List<MesProductionOrder> orderList = mesProductionOrderService.list(new LambdaQueryWrapper<MesProductionOrder>() + .eq(MesProductionOrder::getMaterialNumber, workOrder.getMaterialNumber()) + .eq(MesProductionOrder::getOrderStatus, ProductionOrderStatus.REL.name()) + .eq(MesProductionOrder::getDelFlag, CommonConstant.DEL_FLAG_0) + .orderByAsc(MesProductionOrder::getPlanStart)); + if (orderList.isEmpty()) { + throw new JeecgBootException("鏈壘鍒拌鐗╂枡鐨勫叧鑱旂敓浜ц鍗曪紒"); + } + //榛樿鍙栨椂闂存渶鏃╂湭瀹屾垚鐨勮鍗曪紝涔熷氨鏄涓�椤� + MesProductionOrder order = orderList.get(0); + //鏍规嵁鐢熶骇璁㈠崟id鍜岀墿鏂欑紪鐮佹煡璇㈣鍗旴OM + PmsProcessBillMaterials processBillMaterials = pmsProcessBillMaterialsService.list(new LambdaQueryWrapper<PmsProcessBillMaterials>() + .eq(PmsProcessBillMaterials::getOrderId, order.getId()) + .eq(PmsProcessBillMaterials::getMaterialNumber, workOrder.getMaterialNumber())) + .stream().findFirst().orElse(null); + if (processBillMaterials == null) { + throw new JeecgBootException("鏈壘鍒颁笌璇ョ墿鏂欏叧鑱旂殑璁㈠崟BOM锛�"); + } + //鏌ヨ宸ュ崟鎵�灞炰骇绾垮搴旂殑绾胯竟浠� + LineSideWarehouse lineSideWarehouse = lineSideWarehouseService.list(new LambdaQueryWrapper<LineSideWarehouse>() + .eq(LineSideWarehouse::getFactoryId, workOrder.getFactoryId()) + .eq(LineSideWarehouse::getDelFlag, CommonConstant.DEL_FLAG_0) + .eq(LineSideWarehouse::getWarehouseStatus, CommonConstant.DEFAULT_1)) + .stream().findFirst().orElse(null); + if (lineSideWarehouse == null) { + throw new JeecgBootException("璇ヤ骇绾挎湭閰嶇疆绾胯竟浠擄紒"); + } + //璁㈠崟BOM鏄庣粏 + List<PmsProcessBillMaterialsDetail> processBillMaterialsDetails = pmsProcessBillMaterialsDetailService.queryByMaterialId(processBillMaterials.getId()); + //鏌ヨ璁㈠崟BOM鏄庣粏涓殑鐗╂枡鍦ㄨ浜х嚎绾胯竟浠撲腑鐨勫簱瀛� + List<String> bomMaterialNumberList = processBillMaterialsDetails.stream() + .map(PmsProcessBillMaterialsDetail::getMaterialNumber).collect(Collectors.toList()); + Map<String, LswMaterialInventoryVo> lswMaterialInventoryMap = lswMaterialInventoryService + .selectLineSideMaterialInventoryByMaterialNumber(bomMaterialNumberList, lineSideWarehouse.getId()).stream() + .collect(Collectors.toMap(LswMaterialInventoryVo::getMaterialNumber, v1 -> v1, (v1, v2) -> v1)); + List<MesKittingCompletenessCheck> completenessCheckResultList = CollectionUtil.newArrayList(); + //鏍规嵁璁㈠崟BOM鏄庣粏鍒楀嚭榻愬妫�鏌ョ粨鏋� + for (PmsProcessBillMaterialsDetail processBillMaterialsDetail : processBillMaterialsDetails) { + LswMaterialInventoryVo materialInventoryVo = lswMaterialInventoryMap.get(processBillMaterialsDetail.getMaterialNumber()); + MesKittingCompletenessCheck completenessCheckItem = new MesKittingCompletenessCheck() + .setMaterialNumber(processBillMaterialsDetail.getMaterialNumber()) + .setMaterialName(processBillMaterialsDetail.getMaterialName()) + //闇�姹傛暟閲� = (bom鏄庣粏鐨勯渶姹傛暟閲� / bom璁㈠崟鐨勬暟閲�) * 鎺掍骇宸ュ崟璁″垝鐢熶骇鏁伴噺 + .setRequiredQuantity(processBillMaterialsDetail.getUsageQuantity() + .divide(processBillMaterials.getProductionQuantity(), 2, RoundingMode.HALF_UP) + .multiply(workOrder.getPlanQuantity())) + .setActualQuantity(materialInventoryVo == null ? BigDecimal.ZERO : materialInventoryVo.getStockQuantity()) + .setProductionUnit(processBillMaterialsDetail.getProductionUnit()); + completenessCheckResultList.add(completenessCheckItem); + } + completenessCheckResultList.forEach(item -> { + if (item.getRequiredQuantity().compareTo(item.getActualQuantity()) > 0) { + item.setCheckFlag(CommonConstant.DEFAULT_0); + } else { + item.setCheckFlag(CommonConstant.DEFAULT_1); + } + }); + return completenessCheckResultList; + } } -- Gitblit v1.9.3