device.go 31 KB

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