project_pm_info.go 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. package model
  2. import "github.com/jinzhu/gorm"
  3. type ProjectPMInfo struct {
  4. ID int64 `gorm:"column:ID;primary_key"`
  5. Code string `gorm:"column:Code"`
  6. CorpType uint32 `gorm:"column:CorpType"`
  7. CorpCode string `gorm:"column:CorpCode"`
  8. PType uint32 `gorm:"column:PType"`
  9. PMName string `gorm:"column:PMName"`
  10. PMIDCardType uint32 `gorm:"column:PMIDCardType"`
  11. PMIDCardNumber string `gorm:"column:PMIDCardNumber"`
  12. PMPhone string `gorm:"column:PMPhone"`
  13. ProjectId int64 `gorm:"column:ProjectId"`
  14. CorpName string `gorm:"column:CorpName"`
  15. }
  16. func (ProjectPMInfo) TableName() string {
  17. return "db_smart_attendance.ProjectPMInfo"
  18. }
  19. func (p *ProjectPMInfo) Insert(db *gorm.DB) error {
  20. return db.Table(p.TableName()).Create(p).Error
  21. }
  22. func (p *ProjectPMInfo) Find(db *gorm.DB, where map[string]interface{}, or map[string]interface{}) error {
  23. cond, val, err := whereBuildAndOr(where, or)
  24. if err != nil {
  25. return err
  26. }
  27. return db.Table(p.TableName()).Where(cond, val...).First(p).Error
  28. }
  29. func (p *ProjectPMInfo) All(db *gorm.DB, where map[string]interface{}) (list []ProjectPMInfo, err error) {
  30. if len(where) > 0 {
  31. cond, val, err := whereBuild(where)
  32. if err != nil {
  33. return nil, err
  34. }
  35. result := db.Table(p.TableName()).Where(cond, val).Find(&list)
  36. return list, result.Error
  37. }
  38. result := db.Table(p.TableName()).Find(&list)
  39. return list, result.Error
  40. }
  41. func (p *ProjectPMInfo) Count(db *gorm.DB, where map[string]interface{}) (int64, error) {
  42. if len(where) > 0 {
  43. cond, val, err := whereBuild(where)
  44. if err != nil {
  45. return 0, err
  46. }
  47. ret := int64(0)
  48. err = db.Table(p.TableName()).Where(cond, val...).Count(&ret).Error
  49. return ret, err
  50. }
  51. ret := int64(0)
  52. err := db.Table(p.TableName()).Count(&ret).Error
  53. return ret, err
  54. }
  55. func (p *ProjectPMInfo) Del(db *gorm.DB, where map[string]interface{}) error {
  56. cond, val, err := whereBuild(where)
  57. if err != nil {
  58. return err
  59. }
  60. return db.Table(p.TableName()).Where(cond, val...).Delete(p).Error
  61. }