api.py 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302
  1. # update: 2023-11-11
  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(r'C:\mccbts-ar-py\module-method-python') # for 10.10.61.22
  12. # sys.path.append(r'D:\mccbts-ar-py\module-method-python') # for 192.168.103.34
  13. methods = importlib.import_module(f"xlib")
  14. class API(object):
  15. # def __init__(self, username='System001', password='Swdx@143',
  16. def __init__(self, username='', password=''):
  17. """
  18. 接口地址: https://eaiops.mccbts.com.cn/cigpf-gateway/cigpf-auth/login
  19. 接口说明: 用户认证接口,mcctest/Mcc@1234
  20. 接口地址: http://ycpx04.mccbts.com.cn/cnki-gw/expert/expert/getExpertList
  21. 接口说明:获取专家列表
  22. 接口地址: http://10.8.0.151:8000/datachange/release/interface
  23. 接口说明:该接口可以获取用户数据、部门数据
  24. """
  25. # --- define ---
  26. self.cigpf_api_service = f"https://eaiops.mccbts.com.cn"
  27. self.cnki_api_service = f"http://ycpx04.mccbts.com.cn"
  28. self.datachange_api_service = f"http://10.8.0.151:8000"
  29. self.LIST_USER_TOKEN = 'FA460AD97660475BBD8E1CF31BC7A49B'
  30. self.LIST_DEPT_TOKEN = '4412B9724D254E38B57014CF99EB0312'
  31. def get_user_info(self, username, password):
  32. """
  33. 获取用户信息
  34. return {
  35. 'success': True,
  36. 'message': '操作成功!',
  37. 'code': 200,
  38. 'result': {
  39. 'id': '1399259233832144898',
  40. 'username': 'mcctest',
  41. 'realname': '测试账号',
  42. 'avatar': '/cigpfupload/05a5b1ab84a446c4a2e126da89b0c0af.png',
  43. 'birthday': None,
  44. 'sex': None,
  45. 'thirdId': '',
  46. 'thirdType': 'qt',
  47. 'email': None,
  48. 'phone': '18210635895',
  49. 'orgCode': '1',
  50. 'orgCodeTxt': None,
  51. 'status': 1,
  52. 'delFlag': 0,
  53. 'workNo': '99999',
  54. 'post': None,
  55. 'telephone': None,
  56. 'createBy': '',
  57. 'createTime': None,
  58. 'updateBy': '张宇',
  59. 'updateTime': '2023-11-07 06:00:09',
  60. 'activitiSync': 1,
  61. 'userIdentity': 2,
  62. 'departIds': '1000051C',
  63. 'relTenantIds': None,
  64. 'clientId': None,
  65. 'userType': '2'
  66. },
  67. 'timestamp': 1699666081555
  68. }
  69. """
  70. url = f"{self.cigpf_api_service}/cigpf-gateway/cigpf-auth/login"
  71. # data = {
  72. # 'userName': 'mcctest', # 用户
  73. # 'passWord': 'Mcc@1234', # 密码
  74. # }
  75. data = {
  76. 'userName': username, # 用户
  77. 'passWord': password, # 密码
  78. }
  79. # print(f"API.get_user_info:data: {data}")
  80. print('API.get_user_info.url:', url)
  81. response = requests.post(url, json=data)
  82. if response.status_code > 300:
  83. print('API.get_user_info.result:', response.status_code)
  84. print('API.get_user_info.detail:', response.text)
  85. return {}
  86. else:
  87. print('API.get_user_info.result:', response.status_code)
  88. return response.json()
  89. def get_expert_type_tree_list(self):
  90. """
  91. 获取专家结构树
  92. """
  93. url = f"http://ycpx04.mccbts.com.cn/cnki-gw/expert/expertType/getExpertTypeTreeList"
  94. data = {
  95. 'keyword': ''
  96. }
  97. response = requests.post(url, json=data)
  98. print('API.test.url:', url)
  99. print('API.test.data:', data)
  100. print('API.test.code:', response.status_code)
  101. print('API.test.text:', response.text)
  102. def get_expert_list(self, page=1, rows=10):
  103. """
  104. 获取专家列表
  105. return {
  106. 'msg': '操作成功',
  107. 'code': 200,
  108. 'data': {
  109. 'total': 320,
  110. 'list': [
  111. {
  112. 'id': 407880669122629,
  113. 'expertId': 'b46f7f7e-2883-4281-ba92-0c72fb30a668',
  114. 'expertCode': '40886',
  115. 'expertName': '冯浩川',
  116. 'expertLogo': '',
  117. 'sex': 1,
  118. 'birthday': '1974-08-12 00:00:00',
  119. 'education': None,
  120. 'degree': None,
  121. 'colleges': '',
  122. 'politicalOutlook': '',
  123. 'academicTitle': '',
  124. 'expertTypeId': 'a0846382-dc33-44f5-990d-ea042ab90cf4',
  125. 'expertType': '工程机械组',
  126. 'workUnitOrCurrentPosition': '',
  127. 'professionalAndTechnicalFields': '',
  128. 'mainSocialPositions': '',
  129. 'personalHonors': '',
  130. 'project': [],
  131. 'brief': '',
  132. 'createTime': '2023-04-17 15:30:43',
  133. 'createUserId': '6867b1b3-024f-4065-b991-3ebd48df7b27',
  134. 'type': '',
  135. 'companyId': '45b9801f-d2ff-4886-8076-7f7d8b403e37',
  136. 'company': '协力生产分公司',
  137. 'departmentId': '301e6551-dfd6-4e3e-b7f5-be36e14f84a1',
  138. 'department': '协力_机械维修中心_管理组'
  139. }
  140. ]
  141. }
  142. }
  143. """
  144. url = f"{self.cnki_api_service}/cnki-gw/expert/expert/getExpertList"
  145. data = {
  146. 'pageDto': {
  147. 'page': page,
  148. 'rows': rows
  149. }
  150. }
  151. # print(f"API.get_user_info:data: {data}")
  152. print('API.get_expert_list.url:', url)
  153. response = requests.post(url, json=data)
  154. # --- check ---
  155. if response.status_code > 300:
  156. print('API.get_expert_list.result:', response.status_code)
  157. print('API.get_expert_list.detail:', response.text)
  158. return []
  159. # --- check ---
  160. data = response.json()
  161. if data.get('code') != 200:
  162. return []
  163. # --- check ---
  164. if not data:
  165. return []
  166. return data.get('data').get('list')
  167. def get_staff_list(self):
  168. """
  169. 获取员工列表
  170. return [
  171. {
  172. 'STATUS': '1',
  173. 'ORG_CODE': '1603605',
  174. 'UPDATE_BY': 'HR',
  175. 'CREATE_BY': 'HR',
  176. 'DEPART_NAME': '山西_天车二区_硅钢班',
  177. 'DEL_FLAG': '0',
  178. 'CREATE_TIME': 1659117651000,
  179. 'UPDATE_TIME': 1659117651000,
  180. 'ID': '1001G1AR',
  181. 'DEPART_NAME_ABBR': '山西_天车二区_硅钢班',
  182. 'C1': '1',
  183. 'PARENT_ID': '1001G1AM'
  184. }
  185. ]
  186. """
  187. url = f"{self.datachange_api_service}/datachange/release/interface"
  188. headers = {'Chinasofti-Access-Token': self.LIST_USER_TOKEN}
  189. print('API.get_staff_list.url:', url)
  190. print('API.get_staff_list.headers:', headers)
  191. response = requests.get(url, headers=headers)
  192. # --- check ---
  193. if response.status_code > 300:
  194. print('API.get_staff_list.result:', response.status_code)
  195. print('API.get_staff_list.detail:', response.text)
  196. return []
  197. # --- check ---
  198. data = response.json()
  199. if data.get('code') != 0:
  200. print('API.get_staff_list.detail:', response.text)
  201. return []
  202. return data.get('data')
  203. def get_department_list(self):
  204. """
  205. 获取部门列表
  206. return [
  207. {
  208. 'ORG_ID': '10012B4J',
  209. 'REALNAME': '张天勤',
  210. 'POST': '电焊工',
  211. 'PHONE': '15921009690',
  212. 'SEX': 1,
  213. 'UPDATE_BY': 'HR',
  214. 'DEL_FLAG': 0,
  215. 'UPDATE_TIME': 1661492148000,
  216. 'WORK_NO2': '983260',
  217. 'STATUS': '1',
  218. 'PKID': 'C1924F31EE850472E050080A5C00BCBA',
  219. 'ORG_CODE': '153420410',
  220. 'CREATE_BY': 'HR',
  221. 'CREATE_TIME': 1620205014000,
  222. 'ID': '10000RBZ',
  223. 'WORK_NO': '983260',
  224. 'BIRTHDAY': '1967-02-09'
  225. }
  226. ]
  227. """
  228. url = f"{self.datachange_api_service}/datachange/release/interface"
  229. headers = {'Chinasofti-Access-Token': self.LIST_DEPT_TOKEN}
  230. print('API.get_department_list.url:', url)
  231. print('API.get_department_list.headers:', headers)
  232. response = requests.get(url, headers=headers)
  233. # --- check ---
  234. if response.status_code > 300:
  235. print('API.get_department_list.result:', response.status_code)
  236. print('API.get_department_list.detail:', response.text)
  237. return []
  238. # --- check ---
  239. data = response.json()
  240. if data.get('code') != 0:
  241. print('API.get_department_list.code:', data.get('code'))
  242. print('API.get_department_list.data:', response.text)
  243. return []
  244. return data.get('data')
  245. def test(self):
  246. """
  247. """
  248. url = f"http://ycpx04.mccbts.com.cn/cnki-gw/expert/expertType/getExpertTypeList"
  249. data = {
  250. 'keyword': 'xxx'
  251. }
  252. response = requests.post(url, json=data)
  253. print('API.test.url:', url)
  254. print('API.test.data:', data)
  255. print('API.test.code:', response.status_code)
  256. print('API.test.text:', response.text)
  257. # res = res.json()
  258. # data = {
  259. # 'count': len(res['data']),
  260. # 'data': res['data']
  261. # }
  262. if __name__ == '__main__':
  263. # --- init ---
  264. api = API()
  265. # --- test ---
  266. items = api.get_department_list()
  267. for item in items:
  268. if len(item.get('ORG_CODE')) == 3 and item.get('ORG_CODE')[0] == '1':
  269. print(item)
  270. # --- test ---
  271. # out = api.get_expert_type_tree_list()
  272. # print(out)