Browse Source

称重接口

张保健 4 years ago
parent
commit
5aa468b1e5

+ 38 - 5
controllers/mobile_api_controllers/check_weight_api_controller.go View File

@@ -13,11 +13,10 @@ import (
13 13
 	"net/http"
14 14
 	"net/url"
15 15
 	"strconv"
16
-	_ "strings"
16
+	_"strings"
17 17
 
18 18
 	// "fmt"
19 19
 	_ "reflect"
20
-	_ "strconv"
21 20
 	"time"
22 21
 )
23 22
 
@@ -696,11 +695,44 @@ func (c *CheckWeightApiController) SavePatientInfoDialysis() {
696 695
 		}
697 696
 	}
698 697
 }
698
+
699
+func (c *CheckWeightApiController) SetSyncTime(){
700
+	sn := c.GetString("sn")
701
+	if len(sn)  > 0 {
702
+		redis := service.RedisClient()
703
+		defer redis.Close()
704
+		redis.Set(sn, 0,0)
705
+	}
706
+	serviceTime := time.Now().Unix()
707
+	c.ServeSuccessJSON(map[string]interface{}{
708
+		"status": 	1,
709
+		"servicetime": serviceTime,
710
+	})
711
+}
712
+
699 713
 func (c *CheckWeightApiController) GetPatientList() {
700
-	syncTime, _ := c.GetInt64("synctime", 0)
701
-	force, _ := c.GetInt64("force", 0)
714
+	ftype,_ := c.GetInt64("type",0)
715
+	sn := c.GetString("sn")
716
+	syncTime := int64(0)
717
+
718
+	redis := service.RedisClient()
719
+	defer redis.Close()
720
+	if len(sn)  > 0 {
721
+		syncTimeStr, _ := redis.Get(sn).Result()
722
+		syncTime,_ = strconv.ParseInt(syncTimeStr, 10, 64)
723
+	}
724
+
725
+	if ftype == 1 {
726
+		timeNow := time.Now().Unix()
727
+		redis.Set(sn, timeNow,0)
728
+	}
729
+
702 730
 	adminUserInfo := c.GetMobileAdminUserInfo()
703
-	patientList, total, error := service.GetPatientListByUpdateTime(adminUserInfo.Org.Id, syncTime, force)
731
+	need_update := 0
732
+	patientList, total, error := service.GetPatientListByUpdateTime(adminUserInfo.Org.Id, int64(syncTime))
733
+	if len(patientList)  > 0 {
734
+		need_update = 1
735
+	}
704 736
 	if error != nil {
705 737
 		c.ErrorLog("获取病人列表失败:%v", error)
706 738
 		c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
@@ -708,6 +740,7 @@ func (c *CheckWeightApiController) GetPatientList() {
708 740
 	}
709 741
 	serviceTime := time.Now().Unix()
710 742
 	c.ServeSuccessJSON(map[string]interface{}{
743
+		"need_update" : need_update,
711 744
 		"patientlist": patientList,
712 745
 		"total":       total,
713 746
 		"servicetime": serviceTime,

+ 1 - 0
controllers/mobile_api_controllers/mobile_api_router_register.go View File

@@ -12,6 +12,7 @@ func MobileAPIControllersRegisterRouters() {
12 12
 	beego.Router("/m/api/savebloodpressure", &CheckWeightApiController{}, "Post:SaveBloodPressure")
13 13
 	beego.Router("/m/api/checkbeforedialysis", &CheckWeightApiController{}, "get:GetPatientInfoBeforeDialysis")
14 14
 	beego.Router("/m/api/getpatientlist", &CheckWeightApiController{}, "get:GetPatientList")
15
+	beego.Router("/m/api/setsynctime", &CheckWeightApiController{}, "get:SetSyncTime")
15 16
 	beego.Router("/m/api/getschedulepatient", &CheckWeightApiController{}, "get:GetPatientListForSchedules")
16 17
 	beego.Router("/m/api/getschedulepatientfind", &CheckWeightApiController{}, "get:GetPatientListForSchedulesFind")
17 18
 	beego.Router("/m/api/getpatientinfo", &CheckWeightApiController{}, "get:GetPatientListById")

+ 3 - 3
service/patient_service.go View File

@@ -80,11 +80,11 @@ func GetAllPatientList(orgID int64) (patients []*models.Patients, total int64, e
80 80
 	return
81 81
 }
82 82
 
83
-func GetPatientListByUpdateTime(orgID int64, syncTime int64, force int64) (patients []*models.PatientListForFaceList, total int64, err error) {
83
+func GetPatientListByUpdateTime(orgID int64, syncTime int64) (patients []*models.PatientListForFaceList, total int64, err error) {
84 84
 	db := readDb.Model(&models.PatientListForFaceList{}).Where("user_org_id=?  AND  status=1  AND  avatar <> 'https://images.shengws.com/201809182128222.png' AND avatar <> 'https://images.shengws.com/201809182128111.png' AND avatar <> ''", orgID)
85
-	if force == 0 {
85
+	
86 86
 		db = db.Where("updated_time >= ?", syncTime)
87
-	}
87
+	
88 88
 	err = db.Count(&total).Find(&patients).Error
89 89
 	return
90 90
 }