add webapi接口及加解密处理
This commit is contained in:
parent
66271877da
commit
2a99cc9514
@ -143,6 +143,14 @@
|
||||
<artifactId>axzo-logger-spring-boot-starter</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>cn.axzo.trade</groupId>
|
||||
<artifactId>trade-data-security-spring-boot-starter</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>cn.axzo.trade</groupId>
|
||||
<artifactId>trade-data-security-sd-extension</artifactId>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
|
||||
@ -1,9 +1,9 @@
|
||||
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.axzo.log.platform.server.service.corrector.OperateLogCorrector;
|
||||
import cn.azxo.framework.common.model.CommonPageResponse;
|
||||
import cn.azxo.framework.common.model.CommonResponse;
|
||||
import com.github.xiaoymin.knife4j.annotations.ApiSupport;
|
||||
@ -28,7 +28,7 @@ import javax.validation.Valid;
|
||||
* @description: TODO
|
||||
* @date: 2022/9/16
|
||||
*/
|
||||
@Api(tags = "web-操作日志接口")
|
||||
@Api(tags = "操作日志接口")
|
||||
@ApiSupport(author = "田立勇")
|
||||
@RestController
|
||||
@RequestMapping("/api/v1")
|
||||
@ -39,6 +39,9 @@ public class OperateLogController {
|
||||
@Resource
|
||||
private OperateLogService operateLogService;
|
||||
|
||||
@Resource
|
||||
private OperateLogCorrector operateLogCorrector;
|
||||
|
||||
@Value("${request.param.from.header:true}")
|
||||
private boolean requestParamFromHeader;
|
||||
|
||||
@ -72,7 +75,8 @@ public class OperateLogController {
|
||||
try {
|
||||
String ouTypeStr = request.getHeader("ouType");
|
||||
if (StringUtils.hasText(ouTypeStr)) {
|
||||
handleRequestHeaderParam(Integer.parseInt(ouTypeStr), req, request);
|
||||
//数据矫正
|
||||
operateLogCorrector.correct(Integer.parseInt(ouTypeStr), req, request);
|
||||
}
|
||||
CommonPageResponse<OperateLogQueryRespDTO> resp = operateLogService.queryBasicInfoForPage(req);
|
||||
return CommonResponse.success(resp);
|
||||
@ -84,42 +88,6 @@ public class OperateLogController {
|
||||
}
|
||||
}
|
||||
|
||||
/***
|
||||
* 20221022 定制,根据ouType判断,
|
||||
* 总包(ouType=1)的时候从header获取 workspaceId进行查询,分包(2\3\4\5)从header workspaceId+ouId查询。
|
||||
* 当请求体中存在值时 则不从请求头中获取值进行替换
|
||||
* @param ouType
|
||||
* @param req
|
||||
* @param 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 IllegalArgumentException("can not find workspaceId from header");
|
||||
}
|
||||
if ((req.getWorkspaceId() == null || req.getWorkspaceId() == 0)) {
|
||||
req.setWorkspaceId(Long.valueOf(workspaceId));
|
||||
logger.info("total package, get workspaceId param from request header,workspaceId={},ouType={}.", workspaceId, ouType);
|
||||
}
|
||||
} else if (OuTypeEnums.isSubcontracting(ouType)) {
|
||||
if (!StringUtils.hasText(ouId) || !StringUtils.hasText(workspaceId)) {
|
||||
throw new IllegalArgumentException("can not find workspaceId or ouId from header");
|
||||
}
|
||||
if ((req.getOuId() == null || req.getOuId() == 0)) {
|
||||
req.setOuId(Long.valueOf(ouId));
|
||||
logger.info("sub package,get ouId param from request header,ouId={},ouType={}.", ouId, ouType);
|
||||
}
|
||||
if ((req.getWorkspaceId() == null || req.getWorkspaceId() == 0)) {
|
||||
req.setWorkspaceId(Long.valueOf(workspaceId));
|
||||
logger.info("sub package,get workspaceId param from request header,workspaceId={}.", workspaceId);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@RequestMapping(value = "/operateLog/queryDetailForPage", method = RequestMethod.POST)
|
||||
@ApiOperation(value = "操作日志分页查询(详情列表)")
|
||||
public CommonResponse<CommonPageResponse<OperateLogQueryDetailRespDTO>> operateLogsQueryDetail(@RequestBody @Valid OperateLogQueryReqDTO req,
|
||||
|
||||
@ -0,0 +1,75 @@
|
||||
package cn.axzo.log.platform.server.controller.web;
|
||||
|
||||
import cn.axzo.log.platform.server.dto.OperateLogQueryReqDTO;
|
||||
import cn.axzo.log.platform.server.dto.OperateLogQueryRespDTO;
|
||||
import cn.axzo.log.platform.server.dto.OperateLogReqDTO;
|
||||
import cn.axzo.log.platform.server.exception.ThirdApiException;
|
||||
import cn.axzo.log.platform.server.service.OperateLogService;
|
||||
import cn.axzo.log.platform.server.service.corrector.OperateLogCorrector;
|
||||
import cn.azxo.framework.common.model.CommonPageResponse;
|
||||
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 lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.util.StringUtils;
|
||||
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.annotation.Resource;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.validation.Valid;
|
||||
|
||||
/**
|
||||
* @Author: liyong.tian
|
||||
* @Date: 2022/12/6 17:33
|
||||
* @Description: web端调用接口
|
||||
*/
|
||||
@Api(tags = "web-操作日志接口")
|
||||
@ApiSupport(author = "田立勇")
|
||||
@Slf4j
|
||||
@RestController
|
||||
@RequestMapping("/webapi/v1")
|
||||
public class WebOperateLogController {
|
||||
|
||||
@Resource
|
||||
private OperateLogService operateLogService;
|
||||
|
||||
@Resource
|
||||
private OperateLogCorrector operateLogCorrector;
|
||||
|
||||
@RequestMapping(value = "/operateLog/create", method = RequestMethod.POST)
|
||||
@ApiOperation(value = "操作日志创建")
|
||||
public CommonResponse<Boolean> operateLogCreate(@RequestBody @Valid OperateLogReqDTO req) {
|
||||
try {
|
||||
return CommonResponse.success(operateLogService.insertOperaLog(req));
|
||||
} catch (ThirdApiException apiException) {
|
||||
return CommonResponse.fail(apiException.getMessage());
|
||||
} catch (Exception e) {
|
||||
log.error("create operate log failed.", e);
|
||||
return CommonResponse.fail(e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
@RequestMapping(value = "/operateLog/queryForPage", method = RequestMethod.POST)
|
||||
@ApiOperation(value = "操作日志分页查询")
|
||||
public CommonResponse<CommonPageResponse<OperateLogQueryRespDTO>> operateLogsQuery(@RequestBody @Valid OperateLogQueryReqDTO req,
|
||||
HttpServletRequest request) {
|
||||
try {
|
||||
String ouTypeStr = request.getHeader("ouType");
|
||||
if (StringUtils.hasText(ouTypeStr)) {
|
||||
//数据矫正
|
||||
operateLogCorrector.correct(Integer.parseInt(ouTypeStr), req, request);
|
||||
}
|
||||
CommonPageResponse<OperateLogQueryRespDTO> resp = operateLogService.queryBasicInfoForPage(req);
|
||||
return CommonResponse.success(resp);
|
||||
} catch (IllegalArgumentException argumentException) {
|
||||
return CommonResponse.fail(argumentException.getMessage());
|
||||
} catch (Exception e) {
|
||||
log.error("query operate logs failed,", e);
|
||||
return CommonResponse.fail(e.getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -90,4 +90,8 @@ public class OperateLogQueryReqDTO extends PageRequest {
|
||||
*/
|
||||
@ApiModelProperty(value = "操作表名", position = 12)
|
||||
private String operateTable;
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
}
|
||||
|
||||
@ -1,5 +1,6 @@
|
||||
package cn.axzo.log.platform.server.dto;
|
||||
|
||||
import cn.axzo.trade.datasecurity.sd.extension.annotation.SDCellPhoneField;
|
||||
import com.fasterxml.jackson.annotation.JsonFormat;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import lombok.Data;
|
||||
@ -55,6 +56,7 @@ public class OperateLogQueryRespDTO {
|
||||
* 操作人手机号
|
||||
*/
|
||||
@ApiModelProperty(value = "操作人手机号", position = 6)
|
||||
@SDCellPhoneField
|
||||
private String operateUserPhone;
|
||||
|
||||
/**
|
||||
|
||||
@ -1,5 +1,6 @@
|
||||
package cn.axzo.log.platform.server.entity;
|
||||
|
||||
import cn.axzo.trade.datasecurity.core.annotation.CryptField;
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.Getter;
|
||||
@ -63,6 +64,7 @@ public class OperateLogRecordEntity extends BaseEntity<OperateLogRecordEntity> {
|
||||
/**
|
||||
* 操作人手机号
|
||||
*/
|
||||
@CryptField
|
||||
private String identityUserPhone;
|
||||
|
||||
/**
|
||||
|
||||
@ -0,0 +1,52 @@
|
||||
package cn.axzo.log.platform.server.service.corrector;
|
||||
|
||||
import cn.axzo.log.platform.server.dto.OperateLogQueryReqDTO;
|
||||
import cn.axzo.log.platform.server.enums.OuTypeEnums;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.stereotype.Component;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
|
||||
/**
|
||||
* @Author: liyong.tian
|
||||
* @Date: 2022/12/6 17:43
|
||||
* @Description:
|
||||
*/
|
||||
@Slf4j
|
||||
@Component
|
||||
@RequiredArgsConstructor
|
||||
public class OperateLogCorrector {
|
||||
|
||||
/***
|
||||
* 20221022 定制,根据ouType判断,
|
||||
* 总包(ouType=1)的时候从header获取 workspaceId进行查询,分包(2\3\4\5)从header workspaceId+ouId查询。
|
||||
* 当请求体中存在值时 则不从请求头中获取值进行替换
|
||||
*/
|
||||
public void correct(int ouType, OperateLogQueryReqDTO dto, HttpServletRequest request) {
|
||||
String ouId = request.getHeader("ouId");
|
||||
String workspaceId = request.getHeader("workspaceId");
|
||||
if (OuTypeEnums.isPrimaryContractinUnit(ouType)) {
|
||||
if (!StringUtils.hasText(workspaceId)) {
|
||||
throw new IllegalArgumentException("can not find workspaceId from header");
|
||||
}
|
||||
if ((dto.getWorkspaceId() == null || dto.getWorkspaceId() == 0)) {
|
||||
dto.setWorkspaceId(Long.valueOf(workspaceId));
|
||||
log.info("total package, get workspaceId param from request header,workspaceId={},ouType={}.", workspaceId, ouType);
|
||||
}
|
||||
} else if (OuTypeEnums.isSubcontracting(ouType)) {
|
||||
if (!StringUtils.hasText(ouId) || !StringUtils.hasText(workspaceId)) {
|
||||
throw new IllegalArgumentException("can not find workspaceId or ouId from header");
|
||||
}
|
||||
if ((dto.getOuId() == null || dto.getOuId() == 0)) {
|
||||
dto.setOuId(Long.valueOf(ouId));
|
||||
log.info("sub package,get ouId param from request header,ouId={},ouType={}.", ouId, ouType);
|
||||
}
|
||||
if ((dto.getWorkspaceId() == null || dto.getWorkspaceId() == 0)) {
|
||||
dto.setWorkspaceId(Long.valueOf(workspaceId));
|
||||
log.info("sub package,get workspaceId param from request header,workspaceId={}.", workspaceId);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -35,4 +35,11 @@ mybatis-plus:
|
||||
id-type: auto
|
||||
logic-delete-value: 1 #逻辑已删除值(默认为 1)
|
||||
logic-not-delete-value: 0 #逻辑未删除值(默认为 0)
|
||||
logic-delete-field: is_delete #逻辑删除字段
|
||||
logic-delete-field: is_delete #逻辑删除字段
|
||||
|
||||
trade:
|
||||
data-security:
|
||||
desensitization:
|
||||
enabled: true #开启全局脱敏
|
||||
crypt:
|
||||
enable: true #开启全局加解密
|
||||
Loading…
Reference in New Issue
Block a user