Merge branch 'feature/join_elk/221031' into 'master'
Feature/join elk/221031 See merge request infra/axzo-log-plat!81
This commit is contained in:
commit
eb2f1a5627
@ -128,14 +128,11 @@
|
||||
<artifactId>basics-profiles-api</artifactId>
|
||||
</dependency>
|
||||
|
||||
<!-- 测试 client 使用
|
||||
<dependency>
|
||||
<groupId>cn.axzo.platform</groupId>
|
||||
<artifactId>axzo-log-api</artifactId>
|
||||
<version>1.0.0-SNAPSHOT</version>
|
||||
<scope>test</scope>
|
||||
<groupId>org.springframework.kafka</groupId>
|
||||
<artifactId>spring-kafka</artifactId>
|
||||
</dependency>
|
||||
-->
|
||||
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
|
||||
@ -31,12 +31,15 @@ public class LogPlatApplication {
|
||||
Environment env = context.getEnvironment();
|
||||
logger.info("Application 【{}】 is running on 【{}】 environment!\n\t" +
|
||||
"MySQL: \t{}\t username:{}\t\n\t" +
|
||||
"RabbitMQ: \t{}\t username:{},\t\n",
|
||||
"RabbitMQ: \t{}\t username:{},\t\n" +
|
||||
"kafka: \t{}\t topic:{},\t\n",
|
||||
env.getProperty("spring.application.name"),
|
||||
env.getProperty("spring.profiles.active"),
|
||||
env.getProperty("spring.datasource.url"),
|
||||
env.getProperty("spring.datasource.username"),
|
||||
env.getProperty("spring.rabbitmq.addresses"),
|
||||
env.getProperty("spring.rabbitmq.username"));
|
||||
env.getProperty("spring.rabbitmq.username"),
|
||||
env.getProperty("log-plat.kafka.servers"),
|
||||
env.getProperty("log-plat.kafka.topic"));
|
||||
}
|
||||
}
|
||||
|
||||
@ -0,0 +1,37 @@
|
||||
package cn.axzo.log.platform.server.config;
|
||||
|
||||
import org.apache.kafka.clients.producer.KafkaProducer;
|
||||
import org.apache.kafka.clients.producer.ProducerConfig;
|
||||
import org.apache.kafka.common.serialization.StringSerializer;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.util.Properties;
|
||||
|
||||
/***
|
||||
* @author: pepsi
|
||||
* @description: TODO
|
||||
* @date: 2022/10/30
|
||||
*/
|
||||
@Component
|
||||
public class KafkaProducerConfig {
|
||||
|
||||
|
||||
@Value("${log-plat.kafka.servers:120.46.182.212:9092,120.46.188.248:9092}")
|
||||
private String servers;
|
||||
|
||||
@Value("${log-plat.kafka.topic:axzo.dev.log-plat.sink_elk}")
|
||||
private String topic;
|
||||
|
||||
@Bean
|
||||
public KafkaProducer<String, String> kafkaProducer() {
|
||||
Properties props = new Properties();
|
||||
props.put(ProducerConfig.BOOTSTRAP_SERVERS_CONFIG, servers);
|
||||
props.put(ProducerConfig.CLIENT_ID_CONFIG, "log-plat-producer");
|
||||
props.put(ProducerConfig.KEY_SERIALIZER_CLASS_CONFIG, StringSerializer.class.getName());
|
||||
props.put(ProducerConfig.VALUE_SERIALIZER_CLASS_CONFIG, StringSerializer.class.getName());
|
||||
return new KafkaProducer<>(props);
|
||||
}
|
||||
|
||||
}
|
||||
@ -0,0 +1,56 @@
|
||||
package cn.axzo.log.platform.server.controller.api;
|
||||
|
||||
import cn.axzo.log.platform.server.dto.LogSinkELKReqDTO;
|
||||
import cn.axzo.log.platform.server.exception.BizException;
|
||||
import cn.axzo.log.platform.server.service.LogSinkELKService;
|
||||
import cn.azxo.framework.common.model.CommonResponse;
|
||||
import com.github.xiaoymin.knife4j.annotations.ApiSupport;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.validation.BindingResult;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMethod;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import javax.validation.Valid;
|
||||
|
||||
/***
|
||||
* @author: pepsi
|
||||
* @description: 通过接口方式上报的日志转到kafka中
|
||||
* @date: 2022/10/29
|
||||
*/
|
||||
@Api(tags = "日志转存 ELK 接口")
|
||||
@ApiSupport(author = "彭健")
|
||||
@RestController
|
||||
@RequestMapping("/api/v1")
|
||||
public class LogSinkELKController {
|
||||
|
||||
private final Logger logger = LoggerFactory.getLogger(LogSinkELKController.class);
|
||||
|
||||
@Autowired
|
||||
private LogSinkELKService sinkELKService;
|
||||
|
||||
@RequestMapping(value = "/log/sink/elk", method = RequestMethod.POST)
|
||||
@ApiOperation(value = "日志中转接入 ELK")
|
||||
public CommonResponse<?> logSinkElk(@RequestBody @Valid LogSinkELKReqDTO req,
|
||||
BindingResult bindingResult) {
|
||||
if (bindingResult.hasErrors()) {
|
||||
logger.warn("illegal param for log sink elk.");
|
||||
return CommonResponse.fail(bindingResult.getAllErrors().get(0).getDefaultMessage());
|
||||
}
|
||||
try {
|
||||
sinkELKService.sinkELk(req);
|
||||
return CommonResponse.success();
|
||||
} catch (BizException bizException) {
|
||||
logger.warn("log sink elk biz exception,biz errMsg={}.", bizException.getMessage());
|
||||
return CommonResponse.fail(bizException.getMessage());
|
||||
} catch (Exception e) {
|
||||
logger.error("log sink elk exception,errMsg={}.", e.getMessage());
|
||||
return CommonResponse.fail(e.getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -2,6 +2,7 @@ package cn.axzo.log.platform.server.controller.api;
|
||||
|
||||
import cn.axzo.log.platform.server.dto.*;
|
||||
import cn.axzo.log.platform.server.enums.OuTypeEnums;
|
||||
import cn.axzo.log.platform.server.exception.ThirdApiException;
|
||||
import cn.axzo.log.platform.server.service.OperateLogService;
|
||||
import cn.azxo.framework.common.model.CommonPageResponse;
|
||||
import cn.azxo.framework.common.model.CommonResponse;
|
||||
@ -52,6 +53,8 @@ public class OperateLogController {
|
||||
}
|
||||
try {
|
||||
return CommonResponse.success(operateLogService.insertOperaLog(req));
|
||||
} catch (ThirdApiException apiException) {
|
||||
return CommonResponse.fail(apiException.getMessage());
|
||||
} catch (Exception e) {
|
||||
logger.error("create operate log failed.", e);
|
||||
return CommonResponse.fail(e.getMessage());
|
||||
@ -73,6 +76,8 @@ public class OperateLogController {
|
||||
}
|
||||
CommonPageResponse<OperateLogQueryRespDTO> resp = operateLogService.queryBasicInfoForPage(req);
|
||||
return CommonResponse.success(resp);
|
||||
} catch (IllegalArgumentException argumentException) {
|
||||
return CommonResponse.fail(argumentException.getMessage());
|
||||
} catch (Exception e) {
|
||||
logger.error("query operate logs failed,", e);
|
||||
return CommonResponse.fail(e.getMessage());
|
||||
@ -88,12 +93,12 @@ public class OperateLogController {
|
||||
* @param request
|
||||
* @throws Exception
|
||||
*/
|
||||
private void handleRequestHeaderParam(int ouType, OperateLogQueryReqDTO req, HttpServletRequest request) throws Exception {
|
||||
private void handleRequestHeaderParam(int ouType, OperateLogQueryReqDTO req, HttpServletRequest request) throws IllegalArgumentException {
|
||||
String ouId = request.getHeader("ouId");
|
||||
String workspaceId = request.getHeader("workspaceId");
|
||||
if (OuTypeEnums.isPrimaryContractinUnit(ouType)) {
|
||||
if (!StringUtils.hasText(workspaceId)) {
|
||||
throw new Exception("can not find workspaceId from header");
|
||||
throw new IllegalArgumentException("can not find workspaceId from header");
|
||||
}
|
||||
if ((req.getWorkspaceId() == null || req.getWorkspaceId() == 0)) {
|
||||
req.setWorkspaceId(Long.valueOf(workspaceId));
|
||||
@ -101,7 +106,7 @@ public class OperateLogController {
|
||||
}
|
||||
} else if (OuTypeEnums.isSubcontracting(ouType)) {
|
||||
if (!StringUtils.hasText(ouId) || !StringUtils.hasText(workspaceId)) {
|
||||
throw new Exception("can not find workspaceId or ouId from header");
|
||||
throw new IllegalArgumentException("can not find workspaceId or ouId from header");
|
||||
}
|
||||
if ((req.getOuId() == null || req.getOuId() == 0)) {
|
||||
req.setOuId(Long.valueOf(ouId));
|
||||
@ -123,16 +128,11 @@ public class OperateLogController {
|
||||
if (bindingResult.hasErrors()) {
|
||||
return CommonResponse.fail(bindingResult.getAllErrors().get(0).getDefaultMessage());
|
||||
}
|
||||
/* //todo 先去除 时间跨度校验。
|
||||
if (DateUtil.betweenDay(req.getStartTime(), req.getEndTime(), true) > 7) {
|
||||
logger.error("start and end date interval greater than 7.");
|
||||
return CommonResponse.fail("the time span is greater than 7");
|
||||
}*/
|
||||
try {
|
||||
CommonPageResponse<OperateLogQueryDetailRespDTO> resp = operateLogService.queryForPage(req);
|
||||
return CommonResponse.success(resp);
|
||||
} catch (Exception e) {
|
||||
logger.error("query operate logs failed,", e);
|
||||
logger.warn("query operate logs failed,", e);
|
||||
return CommonResponse.fail(e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
@ -0,0 +1,67 @@
|
||||
package cn.axzo.log.platform.server.dto;
|
||||
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
import javax.validation.constraints.NotNull;
|
||||
import java.util.Map;
|
||||
|
||||
/***
|
||||
* @author: pepsi
|
||||
* @description: TODO
|
||||
* @date: 2022/10/30
|
||||
*/
|
||||
@Data
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
public class LogSinkELKReqDTO {
|
||||
|
||||
@ApiModelProperty(value = "服务名称", position = 1)
|
||||
@NotNull(message = "服务名不可为空")
|
||||
private String serviceName;
|
||||
|
||||
@ApiModelProperty(value = "url信息", position = 2)
|
||||
private String url;
|
||||
|
||||
@ApiModelProperty(value = "内容摘要", position = 3)
|
||||
private String content;
|
||||
|
||||
@ApiModelProperty(value = "操作前数据", position = 4)
|
||||
private String operateBefore;
|
||||
|
||||
@ApiModelProperty(value = "操作后数据", position = 5)
|
||||
private String operateAfter;
|
||||
|
||||
@ApiModelProperty(value = "发生时间(时间戳)", required = true, position = 6, example = "1667211066490")
|
||||
@NotNull(message = "操作时间不能为空")
|
||||
private Long operateTime;
|
||||
|
||||
@ApiModelProperty(value = "结束时间(时间戳)", position = 7, example = "1667211066490")
|
||||
private Long operateEndTime;
|
||||
|
||||
@ApiModelProperty(value = "工作台Id", position = 8)
|
||||
private Long workspaceId;
|
||||
|
||||
@ApiModelProperty(value = "设备号", position = 9)
|
||||
private String sn;
|
||||
|
||||
@ApiModelProperty(value = "描述信息", position = 10)
|
||||
private String desc;
|
||||
|
||||
@ApiModelProperty(value = "用户信息", position = 11)
|
||||
private String userInfo;
|
||||
|
||||
@ApiModelProperty(value = "重试次数", position = 12)
|
||||
private int retryNum;
|
||||
|
||||
@ApiModelProperty(value = "扩展 map", position = 13)
|
||||
private Map<String, String> extValMap;
|
||||
|
||||
@ApiModelProperty(value = "扩展字符串", position = 14)
|
||||
private String logExt;
|
||||
|
||||
@ApiModelProperty(value = "签名", position = 14)
|
||||
private transient String sign;
|
||||
}
|
||||
@ -0,0 +1,18 @@
|
||||
package cn.axzo.log.platform.server.exception;
|
||||
|
||||
/***
|
||||
* @author: pepsi
|
||||
* @description: TODO
|
||||
* @date: 2022/10/30
|
||||
*/
|
||||
public class BizException extends Exception {
|
||||
|
||||
public BizException() {
|
||||
super();
|
||||
}
|
||||
|
||||
public BizException(String msg) {
|
||||
super(msg);
|
||||
}
|
||||
|
||||
}
|
||||
@ -0,0 +1,13 @@
|
||||
package cn.axzo.log.platform.server.exception;
|
||||
|
||||
/***
|
||||
* @author: pepsi
|
||||
* @description: TODO
|
||||
* @date: 2022/10/25
|
||||
*/
|
||||
public class ThirdApiException extends Exception {
|
||||
|
||||
public ThirdApiException(String msg) {
|
||||
super(msg);
|
||||
}
|
||||
}
|
||||
@ -1,6 +1,7 @@
|
||||
package cn.axzo.log.platform.server.service;
|
||||
|
||||
import cn.axzo.log.platform.server.config.SpringContextAware;
|
||||
import cn.axzo.log.platform.server.exception.ServiceException;
|
||||
import com.google.common.cache.CacheBuilder;
|
||||
import com.google.common.cache.CacheLoader;
|
||||
import com.google.common.cache.LoadingCache;
|
||||
@ -96,7 +97,7 @@ public class BaseEsService {
|
||||
}
|
||||
|
||||
|
||||
public boolean insert(String json, String index) throws Exception {
|
||||
public boolean insert(String json, String index) throws ServiceException {
|
||||
IndexRequest request = new IndexRequest(index);
|
||||
request.source(json, XContentType.JSON);
|
||||
try {
|
||||
@ -109,7 +110,7 @@ public class BaseEsService {
|
||||
return true;
|
||||
} catch (Exception e) {
|
||||
logger.error("single insert failed, index=" + index, e);
|
||||
throw new Exception(e.getMessage());
|
||||
throw new ServiceException(e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -0,0 +1,23 @@
|
||||
package cn.axzo.log.platform.server.service;
|
||||
|
||||
import cn.axzo.log.platform.server.dto.LogSinkELKReqDTO;
|
||||
import cn.axzo.log.platform.server.exception.BizException;
|
||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||
|
||||
import java.util.concurrent.ExecutionException;
|
||||
|
||||
/***
|
||||
* @author: pepsi
|
||||
* @description: TODO
|
||||
* @date: 2022/10/29
|
||||
*/
|
||||
public interface LogSinkELKService {
|
||||
|
||||
|
||||
/***
|
||||
* 解密& 消息投入kafka
|
||||
* @param val
|
||||
* @return
|
||||
*/
|
||||
void sinkELk(LogSinkELKReqDTO val) throws BizException, ExecutionException, InterruptedException, JsonProcessingException;
|
||||
}
|
||||
@ -1,6 +1,8 @@
|
||||
package cn.axzo.log.platform.server.service;
|
||||
|
||||
import cn.axzo.log.platform.server.dto.*;
|
||||
import cn.axzo.log.platform.server.exception.ServiceException;
|
||||
import cn.axzo.log.platform.server.exception.ThirdApiException;
|
||||
import cn.azxo.framework.common.model.CommonPageResponse;
|
||||
|
||||
/***
|
||||
@ -14,7 +16,7 @@ public interface OperateLogService {
|
||||
* @param operateLogReq
|
||||
* @return
|
||||
*/
|
||||
boolean insertOperaLog(OperateLogReqDTO operateLogReq) throws Exception;
|
||||
boolean insertOperaLog(OperateLogReqDTO operateLogReq) throws ServiceException, ThirdApiException;
|
||||
|
||||
/**
|
||||
* 分页查询 返回基本字段
|
||||
|
||||
@ -0,0 +1,93 @@
|
||||
package cn.axzo.log.platform.server.service.impl;
|
||||
|
||||
import cn.axzo.log.platform.server.dto.LogSinkELKReqDTO;
|
||||
import cn.axzo.log.platform.server.exception.BizException;
|
||||
import cn.axzo.log.platform.server.service.LogSinkELKService;
|
||||
import cn.axzo.log.platform.server.utils.JacksonCodecUtil;
|
||||
import cn.axzo.log.platform.server.utils.SignUtil;
|
||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||
import org.apache.kafka.clients.producer.Callback;
|
||||
import org.apache.kafka.clients.producer.KafkaProducer;
|
||||
import org.apache.kafka.clients.producer.ProducerRecord;
|
||||
import org.apache.kafka.clients.producer.RecordMetadata;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.concurrent.ExecutionException;
|
||||
|
||||
/***
|
||||
* @author: pepsi
|
||||
* @description: TODO
|
||||
* @date: 2022/10/29
|
||||
*/
|
||||
@Service
|
||||
public class LogSinkELKServiceImpl implements LogSinkELKService {
|
||||
|
||||
private final Logger logger = LoggerFactory.getLogger(LogSinkELKServiceImpl.class);
|
||||
|
||||
private final String SECRET_KEY = "aEsva0zDHECg47P8SuPzmw==";
|
||||
|
||||
@Autowired
|
||||
private KafkaProducer<String, String> kafkaProducer;
|
||||
|
||||
@Value("${log-plat.kafka.topic:axzo.dev.log-plat.sink_elk}")
|
||||
private String topic;
|
||||
|
||||
@Value("${log-plat.kafka.send.async:false}")
|
||||
private Boolean isAsync;
|
||||
|
||||
@Override
|
||||
public void sinkELk(LogSinkELKReqDTO req) throws BizException, ExecutionException, InterruptedException, JsonProcessingException {
|
||||
//解密 && 转换
|
||||
String json = signAndConvert(req);
|
||||
if (isAsync) {
|
||||
kafkaProducer.send(new ProducerRecord<>(topic, json), new KafkaSendCallBack());
|
||||
} else {
|
||||
RecordMetadata recordMetadata = kafkaProducer.send(new ProducerRecord<>(topic, json)).get();
|
||||
logger.info("send msg to kafka success,offset={},partition={}.", recordMetadata.offset(), recordMetadata.partition());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 解密和转换对象
|
||||
* <p>
|
||||
* 思来想去,还是原汤对原食。怎么来的怎么走.
|
||||
*
|
||||
* @param req
|
||||
* @return
|
||||
* @throws BizException
|
||||
*/
|
||||
private String signAndConvert(LogSinkELKReqDTO req) throws BizException {
|
||||
try {
|
||||
LinkedHashMap<String, String> paramsMap = new LinkedHashMap<>();
|
||||
paramsMap.put("serviceName", req.getServiceName());
|
||||
paramsMap.put("operateTime", Long.toString(req.getOperateTime()));
|
||||
paramsMap.put("secretKey", SECRET_KEY);
|
||||
String sign = SignUtil.signParamsMd5(paramsMap);
|
||||
if (!req.getSign().equals(sign)) {
|
||||
logger.warn("request sign is illegal,request sign={},server sign={}.", req.getSign(), sign);
|
||||
throw new BizException("request sign is illegal.");
|
||||
}
|
||||
return JacksonCodecUtil.writeValueAsString(req);
|
||||
} catch (Exception e) {
|
||||
logger.warn("check sign or convert occur exception,msg={}.", e.getMessage());
|
||||
throw new BizException(e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
class KafkaSendCallBack implements Callback {
|
||||
@Override
|
||||
public void onCompletion(RecordMetadata recordMetadata, Exception e) {
|
||||
if (recordMetadata != null) {
|
||||
logger.info("send msg to kafka success,offset={},partition={}.", recordMetadata.offset(), recordMetadata.partition());
|
||||
} else {
|
||||
logger.error("send msg to kafka failed,", e);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -10,11 +10,12 @@ import cn.axzo.basics.profiles.api.UserProfileServiceApi;
|
||||
import cn.axzo.basics.profiles.dto.basic.IdentityProfileDto;
|
||||
import cn.axzo.log.platform.server.dto.*;
|
||||
import cn.axzo.log.platform.server.entity.OperateLogRecordEntity;
|
||||
import cn.axzo.log.platform.server.exception.ServiceException;
|
||||
import cn.axzo.log.platform.server.exception.ThirdApiException;
|
||||
import cn.axzo.log.platform.server.repository.OperateLogRepository;
|
||||
import cn.axzo.log.platform.server.service.BaseEsService;
|
||||
import cn.axzo.log.platform.server.service.OperateLogService;
|
||||
import cn.axzo.log.platform.server.service.converter.OperateLogConverter;
|
||||
import cn.axzo.pudge.core.service.ServiceException;
|
||||
import cn.azxo.framework.common.model.CommonPageResponse;
|
||||
import cn.azxo.framework.common.model.CommonResponse;
|
||||
import cn.hutool.core.date.CalendarUtil;
|
||||
@ -82,7 +83,7 @@ public class OperateLogServiceImpl extends BaseEsService implements OperateLogSe
|
||||
private OperateLogConverter operateLogConverter;
|
||||
|
||||
@Override
|
||||
public boolean insertOperaLog(OperateLogReqDTO operateLogReq) throws Exception {
|
||||
public boolean insertOperaLog(OperateLogReqDTO operateLogReq) throws ServiceException, ThirdApiException {
|
||||
//调用接口字段补全
|
||||
OperateLogRecordEntity record = fieldFill(operateLogReq);
|
||||
//落库
|
||||
@ -216,7 +217,7 @@ public class OperateLogServiceImpl extends BaseEsService implements OperateLogSe
|
||||
return DateUtil.format(currDate, DatePattern.PURE_DATE_PATTERN);
|
||||
}
|
||||
|
||||
private OperateLogRecordEntity fieldFill(OperateLogReqDTO req) {
|
||||
public OperateLogRecordEntity fieldFill(OperateLogReqDTO req) throws ThirdApiException {
|
||||
//补充 termimnal identityType featureName.
|
||||
OperateLogRecordEntity unifiedLogRecord = operateLogConverter.toEntity(req);
|
||||
//判断是否已经传手机和姓名存在,如果不存在则(通过接口调用,获取用户手机姓名)
|
||||
@ -342,13 +343,13 @@ public class OperateLogServiceImpl extends BaseEsService implements OperateLogSe
|
||||
* @param workspaceId
|
||||
* @return
|
||||
*/
|
||||
private GetDetailRes qryWorkspaceInfo(Long workspaceId) {
|
||||
private GetDetailRes qryWorkspaceInfo(Long workspaceId) throws ThirdApiException {
|
||||
GetDetailReq getDetailReq = new GetDetailReq();
|
||||
getDetailReq.setId(workspaceId);
|
||||
Result<GetDetailRes> res = workspaceApi.getDetail(getDetailReq);
|
||||
if (res.getCode() != 200) {
|
||||
logger.error("query workspace with wsId failed,wsId={},errMsg={}.", workspaceId, res.getMsg());
|
||||
throw new ServiceException(res.getMsg());
|
||||
logger.warn("query workspace with wsId failed,wsId={},errMsg={}.", workspaceId, res.getMsg());
|
||||
throw new ThirdApiException(res.getMsg());
|
||||
}
|
||||
return res.getData();
|
||||
}
|
||||
@ -358,10 +359,10 @@ public class OperateLogServiceImpl extends BaseEsService implements OperateLogSe
|
||||
* @param ouId
|
||||
* @return
|
||||
*/
|
||||
private OrganizationalUnitVO qryOrgUnitInf(Long ouId) {
|
||||
private OrganizationalUnitVO qryOrgUnitInf(Long ouId) throws ThirdApiException {
|
||||
CommonResponse<OrganizationalUnitVO> response = organizationalUnitApi.getById(ouId);
|
||||
if (response.getCode() != 200) {
|
||||
throw new ServiceException(response.getMsg());
|
||||
throw new ThirdApiException(response.getMsg());
|
||||
}
|
||||
return response.getData();
|
||||
}
|
||||
@ -373,21 +374,19 @@ public class OperateLogServiceImpl extends BaseEsService implements OperateLogSe
|
||||
* @param identityType
|
||||
* @return
|
||||
*/
|
||||
private IdentityProfileDto qryIdentityProfile(Long identityId, Integer identityType) {
|
||||
//todo 需要根据类型判断用那个接口查询,先写死
|
||||
if (identityType == 5) {
|
||||
|
||||
private IdentityProfileDto qryIdentityProfile(Long identityId, Integer identityType) throws ThirdApiException {
|
||||
if (identityId == null || identityType == null) {
|
||||
throw new ThirdApiException("illegal params,identityId or identityType is null");
|
||||
}
|
||||
|
||||
List<Long> ids = new ArrayList<>();
|
||||
ids.add(identityId);
|
||||
CommonResponse<List<IdentityProfileDto>> response = profileServiceApi.getIdentitiesByIdSet(ids, identityType);
|
||||
if (response.getCode() != 200) {
|
||||
throw new ServiceException(response.getMsg());
|
||||
throw new ThirdApiException(response.getMsg());
|
||||
}
|
||||
List<IdentityProfileDto> profileList = response.getData();
|
||||
if (profileList == null || profileList.isEmpty()) {
|
||||
throw new ServiceException(String.format("can not get identity profile,identityId=%s,identityType=%s", identityId, identityType));
|
||||
throw new ThirdApiException(String.format("can not get identity profile,identityId=%s,identityType=%s", identityId, identityType));
|
||||
}
|
||||
return profileList.get(0);
|
||||
}
|
||||
|
||||
@ -0,0 +1,56 @@
|
||||
package cn.axzo.log.platform.server.utils;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonInclude;
|
||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||
import com.fasterxml.jackson.databind.DeserializationFeature;
|
||||
import com.fasterxml.jackson.databind.MapperFeature;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.fasterxml.jackson.databind.SerializationFeature;
|
||||
|
||||
/***
|
||||
* @author: pepsi
|
||||
* @description: 单例的 ObjectMapper
|
||||
* @date: 2022/10/30
|
||||
*/
|
||||
public class JacksonCodecUtil {
|
||||
|
||||
private static final ObjectMapper mapper;
|
||||
|
||||
static {
|
||||
//创建ObjectMapper对象
|
||||
mapper = new ObjectMapper();
|
||||
|
||||
//configure方法 配置一些需要的参数
|
||||
mapper.enable(SerializationFeature.INDENT_OUTPUT);
|
||||
|
||||
//序列化的时候序列对象的那些属性
|
||||
//JsonInclude.Include.NON_DEFAULT 属性为默认值不序列化
|
||||
//JsonInclude.Include.ALWAYS 所有属性
|
||||
//JsonInclude.Include.NON_EMPTY 属性为 空(“”) 或者为 NULL 都不序列化
|
||||
//JsonInclude.Include.NON_NULL 属性为NULL 不序列化
|
||||
mapper.setSerializationInclusion(JsonInclude.Include.ALWAYS);
|
||||
|
||||
//反序列化时,遇到未知属性会不会报错
|
||||
//true - 遇到没有的属性就报错 false - 没有的属性不会管,不会报错
|
||||
mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
|
||||
|
||||
//如果是空对象的时候,不抛异常
|
||||
mapper.configure(SerializationFeature.FAIL_ON_EMPTY_BEANS, false);
|
||||
|
||||
// 忽略 transient 修饰的属性
|
||||
mapper.configure(MapperFeature.PROPAGATE_TRANSIENT_MARKER, true);
|
||||
|
||||
}
|
||||
|
||||
public static ObjectMapper getObjectMapper() {
|
||||
return mapper;
|
||||
}
|
||||
|
||||
public static <T> T readValue(String content, Class<T> clazz) throws JsonProcessingException {
|
||||
return mapper.readValue(content, clazz);
|
||||
}
|
||||
|
||||
public static String writeValueAsString(Object val) throws JsonProcessingException {
|
||||
return mapper.writeValueAsString(val);
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,28 @@
|
||||
package cn.axzo.log.platform.server.utils;
|
||||
|
||||
import org.springframework.util.DigestUtils;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
/***
|
||||
* @author: pepsi
|
||||
* @description: TODO
|
||||
* @date: 2022/10/31
|
||||
*/
|
||||
public class SignUtil {
|
||||
|
||||
public static String signParamsMd5(Map<String, String> paramsMap) {
|
||||
StringBuilder stringBuilder = new StringBuilder(150);
|
||||
for (Map.Entry<String, String> entry : paramsMap.entrySet()) {
|
||||
if (StringUtils.hasText(entry.getValue())) {
|
||||
stringBuilder.append(entry.getKey()).append("=").append(entry.getValue()).append("&");
|
||||
}
|
||||
}
|
||||
String paramsStr = stringBuilder.toString();
|
||||
if (StringUtils.hasText(paramsStr)) {
|
||||
paramsStr = paramsStr.substring(0, paramsStr.length() - 1);
|
||||
}
|
||||
return DigestUtils.md5DigestAsHex(paramsStr.getBytes());
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,51 @@
|
||||
package cn.axzo.log.platform.server.service;
|
||||
|
||||
import cn.axzo.log.platform.server.utils.SignUtil;
|
||||
import cn.hutool.core.codec.Base64;
|
||||
import cn.hutool.crypto.SecureUtil;
|
||||
import cn.hutool.crypto.digest.DigestAlgorithm;
|
||||
import cn.hutool.crypto.digest.Digester;
|
||||
import cn.hutool.crypto.symmetric.AES;
|
||||
|
||||
import java.util.LinkedHashMap;
|
||||
|
||||
/***
|
||||
* @author: pepsi
|
||||
* @description: TODO
|
||||
* @date: 2022/10/29
|
||||
*/
|
||||
public class AESServiceTest {
|
||||
private static final String BASE64_SECRET = "aEsva0zDHECg47P8SuPzmw==";
|
||||
|
||||
private final static byte[] SECRET_BYTES = Base64.decode(BASE64_SECRET);
|
||||
|
||||
private final static AES aes = SecureUtil.aes(SECRET_BYTES);
|
||||
|
||||
|
||||
// @Test
|
||||
public static void testMD5() {
|
||||
Digester md5 = new Digester(DigestAlgorithm.MD5);
|
||||
String digestHex = md5.digestHex("{\"@timestamp\":\"2022-10-28T18:10:39.179+08:00\",\"app\":\"leaf\",\"level\":\"INFO\",\"traceId\":\"\",\"thread\":\"Thread-IdRule-Update\",\"class\":\"c.a.l.m.impl.IdRuleCacheManagerImpl\",\"message\":\"refresh end! id rule config : {\\\"payment@payment_no\\\":{\\\"bizCode\\\":\\\"001\\\",\\\"bizTag\\\":\\\"payment@payment_no\\\",\\\"createAt\\\":1626147684000,\\\"dateFormat\\\":\\\"yyyyMMddHHmmss\\\",\\\"isDelete\\\":0,\\\"placeholder\\\":\\\"0000\\\",\\\"remark\\\":\\\"支付系统支付单号生成规则\\\",\\\"ruleExpression\\\":\\\"${dateFormat}${bizCode}${placeholder}${sequenceNo}\\\",\\\"sequenceLength\\\":11,\\\"updateAt\\\":1626147684000},\\\"payment@refund_order_no\\\":{\\\"bizCode\\\":\\\"002\\\",\\\"bizTag\\\":\\\"payment@refund_order_no\\\",\\\"createAt\\\":1632985337000,\\\"dateFormat\\\":\\\"yyyyMMddHHmmss\\\",\\\"isDelete\\\":0,\\\"placeholder\\\":\\\"0000\\\",\\\"remark\\\":\\\"支付系统退款单号生成规则\\\",\\\"ruleExpression\\\":\\\"${dateFormat}${bizCode}${placeholder}${sequenceNo}\\\",\\\"sequenceLength\\\":11,\\\"updateAt\\\":1632985337000}}\",\"m\":null,\"error_level\":\"\",\"error_type\":\"\",\"stack_trace\":\"\"}");
|
||||
System.out.println(digestHex);
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
// testMD5();
|
||||
LinkedHashMap<String, String> allParams = new LinkedHashMap<>();
|
||||
allParams.put("serviceName", "panel_facelog");
|
||||
allParams.put("operateTime", "1667211066490");
|
||||
allParams.put("secretKey", "aEsva0zDHECg47P8SuPzmw==");
|
||||
System.out.println(SignUtil.signParamsMd5(allParams));
|
||||
}
|
||||
|
||||
public static void testSign() {
|
||||
LinkedHashMap<String, Object> allParams = new LinkedHashMap<>();
|
||||
allParams.put("serviceName", "panel_facelog");
|
||||
allParams.put("operateTime", "1667138755891");
|
||||
allParams.put("secretKey", "aEsva0zDHECg47P8SuPzmw==");
|
||||
|
||||
// String sign = SignUtil.signParams(DigestAlgorithm.MD5, allParams, "&", "=", true);
|
||||
// System.out.println(sign);
|
||||
}
|
||||
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user