From fade9ea4a7299ea1336f05d233006ef91182f3e5 Mon Sep 17 00:00:00 2001 From: wucongxing <815046773@qq.com> Date: Tue, 11 Jul 2023 13:11:28 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=B0=E5=A2=9E=E4=B8=93=E9=95=BF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- api/controller/base.go | 5 +- api/controller/department.go | 23 +-------- api/controller/diseaseClassExpertise.go | 41 ++++++++++++++++ api/dao/diseaseClassExpertise.go | 20 ++++++++ api/requests/expertise.go | 11 +++++ .../diseaseClassExpertise.go | 49 +++++++++++++++++++ api/router/router.go | 15 ++++++ 7 files changed, 140 insertions(+), 24 deletions(-) create mode 100644 api/controller/diseaseClassExpertise.go create mode 100644 api/requests/expertise.go create mode 100644 api/responses/diseaseClassExpertiseResponse/diseaseClassExpertise.go diff --git a/api/controller/base.go b/api/controller/base.go index a7ae2db..d8919a7 100644 --- a/api/controller/base.go +++ b/api/controller/base.go @@ -25,6 +25,7 @@ type userDoctorManage struct { // Basic 基础数据 type basic struct { - Department // 科室管理 - Hospital // 医院管理 + Department // 科室管理 + Hospital // 医院管理 + DiseaseClassExpertise // 专长管理 } diff --git a/api/controller/department.go b/api/controller/department.go index 668d6ce..151d780 100644 --- a/api/controller/department.go +++ b/api/controller/department.go @@ -29,28 +29,7 @@ func (b *Department) GetDepartmentCustomList(c *gin.Context) { hospitalDepartmentCustomDao := dao.HospitalDepartmentCustom{} - maps := make(map[string]interface{}) - if departmentRequest.DepartmentId != "" { - maps["department_id"] = departmentRequest.DepartmentId - } - - if departmentRequest.DepartmentCustomName != "" { - maps["department_custom_name"] = departmentRequest.DepartmentCustomName - } - - if departmentRequest.DepartmentName != "" { - maps["department_name"] = departmentRequest.DepartmentName - } - - if departmentRequest.DepartmentCode != "" { - maps["department_code"] = departmentRequest.DepartmentCode - } - - if departmentRequest.DepartmentStatus != 0 { - maps["department_status"] = departmentRequest.DepartmentStatus - } - - hospitalDepartmentCustom, err := hospitalDepartmentCustomDao.GetHospitalDepartmentCustomList(maps) + hospitalDepartmentCustom, err := hospitalDepartmentCustomDao.GetHospitalDepartmentCustomListByMaps(departmentRequest.GetDepartmentCustomList) if err != nil { responses.Ok(c) return diff --git a/api/controller/diseaseClassExpertise.go b/api/controller/diseaseClassExpertise.go new file mode 100644 index 0000000..2a264e2 --- /dev/null +++ b/api/controller/diseaseClassExpertise.go @@ -0,0 +1,41 @@ +// Package controller 专长 +package controller + +import ( + "github.com/gin-gonic/gin" + "hospital-admin-api/api/dao" + "hospital-admin-api/api/requests" + "hospital-admin-api/api/responses" + "hospital-admin-api/api/responses/diseaseClassExpertiseResponse" + "hospital-admin-api/global" + "hospital-admin-api/utils" +) + +type DiseaseClassExpertise struct{} + +// GetExpertiseList 获取专长列表 +func (b *DiseaseClassExpertise) GetExpertiseList(c *gin.Context) { + expertiseRequest := requests.ExpertiseRequest{} + if err := c.ShouldBind(&expertiseRequest.GetExpertiseList); err != nil { + responses.FailWithMessage(err.Error(), c) + return + } + + // 参数验证 + if err := global.Validate.Struct(expertiseRequest.GetExpertiseList); err != nil { + responses.FailWithMessage(utils.Translate(err), c) + return + } + + diseaseClassExpertiseDao := dao.DiseaseClassExpertiseDao{} + + diseaseClassExpertises, err := diseaseClassExpertiseDao.GetDiseaseClassExpertiseListByMaps(expertiseRequest.GetExpertiseList) + if err != nil { + responses.Ok(c) + return + } + + // 处理返回值 + getDepartmentListResponse := diseaseClassExpertiseResponse.GetDiseaseClassExpertiseListResponse(diseaseClassExpertises) + responses.OkWithData(getDepartmentListResponse, c) +} diff --git a/api/dao/diseaseClassExpertise.go b/api/dao/diseaseClassExpertise.go index 91dff5a..59d8e40 100644 --- a/api/dao/diseaseClassExpertise.go +++ b/api/dao/diseaseClassExpertise.go @@ -3,6 +3,7 @@ package dao import ( "gorm.io/gorm" "hospital-admin-api/api/model" + "hospital-admin-api/api/requests" "hospital-admin-api/global" ) @@ -70,3 +71,22 @@ func (r *DiseaseClassExpertiseDao) AddDiseaseClassExpertiseByMap(tx *gorm.DB, da } return userDoctorInfo, nil } + +// GetDiseaseClassExpertiseListByMaps 获取专长列表 +func (r *DiseaseClassExpertiseDao) GetDiseaseClassExpertiseListByMaps(expertiseRequest requests.GetExpertiseList) (m []*model.DiseaseClassExpertise, err error) { + result := global.Db + + if expertiseRequest.ExpertiseId != "" { + result = result.Where("expertise_id = ?", expertiseRequest.ExpertiseId) + } + + if expertiseRequest.ExpertiseName != "" { + result = result.Where("expertise_name like ?", "%"+expertiseRequest.ExpertiseName+"%") + } + + err = result.Find(&m).Error + if err != nil { + return nil, err + } + return m, nil +} diff --git a/api/requests/expertise.go b/api/requests/expertise.go new file mode 100644 index 0000000..ffd231b --- /dev/null +++ b/api/requests/expertise.go @@ -0,0 +1,11 @@ +package requests + +type ExpertiseRequest struct { + GetExpertiseList // 获取专长列表 +} + +// GetExpertiseList 获取专长列表 +type GetExpertiseList struct { + ExpertiseId string `json:"expertise_id" form:"expertise_id" label:"主键id"` + ExpertiseName string `json:"expertise_name" form:"expertise_name" label:"专长名称"` +} diff --git a/api/responses/diseaseClassExpertiseResponse/diseaseClassExpertise.go b/api/responses/diseaseClassExpertiseResponse/diseaseClassExpertise.go new file mode 100644 index 0000000..f9af6d2 --- /dev/null +++ b/api/responses/diseaseClassExpertiseResponse/diseaseClassExpertise.go @@ -0,0 +1,49 @@ +package diseaseClassExpertiseResponse + +import ( + "hospital-admin-api/api/model" + "strconv" +) + +type DiseaseClassExpertise struct { + ExpertiseId string `json:"expertise_id"` // 主键 + ExpertiseName string `json:"expertise_name"` // 专长名称 + ExpertiseSort int `json:"expertise_sort"` // 排序(越大排序越靠前) + CreatedAt model.LocalTime `json:"created_at"` // 创建时间 + UpdatedAt model.LocalTime `json:"updated_at"` // 修改时间 +} + +// DiseaseClassExpertiseResponse 专长详情 +func DiseaseClassExpertiseResponse(diseaseClassExpertise *model.DiseaseClassExpertise) *DiseaseClassExpertise { + return &DiseaseClassExpertise{ + ExpertiseId: strconv.FormatInt(diseaseClassExpertise.ExpertiseId, 10), + ExpertiseName: diseaseClassExpertise.ExpertiseName, + ExpertiseSort: diseaseClassExpertise.ExpertiseSort, + CreatedAt: diseaseClassExpertise.CreatedAt, + UpdatedAt: diseaseClassExpertise.UpdatedAt, + } +} + +// GetDiseaseClassExpertiseListResponse 自定义列表 +func GetDiseaseClassExpertiseListResponse(diseaseClassExpertises []*model.DiseaseClassExpertise) []DiseaseClassExpertise { + // 处理返回值 + getDiseaseClassExpertiseListResponses := make([]DiseaseClassExpertise, len(diseaseClassExpertises)) + + if len(diseaseClassExpertises) > 0 { + for i, v := range diseaseClassExpertises { + // 将原始结构体转换为新结构体 + getDiseaseClassExpertiseListResponse := DiseaseClassExpertise{ + ExpertiseId: strconv.FormatInt(v.ExpertiseId, 10), + ExpertiseName: v.ExpertiseName, + ExpertiseSort: v.ExpertiseSort, + CreatedAt: v.CreatedAt, + UpdatedAt: v.UpdatedAt, + } + + // 将转换后的结构体添加到新切片中 + getDiseaseClassExpertiseListResponses[i] = getDiseaseClassExpertiseListResponse + } + } + + return getDiseaseClassExpertiseListResponses +} diff --git a/api/router/router.go b/api/router/router.go index 143ead2..2c9185e 100644 --- a/api/router/router.go +++ b/api/router/router.go @@ -283,4 +283,19 @@ func privateRouter(r *gin.Engine, api controller.Api) { // 获取医院列表-限制条数 hospitalGroup.GET("/list", api.Hospital.GetHospitalLimit) } + + // 专长管理-基础数据 + expertiseGroup := adminGroup.Group("/expertise") + { + // 获取专长列表 + expertiseGroup.GET("/list", api.DiseaseClassExpertise.GetExpertiseList) + + // 获取专长列表-分页 + + // 专长详情 + + // 修改专长 + + // 新增专长 + } }