소스 검색

算法平台

LingxinMeng 2 년 전
부모
커밋
fccdcdf123
21개의 변경된 파일1046개의 추가작업 그리고 0개의 파일을 삭제
  1. 64 0
      simulation-resource-server/src/main/java/com/css/simulation/resource/server/api/advice/ExceptionHandlerControllerAdvice.java
  2. 50 0
      simulation-resource-server/src/main/java/com/css/simulation/resource/server/api/controller/LogController.java
  3. 281 0
      simulation-resource-server/src/main/java/com/css/simulation/resource/server/application/LogService.java
  4. 39 0
      simulation-resource-server/src/main/java/com/css/simulation/resource/server/infrastructure/common/configuration/FeignConfiguration.java
  5. 55 0
      simulation-resource-server/src/main/java/com/css/simulation/resource/server/infrastructure/common/configuration/OAuth2Configuration.java
  6. 84 0
      simulation-resource-server/src/main/java/com/css/simulation/resource/server/infrastructure/common/configuration/TransactionConfiguration.java
  7. 14 0
      simulation-resource-server/src/main/java/com/css/simulation/resource/server/infrastructure/common/configuration/git/GitConfiguration.java
  8. 24 0
      simulation-resource-server/src/main/java/com/css/simulation/resource/server/infrastructure/common/configuration/kafka/KafkaAdminConfiguration.java
  9. 18 0
      simulation-resource-server/src/main/java/com/css/simulation/resource/server/infrastructure/common/configuration/sms/SmsConfiguration.java
  10. 29 0
      simulation-resource-server/src/main/java/com/css/simulation/resource/server/infrastructure/common/demo/ctrl/TestCtrl.java
  11. 17 0
      simulation-resource-server/src/main/java/com/css/simulation/resource/server/infrastructure/common/demo/mapper/TestMapper.java
  12. 37 0
      simulation-resource-server/src/main/java/com/css/simulation/resource/server/infrastructure/common/demo/service/TestService.java
  13. 35 0
      simulation-resource-server/src/main/java/com/css/simulation/resource/server/infrastructure/common/oauth/AuthorityCheck.java
  14. 21 0
      simulation-resource-server/src/main/java/com/css/simulation/resource/server/infrastructure/common/oauth/AuthorizationHolder.java
  15. 42 0
      simulation-resource-server/src/main/java/com/css/simulation/resource/server/infrastructure/common/oauth/MyUserAuthenticationConverter.java
  16. 59 0
      simulation-resource-server/src/main/java/com/css/simulation/resource/server/infrastructure/common/oauth/MyUserDetails.java
  17. 17 0
      simulation-resource-server/src/main/java/com/css/simulation/resource/server/infrastructure/common/oauth/OauthParameter.java
  18. 59 0
      simulation-resource-server/src/main/java/com/css/simulation/resource/server/infrastructure/common/utils/AuthUtil.java
  19. 21 0
      simulation-resource-server/src/main/java/com/css/simulation/resource/server/infrastructure/common/utils/PageUtil.java
  20. 48 0
      simulation-resource-server/src/main/java/com/css/simulation/resource/server/infrastructure/common/utils/PoUtil.java
  21. 32 0
      simulation-resource-server/src/main/java/com/css/simulation/resource/server/infrastructure/mysql/mapper/LogMapper.java

+ 64 - 0
simulation-resource-server/src/main/java/com/css/simulation/resource/server/api/advice/ExceptionHandlerControllerAdvice.java

@@ -0,0 +1,64 @@
+package com.css.simulation.resource.server.api.advice;
+
+import api.common.pojo.common.ResponseBodyVO;
+import lombok.extern.slf4j.Slf4j;
+import org.springframework.http.converter.HttpMessageNotReadableException;
+import org.springframework.security.access.AccessDeniedException;
+import org.springframework.web.bind.MethodArgumentNotValidException;
+import org.springframework.web.bind.annotation.ExceptionHandler;
+import org.springframework.web.bind.annotation.ResponseBody;
+import org.springframework.web.bind.annotation.RestControllerAdvice;
+
+import java.util.Objects;
+
+@RestControllerAdvice
+@Slf4j
+public class ExceptionHandlerControllerAdvice {
+    /**
+     * 方法参数校验
+     */
+    @ExceptionHandler(MethodArgumentNotValidException.class)
+    public ResponseBodyVO<Object> handleMethodArgumentNotValidException(MethodArgumentNotValidException e) {
+        log.error(e.getMessage(), e);
+        return new ResponseBodyVO<>(ResponseBodyVO.Response.SERVER_FAILURE, Objects.requireNonNull(e.getBindingResult().getFieldError()).getDefaultMessage());
+    }
+
+    /**
+     * 请求体缺失异常统一处理
+     */
+    @ExceptionHandler(HttpMessageNotReadableException.class)
+    public ResponseBodyVO<Object> handleHttpMessageNotReadableException(HttpMessageNotReadableException e) {
+        log.error(e.getMessage(), e);
+        return new ResponseBodyVO<>(ResponseBodyVO.Response.SERVER_FAILURE, "Required request body is missing!");
+    }
+
+
+    /**
+     * 权限校验异常统一处理
+     */
+    @ExceptionHandler(AccessDeniedException.class)
+    public ResponseBodyVO<Object> handleAccessDeniedException(AccessDeniedException e) {
+        log.error(e.getMessage(), e);
+        return new ResponseBodyVO<>(ResponseBodyVO.Response.SERVER_FAILURE, "Access is denied!");
+    }
+
+    /**
+     * 权限校验异常统一处理
+     */
+    @ExceptionHandler(RuntimeException.class)
+    public ResponseBodyVO<Object> handleRuntimeException(RuntimeException e) {
+        log.error(e.getMessage(), e);
+        return new ResponseBodyVO<>(ResponseBodyVO.Response.SERVER_FAILURE, e.getMessage());
+    }
+
+    /**
+     * 服务器错误异常统一处理
+     */
+    @ExceptionHandler(Exception.class)
+    @ResponseBody
+    public ResponseBodyVO<Object> handleException(Exception e) {
+        log.error(e.getMessage(), e);
+        return new ResponseBodyVO<>(ResponseBodyVO.Response.SERVER_FAILURE, "服务器错误!");
+    }
+
+}

+ 50 - 0
simulation-resource-server/src/main/java/com/css/simulation/resource/server/api/controller/LogController.java

@@ -0,0 +1,50 @@
+package com.css.simulation.resource.server.api.controller;
+
+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.server.application.LogService;
+import com.github.pagehelper.PageInfo;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.security.access.prepost.PreAuthorize;
+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 LogController {
+
+    @Autowired
+    LogService logService;
+
+    @RequestMapping("/getLoginLogPageList")
+    @ResponseBody
+    @PreAuthorize("@AuthorityCheck.admin()")
+    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
+    @PreAuthorize("@AuthorityCheck.adminAndUser()")
+    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
+    @PreAuthorize("@AuthorityCheck.admin()")
+    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;
+    }
+}

+ 281 - 0
simulation-resource-server/src/main/java/com/css/simulation/resource/server/application/LogService.java

@@ -0,0 +1,281 @@
+package com.css.simulation.resource.server.application;
+
+import api.common.pojo.constants.DictConstants;
+import api.common.pojo.constants.LogConstants;
+import api.common.pojo.param.log.LogPageParam;
+import api.common.pojo.param.model.VehiclePageParam;
+import api.common.pojo.param.scene.SystemUserSceneParam;
+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.model.VehicleTempPO;
+import api.common.pojo.po.scene.SystemScenePackagePO;
+import api.common.pojo.po.system.ClusterPO;
+import api.common.pojo.po.system.ParameterPO;
+import api.common.pojo.po.system.UserPO;
+import api.common.pojo.vo.model.VehicleTempVO;
+import api.common.pojo.vo.scene.UserSceneVO;
+import api.common.pojo.vo.system.UserVO;
+import api.common.util.ObjectUtil;
+import api.common.util.StringUtil;
+import api.common.util.TimeUtil;
+import com.css.simulation.resource.server.infrastructure.common.utils.AuthUtil;
+import com.css.simulation.resource.server.infrastructure.common.utils.PageUtil;
+import com.css.simulation.resource.server.infrastructure.mysql.mapper.LogMapper;
+import com.css.simulation.resource.server.infrastructure.mysql.mapper.UserMapper;
+import com.css.simulation.resource.server.infrastructure.mysql.mapper.VehicleTempMapper;
+import com.github.pagehelper.PageInfo;
+import org.springframework.scheduling.annotation.Async;
+import org.springframework.stereotype.Service;
+
+import javax.annotation.Resource;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Map;
+
+
+@Service
+public class LogService {
+
+    @Resource
+    private LogMapper logMapper;
+
+    @Resource
+    private DictService dictService;
+
+    @Resource
+    private UserMapper userMapper;
+
+    @Resource
+    private VehicleTempMapper vehicleTempMapper;
+
+    /**
+     * 保存普通操作日志(异步)
+     */
+    @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 = new ArrayList<>();
+        String roleCode = AuthUtil.getCurrentUserRoleCode();
+        if (DictConstants.ROLE_CODE_UESR.equals(roleCode)) {//普通用户
+            String currentUserId = AuthUtil.getCurrentUserId();
+            pageParam.setContent(currentUserId);//借用该字段传递当前用户id
+            list = logMapper.getUserOperationLogPageList(pageParam);
+        } else {//管理员
+            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 + "," + DictConstants.ROLE_CODE);
+        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()));
+            po.setRoleCode(dictMaps.get(DictConstants.ROLE_CODE).get(po.getRoleCode()));
+        });
+        return new PageInfo<>(list);
+    }
+
+    /**
+     * 记录用户管理模块日志
+     */
+    public void logUser(String operationType, UserPO userPO) {
+        try {
+            LogSystemPO po = getLogSystemPO(LogConstants.SYS_LOG_USER, operationType);
+            String userId = userPO.getId();
+            String username = userPO.getUsername();
+            if (ObjectUtil.isNull(username)) {
+                UserVO userVO = userMapper.getUserInfo(userId);
+                username = userVO.getUsername();
+            }
+            String content = username + " ( ID: " + userId + " )";
+            po.setContent(content);
+            logMapper.insertSystemLog(po);
+        } catch (Exception e) {
+            e.printStackTrace();
+        }
+    }
+
+    /**
+     * 记录车辆模板管理模块日志
+     */
+    public void logVehicle(String operationType, VehicleTempPO vehicleTempPO) {
+        try {
+            LogSystemPO po = getLogSystemPO(LogConstants.SYS_LOG_VEHICLE, operationType);
+            String vehicleTempId = vehicleTempPO.getId();
+            String modelLabel = vehicleTempPO.getModelLabel();
+            if (ObjectUtil.isNull(modelLabel)) {
+                VehiclePageParam param = new VehiclePageParam();
+                param.setId(vehicleTempId);
+                VehicleTempVO vehicleTempInfo = vehicleTempMapper.getVehicleTempInfo(param);
+                modelLabel = vehicleTempInfo.getModelLabel();
+            }
+            String content = modelLabel + " ( ID: " + vehicleTempId + " )";
+            po.setContent(content);
+            logMapper.insertSystemLog(po);
+        } catch (Exception e) {
+            e.printStackTrace();
+        }
+    }
+
+    /**
+     * 记录参数管理模块日志
+     */
+    public void logParameter(String operationType, ParameterPO parameterPO) {
+        try {
+            LogSystemPO po = getLogSystemPO(LogConstants.SYS_LOG_PARAM, operationType);
+            String paramId = parameterPO.getId();
+            String userId = parameterPO.getUserId();
+            String userName = parameterPO.getUserName();
+            String content = "账户:" + userName + " ( ID: " + userId + " ); 参数配置" + " ( ID: " + paramId + " )";
+            po.setContent(content);
+            logMapper.insertSystemLog(po);
+        } catch (Exception e) {
+            e.printStackTrace();
+        }
+    }
+
+    /**
+     * 记录集群管理模块日志
+     */
+    public void logCluster(String operationType, ClusterPO clusterPO) {
+        try {
+            LogSystemPO po = getLogSystemPO(LogConstants.SYS_LOG_CLUSTER, operationType);
+            String clusterId = clusterPO.getId();
+            String userId = clusterPO.getUserId();
+            String userName = clusterPO.getUserName();
+            String content = "账户:" + userName + " ( ID: " + userId + " ); 节点配置" + " ( ID: " + clusterId + " )";
+            po.setContent(content);
+            logMapper.insertSystemLog(po);
+        } catch (Exception e) {
+            e.printStackTrace();
+        }
+    }
+
+    /**
+     * 获取系统管理日志对象
+     */
+    private LogSystemPO getLogSystemPO(String module, String operationType) {
+        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(module);
+        po.setOperationType(operationType);
+        return po;
+    }
+
+    /**
+     * 记录场景包模块日志
+     */
+    public void logScenePackage(String operationType, SystemScenePackagePO packagePO, SystemUserSceneParam params) {
+        try {
+            LogSystemPO po = getLogSystemPO(LogConstants.SYS_LOG_PACKAGE, operationType);
+            //获取当前登录人姓名
+            String content = null;
+            if (operationType.equals(LogConstants.SYS_LOG_PACKAGE_DELETE)) {
+                content = "删除场景包:" + packagePO.getPackageName() + "(ID:" + packagePO.getId() + ")";
+            } else if (operationType.equals(LogConstants.SYS_LOG_PACKAGE_UPDATE)) {
+                content = "编辑场景包:" + packagePO.getPackageName() + "(ID:" + packagePO.getId() + ")";
+            } else if (operationType.equals(LogConstants.SYS_LOG_PACKAGE_INSERT)) {
+                content = "创建场景包:" + packagePO.getPackageName() + "(ID:" + packagePO.getId() + ")";
+            } else if (operationType.equals(LogConstants.SYS_LOG_PACKAGE_DISTRIBUTION)) {
+                List<UserSceneVO> users = params.getUserIds();
+                StringBuffer sb = new StringBuffer();
+                for (UserSceneVO vo : users) {
+                    sb.append("、").append(vo.getUserName()).append("((ID:").append(vo.getUserId()).append(")");
+                }
+                sb.deleteCharAt(0);
+                content = "分配场景包:" + params.getPackageName() + "(ID:" + params.getPackageId() + ")给用户:" + sb.toString();
+            } else if (operationType.equals(LogConstants.SYS_LOG_PACKAGE_DISTRIBUTION_DELETE)) {
+                List<UserSceneVO> users = params.getUserIds();
+                StringBuffer sb = new StringBuffer();
+                for (UserSceneVO vo : users) {
+                    sb.append("、").append(vo.getUserName()).append("((ID:").append(vo.getUserId()).append(")");
+                }
+                sb.deleteCharAt(0);
+                content = "分配场景包:" + params.getPackageName() + "(ID:" + params.getPackageId() + ")时移除用户:" + sb.toString();
+            }
+            po.setContent(content);
+            logMapper.insertSystemLog(po);
+        } catch (Exception e) {
+            e.printStackTrace();
+        }
+    }
+
+    /**
+     * 记录场景包分配模块日志
+     */
+    public void logSystemUserSceneByPackageId(String operationType, SystemUserSceneParam param, String packageCount) {
+        try {
+            LogSystemPO po = getLogSystemPO(LogConstants.SYS_LOG_PACKAGE_GRANT, operationType);
+            String content = param.getUserName() + "(ID" + param.getUserId() + ")" + "分配场景包:" + packageCount;
+            po.setContent(content);
+            logMapper.insertSystemLog(po);
+        } catch (Exception e) {
+            e.printStackTrace();
+        }
+    }
+
+    /**
+     * 记录场景库管理模块日志
+     */
+    public void logSceneDelete(String operationType, Map map) {
+        try {
+            LogSystemPO po = getLogSystemPO(LogConstants.SYS_LOG_SCENE, operationType);
+            Map<String, String> mapType = dictService.getDictMapByType(DictConstants.SCENE_TYPE);
+            String content = "删除" + mapType.get(map.get("type")) + ":" + map.get("sceneName");
+            po.setContent(content);
+            logMapper.insertSystemLog(po);
+        } catch (Exception e) {
+            e.printStackTrace();
+        }
+    }
+
+    /**
+     * 记录场景上传模块日志
+     */
+    public void logSceneUpload(String operationType, String content) {
+        try {
+            LogSystemPO po = getLogSystemPO(LogConstants.SYS_LOG_SCENE_TASK, operationType);
+            //获取当前登录人姓名
+            po.setContent(content);
+            logMapper.insertSystemLog(po);
+        } catch (Exception e) {
+            e.printStackTrace();
+        }
+    }
+}

+ 39 - 0
simulation-resource-server/src/main/java/com/css/simulation/resource/server/infrastructure/common/configuration/FeignConfiguration.java

@@ -0,0 +1,39 @@
+package com.css.simulation.resource.server.infrastructure.common.configuration;
+
+import api.common.util.ObjectUtil;
+import com.css.simulation.resource.server.infrastructure.common.oauth.AuthorizationHolder;
+import feign.Logger;
+import feign.RequestInterceptor;
+import feign.RequestTemplate;
+import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.Configuration;
+import org.springframework.web.context.request.RequestContextHolder;
+import org.springframework.web.context.request.ServletRequestAttributes;
+
+import javax.servlet.http.HttpServletRequest;
+
+/**
+ * 转发 token
+ */
+@Configuration
+public class FeignConfiguration implements RequestInterceptor {
+
+    @Bean
+    public Logger.Level feignLoggerLevel() {
+        return Logger.Level.FULL;
+    }
+
+    @Override
+    public void apply(RequestTemplate requestTemplate) {
+        ServletRequestAttributes attributes = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes();
+        String authorization = "";
+        if(ObjectUtil.isNull(attributes)){
+            authorization = AuthorizationHolder.getAuthorization();
+            AuthorizationHolder.remove();
+        }else{
+            HttpServletRequest request = attributes.getRequest();
+            authorization = request.getHeader("Authorization");
+        }
+        requestTemplate.header("Authorization", authorization);
+    }
+}

+ 55 - 0
simulation-resource-server/src/main/java/com/css/simulation/resource/server/infrastructure/common/configuration/OAuth2Configuration.java

@@ -0,0 +1,55 @@
+package com.css.simulation.resource.server.infrastructure.common.configuration;
+
+import com.css.simulation.resource.server.infrastructure.common.oauth.MyUserAuthenticationConverter;
+import com.css.simulation.resource.server.infrastructure.common.oauth.OauthParameter;
+import org.springframework.context.annotation.Configuration;
+import org.springframework.security.config.annotation.web.builders.HttpSecurity;
+import org.springframework.security.config.http.SessionCreationPolicy;
+import org.springframework.security.oauth2.config.annotation.web.configuration.ResourceServerConfigurerAdapter;
+import org.springframework.security.oauth2.config.annotation.web.configurers.ResourceServerSecurityConfigurer;
+import org.springframework.security.oauth2.provider.token.DefaultAccessTokenConverter;
+import org.springframework.security.oauth2.provider.token.RemoteTokenServices;
+
+import javax.annotation.Resource;
+
+@Configuration
+public class OAuth2Configuration extends ResourceServerConfigurerAdapter {
+
+    @Resource
+    private OauthParameter oauthParameter;
+
+    @Resource
+    MyUserAuthenticationConverter myUserAuthenticationConverter;
+
+    @Override
+    public void configure(ResourceServerSecurityConfigurer resources) {
+        //令牌解析服务配置
+        RemoteTokenServices services = new RemoteTokenServices();
+        services.setCheckTokenEndpointUrl(oauthParameter.getCheckTokenEndpointUrl());  // 需要在授权服务器公开 /oauth/check_token
+        services.setClientId(oauthParameter.getClientId());
+        services.setClientSecret(oauthParameter.getClientSecret());
+        //自定义令牌转换器
+        DefaultAccessTokenConverter defaultAccessTokenConverter = new DefaultAccessTokenConverter();
+        defaultAccessTokenConverter.setUserTokenConverter(myUserAuthenticationConverter);
+        services.setAccessTokenConverter(defaultAccessTokenConverter);
+        resources.resourceId(oauthParameter.getResourceId())      // 资源 id
+                .tokenServices(services)    // 使用远程服务验证令牌的服务
+                .stateless(true);   // 无状态模式,即无需用户登录,无 session
+    }
+
+    /**
+     * 配置拦截请求,通过 scope
+     */
+    @Override
+    public void configure(HttpSecurity http) throws Exception {
+        http.csrf().disable()   // 禁用 csrf
+                .sessionManagement().sessionCreationPolicy(SessionCreationPolicy.STATELESS)// 无状态验证
+                .and()
+                .authorizeRequests()
+                .antMatchers("/**/report/**").access("#oauth2.hasScope('other')")//算法平台接口
+                .antMatchers("/**/monitor/createAutomaticSubProject").permitAll()//定时任务接口
+                .antMatchers("/druid/**").permitAll()
+                .anyRequest().access("#oauth2.hasScope('all')") // 拦截所有请求判断 scope
+        ;
+    }
+}

+ 84 - 0
simulation-resource-server/src/main/java/com/css/simulation/resource/server/infrastructure/common/configuration/TransactionConfiguration.java

@@ -0,0 +1,84 @@
+package com.css.simulation.resource.server.infrastructure.common.configuration;
+
+import org.springframework.aop.framework.autoproxy.BeanNameAutoProxyCreator;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.beans.factory.annotation.Qualifier;
+import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.Configuration;
+import org.springframework.jdbc.datasource.DataSourceTransactionManager;
+import org.springframework.transaction.TransactionDefinition;
+import org.springframework.transaction.TransactionManager;
+import org.springframework.transaction.interceptor.*;
+
+import javax.sql.DataSource;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.Map;
+
+/**
+ * 声明式事务配置
+ */
+@Configuration
+public class TransactionConfiguration {
+
+    @Autowired
+    DataSource dataSource;
+
+    @Bean(name = "masterTransactionManager")
+    public DataSourceTransactionManager masterTransactionManager(DataSource dataSource) {
+        return new DataSourceTransactionManager(dataSource);
+    }
+
+    @Autowired
+    @Qualifier(value = "masterTransactionManager")
+    private TransactionManager transactionManager;
+
+    @Bean
+    public TransactionInterceptor txAdvice() {
+
+        /*只读事务,不做更新操作*/
+        RuleBasedTransactionAttribute readOnlyTx = new RuleBasedTransactionAttribute();
+        readOnlyTx.setReadOnly(true);
+        readOnlyTx.setPropagationBehavior(TransactionDefinition.PROPAGATION_NOT_SUPPORTED);
+
+        /*当前存在事务就使用当前事务,当前不存在事务就创建一个新的事务*/
+        RuleBasedTransactionAttribute requiredTx = new RuleBasedTransactionAttribute();
+        requiredTx.setRollbackRules(Collections.singletonList(new RollbackRuleAttribute(Exception.class)));
+        requiredTx.setPropagationBehavior(TransactionDefinition.PROPAGATION_REQUIRED);
+        requiredTx.setTimeout(5000);
+
+
+        Map<String, TransactionAttribute> txMap = new HashMap<>();
+        txMap.put("save*", requiredTx);
+        txMap.put("insert*", requiredTx);
+        txMap.put("update*", requiredTx);
+        txMap.put("remove*", requiredTx);
+        txMap.put("add*", requiredTx);
+        txMap.put("share*", requiredTx);
+        txMap.put("fx*", requiredTx);
+        txMap.put("del*", requiredTx);
+        /*select,count开头的方法,开启只读,提高数据库访问性能*/
+        txMap.put("select*", readOnlyTx);
+        txMap.put("query*", readOnlyTx);
+        txMap.put("get*", readOnlyTx);
+        txMap.put("list*", readOnlyTx);
+        txMap.put("find*", readOnlyTx);
+        txMap.put("count*", readOnlyTx);
+        txMap.put("*", requiredTx);
+
+        NameMatchTransactionAttributeSource source = new NameMatchTransactionAttributeSource();
+        source.setNameMap(txMap);
+
+        return new TransactionInterceptor(transactionManager, source);
+    }
+
+    @Bean
+    public BeanNameAutoProxyCreator txProxy() {
+        final BeanNameAutoProxyCreator creator = new BeanNameAutoProxyCreator();
+        creator.setInterceptorNames("txAdvice");
+        creator.setBeanNames("*Service");
+        creator.setProxyTargetClass(true);
+        return creator;
+    }
+
+}

+ 14 - 0
simulation-resource-server/src/main/java/com/css/simulation/resource/server/infrastructure/common/configuration/git/GitConfiguration.java

@@ -0,0 +1,14 @@
+package com.css.simulation.resource.server.infrastructure.common.configuration.git;
+
+import lombok.Data;
+import org.springframework.boot.context.properties.ConfigurationProperties;
+import org.springframework.context.annotation.Configuration;
+
+@Configuration
+@ConfigurationProperties(prefix = "git")
+@Data
+public class GitConfiguration {
+    private String name;
+    private String url;
+    private String tempDirectory;
+}

+ 24 - 0
simulation-resource-server/src/main/java/com/css/simulation/resource/server/infrastructure/common/configuration/kafka/KafkaAdminConfiguration.java

@@ -0,0 +1,24 @@
+package com.css.simulation.resource.server.infrastructure.common.configuration.kafka;
+
+import org.apache.kafka.clients.admin.Admin;
+import org.apache.kafka.clients.admin.KafkaAdminClient;
+import org.apache.kafka.clients.producer.ProducerConfig;
+import org.springframework.beans.factory.annotation.Value;
+import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.Configuration;
+
+import java.util.Properties;
+
+@Configuration
+public class KafkaAdminConfiguration {
+
+    @Value("${spring.kafka.bootstrap-servers}")
+    private String bootstrapServers;    // 服务器
+
+    @Bean("myKafkaAdmin")
+    public Admin admin() {
+        Properties properties = new Properties();
+        properties.put(ProducerConfig.BOOTSTRAP_SERVERS_CONFIG, bootstrapServers);
+        return KafkaAdminClient.create(properties);
+    }
+}

+ 18 - 0
simulation-resource-server/src/main/java/com/css/simulation/resource/server/infrastructure/common/configuration/sms/SmsConfiguration.java

@@ -0,0 +1,18 @@
+package com.css.simulation.resource.server.infrastructure.common.configuration.sms;
+
+import lombok.Data;
+import org.springframework.boot.context.properties.ConfigurationProperties;
+import org.springframework.context.annotation.Configuration;
+
+@Configuration
+@ConfigurationProperties(prefix = "sms")
+@Data
+public class SmsConfiguration {
+    private String secretId;
+    private String secretKey;
+    private String sdkAppId;
+    private String signName;
+    private String templateIdForReset;
+    private String templateIdForCreate;
+    private String kafkaTopic;
+}

+ 29 - 0
simulation-resource-server/src/main/java/com/css/simulation/resource/server/infrastructure/common/demo/ctrl/TestCtrl.java

@@ -0,0 +1,29 @@
+package com.css.simulation.resource.server.infrastructure.common.demo.ctrl;
+
+import api.common.pojo.common.ResponseBodyVO;
+import api.common.pojo.param.demo.TestPageParam;
+import api.common.pojo.vo.demo.TestVO;
+import com.css.simulation.resource.server.infrastructure.common.demo.service.TestService;
+import com.github.pagehelper.PageInfo;
+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;
+
+import javax.annotation.Resource;
+
+@Controller
+@RequestMapping("/test")
+public class TestCtrl {
+
+    @Resource
+    private TestService testService;
+
+    @RequestMapping("/getTestPageList")
+    @ResponseBody
+    public ResponseBodyVO<PageInfo<TestVO>> getTestPageList(@RequestBody TestPageParam pageParam){
+        ResponseBodyVO<PageInfo<TestVO>> response = new ResponseBodyVO<PageInfo<TestVO>>(ResponseBodyVO.Response.SUCCESS);
+        response.setInfo(testService.getTestPageList(pageParam));
+        return response;
+    }
+}

+ 17 - 0
simulation-resource-server/src/main/java/com/css/simulation/resource/server/infrastructure/common/demo/mapper/TestMapper.java

@@ -0,0 +1,17 @@
+package com.css.simulation.resource.server.infrastructure.common.demo.mapper;
+
+
+import api.common.pojo.param.demo.TestPageParam;
+import api.common.pojo.vo.demo.TestVO;
+import org.apache.ibatis.annotations.Mapper;
+import org.springframework.stereotype.Repository;
+
+import java.util.List;
+
+@Mapper
+@Repository
+public interface TestMapper {
+
+    List<TestVO> getTestPageList(TestPageParam params);
+
+}

+ 37 - 0
simulation-resource-server/src/main/java/com/css/simulation/resource/server/infrastructure/common/demo/service/TestService.java

@@ -0,0 +1,37 @@
+package com.css.simulation.resource.server.infrastructure.common.demo.service;
+
+import api.common.pojo.constants.DictConstants;
+import api.common.pojo.param.demo.TestPageParam;
+import api.common.pojo.vo.demo.TestVO;
+import com.css.simulation.resource.server.infrastructure.common.demo.mapper.TestMapper;
+import com.css.simulation.resource.server.infrastructure.common.utils.PageUtil;
+import com.css.simulation.resource.server.application.DictService;
+import com.github.pagehelper.PageInfo;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
+
+import java.util.List;
+import java.util.Map;
+
+@Service
+public class TestService {
+
+    @Autowired
+    TestMapper testMapper;
+
+    @Autowired
+    DictService dictService;
+
+    public PageInfo<TestVO> getTestPageList(TestPageParam params) {
+        PageUtil.setPageInfo(params);
+        //params.setCreateUserId(AuthUtil.getCurrentUserId());
+        List<TestVO> list = testMapper.getTestPageList(params);
+        //字典翻译
+        //Map<String, Map<String, String>> dictMapsByTypes = dictService.getDictMapsByTypes(DictConstants.LEVEL + "," + DictConstants.DRIVE_TYPE);
+        Map<String, Map<String, String>> dictMapsByTypes = dictService.getDictMapsByTypes(DictConstants.LEVEL,DictConstants.DRIVE_TYPE);
+        list.forEach(testVO ->{
+            testVO.setLevel_name(dictMapsByTypes.get(DictConstants.LEVEL).get(testVO.getLevel()));
+        });
+        return new PageInfo<>(list);
+    }
+}

+ 35 - 0
simulation-resource-server/src/main/java/com/css/simulation/resource/server/infrastructure/common/oauth/AuthorityCheck.java

@@ -0,0 +1,35 @@
+package com.css.simulation.resource.server.infrastructure.common.oauth;
+
+import api.common.pojo.constants.DictConstants;
+import com.css.simulation.resource.server.infrastructure.common.utils.AuthUtil;
+import org.springframework.stereotype.Component;
+
+@Component("AuthorityCheck")
+public class AuthorityCheck {
+
+    public boolean admin(){
+        String roleCode = AuthUtil.getCurrentUserRoleCode();
+        switch (roleCode){
+            case DictConstants.ROLE_CODE_SYSADMIN:
+                return true;
+            case DictConstants.ROLE_CODE_ADMIN:
+                return true;
+            default:
+                return false;
+        }
+    }
+
+    public boolean adminAndUser(){
+        String roleCode = AuthUtil.getCurrentUserRoleCode();
+        switch (roleCode){
+            case DictConstants.ROLE_CODE_SYSADMIN:
+                return true;
+            case DictConstants.ROLE_CODE_ADMIN:
+                return true;
+            case DictConstants.ROLE_CODE_UESR:
+                return true;
+            default:
+                return false;
+        }
+    }
+}

+ 21 - 0
simulation-resource-server/src/main/java/com/css/simulation/resource/server/infrastructure/common/oauth/AuthorizationHolder.java

@@ -0,0 +1,21 @@
+package com.css.simulation.resource.server.infrastructure.common.oauth;
+
+import org.springframework.core.NamedInheritableThreadLocal;
+
+public class AuthorizationHolder {
+
+    private static final ThreadLocal<String> inheritableRequestAttributesHolder = new NamedInheritableThreadLocal("Authorization");
+
+    public static void setAuthorization(String authorization){
+        inheritableRequestAttributesHolder.set(authorization);
+    }
+
+    public static String getAuthorization(){
+        return inheritableRequestAttributesHolder.get();
+    }
+
+    public static void remove(){
+        inheritableRequestAttributesHolder.remove();
+    }
+
+}

+ 42 - 0
simulation-resource-server/src/main/java/com/css/simulation/resource/server/infrastructure/common/oauth/MyUserAuthenticationConverter.java

@@ -0,0 +1,42 @@
+package com.css.simulation.resource.server.infrastructure.common.oauth;
+
+import org.springframework.security.authentication.UsernamePasswordAuthenticationToken;
+import org.springframework.security.core.Authentication;
+import org.springframework.security.core.GrantedAuthority;
+import org.springframework.security.core.authority.AuthorityUtils;
+import org.springframework.security.oauth2.provider.token.DefaultUserAuthenticationConverter;
+import org.springframework.stereotype.Component;
+import org.springframework.util.StringUtils;
+
+import java.util.*;
+
+@Component
+public class MyUserAuthenticationConverter extends DefaultUserAuthenticationConverter {
+
+    @Override
+    public Authentication extractAuthentication(Map<String, ?> map) {
+        List<GrantedAuthority> list = new LinkedList<>();
+        //解析权限
+        if (map.containsKey(AUTHORITIES)) {
+            Object authorities = map.get(AUTHORITIES);
+            if (authorities instanceof String) {
+                list = AuthorityUtils.commaSeparatedStringToAuthorityList((String) authorities);
+            } else if (authorities instanceof Collection) {
+                list = AuthorityUtils.commaSeparatedStringToAuthorityList(StringUtils.collectionToCommaDelimitedString((Collection) authorities));
+            } else {
+                throw new IllegalArgumentException("Authorities must be either a String or a Collection");
+            }
+        }
+        //解析当前登录人信息
+        MyUserDetails userDetails = new MyUserDetails();
+        userDetails.setId((String) map.get("id"));
+        userDetails.setUsername((String) map.get("username"));
+        userDetails.setRoleCode((String) map.get("roleCode"));
+        userDetails.setUseType((String) map.get("useType"));
+        userDetails.setCreateUserId((String) map.get("createUserId"));
+        return new UsernamePasswordAuthenticationToken(userDetails, "N/A", list);
+    }
+
+
+
+}

+ 59 - 0
simulation-resource-server/src/main/java/com/css/simulation/resource/server/infrastructure/common/oauth/MyUserDetails.java

@@ -0,0 +1,59 @@
+package com.css.simulation.resource.server.infrastructure.common.oauth;
+
+import lombok.AllArgsConstructor;
+import lombok.Builder;
+import lombok.Data;
+import lombok.NoArgsConstructor;
+import org.springframework.security.core.GrantedAuthority;
+import org.springframework.security.core.userdetails.UserDetails;
+
+import java.io.Serializable;
+import java.util.Set;
+
+@Data
+@Builder
+@NoArgsConstructor
+@AllArgsConstructor
+public class MyUserDetails implements UserDetails, Serializable {
+    private static final long serialVersionUID = -158357727659030597L;
+    private String id;
+    private String username;
+    private String password;
+    private String roleCode;
+    private String useType;
+    private String createUserId;
+    private Set<GrantedAuthority> authorities;
+
+
+    /**
+     * 默认 false 是将用户账号过期,需改成 true 不过期
+     */
+    @Override
+    public boolean isAccountNonExpired() {
+        return true;
+    }
+
+    /**
+     * 默认 false 是将用户上锁,需改成 true 不上锁
+     */
+    @Override
+    public boolean isAccountNonLocked() {
+        return true;
+    }
+
+    /**
+     * 默认 false 是用户凭证国汽,需改成 true 不过期
+     */
+    @Override
+    public boolean isCredentialsNonExpired() {
+        return true;
+    }
+
+    /**
+     * 默认 false 是将用户失效,需改成 true 不失效
+     */
+    @Override
+    public boolean isEnabled() {
+        return true;
+    }
+}

+ 17 - 0
simulation-resource-server/src/main/java/com/css/simulation/resource/server/infrastructure/common/oauth/OauthParameter.java

@@ -0,0 +1,17 @@
+package com.css.simulation.resource.server.infrastructure.common.oauth;
+
+import lombok.Data;
+import org.springframework.boot.context.properties.ConfigurationProperties;
+import org.springframework.stereotype.Component;
+
+@Data
+@Component
+@ConfigurationProperties(prefix="oauth")
+public class OauthParameter {
+
+    private String resourceId;
+    private String checkTokenEndpointUrl;
+    private String clientId;
+    private String clientSecret;
+    private String simulationDefaultPassword = "123456";
+}

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

@@ -0,0 +1,59 @@
+package com.css.simulation.resource.server.infrastructure.common.utils;
+
+import com.css.simulation.resource.server.infrastructure.common.oauth.MyUserDetails;
+import lombok.extern.slf4j.Slf4j;
+import org.springframework.security.core.Authentication;
+import org.springframework.security.core.context.SecurityContextHolder;
+
+/**
+ * 认证信息工具类
+ */
+@Slf4j
+public class AuthUtil {
+
+    /**
+     * 获取当前登录人id
+     */
+    public static String getCurrentUserId() {
+        Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
+        MyUserDetails userDetails = (MyUserDetails) authentication.getPrincipal();
+        return userDetails.getId();
+    }
+
+    /**
+     * 获取当前登录人roleCode
+     */
+    public static String getCurrentUserRoleCode() {
+        Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
+        MyUserDetails userDetails = (MyUserDetails) authentication.getPrincipal();
+        return userDetails.getRoleCode();
+    }
+
+    /**
+     * 获取当前登录人useType
+     */
+    public static String getCurrentUseType() {
+        Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
+        MyUserDetails userDetails = (MyUserDetails) authentication.getPrincipal();
+        return userDetails.getUseType();
+    }
+
+    /**
+     * 获取当前登录人username
+     */
+    public static String getCurrentUsername() {
+        Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
+        MyUserDetails userDetails = (MyUserDetails) authentication.getPrincipal();
+        return userDetails.getUsername();
+    }
+
+    /**
+     * 获取当前登录人createUserId
+     */
+    public static String getCreateUserId() {
+        Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
+        MyUserDetails userDetails = (MyUserDetails) authentication.getPrincipal();
+        return userDetails.getCreateUserId();
+    }
+
+}

+ 21 - 0
simulation-resource-server/src/main/java/com/css/simulation/resource/server/infrastructure/common/utils/PageUtil.java

@@ -0,0 +1,21 @@
+package com.css.simulation.resource.server.infrastructure.common.utils;
+
+import api.common.pojo.common.PageVO;
+import com.github.pagehelper.PageHelper;
+
+/**
+ * 分页工具类
+ */
+public class PageUtil {
+
+    /**
+     * 统一设置分页参数
+     * @param param
+     */
+    public static void setPageInfo(Object param){
+        if(param != null && param instanceof PageVO) {
+            PageVO pagevo = (PageVO) param;
+            PageHelper.startPage(pagevo.getCurrentPage(), pagevo.getPageSize());
+        }
+    }
+}

+ 48 - 0
simulation-resource-server/src/main/java/com/css/simulation/resource/server/infrastructure/common/utils/PoUtil.java

@@ -0,0 +1,48 @@
+package com.css.simulation.resource.server.infrastructure.common.utils;
+
+import api.common.pojo.common.CommonPO;
+import api.common.pojo.constants.DictConstants;
+import api.common.util.ObjectUtil;
+import api.common.util.TimeUtil;
+
+import java.sql.Timestamp;
+
+public class PoUtil {
+
+    /**
+     * 初始化po的常规字段
+     */
+    public static void initAddPo(CommonPO po){
+        if(ObjectUtil.isNull(po)){
+            return ;
+        }
+        String currentUserId = AuthUtil.getCurrentUserId();
+        Timestamp currentTime = TimeUtil.getNowForMysql();
+        po.setCreateUserId(currentUserId);
+        po.setCreateTime(currentTime);
+        po.setModifyUserId(currentUserId);
+        po.setModifyTime(currentTime);
+        po.setIsDeleted(DictConstants.NO);
+    };
+
+    public static void initDelPo(CommonPO po){
+        if(ObjectUtil.isNull(po)){
+            return ;
+        }
+        String currentUserId = AuthUtil.getCurrentUserId();
+        Timestamp currentTime = TimeUtil.getNowForMysql();
+        po.setModifyUserId(currentUserId);
+        po.setModifyTime(currentTime);
+        po.setIsDeleted(DictConstants.YES);
+    };
+
+    public static void initUpdatePo(CommonPO po){
+        if(ObjectUtil.isNull(po)){
+            return ;
+        }
+        String currentUserId = AuthUtil.getCurrentUserId();
+        Timestamp currentTime = TimeUtil.getNowForMysql();
+        po.setModifyUserId(currentUserId);
+        po.setModifyTime(currentTime);
+    };
+}

+ 32 - 0
simulation-resource-server/src/main/java/com/css/simulation/resource/server/infrastructure/mysql/mapper/LogMapper.java

@@ -0,0 +1,32 @@
+package com.css.simulation.resource.server.infrastructure.mysql.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 api.common.pojo.vo.home.LineChartVO;
+import org.apache.ibatis.annotations.Mapper;
+import org.apache.ibatis.annotations.Param;
+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<LogOperationPO> getUserOperationLogPageList(LogPageParam pageParam);
+
+    List<LogSystemPO> getSystemLogPageList(LogPageParam pageParam);
+
+    void insertSystemLog(LogSystemPO po);
+
+    List<LineChartVO> getAccessCount(@Param("dateBegin") String dateBegin);
+
+}