|
|
|
|
@ -6,6 +6,7 @@ import com.flossom.common.core.domain.entity.SysRole;
|
|
|
|
|
import com.flossom.common.core.domain.entity.SysTag;
|
|
|
|
|
import com.flossom.common.core.domain.entity.SysUser;
|
|
|
|
|
import com.flossom.common.core.domain.vo.TreeSelect;
|
|
|
|
|
import com.flossom.common.core.enums.TagTypeStatus;
|
|
|
|
|
import com.flossom.common.core.exception.ServiceException;
|
|
|
|
|
import com.flossom.common.core.mapper.SysDeptMapper;
|
|
|
|
|
import com.flossom.common.core.mapper.SysRoleMapper;
|
|
|
|
|
@ -20,10 +21,7 @@ import com.flossom.system.service.ISysTagService;
|
|
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
|
|
|
|
import java.util.ArrayList;
|
|
|
|
|
import java.util.Iterator;
|
|
|
|
|
import java.util.List;
|
|
|
|
|
import java.util.Objects;
|
|
|
|
|
import java.util.*;
|
|
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
@ -32,8 +30,7 @@ import java.util.stream.Collectors;
|
|
|
|
|
* @author flossom
|
|
|
|
|
*/
|
|
|
|
|
@Service
|
|
|
|
|
public class SysTagServiceImpl implements ISysTagService
|
|
|
|
|
{
|
|
|
|
|
public class SysTagServiceImpl implements ISysTagService {
|
|
|
|
|
@Autowired
|
|
|
|
|
private SysTagMapper tagMapper;
|
|
|
|
|
|
|
|
|
|
@ -48,8 +45,7 @@ public class SysTagServiceImpl implements ISysTagService
|
|
|
|
|
*/
|
|
|
|
|
@Override
|
|
|
|
|
@DataScope(deptAlias = "d")
|
|
|
|
|
public List<SysTag> selectDeptList(SysTag tag)
|
|
|
|
|
{
|
|
|
|
|
public List<SysTag> selectDeptList(SysTag tag) {
|
|
|
|
|
return tagMapper.selectDeptList(tag);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@ -60,8 +56,7 @@ public class SysTagServiceImpl implements ISysTagService
|
|
|
|
|
* @return 标签树信息集合
|
|
|
|
|
*/
|
|
|
|
|
@Override
|
|
|
|
|
public List<TreeSelect> selectDeptTreeList(SysTag tag)
|
|
|
|
|
{
|
|
|
|
|
public List<TreeSelect> selectDeptTreeList(SysTag tag) {
|
|
|
|
|
List<SysTag> tags = SpringUtils.getAopProxy(this).selectDeptList(tag);
|
|
|
|
|
return buildDeptTreeSelect(tags);
|
|
|
|
|
}
|
|
|
|
|
@ -73,21 +68,17 @@ public class SysTagServiceImpl implements ISysTagService
|
|
|
|
|
* @return 树结构列表
|
|
|
|
|
*/
|
|
|
|
|
@Override
|
|
|
|
|
public List<SysTag> buildDeptTree(List<SysTag> tags)
|
|
|
|
|
{
|
|
|
|
|
public List<SysTag> buildDeptTree(List<SysTag> tags) {
|
|
|
|
|
List<SysTag> returnList = new ArrayList<SysTag>();
|
|
|
|
|
List<Long> tempList = tags.stream().map(SysTag::getId).collect(Collectors.toList());
|
|
|
|
|
for (SysTag tag : tags)
|
|
|
|
|
{
|
|
|
|
|
for (SysTag tag : tags) {
|
|
|
|
|
// 如果是顶级节点, 遍历该父节点的所有子节点
|
|
|
|
|
if (!tempList.contains(tag.getParentId()))
|
|
|
|
|
{
|
|
|
|
|
if (!tempList.contains(tag.getParentId())) {
|
|
|
|
|
recursionFn(tags, tag);
|
|
|
|
|
returnList.add(tag);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (returnList.isEmpty())
|
|
|
|
|
{
|
|
|
|
|
if (returnList.isEmpty()) {
|
|
|
|
|
returnList = tags;
|
|
|
|
|
}
|
|
|
|
|
return returnList;
|
|
|
|
|
@ -100,8 +91,7 @@ public class SysTagServiceImpl implements ISysTagService
|
|
|
|
|
* @return 下拉树结构列表
|
|
|
|
|
*/
|
|
|
|
|
@Override
|
|
|
|
|
public List<TreeSelect> buildDeptTreeSelect(List<SysTag> tags)
|
|
|
|
|
{
|
|
|
|
|
public List<TreeSelect> buildDeptTreeSelect(List<SysTag> tags) {
|
|
|
|
|
List<SysTag> deptTrees = buildDeptTree(tags);
|
|
|
|
|
return deptTrees.stream().map(TreeSelect::new).collect(Collectors.toList());
|
|
|
|
|
}
|
|
|
|
|
@ -113,8 +103,7 @@ public class SysTagServiceImpl implements ISysTagService
|
|
|
|
|
* @return 选中标签列表
|
|
|
|
|
*/
|
|
|
|
|
@Override
|
|
|
|
|
public List<Long> selectDeptListByRoleId(Long roleId)
|
|
|
|
|
{
|
|
|
|
|
public List<Long> selectDeptListByRoleId(Long roleId) {
|
|
|
|
|
SysRole role = roleMapper.selectRoleById(roleId);
|
|
|
|
|
return tagMapper.selectDeptListByRoleId(roleId, role.isDeptCheckStrictly());
|
|
|
|
|
}
|
|
|
|
|
@ -126,8 +115,7 @@ public class SysTagServiceImpl implements ISysTagService
|
|
|
|
|
* @return 标签信息
|
|
|
|
|
*/
|
|
|
|
|
@Override
|
|
|
|
|
public SysTag selectDeptById(Long id)
|
|
|
|
|
{
|
|
|
|
|
public SysTag selectDeptById(Long id) {
|
|
|
|
|
return tagMapper.selectDeptById(id);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@ -138,8 +126,7 @@ public class SysTagServiceImpl implements ISysTagService
|
|
|
|
|
* @return 子标签数
|
|
|
|
|
*/
|
|
|
|
|
@Override
|
|
|
|
|
public int selectNormalChildrenDeptById(Long id)
|
|
|
|
|
{
|
|
|
|
|
public int selectNormalChildrenDeptById(Long id) {
|
|
|
|
|
return tagMapper.selectNormalChildrenDeptById(id);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@ -150,8 +137,7 @@ public class SysTagServiceImpl implements ISysTagService
|
|
|
|
|
* @return 结果
|
|
|
|
|
*/
|
|
|
|
|
@Override
|
|
|
|
|
public boolean hasChildByDeptId(Long id)
|
|
|
|
|
{
|
|
|
|
|
public boolean hasChildByDeptId(Long id) {
|
|
|
|
|
int result = tagMapper.hasChildByDeptId(id);
|
|
|
|
|
return result > 0;
|
|
|
|
|
}
|
|
|
|
|
@ -163,8 +149,7 @@ public class SysTagServiceImpl implements ISysTagService
|
|
|
|
|
* @return 结果 true 存在 false 不存在
|
|
|
|
|
*/
|
|
|
|
|
@Override
|
|
|
|
|
public boolean checkDeptExistUser(Long id)
|
|
|
|
|
{
|
|
|
|
|
public boolean checkDeptExistUser(Long id) {
|
|
|
|
|
int result = tagMapper.checkDeptExistUser(id);
|
|
|
|
|
return result > 0;
|
|
|
|
|
}
|
|
|
|
|
@ -176,12 +161,10 @@ public class SysTagServiceImpl implements ISysTagService
|
|
|
|
|
* @return 结果
|
|
|
|
|
*/
|
|
|
|
|
@Override
|
|
|
|
|
public boolean checkDeptNameUnique(SysTag tag)
|
|
|
|
|
{
|
|
|
|
|
public boolean checkDeptNameUnique(SysTag tag) {
|
|
|
|
|
Long deptId = StringUtils.isNull(tag.getId()) ? -1L : tag.getId();
|
|
|
|
|
SysTag info = tagMapper.checkDeptNameUnique(tag.getTagName(), tag.getParentId());
|
|
|
|
|
if (StringUtils.isNotNull(info) && info.getId().longValue() != deptId.longValue())
|
|
|
|
|
{
|
|
|
|
|
if (StringUtils.isNotNull(info) && info.getId().longValue() != deptId.longValue()) {
|
|
|
|
|
return UserConstants.NOT_UNIQUE;
|
|
|
|
|
}
|
|
|
|
|
return UserConstants.UNIQUE;
|
|
|
|
|
@ -193,15 +176,12 @@ public class SysTagServiceImpl implements ISysTagService
|
|
|
|
|
* @param id 标签id
|
|
|
|
|
*/
|
|
|
|
|
@Override
|
|
|
|
|
public void checkDeptDataScope(Long id)
|
|
|
|
|
{
|
|
|
|
|
if (!SysUser.isAdmin(SecurityUtils.getUserId()))
|
|
|
|
|
{
|
|
|
|
|
public void checkDeptDataScope(Long id) {
|
|
|
|
|
if (!SysUser.isAdmin(SecurityUtils.getUserId())) {
|
|
|
|
|
SysTag tag = new SysTag();
|
|
|
|
|
tag.setId(id);
|
|
|
|
|
List<SysTag> tags = SpringUtils.getAopProxy(this).selectDeptList(tag);
|
|
|
|
|
if (StringUtils.isEmpty(tags))
|
|
|
|
|
{
|
|
|
|
|
if (StringUtils.isEmpty(tags)) {
|
|
|
|
|
throw new ServiceException("没有权限访问标签数据!");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
@ -214,15 +194,14 @@ public class SysTagServiceImpl implements ISysTagService
|
|
|
|
|
* @return 结果
|
|
|
|
|
*/
|
|
|
|
|
@Override
|
|
|
|
|
public int insertDept(SysTag tag)
|
|
|
|
|
{
|
|
|
|
|
public int insertDept(SysTag tag) {
|
|
|
|
|
SysTag info = tagMapper.selectDeptById(tag.getParentId());
|
|
|
|
|
// 如果父节点不为正常状态,则不允许新增子节点
|
|
|
|
|
// if (!UserConstants.DEPT_NORMAL.equals(info.getStatus()))
|
|
|
|
|
// {
|
|
|
|
|
// throw new ServiceException("标签停用,不允许新增");
|
|
|
|
|
// }
|
|
|
|
|
if(Objects.isNull(info)) {
|
|
|
|
|
if (Objects.isNull(info)) {
|
|
|
|
|
tag.setAncestors("0");
|
|
|
|
|
tag.setParentId(0l);
|
|
|
|
|
}
|
|
|
|
|
@ -237,12 +216,10 @@ public class SysTagServiceImpl implements ISysTagService
|
|
|
|
|
* @return 结果
|
|
|
|
|
*/
|
|
|
|
|
@Override
|
|
|
|
|
public int updateDept(SysTag tag)
|
|
|
|
|
{
|
|
|
|
|
public int updateDept(SysTag tag) {
|
|
|
|
|
SysTag newParentDept = tagMapper.selectDeptById(tag.getParentId());
|
|
|
|
|
SysTag oldDept = tagMapper.selectDeptById(tag.getId());
|
|
|
|
|
if (StringUtils.isNotNull(newParentDept) && StringUtils.isNotNull(oldDept))
|
|
|
|
|
{
|
|
|
|
|
if (StringUtils.isNotNull(newParentDept) && StringUtils.isNotNull(oldDept)) {
|
|
|
|
|
String newAncestors = newParentDept.getAncestors() + "," + newParentDept.getId();
|
|
|
|
|
String oldAncestors = oldDept.getAncestors();
|
|
|
|
|
tag.setAncestors(newAncestors);
|
|
|
|
|
@ -250,8 +227,7 @@ public class SysTagServiceImpl implements ISysTagService
|
|
|
|
|
}
|
|
|
|
|
int result = tagMapper.updateDept(tag);
|
|
|
|
|
if (UserConstants.DEPT_NORMAL.equals(tag.getStatus()) && StringUtils.isNotEmpty(tag.getAncestors())
|
|
|
|
|
&& !StringUtils.equals("0", tag.getAncestors()))
|
|
|
|
|
{
|
|
|
|
|
&& !StringUtils.equals("0", tag.getAncestors())) {
|
|
|
|
|
// 如果该标签是启用状态,则启用该标签的所有上级标签
|
|
|
|
|
updateParentDeptStatusNormal(tag);
|
|
|
|
|
}
|
|
|
|
|
@ -263,8 +239,7 @@ public class SysTagServiceImpl implements ISysTagService
|
|
|
|
|
*
|
|
|
|
|
* @param
|
|
|
|
|
*/
|
|
|
|
|
private void updateParentDeptStatusNormal(SysTag tag)
|
|
|
|
|
{
|
|
|
|
|
private void updateParentDeptStatusNormal(SysTag tag) {
|
|
|
|
|
String ancestors = tag.getAncestors();
|
|
|
|
|
Long[] deptIds = Convert.toLongArray(ancestors);
|
|
|
|
|
tagMapper.updateDeptStatusNormal(deptIds);
|
|
|
|
|
@ -277,15 +252,12 @@ public class SysTagServiceImpl implements ISysTagService
|
|
|
|
|
* @param newAncestors 新的父ID集合
|
|
|
|
|
* @param oldAncestors 旧的父ID集合
|
|
|
|
|
*/
|
|
|
|
|
public void updateDeptChildren(Long id, String newAncestors, String oldAncestors)
|
|
|
|
|
{
|
|
|
|
|
public void updateDeptChildren(Long id, String newAncestors, String oldAncestors) {
|
|
|
|
|
List<SysTag> children = tagMapper.selectChildrenDeptById(id);
|
|
|
|
|
for (SysTag child : children)
|
|
|
|
|
{
|
|
|
|
|
for (SysTag child : children) {
|
|
|
|
|
child.setAncestors(child.getAncestors().replaceFirst(oldAncestors, newAncestors));
|
|
|
|
|
}
|
|
|
|
|
if (children.size() > 0)
|
|
|
|
|
{
|
|
|
|
|
if (children.size() > 0) {
|
|
|
|
|
tagMapper.updateDeptChildren(children);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
@ -297,8 +269,7 @@ public class SysTagServiceImpl implements ISysTagService
|
|
|
|
|
* @return 结果
|
|
|
|
|
*/
|
|
|
|
|
@Override
|
|
|
|
|
public int deleteDeptById(Long id)
|
|
|
|
|
{
|
|
|
|
|
public int deleteDeptById(Long id) {
|
|
|
|
|
return tagMapper.deleteDeptById(id);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@ -308,18 +279,49 @@ public class SysTagServiceImpl implements ISysTagService
|
|
|
|
|
return buildDeptTreeSelect(tags);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public List<Map<String, Object>> getMiniProgramTags() {
|
|
|
|
|
List<Map<String, Object>> tagList = new ArrayList<>();
|
|
|
|
|
// 获取小程序标签
|
|
|
|
|
List<SysTag> miniProgramTags = tagMapper.selectSecondTagByType(TagTypeStatus.MINI_PROGRAM.getCode());
|
|
|
|
|
if (miniProgramTags != null && miniProgramTags.size() > 0) {
|
|
|
|
|
Map<String, Object> map;
|
|
|
|
|
for (SysTag miniProgramTag : miniProgramTags) {
|
|
|
|
|
map = new HashMap<>();
|
|
|
|
|
map.put("label", miniProgramTag.getTagName());
|
|
|
|
|
map.put("value", miniProgramTag.getId());
|
|
|
|
|
tagList.add(map);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return tagList;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public List<Map<String, Object>> getWecomTags() {
|
|
|
|
|
List<Map<String, Object>> tagList = new ArrayList<>();
|
|
|
|
|
// 获取小程序标签
|
|
|
|
|
List<SysTag> miniProgramTags = tagMapper.selectSecondTagByType(TagTypeStatus.ENTERPRISE_WECHAT.getCode());
|
|
|
|
|
if (miniProgramTags != null && miniProgramTags.size() > 0) {
|
|
|
|
|
Map<String, Object> map;
|
|
|
|
|
for (SysTag miniProgramTag : miniProgramTags) {
|
|
|
|
|
map = new HashMap<>();
|
|
|
|
|
map.put("label", miniProgramTag.getTagName());
|
|
|
|
|
map.put("value", miniProgramTag.getId());
|
|
|
|
|
tagList.add(map);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return tagList;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 递归列表
|
|
|
|
|
*/
|
|
|
|
|
private void recursionFn(List<SysTag> list, SysTag t)
|
|
|
|
|
{
|
|
|
|
|
private void recursionFn(List<SysTag> list, SysTag t) {
|
|
|
|
|
// 得到子节点列表
|
|
|
|
|
List<SysTag> childList = getChildList(list, t);
|
|
|
|
|
t.setChildren(childList);
|
|
|
|
|
for (SysTag tChild : childList)
|
|
|
|
|
{
|
|
|
|
|
if (hasChild(list, tChild))
|
|
|
|
|
{
|
|
|
|
|
for (SysTag tChild : childList) {
|
|
|
|
|
if (hasChild(list, tChild)) {
|
|
|
|
|
recursionFn(list, tChild);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
@ -328,15 +330,12 @@ public class SysTagServiceImpl implements ISysTagService
|
|
|
|
|
/**
|
|
|
|
|
* 得到子节点列表
|
|
|
|
|
*/
|
|
|
|
|
private List<SysTag> getChildList(List<SysTag> list, SysTag t)
|
|
|
|
|
{
|
|
|
|
|
private List<SysTag> getChildList(List<SysTag> list, SysTag t) {
|
|
|
|
|
List<SysTag> tlist = new ArrayList<SysTag>();
|
|
|
|
|
Iterator<SysTag> it = list.iterator();
|
|
|
|
|
while (it.hasNext())
|
|
|
|
|
{
|
|
|
|
|
while (it.hasNext()) {
|
|
|
|
|
SysTag n = (SysTag) it.next();
|
|
|
|
|
if (StringUtils.isNotNull(n.getParentId()) && n.getParentId().longValue() == t.getId().longValue())
|
|
|
|
|
{
|
|
|
|
|
if (StringUtils.isNotNull(n.getParentId()) && n.getParentId().longValue() == t.getId().longValue()) {
|
|
|
|
|
tlist.add(n);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
@ -346,8 +345,7 @@ public class SysTagServiceImpl implements ISysTagService
|
|
|
|
|
/**
|
|
|
|
|
* 判断是否有子节点
|
|
|
|
|
*/
|
|
|
|
|
private boolean hasChild(List<SysTag> list, SysTag t)
|
|
|
|
|
{
|
|
|
|
|
private boolean hasChild(List<SysTag> list, SysTag t) {
|
|
|
|
|
return getChildList(list, t).size() > 0 ? true : false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|