package logic import ( "errors" "git.rtzhtech.cn/iss/public-lib/dao" "git.rtzhtech.cn/iss/public-lib/dto" "git.rtzhtech.cn/iss/public-lib/model" "git.rtzhtech.cn/iss/public-lib/svc" "github.com/gogf/gf/v2/util/gconv" ) // NewMapInfoLogic // @函数名:NewMapInfoLogic // @函数功能描述: 初始化地图信息 // @返回值:*MapInfoLogic // func NewMapInfoLogic() *MapInfoLogic { return &MapInfoLogic{ SvcCtx: svc.SvcCtx, } } type MapInfoLogic struct { SvcCtx *svc.ServiceContext } // GetMapInfo // @函数名:GetMapInfo // @函数功能描述: 获取地图信息 // @对象名:c // @参数定义:req // @返回值:*dto.GetMapInfoResponse // @返回值:error // func (c *MapInfoLogic) GetMapInfo(req *dto.GetMapInfoRequest) (*dto.GetMapInfoResponse, error) { var ( resp = new(dto.GetMapInfoResponse) total int64 ) cond := dao.Condition{} where := make(map[string]any) if req.Stageid != "" { where["stageid"] = req.Stageid } if req.AppId != 0 { where["appid"] = req.AppId } if req.Stationid != 0 { where["stationid"] = req.Stationid } if req.Maptype != 0 { where["maptype"] = req.Maptype } if req.Index != 0 { where["index"] = req.Index } cond.Where = where err := c.SvcCtx.MapInfo.Base.Count(&cond, &total) if err != nil { return resp, err } if total == 0 { return resp, nil } if req.Limit < 1 { req.Limit = 20 } if req.Page < 1 { req.Page = 1 } cond.Offset = (req.Page - 1) * req.Limit cond.Limit = req.Limit cond.OrderBy = "id desc" err = c.SvcCtx.MapInfo.Base.Find(&cond, &resp.List) if err != nil { return resp, err } resp.Total = total return resp, nil } // SaveMapInfo // @函数名:SaveMapInfo // @函数功能描述: 保存地图信息 // @对象名:c // @参数定义:req // @返回值:error // func (c *MapInfoLogic) SaveMapInfo(req *model.MapInfo) error { maps := gconv.Map(req) return c.SvcCtx.MapInfo.Base.Replace(maps) } // DelMapInfo // @函数名:DelMapInfo // @函数功能描述: 删除地图信息 // @对象名:c // @参数定义:id // @返回值:error // func (c *MapInfoLogic) DelMapInfo(id int32) error { if id == 0 { return errors.New("参数id为0") } md := c.SvcCtx.MapInfo _, err := md.Where(md.ID.Eq(id)).Delete() return err }