vedio.go 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234
  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. "fmt"
  6. "github.com/jinzhu/gorm"
  7. "time"
  8. )
  9. type Vssdevtbl struct {
  10. Id int64 `gorm:"column:ID" json:"id" form:"id"`
  11. Devpubid string `gorm:"column:DevPubID" json:"devpubid" form:"devpubid"`
  12. Devnickname string `gorm:"column:DevNickname" json:"devnickname" form:"devnickname"`
  13. Username string `gorm:"column:UserName" json:"username" form:"username"`
  14. Passwd string `gorm:"column:Passwd" json:"passwd" form:"passwd"`
  15. Corpid string `gorm:"column:CorpID" json:"corpid" form:"corpid"`
  16. Ip string `gorm:"column:IP" json:"ip" form:"ip"`
  17. Port int64 `gorm:"column:Port" json:"port" form:"port"`
  18. Alive int64 `gorm:"column:Alive" json:"alive" form:"alive"`
  19. Subcatalogtime int64 `gorm:"column:SubCatalogTime" json:"subcatalogtime" form:"subcatalogtime"`
  20. Devmode string `gorm:"column:DevMode" json:"devmode" form:"devmode"`
  21. Mediatransport string `gorm:"column:MediaTransport" json:"mediatransport" form:"mediatransport"`
  22. Dmarker int64 `gorm:"column:DMarker" json:"dmarker" form:"dmarker"`
  23. UpdateTime time.Time `gorm:"column:updatetime" json:"updatetime" form:"updatetime"`
  24. ChannelCount int
  25. }
  26. func (Vssdevtbl) TableName() string {
  27. return "VSSDevTbl"
  28. }
  29. func (p *Vssdevtbl) Insert(db *gorm.DB) error {
  30. return db.Create(p).Error
  31. }
  32. func (p *Vssdevtbl) Del(db *gorm.DB, where map[string]interface{}) error {
  33. cond, val, err := whereBuild(where)
  34. if err != nil {
  35. return err
  36. }
  37. return db.Table(p.TableName()).Where(cond, val...).Delete(p).Error
  38. }
  39. func (p *Vssdevtbl) 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 *Vssdevtbl) Update(db *gorm.DB, where map[string]interface{}, values map[string]interface{}) error {
  47. cond, val, err := whereBuild(where)
  48. if err != nil {
  49. return err
  50. }
  51. return db.Table(p.TableName()).Where(cond, val...).Updates(values).Error
  52. }
  53. func (p *Vssdevtbl) FindSort(db *gorm.DB, where map[string]interface{}, sort string) error {
  54. cond, val, err := whereBuild(where)
  55. if err != nil {
  56. return err
  57. }
  58. ps := []Vssdevtbl{}
  59. err = db.Table(p.TableName()).Where(cond, val...).Order(sort).Limit(1).Find(&ps).Error
  60. if err != nil {
  61. return err
  62. }
  63. if len(ps) > 0 {
  64. *p = ps[0]
  65. }
  66. return nil
  67. }
  68. func (p *Vssdevtbl) Save(db *gorm.DB) error {
  69. return db.Save(p).Error
  70. }
  71. func (p *Vssdevtbl) Count(db *gorm.DB, where map[string]interface{}) (int64, error) {
  72. if len(where) > 0 {
  73. cond, val, err := whereBuild(where)
  74. if err != nil {
  75. return 0, err
  76. }
  77. ret := int64(0)
  78. err = db.Table(p.TableName()).Where(cond, val...).Count(&ret).Error
  79. return ret, err
  80. }
  81. ret := int64(0)
  82. err := db.Table(p.TableName()).Count(&ret).Error
  83. return ret, err
  84. }
  85. func (p *Vssdevtbl) List(db *gorm.DB, where map[string]interface{}, page int) (list []Vssdevtbl, err error) {
  86. offset := (int(page) - 1) *PageSize
  87. if len(where) > 0 {
  88. cond, val, err := whereBuild(where)
  89. if err != nil {
  90. return list, err
  91. }
  92. result := db.Table(p.TableName()).Where(cond, val...).Limit(PageSize).Offset(offset).Find(&list)
  93. return list, result.Error
  94. }
  95. result := db.Table(p.TableName()).Limit(PageSize).Offset(offset).Find(&list)
  96. return list, result.Error
  97. }
  98. type Vsschanneltbl struct {
  99. ID int64 `gorm:"column:ID"`
  100. Devpubid string `gorm:"column:DevPubID"`
  101. Restype int64 `gorm:"column:ResType"`
  102. Nickname string `gorm:"column:Nickname"`
  103. Chanpubid string `gorm:"column:ChanPubID"`
  104. Alive int64 `gorm:"column:Alive"`
  105. Corpid string `gorm:"column:CorpID"`
  106. Model string `gorm:"column:Model"`
  107. Owner string `gorm:"column:Owner"`
  108. Civilcode string `gorm:"column:CivilCode"`
  109. Address string `gorm:"column:Address"`
  110. Parental int64 `gorm:"column:Parental"`
  111. Parentid string `gorm:"column:ParentId"`
  112. Ip string `gorm:"column:IP"`
  113. Port int64 `gorm:"column:Port"`
  114. Longitude float64 `gorm:"column:Longitude"`
  115. Latitude float64 `gorm:"column:Latitude"`
  116. Altitude float64 `gorm:"column:Altitude"`
  117. Ptztype int64 `gorm:"column:PTZType"`
  118. Roomtype int64 `gorm:"column:RoomType"`
  119. Directiontype int64 `gorm:"column:DirectionType"`
  120. Streamtype int64 `gorm:"column:StreamType"`
  121. Chanrtspurl string `gorm:"column:ChanRtspUrl"`
  122. Realrtspurl string `gorm:"column:RealRtspUrl"`
  123. Dmarker int64 `gorm:"column:DMarker"`
  124. Updatetime time.Time `gorm:"column:UpdateTime"`
  125. }
  126. func (Vsschanneltbl) TableName() string {
  127. return "VSSChannelTbl"
  128. }
  129. func (p *Vsschanneltbl) Insert(db *gorm.DB) error {
  130. return db.Create(p).Error
  131. }
  132. func (p *Vsschanneltbl) Del(db *gorm.DB, where map[string]interface{}) error {
  133. cond, val, err := whereBuild(where)
  134. if err != nil {
  135. return err
  136. }
  137. return db.Table(p.TableName()).Where(cond, val...).Delete(p).Error
  138. }
  139. func (p *Vsschanneltbl) Find(db *gorm.DB, where map[string]interface{}) error {
  140. cond, val, err := whereBuild(where)
  141. if err != nil {
  142. return err
  143. }
  144. return db.Table(p.TableName()).Where(cond, val...).First(p).Error
  145. }
  146. func (p *Vsschanneltbl) Update(db *gorm.DB, where map[string]interface{}, values map[string]interface{}) error {
  147. cond, val, err := whereBuild(where)
  148. if err != nil {
  149. return err
  150. }
  151. return db.Table(p.TableName()).Where(cond, val...).Updates(values).Error
  152. }
  153. func (p *Vsschanneltbl) Save(db *gorm.DB) error {
  154. return db.Save(p).Error
  155. }
  156. func (p *Vsschanneltbl) Count(db *gorm.DB, where map[string]interface{}) (int64, error) {
  157. if len(where) > 0 {
  158. cond, val, err := whereBuild(where)
  159. if err != nil {
  160. return 0, err
  161. }
  162. ret := int64(0)
  163. err = db.Table(p.TableName()).Where(cond, val...).Count(&ret).Error
  164. return ret, err
  165. }
  166. ret := int64(0)
  167. err := db.Table(p.TableName()).Count(&ret).Error
  168. return ret, err
  169. }
  170. func (p *Vsschanneltbl) List(db *gorm.DB, where map[string]interface{}, page int32) (list []Vsschanneltbl, err error) {
  171. offset := int(page - 1) *PageSize
  172. if len(where) > 0 {
  173. cond, val, err := whereBuild(where)
  174. if err != nil {
  175. return list, err
  176. }
  177. result := db.Table(p.TableName()).Where(cond, val...).Limit(PageSize).Offset(offset).Find(&list)
  178. return list, result.Error
  179. }
  180. result := db.Table(p.TableName()).Limit(PageSize).Offset(offset).Find(&list)
  181. return list, result.Error
  182. }
  183. func DelVedio(db *gorm.DB, projectId int64) error {
  184. sql := fmt.Sprintf("delete from VSSDevTbl where DevPubID in(select sn from t_device where project_id=%d and device_code=%d)", projectId, DeviceTypeVedio)
  185. err := db.Exec(sql).Error
  186. if err != nil {
  187. return err
  188. }
  189. sql = fmt.Sprintf("delete from VSSChannelTbl where DevPubID in(select sn from t_device where project_id=%d and device_code=%d)", projectId,DeviceTypeVedio)
  190. err = db.Exec(sql).Error
  191. if err != nil {
  192. return err
  193. }
  194. return nil
  195. }