Browse Source

日志管理

WXF 3 years ago
parent
commit
846a38ca0a
17 changed files with 578 additions and 2 deletions
  1. 1 0
      api-common/src/main/java/api/common/pojo/constants/DictConstants.java
  2. 32 0
      api-common/src/main/java/api/common/pojo/constants/LogConstants.java
  3. 27 0
      api-common/src/main/java/api/common/pojo/param/log/LogPageParam.java
  4. 1 0
      api-common/src/main/java/api/common/pojo/po/log/LogLoginPO.java
  5. 24 0
      api-common/src/main/java/api/common/pojo/po/log/LogOperationPO.java
  6. 27 0
      api-common/src/main/java/api/common/pojo/po/log/LogSystemPO.java
  7. 31 0
      api-common/src/main/java/api/common/util/LogUtil.java
  8. 2 0
      simulation-resource-server/src/main/java/com/css/simulation/resource/Application.java
  9. 122 0
      simulation-resource-server/src/main/java/com/css/simulation/resource/common/log/LogAdvice.java
  10. 10 0
      simulation-resource-server/src/main/java/com/css/simulation/resource/common/utils/AuthUtil.java
  11. 46 0
      simulation-resource-server/src/main/java/com/css/simulation/resource/log/ctrl/LogCtrl.java
  12. 26 0
      simulation-resource-server/src/main/java/com/css/simulation/resource/log/mapper/LogMapper.java
  13. 93 0
      simulation-resource-server/src/main/java/com/css/simulation/resource/log/service/LogService.java
  14. 2 1
      simulation-resource-server/src/main/java/com/css/simulation/resource/model/ctrl/VehicleCtrl.java
  15. 5 0
      simulation-resource-server/src/main/java/com/css/simulation/resource/model/service/VehicleService.java
  16. 1 1
      simulation-resource-server/src/main/resources/logback-spring.xml
  17. 128 0
      simulation-resource-server/src/main/resources/mapper/log/LogMapper.xml

+ 1 - 0
api-common/src/main/java/api/common/pojo/constants/DictConstants.java

@@ -27,6 +27,7 @@ public class DictConstants {
     public static final String PROJECT_RUN_STATE = "projectRunState";//项目运行状态
     public static final String PROJECT_RUN_STATE = "projectRunState";//项目运行状态
     public static final String VALIDATION_STATUS = "validationStatus";//项目运行状态
     public static final String VALIDATION_STATUS = "validationStatus";//项目运行状态
     public static final String ROLE_CODE = "roleCode";//用户类型(角色编码)
     public static final String ROLE_CODE = "roleCode";//用户类型(角色编码)
+    public static final String USE_TYPE = "useType";//占用类型
 
 
     public static final String ALGORITHM_FILE = "algorithmFile";//算法文件上传type
     public static final String ALGORITHM_FILE = "algorithmFile";//算法文件上传type
 
 

+ 32 - 0
api-common/src/main/java/api/common/pojo/constants/LogConstants.java

@@ -0,0 +1,32 @@
+package api.common.pojo.constants;
+
+public class LogConstants {
+
+    //字典类型
+    public static final String MODULE_TYPE = "moduleType";//模块
+    public static final String OPERATION_TYPE = "operationType";//操作类型
+    public static final String SYS_LOG_TYPE = "sysLogType";//系统日志类型
+
+    //字典项
+    public static final String MODULE_VEHICLE = "1";//模块-车辆模型
+    public static final String MODULE_CAMERA = "2";//模块-传感器模型-摄像头
+    public static final String MODULE_OGT = "3";//模块-传感器模型-完美传感器
+    public static final String MODULE_LIDAR = "4";//模块-传感器模型-激光雷达
+    public static final String MODULE_GPS = "5";//模块-传感器模型-GPS
+    public static final String MODULE_CONFIG = "6";//模块-车辆配置
+    public static final String MODULE_ALGORITH = "7";//模块-算法库
+    public static final String MODULE_SCENE_TEST_PACKAGE = "8";//模块-场景库-场景测试包
+    public static final String MODULE_SCORING = "9";//模块-场景库-评分规则
+    public static final String MODULE_SCENE_NATURAL = "10";//模块-场景库-自然驾驶场景
+    public static final String MODULE_SCENE_STANDARDS = "11";//模块-场景库-标准法规场景
+    public static final String MODULE_SCENE_ACCIDENT = "12";//模块-场景库-交通事故场景
+
+
+    public static final String SYS_LOG_USER = "01";//用户管理
+    public static final String SYS_LOG_USER_INSERT = "0101";//用户管理-新增
+    public static final String SYS_LOG_USER_UPDATE = "0102";//用户管理-修改
+    public static final String SYS_LOG_USER_RESET = "0103";//用户管理-重置密码
+    public static final String SYS_LOG_USER_START = "0104";//用户管理-启用
+    public static final String SYS_LOG_USER_STOP = "0105";//用户管理-停用
+
+}

+ 27 - 0
api-common/src/main/java/api/common/pojo/param/log/LogPageParam.java

@@ -0,0 +1,27 @@
+package api.common.pojo.param.log;
+
+import api.common.pojo.common.PageVO;
+import com.fasterxml.jackson.annotation.JsonFormat;
+import lombok.Data;
+import java.sql.Timestamp;
+
+@Data
+public class LogPageParam extends PageVO {
+
+    //账户id
+    private String id;
+    //账户名
+    private String username;
+    //模块
+    private String module;
+    //操作类型
+    private String operationType;
+    //操作内容
+    private String content;
+    //操作时间起
+    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss",timezone="GMT+8")
+    private Timestamp createTimeBegin;
+    //操作时间止
+    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss",timezone="GMT+8")
+    private Timestamp createTimeEnd;
+}

+ 1 - 0
api-common/src/main/java/api/common/pojo/po/log/LogLoginPO.java

@@ -1,5 +1,6 @@
 package api.common.pojo.po.log;
 package api.common.pojo.po.log;
 
 
+import com.fasterxml.jackson.annotation.JsonFormat;
 import lombok.Data;
 import lombok.Data;
 
 
 import java.sql.Timestamp;
 import java.sql.Timestamp;

+ 24 - 0
api-common/src/main/java/api/common/pojo/po/log/LogOperationPO.java

@@ -0,0 +1,24 @@
+package api.common.pojo.po.log;
+
+import lombok.Data;
+
+import java.sql.Timestamp;
+
+@Data
+public class LogOperationPO {
+
+    //主键id
+    private String id;
+    //账户id
+    private String userId;
+    //账户名
+    private String username;
+    //操作IP
+    private String ip;
+    //模块
+    private String module;
+    //操作类型
+    private String operationType;
+    //创建时间
+    private Timestamp createTime;
+}

+ 27 - 0
api-common/src/main/java/api/common/pojo/po/log/LogSystemPO.java

@@ -0,0 +1,27 @@
+package api.common.pojo.po.log;
+
+import lombok.Data;
+
+import java.sql.Timestamp;
+
+@Data
+public class LogSystemPO {
+
+    //主键id
+    private String id;
+    //账户id
+    private String userId;
+    //账户名
+    private String username;
+    //账户类型
+    private String roleCode;
+    //模块
+    private String module;
+    //操作类型
+    private String operationType;
+    //操作内容
+    private String content;
+    //创建时间
+    private Timestamp createTime;
+
+}

+ 31 - 0
api-common/src/main/java/api/common/util/LogUtil.java

@@ -0,0 +1,31 @@
+package api.common.util;
+
+public abstract class LogUtil {
+
+    protected static final ThreadLocal<String> OPERATION_TYPE = new ThreadLocal();
+
+    public static void insert(){
+        OPERATION_TYPE.set("1");
+    };
+
+    public static void update(){
+        OPERATION_TYPE.set("2");
+    };
+
+    public static void delete(){
+        OPERATION_TYPE.set("0");
+    };
+
+    public static String getOperationType(){
+        return OPERATION_TYPE.get();
+    };
+
+    public static void remove(){
+        OPERATION_TYPE.remove();
+    };
+
+    public static void share() {
+        OPERATION_TYPE.set("3");
+    }
+
+}

+ 2 - 0
simulation-resource-server/src/main/java/com/css/simulation/resource/Application.java

@@ -3,6 +3,7 @@ package com.css.simulation.resource;
 import org.springframework.boot.SpringApplication;
 import org.springframework.boot.SpringApplication;
 import org.springframework.boot.autoconfigure.SpringBootApplication;
 import org.springframework.boot.autoconfigure.SpringBootApplication;
 import org.springframework.cloud.openfeign.EnableFeignClients;
 import org.springframework.cloud.openfeign.EnableFeignClients;
+import org.springframework.scheduling.annotation.EnableAsync;
 import org.springframework.security.oauth2.config.annotation.web.configuration.EnableResourceServer;
 import org.springframework.security.oauth2.config.annotation.web.configuration.EnableResourceServer;
 import org.springframework.transaction.annotation.EnableTransactionManagement;
 import org.springframework.transaction.annotation.EnableTransactionManagement;
 
 
@@ -11,6 +12,7 @@ import org.springframework.transaction.annotation.EnableTransactionManagement;
 @EnableFeignClients
 @EnableFeignClients
 @EnableResourceServer
 @EnableResourceServer
 @EnableTransactionManagement
 @EnableTransactionManagement
+@EnableAsync
 public class Application {
 public class Application {
 
 
     public static void main(String[] args) {
     public static void main(String[] args) {

+ 122 - 0
simulation-resource-server/src/main/java/com/css/simulation/resource/common/log/LogAdvice.java

@@ -0,0 +1,122 @@
+package com.css.simulation.resource.common.log;
+
+import api.common.pojo.common.ResponseBodyVO;
+import api.common.pojo.po.log.LogOperationPO;
+import api.common.util.LogUtil;
+import api.common.util.ObjectUtil;
+import com.css.simulation.resource.common.utils.AuthUtil;
+import com.css.simulation.resource.log.service.LogService;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.core.MethodParameter;
+import org.springframework.http.HttpHeaders;
+import org.springframework.http.MediaType;
+import org.springframework.http.server.ServerHttpRequest;
+import org.springframework.http.server.ServerHttpResponse;
+import org.springframework.web.bind.annotation.ControllerAdvice;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.servlet.mvc.method.annotation.ResponseBodyAdvice;
+
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+
+
+@ControllerAdvice
+public class LogAdvice implements ResponseBodyAdvice {
+
+    @Autowired
+    LogService logService;
+
+    @Override
+    public boolean supports(MethodParameter methodParameter, Class aClass) {
+        return true;
+    }
+
+    @Override
+    public Object beforeBodyWrite(Object o, MethodParameter methodParameter, MediaType mediaType, Class aClass, ServerHttpRequest serverHttpRequest, ServerHttpResponse serverHttpResponse) {
+        //没有操作标记则返回
+        String operationType = LogUtil.getOperationType();
+        LogUtil.remove();//线程标记清空
+        if(ObjectUtil.isNull(operationType)){
+            return o;
+        }
+        //异常后返回
+        if(o instanceof ResponseBodyVO){
+            boolean status = ((ResponseBodyVO) o).isStatus();
+            if(!status){
+                return o;
+            }
+        }
+        //类注解的模块名
+        Class<?> containingClass = methodParameter.getContainingClass();
+        RequestMapping classAnnotation = containingClass.getAnnotation(RequestMapping.class);
+        if(ObjectUtil.isNull(classAnnotation)){
+            return o;
+        }
+        String modelName = classAnnotation.name();
+        if(ObjectUtil.isNull(modelName)){
+            modelName = "未命名模块";
+        }
+        try {
+            //获取ip
+            String ip = getRemoteAddress(serverHttpRequest);
+            LogOperationPO po = new LogOperationPO();
+            po.setIp(ip);
+            po.setModule(modelName);
+            po.setOperationType(operationType);
+            po.setUserId(AuthUtil.getCurrentUserId());
+            po.setUsername(AuthUtil.getCurrentUsername());
+            logService.saveOperationLog(po);
+        }catch (Exception e){
+            //e.printStackTrace();
+        }
+        return o;
+    }
+
+    //IP地址获取
+    private String getRemoteAddress(ServerHttpRequest serverHttpRequest) {
+        HttpHeaders headers = serverHttpRequest.getHeaders();
+        String ip = headers.getFirst("x-forwarded-for");
+        if(ip != null && ip.length() != 0){
+            if(ip.indexOf(",") != -1){
+                ip = ip.split(",")[0];
+            }
+        }
+        if(ip == null || ip.length() == 0){
+            ip = headers.getFirst("Proxy-Client-IP");
+        }
+        if(ip == null || ip.length() == 0){
+            ip = headers.getFirst("WL-Proxy-Client-IP");
+        }
+        if(ip == null || ip.length() == 0){
+            ip = headers.getFirst("HTTP_CLIENT_IP");
+        }
+        if(ip == null || ip.length() == 0){
+            ip = headers.getFirst("HTTP_X_FORWARDED_FOR");
+        }
+        if(ip == null || ip.length() == 0){
+            ip = headers.getFirst("X-Real-IP");
+        }
+        if(ip == null || ip.length() == 0){
+            ip = serverHttpRequest.getRemoteAddress().getAddress().getHostAddress();
+        }
+        if(isIpv4(ip)){
+            return ip;
+        }else{
+            return "Illegal IP address";
+        }
+
+    }
+
+    //IP地址验证,防止非法地址
+    private boolean isIpv4(String ipAddress) {
+        String ip = "^(1\\d{2}|2[0-4]\\d|25[0-5]|[1-9]\\d|[1-9])\\."
+                +"(00?\\d|1\\d{2}|2[0-4]\\d|25[0-5]|[1-9]\\d|\\d)\\."
+                +"(00?\\d|1\\d{2}|2[0-4]\\d|25[0-5]|[1-9]\\d|\\d)\\."
+                +"(00?\\d|1\\d{2}|2[0-4]\\d|25[0-5]|[1-9]\\d|\\d)$";
+
+        Pattern pattern = Pattern.compile(ip);
+        Matcher matcher = pattern.matcher(ipAddress);
+        return matcher.matches();
+    }
+
+}

+ 10 - 0
simulation-resource-server/src/main/java/com/css/simulation/resource/common/utils/AuthUtil.java

@@ -39,4 +39,14 @@ public class AuthUtil {
         return userType;
         return userType;
     }
     }
 
 
+    /**
+     * 获取当前登录人username
+     */
+    public static String getCurrentUsername(){
+        Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
+        MyUserDetails userDetails = (MyUserDetails)authentication.getPrincipal();
+        String username = userDetails.getUsername();
+        return username;
+    }
+
 }
 }

+ 46 - 0
simulation-resource-server/src/main/java/com/css/simulation/resource/log/ctrl/LogCtrl.java

@@ -0,0 +1,46 @@
+package com.css.simulation.resource.log.ctrl;
+
+import api.common.pojo.common.ResponseBodyVO;
+import api.common.pojo.param.log.LogPageParam;
+import api.common.pojo.po.log.LogLoginPO;
+import api.common.pojo.po.log.LogOperationPO;
+import api.common.pojo.po.log.LogSystemPO;
+import com.css.simulation.resource.log.service.LogService;
+import com.github.pagehelper.PageInfo;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Controller;
+import org.springframework.web.bind.annotation.RequestBody;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.ResponseBody;
+
+@Controller
+@RequestMapping("/log")
+public class LogCtrl {
+
+    @Autowired
+    LogService logService;
+
+    @RequestMapping("/getLoginLogPageList")
+    @ResponseBody
+    public ResponseBodyVO<PageInfo<LogLoginPO>> getLoginLogPageList(@RequestBody LogPageParam pageParam){
+        ResponseBodyVO<PageInfo<LogLoginPO>> response = new ResponseBodyVO<PageInfo<LogLoginPO>>(ResponseBodyVO.Response.SUCCESS);
+        response.setInfo(logService.getLoginLogPageList(pageParam));
+        return response;
+    }
+
+    @RequestMapping("/getOperationLogPageList")
+    @ResponseBody
+    public ResponseBodyVO<PageInfo<LogOperationPO>> getOperationLogPageList(@RequestBody LogPageParam pageParam){
+        ResponseBodyVO<PageInfo<LogOperationPO>> response = new ResponseBodyVO<PageInfo<LogOperationPO>>(ResponseBodyVO.Response.SUCCESS);
+        response.setInfo(logService.getOperationLogPageList(pageParam));
+        return response;
+    }
+
+    @RequestMapping("/getSystemLogPageList")
+    @ResponseBody
+    public ResponseBodyVO<PageInfo<LogSystemPO>> getSystemLogPageList(@RequestBody LogPageParam pageParam){
+        ResponseBodyVO<PageInfo<LogSystemPO>> response = new ResponseBodyVO<PageInfo<LogSystemPO>>(ResponseBodyVO.Response.SUCCESS);
+        response.setInfo(logService.getSystemLogPageList(pageParam));
+        return response;
+    }
+}

+ 26 - 0
simulation-resource-server/src/main/java/com/css/simulation/resource/log/mapper/LogMapper.java

@@ -0,0 +1,26 @@
+package com.css.simulation.resource.log.mapper;
+
+import api.common.pojo.param.log.LogPageParam;
+import api.common.pojo.po.log.LogLoginPO;
+import api.common.pojo.po.log.LogOperationPO;
+import api.common.pojo.po.log.LogSystemPO;
+import org.apache.ibatis.annotations.Mapper;
+import org.springframework.stereotype.Repository;
+
+import java.util.List;
+
+@Mapper
+@Repository
+public interface LogMapper {
+
+    void insertOperationLog(LogOperationPO po);
+
+    List<LogLoginPO> getLoginLogPageList(LogPageParam pageParam);
+
+    List<LogOperationPO> getOperationLogPageList(LogPageParam pageParam);
+
+    List<LogSystemPO> getSystemLogPageList(LogPageParam pageParam);
+
+    void insertSystemLog(LogSystemPO po);
+
+}

+ 93 - 0
simulation-resource-server/src/main/java/com/css/simulation/resource/log/service/LogService.java

@@ -0,0 +1,93 @@
+package com.css.simulation.resource.log.service;
+
+import api.common.pojo.constants.LogConstants;
+import api.common.pojo.param.log.LogPageParam;
+import api.common.pojo.po.log.LogLoginPO;
+import api.common.pojo.po.log.LogOperationPO;
+import api.common.pojo.po.log.LogSystemPO;
+import api.common.pojo.po.system.UserPO;
+import api.common.util.ObjectUtil;
+import api.common.util.StringUtil;
+import api.common.util.TimeUtil;
+import com.css.simulation.resource.common.utils.AuthUtil;
+import com.css.simulation.resource.common.utils.PageUtil;
+import com.css.simulation.resource.log.mapper.LogMapper;
+import com.css.simulation.resource.system.service.DictService;
+import com.github.pagehelper.PageInfo;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.scheduling.annotation.Async;
+import org.springframework.stereotype.Service;
+
+import java.util.List;
+import java.util.Map;
+
+
+@Service
+public class LogService {
+
+    @Autowired
+    LogMapper logMapper;
+
+    @Autowired
+    DictService dictService;
+
+    @Async
+    public void saveOperationLog(LogOperationPO po) {
+        po.setId(StringUtil.getRandomUUID());
+        po.setCreateTime(TimeUtil.getNowForMysql());
+        logMapper.insertOperationLog(po);
+    }
+
+    public PageInfo<LogLoginPO> getLoginLogPageList(LogPageParam pageParam) {
+        PageUtil.setPageInfo(pageParam);
+        List<LogLoginPO> list = logMapper.getLoginLogPageList(pageParam);
+        return new PageInfo<>(list);
+    }
+
+    public PageInfo<LogOperationPO> getOperationLogPageList(LogPageParam pageParam) {
+        PageUtil.setPageInfo(pageParam);
+        List<LogOperationPO> list = logMapper.getOperationLogPageList(pageParam);
+        //字典翻译
+        Map<String, Map<String, String>> dictMaps = dictService.getDictMapsByTypes(LogConstants.MODULE_TYPE + "," + LogConstants.OPERATION_TYPE);
+        list.forEach(po ->{
+            po.setModule(dictMaps.get(LogConstants.MODULE_TYPE).get(po.getModule()));
+            po.setOperationType(dictMaps.get(LogConstants.OPERATION_TYPE).get(po.getOperationType()));
+        });
+        return new PageInfo<>(list);
+    }
+
+    public PageInfo<LogSystemPO> getSystemLogPageList(LogPageParam pageParam) {
+        PageUtil.setPageInfo(pageParam);
+        List<LogSystemPO> list = logMapper.getSystemLogPageList(pageParam);
+        //字典翻译
+        Map<String, Map<String, String>> dictMaps = dictService.getDictMapsByTypes(LogConstants.SYS_LOG_TYPE);
+        list.forEach(po ->{
+            po.setModule(dictMaps.get(LogConstants.SYS_LOG_TYPE).get(po.getModule()));
+            po.setOperationType(dictMaps.get(LogConstants.SYS_LOG_TYPE).get(po.getOperationType()));
+        });
+        return new PageInfo<>(list);
+    }
+
+    public void logUser(String operationType, UserPO userPO) {
+        try {
+            LogSystemPO po = new LogSystemPO();
+            po.setId(StringUtil.getRandomUUID());
+            po.setCreateTime(TimeUtil.getNowForMysql());
+            po.setUserId(AuthUtil.getCurrentUserId());
+            po.setUsername(AuthUtil.getCurrentUsername());
+            po.setRoleCode(AuthUtil.getCurrentUserRoleCode());
+            po.setModule(LogConstants.SYS_LOG_USER);
+            String userId = userPO.getId();
+            String username = userPO.getUsername();
+            if(ObjectUtil.isNull(username)){
+                username = "XX";
+            }
+            String content = username + " ( ID: " + userId + " )";
+            po.setContent(content);
+            po.setOperationType(operationType);
+            logMapper.insertSystemLog(po);
+        }catch (Exception e){
+            e.printStackTrace();
+        }
+    }
+}

+ 2 - 1
simulation-resource-server/src/main/java/com/css/simulation/resource/model/ctrl/VehicleCtrl.java

@@ -2,6 +2,7 @@ package com.css.simulation.resource.model.ctrl;
 
 
 
 
 import api.common.pojo.common.ResponseBodyVO;
 import api.common.pojo.common.ResponseBodyVO;
+import api.common.pojo.constants.LogConstants;
 import api.common.pojo.param.model.VehicleParam;
 import api.common.pojo.param.model.VehicleParam;
 import api.common.pojo.po.model.VehiclePO;
 import api.common.pojo.po.model.VehiclePO;
 import api.common.pojo.vo.model.VehicleVO;
 import api.common.pojo.vo.model.VehicleVO;
@@ -16,7 +17,7 @@ import org.springframework.web.bind.annotation.ResponseBody;
 import java.util.List;
 import java.util.List;
 
 
 @Controller
 @Controller
-@RequestMapping("/vehicle")
+@RequestMapping(value = "/vehicle",name = LogConstants.MODULE_VEHICLE)
 public class VehicleCtrl {
 public class VehicleCtrl {
 
 
     @Autowired
     @Autowired

+ 5 - 0
simulation-resource-server/src/main/java/com/css/simulation/resource/model/service/VehicleService.java

@@ -4,6 +4,7 @@ import api.common.pojo.constants.DictConstants;
 import api.common.pojo.param.model.VehicleParam;
 import api.common.pojo.param.model.VehicleParam;
 import api.common.pojo.po.model.VehiclePO;
 import api.common.pojo.po.model.VehiclePO;
 import api.common.pojo.vo.model.VehicleVO;
 import api.common.pojo.vo.model.VehicleVO;
+import api.common.util.LogUtil;
 import api.common.util.ObjectUtil;
 import api.common.util.ObjectUtil;
 import api.common.util.StringUtil;
 import api.common.util.StringUtil;
 import com.css.simulation.resource.common.utils.AuthUtil;
 import com.css.simulation.resource.common.utils.AuthUtil;
@@ -75,8 +76,10 @@ public class VehicleService {
             vehiclePO.setId(StringUtil.getRandomUUID());
             vehiclePO.setId(StringUtil.getRandomUUID());
             vehiclePO.setVehicleCode(StringUtil.getRandomCode());
             vehiclePO.setVehicleCode(StringUtil.getRandomCode());
             vehicleMapper.insert(vehiclePO);
             vehicleMapper.insert(vehiclePO);
+            LogUtil.insert();
         }else{//修改
         }else{//修改
             vehicleMapper.update(vehiclePO);
             vehicleMapper.update(vehiclePO);
+            LogUtil.update();
         }
         }
         return vehiclePO;
         return vehiclePO;
     }
     }
@@ -97,11 +100,13 @@ public class VehicleService {
         vehiclePO.setId(StringUtil.getRandomUUID());
         vehiclePO.setId(StringUtil.getRandomUUID());
         vehiclePO.setVehicleCode(StringUtil.getRandomCode());
         vehiclePO.setVehicleCode(StringUtil.getRandomCode());
         vehicleMapper.insert(vehiclePO);
         vehicleMapper.insert(vehiclePO);
+        LogUtil.share();
         return vehiclePO;
         return vehiclePO;
     }
     }
 
 
     public int delVehicleById(VehiclePO vehiclePO) {
     public int delVehicleById(VehiclePO vehiclePO) {
         PoUtil.initDelPo(vehiclePO);
         PoUtil.initDelPo(vehiclePO);
+        LogUtil.delete();
         return vehicleMapper.delVehicleById(vehiclePO);
         return vehicleMapper.delVehicleById(vehiclePO);
     }
     }
 }
 }

+ 1 - 1
simulation-resource-server/src/main/resources/logback-spring.xml

@@ -1,5 +1,5 @@
 <?xml version="1.0" encoding="UTF-8"?>
 <?xml version="1.0" encoding="UTF-8"?>
-<configuration debug="true">
+<configuration debug="false">
     <!-- 项目名称 -->
     <!-- 项目名称 -->
     <springProperty scop="context" name="PROJECT_NAME" source="spring.application.name" defaultValue="" />
     <springProperty scop="context" name="PROJECT_NAME" source="spring.application.name" defaultValue="" />
     <!--定义不同环境的日志文件的存储地址 使用相对路径-->
     <!--定义不同环境的日志文件的存储地址 使用相对路径-->

+ 128 - 0
simulation-resource-server/src/main/resources/mapper/log/LogMapper.xml

@@ -0,0 +1,128 @@
+<?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.css.simulation.resource.log.mapper.LogMapper" >
+
+    <insert id="insertOperationLog" parameterType="api.common.pojo.po.log.LogOperationPO">
+        INSERT INTO log_operation (
+          id,
+          user_id,
+          username,
+          ip,
+          module,
+          operationType,
+          create_time)
+        VALUES(
+          #{id,jdbcType=VARCHAR},
+          #{userId,jdbcType=VARCHAR},
+          #{username,jdbcType=VARCHAR},
+          #{ip,jdbcType=VARCHAR},
+          #{module,jdbcType=VARCHAR},
+          #{operationType,jdbcType=VARCHAR},
+          #{createTime,jdbcType=TIMESTAMP}
+        )
+    </insert>
+
+    <select id="getLoginLogPageList" parameterType="api.common.pojo.param.log.LogPageParam" resultType="api.common.pojo.po.log.LogLoginPO">
+        SELECT
+          user_id,
+          username,
+          ip,
+          state,
+          create_time
+        FROM log_login
+        WHERE 1=1
+        <if test="username != null and username != ''">
+            and username like CONCAT('%',#{username,jdbcType=VARCHAR},'%')
+        </if>
+        <if test="createTimeBegin != null">
+            and create_time &gt;= #{createTimeBegin,jdbcType=TIMESTAMP}
+        </if>
+        <if test="createTimeEnd != null">
+            and create_time &lt;= #{createTimeEnd,jdbcType=TIMESTAMP}
+        </if>
+        ORDER BY create_time DESC
+    </select>
+
+    <select id="getOperationLogPageList" parameterType="api.common.pojo.param.log.LogPageParam" resultType="api.common.pojo.po.log.LogOperationPO">
+        select
+          id,
+          user_id,
+          username,
+          ip,
+          module,
+          operationType,
+          create_time
+        FROM log_operation
+        WHERE 1=1
+        <if test="username != null and username != ''">
+            and username like CONCAT('%',#{username,jdbcType=VARCHAR},'%')
+        </if>
+        <if test="module != null and module != ''">
+            and module = #{module,jdbcType=VARCHAR}
+        </if>
+        <if test="operationType != null and operationType != ''">
+            and operation_type = #{operationType,jdbcType=VARCHAR}
+        </if>
+        <if test="createTimeBegin != null">
+            and create_time &gt;= #{createTimeBegin,jdbcType=TIMESTAMP}
+        </if>
+        <if test="createTimeEnd != null">
+            and create_time &lt;= #{createTimeEnd,jdbcType=TIMESTAMP}
+        </if>
+        ORDER BY create_time DESC
+    </select>
+
+    <select id="getSystemLogPageList" parameterType="api.common.pojo.param.log.LogPageParam" resultType="api.common.pojo.po.log.LogSystemPO">
+        SELECT
+          id,
+          user_id,
+          username,
+          role_code,
+          module,
+          operation_type,
+          content,
+          create_time
+        FROM log_system
+        WHERE 1=1
+        <if test="username != null and username != ''">
+            and username like CONCAT('%',#{username,jdbcType=VARCHAR},'%')
+        </if>
+        <if test="module != null and module != ''">
+            and module = #{module,jdbcType=VARCHAR}
+        </if>
+        <if test="operationType != null and operationType != ''">
+            and operation_type = #{operationType,jdbcType=VARCHAR}
+        </if>
+        <if test="content != null and content != ''">
+            and content like CONCAT('%',#{content,jdbcType=VARCHAR},'%')
+        </if>
+        <if test="createTimeBegin != null">
+            and create_time &gt;= #{createTimeBegin,jdbcType=TIMESTAMP}
+        </if>
+        <if test="createTimeEnd != null">
+            and create_time &lt;= #{createTimeEnd,jdbcType=TIMESTAMP}
+        </if>
+        ORDER BY create_time DESC
+    </select>
+
+    <insert id="insertSystemLog" parameterType="api.common.pojo.po.log.LogSystemPO">
+        INSERT INTO log_system(
+          id,
+          user_id,
+          username,
+          role_code,
+          module,
+          operation_type,
+          content,
+          create_time
+        )VALUES(
+          #{id,jdbcType=VARCHAR},
+          #{userId,jdbcType=VARCHAR},
+          #{username,jdbcType=VARCHAR},
+          #{roleCode,jdbcType=VARCHAR},
+          #{module,jdbcType=VARCHAR},
+          #{operationType,jdbcType=VARCHAR},
+          #{content,jdbcType=VARCHAR},
+          #{createTime,jdbcType=TIMESTAMP})
+    </insert>
+</mapper>