u3_for_cscec.py 36 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833
  1. # update: 2022-7-18
  2. """
  3. 中建八局一公司业务接口
  4. """
  5. from urllib import parse
  6. import requests
  7. import time
  8. import traceback
  9. import sys
  10. import importlib
  11. sys.path.append('/home/server/projects/taiwuict/cscec-8bur-vms/supplement-python')
  12. # sys.path.append(r'D:\share\gitee\casper.supplement-python') # for pc
  13. methods = importlib.import_module(f"libraries.base_original")
  14. class Api(object):
  15. # def __init__(self, username='System001', password='Swdx@143',
  16. def __init__(self, username='500A7062', password='198797#cjhxbin',
  17. project_id='d0f254cc-8196-499a-8f0d-52bf8ba91486',
  18. project_name='山东省公共卫生临床中心(济南市传染病医院二期)项目工程总承包(EPC)'):
  19. """
  20. 第1现场:
  21. 济南市中心医院(东院区)项目工程总承包(EPC)
  22. 7eeb53a1-2bbd-4efa-8c8e-66936476226c
  23. 第2现场:
  24. 山东省大数据产业基地建设项目施工总承包
  25. 项目编号:500D10301958
  26. ORGID:63729db2-ea9c-4096-b5d9-3ad0369903c8
  27. 第3现场:
  28. 山东省公共卫生临床中心(济南市传染病医院二期)项目工程总承包(EPC)
  29. ORGID:d0f254cc-8196-499a-8f0d-52bf8ba91486
  30. 第4现场:
  31. 济南奥体东 13 及 17-2 号地块开发项目工程总 承包(EPC)
  32. a8defc53-76b3-4f4e-931d-8dd35ba310c7
  33. """
  34. # --- define ---
  35. self.service_url = 'http://app.cscec81.com/api' # 正式环境
  36. # self.service_url = f"http://pmdev.cscec81.com/api" # 正式环境
  37. # self.service_url = 'http://221.214.64.195:31229/api' # 公网测试地址
  38. # self.service_url = 'http://10.198.6.181:31229/api' # vpn测试环境 https://221.214.64.195 gelubo01 Gelubo@2022
  39. # --- release ---
  40. self.project_id = project_id
  41. self.project_name = project_name
  42. # --- release ---
  43. self.token = None
  44. if username and password:
  45. session_id, user_code, user_id = self.get_user_info(username, password)
  46. self.token = f"Bearer {self.get_token(session_id, user_code, user_id)}"
  47. # --- test ---
  48. # self.token_test = 'Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJleHAiOjE2NjAxMTgyODIsInVzZXJfbmFtZSI6Iui1tei_nuWxsTM0NTBhMjI0NmZiLTkwMWYtNGIwNi1hMjU2LTY4YTI4Y2VkZTU2Y2UwZDk5OTk3LTkzNzEtNGMwZi04NDNjLTUyNTMzYjE4ZTYxNSIsImp0aSI6Ijg3MzcxZTY0LTgwNzEtNGJlYy04YWMzLTUxMzViMTU5MzhjMyIsImNsaWVudF9pZCI6ImJyb3dzZXIiLCJzY29wZSI6WyJjbGllbnQiXX0.NF0IXabm_7RRqcdra6A7fsBvyBWa_62rkppQAFxalc4'
  49. @staticmethod
  50. def get_user_info(username, password):
  51. """
  52. 获取用户信息
  53. url: http://pmdev.cscec81.com/Login/Login.ashx?t=' + new Date().getTime() + '&method=CheckLogin
  54. """
  55. # url = f"{self.service_url}/Login/Login.ashx"
  56. url = f"http://app.cscec81.com/Login/Login.ashx" # 正式环境
  57. # url = f"http://pm.cscec81.com/Login/Login.ashx" # 测试环境
  58. # url = f"http://221.214.64.195:31229/Login/Login.ashx" # 测试环境
  59. url += f"?t={int(time.time() * 1000)}&method=CheckLogin"
  60. data = {
  61. 'Username': username,
  62. 'password': password,
  63. 'usertype': '0',
  64. 'sys': 'sitemanage',
  65. 'clientType': '5',
  66. }
  67. payload = parse.urlencode(data, encoding='utf-8')
  68. headers = {
  69. 'Content-Type': 'application/x-www-form-urlencoded',
  70. 'Cookie': 'ASP.NET_SessionId=luy3wg10b2kymc2nbiytn4xt'
  71. }
  72. print('Api.get_user_info.url:', url)
  73. # print('Api.get_user_info.headers:', headers)
  74. # print('Api.get_user_info.payload:', payload)
  75. response = requests.request('POST', url, headers=headers, data=payload)
  76. if response.status_code > 300:
  77. print('Api.get_user_info.result:', response.status_code)
  78. print('Api.get_user_info.detail:', response.text)
  79. return '', '', ''
  80. print('Api.get_user_info.result:', response.status_code)
  81. json_data = response.json()
  82. # print('Api.get_user_info.json_data:', json_data)
  83. if not json_data or not json_data.get('data'):
  84. return '', '', ''
  85. session_id = json_data.get('data').get('ticketID')
  86. user_code = json_data.get('data').get('userCode')
  87. user_id = json_data.get('data').get('userID')
  88. # print('Api.get_user_info.session_id:', session_id)
  89. # print('Api.get_user_info.user_code:', user_code)
  90. # print('Api.get_user_info.user_id:', user_id)
  91. return session_id, user_code, user_id
  92. @staticmethod
  93. def get_token(session_id, user_code, user_id):
  94. """
  95. 获取令牌
  96. url: http://pmdev.cscec81.com/api/oauth/token?grant_type=session&sessionId="
  97. + ticketID + "&userCode=" + userCode + "&userId=" + userID + "&client_type=web&system=1
  98. """
  99. # url = f"{self.service_url}/oauth/token"
  100. url = f"http://app.cscec81.com/api/oauth/token" # 正式环境
  101. # url = f"http://pm.cscec81.com/api/oauth/token" # 测试环境
  102. url += f"?grant_type=session&sessionId={session_id}&userCode={user_code}&userId={user_id}"
  103. url += f"&client_type=web&system=1"
  104. headers = {
  105. 'Authorization': 'Basic YnJvd3Nlcjo='
  106. }
  107. print('Api.get_token.url:', url)
  108. # print('Api.get_token.headers:', headers)
  109. response = requests.post(url=url, headers=headers)
  110. if response.status_code > 300:
  111. print('Api.get_token.result:', response.status_code)
  112. print('Api.get_token.detail:', response.text)
  113. return ''
  114. else:
  115. print('Api.get_token.result:', response.status_code)
  116. # return response.headers.get('authorization')
  117. return response.json().get('access_token')
  118. def get_cscec8_user_list(self):
  119. """
  120. 获取八局管理人员
  121. /api/economic/indoor/getProjectUserList?projectId=05037f9b-5cb6-4a43-9410-c0e6a83f280e
  122. return [
  123. {
  124. cardId: 身份证号
  125. imgUrl: 人脸图片
  126. dutyId: 职务id
  127. dutyName: 职务名称
  128. }
  129. ]
  130. """
  131. url = f"http://app.cscec81.com/api/economic/indoor/getProjectUserFaceList?projectId={self.project_id}"
  132. print('Api.get_cscec8_user_list.url:', url)
  133. response = requests.get(url, headers={'content-type': 'application/json'})
  134. if response.status_code > 300:
  135. print('Api.get_cscec8_user_list.result:', response.status_code)
  136. print('Api.get_cscec8_user_list.detail:', response.text)
  137. return []
  138. json_data = response.json()
  139. # print(json_data)
  140. return json_data
  141. def get_worker_list(self):
  142. """
  143. 获取工人列表(云筑网工人信息)
  144. url: http://app.cscec81.com/api/safeeducation/workerInfo/workers?projectName=济南市中心医院(东院区)项目工程总承包(EPC)
  145. url: http://221.214.64.195:31229/api/safeeducation/workerInfo/workers?projectName=丽泽SOHO项目
  146. return [
  147. {
  148. headImagePath: 人脸图像地址
  149. subContractorName: 劳务公司
  150. workTypeName: 工种
  151. }
  152. ]
  153. """
  154. url = f"http://app.cscec81.com/api/safeeducation/workerInfo/workers?projectName={self.project_name}"
  155. url += f"&page=0&size=5000"
  156. print('Api.get_worker_list.url:', url)
  157. response = requests.get(url, headers={'content-type': 'application/json'})
  158. print('Api.get_worker_list.result:', response.status_code)
  159. if response.status_code > 300:
  160. print('Api.get_worker_list.result:', response.status_code)
  161. print('Api.get_worker_list.detail:', response.text)
  162. return []
  163. json_data = response.json()
  164. # {'projectName': '济南市中心医院(东院区)项目工程总承包(EPC)', 'workerName': '高玉锋',
  165. # 'idCardNumber': '372527198311022813', 'workTypeName': '电气设备安装工', 'headImagePath': None}
  166. if not json_data or not json_data.get('success') or not json_data.get('data'):
  167. return []
  168. if not json_data.get('data').get('content'):
  169. return []
  170. # print(json_data.get('data').keys())
  171. # print(json_data.get('data').get('totalElements'))
  172. # print(len(json_data.get('data').get('content')))
  173. # print(json_data.get('data').get('content')[0])
  174. return json_data.get('data').get('content')
  175. @staticmethod
  176. def get_face_image_by_path(image_path):
  177. """
  178. 获取工人照片
  179. url: https://lwres.yzw.cn/worker-avatar/Original/2018/0612/f3230a72-57ab-4aaf-a741-61d8c078fe89.jpg
  180. """
  181. while True:
  182. try:
  183. url = f"https://lwres.yzw.cn/{image_path}"
  184. # print('Api.get_face_image_by_path.url:', url)
  185. response = requests.get(url, headers={'content-type': 'application/json'})
  186. # print('Api.get_face_image_by_path.result:', response.status_code)
  187. if response.status_code > 300:
  188. print('Api.get_face_image_by_path.result:', response.status_code)
  189. print('Api.get_face_image_by_path.detail:', response.text)
  190. return b''
  191. else:
  192. return response.content
  193. except Exception as exception:
  194. if exception.__class__.__name__ == 'ConnectionError':
  195. print(f"Api.get_face_image_by_path: sleep 60s")
  196. time.sleep(60)
  197. else:
  198. print(f"Api.get_face_image_by_path.exception:{exception.__class__.__name__}")
  199. print(f"Api.get_face_image_by_path.traceback:{traceback.format_exc()}")
  200. return b''
  201. @staticmethod
  202. def get_face_image_by_path_v2(image_path):
  203. """
  204. 获取工人高清头像
  205. url: http://app.cscec81.com/media/202110/25/20211025-161726-381-4862.jpg
  206. """
  207. while True:
  208. try:
  209. url = f"http://app.cscec81.com/media/{image_path}"
  210. # print('Api.get_face_image_by_path_v2.url:', url)
  211. response = requests.get(url, headers={'content-type': 'application/json'})
  212. # print('Api.get_face_image_by_path_v2.result:', response.status_code)
  213. if response.status_code > 300:
  214. print('Api.get_face_image_by_path_v2.result:', response.status_code)
  215. print('Api.get_face_image_by_path_v2.detail:', response.text)
  216. return b''
  217. else:
  218. return response.content
  219. except Exception as exception:
  220. if exception.__class__.__name__ == 'ConnectionError':
  221. print(f"Api.get_face_image_by_path_v2: sleep 60s")
  222. time.sleep(60)
  223. else:
  224. print(f"Api.get_face_image_by_path_v2.exception:{exception.__class__.__name__}")
  225. print(f"Api.get_face_image_by_path_v2.traceback:{traceback.format_exc()}")
  226. return b''
  227. @staticmethod
  228. def get_face_image_by_url(image_url):
  229. """
  230. 获取八局管理人员人脸图像
  231. url: https://hcm.cscec81.com/img?type=photo&size=120&index=ae2f8424-c63f-11ea-b0a9-ea6f5cf6388d&rnd=1653618903725
  232. """
  233. while True:
  234. try:
  235. # print('Api.get_face_image_by_url.url:', url)
  236. response = requests.get(image_url, headers={'content-type': 'application/json'})
  237. # print('Api.get_face_image_by_url.result:', response.status_code)
  238. if response.status_code > 300:
  239. print('Api.get_face_image_by_url.result:', response.status_code)
  240. print('Api.get_face_image_by_url.detail:', response.text)
  241. return b''
  242. else:
  243. return response.content
  244. except Exception as exception:
  245. if exception.__class__.__name__ == 'ConnectionError':
  246. print(f"Api.get_face_image_by_url: sleep 60s")
  247. time.sleep(60)
  248. else:
  249. print(f"Api.get_face_image_by_url.exception:{exception.__class__.__name__}")
  250. print(f"Api.get_face_image_by_url.traceback:{traceback.format_exc()}")
  251. return b''
  252. def upload_file(self, face_uuid, file_path):
  253. """
  254. 上传文件图片
  255. """
  256. # service_url = 'http://221.214.64.195:31229/api'
  257. # url = f"{service_url}/storages/files/anonymousUpload"
  258. url = f"{self.service_url}/storages/files/anonymousUpload"
  259. files = {
  260. 'id': (None, face_uuid),
  261. 'file': ('1.jpg', open(file_path, 'rb'), 'image/jpg'),
  262. }
  263. headers = {
  264. 'Authorization': self.token,
  265. }
  266. print('Api.upload_file.url:', url)
  267. response = requests.post(url=url, files=files, headers=headers)
  268. if response.status_code > 300:
  269. print('Api.upload_file.result:', response.status_code)
  270. # print('Api.upload_file.detail:', response.text)
  271. return ''
  272. else:
  273. print('Api.upload_file.result:', response.status_code)
  274. """
  275. 原地址
  276. http://10.198.6.181:31900/cscec81-cloud/202110/12/20211012-161022-713-7035.jpg
  277. http://10.198.6.173:30900/cscec81-cloud/202206/13/20220613-022118-96-3795.jpg
  278. 替换后地址
  279. http://221.214.64.195:31229/media/202110/12/20211012-161022-713-7035.jpg
  280. http://app.cscec81.com/media/202110/12/20211012-161022-713-7035.jpg
  281. """
  282. link = response.json().get('link')
  283. # link = link.replace('http://10.198.6.181:31900/cscec81-cloud', 'http://221.214.64.195:31229/media') # 测试
  284. # link = link.replace('http://10.198.6.173:30900/cscec81-cloud', 'http://app.cscec81.com/media') # 正式
  285. # link = f"http://221.214.64.195:31229/media{link.split('cscec81-cloud')[1]}" # 测试环境
  286. link = f"http://app.cscec81.com/media{link.split('cscec81-cloud')[1]}" # 正式环境
  287. return link
  288. def get_user_list(self):
  289. """
  290. 获取在职人员列表
  291. """
  292. url = f"{self.service_url}/system/users/getUserList"
  293. data = {
  294. 'companyId': self.project_id, # 单位id
  295. 'userName': '', # 人员名称
  296. 'isMainPosition': '', # 1 主职 0 主职+兼职
  297. 'postId': '', # 职务
  298. 'postName': '',
  299. }
  300. headers = {
  301. 'Authorization': self.token
  302. }
  303. # print('Api.get_user_list.url:', url)
  304. response = requests.get(url, params=data, headers=headers)
  305. # print('Api.get_user_list.result:', response.status_code)
  306. if response.status_code > 300:
  307. print('Api.get_user_list.result:', response.status_code)
  308. print('Api.get_user_list.detail:', response.text)
  309. return []
  310. json_data = response.json()
  311. if not json_data.get('content'):
  312. return []
  313. print(json_data.get('content')[0])
  314. return json_data.get('content')
  315. def push_face(self, send_at, face_file_link, face_name, cscec8_duty_name, cscec8_id, age, group, source):
  316. """
  317. 上传新增人脸(上传八局管理人员接口)
  318. """
  319. # test_service_url = 'http://10.198.6.181:31229/api'
  320. # url = f"{test_service_url}/worker/userInfo"
  321. url = f"{self.service_url}/worker/userInfo"
  322. data = [{
  323. 'groupId': group, # 分组ID 001 陌生人 002 劳务工人 003 临时用工 004 项目管理人员 005 VIP 006 黑名单 007 其他
  324. 'equipmentId': self.project_id, # 设备id
  325. 'userId': cscec8_id, # 用户唯一标识 人脸id
  326. 'userName': face_name, # 用户名 人脸名称
  327. 'age': age, # 年龄
  328. 'postInfoName': cscec8_duty_name, # 职务
  329. 'lastEnterTime': send_at, # 最后进入时间 '2021-08-10 08:00:00'
  330. 'faceInfo': face_file_link, # 文件链接地址
  331. 'sourceType': source, # 是否是八局人脸库信息 0 不是 1 是
  332. }]
  333. # print('Api.push_face:data:', data)
  334. # methods.debug_log('Api.push_face', f"m-418 | data: {data}")
  335. headers = {
  336. 'Authorization': self.token,
  337. # 'Authorization': self.token_test,
  338. }
  339. # print('Api.push_face.url:', url)
  340. response = requests.post(url, json=data, headers=headers)
  341. if response.status_code > 300:
  342. print('Api.push_face.result:', response.status_code)
  343. print('Api.push_face.detail:', response.text)
  344. methods.debug_log('apis.u3_for_cscec', f"m-395: url -> {url}")
  345. methods.debug_log('apis.u3_for_cscec', f"m-395: data -> {data}")
  346. methods.debug_log('apis.u3_for_cscec', f"m-395: result -> {response.status_code}")
  347. methods.debug_log('apis.u3_for_cscec', f"m-395: detail -> {response.text}")
  348. return False
  349. else:
  350. # print('Api.push_face.result:', response.status_code)
  351. # print('Api.push_face:json:', response.json())
  352. return True
  353. def push_work_info(self, send_at, face_file_link, face_name, prc_id, worker_contractor, worker_type_name, age,
  354. find_at):
  355. """
  356. 添加劳务人员接口(上传农民工接口)
  357. """
  358. # test_service_url = 'http://425ax87563.zicp.vip'
  359. # url = f"{test_service_url}/worker/userInfo/workerInfo"
  360. url = f"{self.service_url}/worker/userInfo/workerInfo"
  361. data = [{
  362. 'equipmentId': self.project_id, # 设备id
  363. 'userId': prc_id, # 用户唯一标识 农民工身份证id
  364. 'userName': face_name, # 用户名 工人名称
  365. 'userCerd': prc_id, # 用户身份证号
  366. 'age': age, # 年龄
  367. 'postInfoName': '', # 职务
  368. 'workType': worker_type_name, # 工种(农民工)
  369. 'labourCompany': worker_contractor, # 劳务公司(农民工)
  370. 'enterState': '', # 进场状态
  371. 'enterTime': '', # 进场时间
  372. 'synTime': find_at, # 同步时间(同步云筑网时间)
  373. 'lastEnterTime': send_at, # 最后进入时间 '2021-08-10 08:00:00'
  374. 'faceInfo': face_file_link, # 文件链接地址 人脸信息(图片传八局服务器系统,入参只传服务器文件地址)
  375. 'labourSource': str(0), # 是否八局底库人员 0 不是 1 是
  376. }]
  377. # data = [
  378. # {'equipmentId': '63729db2-ea9c-4096-b5d9-3ad0369903c8', 'userId': '511025199009011013', 'userName': '赵润',
  379. # 'userCerd': '511025199009011013', 'age': '', 'postInfoName': '', 'workType': None, 'labourCompany': None,
  380. # 'enterState': '', 'enterTime': '', 'synTime': '', 'lastEnterTime': '2022-05-27 10:10:56',
  381. # 'faceInfo': 'http://221.214.64.195:31229/media/202205/27/20220527-150651-60-5508.jpg',
  382. # 'labourSource': '0'}]
  383. # print('Api.push_work_info:data:', data)
  384. # methods.debug_log('Api.push_work_info', f"m-464 | data: {data}")
  385. headers = {
  386. 'Authorization': self.token,
  387. # 'Authorization': self.token_test,
  388. }
  389. # print('Api.push_work_info.url:', url)
  390. response = requests.post(url, json=data, headers=headers)
  391. if response.status_code > 300:
  392. # print('Api.push_work_info.result:', response.status_code)
  393. # print('Api.push_work_info.detail:', response.text)
  394. methods.debug_log('apis.u3_for_cscec', f"m-457: url -> {url}")
  395. methods.debug_log('apis.u3_for_cscec', f"m-457: data -> {data}")
  396. methods.debug_log('apis.u3_for_cscec', f"m-457: result -> {response.status_code}")
  397. methods.debug_log('apis.u3_for_cscec', f"m-457: detail -> {response.text}")
  398. return False
  399. else:
  400. # print('Api.push_work_info:json:', response.json())
  401. return True
  402. def pull_update_info(self, start_at):
  403. """
  404. 获取线上更新数据 todo 定时请求更新本地数据相关的数据
  405. """
  406. # test_service_url = 'http://425ax87563.zicp.vip'
  407. # url = f"{test_service_url}/worker/userInfo/findUpdateUserByTime"
  408. url = f"{self.service_url}/worker/userInfo/findUpdateUserByTime"
  409. # url = f"http://425ax87563.zicp.vip/worker/userInfo/findUpdateUserByTime?queryStartTime=2022-05-27 11:09:00"
  410. # url += '?queryStartTime=2022-05-27 11:09:00'
  411. url += f"?queryStartTime={start_at}"
  412. data = {
  413. # 'companyId': self.project_id, # 单位id
  414. # 'queryStartTime': '2021-10-21 11:09:00',
  415. # 'queryStartTime': '2022-05-27 11:09:00',
  416. }
  417. headers = {
  418. 'Authorization': self.token,
  419. # 'Authorization': self.token_test,
  420. }
  421. print('Api.pull_update_info.url:', url)
  422. response = requests.get(url, params=data, headers=headers)
  423. print('Api.pull_update_info.result:', response.status_code)
  424. print('Api.pull_update_info:text:', response.json())
  425. return []
  426. # if response.status_code > 300:
  427. # print('Api.pull_update_info:text:', response.text)
  428. # return []
  429. # json_data = response.json()
  430. # if not json_data.get('content'):
  431. # return []
  432. # print(json_data.get('content')[0])
  433. # return json_data.get('content')
  434. def pull_alarm_list(self, create_at):
  435. """
  436. 获取告警列表
  437. """
  438. # test_service_url = 'http://425ax87563.zicp.vip'
  439. # url = f"{test_service_url}/worker/alarm/alarmPageList"
  440. # url += f"?createTime={create_at}"
  441. url = f"{self.service_url}/worker/alarm/alarmPageList"
  442. url += f"?createTime={create_at}"
  443. params = {
  444. # 'createTime': '2021-08-10 08:00:00'
  445. }
  446. headers = {
  447. 'Authorization': self.token,
  448. # 'Authorization': self.token_test,
  449. }
  450. print('Api.pull_alarm_list.url:', url)
  451. response = requests.get(url, params=params, headers=headers)
  452. if response.status_code > 300:
  453. print('Api.pull_alarm_list.result:', response.status_code)
  454. print('Api.pull_alarm_list.detail:', response.text)
  455. return {}
  456. else:
  457. print('Api.pull_alarm_list.result:', response.status_code)
  458. return response.json()
  459. def pull_alarm_group_list(self, create_at):
  460. """
  461. 获取报警分组列表
  462. return [
  463. {
  464. ALARM_GROUP_STRATEGY_IDS: 1 现场屏显报警 2 现场语音报警 3 微信报警
  465. }
  466. ]
  467. """
  468. # test_service_url = 'http://425ax87563.zicp.vip'
  469. # url = f"{test_service_url}/worker/alarm/alarmGroupList"
  470. url = f"{self.service_url}/worker/alarm/alarmGroupList"
  471. params = {
  472. 'projectId': self.project_id,
  473. 'createTime': create_at,
  474. }
  475. headers = {
  476. 'Authorization': self.token,
  477. # 'Authorization': self.token_test,
  478. }
  479. print('Api.pull_alarm_group_list.url:', url)
  480. response = requests.get(url, params=params, headers=headers)
  481. if response.status_code > 300:
  482. print('Api.pull_alarm_group_list.result:', response.status_code)
  483. print('Api.pull_alarm_group_list.detail:', response.text)
  484. return []
  485. else:
  486. print('Api.pull_alarm_group_list.result:', response.status_code)
  487. return response.json()
  488. def push_message(self):
  489. """
  490. 推送微信消息
  491. {'ALARM_TYPE': 1, 'ALARM_USER_ID': 'f6bae517-0a28-429c-b65b-b16548ab2ca4', 'ALARM_GROUP_NAME': '屏显报警',
  492. 'id': '17ee224382634361bc5b9ef41ce09eb1', 'ALARM_STRATEGY_GROUP_ID': '5e58ed8828c84c779b3cddb0257d6f5f',
  493. 'ALARM_PROJECT_ID': '63729db2-ea9c-4096-b5d9-3ad0369903c8', 'ALARM_NAME': '刘美琪'}
  494. {'ALARM_TYPE': 1, 'ALARM_USER_ID': '7a574580-6af1-40af-a3c8-1c0d5aee567b', 'ALARM_GROUP_NAME': '微信报警',
  495. 'id': '04bb6b4628954b2282b15a3cb2e74ab8', 'ALARM_STRATEGY_GROUP_ID': '0f695744b43447b2b4cbad8dc78389f4',
  496. 'ALARM_PROJECT_ID': '63729db2-ea9c-4096-b5d9-3ad0369903c8', 'ALARM_NAME': '吴非'}
  497. 微信推送结果查询接口 worker/alarm/getWxPushState
  498. 状态 00 未发送 01 发送成功 02 发送失败 03 发送异常
  499. """
  500. # test_service_url = 'http://425ax87563.zicp.vip'
  501. # url = f"{test_service_url}/worker/alarm/getWxAlarmUser"
  502. url = f"{self.service_url}/worker/alarm/getWxAlarmUser"
  503. data = {
  504. 'projectId': self.project_id, # 项目id
  505. # 'groupId': '5e58ed8828c84c779b3cddb0257d6f5f', # 告警组id ALARM_STRATEGY_GROUP_ID
  506. 'groupId': '0f695744b43447b2b4cbad8dc78389f4', # 告警组id ALARM_STRATEGY_GROUP_ID
  507. # 'userId': 'f6bae517-0a28-429c-b65b-b16548ab2ca4', # 告警用户id ALARM_USER_ID
  508. 'userId': '7a574580-6af1-40af-a3c8-1c0d5aee567b', # 告警用户id ALARM_USER_ID
  509. }
  510. print(f"Api.push_message:data: {data}")
  511. headers = {
  512. 'Authorization': self.token,
  513. # 'Authorization': self.token_test,
  514. }
  515. print('Api.push_message.url:', url)
  516. response = requests.post(url, json=data, headers=headers)
  517. if response.status_code > 300:
  518. print('Api.push_message.result:', response.status_code)
  519. print('Api.push_message.detail:', response.text)
  520. return {}
  521. else:
  522. print('Api.push_message.result:', response.status_code)
  523. return response.json()
  524. def check_message_state(self):
  525. """
  526. 微信推送结果查询接口 worker/alarm/getWxPushState
  527. 状态 00 未发送 01 发送成功 02 发送失败 03 发送异常
  528. """
  529. # test_service_url = 'http://425ax87563.zicp.vip'
  530. # url = f"{test_service_url}/worker/alarm/getWxPushState"
  531. url = f"{self.service_url}/worker/alarm/getWxPushState"
  532. # url += f"?wxPushId=24290bde-09d7-444b-b2ea-039213f8b628"
  533. url += f"?wxPushId=77c36ad2-ad35-464b-bf52-6d16fd9c74e0"
  534. data = {
  535. # 'wxPushId': mid,
  536. # 'wxPushId': '24290bde-09d7-444b-b2ea-039213f8b628',
  537. }
  538. headers = {
  539. 'Authorization': self.token,
  540. # 'Authorization': self.token_test,
  541. }
  542. print('Api.check_message_state.url:', url)
  543. # response = requests.get(url, json=data, headers=headers)
  544. response = requests.get(url, headers=headers)
  545. if response.status_code > 300:
  546. print('Api.check_message_state.result:', response.status_code)
  547. print('Api.check_message_state.detail:', response.text)
  548. return {}
  549. else:
  550. print('Api.check_message_state.result:', response.status_code)
  551. # return response.json()
  552. return response.text
  553. def push_state(self):
  554. """
  555. 每分钟发送心跳请求接口
  556. """
  557. # test_service_url = 'http://425ax87563.zicp.vip'
  558. # url = f"{test_service_url}/worker/equipmentMaintain/updateEquStateTime"
  559. url = f"{self.service_url}/worker/equipmentMaintain/updateEquStateTime"
  560. data = {
  561. 'projectId': self.project_id,
  562. }
  563. headers = {
  564. 'Authorization': self.token,
  565. # 'Authorization': self.token_test,
  566. }
  567. # print('Api.push_state.url:', url)
  568. response = requests.post(url, json=data, headers=headers)
  569. if response.status_code > 300:
  570. print('Api.push_state.result:', response.status_code)
  571. print('Api.push_state.detail:', response.text)
  572. return {}
  573. else:
  574. # print('Api.push_state.result:', response.status_code)
  575. return response.json()
  576. def push_face_log(self, user_id, find_at, face_link=''):
  577. """
  578. 上传识别记录
  579. methods.ts_to_string(item.get('create_at'), '%Y-%m-%d %H:%M:%S')
  580. """
  581. # test_service_url = 'http://10.198.6.181:31229/api'
  582. # url = f"{test_service_url}/worker/ledger/addLedger"
  583. url = f"{self.service_url}/worker/ledger/addLedger"
  584. data = [{
  585. 'projectId': self.project_id, # 项目id
  586. 'equipmentInfo': self.project_id, # 设备id
  587. 'equipmentRecognitionTime': find_at, # 识别时间 '2021-10-21 11:09:00'
  588. 'userId': user_id, # 人脸标识 八局人员使用uuid 劳务人员使用身份证号
  589. 'faceInfo': face_link, # 文件链接地址 人脸信息(图片传八局服务器系统,入参只传服务器文件地址)
  590. }]
  591. headers = {
  592. 'Authorization': self.token,
  593. # 'Authorization': self.token_test,
  594. }
  595. # methods.debug_log('apis.u3_for_cscec', f"m-651: project_id -> {self.project_id}")
  596. print('Api.push_face_log.url:', url)
  597. # print('Api.push_face_log:data:', data)
  598. response = requests.post(url, json=data, headers=headers)
  599. if response.status_code > 300:
  600. # print('Api.push_face_log.result:', response.status_code)
  601. # print('Api.push_face_log.detail:', response.text)
  602. methods.debug_log('apis.u3_for_cscec', f"m-678: url -> {url}")
  603. methods.debug_log('apis.u3_for_cscec', f"m-678: data -> {data}")
  604. methods.debug_log('apis.u3_for_cscec', f"m-678: result -> {response.status_code}")
  605. methods.debug_log('apis.u3_for_cscec', f"m-678: detail -> {response.text}")
  606. return False
  607. else:
  608. print('Api.push_face_log.result:', response.status_code)
  609. print('Api.push_face_log.detail:', response.text)
  610. # methods.debug_log('apis.u3_for_cscec', f"m-668: result -> {response.status_code}")
  611. # methods.debug_log('apis.u3_for_cscec', f"m-668: detail -> {response.text}")
  612. # methods.debug_log('apis.u3_for_cscec', f"m-668: detail -> {response.json()}")
  613. return True
  614. if __name__ == '__main__':
  615. # --- init ---
  616. # api = Api(username='500A4475', password='cscec81#')
  617. # api = Api(username='500A7062', password='198797#cjhxbin') # 侯经理 正式环境
  618. api = Api(project_id='63729db2-ea9c-4096-b5d9-3ad0369903c8',
  619. project_name='山东省大数据产业基地建设项目施工总承包') # 正式环境账号
  620. # api = Api(project_id='a8defc53-76b3-4f4e-931d-8dd35ba310c7',
  621. # project_name='济南奥体东 13 及 17-2 号地块开发项目工程总 承包(EPC)') # 正式环境账号
  622. # api = Api() # 正式环境账号
  623. # --- test ---
  624. # out = api.upload_file('aabbccdd-aabbccss-ssggaaff-sseeqqhh', r"D:\3.jpg")
  625. # print(out)
  626. # --- test ---
  627. # api.push_state()
  628. # api.push_face(
  629. # send_at='2022-07-18 08:09:00',
  630. # face_file_link='http://app.cscec81.com/media/202207/18/20220718-105339-394-2140.jpg',
  631. # face_name='张三001',
  632. # cscec8_duty_name='司机',
  633. # cscec8_id='aabbccdd-aabbccss-ssggaaff-sseeqqhh',
  634. # age=60,
  635. # group='004',
  636. # source=1)
  637. # api.push_face_log('aabbccdd-aabbccss-ssggaaff-sseeqqhh', '2022-06-02 08:09:01',
  638. # 'http://app.cscec81.com/media/202207/18/20220718-111202-730-7523.jpg')
  639. # --- test ---
  640. # _dict = {}
  641. # items = api.get_worker_list()
  642. # print(items[0])
  643. # print(len(items))
  644. # for item in items:
  645. # _dict[item.get('idCardNumber')] = 1
  646. # print(len(_dict.keys()))
  647. # --- check 八局人员 ---
  648. # items = api.get_cscec8_user_list()
  649. # for item in items:
  650. # if item.get('userName') in ['孙会沅']:
  651. # print(item)
  652. # --- check avatarAddress ---
  653. # out = api.get_worker_list()
  654. # for one in out:
  655. # if one.get('workerName') in ['鲁成', '韩继涛', '丁保树', '金义莲']:
  656. # print(one)
  657. # # if one.get('subContractorName'):
  658. # # print(one.get('avatarAddress'))
  659. # # print(one.get('flag'), type(one.get('flag')))
  660. # # image = api.get_face_image_by_path_v2(one.get('avatarAddress'))
  661. # # print(type(image), len(image))
  662. # --- test ---
  663. # uuid = '62a166f324bfcf82f7066b65'
  664. # face_image_path = '/home/server/resources/vms-files/2022-0609-112017-618668-raw.jpg'
  665. # face_image_path = '/home/server/resources/vms-files/2022-0601-172536-193936.jpg'
  666. # out = api.upload_file(uuid, face_image_path)
  667. # print(out)
  668. # --- test ---
  669. # o = api.pull_alarm_list('2021-06-01 08:00:00')
  670. # print(o)
  671. # o = api.pull_alarm_group_list('2021-06-01 08:00:00')
  672. # print(o)
  673. # o = api.push_message()
  674. # print(o)
  675. # o = api.check_message_state()
  676. # print(o)
  677. # --- test ---
  678. # o = api.pull_update_info('2022-05-27 11:09:00')
  679. # o = api.pull_alarm_list('2022-05-27 11:09:00')
  680. # o = api.pull_alarm_group_list()
  681. # print(o)
  682. # --- test ---
  683. # o = api.push_work_info(1, 2, 3, 4, 1, 1)
  684. # print(o)
  685. # --- test ---
  686. # u = 'https://hcm.cscec81.com/img?type=photo&size=120&index=ae2f8424-c63f-11ea-b0a9-ea6f5cf6388d&rnd=1653618903725'
  687. # u = 'https://hcm.cscec81.com/img?type=photo&size=120&index=6605f16a-095a-11ec-99ad-da7e2f6980d1&rnd=1653620550071'
  688. # o = api.get_face_image_by_url(u)
  689. # print(o)
  690. # --- test ---
  691. # out = api.get_cscec8_user_list()
  692. # print(len(out))
  693. # for i in out:
  694. # if i.get('userName') == '杜兴昌':
  695. # print(i)
  696. # --- test ---
  697. # out = api.push_face('6166f0ab95a68293064d97c4', '2021-04-14 14:43:55',
  698. # 'http://221.214.64.195:31229/media/202110/21/20211021-120733-570-3862.jpg', 1, '张001')
  699. # out = api.push_work_info('6166f0ab95a68293064d97c4', '2021-10-13 14:43:55',
  700. # 'http://221.214.64.195:31229/media/202110/21/20211021-120733-570-3862.jpg')
  701. # print(out)
  702. # --- test ---
  703. # out = api.pull_alarm_group_list()
  704. # print(out)
  705. # --- test ---
  706. # alarm_group_id = '1dfcd494affd4ee9aeb533c2d12558e7'
  707. # out = api.push_message(alarm_group_id)
  708. # --- test ---
  709. # out = api.pull_alarm_group_list()
  710. # out = api.get_user_list()
  711. # print(out)
  712. # --- test ---
  713. # out = api.get_user_list()
  714. # print(out)
  715. # --- test ---
  716. # def write_bytes(path, data=b''):
  717. # with open(path, 'wb') as f:
  718. # f.write(data)
  719. # outputs = api.get_worker_list_by_project_name('济南市中心医院(东院区)项目工程总承包(EPC)')
  720. # count = 0
  721. # for i in outputs:
  722. # if not i.get('headImagePath'):
  723. # continue
  724. # url = f"https://lwres.yzw.cn/{i.get('headImagePath')}"
  725. # r = requests.get(url, headers={'content-type': 'application/json'})
  726. # count += 1
  727. # name = str(count).zfill(6)
  728. # write_bytes(f"D:\\test\\111\\{name}.jpg", r.content)
  729. # --- test ---
  730. # def write_bytes(path, data=b''):
  731. # with open(path, 'wb') as f:
  732. # f.write(data)
  733. # _url = f"https://lwres.yzw.cn/worker-avatar/Original/2021/0303/0f735c37-118f-4cd8-a0a5-753e0e2fc7d7.jpg"
  734. # r = requests.get(_url, headers={'content-type': 'application/json'})
  735. # write_bytes(f"D:\\test\\111\\{1}.jpg", r.content)
  736. # --- test ---
  737. # d1 = {}
  738. # outputs = api.get_worker_list_by_project_name('济南市中心医院(东院区)项目工程总承包(EPC)')
  739. # for i in outputs:
  740. # if i.get('workTypeName') not in d1:
  741. # d1[i.get('workTypeName')] = 0
  742. # d1[i.get('workTypeName')] += 1
  743. # print(d1)
  744. # --- test ---
  745. # api.get_image('worker-avatar/Original/2018/0612/f3230a72-57ab-4aaf-a741-61d8c078fe89.jpg')
  746. # out = api.get_worker_list_by_project_name('济南市中心医院(东院区)项目工程总承包(EPC)')
  747. # print(len(out))