You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

tech_converge_info.go 19 kB

2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660
  1. package models
  2. import (
  3. "strconv"
  4. "strings"
  5. "time"
  6. "code.gitea.io/gitea/modules/timeutil"
  7. "xorm.io/builder"
  8. )
  9. const (
  10. TechShow = 1
  11. TechHide = 2
  12. TechMigrating = 3
  13. TechMigrateFailed = 4
  14. TechNotExist = 5
  15. )
  16. const DefaultTechApprovedStatus = TechShow
  17. type TechConvergeBaseInfo struct {
  18. ID int64 `xorm:"pk autoincr"`
  19. ProjectNumber string `xorm:"UNIQUE NOT NULL"` //项目立项编号
  20. ProjectName string //科技项目名称
  21. Institution string //项目承担单位
  22. ApplyYear int //申报年度
  23. Province string //所属省(省市)
  24. Category string //单位性质
  25. Recommend string //推荐单位
  26. Owner string //项目负责人
  27. Phone string //负责人电话
  28. Email string //负责人邮箱
  29. Contact string //项目联系人
  30. ContactPhone string //联系人电话
  31. ContactEmail string //联系人邮箱
  32. ExecuteMonth int //执行周期(月)
  33. ExecuteStartYear int //执行开始年份
  34. ExecuteEndYear int //执行结束年份
  35. ExecutePeriod string //执行期限
  36. Type string //项目类型
  37. StartUp string //启动会时间
  38. NumberTopic int
  39. Topic1 string
  40. Topic2 string
  41. Topic3 string
  42. Topic4 string
  43. Topic5 string
  44. Topic6 string
  45. Topic7 string
  46. AllInstitution string `xorm:"TEXT"`
  47. CreatedUnix timeutil.TimeStamp `xorm:"INDEX created"`
  48. UpdatedUnix timeutil.TimeStamp `xorm:"INDEX updated"`
  49. }
  50. func (t *TechConvergeBaseInfo) Brief() *TechConvergeBrief {
  51. return &TechConvergeBrief{
  52. ProjectNumber: t.ProjectNumber,
  53. ProjectName: t.ProjectName,
  54. Institution: t.Institution,
  55. AllInstitution: t.AllInstitution,
  56. }
  57. }
  58. func (t *TechConvergeBaseInfo) IsValidInstitution(institution string) bool {
  59. if t.AllInstitution == "" && t.Institution == "" {
  60. return false
  61. }
  62. allInstitution := make([]string, 0)
  63. if t.AllInstitution != "" {
  64. allInstitution = strings.Split(t.AllInstitution, ",")
  65. }
  66. if t.Institution != "" {
  67. allInstitution = append(allInstitution, t.Institution)
  68. }
  69. newInstitution := strings.Split(institution, ",")
  70. total := len(newInstitution)
  71. matched := 0
  72. for _, n := range newInstitution {
  73. for _, s := range allInstitution {
  74. if s == n {
  75. matched++
  76. break
  77. }
  78. }
  79. }
  80. if matched == total {
  81. return true
  82. }
  83. return false
  84. }
  85. type RepoConvergeInfo struct {
  86. ID int64 `xorm:"pk autoincr"`
  87. RepoID int64
  88. Url string
  89. BaseInfoID int64
  90. Institution string
  91. UID int64
  92. Status int
  93. CreatedUnix timeutil.TimeStamp `xorm:"INDEX created"`
  94. UpdatedUnix timeutil.TimeStamp `xorm:"INDEX updated"`
  95. User *User `xorm:"-"`
  96. Repo *Repository `xorm:"-"`
  97. BaseInfo *TechConvergeBaseInfo `xorm:"-"`
  98. }
  99. func (r *RepoConvergeInfo) InsertOrUpdate() error {
  100. if r.ID != 0 {
  101. _, err := x.ID(r.ID).Update(r)
  102. return err
  103. } else {
  104. _, err := x.InsertOne(r)
  105. return err
  106. }
  107. }
  108. func GetTechConvergeBaseInfoByProjectNumber(projectNumber string) (*TechConvergeBaseInfo, error) {
  109. tb := &TechConvergeBaseInfo{ProjectNumber: projectNumber}
  110. return getTechConvergeBaseInfo(tb)
  111. }
  112. func GetTechConvergeBaseInfoById(id int64) (*TechConvergeBaseInfo, error) {
  113. tb := &TechConvergeBaseInfo{ID: id}
  114. return getTechConvergeBaseInfo(tb)
  115. }
  116. func (baseInfo *TechConvergeBaseInfo) InsertOrUpdate() error {
  117. if baseInfo.ID != 0 {
  118. _, err := x.ID(baseInfo.ID).Update(baseInfo)
  119. return err
  120. } else {
  121. _, err := x.InsertOne(baseInfo)
  122. return err
  123. }
  124. }
  125. type ErrTechConvergeBaseInfoNotExist struct {
  126. ID string
  127. }
  128. func (err ErrTechConvergeBaseInfoNotExist) Error() string {
  129. return "tech.tech_not_exist"
  130. }
  131. func IsErrTechConvergeBaseInfoNotExist(err error) bool {
  132. _, ok := err.(ErrTechConvergeBaseInfoNotExist)
  133. return ok
  134. }
  135. func getTechConvergeBaseInfo(tb *TechConvergeBaseInfo) (*TechConvergeBaseInfo, error) {
  136. has, err := x.Get(tb)
  137. if err != nil {
  138. return nil, err
  139. } else if !has {
  140. if tb.ProjectNumber != "" {
  141. return nil, ErrTechConvergeBaseInfoNotExist{tb.ProjectNumber}
  142. } else {
  143. return nil, ErrTechConvergeBaseInfoNotExist{strconv.FormatInt(tb.ID, 10)}
  144. }
  145. }
  146. return tb, nil
  147. }
  148. func GetProjectNames() []string {
  149. var names []string
  150. x.Table("tech_converge_base_info").Distinct("project_name").Find(&names)
  151. return names
  152. }
  153. func GetIdByProjectName(name string) []string {
  154. var ids []int64
  155. x.Table("tech_converge_base_info").Cols("id").Where("project_name=?", name).Find(&ids)
  156. idStrs := make([]string, 0, len(ids))
  157. for _, id := range ids {
  158. idStrs = append(idStrs, strconv.FormatInt(id, 10))
  159. }
  160. return idStrs
  161. }
  162. func GetSummitRepoIds() []int64 {
  163. var ids []int64
  164. x.Table("repo_converge_info").Cols("repo_id").Find(&ids)
  165. return ids
  166. }
  167. func GetTechRepoTopics(limit int) []string {
  168. repoIds := GetSummitRepoIds()
  169. if len(repoIds) == 0 {
  170. return []string{}
  171. }
  172. //select name, repo_count from topic a, repo_topic b
  173. //where a.id=b.topic_id and repo_id in (1,3) order by repo_count desc
  174. inCondition := "repo_id in ("
  175. const MaxINItems = 1000
  176. for i := 0; i < len(repoIds); i++ {
  177. if i == len(repoIds)-1 {
  178. inCondition += strconv.FormatInt(repoIds[i], 10)
  179. } else if (i+1)%MaxINItems == 0 {
  180. inCondition += strconv.FormatInt(repoIds[i], 10) + ") or repo_id in ("
  181. } else {
  182. inCondition += strconv.FormatInt(repoIds[i], 10) + ","
  183. }
  184. }
  185. inCondition += ")"
  186. sql := "select name, repo_count from topic a, repo_topic b where a.id=b.topic_id and (" + inCondition + ") order by repo_count desc"
  187. if limit > 0 {
  188. sql += "limit " + strconv.Itoa(limit)
  189. }
  190. result, err := x.QueryString(sql)
  191. if err != nil {
  192. return []string{}
  193. }
  194. var topics []string
  195. for _, record := range result {
  196. topics = append(topics, record["name"])
  197. }
  198. return topics
  199. }
  200. func GetProjectTypes() []string {
  201. sql := "SELECT COUNT(id) AS theCount, type from tech_converge_base_info GROUP BY type ORDER BY theCount DESC"
  202. result, err := x.QueryString(sql)
  203. if err != nil {
  204. return []string{}
  205. }
  206. var projectTypes []string
  207. for _, record := range result {
  208. projectTypes = append(projectTypes, record["type"])
  209. }
  210. return projectTypes
  211. }
  212. func GetApplyExecuteYears() ([]int, []int) {
  213. apply, executeStart, executeEnd := GetYearInfos()
  214. applyEnd := time.Now().Year()
  215. var applyArray []int
  216. var executeArray []int
  217. for i := apply; i <= applyEnd; i++ {
  218. applyArray = append(applyArray, i)
  219. }
  220. for i := executeStart; i <= executeEnd; i++ {
  221. executeArray = append(executeArray, i)
  222. }
  223. return applyArray, executeArray
  224. }
  225. func GetYearInfos() (int, int, int) {
  226. 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"
  227. result, err := x.QueryString(sql)
  228. if err != nil {
  229. return 2018, 2019, 2024
  230. }
  231. for _, record := range result {
  232. apply, _ := strconv.Atoi(record["apply_year"])
  233. executeStart, _ := strconv.Atoi(record["execute_start_year"])
  234. executeEnd, _ := strconv.Atoi(record["execute_end_year"])
  235. return apply, executeStart, executeEnd
  236. }
  237. return 2018, 2019, 2024
  238. }
  239. func GetAllInstitutions() []string {
  240. var names []string
  241. x.Table("tech_converge_base_info").Cols("all_institution").Find(&names)
  242. var allNames []string
  243. for _, name := range names {
  244. singleNames := strings.Split(name, ",")
  245. for _, singleName := range singleNames {
  246. if singleName != "" {
  247. if !contains(allNames, singleName) {
  248. allNames = append(allNames, singleName)
  249. }
  250. }
  251. }
  252. }
  253. return allNames
  254. }
  255. func contains(s []string, e string) bool {
  256. for _, a := range s {
  257. if a == e {
  258. return true
  259. }
  260. }
  261. return false
  262. }
  263. type SearchTechOpt struct {
  264. Q string //科技项目名称
  265. ProjectType string
  266. Institution string
  267. ApplyYear int
  268. ExecuteYear int
  269. OrderBy string
  270. ListOptions
  271. }
  272. type SearchRepoOpt struct {
  273. Q string //项目名称,简介
  274. ProjectName string
  275. Topic string
  276. Institution string
  277. OrderBy string
  278. ListOptions
  279. }
  280. type SearchUserRepoOpt struct {
  281. User *User
  282. ListOptions
  283. }
  284. type TechRepoInfoUser struct {
  285. ID int64 `json:"id"`
  286. ProjectNumber string `json:"no"`
  287. ProjectName string `json:"name"`
  288. Institution string `json:"institution"`
  289. AllInstitution string `json:"all_institution"`
  290. Url string `json:"url"`
  291. RepoName string `json:"repo_name"`
  292. RepoOwnerName string `json:"repo_owner_name"`
  293. ContributionInstitution string `json:"contribution_institution"`
  294. UserName string `json:"user_name"`
  295. Status int `json:"status"`
  296. CreatedUnix timeutil.TimeStamp `json:"created_unix"`
  297. UpdatedUnix timeutil.TimeStamp `json:"updated_unix"`
  298. }
  299. type TechRepoInfoAdmin struct {
  300. ID int64 `json:"id"`
  301. Url string `json:"url"`
  302. ContributionInstitution string `json:"contribution_institution"`
  303. Status int `json:"status"`
  304. ProjectNumber string `json:"no"`
  305. ProjectName string `json:"name"`
  306. Institution string `json:"institution"`
  307. Province string `json:"province"`
  308. Category string `json:"category"`
  309. Recommend string `json:"recommend"`
  310. Owner string `json:"owner"`
  311. Phone string `json:"phone"`
  312. Email string `json:"email"`
  313. Contact string `json:"contact"`
  314. ContactPhone string `json:"contact_phone"`
  315. ContactEmail string `json:"contact_email"`
  316. ExecuteMonth int `json:"execute_month"`
  317. ExecutePeriod string `json:"execute_period"`
  318. Type string `json:"type"`
  319. StartUp string `json:"start_up"`
  320. NumberTopic int `json:"number_topic"`
  321. Topic1 string `json:"topic1"`
  322. Topic2 string `json:"topic2"`
  323. Topic3 string `json:"topic3"`
  324. Topic4 string `json:"topic4"`
  325. Topic5 string `json:"topic5"`
  326. AllInstitution string `json:"all_institution"`
  327. RepoName string `json:"repo_name"`
  328. RepoOwnerName string `json:"repo_owner_name"`
  329. UserName string `json:"user_name"`
  330. CreatedUnix timeutil.TimeStamp `json:"created_unix"`
  331. UpdatedUnix timeutil.TimeStamp `json:"updated_unix"`
  332. }
  333. type RepoWithInstitution struct {
  334. ID int64 `json:"id"`
  335. OwnerID int64 `json:"owner_id"`
  336. OwnerName string `json:"owner_name"`
  337. Name string `json:"name"`
  338. Alias string `json:"alias"`
  339. Topics []string `json:"topics"`
  340. Description string `json:"description"`
  341. Institution string `json:"institution"`
  342. RelAvatarLink string `json:"rel_avatar_link"`
  343. UpdatedUnix timeutil.TimeStamp `json:"updated_unix"`
  344. }
  345. type TechRepoInfo struct {
  346. ID int64 `json:"id"`
  347. ProjectName string `json:"project_name"`
  348. Institution string `json:"institution"`
  349. Type string `json:"type"`
  350. ApplyYear int `json:"apply_year"`
  351. ExecutePeriod string `json:"execute_period"`
  352. AllInstitution string `json:"all_institution"`
  353. RepoCount int `json:"repo_numer"`
  354. Repos []*RepoWithInstitution
  355. }
  356. func ShowTechRepo(ids []int64, show bool) error {
  357. status := TechShow
  358. if !show {
  359. status = TechHide
  360. }
  361. idStrs := make([]string, 0, len(ids))
  362. for _, id := range ids {
  363. idStrs = append(idStrs, strconv.FormatInt(id, 10))
  364. }
  365. sql := "update repo_converge_info set status=? where id in (" + strings.Join(idStrs, ",") + ")"
  366. _, err := x.Exec(sql, status)
  367. return err
  368. }
  369. func GetTechRepoInfoForUser(opts *SearchUserRepoOpt) ([]*RepoConvergeInfo, int64, error) {
  370. cond := buildTechRepoForUserCondition(opts)
  371. total, err := x.Where(cond).Count(new(RepoConvergeInfo))
  372. if err != nil {
  373. return nil, 0, err
  374. }
  375. repoConvergeInfos := make([]*RepoConvergeInfo, 0)
  376. err = x.Where(cond).Limit(opts.PageSize, (opts.Page-1)*opts.PageSize).Desc("status").Find(&repoConvergeInfos)
  377. if err != nil {
  378. return nil, 0, err
  379. }
  380. loadAttributes(repoConvergeInfos)
  381. return repoConvergeInfos, total, nil
  382. }
  383. func loadAttributes(infos []*RepoConvergeInfo) {
  384. for _, info := range infos {
  385. info.User, _ = GetUserByID(info.UID)
  386. info.Repo, _ = GetRepositoryByID(info.RepoID)
  387. info.BaseInfo, _ = GetTechConvergeBaseInfoById(info.BaseInfoID)
  388. }
  389. }
  390. func buildTechRepoForUserCondition(opts *SearchUserRepoOpt) builder.Cond {
  391. var cond = builder.NewCond()
  392. if opts.User != nil {
  393. cond = cond.And(builder.Eq{"uid": opts.User.ID})
  394. }
  395. return cond
  396. }
  397. func GetAvailableRepoConvergeInfo(opt *SearchRepoOpt) ([]*RepoConvergeInfo, error) {
  398. repos := make([]*RepoConvergeInfo, 0)
  399. err := x.Table("repo_converge_info").Where(buildRepoFilterCond(opt)).Find(&repos)
  400. return repos, err
  401. }
  402. func buildRepoFilterCond(opt *SearchRepoOpt) string {
  403. sql := "status=" + strconv.Itoa(TechShow)
  404. if opt.Institution != "" {
  405. sql += " and (institution like '%" + opt.Institution + ",%'" + " or institution like '%," + opt.Institution + "%'" + " or institution = '" + opt.Institution + "')"
  406. }
  407. if opt.ProjectName != "" {
  408. baseInfoIds := GetIdByProjectName(opt.ProjectName)
  409. if len(baseInfoIds) > 0 {
  410. sql += " and base_info_id in (" + strings.Join(baseInfoIds, ",") + ")"
  411. }
  412. }
  413. return sql
  414. }
  415. func SearchTechRepoInfo(opt *SearchTechOpt) ([]*TechRepoInfo, int64, error) {
  416. sql := `select a.*,COALESCE(b.count,0) as repo_count, COALESCE(b.max,0) as max from tech_converge_base_info a left join
  417. (select base_info_id,count(id),max(updated_unix) from repo_converge_info where status=` + strconv.Itoa(TechShow) + ` GROUP BY base_info_id ) b
  418. on a.id=b.base_info_id`
  419. totalSql := "select count(*) from (" + sql + ") c" + buildTechFilterCond(opt)
  420. total, err := x.SQL(totalSql).Count(new(TechConvergeBaseInfo))
  421. resultList := make([]*TechRepoInfo, 0)
  422. if err != nil {
  423. return resultList, total, err
  424. }
  425. resultSql := "select id,project_name, institution,type,apply_year,execute_period,all_institution,repo_count from (" +
  426. sql + ") c " + buildTechFilterCond(opt) + opt.OrderBy + " offset " + strconv.Itoa((opt.Page-1)*opt.PageSize) + " limit " + strconv.Itoa(opt.PageSize)
  427. resultMap, err := x.QueryInterface(resultSql)
  428. if err == nil {
  429. for _, record := range resultMap {
  430. resultList = append(resultList, &TechRepoInfo{
  431. ID: record["id"].(int64),
  432. ProjectName: record["project_name"].(string),
  433. Institution: record["institution"].(string),
  434. Type: record["type"].(string),
  435. ApplyYear: int(record["apply_year"].(int64)),
  436. ExecutePeriod: record["execute_period"].(string),
  437. AllInstitution: record["all_institution"].(string),
  438. RepoCount: int(record["repo_count"].(int64)),
  439. })
  440. }
  441. }
  442. loadRepoInfoForTech(resultList)
  443. return resultList, total, err
  444. }
  445. func buildTechFilterCond(opt *SearchTechOpt) string {
  446. sql := ""
  447. if opt.Q != "" {
  448. sql += getWherePrefix(sql) + " project_name like '%" + opt.Q + "%'"
  449. }
  450. if opt.ProjectType != "" {
  451. sql += getWherePrefix(sql) + " type ='" + opt.ProjectType + "'"
  452. }
  453. if opt.ApplyYear != 0 {
  454. sql += getWherePrefix(sql) + " apply_year =" + strconv.Itoa(opt.ApplyYear)
  455. }
  456. if opt.Institution != "" {
  457. sql += getWherePrefix(sql) + " (all_institution like '%" + opt.Institution + ",%'" + " or all_institution like '%," + opt.Institution + "%'" + " or all_institution = '" + opt.Institution + "')"
  458. }
  459. if opt.ExecuteYear != 0 {
  460. sql += getWherePrefix(sql) + " execute_start_year <=" + strconv.Itoa(opt.ExecuteYear) + " and execute_end_year >=" + strconv.Itoa(opt.ExecuteYear)
  461. }
  462. return sql
  463. }
  464. func getWherePrefix(sql string) string {
  465. if sql == "" {
  466. return " where "
  467. }
  468. return " and "
  469. }
  470. func loadRepoInfoForTech(list []*TechRepoInfo) {
  471. for _, techRepo := range list {
  472. techRepo.Repos = []*RepoWithInstitution{}
  473. if techRepo.RepoCount > 0 {
  474. var repoIds []int64
  475. x.Table("repo_converge_info").Cols("repo_id").Where("base_info_id=?", techRepo.ID).Limit(2).Desc("updated_unix").Find(&repoIds)
  476. resultMap, err := GetRepositoriesMapByIDs(repoIds)
  477. if err == nil {
  478. for _, repoId := range repoIds {
  479. repo, ok := resultMap[repoId]
  480. if ok {
  481. techRepo.Repos = append(techRepo.Repos, &RepoWithInstitution{
  482. ID: repo.ID,
  483. Institution: techRepo.Institution,
  484. OwnerID: repo.OwnerID,
  485. OwnerName: repo.OwnerName,
  486. Name: repo.Name,
  487. Alias: repo.Alias,
  488. Topics: repo.Topics,
  489. Description: repo.Description,
  490. RelAvatarLink: repo.RelAvatarLink(),
  491. UpdatedUnix: repo.UpdatedUnix,
  492. })
  493. }
  494. }
  495. }
  496. }
  497. }
  498. }
  499. type TechConvergeBrief struct {
  500. ProjectNumber string `json:"no"` //项目立项编号
  501. ProjectName string `json:"name"` //科技项目名称
  502. Institution string `json:"institution"` //项目承担单位
  503. AllInstitution string `json:"all_institution"`
  504. }
  505. type FindTechOpt struct {
  506. TechNo string
  507. ProjectName string
  508. Institution string
  509. }
  510. func FindTech(opt FindTechOpt) ([]*TechConvergeBaseInfo, error) {
  511. var cond = builder.NewCond()
  512. if opt.TechNo != "" {
  513. cond = cond.And(builder.Like{"project_number", opt.TechNo})
  514. }
  515. if opt.ProjectName != "" {
  516. cond = cond.And(builder.Like{"project_name", opt.ProjectName})
  517. }
  518. if opt.Institution != "" {
  519. cond = cond.And(builder.Like{"institution", opt.Institution}.Or(builder.Like{"all_institution", opt.Institution}))
  520. }
  521. r := make([]*TechConvergeBaseInfo, 0)
  522. err := x.Where(cond).OrderBy("updated_unix desc").Find(&r)
  523. if err != nil {
  524. return nil, err
  525. }
  526. return r, nil
  527. }
  528. func GetTechByTechNo(techNo string) (*TechConvergeBaseInfo, error) {
  529. var tech = &TechConvergeBaseInfo{}
  530. has, err := x.Where("project_number = ?", techNo).Get(tech)
  531. if err != nil {
  532. return nil, err
  533. } else if !has {
  534. return nil, ErrTechConvergeBaseInfoNotExist{}
  535. }
  536. return tech, nil
  537. }
  538. type GetRepoConvergeOpts struct {
  539. RepoId int64
  540. BaseInfoId int64
  541. Status []int
  542. }
  543. func GetRepoConverge(opts GetRepoConvergeOpts) ([]*RepoConvergeInfo, error) {
  544. r := make([]*RepoConvergeInfo, 0)
  545. cond := builder.NewCond()
  546. if opts.RepoId > 0 {
  547. cond = cond.And(builder.Eq{"repo_id": opts.RepoId})
  548. }
  549. if opts.BaseInfoId > 0 {
  550. cond = cond.And(builder.Eq{"base_info_id": opts.BaseInfoId})
  551. }
  552. if len(opts.Status) > 0 {
  553. cond = cond.And(builder.In("status", opts.Status))
  554. }
  555. err := x.Where(cond).Find(&r)
  556. if err != nil {
  557. return nil, err
  558. }
  559. return r, nil
  560. }
  561. func UpdateRepoConvergeStatus(id int64, status int) (int64, error) {
  562. return x.ID(id).Update(&RepoConvergeInfo{
  563. Status: status,
  564. })
  565. }