Explorar o código

作者:张哲
时间:2023/01/18
类型:优化
描述:里程碑(2)知识地图开发

ZizgZh %!s(int64=2) %!d(string=hai) anos
pai
achega
5ba708aba7

+ 2 - 2
src/main/java/com/redxun/knowledge/map/controller/MapContentController.java

@@ -18,9 +18,9 @@ import java.util.List;
 
 @Slf4j
 @RestController
-@RequestMapping("/api-knowledge/knowledge/map/mapContent")
+@RequestMapping("/api-knowledge/map/mapContent")
 @Api(tags = "业务--知识地图学习内容表")
-@ClassDefine(title = "业务--知识地图学习内容表", alias = "MapContentController", path = "/api-knowledge/knowledge/map/mapContent",
+@ClassDefine(title = "业务--知识地图学习内容表", alias = "MapContentController", path = "/api-knowledge/map/mapContent",
         packages = "knowledge", packageName = "子系统名称")
 public class MapContentController extends BaseController<MapContent> {
 

+ 2 - 3
src/main/java/com/redxun/knowledge/map/controller/MapController.java

@@ -96,7 +96,7 @@ public class MapController extends BaseController<Map> {
     @GetMapping("listOfType")
     public JsonResult listOfType(@RequestParam("type") Integer type){
         JsonResult jsonResult = JsonResult.getSuccessResult("");
-        List<HashMap<String, Object>> result = mapService.listOfType(type);
+        List<java.util.Map<String, Object>> result = mapService.listOfType(type);
         return jsonResult.setData(result);
     }
 
@@ -105,12 +105,11 @@ public class MapController extends BaseController<Map> {
     public JsonResult routes(@RequestParam("mapId") String mapId){
         JsonResult jsonResult = JsonResult.getSuccessResult("");
         List<HashMap<String, Object>> result = mapService.routes(mapId);
-        if (!result.isEmpty()){
+        if (result != null){
             return jsonResult.setData(result);
         }else {
             return jsonResult.setData("您没有访问权限");
         }
-
     }
 
 }

+ 2 - 2
src/main/java/com/redxun/knowledge/map/controller/MapGroupPurviewUserController.java

@@ -17,9 +17,9 @@ import java.util.List;
 
 @Slf4j
 @RestController
-@RequestMapping("/api-knowledge/knowledge/map/mapGroupPurviewUserController")
+@RequestMapping("/api-knowledge/map/mapGroupPurviewUserController")
 @Api(tags = "业务--知识地图组织可阅读者表")
-@ClassDefine(title = "业务--知识地图组织可阅读者表", alias = "MapGroupPurviewUserController", path = "/api-knowledge/knowledge/map/mapGroupPurviewUserController",
+@ClassDefine(title = "业务--知识地图组织可阅读者表", alias = "MapGroupPurviewUserController", path = "/api-knowledge/map/mapGroupPurviewUserController",
         packages = "knowledge", packageName = "子系统名称")
 public class MapGroupPurviewUserController extends BaseController<MapGroupPurviewUser> {
 

+ 24 - 2
src/main/java/com/redxun/knowledge/map/controller/MapRouteController.java

@@ -4,21 +4,28 @@ package com.redxun.knowledge.map.controller;
 import com.redxun.common.annotation.ClassDefine;
 import com.redxun.common.base.db.BaseService;
 
+import com.redxun.common.base.entity.JsonResult;
 import com.redxun.knowledge.map.entity.dao.MapRoute;
+import com.redxun.knowledge.map.entity.vo.MapContentVo;
 import com.redxun.knowledge.map.service.MapRouteServiceImpl;
 import com.redxun.web.controller.BaseController;
 import io.swagger.annotations.Api;
+import io.swagger.annotations.ApiOperation;
 import lombok.extern.slf4j.Slf4j;
 import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.web.bind.annotation.GetMapping;
 import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RequestParam;
 import org.springframework.web.bind.annotation.RestController;
 
+import java.util.List;
+
 @Slf4j
 @RestController
-@RequestMapping("/api-knowledge/knowledge/map/mapRoute")
+@RequestMapping("/api-knowledge/map/route")
 @Api(tags = "业务--知识地图学习路径表")
 @ClassDefine(title = "业务--知识地图学习路径表", alias = "MapRouteController",
-        path = "/api-knowledge/knowledge/map/mapRoute", packages = "knowledge", packageName = "子系统名称")
+        path = "/api-knowledge/map/mapRoute", packages = "knowledge", packageName = "子系统名称")
 public class MapRouteController extends BaseController<MapRoute> {
 
     @Autowired
@@ -35,5 +42,20 @@ public class MapRouteController extends BaseController<MapRoute> {
         return "业务--知识地图学习路径表";
     }
 
+    @ApiOperation("根据知识地图路径ID获取知识地图学习内容")
+    @GetMapping("contentTops")
+    public JsonResult contentTops(@RequestParam("routeId")String routeId,
+                                  @RequestParam(value = "tops",required = false,defaultValue = "10")Integer tops){
+        JsonResult jsonResult = JsonResult.getSuccessResult("");
+        List<MapContentVo> mapContentVoList = mapRouteService.contentTops(routeId,tops);
+        if (mapContentVoList != null){
+           return jsonResult.setData(mapContentVoList);
+        } else {
+            return jsonResult.setData("您没有访问权限");
+        }
+
+
+    }
+
 }
 

+ 2 - 0
src/main/java/com/redxun/knowledge/map/entity/dto/MapContentDto.java

@@ -4,6 +4,7 @@ import io.swagger.annotations.ApiModel;
 import io.swagger.annotations.ApiModelProperty;
 import lombok.Data;
 
+import javax.validation.constraints.NotNull;
 import java.io.Serializable;
 
 /**
@@ -34,6 +35,7 @@ public class MapContentDto implements Serializable {
     @ApiModelProperty("访问地址(外部系统)")
     private String outerAccessUrl;
 
+    @NotNull(message = "缺失关键参数:排序不能为空")
     @ApiModelProperty("排序")
     private Integer sort;
 }

+ 2 - 0
src/main/java/com/redxun/knowledge/map/entity/dto/MapRouteDto.java

@@ -7,6 +7,7 @@ import io.swagger.annotations.ApiModel;
 import io.swagger.annotations.ApiModelProperty;
 import lombok.Data;
 
+import javax.validation.constraints.NotNull;
 import java.io.Serializable;
 import java.util.List;
 
@@ -28,6 +29,7 @@ public class MapRouteDto implements Serializable {
     private String name;
 
     //排序
+    @NotNull(message = "缺失关键参数:排序不能为空")
     @ApiModelProperty("排序")
     private Integer sort;
 

+ 76 - 0
src/main/java/com/redxun/knowledge/map/service/MapRouteServiceImpl.java

@@ -2,14 +2,30 @@
 package com.redxun.knowledge.map.service;
 
 
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
 import com.redxun.common.base.db.BaseDao;
 import com.redxun.common.base.db.BaseService;
 import com.redxun.common.service.impl.SuperServiceImpl;
+import com.redxun.knowledge.common.UserService;
+import com.redxun.knowledge.map.entity.dao.Map;
+import com.redxun.knowledge.map.entity.dao.MapContent;
+import com.redxun.knowledge.map.entity.dao.MapGroupPurviewUser;
 import com.redxun.knowledge.map.entity.dao.MapRoute;
+import com.redxun.knowledge.map.entity.vo.MapContentVo;
+import com.redxun.knowledge.map.mapper.MapContentMapper;
+import com.redxun.knowledge.map.mapper.MapGroupPurviewUserMapper;
+import com.redxun.knowledge.map.mapper.MapMapper;
 import com.redxun.knowledge.map.mapper.MapRouteMapper;
+import com.redxun.knowledge.mapper.KnowledgeMapper;
+import org.springframework.beans.BeanUtils;
+import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.HashMap;
 import java.util.List;
+import java.util.stream.Collectors;
 import javax.annotation.Resource;
 
 /**
@@ -21,9 +37,69 @@ public class MapRouteServiceImpl extends SuperServiceImpl<MapRouteMapper, MapRou
     @Resource
     private MapRouteMapper mapRouteMapper;
 
+    @Autowired
+    private MapMapper mapMapper;
+
+    @Autowired
+    private UserService userService;
+
+    @Autowired
+    private MapContentMapper mapContentMapper;
+
+    @Autowired
+    private MapGroupPurviewUserMapper mapGroupPurviewUserMapper;
+
+    @Autowired
+    private KnowledgeMapper knowledgeMapper;
+
     @Override
     public BaseDao<MapRoute> getRepository() {
         return mapRouteMapper;
     }
 
+    /**
+     * PC端根据知识地图路径ID获取知识地图学习内容,根据tops参数设置请求内容条数。(权限判断)
+     * @param routeId
+     * @param tops
+     * @return
+     */
+    public List<MapContentVo> contentTops(String routeId, Integer tops) {
+        // 获取地图
+        Map map = mapMapper.selectById(mapRouteMapper.selectById(routeId).getMapId());
+        // 判断权限
+        //当前登录用户的部门Id
+        String deptId = userService.queryLoginUserDeptId();
+        String[] groupIds = map.getGroupId().split(",");
+        //包含登录人的部门
+        if (Arrays.asList(groupIds).contains(deptId)) {
+            if (map.getGroupPurview() == 1) {
+                return contentInfo(routeId,tops);
+            } else {
+                QueryWrapper<MapGroupPurviewUser> queryWrapper = new QueryWrapper<>();
+                queryWrapper.eq("MAP_ID", map.getPkId());
+                queryWrapper.eq("USER_ID", userService.queryLoginUser());
+                // 查询结果>0,说明该员工可见
+                Integer count = mapGroupPurviewUserMapper.selectCount(queryWrapper);
+                if (count > 0) {
+                    return contentInfo(routeId,tops);
+                }
+            }
+        }
+        return null;
+    }
+
+    /**
+     * PC端根据知识地图路径ID获取知识地图学习内容,根据tops参数设置请求内容条数(方法封装)
+     * @param routeId
+     * @return
+     */
+    private List<MapContentVo> contentInfo(String routeId,Integer tops) {
+        List<MapContent> mapContentList = mapContentMapper.selectList(new LambdaQueryWrapper<MapContent>().eq(MapContent::getRouteId, routeId).orderByAsc(MapContent::getSort));
+        List<MapContentVo> result = mapContentList.stream().limit(tops).map(mapContent -> {
+            MapContentVo mapContentVo = new MapContentVo();
+            BeanUtils.copyProperties(mapContent, mapContentVo);
+            return mapContentVo;
+        }).collect(Collectors.toList());
+        return result;
+    }
 }

+ 69 - 22
src/main/java/com/redxun/knowledge/map/service/MapServiceImpl.java

@@ -39,10 +39,7 @@ import org.springframework.util.CollectionUtils;
 
 import javax.annotation.Resource;
 import java.io.Serializable;
-import java.util.Arrays;
-import java.util.Collection;
-import java.util.HashMap;
-import java.util.List;
+import java.util.*;
 import java.util.stream.Collectors;
 
 /**
@@ -156,6 +153,11 @@ public class MapServiceImpl extends SuperServiceImpl<MapMapper, Map> implements
 
     }
 
+    /**
+     * 管理端查看地图详情
+     * @param pkId
+     * @return
+     */
     public MapVo data(String pkId) {
         MapVo mapVo = new MapVo();
         Map map = mapMapper.selectById(pkId);
@@ -187,7 +189,11 @@ public class MapServiceImpl extends SuperServiceImpl<MapMapper, Map> implements
                             BeanUtils.copyProperties(knowledge,knowledgeVo);
                             String photo = (String) userService.querySexAndPhoto(knowledge.getCreateBy()).get("photo");
                             knowledgeVo.setAuthorHead(photo);
-                            knowledgeVo.setAttachmentType(knowledge.getAttachmentName());
+                            // 有文件,截取文件名后缀
+                            String attachmentName = knowledge.getAttachmentName();
+                            String[] strArray = attachmentName.split("\\.");
+                            int suffixIndex = strArray.length - 1;
+                            knowledgeVo.setAttachmentType(strArray[suffixIndex]);
                             mapContentVo.setKnowledgeVo(knowledgeVo);
                         }
                         return mapContentVo;
@@ -199,6 +205,10 @@ public class MapServiceImpl extends SuperServiceImpl<MapMapper, Map> implements
         return mapVo;
     }
 
+    /**
+     * 管理端删除地图
+     * @param entities
+     */
     @Transactional(rollbackFor = Exception.class)
     @Override
     public void delete(Collection<Serializable> entities) {
@@ -212,10 +222,16 @@ public class MapServiceImpl extends SuperServiceImpl<MapMapper, Map> implements
         this.getRepository().deleteBatchIds(entities);
     }
 
-    public List<HashMap<String, Object>> listOfType(Integer type) {
-        List<Map> mapList = mapMapper.selectList(new LambdaQueryWrapper<Map>().eq(Map::getType, type));
-        List<HashMap<String, Object>> result = mapList.stream().map(map -> {
-            HashMap<String, Object> hashMap = new HashMap<>();
+    /**
+     * PC端根据地图类型字典值获取知识地图列表数据
+     * @param type
+     * @return
+     */
+    public List<java.util.Map<String, Object>> listOfType(Integer type) {
+        List<Map> mapList = mapMapper.selectList(new LambdaQueryWrapper<Map>().eq(Map::getType, type).orderByAsc(Map::getCreateTime));
+        List<java.util.Map<String, Object>> listResult = new ArrayList<>();
+        mapList.forEach(map -> {
+            java.util.Map<String, Object> mapResult = new HashMap<>();
             //当前登录用户的部门Id
             String deptId = userService.queryLoginUserDeptId();
             //权限判断
@@ -224,31 +240,62 @@ public class MapServiceImpl extends SuperServiceImpl<MapMapper, Map> implements
             if (Arrays.asList(groupIds).contains(deptId)){
                 // 阅读权限为1,部门下全体员工可见
                 if (map.getGroupPurview() == 1){
-                    hashMap.put("pkId", map.getPkId());
-                    hashMap.put("name", map.getName());
-                } else if (map.getGroupPurview() == 2){
+                    mapResult.put("pkId", map.getPkId());
+                    mapResult.put("name", map.getName());
+                    listResult.add(mapResult);
+                } else {
                     QueryWrapper<MapGroupPurviewUser> queryWrapper = new QueryWrapper<>();
                     queryWrapper.eq("MAP_ID",map.getPkId());
                     queryWrapper.eq("USER_ID",userService.queryLoginUser());
                     // 查询结果>0,说明该员工可见
                     Integer count = mapGroupPurviewUserMapper.selectCount(queryWrapper);
                     if (count > 0){
-                        hashMap.put("pkId", map.getPkId());
-                        hashMap.put("name", map.getName());
+                        mapResult.put("pkId", map.getPkId());
+                        mapResult.put("name", map.getName());
+                        listResult.add(mapResult);
                     }
-                } else {
-                    return null;
                 }
-            } else {
-                return null;
             }
-            return hashMap;
-        }).collect(Collectors.toList());
-        return result;
+        });
+        return listResult;
     }
 
+    /**
+     * PC端根据知识地图ID获取知识地图配置的学习路径列表数据(加入权限判断)
+     * @param mapId
+     * @return
+     */
     public List<HashMap<String, Object>> routes(String mapId) {
-        List<MapRoute> mapRouteList = mapRouteMapper.selectList(new LambdaQueryWrapper<MapRoute>().eq(MapRoute::getMapId, mapId));
+        //权限判断
+        Map map = mapMapper.selectById(mapId);
+        //当前登录用户的部门Id
+        String deptId = userService.queryLoginUserDeptId();
+        String[] groupIds = map.getGroupId().split(",");
+        //包含登录人的部门
+        if (Arrays.asList(groupIds).contains(deptId)) {
+            if (map.getGroupPurview() == 1) {
+                return routesInfo(mapId);
+            } else {
+                QueryWrapper<MapGroupPurviewUser> queryWrapper = new QueryWrapper<>();
+                queryWrapper.eq("MAP_ID", map.getPkId());
+                queryWrapper.eq("USER_ID", userService.queryLoginUser());
+                // 查询结果>0,说明该员工可见
+                Integer count = mapGroupPurviewUserMapper.selectCount(queryWrapper);
+                if (count > 0) {
+                    return routesInfo(mapId);
+                }
+            }
+        }
+        return null;
+    }
+
+    /**
+     * PC端根据知识地图ID获取知识地图配置的学习路径列表数据(方法封装)
+     * @param mapId
+     * @return
+     */
+    private List<HashMap<String, Object>> routesInfo(String mapId) {
+        List<MapRoute> mapRouteList = mapRouteMapper.selectList(new LambdaQueryWrapper<MapRoute>().eq(MapRoute::getMapId, mapId).orderByAsc(MapRoute::getSort));
         List<HashMap<String, Object>> result = mapRouteList.stream().map(mapRoute -> {
             HashMap<String, Object> hashMap = new HashMap<>();
             hashMap.put("pkId", mapRoute.getPkId());