pendant_state.go 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. package model
  2. import (
  3. "strconv"
  4. "go-common/library/log"
  5. )
  6. // const .
  7. const (
  8. // pendant status
  9. PendantStatusON = 1
  10. PendantStatusOFF = 0
  11. // group status
  12. GroupStatusON = 1
  13. GroupStatusOFF = 0
  14. // packpage status
  15. InvalidPendantPKG = int32(0)
  16. ValidPendantPKG = int32(1)
  17. EquipPendantPKG = int32(2)
  18. // pendant equip
  19. PendantEquipOFF = int8(1)
  20. PendantEquipON = int8(2)
  21. // pendant source
  22. UnknownEquipSource = 0
  23. EquipFromPackage = 1
  24. EquipFromVIP = 2
  25. )
  26. // IsValidSource 挂件来源是否合法 合法:true,无效:false
  27. func IsValidSource(source int64) bool {
  28. if source != EquipFromPackage && source != EquipFromVIP && source != UnknownEquipSource {
  29. log.Error("IsValidSource souce=%v is not correct value", source)
  30. return false
  31. }
  32. return true
  33. }
  34. // ParseSource c处理挂件来源
  35. func ParseSource(sourceStr string) int64 {
  36. // 没有传值,则设置为未知挂件
  37. if sourceStr == "" {
  38. return UnknownEquipSource
  39. }
  40. // 有传递参数,但是没有按照要求传值,也设置为未知挂件
  41. source, err := strconv.ParseInt(sourceStr, 10, 64)
  42. if err != nil {
  43. log.Error("ParseSource err(%+v)", err)
  44. return UnknownEquipSource
  45. }
  46. // 没有按照要求传值,也设置为未知挂件
  47. if source != EquipFromPackage && source != EquipFromVIP && source != UnknownEquipSource {
  48. log.Error("ParseSource souce=%v is not correct value", source)
  49. return UnknownEquipSource
  50. }
  51. return source
  52. }