| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135 |
- package com.persagy.person.controller;
- import java.util.ArrayList;
- import java.util.List;
- import org.springframework.beans.factory.annotation.Autowired;
- import org.springframework.data.redis.core.RedisTemplate;
- 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.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
- import com.esotericsoftware.minlog.Log;
- import com.persagy.common.constant.SaasCommonConstant;
- import com.persagy.common.utils.ResponseResult;
- import com.persagy.common.utils.ResponseResultUtil;
- import com.persagy.common.utils.StringUtil;
- import com.persagy.person.pojo.dto.SaasAccount;
- import com.persagy.person.pojo.dto.SaasAccountProject;
- import com.persagy.person.pojo.dto.SaasArea;
- import com.persagy.person.pojo.dto.SaasProject;
- import com.persagy.person.pojo.vo.BaseUserVO;
- import com.persagy.person.service.ISaasAccountProjectService;
- 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;
- /**
- * 此类,用做每次迭代升级时,无法通过sql兼容老数据,所需定义的接口信息
- * @version
- * @description
- * @company persagy
- * @author zhangqiankun
- * @since 2021年4月13日: 下午5:46:44
- */
- @Api(tags = "迭代-升级接口管理")
- @RestController
- @RequestMapping(value = "/upgrade", method = RequestMethod.POST)
- public class UpgradeController {
-
- @Autowired
- private ISaasAreaService saasAreaService;
-
- @Autowired
- private ISaasAccountService saasAccountService;
-
- @Autowired
- private ISaasProjectService saasProjectService;
-
- @Autowired
- private RedisTemplate<String, Object> redisTemplate;
-
- @Autowired
- private ISaasAccountProjectService saasAccountProjectService;
-
- /**
- * 20210413号迭代升级,新增区域权限表,兼容老数据接口,本接口需在部署的时候,手动调用一次,必须返回成功,才算完成
- * 为防止多次调用,这里采用 REPLACE INTO
- */
- @ApiOperation(value = "新增区域权限,兼容老数据接口")
- @RequestMapping(value = "updateAccountAreaAuth")
- public ResponseResult updateAccountAreaAuth(@RequestBody @Validated BaseUserVO userVO) {
- List<SaasAccountProject> data = new ArrayList<SaasAccountProject>();
- // 查询出所有的账号信息,包含停用的
- List<SaasAccount> accounts = this.saasAccountService.list();
- // 查询出以被分配的项目权限信息
- List<SaasAccountProject> accountProject = this.saasAccountProjectService.list();
- if (CollectionUtil.isEmpty(accountProject)) {
- // 获取所有区域信息
- List<SaasArea> areas = this.saasAreaService.list();
- // 形成,账号、集团、区域关联关系
- for (SaasAccount account : accounts) {
- for (SaasArea area : areas) {
- SaasAccountProject saasAccountArea = new SaasAccountProject();
- saasAccountArea.setAccountId(account.getId());
- saasAccountArea.setGroupCode(account.getGroupCode());
- saasAccountArea.setAreaId(area.getId());
- data.add(saasAccountArea);
- }
- }
- this.saasAccountProjectService.replaceAccountProject(data);
- return ResponseResultUtil.successResult();
- }
- // 获取不存在项目的,空集合
-
- // accountProject 不为空,更新对应记录的areaId
- for (SaasAccountProject project : accountProject) {
- String areaId = null;
- // 更新数据
- LambdaUpdateWrapper<SaasAccountProject> wrapper = new SaasAccountProject.Builder().createUpdateWrapper().accountIdEq(project.getAccountId())
- .groupCodeEq(project.getGroupCode()).projectIdEq(project.getProjectId()).builderUpdateWrapper();
- if (StringUtil.isBlank(project.getProjectId())) {
- LambdaQueryWrapper<SaasArea> queryWrapper = new SaasArea.Builder().createQueryWrapper().groupCodeEq(project.getGroupCode()).areaCodeEq(SaasCommonConstant.STR_STATUS_MINUS_1).builderQueryWrapper();
- SaasArea saasArea = this.saasAreaService.getOne(queryWrapper);
- areaId = saasArea.getId();
- wrapper.apply("(PROJECT_ID IS NULL OR TRIM(PROJECT_ID) = '')");
- } else {
- LambdaQueryWrapper<SaasProject> queryWrapper = new SaasProject.Builder().createQueryWrapper().groupCodeEq(project.getGroupCode()).projectIdEq(project.getProjectId()).builderQueryWrapper();
- SaasProject saasProject = this.saasProjectService.getOne(queryWrapper);
- if (saasProject == null) {
- Log.error("项目信息不存在" + project.getProjectId());
- continue;
- }
- areaId = saasProject.getAreaId();
- wrapper.apply("PROJECT_ID IS NOT NULL AND TRIM(PROJECT_ID) != ''");
- }
- wrapper.set(SaasAccountProject::getAreaId, areaId);
- this.saasAccountProjectService.update(wrapper);
- }
- return ResponseResultUtil.successResult();
- }
-
- /**
- * 20210413号迭代升级,清空redis缓存
- * 为防止多次调用,这里采用 REPLACE INTO
- */
- @ApiOperation(value = "新增区域权限表,兼容老数据接口")
- @RequestMapping(value = "clearRedisCache")
- public ResponseResult clearRedisCache(@RequestBody @Validated BaseUserVO userVO) {
- // 查询出所有的账号信息,包含停用的
- List<SaasAccount> accounts = this.saasAccountService.list();
- for (SaasAccount saasAccount : accounts) {
- this.redisTemplate.delete(saasAccount.getId());
- }
- return ResponseResultUtil.successResult();
- }
-
- }
|