新增了医院管理
This commit is contained in:
parent
62473de7fc
commit
f6d6417acf
112
api/controller/area.go
Normal file
112
api/controller/area.go
Normal file
@ -0,0 +1,112 @@
|
|||||||
|
package controller
|
||||||
|
|
||||||
|
import (
|
||||||
|
"github.com/gin-gonic/gin"
|
||||||
|
"hospital-admin-api/api/dao"
|
||||||
|
"hospital-admin-api/api/dto"
|
||||||
|
"hospital-admin-api/api/requests"
|
||||||
|
"hospital-admin-api/api/responses"
|
||||||
|
"hospital-admin-api/api/service"
|
||||||
|
"hospital-admin-api/global"
|
||||||
|
"hospital-admin-api/utils"
|
||||||
|
"strconv"
|
||||||
|
)
|
||||||
|
|
||||||
|
type Area struct{}
|
||||||
|
|
||||||
|
// GetAreaList 获取地区列表
|
||||||
|
func (b *Area) GetAreaList(c *gin.Context) {
|
||||||
|
areaRequest := requests.AreaRequest{}
|
||||||
|
req := areaRequest.GetAreaList
|
||||||
|
if err := c.ShouldBind(&req); err != nil {
|
||||||
|
responses.FailWithMessage(err.Error(), c)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// 参数验证
|
||||||
|
if err := global.Validate.Struct(req); err != nil {
|
||||||
|
responses.FailWithMessage(utils.Translate(err), c)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// 处理参数
|
||||||
|
if req.ParentId == "" && req.AreaId == "" && req.AreaName == "" {
|
||||||
|
req.ParentId = "1"
|
||||||
|
req.AreaType = 2
|
||||||
|
}
|
||||||
|
|
||||||
|
areaDao := dao.AreaDao{}
|
||||||
|
area, err := areaDao.GetAreaListByStruct(req)
|
||||||
|
if err != nil {
|
||||||
|
responses.Ok(c)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// 处理返回值
|
||||||
|
r := dto.GetAreaListDto(area)
|
||||||
|
responses.OkWithData(r, c)
|
||||||
|
}
|
||||||
|
|
||||||
|
// AddArea 新增地区
|
||||||
|
func (r *Area) AddArea(c *gin.Context) {
|
||||||
|
areaRequest := requests.AreaRequest{}
|
||||||
|
req := areaRequest.AddArea
|
||||||
|
if err := c.ShouldBindJSON(&req); err != nil {
|
||||||
|
responses.FailWithMessage(err.Error(), c)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// 参数验证
|
||||||
|
if err := global.Validate.Struct(req); err != nil {
|
||||||
|
responses.FailWithMessage(utils.Translate(err), c)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// 业务处理
|
||||||
|
areaService := service.AreaService{}
|
||||||
|
_, err := areaService.AddArea(req)
|
||||||
|
if err != nil {
|
||||||
|
responses.FailWithMessage(err.Error(), c)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
responses.Ok(c)
|
||||||
|
}
|
||||||
|
|
||||||
|
// PutArea 修改地区
|
||||||
|
func (r *Area) PutArea(c *gin.Context) {
|
||||||
|
areaRequest := requests.AreaRequest{}
|
||||||
|
req := areaRequest.PutArea
|
||||||
|
if err := c.ShouldBindJSON(&req); err != nil {
|
||||||
|
responses.FailWithMessage(err.Error(), c)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// 参数验证
|
||||||
|
if err := global.Validate.Struct(req); err != nil {
|
||||||
|
responses.FailWithMessage(utils.Translate(err), c)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
id := c.Param("area_id")
|
||||||
|
if id == "" {
|
||||||
|
responses.FailWithMessage("缺少参数", c)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// 将 id 转换为 int64 类型
|
||||||
|
areaId, err := strconv.Atoi(id)
|
||||||
|
if err != nil {
|
||||||
|
responses.Fail(c)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// 业务处理
|
||||||
|
areaService := service.AreaService{}
|
||||||
|
_, err = areaService.PutArea(areaId, req)
|
||||||
|
if err != nil {
|
||||||
|
responses.FailWithMessage(err.Error(), c)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
responses.Ok(c)
|
||||||
|
}
|
||||||
@ -1,117 +1,5 @@
|
|||||||
package controller
|
package controller
|
||||||
|
|
||||||
import (
|
|
||||||
"github.com/gin-gonic/gin"
|
|
||||||
"hospital-admin-api/api/dao"
|
|
||||||
"hospital-admin-api/api/dto"
|
|
||||||
"hospital-admin-api/api/requests"
|
|
||||||
"hospital-admin-api/api/responses"
|
|
||||||
"hospital-admin-api/api/service"
|
|
||||||
"hospital-admin-api/global"
|
|
||||||
"hospital-admin-api/utils"
|
|
||||||
"strconv"
|
|
||||||
)
|
|
||||||
|
|
||||||
type Basic struct {
|
type Basic struct {
|
||||||
Area // 省市区
|
Area // 省市区
|
||||||
}
|
}
|
||||||
|
|
||||||
// Area 省市区
|
|
||||||
type Area struct{}
|
|
||||||
|
|
||||||
// GetAreaList 获取地区列表
|
|
||||||
func (b *Area) GetAreaList(c *gin.Context) {
|
|
||||||
basicRequest := requests.BasicRequest{}
|
|
||||||
req := basicRequest.GetAreaList
|
|
||||||
if err := c.ShouldBind(&req); err != nil {
|
|
||||||
responses.FailWithMessage(err.Error(), c)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
// 参数验证
|
|
||||||
if err := global.Validate.Struct(req); err != nil {
|
|
||||||
responses.FailWithMessage(utils.Translate(err), c)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
// 处理参数
|
|
||||||
if req.ParentId == "" && req.AreaId == "" && req.AreaName == "" {
|
|
||||||
req.ParentId = "1"
|
|
||||||
req.AreaType = 2
|
|
||||||
}
|
|
||||||
|
|
||||||
areaDao := dao.AreaDao{}
|
|
||||||
area, err := areaDao.GetAreaListByStruct(req)
|
|
||||||
if err != nil {
|
|
||||||
responses.Ok(c)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
// 处理返回值
|
|
||||||
r := dto.GetAreaListDto(area)
|
|
||||||
responses.OkWithData(r, c)
|
|
||||||
}
|
|
||||||
|
|
||||||
// AddArea 新增地区
|
|
||||||
func (r *Area) AddArea(c *gin.Context) {
|
|
||||||
basicRequest := requests.BasicRequest{}
|
|
||||||
req := basicRequest.AddArea
|
|
||||||
if err := c.ShouldBindJSON(&req); err != nil {
|
|
||||||
responses.FailWithMessage(err.Error(), c)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
// 参数验证
|
|
||||||
if err := global.Validate.Struct(req); err != nil {
|
|
||||||
responses.FailWithMessage(utils.Translate(err), c)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
// 业务处理
|
|
||||||
basicService := service.BasicService{}
|
|
||||||
_, err := basicService.AddArea(req)
|
|
||||||
if err != nil {
|
|
||||||
responses.FailWithMessage(err.Error(), c)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
responses.Ok(c)
|
|
||||||
}
|
|
||||||
|
|
||||||
// PutArea 修改地区
|
|
||||||
func (r *Area) PutArea(c *gin.Context) {
|
|
||||||
basicRequest := requests.BasicRequest{}
|
|
||||||
req := basicRequest.PutArea
|
|
||||||
if err := c.ShouldBindJSON(&req); err != nil {
|
|
||||||
responses.FailWithMessage(err.Error(), c)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
// 参数验证
|
|
||||||
if err := global.Validate.Struct(req); err != nil {
|
|
||||||
responses.FailWithMessage(utils.Translate(err), c)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
id := c.Param("area_id")
|
|
||||||
if id == "" {
|
|
||||||
responses.FailWithMessage("缺少参数", c)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
// 将 id 转换为 int64 类型
|
|
||||||
areaId, err := strconv.Atoi(id)
|
|
||||||
if err != nil {
|
|
||||||
responses.Fail(c)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
// 业务处理
|
|
||||||
basicService := service.BasicService{}
|
|
||||||
_, err = basicService.PutArea(areaId, req)
|
|
||||||
if err != nil {
|
|
||||||
responses.FailWithMessage(err.Error(), c)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
responses.Ok(c)
|
|
||||||
}
|
|
||||||
|
|||||||
@ -7,28 +7,31 @@ import (
|
|||||||
"hospital-admin-api/api/dto"
|
"hospital-admin-api/api/dto"
|
||||||
"hospital-admin-api/api/requests"
|
"hospital-admin-api/api/requests"
|
||||||
"hospital-admin-api/api/responses"
|
"hospital-admin-api/api/responses"
|
||||||
|
"hospital-admin-api/api/service"
|
||||||
"hospital-admin-api/global"
|
"hospital-admin-api/global"
|
||||||
"hospital-admin-api/utils"
|
"hospital-admin-api/utils"
|
||||||
|
"strconv"
|
||||||
)
|
)
|
||||||
|
|
||||||
type Hospital struct{}
|
type Hospital struct{}
|
||||||
|
|
||||||
// GetHospitalLimit 获取医院列表-限制条数
|
// GetHospitalList 获取医院列表
|
||||||
func (b *Hospital) GetHospitalLimit(c *gin.Context) {
|
func (b *Hospital) GetHospitalList(c *gin.Context) {
|
||||||
hospitalRequest := requests.HospitalRequest{}
|
hospitalRequest := requests.HospitalRequest{}
|
||||||
if err := c.ShouldBind(&hospitalRequest.GetHospitalLimit); err != nil {
|
req := hospitalRequest.GetHospitalList
|
||||||
|
if err := c.ShouldBind(&req); err != nil {
|
||||||
responses.FailWithMessage(err.Error(), c)
|
responses.FailWithMessage(err.Error(), c)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// 参数验证
|
// 参数验证
|
||||||
if err := global.Validate.Struct(hospitalRequest.GetHospitalLimit); err != nil {
|
if err := global.Validate.Struct(req); err != nil {
|
||||||
responses.FailWithMessage(utils.Translate(err), c)
|
responses.FailWithMessage(utils.Translate(err), c)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
hospitalDao := dao.Hospital{}
|
hospitalDao := dao.HospitalDao{}
|
||||||
hospitals, err := hospitalDao.GetHospitalLimitByMaps(hospitalRequest.GetHospitalLimit)
|
hospitals, err := hospitalDao.GetHospitalLimitByMaps(req)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
responses.Ok(c)
|
responses.Ok(c)
|
||||||
return
|
return
|
||||||
@ -38,3 +41,134 @@ func (b *Hospital) GetHospitalLimit(c *gin.Context) {
|
|||||||
getHospitalLimitResponse := dto.GetHospitalListDto(hospitals)
|
getHospitalLimitResponse := dto.GetHospitalListDto(hospitals)
|
||||||
responses.OkWithData(getHospitalLimitResponse, c)
|
responses.OkWithData(getHospitalLimitResponse, c)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// GetHospitalPage 获取医院列表-分页
|
||||||
|
func (r *Hospital) GetHospitalPage(c *gin.Context) {
|
||||||
|
hospitalRequest := requests.HospitalRequest{}
|
||||||
|
req := hospitalRequest.GetHospitalPage
|
||||||
|
if err := c.ShouldBindJSON(&req); err != nil {
|
||||||
|
responses.FailWithMessage(err.Error(), c)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// 参数验证
|
||||||
|
if err := global.Validate.Struct(req); err != nil {
|
||||||
|
responses.FailWithMessage(utils.Translate(err), c)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
if req.Page == 0 {
|
||||||
|
req.Page = 1
|
||||||
|
}
|
||||||
|
|
||||||
|
if req.PageSize == 0 {
|
||||||
|
req.PageSize = 20
|
||||||
|
}
|
||||||
|
|
||||||
|
hospitalDao := dao.HospitalDao{}
|
||||||
|
hospital, total, err := hospitalDao.GetHospitalPageSearch(req, req.Page, req.PageSize)
|
||||||
|
if err != nil {
|
||||||
|
responses.FailWithMessage(err.Error(), c)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// 处理返回值
|
||||||
|
GetHospitalPageResponses := dto.GetHospitalListDto(hospital)
|
||||||
|
|
||||||
|
result := make(map[string]interface{})
|
||||||
|
result["page"] = req.Page
|
||||||
|
result["page_size"] = req.PageSize
|
||||||
|
result["total"] = total
|
||||||
|
result["data"] = GetHospitalPageResponses
|
||||||
|
responses.OkWithData(result, c)
|
||||||
|
}
|
||||||
|
|
||||||
|
// AddHospital 新增医院
|
||||||
|
func (r *Hospital) AddHospital(c *gin.Context) {
|
||||||
|
hospitalRequest := requests.HospitalRequest{}
|
||||||
|
req := hospitalRequest.AddHospital
|
||||||
|
if err := c.ShouldBindJSON(&req); err != nil {
|
||||||
|
responses.FailWithMessage(err.Error(), c)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// 参数验证
|
||||||
|
if err := global.Validate.Struct(req); err != nil {
|
||||||
|
responses.FailWithMessage(utils.Translate(err), c)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// 业务处理
|
||||||
|
hospitalService := service.HospitalService{}
|
||||||
|
_, err := hospitalService.AddHospital(req)
|
||||||
|
if err != nil {
|
||||||
|
responses.FailWithMessage(err.Error(), c)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
responses.Ok(c)
|
||||||
|
}
|
||||||
|
|
||||||
|
// PutHospital 修改医院
|
||||||
|
func (r *Hospital) PutHospital(c *gin.Context) {
|
||||||
|
hospitalRequest := requests.HospitalRequest{}
|
||||||
|
req := hospitalRequest.PutHospital
|
||||||
|
if err := c.ShouldBindJSON(&req); err != nil {
|
||||||
|
responses.FailWithMessage(err.Error(), c)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// 参数验证
|
||||||
|
if err := global.Validate.Struct(req); err != nil {
|
||||||
|
responses.FailWithMessage(utils.Translate(err), c)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
id := c.Param("hospital_id")
|
||||||
|
if id == "" {
|
||||||
|
responses.FailWithMessage("缺少参数", c)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// 将 id 转换为 int64 类型
|
||||||
|
hospitalId, err := strconv.ParseInt(id, 10, 64)
|
||||||
|
if err != nil {
|
||||||
|
responses.Fail(c)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// 业务处理
|
||||||
|
hospitalService := service.HospitalService{}
|
||||||
|
_, err = hospitalService.PutHospital(hospitalId, req)
|
||||||
|
if err != nil {
|
||||||
|
responses.FailWithMessage(err.Error(), c)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
responses.Ok(c)
|
||||||
|
}
|
||||||
|
|
||||||
|
// GetHospital 医院详情
|
||||||
|
func (r *Hospital) GetHospital(c *gin.Context) {
|
||||||
|
id := c.Param("hospital_id")
|
||||||
|
if id == "" {
|
||||||
|
responses.FailWithMessage("缺少参数", c)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// 将 id 转换为 int64 类型
|
||||||
|
hospitalId, err := strconv.ParseInt(id, 10, 64)
|
||||||
|
if err != nil {
|
||||||
|
responses.Fail(c)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// 业务处理
|
||||||
|
hospitalService := service.HospitalService{}
|
||||||
|
getHospitalResponses, err := hospitalService.GetHospital(hospitalId)
|
||||||
|
if err != nil {
|
||||||
|
responses.FailWithMessage(err.Error(), c)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
responses.OkWithData(getHospitalResponses, c)
|
||||||
|
}
|
||||||
|
|||||||
@ -7,11 +7,11 @@ import (
|
|||||||
"hospital-admin-api/global"
|
"hospital-admin-api/global"
|
||||||
)
|
)
|
||||||
|
|
||||||
type Hospital struct {
|
type HospitalDao struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetHospitalById 获取医院数据-医院id
|
// GetHospitalById 获取医院数据-医院id
|
||||||
func (r *Hospital) GetHospitalById(hospitalId int64) (m *model.Hospital, err error) {
|
func (r *HospitalDao) GetHospitalById(hospitalId int64) (m *model.Hospital, err error) {
|
||||||
err = global.Db.First(&m, hospitalId).Error
|
err = global.Db.First(&m, hospitalId).Error
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
@ -20,7 +20,7 @@ func (r *Hospital) GetHospitalById(hospitalId int64) (m *model.Hospital, err err
|
|||||||
}
|
}
|
||||||
|
|
||||||
// AddHospital 新增医院
|
// AddHospital 新增医院
|
||||||
func (r *Hospital) AddHospital(tx *gorm.DB, model *model.Hospital) (*model.Hospital, error) {
|
func (r *HospitalDao) AddHospital(tx *gorm.DB, model *model.Hospital) (*model.Hospital, error) {
|
||||||
if err := tx.Create(model).Error; err != nil {
|
if err := tx.Create(model).Error; err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
@ -28,7 +28,7 @@ func (r *Hospital) AddHospital(tx *gorm.DB, model *model.Hospital) (*model.Hospi
|
|||||||
}
|
}
|
||||||
|
|
||||||
// GetHospitalList 获取医院列表
|
// GetHospitalList 获取医院列表
|
||||||
func (r *Hospital) GetHospitalList(maps interface{}) (m []*model.Hospital, err error) {
|
func (r *HospitalDao) GetHospitalList(maps interface{}) (m []*model.Hospital, err error) {
|
||||||
err = global.Db.Where(maps).Find(&m).Error
|
err = global.Db.Where(maps).Find(&m).Error
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
@ -37,7 +37,7 @@ func (r *Hospital) GetHospitalList(maps interface{}) (m []*model.Hospital, err e
|
|||||||
}
|
}
|
||||||
|
|
||||||
// DeleteHospitalById 删除医院-医院id
|
// DeleteHospitalById 删除医院-医院id
|
||||||
func (r *Hospital) DeleteHospitalById(tx *gorm.DB, hospitalId int64) error {
|
func (r *HospitalDao) DeleteHospitalById(tx *gorm.DB, hospitalId int64) error {
|
||||||
if err := tx.Delete(&model.Hospital{}, hospitalId).Error; err != nil {
|
if err := tx.Delete(&model.Hospital{}, hospitalId).Error; err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@ -45,7 +45,7 @@ func (r *Hospital) DeleteHospitalById(tx *gorm.DB, hospitalId int64) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// EditHospitalById 修改医院-医院id
|
// EditHospitalById 修改医院-医院id
|
||||||
func (r *Hospital) EditHospitalById(tx *gorm.DB, hospitalId int64, data interface{}) error {
|
func (r *HospitalDao) EditHospitalById(tx *gorm.DB, hospitalId int64, data interface{}) error {
|
||||||
err := tx.Model(&model.Hospital{}).Where("hospital_id = ?", hospitalId).Updates(data).Error
|
err := tx.Model(&model.Hospital{}).Where("hospital_id = ?", hospitalId).Updates(data).Error
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
@ -54,7 +54,7 @@ func (r *Hospital) EditHospitalById(tx *gorm.DB, hospitalId int64, data interfac
|
|||||||
}
|
}
|
||||||
|
|
||||||
// GetHospitalLimitByMaps 获取医院列表-限制条数
|
// GetHospitalLimitByMaps 获取医院列表-限制条数
|
||||||
func (r *Hospital) GetHospitalLimitByMaps(hospitalRequest requests.GetHospitalLimit) (m []*model.Hospital, err error) {
|
func (r *HospitalDao) GetHospitalLimitByMaps(hospitalRequest requests.GetHospitalList) (m []*model.Hospital, err error) {
|
||||||
result := global.Db
|
result := global.Db
|
||||||
if hospitalRequest.HospitalName != "" {
|
if hospitalRequest.HospitalName != "" {
|
||||||
result = result.Where("hospital_name like ?", "%"+hospitalRequest.HospitalName+"%")
|
result = result.Where("hospital_name like ?", "%"+hospitalRequest.HospitalName+"%")
|
||||||
@ -94,3 +94,46 @@ func (r *Hospital) GetHospitalLimitByMaps(hospitalRequest requests.GetHospitalLi
|
|||||||
}
|
}
|
||||||
return m, nil
|
return m, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// GetHospitalPageSearch 获取医院列表-分页
|
||||||
|
func (r *HospitalDao) GetHospitalPageSearch(req requests.GetHospitalPage, page, pageSize int) (m []*model.Hospital, total int64, err error) {
|
||||||
|
var totalRecords int64
|
||||||
|
|
||||||
|
// 构建查询条件
|
||||||
|
query := global.Db.Model(&model.Hospital{})
|
||||||
|
|
||||||
|
if req.HospitalName != "" {
|
||||||
|
query = query.Where("hospital_name like ?", "%"+req.HospitalName+"%")
|
||||||
|
}
|
||||||
|
|
||||||
|
if req.HospitalLevelName != "" {
|
||||||
|
query = query.Where("hospital_level_name like ?", "%"+req.HospitalLevelName+"%")
|
||||||
|
}
|
||||||
|
|
||||||
|
if req.ProvinceId != 0 {
|
||||||
|
query = query.Where("province_id = ?", req.ProvinceId)
|
||||||
|
}
|
||||||
|
|
||||||
|
if req.CityId != 0 {
|
||||||
|
query = query.Where("city_id = ?", req.CityId)
|
||||||
|
}
|
||||||
|
|
||||||
|
if req.CountyId != 0 {
|
||||||
|
query = query.Where("county_id = ?", req.CountyId)
|
||||||
|
}
|
||||||
|
|
||||||
|
// 排序
|
||||||
|
query = query.Order("created_at desc")
|
||||||
|
|
||||||
|
// 查询总数量
|
||||||
|
if err := query.Count(&totalRecords).Error; err != nil {
|
||||||
|
return nil, 0, err
|
||||||
|
}
|
||||||
|
|
||||||
|
err = query.Scopes(model.Paginate(page, pageSize)).Find(&m).Error
|
||||||
|
if err != nil {
|
||||||
|
return nil, 0, err
|
||||||
|
}
|
||||||
|
|
||||||
|
return m, totalRecords, nil
|
||||||
|
}
|
||||||
|
|||||||
29
api/requests/area.go
Normal file
29
api/requests/area.go
Normal file
@ -0,0 +1,29 @@
|
|||||||
|
package requests
|
||||||
|
|
||||||
|
type AreaRequest struct {
|
||||||
|
GetAreaList // 获取地区列表
|
||||||
|
AddArea // 新增地区
|
||||||
|
PutArea // 修改地区
|
||||||
|
}
|
||||||
|
|
||||||
|
// GetAreaList 获取地区列表
|
||||||
|
type GetAreaList struct {
|
||||||
|
AreaId string `json:"area_id" form:"area_id" label:"地区编号"`
|
||||||
|
AreaName string `json:"area_name" form:"area_name" label:"名称"`
|
||||||
|
ParentId string `json:"parent_id" form:"parent_id" label:"上级编号"`
|
||||||
|
AreaType int `json:"area_type" form:"area_type" label:"类型(1:国家,2:省,3:市,4:区县)"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// AddArea 新增地区
|
||||||
|
type AddArea struct {
|
||||||
|
AreaName string `json:"area_name" form:"area_name" label:"名称" validate:"required"`
|
||||||
|
ParentId string `json:"parent_id" form:"parent_id" label:"上级编号" validate:"required"`
|
||||||
|
AreaType *int `json:"area_type" form:"area_type" label:"类型(1:国家,2:省,3:市,4:区县)" validate:"required"`
|
||||||
|
Zip string `json:"zip" form:"zip" label:"邮编"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// PutArea 修改地区
|
||||||
|
type PutArea struct {
|
||||||
|
AreaName string `json:"area_name" form:"area_name" label:"名称" validate:"required"`
|
||||||
|
Zip string `json:"zip" form:"zip" label:"邮编"`
|
||||||
|
}
|
||||||
@ -1,29 +1,4 @@
|
|||||||
package requests
|
package requests
|
||||||
|
|
||||||
type BasicRequest struct {
|
type BasicRequest struct {
|
||||||
GetAreaList // 获取地区列表
|
|
||||||
AddArea // 新增地区
|
|
||||||
PutArea // 修改地区
|
|
||||||
}
|
|
||||||
|
|
||||||
// GetAreaList 获取地区列表
|
|
||||||
type GetAreaList struct {
|
|
||||||
AreaId string `json:"area_id" form:"area_id" label:"地区编号"`
|
|
||||||
AreaName string `json:"area_name" form:"area_name" label:"名称"`
|
|
||||||
ParentId string `json:"parent_id" form:"parent_id" label:"上级编号"`
|
|
||||||
AreaType int `json:"area_type" form:"area_type" label:"类型(1:国家,2:省,3:市,4:区县)"`
|
|
||||||
}
|
|
||||||
|
|
||||||
// AddArea 新增地区
|
|
||||||
type AddArea struct {
|
|
||||||
AreaName string `json:"area_name" form:"area_name" label:"名称" validate:"required"`
|
|
||||||
ParentId string `json:"parent_id" form:"parent_id" label:"上级编号" validate:"required"`
|
|
||||||
AreaType *int `json:"area_type" form:"area_type" label:"类型(1:国家,2:省,3:市,4:区县)" validate:"required"`
|
|
||||||
Zip string `json:"zip" form:"zip" label:"邮编"`
|
|
||||||
}
|
|
||||||
|
|
||||||
// PutArea 修改地区
|
|
||||||
type PutArea struct {
|
|
||||||
AreaName string `json:"area_name" form:"area_name" label:"名称" validate:"required"`
|
|
||||||
Zip string `json:"zip" form:"zip" label:"邮编"`
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,13 +1,17 @@
|
|||||||
package requests
|
package requests
|
||||||
|
|
||||||
type HospitalRequest struct {
|
type HospitalRequest struct {
|
||||||
GetHospitalLimit // 获取医院列表-限制条数
|
GetHospitalList // 获取医院列表
|
||||||
|
GetHospitalPage // 获取医院列表-分页
|
||||||
|
AddHospital // 新增医院
|
||||||
|
PutHospital // 修改医院
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetHospitalLimit 获取医院列表-限制条数
|
// GetHospitalList 获取医院列表
|
||||||
type GetHospitalLimit struct {
|
type GetHospitalList struct {
|
||||||
HospitalName string `json:"hospital_name" form:"hospital_name" label:"医院名称"`
|
HospitalName string `json:"hospital_name" form:"hospital_name" label:"医院名称"`
|
||||||
HospitalLevelName string `json:"hospital_level_name" form:"hospital_level_name" label:"医院等级名称"`
|
HospitalLevelName string `json:"hospital_level_name" form:"hospital_level_name" label:"医院等级名称"`
|
||||||
|
HospitalStatus int `json:"hospital_status" form:"hospital_status" label:"状态"` // 状态(0:禁用 1:正常 2:删除)
|
||||||
ProvinceId int `json:"province_id" form:"province_id" label:"省份id"`
|
ProvinceId int `json:"province_id" form:"province_id" label:"省份id"`
|
||||||
Province string `json:"province" form:"province" label:"省份"`
|
Province string `json:"province" form:"province" label:"省份"`
|
||||||
CityId int `json:"city_id" form:"city_id" label:"城市id"`
|
CityId int `json:"city_id" form:"city_id" label:"城市id"`
|
||||||
@ -15,3 +19,46 @@ type GetHospitalLimit struct {
|
|||||||
CountyId int `json:"county_id" form:"county_id" label:"区县id"`
|
CountyId int `json:"county_id" form:"county_id" label:"区县id"`
|
||||||
County string `json:"county" form:"county" label:"区县"`
|
County string `json:"county" form:"county" label:"区县"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// GetHospitalPage 获取医院列表-分页
|
||||||
|
type GetHospitalPage struct {
|
||||||
|
Page int `json:"page" form:"page" label:"页码"`
|
||||||
|
PageSize int `json:"page_size" form:"page_size" label:"每页个数"`
|
||||||
|
HospitalName string `json:"hospital_name" form:"hospital_name" label:"医院名称"`
|
||||||
|
HospitalLevelName string `json:"hospital_level_name" form:"hospital_level_name" label:"医院等级名称"`
|
||||||
|
ProvinceId int `json:"province_id" form:"province_id" label:"省份id"`
|
||||||
|
CityId int `json:"city_id" form:"city_id" label:"城市id"`
|
||||||
|
CountyId int `json:"county_id" form:"county_id" label:"区县id"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// AddHospital 新增医院
|
||||||
|
type AddHospital struct {
|
||||||
|
HospitalName string `json:"hospital_name" form:"hospital_name" label:"医院名称" validate:"required"` // 医院名称
|
||||||
|
HospitalStatus *int `json:"hospital_status" form:"hospital_status" label:"状态" validate:"required,oneof=0 1 2"` // 状态(0:禁用 1:正常 2:删除)
|
||||||
|
HospitalLevelName string `json:"hospital_level_name" form:"hospital_level_name" label:"医院等级名称" validate:"required"` // 医院等级名称
|
||||||
|
PostCode string `json:"post_code" form:"post_code" label:"邮政编码"` // 邮政编码
|
||||||
|
TelePhone string `json:"tele_phone" form:"tele_phone" label:"电话"` // 电话
|
||||||
|
ProvinceId int `json:"province_id" form:"province_id" label:"省份id" validate:"required"` // 省份id
|
||||||
|
CityId int `json:"city_id" form:"city_id" label:"城市id" validate:"required"` // 城市id
|
||||||
|
CountyId int `json:"county_id" form:"county_id" label:"区县id" validate:"required"` // 区县id
|
||||||
|
Address string `json:"address" form:"address" label:"地址" validate:"required"` // 地址
|
||||||
|
Lat string `json:"lat" form:"lat" label:"纬度"` // 纬度
|
||||||
|
Lng string `json:"lng" form:"lng" label:"经度"` // 经度
|
||||||
|
Desc string `json:"desc" form:"desc" label:"简介"` // 简介
|
||||||
|
}
|
||||||
|
|
||||||
|
// PutHospital 修改医院
|
||||||
|
type PutHospital struct {
|
||||||
|
HospitalName string `json:"hospital_name" form:"hospital_name" label:"医院名称" validate:"required"` // 医院名称
|
||||||
|
HospitalStatus *int `json:"hospital_status" form:"hospital_status" label:"状态" validate:"required,oneof=0 1 2"` // 状态(0:禁用 1:正常 2:删除)
|
||||||
|
HospitalLevelName string `json:"hospital_level_name" form:"hospital_level_name" label:"医院等级名称" validate:"required"` // 医院等级名称
|
||||||
|
PostCode string `json:"post_code" form:"post_code" label:"邮政编码"` // 邮政编码
|
||||||
|
TelePhone string `json:"tele_phone" form:"tele_phone" label:"电话"` // 电话
|
||||||
|
ProvinceId int `json:"province_id" form:"province_id" label:"省份id" validate:"required"` // 省份id
|
||||||
|
CityId int `json:"city_id" form:"city_id" label:"城市id" validate:"required"` // 城市id
|
||||||
|
CountyId int `json:"county_id" form:"county_id" label:"区县id" validate:"required"` // 区县id
|
||||||
|
Address string `json:"address" form:"address" label:"地址" validate:"required"` // 地址
|
||||||
|
Lat string `json:"lat" form:"lat" label:"纬度"` // 纬度
|
||||||
|
Lng string `json:"lng" form:"lng" label:"经度"` // 经度
|
||||||
|
Desc string `json:"desc" form:"desc" label:"简介"` // 简介
|
||||||
|
}
|
||||||
|
|||||||
@ -128,7 +128,7 @@ func basicRouter(r *gin.Engine, api controller.Api) {
|
|||||||
hospitalGroup := basicGroup.Group("/hospital")
|
hospitalGroup := basicGroup.Group("/hospital")
|
||||||
{
|
{
|
||||||
// 获取医院列表-限制条数
|
// 获取医院列表-限制条数
|
||||||
hospitalGroup.GET("/list", api.Hospital.GetHospitalLimit)
|
hospitalGroup.GET("/list", api.Hospital.GetHospitalList)
|
||||||
}
|
}
|
||||||
|
|
||||||
// 专长管理-基础数据
|
// 专长管理-基础数据
|
||||||
@ -714,25 +714,6 @@ func privateRouter(r *gin.Engine, api controller.Api) {
|
|||||||
// 获取平台商品列表
|
// 获取平台商品列表
|
||||||
platformGroup.GET("/list", api.Product.GetPlatformProductList)
|
platformGroup.GET("/list", api.Product.GetPlatformProductList)
|
||||||
}
|
}
|
||||||
|
|
||||||
// 麻精药品
|
|
||||||
majingGroup := productGroup.Group("/majing")
|
|
||||||
{
|
|
||||||
// 获取麻精药品列表-分页
|
|
||||||
majingGroup.POST("/page", api.Product.GetProductPage)
|
|
||||||
|
|
||||||
// 系统麻精药品详情
|
|
||||||
majingGroup.GET("/:product_id", api.Product.GetProduct)
|
|
||||||
|
|
||||||
// 新增麻精药品
|
|
||||||
majingGroup.POST("", api.Product.AddProduct)
|
|
||||||
|
|
||||||
// 修改麻精药品
|
|
||||||
majingGroup.PUT("/:product_id", api.Product.PutProduct)
|
|
||||||
|
|
||||||
// 修改麻精药品状态(上/下架)
|
|
||||||
majingGroup.PUT("/status/:product_id", api.Product.PutProductStatus)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// 优惠卷管理
|
// 优惠卷管理
|
||||||
@ -775,7 +756,7 @@ func privateRouter(r *gin.Engine, api controller.Api) {
|
|||||||
areaGroup := basicGroup.Group("/area")
|
areaGroup := basicGroup.Group("/area")
|
||||||
{
|
{
|
||||||
// 获取地区列表
|
// 获取地区列表
|
||||||
areaGroup.GET("", api.Basic.Area.GetAreaList)
|
areaGroup.GET("", api.Area.GetAreaList)
|
||||||
|
|
||||||
// 新增地区
|
// 新增地区
|
||||||
areaGroup.POST("", api.Basic.Area.AddArea)
|
areaGroup.POST("", api.Basic.Area.AddArea)
|
||||||
@ -783,5 +764,24 @@ func privateRouter(r *gin.Engine, api controller.Api) {
|
|||||||
// 修改地区
|
// 修改地区
|
||||||
areaGroup.PUT("/:area_id", api.Basic.Area.PutArea)
|
areaGroup.PUT("/:area_id", api.Basic.Area.PutArea)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 医院管理
|
||||||
|
hospitalGroup := basicGroup.Group("/hospital")
|
||||||
|
{
|
||||||
|
// 获取医院列表-限制条数
|
||||||
|
hospitalGroup.GET("", api.Hospital.GetHospitalList)
|
||||||
|
|
||||||
|
// 获取医院列表-分页
|
||||||
|
hospitalGroup.POST("/page", api.Hospital.GetHospitalPage)
|
||||||
|
|
||||||
|
// 获取医院详情
|
||||||
|
hospitalGroup.GET("/:hospital_id", api.Hospital.GetHospital)
|
||||||
|
|
||||||
|
// 新增医院
|
||||||
|
hospitalGroup.POST("", api.Hospital.AddHospital)
|
||||||
|
|
||||||
|
// 修改医院
|
||||||
|
hospitalGroup.PUT("/:hospital_id", api.Hospital.PutHospital)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -126,7 +126,7 @@ func (r *DoctorInquiryConfigService) GetDoctorInquiryConfig(inquiryConfigId int6
|
|||||||
}
|
}
|
||||||
|
|
||||||
// 获取医生医院数据
|
// 获取医生医院数据
|
||||||
hospitalDao := dao.Hospital{}
|
hospitalDao := dao.HospitalDao{}
|
||||||
hospital, err := hospitalDao.GetHospitalById(userDoctor.HospitalID)
|
hospital, err := hospitalDao.GetHospitalById(userDoctor.HospitalID)
|
||||||
|
|
||||||
// 获取系统问诊配置
|
// 获取系统问诊配置
|
||||||
|
|||||||
113
api/service/area.go
Normal file
113
api/service/area.go
Normal file
@ -0,0 +1,113 @@
|
|||||||
|
package service
|
||||||
|
|
||||||
|
import (
|
||||||
|
"errors"
|
||||||
|
"fmt"
|
||||||
|
"hospital-admin-api/api/dao"
|
||||||
|
"hospital-admin-api/api/model"
|
||||||
|
"hospital-admin-api/api/requests"
|
||||||
|
"hospital-admin-api/global"
|
||||||
|
"strconv"
|
||||||
|
)
|
||||||
|
|
||||||
|
type AreaService struct{}
|
||||||
|
|
||||||
|
// AddArea 新增地区
|
||||||
|
func (r *AreaService) AddArea(req requests.AddArea) (bool, error) {
|
||||||
|
if *req.AreaType == 1 {
|
||||||
|
return false, errors.New("不可添加国家")
|
||||||
|
}
|
||||||
|
|
||||||
|
// 检测上级是否存在
|
||||||
|
maps := make(map[string]interface{})
|
||||||
|
maps["parent_id"] = req.ParentId
|
||||||
|
if *req.AreaType == 4 {
|
||||||
|
maps["area_type"] = 3
|
||||||
|
}
|
||||||
|
if *req.AreaType == 3 {
|
||||||
|
maps["area_type"] = 2
|
||||||
|
}
|
||||||
|
|
||||||
|
if *req.AreaType == 2 {
|
||||||
|
maps["area_type"] = 1
|
||||||
|
}
|
||||||
|
|
||||||
|
areaDao := dao.AreaDao{}
|
||||||
|
_, err := areaDao.GetAreaList(maps)
|
||||||
|
if err != nil {
|
||||||
|
return false, errors.New("上级地区错误")
|
||||||
|
}
|
||||||
|
|
||||||
|
// 开始事务
|
||||||
|
tx := global.Db.Begin()
|
||||||
|
defer func() {
|
||||||
|
if r := recover(); r != nil {
|
||||||
|
tx.Rollback()
|
||||||
|
fmt.Println(r)
|
||||||
|
}
|
||||||
|
}()
|
||||||
|
|
||||||
|
parentId, err := strconv.ParseInt(req.ParentId, 10, 64)
|
||||||
|
if err != nil {
|
||||||
|
tx.Rollback()
|
||||||
|
return false, errors.New("新增失败")
|
||||||
|
}
|
||||||
|
|
||||||
|
// 新增优惠卷表
|
||||||
|
area := &model.Area{
|
||||||
|
AreaName: req.AreaName,
|
||||||
|
ParentId: parentId,
|
||||||
|
Zip: req.Zip,
|
||||||
|
AreaType: *req.AreaType,
|
||||||
|
}
|
||||||
|
|
||||||
|
area, err = areaDao.AddArea(tx, area)
|
||||||
|
if err != nil || area == nil {
|
||||||
|
tx.Rollback()
|
||||||
|
return false, errors.New(err.Error())
|
||||||
|
}
|
||||||
|
|
||||||
|
tx.Commit()
|
||||||
|
return true, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// PutArea 修改地区
|
||||||
|
func (r *AreaService) PutArea(areaId int, req requests.PutArea) (bool, error) {
|
||||||
|
areaDao := dao.AreaDao{}
|
||||||
|
area, err := areaDao.GetAreaById(areaId)
|
||||||
|
if err != nil {
|
||||||
|
return false, err
|
||||||
|
}
|
||||||
|
|
||||||
|
// 开始事务
|
||||||
|
tx := global.Db.Begin()
|
||||||
|
defer func() {
|
||||||
|
if r := recover(); r != nil {
|
||||||
|
tx.Rollback()
|
||||||
|
fmt.Println(r)
|
||||||
|
}
|
||||||
|
}()
|
||||||
|
|
||||||
|
areaData := make(map[string]interface{})
|
||||||
|
|
||||||
|
if req.AreaName != area.AreaName {
|
||||||
|
areaData["area_name"] = req.AreaName
|
||||||
|
}
|
||||||
|
|
||||||
|
if req.Zip != "" {
|
||||||
|
if req.Zip != area.Zip {
|
||||||
|
areaData["zip"] = req.Zip
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if len(areaData) > 0 {
|
||||||
|
err = areaDao.EditAreaById(tx, areaId, areaData)
|
||||||
|
if err != nil || area == nil {
|
||||||
|
tx.Rollback()
|
||||||
|
return false, errors.New(err.Error())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
tx.Commit()
|
||||||
|
return true, nil
|
||||||
|
}
|
||||||
@ -1,113 +1,3 @@
|
|||||||
package service
|
package service
|
||||||
|
|
||||||
import (
|
|
||||||
"errors"
|
|
||||||
"fmt"
|
|
||||||
"hospital-admin-api/api/dao"
|
|
||||||
"hospital-admin-api/api/model"
|
|
||||||
"hospital-admin-api/api/requests"
|
|
||||||
"hospital-admin-api/global"
|
|
||||||
"strconv"
|
|
||||||
)
|
|
||||||
|
|
||||||
type BasicService struct{}
|
type BasicService struct{}
|
||||||
|
|
||||||
// AddArea 新增地区
|
|
||||||
func (r *BasicService) AddArea(req requests.AddArea) (bool, error) {
|
|
||||||
if *req.AreaType == 1 {
|
|
||||||
return false, errors.New("不可添加国家")
|
|
||||||
}
|
|
||||||
|
|
||||||
// 检测上级是否存在
|
|
||||||
maps := make(map[string]interface{})
|
|
||||||
maps["parent_id"] = req.ParentId
|
|
||||||
if *req.AreaType == 4 {
|
|
||||||
maps["area_type"] = 3
|
|
||||||
}
|
|
||||||
if *req.AreaType == 3 {
|
|
||||||
maps["area_type"] = 2
|
|
||||||
}
|
|
||||||
|
|
||||||
if *req.AreaType == 2 {
|
|
||||||
maps["area_type"] = 1
|
|
||||||
}
|
|
||||||
|
|
||||||
areaDao := dao.AreaDao{}
|
|
||||||
_, err := areaDao.GetAreaList(maps)
|
|
||||||
if err != nil {
|
|
||||||
return false, errors.New("上级地区错误")
|
|
||||||
}
|
|
||||||
|
|
||||||
// 开始事务
|
|
||||||
tx := global.Db.Begin()
|
|
||||||
defer func() {
|
|
||||||
if r := recover(); r != nil {
|
|
||||||
tx.Rollback()
|
|
||||||
fmt.Println(r)
|
|
||||||
}
|
|
||||||
}()
|
|
||||||
|
|
||||||
parentId, err := strconv.ParseInt(req.ParentId, 10, 64)
|
|
||||||
if err != nil {
|
|
||||||
tx.Rollback()
|
|
||||||
return false, errors.New("新增失败")
|
|
||||||
}
|
|
||||||
|
|
||||||
// 新增优惠卷表
|
|
||||||
area := &model.Area{
|
|
||||||
AreaName: req.AreaName,
|
|
||||||
ParentId: parentId,
|
|
||||||
Zip: req.Zip,
|
|
||||||
AreaType: *req.AreaType,
|
|
||||||
}
|
|
||||||
|
|
||||||
area, err = areaDao.AddArea(tx, area)
|
|
||||||
if err != nil || area == nil {
|
|
||||||
tx.Rollback()
|
|
||||||
return false, errors.New(err.Error())
|
|
||||||
}
|
|
||||||
|
|
||||||
tx.Commit()
|
|
||||||
return true, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// PutArea 修改地区
|
|
||||||
func (r *BasicService) PutArea(areaId int, req requests.PutArea) (bool, error) {
|
|
||||||
areaDao := dao.AreaDao{}
|
|
||||||
area, err := areaDao.GetAreaById(areaId)
|
|
||||||
if err != nil {
|
|
||||||
return false, err
|
|
||||||
}
|
|
||||||
|
|
||||||
// 开始事务
|
|
||||||
tx := global.Db.Begin()
|
|
||||||
defer func() {
|
|
||||||
if r := recover(); r != nil {
|
|
||||||
tx.Rollback()
|
|
||||||
fmt.Println(r)
|
|
||||||
}
|
|
||||||
}()
|
|
||||||
|
|
||||||
areaData := make(map[string]interface{})
|
|
||||||
|
|
||||||
if req.AreaName != area.AreaName {
|
|
||||||
areaData["area_name"] = req.AreaName
|
|
||||||
}
|
|
||||||
|
|
||||||
if req.Zip != "" {
|
|
||||||
if req.Zip != area.Zip {
|
|
||||||
areaData["zip"] = req.Zip
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if len(areaData) > 0 {
|
|
||||||
err = areaDao.EditAreaById(tx, areaId, areaData)
|
|
||||||
if err != nil || area == nil {
|
|
||||||
tx.Rollback()
|
|
||||||
return false, errors.New(err.Error())
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
tx.Commit()
|
|
||||||
return true, nil
|
|
||||||
}
|
|
||||||
|
|||||||
233
api/service/hospital.go
Normal file
233
api/service/hospital.go
Normal file
@ -0,0 +1,233 @@
|
|||||||
|
package service
|
||||||
|
|
||||||
|
import (
|
||||||
|
"errors"
|
||||||
|
"fmt"
|
||||||
|
"hospital-admin-api/api/dao"
|
||||||
|
"hospital-admin-api/api/dto"
|
||||||
|
"hospital-admin-api/api/model"
|
||||||
|
"hospital-admin-api/api/requests"
|
||||||
|
"hospital-admin-api/global"
|
||||||
|
)
|
||||||
|
|
||||||
|
type HospitalService struct {
|
||||||
|
}
|
||||||
|
|
||||||
|
// AddHospital 新增医院
|
||||||
|
func (r *HospitalService) AddHospital(req requests.AddHospital) (bool, error) {
|
||||||
|
hospitalDao := dao.HospitalDao{}
|
||||||
|
|
||||||
|
// 检测医院是否重复
|
||||||
|
maps := make(map[string]interface{})
|
||||||
|
maps["hospital_name"] = req.HospitalName
|
||||||
|
maps["province_id"] = req.ProvinceId
|
||||||
|
maps["city_id"] = req.CityId
|
||||||
|
hospitals, err := hospitalDao.GetHospitalList(maps)
|
||||||
|
if err != nil {
|
||||||
|
return false, errors.New("医院重复添加")
|
||||||
|
}
|
||||||
|
|
||||||
|
if len(hospitals) != 0 {
|
||||||
|
return false, errors.New("医院重复添加")
|
||||||
|
}
|
||||||
|
|
||||||
|
var province string
|
||||||
|
var city string
|
||||||
|
var county string
|
||||||
|
|
||||||
|
areaDao := dao.AreaDao{}
|
||||||
|
if req.ProvinceId != 0 {
|
||||||
|
area, err := areaDao.GetAreaById(req.ProvinceId)
|
||||||
|
if err != nil || area == nil {
|
||||||
|
return false, errors.New("省份数据错误")
|
||||||
|
}
|
||||||
|
province = area.AreaName
|
||||||
|
}
|
||||||
|
|
||||||
|
if req.CityId != 0 {
|
||||||
|
area, err := areaDao.GetAreaById(req.CityId)
|
||||||
|
if err != nil || area == nil {
|
||||||
|
return false, errors.New("城市数据错误")
|
||||||
|
}
|
||||||
|
city = area.AreaName
|
||||||
|
}
|
||||||
|
|
||||||
|
if req.CountyId != 0 {
|
||||||
|
area, err := areaDao.GetAreaById(req.CountyId)
|
||||||
|
if err != nil || area == nil {
|
||||||
|
return false, errors.New("城市数据错误")
|
||||||
|
}
|
||||||
|
county = area.AreaName
|
||||||
|
}
|
||||||
|
|
||||||
|
// 开始事务
|
||||||
|
tx := global.Db.Begin()
|
||||||
|
defer func() {
|
||||||
|
if r := recover(); r != nil {
|
||||||
|
tx.Rollback()
|
||||||
|
}
|
||||||
|
}()
|
||||||
|
|
||||||
|
// 新增商品表
|
||||||
|
hospital := &model.Hospital{
|
||||||
|
HospitalName: req.HospitalName,
|
||||||
|
HospitalStatus: *req.HospitalStatus,
|
||||||
|
HospitalLevelName: req.HospitalLevelName,
|
||||||
|
PostCode: req.PostCode,
|
||||||
|
TelePhone: req.TelePhone,
|
||||||
|
ProvinceId: req.ProvinceId,
|
||||||
|
Province: province,
|
||||||
|
CityId: req.CityId,
|
||||||
|
City: city,
|
||||||
|
CountyId: req.CountyId,
|
||||||
|
County: county,
|
||||||
|
Address: req.Address,
|
||||||
|
Lat: req.Lat,
|
||||||
|
Lng: req.Lng,
|
||||||
|
Desc: req.Desc,
|
||||||
|
}
|
||||||
|
|
||||||
|
hospital, err = hospitalDao.AddHospital(tx, hospital)
|
||||||
|
if err != nil || hospital == nil {
|
||||||
|
tx.Rollback()
|
||||||
|
return false, errors.New(err.Error())
|
||||||
|
}
|
||||||
|
|
||||||
|
tx.Commit()
|
||||||
|
return true, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// PutHospital 修改医院
|
||||||
|
func (r *HospitalService) PutHospital(hospitalId int64, req requests.PutHospital) (bool, error) {
|
||||||
|
hospitalDao := dao.HospitalDao{}
|
||||||
|
area, err := hospitalDao.GetHospitalById(hospitalId)
|
||||||
|
if err != nil || area == nil {
|
||||||
|
return false, errors.New("省份数据错误")
|
||||||
|
}
|
||||||
|
|
||||||
|
// 开始事务
|
||||||
|
tx := global.Db.Begin()
|
||||||
|
defer func() {
|
||||||
|
if r := recover(); r != nil {
|
||||||
|
tx.Rollback()
|
||||||
|
fmt.Println(r)
|
||||||
|
}
|
||||||
|
}()
|
||||||
|
|
||||||
|
hospitalData := make(map[string]interface{})
|
||||||
|
|
||||||
|
if req.HospitalName != area.HospitalName {
|
||||||
|
hospitalData["hospital_name"] = req.HospitalName
|
||||||
|
}
|
||||||
|
|
||||||
|
if *req.HospitalStatus != area.HospitalStatus {
|
||||||
|
hospitalData["hospital_status"] = req.HospitalStatus
|
||||||
|
}
|
||||||
|
|
||||||
|
if req.HospitalLevelName != area.HospitalLevelName {
|
||||||
|
hospitalData["hospital_level_name"] = req.HospitalLevelName
|
||||||
|
}
|
||||||
|
|
||||||
|
if req.PostCode != "" {
|
||||||
|
if req.PostCode != area.PostCode {
|
||||||
|
hospitalData["post_code"] = req.PostCode
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if req.TelePhone != "" {
|
||||||
|
if req.TelePhone != area.TelePhone {
|
||||||
|
hospitalData["tele_phone"] = req.TelePhone
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if req.ProvinceId != 0 {
|
||||||
|
if req.ProvinceId != area.ProvinceId {
|
||||||
|
areaDao := dao.AreaDao{}
|
||||||
|
area, err := areaDao.GetAreaById(req.ProvinceId)
|
||||||
|
if err != nil || area == nil {
|
||||||
|
return false, errors.New("省份数据错误")
|
||||||
|
}
|
||||||
|
|
||||||
|
hospitalData["province_id"] = req.ProvinceId
|
||||||
|
hospitalData["province"] = area.AreaName
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if req.CityId != 0 {
|
||||||
|
if req.CityId != area.CityId {
|
||||||
|
areaDao := dao.AreaDao{}
|
||||||
|
area, err := areaDao.GetAreaById(req.CityId)
|
||||||
|
if err != nil || area == nil {
|
||||||
|
return false, errors.New("省份数据错误")
|
||||||
|
}
|
||||||
|
|
||||||
|
hospitalData["city_id"] = req.CityId
|
||||||
|
hospitalData["city"] = area.AreaName
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if req.CountyId != 0 {
|
||||||
|
if req.CountyId != area.CountyId {
|
||||||
|
areaDao := dao.AreaDao{}
|
||||||
|
area, err := areaDao.GetAreaById(req.CountyId)
|
||||||
|
if err != nil || area == nil {
|
||||||
|
return false, errors.New("省份数据错误")
|
||||||
|
}
|
||||||
|
|
||||||
|
hospitalData["county_id"] = req.CountyId
|
||||||
|
hospitalData["county"] = area.AreaName
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if req.Address != "" {
|
||||||
|
if req.Address != area.Address {
|
||||||
|
hospitalData["address"] = req.Address
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if req.Lat != "" {
|
||||||
|
if req.Lat != area.Lat {
|
||||||
|
hospitalData["lat"] = req.Lat
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if req.Lng != "" {
|
||||||
|
if req.Lng != area.Lng {
|
||||||
|
hospitalData["lng"] = req.Lng
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if req.Desc != "" {
|
||||||
|
if req.Desc != area.Desc {
|
||||||
|
hospitalData["desc"] = req.Desc
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if len(hospitalData) > 0 {
|
||||||
|
err = hospitalDao.EditHospitalById(tx, hospitalId, hospitalData)
|
||||||
|
if err != nil || area == nil {
|
||||||
|
tx.Rollback()
|
||||||
|
return false, errors.New(err.Error())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
tx.Commit()
|
||||||
|
return true, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// GetHospital 系统优惠卷详情
|
||||||
|
func (r *HospitalService) GetHospital(hospitalId int64) (g *dto.HospitalDto, err error) {
|
||||||
|
hospitalDao := dao.HospitalDao{}
|
||||||
|
hospital, err := hospitalDao.GetHospitalById(hospitalId)
|
||||||
|
if err != nil || hospital == nil {
|
||||||
|
return nil, errors.New(err.Error())
|
||||||
|
}
|
||||||
|
|
||||||
|
// 处理返回值
|
||||||
|
g = dto.GetHospitalDto(hospital)
|
||||||
|
|
||||||
|
return g, nil
|
||||||
|
}
|
||||||
@ -157,7 +157,7 @@ func (r *UserDoctorService) PutUserDoctor(doctorId int64, req requests.PutUserDo
|
|||||||
|
|
||||||
if userDoctor.HospitalID != hospitalId {
|
if userDoctor.HospitalID != hospitalId {
|
||||||
// 获取医院数据
|
// 获取医院数据
|
||||||
hospitalDao := dao.Hospital{}
|
hospitalDao := dao.HospitalDao{}
|
||||||
hospital, err := hospitalDao.GetHospitalById(hospitalId)
|
hospital, err := hospitalDao.GetHospitalById(hospitalId)
|
||||||
if err != nil || hospital == nil {
|
if err != nil || hospital == nil {
|
||||||
return false, errors.New("医院错误")
|
return false, errors.New("医院错误")
|
||||||
@ -773,7 +773,7 @@ func (r *UserDoctorService) AddUserDoctor(userId string, req requests.AddUserDoc
|
|||||||
}
|
}
|
||||||
|
|
||||||
// 获取医院数据
|
// 获取医院数据
|
||||||
hospitalDao := dao.Hospital{}
|
hospitalDao := dao.HospitalDao{}
|
||||||
hospital, err := hospitalDao.GetHospitalById(hospitalId)
|
hospital, err := hospitalDao.GetHospitalById(hospitalId)
|
||||||
if err != nil || hospital == nil {
|
if err != nil || hospital == nil {
|
||||||
return false, errors.New("医院错误")
|
return false, errors.New("医院错误")
|
||||||
@ -1179,7 +1179,7 @@ func (r *UserDoctorService) PutUserDoctorPending(doctorId int64, req requests.Pu
|
|||||||
}
|
}
|
||||||
|
|
||||||
// 获取医院名称
|
// 获取医院名称
|
||||||
hospitalDao := dao.Hospital{}
|
hospitalDao := dao.HospitalDao{}
|
||||||
hospital, err := hospitalDao.GetHospitalById(userDoctor.HospitalID)
|
hospital, err := hospitalDao.GetHospitalById(userDoctor.HospitalID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return false, errors.New("审核失败")
|
return false, errors.New("审核失败")
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user