364 lines
9.0 KiB
Go
364 lines
9.0 KiB
Go
package controller
|
|
|
|
import (
|
|
"case-admin-api/api/dao"
|
|
"case-admin-api/api/dto"
|
|
"case-admin-api/api/model"
|
|
"case-admin-api/api/requests"
|
|
"case-admin-api/api/responses"
|
|
"case-admin-api/api/service"
|
|
"case-admin-api/extend/app"
|
|
"case-admin-api/global"
|
|
"case-admin-api/utils"
|
|
"github.com/gin-gonic/gin"
|
|
"strconv"
|
|
)
|
|
|
|
type ProjectPlatformHospital struct{}
|
|
|
|
// GetProjectPlatformHospitalPage 获取列表-分页
|
|
func (b *ProjectPlatformHospital) GetProjectPlatformHospitalPage(c *gin.Context) {
|
|
ProjectPlatformHospitalRequest := requests.ProjectPlatformHospitalRequest{}
|
|
req := ProjectPlatformHospitalRequest.GetProjectPlatformHospitalPage
|
|
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.Page == 0 {
|
|
req.Page = 1
|
|
}
|
|
|
|
if req.PageSize == 0 {
|
|
req.PageSize = 20
|
|
}
|
|
|
|
// 获取数据
|
|
ProjectPlatformHospitalDao := dao.ProjectPlatformHospitalDao{}
|
|
ProjectPlatformHospitals, total, err := ProjectPlatformHospitalDao.GetProjectPlatformHospitalPageSearch(req, req.Page, req.PageSize)
|
|
if err != nil {
|
|
responses.FailWithMessage(err.Error(), c)
|
|
return
|
|
}
|
|
|
|
// 处理返回值
|
|
g := dto.GetProjectPlatformHospitalListDto(ProjectPlatformHospitals)
|
|
|
|
result := make(map[string]interface{})
|
|
result["page"] = req.Page
|
|
result["page_size"] = req.PageSize
|
|
result["total"] = total
|
|
result["data"] = g
|
|
responses.OkWithData(result, c)
|
|
}
|
|
|
|
// PutProjectPlatformHospitalStatus 操作状态
|
|
func (b *ProjectPlatformHospital) PutProjectPlatformHospitalStatus(c *gin.Context) {
|
|
ProjectPlatformHospitalRequest := requests.ProjectPlatformHospitalRequest{}
|
|
req := ProjectPlatformHospitalRequest.PutProjectPlatformHospitalStatus
|
|
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
|
|
}
|
|
|
|
id := c.Param("white_hospital_id")
|
|
if id == "" {
|
|
responses.FailWithMessage("缺少参数", c)
|
|
return
|
|
}
|
|
|
|
// 将 id 转换为 int64 类型
|
|
whiteHospitalId, err := strconv.ParseInt(id, 10, 64)
|
|
if err != nil {
|
|
responses.Fail(c)
|
|
return
|
|
}
|
|
|
|
ProjectPlatformHospitalDao := dao.ProjectPlatformHospitalDao{}
|
|
projectPlatformHospital, err := ProjectPlatformHospitalDao.GetProjectPlatformHospitalById(whiteHospitalId)
|
|
if err != nil {
|
|
responses.FailWithMessage("数据异常", c)
|
|
return
|
|
}
|
|
|
|
// 检测状态
|
|
if projectPlatformHospital.Status == req.Status {
|
|
responses.Ok(c)
|
|
return
|
|
}
|
|
|
|
// 开始事务
|
|
tx := global.Db.Begin()
|
|
defer func() {
|
|
if r := recover(); r != nil {
|
|
tx.Rollback()
|
|
}
|
|
}()
|
|
|
|
ProjectPlatformHospitalData := make(map[string]interface{})
|
|
ProjectPlatformHospitalData["status"] = req.Status
|
|
err = ProjectPlatformHospitalDao.EditProjectPlatformHospitalById(tx, whiteHospitalId, ProjectPlatformHospitalData)
|
|
if err != nil {
|
|
tx.Rollback()
|
|
responses.FailWithMessage("操作失败", c)
|
|
return
|
|
}
|
|
|
|
tx.Commit()
|
|
responses.Ok(c)
|
|
}
|
|
|
|
// AddProjectPlatformHospital 新增
|
|
func (b *ProjectPlatformHospital) AddProjectPlatformHospital(c *gin.Context) {
|
|
ProjectPlatformHospitalRequest := requests.ProjectPlatformHospitalRequest{}
|
|
req := ProjectPlatformHospitalRequest.AddProjectPlatformHospital
|
|
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
|
|
}
|
|
|
|
// 将 id 转换为 int64 类型
|
|
projectPlatformId, err := strconv.ParseInt(req.ProjectPlatformId, 10, 64)
|
|
if err != nil {
|
|
responses.Fail(c)
|
|
return
|
|
}
|
|
|
|
projectPlatformDao := dao.ProjectPlatformDao{}
|
|
_, err = projectPlatformDao.GetProjectPlatformById(projectPlatformId)
|
|
if err != nil {
|
|
responses.Fail(c)
|
|
return
|
|
}
|
|
|
|
// 检测关联医院
|
|
// 将 id 转换为 int64 类型
|
|
hospitalId, err := strconv.ParseInt(req.HospitalId, 10, 64)
|
|
if err != nil {
|
|
responses.Fail(c)
|
|
return
|
|
}
|
|
|
|
basicHospitalDao := dao.BasicHospitalDao{}
|
|
_, err = basicHospitalDao.GetBasicHospitalById(hospitalId)
|
|
if err != nil {
|
|
responses.FailWithMessage("医院数据异常", c)
|
|
return
|
|
}
|
|
|
|
// 检测是否重复
|
|
maps := make(map[string]interface{})
|
|
maps["project_platform_id"] = projectPlatformId
|
|
maps["hospital_id"] = hospitalId
|
|
projectPlatformHospitalDao := dao.ProjectPlatformHospitalDao{}
|
|
projectPlatformHospitals, _ := projectPlatformHospitalDao.GetProjectPlatformHospitalList(maps)
|
|
if len(projectPlatformHospitals) > 0 {
|
|
responses.FailWithMessage("重复添加", c)
|
|
return
|
|
}
|
|
|
|
// 开始事务
|
|
tx := global.Db.Begin()
|
|
defer func() {
|
|
if r := recover(); r != nil {
|
|
tx.Rollback()
|
|
}
|
|
}()
|
|
|
|
projectPlatformHospital := &model.ProjectPlatformHospital{
|
|
ProjectPlatformId: projectPlatformId,
|
|
HospitalId: hospitalId,
|
|
Status: *req.Status,
|
|
}
|
|
|
|
projectPlatformHospital, err = projectPlatformHospitalDao.AddProjectPlatformHospital(tx, projectPlatformHospital)
|
|
if err != nil {
|
|
tx.Rollback()
|
|
responses.FailWithMessage(err.Error(), c)
|
|
return
|
|
}
|
|
|
|
tx.Commit()
|
|
responses.Ok(c)
|
|
}
|
|
|
|
// DeleteProjectPlatformHospital 删除
|
|
func (b *ProjectPlatformHospital) DeleteProjectPlatformHospital(c *gin.Context) {
|
|
id := c.Param("white_hospital_id")
|
|
if id == "" {
|
|
responses.FailWithMessage("缺少参数", c)
|
|
return
|
|
}
|
|
|
|
// 将 id 转换为 int64 类型
|
|
whiteHospitalId, err := strconv.ParseInt(id, 10, 64)
|
|
if err != nil {
|
|
responses.Fail(c)
|
|
return
|
|
}
|
|
|
|
ProjectPlatformHospitalDao := dao.ProjectPlatformHospitalDao{}
|
|
_, err = ProjectPlatformHospitalDao.GetProjectPlatformHospitalById(whiteHospitalId)
|
|
if err != nil {
|
|
responses.FailWithMessage("数据异常", c)
|
|
return
|
|
}
|
|
|
|
// 开始事务
|
|
tx := global.Db.Begin()
|
|
defer func() {
|
|
if r := recover(); r != nil {
|
|
tx.Rollback()
|
|
}
|
|
}()
|
|
|
|
err = ProjectPlatformHospitalDao.DeleteProjectPlatformHospitalById(tx, whiteHospitalId)
|
|
if err != nil {
|
|
tx.Rollback()
|
|
responses.FailWithMessage("操作失败", c)
|
|
return
|
|
}
|
|
|
|
tx.Commit()
|
|
responses.Ok(c)
|
|
}
|
|
|
|
// GetProjectPlatformHospitalList 查询app医院-列表
|
|
func (b *ProjectPlatformHospital) GetProjectPlatformHospitalList(c *gin.Context) {
|
|
ProjectPlatformHospitalRequest := requests.ProjectPlatformHospitalRequest{}
|
|
req := ProjectPlatformHospitalRequest.GetProjectPlatformHospitalList
|
|
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
|
|
}
|
|
|
|
var g []*dto.BasicHospitalDto
|
|
|
|
// 获取医院信息-Name
|
|
hospitals, err := app.GetHospitalByName(req.HospitalName)
|
|
if err != nil {
|
|
responses.FailWithMessage(err.Error(), c)
|
|
return
|
|
}
|
|
|
|
if len(hospitals.Data) <= 0 {
|
|
responses.OkWithData(g, c)
|
|
return
|
|
}
|
|
|
|
// 开始事务
|
|
tx := global.Db.Begin()
|
|
defer func() {
|
|
if r := recover(); r != nil {
|
|
tx.Rollback()
|
|
}
|
|
}()
|
|
|
|
var basicHospitals []*model.BasicHospital
|
|
|
|
// 处理医院数据
|
|
basicHospitalDao := dao.BasicHospitalDao{}
|
|
for _, v := range hospitals.Data {
|
|
// 检测医院是否存在
|
|
maps := make(map[string]interface{})
|
|
maps["source"] = 2
|
|
maps["hospital_iden"] = v.Uuid
|
|
basicHospital, _ := basicHospitalDao.GetBasicHospital(maps)
|
|
if basicHospital != nil {
|
|
basicHospitals = append(basicHospitals, basicHospital)
|
|
|
|
continue
|
|
}
|
|
|
|
// 增加医院
|
|
hospital := &model.BasicHospital{
|
|
HospitalIden: v.Uuid,
|
|
HospitalName: v.Name,
|
|
Source: 2,
|
|
HospitalLevel: v.Level,
|
|
DoctorNumber: v.ExpertNum,
|
|
Province: v.ProvName,
|
|
City: "",
|
|
County: "",
|
|
Address: "",
|
|
}
|
|
|
|
basicHospital, err = basicHospitalDao.AddBasicHospital(tx, hospital)
|
|
if err != nil {
|
|
tx.Rollback()
|
|
responses.OkWithData(g, c)
|
|
return
|
|
}
|
|
|
|
basicHospitals = append(basicHospitals, basicHospital)
|
|
}
|
|
|
|
g = dto.GetBasicHospitalListDto(basicHospitals)
|
|
|
|
tx.Commit()
|
|
responses.OkWithData(g, c)
|
|
}
|
|
|
|
// ExportProjectPlatformHospital 导出
|
|
func (r *ProjectPlatformHospital) ExportProjectPlatformHospital(c *gin.Context) {
|
|
ProjectPlatformHospitalRequest := requests.ProjectPlatformHospitalRequest{}
|
|
req := ProjectPlatformHospitalRequest.ExportProjectPlatformHospital
|
|
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
|
|
}
|
|
|
|
// 获取数据
|
|
projectPlatformHospitalDao := dao.ProjectPlatformHospitalDao{}
|
|
projectPlatformHospitals, err := projectPlatformHospitalDao.GetProjectPlatformHospitalExportListSearch(req)
|
|
if err != nil {
|
|
responses.FailWithMessage(err.Error(), c)
|
|
return
|
|
}
|
|
|
|
if len(projectPlatformHospitals) <= 0 {
|
|
responses.FailWithMessage("无数据,不可导出", c)
|
|
return
|
|
}
|
|
|
|
// 业务处理
|
|
exportService := service.ExportService{}
|
|
ossAddress, err := exportService.ProjectPlatformHospital(projectPlatformHospitals)
|
|
if err != nil {
|
|
responses.FailWithMessage(err.Error(), c)
|
|
return
|
|
}
|
|
|
|
responses.OkWithData(ossAddress, c)
|
|
}
|