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 SysDictDataController struct { api.Api } // GetPage 获取字典数据列表 // @Summary 获取字典数据列表 // @Description 获取字典数据列表 // @Tags 字典数据 // @Param status query string false "status" // @Param dictCode query string false "dictCode" // @Param dictType query string false "dictType" // @Param pageSize query int false "页条数" // @Param pageIndex query int false "页码" // @Success 200 {object} response.Response{data=response.Page{list=[]model.SysDictData}} "{"code": 200, "data": [...]}" // @Router /api/dict/data [get] // @Security Bearer func (e SysDictDataController) GetPage(c *gin.Context) { s := service.SysDictDataService{} req := dto.SysDictDataGetPageReq{} 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.SysDictData, 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 通过id获取字典数据 // @Summary 通过id获取字典数据 // @Description 通过id获取字典数据 // @Tags 字典数据 // @Param dictCode path int true "字典编码" // @Success 200 {object} response.Response{data=model.SysDictData} "{"code": 200, "data": [...]}" // @Router /api/dict/data/{dictCode} [get] // @Security Bearer func (e SysDictDataController) Get(c *gin.Context) { s := service.SysDictDataService{} req := dto.SysDictDataGetReq{} 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 } var object model.SysDictData err = s.Get(&req, &object) if err != nil { e.Logger.Warnf("Get error: %s", err.Error()) e.Error(500, err, err.Error()) return } e.OK(object, "查询成功") } // Insert 添加字典数据 // @Summary 添加字典数据 // @Description 添加字典数据 // @Tags 字典数据 // @Accept application/json // @Product application/json // @Param data body dto.SysDictDataInsertReq true "data" // @Success 200 {object} response.Response "{"code": 200, "message": "添加成功"}" // @Router /api/dict/data [post] // @Security Bearer func (e SysDictDataController) Insert(c *gin.Context) { s := service.SysDictDataService{} req := dto.SysDictDataInsertReq{} 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 dictCode path int true "字典编码" // @Param data body dto.SysDictDataUpdateReq true "body" // @Success 200 {object} response.Response "{"code": 200, "message": "修改成功"}" // @Router /api/dict/data/{dictCode} [put] // @Security Bearer func (e SysDictDataController) Update(c *gin.Context) { s := service.SysDictDataService{} req := dto.SysDictDataUpdateReq{} 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.Update(&req) if err != nil { e.Error(500, err, err.Error()) return } e.OK(req.GetId(), "更新成功") } // Delete 删除字典数据 // @Summary 删除字典数据 // @Description 删除字典数据 // @Tags 字典数据 // @Param dictCode body dto.SysDictDataDeleteReq true "body" // @Success 200 {object} response.Response "{"code": 200, "message": "删除成功"}" // @Router /api/dict/data [delete] // @Security Bearer func (e SysDictDataController) Delete(c *gin.Context) { s := service.SysDictDataService{} req := dto.SysDictDataDeleteReq{} 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(), "删除成功") } // GetAll 通过key获取数据字典【业务页面使用】 // @Summary 通过key获取数据字典【业务页面使用】 // @Description 通过key获取数据字典【业务页面使用】 // @Tags 字典数据 // @Param dictType query string true "dictType" // @Success 200 {object} response.Response{data=[]dto.SysDictDataGetAllResp} "{"code": 200, "data": [...]}" // @Router /api/dict-data/option-select [get] // @Security Bearer func (e SysDictDataController) GetAll(c *gin.Context) { s := service.SysDictDataService{} req := dto.SysDictDataGetPageReq{} err := e.MakeContext(c). MakeOrm(). Bind(&req, binding.Query). MakeService(&s.Service). Errors if err != nil { e.Logger.Error(err) e.Error(500, err, err.Error()) return } list := make([]model.SysDictData, 0) err = s.GetAll(&req, &list) if err != nil { e.Error(500, err, err.Error()) return } l := make([]dto.SysDictDataGetAllResp, 0) for _, i := range list { d := dto.SysDictDataGetAllResp{} e.Translate(i, &d) l = append(l, d) } e.OK(l, "查询成功") }