project.go 2.8 KB

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