client.py 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  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. timeout = 120
  14. # 开始评估
  15. def start_quality(data: dict, rules_id: int, a2s_ip, topic, timeout, retry=3):
  16. # 本次不使用SSL,所以channel是不安全的
  17. row = {"data": data, "rules_id": rules_id}
  18. bytes_data = json_serialize(row)
  19. for t in range(retry):
  20. try:
  21. resp_data = a2s_execute(a2s_ip, topic, timeout, bytes_data)
  22. if resp_data is None:
  23. continue
  24. result = json_deserialize(resp_data)
  25. return result
  26. except Exception as e:
  27. print(e)
  28. return {}
  29. # 获取规则ID
  30. def get_rule(company, version):
  31. rule_id = ReluClient.find_rule_by_company(ReluMongodb["col"], company, version)
  32. return rule_id
  33. def batch_load_purchasinglist():
  34. """
  35. 批量数据质量检查
  36. """
  37. # 规则查询,根据必要条件 公司名称(用户ID)、版本号
  38. rules_id = get_rule("北京剑鱼信息技术有限公司", "v1.1")
  39. print(rules_id)
  40. # max_id = ObjectId("0" * 24)
  41. max_id = ObjectId("5f164bf552c1d9fbf8437ce0")
  42. while True:
  43. # db = MongoClient('192.168.3.71', 29099, unicode_decode_error_handler="ignore").re4art
  44. # coll_user = db["zc_classify_test"]
  45. db = MongoClient('192.168.3.166', 27082, unicode_decode_error_handler="ignore").zhengluming_27082
  46. coll_user = db["update_data"]
  47. num=0
  48. try:
  49. for item in coll_user.find({"_id":{"$gte":max_id}}).sort("_id",1):
  50. # for item in coll_user.find({"_id":ObjectId("652526dfe17a7c80fb06658a")}):
  51. # for item in coll_user.find().sort("_id",1):
  52. max_id = item["_id"]
  53. print(max_id)
  54. purchasinglist =item.get("purchasinglist")
  55. purchasingsource =item.get("purchasingsource")
  56. #不存在标的物
  57. if not (purchasinglist and purchasingsource):
  58. continue
  59. item["_id"] = str(item["_id"])
  60. # item['detail']=item['details'].replace("\\\"", "\"")
  61. result = start_quality(item, rules_id, a2s_ip, topic, timeout)
  62. print(result)
  63. # 示例:result:{'code': 200, 'msg': '成功', 'data': {'title_qa': {'0201': '非汉字占比>55%'}}}
  64. code=result.get("code")
  65. if code!=200:
  66. #数据出错
  67. continue
  68. data=result.get("data",{})
  69. # coll_user.update_one({"_id":max_id},{"$set":{"data":data}})
  70. coll_user.update_one({"_id":max_id},{"$set":data})
  71. break
  72. except Exception as e:
  73. print(e)
  74. time.sleep(10)
  75. continue
  76. def batch_load_data():
  77. """
  78. 批量数据质量检查
  79. """
  80. # 规则查询,根据必要条件 公司名称(用户ID)、版本号
  81. rules_id = get_rule("北京剑鱼信息技术有限公司", "v1.1")
  82. print(rules_id)
  83. # max_id = ObjectId("0" * 24)
  84. max_id = ObjectId("65409048dd24231d52d9e89c")
  85. while True:
  86. # db = MongoClient('192.168.3.71', 29099, unicode_decode_error_handler="ignore").re4art
  87. # coll_user = db["zc_classify_test"]
  88. db = MongoClient('192.168.3.166', 27082, unicode_decode_error_handler="ignore").zhengluming
  89. coll_user = db["f_sourceinfo_HP_channel_succes_data"]
  90. num=0
  91. try:
  92. for item in coll_user.find({"_id":{"$gte":max_id}}).sort("_id",1):
  93. # for item in coll_user.find({"_id":ObjectId("652526dfe17a7c80fb06658a")}):
  94. # for item in coll_user.find().sort("_id",1):
  95. max_id = item["_id"]
  96. print(max_id)
  97. item["_id"] = str(item["_id"])
  98. # item['detail']=item['details'].replace("\\\"", "\"")
  99. result = start_quality(item, rules_id, a2s_ip, topic, timeout)
  100. print(result)
  101. # 示例:result:{'code': 200, 'msg': '成功', 'data': {'title_qa': {'0201': '非汉字占比>55%'}}}
  102. code=result.get("code")
  103. if code!=200:
  104. #数据出错
  105. continue
  106. data=result.get("data",{})
  107. # coll_user.update_one({"_id":max_id},{"$set":{"data":data}})
  108. coll_user.update_one({"_id":max_id},{"$set":data})
  109. break
  110. except Exception as e:
  111. print(e)
  112. time.sleep(10)
  113. continue
  114. def batch_load_data_test():
  115. """
  116. 批量数据质量检查本地测试
  117. :return:
  118. """
  119. row_data = {
  120. "title":"你好周杰伦成交通知书采购计划任务",
  121. "winner": "第一峡江县文化广电新闻出版旅游局",
  122. "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",
  123. "buyer": "文化广电新闻出版旅游局",
  124. "budget": 3100,
  125. "subtype":"中标",
  126. "projectcode": "3333",
  127. "buyerclass":"学校"
  128. }
  129. # 规则查询,根据必要条件 公司名称(用户ID)、版本号
  130. rules_id = get_rule("北京剑鱼信息技术有限公司", "v1.0")
  131. print(rules_id)
  132. # 评估调用
  133. result = start_quality(row_data, rules_id, a2s_ip, topic, timeout)
  134. print(result)
  135. def batch_load_data_debug():
  136. # 规则查询,根据必要条件 公司名称(用户ID)、版本号
  137. rules_id = get_rule("北京剑鱼信息技术有限公司", "v1.0")
  138. print(rules_id)
  139. db = MongoClient('192.168.3.71', 29099, unicode_decode_error_handler="ignore").re4art
  140. coll_user = db["zc_classify_test"]
  141. for item in coll_user.find({"_id": ObjectId("654862420023f3bdb1624a82")}):
  142. # item['detail'] = item['details'].replace("\\\"", "\"")
  143. item["_id"] = str(item["_id"])
  144. result = start_quality(item, rules_id, a2s_ip, topic, timeout)
  145. print(result)
  146. if __name__ == '__main__':
  147. # batch_load_data()
  148. # batch_load_data_test()
  149. # batch_load_data_debug()
  150. batch_load_purchasinglist()#标的物检查函数