From 1dd93712e3873bf9d4be689f115c964d0703d03f Mon Sep 17 00:00:00 2001 From: liyawei Date: Wed, 13 Apr 2022 19:04:22 +0800 Subject: [PATCH] =?UTF-8?q?=E6=8B=86=E5=88=86-=E5=AF=BC=E5=85=A5=E6=A8=A1?= =?UTF-8?q?=E6=9D=BF=E8=8B=B1=E6=96=87=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../service/impl/SysCategoryServiceImpl.java | 18 + .../impl/FileSplitItemsEOServiceImpl.java | 400 ++++++++++++++---- 2 files changed, 347 insertions(+), 71 deletions(-) diff --git a/jero-boot/jero-boot-module-system/src/main/java/com/jero/modules/system/service/impl/SysCategoryServiceImpl.java b/jero-boot/jero-boot-module-system/src/main/java/com/jero/modules/system/service/impl/SysCategoryServiceImpl.java index 73baf4f08..043b84843 100644 --- a/jero-boot/jero-boot-module-system/src/main/java/com/jero/modules/system/service/impl/SysCategoryServiceImpl.java +++ b/jero-boot/jero-boot-module-system/src/main/java/com/jero/modules/system/service/impl/SysCategoryServiceImpl.java @@ -1,5 +1,6 @@ package com.jero.modules.system.service.impl; +import cn.hutool.core.util.ObjectUtil; import com.alibaba.fastjson.JSONObject; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; @@ -42,6 +43,23 @@ public class SysCategoryServiceImpl extends ServiceImpl getParentPath(SysCategory sysCategory){ + List nameList = new ArrayList<>(); + nameList.add(sysCategory.getName()); + getParent(sysCategory, nameList); + return nameList; + } + + private List getParent(SysCategory sysCategory, List nameList){ + SysCategory parent = sysCategoryMapper.selectById(sysCategory.getPid()); + if(ObjectUtil.isNotEmpty(parent)){ + nameList.add(parent.getName()); + } + if(!"0".equals(sysCategory.getPid())){ + getParent(parent, nameList); + } + return nameList; + } @Override public void addSysCategory(SysCategory sysCategory) { String categoryCode = ""; diff --git a/jero-boot/jero-boot-modules/src/main/java/com/jero/modules/split/service/impl/FileSplitItemsEOServiceImpl.java b/jero-boot/jero-boot-modules/src/main/java/com/jero/modules/split/service/impl/FileSplitItemsEOServiceImpl.java index 792236ad1..7767635b6 100644 --- a/jero-boot/jero-boot-modules/src/main/java/com/jero/modules/split/service/impl/FileSplitItemsEOServiceImpl.java +++ b/jero-boot/jero-boot-modules/src/main/java/com/jero/modules/split/service/impl/FileSplitItemsEOServiceImpl.java @@ -1324,11 +1324,22 @@ public class FileSplitItemsEOServiceImpl extends ServiceImpl1) { //删除原上传文件 FileUnZip.deleteDir(saveDirectory); - return Result.error(1, "压缩包根目录下仅能存在一个excel为导入数据"); + if(CutEnum.CN.getValue().equals(cut)){ + resultMsg = "压缩包根目录下仅能存在一个excel为导入数据"; + }else{ + resultMsg = "Only one Excel file can be imported in the compressed package root directory"; + } + return Result.error(1, resultMsg); } File excelfile = excelfilelist.get(0); // 导入参数设置,默认即可 @@ -1377,7 +1405,7 @@ public class FileSplitItemsEOServiceImpl extends ServiceImpl dbfieldList = Arrays.asList(dbfields.split(",")); // 有顺序 // 解析excel,并返回校验信息 - result = read(excelfile, dbfieldList,fields); + result = read(excelfile, dbfieldList,fields,cut); Long getExcelInfo = System.currentTimeMillis(); //excel读取到的数据 List> datas = result; @@ -1426,23 +1454,43 @@ public class FileSplitItemsEOServiceImpl extends ServiceImpl> read(File file, List dbfieldList, String[] titles) throws IOException, InvalidFormatException { + private List> read(File file, List dbfieldList, String[] titles, String cut) throws IOException, InvalidFormatException { //最终返回数据 List> list = new ArrayList<>(); @@ -1527,13 +1575,25 @@ public class FileSplitItemsEOServiceImpl extends ServiceImpl dto : datas) { i++; int countError = 0; //记录失败数据数量 - String errorMsg = "第" + i + "行:"; + String errorMsg = ""; + if(CutEnum.CN.getValue().equals(cut)){ + errorMsg = "第" + i + "行:"; + }else{ + errorMsg = i + " line:"; + } //判断发布日期,新车型实施日期,在产车实施日期 // try { @@ -1704,7 +1769,7 @@ public class FileSplitItemsEOServiceImpl extends ServiceImpl map : fieldList) { - String fieldName = (String) map.get("db_field_txt");//中文名称 + String fieldName = (String) map.get("db_field_txt");//中文名称/英文名称 String dbfieldName = (String) map.get("db_field_name");//字段名 String mustInput = (String) map.get("field_must_input");//是否必填 String dbLength = map.get("db_length").toString();//字段长度 @@ -1717,20 +1782,36 @@ public class FileSplitItemsEOServiceImpl extends ServiceImpl Long.parseLong(dbLength)) { - errorMsg += fieldName + "不能超过" + dbLength + "个字符;"; + if(CutEnum.CN.getValue().equals(cut)) { + errorMsg += fieldName + "不能超过" + dbLength + "个字符;"; + } else { + errorMsg += fieldName + " can not be more than " + dbLength + " char;"; + } countError++; } //判断数据是否匹配 if (StringUtils.isNotBlank(value)) { value = value.replace(",",","); for (String valueTemp : value.split(",")) { - if (!treeNameList.contains(valueTemp)) { - errorMsg += fieldName + "中的" + valueTemp + "与数据字典不匹配;"; + String lastValue = valueTemp; + if(valueTemp.contains("/")){ + lastValue = valueTemp.substring(valueTemp.lastIndexOf("/")+1); + } + if (!treeNameList.contains(lastValue)) { + if(CutEnum.CN.getValue().equals(cut)) { + errorMsg += fieldName + "中的" + lastValue + "与数据字典不匹配;"; + } else { + errorMsg += fieldName +" "+ lastValue + " does not match the data dictionary;"; + } countError++; } } @@ -1740,16 +1821,33 @@ public class FileSplitItemsEOServiceImpl extends ServiceImpl collect = new ArrayList<>(); if(CutEnum.CN.getValue().equals(cut)) { - collect = categoryList.stream().filter(e -> e.getName().equals(valueTemp)).collect(Collectors.toList()); + String finalLastValue = lastValue; + collect = categoryList.stream().filter(e -> e.getName().equals(finalLastValue)).collect(Collectors.toList()); } else if(CutEnum.EN.getValue().equals(cut)) { - collect = categoryList.stream().filter(e -> e.getEnName().equals(valueTemp)).collect(Collectors.toList()); + String finalLastValue1 = lastValue; + collect = categoryList.stream().filter(e -> e.getEnName().equals(finalLastValue1)).collect(Collectors.toList()); } if (collect.size() != 0) { - valueIdList.add(collect.get(0).getId()); + if(collect.size() == 1){ + valueIdList.add(collect.get(0).getId()); + } else { + // TODO 查询子节点的所有父节点 + for(SysCategory sysCategory : collect){ + List nameList = sysCategoryService.getParentPath(sysCategory); + List targetNameList = Arrays.asList(valueTemp.split("/")); + if(nameList.size() == targetNameList.size() && targetNameList.containsAll(nameList)) { + valueIdList.add(sysCategory.getId()); + continue; + } + } + } } } } @@ -1760,12 +1858,20 @@ public class FileSplitItemsEOServiceImpl extends ServiceImpl Long.parseLong(dbLength)) { - errorMsg += fieldName + "不能超过" + dbLength + "个字符;"; + if(CutEnum.CN.getValue().equals(cut)) { + errorMsg += fieldName + "不能超过" + dbLength + "个字符;"; + } else { + errorMsg += fieldName + " can not be more than" + dbLength + "char;"; + } countError++; } @@ -1773,13 +1879,22 @@ public class FileSplitItemsEOServiceImpl extends ServiceImpl Long.parseLong(dbLength)) { - errorMsg += fieldName + "不能超过" + dbLength + "个字符;"; + if(CutEnum.CN.getValue().equals(cut)) { + errorMsg += fieldName + "不能超过" + dbLength + "个字符;"; + } else { + errorMsg += fieldName + " can not be more than" + dbLength + "char;"; + } countError++; } //判断是否是单选 if (StringUtils.isNotBlank(value) && value.contains(",")) { - errorMsg += fieldName + "为单选项;"; + if(CutEnum.CN.getValue().equals(cut)) { + errorMsg += fieldName + "为单选项;"; + } else { + errorMsg += fieldName + " is single type;"; + } countError++; } //判断数据是否匹配 if (StringUtils.isNotBlank(value)) { if (!itemNameList.contains(value)) { - errorMsg += fieldName + "中的" + value + "与数据字典不匹配;"; + if(CutEnum.CN.getValue().equals(cut)) { + errorMsg += fieldName + "中的" + value + "与数据字典不匹配;"; + } else{ + errorMsg += fieldName + " " + value + " does not match the data dictionary"; + } countError++; } } @@ -1823,12 +1954,20 @@ public class FileSplitItemsEOServiceImpl extends ServiceImpl Long.parseLong(dbLength)) { - errorMsg += fieldName + "不能超过" + dbLength + "个字符;"; + if(CutEnum.CN.getValue().equals(cut)) { + errorMsg += fieldName + "不能超过" + dbLength + "个字符;"; + } else { + errorMsg += fieldName + " can not be more than" + dbLength + "char;"; + } countError++; } //下拉多选 @@ -1836,7 +1975,11 @@ public class FileSplitItemsEOServiceImpl extends ServiceImpl Long.parseLong(dbLength)) { - errorMsg += fieldName + "不能超过" + dbLength + "个字符;"; + if(CutEnum.CN.getValue().equals(cut)) { + errorMsg += fieldName + "不能超过" + dbLength + "个字符;"; + } else { + errorMsg += fieldName + " can not be more than" + dbLength + "char;"; + } countError++; } if (StringUtils.isNotBlank(value)) { @@ -1912,7 +2082,11 @@ public class FileSplitItemsEOServiceImpl extends ServiceImpl nowFileList = FileUnZip.readFileByFilename(filepath, fileName); if (nowFileList.size() == 0) { - errorMsg += fieldName + "压缩包中没有" + fileName + "文件; "; + if(CutEnum.CN.getValue().equals(cut)) { + errorMsg += fieldName + "压缩包中没有" + fileName + "文件; "; + } else { + errorMsg += fieldName + " " + fileName + "isn't present in the cabinet;"; + } countError++; } else { try { @@ -1939,12 +2113,20 @@ public class FileSplitItemsEOServiceImpl extends ServiceImpl Long.parseLong(dbLength)) { - errorMsg += key + "不能超过" + dbLength + "个字符;"; + if(CutEnum.CN.getValue().equals(cut)) { + errorMsg += fieldName + "不能超过" + dbLength + "个字符;"; + } else { + errorMsg += fieldName + " Can not be more than" + dbLength + "char;"; + } countError++; } //判断库中是否存在,如果存在则存id,如果不存在则存输入的值 @@ -1975,7 +2157,11 @@ public class FileSplitItemsEOServiceImpl extends ServiceImpl userIdList = new ArrayList<>(); for(int u=0 ; u"; +// html += message; + html += message + "
"; } map.put("message", html); } @@ -2294,6 +2492,7 @@ public class FileSplitItemsEOServiceImpl extends ServiceImpl dateSingleList = new LinkedList<>();//单选日期字段 List dateMoreList = new LinkedList<>();//多选日期字段 List standardList = new LinkedList<>();//标准选择字段 + List treeList = new LinkedList<>();//树形结构字段 for (Map map : addForm) { if ("1".equals(map.get("field_must_input"))) { sb.append("*" + map.get("db_field_txt") + ","); @@ -2325,53 +2524,112 @@ public class FileSplitItemsEOServiceImpl extends ServiceImpl resultList = new LinkedList<>(); resultList.add(title);