diff --git a/javascript/xuanran.wang/bme/js/BuildContractApply.js b/javascript/xuanran.wang/bme/js/BuildContractApply.js new file mode 100644 index 0000000..a58d098 --- /dev/null +++ b/javascript/xuanran.wang/bme/js/BuildContractApply.js @@ -0,0 +1,54 @@ +/** + * 柏美 施工合同申请js + * 明细表自动添加5行 不允许增删 并校验付款比例是否等于100% 自动计算付款日期 + * @author xuanran.wang + */ +// 明细表 +const detailTable = "detail_2"; +// 主表合同签订日期 +const contractSignDateId = WfForm.convertFieldNameToId("htqdrq"); +// 明细2付款比例字段 +const detail2PayProportionId = WfForm.convertFieldNameToId("fkbl",detailTable); +// 明细2款项类型 +const detail2PaymentTypeId = WfForm.convertFieldNameToId("kxlx",detailTable); +// 明细2前后字段 +const detail2AroundId = WfForm.convertFieldNameToId("qh",detailTable); +// 明细2天数字段 +const detail2DayId = WfForm.convertFieldNameToId("ts",detailTable); +// 明细2预计付款日期 +const detail2ComPayDateId = WfForm.convertFieldNameToId("yjfkrq",detailTable); +// 对应日期 +const detail2TempDateField = WfForm.convertFieldNameToId("dyrq", detailTable); +// 需要计算的款项类型集合 +const computeDatePayType = ['0']; +// 款项类型预计对应日期取值 +const paymentTypeGetValue = { + 0: (index)=>{ + WfForm.changeFieldValue(`${detail2TempDateField}_${index}`,{value : WfForm.getFieldValue(contractSignDateId)}); + } +} +jQuery().ready(function(){ + let configObj = { + 'detailPaymentTypeId':detail2PaymentTypeId, + 'detailTempDateId': detail2TempDateField, + 'around': detail2AroundId, + 'detailComPayDateId': detail2ComPayDateId, + 'dayId': detail2DayId, + 'computeDatePayType': computeDatePayType, + 'paymentTypeGetValue': paymentTypeGetValue + } + // 默认增加5条 + for (let i = 0; i < 5; i++) { + WfForm.addDetailRow(detailTable,{ [detail2PaymentTypeId]: {value: i}}); + } + + // 主表字段发生变化 + mainFieldChangeDetailCom(contractSignDateId, detailTable, configObj); + + // 明细的款项类型字段变化绑定 + detailFieldChangeDetailCom(`${detail2AroundId},${detail2DayId}`, configObj); + + submitCallback(detailTable, detail2PayProportionId); + +}); + diff --git a/javascript/xuanran.wang/bme/js/Common.js b/javascript/xuanran.wang/bme/js/Common.js new file mode 100644 index 0000000..230e7f0 --- /dev/null +++ b/javascript/xuanran.wang/bme/js/Common.js @@ -0,0 +1,154 @@ +const ADD = '1'; +const DEL = '0'; +const READ_ONLY = '1'; +const EDIT = '2'; +/** + * 计算日期 + * @param date 计算日期 + * @param around 前/后 前是0 后是1 + * @param day + */ +function computeDate(date, around, day){ + let dateTime = new Date(date).getTime(); + let mill = 0; + switch (around){ + case ADD:{ + mill = day * 1; + console.log('add :', mill); + break; + } + case DEL:{ + mill = day * -1; + console.log('del :', mill); + break; + } + } + // 转成毫秒数 + mill *= (24 * 60 * 60 * 1000); + dateTime += mill; + return getDate(dateTime); +} + +/** + * 时间戳转 yyyy-MM-dd + * @param time + * @returns {string} + */ +function getDate(time) { + let date = new Date(time); + y = date.getFullYear(); + m = date.getMonth() + 1; + d = date.getDate(); + return y + "-" + (m < 10 ? "0" + m : m) + "-" + (d < 10 ? "0" + d : d); +} + +/** + * 校验比例是否等于100 + * @param detailTable 明细表 + * @param detail2PayProportionId 比例字段 + */ +function submitCallback(detailTable, detail2PayProportionId){ + WfForm.registerCheckEvent(WfForm.OPER_SUBMIT,function(callback){ + let rowArr = WfForm.getDetailAllRowIndexStr(detailTable).split(","); + let sum = 0; + for(let i=0; i < rowArr.length; i++){ + let rowIndex = rowArr[i]; + if(rowIndex !== ""){ + let field = `${detail2PayProportionId}_${rowIndex}`; + sum += parseFloat(WfForm.getFieldValue(field));//遍历明细行字段 + } + } + sum === 100.00 ? callback() : WfForm.showMessage("明细付款比例总和不等于100,请修改后提交!"); + }); +} + +/** + * 明细表字段发生变化进行日期计算 + * @param bindField + * @param configObj + */ +function detailFieldChangeDetailCom(bindField, configObj){ + WfForm.bindDetailFieldChangeEvent(bindField,function(id,index,value){ + configObj.index = index; + changeDetailPayDate(configObj); + }); +} + +/** + * 主表字段发生变化进行日期计算 + * @param mainField + * @param detailTable + * @param configObj + */ +function mainFieldChangeDetailCom(mainField, detailTable, configObj){ + // 主表项目字段变化绑定 + WfForm.bindFieldChangeEvent(mainField, function(obj,id,value){ + let rowArr = WfForm.getDetailAllRowIndexStr(detailTable).split(","); + for(let i=0; i < rowArr.length; i++){ + let index = rowArr[i]; + if(index !== ""){ + configObj.index = index; + changeDetailPayDate(configObj); + } + } + }); +} + +/** + * 先进行主表的dml查询日期字段赋值到明细 然后在计算日期 + * @param obj 配置对象 + */ +function changeDetailPayDate(obj){ + console.log('---- changeDetailPayDate obj ----', obj); + // 明细表的款项类型 + let detailPaymentTypeId = obj['detailPaymentTypeId']; + // 明细下标 + let index = obj['index']; + // 明细表的对应日期 + let detailTempDateId = obj['detailTempDateId']; + // 明细表的前/后 + let aroundId = obj['around']; + // 明细表的预计付款日期 + let detailComPayDateId = obj['detailComPayDateId']; + // 明细表的天数 + let dayId = obj['dayId']; + // 需要计算的款项数组 + let computeDatePayType = obj['computeDatePayType']; + // 获取主表的字符值转换函数 + let paymentTypeGetValue = obj['paymentTypeGetValue']; + // 款项类型 + let paymentType = WfForm.getFieldValue(`${detailPaymentTypeId}_${index}`); + // 先进行赋值 + if(computeDatePayType.includes(paymentType)){ + WfForm.changeFieldAttr(`${detailComPayDateId}_${index}`, READ_ONLY); + // 存在字段联动延时处理 + setTimeout(()=>{ + if(paymentTypeGetValue){ + paymentTypeGetValue[paymentType](index); + } + // 获取对应日期 + let tempDate = WfForm.getFieldValue(`${detailTempDateId}_${index}`); + if(tempDate){ + // 前/后 + let around = WfForm.getFieldValue(`${aroundId}_${index}`); + // 天数 + let day = WfForm.getFieldValue(`${dayId}_${index}`); + // 如果明细表三个字段的值都不为空 那么就去计算日期 + if(tempDate && around && day){ + let comDate = computeDate(tempDate, around, day); + WfForm.changeFieldValue(`${detailComPayDateId}_${index}`,{ + value: comDate + }); + } + }else { + // 如果对应日期为空就给预计付款赋空值 + WfForm.changeFieldValue(`${detailComPayDateId}_${index}`,{ + value: '' + }); + } + },100); + }else{ + // 如果款项类型不需要计算就把预计付款日期属性改成可编辑 + WfForm.changeFieldAttr(`${detailComPayDateId}_${index}`, EDIT); + } +} diff --git a/javascript/xuanran.wang/bme/js/PurchaseContractApply.js b/javascript/xuanran.wang/bme/js/PurchaseContractApply.js new file mode 100644 index 0000000..f4b95b1 --- /dev/null +++ b/javascript/xuanran.wang/bme/js/PurchaseContractApply.js @@ -0,0 +1,58 @@ +/** + * 柏美 采购合同申请js + * @author xuanran.wang + */ +// 明细表 +const detailTable = "detail_3"; +// 主表项目字段 +const mainProjectId = WfForm.convertFieldNameToId("xmmc"); +// 主表合同签订日期 +const contractSignDateId = WfForm.convertFieldNameToId("htqdrq"); +// 明细2付款比例字段 +const detailPayProportionId = WfForm.convertFieldNameToId("fkbl",detailTable); +// 明细2款项类型 +const detailPaymentTypeId = WfForm.convertFieldNameToId("kxlx",detailTable); +// 明细2前后字段 +const detailAroundId = WfForm.convertFieldNameToId("qh",detailTable); +// 明细2天数字段 +const detailDayId = WfForm.convertFieldNameToId("ts",detailTable); +// 明细2预计付款日期 +const detailComPayDateId = WfForm.convertFieldNameToId("yjfkrq",detailTable); +// 对应日期 +const detailTempDateField = WfForm.convertFieldNameToId("dyrq", detailTable); +// 需要计算的款项类型集合 +const computeDatePayType = ['0','2','4']; +// 款项类型预计对应日期取值 +const paymentTypeGetValue = { + 0: (index)=>{ + WfForm.changeFieldValue(`${detailTempDateField}_${index}`,{value : WfForm.getFieldValue(contractSignDateId)}); + }, + 2: (index)=>{ + WfForm.changeFieldValue(`${detailTempDateField}_${index}`,{value : WfForm.getFieldValue(mainActualCheckId)}); + }, + 4: (index)=>{ + WfForm.changeFieldValue(`${detailTempDateField}_${index}`,{value : WfForm.getFieldValue(mainActualCheckId)}); + } +} +$(()=>{ + init(); +}); + +function init(){ + + let obj = { + 'detailPaymentTypeId':detailPaymentTypeId, + 'detailTempDateId': detailTempDateField, + 'around': detailAroundId, + 'detailComPayDateId': detailComPayDateId, + 'dayId': detailDayId, + 'computeDatePayType': computeDatePayType, + 'paymentTypeGetValue': paymentTypeGetValue + } + + // 主表字段发生变化 + mainFieldChangeDetailCom(`${mainProjectId},${contractSignDateId}`, detailTable, obj); + // 明细的款项类型字段变化绑定 + detailFieldChangeDetailCom(`${detailPaymentTypeId},${detailAroundId},${detailDayId}`, obj); + submitCallback(detailTable, detailPayProportionId); +} diff --git a/javascript/xuanran.wang/bme/js/SaleContractApply.js b/javascript/xuanran.wang/bme/js/SaleContractApply.js new file mode 100644 index 0000000..87cb38d --- /dev/null +++ b/javascript/xuanran.wang/bme/js/SaleContractApply.js @@ -0,0 +1,61 @@ +/** + * 柏美 销售合同申请js + * @author xuanran.wang + */ +// 明细表 +const detailTable = "detail_2"; +// 主表项目字段 +const mainProjectId = WfForm.convertFieldNameToId("xmmc"); +// 主表流程归档日期 +const mainWorkFlowEndId = WfForm.convertFieldNameToId("fhdgdrq"); +// 主表实际验收 +const mainActualCheckId = WfForm.convertFieldNameToId("sjysrq"); +// 明细2付款比例字段 +const detail2PayProportionId = WfForm.convertFieldNameToId("fkbl",detailTable); +// 明细2款项类型 +const detail2PaymentTypeId = WfForm.convertFieldNameToId("kxlx",detailTable); +// 明细2前后字段 +const detail2AroundId = WfForm.convertFieldNameToId("qh",detailTable); +// 明细2天数字段 +const detail2DayId = WfForm.convertFieldNameToId("ts",detailTable); +// 明细2预计付款日期 +const detail2ComPayDateId = WfForm.convertFieldNameToId("yjfkrq",detailTable); +// 对应日期 +const detail2TempDateField = WfForm.convertFieldNameToId("dyrq", detailTable); +// 需要计算的款项类型集合 +const computeDatePayType = ['2', '4', '5']; +// 款项类型预计对应日期取值 +const paymentTypeGetValue = { + 2: (index)=>{ + console.log('将主表的 mainWorkFlowEndId : ' + mainWorkFlowEndId + ' val : ' + WfForm.getFieldValue(mainWorkFlowEndId) + ' 赋值给明细 ' + `${detail2TempDateField}_${index}`); + WfForm.changeFieldValue(`${detail2TempDateField}_${index}`,{value : WfForm.getFieldValue(mainWorkFlowEndId)}); + }, + 4: (index)=>{ + WfForm.changeFieldValue(`${detail2TempDateField}_${index}`,{value : WfForm.getFieldValue(mainActualCheckId)}); + }, + 5: (index)=>{ + WfForm.changeFieldValue(`${detail2TempDateField}_${index}`,{value : WfForm.getFieldValue(mainActualCheckId)}); + } +} +$(()=>{ + init(); +}); + +function init(){ + + let obj = { + 'detailPaymentTypeId':detail2PaymentTypeId, + 'detailTempDateId': detail2TempDateField, + 'around': detail2AroundId, + 'detailComPayDateId': detail2ComPayDateId, + 'dayId': detail2DayId, + 'computeDatePayType': computeDatePayType, + 'paymentTypeGetValue': paymentTypeGetValue + } + // 主表字段发生变化 + mainFieldChangeDetailCom(mainProjectId, detailTable, obj); + // 明细的款项类型字段变化绑定 + detailFieldChangeDetailCom(`${detail2PaymentTypeId},${detail2AroundId},${detail2DayId}`, obj); + submitCallback(detailTable, detail2PayProportionId); + +} diff --git a/javascript/xuanran.wang/schroeder/js/Seal.js b/javascript/xuanran.wang/schroeder/js/Seal.js new file mode 100644 index 0000000..334ce52 --- /dev/null +++ b/javascript/xuanran.wang/schroeder/js/Seal.js @@ -0,0 +1,151 @@ + +// 打印盖章 +const pritGz = 1; +// 鉴伪盖章 +const jwGz = 3; +// 开门盖章 +const kmGz = 4; +// 用印方式字段名 +const sealTypeId = WfForm.convertFieldNameToId("yyfs"); +// 用印方式字段名明细 +const detailSealTypeId = WfForm.convertFieldNameToId("yylx","detail_1"); +// 是否需要加骑缝章 +const detailQfzField = WfForm.convertFieldNameToId("sfjgqfz","detail_1"); +// 否 +const no = 1; +// 是 +const yes = 0;// 组合用印 +const zh = 6; +// 取章用印 +const qzyy = 7; +// 是否归档 +const lastField = WfForm.convertFieldNameToId("sfgd"); +// 来源 +const source = WfForm.convertFieldNameToId("htspcfyy"); +//属于合同 +const isht = WfForm.convertFieldNameToId("zyht"); +//完成法神 +const islaw = WfForm.convertFieldNameToId("wcfs"); +// 用印文件字段 +const detailFileTypeId = WfForm.convertFieldNameToId("yywj","detail_1"); + +// 主表 +const mainsealtype = WfForm.convertFieldNameToId("yzzl"); +// 主表合同专用章次数 +const mainht = WfForm.convertFieldNameToId("htzyzcshj"); +// 主表公章次数 +const maingz = WfForm.convertFieldNameToId("gzcshj"); +// 主表法人章次数 +const mainfr = WfForm.convertFieldNameToId("frzcshj"); + +// 必填 +const required = 3; +// 只读 +const readOnly = 1; +// 可编辑 +const edit = 2; +// 默认文件docid +const defaultfile = 85; +// 明细1用印文件 +jQuery(document).ready(()=>{ + let sourceVal = WfForm.getFieldValue(source); + console.log('sourceVal ', sourceVal) + if(sourceVal == 0){ + WfForm.changeSingleField(isht,{value:yes}, {viewAttr:readOnly}); + WfForm.changeSingleField(islaw,{value:yes}, {viewAttr:readOnly}); + // 明细表用印文件字段做只读 + var rowArr = WfForm.getDetailAllRowIndexStr("detail_1").split(","); + for(var i=0; i dataList = Arrays.stream(choiceData.split(",")).collect(Collectors.toList()); - List requestIds = CommonUtil.doCreateWorkFlow(modelId, dataList); // 通过数据审批生成流程 - List errorData = new ArrayList<>(); - for (int i = 0; i < requestIds.size(); i++) { - if (Util.getIntValue(requestIds.get(i), -1) < 0) { - errorData.add(dataList.get(i)); + try { + User logInUser = HrmUserVarify.getUser(request, response); + if(logInUser == null){ + return ApiResult.error(403,"请先登录!"); } + String choiceData = request.getParameter("choiceData"); + if(StringUtils.isBlank(choiceData)){ + return ApiResult.error(403,"请勾选数据!"); + } + int modelId = Util.getIntValue(request.getParameter("modelId"), -1); + String triggerWorkflowSetId = Util.null2DefaultStr(request.getParameter("triggerWorkflowSetId"), ""); + String createDateField = Util.null2DefaultStr(request.getParameter("createDateField"), ""); + if(modelId < 0 || StringUtils.isBlank(triggerWorkflowSetId) || StringUtils.isBlank(createDateField)){ + logger.info(Util.logStr("modelId : {}, triggerWorkflowSetId : {}, createDateField : {}", modelId, triggerWorkflowSetId, createDateField)); + return ApiResult.error(403,"api必要参数未配置!"); + } + return ApiResult.success(JSONObject.toJSONString( createWorkFlowService.hrmCusCreateWorkFlow(choiceData, createDateField, triggerWorkflowSetId, modelId))); + }catch (Exception e){ + logger.error(Util.logStr(e.getMessage())); + logger.error(Util.getErrString(e)); + return ApiResult.error("接口发生异常!"); } - logger.error(Util.logStr("执行创建流程失败集合: {}",JSONObject.toJSONString(errorData))); // 构建日志字符串 - return ApiResult.success(errorData); + } + + @Path("gysCusCreateWorkFlow") + @POST + @Produces(MediaType.TEXT_PLAIN) + public String gysCusCreateWorkFlow(@Context HttpServletRequest request, @Context HttpServletResponse response) { + try { + User logInUser = HrmUserVarify.getUser(request, response); + if(logInUser == null){ + return ApiResult.error(403,"请先登录!"); + } + String choiceData = request.getParameter("choiceData"); + if(StringUtils.isBlank(choiceData)){ + return ApiResult.error(403,"请勾选数据!"); + } + // 执行创建流程数据审批的模块id + int dataApprovalModelId = Util.getIntValue(request.getParameter("dataApprovalModelId"), -1); + // 待合并数据审批id + int createTriggerId = Util.getIntValue(request.getParameter("createTriggerId"), -1); + // 数据同步配置参数 + String asyncCode = Util.null2DefaultStr(request.getParameter("asyncCode"), ""); + // 带合并模块id + String dataModelId = Util.null2DefaultStr(request.getParameter("dataModelId"), ""); + if(createTriggerId < 0 || StringUtils.isBlank(asyncCode) || dataApprovalModelId < 0 || StringUtils.isBlank(dataModelId)){ + logger.info(Util.logStr("createTriggerId : {}, asyncCode : {}, dataApprovalModelId : {}", createTriggerId, asyncCode, dataApprovalModelId)); + return ApiResult.error(403,"api必要参数未配置!"); + } + return ApiResult.success(createWorkFlowService.supplierCusCreateWorkFlow(String.valueOf(createTriggerId), dataModelId, asyncCode, choiceData, dataApprovalModelId)); + }catch (Exception e){ + logger.error(Util.logStr(e.getMessage())); + logger.error(Util.getErrString(e)); + return ApiResult.error("接口发生异常!"); + } + + } + + + } diff --git a/src/main/java/com/api/xuanran/wang/saic_travel/model_create_workflow/service/CreateWorkFlowService.java b/src/main/java/com/api/xuanran/wang/saic_travel/model_create_workflow/service/CreateWorkFlowService.java new file mode 100644 index 0000000..6e175cf --- /dev/null +++ b/src/main/java/com/api/xuanran/wang/saic_travel/model_create_workflow/service/CreateWorkFlowService.java @@ -0,0 +1,233 @@ +package com.api.xuanran.wang.saic_travel.model_create_workflow.service; + +import aiyh.utils.ApiResult; +import aiyh.utils.Util; +import aiyh.utils.excention.CustomerException; +import com.alibaba.fastjson.JSONObject; +import com.icbc.api.internal.apache.http.impl.cookie.S; +import org.apache.commons.collections.CollectionUtils; +import org.apache.commons.collections.MapUtils; +import org.apache.commons.lang3.StringUtils; +import org.apache.log4j.Logger; +import weaver.conn.RecordSet; +import weaver.general.TimeUtil; +import weaver.xuanran.wang.common.mapper.CommonMapper; +import weaver.xuanran.wang.common.util.CommonUtil; +import weaver.xuanran.wang.common.util.CusInfoToOAUtil; +import weaver.xuanran.wang.saic_travel.model_data_async.config.eneity.DataAsyncDetail; +import weaver.xuanran.wang.saic_travel.model_data_async.config.eneity.DataAsyncMain; +import weaver.xuanran.wang.saic_travel.model_data_async.constant.DataAsyncConstant; +import weaver.xuanran.wang.saic_travel.model_data_async.service.DataAsyncConfigService; + +import java.util.*; +import java.util.stream.Collectors; + +/** + *

+ * + * @Author xuanran.wang + * @Date 2022/12/15 14:33 + */ +public class CreateWorkFlowService { + + private final DataAsyncConfigService dataAsyncConfigService = new DataAsyncConfigService(); + private final CommonMapper commonMapper = Util.getMapper(CommonMapper.class); + private final Logger logger = Util.getLogger(); + + /** + *

人员绩效创建流程

+ * @author xuanran.wang + * @dateTime 2022/12/15 17:07 + * @param choiceData 选择的数据 + * @param createDateField 创建日期字段 + * @param triggerWorkflowSetId 数据审批id + * @param modelId 模块id + * @return 流程创建失败的数据id + **/ + public List hrmCusCreateWorkFlow(String choiceData, String createDateField, String triggerWorkflowSetId, int modelId){ + String name = commonMapper.getModelNameByModelId(String.valueOf(modelId)); + List dataList = Arrays.stream(choiceData.split(",")).collect(Collectors.toList()); + RecordSet rs = new RecordSet(); + List> splitList = CommonUtil.splitList(dataList); + for (List list : splitList) { + List ids = list.stream().map(item -> Util.getIntValue(item, -1)).collect(Collectors.toList()); + if(CollectionUtils.isEmpty(ids)){ + continue; + } + String updateCreatDateSql = "update " + name + " set " + createDateField + " = '"+ TimeUtil.getCurrentDateString() +"' where id in ( " + StringUtils.join(ids,",") + " )"; + if(!rs.executeUpdate(updateCreatDateSql)){ + throw new CustomerException(Util.logStr("更新建模表数据失败!, 当前sql : {} ", updateCreatDateSql)); + } + } + // 数据审批配置Id + String[] triggerIds = triggerWorkflowSetId.split(","); + logger.info("triggerIds : " + JSONObject.toJSONString(triggerIds)); + List errorData = new ArrayList<>(); + for (String id : triggerIds) { + String sql = "select id from " + name; + String condition = commonMapper.getConditionByTriggerId(id); + if(StringUtils.isNotBlank(condition)){ + sql += " where " + condition; + } + logger.info(Util.logStr("人员创建流程查询数据sql : {}", sql)); + List filterIds = filterIds(sql); + List dataIds = dataList.stream().filter(filterIds::contains).collect(Collectors.toList()); + if(CollectionUtils.isNotEmpty(dataIds)){ + List requestIds = CommonUtil.doCreateWorkFlow(modelId, dataIds, Util.getIntValue(id, -1)); // 通过数据审批生成流程 + for (int i = 0; i < requestIds.size(); i++) { + if (Util.getIntValue(requestIds.get(i), -1) < 0) { + errorData.add(dataList.get(i)); + } + } + }else { + logger.info("当前数据都不满足触发条件!"); + } + logger.error(Util.logStr("人员创建流程执行创建流程失败集合: {}",JSONObject.toJSONString(errorData))); // 构建日志字符串 + } + return errorData; + } + + /** + *

+ * @author xuanran.wang + * @dateTime 2022/12/15 17:11 + * @param createTriggerId 勾选数据模块 数据审批id + * @param dataModelId 勾选数据的模块id + * @param asyncCode 数据同步配置 + * @param choiceData 选择的数据 + * @param dataApprovalModelId 创建流程的模块id + * @return requestId + **/ + public String supplierCusCreateWorkFlow(String createTriggerId, String dataModelId, String asyncCode, String choiceData, int dataApprovalModelId){ + // 查询来源数据待合并 数据审批配置 + Map configByTriggerId = commonMapper.getConfigByTriggerId(String.valueOf(createTriggerId)); + if(MapUtils.isEmpty(configByTriggerId)){ + return ApiResult.error(403,"请给模块id = [ "+createTriggerId + " ] 配置数据审批!"); + } + // 待合并的表名 + String dataTable = commonMapper.getModelNameByModelId(dataModelId); + String sql = "select id from " + dataTable; + // 触发条件 + String condition = Util.null2DefaultStr(configByTriggerId.get("showcondition"), ""); + String successWriteBack = Util.null2DefaultStr(configByTriggerId.get("successwriteback"), ""); + if(StringUtils.isNotBlank(condition)){ + sql += " where " + condition; + } + List dataList = Arrays.stream(choiceData.split(",")).collect(Collectors.toList()); + logger.info(Util.logStr("查询数据sql : {}", sql)); + List filterIds = filterIds(sql); + // 过滤之后的数据id + List dataIds = dataList.stream().filter(filterIds::contains).collect(Collectors.toList()); + List requestIds = new ArrayList<>(); + if(!CollectionUtils.isEmpty(dataIds)){ + String dataId = asyncModelData(asyncCode, dataIds, dataApprovalModelId); + requestIds = CommonUtil.doCreateWorkFlow(dataApprovalModelId, Collections.singletonList(dataId)); + if(CollectionUtils.isEmpty(requestIds)){ + throw new CustomerException("流程创建失败!"); + } + if(CollectionUtils.isNotEmpty(requestIds) && !(Util.getIntValue(requestIds.get(0),-1) < 0 && StringUtils.isNotBlank(successWriteBack))){ + RecordSet rs = new RecordSet(); + sql = "update " + dataTable + " set " + successWriteBack + " where " + Util.getSubINClause(StringUtils.join(dataIds, ","),"id"," in "); + if (!rs.executeUpdate(sql)) { + logger.error(Util.logStr("回写sql : {}", sql)); + throw new CustomerException("流程创建成功, 但回写失败!"); + } + } + return requestIds.get(0); + }else { + logger.info("当前数据都不满足触发条件!"); + } + return ""; + } + + + /** + *

通过配置数据同步至建模

+ * @author xuanran.wang + * @dateTime 2022/12/2 13:28 + * @param configCode 配置标识 + * @param modelId 模块id + **/ + public String asyncModelData(String configCode, List dataIds, int modelId) { + DataAsyncMain asyncConfig = dataAsyncConfigService.getDataAsyncConfigByUniqueCode(configCode); + String dataSource = asyncConfig.getDataSource(); + String selectSql = dataAsyncConfigService.getSelectSql(asyncConfig); + List asyncDetailList = asyncConfig.getDataAsyncDetailList(); + selectSql += " where " + Util.getSubINClause(StringUtils.join(dataIds, ","),"id"," in "); + RecordSet rs = new RecordSet(); + if (!rs.executeQuery(selectSql)) { + throw new CustomerException(Util.logStr("执行查询数据源sql失败! 当前sql:{}", selectSql)); + } + // 主表同步配置条件 + List mainConfigList = asyncDetailList.stream().filter(item -> !DataAsyncConstant.DETAIL_TABLE.equals(item.getMainOrDetail())).collect(Collectors.toList()); + List detailConfigList = asyncDetailList.stream().filter(item -> DataAsyncConstant.DETAIL_TABLE.equals(item.getMainOrDetail())).collect(Collectors.toList()); + String mainId = ""; + if (rs.next()){ + // 先把数据同步到主表 + LinkedHashMap params = getValue(mainConfigList, rs, dataSource); + mainId = CusInfoToOAUtil.getDataId(modelId, params); + logger.info("生成建模mainId : " + mainId); + } + rs.executeQuery(selectSql); + ArrayList> detailParams = new ArrayList<>(); + while (rs.next()){ + LinkedHashMap value = getValue(detailConfigList, rs, dataSource); + value.put("mainid", mainId); + detailParams.add(value); + } + CusInfoToOAUtil.executeDetailBatch(asyncConfig.getAsyncTargetModelTableName()+ "_dt" + asyncConfig.getDetailIndex(),detailParams); + return mainId; + } + + /** + *

转换值

+ * @author xuanran.wang + * @dateTime 2022/12/15 16:29 + * @param asyncDetailList 配置集合 + * @param rs 结果集 + * @param dataSource 数据来源 + * @return 自定义表插入参数 + **/ + public LinkedHashMap getValue(List asyncDetailList, RecordSet rs, String dataSource){ + LinkedHashMap map = new LinkedHashMap<>(); + for (DataAsyncDetail dataAsyncDetail : asyncDetailList) { + String field = ""; + switch (dataSource){ + case DataAsyncConstant.DATA_SOURCE_MODEL:{ + field = dataAsyncDetail.getDataSourceModelFiledName(); + }break; + case DataAsyncConstant.DATA_SOURCE_CUS_TABLE:{ + field = dataAsyncDetail.getCusTableField(); + }break; + default:throw new CustomerException("暂不支持的数据来源"); + } + // 同步建模字段 + String asyncModelTableField = dataAsyncDetail.getAsyncModelTableField(); + Object value = dataAsyncConfigService.getFieldValue(rs, field, dataAsyncDetail, 0); + map.put(asyncModelTableField, value); + } + if(MapUtils.isEmpty(map)){ + throw new CustomerException("转换配置生成参数map为空!"); + } + return map; + } + + /** + *

获取数据id

+ * @author xuanran.wang + * @dateTime 2022/12/15 13:22 + * @param sql 获取执行条件sql + * @return 数据id + **/ + public List filterIds(String sql){ + RecordSet rs = new RecordSet(); + ArrayList res = new ArrayList<>(); + if (rs.executeQuery(sql)) { + while (rs.next()){ + res.add(Util.null2DefaultStr(rs.getString(1),"")); + } + } + return res; + } + +} diff --git a/src/main/java/weaver/xuanran/wang/bme/action/ContractApplyComDateAction.java b/src/main/java/weaver/xuanran/wang/bme/action/ContractApplyComDateAction.java new file mode 100644 index 0000000..000e4d5 --- /dev/null +++ b/src/main/java/weaver/xuanran/wang/bme/action/ContractApplyComDateAction.java @@ -0,0 +1,91 @@ +package weaver.xuanran.wang.bme.action; + +import aiyh.utils.Util; +import aiyh.utils.action.SafeCusBaseAction; +import aiyh.utils.annotation.RequiredMark; +import aiyh.utils.excention.CustomerException; +import org.apache.commons.lang3.StringUtils; +import weaver.conn.RecordSetTrans; +import weaver.hrm.User; +import weaver.soa.workflow.request.RequestInfo; + +import java.util.Map; + +/** + *

柏美施工合同修改日期action

+ * + * @Author xuanran.wang + * @Date 2022/12/20 11:33 + */ +public class ContractApplyComDateAction extends SafeCusBaseAction { + + /** + *

施工合同项目字段

+ **/ + @RequiredMark + private String buildContractProjectField; + /** + *

施工合同主表名

+ **/ + @RequiredMark + private String buildContractTable; + /** + *

施工合同明细表表名

+ **/ + @RequiredMark + private String detailContractTable; + /** + *

施工合同明细表更新日期字段

+ **/ + @RequiredMark + private String detailContractDateFiled; + /** + *

验收流程项目字段

+ **/ + @RequiredMark + private String projectField; + /** + *

验收流程日期字段

+ **/ + @RequiredMark + private String checkDateField; + /** + *

明细表更新验收日期的条件

+ **/ + private String updateWhere; + + @Override + public void doSubmit(String requestId, String billTable, int workflowId, User user, RequestInfo requestInfo) { + RecordSetTrans rs = requestInfo.getRsTrans(); + rs.setAutoCommit(false); + try { + Map mainTableValue = getMainTableValue(requestInfo); + // 验收流程的实际验收日期 + String checkDate = mainTableValue.get(checkDateField); + String project = mainTableValue.get(projectField); + if(StringUtils.isBlank(checkDate) || StringUtils.isBlank(project)){ + log.error(Util.logStr("checkDate:{}, project:{}", checkDate, project)); + throw new CustomerException("实际验收日期或项目字段字段为空!"); + } + String selectSql = "select id from " + buildContractTable + " where " + buildContractProjectField + " = ?"; + if(rs.executeQuery(selectSql, project) && rs.next()){ + String mainId = rs.getString("id"); + String updateSql = "update " + detailContractTable + " set " + detailContractDateFiled + " = ? where mainid = ?"; + if(StringUtils.isNotBlank(updateWhere)){ + updateSql += " and " + updateWhere; + } + if(!rs.executeUpdate(updateSql, checkDate, mainId)){ + log.error(Util.logStr("更新合同明细表sql:{}, 参数:{}", updateSql, new String[]{checkDate, mainId})); + throw new CustomerException("更新合同sql错误!"); + } + rs.commit(); + }else{ + log.error(Util.logStr("查询施工合同关联项目sql : {}", selectSql)); + } + }catch (Exception e){ + rs.rollback(); + throw new CustomerException(Util.logStr("更新施工合同实际验收日期发生异常: {} ", e.getMessage())); + } + } + +} diff --git a/src/main/java/weaver/xuanran/wang/bme/action/CusCreateWaterNoAction.java b/src/main/java/weaver/xuanran/wang/bme/action/CusCreateWaterNoAction.java new file mode 100644 index 0000000..ca7d9eb --- /dev/null +++ b/src/main/java/weaver/xuanran/wang/bme/action/CusCreateWaterNoAction.java @@ -0,0 +1,111 @@ +package weaver.xuanran.wang.bme.action; + +import aiyh.utils.Util; +import aiyh.utils.action.SafeCusBaseAction; +import aiyh.utils.annotation.RequiredMark; +import aiyh.utils.excention.CustomerException; +import weaver.conn.RecordSet; +import weaver.conn.RecordSetTrans; +import weaver.hrm.User; +import weaver.soa.workflow.request.RequestInfo; +import weaver.xuanran.wang.common.util.CommonUtil; +import weaver.xuanran.wang.common.util.CusInfoToOAUtil; + +import java.util.LinkedHashMap; +import java.util.Map; + +/** + *

柏美存货档案流程生成流水号

+ *

+ * 流程主表的存货档案编码生成流水号 格式:存货分类编码 + 4位流水号 DUJE0101 DUJE0199 => DUJE0201 + *

+ * + * @Author xuanran.wang + * @Date 2022/12/22 13:18 + */ +public class CusCreateWaterNoAction extends SafeCusBaseAction { + + /** + *

存货分类编码字段

+ **/ + @RequiredMark + private String invClassificationCode; + + /** + *

存货编码 生成编号后写入这个字段

+ **/ + @RequiredMark + private String inventoryCode; + + /** + *

生成流水号日志记录模块id

+ **/ + private String serialNumberModelId; + + private static final String START_NO = "0101"; + + @Override + public void doSubmit(String requestId, String billTable, int workflowId, User user, RequestInfo requestInfo) { + log.info("----------- CusCreateWaterNoAction Begin " + requestId + "-----------"); + RecordSetTrans rsts = new RecordSetTrans(); + rsts.setAutoCommit(false); + try { + Map mainTableValue = getMainTableValue(requestInfo); + String invClassificationCodeVal = mainTableValue.get(invClassificationCode); + String nextInventoryCode = getNextInventoryCode(invClassificationCodeVal); + String updateSql = "update " + billTable + " set " + inventoryCode + " = ? where requestid = ?"; + if(!rsts.executeUpdate(updateSql, nextInventoryCode, requestId)){ + log.error(Util.logStr("sql :{}, nextInventoryCode : {}, requestId: {}", updateSql, nextInventoryCode, requestId)); + throw new CustomerException("更新表单存货编码字段失败!"); + } + }catch (Exception e){ + throw new CustomerException(Util.logStr("生成存货编码Action异常: [{}]",e.getMessage())); + } + } + + /** + *

根据分类编码获取下一个流水号

+ * @author xuanran.wang + * @dateTime 2022/12/22 14:08 + * @param inventoryCode 分类编码 + * @return 分类编码+四位流水号 + **/ + private synchronized String getNextInventoryCode(String inventoryCode){ + RecordSet rs = new RecordSet(); + String modelTableName = CommonUtil.getModelTableNameById(Util.getIntValue(serialNumberModelId, -1)); + String sql = "select max(serialNumber) serialNumber from " + modelTableName + " where invClassificationCode = ? order by createDateTime"; + String res = ""; + if(rs.executeQuery(sql, inventoryCode)){ + if (!rs.next()) { + res = inventoryCode + START_NO; + }else { + String serialNumber = rs.getString(1); + String front = serialNumber.substring(0,2); + String end = serialNumber.substring(3); + int frontInt = Util.getIntValue(front); + int endInt = Util.getIntValue(end); + String endStr = ""; + String frontStr = ""; + if(++endInt >= 100){ + frontInt += 1; + endInt = 1; + } + if(endInt < 10){ + endStr = "0" + endInt; + } + if(frontInt < 10){ + frontStr = "0" + frontInt; + } + res = frontStr + endStr; + } + } + LinkedHashMap map = new LinkedHashMap<>(); + map.put("invClassificationCode", inventoryCode); + map.put("serialNumber", res); + map.put("serialCode", inventoryCode + res); + CusInfoToOAUtil.getDataId(Util.getIntValue(serialNumberModelId, -1), map); + return res; + } + + +} \ No newline at end of file diff --git a/src/main/java/weaver/xuanran/wang/common/mapper/CommonMapper.java b/src/main/java/weaver/xuanran/wang/common/mapper/CommonMapper.java index 7520a12..b932268 100644 --- a/src/main/java/weaver/xuanran/wang/common/mapper/CommonMapper.java +++ b/src/main/java/weaver/xuanran/wang/common/mapper/CommonMapper.java @@ -50,4 +50,11 @@ public interface CommonMapper { "ON mp.id = mpd.mainId " + "WHERE mp.modeid = #{modelId} AND mp.isSystem = 1 AND mp.iSSystemFlag = 1") Map getExpendConfigByModeId(@ParamMapper("modelId") int modelId); + + @Select("select * from mode_triggerworkflowset where id = #{triggerId}") + Map getConfigByTriggerId(@ParamMapper("triggerId") String triggerId); + + @Select("select showcondition from mode_triggerworkflowset where id = #{triggerId}") + String getConditionByTriggerId(@ParamMapper("triggerId") String triggerId); + } diff --git a/src/main/java/weaver/xuanran/wang/common/util/CommonUtil.java b/src/main/java/weaver/xuanran/wang/common/util/CommonUtil.java index f1c9c82..0a037d3 100644 --- a/src/main/java/weaver/xuanran/wang/common/util/CommonUtil.java +++ b/src/main/java/weaver/xuanran/wang/common/util/CommonUtil.java @@ -232,6 +232,16 @@ public class CommonUtil { } } + /** + *

将集合进行分割

+ * @author xuanran.wang + * @dateTime 2022/11/25 16:01 + * @param list 待分割的集合 + * @return 分割集合 + **/ + public static List> splitList(List list) { + return splitList(list, SQL_IN_PAGE_SIZE); + } /** *

将集合进行分割

* @author xuanran.wang @@ -337,6 +347,9 @@ public class CommonUtil { * @return true/false **/ public static boolean deleteDataByIds(List ids, String tableName,int pageSize) { + if(CollectionUtils.isEmpty(ids)){ + return true; + } List> lists = CommonUtil.splitList(ids, pageSize); for (List list : lists) { boolean success = commonMapper.deleteModelDataByIds(tableName, list); @@ -526,4 +539,61 @@ public class CommonUtil { return requestIds; } + /** + *

通过数据审批生成流程

+ * @author xuanran.wang + * @dateTime 2022/12/1 21:14 + * @param modeId 模块id + * @param dataIds 模块数据id集合 + * @param triggerWorkflowSetId 数据审批id + **/ + public static List doCreateWorkFlow(int modeId, List dataIds, int triggerWorkflowSetId){ + if(modeId < 0){ + throw new CustomerException("模块id不能小于0!"); + } + if(triggerWorkflowSetId < 0){ + throw new CustomerException("自定义数据审批id不能小于0!"); + } + if(org.springframework.util.CollectionUtils.isEmpty(dataIds)){ + logger.info("暂无数据要生成流程!"); + return Collections.emptyList(); + } + Map expendConfig = commonMapper.getExpendConfigByModeId(modeId); + logger.info(Util.logStr("expendConfig :{}", JSONObject.toJSONString(expendConfig))); + int expendId = expendConfig.get("id"); + int formId = expendConfig.get("formId"); + ArrayList requestIds = new ArrayList<>(); + if(expendId > 0 && triggerWorkflowSetId > 0){ + for (String daId : dataIds) { + ModeDataApproval modeDataApproval = new ModeDataApproval(); + modeDataApproval.setUser(new User(1)); + modeDataApproval.setBillid(Util.getIntValue(daId)); + modeDataApproval.setFormid(formId); + modeDataApproval.setModeid(modeId); + modeDataApproval.setTriggerWorkflowSetId(triggerWorkflowSetId); + modeDataApproval.setPageexpandid(expendId); + Map resMap = modeDataApproval.approvalDataResult(); + logger.info(Util.logStr("模块数据id : {}, 创建流程结果 : {}", daId, JSONObject.toJSONString(resMap))); + requestIds.add(Util.null2String(resMap.get("requestid"))); + } + } + return requestIds; + } + + /** + *

根据模块id获取表名

+ * @author xuanran.wang + * @dateTime 2022/12/22 14:18 + * @param modelId 模块id + * @return 模块表名 + **/ + public static String getModelTableNameById(int modelId){ + if(modelId < 0){ + throw new CustomerException("模块id不能小于0!"); + } + return commonMapper.getModelNameByModelId(String.valueOf(modelId)); + } + + + } diff --git a/src/main/java/weaver/xuanran/wang/common/util/CusInfoToOAUtil.java b/src/main/java/weaver/xuanran/wang/common/util/CusInfoToOAUtil.java index b02e57f..125fd16 100644 --- a/src/main/java/weaver/xuanran/wang/common/util/CusInfoToOAUtil.java +++ b/src/main/java/weaver/xuanran/wang/common/util/CusInfoToOAUtil.java @@ -16,6 +16,7 @@ import weaver.general.TimeUtil; import weaver.xuanran.wang.common.mapper.CommonMapper; import java.util.*; +import java.util.stream.Collectors; /** * @Author xuanran.wang @@ -26,7 +27,7 @@ public class CusInfoToOAUtil { private static final ModeDataIdUpdate modeDataIdUpdate = ModeDataIdUpdate.getInstance(); private static final ModeRightInfo moderightinfo = new ModeRightInfo(); private static final Logger log = Util.getLogger(); - public static final String TABLE_NAME_PLACEHOLDER = "#\\{tableName}"; + private static final String TABLE_NAME_PLACEHOLDER = "#\\{tableName}"; /** *

将自定义信息写入建模

@@ -74,7 +75,7 @@ public class CusInfoToOAUtil { String whereSql, List whereParams, boolean needDel) { - return executeBatch(modelId, Collections.singletonList(new LinkedHashMap<>(params)), whereSql, whereParams, needDel).get(0); + return executeBatch(modelId, Collections.singletonList(new LinkedHashMap<>(params)), whereSql,Collections.singletonList(whereParams), needDel, Collections.emptyList()).get(0); } /** @@ -87,7 +88,7 @@ public class CusInfoToOAUtil { **/ public static List executeBatch( int modelId, List> params) { - return executeBatch(modelId, params, "", Collections.emptyList(), true); + return executeBatch(modelId, params, "", Collections.emptyList()); } /** @@ -111,8 +112,13 @@ public class CusInfoToOAUtil { if(StringUtils.isBlank(tableName)){ throw new CustomerException("模块id为 " + modelId + ", 在系统中暂没查询到对应表单!"); } - return executeBatch(modelId, tableName, params, whereSql, whereParams, true); + ArrayList> lists = new ArrayList<>(); + for (String param : whereParams) { + lists.add(new ArrayList<>(Collections.singleton(param))); + } + return executeBatch(modelId, tableName, params, whereSql, lists, true, Collections.emptyList()); } + /** *

将自定义信息写入建模

* @author xuanran.wang @@ -124,11 +130,12 @@ public class CusInfoToOAUtil { * @param needDel 更新失败是否需要删除已经插入的数据 * @return 建模数据id集合 **/ - public static List executeBatch( int modelId, - List> params, - String whereSql, - List whereParams, - boolean needDel) { + public static List executeBatch( int modelId, + List> params, + String whereSql, + List> whereParams, + boolean needDel, + List> updateParams) { if(modelId < 0){ throw new RuntimeException("建模模块id不能小于0!"); } @@ -136,7 +143,7 @@ public class CusInfoToOAUtil { if(StringUtils.isBlank(tableName)){ throw new CustomerException("模块id为 " + modelId + ", 在系统中暂没查询到对应表单!"); } - return executeBatch(modelId, tableName, params, whereSql, whereParams, needDel); + return executeBatch(modelId, tableName, params, whereSql, whereParams, needDel, updateParams); } /** @@ -149,57 +156,75 @@ public class CusInfoToOAUtil { * @param whereSql 重复数据条件sql * @param whereParams 重复数据参数集合 * @param needDel 更新失败是否需要删除已经插入的数据 + * @param updateParams 更新某条数据的部分字段 * @return 建模数据id集合 **/ public static List executeBatch( int modelId, String tableName, List> params, String whereSql, - List whereParams, - boolean needDel) { + List> whereParams, + boolean needDel, + List> updateParams) { + // 如果要对模块数据中重复的进行更新则判断待插入的集合大小和判断重复的集合大小参数长度是否一致 if(StringUtils.isNotBlank(whereSql)){ if(CollectionUtils.isEmpty(whereParams) || CollectionUtils.isEmpty(params) || whereParams.size() != params.size()){ + log.error(Util.logStr("params : {}", JSONObject.toJSONString(params))); + log.error(Util.logStr("whereSql : {}", whereSql)); + log.error(Util.logStr("whereParams : {} ", JSONObject.toJSONString(whereParams))); + log.error(Util.logStr("updateParams : {} ", updateParams)); throw new CustomerException("使用批量更新时如果需要对重复数据进行更新,参数集合和判断重复参数集合大小必须相等!"); } } RecordSet rs = new RecordSet(); List dataIds = new ArrayList<>(); - List wheres = new ArrayList<>(); + List paramsWheres = new ArrayList<>(); + List updateWheres = new ArrayList<>(); + whereSql = Util.sbc2dbcCase(whereSql); + whereSql = whereSql.replaceAll(TABLE_NAME_PLACEHOLDER, tableName); + // 需要插入的建模参数 + List> tempParams = new ArrayList<>(); + // 如果建模中已经存在只想更新部分字段参数 + List> tempUpdateParams = new ArrayList<>(); for (int i = 0; i < params.size(); i++) { int mainId = -1; if(StringUtils.isNotBlank(whereSql)){ - whereSql = Util.sbc2dbcCase(whereSql); - whereSql = whereSql.replaceAll(TABLE_NAME_PLACEHOLDER, tableName); - if (rs.executeQuery(whereSql, whereParams) && rs.next()) { + // 如果匹配到数据 + if (rs.executeQuery(whereSql, whereParams.get(i)) && rs.next()) { mainId = Util.getIntValue(rs.getString(1),-1); + updateWheres.add(Util.createPrepWhereImpl().whereAnd("id").whereEqual(mainId)); + dataIds.add(String.valueOf(mainId)); + if(!CollectionUtils.isEmpty(updateParams)){ + tempUpdateParams.add(updateParams.get(i)); + }else { + tempUpdateParams.add(params.get(i)); + } }else { - log.info("whereSql : " + whereSql); - log.info("参数 : " + whereParams); + log.info(Util.logStr("==== 未匹配到数据 ==== whereSql : {}, 参数 : {}", whereSql, JSONObject.toJSONString(whereParams.get(i)))); } } if(mainId < 0){ mainId = getNewIdByModelInfo(tableName, modelId); + paramsWheres.add(Util.createPrepWhereImpl().whereAnd("id").whereEqual(mainId)); + dataIds.add(String.valueOf(mainId)); + tempParams.add(params.get(i)); } - dataIds.add(String.valueOf(mainId)); - wheres.add(Util.createPrepWhereImpl().whereAnd("id").whereEqual(mainId)); } - BatchSqlResultImpl batchSql = Util.createSqlBuilder().updateBatchSql(tableName, params, wheres); - String sqlStr = batchSql.getSqlStr(); - List batchList = batchSql.getBatchList(); - if(!rs.executeBatchSql(sqlStr, batchList)){ - log.error(Util.logStr("batchSql:{}", sqlStr)); - log.error(Util.logStr("batchList:{}", JSONObject.toJSONString(batchList))); - log.error(Util.logStr("whereList:{}", JSONObject.toJSONString(wheres))); + try { + if(CollectionUtils.isNotEmpty(tempParams) && CollectionUtils.isNotEmpty(paramsWheres)){ + execute(tableName, tempParams, paramsWheres); + } + if(CollectionUtils.isNotEmpty(tempUpdateParams) && CollectionUtils.isNotEmpty(updateWheres)){ + execute(tableName, tempUpdateParams, updateWheres); + } + }catch (Exception e){ if(needDel){ if (!deleteModelDataByIds(String.valueOf(modelId), dataIds)) { log.error(Util.logStr("删除数据失败!未删除数据集合:{}", JSONObject.toJSONString(dataIds))); } } - throw new CustomerException("执行批量更新sql失败!"); - } - if(CollectionUtils.isEmpty(dataIds)){ - throw new CustomerException("建模数据生成失败!"); + throw new CustomerException(e.getMessage()); } for (String dataId : dataIds) { moderightinfo.rebuildModeDataShareByEdit(1, modelId, Integer.parseInt(dataId)); @@ -207,6 +232,49 @@ public class CusInfoToOAUtil { return dataIds; } + /** + *

将自定义信息写入建模明细表

+ * @author xuanran.wang + * @dateTime 2022/11/23 17:00 + * @param tableName 表名 + * @param params 需要插入的数据map + * @return 建模数据id集合 + **/ + public static boolean executeDetailBatch(String tableName, List> params){ + RecordSet rs = new RecordSet(); + BatchSqlResultImpl batchSql = Util.createSqlBuilder().insertBatchSql(tableName, params); + String sqlStr = batchSql.getSqlStr(); + List list = batchSql.getBatchList(); + if (!rs.executeBatchSql(sqlStr, list)) { + throw new CustomerException(Util.logStr("明细数据插入失败! sql : {}, params : {}", sqlStr, JSONObject.toJSONString(list))); + } + return true; + } + + /** + *

批量写入建模

+ * @author xuanran.wang + * @dateTime 2022/12/15 10:53 + * @param tableName 表名 + * @param params 建模参数 + * @param wheres where条件 + **/ + public static void execute(String tableName, List> params, List wheres){ +// log.info(Util.logStr("params : [{}],size : [{}]", JSONObject.toJSONString(params), params.size())); +// log.info(Util.logStr("wheres : [{}],size : [{}]", JSONObject.toJSONString(wheres), wheres.size())); + BatchSqlResultImpl batchSql = Util.createSqlBuilder().updateBatchSql(tableName, params, wheres); + String sqlStr = batchSql.getSqlStr(); + List batchList = batchSql.getBatchList(); + RecordSet rs = new RecordSet(); + if(!rs.executeBatchSql(sqlStr, batchList)){ + log.error(Util.logStr("batchSql:{}", sqlStr)); + log.error(Util.logStr("batchList:{}", JSONObject.toJSONString(batchList))); + log.error(Util.logStr("whereList:{}", JSONObject.toJSONString(wheres))); + throw new CustomerException("执行批量更新sql失败!请查看后台cus日志!"); + } + } + + /** *

删除建模数据

* @author xuanran.wang @@ -219,6 +287,14 @@ public class CusInfoToOAUtil { String tableName = commonMapper.getModelNameByModelId(modelId); return commonMapper.deleteModelDataByIds(tableName, ids); } + /** + *

获取建模数据id

+ * @author xuanran.wang + * @dateTime 2022/12/15 10:56 + * @param modelTableName 表名 + * @param modelId 模块id + * @return 新的建模数据id + **/ private static Integer getNewIdByModelInfo(String modelTableName, int modelId){ String currentDateTime = TimeUtil.getCurrentTimeString(); //日期 diff --git a/src/main/java/weaver/xuanran/wang/epdi/datapush/eneity/DetailRequestConfig.java b/src/main/java/weaver/xuanran/wang/epdi/datapush/eneity/DetailRequestConfig.java new file mode 100644 index 0000000..f227c77 --- /dev/null +++ b/src/main/java/weaver/xuanran/wang/epdi/datapush/eneity/DetailRequestConfig.java @@ -0,0 +1,21 @@ +package weaver.xuanran.wang.epdi.datapush.eneity; + + +import lombok.Data; + +/** + * @Author xuanran.wang + * @Date 2022/6/18 16:47 + */ +@Data +public class DetailRequestConfig { + private String paramName; + private String paramType; + private String getValueType; + private String valueContext; + private String tableName; + private String workFlowField; + private String fieldName; + private String detailId; + private String parentName; +} diff --git a/src/main/java/weaver/xuanran/wang/epdi/datapush/eneity/MainRequestConfig.java b/src/main/java/weaver/xuanran/wang/epdi/datapush/eneity/MainRequestConfig.java new file mode 100644 index 0000000..bf884f1 --- /dev/null +++ b/src/main/java/weaver/xuanran/wang/epdi/datapush/eneity/MainRequestConfig.java @@ -0,0 +1,25 @@ +package weaver.xuanran.wang.epdi.datapush.eneity; + + +import lombok.Data; + +import java.util.List; + +/** + * @Author xuanran.wang + * @Date 2022/6/18 15:43 + */ +@Data +public class MainRequestConfig { + private String id; + private String uniqueCode; + private String workflow; + private String requestUrl; + private String dataSource; + private String detailIndex; + private String cusSql; + private String configFilePath; + private String enable; + private String methodParameterClassName; + private List detailRequestConfigList; +} diff --git a/src/main/java/weaver/xuanran/wang/saic_travel/model_data_async/config/eneity/DataAsyncDetail.java b/src/main/java/weaver/xuanran/wang/saic_travel/model_data_async/config/eneity/DataAsyncDetail.java index b5ac556..45ad0fc 100644 --- a/src/main/java/weaver/xuanran/wang/saic_travel/model_data_async/config/eneity/DataAsyncDetail.java +++ b/src/main/java/weaver/xuanran/wang/saic_travel/model_data_async/config/eneity/DataAsyncDetail.java @@ -5,7 +5,7 @@ import lombok.*; import java.sql.Timestamp; /** - *

+ *

数据同步配置实体类

* * @Author xuanran.wang * @Date 2022/12/1 14:01 @@ -48,4 +48,16 @@ public class DataAsyncDetail { *

数据来源建模字段名称

**/ private String dataSourceModelFiledName; + /** + *

更新条件

+ **/ + private String updateCriteria; + /** + *

更新字段

+ **/ + private String updateField; + /** + *

主表还是明细表

+ **/ + private String mainOrDetail; } diff --git a/src/main/java/weaver/xuanran/wang/saic_travel/model_data_async/config/eneity/DataAsyncMain.java b/src/main/java/weaver/xuanran/wang/saic_travel/model_data_async/config/eneity/DataAsyncMain.java index 63d4dd2..3b8cbf7 100644 --- a/src/main/java/weaver/xuanran/wang/saic_travel/model_data_async/config/eneity/DataAsyncMain.java +++ b/src/main/java/weaver/xuanran/wang/saic_travel/model_data_async/config/eneity/DataAsyncMain.java @@ -22,5 +22,6 @@ public class DataAsyncMain { private String cusWhere; private String modelTypeTableName; private String asyncTargetModelTableName; + private String detailIndex; private List dataAsyncDetailList; } diff --git a/src/main/java/weaver/xuanran/wang/saic_travel/model_data_async/constant/DataAsyncConstant.java b/src/main/java/weaver/xuanran/wang/saic_travel/model_data_async/constant/DataAsyncConstant.java index 8091b32..7cf6a0a 100644 --- a/src/main/java/weaver/xuanran/wang/saic_travel/model_data_async/constant/DataAsyncConstant.java +++ b/src/main/java/weaver/xuanran/wang/saic_travel/model_data_async/constant/DataAsyncConstant.java @@ -76,4 +76,12 @@ public class DataAsyncConstant { *

转换类型-拆分复制

**/ public static final String CONVERT_RULES_SPLIT_COPY = "5"; + /** + *

主表

+ **/ + public static final String MAIN_TABLE = "0"; + /** + *

明细

+ **/ + public static final String DETAIL_TABLE = "1"; } diff --git a/src/main/java/weaver/xuanran/wang/saic_travel/model_data_async/job/CusDataToModelAsync.java b/src/main/java/weaver/xuanran/wang/saic_travel/model_data_async/job/CusDataToModelAsync.java index 5145d79..63c9725 100644 --- a/src/main/java/weaver/xuanran/wang/saic_travel/model_data_async/job/CusDataToModelAsync.java +++ b/src/main/java/weaver/xuanran/wang/saic_travel/model_data_async/job/CusDataToModelAsync.java @@ -30,9 +30,11 @@ public class CusDataToModelAsync extends BaseCronJob { @Override public void execute() { try { + logger.info("------------ CusDataToModelAsync Begin ------------"); CommonUtil.checkParamNotNull(this); DataAsyncMain dataAsyncConfigByUniqueCode = asyncConfigService.getDataAsyncConfigByUniqueCode(uniqueCode); asyncConfigService.asyncModelData(dataAsyncConfigByUniqueCode, Util.getIntValue(modelId, -1)); + logger.info("------------ CusDataToModelAsync End ------------"); }catch (Exception e){ logger.error(Util.logStr("执行数据同步计划任务失败!异常信息 : {}", e.getMessage())); } diff --git a/src/main/java/weaver/xuanran/wang/saic_travel/model_data_async/mapper/DataAsyncMapper.java b/src/main/java/weaver/xuanran/wang/saic_travel/model_data_async/mapper/DataAsyncMapper.java index f35a416..f105445 100644 --- a/src/main/java/weaver/xuanran/wang/saic_travel/model_data_async/mapper/DataAsyncMapper.java +++ b/src/main/java/weaver/xuanran/wang/saic_travel/model_data_async/mapper/DataAsyncMapper.java @@ -18,6 +18,4 @@ public interface DataAsyncMapper { @CaseConversion(false) RecordSet getRecordSetByCusSql(@SqlString String sql); - - } diff --git a/src/main/java/weaver/xuanran/wang/saic_travel/model_data_async/service/DataAsyncConfigService.java b/src/main/java/weaver/xuanran/wang/saic_travel/model_data_async/service/DataAsyncConfigService.java index c2fc8e8..480ba57 100644 --- a/src/main/java/weaver/xuanran/wang/saic_travel/model_data_async/service/DataAsyncConfigService.java +++ b/src/main/java/weaver/xuanran/wang/saic_travel/model_data_async/service/DataAsyncConfigService.java @@ -2,8 +2,12 @@ package weaver.xuanran.wang.saic_travel.model_data_async.service; import aiyh.utils.Util; import aiyh.utils.excention.CustomerException; +import aiyh.utils.zwl.common.ToolUtil; +import com.alibaba.fastjson.JSONObject; +import org.apache.commons.collections.MapUtils; import org.apache.commons.lang3.StringUtils; import org.apache.log4j.Logger; +import org.jetbrains.annotations.NotNull; import org.springframework.util.Assert; import org.springframework.util.CollectionUtils; import weaver.conn.RecordSet; @@ -62,17 +66,51 @@ public class DataAsyncConfigService { } logger.info("selectSql : " + selectSql); List> linkedHashMapList = new ArrayList<>(); + StringBuilder updateWhereSql = new StringBuilder(); + // 需要更新时候的参数集合 + List> updateLinkedList = new ArrayList<>(); + // 判断是否更新sql的参数 + List> updateWhereParam = new ArrayList<>(); int splitCopy = -1; String splitCopyFiledName = ""; // 复制个数 List splitCopyList = asyncDetailList.stream().filter(item -> DataAsyncConstant.CONVERT_RULES_SPLIT_COPY.equals(item.getConvertRules())).collect(Collectors.toList()); + DataAsyncDetail copyAsyncDetail = null; if(!CollectionUtils.isEmpty(splitCopyList)){ DataAsyncDetail detail = splitCopyList.get(0); + copyAsyncDetail = detail; splitCopy = Util.getIntValue(detail.getCusText(),-1); splitCopyFiledName = Util.null2DefaultStr(detail.getAsyncModelTableField(),""); } + // 更新数据条件 + List updateCriteriaList = asyncDetailList.stream() + .filter(item -> DataAsyncConstant.CONFIG_ENABLE.equals(item.getUpdateCriteria())) + .map(DataAsyncDetail::getAsyncModelTableField) + .collect(Collectors.toList()); + // 更新字段 + List updateFieldList = asyncDetailList.stream() + .filter(item -> DataAsyncConstant.CONFIG_ENABLE.equals(item.getUpdateField())) + .map(DataAsyncDetail::getAsyncModelTableField) + .collect(Collectors.toList()); + // 如果更新条件不为空那么就拼接更新sql + if(!CollectionUtils.isEmpty(updateCriteriaList)){ + StringBuilder sqlSb = new StringBuilder(); + for (int i = 0; i < updateCriteriaList.size(); i++) { + if(i != updateCriteriaList.size() -1 ){ + sqlSb.append(updateCriteriaList.get(i)).append(" = ? and "); + }else { + sqlSb.append(updateCriteriaList.get(i)).append(" = ? "); + } + } + updateWhereSql.append("select id from #{tableName} where ").append(sqlSb); + } while (rs.next()){ + // 建模表插入参数 LinkedHashMap linkedHashMap = new LinkedHashMap<>(); + // 如果数据存在更新参数集合 + LinkedHashMap updateLinkedMap = new LinkedHashMap<>(); + // 更新条件参数 + LinkedHashMap updateParam = new LinkedHashMap<>(); int tempCount = 0; for (DataAsyncDetail dataAsyncDetail : asyncDetailList) { String field = ""; @@ -85,19 +123,49 @@ public class DataAsyncConfigService { }break; default:throw new CustomerException("暂不支持的数据来源"); } + // 同步建模字段 + String asyncModelTableField = dataAsyncDetail.getAsyncModelTableField(); Object value = getFieldValue(rs, field, dataAsyncDetail, tempCount); - linkedHashMap.put(dataAsyncDetail.getAsyncModelTableField(), value); + // 把当前字段和值放到更新条件参数集合中 + if(!CollectionUtils.isEmpty(updateCriteriaList) && updateCriteriaList.contains(asyncModelTableField)){ + updateParam.put(asyncModelTableField, Util.null2DefaultStr(value,"")); + } + // 需要更新时更新字段参数集合 + if(!CollectionUtils.isEmpty(updateCriteriaList) && updateFieldList.contains(asyncModelTableField)){ + updateLinkedMap.put(asyncModelTableField, value); + } + linkedHashMap.put(asyncModelTableField, value); } + updateWhereParam.add(new ArrayList<>(updateParam.values())); linkedHashMapList.add(linkedHashMap); + if(MapUtils.isNotEmpty(updateLinkedMap)){ + updateLinkedList.add(updateLinkedMap); + } // 记录复制 while (++tempCount < splitCopy) { LinkedHashMap copyMap = new LinkedHashMap<>(linkedHashMap); + // 如果更新条件参数map不为空 + if(MapUtils.isNotEmpty(updateLinkedMap)){ + // 需要更新的参数map集合 + LinkedHashMap copyUpdateLinkedMap = new LinkedHashMap<>(updateLinkedMap); + // 如果更新条件中包含拆分复制条件的 + if(copyAsyncDetail != null && updateCriteriaList.contains(copyAsyncDetail.getAsyncModelTableField())){ + updateParam.put(copyAsyncDetail.getAsyncModelTableField(), String.valueOf(tempCount)); + } + // 将拆分复制的值加进去 + if(copyAsyncDetail != null && updateFieldList.contains(copyAsyncDetail.getAsyncModelTableField())){ + copyUpdateLinkedMap.put(splitCopyFiledName, tempCount); + } + updateLinkedList.add(copyUpdateLinkedMap); + updateWhereParam.add(new ArrayList<>(updateParam.values())); + } copyMap.put(splitCopyFiledName, tempCount); linkedHashMapList.add(copyMap); } } - return CusInfoToOAUtil.executeBatch(modelId, linkedHashMapList); + return CusInfoToOAUtil.executeBatch(modelId, linkedHashMapList, updateWhereSql.toString(), updateWhereParam, true, updateLinkedList); } + /** *

根据配置将值转换

* @author xuanran.wang @@ -108,7 +176,7 @@ public class DataAsyncConfigService { * @param count 复制次数 * @return 转换后的值 **/ - public Object getFieldValue(RecordSet recordSet, String field, DataAsyncDetail dataAsyncDetail, int count){ + public Object getFieldValue(RecordSet recordSet, String field, @NotNull DataAsyncDetail dataAsyncDetail, int count){ String convertRules = dataAsyncDetail.getConvertRules(); String dataType = dataAsyncDetail.getDataType(); String cusText = dataAsyncDetail.getCusText(); @@ -131,12 +199,14 @@ public class DataAsyncConfigService { // 自定义sql查询 case DataAsyncConstant.CONVERT_RULES_CUS_SQL: { if(!StringUtils.isBlank(cusText)){ - String cusSql = Util.sbc2dbcCase(cusText); String where = ""; if(StringUtils.isNotBlank(field)){ where = Util.null2DefaultStr(recordSet.getString(field),""); } - tempRs.executeQuery(cusSql, where); + String cusSql = Util.sbc2dbcCase(cusText) + .replace("?",where) + .replace("{main.id}", recordSet.getString("id")); + tempRs.executeQuery(cusSql); if (!tempRs.next()) { logger.error(Util.logStr("执行自定义sql失败!当前sql:{}, 当前参数:{}", cusSql, where)); break; @@ -146,6 +216,7 @@ public class DataAsyncConfigService { }break; case DataAsyncConstant.CONVERT_RULES_DATA_ID: { value = recordSet.getString("id"); + logger.info(Util.logStr("主数据Id : {}", value)); }break; case DataAsyncConstant.CONVERT_RULES_SPLIT_COPY: { value = count; @@ -232,30 +303,33 @@ public class DataAsyncConfigService { * @return 查询数据来源sql **/ public String getSelectSql(DataAsyncMain asyncConfig){ - String dataSource = asyncConfig.getDataSource(); String cusWhere = Util.null2DefaultStr(asyncConfig.getCusWhere(), ""); - String dataSourceTableName = ""; - List asyncDetailList = asyncConfig.getDataAsyncDetailList(); - String selectSql = "select "; - List modelFieldList = new ArrayList<>(); - // 判断数据来源拼接查询sql - switch (dataSource) { - case DataAsyncConstant.DATA_SOURCE_MODEL:{ - modelFieldList = asyncDetailList.stream().map(DataAsyncDetail::getDataSourceModelFiledName).filter(StringUtils::isNotBlank).collect(Collectors.toList()); - dataSourceTableName = asyncConfig.getModelTypeTableName(); - }break; - case DataAsyncConstant.DATA_SOURCE_CUS_TABLE:{ - modelFieldList = asyncDetailList.stream().map(DataAsyncDetail::getCusTableField).filter(StringUtils::isNotBlank).collect(Collectors.toList()); - dataSourceTableName = asyncConfig.getCusTable(); - }break; - default:throw new CustomerException("暂不支持的数据来源!"); - } // 拼接数据源查询sql - selectSql += StringUtils.join(modelFieldList, ",") + " from " + dataSourceTableName; + String selectSql = "select * from " + getTableName(asyncConfig); if(StringUtils.isNotBlank(cusWhere)){ selectSql += " where " + cusWhere; } return selectSql; } + /** + *

根据配置对象获取查询sql

+ * @author xuanran.wang + * @dateTime 2022/12/2 12:56 + * @param asyncConfig 主配置对象 + * @return 查询数据来源sql + **/ + public String getTableName(DataAsyncMain asyncConfig){ + // 判断数据来源拼接查询sql + switch (asyncConfig.getDataSource()) { + case DataAsyncConstant.DATA_SOURCE_MODEL:{ + return asyncConfig.getModelTypeTableName(); + } + case DataAsyncConstant.DATA_SOURCE_CUS_TABLE:{ + return asyncConfig.getCusTable(); + } + default:throw new CustomerException("暂不支持的数据来源!"); + } + } + } diff --git a/src/main/java/weaver/xuanran/wang/schroeder/action/PushSealTaskAction.java b/src/main/java/weaver/xuanran/wang/schroeder/action/PushSealTaskAction.java index f88d2b3..ca81f9e 100644 --- a/src/main/java/weaver/xuanran/wang/schroeder/action/PushSealTaskAction.java +++ b/src/main/java/weaver/xuanran/wang/schroeder/action/PushSealTaskAction.java @@ -1,19 +1,23 @@ package weaver.xuanran.wang.schroeder.action; import aiyh.utils.Util; -import aiyh.utils.action.CusBaseAction; // 基础的action,实现一些基础的参数 +import aiyh.utils.action.SafeCusBaseAction; import aiyh.utils.annotation.RequiredMark; import aiyh.utils.excention.CustomerException; // 自定义异常类 create 2022/3/9 2:20 PM import org.apache.commons.lang3.StringUtils; +import weaver.conn.RecordSet; import weaver.conn.RecordSetTrans; import weaver.hrm.User; import weaver.soa.workflow.request.RequestInfo; -import weaver.workflow.request.RequestManager; +import weaver.xiao.commons.config.entity.RequestMappingConfig; +import weaver.xuanran.wang.common.util.CommonUtil; import weaver.xuanran.wang.common.util.CusInfoToOAUtil; +import weaver.xuanran.wang.schroeder.before.interfaces.CusActionBeforeProcessor; import weaver.xuanran.wang.schroeder.service.SchroederQRCodeService; +import java.lang.reflect.Constructor; +import java.lang.reflect.InvocationTargetException; import java.util.*; -import java.util.function.Function; import java.util.stream.Collectors; @@ -23,7 +27,7 @@ import java.util.stream.Collectors; * @Author xuanran.wang * @Date 2022/11/30 16:08 */ -public class PushSealTaskAction extends CusBaseAction { // 基础的action,实现一些基础的参数 +public class PushSealTaskAction extends SafeCusBaseAction { // 基础的action,实现一些基础的参数 /** *

建模配置唯一标识

@@ -47,43 +51,162 @@ public class PushSealTaskAction extends CusBaseAction { // 基础的action, *

文档记录表模块id

**/ @RequiredMark - private String modelId; + private String docLogModelId; + + /** + *

requestId记录表模块id

+ **/ + @RequiredMark + private String requestIdLogModelId; + + /** + *

开门盖章种类

+ **/ + @RequiredMark + private String filePeopleType; + + /** + *

明细序列

+ **/ + @RequiredMark + private String detailNo; + /** + *

响应成功状态码

+ **/ + @RequiredMark + private String successCode; + /** + *

响应任务字段

+ **/ + @RequiredMark + private String backField; + /** + *

前置接口

+ **/ + private String cusBeforeProcessor; + /** + *

请求格式

+ **/ + private String type; private final SchroederQRCodeService schroederQRCodeService = new SchroederQRCodeService(); // 施罗德业务方法 施罗德业务方法 - - @Override // action 提交流程业务处理方法 具体业务逻辑实现 - public void doSubmit(String requestId, String billTable, int workflowId, User user, RequestManager requestManager) { + public void doSubmit(String requestId, String billTable, int workflowId, User user, RequestInfo requestInfo) { log.info("---------- PushSealTaskSealValue Begin " + requestId + "----------"); - RequestInfo requestInfo = requestInfoThreadLocal.get(); - String scanNum = schroederQRCodeService.pushSealTask(onlyMark, billTable, requestId); // 推送数据创建任务 建模配置唯一标识 - RecordSetTrans trans = requestManager.getRsTrans(); + String delSql = ""; + String mainId = ""; + RecordSetTrans trans = new RecordSetTrans(); trans.setAutoCommit(false); - String updateSql = "update " + billTable + " set " + QRCodeField + " = ? where requestid = ?"; // 二维码来源字段 + // 插入模块的参数集合 + List requestIdLogModelIdList = new ArrayList<>(); + List docLogModelIdList = new ArrayList<>(); + // 前置接口做了添加明细表的操作 最后是否需要删除添加的明细 + boolean del = false; + // 执行前置处理 默认添加一行明细 + if(StringUtils.isNotBlank(cusBeforeProcessor)){ + Map pathParam = Util.parseCusInterfacePathParam(cusBeforeProcessor); + String classPath = pathParam.remove("_ClassPath"); + del = executeBeforeProcessor(classPath, requestInfo, null, pathParam); + } + RecordSet mainRs = new RecordSet(); + mainRs.executeQuery("select * from " + billTable + " where requestid = ?", requestId); + mainRs.next(); try{ + mainId = mainRs.getString("id"); + String detailTable = billTable + "_dt" + detailNo; + if(StringUtils.isNotBlank(mainId)){ + delSql = "delete from " + detailTable + " where mainid = ? "; + } + try{ + // 获取明细表数据 + List> detailList = schroederQRCodeService.getDetailList(detailTable, mainId); + List docIds = detailList.stream() + .map(item -> Util.null2DefaultStr(item.get(fileField), "")) + .filter(StringUtils::isNotBlank).collect(Collectors.toList()); + List> docLogParamList = new ArrayList<>(); + for (String docId : docIds) { + LinkedHashMap map = new LinkedHashMap<>(); + map.put("docId", docId); + map.put("enable", 0); + docLogParamList.add(map); + } + // 将docLog数据写入建模 + docLogModelIdList = CusInfoToOAUtil.executeBatch(Util.getIntValue(docLogModelId, -1), docLogParamList, "select id from #{tableName} where docId = ?", docIds); + // requestLog写入建模 + LinkedHashMap map = new LinkedHashMap<>(); + int count = schroederQRCodeService.getTaskIdByRequestId(requestId); + if(Util.getIntValue(String.valueOf(count),-1) < 0){ + count = 1; + }else { + count += 1; + } + map.put("count", count); + map.put("cusRequestId", requestId); + requestIdLogModelIdList = CusInfoToOAUtil.executeBatch(Util.getIntValue(requestIdLogModelId, -1), Collections.singletonList(map)); + }catch (Exception e){ + throw new CustomerException(Util.logStr("数据写入建模异常!:{}", e.getMessage())); + } + + String scanNum = schroederQRCodeService.pushSealTask(onlyMark, billTable, requestId, type, successCode, backField, filePeopleType); // 推送数据创建任务 建模配置唯一标识 + String updateSql = "update " + billTable + " set " + QRCodeField + " = ? where requestid = ?"; // 二维码来源字段 if(!trans.executeUpdate(updateSql, scanNum, requestId)){ throw new CustomerException(Util.logStr("更新表单sql执行失败!sql : {}, 参数 scanNum : {}, requestId : {}", scanNum, requestId)); // 自定义异常类 create 2022/3/9 2:20 PM 构建日志字符串 } - // 获取明细表数据 - List> detailList = getDetailTableValueByDetailNo(1, requestInfo); - List docIds = detailList.stream() - .map(item -> Util.null2DefaultStr(item.get(fileField), "")) - .filter(StringUtils::isNotBlank).collect(Collectors.toList()); - ArrayList> list = new ArrayList<>(); - for (String docId : docIds) { - LinkedHashMap map = new LinkedHashMap<>(); - map.put("docId", docId); - map.put("enable", 0); - list.add(map); - } - // 将数据写入建模 - CusInfoToOAUtil.executeBatch(Util.getIntValue(modelId, -1), list, "select 1 from #{tableName} where docId = ?", docIds); + }catch (Exception e){ + CommonUtil.deleteDataByIds(requestIdLogModelIdList, Util.getIntValue(requestIdLogModelId,-1)); + CommonUtil.deleteDataByIds(docLogModelIdList, Util.getIntValue(docLogModelId,-1)); trans.rollback(); throw new CustomerException(Util.logStr("执行提交方法异常:{}", e.getMessage())); // 自定义异常类 create 2022/3/9 2:20 PM 构建日志字符串 + }finally { + log.info(Util.logStr("del: {}, sql: {}, mainId: {}", del, delSql, mainId)); + if(del && StringUtils.isNotBlank(delSql)){ + RecordSet rs = new RecordSet(); + if(!rs.executeUpdate(delSql, mainId)){ + log.error(Util.logStr("删除明细表失败! sql: {}, mainId: {}", delSql, mainId)); + } + } } trans.commit(); } + + + + /** + *

执行自定义后置处理方法

+ * + * @param className 全路径类名 + * @return 返回值 + */ + private boolean executeBeforeProcessor(String className, RequestInfo requestInfo, + RequestMappingConfig requestMappingConfig, + Map pathParam) { + 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 (!CusActionBeforeProcessor.class.isAssignableFrom(aClass)) { + throw new IllegalArgumentException("自定义前置置处理接口:" + className + " 不是" + + CusActionBeforeProcessor.class.getName() + "的子类或实现类!"); + } + CusActionBeforeProcessor o; + try { + o = (CusActionBeforeProcessor) constructor.newInstance(); + } catch (InstantiationException | IllegalAccessException | InvocationTargetException e) { + throw new IllegalArgumentException("无法构造" + className + "对象!"); + } + return o.beforeProcessor(requestInfo, requestMappingConfig, pathParam); + } + + } diff --git a/src/main/java/weaver/xuanran/wang/schroeder/action/SalesforceEndpointAction.java b/src/main/java/weaver/xuanran/wang/schroeder/action/SalesforceEndpointAction.java new file mode 100644 index 0000000..2bc8c97 --- /dev/null +++ b/src/main/java/weaver/xuanran/wang/schroeder/action/SalesforceEndpointAction.java @@ -0,0 +1,45 @@ +package weaver.xuanran.wang.schroeder.action; + +import aiyh.utils.Util; +import aiyh.utils.action.SafeCusBaseAction; +import aiyh.utils.annotation.RequiredMark; +import aiyh.utils.excention.CustomerException; +import weaver.hrm.User; +import weaver.soa.workflow.request.RequestInfo; +import weaver.xuanran.wang.schroeder.service.SchroederQRCodeService; + +/** + *

施罗德强制结束任务action

+ * + * @Author xuanran.wang + * @Date 2022/12/23 10:49 + */ +public class SalesforceEndpointAction extends SafeCusBaseAction { + + /** + *

建模配置唯一标识

+ **/ + @RequiredMark + private String onlyMark; + /** + *

响应成功状态码

+ **/ + @RequiredMark + private String successCode; + /** + *

请求方式

+ **/ + @RequiredMark + private String type; + + private final SchroederQRCodeService schroederQRCodeService = new SchroederQRCodeService(); + + @Override + public void doSubmit(String requestId, String billTable, int workflowId, User user, RequestInfo requestInfo) { + try { + schroederQRCodeService.pushSealTask(onlyMark, billTable, requestId,type, successCode,"",""); + }catch (Exception e){ + throw new CustomerException(Util.logStr("执行提交方法异常:{}", e.getMessage())); // + } + } +} diff --git a/src/main/java/weaver/xuanran/wang/schroeder/before/PushSealTaskBeforeProcessor.java b/src/main/java/weaver/xuanran/wang/schroeder/before/PushSealTaskBeforeProcessor.java new file mode 100644 index 0000000..9102938 --- /dev/null +++ b/src/main/java/weaver/xuanran/wang/schroeder/before/PushSealTaskBeforeProcessor.java @@ -0,0 +1,62 @@ +package weaver.xuanran.wang.schroeder.before; + +import aiyh.utils.Util; +import aiyh.utils.excention.CustomerException; +import aiyh.utils.sqlUtil.sqlResult.impl.PrepSqlResultImpl; +import com.alibaba.fastjson.JSONObject; +import org.apache.log4j.Logger; +import weaver.conn.RecordSet; +import weaver.soa.workflow.request.RequestInfo; +import weaver.xiao.commons.config.entity.RequestMappingConfig; +import weaver.xuanran.wang.schroeder.before.interfaces.CusActionBeforeProcessor; + +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +/** + *

将主表数据插入到明细

+ * + * @Author xuanran.wang + * @Date 2022/12/21 16:44 + */ +public class PushSealTaskBeforeProcessor implements CusActionBeforeProcessor { + + private final Logger logger = Util.getLogger(); + + /** + * weaver.xuanran.wang.schroeder.before.PushSealTaskBeforeProcessor?whereSql=`yyfs in (4,7)`&mapping=`yzzl:yzzl,htzyzcshj:htzyzcs,gzcshj:gzcs,frzcshj:frzcs`&detailNo=1 + */ + @Override + public boolean beforeProcessor(RequestInfo requestInfo, RequestMappingConfig requestMappingConfig, Map pathParam) { + String whereSql = pathParam.get("whereSql"); + String tableName = requestInfo.getRequestManager().getBillTableName(); + String sql = "select * from " + tableName + " where requestid = ? and " + whereSql; + RecordSet rs = new RecordSet(); + // 如果主表数据符合插入条件 + // mapping=sas:dashdjas,dhjsadh:dfhjs + logger.info(Util.logStr("前置接口 : sql : {}, 路径参数: {}", sql, JSONObject.toJSONString(pathParam))); + if(rs.executeQuery(sql, requestInfo.getRequestid()) && rs.next()){ + HashMap detailMap = new HashMap<>(); + String mapping = pathParam.get("mapping"); + String detailNo = pathParam.get("detailNo"); + String[] split = mapping.split(","); + for (String str : split) { + String[] map = str.split(":"); + detailMap.put(map[1], Util.null2DefaultStr(rs.getString(map[0]),"")); + } + detailMap.put("mainid", rs.getString("id")); + // 用印文件docId + detailMap.put(pathParam.get("fileField"),pathParam.get("fileFieldValue")); + PrepSqlResultImpl sqlResult = Util.createSqlBuilder().insertSql(tableName + "_dt" + detailNo, detailMap); + String sqlStr = sqlResult.getSqlStr(); + List args = sqlResult.getArgs(); + if (!rs.executeUpdate(sqlStr, args)) { + throw new CustomerException(Util.logStr("明细数据插入失败! sql : {}, params : {}", sqlStr, JSONObject.toJSONString(args))); + } + return true; + } + return false; + } + +} diff --git a/src/main/java/weaver/xuanran/wang/schroeder/before/interfaces/CusActionBeforeProcessor.java b/src/main/java/weaver/xuanran/wang/schroeder/before/interfaces/CusActionBeforeProcessor.java new file mode 100644 index 0000000..972f74a --- /dev/null +++ b/src/main/java/weaver/xuanran/wang/schroeder/before/interfaces/CusActionBeforeProcessor.java @@ -0,0 +1,23 @@ +package weaver.xuanran.wang.schroeder.before.interfaces; + +import weaver.soa.workflow.request.RequestInfo; +import weaver.xiao.commons.config.entity.RequestMappingConfig; + +import java.util.Map; + +/** + *

前置接口处理

+ * + * @Author xuanran.wang + * @Date 2022/12/21 16:40 + */ +public interface CusActionBeforeProcessor { + /** + * 前置处理接口 + * @param requestInfo 流程参数 + * @param requestMappingConfig 根据onlyMark生成的配置对象 + * @param pathParam 自定义前置处理类路径参数 + * @return 是否继续执行 + */ + boolean beforeProcessor(RequestInfo requestInfo, RequestMappingConfig requestMappingConfig, Map pathParam); +} diff --git a/src/main/java/weaver/xuanran/wang/schroeder/cus_field_value/PushSealTaskSealValue.java b/src/main/java/weaver/xuanran/wang/schroeder/cus_field_value/PushSealTaskSealValue.java index 1b9dc5b..eb4605c 100644 --- a/src/main/java/weaver/xuanran/wang/schroeder/cus_field_value/PushSealTaskSealValue.java +++ b/src/main/java/weaver/xuanran/wang/schroeder/cus_field_value/PushSealTaskSealValue.java @@ -27,7 +27,6 @@ public class PushSealTaskSealValue implements CusInterfaceGetValue { // 自定 @Override // 获取参数值 public Object execute(Map mainMap, Map detailMap, String currentValue, Map pathParam) { logger.info(Util.logStr("路径参数:[{}]", JSONObject.toJSONString(pathParam))); - logger.info("路径参数(字符串拼接) : " + JSONObject.toJSONString(pathParam));// 构建日志字符串 // 接口字段 String sealSnField = pathParam.get("sealSnField"); String sealNumField = pathParam.get("sealNumField"); @@ -39,7 +38,6 @@ public class PushSealTaskSealValue implements CusInterfaceGetValue { // 自定 if(checkBlank(sealSnField, sealNumField, sealSnCusSql, sealNumCusSql)){ throw new CustomerException(Util.logStr("自定义类路径中必要参数为空,请检查!当前pathParam : {}", JSONObject.toJSONString(pathParam))); // 自定义异常类 create 2022/3/9 2:20 PM 构建日志字符串 } - logger.info(Util.logStr("当前值 : {}", currentValue)); // 构建日志字符串 // 如果为空返回空集合 if(StringUtils.isBlank(currentValue)){ return Collections.emptyList(); diff --git a/src/main/java/weaver/xuanran/wang/schroeder/mapper/SchroederMapper.java b/src/main/java/weaver/xuanran/wang/schroeder/mapper/SchroederMapper.java index 1812c4c..9e53859 100644 --- a/src/main/java/weaver/xuanran/wang/schroeder/mapper/SchroederMapper.java +++ b/src/main/java/weaver/xuanran/wang/schroeder/mapper/SchroederMapper.java @@ -3,6 +3,7 @@ package weaver.xuanran.wang.schroeder.mapper; import aiyh.utils.annotation.recordset.ParamMapper; import aiyh.utils.annotation.recordset.Select; import aiyh.utils.annotation.recordset.SqlMapper; +import com.icbc.api.internal.apache.http.impl.cookie.S; import java.util.List; import java.util.Map; @@ -41,5 +42,20 @@ public interface SchroederMapper { List> selectSealFileList(@ParamMapper("fileField") String fileField, @ParamMapper("tableName") String tableName, @ParamMapper("mainId") String mainId); + /** + *

得到任务Id

+ * @author xuanran.wang + * @dateTime 2022/12/21 9:39 + * @param cusRequestId 请求id + * @return taskId + **/ + @Select("select max(count) count " + + "from uf_request_task_log " + + "where cusRequestId = #{cusRequestId} " + + "group by cusRequestId") + Integer selectTaskId(@ParamMapper("cusRequestId") String cusRequestId); + @Select("select * from $t{tableName} where mainid = #{mainId}") + List> detailList(@ParamMapper("tableName") String tableName, + @ParamMapper("mainId") String mainId); } diff --git a/src/main/java/weaver/xuanran/wang/schroeder/service/SchroederQRCodeService.java b/src/main/java/weaver/xuanran/wang/schroeder/service/SchroederQRCodeService.java index ad6af3b..8d1f67a 100644 --- a/src/main/java/weaver/xuanran/wang/schroeder/service/SchroederQRCodeService.java +++ b/src/main/java/weaver/xuanran/wang/schroeder/service/SchroederQRCodeService.java @@ -5,29 +5,21 @@ import aiyh.utils.excention.CustomerException; // 自定义异常类 create 20 import aiyh.utils.httpUtil.ResponeVo; import aiyh.utils.httpUtil.util.HttpUtils; import com.alibaba.fastjson.JSON; -import com.alibaba.fastjson.JSONObject; import com.fasterxml.jackson.core.JsonProcessingException; -import com.google.zxing.qrcode.encoder.QRCode; -import com.icbc.api.internal.apache.http.M; import org.apache.commons.collections.CollectionUtils; import org.apache.commons.lang3.StringUtils; import org.apache.log4j.Logger; -import org.junit.Test; -import org.springframework.beans.BeanUtils; import weaver.conn.RecordSet; -import weaver.mobile.plugin.ecology.QRCodeComInfo; import weaver.xiao.commons.config.entity.RequestMappingConfig; import weaver.xiao.commons.config.service.DealWithMapping; import weaver.xuanran.wang.schroeder.mapper.SchroederMapper; import javax.ws.rs.core.MediaType; -import java.io.File; import java.io.IOException; +import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; -import java.util.regex.Matcher; -import java.util.regex.Pattern; import java.util.stream.Collectors; /** @@ -38,10 +30,6 @@ import java.util.stream.Collectors; */ public class SchroederQRCodeService { private static final int SUCCESS_CODE = 200; - /** - *

成功状态码

- **/ - private static final int SUCCESS_STATUS= 0; /** *

接口响应信息

**/ @@ -54,91 +42,154 @@ public class SchroederQRCodeService { *

接口响应状态字段

**/ private static final String STATUS_FIELD = "status"; + /** + *

get

+ **/ + public static final String GET = "GET"; + /** + *

post

+ **/ + public static final String POST = "POST"; + /** + *

requestId记录表名

+ **/ private final DealWithMapping dealWithMapping = new DealWithMapping(); private final Logger log = Util.getLogger(); // 获取日志对象 private final HttpUtils httpUtils = new HttpUtils(); + { httpUtils.getGlobalCache().header.put("Content-Type", MediaType.APPLICATION_JSON); // 全局请求头 } + private final SchroederMapper schroederMapper = Util.getMapper(SchroederMapper.class); /** - *

推送数据创建任务

- * @author xuanran.wang - * @dateTime 2022/12/5 17:05 - * @param onlyMark 唯一编码 + *

推送数据

+ * + * @param onlyMark 唯一编码 * @param billTable 表名 * @param requestId 请求id + * @param type 请求类型 + * @param successCode 成功状态码 + * @param backField 响应字段 + * @param filePeopleType 骑缝章的 filePeopleType * @return 响应数据 + * @author xuanran.wang + * @dateTime 2022/12/5 17:05 **/ - public String pushSealTask(String onlyMark, String billTable, String requestId){ - String res = ""; + public String pushSealTask(String onlyMark, String billTable, + String requestId, String type, + String successCode, String backField,String filePeopleType) { RequestMappingConfig requestMappingConfig = dealWithMapping.treeDealWithUniqueCode(onlyMark); // 将配置参数通过唯一标识查询处理成树形结构 - String cusWhere = Util.null2DefaultStr(requestMappingConfig.getCusWhereSql(),""); - if(StringUtils.isNotBlank(cusWhere)){ - cusWhere = DealWithMapping.sbc2dbcCase(cusWhere); // 全角转半角 + Map requestParam = getParamsMap(requestMappingConfig, billTable, requestId, filePeopleType); + String url = requestMappingConfig.getRequestUrl(); + ResponeVo responeVo = null; + try { + switch (type){ + case GET: { + responeVo = httpUtils.apiGet(url, requestParam, new HashMap<>()); + }break; + case POST: { + responeVo = httpUtils.apiPost(url, requestParam); + }break; + default:throw new CustomerException("暂不支持的请求方式!"); + } + } catch (IOException e) { + throw new CustomerException(Util.logStr("发送请求发生异常! : {}", e.getMessage())); // 自定义异常类 create 2022/3/9 2:20 PM 构建日志字符串 } - String selectMainSql = "select * from " + billTable + " where requestid = ? " + cusWhere; - log.info("查询主表数据sql { " + selectMainSql + " }, requestId { " + requestId + " }"); - RecordSet recordSet = new RecordSet(); - recordSet.executeQuery(selectMainSql, requestId); - if (recordSet.next()) { - dealWithMapping.setMainTable(billTable); - Map requestParam = dealWithMapping.getRequestParam(recordSet, requestMappingConfig); - // 如果明细数据存在骑缝章时候增加一行数据进去 - changeRequestMap(requestParam, billTable + "_dt1", recordSet.getString("id")); - // 解析请求参数配置树,转换成请求参数 - log.info(Util.logStr("请求json : {}", JSONObject.toJSONString(requestParam))); // 构建日志字符串 - String url = requestMappingConfig.getRequestUrl(); - ResponeVo responeVo = null; - try { - responeVo = httpUtils.apiPost(url, requestParam); - } catch (IOException e) { - throw new CustomerException(Util.logStr("发送印章请求发生异常! : {}", e.getMessage())); // 自定义异常类 create 2022/3/9 2:20 PM 构建日志字符串 - } - Map headers = httpUtils.getGlobalCache().header; // 全局请求头 - if (responeVo.getCode() != SUCCESS_CODE) { // 相应状态码 - log.error(Util.logStr("can not fetch [{}],this request params is [{}]," + // 构建日志字符串 - "this request heard is [{}],but response status code is [{}]," + - "this response is [{}]", url, JSON.toJSON(requestParam), JSON.toJSONString(headers), responeVo.getCode(), // 相应状态码 - responeVo.getEntityString())); // 相应内容 - throw new CustomerException(Util.logStr("can not fetch [{}]", url)); // 自定义异常类 create 2022/3/9 2:20 PM 构建日志字符串 - } - Map response; - log.info(Util.logStr("this response is [{}]", responeVo.getEntityString())); // 构建日志字符串 相应内容 - try { - response = responeVo.getEntityMap(); // 根据相应结果转化为map集合 - log.info(Util.logStr("接口响应:{}", JSONObject.toJSONString(response))); // 构建日志字符串 - } catch (JsonProcessingException e) { - log.error(Util.logStr("push data error, can not parse response to map," + // 构建日志字符串 - "this response is [{}], url is [{}],request params is [{}], request heard is [{}];", - responeVo.getEntityString(), url, JSON.toJSONString(requestParam), JSON.toJSONString(headers))); // 相应内容 - throw new CustomerException(Util.logStr("push data error, can not parse response to map")); // 自定义异常类 create 2022/3/9 2:20 PM 构建日志字符串 - } - int status = (int) response.get(STATUS_FIELD); - if(SUCCESS_STATUS != status){ - throw new CustomerException(Util.logStr("接口响应码不为0,接口响应信息:{}", Util.null2DefaultStr(response.get(MESSAGE_FIELD),""))); // 自定义异常类 create 2022/3/9 2:20 PM 构建日志字符串 - } - res = Util.null2DefaultStr(response.get(SCAN_NUM_FIELD),""); + return parseResponseVo(responeVo, url, requestParam, successCode, backField); + } + + /** + *

解析响应对象

+ * @author xuanran.wang + * @dateTime 2022/12/23 11:25 + * @param responseVo 响应对象 + * @param url 地址 + * @param requestParam 请求 + * @param successCode 成功响应标识 + * @param backField 回传字段 + * @return 回传字段的值 + **/ + private String parseResponseVo(ResponeVo responseVo, String url, + Map requestParam, + String successCode, String backField){ + String res = ""; + Map headers = httpUtils.getGlobalCache().header;// 全局请求头 + if (responseVo.getCode() != SUCCESS_CODE) { // 相应状态码 + log.error(Util.logStr("can not fetch [{}],this request params is [{}]," + // 构建日志字符串 + "this request heard is [{}],but response status code is [{}]," + + "this response is [{}]", url, JSON.toJSON(requestParam), JSON.toJSONString(headers), responseVo.getCode(), // 相应状态码 + responseVo.getEntityString())); // 相应内容 + throw new CustomerException(Util.logStr("can not fetch [{}]", url)); // 自定义异常类 create 2022/3/9 2:20 PM 构建日志字符串 } - if(StringUtils.isBlank(res)){ - throw new CustomerException("获取接口中响应任务字段为空, 请检查!"); // 自定义异常类 create 2022/3/9 2:20 PM + Map response; + log.info(Util.logStr("this response is [{}]", responseVo.getEntityString())); // 构建日志字符串 相应内容 + try { + response = responseVo.getEntityMap(); // 根据相应结果转化为map集合 + } catch (JsonProcessingException e) { + log.error(Util.logStr("push data error, can not parse response to map," + // 构建日志字符串 + "this response is [{}], url is [{}],request params is [{}], request heard is [{}];", + responseVo.getEntityString(), url, JSON.toJSONString(requestParam), JSON.toJSONString(headers))); // 相应内容 + throw new CustomerException(Util.logStr("push data error, can not parse response to map")); // 自定义异常类 create 2022/3/9 2:20 PM 构建日志字符串 + } + String status = Util.null2DefaultStr(response.get(STATUS_FIELD), ""); + if (!successCode.equals(status)) { + throw new CustomerException(Util.logStr("接口响应码不为 : [{}],接口响应信息: {}", successCode, Util.null2DefaultStr(response.get(MESSAGE_FIELD), ""))); // 自定义异常类 create 2022/3/9 2:20 PM 构建日志字符串 + } + if(StringUtils.isNotBlank(backField)){ + res = Util.null2DefaultStr(response.get(backField), ""); + if (StringUtils.isBlank(res)) { + throw new CustomerException("获取接口中响应任务字段为空, 请检查!"); // 自定义异常类 create 2022/3/9 2:20 PM + } } return res; } /** - *

骑缝章修改请求参数

+ *

根据配置获取响应信息

* @author xuanran.wang - * @dateTime 2022/12/13 14:15 - * @param requestParam 请求参数 + * @dateTime 2022/12/23 11:02 + * @param requestMappingConfig 请求配置主体 * @param billTable 表名 - * @param mainId 主表id + * @param requestId 请求id + * @param filePeopleType 骑缝章的filePeopleType + * @return 参数配置map **/ - public void changeRequestMap(Map requestParam, String billTable, String mainId){ + public Map getParamsMap(RequestMappingConfig requestMappingConfig, String billTable, String requestId, String filePeopleType) { + String cusWhere = Util.null2DefaultStr(requestMappingConfig.getCusWhereSql(), ""); + if (StringUtils.isNotBlank(cusWhere)) { + cusWhere = DealWithMapping.sbc2dbcCase(cusWhere); // 全角转半角 + } + String selectMainSql = "select * from " + billTable + " where requestid = ? " + cusWhere; + log.info(Util.logStr("查询主表数据sql : {}, requestId : {}", selectMainSql, requestId)); + RecordSet recordSet = new RecordSet(); + recordSet.executeQuery(selectMainSql, requestId); + Map requestParam = new HashMap<>(); + if (recordSet.next()) { + dealWithMapping.setMainTable(billTable); + requestParam = dealWithMapping.getRequestParam(recordSet, requestMappingConfig); + // 如果明细数据存在骑缝章时候增加一行数据进去 + if (StringUtils.isNotBlank(filePeopleType)) { + changeRequestMap(requestParam, billTable + "_dt1", recordSet.getString("id"), filePeopleType); + } + } + return requestParam; + } + + /** + *

骑缝章修改请求参数

+ * + * @param requestParam 请求参数 + * @param billTable 表名 + * @param mainId 主表id + * @author xuanran.wang + * @dateTime 2022/12/13 14:15 + **/ + public void changeRequestMap(Map requestParam, String billTable, String mainId, String filePeopleType) { List> files = (List>) requestParam.get("file"); List> detail1List = schroederMapper.selectSealTaskInfoList(billTable, mainId); - if(CollectionUtils.isEmpty(detail1List) || CollectionUtils.isEmpty(files)){ + if (CollectionUtils.isEmpty(detail1List) || CollectionUtils.isEmpty(files)) { return; } // 遍历明细数据 @@ -148,25 +199,53 @@ public class SchroederQRCodeService { // 从生成的请求参数map中开始匹配 List> filterFiles = files.stream() .filter(item -> { - String filePath = Util.null2DefaultStr(item.get("filePath"), ""); - String docId = Util.null2DefaultStr(filePath.substring(filePath.lastIndexOf("=") + 1),""); + String filePath = Util.null2DefaultStr(item.get("fileUrlPath"), ""); + String docId = Util.null2DefaultStr(filePath.substring(filePath.lastIndexOf("=") + 1), ""); return sealFile.equals(docId); }) .collect(Collectors.toList()); - if(CollectionUtils.isNotEmpty(filterFiles)){ + if (CollectionUtils.isNotEmpty(filterFiles)) { // 只有一个能匹配 Map o = filterFiles.get(0); HashMap tempMap = o.entrySet().stream().collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue, (a, b) -> a, HashMap::new)); // 印章集合 + List> sealList = new ArrayList<>(); HashMap seal = new HashMap<>(); - seal.put("sealSn",Util.null2DefaultStr(detailItem.get("qfzzl"),"")); - seal.put("sealNum",Util.null2DefaultStr(detailItem.get("qfzcs"),"0")); - tempMap.put("seal", seal); + seal.put("sealSn", Util.null2DefaultStr(detailItem.get("qfzzl"), "")); + seal.put("sealNum", Util.null2DefaultStr(detailItem.get("qfzcs"), "0")); + sealList.add(seal); + tempMap.put("seal", sealList); + tempMap.put("filePeopleType", filePeopleType); files.add(tempMap); } } } + + /** + *

获取taskId

+ * + * @return 任务id + * @author xuanran.wang + * @dateTime 2022/12/21 9:42 + **/ + public Integer getTaskIdByRequestId(String requestId) { + return schroederMapper.selectTaskId(requestId); + } + + /** + *

获取明细数据

+ * + * @param tableName 明细表名 + * @param mainId 主id + * @return 明细表数据 + * @author xuanran.wang + * @dateTime 2022/12/21 18:03 + **/ + public List> getDetailList(String tableName, String mainId) { + return schroederMapper.detailList(tableName, mainId); + } + } diff --git a/src/main/java/weaver/xuanran/wang/traffic_bank/waco_first/service/WacoDataPushOAService.java b/src/main/java/weaver/xuanran/wang/traffic_bank/waco_first/service/WacoDataPushOAService.java index e328250..3578d66 100644 --- a/src/main/java/weaver/xuanran/wang/traffic_bank/waco_first/service/WacoDataPushOAService.java +++ b/src/main/java/weaver/xuanran/wang/traffic_bank/waco_first/service/WacoDataPushOAService.java @@ -2,6 +2,7 @@ package weaver.xuanran.wang.traffic_bank.waco_first.service; import aiyh.utils.Util; import aiyh.utils.excention.CustomerException; +import com.alibaba.fastjson.JSONObject; import com.jcraft.jsch.ChannelSftp; import org.apache.commons.collections.CollectionUtils; import org.apache.commons.lang3.StringUtils; @@ -103,9 +104,11 @@ public class WacoDataPushOAService { for (Info info : infos) { List docDetailParam = new ArrayList<>(); Map param = getParamsMapByInfo(secCategory, info, docDetailParam); + logger.info("param : " + JSONObject.toJSONString(param)); String dataId = CusInfoToOAUtil.getDataId(modelId, param, whereSql, Collections.singletonList(info.getInfoId())); + logger.info("dataId : " + JSONObject.toJSONString(dataId)); ids.add(dataId); docDetailContentParams.add(docDetailParam); } diff --git a/src/test/java/xuanran/wang/saic_travel/model_data_async/AsyncTest.java b/src/test/java/xuanran/wang/saic_travel/model_data_async/AsyncTest.java index a95e623..5214895 100644 --- a/src/test/java/xuanran/wang/saic_travel/model_data_async/AsyncTest.java +++ b/src/test/java/xuanran/wang/saic_travel/model_data_async/AsyncTest.java @@ -1,17 +1,25 @@ package xuanran.wang.saic_travel.model_data_async; +import aiyh.utils.ApiResult; +import aiyh.utils.Util; +import aiyh.utils.excention.CustomerException; import basetest.BaseTest; import com.alibaba.fastjson.JSONObject; +import com.api.xuanran.wang.saic_travel.model_create_workflow.service.CreateWorkFlowService; +import org.apache.commons.collections.CollectionUtils; import org.apache.commons.lang3.StringUtils; import org.junit.Test; +import weaver.conn.RecordSet; import weaver.formmode.data.ModeDataApproval; -import weaver.general.Util; +import weaver.general.TimeUtil; import weaver.hrm.User; +import weaver.xuanran.wang.common.mapper.CommonMapper; import weaver.xuanran.wang.common.util.CommonUtil; import weaver.xuanran.wang.saic_travel.model_data_async.config.eneity.DataAsyncMain; import weaver.xuanran.wang.saic_travel.model_data_async.service.DataAsyncConfigService; import java.util.*; +import java.util.stream.Collectors; /** *

@@ -21,7 +29,8 @@ import java.util.*; */ public class AsyncTest extends BaseTest { private DataAsyncConfigService dataAsyncConfigService = new DataAsyncConfigService(); - + private final CommonMapper commonMapper = Util.getMapper(CommonMapper.class); + private final CreateWorkFlowService createWorkFlowService = new CreateWorkFlowService(); @Test public void testGetConfig(){ // DataAsyncMain hrmAsyncTest = dataAsyncConfigService.getDataAsyncConfigByUniqueCode("hrmAsyncTest"); @@ -45,24 +54,71 @@ public class AsyncTest extends BaseTest { @Test public void testAsync(){ -// try { -// DataAsyncMain config = dataAsyncConfigService.getDataAsyncConfigByUniqueCode("wacoTest"); -// List data = dataAsyncConfigService.asyncModelData(config, 109); -// log.info("生成的数据id : " + JSONObject.toJSONString(data)); -// }catch (Exception e){ -// log.error("生成建模数据异常 : " + e.getMessage()); + try { + DataAsyncMain config = dataAsyncConfigService.getDataAsyncConfigByUniqueCode("hrmAsyncTest"); + List data = dataAsyncConfigService.asyncModelData(config, 109); + log.info("生成的数据id : " + JSONObject.toJSONString(data)); + }catch (Exception e){ + log.error("生成建模数据异常 : " + e.getMessage()); + } + +// String choiceData = "2357,2358,2274,2275"; +// String triggerWorkflowSetId = "4"; +// // 勾选的数据集合 +// List dataList = Arrays.stream(choiceData.split(",")).collect(Collectors.toList()); +// RecordSet rs = new RecordSet(); +// List> splitList = CommonUtil.splitList(dataList); +// String name = commonMapper.getModelNameByModelId(String.valueOf(109)); +// for (List list : splitList) { +// List ids = list.stream().map(item -> aiyh.utils.Util.getIntValue(item, -1)).collect(Collectors.toList()); +// if(CollectionUtils.isEmpty(ids)){ +// continue; +// } +// } +// String sql = "select id from " + name; +// for (String id : triggerWorkflowSetId.split(",")) { +// String condition = commonMapper.getConditionByTriggerId(id); +// if(StringUtils.isNotBlank(condition)){ +// sql += " where " + condition; +// } +// log.info(aiyh.utils.Util.logStr("查询数据sql : {}", sql)); +// List filterIds = filterIds(sql); +// List dataIds = dataList.stream().filter(filterIds::contains).collect(Collectors.toList()); +// List requestIds = CommonUtil.doCreateWorkFlow(109, dataIds, aiyh.utils.Util.getIntValue(id, -1)); // 通过数据审批生成流程 +// List errorData = new ArrayList<>(); +// for (int i = 0; i < requestIds.size(); i++) { +// if (aiyh.utils.Util.getIntValue(requestIds.get(i), -1) < 0) { +// errorData.add(dataList.get(i)); +// } +// } +// log.error(Util.logStr("执行创建流程失败集合: {}",JSONObject.toJSONString(errorData))); // 构建日志字符串 // } // List list = CommonUtil.doCreateWorkFlow(109, data); // log.info("触发成功 : " + JSONObject.toJSONString(list)); - log.info("select hr.email from HrmResource hr where status in (0,1,2,3) AND "+ Util.getSubINClause("1,3,323,124,544","id","in") + " and " + Util.getSubINClause("1","id","not in")); - log.info(Util.getSubINClause("1,3,323,124,544","id","in",2)); +// log.info("select hr.email from HrmResource hr where status in (0,1,2,3) AND "+ Util.getSubINClause("1,3,323,124,544","id","in") + " and " + Util.getSubINClause("1","id","not in")); +// log.info(Util.getSubINClause("1,3,323,124,544","id","in",2)); + } + + public List filterIds(String sql){ + RecordSet rs = new RecordSet(); + ArrayList res = new ArrayList<>(); + if (rs.executeQuery(sql)) { + while (rs.next()){ + res.add(Util.null2DefaultStr(rs.getString(1),"")); + } + } + return res; } @Test - public void testNotNull(){ - String str = "jssjhgdkjs?docId={?}&{$requestid}"; - System.out.println(str.replace("{?}", "123") - .replace("{$requestid}", "12194283")); + public void testNotNull() { + try { + String datas = "2600,2601,2602,2603,2599,2598"; + String gys = createWorkFlowService.supplierCusCreateWorkFlow("6", "109", "gys", datas, 110); + log.info(" gys : " + gys); + }catch (Exception e){ + log.error("e => " + e.getMessage()); + } } public boolean checkNull(String ... args){ diff --git a/src/test/java/xuanran/wang/schroeder/download_file/DownLoadFileTest.java b/src/test/java/xuanran/wang/schroeder/download_file/DownLoadFileTest.java index cfd995b..a3e0bf2 100644 --- a/src/test/java/xuanran/wang/schroeder/download_file/DownLoadFileTest.java +++ b/src/test/java/xuanran/wang/schroeder/download_file/DownLoadFileTest.java @@ -1,6 +1,7 @@ package xuanran.wang.schroeder.download_file; import aiyh.utils.Util; +import aiyh.utils.sqlUtil.sqlResult.impl.PrepSqlResultImpl; import basetest.BaseTest; import com.alibaba.fastjson.JSONObject; import com.api.xuanran.wang.schroeder.download_file.mapper.DownLoadFileMapper; @@ -154,4 +155,49 @@ public class DownLoadFileTest extends BaseTest { String resultString = text.replaceAll("2", replacement); log.info("resultString " + resultString); } + + @Test + public void testBefore(){ + Map pathParam = Util.parseCusInterfacePathParam("weaver.xuanran.wang.schroeder.before.PushSealTaskBeforeProcessor?whereSql=`yyfs in (4,7)`&mapping=`yzzl:yzzl,htzyzcshj:htzyzcs,gzcshj:gzcs,frzcshj:frzcs`&detailNo=1"); + HashMap detailMap = new HashMap<>(); + String mapping = pathParam.get("mapping"); + String detailNo = pathParam.get("detailNo"); + String[] split = mapping.split(","); + for (String str : split) { + String[] map = str.split(":"); + detailMap.put(map[1], map[0]); + } + detailMap.put("mainid", "1"); + PrepSqlResultImpl sqlResult = Util.createSqlBuilder().insertSql("121212" + "_dt" + detailNo, detailMap); + String sqlStr = sqlResult.getSqlStr(); + List args = sqlResult.getArgs(); + log.info("sqlStr : " + sqlStr); + log.info("args : " + args); + } + + @Test + public void testUrl(){ + String serialNumber = "0199"; + String front = serialNumber.substring(0,2); + String end = serialNumber.substring(2); + log.info("front " + front); + log.info("end " + end); + int frontInt = Util.getIntValue(front); + int endInt = Util.getIntValue(end); + log.info("frontInt " + frontInt); + log.info("endInt " + endInt); + String endStr = ""; + String frontStr = ""; + if(++endInt >= 100){ + frontInt += 1; + endInt = 1; + } + if(endInt < 10){ + endStr = "0" + endInt; + } + if(frontInt < 10){ + frontStr = "0" + frontInt; + } + log.info(frontStr + endStr); + } } diff --git a/src/test/java/xuanran/wang/traffic_bank/waco_first/WacoFirstTest.java b/src/test/java/xuanran/wang/traffic_bank/waco_first/WacoFirstTest.java index 5a966ed..3699a15 100644 --- a/src/test/java/xuanran/wang/traffic_bank/waco_first/WacoFirstTest.java +++ b/src/test/java/xuanran/wang/traffic_bank/waco_first/WacoFirstTest.java @@ -72,7 +72,7 @@ public class WacoFirstTest extends BaseTest { public void testFinally() throws IOException { String currentDate = TimeUtil.getCurrentDateString(); String WACO_TEMP_PATH = "WACO" + File.separator + "temp" + File.separator; - String fileName = currentDate.replaceAll("-","") + ".zip"; + String fileName = "20221208.zip"; String zipOATempPath = GCONST.getSysFilePath() + WACO_TEMP_PATH + fileName; try { String tempFolder = GCONST.getSysFilePath() + WACO_TEMP_PATH;