feat: client 增删改查

This commit is contained in:
Blizzard
2025-05-08 23:03:00 +08:00
parent 75e9157e5e
commit ab51ba91bc
41 changed files with 1093 additions and 57 deletions
+9
View File
@@ -0,0 +1,9 @@
package service
import "sundynix-go/service/system"
var ServiceGroupApp = new(ServiceGroup)
type ServiceGroup struct {
SystemServiceGroup system.ServiceGroup
}
+6
View File
@@ -0,0 +1,6 @@
package system
type ServiceGroup struct {
UserService
ClientService
}
+53
View File
@@ -0,0 +1,53 @@
package system
import (
"errors"
"gorm.io/gorm"
"sundynix-go/global"
common "sundynix-go/model/commom/request"
"sundynix-go/model/system"
systemReq "sundynix-go/model/system/request"
)
type ClientService struct{}
var ClientServiceApp = new(ClientService)
func (s *ClientService) SaveClient(client system.Client) error {
if !errors.Is(global.DB.Where("client_id = ?", client.ClientId).First(&system.Client{}).Error, gorm.ErrRecordNotFound) {
return errors.New("存在重复clientId,请修改clientId")
}
return global.DB.Create(&client).Error
}
func (s *ClientService) UpdateClient(client system.Client) error {
return global.DB.Model(&client).Where("id = ?", client.Id).Updates(&client).Error
}
func (s *ClientService) GetClientList(info systemReq.GetClientList) (list interface{}, total int64, err error) {
limit := info.PageSize
offset := info.PageSize * (info.Current - 1)
db := global.DB.Model(&system.Client{})
var clientList []system.Client
if info.ClientId != "" {
db = db.Where("client_id = ?", info.ClientId)
}
if info.Name != "" {
db = db.Where("name LIKE ?", "%"+info.Name+"%")
}
err = db.Count(&total).Error
if err != nil {
return
}
err = db.Limit(limit).Offset(offset).Find(&clientList).Error
return clientList, total, err
}
func (s *ClientService) DeleteClientByIds(ids common.IdsReq) (err error) {
return global.DB.Delete(&system.Client{}, "id IN ?", ids.Ids).Error
}
func (s *ClientService) GetClientById(id int) (client system.Client, err error) {
err = global.DB.Where("id = ?", id).First(&client).Error
return client, err
}
+44
View File
@@ -0,0 +1,44 @@
package system
import (
"errors"
"sundynix-go/global"
"sundynix-go/model/system"
systemReq "sundynix-go/model/system/request"
"sundynix-go/utils"
)
type UserService struct{}
var UserServiceApp = new(UserService)
func (userService *UserService) Login(u *system.User) (userInfo *system.User, err error) {
var user system.User
err = global.DB.Where("account = ?", u.Account).First(&user).Error
if err == nil {
if ok := utils.BcryptCheck(u.Password, user.Password); !ok {
return nil, errors.New("密码错误")
}
}
return &user, err
}
func (userService *UserService) GetUserList(info systemReq.GetUserList) (list interface{}, total int64, err error) {
limit := info.PageSize
offset := info.PageSize * (info.Current - 1)
db := global.DB.Model(&system.User{})
var userList []system.User
if info.Account != "" {
db = db.Where("account LIKE ?", "%"+info.Account+"%")
}
if info.Phone != "" {
db = db.Where("phone LIKE ?", "%"+info.Phone+"%")
}
err = db.Count(&total).Error
if err != nil {
return
}
err = db.Limit(limit).Offset(offset).Find(&userList).Error
return userList, total, err
}