提交 ae59edaf 作者: yanxin

关键词组管理增加权限控制

上级 5822adc0
...@@ -19,7 +19,8 @@ import java.util.List; ...@@ -19,7 +19,8 @@ import java.util.List;
@Mapper @Mapper
public interface KeyWordsMapper extends BaseMapper<KeyWords> { public interface KeyWordsMapper extends BaseMapper<KeyWords> {
Page<KeyWordsPage> pageList(@Param("keyWords") KeyWords keyWords, @Param("typeIds") List<String> typeIds, Page<KeyWordsPage> pageList(@Param("userId") String userId,@Param("customerId") String customerId,
@Param("keyWords") KeyWords keyWords, @Param("typeIds") List<String> typeIds,
@Param("subjectId") String subjectId, @Param("search") int search, @Param("subjectId") String subjectId, @Param("search") int search,
@Param("bindingType") String bindingType, Page<KeyWordsPage> page); @Param("bindingType") String bindingType, Page<KeyWordsPage> page);
...@@ -58,9 +59,11 @@ public interface KeyWordsMapper extends BaseMapper<KeyWords> { ...@@ -58,9 +59,11 @@ public interface KeyWordsMapper extends BaseMapper<KeyWords> {
Integer bindCount(@Param("subjectId") String subjectId); Integer bindCount(@Param("subjectId") String subjectId);
List<KeyWordsPage> pageListByTypeIdList(@Param("ids") List<String> ids, @Param("subjectId") String subjectId, @Param("status") int status, @Param("bindingType") String bindingType); List<KeyWordsPage> pageListByTypeIdList(@Param("userId") String userId,@Param("customerId") String customerId,
@Param("ids") List<String> ids, @Param("subjectId") String subjectId, @Param("status") int status, @Param("bindingType") String bindingType);
Integer countByTypeAndIdList(@Param("finalIdList") List<String> finalIdList, @Param("subjectId") String subjectId); Integer countByTypeAndIdList(@Param("userId") String userId,@Param("customerId") String customerId,
@Param("finalIdList") List<String> finalIdList, @Param("subjectId") String subjectId);
List<KeyWordsPage> bindKeyWordsListByIdsAndBindType(@Param("subjectIds") List<String> ids, @Param("bindingType") String bindingType, @Param("metaSearchFlag") Integer metaSearchFlag); List<KeyWordsPage> bindKeyWordsListByIdsAndBindType(@Param("subjectIds") List<String> ids, @Param("bindingType") String bindingType, @Param("metaSearchFlag") Integer metaSearchFlag);
} }
...@@ -32,4 +32,5 @@ public interface KeywordsTypeMapper extends BaseMapper<KeywordsType> { ...@@ -32,4 +32,5 @@ public interface KeywordsTypeMapper extends BaseMapper<KeywordsType> {
*/ */
List<KeywordsTypeVo> listAll(); List<KeywordsTypeVo> listAll();
List<KeywordsTypeVo> listAll(@Param("userId") String userId,@Param("customerId") String customerId);
} }
...@@ -3,7 +3,20 @@ ...@@ -3,7 +3,20 @@
<mapper namespace="com.zzsn.event.mapper.KeyWordsMapper"> <mapper namespace="com.zzsn.event.mapper.KeyWordsMapper">
<select id="pageList" resultType="com.zzsn.event.vo.KeyWordsPage"> <select id="pageList" resultType="com.zzsn.event.vo.KeyWordsPage">
SELECT distinct d.*, c.id as keyWordsTypeId, c.type_name as keyWordTypeNames from key_words d SELECT distinct d.*, c.id as keyWordsTypeId, c.type_name as keyWordTypeNames from
<choose>
<when test="userId !=null and userId != ''">
( select s.* from key_words s inner join sys_user_data_permission dp
on s.id=dp.permission_id and dp.user_id = #{userId} )
</when>
<when test="customerId !=null and customerId != ''">
( select s.* from key_words s inner join customer_data_permission_map m
on s.id=m.permission_id and m.customer_id = #{customerId} )
</when>
<otherwise>
key_words
</otherwise>
</choose> d
LEFT JOIN keywords_type_map b ON b.keywords_id = d.id LEFT JOIN keywords_type_map b ON b.keywords_id = d.id
LEFT JOIN keywords_type c ON b.type_id = c.id LEFT JOIN keywords_type c ON b.type_id = c.id
where 1 = 1 where 1 = 1
...@@ -93,7 +106,21 @@ ...@@ -93,7 +106,21 @@
</select> </select>
<select id="pageListByTypeIdList" resultType="com.zzsn.event.vo.KeyWordsPage"> <select id="pageListByTypeIdList" resultType="com.zzsn.event.vo.KeyWordsPage">
SELECT a.*,b.type_id as typeId FROM key_words a SELECT a.*,b.type_id as typeId FROM
<choose>
<when test="userId !=null and userId != ''">
( select s.* from key_words s inner join sys_user_data_permission dp
on s.id=dp.permission_id and dp.user_id = #{userId} )
</when>
<when test="customerId !=null and customerId != ''">
( select s.* from key_words s inner join customer_data_permission_map m
on s.id=m.permission_id and m.customer_id = #{customerId} )
</when>
<otherwise>
key_words
</otherwise>
</choose>
a
INNER JOIN keywords_type_map b ON a.id = b.keywords_id INNER JOIN keywords_type_map b ON a.id = b.keywords_id
WHERE a.status = #{status} WHERE a.status = #{status}
<if test="ids!=null and ids.size()>0"> <if test="ids!=null and ids.size()>0">
...@@ -112,7 +139,21 @@ ...@@ -112,7 +139,21 @@
</select> </select>
<select id="countByTypeAndIdList" resultType="java.lang.Integer"> <select id="countByTypeAndIdList" resultType="java.lang.Integer">
SELECT count(1) FROM key_words a SELECT count(1) FROM
<choose>
<when test="userId !=null and userId != ''">
( select s.* from key_words s inner join sys_user_data_permission dp
on s.id=dp.permission_id and dp.user_id = #{userId} )
</when>
<when test="customerId !=null and customerId != ''">
( select s.* from key_words s inner join customer_data_permission_map m
on s.id=m.permission_id and m.customer_id = #{customerId} )
</when>
<otherwise>
key_words
</otherwise>
</choose>
a
INNER JOIN keywords_type_map b ON a.id = b.keywords_id INNER JOIN keywords_type_map b ON a.id = b.keywords_id
WHERE b.type_id in WHERE b.type_id in
<foreach item="typeId" collection="finalIdList" open="(" separator="," close=")"> <foreach item="typeId" collection="finalIdList" open="(" separator="," close=")">
......
...@@ -7,7 +7,21 @@ ...@@ -7,7 +7,21 @@
</update> </update>
<select id="listAll" resultType="com.zzsn.event.vo.KeywordsTypeVo"> <select id="listAll" resultType="com.zzsn.event.vo.KeywordsTypeVo">
select s.* from keywords_type s select s.* from keywords_type
<choose>
<when test="userId !=null and userId != ''">
( select s.* from keywords_type s inner join sys_user_data_permission dp
on s.id=dp.permission_id and dp.user_id = #{userId} )
</when>
<when test="customerId !=null and customerId != ''">
( select s.* from keywords_type s inner join customer_data_permission_map m
on s.id=m.permission_id and m.customer_id = #{customerId} )
</when>
<otherwise>
keywords_type
</otherwise>
</choose>
s
</select> </select>
</mapper> </mapper>
...@@ -85,9 +85,9 @@ public interface IKeyWordsService extends IService<KeyWords> { ...@@ -85,9 +85,9 @@ public interface IKeyWordsService extends IService<KeyWords> {
*/ */
Integer bindCount(String subjectId); Integer bindCount(String subjectId);
List<KeyWordsPage> listByTypeIdList(List<String> typeIds, String subjectId, int status,String bindingType); List<KeyWordsPage> listByTypeIdList(String userId,String customerId,List<String> typeIds, String subjectId, int status,String bindingType);
Integer countByTypeAndIdList(List<String> finalIdList, String subjectId); Integer countByTypeAndIdList(String userId, String customerId,List<String> finalIdList, String subjectId);
List<KeyWordsPage> bindKeyWordsListByIdsAndBindType(List<String> ids, String bindingType,Integer metaSearchFlag); List<KeyWordsPage> bindKeyWordsListByIdsAndBindType(List<String> ids, String bindingType,Integer metaSearchFlag);
} }
...@@ -22,11 +22,14 @@ import com.zzsn.event.util.CodeGenerateUtil; ...@@ -22,11 +22,14 @@ import com.zzsn.event.util.CodeGenerateUtil;
import com.zzsn.event.util.RedisUtil; import com.zzsn.event.util.RedisUtil;
import com.zzsn.event.util.tree.Node; import com.zzsn.event.util.tree.Node;
import com.zzsn.event.util.tree.TreeUtil; import com.zzsn.event.util.tree.TreeUtil;
import com.zzsn.event.util.user.AuthUtil;
import com.zzsn.event.util.user.UserVo;
import com.zzsn.event.vo.KeyWordsPage; import com.zzsn.event.vo.KeyWordsPage;
import com.zzsn.event.vo.KeywordsVO; import com.zzsn.event.vo.KeywordsVO;
import com.zzsn.event.vo.SubjectKeywordsMap; import com.zzsn.event.vo.SubjectKeywordsMap;
import com.zzsn.event.xxljob.service.IXxlJobInfoService; import com.zzsn.event.xxljob.service.IXxlJobInfoService;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.BeanUtils; import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.kafka.core.KafkaTemplate; import org.springframework.kafka.core.KafkaTemplate;
...@@ -86,7 +89,19 @@ public class KeyWordsServiceImpl extends ServiceImpl<KeyWordsMapper, KeyWords> i ...@@ -86,7 +89,19 @@ public class KeyWordsServiceImpl extends ServiceImpl<KeyWordsMapper, KeyWords> i
} }
//查询列表 //查询列表
Page<KeyWordsPage> page = new Page<>(pageNo, pageSize); Page<KeyWordsPage> page = new Page<>(pageNo, pageSize);
return baseMapper.pageList(keyWords, typeIds, subjectId, searchValue,bindingType,page);
UserVo loginUser = AuthUtil.getLoginUser();
String userId = null;
String customerId = null;
if(loginUser.getCategory() != null){
Integer category = loginUser.getCategory();
if (category.equals(Constants.COMMON_USER)) {
userId = loginUser.getId();
} else if (category.equals(Constants.ADMIN_USER)) {
customerId = loginUser.getRelTenantIds();
}
}
return baseMapper.pageList(userId,customerId,keyWords, typeIds, subjectId, searchValue,bindingType,page);
} }
@Override @Override
...@@ -276,13 +291,14 @@ public class KeyWordsServiceImpl extends ServiceImpl<KeyWordsMapper, KeyWords> i ...@@ -276,13 +291,14 @@ public class KeyWordsServiceImpl extends ServiceImpl<KeyWordsMapper, KeyWords> i
} }
@Override @Override
public List<KeyWordsPage> listByTypeIdList(List<String> typeIds, String subjectId, int status, String bindingType) { public List<KeyWordsPage> listByTypeIdList(String userId, String customerId,
return baseMapper.pageListByTypeIdList(typeIds,subjectId,status,bindingType); List<String> typeIds, String subjectId, int status, String bindingType) {
return baseMapper.pageListByTypeIdList(userId, customerId,typeIds,subjectId,status,bindingType);
} }
@Override @Override
public Integer countByTypeAndIdList(List<String> finalIdList, String subjectId) { public Integer countByTypeAndIdList(String userId,String customerId,List<String> finalIdList, String subjectId) {
return baseMapper.countByTypeAndIdList(finalIdList,subjectId); return baseMapper.countByTypeAndIdList(userId,customerId,finalIdList,subjectId);
} }
private void addMapMain(KeyWords keyWords, String keyWordsTypeId) { private void addMapMain(KeyWords keyWords, String keyWordsTypeId) {
......
...@@ -2,10 +2,13 @@ package com.zzsn.event.service.impl; ...@@ -2,10 +2,13 @@ package com.zzsn.event.service.impl;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.zzsn.event.constant.Constants;
import com.zzsn.event.entity.KeywordsType; import com.zzsn.event.entity.KeywordsType;
import com.zzsn.event.mapper.KeywordsTypeMapper; import com.zzsn.event.mapper.KeywordsTypeMapper;
import com.zzsn.event.service.IKeyWordsService; import com.zzsn.event.service.IKeyWordsService;
import com.zzsn.event.service.IKeywordsTypeService; import com.zzsn.event.service.IKeywordsTypeService;
import com.zzsn.event.util.user.AuthUtil;
import com.zzsn.event.util.user.UserVo;
import com.zzsn.event.vo.KeyWordsPage; import com.zzsn.event.vo.KeyWordsPage;
import com.zzsn.event.vo.KeywordsTypeVo; import com.zzsn.event.vo.KeywordsTypeVo;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
...@@ -135,11 +138,24 @@ public class KeywordsTypeServiceImpl extends ServiceImpl<KeywordsTypeMapper, Key ...@@ -135,11 +138,24 @@ public class KeywordsTypeServiceImpl extends ServiceImpl<KeywordsTypeMapper, Key
@Override @Override
public List<KeywordsTypeVo> listByParentIdAndSubjectId(String subjectId, String parentId) { public List<KeywordsTypeVo> listByParentIdAndSubjectId(String subjectId, String parentId) {
UserVo loginUser = AuthUtil.getLoginUser();
String userId = null;
String customerId = null;
if(loginUser.getCategory() != null){
Integer category = loginUser.getCategory();
if (category.equals(Constants.COMMON_USER)) {
userId = loginUser.getId();
} else if (category.equals(Constants.ADMIN_USER)) {
customerId = loginUser.getRelTenantIds();
}
}
if (!parentId.equals("0")) { if (!parentId.equals("0")) {
KeywordsType parent = this.getById(parentId); KeywordsType parent = this.getById(parentId);
List<KeywordsTypeVo> finalList = new ArrayList<>(); List<KeywordsTypeVo> finalList = new ArrayList<>();
if (StringUtils.isEmpty(parent.getHasChild()) || "0".equals(parent.getHasChild())) { if (StringUtils.isEmpty(parent.getHasChild()) || "0".equals(parent.getHasChild())) {
List<KeyWordsPage> pageList = keyWordsService.listByTypeIdList(Collections.singletonList(parentId), subjectId, 1,null); List<KeyWordsPage> pageList = keyWordsService.listByTypeIdList(userId,customerId,Collections.singletonList(parentId), subjectId, 1,null);
if (pageList != null && !pageList.isEmpty()) { if (pageList != null && !pageList.isEmpty()) {
for (KeyWordsPage keyWordsPage : pageList) { for (KeyWordsPage keyWordsPage : pageList) {
KeywordsTypeVo keywordsTypeVo = new KeywordsTypeVo(); KeywordsTypeVo keywordsTypeVo = new KeywordsTypeVo();
...@@ -160,7 +176,7 @@ public class KeywordsTypeServiceImpl extends ServiceImpl<KeywordsTypeMapper, Key ...@@ -160,7 +176,7 @@ public class KeywordsTypeServiceImpl extends ServiceImpl<KeywordsTypeMapper, Key
infoSourceTypeVo.setTypeName("所有"); infoSourceTypeVo.setTypeName("所有");
infoSourceTypeVo.setPid("0"); infoSourceTypeVo.setPid("0");
infoSourceTypeVo.setHasChild("1"); infoSourceTypeVo.setHasChild("1");
List<KeywordsTypeVo> list = baseMapper.listAll(); List<KeywordsTypeVo> list = baseMapper.listAll(userId,customerId);
Map<String, List<KeywordsTypeVo>> pidMap = list.stream().collect(Collectors.groupingBy(KeywordsTypeVo::getPid)); Map<String, List<KeywordsTypeVo>> pidMap = list.stream().collect(Collectors.groupingBy(KeywordsTypeVo::getPid));
List<KeywordsTypeVo> firstGroup = list.stream().filter(item -> item.getPid().equals(parentId)).collect(Collectors.toList()); List<KeywordsTypeVo> firstGroup = list.stream().filter(item -> item.getPid().equals(parentId)).collect(Collectors.toList());
...@@ -170,7 +186,7 @@ public class KeywordsTypeServiceImpl extends ServiceImpl<KeywordsTypeMapper, Key ...@@ -170,7 +186,7 @@ public class KeywordsTypeServiceImpl extends ServiceImpl<KeywordsTypeMapper, Key
List<String> oneInList = new ArrayList<>(); List<String> oneInList = new ArrayList<>();
oneInList.add(keywordsTypeVo.getId()); oneInList.add(keywordsTypeVo.getId());
//tips 当数据量大 最好不用列表 //tips 当数据量大 最好不用列表
Integer count = keyWordsService.countByTypeAndIdList(oneInList,subjectId); Integer count = keyWordsService.countByTypeAndIdList(userId,customerId,oneInList,subjectId);
keywordsTypeVo.setChildrenCount(count); keywordsTypeVo.setChildrenCount(count);
} else { } else {
//获取每个下面最后一级分类列表 //获取每个下面最后一级分类列表
...@@ -180,7 +196,7 @@ public class KeywordsTypeServiceImpl extends ServiceImpl<KeywordsTypeMapper, Key ...@@ -180,7 +196,7 @@ public class KeywordsTypeServiceImpl extends ServiceImpl<KeywordsTypeMapper, Key
getFinalIdListInMap(singleList, pidMap, finalGradeList); getFinalIdListInMap(singleList, pidMap, finalGradeList);
List<String> finalIdList = finalGradeList.stream().map(KeywordsTypeVo::getId).collect(Collectors.toList()); List<String> finalIdList = finalGradeList.stream().map(KeywordsTypeVo::getId).collect(Collectors.toList());
if (!finalIdList.isEmpty()) { if (!finalIdList.isEmpty()) {
Integer count = keyWordsService.countByTypeAndIdList(finalIdList, subjectId); Integer count = keyWordsService.countByTypeAndIdList(userId,customerId,finalIdList, subjectId);
keywordsTypeVo.setChildrenCount(count); keywordsTypeVo.setChildrenCount(count);
} else { } else {
keywordsTypeVo.setChildrenCount(0); keywordsTypeVo.setChildrenCount(0);
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论