| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384 |
- package service
- import (
- "context"
- "dashoo.cn/micro/app/dao"
- "dashoo.cn/micro/app/model"
- "github.com/gogf/gf/errors/gerror"
- "github.com/gogf/gf/frame/g"
- "github.com/gogf/gf/util/gconv"
- )
- type groupService struct {
- *contextService
- Dao *dao.SysGroupDao
- }
- func NewGroupService(ctx context.Context) (svc *groupService, err error) {
- svc = new(groupService)
- if svc.contextService, err = svc.Init(ctx); err != nil {
- return nil, err
- }
- svc.Dao = dao.NewSysGroupDao(svc.Tenant)
- svc.Table = svc.Dao.Table
- return svc, nil
- }
- func (s *groupService) GetList(req *model.SysGroupSearchParams) (total int, list []*model.SysGroup, err error) {
- db := s.Dao.M
- if req != nil {
- if req.GroupCode != "" {
- db = db.WhereLike(s.Dao.Columns.GroupCode, req.GroupCode)
- }
- if req.GroupName != "" {
- db = db.WhereLike(s.Dao.Columns.GroupName, req.GroupName)
- }
- if req.Status != "" {
- db = db.Where(s.Dao.Columns.Status, req.Status)
- }
- }
- total, err = db.Count()
- if err != nil {
- g.Log().Error(err)
- err = gerror.New("获取总行数失败")
- }
- err = db.Page(req.GetPage()).Order("sort asc,id asc").Scan(&list)
- if err != nil {
- g.Log().Error(err)
- err = gerror.New("获取数据失败")
- }
- return
- }
- func (s *groupService) GetEntity(id int64) (group *model.SysGroup, err error) {
- err = s.Dao.WherePri(id).Scan(&group)
- return
- }
- func (s *groupService) Create(params *model.SysGroupReq) error {
- data := new(model.SysGroup)
- if err := gconv.Struct(params, data); err != nil {
- return err
- }
- SetCreatedInfo(data, s.GetCxtUserId(), s.GetCxtUserName())
- _, err := s.Dao.Insert(data)
- return err
- }
- func (s *groupService) UpdateById(params *model.UpdateSysGroupReq) (err error) {
- data := new(model.SysGroup)
- if err := gconv.Struct(params, data); err != nil {
- return err
- }
- SetUpdatedInfo(data, s.GetCxtUserId(), s.GetCxtUserName())
- _, err = s.Dao.FieldsEx(UpdateFieldEx...).WherePri(params.Id).Update(data)
- return err
- }
- func (s *groupService) DeleteByIds(ids []int64) error {
- _, err := s.Dao.WhereIn(s.Dao.Columns.Id, ids).Delete()
- return err
- }
|