From a78e3e23d68aaf9243580b4bc0b1f7a7c82cd63c Mon Sep 17 00:00:00 2001 From: 18792927508 <1322446236@qq.com> Date: Tue, 12 Dec 2023 16:22:41 +0800 Subject: [PATCH] =?UTF-8?q?=E5=B7=A5=E5=85=B7=E7=B1=BB=EF=BC=8C=E6=A1=88?= =?UTF-8?q?=E4=BB=B6=E5=8E=8B=E7=BC=A9=E5=8C=85=E5=AF=BC=E5=85=A5=E4=BC=98?= =?UTF-8?q?=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../CaseApplicationController.java | 2 +- .../com/ruoyi/common/utils/IdCardUtils.java | 57 + .../com/ruoyi/common/utils/IdWorkerUtil.java | 48 + .../ruoyi/common/utils/MoneyFormatUtils.java | 53 + .../com/ruoyi/common/utils/ReadFileUtils.java | 86 ++ .../com/ruoyi/common/utils/SpringUtil.java | 34 + .../ruoyi/common/utils/file/FileUtils.java | 14 + .../utils/thread/MultipleThreadWorkUtil.java | 47 +- .../ruoyi/system/mapper/SysDeptMapper.java | 7 + .../ruoyi/system/mapper/SysUserMapper.java | 7 +- .../mapper/CaseApplicationLogMapper.java | 2 + .../mapper/CaseApplicationMapper.java | 6 + .../mapper/CaseAttachLogMapper.java | 1 + .../mapper/ColumnValueLogMapper.java | 2 +- .../mapper/ColumnValueMapper.java | 2 +- .../service/IAdjudicationService.java | 7 + .../service/ICaseApplicationService.java | 2 +- .../service/impl/AdjudicationServiceImpl.java | 30 + .../impl/CaseApplicationServiceImpl.java | 1009 +---------------- .../service/impl/CaseImportValid.java | 328 ++++++ .../service/impl/CaseZipImportImpl.java | 811 +++++++++++++ .../ruoyi/wisdomarbitrate/utils/OCRUtils.java | 186 ++- .../resources/mapper/system/SysDeptMapper.xml | 37 +- .../resources/mapper/system/SysUserMapper.xml | 46 +- .../CaseAffiliateLogMapper.xml | 2 +- .../CaseApplicationLogMapper.xml | 62 + .../wisdomarbitrate/CaseApplicationMapper.xml | 77 +- .../wisdomarbitrate/CaseAttachLogMapper.xml | 7 + 28 files changed, 1876 insertions(+), 1096 deletions(-) create mode 100644 ruoyi-common/src/main/java/com/ruoyi/common/utils/IdCardUtils.java create mode 100644 ruoyi-common/src/main/java/com/ruoyi/common/utils/IdWorkerUtil.java create mode 100644 ruoyi-common/src/main/java/com/ruoyi/common/utils/MoneyFormatUtils.java create mode 100644 ruoyi-common/src/main/java/com/ruoyi/common/utils/ReadFileUtils.java create mode 100644 ruoyi-common/src/main/java/com/ruoyi/common/utils/SpringUtil.java create mode 100644 ruoyi-system/src/main/java/com/ruoyi/wisdomarbitrate/service/impl/CaseImportValid.java create mode 100644 ruoyi-system/src/main/java/com/ruoyi/wisdomarbitrate/service/impl/CaseZipImportImpl.java diff --git a/ruoyi-admin/src/main/java/com/ruoyi/web/controller/wisdomarbitrate/CaseApplicationController.java b/ruoyi-admin/src/main/java/com/ruoyi/web/controller/wisdomarbitrate/CaseApplicationController.java index f3f7a7c..f631ee5 100644 --- a/ruoyi-admin/src/main/java/com/ruoyi/web/controller/wisdomarbitrate/CaseApplicationController.java +++ b/ruoyi-admin/src/main/java/com/ruoyi/web/controller/wisdomarbitrate/CaseApplicationController.java @@ -78,7 +78,7 @@ public class CaseApplicationController extends BaseController { { caseApplication.setCreateBy(getUsername()); - return toAjax(caseApplicationService.insertcaseApplication(caseApplication,null)); + return toAjax(caseApplicationService.insertcaseApplication(caseApplication)); } /** diff --git a/ruoyi-common/src/main/java/com/ruoyi/common/utils/IdCardUtils.java b/ruoyi-common/src/main/java/com/ruoyi/common/utils/IdCardUtils.java new file mode 100644 index 0000000..04cef0f --- /dev/null +++ b/ruoyi-common/src/main/java/com/ruoyi/common/utils/IdCardUtils.java @@ -0,0 +1,57 @@ +package com.ruoyi.common.utils; + +import java.util.Calendar; +import java.util.HashMap; +import java.util.Map; + +/** + * @author wangqiong + * @description 根据身份证号提取有效信息 + * @date 2023-12-11 11:45 + */ +public class IdCardUtils { + /** + * 通过身份证号码获取出生日期、性别、年龄 + * @param certificateNo + * @return 返回的出生日期格式:1990-01-01 性别格式:1-女,0-男 + */ + public static Map getBirAgeSex(String certificateNo) { + String birthday = ""; + String age = ""; + String sexCode = ""; + + int year = Calendar.getInstance().get(Calendar.YEAR); + char[] number = certificateNo.toCharArray(); + boolean flag = true; + if (number.length == 15) { + for (int x = 0; x < number.length; x++) { + if (!flag) return new HashMap(); + flag = Character.isDigit(number[x]); + } + } else if (number.length == 18) { + for (int x = 0; x < number.length - 1; x++) { + if (!flag) return new HashMap(); + flag = Character.isDigit(number[x]); + } + } + if (flag && certificateNo.length() == 15) { + birthday = "19" + certificateNo.substring(6, 8) + "-" + + certificateNo.substring(8, 10) + "-" + + certificateNo.substring(10, 12); + sexCode = Integer.parseInt(certificateNo.substring(certificateNo.length() - 3, certificateNo.length())) % 2 == 0 ? "1" : "0"; + age = (year - Integer.parseInt("19" + certificateNo.substring(6, 8))) + ""; + } else if (flag && certificateNo.length() == 18) { + birthday = certificateNo.substring(6, 10) + "-" + + certificateNo.substring(10, 12) + "-" + + certificateNo.substring(12, 14); + sexCode = Integer.parseInt(certificateNo.substring(certificateNo.length() - 4, certificateNo.length() - 1)) % 2 == 0 ? "1" : "0"; + age = (year - Integer.parseInt(certificateNo.substring(6, 10))) + ""; + } + Map map = new HashMap(); + map.put("birthday", birthday); + map.put("age", age); + map.put("sexCode", sexCode); + return map; + } + +} diff --git a/ruoyi-common/src/main/java/com/ruoyi/common/utils/IdWorkerUtil.java b/ruoyi-common/src/main/java/com/ruoyi/common/utils/IdWorkerUtil.java new file mode 100644 index 0000000..e9f2af4 --- /dev/null +++ b/ruoyi-common/src/main/java/com/ruoyi/common/utils/IdWorkerUtil.java @@ -0,0 +1,48 @@ +package com.ruoyi.common.utils; + +import cn.hutool.core.lang.Snowflake; +import cn.hutool.core.util.IdUtil; +import com.ruoyi.common.utils.uuid.UUID; + +import java.math.BigInteger; +import java.util.Random; + +/** + * 雪花算法工具类 + * zq + * @since 2020/10/30 9:59 + **/ +public class IdWorkerUtil { + private static final long EPOCH = 1479533469598L; //开始时间,固定一个小于当前时间的毫秒数 + private static final int max12bit = 4095; + private static final long max41bit= 1099511627775L; + private static String machineId = "" ; // 机器ID + + /** + * + * 创建ID + * + * @return + * + */ + public static Long getId(){ + + long time = System.currentTimeMillis() - EPOCH + max41bit; + // 二进制的 毫秒级时间戳 + String base = Long.toBinaryString(time); + + // 序列数 + String randomStr = StringUtils.leftPad(Integer.toBinaryString(new Random().nextInt(max12bit)),12,'0'); + if(StringUtils.isNotEmpty(machineId)){ + machineId = StringUtils.leftPad(machineId, 10, '0'); + } + + //拼接 + String appendStr = base + machineId + randomStr; + // 转化为十进制 返回 + BigInteger bi = new BigInteger(appendStr, 2); + + return Long.valueOf(bi.toString()); + } + +} diff --git a/ruoyi-common/src/main/java/com/ruoyi/common/utils/MoneyFormatUtils.java b/ruoyi-common/src/main/java/com/ruoyi/common/utils/MoneyFormatUtils.java new file mode 100644 index 0000000..5436693 --- /dev/null +++ b/ruoyi-common/src/main/java/com/ruoyi/common/utils/MoneyFormatUtils.java @@ -0,0 +1,53 @@ +package com.ruoyi.common.utils; + +import java.math.BigDecimal; +import java.text.NumberFormat; +import java.util.regex.Matcher; +import java.util.regex.Pattern; +/** + * @author wangqiong + * @description 金额格式化 + * @date 2023-12-11 11:45 + */ +public class MoneyFormatUtils { + + /** + * 增加千分位 + * @param money + * @return + */ + public static String moneyFormat(String money) { + // 金额格式化 + try { + Double.parseDouble(money); + + } catch (NumberFormatException e) { + + String regEx = "[^0-9]"; + Pattern p = Pattern.compile(regEx); + Matcher m = p.matcher(money); + String result = m.replaceAll("").trim(); + BigDecimal bigDecimal = null; + if (money.contains("百")) { + bigDecimal = new BigDecimal(result).multiply(new BigDecimal("100")); + } else if (money.contains("千")) { + bigDecimal = new BigDecimal(result).multiply(new BigDecimal("1000")); + } else if (money.contains("万")) { + bigDecimal = new BigDecimal(result).multiply(new BigDecimal("10000")); + } else if (money.contains("百万")) { + bigDecimal = new BigDecimal(result).multiply(new BigDecimal("1000000")); + } else if (money.contains("千万")) { + bigDecimal = new BigDecimal(result).multiply(new BigDecimal("10000000")); + } else if (money.contains("亿")) { + bigDecimal = new BigDecimal(result).multiply(new BigDecimal("100000000")); + } + + NumberFormat format = NumberFormat.getInstance(); + return format.format(bigDecimal); + + } + return ""; + } + + +} diff --git a/ruoyi-common/src/main/java/com/ruoyi/common/utils/ReadFileUtils.java b/ruoyi-common/src/main/java/com/ruoyi/common/utils/ReadFileUtils.java new file mode 100644 index 0000000..870f4af --- /dev/null +++ b/ruoyi-common/src/main/java/com/ruoyi/common/utils/ReadFileUtils.java @@ -0,0 +1,86 @@ +package com.ruoyi.common.utils; + +import org.apache.poi.hwpf.extractor.WordExtractor; +import org.apache.poi.xwpf.extractor.XWPFWordExtractor; +import org.apache.poi.xwpf.usermodel.XWPFDocument; + +import java.io.*; + +/** + * @author wangqiong + * @description 读取文件内容 + * @date 2023-12-11 11:45 + */ +public class ReadFileUtils { + + + public static String readerTxtFile(String filePath){ + BufferedReader br=null; + StringBuilder result=new StringBuilder(); + try { + br = new BufferedReader(new InputStreamReader(new FileInputStream(new File(filePath)),"GBK")); + String line=null; + while ((line=br.readLine())!=null) { + result.append(line).append("\n"); + } + } catch (IOException e) { + e.printStackTrace(); + } finally { + if (null!=br){ + try { + br.close(); + } catch (IOException e) { + e.printStackTrace(); + } + } + } + return result.toString(); + } + public static String readWord(String filePath) throws Exception{ + + File file = new File(filePath); + if(file.length()==0) return ""; // 需要操作原因是可能会空文件问题,如果不做处理,在下面读取中会报错 + StringBuffer sb = new StringBuffer(); + String buffer = ""; + try { + if (filePath.endsWith(".doc")) { + InputStream is = new FileInputStream(file); + WordExtractor ex = new WordExtractor(is); + buffer = ex.getText(); + if(buffer.length() > 0){ + //使用回车换行符分割字符串 + String [] arry = buffer.split("r\\n"); + for (String string : arry) { + sb.append(string.trim()); + } + } + } else if (filePath.endsWith(".docx")) { + FileInputStream fis = new FileInputStream(file); + XWPFDocument xdoc = new XWPFDocument(fis); + XWPFWordExtractor extractor = new XWPFWordExtractor(xdoc); + buffer = extractor.getText(); + sb.append(buffer!=null?buffer:""); + + +// OPCPackage opcPackage = POIXMLDocument.openPackage(filePath); +// XWPFWordExtractor extractor = new XWPFWordExtractor(opcPackage); +// buffer = extractor.getText(); +// if(buffer.length() > 0){ +// //使用换行符分割字符串 +// String [] arry = buffer.split("\n"); +// for (String string : arry) { +// sb.append(string.trim()); +// } +// } + } else { + return null; + } + return sb.toString(); + } catch (Exception e) { + System.out.print("error---->"+filePath); + e.printStackTrace(); + return null; + } + } + +} diff --git a/ruoyi-common/src/main/java/com/ruoyi/common/utils/SpringUtil.java b/ruoyi-common/src/main/java/com/ruoyi/common/utils/SpringUtil.java new file mode 100644 index 0000000..9f36643 --- /dev/null +++ b/ruoyi-common/src/main/java/com/ruoyi/common/utils/SpringUtil.java @@ -0,0 +1,34 @@ +package com.ruoyi.common.utils; + +import org.springframework.beans.BeansException; +import org.springframework.context.ApplicationContext; +import org.springframework.context.ApplicationContextAware; +import org.springframework.stereotype.Component; + +/** + * @author wangqiong + * @description 获取bean工具类 + * @date 2023-12-11 11:45 + */ +@Component +public class SpringUtil implements ApplicationContextAware { + private static ApplicationContext applicationContext; + @Override + public void setApplicationContext(ApplicationContext applicationContext) throws BeansException { + if(SpringUtil.applicationContext==null){ + SpringUtil.applicationContext=applicationContext; + } + } + + public static ApplicationContext getApplicationContext(){ + return applicationContext; + } + + public static T getBean(Class clazz){ + return getApplicationContext().getBean(clazz); + } + + public static T getBean(String name, Class clazz){ + return getApplicationContext().getBean(name,clazz); + } +} diff --git a/ruoyi-common/src/main/java/com/ruoyi/common/utils/file/FileUtils.java b/ruoyi-common/src/main/java/com/ruoyi/common/utils/file/FileUtils.java index ed4cbc9..b659420 100644 --- a/ruoyi-common/src/main/java/com/ruoyi/common/utils/file/FileUtils.java +++ b/ruoyi-common/src/main/java/com/ruoyi/common/utils/file/FileUtils.java @@ -288,4 +288,18 @@ public class FileUtils String baseName = FilenameUtils.getBaseName(fileName); return baseName; } + /** + * 获取文件后缀名 + * @param file + * @return + */ + public static String getFileExtension(File file) { + String name = file.getName(); + int lastIndexOfDot = name.lastIndexOf("."); + if (lastIndexOfDot != -1 && lastIndexOfDot < name.length() - 1) { + return name.substring(lastIndexOfDot + 1); + } else { + return ""; + } + } } diff --git a/ruoyi-common/src/main/java/com/ruoyi/common/utils/thread/MultipleThreadWorkUtil.java b/ruoyi-common/src/main/java/com/ruoyi/common/utils/thread/MultipleThreadWorkUtil.java index 81b9023..cfb5d2e 100644 --- a/ruoyi-common/src/main/java/com/ruoyi/common/utils/thread/MultipleThreadWorkUtil.java +++ b/ruoyi-common/src/main/java/com/ruoyi/common/utils/thread/MultipleThreadWorkUtil.java @@ -185,7 +185,52 @@ public class MultipleThreadWorkUtil { mainLatch,threadLatch,rollBack,times); return returnList; } - + public static List execListFun(MultipleThreadListParam ...params){ + List returnList=new ArrayList<>(); + if(ArrayUtil.isEmpty(params)){ + return returnList; + } + List threadCountList=new ArrayList<>(); + for (MultipleThreadListParam param : params) { + if(param.getList().size()0){ + threadCountList.add(param.getList().size()/SIMPLE_TIME_COUNT+1); + }else{ + threadCountList.add(param.getList().size()/SIMPLE_TIME_COUNT); + } + } + } + int times=0; + for (Integer count : threadCountList) { + times+=count; + } + CountDownLatch mainLatch=new CountDownLatch(1); + //监控子线程 + CountDownLatch threadLatch=new CountDownLatch(times); + //根据子线程执行结果判断是否需要回滚 + BlockingDeque resultList=new LinkedBlockingDeque<>(); + //必须使用对象,如果使用变量会造成线程之间不能共享变量值 + RollBack rollBack=new RollBack(false); + ExecutorService executorService=Executors.newFixedThreadPool(times); + List> futureList=new ArrayList<>(); + for (int i = 0; i < params.length; i++) { + MultipleThreadListParam param=params[i]; + for (int j = 0; j future=executorService.submit(new ExecThread(mainLatch,threadLatch,rollBack,resultList,param.getList().subList(j*SIMPLE_TIME_COUNT,j*SIMPLE_TIME_COUNT+SIMPLE_TIME_COUNT),param.getFunction())); + futureList.add(future); + }else{ + Future future=executorService.submit(new ExecThread(mainLatch,threadLatch,rollBack,resultList,param.getList().subList(j*SIMPLE_TIME_COUNT,param.getList().size()),param.getFunction())); + futureList.add(future); + } + } + } + setResult(executorService,returnList,futureList,resultList, + mainLatch,threadLatch,rollBack,times); + return returnList; + } public static List execByIds(Function execFun,String ids){ List returnList=new ArrayList<>(); if(StrUtil.isEmpty(ids)){ diff --git a/ruoyi-system/src/main/java/com/ruoyi/system/mapper/SysDeptMapper.java b/ruoyi-system/src/main/java/com/ruoyi/system/mapper/SysDeptMapper.java index 6ca6af8..4ef0d06 100644 --- a/ruoyi-system/src/main/java/com/ruoyi/system/mapper/SysDeptMapper.java +++ b/ruoyi-system/src/main/java/com/ruoyi/system/mapper/SysDeptMapper.java @@ -117,4 +117,11 @@ public interface SysDeptMapper public int deleteDeptById(Long deptId); List selectUserDeptListByRoleId(@Param("roleId")Long roleId); + + /** + * 批量新增 + * @param sysDepts + * @return + */ + int batchSave(@Param("list")List sysDepts); } diff --git a/ruoyi-system/src/main/java/com/ruoyi/system/mapper/SysUserMapper.java b/ruoyi-system/src/main/java/com/ruoyi/system/mapper/SysUserMapper.java index 56fde44..e23c18f 100644 --- a/ruoyi-system/src/main/java/com/ruoyi/system/mapper/SysUserMapper.java +++ b/ruoyi-system/src/main/java/com/ruoyi/system/mapper/SysUserMapper.java @@ -165,5 +165,10 @@ public interface SysUserMapper List selectRoleUserByDeptId(@Param("deptId")Long deptId,@Param("roleId") Long roleId ); - + /** + * 批量新增用户 + * @param addUsers + * @return + */ + int batchSave(@Param("list")List addUsers); } diff --git a/ruoyi-system/src/main/java/com/ruoyi/wisdomarbitrate/mapper/CaseApplicationLogMapper.java b/ruoyi-system/src/main/java/com/ruoyi/wisdomarbitrate/mapper/CaseApplicationLogMapper.java index 98310f2..862074f 100644 --- a/ruoyi-system/src/main/java/com/ruoyi/wisdomarbitrate/mapper/CaseApplicationLogMapper.java +++ b/ruoyi-system/src/main/java/com/ruoyi/wisdomarbitrate/mapper/CaseApplicationLogMapper.java @@ -44,4 +44,6 @@ public interface CaseApplicationLogMapper { void batchDeleteLog(@Param("ids") List ids); CaseApplication selectBeforeCase(@Param("caseId") Long caseId, @Param("version")Integer version); + + Integer batchSave(@Param("list")List caseApplications); } diff --git a/ruoyi-system/src/main/java/com/ruoyi/wisdomarbitrate/mapper/CaseApplicationMapper.java b/ruoyi-system/src/main/java/com/ruoyi/wisdomarbitrate/mapper/CaseApplicationMapper.java index d5bd37b..dbeefd4 100644 --- a/ruoyi-system/src/main/java/com/ruoyi/wisdomarbitrate/mapper/CaseApplicationMapper.java +++ b/ruoyi-system/src/main/java/com/ruoyi/wisdomarbitrate/mapper/CaseApplicationMapper.java @@ -125,4 +125,10 @@ public interface CaseApplicationMapper { */ Integer selectBatchNumberLike(); + /** + * 批量新增案件 + * @param caseApplications + * @return + */ + int batchSave(@Param("list")List caseApplications); } diff --git a/ruoyi-system/src/main/java/com/ruoyi/wisdomarbitrate/mapper/CaseAttachLogMapper.java b/ruoyi-system/src/main/java/com/ruoyi/wisdomarbitrate/mapper/CaseAttachLogMapper.java index 9ea2b54..b5d1ca9 100644 --- a/ruoyi-system/src/main/java/com/ruoyi/wisdomarbitrate/mapper/CaseAttachLogMapper.java +++ b/ruoyi-system/src/main/java/com/ruoyi/wisdomarbitrate/mapper/CaseAttachLogMapper.java @@ -27,4 +27,5 @@ public interface CaseAttachLogMapper { CaseAttach queryAnnexById(Integer annexId); + Integer batchSave(@Param("list")List caseAttaches); } diff --git a/ruoyi-system/src/main/java/com/ruoyi/wisdomarbitrate/mapper/ColumnValueLogMapper.java b/ruoyi-system/src/main/java/com/ruoyi/wisdomarbitrate/mapper/ColumnValueLogMapper.java index 27d848f..9c257e0 100644 --- a/ruoyi-system/src/main/java/com/ruoyi/wisdomarbitrate/mapper/ColumnValueLogMapper.java +++ b/ruoyi-system/src/main/java/com/ruoyi/wisdomarbitrate/mapper/ColumnValueLogMapper.java @@ -15,7 +15,7 @@ public interface ColumnValueLogMapper { /** * 批量新增 */ - void batchSave(@Param("list") List list); + int batchSave(@Param("list") List list); void batchUpdate(@Param("list") List list); /** diff --git a/ruoyi-system/src/main/java/com/ruoyi/wisdomarbitrate/mapper/ColumnValueMapper.java b/ruoyi-system/src/main/java/com/ruoyi/wisdomarbitrate/mapper/ColumnValueMapper.java index 2746608..a08899e 100644 --- a/ruoyi-system/src/main/java/com/ruoyi/wisdomarbitrate/mapper/ColumnValueMapper.java +++ b/ruoyi-system/src/main/java/com/ruoyi/wisdomarbitrate/mapper/ColumnValueMapper.java @@ -17,7 +17,7 @@ public interface ColumnValueMapper { /** * 批量新增 */ - void batchSave(@Param("list") List list); + int batchSave(@Param("list") List list); /** * 根据案件id查询字段及值 diff --git a/ruoyi-system/src/main/java/com/ruoyi/wisdomarbitrate/service/IAdjudicationService.java b/ruoyi-system/src/main/java/com/ruoyi/wisdomarbitrate/service/IAdjudicationService.java index b488e55..3c94b26 100644 --- a/ruoyi-system/src/main/java/com/ruoyi/wisdomarbitrate/service/IAdjudicationService.java +++ b/ruoyi-system/src/main/java/com/ruoyi/wisdomarbitrate/service/IAdjudicationService.java @@ -32,4 +32,11 @@ public interface IAdjudicationService { * @return */ AjaxResult emailByCaseId(Long id); + + /** + * 批量生成裁决书 + * @param ids + * @return + */ + AjaxResult batchDocument(List ids); } diff --git a/ruoyi-system/src/main/java/com/ruoyi/wisdomarbitrate/service/ICaseApplicationService.java b/ruoyi-system/src/main/java/com/ruoyi/wisdomarbitrate/service/ICaseApplicationService.java index b74ae4b..a774cc6 100644 --- a/ruoyi-system/src/main/java/com/ruoyi/wisdomarbitrate/service/ICaseApplicationService.java +++ b/ruoyi-system/src/main/java/com/ruoyi/wisdomarbitrate/service/ICaseApplicationService.java @@ -19,7 +19,7 @@ public interface ICaseApplicationService { List selectCaseApplicationListByRole(CaseApplication caseApplication); - int insertcaseApplication(CaseApplication caseApplication, List columnValueList); + int insertcaseApplication(CaseApplication caseApplication); int selectCaseApplicationCount(CaseApplication caseApplication); diff --git a/ruoyi-system/src/main/java/com/ruoyi/wisdomarbitrate/service/impl/AdjudicationServiceImpl.java b/ruoyi-system/src/main/java/com/ruoyi/wisdomarbitrate/service/impl/AdjudicationServiceImpl.java index ad82e8f..8e46939 100644 --- a/ruoyi-system/src/main/java/com/ruoyi/wisdomarbitrate/service/impl/AdjudicationServiceImpl.java +++ b/ruoyi-system/src/main/java/com/ruoyi/wisdomarbitrate/service/impl/AdjudicationServiceImpl.java @@ -11,6 +11,8 @@ import com.ruoyi.common.core.domain.entity.SysDictData; import com.ruoyi.common.core.redis.RedisCache; import com.ruoyi.common.exception.ServiceException; import com.ruoyi.common.utils.*; +import com.ruoyi.common.utils.thread.MultipleThreadListParam; +import com.ruoyi.common.utils.thread.MultipleThreadWorkUtil; import com.ruoyi.system.mapper.SysDictDataMapper; import com.ruoyi.wisdomarbitrate.domain.vo.BookSendVO; import com.ruoyi.wisdomarbitrate.domain.vo.ColumnValue; @@ -49,6 +51,7 @@ import java.text.NumberFormat; import java.text.SimpleDateFormat; import java.time.LocalDate; import java.util.*; +import java.util.concurrent.CountDownLatch; import java.util.function.Function; import java.util.regex.Matcher; import java.util.regex.Pattern; @@ -1252,6 +1255,33 @@ public class AdjudicationServiceImpl implements IAdjudicationService { } return AjaxResult.success(bookSendVO); } + private void setExecList(List execList, List columnValueList){ + if(CollectionUtil.isNotEmpty(columnValueList)){ + Function,Integer> function= columnValueMapper::batchSave; + execList.add(new MultipleThreadListParam(function,columnValueList)); + } + + } + @Transactional + @Override + public AjaxResult batchDocument(List ids) { + // todo 多线程生成裁决书 +// List execList=new ArrayList<>(); +// if(CollectionUtil.isNotEmpty(columnValueList)) { +// setExecList(execList, columnValueList); +// } +// +// if(CollectionUtil.isNotEmpty(execList)){ +// MultipleThreadWorkUtil.execListFun(execList.toArray(new MultipleThreadListParam[execList.size()])); +// } + for (Long id : ids) { + CaseApplication caseApplication = new CaseApplication(); + caseApplication.setId(id); + createDocument(caseApplication); + } + + return AjaxResult.success(); + } public String getNewEquipmentNo() { Object awardNum = redisCache.getCacheObject("awardNum"); diff --git a/ruoyi-system/src/main/java/com/ruoyi/wisdomarbitrate/service/impl/CaseApplicationServiceImpl.java b/ruoyi-system/src/main/java/com/ruoyi/wisdomarbitrate/service/impl/CaseApplicationServiceImpl.java index 9bd4ce6..6ad8569 100644 --- a/ruoyi-system/src/main/java/com/ruoyi/wisdomarbitrate/service/impl/CaseApplicationServiceImpl.java +++ b/ruoyi-system/src/main/java/com/ruoyi/wisdomarbitrate/service/impl/CaseApplicationServiceImpl.java @@ -1,26 +1,16 @@ package com.ruoyi.wisdomarbitrate.service.impl; -import cn.hutool.core.bean.BeanUtil; import cn.hutool.core.collection.CollectionUtil; -import cn.hutool.core.util.IdcardUtil; -import cn.hutool.core.util.ObjectUtil; import cn.hutool.core.util.StrUtil; -import cn.hutool.core.util.ZipUtil; -import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSONArray; import com.alibaba.fastjson.JSONObject; -import com.documents4j.api.DocumentType; -import com.documents4j.api.IConverter; -import com.documents4j.job.LocalConverter; import com.google.gson.Gson; import com.google.gson.JsonArray; import com.google.gson.JsonObject; import com.ruoyi.common.annotation.DataScope; -import com.ruoyi.common.config.RuoYiConfig; import com.ruoyi.common.constant.CaseApplicationConstants; -import com.ruoyi.common.constant.Constants; import com.ruoyi.common.core.domain.AjaxResult; import com.ruoyi.common.core.domain.entity.*; import com.ruoyi.common.core.domain.model.LoginUser; @@ -28,7 +18,6 @@ import com.ruoyi.common.enums.UpdateSubmitStatus; import com.ruoyi.common.exception.EsignDemoException; import com.ruoyi.common.exception.ServiceException; import com.ruoyi.common.utils.*; -import com.ruoyi.common.utils.file.FileUploadUtils; import com.ruoyi.common.utils.file.SaaSAPIFileUtils; import com.ruoyi.common.core.domain.entity.SysUser; import com.ruoyi.common.utils.thread.ThreadPoolUtil; @@ -41,21 +30,11 @@ import com.ruoyi.wisdomarbitrate.domain.*; import com.ruoyi.wisdomarbitrate.domain.vo.SendRoomNoMessageVO; import com.ruoyi.wisdomarbitrate.mapper.*; import com.ruoyi.wisdomarbitrate.service.ICaseApplicationService; -import com.ruoyi.wisdomarbitrate.utils.OCRUtils; import com.ruoyi.wisdomarbitrate.utils.SignAward; import com.ruoyi.wisdomarbitrate.utils.UnZipFileUtils; import com.ruoyi.wisdomarbitrate.utils.ZipFileUtils; import com.tencentyun.TLSSigAPIv2; -import org.apache.pdfbox.pdmodel.PDDocument; - - -import org.apache.poi.hwpf.extractor.WordExtractor; -import org.apache.poi.ooxml.POIXMLDocument; -import org.apache.poi.ooxml.extractor.POIXMLTextExtractor; -import org.apache.poi.openxml4j.opc.OPCPackage; -import org.apache.poi.xwpf.extractor.XWPFWordExtractor; -import org.apache.poi.xwpf.usermodel.XWPFDocument; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Value; import org.springframework.stereotype.Service; @@ -67,16 +46,12 @@ import java.math.RoundingMode; import java.nio.file.Files; import java.nio.file.Path; import java.nio.file.StandardCopyOption; -import java.text.NumberFormat; -import java.text.ParseException; import java.text.SimpleDateFormat; import java.time.LocalDate; import java.time.ZoneId; import java.util.*; import java.util.List; -import java.util.concurrent.TimeUnit; import java.util.function.Function; -import java.util.regex.Matcher; import java.util.regex.Pattern; import java.util.stream.Collectors; import java.util.zip.ZipOutputStream; @@ -138,14 +113,14 @@ public class CaseApplicationServiceImpl implements ICaseApplicationService { private CaseAffiliateLogMapper caseAffiliateLogMapper; @Autowired private CaseAttachLogMapper caseAttachLogMapper; - @Autowired - private FatchRuleMapper fatchRuleMapper; + @Autowired private ColumnValueMapper columnValueMapper; @Autowired private ColumnValueLogMapper columnValueLogMapper; + @Autowired - private SysDictDataMapper dictDataMapper; + private CaseZipImportImpl caseZipImportImpl; // 手机号正则 private static final Pattern TELEPHONE_REGX = Pattern.compile("^1(3\\d|4[5-9]|5[0-35-9]|6[2567]|7[0-8]|8\\d|9[0-35-9])\\d{8}$"); // 邮箱正则 @@ -381,21 +356,7 @@ public class CaseApplicationServiceImpl implements ICaseApplicationService { return caseApplicationMapper.updateCaseLockStatus(caseApplication.getId(), caseApplication.getLockStatus()); } - public void inputChangeToFile(InputStream instream, File file) { - try { - OutputStream outStr = new FileOutputStream(file); - int bytesRead = 0; - byte[] buffer = new byte[8192]; - while ((bytesRead = instream.read(buffer, 0, 1024)) != -1) { - outStr.write(buffer, 0, bytesRead); - } - outStr.flush(); - outStr.close(); - instream.close(); - } catch (Exception e) { - e.printStackTrace(); - } - } + @Override @Transactional @@ -410,7 +371,7 @@ public class CaseApplicationServiceImpl implements ICaseApplicationService { try { ins = file.getInputStream(); zipFile = new File(file.getOriginalFilename()); - inputChangeToFile(ins, zipFile); + caseZipImportImpl.inputChangeToFile(ins, zipFile); } catch (IOException e) { e.printStackTrace(); } @@ -943,8 +904,8 @@ public class CaseApplicationServiceImpl implements ICaseApplicationService { */ @Override @Transactional - public int insertcaseApplication(CaseApplication caseApplication, List columnValueList) { - + public int insertcaseApplication(CaseApplication caseApplication) { + List columnValueList=caseApplication.getColumnValues(); caseApplication.setCaseStatus(CaseApplicationConstants.CASE_APPLICATION); //根据仲裁费用计费规则计算应缴费用 //暂时设置计费比率为0.01 @@ -984,7 +945,7 @@ public class CaseApplicationServiceImpl implements ICaseApplicationService { Long roleId = roleMapper.selectRoleIdByName("申请人"); for (CaseAffiliate caseAffiliate : caseAffiliates) { caseAffiliate.setCaseAppliId(caseApplication.getId()); - caseAffiliate.setCaseAppliLogId(caseApplication.getId()); + // caseAffiliate.setCaseAppliLogId(caseApplication.getId()); if (caseAffiliate.getIdentityType() == 1 && StrUtil.isNotEmpty(caseAffiliate.getName())) { // 将组织机构id设为申请人名称 if (deptMap.containsKey(caseAffiliate.getName())) { @@ -1039,6 +1000,7 @@ public class CaseApplicationServiceImpl implements ICaseApplicationService { // 新增日志 insertCaseLog(caseApplication.getId(), CaseApplicationConstants.CASE_APPLICATION, ""); // 异步新增案件日志 + ThreadPoolUtil.execute(() -> { // 批量新增columnValue自定义字段 if(CollectionUtil.isNotEmpty(columnValueList)) { @@ -1088,7 +1050,7 @@ public class CaseApplicationServiceImpl implements ICaseApplicationService { * @return */ - private String generateCaseNum() { + public String generateCaseNum() { // 自动编码格式 zc+yyyyMMdd+001 String currentDay = DateUtils.dateTime(); String caseNum = "zc" + currentDay; @@ -1097,6 +1059,7 @@ public class CaseApplicationServiceImpl implements ICaseApplicationService { if (null == maxCaseNum) { caseNum = caseNum + "001"; } else { + maxCaseNum=maxCaseNum+1; caseNum = caseNum + String.format("%03d", maxCaseNum); } return caseNum; @@ -1133,9 +1096,6 @@ public class CaseApplicationServiceImpl implements ICaseApplicationService { // 修改记录表状态为已提交修改的内容 caseApplication.setUpdateSubmitStatus(UpdateSubmitStatus.COMMITTED.getCode()); } -// if(rows==0){ -// return rows; -// } List caseAffiliates = caseApplication.getCaseAffiliates(); if (caseAffiliates != null && caseAffiliates.size() > 0) { // 查询所有的组织机构,组装成map @@ -1191,20 +1151,12 @@ public class CaseApplicationServiceImpl implements ICaseApplicationService { && caseApplication.getCaseStatus() != null && caseApplication.getCaseStatus().equals(CaseApplicationConstants.CASE_APPLICATION)) { List filterList = caseAttachList.stream().filter(c -> c.getAnnexType().equals(2)).collect(Collectors.toList()); if (CollectionUtil.isNotEmpty(filterList)) { - // 先删除2的附件在新增 -// caseAttachMapper.deleteByCasedIdAndType(caseApplication.getId(),2,0); -// for (CaseAttach caseAttach : filterList) { -// caseAttach.setCaseAppliId(caseApplication.getId()); -// caseAttachMapper.save(caseAttach); -// } - for (CaseAttach caseAttach : caseAttachList) { caseAttach.setCaseAppliId(caseApplication.getId()); caseAttachMapper.updateCaseAttach(caseAttach); } } - } // 根据案件id查询最新版本号 Integer maxVersion = caseApplicationLogMapper.selectMaxVersionByCaseId(caseApplication.getId()); @@ -1439,23 +1391,20 @@ public class CaseApplicationServiceImpl implements ICaseApplicationService { @Override public CaseApplication selectCaseApplication(CaseApplication caseApplication) { CaseApplication caseApplicationselect = caseApplicationMapper.selectCaseApplication(caseApplication); + if(caseApplicationselect==null){ + throw new ServiceException("案件不存在"); + } CaseAffiliate caseAffiliate = new CaseAffiliate(); caseAffiliate.setCaseAppliId(caseApplication.getId()); ArbitrateRecord arbitrateRecord = new ArbitrateRecord(); arbitrateRecord.setCaseAppliId(caseApplication.getId()); ArbitrateRecord arbitrateRecordselect = arbitrateRecordMapper.selectArbitrateRecord(arbitrateRecord); - ColumnValue columnValue = new ColumnValue(); columnValue.setIsDefault(1); columnValue.setCaseId(caseApplication.getId()); List columnValueList = columnValueMapper.queryColumnValueList(columnValue); caseApplicationselect.setColumnValues(columnValueList); - -// CaseAttach caseAttachSelect = new CaseAttach(); -// caseAttachSelect.setCaseAppliId(caseApplication.getId()); -// caseAttachSelect.setAnnexType(2); - List caseAttachList = caseAttachMapper.queryCaseAttachList(caseApplication); if (caseAttachList != null && caseAttachList.size() > 0) { for (CaseAttach caseAttach : caseAttachList) { @@ -1502,7 +1451,6 @@ public class CaseApplicationServiceImpl implements ICaseApplicationService { ; } else if (identityType == 2) { respondentName.append(caseAffiliateselect.getName()).append(","); - ; } } caseApplicationselect.setApplicantName(applicantName.toString()); @@ -1533,9 +1481,9 @@ public class CaseApplicationServiceImpl implements ICaseApplicationService { List caseApplicationListinsert = new ArrayList<>(); for (int i = 0; i < caseApplicationList.size(); i++) { CaseApplication caseApplication = caseApplicationList.get(i); - + CaseImportValid caseImportValid = new CaseImportValid(caseApplication, deptMap); // 导入校验 - importValid(caseApplication, deptMap); + caseImportValid.importValid(caseApplication, deptMap); // 校验成功的数据 if (StrUtil.isEmpty(caseApplication.getErrorMsg())) { //根据仲裁费用计费规则计算应缴费用 @@ -1635,299 +1583,7 @@ public class CaseApplicationServiceImpl implements ICaseApplicationService { } - /** - * 导入校验 - * - * @param caseApplication - * @param - */ - private void importValid(CaseApplication caseApplication, Map deptMap) { - StringBuilder failureMsg = new StringBuilder(); - caseApplication.setErrorMsg(failureMsg); - // 校验基本字段 - validBaseColumn(caseApplication, failureMsg); - // 校验申请人信息 - validApplicationColumn(caseApplication, failureMsg); - // 校验申请人代理信息 - validApplicationAgentColumn(caseApplication, failureMsg, deptMap); - // 校验被申请人信息 - validDebtorApplicationColumn(caseApplication, failureMsg); - // 校验被申请人代理信息 - validDebtorApplicationAgentColumn(caseApplication, failureMsg); - } - /** - * 校验被申请人代理信息 - * - * @param caseApplication - * @param failureMsg - */ - private void validDebtorApplicationAgentColumn(CaseApplication caseApplication, StringBuilder failureMsg) { - if (StrUtil.isEmpty(caseApplication.getDebtorNameAgent())) { - failureMsg.append("【被申请人主体信息-代理人姓名】字段不能为空;"); - } else if (caseApplication.getDebtorNameAgent().length() > 50) { - failureMsg.append("【被申请人主体信息-代理人姓名】字段超出指定长度,最大长度为50;"); - } - if (StrUtil.isEmpty(caseApplication.getDebtorIdentityNumAgent())) { - failureMsg.append("【被申请人主体信息-代理人身份证号】字段不能为空;"); - } else if (!IdcardUtil.isValidCard((caseApplication.getDebtorIdentityNumAgent()))) { - failureMsg.append("【被申请人主体信息-代理人身份证号】不合法;"); - } - String debtorContactTelphoneAgent = caseApplication.getDebtorContactTelphoneAgent(); - if (StrUtil.isEmpty(debtorContactTelphoneAgent)) { - failureMsg.append("【被申请人主体信息-代理人联系电话】字段不能为空;"); - } else if (!TELEPHONE_REGX.matcher(debtorContactTelphoneAgent).matches()) { - failureMsg.append("【被申请人主体信息-代理人联系电话】字段不合法;"); - } - if (StrUtil.isEmpty(caseApplication.getDebtorContactAddressAgent())) { - failureMsg.append("【被申请人主体信息-代理人联系地址】字段不能为空;"); - } else if (caseApplication.getDebtorContactAddressAgent().length() > 50) { - failureMsg.append("【被申请人主体信息-代理人联系地址】字段超出指定长度,最大长度为50;"); - } - } - - /** - * 校验被申请人信息 - * - * @param caseApplication - * @param failureMsg - */ - private void validDebtorApplicationColumn(CaseApplication caseApplication, StringBuilder failureMsg) { - if (StrUtil.isEmpty(caseApplication.getDebtorName())) { - failureMsg.append("【被申请人主体信息-申请人姓名】字段不能为空;"); - } else if (caseApplication.getDebtorName().length() > 50) { - failureMsg.append("【被申请人主体信息-申请人姓名】字段超出指定长度,最大长度为50;"); - } - if (StrUtil.isEmpty(caseApplication.getDebtorIdentityNum())) { - failureMsg.append("【被申请人主体信息-身份证号】字段不能为空;"); - } else if (!IdcardUtil.isValidCard(caseApplication.getDebtorIdentityNum())) { - failureMsg.append("【被申请人主体信息-身份证号】不合法;"); - } - String debtorContactTelphone = caseApplication.getDebtorContactTelphone(); - if (StrUtil.isEmpty(debtorContactTelphone)) { - failureMsg.append("【被申请人主体信息-联系电话】字段不能为空;"); - } else if (!TELEPHONE_REGX.matcher(debtorContactTelphone).matches()) { - failureMsg.append("【被申请人主体信息-联系电话】字段不合法;"); - } - if (StrUtil.isEmpty(caseApplication.getDebtorContactAddress())) { - failureMsg.append("【被申请人主体信息-联系地址】字段不能为空;"); - } else if (caseApplication.getDebtorContactAddress().length() > 50) { - failureMsg.append("【被申请人主体信息-联系地址】字段超出指定长度,最大长度为50;"); - } - String debtorWorkTelphone = caseApplication.getDebtorWorkTelphone(); - if (StrUtil.isEmpty(debtorWorkTelphone)) { - failureMsg.append("【被申请人主体信息-单位电话】字段不能为空;"); - } else if (!TELEPHONE_REGX.matcher(debtorWorkTelphone).matches()) { - failureMsg.append("【被申请人主体信息-单位电话】字段不合法;"); - } - if (StrUtil.isEmpty(caseApplication.getDebtorWorkAddress())) { - failureMsg.append("【被申请人主体信息-单位地址】字段不能为空;"); - } else if (caseApplication.getDebtorWorkAddress().length() > 50) { - failureMsg.append("【被申请人主体信息-单位地址】字段超出指定长度,最大长度为50;"); - } - if (StrUtil.isEmpty(caseApplication.getResponSex())) { - failureMsg.append("【被申请人主体信息-性别】字段不能为空;"); - } else if (caseApplication.getResponSex().length() > 1) { - failureMsg.append("【被申请人主体信息-性别】字段超出指定长度,最大长度为1;"); - } - if (caseApplication.getResponBirth() == null) { - failureMsg.append("【被申请人主体信息-出生年月日】字段不合法;"); - } else if (caseApplication.getResponBirth().after(new Date())) { - failureMsg.append("【被申请人主体信息-出生年月日】字段不合法,不能超过当前日期;"); - } - if (StrUtil.isEmpty(caseApplication.getDebtorEmail())) { - failureMsg.append("【被申请人主体信息-邮箱】字段不能为空;"); - } else if (!EMAIL_PATTERN.matcher(caseApplication.getDebtorEmail()).matches()) { - - failureMsg.append("【被申请人主体信息-邮箱】字段不合法;"); - } - } - - /** - * 校验申请人代理信息 - * - * @param caseApplication - * @param failureMsg - */ - private void validApplicationAgentColumn(CaseApplication caseApplication, StringBuilder failureMsg, Map deptMap) { - if (StrUtil.isEmpty(caseApplication.getNameAgent())) { - failureMsg.append("【申请人主体信息-代理人姓名】字段不能为空;"); - } else if (caseApplication.getNameAgent().length() > 50) { - failureMsg.append("【申请人主体信息-代理人姓名】字段超出指定长度,最大长度为50;"); - } - if (StrUtil.isEmpty(caseApplication.getIdentityNumAgent())) { - failureMsg.append("【申请人主体信息-代理人身份证号】字段不能为空;"); - } else if (!IdcardUtil.isValidCard(caseApplication.getIdentityNumAgent())) { - failureMsg.append("【申请人主体信息-代理人身份证号】不合法;"); - } - validAgentInfo(caseApplication, failureMsg, deptMap); - String contactTelphoneAgent = caseApplication.getContactTelphoneAgent(); - if (StrUtil.isEmpty(contactTelphoneAgent)) { - failureMsg.append("【申请人主体信息-代理人联系电话】字段不能为空;"); - } else if (!TELEPHONE_REGX.matcher(contactTelphoneAgent).matches()) { - failureMsg.append("【申请人主体信息-代理人联系电话】字段不合法;"); - } - if (StrUtil.isEmpty(caseApplication.getContactAddressAgent())) { - failureMsg.append("【申请人主体信息-代理人联系地址】字段不能为空;"); - } else if (caseApplication.getContactAddressAgent().length() > 50) { - failureMsg.append("【申请人主体信息-代理人联系地址】字段超出指定长度,最大长度为50;"); - } - } - - /** - * 校验代理人与组织机构关系 - * - * @param caseApplication - * @param failureMsg - * @return - */ - private void validAgentInfo(CaseApplication caseApplication, StringBuilder failureMsg, Map deptMap) { - // 申请机构与代理人都不为空,校验代理人与组织机构关系(代理人必须在该部门下) - if (StrUtil.isNotEmpty(caseApplication.getName()) && StrUtil.isNotEmpty(caseApplication.getNameAgent())) { - String applicationOrganId = ""; - // 申请机构已经存在 - if (deptMap.containsKey(caseApplication.getName())) { - applicationOrganId = String.valueOf(deptMap.get(caseApplication.getName())); - } - // 根据代理人身份证去用户表查询 - SysUser agentUser = sysUserMapper.selectUserByIdCard(caseApplication.getIdentityNumAgent()); - // 代理人的部门和申请机构不匹配 - if (null != agentUser && null != agentUser.getDeptId() && !String.valueOf(agentUser.getDeptId()).equals(applicationOrganId)) { -// return "该申请代理人已在"+agentUser.getDeptName()+"申请机构下存在,请检查填写信息是否正确"; - if (null != agentUser.getDept() && StrUtil.isNotEmpty(agentUser.getDept().getDeptName())) { - failureMsg.append("该申请代理人已在【").append(agentUser.getDept().getDeptName()).append("】申请机构下存在,请检查填写信息是否正确"); - } else { - failureMsg.append("该申请代理人已存在,与申请机构不匹配,请检查填写信息是否正确"); - } - } - - } - } - - /** - * 校验申请人主题信息 - * - * @param caseApplication - * @param failureMsg - */ - private void validApplicationColumn(CaseApplication caseApplication, StringBuilder failureMsg) { - if (StrUtil.isEmpty(caseApplication.getName())) { - failureMsg.append("【申请人主体信息-申请人(机构)】字段不能为空;"); - } else if (caseApplication.getName().length() > 20) { - failureMsg.append("【申请人主体信息-申请人(机构)】字段超出指定长度,最大长度为20;"); - } - if (StrUtil.isNotEmpty(caseApplication.getIdentityNum()) && caseApplication.getIdentityNum().length() > 50) { - failureMsg.append("【申请人主体信息-代码】字段超出指定长度,最大长度为50;"); - } - String contactTelphone = caseApplication.getContactTelphone(); - if (StrUtil.isEmpty(contactTelphone)) { - failureMsg.append("【申请人主体信息-联系电话】字段不能为空;"); - } else if (!TELEPHONE_REGX.matcher(contactTelphone).matches()) { - failureMsg.append("【申请人主体信息-联系电话】字段不合法;"); - } - if (StrUtil.isEmpty(caseApplication.getContactAddress())) { - failureMsg.append("【申请人主体信息-联系地址】字段不能为空;"); - } else if (caseApplication.getName().length() > 50) { - failureMsg.append("【申请人主体信息-联系地址】字段超出指定长度,最大长度为50;"); - } - String workTelphone = caseApplication.getWorkTelphone(); - if (StrUtil.isEmpty(workTelphone)) { - failureMsg.append("【申请人主体信息-单位电话】字段不能为空;"); - } else if (!TELEPHONE_REGX.matcher(workTelphone).matches()) { - failureMsg.append("【申请人主体信息-单位电话】字段不合法;"); - } - if (StrUtil.isEmpty(caseApplication.getWorkAddress())) { - failureMsg.append("【申请人主体信息-单位地址】字段不能为空;"); - } else if (caseApplication.getWorkAddress().length() > 50) { - failureMsg.append("【申请人主体信息-单位地址】字段超出指定长度,最大长度为50;"); - } - if (StrUtil.isEmpty(caseApplication.getEmail())) { - failureMsg.append("【申请人主体信息-邮箱】字段不能为空;"); - } else if (!EMAIL_PATTERN.matcher(caseApplication.getEmail()).matches()) { - - failureMsg.append("【申请人主体信息-邮箱】字段不合法;"); - } - } - - /** - * 校验基本字段 - * - * @param caseApplication - * @param failureMsg - */ - private void validBaseColumn(CaseApplication caseApplication, StringBuilder failureMsg) { - if (StrUtil.isEmpty(caseApplication.getCaseName())) { - failureMsg.append("【案件名称】字段不能为空;"); - } else if (caseApplication.getCaseName().length() > 50) { - failureMsg.append("【案件名称】字段超出指定长度,最大长度为50;"); - } - BigDecimal caseSubjectAmount = caseApplication.getCaseSubjectAmount(); - if (null == caseSubjectAmount) { - failureMsg.append("【案件标的】字段不合法;"); - } else { - if (caseSubjectAmount.compareTo(new BigDecimal("0")) < 0 || caseSubjectAmount.compareTo(new BigDecimal("99999999.99")) > 0) { - failureMsg.append("【案件标的】字段超出范围,范围为[0,100000000);"); - } - if (caseSubjectAmount.scale() > 2) { - failureMsg.append("【案件标的】字段超出指定精度(10^-2);"); - } - } - if (caseApplication.getLoanStartDate() == null) { - failureMsg.append("【借款开始日期】字段不合法;"); - } - if (caseApplication.getLoanEndDate() == null) { - failureMsg.append("【借款结束日期】字段不合法;"); - } - if (caseApplication.getLoanStartDate() != null && caseApplication.getLoanEndDate() != null && caseApplication.getLoanStartDate().after(caseApplication.getLoanEndDate())) { - failureMsg.append("【借款结束日期】不能早于【借款开始日期】;"); - } - if (StrUtil.isEmpty(caseApplication.getContractNumber())) { - failureMsg.append("【合同编号】字段不能为空;"); - } else if (caseApplication.getContractNumber().length() > 50) { - failureMsg.append("【合同编号】字段超出指定长度,最大长度为50;"); - } - BigDecimal claimPrinciOwed = caseApplication.getClaimPrinciOwed(); - if (null == claimPrinciOwed) { - failureMsg.append("【申请人主张欠本金】字段不合法;"); - } else { - if (claimPrinciOwed.compareTo(new BigDecimal("0")) < 0 || claimPrinciOwed.compareTo(new BigDecimal("99999999.99")) > 0) { - failureMsg.append("【申请人主张欠本金】字段超出范围,范围为[0,100000000);"); - } - if (claimPrinciOwed.scale() > 2) { - failureMsg.append("【申请人主张欠本金】字段超出指定精度(10^-2);"); - } - } - BigDecimal claimInterestOwed = caseApplication.getClaimInterestOwed(); - if (null == claimInterestOwed) { - failureMsg.append("【申请人主张欠利息】字段不合法;"); - } else { - if (claimInterestOwed.compareTo(new BigDecimal("0")) < 0 || claimInterestOwed.compareTo(new BigDecimal("99999999.99")) > 0) { - failureMsg.append("【申请人主张欠利息】字段超出范围,范围为[0,100000000);"); - } - if (claimInterestOwed.scale() > 2) { - failureMsg.append("【申请人主张欠利息】字段超出指定精度(10^-2);"); - } - } - BigDecimal claimLiquidDamag = caseApplication.getClaimLiquidDamag(); - if (null == claimLiquidDamag) { - failureMsg.append("【申请人主张违约金】字段不合法;"); - } else { - if (claimLiquidDamag.compareTo(new BigDecimal("0")) < 0 || claimLiquidDamag.compareTo(new BigDecimal("99999999.99")) > 0) { - failureMsg.append("【申请人主张违约金】字段超出范围,范围为[0,100000000);"); - } - if (claimLiquidDamag.scale() > 2) { - failureMsg.append("【申请人主张违约金】字段超出指定精度(10^-2);"); - } - } - if (StrUtil.isEmpty(caseApplication.getArbitratClaims())) { - failureMsg.append("【申请人仲裁请求及事实和理由】字段不能为空;"); - } else if (caseApplication.getArbitratClaims().length() > 10000) { - failureMsg.append("【申请人仲裁请求及事实和理由】字段超出指定长度,最大长度为10000;"); - } - if (StrUtil.isNotEmpty(caseApplication.getArbitratClaims()) && caseApplication.getArbitratClaims().length() > 10000) { - failureMsg.append("【申请人请求仲裁庭裁决】字段超出指定长度,最大长度为10000;"); - } - } @Override @@ -2940,10 +2596,6 @@ public class CaseApplicationServiceImpl implements ICaseApplicationService { Map deptMap, Long roleId) { // 申请人信息 CaseAffiliate caseAffiliate = new CaseAffiliate(); - -// BeanUtils.copyBeanProp(caseApplication,caseAffiliate); -// BeanUtils.copyBeanProp(caseAffiliate,caseApplication); -// caseAffiliate.setIdentityType(1); caseAffiliate = buildApplicaInfo(caseApplication); // 申请人(机构),需要判断部门中是否存在,不存在则新增,当身份类型为1的时候,查询时需要根据名称查询组织机构 if (StrUtil.isNotEmpty(caseApplication.getName())) { @@ -3112,10 +2764,6 @@ public class CaseApplicationServiceImpl implements ICaseApplicationService { @Override public long createRoomId(Long caseId) { long roomId = generateRoomId(); - // 新增预约会议表 -// ReservedConference conference = new ReservedConference(caseId, SecurityUtils.getUserId(),roomId, -// null, null); -// reservedConferenceMapper.insert(conference); // 绑定案件与房间号 caseApplicationMapper.bindCaseId(caseId, String.valueOf(roomId)); return roomId; @@ -3194,508 +2842,18 @@ public class CaseApplicationServiceImpl implements ICaseApplicationService { @Transactional @Override public AjaxResult uploadCaseZipFile(MultipartFile file, Long templateId) { - if (file.isEmpty()) { - return AjaxResult.error("请选择要上传的文件"); - } - UUID uuid = UUID.randomUUID(); - // todo - String targetPath = "/home/ruoyi/uploadPath/upload/unzipFile/" + uuid + "/"; -// String targetPath = "D:/home/ruoyi/uploadPath/upload/unzipFile/"+uuid+ "/"; - File zipFile = null; - InputStream ins = null; - try { - ins = file.getInputStream(); - //上传的压缩包保存的路径 - // todo - String savePath = "/home/ruoyi/uploadPath/upload/zipFile/"; -// String savePath = "D:/home/ruoyi/uploadPath/upload/zipFile/"; - String saveName = uuid + "_" + file.getOriginalFilename(); - zipFile = new File(savePath + saveName); - inputChangeToFile(ins, zipFile); - } catch (IOException e) { - e.printStackTrace(); - } - //解压缩上传的压缩包 - boolean unzipSuccess = UnZipFileUtils.unZipFile(zipFile, targetPath); - if (!unzipSuccess) { - // 解压失败 - return AjaxResult.error("解压失败"); - } - // 查询抓取规则 - // todo 批次需要再上传压缩包时用户填写 - List fatchRuleList = fatchRuleMapper.listByTemplateId(templateId); - if (CollectionUtil.isEmpty(fatchRuleList)) { - return error("未设置抓取规则"); - } - File directory = new File(targetPath); - Map andConvertPDF = findAndConvertPDF(directory, fatchRuleList); - if (andConvertPDF == null || andConvertPDF.size() <= 0) { - // 解压失败 - return AjaxResult.error("未获取到文件"); - } - Map fatchMap = new HashMap<>(); - if (CollectionUtil.isNotEmpty(fatchRuleList)) { - Map> fatchRuleMap = fatchRuleList.stream().collect(Collectors.groupingBy(FatchRule::getFileName)); - // 根据抓取规则循环抓取 - for (Map.Entry> entry : fatchRuleMap.entrySet()) { - getFatchContent(andConvertPDF, entry.getKey(), fatchMap, entry.getValue()); - } - } - if (fatchMap.size() <= 0) { - return error("从压缩包中未抓取到内容,请检查抓取字段配置"); - } - // 组装案件内置字段主表内容 - CaseApplication caseApplication = new CaseApplication(); - caseApplication.setTemplateId(templateId); - //默认案件标的 todo 案件标的是什么,默认写死 - caseApplication.setCaseSubjectAmount(new BigDecimal(100000)); - // 从抓取规则表取字段和字典表取基本字段,字典表的字段名塞到基本表,is_default=1自定义字段塞到columnValue - // 抓取规则,0-内置字段,1-自定义字段 - Map> fatchRuleMap = fatchRuleList.stream().collect(Collectors.groupingBy(FatchRule::getIsDefault)); - // 自定义字段,组装columnValue表 - List columnValueList = new ArrayList<>(); - if (fatchRuleMap.size() > 0 && fatchRuleMap.containsKey(1)) { - List columnRules = fatchRuleMap.get(1); - columnRules.forEach(columnRule -> { - ColumnValue columnValue = new ColumnValue(); - columnValue.setColumn(columnRule.getColumn()); - columnValue.setName(columnRule.getColumnName()); - columnValue.setValue(fatchMap.get(columnRule.getColumnName())); - columnValue.setIsDefault(1); - columnValueList.add(columnValue); - }); - } - // 在系统表中查询案件内置字段 - SysDictData sysDictData = new SysDictData(); - sysDictData.setDictType("case_built_type"); - List dictDataList = dictDataMapper.selectDictDataList(sysDictData); - // 组装内置字段 - buildDefaultColumn(caseApplication, dictDataList, fatchMap); - // 设置批号 - if (StrUtil.isEmpty(caseApplication.getBatchNumber())) { - Integer maxBatchNumber = caseApplicationMapper.selectBatchNumberLike(); - if (maxBatchNumber == null) { - caseApplication.setBatchNumber("1"); - } else { - caseApplication.setBatchNumber(maxBatchNumber + 1 + ""); - } - } - List caseAttachs = new ArrayList<>(); - for (Map.Entry entry : andConvertPDF.entrySet()) { - String fileUrl = entry.getValue(); - if(StrUtil.isEmpty(fileUrl)){ - continue; - } - // 上传 - String filePath = RuoYiConfig.getUploadPath(); - - CaseAttach caseAttach = new CaseAttach(); - caseAttach.setCaseAppliId(caseApplication.getId()); - caseAttach.setAnnexPath(filePath); - if (StrUtil.isNotEmpty(fileUrl)) { - String fileName = fileUrl.replace(filePath, "/profile/upload"); - caseAttach.setAnnexName(fileName); - } - // 申请人提供的证据材料 - caseAttach.setAnnexType(2); - caseAttachs.add(caseAttach); - if(fileUrl.contains("仲裁申请书")){ - CaseAttach applyFile = new CaseAttach(); - BeanUtil.copyProperties(caseAttach,applyFile); - applyFile.setAnnexType(1); - caseAttachs.add(applyFile); - } - - } - caseApplication.setCaseAttachList(caseAttachs); - // 案件压缩包导入 - caseApplication.setImportFlag(2); - // 新增案件基本信息表 - this.insertcaseApplication(caseApplication, columnValueList); - - return AjaxResult.success("导入成功"); - - } - - - /** - * 组装内置字段 - * @param caseApplication 案件信息 - * @param dictDataList 内置字段 - * @param fatchMap 抓取字段内容 - */ - private void buildDefaultColumn(CaseApplication caseApplication, List dictDataList, Map fatchMap) { - // 组装内置字段 - if (CollectionUtil.isEmpty(dictDataList)) { - return; - } - List caseAffiliates = new ArrayList<>(); - CaseAffiliate debtorAffiliate = new CaseAffiliate(); - CaseAffiliate affiliate = new CaseAffiliate(); - for (SysDictData dictData : dictDataList) { - if (StrUtil.isNotEmpty(dictData.getDictLabel())) { - if(dictData.getDictLabel().contains("被申请人")) { - // 组装被申请人内置自段 - buildDebtorColumn(dictData, fatchMap, debtorAffiliate); - }else if( dictData.getDictLabel().contains("申请人")|| dictData.getDictLabel().contains("统一社会信用代码") - || dictData.getDictLabel().contains("法定代表人")|| dictData.getDictLabel().contains("委托代理人")) { - // 组装申请人内置自段 - buildAffilcateColumn(dictData, fatchMap, affiliate); - }else if( dictData.getDictLabel().contains("合同编号")) { - // 合同编号 - String contractNumber = fatchMap.get("合同编号"); - if (StrUtil.isNotEmpty(contractNumber)) { - // 提取字母和数字 - String regx = "[^a-zA-Z0-9]"; - String replaceAll = contractNumber.replaceAll(regx, ""); - caseApplication.setContractNumber(replaceAll.toUpperCase()); - } - }else { - ObjectFieldUtils.setValue(caseApplication, dictData.getDictValue(), fatchMap.get(dictData.getDictLabel())); - } - - } else { - ObjectFieldUtils.setValue(caseApplication, dictData.getDictValue(), fatchMap.get(dictData.getDictLabel())); - - } - - } - if(ObjectUtil.isNotEmpty(affiliate)){ - caseAffiliates.add(affiliate); - } - if(ObjectUtil.isNotEmpty(debtorAffiliate)){ - caseAffiliates.add(debtorAffiliate); - } - - caseApplication.setCaseAffiliates(caseAffiliates); - - } - /** - * 组装申请人内置字段 - * @param dictData 内置字段 - * @param fatchMap 抓取内容 - * @param affiliate 案件人员 - */ - private void buildAffilcateColumn(SysDictData dictData, Map fatchMap, CaseAffiliate affiliate) { - - affiliate.setIdentityType(1); - - // 申请人 - switch (dictData.getDictLabel()) { - case "申请人姓名": - affiliate.setName((fatchMap.get(dictData.getDictLabel()))); - break; - case "统一社会信用代码": - affiliate.setIdentityNum((fatchMap.get(dictData.getDictLabel()))); - break; - case "法定代表人": - affiliate.setCompLegalPerson(fatchMap.get(dictData.getDictLabel())); - break; - case "法定代表人职位": - affiliate.setCompLegalperPost((fatchMap.get(dictData.getDictLabel()))); - break; - case "申请人住所": - affiliate.setResidenAffili((fatchMap.get(dictData.getDictLabel()))); - break; - case "申请人联系地址": - affiliate.setContactAddress(fatchMap.get(dictData.getDictLabel())); - break; - case "委托代理人姓名": - affiliate.setNameAgent(fatchMap.get(dictData.getDictLabel())); - break; - case "委托代理人联系电话": - affiliate.setContactTelphoneAgent(fatchMap.get(dictData.getDictLabel())); - break; - case "委托代理人电子邮件": - affiliate.setAgentEmail(StrUtil.isNotEmpty(fatchMap.get(dictData.getDictLabel())) ? fatchMap.get(dictData.getDictLabel()).replace("\n","").replaceAll("\\s", "") : null); - - break; - default: - break; + CaseApplication caseApplication=null; + AjaxResult ajaxResult = caseZipImportImpl.zipImport( file, templateId); + if(ajaxResult.isSuccess()&&caseApplication!=null) { + // 新增案件基本信息表 + this.insertcaseApplication(caseApplication); + return success("导入成功"); + }else { + return ajaxResult; } } - /** - * 组装被申请人内置字段 - * @param dictData 内置字段 - * @param fatchMap 抓取内容 - * @param debtorAffiliate 被申请人 - */ - private void buildDebtorColumn(SysDictData dictData, Map fatchMap, CaseAffiliate debtorAffiliate) { - debtorAffiliate.setIdentityType(2); - // 被申请人 - switch (dictData.getDictLabel()) { - case "被申请人姓名": - debtorAffiliate.setName(fatchMap.get(dictData.getDictLabel())); - break; - case "被申请人身份证号": - String identityNum = fatchMap.get(dictData.getDictLabel()); - debtorAffiliate.setIdentityNum(fatchMap.get(dictData.getDictLabel())); - // 出生年月日,从身份证抓取 - if (StrUtil.isNotEmpty(identityNum)) { - identityNum=identityNum.replace("\n",""); - Map identityNumMap = getBirAgeSex(identityNum); - String birthday = identityNumMap.get("birthday"); - if (StrUtil.isNotEmpty(birthday)) { - SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd"); - Date birthdayDate = null; - try { - birthdayDate = simpleDateFormat.parse(birthday); - } catch (Exception e) { - e.printStackTrace(); - } - debtorAffiliate.setResponBirth(birthdayDate); - } - //从身份证抓取性别 - debtorAffiliate.setResponSex(identityNumMap.get("sexCode")); - } - - break; - case "被申请人住所": - debtorAffiliate.setResidenAffili(fatchMap.get(dictData.getDictLabel())); - break; - case "被申请人联系电话": - debtorAffiliate.setContactTelphone(fatchMap.get(dictData.getDictLabel())); - break; - case "被申请人电子邮件": - debtorAffiliate.setEmail(StrUtil.isNotEmpty(fatchMap.get(dictData.getDictLabel())) ? fatchMap.get(dictData.getDictLabel()).replace("\n","").replaceAll("\\s", "") : null); - - break; - default: - break; - } - - } - - /** - * 金额格式化,增加千分位 - * @param money - * @return - */ - private String moneyFormat(String money) { - // 金额格式化 - try { - Double.parseDouble(money); - - } catch (NumberFormatException e) { - - String regEx = "[^0-9]"; - Pattern p = Pattern.compile(regEx); - Matcher m = p.matcher(money); - String result = m.replaceAll("").trim(); - BigDecimal bigDecimal = null; - if (money.contains("百")) { - bigDecimal = new BigDecimal(result).multiply(new BigDecimal("100")); - } else if (money.contains("千")) { - bigDecimal = new BigDecimal(result).multiply(new BigDecimal("1000")); - } else if (money.contains("万")) { - bigDecimal = new BigDecimal(result).multiply(new BigDecimal("10000")); - } else if (money.contains("百万")) { - bigDecimal = new BigDecimal(result).multiply(new BigDecimal("1000000")); - } else if (money.contains("千万")) { - bigDecimal = new BigDecimal(result).multiply(new BigDecimal("10000000")); - } else if (money.contains("亿")) { - bigDecimal = new BigDecimal(result).multiply(new BigDecimal("100000000")); - } - - NumberFormat format = NumberFormat.getInstance(); - return format.format(bigDecimal); - - } - return ""; - } - - - - /** - * 新增动态配置字段值表 - * @param fatchMap - * @param caseApplicId - */ - private void insertColumnValue(Map fatchMap, Long caseApplicId) { - if(fatchMap==null){ - return; - } - // 新增到动态配置字段表 - List columnValueList=new ArrayList<>(); - // todo 新增完案件信息表后这样改 - - fatchMap.forEach((key,value)->{ - ColumnValue columnValue = new ColumnValue(); - columnValue.setCaseId(caseApplicId); - columnValue.setColumn(key); - columnValue.setValue(value); - // todo 组装的map中的key需要column+@+columnName拼接 - columnValue.setName(""); - columnValueList.add(columnValue); - }); - if(CollectionUtil.isNotEmpty(columnValueList)){ - // 批量新增 - columnValueMapper.batchSave(columnValueList); - } - } - - public static String readerTxtFile(String filePath){ - BufferedReader br=null; - StringBuilder result=new StringBuilder(); - try { - br = new BufferedReader(new InputStreamReader(new FileInputStream(new File(filePath)),"GBK")); - String line=null; - while ((line=br.readLine())!=null) { - result.append(line).append("\n"); - } - } catch (IOException e) { - e.printStackTrace(); - } finally { - if (null!=br){ - try { - br.close(); - } catch (IOException e) { - e.printStackTrace(); - } - } - } - return result.toString(); - } - public static String readWord(String filePath) throws Exception{ - - File file = new File(filePath); - if(file.length()==0) return ""; // 需要操作原因是可能会空文件问题,如果不做处理,在下面读取中会报错 - StringBuffer sb = new StringBuffer(); - String buffer = ""; - try { - if (filePath.endsWith(".doc")) { - InputStream is = new FileInputStream(file); - WordExtractor ex = new WordExtractor(is); - buffer = ex.getText(); - if(buffer.length() > 0){ - //使用回车换行符分割字符串 - String [] arry = buffer.split("r\\n"); - for (String string : arry) { - sb.append(string.trim()); - } - } - } else if (filePath.endsWith(".docx")) { - FileInputStream fis = new FileInputStream(file); - XWPFDocument xdoc = new XWPFDocument(fis); - XWPFWordExtractor extractor = new XWPFWordExtractor(xdoc); - buffer = extractor.getText(); - sb.append(buffer!=null?buffer:""); - - -// OPCPackage opcPackage = POIXMLDocument.openPackage(filePath); -// XWPFWordExtractor extractor = new XWPFWordExtractor(opcPackage); -// buffer = extractor.getText(); -// if(buffer.length() > 0){ -// //使用换行符分割字符串 -// String [] arry = buffer.split("\n"); -// for (String string : arry) { -// sb.append(string.trim()); -// } -// } - } else { - return null; - } - return sb.toString(); - } catch (Exception e) { - System.out.print("error---->"+filePath); - e.printStackTrace(); - return null; - } - } - - /** - * 获取抓取内容 - * @param andConvertPDF 文件路径map - * @param mapKey 文件名 - * @param map 抓取内容map - * @param fatchRules 抓取规则 - */ - private void getFatchContent(Map andConvertPDF, String mapKey, Map map, List fatchRules) { - String fileURL = andConvertPDF.get(mapKey); - if (StrUtil.isEmpty(fileURL)) { - return; - } - if (fileURL.endsWith("txt")) { - String readerFile = readerTxtFile(fileURL); - OCRUtils.fatchRuleGetContent(readerFile, fatchRules, map); - } else if (fileURL.endsWith("doc") || fileURL.endsWith("docx")) { - // doc,docx,text识别内容 - String readerFile = null; - try { - readerFile = readWord(fileURL); - } catch (Exception e) { - e.printStackTrace(); - } - OCRUtils.fatchRuleGetContent(readerFile, fatchRules, map); - - } else if (fileURL.endsWith("pdf")) { - //获取文件的页数 - int fileNumPage = getFileNumPage(fileURL); - //文件转成base64 - String base64 = OCRUtils.pdfConvertBase64(fileURL); - if (base64 == null) { - throw new ServiceException("pdf转base64失败"); - // return false; - } - StringBuilder ocrText = new StringBuilder(); // 创建一个StringBuilder对象 - for (int i = 1; i <= fileNumPage; i++) { - //对接腾讯云接口.识别里面的数据 - String text = OCRUtils.pdfIdentifyText(base64, i, fatchRules); - ocrText.append(text); // 拼接当前的字符串 - // 根据抓取规则截取内容 - OCRUtils.fatchRuleGetContent(ocrText.toString(), fatchRules, map); - - } - } - - - } - - /** - * 通过身份证号码获取出生日期、性别、年龄 - * @param certificateNo - * @return 返回的出生日期格式:1990-01-01 性别格式:1-女,0-男 - */ - public static Map getBirAgeSex(String certificateNo) { - String birthday = ""; - String age = ""; - String sexCode = ""; - - int year = Calendar.getInstance().get(Calendar.YEAR); - char[] number = certificateNo.toCharArray(); - boolean flag = true; - if (number.length == 15) { - for (int x = 0; x < number.length; x++) { - if (!flag) return new HashMap(); - flag = Character.isDigit(number[x]); - } - } else if (number.length == 18) { - for (int x = 0; x < number.length - 1; x++) { - if (!flag) return new HashMap(); - flag = Character.isDigit(number[x]); - } - } - if (flag && certificateNo.length() == 15) { - birthday = "19" + certificateNo.substring(6, 8) + "-" - + certificateNo.substring(8, 10) + "-" - + certificateNo.substring(10, 12); - sexCode = Integer.parseInt(certificateNo.substring(certificateNo.length() - 3, certificateNo.length())) % 2 == 0 ? "1" : "0"; - age = (year - Integer.parseInt("19" + certificateNo.substring(6, 8))) + ""; - } else if (flag && certificateNo.length() == 18) { - birthday = certificateNo.substring(6, 10) + "-" - + certificateNo.substring(10, 12) + "-" - + certificateNo.substring(12, 14); - sexCode = Integer.parseInt(certificateNo.substring(certificateNo.length() - 4, certificateNo.length() - 1)) % 2 == 0 ? "1" : "0"; - age = (year - Integer.parseInt(certificateNo.substring(6, 10))) + ""; - } - Map map = new HashMap(); - map.put("birthday", birthday); - map.put("age", age); - map.put("sexCode", sexCode); - return map; - } /** * 根据附件id修改案件id @@ -3709,125 +2867,6 @@ public class CaseApplicationServiceImpl implements ICaseApplicationService { } - public static Map findAndConvertPDF(File directory, List fatchRuleList ) { - Map pdfPathMap= new HashMap<>(); - if (directory.isFile()) { - String path = ""; - // 如果传入的参数是一个文件 - path = directory.getAbsolutePath(); - pdfPathMap.put(directory.getName(), path); - - } else if (directory.isDirectory()) { - searchAndConvertPDF(directory, pdfPathMap); - } else { - return null; - } - return pdfPathMap; - } - public static boolean isPDF(File file) { - String extension = getFileExtension(file); - return extension.equalsIgnoreCase("pdf"); - } - - public static String getFileExtension(File file) { - String name = file.getName(); - int lastIndexOfDot = name.lastIndexOf("."); - if (lastIndexOfDot != -1 && lastIndexOfDot < name.length() - 1) { - return name.substring(lastIndexOfDot + 1); - } else { - return ""; - } - } - - public static void searchAndConvertPDF(File directory, Map pdfPathMap) { - File[] files = directory.listFiles(); - if (files != null) { - for (File file : files) { - if(file.getName().contains("zip")|| file.getName().contains("rar")){ - continue; - } - if (file.isFile()) { - - pdfPathMap.put(file.getName(),file.getAbsolutePath()); - } else if (file.isDirectory()) { - // 如果是目录,递归查找 - searchAndConvertPDF(file, pdfPathMap); - } - } - } - } - - - private static int getFileNumPage(String pdfUrl) { - File pdfFile = new File(pdfUrl); - int pageCount = 0; - try (PDDocument document = PDDocument.load(pdfFile)) { - pageCount = document.getNumberOfPages(); - } catch (IOException e) { - e.printStackTrace(); - } - return pageCount; - } - - /** - * 获取模板和正文中替换符的内容 - * @param a - * @param b - * @return - */ - public static List getReplaceList(String a,String b){ - String aTmpe = filterString(a); - String bTmpe = filterString(b); - String regex = "(\\{[^}}]*})"; - String[] ptTemplate = aTmpe.replaceAll(regex, "@=").split("@="); - String replace = ""; - for (int i = 0; i < ptTemplate.length; i++) { - if(ptTemplate[i]==null || ptTemplate[i].equals(" "))continue; - if(replace.equals("")){ - replace = bTmpe.replace(ptTemplate[i], "@="); - }else { - replace = replace.replace(ptTemplate[i], "@="); - } - } - List aList = new ArrayList<>(); - String[] split = replace.split("@="); - for (int i =0; i deptMap; + // 手机号正则 + private static final Pattern TELEPHONE_REGX = Pattern.compile("^1(3\\d|4[5-9]|5[0-35-9]|6[2567]|7[0-8]|8\\d|9[0-35-9])\\d{8}$"); + // 邮箱正则 + private static final Pattern EMAIL_PATTERN = Pattern.compile("^[a-zA-Z0-9_+&*-]+(?:\\.[a-zA-Z0-9_+&*-]+)*@(?:[a-zA-Z0-9-]+\\.)+[a-zA-Z]{2,7}$"); + private static SysUserMapper sysUserMapper= SpringUtil.getBean(SysUserMapper.class); + + /** + * 导入校验 + * + * @param caseApplication + * @param + */ + public void importValid(CaseApplication caseApplication, Map deptMap) { + StringBuilder failureMsg = new StringBuilder(); + caseApplication.setErrorMsg(failureMsg); + // 校验基本字段 + validBaseColumn(caseApplication, failureMsg); + // 校验申请人信息 + validApplicationColumn(caseApplication, failureMsg); + // 校验申请人代理信息 + validApplicationAgentColumn(caseApplication, failureMsg, deptMap); + // 校验被申请人信息 + validDebtorApplicationColumn(caseApplication, failureMsg); + // 校验被申请人代理信息 + validDebtorApplicationAgentColumn(caseApplication, failureMsg); + } + + /** + * 校验被申请人代理信息 + * + * @param caseApplication + * @param failureMsg + */ + private void validDebtorApplicationAgentColumn(CaseApplication caseApplication, StringBuilder failureMsg) { + if (StrUtil.isEmpty(caseApplication.getDebtorNameAgent())) { + failureMsg.append("【被申请人主体信息-代理人姓名】字段不能为空;"); + } else if (caseApplication.getDebtorNameAgent().length() > 50) { + failureMsg.append("【被申请人主体信息-代理人姓名】字段超出指定长度,最大长度为50;"); + } + if (StrUtil.isEmpty(caseApplication.getDebtorIdentityNumAgent())) { + failureMsg.append("【被申请人主体信息-代理人身份证号】字段不能为空;"); + } else if (!IdcardUtil.isValidCard((caseApplication.getDebtorIdentityNumAgent()))) { + failureMsg.append("【被申请人主体信息-代理人身份证号】不合法;"); + } + String debtorContactTelphoneAgent = caseApplication.getDebtorContactTelphoneAgent(); + if (StrUtil.isEmpty(debtorContactTelphoneAgent)) { + failureMsg.append("【被申请人主体信息-代理人联系电话】字段不能为空;"); + } else if (!TELEPHONE_REGX.matcher(debtorContactTelphoneAgent).matches()) { + failureMsg.append("【被申请人主体信息-代理人联系电话】字段不合法;"); + } + if (StrUtil.isEmpty(caseApplication.getDebtorContactAddressAgent())) { + failureMsg.append("【被申请人主体信息-代理人联系地址】字段不能为空;"); + } else if (caseApplication.getDebtorContactAddressAgent().length() > 50) { + failureMsg.append("【被申请人主体信息-代理人联系地址】字段超出指定长度,最大长度为50;"); + } + } + + /** + * 校验被申请人信息 + * + * @param caseApplication + * @param failureMsg + */ + private void validDebtorApplicationColumn(CaseApplication caseApplication, StringBuilder failureMsg) { + if (StrUtil.isEmpty(caseApplication.getDebtorName())) { + failureMsg.append("【被申请人主体信息-申请人姓名】字段不能为空;"); + } else if (caseApplication.getDebtorName().length() > 50) { + failureMsg.append("【被申请人主体信息-申请人姓名】字段超出指定长度,最大长度为50;"); + } + if (StrUtil.isEmpty(caseApplication.getDebtorIdentityNum())) { + failureMsg.append("【被申请人主体信息-身份证号】字段不能为空;"); + } else if (!IdcardUtil.isValidCard(caseApplication.getDebtorIdentityNum())) { + failureMsg.append("【被申请人主体信息-身份证号】不合法;"); + } + String debtorContactTelphone = caseApplication.getDebtorContactTelphone(); + if (StrUtil.isEmpty(debtorContactTelphone)) { + failureMsg.append("【被申请人主体信息-联系电话】字段不能为空;"); + } else if (!TELEPHONE_REGX.matcher(debtorContactTelphone).matches()) { + failureMsg.append("【被申请人主体信息-联系电话】字段不合法;"); + } + if (StrUtil.isEmpty(caseApplication.getDebtorContactAddress())) { + failureMsg.append("【被申请人主体信息-联系地址】字段不能为空;"); + } else if (caseApplication.getDebtorContactAddress().length() > 50) { + failureMsg.append("【被申请人主体信息-联系地址】字段超出指定长度,最大长度为50;"); + } + String debtorWorkTelphone = caseApplication.getDebtorWorkTelphone(); + if (StrUtil.isEmpty(debtorWorkTelphone)) { + failureMsg.append("【被申请人主体信息-单位电话】字段不能为空;"); + } else if (!TELEPHONE_REGX.matcher(debtorWorkTelphone).matches()) { + failureMsg.append("【被申请人主体信息-单位电话】字段不合法;"); + } + if (StrUtil.isEmpty(caseApplication.getDebtorWorkAddress())) { + failureMsg.append("【被申请人主体信息-单位地址】字段不能为空;"); + } else if (caseApplication.getDebtorWorkAddress().length() > 50) { + failureMsg.append("【被申请人主体信息-单位地址】字段超出指定长度,最大长度为50;"); + } + if (StrUtil.isEmpty(caseApplication.getResponSex())) { + failureMsg.append("【被申请人主体信息-性别】字段不能为空;"); + } else if (caseApplication.getResponSex().length() > 1) { + failureMsg.append("【被申请人主体信息-性别】字段超出指定长度,最大长度为1;"); + } + if (caseApplication.getResponBirth() == null) { + failureMsg.append("【被申请人主体信息-出生年月日】字段不合法;"); + } else if (caseApplication.getResponBirth().after(new Date())) { + failureMsg.append("【被申请人主体信息-出生年月日】字段不合法,不能超过当前日期;"); + } + if (StrUtil.isEmpty(caseApplication.getDebtorEmail())) { + failureMsg.append("【被申请人主体信息-邮箱】字段不能为空;"); + } else if (!EMAIL_PATTERN.matcher(caseApplication.getDebtorEmail()).matches()) { + + failureMsg.append("【被申请人主体信息-邮箱】字段不合法;"); + } + } + + /** + * 校验申请人代理信息 + * + * @param caseApplication + * @param failureMsg + */ + private void validApplicationAgentColumn(CaseApplication caseApplication, StringBuilder failureMsg, Map deptMap) { + if (StrUtil.isEmpty(caseApplication.getNameAgent())) { + failureMsg.append("【申请人主体信息-代理人姓名】字段不能为空;"); + } else if (caseApplication.getNameAgent().length() > 50) { + failureMsg.append("【申请人主体信息-代理人姓名】字段超出指定长度,最大长度为50;"); + } + if (StrUtil.isEmpty(caseApplication.getIdentityNumAgent())) { + failureMsg.append("【申请人主体信息-代理人身份证号】字段不能为空;"); + } else if (!IdcardUtil.isValidCard(caseApplication.getIdentityNumAgent())) { + failureMsg.append("【申请人主体信息-代理人身份证号】不合法;"); + } + validAgentInfo(caseApplication, failureMsg, deptMap); + String contactTelphoneAgent = caseApplication.getContactTelphoneAgent(); + if (StrUtil.isEmpty(contactTelphoneAgent)) { + failureMsg.append("【申请人主体信息-代理人联系电话】字段不能为空;"); + } else if (!TELEPHONE_REGX.matcher(contactTelphoneAgent).matches()) { + failureMsg.append("【申请人主体信息-代理人联系电话】字段不合法;"); + } + if (StrUtil.isEmpty(caseApplication.getContactAddressAgent())) { + failureMsg.append("【申请人主体信息-代理人联系地址】字段不能为空;"); + } else if (caseApplication.getContactAddressAgent().length() > 50) { + failureMsg.append("【申请人主体信息-代理人联系地址】字段超出指定长度,最大长度为50;"); + } + } + + /** + * 校验代理人与组织机构关系 + * + * @param caseApplication + * @param failureMsg + * @return + */ + private void validAgentInfo(CaseApplication caseApplication, StringBuilder failureMsg, Map deptMap) { + // 申请机构与代理人都不为空,校验代理人与组织机构关系(代理人必须在该部门下) + if (StrUtil.isNotEmpty(caseApplication.getName()) && StrUtil.isNotEmpty(caseApplication.getNameAgent())) { + String applicationOrganId = ""; + // 申请机构已经存在 + if (deptMap.containsKey(caseApplication.getName())) { + applicationOrganId = String.valueOf(deptMap.get(caseApplication.getName())); + } + // 根据代理人身份证去用户表查询 + SysUser agentUser = sysUserMapper.selectUserByIdCard(caseApplication.getIdentityNumAgent()); + // 代理人的部门和申请机构不匹配 + if (null != agentUser && null != agentUser.getDeptId() && !String.valueOf(agentUser.getDeptId()).equals(applicationOrganId)) { +// return "该申请代理人已在"+agentUser.getDeptName()+"申请机构下存在,请检查填写信息是否正确"; + if (null != agentUser.getDept() && StrUtil.isNotEmpty(agentUser.getDept().getDeptName())) { + failureMsg.append("该申请代理人已在【").append(agentUser.getDept().getDeptName()).append("】申请机构下存在,请检查填写信息是否正确"); + } else { + failureMsg.append("该申请代理人已存在,与申请机构不匹配,请检查填写信息是否正确"); + } + } + + } + } + + /** + * 校验申请人主题信息 + * + * @param caseApplication + * @param failureMsg + */ + private void validApplicationColumn(CaseApplication caseApplication, StringBuilder failureMsg) { + if (StrUtil.isEmpty(caseApplication.getName())) { + failureMsg.append("【申请人主体信息-申请人(机构)】字段不能为空;"); + } else if (caseApplication.getName().length() > 20) { + failureMsg.append("【申请人主体信息-申请人(机构)】字段超出指定长度,最大长度为20;"); + } + if (StrUtil.isNotEmpty(caseApplication.getIdentityNum()) && caseApplication.getIdentityNum().length() > 50) { + failureMsg.append("【申请人主体信息-代码】字段超出指定长度,最大长度为50;"); + } + String contactTelphone = caseApplication.getContactTelphone(); + if (StrUtil.isEmpty(contactTelphone)) { + failureMsg.append("【申请人主体信息-联系电话】字段不能为空;"); + } else if (!TELEPHONE_REGX.matcher(contactTelphone).matches()) { + failureMsg.append("【申请人主体信息-联系电话】字段不合法;"); + } + if (StrUtil.isEmpty(caseApplication.getContactAddress())) { + failureMsg.append("【申请人主体信息-联系地址】字段不能为空;"); + } else if (caseApplication.getName().length() > 50) { + failureMsg.append("【申请人主体信息-联系地址】字段超出指定长度,最大长度为50;"); + } + String workTelphone = caseApplication.getWorkTelphone(); + if (StrUtil.isEmpty(workTelphone)) { + failureMsg.append("【申请人主体信息-单位电话】字段不能为空;"); + } else if (!TELEPHONE_REGX.matcher(workTelphone).matches()) { + failureMsg.append("【申请人主体信息-单位电话】字段不合法;"); + } + if (StrUtil.isEmpty(caseApplication.getWorkAddress())) { + failureMsg.append("【申请人主体信息-单位地址】字段不能为空;"); + } else if (caseApplication.getWorkAddress().length() > 50) { + failureMsg.append("【申请人主体信息-单位地址】字段超出指定长度,最大长度为50;"); + } + if (StrUtil.isEmpty(caseApplication.getEmail())) { + failureMsg.append("【申请人主体信息-邮箱】字段不能为空;"); + } else if (!EMAIL_PATTERN.matcher(caseApplication.getEmail()).matches()) { + + failureMsg.append("【申请人主体信息-邮箱】字段不合法;"); + } + } + + /** + * 校验基本字段 + * + * @param caseApplication + * @param failureMsg + */ + private void validBaseColumn(CaseApplication caseApplication, StringBuilder failureMsg) { + if (StrUtil.isEmpty(caseApplication.getCaseName())) { + failureMsg.append("【案件名称】字段不能为空;"); + } else if (caseApplication.getCaseName().length() > 50) { + failureMsg.append("【案件名称】字段超出指定长度,最大长度为50;"); + } + BigDecimal caseSubjectAmount = caseApplication.getCaseSubjectAmount(); + if (null == caseSubjectAmount) { + failureMsg.append("【案件标的】字段不合法;"); + } else { + if (caseSubjectAmount.compareTo(new BigDecimal("0")) < 0 || caseSubjectAmount.compareTo(new BigDecimal("99999999.99")) > 0) { + failureMsg.append("【案件标的】字段超出范围,范围为[0,100000000);"); + } + if (caseSubjectAmount.scale() > 2) { + failureMsg.append("【案件标的】字段超出指定精度(10^-2);"); + } + } + if (caseApplication.getLoanStartDate() == null) { + failureMsg.append("【借款开始日期】字段不合法;"); + } + if (caseApplication.getLoanEndDate() == null) { + failureMsg.append("【借款结束日期】字段不合法;"); + } + if (caseApplication.getLoanStartDate() != null && caseApplication.getLoanEndDate() != null && caseApplication.getLoanStartDate().after(caseApplication.getLoanEndDate())) { + failureMsg.append("【借款结束日期】不能早于【借款开始日期】;"); + } + if (StrUtil.isEmpty(caseApplication.getContractNumber())) { + failureMsg.append("【合同编号】字段不能为空;"); + } else if (caseApplication.getContractNumber().length() > 50) { + failureMsg.append("【合同编号】字段超出指定长度,最大长度为50;"); + } + BigDecimal claimPrinciOwed = caseApplication.getClaimPrinciOwed(); + if (null == claimPrinciOwed) { + failureMsg.append("【申请人主张欠本金】字段不合法;"); + } else { + if (claimPrinciOwed.compareTo(new BigDecimal("0")) < 0 || claimPrinciOwed.compareTo(new BigDecimal("99999999.99")) > 0) { + failureMsg.append("【申请人主张欠本金】字段超出范围,范围为[0,100000000);"); + } + if (claimPrinciOwed.scale() > 2) { + failureMsg.append("【申请人主张欠本金】字段超出指定精度(10^-2);"); + } + } + BigDecimal claimInterestOwed = caseApplication.getClaimInterestOwed(); + if (null == claimInterestOwed) { + failureMsg.append("【申请人主张欠利息】字段不合法;"); + } else { + if (claimInterestOwed.compareTo(new BigDecimal("0")) < 0 || claimInterestOwed.compareTo(new BigDecimal("99999999.99")) > 0) { + failureMsg.append("【申请人主张欠利息】字段超出范围,范围为[0,100000000);"); + } + if (claimInterestOwed.scale() > 2) { + failureMsg.append("【申请人主张欠利息】字段超出指定精度(10^-2);"); + } + } + BigDecimal claimLiquidDamag = caseApplication.getClaimLiquidDamag(); + if (null == claimLiquidDamag) { + failureMsg.append("【申请人主张违约金】字段不合法;"); + } else { + if (claimLiquidDamag.compareTo(new BigDecimal("0")) < 0 || claimLiquidDamag.compareTo(new BigDecimal("99999999.99")) > 0) { + failureMsg.append("【申请人主张违约金】字段超出范围,范围为[0,100000000);"); + } + if (claimLiquidDamag.scale() > 2) { + failureMsg.append("【申请人主张违约金】字段超出指定精度(10^-2);"); + } + } + if (StrUtil.isEmpty(caseApplication.getArbitratClaims())) { + failureMsg.append("【申请人仲裁请求及事实和理由】字段不能为空;"); + } else if (caseApplication.getArbitratClaims().length() > 10000) { + failureMsg.append("【申请人仲裁请求及事实和理由】字段超出指定长度,最大长度为10000;"); + } + if (StrUtil.isNotEmpty(caseApplication.getArbitratClaims()) && caseApplication.getArbitratClaims().length() > 10000) { + failureMsg.append("【申请人请求仲裁庭裁决】字段超出指定长度,最大长度为10000;"); + } + } +} diff --git a/ruoyi-system/src/main/java/com/ruoyi/wisdomarbitrate/service/impl/CaseZipImportImpl.java b/ruoyi-system/src/main/java/com/ruoyi/wisdomarbitrate/service/impl/CaseZipImportImpl.java new file mode 100644 index 0000000..36d3701 --- /dev/null +++ b/ruoyi-system/src/main/java/com/ruoyi/wisdomarbitrate/service/impl/CaseZipImportImpl.java @@ -0,0 +1,811 @@ +package com.ruoyi.wisdomarbitrate.service.impl; + +import cn.hutool.core.bean.BeanUtil; +import cn.hutool.core.collection.CollectionUtil; +import cn.hutool.core.util.ObjectUtil; +import cn.hutool.core.util.StrUtil; +import com.ruoyi.common.constant.CaseApplicationConstants; +import com.ruoyi.common.constant.Constants; +import com.ruoyi.common.core.domain.entity.SysDept; +import com.ruoyi.common.core.domain.entity.SysRole; +import com.ruoyi.common.core.domain.entity.SysUser; +import com.ruoyi.common.enums.UpdateSubmitStatus; +import com.ruoyi.common.utils.*; +import com.ruoyi.common.config.RuoYiConfig; +import com.ruoyi.common.core.domain.AjaxResult; +import com.ruoyi.common.core.domain.entity.SysDictData; +import com.ruoyi.common.exception.ServiceException; +import com.ruoyi.common.utils.file.FileUtils; +import com.ruoyi.common.utils.thread.MultipleThreadListParam; +import com.ruoyi.common.utils.thread.MultipleThreadWorkUtil; +import com.ruoyi.system.domain.SysUserRole; +import com.ruoyi.system.mapper.*; +import com.ruoyi.wisdomarbitrate.domain.CaseAffiliate; +import com.ruoyi.wisdomarbitrate.domain.CaseApplication; +import com.ruoyi.wisdomarbitrate.domain.CaseAttach; +import com.ruoyi.wisdomarbitrate.domain.FatchRule; +import com.ruoyi.wisdomarbitrate.domain.vo.ColumnValue; +import com.ruoyi.wisdomarbitrate.mapper.*; +import com.ruoyi.wisdomarbitrate.utils.OCRUtils; +import com.ruoyi.wisdomarbitrate.utils.UnZipFileUtils; +import org.apache.pdfbox.pdmodel.PDDocument; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; +import org.springframework.web.multipart.MultipartFile; + +import java.io.*; +import java.math.BigDecimal; +import java.text.SimpleDateFormat; +import java.util.*; +import java.util.function.Function; +import java.util.regex.Matcher; +import java.util.regex.Pattern; +import java.util.stream.Collectors; + +import static com.ruoyi.common.core.domain.AjaxResult.error; +import static com.ruoyi.common.core.domain.AjaxResult.success; +import static com.ruoyi.common.utils.SecurityUtils.getUsername; + +/** + * @author wangqiong + * @description 案件压缩包导入 + * @date 2023-12-11 11:45 + */ +@Service +public class CaseZipImportImpl { + @Autowired + private CaseApplicationServiceImpl caseApplicationService; + @Autowired + private FatchRuleMapper fatchRuleMapper; + @Autowired + private SysDictDataMapper dictDataMapper; + @Autowired + private CaseApplicationMapper caseApplicationMapper; + @Autowired + private SysDeptMapper sysDeptMapper; + @Autowired + private SysRoleMapper roleMapper; + @Autowired + private SysUserMapper userMapper; + @Autowired + private SysUserRoleMapper userRoleMapper; + @Autowired + private CaseApplicationLogMapper caseApplicationLogMapper; + @Autowired + private CaseAffiliateLogMapper caseAffiliateLogMapper; + @Autowired + private CaseAttachLogMapper caseAttachLogMapper; + @Autowired + private SmsRecordMapper smsRecordMapper; + @Autowired + private CaseAttachMapper caseAttachMapper; + @Autowired + private ColumnValueMapper columnValueMapper; + @Autowired + private ColumnValueLogMapper columnValueLogMapper; + @Autowired + private CaseAffiliateMapper caseAffiliateMapper; + // 申请人角色id + private long roleId; + private Integer maxCaseNum; + private Integer maxBatchNumber; + + public AjaxResult zipImport(MultipartFile file, Long templateId) { + UUID uuid = UUID.randomUUID(); + // todo + String targetPath = "/home/ruoyi/uploadPath/upload/unzipFile/" + uuid + "/"; +// String targetPath = "D:/home/ruoyi/uploadPath/upload/unzipFile/"+uuid+ "/"; + File zipFile = null; + InputStream ins = null; + try { + ins = file.getInputStream(); + //上传的压缩包保存的路径 + // todo + String savePath = "/home/ruoyi/uploadPath/upload/zipFile/"; +// String savePath = "D:/home/ruoyi/uploadPath/upload/zipFile/"; + String saveName = uuid + "_" + file.getOriginalFilename(); + zipFile = new File(savePath + saveName); + inputChangeToFile(ins, zipFile); + } catch (IOException e) { + e.printStackTrace(); + } + //解压缩上传的压缩包 + boolean unzipSuccess = UnZipFileUtils.unZipFile(zipFile, targetPath); + if (!unzipSuccess) { + // 解压失败 + return AjaxResult.error("解压失败"); + } + // 查询抓取规则 + // todo 批次需要再上传压缩包时用户填写 + List fatchRuleList = fatchRuleMapper.listByTemplateId(templateId); + if (CollectionUtil.isEmpty(fatchRuleList)) { + return error("未设置抓取规则"); + } + File directory = new File(targetPath); + // fileMap> + Map> fileMap = findAndConvertPDF(directory); + if (fileMap == null || fileMap.size() <= 0) { + // 解压失败 + return AjaxResult.error("未获取到文件"); + } + Map fatchMap = new HashMap<>(); + if (CollectionUtil.isNotEmpty(fatchRuleList)) { + + Map> fatchRuleMap = fatchRuleList.stream().collect(Collectors.groupingBy(FatchRule::getFileName)); + // 根据抓取规则循环抓取 + fileMap.forEach((key, fileList) -> { + if (CollectionUtil.isNotEmpty(fileList)) { + for (File caseFile : fileList) { + if (fatchRuleMap.containsKey(caseFile.getName())) { + // 抓取内容 + List fatchRules = fatchRuleMap.get(caseFile.getName()); + getFatchContentList(caseFile, fatchMap, fatchRules, key); + } + } + } + }); + + } + if (fatchMap.size() <= 0) { + return error("从压缩包中未抓取到内容,请检查抓取字段配置"); + } + // 新增的案件 + List caseApplications = new ArrayList<>(); + // 从抓取规则表取字段和字典表取基本字段,字典表的字段名塞到基本表,is_default=1自定义字段塞到columnValue + // 抓取规则,0-内置字段,1-自定义字段 + Map> fatchRuleMap = fatchRuleList.stream().collect(Collectors.groupingBy(FatchRule::getIsDefault)); + // 在系统表中查询案件内置字段 + SysDictData sysDictData = new SysDictData(); + sysDictData.setDictType("case_built_type"); + List dictDataList = dictDataMapper.selectDictDataList(sysDictData); + // 查询所有的组织机构,组装成map + List deptList = sysDeptMapper.selectDeptList(new SysDept()); + // 所有部门 + Map deptMap = new HashMap<>(); + if (CollectionUtil.isNotEmpty(deptList)) { + deptMap = deptList.stream().collect(Collectors.toMap(SysDept::getDeptName, SysDept::getDeptId, (oldV, newV) -> newV)); + + } + // 角色用户 + List userRoleList = new ArrayList<>(); + // 查询申请人角色id + roleId = roleMapper.selectRoleIdByName("申请人"); + + // 案件基本信息 + caseApplications = new ArrayList<>(); + // 自定义字段,组装columnValue表 + List columnValueList = new ArrayList<>(); + // 案件人员 + List caseAffiliates = new ArrayList<>(); + // 组装机构 + List sysDepts = new ArrayList<>(); + // 案件附件 + List caseAttachs = new ArrayList<>(); + /** + * 用户表已存在的用户 + */ + List existUsers = userMapper.selectUserList(new SysUser()); + Map userMap = new HashMap<>(); + if (CollectionUtil.isNotEmpty(existUsers)) { + userMap = existUsers.stream().collect(Collectors.toMap(SysUser::getPhonenumber, Function.identity(), (n1, n2) -> n2)); + } + //查询出当天的案件编号的最大值 + String currentDay = DateUtils.dateTime(); + String caseNum = "zc" + currentDay; + maxCaseNum = caseApplicationMapper.selectCaseNumLike(caseNum, caseNum.length()); + // 需要新增的用户 + List addUsers = new ArrayList<>(); + for (Long caseId : fileMap.keySet()) { + if (CollectionUtil.isEmpty(fileMap.get(caseId))) { + continue; + } + CaseApplication caseApplication = new CaseApplication(); + caseApplications.add(caseApplication); + caseApplication.setId(caseId); + caseApplication.setTemplateId(templateId); + + caseApplication.setCaseStatus(CaseApplicationConstants.CASE_APPLICATION); + caseApplication.setCaseLogId(IdWorkerUtil.getId()); + caseApplication.setUpdateSubmitStatus(UpdateSubmitStatus.UNCOMMITTED.getCode()); + caseApplication.setCaseAppliId(caseApplication.getId()); + //默认案件标的 todo 案件标的是什么,默认写死 + caseApplication.setCaseSubjectAmount(new BigDecimal(100000)); + //todo 暂时设置计费比率为0.01 + BigDecimal feeRate = new BigDecimal(0.01); + BigDecimal feePayable = caseApplication.getCaseSubjectAmount().multiply(feeRate).setScale(2, BigDecimal.ROUND_HALF_UP); + caseApplication.setFeePayable(feePayable); + // 设置批号 + if (StrUtil.isEmpty(caseApplication.getBatchNumber())) { + maxBatchNumber = caseApplicationMapper.selectBatchNumberLike(); + if (maxBatchNumber == null) { + maxBatchNumber=1; + caseApplication.setBatchNumber(maxBatchNumber.toString()); + } else { + maxBatchNumber=maxBatchNumber+1; + caseApplication.setBatchNumber( maxBatchNumber.toString()); + } + } + // 设置编号 + String maxCaseNumStr=generateCaseNum(); + caseApplication.setCaseNum(maxCaseNumStr); + caseApplication.setCreateBy(getUsername()); + caseApplication.setVersion(1); + // 组装案件内置字段主表内容 + + if (fatchRuleMap.size() > 0 && fatchRuleMap.containsKey(1)) { + List columnRules = fatchRuleMap.get(1); + columnRules.forEach(columnRule -> { + ColumnValue columnValue = new ColumnValue(); + columnValue.setColumn(columnRule.getColumn()); + columnValue.setName(columnRule.getColumnName()); + columnValue.setName(columnRule.getColumnName()); + columnValue.setValue(fatchMap.get(columnRule.getColumnName() + Constants.PDFSTR + caseId)); + columnValue.setIsDefault(1); + columnValue.setCaseId(caseId); + columnValue.setCaseAppliLogId(caseApplication.getCaseLogId()); + columnValueList.add(columnValue); + }); + } + caseApplication.setColumnValues(columnValueList); + // 组装内置字段 + buildDefaultColumn(caseApplication, dictDataList, fatchMap, caseAffiliates, deptMap, sysDepts, userMap, addUsers, userRoleList); + for (File caseFile : fileMap.get(caseId)) { + String fileUrl = caseFile.getAbsolutePath(); + if (StrUtil.isEmpty(fileUrl)) { + continue; + } + // 上传 + String filePath = RuoYiConfig.getUploadPath(); + + CaseAttach caseAttach = new CaseAttach(); + caseAttach.setCaseAppliId(caseApplication.getId()); + caseAttach.setCaseAppliLogId(caseApplication.getCaseLogId()); + caseAttach.setAnnexPath(filePath); + if (StrUtil.isNotEmpty(fileUrl)) { + String fileName = fileUrl.replace(filePath, "/profile/upload"); + caseAttach.setAnnexName(fileName); + } + // 申请人提供的证据材料 + caseAttach.setAnnexType(2); + caseAttachs.add(caseAttach); + if (fileUrl.contains("仲裁申请书")) { + CaseAttach applyFile = new CaseAttach(); + BeanUtil.copyProperties(caseAttach, applyFile); + applyFile.setAnnexType(1); + caseAttachs.add(applyFile); + } + } + // 案件压缩包导入 + caseApplication.setImportFlag(2); + + } + // 多线程执行 + List execList=new ArrayList<>(); + if (CollectionUtil.isNotEmpty(addUsers)) { + Function,Integer> function=userMapper::batchSave; + execList.add(new MultipleThreadListParam(function,addUsers)); + } + if (CollectionUtil.isNotEmpty(userRoleList)) { + Function,Integer> function=userRoleMapper::batchUserRole; + execList.add(new MultipleThreadListParam(function,userRoleList)); + + } + if (CollectionUtil.isNotEmpty(sysDepts)) { + Function,Integer> function=sysDeptMapper::batchSave; + execList.add(new MultipleThreadListParam(function,sysDepts)); + + } + if (CollectionUtil.isNotEmpty(caseApplications)) { + Function,Integer> function=caseApplicationMapper::batchSave; + execList.add(new MultipleThreadListParam(function,caseApplications)); + Function,Integer> functionLog=caseApplicationLogMapper::batchSave; + execList.add(new MultipleThreadListParam(functionLog,caseApplications)); + + } + if (CollectionUtil.isNotEmpty(caseAffiliates)) { + Function,Integer> function=caseAffiliateMapper::batchCaseAffiliate; + execList.add(new MultipleThreadListParam(function,caseAffiliates)); + Function,Integer> functionLog=caseAffiliateLogMapper::batchCaseAffiliate; + execList.add(new MultipleThreadListParam(functionLog,caseAffiliates)); + } + if (CollectionUtil.isNotEmpty(caseAttachs)) { + Function,Integer> function=caseAttachMapper::batchSave; + execList.add(new MultipleThreadListParam(function,caseAttachs)); + Function,Integer> functionLog=caseAttachLogMapper::batchSave; + execList.add(new MultipleThreadListParam(functionLog,caseAttachs)); + } + if (CollectionUtil.isNotEmpty(columnValueList)) { + Function,Integer> function=columnValueMapper::batchSave; + execList.add(new MultipleThreadListParam(function,columnValueList)); + Function,Integer> functionLog=columnValueLogMapper::batchSave; + execList.add(new MultipleThreadListParam(functionLog,columnValueList)); + } + if(CollectionUtil.isNotEmpty(execList)){ + MultipleThreadWorkUtil.execListFun(execList.toArray(new MultipleThreadListParam[execList.size()])); + } + return success("导入成功"); + + } + /** + * 获取自动编码 + * + * @return + */ + + public String generateCaseNum() { + // 自动编码格式 zc+yyyyMMdd+001 + String currentDay = DateUtils.dateTime(); + String caseNum = "zc" + currentDay; + + + if (null == maxCaseNum) { + maxCaseNum=1; + caseNum = caseNum + "001"; + } else { + maxCaseNum=maxCaseNum+1; + caseNum = caseNum + String.format("%03d", maxCaseNum); + } + return caseNum; + + } + public void inputChangeToFile(InputStream instream, File file) { + try { + OutputStream outStr = new FileOutputStream(file); + int bytesRead = 0; + byte[] buffer = new byte[8192]; + while ((bytesRead = instream.read(buffer, 0, 1024)) != -1) { + outStr.write(buffer, 0, bytesRead); + } + outStr.flush(); + outStr.close(); + instream.close(); + } catch (Exception e) { + e.printStackTrace(); + } + } + + /** + * 查找文件 + * + * @param directory + * @param + * @return + */ + public static Map> findAndConvertPDF(File directory) { + // caseMap> + Map> caseMap = new HashMap<>(); + if (directory.isFile()) { + String path = ""; + // 如果传入的参数是一个文件 + path = directory.getAbsolutePath(); + List fileList = new ArrayList<>(); + fileList.add(directory); + caseMap.put(IdWorkerUtil.getId(), fileList); + + } else if (directory.isDirectory()) { + searchAndConvertPDF(directory, caseMap, 1, new HashMap<>()); + } else { + return null; + } + return caseMap; + } + + public static boolean isPDF(File file) { + String extension = FileUtils.getFileExtension(file); + return extension.equalsIgnoreCase("pdf"); + } + + + /** + * 递归查找文件夹 + * + * @param directory + * @param caseMap> + * @param i 第几层文件夹 + * @param fileMap> + */ + public static void searchAndConvertPDF(File directory, Map> caseMap, int i, Map fileMap) { + File[] files = directory.listFiles(); + // 约定压缩包第二层一个文件夹为一个案件 + if (files != null) { + if (i == 2) { + for (File file : files) { + fileMap.put(file.getAbsolutePath(), IdWorkerUtil.getId()); + } + } + i++; + for (File file : files) { + + if (file.getName().contains("zip") || file.getName().contains("rar")) { + continue; + } + if (file.isFile()) { + for (Map.Entry entry : fileMap.entrySet()) { + // 为同一个案件 + if (!file.getAbsolutePath().contains(entry.getKey())) { + continue; + } + List fileList; + if (caseMap.containsKey(entry.getValue())) { + fileList = caseMap.get(entry.getValue()); + } else { + fileList = new ArrayList<>(); + } + fileList.add(file); + caseMap.put(entry.getValue(), fileList); + + } + + } else if (file.isDirectory()) { + // 如果是目录,递归查找 + searchAndConvertPDF(file, caseMap, i, fileMap); + } + } + } + } + + + private static int getFileNumPage(String pdfUrl) { + File pdfFile = new File(pdfUrl); + int pageCount = 0; + try (PDDocument document = PDDocument.load(pdfFile)) { + pageCount = document.getNumberOfPages(); + } catch (IOException e) { + e.printStackTrace(); + } + return pageCount; + } + + /** + * 获取模板和正文中替换符的内容 + * + * @param a + * @param b + * @return + */ + public static List getReplaceList(String a, String b) { + String aTmpe = filterString(a); + String bTmpe = filterString(b); + String regex = "(\\{[^}}]*})"; + String[] ptTemplate = aTmpe.replaceAll(regex, "@=").split("@="); + String replace = ""; + for (int i = 0; i < ptTemplate.length; i++) { + if (ptTemplate[i] == null || ptTemplate[i].equals(" ")) continue; + if (replace.equals("")) { + replace = bTmpe.replace(ptTemplate[i], "@="); + } else { + replace = replace.replace(ptTemplate[i], "@="); + } + } + List aList = new ArrayList<>(); + String[] split = replace.split("@="); + for (int i = 0; i < split.length; i++) { + if (split[i] == "" || split[i].equals("")) continue; + aList.add(split[i]); + } + return aList; + } + + // 去掉内容中的换行符 + public static String filterString(String str) { + if (str == null || str.equals("")) { + return null; + } + String regEx = "[\\r\\n]"; + Pattern p = Pattern.compile(regEx); + Matcher m = p.matcher(str); + return m.replaceAll(" ").trim(); + } + + // 检索时,转换特殊字符 + public static String escapeQueryChars(String s) { + if (StringUtils.isBlank(s)) { + return s; + } + StringBuilder sb = new StringBuilder(); + for (int i = 0; i < s.length(); i++) { + char c = s.charAt(i); + // These characters are part of the query syntax and must be escaped + if (c == '\\' || c == '+' || c == '-' || c == '!' || c == '(' || c == ')' + || c == ':' || c == '^' || c == '[' || c == ']' || c == '\"' + || c == '{' || c == '}' || c == '~' || c == '*' || c == '?' + || c == '|' || c == '&' || c == ';' || c == '/' || c == '.' + || c == '$' || Character.isWhitespace(c)) { + sb.append('\\'); + } + sb.append(c); + } + return sb.toString(); + } + + /** + * 组装内置字段 + * + * @param caseApplication 案件信息 + * @param dictDataList 内置字段 + * @param fatchMap 抓取字段内容 + */ + private void buildDefaultColumn(CaseApplication caseApplication, List dictDataList, Map fatchMap, + List caseAffiliates, Map deptMap, List sysDepts, + Map userMap, List addUsers, List userRoleList) { + // 组装内置字段 + if (CollectionUtil.isEmpty(dictDataList)) { + return; + } + // 被申请人 + CaseAffiliate debtorAffiliate = new CaseAffiliate(); + debtorAffiliate.setCaseAppliId(caseApplication.getId()); + debtorAffiliate.setCaseAppliLogId(caseApplication.getCaseLogId()); + // 申请人 + CaseAffiliate affiliate = new CaseAffiliate(); + affiliate.setCaseAppliLogId(caseApplication.getCaseLogId()); + affiliate.setCaseAppliId(caseApplication.getId()); + for (SysDictData dictData : dictDataList) { + if (StrUtil.isNotEmpty(dictData.getDictLabel())) { + if (dictData.getDictLabel().contains("被申请人")) { + // 组装被申请人内置自段 + buildDebtorColumn(dictData, fatchMap, debtorAffiliate,caseApplication.getId()); + } else if (dictData.getDictLabel().contains("申请人") || dictData.getDictLabel().contains("统一社会信用代码") + || dictData.getDictLabel().contains("法定代表人") || dictData.getDictLabel().contains("委托代理人")) { + // 组装申请人内置自段 + buildAffilcateColumn(dictData, fatchMap, affiliate, deptMap, sysDepts, userMap, addUsers, userRoleList,caseApplication.getId()); + } else if (dictData.getDictLabel().contains("合同编号")) { + // 合同编号 + String contractNumber = fatchMap.get("合同编号"+ Constants.PDFSTR + caseApplication.getId()); + if (StrUtil.isNotEmpty(contractNumber)) { + // 提取字母和数字 + String regx = "[^a-zA-Z0-9]"; + String replaceAll = contractNumber.replaceAll(regx, ""); + caseApplication.setContractNumber(replaceAll.toUpperCase()); + } + } else { + ObjectFieldUtils.setValue(caseApplication, dictData.getDictValue(), fatchMap.get(dictData.getDictLabel()+ Constants.PDFSTR + caseApplication.getId())); + } + + } else { + ObjectFieldUtils.setValue(caseApplication, dictData.getDictValue(), fatchMap.get(dictData.getDictLabel()+ Constants.PDFSTR + caseApplication.getId())); + + } + + } + if (ObjectUtil.isNotEmpty(affiliate)) { + caseAffiliates.add(affiliate); + } + if (ObjectUtil.isNotEmpty(debtorAffiliate)) { + caseAffiliates.add(debtorAffiliate); + } + + + } + + /** + * 组装申请人内置字段 + * + * @param dictData 内置字段 + * @param fatchMap 抓取内容 + * @param affiliate 案件人员 + */ + private void buildAffilcateColumn(SysDictData dictData, Map fatchMap, CaseAffiliate affiliate, + Map deptMap, List sysDepts, + Map userMap, List addUsers, List userRoleList,Long caseId) { + + affiliate.setIdentityType(1); + + // 申请人 + switch (dictData.getDictLabel()) { + case "申请人姓名": + affiliate.setName((fatchMap.get(dictData.getDictLabel()+ Constants.PDFSTR + caseId))); + if (StrUtil.isNotEmpty(affiliate.getName())) { + // 组装申请机构 + // 将组织机构id设为申请人名称 + if (deptMap.containsKey(affiliate.getName())) { + affiliate.setApplicationOrganId(String.valueOf(deptMap.get(affiliate.getName()))); + affiliate.setApplicationOrganName(affiliate.getName()); + } else { + // 如果不存在则新增 + SysDept dept = new SysDept(); + dept.setParentId(0L); + dept.setDeptName(affiliate.getName()); + dept.setAncestors("0"); + dept.setOrderNum(1); + dept.setStatus("0"); + dept.setDelFlag("0"); + dept.setCreateBy(getUsername()); + dept.setUpdateBy(getUsername()); + dept.setDeptId(Long.valueOf(IdWorkerUtil.getId())); + sysDepts.add(dept); + deptMap.put(dept.getDeptName(), dept.getDeptId()); + affiliate.setApplicationOrganId(String.valueOf(dept.getDeptId())); + affiliate.setApplicationOrganName(affiliate.getName()); + + } + } + break; + case "统一社会信用代码": + affiliate.setIdentityNum((fatchMap.get(dictData.getDictLabel()+ Constants.PDFSTR + caseId))); + break; + case "法定代表人": + affiliate.setCompLegalPerson(fatchMap.get(dictData.getDictLabel()+ Constants.PDFSTR + caseId)); + break; + case "法定代表人职位": + affiliate.setCompLegalperPost((fatchMap.get(dictData.getDictLabel()+ Constants.PDFSTR + caseId))); + break; + case "申请人住所": + affiliate.setResidenAffili((fatchMap.get(dictData.getDictLabel()+ Constants.PDFSTR + caseId))); + break; + case "申请人联系地址": + affiliate.setContactAddress(fatchMap.get(dictData.getDictLabel()+ Constants.PDFSTR + caseId)); + break; + case "委托代理人姓名": + affiliate.setNameAgent(fatchMap.get(dictData.getDictLabel()+ Constants.PDFSTR + caseId)); + break; + case "委托代理人联系电话": + affiliate.setContactTelphoneAgent(fatchMap.get(dictData.getDictLabel()+ Constants.PDFSTR + caseId)); + if (StrUtil.isNotEmpty(affiliate.getContactTelphoneAgent())) { + // 用户已存在 + if (userMap.containsKey(affiliate.getContactTelphoneAgent())) { + SysUser agentUser = userMap.get(affiliate.getContactTelphoneAgent()); + if (null != agentUser.getDeptId() && String.valueOf(agentUser.getDeptId()).equals(affiliate.getApplicationOrganId())) { + // 同步用户表和案件关联人表的手机号和名称 + affiliate.setContactTelphoneAgent(agentUser.getPhonenumber()); + affiliate.setNameAgent(agentUser.getNickName()); + affiliate.setApplicantAgentUserId(String.valueOf(agentUser.getUserId())); + if (StrUtil.isNotEmpty(agentUser.getIdCard())) { + affiliate.setIdentityNumAgent(agentUser.getIdCard()); + } else { + affiliate.setIdentityNumAgent(affiliate.getIdentityNumAgent()); + } + List longList = new ArrayList<>(); + // 新增角色为申请人 + if (CollectionUtil.isNotEmpty(agentUser.getRoles())) { + longList = agentUser.getRoles().stream().map(SysRole::getRoleId).collect(Collectors.toList()); + if (!longList.contains(roleId)) { + insertAgentUserRole(agentUser, roleId, userRoleList); + } + } else { + + insertAgentUserRole(agentUser, roleId, userRoleList); + } + + } + } else { + // 用户不存在,新增 + SysUser agentUser = new SysUser(); + agentUser.setUserId(Long.valueOf(IdWorkerUtil.getId())); + agentUser.setIdCard(affiliate.getIdentityNumAgent()); + agentUser.setNickName(affiliate.getNameAgent()); + agentUser.setUserName(affiliate.getContactTelphoneAgent()); + agentUser.setPhonenumber(affiliate.getContactTelphoneAgent()); + agentUser.setPassword(SecurityUtils.encryptPassword("abc123456")); + agentUser.setDeptId(Long.valueOf(affiliate.getApplicationOrganId())); + addUsers.add(agentUser); + userMap.put(agentUser.getPhonenumber(), agentUser); + insertAgentUserRole(agentUser, roleId, userRoleList); + + } + } + break; + case "委托代理人电子邮件": + affiliate.setAgentEmail(StrUtil.isNotEmpty(fatchMap.get(dictData.getDictLabel()+ Constants.PDFSTR + caseId)) ? fatchMap.get(dictData.getDictLabel()+ Constants.PDFSTR + caseId).replace("\n", "").replaceAll("\\s", "") : null); + + break; + default: + break; + } + } + + /** + * 新增角色为申请人 + * + * @param agentUser + * @param roleId + */ + private void insertAgentUserRole(SysUser agentUser, Long roleId, List userRoleList) { + + SysUserRole sysUserRole = new SysUserRole(); + sysUserRole.setUserId(agentUser.getUserId()); + sysUserRole.setRoleId(roleId); + userRoleList.add(sysUserRole); + + } + + /** + * 组装被申请人内置字段 + * + * @param dictData 内置字段 + * @param fatchMap 抓取内容 + * @param debtorAffiliate 被申请人 + */ + private void buildDebtorColumn(SysDictData dictData, Map fatchMap, CaseAffiliate debtorAffiliate,Long caseId) { + + debtorAffiliate.setIdentityType(2); + // 被申请人 + switch (dictData.getDictLabel()) { + case "被申请人姓名": + debtorAffiliate.setName(fatchMap.get(dictData.getDictLabel()+ Constants.PDFSTR + caseId)); + break; + case "被申请人身份证号": + String identityNum = fatchMap.get(dictData.getDictLabel()+ Constants.PDFSTR + caseId); + debtorAffiliate.setIdentityNum(fatchMap.get(dictData.getDictLabel()+ Constants.PDFSTR + caseId)); + // 出生年月日,从身份证抓取 + if (StrUtil.isNotEmpty(identityNum)) { + identityNum = identityNum.replace("\n", ""); + Map identityNumMap = IdCardUtils.getBirAgeSex(identityNum); + String birthday = identityNumMap.get("birthday"); + if (StrUtil.isNotEmpty(birthday)) { + SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd"); + Date birthdayDate = null; + try { + birthdayDate = simpleDateFormat.parse(birthday); + } catch (Exception e) { + e.printStackTrace(); + } + debtorAffiliate.setResponBirth(birthdayDate); + } + //从身份证抓取性别 + debtorAffiliate.setResponSex(identityNumMap.get("sexCode")); + } + + break; + case "被申请人住所": + debtorAffiliate.setResidenAffili(fatchMap.get(dictData.getDictLabel()+ Constants.PDFSTR + caseId)); + break; + case "被申请人联系电话": + debtorAffiliate.setContactTelphone(fatchMap.get(dictData.getDictLabel()+ Constants.PDFSTR + caseId)); + break; + case "被申请人电子邮件": + debtorAffiliate.setEmail(StrUtil.isNotEmpty(fatchMap.get(dictData.getDictLabel()+ Constants.PDFSTR + caseId)) ? fatchMap.get(dictData.getDictLabel()+ Constants.PDFSTR + caseId).replace("\n", "").replaceAll("\\s", "") : null); + + break; + default: + break; + } + + } + + /** + * 获取抓取内容 + * + * @param fatchRules 抓取规则 + */ + private void getFatchContentList(File caseFile, Map fatchMap, List fatchRules, Long caseId) { + String fileURL = caseFile.getAbsolutePath(); + if (fileURL.endsWith("txt")) { + String readerFile = ReadFileUtils.readerTxtFile(fileURL); + OCRUtils.fatchRuleGetContent(readerFile, fatchRules, fatchMap, caseId); + } else if (fileURL.endsWith("doc") || fileURL.endsWith("docx")) { + // doc,docx,text识别内容 + String readerFile = null; + try { + readerFile = ReadFileUtils.readWord(fileURL); + } catch (Exception e) { + e.printStackTrace(); + } + OCRUtils.fatchRuleGetContent(readerFile, fatchRules, fatchMap, caseId); + + } else if (fileURL.endsWith("pdf")) { + //获取文件的页数 + int fileNumPage = getFileNumPage(fileURL); + //文件转成base64 + String base64 = OCRUtils.pdfConvertBase64(fileURL); + if (base64 == null) { + throw new ServiceException("pdf转base64失败"); + // return false; + } + StringBuilder ocrText = new StringBuilder(); // 创建一个StringBuilder对象 + for (int i = 1; i <= fileNumPage; i++) { + //对接腾讯云接口.识别里面的数据 + String text = OCRUtils.pdfIdentifyText(base64, i, fatchRules); + ocrText.append(text); // 拼接当前的字符串 + // 根据抓取规则截取内容 + OCRUtils.fatchRuleGetContent(ocrText.toString(), fatchRules, fatchMap, caseId); + + } + } + + + } + + + +} diff --git a/ruoyi-system/src/main/java/com/ruoyi/wisdomarbitrate/utils/OCRUtils.java b/ruoyi-system/src/main/java/com/ruoyi/wisdomarbitrate/utils/OCRUtils.java index 3158fa9..cfb8539 100644 --- a/ruoyi-system/src/main/java/com/ruoyi/wisdomarbitrate/utils/OCRUtils.java +++ b/ruoyi-system/src/main/java/com/ruoyi/wisdomarbitrate/utils/OCRUtils.java @@ -118,10 +118,10 @@ public class OCRUtils { for (FatchRule fatchRule : fatchRules) { // 从后往前抓取 if (fatchRule.getFatchOrder() != null && fatchRule.getFatchOrder() == 1) { - reverseSubstringText(ocrText, fatchRule, fatchMap); + reverseSubstringText(ocrText, fatchRule, fatchMap,null); } else { // 从前往后抓取 - substringText(ocrText, fatchRule, fatchMap); + substringText(ocrText, fatchRule, fatchMap,null); } } @@ -129,43 +129,32 @@ public class OCRUtils { } - public static void sub1(String text, FatchRule fatchRule, Map fatchMap) { - if (StrUtil.isEmpty(fatchRule.getStartContent()) && StrUtil.isEmpty(fatchRule.getEndContent())) { - fatchMap.put(fatchRule.getColumnName(), trimStr(text)); - } else if (StrUtil.isNotEmpty(fatchRule.getStartContent())) { - int startContIndex = StrUtil.ordinalIndexOf(text, fatchRule.getStartContent(), fatchRule.getStartContentRepeatOrder()); - if (startContIndex != -1) { - // 开始不为空结束为空 - if (StrUtil.isEmpty(fatchRule.getEndContent())) { - if ((startContIndex + fatchRule.getStartContent().length()) <= text.length()) { - String substring = text.substring(startContIndex + fatchRule.getStartContent().length()); - // 去除\n - fatchMap.put(fatchRule.getColumnName(), trimStr(substring)); - } + /** + * 根据抓取规则获取内容 + * + * @param ocrText ocr识别的text + * @param fatchRules 抓取规则 + * @return + */ + public static void fatchRuleGetContent(String ocrText, List fatchRules, Map fatchMap, Long caseId) { + if (StrUtil.isEmpty(ocrText) || CollectionUtil.isEmpty(fatchRules)) { + return; + } + for (FatchRule fatchRule : fatchRules) { + // 从后往前抓取 + if (fatchRule.getFatchOrder() != null && fatchRule.getFatchOrder() == 1) { + reverseSubstringText(ocrText, fatchRule, fatchMap, caseId); + } else { + // 从前往后抓取 + substringText(ocrText, fatchRule, fatchMap, caseId); - } else { - // 开始不为空结束不为空 - int endContIndex = StrUtil.ordinalIndexOf(text, fatchRule.getEndContent(), fatchRule.getEndContentRepeatOrder()); - if (endContIndex != -1 && endContIndex <= text.length() && (startContIndex + fatchRule.getStartContent().length()) <= endContIndex) { - String substring = text.substring(startContIndex + fatchRule.getStartContent().length(), endContIndex); - // 去除\n - fatchMap.put(fatchRule.getColumnName(), trimStr(substring)); - } - - } -// - } - - } else if (StrUtil.isEmpty(fatchRule.getStartContent()) && StrUtil.isNotEmpty(fatchRule.getEndContent())) { - // 开始为空结束不为空 - int endContIndex = StrUtil.ordinalIndexOf(text, fatchRule.getEndContent(), fatchRule.getEndContentRepeatOrder()); - if (endContIndex != -1) { - String substring = text.substring(0, endContIndex); - fatchMap.put(fatchRule.getColumnName(), trimStr(substring)); } } + + } + /** * 正向截取字段 * @@ -173,19 +162,19 @@ public class OCRUtils { * @param fatchRule * @param fatchMap */ - private static void substringText(String text, FatchRule fatchRule, Map fatchMap) { + private static void substringText(String text, FatchRule fatchRule, Map fatchMap, Long caseId) { String startContent = fatchRule.getStartContent(); String endContent = fatchRule.getEndContent(); // 开始为空结束为空 if (StrUtil.isEmpty(startContent) && StrUtil.isEmpty(endContent)) { - fatchMap.put(fatchRule.getColumnName(), trimStr(text)); + fatchMap.put(fatchRule.getColumnName()+Constants.PDFSTR+caseId, trimStr(text)); } else if (StrUtil.isNotEmpty(startContent) && StrUtil.isEmpty(endContent)) { // 开始不为空结束为空 int startContIndex = StrUtil.ordinalIndexOf(text, startContent, fatchRule.getStartContentRepeatOrder()); if (startContIndex != -1 && text.length() >= (startContIndex + startContent.length())) { String substring = text.substring(startContIndex + startContent.length()); // 去除\n - fatchMap.put(fatchRule.getColumnName(), trimStr(substring)); + fatchMap.put(fatchRule.getColumnName()+Constants.PDFSTR+caseId, trimStr(substring)); } } else if (StrUtil.isEmpty(startContent) && StrUtil.isNotEmpty(endContent)) { @@ -193,7 +182,7 @@ public class OCRUtils { int endContIndex = StrUtil.ordinalIndexOf(text, endContent, fatchRule.getEndContentRepeatOrder()); if (endContIndex != -1) { String substring = text.substring(0, endContIndex); - fatchMap.put(fatchRule.getColumnName(), trimStr(substring)); + fatchMap.put(fatchRule.getColumnName()+Constants.PDFSTR+caseId, trimStr(substring)); } } else if (StrUtil.isNotEmpty(startContent) && StrUtil.isNotEmpty(endContent)) { // 开始结束不为空 @@ -202,12 +191,72 @@ public class OCRUtils { if (startIndexOf != -1 && endIndexOf != -1 && endIndexOf >= (startIndexOf + startContent.length()) && text.length() >= endIndexOf) { String substring = text.substring(startIndexOf + startContent.length(), endIndexOf); - fatchMap.put(fatchRule.getColumnName(), trimStr(substring)); + fatchMap.put(fatchRule.getColumnName()+Constants.PDFSTR+caseId, trimStr(substring)); } } } + + /** + * 从后往前截取字符串 + * + * @param text + * @param fatchRule + * @param fatchMap + */ + public static void reverseSubstringText(String text, FatchRule fatchRule, Map fatchMap, Long caseId) { + + // 反正字符串 + String reverseText = StrUtil.reverse(text); + // 结束截取字段 + String reverseEndContent = ""; + // 开始截取字段 + String reverseStartContent = ""; + if (StrUtil.isNotEmpty(fatchRule.getEndContent())) { + reverseEndContent = StrUtil.reverse(fatchRule.getEndContent()); + } + if (StrUtil.isNotEmpty(fatchRule.getStartContent())) { + reverseStartContent = StrUtil.reverse(fatchRule.getStartContent()); + } + // 开始和结束截取都为空 + if (StrUtil.isEmpty(reverseStartContent) && StrUtil.isEmpty(reverseEndContent)) { + fatchMap.put(fatchRule.getColumnName()+Constants.PDFSTR+caseId, trimStr(text)); + } else if (StrUtil.isEmpty(reverseStartContent) && StrUtil.isNotEmpty(reverseEndContent)) { + // 开始为空,结束不为空 + // 根据截取的序号查找出位置 + int indexOf = StrUtil.ordinalIndexOf(reverseText, reverseEndContent, fatchRule.getEndContentRepeatOrder()); + if (indexOf != -1) { + String substring = reverseText.substring(0, indexOf); + if (StrUtil.isNotEmpty(substring)) { + fatchMap.put(fatchRule.getColumnName()+Constants.PDFSTR+caseId, trimStr(StrUtil.reverse(substring))); + } + } + } else if (StrUtil.isNotEmpty(reverseStartContent) && StrUtil.isEmpty(reverseEndContent)) { + // 开始不为空,结束为空 + int indexOf = StrUtil.ordinalIndexOf(reverseText, reverseStartContent, fatchRule.getStartContentRepeatOrder()); + if (indexOf != -1 && (indexOf + reverseStartContent.length() <= text.length())) { + String substring = reverseText.substring(indexOf + reverseStartContent.length()); + if (StrUtil.isNotEmpty(substring)) { + fatchMap.put(fatchRule.getColumnName()+Constants.PDFSTR+caseId, trimStr(StrUtil.reverse(substring))); + } + } + + } else if (StrUtil.isNotEmpty(reverseStartContent) && StrUtil.isNotEmpty(reverseEndContent)) { + // 开始结束都不为空 + int endIndexOf = StrUtil.ordinalIndexOf(reverseText, reverseEndContent, fatchRule.getEndContentRepeatOrder()); + int startIndexOf = StrUtil.ordinalIndexOf(reverseText, reverseStartContent, fatchRule.getStartContentRepeatOrder()); + if (startIndexOf != -1 && endIndexOf != -1 && endIndexOf >= (startIndexOf + reverseStartContent.length()) && text.length() >= endIndexOf) { + String substring = reverseText.substring(startIndexOf + reverseStartContent.length(), endIndexOf); + if (StrUtil.isNotEmpty(substring)) { + fatchMap.put(fatchRule.getColumnName()+Constants.PDFSTR+caseId, trimStr(StrUtil.reverse(substring))); + } + } + } + + + } + /** * 去除末尾空格 * @@ -223,63 +272,4 @@ public class OCRUtils { } - /** - * 从后往前截取字符串 - * - * @param text - * @param fatchRule - * @param fatchMap - */ - public static void reverseSubstringText(String text, FatchRule fatchRule, Map fatchMap) { - - // 反正字符串 - String reverseText = StrUtil.reverse(text); - // 结束截取字段 - String reverseEndContent = ""; - // 开始截取字段 - String reverseStartContent = ""; - if (StrUtil.isNotEmpty(fatchRule.getEndContent())) { - reverseEndContent = StrUtil.reverse(fatchRule.getEndContent()); - } - if (StrUtil.isNotEmpty(fatchRule.getStartContent())) { - reverseStartContent = StrUtil.reverse(fatchRule.getStartContent()); - } - // 开始和结束截取都为空 - if (StrUtil.isEmpty(reverseStartContent) && StrUtil.isEmpty(reverseEndContent)) { - fatchMap.put(fatchRule.getColumnName(), trimStr(text)); - } else if (StrUtil.isEmpty(reverseStartContent) && StrUtil.isNotEmpty(reverseEndContent)) { - // 开始为空,结束不为空 - // 根据截取的序号查找出位置 - int indexOf = StrUtil.ordinalIndexOf(reverseText, reverseEndContent, fatchRule.getEndContentRepeatOrder()); - if (indexOf != -1) { - String substring = reverseText.substring(0, indexOf); - if (StrUtil.isNotEmpty(substring)) { - fatchMap.put(fatchRule.getColumnName(), trimStr(StrUtil.reverse(substring))); - } - } - } else if (StrUtil.isNotEmpty(reverseStartContent) && StrUtil.isEmpty(reverseEndContent)) { - // 开始不为空,结束为空 - int indexOf = StrUtil.ordinalIndexOf(reverseText, reverseStartContent, fatchRule.getStartContentRepeatOrder()); - if (indexOf != -1 && (indexOf + reverseStartContent.length() <= text.length())) { - String substring = reverseText.substring(indexOf + reverseStartContent.length()); - if (StrUtil.isNotEmpty(substring)) { - fatchMap.put(fatchRule.getColumnName(), trimStr(StrUtil.reverse(substring))); - } - } - - } else if (StrUtil.isNotEmpty(reverseStartContent) && StrUtil.isNotEmpty(reverseEndContent)) { - // 开始结束都不为空 - int endIndexOf = StrUtil.ordinalIndexOf(reverseText, reverseEndContent, fatchRule.getEndContentRepeatOrder()); - int startIndexOf = StrUtil.ordinalIndexOf(reverseText, reverseStartContent, fatchRule.getStartContentRepeatOrder()); - if (startIndexOf != -1 && endIndexOf != -1 && endIndexOf >= (startIndexOf + reverseStartContent.length()) && text.length() >= endIndexOf) { - String substring = reverseText.substring(startIndexOf + reverseStartContent.length(), endIndexOf); - if (StrUtil.isNotEmpty(substring)) { - fatchMap.put(fatchRule.getColumnName(), trimStr(StrUtil.reverse(substring))); - } - } - } - - - } - } diff --git a/ruoyi-system/src/main/resources/mapper/system/SysDeptMapper.xml b/ruoyi-system/src/main/resources/mapper/system/SysDeptMapper.xml index 1444c0f..588b191 100644 --- a/ruoyi-system/src/main/resources/mapper/system/SysDeptMapper.xml +++ b/ruoyi-system/src/main/resources/mapper/system/SysDeptMapper.xml @@ -121,8 +121,41 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" sysdate() ); - - + + insert into sys_dept( + dept_id, + parent_id, + dept_name, + dept_type, + ancestors, + order_num, + leader, + phone, + email, + status, + create_by, + create_time + )values + + ( + #{item.deptId}, + #{item.parentId}, + #{item.deptName}, + #{item.deptType}, + #{item.ancestors}, + #{item.orderNum}, + #{item.leader}, + #{item.phone}, + #{item.email}, + #{item.status}, + #{item.createBy}, + sysdate() + ) + ; + + + + update sys_dept parent_id = #{parentId}, diff --git a/ruoyi-system/src/main/resources/mapper/system/SysUserMapper.xml b/ruoyi-system/src/main/resources/mapper/system/SysUserMapper.xml index d244b58..20cdafe 100644 --- a/ruoyi-system/src/main/resources/mapper/system/SysUserMapper.xml +++ b/ruoyi-system/src/main/resources/mapper/system/SysUserMapper.xml @@ -59,8 +59,12 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"