project_corp_info.go 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. package model
  2. import (
  3. "github.com/jinzhu/gorm"
  4. "time"
  5. )
  6. type ProjectCorpInfo struct {
  7. ID int64 `gorm:"column:ID;primary_key"`
  8. Code string `gorm:"column:Code"`
  9. CorpName string `gorm:"column:CorpName"`
  10. CorpCode string `gorm:"column:CorpCode"`
  11. AreaCode string `gorm:"column:AreaCode"`
  12. RegisterDate time.Time `gorm:"column:RegisterDate"`
  13. CorpType uint32 `gorm:"column:CorpType"`
  14. ProjectId int64 `gorm:"column:ProjectId"`
  15. }
  16. func (ProjectCorpInfo) TableName() string {
  17. return "ProjectCorpInfo"
  18. }
  19. func (p *ProjectCorpInfo) Insert(db *gorm.DB) error {
  20. return db.Table(p.TableName()).Create(p).Error
  21. }
  22. func (p *ProjectCorpInfo) 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 *ProjectCorpInfo) All(db *gorm.DB, where map[string]interface{}) (list []ProjectCorpInfo, 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 *ProjectCorpInfo) 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 *ProjectCorpInfo) 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. }