device.js 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525
  1. import request, { tenantRequest } from '@/utils/request'
  2. import {
  3. add,
  4. update,
  5. del,
  6. confirm,
  7. messageSend,
  8. send,
  9. confirmAndSend,
  10. addTenant,
  11. addTenantOrOrg,
  12. addUser,
  13. addOrg
  14. } from './base'
  15. import {
  16. AssetType,
  17. AlarmStrategies
  18. } from '@/constant'
  19. export function getRatiosWithUser () {
  20. return tenantRequest({
  21. url: '/device/resolutionRatio',
  22. method: 'GET',
  23. params: addTenantOrOrg({})
  24. }).then(({ data }) => {
  25. return {
  26. data: Object.keys(data).map(key => {
  27. return {
  28. value: key,
  29. label: `${key} ${data[key].slice(0, 3).map(device => device.name).join(', ')}`
  30. }
  31. })
  32. }
  33. })
  34. }
  35. export function getRatios () {
  36. return tenantRequest({
  37. url: '/device/resolutionRatio',
  38. method: 'GET',
  39. params: addTenant({})
  40. }).then(({ data }) => {
  41. return {
  42. data: Object.keys(data).map(key => {
  43. return {
  44. value: key,
  45. label: key
  46. }
  47. })
  48. }
  49. })
  50. }
  51. export function getTimeline (deviceId, options) {
  52. return request({
  53. url: `/content/deviceCalender/${deviceId}`,
  54. method: 'GET',
  55. ...options
  56. }).then(({ data }) => JSON.parse(data.eventDetail) || [])
  57. }
  58. export function addDevice (data) {
  59. return add({
  60. url: '/device',
  61. method: 'POST',
  62. data
  63. })
  64. }
  65. export function updateDevice (data) {
  66. return update({
  67. url: '/device',
  68. method: 'put',
  69. data
  70. })
  71. }
  72. export function deleteDevice ({ id, name }) {
  73. return send({
  74. url: `/device/${id}/standbyDevice`,
  75. method: 'GET',
  76. params: { pageNum: 1, pageSize: 1 }
  77. }).then(({ data }) => confirm(
  78. data.length
  79. ? `删除主设备后备份设备也将删除`
  80. : `删除 ${name} ?`,
  81. data.length
  82. ? `删除 ${name}`
  83. : null
  84. )).then(() => messageSend({
  85. url: `/device/${id}`,
  86. method: 'DELETE'
  87. }, '删除'))
  88. }
  89. export function getDevices (query, options) {
  90. const scope = addTenantOrOrg({})
  91. if (scope.tenant) {
  92. return getDevicesByAdmin({
  93. ...query,
  94. ...scope
  95. }, options)
  96. }
  97. const { pageNum: pageIndex, pageSize, ...params } = query
  98. return tenantRequest({
  99. url: '/device/relation/page',
  100. method: 'GET',
  101. params: {
  102. pageIndex, pageSize,
  103. ...params,
  104. ...scope
  105. },
  106. ...options
  107. })
  108. }
  109. export function getDevicesByAdmin (query, options) {
  110. const { pageNum: pageIndex, pageSize, ...params } = query
  111. return tenantRequest({
  112. url: params.tenant ? '/device/tenant/page' : '/device/relation/page',
  113. method: 'GET',
  114. params: {
  115. pageIndex, pageSize,
  116. ...params
  117. },
  118. ...options
  119. })
  120. }
  121. export function getBoundDevices (query, options) {
  122. const { pageNum: pageIndex, pageSize, ...params } = query
  123. return request({
  124. url: '/device/allocate/page',
  125. method: 'GET',
  126. params: {
  127. pageIndex, pageSize,
  128. ...params
  129. },
  130. ...options
  131. })
  132. }
  133. export function bindDeviceToObject (deviceId, org) {
  134. return send({
  135. url: '/device/allocate/department',
  136. method: 'POST',
  137. data: { deviceId, org }
  138. })
  139. }
  140. export function unbindDevice ({ deviceRelationId, name }) {
  141. return confirmAndSend('移除', name, {
  142. url: `/device/allocate/${deviceRelationId}`,
  143. method: 'DELETE'
  144. })
  145. }
  146. export function unbindDevices (params) {
  147. return request({
  148. url: '/device/allocate/department',
  149. method: 'DELETE',
  150. params
  151. })
  152. }
  153. export function activateDevice ({ id, name }) {
  154. return confirmAndSend('激活', name, {
  155. url: '/device/batch/activate',
  156. method: 'put',
  157. data: [id]
  158. })
  159. }
  160. export function deactivateDevice ({ id, name }) {
  161. return confirmAndSend('停用', name, {
  162. url: '/device/batch/deactivate',
  163. method: 'put',
  164. data: [id]
  165. })
  166. }
  167. export function getDevice (id) {
  168. return request({
  169. url: `/device/${id}`,
  170. method: 'GET'
  171. })
  172. }
  173. export function getSubDevices (query) {
  174. const { id, pageNum: pageIndex, pageSize, ...params } = query
  175. return request({
  176. url: `/device/${id}/standbyDevice`,
  177. method: 'GET',
  178. params: {
  179. pageIndex, pageSize,
  180. ...params
  181. }
  182. })
  183. }
  184. export function addSubDevice ({ id }, data) {
  185. return add({
  186. url: `/device/${id}/addStandby`,
  187. method: 'POST',
  188. data
  189. })
  190. }
  191. export function addProductType (data) {
  192. return add({
  193. url: '/productType',
  194. method: 'POST',
  195. data
  196. })
  197. }
  198. export function updateProductType (data) {
  199. return update({
  200. url: '/productType',
  201. method: 'put',
  202. data
  203. })
  204. }
  205. export function deleteProductType ({ id, name }) {
  206. return del({
  207. url: `/productType/${id}`,
  208. method: 'DELETE'
  209. }, name)
  210. }
  211. export function getProductTypes (query) {
  212. const { pageNum: pageIndex, pageSize, ...params } = query
  213. return tenantRequest({
  214. url: '/productType/list',
  215. method: 'GET',
  216. params: addTenant({
  217. pageIndex, pageSize,
  218. ...params
  219. })
  220. })
  221. }
  222. export function addProduct (data) {
  223. return add({
  224. url: '/product',
  225. method: 'POST',
  226. data
  227. })
  228. }
  229. export function updateProduct (data) {
  230. return update({
  231. url: '/product',
  232. method: 'put',
  233. data
  234. })
  235. }
  236. export function deleteProduct ({ id, name }) {
  237. return del({
  238. url: `/product/${id}`,
  239. method: 'DELETE'
  240. }, name)
  241. }
  242. export function getProducts (query) {
  243. const { pageNum: pageIndex, pageSize, ...params } = query
  244. return tenantRequest({
  245. url: '/product/list',
  246. method: 'GET',
  247. params: addTenant({
  248. pageIndex, pageSize,
  249. ...params
  250. })
  251. })
  252. }
  253. export function addDeviceGroup (data) {
  254. return add({
  255. url: '/deviceGroup',
  256. method: 'POST',
  257. data: addOrg(data, false)
  258. })
  259. }
  260. export function updateDeviceGroup (data) {
  261. return update({
  262. url: '/deviceGroup',
  263. method: 'PUT',
  264. data
  265. })
  266. }
  267. export function deleteDeviceGroup ({ id, name }) {
  268. return del({
  269. url: `/deviceGroup/${id}`,
  270. method: 'DELETE'
  271. }, name)
  272. }
  273. export function getDeviceGroups (query) {
  274. const { pageNum: pageIndex, pageSize, ...params } = query
  275. return tenantRequest({
  276. url: '/deviceGroup/list',
  277. method: 'GET',
  278. params: addUser({
  279. pageIndex, pageSize,
  280. ...params
  281. })
  282. })
  283. }
  284. export function getDevicesByGroup (id) {
  285. return tenantRequest({
  286. url: `/deviceGroup/${id}/device`,
  287. method: 'GET',
  288. params: addTenantOrOrg({})
  289. })
  290. }
  291. export function getDeviceTree () {
  292. return tenantRequest({
  293. url: '/deviceGroup/deviceTree',
  294. method: 'GET',
  295. params: addUser(addTenantOrOrg({}))
  296. })
  297. }
  298. export function addDeviceToGroup (id, deviceId) {
  299. return add({
  300. url: `/deviceGroup/${id}/device`,
  301. method: 'POST',
  302. data: [].concat(deviceId)
  303. })
  304. }
  305. export function deleteDeviceFromGroup (id, { id: deviceId, name }) {
  306. return confirmAndSend('移除', name, {
  307. url: `/deviceGroup/${id}/device`,
  308. method: 'DELETE',
  309. params: { deviceId }
  310. })
  311. }
  312. export function getDeviceStatistics (productId) {
  313. return tenantRequest({
  314. url: '/device/listDeviceTotal',
  315. method: 'GET',
  316. params: addTenantOrOrg({ productId })
  317. })
  318. }
  319. export function getDeviceAlarms (query) {
  320. const { pageNum: pageIndex, pageSize, ...params } = query
  321. return request({
  322. url: '/deviceException/list',
  323. method: 'GET',
  324. params: {
  325. pageIndex, pageSize,
  326. ...params
  327. }
  328. }).then(({ data, totalCount }) => {
  329. return {
  330. data: data.map(({ id, deviceName, level, pic, picUrl, type, handle, status, happenTime, ...item }) => {
  331. const alarm = {
  332. id, deviceName, level, happenTime,
  333. asset: pic && picUrl
  334. ? {
  335. type: AssetType.IMAGE,
  336. url: picUrl,
  337. thumbnail: picUrl
  338. }
  339. : null,
  340. type: getType(type),
  341. handle: ['应用重启', '设备重启', '恢复出厂', '未干预'][handle] || '-',
  342. status: handle <= 2 && status <= 2
  343. ? {
  344. type: ['primary', 'success', 'danger'][status],
  345. label: ['处理中', '成功', '失败'][status]
  346. }
  347. : { label: '-' }
  348. }
  349. AlarmStrategies.forEach(({ key }) => {
  350. alarm[key] = getTag(item[key])
  351. })
  352. return alarm
  353. }),
  354. totalCount
  355. }
  356. })
  357. }
  358. const AlarmType = {
  359. 0: '疑似黑屏',
  360. 1: '设备离线',
  361. 2: '屏幕拓扑结构异常',
  362. 3: '播放非法视频',
  363. 4: '接收卡离线',
  364. 5: '发送控制设备离线',
  365. 6: '浪潮智能网关离线',
  366. 7: '屏幕监控摄像头离线',
  367. 8: '人流监测摄像头离线',
  368. 9: '设备上线',
  369. 10: '回采疑似',
  370. 11: '回采不合规',
  371. 12: '空档期',
  372. 1000: '分割器异常'
  373. }
  374. function getType (type) {
  375. if (type >= 1101 && type <= 1116) {
  376. type = 1000
  377. }
  378. return AlarmType[type] || '-'
  379. }
  380. function getTag (value) {
  381. switch (value) {
  382. case 0:
  383. return {
  384. type: 'danger',
  385. label: '否'
  386. }
  387. case 1:
  388. return {
  389. type: 'success',
  390. label: '是'
  391. }
  392. default:
  393. return { label: '-' }
  394. }
  395. }
  396. export function getTasks (query) {
  397. const { pageNum: pageIndex, pageSize, ...params } = query
  398. return request({
  399. url: '/device/functionTask',
  400. method: 'GET',
  401. params: {
  402. pageIndex, pageSize,
  403. ...params
  404. }
  405. })
  406. }
  407. export function addTask (task) {
  408. return add({
  409. url: '/device/functionTask',
  410. method: 'POST',
  411. data: task
  412. })
  413. }
  414. export function updateTask (task) {
  415. return update({
  416. url: '/device/functionTask',
  417. method: 'PUT',
  418. data: task
  419. })
  420. }
  421. export function deleteTask ({ taskId }) {
  422. return del({
  423. url: `/device/functionTask/${taskId}`,
  424. method: 'DELETE'
  425. })
  426. }
  427. export function activateTask ({ taskId }) {
  428. return confirmAndSend('启用', null, {
  429. url: '/device/functionTask/resume',
  430. method: 'PUT',
  431. data: [taskId]
  432. })
  433. }
  434. export function deactivateTask ({ taskId }) {
  435. return confirmAndSend('停用', null, {
  436. url: '/device/functionTask/pause',
  437. method: 'PUT',
  438. data: [taskId]
  439. })
  440. }
  441. export function getShadow (deviceId) {
  442. return request({
  443. url: `/device/shadow/${deviceId}`,
  444. method: 'GET'
  445. })
  446. }
  447. export function getRecordConfig (deviceId, config) {
  448. return request({
  449. url: '/deviceStream/config',
  450. method: 'GET',
  451. params: { deviceId },
  452. ...config
  453. })
  454. }
  455. export function addRecordConfig (data, config) {
  456. return request({
  457. url: '/deviceStream/config',
  458. method: 'POST',
  459. data,
  460. ...config
  461. })
  462. }
  463. export function updateRecordConfig (data, config) {
  464. return request({
  465. url: '/deviceStream/config',
  466. method: 'PUT',
  467. data,
  468. ...config
  469. })
  470. }
  471. export function authCode (stream) {
  472. return request({
  473. url: `/deviceStream/${stream}/authCode`,
  474. method: 'GET'
  475. })
  476. }