* feat(mcp): 新增gva_review工具并优化字典和代码生成逻辑 * fix: 调整mcp整体逻辑 * chore: 更新.gitignore,添加对本地配置文件的忽略 * feat(logo): 新增Logo组件并在多个页面中替换原有logo实现 * fix: 修复菜单 Logo 部分删除文本后显示异常的问题 * fix:添加字典列表搜索,支持中英文搜索.添加字典详情搜索 * style: 优化部分视觉样式 * feat: 增强错误预览组件的暗黑模式支持 * feat: 优化请求错误消息获取逻辑,增加状态文本优先级 * feat: 添加前端登录验证码静态验证逻辑 * feat: 添加开发环境启动脚本 * feat: 更新 SvgIcon 组件,支持本地图标和 Iconify 图标、移除未使用的 unocss 依赖 * fix:字典支持 tree 结构 * feat: 优化动态路由注册方式 * feat: 添加配置控制标签页keep-alive功能 * feat: 添加全局错误处理机制,捕获 Vue 和 JS 错误 * refactor: 移除API和菜单创建结果中的权限分配提醒,优化输出信息 * feat: 更新 reset.scss,优化全局样式重置,增强兼容性和可读性 * refactor(字典详情): 优化字典详情查询逻辑,移除预加载改为按需加载 * refactor(路由管理): 优化路由添加逻辑,增强路径处理和顶级路由注册 * refactor(系统配置): 将auto-migrate修改为disable-auto-migrate,保证用户升级的兼容性 * feat(utils): 优化字典数据递归查找功能并替换select为tree-select * fix(deps): 修复在字段类型为file生成搜索条件无法运行的bug * fix: 修复header的tools中icon不展示的问题 --------- Co-authored-by: piexlMax(奇淼 <qimiaojiangjizhao@gmail.com> Co-authored-by: Azir-11 <2075125282@qq.com> Co-authored-by: bypanghu <bypanghu@163.com> Co-authored-by: feitianbubu <feitianbubu@qq.com> Co-authored-by: 青菜白玉汤 <79054161+Azir-11@users.noreply.github.com> Co-authored-by: krank <emosick@qq.com>
155 lines
5.1 KiB
Go
155 lines
5.1 KiB
Go
package system
|
||
|
||
import (
|
||
"errors"
|
||
|
||
"github.com/flipped-aurora/gin-vue-admin/server/model/system/request"
|
||
"github.com/gin-gonic/gin"
|
||
|
||
"github.com/flipped-aurora/gin-vue-admin/server/global"
|
||
"github.com/flipped-aurora/gin-vue-admin/server/model/system"
|
||
"gorm.io/gorm"
|
||
)
|
||
|
||
//@author: [piexlmax](https://github.com/piexlmax)
|
||
//@function: CreateSysDictionary
|
||
//@description: 创建字典数据
|
||
//@param: sysDictionary model.SysDictionary
|
||
//@return: err error
|
||
|
||
type DictionaryService struct{}
|
||
|
||
var DictionaryServiceApp = new(DictionaryService)
|
||
|
||
func (dictionaryService *DictionaryService) CreateSysDictionary(sysDictionary system.SysDictionary) (err error) {
|
||
if (!errors.Is(global.GVA_DB.First(&system.SysDictionary{}, "type = ?", sysDictionary.Type).Error, gorm.ErrRecordNotFound)) {
|
||
return errors.New("存在相同的type,不允许创建")
|
||
}
|
||
err = global.GVA_DB.Create(&sysDictionary).Error
|
||
return err
|
||
}
|
||
|
||
//@author: [piexlmax](https://github.com/piexlmax)
|
||
//@function: DeleteSysDictionary
|
||
//@description: 删除字典数据
|
||
//@param: sysDictionary model.SysDictionary
|
||
//@return: err error
|
||
|
||
func (dictionaryService *DictionaryService) DeleteSysDictionary(sysDictionary system.SysDictionary) (err error) {
|
||
err = global.GVA_DB.Where("id = ?", sysDictionary.ID).Preload("SysDictionaryDetails").First(&sysDictionary).Error
|
||
if err != nil && errors.Is(err, gorm.ErrRecordNotFound) {
|
||
return errors.New("请不要搞事")
|
||
}
|
||
if err != nil {
|
||
return err
|
||
}
|
||
err = global.GVA_DB.Delete(&sysDictionary).Error
|
||
if err != nil {
|
||
return err
|
||
}
|
||
|
||
if sysDictionary.SysDictionaryDetails != nil {
|
||
return global.GVA_DB.Where("sys_dictionary_id=?", sysDictionary.ID).Delete(sysDictionary.SysDictionaryDetails).Error
|
||
}
|
||
return
|
||
}
|
||
|
||
//@author: [piexlmax](https://github.com/piexlmax)
|
||
//@function: UpdateSysDictionary
|
||
//@description: 更新字典数据
|
||
//@param: sysDictionary *model.SysDictionary
|
||
//@return: err error
|
||
|
||
func (dictionaryService *DictionaryService) UpdateSysDictionary(sysDictionary *system.SysDictionary) (err error) {
|
||
var dict system.SysDictionary
|
||
sysDictionaryMap := map[string]interface{}{
|
||
"Name": sysDictionary.Name,
|
||
"Type": sysDictionary.Type,
|
||
"Status": sysDictionary.Status,
|
||
"Desc": sysDictionary.Desc,
|
||
"ParentID": sysDictionary.ParentID,
|
||
}
|
||
err = global.GVA_DB.Where("id = ?", sysDictionary.ID).First(&dict).Error
|
||
if err != nil {
|
||
global.GVA_LOG.Debug(err.Error())
|
||
return errors.New("查询字典数据失败")
|
||
}
|
||
if dict.Type != sysDictionary.Type {
|
||
if !errors.Is(global.GVA_DB.First(&system.SysDictionary{}, "type = ?", sysDictionary.Type).Error, gorm.ErrRecordNotFound) {
|
||
return errors.New("存在相同的type,不允许创建")
|
||
}
|
||
}
|
||
|
||
// 检查是否会形成循环引用
|
||
if sysDictionary.ParentID != nil && *sysDictionary.ParentID != 0 {
|
||
if err := dictionaryService.checkCircularReference(sysDictionary.ID, *sysDictionary.ParentID); err != nil {
|
||
return err
|
||
}
|
||
}
|
||
|
||
err = global.GVA_DB.Model(&dict).Updates(sysDictionaryMap).Error
|
||
return err
|
||
}
|
||
|
||
//@author: [piexlmax](https://github.com/piexlmax)
|
||
//@function: GetSysDictionary
|
||
//@description: 根据id或者type获取字典单条数据
|
||
//@param: Type string, Id uint
|
||
//@return: err error, sysDictionary model.SysDictionary
|
||
|
||
func (dictionaryService *DictionaryService) GetSysDictionary(Type string, Id uint, status *bool) (sysDictionary system.SysDictionary, err error) {
|
||
var flag = false
|
||
if status == nil {
|
||
flag = true
|
||
} else {
|
||
flag = *status
|
||
}
|
||
err = global.GVA_DB.Where("(type = ? OR id = ?) and status = ?", Type, Id, flag).Preload("SysDictionaryDetails", func(db *gorm.DB) *gorm.DB {
|
||
return db.Where("status = ? and deleted_at is null", true).Order("sort")
|
||
}).First(&sysDictionary).Error
|
||
return
|
||
}
|
||
|
||
//@author: [piexlmax](https://github.com/piexlmax)
|
||
//@author: [SliverHorn](https://github.com/SliverHorn)
|
||
//@function: GetSysDictionaryInfoList
|
||
//@description: 分页获取字典列表
|
||
//@param: info request.SysDictionarySearch
|
||
//@return: err error, list interface{}, total int64
|
||
|
||
func (dictionaryService *DictionaryService) GetSysDictionaryInfoList(c *gin.Context, req request.SysDictionarySearch) (list interface{}, err error) {
|
||
var sysDictionarys []system.SysDictionary
|
||
query := global.GVA_DB.WithContext(c)
|
||
if req.Name != "" {
|
||
query = query.Where("name LIKE ? OR type LIKE ?", "%"+req.Name+"%", "%"+req.Name+"%")
|
||
}
|
||
// 预加载子字典
|
||
query = query.Preload("Children")
|
||
err = query.Find(&sysDictionarys).Error
|
||
return sysDictionarys, err
|
||
}
|
||
|
||
// checkCircularReference 检查是否会形成循环引用
|
||
func (dictionaryService *DictionaryService) checkCircularReference(currentID uint, parentID uint) error {
|
||
if currentID == parentID {
|
||
return errors.New("不能将字典设置为自己的父级")
|
||
}
|
||
|
||
// 递归检查父级链条
|
||
var parent system.SysDictionary
|
||
err := global.GVA_DB.Where("id = ?", parentID).First(&parent).Error
|
||
if err != nil {
|
||
if errors.Is(err, gorm.ErrRecordNotFound) {
|
||
return nil // 父级不存在,允许设置
|
||
}
|
||
return err
|
||
}
|
||
|
||
// 如果父级还有父级,继续检查
|
||
if parent.ParentID != nil && *parent.ParentID != 0 {
|
||
return dictionaryService.checkCircularReference(currentID, *parent.ParentID)
|
||
}
|
||
|
||
return nil
|
||
}
|