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