designed_project.py 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. #encoding:UTF8
  2. from BaseDataMaintenance.model.ots.BaseModel import BaseModel
  3. from tablestore import *
  4. from BaseDataMaintenance.common.Utils import *
  5. class designed_project(BaseModel):
  6. def __init__(self,_dict):
  7. for k,v in _dict.items():
  8. self.setValue(k,v,True)
  9. self.table_name = "designed_project"
  10. def getPrimary_keys(self):
  11. return ["partitionkey","id"]
  12. def search_by_docids(self,ots_client,docids):
  13. should_q = []
  14. for _docid in docids.split(","):
  15. should_q.append(TermQuery("docids",_docid))
  16. bool_query = BoolQuery(should_queries=should_q)
  17. columns = ["docids"]
  18. rows, next_token, total_count, is_all_succeed = ots_client.search("designed_project", "designed_project_index",
  19. SearchQuery(bool_query, limit=100,get_total_count=True),
  20. ColumnsToGet(columns,return_type=ColumnReturnType.SPECIFIED))
  21. list_dict = getRow_ots(rows)
  22. return list_dict
  23. def update_project(self,ots_client):
  24. docids = self.__dict__.get("docids")
  25. #判断是否有存量生成项目,有则更新且删除多余的
  26. list_dict = self.search_by_docids(ots_client,docids)
  27. if len(list_dict)>0:
  28. for _dict in list_dict[1:]:
  29. _designed_delete = designed_project(_dict)
  30. _designed_delete.delete_row(ots_client)
  31. _designed_update = designed_project(list_dict[0])
  32. properties = _designed_update.getProperties()
  33. _partitionkey = properties.get("partitionkey")
  34. _id = properties.get("id")
  35. self.setProperties("partitionkey",_partitionkey)
  36. self.setProperties("id",_id)
  37. self.update_row(ots_client)
  38. if __name__=="__main__":
  39. pass