| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184 |
- package domain
- import (
- "time"
- "go.uber.org/zap"
- )
- type SmartHubSimStatus string
- const (
- SmartHubSimStatusTestReady SmartHubSimStatus = "TEST_READY" // 可测试
- SmartHubSimStatusActivateReady SmartHubSimStatus = "ACTIVATE_READY" // 可激活
- SmartHubSimStatusActivated SmartHubSimStatus = "ACTIVATED" // 已激活
- SmartHubSimStatusDeactivated SmartHubSimStatus = "DEACTIVATED" // 已停用
- SmartHubSimStatusInventory SmartHubSimStatus = "INVENTORY" // 库存
- SmartHubSimStatusRetired SmartHubSimStatus = "RETIRED" // 失效
- )
- type SmartHubSimCardInfo struct {
- GICCID string `bson:"giccid" json:"giccid"` // sim卡唯一标识
- IMEI string `bson:"imei" json:"imei"` // 国际移动用户识别码
- IMSI string `bson:"imsi" json:"imsi"` // 国际移动用户识别码
- MSISDN string `bson:"msisdn" json:"msisdn"` // 移动用户号码
- Status SmartHubSimStatus `bson:"status" json:"status"` // SmartHubSimStatus
- SellTime string `bson:"sellTime" json:"sellTime"` // 销售时间
- ActivatedTime string `bson:"activatedTime" json:"activatedTime"` // 首次激活时间
- CurrentCycleUsages struct {
- Name string `bson:"name" json:"name"` // 周期名称 exp.2018-10
- DataUsage float64 `bson:"dataUsage" json:"dataUsage"` // 流量用量 KB
- SmsUsage uint `bson:"smsUsage" json:"smsUsage"` // 短信用量 条
- VoiceUsage uint `bson:"voiceUsage" json:"voiceUsage"` // 语音用量 6s * n
- } `bson:"currentCycleUsages" json:"currentCycleUsages"` // 当前周期数据、短信、语言用量
- CurrentCycleAPNUsagesList []struct {
- APN string `bson:"apn" json:"apn"` // APN名称
- DataUsage string `bson:"dataUsage" json:"dataUsage"` // 流量用量 KB
- } `bson:"currentCycleAPNUsagesList" json:"currentCycleAPNUsagesList"` // 设备当前周期APN流量统计
- ServicePackages []struct {
- ID int `bson:"id" json:"id"` // 资费方案id
- Name string `bson:"name" json:"name"` // 资费方案名称
- SubscribeTime string `bson:"subscribeTime" json:"subscribeTime"` // 订购时间
- StartTime string `bson:"startTime" json:"startTime"` // 生效时间
- EndTime string `bson:"endTime" json:"endTime"` // 失效时间
- } `bson:"servicePackages" json:"servicePackages"` // 资费包
- ApnList []struct {
- ApnName string `bson:"apnName" json:"apnName"` // APN名称
- ApnStatus string `bson:"apnStatus" json:"apnStatus"` // APN状态 "CLOSED" or "OPEN"
- } `bson:"apnList" json:"apnList"` // APN列表
- }
- type SmartHubSimCardInfoItem struct {
- GICCID string `bson:"giccid" json:"giccid"` // sim卡唯一标识
- DeviceInfo []struct {
- IMEI string `bson:"imei" json:"imei"` // 国际移动用户识别码
- IMSI string `bson:"imsi" json:"imsi"` // 国际移动用户识别码
- MSISDN string `bson:"msisdn" json:"msisdn"` // 移动用户号码
- } `bson:"deviceInfo" json:"deviceInfo"`
- Status SmartHubSimStatus `bson:"status" json:"status"` // SmartHubSimStatus
- SellTime string `bson:"sellTime" json:"sellTime"` // 销售时间
- ActivatedTime string `bson:"activatedTime" json:"activatedTime"` // 首次激活时间
- CurrentCycleUsages struct {
- DataUsage float64 `bson:"dataUsage" json:"dataUsage"` // 流量用量 KB
- SmsUsage uint `bson:"smsUsage" json:"smsUsage"` // 短信用量 条
- VoiceUsage uint `bson:"voiceUsage" json:"voiceUsage"` // 语音用量 6s * n
- } `bson:"currentCycleUsages" json:"currentCycleUsages"` // 当前周期数据、短信、语言用量
- CurrentCycleAPNUsagesList []struct {
- APN string `bson:"apn" json:"apn"` // APN名称
- DataUsage string `bson:"dataUsage" json:"dataUsage"` // 流量用量 KB
- } `bson:"currentCycleAPNUsagesList" json:"currentCycleAPNUsagesList"` // 设备当前周期APN流量统计
- CurrentBasicServicePackages struct {
- Name string `bson:"name" json:"name"` // 资费方案名称
- StartTime string `bson:"startTime" json:"startTime"` // 生效时间
- EndTime string `bson:"endTime" json:"endTime"` // 失效时间
- } `bson:"currentBasicServicePackages" json:"currentBasicServicePackage"` // 资费包
- ApnList []struct {
- ApnName string `bson:"apnName" json:"apnName"` // APN名称
- ApnStatus string `bson:"apnStatus" json:"apnStatus"` // APN状态 "CLOSED" or "OPEN"
- } `bson:"apnList" json:"apnList"` // APN列表
- }
- type SmartHubSimCardInfoList struct {
- Data []SmartHubSimCardInfoItem `bson:"data" json:"data"`
- Page uint `bson:"page" json:"page"`
- Size uint `bson:"size" json:"size"`
- Total uint64 `bson:"total" json:"total"`
- }
- type SmartHubSimCardInfoStorage struct {
- SN string `bson:"sn" json:"sn"` // 当前使用设备的SN
- GICCID string `bson:"_id" json:"giccid"` // sim卡唯一标识
- IMEI string `bson:"imei" json:"imei"` // 国际移动用户识别码
- IMSI string `bson:"imsi" json:"imsi"` // 国际移动用户识别码
- MSISDN string `bson:"msisdn" json:"msisdn"` // 移动用户号码
- Status SmartHubSimStatus `bson:"status" json:"status"` // SmartHubSimStatus
- SellTime string `bson:"sellTime" json:"sellTime"` // 销售时间
- ActivatedTime string `bson:"activatedTime" json:"activatedTime"` // 首次激活时间
- CurrentCycleUsages struct {
- Name string `bson:"name" json:"name"` // 周期名称 exp.2018-10
- DataUsage float64 `bson:"dataUsage" json:"dataUsage"` // 流量用量 KB
- SmsUsage uint `bson:"smsUsage" json:"smsUsage"` // 短信用量 条
- VoiceUsage uint `bson:"voiceUsage" json:"voiceUsage"` // 语音用量 6s * n
- } `bson:"currentCycleUsages" json:"currentCycleUsages"` // 当前周期数据、短信、语言用量
- CurrentBasicServicePackages struct {
- Name string `bson:"name" json:"name"` // 资费方案名称
- StartTime string `bson:"startTime" json:"startTime"` // 生效时间
- EndTime string `bson:"endTime" json:"endTime"` // 失效时间
- } `bson:"currentBasicServicePackages" json:"currentBasicServicePackage"` // 资费包
- }
- // Code generated. SmartHubSimCardInfo -> SmartHubSimCardInfoStorage
- func SmartHubSimCardInfoToStorage(src *SmartHubSimCardInfo) *SmartHubSimCardInfoStorage {
- if src == nil {
- return nil
- }
- infoStorage := SmartHubSimCardInfoStorage{
- GICCID: src.GICCID,
- IMEI: src.IMEI,
- IMSI: src.IMSI,
- MSISDN: src.MSISDN,
- Status: src.Status,
- SellTime: src.SellTime,
- ActivatedTime: src.ActivatedTime,
- CurrentCycleUsages: src.CurrentCycleUsages,
- }
- nowTime := time.Now()
- for _, pack := range src.ServicePackages {
- startTime, err := time.Parse(time.RFC3339, pack.StartTime)
- if err != nil {
- zap.L().Error("Parse SmartHub Sim Card Info ServicePackage StartTime Error.", zap.String("err", err.Error()))
- continue
- }
- endTime, err := time.Parse(time.RFC3339, pack.EndTime)
- if err != nil {
- zap.L().Error("Parse SmartHub Sim Card Info ServicePackage EndTime Error.", zap.String("err", err.Error()))
- continue
- }
- if (nowTime.Equal(startTime) || nowTime.After(startTime)) &&
- (nowTime.Equal(endTime) || nowTime.Before(endTime)) {
- // 在区间内(含 start 和 end)
- infoStorage.CurrentBasicServicePackages.Name = pack.Name
- infoStorage.CurrentBasicServicePackages.StartTime = pack.StartTime
- infoStorage.CurrentBasicServicePackages.EndTime = pack.EndTime
- break
- }
- }
- return &infoStorage
- }
- // Code generated. SmartHubSimCardInfoItem -> SmartHubSimCardInfoStorage
- func SmartHubSimCardInfoItemToStorage(src *SmartHubSimCardInfoItem) *SmartHubSimCardInfoStorage {
- if src == nil {
- return nil
- }
- infoStorage := SmartHubSimCardInfoStorage{
- GICCID: src.GICCID,
- IMEI: "",
- IMSI: "",
- MSISDN: "",
- Status: src.Status,
- SellTime: src.SellTime,
- ActivatedTime: src.ActivatedTime,
- CurrentBasicServicePackages: src.CurrentBasicServicePackages,
- }
- if len(src.DeviceInfo) > 0 {
- infoStorage.IMEI = src.DeviceInfo[0].IMEI
- infoStorage.IMSI = src.DeviceInfo[0].IMSI
- infoStorage.MSISDN = src.DeviceInfo[0].MSISDN
- }
- nowTime := time.Now()
- infoStorage.CurrentCycleUsages.Name = nowTime.Format("2006-01")
- infoStorage.CurrentCycleUsages.DataUsage = src.CurrentCycleUsages.DataUsage
- infoStorage.CurrentCycleUsages.SmsUsage = src.CurrentCycleUsages.SmsUsage
- infoStorage.CurrentCycleUsages.VoiceUsage = src.CurrentCycleUsages.VoiceUsage
- return &infoStorage
- }
|