smartHubDomain.go 9.1 KB

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