/src/backend/codecc/core/task/biz-task/src/main/java/com/tencent/bk/codecc/task/dao/mongotemplate/GongfengStatProjDao.java

https://github.com/Tencent/bk-ci · Java · 96 lines · 49 code · 11 blank · 36 comment · 2 complexity · bd760ab51e854a230aed311451c4e9d3 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.task.dao.mongotemplate;
  27. import com.tencent.bk.codecc.task.model.GongfengStatProjEntity;
  28. import org.apache.commons.collections.CollectionUtils;
  29. import org.springframework.beans.factory.annotation.Autowired;
  30. import org.springframework.data.mongodb.core.BulkOperations;
  31. import org.springframework.data.mongodb.core.MongoTemplate;
  32. import org.springframework.data.mongodb.core.query.Criteria;
  33. import org.springframework.data.mongodb.core.query.Query;
  34. import org.springframework.data.mongodb.core.query.Update;
  35. import org.springframework.stereotype.Repository;
  36. import java.util.List;
  37. /**
  38. * 工蜂度量数据存取对象
  39. *
  40. * @version V1.1
  41. * @date 2020/3/24
  42. */
  43. @Repository
  44. public class GongfengStatProjDao
  45. {
  46. @Autowired
  47. private MongoTemplate mongoTemplate;
  48. /**
  49. * 插入和更新工蜂度量项目数据
  50. *
  51. * @param statProjectList entityList
  52. */
  53. public void upsertGongfengStatProjList(List<GongfengStatProjEntity> statProjectList)
  54. {
  55. BulkOperations ops = mongoTemplate.bulkOps(BulkOperations.BulkMode.UNORDERED, GongfengStatProjEntity.class);
  56. if (CollectionUtils.isNotEmpty(statProjectList))
  57. {
  58. for (GongfengStatProjEntity statProjEntity : statProjectList)
  59. {
  60. Query query = new Query();
  61. Criteria criteria = Criteria.where("id").is(statProjEntity.getId());
  62. query.addCriteria(criteria);
  63. Update update = new Update();
  64. update.set("id", statProjEntity.getId())
  65. .set("bg_id", statProjEntity.getBgId())
  66. .set("org_paths", statProjEntity.getOrgPaths())
  67. .set("path", statProjEntity.getPath())
  68. .set("description", statProjEntity.getDescription())
  69. .set("visibility", statProjEntity.getVisibility())
  70. .set("visibility_level", statProjEntity.getVisibilityLevel())
  71. .set("belong", statProjEntity.getBelong())
  72. .set("owners", statProjEntity.getOwners())
  73. .set("created_at", statProjEntity.getCreatedAt())
  74. .set("creator", statProjEntity.getCreator())
  75. .set("url", statProjEntity.getUrl())
  76. .set("archived", statProjEntity.getArchived())
  77. .set("is_sensitive", statProjEntity.getIsSensitive())
  78. .set("sensitive_reason", statProjEntity.getSensitiveReason())
  79. .set("public_visibility", statProjEntity.getPublicVisibility());
  80. ops.upsert(query, update);
  81. }
  82. ops.execute();
  83. }
  84. }
  85. }