|
@@ -2,28 +2,259 @@
|
|
|
package com.redxun.knowledge.map.service;
|
|
|
|
|
|
|
|
|
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
+import com.baomidou.mybatisplus.core.metadata.IPage;
|
|
|
import com.redxun.common.base.db.BaseDao;
|
|
|
import com.redxun.common.base.db.BaseService;
|
|
|
+import com.redxun.common.base.db.PageHelper;
|
|
|
+import com.redxun.common.base.search.QueryFilter;
|
|
|
import com.redxun.common.service.impl.SuperServiceImpl;
|
|
|
+import com.redxun.common.tool.IdGenerator;
|
|
|
+import com.redxun.knowledge.common.UserService;
|
|
|
+import com.redxun.knowledge.entity.dao.Knowledge;
|
|
|
+import com.redxun.knowledge.entity.vo.DicVo;
|
|
|
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.dto.MapContentDto;
|
|
|
+import com.redxun.knowledge.map.entity.dto.MapDto;
|
|
|
+import com.redxun.knowledge.map.entity.dto.MapRouteDto;
|
|
|
+import com.redxun.knowledge.map.entity.vo.KnowledgeVo;
|
|
|
+import com.redxun.knowledge.map.entity.vo.MapContentVo;
|
|
|
+import com.redxun.knowledge.map.entity.vo.MapRouteVo;
|
|
|
+import com.redxun.knowledge.map.entity.vo.MapVo;
|
|
|
+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.service.CommonServiceImpl;
|
|
|
+import com.redxun.knowledge.service.KnowledgeServiceImpl;
|
|
|
+import org.springframework.beans.BeanUtils;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
-import java.util.ArrayList;
|
|
|
-import java.util.List;
|
|
|
+import org.springframework.transaction.annotation.Transactional;
|
|
|
+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.stream.Collectors;
|
|
|
|
|
|
/**
|
|
|
-* [业务--知识地图表]业务服务类
|
|
|
-*/
|
|
|
+ * [业务--知识地图表]业务服务类
|
|
|
+ */
|
|
|
@Service
|
|
|
public class MapServiceImpl extends SuperServiceImpl<MapMapper, Map> implements BaseService<Map> {
|
|
|
|
|
|
@Resource
|
|
|
private MapMapper mapMapper;
|
|
|
|
|
|
+ @Autowired
|
|
|
+ private MapRouteMapper mapRouteMapper;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private MapContentMapper mapContentMapper;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private MapGroupPurviewUserMapper mapGroupPurviewUserMapper;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private UserService userService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private CommonServiceImpl commonService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private KnowledgeServiceImpl knowledgeService;
|
|
|
+
|
|
|
@Override
|
|
|
public BaseDao<Map> getRepository() {
|
|
|
return mapMapper;
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 添加地图
|
|
|
+ * @param mapDto
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
+ public String create(MapDto mapDto) {
|
|
|
+ // 向地图表中添加数据
|
|
|
+ Map map = new Map();
|
|
|
+ BeanUtils.copyProperties(mapDto, map);
|
|
|
+ if (mapDto.getPkId() == null){
|
|
|
+ map.setPkId(IdGenerator.getIdStr());
|
|
|
+ }
|
|
|
+ map.setUpdateBy(userService.queryLoginUser());
|
|
|
+ mapMapper.insert(map);
|
|
|
+ Map mapById = mapMapper.selectById(map.getPkId());
|
|
|
+ //向可阅读者表中添加数据
|
|
|
+ List<String> purviewUsers = mapDto.getPurviewUsers();
|
|
|
+ purviewUsers.forEach(purviewUser -> {
|
|
|
+ MapGroupPurviewUser mapGroupPurviewUser = new MapGroupPurviewUser();
|
|
|
+ mapGroupPurviewUser.setPkId(IdGenerator.getIdStr());
|
|
|
+ mapGroupPurviewUser.setMapId(mapById.getPkId());
|
|
|
+ mapGroupPurviewUser.setUserId(purviewUser);
|
|
|
+ mapGroupPurviewUser.setUpdateBy(userService.queryLoginUser());
|
|
|
+ mapGroupPurviewUserMapper.insert(mapGroupPurviewUser);
|
|
|
+ });
|
|
|
+ // 向学习路径表中添加数据
|
|
|
+ if (!CollectionUtils.isEmpty(mapDto.getRoutes())) {
|
|
|
+ List<MapRouteDto> routes = mapDto.getRoutes();
|
|
|
+ routes.forEach(route -> {
|
|
|
+ MapRoute mapRoute = new MapRoute();
|
|
|
+ BeanUtils.copyProperties(route, mapRoute);
|
|
|
+ mapRoute.setPkId(IdGenerator.getIdStr());
|
|
|
+ mapRoute.setMapId(mapById.getPkId());
|
|
|
+ mapRoute.setUpdateBy(userService.queryLoginUser());
|
|
|
+ mapRouteMapper.insert(mapRoute);
|
|
|
+ MapRoute mapRouteById = mapRouteMapper.selectById(mapRoute.getPkId());
|
|
|
+ // 向学习内容表中添加数据
|
|
|
+ if (!CollectionUtils.isEmpty(route.getContents())) {
|
|
|
+ List<MapContentDto> contents = route.getContents();
|
|
|
+ contents.forEach(content -> {
|
|
|
+ MapContent mapContent = new MapContent();
|
|
|
+ BeanUtils.copyProperties(content, mapContent);
|
|
|
+ mapContent.setPkId(IdGenerator.getIdStr());
|
|
|
+ mapContent.setMapId(mapRouteById.getMapId());
|
|
|
+ mapContent.setRouteId(mapRouteById.getPkId());
|
|
|
+ mapContent.setUpdateBy(userService.queryLoginUser());
|
|
|
+ mapContentMapper.insert(mapContent);
|
|
|
+ });
|
|
|
+ }
|
|
|
+ });
|
|
|
+
|
|
|
+ }
|
|
|
+ return mapById.getPkId();
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 分页查询地图列表
|
|
|
+ * @param queryFilter
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ public IPage query(QueryFilter queryFilter) {
|
|
|
+ java.util.Map<String, Object> params = PageHelper.constructParams(queryFilter);
|
|
|
+ IPage page = mapMapper.findAllMap(queryFilter.getPage(), queryFilter.getParams(), params);
|
|
|
+ List<DicVo> dicVoList = commonService.queryDic("KNOWLEDGE_MAP");
|
|
|
+ List<MapVo> records = page.getRecords();
|
|
|
+ records.forEach(e -> {
|
|
|
+ String typeName = e.getTypeName();
|
|
|
+ dicVoList.forEach(dicVo -> {
|
|
|
+ if (dicVo.getValue().equals(typeName)){
|
|
|
+ e.setTypeName(dicVo.getName());
|
|
|
+ }
|
|
|
+ });
|
|
|
+ });
|
|
|
+ return page;
|
|
|
+
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ public MapVo data(String pkId) {
|
|
|
+ MapVo mapVo = new MapVo();
|
|
|
+ Map map = mapMapper.selectById(pkId);
|
|
|
+ BeanUtils.copyProperties(map,mapVo);
|
|
|
+ List<DicVo> dicVoList = commonService.queryDic("KNOWLEDGE_MAP");
|
|
|
+ dicVoList.forEach(dicVo -> {
|
|
|
+ if (map.getType().toString().equals(dicVo.getValue())){
|
|
|
+ mapVo.setTypeName(dicVo.getName());
|
|
|
+ }
|
|
|
+ });
|
|
|
+ List<MapRoute> mapRouteList = mapRouteMapper.selectList(new LambdaQueryWrapper<MapRoute>().eq(MapRoute::getMapId, mapVo.getPkId()).orderByAsc(MapRoute::getSort));
|
|
|
+ if (!CollectionUtils.isEmpty(mapRouteList)){
|
|
|
+ List<MapRouteVo> mapRouteVoList = mapRouteList.stream().map(mapRoute -> {
|
|
|
+ MapRouteVo mapRouteVo = new MapRouteVo();
|
|
|
+ BeanUtils.copyProperties(mapRoute, mapRouteVo);
|
|
|
+ return mapRouteVo;
|
|
|
+ }).collect(Collectors.toList());
|
|
|
+ mapVo.setRoutes(mapRouteVoList);
|
|
|
+ mapRouteVoList.forEach(mapRouteVo -> {
|
|
|
+ List<MapContent> mapContentList = mapContentMapper.selectList(new LambdaQueryWrapper<MapContent>().
|
|
|
+ eq(MapContent::getRouteId, mapRouteVo.getPkId()).orderByAsc(MapContent::getSort));
|
|
|
+ if (!CollectionUtils.isEmpty(mapContentList)){
|
|
|
+ List<MapContentVo> mapContentVoList = mapContentList.stream().map(mapContent -> {
|
|
|
+ MapContentVo mapContentVo = new MapContentVo();
|
|
|
+ BeanUtils.copyProperties(mapContent, mapContentVo);
|
|
|
+ if (mapContent.getKnowledgeId() != null){
|
|
|
+ KnowledgeVo knowledgeVo = new KnowledgeVo();
|
|
|
+ Knowledge knowledge = knowledgeService.get(mapContent.getKnowledgeId());
|
|
|
+ BeanUtils.copyProperties(knowledge,knowledgeVo);
|
|
|
+ String photo = (String) userService.querySexAndPhoto(knowledge.getCreateBy()).get("photo");
|
|
|
+ knowledgeVo.setAuthorHead(photo);
|
|
|
+ knowledgeVo.setAttachmentType(knowledge.getAttachmentName());
|
|
|
+ mapContentVo.setKnowledgeVo(knowledgeVo);
|
|
|
+ }
|
|
|
+ return mapContentVo;
|
|
|
+ }).collect(Collectors.toList());
|
|
|
+ mapRouteVo.setContents(mapContentVoList);
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
+ return mapVo;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
+ @Override
|
|
|
+ public void delete(Collection<Serializable> entities) {
|
|
|
+ //删除学习内容表中数据
|
|
|
+ mapContentMapper.deleteBatchIds(entities);
|
|
|
+ //删除学习路径表中数据
|
|
|
+ mapRouteMapper.deleteBatchIds(entities);
|
|
|
+ //删除可查看员工表中数据
|
|
|
+ mapGroupPurviewUserMapper.deleteBatchIds(entities);
|
|
|
+ //删除地图表中数据
|
|
|
+ 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<>();
|
|
|
+ //当前登录用户的部门Id
|
|
|
+ String deptId = userService.queryLoginUserDeptId();
|
|
|
+ //权限判断
|
|
|
+ String[] groupIds = map.getGroupId().split(",");
|
|
|
+ //是否包含当前用户的部门Id,如果包含 判断该用户是否可见
|
|
|
+ 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){
|
|
|
+ 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());
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+ return hashMap;
|
|
|
+ }).collect(Collectors.toList());
|
|
|
+ return result;
|
|
|
+ }
|
|
|
+
|
|
|
+ public List<HashMap<String, Object>> routes(String mapId) {
|
|
|
+ List<MapRoute> mapRouteList = mapRouteMapper.selectList(new LambdaQueryWrapper<MapRoute>().eq(MapRoute::getMapId, mapId));
|
|
|
+ List<HashMap<String, Object>> result = mapRouteList.stream().map(mapRoute -> {
|
|
|
+ HashMap<String, Object> hashMap = new HashMap<>();
|
|
|
+ hashMap.put("pkId", mapRoute.getPkId());
|
|
|
+ hashMap.put("name", mapRoute.getName());
|
|
|
+ return hashMap;
|
|
|
+ }).collect(Collectors.toList());
|
|
|
+ return result;
|
|
|
+ }
|
|
|
}
|