Browse Source

新建申请页面科技项目查询接口

2023
chenyifan01 2 years ago
parent
commit
8dda4d13e6
6 changed files with 86 additions and 1 deletions
  1. +43
    -0
      models/tech_converge_info.go
  2. +2
    -1
      routers/api/v1/api.go
  3. +9
    -0
      routers/api/v1/tech/repo.go
  4. +14
    -0
      routers/api/v1/tech/tech.go
  5. +3
    -0
      routers/response/api_response.go
  6. +15
    -0
      services/tech/tech.go

+ 43
- 0
models/tech_converge_info.go View File

@@ -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
}

+ 2
- 1
routers/api/v1/api.go View File

@@ -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())




+ 9
- 0
routers/api/v1/tech/repo.go View File

@@ -0,0 +1,9 @@
package tech

import (
"code.gitea.io/gitea/modules/context"
)

func CommitOpenIRepo(ctx *context.APIContext) {

}

+ 14
- 0
routers/api/v1/tech/tech.go View File

@@ -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))
}

+ 3
- 0
routers/response/api_response.go View File

@@ -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()}
}

+ 15
- 0
services/tech/tech.go View File

@@ -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
}

Loading…
Cancel
Save