From 1907780873d4401afae6b8b7a8b2af12fba10f84 Mon Sep 17 00:00:00 2001 From: wucongxing8150 <815046773@qq.com> Date: Wed, 21 Aug 2024 13:14:11 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=B0=E5=A2=9E=E8=8E=B7=E5=8F=96=E6=B0=91?= =?UTF-8?q?=E6=97=8F=E5=88=97=E8=A1=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- api/controller/Basic.go | 21 +++++++++++++++++++++ api/dto/BaseNation.go | 38 ++++++++++++++++++++++++++++++++++++++ api/router/router.go | 7 +++++++ 3 files changed, 66 insertions(+) create mode 100644 api/dto/BaseNation.go diff --git a/api/controller/Basic.go b/api/controller/Basic.go index 58c5cbb..bb742cb 100644 --- a/api/controller/Basic.go +++ b/api/controller/Basic.go @@ -162,3 +162,24 @@ func (r *Basic) GetDiseaseList(c *gin.Context) { responses.OkWithData(g, c) } + +// GetNationList 获取民族列表 +func (r *Basic) GetNationList(c *gin.Context) { + // 获取分类数据 + baseNationDao := dao.BaseNationDao{} + maps := make(map[string]interface{}) + baseNations, err := baseNationDao.GetBaseNationList(maps) + if err != nil { + responses.FailWithMessage(err.Error(), c) + return + } + + // 处理返回值 + g := dto.GetBaseNationListDto(baseNations) + if err != nil { + responses.FailWithMessage(err.Error(), c) + return + } + + responses.OkWithData(g, c) +} diff --git a/api/dto/BaseNation.go b/api/dto/BaseNation.go new file mode 100644 index 0000000..4bc76f9 --- /dev/null +++ b/api/dto/BaseNation.go @@ -0,0 +1,38 @@ +package dto + +import ( + "fmt" + "hepa-calc-api/api/model" +) + +// BaseNationDto 基础数据-民族 +type BaseNationDto struct { + NationId string `json:"nation_id"` // 主键id + AppIden string `json:"app_iden"` // app唯一标识 + NationName string `json:"nation_name"` // 民族名称 + CreatedAt model.LocalTime `json:"created_at"` // 创建时间 + UpdatedAt model.LocalTime `json:"updated_at"` // 更新时间 +} + +// GetBaseNationListDto 列表-基础数据-分类表 +func GetBaseNationListDto(m []*model.BaseNation) []*BaseNationDto { + // 处理返回值 + responses := make([]*BaseNationDto, len(m)) + + if len(m) > 0 { + for i, v := range m { + response := &BaseNationDto{ + NationId: fmt.Sprintf("%d", v.NationId), + AppIden: v.AppIden, + NationName: v.NationName, + CreatedAt: v.CreatedAt, + UpdatedAt: v.UpdatedAt, + } + + // 将转换后的结构体添加到新切片中 + responses[i] = response + } + } + + return responses +} diff --git a/api/router/router.go b/api/router/router.go index 8839804..3ea3114 100644 --- a/api/router/router.go +++ b/api/router/router.go @@ -174,6 +174,13 @@ func basicRouter(r *gin.Engine, api controller.Api) { // 获取疾病分类列表 diseaseGroup.GET("/list", api.Basic.GetDiseaseList) } + + // 民族 + nationGroup := r.Group("/nation") + { + // 获取民族列表 + nationGroup.GET("/list", api.Basic.GetNationList) + } } // privateRouter 私有路由-验证权限