123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159 |
- 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 DosageFormController struct {
- BaseController
- }
- // List 获取剂型列表
- // @Summary 获取剂型列表
- // @Description 获取剂型列表
- // @Tags 剂型
- // @Param body body dto.DosageFormPageReq true "body"
- // @Success 200 {object} response.Page{list=[]models.DosageForm} "{"code": 200, "data": [...]}"
- // @Router /dosage-form/list [post]
- // @Security Bearer
- func (c DosageFormController) List() {
- s := services.DosageForm{}
- reqData := dto.DosageFormPageReq{}
- 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.DosageForm, 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.DosageFormGetReq true "body"
- // @Success 200 {object} response.Response{data=models.DosageForm} "{"code": 200, "data": [...]}"
- // @Router /dosage-form/detail [post]
- // @Security Bearer
- func (c DosageFormController) Detail() {
- s := services.DosageForm{}
- reqData := dto.DosageFormGetReq{}
- 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.DosageForm
- //数据权限检查
- 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
- // @DosageForm application/json
- // @Param data body dto.DosageFormInsertReq true "data"
- // @Success 200 {object} response.Response "{"code": 200, "data": [...]}"
- // @Router /dosage-form/add [post]
- // @Security Bearer
- func (c DosageFormController) Add() {
- s := services.DosageForm{}
- reqData := dto.DosageFormInsertReq{}
- 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
- // @DosageForm application/json
- // @Param data body dto.DosageFormUpdateReq true "body"
- // @Success 200 {object} response.Response "{"code": 200, "data": [...]}"
- // @Router /dosage-form/edit [post]
- // @Security Bearer
- func (c DosageFormController) Edit() {
- s := services.DosageForm{}
- reqData := dto.DosageFormUpdateReq{}
- 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))
- 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
- // @DosageForm application/json
- // @Param id body dto.DosageFormDeleteReq true "请求参数"
- // @Success 200 {object} response.Response "{"code": 200, "data": [...]}"
- // @Router /dosage-form/delete [post]
- // @Security Bearer
- func (c DosageFormController) Delete() {
- s := services.DosageForm{}
- reqData := dto.DosageFormDeleteReq{}
- 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(), "删除成功")
- }
|