123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160 |
- package controllers
- import (
- "Medical_ERP/common/actions"
- "Medical_ERP/common/global"
- _ "Medical_ERP/common/response"
- "Medical_ERP/dto"
- "Medical_ERP/models"
- "Medical_ERP/services"
- "errors"
- "gogs.baozhida.cn/zoie/OAuth-core/pkg/jwtauth/beegouser"
- )
- type SpecController struct {
- BaseController
- }
- // List 获取规格列表
- // @Summary 获取规格列表
- // @Description 获取规格列表
- // @Tags 规格
- // @Param body body dto.SpecPageReq true "body"
- // @Success 200 {object} response.Page{list=[]models.Spec} "{"code": 200, "data": [...]}"
- // @Router /spec/list [post]
- // @Security Bearer
- func (c SpecController) List() {
- s := services.Spec{}
- reqData := dto.SpecPageReq{}
- if err := c.ParseAndValidate(&c.Ctx.Input.RequestBody, &reqData); err != nil {
- err = errors.New("解析表单数据异常")
- c.Error(global.ParseFormErr, err, err.Error())
- return
- }
- list := make([]models.Spec, 0)
- var count int64
- //数据权限检查
- p := actions.GetPermissionFromContext(c.Ctx)
- err := s.GetPage(&reqData, &list, &count, p)
- if err != nil {
- c.Error(global.BadRequest, err, err.Error())
- return
- }
- c.PageOK(list, int(count), reqData.GetPageIndex(), reqData.GetPageSize(), "查询成功")
- }
- // Detail 通过id获取规格
- // @Summary 通过id获取规格
- // @Description 通过id获取规格
- // @Tags 规格
- // @Param body body dto.SpecGetReq true "body"
- // @Success 200 {object} response.Response{data=models.Spec} "{"code": 200, "data": [...]}"
- // @Router /spec/detail [post]
- // @Security Bearer
- func (c SpecController) Detail() {
- s := services.Spec{}
- reqData := dto.SpecGetReq{}
- if err := c.ParseAndValidate(&c.Ctx.Input.RequestBody, &reqData); err != nil {
- err = errors.New("解析表单数据异常")
- c.Error(global.ParseFormErr, err, err.Error())
- return
- }
- var object models.Spec
- //数据权限检查
- p := actions.GetPermissionFromContext(c.Ctx)
- err := s.Get(&reqData, &object, p)
- if err != nil {
- c.Error(500, err, err.Error())
- return
- }
- c.OK(object, "查询成功")
- }
- // Add 添加规格
- // @Summary 添加规格
- // @Description 添加规格
- // @Tags 规格
- // @Accept application/json
- // @Spec application/json
- // @Param data body dto.SpecInsertReq true "data"
- // @Success 200 {object} response.Response "{"code": 200, "data": [...]}"
- // @Router /spec/add [post]
- // @Security Bearer
- func (c SpecController) Add() {
- s := services.Spec{}
- reqData := dto.SpecInsertReq{}
- if err := c.ParseAndValidate(&c.Ctx.Input.RequestBody, &reqData); err != nil {
- err = errors.New("解析表单数据异常")
- c.Error(global.ParseFormErr, err, err.Error())
- return
- }
- reqData.SetCreateBy(beegouser.GetUserId(c.Ctx))
- reqData.SetDeptId(beegouser.GetDeptId(c.Ctx))
- err := s.Insert(&reqData)
- if err != nil {
- c.Error(500, err, err.Error())
- return
- }
- c.OK(reqData.GetId(), "创建成功")
- }
- // Edit 修改规格
- // @Summary 修改规格
- // @Description 修改规格
- // @Tags 规格
- // @Accept application/json
- // @Spec application/json
- // @Param data body dto.SpecUpdateReq true "body"
- // @Success 200 {object} response.Response "{"code": 200, "data": [...]}"
- // @Router /spec/edit [post]
- // @Security Bearer
- func (c SpecController) Edit() {
- s := services.Spec{}
- reqData := dto.SpecUpdateReq{}
- if err := c.ParseAndValidate(&c.Ctx.Input.RequestBody, &reqData); err != nil {
- err = errors.New("解析表单数据异常")
- c.Error(global.ParseFormErr, err, err.Error())
- return
- }
- reqData.SetUpdateBy(beegouser.GetUserId(c.Ctx))
- reqData.SetDeptId(beegouser.GetDeptId(c.Ctx))
- err := s.Update(&reqData)
- if err != nil {
- c.Error(500, err, err.Error())
- return
- }
- c.OK(reqData.GetId(), "更新成功")
- }
- // Delete 删除规格
- // @Summary 删除规格
- // @Description 删除规格
- // @Tags 规格
- // @Accept application/json
- // @Spec application/json
- // @Param id body dto.SpecDeleteReq true "请求参数"
- // @Success 200 {object} response.Response "{"code": 200, "data": [...]}"
- // @Router /spec/delete [post]
- // @Security Bearer
- func (c SpecController) Delete() {
- s := services.Spec{}
- reqData := dto.SpecDeleteReq{}
- if err := c.ParseAndValidate(&c.Ctx.Input.RequestBody, &reqData); err != nil {
- err = errors.New("解析表单数据异常")
- c.Error(global.ParseFormErr, err, err.Error())
- return
- }
- reqData.SetUpdateBy(beegouser.GetUserId(c.Ctx))
- reqData.SetDeptId(beegouser.GetDeptId(c.Ctx))
- err := s.Remove(&reqData)
- if err != nil {
- c.Error(500, err, err.Error())
- return
- }
- c.OK(reqData.GetId(), "删除成功")
- }
|