123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051 |
- #encoding:UTF8
- from BaseDataMaintenance.model.ots.BaseModel import BaseModel
- from tablestore import *
- from BaseDataMaintenance.common.Utils import *
- class designed_project(BaseModel):
- def __init__(self,_dict):
- for k,v in _dict.items():
- self.setValue(k,v,True)
- self.table_name = "designed_project"
- def getPrimary_keys(self):
- return ["partitionkey","id"]
- def search_by_docids(self,ots_client,docids):
- should_q = []
- for _docid in docids.split(","):
- should_q.append(TermQuery("docids",_docid))
- bool_query = BoolQuery(should_queries=should_q)
- columns = ["docids"]
- rows, next_token, total_count, is_all_succeed = ots_client.search("designed_project", "designed_project_index",
- SearchQuery(bool_query, limit=100,get_total_count=True),
- ColumnsToGet(columns,return_type=ColumnReturnType.SPECIFIED))
- list_dict = getRow_ots(rows)
- return list_dict
- def update_project(self,ots_client):
- docids = self.__dict__.get("docids")
- #判断是否有存量生成项目,有则更新且删除多余的
- list_dict = self.search_by_docids(ots_client,docids)
- if len(list_dict)>0:
- for _dict in list_dict[1:]:
- _designed_delete = designed_project(_dict)
- _designed_delete.delete_row(ots_client)
- _designed_update = designed_project(list_dict[0])
- properties = _designed_update.getProperties()
- _partitionkey = properties.get("partitionkey")
- _id = properties.get("id")
- self.setProperties("partitionkey",_partitionkey)
- self.setProperties("id",_id)
- self.update_row(ots_client)
- if __name__=="__main__":
- pass
|