video.go 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240
  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 := (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. func (p *Vssdevtbl) UpdateChannelCount(db *gorm.DB, sn string, count int) error {
  99. sql := fmt.Sprintf("update VSSDevTbl set channel_count=channel_count+%d where DevPubID='%s'", count, sn)
  100. return db.Exec(sql).Error
  101. }
  102. type Vsschanneltbl struct {
  103. ID int64 `gorm:"column:ID"`
  104. Devpubid string `gorm:"column:DevPubID"`
  105. Restype int64 `gorm:"column:ResType"`
  106. Nickname string `gorm:"column:Nickname"`
  107. Chanpubid string `gorm:"column:ChanPubID"`
  108. Alive int64 `gorm:"column:Alive"`
  109. Corpid string `gorm:"column:CorpID"`
  110. Model string `gorm:"column:Model"`
  111. Owner string `gorm:"column:Owner"`
  112. Civilcode string `gorm:"column:CivilCode"`
  113. Address string `gorm:"column:Address"`
  114. Parental int64 `gorm:"column:Parental"`
  115. Parentid string `gorm:"column:ParentId"`
  116. Ip string `gorm:"column:IP"`
  117. Port int64 `gorm:"column:Port"`
  118. Longitude float64 `gorm:"column:Longitude"`
  119. Latitude float64 `gorm:"column:Latitude"`
  120. Altitude float64 `gorm:"column:Altitude"`
  121. Ptztype int64 `gorm:"column:PTZType"`
  122. Roomtype int64 `gorm:"column:RoomType"`
  123. Directiontype int64 `gorm:"column:DirectionType"`
  124. Streamtype int64 `gorm:"column:StreamType"`
  125. Chanrtspurl string `gorm:"column:ChanRtspUrl"`
  126. Realrtspurl string `gorm:"column:RealRtspUrl"`
  127. Dmarker int64 `gorm:"column:DMarker"`
  128. Updatetime time.Time `gorm:"column:UpdateTime"`
  129. }
  130. func (Vsschanneltbl) TableName() string {
  131. return "VSSChannelTbl"
  132. }
  133. func (p *Vsschanneltbl) Insert(db *gorm.DB) error {
  134. return db.Create(p).Error
  135. }
  136. func (p *Vsschanneltbl) Del(db *gorm.DB, where map[string]interface{}) error {
  137. cond, val, err := whereBuild(where)
  138. if err != nil {
  139. return err
  140. }
  141. return db.Table(p.TableName()).Where(cond, val...).Delete(p).Error
  142. }
  143. func (p *Vsschanneltbl) Find(db *gorm.DB, where map[string]interface{}) error {
  144. cond, val, err := whereBuild(where)
  145. if err != nil {
  146. return err
  147. }
  148. return db.Table(p.TableName()).Where(cond, val...).First(p).Error
  149. }
  150. func (p *Vsschanneltbl) Update(db *gorm.DB, where map[string]interface{}, values map[string]interface{}) error {
  151. cond, val, err := whereBuild(where)
  152. if err != nil {
  153. return err
  154. }
  155. return db.Table(p.TableName()).Where(cond, val...).Updates(values).Error
  156. }
  157. func (p *Vsschanneltbl) Save(db *gorm.DB) error {
  158. return db.Save(p).Error
  159. }
  160. func (p *Vsschanneltbl) Count(db *gorm.DB, where map[string]interface{}) (int64, error) {
  161. if len(where) > 0 {
  162. cond, val, err := whereBuild(where)
  163. if err != nil {
  164. return 0, err
  165. }
  166. ret := int64(0)
  167. err = db.Table(p.TableName()).Where(cond, val...).Count(&ret).Error
  168. return ret, err
  169. }
  170. ret := int64(0)
  171. err := db.Table(p.TableName()).Count(&ret).Error
  172. return ret, err
  173. }
  174. func (p *Vsschanneltbl) List(db *gorm.DB, where map[string]interface{}, page int32) (list []Vsschanneltbl, err error) {
  175. offset := (int(page) - 1) *PageSize
  176. if len(where) > 0 {
  177. cond, val, err := whereBuild(where)
  178. if err != nil {
  179. return list, err
  180. }
  181. result := db.Table(p.TableName()).Where(cond, val...).Limit(PageSize).Offset(offset).Find(&list)
  182. return list, result.Error
  183. }
  184. result := db.Table(p.TableName()).Limit(PageSize).Offset(offset).Find(&list)
  185. return list, result.Error
  186. }
  187. func GetProjectIdByChannel(db *gorm.DB, id int64) (int64, error) {
  188. sql := fmt.Sprintf("select t2.project_id from VSSChannelTbl as t1 left join t_device as t2 on t1.DevPubID = t2.sn and t2.device_code=%d where t1.id=?", DeviceTypeVedio)
  189. type Result struct {
  190. ProjectId int64
  191. }
  192. array := []Result{}
  193. err := db.Raw(sql, id).Scan(&array).Error
  194. if err != nil {
  195. return 0, err
  196. }
  197. if len(array) == 0 {
  198. return 0, nil
  199. }
  200. return array[0].ProjectId, nil
  201. }