mapInfoLogic.go 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. package logic
  2. import (
  3. "errors"
  4. "git.rtzhtech.cn/iss/public-lib/dao"
  5. "git.rtzhtech.cn/iss/public-lib/dto"
  6. "git.rtzhtech.cn/iss/public-lib/model"
  7. "git.rtzhtech.cn/iss/public-lib/svc"
  8. "github.com/gogf/gf/v2/util/gconv"
  9. )
  10. // NewMapInfoLogic
  11. // @函数名:NewMapInfoLogic
  12. // @函数功能描述: 初始化地图信息
  13. // @返回值:*MapInfoLogic
  14. //
  15. func NewMapInfoLogic() *MapInfoLogic {
  16. return &MapInfoLogic{
  17. SvcCtx: svc.SvcCtx,
  18. }
  19. }
  20. type MapInfoLogic struct {
  21. SvcCtx *svc.ServiceContext
  22. }
  23. // GetMapInfo
  24. // @函数名:GetMapInfo
  25. // @函数功能描述: 获取地图信息
  26. // @对象名:c
  27. // @参数定义:req
  28. // @返回值:*dto.GetMapInfoResponse
  29. // @返回值:error
  30. //
  31. func (c *MapInfoLogic) GetMapInfo(req *dto.GetMapInfoRequest) (*dto.GetMapInfoResponse, error) {
  32. var (
  33. resp = new(dto.GetMapInfoResponse)
  34. total int64
  35. )
  36. cond := dao.Condition{}
  37. where := make(map[string]any)
  38. if req.Stageid != "" {
  39. where["stageid"] = req.Stageid
  40. }
  41. if req.AppId != 0 {
  42. where["appid"] = req.AppId
  43. }
  44. if req.Stationid != 0 {
  45. where["stationid"] = req.Stationid
  46. }
  47. if req.Maptype != 0 {
  48. where["maptype"] = req.Maptype
  49. }
  50. if req.Index != 0 {
  51. where["index"] = req.Index
  52. }
  53. cond.Where = where
  54. err := c.SvcCtx.MapInfo.Base.Count(&cond, &total)
  55. if err != nil {
  56. return resp, err
  57. }
  58. if total == 0 {
  59. return resp, nil
  60. }
  61. if req.Limit < 1 {
  62. req.Limit = 20
  63. }
  64. if req.Page < 1 {
  65. req.Page = 1
  66. }
  67. cond.Offset = (req.Page - 1) * req.Limit
  68. cond.Limit = req.Limit
  69. cond.OrderBy = "id desc"
  70. err = c.SvcCtx.MapInfo.Base.Find(&cond, &resp.List)
  71. if err != nil {
  72. return resp, err
  73. }
  74. resp.Total = total
  75. return resp, nil
  76. }
  77. // SaveMapInfo
  78. // @函数名:SaveMapInfo
  79. // @函数功能描述: 保存地图信息
  80. // @对象名:c
  81. // @参数定义:req
  82. // @返回值:error
  83. //
  84. func (c *MapInfoLogic) SaveMapInfo(req *model.MapInfo) error {
  85. maps := gconv.Map(req)
  86. return c.SvcCtx.MapInfo.Base.Replace(maps)
  87. }
  88. // DelMapInfo
  89. // @函数名:DelMapInfo
  90. // @函数功能描述: 删除地图信息
  91. // @对象名:c
  92. // @参数定义:id
  93. // @返回值:error
  94. //
  95. func (c *MapInfoLogic) DelMapInfo(id int32) error {
  96. if id == 0 {
  97. return errors.New("参数id为0")
  98. }
  99. md := c.SvcCtx.MapInfo
  100. _, err := md.Where(md.ID.Eq(id)).Delete()
  101. return err
  102. }