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 4.7 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
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172
  1. package models
  2. import (
  3. "fmt"
  4. "strconv"
  5. "code.gitea.io/gitea/modules/timeutil"
  6. "xorm.io/builder"
  7. )
  8. const (
  9. TechHide = 1
  10. TechShow = 2
  11. TechMigrating = 3
  12. TechMigrateFailed = 4
  13. )
  14. const DefaultTechStatus = 2
  15. type TechConvergeBaseInfo struct {
  16. ID int64 `xorm:"pk autoincr"`
  17. ProjectNumber string `xorm:"UNIQUE NOT NULL"` //项目立项编号
  18. ProjectName string //科技项目名称
  19. Institution string //项目承担单位
  20. ApplyYear int //申报年度
  21. Province string //所属省(省市)
  22. Category string //单位性质
  23. Recommend string //推荐单位
  24. Owner string //项目负责人
  25. Phone string //负责人电话
  26. Email string //负责人邮箱
  27. Contact string //项目联系人
  28. ContactPhone string //联系人电话
  29. ContactEmail string //联系人邮箱
  30. ExecuteMonth int //执行周期(月)
  31. ExecuteStartYear int //执行开始年份
  32. ExecuteEndYear int //执行结束年份
  33. ExecutePeriod string //执行期限
  34. Type string //项目类型
  35. StartUp string //启动会时间
  36. NumberTopic int
  37. Topic1 string
  38. Topic2 string
  39. Topic3 string
  40. Topic4 string
  41. Topic5 string
  42. Topic6 string
  43. Topic7 string
  44. AllInstitution string `xorm:"TEXT"`
  45. CreatedUnix timeutil.TimeStamp `xorm:"INDEX created"`
  46. UpdatedUnix timeutil.TimeStamp `xorm:"INDEX updated"`
  47. }
  48. func (t *TechConvergeBaseInfo) Brief() *TechConvergeBrief {
  49. return &TechConvergeBrief{
  50. ProjectNumber: t.ProjectNumber,
  51. ProjectName: t.ProjectName,
  52. Institution: t.Institution,
  53. AllInstitution: t.AllInstitution,
  54. }
  55. }
  56. type RepoConvergeInfo struct {
  57. ID int64 `xorm:"pk autoincr"`
  58. RepoID int64
  59. Url string
  60. BaseInfoID int64
  61. Institution string
  62. UID int64
  63. Status int
  64. CreatedUnix timeutil.TimeStamp `xorm:"INDEX created"`
  65. UpdatedUnix timeutil.TimeStamp `xorm:"INDEX updated"`
  66. User *User `xorm:"-"`
  67. Repo *Repository `xorm:"-"`
  68. BaseInfo *TechConvergeBaseInfo `xorm:"-"`
  69. }
  70. func (r *RepoConvergeInfo) InsertOrUpdate() error {
  71. if r.ID != 0 {
  72. _, err := x.ID(r.ID).Update(r)
  73. return err
  74. } else {
  75. _, err := x.InsertOne(r)
  76. return err
  77. }
  78. }
  79. func GetTechConvergeBaseInfoByProjectNumber(projectNumber string) (*TechConvergeBaseInfo, error) {
  80. tb := &TechConvergeBaseInfo{ProjectNumber: projectNumber}
  81. return getTechConvergeBaseInfo(tb)
  82. }
  83. func (baseInfo *TechConvergeBaseInfo) InsertOrUpdate() error {
  84. if baseInfo.ID != 0 {
  85. _, err := x.ID(baseInfo.ID).Update(baseInfo)
  86. return err
  87. } else {
  88. _, err := x.InsertOne(baseInfo)
  89. return err
  90. }
  91. }
  92. type ErrTechConvergeBaseInfoNotExist struct {
  93. ID string
  94. }
  95. func (err ErrTechConvergeBaseInfoNotExist) Error() string {
  96. return fmt.Sprintf("TechConvergeBaseInfo does not exist [id: %s]", err.ID)
  97. }
  98. func IsErrTechConvergeBaseInfoNotExist(err error) bool {
  99. _, ok := err.(ErrTechConvergeBaseInfoNotExist)
  100. return ok
  101. }
  102. func getTechConvergeBaseInfo(tb *TechConvergeBaseInfo) (*TechConvergeBaseInfo, error) {
  103. has, err := x.Get(tb)
  104. if err != nil {
  105. return nil, err
  106. } else if !has {
  107. if tb.ProjectNumber != "" {
  108. return nil, ErrTechConvergeBaseInfoNotExist{tb.ProjectNumber}
  109. } else {
  110. return nil, ErrTechConvergeBaseInfoNotExist{strconv.FormatInt(tb.ID, 10)}
  111. }
  112. }
  113. return tb, nil
  114. }
  115. type TechConvergeBrief struct {
  116. ProjectNumber string `json:"no"` //项目立项编号
  117. ProjectName string `json:"name"` //科技项目名称
  118. Institution string `json:"institution"` //项目承担单位
  119. AllInstitution string `json:"all_institution"`
  120. }
  121. type FindTechOpt struct {
  122. TechNo string
  123. ProjectName string
  124. Institution string
  125. }
  126. func FindTech(opt FindTechOpt) ([]*TechConvergeBaseInfo, error) {
  127. var cond builder.Cond
  128. if opt.TechNo != "" {
  129. cond = cond.And(builder.Like{"project_number", opt.TechNo})
  130. }
  131. if opt.ProjectName != "" {
  132. cond = cond.And(builder.Like{"project_name", opt.ProjectName})
  133. }
  134. if opt.Institution != "" {
  135. cond = cond.And(builder.Like{"institution", opt.Institution}.Or(builder.Like{"all_institution", opt.Institution}))
  136. }
  137. r := make([]*TechConvergeBaseInfo, 0)
  138. err := x.Where(cond).OrderBy("updated_unix desc").Find(&r)
  139. if err != nil {
  140. return nil, err
  141. }
  142. return r, nil
  143. }
  144. func GetTechByTechNo(techNo string) (*TechConvergeBaseInfo, error) {
  145. var tech *TechConvergeBaseInfo
  146. has, err := x.Where("project_number = ?", techNo).Get(&tech)
  147. if err != nil {
  148. return nil, err
  149. } else if !has {
  150. return nil, ErrTechConvergeBaseInfoNotExist{}
  151. }
  152. return tech, nil
  153. }