refactor(logs): 将日志服务从设备模块迁移到系统模块
- 将 CsLogsPO 相关类从 cs-device 模块移动到 cs-system 模块 - 更新所有相关导入路径以指向新的包位置 - 修改 MqttMessageHandler 使用远程 Feign 客户端调用日志服务 - 清理不再使用的分页和日志 POJO 导入依赖 - 重命名相关 Mapper 和 Service 类以匹配新模块结构
This commit is contained in:
@@ -0,0 +1,20 @@
|
||||
package com.njcn.cssystem.api;
|
||||
|
||||
import com.njcn.common.pojo.constant.ServerInfo;
|
||||
import com.njcn.common.pojo.dto.DeviceLogDTO;
|
||||
import com.njcn.common.pojo.response.HttpResult;
|
||||
import com.njcn.cssystem.api.fallback.CsLogsClientFallbackFactory;
|
||||
import org.springframework.cloud.openfeign.FeignClient;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
|
||||
/**
|
||||
* @author xy
|
||||
*/
|
||||
@FeignClient(value = ServerInfo.CS_DEVICE_BOOT, path = "/cslog", fallbackFactory = CsLogsClientFallbackFactory.class,contextId = "cslog")
|
||||
public interface CsLogsFeignClient {
|
||||
|
||||
@PostMapping("/add")
|
||||
HttpResult addUserLog(@RequestBody DeviceLogDTO deviceLogDTO);
|
||||
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
package com.njcn.cssystem.api.fallback;
|
||||
|
||||
import com.njcn.common.pojo.dto.DeviceLogDTO;
|
||||
import com.njcn.common.pojo.enums.response.CommonResponseEnum;
|
||||
import com.njcn.common.pojo.exception.BusinessException;
|
||||
import com.njcn.common.pojo.response.HttpResult;
|
||||
import com.njcn.cssystem.api.CsLogsFeignClient;
|
||||
import feign.hystrix.FallbackFactory;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
/**
|
||||
* @author xy
|
||||
*/
|
||||
@Slf4j
|
||||
@Component
|
||||
public class CsLogsClientFallbackFactory implements FallbackFactory<CsLogsFeignClient> {
|
||||
@Override
|
||||
public CsLogsFeignClient create(Throwable cause) {
|
||||
//判断抛出异常是否为解码器抛出的业务异常
|
||||
Enum<?> exceptionEnum = CommonResponseEnum.SERVICE_FALLBACK;
|
||||
if (cause.getCause() instanceof BusinessException) {
|
||||
BusinessException businessException = (BusinessException) cause.getCause();
|
||||
}
|
||||
Enum<?> finalExceptionEnum = exceptionEnum;
|
||||
return new CsLogsFeignClient() {
|
||||
|
||||
@Override
|
||||
public HttpResult addUserLog(DeviceLogDTO deviceLogDTO) {
|
||||
log.error("{}异常,降级处理,异常为:{}","新增日志",cause.toString());
|
||||
throw new BusinessException(finalExceptionEnum);
|
||||
}
|
||||
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,100 @@
|
||||
package com.njcn.cssystem.pojo.po;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.*;
|
||||
import com.fasterxml.jackson.annotation.JsonFormat;
|
||||
import lombok.Data;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
/**
|
||||
*
|
||||
* Description:
|
||||
* Date: 2023/8/7 14:02【需求编号】
|
||||
*
|
||||
* @author clam
|
||||
* @version V1.0.0
|
||||
*/
|
||||
@Data
|
||||
@TableName(value = "cs_logs")
|
||||
public class CsLogsPO {
|
||||
@TableId(value = "id", type = IdType.ASSIGN_UUID)
|
||||
private String id;
|
||||
|
||||
|
||||
/**
|
||||
* 用户名称
|
||||
*/
|
||||
@TableField(value = "user_name")
|
||||
private String userName;
|
||||
|
||||
/**
|
||||
* 操作
|
||||
*/
|
||||
@TableField(value = "operate")
|
||||
private String operate;
|
||||
|
||||
/**
|
||||
* 结果(0:失败 1:成功)
|
||||
*/
|
||||
@TableField(value = "`result`")
|
||||
private Integer result;
|
||||
|
||||
/**
|
||||
* 失败原因
|
||||
*/
|
||||
@TableField(value = "fail_reason")
|
||||
private String failReason;
|
||||
|
||||
/**
|
||||
* 登录名称
|
||||
*/
|
||||
@TableField(value = "login_name")
|
||||
private String loginName;
|
||||
|
||||
/**
|
||||
* 创建用户
|
||||
*/
|
||||
@TableField(fill = FieldFill.INSERT, insertStrategy = FieldStrategy.IGNORED)
|
||||
private String createBy;
|
||||
|
||||
|
||||
/**
|
||||
* 创建时间
|
||||
*/
|
||||
@TableField(fill = FieldFill.INSERT, insertStrategy = FieldStrategy.IGNORED)
|
||||
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
|
||||
private LocalDateTime createTime;
|
||||
|
||||
/**
|
||||
* 更新用户
|
||||
*/
|
||||
@TableField(fill = FieldFill.INSERT_UPDATE, insertStrategy = FieldStrategy.IGNORED)
|
||||
private String updateBy;
|
||||
|
||||
/**
|
||||
* 更新时间
|
||||
*/
|
||||
@TableField(fill = FieldFill.INSERT_UPDATE, insertStrategy = FieldStrategy.IGNORED)
|
||||
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
|
||||
private LocalDateTime updateTime;
|
||||
|
||||
public static final String COL_ID = "id";
|
||||
|
||||
public static final String COL_USER_NAME = "user_name";
|
||||
|
||||
public static final String COL_OPERATE = "operate";
|
||||
|
||||
public static final String COL_RESULT = "result";
|
||||
|
||||
public static final String COL_FAIL_REASON = "fail_reason";
|
||||
|
||||
public static final String COL_CREATE_BY = "create_by";
|
||||
|
||||
public static final String COL_CREATE_TIME = "create_time";
|
||||
|
||||
public static final String COL_UPDATE_BY = "update_by";
|
||||
|
||||
public static final String COL_UPDATE_TIME = "update_time";
|
||||
|
||||
public static final String COL_LOGIN_NAME = "login_name";
|
||||
}
|
||||
@@ -0,0 +1,63 @@
|
||||
package com.njcn.cssystem.controller;
|
||||
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import com.njcn.common.pojo.annotation.OperateInfo;
|
||||
import com.njcn.common.pojo.constant.OperateType;
|
||||
import com.njcn.common.pojo.dto.DeviceLogDTO;
|
||||
import com.njcn.common.pojo.enums.common.LogEnum;
|
||||
import com.njcn.common.pojo.enums.response.CommonResponseEnum;
|
||||
import com.njcn.common.pojo.response.HttpResult;
|
||||
import com.njcn.common.utils.HttpResultUtil;
|
||||
import com.njcn.cssystem.pojo.po.CsLogsPO;
|
||||
import com.njcn.cssystem.service.CsLogsPOService;
|
||||
import com.njcn.web.controller.BaseController;
|
||||
import com.njcn.web.pojo.param.BaseParam;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiImplicitParam;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
/**
|
||||
* Description:
|
||||
* Date: 2023/8/7 14:21【需求编号】
|
||||
*
|
||||
* @author clam
|
||||
* @version V1.0.0
|
||||
*/
|
||||
@RestController
|
||||
@Slf4j
|
||||
@Api(tags = "日志管理")
|
||||
@AllArgsConstructor
|
||||
@RequestMapping("/cslog")
|
||||
public class CsLogController extends BaseController {
|
||||
|
||||
private final CsLogsPOService csLogsPOService;
|
||||
|
||||
/**
|
||||
* 插入审计日志
|
||||
*/
|
||||
@OperateInfo(info = LogEnum.SYSTEM_COMMON, operateType = OperateType.ADD)
|
||||
@PostMapping("/add")
|
||||
@ApiOperation("插入设备日志")
|
||||
@ApiImplicitParam(name = "deviceLogDTO", value = "插入日志参数", required = true)
|
||||
public HttpResult addUserLog(@RequestBody DeviceLogDTO deviceLogDTO) {
|
||||
String methodDescribe = getMethodDescribe("addUserLog");
|
||||
csLogsPOService.addLog(deviceLogDTO);
|
||||
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, null, methodDescribe);
|
||||
}
|
||||
@OperateInfo(info = LogEnum.BUSINESS_COMMON)
|
||||
@PostMapping("/queryLog")
|
||||
@ApiOperation("查询日志")
|
||||
@ApiImplicitParam(name = "baseParam", value = "查询日志参数", required = true)
|
||||
public HttpResult<IPage<CsLogsPO>> queryLog(@RequestBody BaseParam baseParam){
|
||||
String methodDescribe = getMethodDescribe("queryLog");
|
||||
IPage<CsLogsPO> list = csLogsPOService.queryPage(baseParam);
|
||||
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, list, methodDescribe);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
package com.njcn.cssystem.mapper;
|
||||
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import com.njcn.cssystem.pojo.po.CsLogsPO;
|
||||
|
||||
/**
|
||||
*
|
||||
* Description:
|
||||
* Date: 2023/8/7 14:02【需求编号】
|
||||
*
|
||||
* @author clam
|
||||
* @version V1.0.0
|
||||
*/
|
||||
public interface CsLogsPOMapper extends BaseMapper<CsLogsPO> {
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
package com.njcn.cssystem.service;
|
||||
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
import com.njcn.common.pojo.dto.DeviceLogDTO;
|
||||
import com.njcn.cssystem.pojo.po.CsLogsPO;
|
||||
import com.njcn.web.pojo.param.BaseParam;
|
||||
|
||||
/**
|
||||
*
|
||||
* Description:
|
||||
* Date: 2023/8/7 14:02【需求编号】
|
||||
*
|
||||
* @author clam
|
||||
* @version V1.0.0
|
||||
*/
|
||||
public interface CsLogsPOService extends IService<CsLogsPO>{
|
||||
|
||||
void addLog(DeviceLogDTO deviceLogDTO);
|
||||
|
||||
IPage<CsLogsPO> queryPage(BaseParam baseParam);
|
||||
}
|
||||
@@ -1,11 +1,9 @@
|
||||
package com.njcn.cssystem.service.impl;
|
||||
|
||||
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.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.njcn.csdevice.api.RoleEngineerDevFeignClient;
|
||||
import com.njcn.csdevice.pojo.po.CsLogsPO;
|
||||
import com.njcn.cssystem.mapper.CsFeedbackChatMapper;
|
||||
import com.njcn.cssystem.mapper.CsFeedbackMapper;
|
||||
import com.njcn.cssystem.pojo.param.CsFeedbackAddParm;
|
||||
@@ -16,7 +14,6 @@ import com.njcn.cssystem.pojo.po.CsFeedbackPO;
|
||||
import com.njcn.cssystem.pojo.po.CsFilePathPO;
|
||||
import com.njcn.cssystem.pojo.vo.CsFeedbackDetailVO;
|
||||
import com.njcn.cssystem.pojo.vo.CsFeedbackVO;
|
||||
import com.njcn.cssystem.service.CsFeedbackChatService;
|
||||
import com.njcn.cssystem.service.CsFeedbackService;
|
||||
import com.njcn.cssystem.service.CsFilePathService;
|
||||
import com.njcn.oss.constant.OssPath;
|
||||
|
||||
@@ -0,0 +1,53 @@
|
||||
package com.njcn.cssystem.service.impl;
|
||||
|
||||
import com.alibaba.fastjson.JSONArray;
|
||||
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.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.njcn.common.pojo.dto.DeviceLogDTO;
|
||||
import com.njcn.cssystem.mapper.CsLogsPOMapper;
|
||||
import com.njcn.cssystem.pojo.po.CsLogsPO;
|
||||
import com.njcn.cssystem.service.CsLogsPOService;
|
||||
import com.njcn.web.pojo.param.BaseParam;
|
||||
import com.njcn.web.utils.RequestUtil;
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.springframework.beans.BeanUtils;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
*
|
||||
* Description:
|
||||
* Date: 2023/8/7 14:02【需求编号】
|
||||
*
|
||||
* @author clam
|
||||
* @version V1.0.0
|
||||
*/
|
||||
@Service
|
||||
public class CsLogsPOServiceImpl extends ServiceImpl<CsLogsPOMapper, CsLogsPO> implements CsLogsPOService {
|
||||
|
||||
@Override
|
||||
public void addLog(DeviceLogDTO deviceLogDTO) {
|
||||
CsLogsPO csPO = new CsLogsPO();
|
||||
BeanUtils.copyProperties(deviceLogDTO,csPO);
|
||||
csPO.setCreateBy(deviceLogDTO.getUserIndex());
|
||||
csPO.setUpdateBy(deviceLogDTO.getUserIndex());
|
||||
this.save(csPO);
|
||||
}
|
||||
|
||||
@Override
|
||||
public IPage<CsLogsPO> queryPage(BaseParam baseParam) {
|
||||
Page<CsLogsPO> returnpage = new Page<> (baseParam.getPageNum ( ), baseParam.getPageSize ( ));
|
||||
String username = RequestUtil.getUsername();
|
||||
String userRole = RequestUtil.getUserRole();
|
||||
List<String> strings = JSONArray.parseArray(userRole, String.class);
|
||||
QueryWrapper<CsLogsPO> csLogsPOQueryWrapper = new QueryWrapper<>();
|
||||
csLogsPOQueryWrapper.lambda()
|
||||
.ge(StringUtils.isNotBlank(baseParam.getSearchBeginTime()),CsLogsPO::getCreateTime,baseParam.getSearchBeginTime()).
|
||||
le(StringUtils.isNotBlank(baseParam.getSearchEndTime()),CsLogsPO::getCreateTime,baseParam.getSearchEndTime()).orderByDesc(CsLogsPO::getCreateTime);
|
||||
IPage<CsLogsPO> list = this.getBaseMapper().selectPage(returnpage,csLogsPOQueryWrapper);
|
||||
return list;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user