computer.go 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. package log
  2. import (
  3. "context"
  4. "log-server/global"
  5. )
  6. type Computer struct {
  7. Id uint `json:"id"`
  8. PcCode string `json:"pc_code"`
  9. User string `json:"user"`
  10. Status int `json:"status"`
  11. CreateTime string `json:"create_time"` // 创建时间
  12. UpdateTime string `json:"update_time"` // 更新时间
  13. Supplier string `json:"supplier"` //电脑供应商
  14. }
  15. func (Computer) TableName() string {
  16. return "computer"
  17. }
  18. const OnlinePcCode = "Online:PcCode"
  19. func (c *Computer) OnlinePcCodeCache() (mps map[string]string, err error) {
  20. ctx := context.Background()
  21. isNull, _ := global.GVA_REDIS.Exists(ctx, OnlinePcCode).Result()
  22. if isNull != 0 {
  23. mps, err = global.GVA_REDIS.HGetAll(ctx, OnlinePcCode).Result()
  24. return
  25. }
  26. return
  27. }
  28. // 更新单条缓存数据
  29. func (c *Computer) UpdateOnlinePcCodeCache(pcCode, user string) (err error) {
  30. ctx := context.Background()
  31. err = global.GVA_REDIS.HSet(ctx, OnlinePcCode, pcCode, user).Err()
  32. return
  33. }
  34. // 删除单条缓存数据
  35. func (c *Computer) DelOnlinePcCodeCache(pcCode string) (err error) {
  36. ctx := context.Background()
  37. err = global.GVA_REDIS.HDel(ctx, OnlinePcCode, pcCode).Err()
  38. return
  39. }
  40. // 清空缓存数据
  41. func (c *Computer) DelAllOnlinePcCodeCache() (err error) {
  42. ctx := context.Background()
  43. keys, _ := global.GVA_REDIS.HKeys(ctx, OnlinePcCode).Result()
  44. err = global.GVA_REDIS.HDel(ctx, OnlinePcCode, keys...).Err()
  45. return
  46. }
  47. func (c *Computer) ExistsPcCodeCache(pcCode string) bool {
  48. ctx := context.Background()
  49. b, _ := global.GVA_REDIS.HExists(ctx, OnlinePcCode, pcCode).Result()
  50. return b
  51. }