Merge branch 'dev' of https://gitea.yeyaguitu.cn/ecology/ebu_ecology_dev1 into dev
commit
28464f4c8d
|
@ -447,7 +447,7 @@ $(() => {
|
||||||
$(() => {
|
$(() => {
|
||||||
const config = {
|
const config = {
|
||||||
table: 'detail_1',
|
table: 'detail_1',
|
||||||
field: ['fj']
|
field: ['qswj']
|
||||||
}
|
}
|
||||||
|
|
||||||
function check() {
|
function check() {
|
||||||
|
@ -456,7 +456,7 @@ $(() => {
|
||||||
try {
|
try {
|
||||||
rowIndexArr.forEach(item => {
|
rowIndexArr.forEach(item => {
|
||||||
config.field.forEach(field => {
|
config.field.forEach(field => {
|
||||||
let value = WfForm.getFieldValue(WfForm.convertFieldNameToId(field, <table></table>) + "_" + item)
|
let value = WfForm.getFieldValue(WfForm.convertFieldNameToId(field, config.table) + "_" + item)
|
||||||
if (value == '' || value == null) {
|
if (value == '' || value == null) {
|
||||||
throw field + " is can not be null!";
|
throw field + " is can not be null!";
|
||||||
}
|
}
|
||||||
|
|
|
@ -71,8 +71,7 @@ public class GenerateFileUtil {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (!tClass.isAnnotationPresent(ActionDesc.class)) {
|
if (!tClass.isAnnotationPresent(ActionDesc.class)) {
|
||||||
log.info(Util.logStr("[{}] has not ActionDesc annotation!", tClass.getName()));
|
throw new CustomerException(Util.logStr("[{}] has not ActionDesc annotation!", tClass.getName()));
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
ActionDesc actionDesc = tClass.getAnnotation(ActionDesc.class);
|
ActionDesc actionDesc = tClass.getAnnotation(ActionDesc.class);
|
||||||
String author = actionDesc.author();
|
String author = actionDesc.author();
|
||||||
|
|
|
@ -3401,7 +3401,7 @@ public class Util extends weaver.general.Util {
|
||||||
throw new CustomerException("计划任务执行异常!异常信息:\n" + Util.getErrString(e));
|
throw new CustomerException("计划任务执行异常!异常信息:\n" + Util.getErrString(e));
|
||||||
}
|
}
|
||||||
|
|
||||||
getLogger().info(Util.logStr("\n\t计划任务 [{}] getDataId success!\n", cronJobClass.getName()));
|
getLogger().info(Util.logStr("\n\t计划任务 [{}] execute success!\n", cronJobClass.getName()));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -3463,6 +3463,7 @@ public class Util extends weaver.general.Util {
|
||||||
throw new CustomerException("没有查找到对应的请求requestId : " + requestId);
|
throw new CustomerException("没有查找到对应的请求requestId : " + requestId);
|
||||||
}
|
}
|
||||||
requestInfo.getRequestManager().setSrc(runType);
|
requestInfo.getRequestManager().setSrc(runType);
|
||||||
|
requestInfo.getRequestManager().setUser(new User(1));
|
||||||
execute = action.execute(requestInfo);
|
execute = action.execute(requestInfo);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
throw new CustomerException("action执行异常!异常信息:\n" + Util.getErrString(e));
|
throw new CustomerException("action执行异常!异常信息:\n" + Util.getErrString(e));
|
||||||
|
@ -3470,7 +3471,7 @@ public class Util extends weaver.general.Util {
|
||||||
if (Action.FAILURE_AND_CONTINUE.equals(execute)) {
|
if (Action.FAILURE_AND_CONTINUE.equals(execute)) {
|
||||||
throw new CustomerException("action执行失败,失败原因:\n" + requestInfo.getRequestManager().getMessagecontent());
|
throw new CustomerException("action执行失败,失败原因:\n" + requestInfo.getRequestManager().getMessagecontent());
|
||||||
}
|
}
|
||||||
getLogger().info(Util.logStr("\n\n\tAction [{}] getDataId success!\n", actionClass.getName()));
|
getLogger().info(Util.logStr("\n\n\tAction [{}] execute success!\n", actionClass.getName()));
|
||||||
}
|
}
|
||||||
|
|
||||||
public static String getSetMethodName(String fieldName) {
|
public static String getSetMethodName(String fieldName) {
|
||||||
|
@ -3638,12 +3639,52 @@ public class Util extends weaver.general.Util {
|
||||||
return o.execute(pathParam, requestId, billTable, workflowId, user, requestInfo);
|
return o.execute(pathParam, requestId, billTable, workflowId, user, requestInfo);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* <h2>通过表fromid查询表名</h2>
|
||||||
|
*
|
||||||
|
* @param fromId fromid
|
||||||
|
* @return 表名
|
||||||
|
*/
|
||||||
public static String selectBillTableByFromId(String fromId) {
|
public static String selectBillTableByFromId(String fromId) {
|
||||||
return mapper.selectBillTableByFromId(fromId);
|
return mapper.selectBillTableByFromId(fromId);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* <h2>删除表数据</h2>
|
||||||
|
*
|
||||||
|
* @param tableName 表
|
||||||
|
* @param dataId 数据id
|
||||||
|
*/
|
||||||
public static void deleteModeId(String tableName, Integer dataId) {
|
public static void deleteModeId(String tableName, Integer dataId) {
|
||||||
mapper.deleteModeId(tableName, dataId);
|
mapper.deleteModeId(tableName, dataId);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* <h2>首字母大写</h2>
|
||||||
|
*
|
||||||
|
* @param str 字符串
|
||||||
|
* @return 转换后字符串
|
||||||
|
*/
|
||||||
|
public static String firstUpperCase(String str) {
|
||||||
|
if (Strings.isNullOrEmpty(str)) {
|
||||||
|
return str;
|
||||||
|
}
|
||||||
|
return str.substring(0, 1).toUpperCase() + str.substring(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* <h2>通过fieldViewInfo对象获取map的值 </h2>
|
||||||
|
*
|
||||||
|
* @param fieldInfo 字段信息对象
|
||||||
|
* @param workflowData 流程值
|
||||||
|
* @return 值
|
||||||
|
*/
|
||||||
|
public static Object getValueByFieldViwInfo(FieldViewInfo fieldInfo, Map<String, Object> workflowData) {
|
||||||
|
String tableName = fieldInfo.getTableName();
|
||||||
|
String[] dts = tableName.split("_dt");
|
||||||
|
if (dts.length == 2) {
|
||||||
|
return Util.getValueByKeyStr("detail_" + dts[1] + "." + fieldInfo.getFieldName(), workflowData);
|
||||||
|
}
|
||||||
|
return Util.getValueByKeyStr("main." + fieldInfo.getFieldName(), workflowData);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -96,7 +96,7 @@ public abstract class CusBaseAction implements Action {
|
||||||
if (this.exceptionCallback(e, requestManager)) {
|
if (this.exceptionCallback(e, requestManager)) {
|
||||||
return Action.FAILURE_AND_CONTINUE;
|
return Action.FAILURE_AND_CONTINUE;
|
||||||
}
|
}
|
||||||
}finally {
|
} finally {
|
||||||
// 无论成功还是失败 都将该线程的requestInfo进行移除
|
// 无论成功还是失败 都将该线程的requestInfo进行移除
|
||||||
requestInfoThreadLocal.remove();
|
requestInfoThreadLocal.remove();
|
||||||
}
|
}
|
||||||
|
@ -113,7 +113,7 @@ public abstract class CusBaseAction implements Action {
|
||||||
*/
|
*/
|
||||||
public boolean exceptionCallback(Exception e, RequestManager requestManager) {
|
public boolean exceptionCallback(Exception e, RequestManager requestManager) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
log.error(Util.logStr("getDataId action fail, exception message is [{}], error stack trace msg is: \n{}",
|
log.error(Util.logStr("execute action fail, exception message is [{}], error stack trace msg is: \n{}",
|
||||||
e.getMessage(), Util.getErrString(e)));
|
e.getMessage(), Util.getErrString(e)));
|
||||||
Util.actionFail(requestManager, e.getMessage());
|
Util.actionFail(requestManager, e.getMessage());
|
||||||
return true;
|
return true;
|
||||||
|
|
|
@ -13,6 +13,7 @@ import weaver.workflow.workflow.WorkflowBillComInfo;
|
||||||
import weaver.workflow.workflow.WorkflowComInfo;
|
import weaver.workflow.workflow.WorkflowComInfo;
|
||||||
|
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* <h1>基础的action,实现一些基础的参数</h1>
|
* <h1>基础的action,实现一些基础的参数</h1>
|
||||||
|
@ -228,6 +229,23 @@ public abstract class SafeCusBaseAction implements Action {
|
||||||
return getListMap(detailTableArr);
|
return getListMap(detailTableArr);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* <h2>获取所有明细数据</h2>
|
||||||
|
*
|
||||||
|
* @return 以明细表需要为键,以明细表数据为值的键值对明细数据信息
|
||||||
|
*/
|
||||||
|
protected Map<String, List<Map<String, Object>>> getDetailTableObjValue(RequestInfo requestInfo) {
|
||||||
|
DetailTable[] detailTableArr = requestInfo.getDetailTableInfo().getDetailTable();
|
||||||
|
Map<String, List<Map<String, String>>> listMap = getListMap(detailTableArr);
|
||||||
|
Map<String, List<Map<String, Object>>> result = new HashMap<>(listMap.size());
|
||||||
|
for (Map.Entry<String, List<Map<String, String>>> entry : listMap.entrySet()) {
|
||||||
|
List<Map<String, String>> list = entry.getValue();
|
||||||
|
List<Map<String, Object>> collect = list.stream().map(item -> new HashMap<String, Object>(item)).collect(Collectors.toList());
|
||||||
|
result.put(entry.getKey(), collect);
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
private Map<String, List<Map<String, String>>> getListMap(DetailTable[] detailTableArr) {
|
private Map<String, List<Map<String, String>>> getListMap(DetailTable[] detailTableArr) {
|
||||||
|
@ -251,6 +269,18 @@ public abstract class SafeCusBaseAction implements Action {
|
||||||
return getDetailValue(detailTable);
|
return getDetailValue(detailTable);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* <h2>获取指定明细表的表数据</h2>
|
||||||
|
*
|
||||||
|
* @param detailNo 明细表编号
|
||||||
|
* @return 明细数据
|
||||||
|
*/
|
||||||
|
protected List<Map<String, Object>> getDetailTableObjValueByDetailNo(int detailNo, RequestInfo requestInfo) {
|
||||||
|
DetailTable detailTable = requestInfo.getDetailTableInfo().getDetailTable(detailNo);
|
||||||
|
List<Map<String, String>> detailValue = getDetailValue(detailTable);
|
||||||
|
return detailValue.stream().map(item -> new HashMap<String, Object>(item)).collect(Collectors.toList());
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* <h2>根据明细表信息获取明细表数据</h2>
|
* <h2>根据明细表信息获取明细表数据</h2>
|
||||||
*
|
*
|
||||||
|
|
|
@ -0,0 +1,19 @@
|
||||||
|
package aiyh.utils.annotation;
|
||||||
|
|
||||||
|
import java.lang.annotation.*;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* <h1>方法编号</h1>
|
||||||
|
*
|
||||||
|
* <p>create: 2023/2/19 23:24</p>
|
||||||
|
*
|
||||||
|
* @author youHong.ai
|
||||||
|
*/
|
||||||
|
@Target(ElementType.METHOD)
|
||||||
|
@Retention(RetentionPolicy.RUNTIME)
|
||||||
|
@Documented
|
||||||
|
public @interface MethodRuleNo {
|
||||||
|
int value();
|
||||||
|
|
||||||
|
String desc();
|
||||||
|
}
|
|
@ -0,0 +1,25 @@
|
||||||
|
package aiyh.utils.annotation.recordset;
|
||||||
|
|
||||||
|
import java.lang.annotation.*;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* <h1>association注解</h1>
|
||||||
|
*
|
||||||
|
* <p>create: 2023/2/19 13:49</p>
|
||||||
|
*
|
||||||
|
* @author youHong.ai
|
||||||
|
*/
|
||||||
|
@Retention(RetentionPolicy.RUNTIME)
|
||||||
|
@Target(ElementType.ANNOTATION_TYPE)
|
||||||
|
@Documented
|
||||||
|
public @interface Association {
|
||||||
|
|
||||||
|
String property();
|
||||||
|
|
||||||
|
String column();
|
||||||
|
|
||||||
|
String select();
|
||||||
|
|
||||||
|
Id id();
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,17 @@
|
||||||
|
package aiyh.utils.annotation.recordset;
|
||||||
|
|
||||||
|
import java.lang.annotation.*;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* <h1>association方法</h1>
|
||||||
|
*
|
||||||
|
* <p>create: 2023/2/20 11:55</p>
|
||||||
|
*
|
||||||
|
* @author youHong.ai
|
||||||
|
*/
|
||||||
|
@Retention(RetentionPolicy.RUNTIME)
|
||||||
|
@Target(ElementType.METHOD)
|
||||||
|
@Documented
|
||||||
|
public @interface AssociationMethod {
|
||||||
|
int value();
|
||||||
|
}
|
|
@ -0,0 +1,17 @@
|
||||||
|
package aiyh.utils.annotation.recordset;
|
||||||
|
|
||||||
|
import java.lang.annotation.*;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* <h1>实体映射注解</h1>
|
||||||
|
*
|
||||||
|
* <p>create: 2023/2/19 21:50</p>
|
||||||
|
*
|
||||||
|
* @author youHong.ai
|
||||||
|
*/
|
||||||
|
@Retention(RetentionPolicy.RUNTIME)
|
||||||
|
@Target(ElementType.METHOD)
|
||||||
|
@Documented
|
||||||
|
public @interface Associations {
|
||||||
|
Association[] value();
|
||||||
|
}
|
|
@ -0,0 +1,27 @@
|
||||||
|
package aiyh.utils.annotation.recordset;
|
||||||
|
|
||||||
|
import java.lang.annotation.*;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* <h1>association注解</h1>
|
||||||
|
*
|
||||||
|
* <p>create: 2023/2/19 13:49</p>
|
||||||
|
*
|
||||||
|
* @author youHong.ai
|
||||||
|
*/
|
||||||
|
@Retention(RetentionPolicy.RUNTIME)
|
||||||
|
@Target(ElementType.ANNOTATION_TYPE)
|
||||||
|
@Documented
|
||||||
|
public @interface CollectionMapping {
|
||||||
|
/** 实体字段名 */
|
||||||
|
String property();
|
||||||
|
|
||||||
|
/** 数据库字段名 */
|
||||||
|
String column();
|
||||||
|
|
||||||
|
/** 查询方法全限定类名 */
|
||||||
|
String select() default "";
|
||||||
|
|
||||||
|
/** collection查询的id信息 */
|
||||||
|
Id id();
|
||||||
|
}
|
|
@ -0,0 +1,17 @@
|
||||||
|
package aiyh.utils.annotation.recordset;
|
||||||
|
|
||||||
|
import java.lang.annotation.*;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* <h1>映射</h1>
|
||||||
|
*
|
||||||
|
* <p>create: 2023/2/19 15:39</p>
|
||||||
|
*
|
||||||
|
* @author youHong.ai
|
||||||
|
*/
|
||||||
|
@Retention(RetentionPolicy.RUNTIME)
|
||||||
|
@Target(ElementType.METHOD)
|
||||||
|
@Documented
|
||||||
|
public @interface CollectionMappings {
|
||||||
|
CollectionMapping[] value();
|
||||||
|
}
|
|
@ -0,0 +1,17 @@
|
||||||
|
package aiyh.utils.annotation.recordset;
|
||||||
|
|
||||||
|
import java.lang.annotation.*;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* <h1>association方法</h1>
|
||||||
|
*
|
||||||
|
* <p>create: 2023/2/20 11:55</p>
|
||||||
|
*
|
||||||
|
* @author youHong.ai
|
||||||
|
*/
|
||||||
|
@Retention(RetentionPolicy.RUNTIME)
|
||||||
|
@Target(ElementType.METHOD)
|
||||||
|
@Documented
|
||||||
|
public @interface CollectionMethod {
|
||||||
|
int value();
|
||||||
|
}
|
|
@ -0,0 +1,21 @@
|
||||||
|
package aiyh.utils.annotation.recordset;
|
||||||
|
|
||||||
|
import java.lang.annotation.*;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* <h1>association和collection对应id</h1>
|
||||||
|
*
|
||||||
|
* <p>create: 2023/2/19 14:41</p>
|
||||||
|
*
|
||||||
|
* @author youHong.ai
|
||||||
|
*/
|
||||||
|
@Retention(RetentionPolicy.RUNTIME)
|
||||||
|
@Target(ElementType.ANNOTATION_TYPE)
|
||||||
|
@Documented
|
||||||
|
public @interface Id {
|
||||||
|
/** 查询方法名的唯一键的Java类型 */
|
||||||
|
Class<?> value();
|
||||||
|
|
||||||
|
/** 方法id */
|
||||||
|
int methodId() default -1;
|
||||||
|
}
|
|
@ -0,0 +1,36 @@
|
||||||
|
package aiyh.utils.entity;
|
||||||
|
|
||||||
|
import lombok.Getter;
|
||||||
|
import lombok.Setter;
|
||||||
|
import lombok.ToString;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* <h1></h1>
|
||||||
|
*
|
||||||
|
* <p>create: 2023/2/20 11:01</p>
|
||||||
|
*
|
||||||
|
* @author youHong.ai
|
||||||
|
*/
|
||||||
|
@Getter
|
||||||
|
@Setter
|
||||||
|
@ToString
|
||||||
|
public class FieldViewInfo {
|
||||||
|
|
||||||
|
/** 字段id */
|
||||||
|
private Integer id;
|
||||||
|
|
||||||
|
/** 字段名 */
|
||||||
|
private String fieldName;
|
||||||
|
|
||||||
|
/** 字段表名 */
|
||||||
|
private String tableName;
|
||||||
|
|
||||||
|
/** 表id */
|
||||||
|
private Integer billId;
|
||||||
|
|
||||||
|
/** 字段类型 */
|
||||||
|
private Integer fieldType;
|
||||||
|
|
||||||
|
/** 字段类型名称 */
|
||||||
|
private String fieldHtmlType;
|
||||||
|
}
|
|
@ -16,6 +16,11 @@ public class CustomerException extends RuntimeException {
|
||||||
private Throwable throwable;
|
private Throwable throwable;
|
||||||
private Integer code = -1;
|
private Integer code = -1;
|
||||||
|
|
||||||
|
public CustomerException(Throwable throwable) {
|
||||||
|
super(throwable);
|
||||||
|
this.msg = throwable.getMessage();
|
||||||
|
}
|
||||||
|
|
||||||
public CustomerException(String msg) {
|
public CustomerException(String msg) {
|
||||||
super(msg);
|
super(msg);
|
||||||
this.msg = msg;
|
this.msg = msg;
|
||||||
|
|
|
@ -37,7 +37,7 @@ public abstract class Try<T> {
|
||||||
* Transform success or pass on failure.
|
* Transform success or pass on failure.
|
||||||
* Takes an optional type parameter of the new type.
|
* Takes an optional type parameter of the new type.
|
||||||
* You need to be specific about the new type if changing type
|
* You need to be specific about the new type if changing type
|
||||||
*
|
* <p>
|
||||||
* Try.ofFailable(() -> "1").<Integer>map((x) -> Integer.valueOf(x))
|
* Try.ofFailable(() -> "1").<Integer>map((x) -> Integer.valueOf(x))
|
||||||
*
|
*
|
||||||
* @param f function to apply to successful value.
|
* @param f function to apply to successful value.
|
||||||
|
@ -51,7 +51,7 @@ public abstract class Try<T> {
|
||||||
* Transform success or pass on failure, taking a Try<U> as the result.
|
* Transform success or pass on failure, taking a Try<U> as the result.
|
||||||
* Takes an optional type parameter of the new type.
|
* Takes an optional type parameter of the new type.
|
||||||
* You need to be specific about the new type if changing type.
|
* You need to be specific about the new type if changing type.
|
||||||
*
|
* <p>
|
||||||
* Try.ofFailable(() -> "1").<Integer>flatMap((x) -> Try.ofFailable(() -> Integer.valueOf(x)))
|
* Try.ofFailable(() -> "1").<Integer>flatMap((x) -> Try.ofFailable(() -> Integer.valueOf(x)))
|
||||||
* returns Integer(1)
|
* returns Integer(1)
|
||||||
*
|
*
|
||||||
|
@ -64,13 +64,13 @@ public abstract class Try<T> {
|
||||||
/**
|
/**
|
||||||
* Specifies a result to use in case of failure.
|
* Specifies a result to use in case of failure.
|
||||||
* Gives access to the exception which can be pattern matched on.
|
* Gives access to the exception which can be pattern matched on.
|
||||||
*
|
* <p>
|
||||||
* Try.ofFailable(() -> "not a number")
|
* Try.ofFailable(() -> "not a number")
|
||||||
* .<Integer>flatMap((x) -> Try.ofFailable(() ->Integer.valueOf(x)))
|
* .<Integer>flatMap((x) -> Try.ofFailable(() ->Integer.valueOf(x)))
|
||||||
* .recover((t) -> 1)
|
* .recover((t) -> 1)
|
||||||
* returns Integer(1)
|
* returns Integer(1)
|
||||||
*
|
*
|
||||||
* @param f function to getDataId on successful result.
|
* @param f function to execute on successful result.
|
||||||
* @return new composed Try
|
* @return new composed Try
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
@ -78,6 +78,7 @@ public abstract class Try<T> {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Try applying f(t) on the case of failure.
|
* Try applying f(t) on the case of failure.
|
||||||
|
*
|
||||||
* @param f function that takes throwable and returns result
|
* @param f function that takes throwable and returns result
|
||||||
* @return a new Try in the case of failure, or the current Success.
|
* @return a new Try in the case of failure, or the current Success.
|
||||||
*/
|
*/
|
||||||
|
@ -120,6 +121,7 @@ public abstract class Try<T> {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets the value T on Success or throws the cause of the failure wrapped into a RuntimeException
|
* Gets the value T on Success or throws the cause of the failure wrapped into a RuntimeException
|
||||||
|
*
|
||||||
* @return T
|
* @return T
|
||||||
* @throws RuntimeException
|
* @throws RuntimeException
|
||||||
*/
|
*/
|
||||||
|
@ -129,6 +131,7 @@ public abstract class Try<T> {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Performs the provided action, when successful
|
* Performs the provided action, when successful
|
||||||
|
*
|
||||||
* @param action action to run
|
* @param action action to run
|
||||||
* @return new composed Try
|
* @return new composed Try
|
||||||
* @throws E if the action throws an exception
|
* @throws E if the action throws an exception
|
||||||
|
@ -137,6 +140,7 @@ public abstract class Try<T> {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Performs the provided action, when failed
|
* Performs the provided action, when failed
|
||||||
|
*
|
||||||
* @param action action to run
|
* @param action action to run
|
||||||
* @return new composed Try
|
* @return new composed Try
|
||||||
* @throws E if the action throws an exception
|
* @throws E if the action throws an exception
|
||||||
|
@ -146,6 +150,7 @@ public abstract class Try<T> {
|
||||||
/**
|
/**
|
||||||
* If a Try is a Success and the predicate holds true, the Success is passed further.
|
* If a Try is a Success and the predicate holds true, the Success is passed further.
|
||||||
* Otherwise (Failure or predicate doesn't hold), pass Failure.
|
* Otherwise (Failure or predicate doesn't hold), pass Failure.
|
||||||
|
*
|
||||||
* @param pred predicate applied to the value held by Try
|
* @param pred predicate applied to the value held by Try
|
||||||
* @return For Success, the same success if predicate holds true, otherwise Failure
|
* @return For Success, the same success if predicate holds true, otherwise Failure
|
||||||
*/
|
*/
|
||||||
|
@ -153,6 +158,7 @@ public abstract class Try<T> {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Try contents wrapped in Optional.
|
* Try contents wrapped in Optional.
|
||||||
|
*
|
||||||
* @return Optional of T, if Success, Empty if Failure or null value
|
* @return Optional of T, if Success, Empty if Failure or null value
|
||||||
*/
|
*/
|
||||||
public abstract Optional<T> toOptional();
|
public abstract Optional<T> toOptional();
|
||||||
|
@ -308,9 +314,9 @@ class Failure<T> extends Try<T> {
|
||||||
@Override
|
@Override
|
||||||
public Try<T> recoverWith(TryMapFunction<? super Throwable, Try<T>> f) {
|
public Try<T> recoverWith(TryMapFunction<? super Throwable, Try<T>> f) {
|
||||||
Objects.requireNonNull(f);
|
Objects.requireNonNull(f);
|
||||||
try{
|
try {
|
||||||
return f.apply(e);
|
return f.apply(e);
|
||||||
}catch(Throwable t){
|
} catch (Throwable t) {
|
||||||
return Try.failure(t);
|
return Try.failure(t);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -75,10 +75,11 @@ public class HttpManager {
|
||||||
return true;
|
return true;
|
||||||
}).build();
|
}).build();
|
||||||
HostnameVerifier hostnameVerifier = NoopHostnameVerifier.INSTANCE;
|
HostnameVerifier hostnameVerifier = NoopHostnameVerifier.INSTANCE;
|
||||||
sslsf = new SSLConnectionSocketFactory(sslContext,
|
sslsf = new SSLConnectionSocketFactory(sslContext, hostnameVerifier);
|
||||||
new String[]{"TLSv1"},
|
// sslsf = new SSLConnectionSocketFactory(sslContext,
|
||||||
null,
|
// new String[]{"TLSv1"},
|
||||||
hostnameVerifier);
|
// null,
|
||||||
|
// hostnameVerifier);
|
||||||
} catch (NoSuchAlgorithmException | KeyStoreException | KeyManagementException e) {
|
} catch (NoSuchAlgorithmException | KeyStoreException | KeyManagementException e) {
|
||||||
throw new RuntimeException(e);
|
throw new RuntimeException(e);
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,6 +2,7 @@ package aiyh.utils.mapper;
|
||||||
|
|
||||||
import aiyh.utils.annotation.recordset.*;
|
import aiyh.utils.annotation.recordset.*;
|
||||||
import aiyh.utils.entity.DocImageInfo;
|
import aiyh.utils.entity.DocImageInfo;
|
||||||
|
import aiyh.utils.entity.FieldViewInfo;
|
||||||
import aiyh.utils.entity.SelectValueEntity;
|
import aiyh.utils.entity.SelectValueEntity;
|
||||||
import aiyh.utils.entity.WorkflowNodeConfig;
|
import aiyh.utils.entity.WorkflowNodeConfig;
|
||||||
|
|
||||||
|
@ -24,7 +25,7 @@ public interface UtilMapper {
|
||||||
* @return 是否开启Debug模式
|
* @return 是否开启Debug模式
|
||||||
*/
|
*/
|
||||||
@Select("select param_value from $t{configTableName} where only_mark = 'enableDebugLog'")
|
@Select("select param_value from $t{configTableName} where only_mark = 'enableDebugLog'")
|
||||||
public Boolean selectLogLevel(@ParamMapper("configTableName") String configTableName);
|
Boolean selectLogLevel(@ParamMapper("configTableName") String configTableName);
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -34,7 +35,7 @@ public interface UtilMapper {
|
||||||
* @return 参数值
|
* @return 参数值
|
||||||
*/
|
*/
|
||||||
@Select("select param_value from $t{configTableName} where only_mark = #{onlyMark} and enable_param = 1")
|
@Select("select param_value from $t{configTableName} where only_mark = #{onlyMark} and enable_param = 1")
|
||||||
public String selectCusConfigParam(@ParamMapper("onlyMark") String onlyMark,
|
String selectCusConfigParam(@ParamMapper("onlyMark") String onlyMark,
|
||||||
@ParamMapper("configTableName") String cusConfigTableName);
|
@ParamMapper("configTableName") String cusConfigTableName);
|
||||||
|
|
||||||
|
|
||||||
|
@ -150,6 +151,25 @@ public interface UtilMapper {
|
||||||
@Select("select * from workflow_bill where id = #{fromId}")
|
@Select("select * from workflow_bill where id = #{fromId}")
|
||||||
String selectBillTableByFromId(@ParamMapper("fromId") String fromId);
|
String selectBillTableByFromId(@ParamMapper("fromId") String fromId);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* <h2>删除指定表数据</h2>
|
||||||
|
*
|
||||||
|
* @param tableName 表名
|
||||||
|
* @param dataId 数据id
|
||||||
|
*/
|
||||||
@Delete("delete from $t{tableName} where id = #{dataId}")
|
@Delete("delete from $t{tableName} where id = #{dataId}")
|
||||||
void deleteModeId(@ParamMapper("tableName") String tableName, @ParamMapper("dataId") Integer dataId);
|
void deleteModeId(@ParamMapper("tableName") String tableName, @ParamMapper("dataId") Integer dataId);
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* <h2>根据字段id查询字段信息</h2>
|
||||||
|
*
|
||||||
|
* @param id 字段id
|
||||||
|
* @return 字段信息
|
||||||
|
*/
|
||||||
|
@Select("select id,fieldname field_name,tablename table_name,\n" +
|
||||||
|
" billid bill_id,fieldtype field_type,\n" +
|
||||||
|
" fieldhtmltype field_html_type\n" +
|
||||||
|
"from workflow_field_table_view where id = #{id}")
|
||||||
|
FieldViewInfo selectFieldInfo(Integer id);
|
||||||
}
|
}
|
||||||
|
|
|
@ -47,17 +47,28 @@ public class RecordsetUtil implements InvocationHandler {
|
||||||
@Override
|
@Override
|
||||||
public Object invoke(Object proxy, Method method, Object[] args) {
|
public Object invoke(Object proxy, Method method, Object[] args) {
|
||||||
if (autoCommit) {
|
if (autoCommit) {
|
||||||
return invokeRs(proxy, method, args);
|
return invokeRs(proxy, method, args, "");
|
||||||
}
|
}
|
||||||
return invokeRsTrans(proxy, method, args);
|
return invokeRsTrans(proxy, method, args, "");
|
||||||
|
}
|
||||||
|
|
||||||
|
public Object invoke(Object proxy, Method method, Object[] args, String name) {
|
||||||
|
if (autoCommit) {
|
||||||
|
return invokeRs(proxy, method, args, name);
|
||||||
|
}
|
||||||
|
return invokeRsTrans(proxy, method, args, name);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private Object invokeRs(Object proxy, Method method, Object[] args) {
|
private Object invokeRs(Object proxy, Method method, Object[] args, String name) {
|
||||||
RecordSet rs = rsManager.getRs(method.getDeclaringClass().getName());
|
String mapperKey = method.getDeclaringClass().getName();
|
||||||
|
if (!"".equals(name) && null != name) {
|
||||||
|
mapperKey += "." + name;
|
||||||
|
}
|
||||||
|
RecordSet rs = rsManager.getRs(mapperKey);
|
||||||
if (rs == null) {
|
if (rs == null) {
|
||||||
rsManager.setRecordSet(method.getDeclaringClass().getName());
|
rsManager.setRecordSet(mapperKey);
|
||||||
rs = rsManager.getRs(method.getDeclaringClass().getName());
|
rs = rsManager.getRs(mapperKey);
|
||||||
}
|
}
|
||||||
SqlHandler sqlHandler = new SqlHandler();
|
SqlHandler sqlHandler = new SqlHandler();
|
||||||
ResultMapper resultMapper = new ResultMapper();
|
ResultMapper resultMapper = new ResultMapper();
|
||||||
|
@ -68,7 +79,7 @@ public class RecordsetUtil implements InvocationHandler {
|
||||||
boolean custom = select.custom();
|
boolean custom = select.custom();
|
||||||
PrepSqlResultImpl handler = sqlHandler.handler(sql, custom, method, args);
|
PrepSqlResultImpl handler = sqlHandler.handler(sql, custom, method, args);
|
||||||
if (!handler.getSqlStr().trim().toLowerCase().startsWith("select ")) {
|
if (!handler.getSqlStr().trim().toLowerCase().startsWith("select ")) {
|
||||||
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!");
|
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!");
|
||||||
}
|
}
|
||||||
Util.getLogger(SQL_LOG).info("解析sql===>" + handler);
|
Util.getLogger(SQL_LOG).info("解析sql===>" + handler);
|
||||||
if (handler.getArgs().isEmpty()) {
|
if (handler.getArgs().isEmpty()) {
|
||||||
|
@ -76,7 +87,7 @@ public class RecordsetUtil implements InvocationHandler {
|
||||||
} else {
|
} else {
|
||||||
rs.executeQuery(handler.getSqlStr(), handler.getArgs());
|
rs.executeQuery(handler.getSqlStr(), handler.getArgs());
|
||||||
}
|
}
|
||||||
return resultMapper.mapperResult(rs, method, method.getReturnType());
|
return resultMapper.mapperResult(rs, method, method.getReturnType(), this);
|
||||||
}
|
}
|
||||||
Update update = method.getAnnotation(Update.class);
|
Update update = method.getAnnotation(Update.class);
|
||||||
if (update != null) {
|
if (update != null) {
|
||||||
|
@ -85,7 +96,7 @@ public class RecordsetUtil implements InvocationHandler {
|
||||||
boolean custom = update.custom();
|
boolean custom = update.custom();
|
||||||
PrepSqlResultImpl handler = sqlHandler.handler(sql, custom, method, args);
|
PrepSqlResultImpl handler = sqlHandler.handler(sql, custom, method, args);
|
||||||
if (!handler.getSqlStr().trim().toLowerCase().startsWith("update ")) {
|
if (!handler.getSqlStr().trim().toLowerCase().startsWith("update ")) {
|
||||||
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!");
|
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!");
|
||||||
}
|
}
|
||||||
Util.getLogger(SQL_LOG).info(handler.toString());
|
Util.getLogger(SQL_LOG).info(handler.toString());
|
||||||
Class<?> returnType = method.getReturnType();
|
Class<?> returnType = method.getReturnType();
|
||||||
|
@ -116,7 +127,7 @@ public class RecordsetUtil implements InvocationHandler {
|
||||||
boolean custom = insert.custom();
|
boolean custom = insert.custom();
|
||||||
PrepSqlResultImpl handler = sqlHandler.handler(sql, custom, method, args);
|
PrepSqlResultImpl handler = sqlHandler.handler(sql, custom, method, args);
|
||||||
if (!handler.getSqlStr().trim().toLowerCase().startsWith("insert ")) {
|
if (!handler.getSqlStr().trim().toLowerCase().startsWith("insert ")) {
|
||||||
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!");
|
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!");
|
||||||
}
|
}
|
||||||
Util.getLogger(SQL_LOG).info(handler.toString());
|
Util.getLogger(SQL_LOG).info(handler.toString());
|
||||||
Class<?> returnType = method.getReturnType();
|
Class<?> returnType = method.getReturnType();
|
||||||
|
@ -140,7 +151,7 @@ public class RecordsetUtil implements InvocationHandler {
|
||||||
boolean custom = delete.custom();
|
boolean custom = delete.custom();
|
||||||
PrepSqlResultImpl handler = sqlHandler.handler(sql, custom, method, args);
|
PrepSqlResultImpl handler = sqlHandler.handler(sql, custom, method, args);
|
||||||
if (!handler.getSqlStr().trim().toLowerCase().startsWith("delete ")) {
|
if (!handler.getSqlStr().trim().toLowerCase().startsWith("delete ")) {
|
||||||
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!");
|
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!");
|
||||||
}
|
}
|
||||||
Util.getLogger(SQL_LOG).info(handler.toString());
|
Util.getLogger(SQL_LOG).info(handler.toString());
|
||||||
Class<?> returnType = method.getReturnType();
|
Class<?> returnType = method.getReturnType();
|
||||||
|
@ -166,10 +177,10 @@ public class RecordsetUtil implements InvocationHandler {
|
||||||
BatchSqlResultImpl batchSqlResult = sqlHandler.handlerBatch(sql, custom, method, args);
|
BatchSqlResultImpl batchSqlResult = sqlHandler.handlerBatch(sql, custom, method, args);
|
||||||
Util.getLogger(SQL_LOG).info(batchSqlResult.toString());
|
Util.getLogger(SQL_LOG).info(batchSqlResult.toString());
|
||||||
if (batchSqlResult.getBatchList().isEmpty()) {
|
if (batchSqlResult.getBatchList().isEmpty()) {
|
||||||
throw new CustomerException("getDataId batch sql error , batch sql args is empty!");
|
throw new CustomerException("execute batch sql error , batch sql args is empty!");
|
||||||
}
|
}
|
||||||
if (!batchSqlResult.getSqlStr().trim().toLowerCase().startsWith("insert ")) {
|
if (!batchSqlResult.getSqlStr().trim().toLowerCase().startsWith("insert ")) {
|
||||||
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!");
|
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!");
|
||||||
}
|
}
|
||||||
boolean b = rs.executeBatchSql(batchSqlResult.getSqlStr(), batchSqlResult.getBatchList());
|
boolean b = rs.executeBatchSql(batchSqlResult.getSqlStr(), batchSqlResult.getBatchList());
|
||||||
if (returnType.equals(void.class)) {
|
if (returnType.equals(void.class)) {
|
||||||
|
@ -189,10 +200,10 @@ public class RecordsetUtil implements InvocationHandler {
|
||||||
BatchSqlResultImpl batchSqlResult = sqlHandler.handlerBatch(sql, custom, method, args);
|
BatchSqlResultImpl batchSqlResult = sqlHandler.handlerBatch(sql, custom, method, args);
|
||||||
Util.getLogger(SQL_LOG).info(batchSqlResult.toString());
|
Util.getLogger(SQL_LOG).info(batchSqlResult.toString());
|
||||||
if (batchSqlResult.getBatchList().isEmpty()) {
|
if (batchSqlResult.getBatchList().isEmpty()) {
|
||||||
throw new CustomerException("getDataId batch sql error , batch sql args is empty!");
|
throw new CustomerException("execute batch sql error , batch sql args is empty!");
|
||||||
}
|
}
|
||||||
if (!batchSqlResult.getSqlStr().trim().toLowerCase().startsWith("update ")) {
|
if (!batchSqlResult.getSqlStr().trim().toLowerCase().startsWith("update ")) {
|
||||||
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!");
|
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!");
|
||||||
}
|
}
|
||||||
boolean b = rs.executeBatchSql(batchSqlResult.getSqlStr(), batchSqlResult.getBatchList());
|
boolean b = rs.executeBatchSql(batchSqlResult.getSqlStr(), batchSqlResult.getBatchList());
|
||||||
if (returnType.equals(void.class)) {
|
if (returnType.equals(void.class)) {
|
||||||
|
@ -212,10 +223,10 @@ public class RecordsetUtil implements InvocationHandler {
|
||||||
BatchSqlResultImpl batchSqlResult = sqlHandler.handlerBatch(sql, custom, method, args);
|
BatchSqlResultImpl batchSqlResult = sqlHandler.handlerBatch(sql, custom, method, args);
|
||||||
Util.getLogger(SQL_LOG).info(batchSqlResult.toString());
|
Util.getLogger(SQL_LOG).info(batchSqlResult.toString());
|
||||||
if (batchSqlResult.getBatchList().isEmpty()) {
|
if (batchSqlResult.getBatchList().isEmpty()) {
|
||||||
throw new CustomerException("getDataId batch sql error , batch sql args is empty!");
|
throw new CustomerException("execute batch sql error , batch sql args is empty!");
|
||||||
}
|
}
|
||||||
if (!batchSqlResult.getSqlStr().trim().toLowerCase().startsWith("delete ")) {
|
if (!batchSqlResult.getSqlStr().trim().toLowerCase().startsWith("delete ")) {
|
||||||
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!");
|
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!");
|
||||||
}
|
}
|
||||||
boolean b = rs.executeBatchSql(batchSqlResult.getSqlStr(), batchSqlResult.getBatchList());
|
boolean b = rs.executeBatchSql(batchSqlResult.getSqlStr(), batchSqlResult.getBatchList());
|
||||||
if (returnType.equals(void.class)) {
|
if (returnType.equals(void.class)) {
|
||||||
|
@ -229,11 +240,15 @@ public class RecordsetUtil implements InvocationHandler {
|
||||||
throw new CustomerException("该方法没有添加注解!请检查是否正确添加注解!@Select、@Update、@Insert、@Delete、@BatchUpdate、@BatchInsert、@BatchDelete");
|
throw new CustomerException("该方法没有添加注解!请检查是否正确添加注解!@Select、@Update、@Insert、@Delete、@BatchUpdate、@BatchInsert、@BatchDelete");
|
||||||
}
|
}
|
||||||
|
|
||||||
private Object invokeRsTrans(Object proxy, Method method, Object[] args) {
|
private Object invokeRsTrans(Object proxy, Method method, Object[] args, String name) {
|
||||||
RecordSetTrans rs = rsManager.getTrans(method.getDeclaringClass().getName());
|
String mapperKey = method.getDeclaringClass().getName();
|
||||||
|
if (!"".equals(name) && null != name) {
|
||||||
|
mapperKey += "." + name;
|
||||||
|
}
|
||||||
|
RecordSetTrans rs = rsManager.getTrans(mapperKey);
|
||||||
if (rs == null) {
|
if (rs == null) {
|
||||||
rsManager.setRecordSetTrans(method.getDeclaringClass().getName());
|
rsManager.setRecordSetTrans(mapperKey);
|
||||||
rs = rsManager.getTrans(method.getDeclaringClass().getName());
|
rs = rsManager.getTrans(mapperKey);
|
||||||
}
|
}
|
||||||
SqlHandler sqlHandler = new SqlHandler();
|
SqlHandler sqlHandler = new SqlHandler();
|
||||||
ResultMapper resultMapper = new ResultMapper();
|
ResultMapper resultMapper = new ResultMapper();
|
||||||
|
@ -244,7 +259,7 @@ public class RecordsetUtil implements InvocationHandler {
|
||||||
boolean custom = select.custom();
|
boolean custom = select.custom();
|
||||||
PrepSqlResultImpl handler = sqlHandler.handler(sql, custom, method, args);
|
PrepSqlResultImpl handler = sqlHandler.handler(sql, custom, method, args);
|
||||||
if (!handler.getSqlStr().trim().toLowerCase().startsWith("select ")) {
|
if (!handler.getSqlStr().trim().toLowerCase().startsWith("select ")) {
|
||||||
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!");
|
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!");
|
||||||
}
|
}
|
||||||
Util.getLogger(SQL_LOG).info("解析sql===>" + handler);
|
Util.getLogger(SQL_LOG).info("解析sql===>" + handler);
|
||||||
try {
|
try {
|
||||||
|
@ -257,7 +272,7 @@ public class RecordsetUtil implements InvocationHandler {
|
||||||
Util.getLogger(SQL_LOG).error("execute sql error! " + Util.getErrString(e));
|
Util.getLogger(SQL_LOG).error("execute sql error! " + Util.getErrString(e));
|
||||||
throw new CustomerException("execute sql error!" + e.getMessage());
|
throw new CustomerException("execute sql error!" + e.getMessage());
|
||||||
}
|
}
|
||||||
return resultMapper.mapperResult(rs, method, method.getReturnType());
|
return resultMapper.mapperResult(rs, method, method.getReturnType(), this);
|
||||||
}
|
}
|
||||||
|
|
||||||
Update update = method.getAnnotation(Update.class);
|
Update update = method.getAnnotation(Update.class);
|
||||||
|
@ -267,7 +282,7 @@ public class RecordsetUtil implements InvocationHandler {
|
||||||
boolean custom = update.custom();
|
boolean custom = update.custom();
|
||||||
PrepSqlResultImpl handler = sqlHandler.handler(sql, custom, method, args);
|
PrepSqlResultImpl handler = sqlHandler.handler(sql, custom, method, args);
|
||||||
if (!handler.getSqlStr().trim().toLowerCase().startsWith("update ")) {
|
if (!handler.getSqlStr().trim().toLowerCase().startsWith("update ")) {
|
||||||
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!");
|
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!");
|
||||||
}
|
}
|
||||||
Util.getLogger(SQL_LOG).info(handler.toString());
|
Util.getLogger(SQL_LOG).info(handler.toString());
|
||||||
Class<?> returnType = method.getReturnType();
|
Class<?> returnType = method.getReturnType();
|
||||||
|
@ -303,7 +318,7 @@ public class RecordsetUtil implements InvocationHandler {
|
||||||
boolean custom = insert.custom();
|
boolean custom = insert.custom();
|
||||||
PrepSqlResultImpl handler = sqlHandler.handler(sql, custom, method, args);
|
PrepSqlResultImpl handler = sqlHandler.handler(sql, custom, method, args);
|
||||||
if (!handler.getSqlStr().trim().toLowerCase().startsWith("insert ")) {
|
if (!handler.getSqlStr().trim().toLowerCase().startsWith("insert ")) {
|
||||||
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!");
|
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!");
|
||||||
}
|
}
|
||||||
Util.getLogger(SQL_LOG).info(handler.toString());
|
Util.getLogger(SQL_LOG).info(handler.toString());
|
||||||
Class<?> returnType = method.getReturnType();
|
Class<?> returnType = method.getReturnType();
|
||||||
|
@ -332,7 +347,7 @@ public class RecordsetUtil implements InvocationHandler {
|
||||||
boolean custom = delete.custom();
|
boolean custom = delete.custom();
|
||||||
PrepSqlResultImpl handler = sqlHandler.handler(sql, custom, method, args);
|
PrepSqlResultImpl handler = sqlHandler.handler(sql, custom, method, args);
|
||||||
if (!handler.getSqlStr().trim().toLowerCase().startsWith("delete ")) {
|
if (!handler.getSqlStr().trim().toLowerCase().startsWith("delete ")) {
|
||||||
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!");
|
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!");
|
||||||
}
|
}
|
||||||
Util.getLogger(SQL_LOG).info(handler.toString());
|
Util.getLogger(SQL_LOG).info(handler.toString());
|
||||||
Class<?> returnType = method.getReturnType();
|
Class<?> returnType = method.getReturnType();
|
||||||
|
@ -364,7 +379,7 @@ public class RecordsetUtil implements InvocationHandler {
|
||||||
Util.getLogger(SQL_LOG).info(batchSqlResult.toString());
|
Util.getLogger(SQL_LOG).info(batchSqlResult.toString());
|
||||||
List<List> batchList = batchSqlResult.getBatchList();
|
List<List> batchList = batchSqlResult.getBatchList();
|
||||||
if (batchList.isEmpty()) {
|
if (batchList.isEmpty()) {
|
||||||
throw new CustomerException("getDataId batch sql error , batch sql args is empty!");
|
throw new CustomerException("execute batch sql error , batch sql args is empty!");
|
||||||
}
|
}
|
||||||
List<List<Object>> batchListTrans = new ArrayList<>();
|
List<List<Object>> batchListTrans = new ArrayList<>();
|
||||||
for (List list : batchList) {
|
for (List list : batchList) {
|
||||||
|
@ -376,7 +391,7 @@ public class RecordsetUtil implements InvocationHandler {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!batchSqlResult.getSqlStr().trim().toLowerCase().startsWith("insert ")) {
|
if (!batchSqlResult.getSqlStr().trim().toLowerCase().startsWith("insert ")) {
|
||||||
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!");
|
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!");
|
||||||
}
|
}
|
||||||
boolean b = true;
|
boolean b = true;
|
||||||
try {
|
try {
|
||||||
|
@ -402,15 +417,15 @@ public class RecordsetUtil implements InvocationHandler {
|
||||||
BatchSqlResultImpl batchSqlResult = sqlHandler.handlerBatch(sql, custom, method, args);
|
BatchSqlResultImpl batchSqlResult = sqlHandler.handlerBatch(sql, custom, method, args);
|
||||||
Util.getLogger(SQL_LOG).info(batchSqlResult.toString());
|
Util.getLogger(SQL_LOG).info(batchSqlResult.toString());
|
||||||
if (batchSqlResult.getBatchList().isEmpty()) {
|
if (batchSqlResult.getBatchList().isEmpty()) {
|
||||||
throw new CustomerException("getDataId batch sql error , batch sql args is empty!");
|
throw new CustomerException("execute batch sql error , batch sql args is empty!");
|
||||||
}
|
}
|
||||||
if (!batchSqlResult.getSqlStr().trim().toLowerCase().startsWith("update ")) {
|
if (!batchSqlResult.getSqlStr().trim().toLowerCase().startsWith("update ")) {
|
||||||
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!");
|
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!");
|
||||||
}
|
}
|
||||||
|
|
||||||
List<List> batchList = batchSqlResult.getBatchList();
|
List<List> batchList = batchSqlResult.getBatchList();
|
||||||
if (batchList.isEmpty()) {
|
if (batchList.isEmpty()) {
|
||||||
throw new CustomerException("getDataId batch sql error , batch sql args is empty!");
|
throw new CustomerException("execute batch sql error , batch sql args is empty!");
|
||||||
}
|
}
|
||||||
List<List<Object>> batchListTrans = new ArrayList<>();
|
List<List<Object>> batchListTrans = new ArrayList<>();
|
||||||
for (List list : batchList) {
|
for (List list : batchList) {
|
||||||
|
@ -443,14 +458,14 @@ public class RecordsetUtil implements InvocationHandler {
|
||||||
BatchSqlResultImpl batchSqlResult = sqlHandler.handlerBatch(sql, custom, method, args);
|
BatchSqlResultImpl batchSqlResult = sqlHandler.handlerBatch(sql, custom, method, args);
|
||||||
Util.getLogger(SQL_LOG).info(batchSqlResult.toString());
|
Util.getLogger(SQL_LOG).info(batchSqlResult.toString());
|
||||||
if (batchSqlResult.getBatchList().isEmpty()) {
|
if (batchSqlResult.getBatchList().isEmpty()) {
|
||||||
throw new CustomerException("getDataId batch sql error , batch sql args is empty!");
|
throw new CustomerException("execute batch sql error , batch sql args is empty!");
|
||||||
}
|
}
|
||||||
if (!batchSqlResult.getSqlStr().trim().toLowerCase().startsWith("delete ")) {
|
if (!batchSqlResult.getSqlStr().trim().toLowerCase().startsWith("delete ")) {
|
||||||
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!");
|
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!");
|
||||||
}
|
}
|
||||||
List<List> batchList = batchSqlResult.getBatchList();
|
List<List> batchList = batchSqlResult.getBatchList();
|
||||||
if (batchList.isEmpty()) {
|
if (batchList.isEmpty()) {
|
||||||
throw new CustomerException("getDataId batch sql error , batch sql args is empty!");
|
throw new CustomerException("execute batch sql error , batch sql args is empty!");
|
||||||
}
|
}
|
||||||
List<List<Object>> batchListTrans = new ArrayList<>();
|
List<List<Object>> batchListTrans = new ArrayList<>();
|
||||||
for (List list : batchList) {
|
for (List list : batchList) {
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
package aiyh.utils.recordset;
|
package aiyh.utils.recordset;
|
||||||
|
|
||||||
import aiyh.utils.Util;
|
import aiyh.utils.Util;
|
||||||
import aiyh.utils.annotation.recordset.CaseConversion;
|
import aiyh.utils.annotation.recordset.*;
|
||||||
import aiyh.utils.excention.CustomerException;
|
import aiyh.utils.excention.CustomerException;
|
||||||
import aiyh.utils.excention.TypeNonsupportException;
|
import aiyh.utils.excention.TypeNonsupportException;
|
||||||
import com.google.common.base.Strings;
|
import com.google.common.base.Strings;
|
||||||
|
@ -13,15 +13,20 @@ import java.beans.Introspector;
|
||||||
import java.beans.PropertyDescriptor;
|
import java.beans.PropertyDescriptor;
|
||||||
import java.lang.reflect.*;
|
import java.lang.reflect.*;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
|
import java.util.function.Function;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author EBU7-dev1-ayh create 2021/12/21 0021 11:03
|
* @author EBU7-dev1-ayh create 2021/12/21 0021 11:03
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
@SuppressWarnings("all")
|
||||||
public class ResultMapper {
|
public class ResultMapper {
|
||||||
|
|
||||||
private static Map<Class<?>, TypeHandler> typeHandler = new HashMap<>();
|
private static final Map<Class<?>, TypeHandler> typeHandler = new HashMap<>();
|
||||||
|
private static final Map<Class<?>, Function<String, Object>> paramType = new HashMap<>();
|
||||||
|
|
||||||
|
private RecordsetUtil recordsetUtil = null;
|
||||||
|
|
||||||
static {
|
static {
|
||||||
IntegerTypeHandler integerTypeHandler = new IntegerTypeHandler();
|
IntegerTypeHandler integerTypeHandler = new IntegerTypeHandler();
|
||||||
|
@ -39,7 +44,21 @@ public class ResultMapper {
|
||||||
typeHandler.put(float.class, new FloatTypeHandler());
|
typeHandler.put(float.class, new FloatTypeHandler());
|
||||||
}
|
}
|
||||||
|
|
||||||
public <T> T mapperResult(RecordSet rs, Method method, Class<T> tClass) {
|
static {
|
||||||
|
paramType.put(String.class, value -> value);
|
||||||
|
paramType.put(Integer.class, Integer::parseInt);
|
||||||
|
paramType.put(int.class, Integer::parseInt);
|
||||||
|
paramType.put(byte.class, Byte::parseByte);
|
||||||
|
paramType.put(short.class, Short::parseShort);
|
||||||
|
paramType.put(long.class, Long::parseLong);
|
||||||
|
paramType.put(Boolean.class, Boolean::parseBoolean);
|
||||||
|
paramType.put(boolean.class, Boolean::parseBoolean);
|
||||||
|
paramType.put(Float.class, Float::parseFloat);
|
||||||
|
paramType.put(float.class, Float::parseFloat);
|
||||||
|
}
|
||||||
|
|
||||||
|
public <T> T mapperResult(RecordSet rs, Method method, Class<T> tClass, RecordsetUtil recordsetUtil) {
|
||||||
|
this.recordsetUtil = recordsetUtil;
|
||||||
if (tClass.equals(void.class)) {
|
if (tClass.equals(void.class)) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
@ -60,7 +79,7 @@ public class ResultMapper {
|
||||||
T t = tClass.newInstance();
|
T t = tClass.newInstance();
|
||||||
if (t instanceof Collection) {
|
if (t instanceof Collection) {
|
||||||
// 集合求出泛型
|
// 集合求出泛型
|
||||||
//获取返回值的类型
|
// 获取返回值的类型
|
||||||
Type genericReturnType = method.getGenericReturnType();
|
Type genericReturnType = method.getGenericReturnType();
|
||||||
Type actualTypeArgument = ((ParameterizedType) genericReturnType).getActualTypeArguments()[0];
|
Type actualTypeArgument = ((ParameterizedType) genericReturnType).getActualTypeArguments()[0];
|
||||||
Class<?> rawType = this.getRawType(actualTypeArgument);
|
Class<?> rawType = this.getRawType(actualTypeArgument);
|
||||||
|
@ -87,6 +106,7 @@ public class ResultMapper {
|
||||||
throw new CustomerException("can not Initialization " + t.getClass() + " [" + rawType + "]");
|
throw new CustomerException("can not Initialization " + t.getClass() + " [" + rawType + "]");
|
||||||
}
|
}
|
||||||
Object object = getObject(rs, o, method);
|
Object object = getObject(rs, o, method);
|
||||||
|
|
||||||
((Collection<? super Object>) t).add(object);
|
((Collection<? super Object>) t).add(object);
|
||||||
}
|
}
|
||||||
return t;
|
return t;
|
||||||
|
@ -97,7 +117,7 @@ public class ResultMapper {
|
||||||
Type actualTypeArgument = ((ParameterizedType) genericReturnType).getActualTypeArguments()[0];
|
Type actualTypeArgument = ((ParameterizedType) genericReturnType).getActualTypeArguments()[0];
|
||||||
Class<?> rawType = this.getRawType(actualTypeArgument);
|
Class<?> rawType = this.getRawType(actualTypeArgument);
|
||||||
if (rawType.equals(List.class)) {
|
if (rawType.equals(List.class)) {
|
||||||
rawType = (Class<T>) ArrayList.class;
|
rawType = ArrayList.class;
|
||||||
}
|
}
|
||||||
if (rawType.equals(Map.class)) {
|
if (rawType.equals(Map.class)) {
|
||||||
rawType = HashMap.class;
|
rawType = HashMap.class;
|
||||||
|
@ -142,7 +162,8 @@ public class ResultMapper {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public <T> T mapperResult(RecordSetTrans rs, Method method, Class<T> tClass) {
|
public <T> T mapperResult(RecordSetTrans rs, Method method, Class<T> tClass, RecordsetUtil recordsetUtil) {
|
||||||
|
this.recordsetUtil = recordsetUtil;
|
||||||
if (tClass.equals(void.class)) {
|
if (tClass.equals(void.class)) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
@ -163,7 +184,7 @@ public class ResultMapper {
|
||||||
T t = tClass.newInstance();
|
T t = tClass.newInstance();
|
||||||
if (t instanceof Collection) {
|
if (t instanceof Collection) {
|
||||||
// 集合求出泛型
|
// 集合求出泛型
|
||||||
//获取返回值的类型
|
// 获取返回值的类型
|
||||||
Type genericReturnType = method.getGenericReturnType();
|
Type genericReturnType = method.getGenericReturnType();
|
||||||
Type actualTypeArgument = ((ParameterizedType) genericReturnType).getActualTypeArguments()[0];
|
Type actualTypeArgument = ((ParameterizedType) genericReturnType).getActualTypeArguments()[0];
|
||||||
Class<?> rawType = this.getRawType(actualTypeArgument);
|
Class<?> rawType = this.getRawType(actualTypeArgument);
|
||||||
|
@ -200,7 +221,7 @@ public class ResultMapper {
|
||||||
Type actualTypeArgument = ((ParameterizedType) genericReturnType).getActualTypeArguments()[0];
|
Type actualTypeArgument = ((ParameterizedType) genericReturnType).getActualTypeArguments()[0];
|
||||||
Class<?> rawType = this.getRawType(actualTypeArgument);
|
Class<?> rawType = this.getRawType(actualTypeArgument);
|
||||||
if (rawType.equals(List.class)) {
|
if (rawType.equals(List.class)) {
|
||||||
rawType = (Class<T>) ArrayList.class;
|
rawType = ArrayList.class;
|
||||||
}
|
}
|
||||||
if (rawType.equals(Map.class)) {
|
if (rawType.equals(Map.class)) {
|
||||||
rawType = HashMap.class;
|
rawType = HashMap.class;
|
||||||
|
@ -247,7 +268,7 @@ public class ResultMapper {
|
||||||
|
|
||||||
public Object getObjectTrans(RecordSetTrans rs, Object o, Method method) {
|
public Object getObjectTrans(RecordSetTrans rs, Object o, Method method) {
|
||||||
CaseConversion annotation = method.getAnnotation(CaseConversion.class);
|
CaseConversion annotation = method.getAnnotation(CaseConversion.class);
|
||||||
boolean enable = annotation == null ? true : annotation.value();
|
boolean enable = annotation == null || annotation.value();
|
||||||
String[] columnName = rs.getColumnName();
|
String[] columnName = rs.getColumnName();
|
||||||
String[] columnTypeName = rs.getColumnTypeName();
|
String[] columnTypeName = rs.getColumnTypeName();
|
||||||
int[] columnTypes = rs.getColumnType();
|
int[] columnTypes = rs.getColumnType();
|
||||||
|
@ -280,7 +301,7 @@ public class ResultMapper {
|
||||||
((Map<? super Object, ? super Object>) o).put(Util.toCamelCase(columnName[i]), rs.getInt(i + 1));
|
((Map<? super Object, ? super Object>) o).put(Util.toCamelCase(columnName[i]), rs.getInt(i + 1));
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
((Map<? super Object, ? super Object>) o).put(columnName[i], rs.getInt(i + 1));
|
((Map<? super Object, ? super Object>) o).put(columnName[i].toLowerCase(), rs.getInt(i + 1));
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if ("FLOAT".equalsIgnoreCase(columnType) || "DOUBLE".equalsIgnoreCase(columnType) || "DECIMAL".equalsIgnoreCase(columnType)) {
|
if ("FLOAT".equalsIgnoreCase(columnType) || "DOUBLE".equalsIgnoreCase(columnType) || "DECIMAL".equalsIgnoreCase(columnType)) {
|
||||||
|
@ -288,14 +309,14 @@ public class ResultMapper {
|
||||||
((Map<? super Object, ? super Object>) o).put(Util.toCamelCase(columnName[i]), rs.getFloat(i + 1));
|
((Map<? super Object, ? super Object>) o).put(Util.toCamelCase(columnName[i]), rs.getFloat(i + 1));
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
((Map<? super Object, ? super Object>) o).put(columnName[i], rs.getFloat(i + 1));
|
((Map<? super Object, ? super Object>) o).put(columnName[i].toLowerCase(), rs.getFloat(i + 1));
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if (enable) {
|
if (enable) {
|
||||||
((Map<? super Object, ? super Object>) o).put(Util.toCamelCase(columnName[i]), rs.getString(i + 1));
|
((Map<? super Object, ? super Object>) o).put(Util.toCamelCase(columnName[i]), rs.getString(i + 1));
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
((Map<? super Object, ? super Object>) o).put(columnName[i], rs.getString(i + 1));
|
((Map<? super Object, ? super Object>) o).put(columnName[i].toLowerCase(), rs.getString(i + 1));
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
return o;
|
return o;
|
||||||
|
@ -339,9 +360,6 @@ public class ResultMapper {
|
||||||
if (Strings.isNullOrEmpty(fieldName)) {
|
if (Strings.isNullOrEmpty(fieldName)) {
|
||||||
fieldName = propertyDescriptor.getDisplayName();
|
fieldName = propertyDescriptor.getDisplayName();
|
||||||
}
|
}
|
||||||
// Util.getLogger().info("获取类字段:" + fieldName);
|
|
||||||
// Util.getLogger().info("获取类字段1:" + propertyDescriptor.getDisplayName());
|
|
||||||
// Util.getLogger().info("获取的数据库数据:" + rs.getString(fieldName));
|
|
||||||
Field declaredField = o.getClass().getDeclaredField(fieldName);
|
Field declaredField = o.getClass().getDeclaredField(fieldName);
|
||||||
if (enable) {
|
if (enable) {
|
||||||
value = ResultMapper.typeHandler.get(propertyType) == null ? null : ResultMapper.typeHandler.get(propertyType).getValue(rs, Util.toUnderlineCase(fieldName), declaredField);
|
value = ResultMapper.typeHandler.get(propertyType) == null ? null : ResultMapper.typeHandler.get(propertyType).getValue(rs, Util.toUnderlineCase(fieldName), declaredField);
|
||||||
|
@ -352,15 +370,15 @@ public class ResultMapper {
|
||||||
}
|
}
|
||||||
|
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
e.printStackTrace();
|
|
||||||
Util.getLogger().error("报错了,写入数据到实体类报错!\n" + Util.getErrString(e));
|
Util.getLogger().error("报错了,写入数据到实体类报错!\n" + Util.getErrString(e));
|
||||||
|
throw new CustomerException(e);
|
||||||
}
|
}
|
||||||
return o;
|
return o;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Object getObject(RecordSet rs, Object o, Method method) {
|
public Object getObject(RecordSet rs, Object o, Method method) {
|
||||||
CaseConversion annotation = method.getAnnotation(CaseConversion.class);
|
CaseConversion annotation = method.getAnnotation(CaseConversion.class);
|
||||||
boolean enable = annotation == null ? true : annotation.value();
|
boolean enable = annotation == null || annotation.value();
|
||||||
String[] columnName = rs.getColumnName();
|
String[] columnName = rs.getColumnName();
|
||||||
String[] columnTypeName = rs.getColumnTypeName();
|
String[] columnTypeName = rs.getColumnTypeName();
|
||||||
int[] columnTypes = rs.getColumnType();
|
int[] columnTypes = rs.getColumnType();
|
||||||
|
@ -388,9 +406,9 @@ public class ResultMapper {
|
||||||
if (o instanceof Map) {
|
if (o instanceof Map) {
|
||||||
for (int i = 0; i < columnName.length; i++) {
|
for (int i = 0; i < columnName.length; i++) {
|
||||||
String columnType = "";
|
String columnType = "";
|
||||||
if(i >= columnTypeName.length){
|
if (i >= columnTypeName.length) {
|
||||||
columnType = "varchar";
|
columnType = "varchar";
|
||||||
}else {
|
} else {
|
||||||
columnType = columnTypeName[i];
|
columnType = columnTypeName[i];
|
||||||
}
|
}
|
||||||
if ("int".equalsIgnoreCase(columnType) || "long".equalsIgnoreCase(columnType) || "number".equalsIgnoreCase(columnType) || "MEDIUMINT".equalsIgnoreCase(columnType) || "TINYINT".equalsIgnoreCase(columnType) || "SMALLINT".equalsIgnoreCase(columnType) || "BIGINT".equalsIgnoreCase(columnType) || "INTEGER".equalsIgnoreCase(columnType)) {
|
if ("int".equalsIgnoreCase(columnType) || "long".equalsIgnoreCase(columnType) || "number".equalsIgnoreCase(columnType) || "MEDIUMINT".equalsIgnoreCase(columnType) || "TINYINT".equalsIgnoreCase(columnType) || "SMALLINT".equalsIgnoreCase(columnType) || "BIGINT".equalsIgnoreCase(columnType) || "INTEGER".equalsIgnoreCase(columnType)) {
|
||||||
|
@ -398,7 +416,7 @@ public class ResultMapper {
|
||||||
((Map<? super Object, ? super Object>) o).put(Util.toCamelCase(columnName[i]), rs.getInt(i + 1));
|
((Map<? super Object, ? super Object>) o).put(Util.toCamelCase(columnName[i]), rs.getInt(i + 1));
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
((Map<? super Object, ? super Object>) o).put(columnName[i], rs.getInt(i + 1));
|
((Map<? super Object, ? super Object>) o).put(columnName[i].toLowerCase(), rs.getInt(i + 1));
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if ("FLOAT".equalsIgnoreCase(columnType) || "DOUBLE".equalsIgnoreCase(columnType) || "DECIMAL".equalsIgnoreCase(columnType)) {
|
if ("FLOAT".equalsIgnoreCase(columnType) || "DOUBLE".equalsIgnoreCase(columnType) || "DECIMAL".equalsIgnoreCase(columnType)) {
|
||||||
|
@ -406,15 +424,36 @@ public class ResultMapper {
|
||||||
((Map<? super Object, ? super Object>) o).put(Util.toCamelCase(columnName[i]), rs.getFloat(i + 1));
|
((Map<? super Object, ? super Object>) o).put(Util.toCamelCase(columnName[i]), rs.getFloat(i + 1));
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
((Map<? super Object, ? super Object>) o).put(columnName[i], rs.getFloat(i + 1));
|
((Map<? super Object, ? super Object>) o).put(columnName[i].toLowerCase(), rs.getFloat(i + 1));
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
if (method.isAnnotationPresent(Associations.class)) {
|
||||||
|
Association association = searchAssociation(method, columnName[i], true);
|
||||||
|
if (association != null) {
|
||||||
|
if (association.column().equalsIgnoreCase(columnName[i])) {
|
||||||
|
Object cassociationValue = association(rs, association, method);
|
||||||
|
((Map<? super Object, ? super Object>) o).put(association.property(), cassociationValue);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (method.isAnnotationPresent(CollectionMappings.class)) {
|
||||||
|
CollectionMapping collectionMapping = searchCollection(method, columnName[i], true);
|
||||||
|
if (collectionMapping != null) {
|
||||||
|
if (collectionMapping.column().equals(columnName[i])) {
|
||||||
|
Object collection = collection(rs, collectionMapping, method);
|
||||||
|
String property = collectionMapping.property();
|
||||||
|
((Map<? super Object, ? super Object>) o).put(property, collection);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
if (enable) {
|
if (enable) {
|
||||||
((Map<? super Object, ? super Object>) o).put(Util.toCamelCase(columnName[i]), rs.getString(i + 1));
|
((Map<? super Object, ? super Object>) o).put(Util.toCamelCase(columnName[i]), rs.getString(i + 1));
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
((Map<? super Object, ? super Object>) o).put(columnName[i], rs.getString(i + 1));
|
((Map<? super Object, ? super Object>) o).put(columnName[i].toLowerCase(), rs.getString(i + 1));
|
||||||
continue;
|
|
||||||
}
|
}
|
||||||
return o;
|
return o;
|
||||||
}
|
}
|
||||||
|
@ -449,6 +488,7 @@ public class ResultMapper {
|
||||||
// Util.getLogger().info("获取对象:" + o.toString());
|
// Util.getLogger().info("获取对象:" + o.toString());
|
||||||
BeanInfo beanInfo = Introspector.getBeanInfo(o.getClass(), Object.class);
|
BeanInfo beanInfo = Introspector.getBeanInfo(o.getClass(), Object.class);
|
||||||
PropertyDescriptor[] propertyDescriptors = beanInfo.getPropertyDescriptors();
|
PropertyDescriptor[] propertyDescriptors = beanInfo.getPropertyDescriptors();
|
||||||
|
|
||||||
for (PropertyDescriptor propertyDescriptor : propertyDescriptors) {
|
for (PropertyDescriptor propertyDescriptor : propertyDescriptors) {
|
||||||
Class<?> propertyType = propertyDescriptor.getPropertyType();
|
Class<?> propertyType = propertyDescriptor.getPropertyType();
|
||||||
Object value = null;
|
Object value = null;
|
||||||
|
@ -457,9 +497,26 @@ public class ResultMapper {
|
||||||
if (Strings.isNullOrEmpty(fieldName)) {
|
if (Strings.isNullOrEmpty(fieldName)) {
|
||||||
fieldName = propertyDescriptor.getDisplayName();
|
fieldName = propertyDescriptor.getDisplayName();
|
||||||
}
|
}
|
||||||
// Util.getLogger().info("获取类字段:" + fieldName);
|
if (method.isAnnotationPresent(Associations.class)) {
|
||||||
// Util.getLogger().info("获取类字段1:" + propertyDescriptor.getDisplayName());
|
Association association = searchAssociation(method, fieldName, false);
|
||||||
// Util.getLogger().info("获取的数据库数据:" + rs.getString(fieldName));
|
if (association != null) {
|
||||||
|
if (association.property().equals(fieldName)) {
|
||||||
|
Object cassociationValue = association(rs, association, method);
|
||||||
|
propertyDescriptor.getWriteMethod().invoke(o, cassociationValue);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (method.isAnnotationPresent(CollectionMappings.class)) {
|
||||||
|
CollectionMapping collectionMapping = searchCollection(method, fieldName, false);
|
||||||
|
if (collectionMapping != null) {
|
||||||
|
if (fieldName.equals(collectionMapping.property()) && !"".equals(collectionMapping.property())) {
|
||||||
|
Object collection = collection(rs, collectionMapping, method);
|
||||||
|
propertyDescriptor.getWriteMethod().invoke(o, collection);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
Field declaredField = o.getClass().getDeclaredField(fieldName);
|
Field declaredField = o.getClass().getDeclaredField(fieldName);
|
||||||
if (enable) {
|
if (enable) {
|
||||||
value = ResultMapper.typeHandler.get(propertyType) == null ? null : ResultMapper.typeHandler.get(propertyType).getValue(rs, Util.toUnderlineCase(fieldName), declaredField);
|
value = ResultMapper.typeHandler.get(propertyType) == null ? null : ResultMapper.typeHandler.get(propertyType).getValue(rs, Util.toUnderlineCase(fieldName), declaredField);
|
||||||
|
@ -469,9 +526,10 @@ public class ResultMapper {
|
||||||
propertyDescriptor.getWriteMethod().invoke(o, value);
|
propertyDescriptor.getWriteMethod().invoke(o, value);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
e.printStackTrace();
|
|
||||||
Util.getLogger().error("报错了,写入数据到实体类报错!\n" + Util.getErrString(e));
|
Util.getLogger().error("报错了,写入数据到实体类报错!\n" + Util.getErrString(e));
|
||||||
|
throw new CustomerException(e.getMessage(), e);
|
||||||
}
|
}
|
||||||
return o;
|
return o;
|
||||||
}
|
}
|
||||||
|
@ -495,4 +553,121 @@ public class ResultMapper {
|
||||||
throw new IllegalArgumentException("Expected a Class, ParameterizedType, or GenericArrayType, but <" + type + "> is of type " + className);
|
throw new IllegalArgumentException("Expected a Class, ParameterizedType, or GenericArrayType, but <" + type + "> is of type " + className);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
private Association searchAssociation(Method method, String filedName, boolean isMap) {
|
||||||
|
|
||||||
|
Associations annotation = method.getAnnotation(Associations.class);
|
||||||
|
Association[] mappings = annotation.value();
|
||||||
|
Association mapping = null;
|
||||||
|
for (Association item : mappings) {
|
||||||
|
String property = isMap ? item.column() : item.property();
|
||||||
|
if (isMap ? filedName.equalsIgnoreCase(property) : filedName.equals(property)) {
|
||||||
|
mapping = item;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return mapping;
|
||||||
|
}
|
||||||
|
|
||||||
|
private Object association(RecordSet rs, Association annotation, Method method) {
|
||||||
|
Id id = annotation.id();
|
||||||
|
String column = annotation.column();
|
||||||
|
String columnValue = rs.getString(column);
|
||||||
|
if (Objects.isNull(columnValue) || "".equals(columnValue)) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
if (id.methodId() != -1) {
|
||||||
|
Class<?> declaringClass = method.getDeclaringClass();
|
||||||
|
Method[] declaredMethods = declaringClass.getDeclaredMethods();
|
||||||
|
for (Method declaredMethod : declaredMethods) {
|
||||||
|
if (declaredMethod.isAnnotationPresent(AssociationMethod.class)) {
|
||||||
|
AssociationMethod collectionMethod = declaredMethod.getAnnotation(AssociationMethod.class);
|
||||||
|
int value = collectionMethod.value();
|
||||||
|
if (id.methodId() == value) {
|
||||||
|
return recordsetUtil.invoke(null, declaredMethod,
|
||||||
|
new Object[]{paramType.get(id.value()).apply(columnValue)}, declaredMethod.getName());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
String selectMethod = annotation.select();
|
||||||
|
int i = selectMethod.lastIndexOf(".");
|
||||||
|
String selectClass = selectMethod.substring(0, i);
|
||||||
|
Class<?> aClass = null;
|
||||||
|
try {
|
||||||
|
aClass = Class.forName(selectClass);
|
||||||
|
} catch (ClassNotFoundException e) {
|
||||||
|
throw new RuntimeException(e);
|
||||||
|
}
|
||||||
|
Method associationMethod = null;
|
||||||
|
try {
|
||||||
|
associationMethod = aClass.getMethod(selectMethod.substring(i + 1), id.value());
|
||||||
|
} catch (NoSuchMethodException e) {
|
||||||
|
throw new RuntimeException(e);
|
||||||
|
}
|
||||||
|
Class<?> returnType = associationMethod.getReturnType();
|
||||||
|
if (List.class.isAssignableFrom(returnType)) {
|
||||||
|
throw new CustomerException("can not set result, association annotation not support result of list! Do you want to use @CollectionSql!");
|
||||||
|
}
|
||||||
|
return recordsetUtil.invoke(null, associationMethod,
|
||||||
|
new Object[]{paramType.get(id.value()).apply(columnValue)}, selectMethod);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
private CollectionMapping searchCollection(Method method, String filedName, boolean isMap) {
|
||||||
|
CollectionMappings annotation = method.getAnnotation(CollectionMappings.class);
|
||||||
|
CollectionMapping[] mappings = annotation.value();
|
||||||
|
CollectionMapping mapping = null;
|
||||||
|
for (CollectionMapping item : mappings) {
|
||||||
|
String property = isMap ? item.column() : item.property();
|
||||||
|
if (isMap ? filedName.equalsIgnoreCase(property) : filedName.equals(property)) {
|
||||||
|
mapping = item;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return mapping;
|
||||||
|
}
|
||||||
|
|
||||||
|
private Object collection(RecordSet rs, CollectionMapping annotation, Method method) {
|
||||||
|
Id id = annotation.id();
|
||||||
|
String column = annotation.column();
|
||||||
|
String columnValue = rs.getString(column);
|
||||||
|
if (Objects.isNull(columnValue) || "".equals(columnValue)) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
if (id.methodId() != -1) {
|
||||||
|
Class<?> declaringClass = method.getDeclaringClass();
|
||||||
|
Method[] declaredMethods = declaringClass.getDeclaredMethods();
|
||||||
|
for (Method declaredMethod : declaredMethods) {
|
||||||
|
if (declaredMethod.isAnnotationPresent(CollectionMethod.class)) {
|
||||||
|
CollectionMethod collectionMethod = declaredMethod.getAnnotation(CollectionMethod.class);
|
||||||
|
int value = collectionMethod.value();
|
||||||
|
if (id.methodId() == value) {
|
||||||
|
return recordsetUtil.invoke(null, declaredMethod,
|
||||||
|
new Object[]{paramType.get(id.value()).apply(columnValue)}, declaredMethod.getName());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
String selectMethod = annotation.select();
|
||||||
|
int i = selectMethod.lastIndexOf(".");
|
||||||
|
String selectClass = selectMethod.substring(0, i);
|
||||||
|
Class<?> aClass = null;
|
||||||
|
try {
|
||||||
|
aClass = Class.forName(selectClass);
|
||||||
|
} catch (ClassNotFoundException e) {
|
||||||
|
throw new RuntimeException(e);
|
||||||
|
}
|
||||||
|
Method associationMethod = null;
|
||||||
|
try {
|
||||||
|
associationMethod = aClass.getMethod(selectMethod.substring(i + 1), id.value());
|
||||||
|
} catch (NoSuchMethodException e) {
|
||||||
|
throw new RuntimeException(e);
|
||||||
|
}
|
||||||
|
Class<?> returnType = associationMethod.getReturnType();
|
||||||
|
if (!List.class.isAssignableFrom(returnType)) {
|
||||||
|
throw new CustomerException("can not set result, CollectionSql annotation only support result of list! Do you want to use @Association!");
|
||||||
|
}
|
||||||
|
return recordsetUtil.invoke(null, associationMethod,
|
||||||
|
new Object[]{paramType.get(id.value()).apply(columnValue)}, selectMethod);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -44,4 +44,33 @@ public class RaceTrackController {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@GET
|
||||||
|
@Path("/get/stage-info")
|
||||||
|
@Produces(MediaType.APPLICATION_JSON)
|
||||||
|
@Consumes(MediaType.APPLICATION_JSON)
|
||||||
|
public String getStageInfo(@Context HttpServletRequest request, @Context HttpServletResponse response) {
|
||||||
|
User user = HrmUserVarify.getUser(request, response);
|
||||||
|
try {
|
||||||
|
return ApiResult.success(service.getStageInfo(user));
|
||||||
|
} catch (Exception e) {
|
||||||
|
log.info("race track get event list error!\n" + Util.getErrString(e));
|
||||||
|
return ApiResult.error("race track get event list error!");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@GET
|
||||||
|
@Path("/get/status")
|
||||||
|
@Produces(MediaType.APPLICATION_JSON)
|
||||||
|
@Consumes(MediaType.APPLICATION_JSON)
|
||||||
|
public String getUserStatus(@Context HttpServletRequest request, @Context HttpServletResponse response) {
|
||||||
|
try {
|
||||||
|
User user = HrmUserVarify.getUser(request, response);
|
||||||
|
return ApiResult.success(user.getStatus());
|
||||||
|
} catch (Exception e) {
|
||||||
|
log.info("get usr status fail!\n" + Util.getErrString(e));
|
||||||
|
return ApiResult.error("get usr status fail!");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,32 @@
|
||||||
|
package com.api.youhong.ai.pcn.racetrack.dto;
|
||||||
|
|
||||||
|
import lombok.Getter;
|
||||||
|
import lombok.Setter;
|
||||||
|
import lombok.ToString;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* <h1>直道图数据库对象</h1>
|
||||||
|
*
|
||||||
|
* <p>create: 2023/2/17 11:41</p>
|
||||||
|
*
|
||||||
|
* @author youHong.ai
|
||||||
|
*/
|
||||||
|
@Setter
|
||||||
|
@Getter
|
||||||
|
@ToString
|
||||||
|
public class RaceTrackStage {
|
||||||
|
/** id */
|
||||||
|
private int id;
|
||||||
|
|
||||||
|
/** 一阶段 */
|
||||||
|
private String oneStage;
|
||||||
|
|
||||||
|
/** 二阶段 */
|
||||||
|
private String towStage;
|
||||||
|
|
||||||
|
/** 三阶段 */
|
||||||
|
private String threeStage;
|
||||||
|
/** 四阶段 */
|
||||||
|
private String fourStage;
|
||||||
|
|
||||||
|
}
|
|
@ -4,6 +4,7 @@ import aiyh.utils.annotation.recordset.ParamMapper;
|
||||||
import aiyh.utils.annotation.recordset.Select;
|
import aiyh.utils.annotation.recordset.Select;
|
||||||
import aiyh.utils.annotation.recordset.SqlMapper;
|
import aiyh.utils.annotation.recordset.SqlMapper;
|
||||||
import com.api.youhong.ai.pcn.racetrack.dto.RaceTrackEvent;
|
import com.api.youhong.ai.pcn.racetrack.dto.RaceTrackEvent;
|
||||||
|
import com.api.youhong.ai.pcn.racetrack.dto.RaceTrackStage;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
@ -47,4 +48,19 @@ public interface RacetrackMapper {
|
||||||
*/
|
*/
|
||||||
@Select("select companyworkyear from hrmresource where id = #{userId}")
|
@Select("select companyworkyear from hrmresource where id = #{userId}")
|
||||||
String selectLengthOfEntryTime(@ParamMapper("userId") Integer userId);
|
String selectLengthOfEntryTime(@ParamMapper("userId") Integer userId);
|
||||||
|
|
||||||
|
|
||||||
|
@Select("select id, $t{raceTrackStageOneField} one_stage," +
|
||||||
|
"$t{raceTrackStageTwoField} tow_stage," +
|
||||||
|
"$t{raceTrackStageThreeField} three_stage ," +
|
||||||
|
"$t{raceTrackStageFourField} four_stage " +
|
||||||
|
"from $t{raceTrackStageTable} " +
|
||||||
|
"where $t{raceTrackStageUserField} = #{userId}")
|
||||||
|
RaceTrackStage selectStageInfoByUserId(@ParamMapper("userId") int uid,
|
||||||
|
@ParamMapper("raceTrackStageTable") String raceTrackStageTable,
|
||||||
|
@ParamMapper("raceTrackStageUserField") String raceTrackStageUserField,
|
||||||
|
@ParamMapper("raceTrackStageOneField") String raceTrackStageOneField,
|
||||||
|
@ParamMapper("raceTrackStageTwoField") String raceTrackStageTwoField,
|
||||||
|
@ParamMapper("raceTrackStageThreeField") String raceTrackStageThreeField,
|
||||||
|
@ParamMapper("raceTrackStageFourField") String raceTrackStageFourField);
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,13 +1,18 @@
|
||||||
package com.api.youhong.ai.pcn.racetrack.service;
|
package com.api.youhong.ai.pcn.racetrack.service;
|
||||||
|
|
||||||
import aiyh.utils.Util;
|
import aiyh.utils.Util;
|
||||||
import cn.hutool.core.lang.Assert;
|
import aiyh.utils.tool.Assert;
|
||||||
import com.api.youhong.ai.pcn.racetrack.dto.RaceTrackEvent;
|
import com.api.youhong.ai.pcn.racetrack.dto.RaceTrackEvent;
|
||||||
|
import com.api.youhong.ai.pcn.racetrack.dto.RaceTrackStage;
|
||||||
import com.api.youhong.ai.pcn.racetrack.mapper.RacetrackMapper;
|
import com.api.youhong.ai.pcn.racetrack.mapper.RacetrackMapper;
|
||||||
|
import com.api.youhong.ai.pcn.racetrack.vo.RaceTrackStageVo;
|
||||||
import com.api.youhong.ai.pcn.racetrack.vo.RaceTrackVo;
|
import com.api.youhong.ai.pcn.racetrack.vo.RaceTrackVo;
|
||||||
|
import com.api.youhong.ai.pcn.racetrack.vo.StageInfoVo;
|
||||||
|
import com.google.common.base.Strings;
|
||||||
import ebu7common.youhong.ai.bean.Builder;
|
import ebu7common.youhong.ai.bean.Builder;
|
||||||
import weaver.hrm.User;
|
import weaver.hrm.User;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -54,6 +59,114 @@ public class RaceTrackService {
|
||||||
return Builder.builder(RaceTrackVo::new)
|
return Builder.builder(RaceTrackVo::new)
|
||||||
.with(RaceTrackVo::setEventList, raceTrackEventList)
|
.with(RaceTrackVo::setEventList, raceTrackEventList)
|
||||||
.with(RaceTrackVo::setLengthOfEntryTime, lengthOfEntryTime)
|
.with(RaceTrackVo::setLengthOfEntryTime, lengthOfEntryTime)
|
||||||
|
.with(RaceTrackVo::setUserStatus, user.getStatus())
|
||||||
.build();
|
.build();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* <h2>获取阶段信息列表</h2>
|
||||||
|
*
|
||||||
|
* @param user 当前用户
|
||||||
|
* @return 阶段信息列表
|
||||||
|
*/
|
||||||
|
public Object getStageInfo(User user) {
|
||||||
|
// 直到图数据表
|
||||||
|
String raceTrackStageTable = Util.getCusConfigValue("RACE_TRACK_STAGE_TABLE");
|
||||||
|
// 数据表用户字段
|
||||||
|
String raceTrackStageUserField = Util.getCusConfigValue("RACE_TRACK_STAGE_USER_FIELD");
|
||||||
|
// 一阶段列名
|
||||||
|
String raceTrackStageOneField = Util.getCusConfigValue("RACE_TRACK_STAGE_ONE_FIELD");
|
||||||
|
// 二阶段列名
|
||||||
|
String raceTrackStageTwoField = Util.getCusConfigValue("RACE_TRACK_STAGE_TWO_FIELD");
|
||||||
|
// 三阶段列名
|
||||||
|
String raceTrackStageThreeField = Util.getCusConfigValue("RACE_TRACK_STAGE_THREE_FIELD");
|
||||||
|
// 四阶段列名
|
||||||
|
String raceTrackStageFourField = Util.getCusConfigValue("RACE_TRACK_STAGE_Four_FIELD");
|
||||||
|
Assert.notBlank(raceTrackStageTable,
|
||||||
|
"race track stage info table can not be null! check configuration [RACE_TRACK_STAGE_TABLE] in uf_cus_dev_config table!");
|
||||||
|
Assert.notBlank(raceTrackStageUserField,
|
||||||
|
"race track stage info user field can not be null! check configuration [RACE_TRACK_STAGE_USER_FIELD] in uf_cus_dev_config table!");
|
||||||
|
Assert.notBlank(raceTrackStageOneField,
|
||||||
|
"race track stage info one stage filed can not be null! check configuration [RACE_TRACK_STAGE_ONE_FIELD] in uf_cus_dev_config table!");
|
||||||
|
Assert.notBlank(raceTrackStageTwoField,
|
||||||
|
"race track stage info tow stage field can not be null! check configuration [RACE_TRACK_STAGE_TWO_FIELD] in uf_cus_dev_config table!");
|
||||||
|
Assert.notBlank(raceTrackStageThreeField,
|
||||||
|
"race track stage info three stage field can not be null! check configuration [RACE_TRACK_STAGE_THREE_FIELD] in uf_cus_dev_config table!");
|
||||||
|
Assert.notBlank(raceTrackStageFourField,
|
||||||
|
"race track stage info four stage field can not be null! check configuration [RACE_TRACK_STAGE_Four_FIELD] in uf_cus_dev_config table!");
|
||||||
|
RaceTrackStage raceTrackStage = mapper.selectStageInfoByUserId(user.getUID(), raceTrackStageTable,
|
||||||
|
raceTrackStageUserField,
|
||||||
|
raceTrackStageOneField,
|
||||||
|
raceTrackStageTwoField,
|
||||||
|
raceTrackStageThreeField,
|
||||||
|
raceTrackStageFourField);
|
||||||
|
List<StageInfoVo> stageInfoVos = pushRaceTrackVo(raceTrackStage);
|
||||||
|
return Builder.builder(RaceTrackStageVo::new)
|
||||||
|
.with(RaceTrackStageVo::setStageVoList, stageInfoVos)
|
||||||
|
.with(RaceTrackStageVo::setStatus, user.getStatus())
|
||||||
|
.build();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* <h2>添加阶段信息</h2>
|
||||||
|
*
|
||||||
|
* @param raceTrackStage 阶段信息
|
||||||
|
* @return 阶段信息列表
|
||||||
|
*/
|
||||||
|
private List<StageInfoVo> pushRaceTrackVo(RaceTrackStage raceTrackStage) {
|
||||||
|
List<StageInfoVo> raceTrackVos = new ArrayList<>();
|
||||||
|
String oneStage = raceTrackStage.getOneStage();
|
||||||
|
String towStage = raceTrackStage.getTowStage();
|
||||||
|
String threeStage = raceTrackStage.getThreeStage();
|
||||||
|
String fourStage = raceTrackStage.getFourStage();
|
||||||
|
setRaceTrackValue(raceTrackVos, oneStage);
|
||||||
|
setRaceTrackValue(raceTrackVos, towStage);
|
||||||
|
setRaceTrackValue(raceTrackVos, threeStage);
|
||||||
|
setRaceTrackValue(raceTrackVos, fourStage);
|
||||||
|
for (int i = 0; i < raceTrackVos.size(); i++) {
|
||||||
|
StageInfoVo item = raceTrackVos.get(i);
|
||||||
|
if (i < raceTrackVos.size() - 1) {
|
||||||
|
if (item == null) {
|
||||||
|
raceTrackVos.set(i, Builder.builder(StageInfoVo::new)
|
||||||
|
.with(StageInfoVo::setFailedToArrive, true)
|
||||||
|
.build());
|
||||||
|
} else {
|
||||||
|
item.setActive(true);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if (item == null) {
|
||||||
|
item = Builder.builder(StageInfoVo::new)
|
||||||
|
.with(StageInfoVo::setFailedToArrive, true)
|
||||||
|
.build();
|
||||||
|
}
|
||||||
|
StageInfoVo nextItem = raceTrackVos.get(i + 1);
|
||||||
|
if (nextItem == null) {
|
||||||
|
item.setActive(true);
|
||||||
|
item.setFailedToArrive(false);
|
||||||
|
} else {
|
||||||
|
item.setPass(true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return raceTrackVos;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* <h2>阶段信息值设置</h2>
|
||||||
|
*
|
||||||
|
* @param raceTrackVos 阶段信息列表
|
||||||
|
* @param stage 阶段字段值
|
||||||
|
*/
|
||||||
|
private static void setRaceTrackValue(List<StageInfoVo> raceTrackVos, String stage) {
|
||||||
|
if (Strings.isNullOrEmpty(stage)) {
|
||||||
|
raceTrackVos.add(null);
|
||||||
|
} else {
|
||||||
|
raceTrackVos.add(
|
||||||
|
Builder.builder(StageInfoVo::new)
|
||||||
|
.with(StageInfoVo::setTime, stage)
|
||||||
|
.build()
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,25 @@
|
||||||
|
package com.api.youhong.ai.pcn.racetrack.vo;
|
||||||
|
|
||||||
|
import lombok.Getter;
|
||||||
|
import lombok.Setter;
|
||||||
|
import lombok.ToString;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* <h1>直道图阶段信息</h1>
|
||||||
|
*
|
||||||
|
* <p>create: 2023/2/17 11:06</p>
|
||||||
|
*
|
||||||
|
* @author youHong.ai
|
||||||
|
*/
|
||||||
|
@Getter
|
||||||
|
@Setter
|
||||||
|
@ToString
|
||||||
|
public class RaceTrackStageVo {
|
||||||
|
private int id;
|
||||||
|
|
||||||
|
private int status;
|
||||||
|
|
||||||
|
private List<StageInfoVo> stageVoList;
|
||||||
|
}
|
|
@ -24,4 +24,7 @@ public class RaceTrackVo {
|
||||||
|
|
||||||
/** 入职时长 */
|
/** 入职时长 */
|
||||||
private String lengthOfEntryTime;
|
private String lengthOfEntryTime;
|
||||||
|
|
||||||
|
|
||||||
|
private int userStatus;
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,26 @@
|
||||||
|
package com.api.youhong.ai.pcn.racetrack.vo;
|
||||||
|
|
||||||
|
import lombok.Getter;
|
||||||
|
import lombok.Setter;
|
||||||
|
import lombok.ToString;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* <h1>阶段信息</h1>
|
||||||
|
*
|
||||||
|
* <p>create: 2023/2/17 11:21</p>
|
||||||
|
*
|
||||||
|
* @author youHong.ai
|
||||||
|
*/
|
||||||
|
@Getter
|
||||||
|
@Setter
|
||||||
|
@ToString
|
||||||
|
public class StageInfoVo {
|
||||||
|
/** 时间 */
|
||||||
|
private String time;
|
||||||
|
/** 通过 */
|
||||||
|
private boolean pass;
|
||||||
|
/** 是否当前节点 */
|
||||||
|
private boolean active;
|
||||||
|
/** 未到达标识 */
|
||||||
|
private boolean failedToArrive;
|
||||||
|
}
|
|
@ -2,13 +2,11 @@ package weaver.youhong.ai.intellectualproperty.action;
|
||||||
|
|
||||||
import aiyh.utils.Util;
|
import aiyh.utils.Util;
|
||||||
import aiyh.utils.action.SafeCusBaseAction;
|
import aiyh.utils.action.SafeCusBaseAction;
|
||||||
import aiyh.utils.annotation.ActionDefaultTestValue;
|
import aiyh.utils.annotation.*;
|
||||||
import aiyh.utils.annotation.ActionOptionalParam;
|
|
||||||
import aiyh.utils.annotation.PrintParamMark;
|
|
||||||
import aiyh.utils.annotation.RequiredMark;
|
|
||||||
import aiyh.utils.excention.CustomerException;
|
import aiyh.utils.excention.CustomerException;
|
||||||
import aiyh.utils.httpUtil.ResponeVo;
|
import aiyh.utils.httpUtil.ResponeVo;
|
||||||
import aiyh.utils.httpUtil.util.HttpUtils;
|
import aiyh.utils.httpUtil.util.HttpUtils;
|
||||||
|
import com.google.common.base.Strings;
|
||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
import lombok.Setter;
|
import lombok.Setter;
|
||||||
import lombok.ToString;
|
import lombok.ToString;
|
||||||
|
@ -16,8 +14,13 @@ import weaver.hrm.User;
|
||||||
import weaver.soa.workflow.request.RequestInfo;
|
import weaver.soa.workflow.request.RequestInfo;
|
||||||
import weaver.xiao.commons.config.entity.RequestMappingConfig;
|
import weaver.xiao.commons.config.entity.RequestMappingConfig;
|
||||||
import weaver.xiao.commons.config.service.DealWithMapping;
|
import weaver.xiao.commons.config.service.DealWithMapping;
|
||||||
|
import weaver.youhong.ai.intellectualproperty.mapper.CaElectronicSignatureMapper;
|
||||||
|
|
||||||
import javax.ws.rs.core.MediaType;
|
import javax.ws.rs.core.MediaType;
|
||||||
|
import java.io.BufferedInputStream;
|
||||||
|
import java.io.ByteArrayInputStream;
|
||||||
|
import java.io.InputStream;
|
||||||
|
import java.util.Base64;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -30,7 +33,11 @@ import java.util.Map;
|
||||||
@Setter
|
@Setter
|
||||||
@Getter
|
@Getter
|
||||||
@ToString
|
@ToString
|
||||||
|
@ActionDesc(value = "电子签action", author = "youhong.ai")
|
||||||
public class CaElectronicSignatureAction extends SafeCusBaseAction {
|
public class CaElectronicSignatureAction extends SafeCusBaseAction {
|
||||||
|
|
||||||
|
public static final ThreadLocal<String> docName = new ThreadLocal<>();
|
||||||
|
public static final int SUCCESS_CODE = 200;
|
||||||
@PrintParamMark
|
@PrintParamMark
|
||||||
@ActionOptionalParam(value = "false", desc = "是否自动提交流程")
|
@ActionOptionalParam(value = "false", desc = "是否自动提交流程")
|
||||||
@ActionDefaultTestValue("false")
|
@ActionDefaultTestValue("false")
|
||||||
|
@ -46,10 +53,23 @@ public class CaElectronicSignatureAction extends SafeCusBaseAction {
|
||||||
@RequiredMark("请求接口参数配置表中的唯一标识字段的值")
|
@RequiredMark("请求接口参数配置表中的唯一标识字段的值")
|
||||||
private String onlyMark;
|
private String onlyMark;
|
||||||
|
|
||||||
|
|
||||||
|
@PrintParamMark
|
||||||
|
@ActionOptionalParam(value = "", desc = "签署后文件存储字段,只支持主表字段")
|
||||||
|
private String signFileField;
|
||||||
|
|
||||||
|
|
||||||
|
@PrintParamMark
|
||||||
|
@ActionOptionalParam(value = "", desc = "签署文件的文件唯一编号存储字段,只支持主表字段")
|
||||||
|
private String signFileNoField;
|
||||||
|
|
||||||
private final DealWithMapping dealWithMapping = new DealWithMapping();
|
private final DealWithMapping dealWithMapping = new DealWithMapping();
|
||||||
|
|
||||||
private final HttpUtils httpUtils = new HttpUtils();
|
private final HttpUtils httpUtils = new HttpUtils();
|
||||||
|
|
||||||
|
|
||||||
|
private final CaElectronicSignatureMapper mapper = Util.getMapper(CaElectronicSignatureMapper.class);
|
||||||
|
|
||||||
{
|
{
|
||||||
httpUtils.getGlobalCache().header.put("Content-Type", MediaType.APPLICATION_JSON);
|
httpUtils.getGlobalCache().header.put("Content-Type", MediaType.APPLICATION_JSON);
|
||||||
}
|
}
|
||||||
|
@ -63,7 +83,19 @@ public class CaElectronicSignatureAction extends SafeCusBaseAction {
|
||||||
String requestUrl = requestMappingConfig.getRequestUrl();
|
String requestUrl = requestMappingConfig.getRequestUrl();
|
||||||
Map<String, Object> requestParam = dealWithMapping.getRequestParam(super.getObjMainTableValue(requestInfo), requestMappingConfig);
|
Map<String, Object> requestParam = dealWithMapping.getRequestParam(super.getObjMainTableValue(requestInfo), requestMappingConfig);
|
||||||
ResponeVo responeVo = httpUtils.apiPost(requestUrl, requestParam);
|
ResponeVo responeVo = httpUtils.apiPost(requestUrl, requestParam);
|
||||||
|
if (responeVo.getCode() != SUCCESS_CODE) {
|
||||||
|
throw new CustomerException(responeVo.getCode() + ", fetch ca sign fail! ");
|
||||||
|
}
|
||||||
Map<String, Object> responseMap = responeVo.getResponseMap();
|
Map<String, Object> responseMap = responeVo.getResponseMap();
|
||||||
|
String documentNo = Util.null2String(responseMap.get("document_no"));
|
||||||
|
String pdf = Util.null2String(responseMap.get("pdf"));
|
||||||
|
InputStream inputStream = base64ContentToFile(pdf);
|
||||||
|
String docCategorys = Util.getDocCategorysByTable(String.valueOf(workflowId), signFileField, billTable);
|
||||||
|
String[] docCategoryArr = docCategorys.split(",");
|
||||||
|
int docCategory = Integer.parseInt(docCategoryArr[docCategoryArr.length - 1]);
|
||||||
|
int docId = Util.createDoc(Strings.isNullOrEmpty(docName.get()) ? "sign.pdf" : docName.get(), docCategory, inputStream, 1);
|
||||||
|
docName.remove();
|
||||||
|
writeBack(documentNo, billTable, requestId, docId);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
if (Boolean.parseBoolean(block)) {
|
if (Boolean.parseBoolean(block)) {
|
||||||
throw new CustomerException(e.getMessage(), e);
|
throw new CustomerException(e.getMessage(), e);
|
||||||
|
@ -75,7 +107,49 @@ public class CaElectronicSignatureAction extends SafeCusBaseAction {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* <h2>回写数据</h2>
|
||||||
|
*
|
||||||
|
* @param documentNo 文档编号
|
||||||
|
* @param billTable 表名
|
||||||
|
* @param requestId 请求ID
|
||||||
|
* @param docId 文档id
|
||||||
|
*/
|
||||||
|
public void writeBack(String documentNo, String billTable, String requestId, int docId) {
|
||||||
|
if (!mapper.updateDocumentAndNo(billTable, signFileNoField, documentNo, signFileField, docId, requestId)) {
|
||||||
|
try {
|
||||||
|
Thread.sleep(500);
|
||||||
|
} catch (Exception ignore) {
|
||||||
|
|
||||||
|
}
|
||||||
|
// 再次尝试
|
||||||
|
if (!mapper.updateDocumentAndNo(billTable, signFileNoField, documentNo, signFileField, docId, requestId)) {
|
||||||
|
throw new CustomerException("can not update sign file to workflow!");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* <h2>提交流程</h2>
|
||||||
|
*
|
||||||
|
* @param requestId 请求id
|
||||||
|
* @param userId 用户id
|
||||||
|
*/
|
||||||
public void submitWorkflow(String requestId, Integer userId) {
|
public void submitWorkflow(String requestId, Integer userId) {
|
||||||
Util.submitWorkflowThread(Integer.parseInt(requestId), userId, "电子签自动提交流程");
|
Util.submitWorkflowThread(Integer.parseInt(requestId), userId, "电子签自动提交流程");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 4. Base64字符串 转 文件(图片、pdf) -- 多用于测试
|
||||||
|
*
|
||||||
|
* @param base64Content Base64 字符串
|
||||||
|
*/
|
||||||
|
public InputStream base64ContentToFile(String base64Content) {
|
||||||
|
// Base64解码到字符数组
|
||||||
|
byte[] bytes = Base64.getDecoder().decode(base64Content);
|
||||||
|
ByteArrayInputStream byteInputStream = new ByteArrayInputStream(bytes);
|
||||||
|
return new BufferedInputStream(byteInputStream);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,41 @@
|
||||||
|
package weaver.youhong.ai.intellectualproperty.cusgetvalue;
|
||||||
|
|
||||||
|
import aiyh.utils.Util;
|
||||||
|
import aiyh.utils.entity.DocImageInfo;
|
||||||
|
import aiyh.utils.excention.CustomerException;
|
||||||
|
import org.apache.log4j.Logger;
|
||||||
|
import weaver.file.ImageFileManager;
|
||||||
|
import weaver.xiao.commons.config.interfacies.CusInterfaceGetValue;
|
||||||
|
import weaver.youhong.ai.intellectualproperty.action.CaElectronicSignatureAction;
|
||||||
|
|
||||||
|
import java.io.InputStream;
|
||||||
|
import java.util.Base64;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* <h1>自定义接口获取值</h1>
|
||||||
|
*
|
||||||
|
* <p>create: 2023/2/17 15:44</p>
|
||||||
|
*
|
||||||
|
* @author youHong.ai
|
||||||
|
*/
|
||||||
|
public class FileToBase64CusGetValue implements CusInterfaceGetValue {
|
||||||
|
private final Logger log = Util.getLogger();
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Object execute(Map<String, Object> mainMap, Map<String, Object> detailMap,
|
||||||
|
String currentValue, Map<String, String> pathParam) {
|
||||||
|
try {
|
||||||
|
DocImageInfo docImageInfo = Util.selectImageInfoByDocId(currentValue);
|
||||||
|
InputStream inputStream = ImageFileManager.getInputStreamById(docImageInfo.getImageFileId());
|
||||||
|
byte[] src = new byte[inputStream.available()];
|
||||||
|
inputStream.read(src);
|
||||||
|
String fileBase64 = Base64.getEncoder().encodeToString(src);
|
||||||
|
CaElectronicSignatureAction.docName.set(docImageInfo.getImageFileName());
|
||||||
|
return fileBase64;
|
||||||
|
} catch (Exception e) {
|
||||||
|
log.error("convert file to base64 fail!" + e.getMessage() + "\n" + Util.getErrString(e));
|
||||||
|
throw new CustomerException("convert file to base64 fail!");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,36 @@
|
||||||
|
package weaver.youhong.ai.intellectualproperty.mapper;
|
||||||
|
|
||||||
|
import aiyh.utils.annotation.recordset.ParamMapper;
|
||||||
|
import aiyh.utils.annotation.recordset.SqlMapper;
|
||||||
|
import aiyh.utils.annotation.recordset.Update;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* <h1></h1>
|
||||||
|
*
|
||||||
|
* <p>create: 2023/2/17 15:27</p>
|
||||||
|
*
|
||||||
|
* @author youHong.ai
|
||||||
|
*/
|
||||||
|
@SqlMapper
|
||||||
|
public interface CaElectronicSignatureMapper {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* <h2>更新回写文件信息</h2>
|
||||||
|
*
|
||||||
|
* @param billTable 表明
|
||||||
|
* @param documentNoField 文件编号存储字段
|
||||||
|
* @param documentNo 文档编号
|
||||||
|
* @param documentField 文档存储字段
|
||||||
|
* @param documentId 文档id
|
||||||
|
* @param requestId 请求id
|
||||||
|
* @return 是否更新成功
|
||||||
|
*/
|
||||||
|
@Update("update $t{billTable} set $t{documentNoField} = #{documentNo}, " +
|
||||||
|
" $t{documentField} = #{documentId} where requestId = #{requestId}")
|
||||||
|
boolean updateDocumentAndNo(@ParamMapper("billTable") String billTable,
|
||||||
|
@ParamMapper("documentNoField") String documentNoField,
|
||||||
|
@ParamMapper("documentNo") String documentNo,
|
||||||
|
@ParamMapper("documentField") String documentField,
|
||||||
|
@ParamMapper("documentId") int documentId,
|
||||||
|
@ParamMapper("requestId") String requestId);
|
||||||
|
}
|
|
@ -0,0 +1,106 @@
|
||||||
|
package weaver.youhong.ai.pcn.actioin.conditionssetvalue;
|
||||||
|
|
||||||
|
import aiyh.utils.Util;
|
||||||
|
import aiyh.utils.action.SafeCusBaseAction;
|
||||||
|
import aiyh.utils.annotation.*;
|
||||||
|
import aiyh.utils.excention.CustomerException;
|
||||||
|
import com.google.common.base.Strings;
|
||||||
|
import ebu7common.youhong.ai.bean.Builder;
|
||||||
|
import lombok.Getter;
|
||||||
|
import lombok.Setter;
|
||||||
|
import lombok.ToString;
|
||||||
|
import weaver.hrm.User;
|
||||||
|
import weaver.soa.workflow.request.RequestInfo;
|
||||||
|
import weaver.youhong.ai.pcn.actioin.conditionssetvalue.dto.UpdateDetailRowDto;
|
||||||
|
import weaver.youhong.ai.pcn.actioin.conditionssetvalue.service.WorkflowConditionsSetValueService;
|
||||||
|
|
||||||
|
import java.util.*;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* <h1>流程字段条件赋值action</h1>
|
||||||
|
*
|
||||||
|
* <p>create: 2023/2/19 13:27</p>
|
||||||
|
*
|
||||||
|
* @author youHong.ai
|
||||||
|
*/
|
||||||
|
@Setter
|
||||||
|
@Getter
|
||||||
|
@ToString
|
||||||
|
@ActionDesc(value = "流程字段根据不同条件赋值", author = "youhong.ai")
|
||||||
|
public class WorkflowConditionsSetValueAction extends SafeCusBaseAction {
|
||||||
|
|
||||||
|
@RequiredMark("流程条件赋值配置表唯一标识字段值")
|
||||||
|
@PrintParamMark
|
||||||
|
@ActionDefaultTestValue("test")
|
||||||
|
private String onlyMark;
|
||||||
|
|
||||||
|
@ActionOptionalParam(desc = "条件修改所在明细表,1-明细1,2-明细2", value = "")
|
||||||
|
@PrintParamMark
|
||||||
|
@ActionDefaultTestValue("1")
|
||||||
|
private String detailNo;
|
||||||
|
|
||||||
|
@PrintParamMark
|
||||||
|
@ActionOptionalParam(value = "false", desc = "是否自动提交流程")
|
||||||
|
private String submitAction = "false";
|
||||||
|
|
||||||
|
@PrintParamMark
|
||||||
|
@ActionOptionalParam(value = "true", desc = "是否失败后阻断流程")
|
||||||
|
private String block = "true";
|
||||||
|
|
||||||
|
private final WorkflowConditionsSetValueService service = new WorkflowConditionsSetValueService();
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void doSubmit(String requestId, String billTable, int workflowId, User user, RequestInfo requestInfo) {
|
||||||
|
try {
|
||||||
|
Map<String, Object> workflowData = new HashMap<>(16);
|
||||||
|
Map<String, Object> workflowMainData = super.getObjMainTableValue(requestInfo);
|
||||||
|
if (Strings.isNullOrEmpty(detailNo)) {
|
||||||
|
/* ******************* 数据修改主表 ******************* */
|
||||||
|
Map<String, Object> conditionsValue = service.getConditionsValue(onlyMark, workflowData).get(billTable);
|
||||||
|
service.updateWorkflowData(conditionsValue, billTable, requestId);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
/* ******************* 明细表 ******************* */
|
||||||
|
List<Map<String, Object>> detailData = super.getDetailTableObjValueByDetailNo(Integer.parseInt(detailNo), requestInfo);
|
||||||
|
workflowData.put("main", workflowMainData);
|
||||||
|
workflowData.put("_user_", user);
|
||||||
|
workflowData.put("_workflowId_", workflowId);
|
||||||
|
workflowData.put("_requestId_", requestId);
|
||||||
|
workflowData.put("_billTable_", billTable);
|
||||||
|
List<UpdateDetailRowDto> main = new ArrayList<>();
|
||||||
|
List<UpdateDetailRowDto> detail = new ArrayList<>();
|
||||||
|
for (Map<String, Object> detailDatum : detailData) {
|
||||||
|
workflowData.put("detail_" + detailNo, detailDatum);
|
||||||
|
Map<String, Map<String, Object>> conditionsValues = service.getConditionsValue(onlyMark, workflowData);
|
||||||
|
Map<String, Object> mainConditions = conditionsValues.get(billTable);
|
||||||
|
if (!Objects.isNull(mainConditions) && !mainConditions.isEmpty()) {
|
||||||
|
main.add(Builder.builder(UpdateDetailRowDto::new)
|
||||||
|
.with(UpdateDetailRowDto::setWhereValue, requestId)
|
||||||
|
.with(UpdateDetailRowDto::setWhereField, "requestid")
|
||||||
|
.with(UpdateDetailRowDto::setUpdateData, mainConditions)
|
||||||
|
.build());
|
||||||
|
}
|
||||||
|
Map<String, Object> detailCondition = conditionsValues.get(billTable + "_dt" + detailNo);
|
||||||
|
if (!Objects.isNull(detailCondition) && !detailCondition.isEmpty()) {
|
||||||
|
detail.add(Builder.builder(UpdateDetailRowDto::new)
|
||||||
|
.with(UpdateDetailRowDto::setWhereValue, detailDatum.get("id"))
|
||||||
|
.with(UpdateDetailRowDto::setWhereField, "id")
|
||||||
|
.with(UpdateDetailRowDto::setUpdateData, detailCondition)
|
||||||
|
.build());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
service.updateWorkflowDetailData(main, billTable, null);
|
||||||
|
service.updateWorkflowDetailData(detail, billTable + "_dt" + detailNo, detailNo);
|
||||||
|
} catch (Exception e) {
|
||||||
|
if (Boolean.parseBoolean(block)) {
|
||||||
|
throw new CustomerException(e.getMessage(), e);
|
||||||
|
}
|
||||||
|
} finally {
|
||||||
|
this.submitWorkflow(requestId, user.getUID());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void submitWorkflow(String requestId, Integer userId) {
|
||||||
|
Util.submitWorkflowThread(Integer.parseInt(requestId), userId, "邮件发送附件提交流程!");
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,26 @@
|
||||||
|
package weaver.youhong.ai.pcn.actioin.conditionssetvalue.dto;
|
||||||
|
|
||||||
|
import lombok.Getter;
|
||||||
|
import lombok.Setter;
|
||||||
|
import lombok.ToString;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* <h1>条件值dto</h1>
|
||||||
|
*
|
||||||
|
* <p>create: 2023/2/19 19:57</p>
|
||||||
|
*
|
||||||
|
* @author youHong.ai
|
||||||
|
*/
|
||||||
|
@Getter
|
||||||
|
@Setter
|
||||||
|
@ToString
|
||||||
|
public class ConditionValueDto {
|
||||||
|
/** 字段名称 */
|
||||||
|
private String fieldName;
|
||||||
|
|
||||||
|
/** 对应值 */
|
||||||
|
private Object value;
|
||||||
|
|
||||||
|
/** 表名称 */
|
||||||
|
private String tableName;
|
||||||
|
}
|
|
@ -0,0 +1,25 @@
|
||||||
|
package weaver.youhong.ai.pcn.actioin.conditionssetvalue.dto;
|
||||||
|
|
||||||
|
import lombok.Getter;
|
||||||
|
import lombok.Setter;
|
||||||
|
import lombok.ToString;
|
||||||
|
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* <h1>更新明细数据</h1>
|
||||||
|
*
|
||||||
|
* <p>create: 2023/2/20 13:46</p>
|
||||||
|
*
|
||||||
|
* @author youHong.ai
|
||||||
|
*/
|
||||||
|
@Getter
|
||||||
|
@Setter
|
||||||
|
@ToString
|
||||||
|
public class UpdateDetailRowDto {
|
||||||
|
private String whereField;
|
||||||
|
|
||||||
|
private Object whereValue;
|
||||||
|
|
||||||
|
private Map<String, Object> updateData;
|
||||||
|
}
|
|
@ -0,0 +1,40 @@
|
||||||
|
package weaver.youhong.ai.pcn.actioin.conditionssetvalue.entity;
|
||||||
|
|
||||||
|
import aiyh.utils.entity.FieldViewInfo;
|
||||||
|
import lombok.Getter;
|
||||||
|
import lombok.Setter;
|
||||||
|
import lombok.ToString;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* <h1>流程条件赋值配置明细行</h1>
|
||||||
|
*
|
||||||
|
* <p>create: 2023/2/19 16:19</p>
|
||||||
|
*
|
||||||
|
* @author youHong.ai
|
||||||
|
*/
|
||||||
|
@Setter
|
||||||
|
@Getter
|
||||||
|
@ToString
|
||||||
|
public class ConditionItem {
|
||||||
|
private Integer id;
|
||||||
|
|
||||||
|
/** 赋值字段 */
|
||||||
|
private FieldViewInfo targetField;
|
||||||
|
/** 条件取值字段 */
|
||||||
|
private FieldViewInfo conditionsField;
|
||||||
|
/** 条件 */
|
||||||
|
private Integer conditions;
|
||||||
|
/** 条件对比方式 */
|
||||||
|
private Integer conditionsType;
|
||||||
|
/** 条件对比字段 */
|
||||||
|
private FieldViewInfo conditionsContrastField;
|
||||||
|
/** 条件自定义值 */
|
||||||
|
private String customerConditionsValue;
|
||||||
|
/** 赋值规则 */
|
||||||
|
private Integer valueSetRules;
|
||||||
|
/** 自定义赋值 */
|
||||||
|
private String customerSetValue;
|
||||||
|
|
||||||
|
/** 取值字段 */
|
||||||
|
private FieldViewInfo valueField;
|
||||||
|
}
|
|
@ -0,0 +1,32 @@
|
||||||
|
package weaver.youhong.ai.pcn.actioin.conditionssetvalue.entity;
|
||||||
|
|
||||||
|
import lombok.Getter;
|
||||||
|
import lombok.Setter;
|
||||||
|
import lombok.ToString;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* <h1>流程条件赋值配置主表</h1>
|
||||||
|
*
|
||||||
|
* <p>create: 2023/2/19 13:43</p>
|
||||||
|
*
|
||||||
|
* @author youHong.ai
|
||||||
|
*/
|
||||||
|
@Setter
|
||||||
|
@Getter
|
||||||
|
@ToString
|
||||||
|
public class ConditionsSetValueConfigMain {
|
||||||
|
|
||||||
|
/** id */
|
||||||
|
private Integer id;
|
||||||
|
|
||||||
|
/** 唯一标识 */
|
||||||
|
private String onlyMark;
|
||||||
|
|
||||||
|
/** 流程类型 */
|
||||||
|
private Integer workflowType;
|
||||||
|
|
||||||
|
/** 明细配置表,条件配置 */
|
||||||
|
private List<ConditionItem> conditionItemList;
|
||||||
|
}
|
|
@ -0,0 +1,93 @@
|
||||||
|
package weaver.youhong.ai.pcn.actioin.conditionssetvalue.mapper;
|
||||||
|
|
||||||
|
import aiyh.utils.annotation.recordset.*;
|
||||||
|
import weaver.youhong.ai.pcn.actioin.conditionssetvalue.entity.ConditionItem;
|
||||||
|
import weaver.youhong.ai.pcn.actioin.conditionssetvalue.entity.ConditionsSetValueConfigMain;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* <h1>流程字段条件值赋值mapper</h1>
|
||||||
|
*
|
||||||
|
* <p>create: 2023/2/19 13:37</p>
|
||||||
|
*
|
||||||
|
* @author youHong.ai
|
||||||
|
*/
|
||||||
|
@SqlMapper
|
||||||
|
public interface WorkflowConditionsSetValueMapper {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* <h2>根据唯一标识查询条件赋值配置数据</h2>
|
||||||
|
*
|
||||||
|
* @param onlyMark 唯一标识
|
||||||
|
* @return 配置数据
|
||||||
|
*/
|
||||||
|
@Select("select * from uf_wf_conditi_assig where only_mark = #{onlyMark}")
|
||||||
|
@CollectionMappings({
|
||||||
|
@CollectionMapping(property = "conditionItemList",
|
||||||
|
column = "id",
|
||||||
|
id = @Id(value = Integer.class, methodId = 1))
|
||||||
|
})
|
||||||
|
ConditionsSetValueConfigMain selectConfigByOnlyMark(@ParamMapper("onlyMark") String onlyMark);
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* <h2>根据主表id查询明细表数据</h2>
|
||||||
|
*
|
||||||
|
* @param mainId 主表ID
|
||||||
|
* @return 明细数据
|
||||||
|
*/
|
||||||
|
@Select("select * from uf_wf_conditi_assig_dt1 where mainid = #{mainId}")
|
||||||
|
@Associations({
|
||||||
|
@Association(property = "targetField",
|
||||||
|
column = "target_field",
|
||||||
|
select = "aiyh.utils.mapper.UtilMapper.selectFieldInfo",
|
||||||
|
id = @Id(Integer.class)),
|
||||||
|
@Association(property = "conditionsField",
|
||||||
|
column = "conditions_field",
|
||||||
|
select = "aiyh.utils.mapper.UtilMapper.selectFieldInfo",
|
||||||
|
id = @Id(Integer.class)),
|
||||||
|
@Association(property = "conditionsContrastField",
|
||||||
|
column = "conditions_contrast_field",
|
||||||
|
select = "aiyh.utils.mapper.UtilMapper.selectFieldInfo",
|
||||||
|
id = @Id(Integer.class)),
|
||||||
|
@Association(property = "valueField",
|
||||||
|
column = "value_field",
|
||||||
|
select = "aiyh.utils.mapper.UtilMapper.selectFieldInfo",
|
||||||
|
id = @Id(Integer.class))
|
||||||
|
})
|
||||||
|
@CollectionMethod(1)
|
||||||
|
List<ConditionItem> selectConditionItemsByMainId(Integer mainId);
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* <h2>查询自定义sql</h2>
|
||||||
|
*
|
||||||
|
* @param sql 自定义sql
|
||||||
|
* @param workflowData 流程数据
|
||||||
|
* @return 查询结果
|
||||||
|
*/
|
||||||
|
@Select(custom = true)
|
||||||
|
String selectCustomerSql(@SqlString String sql, Map<String, Object> workflowData);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* <h2>更新流程表单数据</h2>
|
||||||
|
*
|
||||||
|
* @param sql 自定义sql
|
||||||
|
* @param conditionData 条件值
|
||||||
|
* @return 是否更新成功
|
||||||
|
*/
|
||||||
|
@Update(custom = true)
|
||||||
|
boolean updateWorkflowData(@SqlString String sql, Map<String, Object> conditionData);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* <h2>批量更新数据</h2>
|
||||||
|
*
|
||||||
|
* @param sql sql
|
||||||
|
* @param updateBatchData 批量参数
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
@BatchUpdate(custom = true)
|
||||||
|
boolean batchUpdateWorkflowData(@SqlString String sql, @BatchSqlArgs List<Map<String, Object>> updateBatchData);
|
||||||
|
}
|
|
@ -0,0 +1,150 @@
|
||||||
|
package weaver.youhong.ai.pcn.actioin.conditionssetvalue.service;
|
||||||
|
|
||||||
|
import aiyh.utils.Util;
|
||||||
|
import aiyh.utils.tool.Assert;
|
||||||
|
import weaver.youhong.ai.pcn.actioin.conditionssetvalue.dto.ConditionValueDto;
|
||||||
|
import weaver.youhong.ai.pcn.actioin.conditionssetvalue.dto.UpdateDetailRowDto;
|
||||||
|
import weaver.youhong.ai.pcn.actioin.conditionssetvalue.entity.ConditionItem;
|
||||||
|
import weaver.youhong.ai.pcn.actioin.conditionssetvalue.entity.ConditionsSetValueConfigMain;
|
||||||
|
import weaver.youhong.ai.pcn.actioin.conditionssetvalue.mapper.WorkflowConditionsSetValueMapper;
|
||||||
|
import weaver.youhong.ai.pcn.actioin.conditionssetvalue.util.ConditionsTreatment;
|
||||||
|
import weaver.youhong.ai.pcn.actioin.conditionssetvalue.util.ConditionsTypeTreatment;
|
||||||
|
import weaver.youhong.ai.pcn.actioin.conditionssetvalue.util.ValueSetRulesTreatment;
|
||||||
|
|
||||||
|
import java.util.*;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* <h1>流程字段值条件赋值service</h1>
|
||||||
|
*
|
||||||
|
* <p>create: 2023/2/19 13:37</p>
|
||||||
|
*
|
||||||
|
* @author youHong.ai
|
||||||
|
*/
|
||||||
|
public class WorkflowConditionsSetValueService {
|
||||||
|
private final WorkflowConditionsSetValueMapper mapper = Util.getMapper(WorkflowConditionsSetValueMapper.class);
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* <h2>获取条件赋值映射规则处理后的字段值</h2>
|
||||||
|
*
|
||||||
|
* @param onlyMark 配置表唯一标识
|
||||||
|
* @param workflowData 流程表数据
|
||||||
|
* @return 映射结果
|
||||||
|
*/
|
||||||
|
public Map<String, Map<String, Object>> getConditionsValue(String onlyMark, Map<String, Object> workflowData) {
|
||||||
|
|
||||||
|
/* ******************* 查询配置表 ******************* */
|
||||||
|
ConditionsSetValueConfigMain conditionsSetValueConfigMain = mapper.selectConfigByOnlyMark(onlyMark);
|
||||||
|
Assert.notNull(conditionsSetValueConfigMain, "can not query configuration by onlyMark [{}]", onlyMark);
|
||||||
|
List<ConditionItem> conditionItemList = conditionsSetValueConfigMain.getConditionItemList();
|
||||||
|
Assert.notEmpty(conditionItemList, "can not query conditionItemList by onlyMark [{}]", onlyMark);
|
||||||
|
/* ******************* 映射规则处理 ,责任链初始化 ******************* */
|
||||||
|
ConditionsTypeTreatment conditionsTypeTreatment = new ConditionsTypeTreatment(
|
||||||
|
new ConditionsTreatment(
|
||||||
|
new ValueSetRulesTreatment()
|
||||||
|
)
|
||||||
|
);
|
||||||
|
// 映射值处理
|
||||||
|
List<ConditionValueDto> valueDtoList = new ArrayList<>();
|
||||||
|
for (ConditionItem conditionItem : conditionItemList) {
|
||||||
|
ConditionValueDto conditionValueDto = conditionsTypeTreatment.conditionsTypeTreatment(conditionItem, workflowData);
|
||||||
|
if (!Objects.isNull(conditionValueDto)) {
|
||||||
|
valueDtoList.add(conditionValueDto);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Map<String, List<ConditionValueDto>> collect = valueDtoList.stream().collect(Collectors.groupingBy(ConditionValueDto::getTableName));
|
||||||
|
|
||||||
|
// 最终结果转为map
|
||||||
|
Map<String, Map<String, Object>> result = new HashMap<>(valueDtoList.size());
|
||||||
|
for (Map.Entry<String, List<ConditionValueDto>> entry : collect.entrySet()) {
|
||||||
|
Map<String, Object> map = new HashMap<>(valueDtoList.size());
|
||||||
|
for (ConditionValueDto item : entry.getValue()) {
|
||||||
|
map.put(item.getFieldName(), item.getValue());
|
||||||
|
}
|
||||||
|
result.put(entry.getKey(), map);
|
||||||
|
}
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* <h2>更新明细表数据</h2>
|
||||||
|
*
|
||||||
|
* @param updateDetailRowDtoList 更新数据
|
||||||
|
* @param billTable 表
|
||||||
|
* @param detailNo 明细号
|
||||||
|
*/
|
||||||
|
public void updateWorkflowDetailData(List<UpdateDetailRowDto> updateDetailRowDtoList, String billTable, String detailNo) {
|
||||||
|
if (updateDetailRowDtoList.isEmpty()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
UpdateDetailRowDto updateDetailRow = updateDetailRowDtoList.get(0);
|
||||||
|
if (Objects.isNull(detailNo)) {
|
||||||
|
// 主表
|
||||||
|
updateWorkflowData(updateDetailRow.getUpdateData(), billTable, Util.null2String(updateDetailRow.getWhereValue()));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
List<Map<String, Object>> updateBatchData = new ArrayList<>(updateDetailRowDtoList.size());
|
||||||
|
for (UpdateDetailRowDto updateDetailRowDto : updateDetailRowDtoList) {
|
||||||
|
Map<String, Object> updateData = updateDetailRowDto.getUpdateData();
|
||||||
|
updateData.put("_id_", updateDetailRow.getWhereValue());
|
||||||
|
updateBatchData.add(updateData);
|
||||||
|
}
|
||||||
|
StringBuilder sb = new StringBuilder("update ");
|
||||||
|
sb.append(billTable).append(" set ");
|
||||||
|
for (Map.Entry<String, Object> entry : updateBatchData.get(0).entrySet()) {
|
||||||
|
sb.append(entry.getKey())
|
||||||
|
.append(" = #{item.")
|
||||||
|
.append(entry.getKey())
|
||||||
|
.append("},");
|
||||||
|
}
|
||||||
|
sb.deleteCharAt(sb.length() - 1);
|
||||||
|
sb.append(" where ")
|
||||||
|
.append(updateDetailRow.getWhereField())
|
||||||
|
.append(" = #{item._id_}");
|
||||||
|
String sql = sb.toString();
|
||||||
|
boolean flag = mapper.batchUpdateWorkflowData(sql, updateBatchData);
|
||||||
|
if (!flag) {
|
||||||
|
try {
|
||||||
|
Thread.sleep(500);
|
||||||
|
} catch (InterruptedException ignore) {
|
||||||
|
}
|
||||||
|
mapper.batchUpdateWorkflowData(sql, updateBatchData);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* <h2>更新流程表单数据</h2>
|
||||||
|
*
|
||||||
|
* @param conditionData 条件值
|
||||||
|
* @param billTable 表单表名
|
||||||
|
* @param requestId 当前请求ID
|
||||||
|
*/
|
||||||
|
public void updateWorkflowData(Map<String, Object> conditionData, String billTable, String requestId) {
|
||||||
|
if (conditionData.isEmpty()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
StringBuilder sb = new StringBuilder("update ");
|
||||||
|
sb.append(billTable).append(" set ");
|
||||||
|
for (Map.Entry<String, Object> entry : conditionData.entrySet()) {
|
||||||
|
sb.append(entry.getKey())
|
||||||
|
.append(" = #{")
|
||||||
|
.append(entry.getKey())
|
||||||
|
.append("},");
|
||||||
|
}
|
||||||
|
sb.deleteCharAt(sb.length() - 1);
|
||||||
|
sb.append(" where requestid = ")
|
||||||
|
.append(requestId);
|
||||||
|
String sql = sb.toString();
|
||||||
|
boolean flag = mapper.updateWorkflowData(sql, conditionData);
|
||||||
|
if (!flag) {
|
||||||
|
try {
|
||||||
|
Thread.sleep(500);
|
||||||
|
} catch (InterruptedException ignore) {
|
||||||
|
}
|
||||||
|
mapper.updateWorkflowData(sql, conditionData);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,82 @@
|
||||||
|
package weaver.youhong.ai.pcn.actioin.conditionssetvalue.util;
|
||||||
|
|
||||||
|
import aiyh.utils.Util;
|
||||||
|
import aiyh.utils.annotation.MethodRuleNo;
|
||||||
|
import weaver.youhong.ai.pcn.actioin.conditionssetvalue.dto.ConditionValueDto;
|
||||||
|
import weaver.youhong.ai.pcn.actioin.conditionssetvalue.entity.ConditionItem;
|
||||||
|
|
||||||
|
import java.lang.reflect.InvocationTargetException;
|
||||||
|
import java.lang.reflect.Method;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.function.BiFunction;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* <h1>条件处理</h1>
|
||||||
|
*
|
||||||
|
* <p>create: 2023/2/19 17:41</p>
|
||||||
|
*
|
||||||
|
* @author youHong.ai
|
||||||
|
*/
|
||||||
|
public class ConditionsTreatment {
|
||||||
|
|
||||||
|
private final ValueSetRulesTreatment valueSetRulesTreatment;
|
||||||
|
|
||||||
|
private static final Map<Integer, BiFunction<String, String, Boolean>> METHOD_MAP = new HashMap<>();
|
||||||
|
|
||||||
|
/* ******************* 初始化策略方法 ******************* */ {
|
||||||
|
Class<ConditionsTreatment> valueRuleMethodClass = ConditionsTreatment.class;
|
||||||
|
Method[] methods = valueRuleMethodClass.getDeclaredMethods();
|
||||||
|
for (Method method : methods) {
|
||||||
|
if (method.isAnnotationPresent(MethodRuleNo.class)) {
|
||||||
|
MethodRuleNo annotation = method.getAnnotation(MethodRuleNo.class);
|
||||||
|
int value = annotation.value();
|
||||||
|
METHOD_MAP.put(value, (sourceValue, conditionValue) -> {
|
||||||
|
try {
|
||||||
|
return (Boolean) method.invoke(this, sourceValue, conditionValue);
|
||||||
|
} catch (IllegalAccessException | InvocationTargetException e) {
|
||||||
|
throw new RuntimeException(e);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public ConditionsTreatment(ValueSetRulesTreatment valueSetRulesTreatment) {
|
||||||
|
this.valueSetRulesTreatment = valueSetRulesTreatment;
|
||||||
|
}
|
||||||
|
|
||||||
|
public ConditionValueDto executeTreatment(ConditionItem conditionItem, Object value) {
|
||||||
|
Map<String, Object> workflowData = ConditionsTypeTreatment.WORKFLOW_DATA.get();
|
||||||
|
Object sourceValue = workflowData.get(conditionItem.getConditionsField().getFieldName());
|
||||||
|
Boolean apply = METHOD_MAP.get(conditionItem.getConditions()).apply(
|
||||||
|
Util.null2String(sourceValue),
|
||||||
|
Util.null2String(value)
|
||||||
|
);
|
||||||
|
if (apply) {
|
||||||
|
return this.valueSetRulesTreatment.createConditionValue(conditionItem);
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@MethodRuleNo(value = 0, desc = "不等于")
|
||||||
|
private boolean notEqual(String sourceValue, String value) {
|
||||||
|
return !sourceValue.equals(value);
|
||||||
|
}
|
||||||
|
|
||||||
|
@MethodRuleNo(value = 1, desc = "等于")
|
||||||
|
private boolean equalTo(String sourceValue, String value) {
|
||||||
|
return sourceValue.equals(value);
|
||||||
|
}
|
||||||
|
|
||||||
|
@MethodRuleNo(value = 2, desc = "大于")
|
||||||
|
private boolean greaterThan(String sourceValue, String value) {
|
||||||
|
return Double.parseDouble(sourceValue) > Double.parseDouble(value);
|
||||||
|
}
|
||||||
|
|
||||||
|
@MethodRuleNo(value = 3, desc = "小于")
|
||||||
|
private boolean lessThen(String sourceValue, String value) {
|
||||||
|
return Double.parseDouble(sourceValue) < Double.parseDouble(value);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,81 @@
|
||||||
|
package weaver.youhong.ai.pcn.actioin.conditionssetvalue.util;
|
||||||
|
|
||||||
|
import aiyh.utils.Util;
|
||||||
|
import aiyh.utils.annotation.MethodRuleNo;
|
||||||
|
import aiyh.utils.entity.FieldViewInfo;
|
||||||
|
import weaver.youhong.ai.pcn.actioin.conditionssetvalue.dto.ConditionValueDto;
|
||||||
|
import weaver.youhong.ai.pcn.actioin.conditionssetvalue.entity.ConditionItem;
|
||||||
|
import weaver.youhong.ai.pcn.actioin.conditionssetvalue.mapper.WorkflowConditionsSetValueMapper;
|
||||||
|
|
||||||
|
import java.lang.reflect.InvocationTargetException;
|
||||||
|
import java.lang.reflect.Method;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.function.BiFunction;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* <h1>条件对比方式</h1>
|
||||||
|
*
|
||||||
|
* <p>create: 2023/2/19 17:44</p>
|
||||||
|
*
|
||||||
|
* @author youHong.ai
|
||||||
|
*/
|
||||||
|
public class ConditionsTypeTreatment {
|
||||||
|
|
||||||
|
private final WorkflowConditionsSetValueMapper mapper = Util.getMapper(WorkflowConditionsSetValueMapper.class);
|
||||||
|
|
||||||
|
private final ConditionsTreatment conditionsTreatment;
|
||||||
|
|
||||||
|
public final static ThreadLocal<Map<String, Object>> WORKFLOW_DATA = new ThreadLocal<>();
|
||||||
|
|
||||||
|
private static final Map<Integer, BiFunction<ConditionItem, Map<String, Object>, Object>> METHOD_MAP = new HashMap<>();
|
||||||
|
|
||||||
|
public ConditionsTypeTreatment(ConditionsTreatment conditionsTreatment) {
|
||||||
|
this.conditionsTreatment = conditionsTreatment;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* ******************* 初始化策略方法 ******************* */ {
|
||||||
|
Class<ConditionsTypeTreatment> valueRuleMethodClass = ConditionsTypeTreatment.class;
|
||||||
|
Method[] methods = valueRuleMethodClass.getDeclaredMethods();
|
||||||
|
for (Method method : methods) {
|
||||||
|
if (method.isAnnotationPresent(MethodRuleNo.class)) {
|
||||||
|
MethodRuleNo annotation = method.getAnnotation(MethodRuleNo.class);
|
||||||
|
int value = annotation.value();
|
||||||
|
METHOD_MAP.put(value, (conditionItem, workflowData) -> {
|
||||||
|
try {
|
||||||
|
return method.invoke(this, conditionItem, workflowData);
|
||||||
|
} catch (IllegalAccessException | InvocationTargetException e) {
|
||||||
|
throw new RuntimeException(e);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public ConditionValueDto conditionsTypeTreatment(ConditionItem conditionItem, Map<String, Object> workflowData) {
|
||||||
|
WORKFLOW_DATA.set(workflowData);
|
||||||
|
Object conditionValue = METHOD_MAP.get(conditionItem.getConditionsType()).apply(conditionItem, workflowData);
|
||||||
|
ConditionValueDto conditionValueDto = this.conditionsTreatment.executeTreatment(conditionItem, conditionValue);
|
||||||
|
WORKFLOW_DATA.remove();
|
||||||
|
return conditionValueDto;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@MethodRuleNo(value = 0, desc = "流程字段")
|
||||||
|
private Object workflowField(ConditionItem conditionItem, Map<String, Object> workflowData) {
|
||||||
|
FieldViewInfo fieldInfo = conditionItem.getConditionsContrastField();
|
||||||
|
return Util.getValueByFieldViwInfo(fieldInfo, workflowData);
|
||||||
|
}
|
||||||
|
|
||||||
|
@MethodRuleNo(value = 1, desc = "固定值")
|
||||||
|
private Object fixValue(ConditionItem conditionItem, Map<String, Object> workflowData) {
|
||||||
|
return conditionItem.getCustomerConditionsValue();
|
||||||
|
}
|
||||||
|
|
||||||
|
@MethodRuleNo(value = 2, desc = "自定义sql")
|
||||||
|
private Object customerSql(ConditionItem conditionItem, Map<String, Object> workflowData) {
|
||||||
|
return mapper.selectCustomerSql(conditionItem.getCustomerConditionsValue(), workflowData);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,76 @@
|
||||||
|
package weaver.youhong.ai.pcn.actioin.conditionssetvalue.util;
|
||||||
|
|
||||||
|
import aiyh.utils.Util;
|
||||||
|
import aiyh.utils.annotation.MethodRuleNo;
|
||||||
|
import aiyh.utils.entity.FieldViewInfo;
|
||||||
|
import ebu7common.youhong.ai.bean.Builder;
|
||||||
|
import weaver.youhong.ai.pcn.actioin.conditionssetvalue.dto.ConditionValueDto;
|
||||||
|
import weaver.youhong.ai.pcn.actioin.conditionssetvalue.entity.ConditionItem;
|
||||||
|
import weaver.youhong.ai.pcn.actioin.conditionssetvalue.mapper.WorkflowConditionsSetValueMapper;
|
||||||
|
|
||||||
|
import java.lang.reflect.InvocationTargetException;
|
||||||
|
import java.lang.reflect.Method;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.function.BiFunction;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* <h1>赋值规则处理</h1>
|
||||||
|
*
|
||||||
|
* <p>create: 2023/2/19 17:46</p>
|
||||||
|
*
|
||||||
|
* @author youHong.ai
|
||||||
|
*/
|
||||||
|
public class ValueSetRulesTreatment {
|
||||||
|
|
||||||
|
private static final Map<Integer, BiFunction<ConditionItem, Map<String, Object>, Object>> METHOD_MAP = new HashMap<>();
|
||||||
|
|
||||||
|
private final WorkflowConditionsSetValueMapper mapper = Util.getMapper(WorkflowConditionsSetValueMapper.class);
|
||||||
|
|
||||||
|
/* ******************* 初始化策略方法 ******************* */ {
|
||||||
|
Class<ValueSetRulesTreatment> valueRuleMethodClass = ValueSetRulesTreatment.class;
|
||||||
|
Method[] methods = valueRuleMethodClass.getDeclaredMethods();
|
||||||
|
for (Method method : methods) {
|
||||||
|
if (method.isAnnotationPresent(MethodRuleNo.class)) {
|
||||||
|
MethodRuleNo annotation = method.getAnnotation(MethodRuleNo.class);
|
||||||
|
int value = annotation.value();
|
||||||
|
METHOD_MAP.put(value, (conditionItem, workflowData) -> {
|
||||||
|
try {
|
||||||
|
return method.invoke(this, conditionItem, workflowData);
|
||||||
|
} catch (IllegalAccessException | InvocationTargetException e) {
|
||||||
|
throw new RuntimeException(e);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public ConditionValueDto createConditionValue(ConditionItem conditionItem) {
|
||||||
|
Map<String, Object> workflowData = ConditionsTypeTreatment.WORKFLOW_DATA.get();
|
||||||
|
Object value = METHOD_MAP.get(conditionItem.getValueSetRules()).apply(conditionItem, workflowData);
|
||||||
|
return Builder.builder(ConditionValueDto::new)
|
||||||
|
.with(ConditionValueDto::setFieldName, conditionItem.getTargetField().getFieldName())
|
||||||
|
.with(ConditionValueDto::setValue, value)
|
||||||
|
.build();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@MethodRuleNo(value = 0, desc = "固定值")
|
||||||
|
private Object fixValue(ConditionItem conditionItem, Map<String, Object> workflowData) {
|
||||||
|
return conditionItem.getCustomerSetValue();
|
||||||
|
}
|
||||||
|
|
||||||
|
@MethodRuleNo(value = 1, desc = "流程字段")
|
||||||
|
private Object workflowField(ConditionItem conditionItem, Map<String, Object> workflowData) {
|
||||||
|
FieldViewInfo fieldInfo = conditionItem.getValueField();
|
||||||
|
return Util.getValueByFieldViwInfo(fieldInfo, workflowData);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@MethodRuleNo(value = 2, desc = "自定义sql")
|
||||||
|
private Object customerSql(ConditionItem conditionItem, Map<String, Object> workflowData) {
|
||||||
|
return mapper.selectCustomerSql(conditionItem.getCustomerSetValue(), workflowData);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,22 @@
|
||||||
|
package youhong.ai.intellectualproperty;
|
||||||
|
|
||||||
|
import aiyh.utils.GenerateFileUtil;
|
||||||
|
import basetest.BaseTest;
|
||||||
|
import org.junit.Test;
|
||||||
|
import weaver.youhong.ai.intellectualproperty.action.CaElectronicSignatureAction;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* <h1>测试</h1>
|
||||||
|
*
|
||||||
|
* <p>create: 2023/2/18 14:32</p>
|
||||||
|
*
|
||||||
|
* @author youHong.ai
|
||||||
|
*/
|
||||||
|
public class TestAction extends BaseTest {
|
||||||
|
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void test() {
|
||||||
|
GenerateFileUtil.createActionDocument(CaElectronicSignatureAction.class);
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,26 @@
|
||||||
|
package youhong.ai.pcn;
|
||||||
|
|
||||||
|
import aiyh.utils.Util;
|
||||||
|
import basetest.BaseTest;
|
||||||
|
import com.alibaba.fastjson.JSON;
|
||||||
|
import org.junit.Test;
|
||||||
|
import weaver.youhong.ai.pcn.actioin.conditionssetvalue.entity.ConditionsSetValueConfigMain;
|
||||||
|
import weaver.youhong.ai.pcn.actioin.conditionssetvalue.mapper.WorkflowConditionsSetValueMapper;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* <h1>查询测试</h1>
|
||||||
|
*
|
||||||
|
* <p>create: 2023/2/19 16:33</p>
|
||||||
|
*
|
||||||
|
* @author youHong.ai
|
||||||
|
*/
|
||||||
|
public class MapperTest extends BaseTest {
|
||||||
|
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void test() {
|
||||||
|
WorkflowConditionsSetValueMapper mapper = Util.getMapper(WorkflowConditionsSetValueMapper.class);
|
||||||
|
ConditionsSetValueConfigMain conditionsSetValueConfigMain = mapper.selectConfigByOnlyMark("test");
|
||||||
|
System.out.println(JSON.toJSONString(conditionsSetValueConfigMain));
|
||||||
|
}
|
||||||
|
}
|
|
@ -7,6 +7,7 @@ import com.engine.common.util.ServiceUtil;
|
||||||
import com.engine.hrm.service.impl.RolesMembersServiceImpl;
|
import com.engine.hrm.service.impl.RolesMembersServiceImpl;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import weaver.hrm.User;
|
import weaver.hrm.User;
|
||||||
|
import weaver.youhong.ai.pcn.actioin.conditionssetvalue.WorkflowConditionsSetValueAction;
|
||||||
import weaver.youhong.ai.pcn.schedule.addrolebyhasundering.RegisterRoleMemberByHasUnderingCronJob;
|
import weaver.youhong.ai.pcn.schedule.addrolebyhasundering.RegisterRoleMemberByHasUnderingCronJob;
|
||||||
import weaver.youhong.ai.pcn.schedule.addrolemember.RegisterRoleMemberCronJob;
|
import weaver.youhong.ai.pcn.schedule.addrolemember.RegisterRoleMemberCronJob;
|
||||||
|
|
||||||
|
@ -58,4 +59,22 @@ public class RolesTest extends BaseTest {
|
||||||
GenerateFileUtil.createCronJobDocument(RegisterRoleMemberByHasUnderingCronJob.class);
|
GenerateFileUtil.createCronJobDocument(RegisterRoleMemberByHasUnderingCronJob.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void test3() {
|
||||||
|
String value = "1";
|
||||||
|
System.out.println(Double.parseDouble(value));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testWorkflowConditionSetValue() {
|
||||||
|
Util.actionTest(WorkflowConditionsSetValueAction.class, 86088);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void generateFile() {
|
||||||
|
GenerateFileUtil.createActionDocument(WorkflowConditionsSetValueAction.class);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -19,7 +19,7 @@ import lombok.ToString;
|
||||||
public class Student {
|
public class Student {
|
||||||
private int id;
|
private int id;
|
||||||
|
|
||||||
@SqlDbFieldAnn("a")
|
@SqlDbFieldAnn("WOLFLOWTYPE")
|
||||||
private String name;
|
private String name;
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue