index.ts 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454
  1. import qs from 'qs';
  2. import { request } from '@/utils';
  3. import type {
  4. AddInterface,
  5. AgreementUpdate,
  6. DeviceGroupItem,
  7. DevicesList,
  8. DictTypeData,
  9. DictTypeDataParams,
  10. EquipmentInformationForm,
  11. EquipmentTypeItem,
  12. EquipmentUpdateForm,
  13. GatewayInformation,
  14. GatewayInterface,
  15. GatewayModelInfo,
  16. GetListItem,
  17. GroupingList,
  18. GroupingListData,
  19. InterfaceData,
  20. ListEquipmentParametersItemData,
  21. ListInfo,
  22. ListInterfaces,
  23. ListPhysicalInterfaces,
  24. ParameterVerification,
  25. PostProtocolPage,
  26. PostProtocolPageItemData,
  27. ProtocolBaseInfo,
  28. ProtocolGatewayListListItem,
  29. ProtocolItemData,
  30. ProtocolList,
  31. ProtocolListItem,
  32. ProtocolParamData,
  33. ProtocolParamInfo,
  34. ProtocolParamSearchParams,
  35. ProtocolReset,
  36. ProtocolStandardParamData,
  37. ProtocolStandardParamSearchParams,
  38. SerialNumberItemData,
  39. VerificationAgreement,
  40. VerificationEquipment,
  41. } from '@/types';
  42. /**
  43. * 获取认证授权服务 url
  44. */
  45. const apiUaa = (path: string, params?: unknown) => {
  46. const apiUrl = params ? `${path}?${qs.stringify(params)}` : path;
  47. return `/api-uaa${apiUrl}`;
  48. };
  49. /**
  50. * 获取系统服务 url
  51. */
  52. const apiSys = (path: string, params?: unknown) => {
  53. const apiUrl = params ? `${path}?${qs.stringify(params)}` : path;
  54. return `/api-sys${apiUrl}`;
  55. };
  56. /**
  57. * 获取业务服务 url
  58. */
  59. const apiBiz = (path: string, params?: unknown) => {
  60. const apiUrl = params ? `${path}?${qs.stringify(params)}` : path;
  61. return `/api-biz${apiUrl}`;
  62. };
  63. // ----- 认证授权服务 -----
  64. // 登录和注销
  65. export const loginUser = async () => {
  66. const params = {
  67. grant_type: 'password',
  68. username: 'admin1',
  69. password: 'admin',
  70. };
  71. await request(apiUaa('/oauth/token', params), {
  72. method: 'POST',
  73. headers: {
  74. Authorization: 'Basic ' + btoa('unimat:unimat'),
  75. },
  76. });
  77. };
  78. export const logoutUser = async () => {
  79. await request(apiUaa('/oauth/remove/token'));
  80. };
  81. export const refreshUser = async () => {
  82. await request(apiUaa('/oauth/token'));
  83. };
  84. // ----- 系统服务 -----
  85. // 字典类型表
  86. export const getDictTypeData = async (params: DictTypeDataParams) => {
  87. const data = await request<DictTypeData[]>(apiSys('/sysDictType/typeAndData/', params));
  88. return data;
  89. };
  90. // ----- 业务服务 -----
  91. // 设备组列表
  92. export const getPageList = async () => {
  93. const data = await request<DeviceGroupItem[]>(apiBiz('/deviceGroup/getList'), {
  94. method: 'POST',
  95. });
  96. return data;
  97. };
  98. // 设备列表
  99. export const deviceAdd = async (equipmentInformationForm: EquipmentInformationForm) => {
  100. const data = await request<number>(apiBiz('/device/add'), {
  101. method: 'POST',
  102. body: JSON.stringify(equipmentInformationForm),
  103. });
  104. return data;
  105. };
  106. export const deviceDeletion = async (id: number) => {
  107. await request(apiBiz(`${'/device/delete/'}${id}`), {
  108. method: 'POST',
  109. });
  110. };
  111. export const queryDevicesList = async (devicesList: DevicesList) => {
  112. await request(apiBiz('/device/getPageList'), {
  113. method: 'POST',
  114. body: JSON.stringify(devicesList),
  115. });
  116. };
  117. // 设备网关
  118. export const deviceGatewayUpdate = async (equipmentUpdateForm: EquipmentUpdateForm[]) => {
  119. await request(apiBiz('/deviceGateway/update'), {
  120. method: 'POST',
  121. body: JSON.stringify(equipmentUpdateForm),
  122. });
  123. };
  124. // 设备协议参数验证
  125. export const postParameterVerification = async (deviceId: number) => {
  126. const data = await request<ParameterVerification[]>(apiBiz('/protocolParamVerify/list'), {
  127. method: 'POST',
  128. body: JSON.stringify(deviceId),
  129. });
  130. return data;
  131. };
  132. // 设备参数分组
  133. export const equipmentParametersList = async (groupingList: GroupingList[]) => {
  134. await request(apiBiz('/deviceParamGroup/update/batch'), {
  135. method: 'POST',
  136. body: JSON.stringify(groupingList),
  137. });
  138. };
  139. export const queryEquipmentParametersList = async (deviceId: number) => {
  140. const data = await request<GroupingListData[]>(apiBiz('/deviceParamGroup/getList'), {
  141. method: 'POST',
  142. body: JSON.stringify({ deviceId }),
  143. });
  144. return data;
  145. };
  146. // 网关基本信息
  147. export const addGateway = async () => {
  148. await request(apiBiz('/gateway/add'));
  149. };
  150. export const validateGatewayInfo = async (registerGatewayForm: VerificationEquipment) => {
  151. const data = await request<GatewayInformation>(apiBiz('/gateway/validate', registerGatewayForm), {
  152. method: 'POST',
  153. });
  154. return data;
  155. };
  156. // 网关通讯
  157. export const gatewayLinkAdd = async (addInterface: AddInterface) => {
  158. await request(apiBiz('/gatewayLink/add'), {
  159. method: 'POST',
  160. body: JSON.stringify(addInterface),
  161. });
  162. };
  163. export const gatewayLinkDelete = async (id: number) => {
  164. await request(apiBiz(`${'/gatewayLink/delete/'}${id}`), {
  165. method: 'POST',
  166. });
  167. };
  168. export const gatewayLinkGetList = async (gatewayId: number) => {
  169. const data = await request<InterfaceData[]>(apiBiz(`${'/gatewayLink/getList/'}${gatewayId}`), {
  170. method: 'POST',
  171. });
  172. return data;
  173. };
  174. export const gatewayLinkUpdate = async (agreementUpdate: AgreementUpdate) => {
  175. await request(apiBiz('/gatewayLink/update'), {
  176. method: 'POST',
  177. body: JSON.stringify(agreementUpdate),
  178. });
  179. };
  180. // 网关型号
  181. export const getGatewayModelInfo = async (id: number) => {
  182. const data = await request<GatewayModelInfo>(apiBiz(`${'/gatewayModel/info/'}${id}`));
  183. return data;
  184. };
  185. export const getGatewayModelInterfaces = async (id: number) => {
  186. const data = await request<GatewayInterface[]>(apiBiz(`${'/gatewayModel/interfaces/'}${id}`), {
  187. method: 'POST',
  188. });
  189. return data;
  190. };
  191. // 网关物理接口协议
  192. export const obtainListPhysicalInterfaces = async (id: number) => {
  193. const data = await request<ListPhysicalInterfaces[]>(apiBiz(`${'/gatewayInterfaceProtocol/getProtocols/'}${id}`));
  194. return data;
  195. };
  196. // 网关型号物理接口
  197. export const obtainListInterfaces = async (id: number) => {
  198. const data = await request<ListInterfaces[]>(apiBiz(`${'/gatewayPhysicalInterface/getInterfaces/'}${id}`));
  199. return data;
  200. };
  201. // 网关接口协议
  202. export const gatewayLinkProtocolList = async <T>(protocolListItem: ProtocolListItem) => {
  203. const data = await request<T>(apiBiz('/gatewayLinkProtocol/getParamPageList'), {
  204. method: 'POST',
  205. body: JSON.stringify(protocolListItem),
  206. });
  207. return data;
  208. };
  209. export const gatewayLinkProtocolGatewayList = async (protocolGatewayListListItem: ProtocolGatewayListListItem) => {
  210. const data = await request<ListEquipmentParametersItemData>(
  211. apiBiz('/gatewayLinkProtocol/getParamPageListByGateway'),
  212. {
  213. method: 'POST',
  214. body: JSON.stringify(protocolGatewayListListItem),
  215. },
  216. );
  217. return data;
  218. };
  219. export const gatewayLinkList = async (id: number) => {
  220. const data = await request<VerificationAgreement[]>(apiBiz(`${'/gatewayLinkProtocol/getProtocolInfoList/'}${id}`), {
  221. method: 'POST',
  222. });
  223. return data;
  224. };
  225. export const gatewayLinkProtocolReset = async (protocolReset: ProtocolReset) => {
  226. await request(apiBiz('/gatewayLinkProtocol/reset'), {
  227. method: 'POST',
  228. body: JSON.stringify(protocolReset),
  229. });
  230. };
  231. export const postProtocolCandidatesList = async (protocolList: ProtocolList, gatewayId: number) => {
  232. const data = await request<ProtocolItemData>(apiBiz(`${'/gatewayLinkProtocol/getProtocolCandidates/'}${gatewayId}`), {
  233. method: 'POST',
  234. body: JSON.stringify(protocolList),
  235. });
  236. return data;
  237. };
  238. // 组织网关
  239. export const orgGatewayRegister = async (gatewayId: number) => {
  240. await request(apiBiz('/orgGateway/register'), {
  241. method: 'POST',
  242. body: JSON.stringify({ gatewayId }),
  243. });
  244. };
  245. export const orgGatewaySerialNumber = async (protocolList: ProtocolList) => {
  246. const data = await request<SerialNumberItemData>(apiBiz('/orgGateway/getGatewayPageList'), {
  247. method: 'POST',
  248. body: JSON.stringify(protocolList),
  249. });
  250. return data;
  251. };
  252. // 协议标准参数
  253. export const getProtocolStandardParamList = async (params: ProtocolStandardParamSearchParams) => {
  254. const data = await request<ProtocolStandardParamData>(apiBiz('/protocolStandardParam/getPageList'), {
  255. method: 'POST',
  256. body: JSON.stringify(params),
  257. });
  258. return data;
  259. };
  260. // 协议参数
  261. export const addProtocolParam = async (params: Partial<ProtocolParamInfo>) => {
  262. await request(apiBiz('/protocolParamInfo/add'), {
  263. method: 'POST',
  264. body: JSON.stringify(params),
  265. });
  266. };
  267. export const getProtocolParamList = async (params: ProtocolParamSearchParams) => {
  268. const data = await request<ProtocolParamData>(apiBiz('/protocolParamInfo/getPageList'), {
  269. method: 'POST',
  270. body: JSON.stringify(params),
  271. });
  272. return data;
  273. };
  274. export const batchDeleleProtocolParam = async (params: number[]) => {
  275. await request(apiBiz('/protocolParamInfo/batchDeleleByIds'), {
  276. method: 'POST',
  277. body: JSON.stringify(params),
  278. });
  279. };
  280. // 协议基本信息
  281. export const addProtocolBaseInfo = async () => {
  282. await request(apiBiz('/protocolBaseInfo/add'), {
  283. method: 'POST',
  284. });
  285. };
  286. export const downloadProtocolTemplate = async (fileName: string) => {
  287. const blob = await request<Blob>(apiBiz(`/protocolBaseInfo/downloadTemplate/${fileName}`));
  288. return blob;
  289. };
  290. export const uploadUserProtocol = async (protocolType: string, file: Blob) => {
  291. const formData = new FormData();
  292. formData.append('file', file);
  293. const data = await request<Pick<ProtocolBaseInfo, 'id' | 'protocolName' | 'protocolType'>>(
  294. apiBiz('/protocolBaseInfo/uploadUserTemplate/', { protocolType }),
  295. {
  296. method: 'POST',
  297. body: formData,
  298. },
  299. );
  300. return data;
  301. };
  302. export const reUploadUserProtocol = async (protocolType: string, id: number, file: Blob) => {
  303. const formData = new FormData();
  304. formData.append('file', file);
  305. const data = await request<Pick<ProtocolBaseInfo, 'id' | 'protocolName' | 'protocolType'>>(
  306. apiBiz('/protocolBaseInfo/resetConfiguration/', { protocolType, id }),
  307. {
  308. method: 'POST',
  309. body: formData,
  310. },
  311. );
  312. return data;
  313. };
  314. export const downloadUserProtocol = async (protocolType: string, protocolName: string) => {
  315. const blob = await request<Blob>(
  316. apiBiz('/protocolBaseInfo/downloadUserProtocol/', {
  317. protocolType,
  318. protocolName,
  319. }),
  320. );
  321. return blob;
  322. };
  323. /**
  324. * @deprecated
  325. */
  326. export const getUploadProtocol = async (protocolType: string, protocolName: string) => {
  327. const data = await request<ProtocolBaseInfo>(
  328. apiBiz('/protocolBaseInfo/findUploadProtocolBaseInfo/', {
  329. protocolType,
  330. protocolName,
  331. }),
  332. );
  333. return data;
  334. };
  335. export const getProtocolBaseInfo = async (id: number) => {
  336. const data = await request<ProtocolBaseInfo>(apiBiz(`/protocolBaseInfo/info/${id}`));
  337. return data;
  338. };
  339. export const updateProtocolBaseInfo = async (params: Partial<ProtocolBaseInfo>) => {
  340. await request(apiBiz('/protocolBaseInfo/update'), {
  341. method: 'POST',
  342. body: JSON.stringify(params),
  343. });
  344. };
  345. export const postProtocolList = async (protocolList: ProtocolList) => {
  346. const data = await request<ProtocolItemData>(apiBiz('/protocolBaseInfo/getPageList'), {
  347. method: 'POST',
  348. body: JSON.stringify(protocolList),
  349. });
  350. return data;
  351. };
  352. // 协议参数表
  353. export const postProtocolPageList = async (postProtocolPage: PostProtocolPage) => {
  354. const data = await request<PostProtocolPageItemData>(apiBiz('/protocolParamInfo/page/list'), {
  355. method: 'POST',
  356. body: JSON.stringify(postProtocolPage),
  357. });
  358. return data;
  359. };
  360. export const postProtocolGetList = async (getListItem: GetListItem) => {
  361. const data = await request<PostProtocolPageItemData>(apiBiz('/protocolParamInfo/getList'), {
  362. method: 'POST',
  363. body: JSON.stringify(getListItem),
  364. });
  365. return data;
  366. };
  367. // 全局参数
  368. export const groupList = async (listInfo: ListInfo) => {
  369. const data = await request<EquipmentTypeItem[]>(apiBiz('/deviceGlobalData/getList'), {
  370. method: 'POST',
  371. body: JSON.stringify(listInfo),
  372. });
  373. return data;
  374. };