project.go 33 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274
  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-site-management-gateway/errors"
  12. param_v1 "smart-site-management-gateway/param/v1"
  13. "smart-site-management-gateway/pb"
  14. "smart-site-management-gateway/pb/v1"
  15. "smart-site-management-gateway/utils"
  16. )
  17. // 设备列表
  18. // @Summary 设备列表
  19. // @Description 设备列表
  20. // @Tags 设备后台设置
  21. // @Accept json
  22. // @Produce json
  23. // @Param token header string true " "
  24. // @Param page query int false " "
  25. // @Param page_size query int false " "
  26. // @Param filter query string false " "
  27. // @Param status query int false " 审核状态 -1 不过滤, 0 待审核 1 通过 2 未通过 "
  28. // @Success 200 {object} v1.DeviceListResponse
  29. // @Failure 500 {object} base.HTTPError
  30. // @Router /api/v1/device/list [get]
  31. func (c *Controller) DeviceList(ctx *gin.Context) {
  32. // 解析参数
  33. req := &param_v1.DeviceListRequest{}
  34. var loginUid int64
  35. var userName string
  36. parseParamTask := func() error {
  37. err := util.ShouldBind(ctx, &req.Header, nil, &req.DeviceListQuery, nil)
  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. loginUid, userName, err = utils.GetJwtIdFromCtx(ctx)
  45. return nil
  46. }
  47. // 业务处理
  48. handleServiceTask := func() error {
  49. // 响应数据
  50. _, projectId, err := utils.GetSubjectValue(ctx)
  51. if err != nil {
  52. return err
  53. }
  54. if req.Page < 1 {
  55. req.Page = 1
  56. }
  57. resp := param_v1.DeviceListResponse{}
  58. rpcReq := &v1.DeviceListRequest{
  59. Page: req.Page,
  60. Filter: req.Filter,
  61. PageSize:req.PageSize,
  62. }
  63. //req.FilterStatus = "1"
  64. if req.Status > -1 {
  65. rpcReq.StatusFilters = append(rpcReq.StatusFilters, int32(req.Status))
  66. }
  67. rpcReq.ProjectId = projectId
  68. reply, err := pb.Project.DeviceList(ctx, rpcReq)
  69. if err != nil {
  70. s, _ := json.MarshalToString(req)
  71. logger.Error("func",
  72. zap.String("call", "DeviceList"),
  73. zap.String("params", s),
  74. zap.String("error", err.Error()))
  75. return errors.ErrorTransForm(err)
  76. }
  77. resp.Data = *reply
  78. if resp.Data.List == nil {
  79. resp.Data.List = make([]*v1.DeviceItem, 0)
  80. }
  81. ctx.JSON(http.StatusOK, resp)
  82. return nil
  83. }
  84. // 执行任务
  85. httptasker.Exec(ctx, parseParamTask, handleServiceTask)
  86. }
  87. // 视频设备列表
  88. // @Summary 视频设备列表
  89. // @Description 视频设备列表
  90. // @Tags device
  91. // @Accept json
  92. // @Produce json
  93. // @Param token header string true " "
  94. // @Param filter query string false "过滤字段"
  95. // @Param page query int false " "
  96. // @Success 200 {object} v1.VedioListResponse
  97. // @Failure 500 {object} base.HTTPError
  98. // @Router /api/v1/device/vedio_list [get]
  99. func (c *Controller) DeviceVedioList(ctx *gin.Context) {
  100. // 解析参数
  101. req := &param_v1.VedioListRequest{}
  102. var loginUid int64
  103. var userName string
  104. parseParamTask := func() error {
  105. err := util.ShouldBind(ctx, &req.Header, nil, &req.VedioListQuery, nil)
  106. if err != nil {
  107. logger.Error("func",
  108. zap.String("call", "util.ShouldBind"),
  109. zap.String("error", err.Error()))
  110. return errors.ParamsError
  111. }
  112. loginUid, userName, err = utils.GetJwtIdFromCtx(ctx)
  113. return nil
  114. }
  115. // 业务处理
  116. handleServiceTask := func() error {
  117. // 响应数据
  118. _, projectId, err := utils.GetSubjectValue(ctx)
  119. if err != nil {
  120. return err
  121. }
  122. resp := param_v1.VedioListResponse{}
  123. rpcReq := &v1.VedioListRequest{}
  124. rpcReq.Page = req.Page
  125. rpcReq.ProjectId = projectId
  126. rpcReq.Filter = req.Filter
  127. /*
  128. if req.FilterStatus != "" {
  129. array := strings.Split(req.FilterStatus, ",")
  130. for _, v := range array {
  131. value, _ := strconv.Atoi(v)
  132. rpcReq.StatusFilters = append(rpcReq.StatusFilters, int32(value))
  133. }
  134. }*/
  135. reply, err := pb.Project.VedioList(ctx, rpcReq)
  136. if err != nil {
  137. s, _ := json.MarshalToString(req)
  138. logger.Error("func",
  139. zap.String("call", "VedioList"),
  140. zap.String("params", s),
  141. zap.String("error", err.Error()))
  142. return errors.ErrorTransForm(err)
  143. }
  144. resp.Data = *reply
  145. if resp.Data.List == nil {
  146. resp.Data.List = make([]*v1.VedioItem, 0)
  147. }
  148. ctx.JSON(http.StatusOK, resp)
  149. return nil
  150. }
  151. // 执行任务
  152. httptasker.Exec(ctx, parseParamTask, handleServiceTask)
  153. }
  154. // 通道列表
  155. // @Summary 通道列表
  156. // @Description 通道列表
  157. // @Tags device
  158. // @Accept json
  159. // @Produce json
  160. // @Param token header string true " "
  161. // @Param sn query string false " "
  162. // @Param page query int false " "
  163. // @Param page_size query int false " "
  164. // @Param channel_no query string false " "
  165. // @Success 200 {object} v1.ChannelListResponse
  166. // @Failure 500 {object} base.HTTPError
  167. // @Router /api/v1/device/vedio_channel_list [get]
  168. func (c *Controller) DeviceVedioChannelList(ctx *gin.Context) {
  169. // 解析参数
  170. req := &param_v1.ChannelListRequest{}
  171. var loginUid int64
  172. var userName string
  173. parseParamTask := func() error {
  174. err := util.ShouldBind(ctx, &req.Header, nil, &req.ChannelListQuery, nil)
  175. if err != nil {
  176. logger.Error("func",
  177. zap.String("call", "util.ShouldBind"),
  178. zap.String("error", err.Error()))
  179. return errors.ParamsError
  180. }
  181. loginUid, userName, err = utils.GetJwtIdFromCtx(ctx)
  182. return nil
  183. }
  184. // 业务处理
  185. handleServiceTask := func() error {
  186. // 响应数据
  187. _, projectId, err := utils.GetSubjectValue(ctx)
  188. if err != nil {
  189. return err
  190. }
  191. resp := param_v1.ChannelListResponse{}
  192. rpcReq := &v1.ChannelListRequest{}
  193. rpcReq.Page = req.Page
  194. rpcReq.Sn = req.Sn
  195. rpcReq.ChannelNo = req.ChannelNo
  196. rpcReq.PageSise = req.PageSize
  197. rpcReq.ProjectId = projectId
  198. /*
  199. if req.FilterStatus != "" {
  200. array := strings.Split(req.FilterStatus, ",")
  201. for _, v := range array {
  202. value, _ := strconv.Atoi(v)
  203. rpcReq.StatusFilters = append(rpcReq.StatusFilters, int32(value))
  204. }
  205. }*/
  206. reply, err := pb.Project.ChannelList(ctx, rpcReq)
  207. if err != nil {
  208. s, _ := json.MarshalToString(req)
  209. logger.Error("func",
  210. zap.String("call", "ChannelList"),
  211. zap.String("params", s),
  212. zap.String("error", err.Error()))
  213. return errors.ErrorTransForm(err)
  214. }
  215. resp.Data = *reply
  216. if resp.Data.List == nil {
  217. resp.Data.List = make([]*v1.ChannelItem, 0)
  218. }
  219. ctx.JSON(http.StatusOK, resp)
  220. return nil
  221. }
  222. // 执行任务
  223. httptasker.Exec(ctx, parseParamTask, handleServiceTask)
  224. }
  225. // 未绑定设备的通道列表
  226. // @Summary 未绑定设备的通道列表
  227. // @Description 未绑定设备的通道列表
  228. // @Tags device
  229. // @Accept json
  230. // @Produce json
  231. // @Param token header string true " "
  232. // @Success 200 {object} v1.ChannelListResponse
  233. // @Failure 500 {object} base.HTTPError
  234. // @Router /api/v1/device/vedio_channel_unbind [get]
  235. func (c *Controller) DeviceVedioChannelUnbindList(ctx *gin.Context) {
  236. // 解析参数
  237. req := &param_v1.ChannelListRequest{}
  238. var loginUid int64
  239. var userName string
  240. parseParamTask := func() error {
  241. err := util.ShouldBind(ctx, &req.Header, nil, &req.ChannelListQuery, nil)
  242. if err != nil {
  243. logger.Error("func",
  244. zap.String("call", "util.ShouldBind"),
  245. zap.String("error", err.Error()))
  246. return errors.ParamsError
  247. }
  248. loginUid, userName, err = utils.GetJwtIdFromCtx(ctx)
  249. return nil
  250. }
  251. // 业务处理
  252. handleServiceTask := func() error {
  253. // 响应数据
  254. _, projectId, err := utils.GetSubjectValue(ctx)
  255. if err != nil {
  256. return err
  257. }
  258. resp := param_v1.ChannelListUnbindResponse{}
  259. rpcReq := &v1.ChannelListRequest{}
  260. rpcReq.ProjectId = projectId
  261. rpcReq.IsUnbind = true
  262. reply, err := pb.Project.ChannelList(ctx, rpcReq)
  263. if err != nil {
  264. s, _ := json.MarshalToString(req)
  265. logger.Error("func",
  266. zap.String("call", "ChannelList"),
  267. zap.String("params", s),
  268. zap.String("error", err.Error()))
  269. return errors.ErrorTransForm(err)
  270. }
  271. resp.Data.List = reply.List
  272. if resp.Data.List == nil {
  273. resp.Data.List = make([]*v1.ChannelItem, 0)
  274. }
  275. ctx.JSON(http.StatusOK, resp)
  276. return nil
  277. }
  278. // 执行任务
  279. httptasker.Exec(ctx, parseParamTask, handleServiceTask)
  280. }
  281. // 申请的设备列表
  282. // @Summary 申请的设备列表
  283. // @Description 申请的设备列表
  284. // @Tags 设备后台设置
  285. // @Accept json
  286. // @Produce json
  287. // @Param token header string true " "
  288. // @Param page query int false " "
  289. // @Param filter query string false " "
  290. // @Success 200 {object} v1.DeviceListResponse
  291. // @Failure 500 {object} base.HTTPError
  292. // @Router /api/v1/device/apply_list [get]
  293. func (c *Controller) DeviceApplyList(ctx *gin.Context) {
  294. // 解析参数
  295. req := &param_v1.DeviceListRequest{}
  296. var loginUid int64
  297. var userName string
  298. parseParamTask := func() error {
  299. err := util.ShouldBind(ctx, &req.Header, nil, &req.DeviceListQuery, nil)
  300. if err != nil {
  301. logger.Error("func",
  302. zap.String("call", "util.ShouldBind"),
  303. zap.String("error", err.Error()))
  304. return errors.ParamsError
  305. }
  306. loginUid, userName, err = utils.GetJwtIdFromCtx(ctx)
  307. return nil
  308. }
  309. // 业务处理
  310. handleServiceTask := func() error {
  311. // 响应数据
  312. _, projectId, err := utils.GetSubjectValue(ctx)
  313. if err != nil {
  314. return err
  315. }
  316. if req.Page < 1 {
  317. req.Page = 1
  318. }
  319. resp := param_v1.DeviceListResponse{}
  320. rpcReq := &v1.DeviceListRequest{
  321. Page: req.Page,
  322. Filter: req.Filter,
  323. }
  324. rpcReq.StatusFilters = append(rpcReq.StatusFilters, 0)
  325. rpcReq.StatusFilters = append(rpcReq.StatusFilters, 2)
  326. rpcReq.ProjectId = projectId
  327. reply, err := pb.Project.DeviceList(ctx, rpcReq)
  328. if err != nil {
  329. s, _ := json.MarshalToString(req)
  330. logger.Error("func",
  331. zap.String("call", "DeviceList"),
  332. zap.String("params", s),
  333. zap.String("error", err.Error()))
  334. return errors.ErrorTransForm(err)
  335. }
  336. resp.Data = *reply
  337. if resp.Data.List == nil {
  338. resp.Data.List = make([]*v1.DeviceItem, 0)
  339. }
  340. ctx.JSON(http.StatusOK, resp)
  341. return nil
  342. }
  343. // 执行任务
  344. httptasker.Exec(ctx, parseParamTask, handleServiceTask)
  345. }
  346. // 项目变更申请
  347. // @Summary 项目变更申请
  348. // @Description 项目变更申请
  349. // @Tags 项目后台设置
  350. // @Accept json
  351. // @Produce json
  352. // @Param token header string true " "
  353. // @Param body body v1.ProjectChangeBody true " "
  354. // @Success 200 {object} v1.DeviceListResponse
  355. // @Failure 500 {object} base.HTTPError
  356. // @Router /api/v1/project [put]
  357. func (c *Controller) ProjectChange(ctx *gin.Context) {
  358. // 解析参数
  359. req := &param_v1.ProjectChangeRequest{}
  360. var loginUid int64
  361. var userName string
  362. parseParamTask := func() error {
  363. err := util.ShouldBind(ctx, &req.Header, nil, nil, &req.ProjectChangeBody)
  364. if err != nil {
  365. logger.Error("func",
  366. zap.String("call", "util.ShouldBind"),
  367. zap.String("error", err.Error()))
  368. return errors.ParamsError
  369. }
  370. loginUid, userName, err = utils.GetJwtIdFromCtx(ctx)
  371. return nil
  372. }
  373. // 业务处理
  374. var pid int64
  375. handleServiceTask := func() error {
  376. // 响应数据
  377. _, projectId, err := utils.GetSubjectValue(ctx)
  378. if err != nil {
  379. return err
  380. }
  381. pid = projectId
  382. resp := param_v1.ProjectChangeResponse{}
  383. rpcReq := &v1.ProjectChangeRequest{
  384. Id: projectId,
  385. }
  386. rpcReq.List = make([]*v1.ProjectInfoItem, len(req.List))
  387. for i, v := range req.List {
  388. rpcReq.List[i] = &v1.ProjectInfoItem{}
  389. rpcReq.List[i].Name = v.Name
  390. rpcReq.List[i].Value = v.Value
  391. }
  392. _, err = pb.Project.ProjectChange(ctx, rpcReq)
  393. if err != nil {
  394. s, _ := json.MarshalToString(req)
  395. logger.Error("func",
  396. zap.String("call", "ProjectChange"),
  397. zap.String("params", s),
  398. zap.String("error", err.Error()))
  399. return errors.ErrorTransForm(err)
  400. }
  401. ctx.JSON(http.StatusOK, resp)
  402. return nil
  403. }
  404. // 执行任务
  405. err := httptasker.Exec(ctx, parseParamTask, handleServiceTask)
  406. s, _ := json.MarshalToString(req)
  407. utils.LogWrite("项目变更申请", loginUid, userName, s, err, pid)
  408. }
  409. // 项目变更申请前获取当前项目字段信息
  410. // @Summary 项目变更申请前获取当前项目字段信息
  411. // @Description 项目变更申请前获取当前项目字段信息
  412. // @Tags 项目后台设置
  413. // @Accept json
  414. // @Produce json
  415. // @Param token header string true " "
  416. // @Success 200 {object} v1.ProjectInfoForChangeResponse
  417. // @Failure 500 {object} base.HTTPError
  418. // @Router /api/v1/project/fields [get]
  419. func (c *Controller) ProjectInfoForChange(ctx *gin.Context) {
  420. // 解析参数
  421. req := &param_v1.ProjectInfoForChangeRequest{}
  422. var loginUid int64
  423. var userName string
  424. parseParamTask := func() error {
  425. err := util.ShouldBind(ctx, &req.Header, nil, nil, nil)
  426. if err != nil {
  427. logger.Error("func",
  428. zap.String("call", "util.ShouldBind"),
  429. zap.String("error", err.Error()))
  430. return errors.ParamsError
  431. }
  432. loginUid, userName, err = utils.GetJwtIdFromCtx(ctx)
  433. return nil
  434. }
  435. // 业务处理
  436. handleServiceTask := func() error {
  437. // 响应数据
  438. _, projectId, err := utils.GetSubjectValue(ctx)
  439. if err != nil {
  440. return err
  441. }
  442. resp := param_v1.ProjectInfoForChangeResponse{}
  443. rpcReq := &v1.ProjectInfoForChangeRequest{
  444. Id: projectId,
  445. }
  446. reply, err := pb.Project.ProjectInfoForChange(ctx, rpcReq)
  447. if err != nil {
  448. s, _ := json.MarshalToString(req)
  449. logger.Error("func",
  450. zap.String("call", "ProjectChange"),
  451. zap.String("params", s),
  452. zap.String("error", err.Error()))
  453. return errors.ErrorTransForm(err)
  454. }
  455. resp.Data = *reply
  456. ctx.JSON(http.StatusOK, resp)
  457. return nil
  458. }
  459. // 执行任务
  460. httptasker.Exec(ctx, parseParamTask, handleServiceTask)
  461. }
  462. // 项目变更申请列表
  463. // @Summary 项目变更申请列表
  464. // @Description 项目变更申请列表
  465. // @Tags 项目后台设置
  466. // @Accept json
  467. // @Produce json
  468. // @Param token header string true " "
  469. // @Param page query int false " "
  470. // @Success 200 {object} v1.ProjectChangeInfoListResponse
  471. // @Failure 500 {object} base.HTTPError
  472. // @Router /api/v1/project/change_job_list [get]
  473. func (c *Controller) ProjectChangeInfoList(ctx *gin.Context) {
  474. // 解析参数
  475. req := &param_v1.ProjectChangeInfoListRequest{}
  476. var loginUid int64
  477. var userName string
  478. parseParamTask := func() error {
  479. err := util.ShouldBind(ctx, &req.Header, nil, &req.ProjectChangeInfoListQuery, nil)
  480. if err != nil {
  481. logger.Error("func",
  482. zap.String("call", "util.ShouldBind"),
  483. zap.String("error", err.Error()))
  484. return errors.ParamsError
  485. }
  486. loginUid, userName, err = utils.GetJwtIdFromCtx(ctx)
  487. return nil
  488. }
  489. // 业务处理
  490. handleServiceTask := func() error {
  491. // 响应数据
  492. _, projectId, err := utils.GetSubjectValue(ctx)
  493. if err != nil {
  494. return err
  495. }
  496. if req.Page < 1 {
  497. req.Page = 1
  498. }
  499. resp := param_v1.ProjectChangeInfoListResponse{}
  500. rpcReq := &v1.ProjectChangeInfoListRequest{
  501. Id: projectId,
  502. Page: req.Page,
  503. }
  504. reply, err := pb.Project.ProjectChangeInfoList(ctx, rpcReq)
  505. if err != nil {
  506. s, _ := json.MarshalToString(req)
  507. logger.Error("func",
  508. zap.String("call", "ProjectChangeInfoList"),
  509. zap.String("params", s),
  510. zap.String("error", err.Error()))
  511. return errors.ErrorTransForm(err)
  512. }
  513. resp.Data = *reply
  514. ctx.JSON(http.StatusOK, resp)
  515. return nil
  516. }
  517. // 执行任务
  518. httptasker.Exec(ctx, parseParamTask, handleServiceTask)
  519. }
  520. // 设备入库审批
  521. // @Summary 设备入库审批
  522. // @Description 设备入库审批
  523. // @Tags 设备后台设置
  524. // @Accept json
  525. // @Produce json
  526. // @Param token header string true " "
  527. // @Param body body v1.DeviceApproveBody true " "
  528. // @Success 200 {object} v1.DeviceApproveResponse
  529. // @Failure 500 {object} base.HTTPError
  530. // @Router /api/v1/project/device_approve [put]
  531. func (c *Controller) DeviceApprove(ctx *gin.Context) {
  532. // 解析参数
  533. req := &param_v1.DeviceApproveRequest{}
  534. var loginUid int64
  535. var userName string
  536. parseParamTask := func() error {
  537. err := util.ShouldBind(ctx, &req.Header, nil, nil, &req.DeviceApproveBody)
  538. if err != nil {
  539. logger.Error("func",
  540. zap.String("call", "util.ShouldBind"),
  541. zap.String("error", err.Error()))
  542. return errors.ParamsError
  543. }
  544. loginUid, userName, err = utils.GetJwtIdFromCtx(ctx)
  545. return nil
  546. }
  547. // 业务处理
  548. var pid int64
  549. handleServiceTask := func() error {
  550. _, projectId, err := utils.GetSubjectValue(ctx)
  551. if err != nil {
  552. return err
  553. }
  554. pid = projectId
  555. // 响应数据
  556. resp := param_v1.DeviceApproveResponse{}
  557. rpcReq := &v1.DeviceApproveRequest{
  558. Id: req.Id,
  559. Status: req.Status,
  560. Feedback: req.Feedback,
  561. }
  562. _, err = pb.Project.DeviceApprove(ctx, rpcReq)
  563. if err != nil {
  564. s, _ := json.MarshalToString(req)
  565. logger.Error("func",
  566. zap.String("call", "DeviceApprove"),
  567. zap.String("params", s),
  568. zap.String("error", err.Error()))
  569. return errors.ErrorTransForm(err)
  570. }
  571. ctx.JSON(http.StatusOK, resp)
  572. return nil
  573. }
  574. // 执行任务
  575. err := httptasker.Exec(ctx, parseParamTask, handleServiceTask)
  576. s, _ := json.MarshalToString(req)
  577. utils.LogWrite("设备入库审批", loginUid, userName, s, err, pid)
  578. }
  579. /*
  580. //
  581. // @Summary 设备下的摄像头
  582. // @Description 设备下的摄像头
  583. // @Tags device
  584. // @Accept json
  585. // @Produce json
  586. // @Param token header string true " "
  587. // @Param device_id query int64 true " "
  588. // @Success 200 {object} v1.DeviceCameraResponse
  589. // @Failure 500 {object} base.HTTPError
  590. // @Router /api/v1/device/camera [get]
  591. func (c *Controller) DeviceCamera(ctx *gin.Context) {
  592. // 解析参数
  593. req := &param_v1.DeviceCameraRequest{}
  594. var loginUid int64
  595. var userName string
  596. parseParamTask := func() error {
  597. err := util.ShouldBind(ctx, nil, nil, &req.DeviceCameraQuery, 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, userName, err = utils.GetJwtIdFromCtx(ctx)
  605. return nil
  606. }
  607. // 业务处理
  608. handleServiceTask := func() error {
  609. _, projectId, err := utils.GetSubjectValue(ctx)
  610. if err != nil {
  611. return err
  612. }
  613. // 响应数据
  614. resp := param_v1.DeviceCameraResponse{}
  615. rpcReq := &v1.CameraListRequest{
  616. DeviceId:req.DeviceId,
  617. ProjectId:projectId,
  618. }
  619. rpcRsp, err := pb.Project.CameraList(ctx, rpcReq)
  620. if err != nil {
  621. s, _ := json.MarshalToString(req)
  622. logger.Error("func",
  623. zap.String("call", "pb.Project.CameraList"),
  624. zap.String("params", s),
  625. zap.String("error", err.Error()))
  626. return errors.ErrorTransForm(err)
  627. }
  628. if len(rpcRsp.List) > 0 {
  629. resp.Data = *rpcRsp.List[0]
  630. }
  631. ctx.JSON(http.StatusOK, resp)
  632. return nil
  633. }
  634. // 执行任务
  635. httptasker.Exec(ctx, parseParamTask, handleServiceTask)
  636. }
  637. */
  638. // 项目信息
  639. // @Summary 项目信息
  640. // @Description 项目信息
  641. // @Tags project
  642. // @Accept json
  643. // @Produce json
  644. // @Param token header string true " "
  645. // @Success 200 {object} v1.ProjectInfoResponse
  646. // @Failure 500 {object} base.HTTPError
  647. // @Router /api/v1/project/info [get]
  648. func (c *Controller) ProjectInfo(ctx *gin.Context) {
  649. // 解析参数
  650. req := &param_v1.ProjectInfoRequest{}
  651. var loginUid int64
  652. var userName string
  653. parseParamTask := func() error {
  654. err := util.ShouldBind(ctx, &req.Header, nil, nil, nil)
  655. if err != nil {
  656. logger.Error("func",
  657. zap.String("call", "util.ShouldBind"),
  658. zap.String("error", err.Error()))
  659. return errors.ParamsError
  660. }
  661. loginUid, userName, err = utils.GetJwtIdFromCtx(ctx)
  662. return nil
  663. }
  664. // 业务处理
  665. handleServiceTask := func() error {
  666. // 响应数据
  667. _, projectId, err := utils.GetSubjectValue(ctx)
  668. if err != nil {
  669. return err
  670. }
  671. resp := param_v1.ProjectInfoResponse{}
  672. rpcReq := &v1.ProjectInfoRequest{
  673. ProjectId:projectId,
  674. }
  675. reply, err := pb.Project.ProjectInfo(ctx, rpcReq)
  676. if err != nil {
  677. s, _ := json.MarshalToString(req)
  678. logger.Error("func",
  679. zap.String("call", "ProjectInfo"),
  680. zap.String("params", s),
  681. zap.String("error", err.Error()))
  682. return errors.ErrorTransForm(err)
  683. }
  684. resp.Data = *reply
  685. ctx.JSON(http.StatusOK, resp)
  686. return nil
  687. }
  688. // 执行任务
  689. httptasker.Exec(ctx, parseParamTask, handleServiceTask)
  690. }
  691. // 项目设备统计
  692. // @Summary 项目设备统计
  693. // @Description 项目设备统计
  694. // @Tags project
  695. // @Accept json
  696. // @Produce json
  697. // @Param token header string true " "
  698. // @Success 200 {object} v1.ProjectDeviceStatisticsResponse
  699. // @Failure 500 {object} base.HTTPError
  700. // @Router /api/v1/project/device_statistics [get]
  701. func (c *Controller) ProjectDeviceStatistics(ctx *gin.Context) {
  702. // 解析参数
  703. req := &param_v1.ProjectDeviceStatisticsRequest{}
  704. var loginUid int64
  705. var userName string
  706. parseParamTask := func() error {
  707. err := util.ShouldBind(ctx, &req.Header, nil, nil, nil)
  708. if err != nil {
  709. logger.Error("func",
  710. zap.String("call", "util.ShouldBind"),
  711. zap.String("error", err.Error()))
  712. return errors.ParamsError
  713. }
  714. loginUid, userName, err = utils.GetJwtIdFromCtx(ctx)
  715. return nil
  716. }
  717. // 业务处理
  718. handleServiceTask := func() error {
  719. // 响应数据
  720. _, projectId, err := utils.GetSubjectValue(ctx)
  721. if err != nil {
  722. return err
  723. }
  724. resp := param_v1.ProjectDeviceStatisticsResponse{}
  725. rpcReq := &v1.ProjectDeviceStatisticsRequest{
  726. ProjectId:projectId,
  727. }
  728. reply, err := pb.Project.ProjectDeviceStatistics(ctx, rpcReq)
  729. if err != nil {
  730. s, _ := json.MarshalToString(req)
  731. logger.Error("func",
  732. zap.String("call", "ProjectDeviceStatistics"),
  733. zap.String("params", s),
  734. zap.String("error", err.Error()))
  735. return errors.ErrorTransForm(err)
  736. }
  737. resp.Data = *reply
  738. if resp.Data.List == nil {
  739. resp.Data.List = []*v1.ProjectDeviceStatistics{}
  740. }
  741. ctx.JSON(http.StatusOK, resp)
  742. return nil
  743. }
  744. // 执行任务
  745. httptasker.Exec(ctx, parseParamTask, handleServiceTask)
  746. }
  747. // 项目进度列表
  748. // @Summary 项目进度列表
  749. // @Description 项目进度列表
  750. // @Tags project
  751. // @Accept json
  752. // @Produce json
  753. // @Param token header string true " "
  754. // @Success 200 {object} v1.ProjectProgressResponse
  755. // @Failure 500 {object} base.HTTPError
  756. // @Router /api/v1/project/progress_list [get]
  757. func (c *Controller) ProjectProgress(ctx *gin.Context) {
  758. // 解析参数
  759. req := &param_v1.ProjectProgressRequest{}
  760. var loginUid int64
  761. var userName string
  762. parseParamTask := func() error {
  763. err := util.ShouldBind(ctx, &req.Header, nil, nil, nil)
  764. if err != nil {
  765. logger.Error("func",
  766. zap.String("call", "util.ShouldBind"),
  767. zap.String("error", err.Error()))
  768. return errors.ParamsError
  769. }
  770. loginUid, userName, err = utils.GetJwtIdFromCtx(ctx)
  771. return nil
  772. }
  773. // 业务处理
  774. handleServiceTask := func() error {
  775. // 响应数据
  776. _, projectId, err := utils.GetSubjectValue(ctx)
  777. if err != nil {
  778. return err
  779. }
  780. resp := param_v1.ProjectProgressResponse{}
  781. rpcReq := &v1.ProjectProgressRequest{
  782. ProjectId:projectId,
  783. }
  784. reply, err := pb.Project.ProjectProgress(ctx, rpcReq)
  785. if err != nil {
  786. s, _ := json.MarshalToString(req)
  787. logger.Error("func",
  788. zap.String("call", "ProjectProgress"),
  789. zap.String("params", s),
  790. zap.String("error", err.Error()))
  791. return errors.ErrorTransForm(err)
  792. }
  793. resp.Data = *reply
  794. if resp.Data.List == nil {
  795. resp.Data.List = []*v1.ProjectProgress{}
  796. }
  797. ctx.JSON(http.StatusOK, resp)
  798. return nil
  799. }
  800. // 执行任务
  801. httptasker.Exec(ctx, parseParamTask, handleServiceTask)
  802. }
  803. // 添加项目进度
  804. // @Summary 添加项目进度
  805. // @Description 添加项目进度
  806. // @Tags project
  807. // @Accept json
  808. // @Produce json
  809. // @Param token header string true " "
  810. // @Param body body v1.ProjectProgressAddBody true " "
  811. // @Success 200 {object} v1.ProjectProgressAddResponse
  812. // @Failure 500 {object} base.HTTPError
  813. // @Router /api/v1/project/progress [post]
  814. func (c *Controller) ProjectProgressAdd(ctx *gin.Context) {
  815. // 解析参数
  816. req := &param_v1.ProjectProgressAddRequest{}
  817. var loginUid int64
  818. var userName string
  819. parseParamTask := func() error {
  820. err := util.ShouldBind(ctx, &req.Header, nil, nil, &req.ProjectProgressAddBody)
  821. if err != nil {
  822. logger.Error("func",
  823. zap.String("call", "util.ShouldBind"),
  824. zap.String("error", err.Error()))
  825. return errors.ParamsError
  826. }
  827. loginUid, userName, err = utils.GetJwtIdFromCtx(ctx)
  828. return nil
  829. }
  830. // 业务处理
  831. var pid int64
  832. handleServiceTask := func() error {
  833. // 响应数据
  834. _, projectId, err := utils.GetSubjectValue(ctx)
  835. if err != nil {
  836. return err
  837. }
  838. pid = projectId
  839. resp := param_v1.ProjectProgressAddResponse{}
  840. rpcReq := &v1.ProjectProgressAddRequest{
  841. ProjectId:projectId,
  842. Name:req.Name,
  843. ExpectEndTime:req.ExpectEndTime,
  844. ExpectStartTime:req.ExpectStartTime,
  845. }
  846. reply, err := pb.Project.ProjectProgressAdd(ctx, rpcReq)
  847. if err != nil {
  848. s, _ := json.MarshalToString(req)
  849. logger.Error("func",
  850. zap.String("call", "ProjectProgressAdd"),
  851. zap.String("params", s),
  852. zap.String("error", err.Error()))
  853. return errors.ErrorTransForm(err)
  854. }
  855. resp.Data = *reply
  856. ctx.JSON(http.StatusOK, resp)
  857. return nil
  858. }
  859. // 执行任务
  860. err := httptasker.Exec(ctx, parseParamTask, handleServiceTask)
  861. s, _ := json.MarshalToString(req)
  862. utils.LogWrite("添加项目进度", loginUid, userName, s, err, pid)
  863. }
  864. //
  865. // @Summary 项目进度完成或开工
  866. // @Description 项目进度完成或开工
  867. // @Tags project
  868. // @Accept json
  869. // @Produce json
  870. // @Param token header string true " "
  871. // @Param body body v1.ProjectProgressSetBody true " "
  872. // @Success 200 {object} v1.ProjectProgressSetResponse
  873. // @Failure 500 {object} base.HTTPError
  874. // @Router /api/v1/project/progress [put]
  875. func (c *Controller) ProjectProgressSet(ctx *gin.Context) {
  876. // 解析参数
  877. req := &param_v1.ProjectProgressSetRequest{}
  878. var loginUid int64
  879. var userName string
  880. parseParamTask := func() error {
  881. err := util.ShouldBind(ctx, &req.Header, nil, nil, &req.ProjectProgressSetBody)
  882. if err != nil {
  883. logger.Error("func",
  884. zap.String("call", "util.ShouldBind"),
  885. zap.String("error", err.Error()))
  886. return errors.ParamsError
  887. }
  888. if (req.RealityStartTime <= 0 && req.RealityEndTime <= 0) ||
  889. (req.RealityStartTime > 0 && req.RealityEndTime > 0) {
  890. return errors.ParamsError
  891. }
  892. loginUid, userName, err = utils.GetJwtIdFromCtx(ctx)
  893. return nil
  894. }
  895. // 业务处理
  896. var pid int64
  897. handleServiceTask := func() error {
  898. _, projectId, err := utils.GetSubjectValue(ctx)
  899. if err != nil {
  900. return err
  901. }
  902. pid = projectId
  903. // 响应数据
  904. resp := param_v1.ProjectProgressSetResponse{}
  905. rpcReq := &v1.ProjectProgressSetRequest{
  906. Id:req.Id,
  907. Image:req.Image,
  908. Start:req.RealityStartTime,
  909. End:req.RealityEndTime,
  910. }
  911. _, err = pb.Project.ProjectProgressSet(ctx, rpcReq)
  912. if err != nil {
  913. s, _ := json.MarshalToString(req)
  914. logger.Error("func",
  915. zap.String("call", "ProjectProgressSet"),
  916. zap.String("params", s),
  917. zap.String("error", err.Error()))
  918. return errors.ErrorTransForm(err)
  919. }
  920. ctx.JSON(http.StatusOK, resp)
  921. return nil
  922. }
  923. // 执行任务
  924. err := httptasker.Exec(ctx, parseParamTask, handleServiceTask)
  925. s, _ := json.MarshalToString(req)
  926. utils.LogWrite("项目进度完成", loginUid, userName, s, err, pid)
  927. }
  928. // 删除项目进度
  929. // @Summary 删除项目进度
  930. // @Description 删除项目进度
  931. // @Tags project
  932. // @Accept json
  933. // @Produce json
  934. // @Param token header string true " "
  935. // @Param id path int64 true " "
  936. // @Success 200 {object} v1.ProjectProgressDelResponse
  937. // @Failure 500 {object} base.HTTPError
  938. // @Router /api/v1/project/progress/{id} [delete]
  939. func (c *Controller) ProjectProgressDel(ctx *gin.Context) {
  940. // 解析参数
  941. req := &param_v1.ProjectProgressDelRequest{}
  942. var loginUid int64
  943. var userName string
  944. parseParamTask := func() error {
  945. err := util.ShouldBind(ctx, &req.Header, &req.ProjectProgressDelPath, nil, nil)
  946. if err != nil {
  947. logger.Error("func",
  948. zap.String("call", "util.ShouldBind"),
  949. zap.String("error", err.Error()))
  950. return errors.ParamsError
  951. }
  952. loginUid, userName, err = utils.GetJwtIdFromCtx(ctx)
  953. return nil
  954. }
  955. // 业务处理
  956. var pid int64
  957. handleServiceTask := func() error {
  958. _, projectId, err := utils.GetSubjectValue(ctx)
  959. if err != nil {
  960. return err
  961. }
  962. pid = projectId
  963. // 响应数据
  964. resp := param_v1.ProjectProgressDelResponse{}
  965. rpcReq := &v1.ProjectProgressDelRequest{
  966. Id:req.Id,
  967. }
  968. _, err = pb.Project.ProjectProgressDel(ctx, rpcReq)
  969. if err != nil {
  970. s, _ := json.MarshalToString(req)
  971. logger.Error("func",
  972. zap.String("call", "ProjectProgressDel"),
  973. zap.String("params", s),
  974. zap.String("error", err.Error()))
  975. return errors.ErrorTransForm(err)
  976. }
  977. ctx.JSON(http.StatusOK, resp)
  978. return nil
  979. }
  980. // 执行任务
  981. err := httptasker.Exec(ctx, parseParamTask, handleServiceTask)
  982. s, _ := json.MarshalToString(req)
  983. utils.LogWrite("删除项目进度", loginUid, userName, s, err, pid)
  984. }
  985. // 设备绑定的摄像头
  986. // @Summary 设备绑定的摄像头
  987. // @Description 设备绑定的摄像头
  988. // @Tags device
  989. // @Accept json
  990. // @Produce json
  991. // @Param token header string true " "
  992. // @Param sn query string false " "
  993. // @Success 200 {object} v1.DeviceVideoChannelResponse
  994. // @Failure 500 {object} base.HTTPError
  995. // @Router /api/v1/device/vedio_channel [get]
  996. func (c *Controller) DeviceVideoChannel(ctx *gin.Context) {
  997. // 解析参数
  998. req := &param_v1.DeviceVideoChannelRequest{}
  999. var loginUid int64
  1000. var userName string
  1001. parseParamTask := func() error {
  1002. err := util.ShouldBind(ctx, &req.Header, nil, &req.DeviceVideoChannelQuery, nil)
  1003. if err != nil {
  1004. logger.Error("func",
  1005. zap.String("call", "util.ShouldBind"),
  1006. zap.String("error", err.Error()))
  1007. return errors.ParamsError
  1008. }
  1009. loginUid, userName, err = utils.GetJwtIdFromCtx(ctx)
  1010. return nil
  1011. }
  1012. // 业务处理
  1013. handleServiceTask := func() error {
  1014. // 响应数据
  1015. _, projectId, err := utils.GetSubjectValue(ctx)
  1016. if err != nil {
  1017. return err
  1018. }
  1019. resp := param_v1.DeviceVideoChannelResponse{}
  1020. rpcReq := &v1.DeviceVideoChannelRequest{}
  1021. rpcReq.Sn = req.Sn
  1022. rpcReq.ProjectId = projectId
  1023. /*
  1024. if req.FilterStatus != "" {
  1025. array := strings.Split(req.FilterStatus, ",")
  1026. for _, v := range array {
  1027. value, _ := strconv.Atoi(v)
  1028. rpcReq.StatusFilters = append(rpcReq.StatusFilters, int32(value))
  1029. }
  1030. }*/
  1031. reply, err := pb.Project.DeviceVideoChannel(ctx, rpcReq)
  1032. if err != nil {
  1033. s, _ := json.MarshalToString(req)
  1034. logger.Error("func",
  1035. zap.String("call", "DeviceVideoChannel"),
  1036. zap.String("params", s),
  1037. zap.String("error", err.Error()))
  1038. return errors.ErrorTransForm(err)
  1039. }
  1040. resp.Data = *reply
  1041. ctx.JSON(http.StatusOK, resp)
  1042. return nil
  1043. }
  1044. // 执行任务
  1045. httptasker.Exec(ctx, parseParamTask, handleServiceTask)
  1046. }
  1047. // 设置项目平面图或效果图
  1048. // @Summary 设置项目平面图或效果图
  1049. // @Description 设置项目平面图或效果图
  1050. // @Tags 项目后台设置
  1051. // @Accept json
  1052. // @Produce json
  1053. // @Param token header string true " "
  1054. // @Param body body v1.ProjectSetPicBody true " "
  1055. // @Success 200 {object} v1.ProjectSetPicResponse
  1056. // @Failure 500 {object} base.HTTPError
  1057. // @Router /api/v1/project/pic [put]
  1058. func (c *Controller) ProjectSetPic(ctx *gin.Context) {
  1059. // 解析参数
  1060. req := &param_v1.ProjectSetPicRequest{}
  1061. var loginUid int64
  1062. var userName string
  1063. parseParamTask := func() error {
  1064. err := util.ShouldBind(ctx, &req.Header, nil, nil, &req.ProjectSetPicBody)
  1065. if err != nil {
  1066. logger.Error("func",
  1067. zap.String("call", "util.ShouldBind"),
  1068. zap.String("error", err.Error()))
  1069. return errors.ParamsError
  1070. }
  1071. loginUid, userName, err = utils.GetJwtIdFromCtx(ctx)
  1072. return nil
  1073. }
  1074. // 业务处理
  1075. var pid int64
  1076. handleServiceTask := func() error {
  1077. // 响应数据
  1078. _, projectId, err := utils.GetSubjectValue(ctx)
  1079. if err != nil {
  1080. return err
  1081. }
  1082. pid = projectId
  1083. resp := param_v1.ProjectSetPicResponse{}
  1084. rpcReq := &v1.ProjectSetPicRequest{
  1085. ProjectId: projectId,
  1086. PicUrl:req.PicUrl,
  1087. PicType:req.PicType,
  1088. }
  1089. _, err = pb.Project.ProjectSetPic(ctx, rpcReq)
  1090. if err != nil {
  1091. s, _ := json.MarshalToString(req)
  1092. logger.Error("func",
  1093. zap.String("call", "ProjectSetPic"),
  1094. zap.String("params", s),
  1095. zap.String("error", err.Error()))
  1096. return errors.ErrorTransForm(err)
  1097. }
  1098. ctx.JSON(http.StatusOK, resp)
  1099. return nil
  1100. }
  1101. // 执行任务
  1102. err := httptasker.Exec(ctx, parseParamTask, handleServiceTask)
  1103. s, _ := json.MarshalToString(req)
  1104. utils.LogWrite("设置项目平面图或效果图", loginUid, userName, s, err, pid)
  1105. }
  1106. // 修改项目名称或地址
  1107. // @Summary 修改项目名称或地址
  1108. // @Description 修改项目名称或地址
  1109. // @Tags 项目后台设置
  1110. // @Accept json
  1111. // @Produce json
  1112. // @Param token header string true " "
  1113. // @Param body body v1.ProjectUpdateBody true " "
  1114. // @Success 200 {object} v1.ProjectUpdateResponse
  1115. // @Failure 500 {object} base.HTTPError
  1116. // @Router /api/v1/project/name_location [put]
  1117. func (c *Controller) ProjectUpdate(ctx *gin.Context) {
  1118. // 解析参数
  1119. req := &param_v1.ProjectUpdateRequest{}
  1120. var loginUid int64
  1121. var userName string
  1122. parseParamTask := func() error {
  1123. err := util.ShouldBind(ctx, &req.Header, nil, nil, &req.ProjectUpdateBody)
  1124. if err != nil {
  1125. logger.Error("func",
  1126. zap.String("call", "util.ShouldBind"),
  1127. zap.String("error", err.Error()))
  1128. return errors.ParamsError
  1129. }
  1130. loginUid, userName, err = utils.GetJwtIdFromCtx(ctx)
  1131. return nil
  1132. }
  1133. // 业务处理
  1134. var pid int64
  1135. handleServiceTask := func() error {
  1136. // 响应数据
  1137. _, projectId, err := utils.GetSubjectValue(ctx)
  1138. if err != nil {
  1139. return err
  1140. }
  1141. pid = projectId
  1142. resp := param_v1.ProjectUpdateResponse{}
  1143. rpcReq := &v1.ProjectUpdateRequest{
  1144. ProjectId: projectId,
  1145. Name:req.Name,
  1146. ShortName:req.ShortName,
  1147. Location:req.Location,
  1148. }
  1149. _, err = pb.Project.ProjectUpdate(ctx, rpcReq)
  1150. if err != nil {
  1151. s, _ := json.MarshalToString(req)
  1152. logger.Error("func",
  1153. zap.String("call", "ProjectUpdate"),
  1154. zap.String("params", s),
  1155. zap.String("error", err.Error()))
  1156. return errors.ErrorTransForm(err)
  1157. }
  1158. ctx.JSON(http.StatusOK, resp)
  1159. return nil
  1160. }
  1161. // 执行任务
  1162. err := httptasker.Exec(ctx, parseParamTask, handleServiceTask)
  1163. s, _ := json.MarshalToString(req)
  1164. utils.LogWrite("修改项目名称或地址", loginUid, userName, s, err, pid)
  1165. }