Explorar o código

新增上课准备Redis生成

jyq %!s(int64=4) %!d(string=hai) anos
pai
achega
8dc29ba304

+ 44 - 38
api/grpc/base.go

@@ -949,7 +949,7 @@ func (a Api) ClassStartPrepare(ctx context.Context, r *pb.CourseStandardRequest)
 	if q.IsHr == 1 {
 		hrRs := service.Hr{}.HrClassStartPrepare(token, q.ShopID, q.JsonStr, sign)
 		if !a.checkRs(hrRs) {
-			rst := a.toWebFunc(rs)
+			rst := a.toWebFunc(hrRs)
 			return rst, nil
 		}
 	}
@@ -1017,7 +1017,7 @@ func (a Api) VipClassDetailAdd(ctx context.Context, r *pb.CourseStandardRequest)
 	if q.IsHr == 1 {
 		hrRs := service.Hr{}.HrClassDetailAdd(token, q.ShopID, q.JsonStr, sign)
 		if !a.checkRs(hrRs) {
-			rst := a.toWebFunc(rs)
+			rst := a.toWebFunc(hrRs)
 			return rst, nil
 		}
 	}
@@ -1033,23 +1033,25 @@ func (a Api) VipClassDetailAdd(ctx context.Context, r *pb.CourseStandardRequest)
 func (a Api) VipClassDetailDel(ctx context.Context, r *pb.CourseStandardRequest) (*pb.StandardReply, error) {
 	// 获取token,并验证签名函数
 	token, q, sign := a.courseToGoVerify(ctx, r)
-
-	rs := service.Course{}.VipClassDetailDel(token, q.ShopID, q.JsonStr, sign)
-	if !a.checkRs(rs) {
-		rst := a.toWebFunc(rs)
-		return rst, nil
-	}
+	// 删除应该是先删除心率跟评分库,再去删除基础库数据
 	if q.IsHr == 1 {
 		hrRs := service.Hr{}.HrClassDetailDel(token, q.ShopID, q.JsonStr, sign)
 		if !a.checkRs(hrRs) {
-			rst := a.toWebFunc(rs)
+			rst := a.toWebFunc(hrRs)
 			return rst, nil
 		}
 	}
+
 	if q.IsScore == 1 {
 		// todo 调用评分系统接口
 	}
 
+	rs := service.Course{}.VipClassDetailDel(token, q.ShopID, q.JsonStr, sign)
+	if !a.checkRs(rs) {
+		rst := a.toWebFunc(rs)
+		return rst, nil
+	}
+
 	rst := a.toWebFunc(rs)
 	return rst, nil
 }
@@ -1067,7 +1069,7 @@ func (a Api) TmpClassDetailAdd(ctx context.Context, r *pb.CourseStandardRequest)
 	if q.IsHr == 1 {
 		hrRs := service.Hr{}.HrClassDetailDel(token, q.ShopID, q.JsonStr, sign)
 		if !a.checkRs(hrRs) {
-			rst := a.toWebFunc(rs)
+			rst := a.toWebFunc(hrRs)
 			return rst, nil
 		}
 	}
@@ -1083,16 +1085,11 @@ func (a Api) TmpClassDetailAdd(ctx context.Context, r *pb.CourseStandardRequest)
 func (a Api) TmpClassDetailDel(ctx context.Context, r *pb.CourseStandardRequest) (*pb.StandardReply, error) {
 	// 获取token,并验证签名函数
 	token, q, sign := a.courseToGoVerify(ctx, r)
-
-	rs := service.Course{}.TmpClassDetailDel(token, q.ShopID, q.JsonStr, sign)
-	if !a.checkRs(rs) {
-		rst := a.toWebFunc(rs)
-		return rst, nil
-	}
+	// 删除应该是先删除心率跟评分库,再去删除基础库数据
 	if q.IsHr == 1 {
 		hrRs := service.Hr{}.HrClassDetailDel(token, q.ShopID, q.JsonStr, sign)
 		if !a.checkRs(hrRs) {
-			rst := a.toWebFunc(rs)
+			rst := a.toWebFunc(hrRs)
 			return rst, nil
 		}
 	}
@@ -1100,6 +1097,12 @@ func (a Api) TmpClassDetailDel(ctx context.Context, r *pb.CourseStandardRequest)
 		// todo 调用评分系统接口
 	}
 
+	rs := service.Course{}.TmpClassDetailDel(token, q.ShopID, q.JsonStr, sign)
+	if !a.checkRs(rs) {
+		rst := a.toWebFunc(rs)
+		return rst, nil
+	}
+
 	rst := a.toWebFunc(rs)
 	return rst, nil
 }
@@ -1117,7 +1120,7 @@ func (a Api) VipClassDetailStatueEdit(ctx context.Context, r *pb.CourseStandardR
 	if q.IsHr == 1 {
 		hrRs := service.Hr{}.HrClassDetailStatusEdit(token, q.ShopID, q.JsonStr, sign)
 		if !a.checkRs(hrRs) {
-			rst := a.toWebFunc(rs)
+			rst := a.toWebFunc(hrRs)
 			return rst, nil
 		}
 	}
@@ -1134,25 +1137,28 @@ func (a Api) ClassStartConfirm(ctx context.Context, r *pb.CourseStandardRequest)
 	// 获取token,并验证签名函数
 	token, q, sign := a.courseToGoVerify(ctx, r)
 
-	//rs := service.Course{}.ClassStartConfirm(token, q.ShopID, q.JsonStr, sign)
-	//if !a.checkRs(rs) {
-	//	rst := a.toWebFunc(rs)
-	//	return rst, nil
-	//}
-	//if q.IsHr == 1 {
-	//	hrRs := service.Hr{}.HrClassStartConfirm(token, q.ShopID, q.JsonStr, sign)
-	//	if !a.checkRs(hrRs) {
-	//		rst := a.toWebFunc(rs)
-	//		return rst, nil
-	//	}
-	//}
-	//if q.IsScore == 1 {
-	//	// todo 调用评分系统接口
-	//}
-	// todo 所有步骤执行成功后,调用课程Sn查询接口,生成R1验证Redis
-	// todo 使用StdId查询课程绑定显示端EqSn列表,内容为EqSnList,DuIdList
-	rs := service.HrRedis{}.ClassStartR1AndOnClassByUUStdID(token, q.ShopID, q.UUStdID)
-	println(sign)
+	rs := service.Course{}.ClassStartConfirm(token, q.ShopID, q.JsonStr, sign)
+	if !a.checkRs(rs) {
+		rst := a.toWebFunc(rs)
+		return rst, nil
+	}
+
+	if q.IsScore == 1 {
+		// todo 调用评分系统接口
+	}
+	if q.IsHr == 1 {
+		hrRs := service.Hr{}.HrClassStartConfirm(token, q.ShopID, q.JsonStr, sign)
+		if !a.checkRs(hrRs) {
+			rst := a.toWebFunc(hrRs)
+			return rst, nil
+		}
+		redisRs := service.HrRedis{}.ClassStartR1AndOnClassByUUStdID(token, q.ShopID, q.UUStdID)
+		if !a.checkRs(redisRs) {
+			rst := a.toWebFunc(redisRs)
+			return rst, nil
+		}
+	}
+
 	rst := a.toWebFunc(rs)
 	return rst, nil
 }
@@ -1180,7 +1186,7 @@ func (a Api) ClassGiveUpConfirm(ctx context.Context, r *pb.CourseStandardRequest
 	if q.IsHr == 1 {
 		hrRs := service.Hr{}.HrClassGiveUpConfirm(token, q.ShopID, q.JsonStr, sign)
 		if !a.checkRs(hrRs) {
-			rst := a.toWebFunc(rs)
+			rst := a.toWebFunc(hrRs)
 			return rst, nil
 		}
 	}

+ 55 - 1
assembly/base/service/hrRedis.go

@@ -8,7 +8,9 @@
 package service
 
 import (
+	"sportfitness/base/assembly/heartRate/model"
 	"sportfitness/base/assembly/heartRate/repository/postgre"
+	"sportfitness/base/assembly/heartRate/repository/redis"
 	"sportfitness/base/errors"
 )
 
@@ -24,9 +26,61 @@ func (h HrRedis) ClassStartR1AndOnClassByUUStdID(token string, objectShopId int6
 	if err != nil {
 		panic(errors.PGError)
 	}
-	if !h.checkRs(rst) {
+	rsMap, b := h.JSONToMap(rst)
+	if !b {
 		return rst
 	}
+	sn := rsMap["rs"].(map[string]interface{})["sn_info"].([]interface{})
+	eqSn := rsMap["rs"].(map[string]interface{})["eqsn_list"].([]interface{})
+	var snInfo []model.HrVerifyDetail
 
+	// 心率带信息sn_info
+	for _, v := range sn {
+		one := model.HrVerifyDetail{}
+		one.Sn = v.(map[string]interface{})["sn"].(string)
+		one.Age = int(v.(map[string]interface{})["age"].(float64))
+		one.Sex = int(v.(map[string]interface{})["sex"].(float64))
+		one.Name = v.(map[string]interface{})["name"].(string)
+		one.CrId = int64(v.(map[string]interface{})["cr_id"].(float64))
+		one.Height = int(v.(map[string]interface{})["height"].(float64))
+		one.Weight = int(v.(map[string]interface{})["weight"].(float64))
+		one.HeadImg = v.(map[string]interface{})["headurl"].(string)
+		one.GroupNo = int(v.(map[string]interface{})["group_no"].(float64))
+		one.IsPrivate = int(v.(map[string]interface{})["is_private"].(float64))
+		one.IsBirthday = int(v.(map[string]interface{})["is_birthday"].(float64))
+		one.PowerPercent = int(v.(map[string]interface{})["power_percent"].(float64))
+
+		snInfo = append(snInfo, one)
+	}
+	// eqSn信息eqsn_list
+	var eqSnInfo []model.ClassStartDetail
+	//var onClass []model.CrIdList
+	for _, k := range eqSn {
+		one := model.ClassStartDetail{}
+		//class := model.CrIdList{}
+		one.EqSn = k.(map[string]interface{})["eqsn"].(string)
+		//class.EqSn = k.(map[string]interface{})["eqsn"].(string)
+		classInfo := k.(map[string]interface{})["std_info"].(map[string]interface{})["classinfo"].([]interface{})
+		for _, c := range classInfo {
+			// 循环遍历classInfo
+			info := model.ClassInfo{}
+			info.Coach = c.(map[string]interface{})["coach"].(string)
+			info.ClassName = c.(map[string]interface{})["class_name"].(string)
+			info.ClassType = int(c.(map[string]interface{})["class_type"].(float64))
+			info.MemberCount = int(c.(map[string]interface{})["member_count"].(float64))
+			one.StdInfo.ClassInfoList = append(one.StdInfo.ClassInfoList, info)
+		}
+		crId := k.(map[string]interface{})["crid_list"].([]interface{})
+		for _, c := range crId {
+			id := int64(c.(float64))
+			one.CrIdLIst = append(one.CrIdLIst, id)
+		}
+		eqSnInfo = append(eqSnInfo, one)
+		//onClass = append(onClass, class)
+	}
+
+	redis.OnClassRedis(eqSnInfo)
+	redis.HrVerifyR1(snInfo)
+	//redis
 	return rst
 }

+ 16 - 6
assembly/heartRate/model/band_data.go

@@ -1,10 +1,20 @@
 package model
 
 type BandData struct {
-	BandId    int
-	HubId     int
-	HeartRate int
-	Battery   int
-	TimeMiles int64
-	CrId      int
+	CrId       int64
+	BandId     int
+	HubId      int
+	HeartRate  int
+	Battery    int
+	TimeMiles  int64
+	Age        int
+	Weight     int
+	Sex        int
+	StaticHr   int
+	Height     int
+	HeadImg    string
+	Name       string
+	IsPrivate  int
+	GroupNo    int
+	IsBirthday int
 }

+ 42 - 0
assembly/heartRate/model/class_start_redis.go

@@ -0,0 +1,42 @@
+// Package model
+/**
+ * @ File: class_start_redis.go
+ * @ Date: 2021/6/9 20:49
+ * @ Author: JYQ
+ * @ Description:
+ */
+package model
+
+import (
+	"time"
+)
+
+type StdInfo struct {
+	ClassStatus   int `json:"class_status"`
+	ClassInfoList []ClassInfo
+}
+
+type ClassInfo struct {
+	Coach       string    `json:"coach"`
+	BeginTime   time.Time `json:"begin_time"`
+	ClassName   string    `json:"class_name"`
+	ClassType   int       `json:"class_type"`
+	MemberCount int       `json:"member_count"`
+}
+
+type ClassStartDetail struct {
+	EqSn string `json:"eqsn"`
+	StdInfo
+	CrIdLIst []int64 `json:"crid_list"`
+}
+
+type CrIdList struct {
+	EqSn     string  `json:"eqsn"`
+	CrIdLIst []int64 `json:"crid_list"`
+}
+
+type ClassStartJson struct {
+	Code   int                `json:"rsCode"`
+	Memo   string             `json:"rsMemo"`
+	Result []ClassStartDetail `json:"rsResult"`
+}

+ 12 - 10
assembly/heartRate/model/hr_verify.go

@@ -8,16 +8,18 @@
 package model
 
 type HrVerify struct {
-	CrId      int    `json:"cr_id"`
-	Age       int    `json:"age"`
-	Weight    int    `json:"weight"`
-	Sex       int    `json:"sex"`
-	StaticHr  int    `json:"static_hr"`
-	Height    int    `json:"height"`
-	HeadImg   string `json:"head_img"`
-	Name      string `json:"name"`
-	IsPrivate int    `json:"is_private"`
-	GroupNo   int    `json:"group_no"`
+	CrId         int64  `json:"cr_id"`
+	Age          int    `json:"age"`
+	Weight       int    `json:"weight"`
+	Sex          int    `json:"sex"`
+	StaticHr     int    `json:"static_hr"`
+	Height       int    `json:"height"`
+	HeadImg      string `json:"head_img"`
+	Name         string `json:"name"`
+	IsPrivate    int    `json:"is_private"`
+	GroupNo      int    `json:"group_no"`
+	IsBirthday   int    `json:"is_birthday"`
+	PowerPercent int    `json:"battery"`
 }
 
 type HrVerifyDetail struct {

+ 28 - 21
assembly/heartRate/repository/redis/hr_verify_r1.go

@@ -11,32 +11,39 @@ import (
 	"encoding/json"
 	"fmt"
 	"sportfitness/base/assembly/heartRate/model"
-
-	"github.com/go-redis/redis/v8"
-	"github.com/sirupsen/logrus"
 )
 
 const hrVerifyR1Key = prefix + ":hr_verify_r1"
 
 func HrVerifyR1(list []model.HrVerifyDetail) {
-	cmder, err := getClient().TxPipelined(ctx, func(pipeliner redis.Pipeliner) error {
-		for _, one := range list {
-			data, err2 := json.Marshal(one.HrVerify)
-			if err2 != nil {
-				panic(err2)
-			}
-			pipeliner.Set(ctx, fmt.Sprintf("%s:%s", hrVerifyR1Key, one.Sn), data, 0)
-		}
-		return nil
-	})
-
-	if err != nil {
-		logrus.Errorf("HrVerufyR1 保存失败:%s", err)
-		return
-	}
-	for _, r := range cmder {
-		if r.Err() != nil {
-			logrus.Errorf("HrVerufyR1 保存失败:%s", r.Err())
+	for _, one := range list {
+		data, err2 := json.Marshal(one.HrVerify)
+		if err2 != nil {
+			panic(err2)
 		}
+		getClient().Set(ctx, fmt.Sprintf("%s:%s", hrVerifyR1Key, one.Sn), data, 0)
 	}
 }
+
+//func HrVerifyR1(list []model.HrVerifyDetail) {
+//	cmder, err := getClient().TxPipelined(ctx, func(pipeliner redis.Pipeliner) error {
+//		for _, one := range list {
+//			data, err2 := json.Marshal(one.HrVerify)
+//			if err2 != nil {
+//				panic(err2)
+//			}
+//			pipeliner.Set(ctx, fmt.Sprintf("%s:%s", hrVerifyR1Key, one.Sn), data, 0)
+//		}
+//		return nil
+//	})
+//
+//	if err != nil {
+//		logrus.Errorf("HrVerufyR1 保存失败:%s", err)
+//		return
+//	}
+//	for _, r := range cmder {
+//		if r.Err() != nil {
+//			logrus.Errorf("HrVerufyR1 保存失败:%s", r.Err())
+//		}
+//	}
+//}

+ 57 - 0
assembly/heartRate/repository/redis/on_class.go

@@ -0,0 +1,57 @@
+//Package redis
+/**
+ * @ File:
+ * @ Date: 2021/6/10 13:57
+ * @ Author: JYQ
+ * @ Description:
+ */
+package redis
+
+import (
+	"encoding/json"
+	"fmt"
+	"sportfitness/base/assembly/heartRate/model"
+)
+
+const OnClassKey = prefix + ":on_class"
+
+func OnClassRedis(classInfo []model.ClassStartDetail) {
+	for _, v := range classInfo {
+		crIdList, err2 := json.Marshal(v.CrIdLIst)
+		if err2 != nil {
+			panic(err2)
+		}
+		stdInfo, err2 := json.Marshal(v.StdInfo)
+		if err2 != nil {
+			panic(err2)
+		}
+		getClient().HSet(ctx, fmt.Sprintf("%s:%s", OnClassKey, v.EqSn),
+			"crIdList", crIdList,
+			"stdInfo", stdInfo)
+	}
+}
+
+//func OnClassRedis(list []model.CrIdList) {
+//	cmders, err := getClient().TxPipelined(ctx, func(pipeliner redis.Pipeliner) error {
+//		for _, v := range list {
+//			data, err2 := json.Marshal(v.CrIdLIst)
+//			if err2 != nil {
+//				panic(err2)
+//			}
+//			//HSet(ctx, hashKey, fmt.Sprintf("K%02d", i), "x")
+//			i := pipeliner.HSet(ctx, fmt.Sprintf("%s:%s", OnClassKey, v.EqSn), "crid_list", data)
+//			println(i)
+//		}
+//		return nil
+//	})
+//	if err != nil {
+//		logrus.Errorf("OnClass 保存失败:%s", err)
+//		return
+//	}
+//
+//	for _, r := range cmders {
+//		if r.Err() != nil {
+//			logrus.Errorf("OnClass 保存失败:%s", r.Err())
+//		}
+//	}
+//}