Merge branch 'dev' of https://gitea.yeyaguitu.cn/ecology/ebu_ecology_dev1 into dev
commit
8057e5dc28
|
@ -23,7 +23,6 @@ log
|
||||||
# should NOT be excluded as they contain compiler settings and other important
|
# should NOT be excluded as they contain compiler settings and other important
|
||||||
# information for Eclipse / Flash Builder.
|
# information for Eclipse / Flash Builder.
|
||||||
|
|
||||||
/target/
|
|
||||||
/log/
|
/log/
|
||||||
.DS_Store
|
.DS_Store
|
||||||
/src/main/resources/WEB-INF/prop/weaver.properties
|
/src/main/resources/WEB-INF/prop/weaver.properties
|
||||||
|
@ -42,6 +41,9 @@ DirectoryV2.xml
|
||||||
*.iml
|
*.iml
|
||||||
src/main/resources/WEB-INF/sqllog/
|
src/main/resources/WEB-INF/sqllog/
|
||||||
java.io.tempdir/
|
java.io.tempdir/
|
||||||
|
ecology-9-dev.iml
|
||||||
|
src/test/resources/font
|
||||||
|
src/main/resources/WEB-INF/vm/outFile
|
||||||
|
target/
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,149 @@
|
||||||
|
window.Utils = {
|
||||||
|
/**
|
||||||
|
* @author youhong.ai
|
||||||
|
* @desc 发起请求
|
||||||
|
*/
|
||||||
|
request: function (url, type = "GET", data, isAsync = true, success = () => {
|
||||||
|
}, error = () => {
|
||||||
|
}, complete = () => {
|
||||||
|
}, contentType = 'application/json', beforeSend = () => {
|
||||||
|
}) {
|
||||||
|
let options = {
|
||||||
|
url,
|
||||||
|
type,
|
||||||
|
dataType: "json",
|
||||||
|
contentType,
|
||||||
|
async: isAsync,
|
||||||
|
data,
|
||||||
|
beforeSend,
|
||||||
|
success,
|
||||||
|
error,
|
||||||
|
complete,
|
||||||
|
}
|
||||||
|
if (contentType == 'application/json') {
|
||||||
|
options.data = JSON.stringify(data)
|
||||||
|
}
|
||||||
|
return $.ajax(options)
|
||||||
|
},
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author youhong.ai
|
||||||
|
* @desc 发起请求
|
||||||
|
*/
|
||||||
|
api: function (requestOptions = {
|
||||||
|
url: "",
|
||||||
|
type: "GET",
|
||||||
|
data: "",
|
||||||
|
isAsync: true,
|
||||||
|
success: () => {
|
||||||
|
},
|
||||||
|
error: () => {
|
||||||
|
},
|
||||||
|
complete: () => {
|
||||||
|
},
|
||||||
|
contentType: 'application/json',
|
||||||
|
beforeSend: () => {
|
||||||
|
}
|
||||||
|
}) {
|
||||||
|
let options = Object.assign({
|
||||||
|
url: "",
|
||||||
|
type: "GET",
|
||||||
|
data: "",
|
||||||
|
isAsync: true,
|
||||||
|
success: () => {
|
||||||
|
},
|
||||||
|
error: () => {
|
||||||
|
},
|
||||||
|
complete: () => {
|
||||||
|
},
|
||||||
|
contentType: 'application/json',
|
||||||
|
beforeSend: () => {
|
||||||
|
}
|
||||||
|
}, requestOptions)
|
||||||
|
return $.ajax(options)
|
||||||
|
},
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author youhong.ai
|
||||||
|
* @desc 获取react组件实例
|
||||||
|
*/
|
||||||
|
findReact: function (dom, traverseUp = 0) {
|
||||||
|
const key = Object.keys(dom).find(key => {
|
||||||
|
return key.startsWith("__reactFiber$") // react 17+
|
||||||
|
|| key.startsWith("__reactInternalInstance$")
|
||||||
|
|| key.startsWith("__reactEventHandlers$"); // react <17
|
||||||
|
});
|
||||||
|
const domFiber = dom[key];
|
||||||
|
if (domFiber == null) return null;
|
||||||
|
// react <16
|
||||||
|
if (domFiber._currentElement) {
|
||||||
|
let compFiber = domFiber._currentElement._owner;
|
||||||
|
for (let i = 0; i < traverseUp; i++) {
|
||||||
|
compFiber = compFiber._currentElement._owner;
|
||||||
|
}
|
||||||
|
return compFiber._instance;
|
||||||
|
}
|
||||||
|
// react 16+
|
||||||
|
const GetCompFiber = fiber => {
|
||||||
|
let parentFiber = fiber.return;
|
||||||
|
while (typeof parentFiber.type == "string") {
|
||||||
|
parentFiber = parentFiber.return;
|
||||||
|
}
|
||||||
|
return parentFiber;
|
||||||
|
};
|
||||||
|
let compFiber = GetCompFiber(domFiber);
|
||||||
|
for (let i = 0; i < traverseUp; i++) {
|
||||||
|
compFiber = GetCompFiber(compFiber);
|
||||||
|
}
|
||||||
|
return compFiber.stateNode;
|
||||||
|
},
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 转换字段名为字段ID
|
||||||
|
* @param fieldName 字段名称
|
||||||
|
* @returns {*|string}
|
||||||
|
*/
|
||||||
|
convertNameToIdUtil: function (fieldName) {
|
||||||
|
let fieldIds = [];
|
||||||
|
if (fieldName instanceof Array) {
|
||||||
|
fieldName.forEach(item => {
|
||||||
|
fieldIds.push(Utils.convertNameObjToId(item))
|
||||||
|
})
|
||||||
|
return fieldIds.join(',')
|
||||||
|
}
|
||||||
|
return Utils.convertNameObjToId(fieldName)
|
||||||
|
},
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 将字段名称转为字段id
|
||||||
|
* @param fieldObj 字段名称对象 {string|object}
|
||||||
|
* @returns {*}
|
||||||
|
*/
|
||||||
|
convertNameObjToId: function (fieldObj = {fieldName: '', table: 'main'}) {
|
||||||
|
if (typeof fieldObj === 'object') {
|
||||||
|
return WfForm.convertFieldNameToId(fieldObj.fieldName, fieldObj.table)
|
||||||
|
}
|
||||||
|
return WfForm.convertFieldNameToId(fieldObj)
|
||||||
|
},
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 根据字段名称查询字段值
|
||||||
|
* @param fieldName 字段名称
|
||||||
|
* @param rowIndex 明细行下表(明细获取才传递)
|
||||||
|
* @returns {*} 字段值
|
||||||
|
*/
|
||||||
|
getFiledValueByName: function (fieldName, rowIndex) {
|
||||||
|
return WfForm.getFieldValue(Utils.convertNameObjToId(fieldName) + (rowIndex ? '_' + rowIndex : ''))
|
||||||
|
},
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 通过字段名称修改字段值
|
||||||
|
* @param fieldName 字段名称
|
||||||
|
* @param value 值
|
||||||
|
*/
|
||||||
|
changeFieldValueByName: function (fieldName, value) {
|
||||||
|
WfForm.changeFieldValue(Utils.convertNameObjToId(fieldName), {value})
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,172 @@
|
||||||
|
const WfForm = {
|
||||||
|
isMobile: () => {
|
||||||
|
// true表示是eMobile、微信、钉钉等移动终端,false代表PC端
|
||||||
|
},
|
||||||
|
}
|
||||||
|
WfForm.OPER_SAVE = '保存'
|
||||||
|
WfForm.OPER_SUBMIT = '提交/批准/提交需反馈/不需反馈等'
|
||||||
|
WfForm.OPER_SUBMITCONFIRM = '提交至确认页面,如果是确认界面,点确认触发的是SUBMIT'
|
||||||
|
WfForm.OPER_REJECT = '退回'
|
||||||
|
WfForm.OPER_REMARK = '批注提交'
|
||||||
|
WfForm.OPER_INTERVENE = '干预'
|
||||||
|
WfForm.OPER_FORWARD = '转发'
|
||||||
|
WfForm.OPER_TAKEBACK = '强制收回'
|
||||||
|
WfForm.OPER_DELETE = '删除'
|
||||||
|
WfForm.OPER_ADDROW = '添加明细行,需拼明细表序号'
|
||||||
|
WfForm.OPER_DELROW = '删除明细行,需拼明细表序号'
|
||||||
|
WfForm.OPER_PRINTPREVIEW = '打印预览 KB900190501'
|
||||||
|
WfForm.OPER_EDITDETAILROW = '移动端-编辑明细 KB900191101'
|
||||||
|
WfForm.OPER_BEFOREVERIFY = '校验必填前触发事件 KB900191201'
|
||||||
|
WfForm.OPER_TURNHANDLE = '转办 KB900201101'
|
||||||
|
WfForm.OPER_ASKOPINION = '意见征询 KB900201101'
|
||||||
|
WfForm.OPER_TAKFROWARD = '征询转办 KB900201101'
|
||||||
|
WfForm.OPER_TURNREAD = '传阅 KB900201101'
|
||||||
|
WfForm.OPER_FORCEOVER = '强制归档 KB900201101'
|
||||||
|
WfForm.OPER_BEFORECLICKBTN = '点右键按钮前 KB900201101'
|
||||||
|
WfForm.OPER_SAVECOMPLETE = '保存后页面跳转前 KB900210501'
|
||||||
|
WfForm.OPER_WITHDRAW = '撤回 KB900201101'
|
||||||
|
WfForm.OPER_CLOSE = '页面关闭'
|
||||||
|
|
||||||
|
WfForm.registerCheckEvent = (type, callback = (callback) = {}) => {
|
||||||
|
// WfForm.registerCheckEvent(WfForm.OPER_SAVE+","+WfForm.OPER_SUBMIT,function(callback){
|
||||||
|
// //... 执行自定义逻辑
|
||||||
|
// callback();
|
||||||
|
// });
|
||||||
|
}
|
||||||
|
|
||||||
|
WfForm.ACTION_ADDROW = '添加明细行,需拼明细表序号 KB900190407'
|
||||||
|
WfForm.ACTION_DELROW = '删除明细行,需拼明细表序号 KB900190407'
|
||||||
|
WfForm.ACTION_EDITDETAILROW = '移动端-编辑明细行,需拼明细表序号 KB900190501'
|
||||||
|
WfForm.ACTION_SWITCHDETAILPAGING = '切换明细分页 KB900191201'
|
||||||
|
WfForm.ACTION_SWITCHTABLAYOUT = '切换模板布局标签页 KB900191201'
|
||||||
|
|
||||||
|
WfForm.registerAction = (type, callback) => {
|
||||||
|
// WfForm.registerAction(WfForm.ACTION_ADDROW+"1", function(index){
|
||||||
|
// alert("添加行下标是"+index);
|
||||||
|
// }); //下标从1开始,明细1添加行触发事件,注册函数入参为新添加行下标
|
||||||
|
// WfForm.registerAction(WfForm.ACTION_DELROW+"2", function(arg){
|
||||||
|
// alert("删除行下标集合是"+arg.join(","));
|
||||||
|
// }); //下标从1开始,明细2删除行触发事件
|
||||||
|
// WfForm.registerAction(WfForm.ACTION_SWITCHDETAILPAGING, function(groupid){
|
||||||
|
// alert("切换明细表"+(groupid+1)+"的页码触发事件");
|
||||||
|
// });
|
||||||
|
// WfForm.registerAction(WfForm.ACTION_SWITCHTABLAYOUT, function(tabid){
|
||||||
|
// alert("切换到标签项"+tabid+"触发事件");
|
||||||
|
// });
|
||||||
|
}
|
||||||
|
|
||||||
|
WfForm.convertFieldNameToId = (fieldName, table, flag) => {
|
||||||
|
// var fieldid = WfForm.convertFieldNameToId("zs");
|
||||||
|
// var fieldid = WfForm.convertFieldNameToId("zs_mx", "detail_1");
|
||||||
|
// var fieldid = WfForm.convertFieldNameToId("zs_mx", "detail_1", false);
|
||||||
|
}
|
||||||
|
|
||||||
|
WfForm.getFieldValue = function (fieldMark) {
|
||||||
|
// fieldMark String 是 字段标示,格式field${字段ID}_${明细行号}
|
||||||
|
// var fieldvalue = WfForm.getFieldValue("field110");
|
||||||
|
}
|
||||||
|
|
||||||
|
WfForm.bindFieldChangeEvent = function (fieldMarkStr, funobj = (obj, id, value) => {
|
||||||
|
}) {
|
||||||
|
// fieldMarkStr String 是 绑定字段标示,可多个拼接逗号隔开,例如:field110(主字段),field111_2(明细字段)……
|
||||||
|
// funobj Function 是 字段值变化触发的自定义函数,函数默认传递以下三个参数,参数1:触发字段的DOM对象,参数2:触发字段的标示(field27555等),参数3:修改后的值
|
||||||
|
// WfForm.bindFieldChangeEvent("field27555,field27556", function (obj, id, value) {
|
||||||
|
// console.log("WfForm.bindFieldChangeEvent--", obj, id, value);
|
||||||
|
// });
|
||||||
|
}
|
||||||
|
|
||||||
|
WfForm.bindDetailFieldChangeEvent = function (fieldMarkStr, funobj = (id, rowIndex, value) => {
|
||||||
|
}) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
WfForm.controlBtnDisabled = function (isDisabled) {
|
||||||
|
// isDisabled boolean 是 true:按钮全部置灰不可操作,false:恢复按钮可操作状态
|
||||||
|
// function subimtForm(params){
|
||||||
|
// WfForm.controlBtnDisabled(true); //操作按钮置灰
|
||||||
|
// ...
|
||||||
|
// WfForm.controlBtnDisabled(false);
|
||||||
|
// }
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
WfForm.showMessage = function (msg, type, duration) {
|
||||||
|
// 参数 参数类型 必须 说明
|
||||||
|
// msg String true 提示信息内容
|
||||||
|
// type int false 提示类型,1(警告)、2(错误)、3(成功)、4(一般),默认为1,不同类型提示信息效果不同
|
||||||
|
// duration Float false 多长时间自动消失,单位秒,默认为1.5秒
|
||||||
|
// WfForm.showMessage("结束时间需大于开始时间"); //警告信息,1.5s后自动消失
|
||||||
|
// WfForm.showMessage("运算错误", 2, 10); //错误信息,10s后消失
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
WfForm.getBaseInfo = function () {
|
||||||
|
// console.log(WfForm.getBaseInfo()); //返回当前请求基础信息
|
||||||
|
// //输出对象说明:
|
||||||
|
return {
|
||||||
|
f_weaver_belongto_userid: "5240", //用户信息
|
||||||
|
f_weaver_belongto_usertype: "0",
|
||||||
|
formid: -2010, //表单id
|
||||||
|
isbill: "1", //新表单/老表单
|
||||||
|
nodeid: 19275, //节点id
|
||||||
|
requestid: 4487931, //请求id
|
||||||
|
workflowid: 16084, //路径id
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
WfForm.changeFieldValue = function (fieldMark, valueInfo) {
|
||||||
|
// fieldMark String 是 字段标示,格式field${字段ID}_${明细行号}
|
||||||
|
// valueInfo JSON 是 字段值信息,非浏览按钮字段格式为{value:”修改的值”};specialobj为浏览按钮信息,数组格式;showhtml属性只在单行文本类型且只读情况下生效;
|
||||||
|
//修改文本框、多行文本、选择框等字段类型
|
||||||
|
// WfForm.changeFieldValue("field123", {value:"1.234"});
|
||||||
|
// //修改浏览框字段的值,必须有specialobj数组结构对象
|
||||||
|
// WfForm.changeFieldValue("field11_2", {
|
||||||
|
// value: "2,3",
|
||||||
|
// specialobj:[
|
||||||
|
// {id:"2",name:"张三"},
|
||||||
|
// {id:"3",name:"李四"}
|
||||||
|
// ]
|
||||||
|
// });
|
||||||
|
// //修改check框字段(0不勾选、1勾选)
|
||||||
|
// WfForm.changeFieldValue("field123", {value:"1"});
|
||||||
|
// //针对单行文本框字段类型,只读情况,支持显示值跟入库值不一致
|
||||||
|
// WfForm.changeFieldValue("field123", {
|
||||||
|
// value: "入库真实值",
|
||||||
|
// specialobj: {
|
||||||
|
// showhtml: "界面显示值"
|
||||||
|
// }
|
||||||
|
// });
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取流览框显示值
|
||||||
|
* fieldMark String 是 字段标示,格式field${字段ID}_${明细行号}
|
||||||
|
* splitChar String 否 分隔符,默认以逗号分隔
|
||||||
|
* @param fieldMark
|
||||||
|
* @param splitChar
|
||||||
|
*/
|
||||||
|
WfForm.getBrowserShowName = function (fieldMark, splitChar) {
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/* ******************* 建模表开发依赖 ******************* */
|
||||||
|
|
||||||
|
const ModeList = {}
|
||||||
|
ModeList.dataLoadAfter = function (data) {
|
||||||
|
// 描述:在列表数据加载完,对列表的数据进行二次加工,并渲染。 dataLoadAfter传入dataHandle方法,用来接收并处理数据,dataHandle有两个参数。
|
||||||
|
// var dataHandle = function(datas,displayType){
|
||||||
|
// //Changes to 'datas' do not directly modify the real database data, but modify the data received at the front end.
|
||||||
|
// var newDatas = datas;
|
||||||
|
// if(displayType == 'normal'){
|
||||||
|
// console.log(newDatas);
|
||||||
|
// }
|
||||||
|
// return newDatas;
|
||||||
|
// }
|
||||||
|
// ModeList.dataLoadAfter(dataHandle);
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,61 @@
|
||||||
|
/**
|
||||||
|
* 柏美 施工合同申请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 DETAIL_MAX_SIZE = 5;
|
||||||
|
// 款项类型预计对应日期取值
|
||||||
|
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
|
||||||
|
}
|
||||||
|
let rowArr = WfForm.getDetailAllRowIndexStr(detailTable).split(",");
|
||||||
|
|
||||||
|
if(rowArr.length !== DETAIL_MAX_SIZE){
|
||||||
|
// 默认增加5条
|
||||||
|
for (let i = 0; i < 5; i++) {
|
||||||
|
WfForm.addDetailRow(detailTable,{ [detail2PaymentTypeId]: {value: i}});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
changeDetailFieldReadOnly(detailTable, detail2ComPayDateId, detail2PaymentTypeId, computeDatePayType)
|
||||||
|
|
||||||
|
// 主表字段发生变化
|
||||||
|
mainFieldChangeDetailCom(contractSignDateId, detailTable, configObj);
|
||||||
|
|
||||||
|
// 明细的款项类型字段变化绑定
|
||||||
|
detailFieldChangeDetailCom(`${detail2PaymentTypeId},${detail2AroundId},${detail2DayId}`, configObj);
|
||||||
|
|
||||||
|
submitCallback(detailTable, detail2PayProportionId);
|
||||||
|
|
||||||
|
});
|
||||||
|
|
|
@ -0,0 +1,175 @@
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 改变明细表字段只读
|
||||||
|
* @param detailTable
|
||||||
|
* @param detailComDateField
|
||||||
|
* @param detailPaymentTypeId
|
||||||
|
* @param readOnlyArr
|
||||||
|
*/
|
||||||
|
function changeDetailFieldReadOnly(detailTable, detailComDateField, detailPaymentTypeId, readOnlyArr){
|
||||||
|
let rowArr = WfForm.getDetailAllRowIndexStr(detailTable).split(",");
|
||||||
|
for(let i=0; i < rowArr.length; i++){
|
||||||
|
let index = rowArr[i];
|
||||||
|
if(index !== ""){
|
||||||
|
let paymentType = WfForm.getFieldValue(`${detailPaymentTypeId}_${index}`);
|
||||||
|
// 先进行赋值
|
||||||
|
if(readOnlyArr.includes(paymentType)){
|
||||||
|
WfForm.changeFieldAttr(`${detailComDateField}_${index}`, READ_ONLY);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,60 @@
|
||||||
|
/**
|
||||||
|
* 柏美 采购合同申请js
|
||||||
|
* @author xuanran.wang
|
||||||
|
*/
|
||||||
|
// 明细表
|
||||||
|
const detailTable = "detail_3";
|
||||||
|
// 主表订单编号字段
|
||||||
|
const mainProjectId = WfForm.convertFieldNameToId("ddh1");
|
||||||
|
// 主表合同签订日期
|
||||||
|
const contractSignDateId = WfForm.convertFieldNameToId("htqdrq");
|
||||||
|
// 主表订单申请日期
|
||||||
|
const mainPOApplyId = WfForm.convertFieldNameToId("rkdsqrq");
|
||||||
|
// 明细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(mainPOApplyId)});
|
||||||
|
},
|
||||||
|
4: (index)=>{
|
||||||
|
WfForm.changeFieldValue(`${detailTempDateField}_${index}`,{value : WfForm.getFieldValue(mainPOApplyId)});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
$(()=>{
|
||||||
|
init();
|
||||||
|
});
|
||||||
|
|
||||||
|
function init(){
|
||||||
|
|
||||||
|
let obj = {
|
||||||
|
'detailPaymentTypeId':detailPaymentTypeId,
|
||||||
|
'detailTempDateId': detailTempDateField,
|
||||||
|
'around': detailAroundId,
|
||||||
|
'detailComPayDateId': detailComPayDateId,
|
||||||
|
'dayId': detailDayId,
|
||||||
|
'computeDatePayType': computeDatePayType,
|
||||||
|
'paymentTypeGetValue': paymentTypeGetValue
|
||||||
|
}
|
||||||
|
changeDetailFieldReadOnly(detailTable, detailComPayDateId, detailPaymentTypeId, computeDatePayType)
|
||||||
|
// 主表字段发生变化
|
||||||
|
mainFieldChangeDetailCom(`${mainProjectId},${contractSignDateId}`, detailTable, obj);
|
||||||
|
// 明细的款项类型字段变化绑定
|
||||||
|
detailFieldChangeDetailCom(`${detailPaymentTypeId},${detailAroundId},${detailDayId}`, obj);
|
||||||
|
submitCallback(detailTable, detailPayProportionId);
|
||||||
|
}
|
|
@ -0,0 +1,62 @@
|
||||||
|
/**
|
||||||
|
* 柏美 销售合同申请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
|
||||||
|
}
|
||||||
|
changeDetailFieldReadOnly(detailTable, detail2ComPayDateId, detail2PaymentTypeId, computeDatePayType)
|
||||||
|
// 主表字段发生变化
|
||||||
|
mainFieldChangeDetailCom(mainProjectId, detailTable, obj);
|
||||||
|
// 明细的款项类型字段变化绑定
|
||||||
|
detailFieldChangeDetailCom(`${detail2PaymentTypeId},${detail2AroundId},${detail2DayId}`, obj);
|
||||||
|
submitCallback(detailTable, detail2PayProportionId);
|
||||||
|
|
||||||
|
}
|
|
@ -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<rowArr.length; i++){
|
||||||
|
var rowIndex = rowArr[i];
|
||||||
|
if(rowIndex !== ""){
|
||||||
|
WfForm.changeFieldAttr(`${detailFileTypeId}_${rowIndex}`, readOnly);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// 明细行上+-按钮清除
|
||||||
|
$('#detail1Btn').empty();
|
||||||
|
}
|
||||||
|
|
||||||
|
WfForm.bindFieldChangeEvent(sealTypeId, function(obj,id,val){ //变更用印方式触发
|
||||||
|
changeDetailFieldVal();
|
||||||
|
if(val == qzyy || val == kmGz){
|
||||||
|
WfForm.delDetailRow("detail_1", "all");
|
||||||
|
}
|
||||||
|
if(pritGz == val || jwGz == val || zh == val){
|
||||||
|
WfForm.changeSingleField(lastField,{value:1}, {viewAttr:readOnly});
|
||||||
|
} else if (kmGz == val){
|
||||||
|
WfForm.changeSingleField(lastField,{value:2}, {viewAttr:readOnly});
|
||||||
|
} else{
|
||||||
|
WfForm.changeSingleField(lastField,{value:''}, {viewAttr:required});
|
||||||
|
}
|
||||||
|
|
||||||
|
addRow();
|
||||||
|
});
|
||||||
|
|
||||||
|
WfForm.bindFieldChangeEvent(`${mainsealtype}, ${mainfr}, ${maingz}, ${mainht}`, function(obj,id,val){
|
||||||
|
WfForm.delDetailRow("detail_1", "all");
|
||||||
|
addRow();
|
||||||
|
})
|
||||||
|
|
||||||
|
WfForm.registerCheckEvent(WfForm.OPER_ADDROW+ "1", function(callback){
|
||||||
|
callback(); //允许继续添加行调用callback,不调用代表阻断添加
|
||||||
|
let val = WfForm.getFieldValue(sealTypeId);
|
||||||
|
if(val == zh){
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
changeDetailFieldVal();
|
||||||
|
});
|
||||||
|
|
||||||
|
})
|
||||||
|
|
||||||
|
function addRow(){
|
||||||
|
let val = WfForm.getFieldValue(sealTypeId);
|
||||||
|
if(val == kmGz || val == qzyy){
|
||||||
|
// 明细1印章种类
|
||||||
|
let detail1SealType = WfForm.convertFieldNameToId("yzzl","detail_1");
|
||||||
|
// 明细1合同专用章次数
|
||||||
|
let detail1ht = WfForm.convertFieldNameToId("htzyzcs","detail_1");
|
||||||
|
// 明细1公章次数
|
||||||
|
let detail1gz = WfForm.convertFieldNameToId("gzcs","detail_1");
|
||||||
|
// 明细1法人章次数
|
||||||
|
let detail1fr = WfForm.convertFieldNameToId("frzcs","detail_1");
|
||||||
|
console.log('detail1SealType ', detail1SealType);
|
||||||
|
console.log('detail1ht ', detail1SealType);
|
||||||
|
console.log('detail1SealType ', detail1SealType);
|
||||||
|
console.log('detail1SealType ', detail1SealType);
|
||||||
|
let obj = {
|
||||||
|
detailFileTypeId: {value:defaultfile},
|
||||||
|
detail1SealType: {value:WfForm.getFieldValue(mainsealtype)},
|
||||||
|
detail1gz: {value:WfForm.getFieldValue(maingz)},
|
||||||
|
detail1fr: {value:WfForm.getFieldValue(mainfr)},
|
||||||
|
detail1ht: {value:WfForm.getFieldValue(mainht)}
|
||||||
|
};
|
||||||
|
console.log('obj ', obj)
|
||||||
|
WfForm.addDetailRow("detail_1",obj);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
function changeDetailFieldVal(){
|
||||||
|
let val = WfForm.getFieldValue(sealTypeId);
|
||||||
|
// 必填
|
||||||
|
let attr = required;
|
||||||
|
let syqf = '';
|
||||||
|
if(val == pritGz || val == jwGz){
|
||||||
|
attr = readOnly;
|
||||||
|
syqf = no;
|
||||||
|
}else{
|
||||||
|
val = '';
|
||||||
|
}
|
||||||
|
|
||||||
|
var rowArr = WfForm.getDetailAllRowIndexStr("detail_1").split(",");
|
||||||
|
for(var i=0; i<rowArr.length; i++){
|
||||||
|
var rowIndex = rowArr[i];
|
||||||
|
if(rowIndex !== ""){
|
||||||
|
WfForm.changeSingleField(`${detailSealTypeId}_${rowIndex}`,{value:val}, {viewAttr:attr});
|
||||||
|
WfForm.changeSingleField(`${detailQfzField}_${rowIndex}`,{value:syqf}, {viewAttr:attr});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,179 @@
|
||||||
|
/* ******************* 丰田纺织流程代码块 可选择流程中的字段配置流程标题生成规则******************* */
|
||||||
|
|
||||||
|
class ConfigWorkflowTitle {
|
||||||
|
|
||||||
|
constructor(config) {
|
||||||
|
this.config = config
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 初始化参数
|
||||||
|
*/
|
||||||
|
init = () => {
|
||||||
|
let baseInfo = WfForm.getBaseInfo();
|
||||||
|
if (baseInfo.workflowid != this.config.workflowId) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
let filedArr = []
|
||||||
|
this.config.rules.filter(item => item.type === RulesType.FIELD_VALUE
|
||||||
|
|| item.type === RulesType.SELECT_VALUE
|
||||||
|
|| item.type === RulesType.RADIO_VALUE).forEach(item => filedArr.push(item.fieldName))
|
||||||
|
this.addListenerEvent(filedArr)
|
||||||
|
this.addListenerSubmitEvent()
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 监听提交流程动作
|
||||||
|
*/
|
||||||
|
addListenerSubmitEvent = () => {
|
||||||
|
Utils.registerAction(WfForm.OPER_SAVE + "," + WfForm.OPER_SUBMIT, callback => {
|
||||||
|
this.changeWorkflowTitle()
|
||||||
|
callback()
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 修改流程标题字段值
|
||||||
|
*/
|
||||||
|
changeWorkflowTitle = () => {
|
||||||
|
let workflowTitle = []
|
||||||
|
this.config.rules.forEach(item => {
|
||||||
|
workflowTitle.push(item.type.run(item))
|
||||||
|
})
|
||||||
|
WfForm.changeFieldValue(this.config.titleFieldName === 'field-1' ? 'field-1' :
|
||||||
|
Utils.convertNameToIdUtil(this.config.titleFieldName), {
|
||||||
|
value: workflowTitle.join("")
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 添加监听方法
|
||||||
|
* @param fileNameArr 需要监听的字段数组
|
||||||
|
*/
|
||||||
|
addListenerEvent = (fileNameArr) => {
|
||||||
|
console.log(Utils.convertNameToIdUtil(fileNameArr))
|
||||||
|
WfForm.bindFieldChangeEvent(Utils.convertNameToIdUtil(fileNameArr), (obj, id, value) => {
|
||||||
|
this.changeWorkflowTitle()
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
class RulesType {
|
||||||
|
// 固定值
|
||||||
|
static FIX_STRING = {
|
||||||
|
value: 0,
|
||||||
|
run: item => item.value
|
||||||
|
}
|
||||||
|
// 字段值
|
||||||
|
static FIELD_VALUE = {
|
||||||
|
value: 1,
|
||||||
|
run: item => Utils.getFiledValueByName(item.fieldName)
|
||||||
|
}
|
||||||
|
// 下拉框显示值
|
||||||
|
static SELECT_VALUE = {
|
||||||
|
value: 2,
|
||||||
|
run: item => $(`div[data-fieldname='${item.fieldName}'] .ant-select-selection-selected-value`).text()
|
||||||
|
}
|
||||||
|
// 单选按钮
|
||||||
|
static RADIO_VALUE = {
|
||||||
|
value: 3,
|
||||||
|
run: item => $(`div[data-fieldname='${item.fieldName}'] .ant-radio.ant-radio.ant-radio-checked.ant-radio-checked`).next().text()
|
||||||
|
}
|
||||||
|
// 当前日期 yyyy-mm-dd
|
||||||
|
static CURRENT_DATE = {
|
||||||
|
value: 4,
|
||||||
|
run: () => {
|
||||||
|
const date = new Date();
|
||||||
|
let year = date.getFullYear();
|
||||||
|
let month = date.getMonth() + 1;
|
||||||
|
let day = date.getDay();
|
||||||
|
if (month < 10) {
|
||||||
|
month = '0' + month
|
||||||
|
}
|
||||||
|
if (day < 10) {
|
||||||
|
day = '0' + day
|
||||||
|
}
|
||||||
|
return year + "-" + month + "-" + day
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// 当前时间 HH:mm:ss
|
||||||
|
static CURRENT_TIME = {
|
||||||
|
value: 5,
|
||||||
|
run: () => {
|
||||||
|
const date = new Date();
|
||||||
|
let hours = date.getHours();
|
||||||
|
let minutes = date.getMinutes();
|
||||||
|
let seconds = date.getSeconds();
|
||||||
|
return hours + ":" + minutes + ":" + seconds
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// 当前年份
|
||||||
|
static CURRENT_YEAR = {
|
||||||
|
value: 6,
|
||||||
|
run: () => new Date().getFullYear()
|
||||||
|
|
||||||
|
}
|
||||||
|
// 当前月份
|
||||||
|
static CURRENT_MONTH = {
|
||||||
|
value: 7,
|
||||||
|
run: () => new Date().getMonth() + 1 < 10 ? new Date().getMonth() + 1 : '0' + new Date().getMonth() + 1
|
||||||
|
|
||||||
|
}
|
||||||
|
// 当前天数
|
||||||
|
static CURRENT_DAY = {
|
||||||
|
value: 8,
|
||||||
|
run: () => new Date().getDay() < 10 ? new Date().getDay() : '0' + new Date().getDay()
|
||||||
|
|
||||||
|
}
|
||||||
|
// 当前小时
|
||||||
|
static CURRENT_HOUR = {
|
||||||
|
value: 9,
|
||||||
|
run: () => new Date().getHours()
|
||||||
|
|
||||||
|
}
|
||||||
|
// 当前分钟
|
||||||
|
static CURRENT_MINUTE = {
|
||||||
|
value: 10,
|
||||||
|
run: () => new Date().getMinutes()
|
||||||
|
|
||||||
|
}
|
||||||
|
// 当前秒数
|
||||||
|
static CURRENT_SECOND = {
|
||||||
|
value: 11,
|
||||||
|
run: () => new Date().getSeconds()
|
||||||
|
}
|
||||||
|
// 当前时间戳
|
||||||
|
static CURRENT_TIME_STAMP = {
|
||||||
|
value: 12,
|
||||||
|
run: () => new Date().getTime()
|
||||||
|
}
|
||||||
|
// 流水号
|
||||||
|
static RANDOM = {
|
||||||
|
value: 13,
|
||||||
|
run: item => {
|
||||||
|
let result = []
|
||||||
|
let range = [1, 2, 3, 4, 5, 6, 7, 8, 9, 0]
|
||||||
|
for (let i = 0; i < item.length; i++) {
|
||||||
|
let index = parseInt(Math.random(0, 10) * 10)
|
||||||
|
result.push(range[index])
|
||||||
|
}
|
||||||
|
return result.join("")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
static BROWSER_SHOW_NAME = {
|
||||||
|
value: 14,
|
||||||
|
run: item => {
|
||||||
|
let fieldId = Utils.convertNameObjToId(item.fieldName)
|
||||||
|
return WfForm.getBrowserShowName(fieldId)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
window.RulesType = RulesType
|
||||||
|
window.ConfigWorkflowTitle = ConfigWorkflowTitle
|
||||||
|
|
||||||
|
/* ******************* 可选择流程中的字段配置流程标题生成规则 end ******************* */
|
|
@ -0,0 +1,29 @@
|
||||||
|
/* ******************* youhong.ai 丰田纺织流程代码块 可选择流程中的字段配置流程标题生成规则******************* */
|
||||||
|
|
||||||
|
$(() => {
|
||||||
|
let workflowTitleConfig = {
|
||||||
|
workflowId: '44',
|
||||||
|
titleFieldName: 'field-1',
|
||||||
|
rules: [{
|
||||||
|
type: RulesType.CURRENT_DATE
|
||||||
|
},
|
||||||
|
{
|
||||||
|
type: RulesType.FIX_STRING,
|
||||||
|
value: '-'
|
||||||
|
}, {
|
||||||
|
type: RulesType.FIELD_VALUE,
|
||||||
|
fieldName: 'mc'
|
||||||
|
}, {
|
||||||
|
type: RulesType.FIELD_VALUE,
|
||||||
|
fieldName: 'sjid'
|
||||||
|
}, {
|
||||||
|
type: RulesType.RANDOM,
|
||||||
|
length: 5
|
||||||
|
}, {
|
||||||
|
type: RulesType.RANDOM,
|
||||||
|
length: 5
|
||||||
|
}]
|
||||||
|
}
|
||||||
|
new ConfigWorkflowTitle(workflowTitleConfig).init()
|
||||||
|
})
|
||||||
|
/* ******************* 可选择流程中的字段配置流程标题生成规则 end ******************* */
|
|
@ -1 +1,300 @@
|
||||||
// 流程代码块
|
/* ******************* 保时捷target setting流程提交控制 start ******************* */
|
||||||
|
window.workflowCus = Object.assign(window.workflowCus ? window.workflowCus : {}, {
|
||||||
|
/**
|
||||||
|
* @author youhong.ai
|
||||||
|
* @desc 禁止点击提交按钮
|
||||||
|
*/
|
||||||
|
doNotClickSubmit: function () {
|
||||||
|
let submitButton = $('.ant-btn.ant-btn-primary[ecid="_Route@vmt0lk_Comp@upn4fo_Button@2oxqe7@0_button@xq1ea3"][title="Submit "]')
|
||||||
|
if (submitButton.length === 0) {
|
||||||
|
submitButton = $('.ant-btn.ant-btn-primary[ecid="_Route@vmt0lk_Comp@upn4fo_Button@2oxqe7@0_button@xq1ea3"][title="提交"]')
|
||||||
|
}
|
||||||
|
if (submitButton.length === 0) {
|
||||||
|
submitButton = $("#weareqtop_9v5e5i_1670481049632 div.ant-row.wea-new-top-req div.ant-col-xs-18.ant-col-sm-18.ant-col-md-16.ant-col-lg-14 button[title='提交'],[title='Submit '],[title='Submit']")
|
||||||
|
}
|
||||||
|
if (submitButton.length !== 0) {
|
||||||
|
let buttonReact = window.Utils.findReact(submitButton[0])
|
||||||
|
let rightBtn = Utils.findReact($(".ant-menu-item.text-elli[ecid='_Route@vmt0lk_Comp@upn4fo_WeaRightMenu@1ok9r0_Item@eu37n0_li@zyccqn']")[0])
|
||||||
|
setTimeout(() => {
|
||||||
|
buttonReact.props.disabled = true
|
||||||
|
buttonReact.setState({})
|
||||||
|
rightBtn.props.disabled = true
|
||||||
|
rightBtn.setState({})
|
||||||
|
}, 100)
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author youhong.ai
|
||||||
|
* @desc 允许点击按钮
|
||||||
|
*/
|
||||||
|
allowClickSubmit: function () {
|
||||||
|
let submitButton = $('.ant-btn.ant-btn-primary[ecid="_Route@vmt0lk_Comp@upn4fo_Button@2oxqe7@0_button@xq1ea3"][title="Submit "]')
|
||||||
|
if (submitButton.length === 0) {
|
||||||
|
submitButton = $('.ant-btn.ant-btn-primary[ecid="_Route@vmt0lk_Comp@upn4fo_Button@2oxqe7@0_button@xq1ea3"][title="提交"]')
|
||||||
|
}
|
||||||
|
if (submitButton.length === 0) {
|
||||||
|
submitButton = $("#weareqtop_9v5e5i_1670481049632 div.ant-row.wea-new-top-req div.ant-col-xs-18.ant-col-sm-18.ant-col-md-16.ant-col-lg-14 button[title='提交'],[title='Submit '],[title='Submit']")
|
||||||
|
}
|
||||||
|
if (submitButton.length !== 0) {
|
||||||
|
WfForm.controlBtnDisabled(false)
|
||||||
|
let buttonReact = window.Utils.findReact(submitButton[0])
|
||||||
|
buttonReact.props.disabled = false
|
||||||
|
buttonReact.setState({})
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 监听qzhj字段值改变
|
||||||
|
* @author youhong.ai
|
||||||
|
* @param id 字段id
|
||||||
|
* @param value 字段值
|
||||||
|
* @param obj 字段值对象
|
||||||
|
*/
|
||||||
|
onQzhjFieldChangeValue: function (obj, id, value) {
|
||||||
|
if (value != '100') {
|
||||||
|
window.workflowCus.doNotClickSubmit()
|
||||||
|
} else {
|
||||||
|
window.workflowCus.allowClickSubmit()
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 检查qzhj字段值
|
||||||
|
* @author youhong.ai
|
||||||
|
* @param fieldId qzhj字段id
|
||||||
|
*/
|
||||||
|
checkOnQzhJfiedlChangeValue: function (fieldId) {
|
||||||
|
let value = WfForm.getFieldValue(fieldId);
|
||||||
|
window.workflowCus.onQzhjFieldChangeValue(null, null, value)
|
||||||
|
},
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 检查提交按钮是否符合条件
|
||||||
|
* @author youhong.ai
|
||||||
|
* @param fieldId 字段id
|
||||||
|
* @returns {(function(function()=): void)|*}
|
||||||
|
*/
|
||||||
|
checkClickSubmit: function (fieldId) {
|
||||||
|
return (callback = () => {
|
||||||
|
}) => {
|
||||||
|
let value = WfForm.getFieldValue(fieldId);
|
||||||
|
if (value != 100) {
|
||||||
|
WfForm.showMessage("~`~`7 目标设定的总值必须是100%,请检查并修改后提交。 " + "`~`8 The total value of target setting must be 100%,please check to submit after modification! " + "`~`9 目标设定的总值必须是100%,请检查并修改后提交。`~`~", 2, 5);
|
||||||
|
} else {
|
||||||
|
callback()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 保存按钮触发流程转数据
|
||||||
|
* @author youhong.ai
|
||||||
|
*/
|
||||||
|
saveTriggerWorkflowToModel: async function () {
|
||||||
|
let baseInfo = WfForm.getBaseInfo()
|
||||||
|
if (baseInfo && baseInfo.requestid != '-1') {
|
||||||
|
let result = await Utils.api({
|
||||||
|
url: "/api/aiyh/workflow/target-setting/save-trigger",
|
||||||
|
type: "POST",
|
||||||
|
contentType: "application/json",
|
||||||
|
data: JSON.stringify({
|
||||||
|
requestId: baseInfo.requestid,
|
||||||
|
nodeId: baseInfo.nodeid,
|
||||||
|
isBill: baseInfo.isbill,
|
||||||
|
formId: baseInfo.formid,
|
||||||
|
workflowId: baseInfo.workflowid
|
||||||
|
})
|
||||||
|
})
|
||||||
|
if (result && result.code === 200) {
|
||||||
|
localStorage.setItem("saveTriggerWorkflowToModel", "false")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
|
||||||
|
saveAfterCallback: function (callback) {
|
||||||
|
localStorage.setItem("saveTriggerWorkflowToModel", "true")
|
||||||
|
callback()
|
||||||
|
}
|
||||||
|
|
||||||
|
})
|
||||||
|
|
||||||
|
/* ******************* 保时捷target setting流程提交控制 end ******************* */
|
||||||
|
|
||||||
|
/* ******************* 保时捷target setting流程提交控制 start ******************* */
|
||||||
|
$(() => {
|
||||||
|
let qzhjFieldId = WfForm.convertFieldNameToId("qzhj")
|
||||||
|
window.workflowCus.checkOnQzhJfiedlChangeValue(qzhjFieldId)
|
||||||
|
WfForm.registerCheckEvent(WfForm.OPER_SUBMIT, window.workflowCus.checkClickSubmit(qzhjFieldId))
|
||||||
|
WfForm.registerCheckEvent(WfForm.OPER_SAVECOMPLETE, window.workflowCus.saveAfterCallback)
|
||||||
|
WfForm.bindFieldChangeEvent(qzhjFieldId, window.workflowCus.onQzhjFieldChangeValue)
|
||||||
|
let flag = localStorage.getItem("saveTriggerWorkflowToModel")
|
||||||
|
if (flag === "true") {
|
||||||
|
window.workflowCus.saveTriggerWorkflowToModel()
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
/* ******************* 保时捷target setting流程提交控制 end ******************* */
|
||||||
|
|
||||||
|
|
||||||
|
/* ******************* 保时捷个人目标台账查询target setting按钮默认置灰色 ******************* */
|
||||||
|
window.workflowCus = Object.assign(window.workflowCus ? window.workflowCus : {}, {
|
||||||
|
|
||||||
|
notAllowedTargetSetting: function () {
|
||||||
|
window.workflowCus.changeBtnDisabledValue(true)
|
||||||
|
},
|
||||||
|
|
||||||
|
changeBtnDisabledValue: function (disable) {
|
||||||
|
if ($(".ant-btn.ant-btn-primary[ecid='_Route@9uoqid_Com@knmejd_ButtonNew@813let@0_Button@tegwjx_button@xq1ea3']").length === 0) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
let button = Utils.findReact($(".ant-btn.ant-btn-primary[ecid='_Route@9uoqid_Com@knmejd_ButtonNew@813let@0_Button@tegwjx_button@xq1ea3']")[0])
|
||||||
|
if (button) {
|
||||||
|
button.props.disabled = disable
|
||||||
|
button.setState({})
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
allowedTargetSettingBtnClick: function () {
|
||||||
|
window.workflowCus.changeBtnDisabledValue(false)
|
||||||
|
},
|
||||||
|
|
||||||
|
queryTotalWeight: function () {
|
||||||
|
Utils.api({
|
||||||
|
url: "/api/ayh/target-setting/btn/can-allowed"
|
||||||
|
}).then(res => {
|
||||||
|
if (res && res.code === 200) {
|
||||||
|
if (res.data) {
|
||||||
|
window.workflowCus.allowedTargetSettingBtnClick()
|
||||||
|
} else {
|
||||||
|
window.workflowCus.notAllowedTargetSetting()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}).catch(error => {
|
||||||
|
console.log(err)
|
||||||
|
})
|
||||||
|
},
|
||||||
|
|
||||||
|
reRender: function () {
|
||||||
|
const dataHandle = function (datas, displayType) {
|
||||||
|
window.workflowCus.notAllowedTargetSetting()
|
||||||
|
//Changes to 'datas' do not directly modify the real database data, but modify the data received at the front end.
|
||||||
|
$(() => {
|
||||||
|
window.workflowCus.queryTotalWeight()
|
||||||
|
})
|
||||||
|
return datas
|
||||||
|
|
||||||
|
}
|
||||||
|
ModeList.dataLoadAfter(dataHandle)
|
||||||
|
}
|
||||||
|
|
||||||
|
})
|
||||||
|
|
||||||
|
$(() => {
|
||||||
|
window.workflowCus.notAllowedTargetSetting()
|
||||||
|
setTimeout(() => {
|
||||||
|
window.workflowCus.notAllowedTargetSetting()
|
||||||
|
}, 10)
|
||||||
|
window.workflowCus.reRender()
|
||||||
|
})
|
||||||
|
/* ******************* 保时捷个人目标台账查询target setting按钮默认置灰色 END ******************* */
|
||||||
|
|
||||||
|
|
||||||
|
/* ******************* apa流程通过apa分数字段带出level字段 ******************* */
|
||||||
|
|
||||||
|
window.workflowCus = Object.assign(window.workflowCus ? window.workflowCus : {}, {
|
||||||
|
getLevelByScore: async function (config) {
|
||||||
|
let scoreFiled = config.scoreFiled
|
||||||
|
let score = Utils.getFiledValueByName(scoreFiled);
|
||||||
|
if (score == 0 || score == '') {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
let result = await Utils.api({
|
||||||
|
url: "/api/ayh/workflow/apa/level",
|
||||||
|
data: {
|
||||||
|
score
|
||||||
|
}
|
||||||
|
})
|
||||||
|
if (result && result.code === 200) {
|
||||||
|
Utils.changeFieldValueByName(config.levelField, result.data)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
})
|
||||||
|
/* ******************* apa流程通过apa分数字段带出level字段eng ******************* */
|
||||||
|
|
||||||
|
|
||||||
|
/* ******************* apa流程通过apa分数字段带出level字段 ******************* */
|
||||||
|
$(() => {
|
||||||
|
let config = {
|
||||||
|
scoreFiled: "apafsptyg",
|
||||||
|
levelField: "level1"
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
setTimeout(() => {
|
||||||
|
WfForm.bindFieldChangeEvent(Utils.convertNameObjToId(config.scoreFiled), () => {
|
||||||
|
window.workflowCus.getLevelByScore(config)
|
||||||
|
})
|
||||||
|
window.workflowCus.getLevelByScore(config)
|
||||||
|
}, 100)
|
||||||
|
} catch (err) {
|
||||||
|
console.log(err)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
/* ******************* apa流程通过apa分数字段带出level字段eng ******************* */
|
||||||
|
|
||||||
|
|
||||||
|
/* ******************* apa(employee)流程明细分数控制 ******************* */
|
||||||
|
function addChangeEventListener(configItem) {
|
||||||
|
let fieldIds = Utils.convertNameToIdUtil([{
|
||||||
|
fieldName: configItem.selfEvaluationScore,
|
||||||
|
table: configItem.table
|
||||||
|
}, {
|
||||||
|
fieldName: configItem.leaderScore,
|
||||||
|
table: configItem.table
|
||||||
|
}])
|
||||||
|
WfForm.bindDetailFieldChangeEvent(fieldIds, (id, rowIndex, value) => {
|
||||||
|
if (value == '') {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if (value >= 1 && value <= 5) {
|
||||||
|
if (value % 0.5 !== 0) {
|
||||||
|
showHint(id + "_" + rowIndex)
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
showHint(id + "_" + rowIndex)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
function showHint(id) {
|
||||||
|
WfForm.showMessage(`Evaluate your target completion by selecting a score.
|
||||||
|
The scores are of 0.5 break-down.
|
||||||
|
5 - Outstanding
|
||||||
|
4 - Exceeds Expectations
|
||||||
|
3 - Meets Expectations
|
||||||
|
2 - Needs Improvement
|
||||||
|
1 - Unsatisfactory`, 2, 10)
|
||||||
|
setTimeout(() => {
|
||||||
|
WfForm.changeFieldValue(id, {value: ""})
|
||||||
|
}, 100)
|
||||||
|
}
|
||||||
|
|
||||||
|
$(() => {
|
||||||
|
let employeeDetailConfig = [{
|
||||||
|
table: 'detail_1',
|
||||||
|
selfEvaluationScore: 'zp',
|
||||||
|
leaderScore: 'ldpf'
|
||||||
|
}, {
|
||||||
|
table: 'detail_2',
|
||||||
|
selfEvaluationScore: 'zp',
|
||||||
|
leaderScore: 'ldpf'
|
||||||
|
}]
|
||||||
|
employeeDetailConfig.forEach(item => {
|
||||||
|
addChangeEventListener(item)
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
|
/* ******************* apa(employee)流程明细分数控制end ******************* */
|
29
pom.xml
29
pom.xml
|
@ -1,4 +1,4 @@
|
||||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://maven.apache.org/POM/4.0.0"
|
||||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
|
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
|
||||||
<!--指定了当前pom的版本,4.0.0是固定的 -->
|
<!--指定了当前pom的版本,4.0.0是固定的 -->
|
||||||
<modelVersion>4.0.0</modelVersion>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
@ -56,8 +56,8 @@
|
||||||
<version>${lombok.version}</version>
|
<version>${lombok.version}</version>
|
||||||
<scope>provided</scope>
|
<scope>provided</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
|
|
||||||
<!-- 单元测试-->
|
<!-- 单元测试-->
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>junit</groupId>
|
<groupId>junit</groupId>
|
||||||
|
@ -65,7 +65,28 @@
|
||||||
<version>4.12</version>
|
<version>4.12</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
|
|
||||||
|
<!-- easy excel -->
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.alibaba</groupId>
|
||||||
|
<artifactId>easyexcel</artifactId>
|
||||||
|
<version>2.2.0-beta1</version>
|
||||||
|
<exclusions>
|
||||||
|
<exclusion>
|
||||||
|
<groupId>org.slf4j</groupId>
|
||||||
|
<artifactId>slf4j-api</artifactId>
|
||||||
|
</exclusion>
|
||||||
|
</exclusions>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.apache.rocketmq</groupId>
|
||||||
|
<artifactId>rocketmq-client</artifactId>
|
||||||
|
<version>4.4.0</version>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
</dependencies>
|
</dependencies>
|
||||||
|
|
||||||
|
|
|
@ -26,7 +26,6 @@ select (bill.id + '-' + base.id) id,
|
||||||
from workflow_billdetailtable bill
|
from workflow_billdetailtable bill
|
||||||
join workflow_base base on base.formid = bill.billid;
|
join workflow_base base on base.formid = bill.billid;
|
||||||
|
|
||||||
|
|
||||||
create view workflow_field_table_view as
|
create view workflow_field_table_view as
|
||||||
select wb.id,
|
select wb.id,
|
||||||
wb.fieldname,
|
wb.fieldname,
|
||||||
|
|
|
@ -10,9 +10,9 @@ import java.util.regex.Matcher;
|
||||||
import java.util.regex.Pattern;
|
import java.util.regex.Pattern;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author EBU7-dev1-ayh
|
* <h1>多语言工具类</h1>
|
||||||
* create 2021/12/13 0013 10:29
|
*
|
||||||
* 多语言工具类
|
* @author EBU7-dev1-ayh create 2021/12/13 0013 10:29
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -7,24 +7,26 @@ import java.io.File;
|
||||||
import java.io.Reader;
|
import java.io.Reader;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author EBU7-dev1-ayh
|
* <h1>mybatis集成工具</h1>
|
||||||
* create 2021/12/14 0014 15:57
|
*
|
||||||
|
* @author EBU7-dev1-ayh create 2021/12/14 0014 15:57
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
public class MybatisUtil {
|
public class MybatisUtil {
|
||||||
private static SqlSessionManager sqlSessionManager = null;
|
private static SqlSessionManager sqlSessionManager = null;
|
||||||
|
|
||||||
private synchronized static void init(String config){
|
private synchronized static void init(String config) {
|
||||||
try {
|
try {
|
||||||
Reader resourceAsReader = Resources.getResourceAsReader("WEB-INF" + File.separator +config);
|
Reader resourceAsReader = Resources.getResourceAsReader("WEB-INF" + File.separator + config);
|
||||||
sqlSessionManager = SqlSessionManager.newInstance(resourceAsReader);
|
sqlSessionManager = SqlSessionManager.newInstance(resourceAsReader);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
public static SqlSessionManager getSessionManager(String config){
|
|
||||||
if(sqlSessionManager == null){
|
public static SqlSessionManager getSessionManager(String config) {
|
||||||
|
if (sqlSessionManager == null) {
|
||||||
synchronized (MybatisUtil.class) {
|
synchronized (MybatisUtil.class) {
|
||||||
if (sqlSessionManager == null) {
|
if (sqlSessionManager == null) {
|
||||||
init(config);
|
init(config);
|
||||||
|
@ -34,7 +36,7 @@ public class MybatisUtil {
|
||||||
return sqlSessionManager;
|
return sqlSessionManager;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static <T> T getMapper(Class<T> tClass){
|
public static <T> T getMapper(Class<T> tClass) {
|
||||||
return sqlSessionManager.getMapper(tClass);
|
return sqlSessionManager.getMapper(tClass);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,8 +1,11 @@
|
||||||
package aiyh.utils;
|
package aiyh.utils;
|
||||||
|
|
||||||
import aiyh.utils.action.CusBaseAction;
|
import aiyh.utils.action.CusBaseAction;
|
||||||
|
import aiyh.utils.action.SafeCusActionProcessInterface;
|
||||||
import aiyh.utils.annotation.*;
|
import aiyh.utils.annotation.*;
|
||||||
|
import aiyh.utils.annotation.recordset.SqlMapper;
|
||||||
import aiyh.utils.entity.*;
|
import aiyh.utils.entity.*;
|
||||||
|
import aiyh.utils.excention.BindingException;
|
||||||
import aiyh.utils.excention.CustomerException;
|
import aiyh.utils.excention.CustomerException;
|
||||||
import aiyh.utils.fileUtil.ProperUtil;
|
import aiyh.utils.fileUtil.ProperUtil;
|
||||||
import aiyh.utils.mapUtil.UtilHashMap;
|
import aiyh.utils.mapUtil.UtilHashMap;
|
||||||
|
@ -43,6 +46,8 @@ import weaver.soa.workflow.request.RequestInfo;
|
||||||
import weaver.soa.workflow.request.RequestService;
|
import weaver.soa.workflow.request.RequestService;
|
||||||
import weaver.systeminfo.SystemEnv;
|
import weaver.systeminfo.SystemEnv;
|
||||||
import weaver.workflow.request.RequestManager;
|
import weaver.workflow.request.RequestManager;
|
||||||
|
import weaver.workflow.workflow.WorkflowBillComInfo;
|
||||||
|
import weaver.workflow.workflow.WorkflowComInfo;
|
||||||
import weaver.workflow.workflow.WorkflowVersion;
|
import weaver.workflow.workflow.WorkflowVersion;
|
||||||
|
|
||||||
import javax.servlet.http.HttpServletRequest;
|
import javax.servlet.http.HttpServletRequest;
|
||||||
|
@ -52,10 +57,7 @@ import java.beans.IntrospectionException;
|
||||||
import java.beans.Introspector;
|
import java.beans.Introspector;
|
||||||
import java.beans.PropertyDescriptor;
|
import java.beans.PropertyDescriptor;
|
||||||
import java.io.*;
|
import java.io.*;
|
||||||
import java.lang.reflect.Field;
|
import java.lang.reflect.*;
|
||||||
import java.lang.reflect.InvocationTargetException;
|
|
||||||
import java.lang.reflect.Method;
|
|
||||||
import java.lang.reflect.Modifier;
|
|
||||||
import java.math.BigDecimal;
|
import java.math.BigDecimal;
|
||||||
import java.net.URLDecoder;
|
import java.net.URLDecoder;
|
||||||
import java.nio.charset.StandardCharsets;
|
import java.nio.charset.StandardCharsets;
|
||||||
|
@ -93,6 +95,7 @@ public class Util extends weaver.general.Util {
|
||||||
public static final String UF_CUS_DEV_CONFIG = "uf_cus_dev_config";
|
public static final String UF_CUS_DEV_CONFIG = "uf_cus_dev_config";
|
||||||
private static final UtilService utilService = new UtilService();
|
private static final UtilService utilService = new UtilService();
|
||||||
private static final RecordsetUtil recordsetUtil = new RecordsetUtil();
|
private static final RecordsetUtil recordsetUtil = new RecordsetUtil();
|
||||||
|
private static final RecordsetUtil recordsetTransUtil = new RecordsetUtil();
|
||||||
private static final UtilMapper mapper = recordsetUtil.getMapper(UtilMapper.class);
|
private static final UtilMapper mapper = recordsetUtil.getMapper(UtilMapper.class);
|
||||||
private static final Map<String, Logger> otherLog = new HashMap<>(8);
|
private static final Map<String, Logger> otherLog = new HashMap<>(8);
|
||||||
static ToolUtil toolUtil = new ToolUtil();
|
static ToolUtil toolUtil = new ToolUtil();
|
||||||
|
@ -186,7 +189,7 @@ public class Util extends weaver.general.Util {
|
||||||
String str = sqlBuilder.toString().trim();
|
String str = sqlBuilder.toString().trim();
|
||||||
String removeSeparator = ",";
|
String removeSeparator = ",";
|
||||||
if (str.endsWith(removeSeparator)) {
|
if (str.endsWith(removeSeparator)) {
|
||||||
// 如果以分割号结尾,则去除分割号
|
// 如果以分割号结尾,则去除分割号
|
||||||
str = str.substring(0, str.length() - 1);
|
str = str.substring(0, str.length() - 1);
|
||||||
}
|
}
|
||||||
if (str.trim().startsWith(removeSeparator)) {
|
if (str.trim().startsWith(removeSeparator)) {
|
||||||
|
@ -205,7 +208,7 @@ public class Util extends weaver.general.Util {
|
||||||
public static String removeSeparator(StringBuilder sqlBuilder, String removeSeparator) {
|
public static String removeSeparator(StringBuilder sqlBuilder, String removeSeparator) {
|
||||||
String str = sqlBuilder.toString().trim();
|
String str = sqlBuilder.toString().trim();
|
||||||
if (str.endsWith(removeSeparator)) {
|
if (str.endsWith(removeSeparator)) {
|
||||||
// 如果以分割号结尾,则去除分割号
|
// 如果以分割号结尾,则去除分割号
|
||||||
str = str.substring(0, str.length() - 1);
|
str = str.substring(0, str.length() - 1);
|
||||||
}
|
}
|
||||||
if (str.trim().startsWith(removeSeparator)) {
|
if (str.trim().startsWith(removeSeparator)) {
|
||||||
|
@ -224,7 +227,7 @@ public class Util extends weaver.general.Util {
|
||||||
public static String removeSeparator(String string, String removeSeparator) {
|
public static String removeSeparator(String string, String removeSeparator) {
|
||||||
String str = string.trim();
|
String str = string.trim();
|
||||||
if (str.endsWith(removeSeparator)) {
|
if (str.endsWith(removeSeparator)) {
|
||||||
// 如果以分割号结尾,则去除分割号
|
// 如果以分割号结尾,则去除分割号
|
||||||
str = str.substring(0, str.length() - 1);
|
str = str.substring(0, str.length() - 1);
|
||||||
}
|
}
|
||||||
if (str.trim().startsWith(removeSeparator)) {
|
if (str.trim().startsWith(removeSeparator)) {
|
||||||
|
@ -1212,8 +1215,8 @@ public class Util extends weaver.general.Util {
|
||||||
inputStream = new BufferedInputStream(new FileInputStream(path));
|
inputStream = new BufferedInputStream(new FileInputStream(path));
|
||||||
is = new InputStreamReader(inputStream, StandardCharsets.UTF_8);
|
is = new InputStreamReader(inputStream, StandardCharsets.UTF_8);
|
||||||
prop.load(is);
|
prop.load(is);
|
||||||
// Enumeration<?> enumeration = prop.propertyNames();
|
// Enumeration<?> enumeration = prop.propertyNames();
|
||||||
// 顺序读取
|
// 顺序读取
|
||||||
Enumeration<?> enumeration = prop.keys();
|
Enumeration<?> enumeration = prop.keys();
|
||||||
while (enumeration.hasMoreElements()) {
|
while (enumeration.hasMoreElements()) {
|
||||||
String key = (String) enumeration.nextElement();
|
String key = (String) enumeration.nextElement();
|
||||||
|
@ -1256,7 +1259,7 @@ public class Util extends weaver.general.Util {
|
||||||
Pattern compile = Pattern.compile(objRegex);
|
Pattern compile = Pattern.compile(objRegex);
|
||||||
Matcher matcher = compile.matcher(key);
|
Matcher matcher = compile.matcher(key);
|
||||||
if (matcher.find()) {
|
if (matcher.find()) {
|
||||||
// 只匹配前缀.key=value模式的
|
// 只匹配前缀.key=value模式的
|
||||||
String resultKey = matcher.group("key");
|
String resultKey = matcher.group("key");
|
||||||
preResult.put(resultKey, prop2MapPutValue(value));
|
preResult.put(resultKey, prop2MapPutValue(value));
|
||||||
}
|
}
|
||||||
|
@ -1264,7 +1267,7 @@ public class Util extends weaver.general.Util {
|
||||||
compile = Pattern.compile(moreKey);
|
compile = Pattern.compile(moreKey);
|
||||||
matcher = compile.matcher(key);
|
matcher = compile.matcher(key);
|
||||||
if (matcher.find()) {
|
if (matcher.find()) {
|
||||||
// 匹配前缀.key1.key2=value模式的
|
// 匹配前缀.key1.key2=value模式的
|
||||||
String objKey = matcher.group("objKey");
|
String objKey = matcher.group("objKey");
|
||||||
String prefixStr = prePrefix + "." + objKey;
|
String prefixStr = prePrefix + "." + objKey;
|
||||||
Map<String, Object> valueMap;
|
Map<String, Object> valueMap;
|
||||||
|
@ -1282,11 +1285,11 @@ public class Util extends weaver.general.Util {
|
||||||
compile = Pattern.compile(strList);
|
compile = Pattern.compile(strList);
|
||||||
matcher = compile.matcher(key);
|
matcher = compile.matcher(key);
|
||||||
if (matcher.find()) {
|
if (matcher.find()) {
|
||||||
// 匹配前缀.key[0]=value模式的
|
// 匹配前缀.key[0]=value模式的
|
||||||
String objKey = matcher.group("key");
|
String objKey = matcher.group("key");
|
||||||
int index = Integer.parseInt(matcher.group("index"));
|
int index = Integer.parseInt(matcher.group("index"));
|
||||||
if (preResult.containsKey(objKey)) {
|
if (preResult.containsKey(objKey)) {
|
||||||
// 存在值
|
// 存在值
|
||||||
List<Object> valueList = (List<Object>) preResult.get(objKey);
|
List<Object> valueList = (List<Object>) preResult.get(objKey);
|
||||||
if (index >= valueList.size()) {
|
if (index >= valueList.size()) {
|
||||||
valueList.add(prop2MapPutValue(value));
|
valueList.add(prop2MapPutValue(value));
|
||||||
|
@ -1301,19 +1304,19 @@ public class Util extends weaver.general.Util {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
String objArray = "^(" + prePrefix + "\\.)(?<arrKey>(\\w+))(\\[(?<index>([0-9])+)])\\.(?<objKey>(\\S)+)$";
|
String objArray = "^(" + prePrefix + "\\.)(?<arrKey>(\\w+))(\\[(?<index>([0-9])+)])\\.(?<objKey>(\\S)+)$";
|
||||||
// String objArray = "^("+prePrefix+"\\.)(?<arrKey>(\\w+))(\\[(?<index>([0-9])+)])(\\.(?<objKey>(\\S)+))+";
|
// String objArray = "^("+prePrefix+"\\.)(?<arrKey>(\\w+))(\\[(?<index>([0-9])+)])(\\.(?<objKey>(\\S)+))+";
|
||||||
compile = Pattern.compile(objArray);
|
compile = Pattern.compile(objArray);
|
||||||
matcher = compile.matcher(key);
|
matcher = compile.matcher(key);
|
||||||
if (matcher.find()) {
|
if (matcher.find()) {
|
||||||
// 匹配前缀.key[0].name=value的模式
|
// 匹配前缀.key[0].name=value的模式
|
||||||
String arrKey = matcher.group("arrKey");
|
String arrKey = matcher.group("arrKey");
|
||||||
String objKey = matcher.group("objKey");
|
String objKey = matcher.group("objKey");
|
||||||
int index = Integer.parseInt(matcher.group("index"));
|
int index = Integer.parseInt(matcher.group("index"));
|
||||||
List<Map<String, Object>> mapList;
|
List<Map<String, Object>> mapList;
|
||||||
if (preResult.containsKey(arrKey)) {
|
if (preResult.containsKey(arrKey)) {
|
||||||
// 存在
|
// 存在
|
||||||
mapList = (List<Map<String, Object>>) preResult.get(arrKey);
|
mapList = (List<Map<String, Object>>) preResult.get(arrKey);
|
||||||
// mapList
|
// mapList
|
||||||
Map<String, Object> valueMap;
|
Map<String, Object> valueMap;
|
||||||
if (index >= mapList.size()) {
|
if (index >= mapList.size()) {
|
||||||
valueMap = new HashMap<>();
|
valueMap = new HashMap<>();
|
||||||
|
@ -1346,7 +1349,7 @@ public class Util extends weaver.general.Util {
|
||||||
int arrMoreIndex = Integer.parseInt(arrMoreKeyMatcher.group("index"));
|
int arrMoreIndex = Integer.parseInt(arrMoreKeyMatcher.group("index"));
|
||||||
List<Object> arrMoreListValue;
|
List<Object> arrMoreListValue;
|
||||||
if (valueMap.containsKey(arrMoreArrKey)) {
|
if (valueMap.containsKey(arrMoreArrKey)) {
|
||||||
// 存在值
|
// 存在值
|
||||||
arrMoreListValue = (List<Object>) valueMap.get(arrMoreArrKey);
|
arrMoreListValue = (List<Object>) valueMap.get(arrMoreArrKey);
|
||||||
if (arrMoreIndex >= arrMoreListValue.size()) {
|
if (arrMoreIndex >= arrMoreListValue.size()) {
|
||||||
arrMoreListValue.add(prop2MapPutValue(value));
|
arrMoreListValue.add(prop2MapPutValue(value));
|
||||||
|
@ -1361,11 +1364,11 @@ public class Util extends weaver.general.Util {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
// 直接添加
|
// 直接添加
|
||||||
valueMap.put(objKey, prop2MapPutValue(value));
|
valueMap.put(objKey, prop2MapPutValue(value));
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
// 不存在
|
// 不存在
|
||||||
mapList = new ArrayList<>();
|
mapList = new ArrayList<>();
|
||||||
Map<String, Object> valueMap = new HashMap<>();
|
Map<String, Object> valueMap = new HashMap<>();
|
||||||
valueMap.put(objKey, prop2MapPutValue(value));
|
valueMap.put(objKey, prop2MapPutValue(value));
|
||||||
|
@ -1494,7 +1497,7 @@ public class Util extends weaver.general.Util {
|
||||||
//
|
//
|
||||||
private static <T> Predicate<T> distinctByKey(Function<? super T, ?> keyExtractor) {
|
private static <T> Predicate<T> distinctByKey(Function<? super T, ?> keyExtractor) {
|
||||||
Map<Object, Boolean> seen = new ConcurrentHashMap<>();
|
Map<Object, Boolean> seen = new ConcurrentHashMap<>();
|
||||||
// putIfAbsent添加不存在的键,返回null,如果为null表示不重复
|
// putIfAbsent添加不存在的键,返回null,如果为null表示不重复
|
||||||
return t -> seen.putIfAbsent(keyExtractor.apply(t), Boolean.TRUE) == null;
|
return t -> seen.putIfAbsent(keyExtractor.apply(t), Boolean.TRUE) == null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1585,7 +1588,7 @@ public class Util extends weaver.general.Util {
|
||||||
for (int i = 0; i < inputList.size(); i++) {
|
for (int i = 0; i < inputList.size(); i++) {
|
||||||
T item = inputList.get(i);
|
T item = inputList.get(i);
|
||||||
if (item instanceof InputStream) {
|
if (item instanceof InputStream) {
|
||||||
// 属于单级文件,直接压缩并返回
|
// 属于单级文件,直接压缩并返回
|
||||||
try {
|
try {
|
||||||
zipOut.putNextEntry(new ZipEntry(base + i));
|
zipOut.putNextEntry(new ZipEntry(base + i));
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
|
@ -1618,7 +1621,7 @@ public class Util extends weaver.general.Util {
|
||||||
if (item instanceof ListZipEntity) {
|
if (item instanceof ListZipEntity) {
|
||||||
ListZipEntity listZipEntity = (ListZipEntity) item;
|
ListZipEntity listZipEntity = (ListZipEntity) item;
|
||||||
if (listZipEntity.isDirectory()) {
|
if (listZipEntity.isDirectory()) {
|
||||||
// 表示属于文件夹,循环添加处理文件夹
|
// 表示属于文件夹,循环添加处理文件夹
|
||||||
handlerDirectory(listZipEntity.getFileList(), zipOut, base + listZipEntity.getDirectory() + File.separator);
|
handlerDirectory(listZipEntity.getFileList(), zipOut, base + listZipEntity.getDirectory() + File.separator);
|
||||||
} else {
|
} else {
|
||||||
List<AInputStream> aInputStreams = listZipEntity.getaInputStreamList();
|
List<AInputStream> aInputStreams = listZipEntity.getaInputStreamList();
|
||||||
|
@ -1649,7 +1652,7 @@ public class Util extends weaver.general.Util {
|
||||||
int catchLen = 10 * 1024;
|
int catchLen = 10 * 1024;
|
||||||
for (ListZipEntity listZipEntity : fileList) {
|
for (ListZipEntity listZipEntity : fileList) {
|
||||||
if (listZipEntity.isDirectory()) {
|
if (listZipEntity.isDirectory()) {
|
||||||
// 如果是文件夹
|
// 如果是文件夹
|
||||||
handlerDirectory(listZipEntity.getFileList(), zipOut, base + listZipEntity.getDirectory() + File.separator);
|
handlerDirectory(listZipEntity.getFileList(), zipOut, base + listZipEntity.getDirectory() + File.separator);
|
||||||
} else {
|
} else {
|
||||||
List<AInputStream> aInputStreams = listZipEntity.getaInputStreamList();
|
List<AInputStream> aInputStreams = listZipEntity.getaInputStreamList();
|
||||||
|
@ -1759,8 +1762,8 @@ public class Util extends weaver.general.Util {
|
||||||
@Deprecated
|
@Deprecated
|
||||||
public static String getDocCategorysById(String workflowId, String docFieldId) {
|
public static String getDocCategorysById(String workflowId, String docFieldId) {
|
||||||
RecordSet rs = new RecordSet();
|
RecordSet rs = new RecordSet();
|
||||||
// rs.executeQuery("select formid from workflow_base where id = ?",workflowId);
|
// rs.executeQuery("select formid from workflow_base where id = ?",workflowId);
|
||||||
// String formId = Util.recordeSet2Entity(rs, String.class);
|
// String formId = Util.recordeSet2Entity(rs, String.class);
|
||||||
String query = "select doccategory from workflow_fileupload where workflowid = ? and fieldid = ?";
|
String query = "select doccategory from workflow_fileupload where workflowid = ? and fieldid = ?";
|
||||||
rs.executeQuery(query, workflowId, docFieldId);
|
rs.executeQuery(query, workflowId, docFieldId);
|
||||||
String docCategorys = Util.null2String(Util.recordeSet2Entity(rs, String.class));
|
String docCategorys = Util.null2String(Util.recordeSet2Entity(rs, String.class));
|
||||||
|
@ -1976,6 +1979,55 @@ public class Util extends weaver.general.Util {
|
||||||
return recordsetUtil.getMapper(t);
|
return recordsetUtil.getMapper(t);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* <h2>getTransMapper 获取事务对象mapper</h2>
|
||||||
|
* <i>2022/12/21 22:45</i>
|
||||||
|
* ************************************************************
|
||||||
|
*
|
||||||
|
* @param t 类
|
||||||
|
* @param <T> 代理类
|
||||||
|
* @return T
|
||||||
|
* @author youHong.ai ******************************************
|
||||||
|
*/
|
||||||
|
public static <T> T getTransMapper(Class<T> t) {
|
||||||
|
return recordsetTransUtil.getMapper(t, false);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* <h2>commitTransMapper 提交事务mapper的事务</h2>
|
||||||
|
* <i>2022/12/21 22:46</i>
|
||||||
|
* ************************************************************
|
||||||
|
*
|
||||||
|
* @return boolean 是否提交成功
|
||||||
|
* @author youHong.ai ******************************************
|
||||||
|
*/
|
||||||
|
public static <T> boolean commitTransMapper(Class<T> t) {
|
||||||
|
if (t == null) {
|
||||||
|
throw new NullPointerException("can not commit trans for null mapper proxy!");
|
||||||
|
}
|
||||||
|
if (t.getAnnotation(SqlMapper.class) == null) {
|
||||||
|
throw new BindingException("can not find SqlMapper annotation!");
|
||||||
|
}
|
||||||
|
return recordsetTransUtil.getRsManager().commit(t.getName());
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* <h2>rollbackTransMapper 回滚事务mapper 的事务</h2>
|
||||||
|
* <i>2022/12/21 22:46</i>
|
||||||
|
* ************************************************************
|
||||||
|
*
|
||||||
|
* @return boolean 是否回滚成功
|
||||||
|
* @author youHong.ai ******************************************
|
||||||
|
*/
|
||||||
|
public static <T> boolean rollbackTransMapper(Class<T> t) {
|
||||||
|
if (t == null) {
|
||||||
|
throw new NullPointerException("can not commit trans for null mapper proxy!");
|
||||||
|
}
|
||||||
|
if (t.getAnnotation(SqlMapper.class) == null) {
|
||||||
|
throw new BindingException("can not find SqlMapper annotation!");
|
||||||
|
}
|
||||||
|
return recordsetTransUtil.getRsManager().rollback(t.getName());
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* join方法
|
* join方法
|
||||||
|
@ -2080,6 +2132,7 @@ public class Util extends weaver.general.Util {
|
||||||
appender.setAppend(true);
|
appender.setAppend(true);
|
||||||
appender.activateOptions();
|
appender.activateOptions();
|
||||||
log.addAppender(appender);
|
log.addAppender(appender);
|
||||||
|
log.setAdditivity(false);
|
||||||
log.setLevel(Level.INFO);
|
log.setLevel(Level.INFO);
|
||||||
/*
|
/*
|
||||||
boolean enableDebug = false;
|
boolean enableDebug = false;
|
||||||
|
@ -2127,6 +2180,7 @@ public class Util extends weaver.general.Util {
|
||||||
appender.setAppend(true);
|
appender.setAppend(true);
|
||||||
appender.activateOptions();
|
appender.activateOptions();
|
||||||
cusLog.addAppender(appender);
|
cusLog.addAppender(appender);
|
||||||
|
cusLog.setAdditivity(false);
|
||||||
/*
|
/*
|
||||||
boolean enableDebug = false;
|
boolean enableDebug = false;
|
||||||
try {
|
try {
|
||||||
|
@ -2303,7 +2357,7 @@ public class Util extends weaver.general.Util {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
dataMap.put(id, item);
|
dataMap.put(id, item);
|
||||||
// 判断是否属于根节点,如果是根节点,则将数据添加到树中
|
// 判断是否属于根节点,如果是根节点,则将数据添加到树中
|
||||||
if (predicate.test(parentId)) {
|
if (predicate.test(parentId)) {
|
||||||
if (childMap.containsKey(id)) {
|
if (childMap.containsKey(id)) {
|
||||||
continue;
|
continue;
|
||||||
|
@ -2311,29 +2365,29 @@ public class Util extends weaver.general.Util {
|
||||||
treeList.add(item);
|
treeList.add(item);
|
||||||
childMap.put(id, item);
|
childMap.put(id, item);
|
||||||
} else {
|
} else {
|
||||||
// 如果不是根节点,则通过id查找到父级
|
// 如果不是根节点,则通过id查找到父级
|
||||||
T parent = dataMap.get(parentId);
|
T parent = dataMap.get(parentId);
|
||||||
if (Objects.isNull(parent)) {
|
if (Objects.isNull(parent)) {
|
||||||
// 如果父级为空,则说明他的父级还没有遍历到,需要从之后的数据进行遍历,直到找到父级为止
|
// 如果父级为空,则说明他的父级还没有遍历到,需要从之后的数据进行遍历,直到找到父级为止
|
||||||
List<T> list = buildTree(dataList, dataMap, childMap, index, getIdFn, getParentId, setChildFn, predicate);
|
List<T> list = buildTree(dataList, dataMap, childMap, index, getIdFn, getParentId, setChildFn, predicate);
|
||||||
parent = dataMap.get(parentId);
|
parent = dataMap.get(parentId);
|
||||||
if (Objects.isNull(parent)) {
|
if (Objects.isNull(parent)) {
|
||||||
// 如果还是没有查询到父节点,则表明是顶层节点,将他添加到顶层节点中
|
// 如果还是没有查询到父节点,则表明是顶层节点,将他添加到顶层节点中
|
||||||
treeList.add(item);
|
treeList.add(item);
|
||||||
} else {
|
} else {
|
||||||
// 如果找到了父节点,则将自己挂到父节点上
|
// 如果找到了父节点,则将自己挂到父节点上
|
||||||
if (childMap.containsKey(id)) {
|
if (childMap.containsKey(id)) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
setChildFn.accept(parent, item);
|
setChildFn.accept(parent, item);
|
||||||
childMap.put(id, item);
|
childMap.put(id, item);
|
||||||
}
|
}
|
||||||
// 如果查找的list不为空并且有值,那就说明属于根节点
|
// 如果查找的list不为空并且有值,那就说明属于根节点
|
||||||
if (list != null && list.size() > 0) {
|
if (list != null && list.size() > 0) {
|
||||||
treeList.addAll(list);
|
treeList.addAll(list);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// 如果找到了父节点,则将自己挂到父节点上
|
// 如果找到了父节点,则将自己挂到父节点上
|
||||||
if (childMap.containsKey(id)) {
|
if (childMap.containsKey(id)) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
@ -2375,7 +2429,7 @@ public class Util extends weaver.general.Util {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
dataMap.put(id, item);
|
dataMap.put(id, item);
|
||||||
// 判断是否属于根节点,如果是根节点,则将数据添加到树中
|
// 判断是否属于根节点,如果是根节点,则将数据添加到树中
|
||||||
if (predicate.test(parentId)) {
|
if (predicate.test(parentId)) {
|
||||||
if (childMap.containsKey(id)) {
|
if (childMap.containsKey(id)) {
|
||||||
continue;
|
continue;
|
||||||
|
@ -2383,17 +2437,17 @@ public class Util extends weaver.general.Util {
|
||||||
treeList.add(item);
|
treeList.add(item);
|
||||||
childMap.put(id, item);
|
childMap.put(id, item);
|
||||||
} else {
|
} else {
|
||||||
// 如果不是根节点,则通过id查找到父级
|
// 如果不是根节点,则通过id查找到父级
|
||||||
T parent = dataMap.get(parentId);
|
T parent = dataMap.get(parentId);
|
||||||
if (Objects.isNull(parent)) {
|
if (Objects.isNull(parent)) {
|
||||||
// 如果父级为空,则说明他的父级还没有遍历到,需要从之后的数据进行遍历,直到找到父级为止
|
// 如果父级为空,则说明他的父级还没有遍历到,需要从之后的数据进行遍历,直到找到父级为止
|
||||||
List<T> list = buildTree(dataList, dataMap, childMap, index, getIdFn, getParentId, getChildFn, setChildFn, predicate);
|
List<T> list = buildTree(dataList, dataMap, childMap, index, getIdFn, getParentId, getChildFn, setChildFn, predicate);
|
||||||
parent = dataMap.get(parentId);
|
parent = dataMap.get(parentId);
|
||||||
if (Objects.isNull(parent)) {
|
if (Objects.isNull(parent)) {
|
||||||
// 如果还是没有查询到父节点,则表明是顶层节点,将他添加到顶层节点中
|
// 如果还是没有查询到父节点,则表明是顶层节点,将他添加到顶层节点中
|
||||||
treeList.add(item);
|
treeList.add(item);
|
||||||
} else {
|
} else {
|
||||||
// 如果找到了父节点,则将自己挂到父节点上
|
// 如果找到了父节点,则将自己挂到父节点上
|
||||||
if (childMap.containsKey(id)) {
|
if (childMap.containsKey(id)) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
@ -2402,12 +2456,12 @@ public class Util extends weaver.general.Util {
|
||||||
setChildFn.accept(parent, childList);
|
setChildFn.accept(parent, childList);
|
||||||
childMap.put(id, item);
|
childMap.put(id, item);
|
||||||
}
|
}
|
||||||
// 如果查找的list不为空并且有值,那就说明属于根节点
|
// 如果查找的list不为空并且有值,那就说明属于根节点
|
||||||
if (list != null && list.size() > 0) {
|
if (list != null && list.size() > 0) {
|
||||||
treeList.addAll(list);
|
treeList.addAll(list);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// 如果找到了父节点,则将自己挂到父节点上
|
// 如果找到了父节点,则将自己挂到父节点上
|
||||||
if (childMap.containsKey(id)) {
|
if (childMap.containsKey(id)) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
@ -2468,7 +2522,7 @@ public class Util extends weaver.general.Util {
|
||||||
throw new RuntimeException("invoke method err, cant not invoke method set" + name.substring(0, 1).toUpperCase() + name.substring(1));
|
throw new RuntimeException("invoke method err, cant not invoke method set" + name.substring(0, 1).toUpperCase() + name.substring(1));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// TODO 复制bean
|
// TODO 复制bean
|
||||||
return target;
|
return target;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -3070,20 +3124,25 @@ public class Util extends weaver.general.Util {
|
||||||
Matcher matcher = compile.matcher(logStr);
|
Matcher matcher = compile.matcher(logStr);
|
||||||
int n = 0;
|
int n = 0;
|
||||||
while (matcher.find()) {
|
while (matcher.find()) {
|
||||||
|
if (n + 1 > args.length) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
logStr = logStr.replaceFirst(pattern, "{" + n++ + "}");
|
logStr = logStr.replaceFirst(pattern, "{" + n++ + "}");
|
||||||
}
|
}
|
||||||
Object arg = args[args.length - 1];
|
try {
|
||||||
if (arg instanceof Throwable) {
|
Object arg = args[args.length - 1];
|
||||||
for (int i = 0; i < args.length - 1; i++) {
|
if (arg instanceof Throwable) {
|
||||||
pattern = "\\{" + i + "}";
|
for (int i = 0; i < args.length - 1; i++) {
|
||||||
logStr = logStr.replaceFirst(pattern, String.valueOf(args[i].toString()));
|
pattern = "\\{" + i + "}";
|
||||||
|
logStr = logStr.replaceFirst(pattern, Matcher.quoteReplacement(String.valueOf(args[i])));
|
||||||
|
}
|
||||||
|
return logStr + "\n" + getErrString((Throwable) arg);
|
||||||
}
|
}
|
||||||
return logStr + "\n" + getErrString((Throwable) arg);
|
} catch (Exception ignore) {
|
||||||
}
|
}
|
||||||
int i = 0;
|
for (int i = 0; i < args.length; i++) {
|
||||||
for (Object o : args) {
|
pattern = "\\{" + i + "}";
|
||||||
pattern = "\\{" + i++ + "}";
|
logStr = logStr.replaceFirst(pattern, Matcher.quoteReplacement(String.valueOf(args[i])));
|
||||||
logStr = logStr.replaceFirst(pattern, String.valueOf(o));
|
|
||||||
}
|
}
|
||||||
return logStr;
|
return logStr;
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
|
@ -3229,7 +3288,7 @@ public class Util extends weaver.general.Util {
|
||||||
action = cronJobClass.newInstance();
|
action = cronJobClass.newInstance();
|
||||||
if (declaredFields.length > 0) {
|
if (declaredFields.length > 0) {
|
||||||
for (Field declaredField : declaredFields) {
|
for (Field declaredField : declaredFields) {
|
||||||
// 必填参数验证
|
// 必填参数验证
|
||||||
boolean hasRequiredMark = declaredField.isAnnotationPresent(RequiredMark.class);
|
boolean hasRequiredMark = declaredField.isAnnotationPresent(RequiredMark.class);
|
||||||
String name = declaredField.getName();
|
String name = declaredField.getName();
|
||||||
String setMethodName = getSetMethodName(name);
|
String setMethodName = getSetMethodName(name);
|
||||||
|
@ -3310,7 +3369,7 @@ public class Util extends weaver.general.Util {
|
||||||
action = actionClass.newInstance();
|
action = actionClass.newInstance();
|
||||||
if (declaredFields.length > 0) {
|
if (declaredFields.length > 0) {
|
||||||
for (Field declaredField : declaredFields) {
|
for (Field declaredField : declaredFields) {
|
||||||
// 必填参数验证
|
// 必填参数验证
|
||||||
boolean hasRequiredMark = declaredField.isAnnotationPresent(RequiredMark.class);
|
boolean hasRequiredMark = declaredField.isAnnotationPresent(RequiredMark.class);
|
||||||
String name = declaredField.getName();
|
String name = declaredField.getName();
|
||||||
String setMethodName = getSetMethodName(name);
|
String setMethodName = getSetMethodName(name);
|
||||||
|
@ -3430,7 +3489,7 @@ public class Util extends weaver.general.Util {
|
||||||
String classPath = split[0];
|
String classPath = split[0];
|
||||||
String paramStr = "";
|
String paramStr = "";
|
||||||
if (split.length > 1) {
|
if (split.length > 1) {
|
||||||
paramStr = Arrays.stream(split).skip(1).collect(Collectors.joining(""));
|
paramStr = Arrays.stream(split).skip(1).collect(Collectors.joining("?"));
|
||||||
}
|
}
|
||||||
/* 获取?后的参数:"weaver.aiyh_jitu.pushdata.service.toones.GetRequestValueCusGetValueImpl?" +
|
/* 获取?后的参数:"weaver.aiyh_jitu.pushdata.service.toones.GetRequestValueCusGetValueImpl?" +
|
||||||
"requestType=get&apiOnlyMark=getAssign&valueKey=data&assign=#{main.zd2}&" +
|
"requestType=get&apiOnlyMark=getAssign&valueKey=data&assign=#{main.zd2}&" +
|
||||||
|
@ -3458,11 +3517,13 @@ public class Util extends weaver.general.Util {
|
||||||
value:#sql{select workcode from hrmresource where id = #{main.zd1} and test = #{h-hah} and a in (${hrmids})}
|
value:#sql{select workcode from hrmresource where id = #{main.zd1} and test = #{h-hah} and a in (${hrmids})}
|
||||||
key:hah
|
key:hah
|
||||||
value:haode*/
|
value:haode*/
|
||||||
// 最终通过反射调用weaver.aiyh_jitu.pushdata.service.GetAssignProcessorProcessorImpl类,将参数传递给这个类,
|
// 最终通过反射调用weaver.aiyh_jitu.pushdata.service.GetAssignProcessorProcessorImpl类,将参数传递给这个类,
|
||||||
// String pattern = "&?(?<key>([#.\\w\\u4E00-\\u9FA5]+))=(?<value>((#(\\{|sql\\{))?([()\\-$#={ }.\\w\\u4E00-\\u9FA5?]+)?}?))&?";
|
//String pattern = "&?(?<key>([#.\\w\\u4E00-\\u9FA5]+))=" +
|
||||||
|
// "(?<value>(`([\\s():/\\t\\-&*'?$#={ }.\\w\\u4E00-\\u9FA5]*)`|" +
|
||||||
|
// "((#(\\{|sql\\{))?([():/\\-$#={ }.\\w\\u4E00-\\u9FA5?]+)?}?)))&?";
|
||||||
String pattern = "&?(?<key>([#.\\w\\u4E00-\\u9FA5]+))=" +
|
String pattern = "&?(?<key>([#.\\w\\u4E00-\\u9FA5]+))=" +
|
||||||
"(?<value>((`([():/\\-&?$#={ }.\\w\\u4E00-\\u9FA5?]*)`)|" +
|
"(?<value>(`([^`]*)`|" +
|
||||||
"((#(\\{|sql\\{))?([():/\\-$#={ }.\\w\\u4E00-\\u9FA5?]+)?}?)))&?";
|
"((#(\\{|sql\\{))?([():/\\-$_*#={ }.\\w\\u4E00-\\u9FA5?]+)?}?)))&?";
|
||||||
Pattern compile = Pattern.compile(pattern);
|
Pattern compile = Pattern.compile(pattern);
|
||||||
Matcher matcher = compile.matcher(paramStr);
|
Matcher matcher = compile.matcher(paramStr);
|
||||||
Map<String, String> pathParamMap = new HashMap<>(8);
|
Map<String, String> pathParamMap = new HashMap<>(8);
|
||||||
|
@ -3470,8 +3531,55 @@ public class Util extends weaver.general.Util {
|
||||||
while (matcher.find()) {
|
while (matcher.find()) {
|
||||||
String key = matcher.group("key");
|
String key = matcher.group("key");
|
||||||
String paramValue = matcher.group("value");
|
String paramValue = matcher.group("value");
|
||||||
|
if (paramValue.startsWith("`") && paramValue.endsWith("`")) {
|
||||||
|
paramValue = paramValue.substring(1, paramValue.length() - 1);
|
||||||
|
}
|
||||||
pathParamMap.put(key, paramValue);
|
pathParamMap.put(key, paramValue);
|
||||||
}
|
}
|
||||||
return pathParamMap;
|
return pathParamMap;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static Object executeActionProcess(String process, RequestInfo requestInfo) {
|
||||||
|
if (StringUtils.isNullOrEmpty(process)) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
RequestManager requestManager = requestInfo.getRequestManager();
|
||||||
|
String billTable = requestManager.getBillTableName();
|
||||||
|
String requestId = requestInfo.getRequestid();
|
||||||
|
User user = requestInfo.getRequestManager().getUser();
|
||||||
|
int workflowId = requestManager.getWorkflowid();
|
||||||
|
// 操作类型 submit - 提交 reject - 退回 等
|
||||||
|
String src = requestManager.getSrc();
|
||||||
|
if ("".equals(billTable)) {
|
||||||
|
WorkflowComInfo workflowComInfo = new WorkflowComInfo();
|
||||||
|
String formId = workflowComInfo.getFormId(String.valueOf(workflowId));
|
||||||
|
WorkflowBillComInfo workflowBillComInfo = new WorkflowBillComInfo();
|
||||||
|
billTable = workflowBillComInfo.getTablename(formId);
|
||||||
|
}
|
||||||
|
Class<SafeCusActionProcessInterface> clazz = SafeCusActionProcessInterface.class;
|
||||||
|
Class<?> aClass;
|
||||||
|
try {
|
||||||
|
aClass = Class.forName(process);
|
||||||
|
} catch (ClassNotFoundException e) {
|
||||||
|
throw new IllegalArgumentException("未能找到自定义接口:" + process);
|
||||||
|
}
|
||||||
|
if (!clazz.isAssignableFrom(aClass)) {
|
||||||
|
throw new IllegalArgumentException("自定义接口:" + process + " 不是"
|
||||||
|
+ clazz.getName() + "的子类或实现类!");
|
||||||
|
}
|
||||||
|
Constructor<?> constructor;
|
||||||
|
try {
|
||||||
|
constructor = aClass.getConstructor();
|
||||||
|
} catch (NoSuchMethodException e) {
|
||||||
|
throw new IllegalArgumentException(process + "没有空参构造方法,无法获取构造方法对象!");
|
||||||
|
}
|
||||||
|
SafeCusActionProcessInterface o;
|
||||||
|
try {
|
||||||
|
o = (SafeCusActionProcessInterface) constructor.newInstance();
|
||||||
|
} catch (InstantiationException | IllegalAccessException | InvocationTargetException e) {
|
||||||
|
throw new IllegalArgumentException("无法构造" + process + "对象!");
|
||||||
|
}
|
||||||
|
Map<String, String> pathParam = Util.parseCusInterfacePathParam(process);
|
||||||
|
return o.execute(pathParam, requestId, billTable, workflowId, user, requestInfo);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -19,9 +19,9 @@ import java.util.*;
|
||||||
*
|
*
|
||||||
* @author EBU7-dev-1 aiyh
|
* @author EBU7-dev-1 aiyh
|
||||||
*/
|
*/
|
||||||
|
@Deprecated
|
||||||
public abstract class CusBaseAction implements Action {
|
public abstract class CusBaseAction implements Action {
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 全局日志对象
|
* 全局日志对象
|
||||||
*/
|
*/
|
||||||
|
@ -31,31 +31,36 @@ public abstract class CusBaseAction implements Action {
|
||||||
* 全局requestInfo对象
|
* 全局requestInfo对象
|
||||||
*/
|
*/
|
||||||
protected RequestInfo globalRequestInfo;
|
protected RequestInfo globalRequestInfo;
|
||||||
|
/**
|
||||||
|
* <h2>线程局部变量</h2>
|
||||||
|
**/
|
||||||
|
protected static ThreadLocal<RequestInfo> requestInfoThreadLocal = new ThreadLocal<>();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* <h2>初始化流程默认的处理方法</h2>
|
* <h2>初始化流程默认的处理方法</h2>
|
||||||
*/
|
*/
|
||||||
private void initHandleMethod() {
|
private void initHandleMethod() {
|
||||||
// 提交
|
// 提交
|
||||||
actionHandleMethod.put(ActionRunType.SUBMIT, this::doSubmit);
|
actionHandleMethod.put(ActionRunType.SUBMIT, this::doSubmit);
|
||||||
// 退回
|
// 退回
|
||||||
actionHandleMethod.put(ActionRunType.REJECT, this::doReject);
|
actionHandleMethod.put(ActionRunType.REJECT, this::doReject);
|
||||||
// 撤回
|
// 撤回
|
||||||
actionHandleMethod.put(ActionRunType.WITHDRAW, this::doWithdraw);
|
actionHandleMethod.put(ActionRunType.WITHDRAW, this::doWithdraw);
|
||||||
// 强制收回
|
// 强制收回
|
||||||
actionHandleMethod.put(ActionRunType.DRAW_BACK, this::doDrawBack);
|
actionHandleMethod.put(ActionRunType.DRAW_BACK, this::doDrawBack);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public final String execute(RequestInfo requestInfo) {
|
public final String execute(RequestInfo requestInfo) {
|
||||||
|
requestInfoThreadLocal.set(requestInfo);
|
||||||
this.globalRequestInfo = requestInfo;
|
this.globalRequestInfo = requestInfo;
|
||||||
RequestManager requestManager = requestInfo.getRequestManager();
|
RequestManager requestManager = requestInfo.getRequestManager();
|
||||||
String billTable = requestManager.getBillTableName();
|
String billTable = requestManager.getBillTableName();
|
||||||
String requestId = requestInfo.getRequestid();
|
String requestId = requestInfo.getRequestid();
|
||||||
User user = requestInfo.getRequestManager().getUser();
|
User user = requestInfo.getRequestManager().getUser();
|
||||||
int workflowId = requestManager.getWorkflowid();
|
int workflowId = requestManager.getWorkflowid();
|
||||||
// 操作类型 submit - 提交 reject - 退回 等
|
// 操作类型 submit - 提交 reject - 退回 等
|
||||||
String src = requestManager.getSrc();
|
String src = requestManager.getSrc();
|
||||||
if ("".equals(billTable)) {
|
if ("".equals(billTable)) {
|
||||||
WorkflowComInfo workflowComInfo = new WorkflowComInfo();
|
WorkflowComInfo workflowComInfo = new WorkflowComInfo();
|
||||||
|
@ -68,13 +73,13 @@ public abstract class CusBaseAction implements Action {
|
||||||
if (StringUtils.isEmpty(src)) {
|
if (StringUtils.isEmpty(src)) {
|
||||||
src = "submit";
|
src = "submit";
|
||||||
}
|
}
|
||||||
// 初始化默认的流程处理方法
|
// 初始化默认的流程处理方法
|
||||||
initHandleMethod();
|
initHandleMethod();
|
||||||
// 提供自定义注册处理方法
|
// 提供自定义注册处理方法
|
||||||
registerHandler(actionHandleMethod);
|
registerHandler(actionHandleMethod);
|
||||||
// 获取流程对应的处理方法
|
// 获取流程对应的处理方法
|
||||||
CusBaseActionHandleFunction cusBaseActionHandleFunction = actionHandleMethod.get(src);
|
CusBaseActionHandleFunction cusBaseActionHandleFunction = actionHandleMethod.get(src);
|
||||||
// 默认没有直接成功不做拦截
|
// 默认没有直接成功不做拦截
|
||||||
if (null == cusBaseActionHandleFunction) {
|
if (null == cusBaseActionHandleFunction) {
|
||||||
return Action.SUCCESS;
|
return Action.SUCCESS;
|
||||||
}
|
}
|
||||||
|
@ -91,6 +96,9 @@ public abstract class CusBaseAction implements Action {
|
||||||
if (this.exceptionCallback(e, requestManager)) {
|
if (this.exceptionCallback(e, requestManager)) {
|
||||||
return Action.FAILURE_AND_CONTINUE;
|
return Action.FAILURE_AND_CONTINUE;
|
||||||
}
|
}
|
||||||
|
}finally {
|
||||||
|
// 无论成功还是失败 都将该线程的requestInfo进行移除
|
||||||
|
requestInfoThreadLocal.remove();
|
||||||
}
|
}
|
||||||
return Action.SUCCESS;
|
return Action.SUCCESS;
|
||||||
}
|
}
|
||||||
|
@ -124,8 +132,7 @@ public abstract class CusBaseAction implements Action {
|
||||||
/**
|
/**
|
||||||
* <h2>action 提交流程业务处理方法</h2>
|
* <h2>action 提交流程业务处理方法</h2>
|
||||||
* <p>具体业务逻辑实现
|
* <p>具体业务逻辑实现
|
||||||
* 全局存在log成员变量,用于日志的输出
|
* 全局存在log成员变量,用于日志的输出 Util.actionFailException(requestManager,"error msg"); 用于提示action执行失败
|
||||||
* Util.actionFailException(requestManager,"error msg"); 用于提示action执行失败
|
|
||||||
* </p>
|
* </p>
|
||||||
*
|
*
|
||||||
* @param requestId 流程请求ID
|
* @param requestId 流程请求ID
|
||||||
|
@ -142,8 +149,7 @@ public abstract class CusBaseAction implements Action {
|
||||||
/**
|
/**
|
||||||
* <h2>action 退回流程业务处理方法</h2>
|
* <h2>action 退回流程业务处理方法</h2>
|
||||||
* <p>具体业务逻辑实现
|
* <p>具体业务逻辑实现
|
||||||
* 全局存在log成员变量,用于日志的输出
|
* 全局存在log成员变量,用于日志的输出 Util.actionFailException(requestManager,"error msg"); 用于提示action执行失败
|
||||||
* Util.actionFailException(requestManager,"error msg"); 用于提示action执行失败
|
|
||||||
* </p>
|
* </p>
|
||||||
*
|
*
|
||||||
* @param requestId 流程请求ID
|
* @param requestId 流程请求ID
|
||||||
|
@ -159,8 +165,7 @@ public abstract class CusBaseAction implements Action {
|
||||||
/**
|
/**
|
||||||
* <h2>action 撤回、撤回流程流程业务处理方法</h2>
|
* <h2>action 撤回、撤回流程流程业务处理方法</h2>
|
||||||
* <p>具体业务逻辑实现
|
* <p>具体业务逻辑实现
|
||||||
* 全局存在log成员变量,用于日志的输出
|
* 全局存在log成员变量,用于日志的输出 Util.actionFailException(requestManager,"error msg"); 用于提示action执行失败
|
||||||
* Util.actionFailException(requestManager,"error msg"); 用于提示action执行失败
|
|
||||||
* </p>
|
* </p>
|
||||||
*
|
*
|
||||||
* @param requestId 流程请求ID
|
* @param requestId 流程请求ID
|
||||||
|
@ -177,8 +182,7 @@ public abstract class CusBaseAction implements Action {
|
||||||
/**
|
/**
|
||||||
* <h2>action 强制收回流程业务处理方法</h2>
|
* <h2>action 强制收回流程业务处理方法</h2>
|
||||||
* <p>具体业务逻辑实现
|
* <p>具体业务逻辑实现
|
||||||
* 全局存在log成员变量,用于日志的输出
|
* 全局存在log成员变量,用于日志的输出 Util.actionFailException(requestManager,"error msg"); 用于提示action执行失败
|
||||||
* Util.actionFailException(requestManager,"error msg"); 用于提示action执行失败
|
|
||||||
* </p>
|
* </p>
|
||||||
*
|
*
|
||||||
* @param requestId 流程请求ID
|
* @param requestId 流程请求ID
|
||||||
|
@ -199,7 +203,7 @@ public abstract class CusBaseAction implements Action {
|
||||||
*/
|
*/
|
||||||
@Deprecated
|
@Deprecated
|
||||||
protected Map<String, String> getMainTableValue() {
|
protected Map<String, String> getMainTableValue() {
|
||||||
// 获取主表数据
|
// 获取主表数据
|
||||||
Property[] propertyArr = globalRequestInfo.getMainTableInfo().getProperty();
|
Property[] propertyArr = globalRequestInfo.getMainTableInfo().getProperty();
|
||||||
return getStringMap(propertyArr);
|
return getStringMap(propertyArr);
|
||||||
}
|
}
|
||||||
|
@ -210,7 +214,7 @@ public abstract class CusBaseAction implements Action {
|
||||||
* @return 流程主表数据
|
* @return 流程主表数据
|
||||||
*/
|
*/
|
||||||
protected Map<String, String> getMainTableValue(RequestInfo requestInfo) {
|
protected Map<String, String> getMainTableValue(RequestInfo requestInfo) {
|
||||||
// 获取主表数据
|
// 获取主表数据
|
||||||
Property[] propertyArr = requestInfo.getMainTableInfo().getProperty();
|
Property[] propertyArr = requestInfo.getMainTableInfo().getProperty();
|
||||||
return getStringMap(propertyArr);
|
return getStringMap(propertyArr);
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,6 +10,7 @@ import weaver.workflow.request.RequestManager;
|
||||||
* <p>create: 2022-07-23 18:05</p>
|
* <p>create: 2022-07-23 18:05</p>
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
@Deprecated
|
||||||
@FunctionalInterface
|
@FunctionalInterface
|
||||||
public interface CusBaseActionHandleFunction {
|
public interface CusBaseActionHandleFunction {
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -16,7 +16,7 @@ import weaver.interfaces.schedule.BaseCronJob;
|
||||||
public abstract class CusBaseCronJob extends BaseCronJob {
|
public abstract class CusBaseCronJob extends BaseCronJob {
|
||||||
|
|
||||||
|
|
||||||
Logger log = Util.getLogger();
|
protected Logger log = Util.getLogger();
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -39,8 +39,7 @@ public abstract class CusBaseCronJob extends BaseCronJob {
|
||||||
* <i>2022/12/4 13:59</i>
|
* <i>2022/12/4 13:59</i>
|
||||||
* ******************************************
|
* ******************************************
|
||||||
*
|
*
|
||||||
* @author youHong.ai
|
* @author youHong.ai ******************************************
|
||||||
* ******************************************
|
|
||||||
*/
|
*/
|
||||||
public abstract void runCode();
|
public abstract void runCode();
|
||||||
|
|
||||||
|
@ -51,8 +50,7 @@ public abstract class CusBaseCronJob extends BaseCronJob {
|
||||||
* ******************************************
|
* ******************************************
|
||||||
*
|
*
|
||||||
* @param e 异常类
|
* @param e 异常类
|
||||||
* @author youHong.ai
|
* @author youHong.ai ******************************************
|
||||||
* ******************************************
|
|
||||||
*/
|
*/
|
||||||
public void exceptionCallback(Throwable e) {
|
public void exceptionCallback(Throwable e) {
|
||||||
log.error("execute cronJon failure! error detail msg \n" + Util.getErrString(e));
|
log.error("execute cronJon failure! error detail msg \n" + Util.getErrString(e));
|
||||||
|
|
|
@ -0,0 +1,37 @@
|
||||||
|
package aiyh.utils.action;
|
||||||
|
|
||||||
|
import weaver.hrm.User;
|
||||||
|
import weaver.soa.workflow.request.RequestInfo;
|
||||||
|
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* <h1>流程自定义前置后置处理方法</h1>
|
||||||
|
*
|
||||||
|
* <p>create: 2023-01-10 13:19</p>
|
||||||
|
*
|
||||||
|
* @author youHong.ai
|
||||||
|
*/
|
||||||
|
|
||||||
|
@FunctionalInterface
|
||||||
|
|
||||||
|
public interface SafeCusActionProcessInterface {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* <h2>execute 流程action处理方法</h2>
|
||||||
|
* <i>2023/1/10 13:21</i>
|
||||||
|
* ************************************************************
|
||||||
|
*
|
||||||
|
* @param pathParams 路径参数
|
||||||
|
* @param requestId 流程请求id
|
||||||
|
* @param billTable 流程主表表名
|
||||||
|
* @param workflowId 流程workflowId
|
||||||
|
* @param user 流程当前操作人
|
||||||
|
* @param requestInfo action参数
|
||||||
|
* @return Object 返回值
|
||||||
|
* @author youHong.ai ******************************************
|
||||||
|
*/
|
||||||
|
|
||||||
|
Object execute(Map<String, String> pathParams, String requestId, String billTable, int workflowId,
|
||||||
|
User user, RequestInfo requestInfo);
|
||||||
|
}
|
|
@ -0,0 +1,288 @@
|
||||||
|
package aiyh.utils.action;
|
||||||
|
|
||||||
|
import aiyh.utils.Util;
|
||||||
|
import aiyh.utils.excention.CustomerException;
|
||||||
|
import org.apache.commons.lang3.StringUtils;
|
||||||
|
import org.apache.log4j.Logger;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
import weaver.hrm.User;
|
||||||
|
import weaver.interfaces.workflow.action.Action;
|
||||||
|
import weaver.soa.workflow.request.*;
|
||||||
|
import weaver.workflow.request.RequestManager;
|
||||||
|
import weaver.workflow.workflow.WorkflowBillComInfo;
|
||||||
|
import weaver.workflow.workflow.WorkflowComInfo;
|
||||||
|
|
||||||
|
import java.util.*;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* <h1>基础的action,实现一些基础的参数</h1>
|
||||||
|
*
|
||||||
|
* @author EBU7-dev-1 aiyh
|
||||||
|
*/
|
||||||
|
public abstract class SafeCusBaseAction implements Action {
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 全局日志对象
|
||||||
|
*/
|
||||||
|
protected final Logger log = Util.getLogger();
|
||||||
|
private final Map<String, SafeCusBaseActionHandleFunction> actionHandleMethod = new HashMap<>();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* <h2>初始化流程默认的处理方法</h2>
|
||||||
|
*/
|
||||||
|
private void initHandleMethod() {
|
||||||
|
// 提交
|
||||||
|
actionHandleMethod.put(ActionRunType.SUBMIT, this::doSubmit);
|
||||||
|
// 退回
|
||||||
|
actionHandleMethod.put(ActionRunType.REJECT, this::doReject);
|
||||||
|
// 撤回
|
||||||
|
actionHandleMethod.put(ActionRunType.WITHDRAW, this::doWithdraw);
|
||||||
|
// 强制收回
|
||||||
|
actionHandleMethod.put(ActionRunType.DRAW_BACK, this::doDrawBack);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public final String execute(RequestInfo requestInfo) {
|
||||||
|
RequestManager requestManager = requestInfo.getRequestManager();
|
||||||
|
String billTable = requestManager.getBillTableName();
|
||||||
|
String requestId = requestInfo.getRequestid();
|
||||||
|
User user = requestInfo.getRequestManager().getUser();
|
||||||
|
int workflowId = requestManager.getWorkflowid();
|
||||||
|
// 操作类型 submit - 提交 reject - 退回 等
|
||||||
|
String src = requestManager.getSrc();
|
||||||
|
if ("".equals(billTable)) {
|
||||||
|
WorkflowComInfo workflowComInfo = new WorkflowComInfo();
|
||||||
|
String formId = workflowComInfo.getFormId(String.valueOf(workflowId));
|
||||||
|
WorkflowBillComInfo workflowBillComInfo = new WorkflowBillComInfo();
|
||||||
|
billTable = workflowBillComInfo.getTablename(formId);
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
Util.verifyRequiredField(this);
|
||||||
|
if (StringUtils.isEmpty(src)) {
|
||||||
|
src = "submit";
|
||||||
|
}
|
||||||
|
// 初始化默认的流程处理方法
|
||||||
|
initHandleMethod();
|
||||||
|
// 提供自定义注册处理方法
|
||||||
|
registerHandler(actionHandleMethod);
|
||||||
|
// 获取流程对应的处理方法
|
||||||
|
SafeCusBaseActionHandleFunction cusBaseActionHandleFunction = actionHandleMethod.get(src);
|
||||||
|
// 默认没有直接成功不做拦截
|
||||||
|
if (null == cusBaseActionHandleFunction) {
|
||||||
|
return Action.SUCCESS;
|
||||||
|
}
|
||||||
|
cusBaseActionHandleFunction.handle(requestId, billTable, workflowId, user, requestInfo);
|
||||||
|
} catch (CustomerException e) {
|
||||||
|
if (e.getCode() != null && e.getCode() == 500) {
|
||||||
|
Util.actionFail(requestManager, e.getMessage());
|
||||||
|
return Action.FAILURE_AND_CONTINUE;
|
||||||
|
}
|
||||||
|
if (this.exceptionCallback(e, requestManager)) {
|
||||||
|
return Action.FAILURE_AND_CONTINUE;
|
||||||
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
if (this.exceptionCallback(e, requestManager)) {
|
||||||
|
return Action.FAILURE_AND_CONTINUE;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return Action.SUCCESS;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* <h2>程序执行异常回调</h2>
|
||||||
|
*
|
||||||
|
* @param e 异常信息
|
||||||
|
* @param requestManager requestManager对象
|
||||||
|
* @return 是否阻止action往下提交,true- 阻止, false-放行
|
||||||
|
*/
|
||||||
|
public boolean exceptionCallback(Exception e, RequestManager requestManager) {
|
||||||
|
e.printStackTrace();
|
||||||
|
log.error(Util.logStr("getDataId action fail, exception message is [{}], error stack trace msg is: \n{}",
|
||||||
|
e.getMessage(), Util.getErrString(e)));
|
||||||
|
Util.actionFail(requestManager, e.getMessage());
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* <h2>流程其他流转类型处理方法注册</h2>
|
||||||
|
*
|
||||||
|
* @param actionHandleMethod 处理方法对应map
|
||||||
|
*/
|
||||||
|
public void registerHandler(Map<String, SafeCusBaseActionHandleFunction> actionHandleMethod) {
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* <h2>action 提交流程业务处理方法</h2>
|
||||||
|
* <p>具体业务逻辑实现
|
||||||
|
* 全局存在log成员变量,用于日志的输出 Util.actionFailException(requestManager,"error msg"); 用于提示action执行失败
|
||||||
|
* </p>
|
||||||
|
*
|
||||||
|
* @param requestId 流程请求ID
|
||||||
|
* @param billTable 流程对应主表名称
|
||||||
|
* @param workflowId 流程对应流程ID
|
||||||
|
* @param user 当前节点操作者用户
|
||||||
|
* @param requestInfo 请求管理对象
|
||||||
|
*/
|
||||||
|
|
||||||
|
public abstract void doSubmit(String requestId, String billTable, int workflowId,
|
||||||
|
User user, RequestInfo requestInfo);
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* <h2>action 退回流程业务处理方法</h2>
|
||||||
|
* <p>具体业务逻辑实现
|
||||||
|
* 全局存在log成员变量,用于日志的输出 Util.actionFailException(requestManager,"error msg"); 用于提示action执行失败
|
||||||
|
* </p>
|
||||||
|
*
|
||||||
|
* @param requestId 流程请求ID
|
||||||
|
* @param billTable 流程对应主表名称
|
||||||
|
* @param workflowId 流程对应流程ID
|
||||||
|
* @param user 当前节点操作者用户
|
||||||
|
* @param requestInfo 请求管理对象
|
||||||
|
*/
|
||||||
|
public void doReject(String requestId, String billTable, int workflowId,
|
||||||
|
User user, RequestInfo requestInfo) {
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* <h2>action 撤回、撤回流程流程业务处理方法</h2>
|
||||||
|
* <p>具体业务逻辑实现
|
||||||
|
* 全局存在log成员变量,用于日志的输出 Util.actionFailException(requestManager,"error msg"); 用于提示action执行失败
|
||||||
|
* </p>
|
||||||
|
*
|
||||||
|
* @param requestId 流程请求ID
|
||||||
|
* @param billTable 流程对应主表名称
|
||||||
|
* @param workflowId 流程对应流程ID
|
||||||
|
* @param user 当前节点操作者用户
|
||||||
|
* @param requestInfo 请求管理对象
|
||||||
|
*/
|
||||||
|
public void doWithdraw(String requestId, String billTable, int workflowId,
|
||||||
|
User user, RequestInfo requestInfo) {
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* <h2>action 强制收回流程业务处理方法</h2>
|
||||||
|
* <p>具体业务逻辑实现
|
||||||
|
* 全局存在log成员变量,用于日志的输出 Util.actionFailException(requestManager,"error msg"); 用于提示action执行失败
|
||||||
|
* </p>
|
||||||
|
*
|
||||||
|
* @param requestId 流程请求ID
|
||||||
|
* @param billTable 流程对应主表名称
|
||||||
|
* @param workflowId 流程对应流程ID
|
||||||
|
* @param user 当前节点操作者用户
|
||||||
|
* @param requestInfo 请求管理对象
|
||||||
|
*/
|
||||||
|
public void doDrawBack(String requestId, String billTable, int workflowId,
|
||||||
|
User user, RequestInfo requestInfo) {
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* <h2>获取流程主表数据</h2>
|
||||||
|
*
|
||||||
|
* @return 流程主表数据
|
||||||
|
*/
|
||||||
|
protected Map<String, String> getMainTableValue(RequestInfo requestInfo) {
|
||||||
|
// 获取主表数据
|
||||||
|
Property[] propertyArr = requestInfo.getMainTableInfo().getProperty();
|
||||||
|
return getStringMap(propertyArr);
|
||||||
|
}
|
||||||
|
|
||||||
|
@NotNull
|
||||||
|
private Map<String, String> getStringMap(Property[] propertyArr) {
|
||||||
|
if (null == propertyArr) {
|
||||||
|
return Collections.emptyMap();
|
||||||
|
}
|
||||||
|
Map<String, String> mainTable = new HashMap<>((int) Math.ceil(propertyArr.length * 1.4));
|
||||||
|
for (Property property : propertyArr) {
|
||||||
|
String fieldName = property.getName();
|
||||||
|
String value = property.getValue();
|
||||||
|
mainTable.put(fieldName, value);
|
||||||
|
}
|
||||||
|
return mainTable;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* <h2>获取所有明细数据</h2>
|
||||||
|
*
|
||||||
|
* @return 以明细表需要为键,以明细表数据为值的键值对明细数据信息
|
||||||
|
*/
|
||||||
|
protected Map<String, List<Map<String, String>>> getDetailTableValue(RequestInfo requestInfo) {
|
||||||
|
DetailTable[] detailTableArr = requestInfo.getDetailTableInfo().getDetailTable();
|
||||||
|
return getListMap(detailTableArr);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@NotNull
|
||||||
|
private Map<String, List<Map<String, String>>> getListMap(DetailTable[] detailTableArr) {
|
||||||
|
Map<String, List<Map<String, String>>> detailDataList = new HashMap<>((int) Math.ceil(detailTableArr.length * 1.4));
|
||||||
|
for (DetailTable detailTable : detailTableArr) {
|
||||||
|
List<Map<String, String>> detailData = getDetailValue(detailTable);
|
||||||
|
detailDataList.put(detailTable.getId(), detailData);
|
||||||
|
}
|
||||||
|
return detailDataList;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* <h2>获取指定明细表的表数据</h2>
|
||||||
|
*
|
||||||
|
* @param detailNo 明细表编号
|
||||||
|
* @return 明细数据
|
||||||
|
*/
|
||||||
|
protected List<Map<String, String>> getDetailTableValueByDetailNo(int detailNo, RequestInfo requestInfo) {
|
||||||
|
DetailTable detailTable = requestInfo.getDetailTableInfo().getDetailTable(detailNo);
|
||||||
|
return getDetailValue(detailTable);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* <h2>根据明细表信息获取明细表数据</h2>
|
||||||
|
*
|
||||||
|
* @param detailTable 明细表对象
|
||||||
|
* @return 明细表数据
|
||||||
|
*/
|
||||||
|
@NotNull
|
||||||
|
private List<Map<String, String>> getDetailValue(DetailTable detailTable) {
|
||||||
|
Row[] rowArr = detailTable.getRow();
|
||||||
|
List<Map<String, String>> detailData = new ArrayList<>(rowArr.length);
|
||||||
|
for (Row row : rowArr) {
|
||||||
|
Cell[] cellArr = row.getCell();
|
||||||
|
Map<String, String> rowData = new HashMap<>((int) Math.ceil(cellArr.length * (1 + 0.4)));
|
||||||
|
rowData.put("id", row.getId());
|
||||||
|
for (Cell cell : cellArr) {
|
||||||
|
String fieldName = cell.getName();
|
||||||
|
String value = cell.getValue();
|
||||||
|
rowData.put(fieldName, value);
|
||||||
|
}
|
||||||
|
detailData.add(rowData);
|
||||||
|
}
|
||||||
|
return detailData;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public static final class ActionRunType {
|
||||||
|
/**
|
||||||
|
* 退回
|
||||||
|
*/
|
||||||
|
public static final String REJECT = "reject";
|
||||||
|
/**
|
||||||
|
* 撤回
|
||||||
|
*/
|
||||||
|
public static final String WITHDRAW = "withdraw";
|
||||||
|
/**
|
||||||
|
* 强制收回
|
||||||
|
*/
|
||||||
|
public static final String DRAW_BACK = "drawBack";
|
||||||
|
/**
|
||||||
|
* 提交
|
||||||
|
*/
|
||||||
|
public static final String SUBMIT = "submit";
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,26 @@
|
||||||
|
package aiyh.utils.action;
|
||||||
|
|
||||||
|
import weaver.hrm.User;
|
||||||
|
import weaver.soa.workflow.request.RequestInfo;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* <h1>流程类型处理方法</h1>
|
||||||
|
*
|
||||||
|
* @author EBU7-dev-1 aiyh
|
||||||
|
* <p>create: 2022-07-23 18:05</p>
|
||||||
|
*/
|
||||||
|
|
||||||
|
@FunctionalInterface
|
||||||
|
public interface SafeCusBaseActionHandleFunction {
|
||||||
|
/**
|
||||||
|
* <h2>流程处理方法action</h2>
|
||||||
|
*
|
||||||
|
* @param requestId 流程请求ID
|
||||||
|
* @param billTable 流程对应主表名称
|
||||||
|
* @param workflowId 流程对应流程ID
|
||||||
|
* @param user 当前节点操作者用户
|
||||||
|
* @param requestInfo 请求管理对象
|
||||||
|
*/
|
||||||
|
void handle(String requestId, String billTable, int workflowId,
|
||||||
|
User user, RequestInfo requestInfo);
|
||||||
|
}
|
|
@ -27,6 +27,8 @@ public class ResponeVo implements HttpResponse {
|
||||||
* 相应内容
|
* 相应内容
|
||||||
*/
|
*/
|
||||||
private String entityString;
|
private String entityString;
|
||||||
|
|
||||||
|
private Map<String, Object> entityMap;
|
||||||
/**
|
/**
|
||||||
* 相应头信息
|
* 相应头信息
|
||||||
*/
|
*/
|
||||||
|
@ -39,7 +41,6 @@ public class ResponeVo implements HttpResponse {
|
||||||
|
|
||||||
private Map<String, Object> requestData;
|
private Map<String, Object> requestData;
|
||||||
|
|
||||||
|
|
||||||
private HttpResponse response;
|
private HttpResponse response;
|
||||||
|
|
||||||
public int getCode() {
|
public int getCode() {
|
||||||
|
@ -68,11 +69,15 @@ public class ResponeVo implements HttpResponse {
|
||||||
* @return 资源皇后的map集合
|
* @return 资源皇后的map集合
|
||||||
* @throws JsonProcessingException JSON转换异常
|
* @throws JsonProcessingException JSON转换异常
|
||||||
*/
|
*/
|
||||||
|
@Deprecated
|
||||||
public Map<String, Object> getEntityMap() throws JsonProcessingException {
|
public Map<String, Object> getEntityMap() throws JsonProcessingException {
|
||||||
ObjectMapper mapper = new ObjectMapper();
|
ObjectMapper mapper = new ObjectMapper();
|
||||||
return mapper.readValue(this.getEntityString(), Map.class);
|
return mapper.readValue(this.getEntityString(), Map.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Map<String, Object> getResponseMap(){
|
||||||
|
return this.entityMap;
|
||||||
|
}
|
||||||
/**
|
/**
|
||||||
* 根据相应结果,转化为实体类
|
* 根据相应结果,转化为实体类
|
||||||
*
|
*
|
||||||
|
@ -81,11 +86,21 @@ public class ResponeVo implements HttpResponse {
|
||||||
* @return 转换后的实体类
|
* @return 转换后的实体类
|
||||||
* @throws JsonProcessingException JSON转换异常
|
* @throws JsonProcessingException JSON转换异常
|
||||||
*/
|
*/
|
||||||
|
@Deprecated
|
||||||
public <T> T getEntity(Class<T> clazz) throws JsonProcessingException {
|
public <T> T getEntity(Class<T> clazz) throws JsonProcessingException {
|
||||||
ObjectMapper mapper = new ObjectMapper();
|
ObjectMapper mapper = new ObjectMapper();
|
||||||
return mapper.readValue(this.getEntityString(), clazz);
|
return mapper.readValue(this.getEntityString(), clazz);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public <T> T getResponseEntity(Class<T> clazz) {
|
||||||
|
ObjectMapper mapper = new ObjectMapper();
|
||||||
|
try {
|
||||||
|
return mapper.readValue(this.getEntityString(), clazz);
|
||||||
|
} catch (JsonProcessingException e) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 根据相应结果,转化为实体类
|
* 根据相应结果,转化为实体类
|
||||||
*
|
*
|
||||||
|
@ -98,6 +113,45 @@ public class ResponeVo implements HttpResponse {
|
||||||
return mapper.readValue(this.getEntityString(), typeReference);
|
return mapper.readValue(this.getEntityString(), typeReference);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public String getEntityString() {
|
||||||
|
return entityString;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setEntityString(String entityString) {
|
||||||
|
this.entityString = entityString;
|
||||||
|
try{
|
||||||
|
ObjectMapper mapper = new ObjectMapper();
|
||||||
|
this.entityMap = mapper.readValue(this.getEntityString(), Map.class);
|
||||||
|
}catch (Exception ignore){
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public InputStream getContent() {
|
||||||
|
return content;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setContent(InputStream content) {
|
||||||
|
this.content = content;
|
||||||
|
}
|
||||||
|
|
||||||
|
public byte[] getContentByteArr() {
|
||||||
|
return contentByteArr;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setContentByteArr(byte[] contentByteArr) {
|
||||||
|
this.contentByteArr = contentByteArr;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return "ResponeVo{" +
|
||||||
|
"code=" + code +
|
||||||
|
", entityString='" + entityString + '\'' +
|
||||||
|
", otherParam=" + requestData +
|
||||||
|
'}';
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 根据相应结果转化为实体集合
|
* 根据相应结果转化为实体集合
|
||||||
*
|
*
|
||||||
|
@ -243,37 +297,6 @@ public class ResponeVo implements HttpResponse {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public String getEntityString() {
|
|
||||||
return entityString;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setEntityString(String entityString) {
|
|
||||||
this.entityString = entityString;
|
|
||||||
}
|
|
||||||
|
|
||||||
public InputStream getContent() {
|
|
||||||
return content;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setContent(InputStream content) {
|
|
||||||
this.content = content;
|
|
||||||
}
|
|
||||||
|
|
||||||
public byte[] getContentByteArr() {
|
|
||||||
return contentByteArr;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setContentByteArr(byte[] contentByteArr) {
|
|
||||||
this.contentByteArr = contentByteArr;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String toString() {
|
|
||||||
return "ResponeVo{" +
|
|
||||||
"code=" + code +
|
|
||||||
", entityString='" + entityString + '\'' +
|
|
||||||
", otherParam=" + requestData +
|
|
||||||
'}';
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -5,6 +5,7 @@ import com.alibaba.fastjson.annotation.JSONField;
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
|
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* <h1>http请求信息</h1>
|
* <h1>http请求信息</h1>
|
||||||
|
@ -27,5 +28,7 @@ public class HttpUtilParamInfo {
|
||||||
@JSONField(format = "yyyy-MM-dd HH:mm:ss")
|
@JSONField(format = "yyyy-MM-dd HH:mm:ss")
|
||||||
private Date responseDate;
|
private Date responseDate;
|
||||||
|
|
||||||
|
private Map<String,Object> responseMap;
|
||||||
|
private String responseString;
|
||||||
private ResponeVo response;
|
private ResponeVo response;
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,9 +8,9 @@ import aiyh.utils.zwl.common.ToolUtil;
|
||||||
import com.alibaba.fastjson.JSON;
|
import com.alibaba.fastjson.JSON;
|
||||||
import com.alibaba.fastjson.JSONObject;
|
import com.alibaba.fastjson.JSONObject;
|
||||||
import com.alibaba.fastjson.serializer.SerializerFeature;
|
import com.alibaba.fastjson.serializer.SerializerFeature;
|
||||||
|
import com.alibaba.fastjson.support.spring.PropertyPreFilters;
|
||||||
import com.google.common.base.Strings;
|
import com.google.common.base.Strings;
|
||||||
import com.google.common.util.concurrent.ThreadFactoryBuilder;
|
import com.google.common.util.concurrent.ThreadFactoryBuilder;
|
||||||
import org.apache.http.Header;
|
|
||||||
import org.apache.http.HttpEntity;
|
import org.apache.http.HttpEntity;
|
||||||
import org.apache.http.NameValuePair;
|
import org.apache.http.NameValuePair;
|
||||||
import org.apache.http.client.CredentialsProvider;
|
import org.apache.http.client.CredentialsProvider;
|
||||||
|
@ -51,6 +51,8 @@ public class HttpUtils {
|
||||||
private final GlobalCache globalCache = new GlobalCache();
|
private final GlobalCache globalCache = new GlobalCache();
|
||||||
// 线程池
|
// 线程池
|
||||||
private final ThreadPoolExecutor executorService;
|
private final ThreadPoolExecutor executorService;
|
||||||
|
private final PropertyPreFilters filters = new PropertyPreFilters();
|
||||||
|
private final PropertyPreFilters.MySimplePropertyPreFilter excludefilter = filters.addFilter();
|
||||||
// 默认编码
|
// 默认编码
|
||||||
private String DEFAULT_ENCODING = "UTF-8";
|
private String DEFAULT_ENCODING = "UTF-8";
|
||||||
/**
|
/**
|
||||||
|
@ -67,6 +69,8 @@ public class HttpUtils {
|
||||||
new LinkedBlockingQueue<>(1024),
|
new LinkedBlockingQueue<>(1024),
|
||||||
threadFactory,
|
threadFactory,
|
||||||
new ThreadPoolExecutor.AbortPolicy());
|
new ThreadPoolExecutor.AbortPolicy());
|
||||||
|
String[] excludeProperties = {"locale", "contentByteArr", "response"};
|
||||||
|
excludefilter.addExcludes(excludeProperties);
|
||||||
}
|
}
|
||||||
|
|
||||||
public HttpUtils() {
|
public HttpUtils() {
|
||||||
|
@ -121,11 +125,11 @@ public class HttpUtils {
|
||||||
String str = sqlBuilder.toString().trim();
|
String str = sqlBuilder.toString().trim();
|
||||||
String removeSeparator = "&";
|
String removeSeparator = "&";
|
||||||
if (str.endsWith(removeSeparator)) {
|
if (str.endsWith(removeSeparator)) {
|
||||||
// 如果以分&号结尾,则去除&号
|
// 如果以分&号结尾,则去除&号
|
||||||
str = str.substring(0, str.length() - 1);
|
str = str.substring(0, str.length() - 1);
|
||||||
}
|
}
|
||||||
if (str.trim().startsWith(removeSeparator)) {
|
if (str.trim().startsWith(removeSeparator)) {
|
||||||
// 如果以&开头,则去除&
|
// 如果以&开头,则去除&
|
||||||
str = str.substring(1);
|
str = str.substring(1);
|
||||||
}
|
}
|
||||||
return str;
|
return str;
|
||||||
|
@ -277,8 +281,8 @@ public class HttpUtils {
|
||||||
|
|
||||||
public ResponeVo apiGet(String url, Map<String, Object> params, Map<String, String> headers) throws IOException {
|
public ResponeVo apiGet(String url, Map<String, Object> params, Map<String, String> headers) throws IOException {
|
||||||
Map<String, Object> paramsMap = paramsHandle(params);
|
Map<String, Object> paramsMap = paramsHandle(params);
|
||||||
String getUrl = urlHandle(url, paramsMap);
|
|
||||||
Map<String, String> headerMap = headersHandle(headers);
|
Map<String, String> headerMap = headersHandle(headers);
|
||||||
|
String getUrl = urlHandle(url, paramsMap);
|
||||||
CloseableHttpClient httpConnection = HttpManager.getHttpConnection(url, this.credentialsProvider);
|
CloseableHttpClient httpConnection = HttpManager.getHttpConnection(url, this.credentialsProvider);
|
||||||
HttpGet httpGet = new HttpGet(getUrl.trim());
|
HttpGet httpGet = new HttpGet(getUrl.trim());
|
||||||
for (Map.Entry<String, String> entry : headerMap.entrySet()) {
|
for (Map.Entry<String, String> entry : headerMap.entrySet()) {
|
||||||
|
@ -405,6 +409,13 @@ public class HttpUtils {
|
||||||
return baseRequest(httpConnection, httpPost);
|
return baseRequest(httpConnection, httpPost);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public ResponeVo apiPost(String url, List<Object> params, Map<String, String> headers) throws IOException {
|
||||||
|
CloseableHttpClient httpConnection = HttpManager.getHttpConnection(url, this.credentialsProvider);
|
||||||
|
Map<String, String> headerMap = headersHandle(headers);
|
||||||
|
HttpPost httpPost = handleHttpPost(url, headerMap, params);
|
||||||
|
return baseRequest(httpConnection, httpPost);
|
||||||
|
}
|
||||||
|
|
||||||
public ResponeVo apiPostObject(String url, Object params, Map<String, String> headers) throws IOException {
|
public ResponeVo apiPostObject(String url, Object params, Map<String, String> headers) throws IOException {
|
||||||
CloseableHttpClient httpConnection = HttpManager.getHttpConnection(url, this.credentialsProvider);
|
CloseableHttpClient httpConnection = HttpManager.getHttpConnection(url, this.credentialsProvider);
|
||||||
Map<String, String> headerMap = headersHandle(headers);
|
Map<String, String> headerMap = headersHandle(headers);
|
||||||
|
@ -638,10 +649,16 @@ public class HttpUtils {
|
||||||
httpUtilParamInfo = new HttpUtilParamInfo();
|
httpUtilParamInfo = new HttpUtilParamInfo();
|
||||||
}
|
}
|
||||||
httpUtilParamInfo.setResponse(apply);
|
httpUtilParamInfo.setResponse(apply);
|
||||||
|
if (apply.getResponseMap() == null) {
|
||||||
|
httpUtilParamInfo.setResponseString(apply.getEntityString());
|
||||||
|
} else {
|
||||||
|
httpUtilParamInfo.setResponseMap(apply.getResponseMap());
|
||||||
|
}
|
||||||
httpUtilParamInfo.setResponseDate(new Date());
|
httpUtilParamInfo.setResponseDate(new Date());
|
||||||
try {
|
try {
|
||||||
log.info(Util.logStr("url [{}] request info : [\n{}\n];", httpUtilParamInfo.getUrl(),
|
log.info(Util.logStr("url [{}] request info : [\n{}\n];", httpUtilParamInfo.getUrl(),
|
||||||
JSONObject.toJSONString(httpUtilParamInfo,
|
JSONObject.toJSONString(httpUtilParamInfo,
|
||||||
|
excludefilter,
|
||||||
SerializerFeature.PrettyFormat,
|
SerializerFeature.PrettyFormat,
|
||||||
SerializerFeature.WriteDateUseDateFormat)));
|
SerializerFeature.WriteDateUseDateFormat)));
|
||||||
} catch (Exception ignore) {
|
} catch (Exception ignore) {
|
||||||
|
@ -669,11 +686,17 @@ public class HttpUtils {
|
||||||
httpUtilParamInfo = new HttpUtilParamInfo();
|
httpUtilParamInfo = new HttpUtilParamInfo();
|
||||||
}
|
}
|
||||||
httpUtilParamInfo.setResponse(apply);
|
httpUtilParamInfo.setResponse(apply);
|
||||||
|
if (apply.getResponseMap() == null) {
|
||||||
|
httpUtilParamInfo.setResponseString(apply.getEntityString());
|
||||||
|
} else {
|
||||||
|
httpUtilParamInfo.setResponseMap(apply.getResponseMap());
|
||||||
|
}
|
||||||
httpUtilParamInfo.setResponseDate(new Date());
|
httpUtilParamInfo.setResponseDate(new Date());
|
||||||
HTTP_UTIL_PARAM_INFO_THREAD_LOCAL.remove();
|
HTTP_UTIL_PARAM_INFO_THREAD_LOCAL.remove();
|
||||||
try {
|
try {
|
||||||
log.info(Util.logStr("url [{}] request info : [\n{}\n];", httpUtilParamInfo.getUrl(),
|
log.info(Util.logStr("url [{}] request info : [\n{}\n];", httpUtilParamInfo.getUrl(),
|
||||||
JSONObject.toJSONString(httpUtilParamInfo,
|
JSONObject.toJSONString(httpUtilParamInfo,
|
||||||
|
excludefilter,
|
||||||
SerializerFeature.PrettyFormat,
|
SerializerFeature.PrettyFormat,
|
||||||
SerializerFeature.WriteDateUseDateFormat)));
|
SerializerFeature.WriteDateUseDateFormat)));
|
||||||
} catch (Exception ignore) {
|
} catch (Exception ignore) {
|
||||||
|
@ -696,17 +719,22 @@ public class HttpUtils {
|
||||||
try {
|
try {
|
||||||
response = httpClient.execute(request);
|
response = httpClient.execute(request);
|
||||||
HttpEntity entity = response.getEntity();
|
HttpEntity entity = response.getEntity();
|
||||||
Header[] allHeaders = response.getAllHeaders();
|
|
||||||
Locale locale = response.getLocale();
|
Locale locale = response.getLocale();
|
||||||
responeVo.setLocale(locale);
|
responeVo.setLocale(locale);
|
||||||
responeVo.setEntityString(EntityUtils.toString(entity, DEFAULT_ENCODING));
|
responeVo.setEntityString(EntityUtils.toString(entity, DEFAULT_ENCODING));
|
||||||
responeVo.setCode(response.getStatusLine().getStatusCode());
|
responeVo.setCode(response.getStatusLine().getStatusCode());
|
||||||
responeVo.setResponse(response);
|
responeVo.setResponse(response);
|
||||||
httpUtilParamInfo.setResponse(responeVo);
|
httpUtilParamInfo.setResponse(responeVo);
|
||||||
|
if (responeVo.getResponseMap() == null) {
|
||||||
|
httpUtilParamInfo.setResponseString(responeVo.getEntityString());
|
||||||
|
} else {
|
||||||
|
httpUtilParamInfo.setResponseMap(responeVo.getResponseMap());
|
||||||
|
}
|
||||||
httpUtilParamInfo.setResponseDate(new Date());
|
httpUtilParamInfo.setResponseDate(new Date());
|
||||||
try {
|
try {
|
||||||
log.info(Util.logStr("url [{}] request info : [\n{}\n];", httpUtilParamInfo.getUrl(),
|
log.info(Util.logStr("url [{}] request info : [\n{}\n];", httpUtilParamInfo.getUrl(),
|
||||||
JSONObject.toJSONString(httpUtilParamInfo,
|
JSONObject.toJSONString(httpUtilParamInfo,
|
||||||
|
excludefilter,
|
||||||
SerializerFeature.PrettyFormat,
|
SerializerFeature.PrettyFormat,
|
||||||
SerializerFeature.WriteDateUseDateFormat)));
|
SerializerFeature.WriteDateUseDateFormat)));
|
||||||
} catch (Exception ignore) {
|
} catch (Exception ignore) {
|
||||||
|
@ -718,6 +746,7 @@ public class HttpUtils {
|
||||||
httpUtilParamInfo.setResponseDate(new Date());
|
httpUtilParamInfo.setResponseDate(new Date());
|
||||||
log.info(Util.logStr("url [{}] request info : [\n{}\n];", httpUtilParamInfo.getUrl(),
|
log.info(Util.logStr("url [{}] request info : [\n{}\n];", httpUtilParamInfo.getUrl(),
|
||||||
JSONObject.toJSONString(httpUtilParamInfo,
|
JSONObject.toJSONString(httpUtilParamInfo,
|
||||||
|
excludefilter,
|
||||||
SerializerFeature.PrettyFormat,
|
SerializerFeature.PrettyFormat,
|
||||||
SerializerFeature.WriteDateUseDateFormat)));
|
SerializerFeature.WriteDateUseDateFormat)));
|
||||||
} catch (Exception ignore) {
|
} catch (Exception ignore) {
|
||||||
|
@ -981,17 +1010,23 @@ public class HttpUtils {
|
||||||
if (Strings.isNullOrEmpty(contentType)) {
|
if (Strings.isNullOrEmpty(contentType)) {
|
||||||
List<NameValuePair> nvps = new ArrayList<>();
|
List<NameValuePair> nvps = new ArrayList<>();
|
||||||
for (Map.Entry<String, Object> entry : params.entrySet()) {
|
for (Map.Entry<String, Object> entry : params.entrySet()) {
|
||||||
nvps.add(new BasicNameValuePair(entry.getKey(), JSON.toJSONString(entry.getValue())));
|
//nvps.add(new BasicNameValuePair(entry.getKey(), JSON.toJSONString(entry.getValue())));
|
||||||
|
|
||||||
|
//修复请求form表单提交时,参数值被双引号括了起来
|
||||||
|
nvps.add(new BasicNameValuePair(entry.getKey(), Util.null2String(entry.getValue())));
|
||||||
}
|
}
|
||||||
httpPost.setHeader("Content-Type", HttpArgsType.DEFAULT_CONTENT_TYPE);
|
httpPost.setHeader("Content-Type", HttpArgsType.DEFAULT_CONTENT_TYPE);
|
||||||
httpPost.setEntity(new UrlEncodedFormEntity(nvps));
|
httpPost.setEntity(new UrlEncodedFormEntity(nvps));
|
||||||
} else if (contentType.toUpperCase().startsWith(HttpArgsType.X_WWW_FORM_URLENCODED.toUpperCase())) {
|
} else if (contentType.toUpperCase().startsWith(HttpArgsType.X_WWW_FORM_URLENCODED.toUpperCase())) {
|
||||||
List<NameValuePair> nvps = new ArrayList<>();
|
List<NameValuePair> nvps = new ArrayList<>();
|
||||||
for (Map.Entry<String, Object> entry : params.entrySet()) {
|
for (Map.Entry<String, Object> entry : params.entrySet()) {
|
||||||
nvps.add(new BasicNameValuePair(entry.getKey(), JSON.toJSONString(entry.getValue())));
|
//nvps.add(new BasicNameValuePair(entry.getKey(), JSON.toJSONString(entry.getValue())));
|
||||||
|
|
||||||
|
//修复请求form表单提交时,参数值被双引号括了起来
|
||||||
|
nvps.add(new BasicNameValuePair(entry.getKey(), Util.null2String(entry.getValue())));
|
||||||
}
|
}
|
||||||
httpPost.setEntity(new UrlEncodedFormEntity(nvps));
|
httpPost.setEntity(new UrlEncodedFormEntity(nvps));
|
||||||
// } else if (contentType.toUpperCase().startsWith(HttpArgsType.APPLICATION_JSON.toUpperCase())) {
|
// } else if (contentType.toUpperCase().startsWith(HttpArgsType.APPLICATION_JSON.toUpperCase())) {
|
||||||
} else {
|
} else {
|
||||||
StringEntity stringEntity;
|
StringEntity stringEntity;
|
||||||
if (params.containsKey(JSON_PARAM_KEY)) {
|
if (params.containsKey(JSON_PARAM_KEY)) {
|
||||||
|
@ -1009,6 +1044,10 @@ public class HttpUtils {
|
||||||
return handleHttpPostObject(url, headerMap, paramsMap);
|
return handleHttpPostObject(url, headerMap, paramsMap);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private HttpPost handleHttpPost(String url, Map<String, String> headerMap, List<Object> params) throws UnsupportedEncodingException {
|
||||||
|
return handleHttpPostObject(url, headerMap, params);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* <h2>上传文件</h2>
|
* <h2>上传文件</h2>
|
||||||
*
|
*
|
||||||
|
@ -1020,8 +1059,14 @@ public class HttpUtils {
|
||||||
*/
|
*/
|
||||||
private HttpPost uploadFileByInputStream(String url, List<HttpMultipartFile> multipartFileList,
|
private HttpPost uploadFileByInputStream(String url, List<HttpMultipartFile> multipartFileList,
|
||||||
Map<String, Object> params, Map<String, String> headers) {
|
Map<String, Object> params, Map<String, String> headers) {
|
||||||
log.info(Util.logStr("start request : url is [{}]" +
|
//log.info(Util.logStr("start request : url is [{}],other param [\n{}\n],heard [\n{}\n]", url, JSONObject.toJSONString(params,
|
||||||
"", url));
|
// excludefilter,
|
||||||
|
// SerializerFeature.PrettyFormat,
|
||||||
|
// SerializerFeature.WriteDateUseDateFormat),
|
||||||
|
// JSONObject.toJSONString(headers,
|
||||||
|
// excludefilter,
|
||||||
|
// SerializerFeature.PrettyFormat,
|
||||||
|
// SerializerFeature.WriteDateUseDateFormat)));
|
||||||
HttpUtilParamInfo httpUtilParamInfo = new HttpUtilParamInfo();
|
HttpUtilParamInfo httpUtilParamInfo = new HttpUtilParamInfo();
|
||||||
httpUtilParamInfo.setParams(params);
|
httpUtilParamInfo.setParams(params);
|
||||||
httpUtilParamInfo.setUrl(url);
|
httpUtilParamInfo.setUrl(url);
|
||||||
|
@ -1069,8 +1114,14 @@ public class HttpUtils {
|
||||||
*/
|
*/
|
||||||
private HttpPut uploadFileByInputStreamPut(String url, List<HttpMultipartFile> multipartFileList,
|
private HttpPut uploadFileByInputStreamPut(String url, List<HttpMultipartFile> multipartFileList,
|
||||||
Map<String, Object> params, Map<String, String> headers) {
|
Map<String, Object> params, Map<String, String> headers) {
|
||||||
log.info(Util.logStr("start request : url is [{}]" +
|
log.info(Util.logStr("start request : url is [{}],other param [\n{}\n],heard [\n{}\n]", url, JSONObject.toJSONString(params,
|
||||||
"", url));
|
excludefilter,
|
||||||
|
SerializerFeature.PrettyFormat,
|
||||||
|
SerializerFeature.WriteDateUseDateFormat),
|
||||||
|
JSONObject.toJSONString(headers,
|
||||||
|
excludefilter,
|
||||||
|
SerializerFeature.PrettyFormat,
|
||||||
|
SerializerFeature.WriteDateUseDateFormat)));
|
||||||
HttpUtilParamInfo httpUtilParamInfo = new HttpUtilParamInfo();
|
HttpUtilParamInfo httpUtilParamInfo = new HttpUtilParamInfo();
|
||||||
httpUtilParamInfo.setParams(params);
|
httpUtilParamInfo.setParams(params);
|
||||||
httpUtilParamInfo.setUrl(url);
|
httpUtilParamInfo.setUrl(url);
|
||||||
|
@ -1153,14 +1204,18 @@ public class HttpUtils {
|
||||||
if (Strings.isNullOrEmpty(contentType)) {
|
if (Strings.isNullOrEmpty(contentType)) {
|
||||||
List<NameValuePair> nvps = new ArrayList<>();
|
List<NameValuePair> nvps = new ArrayList<>();
|
||||||
for (Map.Entry<String, Object> entry : paramsMap.entrySet()) {
|
for (Map.Entry<String, Object> entry : paramsMap.entrySet()) {
|
||||||
nvps.add(new BasicNameValuePair(entry.getKey(), JSON.toJSONString(entry.getValue())));
|
//nvps.add(new BasicNameValuePair(entry.getKey(), JSON.toJSONString(entry.getValue())));
|
||||||
|
//修复请求form表单提交时,参数值被双引号括了起来
|
||||||
|
nvps.add(new BasicNameValuePair(entry.getKey(), Util.null2String(entry.getValue())));
|
||||||
}
|
}
|
||||||
httpPut.setHeader("Content-Type", HttpArgsType.DEFAULT_CONTENT_TYPE);
|
httpPut.setHeader("Content-Type", HttpArgsType.DEFAULT_CONTENT_TYPE);
|
||||||
httpPut.setEntity(new UrlEncodedFormEntity(nvps));
|
httpPut.setEntity(new UrlEncodedFormEntity(nvps));
|
||||||
} else if (contentType.toUpperCase().startsWith(HttpArgsType.X_WWW_FORM_URLENCODED.toUpperCase())) {
|
} else if (contentType.toUpperCase().startsWith(HttpArgsType.X_WWW_FORM_URLENCODED.toUpperCase())) {
|
||||||
List<NameValuePair> nvps = new ArrayList<>();
|
List<NameValuePair> nvps = new ArrayList<>();
|
||||||
for (Map.Entry<String, Object> entry : paramsMap.entrySet()) {
|
for (Map.Entry<String, Object> entry : paramsMap.entrySet()) {
|
||||||
nvps.add(new BasicNameValuePair(entry.getKey(), JSON.toJSONString(entry.getValue())));
|
//nvps.add(new BasicNameValuePair(entry.getKey(), JSON.toJSONString(entry.getValue())));
|
||||||
|
//修复请求form表单提交时,参数值被双引号括了起来
|
||||||
|
nvps.add(new BasicNameValuePair(entry.getKey(), Util.null2String(entry.getValue())));
|
||||||
}
|
}
|
||||||
httpPut.setEntity(new UrlEncodedFormEntity(nvps));
|
httpPut.setEntity(new UrlEncodedFormEntity(nvps));
|
||||||
} else if (contentType.toUpperCase().startsWith(HttpArgsType.APPLICATION_JSON.toUpperCase())) {
|
} else if (contentType.toUpperCase().startsWith(HttpArgsType.APPLICATION_JSON.toUpperCase())) {
|
||||||
|
|
|
@ -0,0 +1,27 @@
|
||||||
|
package aiyh.utils.lock;
|
||||||
|
|
||||||
|
import lombok.Getter;
|
||||||
|
import lombok.Setter;
|
||||||
|
import lombok.ToString;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* <h1>锁参数信息</h1>
|
||||||
|
*
|
||||||
|
* <p>create: 2022-12-11 02:07</p>
|
||||||
|
*
|
||||||
|
* @author youHong.ai
|
||||||
|
*/
|
||||||
|
|
||||||
|
@Getter
|
||||||
|
@Setter
|
||||||
|
@ToString
|
||||||
|
public class LockEntity {
|
||||||
|
/** 锁住次数 */
|
||||||
|
private Integer times;
|
||||||
|
|
||||||
|
/** 锁标识 */
|
||||||
|
private Thread lockMark;
|
||||||
|
|
||||||
|
/** 过期时间 */
|
||||||
|
private Long expirationTime;
|
||||||
|
}
|
|
@ -0,0 +1,33 @@
|
||||||
|
package aiyh.utils.lock;
|
||||||
|
|
||||||
|
import lombok.Getter;
|
||||||
|
import lombok.Setter;
|
||||||
|
import lombok.ToString;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* <h1>锁对应数据库的实体类</h1>
|
||||||
|
*
|
||||||
|
* <p>create: 2022-12-11 00:24</p>
|
||||||
|
*
|
||||||
|
* @author youHong.ai
|
||||||
|
*/
|
||||||
|
|
||||||
|
@Setter
|
||||||
|
@Getter
|
||||||
|
@ToString
|
||||||
|
public class LockPojo {
|
||||||
|
/**
|
||||||
|
* 数据库id
|
||||||
|
*/
|
||||||
|
private Integer id;
|
||||||
|
|
||||||
|
/** 过期时间 */
|
||||||
|
private Long expirationTime;
|
||||||
|
|
||||||
|
/** 锁的键 */
|
||||||
|
private String lockName;
|
||||||
|
|
||||||
|
/** 锁状态 */
|
||||||
|
private Integer lockStatus;
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,129 @@
|
||||||
|
package aiyh.utils.lock;
|
||||||
|
|
||||||
|
import aiyh.utils.annotation.recordset.ParamMapper;
|
||||||
|
import aiyh.utils.annotation.recordset.Select;
|
||||||
|
import aiyh.utils.annotation.recordset.SqlMapper;
|
||||||
|
import aiyh.utils.annotation.recordset.Update;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* <h1>分布式锁数据库查询</h1>
|
||||||
|
*
|
||||||
|
* <p>create: 2022-12-11 00:22</p>
|
||||||
|
*
|
||||||
|
* @author youHong.ai
|
||||||
|
*/
|
||||||
|
|
||||||
|
@SqlMapper
|
||||||
|
public interface LockUtilMapper {
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* <h2>根据锁名称获取锁状态</h2>
|
||||||
|
* <i>2022/12/11 00:37</i>
|
||||||
|
* ******************************************
|
||||||
|
*
|
||||||
|
* @param lockKey 锁名称
|
||||||
|
* @return LockPojo 锁参数对象
|
||||||
|
* @author youHong.ai ******************************************
|
||||||
|
*/
|
||||||
|
@Select("select id, lock_name, lock_status, expiration_time " +
|
||||||
|
"from uf_cus_lock " +
|
||||||
|
"where lock_name = #{lockKey}")
|
||||||
|
LockPojo selectLock(@ParamMapper("lockKey") String lockKey);
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* <h2>根据锁名称释放锁资源</h2>
|
||||||
|
* <i>2022/12/11 00:46</i>
|
||||||
|
* ******************************************
|
||||||
|
*
|
||||||
|
* @param id 锁id
|
||||||
|
* @return boolean 是否更新成功
|
||||||
|
* @author youHong.ai ******************************************
|
||||||
|
*/
|
||||||
|
@Update("update uf_cus_lock " +
|
||||||
|
"set lock_status = 0 " +
|
||||||
|
"where id = #{id} " +
|
||||||
|
" and lock_status = 1")
|
||||||
|
boolean unLock(@ParamMapper("id") Integer id);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* <h2>根据锁名称释放锁资源</h2>
|
||||||
|
* <i>2022/12/11 00:46</i>
|
||||||
|
* ******************************************
|
||||||
|
*
|
||||||
|
* @param lockKey 锁名称
|
||||||
|
* @return boolean 是否更新成功
|
||||||
|
* @author youHong.ai ******************************************
|
||||||
|
*/
|
||||||
|
@Update("update uf_cus_lock " +
|
||||||
|
"set lock_status = 0 " +
|
||||||
|
"where lock_name = #{lockKey} " +
|
||||||
|
" and lock_status = 1")
|
||||||
|
boolean unLock(@ParamMapper("lockKey") String lockKey);
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* <h2>更新锁状态,锁住资源</h2>
|
||||||
|
* <i>2022/12/11 00:49</i>
|
||||||
|
* ******************************************
|
||||||
|
*
|
||||||
|
* @param id 数据id
|
||||||
|
* @param lockKey 锁名称
|
||||||
|
* @param time 过期时间
|
||||||
|
* @return boolean 是否成功锁住资源
|
||||||
|
* @author youHong.ai ******************************************
|
||||||
|
*/
|
||||||
|
@Update("update uf_cus_lock " +
|
||||||
|
"set lock_name = #{lockKey}," +
|
||||||
|
" expiration_time = #{time}," +
|
||||||
|
" lock_status = 1 " +
|
||||||
|
"where id = #{id} " +
|
||||||
|
" and (lock_status = 0 or expiration_time < #{time})")
|
||||||
|
boolean lock(@ParamMapper("id") Integer id,
|
||||||
|
@ParamMapper("lockKey") String lockKey,
|
||||||
|
@ParamMapper("time") Long time);
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* <h2>更新锁过期时间,续期</h2>
|
||||||
|
* <i>2022/12/11 00:52</i>
|
||||||
|
* ******************************************
|
||||||
|
*
|
||||||
|
* @param lockKey 锁名称
|
||||||
|
* @param time 过期时间
|
||||||
|
* @return boolean 是否更新成功
|
||||||
|
* @author youHong.ai ******************************************
|
||||||
|
*/
|
||||||
|
@Update("update uf_cus_lock " +
|
||||||
|
"set expiration_time = #{time} " +
|
||||||
|
"where lock_name = #{lockKey} " +
|
||||||
|
" and lock_status = 1")
|
||||||
|
boolean updateLockTime(@ParamMapper("lockKey") String lockKey,
|
||||||
|
@ParamMapper("time") Long time);
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* <h2>对过期锁重新设置锁</h2>
|
||||||
|
* <i>2022/12/11 15:02</i>
|
||||||
|
* ******************************************
|
||||||
|
*
|
||||||
|
* @param id 锁id
|
||||||
|
* @param lockKey 锁名称
|
||||||
|
* @param time 锁过期时间
|
||||||
|
* @param expirationTime 上一个锁的过期时间
|
||||||
|
* @return boolean 是否重新上锁成功
|
||||||
|
* @author youHong.ai ******************************************
|
||||||
|
*/
|
||||||
|
@Update("update uf_cus_lock " +
|
||||||
|
"set lock_name = #{lockKey}, " +
|
||||||
|
" expiration_time = #{time}, " +
|
||||||
|
" lock_status = 1 " +
|
||||||
|
"where id = #{id} " +
|
||||||
|
" and lock_status = 1 " +
|
||||||
|
" and expiration_time = #{expirationTime}")
|
||||||
|
boolean reLock(@ParamMapper("id") Integer id,
|
||||||
|
@ParamMapper("lockKey") String lockKey,
|
||||||
|
@ParamMapper("time") Long time,
|
||||||
|
@ParamMapper("expirationTime") Long expirationTime);
|
||||||
|
}
|
|
@ -0,0 +1,350 @@
|
||||||
|
package aiyh.utils.lock;
|
||||||
|
|
||||||
|
import aiyh.utils.Util;
|
||||||
|
import aiyh.utils.excention.CustomerException;
|
||||||
|
import cn.hutool.core.thread.ThreadUtil;
|
||||||
|
import ebu7common.youhong.ai.bean.Builder;
|
||||||
|
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.Objects;
|
||||||
|
import java.util.concurrent.ConcurrentHashMap;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* <h1>分布式锁</h1>
|
||||||
|
*
|
||||||
|
* <p>create: 2022-12-11 00:21</p>
|
||||||
|
*
|
||||||
|
* @author youHong.ai
|
||||||
|
*/
|
||||||
|
|
||||||
|
public class LockUtils {
|
||||||
|
|
||||||
|
private static final LockUtilMapper mapper = Util.getMapper(LockUtilMapper.class);
|
||||||
|
|
||||||
|
private static final Map<String, LockEntity> LOCK_MAP = new ConcurrentHashMap<>();
|
||||||
|
|
||||||
|
/** 默认过期时间 10s */
|
||||||
|
private static final Long DEFAULT_OVERDUE_TIME = 1_000 * 10L;
|
||||||
|
|
||||||
|
private static final String UF_CUS_LOCK = "uf_cus_lock";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* <h2>上锁</h2>
|
||||||
|
* <i>2022/12/11 15:40</i>
|
||||||
|
* ******************************************
|
||||||
|
*
|
||||||
|
* @param lockName 锁名称
|
||||||
|
* @param reentrant 是否可重入
|
||||||
|
* @return boolean 是否抢占成功
|
||||||
|
* @author youHong.ai ******************************************
|
||||||
|
*/
|
||||||
|
public static boolean lock(String lockName, boolean reentrant) {
|
||||||
|
return lock(lockName, DEFAULT_OVERDUE_TIME, reentrant);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* <h2>上锁</h2>
|
||||||
|
* <i>2022/12/11 15:40</i>
|
||||||
|
* ******************************************
|
||||||
|
*
|
||||||
|
* @param lockName 锁名称
|
||||||
|
* @param overdueTime 超时时间
|
||||||
|
* @param reentrant 是否可重入
|
||||||
|
* @return boolean 是否抢占成功
|
||||||
|
* @author youHong.ai ******************************************
|
||||||
|
*/
|
||||||
|
public static boolean lock(String lockName, Long overdueTime, boolean reentrant) {
|
||||||
|
LockPojo lockPojo = mapper.selectLock(lockName);
|
||||||
|
if (Objects.isNull(lockPojo) || lockPojo.getId() <= 0) {
|
||||||
|
return insertLock(lockName, overdueTime);
|
||||||
|
} else {
|
||||||
|
// 存在当前的锁的锁名称
|
||||||
|
if (lockPojo.getLockStatus() == 1) {
|
||||||
|
// 锁处于锁定状态
|
||||||
|
return onLock(lockName, overdueTime, reentrant, lockPojo);
|
||||||
|
} else {
|
||||||
|
// 处于未锁定状态开始对资源上锁
|
||||||
|
boolean lock = mapper.lock(lockPojo.getId(), lockName, overdueTime);
|
||||||
|
if (lock) {
|
||||||
|
// 锁定成功
|
||||||
|
LOCK_MAP.put(lockName,
|
||||||
|
Builder.builder(LockEntity::new)
|
||||||
|
.with(LockEntity::setTimes, 1)
|
||||||
|
.with(LockEntity::setLockMark, Thread.currentThread())
|
||||||
|
.with(LockEntity::setExpirationTime, overdueTime)
|
||||||
|
.build());
|
||||||
|
return true;
|
||||||
|
} else {
|
||||||
|
// 抢占锁失败
|
||||||
|
lockPojo = mapper.selectLock(lockName);
|
||||||
|
return retryGetLock(lockName, overdueTime, lockPojo);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* <h2>处于锁状态</h2>
|
||||||
|
* <i>2022/12/11 12:23</i>
|
||||||
|
* ******************************************
|
||||||
|
*
|
||||||
|
* @param lockName 锁名称
|
||||||
|
* @param overdueTime 锁超时时间
|
||||||
|
* @param reentrant 是否可重入锁
|
||||||
|
* @param lockPojo 锁信息对象
|
||||||
|
* @return boolean 是否获取锁成功
|
||||||
|
* @author youHong.ai ******************************************
|
||||||
|
*/
|
||||||
|
private static boolean onLock(String lockName, Long overdueTime, boolean reentrant, LockPojo lockPojo) {
|
||||||
|
Long time = lockPojo.getExpirationTime();
|
||||||
|
if (time > System.currentTimeMillis()) {
|
||||||
|
// 锁过期了 如果要使锁生效就将日期加长
|
||||||
|
return lockExpiration(lockName, overdueTime, lockPojo);
|
||||||
|
} else {
|
||||||
|
//锁没有过期
|
||||||
|
return inLockTime(lockName, overdueTime, reentrant);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* <h2>锁未过期</h2>
|
||||||
|
* <i>2022/12/11 12:24</i>
|
||||||
|
* ******************************************
|
||||||
|
*
|
||||||
|
* @param lockName 锁名称
|
||||||
|
* @param overdueTime 锁过期时间
|
||||||
|
* @param reentrant 是否可重入
|
||||||
|
* @return boolean 是否成功获取锁
|
||||||
|
* @author youHong.ai ******************************************
|
||||||
|
*/
|
||||||
|
private static boolean inLockTime(String lockName, Long overdueTime, boolean reentrant) {
|
||||||
|
//判断是否存在本地锁对象中
|
||||||
|
LockPojo lockPojo = mapper.selectLock(lockName);
|
||||||
|
if (!LOCK_MAP.containsKey(lockName)) {
|
||||||
|
// 不是本地锁,不支持可重入,使线程进入等待状态
|
||||||
|
int n = 0;
|
||||||
|
return retryGetLock(lockName, overdueTime, lockPojo);
|
||||||
|
}
|
||||||
|
// 是本地锁
|
||||||
|
return getLock(lockName, overdueTime, reentrant);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* <h2>尝试抢占资源锁</h2>
|
||||||
|
* <i>2022/12/11 15:34</i>
|
||||||
|
* ******************************************
|
||||||
|
*
|
||||||
|
* @param lockName 锁名称
|
||||||
|
* @param overdueTime 锁过期时间
|
||||||
|
* @param lockPojo 锁参数对象
|
||||||
|
* @return boolean 是否抢占锁成功
|
||||||
|
* @author youHong.ai ******************************************
|
||||||
|
*/
|
||||||
|
private static boolean retryGetLock(String lockName, Long overdueTime, LockPojo lockPojo) {
|
||||||
|
while (lockPojo.getExpirationTime() > System.currentTimeMillis()) {
|
||||||
|
// 锁还没过期,使线程休眠
|
||||||
|
long l = lockPojo.getExpirationTime() - System.currentTimeMillis();
|
||||||
|
if (l > 10) {
|
||||||
|
ThreadUtil.safeSleep(l - 10L);
|
||||||
|
}
|
||||||
|
// 尝试获取锁
|
||||||
|
lockExpiration(lockName, overdueTime + l, lockPojo);
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* <h2>获取锁</h2>
|
||||||
|
* <i>2022/12/11 13:57</i>
|
||||||
|
* ******************************************
|
||||||
|
*
|
||||||
|
* @param lockName 锁名称
|
||||||
|
* @param overdueTime 超时时间
|
||||||
|
* @param reentrant 是否可重入
|
||||||
|
* @return boolean 锁是否获取成功
|
||||||
|
* @author youHong.ai ******************************************
|
||||||
|
*/
|
||||||
|
private static boolean getLock(String lockName, Long overdueTime, boolean reentrant) {
|
||||||
|
if (reentrant) {
|
||||||
|
LockEntity lockEntity = LOCK_MAP.get(lockName);
|
||||||
|
lockEntity.setTimes(lockEntity.getTimes() + 1);
|
||||||
|
} else {
|
||||||
|
LockPojo lockPojo = mapper.selectLock(lockName);
|
||||||
|
retryGetLock(lockName, overdueTime, lockPojo);
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* <h2>锁过期</h2>
|
||||||
|
* <i>2022/12/11 12:25</i>
|
||||||
|
* ******************************************
|
||||||
|
*
|
||||||
|
* @param lockName 锁名称
|
||||||
|
* @param overdueTime 锁过期时间
|
||||||
|
* @return boolean 是否成功获取锁
|
||||||
|
* @author youHong.ai ******************************************
|
||||||
|
*/
|
||||||
|
private static boolean lockExpiration(String lockName, Long overdueTime, LockPojo lockPojo) {
|
||||||
|
boolean lock = mapper.reLock(lockPojo.getId(), lockName, overdueTime, lockPojo.getExpirationTime());
|
||||||
|
if (lock) {
|
||||||
|
//更新锁状态成功
|
||||||
|
LockEntity lockEntity = Builder.builder(LockEntity::new)
|
||||||
|
.with(LockEntity::setTimes, 1)
|
||||||
|
.with(LockEntity::setLockMark, Thread.currentThread())
|
||||||
|
.with(LockEntity::setExpirationTime, overdueTime)
|
||||||
|
.build();
|
||||||
|
LOCK_MAP.put(lockName, lockEntity);
|
||||||
|
return true;
|
||||||
|
} else {
|
||||||
|
// 更新失败,可能是其他服务器抢先获得了锁
|
||||||
|
LockPojo newLockPojo = mapper.selectLock(lockName);
|
||||||
|
if (Objects.isNull(newLockPojo)) {
|
||||||
|
// 锁被释放了
|
||||||
|
boolean isLock = insertLock(lockName, overdueTime);
|
||||||
|
if (!isLock) {
|
||||||
|
throw new CustomerException("can not getLock!");
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
if (newLockPojo.getExpirationTime() > lockPojo.getExpirationTime()) {
|
||||||
|
// 锁被其他机器抢占
|
||||||
|
return retryGetLock(lockName, overdueTime, newLockPojo);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* <h2>新增锁记录</h2>
|
||||||
|
* <i>2022/12/11 12:25</i>
|
||||||
|
* ******************************************
|
||||||
|
*
|
||||||
|
* @param lockName 锁名称
|
||||||
|
* @param overdueTime 锁过期时间
|
||||||
|
* @return boolean 是否是可重入锁
|
||||||
|
* @author youHong.ai ******************************************
|
||||||
|
*/
|
||||||
|
private static boolean insertLock(String lockName, Long overdueTime) {
|
||||||
|
// 没有锁需要新增一条锁记录
|
||||||
|
String modeId = Util.getModeIdByTableName(UF_CUS_LOCK);
|
||||||
|
int dataId = Util.getModeDataId(UF_CUS_LOCK, Integer.parseInt(modeId), 1);
|
||||||
|
long currentTime = System.currentTimeMillis();
|
||||||
|
Long expirationTime = currentTime + overdueTime;
|
||||||
|
boolean lock = mapper.lock(dataId, lockName, expirationTime);
|
||||||
|
if (lock) {
|
||||||
|
// 锁成功
|
||||||
|
LockEntity lockEntity = Builder.builder(LockEntity::new)
|
||||||
|
.with(LockEntity::setTimes, 1)
|
||||||
|
.with(LockEntity::setLockMark, Thread.currentThread())
|
||||||
|
.with(LockEntity::setExpirationTime, overdueTime)
|
||||||
|
.build();
|
||||||
|
LOCK_MAP.put(lockName, lockEntity);
|
||||||
|
} else {
|
||||||
|
LockPojo lockPojo = mapper.selectLock(lockName);
|
||||||
|
if (Objects.isNull(lockPojo)) {
|
||||||
|
// 锁失败
|
||||||
|
retryLock(dataId, lockName, expirationTime, 0);
|
||||||
|
} else {
|
||||||
|
// 其他服务器抢占了锁资源
|
||||||
|
return retryGetLock(lockName, overdueTime, lockPojo);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* <h2>重试锁</h2>
|
||||||
|
* <i>2022/12/11 01:39</i>
|
||||||
|
* ************************************************************
|
||||||
|
*
|
||||||
|
* @param dataId 数据id
|
||||||
|
* @param lockName 锁名称
|
||||||
|
* @param expirationTime 过期时间
|
||||||
|
* @param n 重试次数
|
||||||
|
* @author youHong.ai ******************************************
|
||||||
|
*/
|
||||||
|
private static void retryLock(int dataId, String lockName, Long expirationTime, int n) {
|
||||||
|
if (n > 5) {
|
||||||
|
throw new CustomerException("get lock error! 5 failed attempts to update the database!");
|
||||||
|
}
|
||||||
|
ThreadUtil.safeSleep((n + 1) * 500);
|
||||||
|
boolean lock = mapper.lock(dataId, lockName, expirationTime + (n + 1) * 500L);
|
||||||
|
if (lock) {
|
||||||
|
// 锁成功
|
||||||
|
LockEntity lockEntity = Builder.builder(LockEntity::new)
|
||||||
|
.with(LockEntity::setTimes, 1)
|
||||||
|
.with(LockEntity::setLockMark, Thread.currentThread())
|
||||||
|
.with(LockEntity::setExpirationTime, expirationTime + (1 + n) * 500L)
|
||||||
|
.build();
|
||||||
|
LOCK_MAP.put(lockName, lockEntity);
|
||||||
|
} else {
|
||||||
|
// 锁失败
|
||||||
|
retryLock(dataId, lockName, expirationTime, n + 1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* <h2>释放锁</h2>
|
||||||
|
* <i>2022/12/11 15:56</i>
|
||||||
|
* ******************************************
|
||||||
|
*
|
||||||
|
* @param lockName 锁名称
|
||||||
|
* @author youHong.ai ******************************************
|
||||||
|
*/
|
||||||
|
public static void unLock(String lockName) {
|
||||||
|
if (LOCK_MAP.containsKey(lockName)) {
|
||||||
|
// 存在本地锁
|
||||||
|
LockEntity lockEntity = LOCK_MAP.get(lockName);
|
||||||
|
if (!lockEntity.getLockMark().equals(Thread.currentThread())) {
|
||||||
|
// 并非当前上锁的线程在释放锁
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
Integer times = lockEntity.getTimes();
|
||||||
|
if (times - 1 == 0) {
|
||||||
|
boolean unlock = mapper.unLock(lockName);
|
||||||
|
if (!unlock) {
|
||||||
|
int n = 0;
|
||||||
|
do {
|
||||||
|
if (n++ > 5) {
|
||||||
|
throw new CustomerException("can not unLock!Failed to release the lock after five attempts!");
|
||||||
|
}
|
||||||
|
} while (!mapper.unLock(lockName)); // 释放锁失败
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
lockEntity.setTimes(lockEntity.getTimes() - 1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* <h2>锁续期</h2>
|
||||||
|
* <i>2022/12/11 15:49</i>
|
||||||
|
* ******************************************
|
||||||
|
*
|
||||||
|
* @param lockKey 锁名字
|
||||||
|
* @param expirationTime 锁过期时间
|
||||||
|
* @return boolean 是否续期成功
|
||||||
|
* @author youHong.ai ******************************************
|
||||||
|
*/
|
||||||
|
public boolean updateLockTime(String lockKey, Long expirationTime) {
|
||||||
|
if (!mapper.updateLockTime(lockKey, expirationTime)) {
|
||||||
|
// 更新失败
|
||||||
|
int n = 0;
|
||||||
|
do {
|
||||||
|
if (n++ > 5) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
} while (!mapper.updateLockTime(lockKey, expirationTime));
|
||||||
|
}
|
||||||
|
if (LOCK_MAP.containsKey(lockKey)) {
|
||||||
|
// 存在本地锁,更新锁信息
|
||||||
|
LockEntity lockEntity = LOCK_MAP.get(lockKey);
|
||||||
|
lockEntity.setExpirationTime(expirationTime);
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -6,23 +6,33 @@ import aiyh.utils.excention.CustomerException;
|
||||||
import com.google.common.base.Strings;
|
import com.google.common.base.Strings;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import weaver.conn.RecordSet;
|
import weaver.conn.RecordSet;
|
||||||
|
import weaver.conn.RecordSetTrans;
|
||||||
|
|
||||||
import java.lang.reflect.Field;
|
import java.lang.reflect.Field;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author EBU7-dev1-ayh
|
* @author EBU7-dev1-ayh create 2021/12/21 0021 13:34
|
||||||
* create 2021/12/21 0021 13:34
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
public class BooleanTypeHandler implements TypeHandler{
|
public class BooleanTypeHandler implements TypeHandler {
|
||||||
@Override
|
@Override
|
||||||
public Object getValue(RecordSet rs, String fieldName, Field declaredField) {
|
public Object getValue(RecordSet rs, String fieldName, Field declaredField) {
|
||||||
return getBoolean(declaredField, rs.getString(fieldName));
|
return getBoolean(declaredField, rs.getString(fieldName));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Object getValue(RecordSet rs, int index,Field declaredField) {
|
public Object getValue(RecordSet rs, int index, Field declaredField) {
|
||||||
|
return getBoolean(declaredField, rs.getString(index));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Object getValue(RecordSetTrans rs, String fieldName, Field declaredField) {
|
||||||
|
return getBoolean(declaredField, rs.getString(fieldName));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Object getValue(RecordSetTrans rs, int index, Field declaredField) {
|
||||||
return getBoolean(declaredField, rs.getString(index));
|
return getBoolean(declaredField, rs.getString(index));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -58,7 +68,7 @@ public class BooleanTypeHandler implements TypeHandler{
|
||||||
} else {
|
} else {
|
||||||
return defaultValue;
|
return defaultValue;
|
||||||
}
|
}
|
||||||
}else {
|
} else {
|
||||||
return defaultValue;
|
return defaultValue;
|
||||||
}
|
}
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
|
|
|
@ -4,14 +4,14 @@ import aiyh.utils.annotation.DateFormatAn;
|
||||||
import aiyh.utils.excention.TypeNonsupportException;
|
import aiyh.utils.excention.TypeNonsupportException;
|
||||||
import com.ibm.icu.text.SimpleDateFormat;
|
import com.ibm.icu.text.SimpleDateFormat;
|
||||||
import weaver.conn.RecordSet;
|
import weaver.conn.RecordSet;
|
||||||
|
import weaver.conn.RecordSetTrans;
|
||||||
|
|
||||||
import java.lang.reflect.Field;
|
import java.lang.reflect.Field;
|
||||||
import java.text.ParseException;
|
import java.text.ParseException;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author EBU7-dev1-ayh
|
* @author EBU7-dev1-ayh create 2021/12/21 0021 13:35
|
||||||
* create 2021/12/21 0021 13:35
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
@ -53,4 +53,42 @@ public class DataTypeHandler implements TypeHandler {
|
||||||
}
|
}
|
||||||
return date;
|
return date;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Object getValue(RecordSetTrans rs, String fieldName, Field declaredField) {
|
||||||
|
if (declaredField == null) {
|
||||||
|
throw new TypeNonsupportException("An error occurred while trying to convert the query result field to type Date!");
|
||||||
|
}
|
||||||
|
DateFormatAn annotation = declaredField.getAnnotation(DateFormatAn.class);
|
||||||
|
Date date = null;
|
||||||
|
if (annotation != null) {
|
||||||
|
String value = annotation.value();
|
||||||
|
try {
|
||||||
|
date = new SimpleDateFormat(value).parse(rs.getString(fieldName));
|
||||||
|
} catch (ParseException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
throw new TypeNonsupportException("Failed to convert [" + rs.getString(fieldName) + "] to a Date object as [" + value + "]!!");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return date;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Object getValue(RecordSetTrans rs, int index, Field declaredField) {
|
||||||
|
if (declaredField == null) {
|
||||||
|
throw new TypeNonsupportException("An error occurred while trying to convert the query result field to type Date!");
|
||||||
|
}
|
||||||
|
DateFormatAn annotation = declaredField.getAnnotation(DateFormatAn.class);
|
||||||
|
Date date = null;
|
||||||
|
if (annotation != null) {
|
||||||
|
String value = annotation.value();
|
||||||
|
try {
|
||||||
|
date = new SimpleDateFormat(value).parse(rs.getString(index));
|
||||||
|
} catch (ParseException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
throw new TypeNonsupportException("Failed to convert [" + rs.getString(index) + "] to a Date object as [" + value + "]!!");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return date;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,6 +2,7 @@ package aiyh.utils.recordset;
|
||||||
|
|
||||||
import aiyh.utils.Util;
|
import aiyh.utils.Util;
|
||||||
import weaver.conn.RecordSet;
|
import weaver.conn.RecordSet;
|
||||||
|
import weaver.conn.RecordSetTrans;
|
||||||
|
|
||||||
import java.lang.reflect.Field;
|
import java.lang.reflect.Field;
|
||||||
|
|
||||||
|
@ -15,13 +16,25 @@ import java.lang.reflect.Field;
|
||||||
public class FloatTypeHandler implements TypeHandler {
|
public class FloatTypeHandler implements TypeHandler {
|
||||||
@Override
|
@Override
|
||||||
public Object getValue(RecordSet rs, String fieldName, Field declaredField) {
|
public Object getValue(RecordSet rs, String fieldName, Field declaredField) {
|
||||||
String string = Util.null2DefaultStr(rs.getString(fieldName),"0.0");
|
String string = Util.null2DefaultStr(rs.getString(fieldName), "0.0");
|
||||||
return Float.parseFloat(string);
|
return Float.parseFloat(string);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Object getValue(RecordSet rs, int index, Field declaredField) {
|
public Object getValue(RecordSet rs, int index, Field declaredField) {
|
||||||
String string = Util.null2DefaultStr(rs.getString(index),"0.0");
|
String string = Util.null2DefaultStr(rs.getString(index), "0.0");
|
||||||
|
return Float.parseFloat(string);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Object getValue(RecordSetTrans rs, String fieldName, Field declaredField) {
|
||||||
|
String string = Util.null2DefaultStr(rs.getString(fieldName), "0.0");
|
||||||
|
return Float.parseFloat(string);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Object getValue(RecordSetTrans rs, int index, Field declaredField) {
|
||||||
|
String string = Util.null2DefaultStr(rs.getString(index), "0.0");
|
||||||
return Float.parseFloat(string);
|
return Float.parseFloat(string);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,30 +2,48 @@ package aiyh.utils.recordset;
|
||||||
|
|
||||||
import aiyh.utils.Util;
|
import aiyh.utils.Util;
|
||||||
import weaver.conn.RecordSet;
|
import weaver.conn.RecordSet;
|
||||||
|
import weaver.conn.RecordSetTrans;
|
||||||
|
|
||||||
import java.lang.reflect.Field;
|
import java.lang.reflect.Field;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author EBU7-dev1-ayh
|
* @author EBU7-dev1-ayh create 2021/12/21 0021 13:10
|
||||||
* create 2021/12/21 0021 13:10
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
public class IntegerTypeHandler implements TypeHandler{
|
public class IntegerTypeHandler implements TypeHandler {
|
||||||
@Override
|
@Override
|
||||||
public Object getValue(RecordSet rs, String fieldName, Field declaredField) {
|
public Object getValue(RecordSet rs, String fieldName, Field declaredField) {
|
||||||
String string = Util.null2DefaultStr(rs.getString(fieldName),"-1");
|
String string = Util.null2DefaultStr(rs.getString(fieldName), "-1");
|
||||||
if(string.contains(".")){
|
if (string.contains(".")) {
|
||||||
string = string.substring(0,string.indexOf("."));
|
string = string.substring(0, string.indexOf("."));
|
||||||
}
|
}
|
||||||
return Integer.parseInt(string);
|
return Integer.parseInt(string);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Object getValue(RecordSet rs, int index,Field declaredField) {
|
public Object getValue(RecordSet rs, int index, Field declaredField) {
|
||||||
String string = Util.null2DefaultStr(rs.getString(index),"-1");
|
String string = Util.null2DefaultStr(rs.getString(index), "-1");
|
||||||
if(string.contains(".")){
|
if (string.contains(".")) {
|
||||||
string = string.substring(0,string.indexOf("."));
|
string = string.substring(0, string.indexOf("."));
|
||||||
|
}
|
||||||
|
return Integer.parseInt(string);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Object getValue(RecordSetTrans rs, String fieldName, Field declaredField) {
|
||||||
|
String string = Util.null2DefaultStr(rs.getString(fieldName), "-1");
|
||||||
|
if (string.contains(".")) {
|
||||||
|
string = string.substring(0, string.indexOf("."));
|
||||||
|
}
|
||||||
|
return Integer.parseInt(string);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Object getValue(RecordSetTrans rs, int index, Field declaredField) {
|
||||||
|
String string = Util.null2DefaultStr(rs.getString(index), "-1");
|
||||||
|
if (string.contains(".")) {
|
||||||
|
string = string.substring(0, string.indexOf("."));
|
||||||
}
|
}
|
||||||
return Integer.parseInt(string);
|
return Integer.parseInt(string);
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,48 +7,70 @@ import aiyh.utils.excention.CustomerException;
|
||||||
import aiyh.utils.sqlUtil.sqlResult.impl.BatchSqlResultImpl;
|
import aiyh.utils.sqlUtil.sqlResult.impl.BatchSqlResultImpl;
|
||||||
import aiyh.utils.sqlUtil.sqlResult.impl.PrepSqlResultImpl;
|
import aiyh.utils.sqlUtil.sqlResult.impl.PrepSqlResultImpl;
|
||||||
import weaver.conn.RecordSet;
|
import weaver.conn.RecordSet;
|
||||||
|
import weaver.conn.RecordSetTrans;
|
||||||
|
|
||||||
import java.lang.reflect.InvocationHandler;
|
import java.lang.reflect.InvocationHandler;
|
||||||
import java.lang.reflect.Method;
|
import java.lang.reflect.Method;
|
||||||
import java.lang.reflect.Proxy;
|
import java.lang.reflect.Proxy;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author EBU7-dev1-ayh
|
* @author EBU7-dev1-ayh create 2021/12/19 0019 14:39
|
||||||
* create 2021/12/19 0019 14:39
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
public class RecordsetUtil implements InvocationHandler {
|
public class RecordsetUtil implements InvocationHandler {
|
||||||
|
|
||||||
private final RecordSet recordSet = new RecordSet();
|
|
||||||
|
public static final String SQL_LOG = "sql_log";
|
||||||
|
private final RsThreadLocalManager rsManager = new RsThreadLocalManager();
|
||||||
|
|
||||||
|
private boolean autoCommit = true;
|
||||||
|
|
||||||
public <T> T getMapper(Class<T> tClass) {
|
public <T> T getMapper(Class<T> tClass) {
|
||||||
|
return getMapper(tClass, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
public <T> T getMapper(Class<T> tClass, boolean autoCommit) {
|
||||||
if (tClass == null) {
|
if (tClass == null) {
|
||||||
throw new BindingException("class is null!");
|
throw new BindingException("class is null!");
|
||||||
}
|
}
|
||||||
if (tClass.getAnnotation(SqlMapper.class) == null) {
|
if (tClass.getAnnotation(SqlMapper.class) == null) {
|
||||||
throw new BindingException("can not find SqlMapper annotation!");
|
throw new BindingException("can not find SqlMapper annotation!");
|
||||||
}
|
}
|
||||||
|
this.autoCommit = autoCommit;
|
||||||
return (T) Proxy.newProxyInstance(tClass.getClassLoader(), new Class[]{tClass}, this);
|
return (T) Proxy.newProxyInstance(tClass.getClassLoader(), new Class[]{tClass}, this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Object invoke(Object proxy, Method method, Object[] args) {
|
public Object invoke(Object proxy, Method method, Object[] args) {
|
||||||
|
if (autoCommit) {
|
||||||
|
return invokeRs(proxy, method, args);
|
||||||
|
}
|
||||||
|
return invokeRsTrans(proxy, method, args);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
private Object invokeRs(Object proxy, Method method, Object[] args) {
|
||||||
|
RecordSet rs = rsManager.getRs(method.getDeclaringClass().getName());
|
||||||
|
if (rs == null) {
|
||||||
|
rsManager.setRecordSet(method.getDeclaringClass().getName());
|
||||||
|
rs = rsManager.getRs(method.getDeclaringClass().getName());
|
||||||
|
}
|
||||||
SqlHandler sqlHandler = new SqlHandler();
|
SqlHandler sqlHandler = new SqlHandler();
|
||||||
ResultMapper resultMapper = new ResultMapper();
|
ResultMapper resultMapper = new ResultMapper();
|
||||||
Select select = method.getAnnotation(Select.class);
|
Select select = method.getAnnotation(Select.class);
|
||||||
if (select != null) {
|
if (select != null) {
|
||||||
// 查询
|
// 查询
|
||||||
RecordSet rs = new RecordSet();
|
|
||||||
String sql = select.value();
|
String sql = select.value();
|
||||||
boolean custom = select.custom();
|
boolean custom = select.custom();
|
||||||
PrepSqlResultImpl handler = sqlHandler.handler(sql, custom, method, args);
|
PrepSqlResultImpl handler = sqlHandler.handler(sql, custom, method, args);
|
||||||
if (!handler.getSqlStr().trim().toLowerCase().startsWith("select ")) {
|
if (!handler.getSqlStr().trim().toLowerCase().startsWith("select ")) {
|
||||||
throw new CustomerException("The sql statement does not match, the @Select annotation can only getDataId the select statement, please check whether the sql statement matches!");
|
throw new CustomerException("The sql statement does not match, the @Select annotation can only getDataId the select statement, please check whether the sql statement matches!");
|
||||||
}
|
}
|
||||||
Util.getLogger("sql_log").info("解析sql===>" + handler);
|
Util.getLogger(SQL_LOG).info("解析sql===>" + handler);
|
||||||
if (handler.getArgs().isEmpty()) {
|
if (handler.getArgs().isEmpty()) {
|
||||||
rs.executeQuery(handler.getSqlStr());
|
rs.executeQuery(handler.getSqlStr());
|
||||||
} else {
|
} else {
|
||||||
|
@ -57,22 +79,21 @@ public class RecordsetUtil implements InvocationHandler {
|
||||||
return resultMapper.mapperResult(rs, method, method.getReturnType());
|
return resultMapper.mapperResult(rs, method, method.getReturnType());
|
||||||
}
|
}
|
||||||
Update update = method.getAnnotation(Update.class);
|
Update update = method.getAnnotation(Update.class);
|
||||||
|
|
||||||
if (update != null) {
|
if (update != null) {
|
||||||
// 查询
|
// 查询
|
||||||
String sql = update.value();
|
String sql = update.value();
|
||||||
boolean custom = update.custom();
|
boolean custom = update.custom();
|
||||||
PrepSqlResultImpl handler = sqlHandler.handler(sql, custom, method, args);
|
PrepSqlResultImpl handler = sqlHandler.handler(sql, custom, method, args);
|
||||||
if (!handler.getSqlStr().trim().toLowerCase().startsWith("update ")) {
|
if (!handler.getSqlStr().trim().toLowerCase().startsWith("update ")) {
|
||||||
throw new CustomerException("The sql statement does not match, the @Update annotation can only getDataId the update statement, please check whether the sql statement matches!");
|
throw new CustomerException("The sql statement does not match, the @Update annotation can only getDataId the update statement, please check whether the sql statement matches!");
|
||||||
}
|
}
|
||||||
Util.getLogger("sql_log").info(handler.toString());
|
Util.getLogger(SQL_LOG).info(handler.toString());
|
||||||
Class<?> returnType = method.getReturnType();
|
Class<?> returnType = method.getReturnType();
|
||||||
boolean b;
|
boolean b;
|
||||||
if (handler.getArgs().isEmpty()) {
|
if (handler.getArgs().isEmpty()) {
|
||||||
b = recordSet.executeUpdate(handler.getSqlStr());
|
b = rs.executeUpdate(handler.getSqlStr());
|
||||||
} else {
|
} else {
|
||||||
b = recordSet.executeUpdate(handler.getSqlStr(), handler.getArgs());
|
b = rs.executeUpdate(handler.getSqlStr(), handler.getArgs());
|
||||||
}
|
}
|
||||||
if (returnType.equals(void.class)) {
|
if (returnType.equals(void.class)) {
|
||||||
return null;
|
return null;
|
||||||
|
@ -90,20 +111,20 @@ public class RecordsetUtil implements InvocationHandler {
|
||||||
}
|
}
|
||||||
Insert insert = method.getAnnotation(Insert.class);
|
Insert insert = method.getAnnotation(Insert.class);
|
||||||
if (insert != null) {
|
if (insert != null) {
|
||||||
// 查询
|
// 查询
|
||||||
String sql = insert.value();
|
String sql = insert.value();
|
||||||
boolean custom = insert.custom();
|
boolean custom = insert.custom();
|
||||||
PrepSqlResultImpl handler = sqlHandler.handler(sql, custom, method, args);
|
PrepSqlResultImpl handler = sqlHandler.handler(sql, custom, method, args);
|
||||||
if (!handler.getSqlStr().trim().toLowerCase().startsWith("insert ")) {
|
if (!handler.getSqlStr().trim().toLowerCase().startsWith("insert ")) {
|
||||||
throw new CustomerException("The sql statement does not match, the @Insert annotation can only getDataId the insert statement, please check whether the sql statement matches!");
|
throw new CustomerException("The sql statement does not match, the @Insert annotation can only getDataId the insert statement, please check whether the sql statement matches!");
|
||||||
}
|
}
|
||||||
Util.getLogger("sql_log").info(handler.toString());
|
Util.getLogger(SQL_LOG).info(handler.toString());
|
||||||
Class<?> returnType = method.getReturnType();
|
Class<?> returnType = method.getReturnType();
|
||||||
boolean b;
|
boolean b;
|
||||||
if (handler.getArgs().isEmpty()) {
|
if (handler.getArgs().isEmpty()) {
|
||||||
b = recordSet.executeUpdate(handler.getSqlStr());
|
b = rs.executeUpdate(handler.getSqlStr());
|
||||||
} else {
|
} else {
|
||||||
b = recordSet.executeUpdate(handler.getSqlStr(), handler.getArgs());
|
b = rs.executeUpdate(handler.getSqlStr(), handler.getArgs());
|
||||||
}
|
}
|
||||||
if (returnType.equals(void.class)) {
|
if (returnType.equals(void.class)) {
|
||||||
return null;
|
return null;
|
||||||
|
@ -114,20 +135,20 @@ public class RecordsetUtil implements InvocationHandler {
|
||||||
}
|
}
|
||||||
Delete delete = method.getAnnotation(Delete.class);
|
Delete delete = method.getAnnotation(Delete.class);
|
||||||
if (delete != null) {
|
if (delete != null) {
|
||||||
// 查询
|
// 查询
|
||||||
String sql = delete.value();
|
String sql = delete.value();
|
||||||
boolean custom = delete.custom();
|
boolean custom = delete.custom();
|
||||||
PrepSqlResultImpl handler = sqlHandler.handler(sql, custom, method, args);
|
PrepSqlResultImpl handler = sqlHandler.handler(sql, custom, method, args);
|
||||||
if (!handler.getSqlStr().trim().toLowerCase().startsWith("delete ")) {
|
if (!handler.getSqlStr().trim().toLowerCase().startsWith("delete ")) {
|
||||||
throw new CustomerException("The sql statement does not match, the @Delete annotation can only getDataId the delete statement, please check whether the sql statement matches!");
|
throw new CustomerException("The sql statement does not match, the @Delete annotation can only getDataId the delete statement, please check whether the sql statement matches!");
|
||||||
}
|
}
|
||||||
Util.getLogger("sql_log").info(handler.toString());
|
Util.getLogger(SQL_LOG).info(handler.toString());
|
||||||
Class<?> returnType = method.getReturnType();
|
Class<?> returnType = method.getReturnType();
|
||||||
boolean b;
|
boolean b;
|
||||||
if (handler.getArgs().isEmpty()) {
|
if (handler.getArgs().isEmpty()) {
|
||||||
b = recordSet.executeUpdate(handler.getSqlStr());
|
b = rs.executeUpdate(handler.getSqlStr());
|
||||||
} else {
|
} else {
|
||||||
b = recordSet.executeUpdate(handler.getSqlStr(), handler.getArgs());
|
b = rs.executeUpdate(handler.getSqlStr(), handler.getArgs());
|
||||||
}
|
}
|
||||||
if (returnType.equals(void.class)) {
|
if (returnType.equals(void.class)) {
|
||||||
return null;
|
return null;
|
||||||
|
@ -143,14 +164,14 @@ public class RecordsetUtil implements InvocationHandler {
|
||||||
Class<?> returnType = method.getReturnType();
|
Class<?> returnType = method.getReturnType();
|
||||||
boolean custom = batchInsert.custom();
|
boolean custom = batchInsert.custom();
|
||||||
BatchSqlResultImpl batchSqlResult = sqlHandler.handlerBatch(sql, custom, method, args);
|
BatchSqlResultImpl batchSqlResult = sqlHandler.handlerBatch(sql, custom, method, args);
|
||||||
Util.getLogger("sql_log").info(batchSqlResult.toString());
|
Util.getLogger(SQL_LOG).info(batchSqlResult.toString());
|
||||||
if (batchSqlResult.getBatchList().isEmpty()) {
|
if (batchSqlResult.getBatchList().isEmpty()) {
|
||||||
throw new CustomerException("getDataId batch sql error , batch sql args is empty!");
|
throw new CustomerException("getDataId batch sql error , batch sql args is empty!");
|
||||||
}
|
}
|
||||||
if (!batchSqlResult.getSqlStr().trim().toLowerCase().startsWith("insert ")) {
|
if (!batchSqlResult.getSqlStr().trim().toLowerCase().startsWith("insert ")) {
|
||||||
throw new CustomerException("The sql statement does not match, the @Insert annotation can only getDataId the insert statement, please check whether the sql statement matches!");
|
throw new CustomerException("The sql statement does not match, the @Insert annotation can only getDataId the insert statement, please check whether the sql statement matches!");
|
||||||
}
|
}
|
||||||
boolean b = recordSet.executeBatchSql(batchSqlResult.getSqlStr(), batchSqlResult.getBatchList());
|
boolean b = rs.executeBatchSql(batchSqlResult.getSqlStr(), batchSqlResult.getBatchList());
|
||||||
if (returnType.equals(void.class)) {
|
if (returnType.equals(void.class)) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
@ -166,14 +187,14 @@ public class RecordsetUtil implements InvocationHandler {
|
||||||
Class<?> returnType = method.getReturnType();
|
Class<?> returnType = method.getReturnType();
|
||||||
boolean custom = batchUpdate.custom();
|
boolean custom = batchUpdate.custom();
|
||||||
BatchSqlResultImpl batchSqlResult = sqlHandler.handlerBatch(sql, custom, method, args);
|
BatchSqlResultImpl batchSqlResult = sqlHandler.handlerBatch(sql, custom, method, args);
|
||||||
Util.getLogger("sql_log").info(batchSqlResult.toString());
|
Util.getLogger(SQL_LOG).info(batchSqlResult.toString());
|
||||||
if (batchSqlResult.getBatchList().isEmpty()) {
|
if (batchSqlResult.getBatchList().isEmpty()) {
|
||||||
throw new CustomerException("getDataId batch sql error , batch sql args is empty!");
|
throw new CustomerException("getDataId batch sql error , batch sql args is empty!");
|
||||||
}
|
}
|
||||||
if (!batchSqlResult.getSqlStr().trim().toLowerCase().startsWith("update ")) {
|
if (!batchSqlResult.getSqlStr().trim().toLowerCase().startsWith("update ")) {
|
||||||
throw new CustomerException("The sql statement does not match, the @Update annotation can only getDataId the update statement, please check whether the sql statement matches!");
|
throw new CustomerException("The sql statement does not match, the @Update annotation can only getDataId the update statement, please check whether the sql statement matches!");
|
||||||
}
|
}
|
||||||
boolean b = recordSet.executeBatchSql(batchSqlResult.getSqlStr(), batchSqlResult.getBatchList());
|
boolean b = rs.executeBatchSql(batchSqlResult.getSqlStr(), batchSqlResult.getBatchList());
|
||||||
if (returnType.equals(void.class)) {
|
if (returnType.equals(void.class)) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
@ -189,14 +210,14 @@ public class RecordsetUtil implements InvocationHandler {
|
||||||
Class<?> returnType = method.getReturnType();
|
Class<?> returnType = method.getReturnType();
|
||||||
boolean custom = batchDelete.custom();
|
boolean custom = batchDelete.custom();
|
||||||
BatchSqlResultImpl batchSqlResult = sqlHandler.handlerBatch(sql, custom, method, args);
|
BatchSqlResultImpl batchSqlResult = sqlHandler.handlerBatch(sql, custom, method, args);
|
||||||
Util.getLogger("sql_log").info(batchSqlResult.toString());
|
Util.getLogger(SQL_LOG).info(batchSqlResult.toString());
|
||||||
if (batchSqlResult.getBatchList().isEmpty()) {
|
if (batchSqlResult.getBatchList().isEmpty()) {
|
||||||
throw new CustomerException("getDataId batch sql error , batch sql args is empty!");
|
throw new CustomerException("getDataId batch sql error , batch sql args is empty!");
|
||||||
}
|
}
|
||||||
if (!batchSqlResult.getSqlStr().trim().toLowerCase().startsWith("delete ")) {
|
if (!batchSqlResult.getSqlStr().trim().toLowerCase().startsWith("delete ")) {
|
||||||
throw new CustomerException("The sql statement does not match, the @Delete annotation can only getDataId the delete statement, please check whether the sql statement matches!");
|
throw new CustomerException("The sql statement does not match, the @Delete annotation can only getDataId the delete statement, please check whether the sql statement matches!");
|
||||||
}
|
}
|
||||||
boolean b = recordSet.executeBatchSql(batchSqlResult.getSqlStr(), batchSqlResult.getBatchList());
|
boolean b = rs.executeBatchSql(batchSqlResult.getSqlStr(), batchSqlResult.getBatchList());
|
||||||
if (returnType.equals(void.class)) {
|
if (returnType.equals(void.class)) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
@ -208,4 +229,255 @@ public class RecordsetUtil implements InvocationHandler {
|
||||||
throw new CustomerException("该方法没有添加注解!请检查是否正确添加注解!@Select、@Update、@Insert、@Delete、@BatchUpdate、@BatchInsert、@BatchDelete");
|
throw new CustomerException("该方法没有添加注解!请检查是否正确添加注解!@Select、@Update、@Insert、@Delete、@BatchUpdate、@BatchInsert、@BatchDelete");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private Object invokeRsTrans(Object proxy, Method method, Object[] args) {
|
||||||
|
RecordSetTrans rs = rsManager.getTrans(method.getDeclaringClass().getName());
|
||||||
|
if (rs == null) {
|
||||||
|
rsManager.setRecordSetTrans(method.getDeclaringClass().getName());
|
||||||
|
rs = rsManager.getTrans(method.getDeclaringClass().getName());
|
||||||
|
}
|
||||||
|
SqlHandler sqlHandler = new SqlHandler();
|
||||||
|
ResultMapper resultMapper = new ResultMapper();
|
||||||
|
Select select = method.getAnnotation(Select.class);
|
||||||
|
if (select != null) {
|
||||||
|
// 查询
|
||||||
|
String sql = select.value();
|
||||||
|
boolean custom = select.custom();
|
||||||
|
PrepSqlResultImpl handler = sqlHandler.handler(sql, custom, method, args);
|
||||||
|
if (!handler.getSqlStr().trim().toLowerCase().startsWith("select ")) {
|
||||||
|
throw new CustomerException("The sql statement does not match, the @Select annotation can only getDataId the select statement, please check whether the sql statement matches!");
|
||||||
|
}
|
||||||
|
Util.getLogger(SQL_LOG).info("解析sql===>" + handler);
|
||||||
|
try {
|
||||||
|
if (handler.getArgs().isEmpty()) {
|
||||||
|
rs.executeQuery(handler.getSqlStr());
|
||||||
|
} else {
|
||||||
|
rs.executeQuery(handler.getSqlStr(), handler.getArgs());
|
||||||
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
Util.getLogger(SQL_LOG).error("execute sql error! " + Util.getErrString(e));
|
||||||
|
throw new CustomerException("execute sql error!" + e.getMessage());
|
||||||
|
}
|
||||||
|
return resultMapper.mapperResult(rs, method, method.getReturnType());
|
||||||
|
}
|
||||||
|
|
||||||
|
Update update = method.getAnnotation(Update.class);
|
||||||
|
if (update != null) {
|
||||||
|
// 查询
|
||||||
|
String sql = update.value();
|
||||||
|
boolean custom = update.custom();
|
||||||
|
PrepSqlResultImpl handler = sqlHandler.handler(sql, custom, method, args);
|
||||||
|
if (!handler.getSqlStr().trim().toLowerCase().startsWith("update ")) {
|
||||||
|
throw new CustomerException("The sql statement does not match, the @Update annotation can only getDataId the update statement, please check whether the sql statement matches!");
|
||||||
|
}
|
||||||
|
Util.getLogger(SQL_LOG).info(handler.toString());
|
||||||
|
Class<?> returnType = method.getReturnType();
|
||||||
|
boolean b;
|
||||||
|
try {
|
||||||
|
if (handler.getArgs().isEmpty()) {
|
||||||
|
b = rs.executeUpdate(handler.getSqlStr());
|
||||||
|
} else {
|
||||||
|
b = rs.executeUpdate(handler.getSqlStr(), handler.getArgs());
|
||||||
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
Util.getLogger(SQL_LOG).error("execute sql error! " + Util.getErrString(e));
|
||||||
|
throw new CustomerException("execute sql error!" + e.getMessage());
|
||||||
|
}
|
||||||
|
if (returnType.equals(void.class)) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
if (returnType.equals(int.class) || returnType.equals(Integer.class)) {
|
||||||
|
if (b) {
|
||||||
|
return 1;
|
||||||
|
} else {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (returnType.equals(boolean.class) || returnType.equals(Boolean.class)) {
|
||||||
|
return b;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Insert insert = method.getAnnotation(Insert.class);
|
||||||
|
if (insert != null) {
|
||||||
|
// 查询
|
||||||
|
String sql = insert.value();
|
||||||
|
boolean custom = insert.custom();
|
||||||
|
PrepSqlResultImpl handler = sqlHandler.handler(sql, custom, method, args);
|
||||||
|
if (!handler.getSqlStr().trim().toLowerCase().startsWith("insert ")) {
|
||||||
|
throw new CustomerException("The sql statement does not match, the @Insert annotation can only getDataId the insert statement, please check whether the sql statement matches!");
|
||||||
|
}
|
||||||
|
Util.getLogger(SQL_LOG).info(handler.toString());
|
||||||
|
Class<?> returnType = method.getReturnType();
|
||||||
|
boolean b;
|
||||||
|
try {
|
||||||
|
if (handler.getArgs().isEmpty()) {
|
||||||
|
b = rs.executeUpdate(handler.getSqlStr());
|
||||||
|
} else {
|
||||||
|
b = rs.executeUpdate(handler.getSqlStr(), handler.getArgs());
|
||||||
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
Util.getLogger(SQL_LOG).error("execute sql error! " + Util.getErrString(e));
|
||||||
|
throw new CustomerException("execute sql error!" + e.getMessage());
|
||||||
|
}
|
||||||
|
if (returnType.equals(void.class)) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
if (returnType.equals(boolean.class) || returnType.equals(Boolean.class)) {
|
||||||
|
return b;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Delete delete = method.getAnnotation(Delete.class);
|
||||||
|
if (delete != null) {
|
||||||
|
// 查询
|
||||||
|
String sql = delete.value();
|
||||||
|
boolean custom = delete.custom();
|
||||||
|
PrepSqlResultImpl handler = sqlHandler.handler(sql, custom, method, args);
|
||||||
|
if (!handler.getSqlStr().trim().toLowerCase().startsWith("delete ")) {
|
||||||
|
throw new CustomerException("The sql statement does not match, the @Delete annotation can only getDataId the delete statement, please check whether the sql statement matches!");
|
||||||
|
}
|
||||||
|
Util.getLogger(SQL_LOG).info(handler.toString());
|
||||||
|
Class<?> returnType = method.getReturnType();
|
||||||
|
boolean b;
|
||||||
|
try {
|
||||||
|
if (handler.getArgs().isEmpty()) {
|
||||||
|
b = rs.executeUpdate(handler.getSqlStr());
|
||||||
|
} else {
|
||||||
|
b = rs.executeUpdate(handler.getSqlStr(), handler.getArgs());
|
||||||
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
Util.getLogger(SQL_LOG).error("execute sql error! " + Util.getErrString(e));
|
||||||
|
throw new CustomerException("execute sql error!" + e.getMessage());
|
||||||
|
}
|
||||||
|
if (returnType.equals(void.class)) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
if (returnType.equals(boolean.class) || returnType.equals(Boolean.class)) {
|
||||||
|
return b;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
boolean hasBatchInsert = method.isAnnotationPresent(BatchInsert.class);
|
||||||
|
if (hasBatchInsert) {
|
||||||
|
BatchInsert batchInsert = method.getAnnotation(BatchInsert.class);
|
||||||
|
String sql = batchInsert.value();
|
||||||
|
Class<?> returnType = method.getReturnType();
|
||||||
|
boolean custom = batchInsert.custom();
|
||||||
|
BatchSqlResultImpl batchSqlResult = sqlHandler.handlerBatch(sql, custom, method, args);
|
||||||
|
Util.getLogger(SQL_LOG).info(batchSqlResult.toString());
|
||||||
|
List<List> batchList = batchSqlResult.getBatchList();
|
||||||
|
if (batchList.isEmpty()) {
|
||||||
|
throw new CustomerException("getDataId batch sql error , batch sql args is empty!");
|
||||||
|
}
|
||||||
|
List<List<Object>> batchListTrans = new ArrayList<>();
|
||||||
|
for (List list : batchList) {
|
||||||
|
List<Object> listItem = new ArrayList<>();
|
||||||
|
for (Object o : list) {
|
||||||
|
listItem.add(o);
|
||||||
|
}
|
||||||
|
batchListTrans.add(listItem);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!batchSqlResult.getSqlStr().trim().toLowerCase().startsWith("insert ")) {
|
||||||
|
throw new CustomerException("The sql statement does not match, the @Insert annotation can only getDataId the insert statement, please check whether the sql statement matches!");
|
||||||
|
}
|
||||||
|
boolean b = true;
|
||||||
|
try {
|
||||||
|
rs.executeBatchSql(batchSqlResult.getSqlStr(), batchListTrans);
|
||||||
|
} catch (Exception e) {
|
||||||
|
Util.getLogger(SQL_LOG).error("execute sql error! " + Util.getErrString(e));
|
||||||
|
throw new CustomerException("execute sql error!" + e.getMessage());
|
||||||
|
}
|
||||||
|
if (returnType.equals(void.class)) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
if (returnType.equals(boolean.class) || returnType.equals(Boolean.class)) {
|
||||||
|
return b;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
boolean hasBatchUpdate = method.isAnnotationPresent(BatchUpdate.class);
|
||||||
|
if (hasBatchUpdate) {
|
||||||
|
BatchUpdate batchUpdate = method.getAnnotation(BatchUpdate.class);
|
||||||
|
String sql = batchUpdate.value();
|
||||||
|
Class<?> returnType = method.getReturnType();
|
||||||
|
boolean custom = batchUpdate.custom();
|
||||||
|
BatchSqlResultImpl batchSqlResult = sqlHandler.handlerBatch(sql, custom, method, args);
|
||||||
|
Util.getLogger(SQL_LOG).info(batchSqlResult.toString());
|
||||||
|
if (batchSqlResult.getBatchList().isEmpty()) {
|
||||||
|
throw new CustomerException("getDataId batch sql error , batch sql args is empty!");
|
||||||
|
}
|
||||||
|
if (!batchSqlResult.getSqlStr().trim().toLowerCase().startsWith("update ")) {
|
||||||
|
throw new CustomerException("The sql statement does not match, the @Update annotation can only getDataId the update statement, please check whether the sql statement matches!");
|
||||||
|
}
|
||||||
|
|
||||||
|
List<List> batchList = batchSqlResult.getBatchList();
|
||||||
|
if (batchList.isEmpty()) {
|
||||||
|
throw new CustomerException("getDataId batch sql error , batch sql args is empty!");
|
||||||
|
}
|
||||||
|
List<List<Object>> batchListTrans = new ArrayList<>();
|
||||||
|
for (List list : batchList) {
|
||||||
|
List<Object> listItem = new ArrayList<>();
|
||||||
|
for (Object o : list) {
|
||||||
|
listItem.add(o);
|
||||||
|
}
|
||||||
|
batchListTrans.add(listItem);
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
rs.executeBatchSql(batchSqlResult.getSqlStr(), batchListTrans);
|
||||||
|
} catch (Exception e) {
|
||||||
|
Util.getLogger(SQL_LOG).error("execute sql error! " + Util.getErrString(e));
|
||||||
|
throw new CustomerException("execute sql error!" + e.getMessage());
|
||||||
|
}
|
||||||
|
if (returnType.equals(void.class)) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
if (returnType.equals(boolean.class) || returnType.equals(Boolean.class)) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
boolean hasBatchDelete = method.isAnnotationPresent(BatchDelete.class);
|
||||||
|
if (hasBatchDelete) {
|
||||||
|
BatchDelete batchDelete = method.getAnnotation(BatchDelete.class);
|
||||||
|
String sql = batchDelete.value();
|
||||||
|
Class<?> returnType = method.getReturnType();
|
||||||
|
boolean custom = batchDelete.custom();
|
||||||
|
BatchSqlResultImpl batchSqlResult = sqlHandler.handlerBatch(sql, custom, method, args);
|
||||||
|
Util.getLogger(SQL_LOG).info(batchSqlResult.toString());
|
||||||
|
if (batchSqlResult.getBatchList().isEmpty()) {
|
||||||
|
throw new CustomerException("getDataId batch sql error , batch sql args is empty!");
|
||||||
|
}
|
||||||
|
if (!batchSqlResult.getSqlStr().trim().toLowerCase().startsWith("delete ")) {
|
||||||
|
throw new CustomerException("The sql statement does not match, the @Delete annotation can only getDataId the delete statement, please check whether the sql statement matches!");
|
||||||
|
}
|
||||||
|
List<List> batchList = batchSqlResult.getBatchList();
|
||||||
|
if (batchList.isEmpty()) {
|
||||||
|
throw new CustomerException("getDataId batch sql error , batch sql args is empty!");
|
||||||
|
}
|
||||||
|
List<List<Object>> batchListTrans = new ArrayList<>();
|
||||||
|
for (List list : batchList) {
|
||||||
|
List<Object> listItem = new ArrayList<>();
|
||||||
|
for (Object o : list) {
|
||||||
|
listItem.add(o);
|
||||||
|
}
|
||||||
|
batchListTrans.add(listItem);
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
rs.executeBatchSql(batchSqlResult.getSqlStr(), batchListTrans);
|
||||||
|
} catch (Exception e) {
|
||||||
|
Util.getLogger(SQL_LOG).error("execute sql error! " + Util.getErrString(e));
|
||||||
|
throw new CustomerException("execute sql error!" + e.getMessage());
|
||||||
|
}
|
||||||
|
if (returnType.equals(void.class)) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
if (returnType.equals(boolean.class) || returnType.equals(Boolean.class)) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
throw new CustomerException("该方法没有添加注解!请检查是否正确添加注解!@Select、@Update、@Insert、@Delete、@BatchUpdate、@BatchInsert、@BatchDelete");
|
||||||
|
}
|
||||||
|
|
||||||
|
public RsThreadLocalManager getRsManager() {
|
||||||
|
return rsManager;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -15,8 +15,7 @@ import java.lang.reflect.*;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author EBU7-dev1-ayh
|
* @author EBU7-dev1-ayh create 2021/12/21 0021 11:03
|
||||||
* create 2021/12/21 0021 11:03
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
@ -60,7 +59,7 @@ public class ResultMapper {
|
||||||
}
|
}
|
||||||
T t = tClass.newInstance();
|
T t = tClass.newInstance();
|
||||||
if (t instanceof Collection) {
|
if (t instanceof Collection) {
|
||||||
// 集合求出泛型
|
// 集合求出泛型
|
||||||
//获取返回值的类型
|
//获取返回值的类型
|
||||||
Type genericReturnType = method.getGenericReturnType();
|
Type genericReturnType = method.getGenericReturnType();
|
||||||
Type actualTypeArgument = ((ParameterizedType) genericReturnType).getActualTypeArguments()[0];
|
Type actualTypeArgument = ((ParameterizedType) genericReturnType).getActualTypeArguments()[0];
|
||||||
|
@ -93,7 +92,7 @@ public class ResultMapper {
|
||||||
return t;
|
return t;
|
||||||
}
|
}
|
||||||
if (t instanceof Map) {
|
if (t instanceof Map) {
|
||||||
// map
|
// map
|
||||||
Type genericReturnType = method.getGenericReturnType();
|
Type genericReturnType = method.getGenericReturnType();
|
||||||
Type actualTypeArgument = ((ParameterizedType) genericReturnType).getActualTypeArguments()[0];
|
Type actualTypeArgument = ((ParameterizedType) genericReturnType).getActualTypeArguments()[0];
|
||||||
Class<?> rawType = this.getRawType(actualTypeArgument);
|
Class<?> rawType = this.getRawType(actualTypeArgument);
|
||||||
|
@ -103,7 +102,7 @@ public class ResultMapper {
|
||||||
if (rawType.equals(Map.class)) {
|
if (rawType.equals(Map.class)) {
|
||||||
rawType = HashMap.class;
|
rawType = HashMap.class;
|
||||||
}
|
}
|
||||||
// Object o = rawType.newInstance();
|
// Object o = rawType.newInstance();
|
||||||
Object o = null;
|
Object o = null;
|
||||||
try {
|
try {
|
||||||
Constructor<?> constructor = rawType.getConstructor();
|
Constructor<?> constructor = rawType.getConstructor();
|
||||||
|
@ -143,6 +142,222 @@ public class ResultMapper {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public <T> T mapperResult(RecordSetTrans rs, Method method, Class<T> tClass) {
|
||||||
|
if (tClass.equals(void.class)) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
if (tClass.equals(RecordSet.class) || tClass.equals(RecordSetTrans.class)) {
|
||||||
|
return (T) rs;
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
if (tClass.equals(List.class)) {
|
||||||
|
tClass = (Class<T>) ArrayList.class;
|
||||||
|
}
|
||||||
|
if (tClass.equals(Map.class)) {
|
||||||
|
tClass = (Class<T>) HashMap.class;
|
||||||
|
}
|
||||||
|
if (ResultMapper.typeHandler.containsKey(tClass)) {
|
||||||
|
rs.next();
|
||||||
|
return (T) ResultMapper.typeHandler.get(tClass).getValue(rs, 1, null);
|
||||||
|
}
|
||||||
|
T t = tClass.newInstance();
|
||||||
|
if (t instanceof Collection) {
|
||||||
|
// 集合求出泛型
|
||||||
|
//获取返回值的类型
|
||||||
|
Type genericReturnType = method.getGenericReturnType();
|
||||||
|
Type actualTypeArgument = ((ParameterizedType) genericReturnType).getActualTypeArguments()[0];
|
||||||
|
Class<?> rawType = this.getRawType(actualTypeArgument);
|
||||||
|
if (rawType.equals(Map.class)) {
|
||||||
|
rawType = HashMap.class;
|
||||||
|
}
|
||||||
|
while (rs.next()) {
|
||||||
|
Object o = null;
|
||||||
|
try {
|
||||||
|
Constructor<?> constructor = rawType.getConstructor();
|
||||||
|
o = constructor.newInstance();
|
||||||
|
} catch (NoSuchMethodException | InvocationTargetException ignored) {
|
||||||
|
if (Number.class.isAssignableFrom(rawType)) {
|
||||||
|
Constructor<?> constructor;
|
||||||
|
try {
|
||||||
|
constructor = rawType.getConstructor(String.class);
|
||||||
|
o = constructor.newInstance("-1");
|
||||||
|
} catch (NoSuchMethodException | InvocationTargetException e) {
|
||||||
|
throw new CustomerException("can not Initialization " + t.getClass() + " [" + rawType + "]", e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (o == null) {
|
||||||
|
throw new CustomerException("can not Initialization " + t.getClass() + " [" + rawType + "]");
|
||||||
|
}
|
||||||
|
Object object = getObjectTrans(rs, o, method);
|
||||||
|
((Collection<? super Object>) t).add(object);
|
||||||
|
}
|
||||||
|
return t;
|
||||||
|
}
|
||||||
|
if (t instanceof Map) {
|
||||||
|
// map
|
||||||
|
Type genericReturnType = method.getGenericReturnType();
|
||||||
|
Type actualTypeArgument = ((ParameterizedType) genericReturnType).getActualTypeArguments()[0];
|
||||||
|
Class<?> rawType = this.getRawType(actualTypeArgument);
|
||||||
|
if (rawType.equals(List.class)) {
|
||||||
|
rawType = (Class<T>) ArrayList.class;
|
||||||
|
}
|
||||||
|
if (rawType.equals(Map.class)) {
|
||||||
|
rawType = HashMap.class;
|
||||||
|
}
|
||||||
|
// Object o = rawType.newInstance();
|
||||||
|
Object o = null;
|
||||||
|
try {
|
||||||
|
Constructor<?> constructor = rawType.getConstructor();
|
||||||
|
o = constructor.newInstance();
|
||||||
|
} catch (NoSuchMethodException | InvocationTargetException ignored) {
|
||||||
|
if (Number.class.isAssignableFrom(rawType)) {
|
||||||
|
Constructor<?> constructor;
|
||||||
|
try {
|
||||||
|
constructor = rawType.getConstructor(String.class);
|
||||||
|
o = constructor.newInstance("-1");
|
||||||
|
} catch (NoSuchMethodException | InvocationTargetException e) {
|
||||||
|
throw new CustomerException("can not Initialization " + t.getClass() + " [" + rawType + "]", e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (o == null) {
|
||||||
|
throw new CustomerException("can not Initialization " + t.getClass() + " [" + rawType + "]");
|
||||||
|
}
|
||||||
|
if (o instanceof Map || o instanceof Collection) {
|
||||||
|
throw new TypeNonsupportException("An unsupported return type!");
|
||||||
|
}
|
||||||
|
if (rs.next()) {
|
||||||
|
return (T) getObjectTrans(rs, t, method);
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
if (t.getClass().isArray()) {
|
||||||
|
throw new TypeNonsupportException("An unsupported return type!");
|
||||||
|
}
|
||||||
|
if (rs.next()) {
|
||||||
|
return (T) getObjectTrans(rs, t, method);
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
} catch (InstantiationException | IllegalAccessException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Object getObjectTrans(RecordSetTrans rs, Object o, Method method) {
|
||||||
|
CaseConversion annotation = method.getAnnotation(CaseConversion.class);
|
||||||
|
boolean enable = annotation == null ? true : annotation.value();
|
||||||
|
String[] columnName = rs.getColumnName();
|
||||||
|
String[] columnTypeName = rs.getColumnTypeName();
|
||||||
|
int[] columnTypes = rs.getColumnType();
|
||||||
|
if (columnTypeName == null) {
|
||||||
|
columnTypeName = new String[columnTypes.length];
|
||||||
|
for (int i = 0; i < columnTypes.length; i++) {
|
||||||
|
int type = columnTypes[i];
|
||||||
|
switch (type) {
|
||||||
|
case -1:
|
||||||
|
columnTypeName[i] = "TEXT";
|
||||||
|
break;
|
||||||
|
case 4:
|
||||||
|
columnTypeName[i] = "INT";
|
||||||
|
break;
|
||||||
|
case 12:
|
||||||
|
columnTypeName[i] = "VARCHAR";
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
columnTypeName[i] = "VARCHAR";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
if (o instanceof Map) {
|
||||||
|
for (int i = 0; i < columnName.length; i++) {
|
||||||
|
String columnType = columnTypeName[i];
|
||||||
|
if ("int".equalsIgnoreCase(columnType) || "long".equalsIgnoreCase(columnType) || "number".equalsIgnoreCase(columnType) || "MEDIUMINT".equalsIgnoreCase(columnType) || "TINYINT".equalsIgnoreCase(columnType) || "SMALLINT".equalsIgnoreCase(columnType) || "BIGINT".equalsIgnoreCase(columnType) || "INTEGER".equalsIgnoreCase(columnType)) {
|
||||||
|
if (enable) {
|
||||||
|
((Map<? super Object, ? super Object>) o).put(Util.toCamelCase(columnName[i]), rs.getInt(i + 1));
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
((Map<? super Object, ? super Object>) o).put(columnName[i], rs.getInt(i + 1));
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if ("FLOAT".equalsIgnoreCase(columnType) || "DOUBLE".equalsIgnoreCase(columnType) || "DECIMAL".equalsIgnoreCase(columnType)) {
|
||||||
|
if (enable) {
|
||||||
|
((Map<? super Object, ? super Object>) o).put(Util.toCamelCase(columnName[i]), rs.getFloat(i + 1));
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
((Map<? super Object, ? super Object>) o).put(columnName[i], rs.getFloat(i + 1));
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if (enable) {
|
||||||
|
((Map<? super Object, ? super Object>) o).put(Util.toCamelCase(columnName[i]), rs.getString(i + 1));
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
((Map<? super Object, ? super Object>) o).put(columnName[i], rs.getString(i + 1));
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
return o;
|
||||||
|
}
|
||||||
|
if (o instanceof Collection) {
|
||||||
|
throw new TypeNonsupportException("An unsupported return type!");
|
||||||
|
}
|
||||||
|
if (o instanceof Number) {
|
||||||
|
for (int i = 0; i < columnName.length; i++) {
|
||||||
|
String columnType = columnTypeName[i];
|
||||||
|
if ("int".equalsIgnoreCase(columnType) || "long".equalsIgnoreCase(columnType) || "number".equalsIgnoreCase(columnType) || "MEDIUMINT".equalsIgnoreCase(columnType) || "TINYINT".equalsIgnoreCase(columnType) || "SMALLINT".equalsIgnoreCase(columnType) || "BIGINT".equalsIgnoreCase(columnType) || "INTEGER".equalsIgnoreCase(columnType)) {
|
||||||
|
return rs.getInt(i + 1);
|
||||||
|
}
|
||||||
|
if ("FLOAT".equalsIgnoreCase(columnType) || "DOUBLE".equalsIgnoreCase(columnType) || "DECIMAL".equalsIgnoreCase(columnType)) {
|
||||||
|
return rs.getFloat(i + 1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return o;
|
||||||
|
}
|
||||||
|
if (o instanceof String) {
|
||||||
|
for (int i = 0; i < columnName.length; i++) {
|
||||||
|
return rs.getString(i + 1);
|
||||||
|
}
|
||||||
|
return o;
|
||||||
|
}
|
||||||
|
if (o instanceof Boolean) {
|
||||||
|
for (int i = 0; i < columnName.length; i++) {
|
||||||
|
return rs.getBoolean(i + 1);
|
||||||
|
}
|
||||||
|
return o;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Util.getLogger().info("获取对象:" + o.toString());
|
||||||
|
BeanInfo beanInfo = Introspector.getBeanInfo(o.getClass(), Object.class);
|
||||||
|
PropertyDescriptor[] propertyDescriptors = beanInfo.getPropertyDescriptors();
|
||||||
|
for (PropertyDescriptor propertyDescriptor : propertyDescriptors) {
|
||||||
|
Class<?> propertyType = propertyDescriptor.getPropertyType();
|
||||||
|
Object value = null;
|
||||||
|
String fieldName = propertyDescriptor.getName();
|
||||||
|
|
||||||
|
if (Strings.isNullOrEmpty(fieldName)) {
|
||||||
|
fieldName = propertyDescriptor.getDisplayName();
|
||||||
|
}
|
||||||
|
// Util.getLogger().info("获取类字段:" + fieldName);
|
||||||
|
// Util.getLogger().info("获取类字段1:" + propertyDescriptor.getDisplayName());
|
||||||
|
// Util.getLogger().info("获取的数据库数据:" + rs.getString(fieldName));
|
||||||
|
Field declaredField = o.getClass().getDeclaredField(fieldName);
|
||||||
|
if (enable) {
|
||||||
|
value = ResultMapper.typeHandler.get(propertyType) == null ? null : ResultMapper.typeHandler.get(propertyType).getValue(rs, Util.toUnderlineCase(fieldName), declaredField);
|
||||||
|
} else {
|
||||||
|
value = ResultMapper.typeHandler.get(propertyType) == null ? null : ResultMapper.typeHandler.get(propertyType).getValue(rs, fieldName, declaredField);
|
||||||
|
}
|
||||||
|
propertyDescriptor.getWriteMethod().invoke(o, value);
|
||||||
|
}
|
||||||
|
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
Util.getLogger().error("报错了,写入数据到实体类报错!\n" + Util.getErrString(e));
|
||||||
|
}
|
||||||
|
return o;
|
||||||
|
}
|
||||||
|
|
||||||
public Object getObject(RecordSet rs, Object o, Method method) {
|
public Object getObject(RecordSet rs, Object o, Method method) {
|
||||||
CaseConversion annotation = method.getAnnotation(CaseConversion.class);
|
CaseConversion annotation = method.getAnnotation(CaseConversion.class);
|
||||||
boolean enable = annotation == null ? true : annotation.value();
|
boolean enable = annotation == null ? true : annotation.value();
|
||||||
|
@ -226,7 +441,7 @@ public class ResultMapper {
|
||||||
return o;
|
return o;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Util.getLogger().info("获取对象:" + o.toString());
|
// Util.getLogger().info("获取对象:" + o.toString());
|
||||||
BeanInfo beanInfo = Introspector.getBeanInfo(o.getClass(), Object.class);
|
BeanInfo beanInfo = Introspector.getBeanInfo(o.getClass(), Object.class);
|
||||||
PropertyDescriptor[] propertyDescriptors = beanInfo.getPropertyDescriptors();
|
PropertyDescriptor[] propertyDescriptors = beanInfo.getPropertyDescriptors();
|
||||||
for (PropertyDescriptor propertyDescriptor : propertyDescriptors) {
|
for (PropertyDescriptor propertyDescriptor : propertyDescriptors) {
|
||||||
|
@ -237,9 +452,9 @@ public class ResultMapper {
|
||||||
if (Strings.isNullOrEmpty(fieldName)) {
|
if (Strings.isNullOrEmpty(fieldName)) {
|
||||||
fieldName = propertyDescriptor.getDisplayName();
|
fieldName = propertyDescriptor.getDisplayName();
|
||||||
}
|
}
|
||||||
// Util.getLogger().info("获取类字段:" + fieldName);
|
// Util.getLogger().info("获取类字段:" + fieldName);
|
||||||
// Util.getLogger().info("获取类字段1:" + propertyDescriptor.getDisplayName());
|
// Util.getLogger().info("获取类字段1:" + propertyDescriptor.getDisplayName());
|
||||||
// Util.getLogger().info("获取的数据库数据:" + rs.getString(fieldName));
|
// Util.getLogger().info("获取的数据库数据:" + rs.getString(fieldName));
|
||||||
Field declaredField = o.getClass().getDeclaredField(fieldName);
|
Field declaredField = o.getClass().getDeclaredField(fieldName);
|
||||||
if (enable) {
|
if (enable) {
|
||||||
value = ResultMapper.typeHandler.get(propertyType) == null ? null : ResultMapper.typeHandler.get(propertyType).getValue(rs, Util.toUnderlineCase(fieldName), declaredField);
|
value = ResultMapper.typeHandler.get(propertyType) == null ? null : ResultMapper.typeHandler.get(propertyType).getValue(rs, Util.toUnderlineCase(fieldName), declaredField);
|
||||||
|
|
|
@ -0,0 +1,238 @@
|
||||||
|
package aiyh.utils.recordset;
|
||||||
|
|
||||||
|
import aiyh.utils.excention.CustomerException;
|
||||||
|
import weaver.conn.RecordSet;
|
||||||
|
import weaver.conn.RecordSetTrans;
|
||||||
|
|
||||||
|
import java.util.Iterator;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.Objects;
|
||||||
|
import java.util.concurrent.ConcurrentHashMap;
|
||||||
|
import java.util.concurrent.Executors;
|
||||||
|
import java.util.concurrent.ScheduledExecutorService;
|
||||||
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* <h1>ThreadLocal管理类</h1>
|
||||||
|
*
|
||||||
|
* <p>create: 2022-12-21 21:31</p>
|
||||||
|
*
|
||||||
|
* @author youHong.ai
|
||||||
|
*/
|
||||||
|
|
||||||
|
public class RsThreadLocalManager {
|
||||||
|
|
||||||
|
private static final ConcurrentHashMap<Long, Map<String, RsThreadLocalMap>> rsMap = new ConcurrentHashMap<>();
|
||||||
|
|
||||||
|
private final ScheduledExecutorService executor = Executors.newSingleThreadScheduledExecutor();
|
||||||
|
|
||||||
|
public RsThreadLocalManager() {
|
||||||
|
startMonitor();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* <h2>定时清除过期的rs对象</h2>
|
||||||
|
* <i>2022/12/21 22:02</i>
|
||||||
|
* ************************************************************
|
||||||
|
*
|
||||||
|
* @author youHong.ai ******************************************
|
||||||
|
*/
|
||||||
|
private void startMonitor() {
|
||||||
|
executor.scheduleAtFixedRate(this::checkExpireRs, 0, 2, TimeUnit.MINUTES);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* <h2>checkExpireRs 检查清除过期的rs对象</h2>
|
||||||
|
* <i>2022/12/21 22:02</i>
|
||||||
|
* ************************************************************
|
||||||
|
*
|
||||||
|
* @author youHong.ai ******************************************
|
||||||
|
*/
|
||||||
|
private void checkExpireRs() {
|
||||||
|
Iterator<Map.Entry<Long, Map<String, RsThreadLocalMap>>> iterator = rsMap.entrySet().iterator();
|
||||||
|
while (iterator.hasNext()) {
|
||||||
|
Map.Entry<Long, Map<String, RsThreadLocalMap>> entity = iterator.next();
|
||||||
|
Map<String, RsThreadLocalMap> map = entity.getValue();
|
||||||
|
Iterator<Map.Entry<String, RsThreadLocalMap>> mapIterator = map.entrySet().iterator();
|
||||||
|
while (mapIterator.hasNext()) {
|
||||||
|
Map.Entry<String, RsThreadLocalMap> mapEntity = mapIterator.next();
|
||||||
|
RsThreadLocalMap value = mapEntity.getValue();
|
||||||
|
if (System.currentTimeMillis() >= value.getExpireTime() || value.getExpireTime() != -1) {
|
||||||
|
mapIterator.remove();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (map.isEmpty()) {
|
||||||
|
iterator.remove();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* <h2>setRecordSet 设置当前线程的rs对象</h2>
|
||||||
|
* <i>2022/12/21 22:03</i>
|
||||||
|
* ************************************************************
|
||||||
|
*
|
||||||
|
* @author youHong.ai ******************************************
|
||||||
|
*/
|
||||||
|
public void setRecordSet(String className) {
|
||||||
|
RsThreadLocalMap rsThreadLocalMap = new RsThreadLocalMap(new RecordSet(), getExpireTime());
|
||||||
|
setRecordSetOrTrans(className, rsThreadLocalMap);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void setRecordSetOrTrans(String className, RsThreadLocalMap rsThreadLocalMap) {
|
||||||
|
Map<String, RsThreadLocalMap> map = rsMap.get(Thread.currentThread().getId());
|
||||||
|
if (Objects.isNull(map)) {
|
||||||
|
map = new ConcurrentHashMap<>();
|
||||||
|
}
|
||||||
|
map.put(className, rsThreadLocalMap);
|
||||||
|
rsMap.put(Thread.currentThread().getId(), map);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* <h2>setRecordSet 设置当前线程的事务对象</h2>
|
||||||
|
* <i>2022/12/21 22:03</i>
|
||||||
|
* ************************************************************
|
||||||
|
*
|
||||||
|
* @author youHong.ai ******************************************
|
||||||
|
*/
|
||||||
|
public void setRecordSetTrans(String className) {
|
||||||
|
RecordSetTrans recordSetTrans = new RecordSetTrans();
|
||||||
|
recordSetTrans.setAutoCommit(false);
|
||||||
|
RsThreadLocalMap rsThreadLocalMap = new RsThreadLocalMap(recordSetTrans, -1L);
|
||||||
|
setRecordSetOrTrans(className, rsThreadLocalMap);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* <h2>getExpireTime 获取过期时间</h2>
|
||||||
|
* <i>2022/12/21 22:06</i>
|
||||||
|
* ************************************************************
|
||||||
|
*
|
||||||
|
* @return Long
|
||||||
|
* @author youHong.ai ******************************************
|
||||||
|
*/
|
||||||
|
public Long getExpireTime() {
|
||||||
|
return System.currentTimeMillis() + 1000L * 60 * 3;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* <h2>getRs 获取当前线程的rs对象</h2>
|
||||||
|
* <i>2022/12/21 22:04</i>
|
||||||
|
* ************************************************************
|
||||||
|
*
|
||||||
|
* @return RecordSet
|
||||||
|
* @author youHong.ai ******************************************
|
||||||
|
*/
|
||||||
|
public RecordSet getRs(String className) {
|
||||||
|
Map<String, RsThreadLocalMap> map = rsMap.get(Thread.currentThread().getId());
|
||||||
|
if (Objects.isNull(map)) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
RsThreadLocalMap rsThreadLocalMap = map.get(className);
|
||||||
|
if (Objects.isNull(rsThreadLocalMap)) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
rsThreadLocalMap.setExpireTime(getExpireTime());
|
||||||
|
return rsThreadLocalMap.getRecordSet();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* <h2>getTrans 获取当前线程的事务rs</h2>
|
||||||
|
* <i>2022/12/21 22:04</i>
|
||||||
|
* ************************************************************
|
||||||
|
*
|
||||||
|
* @return RecordSetTrans 事务rs
|
||||||
|
* @author youHong.ai ******************************************
|
||||||
|
*/
|
||||||
|
public RecordSetTrans getTrans(String className) {
|
||||||
|
Map<String, RsThreadLocalMap> map = rsMap.get(Thread.currentThread().getId());
|
||||||
|
if (Objects.isNull(map)) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
RsThreadLocalMap rsThreadLocalMap = map.get(className);
|
||||||
|
if (Objects.isNull(rsThreadLocalMap)) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
rsThreadLocalMap.setExpireTime(-1L);
|
||||||
|
return rsThreadLocalMap.getRecordSetTrans();
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean commit(String className) {
|
||||||
|
RecordSetTrans recordSetTrans = getRecordSetTrans(className);
|
||||||
|
return recordSetTrans.commit();
|
||||||
|
}
|
||||||
|
|
||||||
|
private RecordSetTrans getRecordSetTrans(String className) {
|
||||||
|
Map<String, RsThreadLocalMap> map = rsMap.get(Thread.currentThread().getId());
|
||||||
|
if (Objects.isNull(map)) {
|
||||||
|
throw new CustomerException("can not find RecordSetTrans instance! please Contact the developer of RecordsetUtil.java!");
|
||||||
|
}
|
||||||
|
RsThreadLocalMap rsThreadLocalMap = map.get(className);
|
||||||
|
if (Objects.isNull(rsThreadLocalMap)) {
|
||||||
|
throw new CustomerException("can not find RecordSetTrans instance! please Contact the developer of RecordsetUtil.java!");
|
||||||
|
}
|
||||||
|
rsThreadLocalMap.setExpireTime(getExpireTime());
|
||||||
|
RecordSetTrans recordSetTrans = rsThreadLocalMap.getRecordSetTrans();
|
||||||
|
return recordSetTrans;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public boolean rollback(String className) {
|
||||||
|
RecordSetTrans recordSetTrans = getRecordSetTrans(className);
|
||||||
|
return recordSetTrans.rollback();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* <h2>remove 删除当前线程的rs对象</h2>
|
||||||
|
* <i>2022/12/21 22:05</i>
|
||||||
|
* ************************************************************
|
||||||
|
*
|
||||||
|
* @author youHong.ai ******************************************
|
||||||
|
*/
|
||||||
|
public void remove() {
|
||||||
|
rsMap.remove(Thread.currentThread().getId());
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
static class RsThreadLocalMap {
|
||||||
|
private RecordSet recordSet;
|
||||||
|
|
||||||
|
private RecordSetTrans recordSetTrans;
|
||||||
|
private Long expireTime;
|
||||||
|
|
||||||
|
public RsThreadLocalMap(RecordSet recordSet, Long expireTime) {
|
||||||
|
this.recordSet = recordSet;
|
||||||
|
this.expireTime = expireTime;
|
||||||
|
}
|
||||||
|
|
||||||
|
public RsThreadLocalMap(RecordSetTrans recordSetTrans, Long expireTime) {
|
||||||
|
this.recordSetTrans = recordSetTrans;
|
||||||
|
this.expireTime = expireTime;
|
||||||
|
}
|
||||||
|
|
||||||
|
public RecordSetTrans getRecordSetTrans() {
|
||||||
|
return recordSetTrans;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setRecordSetTrans(RecordSetTrans recordSetTrans) {
|
||||||
|
this.recordSetTrans = recordSetTrans;
|
||||||
|
}
|
||||||
|
|
||||||
|
public RecordSet getRecordSet() {
|
||||||
|
return recordSet;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setRecordSet(RecordSet recordSet) {
|
||||||
|
this.recordSet = recordSet;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Long getExpireTime() {
|
||||||
|
return expireTime;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setExpireTime(Long expireTime) {
|
||||||
|
this.expireTime = expireTime;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,23 +1,33 @@
|
||||||
package aiyh.utils.recordset;
|
package aiyh.utils.recordset;
|
||||||
|
|
||||||
import weaver.conn.RecordSet;
|
import weaver.conn.RecordSet;
|
||||||
|
import weaver.conn.RecordSetTrans;
|
||||||
|
|
||||||
import java.lang.reflect.Field;
|
import java.lang.reflect.Field;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author EBU7-dev1-ayh
|
* @author EBU7-dev1-ayh create 2021/12/21 0021 13:06
|
||||||
* create 2021/12/21 0021 13:06
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
public class StringTypeHandler implements TypeHandler{
|
public class StringTypeHandler implements TypeHandler {
|
||||||
@Override
|
@Override
|
||||||
public Object getValue(RecordSet rs, String fieldName, Field declaredField) {
|
public Object getValue(RecordSet rs, String fieldName, Field declaredField) {
|
||||||
return rs.getString(fieldName);
|
return rs.getString(fieldName);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Object getValue(RecordSet rs, int index,Field declaredField) {
|
public Object getValue(RecordSet rs, int index, Field declaredField) {
|
||||||
|
return rs.getString(index);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Object getValue(RecordSetTrans rs, String fieldName, Field declaredField) {
|
||||||
|
return rs.getString(fieldName);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Object getValue(RecordSetTrans rs, int index, Field declaredField) {
|
||||||
return rs.getString(index);
|
return rs.getString(index);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,15 +1,20 @@
|
||||||
package aiyh.utils.recordset;
|
package aiyh.utils.recordset;
|
||||||
|
|
||||||
import weaver.conn.RecordSet;
|
import weaver.conn.RecordSet;
|
||||||
|
import weaver.conn.RecordSetTrans;
|
||||||
|
|
||||||
import java.lang.reflect.Field;
|
import java.lang.reflect.Field;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author @author EBU7-dev1-ay
|
* @author @author EBU7-dev1-ay create 2021/12/21 0021 13:05
|
||||||
* create 2021/12/21 0021 13:05
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
public interface TypeHandler {
|
public interface TypeHandler {
|
||||||
Object getValue(RecordSet rs, String fieldName, Field declaredField);
|
Object getValue(RecordSet rs, String fieldName, Field declaredField);
|
||||||
Object getValue(RecordSet rs,int index,Field declaredField);
|
|
||||||
|
Object getValue(RecordSet rs, int index, Field declaredField);
|
||||||
|
|
||||||
|
Object getValue(RecordSetTrans rs, String fieldName, Field declaredField);
|
||||||
|
|
||||||
|
Object getValue(RecordSetTrans rs, int index, Field declaredField);
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,44 @@
|
||||||
|
package com.api.xuanran.wang.ambofo.checkuser.controller;
|
||||||
|
|
||||||
|
import aiyh.utils.ApiResult;
|
||||||
|
import aiyh.utils.Util;
|
||||||
|
import com.api.xuanran.wang.ambofo.checkuser.service.CheckUserService;
|
||||||
|
import org.apache.log4j.Logger;
|
||||||
|
|
||||||
|
import javax.servlet.http.HttpServletRequest;
|
||||||
|
import javax.servlet.http.HttpServletResponse;
|
||||||
|
import javax.ws.rs.GET;
|
||||||
|
import javax.ws.rs.POST;
|
||||||
|
import javax.ws.rs.Path;
|
||||||
|
import javax.ws.rs.Produces;
|
||||||
|
import javax.ws.rs.core.Context;
|
||||||
|
import javax.ws.rs.core.MediaType;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* <h1>安波福从AD域中校验用户是否存在</h1>
|
||||||
|
*
|
||||||
|
* @Author xuanran.wang
|
||||||
|
* @Date 2022/12/12 14:24
|
||||||
|
*/
|
||||||
|
@Path("/wxr/ambofo/")
|
||||||
|
public class CheckUserController {
|
||||||
|
|
||||||
|
private final Logger log = Util.getLogger();
|
||||||
|
|
||||||
|
@Path("checkUser")
|
||||||
|
@POST
|
||||||
|
@Produces(MediaType.TEXT_PLAIN)
|
||||||
|
public String checkUser(@Context HttpServletRequest request, @Context HttpServletResponse response) {
|
||||||
|
String checkContent = request.getParameter("checkContent");
|
||||||
|
try {
|
||||||
|
CheckUserService checkUserService = new CheckUserService();
|
||||||
|
boolean has = checkUserService.checkADHasUser(checkContent);
|
||||||
|
return ApiResult.success(has,"ok");
|
||||||
|
}catch (Exception e){
|
||||||
|
String error = Util.logStr("AD查询接口发生异常:{}", e.getMessage());
|
||||||
|
log.error(error);
|
||||||
|
log.error(Util.getErrString(e));
|
||||||
|
return ApiResult.error(500, error);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,156 @@
|
||||||
|
package com.api.xuanran.wang.ambofo.checkuser.service;
|
||||||
|
|
||||||
|
|
||||||
|
import aiyh.utils.Util;
|
||||||
|
import aiyh.utils.excention.CustomerException;
|
||||||
|
import com.alibaba.fastjson.JSONObject;
|
||||||
|
import org.apache.commons.collections.MapUtils;
|
||||||
|
import org.apache.log4j.Logger;
|
||||||
|
import javax.naming.Context;
|
||||||
|
import javax.naming.NamingEnumeration;
|
||||||
|
import javax.naming.NamingException;
|
||||||
|
import javax.naming.directory.SearchControls;
|
||||||
|
import javax.naming.directory.SearchResult;
|
||||||
|
import javax.naming.ldap.InitialLdapContext;
|
||||||
|
import javax.naming.ldap.LdapContext;
|
||||||
|
import java.util.Hashtable;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* <h1>安波福从AD校验用户是否存在业务方法</h1>
|
||||||
|
*
|
||||||
|
* @Author xuanran.wang
|
||||||
|
* @Date 2022/12/12 14:29
|
||||||
|
*/
|
||||||
|
public class CheckUserService {
|
||||||
|
|
||||||
|
private Map<String, Object> ADConfig = null;
|
||||||
|
private final Logger log = Util.getLogger();
|
||||||
|
/**
|
||||||
|
* <h1>构造方法中初始化配置文件</h1>
|
||||||
|
* @author xuanran.wang
|
||||||
|
* @dateTime 2022/12/12 15:31
|
||||||
|
**/
|
||||||
|
public CheckUserService(){
|
||||||
|
// AD配置文件
|
||||||
|
ADConfig = Util.getProperties2Map("AmbofoADConfig");
|
||||||
|
if(MapUtils.isEmpty(ADConfig)){
|
||||||
|
throw new CustomerException("请检查/filesystem/prop/prop2map 文件夹下是否存在AmbofoADConfig.properties文件!");
|
||||||
|
}
|
||||||
|
|
||||||
|
log.info(Util.logStr("AD配置对象 : [{}]", JSONObject.toJSONString(ADConfig)));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* <h1>校验AD是否存在指定用户</h1>
|
||||||
|
* @author xuanran.wang
|
||||||
|
* @dateTime 2022/12/12 15:22
|
||||||
|
* @param checkInfo 校验内容
|
||||||
|
* @return true/false 有/没有
|
||||||
|
**/
|
||||||
|
public boolean checkADHasUser(String checkInfo) {
|
||||||
|
//连接到AD
|
||||||
|
LdapContext ldapContext = login();
|
||||||
|
try {
|
||||||
|
// 域节点
|
||||||
|
String searchBase = Util.null2String(ADConfig.get("searchBase"));
|
||||||
|
// LDAP搜索过滤器类 cn=*name*模糊查询 cn=name 精确查询 String searchFilter = "(objectClass="+type+")";
|
||||||
|
//查询域帐号
|
||||||
|
String searchFilter = "(" + Util.null2String(ADConfig.get("queryField")) + "=" + checkInfo + ")";
|
||||||
|
log.info("searchFilter : " + searchFilter);
|
||||||
|
// 创建搜索控制器
|
||||||
|
SearchControls searchControl = new SearchControls();
|
||||||
|
// 设置搜索范围 深度
|
||||||
|
searchControl.setSearchScope(SearchControls.SUBTREE_SCOPE);
|
||||||
|
// 根据设置的域节点、过滤器类和搜索控制器搜索LDAP得到结果
|
||||||
|
NamingEnumeration answer = ldapContext.search(searchBase, searchFilter, searchControl);
|
||||||
|
boolean has = answer.hasMoreElements();
|
||||||
|
log.info("has " + has);
|
||||||
|
if(has){
|
||||||
|
SearchResult sr = (SearchResult) answer.next();
|
||||||
|
String dn = sr.getName();
|
||||||
|
log.info("dn " + dn);
|
||||||
|
}
|
||||||
|
// 初始化搜索结果数为0
|
||||||
|
return has;
|
||||||
|
} catch (NamingException e) {
|
||||||
|
throw new CustomerException(Util.logStr("从AD搜索用户异常:[{}]",e.getMessage()));
|
||||||
|
} finally {
|
||||||
|
close(ldapContext);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void logAllUser() {
|
||||||
|
//连接到AD
|
||||||
|
LdapContext ldapContext = login();
|
||||||
|
try {
|
||||||
|
// 域节点
|
||||||
|
String searchBase = Util.null2String(ADConfig.get("searchBase"));
|
||||||
|
// LDAP搜索过滤器类 cn=*name*模糊查询 cn=name 精确查询 String searchFilter = "(objectClass="+type+")";
|
||||||
|
// 创建搜索控制器
|
||||||
|
SearchControls searchControl = new SearchControls();
|
||||||
|
// 设置搜索范围 深度
|
||||||
|
searchControl.setSearchScope(SearchControls.SUBTREE_SCOPE);
|
||||||
|
// 根据设置的域节点、过滤器类和搜索控制器搜索LDAP得到结果
|
||||||
|
NamingEnumeration answer = ldapContext.search(searchBase, "", searchControl);
|
||||||
|
//4. 获取查询的内容
|
||||||
|
while (answer.hasMoreElements()) {
|
||||||
|
SearchResult sr = (SearchResult) answer.next();
|
||||||
|
String dn = sr.getName();
|
||||||
|
log.info("dn " + dn);
|
||||||
|
}
|
||||||
|
} catch (NamingException e) {
|
||||||
|
throw new CustomerException(Util.logStr("从AD搜索用户异常:[{}]",e.getMessage()));
|
||||||
|
} finally {
|
||||||
|
close(ldapContext);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* <h1>创建LDAP连接</h1>
|
||||||
|
* @author xuanran.wang
|
||||||
|
* @dateTime 2022/12/12 15:21
|
||||||
|
* @return LDAP连接对象
|
||||||
|
**/
|
||||||
|
private LdapContext login() {
|
||||||
|
String userName = Util.null2String(ADConfig.get("userName"));
|
||||||
|
String password = Util.null2String(ADConfig.get("password"));
|
||||||
|
String server = Util.null2String(ADConfig.get("server"));
|
||||||
|
String driver = Util.null2String(ADConfig.get("driver"));
|
||||||
|
String authentication = Util.null2String(ADConfig.get("authentication"));
|
||||||
|
try {
|
||||||
|
Hashtable<String, String> env = new Hashtable<>();
|
||||||
|
//用户名称,cn,ou,dc 分别:用户,组,域
|
||||||
|
env.put(Context.SECURITY_PRINCIPAL, userName);
|
||||||
|
//用户密码 cn 的密码
|
||||||
|
env.put(Context.SECURITY_CREDENTIALS, password);
|
||||||
|
//url 格式:协议://ip:端口/组,域 ,直接连接到域或者组上面
|
||||||
|
env.put(Context.PROVIDER_URL, server);
|
||||||
|
//LDAP 工厂
|
||||||
|
env.put(Context.INITIAL_CONTEXT_FACTORY, driver);
|
||||||
|
//验证的类型 "none", "simple", "strong"
|
||||||
|
env.put(Context.SECURITY_AUTHENTICATION, authentication);
|
||||||
|
return new InitialLdapContext(env, null);
|
||||||
|
} catch (NamingException e) {
|
||||||
|
throw new CustomerException(Util.logStr("连接AD失败! : {}", e.getMessage()));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* <h1>关闭连接</h1>
|
||||||
|
* @author xuanran.wang
|
||||||
|
* @dateTime 2022/12/12 15:30
|
||||||
|
* @param lct AD连接对象
|
||||||
|
**/
|
||||||
|
private void close(LdapContext lct) {
|
||||||
|
try {
|
||||||
|
if (lct != null){
|
||||||
|
//关闭连接
|
||||||
|
lct.close();
|
||||||
|
}
|
||||||
|
} catch (NamingException e) {
|
||||||
|
throw new CustomerException(Util.logStr("关闭AD连接失败! : {}", e.getMessage()));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -2,20 +2,28 @@ package com.api.xuanran.wang.saic_travel.model_create_workflow.controller;
|
||||||
|
|
||||||
import aiyh.utils.ApiResult;
|
import aiyh.utils.ApiResult;
|
||||||
import aiyh.utils.Util;
|
import aiyh.utils.Util;
|
||||||
|
import aiyh.utils.excention.CustomerException;
|
||||||
import com.alibaba.fastjson.JSONObject;
|
import com.alibaba.fastjson.JSONObject;
|
||||||
|
import com.api.xuanran.wang.saic_travel.model_create_workflow.service.CreateWorkFlowService;
|
||||||
|
import com.icbc.api.internal.apache.http.E;
|
||||||
|
import org.apache.commons.collections.CollectionUtils;
|
||||||
|
import org.apache.commons.collections.MapUtils;
|
||||||
|
import org.apache.commons.lang3.StringUtils;
|
||||||
import org.apache.log4j.Logger;
|
import org.apache.log4j.Logger;
|
||||||
|
import weaver.conn.RecordSet;
|
||||||
|
import weaver.formmode.data.ModeDataApproval;
|
||||||
|
import weaver.general.TimeUtil;
|
||||||
import weaver.hrm.HrmUserVarify;
|
import weaver.hrm.HrmUserVarify;
|
||||||
import weaver.hrm.User;
|
import weaver.hrm.User;
|
||||||
import weaver.xuanran.wang.common.util.CommonUtil;
|
import weaver.xuanran.wang.common.mapper.CommonMapper;
|
||||||
|
import weaver.xuanran.wang.common.util.CommonUtil; // 工具类
|
||||||
|
|
||||||
import javax.servlet.http.HttpServletRequest;
|
import javax.servlet.http.HttpServletRequest;
|
||||||
import javax.servlet.http.HttpServletResponse;
|
import javax.servlet.http.HttpServletResponse;
|
||||||
import javax.ws.rs.*;
|
import javax.ws.rs.*;
|
||||||
import javax.ws.rs.core.Context;
|
import javax.ws.rs.core.Context;
|
||||||
import javax.ws.rs.core.MediaType;
|
import javax.ws.rs.core.MediaType;
|
||||||
import java.util.ArrayList;
|
import java.util.*;
|
||||||
import java.util.Arrays;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -26,27 +34,77 @@ import java.util.stream.Collectors;
|
||||||
@Path("/wxr/saicTravel/")
|
@Path("/wxr/saicTravel/")
|
||||||
public class CusCreateWorkFlowController {
|
public class CusCreateWorkFlowController {
|
||||||
|
|
||||||
private final Logger logger = Util.getLogger();
|
private final Logger logger = Util.getLogger(); // 获取日志对象
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
private final CreateWorkFlowService createWorkFlowService = new CreateWorkFlowService();
|
||||||
|
|
||||||
|
|
||||||
@Path("cusCreateWorkFlow")
|
@Path("cusCreateWorkFlow")
|
||||||
@POST
|
@POST
|
||||||
@Produces(MediaType.TEXT_PLAIN)
|
@Produces(MediaType.TEXT_PLAIN)
|
||||||
public String createWorkFlow(@Context HttpServletRequest request, @Context HttpServletResponse response) {
|
public String createWorkFlow(@Context HttpServletRequest request, @Context HttpServletResponse response) {
|
||||||
User logInUser = HrmUserVarify.getUser(request, response);
|
try {
|
||||||
if(logInUser == null){
|
User logInUser = HrmUserVarify.getUser(request, response);
|
||||||
return ApiResult.error(403,"请先登录!");
|
if(logInUser == null){
|
||||||
}
|
return ApiResult.error(403,"请先登录!");
|
||||||
String choiceData = request.getParameter("choiceData");
|
|
||||||
int modelId = Util.getIntValue(request.getParameter("modelId"), -1);
|
|
||||||
List<String> dataList = Arrays.stream(choiceData.split(",")).collect(Collectors.toList());
|
|
||||||
List<String> requestIds = CommonUtil.doCreateWorkFlow(modelId, dataList);
|
|
||||||
List<String> errorData = new ArrayList<>();
|
|
||||||
for (int i = 0; i < requestIds.size(); i++) {
|
|
||||||
if (Util.getIntValue(requestIds.get(i), -1) < 0) {
|
|
||||||
errorData.add(dataList.get(i));
|
|
||||||
}
|
}
|
||||||
|
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("接口发生异常!");
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -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;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* <h1></h1>
|
||||||
|
*
|
||||||
|
* @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();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* <h1>人员绩效创建流程</h1>
|
||||||
|
* @author xuanran.wang
|
||||||
|
* @dateTime 2022/12/15 17:07
|
||||||
|
* @param choiceData 选择的数据
|
||||||
|
* @param createDateField 创建日期字段
|
||||||
|
* @param triggerWorkflowSetId 数据审批id
|
||||||
|
* @param modelId 模块id
|
||||||
|
* @return 流程创建失败的数据id
|
||||||
|
**/
|
||||||
|
public List<String> hrmCusCreateWorkFlow(String choiceData, String createDateField, String triggerWorkflowSetId, int modelId){
|
||||||
|
String name = commonMapper.getModelNameByModelId(String.valueOf(modelId));
|
||||||
|
List<String> dataList = Arrays.stream(choiceData.split(",")).collect(Collectors.toList());
|
||||||
|
RecordSet rs = new RecordSet();
|
||||||
|
List<List<String>> splitList = CommonUtil.splitList(dataList);
|
||||||
|
for (List<String> list : splitList) {
|
||||||
|
List<Integer> 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<String> 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<String> filterIds = filterIds(sql);
|
||||||
|
List<String> dataIds = dataList.stream().filter(filterIds::contains).collect(Collectors.toList());
|
||||||
|
if(CollectionUtils.isNotEmpty(dataIds)){
|
||||||
|
List<String> 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;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* <h1></h1>
|
||||||
|
* @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<String, String> 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<String> dataList = Arrays.stream(choiceData.split(",")).collect(Collectors.toList());
|
||||||
|
logger.info(Util.logStr("查询数据sql : {}", sql));
|
||||||
|
List<String> filterIds = filterIds(sql);
|
||||||
|
// 过滤之后的数据id
|
||||||
|
List<String> dataIds = dataList.stream().filter(filterIds::contains).collect(Collectors.toList());
|
||||||
|
List<String> 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 "";
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* <h1>通过配置数据同步至建模</h1>
|
||||||
|
* @author xuanran.wang
|
||||||
|
* @dateTime 2022/12/2 13:28
|
||||||
|
* @param configCode 配置标识
|
||||||
|
* @param modelId 模块id
|
||||||
|
**/
|
||||||
|
public String asyncModelData(String configCode, List<String> dataIds, int modelId) {
|
||||||
|
DataAsyncMain asyncConfig = dataAsyncConfigService.getDataAsyncConfigByUniqueCode(configCode);
|
||||||
|
String dataSource = asyncConfig.getDataSource();
|
||||||
|
String selectSql = dataAsyncConfigService.getSelectSql(asyncConfig);
|
||||||
|
List<DataAsyncDetail> 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<DataAsyncDetail> mainConfigList = asyncDetailList.stream().filter(item -> !DataAsyncConstant.DETAIL_TABLE.equals(item.getMainOrDetail())).collect(Collectors.toList());
|
||||||
|
List<DataAsyncDetail> detailConfigList = asyncDetailList.stream().filter(item -> DataAsyncConstant.DETAIL_TABLE.equals(item.getMainOrDetail())).collect(Collectors.toList());
|
||||||
|
String mainId = "";
|
||||||
|
if (rs.next()){
|
||||||
|
// 先把数据同步到主表
|
||||||
|
LinkedHashMap<String, Object> params = getValue(mainConfigList, rs, dataSource);
|
||||||
|
mainId = CusInfoToOAUtil.getDataId(modelId, params);
|
||||||
|
logger.info("生成建模mainId : " + mainId);
|
||||||
|
}
|
||||||
|
rs.executeQuery(selectSql);
|
||||||
|
ArrayList<LinkedHashMap<String, Object>> detailParams = new ArrayList<>();
|
||||||
|
while (rs.next()){
|
||||||
|
LinkedHashMap<String, Object> value = getValue(detailConfigList, rs, dataSource);
|
||||||
|
value.put("mainid", mainId);
|
||||||
|
detailParams.add(value);
|
||||||
|
}
|
||||||
|
CusInfoToOAUtil.executeDetailBatch(asyncConfig.getAsyncTargetModelTableName()+ "_dt" + asyncConfig.getDetailIndex(),detailParams);
|
||||||
|
return mainId;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* <h1>转换值</h1>
|
||||||
|
* @author xuanran.wang
|
||||||
|
* @dateTime 2022/12/15 16:29
|
||||||
|
* @param asyncDetailList 配置集合
|
||||||
|
* @param rs 结果集
|
||||||
|
* @param dataSource 数据来源
|
||||||
|
* @return 自定义表插入参数
|
||||||
|
**/
|
||||||
|
public LinkedHashMap<String, Object> getValue(List<DataAsyncDetail> asyncDetailList, RecordSet rs, String dataSource){
|
||||||
|
LinkedHashMap<String, Object> 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;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* <h1>获取数据id</h1>
|
||||||
|
* @author xuanran.wang
|
||||||
|
* @dateTime 2022/12/15 13:22
|
||||||
|
* @param sql 获取执行条件sql
|
||||||
|
* @return 数据id
|
||||||
|
**/
|
||||||
|
public List<String> filterIds(String sql){
|
||||||
|
RecordSet rs = new RecordSet();
|
||||||
|
ArrayList<String> res = new ArrayList<>();
|
||||||
|
if (rs.executeQuery(sql)) {
|
||||||
|
while (rs.next()){
|
||||||
|
res.add(Util.null2DefaultStr(rs.getString(1),""));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -1,9 +1,13 @@
|
||||||
package com.api.xuanran.wang.schroeder.download_file.controller;
|
package com.api.xuanran.wang.schroeder.download_file.controller;
|
||||||
|
|
||||||
import aiyh.utils.Util;
|
import aiyh.utils.Util;
|
||||||
|
import aiyh.utils.excention.CustomerException;
|
||||||
|
import com.alibaba.fastjson.JSONObject;
|
||||||
import com.api.xuanran.wang.schroeder.download_file.service.DownLoadFileService;
|
import com.api.xuanran.wang.schroeder.download_file.service.DownLoadFileService;
|
||||||
import org.apache.commons.io.IOUtils;
|
import org.apache.commons.io.IOUtils;
|
||||||
|
import org.apache.commons.lang3.StringUtils;
|
||||||
import org.apache.log4j.Logger;
|
import org.apache.log4j.Logger;
|
||||||
|
import weaver.docs.docs.DocInfo;
|
||||||
import weaver.file.ImageFileManager;
|
import weaver.file.ImageFileManager;
|
||||||
|
|
||||||
import javax.servlet.http.HttpServletRequest;
|
import javax.servlet.http.HttpServletRequest;
|
||||||
|
@ -43,6 +47,9 @@ public class DownLoadFileController {
|
||||||
Map<String, Object> fileInfo = downLoadFileService.getFileInfo(docId);
|
Map<String, Object> fileInfo = downLoadFileService.getFileInfo(docId);
|
||||||
String fileName = Util.null2String(fileInfo.get("fileName"));
|
String fileName = Util.null2String(fileInfo.get("fileName"));
|
||||||
int imageFileId = Util.getIntValue(Util.null2DefaultStr(fileInfo.get("imageFileId"),""), -1);
|
int imageFileId = Util.getIntValue(Util.null2DefaultStr(fileInfo.get("imageFileId"),""), -1);
|
||||||
|
if(StringUtils.isBlank(fileName) || imageFileId < 0){
|
||||||
|
throw new CustomerException(Util.logStr("文件信息部分字段查询为空!当前查询结果map:[{}]", JSONObject.toJSONString(fileInfo)));
|
||||||
|
}
|
||||||
InputStream is = ImageFileManager.getInputStreamById(imageFileId);
|
InputStream is = ImageFileManager.getInputStreamById(imageFileId);
|
||||||
byte[] bytes = IOUtils.toByteArray(is);
|
byte[] bytes = IOUtils.toByteArray(is);
|
||||||
StreamingOutput output = outputStream ->{
|
StreamingOutput output = outputStream ->{
|
||||||
|
|
|
@ -1,33 +0,0 @@
|
||||||
package com.api.xuanran.wang.schroeder.download_file.mapper;
|
|
||||||
|
|
||||||
import aiyh.utils.annotation.recordset.ParamMapper;
|
|
||||||
import aiyh.utils.annotation.recordset.Select;
|
|
||||||
import aiyh.utils.annotation.recordset.SqlMapper;
|
|
||||||
|
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* <h1>文件下载mapper</h1>
|
|
||||||
*
|
|
||||||
* @Author xuanran.wang
|
|
||||||
* @Date 2022/12/7 10:58
|
|
||||||
*/
|
|
||||||
@SqlMapper
|
|
||||||
public interface DownLoadFileMapper {
|
|
||||||
|
|
||||||
/**
|
|
||||||
* <h1>根据docId查询附件信息</h1>
|
|
||||||
* @author xuanran.wang
|
|
||||||
* @dateTime 2022/12/7 11:01
|
|
||||||
* @param docId docId
|
|
||||||
* @return 文件imageField以及文件名
|
|
||||||
**/
|
|
||||||
@Select("select t3.imagefileid imageFileId,t3.imagefilename fileName,t3.filerealpath filePath " +
|
|
||||||
"from DocDetail t1 " +
|
|
||||||
"left join DocImageFile t2 " +
|
|
||||||
"on t2.docid = t1.id " +
|
|
||||||
"left join ImageFile t3 " +
|
|
||||||
"on t3.imagefileid = t2.imagefileid " +
|
|
||||||
"where t1.id = #{docId}")
|
|
||||||
Map<String, Object> selectDocInfoByDocId(@ParamMapper("docId") String docId);
|
|
||||||
}
|
|
|
@ -2,11 +2,11 @@ package com.api.xuanran.wang.schroeder.download_file.service;
|
||||||
|
|
||||||
import aiyh.utils.Util;
|
import aiyh.utils.Util;
|
||||||
import aiyh.utils.excention.CustomerException;
|
import aiyh.utils.excention.CustomerException;
|
||||||
import com.alibaba.fastjson.JSONObject;
|
|
||||||
import com.api.xuanran.wang.schroeder.download_file.mapper.DownLoadFileMapper;
|
|
||||||
import org.apache.commons.collections.MapUtils;
|
import org.apache.commons.collections.MapUtils;
|
||||||
import org.apache.commons.lang3.StringUtils;
|
import org.apache.commons.lang3.StringUtils;
|
||||||
import weaver.conn.RecordSet;
|
import weaver.conn.RecordSet;
|
||||||
|
|
||||||
|
import java.util.HashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -19,12 +19,11 @@ public class DownLoadFileService {
|
||||||
/**
|
/**
|
||||||
* <h2>文件记录表</h2>
|
* <h2>文件记录表</h2>
|
||||||
**/
|
**/
|
||||||
private static final String DOC_LOG_TABLE_NAME = "doc_log";
|
private static final String DOC_LOG_TABLE_NAME = "uf_doc_log";
|
||||||
/**
|
/**
|
||||||
* <h2>查询文件记录sql</h2>
|
* <h2>查询文件记录sql</h2>
|
||||||
**/
|
**/
|
||||||
private static final String SELECT_DOC_LOG_SQL = "select 1 from " + DOC_LOG_TABLE_NAME + " where docId = ? and enable = 0";
|
private static final String SELECT_DOC_LOG_SQL = "select 1 from " + DOC_LOG_TABLE_NAME + " where docId = ? and enable = 0";
|
||||||
private final DownLoadFileMapper downLoadFileMapper = Util.getMapper(DownLoadFileMapper.class);
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* <h1>根据docId获取文件信息</h1>
|
* <h1>根据docId获取文件信息</h1>
|
||||||
|
@ -33,23 +32,29 @@ public class DownLoadFileService {
|
||||||
* @param docId docId
|
* @param docId docId
|
||||||
**/
|
**/
|
||||||
public Map<String, Object> getFileInfo(String docId) {
|
public Map<String, Object> getFileInfo(String docId) {
|
||||||
|
RecordSet rs = new RecordSet();
|
||||||
if(StringUtils.isBlank(docId)) {
|
if(StringUtils.isBlank(docId)) {
|
||||||
throw new CustomerException(Util.logStr("下载文件失败, 请求路径中不包含指定的docId!当前请求docId:{}", docId));
|
throw new CustomerException(Util.logStr("下载文件失败, 请求路径中不包含指定的docId!当前请求docId:{}", docId));
|
||||||
}
|
}
|
||||||
RecordSet rs = new RecordSet();
|
|
||||||
if (!rs.executeQuery(SELECT_DOC_LOG_SQL, docId) || !rs.next()) {
|
if (!rs.executeQuery(SELECT_DOC_LOG_SQL, docId) || !rs.next()) {
|
||||||
throw new CustomerException("下载文件失败, 请确认文件记录表中是否存在docId = [ " + docId + " ]的文件!");
|
throw new CustomerException("下载文件失败, 请确认文件记录表中是否存在docId = [ " + docId + " ]的文件!");
|
||||||
}
|
}
|
||||||
Map<String, Object> fileInfoMap = downLoadFileMapper.selectDocInfoByDocId(docId);
|
String sql = " select t3.imagefileid imageFileId,t3.imagefilename fileName " +
|
||||||
if(MapUtils.isEmpty(fileInfoMap)){
|
" from DocDetail t1 " +
|
||||||
throw new CustomerException("执行查询文件信息sql失败!");
|
" left join DocImageFile t2 " +
|
||||||
|
" on t2.docid = t1.id " +
|
||||||
|
" left join ImageFile t3 " +
|
||||||
|
" on t3.imagefileid = t2.imagefileid " +
|
||||||
|
" where t1.id = ?";
|
||||||
|
HashMap<String, Object> res = new HashMap<>();
|
||||||
|
if (rs.executeQuery(sql, docId) && rs.next()) {
|
||||||
|
res.put("imageFileId", rs.getString("imageFileId"));
|
||||||
|
res.put("fileName", rs.getString("fileName"));
|
||||||
}
|
}
|
||||||
String fileName = Util.null2DefaultStr(fileInfoMap.get("fileName"),"");
|
if(MapUtils.isEmpty(res)){
|
||||||
int imageFileId = Util.getIntValue(Util.null2DefaultStr(fileInfoMap.get("imageFileId"),""), -1);
|
throw new CustomerException(Util.logStr("执行查询文件信息sql失败! 当前sql : {}", sql));
|
||||||
if(StringUtils.isBlank(fileName) ||imageFileId < 0){
|
|
||||||
throw new CustomerException(Util.logStr("文件信息部分字段查询为空!当前查询结果map:[{}]", JSONObject.toJSONString(fileInfoMap)));
|
|
||||||
}
|
}
|
||||||
return fileInfoMap;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,49 @@
|
||||||
|
package com.api.youhong.ai.pcn.mode.apadefaultyear.controller;
|
||||||
|
|
||||||
|
import aiyh.utils.ApiResult;
|
||||||
|
import aiyh.utils.Util;
|
||||||
|
import com.api.youhong.ai.pcn.mode.apadefaultyear.service.DefaultQueryYearService;
|
||||||
|
import org.apache.log4j.Logger;
|
||||||
|
|
||||||
|
import javax.ws.rs.Consumes;
|
||||||
|
import javax.ws.rs.GET;
|
||||||
|
import javax.ws.rs.Path;
|
||||||
|
import javax.ws.rs.Produces;
|
||||||
|
import javax.ws.rs.core.MediaType;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* <h1>查询默认的apa年份过滤默认年</h1>
|
||||||
|
*
|
||||||
|
* <p>create: 2023-01-05 14:54</p>
|
||||||
|
*
|
||||||
|
* @author youHong.ai
|
||||||
|
*/
|
||||||
|
|
||||||
|
@Path("ayh/mode/default-year")
|
||||||
|
public class DefaultQueryYearController {
|
||||||
|
|
||||||
|
private final Logger log = Util.getLogger();
|
||||||
|
|
||||||
|
private final DefaultQueryYearService service = new DefaultQueryYearService();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* <h2>getYear 获取默认的搜索年份</h2>
|
||||||
|
* <i>2023/1/5 15:09</i>
|
||||||
|
* ************************************************************
|
||||||
|
*
|
||||||
|
* @return String 年份响应数据
|
||||||
|
* @author youHong.ai ******************************************
|
||||||
|
*/
|
||||||
|
@Path("/get-year")
|
||||||
|
@GET
|
||||||
|
@Produces(MediaType.APPLICATION_JSON)
|
||||||
|
@Consumes(MediaType.APPLICATION_JSON)
|
||||||
|
public String getYear() {
|
||||||
|
try {
|
||||||
|
return ApiResult.success(service.getYear());
|
||||||
|
} catch (Exception e) {
|
||||||
|
log.error("get default year error! exception msg is: \n" + Util.getErrString(e));
|
||||||
|
return ApiResult.error(e.getMessage());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,29 @@
|
||||||
|
package com.api.youhong.ai.pcn.mode.apadefaultyear.mapper;
|
||||||
|
|
||||||
|
import aiyh.utils.annotation.recordset.Select;
|
||||||
|
import aiyh.utils.annotation.recordset.SqlMapper;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* <h1>查询数据库数据</h1>
|
||||||
|
*
|
||||||
|
* <p>create: 2023-01-05 15:04</p>
|
||||||
|
*
|
||||||
|
* @author youHong.ai
|
||||||
|
*/
|
||||||
|
|
||||||
|
@SqlMapper
|
||||||
|
public interface DefaultQueryYearMapper {
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* <h2>selectYearById 通过数据ID查询对应年份</h2>
|
||||||
|
* <i>2023/1/5 15:08</i>
|
||||||
|
* ************************************************************
|
||||||
|
*
|
||||||
|
* @param id 数据id
|
||||||
|
* @return String 对应年份
|
||||||
|
* @author youHong.ai ******************************************
|
||||||
|
*/
|
||||||
|
@Select("select nf from uf_hrfunction where id = #{id}")
|
||||||
|
String selectYearById(Integer id);
|
||||||
|
}
|
|
@ -0,0 +1,33 @@
|
||||||
|
package com.api.youhong.ai.pcn.mode.apadefaultyear.service;
|
||||||
|
|
||||||
|
import aiyh.utils.Util;
|
||||||
|
import cn.hutool.core.lang.Assert;
|
||||||
|
import com.api.youhong.ai.pcn.mode.apadefaultyear.mapper.DefaultQueryYearMapper;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* <h1>获取年份</h1>
|
||||||
|
*
|
||||||
|
* <p>create: 2023-01-05 15:02</p>
|
||||||
|
*
|
||||||
|
* @author youHong.ai
|
||||||
|
*/
|
||||||
|
|
||||||
|
public class DefaultQueryYearService {
|
||||||
|
|
||||||
|
|
||||||
|
private final DefaultQueryYearMapper mapper = Util.getMapper(DefaultQueryYearMapper.class);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* <h2>getYear 查询默认搜索年份</h2>
|
||||||
|
* <i>2023/1/5 15:06</i>
|
||||||
|
* ************************************************************
|
||||||
|
*
|
||||||
|
* @return String 默认搜索年份
|
||||||
|
* @author youHong.ai ******************************************
|
||||||
|
*/
|
||||||
|
public String getYear() {
|
||||||
|
String year = mapper.selectYearById(1);
|
||||||
|
Assert.notBlank(year, "query year is null or blank!");
|
||||||
|
return year;
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,6 +1,7 @@
|
||||||
package com.api.youhong.ai.pcn.organization.orgchart.controller;
|
package com.api.youhong.ai.pcn.organization.orgchart.controller;
|
||||||
|
|
||||||
import aiyh.utils.ApiResult;
|
import aiyh.utils.ApiResult;
|
||||||
|
import aiyh.utils.Util;
|
||||||
import com.api.youhong.ai.pcn.organization.orgchart.service.OrgChartService;
|
import com.api.youhong.ai.pcn.organization.orgchart.service.OrgChartService;
|
||||||
import com.api.youhong.ai.pcn.organization.orgchart.vo.OrgChartNodeVo;
|
import com.api.youhong.ai.pcn.organization.orgchart.vo.OrgChartNodeVo;
|
||||||
import weaver.hrm.HrmUserVarify;
|
import weaver.hrm.HrmUserVarify;
|
||||||
|
@ -35,8 +36,28 @@ public class OrgChartController {
|
||||||
@Consumes(MediaType.APPLICATION_JSON)
|
@Consumes(MediaType.APPLICATION_JSON)
|
||||||
@Produces(MediaType.APPLICATION_JSON)
|
@Produces(MediaType.APPLICATION_JSON)
|
||||||
public String getOrgChartTree(@Context HttpServletRequest request, @Context HttpServletResponse response) {
|
public String getOrgChartTree(@Context HttpServletRequest request, @Context HttpServletResponse response) {
|
||||||
User logInUser = HrmUserVarify.getUser(request, response);
|
try {
|
||||||
List<OrgChartNodeVo> treeList = service.getOrgChartTree(logInUser);
|
User logInUser = HrmUserVarify.getUser(request, response);
|
||||||
return ApiResult.success(treeList);
|
List<OrgChartNodeVo> treeList = service.getOrgChartTree(logInUser);
|
||||||
|
return ApiResult.success(treeList);
|
||||||
|
} catch (Exception e) {
|
||||||
|
Util.getLogger().error("get chart tree error ! \n" + Util.getErrString(e));
|
||||||
|
return ApiResult.error("get chart tree error!" + e.getMessage());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Path("get-all")
|
||||||
|
@GET
|
||||||
|
@Consumes(MediaType.APPLICATION_JSON)
|
||||||
|
@Produces(MediaType.APPLICATION_JSON)
|
||||||
|
public String getOrgChartTreeAll(@Context HttpServletRequest request, @Context HttpServletResponse response) {
|
||||||
|
try {
|
||||||
|
User logInUser = HrmUserVarify.getUser(request, response);
|
||||||
|
List<OrgChartNodeVo> treeList = service.getOrgChartTreeAll(logInUser);
|
||||||
|
return ApiResult.success(treeList);
|
||||||
|
} catch (Exception e) {
|
||||||
|
Util.getLogger().error("get all chart tree error ! \n" + Util.getErrString(e));
|
||||||
|
return ApiResult.error("get all chart tree error!" + e.getMessage());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -40,7 +40,7 @@ public interface OrgChartMapper {
|
||||||
" hrm.departmentid department_id, " +
|
" hrm.departmentid department_id, " +
|
||||||
" dept.DEPARTMENTNAME department_name, " +
|
" dept.DEPARTMENTNAME department_name, " +
|
||||||
" job.JOBTITLENAME job_title_name, " +
|
" job.JOBTITLENAME job_title_name, " +
|
||||||
" cus1.$t{typeOfEmploymentFiled} type_of_employment " +
|
" uftb.$t{parentField} type_of_employment " +
|
||||||
"from hrmresource hrm " +
|
"from hrmresource hrm " +
|
||||||
" inner join hrmjobtitles job on hrm.JOBTITLE = job.id " +
|
" inner join hrmjobtitles job on hrm.JOBTITLE = job.id " +
|
||||||
" inner join cus_fielddata cus on cus.ID = hrm.ID " +
|
" inner join cus_fielddata cus on cus.ID = hrm.ID " +
|
||||||
|
@ -50,9 +50,13 @@ public interface OrgChartMapper {
|
||||||
" and cus1.scope = 'HrmCustomFieldByInfoType' " +
|
" and cus1.scope = 'HrmCustomFieldByInfoType' " +
|
||||||
" and cus1.scopeid = -1" +
|
" and cus1.scopeid = -1" +
|
||||||
" inner join hrmdepartment dept on dept.id = hrm.DEPARTMENTID " +
|
" inner join hrmdepartment dept on dept.id = hrm.DEPARTMENTID " +
|
||||||
|
" inner join $t{typeOfEmploymentTable} uftb on uftb.$t{typeOfEmploymentIdField} = cus1.$t{typeOfEmploymentFiled} " +
|
||||||
"where hrm.status in (0, 1)")
|
"where hrm.status in (0, 1)")
|
||||||
List<HrmResource> selectAll(@ParamMapper("typeOfEmploymentFiled") String typeOfEmploymentField,
|
List<HrmResource> selectAll(@ParamMapper("typeOfEmploymentFiled") String typeOfEmploymentField,
|
||||||
@ParamMapper("lastNameEnField") String lastNameEnField);
|
@ParamMapper("lastNameEnField") String lastNameEnField,
|
||||||
|
@ParamMapper("typeOfEmploymentTable") String typeOfEmploymentTable,
|
||||||
|
@ParamMapper("parentField") String parentField,
|
||||||
|
@ParamMapper("typeOfEmploymentIdField") String typeOfEmploymentIdField);
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -41,84 +41,13 @@ public class OrgChartService {
|
||||||
*/
|
*/
|
||||||
public List<OrgChartNodeVo> getOrgChartTree(User logInUser) {
|
public List<OrgChartNodeVo> getOrgChartTree(User logInUser) {
|
||||||
int userId = logInUser.getUID();
|
int userId = logInUser.getUID();
|
||||||
String typeOfEmploymentField = Util.getCusConfigValue("typeOfEmploymentField");
|
|
||||||
Assert.notBlank(typeOfEmploymentField, "config [typeOfEmploymentField] is null or blank!");
|
|
||||||
String lastNameEnField = Util.getCusConfigValue("lastNameEnField");
|
|
||||||
Assert.notBlank(lastNameEnField, "config [lastNameEnField] is null or blank!");
|
|
||||||
List<HrmResource> hrmResourceList = mapper.selectAll(typeOfEmploymentField, lastNameEnField);
|
|
||||||
if (Objects.isNull(hrmResourceList) || hrmResourceList.isEmpty()) {
|
|
||||||
throw new CustomerException("查询不到相关人员!");
|
|
||||||
}
|
|
||||||
//List<HrmResourceDto> hrmResourceDtoList = new ArrayList();
|
|
||||||
AtomicReference<HrmResourceDto> currentUser = new AtomicReference<>();
|
AtomicReference<HrmResourceDto> currentUser = new AtomicReference<>();
|
||||||
/* ******************* 将pojo转换为Dto对象,对节点属性默认值赋值,找出当前用户并设置显示 ******************* */
|
List<HrmResourceDto> hrmResourceDtoList = getHrmResourceDtoList(userId, currentUser);
|
||||||
List<HrmResourceDto> hrmResourceDtoList = hrmResourceList.stream()
|
|
||||||
.map(struct::hrmResourceToDto)
|
|
||||||
.peek(item -> Builder.startSet(item)
|
|
||||||
.with(HrmResourceDto::setShow, 0)
|
|
||||||
.with(HrmResourceDto::setShowBrother, 0)
|
|
||||||
.with(HrmResourceDto::setShowChildren, 0)
|
|
||||||
.endSet())
|
|
||||||
.collect(Collectors.toList());
|
|
||||||
hrmResourceDtoList.stream()
|
|
||||||
.peek(item -> {
|
|
||||||
if (item.getManagerId() == userId) {
|
|
||||||
item.setShow(1);
|
|
||||||
}
|
|
||||||
})
|
|
||||||
.filter(item -> item.getId() == userId)
|
|
||||||
.forEach(item -> {
|
|
||||||
Builder.startSet(item)
|
|
||||||
.with(HrmResourceDto::setShow, 1)
|
|
||||||
.with(HrmResourceDto::setShowBrother, 1)
|
|
||||||
.with(HrmResourceDto::setShowChildren, 1)
|
|
||||||
.with(HrmResourceDto::setCurrent, true)
|
|
||||||
.endSet();
|
|
||||||
currentUser.set(item);
|
|
||||||
});
|
|
||||||
/* ******************* 系统管理员默认全部展开哦 ******************* */
|
/* ******************* 系统管理员默认全部展开哦 ******************* */
|
||||||
if (userId == 1) {
|
if (userId == 1) {
|
||||||
List<OrgChartNodeVo> collect = hrmResourceDtoList.stream()
|
return systemAdminTree(hrmResourceDtoList);
|
||||||
.map(struct::hrmResourceDtoToVo)
|
|
||||||
.peek(item -> Builder.startSet(item)
|
|
||||||
.with(OrgChartNodeVo::setShow, 1)
|
|
||||||
.with(OrgChartNodeVo::setShowBrother, 1)
|
|
||||||
.with(OrgChartNodeVo::setShowChildren, 1)
|
|
||||||
.with(OrgChartNodeVo::setCurrent, true)
|
|
||||||
.endSet())
|
|
||||||
.collect(Collectors.toList());
|
|
||||||
return Util.listToTree(collect, OrgChartNodeVo::getId, OrgChartNodeVo::getManagerId,
|
|
||||||
OrgChartNodeVo::getChildren, OrgChartNodeVo::setChildren,
|
|
||||||
parentId -> parentId == null || parentId <= 0)
|
|
||||||
.stream().peek(item -> Builder.startSet(item)
|
|
||||||
.with(OrgChartNodeVo::setIsRoot, true)
|
|
||||||
.with(OrgChartNodeVo::setCurrent, true)
|
|
||||||
.endSet())
|
|
||||||
.peek(item -> recursionChildrenNums(item, 0))
|
|
||||||
.collect(Collectors.toList());
|
|
||||||
}
|
}
|
||||||
Assert.notNull(currentUser.get(), "not find current login user info!");
|
filterCurrentSubCom(hrmResourceDtoList, currentUser, logInUser);
|
||||||
/* ******************* 根据当前登陆人的分部来过滤 ******************* */
|
|
||||||
hrmResourceDtoList = hrmResourceDtoList.stream()
|
|
||||||
.filter(item -> logInUser.getUserSubCompany1() == item.getSubCompanyId())
|
|
||||||
.collect(Collectors.toList());
|
|
||||||
/* ******************* 查找当前登陆人员的所有上级 ******************* */
|
|
||||||
String currentUserManagerStr = currentUser.get().getManagerStr();
|
|
||||||
if (Objects.isNull(currentUserManagerStr)) {
|
|
||||||
currentUserManagerStr = "";
|
|
||||||
}
|
|
||||||
currentUserManagerStr = Util.removeSeparator(currentUserManagerStr, ",");
|
|
||||||
List<Integer> currentUserManagerList = Arrays.stream(currentUserManagerStr.split(","))
|
|
||||||
.map(Integer::parseInt)
|
|
||||||
.collect(Collectors.toList());
|
|
||||||
/* ******************* 对当前用户的所有直接上级设置标识 ******************* */
|
|
||||||
hrmResourceDtoList.stream()
|
|
||||||
.filter(item -> currentUserManagerList.contains(item.getId()))
|
|
||||||
.forEach(item -> Builder.startSet(item)
|
|
||||||
.with(HrmResourceDto::setShowChildren, 1)
|
|
||||||
.with(HrmResourceDto::setCurrentParent, true)
|
|
||||||
.endSet());
|
|
||||||
|
|
||||||
/* ******************* 查询当前用户的是否全部展示或显示小红点的配置信息 ******************* */
|
/* ******************* 查询当前用户的是否全部展示或显示小红点的配置信息 ******************* */
|
||||||
ShowPointOrAll showPointOrAll = mapper.selectShowPointOrAll(userId);
|
ShowPointOrAll showPointOrAll = mapper.selectShowPointOrAll(userId);
|
||||||
List<OrgChartNodeVo> orgChartNodeVoList = null;
|
List<OrgChartNodeVo> orgChartNodeVoList = null;
|
||||||
|
@ -157,6 +86,176 @@ public class OrgChartService {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* <h2>getOrgChartTreeAll 获取所有的数据并默认展开</h2>
|
||||||
|
* <i>2022/12/16 17:21</i>
|
||||||
|
* ************************************************************
|
||||||
|
*
|
||||||
|
* @param logInUser 当前登陆id
|
||||||
|
* @return List<OrgChartNodeVo> 最终树
|
||||||
|
* @author youHong.ai ******************************************
|
||||||
|
*/
|
||||||
|
public List<OrgChartNodeVo> getOrgChartTreeAll(User logInUser) {
|
||||||
|
int userId = logInUser.getUID();
|
||||||
|
AtomicReference<HrmResourceDto> currentUser = new AtomicReference<>();
|
||||||
|
List<HrmResourceDto> hrmResourceDtoList = getHrmResourceDtoList(userId, currentUser);
|
||||||
|
/* ******************* 系统管理员默认全部展开哦 ******************* */
|
||||||
|
if (userId == 1) {
|
||||||
|
return systemAdminTree(hrmResourceDtoList);
|
||||||
|
}
|
||||||
|
filterCurrentSubCom(hrmResourceDtoList, currentUser, logInUser);
|
||||||
|
List<OrgChartNodeVo> orgChartNodeVoList = null;
|
||||||
|
/* ******************* 转换dto为Vo并且设置根节点标识 ******************* */
|
||||||
|
orgChartNodeVoList = hrmResourceDtoList.stream()
|
||||||
|
.map(struct::hrmResourceDtoToVo)
|
||||||
|
.peek(item ->
|
||||||
|
Builder.startSet(item)
|
||||||
|
.with(OrgChartNodeVo::setShow, 1)
|
||||||
|
.with(OrgChartNodeVo::setShowBrother, 1)
|
||||||
|
.with(OrgChartNodeVo::setShowChildren, 1)
|
||||||
|
.endSet()
|
||||||
|
).collect(Collectors.toList());
|
||||||
|
|
||||||
|
return Util.listToTree(orgChartNodeVoList, OrgChartNodeVo::getId,
|
||||||
|
OrgChartNodeVo::getManagerId, OrgChartNodeVo::getChildren,
|
||||||
|
OrgChartNodeVo::setChildren,
|
||||||
|
parentId -> parentId == null || parentId <= 0)
|
||||||
|
.stream()
|
||||||
|
.peek(item -> item.setIsRoot(true))
|
||||||
|
.peek(item -> recursionChildrenNums(item, 0))
|
||||||
|
.collect(Collectors.toList());
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* <h2>filterCurrentSubCom 过滤当前分部的人员,并且设置用户上级标识</h2>
|
||||||
|
* <i>2022/12/16 17:16</i>
|
||||||
|
* ************************************************************
|
||||||
|
*
|
||||||
|
* @param hrmResourceDtoList 人力资源dtolist
|
||||||
|
* @param currentUser 当前用户
|
||||||
|
* @param logInUser 当前登陆用户
|
||||||
|
* @author youHong.ai ******************************************
|
||||||
|
*/
|
||||||
|
private void filterCurrentSubCom(List<HrmResourceDto> hrmResourceDtoList,
|
||||||
|
AtomicReference<HrmResourceDto> currentUser,
|
||||||
|
User logInUser) {
|
||||||
|
Assert.notNull(currentUser.get(), "not find current login user info!");
|
||||||
|
/* ******************* 根据当前登陆人的分部来过滤 ******************* */
|
||||||
|
hrmResourceDtoList = hrmResourceDtoList.stream()
|
||||||
|
.filter(item -> logInUser.getUserSubCompany1() == item.getSubCompanyId())
|
||||||
|
.collect(Collectors.toList());
|
||||||
|
/* ******************* 查找当前登陆人员的所有上级 ******************* */
|
||||||
|
String currentUserManagerStr = currentUser.get().getManagerStr();
|
||||||
|
if (Objects.isNull(currentUserManagerStr) || "".equals(currentUserManagerStr)) {
|
||||||
|
currentUserManagerStr = "0";
|
||||||
|
}
|
||||||
|
currentUserManagerStr = Util.removeSeparator(currentUserManagerStr, ",");
|
||||||
|
List<Integer> currentUserManagerList = Arrays.stream(currentUserManagerStr.split(","))
|
||||||
|
.map(Integer::parseInt)
|
||||||
|
.collect(Collectors.toList());
|
||||||
|
/* ******************* 对当前用户的所有直接上级设置标识 ******************* */
|
||||||
|
hrmResourceDtoList.stream()
|
||||||
|
.filter(item -> currentUserManagerList.contains(item.getId()))
|
||||||
|
.forEach(item -> Builder.startSet(item)
|
||||||
|
.with(HrmResourceDto::setShowChildren, 1)
|
||||||
|
.with(HrmResourceDto::setCurrentParent, true)
|
||||||
|
.endSet());
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* <h2>systemAdminTree 系统管理员返回全部展开的数据</h2>
|
||||||
|
* <i>2022/12/16 17:15</i>
|
||||||
|
* ************************************************************
|
||||||
|
*
|
||||||
|
* @param hrmResourceDtoList 人力资源dtolist
|
||||||
|
* @return List<OrgChartNodeVo> 树型list
|
||||||
|
* @author youHong.ai ******************************************
|
||||||
|
*/
|
||||||
|
private List<OrgChartNodeVo> systemAdminTree(List<HrmResourceDto> hrmResourceDtoList) {
|
||||||
|
List<OrgChartNodeVo> collect = hrmResourceDtoList.stream()
|
||||||
|
.map(struct::hrmResourceDtoToVo)
|
||||||
|
.peek(item -> Builder.startSet(item)
|
||||||
|
.with(OrgChartNodeVo::setShow, 1)
|
||||||
|
.with(OrgChartNodeVo::setShowBrother, 1)
|
||||||
|
.with(OrgChartNodeVo::setShowChildren, 1)
|
||||||
|
.with(OrgChartNodeVo::setCurrent, true)
|
||||||
|
.endSet())
|
||||||
|
.collect(Collectors.toList());
|
||||||
|
return Util.listToTree(collect, OrgChartNodeVo::getId, OrgChartNodeVo::getManagerId,
|
||||||
|
OrgChartNodeVo::getChildren, OrgChartNodeVo::setChildren,
|
||||||
|
parentId -> parentId == null || parentId <= 0)
|
||||||
|
.stream().peek(item -> Builder.startSet(item)
|
||||||
|
.with(OrgChartNodeVo::setIsRoot, true)
|
||||||
|
.with(OrgChartNodeVo::setCurrent, true)
|
||||||
|
.endSet())
|
||||||
|
.peek(item -> recursionChildrenNums(item, 0))
|
||||||
|
.collect(Collectors.toList());
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* <h2>getHrmResourceDtoList 获取人力资源dto对象list</h2>
|
||||||
|
* <i>2022/12/16 17:09</i>
|
||||||
|
* ************************************************************
|
||||||
|
*
|
||||||
|
* @param userId 当前登陆用户ID
|
||||||
|
* @param currentUser 当前登陆用户对象
|
||||||
|
* @return List<HrmResourceDto> 人力资源dto对象list
|
||||||
|
* @author youHong.ai ******************************************
|
||||||
|
*/
|
||||||
|
private List<HrmResourceDto> getHrmResourceDtoList(Integer userId, AtomicReference<HrmResourceDto> currentUser) {
|
||||||
|
// 人员类型自定义字段
|
||||||
|
String typeOfEmploymentField = Util.getCusConfigValue("typeOfEmploymentField");
|
||||||
|
Assert.notBlank(typeOfEmploymentField, "config [typeOfEmploymentField] is null or blank!");
|
||||||
|
// 英文自定义名称字段
|
||||||
|
String lastNameEnField = Util.getCusConfigValue("lastNameEnField");
|
||||||
|
Assert.notBlank(lastNameEnField, "config [lastNameEnField] is null or blank!");
|
||||||
|
// 人员类型id字段 建模表
|
||||||
|
String typeOfEmploymentIdField = Util.getCusConfigValue("typeOfEmploymentIdField");
|
||||||
|
Assert.notBlank(typeOfEmploymentIdField, "config [typeOfEmploymentIdField] is null or blank!");
|
||||||
|
// 人员类型父级字段 建模表
|
||||||
|
String parentField = Util.getCusConfigValue("parentField");
|
||||||
|
Assert.notBlank(parentField, "config [parentField] is null or blank!");
|
||||||
|
// 人员类型建模表表名
|
||||||
|
String typeOfEmploymentTable = Util.getCusConfigValue("typeOfEmploymentTable");
|
||||||
|
Assert.notBlank(typeOfEmploymentTable, "config [typeOfEmploymentTable] is null or blank!");
|
||||||
|
// 查询所有人员信息
|
||||||
|
List<HrmResource> hrmResourceList = mapper.selectAll(typeOfEmploymentField, lastNameEnField,
|
||||||
|
typeOfEmploymentTable, parentField, typeOfEmploymentIdField);
|
||||||
|
if (Objects.isNull(hrmResourceList) || hrmResourceList.isEmpty()) {
|
||||||
|
throw new CustomerException("查询不到相关人员!");
|
||||||
|
}
|
||||||
|
//List<HrmResourceDto> hrmResourceDtoList = new ArrayList();
|
||||||
|
/* ******************* 将pojo转换为Dto对象,对节点属性默认值赋值,找出当前用户并设置显示 ******************* */
|
||||||
|
List<HrmResourceDto> hrmResourceDtoList = hrmResourceList.stream()
|
||||||
|
.map(struct::hrmResourceToDto)
|
||||||
|
.peek(item -> Builder.startSet(item)
|
||||||
|
.with(HrmResourceDto::setShow, 0)
|
||||||
|
.with(HrmResourceDto::setShowBrother, 0)
|
||||||
|
.with(HrmResourceDto::setShowChildren, 0)
|
||||||
|
.endSet())
|
||||||
|
.collect(Collectors.toList());
|
||||||
|
hrmResourceDtoList.stream()
|
||||||
|
.peek(item -> {
|
||||||
|
if (Objects.equals(item.getManagerId(), userId)) {
|
||||||
|
item.setShow(1);
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.filter(item -> Objects.equals(item.getId(), userId))
|
||||||
|
.forEach(item -> {
|
||||||
|
Builder.startSet(item)
|
||||||
|
.with(HrmResourceDto::setShow, 1)
|
||||||
|
.with(HrmResourceDto::setShowBrother, 1)
|
||||||
|
.with(HrmResourceDto::setShowChildren, 1)
|
||||||
|
.with(HrmResourceDto::setCurrent, true)
|
||||||
|
.endSet();
|
||||||
|
currentUser.set(item);
|
||||||
|
});
|
||||||
|
return hrmResourceDtoList;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* <h2>计算节点所有子节点的数量</h2>
|
* <h2>计算节点所有子节点的数量</h2>
|
||||||
* <i>2022/12/3 17:55</i>
|
* <i>2022/12/3 17:55</i>
|
||||||
|
|
|
@ -0,0 +1,38 @@
|
||||||
|
package com.api.youhong.ai.pcn.workflow.doworkflowtomodel.controller;
|
||||||
|
|
||||||
|
import aiyh.utils.ApiResult;
|
||||||
|
import aiyh.utils.Util;
|
||||||
|
import com.api.youhong.ai.pcn.workflow.doworkflowtomodel.service.ApaLevelByScoreService;
|
||||||
|
import org.apache.log4j.Logger;
|
||||||
|
|
||||||
|
import javax.ws.rs.*;
|
||||||
|
import javax.ws.rs.core.MediaType;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* <h1>通过apa分数获取apalevel</h1>
|
||||||
|
*
|
||||||
|
* <p>create: 2022-12-13 10:37</p>
|
||||||
|
*
|
||||||
|
* @author youHong.ai
|
||||||
|
*/
|
||||||
|
|
||||||
|
@Path("ayh/workflow/apa")
|
||||||
|
public class ApaLevelByScoreController {
|
||||||
|
|
||||||
|
private final Logger log = Util.getLogger();
|
||||||
|
private final ApaLevelByScoreService service = new ApaLevelByScoreService();
|
||||||
|
|
||||||
|
@Path("/level")
|
||||||
|
@GET
|
||||||
|
@Produces(MediaType.APPLICATION_JSON)
|
||||||
|
@Consumes(MediaType.APPLICATION_JSON)
|
||||||
|
public String getLevelByScore(@QueryParam("score") Double score) {
|
||||||
|
try {
|
||||||
|
Integer level = service.getLevelByScore(score);
|
||||||
|
return ApiResult.success(level);
|
||||||
|
} catch (Exception e) {
|
||||||
|
log.error("get level error \n" + Util.getErrString(e));
|
||||||
|
return ApiResult.error("get level error " + e.getMessage());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,46 @@
|
||||||
|
package com.api.youhong.ai.pcn.workflow.doworkflowtomodel.controller;
|
||||||
|
|
||||||
|
import aiyh.utils.ApiResult;
|
||||||
|
import aiyh.utils.Util;
|
||||||
|
import com.api.youhong.ai.pcn.workflow.doworkflowtomodel.service.NotAllowedClickTGSService;
|
||||||
|
import weaver.hrm.HrmUserVarify;
|
||||||
|
import weaver.hrm.User;
|
||||||
|
|
||||||
|
import javax.servlet.http.HttpServletRequest;
|
||||||
|
import javax.servlet.http.HttpServletResponse;
|
||||||
|
import javax.ws.rs.Consumes;
|
||||||
|
import javax.ws.rs.GET;
|
||||||
|
import javax.ws.rs.Path;
|
||||||
|
import javax.ws.rs.Produces;
|
||||||
|
import javax.ws.rs.core.Context;
|
||||||
|
import javax.ws.rs.core.MediaType;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* <h1>是否允许当前用户点击targetSetting按钮</h1>
|
||||||
|
*
|
||||||
|
* <p>create: 2022-12-12 15:36</p>
|
||||||
|
*
|
||||||
|
* @author youHong.ai
|
||||||
|
*/
|
||||||
|
|
||||||
|
@Path("/ayh/target-setting/btn")
|
||||||
|
public class NotAllowedClickTGSController {
|
||||||
|
|
||||||
|
private final NotAllowedClickTGSService service = new NotAllowedClickTGSService();
|
||||||
|
|
||||||
|
@Path("/can-allowed")
|
||||||
|
@GET
|
||||||
|
@Produces(MediaType.APPLICATION_JSON)
|
||||||
|
@Consumes(MediaType.APPLICATION_JSON)
|
||||||
|
public String canAllowedClickTGSBtn(@Context HttpServletRequest request, @Context HttpServletResponse response) {
|
||||||
|
User user = HrmUserVarify.getUser(request, response);
|
||||||
|
try {
|
||||||
|
return ApiResult.success(service.canAllowedClickTGSBtn(user));
|
||||||
|
} catch (Exception e) {
|
||||||
|
Util.getLogger().error("get can allowed click target setting button error!\n" + Util.getErrString(e));
|
||||||
|
return ApiResult.error("system error!");
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,49 @@
|
||||||
|
package com.api.youhong.ai.pcn.workflow.doworkflowtomodel.controller;
|
||||||
|
|
||||||
|
import aiyh.utils.ApiResult;
|
||||||
|
import aiyh.utils.Util;
|
||||||
|
import com.api.youhong.ai.pcn.workflow.doworkflowtomodel.service.TriggerWorkflowToModelService;
|
||||||
|
import io.swagger.v3.oas.annotations.parameters.RequestBody;
|
||||||
|
import org.apache.log4j.Logger;
|
||||||
|
import weaver.hrm.HrmUserVarify;
|
||||||
|
import weaver.hrm.User;
|
||||||
|
|
||||||
|
import javax.servlet.http.HttpServletRequest;
|
||||||
|
import javax.servlet.http.HttpServletResponse;
|
||||||
|
import javax.ws.rs.Consumes;
|
||||||
|
import javax.ws.rs.POST;
|
||||||
|
import javax.ws.rs.Path;
|
||||||
|
import javax.ws.rs.Produces;
|
||||||
|
import javax.ws.rs.core.Context;
|
||||||
|
import javax.ws.rs.core.MediaType;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* <h1>保存按钮流程转数据接口</h1>
|
||||||
|
*
|
||||||
|
* <p>create: 2022-12-08 18:09</p>
|
||||||
|
*
|
||||||
|
* @author youHong.ai
|
||||||
|
*/
|
||||||
|
|
||||||
|
@Path("/aiyh/workflow/target-setting")
|
||||||
|
public class TriggerWorkflowToModelController {
|
||||||
|
|
||||||
|
private final TriggerWorkflowToModelService service = new TriggerWorkflowToModelService();
|
||||||
|
private final Logger logger = Util.getLogger();
|
||||||
|
|
||||||
|
@Path("/save-trigger")
|
||||||
|
@POST
|
||||||
|
@Consumes(MediaType.APPLICATION_JSON)
|
||||||
|
@Produces(MediaType.APPLICATION_JSON)
|
||||||
|
public String saveTriggerWorkflowToModel(@RequestBody Map<String, Object> params,
|
||||||
|
@Context HttpServletRequest request, @Context HttpServletResponse response) {
|
||||||
|
try {
|
||||||
|
User user = HrmUserVarify.getUser(request, response);
|
||||||
|
return ApiResult.success(service.saveTriggerWorkflowToModel(params, request, user));
|
||||||
|
} catch (Exception e) {
|
||||||
|
logger.error("save trigger workflow to mode data error ! \n" + Util.getErrString(e));
|
||||||
|
return ApiResult.error(e.getMessage());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,28 @@
|
||||||
|
package com.api.youhong.ai.pcn.workflow.doworkflowtomodel.mapper;
|
||||||
|
|
||||||
|
import aiyh.utils.annotation.recordset.Select;
|
||||||
|
import aiyh.utils.annotation.recordset.SqlMapper;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* <h1></h1>
|
||||||
|
*
|
||||||
|
* <p>create: 2022-12-13 10:42</p>
|
||||||
|
*
|
||||||
|
* @author youHong.ai
|
||||||
|
*/
|
||||||
|
|
||||||
|
@SqlMapper
|
||||||
|
public interface ApaLevelByScoreMapper {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* <h2>通过apa分数查询对应的分数等级</h2>
|
||||||
|
* <i>2022/12/13 10:47</i>
|
||||||
|
* ************************************************************
|
||||||
|
*
|
||||||
|
* @param score 分数
|
||||||
|
* @return Integer 当前分数对应的等级
|
||||||
|
* @author youHong.ai ******************************************
|
||||||
|
*/
|
||||||
|
@Select("select level1 from uf_APAlevel where #{score} between zdf and zgf")
|
||||||
|
Integer selectLevelByScore(Double score);
|
||||||
|
}
|
|
@ -0,0 +1,46 @@
|
||||||
|
package com.api.youhong.ai.pcn.workflow.doworkflowtomodel.mapper;
|
||||||
|
|
||||||
|
import aiyh.utils.annotation.recordset.ParamMapper;
|
||||||
|
import aiyh.utils.annotation.recordset.Select;
|
||||||
|
import aiyh.utils.annotation.recordset.SqlMapper;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* <h1></h1>
|
||||||
|
*
|
||||||
|
* <p>create: 2022-12-12 15:56</p>
|
||||||
|
*
|
||||||
|
* @author youHong.ai
|
||||||
|
*/
|
||||||
|
|
||||||
|
@SqlMapper
|
||||||
|
public interface NotAllowedClickTGSMapper {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* <h2>根据用户id和当前年份查询个人目标台账主表id</h2>
|
||||||
|
* <i>2022/12/12 17:27</i>
|
||||||
|
* ************************************************************
|
||||||
|
*
|
||||||
|
* @param userId 用户id
|
||||||
|
* @param currentYear 当前年年份
|
||||||
|
* @return List<Integer> 主表id数组
|
||||||
|
* @author youHong.ai ******************************************
|
||||||
|
*/
|
||||||
|
@Select("select id from uf_targetsettingdat where sqr = #{userId} and nf = #{currentYear}")
|
||||||
|
List<Integer> selectMainIdsByUserIdAndYear(@ParamMapper("userId") Integer userId,
|
||||||
|
@ParamMapper("currentYear") String currentYear);
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* <h2>根据主表id查询明细数据</h2>
|
||||||
|
* <i>2022/12/12 17:28</i>
|
||||||
|
* ************************************************************
|
||||||
|
*
|
||||||
|
* @param list 主表id数组
|
||||||
|
* @return List<String> 明细权重
|
||||||
|
* @author youHong.ai ******************************************
|
||||||
|
*/
|
||||||
|
@Select("select qz from uf_targetsettingdat_dt1 where mainid in (${list})")
|
||||||
|
List<String> selectWeightByMainIds(List<Integer> list);
|
||||||
|
}
|
|
@ -0,0 +1,35 @@
|
||||||
|
package com.api.youhong.ai.pcn.workflow.doworkflowtomodel.mapper;
|
||||||
|
|
||||||
|
import aiyh.utils.annotation.recordset.ParamMapper;
|
||||||
|
import aiyh.utils.annotation.recordset.Select;
|
||||||
|
import aiyh.utils.annotation.recordset.SqlMapper;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* <h1>查询数据库</h1>
|
||||||
|
*
|
||||||
|
* <p>create: 2022-12-09 22:26</p>
|
||||||
|
*
|
||||||
|
* @author youHong.ai
|
||||||
|
*/
|
||||||
|
|
||||||
|
@SqlMapper
|
||||||
|
public interface TriggerWorkflowToModelMapper {
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* <h2>查询当前节点上的流程转数据acitonId</h2>
|
||||||
|
* <i>2022/12/9 22:29</i>
|
||||||
|
* ******************************************
|
||||||
|
*
|
||||||
|
* @param nodeId 当前节点id
|
||||||
|
* @return List<Integer> 流程转数据的actionId
|
||||||
|
* @author youHong.ai ******************************************
|
||||||
|
*/
|
||||||
|
@Select("select ACTIONID from mode_workflowtomodeset where TRIGGERNODEID = #{nodeId} " +
|
||||||
|
" and isenable = 1 and workflowid = #{workflowId}")
|
||||||
|
List<Integer> selectActionId(@ParamMapper("nodeId") String nodeId,
|
||||||
|
@ParamMapper("workflowId") String workflowId);
|
||||||
|
}
|
||||||
|
|
|
@ -0,0 +1,34 @@
|
||||||
|
package com.api.youhong.ai.pcn.workflow.doworkflowtomodel.service;
|
||||||
|
|
||||||
|
import aiyh.utils.Util;
|
||||||
|
import aiyh.utils.excention.CustomerException;
|
||||||
|
import com.api.youhong.ai.pcn.workflow.doworkflowtomodel.mapper.ApaLevelByScoreMapper;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* <h1></h1>
|
||||||
|
*
|
||||||
|
* <p>create: 2022-12-13 10:40</p>
|
||||||
|
*
|
||||||
|
* @author youHong.ai
|
||||||
|
*/
|
||||||
|
|
||||||
|
public class ApaLevelByScoreService {
|
||||||
|
private final ApaLevelByScoreMapper mapper = Util.getMapper(ApaLevelByScoreMapper.class);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* <h2>根据分数查询等级</h2>
|
||||||
|
* <i>2022/12/13 10:55</i>
|
||||||
|
* ************************************************************
|
||||||
|
*
|
||||||
|
* @param score 分数
|
||||||
|
* @return Integer 等级
|
||||||
|
* @author youHong.ai ******************************************
|
||||||
|
*/
|
||||||
|
public Integer getLevelByScore(Double score) {
|
||||||
|
Integer level = mapper.selectLevelByScore(score);
|
||||||
|
if (level < -1) {
|
||||||
|
throw new CustomerException("query level error, score is [" + score + "");
|
||||||
|
}
|
||||||
|
return level;
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,47 @@
|
||||||
|
package com.api.youhong.ai.pcn.workflow.doworkflowtomodel.service;
|
||||||
|
|
||||||
|
import aiyh.utils.Util;
|
||||||
|
import com.api.youhong.ai.pcn.workflow.doworkflowtomodel.mapper.NotAllowedClickTGSMapper;
|
||||||
|
import weaver.hrm.User;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Objects;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* <h1></h1>
|
||||||
|
*
|
||||||
|
* <p>create: 2022-12-12 15:38</p>
|
||||||
|
*
|
||||||
|
* @author youHong.ai
|
||||||
|
*/
|
||||||
|
|
||||||
|
public class NotAllowedClickTGSService {
|
||||||
|
|
||||||
|
|
||||||
|
private final NotAllowedClickTGSMapper mapper = Util.getMapper(NotAllowedClickTGSMapper.class);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* <h2>查询是否可以点击创建targetSetting流程</h2>
|
||||||
|
* <i>2022/12/12 17:29</i>
|
||||||
|
* ************************************************************
|
||||||
|
*
|
||||||
|
* @param user 当前登陆用户
|
||||||
|
* @return boolean 是否可以点击创建按钮
|
||||||
|
* @author youHong.ai ******************************************
|
||||||
|
*/
|
||||||
|
public boolean canAllowedClickTGSBtn(User user) {
|
||||||
|
List<Integer> mainIdList = mapper.selectMainIdsByUserIdAndYear(user.getUID(), Util.getTime("yyyy"));
|
||||||
|
if (Objects.isNull(mainIdList) || mainIdList.isEmpty()) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
List<String> qzList = mapper.selectWeightByMainIds(mainIdList);
|
||||||
|
if (Objects.isNull(qzList) || qzList.isEmpty()) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
Integer sum = qzList.stream()
|
||||||
|
.filter(item -> !Util.isNullOrEmpty(item))
|
||||||
|
.map(Integer::parseInt)
|
||||||
|
.reduce(0, Integer::sum);
|
||||||
|
return sum < 100;
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,84 @@
|
||||||
|
package com.api.youhong.ai.pcn.workflow.doworkflowtomodel.service;
|
||||||
|
|
||||||
|
import aiyh.utils.Util;
|
||||||
|
import com.alibaba.fastjson.JSON;
|
||||||
|
import com.api.youhong.ai.pcn.workflow.doworkflowtomodel.mapper.TriggerWorkflowToModelMapper;
|
||||||
|
import org.apache.log4j.Logger;
|
||||||
|
import weaver.formmode.interfaces.action.WorkflowToMode;
|
||||||
|
import weaver.hrm.User;
|
||||||
|
import weaver.soa.workflow.request.RequestInfo;
|
||||||
|
import weaver.soa.workflow.request.RequestService;
|
||||||
|
import weaver.workflow.request.RequestManager;
|
||||||
|
|
||||||
|
import javax.servlet.http.HttpServletRequest;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.Objects;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* <h1></h1>
|
||||||
|
*
|
||||||
|
* <p>create: 2022-12-09 10:49</p>
|
||||||
|
*
|
||||||
|
* @author youHong.ai
|
||||||
|
*/
|
||||||
|
|
||||||
|
public class TriggerWorkflowToModelService {
|
||||||
|
private final RequestService service = new RequestService();
|
||||||
|
|
||||||
|
private final TriggerWorkflowToModelMapper mapper = Util.getMapper(TriggerWorkflowToModelMapper.class);
|
||||||
|
private final Logger log = Util.getLogger();
|
||||||
|
|
||||||
|
public String saveTriggerWorkflowToModel(Map<String, Object> params, HttpServletRequest request, User user) {
|
||||||
|
log.info("request param:" + JSON.toJSONString(params));
|
||||||
|
String requestId = String.valueOf(params.get("requestId"));
|
||||||
|
String nodeId = String.valueOf(params.get("nodeId"));
|
||||||
|
String isBill = String.valueOf(params.get("isBill"));
|
||||||
|
String formId = String.valueOf(params.get("formId"));
|
||||||
|
String workflowId = String.valueOf(params.get("workflowId"));
|
||||||
|
RequestInfo requestInfo = service.getRequest(Integer.parseInt(requestId));
|
||||||
|
requestInfo.setIspreadd("1");
|
||||||
|
requestInfo.setWorkflowid(workflowId);
|
||||||
|
RequestManager requestManager = requestInfo.getRequestManager();
|
||||||
|
requestManager.setRequest(request);
|
||||||
|
requestManager.setUser(user);
|
||||||
|
requestManager.setNodeid(Integer.parseInt(nodeId));
|
||||||
|
requestManager.setIsbill(Integer.parseInt(isBill));
|
||||||
|
requestManager.setFormid(Integer.parseInt(formId));
|
||||||
|
requestManager.setWorkflowid(Integer.parseInt(workflowId));
|
||||||
|
WorkflowToMode workflowToMode = new WorkflowToMode();
|
||||||
|
workflowToMode.setNodeid(Integer.parseInt(nodeId));
|
||||||
|
workflowToMode.setIp(getRemoteHost(request));
|
||||||
|
List<Integer> actionIds = mapper.selectActionId(nodeId, workflowId);
|
||||||
|
if (Objects.isNull(actionIds) || actionIds.isEmpty()) {
|
||||||
|
return "can not query actionIds;";
|
||||||
|
}
|
||||||
|
List<String> failAction = new ArrayList<>();
|
||||||
|
for (Integer actionId : actionIds) {
|
||||||
|
workflowToMode.setActionid(actionId);
|
||||||
|
if ("0".equals(workflowToMode.execute(requestInfo))) {
|
||||||
|
failAction.add("[" + actionId + "]: " + requestManager.getMessagecontent() + "\t" + requestManager.getMessage());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (failAction.isEmpty()) {
|
||||||
|
return "success";
|
||||||
|
}
|
||||||
|
log.error(Util.join(failAction, "\n"));
|
||||||
|
return "action execute finish! execute fail!";
|
||||||
|
}
|
||||||
|
|
||||||
|
private String getRemoteHost(HttpServletRequest request) {
|
||||||
|
String ip = request.getHeader("x-forwarded-for");
|
||||||
|
if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) {
|
||||||
|
ip = request.getHeader("Proxy-Client-IP");
|
||||||
|
}
|
||||||
|
if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) {
|
||||||
|
ip = request.getHeader("WL-Proxy-Client-IP");
|
||||||
|
}
|
||||||
|
if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) {
|
||||||
|
ip = request.getRemoteAddr();
|
||||||
|
}
|
||||||
|
return ip.equals("0:0:0:0:0:0:0:1") ? "127.0.0.1" : ip;
|
||||||
|
}
|
||||||
|
}
|
|
@ -62,7 +62,7 @@ public class ConfigMappingCMD {
|
||||||
" where mainid = ? ";
|
" where mainid = ? ";
|
||||||
break;
|
break;
|
||||||
case MODEL:
|
case MODEL:
|
||||||
queryDetail1Sql = "select paramName,paramType,getValueType,dataSource,belongTo,workflowField,modelField,fieldName,valueContext, " +
|
queryDetail1Sql = "select paramName,paramType,getValueType,dataSource,belongTo,workflowField,modelField,fv.fieldName,valueContext, " +
|
||||||
" fv.id fieldId,fv.fieldname,fv.tablename,fv.indexdesc " +
|
" fv.id fieldId,fv.fieldname,fv.tablename,fv.indexdesc " +
|
||||||
" from " + configTableName + "_dt1 config " +
|
" from " + configTableName + "_dt1 config " +
|
||||||
" left join workflow_field_table_view fv on config.modelField = fv.id " +
|
" left join workflow_field_table_view fv on config.modelField = fv.id " +
|
||||||
|
|
|
@ -397,7 +397,7 @@ public class DealWithMapping extends ToolUtil {
|
||||||
List<Object> tempList = new ArrayList();
|
List<Object> tempList = new ArrayList();
|
||||||
for (Object o : list) {
|
for (Object o : list) {
|
||||||
if (o instanceof Map) {
|
if (o instanceof Map) {
|
||||||
// map处理 key->1的类型
|
// map处理 key->1的类型
|
||||||
Map<String, Object> mapItem = (Map<String, Object>) o;
|
Map<String, Object> mapItem = (Map<String, Object>) o;
|
||||||
Map<String, List<ListMapIndexValue>> tempMap = new HashMap<>(8);
|
Map<String, List<ListMapIndexValue>> tempMap = new HashMap<>(8);
|
||||||
for (Map.Entry<String, Object> entry : mapItem.entrySet()) {
|
for (Map.Entry<String, Object> entry : mapItem.entrySet()) {
|
||||||
|
@ -443,11 +443,11 @@ public class DealWithMapping extends ToolUtil {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// tempList.addAll(list);
|
// tempList.addAll(list);
|
||||||
requestParam.put(paramName, tempList);
|
requestParam.put(paramName, tempList);
|
||||||
// if (!tempList.isEmpty()) {
|
// if (!tempList.isEmpty()) {
|
||||||
// requestParam.put(paramName, tempList);
|
// requestParam.put(paramName, tempList);
|
||||||
// }
|
// }
|
||||||
} else {
|
} else {
|
||||||
Object value = this.normalValueDeal(mainMap, detailMap, mappingDetail);
|
Object value = this.normalValueDeal(mainMap, detailMap, mappingDetail);
|
||||||
if (!Objects.isNull(value)) {
|
if (!Objects.isNull(value)) {
|
||||||
|
@ -488,7 +488,7 @@ public class DealWithMapping extends ToolUtil {
|
||||||
List<Object> tempList = new ArrayList();
|
List<Object> tempList = new ArrayList();
|
||||||
for (Object o : list) {
|
for (Object o : list) {
|
||||||
if (o instanceof Map) {
|
if (o instanceof Map) {
|
||||||
// map处理
|
// map处理
|
||||||
Map<String, Object> mapItem = (Map<String, Object>) o;
|
Map<String, Object> mapItem = (Map<String, Object>) o;
|
||||||
Map<String, List<ListMapIndexValue>> tempMap = new HashMap<>(8);
|
Map<String, List<ListMapIndexValue>> tempMap = new HashMap<>(8);
|
||||||
for (Map.Entry<String, Object> entry : mapItem.entrySet()) {
|
for (Map.Entry<String, Object> entry : mapItem.entrySet()) {
|
||||||
|
@ -534,11 +534,11 @@ public class DealWithMapping extends ToolUtil {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// tempList.addAll(list);
|
// tempList.addAll(list);
|
||||||
requestParam.put(paramName, tempList);
|
requestParam.put(paramName, tempList);
|
||||||
// if (!tempList.isEmpty()) {
|
// if (!tempList.isEmpty()) {
|
||||||
// requestParam.put(paramName, tempList);
|
// requestParam.put(paramName, tempList);
|
||||||
// }
|
// }
|
||||||
} else {
|
} else {
|
||||||
Object value = this.normalValueDeal(mainMap, detailMap, relationRs, mappingDetail);
|
Object value = this.normalValueDeal(mainMap, detailMap, relationRs, mappingDetail);
|
||||||
if (!Objects.isNull(value)) {
|
if (!Objects.isNull(value)) {
|
||||||
|
@ -574,11 +574,18 @@ public class DealWithMapping extends ToolUtil {
|
||||||
// 流程字段
|
// 流程字段
|
||||||
case WORKFLOW_FIELD: {
|
case WORKFLOW_FIELD: {
|
||||||
FieldMessage fieldMassage = mappingDetail.getFieldMassage();
|
FieldMessage fieldMassage = mappingDetail.getFieldMassage();
|
||||||
String fieldName = fieldMassage.getFieldName().toLowerCase();
|
String fieldName = fieldMassage.getFieldName();
|
||||||
|
String fieldNameLower = fieldName.toLowerCase();
|
||||||
if ("1".equals(childSource)) {
|
if ("1".equals(childSource)) {
|
||||||
value = Util.null2String(detailMap.get(fieldName));
|
value = Util.null2String(detailMap.get(fieldNameLower));
|
||||||
|
if ("".equals(value)) {
|
||||||
|
value = Util.null2String(detailMap.get(fieldName));
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
value = Util.null2String(mainMap.get(fieldName));
|
value = Util.null2String(mainMap.get(fieldNameLower));
|
||||||
|
if ("".equals(value)) {
|
||||||
|
value = Util.null2String(mainMap.get(fieldName));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
@ -587,11 +594,18 @@ public class DealWithMapping extends ToolUtil {
|
||||||
FieldMessage fieldMassage = mappingDetail.getFieldMassage();
|
FieldMessage fieldMassage = mappingDetail.getFieldMassage();
|
||||||
String workFlowVal = "";
|
String workFlowVal = "";
|
||||||
if (fieldMassage != null) {
|
if (fieldMassage != null) {
|
||||||
String fieldName = fieldMassage.getFieldName().toLowerCase();
|
String fieldName = fieldMassage.getFieldName();
|
||||||
|
String fieldNameLowe = fieldName.toLowerCase();
|
||||||
if ("1".equals(childSource)) {
|
if ("1".equals(childSource)) {
|
||||||
workFlowVal = Util.null2String(detailMap.get(fieldName));
|
workFlowVal = Util.null2String(detailMap.get(fieldNameLowe));
|
||||||
|
if ("".equals(workFlowVal)) {
|
||||||
|
workFlowVal = Util.null2String(detailMap.get(fieldName));
|
||||||
|
}
|
||||||
} else if ("0".equals(childSource)) {
|
} else if ("0".equals(childSource)) {
|
||||||
workFlowVal = Util.null2String(mainMap.get(fieldName));
|
workFlowVal = Util.null2String(mainMap.get(fieldNameLowe));
|
||||||
|
if ("".equals(workFlowVal)) {
|
||||||
|
workFlowVal = Util.null2String(mainMap.get(fieldName));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
value = Util.null2String(valueContext)
|
value = Util.null2String(valueContext)
|
||||||
|
@ -635,7 +649,7 @@ public class DealWithMapping extends ToolUtil {
|
||||||
} else {
|
} else {
|
||||||
value = Util.null2String(mainMap.get("id"));
|
value = Util.null2String(mainMap.get("id"));
|
||||||
}
|
}
|
||||||
// value = Util.null2String(main.getString("id"));
|
// value = Util.null2String(main.getString("id"));
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
// 随机数
|
// 随机数
|
||||||
|
@ -666,6 +680,8 @@ public class DealWithMapping extends ToolUtil {
|
||||||
for (DocImageFile docImageFile : docImageFiles) {
|
for (DocImageFile docImageFile : docImageFiles) {
|
||||||
MultipartFile multipartFile = new MultipartFile();
|
MultipartFile multipartFile = new MultipartFile();
|
||||||
InputStream fileInputStream = ImageFileManager.getInputStreamById(docImageFile.getImageFileId());
|
InputStream fileInputStream = ImageFileManager.getInputStreamById(docImageFile.getImageFileId());
|
||||||
|
multipartFile.setDocId(docImageFile.getDocId());
|
||||||
|
multipartFile.setImageFileId(docImageFile.getImageFileId());
|
||||||
multipartFile.setFileKey(paramName);
|
multipartFile.setFileKey(paramName);
|
||||||
multipartFile.setStream(fileInputStream);
|
multipartFile.setStream(fileInputStream);
|
||||||
multipartFile.setFileName(docImageFile.getImageFileName());
|
multipartFile.setFileName(docImageFile.getImageFileName());
|
||||||
|
@ -674,7 +690,7 @@ public class DealWithMapping extends ToolUtil {
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
// 自定义接口
|
// 自定义接口
|
||||||
case CUS_INTERFACE: {
|
case CUS_INTERFACE: {
|
||||||
if (null == valueContext || valueContext.length() == 0) {
|
if (null == valueContext || valueContext.length() == 0) {
|
||||||
} else {
|
} else {
|
||||||
|
@ -834,18 +850,31 @@ public class DealWithMapping extends ToolUtil {
|
||||||
// 流程字段
|
// 流程字段
|
||||||
case WORKFLOW_FIELD: {
|
case WORKFLOW_FIELD: {
|
||||||
FieldMessage fieldMassage = mappingDetail.getFieldMassage();
|
FieldMessage fieldMassage = mappingDetail.getFieldMassage();
|
||||||
String fieldName = fieldMassage.getFieldName().toLowerCase();
|
String fieldName = fieldMassage.getFieldName();
|
||||||
|
String fieldNameLower = fieldName.toLowerCase();
|
||||||
this.writeDebuggerLog("fieldName:" + fieldName);
|
this.writeDebuggerLog("fieldName:" + fieldName);
|
||||||
if ("1".equals(childSource)) {
|
if ("1".equals(childSource)) {
|
||||||
value = Util.null2String(detailMap.get(fieldName));
|
value = Util.null2String(detailMap.get(fieldNameLower));
|
||||||
|
if ("".equals(value)) {
|
||||||
|
value = Util.null2String(detailMap.get(fieldName));
|
||||||
|
}
|
||||||
} else if ("0".equals(childSource)) {
|
} else if ("0".equals(childSource)) {
|
||||||
value = Util.null2String(mainMap.get(fieldName));
|
value = Util.null2String(mainMap.get(fieldNameLower));
|
||||||
|
if ("".equals(value)) {
|
||||||
|
value = Util.null2String(mainMap.get(fieldName));
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
value = Util.null2String(relationRs.getString(fieldName));
|
value = Util.null2String(relationRs.getString(fieldNameLower));
|
||||||
|
if ("".equals(value)) {
|
||||||
|
value = Util.null2String(relationRs.getString(fieldName));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if ("rootNode".equals(mappingDetail.getBelongTo()) && "2".equals(childSource)) {
|
if ("rootNode".equals(mappingDetail.getBelongTo()) && "2".equals(childSource)) {
|
||||||
writeDebuggerLog("主表取关联流程字段 => " + paramName);
|
writeDebuggerLog("主表取关联流程字段 => " + paramName);
|
||||||
value = Util.null2String(tempRs.getString(fieldName));
|
value = Util.null2String(tempRs.getString(fieldNameLower));
|
||||||
|
if ("".equals(value)) {
|
||||||
|
value = Util.null2String(tempRs.getString(fieldName));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
@ -854,16 +883,29 @@ public class DealWithMapping extends ToolUtil {
|
||||||
FieldMessage fieldMassage = mappingDetail.getFieldMassage();
|
FieldMessage fieldMassage = mappingDetail.getFieldMassage();
|
||||||
String workFlowVal = "";
|
String workFlowVal = "";
|
||||||
if (fieldMassage != null) {
|
if (fieldMassage != null) {
|
||||||
String fieldName = fieldMassage.getFieldName().toLowerCase();
|
String fieldName = fieldMassage.getFieldName();
|
||||||
|
String fieldNameLower = fieldName.toLowerCase();
|
||||||
if ("1".equals(childSource)) {
|
if ("1".equals(childSource)) {
|
||||||
workFlowVal = Util.null2String(detailMap.get(fieldName));
|
workFlowVal = Util.null2String(detailMap.get(fieldNameLower));
|
||||||
|
if ("".equals(workFlowVal)) {
|
||||||
|
workFlowVal = Util.null2String(detailMap.get(fieldName));
|
||||||
|
}
|
||||||
} else if ("0".equals(childSource)) {
|
} else if ("0".equals(childSource)) {
|
||||||
workFlowVal = Util.null2String(mainMap.get(fieldName));
|
workFlowVal = Util.null2String(mainMap.get(fieldNameLower));
|
||||||
|
if ("".equals(workFlowVal)) {
|
||||||
|
workFlowVal = Util.null2String(mainMap.get(fieldName));
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
workFlowVal = Util.null2String(relationRs.getString(fieldName));
|
workFlowVal = Util.null2String(relationRs.getString(fieldNameLower));
|
||||||
|
if ("".equals(workFlowVal)) {
|
||||||
|
workFlowVal = Util.null2String(relationRs.getString(fieldName));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if ("rootNode".equals(mappingDetail.getBelongTo()) && "2".equals(childSource)) {
|
if ("rootNode".equals(mappingDetail.getBelongTo()) && "2".equals(childSource)) {
|
||||||
workFlowVal = Util.null2String(tempRs.getString(fieldName));
|
workFlowVal = Util.null2String(tempRs.getString(fieldNameLower));
|
||||||
|
if ("".equals(workFlowVal)) {
|
||||||
|
workFlowVal = Util.null2String(tempRs.getString(fieldName));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
value = Util.null2String(valueContext)
|
value = Util.null2String(valueContext)
|
||||||
|
@ -961,7 +1003,7 @@ public class DealWithMapping extends ToolUtil {
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
// 自定义接口
|
// 自定义接口
|
||||||
case CUS_INTERFACE: {
|
case CUS_INTERFACE: {
|
||||||
if (null == valueContext || valueContext.length() == 0) {
|
if (null == valueContext || valueContext.length() == 0) {
|
||||||
} else {
|
} else {
|
||||||
|
@ -1142,10 +1184,10 @@ public class DealWithMapping extends ToolUtil {
|
||||||
list.add(o);
|
list.add(o);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// for (MappingDetail mappingDetail : childList) {
|
// for (MappingDetail mappingDetail : childList) {
|
||||||
// Object o = this.normalValueDeal(recordSet, null, mappingDetail);
|
// Object o = this.normalValueDeal(recordSet, null, mappingDetail);
|
||||||
// list.add(o);
|
// list.add(o);
|
||||||
// }
|
// }
|
||||||
} else if ("2".equals(childSource)) {
|
} else if ("2".equals(childSource)) {
|
||||||
// 自定义接口
|
// 自定义接口
|
||||||
Map<String, String> pathParamMap = new HashMap<>(8);
|
Map<String, String> pathParamMap = new HashMap<>(8);
|
||||||
|
@ -1221,10 +1263,10 @@ public class DealWithMapping extends ToolUtil {
|
||||||
list.add(o);
|
list.add(o);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// for (MappingDetail mappingDetail : childList) {
|
// for (MappingDetail mappingDetail : childList) {
|
||||||
// Object o = this.normalValueDeal(recordSet, null, mappingDetail);
|
// Object o = this.normalValueDeal(recordSet, null, mappingDetail);
|
||||||
// list.add(o);
|
// list.add(o);
|
||||||
// }
|
// }
|
||||||
} else if ("2".equals(childSource)) {
|
} else if ("2".equals(childSource)) {
|
||||||
// 自定义接口
|
// 自定义接口
|
||||||
Map<String, String> pathParamMap = new HashMap<>(8);
|
Map<String, String> pathParamMap = new HashMap<>(8);
|
||||||
|
@ -1259,8 +1301,9 @@ public class DealWithMapping extends ToolUtil {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* <h2>请求结果赋值到配置信息中</h2>
|
* <h2>请求结果赋值到配置信息中</h2>
|
||||||
|
*
|
||||||
* @param responseMappingList 回写信息配置列表
|
* @param responseMappingList 回写信息配置列表
|
||||||
* @param requestRes 请求结果
|
* @param requestRes 请求结果
|
||||||
* @return 要插入的信息
|
* @return 要插入的信息
|
||||||
*/
|
*/
|
||||||
public Map<String, Map<String, Object>> dealResponse(List<ResponseMapping> responseMappingList, Map<String, Object> requestRes) {
|
public Map<String, Map<String, Object>> dealResponse(List<ResponseMapping> responseMappingList, Map<String, Object> requestRes) {
|
||||||
|
@ -1364,7 +1407,7 @@ public class DealWithMapping extends ToolUtil {
|
||||||
String classPath = split[0];
|
String classPath = split[0];
|
||||||
String paramStr = "";
|
String paramStr = "";
|
||||||
if (split.length > 1) {
|
if (split.length > 1) {
|
||||||
paramStr = Arrays.stream(split).skip(1).collect(Collectors.joining(""));
|
paramStr = Arrays.stream(split).skip(1).collect(Collectors.joining("?"));
|
||||||
}
|
}
|
||||||
/* 获取?后的参数:"weaver.aiyh_jitu.pushdata.service.toones.GetRequestValueCusGetValueImpl?" +
|
/* 获取?后的参数:"weaver.aiyh_jitu.pushdata.service.toones.GetRequestValueCusGetValueImpl?" +
|
||||||
"requestType=get&apiOnlyMark=getAssign&valueKey=data&assign=#{main.zd2}&" +
|
"requestType=get&apiOnlyMark=getAssign&valueKey=data&assign=#{main.zd2}&" +
|
||||||
|
@ -1392,10 +1435,10 @@ public class DealWithMapping extends ToolUtil {
|
||||||
value:#sql{select workcode from hrmresource where id = #{main.zd1} and test = #{h-hah} and a in (${hrmids})}
|
value:#sql{select workcode from hrmresource where id = #{main.zd1} and test = #{h-hah} and a in (${hrmids})}
|
||||||
key:hah
|
key:hah
|
||||||
value:haode*/
|
value:haode*/
|
||||||
// 最终通过反射调用weaver.aiyh_jitu.pushdata.service.GetAssignProcessorProcessorImpl类,将参数传递给这个类, 使用``包裹的字符串会被解析为一个字符串
|
// 最终通过反射调用weaver.aiyh_jitu.pushdata.service.GetAssignProcessorProcessorImpl类,将参数传递给这个类, 使用``包裹的字符串会被解析为一个字符串
|
||||||
String pattern = "&?(?<key>([#.\\w\\u4E00-\\u9FA5]+))=" +
|
String pattern = "&?(?<key>([#.\\w\\u4E00-\\u9FA5]+))=" +
|
||||||
"(?<value>((`([():/\\-&$?#={ }.\\w\\u4E00-\\u9FA5?]*)`)|" +
|
"(?<value>((`([^`]*)`)|" +
|
||||||
"((#(\\{|sql\\{))?([():/\\-$#={ }.\\w\\u4E00-\\u9FA5?]+)?}?)))&?";
|
"((#(\\{|sql\\{))?([():/\\-$_#={ }.\\w\\u4E00-\\u9FA5?]+)?}?)))&?";
|
||||||
Pattern compile = Pattern.compile(pattern);
|
Pattern compile = Pattern.compile(pattern);
|
||||||
Matcher matcher = compile.matcher(paramStr);
|
Matcher matcher = compile.matcher(paramStr);
|
||||||
while (matcher.find()) {
|
while (matcher.find()) {
|
||||||
|
|
|
@ -0,0 +1,92 @@
|
||||||
|
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;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* <h1>柏美施工合同修改日期action</h1>
|
||||||
|
*
|
||||||
|
* @Author xuanran.wang
|
||||||
|
* @Date 2022/12/20 11:33
|
||||||
|
*/
|
||||||
|
public class ContractApplyComDateAction extends SafeCusBaseAction {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* <h2>施工合同项目字段</h2>
|
||||||
|
**/
|
||||||
|
@RequiredMark
|
||||||
|
private String buildContractProjectField;
|
||||||
|
/**
|
||||||
|
* <h2>施工合同主表名</h2>
|
||||||
|
**/
|
||||||
|
@RequiredMark
|
||||||
|
private String buildContractTable;
|
||||||
|
/**
|
||||||
|
* <h2>施工合同明细表表名</h2>
|
||||||
|
**/
|
||||||
|
@RequiredMark
|
||||||
|
private String detailContractTable;
|
||||||
|
/**
|
||||||
|
* <h2>施工合同明细表更新日期字段</h2>
|
||||||
|
**/
|
||||||
|
@RequiredMark
|
||||||
|
private String detailContractDateFiled;
|
||||||
|
/**
|
||||||
|
* <h2>验收流程项目字段</h2>
|
||||||
|
**/
|
||||||
|
@RequiredMark
|
||||||
|
private String projectField;
|
||||||
|
/**
|
||||||
|
* <h2>验收流程日期字段</h2>
|
||||||
|
**/
|
||||||
|
@RequiredMark
|
||||||
|
private String checkDateField;
|
||||||
|
/**
|
||||||
|
* <h2>明细表更新验收日期的条件</h2>
|
||||||
|
**/
|
||||||
|
private String updateWhere;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void doSubmit(String requestId, String billTable, int workflowId, User user, RequestInfo requestInfo) {
|
||||||
|
log.info(Util.logStr("--------------- requestId : {} Begin ---------------", requestId));
|
||||||
|
RecordSetTrans rs = new RecordSetTrans();
|
||||||
|
rs.setAutoCommit(false);
|
||||||
|
try {
|
||||||
|
Map<String, String> 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;
|
||||||
|
}
|
||||||
|
log.info(Util.logStr("更新合同明细表sql:{}, 参数:{}, {}", updateSql, checkDate, mainId));
|
||||||
|
if(!rs.executeUpdate(updateSql, checkDate, mainId)){
|
||||||
|
throw new CustomerException("更新合同sql错误!");
|
||||||
|
}
|
||||||
|
rs.commit();
|
||||||
|
}else{
|
||||||
|
log.error(Util.logStr("查询施工合同关联项目sql暂未查到数据! sql {} ,{}", selectSql, requestId));
|
||||||
|
}
|
||||||
|
}catch (Exception e){
|
||||||
|
rs.rollback();
|
||||||
|
throw new CustomerException(Util.logStr("更新施工合同实际验收日期发生异常: {} ", e.getMessage()));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -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;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* <h1>柏美存货档案流程生成流水号</h1>
|
||||||
|
* <p>
|
||||||
|
* 流程主表的存货档案编码生成流水号 格式:存货分类编码 + 4位流水号 DUJE0101 DUJE0199 => DUJE0201
|
||||||
|
* </p>
|
||||||
|
*
|
||||||
|
* @Author xuanran.wang
|
||||||
|
* @Date 2022/12/22 13:18
|
||||||
|
*/
|
||||||
|
public class CusCreateWaterNoAction extends SafeCusBaseAction {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* <h2>存货分类编码字段</h2>
|
||||||
|
**/
|
||||||
|
@RequiredMark
|
||||||
|
private String invClassificationCode;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* <h2>存货编码 生成编号后写入这个字段</h2>
|
||||||
|
**/
|
||||||
|
@RequiredMark
|
||||||
|
private String inventoryCode;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* <h2>生成流水号日志记录模块id</h2>
|
||||||
|
**/
|
||||||
|
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<String, String> 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()));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* <h1>根据分类编码获取下一个流水号</h1>
|
||||||
|
* @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<String, Object> 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;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
|
@ -50,4 +50,11 @@ public interface CommonMapper {
|
||||||
"ON mp.id = mpd.mainId " +
|
"ON mp.id = mpd.mainId " +
|
||||||
"WHERE mp.modeid = #{modelId} AND mp.isSystem = 1 AND mp.iSSystemFlag = 1")
|
"WHERE mp.modeid = #{modelId} AND mp.isSystem = 1 AND mp.iSSystemFlag = 1")
|
||||||
Map<String, Integer> getExpendConfigByModeId(@ParamMapper("modelId") int modelId);
|
Map<String, Integer> getExpendConfigByModeId(@ParamMapper("modelId") int modelId);
|
||||||
|
|
||||||
|
@Select("select * from mode_triggerworkflowset where id = #{triggerId}")
|
||||||
|
Map<String, String> getConfigByTriggerId(@ParamMapper("triggerId") String triggerId);
|
||||||
|
|
||||||
|
@Select("select showcondition from mode_triggerworkflowset where id = #{triggerId}")
|
||||||
|
String getConditionByTriggerId(@ParamMapper("triggerId") String triggerId);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -12,6 +12,8 @@ import org.apache.log4j.Logger;
|
||||||
import weaver.conn.RecordSet;
|
import weaver.conn.RecordSet;
|
||||||
import weaver.formmode.data.ModeDataApproval;
|
import weaver.formmode.data.ModeDataApproval;
|
||||||
import weaver.hrm.User;
|
import weaver.hrm.User;
|
||||||
|
import weaver.xiao.commons.config.entity.RequestMappingConfig;
|
||||||
|
import weaver.xiao.commons.config.service.DealWithMapping;
|
||||||
import weaver.xuanran.wang.common.annocation.CusDateFormat;
|
import weaver.xuanran.wang.common.annocation.CusDateFormat;
|
||||||
import weaver.xuanran.wang.common.annocation.ParamNotNull;
|
import weaver.xuanran.wang.common.annocation.ParamNotNull;
|
||||||
import weaver.xuanran.wang.common.mapper.CommonMapper;
|
import weaver.xuanran.wang.common.mapper.CommonMapper;
|
||||||
|
@ -232,6 +234,16 @@ public class CommonUtil {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* <h1>将集合进行分割</h1>
|
||||||
|
* @author xuanran.wang
|
||||||
|
* @dateTime 2022/11/25 16:01
|
||||||
|
* @param list 待分割的集合
|
||||||
|
* @return 分割集合
|
||||||
|
**/
|
||||||
|
public static <T> List<List<T>> splitList(List<T> list) {
|
||||||
|
return splitList(list, SQL_IN_PAGE_SIZE);
|
||||||
|
}
|
||||||
/**
|
/**
|
||||||
* <h1>将集合进行分割</h1>
|
* <h1>将集合进行分割</h1>
|
||||||
* @author xuanran.wang
|
* @author xuanran.wang
|
||||||
|
@ -337,6 +349,9 @@ public class CommonUtil {
|
||||||
* @return true/false
|
* @return true/false
|
||||||
**/
|
**/
|
||||||
public static boolean deleteDataByIds(List<String> ids, String tableName,int pageSize) {
|
public static boolean deleteDataByIds(List<String> ids, String tableName,int pageSize) {
|
||||||
|
if(CollectionUtils.isEmpty(ids)){
|
||||||
|
return true;
|
||||||
|
}
|
||||||
List<List<String>> lists = CommonUtil.splitList(ids, pageSize);
|
List<List<String>> lists = CommonUtil.splitList(ids, pageSize);
|
||||||
for (List<String> list : lists) {
|
for (List<String> list : lists) {
|
||||||
boolean success = commonMapper.deleteModelDataByIds(tableName, list);
|
boolean success = commonMapper.deleteModelDataByIds(tableName, list);
|
||||||
|
@ -526,4 +541,77 @@ public class CommonUtil {
|
||||||
return requestIds;
|
return requestIds;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* <h1>通过数据审批生成流程</h1>
|
||||||
|
* @author xuanran.wang
|
||||||
|
* @dateTime 2022/12/1 21:14
|
||||||
|
* @param modeId 模块id
|
||||||
|
* @param dataIds 模块数据id集合
|
||||||
|
* @param triggerWorkflowSetId 数据审批id
|
||||||
|
**/
|
||||||
|
public static List<String> doCreateWorkFlow(int modeId, List<String> 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<String, Integer> expendConfig = commonMapper.getExpendConfigByModeId(modeId);
|
||||||
|
logger.info(Util.logStr("expendConfig :{}", JSONObject.toJSONString(expendConfig)));
|
||||||
|
int expendId = expendConfig.get("id");
|
||||||
|
int formId = expendConfig.get("formId");
|
||||||
|
ArrayList<String> 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<String, String> resMap = modeDataApproval.approvalDataResult();
|
||||||
|
logger.info(Util.logStr("模块数据id : {}, 创建流程结果 : {}", daId, JSONObject.toJSONString(resMap)));
|
||||||
|
requestIds.add(Util.null2String(resMap.get("requestid")));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return requestIds;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* <h1>根据模块id获取表名</h1>
|
||||||
|
* @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));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* <h1>将建模配置表中的自定义数据条件进行拼接</h1>
|
||||||
|
* @author xuanran.wang
|
||||||
|
* @dateTime 2023/1/4 15:10
|
||||||
|
* @param requestMappingConfig 建模配置对象
|
||||||
|
* @param tableName 表名
|
||||||
|
* @return 添加建模配置表自定义数据条件只会的sql
|
||||||
|
**/
|
||||||
|
public static String getSelectSql( RequestMappingConfig requestMappingConfig, String tableName){
|
||||||
|
String cusWhere = Util.null2DefaultStr(requestMappingConfig.getCusWhereSql(), "");
|
||||||
|
if (StringUtils.isNotBlank(cusWhere)) {
|
||||||
|
cusWhere = " and " + DealWithMapping.sbc2dbcCase(cusWhere); // 全角转半角
|
||||||
|
}
|
||||||
|
return "select * from " + tableName + " where requestid = ? " + cusWhere;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -16,6 +16,7 @@ import weaver.general.TimeUtil;
|
||||||
import weaver.xuanran.wang.common.mapper.CommonMapper;
|
import weaver.xuanran.wang.common.mapper.CommonMapper;
|
||||||
|
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @Author xuanran.wang
|
* @Author xuanran.wang
|
||||||
|
@ -26,7 +27,7 @@ public class CusInfoToOAUtil {
|
||||||
private static final ModeDataIdUpdate modeDataIdUpdate = ModeDataIdUpdate.getInstance();
|
private static final ModeDataIdUpdate modeDataIdUpdate = ModeDataIdUpdate.getInstance();
|
||||||
private static final ModeRightInfo moderightinfo = new ModeRightInfo();
|
private static final ModeRightInfo moderightinfo = new ModeRightInfo();
|
||||||
private static final Logger log = Util.getLogger();
|
private static final Logger log = Util.getLogger();
|
||||||
public static final String TABLE_NAME_PLACEHOLDER = "#\\{tableName}";
|
private static final String TABLE_NAME_PLACEHOLDER = "#\\{tableName}";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* <h1>将自定义信息写入建模</h1>
|
* <h1>将自定义信息写入建模</h1>
|
||||||
|
@ -74,7 +75,7 @@ public class CusInfoToOAUtil {
|
||||||
String whereSql,
|
String whereSql,
|
||||||
List<String> whereParams,
|
List<String> whereParams,
|
||||||
boolean needDel) {
|
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,35 @@ public class CusInfoToOAUtil {
|
||||||
**/
|
**/
|
||||||
public static List<String> executeBatch( int modelId,
|
public static List<String> executeBatch( int modelId,
|
||||||
List<LinkedHashMap<String, Object>> params) {
|
List<LinkedHashMap<String, Object>> params) {
|
||||||
return executeBatch(modelId, params, "", Collections.emptyList(), true);
|
return executeBatch(modelId, params, "", Collections.emptyList());
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* <h1>将自定义信息写入建模</h1>
|
||||||
|
* @author xuanran.wang
|
||||||
|
* @dateTime 2022/11/23 17:00
|
||||||
|
* @param modelId 模块id
|
||||||
|
* @param params 需要插入的数据map
|
||||||
|
* @param whereSql 重复数据条件sql
|
||||||
|
* @param whereParams 重复数据参数集合
|
||||||
|
* @return 建模数据id集合
|
||||||
|
**/
|
||||||
|
public static List<String> executeBatch( int modelId,
|
||||||
|
List<LinkedHashMap<String, Object>> params,
|
||||||
|
String whereSql,
|
||||||
|
List<String> whereParams) {
|
||||||
|
if(modelId < 0){
|
||||||
|
throw new RuntimeException("建模模块id不能小于0!");
|
||||||
|
}
|
||||||
|
String tableName = commonMapper.getModelNameByModelId(String.valueOf(modelId));
|
||||||
|
if(StringUtils.isBlank(tableName)){
|
||||||
|
throw new CustomerException("模块id为 " + modelId + ", 在系统中暂没查询到对应表单!");
|
||||||
|
}
|
||||||
|
ArrayList<List<String>> lists = new ArrayList<>();
|
||||||
|
for (String param : whereParams) {
|
||||||
|
lists.add(new ArrayList<>(Collections.singleton(param)));
|
||||||
|
}
|
||||||
|
return executeBatch(modelId, tableName, params, whereSql, lists, true, Collections.emptyList());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -101,11 +130,12 @@ public class CusInfoToOAUtil {
|
||||||
* @param needDel 更新失败是否需要删除已经插入的数据
|
* @param needDel 更新失败是否需要删除已经插入的数据
|
||||||
* @return 建模数据id集合
|
* @return 建模数据id集合
|
||||||
**/
|
**/
|
||||||
public static List<String> executeBatch( int modelId,
|
public static List<String> executeBatch( int modelId,
|
||||||
List<LinkedHashMap<String, Object>> params,
|
List<LinkedHashMap<String, Object>> params,
|
||||||
String whereSql,
|
String whereSql,
|
||||||
List<String> whereParams,
|
List<List<String>> whereParams,
|
||||||
boolean needDel) {
|
boolean needDel,
|
||||||
|
List<LinkedHashMap<String, Object>> updateParams) {
|
||||||
if(modelId < 0){
|
if(modelId < 0){
|
||||||
throw new RuntimeException("建模模块id不能小于0!");
|
throw new RuntimeException("建模模块id不能小于0!");
|
||||||
}
|
}
|
||||||
|
@ -113,7 +143,7 @@ public class CusInfoToOAUtil {
|
||||||
if(StringUtils.isBlank(tableName)){
|
if(StringUtils.isBlank(tableName)){
|
||||||
throw new CustomerException("模块id为 " + modelId + ", 在系统中暂没查询到对应表单!");
|
throw new CustomerException("模块id为 " + modelId + ", 在系统中暂没查询到对应表单!");
|
||||||
}
|
}
|
||||||
return executeBatch(modelId, tableName, params, whereSql, whereParams, needDel);
|
return executeBatch(modelId, tableName, params, whereSql, whereParams, needDel, updateParams);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -126,56 +156,75 @@ public class CusInfoToOAUtil {
|
||||||
* @param whereSql 重复数据条件sql
|
* @param whereSql 重复数据条件sql
|
||||||
* @param whereParams 重复数据参数集合
|
* @param whereParams 重复数据参数集合
|
||||||
* @param needDel 更新失败是否需要删除已经插入的数据
|
* @param needDel 更新失败是否需要删除已经插入的数据
|
||||||
|
* @param updateParams 更新某条数据的部分字段
|
||||||
* @return 建模数据id集合
|
* @return 建模数据id集合
|
||||||
**/
|
**/
|
||||||
public static List<String> executeBatch( int modelId,
|
public static List<String> executeBatch( int modelId,
|
||||||
String tableName,
|
String tableName,
|
||||||
List<LinkedHashMap<String, Object>> params,
|
List<LinkedHashMap<String, Object>> params,
|
||||||
String whereSql,
|
String whereSql,
|
||||||
List<String> whereParams,
|
List<List<String>> whereParams,
|
||||||
boolean needDel) {
|
boolean needDel,
|
||||||
|
List<LinkedHashMap<String, Object>> updateParams) {
|
||||||
|
|
||||||
// 如果要对模块数据中重复的进行更新则判断待插入的集合大小和判断重复的集合大小参数长度是否一致
|
// 如果要对模块数据中重复的进行更新则判断待插入的集合大小和判断重复的集合大小参数长度是否一致
|
||||||
if(StringUtils.isNotBlank(whereSql)){
|
if(StringUtils.isNotBlank(whereSql)){
|
||||||
if(CollectionUtils.isEmpty(whereParams) || CollectionUtils.isEmpty(params) || whereParams.size() != params.size()){
|
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("使用批量更新时如果需要对重复数据进行更新,参数集合和判断重复参数集合大小必须相等!");
|
throw new CustomerException("使用批量更新时如果需要对重复数据进行更新,参数集合和判断重复参数集合大小必须相等!");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
RecordSet rs = new RecordSet();
|
RecordSet rs = new RecordSet();
|
||||||
List<String> dataIds = new ArrayList<>();
|
List<String> dataIds = new ArrayList<>();
|
||||||
List<Where> wheres = new ArrayList<>();
|
List<Where> paramsWheres = new ArrayList<>();
|
||||||
|
List<Where> updateWheres = new ArrayList<>();
|
||||||
|
whereSql = Util.sbc2dbcCase(whereSql);
|
||||||
|
whereSql = whereSql.replaceAll(TABLE_NAME_PLACEHOLDER, tableName);
|
||||||
|
// 需要插入的建模参数
|
||||||
|
List<LinkedHashMap<String, Object>> tempParams = new ArrayList<>();
|
||||||
|
// 如果建模中已经存在只想更新部分字段参数
|
||||||
|
List<LinkedHashMap<String, Object>> tempUpdateParams = new ArrayList<>();
|
||||||
for (int i = 0; i < params.size(); i++) {
|
for (int i = 0; i < params.size(); i++) {
|
||||||
int mainId = -1;
|
int mainId = -1;
|
||||||
if(StringUtils.isNotBlank(whereSql)){
|
if(StringUtils.isNotBlank(whereSql)){
|
||||||
whereSql = Util.sbc2dbcCase(whereSql);
|
// 如果匹配到数据
|
||||||
whereSql = whereSql.replaceAll(TABLE_NAME_PLACEHOLDER, tableName);
|
if (rs.executeQuery(whereSql, whereParams.get(i)) && rs.next()) {
|
||||||
log.info("whereSql : " + whereSql);
|
|
||||||
log.info("参数 : " + whereParams);
|
|
||||||
if (rs.executeQuery(whereSql, whereParams) && rs.next()) {
|
|
||||||
mainId = Util.getIntValue(rs.getString(1),-1);
|
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(Util.logStr("==== 未匹配到数据 ==== whereSql : {}, 参数 : {}", whereSql, JSONObject.toJSONString(whereParams.get(i))));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if(mainId < 0){
|
if(mainId < 0){
|
||||||
mainId = getNewIdByModelInfo(tableName, modelId);
|
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);
|
try {
|
||||||
String sqlStr = batchSql.getSqlStr();
|
if(CollectionUtils.isNotEmpty(tempParams) && CollectionUtils.isNotEmpty(paramsWheres)){
|
||||||
List<List> batchList = batchSql.getBatchList();
|
execute(tableName, tempParams, paramsWheres);
|
||||||
if(!rs.executeBatchSql(sqlStr, batchList)){
|
}
|
||||||
log.error(Util.logStr("batchSql:{}", sqlStr));
|
if(CollectionUtils.isNotEmpty(tempUpdateParams) && CollectionUtils.isNotEmpty(updateWheres)){
|
||||||
log.error(Util.logStr("batchList:{}", JSONObject.toJSONString(batchList)));
|
execute(tableName, tempUpdateParams, updateWheres);
|
||||||
log.error(Util.logStr("whereList:{}", JSONObject.toJSONString(wheres)));
|
}
|
||||||
|
}catch (Exception e){
|
||||||
if(needDel){
|
if(needDel){
|
||||||
if (!deleteModelDataByIds(String.valueOf(modelId), dataIds)) {
|
if (!deleteModelDataByIds(String.valueOf(modelId), dataIds)) {
|
||||||
log.error(Util.logStr("删除数据失败!未删除数据集合:{}", JSONObject.toJSONString(dataIds)));
|
log.error(Util.logStr("删除数据失败!未删除数据集合:{}", JSONObject.toJSONString(dataIds)));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
throw new CustomerException("执行批量更新sql失败!");
|
throw new CustomerException(e.getMessage());
|
||||||
}
|
|
||||||
if(CollectionUtils.isEmpty(dataIds)){
|
|
||||||
throw new CustomerException("建模数据生成失败!");
|
|
||||||
}
|
}
|
||||||
for (String dataId : dataIds) {
|
for (String dataId : dataIds) {
|
||||||
moderightinfo.rebuildModeDataShareByEdit(1, modelId, Integer.parseInt(dataId));
|
moderightinfo.rebuildModeDataShareByEdit(1, modelId, Integer.parseInt(dataId));
|
||||||
|
@ -183,6 +232,49 @@ public class CusInfoToOAUtil {
|
||||||
return dataIds;
|
return dataIds;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* <h1>将自定义信息写入建模明细表</h1>
|
||||||
|
* @author xuanran.wang
|
||||||
|
* @dateTime 2022/11/23 17:00
|
||||||
|
* @param tableName 表名
|
||||||
|
* @param params 需要插入的数据map
|
||||||
|
* @return 建模数据id集合
|
||||||
|
**/
|
||||||
|
public static boolean executeDetailBatch(String tableName, List<LinkedHashMap<String, Object>> params){
|
||||||
|
RecordSet rs = new RecordSet();
|
||||||
|
BatchSqlResultImpl batchSql = Util.createSqlBuilder().insertBatchSql(tableName, params);
|
||||||
|
String sqlStr = batchSql.getSqlStr();
|
||||||
|
List<List> list = batchSql.getBatchList();
|
||||||
|
if (!rs.executeBatchSql(sqlStr, list)) {
|
||||||
|
throw new CustomerException(Util.logStr("明细数据插入失败! sql : {}, params : {}", sqlStr, JSONObject.toJSONString(list)));
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* <h1>批量写入建模</h1>
|
||||||
|
* @author xuanran.wang
|
||||||
|
* @dateTime 2022/12/15 10:53
|
||||||
|
* @param tableName 表名
|
||||||
|
* @param params 建模参数
|
||||||
|
* @param wheres where条件
|
||||||
|
**/
|
||||||
|
public static void execute(String tableName, List<LinkedHashMap<String, Object>> params, List<Where> 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<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日志!");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* <h1>删除建模数据</h1>
|
* <h1>删除建模数据</h1>
|
||||||
* @author xuanran.wang
|
* @author xuanran.wang
|
||||||
|
@ -195,6 +287,14 @@ public class CusInfoToOAUtil {
|
||||||
String tableName = commonMapper.getModelNameByModelId(modelId);
|
String tableName = commonMapper.getModelNameByModelId(modelId);
|
||||||
return commonMapper.deleteModelDataByIds(tableName, ids);
|
return commonMapper.deleteModelDataByIds(tableName, ids);
|
||||||
}
|
}
|
||||||
|
/**
|
||||||
|
* <h1>获取建模数据id</h1>
|
||||||
|
* @author xuanran.wang
|
||||||
|
* @dateTime 2022/12/15 10:56
|
||||||
|
* @param modelTableName 表名
|
||||||
|
* @param modelId 模块id
|
||||||
|
* @return 新的建模数据id
|
||||||
|
**/
|
||||||
private static Integer getNewIdByModelInfo(String modelTableName, int modelId){
|
private static Integer getNewIdByModelInfo(String modelTableName, int modelId){
|
||||||
String currentDateTime = TimeUtil.getCurrentTimeString();
|
String currentDateTime = TimeUtil.getCurrentTimeString();
|
||||||
//日期
|
//日期
|
||||||
|
|
|
@ -0,0 +1,65 @@
|
||||||
|
package weaver.xuanran.wang.epdi.asset.action;
|
||||||
|
|
||||||
|
import aiyh.utils.Util;
|
||||||
|
import aiyh.utils.action.SafeCusBaseAction;
|
||||||
|
import aiyh.utils.annotation.PrintParamMark;
|
||||||
|
import aiyh.utils.annotation.RequiredMark;
|
||||||
|
import aiyh.utils.excention.CustomerException;
|
||||||
|
import org.apache.commons.lang3.StringUtils;
|
||||||
|
import weaver.conn.RecordSet;
|
||||||
|
import weaver.hrm.User;
|
||||||
|
import weaver.soa.workflow.request.RequestInfo;
|
||||||
|
import weaver.xuanran.wang.epdi.asset.service.AssetDataPushService;
|
||||||
|
/**
|
||||||
|
* <h1>资产模块action</h1>
|
||||||
|
*
|
||||||
|
* @Author xuanran.wang
|
||||||
|
* @Date 2022/12/26 11:11
|
||||||
|
*/
|
||||||
|
public class AssetDataPushAction extends SafeCusBaseAction {
|
||||||
|
/**
|
||||||
|
* <h2>配置唯一标识</h2>
|
||||||
|
**/
|
||||||
|
@RequiredMark
|
||||||
|
@PrintParamMark
|
||||||
|
private String uniqueCode;
|
||||||
|
/**
|
||||||
|
* <h2>接口返回字段</h2>
|
||||||
|
**/
|
||||||
|
@PrintParamMark
|
||||||
|
private String backField;
|
||||||
|
/**
|
||||||
|
* <h2>token建模配置唯一标识</h2>
|
||||||
|
**/
|
||||||
|
@RequiredMark
|
||||||
|
@PrintParamMark
|
||||||
|
private String tokenUniqueCode;
|
||||||
|
/**
|
||||||
|
* <h2>主表字段</h2>
|
||||||
|
* <p>
|
||||||
|
* 如果存在数据回写 就会把接口返回字段对应的值回写到此字段中
|
||||||
|
* </p>
|
||||||
|
**/
|
||||||
|
@PrintParamMark
|
||||||
|
private String tableField;
|
||||||
|
|
||||||
|
private final AssetDataPushService assetDataPushService = new AssetDataPushService();
|
||||||
|
@Override
|
||||||
|
public void doSubmit(String requestId, String billTable, int workflowId, User user, RequestInfo requestInfo) {
|
||||||
|
try {
|
||||||
|
log.info("----------------- AssetDataPushAction Begin " + requestId + " -----------------");
|
||||||
|
RecordSet updateRs = new RecordSet();
|
||||||
|
String backVal = assetDataPushService.dataPush(uniqueCode, tokenUniqueCode, requestId, backField);
|
||||||
|
// 如果接口响应字段值不为空并且表单回写字段不为空
|
||||||
|
if(StringUtils.isNotBlank(backVal) && StringUtils.isNotBlank(tableField)){
|
||||||
|
String updateSql = "update " + billTable + " set " + tableField + " = ? where requestid = ?";
|
||||||
|
if (!updateRs.executeUpdate(updateSql, backVal, requestId)) {
|
||||||
|
log.error(Util.logStr("更新表单sql : {}, 接口响应参数 : {}, 请求id : {}", backVal, requestId));
|
||||||
|
throw new CustomerException("接口数据回写表单失败!");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}catch (Exception e){
|
||||||
|
throw new CustomerException(Util.logStr("数据推送action异常 : {}", e.getMessage()));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,111 @@
|
||||||
|
package weaver.xuanran.wang.epdi.asset.service;
|
||||||
|
|
||||||
|
import aiyh.utils.Util;
|
||||||
|
import aiyh.utils.excention.CustomerException;
|
||||||
|
import aiyh.utils.httpUtil.ResponeVo;
|
||||||
|
import aiyh.utils.httpUtil.util.HttpUtils;
|
||||||
|
import com.alibaba.fastjson.JSON;
|
||||||
|
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||||
|
import org.apache.commons.lang3.StringUtils;
|
||||||
|
import org.apache.log4j.Logger;
|
||||||
|
import weaver.xuanran.wang.epdi.datapush.eneity.MainRequestConfig;
|
||||||
|
import weaver.xuanran.wang.epdi.datapush.service.RequestPushService;
|
||||||
|
|
||||||
|
import javax.ws.rs.core.MediaType;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* <h1>上海电力研究院数据推送业务方法</h1>
|
||||||
|
*
|
||||||
|
* @Author xuanran.wang
|
||||||
|
* @Date 2022/12/26 11:13
|
||||||
|
*/
|
||||||
|
public class AssetDataPushService {
|
||||||
|
/**
|
||||||
|
* <h2>接口响应信息</h2>
|
||||||
|
**/
|
||||||
|
private static final String MESSAGE_FIELD = "repmsg";
|
||||||
|
/**
|
||||||
|
* <h2>接口响应处理成功标识</h2>
|
||||||
|
**/
|
||||||
|
private static final String SUCCESS_CODE = "1";
|
||||||
|
/**
|
||||||
|
* <h2>接口响应状态码字段</h2>
|
||||||
|
**/
|
||||||
|
private static final String SUCCESS_CODE_FIELD = "repcode";
|
||||||
|
private static final String TOKEN_FIELD = "token";
|
||||||
|
private final RequestPushService requestPushService = new RequestPushService();
|
||||||
|
private final HttpUtils httpUtils = new HttpUtils();
|
||||||
|
{
|
||||||
|
httpUtils.getGlobalCache().header.put("Content-Type", MediaType.APPLICATION_JSON); // 全局请求头
|
||||||
|
}
|
||||||
|
private final Logger log = Util.getLogger();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* <h1>数据推送</h1>
|
||||||
|
* @author xuanran.wang
|
||||||
|
* @dateTime 2022/12/26 14:21
|
||||||
|
* @param uniqueCode 请求体的建模配置唯一标识
|
||||||
|
* @param tokenUniqueCode token建模配置唯一标识
|
||||||
|
* @param requestId 请求id
|
||||||
|
* @param backField 回写字段
|
||||||
|
* @return 响应返回信息
|
||||||
|
**/
|
||||||
|
public String dataPush(String uniqueCode, String tokenUniqueCode, String requestId, String backField){
|
||||||
|
String token = dataPush(tokenUniqueCode, requestId, TOKEN_FIELD);
|
||||||
|
log.info(Util.logStr("token : [{}]", token));
|
||||||
|
httpUtils.getGlobalCache().header.put("token", token);
|
||||||
|
return dataPush(uniqueCode, requestId, backField);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* <h1>数据推送</h1>
|
||||||
|
* @author xuanran.wang
|
||||||
|
* @dateTime 2022/12/26 11:27
|
||||||
|
* @param uniqueCode 配置唯一标识
|
||||||
|
* @param requestId 请求id
|
||||||
|
* @param backField 响应返回字段
|
||||||
|
* @return 响应返回信息
|
||||||
|
**/
|
||||||
|
private String dataPush(String uniqueCode, String requestId, String backField){
|
||||||
|
String res = "";
|
||||||
|
MainRequestConfig config = requestPushService.getRequestPushConfigByUniqueCode(uniqueCode);
|
||||||
|
Map<String, Object> requestParam = requestPushService.getRequestParam(config, requestId);
|
||||||
|
String url = config.getRequestUrl();
|
||||||
|
Map<String, String> headers = httpUtils.getGlobalCache().header;// 全局请
|
||||||
|
ResponeVo responseVo = null;
|
||||||
|
try {
|
||||||
|
responseVo = httpUtils.apiPost(url, requestParam);
|
||||||
|
} catch (IOException e) {
|
||||||
|
throw new CustomerException(Util.logStr("发送请求发生异常! : {}", e.getMessage())); // 自定义异常类 create 2022/3/9 2:20 PM 构建日志字符串
|
||||||
|
}
|
||||||
|
if (responseVo.getCode() != 200) { // 相应状态码
|
||||||
|
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 构建日志字符串
|
||||||
|
}
|
||||||
|
Map<String, Object> response;
|
||||||
|
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 successCode = Util.null2DefaultStr(response.get(SUCCESS_CODE_FIELD), "");
|
||||||
|
if (!successCode.equals(SUCCESS_CODE)) {
|
||||||
|
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("获取接口中指定返回字段 [ " + backField+ " ] 为空, 请检查!"); // 自定义异常类 create 2022/3/9 2:20 PM
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,94 @@
|
||||||
|
package weaver.xuanran.wang.epdi.datapush.constant;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* <h1>uf_request_push配置表常量</h1>
|
||||||
|
*
|
||||||
|
* @Author xuanran.wang
|
||||||
|
* @Date 2022/12/1 14:18
|
||||||
|
*/
|
||||||
|
public class RequestPushConstant {
|
||||||
|
/**
|
||||||
|
* <h2>配置建模表名</h2>
|
||||||
|
**/
|
||||||
|
public static final String MODEL_TABLE_NAME = "uf_request_push";
|
||||||
|
/**
|
||||||
|
* <h2>数据类型-普通</h2>
|
||||||
|
**/
|
||||||
|
public static final String PARAM_NODE_TYPE_GENERAL = "0";
|
||||||
|
/**
|
||||||
|
* <h2>数据类型-对象</h2>
|
||||||
|
**/
|
||||||
|
public static final String PARAM_NODE_TYPE_OBJ = "1";
|
||||||
|
/**
|
||||||
|
* <h2>数据类型-数组</h2>
|
||||||
|
**/
|
||||||
|
public static final String PARAM_NODE_TYPE_LIST = "2";
|
||||||
|
/**
|
||||||
|
* <h2>配置启用</h2>
|
||||||
|
**/
|
||||||
|
public static final String CONFIG_ENABLE = "0";
|
||||||
|
/**
|
||||||
|
* <h2>数据类型-String</h2>
|
||||||
|
**/
|
||||||
|
public static final String DATA_TYPE_STRING = "0";
|
||||||
|
/**
|
||||||
|
* <h2>数据类型-Int</h2>
|
||||||
|
**/
|
||||||
|
public static final String DATA_TYPE_INT = "1";
|
||||||
|
/**
|
||||||
|
* <h2>数据类型-Double</h2>
|
||||||
|
**/
|
||||||
|
public static final String DATA_TYPE_DOUBLE = "2";
|
||||||
|
/**
|
||||||
|
* <h2>数据类型-Date</h2>
|
||||||
|
**/
|
||||||
|
public static final String DATA_TYPE_DATE = "3";
|
||||||
|
/**
|
||||||
|
* <h2>数据类型-DateTime</h2>
|
||||||
|
**/
|
||||||
|
public static final String DATA_TYPE_DATE_TIME = "4";
|
||||||
|
/**
|
||||||
|
* <h2>数据类型-自定义时间格式</h2>
|
||||||
|
**/
|
||||||
|
public static final String DATA_TYPE_CUS_DATE = "7";
|
||||||
|
/**
|
||||||
|
* <h2>数据类型-时间戳</h2>
|
||||||
|
**/
|
||||||
|
public static final String DATA_TYPE_TIME_TIMESTAMP = "8";
|
||||||
|
/**
|
||||||
|
* <h2>转换类型-当前表单字段</h2>
|
||||||
|
**/
|
||||||
|
public static final String CONVERT_RULES_TABLE_FIELD = "0";
|
||||||
|
/**
|
||||||
|
* <h2>转换类型-默认值</h2>
|
||||||
|
**/
|
||||||
|
public static final String CONVERT_RULES_DEFAULT = "1";
|
||||||
|
/**
|
||||||
|
* <h2>转换类型-自定义SQL</h2>
|
||||||
|
**/
|
||||||
|
public static final String CONVERT_RULES_NOW_TIME = "3";
|
||||||
|
/**
|
||||||
|
* <h2>转换类型-当前时间</h2>
|
||||||
|
**/
|
||||||
|
public static final String CONVERT_RULES_CUS_SQL = "4";
|
||||||
|
/**
|
||||||
|
* <h2>转换类型-requestId</h2>
|
||||||
|
**/
|
||||||
|
public static final String CONVERT_RULES_REQUEST_ID = "5";
|
||||||
|
/**
|
||||||
|
* <h2>转换类型-数据id</h2>
|
||||||
|
**/
|
||||||
|
public static final String CONVERT_RULES_DATA_ID = "6";
|
||||||
|
/**
|
||||||
|
* <h2>主表</h2>
|
||||||
|
**/
|
||||||
|
public static final String DATASOURCE_MAIN_TABLE = "0";
|
||||||
|
/**
|
||||||
|
* <h2>明细</h2>
|
||||||
|
**/
|
||||||
|
public static final String DATASOURCE_DETAIL_TABLE = "1";
|
||||||
|
/**
|
||||||
|
* <h2>根节点</h2>
|
||||||
|
**/
|
||||||
|
public static final String ROOT_NODE = "";
|
||||||
|
}
|
|
@ -0,0 +1,27 @@
|
||||||
|
package weaver.xuanran.wang.epdi.datapush.eneity;
|
||||||
|
|
||||||
|
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* <h1>配置表明细表实体类</h1>
|
||||||
|
*
|
||||||
|
* @Author xuanran.wang
|
||||||
|
* @Date 2022/12/23 16:20
|
||||||
|
*/
|
||||||
|
@Data
|
||||||
|
public class DetailRequestConfig {
|
||||||
|
private String paramName;
|
||||||
|
private String paramNodeType;
|
||||||
|
private String detailIndex;
|
||||||
|
private String parentName;
|
||||||
|
private String paramType;
|
||||||
|
private String getValueType;
|
||||||
|
private String valueContext;
|
||||||
|
private String workFlowField;
|
||||||
|
private String dataSource;
|
||||||
|
private String workFlowFieldName;
|
||||||
|
private List<DetailRequestConfig> detailRequestConfigList;
|
||||||
|
}
|
|
@ -0,0 +1,24 @@
|
||||||
|
package weaver.xuanran.wang.epdi.datapush.eneity;
|
||||||
|
|
||||||
|
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* <h1>配置表主表实体类</h1>
|
||||||
|
*
|
||||||
|
* @Author xuanran.wang
|
||||||
|
* @Date 2022/12/23 16:20
|
||||||
|
*/
|
||||||
|
@Data
|
||||||
|
public class MainRequestConfig {
|
||||||
|
private String id;
|
||||||
|
private String uniqueCode;
|
||||||
|
private String workflow;
|
||||||
|
private String requestUrl;
|
||||||
|
private String cusSql;
|
||||||
|
private String enable;
|
||||||
|
private String tableName;
|
||||||
|
private List<DetailRequestConfig> detailRequestConfigList;
|
||||||
|
}
|
|
@ -0,0 +1,50 @@
|
||||||
|
package weaver.xuanran.wang.epdi.datapush.mapper;
|
||||||
|
|
||||||
|
import aiyh.utils.annotation.recordset.CaseConversion;
|
||||||
|
import aiyh.utils.annotation.recordset.ParamMapper;
|
||||||
|
import aiyh.utils.annotation.recordset.Select;
|
||||||
|
import aiyh.utils.annotation.recordset.SqlMapper;
|
||||||
|
import weaver.xuanran.wang.epdi.datapush.constant.RequestPushConstant;
|
||||||
|
import weaver.xuanran.wang.epdi.datapush.eneity.DetailRequestConfig;
|
||||||
|
import weaver.xuanran.wang.epdi.datapush.eneity.MainRequestConfig;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* <h1>数据推送配置mapper</h1>
|
||||||
|
*
|
||||||
|
* @Author xuanran.wang
|
||||||
|
* @Date 2022/12/1 14:35
|
||||||
|
*/
|
||||||
|
@SqlMapper
|
||||||
|
public interface RequestPushMapper {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* <h1>获取配置表主表对象</h1>
|
||||||
|
* @author xuanran.wang
|
||||||
|
* @dateTime 2022/12/1 14:39
|
||||||
|
* @return 主表配置对象
|
||||||
|
**/
|
||||||
|
@Select("select a.*,b.tablename tableName " +
|
||||||
|
"from "+ RequestPushConstant.MODEL_TABLE_NAME +" a " +
|
||||||
|
"left join workflow_table_view b " +
|
||||||
|
"on a.workFlow = b.id " +
|
||||||
|
"where uniqueCode = #{uniqueCode} and enable = " + RequestPushConstant.CONFIG_ENABLE)
|
||||||
|
@CaseConversion(value = false)
|
||||||
|
MainRequestConfig getRequestPushMainConfig(@ParamMapper("uniqueCode") String uniqueCod);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* <h1>获取配置表明细对象集合</h1>
|
||||||
|
* @author xuanran.wang
|
||||||
|
* @dateTime 2022/12/1 14:40
|
||||||
|
* @param mainId 主表主数据id
|
||||||
|
* @return 明细配置集合
|
||||||
|
**/
|
||||||
|
@Select("select a.*,b.fieldname workFlowFieldName " +
|
||||||
|
"from "+ RequestPushConstant.MODEL_TABLE_NAME + "_dt1 a " +
|
||||||
|
"left join workflow_field_table_view b " +
|
||||||
|
"on a.workFlowField = b.id " +
|
||||||
|
"where mainid = #{mainId} and enable = " + RequestPushConstant.CONFIG_ENABLE)
|
||||||
|
@CaseConversion(value = false)
|
||||||
|
List<DetailRequestConfig> getRequestPushDetailConfig(@ParamMapper("mainId") String mainId);
|
||||||
|
}
|
|
@ -0,0 +1,401 @@
|
||||||
|
package weaver.xuanran.wang.epdi.datapush.service;
|
||||||
|
|
||||||
|
import aiyh.utils.Util;
|
||||||
|
import aiyh.utils.excention.CustomerException;
|
||||||
|
import com.alibaba.fastjson.JSONObject;
|
||||||
|
import org.apache.commons.lang3.StringUtils;
|
||||||
|
import org.apache.log4j.Logger;
|
||||||
|
import org.springframework.util.Assert;
|
||||||
|
import weaver.conn.RecordSet;
|
||||||
|
import weaver.xuanran.wang.epdi.datapush.constant.RequestPushConstant;
|
||||||
|
import weaver.xuanran.wang.epdi.datapush.eneity.DetailRequestConfig;
|
||||||
|
import weaver.xuanran.wang.epdi.datapush.eneity.MainRequestConfig;
|
||||||
|
import weaver.xuanran.wang.epdi.datapush.mapper.RequestPushMapper;
|
||||||
|
import weaver.zwl.common.ToolUtil;
|
||||||
|
|
||||||
|
import java.text.ParseException;
|
||||||
|
import java.text.SimpleDateFormat;
|
||||||
|
import java.util.*;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* <h1>上海电力设计院数据推送业务方法</h1>
|
||||||
|
*
|
||||||
|
* @Author xuanran.wang
|
||||||
|
* @Date 2022/12/23 16:20
|
||||||
|
*/
|
||||||
|
public class RequestPushService {
|
||||||
|
private final RequestPushMapper requestPushMapper = Util.getMapper(RequestPushMapper.class);
|
||||||
|
private String tempTableName = "";
|
||||||
|
private final ToolUtil toolUtil = new ToolUtil();
|
||||||
|
|
||||||
|
private final Logger logger = Util.getLogger();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* <h1>获取配置对象</h1>
|
||||||
|
* @author xuanran.wang
|
||||||
|
* @dateTime 2022/12/1 15:09
|
||||||
|
* @param uniqueCode 唯一标识
|
||||||
|
* @return 配置对象
|
||||||
|
**/
|
||||||
|
public MainRequestConfig getRequestPushConfigByUniqueCode(String uniqueCode){
|
||||||
|
MainRequestConfig requestPushMainConfig = requestPushMapper.getRequestPushMainConfig(uniqueCode);
|
||||||
|
Assert.notNull(requestPushMainConfig,"主表配置对象获取为空, 请检查!");
|
||||||
|
List<DetailRequestConfig> requestPushDetailConfig = requestPushMapper.getRequestPushDetailConfig(requestPushMainConfig.getId());
|
||||||
|
Assert.notEmpty(requestPushDetailConfig, "明细表配置集合获取为空, 请检查!");
|
||||||
|
requestPushMainConfig.setDetailRequestConfigList(requestPushDetailConfig);
|
||||||
|
return requestPushMainConfig;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* <h1>根据配置转换流程表单</h1>
|
||||||
|
* @author xuanran.wang
|
||||||
|
* @dateTime 2022/12/23 17:17
|
||||||
|
* @param mainRequestConfig 建模配置对象
|
||||||
|
* @param requestId 请求id
|
||||||
|
* @return 转换后的流程参数map
|
||||||
|
**/
|
||||||
|
public Map<String, Object> getRequestParam(MainRequestConfig mainRequestConfig, String requestId){
|
||||||
|
HashMap<String, Object> res = new HashMap<>();
|
||||||
|
// 请求配置的表
|
||||||
|
try {
|
||||||
|
List<DetailRequestConfig> configList = mainRequestConfig.getDetailRequestConfigList();
|
||||||
|
// 过滤根节点
|
||||||
|
List<DetailRequestConfig> rootNodeList = configList
|
||||||
|
.stream()
|
||||||
|
.filter(item -> RequestPushConstant.ROOT_NODE.equals(item.getParentName()))
|
||||||
|
.collect(Collectors.toList());
|
||||||
|
// 设置子节点
|
||||||
|
for (DetailRequestConfig detailRequestConfig : rootNodeList) {
|
||||||
|
setChildList(detailRequestConfig, configList);
|
||||||
|
}
|
||||||
|
String workflowType = mainRequestConfig.getWorkflow();
|
||||||
|
if(StringUtils.isBlank(workflowType)){
|
||||||
|
setObjValue(rootNodeList, res, null, null);
|
||||||
|
}else {
|
||||||
|
String mainTableName = mainRequestConfig.getTableName();
|
||||||
|
this.tempTableName = mainTableName;
|
||||||
|
RecordSet mainRs = new RecordSet();
|
||||||
|
String sql = "select * from " + mainTableName + " where requestid = ?";
|
||||||
|
if (mainRs.executeQuery(sql,requestId)) {
|
||||||
|
if (mainRs.next()) {
|
||||||
|
setObjValue(rootNodeList, res, mainRs, null);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}catch (Exception e){
|
||||||
|
throw new RuntimeException("执行getRequestParam发生异常 : " + e.getMessage());
|
||||||
|
}
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* <h1><递归设置子对象/h1>
|
||||||
|
* @author xuanran.wang
|
||||||
|
* @dateTime 2022/12/23 17:16
|
||||||
|
* @param detailRequestConfig 明细配置对象
|
||||||
|
* @param detailRequestConfigList 明细配置对象集合
|
||||||
|
**/
|
||||||
|
private void setChildList(DetailRequestConfig detailRequestConfig, List<DetailRequestConfig> detailRequestConfigList){
|
||||||
|
try {
|
||||||
|
// 节点类型
|
||||||
|
String paramNodeType = detailRequestConfig.getParamNodeType();
|
||||||
|
// 参数名称
|
||||||
|
String paramName = detailRequestConfig.getParamName();
|
||||||
|
// 递归设置子节点
|
||||||
|
if(!RequestPushConstant.PARAM_NODE_TYPE_GENERAL.equals(paramNodeType)){
|
||||||
|
List<DetailRequestConfig> childList =
|
||||||
|
detailRequestConfigList.stream().filter(
|
||||||
|
config -> paramName.equals(config.getParentName())
|
||||||
|
).collect(Collectors.toList());
|
||||||
|
detailRequestConfig.setDetailRequestConfigList(childList);
|
||||||
|
for (DetailRequestConfig requestConfig : childList) {
|
||||||
|
setChildList(requestConfig, detailRequestConfigList);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}catch (Exception e){
|
||||||
|
throw new RuntimeException("执行setChildList发生异常 : " + e.getMessage());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* <h1>设置对象类型配置参数值</h1>
|
||||||
|
* @author xuanran.wang
|
||||||
|
* @dateTime 2022/12/23 17:25
|
||||||
|
* @param configList 配置集合
|
||||||
|
* @param res map
|
||||||
|
* @param mainRs 主表结果集
|
||||||
|
* @param detailRs 明细结果集
|
||||||
|
**/
|
||||||
|
private void setObjValue(List<DetailRequestConfig> configList, HashMap<String, Object> res, RecordSet mainRs, RecordSet detailRs) {
|
||||||
|
try {
|
||||||
|
for (DetailRequestConfig requestConfig : configList) {
|
||||||
|
// 参数类型
|
||||||
|
String paramType = requestConfig.getParamNodeType();
|
||||||
|
String paramName = requestConfig.getParamName();
|
||||||
|
List<DetailRequestConfig> childConfigList = requestConfig.getDetailRequestConfigList();
|
||||||
|
// 集合
|
||||||
|
if (RequestPushConstant.PARAM_NODE_TYPE_LIST.equals(paramType)) {
|
||||||
|
List<Object> list = new ArrayList<>();
|
||||||
|
setListValue(requestConfig,childConfigList, list, mainRs);
|
||||||
|
res.put(paramName, list);
|
||||||
|
} else if (RequestPushConstant.PARAM_NODE_TYPE_OBJ.equals(paramType)) {
|
||||||
|
// 对象
|
||||||
|
HashMap<String, Object> map = new HashMap<>();
|
||||||
|
this.setObjValue(childConfigList, map, mainRs, detailRs);
|
||||||
|
}else{
|
||||||
|
// 普通对象
|
||||||
|
Object value = setCommonParamValue(requestConfig, mainRs, detailRs);
|
||||||
|
res.put(paramName, value);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}catch (Exception e){
|
||||||
|
throw new RuntimeException("执行setObjValue发生异常 : " + e.getMessage());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* <h1>设置集合类型配置参数值</h1>
|
||||||
|
* @author xuanran.wang
|
||||||
|
* @dateTime 2022/12/23 17:26
|
||||||
|
* @param detailRequestConfig 配置对象
|
||||||
|
* @param childList 子节点配置集合
|
||||||
|
* @param list 当前配置对象的集合
|
||||||
|
* @param mainRs 主表结果集
|
||||||
|
**/
|
||||||
|
private void setListValue(DetailRequestConfig detailRequestConfig,
|
||||||
|
List<DetailRequestConfig> childList,
|
||||||
|
List<Object> list,
|
||||||
|
RecordSet mainRs) {
|
||||||
|
try {
|
||||||
|
// 子项数据来源
|
||||||
|
String dataSource = detailRequestConfig.getDataSource();
|
||||||
|
// 主表
|
||||||
|
if (RequestPushConstant.DATASOURCE_MAIN_TABLE.equals(dataSource)) {
|
||||||
|
HashMap<String, Object> map = new HashMap<>();
|
||||||
|
this.setObjValue(childList, map, mainRs, null);
|
||||||
|
list.add(map);
|
||||||
|
}else if(RequestPushConstant.DATASOURCE_DETAIL_TABLE.equals(dataSource)){
|
||||||
|
// 子表
|
||||||
|
int mainId = weaver.general.Util.getIntValue(mainRs.getString("id"));
|
||||||
|
String sql = "select * from " + tempTableName + "_dt" + detailRequestConfig.getDetailIndex() + " where mainid = " + mainId;
|
||||||
|
RecordSet detailRs = new RecordSet();
|
||||||
|
if(detailRs.executeQuery(sql)){
|
||||||
|
while (detailRs.next()) {
|
||||||
|
HashMap<String, Object> map = new HashMap<>();
|
||||||
|
this.setObjValue(childList, map, mainRs, detailRs);
|
||||||
|
list.add(map);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}catch (Exception e){
|
||||||
|
throw new RuntimeException("执行setListValue发生异常 : " + e.getMessage());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* <h1>设置普通参数类型配置参数值</h1>
|
||||||
|
* @author xuanran.wang
|
||||||
|
* @dateTime 2022/12/23 17:27
|
||||||
|
* @param detailRequestConfig 配置对象
|
||||||
|
* @param mainRs 主表结果集
|
||||||
|
* @param detailRs 明细结果集
|
||||||
|
* @return 转化后的值
|
||||||
|
**/
|
||||||
|
private Object setCommonParamValue(DetailRequestConfig detailRequestConfig, RecordSet mainRs, RecordSet detailRs){
|
||||||
|
String paramType = detailRequestConfig.getParamType();
|
||||||
|
String getValueType = detailRequestConfig.getGetValueType();
|
||||||
|
String valueContext = detailRequestConfig.getValueContext();
|
||||||
|
String dataSource = detailRequestConfig.getDataSource();
|
||||||
|
String paramName = detailRequestConfig.getParamName();
|
||||||
|
String requestId = "";
|
||||||
|
int mainId = -1;
|
||||||
|
if(null != mainRs){
|
||||||
|
requestId = mainRs.getString("requestid");
|
||||||
|
mainId = Util.getIntValue(mainRs.getString("id"));
|
||||||
|
}
|
||||||
|
int detailId = -1;
|
||||||
|
if(null != detailRs){
|
||||||
|
detailId = Util.getIntValue(detailRs.getString("id"));
|
||||||
|
}
|
||||||
|
Object value = "";
|
||||||
|
switch (getValueType) {
|
||||||
|
// 流程字段
|
||||||
|
case RequestPushConstant.CONVERT_RULES_TABLE_FIELD: {
|
||||||
|
value = getRecordsetVal(detailRequestConfig, mainRs, detailRs);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
// 默认值
|
||||||
|
case RequestPushConstant.CONVERT_RULES_DEFAULT: {
|
||||||
|
value = getRecordsetVal(detailRequestConfig, mainRs, detailRs);
|
||||||
|
value = Util.null2String(valueContext)
|
||||||
|
.replace("{?requestid}", requestId)
|
||||||
|
.replace("{?}", String.valueOf(value));
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
// 当前时间
|
||||||
|
case RequestPushConstant.CONVERT_RULES_NOW_TIME: {
|
||||||
|
value = new Date();
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
// 自定义sql查询
|
||||||
|
case RequestPushConstant.CONVERT_RULES_CUS_SQL: {
|
||||||
|
String tempValue = Util.null2DefaultStr(getRecordsetVal(detailRequestConfig, mainRs, detailRs),"");
|
||||||
|
value = toolUtil.getValueByChangeRule(valueContext, tempValue, requestId, detailId);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
// requestId
|
||||||
|
case RequestPushConstant.CONVERT_RULES_REQUEST_ID: {
|
||||||
|
value = requestId;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
// 数据id
|
||||||
|
case RequestPushConstant.CONVERT_RULES_DATA_ID: {
|
||||||
|
if (RequestPushConstant.DATASOURCE_MAIN_TABLE.equals(dataSource)) {
|
||||||
|
value = mainId;
|
||||||
|
} else {
|
||||||
|
value = detailId;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
throw new CustomerException("不支持的取值方式");
|
||||||
|
}
|
||||||
|
switch (paramType) {
|
||||||
|
// String类型
|
||||||
|
case RequestPushConstant.DATA_TYPE_STRING: {
|
||||||
|
value = Util.null2DefaultStr(value, "");
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
// int类型
|
||||||
|
case RequestPushConstant.DATA_TYPE_INT: {
|
||||||
|
value = Util.getIntValue(Util.null2DefaultStr(value, ""),0);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
// double类型
|
||||||
|
case RequestPushConstant.DATA_TYPE_DOUBLE: {
|
||||||
|
value = Util.getDoubleValue(Util.null2DefaultStr(value, ""),0.00);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
// 日期类型
|
||||||
|
case RequestPushConstant.DATA_TYPE_DATE: {
|
||||||
|
if (Objects.isNull(value)) {
|
||||||
|
value = "";
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
Date date = value instanceof Date ? (Date) value : parseDate(String.valueOf(value));
|
||||||
|
value = this.diyDateFortMat(date, "yyyy-MM-dd");
|
||||||
|
} catch (Exception e) {
|
||||||
|
throw new CustomerException("时间处理异常:参数>>" + paramName);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
// 时间日期类型
|
||||||
|
case RequestPushConstant.DATA_TYPE_DATE_TIME: {
|
||||||
|
if (Objects.isNull(value)) {
|
||||||
|
value = "";
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
Date date = value instanceof Date ? (Date) value : parseDate(String.valueOf(value));
|
||||||
|
value = this.diyDateFortMat(date, "yyyy-MM-dd HH:mm:ss");
|
||||||
|
} catch (Exception e) {
|
||||||
|
throw new CustomerException("时间处理异常:参数>>" + paramName + " 异常信息:" + e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
// 自定义时间格式化类型
|
||||||
|
case RequestPushConstant.DATA_TYPE_CUS_DATE: {
|
||||||
|
if (Objects.isNull(value)) {
|
||||||
|
value = "";
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
Date date = value instanceof Date ? (Date) value : parseDate(String.valueOf(value));
|
||||||
|
value = this.diyDateFortMat(date, valueContext);
|
||||||
|
} catch (Exception e) {
|
||||||
|
throw new CustomerException("时间处理异常:参数>>" + paramName + " 异常信息:" + e.getMessage());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
// 时间戳类型
|
||||||
|
case RequestPushConstant.DATA_TYPE_TIME_TIMESTAMP: {
|
||||||
|
if (Objects.isNull(value)) {
|
||||||
|
value = "";
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
Date date = value instanceof Date ? (Date) value : parseDate(String.valueOf(value));
|
||||||
|
assert date != null;
|
||||||
|
value = date.getTime();
|
||||||
|
} catch (Exception e) {
|
||||||
|
throw new CustomerException("时间处理异常:参数>>" + paramName + " 异常信息:" + e.getMessage());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
default: return value;
|
||||||
|
}
|
||||||
|
return value;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* <h1>获取表单字段的值</h1>
|
||||||
|
* @author xuanran.wang
|
||||||
|
* @dateTime 2022/12/23 17:42
|
||||||
|
* @param config 配置对象
|
||||||
|
* @param mainRs 主表结果集
|
||||||
|
* @param detailRs 明细表结果集
|
||||||
|
* @return 结果集中的值
|
||||||
|
**/
|
||||||
|
public Object getRecordsetVal(DetailRequestConfig config, RecordSet mainRs, RecordSet detailRs){
|
||||||
|
String fieldName = config.getWorkFlowFieldName();
|
||||||
|
String dataSource = config.getDataSource();
|
||||||
|
if(StringUtils.isBlank(fieldName) || StringUtils.isBlank(dataSource)){
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
Object value = "";
|
||||||
|
if (RequestPushConstant.DATASOURCE_MAIN_TABLE.equals(dataSource)) {
|
||||||
|
value = Util.null2DefaultStr(mainRs.getString(fieldName),"");
|
||||||
|
} else {
|
||||||
|
value = Util.null2DefaultStr(detailRs.getString(fieldName),"");
|
||||||
|
}
|
||||||
|
return value;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* <h1>将日期字符串转换为Date对象</h1>
|
||||||
|
*
|
||||||
|
* @param dateStr 日期字符串
|
||||||
|
* @return 日期对象
|
||||||
|
*/
|
||||||
|
private static Date parseDate(String dateStr) {
|
||||||
|
ThreadLocal<SimpleDateFormat> SIMPLE_DATE_FORMAT = ThreadLocal.withInitial(() -> new SimpleDateFormat("yyyy-MM-dd"));
|
||||||
|
if (dateStr == null || dateStr.length() == 0) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
String regex = "\\/|\\.|年|月|日";
|
||||||
|
Date date = null;
|
||||||
|
try {
|
||||||
|
date = SIMPLE_DATE_FORMAT.get().parse(dateStr.replaceAll(regex, "-"));
|
||||||
|
return date;
|
||||||
|
} catch (ParseException e) {
|
||||||
|
throw new CustomerException("无法将" + dateStr + "转换为日期对象!", e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 自定义时间格式化
|
||||||
|
*
|
||||||
|
* @param date 日期
|
||||||
|
* @param tempStr 格式化字符串
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
private String diyDateFortMat(Date date, String tempStr) {
|
||||||
|
SimpleDateFormat simpleDateFormat = new SimpleDateFormat(tempStr);
|
||||||
|
return simpleDateFormat.format(date);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}
|
|
@ -5,7 +5,7 @@ import lombok.*;
|
||||||
import java.sql.Timestamp;
|
import java.sql.Timestamp;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* <h1></h1>
|
* <h1>数据同步配置实体类</h1>
|
||||||
*
|
*
|
||||||
* @Author xuanran.wang
|
* @Author xuanran.wang
|
||||||
* @Date 2022/12/1 14:01
|
* @Date 2022/12/1 14:01
|
||||||
|
@ -48,4 +48,16 @@ public class DataAsyncDetail {
|
||||||
* <h2>数据来源建模字段名称</h2>
|
* <h2>数据来源建模字段名称</h2>
|
||||||
**/
|
**/
|
||||||
private String dataSourceModelFiledName;
|
private String dataSourceModelFiledName;
|
||||||
|
/**
|
||||||
|
* <h2>更新条件</h2>
|
||||||
|
**/
|
||||||
|
private String updateCriteria;
|
||||||
|
/**
|
||||||
|
* <h2>更新字段</h2>
|
||||||
|
**/
|
||||||
|
private String updateField;
|
||||||
|
/**
|
||||||
|
* <h2>主表还是明细表</h2>
|
||||||
|
**/
|
||||||
|
private String mainOrDetail;
|
||||||
}
|
}
|
||||||
|
|
|
@ -22,5 +22,6 @@ public class DataAsyncMain {
|
||||||
private String cusWhere;
|
private String cusWhere;
|
||||||
private String modelTypeTableName;
|
private String modelTypeTableName;
|
||||||
private String asyncTargetModelTableName;
|
private String asyncTargetModelTableName;
|
||||||
|
private String detailIndex;
|
||||||
private List<DataAsyncDetail> dataAsyncDetailList;
|
private List<DataAsyncDetail> dataAsyncDetailList;
|
||||||
}
|
}
|
||||||
|
|
|
@ -76,4 +76,12 @@ public class DataAsyncConstant {
|
||||||
* <h2>转换类型-拆分复制</h2>
|
* <h2>转换类型-拆分复制</h2>
|
||||||
**/
|
**/
|
||||||
public static final String CONVERT_RULES_SPLIT_COPY = "5";
|
public static final String CONVERT_RULES_SPLIT_COPY = "5";
|
||||||
|
/**
|
||||||
|
* <h2>主表</h2>
|
||||||
|
**/
|
||||||
|
public static final String MAIN_TABLE = "0";
|
||||||
|
/**
|
||||||
|
* <h2>明细</h2>
|
||||||
|
**/
|
||||||
|
public static final String DETAIL_TABLE = "1";
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,12 +10,12 @@ import weaver.xuanran.wang.saic_travel.model_data_async.service.DataAsyncConfigS
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* <h1>员工信息同步至建模</h1>
|
* <h1>信息同步至建模</h1>
|
||||||
*
|
*
|
||||||
* @Author xuanran.wang
|
* @Author xuanran.wang
|
||||||
* @Date 2022/12/1 15:20
|
* @Date 2022/12/1 15:20
|
||||||
*/
|
*/
|
||||||
public class HrmDataToModelAsync extends BaseCronJob {
|
public class CusDataToModelAsync extends BaseCronJob {
|
||||||
|
|
||||||
private final Logger logger = Util.getLogger();
|
private final Logger logger = Util.getLogger();
|
||||||
|
|
||||||
|
@ -30,9 +30,11 @@ public class HrmDataToModelAsync extends BaseCronJob {
|
||||||
@Override
|
@Override
|
||||||
public void execute() {
|
public void execute() {
|
||||||
try {
|
try {
|
||||||
|
logger.info("------------ CusDataToModelAsync Begin ------------");
|
||||||
CommonUtil.checkParamNotNull(this);
|
CommonUtil.checkParamNotNull(this);
|
||||||
DataAsyncMain dataAsyncConfigByUniqueCode = asyncConfigService.getDataAsyncConfigByUniqueCode(uniqueCode);
|
DataAsyncMain dataAsyncConfigByUniqueCode = asyncConfigService.getDataAsyncConfigByUniqueCode(uniqueCode);
|
||||||
asyncConfigService.asyncModelData(dataAsyncConfigByUniqueCode, Util.getIntValue(modelId, -1));
|
asyncConfigService.asyncModelData(dataAsyncConfigByUniqueCode, Util.getIntValue(modelId, -1));
|
||||||
|
logger.info("------------ CusDataToModelAsync End ------------");
|
||||||
}catch (Exception e){
|
}catch (Exception e){
|
||||||
logger.error(Util.logStr("执行数据同步计划任务失败!异常信息 : {}", e.getMessage()));
|
logger.error(Util.logStr("执行数据同步计划任务失败!异常信息 : {}", e.getMessage()));
|
||||||
}
|
}
|
|
@ -18,6 +18,4 @@ public interface DataAsyncMapper {
|
||||||
@CaseConversion(false)
|
@CaseConversion(false)
|
||||||
RecordSet getRecordSetByCusSql(@SqlString String sql);
|
RecordSet getRecordSetByCusSql(@SqlString String sql);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,9 +2,12 @@ package weaver.xuanran.wang.saic_travel.model_data_async.service;
|
||||||
|
|
||||||
import aiyh.utils.Util;
|
import aiyh.utils.Util;
|
||||||
import aiyh.utils.excention.CustomerException;
|
import aiyh.utils.excention.CustomerException;
|
||||||
|
import aiyh.utils.zwl.common.ToolUtil;
|
||||||
import com.alibaba.fastjson.JSONObject;
|
import com.alibaba.fastjson.JSONObject;
|
||||||
|
import org.apache.commons.collections.MapUtils;
|
||||||
import org.apache.commons.lang3.StringUtils;
|
import org.apache.commons.lang3.StringUtils;
|
||||||
import org.apache.log4j.Logger;
|
import org.apache.log4j.Logger;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.springframework.util.Assert;
|
import org.springframework.util.Assert;
|
||||||
import org.springframework.util.CollectionUtils;
|
import org.springframework.util.CollectionUtils;
|
||||||
import weaver.conn.RecordSet;
|
import weaver.conn.RecordSet;
|
||||||
|
@ -14,8 +17,6 @@ import weaver.xuanran.wang.saic_travel.model_data_async.config.eneity.DataAsyncD
|
||||||
import weaver.xuanran.wang.saic_travel.model_data_async.config.eneity.DataAsyncMain;
|
import weaver.xuanran.wang.saic_travel.model_data_async.config.eneity.DataAsyncMain;
|
||||||
import weaver.xuanran.wang.saic_travel.model_data_async.config.mapper.DataAsyncConfigMapper;
|
import weaver.xuanran.wang.saic_travel.model_data_async.config.mapper.DataAsyncConfigMapper;
|
||||||
import weaver.xuanran.wang.saic_travel.model_data_async.constant.DataAsyncConstant;
|
import weaver.xuanran.wang.saic_travel.model_data_async.constant.DataAsyncConstant;
|
||||||
import weaver.xuanran.wang.saic_travel.model_data_async.mapper.DataAsyncMapper;
|
|
||||||
import weaver.zwl.common.ToolUtil;
|
|
||||||
|
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
@ -65,17 +66,51 @@ public class DataAsyncConfigService {
|
||||||
}
|
}
|
||||||
logger.info("selectSql : " + selectSql);
|
logger.info("selectSql : " + selectSql);
|
||||||
List<LinkedHashMap<String, Object>> linkedHashMapList = new ArrayList<>();
|
List<LinkedHashMap<String, Object>> linkedHashMapList = new ArrayList<>();
|
||||||
|
StringBuilder updateWhereSql = new StringBuilder();
|
||||||
|
// 需要更新时候的参数集合
|
||||||
|
List<LinkedHashMap<String, Object>> updateLinkedList = new ArrayList<>();
|
||||||
|
// 判断是否更新sql的参数
|
||||||
|
List<List<String>> updateWhereParam = new ArrayList<>();
|
||||||
int splitCopy = -1;
|
int splitCopy = -1;
|
||||||
String splitCopyFiledName = "";
|
String splitCopyFiledName = "";
|
||||||
// 复制个数
|
// 复制个数
|
||||||
List<DataAsyncDetail> splitCopyList = asyncDetailList.stream().filter(item -> DataAsyncConstant.CONVERT_RULES_SPLIT_COPY.equals(item.getConvertRules())).collect(Collectors.toList());
|
List<DataAsyncDetail> splitCopyList = asyncDetailList.stream().filter(item -> DataAsyncConstant.CONVERT_RULES_SPLIT_COPY.equals(item.getConvertRules())).collect(Collectors.toList());
|
||||||
|
DataAsyncDetail copyAsyncDetail = null;
|
||||||
if(!CollectionUtils.isEmpty(splitCopyList)){
|
if(!CollectionUtils.isEmpty(splitCopyList)){
|
||||||
DataAsyncDetail detail = splitCopyList.get(0);
|
DataAsyncDetail detail = splitCopyList.get(0);
|
||||||
|
copyAsyncDetail = detail;
|
||||||
splitCopy = Util.getIntValue(detail.getCusText(),-1);
|
splitCopy = Util.getIntValue(detail.getCusText(),-1);
|
||||||
splitCopyFiledName = Util.null2DefaultStr(detail.getAsyncModelTableField(),"");
|
splitCopyFiledName = Util.null2DefaultStr(detail.getAsyncModelTableField(),"");
|
||||||
}
|
}
|
||||||
|
// 更新数据条件
|
||||||
|
List<String> updateCriteriaList = asyncDetailList.stream()
|
||||||
|
.filter(item -> DataAsyncConstant.CONFIG_ENABLE.equals(item.getUpdateCriteria()))
|
||||||
|
.map(DataAsyncDetail::getAsyncModelTableField)
|
||||||
|
.collect(Collectors.toList());
|
||||||
|
// 更新字段
|
||||||
|
List<String> 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()){
|
while (rs.next()){
|
||||||
|
// 建模表插入参数
|
||||||
LinkedHashMap<String, Object> linkedHashMap = new LinkedHashMap<>();
|
LinkedHashMap<String, Object> linkedHashMap = new LinkedHashMap<>();
|
||||||
|
// 如果数据存在更新参数集合
|
||||||
|
LinkedHashMap<String, Object> updateLinkedMap = new LinkedHashMap<>();
|
||||||
|
// 更新条件参数
|
||||||
|
LinkedHashMap<String, String> updateParam = new LinkedHashMap<>();
|
||||||
int tempCount = 0;
|
int tempCount = 0;
|
||||||
for (DataAsyncDetail dataAsyncDetail : asyncDetailList) {
|
for (DataAsyncDetail dataAsyncDetail : asyncDetailList) {
|
||||||
String field = "";
|
String field = "";
|
||||||
|
@ -88,20 +123,49 @@ public class DataAsyncConfigService {
|
||||||
}break;
|
}break;
|
||||||
default:throw new CustomerException("暂不支持的数据来源");
|
default:throw new CustomerException("暂不支持的数据来源");
|
||||||
}
|
}
|
||||||
|
// 同步建模字段
|
||||||
|
String asyncModelTableField = dataAsyncDetail.getAsyncModelTableField();
|
||||||
Object value = getFieldValue(rs, field, dataAsyncDetail, tempCount);
|
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);
|
linkedHashMapList.add(linkedHashMap);
|
||||||
|
if(MapUtils.isNotEmpty(updateLinkedMap)){
|
||||||
|
updateLinkedList.add(updateLinkedMap);
|
||||||
|
}
|
||||||
// 记录复制
|
// 记录复制
|
||||||
while (++tempCount < splitCopy) {
|
while (++tempCount < splitCopy) {
|
||||||
LinkedHashMap<String, Object> copyMap = new LinkedHashMap<>(linkedHashMap);
|
LinkedHashMap<String, Object> copyMap = new LinkedHashMap<>(linkedHashMap);
|
||||||
|
// 如果更新条件参数map不为空
|
||||||
|
if(MapUtils.isNotEmpty(updateLinkedMap)){
|
||||||
|
// 需要更新的参数map集合
|
||||||
|
LinkedHashMap<String, Object> 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);
|
copyMap.put(splitCopyFiledName, tempCount);
|
||||||
linkedHashMapList.add(copyMap);
|
linkedHashMapList.add(copyMap);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
List<String> list = CusInfoToOAUtil.executeBatch(modelId, linkedHashMapList);
|
return CusInfoToOAUtil.executeBatch(modelId, linkedHashMapList, updateWhereSql.toString(), updateWhereParam, true, updateLinkedList);
|
||||||
return list;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* <h1>根据配置将值转换</h1>
|
* <h1>根据配置将值转换</h1>
|
||||||
* @author xuanran.wang
|
* @author xuanran.wang
|
||||||
|
@ -112,7 +176,7 @@ public class DataAsyncConfigService {
|
||||||
* @param count 复制次数
|
* @param count 复制次数
|
||||||
* @return 转换后的值
|
* @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 convertRules = dataAsyncDetail.getConvertRules();
|
||||||
String dataType = dataAsyncDetail.getDataType();
|
String dataType = dataAsyncDetail.getDataType();
|
||||||
String cusText = dataAsyncDetail.getCusText();
|
String cusText = dataAsyncDetail.getCusText();
|
||||||
|
@ -135,12 +199,14 @@ public class DataAsyncConfigService {
|
||||||
// 自定义sql查询
|
// 自定义sql查询
|
||||||
case DataAsyncConstant.CONVERT_RULES_CUS_SQL: {
|
case DataAsyncConstant.CONVERT_RULES_CUS_SQL: {
|
||||||
if(!StringUtils.isBlank(cusText)){
|
if(!StringUtils.isBlank(cusText)){
|
||||||
String cusSql = Util.sbc2dbcCase(cusText);
|
|
||||||
String where = "";
|
String where = "";
|
||||||
if(StringUtils.isNotBlank(field)){
|
if(StringUtils.isNotBlank(field)){
|
||||||
where = Util.null2DefaultStr(recordSet.getString(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()) {
|
if (!tempRs.next()) {
|
||||||
logger.error(Util.logStr("执行自定义sql失败!当前sql:{}, 当前参数:{}", cusSql, where));
|
logger.error(Util.logStr("执行自定义sql失败!当前sql:{}, 当前参数:{}", cusSql, where));
|
||||||
break;
|
break;
|
||||||
|
@ -150,6 +216,7 @@ public class DataAsyncConfigService {
|
||||||
}break;
|
}break;
|
||||||
case DataAsyncConstant.CONVERT_RULES_DATA_ID: {
|
case DataAsyncConstant.CONVERT_RULES_DATA_ID: {
|
||||||
value = recordSet.getString("id");
|
value = recordSet.getString("id");
|
||||||
|
logger.info(Util.logStr("主数据Id : {}", value));
|
||||||
}break;
|
}break;
|
||||||
case DataAsyncConstant.CONVERT_RULES_SPLIT_COPY: {
|
case DataAsyncConstant.CONVERT_RULES_SPLIT_COPY: {
|
||||||
value = count;
|
value = count;
|
||||||
|
@ -236,30 +303,33 @@ public class DataAsyncConfigService {
|
||||||
* @return 查询数据来源sql
|
* @return 查询数据来源sql
|
||||||
**/
|
**/
|
||||||
public String getSelectSql(DataAsyncMain asyncConfig){
|
public String getSelectSql(DataAsyncMain asyncConfig){
|
||||||
String dataSource = asyncConfig.getDataSource();
|
|
||||||
String cusWhere = Util.null2DefaultStr(asyncConfig.getCusWhere(), "");
|
String cusWhere = Util.null2DefaultStr(asyncConfig.getCusWhere(), "");
|
||||||
String dataSourceTableName = "";
|
|
||||||
List<DataAsyncDetail> asyncDetailList = asyncConfig.getDataAsyncDetailList();
|
|
||||||
String selectSql = "select ";
|
|
||||||
List<String> 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
|
// 拼接数据源查询sql
|
||||||
selectSql += StringUtils.join(modelFieldList, ",") + " from " + dataSourceTableName;
|
String selectSql = "select * from " + getTableName(asyncConfig);
|
||||||
if(StringUtils.isNotBlank(cusWhere)){
|
if(StringUtils.isNotBlank(cusWhere)){
|
||||||
selectSql += " where " + cusWhere;
|
selectSql += " where " + cusWhere;
|
||||||
}
|
}
|
||||||
return selectSql;
|
return selectSql;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* <h1>根据配置对象获取查询sql</h1>
|
||||||
|
* @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("暂不支持的数据来源!");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,14 +1,27 @@
|
||||||
package weaver.xuanran.wang.schroeder.action;
|
package weaver.xuanran.wang.schroeder.action;
|
||||||
|
|
||||||
import aiyh.utils.Util;
|
import aiyh.utils.Util;
|
||||||
import aiyh.utils.action.CusBaseAction;
|
import aiyh.utils.action.SafeCusBaseAction;
|
||||||
import aiyh.utils.annotation.RequiredMark;
|
import aiyh.utils.annotation.RequiredMark;
|
||||||
import aiyh.utils.excention.CustomerException;
|
import aiyh.utils.excention.CustomerException; // 自定义异常类 create 2022/3/9 2:20 PM
|
||||||
|
import com.alibaba.fastjson.JSONObject;
|
||||||
|
import com.alibaba.fastjson.JSONPObject;
|
||||||
|
import org.apache.commons.lang3.StringUtils;
|
||||||
|
import weaver.conn.RecordSet;
|
||||||
import weaver.conn.RecordSetTrans;
|
import weaver.conn.RecordSetTrans;
|
||||||
import weaver.hrm.User;
|
import weaver.hrm.User;
|
||||||
import weaver.workflow.request.RequestManager;
|
import weaver.soa.workflow.request.RequestInfo;
|
||||||
|
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 weaver.xuanran.wang.schroeder.service.SchroederQRCodeService;
|
||||||
|
|
||||||
|
import java.lang.reflect.Constructor;
|
||||||
|
import java.lang.reflect.InvocationTargetException;
|
||||||
|
import java.util.*;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* <h1>施罗德创建二维码action</h1>
|
* <h1>施罗德创建二维码action</h1>
|
||||||
|
@ -16,7 +29,7 @@ import weaver.xuanran.wang.schroeder.service.SchroederQRCodeService;
|
||||||
* @Author xuanran.wang
|
* @Author xuanran.wang
|
||||||
* @Date 2022/11/30 16:08
|
* @Date 2022/11/30 16:08
|
||||||
*/
|
*/
|
||||||
public class PushSealTaskAction extends CusBaseAction {
|
public class PushSealTaskAction extends SafeCusBaseAction { // 基础的action,实现一些基础的参数
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* <h2>建模配置唯一标识</h2>
|
* <h2>建模配置唯一标识</h2>
|
||||||
|
@ -30,24 +43,170 @@ public class PushSealTaskAction extends CusBaseAction {
|
||||||
@RequiredMark
|
@RequiredMark
|
||||||
private String QRCodeField;
|
private String QRCodeField;
|
||||||
|
|
||||||
private final SchroederQRCodeService schroederQRCodeService = new SchroederQRCodeService();
|
/**
|
||||||
|
* <h2>用印文件字段 会将这个字段所有的值存到用印文件记录表中</h2>
|
||||||
|
**/
|
||||||
|
@RequiredMark
|
||||||
|
private String fileField;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* <h2>文档记录表模块id</h2>
|
||||||
|
**/
|
||||||
|
@RequiredMark
|
||||||
|
private String docLogModelId;
|
||||||
|
|
||||||
@Override
|
/**
|
||||||
public void doSubmit(String requestId, String billTable, int workflowId, User user, RequestManager requestManager) {
|
* <h2>requestId记录表模块id</h2>
|
||||||
|
**/
|
||||||
|
@RequiredMark
|
||||||
|
private String requestIdLogModelId;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* <h2>开门盖章种类</h2>
|
||||||
|
**/
|
||||||
|
@RequiredMark
|
||||||
|
private String filePeopleType;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* <h2>明细序列</h2>
|
||||||
|
**/
|
||||||
|
@RequiredMark
|
||||||
|
private String detailNo;
|
||||||
|
/**
|
||||||
|
* <h2>响应成功状态码</h2>
|
||||||
|
**/
|
||||||
|
@RequiredMark
|
||||||
|
private String successCode;
|
||||||
|
/**
|
||||||
|
* <h2>响应任务字段</h2>
|
||||||
|
**/
|
||||||
|
@RequiredMark
|
||||||
|
private String backField;
|
||||||
|
/**
|
||||||
|
* <h2>前置接口</h2>
|
||||||
|
**/
|
||||||
|
private String cusBeforeProcessor;
|
||||||
|
/**
|
||||||
|
* <h2>请求格式</h2>
|
||||||
|
**/
|
||||||
|
private String type;
|
||||||
|
|
||||||
|
private final SchroederQRCodeService schroederQRCodeService = new SchroederQRCodeService(); // 施罗德业务方法 施罗德业务方法
|
||||||
|
|
||||||
|
@Override // action 提交流程业务处理方法 具体业务逻辑实现
|
||||||
|
public void doSubmit(String requestId, String billTable, int workflowId, User user, RequestInfo requestInfo) {
|
||||||
log.info("---------- PushSealTaskSealValue Begin " + requestId + "----------");
|
log.info("---------- PushSealTaskSealValue Begin " + requestId + "----------");
|
||||||
String scanNum = schroederQRCodeService.pushSealTask(onlyMark, billTable, requestId);
|
String delSql = "";
|
||||||
RecordSetTrans trans = requestManager.getRsTrans();
|
String mainId = "";
|
||||||
|
RecordSetTrans trans = new RecordSetTrans();
|
||||||
trans.setAutoCommit(false);
|
trans.setAutoCommit(false);
|
||||||
String updateSql = "update " + billTable + " set " + QRCodeField + " = ? where requestid = ?";
|
// 插入模块的参数集合
|
||||||
|
List<String> requestIdLogModelIdList = new ArrayList<>();
|
||||||
|
List<String> docLogModelIdList = new ArrayList<>();
|
||||||
|
// 前置接口做了添加明细表的操作 最后是否需要删除添加的明细
|
||||||
|
boolean del = false;
|
||||||
|
// 执行前置处理 默认添加一行明细
|
||||||
|
if(StringUtils.isNotBlank(cusBeforeProcessor)){
|
||||||
|
Map<String, String> 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{
|
try{
|
||||||
if(!trans.executeUpdate(updateSql, scanNum, requestId)){
|
mainId = mainRs.getString("id");
|
||||||
throw new CustomerException(Util.logStr("更新表单sql执行失败!sql : {}, 参数 scanNum : {}, requestId : {}", scanNum, requestId));
|
String detailTable = billTable + "_dt" + detailNo;
|
||||||
|
if(StringUtils.isNotBlank(mainId)){
|
||||||
|
delSql = "delete from " + detailTable + " where mainid = ? ";
|
||||||
}
|
}
|
||||||
|
try{
|
||||||
|
List<String> detailFileId = schroederQRCodeService.getDetailFileId(fileField, detailTable, mainId);
|
||||||
|
log.info(Util.logStr("明细docId集合 : {}", JSONObject.toJSONString(detailFileId)));
|
||||||
|
List<LinkedHashMap<String, Object>> docLogParamList = new ArrayList<>();
|
||||||
|
for (String docId : detailFileId) {
|
||||||
|
LinkedHashMap<String, Object> map = new LinkedHashMap<>();
|
||||||
|
map.put("docId", docId);
|
||||||
|
map.put("enable", 0);
|
||||||
|
docLogParamList.add(map);
|
||||||
|
}
|
||||||
|
log.info(Util.logStr("docLogParamList集合 : {}", JSONObject.toJSONString(docLogParamList)));
|
||||||
|
// 将docLog数据写入建模
|
||||||
|
docLogModelIdList = CusInfoToOAUtil.executeBatch(Util.getIntValue(docLogModelId, -1), docLogParamList);
|
||||||
|
// requestLog写入建模
|
||||||
|
LinkedHashMap<String, Object> 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 构建日志字符串
|
||||||
|
}
|
||||||
|
|
||||||
}catch (Exception e){
|
}catch (Exception e){
|
||||||
|
CommonUtil.deleteDataByIds(requestIdLogModelIdList, Util.getIntValue(requestIdLogModelId,-1));
|
||||||
|
CommonUtil.deleteDataByIds(docLogModelIdList, Util.getIntValue(docLogModelId,-1));
|
||||||
trans.rollback();
|
trans.rollback();
|
||||||
throw new CustomerException(Util.logStr("执行提交方法异常:{}", e.getMessage()));
|
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();
|
trans.commit();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* <h2>执行自定义后置处理方法</h2>
|
||||||
|
*
|
||||||
|
* @param className 全路径类名
|
||||||
|
* @return 返回值
|
||||||
|
*/
|
||||||
|
private boolean executeBeforeProcessor(String className, RequestInfo requestInfo,
|
||||||
|
RequestMappingConfig requestMappingConfig,
|
||||||
|
Map<String, String> 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);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,45 @@
|
||||||
|
package weaver.xuanran.wang.schroeder.action;
|
||||||
|
|
||||||
|
import aiyh.utils.Util;
|
||||||
|
import weaver.interfaces.workflow.action.Action;
|
||||||
|
import weaver.soa.workflow.request.RequestInfo;
|
||||||
|
import weaver.xuanran.wang.schroeder.service.SchroederQRCodeService;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* <h1>施罗德强制结束任务action</h1>
|
||||||
|
*
|
||||||
|
* @Author xuanran.wang
|
||||||
|
* @Date 2022/12/23 10:49
|
||||||
|
*/
|
||||||
|
public class SalesforceEndpointAction implements Action {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* <h2>建模配置唯一标识</h2>
|
||||||
|
**/
|
||||||
|
private String onlyMark;
|
||||||
|
/**
|
||||||
|
* <h2>响应成功状态码</h2>
|
||||||
|
**/
|
||||||
|
private String successCode;
|
||||||
|
/**
|
||||||
|
* <h2>请求方式</h2>
|
||||||
|
**/
|
||||||
|
private String type;
|
||||||
|
|
||||||
|
private final SchroederQRCodeService schroederQRCodeService = new SchroederQRCodeService();
|
||||||
|
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String execute(RequestInfo requestInfo) {
|
||||||
|
try {
|
||||||
|
String billTable = requestInfo.getRequestManager().getBillTableName();
|
||||||
|
String requestId = requestInfo.getRequestid();
|
||||||
|
schroederQRCodeService.pushSealTask(onlyMark, billTable, requestId,type, successCode,"","");
|
||||||
|
return Action.SUCCESS;
|
||||||
|
}catch (Exception e){
|
||||||
|
requestInfo.getRequestManager().setMessageid(String.valueOf(System.currentTimeMillis()));
|
||||||
|
requestInfo.getRequestManager().setMessagecontent(Util.logStr("执行提交方法异常:{}", e.getMessage()));
|
||||||
|
return Action.FAILURE_AND_CONTINUE;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -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;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* <h1>将主表数据插入到明细</h1>
|
||||||
|
*
|
||||||
|
* @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<String, String> 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<String, Object> 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<Object> args = sqlResult.getArgs();
|
||||||
|
if (!rs.executeUpdate(sqlStr, args)) {
|
||||||
|
throw new CustomerException(Util.logStr("明细数据插入失败! sql : {}, params : {}", sqlStr, JSONObject.toJSONString(args)));
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -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;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* <h1>前置接口处理</h1>
|
||||||
|
*
|
||||||
|
* @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<String, String> pathParam);
|
||||||
|
}
|
|
@ -1,17 +1,17 @@
|
||||||
package weaver.xuanran.wang.schroeder.cus_field_value;
|
package weaver.xuanran.wang.schroeder.cus_field_value;
|
||||||
|
|
||||||
import aiyh.utils.Util;
|
import aiyh.utils.Util;
|
||||||
import aiyh.utils.excention.CustomerException;
|
import aiyh.utils.excention.CustomerException; // 自定义异常类 create 2022/3/9 2:20 PM
|
||||||
import com.alibaba.fastjson.JSONObject;
|
import com.alibaba.fastjson.JSONObject;
|
||||||
import org.apache.commons.collections.MapUtils;
|
import org.apache.commons.collections.MapUtils;
|
||||||
import org.apache.commons.lang3.StringUtils;
|
import org.apache.commons.lang3.StringUtils;
|
||||||
import org.apache.log4j.Logger;
|
import org.apache.log4j.Logger;
|
||||||
|
import weaver.conn.ConnStatementDataSource;
|
||||||
import weaver.conn.RecordSet;
|
import weaver.conn.RecordSet;
|
||||||
import weaver.xiao.commons.config.interfacies.CusInterfaceGetValue;
|
import weaver.xiao.commons.config.interfacies.CusInterfaceGetValue; // 自定义获取参数值
|
||||||
import weaver.zwl.common.ToolUtil;
|
|
||||||
|
|
||||||
|
import java.sql.SQLException;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
import java.util.stream.Collectors;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* <h1></h1>
|
* <h1></h1>
|
||||||
|
@ -19,12 +19,11 @@ import java.util.stream.Collectors;
|
||||||
* @Author xuanran.wang
|
* @Author xuanran.wang
|
||||||
* @Date 2022/12/2 16:10
|
* @Date 2022/12/2 16:10
|
||||||
*/
|
*/
|
||||||
public class PushSealTaskSealValue implements CusInterfaceGetValue {
|
public class PushSealTaskSealValue implements CusInterfaceGetValue { // 自定义获取参数值
|
||||||
private final ToolUtil toolUtil = new ToolUtil();
|
|
||||||
|
|
||||||
private final Logger logger = Util.getLogger();
|
private final Logger logger = Util.getLogger(); // 获取日志对象
|
||||||
|
|
||||||
@Override
|
@Override // 获取参数值
|
||||||
public Object execute(Map<String, Object> mainMap, Map<String, Object> detailMap, String currentValue, Map<String, String> pathParam) {
|
public Object execute(Map<String, Object> mainMap, Map<String, Object> detailMap, String currentValue, Map<String, String> pathParam) {
|
||||||
logger.info(Util.logStr("路径参数:[{}]", JSONObject.toJSONString(pathParam)));
|
logger.info(Util.logStr("路径参数:[{}]", JSONObject.toJSONString(pathParam)));
|
||||||
// 接口字段
|
// 接口字段
|
||||||
|
@ -36,9 +35,8 @@ public class PushSealTaskSealValue implements CusInterfaceGetValue {
|
||||||
String sealNumCusSql = pathParam.get("sealNumCusSql");
|
String sealNumCusSql = pathParam.get("sealNumCusSql");
|
||||||
// 非空校验
|
// 非空校验
|
||||||
if(checkBlank(sealSnField, sealNumField, sealSnCusSql, sealNumCusSql)){
|
if(checkBlank(sealSnField, sealNumField, sealSnCusSql, sealNumCusSql)){
|
||||||
throw new CustomerException(Util.logStr("自定义类路径中必要参数为空,请检查!当前pathParam : {}", JSONObject.toJSONString(pathParam)));
|
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)){
|
if(StringUtils.isBlank(currentValue)){
|
||||||
return Collections.emptyList();
|
return Collections.emptyList();
|
||||||
|
@ -47,11 +45,19 @@ public class PushSealTaskSealValue implements CusInterfaceGetValue {
|
||||||
int detailId = -1;
|
int detailId = -1;
|
||||||
if(MapUtils.isNotEmpty(detailMap)){
|
if(MapUtils.isNotEmpty(detailMap)){
|
||||||
detailId = Util.getIntValue(String.valueOf(detailMap.get("id")), -1);
|
detailId = Util.getIntValue(String.valueOf(detailMap.get("id")), -1);
|
||||||
|
if(detailId < 0){
|
||||||
|
detailId = Util.getIntValue(String.valueOf(detailMap.get("ID")), -1);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
String requestId = String.valueOf(mainMap.get("requestid"));
|
||||||
|
if(StringUtils.isBlank(requestId)){
|
||||||
|
requestId = String.valueOf(mainMap.get("REQUESTID"));
|
||||||
|
}
|
||||||
|
logger.info(Util.logStr("requestId : {}, detailId : {}", requestId, detailId));
|
||||||
for (String val : currentValue.split(",")) {
|
for (String val : currentValue.split(",")) {
|
||||||
// 印章类型转换执行自定义sql
|
// 印章类型转换执行自定义sql
|
||||||
String inSealVal = Util.null2DefaultStr(toolUtil.getValueByChangeRule(sealSnCusSql, val, String.valueOf(mainMap.get("requestid")), detailId),"");
|
String inSealVal = Util.null2DefaultStr(getValueByChangeRule(sealSnCusSql, val, requestId, detailId,""),""); // 用数据库值,根据规则转换,获取其最终结果
|
||||||
String inSealNumVal = Util.null2DefaultStr(toolUtil.getValueByChangeRule(sealNumCusSql, val, String.valueOf(mainMap.get("requestid")), detailId),"");
|
String inSealNumVal = Util.null2DefaultStr(getValueByChangeRule(sealNumCusSql, val, requestId, detailId,""),""); // 用数据库值,根据规则转换,获取其最终结果
|
||||||
HashMap<String, Object> map = new HashMap<>();
|
HashMap<String, Object> map = new HashMap<>();
|
||||||
map.put(sealSnField, inSealVal);
|
map.put(sealSnField, inSealVal);
|
||||||
map.put(sealNumField, inSealNumVal);
|
map.put(sealNumField, inSealNumVal);
|
||||||
|
@ -60,7 +66,88 @@ public class PushSealTaskSealValue implements CusInterfaceGetValue {
|
||||||
return list;
|
return list;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 用数据库值,根据规则转换,获取其最终结果
|
||||||
|
* @param cus_sql 自定义转换的SQL
|
||||||
|
* @param value 参数值
|
||||||
|
* @param requestid 流程请求ID
|
||||||
|
* @param detailKeyvalue 明细表主键值
|
||||||
|
* @pram datasourceid 外部数据源ID
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public String getValueByChangeRule(String cus_sql,String value,String requestid,int detailKeyvalue,String datasourceid){
|
||||||
|
String endValue = "";
|
||||||
|
|
||||||
|
cus_sql = cus_sql.replace(" ", " ");
|
||||||
|
|
||||||
|
cus_sql = cus_sql.replace("{?dt.id}", String.valueOf(detailKeyvalue));
|
||||||
|
|
||||||
|
//参数进行替换
|
||||||
|
String sqlString = cus_sql.replace("{?requestid}", requestid);
|
||||||
|
|
||||||
|
sqlString = sqlString.replace("?", value);
|
||||||
|
|
||||||
|
sqlString = ToDBC(sqlString);
|
||||||
|
logger.info(Util.logStr("查询sql : {} ", sqlString));
|
||||||
|
try {
|
||||||
|
if(datasourceid != null && !"".equals(datasourceid)){
|
||||||
|
ConnStatementDataSource csds = new ConnStatementDataSource(datasourceid);
|
||||||
|
|
||||||
|
csds.setStatementSql(sqlString);
|
||||||
|
|
||||||
|
csds.executeQuery();
|
||||||
|
|
||||||
|
if(csds.next()){
|
||||||
|
endValue = weaver.general.Util.null2String(csds.getString(1));
|
||||||
|
}
|
||||||
|
|
||||||
|
csds.close();
|
||||||
|
}else{
|
||||||
|
|
||||||
|
RecordSet rs = new RecordSet();
|
||||||
|
if(rs.executeQuery(sqlString)){
|
||||||
|
if (rs.next()) {
|
||||||
|
endValue = weaver.general.Util.null2String(rs.getString(1));
|
||||||
|
logger.info(Util.logStr("执行自定义sql 返回结果 : {}", endValue));
|
||||||
|
}else {
|
||||||
|
logger.error("当前查询没有查询结果!");
|
||||||
|
}
|
||||||
|
}else {
|
||||||
|
logger.error("当前sql查询失败!");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (SQLException e) {
|
||||||
|
// TODO Auto-generated catch block
|
||||||
|
e.printStackTrace();
|
||||||
|
} catch (Exception e) {
|
||||||
|
// TODO Auto-generated catch block
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
|
||||||
|
return endValue;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 全角转半角
|
||||||
|
* @param input
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public String ToDBC(String input) {
|
||||||
|
char c[] = input.toCharArray();
|
||||||
|
for (int i = 0; i < c.length; i++) {
|
||||||
|
if (c[i] == '\u3000') {
|
||||||
|
c[i] = ' ';
|
||||||
|
} else if (c[i] > '\uFF00' && c[i] < '\uFF5F') {
|
||||||
|
c[i] = (char) (c[i] - 65248);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
String returnString = new String(c);
|
||||||
|
return returnString;
|
||||||
|
}
|
||||||
|
|
||||||
public boolean checkBlank(String ... args){
|
public boolean checkBlank(String ... args){
|
||||||
return Arrays.stream(args).anyMatch(StringUtils::isBlank);
|
return Arrays.stream(args).anyMatch(StringUtils::isBlank);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,61 @@
|
||||||
|
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;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* <h1>施罗德查询方法</h1>
|
||||||
|
*
|
||||||
|
* @Author xuanran.wang
|
||||||
|
* @Date 2022/12/13 13:05
|
||||||
|
*/
|
||||||
|
@SqlMapper
|
||||||
|
public interface SchroederMapper {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* <h1>查询明细一数据集</h1>
|
||||||
|
* @author xuanran.wang
|
||||||
|
* @dateTime 2022/12/13 13:10
|
||||||
|
* @param tableName 表名
|
||||||
|
* @param mainId 主表id
|
||||||
|
* @return 明细表数据集合
|
||||||
|
**/
|
||||||
|
@Select("select yywj,qfzzl,qfzcs from $t{tableName} where mainid = #{mainId} and sfjgqfz = 0")
|
||||||
|
List<Map<String, Object>> selectSealTaskInfoList(@ParamMapper("tableName") String tableName,
|
||||||
|
@ParamMapper("mainId") String mainId);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* <h1>查询明细一用印文件docId/h1>
|
||||||
|
* @author xuanran.wang
|
||||||
|
* @dateTime 2022/12/13 13:10
|
||||||
|
* @param fileField 用印文件字段
|
||||||
|
* @param tableName 表名
|
||||||
|
* @param mainId 主表id
|
||||||
|
* @return 明细表数据集合
|
||||||
|
**/
|
||||||
|
@Select("select $t{fileField} from $t{tableName} where mainid = #{mainId}")
|
||||||
|
List<String> selectSealFileList(@ParamMapper("fileField") String fileField,
|
||||||
|
@ParamMapper("tableName") String tableName,
|
||||||
|
@ParamMapper("mainId") String mainId);
|
||||||
|
/**
|
||||||
|
* <h1>得到任务Id</h1>
|
||||||
|
* @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<Map<String, Object>> detailList(@ParamMapper("tableName") String tableName,
|
||||||
|
@ParamMapper("mainId") String mainId);
|
||||||
|
}
|
|
@ -1,23 +1,27 @@
|
||||||
package weaver.xuanran.wang.schroeder.service;
|
package weaver.xuanran.wang.schroeder.service;
|
||||||
|
|
||||||
import aiyh.utils.Util;
|
import aiyh.utils.Util;
|
||||||
import aiyh.utils.excention.CustomerException;
|
import aiyh.utils.excention.CustomerException; // 自定义异常类 create 2022/3/9 2:20 PM
|
||||||
import aiyh.utils.httpUtil.ResponeVo;
|
import aiyh.utils.httpUtil.ResponeVo;
|
||||||
import aiyh.utils.httpUtil.util.HttpUtils;
|
import aiyh.utils.httpUtil.util.HttpUtils;
|
||||||
import com.alibaba.fastjson.JSON;
|
import com.alibaba.fastjson.JSON;
|
||||||
import com.alibaba.fastjson.JSONObject;
|
import com.alibaba.fastjson.JSONObject;
|
||||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||||
import com.google.zxing.qrcode.encoder.QRCode;
|
import org.apache.commons.collections.CollectionUtils;
|
||||||
import org.apache.commons.lang3.StringUtils;
|
import org.apache.commons.lang3.StringUtils;
|
||||||
import org.apache.log4j.Logger;
|
import org.apache.log4j.Logger;
|
||||||
import weaver.conn.RecordSet;
|
import weaver.conn.RecordSet;
|
||||||
import weaver.mobile.plugin.ecology.QRCodeComInfo;
|
|
||||||
import weaver.xiao.commons.config.entity.RequestMappingConfig;
|
import weaver.xiao.commons.config.entity.RequestMappingConfig;
|
||||||
import weaver.xiao.commons.config.service.DealWithMapping;
|
import weaver.xiao.commons.config.service.DealWithMapping;
|
||||||
|
import weaver.xuanran.wang.schroeder.mapper.SchroederMapper;
|
||||||
|
|
||||||
import javax.ws.rs.core.MediaType;
|
import javax.ws.rs.core.MediaType;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* <h1>施罗德业务方法</h1>
|
* <h1>施罗德业务方法</h1>
|
||||||
|
@ -27,10 +31,6 @@ import java.util.Map;
|
||||||
*/
|
*/
|
||||||
public class SchroederQRCodeService {
|
public class SchroederQRCodeService {
|
||||||
private static final int SUCCESS_CODE = 200;
|
private static final int SUCCESS_CODE = 200;
|
||||||
/**
|
|
||||||
* <h2>成功状态码</h2>
|
|
||||||
**/
|
|
||||||
private static final int SUCCESS_STATUS= 0;
|
|
||||||
/**
|
/**
|
||||||
* <h2>接口响应信息</h2>
|
* <h2>接口响应信息</h2>
|
||||||
**/
|
**/
|
||||||
|
@ -43,72 +43,245 @@ public class SchroederQRCodeService {
|
||||||
* <h2>接口响应状态字段</h2>
|
* <h2>接口响应状态字段</h2>
|
||||||
**/
|
**/
|
||||||
private static final String STATUS_FIELD = "status";
|
private static final String STATUS_FIELD = "status";
|
||||||
|
/**
|
||||||
|
* <h2>get</h2>
|
||||||
|
**/
|
||||||
|
public static final String GET = "GET";
|
||||||
|
/**
|
||||||
|
* <h2>post</h2>
|
||||||
|
**/
|
||||||
|
public static final String POST = "POST";
|
||||||
|
/**
|
||||||
|
* <h2>requestId记录表名</h2>
|
||||||
|
**/
|
||||||
private final DealWithMapping dealWithMapping = new DealWithMapping();
|
private final DealWithMapping dealWithMapping = new DealWithMapping();
|
||||||
private final Logger log = Util.getLogger();
|
private final Logger log = Util.getLogger(); // 获取日志对象
|
||||||
private final HttpUtils httpUtils = new HttpUtils();
|
private final HttpUtils httpUtils = new HttpUtils();
|
||||||
|
|
||||||
{
|
{
|
||||||
httpUtils.getGlobalCache().header.put("Content-Type", MediaType.APPLICATION_JSON);
|
httpUtils.getGlobalCache().header.put("Content-Type", MediaType.APPLICATION_JSON); // 全局请求头
|
||||||
|
}
|
||||||
|
|
||||||
|
private final SchroederMapper schroederMapper = Util.getMapper(SchroederMapper.class);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* <h1>推送数据</h1>
|
||||||
|
*
|
||||||
|
* @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 type,
|
||||||
|
String successCode, String backField,String filePeopleType) {
|
||||||
|
RequestMappingConfig requestMappingConfig = dealWithMapping.treeDealWithUniqueCode(onlyMark); // 将配置参数通过唯一标识查询处理成树形结构
|
||||||
|
Map<String, Object> 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 构建日志字符串
|
||||||
|
}
|
||||||
|
return parseResponseVo(responeVo, url, requestParam, successCode, backField);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* <h1>推送数据创建任务</h1>
|
* <h1>解析响应对象</h1>
|
||||||
* @author xuanran.wang
|
* @author xuanran.wang
|
||||||
* @dateTime 2022/12/5 17:05
|
* @dateTime 2022/12/23 11:25
|
||||||
* @param onlyMark 唯一编码
|
* @param responseVo 响应对象
|
||||||
* @param billTable 表名
|
* @param url 地址
|
||||||
* @param requestId 请求id
|
* @param requestParam 请求
|
||||||
* @return 响应数据
|
* @param successCode 成功响应标识
|
||||||
|
* @param backField 回传字段
|
||||||
|
* @return 回传字段的值
|
||||||
**/
|
**/
|
||||||
public String pushSealTask(String onlyMark, String billTable, String requestId){
|
private String parseResponseVo(ResponeVo responseVo, String url,
|
||||||
|
Map<String, Object> requestParam,
|
||||||
|
String successCode, String backField){
|
||||||
String res = "";
|
String res = "";
|
||||||
RequestMappingConfig requestMappingConfig = dealWithMapping.treeDealWithUniqueCode(onlyMark);
|
Map<String, String> headers = httpUtils.getGlobalCache().header;// 全局请求头
|
||||||
String cusWhere = Util.null2DefaultStr(requestMappingConfig.getCusWhereSql(),"");
|
if (responseVo.getCode() != SUCCESS_CODE) { // 相应状态码
|
||||||
if(StringUtils.isNotBlank(cusWhere)){
|
log.error(Util.logStr("can not fetch [{}],this request params is [{}]," + // 构建日志字符串
|
||||||
cusWhere = DealWithMapping.sbc2dbcCase(cusWhere);
|
"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 构建日志字符串
|
||||||
}
|
}
|
||||||
String selectMainSql = "select * from " + billTable + " where requestid = ? " + cusWhere;
|
Map<String, Object> response;
|
||||||
log.info("查询主表数据sql { " + selectMainSql + " }, requestId { " + requestId + " }");
|
log.info(Util.logStr("this response is [{}]", responseVo.getEntityString())); // 构建日志字符串 相应内容
|
||||||
RecordSet recordSet = new RecordSet();
|
try {
|
||||||
recordSet.executeQuery(selectMainSql, requestId);
|
response = responseVo.getEntityMap(); // 根据相应结果转化为map集合
|
||||||
if (recordSet.next()) {
|
} catch (JsonProcessingException e) {
|
||||||
dealWithMapping.setMainTable(billTable);
|
log.error(Util.logStr("push data error, can not parse response to map," + // 构建日志字符串
|
||||||
Map<String, Object> requestParam = dealWithMapping.getRequestParam(recordSet, requestMappingConfig);
|
"this response is [{}], url is [{}],request params is [{}], request heard is [{}];",
|
||||||
log.info(Util.logStr("请求json : {}", JSONObject.toJSONString(requestParam)));
|
responseVo.getEntityString(), url, JSON.toJSONString(requestParam), JSON.toJSONString(headers))); // 相应内容
|
||||||
String url = requestMappingConfig.getRequestUrl();
|
throw new CustomerException(Util.logStr("push data error, can not parse response to map")); // 自定义异常类 create 2022/3/9 2:20 PM 构建日志字符串
|
||||||
ResponeVo responeVo = null;
|
|
||||||
try {
|
|
||||||
responeVo = httpUtils.apiPost(url, requestParam);
|
|
||||||
} catch (IOException e) {
|
|
||||||
throw new CustomerException(Util.logStr("发送印章请求发生异常! : {}", e.getMessage()));
|
|
||||||
}
|
|
||||||
Map<String, String> 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));
|
|
||||||
}
|
|
||||||
Map<String, Object> response;
|
|
||||||
log.info(Util.logStr("this response is [{}]", responeVo.getEntityString()));
|
|
||||||
try {
|
|
||||||
response = responeVo.getEntityMap();
|
|
||||||
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"));
|
|
||||||
}
|
|
||||||
int status = (int) response.get(STATUS_FIELD);
|
|
||||||
if(SUCCESS_STATUS != status){
|
|
||||||
throw new CustomerException(Util.logStr("接口响应码不为0,接口响应信息:{}", Util.null2DefaultStr(response.get(MESSAGE_FIELD),"")));
|
|
||||||
}
|
|
||||||
res = Util.null2DefaultStr(response.get(SCAN_NUM_FIELD),"");
|
|
||||||
}
|
}
|
||||||
if(StringUtils.isBlank(res)){
|
String status = Util.null2DefaultStr(response.get(STATUS_FIELD), "");
|
||||||
throw new CustomerException("获取接口中响应任务字段为空, 请检查!");
|
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;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* <h1>根据配置获取响应信息</h1>
|
||||||
|
* @author xuanran.wang
|
||||||
|
* @dateTime 2022/12/23 11:02
|
||||||
|
* @param requestMappingConfig 请求配置主体
|
||||||
|
* @param billTable 表名
|
||||||
|
* @param requestId 请求id
|
||||||
|
* @param filePeopleType 骑缝章的filePeopleType
|
||||||
|
* @return 参数配置map
|
||||||
|
**/
|
||||||
|
public Map<String, Object> 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<String, Object> 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;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* <h1>骑缝章修改请求参数</h1>
|
||||||
|
*
|
||||||
|
* @param requestParam 请求参数
|
||||||
|
* @param billTable 表名
|
||||||
|
* @param mainId 主表id
|
||||||
|
* @author xuanran.wang
|
||||||
|
* @dateTime 2022/12/13 14:15
|
||||||
|
**/
|
||||||
|
public void changeRequestMap(Map<String, Object> requestParam, String billTable, String mainId, String filePeopleType) {
|
||||||
|
List<Map<String, Object>> files = (List<Map<String, Object>>) requestParam.get("file");
|
||||||
|
if (CollectionUtils.isEmpty(files)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
RecordSet detailRs = new RecordSet();
|
||||||
|
String sql = "select yywj,qfzzl,qfzcs from " + billTable + " where mainid = ? and sfjgqfz = 0";
|
||||||
|
if(!detailRs.executeQuery(sql, mainId)){
|
||||||
|
throw new CustomerException(Util.logStr("查询明细数据sql执行失败!sql : {}, mainId : {}", sql, mainId));
|
||||||
|
}
|
||||||
|
// 貌似有bug 把mapper改成原生recordSet
|
||||||
|
while (detailRs.next()) {
|
||||||
|
// 用印文件
|
||||||
|
String sealFile = Util.null2String(detailRs.getString("yywj"));
|
||||||
|
if(StringUtils.isBlank(sealFile)){
|
||||||
|
sealFile = Util.null2String(detailRs.getString("YYWJ"));
|
||||||
|
}
|
||||||
|
// 从生成的请求参数map中开始匹配
|
||||||
|
String finalSealFile = sealFile;
|
||||||
|
List<Map<String, Object>> filterFiles = files.stream()
|
||||||
|
.filter(item -> {
|
||||||
|
String filePath = Util.null2DefaultStr(item.get("fileUrlPath"), "");
|
||||||
|
String docId = Util.null2DefaultStr(filePath.substring(filePath.lastIndexOf("=") + 1), "");
|
||||||
|
return finalSealFile.equals(docId);
|
||||||
|
})
|
||||||
|
.collect(Collectors.toList());
|
||||||
|
log.info(Util.logStr("filterFiles : {} ", JSONObject.toJSONString(finalSealFile)));
|
||||||
|
if (CollectionUtils.isNotEmpty(filterFiles)) {
|
||||||
|
// 只有一个能匹配
|
||||||
|
Map<String, Object> o = filterFiles.get(0);
|
||||||
|
HashMap<String, Object> tempMap = o.entrySet().stream().collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue, (a, b) -> a, HashMap::new));
|
||||||
|
// 印章集合
|
||||||
|
List<HashMap<String, Object>> sealList = new ArrayList<>();
|
||||||
|
HashMap<String, Object> seal = new HashMap<>();
|
||||||
|
// 骑缝章总类
|
||||||
|
String qfzzl = Util.null2DefaultStr(detailRs.getString("qfzzl"),"");
|
||||||
|
if(StringUtils.isBlank(qfzzl)){
|
||||||
|
qfzzl = Util.null2DefaultStr(detailRs.getString("QFZZL"),"");
|
||||||
|
}
|
||||||
|
log.info(Util.logStr("骑缝章总类 : {}", qfzzl));
|
||||||
|
seal.put("sealSn", qfzzl);
|
||||||
|
String qfzcs = Util.null2DefaultStr(detailRs.getString("qfzcs"),"");
|
||||||
|
if(StringUtils.isBlank(qfzcs)){
|
||||||
|
qfzcs = Util.null2DefaultStr(detailRs.getString("QFZCS"),"");
|
||||||
|
}
|
||||||
|
log.info(Util.logStr("骑缝章次数 : {}", qfzcs));
|
||||||
|
seal.put("sealNum", Util.null2DefaultStr(qfzcs, "0"));
|
||||||
|
sealList.add(seal);
|
||||||
|
tempMap.put("seal", sealList);
|
||||||
|
tempMap.put("filePeopleType", filePeopleType);
|
||||||
|
files.add(tempMap);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* <h1>获取taskId</h1>
|
||||||
|
*
|
||||||
|
* @return 任务id
|
||||||
|
* @author xuanran.wang
|
||||||
|
* @dateTime 2022/12/21 9:42
|
||||||
|
**/
|
||||||
|
public Integer getTaskIdByRequestId(String requestId) {
|
||||||
|
return schroederMapper.selectTaskId(requestId);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* <h1>获取明细数据</h1>
|
||||||
|
*
|
||||||
|
* @param tableName 明细表名
|
||||||
|
* @param mainId 主id
|
||||||
|
* @return 明细表数据
|
||||||
|
* @author xuanran.wang
|
||||||
|
* @dateTime 2022/12/21 18:03
|
||||||
|
**/
|
||||||
|
public List<Map<String, Object>> getDetailList(String tableName, String mainId) {
|
||||||
|
return schroederMapper.detailList(tableName, mainId);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* <h1>获取明细1文件数据id</h1>
|
||||||
|
*
|
||||||
|
* @param fileField 用印文件字段名
|
||||||
|
* @param tableName 明细表名
|
||||||
|
* @param mainId 主id
|
||||||
|
* @return 明细表数据
|
||||||
|
* @author xuanran.wang
|
||||||
|
* @dateTime 2022/12/21 18:03
|
||||||
|
**/
|
||||||
|
public List<String> getDetailFileId(String fileField,String tableName, String mainId) {
|
||||||
|
return schroederMapper.selectSealFileList(fileField,tableName, mainId);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,67 @@
|
||||||
|
package weaver.xuanran.wang.shyl.mq;
|
||||||
|
|
||||||
|
import aiyh.utils.Util;
|
||||||
|
import aiyh.utils.excention.CustomerException;
|
||||||
|
import org.apache.log4j.Logger;
|
||||||
|
import org.apache.rocketmq.client.consumer.DefaultMQPushConsumer;
|
||||||
|
import org.apache.rocketmq.client.consumer.listener.MessageListenerConcurrently;
|
||||||
|
|
||||||
|
import javax.servlet.ServletException;
|
||||||
|
import javax.servlet.http.HttpServlet;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* <h1>上海团校RocketMQListener</h1>
|
||||||
|
*
|
||||||
|
* @Author xuanran.wang
|
||||||
|
* @Date 2022/12/29 12:25
|
||||||
|
*/
|
||||||
|
public abstract class RocketMQConsumerListener extends HttpServlet {
|
||||||
|
private static final Logger log = Util.getLogger();
|
||||||
|
private String configName;
|
||||||
|
public RocketMQConsumerListener() {
|
||||||
|
}
|
||||||
|
public RocketMQConsumerListener(String configName) {
|
||||||
|
this.configName = configName;
|
||||||
|
}
|
||||||
|
@Override
|
||||||
|
public void init() throws ServletException {
|
||||||
|
super.init();
|
||||||
|
initialized();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* <h1>消费者初始化</h1>
|
||||||
|
* @author xuanran.wang
|
||||||
|
* @dateTime 2022/12/29 21:48
|
||||||
|
**/
|
||||||
|
public void initialized() {
|
||||||
|
DefaultMQPushConsumer consumer = null;
|
||||||
|
log.info(Util.logStr("---- consumer : {} initialized start ----", configName));
|
||||||
|
try {
|
||||||
|
try {
|
||||||
|
// 根据配置文件初始化一个consumer对象
|
||||||
|
consumer = RocketMQFactory.getMQPushConsumer(configName, service());
|
||||||
|
}catch (Exception e){
|
||||||
|
throw new CustomerException(Util.logStr("the consumer init exception : {}", e.getMessage()));
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
// 调用start()方法启动consumer
|
||||||
|
consumer.start();
|
||||||
|
}catch (Exception e){
|
||||||
|
throw new CustomerException(Util.logStr("the consumer start exception : {}", e.getMessage()));
|
||||||
|
}
|
||||||
|
log.info(Util.logStr("---- consumer : {} initialized end ----", configName));
|
||||||
|
}catch (Exception e){
|
||||||
|
log.info(Util.logStr("---- consumer : {} initialized error ----", configName));
|
||||||
|
log.error(Util.getErrString(e));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* <h1>每个消费者自定义的消费业务方法</h1>
|
||||||
|
* @author xuanran.wang
|
||||||
|
* @dateTime 2022/12/29 21:49
|
||||||
|
* @return MessageListenerConcurrently 消费者消费方法
|
||||||
|
**/
|
||||||
|
public abstract MessageListenerConcurrently service();
|
||||||
|
}
|
|
@ -0,0 +1,120 @@
|
||||||
|
package weaver.xuanran.wang.shyl.mq;
|
||||||
|
|
||||||
|
import aiyh.utils.Util;
|
||||||
|
import aiyh.utils.excention.CustomerException;
|
||||||
|
import org.apache.rocketmq.client.consumer.DefaultMQPushConsumer;
|
||||||
|
import org.apache.rocketmq.client.consumer.listener.MessageListenerConcurrently;
|
||||||
|
import org.apache.rocketmq.client.exception.MQClientException;
|
||||||
|
import org.apache.rocketmq.client.producer.DefaultMQProducer;
|
||||||
|
import org.apache.rocketmq.common.consumer.ConsumeFromWhere;
|
||||||
|
import org.apache.rocketmq.common.protocol.heartbeat.MessageModel;
|
||||||
|
import weaver.xuanran.wang.shyl.mq.constant.RocketMQConstant;
|
||||||
|
import weaver.xuanran.wang.shyl.mq.util.RocketUtil;
|
||||||
|
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.concurrent.ConcurrentHashMap;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* <h1>rocketMQ工厂</h1>
|
||||||
|
*
|
||||||
|
* @Author xuanran.wang
|
||||||
|
* @Date 2022/12/29 14:21
|
||||||
|
*/
|
||||||
|
public class RocketMQFactory {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* <h2>配置文件本地存储对象</h2>
|
||||||
|
**/
|
||||||
|
public static Map<String, Map<String,Object>> CONFIG_MAPS = new HashMap<>(16);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* <h2>生产者map</h2>
|
||||||
|
**/
|
||||||
|
private static Map<String, DefaultMQProducer> PRODUCER_MAP = new ConcurrentHashMap<>(16);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* <h1>根据配置文件生成消费者对象</h1>
|
||||||
|
* @author xuanran.wang
|
||||||
|
* @dateTime 2023/1/4 12:55
|
||||||
|
* @param configName 配置文件名称
|
||||||
|
* @param messageListenerConcurrently 消息监听处理业务方法
|
||||||
|
* @return 消费者
|
||||||
|
**/
|
||||||
|
public static DefaultMQPushConsumer getMQPushConsumer(String configName, MessageListenerConcurrently messageListenerConcurrently){
|
||||||
|
try {
|
||||||
|
Map<String, Object> configMap = getConfigMapByName(configName);
|
||||||
|
// 最大重试次数
|
||||||
|
int maxReconsumeTimes = Util.getIntValue(Util.null2String(configMap.get("MaxReconsumeTimes")), RocketMQConstant.DEFAULT_MAX_RECONSUME_TIMES);
|
||||||
|
// 声明一个消费者consumer,需要传入一个组 weaver-consumer
|
||||||
|
DefaultMQPushConsumer consumer = new DefaultMQPushConsumer(Util.null2String(configMap.get("ConsumerGroup")));
|
||||||
|
// 设置集群的NameServer地址,多个地址之间以分号分隔 183.192.65.118:9876
|
||||||
|
consumer.setNamesrvAddr(Util.null2String(configMap.get("NameServer")));
|
||||||
|
// 设置consumer的消费策略
|
||||||
|
consumer.setConsumeFromWhere(ConsumeFromWhere.CONSUME_FROM_FIRST_OFFSET);
|
||||||
|
// 集群模式消费,广播消费不会重试
|
||||||
|
consumer.setMessageModel(MessageModel.CLUSTERING);
|
||||||
|
// 设置最大重试次数,默认是16次
|
||||||
|
consumer.setMaxReconsumeTimes(maxReconsumeTimes);
|
||||||
|
// 设置consumer所订阅的Topic和Tag,*代表全部的Tag AUTH_CONSOLE_USERINFO_TOPIC
|
||||||
|
consumer.subscribe(Util.null2String(configMap.get("Topic")), Util.null2String(configMap.get("Tag")));
|
||||||
|
// Listener,主要进行消息的逻辑处理,监听topic,如果有消息就会立即去消费
|
||||||
|
consumer.registerMessageListener(messageListenerConcurrently);
|
||||||
|
return consumer;
|
||||||
|
}catch (Exception e){
|
||||||
|
throw new CustomerException(Util.logStr("consumer init error, now config name is : {} error : {}",configName, e.getMessage()));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* <h1>根据配置文件获取生产者对象</h1>
|
||||||
|
* @author xuanran.wang
|
||||||
|
* @dateTime 2023/1/4 12:59
|
||||||
|
* @param configName 配置文件名称
|
||||||
|
* @return 生产者对象
|
||||||
|
**/
|
||||||
|
public static DefaultMQProducer getMQProducer(String configName){
|
||||||
|
DefaultMQProducer defaultMQProducer = null;
|
||||||
|
if(PRODUCER_MAP.containsKey(configName)){
|
||||||
|
return PRODUCER_MAP.get(configName);
|
||||||
|
}else {
|
||||||
|
synchronized (RocketMQFactory.class){
|
||||||
|
if(PRODUCER_MAP.containsKey(configName)){
|
||||||
|
return PRODUCER_MAP.get(configName);
|
||||||
|
}else {
|
||||||
|
Map<String, Object> configMap = getConfigMapByName(configName);
|
||||||
|
defaultMQProducer = new DefaultMQProducer();
|
||||||
|
// 发送消息最大超时时间 默认60000
|
||||||
|
int sendMsgTimeOut = Util.getIntValue(Util.null2String(configMap.get("sendMsgTimeOut")), RocketMQConstant.PRODUCER_SEND_MSG_TIME_OUT);
|
||||||
|
defaultMQProducer.setSendMsgTimeout(sendMsgTimeOut);
|
||||||
|
try {
|
||||||
|
defaultMQProducer.start();
|
||||||
|
}catch (MQClientException e){
|
||||||
|
throw new CustomerException("producer start error!");
|
||||||
|
}
|
||||||
|
// mq地址
|
||||||
|
defaultMQProducer.setNamesrvAddr(Util.null2String(configMap.get("NameServer")));
|
||||||
|
PRODUCER_MAP.put(configName, defaultMQProducer);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return defaultMQProducer;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* <h1>通过配置文件名称获取配置map</h1>
|
||||||
|
* @author xuanran.wang
|
||||||
|
* @dateTime 2023/1/4 13:18
|
||||||
|
* @param configName 配置文件名称
|
||||||
|
* @return 配置文件map
|
||||||
|
**/
|
||||||
|
private synchronized static Map<String, Object> getConfigMapByName(String configName){
|
||||||
|
Map<String, Object> configMap = new HashMap<>();
|
||||||
|
if(!CONFIG_MAPS.containsKey(configName)){
|
||||||
|
configMap = RocketUtil.initMQConfigMap(configName);
|
||||||
|
CONFIG_MAPS.put(configName, configMap);
|
||||||
|
}
|
||||||
|
return configMap;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,31 @@
|
||||||
|
package weaver.xuanran.wang.shyl.mq.action;
|
||||||
|
|
||||||
|
import aiyh.utils.action.SafeCusBaseAction;
|
||||||
|
import aiyh.utils.annotation.RequiredMark;
|
||||||
|
import weaver.hrm.User;
|
||||||
|
import weaver.soa.workflow.request.RequestInfo;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* <h1>生产者action 将流程数据发送到mq中</h1>
|
||||||
|
*
|
||||||
|
* @author xuanran.wang
|
||||||
|
* @date 2023/1/4 14:47
|
||||||
|
*/
|
||||||
|
public class ProducerAction extends SafeCusBaseAction {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* <h2>mq配置文件名称</h2>
|
||||||
|
**/
|
||||||
|
@RequiredMark
|
||||||
|
private String MQConfigName;
|
||||||
|
/**
|
||||||
|
* <h2>配置文件唯一标识</h2>
|
||||||
|
**/
|
||||||
|
@RequiredMark
|
||||||
|
private String onlyMark;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void doSubmit(String requestId, String billTable, int workflowId, User user, RequestInfo requestInfo) {
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,35 @@
|
||||||
|
package weaver.xuanran.wang.shyl.mq.constant;
|
||||||
|
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* <h1>RocketMQ常量</h1>
|
||||||
|
*
|
||||||
|
* @Author xuanran.wang
|
||||||
|
* @Date 2022/12/30 13:25
|
||||||
|
*/
|
||||||
|
public class RocketMQConstant {
|
||||||
|
public static final String CREATE_ACTION = "CREATE_ACTION";
|
||||||
|
public static final String UPDATE_ACTION = "UPDATE_ACTION";
|
||||||
|
public static final String DELETE_ACTION = "DELETE_ACTION";
|
||||||
|
public static final String PASSWORD_ACTION = "PASSWORD_ACTION";
|
||||||
|
public static final int DEFAULT_MAX_RECONSUME_TIMES = 5;
|
||||||
|
public static final String SEX_GIRL = "1";
|
||||||
|
public static final String SEX_BOY = "2";
|
||||||
|
public static final String STATUS_ENABLE = "1";
|
||||||
|
public static final String STATUS_NO_ENABLE = "4";
|
||||||
|
public static final String ID_TYPE_UNKNOWN = "0";
|
||||||
|
public static final String ID_TYPE_ID_CARD = "1";
|
||||||
|
public static final String ID_TYPE_PASSPORT = "3";
|
||||||
|
public static final String ID_TYPE_STU_CARD = "4";
|
||||||
|
public static final String ID_TYPE_SOLDIER_CARD = "5";
|
||||||
|
public static final String DEFAULT_PASSWORD = "1";
|
||||||
|
public static final int PRODUCER_SEND_MSG_TIME_OUT = 60000;
|
||||||
|
|
||||||
|
public static Map<String, String> SEX_MAPPING = new HashMap<>();
|
||||||
|
|
||||||
|
static {
|
||||||
|
SEX_MAPPING.put(SEX_BOY, "0");
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,35 @@
|
||||||
|
package weaver.xuanran.wang.shyl.mq.consumer;
|
||||||
|
|
||||||
|
import aiyh.utils.Util;
|
||||||
|
import org.apache.log4j.Logger;
|
||||||
|
import org.apache.rocketmq.client.consumer.listener.ConsumeConcurrentlyContext;
|
||||||
|
import org.apache.rocketmq.client.consumer.listener.MessageListenerConcurrently;
|
||||||
|
import org.apache.rocketmq.common.message.MessageExt;
|
||||||
|
import weaver.xuanran.wang.shyl.mq.RocketMQConsumerListener;
|
||||||
|
import weaver.xuanran.wang.shyl.mq.service.impl.OrgServiceImpl;
|
||||||
|
import weaver.xuanran.wang.shyl.mq.util.RocketUtil;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* <h1>部门队列消费者</h1>
|
||||||
|
*
|
||||||
|
* @Author xuanran.wang
|
||||||
|
* @Date 2022/12/29 14:35
|
||||||
|
*/
|
||||||
|
public class OrgConsumer extends RocketMQConsumerListener {
|
||||||
|
|
||||||
|
private static final Logger log = Util.getLogger();
|
||||||
|
private static final String CONFIG_NAME = "OrgConsumer";
|
||||||
|
private final OrgServiceImpl orgService = new OrgServiceImpl();
|
||||||
|
|
||||||
|
public OrgConsumer(){
|
||||||
|
super(CONFIG_NAME);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public MessageListenerConcurrently service() {
|
||||||
|
return (List<MessageExt> msg, ConsumeConcurrentlyContext consumeConcurrentlyContext) -> RocketUtil.execute(msg, consumeConcurrentlyContext, orgService, CONFIG_NAME);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,36 @@
|
||||||
|
package weaver.xuanran.wang.shyl.mq.consumer;
|
||||||
|
|
||||||
|
import aiyh.utils.Util;
|
||||||
|
import org.apache.log4j.Logger;
|
||||||
|
import org.apache.rocketmq.client.consumer.listener.ConsumeConcurrentlyContext;
|
||||||
|
import org.apache.rocketmq.client.consumer.listener.MessageListenerConcurrently;
|
||||||
|
import org.apache.rocketmq.common.message.MessageExt;
|
||||||
|
import weaver.xuanran.wang.shyl.mq.RocketMQConsumerListener;
|
||||||
|
import weaver.xuanran.wang.shyl.mq.service.impl.PassWordServiceImpl;
|
||||||
|
import weaver.xuanran.wang.shyl.mq.util.RocketUtil;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* <h1>密码修改队列消费者</h1>
|
||||||
|
*
|
||||||
|
* @Author xuanran.wang
|
||||||
|
* @Date 2022/12/29 14:35
|
||||||
|
*/
|
||||||
|
public class PassWordConsumer extends RocketMQConsumerListener {
|
||||||
|
|
||||||
|
private static final Logger log = Util.getLogger();
|
||||||
|
public static final String CONFIG_NAME = "PassWordConsumer";
|
||||||
|
|
||||||
|
public PassWordConsumer(){
|
||||||
|
super(CONFIG_NAME);
|
||||||
|
}
|
||||||
|
|
||||||
|
private final PassWordServiceImpl passWordService = new PassWordServiceImpl();
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public MessageListenerConcurrently service() {
|
||||||
|
return (List<MessageExt> msg, ConsumeConcurrentlyContext consumeConcurrentlyContext) -> RocketUtil.execute(msg, consumeConcurrentlyContext, passWordService, CONFIG_NAME);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,35 @@
|
||||||
|
package weaver.xuanran.wang.shyl.mq.consumer;
|
||||||
|
|
||||||
|
import aiyh.utils.Util;
|
||||||
|
import org.apache.log4j.Logger;
|
||||||
|
import org.apache.rocketmq.client.consumer.listener.ConsumeConcurrentlyContext;
|
||||||
|
import org.apache.rocketmq.client.consumer.listener.MessageListenerConcurrently;
|
||||||
|
import org.apache.rocketmq.common.message.MessageExt;
|
||||||
|
import weaver.xuanran.wang.shyl.mq.RocketMQConsumerListener;
|
||||||
|
import weaver.xuanran.wang.shyl.mq.service.impl.UserServiceImpl;
|
||||||
|
import weaver.xuanran.wang.shyl.mq.util.RocketUtil;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* <h1>用户队列消费者</h1>
|
||||||
|
*
|
||||||
|
* @Author xuanran.wang
|
||||||
|
* @Date 2022/12/29 14:35
|
||||||
|
*/
|
||||||
|
public class UserInfoConsumer extends RocketMQConsumerListener {
|
||||||
|
private static final Logger log = Util.getLogger();
|
||||||
|
public static final String CONFIG_NAME = "UserInfoConsumer";
|
||||||
|
|
||||||
|
public UserInfoConsumer(){
|
||||||
|
super(CONFIG_NAME);
|
||||||
|
}
|
||||||
|
|
||||||
|
private final UserServiceImpl userInfoService = new UserServiceImpl();
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public MessageListenerConcurrently service() {
|
||||||
|
return (List<MessageExt> msg, ConsumeConcurrentlyContext consumeConcurrentlyContext) -> RocketUtil.execute(msg, consumeConcurrentlyContext, userInfoService, CONFIG_NAME);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,44 @@
|
||||||
|
package weaver.xuanran.wang.shyl.mq.entity;
|
||||||
|
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* <h1>mq消息实体类</h1>
|
||||||
|
*
|
||||||
|
* @Author xuanran.wang
|
||||||
|
* @Date 2022/12/30 13:09
|
||||||
|
*/
|
||||||
|
@Data
|
||||||
|
public class MQMessage {
|
||||||
|
/**
|
||||||
|
* <h2>消息ID</h2>
|
||||||
|
**/
|
||||||
|
private String id;
|
||||||
|
/**
|
||||||
|
* <h2>消息队列名</h2>
|
||||||
|
* <p>
|
||||||
|
* AUTH_CONSOLE_USERINFO_TOPIC: 用户队列;
|
||||||
|
* AUTH_CONSOLE_ORG_TOPIC: 机构队列;
|
||||||
|
* AUTH_CONSOLE_USERINFO_PASSWORD_TOPIC: 密码修改队列
|
||||||
|
* </p>
|
||||||
|
**/
|
||||||
|
private String topic;
|
||||||
|
/**
|
||||||
|
* <h2>消息内容操作类型</h2>
|
||||||
|
* <p>
|
||||||
|
* CREATE_ACTION:新增;
|
||||||
|
* UPDATE_ACTION: 修改;
|
||||||
|
* DELETE_ACTION: 删除;
|
||||||
|
* PASSWORD_ACTION: 修改密码
|
||||||
|
* </p>
|
||||||
|
**/
|
||||||
|
private String actionType;
|
||||||
|
/**
|
||||||
|
* <h2>消息发送时间</h2>
|
||||||
|
**/
|
||||||
|
private String sendTime;
|
||||||
|
/**
|
||||||
|
* <h2>消息业务内容,json 格式,分业务(用户、机构、密码修改)</h2>
|
||||||
|
**/
|
||||||
|
private String content;
|
||||||
|
}
|
|
@ -0,0 +1,46 @@
|
||||||
|
package weaver.xuanran.wang.shyl.mq.entity;
|
||||||
|
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* <h1>密码修改</h1>
|
||||||
|
*
|
||||||
|
* @Author xuanran.wang
|
||||||
|
* @Date 2022/12/30 13:59
|
||||||
|
*/
|
||||||
|
@Data
|
||||||
|
public class ModifyPassWord {
|
||||||
|
/**
|
||||||
|
* <h2>主键</h2>
|
||||||
|
**/
|
||||||
|
private String id;
|
||||||
|
/**
|
||||||
|
* <h2>用户ID</h2>
|
||||||
|
**/
|
||||||
|
private String uid;
|
||||||
|
/**
|
||||||
|
* <h2>用户账号</h2>
|
||||||
|
**/
|
||||||
|
private String username;
|
||||||
|
/**
|
||||||
|
* <h2>用户名称</h2>
|
||||||
|
**/
|
||||||
|
private String displayName;
|
||||||
|
/**
|
||||||
|
* <h2>旧密码</h2>
|
||||||
|
**/
|
||||||
|
private String oldPassword;
|
||||||
|
/**
|
||||||
|
* <h2>新密码</h2>
|
||||||
|
**/
|
||||||
|
private String password;
|
||||||
|
/**
|
||||||
|
* <h2>确认密码</h2>
|
||||||
|
**/
|
||||||
|
private String confirmPassword;
|
||||||
|
/**
|
||||||
|
* <h2>盐值</h2>
|
||||||
|
**/
|
||||||
|
private String decipherable;
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,38 @@
|
||||||
|
|
||||||
|
package weaver.xuanran.wang.shyl.mq.entity;
|
||||||
|
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* <h1>机构实体</h1>
|
||||||
|
*
|
||||||
|
* @Author xuanran.wang
|
||||||
|
* @Date 2022/12/30 13:56
|
||||||
|
*/
|
||||||
|
@Data
|
||||||
|
public class Org {
|
||||||
|
/**
|
||||||
|
* <h2>机构ID</h2>
|
||||||
|
**/
|
||||||
|
private String id;
|
||||||
|
/**
|
||||||
|
* <h2>机构编号</h2>
|
||||||
|
**/
|
||||||
|
private String orgCode;
|
||||||
|
/**
|
||||||
|
* <h2>机构名称</h2>
|
||||||
|
**/
|
||||||
|
private String orgName;
|
||||||
|
/**
|
||||||
|
* <h2>机构父级ID</h2>
|
||||||
|
**/
|
||||||
|
private String parentId;
|
||||||
|
/**
|
||||||
|
* <h2>机构排序号</h2>
|
||||||
|
**/
|
||||||
|
private String sortIndex;
|
||||||
|
/**
|
||||||
|
* <h2>机构状态</h2>
|
||||||
|
**/
|
||||||
|
private String status;
|
||||||
|
}
|
|
@ -0,0 +1,61 @@
|
||||||
|
package weaver.xuanran.wang.shyl.mq.entity;
|
||||||
|
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* <h1>用户实体</h1>
|
||||||
|
*
|
||||||
|
* @Author xuanran.wang
|
||||||
|
* @Date 2022/12/30 13:52
|
||||||
|
*/
|
||||||
|
@Data
|
||||||
|
public class UserInfo {
|
||||||
|
/**
|
||||||
|
* <h2>用户ID</h2>
|
||||||
|
**/
|
||||||
|
private String id;
|
||||||
|
/**
|
||||||
|
* <h2>用户账号</h2>
|
||||||
|
**/
|
||||||
|
private String userName;
|
||||||
|
/**
|
||||||
|
* <h2>用户名称</h2>
|
||||||
|
**/
|
||||||
|
private String displayName;
|
||||||
|
/**
|
||||||
|
* <h2>用户性别</h2>
|
||||||
|
**/
|
||||||
|
private String gender;
|
||||||
|
/**
|
||||||
|
* <h2>用户生日</h2>
|
||||||
|
**/
|
||||||
|
private String birthDate;
|
||||||
|
/**
|
||||||
|
* <h2>用户证件类型</h2>
|
||||||
|
**/
|
||||||
|
private String idType;
|
||||||
|
/**
|
||||||
|
* <h2>用户证件号</h2>
|
||||||
|
**/
|
||||||
|
private String idCardNo;
|
||||||
|
/**
|
||||||
|
* <h2>用户邮箱</h2>
|
||||||
|
**/
|
||||||
|
private String email;
|
||||||
|
/**
|
||||||
|
* <h2>用户手机号</h2>
|
||||||
|
**/
|
||||||
|
private String mobile;
|
||||||
|
/**
|
||||||
|
* <h2>用户机构ID</h2>
|
||||||
|
**/
|
||||||
|
private String departmentId;
|
||||||
|
/**
|
||||||
|
* <h2>用户机构名称</h2>
|
||||||
|
**/
|
||||||
|
private String department;
|
||||||
|
/**
|
||||||
|
* <h2>用户状态</h2>
|
||||||
|
**/
|
||||||
|
private String status;
|
||||||
|
}
|
|
@ -0,0 +1,75 @@
|
||||||
|
package weaver.xuanran.wang.shyl.mq.mapper;
|
||||||
|
|
||||||
|
import aiyh.utils.annotation.recordset.ParamMapper;
|
||||||
|
import aiyh.utils.annotation.recordset.Update;
|
||||||
|
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* <h1>消费者mapper</h1>
|
||||||
|
*
|
||||||
|
* @Author xuanran.wang
|
||||||
|
* @Date 2022/12/30 14:19
|
||||||
|
*/
|
||||||
|
public interface ConsumerMapper {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* <h1>通过outKey更新人员状态为离职</h1>
|
||||||
|
* @author xuanran.wang
|
||||||
|
* @dateTime 2022/12/30 14:33
|
||||||
|
* @return 更新成功/失败
|
||||||
|
**/
|
||||||
|
@Update("update hrmresource set status = 5 where outkey = #{outKey}")
|
||||||
|
boolean updateUserStatusByOutKey(@ParamMapper("outKey") String outKey);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* <h1>通过outKey删除部门信息</h1>
|
||||||
|
* @author xuanran.wang
|
||||||
|
* @dateTime 2022/12/30 14:33
|
||||||
|
* @param outKey 外部系统id
|
||||||
|
* @return 删除是否成功
|
||||||
|
**/
|
||||||
|
@Update("delete hrmdepartment where outkey = #{outKey}")
|
||||||
|
boolean deleteDepartmentByOutKey(@ParamMapper("outKey") String outKey);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* <h1>通过outKey获取部门数据信息</h1>
|
||||||
|
* @author xuanran.wang
|
||||||
|
* @dateTime 2022/12/30 14:33
|
||||||
|
* @param outKey 外部系统id
|
||||||
|
* @return map key : id, val : 分部id
|
||||||
|
**/
|
||||||
|
@Update("select id departmentId, subcompanyid1 subCompanyId from hrmdepartment where outkey = #{outKey}")
|
||||||
|
Map<String, Integer> getDepInfoByOutKey(@ParamMapper("outKey") String outKey);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* <h1>通过outKey获取人力资源id</h1>
|
||||||
|
* @author xuanran.wang
|
||||||
|
* @dateTime 2022/12/30 14:33
|
||||||
|
* @param outKey 外部系统id
|
||||||
|
* @return id
|
||||||
|
**/
|
||||||
|
@Update("select id from hrmresource where outkey = #{outKey}")
|
||||||
|
String getHrmIdByOutKey(@ParamMapper("outKey") String outKey);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* <h1>通过outKey获取oa部门id</h1>
|
||||||
|
* @author xuanran.wang
|
||||||
|
* @dateTime 2022/12/30 14:33
|
||||||
|
* @param outKey 外部系统id
|
||||||
|
* @return id
|
||||||
|
**/
|
||||||
|
@Update("select id from hrmdepartment where outkey = #{outKey}")
|
||||||
|
String getDepIdByOutKey(@ParamMapper("outKey") String outKey);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* <h1>通过outKey获取oa部门id</h1>
|
||||||
|
* @author xuanran.wang
|
||||||
|
* @dateTime 2022/12/30 14:33
|
||||||
|
* @param id 外部系统id
|
||||||
|
* @return true/false
|
||||||
|
**/
|
||||||
|
@Update("update hrmresource set password = #{password} where id = #{id}")
|
||||||
|
boolean updatePasswordById(@ParamMapper("id") String id,
|
||||||
|
@ParamMapper("password") String password);
|
||||||
|
}
|
|
@ -0,0 +1,41 @@
|
||||||
|
package weaver.xuanran.wang.shyl.mq.service;
|
||||||
|
|
||||||
|
import aiyh.utils.Util;
|
||||||
|
import org.apache.log4j.Logger;
|
||||||
|
import weaver.conn.RecordSet;
|
||||||
|
import weaver.xuanran.wang.shyl.mq.mapper.ConsumerMapper;
|
||||||
|
import weaver.xuanran.wang.shyl.mq.service.interfaces.CreateAction;
|
||||||
|
import weaver.xuanran.wang.shyl.mq.service.interfaces.DeleteAction;
|
||||||
|
import weaver.xuanran.wang.shyl.mq.service.interfaces.PassWordAction;
|
||||||
|
import weaver.xuanran.wang.shyl.mq.service.interfaces.UpdateAction;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* <h1>抽象类</h1>
|
||||||
|
*
|
||||||
|
* @Author xuanran.wang
|
||||||
|
* @Date 2022/12/30 13:04
|
||||||
|
*/
|
||||||
|
public abstract class CusInfoActionService implements CreateAction, DeleteAction, UpdateAction, PassWordAction {
|
||||||
|
protected final RecordSet recordSet = new RecordSet();
|
||||||
|
|
||||||
|
protected final Logger logger = Util.getLogger();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* <h2>consumer-mapper</h2>
|
||||||
|
**/
|
||||||
|
protected final ConsumerMapper consumerMapper = Util.getMapper(ConsumerMapper.class);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* <h1>获取下一个人员id</h1>
|
||||||
|
* @author xuanran.wang
|
||||||
|
* @dateTime 2023/01/03 10:50
|
||||||
|
* @return next id
|
||||||
|
**/
|
||||||
|
protected synchronized String getNextHrmId(){
|
||||||
|
recordSet.executeProc("HrmResourceMaxId_Get", "");
|
||||||
|
recordSet.next();
|
||||||
|
//新增的部门id
|
||||||
|
return Util.null2String(recordSet.getInt(1));
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue