| @@ -5,6 +5,7 @@ import ( | |||||
| "strconv" | "strconv" | ||||
| "code.gitea.io/gitea/modules/timeutil" | "code.gitea.io/gitea/modules/timeutil" | ||||
| "xorm.io/builder" | |||||
| ) | ) | ||||
| type TechConvergeBaseInfo struct { | type TechConvergeBaseInfo struct { | ||||
| @@ -41,6 +42,15 @@ type TechConvergeBaseInfo struct { | |||||
| UpdatedUnix timeutil.TimeStamp `xorm:"INDEX updated"` | 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 { | type RepoConvergeInfo struct { | ||||
| ID int64 `xorm:"pk autoincr"` | ID int64 `xorm:"pk autoincr"` | ||||
| RepoID int64 | RepoID int64 | ||||
| @@ -96,3 +106,36 @@ func getTechConvergeBaseInfo(tb *TechConvergeBaseInfo) (*TechConvergeBaseInfo, e | |||||
| } | } | ||||
| return tb, nil | 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 | |||||
| } | |||||
| @@ -538,8 +538,9 @@ func RegisterRoutes(m *macaron.Macaron) { | |||||
| }, reqToken()) | }, reqToken()) | ||||
| m.Group("/tech", func() { | m.Group("/tech", func() { | ||||
| m.Get("", tech.FindTech) | |||||
| m.Post("/basic", tech.ImportBasicInfo) | m.Post("/basic", tech.ImportBasicInfo) | ||||
| m.Post("/openi", tech.CommitOpenIRepo) | |||||
| }, reqToken()) | }, reqToken()) | ||||
| @@ -0,0 +1,9 @@ | |||||
| package tech | |||||
| import ( | |||||
| "code.gitea.io/gitea/modules/context" | |||||
| ) | |||||
| func CommitOpenIRepo(ctx *context.APIContext) { | |||||
| } | |||||
| @@ -1,6 +1,8 @@ | |||||
| package tech | package tech | ||||
| import ( | import ( | ||||
| "code.gitea.io/gitea/routers/response" | |||||
| techService "code.gitea.io/gitea/services/tech" | |||||
| "net/http" | "net/http" | ||||
| "strconv" | "strconv" | ||||
| "strings" | "strings" | ||||
| @@ -137,3 +139,15 @@ func getBeginEndYear(executePeriod string) (int, int) { | |||||
| } | } | ||||
| return 0, 0 | 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)) | |||||
| } | |||||
| @@ -28,3 +28,6 @@ func OuterSuccessWithData(data interface{}) *AiforgeOuterResponse { | |||||
| func OuterErrorWithData(code int, msg string, data interface{}) *AiforgeOuterResponse { | func OuterErrorWithData(code int, msg string, data interface{}) *AiforgeOuterResponse { | ||||
| return &AiforgeOuterResponse{Code: code, Msg: msg, Data: data} | return &AiforgeOuterResponse{Code: code, Msg: msg, Data: data} | ||||
| } | } | ||||
| func OuterResponseError(err error) *AiforgeOuterResponse { | |||||
| return &AiforgeOuterResponse{Code: RESPONSE_CODE_ERROR_DEFAULT, Msg: err.Error()} | |||||
| } | |||||
| @@ -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 | |||||
| } | |||||