|
@@ -1,30 +1,38 @@
|
|
package com.imcs.admin.business.service.impl;
|
|
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.business.service.DevicMaintainService;
|
|
import com.imcs.admin.common.config.SessionContext;
|
|
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.JdbcDao;
|
|
import com.imcs.admin.db.service.JdbcService;
|
|
import com.imcs.admin.db.service.JdbcService;
|
|
import com.imcs.admin.dto.DeviceMaintainDto;
|
|
import com.imcs.admin.dto.DeviceMaintainDto;
|
|
import com.imcs.admin.dto.DeviceMaintainSubDto;
|
|
import com.imcs.admin.dto.DeviceMaintainSubDto;
|
|
import com.imcs.admin.rbac.data.User;
|
|
import com.imcs.admin.rbac.data.User;
|
|
-import com.imcs.admin.util.DateUtils;
|
|
|
|
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 org.apache.poi.hwpf.HWPFDocument;
|
|
|
|
+import org.apache.poi.hwpf.usermodel.*;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
+import org.springframework.mock.web.MockMultipartFile;
|
|
import org.springframework.stereotype.Service;
|
|
import org.springframework.stereotype.Service;
|
|
|
|
+import org.springframework.transaction.annotation.Propagation;
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
|
+import org.springframework.web.multipart.MultipartFile;
|
|
import org.thymeleaf.util.StringUtils;
|
|
import org.thymeleaf.util.StringUtils;
|
|
|
|
|
|
import javax.annotation.Resource;
|
|
import javax.annotation.Resource;
|
|
|
|
+import java.io.File;
|
|
|
|
+import java.io.FileInputStream;
|
|
|
|
+import java.io.IOException;
|
|
import java.util.ArrayList;
|
|
import java.util.ArrayList;
|
|
import java.util.Date;
|
|
import java.util.Date;
|
|
import java.util.List;
|
|
import java.util.List;
|
|
import java.util.Map;
|
|
import java.util.Map;
|
|
|
|
+import java.util.stream.Collectors;
|
|
|
|
|
|
@Service
|
|
@Service
|
|
@Slf4j
|
|
@Slf4j
|
|
@@ -38,6 +46,9 @@ public class DevicMaintainServiceImpl implements DevicMaintainService {
|
|
|
|
|
|
@Resource
|
|
@Resource
|
|
private GenerateSerial generateSerial;
|
|
private GenerateSerial generateSerial;
|
|
|
|
+ @Resource
|
|
|
|
+ private SysFileService sysFileService;
|
|
|
|
+
|
|
|
|
|
|
@Override
|
|
@Override
|
|
@Transactional(rollbackFor = Exception.class)
|
|
@Transactional(rollbackFor = Exception.class)
|
|
@@ -117,4 +128,225 @@ public class DevicMaintainServiceImpl implements DevicMaintainService {
|
|
|
|
|
|
return true;
|
|
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根据具体情况进行修改
|
|
|
|
+ }
|
|
}
|
|
}
|