|
@@ -354,13 +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");
|
|
|
+ /*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) {
|
|
@@ -399,4 +399,211 @@ public class DevicMaintainServiceImpl implements DevicMaintainService {
|
|
|
return new MockMultipartFile(file.getName(), file.getName(),
|
|
|
"application/msword", content); // 注意:这里的content-type根据具体情况进行修改
|
|
|
}
|
|
|
+
|
|
|
+
|
|
|
+ public void getErp() {
|
|
|
+ String filePath = "D:\\process";
|
|
|
+ File folder = new File(filePath);
|
|
|
+
|
|
|
+ if (folder.exists() && folder.isDirectory()) {
|
|
|
+ System.out.println("文件夹存在!");
|
|
|
+ } else {
|
|
|
+ throw new RuntimeException("文件夹不存在!!!");
|
|
|
+ }
|
|
|
+ List<File> filesToProcess = listFilesToProcess(filePath);
|
|
|
+ if(filesToProcess.size()==0){
|
|
|
+ throw new RuntimeException("文件夹下无有效文件!!!");
|
|
|
+ }
|
|
|
+ for (File file : filesToProcess) {
|
|
|
+ if (file.isFile() && file.getName().endsWith(".doc") && !file.getName().contains("processed")) {
|
|
|
+ // 处理文件
|
|
|
+ processFile1(file);
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ public void processFile1(File file) {
|
|
|
+ String filePath = file.getPath();
|
|
|
+ try {
|
|
|
+ FileInputStream fis = new FileInputStream(filePath);
|
|
|
+ HWPFDocument document = new HWPFDocument(fis);
|
|
|
+
|
|
|
+
|
|
|
+ // 遍历文档中的所有表格
|
|
|
+ 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);
|
|
|
+
|
|
|
+ Map<String, Object> findMaterial = jdbcService.findOne("select * from a_material where material_code=? limit 1", materialName);
|
|
|
+ Long materialId = null;
|
|
|
+ if(findMaterial == null){
|
|
|
+ //物料
|
|
|
+ materialId = jdbcService.insert("insert", "INSERT INTO a_material ( `material_code`, `material_name`,`material_size`) VALUES (?,?,?)", materialName, materialName, three.get(2));
|
|
|
+ }else{
|
|
|
+ materialId = Long.valueOf(findMaterial.get("id").toString());
|
|
|
+ }
|
|
|
+ Map<String, Object> findMaterialStore = jdbcService.findOne("select * from a_material_store where parent_id=? limit 1", materialId);
|
|
|
+
|
|
|
+ if(findMaterialStore == null){
|
|
|
+ //原材料库存
|
|
|
+ jdbcService.insert("insert", "INSERT INTO a_material_store(`parent_id`, `store_amount`) VALUES (?,?);", materialId,materialStore);
|
|
|
+ }else{
|
|
|
+ jdbcService.update("update a_material_store set store_amount=store_amount + ? where parent_id=?",materialStore,materialId);
|
|
|
+ }
|
|
|
+
|
|
|
+ Map<String, Object> findProduct = jdbcService.findOne("select * from a_product where product_code=? limit 1", "xs_"+xsCode);
|
|
|
+ Long productId = null;
|
|
|
+ if(findProduct == null){
|
|
|
+ //产品管理
|
|
|
+ productId = jdbcService.insert("insert", "INSERT INTO a_product (`product_code`, `product_name`, `product_model`, `flat`) VALUES (?,?,?,?);", "xs_"+xsCode, result, productSize, "个");
|
|
|
+
|
|
|
+ }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));
|
|
|
+ String path="/admin/download/"+sysFile.getId()+"/"+sysFile.getFileName();
|
|
|
+
|
|
|
+ Map<String, Object> findProcessVersionId = jdbcService.findOne("select * from a_process_version where parent_id=? limit 1", productId);
|
|
|
+
|
|
|
+ if(findProcessVersionId == null){
|
|
|
+ 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 y=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;
|
|
|
+ y=++y;
|
|
|
+ String procedureName = item.get(1);
|
|
|
+ String procedureContent = item.get(3);
|
|
|
+ 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,y);
|
|
|
+ if(containsTargetString && i != procedureList.size()-1){
|
|
|
+ //过程检
|
|
|
+ y=++y;
|
|
|
+ jdbcService.insert("insert",insertProcessProcedure,processVersionId,15,1,null,1,y);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if(y > 0 ){
|
|
|
+ //完工检检
|
|
|
+ jdbcService.insert("insert",insertProcessProcedure,processVersionId,14,1,null,2,++y);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ 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());
|
|
|
+ //销售订单
|
|
|
+ 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(), 1, 0, new Date(), 0);
|
|
|
+ jdbcService.insert("insert","INSERT INTO a_sales_product (parent_id, product_id, sales_amount, seq) VALUES (?,?,?,?);",salesOrderId,productId,num,1);
|
|
|
+
|
|
|
+ /*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) {
|
|
|
+ log.error("上传工艺规格报错:{}",e);
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|