yxh 4 vuotta sitten
vanhempi
säilyke
bc9c13373e

+ 50 - 0
api/v1/system/sys_dict_type.go

@@ -0,0 +1,50 @@
+/*
+* @desc:字典类型
+* @company:云南奇讯科技有限公司
+* @Author: yixiaohu
+* @Date:   2022/4/14 21:30
+ */
+
+package system
+
+import (
+	"github.com/gogf/gf/v2/frame/g"
+	commonApi "github.com/tiger1103/gfast/v3/api/v1/common"
+	"github.com/tiger1103/gfast/v3/internal/app/common/model"
+	"github.com/tiger1103/gfast/v3/internal/app/common/model/entity"
+)
+
+type DictTypeSearchReq struct {
+	g.Meta   `path:"/system/dict/type/list" tags:"字典管理" method:"get" summary:"字典类型列表"`
+	DictName string `p:"dictName"` //字典名称
+	DictType string `p:"dictType"` //字典类型
+	Status   string `p:"status"`   //字典状态
+	commonApi.PageReq
+}
+
+type DictTypeSearchRes struct {
+	g.Meta       `mime:"application/json"`
+	DictTypeList []*model.SysDictTypeInfoRes `json:"dictTypeList"`
+	commonApi.ListRes
+}
+
+type DictTypeAddReq struct {
+	g.Meta   `path:"/system/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"`
+}
+
+type DictTypeAddRes struct {
+}
+
+type DictTypeGetReq struct {
+	g.Meta `path:"/system/dict/type/get" tags:"字典管理" method:"get" summary:"获取字典类型"`
+	DictId uint `p:"dictId" v:"required#类型id不能为空"`
+}
+
+type DictTypeGetRes struct {
+	g.Meta   `mime:"application/json"`
+	DictType *entity.SysDictType `json:"dictType"`
+}

+ 12 - 1
internal/app/common/model/sys_dict_type.go

@@ -1,8 +1,19 @@
 /*
-* @desc:xxxx功能描述
+* @desc:字典类型
 * @company:云南奇讯科技有限公司
 * @Author: yixiaohu<yxh669@qq.com>
 * @Date:   2022/3/18 11:56
  */
 
 package model
+
+import "github.com/gogf/gf/v2/os/gtime"
+
+type SysDictTypeInfoRes struct {
+	DictId    uint64      `orm:"dict_id,primary"  json:"dictId"`    // 字典主键
+	DictName  string      `orm:"dict_name"        json:"dictName"`  // 字典名称
+	DictType  string      `orm:"dict_type,unique" json:"dictType"`  // 字典类型
+	Status    uint        `orm:"status"           json:"status"`    // 状态(0正常 1停用)
+	Remark    string      `orm:"remark"           json:"remark"`    // 备注
+	CreatedAt *gtime.Time `orm:"created_at"       json:"createdAt"` // 创建日期
+}

+ 106 - 1
internal/app/common/service/sys_dict_type.go

@@ -1,8 +1,113 @@
 /*
-* @desc:xxxx功能描述
+* @desc:字典类型
 * @company:云南奇讯科技有限公司
 * @Author: yixiaohu<yxh669@qq.com>
 * @Date:   2022/3/18 11:55
  */
 
 package service
+
+import "C"
+import (
+	"context"
+	"github.com/gogf/gf/v2/errors/gerror"
+	"github.com/gogf/gf/v2/frame/g"
+	"github.com/gogf/gf/v2/util/gconv"
+	"github.com/tiger1103/gfast/v3/api/v1/system"
+	commonConsts "github.com/tiger1103/gfast/v3/internal/app/common/consts"
+	"github.com/tiger1103/gfast/v3/internal/app/common/model"
+	"github.com/tiger1103/gfast/v3/internal/app/common/model/entity"
+	"github.com/tiger1103/gfast/v3/internal/app/common/service/internal/dao"
+	"github.com/tiger1103/gfast/v3/internal/app/common/service/internal/do"
+	"github.com/tiger1103/gfast/v3/internal/app/system/consts"
+	"github.com/tiger1103/gfast/v3/library/liberr"
+)
+
+type IDictType interface {
+	List(ctx context.Context, req *system.DictTypeSearchReq) (res *system.DictTypeSearchRes, err error)
+	Add(ctx context.Context, req *system.DictTypeAddReq, userId uint64) (err error)
+	Get(ctx context.Context, req *system.DictTypeGetReq) (dictType *entity.SysDictType, err error)
+}
+
+type dictTypeImpl struct {
+}
+
+var dictTypeService = dictTypeImpl{}
+
+func DictType() IDictType {
+	return IDictType(&dictTypeService)
+}
+
+// List 字典类型列表
+func (s *dictTypeImpl) List(ctx context.Context, req *system.DictTypeSearchReq) (res *system.DictTypeSearchRes, err error) {
+	res = new(system.DictTypeSearchRes)
+	err = g.Try(func() {
+		m := dao.SysDictType.Ctx(ctx)
+		if req.DictName != "" {
+			m = m.Where(dao.SysDictType.Columns().DictName+" like ?", "%"+req.DictName+"%")
+		}
+		if req.DictType != "" {
+			m = m.Where(dao.SysDictType.Columns().DictType+" like ?", "%"+req.DictType+"%")
+		}
+		if req.Status != "" {
+			m = m.Where(dao.SysDictType.Columns().Status+" = ", gconv.Int(req.Status))
+		}
+		res.Total, err = m.Count()
+		liberr.ErrIsNil(ctx, err, "获取字典类型失败")
+		if req.PageNum == 0 {
+			req.PageNum = 1
+		}
+		res.CurrentPage = req.PageNum
+		if req.PageSize == 0 {
+			req.PageSize = consts.PageSize
+		}
+		err = m.Fields(model.SysDictTypeInfoRes{}).Page(req.PageNum, req.PageSize).
+			Order(dao.SysDictType.Columns().DictId + " asc").Scan(&res.DictTypeList)
+		liberr.ErrIsNil(ctx, err, "获取字典类型失败")
+	})
+	return
+}
+
+// Add 添加字典类型
+func (s *dictTypeImpl) Add(ctx context.Context, req *system.DictTypeAddReq, userId uint64) (err error) {
+	err = g.Try(func() {
+		err = s.ExistsDictType(ctx, req.DictType)
+		liberr.ErrIsNil(ctx, err)
+		_, err = dao.SysDictType.Ctx(ctx).Insert(do.SysDictType{
+			DictName: req.DictName,
+			DictType: req.DictType,
+			Status:   req.Status,
+			CreateBy: userId,
+			Remark:   req.Remark,
+		})
+		liberr.ErrIsNil(ctx, err, "添加字典类型失败")
+		//清除缓存
+		Cache().RemoveByTag(ctx, commonConsts.CacheSysDictTag)
+	})
+	return
+}
+
+func (s *dictTypeImpl) Get(ctx context.Context, req *system.DictTypeGetReq) (dictType *entity.SysDictType, err error) {
+	err = g.Try(func() {
+		err = dao.SysDictType.Ctx(ctx).Where(dao.SysDictType.Columns().DictId, req.DictId).Scan(&dictType)
+		liberr.ErrIsNil(ctx, err, "获取字典类型失败")
+	})
+	return
+}
+
+// ExistsDictType 检查类型是否已经存在
+func (s *dictTypeImpl) ExistsDictType(ctx context.Context, dictType string, dictId ...int64) (err error) {
+	err = g.Try(func() {
+		m := dao.SysDictType.Ctx(ctx).Fields(dao.SysDictType.Columns().DictId).
+			Where(dao.SysDictType.Columns().DictType, dictType)
+		if len(dictId) > 0 {
+			m = m.Where(dao.SysDictType.Columns().DictId+" !=? ", dictId[0])
+		}
+		res, e := m.One()
+		liberr.ErrIsNil(ctx, e, "sql err")
+		if !res.IsEmpty() {
+			liberr.ErrIsNil(ctx, gerror.New("字典类型已存在"))
+		}
+	})
+	return
+}

+ 30 - 1
internal/app/system/controller/sys_dict_type.go

@@ -1,8 +1,37 @@
 /*
-* @desc:xxxx功能描述
+* @desc:字典类型
 * @company:云南奇讯科技有限公司
 * @Author: yixiaohu<yxh669@qq.com>
 * @Date:   2022/3/18 11:57
  */
 
 package controller
+
+import (
+	"context"
+	"github.com/tiger1103/gfast/v3/api/v1/system"
+	commonService "github.com/tiger1103/gfast/v3/internal/app/common/service"
+	"github.com/tiger1103/gfast/v3/internal/app/system/service"
+)
+
+var DictType = &SysDictTypeController{}
+
+type SysDictTypeController struct {
+}
+
+// List 字典类型列表
+func (c *SysDictTypeController) List(ctx context.Context, req *system.DictTypeSearchReq) (res *system.DictTypeSearchRes, err error) {
+	res, err = commonService.DictType().List(ctx, req)
+	return
+}
+
+// Add 添加字典类型
+func (c *SysDictTypeController) Add(ctx context.Context, req *system.DictTypeAddReq) (res *system.DictTypeAddRes, err error) {
+	err = commonService.DictType().Add(ctx, req, service.Context().GetUserId(ctx))
+	return
+}
+
+func (c *SysDictTypeController) Get(ctx context.Context, req *system.DictTypeGetReq) (res *system.DictTypeGetRes, err error) {
+
+	return
+}

+ 1 - 0
internal/app/system/router/router.go

@@ -27,6 +27,7 @@ func BindController(group *ghttp.RouterGroup) {
 			controller.Role,
 			controller.Dept,
 			controller.Post,
+			controller.DictType,
 			controller.DictData,
 		)
 	})