浏览代码

处理上传 多个选择问题
留言权限检查

wuweihao 3 年之前
父节点
当前提交
63e833ce52

+ 1 - 1
gis_admin/src/main/java/com/gis/admin/controller/LogController.java

@@ -25,7 +25,7 @@ import org.springframework.web.bind.annotation.RestController;
 @Api(tags = "sys-日志管理")
 @RestController
 @RequestMapping("sys/log")
-@RequiresRoles(value = {"sys_admin"}, logical = Logical.OR)
+//@RequiresRoles(value = {"sys_admin"}, logical = Logical.OR)
 public class LogController  {
 
     @Autowired

+ 2 - 2
gis_admin/src/main/java/com/gis/admin/controller/SysResourceController.java

@@ -27,7 +27,7 @@ public class SysResourceController  {
     @Autowired
     SysResourceService entityService;
 
-    @RequiresRoles("sys_admin")
+//    @RequiresRoles("sys_admin")
     @ApiOperation("获取树资源")
     @GetMapping("getTreeResource")
     public Result getTreeResource() {
@@ -40,7 +40,7 @@ public class SysResourceController  {
         return entityService.getTreeAllPermissionsByUserId();
     }
 
-    @RequiresRoles("sys_admin")
+//    @RequiresRoles("sys_admin")
     @WebControllerLog(description = "资源管理-删除缓存", addDb = true)
     @ApiOperation(value = "删除缓存", notes = "更新资源表,需要刷新缓存")
     @GetMapping("refresh")

+ 1 - 1
gis_admin/src/main/java/com/gis/admin/controller/SysRoleController.java

@@ -23,7 +23,7 @@ import javax.validation.Valid;
 @Api(tags = "sys-角色管理")
 @RestController
 @RequestMapping("sys/role")
-@RequiresRoles("sys_admin") //需要admin角色才可以访问此controller
+//@RequiresRoles("sys_admin") //需要admin角色才可以访问此controller
 public class SysRoleController  {
 
     @Autowired

+ 5 - 5
gis_admin/src/main/java/com/gis/admin/controller/SysUserController.java

@@ -32,7 +32,7 @@ public class SysUserController {
     @Autowired
     private SysUserService userService;
 
-    @RequiresRoles(value = {"sys_admin"}, logical = Logical.OR)
+//    @RequiresRoles(value = {"sys_admin"}, logical = Logical.OR)
     @ApiOperation("用户列表")
     @PostMapping("list")
     public Result<SysUserEntity> list(@RequestBody UserPageDateDto param) {
@@ -66,7 +66,7 @@ public class SysUserController {
     }
 
 
-    @RequiresRoles(value = {"sys_admin"}, logical = Logical.OR)
+//    @RequiresRoles(value = {"sys_admin"}, logical = Logical.OR)
     @WebControllerLog(description = "用户管理-重置密码", addDb = true)
     @ApiOperation("重置密码")
     @GetMapping("resetPass/{id}")
@@ -76,7 +76,7 @@ public class SysUserController {
     }
 
 
-    @RequiresRoles(value = {"sys_admin"}, logical = Logical.OR)
+//    @RequiresRoles(value = {"sys_admin"}, logical = Logical.OR)
     @WebControllerLog(description = "用户管理-启用、停用账户")
     @ApiOperation(value = "启用、停用账户", notes = "isEnabled-> 1:可用, 0:禁用")
     @GetMapping("editStatus/{id}/{isEnabled}")
@@ -86,7 +86,7 @@ public class SysUserController {
     }
 
 
-    @RequiresRoles(value = {"sys_admin"}, logical = Logical.OR)
+//    @RequiresRoles(value = {"sys_admin"}, logical = Logical.OR)
     @WebControllerLog(description = "用户管理-删除",addDb = true)
     @ApiOperation("删除")
     @GetMapping("removes/{ids}")
@@ -94,7 +94,7 @@ public class SysUserController {
         return userService.removes(ids);
     }
 
-    @RequiresRoles(value = {"sys_admin"}, logical = Logical.OR)
+//    @RequiresRoles(value = {"sys_admin"}, logical = Logical.OR)
     @WebControllerLog(description = "用户管理-获取角色")
     @ApiOperation("获取角色")
     @GetMapping("getRole")

+ 4 - 4
gis_admin/src/main/java/com/gis/admin/entity/dto/UserDto.java

@@ -68,11 +68,11 @@ public class UserDto {
     private Long roleId;
 
 //    @NotBlank(message = "旧密码不能为空")
-    @ApiModelProperty(value = "旧密码", name = "oldPassword")
-    private String oldPassword;
+//    @ApiModelProperty(value = "旧密码", name = "oldPassword")
+//    private String oldPassword;
 
 //    @NotBlank(message = "新密码不能为空")
-    @ApiModelProperty(value = "新密码", name = "newPassword")
-    private String newPassword;
+//    @ApiModelProperty(value = "新密码", name = "newPassword")
+//    private String newPassword;
 
 }

+ 8 - 8
gis_admin/src/main/java/com/gis/admin/service/impl/SysUserServiceImpl.java

@@ -91,14 +91,14 @@ public class SysUserServiceImpl extends IBaseServiceImpl<SysUserEntity, Long> im
             this.update(entity);
 
             // 更新密码
-            String oldPassword = param.getOldPassword();
-            String newPassword = param.getNewPassword();
-            if (oldPassword !=null && newPassword != null) {
-                PasswordDto dto = new PasswordDto();
-                dto.setOldPassword(oldPassword);
-                dto.setNewPassword(newPassword);
-                updatePassword(dto);
-            }
+//            String oldPassword = param.getOldPassword();
+//            String newPassword = param.getNewPassword();
+//            if (oldPassword !=null && newPassword != null) {
+//                PasswordDto dto = new PasswordDto();
+//                dto.setOldPassword(oldPassword);
+//                dto.setNewPassword(newPassword);
+//                updatePassword(dto);
+//            }
 
             // 每次修改,删除用户角色表信息,重新添加
             sysRoleService.deleteUserRoleByUserId(id);

+ 9 - 0
gis_cms/src/main/java/com/gis/cms/controller/WebManageController.java

@@ -69,6 +69,9 @@ public class WebManageController {
     @Autowired
     GoodsVoteService goodsVoteService;
 
+    @Autowired
+    WebService webService;
+
 
 
 
@@ -177,6 +180,12 @@ public class WebManageController {
         return goodsVoteService.goodsVoteDelByType(goodsId, "like");
     }
 
+    @ApiOperation(value = "v0.2-检查留言", notes = "true:需要弹窗, false:不需要弹窗, 类型:comment:留言,barrage:弹幕")
+    @GetMapping("check/message/{type}")
+    public Result checkMessage(@PathVariable String type) {
+        return webService.checkMessage(type);
+    }
+
 
 
 

+ 3 - 0
gis_cms/src/main/java/com/gis/cms/mapper/BarrageMapper.java

@@ -23,4 +23,7 @@ public interface BarrageMapper extends IBaseMapper<BarrageEntity, Long> {
     @Select("select a.id, a.create_time, a.content, a.display, b.unit, b.real_name, b.nick_name from tb_barrage a left join sys_user b on b.id=a.user_id " +
             "where a.is_delete = '0' and a.id=#{id}")
     BarrageEntity detailMapper(Long id);
+
+    @Select("select count(id) from tb_barrage where is_delete=0 and  user_id=#{userId}")
+    Integer countByUserId(Long userId);
 }

+ 3 - 0
gis_cms/src/main/java/com/gis/cms/mapper/CommentMapper.java

@@ -29,4 +29,7 @@ public interface CommentMapper extends IBaseMapper<CommentEntity, Long> {
     @Select("select a.id, a.create_time, a.content, a.display, a.parent_id, b.unit, b.real_name, b.nick_name from tb_comment a left join sys_user b on b.id=a.user_id " +
             "where a.is_delete = '0' and a.id=#{id}")
     CommentEntity detailMapper(Long id);
+
+    @Select("select count(id) from tb_comment where is_delete=0 and  user_id=#{userId}")
+    Integer countByUserId(Long userId);
 }

+ 2 - 0
gis_cms/src/main/java/com/gis/cms/service/BarrageService.java

@@ -24,4 +24,6 @@ public interface BarrageService extends IBaseService<BarrageEntity, Long> {
     Result saveEntity(CommentDto param);
 
     Result<BarrageEntity> detail(Long id);
+
+    Integer countByUserId(Long userId);
 }

+ 2 - 0
gis_cms/src/main/java/com/gis/cms/service/CommentService.java

@@ -29,4 +29,6 @@ public interface CommentService extends IBaseService<CommentEntity, Long> {
     Result<CommentVo> voListTree(PageDateDto param, Integer display);
 
     Result<CommentEntity> detail(Long id);
+
+    Integer countByUserId(Long userId);
 }

+ 14 - 0
gis_cms/src/main/java/com/gis/cms/service/WebService.java

@@ -0,0 +1,14 @@
+package com.gis.cms.service;
+
+
+import com.gis.common.util.Result;
+
+
+/**
+ * Created by owen on 2020/3/11 0011 16:14
+ */
+public interface WebService {
+
+
+    Result checkMessage(String type);
+}

+ 5 - 0
gis_cms/src/main/java/com/gis/cms/service/impl/BarrageServiceImpl.java

@@ -98,4 +98,9 @@ public class BarrageServiceImpl extends IBaseServiceImpl<BarrageEntity, Long> im
         return Result.success(entity);
     }
 
+    @Override
+    public Integer countByUserId(Long userId) {
+        return entityMapper.countByUserId(userId);
+    }
+
 }

+ 5 - 0
gis_cms/src/main/java/com/gis/cms/service/impl/CommentServiceImpl.java

@@ -104,4 +104,9 @@ public class CommentServiceImpl extends IBaseServiceImpl<CommentEntity, Long> im
         CommentEntity entity = entityMapper.detailMapper(id);
         return Result.success(entity);
     }
+
+    @Override
+    public Integer countByUserId(Long userId) {
+        return entityMapper.countByUserId(userId);
+    }
 }

+ 75 - 30
gis_cms/src/main/java/com/gis/cms/service/impl/QuestionGroupServiceImpl.java

@@ -77,7 +77,7 @@ public class QuestionGroupServiceImpl extends IBaseServiceImpl<QuestionGroupEnti
         }
         String startTime = param.getStartTime();
         String endTime = param.getEndTime();
-        if (StringUtils.isNotBlank(startTime) && StringUtils.isNotBlank(endTime) ) {
+        if (StringUtils.isNotBlank(startTime) && StringUtils.isNotBlank(endTime)) {
             condition.and().andBetween("createTime", startTime, endTime);
         }
         Integer status = param.getStatus();
@@ -108,7 +108,7 @@ public class QuestionGroupServiceImpl extends IBaseServiceImpl<QuestionGroupEnti
 
     }
 
-    private Integer getQuesitongCount(Long id){
+    private Integer getQuesitongCount(Long id) {
         List<QuestionAnswerEntity> answerEntityList = questionAnswerService.findByQuestionGroupId(id);
         return answerEntityList.size();
     }
@@ -117,7 +117,7 @@ public class QuestionGroupServiceImpl extends IBaseServiceImpl<QuestionGroupEnti
     public Result apply(Long id) {
         // 1:审核中
         updateStatus(id, 1);
-        return  Result.success();
+        return Result.success();
     }
 
     @Override
@@ -127,7 +127,7 @@ public class QuestionGroupServiceImpl extends IBaseServiceImpl<QuestionGroupEnti
         if (status == 0) {
             // 审核不通过
             status = 2;
-        } else if (status == 1){
+        } else if (status == 1) {
             // 审核通过
             status = 3;
         } else {
@@ -155,7 +155,7 @@ public class QuestionGroupServiceImpl extends IBaseServiceImpl<QuestionGroupEnti
         }
 
         if (display == 1) {
-            if (entity.getStatus() != 3){
+            if (entity.getStatus() != 3) {
                 return Result.failure("只有审核通过的,才允许设置为显示状态");
             }
         }
@@ -176,10 +176,11 @@ public class QuestionGroupServiceImpl extends IBaseServiceImpl<QuestionGroupEnti
 
     /**
      * 解决excel数据并保存数据库
+     *
      * @param filePath 相对路径
      * @return
      */
-    private void parseExcel(String filePath){
+    private void parseExcel(String filePath) {
         // 读取excel数据
         String excelPath = configConstant.serverBasePath + filePath;
         List<List<Object>> read = ExcelUtils.readExcel(excelPath);
@@ -189,43 +190,53 @@ public class QuestionGroupServiceImpl extends IBaseServiceImpl<QuestionGroupEnti
         // 题组标题
         List<Object> group = read.get(1);
         String groupTitle = group.get(1).toString();
-        if (StrUtil.isBlank(groupTitle)){
+        if (StrUtil.isBlank(groupTitle)) {
             throw new BaseRuntimeException("题组名称不能为空");
         }
-        log.info("题组名称:{}", groupTitle );
+        checkLengthStr(groupTitle);
+        log.info("题组名称:{}", groupTitle);
 
         // 从第三行读取,直接读取题目跟选项, 使用LinkedHashMap区分顺序
         LinkedHashMap<String, TopicDto> topicMap = new LinkedHashMap<>();
+
+
+        // 正确答案,校验是否多个检查
+        HashMap<String, Integer> checkCorrectMap = new HashMap<>();
+
         String topic = null;
         for (int i = 2; i < read.size(); i++) {
             List<Object> list = read.get(i);
-            String tips = (String)list.get(0);
-            if (StrUtil.isBlank(tips)){
+            String tips = (String) list.get(0);
+            if (StrUtil.isBlank(tips)) {
                 log.warn("提示行为空,默认为结束行");
                 break;
             }
             // 题目
-            if (tips.contains("题目")){
-                topic = (String)list.get(1);
+            if (tips.contains("题目")) {
+                topic = (String) list.get(1);
                 // 题目为空,结束循环
-                if (StrUtil.isBlank(topic)){
+                if (StrUtil.isBlank(topic)) {
                     log.warn(tips + ": 为空,结束循环");
                     break;
                 }
 
                 // 保存题目
+                checkLengthStr(topic);
                 TopicDto topicDto = new TopicDto();
                 topicDto.setTopic(topic);
                 topicMap.put(topic, topicDto);
+                checkCorrectMap.put(topic, 0);
             }
 
             // 选项
-            if (tips.contains("选项")){
-                String option = (String)list.get(1);
-                if (StrUtil.isBlank(option)){
+            if (tips.contains("选项")) {
+                String option = (String) list.get(1);
+                if (StrUtil.isBlank(option)) {
                     // 选项为空, 执行下一次循环
                     continue;
                 }
+
+                // 每一行数据
                 TopicDto topicDto = topicMap.get(topic);
                 String random = RandomUtil.randomString(8);
 
@@ -236,19 +247,23 @@ public class QuestionGroupServiceImpl extends IBaseServiceImpl<QuestionGroupEnti
 //                }
 
                 // 预防单元格没有边框拿不到值
-                if (list.size() >2){
-                    String correct = (String)list.get(2);
-                    if (StrUtil.isNotBlank(correct)){
+                if (list.size() > 2) {
+                    String correct = (String) list.get(2);
+                    if (StrUtil.isNotBlank(correct) && StrUtil.equals("√", correct)) {
+                        Integer integer = checkCorrectMap.get(topic);
+                        // 用于校验多个正确答案
+                        checkCorrectMap.put(topic, integer + 1);
                         topicDto.setCorrect(random);
                     }
                 }
 
 
-
+                // 选项
                 LinkedHashMap<String, String> options = topicDto.getOptions();
-                if (CollectionUtil.isEmpty(options)){
+                if (CollectionUtil.isEmpty(options)) {
                     options = new LinkedHashMap<>();
                 }
+                checkLengthStr(option);
                 options.put(random, option);
 
                 topicDto.setOptions(options);
@@ -259,6 +274,10 @@ public class QuestionGroupServiceImpl extends IBaseServiceImpl<QuestionGroupEnti
         }
 
         log.info("excel数据封装完成");
+
+        // 校验正确答案
+        checkCorrect(checkCorrectMap);
+
         // 题组保存数据库
         QuestionGroupEntity groupEntity = new QuestionGroupEntity();
         groupEntity.setName(groupTitle);
@@ -268,7 +287,7 @@ public class QuestionGroupServiceImpl extends IBaseServiceImpl<QuestionGroupEnti
         log.info("保存题组完成, 题组id: {}", groupEntityId);
 
         // 题目保存数据库
-        for(Map.Entry<String, TopicDto> entry : topicMap.entrySet()){
+        for (Map.Entry<String, TopicDto> entry : topicMap.entrySet()) {
             TopicDto value = entry.getValue();
             QuestionAnswerEntity answerEntity = new QuestionAnswerEntity();
             answerEntity.setQuestionGroupId(groupEntityId);
@@ -281,20 +300,48 @@ public class QuestionGroupServiceImpl extends IBaseServiceImpl<QuestionGroupEnti
         log.info("保存题目完成");
 
 
+    }
 
-
+    /**
+     * 校验字符串长度
+     *
+     * @param str
+     */
+    private void checkLengthStr(String str) {
+        if (StringUtils.isNotBlank(str)) {
+            if (str.length() > 100) {
+                throw new BaseRuntimeException(MsgCode.e3006, "标题及选项限长度大于100个字符");
+            }
+        }
     }
 
 
+    /**
+     * 校验同一题目出现多个正确答案
+     *
+     * @param options
+     */
+    private void checkCorrect(Map<String, Integer> options) {
+        for (Map.Entry<String, Integer> entry : options.entrySet()) {
+            String key = entry.getKey();
+            Integer value = entry.getValue();
+            if (value != 1) {
+                throw new BaseRuntimeException("此题目:" + key + ", 答案选项不正确:" + value);
+
+            }
+        }
+    }
+
 
     /**
      * 解析选项
+     *
      * @param options
      * @return
      */
-    private String parseAnswer(Map<String, String> options){
+    private String parseAnswer(Map<String, String> options) {
         JSONArray array = new JSONArray();
-        for(Map.Entry<String, String> entry : options.entrySet()){
+        for (Map.Entry<String, String> entry : options.entrySet()) {
             String key = entry.getKey();
             String value = entry.getValue();
             JSONObject obj = new JSONObject();
@@ -307,7 +354,7 @@ public class QuestionGroupServiceImpl extends IBaseServiceImpl<QuestionGroupEnti
     }
 
 
-    private void updateStatus(Long id, Integer status){
+    private void updateStatus(Long id, Integer status) {
         QuestionGroupEntity entity = this.findById(id);
         if (entity == null) {
             throw new BaseRuntimeException(MsgCode.e3001, "对象不存在");
@@ -364,7 +411,7 @@ public class QuestionGroupServiceImpl extends IBaseServiceImpl<QuestionGroupEnti
         // 相应的答案删除
         questionAnswerService.removeByQuestionGroupId(id);
 
-        return  Result.success();
+        return Result.success();
     }
 
     @Override
@@ -377,10 +424,8 @@ public class QuestionGroupServiceImpl extends IBaseServiceImpl<QuestionGroupEnti
         HashMap<Object, Object> result = new HashMap<>();
         result.put("entity", entity);
         result.put("answer", list);
-        return  Result.success(result);
+        return Result.success(result);
     }
 
 
-
-
 }

+ 4 - 2
gis_cms/src/main/java/com/gis/cms/service/impl/ReportServiceImpl.java

@@ -157,14 +157,16 @@ public class ReportServiceImpl implements ReportService {
 
     private Integer countGoods(){
         StringBuffer sql = new StringBuffer();
-        sql.append("SELECT count(id) as count from tb_goods where is_delete=0 and display=1 and status=3");
+//        sql.append("SELECT count(id) as count from tb_goods where is_delete=0 and display=1 and status=3");
+        sql.append("SELECT count(id) as count from tb_goods where is_delete=0 and status=3");
         log.info("sql: {}", sql.toString());
         return visitLogMapper.countSql(sql.toString());
     }
 
     private Integer countNews(){
         StringBuffer sql = new StringBuffer();
-        sql.append("SELECT count(id) as count from tb_news where is_delete=0 and display=1 and status=3");
+//        sql.append("SELECT count(id) as count from tb_news where is_delete=0 and display=1 and status=3");
+        sql.append("SELECT count(id) as count from tb_news where is_delete=0  and status=3");
         log.info("sql: {}", sql.toString());
         return visitLogMapper.countSql(sql.toString());
     }

+ 91 - 0
gis_cms/src/main/java/com/gis/cms/service/impl/WebServiceImpl.java

@@ -0,0 +1,91 @@
+package com.gis.cms.service.impl;
+
+import cn.hutool.extra.spring.SpringUtil;
+import com.gis.admin.service.SysResourceService;
+import com.gis.cms.service.BarrageService;
+import com.gis.cms.service.CommentService;
+import com.gis.cms.service.WebService;
+import com.gis.common.base.entity.po.BaseEntity;
+import com.gis.common.base.service.IBaseService;
+import com.gis.common.base.service.impl.IBaseServiceImpl;
+import com.gis.common.util.JwtUtil;
+import com.gis.common.util.Result;
+import lombok.extern.slf4j.Slf4j;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
+
+import javax.servlet.http.HttpServletRequest;
+import java.io.Serializable;
+import java.util.Set;
+
+
+/**
+ * Created by owen on 2022/2/9 0011 16:16
+ */
+@Slf4j
+@Service
+public class WebServiceImpl implements WebService {
+
+    @Autowired
+    CommentService commentService;
+
+    @Autowired
+    BarrageService barrageService;
+
+    @Autowired
+    SysResourceService sysResourceService;
+
+    @Autowired
+    HttpServletRequest request;
+
+
+
+
+
+    @Override
+    public Result checkMessage(String type) {
+        Boolean flag = false;
+
+        Long tokenUserId = getTokenUserId();
+
+        // 权限标签
+        Boolean permFlag = false;
+        Set<String> permissionKey = sysResourceService.getPermissionByUserId(tokenUserId);
+        if (permissionKey.contains("comment:display") || permissionKey.contains("barrage:display")){
+            log.info("该用户有留言权限: {}", tokenUserId);
+            permFlag = true;
+        }
+
+
+        // 1.有留言过:不提醒,返回false
+        // 2.没有留言、弹幕是否显示权限:不提醒,返回false
+        // 3.有权限、没有留言: 需要提醒,返回true;
+
+        if ("comment".equals(type)){
+            Integer n = commentService.countByUserId(tokenUserId);
+            if (n == 0 && permFlag){
+                flag = true;
+                log.info("留言需要提醒");
+            }
+        } else {
+            Integer n = barrageService.countByUserId(tokenUserId);
+            if (n == 0 && permFlag){
+                flag = true;
+                log.info("弹幕需要提醒");
+            }
+        }
+
+        return Result.success(flag);
+    }
+
+
+
+    public String getToken(){
+        return request.getHeader("token");
+    }
+
+    /** 获取用户id*/
+    public Long getTokenUserId(){
+        return JwtUtil.getUserId(getToken());
+    }
+}

+ 4 - 1
gis_common/src/main/java/com/gis/common/constant/MsgCode.java

@@ -8,7 +8,7 @@ public class MsgCode {
     /** 对象不存在*/
     public static final Integer e3001 = 3001;
 
-    /** 传文件非法*/
+    /** 传文件非法*/
     public static final Integer e3002 = 3002;
 
     /** 空目录*/
@@ -19,4 +19,7 @@ public class MsgCode {
 
     /** 验证码失效*/
     public static final Integer e3005 = 3005;
+
+    /** 字符串长度非法*/
+    public static final Integer e3006 = 3006;
 }