【新增】接口操作,登录,登出日志
This commit is contained in:
@@ -0,0 +1,18 @@
|
||||
package com.corewing.app.common.annotation;
|
||||
|
||||
import java.lang.annotation.*;
|
||||
|
||||
/**
|
||||
* 自定义日志注解
|
||||
*
|
||||
**/
|
||||
@Target(ElementType.METHOD)
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
@Documented
|
||||
public @interface CommonLog {
|
||||
|
||||
/**
|
||||
* 日志的名称,例如:"修改菜单"
|
||||
*/
|
||||
String value() default "未命名";
|
||||
}
|
||||
104
src/main/java/com/corewing/app/common/aspect/DevLogAop.java
Normal file
104
src/main/java/com/corewing/app/common/aspect/DevLogAop.java
Normal file
@@ -0,0 +1,104 @@
|
||||
|
||||
package com.corewing.app.common.aspect;
|
||||
|
||||
import cn.dev33.satoken.stp.StpUtil;
|
||||
import cn.hutool.json.JSONUtil;
|
||||
import com.corewing.app.common.annotation.CommonLog;
|
||||
import com.corewing.app.entity.User;
|
||||
import com.corewing.app.service.UserService;
|
||||
import com.corewing.app.util.DevLogUtil;
|
||||
import com.corewing.app.util.RedisUtil;
|
||||
import org.aspectj.lang.JoinPoint;
|
||||
import org.aspectj.lang.annotation.AfterReturning;
|
||||
import org.aspectj.lang.annotation.AfterThrowing;
|
||||
import org.aspectj.lang.annotation.Aspect;
|
||||
import org.aspectj.lang.annotation.Pointcut;
|
||||
import org.aspectj.lang.reflect.MethodSignature;
|
||||
import org.springframework.core.annotation.Order;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.lang.reflect.Method;
|
||||
|
||||
/**
|
||||
* 业务日志aop切面
|
||||
*
|
||||
*/
|
||||
@Aspect
|
||||
@Order
|
||||
@Component
|
||||
public class DevLogAop {
|
||||
|
||||
|
||||
@Resource
|
||||
private RedisUtil redisUtil;
|
||||
|
||||
@Resource
|
||||
private UserService userService;
|
||||
|
||||
/**
|
||||
* 日志切入点
|
||||
*
|
||||
* @author xuyuxiang
|
||||
* @date 2020/3/23 17:10
|
||||
*/
|
||||
@Pointcut("@annotation(com.corewing.app.common.annotation.CommonLog)")
|
||||
private void getLogPointCut() {
|
||||
}
|
||||
|
||||
/**
|
||||
* 操作成功返回结果记录日志
|
||||
*
|
||||
*/
|
||||
@AfterReturning(pointcut = "getLogPointCut()", returning = "result")
|
||||
public void doAfterReturning(JoinPoint joinPoint, Object result) {
|
||||
MethodSignature methodSignature = (MethodSignature) joinPoint.getSignature();
|
||||
Method method = methodSignature.getMethod();
|
||||
CommonLog commonLog = method.getAnnotation(CommonLog.class);
|
||||
String userName = "未知";
|
||||
String userId = "-1";
|
||||
try {
|
||||
try {
|
||||
if( StpUtil.isLogin()) {
|
||||
User user = (User) redisUtil.get("APP_" + StpUtil.getLoginId());
|
||||
userName = user.getUsername();
|
||||
userId = user.getId().toString();
|
||||
}
|
||||
} catch (Exception e) {
|
||||
User user = userService.getById(StpUtil.getLoginIdAsLong());
|
||||
userName = user.getUsername();
|
||||
userId = user.getId().toString();
|
||||
}
|
||||
} catch (Exception ignored) {
|
||||
}
|
||||
// 异步记录日志
|
||||
DevLogUtil.executeOperationLog(commonLog, userName, userId, joinPoint, JSONUtil.toJsonStr(result));
|
||||
}
|
||||
|
||||
/**
|
||||
* 操作发生异常记录日志
|
||||
*
|
||||
*/
|
||||
@AfterThrowing(pointcut = "getLogPointCut()", throwing = "exception")
|
||||
public void doAfterThrowing(JoinPoint joinPoint, Exception exception) {
|
||||
MethodSignature methodSignature = (MethodSignature) joinPoint.getSignature();
|
||||
Method method = methodSignature.getMethod();
|
||||
CommonLog commonLog = method.getAnnotation(CommonLog.class);
|
||||
String userName = "未知";
|
||||
String userId = "-1";
|
||||
try {
|
||||
if( StpUtil.isLogin()) {
|
||||
User user = (User) redisUtil.get("APP_" + StpUtil.getLoginId());
|
||||
userName = user.getUsername();
|
||||
userId = user.getId().toString();
|
||||
}
|
||||
} catch (Exception e) {
|
||||
User user = userService.getById(StpUtil.getLoginIdAsLong());
|
||||
userName = user.getUsername();
|
||||
userId = user.getId().toString();
|
||||
}
|
||||
//异步记录日志
|
||||
DevLogUtil.executeExceptionLog(commonLog, userName, userId, joinPoint, exception);
|
||||
}
|
||||
}
|
||||
89
src/main/java/com/corewing/app/entity/DevLog.java
Normal file
89
src/main/java/com/corewing/app/entity/DevLog.java
Normal file
@@ -0,0 +1,89 @@
|
||||
package com.corewing.app.entity;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.FieldFill;
|
||||
import com.baomidou.mybatisplus.annotation.TableField;
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
/**
|
||||
* 日志实体
|
||||
*
|
||||
*/
|
||||
@Getter
|
||||
@Setter
|
||||
@TableName("DEV_LOG")
|
||||
public class DevLog {
|
||||
|
||||
/** id */
|
||||
private String id;
|
||||
|
||||
/** 日志分类 */
|
||||
private String category;
|
||||
|
||||
/** 日志名称 */
|
||||
private String name;
|
||||
|
||||
/** 执行状态 */
|
||||
private String exeStatus;
|
||||
|
||||
/** 具体消息 */
|
||||
private String exeMessage;
|
||||
|
||||
/** 操作ip */
|
||||
private String opIp;
|
||||
|
||||
/** 操作地址 */
|
||||
private String opAddress;
|
||||
|
||||
/** 操作浏览器 */
|
||||
private String opBrowser;
|
||||
|
||||
/** 操作系统 */
|
||||
private String opOs;
|
||||
|
||||
/** 类名称 */
|
||||
private String className;
|
||||
|
||||
/** 方法名称 */
|
||||
private String methodName;
|
||||
|
||||
/** 请求方式 */
|
||||
private String reqMethod;
|
||||
|
||||
/** 请求地址 */
|
||||
private String reqUrl;
|
||||
|
||||
/** 请求参数 */
|
||||
private String paramJson;
|
||||
|
||||
/** 返回结果 */
|
||||
private String resultJson;
|
||||
|
||||
/** 操作时间 */
|
||||
private Date opTime;
|
||||
|
||||
/** 操作人姓名 */
|
||||
private String opUser;
|
||||
|
||||
/** 签名数据 */
|
||||
private String signData;
|
||||
|
||||
/** 创建时间 */
|
||||
@TableField(fill = FieldFill.INSERT)
|
||||
private Date createTime;
|
||||
|
||||
/** 创建人 */
|
||||
@TableField(fill = FieldFill.INSERT)
|
||||
private String createUser;
|
||||
|
||||
/** 更新时间 */
|
||||
@TableField(fill = FieldFill.UPDATE)
|
||||
private Date updateTime;
|
||||
|
||||
/** 更新人 */
|
||||
@TableField(fill = FieldFill.UPDATE)
|
||||
private String updateUser;
|
||||
}
|
||||
29
src/main/java/com/corewing/app/enums/DevLogCategoryEnum.java
Normal file
29
src/main/java/com/corewing/app/enums/DevLogCategoryEnum.java
Normal file
@@ -0,0 +1,29 @@
|
||||
package com.corewing.app.enums;
|
||||
|
||||
import lombok.Getter;
|
||||
|
||||
/**
|
||||
* 日志分类枚举
|
||||
*
|
||||
**/
|
||||
@Getter
|
||||
public enum DevLogCategoryEnum {
|
||||
|
||||
/** APP操作日志 */
|
||||
APP_OPERATE("APP_OPERATE"),
|
||||
|
||||
/** APP异常日志 */
|
||||
APP_EXCEPTION("APP_EXCEPTION"),
|
||||
|
||||
/** APP登录日志 */
|
||||
APP_LOGIN("APP_LOGIN"),
|
||||
|
||||
/** APP登出日志 */
|
||||
APP_LOGOUT("APP_LOGOUT");
|
||||
|
||||
private final String value;
|
||||
|
||||
DevLogCategoryEnum(String value) {
|
||||
this.value = value;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
package com.corewing.app.enums;
|
||||
|
||||
import lombok.Getter;
|
||||
|
||||
@Getter
|
||||
public enum DevLogExeStatusEnum {
|
||||
|
||||
/** 成功 */
|
||||
SUCCESS("SUCCESS"),
|
||||
|
||||
/** 失败 */
|
||||
FAIL("FAIL");
|
||||
|
||||
private final String value;
|
||||
|
||||
DevLogExeStatusEnum(String value) {
|
||||
this.value = value;
|
||||
}
|
||||
}
|
||||
11
src/main/java/com/corewing/app/mapper/DevLogMapper.java
Normal file
11
src/main/java/com/corewing/app/mapper/DevLogMapper.java
Normal file
@@ -0,0 +1,11 @@
|
||||
|
||||
package com.corewing.app.mapper;
|
||||
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import com.corewing.app.entity.DevLog;
|
||||
|
||||
/**
|
||||
* 日志Mapper接口
|
||||
**/
|
||||
public interface DevLogMapper extends BaseMapper<DevLog> {
|
||||
}
|
||||
@@ -1,6 +1,7 @@
|
||||
package com.corewing.app.modules.app;
|
||||
|
||||
import com.corewing.app.common.Result;
|
||||
import com.corewing.app.common.annotation.CommonLog;
|
||||
import com.corewing.app.entity.ContactMsg;
|
||||
import com.corewing.app.service.ContactMsgService;
|
||||
import io.swagger.annotations.Api;
|
||||
@@ -20,6 +21,7 @@ public class AppContactMsgController {
|
||||
@Resource
|
||||
private ContactMsgService contactMsgService;
|
||||
|
||||
@CommonLog("反馈消息")
|
||||
@ApiOperation("消息保存接口")
|
||||
@PostMapping("/save")
|
||||
public Result<String> save(@RequestBody ContactMsg contactMsg) {
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package com.corewing.app.modules.app;
|
||||
|
||||
import com.corewing.app.common.Result;
|
||||
import com.corewing.app.common.annotation.CommonLog;
|
||||
import com.corewing.app.dto.DeviceActivationRequest;
|
||||
import com.corewing.app.service.BizDeviceActivationService;
|
||||
import io.swagger.annotations.Api;
|
||||
@@ -23,6 +24,7 @@ public class AppDeviceController {
|
||||
@Resource
|
||||
private BizDeviceActivationService activationService;
|
||||
|
||||
@CommonLog("激活设备")
|
||||
@ApiOperation("激活接口")
|
||||
@PostMapping("activation")
|
||||
public Result<Boolean> activation(@RequestBody DeviceActivationRequest deviceActivationRequest) {
|
||||
|
||||
@@ -4,6 +4,7 @@ import cn.dev33.satoken.stp.StpUtil;
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.corewing.app.common.Result;
|
||||
import com.corewing.app.common.annotation.CommonLog;
|
||||
import com.corewing.app.dto.FeedbackRequest;
|
||||
import com.corewing.app.entity.Feedback;
|
||||
import com.corewing.app.service.FeedbackService;
|
||||
@@ -39,6 +40,7 @@ public class AppFeedbackController {
|
||||
/**
|
||||
* 创建反馈(支持匿名提交)
|
||||
*/
|
||||
@CommonLog("创建反馈")
|
||||
@ApiOperation("创建反馈")
|
||||
@PostMapping
|
||||
public Result<String> create(@RequestBody FeedbackRequest request, HttpServletRequest httpRequest) {
|
||||
@@ -81,6 +83,7 @@ public class AppFeedbackController {
|
||||
/**
|
||||
* 查询当前用户的反馈列表
|
||||
*/
|
||||
@CommonLog("查询反馈列表")
|
||||
@ApiOperation("查询当前用户的反馈列表")
|
||||
@GetMapping("/my")
|
||||
public Result<List<Feedback>> getMyFeedbackList() {
|
||||
@@ -97,6 +100,7 @@ public class AppFeedbackController {
|
||||
/**
|
||||
* 根据ID查询反馈详情
|
||||
*/
|
||||
@CommonLog("查询反馈详情")
|
||||
@ApiOperation("根据id查询反馈详情")
|
||||
@GetMapping("/{id}")
|
||||
public Result<Feedback> getById(@PathVariable Long id) {
|
||||
@@ -120,6 +124,7 @@ public class AppFeedbackController {
|
||||
* @param feedbackType 问题类型(可选)
|
||||
* @param status 状态(可选)
|
||||
*/
|
||||
@CommonLog("查询反馈列表分页")
|
||||
@ApiOperation("分页查询反馈列表")
|
||||
@GetMapping("/page")
|
||||
public Result<IPage<Feedback>> getPageList(
|
||||
@@ -140,6 +145,7 @@ public class AppFeedbackController {
|
||||
/**
|
||||
* 更新反馈状态
|
||||
*/
|
||||
@CommonLog("更新反馈状态")
|
||||
@ApiOperation("更新反馈状态")
|
||||
@PutMapping("/{id}/status")
|
||||
public Result<String> updateStatus(@PathVariable Long id, @RequestParam Integer status) {
|
||||
@@ -157,6 +163,7 @@ public class AppFeedbackController {
|
||||
/**
|
||||
* 删除反馈
|
||||
*/
|
||||
@CommonLog("删除反馈")
|
||||
@ApiOperation("删除反馈")
|
||||
@DeleteMapping("/{id}")
|
||||
public Result<String> delete(@PathVariable Long id) {
|
||||
@@ -174,6 +181,7 @@ public class AppFeedbackController {
|
||||
/**
|
||||
* 测试钉钉推送
|
||||
*/
|
||||
@CommonLog("测试钉钉推送")
|
||||
@ApiOperation("测试钉钉推送")
|
||||
@GetMapping("/test-dingtalk")
|
||||
public Result<String> testDingTalk() {
|
||||
@@ -196,6 +204,7 @@ public class AppFeedbackController {
|
||||
/**
|
||||
* 发送反馈信息到钉钉
|
||||
*/
|
||||
@CommonLog("发送反馈信息到钉钉")
|
||||
@ApiOperation("发送反馈信息到钉钉")
|
||||
private void sendFeedbackToDingTalk(Feedback feedback, String submitIp, String submitRegion) {
|
||||
try {
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package com.corewing.app.modules.app;
|
||||
|
||||
import com.corewing.app.common.Result;
|
||||
import com.corewing.app.common.annotation.CommonLog;
|
||||
import com.corewing.app.entity.FeedbackLog;
|
||||
import com.corewing.app.service.FeedbackLogService;
|
||||
import io.swagger.annotations.Api;
|
||||
@@ -28,6 +29,7 @@ public class AppFeedbackLogController {
|
||||
* @param feedbackLog
|
||||
* @return
|
||||
*/
|
||||
@CommonLog("上传反馈日志")
|
||||
@ApiOperation("上传日志")
|
||||
@PostMapping("/uploadFeedbackLog")
|
||||
public Result<String> uploadFeedbackLog(MultipartFile file, FeedbackLog feedbackLog) {
|
||||
|
||||
@@ -4,6 +4,7 @@ import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.corewing.app.common.Result;
|
||||
import com.corewing.app.common.annotation.CommonLog;
|
||||
import com.corewing.app.entity.Firmware;
|
||||
import com.corewing.app.service.FirmwareService;
|
||||
import com.corewing.app.util.I18nUtil;
|
||||
@@ -29,6 +30,7 @@ public class AppFirmwareController {
|
||||
/**
|
||||
* 根据ID查询固件
|
||||
*/
|
||||
@CommonLog("根据id查询固件")
|
||||
@ApiOperation("根据id查询固件")
|
||||
@GetMapping("/{id}")
|
||||
public Result<Firmware> getById(@PathVariable Long id) {
|
||||
@@ -47,6 +49,7 @@ public class AppFirmwareController {
|
||||
* @param firmwareName 固件名称(可选)
|
||||
* @param firmwareType 固件类型(可选)
|
||||
*/
|
||||
@CommonLog("分页查询固件列表")
|
||||
@ApiOperation("分页查询固件列表")
|
||||
@GetMapping("/page")
|
||||
public Result<IPage<Firmware>> page(
|
||||
@@ -78,6 +81,7 @@ public class AppFirmwareController {
|
||||
/**
|
||||
* 查询所有固件
|
||||
*/
|
||||
@CommonLog("查询所有固件集合")
|
||||
@ApiOperation("查询所有固件集合")
|
||||
@GetMapping("/list")
|
||||
public Result<java.util.List<Firmware>> list() {
|
||||
@@ -90,6 +94,7 @@ public class AppFirmwareController {
|
||||
*
|
||||
* @param firmwareType 固件类型
|
||||
*/
|
||||
@CommonLog("根据类型查询固件版本")
|
||||
@ApiOperation("根据类型查询固件版本")
|
||||
@GetMapping("/type/{firmwareType}")
|
||||
public Result<java.util.List<Firmware>> listByType(@PathVariable Integer firmwareType) {
|
||||
|
||||
@@ -3,6 +3,7 @@ package com.corewing.app.modules.app;
|
||||
import cn.hutool.core.lang.tree.Tree;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.corewing.app.common.Result;
|
||||
import com.corewing.app.common.annotation.CommonLog;
|
||||
import com.corewing.app.dto.AppModel.*;
|
||||
import com.corewing.app.entity.AppModel;
|
||||
import com.corewing.app.entity.AppModelCategory;
|
||||
@@ -37,6 +38,7 @@ public class AppModelController {
|
||||
* @param modelPageRequest
|
||||
* @return
|
||||
*/
|
||||
@CommonLog("模型数据分页")
|
||||
@ApiOperation("模型数据分页")
|
||||
@GetMapping("/page")
|
||||
public Result<Page<AppModel>> page(ModelPageRequest modelPageRequest) {
|
||||
@@ -48,6 +50,7 @@ public class AppModelController {
|
||||
* @param modelListRequest
|
||||
* @return
|
||||
*/
|
||||
@CommonLog("模型数据集合")
|
||||
@ApiOperation("模型数据集合")
|
||||
@GetMapping("/list")
|
||||
public Result<List<AppModel>> list(ModelListRequest modelListRequest) {
|
||||
@@ -60,6 +63,7 @@ public class AppModelController {
|
||||
* @param modelCategoryPageRequest
|
||||
* @return
|
||||
*/
|
||||
@CommonLog("模型分类数据分页")
|
||||
@ApiOperation("模型分类数据分页")
|
||||
@GetMapping("/category/page")
|
||||
public Result<Page<AppModelCategory>> categoryPage(ModelCategoryPageRequest modelCategoryPageRequest) {
|
||||
@@ -71,6 +75,7 @@ public class AppModelController {
|
||||
* @param modelCategoryListRequest
|
||||
* @return
|
||||
*/
|
||||
@CommonLog("模型分类数据集合")
|
||||
@ApiOperation("模型分类数据集合")
|
||||
@GetMapping("/category/list")
|
||||
public Result<List<AppModelCategory>> categoryList(ModelCategoryListRequest modelCategoryListRequest) {
|
||||
@@ -82,6 +87,7 @@ public class AppModelController {
|
||||
* @param modelCategoryListRequest
|
||||
* @return
|
||||
*/
|
||||
@CommonLog("模型分类树形集合")
|
||||
@ApiOperation("模型分类树形集合")
|
||||
@GetMapping("/category/tree")
|
||||
public Result<List<Tree<String>>> categoryTree(ModelCategoryListRequest modelCategoryListRequest) {
|
||||
@@ -93,6 +99,7 @@ public class AppModelController {
|
||||
* @param modelFavoriteRequest
|
||||
* @return
|
||||
*/
|
||||
@CommonLog("收藏模型")
|
||||
@ApiOperation("收藏模型")
|
||||
@PostMapping("/favorite")
|
||||
public Result<String> favorite(@RequestBody @Valid ModelFavoriteRequest modelFavoriteRequest) {
|
||||
@@ -104,6 +111,7 @@ public class AppModelController {
|
||||
* @param modelDownloadRequest
|
||||
* @return
|
||||
*/
|
||||
@CommonLog("增加模型下载记录")
|
||||
@ApiOperation("增加模型下载记录")
|
||||
@PostMapping("/download")
|
||||
public Result<String> download(@RequestBody @Valid ModelDownloadRequest modelDownloadRequest) {
|
||||
@@ -115,6 +123,7 @@ public class AppModelController {
|
||||
* @param modelLikeRequest
|
||||
* @return
|
||||
*/
|
||||
@CommonLog("点赞模型")
|
||||
@ApiOperation("点赞模型")
|
||||
@PostMapping("/like")
|
||||
public Result<String> like(@RequestBody @Valid ModelLikeRequest modelLikeRequest) {
|
||||
@@ -125,6 +134,7 @@ public class AppModelController {
|
||||
* 模型详情
|
||||
* @return
|
||||
*/
|
||||
@CommonLog("模型详情")
|
||||
@ApiOperation("模型详情")
|
||||
@GetMapping("/detail/{modelId}")
|
||||
public Result<AppModel> detail(@PathVariable String modelId) {
|
||||
@@ -136,6 +146,7 @@ public class AppModelController {
|
||||
* @param modelCreateRequest
|
||||
* @return
|
||||
*/
|
||||
@CommonLog("创建模型")
|
||||
@ApiOperation("创建模型")
|
||||
@PostMapping("/create")
|
||||
public Result<String> create(@Valid ModelCreateRequest modelCreateRequest) {
|
||||
@@ -147,6 +158,7 @@ public class AppModelController {
|
||||
* @param modelIdRequest
|
||||
* @return
|
||||
*/
|
||||
@CommonLog("提交模型审核")
|
||||
@ApiOperation("提交模型审核")
|
||||
@PostMapping("/audit")
|
||||
public Result<String> audit(@RequestBody @Valid ModelIdRequest modelIdRequest) {
|
||||
@@ -158,6 +170,7 @@ public class AppModelController {
|
||||
* @param modelFavoriteListRequest
|
||||
* @return
|
||||
*/
|
||||
@CommonLog("收藏模型列表")
|
||||
@ApiOperation("收藏模型列表")
|
||||
@GetMapping("/favorite/list")
|
||||
public Result<List<AppModel>> favoriteList(ModelFavoriteListRequest modelFavoriteListRequest) {
|
||||
@@ -169,7 +182,8 @@ public class AppModelController {
|
||||
* @param modelFavoritePageRequest
|
||||
* @return
|
||||
*/
|
||||
@ApiOperation("收藏模型分页列表")
|
||||
@CommonLog("收藏模型分页列表分页")
|
||||
@ApiOperation("收藏模型分页列表分页")
|
||||
@GetMapping("/favorite/page")
|
||||
public Result<Page<AppModel>> favoritePage(ModelFavoritePageRequest modelFavoritePageRequest) {
|
||||
return Result.success(appModelService.favoritePage(modelFavoritePageRequest));
|
||||
@@ -180,6 +194,7 @@ public class AppModelController {
|
||||
* @param modelIdRequest
|
||||
* @return
|
||||
*/
|
||||
@CommonLog("模型下架")
|
||||
@ApiOperation("模型下架")
|
||||
@PostMapping("/delisted")
|
||||
public Result<String> delisted(@RequestBody @Valid ModelIdRequest modelIdRequest) {
|
||||
@@ -192,6 +207,7 @@ public class AppModelController {
|
||||
* @param modelDownloadLogListRequest
|
||||
* @return
|
||||
*/
|
||||
@CommonLog("模型下载记录列表")
|
||||
@ApiOperation("模型下载记录列表")
|
||||
@GetMapping("/download_log/list")
|
||||
public Result<List<AppModel>> downloadLogList(ModelDownloadLogListRequest modelDownloadLogListRequest) {
|
||||
@@ -203,7 +219,8 @@ public class AppModelController {
|
||||
* @param modelDownloadLogPageRequest
|
||||
* @return
|
||||
*/
|
||||
@ApiOperation("模型下载记录分页列表")
|
||||
@CommonLog("模型下载记录分页列表分页")
|
||||
@ApiOperation("模型下载记录分页列表分页")
|
||||
@GetMapping("/download_log/page")
|
||||
public Result<Page<AppModel>> downloadLogPage(ModelDownloadLogPageRequest modelDownloadLogPageRequest) {
|
||||
return Result.success(appModelService.downloadLogPage(modelDownloadLogPageRequest));
|
||||
@@ -213,6 +230,7 @@ public class AppModelController {
|
||||
* 删除模型
|
||||
* @return
|
||||
*/
|
||||
@CommonLog("删除模型")
|
||||
@ApiOperation("删除模型")
|
||||
@DeleteMapping("/delete/{id}")
|
||||
public Result<String> delete(@PathVariable String id) {
|
||||
|
||||
@@ -4,6 +4,7 @@ import cn.dev33.satoken.stp.StpUtil;
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.corewing.app.common.Result;
|
||||
import com.corewing.app.common.annotation.CommonLog;
|
||||
import com.corewing.app.dto.CreateParamRequest;
|
||||
import com.corewing.app.dto.UpdateParamRequest;
|
||||
import com.corewing.app.entity.ParamsCenter;
|
||||
@@ -37,6 +38,7 @@ public class AppParamsCenterController {
|
||||
/**
|
||||
* 创建参数配置
|
||||
*/
|
||||
@CommonLog("创建参数配置接口")
|
||||
@ApiOperation("创建参数配置接口")
|
||||
@PostMapping
|
||||
public Result<String> create(@Valid @RequestBody CreateParamRequest request) {
|
||||
@@ -69,6 +71,7 @@ public class AppParamsCenterController {
|
||||
/**
|
||||
* 更新参数配置
|
||||
*/
|
||||
@CommonLog("更新参数配置接口")
|
||||
@ApiOperation("更新参数配置接口")
|
||||
@PutMapping
|
||||
public Result<String> update(@Valid @RequestBody UpdateParamRequest request) {
|
||||
@@ -107,6 +110,7 @@ public class AppParamsCenterController {
|
||||
/**
|
||||
* 删除参数配置
|
||||
*/
|
||||
@CommonLog("根据id删除参数配置")
|
||||
@ApiOperation("根据id删除参数配置")
|
||||
@DeleteMapping("/{id}")
|
||||
public Result<String> delete(@PathVariable Long id) {
|
||||
@@ -135,6 +139,7 @@ public class AppParamsCenterController {
|
||||
/**
|
||||
* 根据ID查询参数配置
|
||||
*/
|
||||
@CommonLog("根据id查询参数配置")
|
||||
@ApiOperation("根据id查询参数配置")
|
||||
@GetMapping("/{id}")
|
||||
public Result<ParamsCenterVO> getById(@PathVariable Long id) {
|
||||
@@ -158,6 +163,7 @@ public class AppParamsCenterController {
|
||||
/**
|
||||
* 查询所有公共参数列表(公开接口,支持飞控型号过滤)
|
||||
*/
|
||||
@CommonLog("获取所有公共参数集合")
|
||||
@ApiOperation("获取所有公共参数集合")
|
||||
@GetMapping("/all/list")
|
||||
public Result<List<ParamsCenterVO>> listAll(@RequestParam(required = false) String fcModel) {
|
||||
@@ -172,6 +178,7 @@ public class AppParamsCenterController {
|
||||
/**
|
||||
* 查询当前用户的参数列表(支持飞控型号过滤)
|
||||
*/
|
||||
@CommonLog("获取当前用户的参数列表")
|
||||
@ApiOperation("获取当前用户的参数列表")
|
||||
@GetMapping("/my/list")
|
||||
public Result<List<ParamsCenterVO>> listMy(@RequestParam(required = false) String fcModel) {
|
||||
@@ -187,6 +194,7 @@ public class AppParamsCenterController {
|
||||
/**
|
||||
* 分页查询所有参数列表(公开接口,支持飞控型号过滤)
|
||||
*/
|
||||
@CommonLog("分页查询所有公共参数集合")
|
||||
@ApiOperation("分页查询所有公共参数集合")
|
||||
@GetMapping("/all/page")
|
||||
public Result<IPage<ParamsCenterVO>> pageAll(
|
||||
@@ -205,7 +213,8 @@ public class AppParamsCenterController {
|
||||
/**
|
||||
* 分页查询当前用户的参数列表(支持飞控型号过滤)
|
||||
*/
|
||||
@ApiOperation("分页查询当前用户参数列表")
|
||||
@CommonLog("分页查询当前用户参数列表分页")
|
||||
@ApiOperation("分页查询当前用户参数列表分页")
|
||||
@GetMapping("/my/page")
|
||||
public Result<IPage<ParamsCenterVO>> pageMy(
|
||||
@RequestParam(defaultValue = "1") Long current,
|
||||
@@ -224,6 +233,7 @@ public class AppParamsCenterController {
|
||||
/**
|
||||
* 增加下载次数
|
||||
*/
|
||||
@CommonLog("增加参数中心下载次数")
|
||||
@ApiOperation("增加参数中心下载次数")
|
||||
@PostMapping("/{id}/download")
|
||||
public Result<String> incrementDownloadCount(@PathVariable Long id) {
|
||||
@@ -262,6 +272,7 @@ public class AppParamsCenterController {
|
||||
* @param id
|
||||
* @return
|
||||
*/
|
||||
@CommonLog("发布公共参数提交审核")
|
||||
@ApiOperation("发布公共参数提交审核")
|
||||
@GetMapping("/review/{id}")
|
||||
public Result<String> review(@PathVariable Long id) {
|
||||
|
||||
@@ -2,6 +2,7 @@ package com.corewing.app.modules.app;
|
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.corewing.app.common.Result;
|
||||
import com.corewing.app.common.annotation.CommonLog;
|
||||
import com.corewing.app.entity.PrivacyPolicy;
|
||||
import com.corewing.app.service.PrivacyPolicyService;
|
||||
import io.swagger.annotations.Api;
|
||||
@@ -31,6 +32,7 @@ public class AppPrivacyPolicyController {
|
||||
* 隐私政策列表
|
||||
* @return
|
||||
*/
|
||||
@CommonLog("隐私政策列表")
|
||||
@ApiOperation("隐私政策列表")
|
||||
@GetMapping("/view_list/{lang}")
|
||||
public String viewList(@PathVariable String lang, ModelMap modelMap) {
|
||||
@@ -46,6 +48,7 @@ public class AppPrivacyPolicyController {
|
||||
* @param category
|
||||
* @return
|
||||
*/
|
||||
@CommonLog("根据类型获取集合数据")
|
||||
@ApiOperation("根据类型获取集合数据")
|
||||
@GetMapping("/getListByCategory/{category}")
|
||||
@ResponseBody
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package com.corewing.app.modules.app;
|
||||
|
||||
import com.corewing.app.common.Result;
|
||||
import com.corewing.app.common.annotation.CommonLog;
|
||||
import com.corewing.app.dto.publicFirmware.PublicBoardTypeListRequest;
|
||||
import com.corewing.app.dto.publicFirmware.PublicFirmwareListRequest;
|
||||
import com.corewing.app.dto.publicFirmware.PublicFirmwareVersionListRequest;
|
||||
@@ -33,25 +34,28 @@ public class AppPublicFirmwareController {
|
||||
@Resource
|
||||
private AppPublicFirmwarePlaneService appPublicFirmwarePlaneService;
|
||||
|
||||
|
||||
@CommonLog("获取固件类型集合")
|
||||
@ApiOperation("获取固件类型集合")
|
||||
@GetMapping("/getFirmwareTypeAll")
|
||||
public Result<List<BizDict>> getFirmwareTypeAll() {
|
||||
return Result.success(bizDictService.getDataListByKey());
|
||||
}
|
||||
|
||||
@CommonLog("根据固件类型获取版本集合")
|
||||
@ApiOperation("根据固件类型获取版本集合")
|
||||
@GetMapping("/getVersionList")
|
||||
public Result<List<AppPublicFirmwareVersion>> getVersionList(PublicFirmwareVersionListRequest publicFirmwareVersionListRequest) {
|
||||
return Result.success(appPublicFirmwareVersionService.getVersionList(publicFirmwareVersionListRequest));
|
||||
}
|
||||
|
||||
@CommonLog("根据固件类型&版本获取板载类型集合")
|
||||
@ApiOperation("根据固件类型&版本获取板载类型集合")
|
||||
@GetMapping("/getBoardTypeList")
|
||||
public Result<List<String>> getBoardTypeList(PublicBoardTypeListRequest publicBoardTypeListRequest) {
|
||||
return Result.success(appPublicFirmwarePlaneService.getBoardTypeList(publicBoardTypeListRequest));
|
||||
}
|
||||
|
||||
@CommonLog("根据固件类型&版本&板载获取固件集合")
|
||||
@ApiOperation("根据固件类型&版本&板载获取固件集合")
|
||||
@GetMapping("/getFirmwareList")
|
||||
public Result<List<AppPublicFirmwarePlane>> getFirmwareList(PublicFirmwareListRequest publicFirmwareListRequest) {
|
||||
|
||||
@@ -2,6 +2,7 @@ package com.corewing.app.modules.app;
|
||||
|
||||
import cn.dev33.satoken.stp.StpUtil;
|
||||
import com.corewing.app.common.Result;
|
||||
import com.corewing.app.common.annotation.CommonLog;
|
||||
import com.corewing.app.dto.uploadReplaySessionRequest;
|
||||
import com.corewing.app.entity.ReplaySession;
|
||||
import com.corewing.app.service.ReplaySessionService;
|
||||
@@ -24,6 +25,7 @@ public class AppReplaySessionController {
|
||||
* 获取飞行记录
|
||||
* @return
|
||||
*/
|
||||
@CommonLog("获取当前用户飞行记录")
|
||||
@ApiOperation("获取当前用户飞行记录")
|
||||
@GetMapping("/getReplayList")
|
||||
public Result<List<ReplaySession>> getReplayList() {
|
||||
@@ -35,6 +37,7 @@ public class AppReplaySessionController {
|
||||
* @param uploadReplaySessionRequests
|
||||
* @return
|
||||
*/
|
||||
@CommonLog("上传飞行记录")
|
||||
@ApiOperation("上传飞行记录")
|
||||
@PostMapping("/uploadReplaySession")
|
||||
public Result<Boolean> uploadReplaySession(@RequestBody List<uploadReplaySessionRequest> uploadReplaySessionRequests) {
|
||||
@@ -46,6 +49,7 @@ public class AppReplaySessionController {
|
||||
* @param syncId
|
||||
* @return
|
||||
*/
|
||||
@CommonLog("根据同步id删除飞行记录")
|
||||
@ApiOperation("根据同步id删除飞行记录")
|
||||
@DeleteMapping("/deleteReplaySession/{syncId}")
|
||||
public Result<Boolean> deleteReplaySession(@PathVariable String syncId) {
|
||||
|
||||
@@ -4,6 +4,7 @@ import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.corewing.app.common.Result;
|
||||
import com.corewing.app.common.annotation.CommonLog;
|
||||
import com.corewing.app.entity.Tutorial;
|
||||
import com.corewing.app.entity.TutorialCategory;
|
||||
import com.corewing.app.service.TutorialCategoryService;
|
||||
@@ -41,6 +42,7 @@ public class AppTutorialController {
|
||||
* @param model 数据模型
|
||||
* @return 详情页
|
||||
*/
|
||||
@CommonLog("跳转到界面查看教程详情")
|
||||
@ApiOperation("跳转到界面查看教程详情")
|
||||
@GetMapping("/viewDetail/{tutorialId}")
|
||||
public String viewDetail(@PathVariable Long tutorialId, ModelMap model) {
|
||||
@@ -55,6 +57,7 @@ public class AppTutorialController {
|
||||
* @param tutorialId 教程id
|
||||
* @return
|
||||
*/
|
||||
@CommonLog("添加查看次数")
|
||||
@ApiOperation("添加查看次数")
|
||||
@GetMapping("/addViewCount")
|
||||
@ResponseBody
|
||||
@@ -74,6 +77,7 @@ public class AppTutorialController {
|
||||
* @param firstStatus 置首状态(选填)
|
||||
*
|
||||
*/
|
||||
@CommonLog("分类查询集合")
|
||||
@ApiOperation("分类查询集合")
|
||||
@GetMapping("/category")
|
||||
@ResponseBody
|
||||
@@ -97,6 +101,7 @@ public class AppTutorialController {
|
||||
* @param tutorialTitle 教程标题(选填)
|
||||
*
|
||||
*/
|
||||
@CommonLog("分页查询教程列表")
|
||||
@ApiOperation("分页查询教程列表")
|
||||
@GetMapping("/page")
|
||||
@ResponseBody
|
||||
|
||||
@@ -2,16 +2,19 @@ package com.corewing.app.modules.app;
|
||||
|
||||
import cn.dev33.satoken.stp.StpUtil;
|
||||
import com.corewing.app.common.Result;
|
||||
import com.corewing.app.common.annotation.CommonLog;
|
||||
import com.corewing.app.dto.*;
|
||||
import com.corewing.app.entity.User;
|
||||
import com.corewing.app.service.UserService;
|
||||
import com.corewing.app.service.VerifyCodeService;
|
||||
import com.corewing.app.util.I18nUtil;
|
||||
import com.corewing.app.util.IpUtil;
|
||||
import com.corewing.app.util.RedisUtil;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.validation.Valid;
|
||||
import java.util.HashMap;
|
||||
@@ -25,17 +28,20 @@ import java.util.Map;
|
||||
@RequestMapping("/user")
|
||||
public class AppUserController {
|
||||
|
||||
private final UserService userService;
|
||||
private final VerifyCodeService verifyCodeService;
|
||||
@Resource
|
||||
private UserService userService;
|
||||
|
||||
@Resource
|
||||
private VerifyCodeService verifyCodeService;
|
||||
|
||||
@Resource
|
||||
private RedisUtil redisUtil;
|
||||
|
||||
public AppUserController(UserService userService, VerifyCodeService verifyCodeService) {
|
||||
this.userService = userService;
|
||||
this.verifyCodeService = verifyCodeService;
|
||||
}
|
||||
|
||||
/**
|
||||
* 发送验证码
|
||||
*/
|
||||
@CommonLog("发送验证码接口")
|
||||
@ApiOperation("发送验证码接口")
|
||||
@PostMapping("/sendCode")
|
||||
public Result<String> sendCode(@RequestBody SendCodeRequest request) {
|
||||
@@ -69,6 +75,8 @@ public class AppUserController {
|
||||
data.put("userId", user.getId());
|
||||
data.put("username", user.getUsername());
|
||||
|
||||
redisUtil.set("APP_" + user.getId(), user);
|
||||
|
||||
return Result.success(I18nUtil.getMessage("user.login.success"), data);
|
||||
} catch (Exception e) {
|
||||
return Result.error(e.getMessage());
|
||||
@@ -111,19 +119,28 @@ public class AppUserController {
|
||||
/**
|
||||
* 获取当前登录用户信息
|
||||
*/
|
||||
@CommonLog("获取当前登录用户信息")
|
||||
@ApiOperation("获取当前登录用户信息")
|
||||
@GetMapping("/info")
|
||||
public Result<User> getUserInfo() {
|
||||
Long userId = StpUtil.getLoginIdAsLong();
|
||||
User user = userService.getById(userId);
|
||||
// 隐藏密码
|
||||
user.setPassword(null);
|
||||
return Result.success(user);
|
||||
|
||||
try {
|
||||
// 缓存获取
|
||||
User user = (User) redisUtil.get("APP_" + userId);
|
||||
return Result.success(user);
|
||||
} catch (Exception e) {
|
||||
User user = userService.getById(userId);
|
||||
// 隐藏密码
|
||||
user.setPassword(null);
|
||||
return Result.success(user);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据ID查询用户
|
||||
*/
|
||||
@CommonLog("根据id查询用户")
|
||||
@ApiOperation("根据id查询用户")
|
||||
@GetMapping("/{id}")
|
||||
public Result<User> getById(@PathVariable Long id) {
|
||||
@@ -139,6 +156,7 @@ public class AppUserController {
|
||||
/**
|
||||
* 更新用户信息
|
||||
*/
|
||||
@CommonLog("更新用户信息")
|
||||
@ApiOperation("更新用户信息")
|
||||
@PutMapping("/update")
|
||||
public Result<String> update(@RequestBody User user) {
|
||||
@@ -147,6 +165,10 @@ public class AppUserController {
|
||||
// 不允许通过此接口修改密码
|
||||
user.setPassword(null);
|
||||
boolean success = userService.updateById(user);
|
||||
|
||||
// 更新缓存
|
||||
User cacheUser = userService.getById(userId);
|
||||
redisUtil.set("APP_" + user.getId(), cacheUser);
|
||||
if (success) {
|
||||
return Result.success(I18nUtil.getMessage("user.update.success"));
|
||||
}
|
||||
@@ -156,6 +178,7 @@ public class AppUserController {
|
||||
/**
|
||||
* 修改密码
|
||||
*/
|
||||
@CommonLog("用户修改密码")
|
||||
@ApiOperation("用户修改密码")
|
||||
@PutMapping("/password")
|
||||
public Result<String> updatePassword(@RequestBody UpdatePasswordRequest request) {
|
||||
@@ -189,6 +212,7 @@ public class AppUserController {
|
||||
* @param request
|
||||
* @return
|
||||
*/
|
||||
@CommonLog("忘记密码")
|
||||
@ApiOperation("忘记密码")
|
||||
@PutMapping("/forgetPassword")
|
||||
public Result<String> forgetPassword(@RequestBody ForgetPasswordRequest request) {
|
||||
@@ -213,6 +237,7 @@ public class AppUserController {
|
||||
data.put("token", token);
|
||||
data.put("userId", user.getId());
|
||||
data.put("username", user.getUsername());
|
||||
redisUtil.set("APP_" + user.getId(), user);
|
||||
return Result.success(I18nUtil.getMessage("user.login.success"), data);
|
||||
}
|
||||
|
||||
@@ -221,6 +246,7 @@ public class AppUserController {
|
||||
* @param logoffRequest
|
||||
* @return
|
||||
*/
|
||||
@CommonLog("注销用户")
|
||||
@ApiOperation("注销用户")
|
||||
@DeleteMapping("/delete")
|
||||
public Result<String> logoff(@RequestBody @Valid LogoffRequest logoffRequest) {
|
||||
@@ -231,6 +257,7 @@ public class AppUserController {
|
||||
* 注销发送验证码
|
||||
* @return
|
||||
*/
|
||||
@CommonLog("发送注销验证码")
|
||||
@ApiOperation("发送注销验证码")
|
||||
@PostMapping("/delete/sendCode")
|
||||
public Result<Map<String, String>> deleteSendCode() {
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package com.corewing.app.modules.app;
|
||||
|
||||
import com.corewing.app.common.Result;
|
||||
import com.corewing.app.common.annotation.CommonLog;
|
||||
import com.corewing.app.dto.CheckVersionRequest;
|
||||
import com.corewing.app.entity.AppVersion;
|
||||
import com.corewing.app.service.AppVersionService;
|
||||
@@ -28,6 +29,7 @@ public class AppVersionController {
|
||||
* @param checkVersionRequest
|
||||
* @return
|
||||
*/
|
||||
@CommonLog("校验是否有新版本")
|
||||
@ApiOperation("校验是否有新版本")
|
||||
@GetMapping("/checkUpdate")
|
||||
public Result<Object> checkUpdate(CheckVersionRequest checkVersionRequest) {
|
||||
|
||||
19
src/main/java/com/corewing/app/service/DevLogService.java
Normal file
19
src/main/java/com/corewing/app/service/DevLogService.java
Normal file
@@ -0,0 +1,19 @@
|
||||
|
||||
package com.corewing.app.service;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
import com.corewing.app.entity.DevLog;
|
||||
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 日志Service接口
|
||||
*
|
||||
* @author xuyuxiang
|
||||
* @date 2022/9/2 15:04
|
||||
*/
|
||||
public interface DevLogService extends IService<DevLog> {
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
package com.corewing.app.service.impl;
|
||||
|
||||
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.corewing.app.entity.DevLog;
|
||||
import com.corewing.app.mapper.DevLogMapper;
|
||||
import com.corewing.app.service.DevLogService;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
|
||||
/**
|
||||
* 日志Service接口实现类
|
||||
*
|
||||
* @author xuyuxiang
|
||||
* @date 2022/9/2 15:05
|
||||
*/
|
||||
@Service
|
||||
public class DevLogServiceImpl extends ServiceImpl<DevLogMapper, DevLog> implements DevLogService {
|
||||
|
||||
|
||||
}
|
||||
@@ -18,8 +18,6 @@ import java.io.InputStream;
|
||||
* 根据ip地址定位工具类,离线方式
|
||||
* 参考地址:<a href="https://gitee.com/lionsoul/ip2region/tree/master/binding/java">ip2region</a>
|
||||
*
|
||||
* @author xuyuxiang
|
||||
* @date 2020/3/16 11:25
|
||||
*/
|
||||
@Slf4j
|
||||
public class CommonIpAddressUtil {
|
||||
@@ -62,8 +60,6 @@ public class CommonIpAddressUtil {
|
||||
/**
|
||||
* 获取客户端ip
|
||||
*
|
||||
* @author xuyuxiang
|
||||
* @date 2020/3/19 9:32
|
||||
*/
|
||||
public static String getIp(HttpServletRequest request) {
|
||||
if (ObjectUtil.isEmpty(request)) {
|
||||
@@ -81,8 +77,6 @@ public class CommonIpAddressUtil {
|
||||
/**
|
||||
* 根据IP地址离线获取城市
|
||||
*
|
||||
* @author xuyuxiang
|
||||
* @date 2022/4/27 23:14
|
||||
*/
|
||||
public static String getCityInfo(String ip) {
|
||||
try {
|
||||
|
||||
60
src/main/java/com/corewing/app/util/CommonJoinPointUtil.java
Normal file
60
src/main/java/com/corewing/app/util/CommonJoinPointUtil.java
Normal file
@@ -0,0 +1,60 @@
|
||||
package com.corewing.app.util;
|
||||
|
||||
import cn.hutool.core.map.MapUtil;
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import cn.hutool.json.JSONObject;
|
||||
import cn.hutool.json.JSONUtil;
|
||||
import jakarta.servlet.http.HttpServletRequest;
|
||||
import jakarta.servlet.http.HttpServletResponse;
|
||||
import org.aspectj.lang.JoinPoint;
|
||||
import org.aspectj.lang.Signature;
|
||||
import org.aspectj.lang.reflect.MethodSignature;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
public class CommonJoinPointUtil {
|
||||
|
||||
/**
|
||||
* 获取切面的参数JSON
|
||||
*
|
||||
*/
|
||||
public static String getArgsJsonString(JoinPoint joinPoint) {
|
||||
Signature signature = joinPoint.getSignature();
|
||||
// 参数名数组
|
||||
String[] parameterNames = ((MethodSignature) signature).getParameterNames();
|
||||
// 构造参数组集合
|
||||
Map<String, Object> map = MapUtil.newHashMap();
|
||||
Object[] args = joinPoint.getArgs();
|
||||
for (int i = 0; i < args.length; i++) {
|
||||
if(ObjectUtil.isNotEmpty(args[i]) && isUsefulParam(args[i])) {
|
||||
if(JSONUtil.isTypeJSON(StrUtil.toString(args[i]))) {
|
||||
try {
|
||||
JSONObject jsonObject = JSONUtil.parseObj(args[i]);
|
||||
if(ObjectUtil.isNotEmpty(jsonObject)) {
|
||||
map.put(parameterNames[i], jsonObject);
|
||||
} else {
|
||||
map.put(parameterNames[i], JSONUtil.parseArray(args[i]));
|
||||
}
|
||||
} catch (Exception e) {
|
||||
map.put(parameterNames[i], null);
|
||||
}
|
||||
} else {
|
||||
map.put(parameterNames[i], JSONUtil.toJsonStr(args[i]));
|
||||
}
|
||||
}
|
||||
}
|
||||
return JSONUtil.toJsonStr(map);
|
||||
}
|
||||
|
||||
/**
|
||||
* 判断是否需要拼接的参数,过滤掉HttpServletRequest,MultipartFile,HttpServletResponse等类型参数
|
||||
*
|
||||
*/
|
||||
private static boolean isUsefulParam(Object arg) {
|
||||
return !(arg instanceof MultipartFile) &&
|
||||
!(arg instanceof HttpServletRequest) &&
|
||||
!(arg instanceof HttpServletResponse);
|
||||
}
|
||||
}
|
||||
@@ -9,6 +9,7 @@ import javax.servlet.http.Cookie;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
|
||||
|
||||
/**
|
||||
* HttpServlet工具类,获取当前request和response
|
||||
*/
|
||||
@@ -18,8 +19,6 @@ public class CommonServletUtil {
|
||||
/**
|
||||
* 从请求中中获取参数
|
||||
*
|
||||
* @author xuyuxiang
|
||||
* @date 2021/10/14 10:44
|
||||
**/
|
||||
public static String getParamFromRequest(String paramName) {
|
||||
HttpServletRequest request = getRequest();
|
||||
@@ -47,7 +46,7 @@ public class CommonServletUtil {
|
||||
return paramValue;
|
||||
}
|
||||
|
||||
public static HttpServletRequest getRequest() {
|
||||
public static javax.servlet.http.HttpServletRequest getRequest() {
|
||||
ServletRequestAttributes servletRequestAttributes;
|
||||
try {
|
||||
servletRequestAttributes = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes();
|
||||
|
||||
66
src/main/java/com/corewing/app/util/CommonUaUtil.java
Normal file
66
src/main/java/com/corewing/app/util/CommonUaUtil.java
Normal file
@@ -0,0 +1,66 @@
|
||||
package com.corewing.app.util;
|
||||
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import cn.hutool.extra.servlet.ServletUtil;
|
||||
import cn.hutool.http.useragent.Browser;
|
||||
import cn.hutool.http.useragent.UserAgent;
|
||||
import cn.hutool.http.useragent.UserAgentUtil;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
|
||||
/**
|
||||
* 用户代理工具类
|
||||
*
|
||||
*/
|
||||
public class CommonUaUtil {
|
||||
|
||||
/**
|
||||
* 获取客户端浏览器
|
||||
*
|
||||
*/
|
||||
public static String getBrowser(HttpServletRequest request) {
|
||||
UserAgent userAgent = getUserAgent(request);
|
||||
if (ObjectUtil.isEmpty(userAgent)) {
|
||||
return StrUtil.DASHED;
|
||||
} else {
|
||||
String browser = userAgent.getBrowser().toString();
|
||||
if (StrUtil.isNotBlank(browser) && browser.length() > 250) {
|
||||
browser = browser.substring(0, 250);
|
||||
}
|
||||
return "Unknown".equals(browser) ? StrUtil.DASHED : browser;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取客户端操作系统
|
||||
*
|
||||
*/
|
||||
public static String getOs(HttpServletRequest request) {
|
||||
UserAgent userAgent = getUserAgent(request);
|
||||
if (ObjectUtil.isEmpty(userAgent)) {
|
||||
return StrUtil.DASHED;
|
||||
} else {
|
||||
String os = userAgent.getOs().toString();
|
||||
if (StrUtil.isNotBlank(os) && os.length() > 250) {
|
||||
os = os.substring(0, 250);
|
||||
}
|
||||
return "Unknown".equals(os) ? StrUtil.DASHED : os;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取请求代理头
|
||||
*
|
||||
*/
|
||||
private static UserAgent getUserAgent(HttpServletRequest request) {
|
||||
String userAgentStr = ServletUtil.getHeaderIgnoreCase(request, "User-Agent");
|
||||
UserAgent userAgent = UserAgentUtil.parse(userAgentStr);
|
||||
if (ObjectUtil.isNotEmpty(userAgentStr)) {
|
||||
if ("Unknown".equals(userAgent.getBrowser().getName())) {
|
||||
userAgent.setBrowser(new Browser(userAgentStr, null, ""));
|
||||
}
|
||||
}
|
||||
return userAgent;
|
||||
}
|
||||
}
|
||||
143
src/main/java/com/corewing/app/util/DevLogUtil.java
Normal file
143
src/main/java/com/corewing/app/util/DevLogUtil.java
Normal file
@@ -0,0 +1,143 @@
|
||||
package com.corewing.app.util;
|
||||
|
||||
import cn.hutool.core.date.DateTime;
|
||||
import cn.hutool.core.exceptions.ExceptionUtil;
|
||||
import cn.hutool.core.thread.ThreadUtil;
|
||||
import cn.hutool.extra.spring.SpringUtil;
|
||||
import com.corewing.app.common.annotation.CommonLog;
|
||||
import com.corewing.app.entity.DevLog;
|
||||
import com.corewing.app.enums.DevLogCategoryEnum;
|
||||
import com.corewing.app.enums.DevLogExeStatusEnum;
|
||||
import com.corewing.app.service.DevLogService;
|
||||
import org.apache.commons.codec.digest.Md5Crypt;
|
||||
import org.aspectj.lang.JoinPoint;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
|
||||
|
||||
/**
|
||||
* 日志工具类
|
||||
*
|
||||
* @author xuyuxiang
|
||||
* @date 2022/9/2 15:26
|
||||
*/
|
||||
public class DevLogUtil {
|
||||
|
||||
private static final DevLogService devLogService = SpringUtil.getBean(DevLogService.class);
|
||||
|
||||
/**
|
||||
* 记录操作日志
|
||||
*
|
||||
*/
|
||||
public static void executeOperationLog(CommonLog commonLog, String userName, String userId, JoinPoint joinPoint, String resultJson) {
|
||||
HttpServletRequest request = CommonServletUtil.getRequest();
|
||||
String requestURI = request.getRequestURI();
|
||||
String method = request.getRequestURI();
|
||||
DevLog devLog = genBasOpLog();
|
||||
ThreadUtil.execute(() -> {
|
||||
devLog.setCategory(DevLogCategoryEnum.APP_OPERATE.getValue());
|
||||
devLog.setName(commonLog.value());
|
||||
devLog.setExeStatus(DevLogExeStatusEnum.SUCCESS.getValue());
|
||||
devLog.setClassName(joinPoint.getTarget().getClass().getName());
|
||||
devLog.setMethodName(joinPoint.getSignature().getName());
|
||||
devLog.setReqMethod(method);
|
||||
devLog.setReqUrl(requestURI);
|
||||
devLog.setParamJson(CommonJoinPointUtil.getArgsJsonString(joinPoint));
|
||||
devLog.setResultJson(resultJson);
|
||||
devLog.setOpTime(DateTime.now());
|
||||
devLog.setOpUser(userName);
|
||||
devLog.setCreateUser(userId);
|
||||
creatLogSignValue(devLog);
|
||||
devLogService.save(devLog);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* 记录异常日志
|
||||
*
|
||||
*/
|
||||
public static void executeExceptionLog(CommonLog commonLog, String userName, String userId, JoinPoint joinPoint, Exception exception) {
|
||||
HttpServletRequest request = CommonServletUtil.getRequest();
|
||||
String requestURI = request.getRequestURI();
|
||||
String method = request.getRequestURI();
|
||||
DevLog devLog = genBasOpLog();
|
||||
ThreadUtil.execute(() -> {
|
||||
devLog.setCategory(DevLogCategoryEnum.APP_EXCEPTION.getValue());
|
||||
devLog.setName(commonLog.value());
|
||||
devLog.setExeStatus(DevLogExeStatusEnum.FAIL.getValue());
|
||||
devLog.setExeMessage(ExceptionUtil.stacktraceToString(exception, Integer.MAX_VALUE));
|
||||
devLog.setClassName(joinPoint.getTarget().getClass().getName());
|
||||
devLog.setMethodName(joinPoint.getSignature().getName());
|
||||
devLog.setReqMethod(method);
|
||||
devLog.setReqUrl(requestURI);
|
||||
devLog.setParamJson(CommonJoinPointUtil.getArgsJsonString(joinPoint));
|
||||
devLog.setOpTime(DateTime.now());
|
||||
devLog.setOpUser(userName);
|
||||
devLog.setCreateUser(userId);
|
||||
creatLogSignValue(devLog);
|
||||
devLogService.save(devLog);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* 记录登录日志
|
||||
*
|
||||
* @author xuyuxiang
|
||||
* @date 2022/9/2 16:08
|
||||
*/
|
||||
public static void executeLoginLog(String userName) {
|
||||
DevLog devLog = genBasOpLog();
|
||||
ThreadUtil.execute(() -> {
|
||||
devLog.setCategory(DevLogCategoryEnum.APP_LOGIN.getValue());
|
||||
devLog.setName("用户登录");
|
||||
devLog.setExeStatus(DevLogExeStatusEnum.SUCCESS.getValue());
|
||||
devLog.setOpTime(DateTime.now());
|
||||
devLog.setOpUser(userName);
|
||||
creatLogSignValue(devLog);
|
||||
devLogService.save(devLog);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* 记录登出日志
|
||||
*
|
||||
* @author xuyuxiang
|
||||
* @date 2022/9/2 16:08
|
||||
*/
|
||||
public static void executeLogoutLog(String userName) {
|
||||
DevLog devLog = genBasOpLog();
|
||||
ThreadUtil.execute(() -> {
|
||||
devLog.setCategory(DevLogCategoryEnum.APP_LOGOUT.getValue());
|
||||
devLog.setName("用户登出");
|
||||
devLog.setExeStatus(DevLogExeStatusEnum.SUCCESS.getValue());
|
||||
devLog.setOpTime(DateTime.now());
|
||||
devLog.setOpUser(userName);
|
||||
creatLogSignValue(devLog);
|
||||
devLogService.save(devLog);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* 构建基础操作日志
|
||||
*
|
||||
*/
|
||||
private static DevLog genBasOpLog() {
|
||||
HttpServletRequest request = CommonServletUtil.getRequest();
|
||||
String ip = IpUtil.getClientIp(request);
|
||||
DevLog devLog = new DevLog();
|
||||
devLog.setOpIp(ip);
|
||||
devLog.setOpAddress(CommonIpAddressUtil.getCityInfo(ip));
|
||||
devLog.setOpBrowser(CommonUaUtil.getBrowser(request));
|
||||
devLog.setOpOs(CommonUaUtil.getOs(request));
|
||||
return devLog;
|
||||
}
|
||||
|
||||
/**
|
||||
* 构建日志完整性保护签名数据
|
||||
*/
|
||||
private static void creatLogSignValue (DevLog devLog) {
|
||||
String logStr = devLog.toString().replaceAll(" +","");
|
||||
devLog.setSignData(Md5Crypt.md5Crypt(logStr.getBytes(StandardCharsets.UTF_8)));
|
||||
}
|
||||
}
|
||||
@@ -2,8 +2,8 @@
|
||||
# spring profiles configuration
|
||||
#########################################
|
||||
#spring.profiles.active=local
|
||||
#spring.profiles.active=test
|
||||
spring.profiles.active=prod
|
||||
spring.profiles.active=test
|
||||
#spring.profiles.active=prod
|
||||
#########################################
|
||||
|
||||
# 应用服务 WEB 访问端口
|
||||
|
||||
6
src/main/resources/mapper/DevLogMapper.xml
Normal file
6
src/main/resources/mapper/DevLogMapper.xml
Normal file
@@ -0,0 +1,6 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
<mapper namespace="com.corewing.app.mapper.DevLogMapper">
|
||||
|
||||
|
||||
</mapper>
|
||||
Reference in New Issue
Block a user