project.go 3.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. package model
  2. import (
  3. "github.com/jinzhu/gorm"
  4. "time"
  5. )
  6. type ProjectInfo struct {
  7. ID int64 `gorm:"column:ID;PRIMARY_KEY" json:"ID" form:"id"`
  8. Code string `gorm:"column:Code" json:"Code" form:"code"`
  9. Name string `gorm:"column:Name" json:"Name" form:"name"`
  10. Safetyno string `gorm:"column:SafetyNo" json:"SafetyNo" form:"safetyno"`
  11. Prjcode string `gorm:"column:PrjCode" json:"PrjCode" form:"prjcode"`
  12. Description string `gorm:"column:Description" json:"Description" form:"description"`
  13. Category uint32 `gorm:"column:Category" json:"Category" form:"category"`
  14. Constructtype uint32 `gorm:"column:ConstructType" json:"ConstructType" form:"constructtype"`
  15. InvestType string `gorm:"column:InvestType" json:"InvestType" form:"investtype"`
  16. Areacode string `gorm:"column:AreaCode" json:"AreaCode" form:"areacode"`
  17. Address string `gorm:"column:Address" json:"Address" form:"address"`
  18. Buildingarea float64 `gorm:"column:BuildingArea" json:"BuildingArea" form:"buildingarea"`
  19. Buildinglength float64 `gorm:"column:BuildingLength" json:"BuildingLength" form:"buildinglength"`
  20. Invest float64 `gorm:"column:Invest" json:"Invest" form:"invest"`
  21. Scale string `gorm:"column:Scale" json:"Scale" form:"scale"`
  22. Startdate time.Time `gorm:"column:StartDate" json:"StartDate" form:"startdate"`
  23. Enddate time.Time `gorm:"column:EndDate" json:"EndDate" form:"enddate"`
  24. Lng float64 `gorm:"column:Lng" json:"Lng" form:"lng"`
  25. Lat float64 `gorm:"column:Lat" json:"Lat" form:"lat"`
  26. Thirdpartyprojectcode string `gorm:"column:ThirdpartyProjectCode" json:"ThirdpartyProjectCode" form:"thirdpartyprojectcode"`
  27. Prjstatus uint32 `gorm:"column:PrjStatus" json:"PrjStatus" form:"prjstatus"`
  28. Effectpic string `gorm:"column:EffectPic" json:"EffectPic" form:"effectpic"`
  29. Planpic string `gorm:"column:PlanPic" json:"PlanPic" form:"planpic"`
  30. Createdat time.Time `gorm:"column:CreatedAt" json:"CreatedAt" form:"createdat"`
  31. Updatedat time.Time `gorm:"column:UpdatedAt" json:"UpdatedAt" form:"updatedat"`
  32. Cid int64 `gorm:"column:Cid" json:"cid"`
  33. }
  34. func (ProjectInfo) TableName() string {
  35. return "ProjectInfo"
  36. }
  37. func (p *ProjectInfo) List(db *gorm.DB, where map[string]interface{}, or map[string]interface{}, page int32, pageSize int32) (list []ProjectInfo, err error) {
  38. if len(where) > 0 || len(or) > 0 {
  39. cond, val, err := whereBuildAndOr(where, or)
  40. if err != nil {
  41. return list, err
  42. }
  43. if pageSize < 0 {
  44. result := db.Table(p.TableName()).Where(cond, val...).Order("CreatedAt desc").Find(&list)
  45. return list, result.Error
  46. }
  47. offset := (page - 1) * pageSize
  48. result := db.Table(p.TableName()).Where(cond, val...).Order("CreatedAt desc").Limit(pageSize).Offset(offset).Find(&list)
  49. return list, result.Error
  50. }
  51. if pageSize < 0 {
  52. result := db.Table(p.TableName()).Order("CreatedAt desc").Find(&list)
  53. return list, result.Error
  54. }
  55. offset := (page - 1) * pageSize
  56. result := db.Table(p.TableName()).Order("CreatedAt desc").Limit(pageSize).Offset(offset).Find(&list)
  57. return list, result.Error
  58. }
  59. func (p *ProjectInfo) Find(db *gorm.DB, where map[string]interface{}) error {
  60. cond, val, err := whereBuild(where)
  61. if err != nil {
  62. return err
  63. }
  64. return db.Table(p.TableName()).Where(cond, val...).First(p).Error
  65. }