DevcloudDataAnalysisServiceImpl.java 60 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450
  1. package com.seecoder.dataanalysis.analysis.impl;
  2. import com.seecoder.dataanalysis.analysis.DevcloudDataAnalysisService;
  3. import com.seecoder.dataanalysis.data.dao.devcloud.*;
  4. import com.seecoder.dataanalysis.data.dao.eval.UserDao;
  5. import com.seecoder.dataanalysis.data.entity.devcloud.*;
  6. import com.seecoder.dataanalysis.data.entity.devcloud.display.*;
  7. import com.seecoder.dataanalysis.data.entity.eval.User;
  8. import com.seecoder.dataanalysis.vo.devcloud.*;
  9. import org.springframework.beans.factory.annotation.Autowired;
  10. import org.springframework.stereotype.Service;
  11. import java.text.DecimalFormat;
  12. import java.util.ArrayList;
  13. import java.util.List;
  14. import java.util.Optional;
  15. /**
  16. * @author Peng Yiyan
  17. * @since 2022/03/12
  18. */
  19. @Service
  20. public class DevcloudDataAnalysisServiceImpl implements DevcloudDataAnalysisService {
  21. @Autowired
  22. private DevcloudInfoDao devcloudInfoDao;
  23. @Autowired
  24. private DevcloudProjectDao devcloudProjectDao;
  25. @Autowired
  26. private DevcloudUserDao devcloudUserDao;
  27. // @Autowired
  28. // private ProjectRelateDao projectRelateDao;
  29. @Autowired
  30. private UserDao userDao;
  31. @Autowired
  32. private ProjectDao projectDao;
  33. @Override
  34. public DevcloudInfo updateDevInfoType100(BugInfoDTO bugInfoDTO){
  35. Integer projectId = bugInfoDTO.getProjectId();
  36. DevcloudInfo devcloudInfo;
  37. Optional<DevcloudInfo> result = devcloudInfoDao.findById(projectId);
  38. if(!result.isPresent()){
  39. devcloudInfo = new DevcloudInfo(projectId);
  40. }else {
  41. devcloudInfo = devcloudInfoDao.findById(projectId).get();
  42. }
  43. List<BugInfo> bugInfoList = devcloudInfo.getBugList();
  44. boolean exist = false;
  45. for(int i=0;i<bugInfoList.size();i++){
  46. //如果已经存在bug_id,则视为对bugInfo的修改
  47. // System.out.println("--------"+bugInfoList.get(i).getBugId());
  48. if(bugInfoList.get(i).getBugId().equals(bugInfoDTO.getBugId())){
  49. exist = true;
  50. bugInfoList.get(i).setBugId(bugInfoDTO.getBugId());
  51. bugInfoList.get(i).setUserId(bugInfoDTO.getUserId());
  52. bugInfoList.get(i).setPriority(bugInfoDTO.getPriority());
  53. bugInfoList.get(i).setTitle(bugInfoDTO.getTitle());
  54. bugInfoList.get(i).setDescription(bugInfoDTO.getDescription());
  55. bugInfoList.get(i).setTimeToTake(bugInfoDTO.getTimeToTake());
  56. bugInfoList.get(i).setBugState(bugInfoDTO.getBugState());
  57. break;
  58. }
  59. }
  60. //如果不存在bug_id,将bugInfo加入List
  61. if(!exist){
  62. BugInfo bugInfoNew = new BugInfo();
  63. bugInfoNew.setBugId(bugInfoDTO.getBugId());
  64. bugInfoNew.setUserId(bugInfoDTO.getUserId());
  65. bugInfoNew.setPriority(bugInfoDTO.getPriority());
  66. bugInfoNew.setTitle(bugInfoDTO.getTitle());
  67. bugInfoNew.setDescription(bugInfoDTO.getDescription());
  68. bugInfoNew.setTimeToTake(bugInfoDTO.getTimeToTake());
  69. bugInfoNew.setBugState(bugInfoDTO.getBugState());
  70. bugInfoList.add(bugInfoNew);
  71. }
  72. devcloudInfo.setBugList(bugInfoList);
  73. devcloudInfoDao.save(devcloudInfo);
  74. return devcloudInfo;
  75. }
  76. @Override
  77. public DevcloudInfo updateDevInfoType101(CommitInfoDTO commitInfoDTO){
  78. Integer projectId = commitInfoDTO.getProjectId();
  79. DevcloudInfo devcloudInfo;
  80. Optional<DevcloudInfo> result = devcloudInfoDao.findById(projectId);
  81. if(!result.isPresent()){
  82. devcloudInfo = new DevcloudInfo(projectId);
  83. }else {
  84. devcloudInfo = devcloudInfoDao.findById(projectId).get();
  85. }
  86. List<CommitInfo> commitInfoList = devcloudInfo.getCommitList();
  87. boolean exist = false;
  88. for(int i=0;i<commitInfoList.size();i++){
  89. if(commitInfoList.get(i).getCommitId().equals(commitInfoDTO.getCommitId())){
  90. exist = true;
  91. break;
  92. }
  93. }
  94. if(!exist){
  95. //新建commit信息
  96. CommitInfo commitInfo = new CommitInfo();
  97. commitInfo.setCommitId(commitInfoDTO.getCommitId());
  98. commitInfo.setUserId(commitInfoDTO.getUserId());
  99. commitInfo.setCommitName(commitInfoDTO.getCommitName());
  100. commitInfo.setCommitTime(commitInfoDTO.getCommitTime());
  101. commitInfo.setMessage(commitInfoDTO.getMessage());
  102. commitInfo.setType(commitInfoDTO.getType());
  103. commitInfoList.add(commitInfo);
  104. }else {
  105. System.out.println("请勿重复插入");
  106. }
  107. devcloudInfo.setCommitList(commitInfoList);
  108. devcloudInfoDao.save(devcloudInfo);
  109. return devcloudInfo;
  110. }
  111. @Override
  112. public DevcloudInfo updateDevInfoType102(TestInfoDTO testInfoDTO){
  113. Integer projectId = testInfoDTO.getProjectId();
  114. DevcloudInfo devcloudInfo;
  115. Optional<DevcloudInfo> result = devcloudInfoDao.findById(projectId);
  116. if(!result.isPresent()){
  117. devcloudInfo = new DevcloudInfo(projectId);
  118. }else {
  119. devcloudInfo = devcloudInfoDao.findById(projectId).get();
  120. }
  121. List<TestInfo> testInfoList = devcloudInfo.getTestList();
  122. boolean exist = false;
  123. for(int i=0;i<testInfoList.size();i++){
  124. if(testInfoList.get(i).getApiTestId().equals(testInfoDTO.getApiTestId())){
  125. exist = true;
  126. break;
  127. }
  128. }
  129. //新建测试信息
  130. if(!exist){
  131. TestInfo testInfo = new TestInfo();
  132. testInfo.setApiTestId(testInfoDTO.getApiTestId());
  133. testInfo.setUserId(testInfoDTO.getUserId());
  134. testInfo.setSuccess(testInfoDTO.getSuccess());
  135. testInfo.setFailure(testInfoDTO.getFailure());
  136. testInfoList.add(testInfo);
  137. }else {
  138. System.out.println("请勿重复插入");
  139. }
  140. devcloudInfo.setTestList(testInfoList);
  141. devcloudInfoDao.save(devcloudInfo);
  142. return devcloudInfo;
  143. }
  144. @Override
  145. public DevcloudInfo updateDevInfoType103(PipelineCreationDTO pipelineCreationDTO){
  146. Integer projectId = pipelineCreationDTO.getProjectId();
  147. DevcloudInfo devcloudInfo;
  148. Optional<DevcloudInfo> result = devcloudInfoDao.findById(projectId);
  149. if(!result.isPresent()){
  150. devcloudInfo = new DevcloudInfo(projectId);
  151. }else {
  152. devcloudInfo = devcloudInfoDao.findById(projectId).get();
  153. }
  154. List<PipelineInfo> pipelineInfoList = devcloudInfo.getPipelineList();
  155. boolean exist = false;
  156. for(int i=0;i<pipelineInfoList.size();i++){
  157. if(pipelineInfoList.get(i).getPipelineId().equals(pipelineCreationDTO.getPipelineId())){
  158. exist = true;
  159. break;
  160. }
  161. }
  162. //新建流水线信息
  163. if(!exist){
  164. // System.out.println(pipelineInfoList.size());
  165. // System.out.println(pipelineCreationDTO.getPipelineId());
  166. PipelineInfo pipelineInfo = new PipelineInfo();
  167. pipelineInfo.setPipelineId(pipelineCreationDTO.getPipelineId());
  168. pipelineInfoList.add(pipelineInfo);
  169. }else {
  170. System.out.println("请勿重复插入");
  171. }
  172. devcloudInfo.setPipelineList(pipelineInfoList);
  173. devcloudInfoDao.save(devcloudInfo);
  174. return devcloudInfo;
  175. }
  176. @Override
  177. public DevcloudInfo updateDevInfoType104(PipelineDeletionDTO pipelineDeletionDTO){
  178. Integer projectId = pipelineDeletionDTO.getProjectId();
  179. Integer pipelineId = pipelineDeletionDTO.getPipelineId();
  180. DevcloudInfo devcloudInfo;
  181. Optional<DevcloudInfo> result = devcloudInfoDao.findById(projectId);
  182. if(!result.isPresent()){
  183. devcloudInfo = new DevcloudInfo(projectId);
  184. }else {
  185. devcloudInfo = devcloudInfoDao.findById(projectId).get();
  186. }
  187. List<PipelineInfo> pipelineInfoList = devcloudInfo.getPipelineList();
  188. //找到对应的id,删除
  189. for(int i=0;i<pipelineInfoList.size();i++){
  190. if(pipelineInfoList.get(i).getPipelineId().equals(pipelineId)){
  191. // System.out.println("will remove");
  192. pipelineInfoList.remove(i);
  193. break;
  194. }
  195. }
  196. devcloudInfo.setPipelineList(pipelineInfoList);
  197. devcloudInfoDao.save(devcloudInfo);
  198. return devcloudInfo;
  199. }
  200. @Override
  201. public DevcloudInfo updateDevInfoType105(PipelineDeployDTO pipelineDeployDTO){
  202. Integer projectId = pipelineDeployDTO.getProjectId();
  203. Integer pipelineId = pipelineDeployDTO.getPipelineId();
  204. // DevcloudInfo devcloudInfo = devcloudInfoDao.findById(projectId).get();
  205. DevcloudInfo devcloudInfo;
  206. Optional<DevcloudInfo> result = devcloudInfoDao.findById(projectId);
  207. if(!result.isPresent()){
  208. devcloudInfo = new DevcloudInfo(projectId);
  209. }else {
  210. devcloudInfo = devcloudInfoDao.findById(projectId).get();
  211. }
  212. List<PipelineInfo> pipelineInfoList = devcloudInfo.getPipelineList();
  213. //找到对应的id,存入部署信息
  214. for(int i=0;i<pipelineInfoList.size();i++){
  215. if(pipelineInfoList.get(i).getPipelineId().equals(pipelineId)){
  216. List<RecordInfo> recordInfoList = pipelineInfoList.get(i).getRecordList();
  217. RecordInfo recordInfo = new RecordInfo();
  218. recordInfo.setRecordId(pipelineDeployDTO.getRecordId());
  219. recordInfo.setUserId(pipelineDeployDTO.getUserId());
  220. recordInfo.setResult(pipelineDeployDTO.getResult());
  221. recordInfoList.add(recordInfo);
  222. break;
  223. }
  224. }
  225. devcloudInfo.setPipelineList(pipelineInfoList);
  226. devcloudInfoDao.save(devcloudInfo);
  227. return devcloudInfo;
  228. }
  229. @Override
  230. public DevcloudInfo updateDevInfoType106(TreeNodeInfoDTO treeNodeInfoDTO){
  231. Integer projectId = treeNodeInfoDTO.getProjectId();
  232. DevcloudInfo devcloudInfo;
  233. Optional<DevcloudInfo> result = devcloudInfoDao.findById(projectId);
  234. if(!result.isPresent()){
  235. devcloudInfo = new DevcloudInfo(projectId);
  236. }else {
  237. devcloudInfo = devcloudInfoDao.findById(projectId).get();
  238. }
  239. List<TreeNodeInfo> treeNodeInfoList = devcloudInfo.getTreeNodeList();
  240. boolean exist = false;
  241. for(int i=0;i<treeNodeInfoList.size();i++){
  242. //如果已经存在node_id,则视为对节点信息的修改
  243. if(treeNodeInfoList.get(i).getNodeId().equals(treeNodeInfoDTO.getNodeId())){
  244. exist = true;
  245. treeNodeInfoList.get(i).setTitle(treeNodeInfoDTO.getTitle());
  246. treeNodeInfoList.get(i).setUserId(treeNodeInfoDTO.getUserId());
  247. treeNodeInfoList.get(i).setType(treeNodeInfoDTO.getType());
  248. treeNodeInfoList.get(i).setPriority(treeNodeInfoDTO.getPriority());
  249. treeNodeInfoList.get(i).setState(treeNodeInfoDTO.getState());
  250. treeNodeInfoList.get(i).setTimeToTake(treeNodeInfoDTO.getTimeToTake());
  251. treeNodeInfoList.get(i).setParentId(treeNodeInfoDTO.getParentId());
  252. treeNodeInfoList.get(i).setDeep(treeNodeInfoDTO.getDeep());
  253. break;
  254. }
  255. }
  256. //如果不存在node_id,则视为添加节点
  257. if(!exist){
  258. TreeNodeInfo treeNodeInfoNew = new TreeNodeInfo();
  259. treeNodeInfoNew.setNodeId(treeNodeInfoDTO.getNodeId());
  260. treeNodeInfoNew.setTitle(treeNodeInfoDTO.getTitle());
  261. treeNodeInfoNew.setUserId(treeNodeInfoDTO.getUserId());
  262. treeNodeInfoNew.setType(treeNodeInfoDTO.getType());
  263. treeNodeInfoNew.setPriority(treeNodeInfoDTO.getPriority());
  264. treeNodeInfoNew.setState(treeNodeInfoDTO.getState());
  265. treeNodeInfoNew.setTimeToTake(treeNodeInfoDTO.getTimeToTake());
  266. treeNodeInfoNew.setParentId(treeNodeInfoDTO.getParentId());
  267. treeNodeInfoNew.setDeep(treeNodeInfoDTO.getDeep());
  268. treeNodeInfoList.add(treeNodeInfoNew);
  269. }
  270. devcloudInfo.setTreeNodeList(treeNodeInfoList);
  271. devcloudInfoDao.save(devcloudInfo);
  272. return devcloudInfo;
  273. }
  274. @Override
  275. public DevcloudInfo updateDevInfoType107(TreeNodeDeletionDTO treeNodeDeletionDTO){
  276. Integer projectId = treeNodeDeletionDTO.getProjectId();
  277. DevcloudInfo devcloudInfo;
  278. Optional<DevcloudInfo> result = devcloudInfoDao.findById(projectId);
  279. if(!result.isPresent()){
  280. devcloudInfo = new DevcloudInfo(projectId);
  281. }else {
  282. devcloudInfo = devcloudInfoDao.findById(projectId).get();
  283. }
  284. List<TreeNodeInfo> treeNodeInfoList = devcloudInfo.getTreeNodeList();
  285. List<Integer> nodeIds = treeNodeDeletionDTO.getNodeIds();
  286. for(int i=0;i<nodeIds.size();i++){
  287. Integer nodeId = nodeIds.get(i);
  288. for(int j=0;j<treeNodeInfoList.size();j++){
  289. if(treeNodeInfoList.get(j).getNodeId().equals(nodeId)){
  290. treeNodeInfoList.remove(j);
  291. break;
  292. }
  293. }
  294. }
  295. devcloudInfo.setTreeNodeList(treeNodeInfoList);
  296. devcloudInfoDao.save(devcloudInfo);
  297. return devcloudInfo;
  298. }
  299. @Override
  300. public DevcloudProject updateDevInfoType108(AddProjectDTO addProjectDTO){
  301. Integer projectId = addProjectDTO.getProjectId();
  302. DevcloudProject devcloudProject;
  303. Optional<DevcloudProject> result = devcloudProjectDao.findById(projectId);
  304. //如果项目-用户信息不存在,则新建项目-用户信息,否则直接查询
  305. if(!result.isPresent()){
  306. devcloudProject = new DevcloudProject();
  307. devcloudProject.setProjectId(projectId);
  308. // devcloudProjectDao.save(devcloudProject);
  309. }else {
  310. devcloudProject = devcloudProjectDao.findById(projectId).get();
  311. }
  312. List<Integer> memberIds = devcloudProject.getUserIds();
  313. //如果该添加日志中的成员id还不在项目中,则加入
  314. if(!memberIds.contains(addProjectDTO.getUserId())){
  315. memberIds.add(addProjectDTO.getUserId());
  316. }
  317. devcloudProject.setUserIds(memberIds);
  318. devcloudProjectDao.save(devcloudProject);
  319. Integer userId = addProjectDTO.getUserId();
  320. // //查询该项目是否有关联项目,如果有关联项目,需要把该成员也加入关联项目中
  321. // Optional<ProjectRelate> result2 = projectRelateDao.findById(projectId);
  322. // Integer relateId = -1;
  323. // //如果存在关联项目
  324. // if(result2.isPresent()){
  325. // relateId = projectRelateDao.findById(projectId).get().getRelateId();
  326. // }
  327. //
  328. // DevcloudProject relateProject;
  329. // if(relateId != -1){
  330. // Optional<DevcloudProject> result3 = devcloudProjectDao.findById(relateId);
  331. // if(!result3.isPresent()){
  332. // relateProject = new DevcloudProject();
  333. // relateProject.setProjectId(relateId);
  334. // }else {
  335. // relateProject = devcloudProjectDao.findById(relateId).get();
  336. // }
  337. //
  338. // List<Integer> relateMembers = relateProject.getUserIds();
  339. // if(!relateMembers.contains(userId)){
  340. // relateMembers.add(userId);
  341. // relateProject.setUserIds(relateMembers);
  342. // }
  343. //
  344. // devcloudProjectDao.save(relateProject);
  345. // }
  346. //处理完项目-用户关系,现在处理用户-项目关系
  347. //所有的devcloudUser都在此处创建
  348. DevcloudUser devcloudUser;
  349. Optional<DevcloudUser> result1 = devcloudUserDao.findById(userId);
  350. if(!result1.isPresent()){
  351. devcloudUser = new DevcloudUser();
  352. devcloudUser.setUserId(userId);
  353. }else {
  354. devcloudUser = devcloudUserDao.findById(userId).get();
  355. }
  356. List<Integer> projectIds = devcloudUser.getProjectIds();
  357. if(!projectIds.contains(addProjectDTO.getProjectId())){
  358. projectIds.add(addProjectDTO.getProjectId());
  359. }
  360. // if(relateId!=-1){
  361. // if(!projectIds.contains(relateId)){
  362. // projectIds.add(relateId);
  363. // }
  364. // }
  365. devcloudUser.setProjectIds(projectIds);
  366. devcloudUserDao.save(devcloudUser);
  367. return devcloudProject;
  368. }
  369. @Override
  370. public int updateDevInfoType109(RelateProjectDTO relateProjectDTO){
  371. Integer projectAId = relateProjectDTO.getProjectAId();
  372. Integer projectBId = relateProjectDTO.getProjectBId();
  373. // ProjectRelate projectRelate;
  374. // Optional<ProjectRelate> result = projectRelateDao.findById(projectAId);
  375. // if(!result.isPresent()){
  376. // projectRelate = new ProjectRelate();
  377. // projectRelate.setProjectId(projectAId);
  378. // projectRelate.setRelateId(relateProjectDTO.getProjectBId());
  379. // projectRelateDao.save(projectRelate);
  380. // }else {
  381. // //项目的关联项目只能有一个
  382. // projectRelate = projectRelateDao.findById(projectAId).get();
  383. // projectRelate.setRelateId(relateProjectDTO.getProjectBId());
  384. // projectRelateDao.save(projectRelate);
  385. // }
  386. //增加关联后,A和B中的成员应该相同,每个成员也应该加入
  387. //先将A、B项目中的成员同步
  388. DevcloudProject projectA, projectB;
  389. Optional<DevcloudProject> result1 = devcloudProjectDao.findById(projectAId);
  390. if(!result1.isPresent()){
  391. projectA = new DevcloudProject();
  392. projectA.setProjectId(projectAId);
  393. }else {
  394. projectA = devcloudProjectDao.findById(projectAId).get();
  395. }
  396. Optional<DevcloudProject> result2 = devcloudProjectDao.findById(projectBId);
  397. if(!result2.isPresent()){
  398. projectB = new DevcloudProject();
  399. projectB.setProjectId(projectBId);
  400. }else {
  401. projectB = devcloudProjectDao.findById(projectBId).get();
  402. }
  403. //将A和B中的user_id进行合并
  404. List<Integer> totalMembers = new ArrayList<>();
  405. for(Integer id : projectA.getUserIds()){
  406. if(!totalMembers.contains(id)){
  407. totalMembers.add(id);
  408. }
  409. }
  410. for(Integer id : projectB.getUserIds()){
  411. if(!totalMembers.contains(id)){
  412. totalMembers.add(id);
  413. }
  414. }
  415. projectA.setUserIds(totalMembers);
  416. projectB.setUserIds(new ArrayList<>(totalMembers));
  417. devcloudProjectDao.save(projectA);
  418. devcloudProjectDao.save(projectB);
  419. //然后将小组成员遍历,将projectA、B都添加
  420. for(Integer userId : totalMembers){
  421. DevcloudUser devcloudUser;
  422. Optional<DevcloudUser> result3 = devcloudUserDao.findById(userId);
  423. if(!result3.isPresent()){
  424. devcloudUser = new DevcloudUser();
  425. devcloudUser.setUserId(userId);
  426. }else {
  427. devcloudUser = devcloudUserDao.findById(userId).get();
  428. }
  429. List<Integer> projectIds = devcloudUser.getProjectIds();
  430. if(!projectIds.contains(projectAId)){
  431. projectIds.add(projectAId);
  432. }
  433. if(!projectIds.contains(projectBId)){
  434. projectIds.add(projectBId);
  435. }
  436. devcloudUser.setProjectIds(projectIds);
  437. devcloudUserDao.save(devcloudUser);
  438. }
  439. return 1;
  440. }
  441. @Override
  442. public Project updateDevInfoType110(ProjectDTO projectDTO){
  443. Integer projectId = projectDTO.getProjectId();
  444. Project project;
  445. Optional<Project> result = projectDao.findById(projectId);
  446. if(!result.isPresent()){
  447. project = new Project();
  448. }else {
  449. System.out.println("请勿重复添加项目");
  450. return projectDao.findById(projectId).get();
  451. }
  452. project.setProjectId(projectId);
  453. project.setProjectName(projectDTO.getProjectName());
  454. project.setDescription(projectDTO.getDescription());
  455. projectDao.save(project);
  456. //添加项目之后,初始化项目的devInfo
  457. DevcloudInfo devcloudInfo;
  458. Optional<DevcloudInfo> result2 = devcloudInfoDao.findById(projectId);
  459. if(!result2.isPresent()){
  460. devcloudInfo = new DevcloudInfo(projectId);
  461. devcloudInfoDao.save(devcloudInfo);
  462. }
  463. return project;
  464. }
  465. @Override
  466. public User updateDevInfoType111(UserDTO userDTO){
  467. Integer userId = userDTO.getUserId();
  468. User user;
  469. Optional<User> result = userDao.findById(userId);
  470. if(!result.isPresent()){
  471. user = new User();
  472. }else {
  473. System.out.println("该用户已存在");
  474. return userDao.findByUserId(userId);
  475. }
  476. user.setUserId(userId);
  477. user.setName(userDTO.getName());
  478. user.setRole(userDTO.getRole());
  479. user.setEmail(userDTO.getEmail());
  480. user.setPhone(userDTO.getPhone());
  481. userDao.save(user);
  482. return user;
  483. }
  484. @Override
  485. public FormatStudent getStudentAnalysis(Integer user_id){
  486. FormatStudent formatStudent = new FormatStudent();
  487. User user = userDao.findByUserId(user_id);
  488. DevcloudUser devcloudUser;
  489. Optional<DevcloudUser> result = devcloudUserDao.findById(user_id);
  490. //如果devcloudUser不存在,说明用户还没有加入任何项目
  491. //但如果存在对应的User信息,则帮用户新建devcloudUser
  492. if(!result.isPresent()){
  493. // System.out.println("没有查找到学生id");
  494. }else {
  495. devcloudUser = devcloudUserDao.findById(user_id).get();
  496. }
  497. //放入展示数据
  498. formatStudent.setUserId(user_id);
  499. formatStudent.setName(user.getName());
  500. formatStudent.setEmail(user.getEmail());
  501. //根据用户id找到和该用户关联的所有项目id
  502. List<Integer> projectList = devcloudUserDao.findById(user_id).get().getProjectIds();
  503. List<Project> projects = new ArrayList<>();
  504. for(int i=0;i<projectList.size();i++){
  505. projects.add(projectDao.findById(projectList.get(i)).get());
  506. }
  507. //放入个人包含的所有项目信息
  508. formatStudent.setProjects(projects);
  509. //放入个人Commit信息,测试信息,流水线信息
  510. Commit commit = new Commit();
  511. Test test = new Test();
  512. Pipeline pipeline = new Pipeline();
  513. //新增
  514. Bug bugList = new Bug();
  515. TreeNode treeNode = new TreeNode();
  516. Integer commit_times=0,valid_commit_time=0,buglist_commit=0,feature_commit=0;
  517. List<String> commit_msg_overview = new ArrayList<>();
  518. Integer test_success=0,test_failure=0,test_times=0,test_concurrency_count=0;
  519. Integer pipeline_deploy=0,pipeline_pass=0,pipeline_failure=0;
  520. //新增bugList和TreeNode
  521. Integer bug_times=0,high_times=0,finished_times=0;
  522. Integer treeNode_times=0,high_treeNode_times=0,finished_treeNode_times=0;
  523. //遍历所有相关项目
  524. for(int i=0;i<projectList.size();i++){
  525. Integer projectId = projectList.get(i);
  526. DevcloudInfo devcloudInfo = devcloudInfoDao.findById(projectId).get();
  527. //遍历devInfo中的commit信息
  528. List<CommitInfo> commitInfos = devcloudInfo.getCommitList();
  529. for(CommitInfo commitInfo : commitInfos){
  530. if(commitInfo.getUserId() == null) {
  531. continue;
  532. }else if(commitInfo.getUserId().equals(user_id)){
  533. commit_times++;
  534. commit_msg_overview.add(commitInfo.getMessage());
  535. //如果是需求的commit
  536. if(commitInfo.getType().toLowerCase().equals("tree_id")){
  537. feature_commit++;
  538. }
  539. //如果是bug_list的commit
  540. if(commitInfo.getType().toLowerCase().equals("bug_id")){
  541. buglist_commit++;
  542. }
  543. //判断是否是有效的commit
  544. if(commitInfo.getMessage().startsWith("feat:")||commitInfo.getMessage().startsWith("fix:")){
  545. valid_commit_time++;
  546. }
  547. }
  548. }
  549. //遍历devInfo中的test信息
  550. List<TestInfo> testInfos = devcloudInfo.getTestList();
  551. for(TestInfo testInfo : testInfos){
  552. if(testInfo.getUserId() == null) {
  553. continue;
  554. }else if(testInfo.getUserId().equals(user_id)){
  555. test_times++;
  556. test_success += testInfo.getSuccess();
  557. test_failure += testInfo.getFailure();
  558. test_concurrency_count += testInfo.getSuccess();
  559. test_concurrency_count += testInfo.getFailure();
  560. }
  561. }
  562. //遍历devInfo中的pipeline信息
  563. List<PipelineInfo> pipelineInfos = devcloudInfo.getPipelineList();
  564. for(PipelineInfo pipelineInfo : pipelineInfos){
  565. //遍历每个流水线中的部署记录
  566. List<RecordInfo> recordInfos = pipelineInfo.getRecordList();
  567. for(RecordInfo recordInfo : recordInfos){
  568. if(recordInfo.getUserId() == null) {
  569. continue;
  570. }else if(recordInfo.getUserId().equals(user_id)){
  571. pipeline_deploy++;
  572. if(recordInfo.getResult().equals("部署成功")){
  573. pipeline_pass++;
  574. }
  575. if(recordInfo.getResult().equals("部署失败")){
  576. pipeline_failure++;
  577. }
  578. }
  579. }
  580. }
  581. //遍历devInfo中的bugList信息
  582. List<BugInfo> bugInfos = devcloudInfo.getBugList();
  583. for(BugInfo bugInfo : bugInfos){
  584. if(bugInfo.getUserId() == null){
  585. continue;
  586. }else if(bugInfo.getUserId().equals(user_id)){
  587. bug_times++;
  588. if(bugInfo.getPriority().toLowerCase().equals("high")){
  589. high_times++;
  590. }
  591. if(bugInfo.getBugState().toLowerCase().equals("finished")){
  592. finished_times++;
  593. }
  594. }
  595. }
  596. //遍历devInfo的treeNode信息
  597. List<TreeNodeInfo> treeNodeInfos = devcloudInfo.getTreeNodeList();
  598. for(TreeNodeInfo treeNodeInfo : treeNodeInfos){
  599. if(treeNodeInfo.getUserId() == null){
  600. continue;
  601. }else if(treeNodeInfo.getUserId().equals(user_id)){
  602. treeNode_times++;
  603. if(treeNodeInfo.getPriority().toLowerCase().equals("high")){
  604. high_treeNode_times++;
  605. }
  606. if(treeNodeInfo.getState().toLowerCase().equals("finished")){
  607. finished_treeNode_times++;
  608. }
  609. }
  610. }
  611. }
  612. //commit
  613. commit.setCommit_times(commit_times);
  614. commit.setValid_commit_times(valid_commit_time);
  615. commit.setBuglist_commit(buglist_commit);
  616. commit.setFeature_commit(feature_commit);
  617. commit.setCommit_msg_overview(commit_msg_overview);
  618. //test
  619. test.setTest_times(test_times);
  620. test.setTest_concurrency_count(test_concurrency_count);
  621. test.setTest_concurrency_success(test_success);
  622. test.setTest_concurrency_failure(test_failure);
  623. //pipeline
  624. pipeline.setPipeline_deploy(pipeline_deploy);
  625. pipeline.setPipeline_pass(pipeline_pass);
  626. pipeline.setPipline_failure(pipeline_failure);
  627. //bugList
  628. bugList.setBug_times(bug_times);
  629. bugList.setHigh_times(high_times);
  630. bugList.setFinished_times(finished_times);
  631. //treeNode
  632. treeNode.setTreeNode_times(treeNode_times);
  633. treeNode.setHigh_treeNode_times(high_treeNode_times);
  634. treeNode.setFinished_treeNode_times(finished_treeNode_times);
  635. formatStudent.setCommit(commit);
  636. formatStudent.setTest(test);
  637. formatStudent.setPipeline(pipeline);
  638. formatStudent.setBuglist(bugList);
  639. formatStudent.setTreeNode(treeNode);
  640. return formatStudent;
  641. }
  642. @Override
  643. public FormatGroup getGroupAnalysis(Integer project_id){
  644. //暂时不存在GroupId,先使用ProjectId代替
  645. FormatGroup formatGroup = new FormatGroup();
  646. //记录该小组拥有的所有项目的id
  647. List<Integer> projectList = new ArrayList<>();
  648. //记录所有项目的信息,用于小组项目信息展示
  649. List<Project> projects = new ArrayList<>();
  650. // Integer projectAId = project_id;
  651. // Integer projectBId;
  652. // Optional<ProjectRelate> result1 = projectRelateDao.findById(project_id);
  653. // if(!result1.isPresent()){
  654. // System.out.println("没有找到关联项目");
  655. // }else {
  656. // projectBId = projectRelateDao.findById(project_id).get().getRelateId();
  657. // projectList.add(projectBId);
  658. // projects.add(projectDao.findById(projectBId).get());
  659. // }
  660. //先将传入的project加入List
  661. projectList.add(project_id);
  662. projects.add(projectDao.findById(project_id).get());
  663. Optional<DevcloudProject> result2 = devcloudProjectDao.findById(project_id);
  664. if(!result2.isPresent()){
  665. System.out.println("没有找到项目的成员信息");
  666. return null;
  667. }
  668. List<Integer> userIds = devcloudProjectDao.findById(project_id).get().getUserIds();
  669. //遍历加入项目中所有成员下拥有的项目,得到该小组所有的项目
  670. for(Integer userId : userIds){
  671. Optional<DevcloudUser> result = devcloudUserDao.findById(userId);
  672. if(!result.isPresent()){
  673. continue;
  674. }else {
  675. List<Integer> proIds = devcloudUserDao.findById(userId).get().getProjectIds();
  676. for(Integer proId : proIds){
  677. if(!projectList.contains(proId)){
  678. projectList.add(proId);
  679. projects.add(projectDao.findById(proId).get());
  680. }
  681. }
  682. }
  683. }
  684. //将所有的成员信息加入
  685. List<User> users = new ArrayList<>();
  686. for(int i=0;i<userIds.size();i++){
  687. Integer userId = userIds.get(i);
  688. users.add(userDao.findByUserId(userId));
  689. }
  690. int n = userIds.size();
  691. formatGroup.setProjects(projects);
  692. formatGroup.setStudents(users);
  693. //放入小组Commit信息,测试信息,流水线信息
  694. Commit commit = new Commit();
  695. Test test = new Test();
  696. Pipeline pipeline = new Pipeline();
  697. //新增
  698. Bug bugList = new Bug();
  699. TreeNode treeNode = new TreeNode();
  700. Integer commit_times=0,valid_commit_time=0,buglist_commit=0,feature_commit=0;
  701. //记录小组不同成员的commit贡献
  702. int[] commitTimes = new int[n];
  703. List<String> commit_msg_overview = new ArrayList<>();
  704. Integer test_success=0,test_failure=0,test_times=0,test_concurrency_count=0;
  705. //记录小组不同成员的test贡献
  706. int[] testTimes = new int[n];
  707. Integer pipeline_deploy=0,pipeline_pass=0,pipeline_failure=0;
  708. //记录小组不同成员的deploy贡献
  709. int[] pipeTimes = new int[n];
  710. //新增bugList,treeNode
  711. Integer bug_times=0,high_times=0,finished_times=0;
  712. //记录小组不同成员的bugList贡献
  713. int[] bugTimes = new int[n];
  714. Integer treeNode_times=0,high_treeNode_times=0,finished_treeNode_times=0;
  715. //记录小组不同成员的treeNode贡献
  716. int[] treeNodeTimes = new int[n];
  717. //遍历所有的项目,将整体信息作为小组的分析情况
  718. for(int i=0;i<projectList.size();i++){
  719. Integer projectId = projectList.get(i);
  720. DevcloudInfo devcloudInfo;
  721. Optional<DevcloudInfo> result3 = devcloudInfoDao.findById(projectId);
  722. //如果找不到对应的项目信息则跳过该项目
  723. if(!result3.isPresent()){
  724. continue;
  725. }
  726. devcloudInfo = devcloudInfoDao.findById(projectId).get();
  727. //遍历devInfo中的commit信息
  728. List<CommitInfo> commitInfos = devcloudInfo.getCommitList();
  729. // System.out.println("commitInfosSize: "+commitInfos.size());
  730. // commit_times += commitInfos.size();
  731. for(CommitInfo commitInfo : commitInfos){
  732. if(commitInfo.getUserId() == null || isInGroup(commitInfo.getUserId(),userIds)==false){
  733. continue;
  734. }else{
  735. commit_times++;
  736. commit_msg_overview.add(commitInfo.getMessage());
  737. //如果是需求的commit
  738. if(commitInfo.getType().toLowerCase().equals("tree_id")||commitInfo.getMessage().startsWith("feat:")){
  739. feature_commit++;
  740. }
  741. //如果是bug_list的commit
  742. if(commitInfo.getType().toLowerCase().equals("bug_id")||commitInfo.getMessage().startsWith("fix:")){
  743. buglist_commit++;
  744. }
  745. //判断是否是有效的commit
  746. if(commitInfo.getMessage().startsWith("feat:")||commitInfo.getMessage().startsWith("fix:")){
  747. valid_commit_time++;
  748. }
  749. }
  750. for(int j=0;j<userIds.size();j++){
  751. Integer user_id = userIds.get(j);
  752. if(commitInfo.getUserId() == null) {
  753. continue;
  754. }else if(commitInfo.getUserId().equals(user_id)){
  755. commitTimes[j]++;
  756. // //如果是需求的commit
  757. // if(commitInfo.getType().toLowerCase().equals("tree_id")||commitInfo.getMessage().startsWith("feat:")){
  758. // feature_commit++;
  759. // }
  760. // //如果是bug_list的commit
  761. // if(commitInfo.getType().toLowerCase().equals("bug_id")||commitInfo.getMessage().startsWith("fix:")){
  762. // buglist_commit++;
  763. // }
  764. // //判断是否是有效的commit
  765. // if(commitInfo.getMessage().startsWith("feat:")||commitInfo.getMessage().startsWith("fix:")){
  766. // valid_commit_time++;
  767. // }
  768. }
  769. }
  770. }
  771. //遍历devInfo中的test信息
  772. List<TestInfo> testInfos = devcloudInfo.getTestList();
  773. // test_times += testInfos.size();
  774. for(TestInfo testInfo : testInfos){
  775. if(testInfo.getUserId() == null || isInGroup(testInfo.getUserId(),userIds)==false){
  776. continue;
  777. }else {
  778. test_times++;
  779. test_success += testInfo.getSuccess();
  780. test_failure += testInfo.getFailure();
  781. test_concurrency_count += testInfo.getSuccess();
  782. test_concurrency_count += testInfo.getFailure();
  783. }
  784. for(int j=0;j<userIds.size();j++){
  785. Integer user_id = userIds.get(j);
  786. if(testInfo.getUserId() == null) {
  787. continue;
  788. }else if(testInfo.getUserId().equals(user_id)){
  789. testTimes[j]++;
  790. // test_success += testInfo.getSuccess();
  791. // test_failure += testInfo.getFailure();
  792. // test_concurrency_count += testInfo.getSuccess();
  793. // test_concurrency_count += testInfo.getFailure();
  794. }
  795. }
  796. }
  797. //遍历devInfo中的pipeline信息
  798. List<PipelineInfo> pipelineInfos = devcloudInfo.getPipelineList();
  799. for(PipelineInfo pipelineInfo : pipelineInfos){
  800. //遍历每个流水线中的部署记录
  801. List<RecordInfo> recordInfos = pipelineInfo.getRecordList();
  802. // for(int j=0;j<userIds.size();j++){
  803. // Integer user_id = userIds.get(j);
  804. // for(RecordInfo recordInfo : recordInfos){
  805. // pipeline_deploy++;
  806. // if(recordInfo.getUserId() == null) {
  807. // continue;
  808. // }else if(recordInfo.getUserId().equals(user_id)){
  809. // pipeTimes[j]++;
  810. // if(recordInfo.getResult().equals("部署成功")){
  811. // pipeline_pass++;
  812. // }
  813. // if(recordInfo.getResult().equals("部署失败")){
  814. // pipeline_failure++;
  815. // }
  816. // }
  817. // }
  818. // }
  819. for(RecordInfo recordInfo : recordInfos){
  820. if(recordInfo.getUserId() == null || isInGroup(recordInfo.getUserId(),userIds)==false){
  821. continue;
  822. }else {
  823. pipeline_deploy++;
  824. if(recordInfo.getResult().equals("部署成功")){
  825. pipeline_pass++;
  826. }
  827. if(recordInfo.getResult().equals("部署失败")){
  828. pipeline_failure++;
  829. }
  830. }
  831. for(int j=0;j<userIds.size();j++){
  832. Integer user_id = userIds.get(j);
  833. if(recordInfo.getUserId() == null) {
  834. continue;
  835. }else if(recordInfo.getUserId().equals(user_id)){
  836. pipeTimes[j]++;
  837. }
  838. }
  839. }
  840. }
  841. //遍历devInfo中的bugList信息
  842. List<BugInfo> bugInfos = devcloudInfo.getBugList();
  843. for(BugInfo bugInfo : bugInfos){
  844. if(bugInfo.getUserId() == null || isInGroup(bugInfo.getUserId(),userIds)==false){
  845. continue;
  846. }else {
  847. bug_times++;
  848. if(bugInfo.getPriority().toLowerCase().equals("high")){
  849. high_times++;
  850. }
  851. if(bugInfo.getBugState().toLowerCase().equals("finished")){
  852. finished_times++;
  853. }
  854. }
  855. for(int j=0;j<userIds.size();j++){
  856. Integer user_id = userIds.get(j);
  857. if(bugInfo.getUserId() == null){
  858. continue;
  859. }else if(bugInfo.getUserId().equals(user_id)){
  860. bugTimes[j]++;
  861. // if(bugInfo.getPriority().toLowerCase().equals("high")){
  862. // high_times++;
  863. // }
  864. // if(bugInfo.getBugState().toLowerCase().equals("finished")){
  865. // finished_times++;
  866. // }
  867. }
  868. }
  869. }
  870. //遍历devInfo的treeNode信息
  871. List<TreeNodeInfo> treeNodeInfos = devcloudInfo.getTreeNodeList();
  872. for(TreeNodeInfo treeNodeInfo : treeNodeInfos){
  873. if(treeNodeInfo.getUserId() == null || isInGroup(treeNodeInfo.getUserId(),userIds)==false){
  874. continue;
  875. }else {
  876. treeNode_times++;
  877. if(treeNodeInfo.getPriority().toLowerCase().equals("high")){
  878. high_treeNode_times++;
  879. }
  880. if(treeNodeInfo.getState().toLowerCase().equals("finished")){
  881. finished_treeNode_times++;
  882. }
  883. }
  884. for(int j=0;j<userIds.size();j++){
  885. Integer user_id = userIds.get(j);
  886. if(treeNodeInfo.getUserId() == null){
  887. continue;
  888. }else if(treeNodeInfo.getUserId().equals(user_id)){
  889. treeNodeTimes[j]++;
  890. // if(treeNodeInfo.getPriority().toLowerCase().equals("high")){
  891. // high_treeNode_times++;
  892. // }
  893. // if(treeNodeInfo.getState().toLowerCase().equals("finished")){
  894. // finished_treeNode_times++;
  895. // }
  896. }
  897. }
  898. }
  899. }
  900. DecimalFormat df = new DecimalFormat("#.00");
  901. //commit
  902. commit.setCommit_times(commit_times);
  903. commit.setValid_commit_times(valid_commit_time);
  904. commit.setBuglist_commit(buglist_commit);
  905. commit.setFeature_commit(feature_commit);
  906. commit.setCommit_msg_overview(commit_msg_overview);
  907. List<Contribution> commitContribution = new ArrayList<>();
  908. for(int i=0;i<userIds.size();i++){
  909. Contribution contribution = new Contribution();
  910. contribution.setUserId(users.get(i).getUserId());
  911. contribution.setName(users.get(i).getName());
  912. contribution.setTimes(commitTimes[i]);
  913. Double value;
  914. if(commit_times == 0){
  915. value = 0.0;
  916. }else {
  917. value = (double)commitTimes[i]/(double)commit_times;
  918. }
  919. contribution.setProportion(Double.valueOf(df.format(value)));
  920. commitContribution.add(contribution);
  921. }
  922. commit.setCommit_contribution(commitContribution);
  923. //test
  924. test.setTest_times(test_times);
  925. test.setTest_concurrency_count(test_concurrency_count);
  926. test.setTest_concurrency_success(test_success);
  927. test.setTest_concurrency_failure(test_failure);
  928. List<Contribution> testContribution = new ArrayList<>();
  929. for(int i=0;i<userIds.size();i++){
  930. Contribution contribution = new Contribution();
  931. contribution.setUserId(users.get(i).getUserId());
  932. contribution.setName(users.get(i).getName());
  933. contribution.setTimes(testTimes[i]);
  934. Double value;
  935. if(test_times == 0){
  936. value = 0.0;
  937. }else {
  938. value = (double)testTimes[i]/(double)test_times;
  939. }
  940. contribution.setProportion(Double.valueOf(df.format(value)));
  941. testContribution.add(contribution);
  942. }
  943. test.setTest_contribution(testContribution);
  944. //pipeline
  945. pipeline.setPipeline_deploy(pipeline_deploy);
  946. pipeline.setPipeline_pass(pipeline_pass);
  947. pipeline.setPipline_failure(pipeline_failure);
  948. List<Contribution> deployContribution = new ArrayList<>();
  949. for(int i=0;i<userIds.size();i++){
  950. Contribution contribution = new Contribution();
  951. contribution.setUserId(users.get(i).getUserId());
  952. contribution.setName(users.get(i).getName());
  953. contribution.setTimes(pipeTimes[i]);
  954. Double value;
  955. if(pipeline_deploy == 0){
  956. value = 0.0;
  957. }else {
  958. value = (double)pipeTimes[i]/(double)pipeline_deploy;
  959. }
  960. contribution.setProportion(Double.valueOf(df.format(value)));
  961. deployContribution.add(contribution);
  962. }
  963. pipeline.setPipeline_contribution(deployContribution);
  964. //bugList
  965. bugList.setBug_times(bug_times);
  966. bugList.setHigh_times(high_times);
  967. bugList.setFinished_times(finished_times);
  968. List<Contribution> bugContribution = new ArrayList<>();
  969. for(int i=0;i<userIds.size();i++){
  970. Contribution contribution = new Contribution();
  971. contribution.setUserId(users.get(i).getUserId());
  972. contribution.setName(users.get(i).getName());
  973. contribution.setTimes(bugTimes[i]);
  974. Double value;
  975. if(bug_times == 0){
  976. value = 0.0;
  977. }else {
  978. value = (double)bugTimes[i]/(double)bug_times;
  979. }
  980. contribution.setProportion(Double.valueOf(df.format(value)));
  981. bugContribution.add(contribution);
  982. }
  983. bugList.setBug_contribution(bugContribution);
  984. //treeNode
  985. treeNode.setTreeNode_times(treeNode_times);
  986. treeNode.setHigh_treeNode_times(high_treeNode_times);
  987. treeNode.setFinished_treeNode_times(finished_treeNode_times);
  988. List<Contribution> treeNodeContribution = new ArrayList<>();
  989. for(int i=0;i<userIds.size();i++){
  990. Contribution contribution = new Contribution();
  991. contribution.setUserId(users.get(i).getUserId());
  992. contribution.setName(users.get(i).getName());
  993. contribution.setTimes(treeNodeTimes[i]);
  994. Double value;
  995. if(bug_times == 0){
  996. value = 0.0;
  997. }else {
  998. value = (double)treeNodeTimes[i]/(double)treeNode_times;
  999. }
  1000. contribution.setProportion(Double.valueOf(df.format(value)));
  1001. treeNodeContribution.add(contribution);
  1002. }
  1003. treeNode.setTreeNode_contribution(treeNodeContribution);
  1004. formatGroup.setCommit(commit);
  1005. formatGroup.setTest(test);
  1006. formatGroup.setPipeline(pipeline);
  1007. formatGroup.setBuglist(bugList);
  1008. formatGroup.setTreeNode(treeNode);
  1009. return formatGroup;
  1010. }
  1011. //判断该记录是否为组员提交的方法
  1012. boolean isInGroup(int id,List<Integer> userIds){
  1013. for(Integer userId : userIds){
  1014. // System.out.println("userid: "+userId);
  1015. // System.out.println("now Id: "+id);
  1016. if(userId == id){
  1017. return true;
  1018. }
  1019. }
  1020. return false;
  1021. }
  1022. @Override
  1023. public FormatGroup getProjectAnalysis(Integer project_id){
  1024. //暂时不存在GroupId,先使用ProjectId代替
  1025. FormatGroup formatGroup = new FormatGroup();
  1026. //记录该小组拥有的所有项目的id
  1027. List<Integer> projectList = new ArrayList<>();
  1028. //记录所有项目的信息,用于小组项目信息展示
  1029. List<Project> projects = new ArrayList<>();
  1030. //先将传入的project加入List
  1031. projectList.add(project_id);
  1032. projects.add(projectDao.findById(project_id).get());
  1033. Optional<DevcloudProject> result2 = devcloudProjectDao.findById(project_id);
  1034. if(!result2.isPresent()){
  1035. System.out.println("没有找到项目的成员信息");
  1036. return null;
  1037. }
  1038. List<Integer> userIds = devcloudProjectDao.findById(project_id).get().getUserIds();
  1039. //将所有的成员信息加入
  1040. List<User> users = new ArrayList<>();
  1041. for(int i=0;i<userIds.size();i++){
  1042. Integer userId = userIds.get(i);
  1043. users.add(userDao.findByUserId(userId));
  1044. }
  1045. int n = userIds.size();
  1046. formatGroup.setProjects(projects);
  1047. formatGroup.setStudents(users);
  1048. //放入小组Commit信息,测试信息,流水线信息
  1049. Commit commit = new Commit();
  1050. Test test = new Test();
  1051. Pipeline pipeline = new Pipeline();
  1052. //新增
  1053. Bug bugList = new Bug();
  1054. TreeNode treeNode = new TreeNode();
  1055. Integer commit_times=0,valid_commit_time=0,buglist_commit=0,feature_commit=0;
  1056. //记录小组不同成员的commit贡献
  1057. int[] commitTimes = new int[n];
  1058. List<String> commit_msg_overview = new ArrayList<>();
  1059. Integer test_success=0,test_failure=0,test_times=0,test_concurrency_count=0;
  1060. //记录小组不同成员的test贡献
  1061. int[] testTimes = new int[n];
  1062. Integer pipeline_deploy=0,pipeline_pass=0,pipeline_failure=0;
  1063. //记录小组不同成员的deploy贡献
  1064. int[] pipeTimes = new int[n];
  1065. //新增bugList,treeNode
  1066. Integer bug_times=0,high_times=0,finished_times=0;
  1067. //记录小组不同成员的bugList贡献
  1068. int[] bugTimes = new int[n];
  1069. Integer treeNode_times=0,high_treeNode_times=0,finished_treeNode_times=0;
  1070. //记录小组不同成员的treeNode贡献
  1071. int[] treeNodeTimes = new int[n];
  1072. //遍历所有的项目,将整体信息作为小组的分析情况
  1073. for(int i=0;i<projectList.size();i++){
  1074. Integer projectId = projectList.get(i);
  1075. DevcloudInfo devcloudInfo;
  1076. Optional<DevcloudInfo> result3 = devcloudInfoDao.findById(projectId);
  1077. //如果找不到对应的项目信息则跳过该项目
  1078. if(!result3.isPresent()){
  1079. continue;
  1080. }
  1081. devcloudInfo = devcloudInfoDao.findById(projectId).get();
  1082. //遍历devInfo中的commit信息
  1083. List<CommitInfo> commitInfos = devcloudInfo.getCommitList();
  1084. // System.out.println("commitInfosSize: "+commitInfos.size());
  1085. // commit_times += commitInfos.size();
  1086. for(CommitInfo commitInfo : commitInfos){
  1087. if(commitInfo.getUserId() == null || isInGroup(commitInfo.getUserId(),userIds)==false){
  1088. continue;
  1089. }else{
  1090. commit_times++;
  1091. commit_msg_overview.add(commitInfo.getMessage());
  1092. //如果是需求的commit
  1093. if(commitInfo.getType().toLowerCase().equals("tree_id")||commitInfo.getMessage().startsWith("feat:")){
  1094. feature_commit++;
  1095. }
  1096. //如果是bug_list的commit
  1097. if(commitInfo.getType().toLowerCase().equals("bug_id")||commitInfo.getMessage().startsWith("fix:")){
  1098. buglist_commit++;
  1099. }
  1100. //判断是否是有效的commit
  1101. if(commitInfo.getMessage().startsWith("feat:")||commitInfo.getMessage().startsWith("fix:")){
  1102. valid_commit_time++;
  1103. }
  1104. }
  1105. for(int j=0;j<userIds.size();j++){
  1106. Integer user_id = userIds.get(j);
  1107. if(commitInfo.getUserId() == null) {
  1108. continue;
  1109. }else if(commitInfo.getUserId().equals(user_id)){
  1110. commitTimes[j]++;
  1111. }
  1112. }
  1113. }
  1114. //遍历devInfo中的test信息
  1115. List<TestInfo> testInfos = devcloudInfo.getTestList();
  1116. // test_times += testInfos.size();
  1117. for(TestInfo testInfo : testInfos){
  1118. if(testInfo.getUserId() == null || isInGroup(testInfo.getUserId(),userIds)==false){
  1119. continue;
  1120. }else {
  1121. test_times++;
  1122. test_success += testInfo.getSuccess();
  1123. test_failure += testInfo.getFailure();
  1124. test_concurrency_count += testInfo.getSuccess();
  1125. test_concurrency_count += testInfo.getFailure();
  1126. }
  1127. for(int j=0;j<userIds.size();j++){
  1128. Integer user_id = userIds.get(j);
  1129. if(testInfo.getUserId() == null) {
  1130. continue;
  1131. }else if(testInfo.getUserId().equals(user_id)){
  1132. testTimes[j]++;
  1133. }
  1134. }
  1135. }
  1136. //遍历devInfo中的pipeline信息
  1137. List<PipelineInfo> pipelineInfos = devcloudInfo.getPipelineList();
  1138. for(PipelineInfo pipelineInfo : pipelineInfos){
  1139. //遍历每个流水线中的部署记录
  1140. List<RecordInfo> recordInfos = pipelineInfo.getRecordList();
  1141. for(RecordInfo recordInfo : recordInfos){
  1142. if(recordInfo.getUserId() == null || isInGroup(recordInfo.getUserId(),userIds)==false){
  1143. continue;
  1144. }else {
  1145. pipeline_deploy++;
  1146. if(recordInfo.getResult().equals("部署成功")){
  1147. pipeline_pass++;
  1148. }
  1149. if(recordInfo.getResult().equals("部署失败")){
  1150. pipeline_failure++;
  1151. }
  1152. }
  1153. for(int j=0;j<userIds.size();j++){
  1154. Integer user_id = userIds.get(j);
  1155. if(recordInfo.getUserId() == null) {
  1156. continue;
  1157. }else if(recordInfo.getUserId().equals(user_id)){
  1158. pipeTimes[j]++;
  1159. }
  1160. }
  1161. }
  1162. }
  1163. //遍历devInfo中的bugList信息
  1164. List<BugInfo> bugInfos = devcloudInfo.getBugList();
  1165. for(BugInfo bugInfo : bugInfos){
  1166. if(bugInfo.getUserId() == null || isInGroup(bugInfo.getUserId(),userIds)==false){
  1167. continue;
  1168. }else {
  1169. bug_times++;
  1170. if(bugInfo.getPriority().toLowerCase().equals("high")){
  1171. high_times++;
  1172. }
  1173. if(bugInfo.getBugState().toLowerCase().equals("finished")){
  1174. finished_times++;
  1175. }
  1176. }
  1177. for(int j=0;j<userIds.size();j++){
  1178. Integer user_id = userIds.get(j);
  1179. if(bugInfo.getUserId() == null){
  1180. continue;
  1181. }else if(bugInfo.getUserId().equals(user_id)){
  1182. bugTimes[j]++;
  1183. }
  1184. }
  1185. }
  1186. //遍历devInfo的treeNode信息
  1187. List<TreeNodeInfo> treeNodeInfos = devcloudInfo.getTreeNodeList();
  1188. for(TreeNodeInfo treeNodeInfo : treeNodeInfos){
  1189. if(treeNodeInfo.getUserId() == null || isInGroup(treeNodeInfo.getUserId(),userIds)==false){
  1190. continue;
  1191. }else {
  1192. treeNode_times++;
  1193. if(treeNodeInfo.getPriority().toLowerCase().equals("high")){
  1194. high_treeNode_times++;
  1195. }
  1196. if(treeNodeInfo.getState().toLowerCase().equals("finished")){
  1197. finished_treeNode_times++;
  1198. }
  1199. }
  1200. for(int j=0;j<userIds.size();j++){
  1201. Integer user_id = userIds.get(j);
  1202. if(treeNodeInfo.getUserId() == null){
  1203. continue;
  1204. }else if(treeNodeInfo.getUserId().equals(user_id)){
  1205. treeNodeTimes[j]++;
  1206. }
  1207. }
  1208. }
  1209. }
  1210. DecimalFormat df = new DecimalFormat("#.00");
  1211. //commit
  1212. commit.setCommit_times(commit_times);
  1213. commit.setValid_commit_times(valid_commit_time);
  1214. commit.setBuglist_commit(buglist_commit);
  1215. commit.setFeature_commit(feature_commit);
  1216. commit.setCommit_msg_overview(commit_msg_overview);
  1217. List<Contribution> commitContribution = new ArrayList<>();
  1218. for(int i=0;i<userIds.size();i++){
  1219. Contribution contribution = new Contribution();
  1220. contribution.setUserId(users.get(i).getUserId());
  1221. contribution.setName(users.get(i).getName());
  1222. contribution.setTimes(commitTimes[i]);
  1223. Double value;
  1224. if(commit_times == 0){
  1225. value = 0.0;
  1226. }else {
  1227. value = (double)commitTimes[i]/(double)commit_times;
  1228. }
  1229. contribution.setProportion(Double.valueOf(df.format(value)));
  1230. commitContribution.add(contribution);
  1231. }
  1232. commit.setCommit_contribution(commitContribution);
  1233. //test
  1234. test.setTest_times(test_times);
  1235. test.setTest_concurrency_count(test_concurrency_count);
  1236. test.setTest_concurrency_success(test_success);
  1237. test.setTest_concurrency_failure(test_failure);
  1238. List<Contribution> testContribution = new ArrayList<>();
  1239. for(int i=0;i<userIds.size();i++){
  1240. Contribution contribution = new Contribution();
  1241. contribution.setUserId(users.get(i).getUserId());
  1242. contribution.setName(users.get(i).getName());
  1243. contribution.setTimes(testTimes[i]);
  1244. Double value;
  1245. if(test_times == 0){
  1246. value = 0.0;
  1247. }else {
  1248. value = (double)testTimes[i]/(double)test_times;
  1249. }
  1250. contribution.setProportion(Double.valueOf(df.format(value)));
  1251. testContribution.add(contribution);
  1252. }
  1253. test.setTest_contribution(testContribution);
  1254. //pipeline
  1255. pipeline.setPipeline_deploy(pipeline_deploy);
  1256. pipeline.setPipeline_pass(pipeline_pass);
  1257. pipeline.setPipline_failure(pipeline_failure);
  1258. List<Contribution> deployContribution = new ArrayList<>();
  1259. for(int i=0;i<userIds.size();i++){
  1260. Contribution contribution = new Contribution();
  1261. contribution.setUserId(users.get(i).getUserId());
  1262. contribution.setName(users.get(i).getName());
  1263. contribution.setTimes(pipeTimes[i]);
  1264. Double value;
  1265. if(pipeline_deploy == 0){
  1266. value = 0.0;
  1267. }else {
  1268. value = (double)pipeTimes[i]/(double)pipeline_deploy;
  1269. }
  1270. contribution.setProportion(Double.valueOf(df.format(value)));
  1271. deployContribution.add(contribution);
  1272. }
  1273. pipeline.setPipeline_contribution(deployContribution);
  1274. //bugList
  1275. bugList.setBug_times(bug_times);
  1276. bugList.setHigh_times(high_times);
  1277. bugList.setFinished_times(finished_times);
  1278. List<Contribution> bugContribution = new ArrayList<>();
  1279. for(int i=0;i<userIds.size();i++){
  1280. Contribution contribution = new Contribution();
  1281. contribution.setUserId(users.get(i).getUserId());
  1282. contribution.setName(users.get(i).getName());
  1283. contribution.setTimes(bugTimes[i]);
  1284. Double value;
  1285. if(bug_times == 0){
  1286. value = 0.0;
  1287. }else {
  1288. value = (double)bugTimes[i]/(double)bug_times;
  1289. }
  1290. contribution.setProportion(Double.valueOf(df.format(value)));
  1291. bugContribution.add(contribution);
  1292. }
  1293. bugList.setBug_contribution(bugContribution);
  1294. //treeNode
  1295. treeNode.setTreeNode_times(treeNode_times);
  1296. treeNode.setHigh_treeNode_times(high_treeNode_times);
  1297. treeNode.setFinished_treeNode_times(finished_treeNode_times);
  1298. List<Contribution> treeNodeContribution = new ArrayList<>();
  1299. for(int i=0;i<userIds.size();i++){
  1300. Contribution contribution = new Contribution();
  1301. contribution.setUserId(users.get(i).getUserId());
  1302. contribution.setName(users.get(i).getName());
  1303. contribution.setTimes(treeNodeTimes[i]);
  1304. Double value;
  1305. if(bug_times == 0){
  1306. value = 0.0;
  1307. }else {
  1308. value = (double)treeNodeTimes[i]/(double)treeNode_times;
  1309. }
  1310. contribution.setProportion(Double.valueOf(df.format(value)));
  1311. treeNodeContribution.add(contribution);
  1312. }
  1313. treeNode.setTreeNode_contribution(treeNodeContribution);
  1314. formatGroup.setCommit(commit);
  1315. formatGroup.setTest(test);
  1316. formatGroup.setPipeline(pipeline);
  1317. formatGroup.setBuglist(bugList);
  1318. formatGroup.setTreeNode(treeNode);
  1319. return formatGroup;
  1320. }
  1321. }