diff --git a/bonus-modules/bonus-smart-canteen/src/main/java/com/bonus/core/allocation/canteen/controller/AllocAreaController.java b/bonus-modules/bonus-smart-canteen/src/main/java/com/bonus/core/allocation/canteen/controller/AllocAreaController.java new file mode 100644 index 00000000..b6f2703b --- /dev/null +++ b/bonus-modules/bonus-smart-canteen/src/main/java/com/bonus/core/allocation/canteen/controller/AllocAreaController.java @@ -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 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/core/allocation/canteen/mapper/AllocAreaMapper.java b/bonus-modules/bonus-smart-canteen/src/main/java/com/bonus/core/allocation/canteen/mapper/AllocAreaMapper.java index 9e9ce3fd..3c82a2e8 100644 --- a/bonus-modules/bonus-smart-canteen/src/main/java/com/bonus/core/allocation/canteen/mapper/AllocAreaMapper.java +++ b/bonus-modules/bonus-smart-canteen/src/main/java/com/bonus/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/core/allocation/canteen/service/AllocAreaService.java b/bonus-modules/bonus-smart-canteen/src/main/java/com/bonus/core/allocation/canteen/service/AllocAreaService.java index 1856b9a5..ba57cbb8 100644 --- a/bonus-modules/bonus-smart-canteen/src/main/java/com/bonus/core/allocation/canteen/service/AllocAreaService.java +++ b/bonus-modules/bonus-smart-canteen/src/main/java/com/bonus/core/allocation/canteen/service/AllocAreaService.java @@ -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 { @@ -21,8 +21,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/core/allocation/canteen/service/impl/AllocAreaServiceImpl.java b/bonus-modules/bonus-smart-canteen/src/main/java/com/bonus/core/allocation/canteen/service/impl/AllocAreaServiceImpl.java index b145039d..7967d544 100644 --- a/bonus-modules/bonus-smart-canteen/src/main/java/com/bonus/core/allocation/canteen/service/impl/AllocAreaServiceImpl.java +++ b/bonus-modules/bonus-smart-canteen/src/main/java/com/bonus/core/allocation/canteen/service/impl/AllocAreaServiceImpl.java @@ -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 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 9565ee82..2b063216 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 - - - - - - - - - - - - - - - - - - - - - - - + +