系统区域权限树

This commit is contained in:
sxu 2025-02-28 16:51:02 +08:00
parent 23b671d75d
commit 9b5715bd4e
5 changed files with 159 additions and 73 deletions

View File

@ -0,0 +1,78 @@
package com.bonus.core.allocation.canteen.controller;
import cn.hutool.core.lang.tree.Tree;
import com.bonus.core.allocation.canteen.service.AllocAreaService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Lazy;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import java.util.List;
@RestController
@RequestMapping({"/api/v2/alloc/area"})
@Api(
tags = {"lsh_食堂区域控制器"}
)
public class AllocAreaController {
private static final Logger log = LoggerFactory.getLogger(AllocAreaController.class);
// @Autowired
// @Lazy
// private AllocCanteenBusiness allocCanteenBusiness;
@Autowired
@Lazy
private AllocAreaService allocAreaService;
// @ApiOperation("分页查询区域列表")
// @PostMapping({"/page"})
// @RequiresGuest
// public Page<AllocAreaVO> pageArea(@RequestBody LeRequest<AllocAreaParam> request) {
// return this.allocAreaService.pageArea((AllocAreaParam)request.getContent());
// }
//
// @ApiOperation("系统区域树")
// @PostMapping({"/system/tree"})
// public List<Tree<Long>> getSystemAreaTree() {
// return this.allocAreaService.getSystemAreaTree();
// }
@ApiOperation("系统区域权限树")
@PostMapping({"/system-auth/tree"})
public List<Tree<Long>> getSystemAuthAreaTree() {
return this.allocAreaService.getSystemAuthAreaTree();
}
// @ApiOperation("根据区域id查询区域名称")
// @PostMapping({"/get-area-name"})
// @RequiresGuest
// public LeResponse<String> getAreaName(@RequestBody LeRequest<Long> request) {
// return LeResponse.succ(this.allocAreaService.getAreaName((Long)request.getContent()));
// }
//
// @ApiOperation("新增区域")
// @PostMapping({"/add"})
// @RequiresGuest
// public void addArea(@RequestBody @Valid LeRequest<AllocAreaAddDTO> request) {
// this.allocAreaService.addArea((AllocAreaAddDTO)request.getContent());
// }
//
// @ApiOperation("修改区域")
// @PostMapping({"/update"})
// @RequiresGuest
// public void updateArea(@RequestBody @Valid LeRequest<AllocAreaUpdateDTO> request) {
// this.allocAreaService.updateArea((AllocAreaUpdateDTO)request.getContent());
// }
//
// @ApiOperation("删除区域")
// @PostMapping({"/remove"})
// @RequiresGuest
// public void removeArea(@RequestBody @Valid LeRequest<Long> request) {
// this.allocCanteenBusiness.removeArea((Long)request.getContent());
// }
}

View File

@ -33,8 +33,8 @@ public interface AllocAreaMapper extends BaseMapper<AllocArea> {
// )
List<AllocAreaTreeVO> listAllTreeArea();
// List<AllocAreaTreeVO> listSystemArea(Long tenantId);
//
List<AllocAreaTreeVO> listSystemArea(Long tenantId);
// @Select({"SELECT area_id FROM alloc_area WHERE super_id = #{superId} AND if_del = 2"})
// List<Long> listChildAreaId(Long superId);
//

View File

@ -1,9 +1,9 @@
package com.bonus.core.allocation.canteen.service;
import cn.hutool.core.lang.tree.Tree;
import com.baomidou.mybatisplus.extension.service.IService;
import com.bonus.core.allocation.canteen.model.AllocArea;
import com.bonus.core.allocation.canteen.vo.AllocAreaFullNameVO;
import java.util.List;
public interface AllocAreaService extends IService<AllocArea> {
@ -21,8 +21,8 @@ public interface AllocAreaService extends IService<AllocArea> {
// List<Tree<Long>> getSystemAreaTree();
//
// List<Tree<Long>> getSystemAuthAreaTree();
//
List<Tree<Long>> getSystemAuthAreaTree();
// void addArea(AllocAreaAddDTO areaAddDTO);
//
// void batchSaveFirstArea(List<String> areaNameList);

View File

@ -1,23 +1,31 @@
package com.bonus.core.allocation.canteen.service.impl;
import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.lang.tree.Tree;
import cn.hutool.core.lang.tree.TreeNodeConfig;
import cn.hutool.core.lang.tree.TreeUtil;
import cn.hutool.core.text.CharSequenceUtil;
import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.bonus.constant.LeConstants;
import com.bonus.core.allocation.canteen.mapper.AllocAreaMapper;
import com.bonus.core.allocation.canteen.model.AllocArea;
import com.bonus.core.allocation.canteen.service.AllocAreaService;
import com.bonus.core.allocation.canteen.vo.AllocAreaFullNameVO;
import com.bonus.core.allocation.canteen.vo.AllocAreaTreeVO;
import com.bonus.core.common.utils.TenantContextHolder;
import com.bonus.core.common.utils.TreeNodeUtil;
import com.bonus.core.common.utils.BaseTreeNode;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;
import java.util.ArrayList;
import java.util.Comparator;
import java.util.Iterator;
import java.util.List;
import java.util.stream.Collectors;
@Service
public class AllocAreaServiceImpl extends ServiceImpl<AllocAreaMapper, AllocArea> implements AllocAreaService {
@ -162,51 +170,51 @@ public class AllocAreaServiceImpl extends ServiceImpl<AllocAreaMapper, AllocArea
// treeNode.putExtra("crtime", area.getCrtime());
// });
// }
//
// public List<Tree<Long>> getSystemAuthAreaTree() {
// List<AllocAreaTreeVO> areaList = ((AllocAreaMapper)this.baseMapper).listSystemArea(TenantContextHolder.getTenantId());
// List<AllocAreaTreeVO> filterAreaTreeList = ((AllocAreaMapper)this.baseMapper).listAllTreeArea();
// if (CollUtil.isNotEmpty(filterAreaTreeList)) {
// List<Long> filterAreaIdList = (List)filterAreaTreeList.stream().map(BaseTreeNode::getId).collect(Collectors.toList());
// areaList.removeIf((treeVO) -> {
// return !LeConstants.DATA_DEFAULT_LONG.equals(treeVO.getParentId()) && !filterAreaIdList.contains(treeVO.getId());
// });
// }
//
// TreeNodeConfig treeNodeConfig = new TreeNodeConfig();
// treeNodeConfig.setWeightKey("crtime");
// treeNodeConfig.setNameKey("treeName");
// areaList.sort(Comparator.comparing(AllocAreaTreeVO::getSortNo));
// if (areaList.size() > 1 && ((AllocAreaTreeVO)areaList.get(1)).getSortNo() >= 2) {
// if (((AllocAreaTreeVO)areaList.get(1)).getSortNo() == 2) {
// areaList.forEach((allocAreaTreeVO) -> {
// if (allocAreaTreeVO.getSortNo() == 2) {
// allocAreaTreeVO.setParentId(TenantContextHolder.getTenantId());
// }
//
// });
// }
//
// if (((AllocAreaTreeVO)areaList.get(1)).getSortNo() == 3) {
// areaList.forEach((allocAreaTreeVO) -> {
// if (allocAreaTreeVO.getSortNo() == 3) {
// allocAreaTreeVO.setParentId(TenantContextHolder.getTenantId());
// }
//
// });
// }
// }
//
// return TreeUtil.build(areaList, LeConstants.DATA_DEFAULT_LONG, treeNodeConfig, (area, treeNode) -> {
// treeNode.setId(area.getId());
// treeNode.setName(area.getTreeName());
// treeNode.setParentId(area.getParentId());
// treeNode.putExtra("areaLevel", area.getAreaLevel());
// treeNode.putExtra("sortNo", area.getSortNo());
// treeNode.putExtra("crtime", area.getCrtime());
// });
// }
//
public List<Tree<Long>> getSystemAuthAreaTree() {
List<AllocAreaTreeVO> areaList = ((AllocAreaMapper)this.baseMapper).listSystemArea(TenantContextHolder.getTenantId());
List<AllocAreaTreeVO> filterAreaTreeList = ((AllocAreaMapper)this.baseMapper).listAllTreeArea();
if (CollUtil.isNotEmpty(filterAreaTreeList)) {
List<Long> filterAreaIdList = (List)filterAreaTreeList.stream().map(BaseTreeNode::getId).collect(Collectors.toList());
areaList.removeIf((treeVO) -> {
return !LeConstants.DATA_DEFAULT_LONG.equals(treeVO.getParentId()) && !filterAreaIdList.contains(treeVO.getId());
});
}
TreeNodeConfig treeNodeConfig = new TreeNodeConfig();
treeNodeConfig.setWeightKey("crtime");
treeNodeConfig.setNameKey("treeName");
areaList.sort(Comparator.comparing(AllocAreaTreeVO::getSortNo));
if (areaList.size() > 1 && ((AllocAreaTreeVO)areaList.get(1)).getSortNo() >= 2) {
if (((AllocAreaTreeVO)areaList.get(1)).getSortNo() == 2) {
areaList.forEach((allocAreaTreeVO) -> {
if (allocAreaTreeVO.getSortNo() == 2) {
allocAreaTreeVO.setParentId(TenantContextHolder.getTenantId());
}
});
}
if (((AllocAreaTreeVO)areaList.get(1)).getSortNo() == 3) {
areaList.forEach((allocAreaTreeVO) -> {
if (allocAreaTreeVO.getSortNo() == 3) {
allocAreaTreeVO.setParentId(TenantContextHolder.getTenantId());
}
});
}
}
return TreeUtil.build(areaList, LeConstants.DATA_DEFAULT_LONG, treeNodeConfig, (area, treeNode) -> {
treeNode.setId(area.getId());
treeNode.setName(area.getTreeName());
treeNode.setParentId(area.getParentId());
treeNode.putExtra("areaLevel", area.getAreaLevel());
treeNode.putExtra("sortNo", area.getSortNo());
treeNode.putExtra("crtime", area.getCrtime());
});
}
// public void addArea(AllocAreaAddDTO areaDTO) {
// this.checkAreaName(areaDTO.getAreaName(), (Long)null);
// AllocArea addArea = new AllocArea(Id.next());

View File

@ -31,29 +31,29 @@
WHERE t1.if_del = 2
</select>
<!-- &lt;!&ndash; 系统区域树(无权限) &ndash;&gt;-->
<!-- <select id="listSystemArea" resultType="net.xnzn.core.allocation.canteen.vo.AllocAreaTreeVO">-->
<!-- SELECT id, parent_id, tree_name, area_level, sort_no, crtime-->
<!-- FROM (-->
<!-- SELECT #{merchantId} AS id,-->
<!-- - 1 AS parent_id,-->
<!-- merchant_name AS tree_name,-->
<!-- 0 AS area_level,-->
<!-- 0 AS sort_no,-->
<!-- 2 AS if_del,-->
<!-- crtime-->
<!-- FROM merc_merchant-->
<!-- UNION ALL-->
<!-- SELECT area_id AS id,-->
<!-- super_id AS parent_id,-->
<!-- area_name AS tree_name,-->
<!-- if(third_area_name is not null, 3, 0) AS area_level,-->
<!-- sort_no AS sort_no,-->
<!-- if_del,-->
<!-- crtime-->
<!-- FROM alloc_area ) as s-->
<!-- WHERE if_del = 2-->
<!-- </select>-->
<!-- 系统区域树(无权限) -->
<select id="listSystemArea" resultType="com.bonus.core.allocation.canteen.vo.AllocAreaTreeVO">
SELECT id, parent_id, tree_name, area_level, sort_no, crtime
FROM (
SELECT #{merchantId} AS id,
- 1 AS parent_id,
merchant_name AS tree_name,
0 AS area_level,
0 AS sort_no,
2 AS if_del,
crtime
FROM merc_merchant
UNION ALL
SELECT area_id AS id,
super_id AS parent_id,
area_name AS tree_name,
if(third_area_name is not null, 3, 0) AS area_level,
sort_no AS sort_no,
if_del,
crtime
FROM alloc_area ) as s
WHERE if_del = 2
</select>
<!-- <select id="listAreaByUserRole" resultType="net.xnzn.core.allocation.canteen.vo.AllocAreaVO">-->
<!-- SELECT t1.area_id,-->