package logic import ( "errors" "fmt" "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" ) // NewSysStationLogic // @函数名:NewSysStationLogic // @函数功能描述:初始化变电站 // @返回值:SysStation // func NewSysStationLogic() SysStation { return SysStation{ SvcCtx: svc.SvcCtx, } } type SysStation struct { SvcCtx *svc.ServiceContext } // SaveSysStation // @函数名:SaveSysStation // @函数功能描述: 保存变电站信息 // @对象名:c // @参数定义:req // @返回值:error // func (c *SysStation) SaveSysStation(req *model.SysStation) error { maps := gconv.Map(req) return c.SvcCtx.SysStation.Base.Replace(maps) } // SaveSysStationMap // @函数名:SaveSysStationMap // @函数功能描述: 通过map 保存变电站信息 // @对象名:c // @参数定义:maps // @返回值:error // func (c *SysStation) SaveSysStationMap(maps map[string]interface{}) error { if maps == nil || len(maps) == 0 { return errors.New("参数为空") } return c.SvcCtx.SysStation.Base.Replace(maps) } // DelSysStation // @函数名:DelSysStation // @函数功能描述: 删除变电站信息 // @对象名:c // @参数定义:id // @返回值:error // func (c *SysStation) DelSysStation(id int32) error { md := c.SvcCtx.SysStation _, err := md.Where(md.ID.Eq(id)).Delete() return err } // GetSysStation // @函数名:GetSysStation // @函数功能描述: 获取变电站信息 // @对象名:c // @参数定义:req // @返回值:*dto.GetSysStationResponse // @返回值:error // func (c *SysStation) GetSysStation(req *dto.GetSysStationRequest) (*dto.GetSysStationResponse, error) { var ( resp = new(dto.GetSysStationResponse) ) cond := new(dao.Condition) where := map[string]any{} if req.Stationid != 0 { where[c.SvcCtx.SysStation.Stationid.String()] = req.Stationid } if req.Name != "" { UserNameLikeStr := fmt.Sprintf("%s like ?", c.SvcCtx.SysStation.Name.String()) where[UserNameLikeStr] = "%" + req.Name + "%" } cond.Where = where var num int64 c.SvcCtx.SysStation.Base.Count(cond, &num) if req.Page < 1 { req.Page = 1 } if req.Limit < 1 { req.Limit = 20 } cond.Limit = req.Limit cond.Offset = (req.Page - 1) * req.Limit cond.OrderBy = "id desc" err := c.SvcCtx.SysStation.Base.Find(cond, &resp.List) if err != nil { return resp, err } resp.Total = num return resp, nil }