dev_screens.go 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223
  1. package devices
  2. import (
  3. "github.com/gin-gonic/gin"
  4. "go.uber.org/zap"
  5. "server/dao/devices"
  6. "server/global"
  7. promodel "server/model/common/devices"
  8. "server/model/common/request"
  9. "server/model/common/response"
  10. model "server/model/devices"
  11. "server/utils"
  12. )
  13. type ScreensApi struct{}
  14. func (s *ScreensApi) QueryScreensParms(c *gin.Context) {
  15. list, err := ScreensService.QueryScreensParms()
  16. if err != nil {
  17. global.GVA_LOG.Error("获取屏参失败!", zap.Error(err))
  18. response.FailWithMessage("获取失败", c)
  19. return
  20. }
  21. response.OkWithDetailed(list, "获取成功", c)
  22. }
  23. func (s *ScreensApi) ScreensList(c *gin.Context) {
  24. var pageInfo request.PageInfo
  25. err := c.ShouldBindJSON(&pageInfo)
  26. if err != nil {
  27. response.FailWithMessage(err.Error(), c)
  28. return
  29. }
  30. err = utils.Verify(pageInfo, utils.PageInfoVerify)
  31. if err != nil {
  32. response.FailWithMessage(err.Error(), c)
  33. return
  34. }
  35. list, total, err := ScreensService.GetScreensInfoList(pageInfo)
  36. if err != nil {
  37. global.GVA_LOG.Error("获取失败!", zap.Error(err))
  38. response.FailWithMessage("获取失败", c)
  39. return
  40. }
  41. response.OkWithDetailed(response.PageResult{
  42. List: list,
  43. Total: total,
  44. Page: pageInfo.Page,
  45. PageSize: pageInfo.PageSize,
  46. }, "获取成功", c)
  47. }
  48. func (s *ScreensApi) DelScreens(c *gin.Context) {
  49. var reqId request.GetById
  50. err := c.ShouldBindJSON(&reqId)
  51. if err != nil {
  52. response.FailWithMessage(err.Error(), c)
  53. return
  54. }
  55. err = utils.Verify(reqId, utils.IdVerify)
  56. if err != nil {
  57. response.FailWithMessage(err.Error(), c)
  58. return
  59. }
  60. err = ScreensService.DelScreens(reqId.ID)
  61. if err != nil {
  62. global.GVA_LOG.Error("删除失败!", zap.Error(err))
  63. response.FailWithMessage("删除失败", c)
  64. return
  65. }
  66. response.OkWithMessage("删除成功", c)
  67. }
  68. func (s *ScreensApi) AddScreens(c *gin.Context) {
  69. var sc model.ReqScreens
  70. err := c.ShouldBindJSON(&sc)
  71. if err != nil {
  72. response.FailWithMessage(err.Error(), c)
  73. return
  74. }
  75. screens := devices.Screens{
  76. ScreensName: sc.ScreensName,
  77. ScreensCode: sc.ScreensCode,
  78. Sn: sc.Sn,
  79. Network: sc.Network,
  80. ScreensBrand: sc.ScreensBrand,
  81. ScreensModel: sc.ScreensModel,
  82. IPAddress: sc.IpAddress,
  83. GatewayId: sc.GatewayID,
  84. ResolutionId: sc.ResolutionId,
  85. ScreensSizeId: sc.ScreensSizeId,
  86. Shunt: sc.Shunt,
  87. ShuntDescribe: sc.ShuntDescribe,
  88. InstallTime: sc.InstallTime,
  89. }
  90. err = ScreensService.AddScreens(screens)
  91. if err != nil {
  92. global.GVA_LOG.Error(err.Error(), zap.Error(err))
  93. response.FailWithMessage(err.Error(), c)
  94. return
  95. }
  96. response.OkWithMessage("添加成功", c)
  97. }
  98. func (s *ScreensApi) UpdateScreens(c *gin.Context) {
  99. var sc model.ReqScreens
  100. err := c.ShouldBindJSON(&sc)
  101. if err != nil {
  102. response.FailWithMessage(err.Error(), c)
  103. return
  104. }
  105. err = utils.Verify(sc, utils.IdVerify)
  106. if err != nil {
  107. response.FailWithMessage(err.Error(), c)
  108. return
  109. }
  110. screens := devices.Screens{
  111. ID: sc.ID,
  112. ScreensName: sc.ScreensName,
  113. ScreensCode: sc.ScreensCode,
  114. Sn: sc.Sn,
  115. Network: sc.Network,
  116. ScreensBrand: sc.ScreensBrand,
  117. ScreensModel: sc.ScreensModel,
  118. IPAddress: sc.IpAddress,
  119. GatewayId: sc.GatewayID,
  120. ResolutionId: sc.ResolutionId,
  121. ScreensSizeId: sc.ScreensSizeId,
  122. Shunt: sc.Shunt,
  123. ShuntDescribe: sc.ShuntDescribe,
  124. InstallTime: sc.InstallTime,
  125. }
  126. err = ScreensService.UpdateScreens(screens)
  127. if err != nil {
  128. global.GVA_LOG.Error("设置失败!", zap.Error(err))
  129. response.FailWithMessage("设置失败", c)
  130. return
  131. }
  132. response.OkWithMessage("设置成功", c)
  133. }
  134. // 熄屏-亮屏幕
  135. func (s *ScreensApi) SwitchScreens(c *gin.Context) {
  136. var swch promodel.SwitchScreens
  137. err := c.ShouldBindJSON(&swch)
  138. if err != nil {
  139. response.FailWithMessage(err.Error(), c)
  140. return
  141. }
  142. err = ScreensService.SwitchScreens(swch)
  143. if err != nil {
  144. global.GVA_LOG.Error("操作失败!", zap.Error(err))
  145. response.FailWithMessage("操作失败", c)
  146. return
  147. }
  148. response.OkWithMessage("操作成功", c)
  149. }
  150. // 发送内码文字
  151. func (s *ScreensApi) SendInternalCode(c *gin.Context) {
  152. var ic model.ReqInCode
  153. err := c.ShouldBindJSON(&ic)
  154. if err != nil {
  155. response.FailWithMessage(err.Error(), c)
  156. return
  157. }
  158. var inCodeArr []promodel.InternalCodeContent
  159. for _, content := range ic.Content {
  160. inCode := promodel.InternalCodeContent{Text: content.Text, Color: 0x01, Size: 0x12} //默认红色,大小24号
  161. if content.Color == "绿色" {
  162. inCode.Color = 0x02
  163. }
  164. if content.Color == "黄色" {
  165. inCode.Color = 0x03
  166. }
  167. inCodeArr = append(inCodeArr, inCode)
  168. }
  169. err = ScreensService.SendInternalCode(ic.Sn, inCodeArr)
  170. if err != nil {
  171. global.GVA_LOG.Error("操作失败!", zap.Error(err))
  172. response.FailWithMessage("操作失败", c)
  173. return
  174. }
  175. response.OkWithMessage("操作成功", c)
  176. }
  177. // 远程喊话
  178. func (s *ScreensApi) VoiceBroad(c *gin.Context) {
  179. var vb promodel.VoiceBroad
  180. err := c.ShouldBindJSON(&vb)
  181. if err != nil {
  182. response.FailWithMessage(err.Error(), c)
  183. return
  184. }
  185. err = ScreensService.VoiceBroad(vb.Sn, vb.BroadContent)
  186. if err != nil {
  187. global.GVA_LOG.Error("操作失败!", zap.Error(err))
  188. response.FailWithMessage("操作失败", c)
  189. return
  190. }
  191. response.OkWithMessage("操作成功", c)
  192. }
  193. // 调节亮度
  194. func (s *ScreensApi) SetBright(c *gin.Context) {
  195. var sb model.ReqBrightness
  196. err := c.ShouldBindJSON(&sb)
  197. if err != nil {
  198. response.FailWithMessage(err.Error(), c)
  199. return
  200. }
  201. err = ScreensService.SetBright(sb)
  202. if err != nil {
  203. global.GVA_LOG.Error("操作失败!", zap.Error(err))
  204. response.FailWithMessage("操作失败", c)
  205. return
  206. }
  207. response.OkWithMessage("操作成功", c)
  208. }