Kaynağa Gözat

工艺路径批量导入

oyq28 1 yıl önce
ebeveyn
işleme
34854ab452

+ 19 - 0
pom.xml

@@ -216,6 +216,25 @@
             <systemPath>${basedir}/bin/JposPrinterSDK.jar</systemPath>
         </dependency>
 
+        <dependency>
+            <groupId>org.apache.poi</groupId>
+            <artifactId>poi</artifactId>
+            <version>5.2.3</version>
+        </dependency>
+
+        <!-- Apache POI HWPF (for handling .doc files) -->
+        <dependency>
+            <groupId>org.apache.poi</groupId>
+            <artifactId>poi-scratchpad</artifactId>
+            <version>5.2.3</version>
+        </dependency>
+
+        <dependency>
+            <groupId>com.hankcs</groupId>
+            <artifactId>hanlp</artifactId>
+            <version>portable-1.8.1</version> <!-- 可以根据需要调整版本号 -->
+        </dependency>
+
     </dependencies>
 
     <build>

+ 20 - 6
src/main/java/com/imcs/admin/business/controller/BusinessController.java

@@ -12,6 +12,7 @@ import org.springframework.transaction.annotation.Transactional;
 import org.springframework.web.bind.annotation.*;
 
 import javax.annotation.Resource;
+import java.util.List;
 import java.util.Map;
 
 @RestController
@@ -49,6 +50,14 @@ public class BusinessController {
         }
         return Result.success();
     }
+    @PostMapping("/sales/applyStatus/ids")
+    public Result applyStatusBatch(@RequestBody Map<String,Object> map){
+        String[] ids = map.get("ids").toString().split(",");
+        for (String item:ids){
+            businessService.salesProductionOrder(Long.valueOf(item));
+        }
+        return Result.success();
+    }
 
     /**
      * 生产令拆批
@@ -270,17 +279,20 @@ public class BusinessController {
      * @param id
      * @return
      */
-    @GetMapping("/productIn/{id}")
-    public Result productIn(@PathVariable("id") Long id){
-        businessService.productIn(id);
+    @GetMapping("/productIn/{id}/{lastReportAmount}/{scrapAmount}")
+    public Result productIn(@PathVariable("id") Long id,@PathVariable("lastReportAmount") Long lastReportAmount,@PathVariable("scrapAmount") Long scrapAmount){
+        businessService.productIn(id,lastReportAmount,scrapAmount);
         return Result.success();
     }
 
     @PostMapping("/productIn/ids")
     public Result productInBatch(@RequestBody Map<String,Object> map){
-        String[] ids = map.get("ids").toString().split(",");
-        for (String item:ids){
-                businessService.productIn(Long.valueOf(item));
+        List<Map<String,Object>> list=(List<Map<String,Object>>)map.get("rows");
+        for (Map<String,Object> item:list){
+            String id = item.get("id").toString();
+            String scrapAmount = item.get("scrapAmount").toString();
+            String lastReportAmount = item.get("lastReportAmount").toString();
+            businessService.productIn(Long.valueOf(id),Long.valueOf(lastReportAmount),Long.valueOf(scrapAmount));
 
         }
         return Result.success();
@@ -328,4 +340,6 @@ public class BusinessController {
     }
 
 
+
+
 }

+ 8 - 4
src/main/java/com/imcs/admin/business/controller/DevicMaintainController.java

@@ -7,12 +7,10 @@ import com.imcs.admin.common.Result;
 import com.imcs.admin.dto.DeviceMaintainDto;
 import lombok.extern.slf4j.Slf4j;
 import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.web.bind.annotation.PostMapping;
-import org.springframework.web.bind.annotation.RequestBody;
-import org.springframework.web.bind.annotation.RequestMapping;
-import org.springframework.web.bind.annotation.RestController;
+import org.springframework.web.bind.annotation.*;
 
 import javax.annotation.Resource;
+import java.util.Map;
 
 @Slf4j
 @RestController
@@ -50,4 +48,10 @@ public class DevicMaintainController {
         return Result.success(aBoolean);
     }
 
+    @PostMapping("/processUpload")
+    public Result processUpload(@RequestBody Map<String,Object> map){
+        devicMaintainService.processUpload(map);
+        return Result.success();
+    }
+
 }

+ 1 - 1
src/main/java/com/imcs/admin/business/service/BusinessService.java

@@ -26,7 +26,7 @@ public interface BusinessService {
 
     void inOut(Long id);
 
-    void productIn(Long id);
+    void productIn(Long id,Long lastReportAmount,Long scrapAmount);
 
     void scrapAmount(Long id, Map<String, Object> map);
 

+ 3 - 0
src/main/java/com/imcs/admin/business/service/DevicMaintainService.java

@@ -5,9 +5,12 @@ import com.imcs.admin.dto.DeviceMaintainDto;
 import org.springframework.web.bind.annotation.PostMapping;
 import org.springframework.web.bind.annotation.RequestBody;
 
+import java.util.Map;
+
 public interface DevicMaintainService {
 
     public Boolean addDeviceMaintainTask(DeviceMaintainDto deviceMaintainDto);
     public Boolean saveDeviceMaintainTask(DeviceMaintainDto deviceMaintainDto);
 
+    void processUpload(Map<String,Object> map);
 }

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

@@ -226,9 +226,9 @@ public class BusinessServiceImpl implements BusinessService{
             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"))){
+                /*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;
@@ -409,7 +409,7 @@ public class BusinessServiceImpl implements BusinessService{
             Long materialId=Long.valueOf(item.get("materialId").toString());
             Integer amount=Integer.valueOf(item.get("amount").toString());
             String materialName = item.get("materialName").toString();
-            int update = jdbcService.update("update a_material_store set store_amount=store_amount - ? where parent_id = ?", amount, materialId);
+            int update = jdbcService.update("update a_material_store set store_amount=store_amount - ? where parent_id = ? and store_amount - ? > 0", amount, materialId,amount);
             if(update <= 0){
                 throw new RuntimeException(materialName+"物料不足");
             }
@@ -417,7 +417,7 @@ public class BusinessServiceImpl implements BusinessService{
     }
 
     @Override
-    public void productIn(Long id) {
+    public void productIn(Long id,Long lastReportAmount,Long scrapAmount) {
         Map<String, Object> one = jdbcService.findOne("select * from a_production_work_order where production_order_code = (select production_order_code from a_production_work_order where id= ?) order by seq desc limit 1", id);
         Long endId = Long.valueOf(one.get("id").toString());
         Long productionOrderId = Long.valueOf(one.get("productionOrderId").toString());
@@ -431,6 +431,10 @@ public class BusinessServiceImpl implements BusinessService{
             throw new RuntimeException("还有"+count +"条不良品记录未处理");
         }
 
+        //如果全部 报废,则关闭所有任务
+        if(lastReportAmount.equals(scrapAmount)){
+            jdbcService.update("update a_production_work_order set status=2,is_receive=2,real_end_date = now() where production_order_id=?",productionOrderId);
+        }
         //最后一道工序入库
         if(id.equals(endId)){
             Map<String, Object> flag = jdbcService.findOne("select * from a_product_store where parent_id = (select product_id from a_production_order where id = ?)", productionOrderId);

+ 237 - 5
src/main/java/com/imcs/admin/business/service/impl/DevicMaintainServiceImpl.java

@@ -1,30 +1,38 @@
 package com.imcs.admin.business.service.impl;
 
 
-import com.alibaba.fastjson.JSON;
-import com.alibaba.fastjson.JSONObject;
+import com.hankcs.hanlp.HanLP;
+import com.hankcs.hanlp.dictionary.py.Pinyin;
 import com.imcs.admin.business.service.DevicMaintainService;
 import com.imcs.admin.common.config.SessionContext;
-import com.imcs.admin.common.data.Obj;
+import com.imcs.admin.common.data.SysFile;
+import com.imcs.admin.common.service.SysFileService;
 import com.imcs.admin.db.service.JdbcDao;
 import com.imcs.admin.db.service.JdbcService;
 import com.imcs.admin.dto.DeviceMaintainDto;
 import com.imcs.admin.dto.DeviceMaintainSubDto;
 import com.imcs.admin.rbac.data.User;
-import com.imcs.admin.util.DateUtils;
 import com.imcs.admin.util.GenerateSerial;
-import com.imcs.admin.util.StringUtil;
 import lombok.extern.slf4j.Slf4j;
+import org.apache.poi.hwpf.HWPFDocument;
+import org.apache.poi.hwpf.usermodel.*;
 import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.mock.web.MockMultipartFile;
 import org.springframework.stereotype.Service;
+import org.springframework.transaction.annotation.Propagation;
 import org.springframework.transaction.annotation.Transactional;
+import org.springframework.web.multipart.MultipartFile;
 import org.thymeleaf.util.StringUtils;
 
 import javax.annotation.Resource;
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.IOException;
 import java.util.ArrayList;
 import java.util.Date;
 import java.util.List;
 import java.util.Map;
+import java.util.stream.Collectors;
 
 @Service
 @Slf4j
@@ -38,6 +46,9 @@ public class DevicMaintainServiceImpl  implements DevicMaintainService {
 
     @Resource
     private GenerateSerial generateSerial;
+    @Resource
+    private SysFileService sysFileService;
+
 
     @Override
     @Transactional(rollbackFor = Exception.class)
@@ -117,4 +128,225 @@ public class DevicMaintainServiceImpl  implements DevicMaintainService {
 
         return true;
     }
+
+    @Transactional
+    public  void processUpload(Map<String,Object> map) {
+        String filePath = map.get("filePath").toString();
+        File folder = new File(filePath);
+
+        if (folder.exists() && folder.isDirectory()) {
+            System.out.println("文件夹存在!");
+        } else {
+            throw new RuntimeException("文件夹不存在!!!");
+        }
+        String folderPath = "D:\\process"; // 文件夹路径
+        List<File> filesToProcess = listFilesToProcess(folderPath);
+        if(filesToProcess.size()==0){
+            throw new RuntimeException("文件夹下无有效文件!!!");
+        }
+        for (File file : filesToProcess) {
+            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("文件重命名失败!");
+                }
+
+
+            }
+        }
+    }
+    public  List<File> listFilesToProcess(String folderPath) {
+        List<File> filesToProcess = new ArrayList<>();
+        File folder = new File(folderPath);
+        File[] files = folder.listFiles();
+        if (files != null) {
+            for (File file : files) {
+                if (file.isFile() && file.getName().endsWith(".doc") && !file.getName().contains("processed")) {
+                    filesToProcess.add(file);
+                }
+            }
+        }
+        return filesToProcess;
+    }
+    @Transactional(propagation = Propagation.REQUIRES_NEW)
+    public  void processFile(File file) {
+        String filePath = file.getPath();
+        try {
+            FileInputStream fis = new FileInputStream(filePath);
+            HWPFDocument document = new HWPFDocument(fis);
+            fis.close();
+
+            // 遍历文档中的所有表格
+            Range range = document.getRange();
+            TableIterator it = new TableIterator(range);
+            List<List<String>> list=new ArrayList<>();
+            while (it.hasNext()) {
+                Table table = it.next();
+                // 遍历表格中的所有行
+                for (int i = 0; i < table.numRows(); i++) {
+                    TableRow row = table.getRow(i);
+                    // 遍历行中的所有单元格
+                    List<String> item=new ArrayList<>();
+                    for (int j = 0; j < row.numCells(); j++) {
+
+                        TableCell cell = row.getCell(j);
+                        // 获取单元格的内容并输出
+                        System.out.print(cell.text().replace("","").replace("\r","")+"\t");
+
+                        String replace = cell.text().replace("", "").replace("\r", "");
+                        item.add(replace);
+
+                    }
+                    boolean b = item.stream().allMatch(String::isEmpty);
+                    if (!b){
+                        list.add(item);
+                    }
+                    System.out.println(); // 换行
+                }
+            }
+            //第一行 获取 XS令号
+            List<String> strings = list.get(0);
+            String xsCode = strings.get(0).substring(5);
+
+            //第3行 获取 产品名称 数量
+            List<String> two = list.get(2);
+
+            String tuhao = two.get(0);
+            String productName = two.get(2);
+            //产品名称
+            String result = two.stream()
+                    .collect(Collectors.joining("_"));
+            //数量
+            int num = Integer.parseInt(two.get(3));
+
+
+
+            //第5行 获取 材料牌号  零件设计规格
+            List<String> three = list.get(4);
+            //产品规格
+            String productSize = three.get(1);
+            String materialName = three.get(0) + "_" + three.get(2);
+            int materialStore = Integer.parseInt(three.get(4));
+
+            //图纸版次
+            String processVersion = three.get(6);
+            //第8行 获取 工序
+            List<String> seven = list.get(7);
+
+            //物料
+            Long materialId = jdbcService.insert("insert", "INSERT INTO a_material ( `material_code`, `material_name`,`material_size`) VALUES (?,?,?)", materialName, materialName, three.get(2));
+
+
+            //原材料库存
+            Long materialStoreId = jdbcService.insert("insert", "INSERT INTO a_material_store(`parent_id`, `store_amount`) VALUES (?,?);", materialId,materialStore);
+
+            //产品管理
+            Long 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);
+
+            //工艺路径
+            SysFile sysFile = sysFileService.upload(convertToMultipartFile(file));
+            String path="/admin/download/"+sysFile.getId()+"/"+sysFile.getFileName();
+
+
+
+            Long processVersionId = jdbcService.insert("insert", "INSERT INTO a_process_version(`process_version`,`create_time`, `create_by`, `parent_id`, `status`, `device_id`,contract_file,business_type) VALUES (?,?,?,?,?,'2,6,7,9,10,11,12,15,16,20,3,4,5,8,13,14,17,18,19',?,?);\n", processVersion, new Date(), getUserId(), productId, 1,path,4);
+
+            String insertProcessProcedure="INSERT INTO a_process_procedure (`parent_id`, `procedure_id`, `is_outsourcing`, `work_hour`, `inspect_type`, `seq`) VALUES (?,?,?,?,?,?);";
+
+            String targetString = "注意:每道工序加工后实施检验,检验合格后方可转下序";
+
+            // 判断列表中是否包含目标字符串
+            boolean containsTargetString = list.stream()
+                    .flatMap(List::stream) // 将所有子列表合并成一个流
+                    .anyMatch(s -> s.equals(targetString)); // 判断是否存在目标字符串
+
+
+            //工序  工艺路径工序
+            List<List<String>> procedureList=new ArrayList<>();
+            for(List<String> item:list){
+                if (!item.isEmpty() && isNumeric(item.get(0))) {
+                    procedureList.add(item);
+                }
+            }
+
+            int wgSeq=0;
+            for(int i =0;i<procedureList.size();i++){
+                List<String> item=procedureList.get(i);
+                if (!item.isEmpty() && isNumeric(item.get(0))) {
+                    //int seq = Integer.parseInt(item.get(0));
+                    int seq=i+1;
+                    wgSeq=seq;
+                    String procedureName = item.get(1);
+                    String procedureContent = item.get(2);
+                    String procedureCode = convertToPinyin(procedureName);
+                    Map<String, Object> one = jdbcService.findOne("select * from a_procedure where procedure_code=? and procedure_name=? and procedure_content=?", procedureCode, procedureName, procedureContent);
+                    Long procedureId=null;
+                    if(one !=null){
+                        procedureId=Long.valueOf(one.get("id").toString());
+                    }else{
+                        procedureId = jdbcService.insert("insert", "INSERT INTO a_procedure (`procedure_code`, `procedure_name`, `procedure_content`) VALUES (?,?,?);", procedureCode, procedureName, procedureContent);
+                    }
+                    jdbcService.insert("insert",insertProcessProcedure,processVersionId,procedureId,0,null,null,seq);
+                    if(containsTargetString && i != item.size()-1){
+                        jdbcService.insert("insert",insertProcessProcedure,processVersionId,15,1,null,1,seq+1);
+                    }
+                }
+            }
+            if(wgSeq > 0 ){
+                jdbcService.insert("insert",insertProcessProcedure,processVersionId,14,2,null,2,wgSeq+1);
+            }
+
+            Map<String, Object> one = jdbcService.findOne("select value from dic_item where parent_id = (select id from dic where dic_code='autoGeneration') and label = '销售订单'");
+
+            Boolean value = Boolean.valueOf(one.get("value").toString());
+            if(value){
+                //销售订单
+                Long salesOrderId = jdbcService.insert("insert", "INSERT INTO b_sales_order (order_code, order_name, deliver_date, apply_status, is_issue, created_at, status) VALUES (?,?,?,?,?,?,?);"
+                        , generateSerial.generateSerialNumber("bSalesOrder"), xsCode + "_" + result, new Date(), 0, 0, new Date(), 0);
+                jdbcService.insert("insert","INSERT INTO a_sales_product (parent_id, product_id, sales_amount, seq) VALUES (?,?,?,?);",salesOrderId,productId,num,1);
+            }
+
+            document.close();
+        } catch (IOException e) {
+            e.printStackTrace();
+        }
+    }
+
+    // 将中文文本转换成拼音并将首字母大写
+    public static String convertToPinyin(String chineseText) {
+        StringBuilder pinyinBuilder = new StringBuilder();
+        List<Pinyin> pinyins = HanLP.convertToPinyinList(chineseText);
+        for (Pinyin pinyin : pinyins) {
+            pinyinBuilder.append(Character.toUpperCase(pinyin.getPinyinWithoutTone().charAt(0))); // 将拼音首字母大写
+        }
+        return pinyinBuilder.toString();
+    }
+
+    public Long getUserId(){
+        Long userId = SessionContext.getSession().getUserId();
+        return userId;
+    }
+
+    public  boolean isNumeric(String str) {
+        return str.matches("-?\\d+(\\.\\d+)?");
+    }
+
+    public  MultipartFile convertToMultipartFile(File file) throws IOException {
+        // 读取文件内容
+        byte[] content = new byte[(int) file.length()];
+        FileInputStream fileInputStream = new FileInputStream(file);
+        fileInputStream.read(content);
+        fileInputStream.close();
+
+        // 创建一个MockMultipartFile对象,模拟文件上传过程
+        return new MockMultipartFile(file.getName(), file.getName(),
+                "application/msword", content); // 注意:这里的content-type根据具体情况进行修改
+    }
 }

+ 17 - 0
src/main/java/com/imcs/admin/page/controller/CommonController.java

@@ -661,5 +661,22 @@ public class CommonController {
         return Result.success();
     }
 
+    @RequestMapping("/{model}/applyBatch/{id}/{field}/{status}")
+    public Result applyBatch(@RequestBody Map<String,Object> map,@PathVariable("id") Long id, @PathVariable("model") String model,@PathVariable("status") Long status,@PathVariable("field") String field) {
+        String tableName = StringUtil.toSqlColumn(model);
+        Long enterpriseId = SessionContext.getSession().getEnterpriseId();
+
+        if (id != null && StringUtils.isNotBlank(id.toString()) && !jdbcService.ownerEnterprise(tableName, id, enterpriseId)) {
+            return Result.error("没有数据权限.");
+        }
+        String[] ids = map.get("ids").toString().split(",");
+        for (String item:ids){
+            jdbcService.apply(Long.valueOf(item),tableName,status,field);
+        }
+
+
+        return Result.success();
+    }
+
 
 }