Jelajahi Sumber

公用逻辑提取

wangchuanjin 2 tahun lalu
induk
melakukan
bf03cf6dae
1 mengubah file dengan 18 tambahan dan 17 penghapusan
  1. 18 17
      p/struct.go

+ 18 - 17
p/struct.go

@@ -103,6 +103,21 @@ type PushSet struct {
 	FollowEnt          *PushSetChild //企业情报监控-企业中标动态推送设置
 }
 
+func (p *PushSet) ResetSubSet() {
+	if p.SubSet == nil {
+		return
+	}
+	if p.SubSet.RateMode == 0 || p.SubSet.RateMode == 5 {
+		p.SubSet.RateMode = 2
+		if len(p.SubSet.Times) == 0 {
+			p.SubSet.Times = append(p.SubSet.Times, "09:00", "14:00")
+		}
+	} else if p.SubSet.RateMode == 2 && len(p.SubSet.Times) == 0 {
+		p.SubSet.Times = append(p.SubSet.Times, "09:00")
+	}
+	sort.Strings(p.SubSet.Times)
+}
+
 type PushSetChild struct {
 	RateMode int      //推送时间
 	Times    []string //自定义推送时间
@@ -178,21 +193,7 @@ func NewUserInfo(temp map[string]interface{}, tp int) *UserInfo {
 //解析用户的推送设置
 func (u *UserInfo) GetPushSet(obj map[string]interface{}) {
 	subSet, _ := obj["o_subset"].(map[string]interface{})
-	rateMode := util.IntAll(subSet["i_ratemode"])
-	times := []string{}
-	a_times, _ := subSet["a_times"].([]interface{})
-	for _, v := range a_times {
-		times = append(times, util.ObjToString(v))
-	}
-	if rateMode == 0 || rateMode == 5 {
-		rateMode = 2
-		if len(times) == 0 {
-			times = append(times, "09:00", "14:00")
-		}
-	} else if rateMode == 2 && len(times) == 0 {
-		times = append(times, "09:00")
-	}
-	sort.Strings(times)
+	times, _ := subSet["a_times"].([]interface{})
 	weekReport, _ := obj["o_week_report"].(map[string]interface{})
 	monthReport, _ := obj["o_month_report"].(map[string]interface{})
 	newprojectForecast, _ := obj["o_newproject_forecast"].(map[string]interface{})
@@ -205,8 +206,8 @@ func (u *UserInfo) GetPushSet(obj map[string]interface{}) {
 			WxPush:   util.IntAllDef(subSet["i_wxpush"], 1),
 			AppPush:  util.IntAllDef(subSet["i_apppush"], 1),
 			MailPush: util.IntAll(subSet["i_mailpush"]),
-			RateMode: rateMode,
-			Times:    times,
+			RateMode: util.IntAll(subSet["i_ratemode"]),
+			Times:    util.ObjArrToStringArr(times),
 		},
 		WeekReport: &PushSetChild{
 			WxPush:   util.IntAllDef(weekReport["i_wxpush"], 1),