就诊人列表-导出
This commit is contained in:
parent
7d78e7f39e
commit
f972ee1f46
@ -253,3 +253,37 @@ func (r *Export) UserPatient(c *gin.Context) {
|
|||||||
|
|
||||||
responses.OkWithData(ossAddress, c)
|
responses.OkWithData(ossAddress, c)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// PatientFamily 就诊人列表
|
||||||
|
func (r *Export) PatientFamily(c *gin.Context) {
|
||||||
|
userPatientRequest := requests.PatientFamilyRequest{}
|
||||||
|
req := userPatientRequest.PatientFamilyExportList
|
||||||
|
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
|
||||||
|
}
|
||||||
|
|
||||||
|
// 获取数据
|
||||||
|
patientFamilyDao := dao.PatientFamilyDao{}
|
||||||
|
patientFamilys, err := patientFamilyDao.GetPatientFamilyExportListSearch(req)
|
||||||
|
if err != nil {
|
||||||
|
responses.FailWithMessage(err.Error(), c)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// 业务处理
|
||||||
|
exportService := service.ExportService{}
|
||||||
|
ossAddress, err := exportService.PatientFamily(patientFamilys)
|
||||||
|
if err != nil {
|
||||||
|
responses.FailWithMessage(err.Error(), c)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
responses.OkWithData(ossAddress, c)
|
||||||
|
}
|
||||||
|
|||||||
@ -16,28 +16,29 @@ type PatientFamily struct{}
|
|||||||
|
|
||||||
// GetPatientFamilyPage 获取就诊人列表-分页
|
// GetPatientFamilyPage 获取就诊人列表-分页
|
||||||
func (r *PatientFamily) GetPatientFamilyPage(c *gin.Context) {
|
func (r *PatientFamily) GetPatientFamilyPage(c *gin.Context) {
|
||||||
req := requests.PatientFamilyRequest{}
|
patientFamilyRequest := requests.PatientFamilyRequest{}
|
||||||
if err := c.ShouldBind(&req.GetPatientFamilyPage); err != nil {
|
req := patientFamilyRequest.GetPatientFamilyPage
|
||||||
|
if err := c.ShouldBind(&req); err != nil {
|
||||||
responses.FailWithMessage(err.Error(), c)
|
responses.FailWithMessage(err.Error(), c)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// 参数验证
|
// 参数验证
|
||||||
if err := global.Validate.Struct(req.GetPatientFamilyPage); err != nil {
|
if err := global.Validate.Struct(req); err != nil {
|
||||||
responses.FailWithMessage(utils.Translate(err), c)
|
responses.FailWithMessage(utils.Translate(err), c)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if req.GetPatientFamilyPage.Page == 0 {
|
if req.Page == 0 {
|
||||||
req.GetPatientFamilyPage.Page = 1
|
req.Page = 1
|
||||||
}
|
}
|
||||||
|
|
||||||
if req.GetPatientFamilyPage.PageSize == 0 {
|
if req.PageSize == 0 {
|
||||||
req.GetPatientFamilyPage.PageSize = 20
|
req.PageSize = 20
|
||||||
}
|
}
|
||||||
|
|
||||||
patientFamilyDao := dao.PatientFamilyDao{}
|
patientFamilyDao := dao.PatientFamilyDao{}
|
||||||
patientFamily, total, err := patientFamilyDao.GetPatientFamilyPageSearch(req.GetPatientFamilyPage, req.GetPatientFamilyPage.Page, req.GetPatientFamilyPage.PageSize)
|
patientFamily, total, err := patientFamilyDao.GetPatientFamilyPageSearch(req, req.Page, req.PageSize)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
responses.FailWithMessage(err.Error(), c)
|
responses.FailWithMessage(err.Error(), c)
|
||||||
return
|
return
|
||||||
@ -47,8 +48,8 @@ func (r *PatientFamily) GetPatientFamilyPage(c *gin.Context) {
|
|||||||
GetPatientFamilyPage := dto.GetPatientFamilyListDto(patientFamily)
|
GetPatientFamilyPage := dto.GetPatientFamilyListDto(patientFamily)
|
||||||
|
|
||||||
result := make(map[string]interface{})
|
result := make(map[string]interface{})
|
||||||
result["page"] = req.GetPatientFamilyPage.Page
|
result["page"] = req.Page
|
||||||
result["page_size"] = req.GetPatientFamilyPage.PageSize
|
result["page_size"] = req.PageSize
|
||||||
result["total"] = total
|
result["total"] = total
|
||||||
result["data"] = GetPatientFamilyPage
|
result["data"] = GetPatientFamilyPage
|
||||||
responses.OkWithData(result, c)
|
responses.OkWithData(result, c)
|
||||||
|
|||||||
@ -1,6 +1,7 @@
|
|||||||
package dao
|
package dao
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"errors"
|
||||||
"gorm.io/gorm"
|
"gorm.io/gorm"
|
||||||
"hospital-admin-api/api/model"
|
"hospital-admin-api/api/model"
|
||||||
"hospital-admin-api/api/requests"
|
"hospital-admin-api/api/requests"
|
||||||
@ -161,3 +162,88 @@ func (r *PatientFamilyDao) GetPatientFamilyPageSearch(req requests.GetPatientFam
|
|||||||
|
|
||||||
return m, totalRecords, nil
|
return m, totalRecords, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// GetPatientFamilyExportListSearch 获取家庭成员列表-导出
|
||||||
|
func (r *PatientFamilyDao) GetPatientFamilyExportListSearch(req requests.PatientFamilyExportList) (m []*model.PatientFamily, err error) {
|
||||||
|
// 构建查询条件
|
||||||
|
query := global.Db.Model(&model.PatientFamily{}).Select("family_id", "patient_id", "relation", "status", "card_name", "mobile_mask", "created_at")
|
||||||
|
|
||||||
|
// 患者表
|
||||||
|
query = query.Preload("UserPatient", func(db *gorm.DB) *gorm.DB {
|
||||||
|
return db.Omit("open_id", "union_id", "wx_session_key")
|
||||||
|
})
|
||||||
|
|
||||||
|
// 用户表
|
||||||
|
query = query.Preload("UserPatient.User", func(db *gorm.DB) *gorm.DB {
|
||||||
|
return db.Omit("user_password", "salt")
|
||||||
|
})
|
||||||
|
|
||||||
|
// 当前搜索数据
|
||||||
|
if req.Type == 1 {
|
||||||
|
// 状态
|
||||||
|
if req.Status != nil {
|
||||||
|
query = query.Where("status = ?", req.Status)
|
||||||
|
}
|
||||||
|
|
||||||
|
// 手机号
|
||||||
|
if req.Mobile != "" {
|
||||||
|
userSubQuery := global.Db.Model(&model.User{}).
|
||||||
|
Select("user_id").
|
||||||
|
Where("mobile = ?", req.Mobile)
|
||||||
|
|
||||||
|
userPatientSubQuery := global.Db.Model(&model.UserPatient{}).
|
||||||
|
Select("patient_id").
|
||||||
|
Where(gorm.Expr("user_id IN (?)", userSubQuery))
|
||||||
|
|
||||||
|
query = query.Where(gorm.Expr("patient_id IN (?)", userPatientSubQuery))
|
||||||
|
}
|
||||||
|
|
||||||
|
// 用户名称-用户-就诊人
|
||||||
|
if req.UserName != "" {
|
||||||
|
// 用户
|
||||||
|
patientFamilySubQuery := global.Db.Model(&model.UserPatient{}).
|
||||||
|
Select("patient_id").
|
||||||
|
Where("user_name LIKE ?", "%"+req.UserName+"%")
|
||||||
|
|
||||||
|
// 就诊人
|
||||||
|
query = query.Where("card_name LIKE ?", "%"+req.UserName+"%")
|
||||||
|
|
||||||
|
query = query.Or("patient_id IN (?)", patientFamilySubQuery).Or(query)
|
||||||
|
}
|
||||||
|
|
||||||
|
// 注册时间
|
||||||
|
if req.CreatedAt != "" {
|
||||||
|
cancelTime := strings.Split(req.CreatedAt, "&")
|
||||||
|
if len(cancelTime) == 2 {
|
||||||
|
startTime, _ := time.Parse("2006-01-02", cancelTime[0])
|
||||||
|
endTime, _ := time.Parse("2006-01-02", cancelTime[1])
|
||||||
|
|
||||||
|
if startTime == endTime {
|
||||||
|
endTime = endTime.Add(23*time.Hour + 59*time.Minute + 59*time.Second)
|
||||||
|
}
|
||||||
|
|
||||||
|
query = query.Where("created_at BETWEEN ? AND ?", startTime, endTime)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 当前选中数据
|
||||||
|
if req.Type == 2 {
|
||||||
|
if req.Id == "" {
|
||||||
|
return nil, errors.New("未提供需导出数据编号")
|
||||||
|
}
|
||||||
|
|
||||||
|
id := strings.Split(req.Id, ",")
|
||||||
|
query = query.Where("family_id IN (?)", id)
|
||||||
|
}
|
||||||
|
|
||||||
|
// 排序
|
||||||
|
query = query.Order("created_at desc")
|
||||||
|
|
||||||
|
err = query.Find(&m).Error
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
return m, nil
|
||||||
|
}
|
||||||
|
|||||||
@ -1,7 +1,8 @@
|
|||||||
package requests
|
package requests
|
||||||
|
|
||||||
type PatientFamilyRequest struct {
|
type PatientFamilyRequest struct {
|
||||||
GetPatientFamilyPage // 获取就诊人列表-分页
|
GetPatientFamilyPage // 获取就诊人列表-分页
|
||||||
|
PatientFamilyExportList // 获取就诊人列表-导出
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetPatientFamilyPage 获取就诊人列表-分页
|
// GetPatientFamilyPage 获取就诊人列表-分页
|
||||||
@ -13,3 +14,13 @@ type GetPatientFamilyPage struct {
|
|||||||
Mobile string `json:"mobile" form:"mobile" label:"手机号"`
|
Mobile string `json:"mobile" form:"mobile" label:"手机号"`
|
||||||
CreatedAt string `json:"created_at" form:"created_at" label:"添加时间"` // 时间区间,数组形式,下标0为开始时间,下标1为结束时间
|
CreatedAt string `json:"created_at" form:"created_at" label:"添加时间"` // 时间区间,数组形式,下标0为开始时间,下标1为结束时间
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// PatientFamilyExportList 获取就诊人列表-导出
|
||||||
|
type PatientFamilyExportList struct {
|
||||||
|
Type int `json:"type" form:"type" label:"类型" validate:"required,oneof=1 2 3"` // 1:当前搜索数据 2:当前选择数据 3:全部数据
|
||||||
|
Id string `json:"id" form:"id" label:"id"` // 选择数据的id,逗号分隔,当type为2时必填
|
||||||
|
UserName string `json:"user_name" form:"user_name" label:"用户名称"`
|
||||||
|
Status *int `json:"status" form:"status" label:"状态"` // (0:禁用 1:正常 2:删除)
|
||||||
|
Mobile string `json:"mobile" form:"mobile" label:"手机号"`
|
||||||
|
CreatedAt string `json:"created_at" form:"created_at" label:"添加时间"` // 时间区间,数组形式,下标0为开始时间,下标1为结束时间
|
||||||
|
}
|
||||||
|
|||||||
@ -628,7 +628,7 @@ func privateRouter(r *gin.Engine, api controller.Api) {
|
|||||||
patientGroup.POST("", api.Export.UserPatient)
|
patientGroup.POST("", api.Export.UserPatient)
|
||||||
|
|
||||||
// 就诊人列表
|
// 就诊人列表
|
||||||
patientGroup.POST("/family", api.UserCaCert.RenewUserCloudCert)
|
patientGroup.POST("/family", api.Export.PatientFamily)
|
||||||
}
|
}
|
||||||
|
|
||||||
// 订单
|
// 订单
|
||||||
|
|||||||
@ -183,6 +183,29 @@ type UserPatientData struct {
|
|||||||
CreatedAt time.Time // 创建时间
|
CreatedAt time.Time // 创建时间
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// PatientFamilyData 就诊人列表
|
||||||
|
type PatientFamilyData struct {
|
||||||
|
UserName string `json:"user_name"` // 账号名称
|
||||||
|
CardName string `json:"card_name"` // 患者姓名
|
||||||
|
Relation string `json:"relation"` // 与患者关系(1:本人 2:父母 3:爱人 4:子女 5:亲戚 6:其他)
|
||||||
|
Status string `json:"status"` // 状态(1:正常 2:删除)
|
||||||
|
Mobile string `json:"mobile"` // 用户电话
|
||||||
|
IsDefault string `json:"is_default"` // 是否默认(0:否 1:是)
|
||||||
|
Type string `json:"type"` // 身份类型(1:身份证 2:护照 3:港澳通行证 4:台胞证)
|
||||||
|
IdNumber string `json:"id_number"` // 证件号码
|
||||||
|
Sex string `json:"sex"` // 性别(0:未知 1:男 2:女)
|
||||||
|
Age string `json:"age"` // 年龄
|
||||||
|
Province string `json:"province"` // 省份
|
||||||
|
City string `json:"city"` // 城市
|
||||||
|
County string `json:"county"` // 区县
|
||||||
|
Height string `json:"height"` // 身高(cm)
|
||||||
|
Weight string `json:"weight"` // 体重(kg)
|
||||||
|
MaritalStatus string `json:"marital_status"` // 婚姻状况(0:未婚 1:已婚 2:离异)
|
||||||
|
NationName string `json:"nation_name"` // 民族名称
|
||||||
|
JobName string `json:"job_name"` // 职业名称
|
||||||
|
CreatedAt time.Time `json:"created_at"` // 创建时间
|
||||||
|
}
|
||||||
|
|
||||||
// DoctorWithdrawal 提现记录
|
// DoctorWithdrawal 提现记录
|
||||||
func (r *ExportService) DoctorWithdrawal(doctorWithdrawals []*model.DoctorWithdrawal) (string, error) {
|
func (r *ExportService) DoctorWithdrawal(doctorWithdrawals []*model.DoctorWithdrawal) (string, error) {
|
||||||
header := []utils.HeaderCellData{
|
header := []utils.HeaderCellData{
|
||||||
@ -1094,3 +1117,84 @@ func (r *ExportService) UserPatient(d []*model.UserPatient) (string, error) {
|
|||||||
ossPath = utils.AddOssDomain("/" + ossPath)
|
ossPath = utils.AddOssDomain("/" + ossPath)
|
||||||
return ossPath, nil
|
return ossPath, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// PatientFamily 就诊人列表
|
||||||
|
func (r *ExportService) PatientFamily(d []*model.PatientFamily) (string, error) {
|
||||||
|
header := []utils.HeaderCellData{
|
||||||
|
{Value: "账号名称", CellType: "string", NumberFmt: "", ColWidth: 18},
|
||||||
|
{Value: "患者姓名", CellType: "string", NumberFmt: "", ColWidth: 18},
|
||||||
|
{Value: "关系", CellType: "string", NumberFmt: "", ColWidth: 18},
|
||||||
|
{Value: "状态", CellType: "string", NumberFmt: "", ColWidth: 18},
|
||||||
|
{Value: "用户电话", CellType: "string", NumberFmt: "", ColWidth: 18},
|
||||||
|
{Value: "默认", CellType: "string", NumberFmt: "", ColWidth: 18},
|
||||||
|
{Value: "身份类型", CellType: "string", NumberFmt: "", ColWidth: 18},
|
||||||
|
{Value: "证件号码", CellType: "string", NumberFmt: "", ColWidth: 25},
|
||||||
|
{Value: "性别", CellType: "string", NumberFmt: "", ColWidth: 18},
|
||||||
|
{Value: "年龄", CellType: "string", NumberFmt: "", ColWidth: 18},
|
||||||
|
{Value: "省份", CellType: "string", NumberFmt: "", ColWidth: 20},
|
||||||
|
{Value: "城市", CellType: "string", NumberFmt: "", ColWidth: 22},
|
||||||
|
{Value: "区县", CellType: "string", NumberFmt: "", ColWidth: 25},
|
||||||
|
{Value: "身高(cm)", CellType: "string", NumberFmt: "", ColWidth: 18},
|
||||||
|
{Value: "体重(kg)", CellType: "string", NumberFmt: "", ColWidth: 18},
|
||||||
|
{Value: "婚姻状况", CellType: "string", NumberFmt: "", ColWidth: 18},
|
||||||
|
{Value: "民族名称", CellType: "string", NumberFmt: "", ColWidth: 22},
|
||||||
|
{Value: "职业名称", CellType: "string", NumberFmt: "", ColWidth: 22},
|
||||||
|
{Value: "创建时间", CellType: "date", NumberFmt: "yyyy-mm-dd hh:mm:ss", ColWidth: 30},
|
||||||
|
}
|
||||||
|
|
||||||
|
var dataSlice []interface{}
|
||||||
|
for _, v := range d {
|
||||||
|
data := PatientFamilyData{
|
||||||
|
CardName: v.CardName,
|
||||||
|
Relation: utils.RelationToString(*v.Relation),
|
||||||
|
Status: utils.PatientFamilyStatusToString(v.Status),
|
||||||
|
IsDefault: utils.IsDefaultToString(v.IsDefault),
|
||||||
|
Type: utils.CardTypeToString(v.Type),
|
||||||
|
IdNumber: v.IdNumber,
|
||||||
|
Sex: utils.SexToString(v.Sex),
|
||||||
|
Age: fmt.Sprintf("%d", v.Age),
|
||||||
|
Province: v.Province,
|
||||||
|
City: v.City,
|
||||||
|
County: v.County,
|
||||||
|
Height: v.Height,
|
||||||
|
Weight: v.Weight,
|
||||||
|
MaritalStatus: utils.MaritalStatusToString(v.MaritalStatus),
|
||||||
|
NationName: v.NationName,
|
||||||
|
JobName: v.JobName,
|
||||||
|
}
|
||||||
|
|
||||||
|
if v.UserPatient != nil {
|
||||||
|
data.UserName = v.UserPatient.UserName
|
||||||
|
if v.UserPatient.User != nil {
|
||||||
|
data.Mobile = v.UserPatient.User.Mobile
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if v.CreatedAt != (model.LocalTime{}) {
|
||||||
|
t := time.Time(v.CreatedAt)
|
||||||
|
data.CreatedAt = t
|
||||||
|
}
|
||||||
|
|
||||||
|
dataSlice = append(dataSlice, data)
|
||||||
|
}
|
||||||
|
|
||||||
|
file, err := utils.Export(header, dataSlice)
|
||||||
|
if err != nil {
|
||||||
|
return "", err
|
||||||
|
}
|
||||||
|
|
||||||
|
// 设置文件名字
|
||||||
|
now := time.Now()
|
||||||
|
dateTimeString := now.Format("20060102150405") // 当前时间字符串
|
||||||
|
rand.Seed(time.Now().UnixNano()) // 设置随机数
|
||||||
|
ossPath := "admin/export/output" + dateTimeString + fmt.Sprintf("%d", rand.Intn(9000)+1000) + ".xlsx"
|
||||||
|
|
||||||
|
// 上传oss
|
||||||
|
_, err = aliyun.PutObjectByte(ossPath, file.Bytes())
|
||||||
|
if err != nil {
|
||||||
|
return "", err
|
||||||
|
}
|
||||||
|
|
||||||
|
ossPath = utils.AddOssDomain("/" + ossPath)
|
||||||
|
return ossPath, nil
|
||||||
|
}
|
||||||
|
|||||||
@ -403,3 +403,61 @@ func EntryStatusToString(i int) string {
|
|||||||
return ""
|
return ""
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// RelationToString 与患者关系(1:本人 2:父母 3:爱人 4:子女 5:亲戚 6:其他)
|
||||||
|
func RelationToString(i int) string {
|
||||||
|
switch i {
|
||||||
|
case 1:
|
||||||
|
return "本人"
|
||||||
|
case 2:
|
||||||
|
return "父母"
|
||||||
|
case 3:
|
||||||
|
return "爱人"
|
||||||
|
case 4:
|
||||||
|
return "子女"
|
||||||
|
case 5:
|
||||||
|
return "亲戚"
|
||||||
|
case 6:
|
||||||
|
return "其他"
|
||||||
|
default:
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// PatientFamilyStatusToString 家庭成员状态(1:正常 2:删除)
|
||||||
|
func PatientFamilyStatusToString(i int) string {
|
||||||
|
switch i {
|
||||||
|
case 1:
|
||||||
|
return "正常"
|
||||||
|
case 2:
|
||||||
|
return "删除"
|
||||||
|
default:
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// IsDefaultToString 是否默认(0:否 1:是)
|
||||||
|
func IsDefaultToString(i int) string {
|
||||||
|
switch i {
|
||||||
|
case 0:
|
||||||
|
return "否"
|
||||||
|
case 1:
|
||||||
|
return "是"
|
||||||
|
default:
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// MaritalStatusToString 婚姻状况(0:未婚 1:已婚 2:离异)
|
||||||
|
func MaritalStatusToString(i int) string {
|
||||||
|
switch i {
|
||||||
|
case 0:
|
||||||
|
return "未婚"
|
||||||
|
case 1:
|
||||||
|
return "已婚"
|
||||||
|
case 2:
|
||||||
|
return "离异"
|
||||||
|
default:
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user