appdeviceconfig.go 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. package business
  2. import (
  3. "fmt"
  4. "time"
  5. "github.com/gin-gonic/gin"
  6. "github.com/gin-gonic/gin/binding"
  7. //"device-manage/app/admin/models"
  8. "device-manage/app/admin/models/busmodels"
  9. "device-manage/tools"
  10. "device-manage/tools/app"
  11. )
  12. func GetAppDeviceBindedList(c *gin.Context) {
  13. var data busmodels.BusAppDeviceBind
  14. var params busmodels.QueryBindedDeviceParams
  15. err := c.MustBindWith(&params, binding.JSON)
  16. pageSize := params.PageSize
  17. pageIndex := params.PageIndex
  18. gids := params.Gids
  19. deviceSn := params.DeviceSn
  20. data.AppId = params.AppId
  21. fmt.Println(data)
  22. result, count, err := data.GetBindedPage(pageSize, pageIndex, deviceSn, gids)
  23. tools.HasError(err, "", -1)
  24. app.PageOK(c, result, count, pageIndex, pageSize, "")
  25. }
  26. //deviceSn是查询参数
  27. func GetAppDeviceUnBindedList(c *gin.Context) {
  28. var data busmodels.BusAppDeviceBind
  29. var params busmodels.QueryBindedDeviceParams
  30. err := c.MustBindWith(&params, binding.JSON)
  31. pageSize := params.PageSize
  32. pageIndex := params.PageIndex
  33. gids := params.Gids
  34. deviceSn := params.DeviceSn
  35. data.AppId = params.AppId
  36. result, count, err := data.GetUnBindedPage(pageSize, pageIndex, deviceSn, gids)
  37. tools.HasError(err, "", -1)
  38. app.PageOK(c, result, count, pageIndex, pageSize, "")
  39. }
  40. func InsertAppDeviceBinded(c *gin.Context) {
  41. var data busmodels.AppDeviceData
  42. var bindInfo busmodels.BusAppDeviceBind
  43. err := c.ShouldBindWith(&data, binding.JSON)
  44. tools.HasError(err, "非法数据格式", 500)
  45. user := tools.GetUserIdStr(c)
  46. bindInfo.CreateBy = user
  47. bindInfo.UpdateBy = user
  48. fmt.Println(user)
  49. times := time.Now()
  50. bindInfo.CreatedAt = times
  51. bindInfo.UpdatedAt = times
  52. id, err := bindInfo.Insert(data)
  53. fmt.Println(id)
  54. tools.HasError(err, "绑定失败", 500)
  55. app.OK(c, id, "绑定成功")
  56. }
  57. func DeleteAppDeviceBinded(c *gin.Context) {
  58. var data busmodels.BusAppDeviceBind
  59. data.UpdateBy = tools.GetUserIdStr(c)
  60. IDS := tools.IdsStrToIdsIntGroup("bindId", c)
  61. fmt.Println(IDS)
  62. result, err := data.BatchDelete(IDS)
  63. tools.HasError(err, "解绑定失败", 500)
  64. app.OK(c, result, "解绑定成功")
  65. }