diff --git a/models/tech_converge_info.go b/models/tech_converge_info.go index 5bfae375a..d921daada 100644 --- a/models/tech_converge_info.go +++ b/models/tech_converge_info.go @@ -5,34 +5,37 @@ import ( ) type TechConvergeBaseInfo struct { - ID int64 `xorm:"pk autoincr"` - ProjectNumber string `xorm:"index"` //项目立项编号 - ProjectName string //科技项目名称 - Institution string //项目承担单位 - ApplyYear int //申报年度 - Province string //所属省(省市) - Category string //单位性质 - Recommend string //推荐单位 - Owner string //项目负责人 - Phone string //负责人电话 - Email string //负责人邮箱 - Contact string //项目联系人 - ContactPhone string //联系人电话 - ContactEmail string //联系人邮箱 - ExecutePeriod int //执行周期 - ExecuteStartYear int //执行开始年份 - ExecuteEndYear int //执行结束年份 - ExecuteDeadLine string //执行期限 - Type string //项目类型 - StartUp timeutil.TimeStamp //启动会时间 - NameAndInstitution1 string - NameAndInstitution2 string - NameAndInstitution3 string - NameAndInstitution4 string - NameAndInstitution5 string - AllInstitution string `xorm:"TEXT"` - CreatedUnix timeutil.TimeStamp `xorm:"INDEX created"` - UpdatedUnix timeutil.TimeStamp `xorm:"INDEX updated"` + ID int64 `xorm:"pk autoincr"` + ProjectNumber string `xorm:"index"` //项目立项编号 + ProjectName string //科技项目名称 + Institution string //项目承担单位 + ApplyYear int //申报年度 + Province string //所属省(省市) + Category string //单位性质 + Recommend string //推荐单位 + Owner string //项目负责人 + Phone string //负责人电话 + Email string //负责人邮箱 + Contact string //项目联系人 + ContactPhone string //联系人电话 + ContactEmail string //联系人邮箱 + ExecuteMonth int //执行周期(月) + ExecuteStartYear int //执行开始年份 + ExecuteEndYear int //执行结束年份 + ExecutePeriod string //执行期限 + Type string //项目类型 + StartUp string //启动会时间 + NumberTopic int + Topic1 string + Topic2 string + Topic3 string + Topic4 string + Topic5 string + Topic6 string + Topic7 string + AllInstitution string `xorm:"TEXT"` + CreatedUnix timeutil.TimeStamp `xorm:"INDEX created"` + UpdatedUnix timeutil.TimeStamp `xorm:"INDEX updated"` } type RepoConvergeInfo struct { diff --git a/routers/api/v1/tech/tech.go b/routers/api/v1/tech/tech.go index e2f04d693..78777b2f2 100644 --- a/routers/api/v1/tech/tech.go +++ b/routers/api/v1/tech/tech.go @@ -3,6 +3,7 @@ package tech import ( "net/http" "strconv" + "strings" "github.com/lunny/log" @@ -32,17 +33,76 @@ func ImportBasicInfo(ctx *context.APIContext) { for i, row := range rows { if i != 0 { baseInfo := &models.TechConvergeBaseInfo{} - baseInfo.ProjectNumber = row[2] - baseInfo.ApplyYear, err = strconv.Atoi(row[1]) + baseInfo.ProjectNumber = strings.TrimSpace(row[2]) + baseInfo.ApplyYear, err = strconv.Atoi(strings.TrimSpace(row[1])) log.Warn("base info apply year parse err ", i) - baseInfo.ProjectName = row[3] - baseInfo.Type = row[16] - baseInfo.Owner = row[8] - baseInfo.Email = row[10] - baseInfo.Phone = row[9] - baseInfo.Recommend = row[7] - baseInfo.Institution = row[4] + baseInfo.ProjectName = strings.TrimSpace(row[3]) + baseInfo.Type = strings.TrimSpace(row[16]) + baseInfo.Owner = strings.TrimSpace(row[8]) + baseInfo.Email = strings.TrimSpace(row[10]) + baseInfo.Phone = strings.TrimSpace(row[9]) + baseInfo.Recommend = strings.TrimSpace(row[7]) + baseInfo.Institution = strings.TrimSpace(row[4]) + baseInfo.Category = strings.TrimSpace(row[6]) + baseInfo.Province = strings.TrimSpace(row[5]) + baseInfo.Contact = strings.TrimSpace(row[11]) + baseInfo.ContactPhone = strings.TrimSpace(row[12]) + baseInfo.ContactEmail = strings.TrimSpace(row[13]) + baseInfo.ExecuteMonth, _ = strconv.Atoi(strings.TrimSpace(row[14])) + baseInfo.ExecutePeriod = strings.TrimSpace(row[15]) + baseInfo.ExecuteStartYear, baseInfo.ExecuteEndYear = getBeginEndYear(baseInfo.ExecutePeriod) + baseInfo.StartUp = strings.TrimSpace(row[17]) + baseInfo.NumberTopic, _ = strconv.Atoi(strings.TrimSpace(row[30])) + baseInfo.Topic1 = strings.TrimSpace(row[31]) + baseInfo.Topic2 = strings.TrimSpace(row[32]) + baseInfo.Topic3 = strings.TrimSpace(row[33]) + baseInfo.Topic4 = strings.TrimSpace(row[34]) + baseInfo.Topic5 = strings.TrimSpace(row[35]) + + replaceNewLineWithComma(strings.TrimSpace(row[36])) + + //启智项目名称、科技项目名称、项目立项编号、项目承担单位、申报年度、所属省(省市)、单位性质、推荐单位、项目负责人、负责人电话、负责人邮箱 + // //、项目联系人、联系人电话、联系人邮箱、 + //、启动会时间、课题数量、课题一名称及承担单位、课题二名称及承担单位、课题三名称及承担单位、课题四名称及承担单位、课题五名称及承担单位、所有参与单位、申请账号、操作 + + } + } +} + +func replaceNewLineWithComma(s string) string { + const replacement = "," + + var replacer = strings.NewReplacer( + "\r\n", replacement, + "\r", replacement, + "\n", replacement, + "\v", replacement, + "\f", replacement, + "\u0085", replacement, + "\u2028", replacement, + "\u2029", replacement, + ) + return replacer.Replace(s) +} + +/** + 2019.12-2023.12 +*/ +func getBeginEndYear(executePeriod string) (int, int) { + period := strings.Split(executePeriod, "-") + if len(period) == 2 { + start := strings.Split(period[0], ".") + end := strings.Split(period[1], ".") + + if len(start) == 2 && len(end) == 2 { + startYear, err := strconv.Atoi(start[0]) + endYear, err1 := strconv.Atoi(end[0]) + if err == nil && err1 == nil { + return startYear, endYear + } } + } + return 0, 0 }