|
|
@@ -3,9 +3,14 @@ package cn.seecoder.fdroidrepository.Service.ServiceImpl;
|
|
|
import cn.seecoder.fdroidrepository.DataObject.ApplicationProperties;
|
|
|
import cn.seecoder.fdroidrepository.DataObject.Enum.BuildTaskStatusEnum;
|
|
|
import cn.seecoder.fdroidrepository.DataObject.Enum.BuildTypeEnum;
|
|
|
+import cn.seecoder.fdroidrepository.DataObject.Enum.ResultCode;
|
|
|
+import cn.seecoder.fdroidrepository.DataObject.PO.AppContributeRelationPO;
|
|
|
import cn.seecoder.fdroidrepository.DataObject.PO.AppInfoPO;
|
|
|
import cn.seecoder.fdroidrepository.DataObject.PO.BuildTaskPO;
|
|
|
import cn.seecoder.fdroidrepository.DataObject.VO.AppInfoVO;
|
|
|
+import cn.seecoder.fdroidrepository.DataObject.VO.BuildTaskCreateVO;
|
|
|
+import cn.seecoder.fdroidrepository.DataObject.VO.Response;
|
|
|
+import cn.seecoder.fdroidrepository.Mapper.AppContributeRelationMapper;
|
|
|
import cn.seecoder.fdroidrepository.Mapper.AppInfoMapper;
|
|
|
import cn.seecoder.fdroidrepository.Mapper.BuildTaskMapper;
|
|
|
import cn.seecoder.fdroidrepository.Pipeline.*;
|
|
|
@@ -21,31 +26,65 @@ import java.io.BufferedWriter;
|
|
|
import java.io.File;
|
|
|
import java.io.FileWriter;
|
|
|
import java.util.Date;
|
|
|
+import java.util.List;
|
|
|
import java.util.concurrent.*;
|
|
|
|
|
|
@Service
|
|
|
public class AppServiceImpl implements AppService {
|
|
|
private static final ThreadPoolExecutor THREAD_POOL_EXECUTOR = new ThreadPoolExecutor(4, 8, 1000, TimeUnit.SECONDS, new LinkedBlockingQueue<>(512), new ThreadPoolExecutor.DiscardPolicy());
|
|
|
private static final Logger logger = LoggerFactory.getLogger(AppServiceImpl.class);
|
|
|
+ private static final Integer SYSTEM_DEFAULT_ID = -1;
|
|
|
private final BuildTaskMapper buildTaskMapper;
|
|
|
private final AppInfoMapper appInfoMapper;
|
|
|
+ private final AppContributeRelationMapper relationMapper;
|
|
|
|
|
|
@Autowired
|
|
|
- public AppServiceImpl(BuildTaskMapper buildTaskMapper, AppInfoMapper appInfoMapper) {
|
|
|
+ public AppServiceImpl(BuildTaskMapper buildTaskMapper, AppInfoMapper appInfoMapper, AppContributeRelationMapper relationMapper) {
|
|
|
this.buildTaskMapper = buildTaskMapper;
|
|
|
this.appInfoMapper = appInfoMapper;
|
|
|
+ this.relationMapper = relationMapper;
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- public Integer createAppInfo(AppInfoVO appInfoVO) {
|
|
|
+ public Response createAppInfo(AppInfoVO appInfoVO) {
|
|
|
AppInfoPO appInfoPO = new AppInfoPO();
|
|
|
BeanUtils.copyProperties(appInfoVO, appInfoPO);
|
|
|
+ appInfoPO.setCreateTime(new Date(System.currentTimeMillis()));
|
|
|
Integer appId = appInfoMapper.insertAppInfo(appInfoPO);
|
|
|
- return appId;
|
|
|
+ // 创建 AppContributeRelation 并进行保存
|
|
|
+ for (Integer userId : appInfoVO.getContributorIds()) {
|
|
|
+ relationMapper.insert(appId, userId);
|
|
|
+ }
|
|
|
+ return Response.buildSuccess(appId);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public Response updateAppInfo(AppInfoVO appInfoVO) {
|
|
|
+ if (appInfoVO == null || appInfoVO.getId() == null) {
|
|
|
+ return Response.buildFailure(ResultCode.ILLEGAL_ARGUMENT.getCode(), ResultCode.ILLEGAL_ARGUMENT.getMessage());
|
|
|
+ }
|
|
|
+ appInfoVO.setCreateTime(null);
|
|
|
+ AppInfoPO appInfoPO = new AppInfoPO();
|
|
|
+ BeanUtils.copyProperties(appInfoVO, appInfoPO);
|
|
|
+ Integer result = appInfoMapper.updateAppInfo(appInfoPO);
|
|
|
+ // 更改AppContributeRelation
|
|
|
+ List<Integer> oldContributorIds = relationMapper.selectContributorIdsByAppId(appInfoVO.getId());
|
|
|
+ List<Integer> newContributorIds = appInfoVO.getContributorIds();
|
|
|
+ for (Integer userId : oldContributorIds) {
|
|
|
+ if (!newContributorIds.contains(userId)) {
|
|
|
+ relationMapper.deleteRelation(appInfoVO.getId(), userId);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ for (Integer userId : newContributorIds) {
|
|
|
+ if (!oldContributorIds.contains(userId)) {
|
|
|
+ relationMapper.insert(appInfoVO.getId(), userId);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return Response.buildSuccess();
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- public Boolean rewriteGradleFile(Integer taskId, String fileName, String content) {
|
|
|
+ public Response rewriteGradleFile(Integer taskId, String fileName, String content) {
|
|
|
try {
|
|
|
File file = new File(fileName);
|
|
|
if (!file.exists()) {
|
|
|
@@ -68,23 +107,24 @@ public class AppServiceImpl implements AppService {
|
|
|
WaitLock waitLock = new WaitLock();
|
|
|
CommonValueTable.LockTable.put(taskId, waitLock);
|
|
|
}
|
|
|
- return true;
|
|
|
+ return Response.buildSuccess(true);
|
|
|
} catch (Exception exception) {
|
|
|
logger.error("重写Gradle文件失败,错误信息: {}", exception.getMessage());
|
|
|
- return false;
|
|
|
+ return Response.buildFailure(ResultCode.GRADLE_REWRITE_FAIL.getCode(), ResultCode.GRADLE_REWRITE_FAIL.getMessage());
|
|
|
}
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- public BuildTaskPO checkTaskStatus(Integer taskId) {
|
|
|
+ public Response checkTaskStatus(Integer taskId) {
|
|
|
ExecuteResult result = CommonValueTable.ResultTable.get(taskId);
|
|
|
BuildTaskPO buildTaskPO = this.buildTaskMapper.selectById(taskId);
|
|
|
- if (result != null) {
|
|
|
+ if (result == null) {
|
|
|
+ return Response.buildFailure(ResultCode.BUILD_TASK_NON_EXIST.getCode(), ResultCode.BUILD_TASK_NON_EXIST.getMessage());
|
|
|
+ } else {
|
|
|
// 根据对应的执行结果内容进行更新
|
|
|
buildTaskPO.setStatus(result.getStatus());
|
|
|
buildTaskPO.setUpdateTime(result.getUpdateTime());
|
|
|
buildTaskPO.setMessage(result.getMessage());
|
|
|
- buildTaskPO.setResult(result.getResult());
|
|
|
buildTaskMapper.updateById(buildTaskPO);
|
|
|
|
|
|
// 流水线已经执行完成,删除其在Map中的内容,防止空间堆积
|
|
|
@@ -92,31 +132,26 @@ public class AppServiceImpl implements AppService {
|
|
|
CommonValueTable.ResultTable.remove(taskId);
|
|
|
}
|
|
|
}
|
|
|
- return buildTaskPO;
|
|
|
+ return Response.buildSuccess(buildTaskPO);
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- public Integer createBuildTask(Integer appId, Integer userId, String branch, BuildTypeEnum typeEnum) {
|
|
|
- AppInfoPO appInfoPO = appInfoMapper.selectById(appId);
|
|
|
+ public Response createBuildTask(BuildTaskCreateVO createVO) {
|
|
|
+ AppInfoPO appInfoPO = appInfoMapper.selectById(createVO.getAppId());
|
|
|
if (appInfoPO == null) {
|
|
|
- // AppInfo不存在
|
|
|
- logger.error("对应的AppInfo不存在");
|
|
|
- return -1;
|
|
|
+ return Response.buildFailure(ResultCode.APPINFO_NON_EXIST.getCode(), ResultCode.APPINFO_NON_EXIST.getMessage());
|
|
|
}
|
|
|
- BuildTaskPO buildTaskPO = BuildTaskPO.builder()
|
|
|
- .appId(appId)
|
|
|
- .createUserId(userId)
|
|
|
- .createTime(new Date(System.currentTimeMillis()))
|
|
|
- .buildType(typeEnum)
|
|
|
- .status(BuildTaskStatusEnum.NEW)
|
|
|
- .build();
|
|
|
+ BuildTaskPO buildTaskPO = new BuildTaskPO();
|
|
|
+ BeanUtils.copyProperties(createVO, buildTaskPO);
|
|
|
+ buildTaskPO.setCreateTime(new Date(System.currentTimeMillis()));
|
|
|
+ buildTaskPO.setStatus(BuildTaskStatusEnum.NEW);
|
|
|
Integer taskId = buildTaskMapper.insert(buildTaskPO);
|
|
|
buildTaskPO.setId(taskId);
|
|
|
ApplicationProperties app = ApplicationProperties.builder()
|
|
|
- .appId(appId)
|
|
|
+ .appId(createVO.getAppId())
|
|
|
.appName(appInfoPO.getAppName())
|
|
|
.repoUrl(appInfoPO.getRepoUrl())
|
|
|
- .branch(branch)
|
|
|
+ .branch(appInfoPO.getBuildBranch())
|
|
|
.build();
|
|
|
THREAD_POOL_EXECUTOR.execute(new Runnable() {
|
|
|
@Override
|
|
|
@@ -130,6 +165,13 @@ public class AppServiceImpl implements AppService {
|
|
|
}
|
|
|
}
|
|
|
});
|
|
|
- return taskId;
|
|
|
+ return Response.buildSuccess(taskId);
|
|
|
+ }
|
|
|
+
|
|
|
+ private AppInfoVO buildAppInfoVO(AppInfoPO appInfoPO) {
|
|
|
+ AppInfoVO appInfoVO = new AppInfoVO();
|
|
|
+ BeanUtils.copyProperties(appInfoPO, appInfoVO);
|
|
|
+ appInfoVO.setContributorIds(relationMapper.selectContributorIdsByAppId(appInfoPO.getId()));
|
|
|
+ return appInfoVO;
|
|
|
}
|
|
|
}
|