From c43b0e959748e00ec6261c02a409c4eea8374e5f Mon Sep 17 00:00:00 2001 From: sxu <602087911@qq.com> Date: Fri, 28 Feb 2025 16:50:53 +0800 Subject: [PATCH] =?UTF-8?q?=E7=B3=BB=E7=BB=9F=E5=8C=BA=E5=9F=9F=E6=9D=83?= =?UTF-8?q?=E9=99=90=E6=A0=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/AllocAreaController.java | 77 +++++++++++++++ .../canteen/mapper/AllocAreaMapper.java | 4 +- .../canteen/service/AllocAreaService.java | 5 +- .../service/impl/AllocAreaServiceImpl.java | 98 ++++++++++--------- .../mapper/alloc/AllocAreaMapper.xml | 46 ++++----- 5 files changed, 158 insertions(+), 72 deletions(-) create mode 100644 bonus-modules/bonus-smart-canteen/src/main/java/com/bonus/canteen/core/allocation/canteen/controller/AllocAreaController.java diff --git a/bonus-modules/bonus-smart-canteen/src/main/java/com/bonus/canteen/core/allocation/canteen/controller/AllocAreaController.java b/bonus-modules/bonus-smart-canteen/src/main/java/com/bonus/canteen/core/allocation/canteen/controller/AllocAreaController.java new file mode 100644 index 00000000..6063c5e4 --- /dev/null +++ b/bonus-modules/bonus-smart-canteen/src/main/java/com/bonus/canteen/core/allocation/canteen/controller/AllocAreaController.java @@ -0,0 +1,77 @@ +package com.bonus.canteen.core.allocation.canteen.controller; + +import cn.hutool.core.lang.tree.Tree; +import com.bonus.canteen.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 pageArea(@RequestBody LeRequest request) { +// return this.allocAreaService.pageArea((AllocAreaParam)request.getContent()); +// } +// +// @ApiOperation("系统区域树") +// @PostMapping({"/system/tree"}) +// public List> getSystemAreaTree() { +// return this.allocAreaService.getSystemAreaTree(); +// } + + @ApiOperation("系统区域权限树") + @PostMapping({"/system-auth/tree"}) + public List> getSystemAuthAreaTree() { + return this.allocAreaService.getSystemAuthAreaTree(); + } + +// @ApiOperation("根据区域id,查询区域名称") +// @PostMapping({"/get-area-name"}) +// @RequiresGuest +// public LeResponse getAreaName(@RequestBody LeRequest request) { +// return LeResponse.succ(this.allocAreaService.getAreaName((Long)request.getContent())); +// } +// +// @ApiOperation("新增区域") +// @PostMapping({"/add"}) +// @RequiresGuest +// public void addArea(@RequestBody @Valid LeRequest request) { +// this.allocAreaService.addArea((AllocAreaAddDTO)request.getContent()); +// } +// +// @ApiOperation("修改区域") +// @PostMapping({"/update"}) +// @RequiresGuest +// public void updateArea(@RequestBody @Valid LeRequest request) { +// this.allocAreaService.updateArea((AllocAreaUpdateDTO)request.getContent()); +// } +// +// @ApiOperation("删除区域") +// @PostMapping({"/remove"}) +// @RequiresGuest +// public void removeArea(@RequestBody @Valid LeRequest request) { +// this.allocCanteenBusiness.removeArea((Long)request.getContent()); +// } +} diff --git a/bonus-modules/bonus-smart-canteen/src/main/java/com/bonus/canteen/core/allocation/canteen/mapper/AllocAreaMapper.java b/bonus-modules/bonus-smart-canteen/src/main/java/com/bonus/canteen/core/allocation/canteen/mapper/AllocAreaMapper.java index 271a4753..d915eca3 100644 --- a/bonus-modules/bonus-smart-canteen/src/main/java/com/bonus/canteen/core/allocation/canteen/mapper/AllocAreaMapper.java +++ b/bonus-modules/bonus-smart-canteen/src/main/java/com/bonus/canteen/core/allocation/canteen/mapper/AllocAreaMapper.java @@ -33,8 +33,8 @@ public interface AllocAreaMapper extends BaseMapper { // ) List listAllTreeArea(); -// List listSystemArea(Long tenantId); -// + List listSystemArea(Long tenantId); + // @Select({"SELECT area_id FROM alloc_area WHERE super_id = #{superId} AND if_del = 2"}) // List listChildAreaId(Long superId); // diff --git a/bonus-modules/bonus-smart-canteen/src/main/java/com/bonus/canteen/core/allocation/canteen/service/AllocAreaService.java b/bonus-modules/bonus-smart-canteen/src/main/java/com/bonus/canteen/core/allocation/canteen/service/AllocAreaService.java index b5e2277d..f45bc6f0 100644 --- a/bonus-modules/bonus-smart-canteen/src/main/java/com/bonus/canteen/core/allocation/canteen/service/AllocAreaService.java +++ b/bonus-modules/bonus-smart-canteen/src/main/java/com/bonus/canteen/core/allocation/canteen/service/AllocAreaService.java @@ -1,5 +1,6 @@ package com.bonus.canteen.core.allocation.canteen.service; +import cn.hutool.core.lang.tree.Tree; import com.baomidou.mybatisplus.extension.service.IService; import com.bonus.canteen.core.allocation.canteen.model.AllocArea; import com.bonus.canteen.core.allocation.canteen.vo.AllocAreaFullNameVO; @@ -21,8 +22,8 @@ public interface AllocAreaService extends IService { // List> getSystemAreaTree(); // -// List> getSystemAuthAreaTree(); -// + List> getSystemAuthAreaTree(); + // void addArea(AllocAreaAddDTO areaAddDTO); // // void batchSaveFirstArea(List areaNameList); diff --git a/bonus-modules/bonus-smart-canteen/src/main/java/com/bonus/canteen/core/allocation/canteen/service/impl/AllocAreaServiceImpl.java b/bonus-modules/bonus-smart-canteen/src/main/java/com/bonus/canteen/core/allocation/canteen/service/impl/AllocAreaServiceImpl.java index 3f81e28b..5e9d529d 100644 --- a/bonus-modules/bonus-smart-canteen/src/main/java/com/bonus/canteen/core/allocation/canteen/service/impl/AllocAreaServiceImpl.java +++ b/bonus-modules/bonus-smart-canteen/src/main/java/com/bonus/canteen/core/allocation/canteen/service/impl/AllocAreaServiceImpl.java @@ -1,6 +1,9 @@ package com.bonus.canteen.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; @@ -10,14 +13,19 @@ import com.bonus.canteen.core.allocation.canteen.model.AllocArea; import com.bonus.canteen.core.allocation.canteen.service.AllocAreaService; import com.bonus.canteen.core.allocation.canteen.vo.AllocAreaFullNameVO; import com.bonus.canteen.core.allocation.canteen.vo.AllocAreaTreeVO; +import com.bonus.canteen.core.common.utils.TenantContextHolder; import com.bonus.canteen.core.common.utils.TreeNodeUtil; +import com.bonus.canteen.core.common.utils.BaseTreeNode; +import com.bonus.common.houqin.constant.LeConstants; 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 implements AllocAreaService { @@ -162,51 +170,51 @@ public class AllocAreaServiceImpl extends ServiceImpl> getSystemAuthAreaTree() { -// List areaList = ((AllocAreaMapper)this.baseMapper).listSystemArea(TenantContextHolder.getTenantId()); -// List filterAreaTreeList = ((AllocAreaMapper)this.baseMapper).listAllTreeArea(); -// if (CollUtil.isNotEmpty(filterAreaTreeList)) { -// List 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> getSystemAuthAreaTree() { + List areaList = ((AllocAreaMapper)this.baseMapper).listSystemArea(TenantContextHolder.getTenantId()); + List filterAreaTreeList = ((AllocAreaMapper)this.baseMapper).listAllTreeArea(); + if (CollUtil.isNotEmpty(filterAreaTreeList)) { + List 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()); diff --git a/bonus-modules/bonus-smart-canteen/src/main/resources/mapper/alloc/AllocAreaMapper.xml b/bonus-modules/bonus-smart-canteen/src/main/resources/mapper/alloc/AllocAreaMapper.xml index be9331cb..fdb079f1 100644 --- a/bonus-modules/bonus-smart-canteen/src/main/resources/mapper/alloc/AllocAreaMapper.xml +++ b/bonus-modules/bonus-smart-canteen/src/main/resources/mapper/alloc/AllocAreaMapper.xml @@ -31,29 +31,29 @@ WHERE t1.if_del = 2 - - - - - - - - - - - - - - - - - - - - - - - + +