提交 bd0d3eef 编写于 作者: zhouweidong's avatar zhouweidong

解决oracle下update历史已删除资源过长问题

上级 531d3f22
package cn.ibizlab.core.extensions.service;
import cn.ibizlab.core.uaa.domain.SysApp;
import cn.ibizlab.core.uaa.domain.SysPSSystem;
import cn.ibizlab.core.uaa.domain.SysPermission;
import cn.ibizlab.core.uaa.extensions.domain.PermissionType;
import cn.ibizlab.core.uaa.service.ISysPermissionService;
import cn.ibizlab.core.uaa.service.impl.SysPSSystemServiceImpl;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import lombok.extern.slf4j.Slf4j;
import cn.ibizlab.core.uaa.domain.SysPSSystem;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Lazy;
import org.springframework.context.annotation.Primary;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.context.annotation.Primary;
import org.springframework.util.StringUtils;
import java.util.*;
......@@ -142,9 +142,13 @@ public class SysPSSystemExService extends SysPSSystemServiceImpl {
//移除无效资源
if(delPermission.size()>0)
sysPermissionService.removeBatch(delPermission.keySet());
//查询以往删除过的资源
String delIds = getDelPermissionIds(list,system.getPssystemid());
//将当前系统本次资源enable设为1以避免enable=0时,导致saveOrUpdate无法检测到主键存在,最终插入数据导致主键重复
if(newIds.size()>0)
sysPermissionService.execute(String.format("update ibzpermission set enable = 1 where sys_permissionid in (%s)",getIds(newIds)),null);
if(newIds.size()>0 && !StringUtils.isEmpty(delIds))
sysPermissionService.execute(String.format("update ibzpermission set enable = 1 where sys_permissionid in (%s)",delIds),null);
//存储或更新资源saveOrUpdate
if(list.size()>0)
sysPermissionService.saveBatch(list);
......@@ -157,6 +161,31 @@ public class SysPSSystemExService extends SysPSSystemServiceImpl {
return "'" + String.join("','", strIdArr) + "'";
}
/**
* 查询以往删除过的数据
* @param list
* @return
*/
private String getDelPermissionIds(Set<SysPermission> list , String systemId) {
String strDelIds = null;
Map<String, Integer> delPermission = new HashMap<>();
Map param =new HashMap();
param.put("systemid",systemId);
sysPermissionService.select("select sys_permissionid from ibzpermission t where pssystemid = #{et.systemid} and t.enable = 0 ", param).forEach(sysPermission -> delPermission.put(sysPermission.getString("sys_permissionid"), 1));
if (delPermission.size() == 0)
return strDelIds;
Set<String> delIds = new HashSet<>();
for (SysPermission permission : list) {
if (!StringUtils.isEmpty(permission.getPermissionid())) {
if (delPermission.containsKey(permission.getPermissionid())) {
delIds.add(permission.getPermissionid());
}
}
}
if (delIds.size() > 0) {
strDelIds = getIds(delIds);
}
return strDelIds;
}
}
Markdown 格式
0% or
您添加了 0 到此讨论。请谨慎行事。
先完成此消息的编辑!
想要评论请 注册