client.py 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164
  1. # coding:utf-8
  2. import time
  3. from a2s.tools import json_serialize, json_deserialize
  4. from a2s.a2s_client import a2s_execute
  5. from docs.config import ReluMongodb
  6. from util.mogodb_helper import MongoDBInterface
  7. from pymongo import MongoClient
  8. from bson import ObjectId
  9. ReluClient = MongoDBInterface(ReluMongodb)
  10. # 评估服务配置
  11. a2s_ip = "192.168.3.240:9090"
  12. topic = "quality_bid"
  13. #本地测试用的主题
  14. # topic = "test_quality_bid"
  15. timeout = 120
  16. # 开始评估
  17. def start_quality(data: dict, rules_id: int, a2s_ip, topic, timeout, retry=3):
  18. # 本次不使用SSL,所以channel是不安全的
  19. row = {"data": data, "rules_id": rules_id}
  20. bytes_data = json_serialize(row)
  21. for t in range(retry):
  22. try:
  23. resp_data = a2s_execute(a2s_ip, topic, timeout, bytes_data)
  24. if resp_data is None:
  25. continue
  26. result = json_deserialize(resp_data)
  27. return result
  28. except Exception as e:
  29. print(e)
  30. return {}
  31. # 获取规则ID
  32. def get_rule(company, version):
  33. rule_id = ReluClient.find_rule_by_company(ReluMongodb["col"], company, version)
  34. return rule_id
  35. def batch_load_purchasinglist():
  36. """
  37. 批量数据质量检查
  38. """
  39. # 规则查询,根据必要条件 公司名称(用户ID)、版本号
  40. rules_id = get_rule("北京剑鱼信息技术有限公司", "v1.1")
  41. print(rules_id)
  42. # max_id = ObjectId("0" * 24)
  43. max_id = ObjectId("5f8e5e1650cded0641ae3f7e")
  44. while True:
  45. # db = MongoClient('192.168.3.71', 29099, unicode_decode_error_handler="ignore").re4art
  46. # coll_user = db["zc_classify_test"]
  47. db = MongoClient('192.168.3.166', 27082, unicode_decode_error_handler="ignore").zhengluming_27082
  48. coll_user = db["update_data"]
  49. num=0
  50. try:
  51. # for item in coll_user.find({"_id":{"$gte":max_id}}).sort("_id",1):
  52. for item in coll_user.find({"_id":ObjectId("60f84adf1a75b8f4460ead47")}):
  53. # for item in coll_user.find().sort("_id",1):
  54. max_id = item["_id"]
  55. print(max_id)
  56. purchasinglist =item.get("purchasinglist")
  57. purchasingsource =item.get("purchasingsource")
  58. #不存在标的物
  59. if not (purchasinglist and purchasingsource):
  60. continue
  61. item["_id"] = str(item["_id"])
  62. # item['detail']=item['details'].replace("\\\"", "\"")
  63. result = start_quality(item, rules_id, a2s_ip, topic, timeout)
  64. print(result)
  65. # 示例:result:{'code': 200, 'msg': '成功', 'data': {'title_qa': {'0201': '非汉字占比>55%'}}}
  66. code=result.get("code")
  67. if code!=200:
  68. #数据出错
  69. coll_user.update_one({"_id": max_id}, {"$set": {"flag": 1}})
  70. continue
  71. data=result.get("data",{})
  72. # coll_user.update_one({"_id":max_id},{"$set":{"data":data}})
  73. coll_user.update_one({"_id":max_id},{"$set":data})
  74. break
  75. except Exception as e:
  76. print(e)
  77. time.sleep(10)
  78. continue
  79. def batch_load_data():
  80. """
  81. 批量数据质量检查
  82. """
  83. # 规则查询,根据必要条件 公司名称(用户ID)、版本号
  84. rules_id = get_rule("北京剑鱼信息技术有限公司", "v1.2")
  85. print(rules_id)
  86. max_id = ObjectId("0" * 24)
  87. # max_id = ObjectId("655ec5609aed6eb2ffa654ca")
  88. while True:
  89. db = MongoClient('192.168.3.206', 27080, unicode_decode_error_handler="ignore").data_quality
  90. coll_user = db["bidding_20231221"]
  91. # db = MongoClient('192.168.3.166', 27082, unicode_decode_error_handler="ignore").zhengluming_27082
  92. # coll_user = db["update_data"]
  93. try:
  94. for item in coll_user.find({"_id":{"$gte":max_id}}).sort("_id",1):
  95. # for item in coll_user.find({"_id":ObjectId("655ec5579aed6eb2ffa63d6d")}):
  96. # for item in coll_user.find().sort("_id",1):
  97. max_id = item["_id"]
  98. print(max_id)
  99. item["_id"] = str(item["_id"])
  100. # item['detail']=item['details'].replace("\\\"", "\"")
  101. result = start_quality(item, rules_id, a2s_ip, topic, timeout)
  102. print(result)
  103. # 示例:result:{'code': 200, 'msg': '成功', 'data': {'title_qa': {'0201': '非汉字占比>55%'}}}
  104. code=result.get("code")
  105. if code!=200:
  106. #数据出错
  107. coll_user.update_one({"_id":max_id},{"$set":{"flag":1}})
  108. continue
  109. data=result.get("data",{})
  110. # coll_user.update_one({"_id":max_id},{"$set":{"data":data}})
  111. coll_user.update_one({"_id":max_id},{"$set":data})
  112. break
  113. except Exception as e:
  114. print(e)
  115. time.sleep(10)
  116. continue
  117. def batch_load_data_test():
  118. """
  119. 批量数据质量检查本地测试
  120. :return:
  121. """
  122. row_data = {
  123. "title":"你好周杰伦成交通知书...采购计划任务",
  124. "winner": "第一峡江县文化广电新闻出版旅游局",
  125. "detail": "一、采购人名称: 峡江县文化广电新闻出版旅游局 <br/> 二、供应商名称: 中国广电江西网络有限公司峡江县分公司 <br/> 四、中标金额: 140万 <br/> 三、采购项目名称: 峡江县文化广电新闻出版旅游局服务工程项目 <br/> 四、采购项目编号: 2881401000001829192 <br/> 五、合同编号: 2023M0816360823000201 <br/> 六、合同内容:<br/> <table> <tbody><tr> <td>序号</td> <td>标项名称</td> <td>规格型号</td> <td>单位</td> <td>数量</td> <td>单价(元)</td> <td colspan=\"1\">总123价(元)</td> </tr> <tr> <td>1</td> <td>有线电视 宽带网络安装 通信系统工程</td> <td></td> <td>项</td> <td>1.00</td> <td>30416</td> <td colspan=\"1\">30416</td> </tr> </tbody></table><br/> <br/> 服务要求或标的基本概况: <br/> 七、其它事项:<br/> / <br/> 八、联系方式<br/> 1、 采购人名称: 峡江县文化广电新闻出版旅游局 <br/> 联系人: 傅昕尧 <br/> 联系电话: 1569022**** <br/> 传真: <br/> 地址: 玉华路71号 <br/> 2、供应商名称: 中国广电江西网络有限公司峡江县分公司 <br/> 地址: 江西省吉安市峡江县江西省吉安市峡江县文化广播电视局 <br/>附件信息:<br/>关于通信系统工程的服务工程合同(2023M0816360823000201).pdf",
  126. "buyer": "文化广电新闻出版旅游局",
  127. "budget": 3100,
  128. "subtype":"中标",
  129. "projectcode": "3333",
  130. "buyerclass":"学校"
  131. }
  132. # 规则查询,根据必要条件 公司名称(用户ID)、版本号
  133. rules_id = get_rule("北京剑鱼信息技术有限公司", "v1.0")
  134. print(rules_id)
  135. # 评估调用
  136. result = start_quality(row_data, rules_id, a2s_ip, topic, timeout)
  137. print(result)
  138. def batch_load_data_debug():
  139. # 规则查询,根据必要条件 公司名称(用户ID)、版本号
  140. rules_id = get_rule("北京剑鱼信息技术有限公司", "v1.2")
  141. print(rules_id)
  142. db = MongoClient('192.168.3.206', 27080, unicode_decode_error_handler="ignore").data_quality
  143. coll_user = db["bidding_20231122"]
  144. for item in coll_user.find({"_id": ObjectId("655ec5319aed6eb2ffa5d7ce")}):
  145. # item['detail'] = item['details'].replace("\\\"", "\"")
  146. item["_id"] = str(item["_id"])
  147. result = start_quality(item, rules_id, a2s_ip, topic, timeout)
  148. print(result)
  149. if __name__ == '__main__':
  150. batch_load_data()
  151. # batch_load_data_test()
  152. # batch_load_data_debug()
  153. # batch_load_purchasinglist()#标的物检查函数