Bladeren bron

bug 修复

wudingsheng 1 jaar geleden
bovenliggende
commit
59d25734d3

+ 20 - 4
src/main/java/com/imcs/admin/business/service/impl/BusinessServiceImpl.java

@@ -194,7 +194,7 @@ public class BusinessServiceImpl implements BusinessService{
         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");
+            StringBuffer versiondDviceStr=new StringBuffer("select ifnull(count(*),0) as work_count,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)
@@ -209,9 +209,25 @@ public class BusinessServiceImpl implements BusinessService{
             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");
+                // 判断所有的workCount是否都相同
+                boolean allWorkCountsSame = query.stream()
+                        .map(map -> Long.valueOf(map.get("workCount").toString())) // 获取所有的workCount
+                        .distinct() // 去重,只保留不同的workCount
+                        .count() <= 1; // 如果去重后只剩下一个元素,说明所有的workCount都相同
+                Optional<Map<String, Object>> minElement=null;
+                if (allWorkCountsSame) {
+                     minElement = query.stream().findFirst();
+                    // 如果查询结果为空,minElement 也会是一个空的 Optional 对象
+                    // 接下来执行你的逻辑,使用 minElement 变量
+                } else {
+                    // 处理所有的workCount不同的情况
+                     minElement = query.stream()
+                            .min(Comparator.comparing(map -> Long.valueOf(map.get("workCount").toString())));
+                }
+
+                Integer intValue = (Integer) minElement.get().get("workDeviceId");
+                versionWorkDeviceId = Long.valueOf(intValue.longValue());
+
             }
 
         } else {

+ 17 - 12
src/main/java/com/imcs/admin/business/service/impl/DevicMaintainServiceImpl.java

@@ -143,8 +143,7 @@ public class DevicMaintainServiceImpl  implements DevicMaintainService {
         } else {
             throw new RuntimeException("文件夹不存在!!!");
         }
-        String folderPath = "D:\\process"; // 文件夹路径
-        List<File> filesToProcess = listFilesToProcess(folderPath);
+        List<File> filesToProcess = listFilesToProcess(filePath);
         if(filesToProcess.size()==0){
             throw new RuntimeException("文件夹下无有效文件!!!");
         }
@@ -152,13 +151,7 @@ public class DevicMaintainServiceImpl  implements DevicMaintainService {
             if (file.isFile() && file.getName().endsWith(".doc") && !file.getName().contains("processed")) {
                 // 处理文件
                 processFile(file);
-                String replace = file.getName().replace(".doc", "_processed.doc");
-                File newFile = new File(file.getParent(), replace);
-                if (file.renameTo(newFile)) {
-                    System.out.println("文件重命名成功!");
-                } else {
-                    System.out.println("文件重命名失败!");
-                }
+
 
 
             }
@@ -264,12 +257,17 @@ public class DevicMaintainServiceImpl  implements DevicMaintainService {
             if(findProduct == null){
                 //产品管理
                 productId = jdbcService.insert("insert", "INSERT INTO a_product (`product_code`, `product_name`, `product_model`, `flat`) VALUES (?,?,?,?);", "xs_"+xsCode, result, productSize, "个");
-                //产品物料
-                jdbcService.insert("insert","INSERT INTO a_product_material (`parent_id`, `material_id`, `material_amount`, `seq`) VALUES (?,?,1,1);",productId,materialId);
+
             }else{
                 productId=Long.valueOf(findProduct.get("id").toString());
             }
 
+            //产品物料
+            Map<String, Object> findProductMaterial = jdbcService.findOne("select * from a_product_material where parent_id=? and material_id =? limit 1", productId,materialId);
+            if(findProductMaterial == null){
+
+                jdbcService.insert("insert","INSERT INTO a_product_material (`parent_id`, `material_id`, `material_amount`, `seq`) VALUES (?,?,1,1);",productId,materialId);
+            }
 
             //工艺路径
             SysFile sysFile = sysFileService.upload(convertToMultipartFile(file));
@@ -325,7 +323,7 @@ public class DevicMaintainServiceImpl  implements DevicMaintainService {
                 }
                 if(y > 0 ){
                     //完工检检
-                    jdbcService.insert("insert",insertProcessProcedure,processVersionId,14,2,null,2,++y);
+                    jdbcService.insert("insert",insertProcessProcedure,processVersionId,14,1,null,2,++y);
                 }
             }
 
@@ -356,6 +354,13 @@ public class DevicMaintainServiceImpl  implements DevicMaintainService {
                 //生产任务下达
                 jdbcService.update("update a_production_work_order set apply_status=1 where production_order_id=?",productionOrderId);
             }
+            String replace = file.getName().replace(".doc", "_已处理.doc");
+            File newFile = new File(file.getParent(), replace);
+            if (file.renameTo(newFile)) {
+                System.out.println("文件重命名成功!");
+            } else {
+                System.out.println("文件重命名失败!");
+            }
             fis.close();
             document.close();
         } catch (IOException e) {