plat_user_config.go 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. package plat
  2. import (
  3. "context"
  4. "dashoo.cn/micro/app/dao/plat"
  5. model "dashoo.cn/micro/app/model/plat"
  6. "dashoo.cn/micro/app/service"
  7. )
  8. type UserConfigService struct {
  9. *service.ContextService
  10. Dao *plat.PlatUserConfigDao
  11. }
  12. func NewUserConfigService(ctx context.Context) (svc *UserConfigService, err error) {
  13. svc = new(UserConfigService)
  14. if svc.ContextService, err = svc.Init(ctx); err != nil {
  15. return nil, err
  16. }
  17. svc.Dao = plat.NewPlatUserConfigDao(svc.Tenant)
  18. return svc, nil
  19. }
  20. // QueryByUserIdAndModelCode 根据用户ID和模块编码查询
  21. func (s *UserConfigService) QueryByUserIdAndModelCode(userId int, moduleCode string) (config *model.PlatUserConfig, err error) {
  22. return s.Dao.Where("user_id = ? and module_code = ?", s.GetCxtUserId(), moduleCode).One()
  23. }
  24. // Create 添加用户配置信息
  25. func (s *UserConfigService) Create(param *model.PlatUserConfig) (lastInsertId int64, err error) {
  26. return s.Dao.InsertAndGetId(param)
  27. }
  28. // Edit 修改配置信息
  29. func (s *UserConfigService) Edit(param *model.PlatUserConfig) (err error) {
  30. _, err = s.Dao.Fields(s.Dao.C.ConfigInfo).WherePri(param.Id).Data(param).Update()
  31. return err
  32. }
  33. // Delete 删除配置信息
  34. func (s *UserConfigService) Delete(param *model.PlatUserConfig) (err error) {
  35. _, err = s.Dao.WherePri(param.Id).Delete()
  36. return err
  37. }