Explorar el Código

生产排产bug修复

oyq28 hace 1 año
padre
commit
7019e72def

+ 77 - 32
src/main/java/com/imcs/admin/business/service/impl/BusinessServiceImpl.java

@@ -10,6 +10,7 @@ import com.imcs.admin.common.config.SessionContext;
 import com.imcs.admin.db.service.JdbcDao;
 import com.imcs.admin.db.service.JdbcDao;
 import com.imcs.admin.db.service.JdbcService;
 import com.imcs.admin.db.service.JdbcService;
 import com.imcs.admin.util.GenerateSerial;
 import com.imcs.admin.util.GenerateSerial;
+import com.imcs.admin.util.StringUtil;
 import lombok.extern.slf4j.Slf4j;
 import lombok.extern.slf4j.Slf4j;
 import net.jposprinter.Sdk;
 import net.jposprinter.Sdk;
 import org.apache.commons.collections.map.HashedMap;
 import org.apache.commons.collections.map.HashedMap;
@@ -24,6 +25,7 @@ import java.nio.charset.Charset;
 import java.util.*;
 import java.util.*;
 import java.util.regex.Matcher;
 import java.util.regex.Matcher;
 import java.util.regex.Pattern;
 import java.util.regex.Pattern;
+import java.util.stream.Collectors;
 
 
 @Transactional(rollbackFor = Exception.class)
 @Transactional(rollbackFor = Exception.class)
 @Service
 @Service
@@ -68,7 +70,7 @@ public class BusinessServiceImpl implements BusinessService{
         args.add(StrUtil.format("{}",id));
         args.add(StrUtil.format("{}",id));
         PageParam pageParam = new PageParam();
         PageParam pageParam = new PageParam();
         pageParam.put("openPage","NO");
         pageParam.put("openPage","NO");
-        Result<PageData<Map<String, Object>>> detailQuery = jdbcDao.query(new PageParam(), str.toString(), args.toArray());
+        Result<PageData<Map<String, Object>>> detailQuery = jdbcDao.query(pageParam, str.toString(), args.toArray());
         List<Map<String, Object>> items = detailQuery.getData().getItems();
         List<Map<String, Object>> items = detailQuery.getData().getItems();
         items.stream().forEach(vo->{
         items.stream().forEach(vo->{
             String productCode = vo.get("productCode").toString();
             String productCode = vo.get("productCode").toString();
@@ -173,7 +175,7 @@ public class BusinessServiceImpl implements BusinessService{
         String orderName = one.get("orderName").toString();
         String orderName = one.get("orderName").toString();
         String productionOrderCode = one.get("productionOrderCode").toString();
         String productionOrderCode = one.get("productionOrderCode").toString();
 
 
-        StringBuffer selectProcedureStr=new StringBuffer("\tselect pp.*,p.procedure_code,p.procedure_name from a_process_version pv\n" +
+        StringBuffer selectProcedureStr=new StringBuffer("select pv.device_id as version_device_id,pp.*,p.procedure_code,p.procedure_name from a_process_version pv\n" +
                 "\tleft join a_process_procedure pp on pv.id=pp.parent_id\n" +
                 "\tleft join a_process_procedure pp on pv.id=pp.parent_id\n" +
                 "\tleft join a_procedure p on p.id=pp.procedure_id\n" +
                 "\tleft join a_procedure p on p.id=pp.procedure_id\n" +
                 "\t where pv.parent_id = ? and pv.status = 1 order by pp.seq");
                 "\t where pv.parent_id = ? and pv.status = 1 order by pp.seq");
@@ -181,45 +183,88 @@ public class BusinessServiceImpl implements BusinessService{
         args.add(StrUtil.format("{}",productId));
         args.add(StrUtil.format("{}",productId));
         PageParam pageParam = new PageParam();
         PageParam pageParam = new PageParam();
         pageParam.put("openPage","NO");
         pageParam.put("openPage","NO");
-        Result<PageData<Map<String, Object>>> detailQuery = jdbcDao.query(new PageParam(), selectProcedureStr.toString(), args.toArray());
+        Result<PageData<Map<String, Object>>> detailQuery = jdbcDao.query(pageParam, selectProcedureStr.toString(), args.toArray());
         List<Map<String, Object>> items = detailQuery.getData().getItems();
         List<Map<String, Object>> items = detailQuery.getData().getItems();
         if(CollectionUtil.isEmpty(items)){
         if(CollectionUtil.isEmpty(items)){
             throw new RuntimeException("该产品无有效工艺路径");
             throw new RuntimeException("该产品无有效工艺路径");
         }
         }
+        Map<String, Object> stringObjectMap = items.get(0);
+        //工艺版本设备
+        Long versionWorkDeviceId;
+        if(stringObjectMap.containsKey("versionDeviceId") && !Objects.isNull(stringObjectMap.get("versionDeviceId")) && StringUtils.isNotBlank(stringObjectMap.get("versionDeviceId").toString())) {
+            String versionDeviceId = stringObjectMap.get("versionDeviceId").toString();
+
+            StringBuffer versiondDviceStr=new StringBuffer("select count(*) as workCount,work_device_id from a_production_work_order WHERE status in (0,1) and work_device_id IN ("+versionDeviceId+") GROUP BY work_device_id");
+            List<Map<String, Object>> query = query(versiondDviceStr.toString(), new Object[]{});
+            List<Long> versionDeviceIds = Arrays.stream(versionDeviceId.split(","))
+                    .map(Long::valueOf)
+                    .collect(Collectors.toList());
+
+            List<Long> workDeviceIdList = query.stream()
+                    .map(map -> Long.valueOf(map.get("workDeviceId").toString()))
+                    .collect(Collectors.toList());
+            List<Long> difference = new ArrayList<>(versionDeviceIds);
+            difference.removeAll(workDeviceIdList);
+            //如果差值不等于空,说明还有工艺设备没有安排任务,随机一台设备
+            if(CollectionUtil.isNotEmpty(difference)){
+                versionWorkDeviceId=difference.get(0);
+            }else{
+                Optional<Map<String, Object>> minElement = query.stream()
+                        .min(Comparator.comparing(map -> (Integer) map.get("workCount")));
+                versionWorkDeviceId = (Long) minElement.get().get("workDeviceId");
+            }
+
+        } else {
+            versionWorkDeviceId = null;
+        }
+
         StringBuffer insertWork=new StringBuffer("INSERT INTO a_production_work_order (`apply_status`, `create_time`, `order_code`, `order_name`, `plan_amount`, " +
         StringBuffer insertWork=new StringBuffer("INSERT INTO a_production_work_order (`apply_status`, `create_time`, `order_code`, `order_name`, `plan_amount`, " +
                 "`procedure_name`, `process_procedure_id`,`work_device_id`, `seq`, `status`, `work_code`,  `task_type`, `production_order_code`, `work_device`, `sales_order_id`, `production_order_id`, `is_receive`,report_amount,scrap_amount) " +
                 "`procedure_name`, `process_procedure_id`,`work_device_id`, `seq`, `status`, `work_code`,  `task_type`, `production_order_code`, `work_device`, `sales_order_id`, `production_order_id`, `is_receive`,report_amount,scrap_amount) " +
                 "VALUES ( ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)");
                 "VALUES ( ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)");
 
 
-        items.stream().forEach(vo->{
-            String procedureName = vo.get("procedureName").toString();
-            Integer taskType = Integer.valueOf(vo.get("isOutsourcing").toString());
-            if(taskType == 0 && Objects.isNull(vo.get("deviceId"))){
-                throw new RuntimeException(procedureName+"加工工序未绑定设备");
-            }
-
-            Long processProcedureId = Long.valueOf(vo.get("id").toString());
-            Integer seq = Integer.valueOf(vo.get("seq").toString());
-            Long workDeviceId = null;
-            if(!Objects.isNull(vo.get("deviceId")) && StringUtils.isNotBlank(vo.get("deviceId").toString())){
-                String deviceId = vo.get("deviceId").toString();
-                StringBuffer deviceStr=new StringBuffer("select MIN(t.workCount),t.work_device_id from (\n" +
-                        "select count(*) as workCount,work_device_id from a_production_work_order WHERE status in (0,1) and work_device_id IN (?) GROUP BY work_device_id)t order by t.work_device_id limit 1");
-                Map<String, Object> minDevice = jdbcService.findOne(deviceStr.toString(), deviceId);
-                if(minDevice.containsKey("workDeviceId") && !Objects.isNull(minDevice.get("workDeviceId"))){
-                    workDeviceId=Long.valueOf(minDevice.get("workDeviceId").toString());
+        //工序设备
+            items.stream().forEach(vo->{
+                String procedureName = vo.get("procedureName").toString();
+                Integer taskType = Integer.valueOf(vo.get("isOutsourcing").toString());
+                if(taskType == 0 && Objects.isNull(vo.get("deviceId"))){
+                    throw new RuntimeException(procedureName+"加工工序未绑定设备");
+                }
+                Long processProcedureId = Long.valueOf(vo.get("id").toString());
+                Integer seq = Integer.valueOf(vo.get("seq").toString());
+                Long workDeviceId = null;
+                if(!Objects.isNull(vo.get("deviceId")) && StringUtils.isNotBlank(vo.get("deviceId").toString()) && versionWorkDeviceId == null){
+                    String deviceId = vo.get("deviceId").toString();
+                    StringBuffer deviceStr=new StringBuffer("select count(*) as workCount,work_device_id from a_production_work_order WHERE status in (0,1) and work_device_id IN ("+deviceId+") GROUP BY work_device_id");
+                    List<Map<String, Object>> query = query(deviceStr.toString(), new Object[]{});
+                    List<Long> deviceIds = Arrays.stream(deviceId.split(","))
+                            .map(Long::valueOf)
+                            .collect(Collectors.toList());
+
+                    List<Long> deviceIdList = query.stream()
+                            .map(map -> Long.valueOf(map.get("workDeviceId").toString()))
+                            .collect(Collectors.toList());
+                    List<Long> difference = new ArrayList<>(deviceIds);
+                    difference.removeAll(deviceIdList);
+                    //如果差值不等于空,说明还有工艺路径工序设备没有安排任务,随机一台设备
+                    if(CollectionUtil.isNotEmpty(difference)){
+                        workDeviceId=difference.get(0);
+                    }else{
+                        Optional<Map<String, Object>> minElement = query.stream()
+                                .min(Comparator.comparing(map -> (Integer) map.get("workCount")));
+                        workDeviceId =  Long.valueOf(minElement.get().get("workDeviceId").toString());
+                    }
                 }else{
                 }else{
-                    workDeviceId=Long.valueOf(deviceId.split(",")[0]);
+                    workDeviceId=versionWorkDeviceId;
+                }
+                Map<String, Object> deviceMap=new HashMap<>();
+                String deviceName=null;
+                if(workDeviceId != null){
+                    deviceMap = jdbcService.findOne("select * from a_device where id = ? ", workDeviceId);
+                    deviceName = deviceMap.get("deviceName").toString();
                 }
                 }
-            }
-            Map<String, Object> deviceMap=new HashMap<>();
-            String deviceName=null;
-            if(workDeviceId != null){
-                deviceMap = jdbcService.findOne("select * from a_device where id = ? ", workDeviceId);
-                deviceName = deviceMap.get("deviceName").toString();
-            }
 
 
-            jdbcService.insert("执行insert",insertWork.toString(),0,new Date(),orderCode,orderName,planAmount,procedureName,processProcedureId,taskType == 0 ? workDeviceId : null,seq,0,generateSerial.generateSerialNumber("aProductionWorkOrder"),taskType,productionOrderCode,taskType == 0 ? deviceName : null,salesOrderId,productionId,0,0,0);
-        });
+                jdbcService.insert("执行insert",insertWork.toString(),0,new Date(),orderCode,orderName,planAmount,procedureName,processProcedureId,taskType == 0 ? workDeviceId : null,seq,0,generateSerial.generateSerialNumber("aProductionWorkOrder"),taskType,productionOrderCode,taskType == 0 ? deviceName : null,salesOrderId,productionId,0,0,0);
+            });
 
 
         jdbcService.update("update a_production_order set is_plan = 2 where id = ?",id);
         jdbcService.update("update a_production_order set is_plan = 2 where id = ?",id);
     }
     }
@@ -272,7 +317,7 @@ public class BusinessServiceImpl implements BusinessService{
             args.add(StrUtil.format("{}",id));
             args.add(StrUtil.format("{}",id));
             PageParam pageParam = new PageParam();
             PageParam pageParam = new PageParam();
             pageParam.put("openPage","NO");
             pageParam.put("openPage","NO");
-            Result<PageData<Map<String, Object>>> detailQuery = jdbcDao.query(new PageParam(), selectProcedureStr.toString(), args.toArray());
+            Result<PageData<Map<String, Object>>> detailQuery = jdbcDao.query(pageParam, selectProcedureStr.toString(), args.toArray());
             List<Map<String, Object>> items = detailQuery.getData().getItems();
             List<Map<String, Object>> items = detailQuery.getData().getItems();
             StringBuffer insertInOutDetail=new StringBuffer("INSERT INTO a_material_in_out_record_detail ( material_id, material_code, material_name, amount, material_in_out_record_id,seq) \n" +
             StringBuffer insertInOutDetail=new StringBuffer("INSERT INTO a_material_in_out_record_detail ( material_id, material_code, material_name, amount, material_in_out_record_id,seq) \n" +
                     "VALUES (?, ?, ?, ?, ?, ?)");
                     "VALUES (?, ?, ?, ?, ?, ?)");
@@ -447,7 +492,7 @@ public class BusinessServiceImpl implements BusinessService{
         }
         }
         PageParam pageParam = new PageParam();
         PageParam pageParam = new PageParam();
         pageParam.put("openPage","NO");
         pageParam.put("openPage","NO");
-        Result<PageData<Map<String, Object>>> detailQuery = jdbcDao.query(new PageParam(), sql, args.toArray());
+        Result<PageData<Map<String, Object>>> detailQuery = jdbcDao.query(pageParam, sql, args.toArray());
         List<Map<String, Object>> items = detailQuery.getData().getItems();
         List<Map<String, Object>> items = detailQuery.getData().getItems();
         return items;
         return items;
     }
     }

+ 5 - 0
src/main/java/com/imcs/admin/db/service/impl/MysqlJdbcDaoImpl.java

@@ -9,6 +9,7 @@ import com.imcs.admin.common.PageData;
 import com.imcs.admin.common.PageParam;
 import com.imcs.admin.common.PageParam;
 import com.imcs.admin.common.Result;
 import com.imcs.admin.common.Result;
 import com.imcs.admin.db.service.JdbcDao;
 import com.imcs.admin.db.service.JdbcDao;
+import com.imcs.admin.page.constants.Whether;
 import com.imcs.admin.util.RowMapperUtil;
 import com.imcs.admin.util.RowMapperUtil;
 import com.imcs.admin.util.StringUtil;
 import com.imcs.admin.util.StringUtil;
 import lombok.extern.slf4j.Slf4j;
 import lombok.extern.slf4j.Slf4j;
@@ -101,6 +102,10 @@ public class MysqlJdbcDaoImpl implements JdbcDao {
         if(start >= count || start < 0){
         if(start >= count || start < 0){
             start = 0;
             start = 0;
         }
         }
+        if(pageParam.containsKey("openPage") && Whether.NO.equals(pageParam.get("openPage").toString())){
+            pageParam.put("page",1);
+            pageParam.put("perPage",Integer.MAX_VALUE);
+        }
         String pageSql = StrUtil.format("{} limit {},{}",sql,start,pageParam.getPerPage());
         String pageSql = StrUtil.format("{} limit {},{}",sql,start,pageParam.getPerPage());
 
 
         List<Map<String,Object>> data = jdbcTemplate.query(pageSql, RowMapperUtil.newMapMapper(),args);
         List<Map<String,Object>> data = jdbcTemplate.query(pageSql, RowMapperUtil.newMapMapper(),args);

+ 2 - 1
待上线功能.cmd

@@ -1,3 +1,4 @@
 1、技术文档管理
 1、技术文档管理
 2、生产任务功能权限 只能看到自己的任务   涉及 生产任务  (外协任务 质检任务 不包含)
 2、生产任务功能权限 只能看到自己的任务   涉及 生产任务  (外协任务 质检任务 不包含)
-3、设备点检 保养
+3、设备点检 保养
+4、工艺路径版本新增设备