任务三
This commit is contained in:
+19
-22
@@ -41,7 +41,7 @@ func (r *apiRepo) Update(ctx context.Context, api *system.Api) error {
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if safeString(old.Path) != api.Path || safeString(old.Method) != api.Method {
|
||||
if old.Path != api.Path || old.Method != api.Method {
|
||||
dup, ferr := query.SysAPI.WithContext(ctx).Where(
|
||||
query.SysAPI.Path.Eq(api.Path),
|
||||
query.SysAPI.Method.Eq(api.Method),
|
||||
@@ -201,18 +201,15 @@ func (r *apiRepo) GetApiGroups(ctx context.Context) ([]string, map[string]string
|
||||
var groups []string
|
||||
|
||||
for _, m := range list {
|
||||
path := safeString(m.Path)
|
||||
apiGroup := safeString(m.APIGroup)
|
||||
|
||||
if !groupMap[apiGroup] {
|
||||
groupMap[apiGroup] = true
|
||||
groups = append(groups, apiGroup)
|
||||
if !groupMap[m.APIGroup] {
|
||||
groupMap[m.APIGroup] = true
|
||||
groups = append(groups, m.APIGroup)
|
||||
}
|
||||
|
||||
if len(path) > 1 {
|
||||
parts := strings.Split(path, "/")
|
||||
if len(m.Path) > 1 {
|
||||
parts := strings.Split(m.Path, "/")
|
||||
if len(parts) > 1 {
|
||||
apiGroupMap[parts[1]] = apiGroup
|
||||
apiGroupMap[parts[1]] = m.APIGroup
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -221,8 +218,8 @@ func (r *apiRepo) GetApiGroups(ctx context.Context) ([]string, map[string]string
|
||||
|
||||
func (r *apiRepo) CreateIgnoreApi(ctx context.Context, path, method string) error {
|
||||
m := &model.SysIgnoreAPI{
|
||||
Path: &path,
|
||||
Method: &method,
|
||||
Path: path,
|
||||
Method: method,
|
||||
}
|
||||
return r.db.WithContext(ctx).Create(m).Error
|
||||
}
|
||||
@@ -239,8 +236,8 @@ func (r *apiRepo) FindAllIgnoreApis(ctx context.Context) ([]*system.IgnoreApi, e
|
||||
result := make([]*system.IgnoreApi, len(list))
|
||||
for i, m := range list {
|
||||
result[i] = &system.IgnoreApi{
|
||||
Path: safeString(m.Path),
|
||||
Method: safeString(m.Method),
|
||||
Path: m.Path,
|
||||
Method: m.Method,
|
||||
}
|
||||
}
|
||||
return result, nil
|
||||
@@ -250,19 +247,19 @@ func (r *apiRepo) FindAllIgnoreApis(ctx context.Context) ([]*system.IgnoreApi, e
|
||||
func toModelAPI(a *system.Api) *model.SysAPI {
|
||||
return &model.SysAPI{
|
||||
ID: int64(a.ID),
|
||||
Path: &a.Path,
|
||||
Description: &a.Description,
|
||||
APIGroup: &a.ApiGroup,
|
||||
Method: &a.Method,
|
||||
Path: a.Path,
|
||||
Description: a.Description,
|
||||
APIGroup: a.ApiGroup,
|
||||
Method: a.Method,
|
||||
}
|
||||
}
|
||||
|
||||
func toBizAPI(m *model.SysAPI) *system.Api {
|
||||
return &system.Api{
|
||||
ID: uint(m.ID),
|
||||
Path: safeString(m.Path),
|
||||
Description: safeString(m.Description),
|
||||
ApiGroup: safeString(m.APIGroup),
|
||||
Method: safeString(m.Method),
|
||||
Path: m.Path,
|
||||
Description: m.Description,
|
||||
ApiGroup: m.APIGroup,
|
||||
Method: m.Method,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -23,12 +23,11 @@ func NewAuthorityRepo(db *gorm.DB) system.AuthorityRepo {
|
||||
func (r *authorityRepo) Create(ctx context.Context, auth *system.Authority) error {
|
||||
m := &model.SysAuthority{
|
||||
AuthorityID: int64(auth.AuthorityId),
|
||||
AuthorityName: &auth.AuthorityName,
|
||||
DefaultRouter: &auth.DefaultRouter,
|
||||
AuthorityName: auth.AuthorityName,
|
||||
DefaultRouter: auth.DefaultRouter,
|
||||
}
|
||||
if auth.ParentId != nil {
|
||||
parentId := int64(*auth.ParentId)
|
||||
m.ParentID = &parentId
|
||||
m.ParentID = int64(*auth.ParentId)
|
||||
}
|
||||
return r.db.WithContext(ctx).Create(m).Error
|
||||
}
|
||||
@@ -141,10 +140,7 @@ func (r *authorityRepo) GetParentAuthorityID(ctx context.Context, authorityId ui
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
if m.ParentID == nil {
|
||||
return 0, nil
|
||||
}
|
||||
return uint(*m.ParentID), nil
|
||||
return uint(m.ParentID), nil
|
||||
}
|
||||
|
||||
func (r *authorityRepo) SetDataAuthority(ctx context.Context, authorityId uint, dataAuthorityIds []uint) error {
|
||||
@@ -216,9 +212,8 @@ func (r *authorityRepo) CopyAuthorityBtns(ctx context.Context, oldAuthorityId, n
|
||||
return nil
|
||||
}
|
||||
|
||||
newAuthorityIdInt64 := int64(newAuthorityId)
|
||||
for i := range btns {
|
||||
btns[i].AuthorityID = &newAuthorityIdInt64
|
||||
btns[i].AuthorityID = int64(newAuthorityId)
|
||||
}
|
||||
|
||||
return r.db.WithContext(ctx).Create(&btns).Error
|
||||
@@ -258,11 +253,11 @@ func (r *authorityRepo) DeleteAuthorityRelations(ctx context.Context, authorityI
|
||||
func toBizAuthority(m *model.SysAuthority) *system.Authority {
|
||||
auth := &system.Authority{
|
||||
AuthorityId: uint(m.AuthorityID),
|
||||
AuthorityName: safeString(m.AuthorityName),
|
||||
DefaultRouter: safeString(m.DefaultRouter),
|
||||
AuthorityName: m.AuthorityName,
|
||||
DefaultRouter: m.DefaultRouter,
|
||||
}
|
||||
if m.ParentID != nil {
|
||||
parentId := uint(*m.ParentID)
|
||||
if m.ParentID != 0 {
|
||||
parentId := uint(m.ParentID)
|
||||
auth.ParentId = &parentId
|
||||
}
|
||||
return auth
|
||||
|
||||
@@ -0,0 +1,472 @@
|
||||
package system
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"strconv"
|
||||
|
||||
"kra/internal/biz/system"
|
||||
"kra/internal/data/model"
|
||||
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
|
||||
type dictionaryRepo struct {
|
||||
db *gorm.DB
|
||||
}
|
||||
|
||||
// NewDictionaryRepo 创建字典仓储
|
||||
func NewDictionaryRepo(db *gorm.DB) system.DictionaryRepo {
|
||||
return &dictionaryRepo{db: db}
|
||||
}
|
||||
|
||||
func (r *dictionaryRepo) Create(ctx context.Context, dict *system.Dictionary) error {
|
||||
m := toModelDictionary(dict)
|
||||
if err := r.db.WithContext(ctx).Create(m).Error; err != nil {
|
||||
return err
|
||||
}
|
||||
dict.ID = uint(m.ID)
|
||||
return nil
|
||||
}
|
||||
|
||||
func (r *dictionaryRepo) Update(ctx context.Context, dict *system.Dictionary) error {
|
||||
updates := map[string]interface{}{
|
||||
"name": dict.Name,
|
||||
"type": dict.Type,
|
||||
"status": dict.Status,
|
||||
"desc": dict.Desc,
|
||||
"parent_id": dict.ParentID,
|
||||
}
|
||||
return r.db.WithContext(ctx).Model(&model.SysDictionary{}).Where("id = ?", dict.ID).Updates(updates).Error
|
||||
}
|
||||
|
||||
func (r *dictionaryRepo) Delete(ctx context.Context, id uint) error {
|
||||
return r.db.WithContext(ctx).Delete(&model.SysDictionary{}, id).Error
|
||||
}
|
||||
|
||||
func (r *dictionaryRepo) FindByID(ctx context.Context, id uint) (*system.Dictionary, error) {
|
||||
var m model.SysDictionary
|
||||
if err := r.db.WithContext(ctx).First(&m, id).Error; err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return toBizDictionary(&m), nil
|
||||
}
|
||||
|
||||
func (r *dictionaryRepo) FindByType(ctx context.Context, typ string) (*system.Dictionary, error) {
|
||||
var m model.SysDictionary
|
||||
if err := r.db.WithContext(ctx).Where("type = ?", typ).First(&m).Error; err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return toBizDictionary(&m), nil
|
||||
}
|
||||
|
||||
func (r *dictionaryRepo) GetByTypeOrID(ctx context.Context, typ string, id uint, status *bool) (*system.Dictionary, error) {
|
||||
flag := true
|
||||
if status != nil {
|
||||
flag = *status
|
||||
}
|
||||
var m model.SysDictionary
|
||||
db := r.db.WithContext(ctx).Where("(type = ? OR id = ?) AND status = ?", typ, id, flag)
|
||||
if err := db.First(&m).Error; err != nil {
|
||||
return nil, err
|
||||
}
|
||||
dict := toBizDictionary(&m)
|
||||
// 加载详情
|
||||
var details []model.SysDictionaryDetail
|
||||
r.db.WithContext(ctx).Where("sys_dictionary_id = ? AND status = ?", m.ID, true).Order("sort").Find(&details)
|
||||
// 详情在service层处理
|
||||
return dict, nil
|
||||
}
|
||||
|
||||
func (r *dictionaryRepo) List(ctx context.Context, name string) ([]*system.Dictionary, error) {
|
||||
db := r.db.WithContext(ctx).Model(&model.SysDictionary{})
|
||||
if name != "" {
|
||||
db = db.Where("name LIKE ? OR type LIKE ?", "%"+name+"%", "%"+name+"%")
|
||||
}
|
||||
// 预加载子字典
|
||||
db = db.Preload("Children")
|
||||
var list []model.SysDictionary
|
||||
if err := db.Find(&list).Error; err != nil {
|
||||
return nil, err
|
||||
}
|
||||
result := make([]*system.Dictionary, len(list))
|
||||
for i, m := range list {
|
||||
result[i] = toBizDictionary(&m)
|
||||
}
|
||||
return result, nil
|
||||
}
|
||||
|
||||
func (r *dictionaryRepo) CheckCircularReference(ctx context.Context, currentID, parentID uint) error {
|
||||
if currentID == parentID {
|
||||
return errors.New("不能将字典设置为自己的父级")
|
||||
}
|
||||
var parent model.SysDictionary
|
||||
if err := r.db.WithContext(ctx).Where("id = ?", parentID).First(&parent).Error; err != nil {
|
||||
if errors.Is(err, gorm.ErrRecordNotFound) {
|
||||
return nil
|
||||
}
|
||||
return err
|
||||
}
|
||||
if parent.ParentID != 0 {
|
||||
return r.CheckCircularReference(ctx, currentID, uint(parent.ParentID))
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
type dictionaryDetailRepo struct {
|
||||
db *gorm.DB
|
||||
}
|
||||
|
||||
// NewDictionaryDetailRepo 创建字典详情仓储
|
||||
func NewDictionaryDetailRepo(db *gorm.DB) system.DictionaryDetailRepo {
|
||||
return &dictionaryDetailRepo{db: db}
|
||||
}
|
||||
|
||||
func (r *dictionaryDetailRepo) Create(ctx context.Context, detail *system.DictionaryDetail) error {
|
||||
m := toModelDictionaryDetail(detail)
|
||||
if err := r.db.WithContext(ctx).Create(m).Error; err != nil {
|
||||
return err
|
||||
}
|
||||
detail.ID = uint(m.ID)
|
||||
return nil
|
||||
}
|
||||
|
||||
func (r *dictionaryDetailRepo) Update(ctx context.Context, detail *system.DictionaryDetail) error {
|
||||
m := toModelDictionaryDetail(detail)
|
||||
return r.db.WithContext(ctx).Save(m).Error
|
||||
}
|
||||
|
||||
func (r *dictionaryDetailRepo) Delete(ctx context.Context, id uint) error {
|
||||
return r.db.WithContext(ctx).Delete(&model.SysDictionaryDetail{}, id).Error
|
||||
}
|
||||
|
||||
func (r *dictionaryDetailRepo) FindByID(ctx context.Context, id uint) (*system.DictionaryDetail, error) {
|
||||
var m model.SysDictionaryDetail
|
||||
if err := r.db.WithContext(ctx).First(&m, id).Error; err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return toBizDictionaryDetail(&m), nil
|
||||
}
|
||||
|
||||
func (r *dictionaryDetailRepo) List(ctx context.Context, page, pageSize int, filters map[string]interface{}) ([]*system.DictionaryDetail, int64, error) {
|
||||
db := r.db.WithContext(ctx).Model(&model.SysDictionaryDetail{})
|
||||
if v, ok := filters["label"]; ok && v != "" {
|
||||
db = db.Where("label LIKE ?", "%"+v.(string)+"%")
|
||||
}
|
||||
if v, ok := filters["value"]; ok && v != "" {
|
||||
db = db.Where("value = ?", v)
|
||||
}
|
||||
if v, ok := filters["status"]; ok {
|
||||
db = db.Where("status = ?", v)
|
||||
}
|
||||
if v, ok := filters["sys_dictionary_id"]; ok && v.(uint) != 0 {
|
||||
db = db.Where("sys_dictionary_id = ?", v)
|
||||
}
|
||||
if v, ok := filters["parent_id"]; ok {
|
||||
db = db.Where("parent_id = ?", v)
|
||||
}
|
||||
if v, ok := filters["level"]; ok {
|
||||
db = db.Where("level = ?", v)
|
||||
}
|
||||
|
||||
var total int64
|
||||
if err := db.Count(&total).Error; err != nil {
|
||||
return nil, 0, err
|
||||
}
|
||||
|
||||
offset := (page - 1) * pageSize
|
||||
var list []model.SysDictionaryDetail
|
||||
if err := db.Offset(offset).Limit(pageSize).Order("sort").Order("id").Find(&list).Error; err != nil {
|
||||
return nil, 0, err
|
||||
}
|
||||
|
||||
result := make([]*system.DictionaryDetail, len(list))
|
||||
for i, m := range list {
|
||||
result[i] = toBizDictionaryDetail(&m)
|
||||
}
|
||||
return result, total, nil
|
||||
}
|
||||
|
||||
func (r *dictionaryDetailRepo) GetListByDictionaryID(ctx context.Context, dictionaryID uint) ([]*system.DictionaryDetail, error) {
|
||||
var list []model.SysDictionaryDetail
|
||||
if err := r.db.WithContext(ctx).Where("sys_dictionary_id = ?", dictionaryID).Find(&list).Error; err != nil {
|
||||
return nil, err
|
||||
}
|
||||
result := make([]*system.DictionaryDetail, len(list))
|
||||
for i, m := range list {
|
||||
result[i] = toBizDictionaryDetail(&m)
|
||||
}
|
||||
return result, nil
|
||||
}
|
||||
|
||||
func (r *dictionaryDetailRepo) GetTreeList(ctx context.Context, dictionaryID uint) ([]*system.DictionaryDetail, error) {
|
||||
var list []model.SysDictionaryDetail
|
||||
if err := r.db.WithContext(ctx).Where("sys_dictionary_id = ? AND parent_id IS NULL", dictionaryID).Order("sort").Find(&list).Error; err != nil {
|
||||
return nil, err
|
||||
}
|
||||
result := make([]*system.DictionaryDetail, len(list))
|
||||
for i, m := range list {
|
||||
result[i] = toBizDictionaryDetail(&m)
|
||||
r.setDisabled(result[i])
|
||||
if err := r.loadChildren(ctx, result[i]); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
return result, nil
|
||||
}
|
||||
|
||||
func (r *dictionaryDetailRepo) loadChildren(ctx context.Context, detail *system.DictionaryDetail) error {
|
||||
var children []model.SysDictionaryDetail
|
||||
if err := r.db.WithContext(ctx).Where("parent_id = ?", detail.ID).Order("sort").Find(&children).Error; err != nil {
|
||||
return err
|
||||
}
|
||||
for _, m := range children {
|
||||
child := toBizDictionaryDetail(&m)
|
||||
r.setDisabled(child)
|
||||
if err := r.loadChildren(ctx, child); err != nil {
|
||||
return err
|
||||
}
|
||||
detail.Children = append(detail.Children, child)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (r *dictionaryDetailRepo) setDisabled(detail *system.DictionaryDetail) {
|
||||
if detail.Status != nil {
|
||||
detail.Disabled = !*detail.Status
|
||||
} else {
|
||||
detail.Disabled = false
|
||||
}
|
||||
}
|
||||
|
||||
func (r *dictionaryDetailRepo) GetByParent(ctx context.Context, dictionaryID uint, parentID *uint, includeChildren bool) ([]*system.DictionaryDetail, error) {
|
||||
db := r.db.WithContext(ctx).Model(&model.SysDictionaryDetail{}).Where("sys_dictionary_id = ?", dictionaryID)
|
||||
if parentID != nil {
|
||||
db = db.Where("parent_id = ?", *parentID)
|
||||
} else {
|
||||
db = db.Where("parent_id IS NULL")
|
||||
}
|
||||
var list []model.SysDictionaryDetail
|
||||
if err := db.Order("sort").Find(&list).Error; err != nil {
|
||||
return nil, err
|
||||
}
|
||||
result := make([]*system.DictionaryDetail, len(list))
|
||||
for i, m := range list {
|
||||
result[i] = toBizDictionaryDetail(&m)
|
||||
r.setDisabled(result[i])
|
||||
if includeChildren {
|
||||
if err := r.loadChildren(ctx, result[i]); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
}
|
||||
return result, nil
|
||||
}
|
||||
|
||||
func (r *dictionaryDetailRepo) GetByDictionaryIDAndValue(ctx context.Context, dictionaryID uint, value string) (*system.DictionaryDetail, error) {
|
||||
var m model.SysDictionaryDetail
|
||||
if err := r.db.WithContext(ctx).Where("sys_dictionary_id = ? AND value = ?", dictionaryID, value).First(&m).Error; err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return toBizDictionaryDetail(&m), nil
|
||||
}
|
||||
|
||||
func (r *dictionaryDetailRepo) GetByTypeAndValue(ctx context.Context, typ, value string) (*system.DictionaryDetail, error) {
|
||||
var m model.SysDictionaryDetail
|
||||
if err := r.db.WithContext(ctx).Model(&model.SysDictionaryDetail{}).
|
||||
Joins("JOIN sys_dictionaries ON sys_dictionaries.id = sys_dictionary_details.sys_dictionary_id").
|
||||
Where("sys_dictionaries.type = ? AND sys_dictionary_details.value = ?", typ, value).
|
||||
First(&m).Error; err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return toBizDictionaryDetail(&m), nil
|
||||
}
|
||||
|
||||
func (r *dictionaryDetailRepo) GetTreeListByType(ctx context.Context, typ string) ([]*system.DictionaryDetail, error) {
|
||||
var list []model.SysDictionaryDetail
|
||||
if err := r.db.WithContext(ctx).Model(&model.SysDictionaryDetail{}).
|
||||
Joins("JOIN sys_dictionaries ON sys_dictionaries.id = sys_dictionary_details.sys_dictionary_id").
|
||||
Where("sys_dictionaries.type = ? AND sys_dictionary_details.parent_id IS NULL", typ).
|
||||
Order("sys_dictionary_details.sort").
|
||||
Find(&list).Error; err != nil {
|
||||
return nil, err
|
||||
}
|
||||
result := make([]*system.DictionaryDetail, len(list))
|
||||
for i, m := range list {
|
||||
result[i] = toBizDictionaryDetail(&m)
|
||||
r.setDisabled(result[i])
|
||||
if err := r.loadChildren(ctx, result[i]); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
return result, nil
|
||||
}
|
||||
|
||||
func (r *dictionaryDetailRepo) GetListByType(ctx context.Context, typ string) ([]*system.DictionaryDetail, error) {
|
||||
var list []model.SysDictionaryDetail
|
||||
if err := r.db.WithContext(ctx).Model(&model.SysDictionaryDetail{}).
|
||||
Joins("JOIN sys_dictionaries ON sys_dictionaries.id = sys_dictionary_details.sys_dictionary_id").
|
||||
Where("sys_dictionaries.type = ?", typ).
|
||||
Find(&list).Error; err != nil {
|
||||
return nil, err
|
||||
}
|
||||
result := make([]*system.DictionaryDetail, len(list))
|
||||
for i, m := range list {
|
||||
result[i] = toBizDictionaryDetail(&m)
|
||||
}
|
||||
return result, nil
|
||||
}
|
||||
|
||||
func (r *dictionaryDetailRepo) HasChildren(ctx context.Context, id uint) (bool, error) {
|
||||
var count int64
|
||||
if err := r.db.WithContext(ctx).Model(&model.SysDictionaryDetail{}).Where("parent_id = ?", id).Count(&count).Error; err != nil {
|
||||
return false, err
|
||||
}
|
||||
return count > 0, nil
|
||||
}
|
||||
|
||||
func (r *dictionaryDetailRepo) CheckCircularReference(ctx context.Context, id, parentID uint) bool {
|
||||
if id == parentID {
|
||||
return true
|
||||
}
|
||||
var parent model.SysDictionaryDetail
|
||||
if err := r.db.WithContext(ctx).First(&parent, parentID).Error; err != nil {
|
||||
return false
|
||||
}
|
||||
if parent.ParentID == 0 {
|
||||
return false
|
||||
}
|
||||
return r.CheckCircularReference(ctx, id, uint(parent.ParentID))
|
||||
}
|
||||
|
||||
func (r *dictionaryDetailRepo) UpdateChildrenLevelAndPath(ctx context.Context, parentID uint) error {
|
||||
var children []model.SysDictionaryDetail
|
||||
if err := r.db.WithContext(ctx).Where("parent_id = ?", parentID).Find(&children).Error; err != nil {
|
||||
return err
|
||||
}
|
||||
var parent model.SysDictionaryDetail
|
||||
if err := r.db.WithContext(ctx).First(&parent, parentID).Error; err != nil {
|
||||
return err
|
||||
}
|
||||
for _, child := range children {
|
||||
child.Level = parent.Level + 1
|
||||
if parent.Path == "" {
|
||||
child.Path = strconv.Itoa(int(parent.ID))
|
||||
} else {
|
||||
child.Path = parent.Path + "," + strconv.Itoa(int(parent.ID))
|
||||
}
|
||||
if err := r.db.WithContext(ctx).Save(&child).Error; err != nil {
|
||||
return err
|
||||
}
|
||||
if err := r.UpdateChildrenLevelAndPath(ctx, uint(child.ID)); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (r *dictionaryDetailRepo) GetPath(ctx context.Context, id uint) ([]*system.DictionaryDetail, error) {
|
||||
var m model.SysDictionaryDetail
|
||||
if err := r.db.WithContext(ctx).First(&m, id).Error; err != nil {
|
||||
return nil, err
|
||||
}
|
||||
detail := toBizDictionaryDetail(&m)
|
||||
path := []*system.DictionaryDetail{detail}
|
||||
if m.ParentID != 0 {
|
||||
parentPath, err := r.GetPath(ctx, uint(m.ParentID))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
path = append(parentPath, path...)
|
||||
}
|
||||
return path, nil
|
||||
}
|
||||
|
||||
func (r *dictionaryDetailRepo) DeleteByDictionaryID(ctx context.Context, dictionaryID uint) error {
|
||||
return r.db.WithContext(ctx).Where("sys_dictionary_id = ?", dictionaryID).Delete(&model.SysDictionaryDetail{}).Error
|
||||
}
|
||||
|
||||
func (r *dictionaryDetailRepo) BatchCreate(ctx context.Context, details []*system.DictionaryDetail) error {
|
||||
models := make([]*model.SysDictionaryDetail, len(details))
|
||||
for i, d := range details {
|
||||
models[i] = toModelDictionaryDetail(d)
|
||||
}
|
||||
return r.db.WithContext(ctx).Create(&models).Error
|
||||
}
|
||||
|
||||
func (r *dictionaryDetailRepo) BatchUpdateParentID(ctx context.Context, idMap map[uint]uint) error {
|
||||
// idMap: oldID -> newID
|
||||
// 这里需要根据实际导入逻辑处理
|
||||
return nil
|
||||
}
|
||||
|
||||
// 转换函数
|
||||
func toModelDictionary(d *system.Dictionary) *model.SysDictionary {
|
||||
m := &model.SysDictionary{
|
||||
ID: int64(d.ID),
|
||||
Name: d.Name,
|
||||
Type: d.Type,
|
||||
Desc: d.Desc,
|
||||
}
|
||||
if d.Status != nil {
|
||||
m.Status = *d.Status
|
||||
}
|
||||
if d.ParentID != nil {
|
||||
m.ParentID = int64(*d.ParentID)
|
||||
}
|
||||
return m
|
||||
}
|
||||
|
||||
func toBizDictionary(m *model.SysDictionary) *system.Dictionary {
|
||||
d := &system.Dictionary{
|
||||
ID: uint(m.ID),
|
||||
Name: m.Name,
|
||||
Type: m.Type,
|
||||
Status: &m.Status,
|
||||
Desc: m.Desc,
|
||||
}
|
||||
if m.ParentID != 0 {
|
||||
pid := uint(m.ParentID)
|
||||
d.ParentID = &pid
|
||||
}
|
||||
return d
|
||||
}
|
||||
|
||||
func toModelDictionaryDetail(d *system.DictionaryDetail) *model.SysDictionaryDetail {
|
||||
m := &model.SysDictionaryDetail{
|
||||
ID: int64(d.ID),
|
||||
Label: d.Label,
|
||||
Value: d.Value,
|
||||
Extend: d.Extend,
|
||||
Sort: int64(d.Sort),
|
||||
SysDictionaryID: int64(d.SysDictionaryID),
|
||||
Level: int64(d.Level),
|
||||
Path: d.Path,
|
||||
}
|
||||
if d.Status != nil {
|
||||
m.Status = *d.Status
|
||||
}
|
||||
if d.ParentID != nil {
|
||||
m.ParentID = int64(*d.ParentID)
|
||||
}
|
||||
return m
|
||||
}
|
||||
|
||||
func toBizDictionaryDetail(m *model.SysDictionaryDetail) *system.DictionaryDetail {
|
||||
d := &system.DictionaryDetail{
|
||||
ID: uint(m.ID),
|
||||
Label: m.Label,
|
||||
Value: m.Value,
|
||||
Extend: m.Extend,
|
||||
Status: &m.Status,
|
||||
Sort: int(m.Sort),
|
||||
SysDictionaryID: uint(m.SysDictionaryID),
|
||||
Level: int(m.Level),
|
||||
Path: m.Path,
|
||||
}
|
||||
if m.ParentID != 0 {
|
||||
pid := uint(m.ParentID)
|
||||
d.ParentID = &pid
|
||||
}
|
||||
return d
|
||||
}
|
||||
@@ -76,10 +76,10 @@ func (r *menuRepo) CreateBaseMenu(ctx context.Context, menu *system.BaseMenu) er
|
||||
if len(menu.Parameters) > 0 {
|
||||
for _, p := range menu.Parameters {
|
||||
param := &model.SysBaseMenuParameter{
|
||||
SysBaseMenuID: ptrInt64(int64(m.ID)),
|
||||
Type: &p.Type,
|
||||
Key: &p.Key,
|
||||
Value: &p.Value,
|
||||
SysBaseMenuID: int64(m.ID),
|
||||
Type: p.Type,
|
||||
Key: p.Key,
|
||||
Value: p.Value,
|
||||
}
|
||||
if err := tx.Create(param).Error; err != nil {
|
||||
return err
|
||||
@@ -91,9 +91,9 @@ func (r *menuRepo) CreateBaseMenu(ctx context.Context, menu *system.BaseMenu) er
|
||||
if len(menu.MenuBtn) > 0 {
|
||||
for _, b := range menu.MenuBtn {
|
||||
btn := &model.SysBaseMenuBtn{
|
||||
SysBaseMenuID: ptrInt64(int64(m.ID)),
|
||||
Name: &b.Name,
|
||||
Desc: &b.Desc,
|
||||
SysBaseMenuID: int64(m.ID),
|
||||
Name: b.Name,
|
||||
Desc: b.Desc,
|
||||
}
|
||||
if err := tx.Create(btn).Error; err != nil {
|
||||
return err
|
||||
@@ -115,7 +115,7 @@ func (r *menuRepo) UpdateBaseMenu(ctx context.Context, menu *system.BaseMenu) er
|
||||
}
|
||||
|
||||
// 检查name是否重复
|
||||
if safeString(oldMenu.Name) != menu.Name {
|
||||
if oldMenu.Name != menu.Name {
|
||||
var count int64
|
||||
if err := tx.Model(&model.SysBaseMenu{}).Where("id <> ? AND name = ?", menu.ID, menu.Name).Count(&count).Error; err != nil {
|
||||
return err
|
||||
@@ -137,10 +137,10 @@ func (r *menuRepo) UpdateBaseMenu(ctx context.Context, menu *system.BaseMenu) er
|
||||
if len(menu.Parameters) > 0 {
|
||||
for _, p := range menu.Parameters {
|
||||
param := &model.SysBaseMenuParameter{
|
||||
SysBaseMenuID: ptrInt64(int64(menu.ID)),
|
||||
Type: &p.Type,
|
||||
Key: &p.Key,
|
||||
Value: &p.Value,
|
||||
SysBaseMenuID: int64(menu.ID),
|
||||
Type: p.Type,
|
||||
Key: p.Key,
|
||||
Value: p.Value,
|
||||
}
|
||||
if err := tx.Create(param).Error; err != nil {
|
||||
return err
|
||||
@@ -152,9 +152,9 @@ func (r *menuRepo) UpdateBaseMenu(ctx context.Context, menu *system.BaseMenu) er
|
||||
if len(menu.MenuBtn) > 0 {
|
||||
for _, b := range menu.MenuBtn {
|
||||
btn := &model.SysBaseMenuBtn{
|
||||
SysBaseMenuID: ptrInt64(int64(menu.ID)),
|
||||
Name: &b.Name,
|
||||
Desc: &b.Desc,
|
||||
SysBaseMenuID: int64(menu.ID),
|
||||
Name: b.Name,
|
||||
Desc: b.Desc,
|
||||
}
|
||||
if err := tx.Create(btn).Error; err != nil {
|
||||
return err
|
||||
@@ -295,9 +295,7 @@ func (r *menuRepo) FindAllBaseMenus(ctx context.Context) ([]*system.BaseMenu, er
|
||||
r.db.WithContext(ctx).Find(&allParams)
|
||||
paramMap := make(map[int64][]model.SysBaseMenuParameter)
|
||||
for _, p := range allParams {
|
||||
if p.SysBaseMenuID != nil {
|
||||
paramMap[*p.SysBaseMenuID] = append(paramMap[*p.SysBaseMenuID], p)
|
||||
}
|
||||
paramMap[p.SysBaseMenuID] = append(paramMap[p.SysBaseMenuID], p)
|
||||
}
|
||||
|
||||
// 获取所有按钮
|
||||
@@ -305,9 +303,7 @@ func (r *menuRepo) FindAllBaseMenus(ctx context.Context) ([]*system.BaseMenu, er
|
||||
r.db.WithContext(ctx).Find(&allBtns)
|
||||
btnMap := make(map[int64][]model.SysBaseMenuBtn)
|
||||
for _, b := range allBtns {
|
||||
if b.SysBaseMenuID != nil {
|
||||
btnMap[*b.SysBaseMenuID] = append(btnMap[*b.SysBaseMenuID], b)
|
||||
}
|
||||
btnMap[b.SysBaseMenuID] = append(btnMap[b.SysBaseMenuID], b)
|
||||
}
|
||||
|
||||
result := make([]*system.BaseMenu, len(menus))
|
||||
@@ -329,9 +325,7 @@ func (r *menuRepo) FindBaseMenusByIds(ctx context.Context, ids []string) ([]*sys
|
||||
r.db.WithContext(ctx).Where("sys_base_menu_id in (?)", ids).Find(&allParams)
|
||||
paramMap := make(map[int64][]model.SysBaseMenuParameter)
|
||||
for _, p := range allParams {
|
||||
if p.SysBaseMenuID != nil {
|
||||
paramMap[*p.SysBaseMenuID] = append(paramMap[*p.SysBaseMenuID], p)
|
||||
}
|
||||
paramMap[p.SysBaseMenuID] = append(paramMap[p.SysBaseMenuID], p)
|
||||
}
|
||||
|
||||
// 获取按钮
|
||||
@@ -339,9 +333,7 @@ func (r *menuRepo) FindBaseMenusByIds(ctx context.Context, ids []string) ([]*sys
|
||||
r.db.WithContext(ctx).Where("sys_base_menu_id in (?)", ids).Find(&allBtns)
|
||||
btnMap := make(map[int64][]model.SysBaseMenuBtn)
|
||||
for _, b := range allBtns {
|
||||
if b.SysBaseMenuID != nil {
|
||||
btnMap[*b.SysBaseMenuID] = append(btnMap[*b.SysBaseMenuID], b)
|
||||
}
|
||||
btnMap[b.SysBaseMenuID] = append(btnMap[b.SysBaseMenuID], b)
|
||||
}
|
||||
|
||||
result := make([]*system.BaseMenu, len(menus))
|
||||
@@ -374,9 +366,7 @@ func (r *menuRepo) FindAuthorityBtns(ctx context.Context, authorityId uint) ([]*
|
||||
// 获取按钮名称
|
||||
var btnIds []int64
|
||||
for _, b := range btns {
|
||||
if b.SysBaseMenuBtnID != nil {
|
||||
btnIds = append(btnIds, *b.SysBaseMenuBtnID)
|
||||
}
|
||||
btnIds = append(btnIds, b.SysBaseMenuBtnID)
|
||||
}
|
||||
|
||||
btnNameMap := make(map[int64]string)
|
||||
@@ -384,22 +374,17 @@ func (r *menuRepo) FindAuthorityBtns(ctx context.Context, authorityId uint) ([]*
|
||||
var menuBtns []model.SysBaseMenuBtn
|
||||
r.db.WithContext(ctx).Where("id in (?)", btnIds).Find(&menuBtns)
|
||||
for _, mb := range menuBtns {
|
||||
btnNameMap[mb.ID] = safeString(mb.Name)
|
||||
btnNameMap[mb.ID] = mb.Name
|
||||
}
|
||||
}
|
||||
|
||||
result := make([]*system.AuthorityBtn, len(btns))
|
||||
for i, b := range btns {
|
||||
result[i] = &system.AuthorityBtn{}
|
||||
if b.AuthorityID != nil {
|
||||
result[i].AuthorityId = uint(*b.AuthorityID)
|
||||
}
|
||||
if b.SysMenuID != nil {
|
||||
result[i].SysMenuID = uint(*b.SysMenuID)
|
||||
}
|
||||
if b.SysBaseMenuBtnID != nil {
|
||||
result[i].SysBaseMenuBtnID = uint(*b.SysBaseMenuBtnID)
|
||||
result[i].BtnName = btnNameMap[*b.SysBaseMenuBtnID]
|
||||
result[i] = &system.AuthorityBtn{
|
||||
AuthorityId: uint(b.AuthorityID),
|
||||
SysMenuID: uint(b.SysMenuID),
|
||||
SysBaseMenuBtnID: uint(b.SysBaseMenuBtnID),
|
||||
BtnName: btnNameMap[b.SysBaseMenuBtnID],
|
||||
}
|
||||
}
|
||||
return result, nil
|
||||
@@ -429,55 +414,40 @@ func (r *menuRepo) SetMenuAuthority(ctx context.Context, authorityId uint, menuI
|
||||
|
||||
// 转换函数
|
||||
func toModelBaseMenu(m *system.BaseMenu) *model.SysBaseMenu {
|
||||
parentId := int64(m.ParentId)
|
||||
sort := int64(m.Sort)
|
||||
|
||||
return &model.SysBaseMenu{
|
||||
ID: int64(m.ID),
|
||||
ParentID: &parentId,
|
||||
Path: &m.Path,
|
||||
Name: &m.Name,
|
||||
Hidden: &m.Hidden,
|
||||
Component: &m.Component,
|
||||
Sort: &sort,
|
||||
ActiveName: &m.ActiveName,
|
||||
KeepAlive: &m.KeepAlive,
|
||||
DefaultMenu: &m.DefaultMenu,
|
||||
Title: &m.Title,
|
||||
Icon: &m.Icon,
|
||||
CloseTab: &m.CloseTab,
|
||||
TransitionType: &m.TransitionType,
|
||||
ParentID: int64(m.ParentId),
|
||||
Path: m.Path,
|
||||
Name: m.Name,
|
||||
Hidden: m.Hidden,
|
||||
Component: m.Component,
|
||||
Sort: int64(m.Sort),
|
||||
ActiveName: m.ActiveName,
|
||||
KeepAlive: m.KeepAlive,
|
||||
DefaultMenu: m.DefaultMenu,
|
||||
Title: m.Title,
|
||||
Icon: m.Icon,
|
||||
CloseTab: m.CloseTab,
|
||||
TransitionType: m.TransitionType,
|
||||
}
|
||||
}
|
||||
|
||||
func toBizBaseMenu(m *model.SysBaseMenu, params []model.SysBaseMenuParameter, btns []model.SysBaseMenuBtn) *system.BaseMenu {
|
||||
menu := &system.BaseMenu{
|
||||
ID: uint(m.ID),
|
||||
Path: safeString(m.Path),
|
||||
Name: safeString(m.Name),
|
||||
Component: safeString(m.Component),
|
||||
ActiveName: safeString(m.ActiveName),
|
||||
Title: safeString(m.Title),
|
||||
Icon: safeString(m.Icon),
|
||||
TransitionType: safeString(m.TransitionType),
|
||||
}
|
||||
if m.ParentID != nil {
|
||||
menu.ParentId = uint(*m.ParentID)
|
||||
}
|
||||
if m.Sort != nil {
|
||||
menu.Sort = int(*m.Sort)
|
||||
}
|
||||
if m.Hidden != nil {
|
||||
menu.Hidden = *m.Hidden
|
||||
}
|
||||
if m.KeepAlive != nil {
|
||||
menu.KeepAlive = *m.KeepAlive
|
||||
}
|
||||
if m.DefaultMenu != nil {
|
||||
menu.DefaultMenu = *m.DefaultMenu
|
||||
}
|
||||
if m.CloseTab != nil {
|
||||
menu.CloseTab = *m.CloseTab
|
||||
ParentId: uint(m.ParentID),
|
||||
Path: m.Path,
|
||||
Name: m.Name,
|
||||
Hidden: m.Hidden,
|
||||
Component: m.Component,
|
||||
Sort: int(m.Sort),
|
||||
ActiveName: m.ActiveName,
|
||||
KeepAlive: m.KeepAlive,
|
||||
DefaultMenu: m.DefaultMenu,
|
||||
Title: m.Title,
|
||||
Icon: m.Icon,
|
||||
CloseTab: m.CloseTab,
|
||||
TransitionType: m.TransitionType,
|
||||
}
|
||||
|
||||
// 转换参数
|
||||
@@ -485,13 +455,11 @@ func toBizBaseMenu(m *model.SysBaseMenu, params []model.SysBaseMenuParameter, bt
|
||||
menu.Parameters = make([]*system.MenuParameter, len(params))
|
||||
for i, p := range params {
|
||||
menu.Parameters[i] = &system.MenuParameter{
|
||||
ID: uint(p.ID),
|
||||
Type: safeString(p.Type),
|
||||
Key: safeString(p.Key),
|
||||
Value: safeString(p.Value),
|
||||
}
|
||||
if p.SysBaseMenuID != nil {
|
||||
menu.Parameters[i].SysBaseMenuID = uint(*p.SysBaseMenuID)
|
||||
ID: uint(p.ID),
|
||||
SysBaseMenuID: uint(p.SysBaseMenuID),
|
||||
Type: p.Type,
|
||||
Key: p.Key,
|
||||
Value: p.Value,
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -501,12 +469,10 @@ func toBizBaseMenu(m *model.SysBaseMenu, params []model.SysBaseMenuParameter, bt
|
||||
menu.MenuBtn = make([]*system.MenuBtn, len(btns))
|
||||
for i, b := range btns {
|
||||
menu.MenuBtn[i] = &system.MenuBtn{
|
||||
ID: uint(b.ID),
|
||||
Name: safeString(b.Name),
|
||||
Desc: safeString(b.Desc),
|
||||
}
|
||||
if b.SysBaseMenuID != nil {
|
||||
menu.MenuBtn[i].SysBaseMenuID = uint(*b.SysBaseMenuID)
|
||||
ID: uint(b.ID),
|
||||
SysBaseMenuID: uint(b.SysBaseMenuID),
|
||||
Name: b.Name,
|
||||
Desc: b.Desc,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,131 @@
|
||||
package system
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"kra/internal/biz/system"
|
||||
"kra/internal/data/model"
|
||||
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
|
||||
type operationRecordRepo struct {
|
||||
db *gorm.DB
|
||||
}
|
||||
|
||||
// NewOperationRecordRepo 创建操作记录仓储
|
||||
func NewOperationRecordRepo(db *gorm.DB) system.OperationRecordRepo {
|
||||
return &operationRecordRepo{db: db}
|
||||
}
|
||||
|
||||
func (r *operationRecordRepo) Create(ctx context.Context, record *system.OperationRecord) error {
|
||||
m := toModelOperationRecord(record)
|
||||
if err := r.db.WithContext(ctx).Create(m).Error; err != nil {
|
||||
return err
|
||||
}
|
||||
record.ID = uint(m.ID)
|
||||
return nil
|
||||
}
|
||||
|
||||
func (r *operationRecordRepo) Delete(ctx context.Context, id uint) error {
|
||||
return r.db.WithContext(ctx).Delete(&model.SysOperationRecord{}, id).Error
|
||||
}
|
||||
|
||||
func (r *operationRecordRepo) DeleteByIds(ctx context.Context, ids []uint) error {
|
||||
return r.db.WithContext(ctx).Delete(&model.SysOperationRecord{}, "id in (?)", ids).Error
|
||||
}
|
||||
|
||||
func (r *operationRecordRepo) FindByID(ctx context.Context, id uint) (*system.OperationRecord, error) {
|
||||
var m model.SysOperationRecord
|
||||
if err := r.db.WithContext(ctx).Where("id = ?", id).First(&m).Error; err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return toBizOperationRecord(&m, nil), nil
|
||||
}
|
||||
|
||||
func (r *operationRecordRepo) List(ctx context.Context, page, pageSize int, filters map[string]interface{}) ([]*system.OperationRecord, int64, error) {
|
||||
db := r.db.WithContext(ctx).Model(&model.SysOperationRecord{})
|
||||
|
||||
if v, ok := filters["method"]; ok && v != "" {
|
||||
db = db.Where("method = ?", v)
|
||||
}
|
||||
if v, ok := filters["path"]; ok && v != "" {
|
||||
db = db.Where("path LIKE ?", "%"+v.(string)+"%")
|
||||
}
|
||||
if v, ok := filters["status"]; ok && v.(int) != 0 {
|
||||
db = db.Where("status = ?", v)
|
||||
}
|
||||
|
||||
var total int64
|
||||
if err := db.Count(&total).Error; err != nil {
|
||||
return nil, 0, err
|
||||
}
|
||||
|
||||
offset := (page - 1) * pageSize
|
||||
var list []model.SysOperationRecord
|
||||
if err := db.Order("id desc").Offset(offset).Limit(pageSize).Find(&list).Error; err != nil {
|
||||
return nil, 0, err
|
||||
}
|
||||
|
||||
// 预加载用户信息
|
||||
userIDs := make([]int64, 0)
|
||||
for _, m := range list {
|
||||
userIDs = append(userIDs, m.UserID)
|
||||
}
|
||||
userMap := make(map[int64]*model.SysUser)
|
||||
if len(userIDs) > 0 {
|
||||
var users []model.SysUser
|
||||
r.db.WithContext(ctx).Where("id in (?)", userIDs).Find(&users)
|
||||
for i := range users {
|
||||
userMap[users[i].ID] = &users[i]
|
||||
}
|
||||
}
|
||||
|
||||
result := make([]*system.OperationRecord, len(list))
|
||||
for i, m := range list {
|
||||
user := userMap[m.UserID]
|
||||
result[i] = toBizOperationRecord(&m, user)
|
||||
}
|
||||
return result, total, nil
|
||||
}
|
||||
|
||||
// 转换函数
|
||||
func toModelOperationRecord(r *system.OperationRecord) *model.SysOperationRecord {
|
||||
return &model.SysOperationRecord{
|
||||
ID: int64(r.ID),
|
||||
IP: r.IP,
|
||||
Method: r.Method,
|
||||
Path: r.Path,
|
||||
Status: int64(r.Status),
|
||||
Latency: r.Latency,
|
||||
Agent: r.Agent,
|
||||
ErrorMessage: r.ErrorMessage,
|
||||
Body: r.Body,
|
||||
Resp: r.Resp,
|
||||
UserID: int64(r.UserID),
|
||||
}
|
||||
}
|
||||
|
||||
func toBizOperationRecord(m *model.SysOperationRecord, user *model.SysUser) *system.OperationRecord {
|
||||
r := &system.OperationRecord{
|
||||
ID: uint(m.ID),
|
||||
IP: m.IP,
|
||||
Method: m.Method,
|
||||
Path: m.Path,
|
||||
Status: int(m.Status),
|
||||
Latency: m.Latency,
|
||||
Agent: m.Agent,
|
||||
ErrorMessage: m.ErrorMessage,
|
||||
Body: m.Body,
|
||||
Resp: m.Resp,
|
||||
UserID: uint(m.UserID),
|
||||
}
|
||||
if user != nil {
|
||||
r.User = &system.User{
|
||||
ID: uint(user.ID),
|
||||
Username: user.Username,
|
||||
NickName: user.NickName,
|
||||
}
|
||||
}
|
||||
return r
|
||||
}
|
||||
@@ -263,9 +263,7 @@ func (r *userRepo) GetAuthorityMenuRouters(ctx context.Context, authorityId uint
|
||||
|
||||
routers := make([]string, len(menus))
|
||||
for i, m := range menus {
|
||||
if m.Name != nil {
|
||||
routers[i] = *m.Name
|
||||
}
|
||||
routers[i] = m.Name
|
||||
}
|
||||
return routers, nil
|
||||
}
|
||||
@@ -275,76 +273,41 @@ func (r *userRepo) GetAuthorityDefaultRouter(ctx context.Context, authorityId ui
|
||||
if err := r.db.WithContext(ctx).Where("authority_id = ?", authorityId).First(&authority).Error; err != nil {
|
||||
return "", err
|
||||
}
|
||||
if authority.DefaultRouter != nil {
|
||||
return *authority.DefaultRouter, nil
|
||||
}
|
||||
return "", nil
|
||||
return authority.DefaultRouter, nil
|
||||
}
|
||||
|
||||
// 转换函数
|
||||
func toBizUser(u *system.User) *model.SysUser {
|
||||
uuidStr := u.UUID.String()
|
||||
username := u.Username
|
||||
password := u.Password
|
||||
nickName := u.NickName
|
||||
headerImg := u.HeaderImg
|
||||
authorityID := int64(u.AuthorityId)
|
||||
phone := u.Phone
|
||||
email := u.Email
|
||||
enable := int64(u.Enable)
|
||||
|
||||
return &model.SysUser{
|
||||
ID: int64(u.ID),
|
||||
UUID: &uuidStr,
|
||||
Username: &username,
|
||||
Password: &password,
|
||||
NickName: &nickName,
|
||||
HeaderImg: &headerImg,
|
||||
AuthorityID: &authorityID,
|
||||
Phone: &phone,
|
||||
Email: &email,
|
||||
Enable: &enable,
|
||||
UUID: u.UUID.String(),
|
||||
Username: u.Username,
|
||||
Password: u.Password,
|
||||
NickName: u.NickName,
|
||||
HeaderImg: u.HeaderImg,
|
||||
AuthorityID: int64(u.AuthorityId),
|
||||
Phone: u.Phone,
|
||||
Email: u.Email,
|
||||
Enable: int64(u.Enable),
|
||||
}
|
||||
}
|
||||
|
||||
func toModelUser(m *model.SysUser) *system.User {
|
||||
u := &system.User{ID: uint(m.ID)}
|
||||
if m.UUID != nil {
|
||||
u.UUID, _ = uuid.Parse(*m.UUID)
|
||||
}
|
||||
if m.Username != nil {
|
||||
u.Username = *m.Username
|
||||
}
|
||||
if m.Password != nil {
|
||||
u.Password = *m.Password
|
||||
}
|
||||
if m.NickName != nil {
|
||||
u.NickName = *m.NickName
|
||||
}
|
||||
if m.HeaderImg != nil {
|
||||
u.HeaderImg = *m.HeaderImg
|
||||
}
|
||||
if m.AuthorityID != nil {
|
||||
u.AuthorityId = uint(*m.AuthorityID)
|
||||
}
|
||||
if m.Phone != nil {
|
||||
u.Phone = *m.Phone
|
||||
}
|
||||
if m.Email != nil {
|
||||
u.Email = *m.Email
|
||||
}
|
||||
if m.Enable != nil {
|
||||
u.Enable = int(*m.Enable)
|
||||
}
|
||||
if m.OriginSetting != nil {
|
||||
u.OriginSetting = json.RawMessage(*m.OriginSetting)
|
||||
}
|
||||
if m.CreatedAt != nil {
|
||||
u.CreatedAt = *m.CreatedAt
|
||||
}
|
||||
if m.UpdatedAt != nil {
|
||||
u.UpdatedAt = *m.UpdatedAt
|
||||
u := &system.User{
|
||||
ID: uint(m.ID),
|
||||
Username: m.Username,
|
||||
Password: m.Password,
|
||||
NickName: m.NickName,
|
||||
HeaderImg: m.HeaderImg,
|
||||
AuthorityId: uint(m.AuthorityID),
|
||||
Phone: m.Phone,
|
||||
Email: m.Email,
|
||||
Enable: int(m.Enable),
|
||||
OriginSetting: json.RawMessage(m.OriginSetting),
|
||||
CreatedAt: m.CreatedAt,
|
||||
UpdatedAt: m.UpdatedAt,
|
||||
}
|
||||
u.UUID, _ = uuid.Parse(m.UUID)
|
||||
return u
|
||||
}
|
||||
|
||||
@@ -354,11 +317,11 @@ func toModelUserWithAuthorities(m *model.SysUser) *system.User {
|
||||
// 转换Authority
|
||||
u.Authority = &system.Authority{
|
||||
AuthorityId: uint(m.Authority.AuthorityID),
|
||||
AuthorityName: safeString(m.Authority.AuthorityName),
|
||||
DefaultRouter: safeString(m.Authority.DefaultRouter),
|
||||
AuthorityName: m.Authority.AuthorityName,
|
||||
DefaultRouter: m.Authority.DefaultRouter,
|
||||
}
|
||||
if m.Authority.ParentID != nil {
|
||||
pid := uint(*m.Authority.ParentID)
|
||||
if m.Authority.ParentID != 0 {
|
||||
pid := uint(m.Authority.ParentID)
|
||||
u.Authority.ParentId = &pid
|
||||
}
|
||||
|
||||
@@ -368,11 +331,11 @@ func toModelUserWithAuthorities(m *model.SysUser) *system.User {
|
||||
for i, a := range m.Authorities {
|
||||
u.Authorities[i] = &system.Authority{
|
||||
AuthorityId: uint(a.AuthorityID),
|
||||
AuthorityName: safeString(a.AuthorityName),
|
||||
DefaultRouter: safeString(a.DefaultRouter),
|
||||
AuthorityName: a.AuthorityName,
|
||||
DefaultRouter: a.DefaultRouter,
|
||||
}
|
||||
if a.ParentID != nil {
|
||||
pid := uint(*a.ParentID)
|
||||
if a.ParentID != 0 {
|
||||
pid := uint(a.ParentID)
|
||||
u.Authorities[i].ParentId = &pid
|
||||
}
|
||||
}
|
||||
@@ -380,10 +343,3 @@ func toModelUserWithAuthorities(m *model.SysUser) *system.User {
|
||||
|
||||
return u
|
||||
}
|
||||
|
||||
func safeString(s *string) string {
|
||||
if s == nil {
|
||||
return ""
|
||||
}
|
||||
return *s
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user