|
@@ -3,6 +3,8 @@ package models |
|
|
import ( |
|
|
import ( |
|
|
"fmt" |
|
|
"fmt" |
|
|
"strconv" |
|
|
"strconv" |
|
|
|
|
|
"strings" |
|
|
|
|
|
"time" |
|
|
|
|
|
|
|
|
"code.gitea.io/gitea/modules/timeutil" |
|
|
"code.gitea.io/gitea/modules/timeutil" |
|
|
"xorm.io/builder" |
|
|
"xorm.io/builder" |
|
@@ -126,6 +128,133 @@ func getTechConvergeBaseInfo(tb *TechConvergeBaseInfo) (*TechConvergeBaseInfo, e |
|
|
return tb, nil |
|
|
return tb, nil |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
func GetProjectNames() []string { |
|
|
|
|
|
var names []string |
|
|
|
|
|
x.Table("tech_converge_base_info").Distinct("project_name").Find(&names) |
|
|
|
|
|
return names |
|
|
|
|
|
} |
|
|
|
|
|
func GetRepoIds() []int64 { |
|
|
|
|
|
var ids []int64 |
|
|
|
|
|
x.Table("repo_converge_info").Cols("repo_id").Find(&ids) |
|
|
|
|
|
return ids |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
func GetTechRepoTopics(limit int) []string { |
|
|
|
|
|
|
|
|
|
|
|
repoIds := GetRepoIds() |
|
|
|
|
|
if len(repoIds) == 0 { |
|
|
|
|
|
return []string{} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
//select name, repo_count from topic a, repo_topic b |
|
|
|
|
|
//where a.id=b.topic_id and repo_id in (1,3) order by repo_count desc |
|
|
|
|
|
incondition := "repo_id in (" |
|
|
|
|
|
|
|
|
|
|
|
const MaxINItems = 1000 |
|
|
|
|
|
for i := 0; i < len(repoIds); i++ { |
|
|
|
|
|
if i == len(repoIds)-1 { |
|
|
|
|
|
incondition += strconv.FormatInt(repoIds[i], 10) |
|
|
|
|
|
} else if (i+1)%MaxINItems == 0 { |
|
|
|
|
|
incondition += strconv.FormatInt(repoIds[i], 10) + ") or repo_id in (" |
|
|
|
|
|
} else { |
|
|
|
|
|
incondition += strconv.FormatInt(repoIds[i], 10) + "," |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
incondition += ")" |
|
|
|
|
|
|
|
|
|
|
|
sql := "select name, repo_count from topic a, repo_topic b where a.id=b.topic_id and (" + incondition + ") order by repo_count desc" |
|
|
|
|
|
if limit > 0 { |
|
|
|
|
|
sql += "limit " + strconv.Itoa(limit) |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
result, err := x.QueryString(sql) |
|
|
|
|
|
if err != nil { |
|
|
|
|
|
return []string{} |
|
|
|
|
|
} |
|
|
|
|
|
var topics []string |
|
|
|
|
|
for _, record := range result { |
|
|
|
|
|
topics = append(topics, record["name"]) |
|
|
|
|
|
} |
|
|
|
|
|
return topics |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
func GetProjectTypes() []string { |
|
|
|
|
|
|
|
|
|
|
|
sql := "SELECT COUNT(id) AS theCount, type from tech_converge_base_info GROUP BY type ORDER BY theCount DESC" |
|
|
|
|
|
result, err := x.QueryString(sql) |
|
|
|
|
|
if err != nil { |
|
|
|
|
|
return []string{} |
|
|
|
|
|
} |
|
|
|
|
|
var projectTypes []string |
|
|
|
|
|
for _, record := range result { |
|
|
|
|
|
projectTypes = append(projectTypes, record["type"]) |
|
|
|
|
|
} |
|
|
|
|
|
return projectTypes |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
func GetApplyExecuteYears() ([]int, []int) { |
|
|
|
|
|
apply, executeStart, executeEnd := GetYearInfos() |
|
|
|
|
|
applyEnd := time.Now().Year() |
|
|
|
|
|
|
|
|
|
|
|
var applyArray []int |
|
|
|
|
|
var executeArray []int |
|
|
|
|
|
|
|
|
|
|
|
for i := apply; i <= applyEnd; i++ { |
|
|
|
|
|
applyArray = append(applyArray, i) |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
for i := executeStart; i <= executeEnd; i++ { |
|
|
|
|
|
executeArray = append(executeArray, i) |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
return applyArray, executeArray |
|
|
|
|
|
} |
|
|
|
|
|
func GetYearInfos() (int, int, int) { |
|
|
|
|
|
|
|
|
|
|
|
sql := "select min(apply_year) as apply_year,min(CASE WHEN execute_start_year != 0 THEN execute_start_year END) as execute_start_year,max(execute_end_year) as execute_end_year from tech_converge_base_info" |
|
|
|
|
|
result, err := x.QueryString(sql) |
|
|
|
|
|
if err != nil { |
|
|
|
|
|
return 2018, 2019, 2024 |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
for _, record := range result { |
|
|
|
|
|
apply, _ := strconv.Atoi(record["apply_year"]) |
|
|
|
|
|
executeStart, _ := strconv.Atoi(record["execute_start_year"]) |
|
|
|
|
|
executeEnd, _ := strconv.Atoi(record["execute_end_year"]) |
|
|
|
|
|
return apply, executeStart, executeEnd |
|
|
|
|
|
} |
|
|
|
|
|
return 2018, 2019, 2024 |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
func GetAllInstitutions() []string { |
|
|
|
|
|
var names []string |
|
|
|
|
|
x.Table("tech_converge_base_info").Cols("all_institution").Find(&names) |
|
|
|
|
|
var allNames []string |
|
|
|
|
|
for _, name := range names { |
|
|
|
|
|
singleNames := strings.Split(name, ",") |
|
|
|
|
|
for _, singleName := range singleNames { |
|
|
|
|
|
if singleName != "" { |
|
|
|
|
|
if !contains(allNames, singleName) { |
|
|
|
|
|
allNames = append(allNames, singleName) |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
return allNames |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
func contains(s []string, e string) bool { |
|
|
|
|
|
for _, a := range s { |
|
|
|
|
|
if a == e { |
|
|
|
|
|
return true |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
return false |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
type TechConvergeBrief struct { |
|
|
type TechConvergeBrief struct { |
|
|
ProjectNumber string `json:"no"` //项目立项编号 |
|
|
ProjectNumber string `json:"no"` //项目立项编号 |
|
|
ProjectName string `json:"name"` //科技项目名称 |
|
|
ProjectName string `json:"name"` //科技项目名称 |
|
|