123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221 |
- 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, "查询成功")
- }
|