perf:调整消息日志相关代码
This commit is contained in:
@@ -2,7 +2,6 @@ package com.tiesheng.demo.controller;
|
||||
|
||||
import cn.hutool.core.collection.CollUtil;
|
||||
import cn.hutool.core.date.TimeInterval;
|
||||
import cn.hutool.json.JSONUtil;
|
||||
import cn.hutool.log.LogFactory;
|
||||
import cn.hutool.poi.excel.ExcelUtil;
|
||||
import com.alibaba.excel.EasyExcel;
|
||||
@@ -12,8 +11,6 @@ import com.tiesheng.annotation.token.TokenIgnore;
|
||||
import com.tiesheng.database.config.DbBackupConfig;
|
||||
import com.tiesheng.demo.pojos.PoiBean;
|
||||
import com.tiesheng.demo.pojos.TestFile;
|
||||
import com.tiesheng.message.pojos.MessageReqResp;
|
||||
import com.tiesheng.message.pojos.UserChannel;
|
||||
import com.tiesheng.platform.config.ding.PlatformDingConfig;
|
||||
import com.tiesheng.platform.config.ding.bean.DingUserInfo;
|
||||
import com.tiesheng.util.config.EncryptConfig;
|
||||
@@ -53,8 +50,6 @@ public class TestController {
|
||||
@Autowired
|
||||
EncryptConfig encryptConfig;
|
||||
@Autowired
|
||||
CoreMessageService coreMessageService;
|
||||
@Autowired
|
||||
CoreLogService coreLogService;
|
||||
@Autowired
|
||||
DbBackupConfig dbBackupConfig;
|
||||
@@ -99,12 +94,12 @@ public class TestController {
|
||||
|
||||
@GetMapping("/send")
|
||||
@TokenIgnore
|
||||
public ApiResp<MessageReqResp> sendMessage() {
|
||||
public ApiResp<String> sendMessage() {
|
||||
|
||||
MessageReqResp reqResp = coreMessageService.send(new UserChannel("13567116463", "sms"),
|
||||
JSONUtil.createObj().putOpt("action", "sms-visitor-invite"));
|
||||
// MessageReqResp reqResp = coreMessageService.send(new UserChannel("13567116463", "sms"),
|
||||
// JSONUtil.createObj().putOpt("action", "sms-visitor-invite"));
|
||||
|
||||
return ApiResp.respOK(reqResp);
|
||||
return ApiResp.respOK(null);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -7,9 +7,9 @@ import cn.hutool.core.util.StrUtil;
|
||||
import cn.hutool.crypto.SecureUtil;
|
||||
import cn.hutool.json.JSONObject;
|
||||
import cn.hutool.json.JSONUtil;
|
||||
import com.tiesheng.message.pojos.MessageReqResp;
|
||||
import com.tiesheng.message.service.TsMessageSender;
|
||||
import com.tiesheng.util.exception.ApiException;
|
||||
import com.tiesheng.util.pojos.ApiResp;
|
||||
import com.tiesheng.util.service.http.OkHttpUtil;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.context.properties.ConfigurationProperties;
|
||||
@@ -119,17 +119,7 @@ public class AliyunSmsSender implements TsMessageSender {
|
||||
* @param tempParam 短信模板
|
||||
* @return
|
||||
*/
|
||||
public MessageReqResp sendSms(String phoneNumbers, AliyunTempParam tempParam) {
|
||||
|
||||
MessageReqResp reqResp = new MessageReqResp("阿里云短信");
|
||||
reqResp.setTarget(phoneNumbers);
|
||||
reqResp.setResult(1);
|
||||
reqResp.setContent(JSONUtil.createObj()
|
||||
.putOpt("PhoneNumbers", phoneNumbers)
|
||||
.putOpt("SignName", tempParam.getSignName())
|
||||
.putOpt("TemplateCode", tempParam.getTemplateCode())
|
||||
.putOpt("TemplateParam", tempParam.getTemplateParam())
|
||||
.toString());
|
||||
public ApiResp<String> sendSms(String phoneNumbers, AliyunTempParam tempParam) {
|
||||
|
||||
// 业务API参数
|
||||
ConcurrentHashMap<String, String> queryMap = new ConcurrentHashMap<>();
|
||||
@@ -140,18 +130,16 @@ public class AliyunSmsSender implements TsMessageSender {
|
||||
queryMap.put("TemplateParam", tempParam.getTemplateParam().toString());
|
||||
}
|
||||
|
||||
reqResp.setRespBody(request("SendSms", queryMap));
|
||||
JSONObject respObj = JSONUtil.parseObj(reqResp.getRespBody());
|
||||
JSONObject respObj = JSONUtil.parseObj(request("SendSms", queryMap));
|
||||
if (!Objects.equals(respObj.getStr("Code"), "OK")) {
|
||||
reqResp.setResult(0);
|
||||
reqResp.setToast(respObj.getStr("Message"));
|
||||
return ApiResp.resp130(respObj.getStr("Message"));
|
||||
}
|
||||
|
||||
return reqResp;
|
||||
return ApiResp.respOK("");
|
||||
}
|
||||
|
||||
@Override
|
||||
public MessageReqResp send(String user, JSONObject body) {
|
||||
public ApiResp<String> send(String user, JSONObject body) {
|
||||
boolean mobile = Validator.isMobile(user);
|
||||
if (!mobile) {
|
||||
return null;
|
||||
|
||||
@@ -1,87 +0,0 @@
|
||||
package com.tiesheng.message.pojos;
|
||||
|
||||
public class MessageReqResp {
|
||||
|
||||
private String type;
|
||||
|
||||
/**
|
||||
* 发送对象
|
||||
*/
|
||||
private String target;
|
||||
|
||||
/**
|
||||
* 发送内容
|
||||
*/
|
||||
private String content;
|
||||
|
||||
/**
|
||||
* 返回结果
|
||||
*/
|
||||
private String respBody;
|
||||
|
||||
/**
|
||||
* 结果,0-否,1-是
|
||||
*/
|
||||
private Integer result;
|
||||
|
||||
/**
|
||||
* 提示的异常信息
|
||||
*/
|
||||
private String toast;
|
||||
|
||||
public MessageReqResp(String type) {
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
// setter\getter
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
|
||||
public String getType() {
|
||||
return type;
|
||||
}
|
||||
|
||||
public void setType(String type) {
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
public String getTarget() {
|
||||
return target;
|
||||
}
|
||||
|
||||
public void setTarget(String target) {
|
||||
this.target = target;
|
||||
}
|
||||
|
||||
public String getContent() {
|
||||
return content;
|
||||
}
|
||||
|
||||
public void setContent(String content) {
|
||||
this.content = content;
|
||||
}
|
||||
|
||||
public String getRespBody() {
|
||||
return respBody;
|
||||
}
|
||||
|
||||
public void setRespBody(String respBody) {
|
||||
this.respBody = respBody;
|
||||
}
|
||||
|
||||
public Integer getResult() {
|
||||
return result;
|
||||
}
|
||||
|
||||
public void setResult(Integer result) {
|
||||
this.result = result;
|
||||
}
|
||||
|
||||
public String getToast() {
|
||||
return toast;
|
||||
}
|
||||
|
||||
public void setToast(String toast) {
|
||||
this.toast = toast;
|
||||
}
|
||||
}
|
||||
@@ -2,7 +2,7 @@ package com.tiesheng.message.service;
|
||||
|
||||
|
||||
import cn.hutool.json.JSONObject;
|
||||
import com.tiesheng.message.pojos.MessageReqResp;
|
||||
import com.tiesheng.util.pojos.ApiResp;
|
||||
|
||||
/**
|
||||
* @author hao
|
||||
@@ -20,7 +20,7 @@ public interface TsMessageSender {
|
||||
* @param channel 消息通道,如果为空表示所有通道
|
||||
* @return 返回的内容,如果为空表示发送成功
|
||||
*/
|
||||
MessageReqResp send(String user, JSONObject body);
|
||||
ApiResp<String> send(String user, JSONObject body);
|
||||
|
||||
|
||||
/**
|
||||
|
||||
@@ -4,8 +4,8 @@ import cn.hutool.core.collection.CollUtil;
|
||||
import cn.hutool.core.util.ArrayUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import cn.hutool.json.JSONObject;
|
||||
import com.tiesheng.message.pojos.MessageReqResp;
|
||||
import com.tiesheng.message.pojos.UserChannel;
|
||||
import com.tiesheng.util.pojos.ApiResp;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
@@ -61,18 +61,18 @@ public class TsMessageService {
|
||||
* @param userChannel
|
||||
* @param body
|
||||
*/
|
||||
public MessageReqResp send(UserChannel userChannel, JSONObject body) {
|
||||
public ApiResp<String> send(UserChannel userChannel, JSONObject body) {
|
||||
|
||||
if (StrUtil.isEmpty(userChannel.getUser()) || StrUtil.isEmpty(userChannel.getChannel())) {
|
||||
return null;
|
||||
return ApiResp.resp130("消息对象或消息通道不存在");
|
||||
}
|
||||
|
||||
TsMessageSender messageSender = CollUtil.findOne(messageSenderList,
|
||||
sender -> Objects.equals(sender.getChannel(), userChannel.getChannel()) && sender.support());
|
||||
if (messageSender != null) {
|
||||
messageSender.send(userChannel.getUser(), body);
|
||||
return messageSender.send(userChannel.getUser(), body);
|
||||
}
|
||||
return null;
|
||||
return ApiResp.resp130("消息未成功发送");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -129,6 +129,19 @@ public class ApiResp<T> {
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 130错误
|
||||
*
|
||||
* @param msg
|
||||
* @return
|
||||
*/
|
||||
public static ApiResp<String> resp130(String msg) {
|
||||
ApiResp<String> result = new ApiResp<>();
|
||||
result.code = 130;
|
||||
result.message = msg;
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* 是否成功
|
||||
*
|
||||
|
||||
@@ -1,37 +0,0 @@
|
||||
package com.tiesheng.util.service.http;
|
||||
|
||||
import cn.hutool.json.JSONUtil;
|
||||
import cn.hutool.log.LogFactory;
|
||||
import okhttp3.Interceptor;
|
||||
import okhttp3.Request;
|
||||
import okhttp3.Response;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public class HttpLogInterceptor implements Interceptor {
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public Response intercept(@NotNull Chain chain) {
|
||||
|
||||
Request request = chain.request();
|
||||
|
||||
Response response;
|
||||
try {
|
||||
response = chain.proceed(request);
|
||||
} catch (Exception e) {
|
||||
response = new Response.Builder()
|
||||
.request(request)
|
||||
.body(OkHttpUtil.ofJsonResponse(JSONUtil.createObj()
|
||||
.putOpt("code", -1)
|
||||
.putOpt("message", e.getMessage())
|
||||
.putOpt("exception", e)
|
||||
.toString()))
|
||||
.code(200).build();
|
||||
}
|
||||
|
||||
LogFactory.get().info("url: {},body: {}", request.url(), response.body().contentType().toString());
|
||||
|
||||
return response;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -3,13 +3,14 @@ package com.tiesheng.web.controller;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.tiesheng.util.pojos.ApiResp;
|
||||
import com.tiesheng.util.pojos.PageDTO;
|
||||
import com.tiesheng.web.pojos.dao.CoreLogApi;
|
||||
import com.tiesheng.web.pojos.dao.CoreLogLogin;
|
||||
import com.tiesheng.web.pojos.dao.CoreLogOperation;
|
||||
import com.tiesheng.web.pojos.dao.CoreLogProcess;
|
||||
import com.tiesheng.util.pojos.PageDTO;
|
||||
import com.tiesheng.web.pojos.vo.ProcessDetailVo;
|
||||
import com.tiesheng.web.service.CoreLogService;
|
||||
import com.tiesheng.util.pojos.ApiResp;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
@@ -69,23 +70,23 @@ public class LogController {
|
||||
|
||||
|
||||
/**
|
||||
* 登录日志列表
|
||||
* 调用日志
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
@GetMapping("/message/page")
|
||||
public ApiResp<List<CoreLogMessage>> messagePage(String result, @Valid PageDTO dto) {
|
||||
@GetMapping("/api/page")
|
||||
public ApiResp<List<CoreLogApi>> messagePage(String result, @Valid PageDTO dto) {
|
||||
|
||||
QueryWrapper<CoreLogMessage> queryWrapper = new QueryWrapper<>();
|
||||
QueryWrapper<CoreLogApi> queryWrapper = new QueryWrapper<>();
|
||||
queryWrapper.eq("is_deleted", 0);
|
||||
if (!StrUtil.isEmpty(result)) {
|
||||
queryWrapper.eq("result", result);
|
||||
}
|
||||
dto.likeColumns(queryWrapper, "type", "target", "content", "resp_body");
|
||||
dto.likeColumns(queryWrapper, "type", "content");
|
||||
queryWrapper.orderByDesc("create_time");
|
||||
|
||||
Page<CoreLogMessage> page = dto.pageObj();
|
||||
coreLogService.getLogMessageMapper().selectPage(page, queryWrapper);
|
||||
Page<CoreLogApi> page = dto.pageObj();
|
||||
coreLogService.getLogApiMapper().selectPage(page, queryWrapper);
|
||||
return ApiResp.respOK(page.getRecords(), page.getTotal());
|
||||
}
|
||||
|
||||
|
||||
@@ -4,4 +4,4 @@ import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import com.tiesheng.web.pojos.dao.CoreLogApi;
|
||||
|
||||
public interface CoreLogApiMapper extends BaseMapper<CoreLogApi> {
|
||||
}
|
||||
}
|
||||
@@ -13,6 +13,7 @@ import com.tiesheng.util.config.Ip2regionConfig;
|
||||
import com.tiesheng.util.exception.ApiException;
|
||||
import com.tiesheng.util.pojos.TokenBean;
|
||||
import com.tiesheng.util.service.TsServiceBase;
|
||||
import com.tiesheng.web.mapper.CoreLogApiMapper;
|
||||
import com.tiesheng.web.mapper.CoreLogLoginMapper;
|
||||
import com.tiesheng.web.mapper.CoreLogOperationMapper;
|
||||
import com.tiesheng.web.mapper.CoreLogProcessMapper;
|
||||
@@ -47,7 +48,7 @@ public class CoreLogService extends TsServiceBase<CoreLogOperationMapper, CoreLo
|
||||
@Autowired
|
||||
CoreLogLoginMapper coreLogLoginMapper;
|
||||
@Autowired
|
||||
CoreLogMessageMapper coreLogMessageMapper;
|
||||
CoreLogApiMapper coreLogApiMapper;
|
||||
@Autowired
|
||||
Ip2regionConfig ip2regionConfig;
|
||||
@Autowired
|
||||
@@ -57,8 +58,8 @@ public class CoreLogService extends TsServiceBase<CoreLogOperationMapper, CoreLo
|
||||
return coreLogLoginMapper;
|
||||
}
|
||||
|
||||
public CoreLogMessageMapper getLogMessageMapper() {
|
||||
return coreLogMessageMapper;
|
||||
public CoreLogApiMapper getLogApiMapper() {
|
||||
return coreLogApiMapper;
|
||||
}
|
||||
|
||||
public CoreLogProcessMapper getCoreLogProcessMapper() {
|
||||
|
||||
@@ -0,0 +1,40 @@
|
||||
//package com.tiesheng.web.service;
|
||||
//
|
||||
//import cn.hutool.json.JSONUtil;
|
||||
//import cn.hutool.log.LogFactory;
|
||||
//import com.tiesheng.util.service.http.OkHttpUtil;
|
||||
//import okhttp3.Interceptor;
|
||||
//import okhttp3.Request;
|
||||
//import okhttp3.Response;
|
||||
//import org.springframework.stereotype.Component;
|
||||
//
|
||||
//import javax.validation.constraints.NotNull;
|
||||
//
|
||||
//@Component
|
||||
//public class LogApiOkHttpInterceptor implements Interceptor {
|
||||
//
|
||||
// @NotNull
|
||||
// @Override
|
||||
// public Response intercept(@NotNull Chain chain) {
|
||||
//
|
||||
// Request request = chain.request();
|
||||
//
|
||||
// Response response;
|
||||
// try {
|
||||
// response = chain.proceed(request);
|
||||
// } catch (Exception e) {
|
||||
// response = new Response.Builder()
|
||||
// .request(request)
|
||||
// .body(OkHttpUtil.ofJsonResponse(JSONUtil.createObj()
|
||||
// .putOpt("code", -1)
|
||||
// .putOpt("message", e.getMessage())
|
||||
// .putOpt("exception", e)
|
||||
// .toString()))
|
||||
// .code(200).build();
|
||||
// }
|
||||
//
|
||||
// LogFactory.get().info("url: {},body: {}", request.url(), response.body().contentType().toString());
|
||||
//
|
||||
// return response;
|
||||
// }
|
||||
//}
|
||||
Reference in New Issue
Block a user