From d4df5698ec3fdc93bfc6a2cddb1976ecc9ab0bb7 Mon Sep 17 00:00:00 2001 From: wangxuanran <3055088966@qq.com> Date: Fri, 25 Nov 2022 16:32:54 +0800 Subject: [PATCH] =?UTF-8?q?wxr=202022-11-25=E5=A8=81=E7=A7=91=E6=95=B0?= =?UTF-8?q?=E6=8D=AE=E5=85=88=E8=A1=8C=E4=BB=A3=E7=A0=81=E7=BC=96=E5=86=99?= =?UTF-8?q?=E4=BB=A5=E5=8F=8A=E5=A2=9E=E5=8A=A0=E5=B8=B8=E7=94=A8=E4=BF=A1?= =?UTF-8?q?=E6=81=AF=E6=96=87=E6=A1=A3=E5=90=8E=E7=AB=AF1-4=E5=86=85?= =?UTF-8?q?=E5=AE=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitignore | 2 +- .../wang/common/annocation/CusDateFormat.java | 19 +++++++ .../xuanran/wang/common/util/CommonUtil.java | 49 ++++++++++++++++-- .../wang/{ => common}/util/FtpUtil.java | 7 ++- .../traffic_bank/waco_first/entity/Info.java | 2 + .../waco_first/job/WacoDataPushOA.java | 2 +- .../service/WacoDataPushOAService.java | 51 ++++++++++++++----- .../waco_first/WacoFirstTest.java | 7 --- 常用信息.md | 45 ++++++++++++++++ 9 files changed, 153 insertions(+), 31 deletions(-) create mode 100644 src/main/java/weaver/xuanran/wang/common/annocation/CusDateFormat.java rename src/main/java/weaver/xuanran/wang/{ => common}/util/FtpUtil.java (97%) diff --git a/.gitignore b/.gitignore index 4a54ba7..9539534 100644 --- a/.gitignore +++ b/.gitignore @@ -30,7 +30,7 @@ log /file/ /src/test/resources/application.properties /src/test/resources/application.xml -/src/main/resources/file +/file DirectoryV2.xml diff --git a/src/main/java/weaver/xuanran/wang/common/annocation/CusDateFormat.java b/src/main/java/weaver/xuanran/wang/common/annocation/CusDateFormat.java new file mode 100644 index 0000000..f236b2a --- /dev/null +++ b/src/main/java/weaver/xuanran/wang/common/annocation/CusDateFormat.java @@ -0,0 +1,19 @@ +package weaver.xuanran.wang.common.annocation; + +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +/** + *

+ * + * @Author xuanran.wang + * @Date 2022/11/25 15:55 + */ +@Target({ElementType.FIELD,ElementType.TYPE}) +@Retention(RetentionPolicy.RUNTIME) +public @interface CusDateFormat { + String from(); + String to() default "yyyy-MM-dd"; +} diff --git a/src/main/java/weaver/xuanran/wang/common/util/CommonUtil.java b/src/main/java/weaver/xuanran/wang/common/util/CommonUtil.java index 2ab0d3f..988ab6f 100644 --- a/src/main/java/weaver/xuanran/wang/common/util/CommonUtil.java +++ b/src/main/java/weaver/xuanran/wang/common/util/CommonUtil.java @@ -6,15 +6,15 @@ import org.apache.commons.collections.CollectionUtils; import org.apache.commons.collections.MapUtils; import org.apache.commons.lang3.StringUtils; import org.apache.log4j.Logger; +import weaver.xuanran.wang.common.annocation.CusDateFormat; import weaver.xuanran.wang.common.annocation.ParamNotNull; import java.io.*; import java.lang.reflect.Field; import java.nio.charset.Charset; -import java.util.Collections; -import java.util.Enumeration; -import java.util.List; -import java.util.Map; +import java.text.ParseException; +import java.text.SimpleDateFormat; +import java.util.*; import java.util.stream.Collectors; import java.util.stream.Stream; import java.util.zip.ZipEntry; @@ -31,6 +31,8 @@ public class CommonUtil { public static final int SQL_IN_PAGE_SIZE = 100; + private static final SimpleDateFormat DATE_FORMAT = new SimpleDateFormat("yyyy-MM-dd"); + /** *

将文件解压至指定文件夹中

* @author xuanran.wang @@ -120,6 +122,7 @@ public class CommonUtil { } return builder.toString(); } + /** *

检查属性是否存在空值

* @author xuanran.wang @@ -158,6 +161,15 @@ public class CommonUtil { } } } + + /** + *

将集合进行分割

+ * @author xuanran.wang + * @dateTime 2022/11/25 16:01 + * @param list 待分割的集合 + * @param splitSize 分页大小 + * @return 分割集合 + **/ public static List> splitList(List list, int splitSize) { //判断集合是否为空 if (CollectionUtils.isEmpty(list)) @@ -172,4 +184,33 @@ public class CommonUtil { .filter(b -> !b.isEmpty()) .collect(Collectors.toList()); } + /** + *

通过自定义日期注解转换参数值

+ * @author xuanran.wang + * @dateTime 2022/11/25 16:07 + * @param cusDateFormat 自定义日期注解 + * @param value 待转换的值 + * @return 转换后的值 + **/ + public static String getDateByCusDateFormat(CusDateFormat cusDateFormat, Object value){ + String from = cusDateFormat.from(); + if(StringUtils.isBlank(Util.null2String(from))){ + throw new CustomerException("使用CusDateFormat注解时, from参数不能为空!"); + } + Date date = null; + SimpleDateFormat simpleDateFormat = new SimpleDateFormat(from); + try { + date = simpleDateFormat.parse(String.valueOf(value)); + }catch (ParseException e) { + throw new RuntimeException(Util.logStr("解析日期失败!当前传入转化格式:[{}],待转化日期:[{}]", from, value)); + } + String to = cusDateFormat.to(); + simpleDateFormat = new SimpleDateFormat(to); + try { + // 用时间戳进行转换 + return simpleDateFormat.format(date.getTime()); + }catch (Exception e){ + throw new RuntimeException(Util.logStr("解析日期失败!当前传入转化格式:[{}],待转化日期:[{}]", to, date)); + } + } } diff --git a/src/main/java/weaver/xuanran/wang/util/FtpUtil.java b/src/main/java/weaver/xuanran/wang/common/util/FtpUtil.java similarity index 97% rename from src/main/java/weaver/xuanran/wang/util/FtpUtil.java rename to src/main/java/weaver/xuanran/wang/common/util/FtpUtil.java index 5f18cea..468548d 100644 --- a/src/main/java/weaver/xuanran/wang/util/FtpUtil.java +++ b/src/main/java/weaver/xuanran/wang/common/util/FtpUtil.java @@ -1,4 +1,4 @@ -package weaver.xuanran.wang.util; +package weaver.xuanran.wang.common.util; import aiyh.utils.Util; import aiyh.utils.excention.CustomerException; @@ -6,14 +6,13 @@ import com.jcraft.jsch.*; import org.apache.log4j.Logger; import java.io.File; -import java.io.FileOutputStream; import java.nio.file.Files; import java.util.Iterator; import java.util.Properties; import java.util.Vector; /** - *

+ *

ftpUtil

* * @Author xuanran.wang * @Date 2022/11/22 17:25 @@ -155,7 +154,7 @@ public class FtpUtil { if(!file.getParentFile().exists()){ file.getParentFile().mkdirs(); } - sftp.get(downloadFile, new FileOutputStream(file)); + sftp.get(downloadFile, Files.newOutputStream(file.toPath())); } catch (Exception e) { throw new CustomerException("下载文件出现异常: " + e.getMessage()); } diff --git a/src/main/java/weaver/xuanran/wang/traffic_bank/waco_first/entity/Info.java b/src/main/java/weaver/xuanran/wang/traffic_bank/waco_first/entity/Info.java index c9b6019..289e2b9 100644 --- a/src/main/java/weaver/xuanran/wang/traffic_bank/waco_first/entity/Info.java +++ b/src/main/java/weaver/xuanran/wang/traffic_bank/waco_first/entity/Info.java @@ -1,6 +1,7 @@ package weaver.xuanran.wang.traffic_bank.waco_first.entity; import lombok.Data; +import weaver.xuanran.wang.common.annocation.CusDateFormat; import weaver.xuanran.wang.traffic_bank.waco_first.annocation.BodyPath; /** @@ -17,6 +18,7 @@ public class Info { private String jurisdictionName; private String adminPenaltyNumber; private String industryClassification; + @CusDateFormat(from = "yyyy.MM.dd") private String adminPenaltyDate; private String punishmentObjectType; private String punishedParties; diff --git a/src/main/java/weaver/xuanran/wang/traffic_bank/waco_first/job/WacoDataPushOA.java b/src/main/java/weaver/xuanran/wang/traffic_bank/waco_first/job/WacoDataPushOA.java index 7064acc..c88a48a 100644 --- a/src/main/java/weaver/xuanran/wang/traffic_bank/waco_first/job/WacoDataPushOA.java +++ b/src/main/java/weaver/xuanran/wang/traffic_bank/waco_first/job/WacoDataPushOA.java @@ -8,7 +8,7 @@ import weaver.xuanran.wang.common.annocation.ParamNotNull; import weaver.xuanran.wang.common.util.CommonUtil; import weaver.xuanran.wang.traffic_bank.waco_first.entity.Info; import weaver.xuanran.wang.traffic_bank.waco_first.service.WacoDataPushOAService; -import weaver.xuanran.wang.util.FtpUtil; +import weaver.xuanran.wang.common.util.FtpUtil; import java.util.List; diff --git a/src/main/java/weaver/xuanran/wang/traffic_bank/waco_first/service/WacoDataPushOAService.java b/src/main/java/weaver/xuanran/wang/traffic_bank/waco_first/service/WacoDataPushOAService.java index fe124b5..98d7c1a 100644 --- a/src/main/java/weaver/xuanran/wang/traffic_bank/waco_first/service/WacoDataPushOAService.java +++ b/src/main/java/weaver/xuanran/wang/traffic_bank/waco_first/service/WacoDataPushOAService.java @@ -4,8 +4,6 @@ import aiyh.utils.Util; import aiyh.utils.excention.CustomerException; import com.alibaba.fastjson.JSONObject; import com.jcraft.jsch.ChannelSftp; -import com.jcraft.jsch.SftpException; -import com.weaver.procedure.doc.Doc_diracl_insert_type3; import org.apache.commons.collections.CollectionUtils; import org.apache.commons.lang3.StringUtils; import org.apache.log4j.Logger; @@ -13,17 +11,17 @@ import org.dom4j.Document; import org.dom4j.Element; import org.dom4j.io.SAXReader; import weaver.conn.RecordSet; -import weaver.conn.RecordSetTrans; import weaver.docs.webservices.DocInfo; import weaver.docs.webservices.DocServiceImpl; import weaver.general.GCONST; import weaver.general.TimeUtil; import weaver.hrm.User; +import weaver.xuanran.wang.common.annocation.CusDateFormat; import weaver.xuanran.wang.common.util.CommonUtil; import weaver.xuanran.wang.common.util.CusInfoToOAUtil; import weaver.xuanran.wang.traffic_bank.waco_first.annocation.BodyPath; import weaver.xuanran.wang.traffic_bank.waco_first.entity.Info; -import weaver.xuanran.wang.util.FtpUtil; +import weaver.xuanran.wang.common.util.FtpUtil; import java.io.File; import java.lang.reflect.Field; @@ -44,7 +42,7 @@ public class WacoDataPushOAService { private static final String WACO_TEMP_PATH = File.separator + "WACO" + File.separator + "temp" + File.separator; private static final String INSERT_DOC_DETAIL_CONTENT_SQL = "insert into docdetailcontent(docid,doccontent) values(?,?)"; /** - *

+ *

从ftp上获取今日信息,整理成info对象集合

* @author xuanran.wang * @dateTime 2022/11/23 16:29 * @param connect ftp连接对象 @@ -85,43 +83,67 @@ public class WacoDataPushOAService { return infos; } + /** + *

将info对象写入建模

+ * @author xuanran.wang + * @dateTime 2022/11/23 21:33 + * @param modelId 模块id + * @param secCategory 目录id + * @param infos 对象集合 + **/ public void writeInfoToOA(int modelId, int secCategory, List infos) { String whereSql = "select 1 from " + CusInfoToOAUtil.TABLE_NAME_PLACEHOLDER + " where infoId = ?"; List ids = new ArrayList<>(); + // docDetailContent表参数 + List docDetailContentParams = new ArrayList<>(); try { for (Info info : infos) { - Map param = getParamsMapByInfo(secCategory, info); + List docDetailParam = new ArrayList<>(); + Map param = getParamsMapByInfo(secCategory, info, docDetailParam); int dataId = CusInfoToOAUtil.execute(modelId, param, whereSql, Collections.singletonList(info.getInfoId())); ids.add(String.valueOf(dataId)); + docDetailContentParams.add(docDetailParam); + } + RecordSet updateRs = new RecordSet(); + if (!updateRs.executeBatchSql(INSERT_DOC_DETAIL_CONTENT_SQL, docDetailContentParams)) { + throw new CustomerException("批量数据写入doc_detail_content表失败!, 当前参数: " + docDetailContentParams.get(0)); } }catch (Exception e){ logger.error(Util.logStr("写入建模出现异常:[{}]", e.getMessage())); + // sql用了in防止集合过大sql报错进行集合分割 List> splitList = CommonUtil.splitList(ids, CommonUtil.SQL_IN_PAGE_SIZE); for (List list : splitList) { if (!CusInfoToOAUtil.deleteModelDataByIds(String.valueOf(modelId), list)) { logger.error(Util.logStr("删除数据失败, 数据集合 : [{}] ", JSONObject.toJSONString(list))); } } + throw new RuntimeException("写入建模出现异常:" + e.getMessage()); } } /** - *

+ *

根据info对象获取插入数据库的参数

* @author xuanran.wang * @dateTime 2022/11/23 21:09 - * @param secCategory - * @param info - * @return + * @param secCategory 目录id + * @param info 数据对象 + * @return 参数 **/ - public Map getParamsMapByInfo(int secCategory, Info info) throws Exception { + public Map getParamsMapByInfo(int secCategory, Info info, List docDetailParam) throws Exception { Class clazz = info.getClass(); Field[] fields = clazz.getDeclaredFields(); HashMap res = new HashMap<>(); for (Field field : fields) { field.setAccessible(true); Object value = field.get(info); + // 进行日期解析 + CusDateFormat cusDate = field.getDeclaredAnnotation(CusDateFormat.class); + if(cusDate != null){ + value = CommonUtil.getDateByCusDateFormat(cusDate, value); + } + // 文件解析 BodyPath annotation = field.getDeclaredAnnotation(BodyPath.class); if(annotation != null){ DocInfo docInfo = new DocInfo(); @@ -131,10 +153,11 @@ public class WacoDataPushOAService { docInfo.setDoccontent(body); DocServiceImpl docService = new DocServiceImpl(); int docId = docService.createDocByUser(docInfo, new User(1)); - res.put(field.getName(), docId); - }else { - res.put(field.getName(), value); + docDetailParam.add(String.valueOf(docId)); + docDetailParam.add(body); + value = docId; } + res.put(field.getName(), value); } return res; } diff --git a/src/test/java/xuanran/wang/traffic_bank/waco_first/WacoFirstTest.java b/src/test/java/xuanran/wang/traffic_bank/waco_first/WacoFirstTest.java index f90842a..eb6c837 100644 --- a/src/test/java/xuanran/wang/traffic_bank/waco_first/WacoFirstTest.java +++ b/src/test/java/xuanran/wang/traffic_bank/waco_first/WacoFirstTest.java @@ -4,19 +4,12 @@ import aiyh.utils.excention.CustomerException; import basetest.BaseTest; import com.alibaba.fastjson.JSONObject; import org.apache.commons.collections.CollectionUtils; -import org.apache.commons.lang3.StringUtils; -import org.apache.log4j.DailyRollingFileAppender; -import org.apache.log4j.PatternLayout; -import org.apache.log4j.Priority; import org.junit.Test; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; import weaver.general.GCONST; import weaver.general.TimeUtil; import weaver.xuanran.wang.common.util.CommonUtil; import weaver.xuanran.wang.traffic_bank.waco_first.entity.Info; import weaver.xuanran.wang.traffic_bank.waco_first.service.WacoDataPushOAService; -import weaver.xuanran.wang.util.FtpUtil; import java.io.File; import java.util.ArrayList; diff --git a/常用信息.md b/常用信息.md index 95cda5e..519a8de 100644 --- a/常用信息.md +++ b/常用信息.md @@ -383,3 +383,48 @@ from workflow_nodebase nb ``` ### 后端 + +**1.后端根据请求获取登录用户信息** +> 维护人员:xuanran.wang +```java +User logInUser = HrmUserVarify.getUser(request, response)); +// 传入id会将此人员信息带出 +User user = new User(id); +// 获取人员id +user.getUID(); +``` + +**2.发送邮件** +> 维护人员:xuanran.wang +```java +/** + *

发送邮件

+ * @param address 邮箱地址 + * @param title 标题 + * @param content 正文 + **/ +EmailWorkRunnable.threadModeReminder(address, title, content); +``` + +**3.短信服务** +> 维护人员:xuanran.wang +```java +public class SendSms implements SmsService { + @Override + public boolean sendSMS(String smsId, String number, String msg) { + //执行短信调用接口逻辑 + return SMSUtil.sendSms(number,msg,url,sn,pwd); + } +} +``` +**4.三方插件文档转PDF(培训群找过来的)** +> 维护人员:xuanran.wang +```java +wps转PDF: +DocImagefileToPdfUseWps toPdfUseWps = new DocImagefileToPdfUseWps(); +newimagefileid = toPdfUseWps.officeDocumetnToPdfByImagefileid(docimagefileid); + +永中转PDF: +DocImagefileToPdf yozoToPdf = new DocImagefileToPdf(); +newimagefileid = yozoToPdf.officeDocumetnToPdfByImagefileid(docimagefileid); +``` \ No newline at end of file