Skip to content

Commit

Permalink
Merge pull request #15 from singledemon/main
Browse files Browse the repository at this point in the history
 字典类型添加字段代码
  • Loading branch information
xinjiayu authored Sep 8, 2023
2 parents 72ea312 + 1d20bf9 commit 0ab7981
Show file tree
Hide file tree
Showing 9 changed files with 77 additions and 43 deletions.
33 changes: 18 additions & 15 deletions api/v1/common/dict_type.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,11 @@ import (
)

type DictTypeSearchReq struct {
g.Meta `path:"/dict/type/list" tags:"字典管理" method:"get" summary:"字典类型列表"`
DictName string `p:"dictName"` //字典名称
DictType string `p:"dictType"` //字典类型
Status string `p:"status"` //字典状态
g.Meta `path:"/dict/type/list" tags:"字典管理" method:"get" summary:"字典类型列表"`
DictName string `p:"dictName"` //字典名称
DictType string `p:"dictType"` //字典类型
Status string `p:"status"` //字典状态
DictClass string `p:"dictClass"` //字典分类
*PaginationReq
}

Expand All @@ -20,11 +21,12 @@ type DictTypeSearchRes struct {
}

type DictTypeAddReq struct {
g.Meta `path:"/dict/type/add" tags:"字典管理" method:"post" summary:"添加字典类型"`
DictName string `p:"dictName" v:"required#字典名称不能为空"`
DictType string `p:"dictType" v:"required#字典类型不能为空"`
Status uint `p:"status" v:"required|in:0,1#状态不能为空|状态只能为0或1"`
Remark string `p:"remark"`
g.Meta `path:"/dict/type/add" tags:"字典管理" method:"post" summary:"添加字典类型"`
DictName string `p:"dictName" v:"required#字典名称不能为空"`
DictType string `p:"dictType" v:"required#字典类型不能为空"`
Status uint `p:"status" v:"required|in:0,1#状态不能为空|状态只能为0或1"`
DictClass string `p:"dictClass"` //字典分类
Remark string `p:"remark"`
}

type DictTypeAddRes struct {
Expand All @@ -41,12 +43,13 @@ type DictTypeGetRes struct {
}

type DictTypeEditReq struct {
g.Meta `path:"/dict/type/edit" tags:"字典管理" method:"put" summary:"修改字典类型"`
DictId int `p:"dictId" v:"required|min:1#主键ID不能为空|主键ID必须为大于0的值"`
DictName string `p:"dictName" v:"required#字典名称不能为空"`
DictType string `p:"dictType" v:"required#字典类型不能为空"`
Status uint `p:"status" v:"required|in:0,1#状态不能为空|状态只能为0或1"`
Remark string `p:"remark"`
g.Meta `path:"/dict/type/edit" tags:"字典管理" method:"put" summary:"修改字典类型"`
DictId int `p:"dictId" v:"required|min:1#主键ID不能为空|主键ID必须为大于0的值"`
DictName string `p:"dictName" v:"required#字典名称不能为空"`
DictType string `p:"dictType" v:"required#字典类型不能为空"`
Status uint `p:"status" v:"required|in:0,1#状态不能为空|状态只能为0或1"`
DictClass string `p:"dictClass"` //字典分类
Remark string `p:"remark"`
}

type DictTypeEditRes struct {
Expand Down
2 changes: 1 addition & 1 deletion internal/dao/internal/sys_dict_data.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion internal/dao/internal/sys_dict_type.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 7 additions & 3 deletions internal/logic/common/dict_data.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,15 @@ func (s *sDictData) GetDictWithDataByType(ctx context.Context, input *model.GetD
//从数据库获取
dict = &model.GetDictOut{}
//获取类型数据
err = dao.SysDictType.Ctx(ctx).Where(dao.SysDictType.Columns().DictType, input.DictType).
Where(dao.SysDictType.Columns().Status, 1).Fields(model.DictTypeOut{}).Scan(&dict.Data)
err = dao.SysDictType.Ctx(ctx).Where(g.Map{
dao.SysDictType.Columns().DictType: input.DictType,
dao.SysDictType.Columns().Status: 1,
}).Fields(model.DictTypeOut{}).Scan(&dict.Data)
liberr.ErrIsNil(ctx, err, "获取字典类型失败")
err = dao.SysDictData.Ctx(ctx).Fields(model.DictDataOut{}).
Where(dao.SysDictData.Columns().DictType, input.DictType).
Where(g.Map{
dao.SysDictData.Columns().DictType: input.DictType,
}).
Order(dao.SysDictData.Columns().DictSort + " asc," +
dao.SysDictData.Columns().DictCode + " asc").
Scan(&dict.Values)
Expand Down
27 changes: 17 additions & 10 deletions internal/logic/common/dict_type.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,9 @@ func (s *sDictType) List(ctx context.Context, input *model.DictTypeDoInput) (tot
if input.Status != "" {
m = m.Where(dao.SysDictType.Columns().Status+" = ", gconv.Int(input.Status))
}
if input.DictClass != "" {
m = m.Where(dao.SysDictType.Columns().DictClass+" = ", input.DictClass)
}
total, err = m.Count()
liberr.ErrIsNil(ctx, err, "获取字典类型失败")
if input.PageNum == 0 {
Expand All @@ -61,12 +64,15 @@ func (s *sDictType) Add(ctx context.Context, input *model.AddDictTypeInput, user
err = g.Try(ctx, func(ctx context.Context) {
err = s.ExistsDictType(ctx, input.DictType)
liberr.ErrIsNil(ctx, err)
parentId := 0
_, err = dao.SysDictType.Ctx(ctx).Insert(do.SysDictType{
DictName: input.DictName,
DictType: input.DictType,
Status: input.Status,
CreateBy: userId,
Remark: input.Remark,
DictName: input.DictName,
DictType: input.DictType,
Status: input.Status,
CreateBy: userId,
Remark: input.Remark,
DictClass: input.DictClass,
ParentId: parentId,
})
liberr.ErrIsNil(ctx, err, "添加字典类型失败")
//清除缓存
Expand All @@ -87,11 +93,12 @@ func (s *sDictType) Edit(ctx context.Context, input *model.EditDictTypeInput, us
liberr.ValueIsNil(dictType, "字典类型不存在")
//修改字典类型
_, e = dao.SysDictType.Ctx(ctx).TX(tx).WherePri(input.DictId).Update(do.SysDictType{
DictName: input.DictName,
DictType: input.DictType,
Status: input.Status,
UpdateBy: userId,
Remark: input.Remark,
DictName: input.DictName,
DictType: input.DictType,
Status: input.Status,
UpdateBy: userId,
Remark: input.Remark,
DictClass: input.DictClass,
})
liberr.ErrIsNil(ctx, e, "修改字典类型失败")
//修改字典数据
Expand Down
1 change: 1 addition & 0 deletions internal/model/do/sys_dict_type.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion internal/model/entity/sys_dict_type.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

31 changes: 19 additions & 12 deletions internal/model/sys_dict_type.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@ package model
import "github.com/gogf/gf/v2/os/gtime"

type DictTypeDoInput struct {
DictName string `p:"dictName"` //字典名称
DictType string `p:"dictType"` //字典类型
Status string `p:"status"` //字典状态
DictName string `p:"dictName"` //字典名称
DictType string `p:"dictType"` //字典类型
Status string `p:"status"` //字典状态
DictClass string `p:"dictClass"` //字典分类
*PaginationInput
}
type SysDictTypeInfoOut struct {
Expand All @@ -15,21 +16,24 @@ type SysDictTypeInfoOut struct {
Status uint `orm:"status" json:"status"` // 状态(0正常 1停用)
Remark string `orm:"remark" json:"remark"` // 备注
CreatedAt *gtime.Time `orm:"created_at" json:"createdAt"` // 创建日期
DictClass string `orm:"dict_class" json:"dictClass"` // 字典分类
}

type AddDictTypeInput struct {
DictName string `p:"dictName"`
DictType string `p:"dictType"`
Status uint `p:"status"`
Remark string `p:"remark"`
DictName string `p:"dictName"`
DictType string `p:"dictType"`
Status uint `p:"status"`
Remark string `p:"remark"`
DictClass string `p:"dictClass"`
}

type EditDictTypeInput struct {
DictId int `p:"dictId"`
DictName string `p:"dictName"`
DictType string `p:"dictType"`
Status uint `p:"status"`
Remark string `p:"remark"`
DictId int `p:"dictId"`
DictName string `p:"dictName"`
DictType string `p:"dictType"`
Status uint `p:"status"`
Remark string `p:"remark"`
DictClass string `p:"dictClass"`
}

type SysDictTypeInfoRes struct {
Expand All @@ -39,6 +43,7 @@ type SysDictTypeInfoRes struct {
Status uint `orm:"status" json:"status"` // 状态(0正常 1停用)
Remark string `orm:"remark" json:"remark"` // 备注
CreatedAt *gtime.Time `orm:"created_at" json:"createdAt"` // 创建日期
DictClass string `orm:"dict_class" json:"dictClass"` // 字典分类
}

type SysDictTypeOut struct {
Expand All @@ -51,6 +56,7 @@ type SysDictTypeOut struct {
Remark string `json:"remark" description:"备注"`
CreatedAt *gtime.Time `json:"createdAt" description:"创建日期"`
UpdatedAt *gtime.Time `json:"updatedAt" description:"修改日期"`
DictClass string `json:"dictClass" description:"字典分类"`
}

type SysDictTypeRes struct {
Expand All @@ -63,4 +69,5 @@ type SysDictTypeRes struct {
Remark string `json:"remark" description:"备注"`
CreatedAt *gtime.Time `json:"createdAt" description:"创建日期"`
UpdatedAt *gtime.Time `json:"updatedAt" description:"修改日期"`
DictClass string `json:"dictClass" description:"字典分类"`
}
9 changes: 9 additions & 0 deletions manifest/sql/update.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
-- ----------------------------
-- 2023-09-08 修改字典类型表
-- ----------------------------
ALTER TABLE `sagoo_iot`.`sys_dict_data`
ADD COLUMN `dict_class` varchar(10) NOT NULL DEFAULT 0 COMMENT '字典分类取值从字典类型' AFTER `remark`;
ALTER TABLE `sagoo_iot`.`sys_dict_type`
MODIFY COLUMN `is_deleted` int NOT NULL DEFAULT 0 COMMENT '是否删除 0未删除 1已删除' AFTER `status`;
ALTER TABLE `sagoo_iot`.`sys_dict_type`
MODIFY COLUMN `module_classify` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL COMMENT '模块分类' AFTER `dict_type`;

0 comments on commit 0ab7981

Please sign in to comment.