2023-04-09 上海大数据中心统一待办
parent
9275631cd8
commit
7717781676
|
@ -22,6 +22,7 @@ const detail2TempDateField = WfForm.convertFieldNameToId("dyrq", detailTable);
|
||||||
// 需要计算的款项类型集合
|
// 需要计算的款项类型集合
|
||||||
const computeDatePayType = ['0'];
|
const computeDatePayType = ['0'];
|
||||||
const DETAIL_MAX_SIZE = 5;
|
const DETAIL_MAX_SIZE = 5;
|
||||||
|
const readOnlyArr = ['0'];
|
||||||
// 款项类型预计对应日期取值
|
// 款项类型预计对应日期取值
|
||||||
const paymentTypeGetValue = {
|
const paymentTypeGetValue = {
|
||||||
0: (index)=>{
|
0: (index)=>{
|
||||||
|
@ -36,7 +37,8 @@ jQuery().ready(function(){
|
||||||
'detailComPayDateId': detail2ComPayDateId,
|
'detailComPayDateId': detail2ComPayDateId,
|
||||||
'dayId': detail2DayId,
|
'dayId': detail2DayId,
|
||||||
'computeDatePayType': computeDatePayType,
|
'computeDatePayType': computeDatePayType,
|
||||||
'paymentTypeGetValue': paymentTypeGetValue
|
'paymentTypeGetValue': paymentTypeGetValue,
|
||||||
|
'readOnlyArr': readOnlyArr
|
||||||
}
|
}
|
||||||
let rowArr = WfForm.getDetailAllRowIndexStr(detailTable).split(",");
|
let rowArr = WfForm.getDetailAllRowIndexStr(detailTable).split(",");
|
||||||
|
|
||||||
|
@ -49,7 +51,7 @@ jQuery().ready(function(){
|
||||||
|
|
||||||
addRowBack(2, configObj);
|
addRowBack(2, configObj);
|
||||||
|
|
||||||
changeDetailFieldReadOnly(detailTable, detail2ComPayDateId, detail2PaymentTypeId, computeDatePayType)
|
changeDetailFieldReadOnly(detailTable, detail2ComPayDateId, detail2PaymentTypeId, readOnlyArr)
|
||||||
|
|
||||||
// 主表字段发生变化
|
// 主表字段发生变化
|
||||||
mainFieldChangeDetailCom(contractSignDateId, detailTable, configObj);
|
mainFieldChangeDetailCom(contractSignDateId, detailTable, configObj);
|
||||||
|
|
|
@ -60,6 +60,7 @@ function submitCallback(detailTable, detail2PayProportionId){
|
||||||
sum += parseFloat(WfForm.getFieldValue(field));//遍历明细行字段
|
sum += parseFloat(WfForm.getFieldValue(field));//遍历明细行字段
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
console.log('sum => ', sum)
|
||||||
sum === 100.00 ? callback() : WfForm.showMessage("明细付款比例总和不等于100,请修改后提交!");
|
sum === 100.00 ? callback() : WfForm.showMessage("明细付款比例总和不等于100,请修改后提交!");
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -118,11 +119,18 @@ function changeDetailPayDate(obj){
|
||||||
let computeDatePayType = obj['computeDatePayType'];
|
let computeDatePayType = obj['computeDatePayType'];
|
||||||
// 获取主表的字符值转换函数
|
// 获取主表的字符值转换函数
|
||||||
let paymentTypeGetValue = obj['paymentTypeGetValue'];
|
let paymentTypeGetValue = obj['paymentTypeGetValue'];
|
||||||
|
// 只读
|
||||||
|
let readOnlyArr = obj['readOnlyArr'];
|
||||||
// 款项类型
|
// 款项类型
|
||||||
let paymentType = WfForm.getFieldValue(`${detailPaymentTypeId}_${index}`);
|
let paymentType = WfForm.getFieldValue(`${detailPaymentTypeId}_${index}`);
|
||||||
|
if(readOnlyArr.includes(paymentType)){
|
||||||
|
WfForm.changeFieldAttr(`${detailComPayDateId}_${index}`, READ_ONLY);
|
||||||
|
}else{
|
||||||
|
// 如果款项类型不需要计算就把预计付款日期属性改成可编辑
|
||||||
|
WfForm.changeFieldAttr(`${detailComPayDateId}_${index}`, EDIT);
|
||||||
|
}
|
||||||
// 先进行赋值
|
// 先进行赋值
|
||||||
if(computeDatePayType.includes(paymentType)){
|
if(computeDatePayType.includes(paymentType)){
|
||||||
WfForm.changeFieldAttr(`${detailComPayDateId}_${index}`, READ_ONLY);
|
|
||||||
// 存在字段联动延时处理
|
// 存在字段联动延时处理
|
||||||
setTimeout(()=>{
|
setTimeout(()=>{
|
||||||
if(paymentTypeGetValue){
|
if(paymentTypeGetValue){
|
||||||
|
@ -142,16 +150,14 @@ function changeDetailPayDate(obj){
|
||||||
value: comDate
|
value: comDate
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}else {
|
|
||||||
// 如果对应日期为空就给预计付款赋空值
|
|
||||||
WfForm.changeFieldValue(`${detailComPayDateId}_${index}`,{
|
|
||||||
value: ''
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
// else {
|
||||||
|
// // 如果对应日期为空就给预计付款赋空值
|
||||||
|
// WfForm.changeFieldValue(`${detailComPayDateId}_${index}`,{
|
||||||
|
// value: ''
|
||||||
|
// });
|
||||||
|
// }
|
||||||
},100);
|
},100);
|
||||||
}else{
|
|
||||||
// 如果款项类型不需要计算就把预计付款日期属性改成可编辑
|
|
||||||
WfForm.changeFieldAttr(`${detailComPayDateId}_${index}`, EDIT);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,26 @@
|
||||||
|
const zrckField = WfForm.convertFieldNameToId('zrck');
|
||||||
|
const zcckField = WfForm.convertFieldNameToId('zcck');
|
||||||
|
// 主表存货编码
|
||||||
|
const mainStockSetField = WfForm.convertFieldNameToId('chbmjh');
|
||||||
|
// 明细1存货编码字段
|
||||||
|
const deail1StockSetField = WfForm.convertFieldNameToId('chbm','detail_1');
|
||||||
|
jQuery(document).ready(function(){
|
||||||
|
WfForm.triggerFieldAllLinkage(zrckField);
|
||||||
|
WfForm.triggerFieldAllLinkage(zcckField);
|
||||||
|
initStockNo();
|
||||||
|
});
|
||||||
|
function initStockNo(){
|
||||||
|
var rowArr = WfForm.getDetailAllRowIndexStr("detail_1").split(",");
|
||||||
|
let arr = [];
|
||||||
|
for(var i=0; i<rowArr.length; i++){
|
||||||
|
var rowIndex = rowArr[i];
|
||||||
|
if(rowIndex !== ""){
|
||||||
|
let val = WfForm.getFieldValue(`${deail1StockSetField}_${rowIndex}`);
|
||||||
|
arr.push(val);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
WfForm.changeFieldValue(mainStockSetField, {value:arr.join(',')});
|
||||||
|
setTimeout(()=>{
|
||||||
|
WfForm.triggerFieldAllLinkage(mainStockSetField);
|
||||||
|
},500);
|
||||||
|
}
|
|
@ -3,30 +3,157 @@ const yjfksj = WfForm.convertFieldNameToId('yjfksj');
|
||||||
// 主表比例
|
// 主表比例
|
||||||
const bl = WfForm.convertFieldNameToId('bcfkbl');
|
const bl = WfForm.convertFieldNameToId('bcfkbl');
|
||||||
// 明细要求付款日期
|
// 明细要求付款日期
|
||||||
const detail3Yqfkrq = WfForm.convertFieldNameToId('yqfkrq',"detail_3");
|
const detail3Yqfkrq = WfForm.convertFieldNameToId('yqfkrq', "detail_3");
|
||||||
// 明细本次付款比例
|
// 明细本次付款比例
|
||||||
const detailBl = WfForm.convertFieldNameToId('bcfkbl',"detail_3");
|
const detailBl = WfForm.convertFieldNameToId('bcfkbl', "detail_3");
|
||||||
|
// 关联订单
|
||||||
|
const relationOrder = WfForm.convertFieldNameToId("gldd");
|
||||||
|
// 明细4施工合同字段
|
||||||
|
const detail4SgField = WfForm.convertFieldNameToId("sght", "detail_4");
|
||||||
|
// 明细4采购合同字段
|
||||||
|
const detail4CgField = WfForm.convertFieldNameToId("cght", "detail_4");
|
||||||
|
// 明细4发票字段
|
||||||
|
const detail4FpField = WfForm.convertFieldNameToId("fpje", "detail_4");
|
||||||
|
// 明细4合同发票金额和
|
||||||
|
let detail4Map = new Map();
|
||||||
|
// 明细3施工合同字段
|
||||||
|
const detail3SgField = WfForm.convertFieldNameToId("sght", "detail_3");
|
||||||
|
// 明细3采购合同字段
|
||||||
|
const detail3CgField = WfForm.convertFieldNameToId("cght", "detail_3");
|
||||||
|
// 明细3 含税金额
|
||||||
|
const detail3TaxField = WfForm.convertFieldNameToId("ddhsje", "detail_3");
|
||||||
|
// 明细3以收票金额
|
||||||
|
const detail3YspField = WfForm.convertFieldNameToId("yspje", "detail_3");
|
||||||
|
|
||||||
WfForm.registerCheckEvent(WfForm.OPER_ADDROW + "3", function (callback) {
|
WfForm.registerCheckEvent(WfForm.OPER_ADDROW + "3", function (callback) {
|
||||||
callback();
|
callback();
|
||||||
|
setTimeout(() => {
|
||||||
|
initDeatail3Date();
|
||||||
|
}, 5)
|
||||||
|
});
|
||||||
|
// 关联订单变化时将明细四的合同-金额map进行初始化
|
||||||
|
WfForm.bindFieldChangeEvent(relationOrder, function (obj, id, value) {
|
||||||
|
setTimeout(() => {
|
||||||
|
initDetail4Map();
|
||||||
|
changeDetail3SpMoney();
|
||||||
|
}, 2000);
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
|
WfForm.bindFieldChangeEvent(`${yjfksj},${bl}`, function (obj, id, value) {
|
||||||
initDeatail3Date();
|
initDeatail3Date();
|
||||||
});
|
});
|
||||||
|
|
||||||
WfForm.bindFieldChangeEvent(`${yjfksj},${bl}`, function(obj,id,value){
|
// 计算明细三开票金额
|
||||||
initDeatail3Date();
|
function changeDetail3SpMoney() {
|
||||||
});
|
|
||||||
|
|
||||||
function initDeatail3Date(){
|
|
||||||
let dateVal = WfForm.getFieldValue(yjfksj);
|
|
||||||
let blVal = WfForm.getFieldValue(bl);
|
|
||||||
console.log('dateVal ', dateVal);
|
|
||||||
console.log('blVal ', blVal);
|
|
||||||
let detail3RowArr = WfForm.getDetailAllRowIndexStr('detail_3').split(",");
|
let detail3RowArr = WfForm.getDetailAllRowIndexStr('detail_3').split(",");
|
||||||
for (let i = 0; i < detail3RowArr.length; i++) {
|
for (let i = 0; i < detail3RowArr.length; i++) {
|
||||||
let rowIndex = detail3RowArr[i];
|
let rowIndex = detail3RowArr[i];
|
||||||
if (rowIndex !== "") {
|
if (rowIndex !== "") {
|
||||||
WfForm.changeFieldValue(`${detail3Yqfkrq}_${rowIndex}`,{value: dateVal});
|
let detail3SgFieldVal = WfForm.getFieldValue(`${detail3SgField}_${rowIndex}`);
|
||||||
WfForm.changeFieldValue(`${detailBl}_${rowIndex}`,{value: blVal});
|
let detail3CgFieldVal = WfForm.getFieldValue(`${detail3CgField}_${rowIndex}`);
|
||||||
|
let fpje = detail4Map.get(detail3SgFieldVal) ?? detail4Map.get(detail3CgFieldVal);
|
||||||
|
let mapVal = detail4Map.get(detail3SgFieldVal);
|
||||||
|
let key = detail3SgFieldVal;
|
||||||
|
if (!mapVal) {
|
||||||
|
key = detail3CgFieldVal;
|
||||||
|
}
|
||||||
|
console.log('key ', key);
|
||||||
|
if (fpje) {
|
||||||
|
console.log('fpje => ', fpje);
|
||||||
|
// 0.1 0.3
|
||||||
|
let detail3TaxVal = WfForm.getFieldValue(`${detail3TaxField}_${rowIndex}`);
|
||||||
|
console.log('detail3TaxVal => ', detail3TaxVal);
|
||||||
|
let tempJe = fpje - detail3TaxVal;
|
||||||
|
console.log('tempJe => ', tempJe);
|
||||||
|
if (fpje > detail3TaxVal) {
|
||||||
|
WfForm.changeFieldValue(`${detail3YspField}_${rowIndex}`, {value: detail3TaxVal});
|
||||||
|
} else if (tempJe <= 0 && fpje == 0) {
|
||||||
|
WfForm.changeFieldValue(`${detail3YspField}_${rowIndex}`, {value: 0});
|
||||||
|
} else if (tempJe < 0) {
|
||||||
|
WfForm.changeFieldValue(`${detail3YspField}_${rowIndex}`, {value: fpje});
|
||||||
|
tempJe = 0;
|
||||||
|
}
|
||||||
|
detail4Map.set(key, tempJe);
|
||||||
|
console.log('detail4Map ', detail4Map)
|
||||||
|
} else {
|
||||||
|
WfForm.changeFieldValue(`${detail3YspField}_${rowIndex}`, {value: 0});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
function initDeatail3Date() {
|
||||||
|
let dateVal = WfForm.getFieldValue(yjfksj);
|
||||||
|
let blVal = WfForm.getFieldValue(bl);
|
||||||
|
let detail3RowArr = WfForm.getDetailAllRowIndexStr('detail_3').split(",");
|
||||||
|
for (let i = 0; i < detail3RowArr.length; i++) {
|
||||||
|
let rowIndex = detail3RowArr[i];
|
||||||
|
if (rowIndex !== "") {
|
||||||
|
WfForm.changeFieldValue(`${detail3Yqfkrq}_${rowIndex}`, {value: dateVal});
|
||||||
|
WfForm.changeFieldValue(`${detailBl}_${rowIndex}`, {value: blVal});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function initDetail4Map() {
|
||||||
|
let detail4RowArr = WfForm.getDetailAllRowIndexStr('detail_4').split(",");
|
||||||
|
console.log('detail4RowArr ', detail4RowArr);
|
||||||
|
for (let i = 0; i < detail4RowArr.length; i++) {
|
||||||
|
let rowIndex = detail4RowArr[i];
|
||||||
|
if (rowIndex !== "") {
|
||||||
|
let detail4SgFieldVal = WfForm.getFieldValue(`${detail4SgField}_${rowIndex}`);
|
||||||
|
let detail4CgFieldVal = WfForm.getFieldValue(`${detail4CgField}_${rowIndex}`);
|
||||||
|
let detail4FpFieldVal = WfForm.getFieldValue(`${detail4FpField}_${rowIndex}`);
|
||||||
|
let key = -1;
|
||||||
|
console.log('detail4SgFieldVal ', detail4SgFieldVal);
|
||||||
|
console.log('detail4CgFieldVal ', detail4CgFieldVal);
|
||||||
|
console.log('detail4FpFieldVal ', detail4FpFieldVal);
|
||||||
|
if (!detail4FpFieldVal) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
key = detail4CgFieldVal ?? detail4SgFieldVal;
|
||||||
|
console.log('key ', key);
|
||||||
|
let tempVal = parseFloat(detail4Map.get(key) ?? 0);
|
||||||
|
tempVal += parseFloat(detail4FpFieldVal);
|
||||||
|
detail4Map.set(key, tempVal);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
console.log('detail4Map ', detail4Map)
|
||||||
|
}
|
||||||
|
|
||||||
|
const detail3ApplyMoneyField = WfForm.convertFieldNameToId("bcfkje", "detail_3");
|
||||||
|
const detail3CgId = WfForm.convertFieldNameToId("cgddzbid", "detail_3");
|
||||||
|
const detail3Bl = WfForm.convertFieldNameToId('bcfkbl', "detail_3");
|
||||||
|
let detailBlMap = new Map();
|
||||||
|
const detail1Bl = WfForm.convertFieldNameToId('fkbl', "detail_1");
|
||||||
|
const detail1CgId = WfForm.convertFieldNameToId("cgddzbid", "detail_1");
|
||||||
|
WfForm.bindDetailFieldChangeEvent(detail3ApplyMoneyField, (id, rowIndex, value) => {
|
||||||
|
let detail3RowArr = WfForm.getDetailAllRowIndexStr('detail_3').split(",");
|
||||||
|
detailBlMap = new Map();
|
||||||
|
for (let i = 0; i < detail3RowArr.length; i++) {
|
||||||
|
let rowIndex = detail3RowArr[i];
|
||||||
|
if (rowIndex !== "") {
|
||||||
|
let bl = parseFloat(WfForm.getFieldValue(`${detail3Bl}_${rowIndex}`));
|
||||||
|
let cg = WfForm.getFieldValue(`${detail3CgId}_${rowIndex}`);
|
||||||
|
let mapVal = parseFloat(detailBlMap.get(cg) ?? 0) + bl;
|
||||||
|
detailBlMap.set(cg, mapVal);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
console.log('detailBlMap ', detailBlMap)
|
||||||
|
let detail1RowArr = WfForm.getDetailAllRowIndexStr('detail_1').split(",");
|
||||||
|
for (let i = 0; i < detail1RowArr.length; i++) {
|
||||||
|
let rowIndex = detail1RowArr[i];
|
||||||
|
if (rowIndex !== "") {
|
||||||
|
let cg = WfForm.getFieldValue(`${detail1CgId}_${rowIndex}`);
|
||||||
|
let val = detailBlMap.get(cg) === '' ? 0 : detailBlMap.get(cg);
|
||||||
|
WfForm.changeFieldValue(`${detail1Bl}_${rowIndex}`, {value: val})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -23,6 +23,7 @@ const detailComPayDateId = WfForm.convertFieldNameToId("yjfkrq",detailTable);
|
||||||
// 对应日期
|
// 对应日期
|
||||||
const detailTempDateField = WfForm.convertFieldNameToId("dyrq", detailTable);
|
const detailTempDateField = WfForm.convertFieldNameToId("dyrq", detailTable);
|
||||||
// 需要计算的款项类型集合
|
// 需要计算的款项类型集合
|
||||||
|
const readOnlyArr = ['0'];
|
||||||
const computeDatePayType = ['0','2','4'];
|
const computeDatePayType = ['0','2','4'];
|
||||||
// 款项类型预计对应日期取值
|
// 款项类型预计对应日期取值
|
||||||
const paymentTypeGetValue = {
|
const paymentTypeGetValue = {
|
||||||
|
@ -49,12 +50,13 @@ function init(){
|
||||||
'detailComPayDateId': detailComPayDateId,
|
'detailComPayDateId': detailComPayDateId,
|
||||||
'dayId': detailDayId,
|
'dayId': detailDayId,
|
||||||
'computeDatePayType': computeDatePayType,
|
'computeDatePayType': computeDatePayType,
|
||||||
'paymentTypeGetValue': paymentTypeGetValue
|
'paymentTypeGetValue': paymentTypeGetValue,
|
||||||
|
'readOnlyArr': readOnlyArr
|
||||||
}
|
}
|
||||||
|
|
||||||
addRowBack(3, obj);
|
addRowBack(3, obj);
|
||||||
|
|
||||||
changeDetailFieldReadOnly(detailTable, detailComPayDateId, detailPaymentTypeId, computeDatePayType)
|
changeDetailFieldReadOnly(detailTable, detailComPayDateId, detailPaymentTypeId, readOnlyArr)
|
||||||
// 主表字段发生变化
|
// 主表字段发生变化
|
||||||
mainFieldChangeDetailCom(`${mainProjectId},${contractSignDateId}`, detailTable, obj);
|
mainFieldChangeDetailCom(`${mainProjectId},${contractSignDateId}`, detailTable, obj);
|
||||||
// 明细的款项类型字段变化绑定
|
// 明细的款项类型字段变化绑定
|
||||||
|
|
|
@ -11,7 +11,7 @@ const mainWorkFlowEndId = WfForm.convertFieldNameToId("fhdgdrq");
|
||||||
// 主表实际验收
|
// 主表实际验收
|
||||||
const mainActualCheckId = WfForm.convertFieldNameToId("sjysrq");
|
const mainActualCheckId = WfForm.convertFieldNameToId("sjysrq");
|
||||||
// 明细2付款比例字段
|
// 明细2付款比例字段
|
||||||
const detail2PayProportionId = WfForm.convertFieldNameToId("fkbl",detailTable);
|
const detail2PayProportionId = WfForm.convertFieldNameToId("skbl",detailTable);
|
||||||
// 明细2款项类型
|
// 明细2款项类型
|
||||||
const detail2PaymentTypeId = WfForm.convertFieldNameToId("kxlx",detailTable);
|
const detail2PaymentTypeId = WfForm.convertFieldNameToId("kxlx",detailTable);
|
||||||
// 明细2前后字段
|
// 明细2前后字段
|
||||||
|
@ -24,6 +24,8 @@ const detail2ComPayDateId = WfForm.convertFieldNameToId("yjfkrq",detailTable);
|
||||||
const detail2TempDateField = WfForm.convertFieldNameToId("dyrq", detailTable);
|
const detail2TempDateField = WfForm.convertFieldNameToId("dyrq", detailTable);
|
||||||
// 需要计算的款项类型集合
|
// 需要计算的款项类型集合
|
||||||
const computeDatePayType = ['2', '4', '5'];
|
const computeDatePayType = ['2', '4', '5'];
|
||||||
|
// 只读 明细款项类型
|
||||||
|
const readOnlyArr = [];
|
||||||
// 款项类型预计对应日期取值
|
// 款项类型预计对应日期取值
|
||||||
const paymentTypeGetValue = {
|
const paymentTypeGetValue = {
|
||||||
2: (index)=>{
|
2: (index)=>{
|
||||||
|
@ -50,10 +52,11 @@ function init(){
|
||||||
'detailComPayDateId': detail2ComPayDateId,
|
'detailComPayDateId': detail2ComPayDateId,
|
||||||
'dayId': detail2DayId,
|
'dayId': detail2DayId,
|
||||||
'computeDatePayType': computeDatePayType,
|
'computeDatePayType': computeDatePayType,
|
||||||
'paymentTypeGetValue': paymentTypeGetValue
|
'paymentTypeGetValue': paymentTypeGetValue,
|
||||||
|
'readOnlyArr': readOnlyArr
|
||||||
}
|
}
|
||||||
addRowBack(2, obj);
|
addRowBack(2, obj);
|
||||||
changeDetailFieldReadOnly(detailTable, detail2ComPayDateId, detail2PaymentTypeId, computeDatePayType)
|
changeDetailFieldReadOnly(detailTable, detail2ComPayDateId, detail2PaymentTypeId, readOnlyArr);
|
||||||
// 主表字段发生变化
|
// 主表字段发生变化
|
||||||
mainFieldChangeDetailCom(mainProjectId, detailTable, obj);
|
mainFieldChangeDetailCom(mainProjectId, detailTable, obj);
|
||||||
// 明细的款项类型字段变化绑定
|
// 明细的款项类型字段变化绑定
|
||||||
|
|
|
@ -0,0 +1,45 @@
|
||||||
|
const enable = 0;
|
||||||
|
// 班级浏览按钮表单字段id
|
||||||
|
const classFieldId = WfForm.convertFieldNameToId("bjmc");
|
||||||
|
// 明细1学员id
|
||||||
|
const detail1StuId = WfForm.convertFieldNameToId("studentId","detail_1");;
|
||||||
|
// 明细1学员编号
|
||||||
|
const detail1StuNo = WfForm.convertFieldNameToId("studentNo","detail_1");;
|
||||||
|
// 明细1学员姓名
|
||||||
|
const detail1StuName = WfForm.convertFieldNameToId("studentName","detail_1");;
|
||||||
|
// 明细1班级id
|
||||||
|
const detail1ClassId = WfForm.convertFieldNameToId("classId","detail_1");
|
||||||
|
// 主表学员汇总字段
|
||||||
|
const stuAllField = WfForm.convertFieldNameToId("mxxybhhzfz");
|
||||||
|
WfForm.bindFieldChangeEvent(classFieldId, function(obj,id,value){
|
||||||
|
let classId = WfForm.getBrowserShowName(classFieldId);
|
||||||
|
WfForm.delDetailRow("detail_1", "all");
|
||||||
|
$.get('/api/wxr/students/getStudentsByClassId',{id:classId},(res)=>{
|
||||||
|
let obj = JSON.parse(res);
|
||||||
|
if(obj.code != 200){
|
||||||
|
WfForm.showMessage(obj.msg);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
console.log('obj ', obj);
|
||||||
|
let objData = obj.data;
|
||||||
|
let responseObj = JSON.parse(objData);
|
||||||
|
if(!responseObj || !responseObj.data){
|
||||||
|
WfForm.showMessage(responseObj.msg);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
objData = responseObj.data;
|
||||||
|
WfForm.changeFieldValue(stuAllField, {value: ''});
|
||||||
|
let stuArr = [];
|
||||||
|
objData.forEach((item)=>{
|
||||||
|
let detailObj = {};
|
||||||
|
detailObj[detail1StuId] = { value: item.id };
|
||||||
|
detailObj[detail1StuNo] = { value: item.studentNo };
|
||||||
|
detailObj[detail1StuName] = { value: item.studentName };
|
||||||
|
detailObj[detail1ClassId] = { value: item.classId };
|
||||||
|
// console.log('detailObj ', detailObj)
|
||||||
|
WfForm.addDetailRow("detail_1",detailObj);
|
||||||
|
stuArr.push(item.studentNo);
|
||||||
|
})
|
||||||
|
WfForm.changeFieldValue(stuAllField, {value: stuArr.join(',')});
|
||||||
|
})
|
||||||
|
});
|
6
pom.xml
6
pom.xml
|
@ -103,6 +103,12 @@
|
||||||
<version>4.4.0</version>
|
<version>4.4.0</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.apache.kafka</groupId>
|
||||||
|
<artifactId>kafka-clients</artifactId>
|
||||||
|
<version>2.3.1</version>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>cn.afterturn</groupId>
|
<groupId>cn.afterturn</groupId>
|
||||||
<artifactId>easypoi-base</artifactId>
|
<artifactId>easypoi-base</artifactId>
|
||||||
|
|
|
@ -6,8 +6,6 @@ import aiyh.utils.excention.CustomerException;
|
||||||
import com.alibaba.fastjson.JSONArray;
|
import com.alibaba.fastjson.JSONArray;
|
||||||
import com.alibaba.fastjson.JSONObject;
|
import com.alibaba.fastjson.JSONObject;
|
||||||
import com.api.xuanran.wang.shyl.service.BatchCreateWorkflowService;
|
import com.api.xuanran.wang.shyl.service.BatchCreateWorkflowService;
|
||||||
import com.api.xuanran.wang.shyl.service.MeetingService;
|
|
||||||
import com.api.xuanran.wang.shyl.vo.CreateWfVO;
|
|
||||||
import com.engine.common.util.ServiceUtil;
|
import com.engine.common.util.ServiceUtil;
|
||||||
import com.engine.workflow.publicApi.WorkflowRequestOperatePA;
|
import com.engine.workflow.publicApi.WorkflowRequestOperatePA;
|
||||||
import com.engine.workflow.publicApi.impl.WorkflowRequestOperatePAImpl;
|
import com.engine.workflow.publicApi.impl.WorkflowRequestOperatePAImpl;
|
||||||
|
@ -16,7 +14,6 @@ import io.swagger.v3.oas.annotations.parameters.RequestBody;
|
||||||
import org.apache.commons.lang3.StringUtils;
|
import org.apache.commons.lang3.StringUtils;
|
||||||
import org.apache.log4j.Logger;
|
import org.apache.log4j.Logger;
|
||||||
import weaver.hrm.User;
|
import weaver.hrm.User;
|
||||||
import weaver.xuanran.wang.common.mapper.CommonMapper;
|
|
||||||
|
|
||||||
import javax.servlet.http.HttpServletRequest;
|
import javax.servlet.http.HttpServletRequest;
|
||||||
import javax.servlet.http.HttpServletResponse;
|
import javax.servlet.http.HttpServletResponse;
|
||||||
|
@ -26,7 +23,6 @@ import javax.ws.rs.Path;
|
||||||
import javax.ws.rs.Produces;
|
import javax.ws.rs.Produces;
|
||||||
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.List;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* <h1>上海团校-批量创建流程接口</h1>
|
* <h1>上海团校-批量创建流程接口</h1>
|
||||||
|
|
|
@ -0,0 +1,54 @@
|
||||||
|
package com.api.xuanran.wang.shyl.controller;
|
||||||
|
|
||||||
|
import aiyh.utils.ApiResult;
|
||||||
|
import aiyh.utils.Util;
|
||||||
|
import aiyh.utils.excention.CustomerException;
|
||||||
|
import com.api.xuanran.wang.shyl.service.UserUpdateToMQService;
|
||||||
|
import org.apache.commons.lang3.StringUtils;
|
||||||
|
import org.apache.log4j.Logger;
|
||||||
|
|
||||||
|
import javax.servlet.http.HttpServletRequest;
|
||||||
|
import javax.servlet.http.HttpServletResponse;
|
||||||
|
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>用户信息更新将数据发送到队列中</h1>
|
||||||
|
*
|
||||||
|
* @author xuanran.wang
|
||||||
|
* @date 2023/3/20 17:15
|
||||||
|
*/
|
||||||
|
@Path("/wxr/user_mq")
|
||||||
|
public class UserUpdateToMQController {
|
||||||
|
private final Logger log = Util.getLogger();
|
||||||
|
private final UserUpdateToMQService userUpdateToMQService = new UserUpdateToMQService();
|
||||||
|
/**
|
||||||
|
* <h1>用户信息更新</h1>
|
||||||
|
* @author xuanran.wang
|
||||||
|
* @dateTime 2023/3/1 15:24
|
||||||
|
**/
|
||||||
|
@Path("/update")
|
||||||
|
@POST
|
||||||
|
@Produces(MediaType.TEXT_PLAIN)
|
||||||
|
public String updateUserInfoToMQ(@Context HttpServletRequest request,
|
||||||
|
@Context HttpServletResponse response){
|
||||||
|
try {
|
||||||
|
String id = Util.null2DefaultStr(request.getParameter("id"),"");
|
||||||
|
String onlyMark = Util.null2DefaultStr(request.getParameter("onlyMark"),"");
|
||||||
|
String configName = Util.null2DefaultStr(request.getParameter("configName"),"");
|
||||||
|
String debug = Util.null2DefaultStr(request.getParameter("debug"),"");
|
||||||
|
if(StringUtils.isBlank(id) || StringUtils.isBlank(onlyMark) || StringUtils.isBlank(configName)){
|
||||||
|
throw new CustomerException("update user to mq id or onlyMark or configName can not null!");
|
||||||
|
}
|
||||||
|
userUpdateToMQService.toMQ(id, onlyMark, configName, debug);
|
||||||
|
return ApiResult.success(null);
|
||||||
|
}catch (Exception e){
|
||||||
|
log.error(Util.logStr("MeetingController error ! {}", e.getMessage()));
|
||||||
|
return ApiResult.error(500,"会议取消接口发生异常! 异常信息 :[ " + e.getMessage() + " ]");
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
|
@ -5,7 +5,7 @@ import aiyh.utils.annotation.recordset.Select;
|
||||||
import aiyh.utils.annotation.recordset.SqlMapper;
|
import aiyh.utils.annotation.recordset.SqlMapper;
|
||||||
import com.api.xuanran.wang.shyl.entity.ProducerCarInfo;
|
import com.api.xuanran.wang.shyl.entity.ProducerCarInfo;
|
||||||
|
|
||||||
import java.util.HashMap;
|
import java.util.Map;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* <h1>生产者mapper</h1>
|
* <h1>生产者mapper</h1>
|
||||||
|
@ -15,6 +15,13 @@ import java.util.HashMap;
|
||||||
*/
|
*/
|
||||||
@SqlMapper
|
@SqlMapper
|
||||||
public interface ProducerMapper {
|
public interface ProducerMapper {
|
||||||
|
/**
|
||||||
|
* <h1>通过车辆ID查信息</h1>
|
||||||
|
* @author xuanran.wang
|
||||||
|
* @dateTime 2023/3/20 17:26
|
||||||
|
* @param id 车辆id
|
||||||
|
* @return 车辆实体
|
||||||
|
**/
|
||||||
@Select("select a.id carCode, Deposit status,b.outkey driver, b.lastname userName, " +
|
@Select("select a.id carCode, Deposit status,b.outkey driver, b.lastname userName, " +
|
||||||
"b.telephone userPhone, carNo plateList, remark " +
|
"b.telephone userPhone, carNo plateList, remark " +
|
||||||
"from carinfo a " +
|
"from carinfo a " +
|
||||||
|
@ -23,6 +30,13 @@ public interface ProducerMapper {
|
||||||
"where a.id = #{id}")
|
"where a.id = #{id}")
|
||||||
ProducerCarInfo queryCarInfo(@ParamMapper("id") String id);
|
ProducerCarInfo queryCarInfo(@ParamMapper("id") String id);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* <h1>通过车排号查信息</h1>
|
||||||
|
* @author xuanran.wang
|
||||||
|
* @dateTime 2023/3/20 17:27
|
||||||
|
* @param carNo 车牌号
|
||||||
|
* @return 车辆实体
|
||||||
|
**/
|
||||||
@Select("select a.id carCode, Deposit status,b.outkey driver, b.lastname userName, " +
|
@Select("select a.id carCode, Deposit status,b.outkey driver, b.lastname userName, " +
|
||||||
"b.telephone userPhone, carNo plateList, remark " +
|
"b.telephone userPhone, carNo plateList, remark " +
|
||||||
"from carinfo a " +
|
"from carinfo a " +
|
||||||
|
@ -30,4 +44,14 @@ public interface ProducerMapper {
|
||||||
"on a.driver = b.id " +
|
"on a.driver = b.id " +
|
||||||
"where a.carNo = #{carNo}")
|
"where a.carNo = #{carNo}")
|
||||||
ProducerCarInfo queryCarNo(@ParamMapper("carNo") String carNo);
|
ProducerCarInfo queryCarNo(@ParamMapper("carNo") String carNo);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* <h1>根据人员ID查询信息</h1>
|
||||||
|
* @author xuanran.wang
|
||||||
|
* @dateTime 2023/3/20 17:27
|
||||||
|
* @param id 人员ID
|
||||||
|
* @return 人员信息
|
||||||
|
**/
|
||||||
|
@Select("select * from hrmresource where id = #{id}")
|
||||||
|
Map<String, Object> queryUserInfo(@ParamMapper("id") String id);
|
||||||
}
|
}
|
||||||
|
|
|
@ -81,6 +81,10 @@ public class CarService {
|
||||||
carNo = Util.null2DefaultStr(request.getParameter("carNo"),"");
|
carNo = Util.null2DefaultStr(request.getParameter("carNo"),"");
|
||||||
info = producerMapper.queryCarNo(carNo);
|
info = producerMapper.queryCarNo(carNo);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//add by taojw
|
||||||
|
// String plateList = info.getPlateList();
|
||||||
|
|
||||||
// 如果能找到就说明是更新或者新增
|
// 如果能找到就说明是更新或者新增
|
||||||
if("del".equals(operation)){ //删除状态下
|
if("del".equals(operation)){ //删除状态下
|
||||||
info = new ProducerCarInfo();
|
info = new ProducerCarInfo();
|
||||||
|
@ -88,6 +92,7 @@ public class CarService {
|
||||||
info.setStatus("1");
|
info.setStatus("1");
|
||||||
info.setRemark("");
|
info.setRemark("");
|
||||||
info.setDriver("");
|
info.setDriver("");
|
||||||
|
//edit by taojw
|
||||||
info.setPlateList("");
|
info.setPlateList("");
|
||||||
info.setUserName("");
|
info.setUserName("");
|
||||||
info.setUserPhone("");
|
info.setUserPhone("");
|
||||||
|
|
|
@ -0,0 +1,57 @@
|
||||||
|
package com.api.xuanran.wang.shyl.service;
|
||||||
|
|
||||||
|
import aiyh.utils.Util;
|
||||||
|
import com.alibaba.fastjson.JSONObject;
|
||||||
|
import com.api.xuanran.wang.shyl.mapper.ProducerMapper;
|
||||||
|
import org.apache.commons.collections.MapUtils;
|
||||||
|
import org.apache.commons.lang3.StringUtils;
|
||||||
|
import org.apache.log4j.Logger;
|
||||||
|
import weaver.conn.RecordSet;
|
||||||
|
import weaver.xiao.commons.config.entity.RequestMappingConfig;
|
||||||
|
import weaver.xiao.commons.config.service.DealWithMapping;
|
||||||
|
import weaver.xuanran.wang.shyl_mq.util.RocketConsumerUtil;
|
||||||
|
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.Objects;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* <h1>用户信息更新将数据发送到队列业务方法</h1>
|
||||||
|
*
|
||||||
|
* @author xuanran.wang
|
||||||
|
* @date 2023/3/20 17:18
|
||||||
|
*/
|
||||||
|
public class UserUpdateToMQService {
|
||||||
|
|
||||||
|
private final Logger logger = Util.getLogger();
|
||||||
|
|
||||||
|
private final DealWithMapping dealWithMapping = new DealWithMapping();
|
||||||
|
|
||||||
|
private final ProducerMapper producerMapper = Util.getMapper(ProducerMapper.class);
|
||||||
|
|
||||||
|
private static final String HRM_TABLE = "hrmresource";
|
||||||
|
|
||||||
|
|
||||||
|
public void toMQ(String id,
|
||||||
|
String onlyMark,
|
||||||
|
String configName,
|
||||||
|
String debug){
|
||||||
|
Map<String, Object> userMap = producerMapper.queryUserInfo(id);
|
||||||
|
if(MapUtils.isEmpty(userMap)){
|
||||||
|
logger.error(Util.logStr("userId: {}, userInfo is empty!"));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
RequestMappingConfig config = dealWithMapping.treeDealWithUniqueCode(onlyMark);
|
||||||
|
dealWithMapping.setMainTable(HRM_TABLE);
|
||||||
|
Map<String, Object> param = dealWithMapping.getRequestParam(userMap, config);
|
||||||
|
if(MapUtils.isEmpty(param)){
|
||||||
|
logger.error(Util.logStr("userId:{}, 生成json为空!",id));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if(StringUtils.isNotBlank(debug)){
|
||||||
|
logger.info("update user json : \n" + JSONObject.toJSONString(param));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
RocketConsumerUtil.producerSendMsg(configName, JSONObject.toJSONString(param), id);
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,70 @@
|
||||||
|
package weaver.shyl.workflow.action;
|
||||||
|
|
||||||
|
import aiyh.utils.Util;
|
||||||
|
import aiyh.utils.entity.DocImageInfo;
|
||||||
|
import aiyh.utils.excention.CustomerException;
|
||||||
|
import com.alibaba.fastjson.JSONObject;
|
||||||
|
import org.apache.commons.lang3.StringUtils;
|
||||||
|
import org.apache.log4j.Logger;
|
||||||
|
import weaver.file.ImageFileManager;
|
||||||
|
import weaver.xiao.commons.config.interfacies.CusInterfaceGetValue;
|
||||||
|
|
||||||
|
import java.io.ByteArrayOutputStream;
|
||||||
|
import java.io.InputStream;
|
||||||
|
import java.util.Base64;
|
||||||
|
import java.util.Map;
|
||||||
|
/**
|
||||||
|
* <h1>团校-流程中字段图片附件转成base64</h1>
|
||||||
|
*
|
||||||
|
* @author xuanran.wang
|
||||||
|
* @date 2023/3/27 22:41
|
||||||
|
*/
|
||||||
|
public class FileTypeFieldConvert implements CusInterfaceGetValue {
|
||||||
|
|
||||||
|
private final Logger log = Util.getLogger();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取参数值
|
||||||
|
*
|
||||||
|
* @param mainMap 主表数据
|
||||||
|
* @param detailMap 明细表数据
|
||||||
|
* @param currentValue 当前字段值
|
||||||
|
* @param pathParam 路径参数
|
||||||
|
* @return 最终返回参数
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public Object execute(Map<String, Object> mainMap, Map<String, Object> detailMap, String currentValue, Map<String, String> pathParam) {
|
||||||
|
try {
|
||||||
|
log.info("原文件图片ID:[" + currentValue + "]");
|
||||||
|
log.info("pathParam : " + JSONObject.toJSONString(pathParam));
|
||||||
|
int tempId = Util.getIntValue(currentValue, -1);
|
||||||
|
if(!"".equals(currentValue) && tempId > 0 && !currentValue.contains(",")) {
|
||||||
|
String imageFileId = Util.null2DefaultStr(pathParam.get("imageFileId"),"");
|
||||||
|
InputStream inputStream;
|
||||||
|
if (StringUtils.isBlank(imageFileId)) {
|
||||||
|
DocImageInfo docImageInfo = Util.selectImageInfoByDocId(currentValue);
|
||||||
|
inputStream = ImageFileManager.getInputStreamById(docImageInfo.getImageFileId());
|
||||||
|
}else {
|
||||||
|
int fileId = Util.getIntValue(currentValue, -1);
|
||||||
|
if(fileId < 0){
|
||||||
|
throw new CustomerException("image file id < 0");
|
||||||
|
}
|
||||||
|
inputStream = ImageFileManager.getInputStreamById(fileId);
|
||||||
|
}
|
||||||
|
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
|
||||||
|
byte[] buffer = new byte[1024];
|
||||||
|
int bytesRead;
|
||||||
|
while ((bytesRead = inputStream.read(buffer)) != -1) {
|
||||||
|
outputStream.write(buffer, 0, bytesRead);
|
||||||
|
}
|
||||||
|
byte[] bytes = outputStream.toByteArray();
|
||||||
|
return Base64.getEncoder().encodeToString(bytes);
|
||||||
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
log.error("convert file to base64 fail!" + e.getMessage() + "\n" + Util.getErrString(e));
|
||||||
|
throw new CustomerException("convert file to base64 fail!");
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -0,0 +1,49 @@
|
||||||
|
package weaver.xuanran.wang.bme.action;
|
||||||
|
|
||||||
|
import aiyh.utils.Util;
|
||||||
|
import org.apache.commons.lang3.StringUtils;
|
||||||
|
import org.apache.log4j.Logger;
|
||||||
|
import weaver.conn.RecordSet;
|
||||||
|
import weaver.interfaces.workflow.action.Action;
|
||||||
|
import weaver.soa.workflow.request.RequestInfo;
|
||||||
|
import weaver.workflow.request.RequestManager;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* <h1>校验客户名称</h1>
|
||||||
|
*
|
||||||
|
* @author xuanran.wang
|
||||||
|
* @date 2023/4/6 09:51
|
||||||
|
*/
|
||||||
|
public class CheckConsumerNameAction implements Action {
|
||||||
|
private final Logger log = Util.getLogger();
|
||||||
|
private String wfConsumerField;
|
||||||
|
private String modelConsumerField;
|
||||||
|
private String modelName;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String execute(RequestInfo request) {
|
||||||
|
String requestId = request.getRequestid();
|
||||||
|
String tableName = request.getRequestManager().getBillTableName();
|
||||||
|
RecordSet rs = new RecordSet();
|
||||||
|
|
||||||
|
wfConsumerField = Util.null2DefaultStr(wfConsumerField, "khmc");
|
||||||
|
modelConsumerField = Util.null2DefaultStr(modelConsumerField, "khmc");
|
||||||
|
modelName = Util.null2DefaultStr(modelName, "uf_kh");
|
||||||
|
|
||||||
|
RequestManager requestManager = request.getRequestManager();
|
||||||
|
rs.executeQuery("select * from " + tableName + " where requestid = ?", requestId);
|
||||||
|
rs.next();
|
||||||
|
String wfConsumer = rs.getString(wfConsumerField);
|
||||||
|
log.info("wfConsumer : [ " + wfConsumer + " ]");
|
||||||
|
if(StringUtils.isNotBlank(wfConsumer)){
|
||||||
|
String sql = "select id from " + modelName + " where " + modelConsumerField + " = ?";
|
||||||
|
log.info("sql : " + sql + " ,参数: " + wfConsumer);
|
||||||
|
if (rs.executeQuery(sql, wfConsumer) && rs.next()) {
|
||||||
|
requestManager.setMessageid(System.currentTimeMillis() + "");
|
||||||
|
requestManager.setMessagecontent("当前客户名称: " + wfConsumer + " ,在客户表中已经存在请修改后提交!");
|
||||||
|
return Action.FAILURE_AND_CONTINUE;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return Action.SUCCESS;
|
||||||
|
}
|
||||||
|
}
|
|
@ -68,6 +68,7 @@ public class ContractApplyComDateAction implements Action {
|
||||||
* <h2>明细前后字段</h2>
|
* <h2>明细前后字段</h2>
|
||||||
**/
|
**/
|
||||||
@RequiredMark
|
@RequiredMark
|
||||||
|
@PrintParamMark
|
||||||
private String beforeBackField;
|
private String beforeBackField;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -124,6 +125,7 @@ public class ContractApplyComDateAction implements Action {
|
||||||
log.error(Util.logStr("checkDate:{}, project:{}", checkDate, project));
|
log.error(Util.logStr("checkDate:{}, project:{}", checkDate, project));
|
||||||
throw new CustomerException("实际验收日期或项目字段字段为空!");
|
throw new CustomerException("实际验收日期或项目字段字段为空!");
|
||||||
}
|
}
|
||||||
|
// select a.id,a.requestid from formtable_main_58 a right join uf_cgdd b on a.htbh = b.lcbh where b.id =
|
||||||
String selectSql = "select id,requestid from " + buildContractTable + " where " + buildContractProjectField + " = ?";
|
String selectSql = "select id,requestid from " + buildContractTable + " where " + buildContractProjectField + " = ?";
|
||||||
if(StringUtils.isNotBlank(relationSql)){
|
if(StringUtils.isNotBlank(relationSql)){
|
||||||
selectSql = relationSql;
|
selectSql = relationSql;
|
||||||
|
@ -159,7 +161,6 @@ public class ContractApplyComDateAction implements Action {
|
||||||
params.add(param);
|
params.add(param);
|
||||||
log.info(Util.logStr("关联流程requestId: {}, 流程明细前后字段: {}, 天数: {}, 计算后的日期: {}",tempRequestId, beforeBack, day, computeDate));
|
log.info(Util.logStr("关联流程requestId: {}, 流程明细前后字段: {}, 天数: {}, 计算后的日期: {}",tempRequestId, beforeBack, day, computeDate));
|
||||||
}
|
}
|
||||||
}
|
|
||||||
if(CollectionUtils.isNotEmpty(params)){
|
if(CollectionUtils.isNotEmpty(params)){
|
||||||
if(!rs.executeBatchSql(updateSql,params)){
|
if(!rs.executeBatchSql(updateSql,params)){
|
||||||
log.error(Util.logStr("更新sql : {}, 参数 : {}", updateSql, params));
|
log.error(Util.logStr("更新sql : {}, 参数 : {}", updateSql, params));
|
||||||
|
@ -168,7 +169,7 @@ public class ContractApplyComDateAction implements Action {
|
||||||
}else {
|
}else {
|
||||||
log.error(Util.logStr("明细表: {}不存在数据!", detailContractTable));
|
log.error(Util.logStr("明细表: {}不存在数据!", detailContractTable));
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}else{
|
}else{
|
||||||
log.error(Util.logStr("查询关联项目sql暂未查到数据! sql {} ,{}", selectSql, requestId));
|
log.error(Util.logStr("查询关联项目sql暂未查到数据! sql {} ,{}", selectSql, requestId));
|
||||||
}
|
}
|
||||||
|
|
|
@ -150,13 +150,15 @@ public class CusInfoToOAUtil {
|
||||||
* @dateTime 2023/2/9 11:51
|
* @dateTime 2023/2/9 11:51
|
||||||
* @param modelId 模块id
|
* @param modelId 模块id
|
||||||
* @param list 插入参数集合
|
* @param list 插入参数集合
|
||||||
* @param whereSql 更新条件
|
* @param whereSql 更新条件sql
|
||||||
* @return 建模数据id
|
* @return 建模数据id
|
||||||
**/
|
**/
|
||||||
public static List<String> executeBatchByEntity(int modelId, List<?> list, String whereSql){
|
public static List<String> executeBatchByEntity(int modelId, List<?> list, String whereSql){
|
||||||
String tableName = checkModelId(modelId);
|
String tableName = checkModelId(modelId);
|
||||||
List<LinkedHashMap<String, Object>> params = new ArrayList<>();
|
List<LinkedHashMap<String, Object>> params = new ArrayList<>();
|
||||||
List<List<String>> whereParams = new ArrayList<>();
|
List<List<String>> whereParams = new ArrayList<>();
|
||||||
|
StringBuilder whereSqlSb;
|
||||||
|
LinkedHashSet<String> whereFields = new LinkedHashSet<>();
|
||||||
for (Object o : list) {
|
for (Object o : list) {
|
||||||
if(Objects.isNull(o)){
|
if(Objects.isNull(o)){
|
||||||
continue;
|
continue;
|
||||||
|
@ -165,7 +167,14 @@ public class CusInfoToOAUtil {
|
||||||
Field[] fields = clazz.getDeclaredFields();
|
Field[] fields = clazz.getDeclaredFields();
|
||||||
LinkedHashMap<String, Object> linkedHashMap = new LinkedHashMap<>();
|
LinkedHashMap<String, Object> linkedHashMap = new LinkedHashMap<>();
|
||||||
ArrayList<String> whereParam = new ArrayList<>();
|
ArrayList<String> whereParam = new ArrayList<>();
|
||||||
for (Field field : fields) {
|
List<Field> fieldArr = Arrays.stream(fields).collect(Collectors.toList());
|
||||||
|
Class<?> superclass = clazz.getSuperclass();
|
||||||
|
// 找出父类所有的字段
|
||||||
|
while (superclass != null){
|
||||||
|
fieldArr.addAll(Arrays.stream(superclass.getDeclaredFields()).collect(Collectors.toList()));
|
||||||
|
superclass = superclass.getSuperclass();
|
||||||
|
}
|
||||||
|
for (Field field : fieldArr) {
|
||||||
field.setAccessible(true);
|
field.setAccessible(true);
|
||||||
String fieldName = field.getName();
|
String fieldName = field.getName();
|
||||||
Object fieldValue;
|
Object fieldValue;
|
||||||
|
@ -194,14 +203,25 @@ public class CusInfoToOAUtil {
|
||||||
if(null == sqlUpdateWhereField || !sqlUpdateWhereField.value()){
|
if(null == sqlUpdateWhereField || !sqlUpdateWhereField.value()){
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
if(StringUtils.isBlank(whereSql)){
|
||||||
|
whereFields.add(fieldName + " = ?");
|
||||||
|
}
|
||||||
whereParam.add(fieldValue.toString());
|
whereParam.add(fieldValue.toString());
|
||||||
}
|
}
|
||||||
params.add(linkedHashMap);
|
params.add(linkedHashMap);
|
||||||
whereParams.add(whereParam);
|
whereParams.add(whereParam);
|
||||||
}
|
}
|
||||||
|
if(!whereFields.isEmpty()){
|
||||||
|
whereSqlSb = new StringBuilder("select id from #{tableName} where ");
|
||||||
|
for (String field : whereFields) {
|
||||||
|
whereSqlSb.append(field).append(" and ");
|
||||||
|
}
|
||||||
|
whereSql = whereSqlSb.substring(0, whereSqlSb.length() - 4);
|
||||||
|
}
|
||||||
return executeBatch(modelId, tableName, params, whereSql, whereParams, true, new ArrayList<>());
|
return executeBatch(modelId, tableName, params, whereSql, whereParams, true, new ArrayList<>());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* <h1>将自定义信息写入建模</h1>
|
* <h1>将自定义信息写入建模</h1>
|
||||||
* @author xuanran.wang
|
* @author xuanran.wang
|
||||||
|
|
|
@ -0,0 +1,64 @@
|
||||||
|
package weaver.xuanran.wang.immc;
|
||||||
|
|
||||||
|
import aiyh.utils.Util;
|
||||||
|
import aiyh.utils.action.SafeCusBaseAction;
|
||||||
|
import aiyh.utils.annotation.ActionDesc;
|
||||||
|
import aiyh.utils.annotation.ActionOptionalParam;
|
||||||
|
import aiyh.utils.annotation.PrintParamMark;
|
||||||
|
import aiyh.utils.annotation.RequiredMark;
|
||||||
|
import weaver.hrm.User;
|
||||||
|
import weaver.soa.workflow.request.RequestInfo;
|
||||||
|
import weaver.xuanran.wang.immc.entity.VmsResponseVoField;
|
||||||
|
import weaver.xuanran.wang.immc.service.WorkFlowToVmsAndMQService;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* <h1>智己 将流程数据推送到接口/kafka队列中</h1>
|
||||||
|
*
|
||||||
|
* @author xuanran.wang
|
||||||
|
* @date 2023/3/30 11:21
|
||||||
|
*/
|
||||||
|
@ActionDesc(value = "智己 将流程数据推送到接口/kafka队列中", author = "xuanran.wang")
|
||||||
|
public class WorkFlowToVmsAndMQ extends SafeCusBaseAction {
|
||||||
|
|
||||||
|
private final WorkFlowToVmsAndMQService workFlowToVmsAndMQService = new WorkFlowToVmsAndMQService();
|
||||||
|
/**
|
||||||
|
* <h2>
|
||||||
|
* OA-uat
|
||||||
|
* 用户密码
|
||||||
|
* oa_uat_user/los0cp6aiV1iO1e2
|
||||||
|
* Topic
|
||||||
|
* oa_service_immc_topic_uat
|
||||||
|
* 接入点
|
||||||
|
* 10.184.42.41:9094,10.184.42.42:9094,10.184.42.40:9094
|
||||||
|
* </h2>
|
||||||
|
**/
|
||||||
|
@PrintParamMark
|
||||||
|
@ActionOptionalParam(value = "", desc = "kafka配置文件名称")
|
||||||
|
private String kafkaConfig;
|
||||||
|
|
||||||
|
@PrintParamMark
|
||||||
|
@RequiredMark("建模配置文件唯一标识")
|
||||||
|
private String onlyMark;
|
||||||
|
|
||||||
|
@PrintParamMark
|
||||||
|
@ActionOptionalParam(value = "code", desc = "接口成功标识字段")
|
||||||
|
private String successField;
|
||||||
|
@PrintParamMark
|
||||||
|
@ActionOptionalParam(value = "200", desc = "接口成功标识默认200")
|
||||||
|
private String successVal;
|
||||||
|
@PrintParamMark
|
||||||
|
@ActionOptionalParam(value = "message", desc = "报错返回信息字段")
|
||||||
|
private String msg;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void doSubmit(String requestId, String billTable, int workflowId, User user, RequestInfo requestInfo) {
|
||||||
|
log.info("-------------- " + requestId + " begin --------------");
|
||||||
|
VmsResponseVoField vmsResponseVoField = VmsResponseVoField
|
||||||
|
.builder()
|
||||||
|
.successField(Util.null2DefaultStr(successField, "code"))
|
||||||
|
.successVal(Util.null2DefaultStr(successVal, "200"))
|
||||||
|
.message(Util.null2DefaultStr(msg, "message"))
|
||||||
|
.build();
|
||||||
|
workFlowToVmsAndMQService.workFlowToVmsAndMQ(onlyMark, billTable, requestId, vmsResponseVoField, kafkaConfig);
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,50 @@
|
||||||
|
package weaver.xuanran.wang.immc.cusfieldvalue;
|
||||||
|
|
||||||
|
import aiyh.utils.Util;
|
||||||
|
import com.alibaba.fastjson.JSONObject;
|
||||||
|
import org.apache.commons.lang3.StringUtils;
|
||||||
|
import org.apache.log4j.Logger;
|
||||||
|
import weaver.xiao.commons.config.interfacies.CusInterfaceGetValue;
|
||||||
|
import weaver.xiao.commons.config.interfacies.CusInterfaceListValue;
|
||||||
|
import weaver.xuanran.wang.immc.mapper.ImMcMapper;
|
||||||
|
|
||||||
|
import java.util.*;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* <h1>附件集合</h1>
|
||||||
|
*
|
||||||
|
* @author xuanran.wang
|
||||||
|
* @date 2023/3/30 15:11
|
||||||
|
*/
|
||||||
|
public class CusListValue implements CusInterfaceGetValue {
|
||||||
|
|
||||||
|
private final Logger log = Util.getLogger();
|
||||||
|
private final ImMcMapper mapper = Util.getMapper(ImMcMapper.class);
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Object execute(Map<String, Object> mainMap, Map<String, Object> detailMap, String currentValue, Map<String, String> pathParam) {
|
||||||
|
List<Object> list = new ArrayList<>();
|
||||||
|
log.info("pathParam : \n" + JSONObject.toJSONString(pathParam));
|
||||||
|
String attachmentField = Util.null2DefaultStr(pathParam.get("attachmentField"), "");
|
||||||
|
String cusSql = Util.null2DefaultStr(pathParam.get("cusSql"), "");
|
||||||
|
if(StringUtils.isNotBlank(cusSql)){
|
||||||
|
String docIds = "";
|
||||||
|
if (StringUtils.isNotBlank(attachmentField)) {
|
||||||
|
List<String> attachment = new ArrayList<>();
|
||||||
|
for (String item : attachmentField.split(",")) {
|
||||||
|
String filedValue = Util.null2DefaultStr(mainMap.get(item),"");
|
||||||
|
if(StringUtils.isNotBlank(Util.null2DefaultStr(mainMap.get(item),""))){
|
||||||
|
attachment.add(filedValue);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
docIds = StringUtils.join(attachment, ",");
|
||||||
|
}
|
||||||
|
cusSql = cusSql
|
||||||
|
.replace("{?docIds}", "( " + docIds + " )")
|
||||||
|
.replace("{?requestid}",Util.null2DefaultStr(mainMap.get("requestid"),""));
|
||||||
|
List<Map<String, String>> attachmentInfo = mapper.getAttachmentInfo(cusSql);
|
||||||
|
list.addAll(attachmentInfo);
|
||||||
|
}
|
||||||
|
return list;
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,23 @@
|
||||||
|
package weaver.xuanran.wang.immc.entity;
|
||||||
|
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
|
import lombok.Builder;
|
||||||
|
import lombok.Data;
|
||||||
|
import lombok.NoArgsConstructor;
|
||||||
|
import org.kie.api.definition.rule.All;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* <h1>vms响应对象</h1>
|
||||||
|
*
|
||||||
|
* @author xuanran.wang
|
||||||
|
* @date 2023/3/30 14:23
|
||||||
|
*/
|
||||||
|
@Data
|
||||||
|
@AllArgsConstructor
|
||||||
|
@NoArgsConstructor
|
||||||
|
@Builder
|
||||||
|
public class VmsResponseVoField {
|
||||||
|
private String successField;
|
||||||
|
private String successVal;
|
||||||
|
private String message;
|
||||||
|
}
|
|
@ -0,0 +1,20 @@
|
||||||
|
package weaver.xuanran.wang.immc.mapper;
|
||||||
|
|
||||||
|
import aiyh.utils.annotation.recordset.Select;
|
||||||
|
import aiyh.utils.annotation.recordset.SqlMapper;
|
||||||
|
import aiyh.utils.annotation.recordset.SqlString;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* <h1>dao</h1>
|
||||||
|
*
|
||||||
|
* @author xuanran.wang
|
||||||
|
* @date 2023/3/30 15:27
|
||||||
|
*/
|
||||||
|
@SqlMapper
|
||||||
|
public interface ImMcMapper {
|
||||||
|
@Select(custom = true)
|
||||||
|
List<Map<String, String>> getAttachmentInfo(@SqlString String sql);
|
||||||
|
}
|
|
@ -0,0 +1,165 @@
|
||||||
|
package weaver.xuanran.wang.immc.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.alibaba.fastjson.JSONObject;
|
||||||
|
import org.apache.commons.collections.MapUtils;
|
||||||
|
import org.apache.commons.lang3.StringUtils;
|
||||||
|
import org.apache.kafka.clients.producer.KafkaProducer;
|
||||||
|
import org.apache.kafka.clients.producer.ProducerRecord;
|
||||||
|
import org.apache.kafka.clients.producer.RecordMetadata;
|
||||||
|
import org.apache.log4j.Logger;
|
||||||
|
import weaver.conn.RecordSet;
|
||||||
|
import weaver.xiao.commons.config.entity.RequestMappingConfig;
|
||||||
|
import weaver.xiao.commons.config.service.DealWithMapping;
|
||||||
|
import weaver.xuanran.wang.common.util.CommonUtil;
|
||||||
|
import weaver.xuanran.wang.immc.entity.VmsResponseVoField;
|
||||||
|
|
||||||
|
import javax.ws.rs.core.MediaType;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* <h1>vms业务方法</h1>
|
||||||
|
*
|
||||||
|
* @Author xuanran.wang
|
||||||
|
* @Date 2022/12/1 10:58
|
||||||
|
*/
|
||||||
|
public class WorkFlowToVmsAndMQService {
|
||||||
|
private static final int SUCCESS_CODE = 200;
|
||||||
|
private final DealWithMapping dealWithMapping = new DealWithMapping();
|
||||||
|
private final Logger log = Util.getLogger(); // 获取日志对象
|
||||||
|
private final HttpUtils httpUtils = new HttpUtils();
|
||||||
|
// 表单字段
|
||||||
|
private static final String MQ_SUCCESS = "mq_success";
|
||||||
|
// 表单字段
|
||||||
|
private static final String VMS_SUCCESS = "vms_success";
|
||||||
|
private static final String SUCCESS = "0";
|
||||||
|
{
|
||||||
|
httpUtils.getGlobalCache().header.put("Content-Type", MediaType.APPLICATION_JSON); // 全局请求头
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* <h1>推送数据</h1>
|
||||||
|
*
|
||||||
|
* @param onlyMark 唯一编码
|
||||||
|
* @param billTable 表名
|
||||||
|
* @param requestId 请求id
|
||||||
|
* @param vmsResponseVoField vms成功标识
|
||||||
|
* @param config kafka配置文件名称
|
||||||
|
* @author xuanran.wang
|
||||||
|
* @dateTime 2022/12/5 17:05
|
||||||
|
**/
|
||||||
|
public void workFlowToVmsAndMQ(String onlyMark, String billTable, String requestId, VmsResponseVoField vmsResponseVoField, String config) {
|
||||||
|
RequestMappingConfig requestMappingConfig = dealWithMapping.treeDealWithUniqueCode(onlyMark); // 将配置参数通过唯一标识查询处理成树形结构
|
||||||
|
String selectMainSql = CommonUtil.getSelectSql(requestMappingConfig, billTable);
|
||||||
|
log.info(Util.logStr("查询主表数据sql : {}, requestId : {}", selectMainSql, requestId));
|
||||||
|
RecordSet recordSet = new RecordSet();
|
||||||
|
recordSet.executeQuery(selectMainSql, requestId);
|
||||||
|
recordSet.next();
|
||||||
|
String url = requestMappingConfig.getRequestUrl();
|
||||||
|
dealWithMapping.setMainTable(billTable);
|
||||||
|
Map<String, Object> param = dealWithMapping.getRequestParam(recordSet, requestMappingConfig);
|
||||||
|
String vmsSuccess = Util.null2DefaultStr(recordSet.getString(VMS_SUCCESS),"");
|
||||||
|
String mqSuccess = Util.null2DefaultStr(recordSet.getString(MQ_SUCCESS),"");
|
||||||
|
if(!SUCCESS.equals(vmsSuccess)){
|
||||||
|
ResponeVo responeVo;
|
||||||
|
try {
|
||||||
|
responeVo = httpUtils.apiPost(url, param);
|
||||||
|
} catch (IOException e) {
|
||||||
|
throw new CustomerException(Util.logStr("发送请求发生异常! : {}", e.getMessage())); // 自定义异常类 create 2022/3/9 2:20 PM 构建日志字符串
|
||||||
|
}
|
||||||
|
parseResponseVo(responeVo, url, param, vmsResponseVoField);
|
||||||
|
updateWorkFlow(VMS_SUCCESS, billTable, requestId);
|
||||||
|
}
|
||||||
|
if(!SUCCESS.equals(mqSuccess) && StringUtils.isNotBlank(config)){
|
||||||
|
sendToMQ(config, param);
|
||||||
|
updateWorkFlow(MQ_SUCCESS, billTable, requestId);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* <h1>解析响应对象</h1>
|
||||||
|
* @author xuanran.wang
|
||||||
|
* @dateTime 2022/12/23 11:25
|
||||||
|
* @param responseVo 响应对象
|
||||||
|
* @param url 地址
|
||||||
|
* @param requestParam 请求
|
||||||
|
**/
|
||||||
|
private void parseResponseVo(ResponeVo responseVo, String url, Map<String, Object> requestParam, VmsResponseVoField vmsResponseVoField){
|
||||||
|
if (responseVo.getCode() != SUCCESS_CODE) { // 相应状态码
|
||||||
|
log.error(Util.logStr("can not fetch [{}],this request params is [{}]," + // 构建日志字符串
|
||||||
|
"this request heard is [{}],but response status code is [{}]," +
|
||||||
|
"this response is [{}]", url, JSON.toJSON(requestParam), JSON.toJSONString(httpUtils.getGlobalCache().header), responseVo.getCode(), // 相应状态码
|
||||||
|
responseVo.getEntityString())); // 相应内容
|
||||||
|
throw new CustomerException(Util.logStr("can not fetch [{}]", url)); // 自定义异常类 create 2022/3/9 2:20 PM 构建日志字符串
|
||||||
|
}
|
||||||
|
log.info(Util.logStr("vmsResponseVoField: {}", JSONObject.toJSONString(vmsResponseVoField)));
|
||||||
|
Map<String, Object> response = responseVo.getResponseMap(); // 根据相应结果转化为map集合
|
||||||
|
String successCode = Util.null2DefaultStr(response.get(vmsResponseVoField.getSuccessField()), "");
|
||||||
|
if (!vmsResponseVoField.getSuccessVal().equals(successCode)) {
|
||||||
|
throw new CustomerException(Util.logStr("接口响应码不为 : [{}],接口响应信息: {}", successCode, Util.null2DefaultStr(response.get(vmsResponseVoField.getMessage()), ""))); // 自定义异常类 create 2022/3/9 2:20 PM 构建日志字符串
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* <h1>将流程信息发送到kafka</h1>
|
||||||
|
* @author xuanran.wang
|
||||||
|
* @dateTime 2023/3/30 14:56
|
||||||
|
* @param kafkaConfig kafka配置文件名称
|
||||||
|
* @param message 消息对象
|
||||||
|
**/
|
||||||
|
public void sendToMQ(String kafkaConfig, Map<String, Object> message){
|
||||||
|
KafkaProducer<String, String> producer = null;
|
||||||
|
try {
|
||||||
|
Map<String, Object> configMap = Util.getProperties2Map(kafkaConfig);
|
||||||
|
if(MapUtils.isEmpty(configMap)){
|
||||||
|
throw new CustomerException("please check /web-inf/prop2map has " + kafkaConfig + ".properties");
|
||||||
|
}
|
||||||
|
log.info("kafkaConfig : " + JSONObject.toJSONString(configMap));
|
||||||
|
String topic = Util.null2DefaultStr(configMap.get("topic"),"");
|
||||||
|
if(StringUtils.isBlank(topic)){
|
||||||
|
throw new CustomerException("kafka properties topic can not null!");
|
||||||
|
}
|
||||||
|
producer = new KafkaProducer<>(configMap);
|
||||||
|
// 发送消息到指定主题
|
||||||
|
ProducerRecord<String, String> record = new ProducerRecord<>(topic, JSONObject.toJSONString(message));
|
||||||
|
try {
|
||||||
|
RecordMetadata recordMetadata = producer.send(record).get();
|
||||||
|
log.info(Util.logStr("send mq recordMetadata: {}", JSONObject.toJSONString(recordMetadata)));
|
||||||
|
}catch (Exception e){
|
||||||
|
throw new CustomerException(Util.logStr("producer send error: {}!", e.getMessage()));
|
||||||
|
}
|
||||||
|
}catch (Exception e){
|
||||||
|
throw new CustomerException(Util.logStr("send to kafka error!: {}", e.getMessage()));
|
||||||
|
}finally {
|
||||||
|
// 关闭Kafka生产者实例
|
||||||
|
if(producer != null){
|
||||||
|
producer.close();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* <h1>更新流程sql</h1>
|
||||||
|
* @author xuanran.wang
|
||||||
|
* @dateTime 2023/3/30 19:18
|
||||||
|
* @param field 主表字段
|
||||||
|
* @param tableName 表名
|
||||||
|
* @param requestId 请求id
|
||||||
|
**/
|
||||||
|
public void updateWorkFlow(String field, String tableName, String requestId){
|
||||||
|
String updateSQL = "update " + tableName + " set " + field + " = " + SUCCESS + " where requestid = ?";
|
||||||
|
RecordSet recordSet = new RecordSet();
|
||||||
|
if(!recordSet.executeUpdate(updateSQL, requestId)){
|
||||||
|
log.error(Util.logStr("update field error! sql: {}, requestId: {}", updateSQL, requestId));
|
||||||
|
throw new CustomerException("更新表单字段失败!");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,26 @@
|
||||||
|
package weaver.xuanran.wang.sh_bigdata.common.entity;
|
||||||
|
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
|
import lombok.Builder;
|
||||||
|
import lombok.Data;
|
||||||
|
import lombok.NoArgsConstructor;
|
||||||
|
|
||||||
|
import java.util.function.Consumer;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* <h1>自定义请求条件</h1>
|
||||||
|
*
|
||||||
|
* @author xuanran.wang
|
||||||
|
* @date 2023/4/6 19:34
|
||||||
|
*/
|
||||||
|
@Data
|
||||||
|
@Builder
|
||||||
|
@AllArgsConstructor
|
||||||
|
@NoArgsConstructor
|
||||||
|
public class CusSuccess {
|
||||||
|
private String successField;
|
||||||
|
private int successValue;
|
||||||
|
private String errorMsg;
|
||||||
|
private String dataKey;
|
||||||
|
private Object response;
|
||||||
|
}
|
|
@ -0,0 +1,25 @@
|
||||||
|
package weaver.xuanran.wang.sh_bigdata.common.entity;
|
||||||
|
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* <h1>token实体类</h1>
|
||||||
|
*
|
||||||
|
* @author xuanran.wang
|
||||||
|
* @date 2023/4/7 23:29
|
||||||
|
*/
|
||||||
|
@Data
|
||||||
|
public class CusToken {
|
||||||
|
/**
|
||||||
|
* <h2>token</h2>
|
||||||
|
**/
|
||||||
|
private String access_token;
|
||||||
|
/**
|
||||||
|
* <h2>有效时间(s)</h2>
|
||||||
|
**/
|
||||||
|
private long expires_in;
|
||||||
|
/**
|
||||||
|
* <h2>过期时间戳</h2>
|
||||||
|
**/
|
||||||
|
private long expiryTime;
|
||||||
|
}
|
|
@ -0,0 +1,74 @@
|
||||||
|
package weaver.xuanran.wang.sh_bigdata.common.util;
|
||||||
|
|
||||||
|
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.alibaba.fastjson.JSONObject;
|
||||||
|
import org.apache.commons.lang3.StringUtils;
|
||||||
|
import org.apache.log4j.Logger;
|
||||||
|
import weaver.xuanran.wang.sh_bigdata.common.entity.CusSuccess;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* <h1>请求模版方法</h1>
|
||||||
|
*
|
||||||
|
* @author xuanran.wang
|
||||||
|
* @date 2023/4/4 11:51
|
||||||
|
*/
|
||||||
|
public class RequestMasterPlate{
|
||||||
|
private final Logger log = Util.getLogger();
|
||||||
|
private final HttpUtils httpUtils = new HttpUtils();
|
||||||
|
private static final int HTTP_SUCCESS_CODE = 200;
|
||||||
|
|
||||||
|
public <T> T apiGet(String url, Map<String, Object> params, Map<String, String> headers, CusSuccess cusSuccess){
|
||||||
|
ResponeVo responeVo;
|
||||||
|
try {
|
||||||
|
responeVo = httpUtils.apiGet(url, params, headers);
|
||||||
|
} catch (IOException e) {
|
||||||
|
throw new CustomerException(Util.logStr("发送请求发生异常! : {}", e.getMessage())); // 自定义异常类 create 2022/3/9 2:20 PM 构建日志字符串
|
||||||
|
}
|
||||||
|
return parseResponse(url, responeVo, params, cusSuccess);
|
||||||
|
}
|
||||||
|
|
||||||
|
public <T> T apiPost(String url, Object o, Map<String, String> headers, CusSuccess cusSuccess){
|
||||||
|
ResponeVo responeVo;
|
||||||
|
try {
|
||||||
|
responeVo = httpUtils.apiPostObject(url, o, headers);
|
||||||
|
} catch (IOException e) {
|
||||||
|
throw new CustomerException(Util.logStr("发送请求发生异常! : {}", e.getMessage())); // 自定义异常类 create 2022/3/9 2:20 PM 构建日志字符串
|
||||||
|
}
|
||||||
|
return parseResponse(url, responeVo, o, cusSuccess);
|
||||||
|
}
|
||||||
|
|
||||||
|
public <T> T parseResponse(String url, ResponeVo responseVo, Object o, CusSuccess cusSuccess){
|
||||||
|
if (responseVo.getCode() != HTTP_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(o), JSON.toJSONString(httpUtils.getGlobalCache().header), responseVo.getCode(), // 相应状态码
|
||||||
|
responseVo.getEntityString())); // 相应内容
|
||||||
|
throw new CustomerException(Util.logStr("can not fetch [{}]", url)); // 自定义异常类 create 2022/3/9 2:20 PM 构建日志字符串
|
||||||
|
}
|
||||||
|
Map<String, Object> response = responseVo.getResponseMap(); // 根据相应结果转化为map集合
|
||||||
|
cusSuccess.setResponse(response);
|
||||||
|
int responseValue = Util.getIntValue(Util.null2DefaultStr(response.get(cusSuccess.getSuccessField()), ""),-1);
|
||||||
|
if (cusSuccess.getSuccessValue() != responseValue) {
|
||||||
|
throw new CustomerException(Util.logStr("接口响应码不为: [{}], 接口响应信息: {}", cusSuccess.getSuccessValue(), Util.null2DefaultStr(response.get(cusSuccess.getErrorMsg()), ""))); // 自定义异常类 create 2022/3/9 2:20 PM 构建日志字符串
|
||||||
|
}
|
||||||
|
String[] split = Util.null2DefaultStr(cusSuccess.getDataKey(),"").split("\\.");
|
||||||
|
int len = split.length;
|
||||||
|
if(len == 0 || StringUtils.isBlank(cusSuccess.getDataKey())){
|
||||||
|
return (T)response;
|
||||||
|
}
|
||||||
|
for (int i = 0; i < len - 1; i++) {
|
||||||
|
response = (Map) response.get(split[i]);
|
||||||
|
}
|
||||||
|
return (T) response.get(split[len - 1]);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,167 @@
|
||||||
|
package weaver.xuanran.wang.sh_bigdata.common.util;
|
||||||
|
|
||||||
|
import aiyh.utils.Util;
|
||||||
|
import aiyh.utils.excention.CustomerException;
|
||||||
|
import com.alibaba.fastjson.JSONObject;
|
||||||
|
import lombok.Data;
|
||||||
|
import org.apache.commons.collections.CollectionUtils;
|
||||||
|
import org.apache.commons.lang3.StringUtils;
|
||||||
|
import org.apache.log4j.Logger;
|
||||||
|
import weaver.workflow.request.todo.RequestStatusObj;
|
||||||
|
import weaver.xuanran.wang.common.mapper.CommonMapper;
|
||||||
|
import weaver.xuanran.wang.sh_bigdata.task_async.entity.CusDoneTask;
|
||||||
|
import weaver.xuanran.wang.sh_bigdata.task_async.entity.CusTodoTask;
|
||||||
|
import weaver.xuanran.wang.sh_bigdata.task_async.mapper.SendTodoTaskMapper;
|
||||||
|
|
||||||
|
import java.util.*;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* <h1></h1>
|
||||||
|
*
|
||||||
|
* @author xuanran.wang
|
||||||
|
* @date 2023/4/6 16:47
|
||||||
|
*/
|
||||||
|
@Data
|
||||||
|
public class SendTodoTaskUtil {
|
||||||
|
private final SendTodoTaskMapper mapper = Util.getMapper(SendTodoTaskMapper.class);
|
||||||
|
private final CommonMapper commonMapper = Util.getMapper(CommonMapper.class);
|
||||||
|
private String appId;
|
||||||
|
private String oaAddress;
|
||||||
|
private Logger log = Util.getLogger();
|
||||||
|
|
||||||
|
{
|
||||||
|
oaAddress = getOAAddress();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* <h1>将待办/已办集合进行去重</h1>
|
||||||
|
* @author xuanran.wang
|
||||||
|
* @dateTime 2023/4/6 17:01
|
||||||
|
* @param list 待办/已办集合
|
||||||
|
* @return 去重后的数据
|
||||||
|
**/
|
||||||
|
public List<RequestStatusObj> distantList(List<RequestStatusObj> list){
|
||||||
|
if(CollectionUtils.isEmpty(list)){
|
||||||
|
return new ArrayList<>();
|
||||||
|
}
|
||||||
|
HashMap<String, RequestStatusObj> obj = new HashMap<>();
|
||||||
|
for (RequestStatusObj statusObj : list) {
|
||||||
|
String str = statusObj.getRequestid() + "" + statusObj.getUser().getUID();
|
||||||
|
if(obj.containsKey(str)){
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
obj.put(str, statusObj);
|
||||||
|
}
|
||||||
|
return new ArrayList<>(obj.values());
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* <h1>将oa任务对象转换成三方系统任务对象</h1>
|
||||||
|
* @author xuanran.wang
|
||||||
|
* @dateTime 2023/4/6 17:29
|
||||||
|
* @param objs 任务对象
|
||||||
|
* @return 三方系统任务接收对象
|
||||||
|
**/
|
||||||
|
public List<CusTodoTask> getTodoTaskInfo(List<RequestStatusObj> objs){
|
||||||
|
ArrayList<CusTodoTask> res = new ArrayList<>();
|
||||||
|
for (RequestStatusObj obj : objs) {
|
||||||
|
String taskId = getTaskId(0, obj);
|
||||||
|
CusTodoTask todoTask = new CusTodoTask();
|
||||||
|
int requestId = obj.getRequestid();
|
||||||
|
int userId = obj.getUser().getUID();
|
||||||
|
todoTask.setTaskNum(taskId);
|
||||||
|
todoTask.setAppId(appId);
|
||||||
|
todoTask.setTaskName(obj.getRequestnamenew());
|
||||||
|
todoTask.setTaskDesc(obj.getRequestnamenew());
|
||||||
|
todoTask.setLinkUrl(oaAddress + "/spa/workflow/static4form/index.html?#/main/workflow/req?requestid="+requestId);
|
||||||
|
todoTask.setMobileLinkUrl(oaAddress + "/spa/workflow/static4mobileform/index.html?#/req?requestid="+requestId);
|
||||||
|
todoTask.setSender(getConvertHrm(0, obj, obj.getCreator().getUID() + ""));
|
||||||
|
todoTask.setReceiver(getConvertHrm(1, obj,userId + ""));
|
||||||
|
res.add(todoTask);
|
||||||
|
}
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* <h1>将oa任务对象转换成三方系统任务对象</h1>
|
||||||
|
* @author xuanran.wang
|
||||||
|
* @dateTime 2023/4/6 17:29
|
||||||
|
* @param objs 任务对象
|
||||||
|
* @return 三方系统任务接收对象
|
||||||
|
**/
|
||||||
|
public List<CusDoneTask> getDoneTaskInfo(List<RequestStatusObj> objs){
|
||||||
|
ArrayList<CusDoneTask> res = new ArrayList<>();
|
||||||
|
for (RequestStatusObj obj : objs) {
|
||||||
|
String taskId = getTaskId(1, obj);
|
||||||
|
List<String> list = mapper.queryUnSendTodoTaskList(taskId);
|
||||||
|
for (String num : list) {
|
||||||
|
CusDoneTask doneTask = new CusDoneTask();
|
||||||
|
doneTask.setTaskNum(num);
|
||||||
|
doneTask.setStatus(1);
|
||||||
|
doneTask.setAppId(appId);
|
||||||
|
res.add(doneTask);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* <h1>获取任务id</h1>
|
||||||
|
* @author xuanran.wang
|
||||||
|
* @dateTime 2023/4/9 17:25
|
||||||
|
* @param type 任务类型 0:待办 1:已办
|
||||||
|
* @param obj 任务对象
|
||||||
|
* @return 任务ID
|
||||||
|
**/
|
||||||
|
public String getTaskId(int type, RequestStatusObj obj){
|
||||||
|
String taskId = obj.getRequestid() + "" + obj.getUser().getUID();
|
||||||
|
if(type == 0){
|
||||||
|
taskId += (System.currentTimeMillis() / 1000);
|
||||||
|
}
|
||||||
|
return taskId;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* <h1>获取转换后的人员id</h1>
|
||||||
|
* @author xuanran.wang
|
||||||
|
* @dateTime 2023/4/6 16:55
|
||||||
|
* @param type 类型 0:发送人 1:接收人
|
||||||
|
* @param obj 任务对象
|
||||||
|
* @param hrmId 人力资源ID
|
||||||
|
* @return 转换后的人员id
|
||||||
|
**/
|
||||||
|
public String getConvertHrm(int type, RequestStatusObj obj, String hrmId){
|
||||||
|
String convertSql;
|
||||||
|
if(type == 0){
|
||||||
|
convertSql = Util.null2DefaultStr(ShBigDataUtil.getPropertiesValByKey("hrmSenderConvertRuleSql"),"");
|
||||||
|
}else {
|
||||||
|
convertSql = Util.null2DefaultStr(ShBigDataUtil.getPropertiesValByKey("hrmReceiveConvertRuleSql"),"");
|
||||||
|
}
|
||||||
|
if(StringUtils.isNotBlank(convertSql) && StringUtils.isNotBlank(hrmId)){
|
||||||
|
List<String> ids = Arrays.stream(hrmId.split(",")).collect(Collectors.toList());
|
||||||
|
int requestId = obj.getRequestid();
|
||||||
|
convertSql = convertSql
|
||||||
|
.replace("{?.requestId}", requestId + "")
|
||||||
|
.replace("{?.nodeId}",obj.getNodeid() + "");
|
||||||
|
return Util.null2DefaultStr(StringUtils.join(mapper.selectHrmConvertId(convertSql, ids), ","),hrmId + "");
|
||||||
|
}
|
||||||
|
return hrmId + "";
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* <h1>获取oa地址</h1>
|
||||||
|
* @author xuanran.wang
|
||||||
|
* @dateTime 2022/12/22 13:51
|
||||||
|
* @return OA地址
|
||||||
|
**/
|
||||||
|
public String getOAAddress(){
|
||||||
|
String address = mapper.queryOAAddress();
|
||||||
|
if(StringUtils.isBlank(address)){
|
||||||
|
throw new CustomerException("OAAddress can not null!");
|
||||||
|
}
|
||||||
|
return address;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,120 @@
|
||||||
|
package weaver.xuanran.wang.sh_bigdata.common.util;
|
||||||
|
|
||||||
|
import aiyh.utils.Util;
|
||||||
|
import aiyh.utils.excention.CustomerException;
|
||||||
|
import com.alibaba.fastjson.JSONObject;
|
||||||
|
import org.apache.commons.collections.MapUtils;
|
||||||
|
import org.apache.commons.lang3.StringUtils;
|
||||||
|
import weaver.xuanran.wang.sh_bigdata.common.entity.CusSuccess;
|
||||||
|
import weaver.xuanran.wang.sh_bigdata.common.entity.CusToken;
|
||||||
|
import weaver.xuanran.wang.sh_bigdata.org_hrm_async.annotations.CusDbEntityMapping;
|
||||||
|
|
||||||
|
import java.lang.reflect.Field;
|
||||||
|
import java.util.*;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* <h1>上海大数据中心工具方法</h1>
|
||||||
|
*
|
||||||
|
* @author xuanran.wang
|
||||||
|
* @date 2023/4/4 11:34
|
||||||
|
*/
|
||||||
|
public class ShBigDataUtil {
|
||||||
|
|
||||||
|
private static final String CONFIG_NAME = "ShBigdataConf";
|
||||||
|
|
||||||
|
private static final List<String> WHILTE_LIST = new ArrayList<>();
|
||||||
|
|
||||||
|
static {
|
||||||
|
WHILTE_LIST.add("hrmSenderConvertRuleSql");
|
||||||
|
WHILTE_LIST.add("hrmReceiveConvertRuleSql");
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* <h1>获取token</h1>
|
||||||
|
* @author xuanran.wang
|
||||||
|
* @dateTime 2023/4/6 19:59
|
||||||
|
* @return token
|
||||||
|
**/
|
||||||
|
public static String getToken(){
|
||||||
|
return TokenUtil.getToken();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* <h1>给post请求的url添加token</h1>
|
||||||
|
* @author xuanran.wang
|
||||||
|
* @dateTime 2023/4/6 20:11
|
||||||
|
* @param url 路径
|
||||||
|
* @return 添加完token的路径url
|
||||||
|
**/
|
||||||
|
public static String addToken2Url(String url){
|
||||||
|
return url + "?access_token=" + getToken();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* <h1>获取配置文件</h1>
|
||||||
|
* @author xuanran.wang
|
||||||
|
* @dateTime 2023/4/4 11:47
|
||||||
|
* @return 配置文件map
|
||||||
|
**/
|
||||||
|
public static Map<String, Object> getConfFromProperties(){
|
||||||
|
Map<String, Object> configMap = Util.getProperties2Map(CONFIG_NAME);
|
||||||
|
if(MapUtils.isEmpty(configMap)){
|
||||||
|
throw new CustomerException(Util.logStr("/web-inf/prop/prop2map/{}.properties can not empty!", CONFIG_NAME));
|
||||||
|
}
|
||||||
|
return configMap;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* <h1>从配置文件中获取指定key的value并进行校验</h1>
|
||||||
|
* @author xuanran.wang
|
||||||
|
* @dateTime 2023/4/6 10:45
|
||||||
|
* @param key 指定的key
|
||||||
|
* @return value
|
||||||
|
**/
|
||||||
|
public static String getPropertiesValByKey(String key){
|
||||||
|
Map<String, Object> conf = getConfFromProperties();
|
||||||
|
String value = Util.null2DefaultStr(conf.get(key), "");
|
||||||
|
if(StringUtils.isBlank(value) && !WHILTE_LIST.contains(key)){
|
||||||
|
throw new CustomerException(Util.logStr("/web-inf/prop/prop2map/{}.properties the key = {} can not empty!",CONFIG_NAME, key));
|
||||||
|
}
|
||||||
|
return value;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* <h1>解析注解并将实体类转换成map</h1>
|
||||||
|
* @author xuanran.wang
|
||||||
|
* @dateTime 2023/4/6 12:27
|
||||||
|
* @param type 表类型 0: 分部, 1: 部门
|
||||||
|
* @param o 对象
|
||||||
|
* @return 参数
|
||||||
|
**/
|
||||||
|
public static LinkedHashMap<String, Object> parseCusDbEntityMapping(int type, Object o) throws IllegalAccessException {
|
||||||
|
Class<?> clazz = o.getClass();
|
||||||
|
LinkedHashMap<String, Object> params = new LinkedHashMap<>();
|
||||||
|
Field[] fields = clazz.getDeclaredFields();
|
||||||
|
Field[] superFields = clazz.getSuperclass().getDeclaredFields();
|
||||||
|
List<Field> collect = Arrays.stream(fields).collect(Collectors.toList());
|
||||||
|
if(superFields.length > 0){
|
||||||
|
collect.addAll(Arrays.stream(superFields).collect(Collectors.toList()));
|
||||||
|
}
|
||||||
|
for (Field field : collect) {
|
||||||
|
CusDbEntityMapping cusDbEntityMapping = field.getDeclaredAnnotation(CusDbEntityMapping.class);
|
||||||
|
if(cusDbEntityMapping != null){
|
||||||
|
String[] dbFields = cusDbEntityMapping.dbFiled();
|
||||||
|
String dbField;
|
||||||
|
if(dbFields.length == 0 || type == -1){
|
||||||
|
dbField = field.getName();
|
||||||
|
}else {
|
||||||
|
int index = Math.min(dbFields.length, type);
|
||||||
|
dbField = dbFields[index - 1];
|
||||||
|
}
|
||||||
|
field.setAccessible(true);
|
||||||
|
params.put(dbField, field.get(o));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return params;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,78 @@
|
||||||
|
package weaver.xuanran.wang.sh_bigdata.common.util;
|
||||||
|
|
||||||
|
import aiyh.utils.Util;
|
||||||
|
import com.alibaba.fastjson.JSONObject;
|
||||||
|
import org.apache.dubbo.common.serialize.fastjson.FastJsonObjectOutput;
|
||||||
|
import org.apache.log4j.Logger;
|
||||||
|
import weaver.xuanran.wang.sh_bigdata.common.entity.CusSuccess;
|
||||||
|
import weaver.xuanran.wang.sh_bigdata.common.entity.CusToken;
|
||||||
|
|
||||||
|
import java.util.Date;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* <h1>token 工具类</h1>
|
||||||
|
*
|
||||||
|
* @author xuanran.wang
|
||||||
|
* @date 2023/4/7 23:27
|
||||||
|
*/
|
||||||
|
public class TokenUtil {
|
||||||
|
private static final Logger log = Util.getLogger();
|
||||||
|
private static volatile CusToken cusToken = null;
|
||||||
|
private static final CusSuccess tokenCusSuccess = CusSuccess.builder()
|
||||||
|
.successField("errcode")
|
||||||
|
.successValue(0)
|
||||||
|
.errorMsg("msg")
|
||||||
|
.dataKey("")
|
||||||
|
.build();
|
||||||
|
private static final RequestMasterPlate requestMasterPlate = new RequestMasterPlate();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* <h1>获取token</h1>
|
||||||
|
* @author xuanran.wang
|
||||||
|
* @dateTime 2023/4/6 19:59
|
||||||
|
* @return token
|
||||||
|
**/
|
||||||
|
public static String getToken() {
|
||||||
|
if(cusToken == null){
|
||||||
|
synchronized (TokenUtil.class){
|
||||||
|
if(cusToken == null){
|
||||||
|
return getTokenByHTTP();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
long expiryTime = cusToken.getExpiryTime();
|
||||||
|
if(new Date().getTime() >= expiryTime){
|
||||||
|
synchronized (TokenUtil.class){
|
||||||
|
expiryTime = cusToken.getExpiryTime();
|
||||||
|
if(new Date().getTime() >= expiryTime){
|
||||||
|
return getTokenByHTTP();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return cusToken.getAccess_token();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* <h1>从接口获取token</h1>
|
||||||
|
* @author xuanran.wang
|
||||||
|
* @dateTime 2023/4/7 23:49
|
||||||
|
* @return token
|
||||||
|
**/
|
||||||
|
private static String getTokenByHTTP(){
|
||||||
|
HashMap<String, Object> params = new HashMap<>();
|
||||||
|
// 接口调用地址
|
||||||
|
String tokenUrl = ShBigDataUtil.getPropertiesValByKey("tokenUrl");
|
||||||
|
// 密钥
|
||||||
|
String corpSecret = ShBigDataUtil.getPropertiesValByKey("corpSecret");
|
||||||
|
params.put("corpsecret", corpSecret);
|
||||||
|
Map<String, Object> tokenMap = requestMasterPlate.apiGet(tokenUrl, params, new HashMap<>(), tokenCusSuccess);
|
||||||
|
cusToken = JSONObject.parseObject(JSONObject.toJSONString(tokenMap), CusToken.class);
|
||||||
|
long expiryBeforeTime = Util.getIntValue(ShBigDataUtil.getPropertiesValByKey("expiryBeforeTime"), 5);
|
||||||
|
// 默认少5分钟过期
|
||||||
|
cusToken.setExpiryTime(new Date().getTime() + (cusToken.getExpires_in() * 1000) - (60 * expiryBeforeTime * 1000));
|
||||||
|
log.info("http token => " + JSONObject.toJSONString(cusToken));
|
||||||
|
return cusToken.getAccess_token();
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,106 @@
|
||||||
|
package weaver.xuanran.wang.sh_bigdata.org_hrm_async;
|
||||||
|
|
||||||
|
import weaver.hrm.resource.HrmSynDAO;
|
||||||
|
import weaver.interfaces.hrm.*;
|
||||||
|
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* <h1>上海大数据中心人员/组织架构同步</h1>
|
||||||
|
*
|
||||||
|
* @author xuanran.wang
|
||||||
|
* @date 2023/4/4 10:21
|
||||||
|
*/
|
||||||
|
public class OrganizationHrmSyncFromOtherSys implements HrmSynService {
|
||||||
|
private HashMap<String, Object> synResult;
|
||||||
|
|
||||||
|
public OrganizationHrmSyncFromOtherSys(){
|
||||||
|
this.removeSynResult();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String SynTimingToOASubCompany() {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String SynTimingToOADepartment() {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String SynTimingToOAJobtitle() {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String SynTimingToOAHrmResource() {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void SynTimingFromOASubCompany(SubCompanyBean[] subCompanyBeans) {
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void SynTimingFromOADepartment(DepartmentBean[] departmentBeans) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void SynTimingFromOAJobtitle(JobTitleBean[] jobTitleBeans) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void SynTimingFromOAHrmResource(UserBean[] userBeans) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void SynInstantSubCompany(SubCompanyBean subCompanyBean) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void SynInstantDepartment(DepartmentBean departmentBean) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void SynInstantJobtitle(JobTitleBean jobTitleBean) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void SynInstantHrmResource(UserBean userBean) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean SynSendMessage(String s, String s1, String s2, String s3, String s4) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public HashMap getSynResult() {
|
||||||
|
return this.synResult;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void removeSynResult() {
|
||||||
|
this.synResult = new HashMap<>();
|
||||||
|
}
|
||||||
|
|
||||||
|
private Map<String, Object> buildItemMap(String pkCode, String pk, String memo, String success, String error) {
|
||||||
|
//保存结果
|
||||||
|
Map<String, Object> res = new HashMap<>();
|
||||||
|
res.put(weaver.hrm.resource.HrmSynDAO.OUTPK, pkCode);
|
||||||
|
res.put(weaver.hrm.resource.HrmSynDAO.PK, pk);
|
||||||
|
res.put(weaver.hrm.resource.HrmSynDAO.Memo, memo);
|
||||||
|
res.put(weaver.hrm.resource.HrmSynDAO.Success, success);
|
||||||
|
res.put(HrmSynDAO.ErrorMessage, error);
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,16 @@
|
||||||
|
package weaver.xuanran.wang.sh_bigdata.org_hrm_async.annotations;
|
||||||
|
|
||||||
|
import java.lang.annotation.*;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* <h1>自定义实体类与数据库映射</h1>
|
||||||
|
*
|
||||||
|
* @author xuanran.wang
|
||||||
|
* @date 2023/4/6 11:55
|
||||||
|
*/
|
||||||
|
@Retention(RetentionPolicy.RUNTIME)
|
||||||
|
@Target({ElementType.FIELD})
|
||||||
|
@Documented
|
||||||
|
public @interface CusDbEntityMapping {
|
||||||
|
String[] dbFiled() default {};
|
||||||
|
}
|
|
@ -0,0 +1,53 @@
|
||||||
|
package weaver.xuanran.wang.sh_bigdata.org_hrm_async.entity;
|
||||||
|
|
||||||
|
import aiyh.utils.annotation.recordset.SqlDbFieldAnn;
|
||||||
|
import lombok.Data;
|
||||||
|
import weaver.xuanran.wang.sh_bigdata.org_hrm_async.annotations.CusDbEntityMapping;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* <h1>上海大数据中心人员/组织架构同步 部门实体类</h1>
|
||||||
|
*
|
||||||
|
* @author xuanran.wang
|
||||||
|
* @date 2023/4/4 11:03
|
||||||
|
*/
|
||||||
|
@Data
|
||||||
|
public class OtherSysDepartment {
|
||||||
|
/**
|
||||||
|
* <h2>创建的部门id</h2>
|
||||||
|
**/
|
||||||
|
@CusDbEntityMapping(dbFiled ={"outkey"})
|
||||||
|
private int id;
|
||||||
|
/**
|
||||||
|
* <h2>部门名称</h2>
|
||||||
|
**/
|
||||||
|
@CusDbEntityMapping(dbFiled = {"subcompanyname", "departmentname"})
|
||||||
|
private String name;
|
||||||
|
/**
|
||||||
|
* <h2>父部门id。根部门为1</h2>
|
||||||
|
**/
|
||||||
|
@CusDbEntityMapping(dbFiled = {"supsubcomid", "supdepid"})
|
||||||
|
private int parentid;
|
||||||
|
/**
|
||||||
|
* <h2>
|
||||||
|
* 在父部门中的次序值。order值大的排序靠前,order值相等的情况下,按照部门id排,id越小排序越靠前。有效的值范围是[0, 2^32)
|
||||||
|
* </h2>
|
||||||
|
**/
|
||||||
|
@CusDbEntityMapping(dbFiled = {"showorder"})
|
||||||
|
private int order;
|
||||||
|
/**
|
||||||
|
* <h2>所属分部id</h2>
|
||||||
|
**/
|
||||||
|
@CusDbEntityMapping(dbFiled = {"supsubcomid","supsubcomid1"})
|
||||||
|
private int subCompanyId;
|
||||||
|
/**
|
||||||
|
* <h2>
|
||||||
|
* 是否有子部门,0:否,1:是
|
||||||
|
* </h2>
|
||||||
|
**/
|
||||||
|
private int hasChild;
|
||||||
|
|
||||||
|
private List<OtherSysDepartment> childList;
|
||||||
|
}
|
|
@ -0,0 +1,25 @@
|
||||||
|
package weaver.xuanran.wang.sh_bigdata.org_hrm_async.mapper;
|
||||||
|
|
||||||
|
import aiyh.utils.annotation.recordset.Select;
|
||||||
|
import aiyh.utils.annotation.recordset.SqlMapper;
|
||||||
|
import aiyh.utils.annotation.recordset.SqlString;
|
||||||
|
import aiyh.utils.annotation.recordset.Update;
|
||||||
|
import io.swagger.models.auth.In;
|
||||||
|
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* <h1>组织架构同步 mapper</h1>
|
||||||
|
*
|
||||||
|
* @author xuanran.wang
|
||||||
|
* @date 2023/4/6 11:05
|
||||||
|
*/
|
||||||
|
@SqlMapper
|
||||||
|
public interface OrgHrmAsyncMapper {
|
||||||
|
|
||||||
|
@Select("select outkey, id from HrmSubCompany where outkey != '' and outkey is not null")
|
||||||
|
Map<Integer, Integer> selectSubCompany();
|
||||||
|
|
||||||
|
@Update(custom = true)
|
||||||
|
boolean updateSubInfo(@SqlString String sql, Map<String, Object> params);
|
||||||
|
}
|
|
@ -0,0 +1,32 @@
|
||||||
|
package weaver.xuanran.wang.sh_bigdata.org_hrm_async.service;
|
||||||
|
|
||||||
|
import weaver.xuanran.wang.sh_bigdata.org_hrm_async.entity.OtherSysDepartment;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* <h1>上海大数据中心人员/组织架构同步 接口调用</h1>
|
||||||
|
*
|
||||||
|
* @author xuanran.wang
|
||||||
|
* @date 2023/4/4 11:09
|
||||||
|
*/
|
||||||
|
public interface OrgHrmAsyncApiService {
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* <h1>获取用户信息</h1>
|
||||||
|
* @author xuanran.wang
|
||||||
|
* @dateTime 2023/4/4 11:13
|
||||||
|
* @return 响应对象
|
||||||
|
**/
|
||||||
|
List<Object> getUserInfo();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* <h1>获取部门信息</h1>
|
||||||
|
* @author xuanran.wang
|
||||||
|
* @dateTime 2023/4/4 11:13
|
||||||
|
* @return 响应对象
|
||||||
|
**/
|
||||||
|
List<OtherSysDepartment> getDepartmentInfo();
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,31 @@
|
||||||
|
package weaver.xuanran.wang.sh_bigdata.org_hrm_async.service;
|
||||||
|
|
||||||
|
import io.swagger.models.auth.In;
|
||||||
|
import weaver.xuanran.wang.sh_bigdata.org_hrm_async.entity.OtherSysDepartment;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* <h1><上海大数据中心人员/组织架构同步 业务方法/h1>
|
||||||
|
*
|
||||||
|
* @author xuanran.wang
|
||||||
|
* @date 2023/4/4 11:07
|
||||||
|
*/
|
||||||
|
public interface OrgHrmAsyncService {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* <h1>获取分部表中 outKey 与 id对应到map集合</h1>
|
||||||
|
* @author xuanran.wang
|
||||||
|
* @dateTime 2023/4/6 13:44
|
||||||
|
* @return 分部表中 outKey 与 id对应到map集合
|
||||||
|
**/
|
||||||
|
Map<Integer, Integer> initSubCompany();
|
||||||
|
/**
|
||||||
|
* <h1>部门数据同步</h1>
|
||||||
|
* @author xuanran.wang
|
||||||
|
* @dateTime 2023/4/6 13:44
|
||||||
|
**/
|
||||||
|
List<OtherSysDepartment> asyncDepartment();
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,49 @@
|
||||||
|
package weaver.xuanran.wang.sh_bigdata.org_hrm_async.service.impl;
|
||||||
|
|
||||||
|
import com.alibaba.fastjson.JSONObject;
|
||||||
|
import weaver.xuanran.wang.sh_bigdata.common.entity.CusSuccess;
|
||||||
|
import weaver.xuanran.wang.sh_bigdata.org_hrm_async.entity.OtherSysDepartment;
|
||||||
|
import weaver.xuanran.wang.sh_bigdata.org_hrm_async.service.OrgHrmAsyncApiService;
|
||||||
|
import weaver.xuanran.wang.sh_bigdata.common.util.RequestMasterPlate;
|
||||||
|
import weaver.xuanran.wang.sh_bigdata.common.util.ShBigDataUtil;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* <h1>
|
||||||
|
* 上海大数据中心人员/组织架构同步 接口调用 具体业务方法
|
||||||
|
* </h1>
|
||||||
|
*
|
||||||
|
* @author xuanran.wang
|
||||||
|
* @date 2023/4/4 11:24
|
||||||
|
*/
|
||||||
|
public class OrgHrmAsyncApiServiceImpl implements OrgHrmAsyncApiService {
|
||||||
|
private final RequestMasterPlate requestMasterPlate = new RequestMasterPlate();
|
||||||
|
@Override
|
||||||
|
public List<Object> getUserInfo() {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<OtherSysDepartment> getDepartmentInfo() {
|
||||||
|
String departmentInfoUrl = ShBigDataUtil.getPropertiesValByKey("departmentInfoUrl");
|
||||||
|
HashMap<String, Object> params = new HashMap<>();
|
||||||
|
params.put("access_token", ShBigDataUtil.getToken());
|
||||||
|
CusSuccess cusSuccess = CusSuccess.builder()
|
||||||
|
.successField("code")
|
||||||
|
.successValue(0)
|
||||||
|
.errorMsg("msg")
|
||||||
|
.dataKey("data.department")
|
||||||
|
.build();
|
||||||
|
List<Map<String, Object>> list = requestMasterPlate.apiGet(departmentInfoUrl, params, new HashMap<>(), cusSuccess);
|
||||||
|
List<OtherSysDepartment> res = new ArrayList<>();
|
||||||
|
for (Object o : list) {
|
||||||
|
res.add(JSONObject.parseObject(JSONObject.toJSONString(o), OtherSysDepartment.class));
|
||||||
|
}
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,163 @@
|
||||||
|
package weaver.xuanran.wang.sh_bigdata.org_hrm_async.service.impl;
|
||||||
|
|
||||||
|
import aiyh.utils.Util;
|
||||||
|
import aiyh.utils.excention.CustomerException;
|
||||||
|
import org.apache.commons.collections.CollectionUtils;
|
||||||
|
import weaver.conn.RecordSet;
|
||||||
|
import weaver.hrm.company.SubCompanyComInfo;
|
||||||
|
import weaver.matrix.MatrixUtil;
|
||||||
|
import weaver.xuanran.wang.sh_bigdata.org_hrm_async.entity.OtherSysDepartment;
|
||||||
|
import weaver.xuanran.wang.sh_bigdata.org_hrm_async.mapper.OrgHrmAsyncMapper;
|
||||||
|
import weaver.xuanran.wang.sh_bigdata.org_hrm_async.service.OrgHrmAsyncApiService;
|
||||||
|
import weaver.xuanran.wang.sh_bigdata.org_hrm_async.service.OrgHrmAsyncService;
|
||||||
|
import weaver.xuanran.wang.sh_bigdata.common.util.ShBigDataUtil;
|
||||||
|
|
||||||
|
import java.util.Comparator;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* <h1>组织架构同步</h1>
|
||||||
|
*
|
||||||
|
* @author xuanran.wang
|
||||||
|
* @date 2023/4/6 10:10
|
||||||
|
*/
|
||||||
|
public class OrgHrmAsyncServiceImpl implements OrgHrmAsyncService {
|
||||||
|
private final OrgHrmAsyncApiService orgHrmAsyncApiService = new OrgHrmAsyncApiServiceImpl();
|
||||||
|
|
||||||
|
private final OrgHrmAsyncMapper orgHrmAsyncMapper = Util.getMapper(OrgHrmAsyncMapper.class);
|
||||||
|
|
||||||
|
private final SubCompanyComInfo sci = new SubCompanyComInfo();
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Map<Integer, Integer> initSubCompany() {
|
||||||
|
return orgHrmAsyncMapper.selectSubCompany();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<OtherSysDepartment> asyncDepartment() {
|
||||||
|
List<OtherSysDepartment> departmentInfo = orgHrmAsyncApiService.getDepartmentInfo();
|
||||||
|
//TODO 分部(条件待确认)
|
||||||
|
List<OtherSysDepartment> subList = departmentInfo
|
||||||
|
.stream()
|
||||||
|
.filter(item -> -1 == item.getParentid())
|
||||||
|
.sorted(Comparator.comparing(OtherSysDepartment::getId))
|
||||||
|
.collect(Collectors.toList());
|
||||||
|
addHrmSubCompany(subList);
|
||||||
|
|
||||||
|
// 过滤出父节点并根据id进行升序排序
|
||||||
|
List<OtherSysDepartment> rootDepList = departmentInfo
|
||||||
|
.stream()
|
||||||
|
.filter(item -> 0 == item.getHasChild() && -1 != item.getParentid())
|
||||||
|
.sorted(Comparator.comparing(OtherSysDepartment::getId))
|
||||||
|
.collect(Collectors.toList());
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* <h1>同步数据到分部</h1>
|
||||||
|
* @author xuanran.wang
|
||||||
|
* @dateTime 2023/4/6 13:37
|
||||||
|
* @param departmentList 部门数据集合
|
||||||
|
**/
|
||||||
|
public void addHrmSubCompany(List<OtherSysDepartment> departmentList){
|
||||||
|
//新增的分部id
|
||||||
|
int subId;
|
||||||
|
char separator = weaver.general.Util.getSeparator();
|
||||||
|
RecordSet rsSch = new RecordSet();
|
||||||
|
// 分部数据
|
||||||
|
Map<Integer, Integer> subCompany = initSubCompany();
|
||||||
|
for (OtherSysDepartment department : departmentList) {
|
||||||
|
subId = Util.getIntValue(Util.null2DefaultStr(subCompany.get(department.getId()),""),-1);
|
||||||
|
if(subId < 0){
|
||||||
|
String para = department.getName() + separator + department.getName() + separator + "1" + separator
|
||||||
|
+ department.getId()+ separator + "" + separator +department.getOrder();
|
||||||
|
rsSch.executeProc("HrmSubCompany_Insert", para);
|
||||||
|
if (rsSch.next()) {
|
||||||
|
subId = rsSch.getInt(1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
updateTable("HrmSubCompany", subId, 0, department);
|
||||||
|
}
|
||||||
|
//清除全部分部缓存
|
||||||
|
sci.removeCompanyCache();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* <h1>同步数据到分部</h1>
|
||||||
|
* @author xuanran.wang
|
||||||
|
* @dateTime 2023/4/6 13:37
|
||||||
|
* @param departmentList 部门数据集合
|
||||||
|
**/
|
||||||
|
public void addHrmDepartment(List<OtherSysDepartment> departmentList){
|
||||||
|
//新增的分部id
|
||||||
|
int id = 0;
|
||||||
|
char separator = weaver.general.Util.getSeparator();
|
||||||
|
RecordSet rsSch = new RecordSet();
|
||||||
|
for (OtherSysDepartment department : departmentList) {
|
||||||
|
String para = department.getName() + separator + department.getName() + separator + "1" + separator
|
||||||
|
+ department.getParentid() + separator + "" + separator +department.getOrder();
|
||||||
|
rsSch.executeProc("HrmSubCompany_Insert", para);
|
||||||
|
if (rsSch.next()) {
|
||||||
|
id = rsSch.getInt(1);
|
||||||
|
updateTable("HrmSubCompany", id, 0, department);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
//清除全部分部缓存
|
||||||
|
sci.removeCompanyCache();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* <h1>更新分部数据</h1>
|
||||||
|
* @author xuanran.wang
|
||||||
|
* @dateTime 2023/4/6 13:35
|
||||||
|
* @param tableName 表名
|
||||||
|
* @param id 数据id
|
||||||
|
* @param type 类型
|
||||||
|
* @param o 对象
|
||||||
|
**/
|
||||||
|
public void updateTable(String tableName, int id, int type, Object o){
|
||||||
|
StringBuilder sb = new StringBuilder("update ");
|
||||||
|
sb.append(tableName).append(" set ");
|
||||||
|
Map<String, Object> params;
|
||||||
|
try {
|
||||||
|
params = ShBigDataUtil.parseCusDbEntityMapping(type, o);
|
||||||
|
}catch (Exception e){
|
||||||
|
throw new CustomerException("parseCusDbEntityMapping error!");
|
||||||
|
}
|
||||||
|
for (Map.Entry<String, Object> entry : params.entrySet()) {
|
||||||
|
sb.append(entry.getKey())
|
||||||
|
.append(" = #{")
|
||||||
|
.append(entry.getKey())
|
||||||
|
.append("},");
|
||||||
|
}
|
||||||
|
sb.deleteCharAt(sb.length() - 1);
|
||||||
|
sb.append(" where id = ").append(id);
|
||||||
|
boolean success = orgHrmAsyncMapper.updateSubInfo(sb.toString(), params);
|
||||||
|
if(!success){
|
||||||
|
throw new CustomerException(Util.logStr("update {} sql error!", tableName));
|
||||||
|
}
|
||||||
|
//同步分部数据到矩阵
|
||||||
|
MatrixUtil.updateSubcompayData(String.valueOf(id));
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setChildList(List<OtherSysDepartment> departmentList){
|
||||||
|
if(departmentList.size() == 0){
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
for (OtherSysDepartment department : departmentList) {
|
||||||
|
List<OtherSysDepartment> childList = departmentList
|
||||||
|
.stream()
|
||||||
|
.filter(item -> department.getId() == item.getParentid())
|
||||||
|
.collect(Collectors.toList());
|
||||||
|
department.setChildList(childList);
|
||||||
|
if(CollectionUtils.isNotEmpty(childList)){
|
||||||
|
setChildList(childList);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,162 @@
|
||||||
|
package weaver.xuanran.wang.sh_bigdata.task_async;
|
||||||
|
|
||||||
|
import aiyh.utils.ThreadPoolConfig;
|
||||||
|
import aiyh.utils.Util;
|
||||||
|
import com.alibaba.fastjson.JSONObject;
|
||||||
|
import org.apache.commons.collections.CollectionUtils;
|
||||||
|
import org.apache.commons.lang3.StringUtils;
|
||||||
|
import org.apache.log4j.Logger;
|
||||||
|
import weaver.ofs.interfaces.SendRequestStatusDataInterfaces;
|
||||||
|
import weaver.workflow.request.todo.DataObj;
|
||||||
|
import weaver.workflow.request.todo.RequestStatusObj;
|
||||||
|
import weaver.xuanran.wang.sh_bigdata.common.util.SendTodoTaskUtil;
|
||||||
|
import weaver.xuanran.wang.sh_bigdata.task_async.service.impl.SendTodoTaskServiceImpl;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.concurrent.ExecutorService;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* <h1>上海大数据中心统一待办推送</h1>
|
||||||
|
*
|
||||||
|
* @author xuanran.wang
|
||||||
|
* @date 2023/4/6 15:43
|
||||||
|
*/
|
||||||
|
public class SendTodoTaskImpl implements SendRequestStatusDataInterfaces {
|
||||||
|
/**
|
||||||
|
* 后台设置id
|
||||||
|
*/
|
||||||
|
public String id;
|
||||||
|
/**
|
||||||
|
* 设置的系统编号
|
||||||
|
*/
|
||||||
|
public String syscode;
|
||||||
|
/**
|
||||||
|
* 服务器URL
|
||||||
|
*/
|
||||||
|
public String serverurl;
|
||||||
|
/**
|
||||||
|
* 流程白名单
|
||||||
|
*/
|
||||||
|
public ArrayList<String> workflowwhitelist;
|
||||||
|
/**
|
||||||
|
* 人员白名单
|
||||||
|
*/
|
||||||
|
public ArrayList<String> userwhitelist;
|
||||||
|
|
||||||
|
|
||||||
|
public String getId() {
|
||||||
|
return id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getSyscode() {
|
||||||
|
return syscode;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getServerurl() {
|
||||||
|
return serverurl;
|
||||||
|
}
|
||||||
|
|
||||||
|
public ArrayList<String> getWorkflowwhitelist() {
|
||||||
|
return workflowwhitelist;
|
||||||
|
}
|
||||||
|
|
||||||
|
public ArrayList<String> getUserwhitelist() {
|
||||||
|
return userwhitelist;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
private final SendTodoTaskServiceImpl sendTodoTaskService = new SendTodoTaskServiceImpl();
|
||||||
|
private final ExecutorService pool = ThreadPoolConfig.createThreadPoolInstance();
|
||||||
|
private final SendTodoTaskUtil sendTodoTaskUtil = new SendTodoTaskUtil();
|
||||||
|
private final Logger log = Util.getLogger();
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void SendRequestStatusData(ArrayList<DataObj> dataList) {
|
||||||
|
for (DataObj dataObj : dataList) {
|
||||||
|
List<RequestStatusObj> todoList = sendTodoTaskUtil.distantList(dataObj.getTododatas());
|
||||||
|
List<RequestStatusObj> doneList = sendTodoTaskUtil.distantList(dataObj.getDonedatas());
|
||||||
|
try {
|
||||||
|
pool.execute(() -> {
|
||||||
|
log.info("todoList => \n" + JSONObject.toJSONString(todoList));
|
||||||
|
log.info("doneList => \n" + JSONObject.toJSONString(doneList));
|
||||||
|
if (CollectionUtils.isNotEmpty(todoList)) {
|
||||||
|
sendTodoTaskService.sendTodo(todoList);
|
||||||
|
}
|
||||||
|
if (CollectionUtils.isNotEmpty(doneList)) {
|
||||||
|
sendTodoTaskService.sendDone(doneList);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
} catch (Exception e) {
|
||||||
|
log.error("SendTodoTaskImpl error! " + e.getMessage());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 格式化JSON格式输出
|
||||||
|
*
|
||||||
|
* @param jsonStr
|
||||||
|
* @return 返回指定格式化的数据
|
||||||
|
*/
|
||||||
|
public static String formatJson(String jsonStr) {
|
||||||
|
if (null == jsonStr || "".equals(jsonStr))
|
||||||
|
return "";
|
||||||
|
StringBuilder sb = new StringBuilder();
|
||||||
|
char last = '\0';
|
||||||
|
char current = '\0';
|
||||||
|
int indent = 0;
|
||||||
|
boolean isInQuotationMarks = false;
|
||||||
|
for (int i = 0; i < jsonStr.length(); i++) {
|
||||||
|
last = current;
|
||||||
|
current = jsonStr.charAt(i);
|
||||||
|
switch (current) {
|
||||||
|
case '"':
|
||||||
|
if (last != '\\') {
|
||||||
|
isInQuotationMarks = !isInQuotationMarks;
|
||||||
|
}
|
||||||
|
sb.append(current);
|
||||||
|
break;
|
||||||
|
case '{':
|
||||||
|
case '[':
|
||||||
|
sb.append(current);
|
||||||
|
if (!isInQuotationMarks) {
|
||||||
|
sb.append('\n');
|
||||||
|
indent++;
|
||||||
|
addIndentBlank(sb, indent);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case '}':
|
||||||
|
case ']':
|
||||||
|
|
||||||
|
if (!isInQuotationMarks) {
|
||||||
|
sb.append('\n');
|
||||||
|
indent--;
|
||||||
|
addIndentBlank(sb, indent);
|
||||||
|
}
|
||||||
|
sb.append(current);
|
||||||
|
break;
|
||||||
|
case ',':
|
||||||
|
sb.append(current);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
sb.append(current);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return sb.toString();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 添加space(缩进)
|
||||||
|
*
|
||||||
|
* @param sb
|
||||||
|
* @param indent
|
||||||
|
*/
|
||||||
|
private static void addIndentBlank(StringBuilder sb, int indent) {
|
||||||
|
for (int i = 0; i < indent; i++) {
|
||||||
|
sb.append('\t');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,23 @@
|
||||||
|
package weaver.xuanran.wang.sh_bigdata.task_async.entity;
|
||||||
|
|
||||||
|
import aiyh.utils.annotation.recordset.SqlOracleDbFieldAnn;
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
|
import lombok.Data;
|
||||||
|
import lombok.NoArgsConstructor;
|
||||||
|
import weaver.xuanran.wang.common.annocation.SqlFieldMapping;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* <h1>已办实体</h1>
|
||||||
|
*
|
||||||
|
* @author xuanran.wang
|
||||||
|
* @date 2023/4/6 22:21
|
||||||
|
*/
|
||||||
|
@Data
|
||||||
|
@NoArgsConstructor
|
||||||
|
@AllArgsConstructor
|
||||||
|
public class CusDoneTask {
|
||||||
|
@SqlFieldMapping
|
||||||
|
private String taskNum;
|
||||||
|
private int status;
|
||||||
|
private String appId;
|
||||||
|
}
|
|
@ -0,0 +1,39 @@
|
||||||
|
package weaver.xuanran.wang.sh_bigdata.task_async.entity;
|
||||||
|
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
|
import lombok.Data;
|
||||||
|
import lombok.EqualsAndHashCode;
|
||||||
|
import lombok.NoArgsConstructor;
|
||||||
|
import weaver.xuanran.wang.common.annocation.SqlFieldMapping;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* <h1>已办oa实体类</h1>
|
||||||
|
*
|
||||||
|
* @author xuanran.wang
|
||||||
|
* @date 2023/4/7 13:19
|
||||||
|
*/
|
||||||
|
@EqualsAndHashCode(callSuper = true)
|
||||||
|
@Data
|
||||||
|
@AllArgsConstructor
|
||||||
|
@NoArgsConstructor
|
||||||
|
public class CusDoneTaskOA extends CusDoneTask{
|
||||||
|
@SqlFieldMapping
|
||||||
|
private String sourceTaskId;
|
||||||
|
@SqlFieldMapping
|
||||||
|
private String response;
|
||||||
|
@SqlFieldMapping
|
||||||
|
private String requestJson;
|
||||||
|
@SqlFieldMapping
|
||||||
|
private int success;
|
||||||
|
@SqlFieldMapping
|
||||||
|
private String requestUrl;
|
||||||
|
@SqlFieldMapping
|
||||||
|
private int taskType;
|
||||||
|
@SqlFieldMapping
|
||||||
|
private String sendTime;
|
||||||
|
/**
|
||||||
|
* <h2>异常</h2>
|
||||||
|
**/
|
||||||
|
@SqlFieldMapping
|
||||||
|
private String error;
|
||||||
|
}
|
|
@ -0,0 +1,29 @@
|
||||||
|
package weaver.xuanran.wang.sh_bigdata.task_async.entity;
|
||||||
|
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
|
import lombok.Data;
|
||||||
|
import lombok.NoArgsConstructor;
|
||||||
|
import weaver.xuanran.wang.common.annocation.SqlFieldMapping;
|
||||||
|
import weaver.xuanran.wang.common.annocation.SqlUpdateWhereField;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* <h1>待办实体</h1>
|
||||||
|
*
|
||||||
|
* @author xuanran.wang
|
||||||
|
* @date 2023/4/6 16:27
|
||||||
|
*/
|
||||||
|
@Data
|
||||||
|
@NoArgsConstructor
|
||||||
|
@AllArgsConstructor
|
||||||
|
public class CusTodoTask {
|
||||||
|
@SqlFieldMapping
|
||||||
|
protected String taskNum;
|
||||||
|
protected String appId;
|
||||||
|
@SqlFieldMapping
|
||||||
|
protected String taskName;
|
||||||
|
protected String taskDesc;
|
||||||
|
protected String linkUrl;
|
||||||
|
protected String mobileLinkUrl;
|
||||||
|
protected String receiver;
|
||||||
|
protected String sender;
|
||||||
|
}
|
|
@ -0,0 +1,68 @@
|
||||||
|
package weaver.xuanran.wang.sh_bigdata.task_async.entity;
|
||||||
|
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
|
import lombok.Data;
|
||||||
|
import lombok.EqualsAndHashCode;
|
||||||
|
import weaver.xuanran.wang.common.annocation.SqlFieldMapping;
|
||||||
|
import weaver.xuanran.wang.common.annocation.SqlUpdateWhereField;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* <h1>写入oa日志表的实体</h1>
|
||||||
|
*
|
||||||
|
* @author xuanran.wang
|
||||||
|
* @date 2023/4/6 20:18
|
||||||
|
*/
|
||||||
|
@EqualsAndHashCode(callSuper = true)
|
||||||
|
@Data
|
||||||
|
@AllArgsConstructor
|
||||||
|
public class CusTodoTaskToOADetail extends CusTodoTask{
|
||||||
|
/**
|
||||||
|
* <h2>任务类型</h2>
|
||||||
|
**/
|
||||||
|
@SqlFieldMapping
|
||||||
|
private int taskType;
|
||||||
|
/**
|
||||||
|
* <h2>请求路径</h2>
|
||||||
|
**/
|
||||||
|
@SqlFieldMapping
|
||||||
|
private String requestUrl;
|
||||||
|
/**
|
||||||
|
* <h2>接口响应</h2>
|
||||||
|
**/
|
||||||
|
@SqlFieldMapping
|
||||||
|
private String response;
|
||||||
|
/**
|
||||||
|
* <h2>任务源id</h2>
|
||||||
|
**/
|
||||||
|
@SqlFieldMapping
|
||||||
|
@SqlUpdateWhereField
|
||||||
|
private String sourceTaskId;
|
||||||
|
/**
|
||||||
|
* <h2>成功/失败</h2>
|
||||||
|
**/
|
||||||
|
@SqlFieldMapping
|
||||||
|
private int success;
|
||||||
|
/**
|
||||||
|
* <h2>已办发送状态</h2>
|
||||||
|
**/
|
||||||
|
@SqlFieldMapping
|
||||||
|
private int status;
|
||||||
|
/**
|
||||||
|
* <h2>待办json</h2>
|
||||||
|
**/
|
||||||
|
@SqlFieldMapping
|
||||||
|
private String requestJson;
|
||||||
|
/**
|
||||||
|
* <h2>发送时间</h2>
|
||||||
|
**/
|
||||||
|
@SqlFieldMapping
|
||||||
|
private String sendTime;
|
||||||
|
/**
|
||||||
|
* <h2>异常</h2>
|
||||||
|
**/
|
||||||
|
@SqlFieldMapping
|
||||||
|
private String error;
|
||||||
|
public CusTodoTaskToOADetail() {
|
||||||
|
super();
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,30 @@
|
||||||
|
package weaver.xuanran.wang.sh_bigdata.task_async.mapper;
|
||||||
|
|
||||||
|
import aiyh.utils.annotation.recordset.*;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* <h1>统一待办推送mapper</h1>
|
||||||
|
*
|
||||||
|
* @author xuanran.wang
|
||||||
|
* @date 2023/4/6 16:49
|
||||||
|
*/
|
||||||
|
@SqlMapper
|
||||||
|
public interface SendTodoTaskMapper {
|
||||||
|
@Select("select hrmtransrule from ofs_sendinfo where syscode = #{sysCode}")
|
||||||
|
String querySendTodoUserConvert(@ParamMapper("sysCode") String sysCode);
|
||||||
|
@Select("select oaaddress from systemset")
|
||||||
|
String queryOAAddress();
|
||||||
|
|
||||||
|
@Select("select taskNum from uf_todo_task_log " +
|
||||||
|
"where sourceTaskId = #{sourceTaskId} and taskType = 0 and status = 0 and success = 0")
|
||||||
|
List<String> queryUnSendTodoTaskList(@ParamMapper("sourceTaskId") String sourceTaskId);
|
||||||
|
|
||||||
|
@Update("update uf_todo_task_log set status = 1 where taskNum in (${taskNums})")
|
||||||
|
boolean updateStatusByTaskNum(@ParamMapper("taskNums") List<String> taskNums);
|
||||||
|
|
||||||
|
@Select(custom = true)
|
||||||
|
List<String> selectHrmConvertId(@SqlString String sql, @ParamMapper("ids") List<String> ids);
|
||||||
|
}
|
|
@ -0,0 +1,16 @@
|
||||||
|
package weaver.xuanran.wang.sh_bigdata.task_async.service;
|
||||||
|
|
||||||
|
import weaver.workflow.request.todo.RequestStatusObj;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* <h1>发送待办和已办</h1>
|
||||||
|
*
|
||||||
|
* @author xuanran.wang
|
||||||
|
* @date 2023/4/6 16:31
|
||||||
|
*/
|
||||||
|
public interface SendTodoTaskService {
|
||||||
|
void sendTodo(List<RequestStatusObj> todoList);
|
||||||
|
void sendDone(List<RequestStatusObj> doneList);
|
||||||
|
}
|
|
@ -0,0 +1,152 @@
|
||||||
|
package weaver.xuanran.wang.sh_bigdata.task_async.service.impl;
|
||||||
|
|
||||||
|
import aiyh.utils.Util;
|
||||||
|
import aiyh.utils.excention.CustomerException;
|
||||||
|
import com.alibaba.fastjson.JSONObject;
|
||||||
|
import lombok.Data;
|
||||||
|
import org.apache.commons.collections.CollectionUtils;
|
||||||
|
import org.apache.commons.lang3.StringUtils;
|
||||||
|
import org.apache.log4j.Logger;
|
||||||
|
import weaver.general.TimeUtil;
|
||||||
|
import weaver.workflow.request.todo.RequestStatusObj;
|
||||||
|
import weaver.xuanran.wang.common.util.CusInfoToOAUtil;
|
||||||
|
import weaver.xuanran.wang.sh_bigdata.common.entity.CusSuccess;
|
||||||
|
import weaver.xuanran.wang.sh_bigdata.common.util.RequestMasterPlate;
|
||||||
|
import weaver.xuanran.wang.sh_bigdata.common.util.ShBigDataUtil;
|
||||||
|
import weaver.xuanran.wang.sh_bigdata.task_async.entity.CusDoneTask;
|
||||||
|
import weaver.xuanran.wang.sh_bigdata.task_async.entity.CusDoneTaskOA;
|
||||||
|
import weaver.xuanran.wang.sh_bigdata.task_async.entity.CusTodoTask;
|
||||||
|
import weaver.xuanran.wang.sh_bigdata.task_async.entity.CusTodoTaskToOADetail;
|
||||||
|
import weaver.xuanran.wang.sh_bigdata.task_async.mapper.SendTodoTaskMapper;
|
||||||
|
import weaver.xuanran.wang.sh_bigdata.task_async.service.SendTodoTaskService;
|
||||||
|
import weaver.xuanran.wang.sh_bigdata.common.util.SendTodoTaskUtil;
|
||||||
|
|
||||||
|
import javax.ws.rs.core.MediaType;
|
||||||
|
import java.util.*;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* <h1></h1>
|
||||||
|
*
|
||||||
|
* @author xuanran.wang
|
||||||
|
* @date 2023/4/6 16:46
|
||||||
|
*/
|
||||||
|
@Data
|
||||||
|
public class SendTodoTaskServiceImpl implements SendTodoTaskService {
|
||||||
|
private final Logger log = Util.getLogger();
|
||||||
|
private String appId;
|
||||||
|
private final SendTodoTaskUtil sendTodoTaskUtil = new SendTodoTaskUtil();
|
||||||
|
private String addTodoTaskUrl;
|
||||||
|
private String updateTodoTaskUrl;
|
||||||
|
private static final String MODEL_NAME = "uf_todo_task_log";
|
||||||
|
private final HashMap<String,String> header = new HashMap<>();
|
||||||
|
private int modelId;
|
||||||
|
private final RequestMasterPlate requestMasterPlate = new RequestMasterPlate();
|
||||||
|
private final SendTodoTaskMapper mapper = Util.getMapper(SendTodoTaskMapper.class);
|
||||||
|
|
||||||
|
|
||||||
|
{
|
||||||
|
sendTodoTaskUtil.setAppId(ShBigDataUtil.getPropertiesValByKey("appId"));
|
||||||
|
modelId = Util.getIntValue(ShBigDataUtil.getPropertiesValByKey("modelId"),-1);
|
||||||
|
addTodoTaskUrl = ShBigDataUtil.getPropertiesValByKey("addTodoTaskUrl");
|
||||||
|
updateTodoTaskUrl = ShBigDataUtil.getPropertiesValByKey("updateTodoTaskUrl");
|
||||||
|
header.put("Content-Type", MediaType.APPLICATION_JSON);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void sendTodo(List<RequestStatusObj> todoList) {
|
||||||
|
try {
|
||||||
|
CusSuccess cusSuccess = CusSuccess.builder()
|
||||||
|
.successField("code")
|
||||||
|
.successValue(200)
|
||||||
|
.errorMsg("msg")
|
||||||
|
.dataKey("")
|
||||||
|
.build();
|
||||||
|
|
||||||
|
List<CusTodoTask> taskInfo = sendTodoTaskUtil.getTodoTaskInfo(todoList);
|
||||||
|
log.info("---------------- todoTaskInfo ---------------- \n" + JSONObject.toJSONString(taskInfo));
|
||||||
|
Map<String, Object> response = null;
|
||||||
|
int success = 0;
|
||||||
|
String error = null;
|
||||||
|
try {
|
||||||
|
response = requestMasterPlate.apiPost(ShBigDataUtil.addToken2Url(addTodoTaskUrl), taskInfo, header, cusSuccess);
|
||||||
|
}catch (Exception e){
|
||||||
|
log.error("Send Todo API Post Error! " + Util.getErrString(e));
|
||||||
|
error = "Send Todo API Post Error! " + e.getMessage();
|
||||||
|
success = 1;
|
||||||
|
}
|
||||||
|
ArrayList<CusTodoTaskToOADetail> details = new ArrayList<>();
|
||||||
|
for (CusTodoTask cusTodoTask : taskInfo) {
|
||||||
|
|
||||||
|
CusTodoTaskToOADetail detail = new CusTodoTaskToOADetail();
|
||||||
|
detail.setTaskNum(cusTodoTask.getTaskNum());
|
||||||
|
detail.setRequestUrl(addTodoTaskUrl);
|
||||||
|
detail.setTaskName(cusTodoTask.getTaskName());
|
||||||
|
detail.setTaskType(0);
|
||||||
|
detail.setStatus(0);
|
||||||
|
detail.setSuccess(success);
|
||||||
|
detail.setResponse(JSONObject.toJSONString(cusSuccess.getResponse() == null ? response : cusSuccess.getResponse()));
|
||||||
|
detail.setRequestJson(JSONObject.toJSONString(cusTodoTask));
|
||||||
|
String sourceTaskId = detail.getTaskNum().substring(0, detail.getTaskNum().length() - 10);
|
||||||
|
detail.setSourceTaskId(sourceTaskId);
|
||||||
|
detail.setSendTime(TimeUtil.getCurrentTimeString());
|
||||||
|
detail.setError(error);
|
||||||
|
details.add(detail);
|
||||||
|
}
|
||||||
|
CusInfoToOAUtil.executeBatchByEntity(modelId, details,"");
|
||||||
|
}catch (Exception e){
|
||||||
|
log.error("send todo error! " + Util.getErrString(e));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void sendDone(List<RequestStatusObj> doneList) {
|
||||||
|
try {
|
||||||
|
CusSuccess cusSuccess = CusSuccess.builder()
|
||||||
|
.successField("code")
|
||||||
|
.successValue(200)
|
||||||
|
.errorMsg("msg")
|
||||||
|
.dataKey("")
|
||||||
|
.build();
|
||||||
|
|
||||||
|
List<CusDoneTask> doneTaskInfo = sendTodoTaskUtil.getDoneTaskInfo(doneList);
|
||||||
|
log.info("---------------- doneTaskInfo ---------------- \n" + JSONObject.toJSONString(doneTaskInfo));
|
||||||
|
Map<String, Object> response = null;
|
||||||
|
ArrayList<CusDoneTaskOA> list = new ArrayList<>();
|
||||||
|
ArrayList<String> successTaskIds = new ArrayList<>();
|
||||||
|
String error = "";
|
||||||
|
for (CusDoneTask doneTask : doneTaskInfo) {
|
||||||
|
int success = 0;
|
||||||
|
try {
|
||||||
|
response = requestMasterPlate.apiPost(ShBigDataUtil.addToken2Url(updateTodoTaskUrl), doneTask, header, cusSuccess);
|
||||||
|
successTaskIds.add(doneTask.getTaskNum());
|
||||||
|
}catch (Exception e){
|
||||||
|
log.error("Send Todo API Post Error! " + Util.getErrString(e));
|
||||||
|
error = "Send Todo API Post Error! " + Util.getErrString(e);
|
||||||
|
success = 1;
|
||||||
|
}
|
||||||
|
CusDoneTaskOA taskOA = new CusDoneTaskOA();
|
||||||
|
taskOA.setTaskNum(doneTask.getTaskNum());
|
||||||
|
taskOA.setTaskType(1);
|
||||||
|
String sourceTaskId = doneTask.getTaskNum().substring(0, doneTask.getTaskNum().length() - 10);
|
||||||
|
taskOA.setSourceTaskId(sourceTaskId);
|
||||||
|
taskOA.setResponse(JSONObject.toJSONString(cusSuccess.getResponse() == null ? response : cusSuccess.getResponse()));
|
||||||
|
taskOA.setRequestUrl(updateTodoTaskUrl);
|
||||||
|
taskOA.setRequestJson(JSONObject.toJSONString(doneTask));
|
||||||
|
taskOA.setSuccess(success);
|
||||||
|
taskOA.setSendTime(TimeUtil.getCurrentTimeString());
|
||||||
|
taskOA.setError(error);
|
||||||
|
list.add(taskOA);
|
||||||
|
}
|
||||||
|
CusInfoToOAUtil.executeBatchByEntity(modelId, list,"");
|
||||||
|
if(CollectionUtils.isNotEmpty(successTaskIds)){
|
||||||
|
mapper.updateStatusByTaskNum(successTaskIds);
|
||||||
|
}
|
||||||
|
}catch (Exception e){
|
||||||
|
log.error("send done error! " + Util.getErrString(e));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
|
@ -24,7 +24,7 @@ public class MQMessage {
|
||||||
* AUTH_CONSOLE_USERINFO_PASSWORD_TOPIC: 密码修改队列
|
* AUTH_CONSOLE_USERINFO_PASSWORD_TOPIC: 密码修改队列
|
||||||
* </p>
|
* </p>
|
||||||
**/
|
**/
|
||||||
@SqlFieldMapping()
|
@SqlFieldMapping
|
||||||
private String topic;
|
private String topic;
|
||||||
/**
|
/**
|
||||||
* <h2>消息内容操作类型</h2>
|
* <h2>消息内容操作类型</h2>
|
||||||
|
@ -35,19 +35,19 @@ public class MQMessage {
|
||||||
* PASSWORD_ACTION: 修改密码
|
* PASSWORD_ACTION: 修改密码
|
||||||
* </p>
|
* </p>
|
||||||
**/
|
**/
|
||||||
@SqlFieldMapping()
|
@SqlFieldMapping
|
||||||
private String actionType;
|
private String actionType;
|
||||||
/**
|
/**
|
||||||
* <h2>消息发送时间</h2>
|
* <h2>消息发送时间</h2>
|
||||||
**/
|
**/
|
||||||
@SqlFieldMapping()
|
@SqlFieldMapping
|
||||||
private String sendTime;
|
private String sendTime;
|
||||||
/**
|
/**
|
||||||
* <h2>消息业务内容,json 格式,分业务(用户、机构、密码修改)</h2>
|
* <h2>消息业务内容,json 格式,分业务(用户、机构、密码修改)</h2>
|
||||||
**/
|
**/
|
||||||
@SqlFieldMapping()
|
@SqlFieldMapping
|
||||||
private String content;
|
private String content;
|
||||||
|
|
||||||
@SqlFieldMapping()
|
@SqlFieldMapping
|
||||||
private String error;
|
private String error;
|
||||||
}
|
}
|
||||||
|
|
|
@ -100,7 +100,7 @@ public interface ConsumerMapper {
|
||||||
* @param id id
|
* @param id id
|
||||||
* @return true/false
|
* @return true/false
|
||||||
**/
|
**/
|
||||||
@Delete("delete from hrmresource where id = #{id}")
|
@Delete("update hrmresource set status = 7 where id = #{id}")
|
||||||
boolean deleteHrmById(@ParamMapper("id") String id);
|
boolean deleteHrmById(@ParamMapper("id") String id);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -115,4 +115,8 @@ public interface ConsumerMapper {
|
||||||
|
|
||||||
@Select("select count(1) from uf_mqLog where messageId = #{messageId}")
|
@Select("select count(1) from uf_mqLog where messageId = #{messageId}")
|
||||||
int getMainIdFromMQLogByMessageId(@ParamMapper("messageId") String messageId);
|
int getMainIdFromMQLogByMessageId(@ParamMapper("messageId") String messageId);
|
||||||
|
|
||||||
|
@Update("update hrmresource set loginId = #{loginId} where id = #{id}")
|
||||||
|
boolean updateHrmLoginIdById(@ParamMapper("id") String id,
|
||||||
|
@ParamMapper("loginId") String loginId);
|
||||||
}
|
}
|
||||||
|
|
|
@ -29,7 +29,7 @@ public class ProducerService {
|
||||||
private final Logger logger = Util.getLogger();
|
private final Logger logger = Util.getLogger();
|
||||||
|
|
||||||
private final DealWithMapping dealWithMapping = new DealWithMapping();
|
private final DealWithMapping dealWithMapping = new DealWithMapping();
|
||||||
private final ToolUtil toolUtil = new ToolUtil();
|
|
||||||
private final HttpUtils httpUtils = new HttpUtils();
|
private final HttpUtils httpUtils = new HttpUtils();
|
||||||
|
|
||||||
{
|
{
|
||||||
|
@ -54,7 +54,7 @@ public class ProducerService {
|
||||||
ChangeRequestParam changeRequestParam){
|
ChangeRequestParam changeRequestParam){
|
||||||
RequestMappingConfig requestMappingConfig = dealWithMapping.treeDealWithUniqueCode(onlyMark);
|
RequestMappingConfig requestMappingConfig = dealWithMapping.treeDealWithUniqueCode(onlyMark);
|
||||||
String selectMainSql = CommonUtil.getSelectSql(requestMappingConfig, tableName);
|
String selectMainSql = CommonUtil.getSelectSql(requestMappingConfig, tableName);
|
||||||
logger.info("查询主表sql : " + selectMainSql);
|
// logger.info("查询主表sql : " + selectMainSql);
|
||||||
RecordSet recordSet = new RecordSet();
|
RecordSet recordSet = new RecordSet();
|
||||||
recordSet.executeQuery(selectMainSql, requestId);
|
recordSet.executeQuery(selectMainSql, requestId);
|
||||||
Map<String, Object> requestParam = new HashMap<>();
|
Map<String, Object> requestParam = new HashMap<>();
|
||||||
|
@ -69,10 +69,6 @@ public class ProducerService {
|
||||||
if(!Objects.isNull(changeRequestParam)){
|
if(!Objects.isNull(changeRequestParam)){
|
||||||
changeRequestParam.changeRequestParam(requestParam);
|
changeRequestParam.changeRequestParam(requestParam);
|
||||||
}
|
}
|
||||||
// logger.info(Util.logStr("requestId : {}, msg:{}", requestId, JSONObject.toJSONString(requestParam)));
|
RocketConsumerUtil.producerSendMsg(configName, JSONObject.toJSONString(requestParam), requestId);
|
||||||
String sendMQ = Util.null2DefaultStr(toolUtil.getSystemParamValue("sendMQ"),"");
|
|
||||||
if("1".equals(sendMQ)){
|
|
||||||
RocketConsumerUtil.producerSendMsg(configName,JSONObject.toJSONString(requestParam), requestId);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -42,14 +42,14 @@ public class PassWordServiceImpl extends CusInfoActionService {
|
||||||
String content = message.getContent();
|
String content = message.getContent();
|
||||||
ModifyPassWord passWord = JSONObject.parseObject(content, ModifyPassWord.class);
|
ModifyPassWord passWord = JSONObject.parseObject(content, ModifyPassWord.class);
|
||||||
logger.info(Util.logStr("cusPassWordAction messageId: {},UserInfo : {} ",message.getId(),JSONObject.toJSONString(passWord)));
|
logger.info(Util.logStr("cusPassWordAction messageId: {},UserInfo : {} ",message.getId(),JSONObject.toJSONString(passWord)));
|
||||||
String outKey = passWord.getId();
|
// String outKey = passWord.getId();
|
||||||
String hrmId = consumerMapper.getHrmIdByOutKey(outKey);
|
// String hrmId = consumerMapper.getHrmIdByOutKey(outKey);
|
||||||
if(StringUtils.isBlank(hrmId)){
|
// if(StringUtils.isBlank(hrmId)){
|
||||||
throw new CustomerException(Util.logStr("the userId is {} , no personnel information found in oa!", outKey));
|
// throw new CustomerException(Util.logStr("the userId is {} , no personnel information found in oa!", outKey));
|
||||||
}
|
// }
|
||||||
if (!consumerMapper.updatePasswordById(hrmId, Util.getEncrypt(passWord.getPassword()))) {
|
// if (!consumerMapper.updatePasswordById(hrmId, Util.getEncrypt(passWord.getPassword()))) {
|
||||||
throw new CustomerException("update user password error!");
|
// throw new CustomerException("update user password error!");
|
||||||
}
|
// }
|
||||||
writeInOA(message.getId());
|
writeInOA(message.getId());
|
||||||
return ConsumeConcurrentlyStatus.CONSUME_SUCCESS;
|
return ConsumeConcurrentlyStatus.CONSUME_SUCCESS;
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
|
|
|
@ -0,0 +1,124 @@
|
||||||
|
package weaver.xuanran.wang.shyl_mq.service.impl;
|
||||||
|
|
||||||
|
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.apache.rocketmq.client.consumer.listener.ConsumeConcurrentlyStatus;
|
||||||
|
import weaver.hrm.resource.ResourceComInfo;
|
||||||
|
import weaver.xuanran.wang.shyl_mq.entity.MQMessage;
|
||||||
|
import weaver.xuanran.wang.shyl_mq.entity.UserInfo;
|
||||||
|
import weaver.xuanran.wang.shyl_mq.service.CusInfoActionService;
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* <h1>用户业务方法</h1>
|
||||||
|
*
|
||||||
|
* @Author xuanran.wang
|
||||||
|
* @Date 2022/12/30 13:04
|
||||||
|
*/
|
||||||
|
public class UserServiceImpl extends CusInfoActionService {
|
||||||
|
private Logger logger = Util.getLogger("mq-consumer-user");
|
||||||
|
|
||||||
|
{
|
||||||
|
if(null == logger){
|
||||||
|
logger = Util.getLogger("mq-consumer-user");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* <h1>用户新增</h1>
|
||||||
|
* @author xuanran.wang
|
||||||
|
* @dateTime 2023/1/3 13:37
|
||||||
|
* @param message mq消息
|
||||||
|
* @return 成功/重试
|
||||||
|
**/
|
||||||
|
@Override
|
||||||
|
public ConsumeConcurrentlyStatus cusCreateAction(MQMessage message) {
|
||||||
|
try {
|
||||||
|
String content = message.getContent();
|
||||||
|
UserInfo userInfo = JSONObject.parseObject(content, UserInfo.class);
|
||||||
|
logger.info(Util.logStr("userCusCreateAction messageId: {}, UserInfo : {} ",message.getId(), JSONObject.toJSONString(userInfo)));
|
||||||
|
updateLoginId(userInfo);
|
||||||
|
writeInOA(message.getId());
|
||||||
|
return ConsumeConcurrentlyStatus.CONSUME_SUCCESS;
|
||||||
|
}catch (Exception e){
|
||||||
|
throw new CustomerException(Util.logStr("hrmCreateAction error : {}", e.getMessage()));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* <h1>用户删除</h1>
|
||||||
|
* @author xuanran.wang
|
||||||
|
* @dateTime 2023/1/3 13:38
|
||||||
|
* @param message mq消息
|
||||||
|
* @return 成功/重试
|
||||||
|
**/
|
||||||
|
@Override
|
||||||
|
public ConsumeConcurrentlyStatus cusDeleteAction(MQMessage message) {
|
||||||
|
try {
|
||||||
|
String content = message.getContent();
|
||||||
|
UserInfo userInfo = JSONObject.parseObject(content, UserInfo.class);
|
||||||
|
logger.info(Util.logStr("userCusDeleteAction messageId: {},UserInfo : {} ", message.getId(),JSONObject.toJSONString(userInfo)));
|
||||||
|
String id = Util.null2DefaultStr(userInfo.getId(),"");
|
||||||
|
if(StringUtils.isBlank(id)){
|
||||||
|
throw new CustomerException("del user id not null!");
|
||||||
|
}
|
||||||
|
if (!consumerMapper.deleteHrmById(id)) {
|
||||||
|
throw new CustomerException("del user sql execute error!");
|
||||||
|
}
|
||||||
|
ResourceComInfo resourceComInfo = new ResourceComInfo();
|
||||||
|
resourceComInfo.updateResourceInfoCache(id);
|
||||||
|
writeInOA(message.getId());
|
||||||
|
return ConsumeConcurrentlyStatus.CONSUME_SUCCESS;
|
||||||
|
} catch (Exception e) {
|
||||||
|
throw new CustomerException(Util.logStr("hrmDeleteAction execute error : [{}]!", e.getMessage()));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* <h1>用户更新</h1>
|
||||||
|
* @author xuanran.wang
|
||||||
|
* @dateTime 2023/1/3 13:39
|
||||||
|
* @param message mq消息
|
||||||
|
* @return 成功/重试
|
||||||
|
**/
|
||||||
|
@Override
|
||||||
|
public ConsumeConcurrentlyStatus cusUpdateAction(MQMessage message) {
|
||||||
|
try {
|
||||||
|
String content = message.getContent();
|
||||||
|
UserInfo userInfo = JSONObject.parseObject(content, UserInfo.class);
|
||||||
|
logger.info(Util.logStr("userCusUpdateAction messageId: {},UserInfo : {} ", message.getId(), JSONObject.toJSONString(userInfo)));
|
||||||
|
updateLoginId(userInfo);
|
||||||
|
writeInOA(message.getId());
|
||||||
|
return ConsumeConcurrentlyStatus.CONSUME_SUCCESS;
|
||||||
|
}catch (Exception e){
|
||||||
|
throw new CustomerException(Util.logStr("userCusUpdateAction execute error : [{}]!", e.getMessage()));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* <h1><更新登陆名/h1>
|
||||||
|
* @author xuanran.wang
|
||||||
|
* @dateTime 2023/3/28 13:07
|
||||||
|
* @param userInfo 用户实体
|
||||||
|
**/
|
||||||
|
public void updateLoginId(UserInfo userInfo) throws Exception {
|
||||||
|
String id = Util.null2DefaultStr(userInfo.getId(),"");
|
||||||
|
String userName = Util.null2DefaultStr(userInfo.getUserName(),"");
|
||||||
|
if(StringUtils.isBlank(id) || StringUtils.isBlank(userName)){
|
||||||
|
throw new CustomerException("create user id or userName can not null!");
|
||||||
|
}
|
||||||
|
if (!consumerMapper.updateHrmLoginIdById(id, userName)) {
|
||||||
|
throw new CustomerException("update loginId sql execute error!");
|
||||||
|
}
|
||||||
|
ResourceComInfo resourceComInfo = new ResourceComInfo();
|
||||||
|
// 清空缓存
|
||||||
|
resourceComInfo.updateResourceInfoCache(id);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public ConsumeConcurrentlyStatus cusPassWordAction(MQMessage message) {
|
||||||
|
return ConsumeConcurrentlyStatus.CONSUME_SUCCESS;
|
||||||
|
}
|
||||||
|
}
|
|
@ -22,12 +22,12 @@ import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* <h1>用户业务方法</h1>
|
* <h1>用户业务方法-废弃</h1>
|
||||||
*
|
*
|
||||||
* @Author xuanran.wang
|
* @Author xuanran.wang
|
||||||
* @Date 2022/12/30 13:04
|
* @Date 2022/12/30 13:04
|
||||||
*/
|
*/
|
||||||
public class UserServiceImpl extends CusInfoActionService {
|
public class UserServiceImplBack extends CusInfoActionService {
|
||||||
private Logger logger = Util.getLogger("mq-consumer-user");
|
private Logger logger = Util.getLogger("mq-consumer-user");
|
||||||
|
|
||||||
{
|
{
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
package weaver.xuanran.wang.shyl_mq.util;//package weaver.xuanran.wang.shyl.mq.util;
|
package weaver.xuanran.wang.shyl_mq.util;
|
||||||
|
|
||||||
import aiyh.utils.Util;
|
import aiyh.utils.Util;
|
||||||
import aiyh.utils.excention.CustomerException;
|
import aiyh.utils.excention.CustomerException;
|
||||||
|
@ -37,15 +37,21 @@ import java.util.*;
|
||||||
*/
|
*/
|
||||||
public class RocketConsumerUtil {
|
public class RocketConsumerUtil {
|
||||||
private static Logger log = Util.getLogger("mq-util");
|
private static Logger log = Util.getLogger("mq-util");
|
||||||
|
|
||||||
|
private static Logger producerLog = Util.getLogger("mq-producer");
|
||||||
private static final ConsumerMapper consumerMapper = Util.getMapper(ConsumerMapper.class);
|
private static final ConsumerMapper consumerMapper = Util.getMapper(ConsumerMapper.class);
|
||||||
private static final ToolUtil tool = new ToolUtil();
|
private static final ToolUtil tool = new ToolUtil();
|
||||||
private static final int ERROR_LOG_ID;
|
private static final int ERROR_LOG_ID;
|
||||||
|
private static final ToolUtil toolUtil = new ToolUtil();
|
||||||
|
|
||||||
static {
|
static {
|
||||||
ERROR_LOG_ID = Util.getIntValue(tool.getSystemParamValue("mqErrorLogModelId"), -1);
|
ERROR_LOG_ID = Util.getIntValue(tool.getSystemParamValue("mqErrorLogModelId"), -1);
|
||||||
if(log == null){
|
if(log == null){
|
||||||
log = Util.getLogger("mq-util");
|
log = Util.getLogger("mq-util");
|
||||||
}
|
}
|
||||||
|
if(producerLog == null){
|
||||||
|
producerLog = Util.getLogger("mq-producer");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -83,7 +89,7 @@ public class RocketConsumerUtil {
|
||||||
CusInfoActionService cusInfoActionService, String configName){
|
CusInfoActionService cusInfoActionService, String configName){
|
||||||
Map<String, Object> configMap = RocketMQFactory.CONFIG_MAPS.get(configName);
|
Map<String, Object> configMap = RocketMQFactory.CONFIG_MAPS.get(configName);
|
||||||
int maxReconsumeTimes = Util.getIntValue(Util.null2String(configMap.get("MaxReconsumeTimes")), RocketMQConstant.DEFAULT_MAX_RECONSUME_TIMES);
|
int maxReconsumeTimes = Util.getIntValue(Util.null2String(configMap.get("MaxReconsumeTimes")), RocketMQConstant.DEFAULT_MAX_RECONSUME_TIMES);
|
||||||
MessageExt messageExt = null;
|
MessageExt messageExt;
|
||||||
String msgBody = "";
|
String msgBody = "";
|
||||||
String mqMessageId = "";
|
String mqMessageId = "";
|
||||||
MQMessage mqMessage = null;
|
MQMessage mqMessage = null;
|
||||||
|
@ -143,7 +149,7 @@ public class RocketConsumerUtil {
|
||||||
mqMessage.setError(e.getMessage());
|
mqMessage.setError(e.getMessage());
|
||||||
List<String> ids = CusInfoToOAUtil.executeBatchByEntity(ERROR_LOG_ID, Collections.singletonList(mqMessage), "");
|
List<String> ids = CusInfoToOAUtil.executeBatchByEntity(ERROR_LOG_ID, Collections.singletonList(mqMessage), "");
|
||||||
if(CollectionUtils.isEmpty(ids)){
|
if(CollectionUtils.isEmpty(ids)){
|
||||||
log.error("insert into mq_error_log failed!");
|
log.error(Util.logStr("messageId : {}, insert into mq_error_log failed!", mqMessageId));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
log.error(Util.logStr("MQ producer error already bigger maxReconsumeTimes! messageId : {}",mqMessageId));
|
log.error(Util.logStr("MQ producer error already bigger maxReconsumeTimes! messageId : {}",mqMessageId));
|
||||||
|
@ -164,6 +170,10 @@ public class RocketConsumerUtil {
|
||||||
* @param requestId 请求id
|
* @param requestId 请求id
|
||||||
**/
|
**/
|
||||||
public static void producerSendMsg(String configName, String msg, String requestId) {
|
public static void producerSendMsg(String configName, String msg, String requestId) {
|
||||||
|
String sendMQ = Util.null2DefaultStr(toolUtil.getSystemParamValue("sendMQ"),"");
|
||||||
|
if(!"1".equals(sendMQ)){
|
||||||
|
return;
|
||||||
|
}
|
||||||
// 先从本地缓存中获取生产者对象
|
// 先从本地缓存中获取生产者对象
|
||||||
DefaultMQProducer producer = RocketMQFactory.getMQProducer(configName);
|
DefaultMQProducer producer = RocketMQFactory.getMQProducer(configName);
|
||||||
// 获取配置信息
|
// 获取配置信息
|
||||||
|
@ -171,9 +181,10 @@ public class RocketConsumerUtil {
|
||||||
// 队列名
|
// 队列名
|
||||||
String topic = Util.null2DefaultStr(configMap.get("Topic"), "");
|
String topic = Util.null2DefaultStr(configMap.get("Topic"), "");
|
||||||
// tag
|
// tag
|
||||||
String tag = Util.null2DefaultStr(configMap.get("Tag"), "");
|
// String tag = Util.null2DefaultStr(configMap.get("Tag"), "");
|
||||||
Message message;
|
Message message;
|
||||||
try {
|
try {
|
||||||
|
producerLog.info(Util.logStr("requestId: {}, msg: {}", requestId, msg));
|
||||||
message = new Message(topic, msg.getBytes(RemotingHelper.DEFAULT_CHARSET));
|
message = new Message(topic, msg.getBytes(RemotingHelper.DEFAULT_CHARSET));
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
throw new CustomerException(Util.logStr("init message error : {} !", e.getMessage()));
|
throw new CustomerException(Util.logStr("init message error : {} !", e.getMessage()));
|
||||||
|
@ -190,12 +201,12 @@ public class RocketConsumerUtil {
|
||||||
} catch (MQClientException | RemotingException | MQBrokerException | InterruptedException e) {
|
} catch (MQClientException | RemotingException | MQBrokerException | InterruptedException e) {
|
||||||
throw new CustomerException(Util.logStr("producer send message error!: {}", e.getMessage()));
|
throw new CustomerException(Util.logStr("producer send message error!: {}", e.getMessage()));
|
||||||
}
|
}
|
||||||
log.info(Util.logStr("requestId: {}, result : {}",requestId, JSONObject.toJSONString(result)));
|
producerLog.info(Util.logStr("requestId: {}, result : {}",requestId, JSONObject.toJSONString(result)));
|
||||||
SendStatus sendStatus = result.getSendStatus();
|
SendStatus sendStatus = result.getSendStatus();
|
||||||
// 如果失败
|
// 如果失败
|
||||||
if (!SendStatus.SEND_OK.equals(sendStatus)) {
|
if (!SendStatus.SEND_OK.equals(sendStatus)) {
|
||||||
String error = Util.logStr("producer send message call back status is not ok! the message is {}, the status is {}.", msg, sendStatus);
|
String error = Util.logStr("producer send message call back status is not ok! the message is {}, the status is {}.", msg, sendStatus);
|
||||||
log.error(error);
|
producerLog.error(error);
|
||||||
// 如果重试超过最大次数
|
// 如果重试超过最大次数
|
||||||
if(count >= RocketMQConstant.SEND_MAX_COUNT){
|
if(count >= RocketMQConstant.SEND_MAX_COUNT){
|
||||||
throw new CustomerException(error + " and retry > max");
|
throw new CustomerException(error + " and retry > max");
|
||||||
|
|
|
@ -0,0 +1,5 @@
|
||||||
|
producerGroup=weaver-car
|
||||||
|
serverAddr=114.115.168.220:9876
|
||||||
|
topic=AUTH_CONSOLE_ORG_TOPIC
|
||||||
|
tag=*
|
||||||
|
consumerGroup=weaver-car-consumer
|
|
@ -0,0 +1,24 @@
|
||||||
|
# ???????
|
||||||
|
corpSecret=5eab6957b4944d75acfa9cfcc8feff5a
|
||||||
|
agentId=10000060
|
||||||
|
corpId=wwdbb6b075752cc1b9
|
||||||
|
# ??token???
|
||||||
|
tokenUrl=http://ramos-develop.shdata.com:11080/uranus/cgi-bin/gettoken
|
||||||
|
# ??????
|
||||||
|
userInfoUrl=http://ramos-develop.shdata.com:11080/uranus/cgi-bin/request/user/get
|
||||||
|
# ??????
|
||||||
|
departmentInfoUrl=http://ramos-develop.shdata.com:11080/uranus/cgi-bin/request/department/list
|
||||||
|
# ??????
|
||||||
|
addTodoTaskUrl=http://ramos-develop.shdata.com:11080/uranus/cgi-bin/request/task/create
|
||||||
|
# ??????
|
||||||
|
updateTodoTaskUrl=http://ramos-develop.shdata.com:11080/uranus/cgi-bin/request/task/update
|
||||||
|
# ?????????appId
|
||||||
|
appId=wwdbb6b075752cc1b9
|
||||||
|
# ????????????ID
|
||||||
|
modelId=112
|
||||||
|
# ???????????sql ????????outkey ??sql?? select outkey from hrmresource where id in (${ids}) ??
|
||||||
|
hrmSenderConvertRuleSql=select lastname from hrmresource where id in (${ids})
|
||||||
|
# ?????
|
||||||
|
hrmReceiveConvertRuleSql=select lastname from hrmresource where id in (${ids})
|
||||||
|
# oa token??????????
|
||||||
|
expiryBeforeTime=5
|
|
@ -0,0 +1,5 @@
|
||||||
|
bootstrap.servers=10.184.42.41:9094,10.184.42.42:9094,10.184.42.40:9094
|
||||||
|
acks=all
|
||||||
|
retries=1
|
||||||
|
key.serializer=org.apache.kafka.common.serialization.StringSerializer
|
||||||
|
value.serializer=org.apache.kafka.common.serialization.StringSerializer
|
|
@ -1,5 +1,9 @@
|
||||||
package xuanran.wang.http_test.annotations;
|
package xuanran.wang.http_test.annotations;
|
||||||
|
|
||||||
|
import aiyh.utils.tool.cn.hutool.core.annotation.AliasFor;
|
||||||
|
import xuanran.wang.http_test.annotations.request_type.CusRequestType;
|
||||||
|
import xuanran.wang.http_test.constant.CusRequestClientConstant;
|
||||||
|
|
||||||
import java.lang.annotation.*;
|
import java.lang.annotation.*;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -11,5 +15,10 @@ import java.lang.annotation.*;
|
||||||
@Retention(RetentionPolicy.RUNTIME)
|
@Retention(RetentionPolicy.RUNTIME)
|
||||||
@Target({ElementType.TYPE})
|
@Target({ElementType.TYPE})
|
||||||
@Documented
|
@Documented
|
||||||
|
@CusRequestAddress()
|
||||||
public @interface CusRequestClient {
|
public @interface CusRequestClient {
|
||||||
|
@AliasFor(annotation = CusRequestAddress.class, attribute = "host")
|
||||||
|
String host() default "";
|
||||||
|
@AliasFor(annotation = CusRequestAddress.class, attribute = "port")
|
||||||
|
int port() default 0;
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,16 @@
|
||||||
|
package xuanran.wang.http_test.annotations;
|
||||||
|
|
||||||
|
import java.lang.annotation.*;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* <h1>请求地址</h1>
|
||||||
|
*
|
||||||
|
* @author xuanran.wang
|
||||||
|
* @date 2023/3/16 19:59
|
||||||
|
*/
|
||||||
|
@Retention(RetentionPolicy.RUNTIME)
|
||||||
|
@Target({ElementType.TYPE, ElementType.METHOD})
|
||||||
|
@Documented
|
||||||
|
public @interface CusRequestUrl {
|
||||||
|
String url();
|
||||||
|
}
|
|
@ -0,0 +1,16 @@
|
||||||
|
package xuanran.wang.http_test.annotations.body;
|
||||||
|
|
||||||
|
import java.lang.annotation.*;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* <h1>请求体</h1>
|
||||||
|
*
|
||||||
|
* @author xuanran.wang
|
||||||
|
* @date 2023/3/20 21:27
|
||||||
|
*/
|
||||||
|
@Retention(RetentionPolicy.RUNTIME)
|
||||||
|
@Target(ElementType.PARAMETER)
|
||||||
|
@Documented
|
||||||
|
public @interface CusRequestBody {
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,16 @@
|
||||||
|
package xuanran.wang.http_test.annotations.handle;
|
||||||
|
|
||||||
|
import java.lang.annotation.*;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* <h1>自定义handle注解</h1>
|
||||||
|
*
|
||||||
|
* @author xuanran.wang
|
||||||
|
* @date 2023/3/16 15:37
|
||||||
|
*/
|
||||||
|
@Retention(RetentionPolicy.RUNTIME)
|
||||||
|
@Target(ElementType.TYPE)
|
||||||
|
@Documented
|
||||||
|
public @interface CusHandle {
|
||||||
|
int order() default 0;
|
||||||
|
}
|
|
@ -0,0 +1,23 @@
|
||||||
|
package xuanran.wang.http_test.annotations.handle;
|
||||||
|
|
||||||
|
import aiyh.utils.tool.cn.hutool.core.annotation.AliasFor;
|
||||||
|
import xuanran.wang.http_test.annotations.CusRequestUrl;
|
||||||
|
import xuanran.wang.http_test.annotations.request_type.CusRequestType;
|
||||||
|
import xuanran.wang.http_test.constant.CusRequestClientConstant;
|
||||||
|
|
||||||
|
import java.lang.annotation.*;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* <h1>请求前置加载</h1>
|
||||||
|
*
|
||||||
|
* @author xuanran.wang
|
||||||
|
* @date 2023/3/20 21:14
|
||||||
|
*/
|
||||||
|
@Retention(RetentionPolicy.RUNTIME)
|
||||||
|
@Target(ElementType.TYPE)
|
||||||
|
@Documented
|
||||||
|
@CusHandle(order = 0)
|
||||||
|
public @interface CusPreLoadHandle {
|
||||||
|
@AliasFor(annotation = CusHandle.class, attribute = "order")
|
||||||
|
int order() default 0;
|
||||||
|
}
|
|
@ -0,0 +1,19 @@
|
||||||
|
package xuanran.wang.http_test.annotations.handle;
|
||||||
|
|
||||||
|
import xuanran.wang.http_test.handle.CusRequestAfterHandle;
|
||||||
|
import xuanran.wang.http_test.test.TestRequestAfterHandle;
|
||||||
|
|
||||||
|
import java.lang.annotation.*;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* <h1></h1>
|
||||||
|
*
|
||||||
|
* @author xuanran.wang
|
||||||
|
* @date 2023/3/24 14:44
|
||||||
|
*/
|
||||||
|
@Retention(RetentionPolicy.RUNTIME)
|
||||||
|
@Target({ElementType.METHOD, ElementType.TYPE})
|
||||||
|
@Documented
|
||||||
|
public @interface CusReqAfterHandleRegister {
|
||||||
|
Class<?> afterHandle();
|
||||||
|
}
|
|
@ -0,0 +1,19 @@
|
||||||
|
package xuanran.wang.http_test.annotations.handle;
|
||||||
|
|
||||||
|
import java.lang.annotation.*;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* <h1>响应体成功失败标识</h1>
|
||||||
|
*
|
||||||
|
* @author xuanran.wang
|
||||||
|
* @date 2023/3/22 11:29
|
||||||
|
*/
|
||||||
|
@Retention(RetentionPolicy.RUNTIME)
|
||||||
|
@Target({ElementType.TYPE, ElementType.METHOD})
|
||||||
|
@Documented
|
||||||
|
public @interface CusResponseSuccessHandle {
|
||||||
|
String successKey();
|
||||||
|
String successCondition();
|
||||||
|
String errorMsg();
|
||||||
|
String data();
|
||||||
|
}
|
|
@ -14,7 +14,7 @@ import java.lang.annotation.*;
|
||||||
* @date 2023/3/14 22:50
|
* @date 2023/3/14 22:50
|
||||||
*/
|
*/
|
||||||
@Retention(RetentionPolicy.RUNTIME)
|
@Retention(RetentionPolicy.RUNTIME)
|
||||||
@Target({ElementType.METHOD})
|
@Target({ElementType.METHOD,ElementType.PARAMETER})
|
||||||
@Documented
|
@Documented
|
||||||
public @interface CusPathQuery {
|
public @interface CusPathQuery {
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -1,5 +1,9 @@
|
||||||
package xuanran.wang.http_test.annotations.request_type;
|
package xuanran.wang.http_test.annotations.request_type;
|
||||||
|
|
||||||
|
import aiyh.utils.tool.cn.hutool.core.annotation.AliasFor;
|
||||||
|
import xuanran.wang.http_test.annotations.CusRequestUrl;
|
||||||
|
import xuanran.wang.http_test.constant.CusRequestClientConstant;
|
||||||
|
|
||||||
import java.lang.annotation.*;
|
import java.lang.annotation.*;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -11,6 +15,12 @@ import java.lang.annotation.*;
|
||||||
@Retention(RetentionPolicy.RUNTIME)
|
@Retention(RetentionPolicy.RUNTIME)
|
||||||
@Target(ElementType.FIELD)
|
@Target(ElementType.FIELD)
|
||||||
@Documented
|
@Documented
|
||||||
|
@CusRequestUrl(url = "")
|
||||||
|
@CusRequestType(requestType = CusRequestClientConstant.DELETE)
|
||||||
public @interface CusRequestDelete {
|
public @interface CusRequestDelete {
|
||||||
String url() default "";
|
@AliasFor(annotation = CusRequestUrl.class, attribute = "url")
|
||||||
|
String url();
|
||||||
|
|
||||||
|
@AliasFor(annotation = CusRequestType.class, attribute = "requestType")
|
||||||
|
int requestType() default CusRequestClientConstant.DELETE;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,9 @@
|
||||||
package xuanran.wang.http_test.annotations.request_type;
|
package xuanran.wang.http_test.annotations.request_type;
|
||||||
|
|
||||||
|
import aiyh.utils.tool.cn.hutool.core.annotation.AliasFor;
|
||||||
|
import xuanran.wang.http_test.annotations.CusRequestUrl;
|
||||||
|
import xuanran.wang.http_test.constant.CusRequestClientConstant;
|
||||||
|
|
||||||
import java.lang.annotation.*;
|
import java.lang.annotation.*;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -9,8 +13,14 @@ import java.lang.annotation.*;
|
||||||
* @date 2023/3/10 10:15
|
* @date 2023/3/10 10:15
|
||||||
*/
|
*/
|
||||||
@Retention(RetentionPolicy.RUNTIME)
|
@Retention(RetentionPolicy.RUNTIME)
|
||||||
@Target({ElementType.METHOD})
|
@Target({ElementType.METHOD, ElementType.TYPE})
|
||||||
@Documented
|
@Documented
|
||||||
|
@CusRequestUrl(url = "")
|
||||||
|
@CusRequestType(requestType = CusRequestClientConstant.GET)
|
||||||
public @interface CusRequestGet{
|
public @interface CusRequestGet{
|
||||||
String url() default "";
|
@AliasFor(annotation = CusRequestUrl.class, attribute = "url")
|
||||||
|
String url();
|
||||||
|
|
||||||
|
@AliasFor(annotation = CusRequestType.class, attribute = "requestType")
|
||||||
|
int requestType() default CusRequestClientConstant.GET;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,9 @@
|
||||||
package xuanran.wang.http_test.annotations.request_type;
|
package xuanran.wang.http_test.annotations.request_type;
|
||||||
|
|
||||||
|
import aiyh.utils.tool.cn.hutool.core.annotation.AliasFor;
|
||||||
|
import xuanran.wang.http_test.annotations.CusRequestUrl;
|
||||||
|
import xuanran.wang.http_test.constant.CusRequestClientConstant;
|
||||||
|
|
||||||
import java.lang.annotation.*;
|
import java.lang.annotation.*;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -11,6 +15,12 @@ import java.lang.annotation.*;
|
||||||
@Retention(RetentionPolicy.RUNTIME)
|
@Retention(RetentionPolicy.RUNTIME)
|
||||||
@Target({ElementType.METHOD})
|
@Target({ElementType.METHOD})
|
||||||
@Documented
|
@Documented
|
||||||
|
@CusRequestUrl(url = "")
|
||||||
|
@CusRequestType(requestType = CusRequestClientConstant.POST)
|
||||||
public @interface CusRequestPost {
|
public @interface CusRequestPost {
|
||||||
String url() default "";
|
@AliasFor(annotation = CusRequestUrl.class, attribute = "url")
|
||||||
|
String url();
|
||||||
|
|
||||||
|
@AliasFor(annotation = CusRequestType.class, attribute = "requestType")
|
||||||
|
int requestType() default CusRequestClientConstant.POST;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,9 @@
|
||||||
package xuanran.wang.http_test.annotations.request_type;
|
package xuanran.wang.http_test.annotations.request_type;
|
||||||
|
|
||||||
|
import aiyh.utils.tool.cn.hutool.core.annotation.AliasFor;
|
||||||
|
import xuanran.wang.http_test.annotations.CusRequestUrl;
|
||||||
|
import xuanran.wang.http_test.constant.CusRequestClientConstant;
|
||||||
|
|
||||||
import java.lang.annotation.*;
|
import java.lang.annotation.*;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -11,6 +15,12 @@ import java.lang.annotation.*;
|
||||||
@Retention(RetentionPolicy.RUNTIME)
|
@Retention(RetentionPolicy.RUNTIME)
|
||||||
@Target({ElementType.METHOD})
|
@Target({ElementType.METHOD})
|
||||||
@Documented
|
@Documented
|
||||||
|
@CusRequestUrl(url = "")
|
||||||
|
@CusRequestType(requestType = CusRequestClientConstant.PUT)
|
||||||
public @interface CusRequestPut {
|
public @interface CusRequestPut {
|
||||||
String url() default "";
|
@AliasFor(annotation = CusRequestUrl.class, attribute = "url")
|
||||||
|
String url();
|
||||||
|
|
||||||
|
@AliasFor(annotation = CusRequestType.class, attribute = "requestType")
|
||||||
|
int requestType() default CusRequestClientConstant.PUT;
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,16 @@
|
||||||
|
package xuanran.wang.http_test.annotations.request_type;
|
||||||
|
|
||||||
|
import java.lang.annotation.*;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* <h1>请求类型</h1>
|
||||||
|
*
|
||||||
|
* @author xuanran.wang
|
||||||
|
* @date 2023/3/16 23:07
|
||||||
|
*/
|
||||||
|
@Retention(RetentionPolicy.RUNTIME)
|
||||||
|
@Target({ElementType.METHOD, ElementType.TYPE})
|
||||||
|
@Documented
|
||||||
|
public @interface CusRequestType {
|
||||||
|
int requestType() default 0;
|
||||||
|
}
|
|
@ -1,5 +1,16 @@
|
||||||
package xuanran.wang.http_test.constant;
|
package xuanran.wang.http_test.constant;
|
||||||
|
|
||||||
|
import aiyh.utils.Util;
|
||||||
|
import aiyh.utils.excention.CustomerException;
|
||||||
|
import com.alibaba.fastjson.JSONObject;
|
||||||
|
import org.apache.commons.lang3.StringUtils;
|
||||||
|
import xuanran.wang.http_test.annotations.handle.CusResponseSuccessHandle;
|
||||||
|
import xuanran.wang.http_test.entity.CusRequestEntity;
|
||||||
|
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.function.Function;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* <h1>请求工具常量</h1>
|
* <h1>请求工具常量</h1>
|
||||||
*
|
*
|
||||||
|
@ -11,5 +22,51 @@ public class CusRequestClientConstant {
|
||||||
public static final int POST = 1;
|
public static final int POST = 1;
|
||||||
public static final int DELETE = 2;
|
public static final int DELETE = 2;
|
||||||
public static final int PUT = 3;
|
public static final int PUT = 3;
|
||||||
public static final int HEADER = -1;
|
public static final int HTTP_SUCCESS_CODE = 200;
|
||||||
|
public static final Map<String, Function<CusRequestEntity, Object>> CONVERT = new HashMap<>();
|
||||||
|
public static final String IS_NOT_NULL = "{ is not null }";
|
||||||
|
public static final String EQUALS = "{ equals }";
|
||||||
|
public static final String EQUALS_IGNORE_CASE = "{ equalsIgnoreCase }";
|
||||||
|
|
||||||
|
static {
|
||||||
|
CONVERT.put(IS_NOT_NULL, cusRequest ->{
|
||||||
|
Map<String, Object> responseMap = cusRequest.getResponseMap();
|
||||||
|
CusResponseSuccessHandle responseSuccessHandle = cusRequest.getResponseSuccessHandle();
|
||||||
|
String key = responseSuccessHandle.successKey();
|
||||||
|
String errorMsg = responseSuccessHandle.errorMsg();
|
||||||
|
String successValue = Util.null2DefaultStr(Util.getValueByKeyStr(key, responseMap),"");
|
||||||
|
if (successValue == null) {
|
||||||
|
throw new CustomerException(Util.logStr("is not null check response error! the error is {}", responseMap.get(errorMsg)));
|
||||||
|
}
|
||||||
|
return JSONObject.toJSONString(responseMap.get(responseSuccessHandle.data()));
|
||||||
|
});
|
||||||
|
|
||||||
|
CONVERT.put(EQUALS, cusRequest ->{
|
||||||
|
Map<String, Object> responseMap = cusRequest.getResponseMap();
|
||||||
|
CusResponseSuccessHandle responseSuccessHandle = cusRequest.getResponseSuccessHandle();
|
||||||
|
String key = responseSuccessHandle.successKey();
|
||||||
|
String successCondition = responseSuccessHandle.successCondition();
|
||||||
|
String errorMsg = responseSuccessHandle.errorMsg();
|
||||||
|
String successValue = Util.null2DefaultStr(Util.getValueByKeyStr(key, responseMap),"");
|
||||||
|
String successConditionValue = successCondition.trim().replace(EQUALS, "").trim();
|
||||||
|
if(!successConditionValue.equals(successValue)){
|
||||||
|
throw new CustomerException(Util.logStr("equals check response error! the error is {}", responseMap.get(errorMsg)));
|
||||||
|
}
|
||||||
|
return JSONObject.toJSONString(responseMap.get(responseSuccessHandle.data()));
|
||||||
|
});
|
||||||
|
|
||||||
|
CONVERT.put(EQUALS_IGNORE_CASE, cusRequest ->{
|
||||||
|
Map<String, Object> responseMap = cusRequest.getResponseMap();
|
||||||
|
CusResponseSuccessHandle responseSuccessHandle = cusRequest.getResponseSuccessHandle();
|
||||||
|
String key = responseSuccessHandle.successKey();
|
||||||
|
String successCondition = responseSuccessHandle.successCondition();
|
||||||
|
String errorMsg = responseSuccessHandle.errorMsg();
|
||||||
|
String successValue = Util.null2DefaultStr(Util.getValueByKeyStr(key, responseMap),"");
|
||||||
|
String successConditionValue = successCondition.trim().replace(EQUALS_IGNORE_CASE, "").trim();
|
||||||
|
if(!successConditionValue.equalsIgnoreCase(Util.null2DefaultStr(successValue,""))){
|
||||||
|
throw new CustomerException(Util.logStr("equalsIgnoreCase check response error! the error is {}", responseMap.get(errorMsg)));
|
||||||
|
}
|
||||||
|
return JSONObject.toJSONString(responseMap.get(responseSuccessHandle.data()));
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,16 @@
|
||||||
|
package xuanran.wang.http_test.entity;
|
||||||
|
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* <h1>自定义handle</h1>
|
||||||
|
*
|
||||||
|
* @author xuanran.wang
|
||||||
|
* @date 2023/3/16 16:07
|
||||||
|
*/
|
||||||
|
@Data
|
||||||
|
public class CusHandleEntity {
|
||||||
|
private Class<?> handleClass;
|
||||||
|
private int order;
|
||||||
|
private String packageName;
|
||||||
|
}
|
|
@ -4,7 +4,10 @@ import lombok.AllArgsConstructor;
|
||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
import lombok.NoArgsConstructor;
|
import lombok.NoArgsConstructor;
|
||||||
import lombok.Setter;
|
import lombok.Setter;
|
||||||
|
import xuanran.wang.http_test.annotations.handle.CusResponseSuccessHandle;
|
||||||
|
import xuanran.wang.http_test.handle.CusRequestAfterHandle;
|
||||||
|
|
||||||
|
import java.util.HashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.function.Consumer;
|
import java.util.function.Consumer;
|
||||||
|
|
||||||
|
@ -19,11 +22,17 @@ import java.util.function.Consumer;
|
||||||
@Setter
|
@Setter
|
||||||
@Getter
|
@Getter
|
||||||
public class CusRequestEntity{
|
public class CusRequestEntity{
|
||||||
private String url;
|
private String url = "";
|
||||||
private Map<String, String> headers;
|
private Map<String, String> headers = new HashMap<>();
|
||||||
private Map<String, String> pathParams;
|
private Map<String, Object> pathParams = new HashMap<>();
|
||||||
private Object bodyParams;
|
private Object bodyParams = new Object();
|
||||||
private int requestType;
|
private int requestType = -1;
|
||||||
private Consumer<Object> consumer;
|
private Consumer<Object> consumer;
|
||||||
private boolean async;
|
private boolean async = false;
|
||||||
|
private String host = "";
|
||||||
|
private int port;
|
||||||
|
private Class<?> returnType;
|
||||||
|
private CusRequestAfterHandle cusRequestAfter;
|
||||||
|
private CusResponseSuccessHandle responseSuccessHandle;
|
||||||
|
private Map<String, Object> responseMap;
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,21 @@
|
||||||
|
package xuanran.wang.http_test.entity;
|
||||||
|
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
|
import lombok.Data;
|
||||||
|
import lombok.NoArgsConstructor;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* <h1>接口响应成功标识对象</h1>
|
||||||
|
*
|
||||||
|
* @author xuanran.wang
|
||||||
|
* @date 2023/3/29 16:58
|
||||||
|
*/
|
||||||
|
@Data
|
||||||
|
@AllArgsConstructor
|
||||||
|
@NoArgsConstructor
|
||||||
|
public class CusResponseSuccess {
|
||||||
|
private String successKey;
|
||||||
|
private String successCondition;
|
||||||
|
private String errorMsg;
|
||||||
|
private String data;
|
||||||
|
}
|
|
@ -0,0 +1,129 @@
|
||||||
|
package xuanran.wang.http_test.handle;
|
||||||
|
|
||||||
|
import aiyh.utils.Util;
|
||||||
|
import aiyh.utils.excention.CustomerException;
|
||||||
|
import aiyh.utils.httpUtil.ResponeVo;
|
||||||
|
import aiyh.utils.tool.cn.hutool.core.annotation.AnnotationUtil;
|
||||||
|
import com.alibaba.fastjson.JSON;
|
||||||
|
import com.alibaba.fastjson.JSONObject;
|
||||||
|
|
||||||
|
import org.apache.log4j.Logger;
|
||||||
|
import xuanran.wang.http_test.annotations.handle.CusReqAfterHandleRegister;
|
||||||
|
import xuanran.wang.http_test.annotations.handle.CusResponseSuccessHandle;
|
||||||
|
import xuanran.wang.http_test.annotations.request_type.CusRequestType;
|
||||||
|
import xuanran.wang.http_test.constant.CusRequestClientConstant;
|
||||||
|
import xuanran.wang.http_test.entity.CusHandleEntity;
|
||||||
|
import xuanran.wang.http_test.entity.CusRequestEntity;
|
||||||
|
import xuanran.wang.http_test.handle.path_handle.CusBodyParseHandle;
|
||||||
|
import xuanran.wang.http_test.handle.request_handle.CusRequestGetHandle;
|
||||||
|
import xuanran.wang.http_test.handle.request_handle.CusRequestPostHandle;
|
||||||
|
import xuanran.wang.http_test.handle.request_handle.CusUrlHandle;
|
||||||
|
import xuanran.wang.http_test.handle.request_handle.CusDefaultRequestAfterHandle;
|
||||||
|
import xuanran.wang.http_test.handle.util.HandleUtil;
|
||||||
|
import xuanran.wang.http_test.proxy.RequestUtil;
|
||||||
|
|
||||||
|
import java.lang.reflect.Method;
|
||||||
|
import java.lang.reflect.Type;
|
||||||
|
import java.util.*;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* <h1>处理器中心对象</h1>
|
||||||
|
*
|
||||||
|
* @author xuanran.wang
|
||||||
|
* @date 2023/3/16 22:38
|
||||||
|
*/
|
||||||
|
public class CusHandleCenter{
|
||||||
|
|
||||||
|
private final Logger log = Util.getLogger();
|
||||||
|
|
||||||
|
private final Queue<CusRequestBeforeHandle> preloadQueue = new LinkedList<>();
|
||||||
|
private final Map<Integer, CusRequestHandle> requestHandle = new HashMap<>();
|
||||||
|
private final CusRequestAfterHandle cusRequestAfterHandle = new CusDefaultRequestAfterHandle();
|
||||||
|
|
||||||
|
{
|
||||||
|
requestHandle.put(CusRequestClientConstant.GET, new CusRequestGetHandle());
|
||||||
|
requestHandle.put(CusRequestClientConstant.POST, new CusRequestPostHandle());
|
||||||
|
preloadQueue.add(new CusUrlHandle());
|
||||||
|
preloadQueue.add(new CusBodyParseHandle());
|
||||||
|
}
|
||||||
|
|
||||||
|
public void requestBeforeHandle(CusRequestEntity cusRequest, Method method, Object[] args){
|
||||||
|
try {
|
||||||
|
log.info("preloadQueue => " + JSONObject.toJSONString(preloadQueue));
|
||||||
|
// 前置加载处理
|
||||||
|
for (CusRequestBeforeHandle handle : preloadQueue) {
|
||||||
|
handle.handle(cusRequest, method, args);
|
||||||
|
}
|
||||||
|
// 扫描执行handle包下面的所有加了CusHandle注解的实现方法并按order进行排序 包的顺序随机
|
||||||
|
HashMap<String, List<CusHandleEntity>> scan = HandleUtil.scanHandle();
|
||||||
|
log.info("scan => " + JSONObject.toJSONString(scan));
|
||||||
|
for (Map.Entry<String, List<CusHandleEntity>> entry : scan.entrySet()) {
|
||||||
|
List<CusHandleEntity> value = entry.getValue();
|
||||||
|
List<CusHandleEntity> collect = value.stream().sorted(Comparator.comparingInt(CusHandleEntity::getOrder)).collect(Collectors.toList());
|
||||||
|
log.info("扫描到的handle : " + JSONObject.toJSONString(collect));
|
||||||
|
for (CusHandleEntity handle : collect) {
|
||||||
|
Class<?> handleClass = handle.getHandleClass();
|
||||||
|
if (CusRequestBeforeHandle.class.isAssignableFrom(handleClass)) {
|
||||||
|
CusRequestBeforeHandle o = (CusRequestBeforeHandle) handleClass.newInstance();
|
||||||
|
o.handle(cusRequest, method, args);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}catch (Exception e){
|
||||||
|
throw new CustomerException("execute requestBeforeHandle error! " + e.getMessage());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public ResponeVo requestHandle(CusRequestEntity cusRequest, Method method){
|
||||||
|
try {
|
||||||
|
CusRequestType requestType = AnnotationUtil.getSynthesizedAnnotation(method, CusRequestType.class);
|
||||||
|
return requestHandle.get(requestType.requestType()).execute(cusRequest);
|
||||||
|
}catch (Exception e){
|
||||||
|
throw new CustomerException("request error! " + e.getMessage());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public Object requestAfterHandle(Method method, CusRequestEntity cusRequest, ResponeVo responseVo){
|
||||||
|
if(cusRequest.getCusRequestAfter() == null){
|
||||||
|
CusReqAfterHandleRegister cusReqAfterHandleRegister = method.getDeclaredAnnotation(CusReqAfterHandleRegister.class);
|
||||||
|
if(cusReqAfterHandleRegister != null){
|
||||||
|
RequestUtil.setCusRequestAfter(cusReqAfterHandleRegister, cusRequest);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// Type genericReturnType = method.getGenericReturnType();
|
||||||
|
cusRequest.setReturnType(method.getReturnType());
|
||||||
|
CusResponseSuccessHandle cusResponseSuccessHandle = method.getDeclaredAnnotation(CusResponseSuccessHandle.class);
|
||||||
|
if(cusResponseSuccessHandle != null && cusRequest.getResponseSuccessHandle() == null){
|
||||||
|
cusRequest.setResponseSuccessHandle(cusResponseSuccessHandle);
|
||||||
|
}
|
||||||
|
return requestAfterHandle(cusRequest, responseVo);
|
||||||
|
}
|
||||||
|
|
||||||
|
private Object requestAfterHandle(CusRequestEntity cusRequest, ResponeVo responseVo){
|
||||||
|
if(responseVo == null){
|
||||||
|
throw new CustomerException("CusRequestAfterHandle responseVo is null!");
|
||||||
|
}
|
||||||
|
int code = responseVo.getCode();
|
||||||
|
if(CusRequestClientConstant.HTTP_SUCCESS_CODE != code){
|
||||||
|
String url = cusRequest.getUrl();
|
||||||
|
log.error(Util.logStr("can not fetch [{}],this request params is [{}]," + // 构建日志字符串
|
||||||
|
"this request heard is [{}],but response status code is [{}]," +
|
||||||
|
"this response is [{}]", cusRequest.getUrl(), JSON.toJSON(cusRequest.getBodyParams()), JSON.toJSONString(cusRequest.getHeaders()), responseVo.getCode(), // 相应状态码
|
||||||
|
responseVo.getEntityString()));
|
||||||
|
throw new CustomerException(Util.logStr("can not fetch [{}]", url)); //
|
||||||
|
}
|
||||||
|
CusRequestAfterHandle handle = cusRequest.getCusRequestAfter() == null ? new CusDefaultRequestAfterHandle() : cusRequest.getCusRequestAfter();
|
||||||
|
cusRequest.setCusRequestAfter(handle);
|
||||||
|
log.info(Util.logStr("cusRequest: {}", JSONObject.toJSONString(cusRequest)));
|
||||||
|
Object res = handle.parseResponse(cusRequest, responseVo);
|
||||||
|
handle.service(cusRequest, responseVo);
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public void registerPreHandle(CusRequestBeforeHandle handle){
|
||||||
|
preloadQueue.add(handle);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,31 @@
|
||||||
|
package xuanran.wang.http_test.handle;
|
||||||
|
|
||||||
|
import aiyh.utils.httpUtil.ResponeVo;
|
||||||
|
import xuanran.wang.http_test.entity.CusRequestEntity;
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* <h1>请求后处理器</h1>
|
||||||
|
*
|
||||||
|
* @author xuanran.wang
|
||||||
|
* @date 2023/3/16 23:57
|
||||||
|
*/
|
||||||
|
public interface CusRequestAfterHandle{
|
||||||
|
/**
|
||||||
|
* <h1>解析响应方法</h1>
|
||||||
|
* @author xuanran.wang
|
||||||
|
* @dateTime 2023/3/24 15:32
|
||||||
|
* @param cusRequest 请求对象
|
||||||
|
* @param responseVo 响应对象
|
||||||
|
**/
|
||||||
|
Object parseResponse(CusRequestEntity cusRequest, ResponeVo responseVo);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* <h1>do something</h1>
|
||||||
|
* @author xuanran.wang
|
||||||
|
* @dateTime 2023/3/24 15:32
|
||||||
|
* @param cusRequest 请求对象
|
||||||
|
* @param responseVo 响应对象
|
||||||
|
**/
|
||||||
|
void service(CusRequestEntity cusRequest, ResponeVo responseVo);
|
||||||
|
}
|
|
@ -10,6 +10,6 @@ import java.lang.reflect.Method;
|
||||||
* @author xuanran.wang
|
* @author xuanran.wang
|
||||||
* @date 2023/3/10 11:38
|
* @date 2023/3/10 11:38
|
||||||
*/
|
*/
|
||||||
public interface RequestBeforeHandle {
|
public interface CusRequestBeforeHandle {
|
||||||
void handle(CusRequestEntity requestEntity, Method method, Object[] args);
|
void handle(CusRequestEntity cusRequest, Method method, Object[] args);
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,42 @@
|
||||||
|
package xuanran.wang.http_test.handle;
|
||||||
|
|
||||||
|
import aiyh.utils.httpUtil.ResponeVo;
|
||||||
|
import aiyh.utils.httpUtil.util.HttpUtils;
|
||||||
|
import xuanran.wang.http_test.entity.CusRequestEntity;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.lang.reflect.Method;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* <h1>请求参数初始化之后请求之前handle</h1>
|
||||||
|
*
|
||||||
|
* @author xuanran.wang
|
||||||
|
* @date 2023/3/16 23:21
|
||||||
|
*/
|
||||||
|
public abstract class CusRequestHandle {
|
||||||
|
protected HttpUtils httpUtils = new HttpUtils();
|
||||||
|
|
||||||
|
protected final ResponeVo execute(CusRequestEntity cusRequest) throws IOException{
|
||||||
|
String host = cusRequest.getHost();
|
||||||
|
int port = cusRequest.getPort();
|
||||||
|
String url = cusRequest.getUrl();
|
||||||
|
StringBuilder realRequestUrl = new StringBuilder();
|
||||||
|
if(url.startsWith("http:") || url.startsWith("https:")){
|
||||||
|
realRequestUrl.append(url);
|
||||||
|
}else {
|
||||||
|
realRequestUrl.append(host);
|
||||||
|
if(!host.endsWith(":")){
|
||||||
|
realRequestUrl.append(":");
|
||||||
|
}
|
||||||
|
realRequestUrl.append(port);
|
||||||
|
if(!url.endsWith("/")){
|
||||||
|
realRequestUrl.append("/");
|
||||||
|
}
|
||||||
|
realRequestUrl.append(url);
|
||||||
|
}
|
||||||
|
cusRequest.setUrl(realRequestUrl.toString());
|
||||||
|
return request(cusRequest);
|
||||||
|
}
|
||||||
|
// 执行具体的请求方法
|
||||||
|
protected abstract ResponeVo request(CusRequestEntity cusRequest) throws IOException;
|
||||||
|
}
|
|
@ -0,0 +1,84 @@
|
||||||
|
package xuanran.wang.http_test.handle.header_handle;
|
||||||
|
import aiyh.utils.Util;
|
||||||
|
import aiyh.utils.excention.CustomerException;
|
||||||
|
import org.apache.commons.collections.MapUtils;
|
||||||
|
import org.apache.commons.lang3.StringUtils;
|
||||||
|
import xuanran.wang.http_test.annotations.handle.CusHandle;
|
||||||
|
import xuanran.wang.http_test.annotations.header.CusRequestHeader;
|
||||||
|
import xuanran.wang.http_test.entity.CusRequestEntity;
|
||||||
|
import xuanran.wang.http_test.handle.CusRequestBeforeHandle;
|
||||||
|
import xuanran.wang.http_test.interfaces.CusCreateRequestHeader;
|
||||||
|
|
||||||
|
import java.lang.reflect.Method;
|
||||||
|
import java.lang.reflect.Parameter;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* <h1>请求头处理</h1>
|
||||||
|
*
|
||||||
|
* @author xuanran.wang
|
||||||
|
* @date 2023/3/10 14:42
|
||||||
|
*/
|
||||||
|
@CusHandle
|
||||||
|
public class RequestHeaderHandle implements CusRequestBeforeHandle {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void handle(CusRequestEntity cusRequest, Method method, Object[] args) {
|
||||||
|
CusRequestHeader methodCusRequestHeader = method.getDeclaredAnnotation(CusRequestHeader.class);
|
||||||
|
if(methodCusRequestHeader == null){
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
// 数组形式
|
||||||
|
String[] headersArr = methodCusRequestHeader.cusHeaders();
|
||||||
|
HashMap<String, String> headers = new HashMap<>();
|
||||||
|
if(headersArr != null){
|
||||||
|
for (String headerStr : headersArr) {
|
||||||
|
String[] split = headerStr.split(":");
|
||||||
|
String key = Util.null2DefaultStr(split[0],"").trim();
|
||||||
|
String val = Util.null2DefaultStr(split[1],"").trim();
|
||||||
|
if(StringUtils.isNotBlank(key) && StringUtils.isNotBlank(val)){
|
||||||
|
headers.put(key, val);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// java代码自定义
|
||||||
|
String path = Util.null2DefaultStr(methodCusRequestHeader.cusHeadersClassPath(),"");
|
||||||
|
if(StringUtils.isNotBlank(path)){
|
||||||
|
Class<?> clazz;
|
||||||
|
try {
|
||||||
|
clazz = Class.forName(path);
|
||||||
|
} catch (ClassNotFoundException e) {
|
||||||
|
throw new CustomerException(Util.logStr("自定义请求头java类文件没找到!: {}", path));
|
||||||
|
}
|
||||||
|
if(!CusCreateRequestHeader.class.isAssignableFrom(clazz)){
|
||||||
|
throw new CustomerException(Util.logStr("当前类路径:[{}] ,未实现CusCreateRequestHeader接口!", path));
|
||||||
|
}
|
||||||
|
CusCreateRequestHeader o;
|
||||||
|
try {
|
||||||
|
o = (CusCreateRequestHeader) clazz.newInstance();
|
||||||
|
}catch (InstantiationException | IllegalAccessException e) {
|
||||||
|
throw new CustomerException(Util.logStr("实例化 [{}] 对象失败! error:{}", path, e.getMessage()));
|
||||||
|
}
|
||||||
|
Map<String, String> cusCreateHeader = o.createHeader();
|
||||||
|
if(MapUtils.isNotEmpty(cusCreateHeader)){
|
||||||
|
headers.putAll(cusCreateHeader);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// 参数中
|
||||||
|
Parameter[] parameters = method.getParameters();
|
||||||
|
for (int i = 0; i < parameters.length; i++) {
|
||||||
|
Parameter parameter = parameters[i];
|
||||||
|
CusRequestHeader requestHeader = parameter.getAnnotation(CusRequestHeader.class);
|
||||||
|
if(requestHeader != null){
|
||||||
|
String val = Util.null2DefaultStr(args[i], "").trim();
|
||||||
|
String key = requestHeader.value().trim();
|
||||||
|
if(StringUtils.isNotBlank(key) && StringUtils.isNotBlank(val)){
|
||||||
|
headers.put(key, val);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
cusRequest.getHeaders().putAll(headers);
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,39 @@
|
||||||
|
package xuanran.wang.http_test.handle.path_handle;
|
||||||
|
|
||||||
|
import aiyh.utils.excention.CustomerException;
|
||||||
|
import aiyh.utils.tool.cn.hutool.core.annotation.AnnotationUtil;
|
||||||
|
import org.springframework.web.bind.annotation.RequestBody;
|
||||||
|
import xuanran.wang.http_test.annotations.CusRequestUrl;
|
||||||
|
import xuanran.wang.http_test.annotations.body.CusRequestBody;
|
||||||
|
import xuanran.wang.http_test.annotations.request_type.CusRequestType;
|
||||||
|
import xuanran.wang.http_test.constant.CusRequestClientConstant;
|
||||||
|
import xuanran.wang.http_test.entity.CusRequestEntity;
|
||||||
|
import xuanran.wang.http_test.handle.CusRequestBeforeHandle;
|
||||||
|
|
||||||
|
import java.lang.annotation.Annotation;
|
||||||
|
import java.lang.reflect.Method;
|
||||||
|
import java.lang.reflect.Parameter;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* <h1>请求体处理</h1>
|
||||||
|
*
|
||||||
|
* @author xuanran.wang
|
||||||
|
* @date 2023/3/20 21:21
|
||||||
|
*/
|
||||||
|
public class CusBodyParseHandle implements CusRequestBeforeHandle {
|
||||||
|
@Override
|
||||||
|
public void handle(CusRequestEntity cusRequest, Method method, Object[] args) {
|
||||||
|
Parameter[] parameters = method.getParameters();
|
||||||
|
for (int i = 0; i < parameters.length; i++) {
|
||||||
|
Parameter parameter = parameters[i];
|
||||||
|
CusRequestBody requestBody = parameter.getDeclaredAnnotation(CusRequestBody.class);
|
||||||
|
CusRequestType requestType = AnnotationUtil.getSynthesizedAnnotation(method, CusRequestType.class);
|
||||||
|
if(null != requestBody &&
|
||||||
|
null != requestType &&
|
||||||
|
requestType.requestType() != CusRequestClientConstant.GET){
|
||||||
|
cusRequest.setBodyParams(args[i]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -2,9 +2,10 @@ package xuanran.wang.http_test.handle.path_handle;
|
||||||
|
|
||||||
import aiyh.utils.Util;
|
import aiyh.utils.Util;
|
||||||
import org.apache.commons.lang3.StringUtils;
|
import org.apache.commons.lang3.StringUtils;
|
||||||
|
import xuanran.wang.http_test.annotations.handle.CusHandle;
|
||||||
import xuanran.wang.http_test.annotations.request_path.CusPathQuery;
|
import xuanran.wang.http_test.annotations.request_path.CusPathQuery;
|
||||||
import xuanran.wang.http_test.entity.CusRequestEntity;
|
import xuanran.wang.http_test.entity.CusRequestEntity;
|
||||||
import xuanran.wang.http_test.handle.RequestBeforeHandle;
|
import xuanran.wang.http_test.handle.CusRequestBeforeHandle;
|
||||||
|
|
||||||
import java.lang.reflect.Method;
|
import java.lang.reflect.Method;
|
||||||
import java.lang.reflect.Parameter;
|
import java.lang.reflect.Parameter;
|
||||||
|
@ -16,11 +17,12 @@ import java.util.Map;
|
||||||
* @author xuanran.wang
|
* @author xuanran.wang
|
||||||
* @date 2023/3/14 23:11
|
* @date 2023/3/14 23:11
|
||||||
*/
|
*/
|
||||||
public class CusFieldKeyParseHandle implements RequestBeforeHandle {
|
@CusHandle
|
||||||
|
public class CusPathParseHandle implements CusRequestBeforeHandle {
|
||||||
@Override
|
@Override
|
||||||
public void handle(CusRequestEntity requestEntity, Method method, Object[] args) {
|
public void handle(CusRequestEntity cusRequest, Method method, Object[] args) {
|
||||||
Parameter[] parameters = method.getParameters();
|
Parameter[] parameters = method.getParameters();
|
||||||
String url = requestEntity.getUrl();
|
String url = cusRequest.getUrl();
|
||||||
for (int i = 0; i < parameters.length; i++) {
|
for (int i = 0; i < parameters.length; i++) {
|
||||||
Parameter parameter = parameters[i];
|
Parameter parameter = parameters[i];
|
||||||
CusPathQuery cusPathQuery = parameter.getDeclaredAnnotation(CusPathQuery.class);
|
CusPathQuery cusPathQuery = parameter.getDeclaredAnnotation(CusPathQuery.class);
|
||||||
|
@ -33,11 +35,11 @@ public class CusFieldKeyParseHandle implements RequestBeforeHandle {
|
||||||
}else {
|
}else {
|
||||||
Class<?> clazz = parameter.getType();
|
Class<?> clazz = parameter.getType();
|
||||||
if(clazz.isAssignableFrom(Map.class)){
|
if(clazz.isAssignableFrom(Map.class)){
|
||||||
requestEntity.getPathParams().putAll((Map<? extends String, ? extends String>) arg);
|
cusRequest.getPathParams().putAll((Map) arg);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
requestEntity.setUrl(url);
|
cusRequest.setUrl(url);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,22 @@
|
||||||
|
package xuanran.wang.http_test.handle.path_handle;
|
||||||
|
|
||||||
|
import xuanran.wang.http_test.annotations.handle.CusHandle;
|
||||||
|
import xuanran.wang.http_test.annotations.handle.CusPreLoadHandle;
|
||||||
|
import xuanran.wang.http_test.entity.CusRequestEntity;
|
||||||
|
import xuanran.wang.http_test.handle.CusRequestBeforeHandle;
|
||||||
|
|
||||||
|
import java.lang.reflect.Method;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* <h1></h1>
|
||||||
|
*
|
||||||
|
* @author xuanran.wang
|
||||||
|
* @date 2023/3/16 16:22
|
||||||
|
*/
|
||||||
|
@CusHandle
|
||||||
|
public class TestHandle implements CusRequestBeforeHandle {
|
||||||
|
@Override
|
||||||
|
public void handle(CusRequestEntity cusRequest, Method method, Object[] args) {
|
||||||
|
System.out.println("TestHandle 111");
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,47 @@
|
||||||
|
package xuanran.wang.http_test.handle.request_handle;
|
||||||
|
|
||||||
|
import aiyh.utils.Util;
|
||||||
|
import aiyh.utils.excention.CustomerException;
|
||||||
|
import aiyh.utils.httpUtil.ResponeVo;
|
||||||
|
import com.alibaba.fastjson.JSONObject;
|
||||||
|
import org.apache.commons.lang3.StringUtils;
|
||||||
|
import xuanran.wang.http_test.annotations.handle.CusResponseSuccessHandle;
|
||||||
|
import xuanran.wang.http_test.constant.CusRequestClientConstant;
|
||||||
|
import xuanran.wang.http_test.entity.CusRequestEntity;
|
||||||
|
import xuanran.wang.http_test.handle.CusRequestAfterHandle;
|
||||||
|
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* <h1>默认的请求后处理响应类</h1>
|
||||||
|
*
|
||||||
|
* @author xuanran.wang
|
||||||
|
* @date 2023/3/17 11:03
|
||||||
|
*/
|
||||||
|
public class CusDefaultRequestAfterHandle implements CusRequestAfterHandle {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Object parseResponse(CusRequestEntity cusRequest, ResponeVo responseVo) {
|
||||||
|
Class<?> returnType = cusRequest.getReturnType();
|
||||||
|
if(ResponeVo.class.isAssignableFrom(returnType)) {
|
||||||
|
return responseVo;
|
||||||
|
}
|
||||||
|
String json = responseVo.getEntityString();
|
||||||
|
cusRequest.setResponseMap(responseVo.getResponseMap());
|
||||||
|
CusResponseSuccessHandle responseSuccessHandle = cusRequest.getResponseSuccessHandle();
|
||||||
|
if(responseSuccessHandle != null){
|
||||||
|
String successCondition = responseSuccessHandle.successCondition();
|
||||||
|
String str = successCondition.substring(0, successCondition.lastIndexOf("}") + 1);
|
||||||
|
json = Util.null2DefaultStr(CusRequestClientConstant.CONVERT
|
||||||
|
.get(str)
|
||||||
|
.apply(cusRequest),"");
|
||||||
|
}
|
||||||
|
return JSONObject.parseObject(json, returnType);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void service(CusRequestEntity cusRequest, ResponeVo responeVo){
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,21 @@
|
||||||
|
package xuanran.wang.http_test.handle.request_handle;
|
||||||
|
|
||||||
|
import aiyh.utils.httpUtil.ResponeVo;
|
||||||
|
import xuanran.wang.http_test.entity.CusRequestEntity;
|
||||||
|
import xuanran.wang.http_test.handle.CusRequestHandle;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* <h1></h1>
|
||||||
|
*
|
||||||
|
* @author xuanran.wang
|
||||||
|
* @date 2023/3/16 23:20
|
||||||
|
*/
|
||||||
|
public class CusRequestGetHandle extends CusRequestHandle {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected ResponeVo request(CusRequestEntity cusRequest) throws IOException {
|
||||||
|
return httpUtils.apiGet(cusRequest.getUrl(), cusRequest.getPathParams(), cusRequest.getHeaders());
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,21 @@
|
||||||
|
package xuanran.wang.http_test.handle.request_handle;
|
||||||
|
|
||||||
|
import aiyh.utils.httpUtil.ResponeVo;
|
||||||
|
import xuanran.wang.http_test.entity.CusRequestEntity;
|
||||||
|
import xuanran.wang.http_test.handle.CusRequestHandle;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* <h1></h1>
|
||||||
|
*
|
||||||
|
* @author xuanran.wang
|
||||||
|
* @date 2023/3/16 23:20
|
||||||
|
*/
|
||||||
|
public class CusRequestPostHandle extends CusRequestHandle {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected ResponeVo request(CusRequestEntity cusRequest) throws IOException {
|
||||||
|
return httpUtils.apiPostObject(cusRequest.getUrl(), cusRequest.getBodyParams(), cusRequest.getHeaders());
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,29 @@
|
||||||
|
package xuanran.wang.http_test.handle.request_handle;
|
||||||
|
|
||||||
|
import aiyh.utils.excention.CustomerException;
|
||||||
|
import aiyh.utils.tool.cn.hutool.core.annotation.AnnotationUtil;
|
||||||
|
import xuanran.wang.http_test.annotations.CusRequestUrl;
|
||||||
|
import xuanran.wang.http_test.annotations.request_type.CusRequestType;
|
||||||
|
import xuanran.wang.http_test.entity.CusRequestEntity;
|
||||||
|
import xuanran.wang.http_test.handle.CusRequestBeforeHandle;
|
||||||
|
|
||||||
|
import java.lang.reflect.Method;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* <h1>方法路径拼接处理</h1>
|
||||||
|
*
|
||||||
|
* @author xuanran.wang
|
||||||
|
* @date 2023/3/16 19:51
|
||||||
|
*/
|
||||||
|
public class CusUrlHandle implements CusRequestBeforeHandle {
|
||||||
|
@Override
|
||||||
|
public void handle(CusRequestEntity cusRequest, Method method, Object[] args) {
|
||||||
|
CusRequestUrl requestUrl = AnnotationUtil.getSynthesizedAnnotation(method, CusRequestUrl.class);
|
||||||
|
if(requestUrl == null){
|
||||||
|
throw new CustomerException("method not found CusRequestUrl!");
|
||||||
|
}
|
||||||
|
cusRequest.setUrl(requestUrl.url());
|
||||||
|
Class<?> returnType = method.getReturnType();
|
||||||
|
cusRequest.setReturnType(returnType);
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,179 @@
|
||||||
|
package xuanran.wang.http_test.handle.util;
|
||||||
|
|
||||||
|
import aiyh.utils.excention.CustomerException;
|
||||||
|
import ebu7common.youhong.ai.bean.Builder;
|
||||||
|
import xuanran.wang.http_test.annotations.handle.CusHandle;
|
||||||
|
import xuanran.wang.http_test.entity.CusHandleEntity;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.net.URL;
|
||||||
|
import java.nio.file.Files;
|
||||||
|
import java.nio.file.Paths;
|
||||||
|
import java.util.*;
|
||||||
|
import java.util.jar.JarEntry;
|
||||||
|
import java.util.jar.JarInputStream;
|
||||||
|
/**
|
||||||
|
* <h1></h1>
|
||||||
|
*
|
||||||
|
* @author xuanran.wang
|
||||||
|
* @date 2023/3/16 15:42
|
||||||
|
*/
|
||||||
|
public class HandleUtil {
|
||||||
|
/**
|
||||||
|
* <h1>扫描指定路径下对class文件</h1>
|
||||||
|
* @author xuanran.wang
|
||||||
|
* @dateTime 2023/3/16 16:02
|
||||||
|
* @return class
|
||||||
|
**/
|
||||||
|
public static HashMap<String,List<CusHandleEntity>> scanHandle() throws ClassNotFoundException{
|
||||||
|
String packageName = HandleUtil.class.getPackage().getName();
|
||||||
|
return scan(packageName.substring(0, packageName.lastIndexOf(".")));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 扫描指定路径下的类文件
|
||||||
|
*
|
||||||
|
* @param packagePath 包路径
|
||||||
|
*/
|
||||||
|
private static HashMap<String, List<CusHandleEntity>> scan(String packagePath) throws ClassNotFoundException {
|
||||||
|
// 转化包路径为文件路径
|
||||||
|
String scanPath = packagePath.replace(".", "/");
|
||||||
|
// 扫描
|
||||||
|
ClassLoader classLoader = HandleUtil.class.getClassLoader();
|
||||||
|
URL resource = classLoader.getResource(scanPath);
|
||||||
|
Set<String> fileNameSet = new LinkedHashSet<>();
|
||||||
|
if (resource == null) {
|
||||||
|
throw new CustomerException("package is not found! :" + packagePath);
|
||||||
|
}
|
||||||
|
String rootPath = getRootPath(resource);
|
||||||
|
if (isJarFile(resource.getFile())) {
|
||||||
|
try {
|
||||||
|
// 是jar包使用JarInputStream
|
||||||
|
JarInputStream jarInputStream = new JarInputStream(Files.newInputStream(Paths.get(rootPath)));
|
||||||
|
JarEntry nextJarEntry = jarInputStream.getNextJarEntry();
|
||||||
|
// 遍历
|
||||||
|
while (null != nextJarEntry) {
|
||||||
|
String name = nextJarEntry.getName();
|
||||||
|
// 如果是指定包名下的文件并且是.class结尾,那就保存它
|
||||||
|
if (name.startsWith(scanPath) && isClassFile(name)) {
|
||||||
|
fileNameSet.add(name.replace(".class", ""));
|
||||||
|
}
|
||||||
|
nextJarEntry = jarInputStream.getNextJarEntry();
|
||||||
|
}
|
||||||
|
} catch (IOException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
// 是文件夹,获取该文件夹下所有文件
|
||||||
|
Set<String> allFilePath = getAllFilePath(rootPath);
|
||||||
|
for (String filePath : allFilePath) {
|
||||||
|
fileNameSet.add(transFilePathToPackagePath(filePath, scanPath));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
HashMap<String, List<CusHandleEntity>> maps = new HashMap<>();
|
||||||
|
for (String fileName : fileNameSet) {
|
||||||
|
String packageName = fileName.substring(0, fileName.lastIndexOf("."));
|
||||||
|
Class<?> scanClass = Class.forName(fileName, false, HandleUtil.class.getClassLoader());
|
||||||
|
CusHandle annotation = scanClass.getAnnotation(CusHandle.class);
|
||||||
|
if(null != annotation){
|
||||||
|
CusHandleEntity cusHandleEntity = Builder.builder(CusHandleEntity::new)
|
||||||
|
.with(CusHandleEntity::setHandleClass, scanClass)
|
||||||
|
.with(CusHandleEntity::setOrder, annotation.order())
|
||||||
|
.with(CusHandleEntity::setPackageName, packageName)
|
||||||
|
.build();
|
||||||
|
List<CusHandleEntity> cusHandleEntities = new ArrayList<>();
|
||||||
|
if(maps.containsKey(packageName)){
|
||||||
|
cusHandleEntities = maps.get(packageName);
|
||||||
|
}
|
||||||
|
cusHandleEntities.add(cusHandleEntity);
|
||||||
|
maps.put(packageName, cusHandleEntities);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return maps;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 遍历获取某个文件下所有文件名称
|
||||||
|
*
|
||||||
|
* @param path path
|
||||||
|
* @return Set<String>
|
||||||
|
*/
|
||||||
|
private static Set<String> getAllFilePath(String path) {
|
||||||
|
Set<String> fileSet = new LinkedHashSet<>();
|
||||||
|
File file = new File(path);
|
||||||
|
return getAllFilePath(fileSet, file);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 递归遍历获取某个文件下所有文件名称
|
||||||
|
*
|
||||||
|
* @param fileSet fileSet
|
||||||
|
* @param file 源文件
|
||||||
|
* @return Set<String>
|
||||||
|
*/
|
||||||
|
private static Set<String> getAllFilePath(Set<String> fileSet, File file) {
|
||||||
|
if (file.isDirectory()) {
|
||||||
|
File[] files = file.listFiles();
|
||||||
|
if (files != null) {
|
||||||
|
for (File file1 : files) {
|
||||||
|
getAllFilePath(fileSet, file1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if (isClassFile(file.getAbsolutePath())) {
|
||||||
|
fileSet.add(file.getAbsolutePath());
|
||||||
|
}
|
||||||
|
return fileSet;
|
||||||
|
}
|
||||||
|
return fileSet;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 把文件路径转为包路径
|
||||||
|
*
|
||||||
|
* @param filePath filePath
|
||||||
|
* @param scanPath 扫描路径
|
||||||
|
* @return String
|
||||||
|
*/
|
||||||
|
private static String transFilePathToPackagePath(String filePath, String scanPath) {
|
||||||
|
filePath = filePath.replace("\\", "/");
|
||||||
|
String substring = filePath.substring(filePath.indexOf(scanPath), filePath.indexOf(".class"));
|
||||||
|
return substring.replace("\\", ".").replace("/", ".");
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 判断一个文件是不是jar包
|
||||||
|
*
|
||||||
|
* @param fileName fileName
|
||||||
|
* @return true-是,false-否
|
||||||
|
*/
|
||||||
|
private static boolean isJarFile(String fileName) {
|
||||||
|
return fileName.contains(".jar!");
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 判断一个文件class文件
|
||||||
|
*
|
||||||
|
* @param fileName fileName
|
||||||
|
* @return true-是,false-否
|
||||||
|
*/
|
||||||
|
private static boolean isClassFile(String fileName) {
|
||||||
|
return fileName.endsWith(".class");
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取文件路径
|
||||||
|
*
|
||||||
|
* @param url url
|
||||||
|
* @return String
|
||||||
|
*/
|
||||||
|
private static String getRootPath(URL url) {
|
||||||
|
String path = url.getFile();
|
||||||
|
if (path.contains("!")) {
|
||||||
|
return path.substring(5, path.indexOf("!"));
|
||||||
|
}
|
||||||
|
return path;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -3,30 +3,21 @@ package xuanran.wang.http_test.proxy;
|
||||||
import aiyh.utils.Util;
|
import aiyh.utils.Util;
|
||||||
import aiyh.utils.excention.CustomerException;
|
import aiyh.utils.excention.CustomerException;
|
||||||
import aiyh.utils.httpUtil.ResponeVo;
|
import aiyh.utils.httpUtil.ResponeVo;
|
||||||
import aiyh.utils.httpUtil.util.HttpUtils;
|
import aiyh.utils.tool.cn.hutool.core.annotation.AnnotationUtil;
|
||||||
import com.alibaba.fastjson.JSON;
|
|
||||||
import com.alibaba.fastjson.JSONObject;
|
import com.alibaba.fastjson.JSONObject;
|
||||||
import org.apache.log4j.Logger;
|
import org.apache.log4j.Logger;
|
||||||
import xuanran.wang.http_test.annotations.*;
|
import xuanran.wang.http_test.annotations.*;
|
||||||
import xuanran.wang.http_test.annotations.async.CusAsync;
|
import xuanran.wang.http_test.annotations.handle.CusReqAfterHandleRegister;
|
||||||
import xuanran.wang.http_test.annotations.request_type.CusRequestDelete;
|
import xuanran.wang.http_test.annotations.handle.CusResponseSuccessHandle;
|
||||||
import xuanran.wang.http_test.annotations.request_type.CusRequestGet;
|
|
||||||
import xuanran.wang.http_test.annotations.request_type.CusRequestPost;
|
|
||||||
import xuanran.wang.http_test.annotations.request_type.CusRequestPut;
|
|
||||||
import xuanran.wang.http_test.constant.RequestUtilConstant;
|
|
||||||
import xuanran.wang.http_test.entity.CusRequestEntity;
|
import xuanran.wang.http_test.entity.CusRequestEntity;
|
||||||
import xuanran.wang.http_test.handle.*;
|
import xuanran.wang.http_test.handle.CusHandleCenter;
|
||||||
import xuanran.wang.http_test.handle.path_handle.CusFieldKeyParseHandle;
|
import xuanran.wang.http_test.handle.CusRequestAfterHandle;
|
||||||
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.lang.annotation.Annotation;
|
import java.lang.annotation.Annotation;
|
||||||
import java.lang.reflect.InvocationHandler;
|
import java.lang.reflect.InvocationHandler;
|
||||||
import java.lang.reflect.Method;
|
import java.lang.reflect.Method;
|
||||||
import java.lang.reflect.Parameter;
|
|
||||||
import java.lang.reflect.Proxy;
|
import java.lang.reflect.Proxy;
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.Map;
|
|
||||||
import java.util.function.Function;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* <h1>声明式发送http请求</h1>
|
* <h1>声明式发送http请求</h1>
|
||||||
|
@ -36,57 +27,59 @@ import java.util.function.Function;
|
||||||
*/
|
*/
|
||||||
public class RequestUtil implements InvocationHandler {
|
public class RequestUtil implements InvocationHandler {
|
||||||
private CusRequestAddress cusRequestAddress = null;
|
private CusRequestAddress cusRequestAddress = null;
|
||||||
private final HttpUtils httpUtils = new HttpUtils();
|
|
||||||
private final Logger log = Util.getLogger();
|
private final Logger log = Util.getLogger();
|
||||||
private boolean async = false;
|
private final CusHandleCenter handleCenter = new CusHandleCenter();
|
||||||
|
private final CusRequestEntity cusRequest = new CusRequestEntity();
|
||||||
public <T> T getRequestClient(Class<?> clazz){
|
public <T> T getRequestClient(Class<?> clazz){
|
||||||
Annotation annotation = clazz.getDeclaredAnnotation(CusRequest.class);
|
Annotation annotation = clazz.getDeclaredAnnotation(CusRequestClient.class);
|
||||||
if(annotation == null){
|
if(annotation == null){
|
||||||
throw new CustomerException("该类未添加CusRequest注解!");
|
throw new CustomerException(Util.logStr(clazz.getName() + " not found CusRequestClient annotation!"));
|
||||||
|
}
|
||||||
|
// 请求后处理
|
||||||
|
CusReqAfterHandleRegister cusReqAfterHandleRegister = clazz.getDeclaredAnnotation(CusReqAfterHandleRegister.class);
|
||||||
|
if(cusReqAfterHandleRegister != null){
|
||||||
|
setCusRequestAfter(cusReqAfterHandleRegister, cusRequest);
|
||||||
|
}
|
||||||
|
// 响应处理
|
||||||
|
CusResponseSuccessHandle cusResponseSuccessHandle = clazz.getDeclaredAnnotation(CusResponseSuccessHandle.class);
|
||||||
|
if(cusResponseSuccessHandle != null){
|
||||||
|
cusRequest.setResponseSuccessHandle(cusResponseSuccessHandle);
|
||||||
}
|
}
|
||||||
cusRequestAddress = clazz.getDeclaredAnnotation(CusRequestAddress.class);
|
cusRequestAddress = clazz.getDeclaredAnnotation(CusRequestAddress.class);
|
||||||
if(null != clazz.getDeclaredAnnotation(CusAsync.class)){
|
cusRequestAddress = AnnotationUtil.getSynthesizedAnnotation(clazz, CusRequestAddress.class);
|
||||||
async = true;
|
// if(null != clazz.getDeclaredAnnotation(CusAsync.class)){
|
||||||
}
|
// async = true;
|
||||||
|
// }
|
||||||
return (T) Proxy.newProxyInstance(clazz.getClassLoader(), new Class[]{clazz}, this);
|
return (T) Proxy.newProxyInstance(clazz.getClassLoader(), new Class[]{clazz}, this);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Object invoke(Object proxy, Method method, Object[] args) {
|
public Object invoke(Object proxy, Method method, Object[] args) {
|
||||||
StringBuilder url = new StringBuilder();
|
|
||||||
CusRequestEntity cusRequest = new CusRequestEntity();
|
|
||||||
if(cusRequestAddress != null){
|
if(cusRequestAddress != null){
|
||||||
String host = Util.null2DefaultStr(cusRequestAddress.host(),"");
|
String host = Util.null2DefaultStr(cusRequestAddress.host(),"");
|
||||||
int port = Util.getIntValue( Util.null2DefaultStr(cusRequestAddress.port(),""),0);
|
int port = Util.getIntValue( Util.null2DefaultStr(cusRequestAddress.port(),""),0);
|
||||||
url.append(host)
|
cusRequest.setHost(host);
|
||||||
.append(":")
|
cusRequest.setPort(port);
|
||||||
.append(port);
|
|
||||||
cusRequest.setUrl(url.toString());
|
|
||||||
}
|
}
|
||||||
CusFieldKeyParseHandle keyParseHandle = new CusFieldKeyParseHandle();
|
handleCenter.requestBeforeHandle(cusRequest, method, args);
|
||||||
keyParseHandle.handle(cusRequest, method, args);
|
log.info("requestHandle : \n" + JSONObject.toJSONString(cusRequest));
|
||||||
log.info("cusRequest : \n" + JSONObject.toJSONString(cusRequest));
|
ResponeVo responeVo = handleCenter.requestHandle(cusRequest, method);
|
||||||
return "";
|
return handleCenter.requestAfterHandle(method, cusRequest, responeVo);
|
||||||
}
|
}
|
||||||
|
|
||||||
private String appendPath(StringBuilder url, String path){
|
public static void setCusRequestAfter(CusReqAfterHandleRegister cusReqAfterHandleRegister,
|
||||||
if(!path.endsWith("/")){
|
CusRequestEntity cusRequest){
|
||||||
url.append("/");
|
if(cusReqAfterHandleRegister != null){
|
||||||
}
|
Class<?> clazz = cusReqAfterHandleRegister.afterHandle();
|
||||||
url.append(path);
|
if (CusRequestAfterHandle.class.isAssignableFrom(clazz)) {
|
||||||
return url.toString();
|
|
||||||
}
|
|
||||||
|
|
||||||
public Object get(String url, Map<String, Object> params, Map<String , String> headers) throws IOException {
|
|
||||||
return httpUtils.apiGet(url, params, headers);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static boolean isJSON(String str) {
|
|
||||||
try {
|
try {
|
||||||
JSON.parse(str);
|
Object cusRequestAfter = clazz.newInstance();
|
||||||
return true;
|
cusRequest.setCusRequestAfter((CusRequestAfterHandle) cusRequestAfter);
|
||||||
} catch (Exception e) {
|
}catch (Exception e){
|
||||||
return false;
|
throw new CustomerException(Util.logStr("class : {}, newInstance error!", e.getMessage()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,11 +1,15 @@
|
||||||
package xuanran.wang.http_test.service;
|
package xuanran.wang.http_test.service;
|
||||||
|
|
||||||
import aiyh.utils.httpUtil.ResponeVo;
|
|
||||||
import xuanran.wang.http_test.annotations.*;
|
import xuanran.wang.http_test.annotations.*;
|
||||||
|
import xuanran.wang.http_test.annotations.body.CusRequestBody;
|
||||||
|
import xuanran.wang.http_test.annotations.handle.CusResponseSuccessHandle;
|
||||||
import xuanran.wang.http_test.annotations.header.CusRequestHeader;
|
import xuanran.wang.http_test.annotations.header.CusRequestHeader;
|
||||||
|
import xuanran.wang.http_test.annotations.request_path.CusPathQuery;
|
||||||
import xuanran.wang.http_test.annotations.request_type.CusRequestGet;
|
import xuanran.wang.http_test.annotations.request_type.CusRequestGet;
|
||||||
import xuanran.wang.http_test.annotations.request_type.CusRequestPost;
|
import xuanran.wang.http_test.annotations.request_type.CusRequestPost;
|
||||||
|
import xuanran.wang.http_test.constant.CusRequestClientConstant;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -14,19 +18,20 @@ import java.util.Map;
|
||||||
* @author xuanran.wang
|
* @author xuanran.wang
|
||||||
* @date 2023/3/10 12:39
|
* @date 2023/3/10 12:39
|
||||||
*/
|
*/
|
||||||
@CusRequest
|
@CusRequestClient(host = "http://114.115.168.220", port = 8191)
|
||||||
@CusRequestAddress(host = "http://114.115.168.220/educate-plat/api/v1/class/getClassList/{test}", port = 8191)
|
//@CusReqAfterHandleRegister(afterHandle = TestRequestAfterHandle.class)
|
||||||
public interface TestService {
|
public interface TestService {
|
||||||
|
|
||||||
|
@CusRequestGet(url = "educate-plat/api/v1/class/getClassList")
|
||||||
@CusRequestGet(url = "educate-plat/api/v1/class/getClassList/{test}")
|
@CusRequestHeader(cusHeaders = {"sa: sasa", "sas:11212","content-Type:application/json"})
|
||||||
@CusRequestHeader(cusHeaders = {"sa: sasa", "sas:11212"})
|
@CusResponseSuccessHandle(
|
||||||
String getStu(Map<String, Object> path,
|
successKey = "code",
|
||||||
@PostBody Map<String, Object> body,
|
successCondition = CusRequestClientConstant.EQUALS + " 0 ",
|
||||||
|
errorMsg = "msg",
|
||||||
|
data = "data"
|
||||||
|
)
|
||||||
|
Map<String, Object> getStu(Map<String, Object> path,
|
||||||
|
@CusRequestBody Map<String, Object> body,
|
||||||
@CusRequestHeader("hsjhdsad") String test,
|
@CusRequestHeader("hsjhdsad") String test,
|
||||||
@CusPathQuery("test") String test1);
|
@CusPathQuery("test") String test1);
|
||||||
|
|
||||||
@CusRequestPost(url = "test/post/sas")
|
|
||||||
@CusRequestHeader(cusHeaders = {"content-Type: application/json"}, cusHeadersClassPath = "java.fsdfds")
|
|
||||||
String getStu(@PostBody Map<String, Object> body);
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,13 +1,18 @@
|
||||||
package xuanran.wang.http_test.test;
|
package xuanran.wang.http_test.test;
|
||||||
|
|
||||||
import aiyh.utils.httpUtil.ResponeVo;
|
|
||||||
import basetest.BaseTest;
|
import basetest.BaseTest;
|
||||||
|
import com.alibaba.fastjson.JSONObject;
|
||||||
|
import com.api.doc.migrate.util.FtpUtil;
|
||||||
|
import com.jcraft.jsch.ChannelSftp;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
import weaver.backup.utils.ZipUtil;
|
||||||
|
import xuanran.wang.http_test.entity.CusHandleEntity;
|
||||||
|
import xuanran.wang.http_test.handle.util.HandleUtil;
|
||||||
import xuanran.wang.http_test.proxy.CusUtil;
|
import xuanran.wang.http_test.proxy.CusUtil;
|
||||||
import xuanran.wang.http_test.proxy.RequestUtil;
|
|
||||||
import xuanran.wang.http_test.service.TestService;
|
import xuanran.wang.http_test.service.TestService;
|
||||||
|
|
||||||
import java.util.HashMap;
|
import java.util.*;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* <h1></h1>
|
* <h1></h1>
|
||||||
|
@ -24,7 +29,6 @@ public class RequestTest extends BaseTest {
|
||||||
map.put("a","1");
|
map.put("a","1");
|
||||||
map.put("b","2");
|
map.put("b","2");
|
||||||
HashMap<String, Object> body = new HashMap<>();
|
HashMap<String, Object> body = new HashMap<>();
|
||||||
|
|
||||||
body.put("a","3");
|
body.put("a","3");
|
||||||
body.put("b","4");
|
body.put("b","4");
|
||||||
|
|
||||||
|
@ -32,10 +36,29 @@ public class RequestTest extends BaseTest {
|
||||||
|
|
||||||
path.put("e","5");
|
path.put("e","5");
|
||||||
path.put("f","6");
|
path.put("f","6");
|
||||||
requestClient.getStu(map, body, "a", "test1111");
|
Map<String, Object> stu = requestClient.getStu(map, body, "a", "test1111");
|
||||||
|
log.info("stu : \n" + JSONObject.toJSONString(stu));
|
||||||
|
|
||||||
|
// String json = "{\"xuanran.wang.http_test.requestBeforeHandle.path_handle\":[{\"handleClass\":\"xuanran.wang.http_test.requestBeforeHandle.path_handle.CusPathParseHandle\",\"order\":0,\"packageName\":\"xuanran.wang.http_test.requestBeforeHandle.path_handle\"},{\"handleClass\":\"xuanran.wang.http_test.requestBeforeHandle.path_handle.TestHandle\",\"order\":99,\"packageName\":\"xuanran.wang.http_test.requestBeforeHandle.path_handle\"}],\"xuanran.wang.http_test.requestBeforeHandle.header_handle\":[{\"handleClass\":\"xuanran.wang.http_test.requestBeforeHandle.header_handle.RequestHeaderHandle\",\"order\":0,\"packageName\":\"xuanran.wang.http_test.requestBeforeHandle.header_handle\"}]}";
|
||||||
|
// System.out.println(JSONObject.parseObject(JSONObject.toJSONString(json), Map.class));
|
||||||
// String stu1 = requestClient.getStu(body);
|
// String stu1 = requestClient.getStu(body);
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testA(){
|
||||||
|
try {
|
||||||
|
HashMap<String, List<CusHandleEntity>> scan = HandleUtil.scanHandle();
|
||||||
|
for (Map.Entry<String, List<CusHandleEntity>> entry : scan.entrySet()) {
|
||||||
|
List<CusHandleEntity> value = entry.getValue();
|
||||||
|
List<CusHandleEntity> collect = value.stream().sorted(Comparator.comparingInt(CusHandleEntity::getOrder)).collect(Collectors.toList());
|
||||||
|
log.info("collect : " + JSONObject.toJSONString(collect));
|
||||||
|
}
|
||||||
|
log.info("scan => " + JSONObject.toJSONString(scan));
|
||||||
|
}catch (Exception e){
|
||||||
|
log.info("erro => " + e.getMessage());
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,20 @@
|
||||||
|
package xuanran.wang.http_test.test;
|
||||||
|
|
||||||
|
import aiyh.utils.httpUtil.ResponeVo;
|
||||||
|
import xuanran.wang.http_test.entity.CusRequestEntity;
|
||||||
|
import xuanran.wang.http_test.handle.request_handle.CusDefaultRequestAfterHandle;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* <h1></h1>
|
||||||
|
*
|
||||||
|
* @author xuanran.wang
|
||||||
|
* @date 2023/3/20 14:48
|
||||||
|
*/
|
||||||
|
public class TestRequestAfterHandle extends CusDefaultRequestAfterHandle {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void service(CusRequestEntity cusRequest, ResponeVo responseVo) {
|
||||||
|
System.out.println("============== ceshi xia ===============");
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
File diff suppressed because one or more lines are too long
|
@ -0,0 +1,17 @@
|
||||||
|
package xuanran.wang.mq;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* <h1></h1>
|
||||||
|
*
|
||||||
|
* @author xuanran.wang
|
||||||
|
* @date 2023/4/3 15:13
|
||||||
|
*/
|
||||||
|
public enum CusMQType {
|
||||||
|
ROCKET_MQ("RocketMQ",0),
|
||||||
|
KAFKA("Kafka",1),
|
||||||
|
RABBIT_MQ("RabbitMQ",2),
|
||||||
|
ACTIVE_MQ("ActiveMQ",3);
|
||||||
|
|
||||||
|
CusMQType(String type, int code) {
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,21 @@
|
||||||
|
package xuanran.wang.mq.consumer;
|
||||||
|
|
||||||
|
import com.weaverboot.frame.ioc.anno.classAnno.WeaSysInitComponent;
|
||||||
|
import xuanran.wang.mq.infaces.CusMQClient;
|
||||||
|
import xuanran.wang.mq.infaces.callback.CusMQCallBack;
|
||||||
|
import xuanran.wang.mq.mq.CusMQFactory;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* <h1></h1>
|
||||||
|
*
|
||||||
|
* @author xuanran.wang
|
||||||
|
* @date 2023/4/3 15:04
|
||||||
|
*/
|
||||||
|
@WeaSysInitComponent("MQ-消费者")
|
||||||
|
public class DefaultConsumer {
|
||||||
|
|
||||||
|
public static void registerConsumer(String configName, String type, CusMQCallBack callBack){
|
||||||
|
CusMQClient cusMQ = CusMQFactory.createCusMQ(configName, type);
|
||||||
|
cusMQ.consumer(callBack);
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,27 @@
|
||||||
|
package xuanran.wang.mq.infaces;
|
||||||
|
|
||||||
|
import aiyh.utils.Util;
|
||||||
|
import org.apache.log4j.Logger;
|
||||||
|
import xuanran.wang.mq.infaces.aop.CusMQAop;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* <h1>mq基础类</h1>
|
||||||
|
*
|
||||||
|
* @author xuanran.wang
|
||||||
|
* @date 2023/3/31 11:47
|
||||||
|
*/
|
||||||
|
public interface CusBaseMQ {
|
||||||
|
Logger log = Util.getLogger();
|
||||||
|
/**
|
||||||
|
* <h2>初始化生产者</h2>
|
||||||
|
**/
|
||||||
|
void initProducer(String configName);
|
||||||
|
/**
|
||||||
|
* <h2>初始化消费者</h2>
|
||||||
|
**/
|
||||||
|
void initConsumer(String configName);
|
||||||
|
/**
|
||||||
|
* <h2>销毁</h2>
|
||||||
|
**/
|
||||||
|
void destroy();
|
||||||
|
}
|
|
@ -0,0 +1,16 @@
|
||||||
|
package xuanran.wang.mq.infaces;
|
||||||
|
|
||||||
|
import xuanran.wang.mq.infaces.callback.CusMQCallBack;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* <h1>消费者</h1>
|
||||||
|
*
|
||||||
|
* @author xuanran.wang
|
||||||
|
* @date 2023/3/31 11:56
|
||||||
|
*/
|
||||||
|
public interface CusConsumer extends CusBaseMQ{
|
||||||
|
/**
|
||||||
|
* <h2>消费</h2>
|
||||||
|
**/
|
||||||
|
void consumer(CusMQCallBack callBack);
|
||||||
|
}
|
|
@ -0,0 +1,11 @@
|
||||||
|
package xuanran.wang.mq.infaces;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* <h1>客户端</h1>
|
||||||
|
*
|
||||||
|
* @author xuanran.wang
|
||||||
|
* @date 2023/3/31 13:09
|
||||||
|
*/
|
||||||
|
public interface CusMQClient extends CusProducer, CusConsumer {
|
||||||
|
}
|
||||||
|
|
|
@ -0,0 +1,16 @@
|
||||||
|
package xuanran.wang.mq.infaces;
|
||||||
|
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* <h1>生产者方法</h1>
|
||||||
|
*
|
||||||
|
* @author xuanran.wang
|
||||||
|
* @date 2023/3/30 11:37
|
||||||
|
*/
|
||||||
|
public interface CusProducer extends CusBaseMQ{
|
||||||
|
/**
|
||||||
|
* <h2>生产者</h2>
|
||||||
|
**/
|
||||||
|
void send(Object message);
|
||||||
|
}
|
|
@ -0,0 +1,18 @@
|
||||||
|
package xuanran.wang.mq.infaces.aop;
|
||||||
|
|
||||||
|
import aiyh.utils.tool.cn.hutool.core.collection.CollUtil;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* <h1>切面</h1>
|
||||||
|
*
|
||||||
|
* @author xuanran.wang
|
||||||
|
* @date 2023/3/31 12:52
|
||||||
|
*/
|
||||||
|
public interface CusMQAop {
|
||||||
|
void sendBefore();
|
||||||
|
void sendAfter();
|
||||||
|
void consumerBefore();
|
||||||
|
void consumerAfter();
|
||||||
|
void destroyBefore();
|
||||||
|
void destroyAfter();
|
||||||
|
}
|
|
@ -0,0 +1,35 @@
|
||||||
|
package xuanran.wang.mq.infaces.callback;
|
||||||
|
|
||||||
|
import org.apache.kafka.clients.consumer.ConsumerRecords;
|
||||||
|
import org.apache.rocketmq.client.consumer.listener.ConsumeConcurrentlyContext;
|
||||||
|
import org.apache.rocketmq.client.consumer.listener.ConsumeConcurrentlyStatus;
|
||||||
|
import org.apache.rocketmq.client.consumer.listener.MessageListenerConcurrently;
|
||||||
|
import org.apache.rocketmq.common.message.MessageExt;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* <h1>回调</h1>
|
||||||
|
*
|
||||||
|
* @author xuanran.wang
|
||||||
|
* @date 2023/3/31 13:13
|
||||||
|
*/
|
||||||
|
public interface CusMQCallBack {
|
||||||
|
/**
|
||||||
|
* <h1>kafka 回调</h1>
|
||||||
|
* @author xuanran.wang
|
||||||
|
* @dateTime 2023/4/3 14:55
|
||||||
|
* @param records 消息对象
|
||||||
|
**/
|
||||||
|
void kafkaCallBack(ConsumerRecords<String, String> records);
|
||||||
|
/**
|
||||||
|
* <h1>rocket-MQ 回调</h1>
|
||||||
|
* @author xuanran.wang
|
||||||
|
* @dateTime 2023/4/3 14:55
|
||||||
|
* @param msgList 消息列表
|
||||||
|
* @param context 上下文
|
||||||
|
* @return 状态
|
||||||
|
**/
|
||||||
|
ConsumeConcurrentlyStatus rocketCallBack(List<MessageExt> msgList, ConsumeConcurrentlyContext context);
|
||||||
|
}
|
|
@ -0,0 +1,86 @@
|
||||||
|
package xuanran.wang.mq.mq;
|
||||||
|
|
||||||
|
import aiyh.utils.Util;
|
||||||
|
import aiyh.utils.excention.CustomerException;
|
||||||
|
import com.alibaba.fastjson.JSONObject;
|
||||||
|
import lombok.NoArgsConstructor;
|
||||||
|
import org.apache.kafka.clients.consumer.ConsumerRecords;
|
||||||
|
import org.apache.kafka.clients.consumer.KafkaConsumer;
|
||||||
|
import org.apache.kafka.clients.producer.KafkaProducer;
|
||||||
|
import org.apache.kafka.clients.producer.ProducerRecord;
|
||||||
|
import xuanran.wang.mq.infaces.*;
|
||||||
|
import xuanran.wang.mq.infaces.aop.CusMQAop;
|
||||||
|
import xuanran.wang.mq.infaces.callback.CusMQCallBack;
|
||||||
|
import xuanran.wang.mq.util.CusMQUtil;
|
||||||
|
|
||||||
|
import java.time.Duration;
|
||||||
|
import java.time.temporal.ChronoUnit;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* <h1>kafka</h1>
|
||||||
|
*
|
||||||
|
* @author xuanran.wang
|
||||||
|
* @date 2023/3/30 11:44
|
||||||
|
*/
|
||||||
|
@NoArgsConstructor
|
||||||
|
public class CusKafkaMQ implements CusMQClient {
|
||||||
|
private KafkaProducer<String, String> producer = null;
|
||||||
|
private KafkaConsumer<String, String> consumer = null;
|
||||||
|
private Map<String, Object> config = null;
|
||||||
|
private CusMQAop cusMQAop = new DefaultCusMQAop();
|
||||||
|
public CusKafkaMQ(CusMQAop cusMQAop){
|
||||||
|
this.cusMQAop = cusMQAop;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void initProducer(String configName) {
|
||||||
|
config = CusMQUtil.getConfigMapByName(configName);
|
||||||
|
producer = new KafkaProducer<>(config);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void initConsumer(String configName) {
|
||||||
|
config = CusMQUtil.getConfigMapByName(configName);
|
||||||
|
consumer = new KafkaConsumer<>(config);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void send(Object message) {
|
||||||
|
String topic = Util.null2DefaultStr(config.get("topic"),"");
|
||||||
|
try {
|
||||||
|
producer.send(new ProducerRecord<>(topic, JSONObject.toJSONString(message))).get();
|
||||||
|
}catch (Exception e){
|
||||||
|
log.error(Util.logStr("kafka producer topic: {}, message: {}, error: {}", topic, JSONObject.toJSONString(message), e.getMessage()));
|
||||||
|
throw new CustomerException("kafka producer send message error!");
|
||||||
|
}finally {
|
||||||
|
this.destroy();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void consumer(CusMQCallBack callBack) {
|
||||||
|
new Thread(() -> {
|
||||||
|
try {
|
||||||
|
while (true) {
|
||||||
|
/*轮询获取数据*/
|
||||||
|
ConsumerRecords<String, String> records = consumer.poll(Duration.of(100, ChronoUnit.MILLIS));
|
||||||
|
callBack.kafkaCallBack(records);
|
||||||
|
}
|
||||||
|
} finally {
|
||||||
|
consumer.close();
|
||||||
|
}
|
||||||
|
}).start();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void destroy() {
|
||||||
|
if(producer != null){
|
||||||
|
producer.close();
|
||||||
|
}
|
||||||
|
if(consumer != null){
|
||||||
|
consumer.close();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,45 @@
|
||||||
|
package xuanran.wang.mq.mq;
|
||||||
|
|
||||||
|
import aiyh.utils.Util;
|
||||||
|
import aiyh.utils.excention.CustomerException;
|
||||||
|
import xuanran.wang.mq.infaces.CusMQClient;
|
||||||
|
import xuanran.wang.mq.infaces.aop.CusMQAop;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* <h1>工厂</h1>
|
||||||
|
*
|
||||||
|
* @author xuanran.wang
|
||||||
|
* @date 2023/3/30 11:38
|
||||||
|
*/
|
||||||
|
public class CusMQFactory {
|
||||||
|
|
||||||
|
public static final String ROCKET_MQ = "0";
|
||||||
|
|
||||||
|
public static final String KAFKA = "1";
|
||||||
|
|
||||||
|
public static final String RABBIT_MQ = "2";
|
||||||
|
|
||||||
|
public static final String ACTIVE_MQ = "3";
|
||||||
|
|
||||||
|
public static CusMQClient createCusMQ(String configName, String type) {
|
||||||
|
return createCusMQ(configName, type, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static CusMQClient createCusMQ(String configName, String type, CusMQAop cusMQAop){
|
||||||
|
CusMQClient cusAbstractMQ;
|
||||||
|
switch (type){
|
||||||
|
case ROCKET_MQ: {
|
||||||
|
cusAbstractMQ = new CusRocketMQ();
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case KAFKA: {
|
||||||
|
cusAbstractMQ = new CusKafkaMQ();
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
default: throw new CustomerException(Util.logStr("create CusMQClient error! type: {}, not support!", type));
|
||||||
|
}
|
||||||
|
cusAbstractMQ.initConsumer(configName);
|
||||||
|
cusAbstractMQ.initProducer(configName);
|
||||||
|
return cusAbstractMQ;
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,146 @@
|
||||||
|
package xuanran.wang.mq.mq;
|
||||||
|
|
||||||
|
import aiyh.utils.Util;
|
||||||
|
import aiyh.utils.excention.CustomerException;
|
||||||
|
import com.alibaba.fastjson.JSONObject;
|
||||||
|
import lombok.NoArgsConstructor;
|
||||||
|
import org.apache.rocketmq.client.consumer.DefaultMQPushConsumer;
|
||||||
|
import org.apache.rocketmq.client.exception.MQBrokerException;
|
||||||
|
import org.apache.rocketmq.client.exception.MQClientException;
|
||||||
|
import org.apache.rocketmq.client.producer.DefaultMQProducer;
|
||||||
|
import org.apache.rocketmq.client.producer.SendResult;
|
||||||
|
import org.apache.rocketmq.client.producer.SendStatus;
|
||||||
|
import org.apache.rocketmq.common.consumer.ConsumeFromWhere;
|
||||||
|
import org.apache.rocketmq.common.message.Message;
|
||||||
|
import org.apache.rocketmq.common.protocol.heartbeat.MessageModel;
|
||||||
|
import org.apache.rocketmq.remoting.common.RemotingHelper;
|
||||||
|
import org.apache.rocketmq.remoting.exception.RemotingException;
|
||||||
|
import weaver.xuanran.wang.shyl_mq.constant.RocketMQConstant;
|
||||||
|
import xuanran.wang.mq.infaces.CusMQClient;
|
||||||
|
import xuanran.wang.mq.infaces.aop.CusMQAop;
|
||||||
|
import xuanran.wang.mq.infaces.callback.CusMQCallBack;
|
||||||
|
import xuanran.wang.mq.util.CusMQUtil;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* <h1>自定义rocket-mq</h1>
|
||||||
|
*
|
||||||
|
* @author xuanran.wang
|
||||||
|
* @date 2023/3/31 13:02
|
||||||
|
*/
|
||||||
|
@NoArgsConstructor
|
||||||
|
public class CusRocketMQ implements CusMQClient {
|
||||||
|
private DefaultMQProducer producer = null;
|
||||||
|
|
||||||
|
private DefaultMQPushConsumer consumer = null;
|
||||||
|
|
||||||
|
private Map<String, Object> config = null;
|
||||||
|
private CusMQAop cusMQAop = new DefaultCusMQAop();
|
||||||
|
|
||||||
|
public CusRocketMQ(CusMQAop cusMQAop){
|
||||||
|
this.cusMQAop = cusMQAop;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void initProducer(String configName) {
|
||||||
|
Map<String, Object> configMap = CusMQUtil.getConfigMapByName(configName);
|
||||||
|
this.config = configMap;
|
||||||
|
producer = new DefaultMQProducer(Util.null2DefaultStr(configMap.get("producerGroup"),""));
|
||||||
|
// 发送消息最大超时时间 默认60000
|
||||||
|
int sendMsgTimeOut = Util.getIntValue(Util.null2String(configMap.get("sendMsgTimeOut")), RocketMQConstant.PRODUCER_SEND_MSG_TIME_OUT);
|
||||||
|
producer.setSendMsgTimeout(sendMsgTimeOut);
|
||||||
|
producer.setVipChannelEnabled(false);
|
||||||
|
producer.setNamesrvAddr(Util.null2String(configMap.get("serverAddr")));
|
||||||
|
try {
|
||||||
|
producer.start();
|
||||||
|
}catch (MQClientException e){
|
||||||
|
throw new CustomerException(Util.logStr("producer start error!:{}",e.getMessage()));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void initConsumer(String configName) {
|
||||||
|
Map<String, Object> configMap = CusMQUtil.getConfigMapByName(configName);
|
||||||
|
this.config = configMap;
|
||||||
|
try {
|
||||||
|
int maxReconsumeTimes = Util.getIntValue(Util.null2String(configMap.get("maxReconsumeTimes")), RocketMQConstant.DEFAULT_MAX_RECONSUME_TIMES);
|
||||||
|
// 声明一个消费者consumer,需要传入一个组 weaver-consumer
|
||||||
|
consumer = new DefaultMQPushConsumer(Util.null2String(configMap.get("consumerGroup")));
|
||||||
|
// 设置集群的NameServer地址,多个地址之间以分号分隔 183.192.65.118:9876
|
||||||
|
consumer.setNamesrvAddr(Util.null2String(configMap.get("serverAddr")));
|
||||||
|
// 设置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")),"*");
|
||||||
|
// 是否开启vip
|
||||||
|
consumer.setVipChannelEnabled(false);
|
||||||
|
}catch (Exception e){
|
||||||
|
throw new CustomerException(Util.logStr("init rocket MQ consumer error: {}!",e.getMessage()));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void destroy() {
|
||||||
|
if(producer != null){
|
||||||
|
producer.shutdown();
|
||||||
|
}
|
||||||
|
if(consumer != null){
|
||||||
|
consumer.shutdown();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void send(Object message) {
|
||||||
|
cusMQAop.sendBefore();
|
||||||
|
// 队列名
|
||||||
|
String topic = Util.null2DefaultStr(config.get("topic"), "");
|
||||||
|
Message msg;
|
||||||
|
try {
|
||||||
|
msg = new Message(topic, JSONObject.toJSONString(message).getBytes(RemotingHelper.DEFAULT_CHARSET));
|
||||||
|
} catch (Exception e) {
|
||||||
|
throw new CustomerException(Util.logStr("init message error : {} !", e.getMessage()));
|
||||||
|
}
|
||||||
|
// 发送成功标识
|
||||||
|
boolean sendOk = false;
|
||||||
|
// 发送次数
|
||||||
|
int count = 0;
|
||||||
|
do {
|
||||||
|
SendResult result;
|
||||||
|
count++;
|
||||||
|
try {
|
||||||
|
result = producer.send(msg);
|
||||||
|
} catch (MQClientException | RemotingException | MQBrokerException | InterruptedException e) {
|
||||||
|
throw new CustomerException(Util.logStr("producer send message error!: {}", e.getMessage()));
|
||||||
|
}
|
||||||
|
SendStatus sendStatus = result.getSendStatus();
|
||||||
|
// 如果失败
|
||||||
|
if (!SendStatus.SEND_OK.equals(sendStatus)) {
|
||||||
|
String error = Util.logStr("producer send message call back status is not ok! the message is {}, the status is {}.", msg, sendStatus);
|
||||||
|
// 如果重试超过最大次数
|
||||||
|
if(count >= RocketMQConstant.SEND_MAX_COUNT){
|
||||||
|
throw new CustomerException(error + " and retry > max");
|
||||||
|
}
|
||||||
|
}else {
|
||||||
|
sendOk = true;
|
||||||
|
}
|
||||||
|
} while (!sendOk);
|
||||||
|
cusMQAop.sendAfter();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void consumer(CusMQCallBack callBack) {
|
||||||
|
consumer.registerMessageListener(callBack::rocketCallBack);
|
||||||
|
try {
|
||||||
|
consumer.start();
|
||||||
|
}catch (Exception e){
|
||||||
|
throw new CustomerException("consumer start error : " + e.getMessage());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue