diff --git a/src/main/java/weaver/bokang/xiao/common/mapper/WorkflowMapper.java b/src/main/java/weaver/bokang/xiao/common/mapper/WorkflowMapper.java new file mode 100644 index 0000000..f151550 --- /dev/null +++ b/src/main/java/weaver/bokang/xiao/common/mapper/WorkflowMapper.java @@ -0,0 +1,41 @@ +package weaver.bokang.xiao.common.mapper; + +import aiyh.utils.annotation.recordset.ParamMapper; +import aiyh.utils.annotation.recordset.Select; +import aiyh.utils.annotation.recordset.SqlMapper; +import aiyh.utils.annotation.recordset.Update; + +import java.util.Map; + +/** + * @ClassName WorkflowMapper + * @Author 肖博亢 + * @Date 2023/2/3 9:57 + * @Description

流程数据操作

+ **/ +@SqlMapper +public interface WorkflowMapper { + + /** + *

通过requestId查询流程数据

+ * @param requestId requestId + * @param tableName 流程表名 + * @return 流程数据 + */ + @Select("select * from $t{tableName} where requestid = #{requestId}") + Map queryWorkflowByRequestId(@ParamMapper("requestId") String requestId,@ParamMapper("tableName") String tableName); + + /** + *

根据requestId更新流程字段信息

+ * @param tableName 流程表名 + * @param fieldName 字段名 + * @param fieldValue 字段值 + * @param requestId requestId + * @return 更新结果 + */ + @Update("update $t{tableName} set $t{fieldName} = #{fieldValue} where requestid = #{requestId}") + boolean updateWorkflowMsgByRequestId(@ParamMapper("tableName") String tableName, + @ParamMapper("fieldName") String fieldName, + @ParamMapper("fieldValue") String fieldValue, + @ParamMapper("requestId") String requestId); +} diff --git a/src/main/java/weaver/bokang/xiao/kljd_code_generate/action/CodeGenerateAction.java b/src/main/java/weaver/bokang/xiao/kljd_code_generate/action/CodeGenerateAction.java new file mode 100644 index 0000000..e991640 --- /dev/null +++ b/src/main/java/weaver/bokang/xiao/kljd_code_generate/action/CodeGenerateAction.java @@ -0,0 +1,52 @@ +package weaver.bokang.xiao.kljd_code_generate.action; + +import aiyh.utils.Util; +import aiyh.utils.action.SafeCusBaseAction; +import aiyh.utils.annotation.ActionDefaultTestValue; +import aiyh.utils.annotation.ActionDesc; +import aiyh.utils.annotation.PrintParamMark; +import aiyh.utils.annotation.RequiredMark; +import lombok.Setter; +import weaver.bokang.xiao.common.mapper.WorkflowMapper; +import weaver.bokang.xiao.kljd_code_generate.util.CodeGenerateUtil; +import weaver.hrm.User; +import weaver.soa.workflow.request.RequestInfo; + + +import java.util.Map; + +/** + * @ClassName CodeGenerateAction + * @Author 肖博亢 + * @Date 2023/2/6 13:18 + * @Description

流程编号生成

+ **/ + +@ActionDesc(value = "流程编号生成",author = "bokang.xiao") +@Setter +public class CodeGenerateAction extends SafeCusBaseAction { + + private final WorkflowMapper workflowMapper = Util.getMapper(WorkflowMapper.class); + private final CodeGenerateUtil codeGenerateUtil = new CodeGenerateUtil(); + + @RequiredMark("流程编码字段名") + @PrintParamMark + @ActionDefaultTestValue("cs3") + private String codeField; + + @Override + public void doSubmit(String requestId, String billTable, int workflowId, User user, RequestInfo requestInfo) { + log.info(String.format("=================== {%s} begin ======================", this.getClass().getName())); + log.info(String.format("params:[requestId ==>%s],[codeField ==>%s]", requestId,codeField)); + Map workflowMessage = workflowMapper.queryWorkflowByRequestId(requestId, billTable); + String sourceCode = Util.null2String(workflowMessage.get(codeField)); + if(!"".equals(sourceCode)) { + log.error("已经编码过了,无需编码"); + return; + } + + String workflowCode = codeGenerateUtil.codeBuildByWorkflow(String.valueOf(workflowId), requestId, workflowMessage); + workflowMapper.updateWorkflowMsgByRequestId(billTable,codeField,workflowCode,requestId); + } + +} diff --git a/src/main/java/weaver/bokang/xiao/kljd_code_generate/entity/CodeBuildEntity.java b/src/main/java/weaver/bokang/xiao/kljd_code_generate/entity/CodeBuildEntity.java new file mode 100644 index 0000000..88de67c --- /dev/null +++ b/src/main/java/weaver/bokang/xiao/kljd_code_generate/entity/CodeBuildEntity.java @@ -0,0 +1,20 @@ +package weaver.bokang.xiao.kljd_code_generate.entity; + +import lombok.Data; + +/** + * @ClassName CodeBuildEntity + * @Author 肖博亢 + * @Date 2023/2/6 13:24 + * @Description

编号组成配置实体类

+ **/ +@Data +public class CodeBuildEntity { + + private Integer fieldType; + private String workflowField; + private String workflowFieldName; + private Integer changeRule; + private String cusText; + private Integer isAlone; +} diff --git a/src/main/java/weaver/bokang/xiao/kljd_code_generate/entity/CodeConditionEntity.java b/src/main/java/weaver/bokang/xiao/kljd_code_generate/entity/CodeConditionEntity.java new file mode 100644 index 0000000..66d81f2 --- /dev/null +++ b/src/main/java/weaver/bokang/xiao/kljd_code_generate/entity/CodeConditionEntity.java @@ -0,0 +1,17 @@ +package weaver.bokang.xiao.kljd_code_generate.entity; + +import lombok.Data; + +/** + * @ClassName CodeConditionEntity + * @Author 肖博亢 + * @Date 2023/2/6 13:22 + * @Description

编号生成条件实体类

+ **/ +@Data +public class CodeConditionEntity { + private String fieldId; + private Integer compare; + private String value; + private String fieldName; +} diff --git a/src/main/java/weaver/bokang/xiao/kljd_code_generate/entity/CodeRuleConfig.java b/src/main/java/weaver/bokang/xiao/kljd_code_generate/entity/CodeRuleConfig.java new file mode 100644 index 0000000..fb4455a --- /dev/null +++ b/src/main/java/weaver/bokang/xiao/kljd_code_generate/entity/CodeRuleConfig.java @@ -0,0 +1,27 @@ +package weaver.bokang.xiao.kljd_code_generate.entity; + +import lombok.Data; + +import java.util.List; + +/** + * @ClassName CodeRuleConfig + * @Author 肖博亢 + * @Date 2023/2/6 13:20 + * @Description

编号生成规则配置实体类

+ **/ + +@Data +public class CodeRuleConfig { + + private Integer id; + private String workflowType; + private String description; + private String uniqueCode; + private Integer flowType; + private Integer flowNumber; + private Integer startNumber; + private List codeBuildEntityList; + private List codeConditionEntityList; + private List reserveNumberList; +} diff --git a/src/main/java/weaver/bokang/xiao/kljd_code_generate/entity/FlowEntity.java b/src/main/java/weaver/bokang/xiao/kljd_code_generate/entity/FlowEntity.java new file mode 100644 index 0000000..5484daf --- /dev/null +++ b/src/main/java/weaver/bokang/xiao/kljd_code_generate/entity/FlowEntity.java @@ -0,0 +1,19 @@ +package weaver.bokang.xiao.kljd_code_generate.entity; + +import lombok.Data; + +/** + * @ClassName FlowEntity + * @Author 肖博亢 + * @Date 2023/2/7 10:17 + * @Description

流水实体类

+ **/ +@Data +public class FlowEntity { + + private Integer id; + private Integer flowNumber; + private String workflowType; + private Integer codeRule; + private String flowKey; +} diff --git a/src/main/java/weaver/bokang/xiao/kljd_code_generate/enum_type/ChangeRuleEnum.java b/src/main/java/weaver/bokang/xiao/kljd_code_generate/enum_type/ChangeRuleEnum.java new file mode 100644 index 0000000..7ab214b --- /dev/null +++ b/src/main/java/weaver/bokang/xiao/kljd_code_generate/enum_type/ChangeRuleEnum.java @@ -0,0 +1,42 @@ +package weaver.bokang.xiao.kljd_code_generate.enum_type; + +import java.util.EnumSet; +import java.util.HashMap; +import java.util.Map; + +/** + * @ClassName ChangeRuleEnum + * @Author 肖博亢 + * @Date 2023/2/6 15:28 + * @Description

+ **/ +public enum ChangeRuleEnum { + + /** 字段值 */ + FIELD_VALUE(0), + /** 固定值 */ + DEFAULT_VALUE(1), + /** sql转换 */ + CUS_SQL(2), + /** 浏览按钮显示值 */ + BROWSE_VALUE(3), + /** 下拉框显示值 */ + SELECT_VALUE(4); + + private static final Map LOOK_UP = new HashMap<>(8); + + static { + for (ChangeRuleEnum changeRuleEnum : EnumSet.allOf(ChangeRuleEnum.class)){ + LOOK_UP.put(changeRuleEnum.value,changeRuleEnum); + } + } + public final Integer value; + + ChangeRuleEnum(int value){ + this.value = value; + } + + public static ChangeRuleEnum getEnum(int value){ + return LOOK_UP.get(value); + } +} diff --git a/src/main/java/weaver/bokang/xiao/kljd_code_generate/enum_type/CompareEnum.java b/src/main/java/weaver/bokang/xiao/kljd_code_generate/enum_type/CompareEnum.java new file mode 100644 index 0000000..b62a96b --- /dev/null +++ b/src/main/java/weaver/bokang/xiao/kljd_code_generate/enum_type/CompareEnum.java @@ -0,0 +1,41 @@ +package weaver.bokang.xiao.kljd_code_generate.enum_type; + + +import java.util.EnumSet; +import java.util.HashMap; +import java.util.Map; + +/** + * @ClassName CompareEnum + * @Author 肖博亢 + * @Date 2023/2/6 15:05 + * @Description

比较类型枚举

+ **/ +public enum CompareEnum { + + /** 大于 */ + MORE_THAN(0), + /** 小于 */ + LESS_THAN(1), + /** 等于 */ + EQUAL(2), + /** 不等于 */ + NO_EQUAL(3); + + private static final Map LOOK_UP = new HashMap<>(8); + + static { + for (CompareEnum compareEnum : EnumSet.allOf(CompareEnum.class)){ + LOOK_UP.put(compareEnum.value,compareEnum); + } + } + public final Integer value; + + CompareEnum(int value){ + this.value = value; + } + + public static CompareEnum getEnum(int value){ + return LOOK_UP.get(value); + } +} diff --git a/src/main/java/weaver/bokang/xiao/kljd_code_generate/enum_type/FieldTypeEnum.java b/src/main/java/weaver/bokang/xiao/kljd_code_generate/enum_type/FieldTypeEnum.java new file mode 100644 index 0000000..ea57a47 --- /dev/null +++ b/src/main/java/weaver/bokang/xiao/kljd_code_generate/enum_type/FieldTypeEnum.java @@ -0,0 +1,42 @@ +package weaver.bokang.xiao.kljd_code_generate.enum_type; + +import java.util.EnumSet; +import java.util.HashMap; +import java.util.Map; + +/** + * @ClassName FieldTypeEnum + * @Author 肖博亢 + * @Date 2023/2/6 16:03 + * @Description

+ **/ +public enum FieldTypeEnum { + + /** 流程字段 */ + WORKFLOW_FIELD(0), + /** 字符串 */ + STRING(1), + /** 浏览按钮 */ + BROWSE(2), + /** 下拉框 */ + SELECT(3), + /** 流水号 */ + FLOW_NUMBER(4); + + private static final Map LOOK_UP = new HashMap<>(8); + + static { + for (FieldTypeEnum fieldTypeEnum : EnumSet.allOf(FieldTypeEnum.class)){ + LOOK_UP.put(fieldTypeEnum.value,fieldTypeEnum); + } + } + public final Integer value; + + FieldTypeEnum(int value){ + this.value = value; + } + + public static FieldTypeEnum getEnum(int value){ + return LOOK_UP.get(value); + } +} diff --git a/src/main/java/weaver/bokang/xiao/kljd_code_generate/mapper/CodeRuleMapper.java b/src/main/java/weaver/bokang/xiao/kljd_code_generate/mapper/CodeRuleMapper.java new file mode 100644 index 0000000..743b830 --- /dev/null +++ b/src/main/java/weaver/bokang/xiao/kljd_code_generate/mapper/CodeRuleMapper.java @@ -0,0 +1,54 @@ +package weaver.bokang.xiao.kljd_code_generate.mapper; + +import aiyh.utils.annotation.recordset.ParamMapper; +import aiyh.utils.annotation.recordset.Select; +import aiyh.utils.annotation.recordset.SqlMapper; +import weaver.bokang.xiao.kljd_code_generate.entity.CodeBuildEntity; +import weaver.bokang.xiao.kljd_code_generate.entity.CodeConditionEntity; +import weaver.bokang.xiao.kljd_code_generate.entity.CodeRuleConfig; + +import java.util.List; + +/** + * @ClassName CodeRuleMapper + * @Author 肖博亢 + * @Date 2023/2/6 13:19 + * @Description

+ **/ + +@SqlMapper +public interface CodeRuleMapper { + + /** + *

通过流程id查询流程编号生成规则配置

+ * @param workflowId 流程id + * @return 配置列表 + */ + @Select("select * from uf_code_build_rule where workflow_type = #{workflowId}") + List queryCodeRuleConfig(@ParamMapper("workflowId") String workflowId); + + /** + *

通过mainId查询编号生成条件配置

+ * @param mainId 主表id + * @return 配置列表 + */ + @Select("select * from uf_code_build_rule_dt1 where mainid = #{mainId}") + List queryConditionByMainId(@ParamMapper("mainId") int mainId); + + /** + *

通过mainId查询编号组成配置

+ * @param mainId 主表id + * @return 配置列表 + */ + @Select("select * from uf_code_build_rule_dt2 where mainid = #{mainId}") + List queryBuildByMainId(@ParamMapper("mainId") int mainId); + + /** + *

通过mainId查询预留编号

+ * @param mainId 主表id + * @return 预留编号列表 + */ + @Select("select * from uf_code_build_rule_dt3 where mainid = #{mainId}") + List queryReserveNumberByMainId(@ParamMapper("mainId") int mainId); + +} diff --git a/src/main/java/weaver/bokang/xiao/kljd_code_generate/mapper/FlowMapper.java b/src/main/java/weaver/bokang/xiao/kljd_code_generate/mapper/FlowMapper.java new file mode 100644 index 0000000..230d2fd --- /dev/null +++ b/src/main/java/weaver/bokang/xiao/kljd_code_generate/mapper/FlowMapper.java @@ -0,0 +1,41 @@ +package weaver.bokang.xiao.kljd_code_generate.mapper; + +import aiyh.utils.annotation.recordset.*; +import weaver.bokang.xiao.kljd_code_generate.entity.FlowEntity; + + +/** + * @ClassName FlowMapper + * @Author 肖博亢 + * @Date 2023/2/7 11:07 + * @Description

流水操作类

+ **/ +@SqlMapper +public interface FlowMapper { + + /** + *

获取最大单独流水号

+ * @param codeRule 流水规则 + * @param flowKey 单独流水主键 + * @return 流水号 + */ + @Select("select max(flow_number) from uf_flow_info where code_rule = #{codeRule} and flow_key = #{flowKey}") + int getFlowByParam(@ParamMapper("codeRule") int codeRule,@ParamMapper("flowKey") String flowKey); + + /** + *

获取流水号

+ * @param codeRule 流水规则 + * @return 流水号 + */ + @Select("select max(flow_number) from uf_flow_info where code_rule = #{codeRule}") + int getFlowByParam(@ParamMapper("codeRule") int codeRule); + + /** + *

插入流水号数据

+ * @param flowEntity 流水实体类 + * @return 插入结果 + */ + @Update("update uf_flow_info set flow_number = #{flowNumber},workflow_type = #{workflowType},code_rule = #{codeRule},flow_key = #{flowKey} where id = #{id}") + boolean updateFlow(FlowEntity flowEntity); + +} diff --git a/src/main/java/weaver/bokang/xiao/kljd_code_generate/util/CodeGenerateUtil.java b/src/main/java/weaver/bokang/xiao/kljd_code_generate/util/CodeGenerateUtil.java new file mode 100644 index 0000000..3fe7956 --- /dev/null +++ b/src/main/java/weaver/bokang/xiao/kljd_code_generate/util/CodeGenerateUtil.java @@ -0,0 +1,238 @@ +package weaver.bokang.xiao.kljd_code_generate.util; + +import aiyh.utils.Util; +import aiyh.utils.excention.CustomerException; +import org.apache.log4j.Logger; +import weaver.bokang.xiao.kljd_code_generate.entity.CodeBuildEntity; +import weaver.bokang.xiao.kljd_code_generate.entity.CodeConditionEntity; +import weaver.bokang.xiao.kljd_code_generate.entity.CodeRuleConfig; +import weaver.bokang.xiao.kljd_code_generate.entity.FlowEntity; +import weaver.bokang.xiao.kljd_code_generate.enum_type.ChangeRuleEnum; +import weaver.bokang.xiao.kljd_code_generate.enum_type.CompareEnum; +import weaver.bokang.xiao.kljd_code_generate.enum_type.FieldTypeEnum; +import weaver.bokang.xiao.kljd_code_generate.mapper.CodeRuleMapper; +import weaver.bokang.xiao.kljd_code_generate.mapper.FlowMapper; +import weaver.conn.RecordSet; + +import java.util.ArrayList; +import java.util.List; +import java.util.Map; +import java.util.regex.Matcher; +import java.util.regex.Pattern; + +/** + * @ClassName CodeGenerate + * @Author 肖博亢 + * @Date 2023/2/6 14:07 + * @Description

流程编码生成工具类

+ **/ +public class CodeGenerateUtil { + + private final Logger logger = Util.getLogger(); + private final CodeRuleMapper codeRuleMapper = Util.getMapper(CodeRuleMapper.class); + private final FlowMapper flowMapper = Util.getMapper(FlowMapper.class); + + /** + *

通过流程id获取配置信息

+ * @param workflowId 流程id + * @return 配置列表 + */ + public List getRuleConfig(String workflowId){ + List codeRuleConfigList = codeRuleMapper.queryCodeRuleConfig(workflowId); + codeRuleConfigList.forEach(codeRule ->{ + int mainId = codeRule.getId(); + List codeBuildEntities = codeRuleMapper.queryBuildByMainId(mainId); + List codeConditionEntities = codeRuleMapper.queryConditionByMainId(mainId); + List reserveNumberList = codeRuleMapper.queryReserveNumberByMainId(mainId); + codeRule.setCodeBuildEntityList(codeBuildEntities); + codeRule.setCodeConditionEntityList(codeConditionEntities); + codeRule.setReserveNumberList(reserveNumberList); + }); + return codeRuleConfigList; + } + + /** + *

流程编码生成

+ * @param workflowId 流程id + * @param mainMap 流程主表数据 + * @return 流程编码信息 + */ + public String codeBuildByWorkflow(String workflowId,String requestId, Map mainMap){ + String codeNumber = ""; + List ruleConfig = getRuleConfig(workflowId); + logger.info("编码生成配置信息 ==>"+ruleConfig); + for (CodeRuleConfig codeRuleConfig : ruleConfig) { + List codeConditionEntityList = codeRuleConfig.getCodeConditionEntityList(); + boolean isBeginBuild = true; + for (CodeConditionEntity codeConditionEntity : codeConditionEntityList) { + int compare = codeConditionEntity.getCompare(); + String value = codeConditionEntity.getValue(); + String fieldName = codeConditionEntity.getFieldName(); + CompareEnum compareEnum = CompareEnum.getEnum(compare); + String fieldValue = Util.null2String(mainMap.get(fieldName)); + switch (compareEnum){ + case EQUAL:{ + isBeginBuild = fieldValue.equals(value); + }break; + case NO_EQUAL:{ + isBeginBuild = !fieldValue.equals(value); + }break; + case MORE_THAN:{ + isBeginBuild = Util.getIntValue(value) > Util.getIntValue(fieldValue); + }break; + case LESS_THAN:{ + isBeginBuild = Util.getIntValue(value) < Util.getIntValue(fieldValue); + }break; + default:break; + } + if(!isBeginBuild) { + break; + } + } + if(isBeginBuild){ + codeNumber = codeBuild(codeRuleConfig, mainMap); + break; + } + } + return codeNumber; + } + + /** + *

流程编码生成

+ * @param codeRuleConfig 编码生成规则配置实体 + * @param mainMap 流程主表数据 + * @return 流程编码 + */ + public String codeBuild(CodeRuleConfig codeRuleConfig, Map mainMap){ + StringBuilder stringBuilder = new StringBuilder(); + StringBuilder flowKeyBuilder = new StringBuilder(); + List codeBuildEntityList = codeRuleConfig.getCodeBuildEntityList(); + for (CodeBuildEntity codeBuildEntity : codeBuildEntityList) { + int changeRule = codeBuildEntity.getChangeRule(); + int fieldType = codeBuildEntity.getFieldType(); + String workflowField = codeBuildEntity.getWorkflowField(); + String workflowFieldName = codeBuildEntity.getWorkflowFieldName(); + String cusText = codeBuildEntity.getCusText(); + int isAlone = codeBuildEntity.getIsAlone(); + ChangeRuleEnum changeRuleEnum = ChangeRuleEnum.getEnum(changeRule); + FieldTypeEnum fieldTypeEnum = FieldTypeEnum.getEnum(fieldType); + String currentStr = ""; + switch (fieldTypeEnum){ + case WORKFLOW_FIELD:{ + currentStr = Util.null2String(mainMap.get(workflowFieldName)); + }break; + case STRING:{ + currentStr = cusText; + }break; + case FLOW_NUMBER:{ + currentStr = "{flowNumber}"; + }break; + default:break; + } + switch (changeRuleEnum){ + case CUS_SQL:{ + currentStr = executeCusSql(cusText, mainMap); + }break; + case DEFAULT_VALUE:{ + currentStr = currentStr; + } + default:break; + } + if(isAlone == 0){ + flowKeyBuilder.append(currentStr).append("-"); + } + stringBuilder.append(currentStr); + } + String workflowCode = stringBuilder.toString(); + int maxFlow = 0; + String flowAloneKey = flowKeyBuilder.toString(); + if(flowKeyBuilder.length() > 0){ + flowAloneKey = flowAloneKey.substring(0,flowAloneKey.length() - 1); + if(!"".equals(flowAloneKey)){ + maxFlow = flowMapper.getFlowByParam(codeRuleConfig.getId(), flowAloneKey); + }else { + maxFlow = flowMapper.getFlowByParam(codeRuleConfig.getId()); + } + }else { + maxFlow = flowMapper.getFlowByParam(codeRuleConfig.getId()); + } + maxFlow = Math.max(maxFlow, 0); + maxFlow = Math.max(maxFlow,codeRuleConfig.getStartNumber()); + logger.info("流水号 ==>"+maxFlow); + if(codeRuleConfig.getFlowType() != 0 && workflowCode.contains("{flowNumber}")){ + List reserveNumberList = codeRuleConfig.getReserveNumberList(); + //跳过预留编号 + while (true){ + maxFlow ++; + String maxFlowStr = maxFlow + ""; + //若流水方式为流水位数控制,则添加字符0 + if(codeRuleConfig.getFlowType() == 1){ + int leftZero = codeRuleConfig.getFlowNumber() - maxFlowStr.length(); + StringBuilder leftZeroBuilder = new StringBuilder(maxFlowStr); + for (int i = 0; i < leftZero; i++) { + leftZeroBuilder.insert(0,"0"); + } + if(leftZero < 0){ + throw new CustomerException("流水位数超出限制,流水号 ==>"+workflowCode.replace("{flowNumber}",maxFlowStr)); + } + maxFlowStr = leftZeroBuilder.toString(); + } + String tempCode = workflowCode.replace("{flowNumber}",maxFlowStr); + if(!reserveNumberList.contains(tempCode)){ + workflowCode = tempCode; + FlowEntity flowEntity = new FlowEntity(); + flowEntity.setFlowNumber(maxFlow); + flowEntity.setCodeRule(codeRuleConfig.getId()); + flowEntity.setFlowKey(flowAloneKey); + int modeId = Util.getIntValue(Util.getModeIdByTableName("uf_flow_info")); + int dataId = Util.getModeDataId("uf_flow_info", modeId, 1); + flowEntity.setId(dataId); + flowMapper.updateFlow(flowEntity); + Util.rebuildModeDataShareByAsync(1,modeId,dataId); + break; + } + } + } + logger.info("流程编号信息 ==>"+workflowCode); + return workflowCode; + } + + /** + *

执行自定义sql

+ * @param sourceStr sql字符串 + * @param mainMap 主表字段信息 + * @return 执行结果 + */ + public String executeCusSql(String sourceStr,Map mainMap){ + String result = ""; + List paramList = new ArrayList<>(); + String queryString = getQueryString(sourceStr, mainMap,paramList); + RecordSet recordSet = new RecordSet(); + recordSet.executeQuery(queryString,paramList); + if(recordSet.next()){ + result = Util.null2String(recordSet.getString(1)); + } + return result; + } + + /** + *

获取查询字符串

+ * @param sourceStr 原字符串 + * @param mainMap 流程主表数据 + * @param paramList 参数列表 + * @return 查询字符串 + */ + public String getQueryString(String sourceStr,Map mainMap,List paramList){ + String regx = "#\\{(?\\S+)}"; + Pattern compile = Pattern.compile(regx); + Matcher matcher = compile.matcher(sourceStr); + while (matcher.find()){ + String fieldName = matcher.group("fieldName"); + paramList.add(fieldName); + sourceStr = sourceStr.replace("#{" + fieldName + "}", "?"); + paramList.add(Util.null2String(mainMap.get(fieldName))); + } + return sourceStr; + } + +}