123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203 |
- package controller
- import (
- "Medical_OAuth/app/admin/model"
- "Medical_OAuth/app/admin/service"
- "Medical_OAuth/app/admin/service/dto"
- "Medical_OAuth/common/actions"
- "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/jwtauth/user"
- _ "gogs.baozhida.cn/zoie/OAuth-core/pkg/response"
- )
- type SysPostController struct {
- api.Api
- }
- // GetPage 获取岗位列表
- // @Summary 获取岗位列表
- // @Description 获取岗位列表
- // @Tags 岗位
- // @Param postName query string false "岗位名称"
- // @Param status query int false "状态 1-停用 2-正常"
- // @Param sort query int false "排序 ASC-升序 DESC-降序"
- // @Param pageSize query int false "页条数"
- // @Param pageIndex query int false "页码"
- // @Success 200 {object} response.Response{data=response.Page{list=[]model.SysPost}} "{"code": 200, "data": [...]}"
- // @Router /api/post [get]
- // @Security Bearer
- func (e SysPostController) GetPage(c *gin.Context) {
- s := service.SysPost{}
- req := dto.SysPostPageReq{}
- 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.SysPost, 0)
- var count int64
- //数据权限检查
- p := actions.GetPermissionFromContext(c)
- err = s.GetPage(&req, &list, &count, p)
- 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 id path int true "岗位id"
- // @Success 200 {object} response.Response{data=model.SysPost} "{"code": 200, "data": [...]}"
- // @Router /api/post/{id} [get]
- // @Security Bearer
- func (e SysPostController) Get(c *gin.Context) {
- s := service.SysPost{}
- req := dto.SysPostGetReq{}
- 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.SysPost
- //数据权限检查
- p := actions.GetPermissionFromContext(c)
- err = s.Get(&req, &object, p)
- 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.SysPostInsertReq true "data"
- // @Success 200 {object} response.Response "{"code": 200, "data": [...]}"
- // @Router /api/post [post]
- // @Security Bearer
- func (e SysPostController) Insert(c *gin.Context) {
- s := service.SysPost{}
- req := dto.SysPostInsertReq{}
- 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 id path int true "岗位id"
- // @Param data body dto.SysPostUpdateReq true "body"
- // @Success 200 {object} response.Response "{"code": 200, "data": [...]}"
- // @Router /api/post/{id} [put]
- // @Security Bearer
- func (e SysPostController) Update(c *gin.Context) {
- s := service.SysPost{}
- req := dto.SysPostUpdateReq{}
- 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 岗位
- // @Accept application/json
- // @Product application/json
- // @Param id body dto.SysPostDeleteReq true "请求参数"
- // @Success 200 {object} response.Response "{"code": 200, "data": [...]}"
- // @Router /api/post [delete]
- // @Security Bearer
- func (e SysPostController) Delete(c *gin.Context) {
- s := service.SysPost{}
- req := dto.SysPostDeleteReq{}
- userSvc := service.SysUser{}
- err := e.MakeContext(c).
- MakeOrm().
- Bind(&req, binding.JSON).
- MakeService(&s.Service).
- MakeService(&userSvc.Service).
- Errors
- if err != nil {
- e.Logger.Error(err)
- e.Error(500, err, err.Error())
- return
- }
- userReq := dto.SysUserGetCountReq{PostIds: req.Ids}
- var count int64
- err = userSvc.GetCount(&userReq, &count)
- if err != nil {
- e.Error(500, err, err.Error())
- return
- }
- if count > 0 {
- e.Error(500, err, "有用户关联,禁止删除!")
- return
- }
- req.SetUpdateBy(user.GetUserId(c))
- err = s.Remove(&req)
- if err != nil {
- e.Error(500, err, err.Error())
- return
- }
- e.OK(req.GetId(), "删除成功")
- }
|