123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184 |
- package apis
- import (
- "fmt"
-
- "github.com/gin-gonic/gin"
- "github.com/gin-gonic/gin/binding"
- "github.com/go-admin-team/go-admin-core/sdk/api"
- "github.com/go-admin-team/go-admin-core/sdk/pkg/jwtauth/user"
- _ "github.com/go-admin-team/go-admin-core/sdk/pkg/response"
- "go-admin/app/admin/models"
- "go-admin/app/admin/service"
- "go-admin/app/admin/service/dto"
- )
- type SysPost struct {
- api.Api
- }
- // GetPage
- // @Summary 岗位列表数据
- // @Description 获取JSON
- // @Tags 岗位
- // @Param postName query string false "postName"
- // @Param postCode query string false "postCode"
- // @Param postId query string false "postId"
- // @Param status query string false "status"
- // @Success 200 {object} response.Response "{"code": 200, "data": [...]}"
- // @Router /api/v1/post [get]
- // @Security Bearer
- func (e SysPost) 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([]models.SysPost, 0)
- var count int64
- err = s.GetPage(&req, &list, &count)
- if err != nil {
- e.Error(500, err, "查询失败")
- return
- }
- e.PageOK(list, int(count), req.GetPageIndex(), req.GetPageSize(), "查询成功")
- }
- // Get
- // @Summary 获取岗位信息
- // @Description 获取JSON
- // @Tags 岗位
- // @Param id path int true "编码"
- // @Success 200 {object} response.Response "{"code": 200, "data": [...]}"
- // @Router /api/v1/post/{postId} [get]
- // @Security Bearer
- func (e SysPost) 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 models.SysPost
- err = s.Get(&req, &object)
- if err != nil {
- e.Error(500, err, fmt.Sprintf("岗位信息获取失败!错误详情:%s", err.Error()))
- return
- }
- e.OK(object, "查询成功")
- }
- // Insert
- // @Summary 添加岗位
- // @Description 获取JSON
- // @Tags 岗位
- // @Accept application/json
- // @Product application/json
- // @Param data body dto.SysPostInsertReq true "data"
- // @Success 200 {object} response.Response "{"code": 200, "data": [...]}"
- // @Router /api/v1/post [post]
- // @Security Bearer
- func (e SysPost) 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, fmt.Sprintf("新建岗位失败!错误详情:%s", err.Error()))
- return
- }
- e.OK(req.GetId(), "创建成功")
- }
- // Update
- // @Summary 修改岗位
- // @Description 获取JSON
- // @Tags 岗位
- // @Accept application/json
- // @Product application/json
- // @Param data body dto.SysPostUpdateReq true "body"
- // @Success 200 {object} response.Response "{"code": 200, "data": [...]}"
- // @Router /api/v1/post/{id} [put]
- // @Security Bearer
- func (e SysPost) 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, fmt.Sprintf("岗位更新失败!错误详情:%s", err.Error()))
- return
- }
- e.OK(req.GetId(), "更新成功")
- }
- // Delete
- // @Summary 删除岗位
- // @Description 删除数据
- // @Tags 岗位
- // @Param id body dto.SysPostDeleteReq true "请求参数"
- // @Success 200 {object} response.Response "{"code": 200, "data": [...]}"
- // @Router /api/v1/post [delete]
- // @Security Bearer
- func (e SysPost) Delete(c *gin.Context) {
- s := service.SysPost{}
- req :=dto.SysPostDeleteReq{}
- 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.SetUpdateBy(user.GetUserId(c))
- err = s.Remove(&req)
- if err != nil {
- e.Error(500, err, fmt.Sprintf("岗位删除失败!错误详情:%s", err.Error()))
- return
- }
- e.OK(req.GetId(), "删除成功")
- }
|