Revert "预警配置,预警接口,定时插件推送消息,消息模版配置,推送消息日志"

This reverts commit 37b66cee8b.
This commit is contained in:
username 2024-09-07 16:07:53 +08:00
parent 37b66cee8b
commit 24ab9a9dc1
8 changed files with 177 additions and 104 deletions

View File

@ -28,7 +28,7 @@ import java.util.stream.Stream;
* @Author xiangerlin
* @Date 2024/8/28 14:25
**/
@Service(value = "dingTalkExtService")
@Service
public class DingTalkExtServiceImpl implements IDingTalkExtService {

View File

@ -6,9 +6,9 @@ public class SysPushMessageEntity extends BaseEntity {
/** 推送方式 “一次”、“定时” */
private String pushMethod;
/** 预警应用编码 */
private Long warningAppCode;
private String warningAppCode;
/** 预警接口编码 */
private Long warningApiCode;
private String warningApiCode;
/** 接收者ID列表*/
private String recipientIdList;
/** 预警应用类型 */
@ -22,7 +22,7 @@ public class SysPushMessageEntity extends BaseEntity {
/** 返回信息 */
private String returnData;
/** 接收接口编码 */
private Long receiveApiCode;
private String receiveApiCode;
/** 状态1、待发送2、发送中3、发送成功4、发送失败 */
private String status;
@ -34,31 +34,22 @@ public class SysPushMessageEntity extends BaseEntity {
this.pushMethod = pushMethod;
}
public Long getWarningAppCode() {
public String getWarningAppCode() {
return warningAppCode;
}
public void setWarningAppCode(Long warningAppCode) {
public void setWarningAppCode(String warningAppCode) {
this.warningAppCode = warningAppCode;
}
public Long getWarningApiCode() {
public String getWarningApiCode() {
return warningApiCode;
}
public void setWarningApiCode(Long warningApiCode) {
public void setWarningApiCode(String warningApiCode) {
this.warningApiCode = warningApiCode;
}
public Long getReceiveApiCode() {
return receiveApiCode;
}
public void setReceiveApiCode(Long receiveApiCode) {
this.receiveApiCode = receiveApiCode;
}
public String getRecipientIdList() {
return recipientIdList;
}
@ -107,6 +98,14 @@ public class SysPushMessageEntity extends BaseEntity {
this.returnData = returnData;
}
public String getReceiveApiCode() {
return receiveApiCode;
}
public void setReceiveApiCode(String receiveApiCode) {
this.receiveApiCode = receiveApiCode;
}
public String getStatus() {
return status;
}

View File

@ -4,14 +4,14 @@
<resultMap id="get-SysPushMessageEntity-result" type="com.hzya.frame.sysnew.pushMessage.entity.SysPushMessageEntity" >
<result property="pushMethod" column="push_method" jdbcType="VARCHAR"/>
<result property="warningAppCode" column="warning_app_code" jdbcType="INTEGER"/>
<result property="warningApiCode" column="warning_api_code" jdbcType="INTEGER"/>
<result property="warningAppCode" column="warning_app_code" jdbcType="VARCHAR"/>
<result property="warningApiCode" column="warning_api_code" jdbcType="VARCHAR"/>
<result property="warningAppType" column="warning_app_type" jdbcType="VARCHAR"/>
<result property="recipientIdList" column="recipient_id_list" jdbcType="VARCHAR"/>
<result property="sendAppName" column="send_app_name" jdbcType="VARCHAR"/>
<result property="receiveAppName" column="receive_app_name" jdbcType="VARCHAR"/>
<result property="receiveApiName" column="receive_api_name" jdbcType="VARCHAR"/>
<result property="receiveApiCode" column="receive_api_code" jdbcType="INTEGER"/>
<result property="receiveApiCode" column="receive_api_code" jdbcType="VARCHAR"/>
<result property="returnData" column="return_data" jdbcType="LONGVARCHAR"/>
<result property="status" column="status" jdbcType="VARCHAR"/>
</resultMap>

View File

@ -2,12 +2,9 @@ package com.hzya.frame.sysnew.sendMessageLog.service.impl;
import cn.dev33.satoken.stp.StpUtil;
import cn.hutool.http.HttpRequest;
import cn.hutool.json.JSONUtil;
import com.alibaba.fastjson.JSONObject;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.hzya.frame.sysnew.application.api.dao.ISysApplicationApiDao;
import com.hzya.frame.sysnew.application.api.entity.SysApplicationApiEntity;
import com.hzya.frame.sysnew.application.apiPara.dao.ISysApplicationApiParaDao;
import com.hzya.frame.sysnew.application.apiPara.entity.SysApplicationApiParaEntity;
import com.hzya.frame.sysnew.messageTemplate.dao.ISysMessageTemplateDao;
@ -52,8 +49,6 @@ public class SysSendMessageLogServiceImpl extends BaseService<SysSendMessageLogE
@Resource
private ISysUserDao sysUserDao;
@Resource
private ISysApplicationApiDao sysApplicationApiDao;
@Resource
private ISysApplicationApiParaDao sysApplicationApiParaDao;
private ISysSendMessageLogDao sysSendMessageLogDao;
@ -147,6 +142,144 @@ public class SysSendMessageLogServiceImpl extends BaseService<SysSendMessageLogE
return BaseResult.getSuccessMessageEntity("删除发送消息日志成功", entity);
}
// public JsonResultEntity sendMsg(JSONObject jsonObject){
// //拼接一条测试消息数据
// jsonObject.put("log_id","e2f213567c2242eab7401edcb3949c45");
// jsonObject.put("send_app_name","数智中台");
// jsonObject.put("recieve_app_name","东进U8C");
// jsonObject.put("recieve_api_name","存货基本档案修改");
// jsonObject.put("receive_api_code","8000350046");
// jsonObject.put("return_data","{\n" +
// " \"status\": \"falied\",\n" +
// " \"errorcode\": \"-32000\",\n" +
// " \"errormsg\": \"U8C返回信息:以下档案在U8cloud系统中根据公司或者账簿信息找不到请检查详细信息1、档案类型计量档案公司编码0001档案编码\",\n" +
// " \"taskNumber\": \"202408220001\"\n" +
// "}");
// jsonObject.put("status","4");
// jsonObject.put("url","https://oapi.dingtalk.com/topapi/message/corpconversation/asyncsend_v2");
// jsonObject.put("appType","5DD");
//
// //1根据测试消息状态成功失败以及目标API是否启用推送决定是否要推送消息只推送失败的且启用推送的
// //2根据目标API找到其消息模版并根据模版生成消息内容
// //3根据目标API找到其预警应用api并推送消息
// String status = jsonObject.get("status").toString();
// String receiveApiCode = jsonObject.get("receive_api_code").toString();
// String sendAppName = jsonObject.get("send_app_name").toString();
// String receiveApiName = jsonObject.get("recieve_api_name").toString();
// String recieveAppName = jsonObject.get("recieve_app_name").toString();
// String returnData = jsonObject.get("return_data").toString();
// String url = jsonObject.get("url").toString();
// String appType = jsonObject.get("appType").toString();
// String sendMsgContent = "";
//
// SysWarningInterfaceEntity interfaceEntity = new SysWarningInterfaceEntity();
// SysWarningConfigEntity configEntity = new SysWarningConfigEntity();
// SysMessageTemplateEntity templateEntity = new SysMessageTemplateEntity();
//
// interfaceEntity.setApiCode(receiveApiCode);
//
// if(status == null){
// logger.error("日志状态为空");
// return BaseResult.getFailureMessageEntity("日志状态为空");
// }
// if ("4".equals(status)) {
// interfaceEntity = sysWarningInterfaceDao.queryOne(interfaceEntity);
// if(interfaceEntity == null){
// logger.error("未找到API接口预警信息");
// return BaseResult.getFailureMessageEntity("未找到API接口预警信息");
// }
// if(interfaceEntity.getStatus() == null || interfaceEntity.getStatus().equals("1") == false){
// logger.error("API接口未启用推送");
// return BaseResult.getFailureMessageEntity("API接口未启用推送");
// }
// //根据主表id找到主表记录中的消息模版id
// String warningConfigId = interfaceEntity.getWarningConfigId();
// if(warningConfigId == null || "".equals(warningConfigId)){
// logger.error("未找到该接口预警配置信息的主表id");
// return BaseResult.getFailureMessageEntity("未找到该接口预警配置信息的主表id");
// }
// configEntity = sysWarningConfigDao.get(warningConfigId);
// if(configEntity == null){
// logger.error("未找到该接口预警配置信息");
// return BaseResult.getFailureMessageEntity("未找到该接口预警配置信息");
// }
//
// String messageTemplateId = configEntity.getMessageTemplateId();
// if(messageTemplateId == null || "".equals(messageTemplateId)){
// logger.error("未找到该接口预警配置信息的消息模版id");
// return BaseResult.getFailureMessageEntity("未找到该接口预警配置信息的消息模版id");
// }
// templateEntity = sysMessageTemplateDao.get(messageTemplateId);
// if(templateEntity == null){
// logger.error("未找到该接口预警配置信息的消息模版信息");
// return BaseResult.getFailureMessageEntity("未找到该接口预警配置信息的消息模版信息");
// }
//
// String messageContent = templateEntity.getMessageContents();
// if(messageContent == null || "".equals(messageContent)){
// logger.error("未找到该接口预警配置信息的消息模版内容");
// return BaseResult.getFailureMessageEntity("未找到该接口预警配置信息的消息模版内容");
// }
//
// sendMsgContent = messageContent.replace("${reciecveAppName}",recieveAppName);
// sendMsgContent = sendMsgContent.replace("${sendAppName}",sendAppName);
// sendMsgContent = sendMsgContent.replace("${receiveApiName}",receiveApiName);
// sendMsgContent = sendMsgContent.replace("${returnData}",returnData);
//
// String templateName = templateEntity.getTemplateName();
//
// switch (appType){
// case "6WX":
// //调用微信推送消息
// break;
// case "5DD":
// //消息类型3表示钉钉
// String appkey = "dingbltm9wszcl7hoxyg";
// String appsecret = "ex3a9qwdTXWf_VKJEddAg8YE7x98kIl3Nsy_7g0NdwvK3w3nXdUhJ3XQP4lUYs2d";
//
// String type = "3";
// //发送消息时使用的微应用的AgentID
// String agent_id = "3209295620";
// //接收者的userid列表最大用户列表长度100
// String userid_list = configEntity.getRecipientId();
//
// String bodyParams = splicingDDBody(sendMsgContent,agent_id,userid_list).toString();
//
//// String access_token = getAccessToken(appkey,appsecret);
//// String Baseurl = url + "?access_token="+ access_token;
//
// String result = HttpRequest.post("http://127.0.0.1:9999/kangarooDataCenterV3/entranceController/externalCallInterface").
// header("appId","800043").
// header("apiCode","8000430001").
// header("publicKey","ZJYA7v6DubGMm8EdBPGo+Jj9wCpUeCGJEpfBRLiInq4dvDlCe7eDIk+3zDUT+v578prj").
// header("secretKey","bsAMm6tvJs/BV1SO/9ZzjlW+OQaK0mwyv6rLvktyNy/OdltLuG2zze9bT7ttfAA9j3JzOP8MtA1LSGvL+2BWG8c/o7DKi92S4mr3zcGearA=").
// body(bodyParams).
// execute().
// body();
// JSONObject resultJson = JSONObject.parseObject(result);
// String errcode = resultJson.getString("errcode");
//
// if(errcode != null && errcode.equals("0")){
// logger.info("推送消息成功,开始保存日志");
// SysSendMessageLogEntity logentity = saveLog(sendMsgContent,type,resultJson.toString(),templateName);
// logger.info("保存日志成功");
// }else{
// logger.error("推送消息失败,开始保存日志");
// SysSendMessageLogEntity logentity = saveLog(sendMsgContent,type,resultJson.toString(),templateName);
// logger.error("保存日志成功");
// }
// break;
// default:
// logger.error("未找到该应用类型");
// break;
// }
//
// }else{
// logger.error("日志状态为成功,不需要推送消息");
// return BaseResult.getFailureMessageEntity("日志状态为成功,不需要推送消息");
// }
// return BaseResult.getSuccessMessageEntity("true");
// }
/**
* sendMessage方法根据请求错误消息组装成消息模版推送到三方业务系统
@ -159,14 +292,14 @@ public class SysSendMessageLogServiceImpl extends BaseService<SysSendMessageLogE
@Override
public boolean sendMessage(SysPushMessageEntity entity){
String status = entity.getStatus();
Long receiveApiCode = entity.getReceiveApiCode();
String receiveApiCode = entity.getReceiveApiCode();
String sendAppName = entity.getSendAppName();
String receiveApiName = entity.getReceiveApiName();
String recieveAppName = entity.getReceiveAppName();
String returnData = entity.getReturnData();
String warningAppType = entity.getWarningAppType();
Long warningAppCode = entity.getWarningAppCode();
Long warningApiCode = entity.getWarningApiCode();
String warningAppCode = entity.getWarningAppCode();
String warningApiCode = entity.getWarningApiCode();
String sendMsgContent = "";
SysWarningInterfaceEntity interfaceEntity = new SysWarningInterfaceEntity();
@ -254,85 +387,26 @@ public class SysSendMessageLogServiceImpl extends BaseService<SysSendMessageLogE
break;
}
String result = HttpRequest.post("http://127.0.0.1:9999/kangarooDataCenterV3/entranceController/externalCallInterface").
header("appId",warningAppCode.toString()).
header("apiCode",warningApiCode.toString()).
header("appId",warningAppCode).
header("apiCode",warningApiCode).
header("publicKey","ZJYA7v6DubGMm8EdBPGo+Jj9wCpUeCGJEpfBRLiInq4dvDlCe7eDIk+3zDUT+v578prj").
header("secretKey","bsAMm6tvJs/BV1SO/9ZzjlW+OQaK0mwyv6rLvktyNy/OdltLuG2zze9bT7ttfAA9j3JzOP8MtA1LSGvL+2BWG8c/o7DKi92S4mr3zcGearA=").
body(bodyParams).
execute().
body();
JSONObject resultJson = JSONObject.parseObject(result);
String body = resultJson.getString("attribute");
String errcode = resultJson.getJSONObject("attribute").getString("errcode");
if(errcode != null && errcode.equals("0")){
logger.info("推送消息成功,开始保存日志");
saveLog(sendMsgContent,type,resultJson.toString(),templateName,recipientIdList,warningAppReceiverIdList);
SysApplicationApiEntity sysApplicationApiEntity = new SysApplicationApiEntity();
sysApplicationApiEntity.setApiCode(warningApiCode);
SysApplicationApiEntity warningApiEntity = sysApplicationApiDao.queryOne(sysApplicationApiEntity);
//根据预警接口编码以及返回数据判断消息推送是否成功
if(warningApiEntity.getReturnSuccessField() != null && !"".equals(warningApiEntity.getReturnSuccessField())
&& warningApiEntity.getReturnSuccessValue() != null && !"".equals(warningApiEntity.getReturnSuccessValue())){
//先判断返回值是否为JSON格式
if (JSONUtil.isTypeJSON(body)){
JSONObject cheackdatas = JSONObject.parseObject(body);
JSONObject datas = JSONObject.parseObject(body);
String checkdata = cheackdatas.getString(warningApiEntity.getReturnSuccessField());
//判断返回值是否为预警接口预期的返回值(1返回值匹配2返回值配置的就是not null3返回值带.)
if (checkdata != null && warningApiEntity.getReturnSuccessValue().equals(checkdata)) {
logger.info("推送消息成功,开始保存日志");
saveLog(sendMsgContent,type,resultJson.toString(),templateName,recipientIdList,warningAppReceiverIdList);
logger.info("保存日志成功");
}else if(warningApiEntity.getReturnSuccessValue().equals("not null") && checkdata != null){
logger.info("推送消息成功,开始保存日志");
saveLog(sendMsgContent,type,resultJson.toString(),templateName,recipientIdList,warningAppReceiverIdList);
logger.info("保存日志成功");
}else {
String fieldname = warningApiEntity.getReturnSuccessField();
if(fieldname.contains(".")){
String[] fileds = fieldname.split("\\.");
boolean flags = false;
for (int i = 0; i < fileds.length; i++) {
if (JSONUtil.isTypeJSON(datas.getString(fileds[i]))) {
datas = datas.getJSONObject(fileds[i]);
if(fileds.length-2 == i ){
String a = datas.getString(fileds[i+1]);
if (a != null && warningApiEntity.getReturnSuccessValue().equals(a)) {
flags = true;
break;
}else if(warningApiEntity.getReturnSuccessValue().equals("not null") && a != null){
flags = true;
break;
}else {
break;
}
}
}
}
if(flags){
logger.info("推送消息成功,开始保存日志");
saveLog(sendMsgContent,type,resultJson.toString(),templateName,recipientIdList,warningAppReceiverIdList);
logger.info("保存日志成功");
}else {
logger.error("推送消息失败,返回值错误");
saveLog(sendMsgContent,type,resultJson.toString(),templateName,recipientIdList,warningAppReceiverIdList);
logger.error("保存日志成功");
}
}else {
logger.error("推送消息失败,返回值错误");
saveLog(sendMsgContent,type,resultJson.toString(),templateName,recipientIdList,warningAppReceiverIdList);
logger.error("保存日志成功");
}
}
}else{
logger.error("接口调用失败,返回格式错误不是JSON");
saveLog(sendMsgContent,type,resultJson.toString(),templateName,recipientIdList,warningAppReceiverIdList);
logger.error("保存日志成功");
}
logger.info("保存日志成功");
}else{
logger.error("api返回信息字段未配置,开始保存日志");
logger.error("推送消息失败,开始保存日志");
saveLog(sendMsgContent,type,resultJson.toString(),templateName,recipientIdList,warningAppReceiverIdList);
logger.error("保存日志成功");
}
}else{
logger.error("日志状态为成功,不需要推送消息");
return false;

View File

@ -19,7 +19,7 @@ public class SysWarningConfigEntity extends BaseEntity {
/** 预警应用id */
private String warningAppId;
/** 接收推送消息的api编码 */
private Long acceptMessageApiCode;
private String acceptMessageApiCode;
/** 备注 */
private String remark;
/** 是否启用0停用、1启用 */
@ -60,11 +60,11 @@ public class SysWarningConfigEntity extends BaseEntity {
this.warningAppId = warningAppId;
}
public Long getAcceptMessageApiCode() {
public String getAcceptMessageApiCode() {
return acceptMessageApiCode;
}
public void setAcceptMessageApiCode(Long acceptMessageApiCode) {
public void setAcceptMessageApiCode(String acceptMessageApiCode) {
this.acceptMessageApiCode = acceptMessageApiCode;
}

View File

@ -15,7 +15,7 @@
<result property="messageTemplateId" column="message_template_id" jdbcType="VARCHAR"/>
<result property="appId" column="app_id" jdbcType="VARCHAR"/>
<result property="warningAppId" column="warning_app_id" jdbcType="VARCHAR"/>
<result property="acceptMessageApiCode" column="accept_message_api_code" jdbcType="INTEGER"/>
<result property="acceptMessageApiCode" column="accept_message_api_code" jdbcType="VARCHAR"/>
<result property="remark" column="remark" jdbcType="VARCHAR"/>
<result property="status" column="status" jdbcType="VARCHAR"/>
<result property="recipientId" column="recipient_id" jdbcType="VARCHAR"/>

View File

@ -15,7 +15,7 @@ public class SysWarningInterfaceEntity extends BaseEntity {
/** api名称 */
private String apiName;
/** api编码 */
private Long apiCode;
private String apiCode;
/** 推送方式1推送一次、2定时 */
private String pushMethod;
/** 状态0停用、1启用 */
@ -40,11 +40,11 @@ public class SysWarningInterfaceEntity extends BaseEntity {
this.apiName = apiName;
}
public Long getApiCode() {
public String getApiCode() {
return apiCode;
}
public void setApiCode(Long apiCode) {
public void setApiCode(String apiCode) {
this.apiCode = apiCode;
}

View File

@ -13,7 +13,7 @@
<result property="org_id" column="org_id" jdbcType="VARCHAR"/>
<result property="companyId" column="company_id" jdbcType="VARCHAR"/>
<result property="apiName" column="api_name" jdbcType="VARCHAR"/>
<result property="apiCode" column="api_code" jdbcType="INTEGER"/>
<result property="apiCode" column="api_code" jdbcType="VARCHAR"/>
<result property="pushMethod" column="push_method" jdbcType="VARCHAR"/>
<result property="status" column="status" jdbcType="VARCHAR"/>
<result property="warningConfigId" column="warning_config_id" jdbcType="VARCHAR"/>