Merge remote-tracking branch 'origin/dev' into feature/join_elk/221031

This commit is contained in:
pepsi 2022-10-31 10:59:40 +08:00
commit 628ec3ca95
5 changed files with 42 additions and 27 deletions

View File

@ -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());
}
}

View File

@ -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);
}
}

View File

@ -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());
}
}

View File

@ -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;
/**
* 分页查询 返回基本字段

View File

@ -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);
}