package controller import ( "gas-cylinder-api/app/admin/model" "gas-cylinder-api/app/admin/service" "gas-cylinder-api/app/admin/service/dto" "gas-cylinder-api/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 GasCylinderSpecController struct { api.Api } // GetPage 获取钢瓶规格列表 // @Summary 获取钢瓶规格列表 // @Description 获取钢瓶规格列表 // @Tags 钢瓶规格 // @Param name query string false "钢瓶规格名称" // @Success 200 {object} response.Response{data=response.Page{list=[]model.GasCylinderSpec}} "{"code": 200, "data": [...]}" // @Router /api/dispatch-cost [get] // @Security Bearer func (e GasCylinderSpecController) GetPage(c *gin.Context) { s := service.GasCylinderSpec{} req := dto.GasCylinderSpecGetPageReq{} 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 } //数据权限检查 p := actions.GetPermissionFromContext(c) list := make([]model.GasCylinderSpec, 0) var count int64 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 string true "钢瓶规格id" // @Success 200 {object} response.Response{data=model.GasCylinderSpec} "{"code": 200, "data": [...]}" // @Router /api/dispatch-cost/{id} [get] // @Security Bearer func (e GasCylinderSpecController) Get(c *gin.Context) { s := service.GasCylinderSpec{} req := dto.GasCylinderSpecGetReq{} 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.GasCylinderSpec 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.GasCylinderSpecInsertReq true "data" // @Param pageSize query int false "页条数" // @Param page query int false "页码" // @Success 200 {string} string "{"code": 200, "message": "添加成功"}" // @Success 200 {string} string "{"code": -1, "message": "添加失败"}" // @Router /api/dispatch-cost [post] // @Security Bearer func (e GasCylinderSpecController) Insert(c *gin.Context) { s := service.GasCylinderSpec{} req := dto.GasCylinderSpecInsertReq{} 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 } p := actions.GetPermissionFromContext(c) // 设置创建人 req.SetCreateBy(user.GetUserId(c)) req.SetDeptId(p.DeptId) 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.GasCylinderSpecUpdateReq true "body" // @Success 200 {string} string "{"code": 200, "message": "添加成功"}" // @Success 200 {string} string "{"code": -1, "message": "添加失败"}" // @Router /api/dispatch-cost [put] // @Security Bearer func (e GasCylinderSpecController) Update(c *gin.Context) { s := service.GasCylinderSpec{} req := dto.GasCylinderSpecUpdateReq{} err := e.MakeContext(c). MakeOrm(). Bind(&req). MakeService(&s.Service). Errors if err != nil { e.Logger.Error(err) e.Error(500, err, err.Error()) return } p := actions.GetPermissionFromContext(c) req.SetUpdateBy(user.GetUserId(c)) err = s.Update(&req, p) 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 data body dto.GasCylinderSpecDeleteReq true "body" // @Success 200 {string} string "{"code": 200, "message": "删除成功"}" // @Success 200 {string} string "{"code": -1, "message": "删除失败"}" // @Router /api/dispatch-cost [delete] // @Security Bearer func (e GasCylinderSpecController) Delete(c *gin.Context) { s := service.GasCylinderSpec{} req := dto.GasCylinderSpecDeleteReq{} userSvc := service.SysUser{} err := e.MakeContext(c). MakeOrm(). Bind(&req, binding.JSON, nil). MakeService(&s.Service). MakeService(&userSvc.Service). Errors if err != nil { e.Logger.Error(err) e.Error(500, err, err.Error()) return } //数据权限检查 p := actions.GetPermissionFromContext(c) err = s.Remove(&req, p) if err != nil { e.Error(500, err, err.Error()) return } e.OK(req.GetId(), "删除成功") }