diff --git a/models/tech_converge_info.go b/models/tech_converge_info.go index cd45ba0ef..a4e19f7c4 100644 --- a/models/tech_converge_info.go +++ b/models/tech_converge_info.go @@ -5,6 +5,7 @@ import ( "strconv" "code.gitea.io/gitea/modules/timeutil" + "xorm.io/builder" ) type TechConvergeBaseInfo struct { @@ -41,6 +42,15 @@ type TechConvergeBaseInfo struct { UpdatedUnix timeutil.TimeStamp `xorm:"INDEX updated"` } +func (t *TechConvergeBaseInfo) Brief() *TechConvergeBrief { + return &TechConvergeBrief{ + ProjectNumber: t.ProjectNumber, + ProjectName: t.ProjectName, + Institution: t.Institution, + AllInstitution: t.AllInstitution, + } +} + type RepoConvergeInfo struct { ID int64 `xorm:"pk autoincr"` RepoID int64 @@ -96,3 +106,36 @@ func getTechConvergeBaseInfo(tb *TechConvergeBaseInfo) (*TechConvergeBaseInfo, e } return tb, nil } + +type TechConvergeBrief struct { + ProjectNumber string `json:"no"` //项目立项编号 + ProjectName string `json:"name"` //科技项目名称 + Institution string `json:"institution"` //项目承担单位 + AllInstitution string `json:"all_institution"` +} + +type FindTechOpt struct { + TechNo string + ProjectName string + Institution string +} + +func FindTech(opt FindTechOpt) ([]*TechConvergeBaseInfo, error) { + var cond builder.Cond + if opt.TechNo != "" { + cond = cond.And(builder.Like{"project_number", opt.TechNo}) + } + if opt.ProjectName != "" { + cond = cond.And(builder.Like{"project_name", opt.ProjectName}) + } + if opt.Institution != "" { + cond = cond.And(builder.Like{"institution", opt.Institution}.Or(builder.Like{"all_institution", opt.Institution})) + } + + r := make([]*TechConvergeBaseInfo, 0) + err := x.Where(cond).OrderBy("updated_unix desc").Find(&r) + if err != nil { + return nil, err + } + return r, nil +} diff --git a/routers/api/v1/api.go b/routers/api/v1/api.go index 36375a22e..7d6df4cae 100755 --- a/routers/api/v1/api.go +++ b/routers/api/v1/api.go @@ -538,8 +538,9 @@ func RegisterRoutes(m *macaron.Macaron) { }, reqToken()) m.Group("/tech", func() { - + m.Get("", tech.FindTech) m.Post("/basic", tech.ImportBasicInfo) + m.Post("/openi", tech.CommitOpenIRepo) }, reqToken()) diff --git a/routers/api/v1/tech/repo.go b/routers/api/v1/tech/repo.go new file mode 100644 index 000000000..9d0ec2947 --- /dev/null +++ b/routers/api/v1/tech/repo.go @@ -0,0 +1,9 @@ +package tech + +import ( + "code.gitea.io/gitea/modules/context" +) + +func CommitOpenIRepo(ctx *context.APIContext) { + +} diff --git a/routers/api/v1/tech/tech.go b/routers/api/v1/tech/tech.go index b2ae82f9f..6416a5036 100644 --- a/routers/api/v1/tech/tech.go +++ b/routers/api/v1/tech/tech.go @@ -1,6 +1,8 @@ package tech import ( + "code.gitea.io/gitea/routers/response" + techService "code.gitea.io/gitea/services/tech" "net/http" "strconv" "strings" @@ -137,3 +139,15 @@ func getBeginEndYear(executePeriod string) (int, int) { } return 0, 0 } + +func FindTech(ctx *context.APIContext) { + techNo := ctx.Query("no") + name := ctx.Query("name") + institution := ctx.Query("institution") + r, err := techService.FindTech(models.FindTechOpt{TechNo: techNo, ProjectName: name, Institution: institution}) + if err != nil { + ctx.JSON(http.StatusOK, response.OuterResponseError(err)) + return + } + ctx.JSON(http.StatusOK, response.OuterSuccessWithData(r)) +} diff --git a/routers/response/api_response.go b/routers/response/api_response.go index 5cc6ff78e..4a4c940e2 100644 --- a/routers/response/api_response.go +++ b/routers/response/api_response.go @@ -28,3 +28,6 @@ func OuterSuccessWithData(data interface{}) *AiforgeOuterResponse { func OuterErrorWithData(code int, msg string, data interface{}) *AiforgeOuterResponse { return &AiforgeOuterResponse{Code: code, Msg: msg, Data: data} } +func OuterResponseError(err error) *AiforgeOuterResponse { + return &AiforgeOuterResponse{Code: RESPONSE_CODE_ERROR_DEFAULT, Msg: err.Error()} +} diff --git a/services/tech/tech.go b/services/tech/tech.go new file mode 100644 index 000000000..450a03567 --- /dev/null +++ b/services/tech/tech.go @@ -0,0 +1,15 @@ +package tech + +import "code.gitea.io/gitea/models" + +func FindTech(opt models.FindTechOpt) ([]*models.TechConvergeBrief, error) { + techList, err := models.FindTech(opt) + if err != nil { + return nil, err + } + r := make([]*models.TechConvergeBrief, len(techList)) + for i := 0; i < len(techList); i++ { + r[i] = techList[i].Brief() + } + return r, nil +}