From 5ff8e00b794ff2f7559c8762d2d8d695a863b602 Mon Sep 17 00:00:00 2001 From: "weilin.zhu" Date: Thu, 6 Jul 2023 16:27:52 +0800 Subject: [PATCH] =?UTF-8?q?=E4=B8=AD=E5=9B=BD=E8=88=B9=E8=88=B6=E5=B7=A5?= =?UTF-8?q?=E4=B8=9A=E5=87=AD=E8=AF=81=E6=8E=A5=E5=8F=A3=E5=BC=80=E5=8F=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../cssc/formmode/PushNcModeExpand.java | 147 ++++++ .../schedule/cron/PushEmployeeCronJob.java | 106 +++++ .../schedule/cron/PushModeDataCronJob.java | 88 ++++ .../schedule/sqlmapper/PushDataSqlMapper.java | 119 +++++ .../cssc/schedule/util/PushModeDataUtil.java | 144 ++++++ .../voucher/action/VoucherPushAction.java | 227 ++++++++++ .../voucher/sqlmapper/VoucherSqlMapper.java | 120 +++++ .../voucher/util/InterfaceLoggerDao.java | 80 ++++ .../voucher/util/VoucherConstants.java | 94 ++++ .../workflow/voucher/util/VoucherUtil.java | 367 +++++++++++++++ .../java/weaver/zwl/common/ToolUtilNew.java | 426 ++++++++++++++++++ 11 files changed, 1918 insertions(+) create mode 100644 src/main/java/weaver/cssc/formmode/PushNcModeExpand.java create mode 100644 src/main/java/weaver/cssc/schedule/cron/PushEmployeeCronJob.java create mode 100644 src/main/java/weaver/cssc/schedule/cron/PushModeDataCronJob.java create mode 100644 src/main/java/weaver/cssc/schedule/sqlmapper/PushDataSqlMapper.java create mode 100644 src/main/java/weaver/cssc/schedule/util/PushModeDataUtil.java create mode 100644 src/main/java/weaver/cssc/workflow/voucher/action/VoucherPushAction.java create mode 100644 src/main/java/weaver/cssc/workflow/voucher/sqlmapper/VoucherSqlMapper.java create mode 100644 src/main/java/weaver/cssc/workflow/voucher/util/InterfaceLoggerDao.java create mode 100644 src/main/java/weaver/cssc/workflow/voucher/util/VoucherConstants.java create mode 100644 src/main/java/weaver/cssc/workflow/voucher/util/VoucherUtil.java create mode 100644 src/main/java/weaver/zwl/common/ToolUtilNew.java diff --git a/src/main/java/weaver/cssc/formmode/PushNcModeExpand.java b/src/main/java/weaver/cssc/formmode/PushNcModeExpand.java new file mode 100644 index 0000000..63bf5d4 --- /dev/null +++ b/src/main/java/weaver/cssc/formmode/PushNcModeExpand.java @@ -0,0 +1,147 @@ +package weaver.cssc.formmode; + +import aiyh.utils.Util; +import aiyh.utils.httpUtil.HttpArgsType; +import aiyh.utils.httpUtil.ResponeVo; +import aiyh.utils.httpUtil.util.HttpUtils; +import cn.hutool.json.JSONUtil; +import com.alibaba.fastjson.JSONObject; +import org.apache.commons.lang3.StringUtils; +import org.apache.log4j.Logger; +import weaver.cssc.schedule.util.PushModeDataUtil; +import weaver.cssc.workflow.voucher.util.VoucherConstants; +import weaver.formmode.customjavacode.AbstractModeExpandJavaCodeNew; +import weaver.hrm.User; +import weaver.soa.workflow.request.RequestInfo; +import weaver.zwl.common.ToolUtilNew; + +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +/** + * 中国船舶工业 + * 建模数据推送NC 页面扩展 + * @author bleach + * @Date 2023-06-19 + */ +public class PushNcModeExpand extends AbstractModeExpandJavaCodeNew { + + /** + * 日志操作类 + */ + private final Logger logger = Util.getLogger(); + + /** + * 执行模块扩展动作 + * @param param 参数集合 + * param包含(但不限于)以下数据 + * user 当前用户 + * importtype 导入方式(仅在批量导入的接口动作会传输) 1 追加,2覆盖,3更新,获取方式(int)param.get("importtype") + * 导入链接中拼接的特殊参数(仅在批量导入的接口动作会传输),比如a=1,可通过param.get("a")获取参数值 + * 页面链接拼接的参数,比如b=2,可以通过param.get("b")来获取参数 + * @return 返回扩展操作结果 + */ + @Override + public Map doModeExpand(Map param) { + logger.info("-----------PushNcModeExpand Begin ------"); + + Map result = new HashMap<>(); + try { + User user = (User)param.get("user"); + int billId = -1;//数据id + int modeId = -1;//模块id + + RequestInfo requestInfo = (RequestInfo)param.get("RequestInfo"); + if(requestInfo != null) { + billId = Util.getIntValue(requestInfo.getRequestid()); + modeId = Util.getIntValue(requestInfo.getWorkflowid()); + + logger.info("modeId:[" + modeId + "],billId:[" + billId + "]"); + + if (billId > 0 && modeId > 0) { + //------请在下面编写业务逻辑代码------ + PushModeDataUtil dataUtil = new PushModeDataUtil(); + + //获取当前模块对应配置 + Map configMap = dataUtil.getConfigurationByModeId(modeId); + + logger.info("配置信息:[" + JSONUtil.toJsonPrettyStr(dataUtil) + "]"); + + //获取标识字段ID + int flagFieldId = Util.getIntValue(configMap.get("flagField").toString(),0); + //外键字段 + int foreignKeyId = Util.getIntValue(configMap.get("foreignKeyField").toString(),0); + + if(flagFieldId > 0){ + String flagFieldName = ToolUtilNew.getFieldNameByFieldIdStatic(flagFieldId); + + String foreignKeyName = ""; + if(foreignKeyId > 0){ + foreignKeyName = ToolUtilNew.getFieldNameByFieldIdStatic(foreignKeyId); + } + + //获取该模块对应的表名称 + String billTableName = (String) configMap.get("tableName"); + + //接口请求地址 + String requestURL = (String) configMap.get("requestURL"); + + if(StringUtils.isNotBlank(requestURL)){ + Map dataMap = dataUtil.getModeDataByKeyId(billTableName,flagFieldName,billId); + + logger.info("当前数据信息:[" + JSONUtil.toJsonPrettyStr(dataMap) + "]"); + + if(!dataMap.isEmpty()){ + List> fieldList = (List>) configMap.get("fieldList"); + + JSONObject jsonObject = dataUtil.generateJSONObject(fieldList,dataMap); + + HttpUtils httpUtils = new HttpUtils(); + + Map headerMap = new HashMap<>(); + headerMap.put("Content-Type", HttpArgsType.APPLICATION_JSON); + + ResponeVo responeVo = httpUtils.apiPostObject(requestURL,jsonObject,headerMap); + + if(responeVo.getCode() == VoucherConstants.REQUEST_SUCCESS_CODE){ + //接口返回信息转成Map对象 + Map resultMap = responeVo.getResponseMap(); + + int code = Util.getIntValue(Util.null2String(resultMap.get("code")),-1); + + boolean writeStatus; + if(code == 0){//成功 + String foreignKeyValue = (String) resultMap.get("pk"); + + writeStatus = dataUtil.writeBackStatus(true, billTableName, flagFieldName, foreignKeyName, foreignKeyValue, billId); + } else { + writeStatus = dataUtil.writeBackStatus(false,billTableName,flagFieldName,foreignKeyName,"",billId); + } + + logger.info("接口调用结果回写表单结果:[" + writeStatus + "]"); + } else { + logger.info("接口请求失败,失败状态码:[" + responeVo.getCode() + "]"); + } + } else { + logger.info("当前记录:[" + billId + "]不满足条件!"); + } + } + } else { + logger.info("推送标识字段未配置!"); + } + } + } + result.put("flag", "true"); + } catch (Exception e) { + logger.info(Util.getErrString(e)); + result.put("errmsg","自定义出错信息"); + result.put("flag", "false"); + } + + logger.info("-----------PushNcModeExpand End ------"); + return result; + } + + +} diff --git a/src/main/java/weaver/cssc/schedule/cron/PushEmployeeCronJob.java b/src/main/java/weaver/cssc/schedule/cron/PushEmployeeCronJob.java new file mode 100644 index 0000000..f248972 --- /dev/null +++ b/src/main/java/weaver/cssc/schedule/cron/PushEmployeeCronJob.java @@ -0,0 +1,106 @@ +package weaver.cssc.schedule.cron; + +import aiyh.utils.Util; +import aiyh.utils.httpUtil.HttpArgsType; +import aiyh.utils.httpUtil.ResponeVo; +import aiyh.utils.httpUtil.util.HttpUtils; +import org.apache.commons.lang3.StringUtils; +import org.apache.log4j.Logger; +import weaver.cssc.schedule.sqlmapper.PushDataSqlMapper; +import weaver.cssc.workflow.voucher.util.VoucherConstants; +import weaver.general.TimeUtil; +import weaver.interfaces.schedule.BaseCronJob; +import weaver.zwl.common.ToolUtilNew; + +import java.io.IOException; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +/** + * 中国船舶工业 + * 人员数据推送NC 计划任务类 + * @author bleach + * @Date 2023-06-25 + */ +public class PushEmployeeCronJob extends BaseCronJob { + + /** + * 日志操作 + */ + private final Logger logger = Util.getLogger(); + + /** + * SQL接口 + */ + private final PushDataSqlMapper sqlMapper = Util.getMapper(PushDataSqlMapper.class); + /** + * 实现父类 + * 具体的业务实现 + */ + @Override + public void execute() { + //获取上一次同步时间戳 + String lastSyncTs = ToolUtilNew.getStaticSystemParamValue("LastEmployeeSyncTimeStamp"); + + if(StringUtils.isBlank(lastSyncTs)){ + lastSyncTs = "2000-01-01 00:00:01"; + } + + //获取接口地址 + String pushEmployeeRequestURL = ToolUtilNew.getStaticSystemParamValue("EmployeePushRequestURL"); + + if(StringUtils.isBlank(pushEmployeeRequestURL)){ + logger.error("人员推送接口地址配置不存在!配置参数标识:[EmployeePushRequestURL]"); + } + + //获取当前库中需要推送的人员信息 + String selectSqL = "select id as code,lastName as name,certificateNum as id from hrmresource h where status in (0,1,2,3) and created >= '" + lastSyncTs + "' or modified >= '" + lastSyncTs + "'"; + + List> employeeList = sqlMapper.getEmployeeInfo(selectSqL); + + //发送Http请求工具类 + HttpUtils httpUtils = new HttpUtils(); + + if(employeeList != null && employeeList.size() > 0){//遍历结果集 + for(Map employeeMap : employeeList){ + + int keyId = (int) employeeMap.get("code"); + + Map header = new HashMap<>(); + header.put("Content-Type", HttpArgsType.APPLICATION_JSON); + + try { + ResponeVo responeVo = httpUtils.apiPostObject(pushEmployeeRequestURL,employeeMap,header); + + if(responeVo.getCode() == VoucherConstants.REQUEST_SUCCESS_CODE){ + Map resultMap = responeVo.getResponseMap(); + + if(!resultMap.isEmpty()){ + int code = (int) resultMap.get("code"); + + if(code == 1){ + String pk = (String) resultMap.get("pk"); + + sqlMapper.writeBackKeyToEmployee(pk,keyId); + } + } + } else { + //人员接口推送失败 + logger.error("人员接口推送失败,失败状态码:[" + responeVo.getCode() + "]"); + return; + } + } catch (IOException e) { + logger.info(Util.getErrString(e)); + throw new RuntimeException(e); + } + } + } + + //获取当前时间戳 + String currentTs = TimeUtil.getCurrentTimeString(); + + //更新时间戳至配置表中 + sqlMapper.updateTimeStampToConfig(currentTs); + } +} diff --git a/src/main/java/weaver/cssc/schedule/cron/PushModeDataCronJob.java b/src/main/java/weaver/cssc/schedule/cron/PushModeDataCronJob.java new file mode 100644 index 0000000..ca8c5a0 --- /dev/null +++ b/src/main/java/weaver/cssc/schedule/cron/PushModeDataCronJob.java @@ -0,0 +1,88 @@ +package weaver.cssc.schedule.cron; + +import aiyh.utils.Util; +import org.apache.commons.lang3.StringUtils; +import org.apache.log4j.Logger; +import weaver.conn.RecordSet; +import weaver.conn.constant.DBConstant; +import weaver.cssc.schedule.sqlmapper.PushDataSqlMapper; +import weaver.cssc.schedule.util.PushModeDataUtil; +import weaver.interfaces.schedule.BaseCronJob; +import weaver.zwl.common.ToolUtilNew; + +import java.util.List; +import java.util.Map; + +/** + * 中国船舶工业 + * 建模数据推送NC 计划任务类 + * @author bleach + * @Date 2023-06-19 + */ +public class PushModeDataCronJob extends BaseCronJob { + + /** + * 当前类日志 + */ + private final Logger logger = Util.getLogger(); + + /** + * 配置数据ID + */ + private String configId; + + /** + * 推送数据操作数据接口 + */ + private final PushDataSqlMapper sqlMapper = Util.getMapper(PushDataSqlMapper.class); + + /** + * 实现父类方法 + */ + @Override + public void execute() { + logger.info("-------------- PushModeDataCronJob BEGIN ---------------"); + + logger.info("configId:[" + configId + "]"); + + PushModeDataUtil dataUtil = new PushModeDataUtil(); + + //配置集合 + Map configMap = dataUtil.getConfigurationByKeyId(configId); + + if(configMap != null && configMap.size() > 0){ + //模块表名称 + String modeTable = Util.null2String(configMap.get("tableName")); + //获取标识字段 + int flagField = (int) configMap.get("flagField"); + + if(flagField > 0){ + //获取标识字段名称 + String flagFieldName = Util.null2String(ToolUtilNew.getFieldNameByFieldIdStatic(flagField)); + + if(StringUtils.isNotBlank(flagFieldName) && StringUtils.isNotBlank(modeTable)){ + //查询表中已数据集 + String selectSQL = "select * from " + modeTable + " where " + flagFieldName + " is null or " + flagFieldName + " in (0,2)"; + + //待推送数据集合 + List> dataList = sqlMapper.getTodoPushModeDataList(selectSQL); + + + } + } + } + + logger.info("-------------- PushModeDataCronJob END ---------------"); + } + + + + + public String getConfigId() { + return configId; + } + + public void setConfigId(String configId) { + this.configId = configId; + } +} diff --git a/src/main/java/weaver/cssc/schedule/sqlmapper/PushDataSqlMapper.java b/src/main/java/weaver/cssc/schedule/sqlmapper/PushDataSqlMapper.java new file mode 100644 index 0000000..1561c97 --- /dev/null +++ b/src/main/java/weaver/cssc/schedule/sqlmapper/PushDataSqlMapper.java @@ -0,0 +1,119 @@ +package weaver.cssc.schedule.sqlmapper; + +import aiyh.utils.annotation.recordset.*; + +import java.util.List; +import java.util.Map; + +/** + * 中国船舶工业 + * + * 建模数据推送NC生成SQL操作接口 + */ +@SqlMapper +public interface PushDataSqlMapper { + /** + * 获取建模数据推送NC配置 + * @param keyId 配置数据ID + * @return 配置信息集合 + */ + @CaseConversion(value = false) + @Select("select wb.tableName,u.* from uf_modeToNc u inner join modeInfo m on u.modeId = m.id \n" + + "inner join workflow_bill wb on m.formid = wb.id where u.id = #{keyId}") + Map getPushDataConfiguration(@ParamMapper("keyId") String keyId); + + /** + * 根据模块ID获取其对应的表单名称 + * @param modeId 模块ID + * @return 表单名称 + */ + @Select("select wb.tableName from modeInfo m inner join workflow_bill wb on m.formid = wb.id where m.id = #{modeId}") + String getTableNameByModeId(@ParamMapper("modeId") int modeId); + + /** + * 获取建模数据推送NC配置 + * @param modeId 模块ID + * @return 配置信息集合 + */ + @CaseConversion(value = false) + @Select("select wb.tableName,u.* from uf_modeToNc u inner join modeInfo m on u.modeId = m.id \n" + + "inner join workflow_bill wb on m.formid = wb.id where u.modeId = #{modeId}") + Map getPushDataConfigurationByModeId(@ParamMapper("modeId") int modeId); + + /** + * 获取建模数据推送NC配置明细 + * @param mainId 配置主表主键ID + * @return 配置信息集合 + */ + @CaseConversion(value = false) + @Select("select dt.*,wb.fieldName from uf_modeToNc_dt1 dt left join workflow_billfield wb on dt.mField = wb.id where mainId = #{mainId}") + List> getPushDataDetailConfiguration(@ParamMapper("mainId") int mainId); + + + /** + * 查询某条待推送数据的详细信息 + * @param sql 自定义SQL + * @return 待推送数据集合 + */ + @CaseConversion(value = false) + @Select(custom = true) + Map getTodoPushModeDataInfo(@SqlString String sql); + + /** + * 查询待推送的数据 + * @param sql 自定义SQL + * @return 待推送数据集合 + */ + @CaseConversion(value = false) + @Select(custom = true) + List> getTodoPushModeDataList(@SqlString String sql); + + + /** + * 回写成功状态至模块数据 + * @param billTable 模块表名称 + * @param flagFieldName 标识字段名称 + * @param foreignKeyName 外键字段名称 + * @param foreignKeyValue 外键字段值 + * @param keyId 数据ID + * @return 回写结果 + */ + @Update("update $t{billTable} set $t{flagFieldName} = 1,$t{foreignKeyName}=#{foreignKeyValue} where id = #{keyId}") + boolean writeBackSuccess(@ParamMapper("billTable") String billTable,@ParamMapper("flagFieldName") String flagFieldName,@ParamMapper("foreignKeyName") String foreignKeyName,@ParamMapper("foreignKeyValue") String foreignKeyValue,@ParamMapper("keyId") int keyId); + + + /** + * 回写失败状态至模块数据 + * @param billTable 模块表名称 + * @param flagFieldName 标识字段名称 + * @param keyId 数据ID + * @return 回写结果 + */ + @Update("update $t{billTable} set $t{flagFieldName} = 2 where id = #{keyId}") + boolean writeBackFailure(@ParamMapper("billTable") String billTable,@ParamMapper("flagFieldName") String flagFieldName,@ParamMapper("keyId") int keyId); + + + /** + * 查询人员信息 + * @param sql 查询信息SQL + * @return 返回满足条件的人员信息 + */ + @CaseConversion(value = false) + @Select(custom = true) + List> getEmployeeInfo(@SqlString String sql); + + /** + * 外键值更新至人员表自定义字段5中 + * @param pk 外键值 + * @param keyId 人员ID + */ + @Update("update hrmresource set textField5 = #{pk} where id = #{keyId}") + void writeBackKeyToEmployee(@ParamMapper("pk") String pk,@ParamMapper("keyId") int keyId); + + /** + * 更新时间戳至系统配置表中 + * @param timeStamp 时间戳 + */ + @Update("update uf_systemConfig set paramValue = #{timeStamp} where uuid = 'LastEmployeeSyncTimeStamp'") + void updateTimeStampToConfig(@ParamMapper("timeStamp") String timeStamp); +} diff --git a/src/main/java/weaver/cssc/schedule/util/PushModeDataUtil.java b/src/main/java/weaver/cssc/schedule/util/PushModeDataUtil.java new file mode 100644 index 0000000..279df99 --- /dev/null +++ b/src/main/java/weaver/cssc/schedule/util/PushModeDataUtil.java @@ -0,0 +1,144 @@ +package weaver.cssc.schedule.util; + +import aiyh.utils.Util; +import com.alibaba.fastjson.JSONObject; +import org.apache.commons.lang3.StringUtils; +import weaver.cssc.schedule.sqlmapper.PushDataSqlMapper; +import weaver.general.TimeUtil; +import weaver.zwl.common.ToolUtilNew; + +import java.util.List; +import java.util.Map; + +/** + * 中国船舶工业 + * 建模数据推送NC工具类 + * @author bleach + * @Date 2023-06-19 + */ +public class PushModeDataUtil { + + /** + * 数据库操作接口 + */ + private final PushDataSqlMapper sqlMapper = Util.getMapper(PushDataSqlMapper.class); + + + /** + * 获取某个模块对应的配置 + * @param keyId 配置ID + * @return 配置集合 + */ + 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; + } + + /** + * 获取某个模块对应的配置 + * @param modeId 模块ID + * @return 配置集合 + */ + public Map getConfigurationByModeId(int modeId){ + Map configMap = sqlMapper.getPushDataConfigurationByModeId(modeId); + + if(configMap != null && configMap.size() > 0){ + int mainKeyId = (int) configMap.get("id"); + + List> fieldList = sqlMapper.getPushDataDetailConfiguration(mainKeyId); + + configMap.put("fieldList",fieldList); + } + + return configMap; + } + + + /** + * 根据配置生成要发送的JSON对象 + * @param fieldList 字段配置集合 + * @param dataMap 表单数据 + * @return 生成的JSON对象 + */ + public JSONObject generateJSONObject(List> fieldList,Map dataMap){ + JSONObject jsonObject = new JSONObject(); + + for(Map fieldMap : fieldList){ + //JSON节点名称 + String nodeName = Util.null2String(fieldMap.get("nodeName")); + //建模字段名称 + String fieldName = Util.null2String(fieldMap.get("fieldName")); + //转换规则 + int changeRule = (int) fieldMap.get("changeRule"); + //自定义规则 + String cusSQL = Util.null2String(fieldMap.get("cusSQL")); + + //字段值 + String fieldValue = ""; + if(StringUtils.isNotBlank(fieldName) && dataMap.containsKey(fieldName)){ + fieldValue = Util.null2String(dataMap.get(fieldName)); + } + + //数据ID 系统日期 系统日期时间 固定值 自定义规则 + switch (changeRule){ + case 0 ://不转换 + break; + case 1 ://数据ID + fieldValue = Util.null2String(dataMap.get("id")); + break; + case 2 ://系统日期 + fieldValue = TimeUtil.getCurrentDateString(); + break; + case 3 ://系统日期时间 + fieldValue = TimeUtil.getCurrentTimeString(); + break; + case 4 ://固定值 + fieldValue = cusSQL; + break; + case 5 ://自定义SQL + fieldValue = ToolUtilNew.getStaticValueByChangeRule(cusSQL,fieldValue); + break; + } + + jsonObject.put(nodeName,fieldValue); + } + + return jsonObject; + } + + /** + * 根据模块ID获取其对应的表单数据信息 + * @param keyId 模块数据ID + * @return 表单名称 + */ + public Map getModeDataByKeyId(String modeTableName,String flagFieldName,int keyId){ + //查询表中已数据集 + String selectSQL = "select * from " + modeTableName + " where id = " + keyId + " and (" + flagFieldName + " is null or " + flagFieldName + " in (0,2))"; + return sqlMapper.getTodoPushModeDataInfo(selectSQL); + } + + /** + * 回写接口调用状态至模块中 + * @param isSuccess 是否成功 + * @param billTableName 模块表单名称 + * @param flagFieldName 标识字段名称 + * @param keyId 数据ID + * @return 更新成功与否 + */ + public boolean writeBackStatus(boolean isSuccess,String billTableName,String flagFieldName,String foreignKeyName,String foreignKeyValue,int keyId){ + if(isSuccess){ + return sqlMapper.writeBackSuccess(billTableName,flagFieldName,foreignKeyName,foreignKeyValue,keyId); + } else { + return sqlMapper.writeBackFailure(billTableName,flagFieldName,keyId); + } + } +} diff --git a/src/main/java/weaver/cssc/workflow/voucher/action/VoucherPushAction.java b/src/main/java/weaver/cssc/workflow/voucher/action/VoucherPushAction.java new file mode 100644 index 0000000..3f7f944 --- /dev/null +++ b/src/main/java/weaver/cssc/workflow/voucher/action/VoucherPushAction.java @@ -0,0 +1,227 @@ +package weaver.cssc.workflow.voucher.action; + +import aiyh.utils.Util; +import aiyh.utils.action.SafeCusBaseAction; +import aiyh.utils.httpUtil.HttpArgsType; +import aiyh.utils.httpUtil.ResponeVo; +import aiyh.utils.httpUtil.util.HttpUtils; +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.cssc.workflow.voucher.sqlmapper.VoucherSqlMapper; +import weaver.cssc.workflow.voucher.util.InterfaceLoggerDao; +import weaver.cssc.workflow.voucher.util.VoucherConstants; +import weaver.cssc.workflow.voucher.util.VoucherUtil; +import weaver.general.TimeUtil; +import weaver.hrm.User; +import weaver.soa.workflow.request.RequestInfo; +import weaver.zwl.common.ToolUtilNew; + +import java.io.IOException; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + + +/** + * 中国船舶工业 + * 流程数据推送NC生成凭证Action + * @author bleach + * @Date 2023-06-19 + */ +public class VoucherPushAction extends SafeCusBaseAction { + + /** + * 日志操作类 + */ + private final Logger logger = Util.getLogger(); + + /** + * 自定义参数 + */ + private String cusParamValue = ""; + + /** + * 操作数据接口 + */ + private final VoucherSqlMapper sqlMapper = Util.getMapper(VoucherSqlMapper.class); + + /** + * 流程提交方法执行Action + * 具体的业务实现 + * @param requestId 流程请求ID + * @param billTable 流程表单名称 + * @param workflowId 流程类型ID + * @param user 当前用户 + * @param requestInfo 流程请求信息 + */ + @SuppressWarnings("unchecked") + @Override + public void doSubmit(String requestId, String billTable, int workflowId, User user, RequestInfo requestInfo) { + logger.info("---------------- VoucherPushAction Begin -------------"); + + InterfaceLoggerDao interfaceLoggerDao = new InterfaceLoggerDao(); + + interfaceLoggerDao.setWorkflowId(workflowId); + interfaceLoggerDao.setSourceRequestId(requestId); + interfaceLoggerDao.setOperateDateTime(TimeUtil.getCurrentTimeString()); + + logger.info("workflowId:[" + workflowId + "],requestId:[" + requestId + "],billTable:[" + billTable + "]"); + VoucherUtil voucherUtil = new VoucherUtil(); + + Map configMap = voucherUtil.getConfigurationByWorkflowId(String.valueOf(workflowId),cusParamValue); + + if(configMap != null && configMap.size() > 0){ + //获取数据条件 + String dataCondition = (String) configMap.get("dataCondition"); + + RecordSet rs ; + + if(StringUtils.isNotBlank(dataCondition)){ + dataCondition = ToolUtilNew.staticToDBC(dataCondition); + + rs = sqlMapper.getWorkflowMainInfoAndCusWhere(billTable,requestId,dataCondition); + } else { + rs = sqlMapper.getWorkflowMainInfo(billTable,requestId); + } + + int mainId = -1; + if(rs.next()){ + mainId = Util.getIntValue(rs.getString("id"),-1); + } + + if(mainId > -1){ + //流程请求标题 + String requestName = ""; + //流程请求编号 + String requestMark = ""; + + //获取流程基础信息 + RecordSetTrans rsts = requestInfo.getRsTrans(); + + if(rsts == null){ + rsts = new RecordSetTrans(); + } + + try { + if(rsts.executeQuery("select * from workflow_requestBase where requestId = ?",requestId)){ + if(rsts.next()){ + requestName = Util.null2String(rsts.getString("requestName")); + requestMark = Util.null2String(rsts.getString("requestMark")); + } + } + } catch (Exception e) { + Util.actionFailException(requestInfo.getRequestManager(),"获取流程基本信息异常,异常信息:[" + e.getMessage() + "]!"); + throw new RuntimeException(e); + } + + interfaceLoggerDao.setRequestNo(requestMark); + interfaceLoggerDao.setOperator(user.getUID()); + + List> fieldList = (List>) configMap.get("fieldList"); + List> detailList = (List>) configMap.get("detailList"); + + voucherUtil.setDetailList(detailList); + voucherUtil.setFieldList(fieldList); + + //流程基础信息集合[流程请求ID,流程请求标题,流程请求编号,流程表单名称,主表数据ID] + String[] baseArray = new String[]{requestId,requestName,requestMark,billTable,String.valueOf(mainId)}; + + //根据配置生成JSON对象 + JSONObject jsonObject = voucherUtil.recursionGenerateJSONObject(baseArray,rs,null, 0,"",0,0); + + logger.info("生成JSON字符串为:[" + jsonObject.toJSONString() + "]"); + + interfaceLoggerDao.setRequestBody(jsonObject.toJSONString()); + + //NC凭证接口地址 + String voucherRequestURL = ToolUtilNew.getStaticSystemParamValue("NC_VoucherRequestURL"); + + if(StringUtils.isNotBlank(voucherRequestURL)){ + HttpUtils httpUtils = new HttpUtils(); + + try { + Map headerMap = new HashMap<>(); + headerMap.put("Content-Type", HttpArgsType.APPLICATION_JSON); + + ResponeVo responeVo = httpUtils.apiPostObject(voucherRequestURL,jsonObject,headerMap); + + if(responeVo.getCode() == VoucherConstants.REQUEST_SUCCESS_CODE){ + //获取返回信息 + String result = responeVo.getEntityString(); + + interfaceLoggerDao.setResponseBody(result); + + JSONObject resultObj = JSONObject.parseObject(result); + + if(resultObj.containsKey("code")){ + int code = resultObj.getIntValue("code"); + + if(code == 0){ + String pk = resultObj.getString("pk"); + + String backFieldName = (String) configMap.get("backFieldName"); + if(StringUtils.isNotBlank(backFieldName)){ + sqlMapper.backVoucherNoToBill(billTable,backFieldName,pk,requestId); + } + + interfaceLoggerDao.setDealStatus(VoucherConstants.DEAL_STATUS_SUCCESS); + interfaceLoggerDao.setDealMessage("接口调用成功!"); + } else { + String message = resultObj.getString("msg"); + + interfaceLoggerDao.setDealStatus(VoucherConstants.DEAL_STATUS_FAILURE); + interfaceLoggerDao.setDealMessage("调用NC凭证接口失败,失败状态码:[" + message + "]!"); + interfaceLoggerDao.insertInterfaceLog(interfaceLoggerDao); + //接口调用失败 + Util.actionFailException(requestInfo.getRequestManager(),"调用NC凭证接口失败,失败状态码:[" + message + "]!"); + } + } else { + interfaceLoggerDao.setDealStatus(VoucherConstants.DEAL_STATUS_FAILURE); + interfaceLoggerDao.setDealMessage("调用NC凭证接口失败,接口返回信息为空!"); + } + } else { + interfaceLoggerDao.setDealStatus(VoucherConstants.DEAL_STATUS_FAILURE); + interfaceLoggerDao.setDealMessage("调用NC凭证接口失败,失败状态码:[" + responeVo.getCode() + "]!"); + interfaceLoggerDao.insertInterfaceLog(interfaceLoggerDao); + Util.actionFailException(requestInfo.getRequestManager(),"调用NC凭证接口失败,失败状态码:[" + responeVo.getCode() + "]!"); + } + } catch (IOException e) { + interfaceLoggerDao.setDealStatus(VoucherConstants.DEAL_STATUS_FAILURE); + interfaceLoggerDao.setDealMessage("调用NC凭证接口异常,异常信息:" + e.getMessage()); + interfaceLoggerDao.insertInterfaceLog(interfaceLoggerDao); + logger.error(Util.getErrString(e)); + Util.actionFailException(requestInfo.getRequestManager(),"调用NC凭证接口异常!"); + //throw new RuntimeException(e); + } + } else { + interfaceLoggerDao.setDealStatus(VoucherConstants.DEAL_STATUS_NO_DEAL); + interfaceLoggerDao.setDealMessage("NC凭证接口地址未配置!"); + interfaceLoggerDao.insertInterfaceLog(interfaceLoggerDao); + Util.actionFailException(requestInfo.getRequestManager(),"NC凭证接口地址未配置!"); + } + } else { + interfaceLoggerDao.setDealStatus(VoucherConstants.DEAL_STATUS_NO_DEAL); + interfaceLoggerDao.setDealMessage("当前流程不满足自定义条件:[" + dataCondition + "]"); + logger.info("当前流程不满足自定义条件:[" + dataCondition + "]"); + } + } else { + interfaceLoggerDao.setDealStatus(VoucherConstants.DEAL_STATUS_NO_DEAL); + interfaceLoggerDao.setDealMessage("该流程自定义参数值[" + cusParamValue + "]对应的配置不存在!"); + logger.info("该流程自定义参数值[" + cusParamValue + "]对应的配置不存在!"); + } + + interfaceLoggerDao.insertInterfaceLog(interfaceLoggerDao); + logger.info("---------------- VoucherPushAction End -------------"); + } + + public String getCusParamValue() { + return cusParamValue; + } + + public void setCusParamValue(String cusParamValue) { + this.cusParamValue = cusParamValue; + } +} diff --git a/src/main/java/weaver/cssc/workflow/voucher/sqlmapper/VoucherSqlMapper.java b/src/main/java/weaver/cssc/workflow/voucher/sqlmapper/VoucherSqlMapper.java new file mode 100644 index 0000000..110989d --- /dev/null +++ b/src/main/java/weaver/cssc/workflow/voucher/sqlmapper/VoucherSqlMapper.java @@ -0,0 +1,120 @@ +package weaver.cssc.workflow.voucher.sqlmapper; + +import aiyh.utils.annotation.recordset.*; +import weaver.conn.RecordSet; +import weaver.cssc.workflow.voucher.util.InterfaceLoggerDao; + +import java.util.List; +import java.util.Map; + +/** + * 中国船舶工业 + * 流程数据推送NC生成凭证 SQL操作接口 + */ +@SqlMapper +public interface VoucherSqlMapper { + + /** + * 根据类型类型ID获取其对应的配置信息 + * @param allWorkflowId 流程类型ID + * @return 返回数据集 + */ + @CaseConversion(value = false) + @Select("select * from uf_wfDataToNCVoucher where wfId in ($t{allWorkflowId})") + Map getConfigurationByWorkflowId(@ParamMapper("allWorkflowId") String allWorkflowId); + + /** + * 根据类型类型ID获取其对应的配置信息 + * @param allWorkflowId 流程类型ID + * @param cusParamValue 自定义参数值 + * @return 返回数据集 + */ + @CaseConversion(value = false) + @Select("select * from uf_wfDataToNCVoucher where wfId in ($t{allWorkflowId}) and cusParamValue = #{cusParamValue}") + Map getConfigurationByWorkflowIdAndParam( @ParamMapper("allWorkflowId") String allWorkflowId,@ParamMapper("cusParamValue") String cusParamValue); + + /** + * 获取配置明细表1的信息集合 + * @param mainId 主表主键ID + * @return 明细表1数据集 + */ + @CaseConversion(value = false) + @Select("select dt.* from uf_wfDataToNCVoucher_dt1 dt where dt.mainId = #{mainId}") + List> getFirstDetailConfiguration(@ParamMapper("mainId") int mainId); + + + /** + * 获取配置明细表2的信息集合 + * @param mainId 主表主键ID + * @return 明细表2数据集 + */ + @CaseConversion(value = false) + @Select("select dt.*,wb.fieldName,wb.viewType,wb.detailTable from uf_wfDataToNCVoucher_dt2 dt left join workflow_billField wb on dt.wfFieldId = wb.id where dt.mainId = #{mainId}") + List> getSecondDetailConfiguration( @ParamMapper("mainId") int mainId); + + + /** + * 获取流程主表信息 + * @param billTable 表单名称 + * @param requestId 流程请求ID + * @return 主表数据集 + */ + @CaseConversion(value = false) + @Select("select * from $t{billTable} where requestId = #{requestId}") + RecordSet getWorkflowMainInfo(@ParamMapper("billTable") String billTable, @ParamMapper("requestId") String requestId); + + + /** + * 获取流程主表信息 + * @param billTable 表单名称 + * @param requestId 流程请求ID + * @param sqlWhere 自定义条件 + * @return 主表数据集 + */ + @CaseConversion(value = false) + @Select("select * from $t{billTable} where requestId = #{requestId} and $t{sqlWhere}") + RecordSet getWorkflowMainInfoAndCusWhere( @ParamMapper("billTable") String billTable,@ParamMapper("requestId") String requestId,@ParamMapper("sqlWhere") String sqlWhere); + + /** + * 获取流程明细表信息 + * @param detailBillTable 明细表单名称 + * @param mainId 流程请求ID + * @return 主表数据集 + */ + @CaseConversion(value = false) + @Select("select * from $t{detailBillTable} where mainId = #{mainId}") + RecordSet getWorkflowDetailInfo(@ParamMapper("detailBillTable") String detailBillTable, @ParamMapper("mainId") String mainId); + + /** + * 获取流程明细表信息 + * @param detailBillTable 明细表单名称 + * @param mainId 流程请求ID + * @param sqlWhere 自定义条件 + * @return 主表数据集 + */ + @CaseConversion(value = false) + @Select("select * from $t{detailBillTable} where mainId = #{mainId} and $t{sqlWhere}") + RecordSet getWorkflowDetailInfoAndCusWhere(@ParamMapper("detailBillTable") String detailBillTable, @ParamMapper("mainId") String mainId,@ParamMapper("sqlWhere") String sqlWhere); + + /** + * U8凭证号回写流程主表字段 + * + * @param billTable 表单名称 + * @param backFieldName 回写字段名称 + * @param backFieldValue 回写的凭证号 + * @param requestId 流程请求ID + */ + @CaseConversion(value = false) + @Update("update $t{billTable} set $t{backFieldName} = #{backFieldValue} where requestId = #{requestId}") + void backVoucherNoToBill(@ParamMapper("billTable") String billTable,@ParamMapper("backFieldName") String backFieldName,@ParamMapper("backFieldValue") String backFieldValue,@ParamMapper("requestId") String requestId); + + + /** + * 写入接口日志 + * @param loggerDao 接口日志实体类 + */ + @Update("update uf_interfaceLog set sourceRequestId = #{sourceRequestId},requestNo = #{requestNo},workflowId = #{workflowId}," + + "operator = #{operator},operateDateTime = #{operateDateTime},dealStatus = #{dealStatus},dealMessage = #{dealMessage}," + + "requestBody = #{requestBody},responseBody = #{responseBody},interfaceType = #{interfaceType} where id = #{newDataId}") + boolean insertInterfaceLog(InterfaceLoggerDao loggerDao); +} diff --git a/src/main/java/weaver/cssc/workflow/voucher/util/InterfaceLoggerDao.java b/src/main/java/weaver/cssc/workflow/voucher/util/InterfaceLoggerDao.java new file mode 100644 index 0000000..d557703 --- /dev/null +++ b/src/main/java/weaver/cssc/workflow/voucher/util/InterfaceLoggerDao.java @@ -0,0 +1,80 @@ +package weaver.cssc.workflow.voucher.util; + +import aiyh.utils.Util; +import lombok.Data; +import weaver.cssc.workflow.voucher.sqlmapper.VoucherSqlMapper; + +/** + * 中国船舶工业 + * 接口日志实体类 + */ +@Data +public class InterfaceLoggerDao { + + /** + * 新的记录ID + */ + private int newDataId; + + /** + * 流程请求ID + */ + private String sourceRequestId; + + /** + * 流程请求编号 + */ + private String requestNo; + + /** + * 流程类型ID + */ + private int workflowId; + + /** + * 接口类型 + */ + private int interfaceType; + + /** + * 当前操作者ID + */ + private int operator; + + /** + * 操作日期时间 + */ + private String operateDateTime; + + /** + * 处理状态 + */ + private int dealStatus; + + /** + * 处理消息 + */ + private String dealMessage; + + /** + * 请求报文 + */ + private String requestBody; + + /** + * 响应报文 + */ + private String responseBody; + + + /** + * 接口日志写入操作 + * @param loggerDao 日志类文件 + * @return 返回日志写入结果 + */ + public boolean insertInterfaceLog(InterfaceLoggerDao loggerDao){ + VoucherSqlMapper sqlMapper = Util.getMapper(VoucherSqlMapper.class); + + return sqlMapper.insertInterfaceLog(loggerDao); + } +} diff --git a/src/main/java/weaver/cssc/workflow/voucher/util/VoucherConstants.java b/src/main/java/weaver/cssc/workflow/voucher/util/VoucherConstants.java new file mode 100644 index 0000000..d81db1b --- /dev/null +++ b/src/main/java/weaver/cssc/workflow/voucher/util/VoucherConstants.java @@ -0,0 +1,94 @@ +package weaver.cssc.workflow.voucher.util; + +/** + * 中国船舶工业 + * 流程数据推送NC生成凭证 常量类 + * + * @author bleach + * @Date 2023-06-19 + */ +public class VoucherConstants { + + /** + * JSON 节点类型 - 普通文本 + */ + public final static int JSON_NODE_TYPE_COMMON_TEXT = 0; + + + /** + * JSON 节点类型 - 数组文本 + */ + public final static int JSON_NODE_TYPE_ARRAY_TEXT = 1; + + + /** + * JSON 节点类型 - 普通对象 + */ + public final static int JSON_NODE_TYPE_COMMON_OBJECT = 2; + + + /** + * JSON 节点类型 - 数组对象 + */ + public final static int JSON_NODE_TYPE_ARRAY_OBJECT = 3; + + /** + * 凭证分录借贷方向 - 非凭证分录 + */ + public final static String VOUCHER_ENTRY_NO_VOUCHER = "0"; + + + /** + * 凭证分录借贷方向 - 普通借方 + */ + public final static String VOUCHER_ENTRY_COMMON_DEBIT = "1"; + + + /** + * 凭证分录借贷方向 - 税额借方 + */ + public final static String VOUCHER_ENTRY_TAX_DEBIT = "2"; + + /** + * 凭证分录借贷方向 - 普通贷方 + */ + public final static String VOUCHER_ENTRY_COMMON_CREDIT = "3"; + + /** + * 凭证分录借贷方向 - 冲销贷方 + */ + public final static String VOUCHER_ENTRY_WRITE_OFF_CREDIT = "4"; + + + /** + * 字段特殊属性 - 普通字段 + */ + public final static int FIELD_SPECIAL_COMMON = 0; + + + /** + * 字段特殊属性 - 金额字段 + */ + public final static int FIELD_SPECIAL_AMOUNT = 1; + + /** + * 接口请求 成功状态码 + */ + public final static int REQUEST_SUCCESS_CODE = 200; + + /** + * 处理状态 - 未处理 + */ + public final static int DEAL_STATUS_NO_DEAL = 0; + + /** + * 处理状态 - 处理成功 + */ + public final static int DEAL_STATUS_SUCCESS = 1; + + /** + * 处理状态 - 处理失败 + */ + public final static int DEAL_STATUS_FAILURE = 2; + +} diff --git a/src/main/java/weaver/cssc/workflow/voucher/util/VoucherUtil.java b/src/main/java/weaver/cssc/workflow/voucher/util/VoucherUtil.java new file mode 100644 index 0000000..ee6bd83 --- /dev/null +++ b/src/main/java/weaver/cssc/workflow/voucher/util/VoucherUtil.java @@ -0,0 +1,367 @@ +package weaver.cssc.workflow.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.cssc.workflow.voucher.sqlmapper.VoucherSqlMapper; +import weaver.general.TimeUtil; +import weaver.workflow.workflow.WorkflowVersion; +import weaver.zwl.common.ToolUtilNew; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; +import java.util.Map; + +/** + * 中国船舶工业 + * 流程数据推送NC生成凭证工具类 + * + * @author bleach + * @Date 2023-06-19 + */ +public class VoucherUtil { + + /** + * 数组与流程映射关系配置集合 + */ + private List> detailList = new ArrayList<>(); + + + /** + * 字段配置集合 + */ + private List> fieldList = new ArrayList<>(); + + + private final VoucherSqlMapper sqlMapper = Util.getMapper(VoucherSqlMapper.class); + + + /** + * 递归生成JSON对象 + * @param baseArray 流程基础信息【流程请求ID、流程请求标题、流程请求编号、流程主表名称、流程主表主键ID值】 + * @param rs 流程主表数据集 + * @param rs_detail 流程明细表某一行数据集 + * @param voucherDirection 节点方向 + * @param parentNode 父节点名称 + * @param dtIndex 明细表序列 + * @param rowNum 明细表序号 + * @return JSON对象 + */ + public JSONObject recursionGenerateJSONObject(String[] baseArray,RecordSet rs,RecordSet rs_detail,int voucherDirection,String parentNode,int dtIndex,int rowNum){ + JSONObject jsonObject = new JSONObject(); + + if(fieldList != null && fieldList.size() > 0){ + for(Map fieldMap : fieldList){ + //节点名称 + String _nodeName = (String) fieldMap.get("nodeName"); + //父节点名称 + String _parentNode = (String) fieldMap.get("parentNode"); + + if(!_parentNode.equals(parentNode)){//若当前字段配置与传入的父节点名称不一致直接跳过 + continue; + } + + //字段所属 0-主表 1-明细表 + int _viewType = Util.getIntValue(Util.null2String(fieldMap.get("viewType")),0); + //获取明细表表名称 + String _detailTable = (String) fieldMap.get("detailTable"); + + + if(_viewType == 1 && StringUtils.isNotBlank(_detailTable)){//明细记录 + int _dtIndex = Util.getIntValue(_detailTable.substring(_detailTable.indexOf("_dt") + 3),-1); + + if(_dtIndex != dtIndex){ + continue; + } + } + + String _voucherDirection = (String) fieldMap.get("voucherDirection"); + + if(voucherDirection > 0 && !_voucherDirection.contains(String.valueOf(voucherDirection))) {//说明为会计分录 ,且当前字段的所属分录与传入的分录不一致 + continue; + } + + + //节点类型 + int _nodeType = (int) fieldMap.get("nodeType"); + + switch (_nodeType){ + case VoucherConstants.JSON_NODE_TYPE_COMMON_TEXT : + String fieldValue = getFieldValue(baseArray,fieldMap,rs,rs_detail,rowNum); + + int specialAttr = (int) fieldMap.get("specialAttr"); + + if(VoucherConstants.FIELD_SPECIAL_AMOUNT == specialAttr){ + double amount = Util.getDoubleValue(fieldValue,0.0); + + if(amount == 0.0){ + return null; + } + } + + jsonObject.put(_nodeName,fieldValue); + break; + case VoucherConstants.JSON_NODE_TYPE_ARRAY_TEXT : + String arrayFieldValue = getFieldValue(baseArray,fieldMap,rs,rs_detail,rowNum); + + JSONArray fieldArray = new JSONArray(); + + String[] fieldVal = Util.TokenizerString2(arrayFieldValue,","); + + fieldArray.addAll(Arrays.asList(fieldVal)); + + jsonObject.put(_nodeName,fieldArray); + + break; + case VoucherConstants.JSON_NODE_TYPE_COMMON_OBJECT : + JSONObject _detailObj = recursionGenerateJSONObject(baseArray,rs,rs_detail,voucherDirection,_nodeName,dtIndex,rowNum); + jsonObject.put(_nodeName,_detailObj); + break; + case VoucherConstants.JSON_NODE_TYPE_ARRAY_OBJECT: + //获取该数组对应的明细映射配置 + if(detailList != null && detailList.size() > 0){ + JSONArray itemArray = new JSONArray(); + + int _rowNum = 0; + for(Map detailMap :detailList){ + //对象/数组节点名称 + String _arrayNode = (String) detailMap.get("arrayNode"); + + if(!_arrayNode.equals(_nodeName)){ + continue; + } + + //是否凭证分录 + int _isVoucher = (int) detailMap.get("isVoucher"); + + //明细序列 + int _dtIndex = (int) detailMap.get("dtIndex"); + + //借贷方向 + String _dtItemDirection = (String) detailMap.get("dtItemDirection"); + if(_dtIndex > 0){//明细表 + + //明细条件 + String _dtCondition = (String) detailMap.get("dtCondition"); + + String detailBillTable = baseArray[3] + "_dt" + _dtIndex; + + RecordSet _rs_detail; + + if(StringUtils.isNotBlank(_dtCondition)){ + _dtCondition = ToolUtilNew.staticToDBC(_dtCondition); + + _rs_detail = sqlMapper.getWorkflowDetailInfoAndCusWhere(detailBillTable,baseArray[4],_dtCondition); + } else { + _rs_detail = sqlMapper.getWorkflowDetailInfo(detailBillTable,baseArray[4]); + } + + while(_rs_detail.next()){ + if(_isVoucher == 0){//非凭证分录 + JSONObject detailObj = recursionGenerateJSONObject(baseArray,rs,_rs_detail,Util.getIntValue(VoucherConstants.VOUCHER_ENTRY_NO_VOUCHER,0),_nodeName,_dtIndex,_rowNum++); + + itemArray.add(detailObj); + } else { + for(int k = 1; k <= 4;k++){ + if(_dtItemDirection.contains(String.valueOf(k))) { + JSONObject detailObj = recursionGenerateJSONObject(baseArray,rs,_rs_detail,k,_nodeName,_dtIndex,_rowNum++); + + if(detailObj != null && detailObj.size() > 0){ + itemArray.add(detailObj); + } + } + } + } + } + + } else {//主表 + if(_isVoucher == 1){ + for(int k = 1; k <= 4;k++){ + if(_dtItemDirection.contains(String.valueOf(k))) { + JSONObject detailObj = recursionGenerateJSONObject(baseArray,rs,null,k,_nodeName,_dtIndex,_rowNum++); + + if(detailObj != null && detailObj.size() > 0){ + itemArray.add(detailObj); + } + } + } + /* + //判断是否存在借方 + if(_dtItemDirection.contains(VoucherConstants.VOUCHER_ENTRY_COMMON_DEBIT)){ + JSONObject detailObj = recursionGenerateJSONObject(baseArray,rs,null,Util.getIntValue(VoucherConstants.VOUCHER_ENTRY_COMMON_DEBIT,0),_nodeName,_dtIndex,rowNum++); + + if(detailObj != null && detailObj.size() > 0){ + itemArray.add(detailObj); + } + } + + //税额借方 + if(_dtItemDirection.contains(VoucherConstants.VOUCHER_ENTRY_TAX_DEBIT)){ + JSONObject detailObj = recursionGenerateJSONObject(baseArray,rs,null,Util.getIntValue(VoucherConstants.VOUCHER_ENTRY_TAX_DEBIT,0),_nodeName,_dtIndex,rowNum++); + + if(detailObj != null && detailObj.size() > 0){ + itemArray.add(detailObj); + } + } + + //普通贷方 + if(_dtItemDirection.contains(VoucherConstants.VOUCHER_ENTRY_COMMON_CREDIT)){ + JSONObject detailObj = recursionGenerateJSONObject(baseArray,rs,null,Util.getIntValue(VoucherConstants.VOUCHER_ENTRY_COMMON_CREDIT,0),_nodeName,_dtIndex,rowNum++); + + if(detailObj != null && detailObj.size() > 0){ + itemArray.add(detailObj); + } + } + + //冲销贷方 + if(_dtItemDirection.contains(VoucherConstants.VOUCHER_ENTRY_WRITE_OFF_CREDIT)){ + JSONObject detailObj = recursionGenerateJSONObject(baseArray,rs,null,Util.getIntValue(VoucherConstants.VOUCHER_ENTRY_WRITE_OFF_CREDIT,0),_nodeName,_dtIndex,rowNum++); + + if(detailObj != null && detailObj.size() > 0){ + itemArray.add(detailObj); + } + } + */ + + } else { + JSONObject detailObj = recursionGenerateJSONObject(baseArray,rs,null,Util.getIntValue(VoucherConstants.VOUCHER_ENTRY_NO_VOUCHER,0),_nodeName,_dtIndex,_rowNum++); + + itemArray.add(detailObj); + } + } + } + + jsonObject.put(_nodeName,itemArray); + } + break; + } + } + } + + return jsonObject; + } + + /** + * 根据字段转换规则,获取其最终值 + * @param baseArray 流程基础信息数组 + * @param fieldMap 字段配置映射 + * @param rs 主表数据集 + * @param rs_detail 明细表数据集 + * @param rowNum 明细行号 + * @return 最终值 + */ + private String getFieldValue(String[] baseArray,Map fieldMap,RecordSet rs,RecordSet rs_detail,int rowNum){ + String fieldValue = ""; + + //System.out.println("字段配置:[" + JSONObject.toJSONString(fieldMap) + "]"); + //字段名称 + String fieldName = Util.null2String(fieldMap.get("fieldName")); + //字段所属 + int viewType = Util.getIntValue(Util.null2String(fieldMap.get("viewType")),0); + //转换规则 + int changeRule = Util.getIntValue(Util.null2String(fieldMap.get("changeRule")),0); + //自定义转换 + String cusSQL = (String) fieldMap.get("cusSQL"); + + if(!"".equals(fieldName)){ + if(viewType == 0){ + fieldValue = Util.null2String(rs.getString(fieldName)); + } else if (viewType == 1 && rs_detail != null) { + fieldValue = Util.null2String(rs_detail.getString(fieldName)); + } + } + + switch (changeRule){ + case 0 : //不转换 + break; + case 1 : //流程请求ID + fieldValue = baseArray[0]; + break; + case 2 : //流程请求标题 + fieldValue = baseArray[1]; + break; + case 3 : //流程请求编号 + fieldValue = baseArray[2]; + break; + case 4 : //系统日期 + fieldValue = TimeUtil.getCurrentDateString(); + break; + case 5 : //系统时间 + fieldValue = TimeUtil.getCurrentTimeString(); + break; + case 6 : //固定值 + fieldValue = cusSQL; + break; + case 7 : //明细序列 + fieldValue = String.valueOf(rowNum); + break; + case 8 : //自定义转换 + int detailKey = -1; + + if(cusSQL.contains("{?dt.id}") && rs_detail != null){ + detailKey = Util.getIntValue(rs_detail.getString("id"),0); + } + + fieldValue = ToolUtilNew.getStaticValueByChangeRule(cusSQL,fieldValue,baseArray[0],detailKey); + break; + } + + //System.out.println("fieldValue:" + fieldValue); + return fieldValue; + } + + /** + * 根据流程类型获取其对应的配置信息集合 + * @param workflowId 流程类型ID + * @param cusParamValue 自定义参数值 + * @return 配置信息集合 + */ + public Map getConfigurationByWorkflowId(String workflowId,String cusParamValue){ + Map configMap ; + + //获取该流程类型对应的所有版本ID + String allWfIds = WorkflowVersion.getAllVersionStringByWFIDs(workflowId); + + if(StringUtils.isNotBlank(cusParamValue)){ + configMap = sqlMapper.getConfigurationByWorkflowIdAndParam(allWfIds,cusParamValue); + } else { + configMap = sqlMapper.getConfigurationByWorkflowId(allWfIds); + } + + + if(configMap != null && configMap.size() > 0){ + int mainId = (int) configMap.get("id"); + + //获取明细表1配置集合 + List> detailList = sqlMapper.getFirstDetailConfiguration(mainId); + + List> fieldList = sqlMapper.getSecondDetailConfiguration(mainId); + + + configMap.put("detailList",detailList); + configMap.put("fieldList",fieldList); + } + + return configMap; + } + + + public List> getDetailList() { + return detailList; + } + + public void setDetailList(List> detailList) { + this.detailList = detailList; + } + + public List> getFieldList() { + return fieldList; + } + + public void setFieldList(List> fieldList) { + this.fieldList = fieldList; + } +} diff --git a/src/main/java/weaver/zwl/common/ToolUtilNew.java b/src/main/java/weaver/zwl/common/ToolUtilNew.java new file mode 100644 index 0000000..6b74c17 --- /dev/null +++ b/src/main/java/weaver/zwl/common/ToolUtilNew.java @@ -0,0 +1,426 @@ +package weaver.zwl.common; + +import com.google.common.base.Strings; +import com.weaver.general.TimeUtil; +import org.apache.log4j.*; +import org.h2.util.StringUtils; +import weaver.conn.ConnStatementDataSource; +import weaver.conn.RecordSet; +import weaver.formmode.data.ModeDataIdUpdate; +import weaver.formmode.setup.ModeRightInfo; +import weaver.general.Util; + +import java.io.File; +import java.sql.SQLException; +import java.util.HashMap; +import java.util.Map; + +/** + * 工具类加强版 + */ +@SuppressWarnings("ALL") +public class ToolUtilNew extends ToolUtil{ + /** + * 建模数据权限处理类 + */ + public static final ModeRightInfo MODE_RIGHT_INFO = new ModeRightInfo(); + /** + * 建模新数据ID获取类 + */ + public static final ModeDataIdUpdate mdu = ModeDataIdUpdate.getInstance(); + /** + * 建模新创建的数据,默认用户为系统管理员 + */ + public static final int modeDataDefaultUserId = 1; + /** + * 日志操作类 + */ + private static volatile Logger log = null; + /** + * 其他自定义日志集合 + */ + private static final Map otherLog = new HashMap<>(8); + + /** + * 获取日志对象 + * 若不存在则动态注入值log4j中 + * @return 日志对象 + */ + @SuppressWarnings("deprecation") + public static Logger getLogger() { + if (log == null) { + synchronized (ToolUtilNew.class) { + if (log == null) { + DailyRollingFileAppender appender = new DailyRollingFileAppender(); + log = Logger.getLogger("ayh_cus"); + appender.setName("ayh_cus"); + appender.setEncoding("UTF-8"); + appender.setDatePattern("'_'yyyyMMdd'.log'"); + appender.setFile(weaver.general.GCONST.getLogPath() + "cus" + File.separator + "util_cus" + File.separator + "cus.log"); + appender.setThreshold(Priority.DEBUG); + appender.setLayout(new PatternLayout("[%-5p] [%d{yyyy-MM-dd HH:mm:ss,SSS}] [%r] [Thread:%t][%F.%M:%L] ==> : %m %x %n")); + appender.setAppend(true); + appender.activateOptions(); + log.addAppender(appender); + log.setLevel(Level.INFO); + } + } + } + return log; + } + + /** + * 获取日志类,若不存在则动态注入值log4j中 + * @param name 日志名称 + * @return 日志对象 + */ + public static Logger getLogger(String name) { + + if (otherLog.containsKey(name)) { + return otherLog.get(name); + } + if (!otherLog.containsKey(name)) { + synchronized (ToolUtilNew.otherLog) { + if (otherLog.containsKey(name)) { + return otherLog.get(name); + } + DailyRollingFileAppender appender = new DailyRollingFileAppender(); + Logger cusLog = Logger.getLogger("cus_" + name); + appender.setName("cus_" + name); + appender.setEncoding("UTF-8"); + appender.setDatePattern("'_'yyyyMMdd'.log'"); + appender.setFile(weaver.general.GCONST.getLogPath() + "cus" + File.separator + name + File.separator + "cus.log"); + appender.setThreshold(Priority.DEBUG); + appender.setLayout(new PatternLayout("[%-5p] [%d{yyyy-MM-dd HH:mm:ss,SSS}] [%r] [Thread:%t][%F.%M:%L] ==> : %m %x %n")); + appender.setAppend(true); + appender.activateOptions(); + cusLog.addAppender(appender); + cusLog.setLevel(Level.INFO); + otherLog.put(name, cusLog); + return cusLog; + } + } + return null; + } + + /** + * 获取建模模块ID通过表名 + * + * @param tableName 表名 + * @return 模块ID + */ + public static int getModeIdByTableName(String tableName) { + int modeId = 0; + String querySql = "select id from modeinfo where formid = (select id from workflow_bill where tablename = ?)"; + RecordSet recordSet = new RecordSet(); + recordSet.executeQuery(querySql, tableName); + if (recordSet.next()) { + modeId = Util.getIntValue(recordSet.getString("id"),0); + } + return modeId; + } + + /** + * 获取建模表数据ID + * + * @param tableName 表名 + * @param formModeId 模块ID + * @return 数据ID + */ + public static int getModeDataNewId(String tableName, int formModeId) { + return getModeDataNewId(tableName, formModeId,modeDataDefaultUserId); + } + + /** + * 获取建模表数据ID + * + * @param tableName 表名 + * @param formModeId 模块ID + * @param userId 用户ID + * @return 数据ID + */ + public static int getModeDataNewId(String tableName, int formModeId, int userId) { + return mdu.getModeDataNewId(tableName, formModeId, userId, 0, TimeUtil.getCurrentDateString(), TimeUtil.getOnlyCurrentTimeString()); + } + + + /** + * 建模表数据权限重构 + * + * @param formId 表单ID + * @param id 数据ID + * @param userId 用户ID + */ + public static void rebuildModeDataShare(Integer formId, Integer id) { + rebuildModeDataShare(formId, id,modeDataDefaultUserId); + } + + /** + * 建模表数据权限重构 + * + * @param formId 表单ID + * @param id 数据ID + * @param userId 用户ID + */ + public static void rebuildModeDataShare(Integer formId, Integer id,Integer userId) { + MODE_RIGHT_INFO.rebuildModeDataShareByEdit(userId, formId, id); + } + + /** + * 获取配置表中与某个字符串相似的所有配置信息集合 + * @param likestr 模糊查询字符串 + * @return 配置集合 + */ + public static Map getSystemParamList(String likestr){ + return getSystemParamList(likestr,"uf_systemConfig"); + } + + /** + * 获取配置表中的参数值 + * @param uuid 参数标识 + * @return 参数值 + */ + public static String getStaticSystemParamValue(String uuid){ + return getStaticSystemParamValue(uuid,"uf_systemConfig"); + } + + /** + * 获取配置表中的参数值 + * @param uuid 参数标识 + * @param configTable 参数表名称 + * @return 参数值 + */ + public static String getStaticSystemParamValue(String uuid,String configTable){ + String querySQL = "select paramValue from " + configTable + " where uuid = ?"; + + RecordSet rs = new RecordSet(); + + if(rs.executeQuery(querySQL,uuid) && rs.next()){ + return Util.null2String(rs.getString(1)); + } + + return ""; + } + + /** + * 获取配置表中与某个字符串相似的所有配置信息集合 + * @param likestr 模糊查询字符串 + * @param configTable 配置表 + * @return 配置集合 + */ + public static Map getSystemParamList(String likestr,String configTable){ + Map param_map = new HashMap(); + + String select_sql = "select uuid,paramValue from " + configTable; + + RecordSet rs = new RecordSet(); + + if(!"".equals(likestr)){ + select_sql += " where uuid like '%" + likestr + "%'"; + } + + if(rs.execute(select_sql)){ + while(rs.next()){ + String uuid = Util.null2String(rs.getString(1)); + String paramvalue = Util.null2String(rs.getString(2)); + + param_map.put(uuid, paramvalue); + } + } + return param_map; + } + + /** + * 根据字段ID获取其对应的字段名称 + * @param fieldId 字段ID + * @return 字段名称 + */ + public static String getFieldNameBySingleFieldId(int fieldId){ + String fieldname = ""; + + if(fieldId != 0){ + String querySql = "select fieldname from workflow_billfield where id=?"; + + RecordSet rs = new RecordSet(); + + if(rs.executeQuery(querySql,fieldId)){ + while(rs.next()){ + fieldname = Util.null2String(rs.getString(1)); + } + } + } + return fieldname; + } + + /** + * 获取某个流程某个附件/文档字段对应的文档目录 + * @param workflowId 流程类型ID + * @param docField 文档/附件字段 + * @param tableName 表单名称 + * @return 文档目录ID + */ + public static String getDocCategorysByTable(String workflowId, String docField, String tableName) { + String formId = ""; + RecordSet rs = new RecordSet(); + if(rs.executeQuery("select formid from workflow_base where id = ?", workflowId)){ + if(rs.next()){ + formId = Util.null2String(rs.getString(1)); + } + } + String query = "select doccategory from workflow_fileupload where fieldid in (select id from workflow_billfield where fieldname = ? and billid = ? and (detailtable = ? or detailtable is null))"; + if (!Strings.isNullOrEmpty(tableName) && tableName.contains("_dt")) { + query = "select doccategory from workflow_fileupload where fieldid in (select id from workflow_billfield where fieldname = ? and billid = ? and detailtable = ?)"; + } + + String docCategorys = ""; + + if(rs.executeQuery(query, docField, formId, tableName)){ + if(rs.next()){ + docCategorys = Util.null2String(rs.getString(1)); + } + } + if (StringUtils.isNullOrEmpty(docCategorys)) { + query = "select doccategory from workflow_base where id = ?"; + rs.executeQuery(query, workflowId); + rs.next(); + docCategorys = Util.null2String(rs.getString(1)); + } + + if (StringUtils.isNullOrEmpty(docCategorys)) { + docCategorys = ",,1"; + } + + return docCategorys; + } + + /** + * 根据字段ID获取其对应的字段名称 + * @param fieldId 字段ID + * @return 字段名称 + */ + public static String getFieldNameByFieldIdStatic(int fieldId){ + String fieldname = ""; + + if(fieldId > 0){ + String select_sql = "select fieldname from workflow_billfield where id = ?"; + + RecordSet rs = new RecordSet(); + + if(rs.executeQuery(select_sql,fieldId)){ + while(rs.next()){ + fieldname = Util.null2String(rs.getString(1)); + } + } + } + + return fieldname; + } + + + + /** + * 用数据库值,根据规则转换,获取其最终结果 + * @param cus_sql 自定义转换的SQL + * @param value 参数值 + * @return 配置值 + */ + public static String getStaticValueByChangeRule(String cus_sql,String value){ + return getStaticValueByChangeRule(cus_sql,value,""); + } + + /** + * 用数据库值,根据规则转换,获取其最终结果 + * @param cus_sql 自定义转换的SQL + * @param value 参数值 + * @param requestid 流程请求ID + * @return 返回最终值 + */ + public static String getStaticValueByChangeRule(String cus_sql,String value,String requestid){ + + return getStaticValueByChangeRule(cus_sql,value,requestid,0); + } + + /** + * 用数据库值,根据规则转换,获取其最终结果 + * @param cus_sql 自定义转换的SQL + * @param value 参数值 + * @param requestid 流程请求ID + * @param detailKeyvalue 明细表主键值 + * @return 返回最终值 + */ + public static String getStaticValueByChangeRule(String cus_sql,String value,String requestid,int detailKeyvalue){ + return getStaticValueByChangeRule(cus_sql,value,requestid,detailKeyvalue,null); + } + + /** + * 用数据库值,根据规则转换,获取其最终结果 + * @param cusSQL 自定义转换的SQL + * @param value 参数值 + * @param requestid 流程请求ID + * @param detailKeyvalue 明细表主键值 + * @pram datasourceid 外部数据源ID + * @return 返回最终值 + */ + public static String getStaticValueByChangeRule(String cusSQL,String value,String requestid,int detailKeyvalue,String datasourceid){ + String endValue = ""; + + cusSQL = cusSQL.replace(" ", " "); + + cusSQL = cusSQL.replace("{?dt.id}", String.valueOf(detailKeyvalue)); + + //参数进行替换 + String sqlString = cusSQL.replace("{?requestid}", requestid); + + sqlString = sqlString.replace("?", value); + + sqlString = staticToDBC(sqlString); + try { + if(datasourceid != null && !"".equals(datasourceid)){ + ConnStatementDataSource csds = new ConnStatementDataSource(datasourceid); + + csds.setStatementSql(sqlString); + + csds.executeQuery(); + + if(csds.next()){ + endValue = Util.null2String(csds.getString(1)); + } + + csds.close(); + }else{ + RecordSet rs = new RecordSet(); + if(rs.executeQuery(sqlString)){ + rs.next(); + endValue = Util.null2String(rs.getString(1)); + } + } + } catch (SQLException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } catch (Exception e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + + return endValue; + } + + /** + * 全角转半角 + * @param input 原字符串 + * @return 转换后的字符串 + */ + public static String staticToDBC(String input) { + char c[] = input.toCharArray(); + for (int i = 0; i < c.length; i++) { + if (c[i] == '\u3000') { + c[i] = ' '; + } else if (c[i] > '\uFF00' && c[i] < '\uFF5F') { + c[i] = (char) (c[i] - 65248); + } + } + String returnString = new String(c); + return returnString; + } + +}