Browse Source

新增黑名单设置

wangliang 2 years ago
parent
commit
ae5fcba12e

+ 87 - 0
themis-admin/src/main/java/com/qmth/themis/admin/api/TSBlackListController.java

@@ -0,0 +1,87 @@
+package com.qmth.themis.admin.api;
+
+import com.qmth.themis.business.constant.SystemConstant;
+import com.qmth.themis.business.entity.TSBlackList;
+import com.qmth.themis.business.enums.FieldUniqueEnum;
+import com.qmth.themis.business.service.TSBlackListService;
+import com.qmth.themis.business.service.ThemisCacheService;
+import com.qmth.themis.common.exception.BusinessException;
+import com.qmth.themis.common.util.Result;
+import com.qmth.themis.common.util.ResultUtil;
+import io.swagger.annotations.*;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.dao.DuplicateKeyException;
+import org.springframework.transaction.annotation.Transactional;
+import org.springframework.validation.BindingResult;
+import org.springframework.validation.annotation.Validated;
+import org.springframework.web.bind.annotation.*;
+
+import javax.annotation.Resource;
+import java.util.Optional;
+
+/**
+ * <p>
+ * 黑名单表 前端控制器
+ * </p>
+ *
+ * @author wangliang
+ * @since 2023-01-31
+ */
+@Api(tags = "黑名单信息Controller")
+@RestController
+@RequestMapping(SystemConstant.PREFIX_URL_ADMIN + "/black/list")
+@Validated
+public class TSBlackListController {
+    private final static Logger log = LoggerFactory.getLogger(TSBlackListController.class);
+
+    @Resource
+    TSBlackListService tsBlackListService;
+
+    @Resource
+    ThemisCacheService themisCacheService;
+
+    @ApiOperation(value = "黑名单查询接口")
+    @RequestMapping(value = "/select", method = RequestMethod.POST)
+    @ApiResponses({@ApiResponse(code = 200, message = "黑名单信息", response = TSBlackList.class)})
+    public Result select() {
+        return ResultUtil.ok(themisCacheService.blackListCache());
+    }
+
+    @ApiOperation(value = "黑名单保存接口")
+    @RequestMapping(value = "/save", method = RequestMethod.POST)
+    @ApiResponses({@ApiResponse(code = 200, message = "常规信息", response = Result.class)})
+    @Transactional
+    public Result save(@Validated @ApiParam(value = "黑名单信息", required = true) @RequestBody TSBlackList tsBlackList, BindingResult bindingResult) {
+        if (bindingResult.hasErrors()) {
+            return ResultUtil.error(bindingResult.getAllErrors().get(0).getDefaultMessage());
+        }
+        try {
+            tsBlackListService.saveOrUpdate(tsBlackList);
+            themisCacheService.removeBlackListCache();
+        } catch (Exception e) {
+            log.error(SystemConstant.LOG_ERROR, e);
+            if (e instanceof DuplicateKeyException) {
+                String errorColumn = e.getCause().toString();
+                String columnStr = errorColumn.substring(errorColumn.lastIndexOf("key") + 3, errorColumn.length()).replaceAll("'", "");
+                throw new BusinessException(FieldUniqueEnum.convertToCode(columnStr) + "数据不允许重复插入");
+            } else if (e instanceof BusinessException) {
+                throw new BusinessException(e.getMessage());
+            } else {
+                throw new RuntimeException(e);
+            }
+        }
+        return ResultUtil.ok(true);
+    }
+
+    @ApiOperation(value = "黑名单删除接口")
+    @RequestMapping(value = "/delete", method = RequestMethod.POST)
+    @ApiResponses({@ApiResponse(code = 200, message = "常规信息", response = Result.class)})
+    @Transactional
+    public Result delete(@ApiParam(value = "黑名单id", required = true) @RequestParam Long id) {
+        Optional.ofNullable(id).orElseThrow(() -> new BusinessException("黑名单id不能为空"));
+        tsBlackListService.removeById(id);
+        themisCacheService.removeBlackListCache();
+        return ResultUtil.ok(true);
+    }
+}

+ 1 - 1
themis-business/src/main/java/com/qmth/themis/business/constant/SystemConstant.java

@@ -77,7 +77,6 @@ public class SystemConstant {
     public static final String PREFIX_URL_OE = "/api/oe";
     public static final String PREFIX_URL_MOBILE = "/api/mobile";
 
-
     public static final String ATTACHMENT_TYPE = "attachment.type";
     public static final String ADMIN_LOGO_URL = "admin.logo.url";
     public static final String ADMIN_FILE_HOST = "admin.file.host";
@@ -197,6 +196,7 @@ public class SystemConstant {
 //    public static final String AUTH_INFO_CACHE = "auth:info:cache";
     public static final String EXAM_AUDIO_CACHE = "exam:audio:cache";
     public static final String ATTACHMENT_CACHE = "attachment:cache";
+    public static final String BLACK_LIST_CACHE = "blacklist:cache";
     public volatile static Searcher SEARCHER = null;
     public static final String ONLINE_WARN_INTERVAL = "online.warn.interval";
     public static final String ONLINE_WARN_SCALESIZE = "online.warn.scaleSize";

+ 16 - 0
themis-business/src/main/java/com/qmth/themis/business/dao/TSBlackListMapper.java

@@ -0,0 +1,16 @@
+package com.qmth.themis.business.dao;
+
+import com.baomidou.mybatisplus.core.mapper.BaseMapper;
+import com.qmth.themis.business.entity.TSBlackList;
+
+/**
+ * <p>
+ * 黑名单表 Mapper 接口
+ * </p>
+ *
+ * @author wangliang
+ * @since 2023-01-31
+ */
+public interface TSBlackListMapper extends BaseMapper<TSBlackList> {
+
+}

+ 71 - 0
themis-business/src/main/java/com/qmth/themis/business/entity/TSBlackList.java

@@ -0,0 +1,71 @@
+package com.qmth.themis.business.entity;
+
+import com.fasterxml.jackson.databind.annotation.JsonSerialize;
+import com.fasterxml.jackson.databind.ser.std.ToStringSerializer;
+import com.qmth.themis.business.base.BaseEntity;
+import io.swagger.annotations.ApiModel;
+import io.swagger.annotations.ApiModelProperty;
+
+import javax.validation.constraints.NotNull;
+import java.io.Serializable;
+
+/**
+ * <p>
+ * 黑名单表
+ * </p>
+ *
+ * @author wangliang
+ * @since 2023-01-31
+ */
+@ApiModel(value = "TSBlackList对象", description = "黑名单表")
+public class TSBlackList extends BaseEntity implements Serializable {
+
+    private static final long serialVersionUID = 1L;
+
+    @ApiModelProperty(value = "机构id")
+    @JsonSerialize(using = ToStringSerializer.class)
+    private Long orgId;
+
+    @ApiModelProperty(value = "软件名称")
+    @NotNull(message = "软件名称不能为空")
+    private String softName;
+
+    @ApiModelProperty(value = "进程名称")
+    @NotNull(message = "进程名称不能为空")
+    private String processName;
+
+    @ApiModelProperty(value = "是否启用,0:停用,1:启用")
+    private Boolean enable;
+
+    public Long getOrgId() {
+        return orgId;
+    }
+
+    public void setOrgId(Long orgId) {
+        this.orgId = orgId;
+    }
+
+    public String getSoftName() {
+        return softName;
+    }
+
+    public void setSoftName(String softName) {
+        this.softName = softName;
+    }
+
+    public String getProcessName() {
+        return processName;
+    }
+
+    public void setProcessName(String processName) {
+        this.processName = processName;
+    }
+
+    public Boolean getEnable() {
+        return enable;
+    }
+
+    public void setEnable(Boolean enable) {
+        this.enable = enable;
+    }
+}

+ 3 - 1
themis-business/src/main/java/com/qmth/themis/business/enums/FieldUniqueEnum.java

@@ -39,7 +39,9 @@ public enum FieldUniqueEnum {
 
     room_code_index("该考试批次下考场编码"),
 
-    activity_idx("语音消息");
+    activity_idx("语音消息"),
+
+    soft_index("软件和进程名称");
 
     private String code;
 

+ 16 - 0
themis-business/src/main/java/com/qmth/themis/business/service/TSBlackListService.java

@@ -0,0 +1,16 @@
+package com.qmth.themis.business.service;
+
+import com.baomidou.mybatisplus.extension.service.IService;
+import com.qmth.themis.business.entity.TSBlackList;
+
+/**
+ * <p>
+ * 黑名单表 服务类
+ * </p>
+ *
+ * @author wangliang
+ * @since 2023-01-31
+ */
+public interface TSBlackListService extends IService<TSBlackList> {
+
+}

+ 14 - 1
themis-business/src/main/java/com/qmth/themis/business/service/ThemisCacheService.java

@@ -1,10 +1,11 @@
 package com.qmth.themis.business.service;
 
 import com.qmth.themis.business.dto.AuthDto;
-import com.qmth.themis.business.dto.AuthOrgInfoDto;
 import com.qmth.themis.business.dto.cache.TEStudentCacheDto;
 import com.qmth.themis.business.entity.*;
 
+import java.util.List;
+
 /**
  * @Description: 缓存 服务类
  * @Param:
@@ -245,4 +246,16 @@ public interface ThemisCacheService {
      * @param sysConfig
      */
     public void updateSysConfigCacheForDb(String key, SysConfig sysConfig);
+
+    /**
+     * 黑名单缓存
+     *
+     * @return
+     */
+    public List<TSBlackList> blackListCache();
+
+    /**
+     * 删除黑名单缓存
+     */
+    public void removeBlackListCache();
 }

+ 20 - 0
themis-business/src/main/java/com/qmth/themis/business/service/impl/TSBlackListServiceImpl.java

@@ -0,0 +1,20 @@
+package com.qmth.themis.business.service.impl;
+
+import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
+import com.qmth.themis.business.dao.TSBlackListMapper;
+import com.qmth.themis.business.entity.TSBlackList;
+import com.qmth.themis.business.service.TSBlackListService;
+import org.springframework.stereotype.Service;
+
+/**
+ * <p>
+ * 黑名单表 服务实现类
+ * </p>
+ *
+ * @author wangliang
+ * @since 2023-01-31
+ */
+@Service
+public class TSBlackListServiceImpl extends ServiceImpl<TSBlackListMapper, TSBlackList> implements TSBlackListService {
+
+}

+ 23 - 0
themis-business/src/main/java/com/qmth/themis/business/service/impl/ThemisCacheServiceImpl.java

@@ -67,6 +67,9 @@ public class ThemisCacheServiceImpl implements ThemisCacheService {
     @Resource
     CacheManager cacheManager;
 
+    @Resource
+    TSBlackListService tsBlackListService;
+
     /**
      * 添加机构缓存
      *
@@ -479,4 +482,24 @@ public class ThemisCacheServiceImpl implements ThemisCacheService {
     public void updateSysConfigCacheForDb(String key, SysConfig sysConfig) {
         cacheManager.getCache(SystemConstant.sysConfigCache).put(key, sysConfig);
     }
+
+    /**
+     * 黑名单缓存
+     *
+     * @return
+     */
+    @Override
+    @Cacheable(value = SystemConstant.BLACK_LIST_CACHE, unless = "#result == null")
+    public List<TSBlackList> blackListCache() {
+        return tsBlackListService.list(new QueryWrapper<TSBlackList>().lambda().eq(TSBlackList::getEnable, true));
+    }
+
+    /**
+     * 删除黑名单缓存
+     */
+    @Override
+    @CacheEvict(value = SystemConstant.BLACK_LIST_CACHE)
+    public void removeBlackListCache() {
+
+    }
 }

+ 5 - 0
themis-business/src/main/resources/mapper/TSBlackListMapper.xml

@@ -0,0 +1,5 @@
+<?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.qmth.themis.business.dao.TSBlackListMapper">
+
+</mapper>

+ 42 - 0
themis-exam/src/main/java/com/qmth/themis/exam/api/TSBlackListController.java

@@ -0,0 +1,42 @@
+package com.qmth.themis.exam.api;
+
+import com.qmth.themis.business.constant.SystemConstant;
+import com.qmth.themis.business.entity.TSBlackList;
+import com.qmth.themis.business.service.ThemisCacheService;
+import com.qmth.themis.common.util.Result;
+import com.qmth.themis.common.util.ResultUtil;
+import io.swagger.annotations.Api;
+import io.swagger.annotations.ApiOperation;
+import io.swagger.annotations.ApiResponse;
+import io.swagger.annotations.ApiResponses;
+import org.springframework.validation.annotation.Validated;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RequestMethod;
+import org.springframework.web.bind.annotation.RestController;
+
+import javax.annotation.Resource;
+
+/**
+ * <p>
+ * 黑名单表 前端控制器
+ * </p>
+ *
+ * @author wangliang
+ * @since 2023-01-31
+ */
+@Api(tags = "黑名单信息Controller")
+@RestController
+@RequestMapping(SystemConstant.PREFIX_URL_OE + "/black/list")
+@Validated
+public class TSBlackListController {
+
+    @Resource
+    ThemisCacheService themisCacheService;
+
+    @ApiOperation(value = "黑名单查询接口")
+    @RequestMapping(value = "/select", method = RequestMethod.POST)
+    @ApiResponses({@ApiResponse(code = 200, message = "黑名单信息", response = TSBlackList.class)})
+    public Result select() {
+        return ResultUtil.ok(themisCacheService.blackListCache());
+    }
+}