yxh 4 лет назад
Родитель
Сommit
bbe7faec81

+ 71 - 0
api/v1/system/sys_config.go

@@ -0,0 +1,71 @@
+/*
+* @desc:系统参数配置
+* @company:云南奇讯科技有限公司
+* @Author: yixiaohu
+* @Date:   2022/4/18 21:11
+ */
+
+package system
+
+import (
+	"github.com/gogf/gf/v2/frame/g"
+	commonApi "github.com/tiger1103/gfast/v3/api/v1/common"
+	commonEntity "github.com/tiger1103/gfast/v3/internal/app/common/model/entity"
+)
+
+type ConfigSearchReq struct {
+	g.Meta     `path:"/config/list" tags:"系统参数管理" method:"get" summary:"系统参数列表"`
+	ConfigName string `p:"configName"` //参数名称
+	ConfigKey  string `p:"configKey"`  //参数键名
+	ConfigType string `p:"configType"` //状态
+	commonApi.PageReq
+}
+
+type ConfigSearchRes struct {
+	g.Meta `mime:"application/json"`
+	List   []*commonEntity.SysConfig `json:"list"`
+	commonApi.ListRes
+}
+
+type ConfigReq struct {
+	ConfigName  string `p:"configName"  v:"required#参数名称不能为空"`
+	ConfigKey   string `p:"configKey"  v:"required#参数键名不能为空"`
+	ConfigValue string `p:"configValue"  v:"required#参数键值不能为空"`
+	ConfigType  int    `p:"configType"    v:"required|in:0,1#系统内置不能为空|系统内置类型只能为0或1"`
+	Remark      string `p:"remark"`
+}
+
+type ConfigAddReq struct {
+	g.Meta `path:"/config/add" tags:"系统参数管理" method:"post" summary:"添加系统参数"`
+	*ConfigReq
+}
+
+type ConfigAddRes struct {
+}
+
+type ConfigGetReq struct {
+	g.Meta `path:"/config/get" tags:"系统参数管理" method:"get" summary:"获取系统参数"`
+	Id     int `p:"id"`
+}
+
+type ConfigGetRes struct {
+	g.Meta `mime:"application/json"`
+	Data   *commonEntity.SysConfig `json:"data"`
+}
+
+type ConfigEditReq struct {
+	g.Meta   `path:"/config/edit" tags:"系统参数管理" method:"put" summary:"修改系统参数"`
+	ConfigId int64 `p:"configId" v:"required|min:1#主键ID不能为空|主键ID参数错误"`
+	*ConfigReq
+}
+
+type ConfigEditRes struct {
+}
+
+type ConfigDeleteReq struct {
+	g.Meta `path:"/config/delete" tags:"系统参数管理" method:"delete" summary:"删除系统参数"`
+	Ids    []int `p:"ids"`
+}
+
+type ConfigDeleteRes struct {
+}

+ 1 - 2
internal/app/common/model/entity/sys_config.go

@@ -1,5 +1,5 @@
 // =================================================================================
 // =================================================================================
-// Code generated by GoFrame CLI tool. DO NOT EDIT.
+// Code generated by GoFrame CLI tool. DO NOT EDIT. Created at 2022-04-18 21:09:17
 // =================================================================================
 // =================================================================================
 
 
 package entity
 package entity
@@ -20,5 +20,4 @@ type SysConfig struct {
 	Remark      string      `json:"remark"      description:"备注"`
 	Remark      string      `json:"remark"      description:"备注"`
 	CreatedAt   *gtime.Time `json:"createdAt"   description:"创建时间"`
 	CreatedAt   *gtime.Time `json:"createdAt"   description:"创建时间"`
 	UpdatedAt   *gtime.Time `json:"updatedAt"   description:"修改时间"`
 	UpdatedAt   *gtime.Time `json:"updatedAt"   description:"修改时间"`
-	DeletedAt   *gtime.Time `json:"deletedAt"   description:"删除时间"`
 }
 }

+ 1 - 3
internal/app/common/service/internal/dao/internal/sys_config.go

@@ -1,5 +1,5 @@
 // ==========================================================================
 // ==========================================================================
-// Code generated by GoFrame CLI tool. DO NOT EDIT.
+// Code generated by GoFrame CLI tool. DO NOT EDIT. Created at 2022-04-18 21:09:17
 // ==========================================================================
 // ==========================================================================
 
 
 package internal
 package internal
@@ -29,7 +29,6 @@ type SysConfigColumns struct {
 	Remark      string // 备注
 	Remark      string // 备注
 	CreatedAt   string // 创建时间
 	CreatedAt   string // 创建时间
 	UpdatedAt   string // 修改时间
 	UpdatedAt   string // 修改时间
-	DeletedAt   string // 删除时间
 }
 }
 
 
 //  sysConfigColumns holds the columns for table sys_config.
 //  sysConfigColumns holds the columns for table sys_config.
@@ -44,7 +43,6 @@ var sysConfigColumns = SysConfigColumns{
 	Remark:      "remark",
 	Remark:      "remark",
 	CreatedAt:   "created_at",
 	CreatedAt:   "created_at",
 	UpdatedAt:   "updated_at",
 	UpdatedAt:   "updated_at",
-	DeletedAt:   "deleted_at",
 }
 }
 
 
 // NewSysConfigDao creates and returns a new DAO object for table data access.
 // NewSysConfigDao creates and returns a new DAO object for table data access.

+ 1 - 2
internal/app/common/service/internal/do/sys_config.go

@@ -1,5 +1,5 @@
 // =================================================================================
 // =================================================================================
-// Code generated by GoFrame CLI tool. DO NOT EDIT.
+// Code generated by GoFrame CLI tool. DO NOT EDIT. Created at 2022-04-18 21:09:17
 // =================================================================================
 // =================================================================================
 
 
 package do
 package do
@@ -22,5 +22,4 @@ type SysConfig struct {
 	Remark      interface{} // 备注
 	Remark      interface{} // 备注
 	CreatedAt   *gtime.Time // 创建时间
 	CreatedAt   *gtime.Time // 创建时间
 	UpdatedAt   *gtime.Time // 修改时间
 	UpdatedAt   *gtime.Time // 修改时间
-	DeletedAt   *gtime.Time // 删除时间
 }
 }

+ 143 - 1
internal/app/common/service/sys_config.go

@@ -1,8 +1,150 @@
 /*
 /*
-* @desc:xxxx功能描述
+* @desc:系统参数配置
 * @company:云南奇讯科技有限公司
 * @company:云南奇讯科技有限公司
 * @Author: yixiaohu<yxh669@qq.com>
 * @Author: yixiaohu<yxh669@qq.com>
 * @Date:   2022/3/18 11:55
 * @Date:   2022/3/18 11:55
  */
  */
 
 
 package service
 package service
+
+import (
+	"context"
+	"errors"
+	"github.com/gogf/gf/v2/frame/g"
+	"github.com/gogf/gf/v2/util/gconv"
+	"github.com/tiger1103/gfast/v3/api/v1/system"
+	"github.com/tiger1103/gfast/v3/internal/app/common/consts"
+	"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"
+	systemConsts "github.com/tiger1103/gfast/v3/internal/app/system/consts"
+	"github.com/tiger1103/gfast/v3/library/liberr"
+)
+
+type IConfig interface {
+	List(ctx context.Context, req *system.ConfigSearchReq) (res *system.ConfigSearchRes, err error)
+	Add(ctx context.Context, req *system.ConfigAddReq, userId uint64) (err error)
+	Get(ctx context.Context, id int) (res *system.ConfigGetRes, err error)
+	Edit(ctx context.Context, req *system.ConfigEditReq, userId uint64) (err error)
+	Delete(ctx context.Context, ids []int) (err error)
+}
+
+type configTmpl struct {
+}
+
+var configService = configTmpl{}
+
+func Config() IConfig {
+	return IConfig(&configService)
+}
+
+// List 系统参数列表
+func (s *configTmpl) List(ctx context.Context, req *system.ConfigSearchReq) (res *system.ConfigSearchRes, err error) {
+	res = new(system.ConfigSearchRes)
+	err = g.Try(func() {
+		m := dao.SysConfig.Ctx(ctx)
+		if req != nil {
+			if req.ConfigName != "" {
+				m = m.Where("config_name like ?", "%"+req.ConfigName+"%")
+			}
+			if req.ConfigType != "" {
+				m = m.Where("config_type = ", gconv.Int(req.ConfigType))
+			}
+			if req.ConfigKey != "" {
+				m = m.Where("config_key like ?", "%"+req.ConfigKey+"%")
+			}
+			if len(req.DateRange) > 0 {
+				m = m.Where("create_time >= ? AND create_time<=?", req.DateRange[0], req.DateRange[1])
+			}
+		}
+		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 = systemConsts.PageSize
+		}
+		err = m.Page(req.PageNum, req.PageSize).Order("config_id asc").Scan(&res.List)
+		liberr.ErrIsNil(ctx, err, "获取数据失败")
+	})
+	return
+}
+
+func (s *configTmpl) Add(ctx context.Context, req *system.ConfigAddReq, userId uint64) (err error) {
+	err = g.Try(func() {
+		err = s.CheckConfigKeyUnique(ctx, req.ConfigKey)
+		liberr.ErrIsNil(ctx, err)
+		_, err = dao.SysConfig.Ctx(ctx).Insert(do.SysConfig{
+			ConfigName:  req.ConfigName,
+			ConfigKey:   req.ConfigKey,
+			ConfigValue: req.ConfigValue,
+			ConfigType:  req.ConfigType,
+			CreateBy:    userId,
+			Remark:      req.Remark,
+		})
+		liberr.ErrIsNil(ctx, err, "添加系统参数失败")
+		//清除缓存
+		Cache().RemoveByTag(ctx, consts.CacheSysConfigTag)
+	})
+	return
+}
+
+// CheckConfigKeyUnique 验证参数键名是否存在
+func (s *configTmpl) CheckConfigKeyUnique(ctx context.Context, configKey string, configId ...int64) (err error) {
+	err = g.Try(func() {
+		data := (*entity.SysConfig)(nil)
+		m := dao.SysConfig.Ctx(ctx).Fields(dao.SysConfig.Columns().ConfigId).Where(dao.SysConfig.Columns().ConfigKey, configKey)
+		if len(configId) > 0 {
+			m = m.Where(dao.SysConfig.Columns().ConfigId+" != ?", configId[0])
+		}
+		err = m.Scan(&data)
+		liberr.ErrIsNil(ctx, err, "校验失败")
+		if data != nil {
+			liberr.ErrIsNil(ctx, errors.New("参数键名重复"))
+		}
+	})
+	return nil
+}
+
+// Get 获取系统参数
+func (s *configTmpl) Get(ctx context.Context, id int) (res *system.ConfigGetRes, err error) {
+	res = new(system.ConfigGetRes)
+	err = g.Try(func() {
+		err = dao.SysConfig.Ctx(ctx).WherePri(id).Scan(&res.Data)
+		liberr.ErrIsNil(ctx, err, "获取系统参数失败")
+	})
+	return
+}
+
+// Edit 修改系统参数
+func (s *configTmpl) Edit(ctx context.Context, req *system.ConfigEditReq, userId uint64) (err error) {
+	err = g.Try(func() {
+		err = s.CheckConfigKeyUnique(ctx, req.ConfigKey, req.ConfigId)
+		liberr.ErrIsNil(ctx, err)
+		_, err = dao.SysConfig.Ctx(ctx).WherePri(req.ConfigId).Update(do.SysConfig{
+			ConfigName:  req.ConfigName,
+			ConfigKey:   req.ConfigKey,
+			ConfigValue: req.ConfigValue,
+			ConfigType:  req.ConfigType,
+			UpdateBy:    userId,
+			Remark:      req.Remark,
+		})
+		liberr.ErrIsNil(ctx, err, "修改系统参数失败")
+		//清除缓存
+		Cache().RemoveByTag(ctx, consts.CacheSysConfigTag)
+	})
+	return
+}
+
+// Delete 删除系统参数
+func (s *configTmpl) Delete(ctx context.Context, ids []int) (err error) {
+	err = g.Try(func() {
+		_, err = dao.SysConfig.Ctx(ctx).Delete(dao.SysConfig.Columns().ConfigId+" in (?)", ids)
+		liberr.ErrIsNil(ctx, err, "删除失败")
+		//清除缓存
+		Cache().RemoveByTag(ctx, consts.CacheSysConfigTag)
+	})
+	return
+}

+ 51 - 0
internal/app/system/controller/sys_config.go

@@ -0,0 +1,51 @@
+/*
+* @desc:系统参数配置
+* @company:云南奇讯科技有限公司
+* @Author: yixiaohu
+* @Date:   2022/4/18 21:17
+ */
+
+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 Config = configController{}
+
+type configController struct {
+	BaseController
+}
+
+// List 系统参数列表
+func (c *configController) List(ctx context.Context, req *system.ConfigSearchReq) (res *system.ConfigSearchRes, err error) {
+	res, err = commonService.Config().List(ctx, req)
+	return
+}
+
+// Add 添加系统参数
+func (c *configController) Add(ctx context.Context, req *system.ConfigAddReq) (res *system.ConfigAddRes, err error) {
+	err = commonService.Config().Add(ctx, req, service.Context().GetUserId(ctx))
+	return
+}
+
+// Get 获取系统参数
+func (c *configController) Get(ctx context.Context, req *system.ConfigGetReq) (res *system.ConfigGetRes, err error) {
+	res, err = commonService.Config().Get(ctx, req.Id)
+	return
+}
+
+// Edit 修改系统参数
+func (c *configController) Edit(ctx context.Context, req *system.ConfigEditReq) (res *system.ConfigEditRes, err error) {
+	err = commonService.Config().Edit(ctx, req, service.Context().GetUserId(ctx))
+	return
+}
+
+// Delete 删除系统参数
+func (c *configController) Delete(ctx context.Context, req *system.ConfigDeleteReq) (res *system.ConfigDeleteRes, err error) {
+	err = commonService.Config().Delete(ctx, req.Ids)
+	return
+}

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

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