task_process.go 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. package model
  2. import (
  3. "github.com/jinzhu/gorm"
  4. "time"
  5. )
  6. type TaskProcessingInfo struct {
  7. ID int64 `gorm:"column:ID;PRIMARY_KEY"`
  8. Code string `gorm:"column:Code"`
  9. TaskID string `gorm:"column:TaskID"`
  10. TaskName string `gorm:"column:TaskName"`
  11. AssignmentDate time.Time `gorm:"column:AssignmentDate"`
  12. FinishDate time.Time `gorm:"column:FinishDate"`
  13. ProcessingPerson string `gorm:"column:processingperson"`
  14. Reviewer string `gorm:"column:Reviewer"`
  15. ProcessingDate time.Time `gorm:"column:ProcessingDate"`
  16. ProcessingResults string `gorm:"column:ProcessingResults"`
  17. Status int32 `gorm:"column:Status"`
  18. ProcessingResultsImg string `gorm:"column:ProcessingResultsImg"`
  19. Feedback string `gorm:"column:Feedback"`
  20. ProjectID int64 `gorm:"column:ProjectID"`
  21. TaskDesc string `gorm:"column:TaskDesc"`
  22. TaskType int32 `gorm:"column:TaskType"`
  23. TaskImg string `gorm:"column:TaskImg"`
  24. Pipeline string `gorm:"column:Pipeline"`
  25. ApproveDate time.Time `gorm:"column:ApproveDate"`
  26. ApproveImg string `gorm:"column:ApproveImg"`
  27. }
  28. const (
  29. PipelineCreate = 1
  30. PipelineProcessing = 2
  31. PipelineApprove = 3
  32. )
  33. type TaskPipeline struct {
  34. PipeType int32 `json:"pipe_type"`
  35. Person string `json:"person"`
  36. Desc string `json:"desc"`
  37. Img string `json:"img"`
  38. PipeTime string `json:"pipe_time"`
  39. ApproveStatus bool `json:"approve_status"`
  40. }
  41. func (TaskProcessingInfo) TableName() string {
  42. return "TaskProcessingInfo"
  43. }
  44. func (p *TaskProcessingInfo) List(db *gorm.DB, where map[string]interface{}, or map[string]interface{}, page int32, pageSize int32) (list []TaskProcessingInfo, err error) {
  45. if len(where) > 0 || len(or) > 0 {
  46. cond, val, err := whereBuildAndOr(where, or)
  47. if err != nil {
  48. return list, err
  49. }
  50. if pageSize < 0 {
  51. result := db.Table(p.TableName()).Where(cond, val...).Order("AssignmentDate desc").Find(&list)
  52. return list, result.Error
  53. }
  54. offset := (page - 1) * pageSize
  55. result := db.Table(p.TableName()).Where(cond, val...).Order("AssignmentDate desc").Limit(pageSize).Offset(offset).Find(&list)
  56. return list, result.Error
  57. }
  58. if pageSize < 0 {
  59. result := db.Table(p.TableName()).Order("AssignmentDate desc").Find(&list)
  60. return list, result.Error
  61. }
  62. offset := (page - 1) * pageSize
  63. result := db.Table(p.TableName()).Order("AssignmentDate desc").Limit(pageSize).Offset(offset).Find(&list)
  64. return list, result.Error
  65. }
  66. func (p *TaskProcessingInfo) Insert(db *gorm.DB) error {
  67. return db.Table(p.TableName()).Create(p).Error
  68. }
  69. func (p *TaskProcessingInfo) Del(db *gorm.DB, where map[string]interface{}) error {
  70. cond, val, err := whereBuild(where)
  71. if err != nil {
  72. return err
  73. }
  74. return db.Table(p.TableName()).Where(cond, val...).Delete(p).Error
  75. }
  76. func (p *TaskProcessingInfo) Find(db *gorm.DB, where map[string]interface{}) error {
  77. cond, val, err := whereBuild(where)
  78. if err != nil {
  79. return err
  80. }
  81. return db.Table(p.TableName()).Where(cond, val...).First(p).Error
  82. }
  83. func (p *TaskProcessingInfo) FindOr(db *gorm.DB, where map[string]interface{}, or map[string]interface{}) error {
  84. cond, val, err := whereBuildAndOr(where, or)
  85. if err != nil {
  86. return err
  87. }
  88. return db.Table(p.TableName()).Where(cond, val...).First(p).Error
  89. }
  90. func (p *TaskProcessingInfo) Update(db *gorm.DB, where map[string]interface{}, values map[string]interface{}) error {
  91. cond, val, err := whereBuild(where)
  92. if err != nil {
  93. return err
  94. }
  95. return db.Table(p.TableName()).Where(cond, val...).Updates(values).Error
  96. }
  97. func (p *TaskProcessingInfo) Count(db *gorm.DB, where map[string]interface{}, or map[string]interface{}) (int64, error) {
  98. if len(where) > 0 || len(or) > 0{
  99. cond, val, err := whereBuildAndOr(where, or)
  100. if err != nil {
  101. return 0, err
  102. }
  103. ret := int64(0)
  104. err = db.Table(p.TableName()).Where(cond, val...).Count(&ret).Error
  105. return ret, err
  106. }
  107. ret := int64(0)
  108. err := db.Table(p.TableName()).Count(&ret).Error
  109. return ret, err
  110. }