diff --git a/src/main/java/weaver/cssc/schedule/util/PushModeDataUtil.java b/src/main/java/weaver/cssc/schedule/util/PushModeDataUtil.java index 279df99..d9ee681 100644 --- a/src/main/java/weaver/cssc/schedule/util/PushModeDataUtil.java +++ b/src/main/java/weaver/cssc/schedule/util/PushModeDataUtil.java @@ -32,15 +32,7 @@ public class PushModeDataUtil { public Map getConfigurationByKeyId(String keyId){ Map configMap = sqlMapper.getPushDataConfiguration(keyId); - if(configMap != null && configMap.size() > 0){ - int mainKeyId = (int) configMap.get("id"); - - List> fieldList = sqlMapper.getPushDataDetailConfiguration(mainKeyId); - - configMap.put("fieldList",fieldList); - } - - return configMap; + return getConfiguration(configMap); } /** @@ -51,6 +43,15 @@ public class PushModeDataUtil { public Map getConfigurationByModeId(int modeId){ Map configMap = sqlMapper.getPushDataConfigurationByModeId(modeId); + return getConfiguration(configMap); + } + + /** + * 获取配置信息 + * @param configMap 配置信息结果 + * @return 返回配置信息 + */ + private Map getConfiguration(Map configMap) { if(configMap != null && configMap.size() > 0){ int mainKeyId = (int) configMap.get("id"); diff --git a/src/main/java/weaver/weilin/zhu/asc/workflow/VoucherPushAction.java b/src/main/java/weaver/weilin/zhu/asc/workflow/VoucherPushAction.java new file mode 100644 index 0000000..685b620 --- /dev/null +++ b/src/main/java/weaver/weilin/zhu/asc/workflow/VoucherPushAction.java @@ -0,0 +1,104 @@ +package weaver.weilin.zhu.asc.workflow; + +import aiyh.utils.Util; +import aiyh.utils.httpUtil.HttpArgsType; +import aiyh.utils.httpUtil.ResponeVo; +import aiyh.utils.httpUtil.util.HttpUtils; +import com.alibaba.fastjson.JSONObject; +import org.apache.log4j.Logger; +import weaver.file.Prop; +import weaver.weilin.zhu.common.util.CommonUtil; +import weaver.weilin.zhu.common.voucher.action.CusActionPostInterface; +import weaver.weilin.zhu.common.voucher.action.ResultMessageUtil; + +import java.io.IOException; +import java.util.HashMap; +import java.util.Map; + +/** + * ASC 精品酒店 + * JSON数据推送 NC 接口操作,通用凭证Action后置方法 + * @author bleach + * @version v1.0 2023-07-10 + */ +public class VoucherPushAction implements CusActionPostInterface { + + /** + * 日志操作类 + */ + private final Logger logger = Util.getLogger(); + + + + /** + * 后置处理方法 + * + * @param params 后置处理器参数 + * @return 处理后返回值 + */ + @SuppressWarnings("unchecked") + @Override + public ResultMessageUtil postProcessor(Map params) { + ResultMessageUtil resultMessageUtil = new ResultMessageUtil(); + + JSONObject postObj = (JSONObject) params.get("pushJsonObject"); + Map workflowBaseMap = (Map) params.get("workflowBaseMap"); + Map pathParam = (Map) params.get("pathParam"); + + + Map logMap = new HashMap<>(); + logMap.put("rid",workflowBaseMap.get("requestId")); + logMap.put("interface_name",Util.null2String(pathParam.get("pathParam"))); + logMap.put("system_name",Util.null2String(pathParam.get("system_name"))); + logMap.put("systemCode",Util.null2String(pathParam.get("systemCode"))); + + + //获取接口请求地址 + String requestURL = Util.null2String(Prop.getPropValue("AscVoucher", "url")); + + Map headerMap = new HashMap<>(); + headerMap.put("Content-Type", HttpArgsType.APPLICATION_JSON); + + HttpUtils httpUtils = new HttpUtils(); + + try { + //进行接口数据推送 + ResponeVo responeVo = httpUtils.apiPostObject(requestURL, postObj, headerMap); + + if(responeVo != null && responeVo.getCode() == 200){ + logMap.put("message",responeVo.getEntityString()); + + //接口返回所有信息 + resultMessageUtil.setResponseBody(responeVo.getEntityString()); + + Map resultMap = responeVo.getResponseMap(); + + if(resultMap != null){ + String state = Util.null2String(resultMap.get("state")); + + resultMessageUtil.setSuccess("1".equals(state)); + + logMap.put("result","1".equals(state) ? 0 : 1); + + } else { + logMap.put("result",1); + logMap.put("message","接口返回信息为空!"); + } + } else { + logMap.put("result",1); + logMap.put("message","接口返回信息为空或者请求失败!"); + } + } catch (IOException e) { + logger.error("接口请求异常,异常信息:[" + e.getMessage() + "]"); + logMap.put("result",1); + logMap.put("message","接口请求异常,异常信息:[" + e.getMessage() + "]!"); + throw new RuntimeException(e); + } + + int modeid = Util.getIntValue(Prop.getPropValue("global", "interfacelog_modeid")); + + CommonUtil.insertNewDataToMode(modeid,"uf_interface_log",logMap); + + return resultMessageUtil; + } +} diff --git a/src/main/java/weaver/weilin/zhu/common/util/CommonUtil.java b/src/main/java/weaver/weilin/zhu/common/util/CommonUtil.java new file mode 100644 index 0000000..df75aa8 --- /dev/null +++ b/src/main/java/weaver/weilin/zhu/common/util/CommonUtil.java @@ -0,0 +1,100 @@ +package weaver.weilin.zhu.common.util; + +import aiyh.utils.Util; +import weaver.conn.RecordSet; +import weaver.general.TimeUtil; +import weaver.weilin.zhu.common.util.mapper.CommonSqlMapper; + +import java.util.Map; + +/** + * 通用的工具类型 + */ +public class CommonUtil { + + + /** + * 获取数据库操作接口 + */ + private static final CommonSqlMapper sqlMapper = Util.getMapper(CommonSqlMapper.class); + + /** + * 获取字段详细信息 + * @param fieldId 字段ID + * @return 字段详细信息 + */ + public static FieldDetailInfo getFieldDetailInfo(int fieldId){ + FieldDetailInfo fieldDetailInfo = new FieldDetailInfo(); + + if(fieldId != 0) { + RecordSet rs = new RecordSet(); + + String selectSQL = "select id,fieldName,viewType,detailTable,fieldDbType from workflow_billField where id = ?"; + + if (rs.executeQuery(selectSQL, fieldId) && rs.next()) { + //字段数据库名称 + String fieldName = Util.null2String(rs.getString("fieldName")); + //字段所属 + int viewType = Util.getIntValue(rs.getString("viewType"),0); + //字段明细表名称 + String detailTable = Util.null2String(rs.getString("detailTable")); + //字段数据库类型 + String fieldDbType = Util.null2String(rs.getString("fieldDbType")); + + + fieldDetailInfo.setId(fieldId); + fieldDetailInfo.setFieldName(fieldName); + fieldDetailInfo.setDetailTable(detailTable); + fieldDetailInfo.setDbType(fieldDbType); + + if(viewType == 1 && !"".equals(detailTable)){ + int detailIndex = Util.getIntValue(detailTable.substring(detailTable.indexOf("_dt") + 3),-1); + + fieldDetailInfo.setDetailIndex(detailIndex); + } else { + fieldDetailInfo.setDetailIndex(0); + } + } + } + + return fieldDetailInfo; + } + + + /** + * 根据模块表名称 获取其对应的模块ID (可以预见的BUG:若一个表被多个模块引用,则会出问题) + * @param modeTableName 模块表名称 + * @return 模块ID + */ + public static int getModeIdByTableName(String modeTableName) { + return sqlMapper.getModeIdByTableName(modeTableName); + } + + /** + * 往建模中写入新的记录 + * @param modeId 模块ID + * @param modeTableName 模块表名称 + * @param dataMap 数据集 + */ + public static void insertNewDataToMode(int modeId,String modeTableName, Map dataMap){ + //获取新的记录ID + int newDataId = Util.getModeDataId(modeTableName,modeId,1); + + if(newDataId > 0){ + StringBuilder updateSql = new StringBuilder(); + updateSql.append("update ").append(modeTableName).append(" set modeDataModifyDatetime = '").append(TimeUtil.getCurrentTimeString()).append("'"); + + for(String key : dataMap.keySet()){ + updateSql.append(",").append(key).append("=?"); + } + + updateSql.append(" where id = #{id}"); + + dataMap.put("id",newDataId); + + if(sqlMapper.insertModeData(updateSql.toString(),dataMap)){ + sqlMapper.deleteRedundancyData(modeTableName,newDataId); + } + } + } +} diff --git a/src/main/java/weaver/weilin/zhu/common/util/FieldDetailInfo.java b/src/main/java/weaver/weilin/zhu/common/util/FieldDetailInfo.java new file mode 100644 index 0000000..9437abd --- /dev/null +++ b/src/main/java/weaver/weilin/zhu/common/util/FieldDetailInfo.java @@ -0,0 +1,42 @@ +package weaver.weilin.zhu.common.util; + +import lombok.Data; + +/** + * 字段详细信息实体类 + * @author bleach + * @version 2023-07-10 + */ +@Data +public class FieldDetailInfo { + + /** + * 字段ID + */ + private int id; + + /** + * 字段名称 + */ + private String fieldName; + + /** + * 字段所属 0-主表 1-明细表 + */ + private int viewType; + + /** + * 明细表名称 + */ + private String detailTable; + + /** + * 字段存储数据库类型 + */ + private String dbType; + + /** + * 所属明细表下标 + */ + private int detailIndex; +} diff --git a/src/main/java/weaver/weilin/zhu/common/util/mapper/CommonSqlMapper.java b/src/main/java/weaver/weilin/zhu/common/util/mapper/CommonSqlMapper.java new file mode 100644 index 0000000..750e8a8 --- /dev/null +++ b/src/main/java/weaver/weilin/zhu/common/util/mapper/CommonSqlMapper.java @@ -0,0 +1,42 @@ +package weaver.weilin.zhu.common.util.mapper; + +import aiyh.utils.annotation.recordset.*; + +import java.util.Map; + +/** + * 通用工具类 操作数据库接口 + * @author bleach + * @version 2023-07-12 + */ +public interface CommonSqlMapper { + + /** + * 根据模块表名称 获取其对应的模块ID (可以预见的BUG:若一个表被多个模块引用,则会出问题) + * @param tableName 模块表名称 + * @return 模块ID + */ + @Select("select m.id from modeInfo m inner join workflow_bill wb on m.formId = wb.id where lower(wb.tableName) = #{tableName}") + int getModeIdByTableName(@ParamMapper("tableName") String tableName); + + + /** + * 更新建模数据 + * @param updateSql 更新的SQL语句 + * @param dataMap 数据集 + * @return 更新结果 + */ + @Update(custom = true) + boolean insertModeData(@SqlString String updateSql, Map dataMap); + + + + /** + * 删除建模数据 + * @param tableName 表单名称 + * @param dataId 数据ID + * @return 更新结果 + */ + @Delete("delete from $t{tableName} where id = #{dataId}") + boolean deleteRedundancyData(@ParamMapper("tableName") String tableName, @ParamMapper("dataId") int dataId); +} diff --git a/src/main/java/weaver/weilin/zhu/common/voucher/action/CommonVoucherAction.java b/src/main/java/weaver/weilin/zhu/common/voucher/action/CommonVoucherAction.java new file mode 100644 index 0000000..7c6c3b0 --- /dev/null +++ b/src/main/java/weaver/weilin/zhu/common/voucher/action/CommonVoucherAction.java @@ -0,0 +1,230 @@ +package weaver.weilin.zhu.common.voucher.action; + +import aiyh.utils.Util; +import aiyh.utils.action.SafeCusBaseAction; +import aiyh.utils.annotation.ActionDefaultTestValue; +import aiyh.utils.annotation.PrintParamMark; +import aiyh.utils.annotation.RequiredMark; +import com.alibaba.fastjson.JSONObject; +import org.apache.commons.lang3.StringUtils; +import org.apache.log4j.Logger; +import weaver.conn.RecordSet; +import weaver.conn.RecordSetTrans; +import weaver.hrm.User; +import weaver.soa.workflow.request.RequestInfo; +import weaver.weilin.zhu.common.voucher.entity.BaseConfigDao; +import weaver.weilin.zhu.common.voucher.util.CommonVoucherUtil; +import weaver.weilin.zhu.common.voucher.mapper.CommVoucherSqlMapper; +import weaver.zwl.common.ToolUtilNew; + +import java.lang.reflect.Constructor; +import java.lang.reflect.InvocationTargetException; +import java.util.HashMap; +import java.util.Map; + +/** + * 通用凭证Action入口 + * @author bleach + * @version 2023-07-10 + */ +public class CommonVoucherAction extends SafeCusBaseAction { + + /** + * 日志操作类 + */ + private final Logger logger = Util.getLogger(); + + /** + * SQL接口 + */ + private final CommVoucherSqlMapper sqlMapper = Util.getMapper(CommVoucherSqlMapper.class); + + /** + * 自定义参数值 + */ + private String cusParamValue; + + /** + * 后置实现类接口路径 + */ + @RequiredMark("具体接口请求实现接口类路径!") + @ActionDefaultTestValue("weaver.weilin.zhu.asc.workflow.VoucherPushAction") + @PrintParamMark + private String implementorPath; + + + + /** + *

action 提交流程业务处理方法

+ *

具体业务逻辑实现 + * 全局存在log成员变量,用于日志的输出 Util.actionFailException(requestManager,"error msg"); 用于提示action执行失败 + *

+ * + * @param requestId 流程请求ID + * @param billTable 流程对应主表名称 + * @param workflowId 流程对应流程ID + * @param user 当前节点操作者用户 + * @param requestInfo 请求管理对象 + */ + @Override + public void doSubmit(String requestId, String billTable, int workflowId, User user, RequestInfo requestInfo) { + logger.info("--------------- CommonVoucherAction Begin ---------------"); + + Map workflowBaseMap = getWorkflowBaseInfo(requestInfo.getRsTrans(),requestId); + + CommonVoucherUtil voucherUtil = new CommonVoucherUtil(); + + voucherUtil.setWorkflowBaseMap(workflowBaseMap); + + //自定义配置 + BaseConfigDao baseConfigDao = voucherUtil.getConfigurationByWorkflowId(String.valueOf(workflowId), cusParamValue); + + assert baseConfigDao != null; + + voucherUtil.setThisUser(user); + voucherUtil.setObjectMappingDaoList(baseConfigDao.getObjectMappingDaoList()); + voucherUtil.setNodeFieldMappingDaoList(baseConfigDao.getNodeFieldMappingDaoList()); + + RecordSet rs ; + + String dataCondition = baseConfigDao.getDataCondition(); + + if(StringUtils.isNotBlank(dataCondition)){ + rs = sqlMapper.getWorkflowMainTableInfoAndCondition(billTable,requestId, ToolUtilNew.staticToDBC(dataCondition)); + } else { + rs = sqlMapper.getWorkflowMainTableInfo(billTable,requestId); + } + + if(!rs.next()){ + logger.info("当前流程不满足自定义条件!"); + } + + workflowBaseMap.put("mainId",Util.null2String(rs.getString("id"))); + + //推送的报文 + JSONObject postJsonObj = new JSONObject(); + + StringBuilder postXmlObj = new StringBuilder(); + + if(baseConfigDao.getDataFormat() == 1){ + postXmlObj = voucherUtil.recursionGenerateXML("",null,null,0,0,0); + } else { + //推送的报文 + postJsonObj = voucherUtil.recursionGenerateJsonObject("",null,null,0,0,0); + } + + if(postJsonObj != null || postXmlObj.length() > 0){ + + if(StringUtils.isNotBlank(implementorPath)){ + Map pathParam = Util.parseCusInterfacePathParam(implementorPath); + String className = pathParam.remove("_ClassPath"); + + Map paramsMap = new HashMap<>(); + paramsMap.put("pushJsonObject",postJsonObj); + paramsMap.put("pushXmlObject",postXmlObj); + paramsMap.put("pathParam",pathParam); + paramsMap.put("requestInfo",requestInfo); + paramsMap.put("workflowBaseMap",workflowBaseMap); + paramsMap.put("userInfo",user); + + ResultMessageUtil resultMessageUtil = executePostProcessor(className,paramsMap); + + if(resultMessageUtil.isSuccess()){ + String backFieldname = baseConfigDao.getBackFieldname(); + + String backFieldValue = resultMessageUtil.getBackFieldValue(); + + sqlMapper.resultBackToWorkflowBill(billTable,backFieldname,backFieldValue,requestId); + } else { + //获取失败的错误提示 + String tipMessage = resultMessageUtil.getTipMessage(); + + if(baseConfigDao.getExceptionContinue() == 0){ + //阻止流程提交 + Util.actionFail(requestInfo.getRequestManager(),tipMessage); + } + } + } + } + + logger.info("--------------- CommonVoucherAction End ---------------"); + } + + /** + * 获取流程基础信息 + * @param trans 当前事务 + * @param requestId 流程请求ID + * @return 当前流程信息 + */ + private Map getWorkflowBaseInfo(RecordSetTrans trans,String requestId){ + Map baseInfo = new HashMap<>(); + + if(trans == null){ + trans = new RecordSetTrans(); + } + + String selectSQL = "select requestName,requestMark from workflow_requestBase where requestId = ?"; + + try { + if(trans.executeQuery(selectSQL,requestId) && trans.next()){ + baseInfo.put("requestName",Util.null2String(trans.getString(1))); + baseInfo.put("requestMark",Util.null2String(trans.getString(2))); + } + } catch (Exception e) { + throw new RuntimeException(e); + } + + return baseInfo; + } + + + /** + * 执行自定义后置处理方法 + * + * @param className 全路径类名 + * @param params 参数 + * @return 返回值 + */ + private ResultMessageUtil executePostProcessor(String className, Map params) { + Class aClass; + try { + aClass = Class.forName(className); + } catch (ClassNotFoundException e) { + throw new IllegalArgumentException("未能找到自定义action接口处理方法:" + className); + } + Constructor constructor; + try { + constructor = aClass.getConstructor(); + } catch (NoSuchMethodException e) { + throw new IllegalArgumentException(className + "没有空参构造方法,无法获取构造方法对象!"); + } + if (!CusActionPostInterface.class.isAssignableFrom(aClass)) { + throw new IllegalArgumentException("自定义后置处理接口:" + className + " 不是" + + CusActionPostInterface.class.getName() + "的子类或实现类!"); + } + CusActionPostInterface o; + try { + o = (CusActionPostInterface) constructor.newInstance(); + } catch (InstantiationException | IllegalAccessException | InvocationTargetException e) { + throw new IllegalArgumentException("无法构造" + className + "对象!"); + } + return o.postProcessor(params); + } + + + public String getCusParamValue() { + return cusParamValue; + } + + public void setCusParamValue(String cusParamValue) { + this.cusParamValue = cusParamValue; + } + + public String getImplementorPath() { + return implementorPath; + } + + public void setImplementorPath(String implementorPath) { + this.implementorPath = implementorPath; + } +} diff --git a/src/main/java/weaver/weilin/zhu/common/voucher/action/CusActionPostInterface.java b/src/main/java/weaver/weilin/zhu/common/voucher/action/CusActionPostInterface.java new file mode 100644 index 0000000..762cdeb --- /dev/null +++ b/src/main/java/weaver/weilin/zhu/common/voucher/action/CusActionPostInterface.java @@ -0,0 +1,22 @@ +package weaver.weilin.zhu.common.voucher.action; + +import java.util.Map; + +/** + * 自定义接口操作 + * 通过配置动态生成了JSONObject或者XML信息 + * 该接口中拿到对应的信息进行后续操作 + * + * @author bleach + */ + +public interface CusActionPostInterface { + + /** + * 后置处理方法 + * + * @param params 后置处理器参数 + * @return 处理后返回值 + */ + ResultMessageUtil postProcessor(Map params); +} diff --git a/src/main/java/weaver/weilin/zhu/common/voucher/action/ResultMessageUtil.java b/src/main/java/weaver/weilin/zhu/common/voucher/action/ResultMessageUtil.java new file mode 100644 index 0000000..6d7f7dd --- /dev/null +++ b/src/main/java/weaver/weilin/zhu/common/voucher/action/ResultMessageUtil.java @@ -0,0 +1,32 @@ +package weaver.weilin.zhu.common.voucher.action; + +import lombok.Data; + +/** + * 自定义接口操作 + * 返回信息实体类 + */ +@Data +public class ResultMessageUtil { + + /** + * 是否调用成功 + */ + private boolean isSuccess; + + /** + * 提示消息说明 + */ + private String tipMessage; + + /** + * 接口返回信息 + */ + private String responseBody; + + /** + * 回写的字段值 + */ + private String backFieldValue; + +} diff --git a/src/main/java/weaver/weilin/zhu/common/voucher/convert/CusAsyncConvert.java b/src/main/java/weaver/weilin/zhu/common/voucher/convert/CusAsyncConvert.java new file mode 100644 index 0000000..99aa139 --- /dev/null +++ b/src/main/java/weaver/weilin/zhu/common/voucher/convert/CusAsyncConvert.java @@ -0,0 +1,21 @@ +package weaver.weilin.zhu.common.voucher.convert; + + +import weaver.weilin.zhu.common.voucher.entity.NodeFieldMappingDao; + +import java.util.Map; + +/** + * 自定义转换规则接口 + * @author bleach + */ +public interface CusAsyncConvert { + /** + * 自定义转换接口 + * @param dao 配置信息 + * @param param 自定义转换规则参数 + * @param pathParam 自定义接口路径 + * @return 转换后的值 + */ + String cusConvert(NodeFieldMappingDao dao, RuleMethodParam param, Map pathParam); +} diff --git a/src/main/java/weaver/weilin/zhu/common/voucher/convert/FieldChangeRuleMethod.java b/src/main/java/weaver/weilin/zhu/common/voucher/convert/FieldChangeRuleMethod.java new file mode 100644 index 0000000..15a6b83 --- /dev/null +++ b/src/main/java/weaver/weilin/zhu/common/voucher/convert/FieldChangeRuleMethod.java @@ -0,0 +1,213 @@ +package weaver.weilin.zhu.common.voucher.convert; + +import aiyh.utils.Util; +import aiyh.utils.annotation.MethodRuleNo; +import aiyh.utils.excention.CustomerException; +import com.google.common.base.Strings; +import org.apache.commons.lang3.StringUtils; +import weaver.general.TimeUtil; +import weaver.weilin.zhu.common.util.FieldDetailInfo; +import weaver.weilin.zhu.common.voucher.entity.NodeFieldMappingDao; +import weaver.zwl.common.ToolUtilNew; + +import java.lang.reflect.InvocationTargetException; +import java.lang.reflect.Method; +import java.util.HashMap; +import java.util.Map; +import java.util.function.BiFunction; + +/** + * 流程字段转换规则处理 + * @author bleach + * @version 2023-07-04 + */ +public class FieldChangeRuleMethod { + + public static final Map> VALUE_RULE_FUNCTION = new HashMap<>(); + + static { + Class valueRuleMethodClass = FieldChangeRuleMethod.class; + Method[] methods = valueRuleMethodClass.getMethods(); + for (Method method : methods) { + if (method.isAnnotationPresent(MethodRuleNo.class)) { + MethodRuleNo annotation = method.getAnnotation(MethodRuleNo.class); + int value = annotation.value();//规则标识 + VALUE_RULE_FUNCTION.put(value, (config, map) -> { + try { + FieldChangeRuleMethod valueRuleMethod = new FieldChangeRuleMethod(); + return method.invoke(valueRuleMethod, config, map).toString(); + } catch (IllegalAccessException | InvocationTargetException e) { + throw new RuntimeException(e); + } + }); + } + } + } + + + /** + * 不转换 + * @param dao 流程字段配置信息 + * @param param 转换规则参数集合 + * @return 返回转换后的值 + */ + @MethodRuleNo(value = 0, desc = "不转换") + public String noChange(NodeFieldMappingDao dao, RuleMethodParam param) { + String fieldValue = ""; + FieldDetailInfo fieldInfo = dao.getWfField(); + + if(fieldInfo != null){ + String fieldName = fieldInfo.getFieldName();//字段名称 + + if(StringUtils.isNotBlank(fieldName)){ + int viewType = fieldInfo.getViewType(); + + if(viewType == 0){ + fieldValue = Util.null2String(param.getRs().getString(fieldName)); + } else if(viewType == 1 && param.getRs_detail() != null){ + fieldValue = Util.null2String(param.getRs_detail().getString(fieldName)); + } + + } + } + return fieldValue; + } + + /** + * 流程请求ID + * @param dao 明细配置 + * @param param 转换规则参数集合 + * @return 返回转换后的值 + */ + @MethodRuleNo(value = 1, desc = "流程请求ID") + public String workflowRequestId(NodeFieldMappingDao dao,RuleMethodParam param) { + return Util.null2String(param.getWorkflowBaseMap().get("requestId")); + } + + /** + * 流程请求标题 + * @param dao 明细配置 + * @param param 转换规则参数集合 + * @return 返回转换后的值 + */ + @MethodRuleNo(value = 2, desc = "流程请求标题") + public String workflowRequestTitle(NodeFieldMappingDao dao,RuleMethodParam param) { + return Util.null2String(param.getWorkflowBaseMap().get("requestName")); + } + + /** + * 流程请求编号 + * @param dao 明细配置 + * @param param 转换规则参数集合 + * @return 返回转换后的值 + */ + @MethodRuleNo(value = 3, desc = "流程请求编号") + public String workflowRequestMark(NodeFieldMappingDao dao,RuleMethodParam param) { + return Util.null2String(param.getWorkflowBaseMap().get("requestMark")); + } + + /** + * 系统日期 + * @param dao 明细配置 + * @param param 转换规则参数集合 + * @return 返回转换后的值 + */ + @MethodRuleNo(value = 4, desc = "系统日期") + public String systemDate(NodeFieldMappingDao dao,RuleMethodParam param) { + return TimeUtil.getCurrentDateString(); + } + + /** + * 系统日期时间 + * @param dao 明细配置 + * @param param 转换规则参数集合 + * @return 返回转换后的值 + */ + @MethodRuleNo(value = 5, desc = "系统日期时间") + public String systemDateTime(NodeFieldMappingDao dao,RuleMethodParam param) { + return TimeUtil.getCurrentTimeString(); + } + + /** + * 固定值 + * @param dao 明细配置 + * @param param 转换规则参数集合 + * @return 返回转换后的值 + */ + @MethodRuleNo(value = 6, desc = "固定值") + public String fixValue(NodeFieldMappingDao dao,RuleMethodParam param) { + return Util.null2String(dao.getCusSQL()); + } + + /** + * 明细序列 + * @param dao 明细配置 + * @param param 转换规则参数集合 + * @return 返回转换后的值 + */ + @MethodRuleNo(value = 7, desc = "明细序列") + public String getDetailRowNum(NodeFieldMappingDao dao,RuleMethodParam param) { + return Util.null2String(param.getRowNum()); + } + + + /** + * 自定义SQL转换 + * @param dao 明细配置 + * @param param 转换规则参数集合 + * @return 返回转换后的值 + */ + @MethodRuleNo(value = 8, desc = "自定义SQL") + public String customizeSQL(NodeFieldMappingDao dao,RuleMethodParam param) { + String fieldName = dao.getNodeName();//字段名称 + + //字段值 + String fieldValue = noChange(dao,param); + + String cusSQL = dao.getCusSQL(); + + int detailKeyId = -1; + if(StringUtils.isNotBlank(cusSQL)){ + if( cusSQL.contains("{dt.id}") && param.getRs_detail() != null) { + detailKeyId = Util.getIntValue(param.getRs_detail().getString("id"), -1); + } + + if(param.getThisUser() != null){ + cusSQL = cusSQL.replace("{userId}", String.valueOf(param.getThisUser().getUID())); + + cusSQL = cusSQL.replace("{departmentId}", String.valueOf(param.getThisUser().getUserDepartment())); + + cusSQL = cusSQL.replace("{subCompanyId}", String.valueOf(param.getThisUser().getUserSubCompany1())); + } + } + + fieldValue = ToolUtilNew.getStaticValueByChangeRule(cusSQL,fieldValue,Util.null2String(param.getWorkflowBaseMap().get("requestId")),detailKeyId); + + return fieldValue; + } + + /** + * 自定义转换接口 + * @param dao 明细配置 + * @param param 转换规则参数集合 + * @return 返回转换后的值 + */ + @MethodRuleNo(value = 9, desc = "自定义接口") + public String getCusConvertInterface(NodeFieldMappingDao dao, RuleMethodParam param) { + String cusText = dao.getCusSQL(); + if(Strings.isNullOrEmpty(cusText)){ + return null; + } + try { + Class clazz = Class.forName(cusText); + if(!CusAsyncConvert.class.isAssignableFrom(clazz)){ + throw new CustomerException(cusText + " 接口不存在或者未实现 weaver.weilin.zhu.common.voucher.convert.CusAsyncConvert类!"); + } + CusAsyncConvert o = (CusAsyncConvert) clazz.newInstance(); + Map pathParam = Util.parseCusInterfacePathParam(cusText); + return o.cusConvert(dao, param, pathParam); + }catch (Exception e){ + return null; + } + } +} diff --git a/src/main/java/weaver/weilin/zhu/common/voucher/convert/RuleMethodParam.java b/src/main/java/weaver/weilin/zhu/common/voucher/convert/RuleMethodParam.java new file mode 100644 index 0000000..f75a93a --- /dev/null +++ b/src/main/java/weaver/weilin/zhu/common/voucher/convert/RuleMethodParam.java @@ -0,0 +1,43 @@ +package weaver.weilin.zhu.common.voucher.convert; + +import lombok.Getter; +import lombok.Setter; +import weaver.conn.RecordSet; +import weaver.hrm.User; + +import java.util.Map; + +/** + * 转换规则方法需要的参数类 + * @author bleach + * @version 2023-07-04 + */ +@Getter +@Setter +public class RuleMethodParam { + /** + * 流程主表数据集 + */ + private RecordSet rs ; + + /** + * 流程明细表某一行数据集 + */ + private RecordSet rs_detail; + + /** + * 流程基础信息数组 + */ + private Map workflowBaseMap; + + /** + * 明细序列 + */ + private int rowNum; + + /** + * 当前用户 + */ + private User thisUser; + +} diff --git a/src/main/java/weaver/weilin/zhu/common/voucher/entity/BaseConfigDao.java b/src/main/java/weaver/weilin/zhu/common/voucher/entity/BaseConfigDao.java new file mode 100644 index 0000000..045b90e --- /dev/null +++ b/src/main/java/weaver/weilin/zhu/common/voucher/entity/BaseConfigDao.java @@ -0,0 +1,60 @@ +package weaver.weilin.zhu.common.voucher.entity; + +import lombok.Data; + +import java.util.List; + +/** + * 凭证通用功能 + * 基础配置 + * @author bleach + * @version 2023-07-10 + */ +@Data +public class BaseConfigDao { + + /** + * 配置ID + */ + private int id; + + /** + * 流程类型ID + */ + private String workflowId; + + /** + * 自定义参数值 + */ + private String cusParamValue; + + /** + * 数据条件 + */ + private String dataCondition; + + /** + * 异常是否继续 + */ + private int exceptionContinue; + + /** + * 数据格式 0-JSON 1-XML + */ + private int dataFormat; + + /** + * 回写字段名称 + */ + private String backFieldname; + + /** + * 对象与流程明细映射关系配置 + */ + private List objectMappingDaoList; + + /** + * 节点与流程字段详细配置 + */ + private List nodeFieldMappingDaoList; +} diff --git a/src/main/java/weaver/weilin/zhu/common/voucher/entity/NodeFieldMappingDao.java b/src/main/java/weaver/weilin/zhu/common/voucher/entity/NodeFieldMappingDao.java new file mode 100644 index 0000000..41b246c --- /dev/null +++ b/src/main/java/weaver/weilin/zhu/common/voucher/entity/NodeFieldMappingDao.java @@ -0,0 +1,59 @@ +package weaver.weilin.zhu.common.voucher.entity; + +import lombok.Data; +import weaver.weilin.zhu.common.util.FieldDetailInfo; + +/** + * 凭证通用功能 + * 节点与流程字段配置详细 + * @author bleach + * @version 2023-07-10 + */ +@Data +public class NodeFieldMappingDao { + + /** + * 配置的数据ID + */ + private int id; + + /** + * 节点名称 + */ + private String nodeName; + + /** + * 父节点名称 + */ + private String parentNode; + + /** + * 节点类型 0-普通文本 1-普通对象 2-数组文本 3-数组对象 + */ + private int nodeType; + + /** + * 流程字段信息 + */ + private FieldDetailInfo wfField; + + /** + * 借贷方向 + */ + private String entriesDirection; + + /** + * 转换规则 + */ + private int changeRule; + + /** + * 自定义规则 + */ + private String cusSQL; + + /** + * 特殊属性 0-普通字段 1-金额控制字段 2-科目字段 + */ + private int specialAttr; +} diff --git a/src/main/java/weaver/weilin/zhu/common/voucher/entity/ObjectMappingDao.java b/src/main/java/weaver/weilin/zhu/common/voucher/entity/ObjectMappingDao.java new file mode 100644 index 0000000..2c4db1f --- /dev/null +++ b/src/main/java/weaver/weilin/zhu/common/voucher/entity/ObjectMappingDao.java @@ -0,0 +1,43 @@ +package weaver.weilin.zhu.common.voucher.entity; + +import lombok.Data; + +/** + * 凭证通用功能 + * 对象与流程明细映射关系配置 + * @author bleach + * @version 2023-07-10 + */ +@Data +public class ObjectMappingDao { + + /** + * 数据ID + */ + private int id; + + /** + * 对象名称 + */ + private String objectName; + + /** + * 流程明细 + */ + private int dtIndex; + + /** + * 别名 + */ + private String alias; + + /** + * 借贷方向 + */ + private String entriesDirection; + + /** + * 数据条件 + */ + private String dtCondition; +} diff --git a/src/main/java/weaver/weilin/zhu/common/voucher/entity/VoucherConstants.java b/src/main/java/weaver/weilin/zhu/common/voucher/entity/VoucherConstants.java new file mode 100644 index 0000000..2521903 --- /dev/null +++ b/src/main/java/weaver/weilin/zhu/common/voucher/entity/VoucherConstants.java @@ -0,0 +1,62 @@ +package weaver.weilin.zhu.common.voucher.entity; + +/** + * 凭证通过功能 + * 常量配置 + */ +public class VoucherConstants { + + + /** + * 借贷方向 - 非凭证分录 + */ + public static final int EntriesDirection_NoVoucher = 0; + + /** + * 借贷方向 - 普通借方 + */ + public static final int EntriesDirection_Comm_Debit = 1; + + + /** + * 借贷方向 - 税额借方 + */ + public static final int EntriesDirection_Tax_Debit = 2; + + + + /** + * 借贷方向 - 普通贷方 + */ + public static final int EntriesDirection_Comm_Credit = 3; + + + /** + * 借贷方向 - 冲销贷方 + */ + public static final int EntriesDirection_WriteOff_Credit = 4; + + + /** + * 节点类型 - 普通文本 + */ + public static final int Node_Type_Comm_Text = 0; + + + /** + * 节点类型 - 普通对象 + */ + public static final int Node_Type_Comm_Object = 1; + + + /** + * 节点类型 - 数组文本 + */ + public static final int Node_Type_Array_Text = 2; + + + /** + * 节点类型 - 数组对象 + */ + public static final int Node_Type_Array_Object = 3; +} diff --git a/src/main/java/weaver/weilin/zhu/common/voucher/mapper/CommVoucherSqlMapper.java b/src/main/java/weaver/weilin/zhu/common/voucher/mapper/CommVoucherSqlMapper.java new file mode 100644 index 0000000..ce813f9 --- /dev/null +++ b/src/main/java/weaver/weilin/zhu/common/voucher/mapper/CommVoucherSqlMapper.java @@ -0,0 +1,143 @@ +package weaver.weilin.zhu.common.voucher.mapper; + +import aiyh.utils.annotation.recordset.*; +import weaver.conn.RecordSet; +import weaver.weilin.zhu.common.voucher.entity.BaseConfigDao; +import weaver.weilin.zhu.common.voucher.entity.NodeFieldMappingDao; +import weaver.weilin.zhu.common.voucher.entity.ObjectMappingDao; + +import java.util.List; + +/** + * 凭证通用功能 + * 凭证相关数据操作接口 + * @author bleach + */ +@SqlMapper +public interface CommVoucherSqlMapper { + + /** + * 根据流程类型ID获取其对应的配置信息 + * @param workflowIds 流程类型ID + * @return 配置信息 + */ + @Select("select * from uf_comm_voucher where wfId in ($t{workflowIds})") + @CollectionMappings({ + @CollectionMapping( + property = "objectMappingDaoList", + column = "id", + id = @Id(value = Integer.class, methodId = 1) + ), + @CollectionMapping( + property = "nodeFieldMappingDaoList", + column = "id", + id = @Id(value = Integer.class,methodId = 2) + ) + }) + BaseConfigDao getConfigurationByWorkflowId(@ParamMapper("workflowIds") String workflowIds); + + + + /** + * 根据流程类型ID获取其对应的配置信息 + * @param workflowIds 流程类型ID + * @return 配置信息 + */ + @Select("select * from uf_comm_voucher where wfId in ($t{workflowIds}) and cusParamValue = #{cusParamValue}") + @CollectionMappings({ + @CollectionMapping( + property = "objectMappingDaoList", + column = "id", + id = @Id(value = Integer.class, methodId = 1) + ), + @CollectionMapping( + property = "nodeFieldMappingDaoList", + column = "id", + id = @Id(value = Integer.class,methodId = 2) + ) + }) + BaseConfigDao getConfigurationByWorkflowIdAndCondition(@ParamMapper("workflowIds") String workflowIds,@ParamMapper("cusParamValue") String cusParamValue); + + + + /** + * 获取对象与流程明细表映射配置信息 + * @param mainId 主表主键ID + * @return 映射详细信息 + */ + @Select("select * from uf_comm_voucher_dt1 where mainId = #{mainId}") + @CollectionMethod(value = 1,desc = "获取对象与流程明细表映射配置信息") + List getObjectMappingByMainKeyId(@ParamMapper("mainId") int mainId); + + + + /** + * 获取对象与流程明细表映射配置信息 + * @param mainId 主表主键ID + * @return 映射详细信息 + */ + @Select("select * from uf_comm_voucher_dt2 where mainId = #{mainId}") + @Associations({ + @Association( + property = "wfField", + column = "wfField", + select = "weaver.weilin.zhu.common.util.CommonUtil.getFieldDetailInfo", + id = @Id(Integer.class) + ) + }) + @CaseConversion(value = false) + @CollectionMethod(value = 2,desc = "获取节点名称与字段详细配置信息") + List getNodeFieldMappingByMainKeyId(@ParamMapper("mainId") int mainId); + + + + /** + * 查询流程主表的信息 + * @param billTableMain 明细表名称 + * @param requestId 流程请求D值 + * @return 查询结果数据集 + */ + @Select("select * from $t{billTableMain} where requestId = #{requestId}") + RecordSet getWorkflowMainTableInfo(@ParamMapper("billTableMain") String billTableMain,@ParamMapper("requestId") String requestId); + + + /** + * 查询流程主表的信息 + * @param billTableMain 明细表名称 + * @param requestId 流程请求D值 + * @return 查询结果数据集 + */ + @Select("select * from $t{billTableMain} where requestId = #{requestId} and $t{condition}") + RecordSet getWorkflowMainTableInfoAndCondition(@ParamMapper("billTableMain") String billTableMain,@ParamMapper("requestId") String requestId,@ParamMapper("condition") String condition); + + + + /** + * 查询流程某个明细表的信息 + * @param detailTableName 明细表名称 + * @param mainId 流程主表主键ID值 + * @return 查询结果数据集 + */ + @Select("select * from $t{detailTableName} where mainId = #{mainId}") + RecordSet getWorkflowDetailTableInfo(@ParamMapper("detailTableName") String detailTableName,@ParamMapper("mainId") String mainId); + + + /** + * 查询流程某个明细表的信息 + * @param detailTableName 明细表名称 + * @param mainId 流程主表主键ID值 + * @return 查询结果数据集 + */ + @Select("select * from $t{detailTableName} where mainId = #{mainId} and $t{condition}") + RecordSet getWorkflowDetailTableInfoAndCondition(@ParamMapper("detailTableName") String detailTableName,@ParamMapper("mainId") String mainId,@ParamMapper("condition") String condition); + + /** + * 更新流程表单字段信息 + * @param billTable 表单名称 + * @param backFieldName 回写字段名称 + * @param backFieldValue 回写字段值 + * @param requestId 流程请求ID + */ + @Update("update $t{billTable} set $t{backFieldName} = #{backFieldValue} where requestId = #{requestId}") + void resultBackToWorkflowBill(@ParamMapper("billTable") String billTable,@ParamMapper("backFieldName") String backFieldName,@ParamMapper("backFieldValue") String backFieldValue,@ParamMapper("requestId") String requestId); +} diff --git a/src/main/java/weaver/weilin/zhu/common/voucher/util/CommonVoucherUtil.java b/src/main/java/weaver/weilin/zhu/common/voucher/util/CommonVoucherUtil.java new file mode 100644 index 0000000..190076d --- /dev/null +++ b/src/main/java/weaver/weilin/zhu/common/voucher/util/CommonVoucherUtil.java @@ -0,0 +1,416 @@ +package weaver.weilin.zhu.common.voucher.util; + +import aiyh.utils.Util; +import com.alibaba.fastjson.JSONArray; +import com.alibaba.fastjson.JSONObject; +import org.apache.commons.lang3.StringUtils; +import weaver.conn.RecordSet; +import weaver.hrm.User; +import weaver.weilin.zhu.common.util.FieldDetailInfo; +import weaver.weilin.zhu.common.voucher.convert.FieldChangeRuleMethod; +import weaver.weilin.zhu.common.voucher.convert.RuleMethodParam; +import weaver.weilin.zhu.common.voucher.entity.BaseConfigDao; +import weaver.weilin.zhu.common.voucher.entity.NodeFieldMappingDao; +import weaver.weilin.zhu.common.voucher.entity.ObjectMappingDao; +import weaver.weilin.zhu.common.voucher.mapper.CommVoucherSqlMapper; +import weaver.workflow.workflow.WorkflowVersion; +import weaver.weilin.zhu.common.voucher.entity.VoucherConstants; +import weaver.zwl.common.ToolUtilNew; + +import java.util.Arrays; +import java.util.List; +import java.util.Map; + +/** + * 凭证通用功能 + * 凭证操作工具类 + * @author bleach + * @version 2023-07-10 + */ +public class CommonVoucherUtil { + + /** + * 数据操作接口 + */ + private final CommVoucherSqlMapper sqlMapper = Util.getMapper(CommVoucherSqlMapper.class); + + + /** + * 流程基础信息 + */ + private Map workflowBaseMap; + + /** + * 当前用户 + */ + private User thisUser; + + /** + * 对象与流程明细映射关系配置集合 + */ + private List objectMappingDaoList; + + /** + * 节点与流程字段配置集合 + */ + private List nodeFieldMappingDaoList; + + public CommonVoucherUtil() { + } + + /** + * 根据流程类型ID和自定义参数值,获取其对应的配置信息 + * @param workflowId 流程类型ID + * @param cusParamValue 自定义参数值 + * @return 配置信息 + */ + public BaseConfigDao getConfigurationByWorkflowId(String workflowId,String cusParamValue){ + BaseConfigDao dao = new BaseConfigDao(); + + //获取该流程类型对应的所有版本ID + String allWorkflowIds = WorkflowVersion.getAllVersionStringByWFIDs(workflowId); + + if(StringUtils.isNotBlank(cusParamValue)){ + dao = sqlMapper.getConfigurationByWorkflowIdAndCondition(allWorkflowIds,cusParamValue); + } else { + dao = sqlMapper.getConfigurationByWorkflowId(allWorkflowIds); + } + + return dao; + } + + /** + * 递归生成JSON对象 + * @param parentNode 父节点名称 + * @param rs 流程主表数据集 + * @param rs_detail 流程某个明细表某行数据集 + * @param dtIndex 明细序列 + * @param itemDirection 借贷方向 + * @param rowNum 明细序号 + * @return JSON对象 + */ + public JSONObject recursionGenerateJsonObject(String parentNode, RecordSet rs,RecordSet rs_detail, int dtIndex, int itemDirection,int rowNum){ + JSONObject jsonObject = new JSONObject(); + + for(NodeFieldMappingDao nodeFieldMappingDao : nodeFieldMappingDaoList){ + //节点名称 + String _nodeName = nodeFieldMappingDao.getNodeName(); + + if(StringUtils.isBlank(_nodeName)){ + continue; + } + + /* 父节点名称 */ + String _parentNode = nodeFieldMappingDao.getParentNode(); + + if(!_parentNode.equals(parentNode)){ + continue; + } + + int _nodeType = nodeFieldMappingDao.getNodeType(); + + if(itemDirection > 0){//说明为会计分录 + String _entriesDirection = nodeFieldMappingDao.getEntriesDirection(); + + if(!_entriesDirection.contains(String.valueOf(itemDirection))){//传进来的会计分录方向与当前不一致 + continue; + } + } + + //流程字段新 + FieldDetailInfo workflowField = nodeFieldMappingDao.getWfField(); + + if(workflowField != null){ + int _viewType = workflowField.getViewType(); + + int _detailIndex = workflowField.getDetailIndex(); + if(_viewType == 1 && _detailIndex != dtIndex){ + continue; + } + } + + RuleMethodParam param = new RuleMethodParam(); + param.setRs(rs); + param.setRs_detail(rs_detail); + param.setWorkflowBaseMap(workflowBaseMap); + param.setRowNum(rowNum); + param.setThisUser(thisUser); + + switch (_nodeType){ + case VoucherConstants.Node_Type_Comm_Text: + String nodeValue = FieldChangeRuleMethod.VALUE_RULE_FUNCTION.get(nodeFieldMappingDao.getChangeRule()).apply(nodeFieldMappingDao, param); + + if(nodeFieldMappingDao.getSpecialAttr() == 1 && Util.getDoubleValue(nodeValue,0.0) == 0){ + return null; + } + + jsonObject.put(_nodeName,nodeValue); + + break; + case VoucherConstants.Node_Type_Comm_Object: + JSONObject commObj = recursionGenerateJsonObject(_nodeName,rs,rs_detail,dtIndex,itemDirection,rowNum); + + jsonObject.put(_nodeName,commObj); + break; + case VoucherConstants.Node_Type_Array_Text: + JSONArray arrayText = new JSONArray(); + + String arrayTextValue = FieldChangeRuleMethod.VALUE_RULE_FUNCTION.get(nodeFieldMappingDao.getChangeRule()).apply(nodeFieldMappingDao,param); + + if(StringUtils.isNotBlank(arrayTextValue)){ + arrayText.addAll(Arrays.asList(Util.TokenizerString2(arrayTextValue, ","))); + } + + jsonObject.put(_nodeName,arrayText); + break; + case VoucherConstants.Node_Type_Array_Object: + + JSONArray itemArray = new JSONArray(); + + int _rowNum = 1; + + for(ObjectMappingDao objectMappingDao : objectMappingDaoList){ + String _objectName = objectMappingDao.getObjectName(); + + //别名 + String alias = objectMappingDao.getAlias(); + + if(!_objectName.equals(_nodeName) || (StringUtils.isNotBlank(alias) && !alias.equals(_nodeName))){//对象节点名称 与当前节点不一致 + continue; + } + + int _dtIndex = objectMappingDao.getDtIndex(); + + String _entriesDirection = objectMappingDao.getEntriesDirection(); + + //父节点名称 + String tmpParentNode = StringUtils.isNotBlank(alias) ? alias : _objectName; + + if(_dtIndex > 0){ + String dtCondition = objectMappingDao.getDtCondition(); + + RecordSet _rs_detail; + + //流程明细表名称 + String detailTable = Util.null2String(workflowBaseMap.get("billTableName")) + "_dt" + _dtIndex; + + if(StringUtils.isNotBlank(dtCondition)){ + dtCondition = ToolUtilNew.staticToDBC(dtCondition); + + _rs_detail = sqlMapper.getWorkflowDetailTableInfoAndCondition(detailTable,Util.null2String(workflowBaseMap.get("mainId")),dtCondition); + } else { + _rs_detail = sqlMapper.getWorkflowDetailTableInfo(detailTable,Util.null2String(workflowBaseMap.get("mainId"))); + } + + while(_rs_detail.next()){ + for(String direction : Util.TokenizerString2(_entriesDirection,",")) { + JSONObject itemObj = recursionGenerateJsonObject(tmpParentNode, rs, _rs_detail, _dtIndex, Util.getIntValue(direction), _rowNum++); + + if(itemObj == null || itemObj.isEmpty()){ + _rowNum--; + } else { + itemArray.add(itemObj); + } + } + } + } else {//说明信息来自主表 + for(String direction : Util.TokenizerString2(_entriesDirection,",")){ + JSONObject itemObj = recursionGenerateJsonObject(tmpParentNode,rs,null,0,Util.getIntValue(direction),_rowNum++); + + if(itemObj == null || itemObj.isEmpty()){ + _rowNum--; + } else { + itemArray.add(itemObj); + } + } + } + } + + jsonObject.put(_nodeName,itemArray); + + break; + } + } + + return jsonObject; + } + + /** + * 递归生成XML字符串 + * @param parentNode 父节点名称 + * @param rs 流程主表数据集 + * @param rs_detail 流程某个明细表某行数据集 + * @param dtIndex 明细序列 + * @param itemDirection 借贷方向 + * @param rowNum 明细序号 + * @return XML字符串 + */ + public StringBuilder recursionGenerateXML(String parentNode, RecordSet rs,RecordSet rs_detail, int dtIndex, int itemDirection,int rowNum){ + StringBuilder xmlBuilder = new StringBuilder(); + for(NodeFieldMappingDao nodeFieldMappingDao : nodeFieldMappingDaoList) { + //节点名称 + String _nodeName = nodeFieldMappingDao.getNodeName(); + + if (StringUtils.isBlank(_nodeName)) { + continue; + } + + //父节点名称 + String _parentNode = nodeFieldMappingDao.getParentNode(); + + if (!_parentNode.equals(parentNode)) { + continue; + } + + int _nodeType = nodeFieldMappingDao.getNodeType(); + + if (itemDirection > 0) {//说明为会计分录 + String _entriesDirection = nodeFieldMappingDao.getEntriesDirection(); + + if (!_entriesDirection.contains(String.valueOf(itemDirection))) {//传进来的会计分录方向与当前不一致 + continue; + } + } + + //流程字段新 + FieldDetailInfo workflowField = nodeFieldMappingDao.getWfField(); + + if (workflowField != null) { + int _viewType = workflowField.getViewType(); + + int _detailIndex = workflowField.getDetailIndex(); + if (_viewType == 1 && _detailIndex != dtIndex) { + continue; + } + } + + RuleMethodParam param = new RuleMethodParam(); + param.setRs(rs); + param.setRs_detail(rs_detail); + param.setWorkflowBaseMap(workflowBaseMap); + param.setRowNum(rowNum); + param.setThisUser(thisUser); + + switch (_nodeType) { + case VoucherConstants.Node_Type_Comm_Text: + String nodeValue = FieldChangeRuleMethod.VALUE_RULE_FUNCTION.get(nodeFieldMappingDao.getChangeRule()).apply(nodeFieldMappingDao, param); + + if (nodeFieldMappingDao.getSpecialAttr() == 1 && Util.getDoubleValue(nodeValue, 0.0) == 0) { + return null; + } + xmlBuilder.append("<").append(_nodeName).append(">"); + xmlBuilder.append(nodeValue); + xmlBuilder.append("\n"); + break; + case VoucherConstants.Node_Type_Array_Text: + break; + + case VoucherConstants.Node_Type_Comm_Object: + StringBuilder innerXML = recursionGenerateXML(_nodeName,rs,rs_detail,dtIndex,itemDirection,rowNum); + xmlBuilder.append("<").append(_nodeName).append(">"); + xmlBuilder.append(innerXML); + xmlBuilder.append("\n"); + break; + + case VoucherConstants.Node_Type_Array_Object: + int _rowNum = 1; + + for(ObjectMappingDao objectMappingDao : objectMappingDaoList) { + String _objectName = objectMappingDao.getObjectName(); + + //别名 + String alias = objectMappingDao.getAlias(); + + if (!_objectName.equals(_nodeName) || (StringUtils.isNotBlank(alias) && !alias.equals(_nodeName))) {//对象节点名称 与当前节点不一致 + continue; + } + + int _dtIndex = objectMappingDao.getDtIndex(); + + String _entriesDirection = objectMappingDao.getEntriesDirection(); + + //父节点名称 + String tmpParentNode = StringUtils.isNotBlank(alias) ? alias : _objectName; + + if (_dtIndex > 0) { + String dtCondition = objectMappingDao.getDtCondition(); + + RecordSet _rs_detail; + + //流程明细表名称 + String detailTable = Util.null2String(workflowBaseMap.get("billTableName")) + "_dt" + _dtIndex; + + if (StringUtils.isNotBlank(dtCondition)) { + dtCondition = ToolUtilNew.staticToDBC(dtCondition); + + _rs_detail = sqlMapper.getWorkflowDetailTableInfoAndCondition(detailTable, Util.null2String(workflowBaseMap.get("mainId")), dtCondition); + } else { + _rs_detail = sqlMapper.getWorkflowDetailTableInfo(detailTable, Util.null2String(workflowBaseMap.get("mainId"))); + } + + while (_rs_detail.next()) { + for (String direction : Util.TokenizerString2(_entriesDirection, ",")) { + StringBuilder innerItem = recursionGenerateXML(tmpParentNode,rs,_rs_detail,_dtIndex,Util.getIntValue(direction),_rowNum); + + if(innerItem != null && innerItem.length() > 0){ + xmlBuilder.append("<").append(_nodeName).append(">"); + xmlBuilder.append(innerItem); + xmlBuilder.append("\n"); + } else { + _rowNum--; + } + } + } + } else { //说明数据来自主表 + for(String direction : Util.TokenizerString2(_entriesDirection,",")){ + StringBuilder innerItem = recursionGenerateXML(tmpParentNode,rs,null,0,Util.getIntValue(direction),_rowNum++); + + if(innerItem != null && innerItem.length() > 0){ + xmlBuilder.append("<").append(_nodeName).append(">"); + xmlBuilder.append(innerItem); + xmlBuilder.append("\n"); + } else { + _rowNum--; + } + } + } + } + + break; + } + } + return xmlBuilder; + } + + public User getThisUser() { + return thisUser; + } + + public void setThisUser(User thisUser) { + this.thisUser = thisUser; + } + + public Map getWorkflowBaseMap() { + return workflowBaseMap; + } + + public void setWorkflowBaseMap(Map workflowBaseMap) { + this.workflowBaseMap = workflowBaseMap; + } + + public List getObjectMappingDaoList() { + return objectMappingDaoList; + } + + public void setObjectMappingDaoList(List objectMappingDaoList) { + this.objectMappingDaoList = objectMappingDaoList; + } + + public List getNodeFieldMappingDaoList() { + return nodeFieldMappingDaoList; + } + + public void setNodeFieldMappingDaoList(List nodeFieldMappingDaoList) { + this.nodeFieldMappingDaoList = nodeFieldMappingDaoList; + } +} diff --git a/src/main/java/weaver/weilin/zhu/xyzq/scheduled/sqlmapper/OrganizationSyncSqlMapper.java b/src/main/java/weaver/weilin/zhu/xyzq/scheduled/sqlmapper/OrganizationSyncSqlMapper.java index b75d680..f3ade99 100644 --- a/src/main/java/weaver/weilin/zhu/xyzq/scheduled/sqlmapper/OrganizationSyncSqlMapper.java +++ b/src/main/java/weaver/weilin/zhu/xyzq/scheduled/sqlmapper/OrganizationSyncSqlMapper.java @@ -48,7 +48,7 @@ public interface OrganizationSyncSqlMapper { @Association( property = "modeField", column = "modeField", - select = "weaver.common.util.CommonUtil.getFieldInfo", + select = "weaver.weilin.zhu.common.util.CommonUtil.getFieldDetailInfo", id = @Id(Integer.class) ) }) diff --git a/src/main/java/weaver/weilin/zhu/xyzq/scheduled/task/SyncOrgDataTask.java b/src/main/java/weaver/weilin/zhu/xyzq/scheduled/task/SyncOrgDataTask.java index a6e2c5a..b424c23 100644 --- a/src/main/java/weaver/weilin/zhu/xyzq/scheduled/task/SyncOrgDataTask.java +++ b/src/main/java/weaver/weilin/zhu/xyzq/scheduled/task/SyncOrgDataTask.java @@ -22,7 +22,6 @@ public class SyncOrgDataTask extends BaseCronJob { public void execute() { if(StringUtils.isNotBlank(keyId)){ OrganizationSyncUtil syncUtil = new OrganizationSyncUtil(); - syncUtil.syncData(Util.getIntValue(keyId,0)); } } diff --git a/src/main/jinwei_tao_old_src/com/api/taojw/common/action/RequestDataToApiAction.java b/src/main/jinwei_tao_old_src/com/api/taojw/common/action/RequestDataToApiAction.java index a9d2b8e..8fcdd87 100644 --- a/src/main/jinwei_tao_old_src/com/api/taojw/common/action/RequestDataToApiAction.java +++ b/src/main/jinwei_tao_old_src/com/api/taojw/common/action/RequestDataToApiAction.java @@ -67,7 +67,7 @@ public class RequestDataToApiAction implements Action { } catch (Exception e) { requestInfo.getRequestManager().setMessageid("2022052791002"); requestInfo.getRequestManager().setMessagecontent("Action接口发生异常,requestId:"+ requestId +",请联系管理员!"); - logger.error("VoucherAction.select * from workflow_requestBase error;requestId:" + requestId + "exception:" + e.getMessage() + ";e:" + e); + logger.error("CommonVoucherAction.select * from workflow_requestBase error;requestId:" + requestId + "exception:" + e.getMessage() + ";e:" + e); return Action.FAILURE_AND_CONTINUE; } //获取当前流程信息 diff --git a/src/main/jinwei_tao_old_src/weaver/taojw/common/action/RequestDataToApiAction.java b/src/main/jinwei_tao_old_src/weaver/taojw/common/action/RequestDataToApiAction.java index 68fa61b..c527a91 100644 --- a/src/main/jinwei_tao_old_src/weaver/taojw/common/action/RequestDataToApiAction.java +++ b/src/main/jinwei_tao_old_src/weaver/taojw/common/action/RequestDataToApiAction.java @@ -66,7 +66,7 @@ public class RequestDataToApiAction implements Action { } catch (Exception e) { requestInfo.getRequestManager().setMessageid("2022052791002"); requestInfo.getRequestManager().setMessagecontent("Action接口发生异常,requestId:"+ requestId +",请联系管理员!"); - logger.error("VoucherAction.select * from workflow_requestBase error;requestId:" + requestId + "exception:" + e.getMessage() + ";e:" + e); + logger.error("CommonVoucherAction.select * from workflow_requestBase error;requestId:" + requestId + "exception:" + e.getMessage() + ";e:" + e); return Action.FAILURE_AND_CONTINUE; } //获取当前流程信息