AbstractRelationObject.java 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. package com.persagy.proxy.adm.strategy.relationdata;
  2. import java.util.List;
  3. import java.util.Set;
  4. import com.fasterxml.jackson.databind.node.ObjectNode;
  5. import com.persagy.dmp.basic.dto.RequestData;
  6. import com.persagy.dmp.common.model.response.CommonResult;
  7. import com.persagy.dmp.digital.client.DigitalObjectFacade;
  8. import com.persagy.dmp.digital.client.DigitalRelationFacade;
  9. import com.persagy.dmp.digital.entity.ObjectDigital;
  10. import com.persagy.dmp.digital.entity.ObjectRelation;
  11. import com.persagy.proxy.adm.constant.AdmCommonConstant;
  12. import com.persagy.proxy.adm.constant.AdmRelationTypeEnum;
  13. import com.persagy.proxy.report.model.AdmRelationObject;
  14. import com.persagy.proxy.report.service.IRelationReportService;
  15. import cn.hutool.core.collection.CollectionUtil;
  16. /**
  17. * 普通操作抽象类
  18. *
  19. * @version 1.0.0
  20. * @company persagy
  21. * @author zhangqiankun
  22. * @date 2021年9月2日 下午11:00:26
  23. */
  24. public abstract class AbstractRelationObject implements RelationObjectStrategy {
  25. protected IRelationReportService relationReportService;
  26. public AbstractRelationObject(IRelationReportService reportDownloadService) {
  27. this.relationReportService = reportDownloadService;
  28. }
  29. @Override
  30. public long countRelationObjects(String groupCode, String projectId, AdmRelationTypeEnum typeEnum) {
  31. return this.countRelationObjects(groupCode, projectId);
  32. }
  33. /**
  34. * 统计关系总数
  35. *
  36. * @param groupCode
  37. * @param projectId
  38. * @return
  39. */
  40. protected abstract long countRelationObjects(String groupCode, String projectId);
  41. @Override
  42. public List<ObjectDigital> queryAllRelations(String groupCode, String projectId, String mainContent, Set<String> slaveContent, AdmRelationTypeEnum typeEnum) {
  43. return this.queryAllRelations(groupCode, projectId, mainContent, slaveContent);
  44. }
  45. /**
  46. * 查询出所有的关系对象数据
  47. *
  48. * @param groupCode 集团编码
  49. * @param projectId 项目ID
  50. * @param mainContent 主对象的筛选关键字,筛选范围为id,name,local_id,local_name,cADID.为关系左侧对象
  51. * @param slaveContent 从对象的筛选关键字.objTo对应的对象,筛选范围为id,name,local_id,local_name.为关系右侧对象
  52. * @return 不会返回null
  53. */
  54. protected abstract List<ObjectDigital> queryAllRelations(String groupCode, String projectId, String mainContent, Set<String> slaveContent);
  55. @Override
  56. public void queryPageRelations(List<ObjectDigital> allDigitals, RequestData requestData, String groupCode, String projectId) {
  57. CommonResult<List<ObjectDigital>> queryPrototype = DigitalObjectFacade.queryObjectListByGraphCodeAndRelCodePrototype(groupCode, projectId, AdmCommonConstant.APP_ID, AdmCommonConstant.USER_ID, requestData);
  58. Long count = queryPrototype.getCount();
  59. List<ObjectDigital> infos = queryPrototype.getData();
  60. if (count == null || CollectionUtil.isEmpty(infos)) {
  61. return;
  62. }
  63. allDigitals.addAll(infos);
  64. if (count < 500) {
  65. return;
  66. } else if ((infos.size()*requestData.getPage()) > count) {
  67. return;
  68. } else {
  69. requestData.setPage((requestData.getPage() + 1));
  70. this.queryPageRelations(allDigitals, requestData, groupCode, projectId);
  71. }
  72. }
  73. @Override
  74. public boolean saveRelationObject(ObjectNode relationObject, String groupCode, String projectId) {
  75. ObjectRelation objectRelation = DigitalRelationFacade.createOne(groupCode, projectId, AdmCommonConstant.APP_ID, AdmCommonConstant.USER_ID, relationObject);
  76. return objectRelation != null;
  77. }
  78. @Override
  79. public boolean saveRelationObjects(List<ObjectNode> relationObjects, String groupCode, String projectId) {
  80. List<ObjectRelation> create = DigitalRelationFacade.create(groupCode, projectId, AdmCommonConstant.APP_ID, AdmCommonConstant.USER_ID, relationObjects);
  81. return CollectionUtil.isNotEmpty(create);
  82. }
  83. /**************************************************** 默认不实现的类 *******************************************************/
  84. @Override
  85. public List<AdmRelationObject> exportRelationObject(String groupCode, String projectId) {
  86. throw new UnsupportedOperationException("未实现的策略方法");
  87. }
  88. @Override
  89. public Object beforeSaveRelationObject(AdmRelationObject relationObject, String groupCode, String projectId, String code, AdmRelationTypeEnum typeEnum) {
  90. return this.beforeSaveRelationObject(relationObject, groupCode, projectId, code);
  91. }
  92. protected Object beforeSaveRelationObject(AdmRelationObject relationObject, String groupCode, String projectId, String code) {
  93. throw new UnsupportedOperationException("未实现的策略方法");
  94. }
  95. }