yzc 10 kuukautta sitten
vanhempi
commit
db0be7db7f

+ 3 - 3
hx-mes/src/main/java/com/fjhx/mes/controller/production/ProductionSchedulingController.java

@@ -1,8 +1,8 @@
 package com.fjhx.mes.controller.production;
 
 import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
+import com.fjhx.mes.entity.production.dto.ProductionSchedulingDto;
 import com.fjhx.mes.entity.production.dto.ProductionSchedulingSelectDto;
-import com.fjhx.mes.entity.production.po.ProductionScheduling;
 import com.fjhx.mes.entity.production.vo.ProductionOrderDetailVo;
 import com.fjhx.mes.entity.production.vo.ProductionSchedulingVo;
 import com.fjhx.mes.service.production.ProductionSchedulingService;
@@ -51,8 +51,8 @@ public class ProductionSchedulingController {
      */
     @Log(title = "生产排程", businessType = BusinessType.INSERT)
     @PostMapping("/add")
-    public void add(@RequestBody List<ProductionScheduling> dtoList) {
-        productionSchedulingService.add(dtoList);
+    public void add(@RequestBody ProductionSchedulingDto dto) {
+        productionSchedulingService.add(dto);
     }
 
     /**

+ 5 - 0
hx-mes/src/main/java/com/fjhx/mes/entity/production/dto/ProductionSchedulingSelectDto.java

@@ -57,5 +57,10 @@ public class ProductionSchedulingSelectDto extends BaseSelectDto {
      */
     private Date endDeliveryPeriod;
 
+    /**
+     * 任务id
+     */
+    private Long taskId;
+
 
 }

+ 6 - 0
hx-mes/src/main/java/com/fjhx/mes/entity/production/vo/ProductionOrderDetailVo.java

@@ -8,6 +8,7 @@ import lombok.Setter;
 import java.math.BigDecimal;
 import java.util.Date;
 import java.util.List;
+import java.util.Map;
 
 /**
  * 生产订单明细列表查询返回值实体
@@ -209,4 +210,9 @@ public class ProductionOrderDetailVo extends ProductionOrderDetail {
      * 欠料状态
      */
     private Integer lackStatus;
+
+    /**
+     * 排程信息
+     */
+    private Map<String, ProductionSchedulingVo> schedulingInfo;
 }

+ 5 - 0
hx-mes/src/main/java/com/fjhx/mes/entity/production/vo/ProductionSchedulingVo.java

@@ -69,4 +69,9 @@ public class ProductionSchedulingVo extends ProductionScheduling {
      */
     private BigDecimal sumQuantity;
 
+    /**
+     * 排程报工数
+     */
+    private Integer reportingQuantity;
+
 }

+ 3 - 0
hx-mes/src/main/java/com/fjhx/mes/mapper/production/ProductionSchedulingMapper.java

@@ -25,6 +25,9 @@ public interface ProductionSchedulingMapper extends BaseMapper<ProductionSchedul
      */
     Page<ProductionSchedulingVo> getPage(@Param("page") Page<Object> page, @Param("ew") IWrapper<ProductionScheduling> wrapper);
 
+    List<ProductionSchedulingVo> getList(@Param("ew") IWrapper wrapper);
+
+
     /**
      * 排程合并数量
      */

+ 4 - 1
hx-mes/src/main/java/com/fjhx/mes/service/production/ProductionSchedulingService.java

@@ -6,6 +6,7 @@ import com.fjhx.mes.entity.production.po.ProductionScheduling;
 import com.fjhx.mes.entity.production.vo.ProductionOrderDetailVo;
 import com.fjhx.mes.entity.production.vo.ProductionSchedulingVo;
 import com.ruoyi.common.core.service.BaseService;
+import com.ruoyi.common.utils.wrapper.IWrapper;
 
 import java.util.List;
 import java.util.Map;
@@ -22,12 +23,14 @@ public interface ProductionSchedulingService extends BaseService<ProductionSched
 
     Page<ProductionSchedulingVo> getPage(ProductionSchedulingSelectDto dto);
 
+    List<ProductionSchedulingVo> getList(IWrapper wrapper);
+
     Map<String, List<ProductionSchedulingVo>> listMap(ProductionSchedulingSelectDto dto);
 
     /**
      * 生产排程新增
      */
-    void add(List<ProductionScheduling> dtoList);
+    void add(ProductionScheduling dto);
 
     /**
      * 生产排程删除

+ 31 - 5
hx-mes/src/main/java/com/fjhx/mes/service/production/impl/ProduceOrderDetailServiceImpl.java

@@ -102,16 +102,42 @@ public class ProduceOrderDetailServiceImpl extends ServiceImpl<ProduceOrderDetai
     public Page<ProductionOrderDetailVo> schedulingTaskPage(ProduceOrderDetailSelectDto dto) {
         IWrapper<ProductionOrderDetail> wrapper = getPageCommWrapper(dto);
 
-        //开工确认单提交后才能排程
-        wrapper.eq("pod.begin_work_status", 1);
+//        //开工确认单提交后才能排程
+//        wrapper.eq("pod.begin_work_status", 1);
 
-        //显示当前工序,未排程完的任务
+        //任务Id过滤
+        wrapper.eq("pod.id", dto.getId());
+        //显示当前工序,
         wrapper.eq("ptp.processes_id", dto.getProcessesId());
+
+        //未生产完成
+        wrapper.in("pod.produce_status", 0, 1);
+
         wrapper.groupBy("pod.id");
-        wrapper.having("IFNULL(SUM( ps.quantity ),0)<pod.quantity");
+
+        //未排程完的任务
+//        wrapper.having("IFNULL(SUM( ps.quantity ),0)<pod.quantity");
 
         Page<ProductionOrderDetailVo> page = this.baseMapper.schedulingTaskPage(dto.getPage(), wrapper);
 
+        List<ProductionOrderDetailVo> records = page.getRecords();
+        if (ObjectUtil.isEmpty(records)) {
+            return page;
+        }
+
+        //获取排程信息
+        List<Long> taskIds = records.stream().map(ProductionOrderDetailVo::getId).collect(Collectors.toList());
+        List<ProductionSchedulingVo> schedulingLists = productionSchedulingService.getList(IWrapper.getWrapper().in("ps", ProductionScheduling::getTaskId, taskIds)
+                .eq("ps", ProductionScheduling::getProcessesId, dto.getProcessesId()));
+        Map<Long, List<ProductionSchedulingVo>> schedulingMap = schedulingLists.stream().collect(Collectors.groupingBy(ProductionScheduling::getTaskId));
+        for (ProductionOrderDetailVo record : records) {
+            //赋值排程信息
+            List<ProductionSchedulingVo> schedulingList = schedulingMap.getOrDefault(record.getId(), new ArrayList<>());
+            Map<String, ProductionSchedulingVo> collect = schedulingList.stream().collect(Collectors
+                    .toMap(item -> DateUtil.format(item.getSchedulingDate(), "yyyy-MM-dd"), Function.identity()));
+            record.setSchedulingInfo(collect);
+        }
+
         return commPage(page);
     }
 
@@ -121,7 +147,6 @@ public class ProduceOrderDetailServiceImpl extends ServiceImpl<ProduceOrderDetai
         //只显示投产的数据
         wrapper.isNotNull("po.produce_time");
 
-
         //生产状态
         String produceStatus = dto.getProduceStatus();
         if (ObjectUtil.isNotEmpty(produceStatus)) {
@@ -145,6 +170,7 @@ public class ProduceOrderDetailServiceImpl extends ServiceImpl<ProduceOrderDetai
                     .like("po.code", dto.getKeyword())
                     .or().in("c.create_user", uIds)
                     .or().in("c.buy_corporation_id", cuIds)
+                    .or().like("pod.code", dto.getKeyword())
             );
         }
 

+ 46 - 22
hx-mes/src/main/java/com/fjhx/mes/service/production/impl/ProductionSchedulingServiceImpl.java

@@ -2,6 +2,7 @@ package com.fjhx.mes.service.production.impl;
 
 import cn.hutool.core.date.DateUtil;
 import cn.hutool.core.util.ObjectUtil;
+import cn.hutool.core.util.StrUtil;
 import com.baomidou.dynamic.datasource.annotation.DSTransactional;
 import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
@@ -109,13 +110,18 @@ public class ProductionSchedulingServiceImpl extends ServiceImpl<ProductionSched
         wrapper.isNotNull("po.produce_time");
         //工序id过滤
         wrapper.eq(ProductionScheduling::getProcessesId, dto.getProcessesId());
+        //任务Id过滤
+        wrapper.eq(ProductionScheduling::getTaskId, dto.getTaskId());
 
         //权限过滤:生产排程-1
         wrapper.in("po", ProductionOrder::getCompanyId, SecurityUtils.getCompanyIds());
         wrapper.eq("po", ProductionOrder::getCompanyId, dto.getCompanyId());
 
-        //排程日期过滤
-        wrapper.eq("ps", ProductionScheduling::getSchedulingDate, DateUtil.format(dto.getSchedulingDate(), "yyyy-MM-dd"));
+//        //排程日期过滤
+//        wrapper.eq("ps", ProductionScheduling::getSchedulingDate, DateUtil.format(dto.getSchedulingDate(), "yyyy-MM-dd"));
+        //排程时间范围过滤
+        wrapper.ge("ps", ProductionScheduling::getSchedulingDate, dto.getBeginTime());
+        wrapper.le("ps", ProductionScheduling::getSchedulingDate, dto.getEndTime());
 
         wrapper.orderByDesc("ps.scheduling_date");
 
@@ -137,6 +143,11 @@ public class ProductionSchedulingServiceImpl extends ServiceImpl<ProductionSched
     }
 
     @Override
+    public List<ProductionSchedulingVo> getList(IWrapper wrapper) {
+        return baseMapper.getList(wrapper);
+    }
+
+    @Override
     public Map<String, List<ProductionSchedulingVo>> listMap(ProductionSchedulingSelectDto dto) {
         IWrapper<ProductionScheduling> wrapper = getWrapper();
         //权限过滤:生产排程统计
@@ -156,24 +167,41 @@ public class ProductionSchedulingServiceImpl extends ServiceImpl<ProductionSched
 
     @DSTransactional
     @Override
-    public synchronized void add(List<ProductionScheduling> dtoList) {
-        for (ProductionScheduling dto : dtoList) {
-            dto.setCompanyId(SecurityUtils.getCompanyId());
-
-            //检查是否重复排程
-            long count = this.count(q -> q
-                    .eq(ProductionScheduling::getTaskId, dto.getTaskId())
-                    .eq(ProductionScheduling::getProcessesId, dto.getProcessesId())
-                    .eq(ProductionScheduling::getSchedulingDate, dto.getSchedulingDate())
-            );
-            if (count > 0) {
-                throw new ServiceException(DateUtil.format(dto.getSchedulingDate(), "yyyy-MM-dd") + "已有排程信息,请前往删除重新排程!");
-            }
-            this.save(dto);
+    public synchronized void add(ProductionScheduling dto) {
+        Assert.notEmpty(dto.getTaskId(), "任务id不能为空");
+        Assert.notEmpty(dto.getProcessesId(), "工序id不能为空");
+        Assert.notEmpty(dto.getSchedulingDate(), "排程日期不能为空");
+        Assert.notEmpty(dto.getQuantity(), "排程数量不能为空");
+
+
+        dto.setCompanyId(SecurityUtils.getCompanyId());
 
-            //如果是第一道工序 创建生产领料待出库
-            createProdStockWait(dto);
+        ProductionScheduling oldData = this.getOne(q -> q
+                .eq(ProductionScheduling::getTaskId, dto.getTaskId())
+                .eq(ProductionScheduling::getProcessesId, dto.getProcessesId())
+                .eq(ProductionScheduling::getSchedulingDate, dto.getSchedulingDate())
+        );
+        if (ObjectUtil.isNotEmpty(oldData)) {
+            dto.setId(oldData.getId());
+        }
+        //排程为0直接删除
+        if (ObjectUtil.isNotEmpty(dto.getId()) && dto.getQuantity() == 0) {
+            delete(dto.getId());
+            return;
         }
+        this.saveOrUpdate(dto);
+
+        //排程数校验
+        ProductionOrderDetail taskById = produceOrderDetailService.getById(dto.getTaskId());
+        Assert.notEmpty(taskById, "查询不到排程信息");
+        List<ProductionScheduling> psList = this.list(q -> q.eq(ProductionScheduling::getTaskId, dto.getTaskId()).eq(ProductionScheduling::getProcessesId, dto.getProcessesId()));
+        BigDecimal reduce = BigDecimal.valueOf(psList.stream().map(ProductionScheduling::getQuantity).reduce(Integer::sum).orElse(0));
+        if (reduce.compareTo(taskById.getQuantity()) > 0) {
+            throw new ServiceException(StrUtil.format("排程总数量不能大于订单数量,排程总数量:{},订单数量:{}!", reduce, taskById.getQuantity()));
+        }
+
+        //如果是第一道工序 创建生产领料待出库
+        createProdStockWait(dto);
     }
 
     @DSTransactional
@@ -212,9 +240,6 @@ public class ProductionSchedulingServiceImpl extends ServiceImpl<ProductionSched
             item.setProductHeight(productInfo.getHeight());
             item.setProductColor(productInfo.getColor());
         });
-
-        //赋值任务信息
-
         return voList;
     }
 
@@ -231,7 +256,6 @@ public class ProductionSchedulingServiceImpl extends ServiceImpl<ProductionSched
     /**
      * 根据排程创建生产待出库
      */
-    @DSTransactional
     private synchronized void createProdStockWait(ProductionScheduling dto) {
         ProductionOrderDetail task = produceOrderDetailService.getById(dto.getTaskId());
         Assert.notEmpty(task, "查询不到任务信息!");

+ 19 - 0
hx-mes/src/main/resources/mapper/production/ProductionSchedulingMapper.xml

@@ -24,6 +24,25 @@
                  LEFT JOIN contract c ON po.contract_id = c.id
             ${ew.customSqlSegment}
     </select>
+    <select id="getList" resultType="com.fjhx.mes.entity.production.vo.ProductionSchedulingVo">
+        SELECT ps.*,
+               IFNULL(pr1.sum_quantity, 0) AS reporting_quantity
+        FROM production_scheduling ps
+                 LEFT JOIN (SELECT pr.production_task_id      AS task_id,
+                                   pr.production_processes_id AS processes_id,
+                                   sum(quantity)                 sum_quantity, date ( create_time) AS reporting_date FROM
+		production_reporting pr
+        GROUP BY
+            pr.production_task_id,
+            pr.production_processes_id,
+            reporting_date
+            ) pr1
+        ON pr1.task_id = ps.task_id
+            AND pr1.processes_id = ps.processes_id
+            AND pr1.reporting_date = date (
+            ps.scheduling_date)
+            ${ew.customSqlSegment}
+    </select>
 
     <select id="listSumQuantity" resultType="com.fjhx.mes.entity.production.vo.ProductionSchedulingVo">
         SELECT ps.scheduling_date,