project_progress.go 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  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:ProjectId"`
  23. Name string `gorm:"column:Name"`
  24. ExpectStartTime time.Time `gorm:"column:ExpectStartTime"`
  25. ExpectEndTime time.Time `gorm:"column:ExpectEndTime"`
  26. RealityEndTime time.Time `gorm:"column:RealityEndTime"`
  27. RealityStartTime time.Time `gorm:"column:RealityStartTime"`
  28. Image string `gorm:"column:Image"`
  29. Status int64 `gorm:"column:Status"`
  30. CreatedAt time.Time `gorm:"column:CreatedAt"`
  31. UpdatedAt time.Time `gorm:"column:UpdatedAt"`
  32. }
  33. func (TProjectSchedule) TableName() string {
  34. return "ProjectSchedule"
  35. }
  36. func (p *TProjectSchedule) Del(db *gorm.DB, where map[string]interface{}) error {
  37. cond, val, err := whereBuild(where)
  38. if err != nil {
  39. return err
  40. }
  41. err = db.Table(p.TableName()).Where(cond, val...).Delete(p).Error
  42. if err != nil {
  43. fields, _ := json.Marshal(where)
  44. logger.Error("mysql",
  45. zap.String("sql", "delete from ProjectSchedule"),
  46. zap.String("fields",string(fields)),
  47. zap.String("error", err.Error()))
  48. return errors.DataBaseError
  49. }
  50. return err
  51. }
  52. func (p *TProjectSchedule) Count(db *gorm.DB, where map[string]interface{}, or map[string]interface{}) (int64, error) {
  53. if len(where) > 0 || len(or) > 0{
  54. cond, val, err := whereBuildAndOr(where, or)
  55. if err != nil {
  56. return 0, err
  57. }
  58. ret := int64(0)
  59. err = db.Table(p.TableName()).Where(cond, val...).Count(&ret).Error
  60. return ret, err
  61. }
  62. ret := int64(0)
  63. err := db.Table(p.TableName()).Count(&ret).Error
  64. return ret, err
  65. }