/src/backend/codecc/core/defect/biz-defect/src/main/java/com/tencent/bk/codecc/defect/dao/mongorepository/DefectRepository.java

https://github.com/Tencent/bk-ci · Java · 143 lines · 31 code · 14 blank · 98 comment · 0 complexity · 1debe39ffa7ec9450ee3e7fec6132c45 MD5 · raw file

  1. /*
  2. * Tencent is pleased to support the open source community by making BK-CODECC 蓝鲸代码检查平台 available.
  3. *
  4. * Copyright (C) 2019 THL A29 Limited, a Tencent company. All rights reserved.
  5. *
  6. * BK-CODECC 蓝鲸代码检查平台 is licensed under the MIT license.
  7. *
  8. * A copy of the MIT License is included in this file.
  9. *
  10. *
  11. * Terms of the MIT License:
  12. * ---------------------------------------------------
  13. * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation
  14. * files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy,
  15. * modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the
  16. * Software is furnished to do so, subject to the following conditions:
  17. *
  18. * The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
  19. *
  20. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT
  21. * LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
  22. * NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
  23. * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
  24. * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  25. */
  26. package com.tencent.bk.codecc.defect.dao.mongorepository;
  27. import com.tencent.bk.codecc.defect.model.DefectEntity;
  28. import org.springframework.data.domain.Page;
  29. import org.springframework.data.domain.Pageable;
  30. import org.springframework.data.mongodb.repository.MongoRepository;
  31. import org.springframework.data.mongodb.repository.Query;
  32. import org.springframework.stereotype.Repository;
  33. import java.util.Collection;
  34. import java.util.List;
  35. import java.util.Set;
  36. /**
  37. * 告警查询持久代码
  38. *
  39. * @version V1.0
  40. * @date 2019/10/20
  41. */
  42. @Repository
  43. public interface DefectRepository extends MongoRepository<DefectEntity, String>
  44. {
  45. /**
  46. * 通过实体id查询告警信息
  47. *
  48. * @param entityId
  49. * @return
  50. */
  51. DefectEntity findByEntityId(String entityId);
  52. /**
  53. * 通过任务id,工具名查询告警信息
  54. *
  55. * @param taskId
  56. * @param toolName
  57. * @return
  58. */
  59. List<DefectEntity> findByTaskIdAndToolName(long taskId, String toolName);
  60. /**
  61. * 通过任务id,工具名和状态查询告警信息
  62. *
  63. * @param taskId
  64. * @param toolName
  65. * @param status
  66. * @return
  67. */
  68. List<DefectEntity> findByTaskIdAndToolNameAndStatus(long taskId, String toolName, int status);
  69. /**
  70. * 根据taskId,工具名查询所有的告警ID
  71. *
  72. * @param taskId
  73. * @param toolName
  74. * @return
  75. */
  76. @Query(fields = "{'id':1}", value = "{'task_id': ?0, 'tool_name': ?1}")
  77. List<DefectEntity> findIdsByTaskIdAndToolName(long taskId, String toolName);
  78. /**
  79. * 通过任务id,工具名查询告警信息
  80. *
  81. * @param taskId
  82. * @param toolName
  83. * @return
  84. */
  85. @Query(fields = "{'id':1, 'status':1, 'author_list':1, 'severity':1, 'file_path_name':1, 'exclude_time':1}", value = "{'task_id': ?0, 'tool_name': ?1, 'id': {'$in': ?2}}")
  86. List<DefectEntity> findStatusAndAuthorAndSeverityByTaskIdAndToolNameAndIdIn(long taskId, String toolName, Set<String> idSet);
  87. /**
  88. * 通过任务id,工具名查询告警信息
  89. *
  90. * @param taskId
  91. * @param toolName
  92. * @return
  93. */
  94. @Query(value = "{'task_id': ?0, 'tool_name': ?1, 'id': {'$in': ?2}}")
  95. List<DefectEntity> findByTaskIdAndToolNameAndIdIn(long taskId, String toolName, Set<String> idSet);
  96. /**
  97. * 根据entityIdSet查询告警信息
  98. *
  99. * @param entityIdSet
  100. * @return
  101. */
  102. @Query(fields = "{'id':1, 'status':1}", value = "{'_id': {'$in': ?0}}")
  103. List<DefectEntity> findStatusByEntityIdIn(Set<String> entityIdSet);
  104. /**
  105. * 根据规则名和任务id查询
  106. * @param checkerName
  107. * @param taskId
  108. * @return
  109. */
  110. Page<DefectEntity> findByCheckerNameInAndTaskIdIn(List<String> checkerName, List<Long> taskId, Pageable pageable);
  111. /**
  112. * 根据规则名查询
  113. * @param checkerName
  114. * @return
  115. */
  116. Page<DefectEntity> findByCheckerNameIn(List<String> checkerName, Pageable pageable);
  117. /**
  118. * 获取批量任务、规则名范围的告警数据
  119. *
  120. * @param toolName 工具名称
  121. * @param taskIdSet 任务ID集合
  122. * @param checkerNameSet 规则名集合
  123. * @return entity list
  124. */
  125. @Query(fields = "{'stream_name':0, 'display_category':0, 'display_type':0}",
  126. value = "{'tool_name': ?0, 'task_id': {'$in': ?1}, 'checker_name': {'$in': ?2}}")
  127. List<DefectEntity> findByToolNameAndTaskIdInAndCheckerNameIn(String toolName, Collection<Long> taskIdSet,
  128. Set<String> checkerNameSet);
  129. }