验证角色数据清洗
This commit is contained in:
parent
3766422f3b
commit
25b309a1a6
@ -1,11 +1,12 @@
|
||||
package cn.axzo.tyr.server;
|
||||
|
||||
import cn.hutool.extra.spring.SpringUtil;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.mybatis.spring.annotation.MapperScan;
|
||||
import cn.axzo.tyr.server.job.OMSRoleJobHandler;
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
|
||||
import org.springframework.cloud.openfeign.EnableFeignClients;
|
||||
import org.springframework.context.ConfigurableApplicationContext;
|
||||
import org.springframework.core.env.Environment;
|
||||
import org.springframework.scheduling.annotation.EnableAsync;
|
||||
@ -21,22 +22,33 @@ public class TyrApplication {
|
||||
ConfigurableApplicationContext run = SpringApplication.run(TyrApplication.class, args);
|
||||
Environment env = run.getEnvironment();
|
||||
log.info(
|
||||
"--------------------------------------------------------------------------------------------------------------------\n" +
|
||||
"Application 【{}】 is running on 【{}】 environment!\n" +
|
||||
"Api Local: \thttp://127.0.0.1:{}\n" +
|
||||
"Mysql: \t{}\t username:{}\n" +
|
||||
"Redis: \t{}:{}\t database:{}\n" +
|
||||
"RabbitMQ: \t{}\t username:{}",
|
||||
env.getProperty("spring.application.name"),
|
||||
env.getProperty("spring.profiles.active"),
|
||||
env.getProperty("server.port"),
|
||||
env.getProperty("spring.datasource.url"),
|
||||
env.getProperty("spring.datasource.username"),
|
||||
env.getProperty("spring.redis.host"),
|
||||
env.getProperty("spring.redis.port"),
|
||||
env.getProperty("spring.redis.database"),
|
||||
env.getProperty("spring.rabbitmq.addresses"),
|
||||
env.getProperty("spring.rabbitmq.username") +
|
||||
"\n----------------------------------------------------------");
|
||||
"--------------------------------------------------------------------------------------------------------------------\n" +
|
||||
"Application 【{}】 is running on 【{}】 environment!\n" +
|
||||
"Api Local: \thttp://127.0.0.1:{}\n" +
|
||||
"Mysql: \t{}\t username:{}\n" +
|
||||
"Redis: \t{}:{}\t database:{}\n" +
|
||||
"RabbitMQ: \t{}\t username:{}",
|
||||
env.getProperty("spring.application.name"),
|
||||
env.getProperty("spring.profiles.active"),
|
||||
env.getProperty("server.port"),
|
||||
env.getProperty("spring.datasource.url"),
|
||||
env.getProperty("spring.datasource.username"),
|
||||
env.getProperty("spring.redis.host"),
|
||||
env.getProperty("spring.redis.port"),
|
||||
env.getProperty("spring.redis.database"),
|
||||
env.getProperty("spring.rabbitmq.addresses"),
|
||||
env.getProperty("spring.rabbitmq.username") +
|
||||
"\n----------------------------------------------------------");
|
||||
|
||||
// try {
|
||||
// test();
|
||||
// } catch (Exception e) {
|
||||
// e.printStackTrace();
|
||||
// }
|
||||
}
|
||||
|
||||
// public static void test() throws Exception {
|
||||
// OMSRoleJobHandler executor = SpringUtil.getBean(OMSRoleJobHandler.class);
|
||||
// executor.execute(null);
|
||||
// }
|
||||
}
|
||||
|
||||
@ -1,19 +1,16 @@
|
||||
package job;
|
||||
package cn.axzo.tyr.server.job;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
|
||||
import cn.axzo.pokonyan.config.mybatisplus.BaseEntity;
|
||||
import cn.axzo.tyr.client.model.DictTypeFiledEnum;
|
||||
import cn.axzo.tyr.server.repository.entity.*;
|
||||
import cn.axzo.tyr.server.repository.service.*;
|
||||
import cn.axzo.tyr.server.service.RoleService;
|
||||
import cn.axzo.tyr.server.service.SaasRoleGroupService;
|
||||
import com.xxl.job.core.biz.model.ReturnT;
|
||||
import com.xxl.job.core.handler.IJobHandler;
|
||||
import com.xxl.job.core.handler.annotation.XxlJob;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.commons.collections4.CollectionUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
@ -60,7 +57,7 @@ public class OMSRoleJobHandler extends IJobHandler {
|
||||
*/
|
||||
@Transactional // 在一个事务里面做,一起提交
|
||||
@Override
|
||||
@XxlJob("chengDuSubwayLogRetry")
|
||||
@XxlJob("OMSRoleJobHandler")
|
||||
public ReturnT<String> execute(String s) throws Exception {
|
||||
// 创建角色分组
|
||||
SaasRoleGroup roleGroup = new SaasRoleGroup();
|
||||
@ -68,7 +65,10 @@ public class OMSRoleJobHandler extends IJobHandler {
|
||||
roleGroup.setName("管理员");
|
||||
roleGroupDao.save(roleGroup);
|
||||
// 查询OMS的角色 workspaceType=6 OMS的角色
|
||||
List<SaasRole> oldRole = roleDao.lambdaQuery().eq(SaasRole::getWorkspaceType, 6).list();
|
||||
List<SaasRole> oldRole = roleDao.lambdaQuery()
|
||||
.eq(SaasRole::getWorkspaceType, 6)
|
||||
.notIn(SaasRole::getRoleType,"super_admin")
|
||||
.list();
|
||||
// 重置老角色多余的字段
|
||||
oldRole.forEach(e -> {
|
||||
e.setWorkspaceId(-1l);
|
||||
@ -90,14 +90,37 @@ public class OMSRoleJobHandler extends IJobHandler {
|
||||
return saasRoleGroupRelation;
|
||||
}).collect(Collectors.toList());
|
||||
roleGroupRelationDao.saveBatch(roleGroupRelation);
|
||||
|
||||
// 查询角色关联的角色,打包成新的权限集
|
||||
ArrayList<SaasPermissionGroup> deletePgroup = new ArrayList<>();
|
||||
oldRole.forEach(role -> {
|
||||
List<SaasPgroupRoleRelation> pgroupRoleRelation = pgroupRoleRelationDao.lambdaQuery().eq(SaasPgroupRoleRelation::getRoleId, role.getId()).list();
|
||||
if (CollectionUtils.isEmpty(pgroupRoleRelation)) {
|
||||
return;
|
||||
}
|
||||
List<SaasPermissionGroup> permissionGroup = saasPermissionGroupDao.lambdaQuery().in(BaseEntity::getId, pgroupRoleRelation.stream().map(SaasPgroupRoleRelation::getGroupId).collect(Collectors.toList())).list();
|
||||
if (CollectionUtils.isEmpty(permissionGroup)) {
|
||||
return;
|
||||
}
|
||||
List<SaasPgroupPermissionRelation> pgroupPermissionRelation = pgroupPermissionRelationDao.lambdaQuery().in(SaasPgroupPermissionRelation::getGroupId, permissionGroup.stream().map(BaseEntity::getId).collect(Collectors.toList())).list();
|
||||
if (CollectionUtils.isEmpty(pgroupPermissionRelation)) {
|
||||
// 如果没查到权限则表示当前权限集是无意义的,删掉
|
||||
permissionGroup.forEach(e -> e.setIsDelete(e.getId()));
|
||||
saasPermissionGroupDao.updateBatchById(permissionGroup);
|
||||
// 删除角色权限集关联关系
|
||||
pgroupRoleRelation.forEach(e -> e.setIsDelete(e.getId()));
|
||||
pgroupRoleRelationDao.updateBatchById(pgroupRoleRelation);
|
||||
return;
|
||||
}
|
||||
List<SaasFeature> feature = featureDao.lambdaQuery().in(BaseEntity::getId, pgroupPermissionRelation.stream().map(SaasPgroupPermissionRelation::getFeatureId).collect(Collectors.toList())).list();
|
||||
if (CollectionUtils.isEmpty(feature)) {
|
||||
// 如果没查到权限则表示当前权限集是无意义的,删掉
|
||||
permissionGroup.forEach(e -> e.setIsDelete(e.getId()));
|
||||
saasPermissionGroupDao.updateBatchById(permissionGroup);
|
||||
// 删除角色权限集关联关系
|
||||
pgroupRoleRelation.forEach(e -> e.setIsDelete(e.getId()));
|
||||
pgroupRoleRelationDao.updateBatchById(pgroupRoleRelation);
|
||||
return;
|
||||
}
|
||||
// 创建新的权限集
|
||||
SaasPermissionGroup saasPermissionGroup = new SaasPermissionGroup();
|
||||
saasPermissionGroup.setName("通用权限");
|
||||
Loading…
Reference in New Issue
Block a user