wxr 2022-11-25威科数据先行代码编写以及增加常用信息文档后端1-4内容

main
wangxuanran 2022-11-25 16:32:54 +08:00
parent 665107e3cf
commit d4df5698ec
9 changed files with 153 additions and 31 deletions

2
.gitignore vendored
View File

@ -30,7 +30,7 @@ log
/file/
/src/test/resources/application.properties
/src/test/resources/application.xml
/src/main/resources/file
/file
DirectoryV2.xml

View File

@ -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";
}

View File

@ -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));
}
}
}

View File

@ -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());
}

View File

@ -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;

View File

@ -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;

View File

@ -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;
}

View File

@ -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;

View File

@ -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);
```