| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225 |
- package com.persagy.person.controller;
- import java.util.List;
- import java.util.Map;
- import org.springframework.beans.BeanUtils;
- import org.springframework.beans.factory.annotation.Autowired;
- import org.springframework.validation.annotation.Validated;
- import org.springframework.web.bind.annotation.RequestBody;
- import org.springframework.web.bind.annotation.RequestMapping;
- import org.springframework.web.bind.annotation.RequestMethod;
- import org.springframework.web.bind.annotation.RestController;
- import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
- import com.google.common.collect.Lists;
- import com.persagy.common.constant.SaasCommonConstant;
- import com.persagy.common.enums.ResponseCode;
- import com.persagy.common.utils.ResponseResult;
- import com.persagy.common.utils.ResponseResultUtil;
- import com.persagy.common.utils.StringUtil;
- import com.persagy.person.manage.SaasAreaProjectHandler;
- import com.persagy.person.manage.SaasAuthHandler;
- import com.persagy.person.pojo.dto.SaasAccount;
- import com.persagy.person.pojo.dto.SaasArea;
- import com.persagy.person.pojo.dto.SaasProject;
- import com.persagy.person.pojo.vo.BaseGroupVO;
- import com.persagy.person.pojo.vo.area.SaasAreaCreateVO;
- import com.persagy.person.pojo.vo.area.SaasAreaDeleteVO;
- import com.persagy.person.pojo.vo.area.SaasAreaQueryVO;
- import com.persagy.person.service.ISaasAccountService;
- import com.persagy.person.service.ISaasAreaService;
- import com.persagy.person.service.ISaasProjectService;
- import cn.hutool.core.collection.CollectionUtil;
- import io.swagger.annotations.Api;
- import io.swagger.annotations.ApiOperation;
- /**
- * 区域信息
- *
- * @version 1.0.0
- * @company persagy
- * @author zhangqiankun
- * @date 2021-03-13 15:29:50
- */
- @Api(tags = "区域信息")
- @RestController
- @RequestMapping(value = "/area", method = RequestMethod.POST)
- public class SaasAreaController {
-
- @Autowired
- private SaasAuthHandler saasAuthHandler;
-
- @Autowired
- private ISaasAreaService saasAreaService;
-
- @Autowired
- private ISaasProjectService saasProjectService;
-
- @Autowired
- private ISaasAccountService saasAccountService;
-
- @Autowired
- private SaasAreaProjectHandler saasAreaProjectHandler;
-
- /**
- * 查询区域树
- */
- @ApiOperation(value = "查询区域树")
- @RequestMapping(value = "querySaasAreaTree")
- public ResponseResult querySaasAreaTree(@RequestBody @Validated BaseGroupVO model) {
- List<SaasArea> topList = this.saasAreaProjectHandler.getTopAreaList(model.getGroupCode());
- this.saasAreaProjectHandler.querySaasAreaTree(topList, false);
- return ResponseResultUtil.successResult(topList);
- }
-
- /**
- * 查询区域权限树,做权限判断
- */
- @ApiOperation(value = "查询区域权限树")
- @RequestMapping(value = "queryAllowAreaTree")
- public ResponseResult queryAllowAreaTree(@RequestBody @Validated BaseGroupVO groupVO) {
- List<SaasArea> areaList = this.saasAuthHandler.getAllowAreaList(groupVO.getAccountId(), groupVO.getGroupCode());
- return ResponseResultUtil.successResult(areaList);
- }
-
- /**
- * 区域平铺列表查询
- */
- @ApiOperation(value = "区域平铺列表查询")
- @RequestMapping(value = "querySaasAreaList")
- public ResponseResult querySaasAreaList(@RequestBody @Validated SaasAreaQueryVO queryVO) {
- boolean isAllProjects = true;
- // 如果需要统计项目
- if (queryVO.isTotal()) {
- // 账号数据可见性的权限鉴定
- Map<String, String> authMap = this.saasAuthHandler.validGroupProjectAuth(queryVO.getAccountId(), queryVO.getGroupCode());
- if (StringUtil.isNotBlank(authMap.get(SaasCommonConstant.GROUP_CODE))) {
- queryVO.setGroupCode(authMap.get(SaasCommonConstant.GROUP_CODE));
- }
- // 添加数据访问控制,账号可见域,0-所有集团项目,1-单集团所有项目(此时,集团编码需存在),2-其他
- String accountType = authMap.get(SaasCommonConstant.ACCOUNT_TYPE);
- if (SaasCommonConstant.STR_STATUS_2.equals(accountType)) {
- isAllProjects = false;
- }
- }
- // 区域树查询
- List<SaasArea> list = this.saasAreaProjectHandler.querySaasAreaList(queryVO, isAllProjects);
- return ResponseResultUtil.successResult(list, (long)list.size());
- }
- /**
- * 底层区域平铺列表查询(权限过滤)
- */
- @ApiOperation(value = "底层区域平铺列表查询(权限过滤)")
- @RequestMapping(value = "queryAllowSaasAreaList")
- public ResponseResult queryAllowSaasAreaList(@RequestBody @Validated SaasAreaQueryVO queryVO) {
- boolean isAdmin = false;
- // 账号数据可见性的权限鉴定
- Map<String, String> authMap = this.saasAuthHandler.validGroupProjectAuth(queryVO.getAccountId(), queryVO.getGroupCode());
- if (StringUtil.isNotBlank(authMap.get(SaasCommonConstant.GROUP_CODE))) {
- queryVO.setGroupCode(authMap.get(SaasCommonConstant.GROUP_CODE));
- }
- // 添加数据访问控制,账号可见域,0-所有集团项目,1-单集团所有项目(此时,集团编码需存在),2-其他
- String accountType = authMap.get(SaasCommonConstant.ACCOUNT_TYPE);
- List<SaasArea> areas = null;
- if (SaasCommonConstant.STR_STATUS_2.equals(accountType)) {
- // 其他类型时,需要根据权限表数据,去匹配区域树
- SaasArea saasArea = new SaasArea();
- BeanUtils.copyProperties(queryVO, saasArea);
- areas = this.saasAreaService.queryAllowSaasAreaList(queryVO.getAccountId(), saasArea);
- } else {
- LambdaQueryWrapper<SaasArea> queryWrapper = new SaasArea.Builder().createQueryWrapper().idEq(queryVO.getId())
- .groupCodeEq(queryVO.getGroupCode()).areaCodeEq(queryVO.getAreaCode()).areaNameLike(queryVO.getAreaName())
- .areaTypeEq(queryVO.getAreaType()).updateUserEq(queryVO.getUpdateUser())
- .parentIdEq(queryVO.getParentId()).builderQueryWrapper();
- areas = this.saasAreaService.list(queryWrapper);
- isAdmin = true;
- }
- if (CollectionUtil.isEmpty(areas)) {
- return ResponseResultUtil.successResult(Lists.newArrayList(), 0L);
- }
- if (queryVO.isTotal()) {
- this.saasAreaProjectHandler.totalAreaProjectNum(areas, queryVO.getAccountId(), isAdmin);
- }
- return ResponseResultUtil.successResult(areas, (long)areas.size());
- }
-
- /**
- * 新增,区域编码与区域名称集团下唯一
- */
- @ApiOperation(value = "保存")
- @RequestMapping(value = "createSaasArea")
- public ResponseResult createSaasArea(@RequestBody @Validated SaasAreaCreateVO createVO) {
- // 验证账号信息是否存在
- SaasAccount saasAccount = this.saasAccountService.getOne(createVO.getAccountId(), null, null);
- if (saasAccount == null) {
- return ResponseResultUtil.errorResult(ResponseCode.A0400.getCode(), "账号信息,不存在");
- }
- // 验证区域编码与区域名称的唯一性
- boolean exist = this.saasAreaService.validAreaCodeAndName(createVO.getGroupCode(), createVO.getAreaCode(), createVO.getAreaName(), null);
- if (!exist) {
- return ResponseResultUtil.errorResult(ResponseCode.A0402.getCode(), "区域名称已存在,请检查");
- }
- SaasArea saasArea = new SaasArea();
- BeanUtils.copyProperties(createVO, saasArea);
- saasArea.setId(null);
- saasArea.setUpdateUser(createVO.getAccountId());
- exist = this.saasAreaProjectHandler.createSaasArea(saasArea, saasAccount.getId(), saasAccount.getAccountType());
- return exist ? ResponseResultUtil.successResult("保存成功", saasArea.getId()) : ResponseResultUtil.errorResult("保存失败");
- }
-
- /**
- * 更新,区域编码与区域名称集团下唯一
- */
- @ApiOperation(value = "更新")
- @RequestMapping(value = "updateSaasArea")
- public ResponseResult updateSaasArea(@RequestBody @Validated SaasAreaCreateVO createVO) {
- if (StringUtil.isBlank(createVO.getId())) {
- return ResponseResultUtil.errorResult(ResponseCode.A0400.getCode(), "区域ID不可为空");
- }
- //验证区域编码与区域名称的唯一性
- boolean exist = this.saasAreaService.validAreaCodeAndName(createVO.getGroupCode(), createVO.getAreaCode(), createVO.getAreaName(), createVO.getId());
- if (!exist) {
- return ResponseResultUtil.errorResult(ResponseCode.A0402.getCode(), "区域名称已存在,请检查");
- }
- SaasArea saasArea = new SaasArea();
- BeanUtils.copyProperties(createVO, saasArea);
- saasArea.setUpdateUser(createVO.getAccountId());
- boolean result = this.saasAreaService.updateById(saasArea);
- return result ? ResponseResultUtil.successResult("更新成功") : ResponseResultUtil.errorResult("更新失败");
- }
- /**
- * 物理删除
- */
- @ApiOperation(value = "删除")
- @RequestMapping(value = "deleteSaasArea")
- public ResponseResult deleteSaasArea(@RequestBody @Validated SaasAreaDeleteVO deleteVO) {
- // 验证账号信息是否存在
- SaasAccount saasAccount = this.saasAccountService.getOne(deleteVO.getAccountId(), null, null);
- if (saasAccount == null) {
- return ResponseResultUtil.errorResult(ResponseCode.A0400.getCode(), "账号信息,不存在");
- }
- // 验证区域是否存在
- SaasArea saasArea = this.saasAreaService.getById(deleteVO.getId());
- if (saasArea == null) {
- return ResponseResultUtil.errorResult(ResponseCode.C0320.getCode(), "区域信息不存在");
- }
- // 如果是底层区域,判断,旗下是否存在项目信息,存在不允许删除
- if (SaasCommonConstant.STR_STATUS_1.equals(saasArea.getAreaType())) {
- LambdaQueryWrapper<SaasProject> queryWrapper = new SaasProject.Builder().createQueryWrapper()
- .groupCodeEq(deleteVO.getGroupCode()).areaIdEq(deleteVO.getId())
- .last("limit 0, 1").builderQueryWrapper();
- SaasProject project = this.saasProjectService.getOne(queryWrapper);
- if (project != null) {
- return ResponseResultUtil.errorResult(ResponseCode.A0402.getCode(), "此区域下存在项目ID,不允许删除");
- }
- }
- boolean result = this.saasAreaProjectHandler.deleteSaasArea(deleteVO.getGroupCode(), saasArea.getId(), saasAccount.getAccountType());
- return result ? ResponseResultUtil.successResult("删除成功") : ResponseResultUtil.errorResult("删除失败");
- }
-
- }
|