project.go 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  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. "time"
  7. )
  8. type ProjectInfo struct {
  9. ID int64 `gorm:"column:ID" 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 int64 `gorm:"column:Category" json:"category" form:"category"`
  16. Constructtype int64 `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 int64 `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. }
  35. func (ProjectInfo) TableName() string {
  36. return "ProjectInfo"
  37. }
  38. func (p *ProjectInfo) List(db *gorm.DB, where map[string]interface{}) (list []ProjectInfo, err error) {
  39. if len(where) > 0 {
  40. cond, val, err := whereBuild(where)
  41. if err != nil {
  42. return list, err
  43. }
  44. result := db.Table(p.TableName()).Where(cond, val...).Find(&list)
  45. return list, result.Error
  46. }
  47. result := db.Table(p.TableName()).Find(&list)
  48. return list, result.Error
  49. }
  50. func (p *ProjectInfo) Find(db *gorm.DB, where map[string]interface{}, or map[string]interface{}) error {
  51. cond, val, err := whereBuildAndOr(where, or)
  52. if err != nil {
  53. return err
  54. }
  55. return db.Table(p.TableName()).Where(cond, val...).First(p).Error
  56. }