新增了用户参与记录导出
This commit is contained in:
@@ -49,6 +49,20 @@ type StatsCaseUserData struct {
|
||||
EndTime string // 结束参与时间
|
||||
}
|
||||
|
||||
// UserRecordData 用户参与记录
|
||||
type UserRecordData struct {
|
||||
Id string // id标识
|
||||
CaseName string // 病历名称
|
||||
UserName string // 姓名
|
||||
Province string // 省份
|
||||
UserMobile string // 手机号
|
||||
DoctorTitle string // 职称
|
||||
HospitalName string // 医院
|
||||
DepartmentName string // 科室
|
||||
PlatformName string // 平台名称
|
||||
OperateTime string // 操作时间
|
||||
}
|
||||
|
||||
// ProjectPlatformHospital 医院白名单
|
||||
func (r *ExportService) ProjectPlatformHospital(projectPlatformHospitals []*model.ProjectPlatformHospital) (string, error) {
|
||||
header := []utils.HeaderCellData{
|
||||
@@ -250,3 +264,96 @@ func (r *ExportService) StatsCaseUser(statsCaseUsers []*model.CaseUser) (string,
|
||||
ossPath = utils.AddOssDomain("/" + ossPath)
|
||||
return ossPath, nil
|
||||
}
|
||||
|
||||
// ExportUserRecord 用户参与记录导出
|
||||
func (r *ExportService) ExportUserRecord(userBehaviorRecords []*model.UserBehaviorRecord) (string, error) {
|
||||
header := []utils.HeaderCellData{
|
||||
{Value: "id标识", CellType: "string", NumberFmt: "", ColWidth: 25},
|
||||
{Value: "病历名称", CellType: "string", NumberFmt: "", ColWidth: 35},
|
||||
{Value: "姓名", CellType: "string", NumberFmt: "", ColWidth: 25},
|
||||
{Value: "省份", CellType: "string", NumberFmt: "", ColWidth: 25},
|
||||
{Value: "手机号", CellType: "string", NumberFmt: "", ColWidth: 18},
|
||||
{Value: "职称", CellType: "string", NumberFmt: "", ColWidth: 18},
|
||||
{Value: "医院", CellType: "string", NumberFmt: "", ColWidth: 35},
|
||||
{Value: "科室", CellType: "string", NumberFmt: "", ColWidth: 18},
|
||||
{Value: "平台名称", CellType: "string", NumberFmt: "", ColWidth: 18},
|
||||
{Value: "操作时间", CellType: "date", NumberFmt: "yyyy-mm-dd hh:mm:ss", ColWidth: 30},
|
||||
}
|
||||
|
||||
var dataSlice []interface{}
|
||||
for _, v := range userBehaviorRecords {
|
||||
var createdAt string
|
||||
if v.CreatedAt != (model.LocalTime{}) {
|
||||
createdAt = time.Time(v.StartTime).Format("2006-01-02 15:04:05")
|
||||
}
|
||||
|
||||
userRecordData := UserRecordData{
|
||||
Id: fmt.Sprintf("%d", v.RecordId),
|
||||
CaseName: "",
|
||||
UserName: "",
|
||||
Province: "",
|
||||
UserMobile: "",
|
||||
DoctorTitle: "",
|
||||
HospitalName: "",
|
||||
DepartmentName: "",
|
||||
PlatformName: "",
|
||||
OperateTime: createdAt,
|
||||
}
|
||||
|
||||
// 加载数据-平台名称
|
||||
if v.Platform != nil {
|
||||
userRecordData.PlatformName = v.Platform.PlatformName
|
||||
}
|
||||
|
||||
if v.Case != nil {
|
||||
userRecordData.CaseName = v.Platform.PlatformName
|
||||
}
|
||||
|
||||
if v.User != nil {
|
||||
// 加载数据-手机号
|
||||
userRecordData.UserMobile = v.User.UserMobile
|
||||
|
||||
// 加载数据-科室
|
||||
userRecordData.DepartmentName = v.User.DepartmentName
|
||||
|
||||
// 加载数据-职称
|
||||
userRecordData.DoctorTitle = utils.DoctorTitleToString(v.User.Title)
|
||||
|
||||
// 加载数据-用户名称
|
||||
userRecordData.UserName = v.User.UserName
|
||||
|
||||
// 加载数据-省份
|
||||
if v.User.Hospital != nil {
|
||||
userRecordData.Province = v.User.Hospital.Province
|
||||
|
||||
userRecordData.HospitalName = v.User.Hospital.HospitalName
|
||||
}
|
||||
}
|
||||
|
||||
dataSlice = append(dataSlice, userRecordData)
|
||||
}
|
||||
|
||||
file, err := utils.Export(header, dataSlice)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
||||
ossPath := "dev/"
|
||||
if config.C.Env == "prod" {
|
||||
ossPath = "prod/"
|
||||
}
|
||||
// 设置文件名字
|
||||
now := time.Now()
|
||||
dateTimeString := now.Format("20060102150405") // 当前时间字符串
|
||||
rand.New(rand.NewSource(time.Now().UnixNano())) // 设置随机数
|
||||
ossPath = ossPath + "export/用户参与记录" + 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
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user