forked from Gitlink/microservices
Merge pull request '创建专区时使用内置超管用户来创建,防止创建者未拥有特色专区组织下创建项目的权限' (#557) from otto/ruoyi-gitlink:master into master
This commit is contained in:
commit
cde3a44adc
|
|
@ -1,11 +1,5 @@
|
|||
package com.ruoyi.common.redis.service;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.data.redis.core.BoundSetOperations;
|
||||
import org.springframework.data.redis.core.HashOperations;
|
||||
|
|
@ -13,6 +7,9 @@ import org.springframework.data.redis.core.RedisTemplate;
|
|||
import org.springframework.data.redis.core.ValueOperations;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
/**
|
||||
* spring redis 工具类
|
||||
*
|
||||
|
|
@ -265,4 +262,38 @@ public class RedisService
|
|||
{
|
||||
return redisTemplate.keys(pattern);
|
||||
}
|
||||
|
||||
/**
|
||||
* 列表新增值
|
||||
*
|
||||
* @param key 列表键
|
||||
* @param value 列表值
|
||||
* @return 列表长度
|
||||
*/
|
||||
public Long leftPush(final String key, final String value) {
|
||||
return redisTemplate.opsForList().leftPush(key, value);
|
||||
}
|
||||
|
||||
/**
|
||||
* 列表弹出值
|
||||
*
|
||||
* @param key 列表键
|
||||
* @param timeout 超时时间
|
||||
* @param unit 时间单位
|
||||
* @return 对象
|
||||
*/
|
||||
public Object rightPop(final String key, final long timeout, final TimeUnit unit) {
|
||||
return redisTemplate.opsForList().rightPop(key, timeout, unit);
|
||||
}
|
||||
|
||||
/**
|
||||
* 列表中根据索引查找值
|
||||
*
|
||||
* @param key 列表键
|
||||
* @param index 索引值
|
||||
* @return 对象
|
||||
*/
|
||||
public Object listIndexOf(final String key, final long index) {
|
||||
return redisTemplate.opsForList().index(key, index);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -22,8 +22,7 @@ public class SysUserServiceImpl implements ISysUserService {
|
|||
|
||||
@Override
|
||||
public SysUser selectUserByUserName(String username) {
|
||||
SysUser sysUser = FeignUtils.getReturnData(remoteUserService.getSysUserByUserName(username, SecurityConstants.INNER));
|
||||
return sysUser;
|
||||
return FeignUtils.getReturnData(remoteUserService.getSysUserByUserName(username, SecurityConstants.INNER));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
|||
|
|
@ -41,7 +41,6 @@ import org.slf4j.LoggerFactory;
|
|||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.context.annotation.Lazy;
|
||||
import org.springframework.data.redis.core.RedisTemplate;
|
||||
import org.springframework.scheduling.annotation.Async;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.util.DigestUtils;
|
||||
|
|
@ -70,8 +69,6 @@ public class CmsAsyncServiceImpl implements ICmsAsyncService {
|
|||
private ICmsProjectService cmsProjectService;
|
||||
@Autowired
|
||||
private CmsDocMapper cmsDocMapper;
|
||||
@Autowired
|
||||
public RedisTemplate redisTemplate;
|
||||
@Value("${cms.summaryMaxLength}")
|
||||
private int summaryMaxLength;
|
||||
@Value("${http.gatewayUrl}")
|
||||
|
|
@ -179,8 +176,7 @@ public class CmsAsyncServiceImpl implements ICmsAsyncService {
|
|||
//获取数据库中栏目名称列表
|
||||
List<String> databaseDirNameList = cmsDirList.stream().map(CmsDoc::getName).collect(Collectors.toList());
|
||||
//获取数据库中多的栏目名称列表
|
||||
List<String> deleteDirNameList = new ArrayList<>();
|
||||
deleteDirNameList.addAll(databaseDirNameList);
|
||||
List<String> deleteDirNameList = new ArrayList<>(databaseDirNameList);
|
||||
deleteDirNameList.removeAll(gitLinkDirNameList);
|
||||
for (String deleteDirName : deleteDirNameList) {
|
||||
CmsDoc cmsDir = cmsDocMapper.selectCmsDocDirByNameAndDeptId(deleteDirName, cmsProject.getDeptId());
|
||||
|
|
@ -197,8 +193,7 @@ public class CmsAsyncServiceImpl implements ICmsAsyncService {
|
|||
cmsDocMapper.deleteCmsDocById(cmsDir.getId());
|
||||
}
|
||||
}
|
||||
List<String> addDirNameList = new ArrayList<>();
|
||||
addDirNameList.addAll(gitLinkDirNameList);
|
||||
List<String> addDirNameList = new ArrayList<>(gitLinkDirNameList);
|
||||
addDirNameList.removeAll(databaseDirNameList);
|
||||
//获取GitLink中多的文件夹名称列表
|
||||
for (String addDirName : addDirNameList) {
|
||||
|
|
@ -255,7 +250,7 @@ public class CmsAsyncServiceImpl implements ICmsAsyncService {
|
|||
}
|
||||
}catch (Exception e){
|
||||
logger.error("[{}]同步新增文章发生异常:{}"
|
||||
, e.getMessage());
|
||||
, cmsProject.getName(), e.getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -277,10 +272,10 @@ public class CmsAsyncServiceImpl implements ICmsAsyncService {
|
|||
}
|
||||
} catch (Exception e) {
|
||||
logger.error("[{}]同步删除文章发生异常:{}"
|
||||
, e.getMessage());
|
||||
, cmsProject.getName(), e.getMessage());
|
||||
}
|
||||
}
|
||||
if (removedList.size() > 0) {
|
||||
if (!removedList.isEmpty()) {
|
||||
SyncDatabaseAndGitLinkDir(cmsProject);
|
||||
}
|
||||
}
|
||||
|
|
@ -302,7 +297,7 @@ public class CmsAsyncServiceImpl implements ICmsAsyncService {
|
|||
}
|
||||
} catch (Exception e) {
|
||||
logger.error("[{}]同步修改文章发生异常:{}"
|
||||
, e.getMessage());
|
||||
, cmsProject.getName(), e.getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -364,13 +359,11 @@ public class CmsAsyncServiceImpl implements ICmsAsyncService {
|
|||
//获取数据库所有文件的filePath
|
||||
List<String> databaseFilePathList = cmsDocList.stream().map(CmsDoc::getFilePath).collect(Collectors.toList());
|
||||
//获取需要新增的文章
|
||||
List<String> addDocFilePathList = new ArrayList<>();
|
||||
addDocFilePathList.addAll(gitlinkFilePathList);
|
||||
List<String> addDocFilePathList = new ArrayList<>(gitlinkFilePathList);
|
||||
addDocFilePathList.removeAll(databaseFilePathList);
|
||||
syncDocAddedData(cmsProject, addDocFilePathList);
|
||||
//获取需要删除的文章
|
||||
List<String> removeDocFilePathList = new ArrayList<>();
|
||||
removeDocFilePathList.addAll(databaseFilePathList);
|
||||
List<String> removeDocFilePathList = new ArrayList<>(databaseFilePathList);
|
||||
removeDocFilePathList.removeAll(gitlinkFilePathList);
|
||||
syncDocRemovedData(cmsProject, removeDocFilePathList);
|
||||
//更新所有文章信息
|
||||
|
|
@ -391,19 +384,19 @@ public class CmsAsyncServiceImpl implements ICmsAsyncService {
|
|||
String cmsSyncDeptIdKey=CacheConstants.CMS_SYNC_DEPT_ID_KEY+deptId;
|
||||
//为当前同步操作生成UUID,若拿到的UUID为自身,则执行本次同步动作
|
||||
String UUID= IdUtils.fastSimpleUUID();
|
||||
redisTemplate.opsForList().leftPush(cmsSyncDeptIdKey,UUID);
|
||||
redisService.leftPush(cmsSyncDeptIdKey, UUID);
|
||||
//设置缓存过期时间,防止异常情况导致同步无法继续执行
|
||||
redisTemplate.expire(cmsSyncDeptIdKey,3600,TimeUnit.SECONDS);
|
||||
String currentUUID= String.valueOf(redisTemplate.opsForList().index(cmsSyncDeptIdKey,-1));
|
||||
redisService.expire(cmsSyncDeptIdKey, 3600, TimeUnit.SECONDS);
|
||||
String currentUUID = String.valueOf(redisService.listIndexOf(cmsSyncDeptIdKey, -1));
|
||||
//设置最大循环阈值,防止意外情况导致死循环(7200次,约1小时左右)
|
||||
int threshold=7200;
|
||||
while (!UUID.equals(currentUUID)&&threshold!=0){
|
||||
try {
|
||||
Thread.sleep(1000);
|
||||
} catch (InterruptedException e) {
|
||||
logger.error("同步文章时Sleep失败:"+e.getMessage());
|
||||
logger.error("同步文章时Sleep失败:{}", e.getMessage());
|
||||
}
|
||||
currentUUID= String.valueOf(redisTemplate.opsForList().index(cmsSyncDeptIdKey,-1));
|
||||
currentUUID = String.valueOf(redisService.listIndexOf(cmsSyncDeptIdKey, -1));
|
||||
threshold--;
|
||||
}
|
||||
|
||||
|
|
@ -440,10 +433,10 @@ public class CmsAsyncServiceImpl implements ICmsAsyncService {
|
|||
}
|
||||
}
|
||||
}catch (Exception e) {
|
||||
logger.error("同步文章时发送异常:" + e.getMessage());
|
||||
logger.error("同步文章时发送异常:{}", e.getMessage());
|
||||
}finally {
|
||||
//本次同步执行完成后,再弹出该UUID
|
||||
redisTemplate.opsForList().rightPop(cmsSyncDeptIdKey,500, TimeUnit.MICROSECONDS);
|
||||
redisService.rightPop(cmsSyncDeptIdKey, 500, TimeUnit.MICROSECONDS);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -525,7 +518,8 @@ public class CmsAsyncServiceImpl implements ICmsAsyncService {
|
|||
try {
|
||||
gitLinkRequestHelper.doPatch(CmsGitLinkRequestUrl.UPDATE_PROTECTED_BRANCHES(userName, identifier, params, pushWhitelistUsernames), null);
|
||||
} catch (URISyntaxException e) {
|
||||
e.printStackTrace();
|
||||
logger.error("同步更新保护分支设置失败:{}", e.getMessage());
|
||||
;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -538,7 +532,8 @@ public class CmsAsyncServiceImpl implements ICmsAsyncService {
|
|||
try {
|
||||
gitLinkRequestHelper.doDelete(CmsGitLinkRequestUrl.DELETE_PROTECTED_BRANCHES(userName, identifier, params, pushWhitelistUsernames), null);
|
||||
} catch (URISyntaxException e) {
|
||||
e.printStackTrace();
|
||||
logger.error("同步删除保护分支设置失败:{}", e.getMessage());
|
||||
;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -555,7 +550,8 @@ public class CmsAsyncServiceImpl implements ICmsAsyncService {
|
|||
try {
|
||||
gitLinkRequestHelper.doPost(CmsGitLinkRequestUrl.CREATE_PROTECTED_BRANCHES(userName, identifier, params, pushWhitelistUsernames), null);
|
||||
} catch (URISyntaxException e) {
|
||||
e.printStackTrace();
|
||||
logger.error("同步创建保护分支设置失败:{}", e.getMessage());
|
||||
;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -724,7 +720,7 @@ public class CmsAsyncServiceImpl implements ICmsAsyncService {
|
|||
//updateCmsCommonDatabase(oldCmsDoc);
|
||||
}
|
||||
|
||||
Boolean isChangeContent = false;
|
||||
boolean isChangeContent = false;
|
||||
if (content != null) {
|
||||
String newMd5 = DigestUtils.md5DigestAsHex(content.getBytes());
|
||||
String oldMd5 = null;
|
||||
|
|
@ -887,7 +883,7 @@ public class CmsAsyncServiceImpl implements ICmsAsyncService {
|
|||
//删除旧栏目
|
||||
deleteCmsDocByGitLink(cmsProject, oldCmsDir);
|
||||
} catch (Exception e) {
|
||||
logger.error("重命名栏目失败(原栏目名称[" + oldCmsDir.getName() + "],新栏目名称[" + newCmsDir.getName() + "]):{}", e.getMessage());
|
||||
logger.error("重命名栏目失败(原栏目名称[{}],新栏目名称[{}]):{}", oldCmsDir.getName(), newCmsDir.getName(), e.getMessage());
|
||||
throw new ServiceException("重命名栏目失败(原栏目名称[" + oldCmsDir.getName() + "],新栏目名称[" + newCmsDir.getName() + "])");
|
||||
} finally {
|
||||
remoteZoneService.lockCmsByDeptId(cmsProject.getDeptId(), 0, SecurityConstants.INNER);
|
||||
|
|
|
|||
|
|
@ -18,7 +18,7 @@ public class CmsGitLinkRequestUrl extends GitLinkRequestUrl {
|
|||
* 创建项目
|
||||
*/
|
||||
public static GitLinkRequestUrl CREATE_PROJECT() {
|
||||
return getGitLinkRequestUrl("/api/projects.json");
|
||||
return getAdminGitLinkRequestUrl("/api/projects.json");
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
Loading…
Reference in New Issue