device.go 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581
  1. // Copyright 2019 github.com. All rights reserved.
  2. // Use of this source code is governed by github.com.
  3. package v1
  4. import (
  5. "github.com/gin-gonic/gin"
  6. "github.com/jaryhe/gopkgs/logger"
  7. "github.com/jaryhe/gopkgs/tasker/httptasker"
  8. "github.com/jaryhe/gopkgs/util"
  9. "go.uber.org/zap"
  10. "net/http"
  11. "smart-enterprise-management-gateway/consts"
  12. "smart-enterprise-management-gateway/errors"
  13. param_v1 "smart-enterprise-management-gateway/param/v1"
  14. "smart-enterprise-management-gateway/pb"
  15. "smart-enterprise-management-gateway/pb/v1"
  16. "smart-enterprise-management-gateway/utils"
  17. "strconv"
  18. "strings"
  19. )
  20. // 设备类型总列表
  21. // @Summary 设备类型总列表
  22. // @Description 设备类型总列表
  23. // @Tags device
  24. // @Accept json
  25. // @Produce json
  26. // @Success 200 {object} v1.DeviceAllTypeListResponse
  27. // @Failure 500 {object} base.HTTPError
  28. // @Router /api/v1/device_type_all [get]
  29. func (c *Controller) DeviceTypeAll(ctx *gin.Context) {
  30. // 业务处理
  31. handleServiceTask := func() error {
  32. // 响应数据
  33. resp := param_v1.DeviceAllTypeListResponse{}
  34. rpcReq := &v1.DeviceAllTypeListRequest{}
  35. reply, err := pb.Enterprise.DeviceAllTypeList(ctx, rpcReq)
  36. if err != nil {
  37. logger.Error("func",
  38. zap.String("call", "DeviceAllTypeList"),
  39. zap.String("error", err.Error()))
  40. return errors.ErrorTransForm(err)
  41. }
  42. resp.Data = *reply
  43. if resp.Data.List == nil {
  44. resp.Data.List= make([]*v1.DeviceAllTypeItem, 0)
  45. }
  46. ctx.JSON(http.StatusOK, resp)
  47. return nil
  48. }
  49. // 执行任务
  50. httptasker.Exec(ctx, handleServiceTask)
  51. }
  52. // 已通过审核的设备类型列表
  53. // @Summary 已通过审核的设备类型列表
  54. // @Description 已通过审核的设备类型列表
  55. // @Tags device
  56. // @Accept json
  57. // @Produce json
  58. // @Param token header string true " "
  59. // @Param filter query string false " "
  60. // @Param page query int true " "
  61. // @Success 200 {object} v1.DeviceTypeListResponse
  62. // @Failure 500 {object} base.HTTPError
  63. // @Router /api/v1/device/type_list [get]
  64. func (c *Controller) DeviceTypeList(ctx *gin.Context) {
  65. // 解析参数
  66. req := &param_v1.DeviceTypeListRequest{}
  67. //var loginUid int64
  68. //var userName string
  69. parseParamTask := func() error {
  70. err := util.ShouldBind(ctx, &req.Header, nil, &req.DeviceTypeListQuery, nil)
  71. if err != nil {
  72. logger.Error("func",
  73. zap.String("call", "util.ShouldBind"),
  74. zap.String("error", err.Error()))
  75. return errors.ParamsError
  76. }
  77. //loginUid, userName, err = utils.GetJwtIdFromCtx(ctx)
  78. return nil
  79. }
  80. // 业务处理
  81. handleServiceTask := func() error {
  82. // 响应数据
  83. resp := param_v1.DeviceTypeListResponse{}
  84. rpcReq := &v1.DeviceTypeListRequest{}
  85. rpcReq.Page = req.Page
  86. if rpcReq.Page < 1 {
  87. rpcReq.Page = 1
  88. }
  89. rpcReq.Filter = req.Filter
  90. req.StatusFilters = "3"
  91. if req.StatusFilters != "" {
  92. array := strings.Split(req.StatusFilters, ",")
  93. for _, v := range array {
  94. value, _ := strconv.Atoi(v)
  95. rpcReq.FilterStatus = append(rpcReq.FilterStatus, int32(value))
  96. }
  97. }
  98. reply, err := pb.Enterprise.DeviceTypeList(ctx, rpcReq)
  99. if err != nil {
  100. s, _ := json.MarshalToString(req)
  101. logger.Error("func",
  102. zap.String("call", "DeviceTypeList"),
  103. zap.String("params", s),
  104. zap.String("error", err.Error()))
  105. return errors.ErrorTransForm(err)
  106. }
  107. resp.Data = *reply
  108. if resp.Data.List == nil {
  109. resp.Data.List = make([]*v1.DeviceTypeItem, 0)
  110. }
  111. ctx.JSON(http.StatusOK, resp)
  112. return nil
  113. }
  114. // 执行任务
  115. httptasker.Exec(ctx, parseParamTask, handleServiceTask)
  116. }
  117. // 扬尘设备列表
  118. // @Summary 扬尘设备列表
  119. // @Description 扬尘设备列表
  120. // @Tags device
  121. // @Accept json
  122. // @Produce json
  123. // @Param token header string true " "
  124. // @Param page query int false " "
  125. // @Param filter query string false " "
  126. // @Param project_id query int64 false " "
  127. // @Param state query int32 false " -1 0 1"
  128. // @Success 200 {object} v1.DeviceListResponse
  129. // @Failure 500 {object} base.HTTPError
  130. // @Router /api/v1/device/dust_list [get]
  131. func (c *Controller) DeviceDustList(ctx *gin.Context) {
  132. // 解析参数
  133. req := &param_v1.DeviceListRequest{}
  134. var loginUid int64
  135. //var userName string
  136. parseParamTask := func() error {
  137. err := util.ShouldBind(ctx, &req.Header, nil, &req.DeviceListQuery, nil)
  138. if err != nil {
  139. logger.Error("func",
  140. zap.String("call", "util.ShouldBind"),
  141. zap.String("error", err.Error()))
  142. return errors.ParamsError
  143. }
  144. loginUid, _, err = utils.GetJwtIdFromCtx(ctx)
  145. return nil
  146. }
  147. // 业务处理
  148. handleServiceTask := func() error {
  149. // 响应数据
  150. resp := param_v1.DeviceListResponse{}
  151. rpcReq := &v1.DeviceListRequest{}
  152. rpcReq.Page = req.Page
  153. if rpcReq.Page < 1 {
  154. rpcReq.Page = 1
  155. }
  156. rpcReq.Cid = loginUid
  157. rpcReq.Filter = req.Filter
  158. rpcReq.TypeCode = consts.DeviceTypeDust
  159. req.FilterStatus = "1"
  160. rpcReq.State = req.State
  161. rpcReq.ProjectId = req.ProjectId
  162. if req.FilterStatus != "" {
  163. array := strings.Split(req.FilterStatus, ",")
  164. for _, v := range array {
  165. value, _ := strconv.Atoi(v)
  166. rpcReq.StatusFilters = append(rpcReq.StatusFilters, int32(value))
  167. }
  168. }
  169. reply, err := pb.Enterprise.DeviceList(ctx, rpcReq)
  170. if err != nil {
  171. s, _ := json.MarshalToString(req)
  172. logger.Error("func",
  173. zap.String("call", "DeviceList"),
  174. zap.String("params", s),
  175. zap.String("error", err.Error()))
  176. return errors.ErrorTransForm(err)
  177. }
  178. resp.Data = *reply
  179. if resp.Data.List == nil {
  180. resp.Data.List = make([]*v1.DeviceItem, 0)
  181. }
  182. ctx.JSON(http.StatusOK, resp)
  183. return nil
  184. }
  185. // 执行任务
  186. httptasker.Exec(ctx, parseParamTask, handleServiceTask)
  187. }
  188. // 塔机设备列表
  189. // @Summary 塔机设备列表
  190. // @Description 塔机设备列表
  191. // @Tags device
  192. // @Accept json
  193. // @Produce json
  194. // @Param token header string true " "
  195. // @Param page query int false " "
  196. // @Param filter query string false " "
  197. // @Param project_id query int64 false " "
  198. // @Param state query int32 false " -1 0 1"
  199. // @Success 200 {object} v1.DeviceListResponse
  200. // @Failure 500 {object} base.HTTPError
  201. // @Router /api/v1/device/tower_list [get]
  202. func (c *Controller) DeviceTowerList(ctx *gin.Context) {
  203. // 解析参数
  204. req := &param_v1.DeviceListRequest{}
  205. var loginUid int64
  206. //var userName string
  207. parseParamTask := func() error {
  208. err := util.ShouldBind(ctx, &req.Header, nil, &req.DeviceListQuery, nil)
  209. if err != nil {
  210. logger.Error("func",
  211. zap.String("call", "util.ShouldBind"),
  212. zap.String("error", err.Error()))
  213. return errors.ParamsError
  214. }
  215. loginUid, _, err = utils.GetJwtIdFromCtx(ctx)
  216. return nil
  217. }
  218. // 业务处理
  219. handleServiceTask := func() error {
  220. // 响应数据
  221. resp := param_v1.DeviceListResponse{}
  222. rpcReq := &v1.DeviceListRequest{}
  223. rpcReq.Page = req.Page
  224. if rpcReq.Page < 1 {
  225. rpcReq.Page = 1
  226. }
  227. rpcReq.Cid = loginUid
  228. rpcReq.Filter = req.Filter
  229. rpcReq.TypeCode = consts.DeviceTypeTower
  230. req.FilterStatus = "1"
  231. rpcReq.State = req.State
  232. rpcReq.ProjectId = req.ProjectId
  233. if req.FilterStatus != "" {
  234. array := strings.Split(req.FilterStatus, ",")
  235. for _, v := range array {
  236. value, _ := strconv.Atoi(v)
  237. rpcReq.StatusFilters = append(rpcReq.StatusFilters, int32(value))
  238. }
  239. }
  240. reply, err := pb.Enterprise.DeviceList(ctx, rpcReq)
  241. if err != nil {
  242. s, _ := json.MarshalToString(req)
  243. logger.Error("func",
  244. zap.String("call", "DeviceList"),
  245. zap.String("params", s),
  246. zap.String("error", err.Error()))
  247. return errors.ErrorTransForm(err)
  248. }
  249. resp.Data = *reply
  250. if resp.Data.List == nil {
  251. resp.Data.List = make([]*v1.DeviceItem, 0)
  252. }
  253. ctx.JSON(http.StatusOK, resp)
  254. return nil
  255. }
  256. // 执行任务
  257. httptasker.Exec(ctx, parseParamTask, handleServiceTask)
  258. }
  259. // 升降机设备列表
  260. // @Summary 升降机设备列表
  261. // @Description 升降机设备列表
  262. // @Tags device
  263. // @Accept json
  264. // @Produce json
  265. // @Param token header string true " "
  266. // @Param page query int false " "
  267. // @Param filter query string false " "
  268. // @Param project_id query int64 false " "
  269. // @Param state query int32 false " -1 0 1"
  270. // @Success 200 {object} v1.DeviceListResponse
  271. // @Failure 500 {object} base.HTTPError
  272. // @Router /api/v1/device/lift_list [get]
  273. func (c *Controller) DeviceLiftList(ctx *gin.Context) {
  274. // 解析参数
  275. req := &param_v1.DeviceListRequest{}
  276. var loginUid int64
  277. //var userName string
  278. parseParamTask := func() error {
  279. err := util.ShouldBind(ctx, &req.Header, nil, &req.DeviceListQuery, nil)
  280. if err != nil {
  281. logger.Error("func",
  282. zap.String("call", "util.ShouldBind"),
  283. zap.String("error", err.Error()))
  284. return errors.ParamsError
  285. }
  286. loginUid, _, err = utils.GetJwtIdFromCtx(ctx)
  287. return nil
  288. }
  289. // 业务处理
  290. handleServiceTask := func() error {
  291. // 响应数据
  292. resp := param_v1.DeviceListResponse{}
  293. rpcReq := &v1.DeviceListRequest{}
  294. rpcReq.Page = req.Page
  295. if rpcReq.Page < 1 {
  296. rpcReq.Page = 1
  297. }
  298. rpcReq.Cid = loginUid
  299. rpcReq.Filter = req.Filter
  300. rpcReq.TypeCode = consts.DeviceTypeLift
  301. req.FilterStatus = "1"
  302. rpcReq.State = req.State
  303. rpcReq.ProjectId = req.ProjectId
  304. if req.FilterStatus != "" {
  305. array := strings.Split(req.FilterStatus, ",")
  306. for _, v := range array {
  307. value, _ := strconv.Atoi(v)
  308. rpcReq.StatusFilters = append(rpcReq.StatusFilters, int32(value))
  309. }
  310. }
  311. reply, err := pb.Enterprise.DeviceList(ctx, rpcReq)
  312. if err != nil {
  313. s, _ := json.MarshalToString(req)
  314. logger.Error("func",
  315. zap.String("call", "DeviceList"),
  316. zap.String("params", s),
  317. zap.String("error", err.Error()))
  318. return errors.ErrorTransForm(err)
  319. }
  320. resp.Data = *reply
  321. if resp.Data.List == nil {
  322. resp.Data.List = make([]*v1.DeviceItem, 0)
  323. }
  324. ctx.JSON(http.StatusOK, resp)
  325. return nil
  326. }
  327. // 执行任务
  328. httptasker.Exec(ctx, parseParamTask, handleServiceTask)
  329. }
  330. // 实名制设备列表
  331. // @Summary 实名制设备列表
  332. // @Description 实名制设备列表
  333. // @Tags device
  334. // @Accept json
  335. // @Produce json
  336. // @Param token header string true " "
  337. // @Param page query int false " "
  338. // @Param filter query string false " "
  339. // @Param project_id query int64 false " "
  340. // @Param state query int32 false " -1 0 1"
  341. // @Success 200 {object} v1.DeviceListResponse
  342. // @Failure 500 {object} base.HTTPError
  343. // @Router /api/v1/device/attendance_list [get]
  344. func (c *Controller) DeviceAttendanceList(ctx *gin.Context) {
  345. // 解析参数
  346. req := &param_v1.DeviceListRequest{}
  347. var loginUid int64
  348. //var userName string
  349. parseParamTask := func() error {
  350. err := util.ShouldBind(ctx, &req.Header, nil, &req.DeviceListQuery, nil)
  351. if err != nil {
  352. logger.Error("func",
  353. zap.String("call", "util.ShouldBind"),
  354. zap.String("error", err.Error()))
  355. return errors.ParamsError
  356. }
  357. loginUid, _, err = utils.GetJwtIdFromCtx(ctx)
  358. return nil
  359. }
  360. // 业务处理
  361. handleServiceTask := func() error {
  362. // 响应数据
  363. resp := param_v1.DeviceListResponse{}
  364. rpcReq := &v1.DeviceListRequest{}
  365. rpcReq.Page = req.Page
  366. if rpcReq.Page < 1 {
  367. rpcReq.Page = 1
  368. }
  369. rpcReq.Cid = loginUid
  370. rpcReq.Filter = req.Filter
  371. rpcReq.TypeCode = consts.DeviceTypeAttendance
  372. req.FilterStatus = "1"
  373. rpcReq.State = req.State
  374. rpcReq.ProjectId = req.ProjectId
  375. if req.FilterStatus != "" {
  376. array := strings.Split(req.FilterStatus, ",")
  377. for _, v := range array {
  378. value, _ := strconv.Atoi(v)
  379. rpcReq.StatusFilters = append(rpcReq.StatusFilters, int32(value))
  380. }
  381. }
  382. reply, err := pb.Enterprise.DeviceList(ctx, rpcReq)
  383. if err != nil {
  384. s, _ := json.MarshalToString(req)
  385. logger.Error("func",
  386. zap.String("call", "DeviceList"),
  387. zap.String("params", s),
  388. zap.String("error", err.Error()))
  389. return errors.ErrorTransForm(err)
  390. }
  391. resp.Data = *reply
  392. if resp.Data.List == nil {
  393. resp.Data.List = make([]*v1.DeviceItem, 0)
  394. }
  395. ctx.JSON(http.StatusOK, resp)
  396. return nil
  397. }
  398. // 执行任务
  399. httptasker.Exec(ctx, parseParamTask, handleServiceTask)
  400. }
  401. // 视频设备列表
  402. // @Summary 视频设备列表
  403. // @Description 视频设备列表
  404. // @Tags device
  405. // @Accept json
  406. // @Produce json
  407. // @Param token header string true " "
  408. // @Param filter query string false "过滤字段"
  409. // @Param project_id query int64 false " "
  410. // @Param state query int32 false "-1,0,1"
  411. // @Param page query int false " "
  412. // @Success 200 {object} v1.VedioListResponse
  413. // @Failure 500 {object} base.HTTPError
  414. // @Router /api/v1/device/vedio_list [get]
  415. func (c *Controller) DeviceVedioList(ctx *gin.Context) {
  416. // 解析参数
  417. req := &param_v1.VedioListRequest{}
  418. var loginUid int64
  419. //var userName string
  420. parseParamTask := func() error {
  421. err := util.ShouldBind(ctx, &req.Header, nil, &req.VedioListQuery, nil)
  422. if err != nil {
  423. logger.Error("func",
  424. zap.String("call", "util.ShouldBind"),
  425. zap.String("error", err.Error()))
  426. return errors.ParamsError
  427. }
  428. loginUid, _, err = utils.GetJwtIdFromCtx(ctx)
  429. return nil
  430. }
  431. // 业务处理
  432. handleServiceTask := func() error {
  433. // 响应数据
  434. resp := param_v1.VedioListResponse{}
  435. rpcReq := &v1.VedioListRequest{}
  436. rpcReq.Page = req.Page
  437. rpcReq.Cid = loginUid
  438. rpcReq.Filter = req.Filter
  439. rpcReq.Cid = loginUid
  440. rpcReq.ProjectId = req.ProjectId
  441. rpcReq.State = req.State
  442. rpcReq.StatusFilters = append(rpcReq.StatusFilters, 1)
  443. /*
  444. if req.FilterStatus != "" {
  445. array := strings.Split(req.FilterStatus, ",")
  446. for _, v := range array {
  447. value, _ := strconv.Atoi(v)
  448. rpcReq.StatusFilters = append(rpcReq.StatusFilters, int32(value))
  449. }
  450. }*/
  451. reply, err := pb.Enterprise.VedioList(ctx, rpcReq)
  452. if err != nil {
  453. s, _ := json.MarshalToString(req)
  454. logger.Error("func",
  455. zap.String("call", "VedioList"),
  456. zap.String("params", s),
  457. zap.String("error", err.Error()))
  458. return errors.ErrorTransForm(err)
  459. }
  460. resp.Data = *reply
  461. if resp.Data.List == nil {
  462. resp.Data.List = make([]*v1.VedioItem, 0)
  463. }
  464. ctx.JSON(http.StatusOK, resp)
  465. return nil
  466. }
  467. // 执行任务
  468. httptasker.Exec(ctx, parseParamTask, handleServiceTask)
  469. }
  470. // 通道列表
  471. // @Summary 通道列表
  472. // @Description 通道列表
  473. // @Tags device
  474. // @Accept json
  475. // @Produce json
  476. // @Param token header string true " "
  477. // @Param sn query string true " "
  478. // @Param page query int false " "
  479. // @Param channel_no query string false " "
  480. // @Success 200 {object} v1.ChannelListResponse
  481. // @Failure 500 {object} base.HTTPError
  482. // @Router /api/v1/device/vedio_channel_list [get]
  483. func (c *Controller) DeviceVedioChannelList(ctx *gin.Context) {
  484. // 解析参数
  485. req := &param_v1.ChannelListRequest{}
  486. //var loginUid int64
  487. //var userName string
  488. parseParamTask := func() error {
  489. err := util.ShouldBind(ctx, &req.Header, nil, &req.ChannelListQuery, nil)
  490. if err != nil {
  491. logger.Error("func",
  492. zap.String("call", "util.ShouldBind"),
  493. zap.String("error", err.Error()))
  494. return errors.ParamsError
  495. }
  496. //loginUid, userName, err = utils.GetJwtIdFromCtx(ctx)
  497. return nil
  498. }
  499. // 业务处理
  500. handleServiceTask := func() error {
  501. // 响应数据
  502. resp := param_v1.ChannelListResponse{}
  503. rpcReq := &v1.ChannelListRequest{}
  504. rpcReq.Page = req.Page
  505. rpcReq.Sn = req.Sn
  506. rpcReq.ChannelNo = req.ChannelNo
  507. /*
  508. if req.FilterStatus != "" {
  509. array := strings.Split(req.FilterStatus, ",")
  510. for _, v := range array {
  511. value, _ := strconv.Atoi(v)
  512. rpcReq.StatusFilters = append(rpcReq.StatusFilters, int32(value))
  513. }
  514. }*/
  515. reply, err := pb.Enterprise.ChannelList(ctx, rpcReq)
  516. if err != nil {
  517. s, _ := json.MarshalToString(req)
  518. logger.Error("func",
  519. zap.String("call", "ChannelList"),
  520. zap.String("params", s),
  521. zap.String("error", err.Error()))
  522. return errors.ErrorTransForm(err)
  523. }
  524. resp.Data = *reply
  525. if resp.Data.List == nil {
  526. resp.Data.List = make([]*v1.ChannelItem, 0)
  527. }
  528. ctx.JSON(http.StatusOK, resp)
  529. return nil
  530. }
  531. // 执行任务
  532. httptasker.Exec(ctx, parseParamTask, handleServiceTask)
  533. }