|
@@ -15,27 +15,41 @@ import ( |
|
|
func ImportBasicInfo(ctx *context.APIContext) { |
|
|
func ImportBasicInfo(ctx *context.APIContext) { |
|
|
file, _, err := ctx.GetFile("file") |
|
|
file, _, err := ctx.GetFile("file") |
|
|
if err != nil { |
|
|
if err != nil { |
|
|
ctx.JSON(http.StatusBadRequest, models.BaseErrorMessageApi(ctx.Tr("model_app.get_file_fail"))) |
|
|
|
|
|
|
|
|
log.Error("get file err", err) |
|
|
|
|
|
ctx.JSON(http.StatusBadRequest, models.BaseErrorMessageApi(ctx.Tr("tech.get_file_fail"))) |
|
|
return |
|
|
return |
|
|
} |
|
|
} |
|
|
defer file.Close() |
|
|
defer file.Close() |
|
|
|
|
|
|
|
|
f, err := excelize.OpenReader(file) |
|
|
f, err := excelize.OpenReader(file) |
|
|
if err != nil { |
|
|
if err != nil { |
|
|
ctx.JSON(http.StatusBadRequest, models.BaseErrorMessageApi(ctx.Tr("model_app.get_file_fail"))) |
|
|
|
|
|
|
|
|
log.Error("open file err", err) |
|
|
|
|
|
ctx.JSON(http.StatusBadRequest, models.BaseErrorMessageApi(ctx.Tr("tech.content_type_unsupported"))) |
|
|
return |
|
|
return |
|
|
} |
|
|
} |
|
|
rows, err := f.GetRows(f.GetSheetName(1)) |
|
|
rows, err := f.GetRows(f.GetSheetName(1)) |
|
|
if err != nil { |
|
|
if err != nil { |
|
|
ctx.JSON(http.StatusBadRequest, models.BaseErrorMessageApi(ctx.Tr("model_app.get_file_fail"))) |
|
|
|
|
|
|
|
|
ctx.JSON(http.StatusBadRequest, models.BaseErrorMessageApi(ctx.Tr("tech.content_type_unsupported"))) |
|
|
return |
|
|
return |
|
|
} |
|
|
} |
|
|
for i, row := range rows { |
|
|
for i, row := range rows { |
|
|
if i != 0 { |
|
|
if i != 0 { |
|
|
baseInfo := &models.TechConvergeBaseInfo{} |
|
|
baseInfo := &models.TechConvergeBaseInfo{} |
|
|
baseInfo.ProjectNumber = strings.TrimSpace(row[2]) |
|
|
baseInfo.ProjectNumber = strings.TrimSpace(row[2]) |
|
|
|
|
|
tbInDB, err := models.GetTechConvergeBaseInfoByProjectNumber(baseInfo.ProjectNumber) |
|
|
|
|
|
if err != nil && !models.IsErrTechConvergeBaseInfoNotExist(err) { |
|
|
|
|
|
log.Error("query err ", i, err) |
|
|
|
|
|
ctx.JSON(http.StatusBadRequest, models.BaseErrorMessageApi(ctx.Tr("tech.sql_err"))) |
|
|
|
|
|
return |
|
|
|
|
|
} |
|
|
|
|
|
if tbInDB != nil { |
|
|
|
|
|
baseInfo = tbInDB |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
baseInfo.ApplyYear, err = strconv.Atoi(strings.TrimSpace(row[1])) |
|
|
baseInfo.ApplyYear, err = strconv.Atoi(strings.TrimSpace(row[1])) |
|
|
log.Warn("base info apply year parse err ", i) |
|
|
|
|
|
|
|
|
if err != nil { |
|
|
|
|
|
log.Warn("base info apply year parse err ", i) |
|
|
|
|
|
} |
|
|
baseInfo.ProjectName = strings.TrimSpace(row[3]) |
|
|
baseInfo.ProjectName = strings.TrimSpace(row[3]) |
|
|
baseInfo.Type = strings.TrimSpace(row[16]) |
|
|
baseInfo.Type = strings.TrimSpace(row[16]) |
|
|
baseInfo.Owner = strings.TrimSpace(row[8]) |
|
|
baseInfo.Owner = strings.TrimSpace(row[8]) |
|
@@ -59,14 +73,31 @@ func ImportBasicInfo(ctx *context.APIContext) { |
|
|
baseInfo.Topic4 = strings.TrimSpace(row[34]) |
|
|
baseInfo.Topic4 = strings.TrimSpace(row[34]) |
|
|
baseInfo.Topic5 = strings.TrimSpace(row[35]) |
|
|
baseInfo.Topic5 = strings.TrimSpace(row[35]) |
|
|
|
|
|
|
|
|
replaceNewLineWithComma(strings.TrimSpace(row[36])) |
|
|
|
|
|
|
|
|
allIns := replaceNewLineWithComma(strings.TrimSpace(row[36])) |
|
|
|
|
|
if allIns != "" { |
|
|
|
|
|
allInsArray := strings.Split(allIns, ",") |
|
|
|
|
|
var allInsValid []string |
|
|
|
|
|
for _, ins := range allInsArray { |
|
|
|
|
|
if ins != "" { |
|
|
|
|
|
allInsValid = append(allInsValid, ins) |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
baseInfo.AllInstitution = strings.Join(allInsValid, ",") |
|
|
|
|
|
} |
|
|
|
|
|
if baseInfo.AllInstitution == "" { |
|
|
|
|
|
baseInfo.AllInstitution = baseInfo.Institution |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
//启智项目名称、科技项目名称、项目立项编号、项目承担单位、申报年度、所属省(省市)、单位性质、推荐单位、项目负责人、负责人电话、负责人邮箱 |
|
|
|
|
|
// //、项目联系人、联系人电话、联系人邮箱、 |
|
|
|
|
|
//、启动会时间、课题数量、课题一名称及承担单位、课题二名称及承担单位、课题三名称及承担单位、课题四名称及承担单位、课题五名称及承担单位、所有参与单位、申请账号、操作 |
|
|
|
|
|
|
|
|
err = baseInfo.InsertOrUpdate() |
|
|
|
|
|
if err != nil { |
|
|
|
|
|
log.Error("update err", i, err) |
|
|
|
|
|
ctx.JSON(http.StatusBadRequest, models.BaseErrorMessageApi(ctx.Tr("tech.sql_err"))) |
|
|
|
|
|
return |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
ctx.JSON(http.StatusOK, models.BaseOKMessageApi) |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
func replaceNewLineWithComma(s string) string { |
|
|
func replaceNewLineWithComma(s string) string { |
|
@@ -86,7 +117,7 @@ func replaceNewLineWithComma(s string) string { |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
/** |
|
|
/** |
|
|
2019.12-2023.12 |
|
|
|
|
|
|
|
|
input:2019.12-2023.12 output: 2019,2023 |
|
|
*/ |
|
|
*/ |
|
|
func getBeginEndYear(executePeriod string) (int, int) { |
|
|
func getBeginEndYear(executePeriod string) (int, int) { |
|
|
period := strings.Split(executePeriod, "-") |
|
|
period := strings.Split(executePeriod, "-") |
|
|