wxr 2022-11-25威科数据先行代码编写以及增加常用信息文档后端1-4内容
parent
665107e3cf
commit
d4df5698ec
|
@ -30,7 +30,7 @@ log
|
|||
/file/
|
||||
/src/test/resources/application.properties
|
||||
/src/test/resources/application.xml
|
||||
/src/main/resources/file
|
||||
/file
|
||||
|
||||
DirectoryV2.xml
|
||||
|
||||
|
|
|
@ -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;
|
||||
|
||||
/**
|
||||
* <h1></h1>
|
||||
*
|
||||
* @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";
|
||||
}
|
|
@ -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");
|
||||
|
||||
/**
|
||||
* <h1>将文件解压至指定文件夹中</h1>
|
||||
* @author xuanran.wang
|
||||
|
@ -120,6 +122,7 @@ public class CommonUtil {
|
|||
}
|
||||
return builder.toString();
|
||||
}
|
||||
|
||||
/**
|
||||
* <h1>检查属性是否存在空值</h1>
|
||||
* @author xuanran.wang
|
||||
|
@ -158,6 +161,15 @@ public class CommonUtil {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* <h1>将集合进行分割</h1>
|
||||
* @author xuanran.wang
|
||||
* @dateTime 2022/11/25 16:01
|
||||
* @param list 待分割的集合
|
||||
* @param splitSize 分页大小
|
||||
* @return 分割集合
|
||||
**/
|
||||
public static <T> List<List<T>> splitList(List<T> list, int splitSize) {
|
||||
//判断集合是否为空
|
||||
if (CollectionUtils.isEmpty(list))
|
||||
|
@ -172,4 +184,33 @@ public class CommonUtil {
|
|||
.filter(b -> !b.isEmpty())
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
/**
|
||||
* <h1>通过自定义日期注解转换参数值</h1>
|
||||
* @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));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
|
||||
/**
|
||||
* <h1></h1>
|
||||
* <h1>ftpUtil</h1>
|
||||
*
|
||||
* @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());
|
||||
}
|
|
@ -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;
|
||||
|
|
|
@ -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;
|
||||
|
||||
|
|
|
@ -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(?,?)";
|
||||
/**
|
||||
* <h1></h1>
|
||||
* <h1>从ftp上获取今日信息,整理成info对象集合</h1>
|
||||
* @author xuanran.wang
|
||||
* @dateTime 2022/11/23 16:29
|
||||
* @param connect ftp连接对象
|
||||
|
@ -85,43 +83,67 @@ public class WacoDataPushOAService {
|
|||
return infos;
|
||||
}
|
||||
|
||||
/**
|
||||
* <h1>将info对象写入建模</h1>
|
||||
* @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<Info> infos) {
|
||||
String whereSql = "select 1 from " + CusInfoToOAUtil.TABLE_NAME_PLACEHOLDER + " where infoId = ?";
|
||||
List<String> ids = new ArrayList<>();
|
||||
// docDetailContent表参数
|
||||
List<List> docDetailContentParams = new ArrayList<>();
|
||||
try {
|
||||
for (Info info : infos) {
|
||||
Map<String, Object> param = getParamsMapByInfo(secCategory, info);
|
||||
List<String> docDetailParam = new ArrayList<>();
|
||||
Map<String, Object> 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<List<String>> splitList = CommonUtil.splitList(ids, CommonUtil.SQL_IN_PAGE_SIZE);
|
||||
for (List<String> list : splitList) {
|
||||
if (!CusInfoToOAUtil.deleteModelDataByIds(String.valueOf(modelId), list)) {
|
||||
logger.error(Util.logStr("删除数据失败, 数据集合 : [{}] ", JSONObject.toJSONString(list)));
|
||||
}
|
||||
}
|
||||
throw new RuntimeException("写入建模出现异常:" + e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* <h1></h1>
|
||||
* <h1>根据info对象获取插入数据库的参数</h1>
|
||||
* @author xuanran.wang
|
||||
* @dateTime 2022/11/23 21:09
|
||||
* @param secCategory
|
||||
* @param info
|
||||
* @return
|
||||
* @param secCategory 目录id
|
||||
* @param info 数据对象
|
||||
* @return 参数
|
||||
**/
|
||||
public Map<String, Object> getParamsMapByInfo(int secCategory, Info info) throws Exception {
|
||||
public Map<String, Object> getParamsMapByInfo(int secCategory, Info info, List<String> docDetailParam) throws Exception {
|
||||
Class<? extends Info> clazz = info.getClass();
|
||||
Field[] fields = clazz.getDeclaredFields();
|
||||
HashMap<String, Object> 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;
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
|
|
45
常用信息.md
45
常用信息.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
|
||||
/**
|
||||
* <h1>发送邮件</h1>
|
||||
* @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);
|
||||
```
|
Loading…
Reference in New Issue