123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315 |
- package controller
- import (
- "github.com/gin-gonic/gin"
- "github.com/gin-gonic/gin/binding"
- "gogs.baozhida.cn/zoie/OAuth-core/api"
- _ "gogs.baozhida.cn/zoie/OAuth-core/pkg/response"
- "Medical_OAuth/app/admin/model"
- "Medical_OAuth/app/admin/service"
- "Medical_OAuth/app/admin/service/dto"
- "gogs.baozhida.cn/zoie/OAuth-core/pkg/jwtauth/user"
- )
- type SysConfig struct {
- api.Api
- }
- // GetPage 获取配置管理列表
- // @Summary 获取配置管理列表
- // @Description 获取配置管理列表
- // @Tags 配置管理
- // @Param configName query string false "名称"
- // @Param configKey query string false "key"
- // @Param configType query string false "类型"
- // @Param isFrontend query int false "是否前端"
- // @Param pageSize query int false "页条数"
- // @Param pageIndex query int false "页码"
- // @Success 200 {object} response.Response{data=response.Page{list=[]model.SysConfig}} "{"code": 200, "data": [...]}"
- // @Router /api/sys-config [get]
- // @Security Bearer
- func (e SysConfig) GetPage(c *gin.Context) {
- s := service.SysConfig{}
- req := dto.SysConfigGetPageReq{}
- err := e.MakeContext(c).
- MakeOrm().
- Bind(&req, binding.Form).
- MakeService(&s.Service).
- Errors
- if err != nil {
- e.Logger.Error(err)
- e.Error(500, err, err.Error())
- return
- }
- list := make([]model.SysConfig, 0)
- var count int64
- err = s.GetPage(&req, &list, &count)
- if err != nil {
- e.Error(500, err, err.Error())
- return
- }
- e.PageOK(list, int(count), req.GetPageIndex(), req.GetPageSize(), "查询成功")
- }
- // Get 获取配置管理
- // @Summary 获取配置管理
- // @Description 获取配置管理
- // @Tags 配置管理
- // @Param id path string false "id"
- // @Success 200 {object} response.Response{data=model.SysConfig} "{"code": 200, "data": [...]}"
- // @Router /api/sys-config/{id} [get]
- // @Security Bearer
- func (e SysConfig) Get(c *gin.Context) {
- req := dto.SysConfigGetReq{}
- s := service.SysConfig{}
- err := e.MakeContext(c).
- MakeOrm().
- Bind(&req, binding.JSON, nil).
- MakeService(&s.Service).
- Errors
- if err != nil {
- e.Logger.Error(err)
- e.Error(500, err, err.Error())
- return
- }
- var object model.SysConfig
- err = s.Get(&req, &object)
- if err != nil {
- e.Error(500, err, err.Error())
- return
- }
- e.OK(object, "查询成功")
- }
- // Insert 创建配置管理
- // @Summary 创建配置管理
- // @Description 创建配置管理
- // @Tags 配置管理
- // @Accept application/json
- // @Product application/json
- // @Param data body dto.SysConfigControl true "body"
- // @Success 200 {object} response.Response "{"code": 200, "message": "创建成功"}"
- // @Router /api/sys-config [post]
- // @Security Bearer
- func (e SysConfig) Insert(c *gin.Context) {
- s := service.SysConfig{}
- req := dto.SysConfigControl{}
- err := e.MakeContext(c).
- MakeOrm().
- Bind(&req, binding.JSON).
- MakeService(&s.Service).
- Errors
- if err != nil {
- e.Logger.Error(err)
- e.Error(500, err, err.Error())
- return
- }
- req.SetCreateBy(user.GetUserId(c))
- err = s.Insert(&req)
- if err != nil {
- e.Error(500, err, err.Error())
- return
- }
- e.OK(req.GetId(), "创建成功")
- }
- // Update 修改配置管理
- // @Summary 修改配置管理
- // @Description 修改配置管理
- // @Tags 配置管理
- // @Accept application/json
- // @Product application/json
- // @Param data body dto.SysConfigControl true "body"
- // @Success 200 {object} response.Response "{"code": 200, "message": "修改成功"}"
- // @Router /api/sys-config/{id} [put]
- // @Security Bearer
- func (e SysConfig) Update(c *gin.Context) {
- s := service.SysConfig{}
- req := dto.SysConfigControl{}
- err := e.MakeContext(c).
- MakeOrm().
- Bind(&req, nil, binding.JSON).
- MakeService(&s.Service).
- Errors
- if err != nil {
- e.Logger.Error(err)
- e.Error(500, err, err.Error())
- return
- }
- req.SetUpdateBy(user.GetUserId(c))
- err = s.Update(&req)
- if err != nil {
- e.Error(500, err, err.Error())
- return
- }
- e.OK(req.GetId(), "更新成功")
- }
- // Delete 删除配置管理
- // @Summary 删除配置管理
- // @Description 删除配置管理
- // @Tags 配置管理
- // @Param ids body []int false "ids"
- // @Success 200 {object} response.Response "{"code": 200, "message": "删除成功"}"
- // @Router /api/sys-config [delete]
- // @Security Bearer
- func (e SysConfig) Delete(c *gin.Context) {
- s := service.SysConfig{}
- req := dto.SysConfigDeleteReq{}
- err := e.MakeContext(c).
- MakeOrm().
- Bind(&req, binding.JSON, nil).
- MakeService(&s.Service).
- Errors
- if err != nil {
- e.Logger.Error(err)
- e.Error(500, err, err.Error())
- return
- }
- req.SetUpdateBy(user.GetUserId(c))
- err = s.Remove(&req)
- if err != nil {
- e.Error(500, err, err.Error())
- return
- }
- e.OK(req.GetId(), "删除成功")
- }
- // Get2SysApp 获取系统配置信息
- // @Summary 获取系统前台配置信息,主要注意这里不在验证权限
- // @Description 获取系统配置信息,主要注意这里不在验证权限
- // @Tags 配置管理
- // @Success 200 {object} response.Response{data=map[string]string} "{"code": 200, "data": [...]}"
- // @Router /api/app-config [get]
- func (e SysConfig) Get2SysApp(c *gin.Context) {
- req := dto.SysConfigGetToSysAppReq{}
- s := service.SysConfig{}
- err := e.MakeContext(c).
- MakeOrm().
- Bind(&req, binding.Form).
- MakeService(&s.Service).
- Errors
- if err != nil {
- e.Logger.Error(err)
- return
- }
- // 控制只读前台的数据
- req.IsFrontend = "1"
- list := make([]model.SysConfig, 0)
- err = s.GetWithKeyList(&req, &list)
- if err != nil {
- e.Error(500, err, err.Error())
- return
- }
- mp := make(map[string]string)
- for i := 0; i < len(list); i++ {
- key := list[i].ConfigKey
- if key != "" {
- mp[key] = list[i].ConfigValue
- }
- }
- e.OK(mp, "查询成功")
- }
- // Get2Set 获取配置
- // @Summary 获取配置
- // @Description 界面操作设置配置值的获取
- // @Tags 配置管理
- // @Accept application/json
- // @Product application/json
- // @Success 200 {object} response.Response{data=map[string]interface{}} "{"code": 200, "message": "获取成功"}"
- // @Router /api/set-config [get]
- // @Security Bearer
- func (e SysConfig) Get2Set(c *gin.Context) {
- s := service.SysConfig{}
- req := make([]dto.GetSetSysConfigReq, 0)
- err := e.MakeContext(c).
- MakeOrm().
- MakeService(&s.Service).
- Errors
- if err != nil {
- e.Logger.Error(err)
- e.Error(500, err, err.Error())
- return
- }
- err = s.GetForSet(&req)
- if err != nil {
- e.Error(500, err, err.Error())
- return
- }
- m := make(map[string]interface{}, 0)
- for _, v := range req {
- m[v.ConfigKey] = v.ConfigValue
- }
- e.OK(m, "查询成功")
- }
- // Update2Set 设置配置
- // @Summary 设置配置
- // @Description 界面操作设置配置值
- // @Tags 配置管理
- // @Accept application/json
- // @Product application/json
- // @Param data body []dto.GetSetSysConfigReq true "body"
- // @Success 200 {object} response.Response "{"code": 200, "message": "修改成功"}"
- // @Router /api/set-config [put]
- // @Security Bearer
- func (e SysConfig) Update2Set(c *gin.Context) {
- s := service.SysConfig{}
- req := make([]dto.GetSetSysConfigReq, 0)
- err := e.MakeContext(c).
- MakeOrm().
- Bind(&req, binding.JSON).
- MakeService(&s.Service).
- Errors
- if err != nil {
- e.Logger.Error(err)
- e.Error(500, err, err.Error())
- return
- }
- err = s.UpdateForSet(&req)
- if err != nil {
- e.Error(500, err, err.Error())
- return
- }
- e.OK("", "更新成功")
- }
- // GetSysConfigByKEYForService 根据Key获取SysConfig的Service
- // @Summary 根据Key获取SysConfig的Service
- // @Description 根据Key获取SysConfig的Service
- // @Tags 配置管理
- // @Param configKey path string false "configKey"
- // @Success 200 {object} response.Response{data=dto.SysConfigByKeyReq} "{"code": 200, "data": [...]}"
- // @Router /api/configKey/{{configKey}} [get]
- // @Security Bearer
- func (e SysConfig) GetSysConfigByKEYForService(c *gin.Context) {
- s := service.SysConfig{}
- req := dto.SysConfigByKeyReq{}
- resp := dto.GetSysConfigByKEYForServiceResp{}
- err := e.MakeContext(c).
- MakeOrm().
- Bind(&req, nil).
- MakeService(&s.Service).
- Errors
- if err != nil {
- e.Logger.Error(err)
- e.Error(500, err, err.Error())
- return
- }
- err = s.GetWithKey(&req, &resp)
- if err != nil {
- e.Error(500, err, err.Error())
- return
- }
- e.OK(resp, s.Msg)
- }
|