Compare commits

...

14 Commits
main ... dev

124 changed files with 9003 additions and 7511 deletions

4
.gitignore vendored
View File

@ -18,6 +18,7 @@ log
.idea/
#.gitignore
!.gitignore
*.iml
# Project files, i.e. `.project`, `.actionScriptProperties` and `.flexProperties`
# should NOT be excluded as they contain compiler settings and other important
# information for Eclipse / Flash Builder.
@ -37,6 +38,9 @@ DirectoryV2.xml
/lib/classbeanLib/web-inf-class-lib.jar
/lib/weaverLib/
*.groovy
*.log
src/main/resources/WEB-INF/sqllog/
java.io.tempdir/

View File

@ -1,8 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<module version="4">
<component name="NewModuleRootManager">
<content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$/src/test/resources" type="java-test-resource" />
</content>
</component>
</module>

View File

@ -3287,7 +3287,7 @@ public class Util extends weaver.general.Util {
throw new CustomerException("计划任务执行异常!异常信息:\n" + Util.getErrString(e));
}
getLogger().info(Util.logStr("\n\t计划任务 [{}] execute success!\n", cronJobClass.getName()));
getLogger().info(Util.logStr("\n\t计划任务 [{}] getDataId success!\n", cronJobClass.getName()));
}
@ -3358,7 +3358,7 @@ public class Util extends weaver.general.Util {
if (Action.FAILURE_AND_CONTINUE.equals(execute)) {
throw new CustomerException("action执行失败失败原因\n" + requestInfo.getRequestManager().getMessagecontent());
}
getLogger().info(Util.logStr("\n\n\tAction [{}] execute success!\n", actionClass.getName()));
getLogger().info(Util.logStr("\n\n\tAction [{}] getDataId success!\n", actionClass.getName()));
}
public static String getSetMethodName(String fieldName) {

View File

@ -30,7 +30,7 @@ public abstract class CusBaseAction implements Action {
/**
* requestInfo
*/
protected RequestInfo requestInfo;
protected RequestInfo globalRequestInfo;
/**
* <h2></h2>
@ -49,7 +49,7 @@ public abstract class CusBaseAction implements Action {
@Override
public final String execute(RequestInfo requestInfo) {
this.requestInfo = requestInfo;
this.globalRequestInfo = requestInfo;
RequestManager requestManager = requestInfo.getRequestManager();
String billTable = requestManager.getBillTableName();
String requestId = requestInfo.getRequestid();
@ -105,14 +105,12 @@ public abstract class CusBaseAction implements Action {
*/
public boolean exceptionCallback(Exception e, RequestManager requestManager) {
e.printStackTrace();
log.error(Util.logStr("execute action fail, exception message is [{}], error stack trace msg is: \n{}",
log.error(Util.logStr("getDataId action fail, exception message is [{}], error stack trace msg is: \n{}",
e.getMessage(), Util.getErrString(e)));
Util.actionFail(requestManager, e.getMessage());
return true;
}
;
/**
* <h2></h2>
@ -199,9 +197,26 @@ public abstract class CusBaseAction implements Action {
*
* @return
*/
@Deprecated
protected Map<String, String> getMainTableValue() {
// 获取主表数据
Property[] propertyArr = globalRequestInfo.getMainTableInfo().getProperty();
return getStringMap(propertyArr);
}
/**
* <h2></h2>
*
* @return
*/
protected Map<String, String> getMainTableValue(RequestInfo requestInfo) {
// 获取主表数据
Property[] propertyArr = requestInfo.getMainTableInfo().getProperty();
return getStringMap(propertyArr);
}
@NotNull
private Map<String, String> getStringMap(Property[] propertyArr) {
if (null == propertyArr) {
return Collections.emptyMap();
}
@ -220,8 +235,25 @@ public abstract class CusBaseAction implements Action {
*
* @return
*/
@Deprecated
protected Map<String, List<Map<String, String>>> getDetailTableValue() {
DetailTable[] detailTableArr = globalRequestInfo.getDetailTableInfo().getDetailTable();
return getListMap(detailTableArr);
}
/**
* <h2></h2>
*
* @return
*/
protected Map<String, List<Map<String, String>>> getDetailTableValue(RequestInfo requestInfo) {
DetailTable[] detailTableArr = requestInfo.getDetailTableInfo().getDetailTable();
return getListMap(detailTableArr);
}
@NotNull
private Map<String, List<Map<String, String>>> getListMap(DetailTable[] detailTableArr) {
Map<String, List<Map<String, String>>> detailDataList = new HashMap<>((int) Math.ceil(detailTableArr.length * 1.4));
for (DetailTable detailTable : detailTableArr) {
List<Map<String, String>> detailData = getDetailValue(detailTable);
@ -237,10 +269,21 @@ public abstract class CusBaseAction implements Action {
* @param detailNo
* @return
*/
@Deprecated
protected List<Map<String, String>> getDetailTableValueByDetailNo(int detailNo) {
DetailTable detailTable = globalRequestInfo.getDetailTableInfo().getDetailTable(detailNo);
return getDetailValue(detailTable);
}
/**
* <h2></h2>
*
* @param detailNo
* @return
*/
protected List<Map<String, String>> getDetailTableValueByDetailNo(int detailNo, RequestInfo requestInfo) {
DetailTable detailTable = requestInfo.getDetailTableInfo().getDetailTable(detailNo);
List<Map<String, String>> detailData = getDetailValue(detailTable);
return detailData;
return getDetailValue(detailTable);
}
/**

View File

@ -70,7 +70,7 @@ public abstract class Try<T> {
* .recover((t) -&gt; 1)
* returns Integer(1)
*
* @param f function to execute on successful result.
* @param f function to getDataId on successful result.
* @return new composed Try
*/

View File

@ -46,7 +46,7 @@ public class RecordsetUtil implements InvocationHandler {
boolean custom = select.custom();
PrepSqlResultImpl handler = sqlHandler.handler(sql, custom, method, args);
if (!handler.getSqlStr().trim().toLowerCase().startsWith("select ")) {
throw new CustomerException("The sql statement does not match, the @Select annotation can only execute the select statement, please check whether the sql statement matches!");
throw new CustomerException("The sql statement does not match, the @Select annotation can only getDataId the select statement, please check whether the sql statement matches!");
}
Util.getLogger("sql_log").info("解析sql===>" + handler);
if (handler.getArgs().isEmpty()) {
@ -64,7 +64,7 @@ public class RecordsetUtil implements InvocationHandler {
boolean custom = update.custom();
PrepSqlResultImpl handler = sqlHandler.handler(sql, custom, method, args);
if (!handler.getSqlStr().trim().toLowerCase().startsWith("update ")) {
throw new CustomerException("The sql statement does not match, the @Update annotation can only execute the update statement, please check whether the sql statement matches!");
throw new CustomerException("The sql statement does not match, the @Update annotation can only getDataId the update statement, please check whether the sql statement matches!");
}
Util.getLogger("sql_log").info(handler.toString());
Class<?> returnType = method.getReturnType();
@ -95,7 +95,7 @@ public class RecordsetUtil implements InvocationHandler {
boolean custom = insert.custom();
PrepSqlResultImpl handler = sqlHandler.handler(sql, custom, method, args);
if (!handler.getSqlStr().trim().toLowerCase().startsWith("insert ")) {
throw new CustomerException("The sql statement does not match, the @Insert annotation can only execute the insert statement, please check whether the sql statement matches!");
throw new CustomerException("The sql statement does not match, the @Insert annotation can only getDataId the insert statement, please check whether the sql statement matches!");
}
Util.getLogger("sql_log").info(handler.toString());
Class<?> returnType = method.getReturnType();
@ -119,7 +119,7 @@ public class RecordsetUtil implements InvocationHandler {
boolean custom = delete.custom();
PrepSqlResultImpl handler = sqlHandler.handler(sql, custom, method, args);
if (!handler.getSqlStr().trim().toLowerCase().startsWith("delete ")) {
throw new CustomerException("The sql statement does not match, the @Delete annotation can only execute the delete statement, please check whether the sql statement matches!");
throw new CustomerException("The sql statement does not match, the @Delete annotation can only getDataId the delete statement, please check whether the sql statement matches!");
}
Util.getLogger("sql_log").info(handler.toString());
Class<?> returnType = method.getReturnType();
@ -145,10 +145,10 @@ public class RecordsetUtil implements InvocationHandler {
BatchSqlResultImpl batchSqlResult = sqlHandler.handlerBatch(sql, custom, method, args);
Util.getLogger("sql_log").info(batchSqlResult.toString());
if (batchSqlResult.getBatchList().isEmpty()) {
throw new CustomerException("execute batch sql error , batch sql args is empty!");
throw new CustomerException("getDataId batch sql error , batch sql args is empty!");
}
if (!batchSqlResult.getSqlStr().trim().toLowerCase().startsWith("insert ")) {
throw new CustomerException("The sql statement does not match, the @Insert annotation can only execute the insert statement, please check whether the sql statement matches!");
throw new CustomerException("The sql statement does not match, the @Insert annotation can only getDataId the insert statement, please check whether the sql statement matches!");
}
boolean b = recordSet.executeBatchSql(batchSqlResult.getSqlStr(), batchSqlResult.getBatchList());
if (returnType.equals(void.class)) {
@ -168,10 +168,10 @@ public class RecordsetUtil implements InvocationHandler {
BatchSqlResultImpl batchSqlResult = sqlHandler.handlerBatch(sql, custom, method, args);
Util.getLogger("sql_log").info(batchSqlResult.toString());
if (batchSqlResult.getBatchList().isEmpty()) {
throw new CustomerException("execute batch sql error , batch sql args is empty!");
throw new CustomerException("getDataId batch sql error , batch sql args is empty!");
}
if (!batchSqlResult.getSqlStr().trim().toLowerCase().startsWith("update ")) {
throw new CustomerException("The sql statement does not match, the @Update annotation can only execute the update statement, please check whether the sql statement matches!");
throw new CustomerException("The sql statement does not match, the @Update annotation can only getDataId the update statement, please check whether the sql statement matches!");
}
boolean b = recordSet.executeBatchSql(batchSqlResult.getSqlStr(), batchSqlResult.getBatchList());
if (returnType.equals(void.class)) {
@ -191,10 +191,10 @@ public class RecordsetUtil implements InvocationHandler {
BatchSqlResultImpl batchSqlResult = sqlHandler.handlerBatch(sql, custom, method, args);
Util.getLogger("sql_log").info(batchSqlResult.toString());
if (batchSqlResult.getBatchList().isEmpty()) {
throw new CustomerException("execute batch sql error , batch sql args is empty!");
throw new CustomerException("getDataId batch sql error , batch sql args is empty!");
}
if (!batchSqlResult.getSqlStr().trim().toLowerCase().startsWith("delete ")) {
throw new CustomerException("The sql statement does not match, the @Delete annotation can only execute the delete statement, please check whether the sql statement matches!");
throw new CustomerException("The sql statement does not match, the @Delete annotation can only getDataId the delete statement, please check whether the sql statement matches!");
}
boolean b = recordSet.executeBatchSql(batchSqlResult.getSqlStr(), batchSqlResult.getBatchList());
if (returnType.equals(void.class)) {

View File

@ -0,0 +1,52 @@
package com.api.xuanran.wang.saic_travel.model_create_workflow.controller;
import aiyh.utils.ApiResult;
import aiyh.utils.Util;
import com.alibaba.fastjson.JSONObject;
import org.apache.log4j.Logger;
import weaver.hrm.HrmUserVarify;
import weaver.hrm.User;
import weaver.xuanran.wang.common.util.CommonUtil;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.ws.rs.*;
import javax.ws.rs.core.Context;
import javax.ws.rs.core.MediaType;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;
/**
* <h1>id</h1>
* @Author xuanran.wang
* @Date 2022/12/5 11:53
*/
@Path("/wxr/saicTravel/")
public class CusCreateWorkFlowController {
private final Logger logger = Util.getLogger();
@Path("cusCreateWorkFlow")
@POST
@Produces(MediaType.TEXT_PLAIN)
public String getOrgChartTree(@Context HttpServletRequest request, @Context HttpServletResponse response) {
User logInUser = HrmUserVarify.getUser(request, response);
if(logInUser == null){
return ApiResult.error(403,"请先登录!");
}
String choiceData = request.getParameter("choiceData");
int modelId = Util.getIntValue(request.getParameter("modelId"), -1);
List<String> dataList = Arrays.stream(choiceData.split(",")).collect(Collectors.toList());
List<String> requestIds = CommonUtil.doCreateWorkFlow(modelId, dataList);
List<String> errorData = new ArrayList<>();
for (int i = 0; i < requestIds.size(); i++) {
if (Util.getIntValue(requestIds.get(i), -1) < 0) {
errorData.add(dataList.get(i));
}
}
logger.error(Util.logStr("执行创建流程失败集合: {}",JSONObject.toJSONString(errorData)));
return ApiResult.success(errorData);
}
}

View File

@ -44,7 +44,7 @@ public interface OrgChartMapper {
" inner join hrmjobtitles job on hrm.JOBTITLE = job.id " +
" inner join cus_fielddata cus on cus.ID = hrm.ID " +
" and cus.SCOPE = 'HrmCustomFieldByInfoType' " +
" and cus.SCOPEID = -1 " +
" and cus.SCOPEID = 1 " +
" inner join hrmdepartment dept on dept.id = hrm.DEPARTMENTID " +
"where hrm.status in (0, 1)")
List<HrmResource> selectAll(@ParamMapper("typeOfEmploymentFiled") String typeOfEmploymentField,

View File

@ -1,6 +1,7 @@
package com.api.youhong.ai.pcn.organization.orgchart.service;
import aiyh.utils.Util;
import aiyh.utils.excention.CustomerException;
import cn.hutool.core.lang.Assert;
import com.api.youhong.ai.pcn.organization.orgchart.dto.HrmResourceDto;
import com.api.youhong.ai.pcn.organization.orgchart.mapper.OrgChartMapper;
@ -45,28 +46,17 @@ public class OrgChartService {
String lastNameEnField = Util.getCusConfigValue("lastNameEnField");
Assert.notBlank(lastNameEnField, "config [lastNameEnField] is null or blank!");
List<HrmResource> hrmResourceList = mapper.selectAll(typeOfEmploymentField, lastNameEnField);
if (Objects.isNull(hrmResourceList) || hrmResourceList.isEmpty()) {
throw new CustomerException("查询不到相关人员!");
}
//List<HrmResourceDto> hrmResourceDtoList = new ArrayList();
AtomicReference<HrmResourceDto> currentUser = new AtomicReference<>();
/* ******************* 将pojo转换为Dto对象对节点属性默认值赋值找出当前用户并设置显示 ******************* */
List<HrmResourceDto> hrmResourceDtoList = hrmResourceList.stream()
.map(struct::hrmResourceToDto)
.peek(item -> Builder.startSet(item)
.with(HrmResourceDto::setShow, 0)
.with(HrmResourceDto::setShowBrother, 0)
.with(HrmResourceDto::setShowChildren, 0)
.endSet())
.collect(Collectors.toList());
hrmResourceDtoList.stream()
.filter(item -> item.getId() == userId)
.forEach(item -> {
Builder.startSet(item)
.with(HrmResourceDto::setShow, 1)
.with(HrmResourceDto::setShowBrother, 1)
.with(HrmResourceDto::setShowChildren, 1)
.with(HrmResourceDto::setCurrent, true)
.endSet();
currentUser.set(item);
});
List<HrmResourceDto> hrmResourceDtoList = hrmResourceList.stream().map(struct::hrmResourceToDto).peek(item -> Builder.startSet(item).with(HrmResourceDto::setShow, 0).with(HrmResourceDto::setShowBrother, 0).with(HrmResourceDto::setShowChildren, 0).endSet()).collect(Collectors.toList());
hrmResourceDtoList.stream().filter(item -> item.getId() == userId).forEach(item -> {
Builder.startSet(item).with(HrmResourceDto::setShow, 1).with(HrmResourceDto::setShowBrother, 1).with(HrmResourceDto::setShowChildren, 1).with(HrmResourceDto::setCurrent, true).endSet();
currentUser.set(item);
});
Assert.notNull(currentUser, "not find current login user info!");
/* ******************* 查找当前登陆人员的所有上级 ******************* */
String currentUserManagerStr = currentUser.get().getManagerStr();
@ -74,16 +64,9 @@ public class OrgChartService {
currentUserManagerStr = "";
}
currentUserManagerStr = Util.removeSeparator(currentUserManagerStr, ",");
List<Integer> currentUserManagerList = Arrays.stream(currentUserManagerStr.split(","))
.map(Integer::parseInt)
.collect(Collectors.toList());
List<Integer> currentUserManagerList = Arrays.stream(currentUserManagerStr.split(",")).map(Integer::parseInt).collect(Collectors.toList());
/* ******************* 对当前用户的所有直接上级设置标识 ******************* */
hrmResourceDtoList.stream()
.filter(item -> currentUserManagerList.contains(item.getId()))
.forEach(item -> Builder.startSet(item)
.with(HrmResourceDto::setShowChildren, 1)
.with(HrmResourceDto::setCurrentParent, true)
.endSet());
hrmResourceDtoList.stream().filter(item -> currentUserManagerList.contains(item.getId())).forEach(item -> Builder.startSet(item).with(HrmResourceDto::setShowChildren, 1).with(HrmResourceDto::setCurrentParent, true).endSet());
/* ******************* 查询当前用户的是否全部展示或显示小红点的配置信息 ******************* */
ShowPointOrAll showPointOrAll = mapper.selectShowPointOrAll(userId);
@ -92,34 +75,21 @@ public class OrgChartService {
/* ******************* 转换dto为Vo并且设置根节点标识 ******************* */
orgChartNodeVoList = hrmResourceDtoList.stream()
.map(struct::hrmResourceDtoToVo)
.peek(item -> item.setType(-1))
.collect(Collectors.toList());
} else {
/* ******************* 转换dto为Vo并且设置根节点标识 ******************* */
orgChartNodeVoList = hrmResourceDtoList.stream()
.map(struct::hrmResourceDtoToVo)
.peek(item -> {
if (showPointOrAll.isShowAll()) {
Builder.startSet(item)
.with(OrgChartNodeVo::setShow, 1)
.with(OrgChartNodeVo::setShowBrother, 1)
.with(OrgChartNodeVo::setShowChildren, 1)
.endSet();
}
if (!showPointOrAll.isShowType()) {
item.setType(-1);
}
})
.collect(Collectors.toList());
orgChartNodeVoList = hrmResourceDtoList.stream().map(struct::hrmResourceDtoToVo).peek(item -> {
if (showPointOrAll.isShowAll()) {
Builder.startSet(item).with(OrgChartNodeVo::setShow, 1).with(OrgChartNodeVo::setShowBrother, 1).with(OrgChartNodeVo::setShowChildren, 1).endSet();
}
if (!showPointOrAll.isShowType()) {
item.setType(-1);
}
}).collect(Collectors.toList());
}
return Util.listToTree(orgChartNodeVoList, OrgChartNodeVo::getId,
OrgChartNodeVo::getManagerId, OrgChartNodeVo::getChildren,
OrgChartNodeVo::setChildren,
parentId -> parentId == null || parentId <= 0)
.stream()
.peek(item -> item.setIsRoot(true))
.peek(item -> recursionChildrenNums(item, 0))
.collect(Collectors.toList());
return Util.listToTree(orgChartNodeVoList, OrgChartNodeVo::getId, OrgChartNodeVo::getManagerId, OrgChartNodeVo::getChildren, OrgChartNodeVo::setChildren, parentId -> parentId == null || parentId <= 0).stream().peek(item -> item.setIsRoot(true)).peek(item -> recursionChildrenNums(item, 0)).collect(Collectors.toList());
}

View File

@ -34,4 +34,14 @@ public class MultipartFile {
*
*/
Long fileSize;
/**
* id
*/
private Integer imageFileId;
/**
* docId
*/
private Integer docId;
}

View File

@ -5,10 +5,15 @@ import java.util.HashMap;
import java.util.Map;
/**
* <h1></h1>
* @author XiaoBokang
* @create 2022/6/14 12:56
* <h1> : </h1>
* <p>
* v2.0 xuanran.wang 2022-12-06
* Object
* </p>
*/
public enum ParamTypeEnum {
STRING("0"),
@ -21,7 +26,8 @@ public enum ParamTypeEnum {
CUS_DATE_STR("7"),
TIME_STAMP("8"),
DATE_VAL("9"),
Boolean("10");
Boolean("10"),
Object("11");
private static final Map<String, ParamTypeEnum> LOOK_UP = new HashMap<>(8);

View File

@ -537,7 +537,12 @@ public class DealWithMapping extends ToolUtil {
* @param mainMap
* @param detailMap
* @param mappingDetail
* @return
*
* <h1>:</h1>
* <p>
* v2.0 xuanran.wang
* {?requestid}requestid {?}
* <p>
*/
private Object normalValueDeal(Map<String, Object> mainMap, Map<String, Object> detailMap, MappingDetail mappingDetail) {
@ -563,7 +568,19 @@ public class DealWithMapping extends ToolUtil {
break;
// 默认值
case DEFAULT_VALUE: {
value = valueContext;
FieldMessage fieldMassage = mappingDetail.getFieldMassage();
String workFlowVal = "";
if(fieldMassage != null){
String fieldName = fieldMassage.getFieldName().toLowerCase();
if ("1".equals(childSource)) {
workFlowVal = Util.null2String(detailMap.get(fieldName));
} else if ("0".equals(childSource)) {
workFlowVal = Util.null2String(mainMap.get(fieldName));
}
}
value = Util.null2String(valueContext)
.replace("{?requestid}", String.valueOf(mainMap.get("requestid")))
.replace("{?}", workFlowVal);
}
break;
// 当前时间
@ -764,6 +781,9 @@ public class DealWithMapping extends ToolUtil {
value = Boolean.valueOf(String.valueOf(value));
}
break;
case Object:{
// 当是object类型时不转换 保留原有格式
}break;
default:
return value;
}
@ -778,7 +798,12 @@ public class DealWithMapping extends ToolUtil {
* @param detailMap
* @param mappingDetail
* @param relationRs
* @return
*
* <h1>:</h1>
* <p>
* v2.0 xuanran.wang
* {?requestid}requestid {?}
* <p>
*/
private Object normalValueDeal(Map<String, Object> mainMap, Map<String, Object> detailMap, RecordSet relationRs, MappingDetail mappingDetail) {
String paramType = mappingDetail.getParamType();
@ -810,7 +835,24 @@ public class DealWithMapping extends ToolUtil {
break;
// 默认值
case DEFAULT_VALUE: {
value = valueContext;
FieldMessage fieldMassage = mappingDetail.getFieldMassage();
String workFlowVal = "";
if(fieldMassage != null){
String fieldName = fieldMassage.getFieldName().toLowerCase();
if ("1".equals(childSource)) {
workFlowVal = Util.null2String(detailMap.get(fieldName));
} else if ("0".equals(childSource)) {
workFlowVal = Util.null2String(mainMap.get(fieldName));
} else {
workFlowVal = Util.null2String(relationRs.getString(fieldName));
}
if ("rootNode".equals(mappingDetail.getBelongTo()) && "2".equals(childSource)) {
workFlowVal = Util.null2String(tempRs.getString(fieldName));
}
}
value = Util.null2String(valueContext)
.replace("{?requestid}", String.valueOf(mainMap.get("requestid")))
.replace("{?}", workFlowVal);
}
break;
// 当前时间
@ -893,6 +935,8 @@ public class DealWithMapping extends ToolUtil {
MultipartFile multipartFile = new MultipartFile();
InputStream fileInputStream = ImageFileManager.getInputStreamById(docImageFile.getImageFileId());
multipartFile.setFileKey(paramName);
multipartFile.setImageFileId(docImageFile.getImageFileId());
multipartFile.setDocId(docImageFile.getDocId());
multipartFile.setStream(fileInputStream);
multipartFile.setFileName(docImageFile.getImageFileName());
multipartFile.setFileSize(docImageFile.getFileSize() / 1024);
@ -1024,6 +1068,9 @@ public class DealWithMapping extends ToolUtil {
value = Boolean.valueOf(String.valueOf(value));
}
break;
case Object:{
// 当是object类型时不转换 保留原有格式
}break;
default:
return value;
}

View File

@ -6,7 +6,7 @@ import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
/**
* <h1></h1>
* <h1></h1>
*
* @Author xuanran.wang
* @Date 2022/11/25 15:55
@ -14,6 +14,12 @@ import java.lang.annotation.Target;
@Target({ElementType.FIELD,ElementType.TYPE})
@Retention(RetentionPolicy.RUNTIME)
public @interface CusDateFormat {
/**
* <h2></h2>
**/
String from();
/**
* <h2></h2>
**/
String to() default "yyyy-MM-dd";
}

View File

@ -1,11 +1,9 @@
package weaver.xuanran.wang.common.mapper;
import aiyh.utils.annotation.recordset.Delete;
import aiyh.utils.annotation.recordset.ParamMapper;
import aiyh.utils.annotation.recordset.Select;
import aiyh.utils.annotation.recordset.SqlMapper;
import aiyh.utils.annotation.recordset.*;
import java.util.List;
import java.util.Map;
/**
* @Author xuanran.wang
@ -43,4 +41,13 @@ public interface CommonMapper {
@Delete("delete from $t{tableName} where id in (${ids})")
boolean deleteModelDataByIds(@ParamMapper("tableName") String tableName,
@ParamMapper("ids") List<String> ids);
@Select("SELECT mp.id,m.formId,mpd.triggerWorkflowSetId " +
"FROM MODE_PageExpand mp " +
"INNER JOIN modeInfo m " +
"on mp.modeId = m.id " +
"LEFT JOIN mode_pageExpandDetail mpd " +
"ON mp.id = mpd.mainId " +
"WHERE mp.modeid = #{modelId} AND mp.isSystem = 1 AND mp.iSSystemFlag = 1")
Map<String, Integer> getExpendConfigByModeId(@ParamMapper("modelId") int modelId);
}

View File

@ -2,16 +2,24 @@ package weaver.xuanran.wang.common.util;
import aiyh.utils.Util;
import aiyh.utils.excention.CustomerException;
import com.alibaba.fastjson.JSONObject;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.collections.MapUtils;
import org.apache.commons.io.FileUtils;
import org.apache.commons.lang3.StringUtils;
import org.apache.log4j.Logger;
import weaver.conn.RecordSet;
import weaver.formmode.data.ModeDataApproval;
import weaver.hrm.User;
import weaver.xuanran.wang.common.annocation.CusDateFormat;
import weaver.xuanran.wang.common.annocation.ParamNotNull;
import weaver.xuanran.wang.common.mapper.CommonMapper;
import java.io.*;
import java.lang.reflect.Field;
import java.nio.charset.Charset;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.*;
@ -26,12 +34,26 @@ import java.util.zip.ZipFile;
* @Date 2022/11/23 10:25
*/
public class CommonUtil {
private final Logger logger = Util.getLogger();
public static final int SQL_IN_PAGE_SIZE = 100;
private static final SimpleDateFormat DATE_FORMAT = new SimpleDateFormat("yyyy-MM-dd");
/**
* <h2></h2>
**/
private static final Logger logger = Util.getLogger(CommonUtil.class.getName());
/**
* <h2>sqlin</h2>
**/
public static int SQL_IN_PAGE_SIZE = 100;
/**
* <h2></h2>
**/
public static int DEL_MAX_COUNT = 5;
/**
* <h2>线</h2>
**/
public static int THREAD_SLEEP = 200;
/**
* <h2>mapper</h2>
**/
private static final CommonMapper commonMapper = Util.getMapper(CommonMapper.class);
/**
* <h1></h1>
@ -47,6 +69,8 @@ public class CommonUtil {
}
// 开始解压
ZipFile zipFile = null;
InputStream is = null;
FileOutputStream fos = null;
try {
zipFile = new ZipFile(new File(srcFilePath), Charset.forName("GBK"));
Enumeration<?> entries = zipFile.entries();
@ -55,16 +79,25 @@ public class CommonUtil {
if (entry.isDirectory()) {
String dirPath = acceptFilePath + File.separator + entry.getName();
File dir = new File(dirPath);
dir.mkdirs();
boolean mkdirs = dir.mkdirs();
if(!mkdirs){
throw new CustomerException("创建文件夹失败!, 文件夹路径:[ " + dirPath + " ]");
}
} else {
String temp = acceptFilePath + File.separator + entry.getName();
File targetFile = new File(temp);
if(!targetFile.getParentFile().exists()){
targetFile.getParentFile().mkdirs();
boolean mkdirs = targetFile.getParentFile().mkdirs();
if(!mkdirs){
throw new CustomerException("创建文件夹失败!, 文件夹路径:[ " + targetFile.getParentFile() + " ]");
}
}
targetFile.createNewFile();
InputStream is = zipFile.getInputStream(entry);
FileOutputStream fos = new FileOutputStream(targetFile);
boolean newFile = targetFile.createNewFile();
if(!newFile){
throw new CustomerException("创建文件失败!, 文件路径:[ " + temp + " ]");
}
is = zipFile.getInputStream(entry);
fos = new FileOutputStream(targetFile);
int len;
byte[] buf = new byte[1024];
while ((len = is.read(buf)) != -1) {
@ -85,6 +118,20 @@ public class CommonUtil {
e.printStackTrace();
}
}
if(fos != null){
try {
fos.close();
} catch (IOException e) {
e.printStackTrace();
}
}
if(is != null){
try {
is.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
}
@ -102,14 +149,17 @@ public class CommonUtil {
File file = new File(filePath);
BufferedReader reader = null;
StringBuilder builder = new StringBuilder();
FileReader fileReader = null;
try {
reader = new BufferedReader(new FileReader(file));
fileReader = new FileReader(file);
reader = new BufferedReader(fileReader);
String tempString = null;
// 一次读入一行直到读入null为文件结束
while ((tempString = reader.readLine()) != null) {
builder.append(tempString);
}
reader.close();
fileReader.close();
} catch (IOException e) {
e.printStackTrace();
} finally {
@ -117,6 +167,14 @@ public class CommonUtil {
try {
reader.close();
} catch (IOException ie) {
logger.error("关闭io流异常, " + ie.getMessage());
}
}
if(fileReader != null){
try {
fileReader.close();
} catch (IOException ie) {
logger.error("关闭io流异常, " + ie.getMessage());
}
}
}
@ -129,7 +187,7 @@ public class CommonUtil {
* @dateTime 2022/11/23 15:59
* @param t
**/
public static <T> void checkParamNotNull(T t) throws IllegalAccessException {
public static <T> void checkParamNotNull(T t){
Class<?> clazz = t.getClass();
Field[] fields = clazz.getDeclaredFields();
for (Field field : fields) {
@ -138,7 +196,12 @@ public class CommonUtil {
continue;
}
field.setAccessible(true);
Object value = field.get(t);
Object value = null;
try {
value = field.get(t);
}catch (IllegalAccessException e){
throw new CustomerException("获取类字段值异常: " + e.getMessage());
}
Class<?> valueClass = field.getType();
boolean isNull = false;
if(valueClass.isAssignableFrom(String.class)){
@ -180,8 +243,10 @@ public class CommonUtil {
return Stream.iterate(0, n -> n + 1)
.limit(maxSize)
.parallel()
.map(a -> list.parallelStream().skip((long) a * splitSize).limit(splitSize).collect(Collectors.toList()))
.filter(b -> !b.isEmpty())
.map(a -> list.parallelStream()
.skip((long) a * splitSize).limit(splitSize)
.collect(Collectors.toList())
).filter(b -> !b.isEmpty())
.collect(Collectors.toList());
}
/**
@ -213,4 +278,245 @@ public class CommonUtil {
throw new RuntimeException(Util.logStr("解析日期失败!当前传入转化格式:[{}],待转化日期:[{}]", to, date));
}
}
/**
* <h1>id</h1>
* @author xuanran.wang
* @dateTime 2022/11/28 12:07
* @param ids
* @param tableName
* @return true/false
**/
public static boolean deleteDataByIds(List<String> ids, String tableName) {
return deleteDataByIds(ids, tableName, SQL_IN_PAGE_SIZE);
}
/**
* <h1>id</h1>
* @author xuanran.wang
* @dateTime 2022/11/28 12:07
* @param ids id
* @param modelId id
* @return true/false
**/
public static boolean deleteDataByIds(List<String> ids, int modelId) {
return deleteDataByIds(ids, modelId, SQL_IN_PAGE_SIZE);
}
/**
* <h1>id</h1>
* @author xuanran.wang
* @dateTime 2022/11/28 12:07
* @param ids
* @param modelId id
* @param pageSize SQL in
* @return true/false
**/
public static boolean deleteDataByIds(List<String> ids, int modelId, int pageSize) {
String tableName = commonMapper.getModelNameByModelId(String.valueOf(modelId));
if(StringUtils.isBlank(tableName)){
throw new CustomerException("模块id : " + modelId + ",表名在系统中没有找到!");
}
return deleteDataByIds(ids, tableName, pageSize);
}
/**
* <h1>id</h1>
* @author xuanran.wang
* @dateTime 2022/11/28 12:08
* @param ids id
* @param tableName
* @param pageSize SQL in
* @return true/false
**/
public static boolean deleteDataByIds(List<String> ids, String tableName,int pageSize) {
List<List<String>> lists = CommonUtil.splitList(ids, pageSize);
for (List<String> list : lists) {
boolean success = commonMapper.deleteModelDataByIds(tableName, list);
if(!success){
logger.error(Util.logStr("删除数据失败, 数据集合 : [{}] ", JSONObject.toJSONString(list)));
}
return success;
}
return false;
}
/**
* <h1></h1>
* @author xuanran.wang
* @dateTime 2022/12/1 14:55
* @param path
* @return
**/
public static boolean delFile(String path) throws IOException {
File file = new File(path);
if(!file.exists()){
return true;
}
boolean deleteFlag = true;
int n = 0;
while (deleteFlag) {
try {
n++;
System.gc();
if(file.isDirectory()){
FileUtils.deleteDirectory(file);
}else {
Files.delete(Paths.get(path));
}
deleteFlag = false;
} catch (Exception e) {
try {
Thread.sleep(THREAD_SLEEP);
} catch (InterruptedException interruptedException) {
logger.info(Util.logStr("interruptedException : {}",interruptedException.getMessage()));
}
if (n > DEL_MAX_COUNT) {
deleteFlag = false;
logger.error("临时文件删除失败!路径: " + path);
}
}
}
return false;
}
/**
* <h1></h1>
* @author xuanran.wang
* @dateTime 2022/11/15 22:20
* @param map map
* @param clazz class
* @return
**/
public static <T> T getInstance(Map<String, Object> map, Class<T> clazz) {
if(MapUtils.isEmpty(map)){
throw new CustomerException("getInstance参数map不能为空!");
}
T res = null;
try {
res = clazz.newInstance();
Field[] fields = clazz.getDeclaredFields();
for (Field field : fields) {
// 判断字段类型
if (field.getType().isAssignableFrom(List.class) || field.getType().isAssignableFrom(Map.class)) {
continue;
}
field.setAccessible(true);
String fieldName = field.getName();
String value = Util.null2String(map.get(fieldName));
// oracle数据库大写
if(StringUtils.isBlank(value)){
value = Util.null2String(map.get(fieldName.toUpperCase()));
}
field.set(res, value);
}
} catch (Exception e) {
throw new RuntimeException("实体类生成异常");
}
return res;
}
/**
* <h1></h1>
* @author xuanran.wang
* @dateTime 2022/11/15 22:20
* @param queryRs
* @param clazz class
* @return
**/
public static <T> T getInstance(RecordSet queryRs, Class<T> clazz) {
T res = null;
try {
res = clazz.newInstance();
Field[] fields = clazz.getDeclaredFields();
for (Field field : fields) {
// 判断字段类型
if (field.getType().isAssignableFrom(List.class) || field.getType().isAssignableFrom(Map.class)) {
continue;
}
field.setAccessible(true);
String fieldName = field.getName();
if ("oracle".equals(queryRs.getDBType())) {
fieldName = fieldName.toUpperCase();
}
String value = weaver.general.Util.null2String(queryRs.getString(fieldName));
field.set(res, value);
}
} catch (Exception e) {
throw new RuntimeException("实体类生成异常");
}
return res;
}
/**
* <h2>Date</h2>
*
* @param dateStr
* @return
*/
public static Date parseDate(String dateStr) {
ThreadLocal<SimpleDateFormat> SIMPLE_DATE_FORMAT = ThreadLocal.withInitial(() -> new SimpleDateFormat("yyyy-MM-dd"));
if (dateStr == null || dateStr.length() == 0) {
return null;
}
String regex = "\\/|\\.|年|月|日";
Date date = null;
try {
date = SIMPLE_DATE_FORMAT.get().parse(dateStr.replaceAll(regex, "-"));
return date;
} catch (ParseException e) {
throw new CustomerException("无法将" + dateStr + "转换为日期对象!", e);
}
}
/**
* <h2></h2>
*
* @param date
* @param tempStr
* @return
*/
public static String diyDateFortMat(Date date, String tempStr) {
SimpleDateFormat simpleDateFormat = new SimpleDateFormat(tempStr);
return simpleDateFormat.format(date);
}
/**
* <h1></h1>
* @author xuanran.wang
* @dateTime 2022/12/1 21:14
* @param modeId id
* @param dataIds id
**/
public static List<String> doCreateWorkFlow(int modeId, List<String> dataIds){
if(modeId < 0){
throw new CustomerException("模块id不能小于0!");
}
if(org.springframework.util.CollectionUtils.isEmpty(dataIds)){
logger.info("暂无数据要生成流程!");
return Collections.emptyList();
}
Map<String, Integer> expendConfig = commonMapper.getExpendConfigByModeId(modeId);
logger.info(Util.logStr("expendConfig {}", JSONObject.toJSONString(expendConfig)));
int expendId = expendConfig.get("id");
int formId = expendConfig.get("formId");
int triggerWorkflowSetId = expendConfig.get("triggerWorkflowSetId");
ArrayList<String> requestIds = new ArrayList<>();
if(expendId > 0 && triggerWorkflowSetId > 0){
for (String daId : dataIds) {
ModeDataApproval modeDataApproval = new ModeDataApproval();
modeDataApproval.setUser(new User(1));
modeDataApproval.setBillid(Util.getIntValue(daId));
modeDataApproval.setFormid(formId);
modeDataApproval.setModeid(modeId);
modeDataApproval.setTriggerWorkflowSetId(triggerWorkflowSetId);
modeDataApproval.setPageexpandid(expendId);
Map<String, String> resMap = modeDataApproval.approvalDataResult();
logger.info(Util.logStr("模块数据id : {}, 创建流程结果 : {}", daId, JSONObject.toJSONString(resMap)));
requestIds.add(Util.null2String(resMap.get("requestid")));
}
}
return requestIds;
}
}

View File

@ -2,9 +2,11 @@ package weaver.xuanran.wang.common.util;
import aiyh.utils.Util;
import aiyh.utils.excention.CustomerException;
import aiyh.utils.sqlUtil.sqlResult.impl.PrepSqlResultImpl;
import aiyh.utils.sqlUtil.sqlResult.impl.BatchSqlResultImpl;
import aiyh.utils.sqlUtil.whereUtil.Where;
import com.alibaba.fastjson.JSONObject;
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.conn.RecordSet;
@ -13,8 +15,7 @@ import weaver.formmode.setup.ModeRightInfo;
import weaver.general.TimeUtil;
import weaver.xuanran.wang.common.mapper.CommonMapper;
import java.util.List;
import java.util.Map;
import java.util.*;
/**
* @Author xuanran.wang
@ -25,7 +26,21 @@ public class CusInfoToOAUtil {
private static final ModeDataIdUpdate modeDataIdUpdate = ModeDataIdUpdate.getInstance();
private static final ModeRightInfo moderightinfo = new ModeRightInfo();
private static final Logger log = Util.getLogger();
public static final String TABLE_NAME_PLACEHOLDER = "#\\{table}";
public static final String TABLE_NAME_PLACEHOLDER = "#\\{tableName}";
/**
* <h1></h1>
* @author xuanran.wang
* @dateTime 2022/11/23 17:00
* @param modelId id
* @param params map
* @return id
**/
public static String getDataId(int modelId,
Map<String, Object> params) {
return getDataId(modelId, params, "", Collections.emptyList());
}
/**
* <h1></h1>
* @author xuanran.wang
@ -36,10 +51,61 @@ public class CusInfoToOAUtil {
* @param whereParams
* @return id
**/
public static int execute(int modelId,
Map<String, Object> params,
String whereSql,
List<String> whereParams) {
public static String getDataId(int modelId,
Map<String, Object> params,
String whereSql,
List<String> whereParams) {
return getDataId(modelId, params, whereSql, whereParams, true);
}
/**
* <h1></h1>
* @author xuanran.wang
* @dateTime 2022/11/23 17:00
* @param modelId id
* @param params map
* @param whereSql sql
* @param whereParams
* @param needDel
* @return id
**/
public static String getDataId(int modelId,
Map<String, Object> params,
String whereSql,
List<String> whereParams,
boolean needDel) {
return executeBatch(modelId, Collections.singletonList(new LinkedHashMap<>(params)), whereSql, whereParams, needDel).get(0);
}
/**
* <h1></h1>
* @author xuanran.wang
* @dateTime 2022/11/23 17:00
* @param modelId id
* @param params map
* @return id
**/
public static List<String> executeBatch( int modelId,
List<LinkedHashMap<String, Object>> params) {
return executeBatch(modelId, params, "", Collections.emptyList(), true);
}
/**
* <h1></h1>
* @author xuanran.wang
* @dateTime 2022/11/23 17:00
* @param modelId id
* @param params map
* @param whereSql sql
* @param whereParams
* @param needDel
* @return id
**/
public static List<String> executeBatch( int modelId,
List<LinkedHashMap<String, Object>> params,
String whereSql,
List<String> whereParams,
boolean needDel) {
if(modelId < 0){
throw new RuntimeException("建模模块id不能小于0!");
}
@ -47,37 +113,74 @@ public class CusInfoToOAUtil {
if(StringUtils.isBlank(tableName)){
throw new CustomerException("模块id为 " + modelId + ", 在系统中暂没查询到对应表单!");
}
RecordSet rs = new RecordSet();
int mainId = -1;
boolean needModeRight = false;
return executeBatch(modelId, tableName, params, whereSql, whereParams, needDel);
}
/**
* <h1></h1>
* @author xuanran.wang
* @dateTime 2022/11/23 17:00
* @param modelId id
* @param tableName
* @param params map
* @param whereSql sql
* @param whereParams
* @param needDel
* @return id
**/
public static List<String> executeBatch( int modelId,
String tableName,
List<LinkedHashMap<String, Object>> params,
String whereSql,
List<String> whereParams,
boolean needDel) {
// 如果要对模块数据中重复的进行更新则判断待插入的集合大小和判断重复的集合大小参数长度是否一致
if(StringUtils.isNotBlank(whereSql)){
whereSql = whereSql.replaceAll(TABLE_NAME_PLACEHOLDER, tableName);
if (rs.executeQuery(whereSql, whereParams) && rs.next()) {
mainId = Util.getIntValue(rs.getString(1),-1);
if(CollectionUtils.isEmpty(whereParams) || CollectionUtils.isEmpty(params) || whereParams.size() != params.size()){
throw new CustomerException("使用批量更新时如果需要对重复数据进行更新,参数集合和判断重复参数集合大小必须相等!");
}
}
if(mainId < 0){
mainId = getNewIdByModelInfo(tableName, modelId);
needModeRight = true;
RecordSet rs = new RecordSet();
List<String> dataIds = new ArrayList<>();
List<Where> wheres = new ArrayList<>();
for (int i = 0; i < params.size(); i++) {
int mainId = -1;
if(StringUtils.isNotBlank(whereSql)){
whereSql = Util.sbc2dbcCase(whereSql);
whereSql = whereSql.replaceAll(TABLE_NAME_PLACEHOLDER, tableName);
log.info("whereSql : " + whereSql);
log.info("参数 : " + whereParams);
if (rs.executeQuery(whereSql, whereParams) && rs.next()) {
mainId = Util.getIntValue(rs.getString(1),-1);
}
}
if(mainId < 0){
mainId = getNewIdByModelInfo(tableName, modelId);
}
dataIds.add(String.valueOf(mainId));
wheres.add(Util.createPrepWhereImpl().whereAnd("id").whereEqual(mainId));
}
Where where = Util.createPrepWhereImpl()
.whereAnd("id").whereEqual(mainId);
PrepSqlResultImpl sqlResult = Util.createSqlBuilder().updateSql(
tableName,
params,
where
);
if (!rs.executeUpdate(sqlResult.getSqlStr(), sqlResult.getArgs())) {
String error = Util.logStr("错误信息写入建模后置处理执行更新sql失败!" +
" 当前sql [{}], 当前参数 [{}], where条件[{}]", sqlResult.getSqlStr(),
JSONObject.toJSONString(sqlResult.getArgs()), mainId);
log.error(error);
throw new CustomerException(error);
BatchSqlResultImpl batchSql = Util.createSqlBuilder().updateBatchSql(tableName, params, wheres);
String sqlStr = batchSql.getSqlStr();
List<List> batchList = batchSql.getBatchList();
if(!rs.executeBatchSql(sqlStr, batchList)){
log.error(Util.logStr("batchSql:{}", sqlStr));
log.error(Util.logStr("batchList:{}", JSONObject.toJSONString(batchList)));
log.error(Util.logStr("whereList:{}", JSONObject.toJSONString(wheres)));
if(needDel){
if (!deleteModelDataByIds(String.valueOf(modelId), dataIds)) {
log.error(Util.logStr("删除数据失败!未删除数据集合:{}", JSONObject.toJSONString(dataIds)));
}
}
throw new CustomerException("执行批量更新sql失败!");
}
if(needModeRight){
moderightinfo.rebuildModeDataShareByEdit(1, modelId, mainId);
if(CollectionUtils.isEmpty(dataIds)){
throw new CustomerException("建模数据生成失败!");
}
return mainId;
for (String dataId : dataIds) {
moderightinfo.rebuildModeDataShareByEdit(1, modelId, Integer.parseInt(dataId));
}
return dataIds;
}
/**

View File

@ -0,0 +1,51 @@
package weaver.xuanran.wang.saic_travel.model_data_async.config.eneity;
import lombok.*;
import java.sql.Timestamp;
/**
* <h1></h1>
*
* @Author xuanran.wang
* @Date 2022/12/1 14:01
*/
@Data
public class DataAsyncDetail {
/**
* <h2></h2>
**/
private String asyncModelTable;
/**
* <h2></h2>
**/
private String dataType;
/**
* <h2></h2>
**/
private String dataSourceModelFiled;
/**
* <h2></h2>
**/
private String cusTableField;
/**
* <h2></h2>
**/
private String convertRules;
/**
* <h2></h2>
**/
private String cusText;
/**
* <h2></h2>
**/
private String enable;
/**
* <h2></h2>
**/
private String asyncModelTableField;
/**
* <h2></h2>
**/
private String dataSourceModelFiledName;
}

View File

@ -0,0 +1,26 @@
package weaver.xuanran.wang.saic_travel.model_data_async.config.eneity;
import lombok.*;
import java.util.List;
/**
* <h1></h1>
*
* @Author xuanran.wang
* @Date 2022/12/1 14:00
*/
@Data
public class DataAsyncMain {
private String id;
private String uniqueCode;
private String enable;
private String dataSource;
private String modelType;
private String cusTable;
private String asyncTargetModel;
private String cusWhere;
private String modelTypeTableName;
private String asyncTargetModelTableName;
private List<DataAsyncDetail> dataAsyncDetailList;
}

View File

@ -0,0 +1,50 @@
package weaver.xuanran.wang.saic_travel.model_data_async.config.mapper;
import aiyh.utils.annotation.recordset.ParamMapper;
import aiyh.utils.annotation.recordset.Select;
import aiyh.utils.annotation.recordset.SqlMapper;
import java.util.List;
import java.util.Map;
/**
* <h1>mapper</h1>
*
* @Author xuanran.wang
* @Date 2022/12/1 14:35
*/
@SqlMapper
public interface DataAsyncConfigMapper {
/**
* <h1></h1>
* @author xuanran.wang
* @dateTime 2022/12/1 14:39
* @param uniqueCode
* @return
**/
@Select("select a.*,b.tablename asyncTargetModelTableName,c.tablename modelTypeTableName " +
"from uf_data_async a " +
"left join mode_bill_info_view b " +
"on a.asyncTargetModel = b.id " +
"left join mode_bill_info_view c " +
"on a.modelType = c.id " +
"where uniqueCode = #{uniqueCode} and enable = #{enable}")
Map<String, Object> getDataAsyncMainConfig(@ParamMapper("uniqueCode") String uniqueCode, @ParamMapper("enable") String enable);
/**
* <h1></h1>
* @author xuanran.wang
* @dateTime 2022/12/1 14:40
* @param mainId id
* @return
**/
@Select("select a.*,b.fieldname asyncModelTableField,c.fieldname dataSourceModelFiledName " +
"from uf_data_async_dt1 a " +
"left join workflow_field_table_view b " +
"on a.asyncModelTable = b.id " +
"left join workflow_field_table_view c " +
"on a.dataSourceModelFiled = c.id " +
"where mainid = #{mainId} and enable = #{enable}")
List<Map<String, Object>> getDataAsyncDetailConfig(@ParamMapper("mainId") String mainId,@ParamMapper("enable") String enable);
}

View File

@ -0,0 +1,79 @@
package weaver.xuanran.wang.saic_travel.model_data_async.constant;
/**
* <h1>uf_data_async</h1>
*
* @Author xuanran.wang
* @Date 2022/12/1 14:18
*/
public class DataAsyncConstant {
public static final String MODEL_TABLE_NAME = "uf_data_async";
/**
* <h2>-</h2>
**/
public static final String DATA_SOURCE_MODEL = "0";
/**
* <h2>-</h2>
**/
public static final String DATA_SOURCE_CUS_TABLE = "1";
/**
* <h2></h2>
**/
public static final String CONFIG_ENABLE = "0";
/**
* <h2></h2>
**/
public static final String CONFIG_NOT_ENABLE = "1";
/**
* <h2>-String</h2>
**/
public static final String DATA_TYPE_STRING = "0";
/**
* <h2>-Int</h2>
**/
public static final String DATA_TYPE_INT = "1";
/**
* <h2>-Double</h2>
**/
public static final String DATA_TYPE_DOUBLE = "2";
/**
* <h2>-Date</h2>
**/
public static final String DATA_TYPE_DATE = "3";
/**
* <h2>-DateTime</h2>
**/
public static final String DATA_TYPE_DATE_TIME = "4";
/**
* <h2>-</h2>
**/
public static final String DATA_TYPE_CUS_DATE = "5";
/**
* <h2>-</h2>
**/
public static final String DATA_TYPE_TIME_TIMESTAMP = "6";
/**
* <h2>-</h2>
**/
public static final String CONVERT_RULES_TABLE_FIELD = "0";
/**
* <h2>-</h2>
**/
public static final String CONVERT_RULES_DEFAULT = "1";
/**
* <h2>-</h2>
**/
public static final String CONVERT_RULES_NOW_TIME = "2";
/**
* <h2>-SQL</h2>
**/
public static final String CONVERT_RULES_CUS_SQL = "3";
/**
* <h2>-id</h2>
**/
public static final String CONVERT_RULES_DATA_ID = "4";
/**
* <h2>-</h2>
**/
public static final String CONVERT_RULES_SPLIT_COPY = "5";
}

View File

@ -0,0 +1,41 @@
package weaver.xuanran.wang.saic_travel.model_data_async.job;
import aiyh.utils.Util;
import org.apache.log4j.Logger;
import weaver.interfaces.schedule.BaseCronJob;
import weaver.xuanran.wang.common.annocation.ParamNotNull;
import weaver.xuanran.wang.common.util.CommonUtil;
import weaver.xuanran.wang.saic_travel.model_data_async.config.eneity.DataAsyncMain;
import weaver.xuanran.wang.saic_travel.model_data_async.service.DataAsyncConfigService;
/**
* <h1></h1>
*
* @Author xuanran.wang
* @Date 2022/12/1 15:20
*/
public class HrmDataToModelAsync extends BaseCronJob {
private final Logger logger = Util.getLogger();
private final DataAsyncConfigService asyncConfigService = new DataAsyncConfigService();
@ParamNotNull
private String uniqueCode;
@ParamNotNull
private String modelId;
@Override
public void execute() {
try {
CommonUtil.checkParamNotNull(this);
DataAsyncMain dataAsyncConfigByUniqueCode = asyncConfigService.getDataAsyncConfigByUniqueCode(uniqueCode);
asyncConfigService.asyncModelData(dataAsyncConfigByUniqueCode, Util.getIntValue(modelId, -1));
}catch (Exception e){
logger.error(Util.logStr("执行数据同步计划任务失败!异常信息 : {}", e.getMessage()));
}
}
}

View File

@ -0,0 +1,23 @@
package weaver.xuanran.wang.saic_travel.model_data_async.mapper;
import aiyh.utils.annotation.recordset.*;
import weaver.conn.RecordSet;
import java.util.Map;
/**
* <h1>mapper</h1>
*
* @Author xuanran.wang
* @Date 2022/12/1 16:55
*/
@SqlMapper
public interface DataAsyncMapper {
@Select(custom = true)
@CaseConversion(false)
RecordSet getRecordSetByCusSql(@SqlString String sql);
}

View File

@ -0,0 +1,265 @@
package weaver.xuanran.wang.saic_travel.model_data_async.service;
import aiyh.utils.Util;
import aiyh.utils.excention.CustomerException;
import com.alibaba.fastjson.JSONObject;
import org.apache.commons.lang3.StringUtils;
import org.apache.log4j.Logger;
import org.springframework.util.Assert;
import org.springframework.util.CollectionUtils;
import weaver.conn.RecordSet;
import weaver.xuanran.wang.common.util.CommonUtil;
import weaver.xuanran.wang.common.util.CusInfoToOAUtil;
import weaver.xuanran.wang.saic_travel.model_data_async.config.eneity.DataAsyncDetail;
import weaver.xuanran.wang.saic_travel.model_data_async.config.eneity.DataAsyncMain;
import weaver.xuanran.wang.saic_travel.model_data_async.config.mapper.DataAsyncConfigMapper;
import weaver.xuanran.wang.saic_travel.model_data_async.constant.DataAsyncConstant;
import weaver.xuanran.wang.saic_travel.model_data_async.mapper.DataAsyncMapper;
import weaver.zwl.common.ToolUtil;
import java.util.*;
import java.util.stream.Collectors;
/**
* <h1>service</h1>
*
* @Author xuanran.wang
* @Date 2022/12/1 14:33
*/
public class DataAsyncConfigService {
private final Logger logger = Util.getLogger();
private final RecordSet tempRs = new RecordSet();
private final DataAsyncConfigMapper dataAsyncConfigMapper = Util.getMapper(DataAsyncConfigMapper.class);
/**
* <h1></h1>
* @author xuanran.wang
* @dateTime 2022/12/1 15:09
* @param uniqueCode
* @return
**/
public DataAsyncMain getDataAsyncConfigByUniqueCode(String uniqueCode){
Map<String, Object> mainConfigMap = dataAsyncConfigMapper.getDataAsyncMainConfig(uniqueCode, DataAsyncConstant.CONFIG_ENABLE);
DataAsyncMain dataAsyncMain = CommonUtil.getInstance(mainConfigMap, DataAsyncMain.class);
List<Map<String, Object>> asyncDetailConfig = dataAsyncConfigMapper.getDataAsyncDetailConfig(dataAsyncMain.getId(), DataAsyncConstant.CONFIG_ENABLE);
List<DataAsyncDetail> detailList = asyncDetailConfig.stream().map(item -> CommonUtil.getInstance(item, DataAsyncDetail.class)).collect(Collectors.toList());
Assert.notEmpty(detailList, "明细表配置集合获取为空, 请检查!");
dataAsyncMain.setDataAsyncDetailList(detailList);
return dataAsyncMain;
}
/**
* <h1></h1>
* @author xuanran.wang
* @dateTime 2022/12/2 13:28
* @param asyncConfig
* @param modelId id
**/
public List<String> asyncModelData(DataAsyncMain asyncConfig, int modelId){
String dataSource = asyncConfig.getDataSource();
String selectSql = getSelectSql(asyncConfig);
List<DataAsyncDetail> asyncDetailList = asyncConfig.getDataAsyncDetailList();
RecordSet rs = new RecordSet();
if (!rs.executeQuery(selectSql)) {
throw new CustomerException(Util.logStr("执行查询数据源sql失败! 当前sql:{}", selectSql));
}
logger.info("selectSql : " + selectSql);
List<LinkedHashMap<String, Object>> linkedHashMapList = new ArrayList<>();
int splitCopy = -1;
String splitCopyFiledName = "";
// 复制个数
List<DataAsyncDetail> splitCopyList = asyncDetailList.stream().filter(item -> DataAsyncConstant.CONVERT_RULES_SPLIT_COPY.equals(item.getConvertRules())).collect(Collectors.toList());
if(!CollectionUtils.isEmpty(splitCopyList)){
DataAsyncDetail detail = splitCopyList.get(0);
splitCopy = Util.getIntValue(detail.getCusText(),-1);
splitCopyFiledName = Util.null2DefaultStr(detail.getAsyncModelTableField(),"");
}
while (rs.next()){
LinkedHashMap<String, Object> linkedHashMap = new LinkedHashMap<>();
int tempCount = 0;
for (DataAsyncDetail dataAsyncDetail : asyncDetailList) {
String field = "";
switch (dataSource){
case DataAsyncConstant.DATA_SOURCE_MODEL:{
field = dataAsyncDetail.getDataSourceModelFiledName();
}break;
case DataAsyncConstant.DATA_SOURCE_CUS_TABLE:{
field = dataAsyncDetail.getCusTableField();
}break;
default:throw new CustomerException("暂不支持的数据来源");
}
Object value = getFieldValue(rs, field, dataAsyncDetail, tempCount);
linkedHashMap.put(dataAsyncDetail.getAsyncModelTableField(), value);
}
linkedHashMapList.add(linkedHashMap);
// 记录复制
while (++tempCount < splitCopy) {
LinkedHashMap<String, Object> copyMap = new LinkedHashMap<>(linkedHashMap);
copyMap.put(splitCopyFiledName, tempCount);
linkedHashMapList.add(copyMap);
}
}
List<String> list = CusInfoToOAUtil.executeBatch(modelId, linkedHashMapList);
return list;
}
/**
* <h1></h1>
* @author xuanran.wang
* @dateTime 2022/12/5 10:50
* @param recordSet
* @param field
* @param dataAsyncDetail
* @param count
* @return
**/
public Object getFieldValue(RecordSet recordSet, String field, DataAsyncDetail dataAsyncDetail, int count){
String convertRules = dataAsyncDetail.getConvertRules();
String dataType = dataAsyncDetail.getDataType();
String cusText = dataAsyncDetail.getCusText();
Object value = "";
switch (convertRules) {
// 表单字段
case DataAsyncConstant.CONVERT_RULES_TABLE_FIELD: {
if(!StringUtils.isBlank(field)){
value = Util.null2String(recordSet.getString(field));
}
}break;
// 默认值
case DataAsyncConstant.CONVERT_RULES_DEFAULT: {
value = cusText;
}break;
// 当前时间
case DataAsyncConstant.CONVERT_RULES_NOW_TIME: {
value = new Date();
}break;
// 自定义sql查询
case DataAsyncConstant.CONVERT_RULES_CUS_SQL: {
if(!StringUtils.isBlank(cusText)){
String cusSql = Util.sbc2dbcCase(cusText);
String where = "";
if(StringUtils.isNotBlank(field)){
where = Util.null2DefaultStr(recordSet.getString(field),"");
}
tempRs.executeQuery(cusSql, where);
if (!tempRs.next()) {
logger.error(Util.logStr("执行自定义sql失败!当前sql:{}, 当前参数:{}", cusSql, where));
break;
}
value = tempRs.getString(1);
}
}break;
case DataAsyncConstant.CONVERT_RULES_DATA_ID: {
value = recordSet.getString("id");
}break;
case DataAsyncConstant.CONVERT_RULES_SPLIT_COPY: {
value = count;
}break;
default: throw new CustomerException("不支持的取值方式!");
}
switch (dataType) {
// String类型
case DataAsyncConstant.DATA_TYPE_STRING: {
value = Util.null2DefaultStr(String.valueOf(value), "");
}
break;
// int类型
case DataAsyncConstant.DATA_TYPE_INT: {
value = Util.getIntValue(Util.null2DefaultStr(value, ""), 0);
}
break;
// double类型
case DataAsyncConstant.DATA_TYPE_DOUBLE: {
value = Util.getDoubleValue(Util.null2DefaultStr(value, ""), 0);
}
break;
// 日期类型
case DataAsyncConstant.DATA_TYPE_DATE: {
if (StringUtils.isBlank(Util.null2DefaultStr(value, ""))) {
break;
}
try {
Date date = value instanceof Date ? (Date) value : CommonUtil.parseDate(String.valueOf(value));
value = CommonUtil.diyDateFortMat(date, "yyyy-MM-dd");
} catch (Exception e) {
logger.error(Util.logStr("转换日期类型异常, 当前字段:{},当前值:{}", field, value));
}
}
break;
// 时间日期类型
case DataAsyncConstant.DATA_TYPE_DATE_TIME: {
if (StringUtils.isBlank(Util.null2DefaultStr(value, ""))) {
break;
}
try {
Date date = value instanceof Date ? (Date) value : CommonUtil.parseDate(String.valueOf(value));
value = CommonUtil.diyDateFortMat(date, "yyyy-MM-dd HH:mm:ss");
} catch (Exception e) {
logger.error(Util.logStr("转换日期类型异常, 当前字段:{},当前值:{}", field, value));
}
}
break;
// 自定义时间格式化类型
case DataAsyncConstant.DATA_TYPE_CUS_DATE: {
if (StringUtils.isBlank(Util.null2DefaultStr(value, "")) || StringUtils.isBlank(cusText)) {
break;
}
try {
Date date = value instanceof Date ? (Date) value : CommonUtil.parseDate(String.valueOf(value));
value = CommonUtil.diyDateFortMat(date, cusText);
} catch (Exception e) {
logger.error(Util.logStr("转换日期类型异常, 当前字段:{},当前值:{}", field, value));
}
}
break;
// 时间戳类型
case DataAsyncConstant.DATA_TYPE_TIME_TIMESTAMP: {
if (StringUtils.isBlank(Util.null2DefaultStr(value, "")) || StringUtils.isBlank(cusText)) {
break;
}
try {
Date date = value instanceof Date ? (Date) value : CommonUtil.parseDate(String.valueOf(value));
value = date.getTime();
} catch (Exception e) {
logger.error(Util.logStr("转换日期类型异常, 当前字段:{},当前值:{}", field, value));
}
}break;
default: throw new CustomerException("不支持的字段类型!");
}
return value;
}
/**
* <h1>sql</h1>
* @author xuanran.wang
* @dateTime 2022/12/2 12:56
* @param asyncConfig
* @return sql
**/
public String getSelectSql(DataAsyncMain asyncConfig){
String dataSource = asyncConfig.getDataSource();
String cusWhere = Util.null2DefaultStr(asyncConfig.getCusWhere(), "");
String dataSourceTableName = "";
List<DataAsyncDetail> asyncDetailList = asyncConfig.getDataAsyncDetailList();
String selectSql = "select ";
List<String> modelFieldList = new ArrayList<>();
// 判断数据来源拼接查询sql
switch (dataSource) {
case DataAsyncConstant.DATA_SOURCE_MODEL:{
modelFieldList = asyncDetailList.stream().map(DataAsyncDetail::getDataSourceModelFiledName).filter(StringUtils::isNotBlank).collect(Collectors.toList());
dataSourceTableName = asyncConfig.getModelTypeTableName();
}break;
case DataAsyncConstant.DATA_SOURCE_CUS_TABLE:{
modelFieldList = asyncDetailList.stream().map(DataAsyncDetail::getCusTableField).filter(StringUtils::isNotBlank).collect(Collectors.toList());
dataSourceTableName = asyncConfig.getCusTable();
}break;
default:throw new CustomerException("暂不支持的数据来源!");
}
// 拼接数据源查询sql
selectSql += StringUtils.join(modelFieldList, ",") + " from " + dataSourceTableName;
if(StringUtils.isNotBlank(cusWhere)){
selectSql += " where " + cusWhere;
}
return selectSql;
}
}

View File

@ -0,0 +1,53 @@
package weaver.xuanran.wang.schroeder.action;
import aiyh.utils.Util;
import aiyh.utils.action.CusBaseAction;
import aiyh.utils.annotation.RequiredMark;
import aiyh.utils.excention.CustomerException;
import weaver.conn.RecordSetTrans;
import weaver.hrm.User;
import weaver.workflow.request.RequestManager;
import weaver.xuanran.wang.schroeder.service.SchroederQRCodeService;
/**
* <h1>action</h1>
*
* @Author xuanran.wang
* @Date 2022/11/30 16:08
*/
public class PushSealTaskAction extends CusBaseAction {
/**
* <h2></h2>
**/
@RequiredMark
private String onlyMark;
/**
* <h2></h2>
**/
@RequiredMark
private String QRCodeField;
private final SchroederQRCodeService schroederQRCodeService = new SchroederQRCodeService();
@Override
public void doSubmit(String requestId, String billTable, int workflowId, User user, RequestManager requestManager) {
log.info("---------- PushSealTaskSealValue Begin " + requestId + "----------");
String scanNum = schroederQRCodeService.pushSealTask(onlyMark, billTable, requestId);
RecordSetTrans trans = requestManager.getRsTrans();
trans.setAutoCommit(false);
String updateSql = "update " + billTable + " set " + QRCodeField + " = ? where requestid = ?";
try{
if(!trans.executeUpdate(updateSql, scanNum, requestId)){
throw new CustomerException(Util.logStr("更新表单sql执行失败!sql : {}, 参数 scanNum : {}, requestId : {}", scanNum, requestId));
}
}catch (Exception e){
trans.rollback();
throw new CustomerException(Util.logStr("执行提交方法异常:{}", e.getMessage()));
}
trans.commit();
}
}

View File

@ -0,0 +1,71 @@
package weaver.xuanran.wang.schroeder.cus_field_value;
import aiyh.utils.Util;
import aiyh.utils.excention.CustomerException;
import com.alibaba.fastjson.JSONObject;
import org.apache.commons.collections.MapUtils;
import org.apache.commons.lang3.StringUtils;
import org.apache.log4j.Logger;
import weaver.conn.RecordSet;
import weaver.xiao.commons.config.interfacies.CusInterfaceGetValue;
import weaver.zwl.common.ToolUtil;
import java.util.*;
import java.util.stream.Collectors;
/**
* <h1></h1>
*
* @Author xuanran.wang
* @Date 2022/12/2 16:10
*/
public class PushSealTaskSealValue implements CusInterfaceGetValue {
private final ToolUtil toolUtil = new ToolUtil();
private final Logger logger = Util.getLogger();
@Override
public Object execute(Map<String, Object> mainMap, Map<String, Object> detailMap, String currentValue, Map<String, String> pathParam) {
logger.info(Util.logStr("路径参数:[{}]", JSONObject.toJSONString(pathParam)));
// 接口字段
String sealSnField = pathParam.get("sealSnField");
String sealNumField = pathParam.get("sealNumField");
// 表单字段
String workFlowSealNumField = pathParam.get("workFlowSealNumField");
String workFlowSealSnField = pathParam.get("workFlowSealSnField");
// 自定义sql业务印章类型
String sealSnCusSql = pathParam.get("sealSnCusSql");
// 使用次数
String sealNumCusSql = pathParam.get("sealNumCusSql");
// 非空校验
if(checkBlank(sealSnField, sealNumField, sealSnCusSql, sealNumCusSql, workFlowSealNumField, workFlowSealSnField)){
throw new CustomerException(Util.logStr("自定义类路径中必要参数为空,请检查!当前pathParam : {}", JSONObject.toJSONString(pathParam)));
}
// 表单印章使用类型值
String sealSnVal = Util.null2String(String.valueOf(detailMap.get(sealSnField)),"");
// 如果为空返回空集合
if(StringUtils.isBlank(sealSnVal)){
return Collections.emptyList();
}
ArrayList<Map<String, Object>> list = new ArrayList<>();
logger.info(Util.logStr("当前值 : {}", currentValue));
int detailId = -1;
if(MapUtils.isNotEmpty(detailMap)){
detailId = Util.getIntValue(String.valueOf(detailMap.get("id")), -1);
}
for (String val : sealSnVal.split(",")) {
// 印章类型转换执行自定义sql
String inSealVal = Util.null2DefaultStr(toolUtil.getValueByChangeRule(sealSnCusSql, val, String.valueOf(mainMap.get("requestid")), detailId),"");
String inSealNumVal = Util.null2DefaultStr(toolUtil.getValueByChangeRule(sealNumCusSql, val, String.valueOf(mainMap.get("requestid")), detailId),"");
HashMap<String, Object> map = new HashMap<>();
map.put(sealSnField, inSealVal);
map.put(sealNumField, inSealNumVal);
list.add(map);
}
return list;
}
public boolean checkBlank(String ... args){
return Arrays.stream(args).anyMatch(StringUtils::isBlank);
}
}

View File

@ -0,0 +1,114 @@
package weaver.xuanran.wang.schroeder.service;
import aiyh.utils.Util;
import aiyh.utils.excention.CustomerException;
import aiyh.utils.httpUtil.ResponeVo;
import aiyh.utils.httpUtil.util.HttpUtils;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.google.zxing.qrcode.encoder.QRCode;
import org.apache.commons.lang3.StringUtils;
import org.apache.log4j.Logger;
import weaver.conn.RecordSet;
import weaver.mobile.plugin.ecology.QRCodeComInfo;
import weaver.xiao.commons.config.entity.RequestMappingConfig;
import weaver.xiao.commons.config.service.DealWithMapping;
import javax.ws.rs.core.MediaType;
import java.io.IOException;
import java.util.Map;
/**
* <h1></h1>
*
* @Author xuanran.wang
* @Date 2022/12/1 10:58
*/
public class SchroederQRCodeService {
private static final int SUCCESS_CODE = 200;
/**
* <h2></h2>
**/
private static final int SUCCESS_STATUS= 0;
/**
* <h2></h2>
**/
private static final String MESSAGE_FIELD = "message";
/**
* <h2></h2>
**/
private static final String SCAN_NUM_FIELD = "scanNum";
/**
* <h2></h2>
**/
private static final String STATUS_FIELD = "status";
private final DealWithMapping dealWithMapping = new DealWithMapping();
private final Logger log = Util.getLogger();
private final HttpUtils httpUtils = new HttpUtils();
{
httpUtils.getGlobalCache().header.put("Content-Type", MediaType.APPLICATION_JSON);
}
/**
* <h1></h1>
* @author xuanran.wang
* @dateTime 2022/12/5 17:05
* @param onlyMark
* @param billTable
* @param requestId id
* @return
**/
public String pushSealTask(String onlyMark, String billTable, String requestId){
String res = "";
RequestMappingConfig requestMappingConfig = dealWithMapping.treeDealWithUniqueCode(onlyMark);
String cusWhere = Util.null2DefaultStr(requestMappingConfig.getCusWhereSql(),"");
if(StringUtils.isNotBlank(cusWhere)){
cusWhere = DealWithMapping.sbc2dbcCase(cusWhere);
}
String selectMainSql = "select * from " + billTable + " where requestid = ? " + cusWhere;
log.info("查询主表数据sql { " + selectMainSql + " }, requestId { " + requestId + " }");
RecordSet recordSet = new RecordSet();
recordSet.executeQuery(selectMainSql, requestId);
if (recordSet.next()) {
dealWithMapping.setMainTable(billTable);
Map<String, Object> requestParam = dealWithMapping.getRequestParam(recordSet, requestMappingConfig);
log.info(Util.logStr("请求json : {}", JSONObject.toJSONString(requestParam)));
String url = requestMappingConfig.getRequestUrl();
ResponeVo responeVo = null;
try {
responeVo = httpUtils.apiPost(url, requestParam);
} catch (IOException e) {
throw new CustomerException(Util.logStr("发送印章请求发生异常! : {}", e.getMessage()));
}
Map<String, String> headers = httpUtils.getGlobalCache().header;
if (responeVo.getCode() != SUCCESS_CODE) {
log.error(Util.logStr("can not fetch [{}]this request params is [{}]" +
"this request heard is [{}]but response status code is [{}]" +
"this response is [{}]", url, JSON.toJSON(requestParam), JSON.toJSONString(headers), responeVo.getCode(),
responeVo.getEntityString()));
throw new CustomerException(Util.logStr("can not fetch [{}]", url));
}
Map<String, Object> response;
log.info(Util.logStr("this response is [{}]", responeVo.getEntityString()));
try {
response = responeVo.getEntityMap();
log.info(Util.logStr("接口响应:{}", JSONObject.toJSONString(response)));
} catch (JsonProcessingException e) {
log.error(Util.logStr("push data error, can not parse response to map" +
"this response is [{}], url is [{}]request params is [{}] request heard is [{}];",
responeVo.getEntityString(), url, JSON.toJSONString(requestParam), JSON.toJSONString(headers)));
throw new CustomerException(Util.logStr("push data error, can not parse response to map"));
}
int status = (int) response.get(STATUS_FIELD);
if(SUCCESS_STATUS != status){
throw new CustomerException(Util.logStr("接口响应码不为0,接口响应信息:{}", Util.null2DefaultStr(response.get(MESSAGE_FIELD),"")));
}
res = Util.null2DefaultStr(response.get(SCAN_NUM_FIELD),"");
}
if(StringUtils.isBlank(res)){
throw new CustomerException("获取接口中响应任务字段为空, 请检查!");
}
return res;
}
}

View File

@ -0,0 +1,17 @@
package weaver.xuanran.wang.traffic_bank.waco_first.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/30 11:35
*/
@Target({ElementType.FIELD,ElementType.TYPE})
@Retention(RetentionPolicy.RUNTIME)
public @interface Attachments {
}

View File

@ -0,0 +1,14 @@
package weaver.xuanran.wang.traffic_bank.waco_first.entity;
import lombok.Data;
/**
* <h1></h1>
*
* @Author xuanran.wang
* @Date 2022/11/25 17:56
*/
@Data
public class Attachment {
private String src;
}

View File

@ -4,6 +4,8 @@ import lombok.Data;
import weaver.xuanran.wang.common.annocation.CusDateFormat;
import weaver.xuanran.wang.traffic_bank.waco_first.annocation.BodyPath;
import java.util.List;
/**
* <h1></h1>
*
@ -29,4 +31,5 @@ public class Info {
private String punishmentAmount;
@BodyPath
private String bodyPath;
private List<Attachment> attachments;
}

View File

@ -65,6 +65,7 @@ public class WacoDataPushOA extends BaseCronJob {
@Override
public void execute() {
logger.info("------------------ WacoDataPushOA Begin ------------------");
try {
CommonUtil.checkParamNotNull(this);
ChannelSftp connect = FtpUtil.connect(ftpUrl, Util.getIntValue(ftpPort), ftpUserName, ftpPassWord);
@ -72,7 +73,9 @@ public class WacoDataPushOA extends BaseCronJob {
dataPushOAService.writeInfoToOA(Util.getIntValue(modelId, -1),Util.getIntValue(secCategory, -1), infos);
} catch (Exception e) {
logger.error(Util.logStr("计划任务执行失败!, 具体异常信息 : {}", e.getMessage()));
logger.info("------------------ WacoDataPushOA Error ------------------");
}
logger.info("------------------ WacoDataPushOA End ------------------");
}
}

View File

@ -2,7 +2,6 @@ package weaver.xuanran.wang.traffic_bank.waco_first.service;
import aiyh.utils.Util;
import aiyh.utils.excention.CustomerException;
import com.alibaba.fastjson.JSONObject;
import com.jcraft.jsch.ChannelSftp;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang3.StringUtils;
@ -24,9 +23,12 @@ import weaver.xuanran.wang.traffic_bank.waco_first.entity.Info;
import weaver.xuanran.wang.common.util.FtpUtil;
import java.io.File;
import java.io.InputStream;
import java.lang.reflect.Field;
import java.nio.file.Files;
import java.util.*;
import java.util.regex.Matcher;
import java.util.stream.Collectors;
/**
* <h1></h1>
@ -41,6 +43,7 @@ public class WacoDataPushOAService {
private final Logger logger = Util.getLogger();
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>ftp,info</h1>
* @author xuanran.wang
@ -73,7 +76,7 @@ public class WacoDataPushOAService {
CommonUtil.unZip(zipOATempPath,tempFolder);
ArrayList<Info> infos = new ArrayList<>();
try {
getAllInfoByPath(infos, tempFolder, DATA_SUFFIX);
this.getAllInfoByPath(infos, tempFolder, DATA_SUFFIX);
}catch (Exception e){
throw new CustomerException("获取指定文件夹下的所有xml信息出现异常: " + e.getMessage());
}
@ -92,7 +95,7 @@ public class WacoDataPushOAService {
* @param infos
**/
public void writeInfoToOA(int modelId, int secCategory, List<Info> infos) {
String whereSql = "select 1 from " + CusInfoToOAUtil.TABLE_NAME_PLACEHOLDER + " where infoId = ?";
String whereSql = "select id from #{tableName} where infoId = ?";
List<String> ids = new ArrayList<>();
// docDetailContent表参数
List<List> docDetailContentParams = new ArrayList<>();
@ -100,10 +103,10 @@ public class WacoDataPushOAService {
for (Info info : infos) {
List<String> docDetailParam = new ArrayList<>();
Map<String, Object> param = getParamsMapByInfo(secCategory, info, docDetailParam);
int dataId = CusInfoToOAUtil.execute(modelId, param,
String dataId = CusInfoToOAUtil.getDataId(modelId, param,
whereSql,
Collections.singletonList(info.getInfoId()));
ids.add(String.valueOf(dataId));
ids.add(dataId);
docDetailContentParams.add(docDetailParam);
}
RecordSet updateRs = new RecordSet();
@ -112,13 +115,18 @@ public class WacoDataPushOAService {
}
}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)));
}
}
// sql用了in防止集合过大sql报错进行集合分割默认100
CommonUtil.deleteDataByIds(ids, modelId);
List<String> docIds = docDetailContentParams
.stream()
.map(item -> {
// docId
return Util.null2String(String.valueOf(item.get(0)));
})
.filter(item -> StringUtils.isNotBlank(Util.null2String(item)))
.collect(Collectors.toList());
CommonUtil.splitList(docIds, CommonUtil.SQL_IN_PAGE_SIZE);
CommonUtil.deleteDataByIds(docIds, modelId);
throw new RuntimeException("写入建模出现异常:" + e.getMessage());
}
}
@ -152,8 +160,8 @@ public class WacoDataPushOAService {
String body = CommonUtil.readFileByLines(info.getBodyPath());
docInfo.setDoccontent(body);
DocServiceImpl docService = new DocServiceImpl();
int docId = docService.createDocByUser(docInfo, new User(1));
docDetailParam.add(String.valueOf(docId));
String docId = Util.null2String(docService.createDocByUser(docInfo, new User(1)));
docDetailParam.add(docId);
docDetailParam.add(body);
value = docId;
}
@ -181,7 +189,9 @@ public class WacoDataPushOAService {
}else {
if (childFile.getName().endsWith(suffix)) {
Info info = xmlStrToObject(path + File.separator + childFile.getName());
info.setInfoId(childFile.getName());
// 用文件名去掉后缀做infoId
String fileName = childFile.getName();
info.setInfoId(fileName.substring(0, fileName.lastIndexOf(".")));
res.add(info);
}
}
@ -198,30 +208,53 @@ public class WacoDataPushOAService {
* @return
**/
public Info xmlStrToObject(String filePath) throws Exception {
//1.创建Reader对象
File file = new File(filePath);
if(!file.exists()){
throw new CustomerException(Util.logStr("该路径不存在!:{}", filePath));
}
SAXReader reader = new SAXReader();
//2.加载xml
Document document = reader.read(new File(filePath));
//3.获取根节点
Element rootElement = document.getRootElement();
Iterator iterator = rootElement.elementIterator();
InputStream in = null;
Info info = Info.class.newInstance();
while (iterator.hasNext()){
Element stu = (Element) iterator.next();
Iterator iterator1 = stu.elementIterator();
while (iterator1.hasNext()){
Element stuChild = (Element) iterator1.next();
Field declaredField = info.getClass().getDeclaredField(stuChild.getName());
declaredField.setAccessible(true);
String value = stuChild.getStringValue();
BodyPath annotation = declaredField.getDeclaredAnnotation(BodyPath.class);
if(annotation != null){
String parent = new File(filePath).getParent();
value = value.replaceAll("./", Matcher.quoteReplacement(File.separator))
.replaceAll("/", Matcher.quoteReplacement(File.separator));
value = parent + value;
try {
//1.创建Reader对象
in = Files.newInputStream(file.toPath());
//2.加载xml
Document document = reader.read(in);
//3.获取根节点
Element rootElement = document.getRootElement();
Iterator iterator = rootElement.elementIterator();
while (iterator.hasNext()){
Element stu = (Element) iterator.next();
Iterator iterator1 = stu.elementIterator();
while (iterator1.hasNext()){
Element stuChild = (Element) iterator1.next();
Field declaredField = info.getClass().getDeclaredField(stuChild.getName());
declaredField.setAccessible(true);
String value = stuChild.getStringValue();
BodyPath annotation = declaredField.getDeclaredAnnotation(BodyPath.class);
if(annotation != null){
String parent = new File(filePath).getParent();
// 格式 : ./2E058366389/body.txt
value = value.replaceAll("\\./", Matcher.quoteReplacement(File.separator))
.replaceAll("/", Matcher.quoteReplacement(File.separator));
value = parent + value;
}
declaredField.set(info, value);
}
}
in.close();
}catch (Exception e){
String str = Util.logStr("读取文件夹中xml异常!:{}", e.getMessage());
logger.error(str);
throw new CustomerException(str);
}finally {
if(in != null){
try {
System.gc();
in.close();
}catch (Exception e){
logger.error(Util.logStr("关流异常 : {}", e.getMessage()));
}
declaredField.set(info, value);
}
}
return info;

View File

@ -112,20 +112,20 @@ public class SyncOrganizationConfig<E> extends ToolUtil {
httpPost.setEntity(new StringEntity(JSON.toJSONString(params), HTTP.UTF_8));*/
CloseableHttpResponse execute = null;
try {
// execute = httpClient.execute(httpPost);
// getDataId = httpClient.getDataId(httpPost);
ResponeVo responeVo = httpUtils.apiPost(url, params, heards);
if (responeVo.getCode() == 200) {
return JSON.parseObject(responeVo.getEntityString(), new TypeReference<ResultBean<E>>() {
});
}
/* if (execute.getStatusLine().getStatusCode() == 200) {
HttpEntity entity = execute.getEntity();
/* if (getDataId.getStatusLine().getStatusCode() == 200) {
HttpEntity entity = getDataId.getEntity();
String response = EntityUtils.toString(entity, "utf-8");
return JSON.parseObject(response, new TypeReference<ResultBean<E>>() {
});
}*/
// HttpEntity entity = execute.getEntity();
// HttpEntity entity = getDataId.getEntity();
// String response = EntityUtils.toString(entity, "utf-8");
this.writeErrorLog("人员组织架构的相应数据:" + responeVo.getEntityString());
// System.out.println(url);

View File

@ -887,7 +887,7 @@ public class SyncOrganizationUtils extends ToolUtil {
try {
rs.executeQuery(customRulesValue);
} catch (Exception e) {
writeErrorLog("execute custom sql error: " + customRulesValue);
writeErrorLog("getDataId custom sql error: " + customRulesValue);
writeErrorLog("error info:" + e.getMessage() + "\n");
}
rs.next();

View File

@ -0,0 +1,64 @@
package xuanran.wang.saic_travel.model_data_async;
import basetest.BaseTest;
import com.alibaba.fastjson.JSONObject;
import org.apache.commons.lang3.StringUtils;
import org.junit.Test;
import weaver.formmode.data.ModeDataApproval;
import weaver.hrm.User;
import weaver.xuanran.wang.common.util.CommonUtil;
import weaver.xuanran.wang.saic_travel.model_data_async.config.eneity.DataAsyncMain;
import weaver.xuanran.wang.saic_travel.model_data_async.service.DataAsyncConfigService;
import java.util.*;
/**
* <h1></h1>
*
* @Author xuanran.wang
* @Date 2022/12/1 16:30
*/
public class AsyncTest extends BaseTest {
private DataAsyncConfigService dataAsyncConfigService = new DataAsyncConfigService();
@Test
public void testGetConfig(){
// DataAsyncMain hrmAsyncTest = dataAsyncConfigService.getDataAsyncConfigByUniqueCode("hrmAsyncTest");
// dataAsyncConfigService.jska(hrmAsyncTest);
List<String> list = CommonUtil.doCreateWorkFlow(109, Collections.singletonList("24"));
System.out.println(list);
}
@Test
public void testParse(){
String str = "1&nbsp;带干维护保养用&nbsp;2&nbsp;3&nbsp;日常维护用<br/>21212";
str = str.replace("&nbsp;"," ").replace("<br/>","\n").replace("<br>","\n");
System.out.println("str : " + str);
ArrayList<String> list = new ArrayList<>();
list.add("a");
list.add("b");
list.add("c");
System.out.println(StringUtils.join(list, ","));
}
@Test
public void testAsync(){
DataAsyncMain config = dataAsyncConfigService.getDataAsyncConfigByUniqueCode("hrmAsyncTest");
List<String> data = dataAsyncConfigService.asyncModelData(config, 109);
List<String> list = CommonUtil.doCreateWorkFlow(109, data);
log.info("触发成功 : " + JSONObject.toJSONString(list));
}
@Test
public void testNotNull(){
String str = "jssjhgdkjs?docId={?}&{$requestid}";
System.out.println(str.replace("{?}", "123")
.replace("{$requestid}", "12194283"));
}
public boolean checkNull(String ... args){
return Arrays.stream(args).anyMatch(StringUtils::isBlank);
}
}

View File

@ -1,18 +1,25 @@
package xuanran.wang.traffic_bank.waco_first;
import aiyh.utils.Util;
import aiyh.utils.excention.CustomerException;
import basetest.BaseTest;
import com.alibaba.fastjson.JSONObject;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.io.FileUtils;
import org.apache.commons.lang3.StringUtils;
import org.junit.Test;
import weaver.general.GCONST;
import weaver.general.TimeUtil;
import weaver.xuanran.wang.common.util.CommonUtil;
import weaver.xuanran.wang.common.util.CusInfoToOAUtil;
import weaver.xuanran.wang.traffic_bank.waco_first.entity.Info;
import weaver.xuanran.wang.traffic_bank.waco_first.service.WacoDataPushOAService;
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;
/**
* <h1></h1>
@ -23,17 +30,11 @@ import java.util.ArrayList;
public class WacoFirstTest extends BaseTest {
private WacoDataPushOAService wacoDataPushOAService = new WacoDataPushOAService();
/**
* <h1>xml</h1>
* @author xuanran.wang
* @dateTime 2022/11/22 21:22
**/
@Test
public void testParseXml() throws Exception {
ArrayList<Info> infos = new ArrayList<>();
wacoDataPushOAService.getAllInfoByPath(infos, "F:\\wxr\\项目\\交银理财\\威科先行\\20220924","xml");
System.out.println("info " + JSONObject.toJSONString(infos));
Info info = wacoDataPushOAService.xmlStrToObject("F:\\wxr\\微信\\微信文件\\WeChat Files\\wxid_xrds7r3290sb22\\FileStorage\\File\\2022-11\\20221129_1(1)\\63805316082888_1\\2E004411573.xml");
System.out.println(info);
}
/**
@ -42,7 +43,7 @@ public class WacoFirstTest extends BaseTest {
* @dateTime 2022/11/22 21:22
**/
@Test
public void testUnZipFile() throws Exception {
public void testUnZipFile(){
String currentDate = TimeUtil.getCurrentDateString();
String WACO_TEMP_PATH = "WACO" + File.separator + "temp" + File.separator;
String fileName = currentDate.replaceAll("-","") + ".zip";
@ -61,4 +62,42 @@ public class WacoFirstTest extends BaseTest {
}
System.out.println("infos : \n " + JSONObject.toJSONString(infos));
}
/**
* <h1></h1>
* @author xuanran.wang
* @dateTime 2022/11/25 16:38
**/
@Test
public void testFinally() throws IOException {
String currentDate = TimeUtil.getCurrentDateString();
String WACO_TEMP_PATH = "WACO" + File.separator + "temp" + File.separator;
String fileName = currentDate.replaceAll("-","") + ".zip";
String zipOATempPath = GCONST.getSysFilePath() + WACO_TEMP_PATH + fileName;
try {
String tempFolder = GCONST.getSysFilePath() + WACO_TEMP_PATH;
log.info("tempFolder : { " +tempFolder + " }");
// 进行解压
CommonUtil.unZip(zipOATempPath,tempFolder);
ArrayList<Info> infos = new ArrayList<>();
try {
wacoDataPushOAService.getAllInfoByPath(infos, tempFolder, ".xml");
}catch (Exception e){
throw new CustomerException("获取指定文件夹下的所有xml信息出现异常: " + e.getMessage());
}
log.info("删除文件 : [ " + zipOATempPath.substring(0, zipOATempPath.lastIndexOf(".")) + " ]");
log.info("infos : " + JSONObject.toJSONString(infos));
if(CollectionUtils.isEmpty(infos)){
throw new CustomerException("获取到xml信息集合为空,请检查!");
}
wacoDataPushOAService.writeInfoToOA(107, 5, infos);
}catch (Exception e){
log.error("执行发生异常: " + e.getMessage());
}finally {
CommonUtil.delFile(zipOATempPath.substring(0, zipOATempPath.lastIndexOf(".")));
// CommonUtil.delFile(zipOATempPath);
}
}
}

View File

@ -195,7 +195,7 @@ public class TestOrganization extends BaseTest {
@Test
public void testOrgChart() {
User user = new User(88);
User user = new User(84);
OrgChartService orgChartService = new OrgChartService();
List<OrgChartNodeVo> orgChartTree = orgChartService.getOrgChartTree(user);
System.out.println(JSON.toJSONString(orgChartTree));