project_progress.go 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. // Copyright 2019 github.com. All rights reserved.
  2. // Use of this source code is governed by github.com.
  3. package model
  4. import (
  5. "github.com/jinzhu/gorm"
  6. "go.uber.org/zap"
  7. "smart-enterprise-management/errors"
  8. "time"
  9. "github.com/jaryhe/gopkgs/logger"
  10. "encoding/json"
  11. )
  12. const (
  13. // 未完工
  14. ProjectProgressUnfinish = iota
  15. // 已完工
  16. ProjectProgressFinish
  17. // 延期
  18. ProjectProgressDelay
  19. )
  20. type TProjectSchedule struct {
  21. ID int64 `gorm:"column:id"`
  22. ProjectId int64 `gorm:"column:project_id"`
  23. Name string `gorm:"column:name"`
  24. ExpectStartTime time.Time `gorm:"column:expect_start_time"`
  25. ExpectEndTime time.Time `gorm:"column:expect_end_time"`
  26. RealityEndTime time.Time `gorm:"column:reality_end_time"`
  27. Image string `gorm:"column:image"`
  28. Status int64 `gorm:"column:status"`
  29. CreatedAt time.Time `gorm:"column:created_at"`
  30. UpdatedAt time.Time `gorm:"column:updated_at"`
  31. }
  32. func (TProjectSchedule) TableName() string {
  33. return "t_project_schedule"
  34. }
  35. func (p *TProjectSchedule) Del(db *gorm.DB, where map[string]interface{}) error {
  36. cond, val, err := whereBuild(where)
  37. if err != nil {
  38. return err
  39. }
  40. err = db.Table(p.TableName()).Where(cond, val...).Delete(p).Error
  41. if err != nil {
  42. fields, _ := json.Marshal(where)
  43. logger.Error("mysql",
  44. zap.String("sql", "delete from t_project_schedule"),
  45. zap.String("fields",string(fields)),
  46. zap.String("error", err.Error()))
  47. return errors.DataBaseError
  48. }
  49. return err
  50. }
  51. func (p *TProjectSchedule) Count(db *gorm.DB, where map[string]interface{}, or map[string]interface{}) (int64, error) {
  52. if len(where) > 0 || len(or) > 0{
  53. cond, val, err := whereBuildAndOr(where, or)
  54. if err != nil {
  55. return 0, err
  56. }
  57. ret := int64(0)
  58. err = db.Table(p.TableName()).Where(cond, val...).Count(&ret).Error
  59. return ret, err
  60. }
  61. ret := int64(0)
  62. err := db.Table(p.TableName()).Count(&ret).Error
  63. return ret, err
  64. }