device.go 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940
  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-supplier-management-gateway/errors"
  12. param_v1 "smart-supplier-management-gateway/param/v1"
  13. "smart-supplier-management-gateway/pb"
  14. "smart-supplier-management-gateway/pb/v1"
  15. "smart-supplier-management-gateway/utils"
  16. "strconv"
  17. "strings"
  18. )
  19. // 设备对接
  20. // @Summary 设备对接
  21. // @Description 设备对接
  22. // @Tags device
  23. // @Accept json
  24. // @Produce json
  25. // @Param token header string true "设备类型"
  26. // @Param body body v1.DeviceDockingBody true "设备类型"
  27. // @Success 200 {object} v1.DeviceDockingResponse
  28. // @Failure 500 {object} base.HTTPError
  29. // @Router /api/v1/device/docking [post]
  30. func (c *Controller) DeviceDocking(ctx *gin.Context) {
  31. // 解析参数
  32. var userName string
  33. var loginUid int64
  34. req := &param_v1.DeviceDockingRequest{}
  35. parseParamTask := func() error {
  36. err := util.ShouldBind(ctx, nil, nil, nil, &req.DeviceDockingBody)
  37. if err != nil {
  38. logger.Error("func",
  39. zap.String("call", "util.ShouldBind"),
  40. zap.String("error", err.Error()))
  41. return errors.ParamsError
  42. }
  43. userName, loginUid, err = utils.GetTokenInfo(ctx)
  44. return nil
  45. }
  46. // 业务处理
  47. handleServiceTask := func() error {
  48. uid, err := utils.GetJwtIdFromCtx(ctx)
  49. if err != nil {
  50. return err
  51. }
  52. // 响应数据
  53. resp := param_v1.DeviceDockingResponse{}
  54. rpcReq := &v1.DeviceDockingRequest{
  55. DeviceType:req.DeviceType,
  56. Uid:uid,
  57. }
  58. rpcRsp, err := pb.Supplier.DeviceDocking(ctx, rpcReq)
  59. if err != nil {
  60. s, _ := json.MarshalToString(req)
  61. logger.Error("func",
  62. zap.String("call", "DeviceDocking"),
  63. zap.String("params", s),
  64. zap.String("error", err.Error()))
  65. return err
  66. }
  67. resp.Data = *rpcRsp
  68. ctx.JSON(http.StatusOK, resp)
  69. return nil
  70. }
  71. // 执行任务
  72. err := httptasker.Exec(ctx, parseParamTask, handleServiceTask)
  73. s, _ := json.MarshalToString(req)
  74. utils.LogWrite("设备对接申请", loginUid, userName, s, err, 0)
  75. }
  76. // 添加设备
  77. // @Summary 添加设备
  78. // @Description 添加设备
  79. // @Tags device
  80. // @Accept json
  81. // @Produce json
  82. // @Param token header string true " "
  83. // @Param body body v1.DeviceAddBody true " "
  84. // @Success 200 {object} v1.DeviceAddResponse
  85. // @Failure 500 {object} base.HTTPError
  86. // @Router /api/v1/device [post]
  87. func (c *Controller) DeviceAdd(ctx *gin.Context) {
  88. // 解析参数
  89. req := &param_v1.DeviceAddRequest{}
  90. var loginUid int64
  91. var userName string
  92. parseParamTask := func() error {
  93. err := util.ShouldBind(ctx, &req.Header, nil, nil, &req.DeviceAddBody)
  94. if err != nil {
  95. logger.Error("func",
  96. zap.String("call", "util.ShouldBind"),
  97. zap.String("error", err.Error()))
  98. return errors.ParamsError
  99. }
  100. userName, loginUid, _ = utils.GetTokenInfo(ctx)
  101. return nil
  102. }
  103. // 业务处理
  104. handleServiceTask := func() error {
  105. // 响应数据
  106. resp := param_v1.DeviceAddResponse{}
  107. rpcReq := &v1.DeviceAddRequest{}
  108. utils.StructCopy(rpcReq, &req.DeviceAddBody, "")
  109. rpcReq.ProviderId = loginUid
  110. rpcRsp, err := pb.Supplier.DeviceAdd(ctx, rpcReq)
  111. if err != nil {
  112. s, _ := json.MarshalToString(req)
  113. logger.Error("func",
  114. zap.String("call", "DeviceAdd"),
  115. zap.String("params", s),
  116. zap.String("error", err.Error()))
  117. return errors.ErrorTransForm(err)
  118. }
  119. resp.Data = *rpcRsp
  120. ctx.JSON(http.StatusOK, resp)
  121. return nil
  122. }
  123. // 执行任务
  124. err := httptasker.Exec(ctx, parseParamTask, handleServiceTask)
  125. s, _ := json.MarshalToString(req)
  126. utils.LogWrite("设备入库申请", loginUid, userName, s, err, req.ProjectId)
  127. }
  128. // 拆机申请
  129. // @Summary 拆机申请
  130. // @Description 拆机申请
  131. // @Tags device
  132. // @Accept json
  133. // @Produce json
  134. // @Param token header string true " "
  135. // @Param body body v1.DeviceDelBody true " "
  136. // @Success 200 {object} v1.DeviceDelResponse
  137. // @Failure 500 {object} base.HTTPError
  138. // @Router /api/v1/device [delete]
  139. func (c *Controller) DeviceDel(ctx *gin.Context) {
  140. // 解析参数
  141. req := &param_v1.DeviceDelRequest{}
  142. var loginUid int64
  143. var userName string
  144. parseParamTask := func() error {
  145. err := util.ShouldBind(ctx, &req.Header, nil, nil, &req.DeviceDelBody)
  146. if err != nil {
  147. logger.Error("func",
  148. zap.String("call", "util.ShouldBind"),
  149. zap.String("error", err.Error()))
  150. return errors.ParamsError
  151. }
  152. userName, loginUid, err = utils.GetTokenInfo(ctx)
  153. return nil
  154. }
  155. // 业务处理
  156. projectId := int64(0)
  157. handleServiceTask := func() error {
  158. // 响应数据
  159. resp := param_v1.DeviceDelResponse{}
  160. rpcReq := &v1.DeviceDelRequest{
  161. DeviceId:req.Id,
  162. Reason:req.Reason,
  163. }
  164. reply, err := pb.Supplier.DeviceDel(ctx, rpcReq)
  165. if err != nil {
  166. s, _ := json.MarshalToString(req)
  167. logger.Error("func",
  168. zap.String("call", "DeviceDel"),
  169. zap.String("params", s),
  170. zap.String("error", err.Error()))
  171. return errors.ErrorTransForm(err)
  172. }
  173. projectId = reply.ProjectId
  174. ctx.JSON(http.StatusOK, resp)
  175. return nil
  176. }
  177. // 执行任务
  178. err := httptasker.Exec(ctx, parseParamTask, handleServiceTask)
  179. s, _ := json.MarshalToString(req)
  180. utils.LogWrite("设备拆机申请", loginUid, userName, s, err, projectId)
  181. }
  182. // 设备类型列表
  183. // @Summary 设备类型列表
  184. // @Description 设备类型列表
  185. // @Tags device
  186. // @Accept json
  187. // @Produce json
  188. // @Param token header string true " "
  189. // @Success 200 {object} v1.DeviceTypeListResponse
  190. // @Failure 500 {object} base.HTTPError
  191. // @Router /api/v1/device/default_type_list [get]
  192. func (c *Controller) DeviceDefaultTypeList(ctx *gin.Context) {
  193. // 解析参数
  194. req := &param_v1.DeviceTypeListRequest{}
  195. var loginUid int64
  196. var userName string
  197. parseParamTask := func() error {
  198. err := util.ShouldBind(ctx, &req.Header, nil, nil, nil)
  199. if err != nil {
  200. logger.Error("func",
  201. zap.String("call", "util.ShouldBind"),
  202. zap.String("error", err.Error()))
  203. return errors.ParamsError
  204. }
  205. userName, loginUid, err = utils.GetTokenInfo(ctx)
  206. return nil
  207. }
  208. // 业务处理
  209. handleServiceTask := func() error {
  210. // 响应数据
  211. resp := param_v1.DeviceTypeListResponse{}
  212. rpcReq := &v1.DeviceTypeListRequest{}
  213. rpcReq.ProviderId = 0
  214. reply, err := pb.Supplier.DeviceTypeList(ctx, rpcReq)
  215. if err != nil {
  216. s, _ := json.MarshalToString(req)
  217. logger.Error("func",
  218. zap.String("call", "DeviceTypeList"),
  219. zap.String("params", s),
  220. zap.String("error", err.Error()))
  221. return errors.ErrorTransForm(err)
  222. }
  223. resp.Data = reply.List
  224. if resp.Data == nil {
  225. resp.Data = make([]*v1.DeviceTypeItem, 0)
  226. }
  227. ctx.JSON(http.StatusOK, resp)
  228. return nil
  229. }
  230. // 执行任务
  231. httptasker.Exec(ctx, parseParamTask, handleServiceTask)
  232. }
  233. // 设备类型设申报列表
  234. // @Summary 设备类型申报列表
  235. // @Description 设备类型申报列表
  236. // @Tags device
  237. // @Accept json
  238. // @Produce json
  239. // @Param token header string true " "
  240. // @Param include_vedio query bool false "是否包含视屏设备"
  241. // @Param status_filters query string false "状态,逗号分隔:0 待对接测试 1 测试通过 2对接测试未通过 3. 审核通过 3 审核未通过"
  242. // @Success 200 {object} v1.DeviceTypeListResponse
  243. // @Failure 500 {object} base.HTTPError
  244. // @Router /api/v1/device/type_list [get]
  245. func (c *Controller) DeviceTypeList(ctx *gin.Context) {
  246. // 解析参数
  247. req := &param_v1.DeviceTypeListRequest{}
  248. var loginUid int64
  249. var userName string
  250. parseParamTask := func() error {
  251. err := util.ShouldBind(ctx, &req.Header, nil, &req.DeviceTypeListQuery, nil)
  252. if err != nil {
  253. logger.Error("func",
  254. zap.String("call", "util.ShouldBind"),
  255. zap.String("error", err.Error()))
  256. return errors.ParamsError
  257. }
  258. userName, loginUid, err = utils.GetTokenInfo(ctx)
  259. return nil
  260. }
  261. // 业务处理
  262. handleServiceTask := func() error {
  263. // 响应数据
  264. resp := param_v1.DeviceTypeListResponse{}
  265. rpcReq := &v1.DeviceTypeListRequest{}
  266. rpcReq.ProviderId = loginUid
  267. if req.StatusFilters != "" {
  268. array := strings.Split(req.StatusFilters, ",")
  269. for _, v := range array {
  270. value, _ := strconv.Atoi(v)
  271. rpcReq.StatusFilters = append(rpcReq.StatusFilters, int32(value))
  272. }
  273. }
  274. rpcReq.IncludeVedio = req.IncludeVedio
  275. reply, err := pb.Supplier.DeviceTypeList(ctx, rpcReq)
  276. if err != nil {
  277. s, _ := json.MarshalToString(req)
  278. logger.Error("func",
  279. zap.String("call", "DeviceTypeList"),
  280. zap.String("params", s),
  281. zap.String("error", err.Error()))
  282. return errors.ErrorTransForm(err)
  283. }
  284. resp.Data = reply.List
  285. if resp.Data == nil {
  286. resp.Data = make([]*v1.DeviceTypeItem, 0)
  287. }
  288. ctx.JSON(http.StatusOK, resp)
  289. return nil
  290. }
  291. // 执行任务
  292. httptasker.Exec(ctx, parseParamTask, handleServiceTask)
  293. }
  294. // 设备类型总列表
  295. // @Summary 设备类型总列表
  296. // @Description 设备类型总列表
  297. // @Tags device
  298. // @Accept json
  299. // @Produce json
  300. // @Success 200 {object} v1.DeviceAllTypeListResponse
  301. // @Failure 500 {object} base.HTTPError
  302. // @Router /api/v1/device_type_all [get]
  303. func (c *Controller) DeviceTypeAll(ctx *gin.Context) {
  304. // 业务处理
  305. handleServiceTask := func() error {
  306. // 响应数据
  307. resp := param_v1.DeviceAllTypeListResponse{}
  308. rpcReq := &v1.DeviceTypeListRequest{}
  309. reply, err := pb.Supplier.DeviceTypeList(ctx, rpcReq)
  310. if err != nil {
  311. logger.Error("func",
  312. zap.String("call", "DeviceTypeAll"),
  313. zap.String("error", err.Error()))
  314. return errors.ErrorTransForm(err)
  315. }
  316. resp.Data = *reply
  317. if resp.Data.List == nil {
  318. resp.Data.List = make([]*v1.DeviceTypeItem, 0)
  319. }
  320. ctx.JSON(http.StatusOK, resp)
  321. return nil
  322. }
  323. // 执行任务
  324. httptasker.Exec(ctx, handleServiceTask)
  325. }
  326. // 设备列表
  327. // @Summary 设备列表
  328. // @Description 设备列表
  329. // @Tags device
  330. // @Accept json
  331. // @Produce json
  332. // @Param token header string true " "
  333. // @Param filter query string false "过滤字段"
  334. // @Param page query int false " "
  335. // @Param type_code query int false "设备类型编码"
  336. // @Param filter_status query string false "状态,逗号分隔:0 待审核 1 通过 2 未通过"
  337. // @Success 200 {object} v1.DeviceListResponse
  338. // @Failure 500 {object} base.HTTPError
  339. // @Router /api/v1/device/list [get]
  340. func (c *Controller) DeviceList(ctx *gin.Context) {
  341. // 解析参数
  342. req := &param_v1.DeviceListRequest{}
  343. var loginUid int64
  344. var userName string
  345. parseParamTask := func() error {
  346. err := util.ShouldBind(ctx, &req.Header, nil, &req.DeviceListQuery, nil)
  347. if err != nil {
  348. logger.Error("func",
  349. zap.String("call", "util.ShouldBind"),
  350. zap.String("error", err.Error()))
  351. return errors.ParamsError
  352. }
  353. userName, loginUid, err = utils.GetTokenInfo(ctx)
  354. return nil
  355. }
  356. // 业务处理
  357. handleServiceTask := func() error {
  358. // 响应数据
  359. resp := param_v1.DeviceListResponse{}
  360. rpcReq := &v1.DeviceListRequest{}
  361. rpcReq.ProjectId = req.ProjectId
  362. rpcReq.Page = req.Page
  363. rpcReq.ProviderId = loginUid
  364. rpcReq.Filter = req.Filter
  365. rpcReq.TypeCode = int32(req.TypeCode)
  366. rpcReq.CanDel = req.CanDel
  367. if req.FilterStatus != "" {
  368. array := strings.Split(req.FilterStatus, ",")
  369. for _, v := range array {
  370. value, _ := strconv.Atoi(v)
  371. rpcReq.StatusFilters = append(rpcReq.StatusFilters, int32(value))
  372. }
  373. }
  374. reply, err := pb.Supplier.DeviceList(ctx, rpcReq)
  375. if err != nil {
  376. s, _ := json.MarshalToString(req)
  377. logger.Error("func",
  378. zap.String("call", "DeviceList"),
  379. zap.String("params", s),
  380. zap.String("error", err.Error()))
  381. return errors.ErrorTransForm(err)
  382. }
  383. resp.Data = *reply
  384. if resp.Data.List == nil {
  385. resp.Data.List = make([]*v1.DeviceItem, 0)
  386. }
  387. ctx.JSON(http.StatusOK, resp)
  388. return nil
  389. }
  390. // 执行任务
  391. httptasker.Exec(ctx, parseParamTask, handleServiceTask)
  392. }
  393. // 可拆机的设备列表
  394. // @Summary 可拆机的设备列表
  395. // @Description 可拆机的设备列表
  396. // @Tags device
  397. // @Accept json
  398. // @Produce json
  399. // @Param token header string true " "
  400. // @Param filter query string false "过滤字段"
  401. // @Param page query int false " "
  402. // @Param type_code query int false "设备类型编码"
  403. // @Success 200 {object} v1.DeviceListResponse
  404. // @Failure 500 {object} base.HTTPError
  405. // @Router /api/v1/device/can_del_list [get]
  406. func (c *Controller) DeviceCanDelList(ctx *gin.Context) {
  407. // 解析参数
  408. req := &param_v1.DeviceListRequest{}
  409. var loginUid int64
  410. var userName string
  411. parseParamTask := func() error {
  412. err := util.ShouldBind(ctx, &req.Header, nil, &req.DeviceListQuery, nil)
  413. if err != nil {
  414. logger.Error("func",
  415. zap.String("call", "util.ShouldBind"),
  416. zap.String("error", err.Error()))
  417. return errors.ParamsError
  418. }
  419. userName, loginUid, err = utils.GetTokenInfo(ctx)
  420. return nil
  421. }
  422. // 业务处理
  423. handleServiceTask := func() error {
  424. // 响应数据
  425. resp := param_v1.DeviceListResponse{}
  426. rpcReq := &v1.DeviceListRequest{}
  427. rpcReq.ProjectId = req.ProjectId
  428. rpcReq.Page = req.Page
  429. rpcReq.ProviderId = loginUid
  430. rpcReq.Filter = req.Filter
  431. rpcReq.TypeCode = int32(req.TypeCode)
  432. rpcReq.CanDel = true
  433. reply, err := pb.Supplier.DeviceList(ctx, rpcReq)
  434. if err != nil {
  435. s, _ := json.MarshalToString(req)
  436. logger.Error("func",
  437. zap.String("call", "DeviceList"),
  438. zap.String("params", s),
  439. zap.String("error", err.Error()))
  440. return errors.ErrorTransForm(err)
  441. }
  442. resp.Data = *reply
  443. if resp.Data.List == nil {
  444. resp.Data.List = make([]*v1.DeviceItem, 0)
  445. }
  446. ctx.JSON(http.StatusOK, resp)
  447. return nil
  448. }
  449. // 执行任务
  450. httptasker.Exec(ctx, parseParamTask, handleServiceTask)
  451. }
  452. // 视频设备列表
  453. // @Summary 视频设备列表
  454. // @Description 视频设备列表
  455. // @Tags device
  456. // @Accept json
  457. // @Produce json
  458. // @Param token header string true " "
  459. // @Param filter query string false "过滤字段"
  460. // @Param page query int false " "
  461. // @Success 200 {object} v1.VedioListResponse
  462. // @Failure 500 {object} base.HTTPError
  463. // @Router /api/v1/device/vedio_list [get]
  464. func (c *Controller) DeviceVedioList(ctx *gin.Context) {
  465. // 解析参数
  466. req := &param_v1.VedioListRequest{}
  467. var loginUid int64
  468. var userName string
  469. parseParamTask := func() error {
  470. err := util.ShouldBind(ctx, &req.Header, nil, &req.VedioListQuery, nil)
  471. if err != nil {
  472. logger.Error("func",
  473. zap.String("call", "util.ShouldBind"),
  474. zap.String("error", err.Error()))
  475. return errors.ParamsError
  476. }
  477. userName, loginUid, err = utils.GetTokenInfo(ctx)
  478. return nil
  479. }
  480. // 业务处理
  481. handleServiceTask := func() error {
  482. // 响应数据
  483. resp := param_v1.VedioListResponse{}
  484. rpcReq := &v1.VedioListRequest{}
  485. rpcReq.Page = req.Page
  486. rpcReq.ProviderId = loginUid
  487. rpcReq.Filter = req.Filter
  488. /*
  489. if req.FilterStatus != "" {
  490. array := strings.Split(req.FilterStatus, ",")
  491. for _, v := range array {
  492. value, _ := strconv.Atoi(v)
  493. rpcReq.StatusFilters = append(rpcReq.StatusFilters, int32(value))
  494. }
  495. }*/
  496. reply, err := pb.Supplier.VedioList(ctx, rpcReq)
  497. if err != nil {
  498. s, _ := json.MarshalToString(req)
  499. logger.Error("func",
  500. zap.String("call", "VedioList"),
  501. zap.String("params", s),
  502. zap.String("error", err.Error()))
  503. return errors.ErrorTransForm(err)
  504. }
  505. resp.Data = *reply
  506. if resp.Data.List == nil {
  507. resp.Data.List = make([]*v1.VedioItem, 0)
  508. }
  509. ctx.JSON(http.StatusOK, resp)
  510. return nil
  511. }
  512. // 执行任务
  513. httptasker.Exec(ctx, parseParamTask, handleServiceTask)
  514. }
  515. // 设备拆机工单列表
  516. // @Summary 设备拆机工单列表
  517. // @Description 设备拆机工单列表
  518. // @Tags device
  519. // @Accept json
  520. // @Produce json
  521. // @Param token header string true " "
  522. // @Param page query int false " "
  523. // @Param filter_status query string false "状态,逗号分隔:0 待审核 1 通过 2 未通过"
  524. // @Param filter query string false " "
  525. // @Success 200 {object} v1.DeviceDelJobListResponse
  526. // @Failure 500 {object} base.HTTPError
  527. // @Router /api/v1/device/del_job_list [get]
  528. func (c *Controller) DeviceDelJobList(ctx *gin.Context) {
  529. // 解析参数
  530. req := &param_v1.DeviceDelJobListRequest{}
  531. var loginUid int64
  532. parseParamTask := func() error {
  533. err := util.ShouldBind(ctx, &req.Header, nil, &req.DeviceDelJobListQuery, nil)
  534. if err != nil {
  535. logger.Error("func",
  536. zap.String("call", "util.ShouldBind"),
  537. zap.String("error", err.Error()))
  538. return errors.ParamsError
  539. }
  540. loginUid, err = utils.GetJwtIdFromCtx(ctx)
  541. return nil
  542. }
  543. // 业务处理
  544. handleServiceTask := func() error {
  545. // 响应数据
  546. resp := param_v1.DeviceDelJobListResponse{}
  547. rpcReq := &v1.DeviceDelJobListRequest{
  548. Page:req.Page,
  549. }
  550. if req.FilterStatus != "" {
  551. array := strings.Split(req.FilterStatus, ",")
  552. for _, v := range array {
  553. value, _ := strconv.Atoi(v)
  554. rpcReq.StatusFilters = append(rpcReq.StatusFilters, int32(value))
  555. }
  556. }
  557. rpcReq.ProviderId = loginUid
  558. rpcReq.Filter = req.Filter
  559. reply, err := pb.Supplier.DeviceDelJobList(ctx, rpcReq)
  560. if err != nil {
  561. s, _ := json.MarshalToString(req)
  562. logger.Error("func",
  563. zap.String("call", "DeviceDelJobList"),
  564. zap.String("params", s),
  565. zap.String("error", err.Error()))
  566. return errors.ErrorTransForm(err)
  567. }
  568. resp.Data = *reply
  569. if resp.Data.List == nil {
  570. resp.Data.List = make([]*v1.DeviceDelJobItem, 0)
  571. }
  572. ctx.JSON(http.StatusOK, resp)
  573. return nil
  574. }
  575. // 执行任务
  576. httptasker.Exec(ctx, parseParamTask, handleServiceTask)
  577. }
  578. // 项目列表
  579. // @Summary 项目列表
  580. // @Description 项目列表
  581. // @Tags device
  582. // @Accept json
  583. // @Produce json
  584. // @Param token header string true " "
  585. // @Success 200 {object} v1.ProjectListResponse
  586. // @Failure 500 {object} base.HTTPError
  587. // @Router /api/v1/project/list [get]
  588. func (c *Controller) ProjectList(ctx *gin.Context) {
  589. // 解析参数
  590. req := &param_v1.ProjectListRequest{}
  591. var loginUid int64
  592. var userName string
  593. parseParamTask := func() error {
  594. err := util.ShouldBind(ctx, &req.Header, nil, nil, nil)
  595. if err != nil {
  596. logger.Error("func",
  597. zap.String("call", "util.ShouldBind"),
  598. zap.String("error", err.Error()))
  599. return errors.ParamsError
  600. }
  601. userName, loginUid, err = utils.GetTokenInfo(ctx)
  602. return nil
  603. }
  604. // 业务处理
  605. handleServiceTask := func() error {
  606. // 响应数据
  607. resp := param_v1.ProjectListResponse{}
  608. rpcReq := &v1.ProjectListRequest{}
  609. reply, err := pb.Supplier.ProjectList(ctx, rpcReq)
  610. if err != nil {
  611. s, _ := json.MarshalToString(req)
  612. logger.Error("func",
  613. zap.String("call", "ProjectList"),
  614. zap.String("params", s),
  615. zap.String("error", err.Error()))
  616. return errors.ErrorTransForm(err)
  617. }
  618. resp.Data = reply.List
  619. if resp.Data == nil {
  620. resp.Data = make([]*v1.ProjectItem, 0)
  621. }
  622. ctx.JSON(http.StatusOK, resp)
  623. return nil
  624. }
  625. // 执行任务
  626. httptasker.Exec(ctx, parseParamTask, handleServiceTask)
  627. }
  628. // 添加视频设备
  629. // @Summary 添加视频设备
  630. // @Description 添加视频设备
  631. // @Tags device
  632. // @Accept json
  633. // @Produce json
  634. // @Param token header string true " "
  635. // @Param body body v1.VedioAddBody true " "
  636. // @Success 200 {object} v1.VedioAddResponse
  637. // @Failure 500 {object} base.HTTPError
  638. // @Router /api/v1/device/vedio [post]
  639. func (c *Controller) VedioAdd(ctx *gin.Context) {
  640. // 解析参数
  641. req := &param_v1.VedioAddRequest{}
  642. var loginUid int64
  643. var userName string
  644. parseParamTask := func() error {
  645. err := util.ShouldBind(ctx, &req.Header, nil, nil, &req.VedioAddBody)
  646. if err != nil {
  647. logger.Error("func",
  648. zap.String("call", "util.ShouldBind"),
  649. zap.String("error", err.Error()))
  650. return errors.ParamsError
  651. }
  652. userName, loginUid, _ = utils.GetTokenInfo(ctx)
  653. return nil
  654. }
  655. // 业务处理
  656. handleServiceTask := func() error {
  657. // 响应数据
  658. resp := param_v1.VedioAddResponse{}
  659. rpcReq := &v1.VedioAddRequest{
  660. ProviderId:loginUid,
  661. ProjectId:req.ProjectId,
  662. VedioType:req.VedioType,
  663. Name:req.Name,
  664. ChannelCount:req.ChannelCount,
  665. }
  666. rpcRsp, err := pb.Supplier.VedioAdd(ctx, rpcReq)
  667. if err != nil {
  668. s, _ := json.MarshalToString(req)
  669. logger.Error("func",
  670. zap.String("call", "VedioAdd"),
  671. zap.String("params", s),
  672. zap.String("error", err.Error()))
  673. return errors.ErrorTransForm(err)
  674. }
  675. resp.Data = *rpcRsp
  676. ctx.JSON(http.StatusOK, resp)
  677. return nil
  678. }
  679. // 执行任务
  680. err := httptasker.Exec(ctx, parseParamTask, handleServiceTask)
  681. s, _ := json.MarshalToString(req)
  682. utils.LogWrite("视频设备入库申请", loginUid, userName, s, err, req.ProjectId)
  683. }
  684. // 添加通道
  685. // @Summary 添加通道
  686. // @Description 添加通道
  687. // @Tags device
  688. // @Accept json
  689. // @Produce json
  690. // @Param token header string true " "
  691. // @Param body body v1.ChannelAddBody true " "
  692. // @Success 200 {object} v1.ChannelAddResponse
  693. // @Failure 500 {object} base.HTTPError
  694. // @Router /api/v1/device/vedio_channel [post]
  695. func (c *Controller) ChannelAdd(ctx *gin.Context) {
  696. // 解析参数
  697. req := &param_v1.ChannelAddRequest{}
  698. var loginUid int64
  699. var userName string
  700. parseParamTask := func() error {
  701. err := util.ShouldBind(ctx, &req.Header, nil, nil, &req.ChannelAddBody)
  702. if err != nil {
  703. logger.Error("func",
  704. zap.String("call", "util.ShouldBind"),
  705. zap.String("error", err.Error()))
  706. return errors.ParamsError
  707. }
  708. userName, loginUid, _ = utils.GetTokenInfo(ctx)
  709. return nil
  710. }
  711. // 业务处理
  712. var projectId int64
  713. handleServiceTask := func() error {
  714. // 响应数据
  715. resp := param_v1.ChannelAddResponse{}
  716. rpcReq := &v1.ChannelAddRequest{
  717. Sn:req.Sn,
  718. ChannelCount:req.ChannelCount,
  719. }
  720. rpcRsp, err := pb.Supplier.ChannelAdd(ctx, rpcReq)
  721. if err != nil {
  722. s, _ := json.MarshalToString(req)
  723. logger.Error("func",
  724. zap.String("call", "ChannelAdd"),
  725. zap.String("params", s),
  726. zap.String("error", err.Error()))
  727. return errors.ErrorTransForm(err)
  728. }
  729. projectId = rpcRsp.ProjectId
  730. ctx.JSON(http.StatusOK, resp)
  731. return nil
  732. }
  733. // 执行任务
  734. err := httptasker.Exec(ctx, parseParamTask, handleServiceTask)
  735. s, _ := json.MarshalToString(req)
  736. utils.LogWrite("添加通道", loginUid, userName, s, err, projectId)
  737. }
  738. // 编辑通道
  739. // @Summary 编辑通道
  740. // @Description 编辑通道
  741. // @Tags device
  742. // @Accept json
  743. // @Produce json
  744. // @Param token header string true " "
  745. // @Param body body v1.ChannelUpdateBody true " "
  746. // @Success 200 {object} v1.ChannelUpdateResponse
  747. // @Failure 500 {object} base.HTTPError
  748. // @Router /api/v1/device/vedio_channel [put]
  749. func (c *Controller) ChannelUpdate(ctx *gin.Context) {
  750. // 解析参数
  751. req := &param_v1.ChannelUpdateRequest{}
  752. var loginUid int64
  753. var userName string
  754. parseParamTask := func() error {
  755. err := util.ShouldBind(ctx, &req.Header, nil, nil, &req.ChannelUpdateBody)
  756. if err != nil {
  757. logger.Error("func",
  758. zap.String("call", "util.ShouldBind"),
  759. zap.String("error", err.Error()))
  760. return errors.ParamsError
  761. }
  762. userName, loginUid, _ = utils.GetTokenInfo(ctx)
  763. return nil
  764. }
  765. // 业务处理
  766. var projectId int64
  767. handleServiceTask := func() error {
  768. // 响应数据
  769. resp := param_v1.ChannelUpdateResponse{}
  770. rpcReq := &v1.ChannelUpdateRequest{
  771. Id:req.Id,
  772. Name:req.Name,
  773. }
  774. rpcRsp, err := pb.Supplier.ChannelUpdate(ctx, rpcReq)
  775. if err != nil {
  776. s, _ := json.MarshalToString(req)
  777. logger.Error("func",
  778. zap.String("call", "ChannelUpdate"),
  779. zap.String("params", s),
  780. zap.String("error", err.Error()))
  781. return errors.ErrorTransForm(err)
  782. }
  783. projectId = rpcRsp.ProjectId
  784. ctx.JSON(http.StatusOK, resp)
  785. return nil
  786. }
  787. // 执行任务
  788. err := httptasker.Exec(ctx, parseParamTask, handleServiceTask)
  789. s, _ := json.MarshalToString(req)
  790. utils.LogWrite("编辑通道", loginUid, userName, s, err, projectId)
  791. }
  792. // 通道列表
  793. // @Summary 通道列表
  794. // @Description 通道列表
  795. // @Tags device
  796. // @Accept json
  797. // @Produce json
  798. // @Param token header string true " "
  799. // @Param sn query string true " "
  800. // @Param channel_no query string false " "
  801. // @Param page query int false " "
  802. // @Success 200 {object} v1.ChannelListResponse
  803. // @Failure 500 {object} base.HTTPError
  804. // @Router /api/v1/device/vedio_channel_list [get]
  805. func (c *Controller) DeviceVedioChannelList(ctx *gin.Context) {
  806. // 解析参数
  807. req := &param_v1.ChannelListRequest{}
  808. var loginUid int64
  809. var userName string
  810. parseParamTask := func() error {
  811. err := util.ShouldBind(ctx, &req.Header, nil, &req.ChannelListQuery, nil)
  812. if err != nil {
  813. logger.Error("func",
  814. zap.String("call", "util.ShouldBind"),
  815. zap.String("error", err.Error()))
  816. return errors.ParamsError
  817. }
  818. userName, loginUid, err = utils.GetTokenInfo(ctx)
  819. return nil
  820. }
  821. // 业务处理
  822. handleServiceTask := func() error {
  823. // 响应数据
  824. resp := param_v1.ChannelListResponse{}
  825. rpcReq := &v1.ChannelListRequest{}
  826. rpcReq.Page = req.Page
  827. rpcReq.Sn = req.Sn
  828. rpcReq.ChannelNo = req.ChannelNo
  829. /*
  830. if req.FilterStatus != "" {
  831. array := strings.Split(req.FilterStatus, ",")
  832. for _, v := range array {
  833. value, _ := strconv.Atoi(v)
  834. rpcReq.StatusFilters = append(rpcReq.StatusFilters, int32(value))
  835. }
  836. }*/
  837. reply, err := pb.Supplier.ChannelList(ctx, rpcReq)
  838. if err != nil {
  839. s, _ := json.MarshalToString(req)
  840. logger.Error("func",
  841. zap.String("call", "ChannelList"),
  842. zap.String("params", s),
  843. zap.String("error", err.Error()))
  844. return errors.ErrorTransForm(err)
  845. }
  846. resp.Data = *reply
  847. if resp.Data.List == nil {
  848. resp.Data.List = make([]*v1.ChannelItem, 0)
  849. }
  850. ctx.JSON(http.StatusOK, resp)
  851. return nil
  852. }
  853. // 执行任务
  854. httptasker.Exec(ctx, parseParamTask, handleServiceTask)
  855. }