smartHubDomain.go 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173
  1. package domain
  2. import (
  3. "time"
  4. "go.uber.org/zap"
  5. )
  6. type SmartHubSimCardInfo struct {
  7. GICCID string `bson:"giccid" json:"giccid"` // sim卡唯一标识
  8. IMEI string `bson:"imei" json:"imei"` // 国际移动用户识别码
  9. IMSI string `bson:"imsi" json:"imsi"` // 国际移动用户识别码
  10. MSISDN string `bson:"msisdn" json:"msisdn"` // 移动用户号码
  11. Status string `bson:"status" json:"status"` // SimStatus
  12. SellTime string `bson:"sellTime" json:"sellTime"` // 销售时间
  13. ActivatedTime string `bson:"activatedTime" json:"activatedTime"` // 首次激活时间
  14. CurrentCycleUsages struct {
  15. Name string `bson:"name" json:"name"` // 周期名称 exp.2018-10
  16. DataUsage float64 `bson:"dataUsage" json:"dataUsage"` // 流量用量 KB
  17. SmsUsage uint `bson:"smsUsage" json:"smsUsage"` // 短信用量 条
  18. VoiceUsage uint `bson:"voiceUsage" json:"voiceUsage"` // 语音用量 6s * n
  19. } `bson:"currentCycleUsages" json:"currentCycleUsages"` // 当前周期数据、短信、语言用量
  20. CurrentCycleAPNUsagesList []struct {
  21. APN string `bson:"apn" json:"apn"` // APN名称
  22. DataUsage string `bson:"dataUsage" json:"dataUsage"` // 流量用量 KB
  23. } `bson:"currentCycleAPNUsagesList" json:"currentCycleAPNUsagesList"` // 设备当前周期APN流量统计
  24. ServicePackages []struct {
  25. ID int `bson:"id" json:"id"` // 资费方案id
  26. Name string `bson:"name" json:"name"` // 资费方案名称
  27. SubscribeTime string `bson:"subscribeTime" json:"subscribeTime"` // 订购时间
  28. StartTime string `bson:"startTime" json:"startTime"` // 生效时间
  29. EndTime string `bson:"endTime" json:"endTime"` // 失效时间
  30. } `bson:"servicePackages" json:"servicePackages"` // 资费包
  31. ApnList []struct {
  32. ApnName string `bson:"apnName" json:"apnName"` // APN名称
  33. ApnStatus string `bson:"apnStatus" json:"apnStatus"` // APN状态 "CLOSED" or "OPEN"
  34. } `bson:"apnList" json:"apnList"` // APN列表
  35. }
  36. type SmartHubSimCardInfoItem struct {
  37. GICCID string `bson:"giccid" json:"giccid"` // sim卡唯一标识
  38. DeviceInfo []struct {
  39. IMEI string `bson:"imei" json:"imei"` // 国际移动用户识别码
  40. IMSI string `bson:"imsi" json:"imsi"` // 国际移动用户识别码
  41. MSISDN string `bson:"msisdn" json:"msisdn"` // 移动用户号码
  42. } `bson:"deviceInfo" json:"deviceInfo"`
  43. Status string `bson:"status" json:"status"` // SimStatus
  44. SellTime string `bson:"sellTime" json:"sellTime"` // 销售时间
  45. ActivatedTime string `bson:"activatedTime" json:"activatedTime"` // 首次激活时间
  46. CurrentCycleUsages struct {
  47. DataUsage float64 `bson:"dataUsage" json:"dataUsage"` // 流量用量 KB
  48. SmsUsage uint `bson:"smsUsage" json:"smsUsage"` // 短信用量 条
  49. VoiceUsage uint `bson:"voiceUsage" json:"voiceUsage"` // 语音用量 6s * n
  50. } `bson:"currentCycleUsages" json:"currentCycleUsages"` // 当前周期数据、短信、语言用量
  51. CurrentCycleAPNUsagesList []struct {
  52. APN string `bson:"apn" json:"apn"` // APN名称
  53. DataUsage string `bson:"dataUsage" json:"dataUsage"` // 流量用量 KB
  54. } `bson:"currentCycleAPNUsagesList" json:"currentCycleAPNUsagesList"` // 设备当前周期APN流量统计
  55. CurrentBasicServicePackages struct {
  56. Name string `bson:"name" json:"name"` // 资费方案名称
  57. StartTime string `bson:"startTime" json:"startTime"` // 生效时间
  58. EndTime string `bson:"endTime" json:"endTime"` // 失效时间
  59. } `bson:"currentBasicServicePackages" json:"currentBasicServicePackage"` // 资费包
  60. ApnList []struct {
  61. ApnName string `bson:"apnName" json:"apnName"` // APN名称
  62. ApnStatus string `bson:"apnStatus" json:"apnStatus"` // APN状态 "CLOSED" or "OPEN"
  63. } `bson:"apnList" json:"apnList"` // APN列表
  64. }
  65. type SmartHubSimCardInfoList struct {
  66. Data []SmartHubSimCardInfoItem `bson:"data" json:"data"`
  67. Page uint `bson:"page" json:"page"`
  68. Size uint `bson:"size" json:"size"`
  69. Total uint64 `bson:"total" json:"total"`
  70. }
  71. type SmartHubSimCardInfoStorage struct {
  72. SN string `bson:"sn" json:"sn"` // 当前使用设备的SN
  73. GICCID string `bson:"_id" json:"giccid"` // sim卡唯一标识
  74. IMEI string `bson:"imei" json:"imei"` // 国际移动用户识别码
  75. IMSI string `bson:"imsi" json:"imsi"` // 国际移动用户识别码
  76. MSISDN string `bson:"msisdn" json:"msisdn"` // 移动用户号码
  77. Status string `bson:"status" json:"status"` // SimStatus
  78. SellTime string `bson:"sellTime" json:"sellTime"` // 销售时间
  79. ActivatedTime string `bson:"activatedTime" json:"activatedTime"` // 首次激活时间
  80. CurrentCycleUsages struct {
  81. Name string `bson:"name" json:"name"` // 周期名称 exp.2018-10
  82. DataUsage float64 `bson:"dataUsage" json:"dataUsage"` // 流量用量 KB
  83. SmsUsage uint `bson:"smsUsage" json:"smsUsage"` // 短信用量 条
  84. VoiceUsage uint `bson:"voiceUsage" json:"voiceUsage"` // 语音用量 6s * n
  85. } `bson:"currentCycleUsages" json:"currentCycleUsages"` // 当前周期数据、短信、语言用量
  86. CurrentBasicServicePackages struct {
  87. Name string `bson:"name" json:"name"` // 资费方案名称
  88. StartTime string `bson:"startTime" json:"startTime"` // 生效时间
  89. EndTime string `bson:"endTime" json:"endTime"` // 失效时间
  90. } `bson:"currentBasicServicePackages" json:"currentBasicServicePackage"` // 资费包
  91. }
  92. // Code generated. SmartHubSimCardInfo -> SmartHubSimCardInfoStorage
  93. func SmartHubSimCardInfoToStorage(src *SmartHubSimCardInfo) *SmartHubSimCardInfoStorage {
  94. if src == nil {
  95. return nil
  96. }
  97. infoStorage := SmartHubSimCardInfoStorage{
  98. GICCID: src.GICCID,
  99. IMEI: src.IMEI,
  100. IMSI: src.IMSI,
  101. MSISDN: src.MSISDN,
  102. Status: src.Status,
  103. SellTime: src.SellTime,
  104. ActivatedTime: src.ActivatedTime,
  105. CurrentCycleUsages: src.CurrentCycleUsages,
  106. }
  107. nowTime := time.Now()
  108. for _, pack := range src.ServicePackages {
  109. startTime, err := time.Parse(time.RFC3339, pack.StartTime)
  110. if err != nil {
  111. zap.L().Error("Parse SmartHub Sim Card Info ServicePackage StartTime Error.", zap.String("err", err.Error()))
  112. continue
  113. }
  114. endTime, err := time.Parse(time.RFC3339, pack.EndTime)
  115. if err != nil {
  116. zap.L().Error("Parse SmartHub Sim Card Info ServicePackage EndTime Error.", zap.String("err", err.Error()))
  117. continue
  118. }
  119. if (nowTime.Equal(startTime) || nowTime.After(startTime)) &&
  120. (nowTime.Equal(endTime) || nowTime.Before(endTime)) {
  121. // 在区间内(含 start 和 end)
  122. infoStorage.CurrentBasicServicePackages.Name = pack.Name
  123. infoStorage.CurrentBasicServicePackages.StartTime = pack.StartTime
  124. infoStorage.CurrentBasicServicePackages.EndTime = pack.EndTime
  125. break
  126. }
  127. }
  128. return &infoStorage
  129. }
  130. // Code generated. SmartHubSimCardInfoItem -> SmartHubSimCardInfoStorage
  131. func SmartHubSimCardInfoItemToStorage(src *SmartHubSimCardInfoItem) *SmartHubSimCardInfoStorage {
  132. if src == nil {
  133. return nil
  134. }
  135. infoStorage := SmartHubSimCardInfoStorage{
  136. GICCID: src.GICCID,
  137. IMEI: "",
  138. IMSI: "",
  139. MSISDN: "",
  140. Status: src.Status,
  141. SellTime: src.SellTime,
  142. ActivatedTime: src.ActivatedTime,
  143. CurrentBasicServicePackages: src.CurrentBasicServicePackages,
  144. }
  145. if len(src.DeviceInfo) > 0 {
  146. infoStorage.IMEI = src.DeviceInfo[0].IMEI
  147. infoStorage.IMSI = src.DeviceInfo[0].IMSI
  148. infoStorage.MSISDN = src.DeviceInfo[0].MSISDN
  149. }
  150. nowTime := time.Now()
  151. infoStorage.CurrentCycleUsages.Name = nowTime.Format("2006-01")
  152. infoStorage.CurrentCycleUsages.DataUsage = src.CurrentCycleUsages.DataUsage
  153. infoStorage.CurrentCycleUsages.SmsUsage = src.CurrentCycleUsages.SmsUsage
  154. infoStorage.CurrentCycleUsages.VoiceUsage = src.CurrentCycleUsages.VoiceUsage
  155. return &infoStorage
  156. }