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 2.9 kB

2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. package models
  2. import (
  3. "fmt"
  4. "strconv"
  5. "code.gitea.io/gitea/modules/timeutil"
  6. )
  7. type TechConvergeBaseInfo struct {
  8. ID int64 `xorm:"pk autoincr"`
  9. ProjectNumber string `xorm:"UNIQUE NOT NULL"` //项目立项编号
  10. ProjectName string //科技项目名称
  11. Institution string //项目承担单位
  12. ApplyYear int //申报年度
  13. Province string //所属省(省市)
  14. Category string //单位性质
  15. Recommend string //推荐单位
  16. Owner string //项目负责人
  17. Phone string //负责人电话
  18. Email string //负责人邮箱
  19. Contact string //项目联系人
  20. ContactPhone string //联系人电话
  21. ContactEmail string //联系人邮箱
  22. ExecuteMonth int //执行周期(月)
  23. ExecuteStartYear int //执行开始年份
  24. ExecuteEndYear int //执行结束年份
  25. ExecutePeriod string //执行期限
  26. Type string //项目类型
  27. StartUp string //启动会时间
  28. NumberTopic int
  29. Topic1 string
  30. Topic2 string
  31. Topic3 string
  32. Topic4 string
  33. Topic5 string
  34. Topic6 string
  35. Topic7 string
  36. AllInstitution string `xorm:"TEXT"`
  37. CreatedUnix timeutil.TimeStamp `xorm:"INDEX created"`
  38. UpdatedUnix timeutil.TimeStamp `xorm:"INDEX updated"`
  39. }
  40. type RepoConvergeInfo struct {
  41. ID int64 `xorm:"pk autoincr"`
  42. RepoID int64
  43. Url string
  44. BaseInfoID int64
  45. Institution string
  46. UID int64
  47. Status int
  48. CreatedUnix timeutil.TimeStamp `xorm:"INDEX created"`
  49. UpdatedUnix timeutil.TimeStamp `xorm:"INDEX updated"`
  50. User *User `xorm:"-"`
  51. Repo *Repository `xorm:"-"`
  52. BaseInfo *TechConvergeBaseInfo `xorm:"-"`
  53. }
  54. func GetTechConvergeBaseInfoByProjectNumber(projectNumber string) (*TechConvergeBaseInfo, error) {
  55. tb := &TechConvergeBaseInfo{ProjectNumber: projectNumber}
  56. return getTechConvergeBaseInfo(tb)
  57. }
  58. func (baseInfo *TechConvergeBaseInfo) InsertOrUpdate() error {
  59. if baseInfo.ID != 0 {
  60. _, err := x.ID(baseInfo.ID).Update(baseInfo)
  61. return err
  62. } else {
  63. _, err := x.InsertOne(baseInfo)
  64. return err
  65. }
  66. }
  67. type ErrTechConvergeBaseInfoNotExist struct {
  68. ID string
  69. }
  70. func (err ErrTechConvergeBaseInfoNotExist) Error() string {
  71. return fmt.Sprintf("TechConvergeBaseInfo does not exist [id: %s]", err.ID)
  72. }
  73. func IsErrTechConvergeBaseInfoNotExist(err error) bool {
  74. _, ok := err.(ErrTechConvergeBaseInfoNotExist)
  75. return ok
  76. }
  77. func getTechConvergeBaseInfo(tb *TechConvergeBaseInfo) (*TechConvergeBaseInfo, error) {
  78. has, err := x.Get(tb)
  79. if err != nil {
  80. return nil, err
  81. } else if !has {
  82. if tb.ProjectNumber != "" {
  83. return nil, ErrTechConvergeBaseInfoNotExist{tb.ProjectNumber}
  84. } else {
  85. return nil, ErrTechConvergeBaseInfoNotExist{strconv.FormatInt(tb.ID, 10)}
  86. }
  87. }
  88. return tb, nil
  89. }