张保健 пре 3 година
родитељ
комит
2077e12f84

+ 4 - 4
conf/app.conf Прегледај датотеку

@@ -1,5 +1,5 @@
1 1
 appname = 血透
2
-httpport = 9531
2
+httpport = 9529
3 3
 runmode = prod
4 4
 
5 5
 #
@@ -121,10 +121,10 @@ writepatientuser = syh
121 121
 writepatientpass = xhPECP2nFObR8aUK
122 122
 writepatientname = sgj_cdm
123 123
 
124
-redishost = 349e580b2a524290.redis.rds.aliyuncs.com
124
+redishost = kuyicloud.redis.rds.aliyuncs.com
125 125
 redisport = 6379
126
-redispasswrod = TZtBW098WId3i27clkpj3q8dnUaVFP
127
-redisdb = 0
126
+redispasswrod = 1Q2W3e4r!@#$
127
+redisdb = 8
128 128
 
129 129
 
130 130
 

+ 5 - 5
controllers/base_api_controller.go Прегледај датотеку

@@ -4,7 +4,7 @@ import (
4 4
 	"XT_New/enums"
5 5
 	"XT_New/models"
6 6
 	"XT_New/service"
7
-	"fmt"
7
+	_"fmt"
8 8
 	"strconv"
9 9
 	"strings"
10 10
 )
@@ -119,7 +119,7 @@ func (this *BaseAuthAPIController) Prepare() {
119 119
 			} else {
120 120
 				roles = strings.Split(role.RoleIds, ",")
121 121
 			}
122
-			fmt.Println(roles)
122
+			// fmt.Println(roles)
123 123
 
124 124
 			//获取该用户下所有角色的权限总集
125 125
 			var userRolePurviews string
@@ -135,7 +135,7 @@ func (this *BaseAuthAPIController) Prepare() {
135 135
 			}
136 136
 			//该用户所拥有角色的权限的总集
137 137
 			userRolePurviewsArr = RemoveRepeatedPurviewElement2(strings.Split(userRolePurviews, ","))
138
-			fmt.Println(userRolePurviewsArr)
138
+			// fmt.Println(userRolePurviewsArr)
139 139
 			//系统所记录的权限列表
140 140
 			allPermission, _ := service.GetAllFunctionPurview()
141 141
 
@@ -184,7 +184,7 @@ func (this *BaseAuthAPIController) Prepare() {
184 184
 			} else {
185 185
 				roles = strings.Split(role.RoleIds, ",")
186 186
 			}
187
-			fmt.Println(roles)
187
+			// fmt.Println(roles)
188 188
 
189 189
 			//获取该用户下所有角色的权限总集
190 190
 			var userRolePurviews string
@@ -200,7 +200,7 @@ func (this *BaseAuthAPIController) Prepare() {
200 200
 			}
201 201
 			//该用户所拥有角色的权限的总集
202 202
 			userRolePurviewsArr = RemoveRepeatedPurviewElement2(strings.Split(userRolePurviews, ","))
203
-			fmt.Println(userRolePurviewsArr)
203
+			// fmt.Println(userRolePurviewsArr)
204 204
 			//系统所记录的权限列表
205 205
 			allPermission, _ := service.GetAllFunctionPurview()
206 206
 

+ 152 - 44
controllers/mobile_api_controllers/dialysis_api_controller.go Прегледај датотеку

@@ -92,15 +92,95 @@ func (this *DialysisAPIController) Scheduals() {
92 92
 
93 93
 	if len(scheduals_json_str) == 0 { //没有到缓存数据,从数据库中获取数据,进行缓存到redis
94 94
 		scheduals, err := service.MobileGetDialysisScheduals(orgID, date.Unix(), schedualType)
95
-
96 95
 		if err != nil {
97 96
 			this.ErrorLog("获取排班信息失败:%v", err)
98 97
 			this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
99 98
 		} else {
100
-
101 99
 			if len(scheduals) > 0 {
100
+				patients, _ := service.GetAllPatientListByList(orgID)
101
+				devices, _ := service.GetAllDevicetByList(orgID)
102
+				advices, _ := service.GetAllAdvicestByList(orgID, date.Unix())
103
+				prescriptions,_ := service.GetAllPrescriptionsByList(orgID, date.Unix())
104
+				assessmentBefores,_ := service.GetAllAssessmentBeforesByList(orgID, date.Unix())
105
+				dialysisOrders,_ := service.GetAllDialysisOrdersByList(orgID, date.Unix())
106
+				treatmentSummarys,_ := service.GetAllTreatmentSummarysByList(orgID, date.Unix())
107
+				AssessmentAfterDislysis,_ := service.GetAllAssessmentAfterDislysisByList(orgID, date.Unix())
108
+				hisAdvices,_ := service.GetAllHisAdvicesByList(orgID, date.Unix())
109
+
110
+				for key,item := range scheduals {
111
+					// 获取患者信息
112
+					for _,patient := range patients {
113
+						if item.PatientId == patient.ID {
114
+							scheduals[key].SchedualPatient = patient
115
+							break
116
+						}
117
+					}
118
+					// 床位信息
119
+					for _,device := range devices {
120
+						if item.BedId == device.ID {
121
+							scheduals[key].DeviceNumber = device
122
+							break
123
+						}
124
+					}
125
+
126
+					// 医嘱信息
127
+					scheduals[key].Advices = make([]models.VMDoctorAdviceForList, 0)
128
+					for _,advice := range advices {
129
+						if item.PatientId == advice.PatientId{
130
+							scheduals[key].Advices = append(scheduals[key].Advices,advice)
131
+						}
132
+					}
133
+
134
+					// 医嘱信息
135
+					scheduals[key].HisAdvices = make([]service.VMHisDoctorAdviceInfo, 0)
136
+					for _,hisAdvice := range hisAdvices {
137
+						if item.PatientId == hisAdvice.PatientId{
138
+							scheduals[key].HisAdvices = append(scheduals[key].HisAdvices,hisAdvice)
139
+						}
140
+					}
141
+
142
+					// 医嘱信息
143
+					for _,prescription := range prescriptions {
144
+						if item.PatientId == prescription.PatientId{
145
+							scheduals[key].Prescription = prescription
146
+							break
147
+						}
148
+					}
149
+
150
+					// 透前评估
151
+					for _,assessmentBefore := range assessmentBefores {
152
+						if item.PatientId == assessmentBefore.PatientId{
153
+							scheduals[key].AssessmentBeforeDislysis = assessmentBefore
154
+							break
155
+						}
156
+					}
157
+
158
+					// 透析上下机
159
+					for _,dialysisOrder := range dialysisOrders {
160
+						if item.PatientId == dialysisOrder.PatientId{
161
+							scheduals[key].DialysisOrder = dialysisOrder
162
+							break
163
+						}
164
+					}
165
+
166
+					// 治疗小节
167
+					for _,afterDislysis := range AssessmentAfterDislysis {
168
+						if item.PatientId == afterDislysis.PatientId{
169
+							scheduals[key].AssessmentAfterDislysis = afterDislysis
170
+							break
171
+						}
172
+					}
173
+
174
+					// 透后评估
175
+					for _,treatmentSummary := range treatmentSummarys {
176
+						if item.PatientId == treatmentSummary.PatientId{
177
+							scheduals[key].TreatmentSummary = treatmentSummary
178
+							break
179
+						}
180
+					}
181
+				}
102 182
 				//缓存数据
103
-				scheduals_json, err := json.Marshal(scheduals)
183
+				scheduals_json, err := json.Marshal(&scheduals)
104 184
 				if err == nil {
105 185
 					redis.Set(key, scheduals_json, time.Second*60)
106 186
 				}
@@ -225,7 +305,6 @@ func (this *DialysisAPIController) WaitingScheduals() {
225 305
 // @param patient_id:int
226 306
 // @param date:string (yyyy-MM-dd)
227 307
 func (this *DialysisAPIController) DialysisRecord() {
228
-
229 308
 	patientID, _ := this.GetInt64("patient_id")
230 309
 	recordDateStr := this.GetString("date")
231 310
 	if patientID <= 0 {
@@ -243,16 +322,19 @@ func (this *DialysisAPIController) DialysisRecord() {
243 322
 	}
244 323
 
245 324
 	adminInfo := this.GetMobileAdminUserInfo()
246
-	patient, getPatientErr := service.MobileGetPatientDetail(adminInfo.Org.Id, patientID)
325
+
326
+	// 先走redis,没有走数据库
327
+	patient, getPatientErr := service.FindPatientByIdWithDiseases(adminInfo.Org.Id, patientID)
247 328
 	if getPatientErr != nil {
248 329
 		this.ErrorLog("获取患者信息失败:%v", getPatientErr)
249 330
 		this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
250 331
 		return
251
-	} else if patient == nil {
332
+	} else if patient.ID == 0 {
252 333
 		this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
253 334
 		return
254 335
 	}
255 336
 
337
+	// 先走redis,没有走数据库
256 338
 	schedual, getSchedualErr := service.MobileGetSchedualDetail(adminInfo.Org.Id, patientID, date.Unix())
257 339
 
258 340
 	if getSchedualErr != nil {
@@ -261,6 +343,7 @@ func (this *DialysisAPIController) DialysisRecord() {
261 343
 		return
262 344
 	}
263 345
 
346
+	// 先走redis,没有走数据库
264 347
 	receiverTreatmentAccess, getRTARErr := service.MobileGetReceiverTreatmentAccessRecord(adminInfo.Org.Id, patientID, date.Unix())
265 348
 	if getRTARErr != nil {
266 349
 		this.ErrorLog("获取接诊评估失败:%v", getRTARErr)
@@ -268,6 +351,7 @@ func (this *DialysisAPIController) DialysisRecord() {
268 351
 		return
269 352
 	}
270 353
 
354
+	// // 先走redis,没有走数据库
271 355
 	predialysisEvaluation, getPEErr := service.MobileGetPredialysisEvaluation(adminInfo.Org.Id, patientID, date.Unix())
272 356
 	if getPEErr != nil {
273 357
 		this.ErrorLog("获取透前评估失败:%v", getPEErr)
@@ -275,6 +359,7 @@ func (this *DialysisAPIController) DialysisRecord() {
275 359
 		return
276 360
 	}
277 361
 
362
+	// // 先走redis,没有走数据库
278 363
 	lastPredialysisEvaluation, getLPEErr := service.MobileGetLastTimePredialysisEvaluation(adminInfo.Org.Id, patientID, date.Unix())
279 364
 	if getLPEErr != nil {
280 365
 		this.ErrorLog("获取上一次透前评估失败:%v", getLPEErr)
@@ -282,6 +367,7 @@ func (this *DialysisAPIController) DialysisRecord() {
282 367
 		return
283 368
 	}
284 369
 
370
+	// // 先走redis,没有走数据库
285 371
 	doctorAdvices, getDoctorAdvicesErr := service.MobileGetDoctorAdvicesByGroups(adminInfo.Org.Id, patientID, date.Unix())
286 372
 	if getDoctorAdvicesErr != nil {
287 373
 		this.ErrorLog("获取临时医嘱失败:%v", getDoctorAdvicesErr)
@@ -289,6 +375,7 @@ func (this *DialysisAPIController) DialysisRecord() {
289 375
 		return
290 376
 	}
291 377
 
378
+	// // 先走redis,没有走数据库
292 379
 	dialysisOrder, getDialysisOrderErr := service.MobileGetSchedualDialysisRecord(adminInfo.Org.Id, patientID, date.Unix())
293 380
 	if getDialysisOrderErr != nil {
294 381
 		this.ErrorLog("获取透析记录失败:%v", getDialysisOrderErr)
@@ -296,6 +383,7 @@ func (this *DialysisAPIController) DialysisRecord() {
296 383
 		return
297 384
 	}
298 385
 
386
+	// // 先走redis,没有走数据库
299 387
 	doubleCheck, getDoubleCheckErr := service.MobileGetDoubleCheck(adminInfo.Org.Id, patientID, date.Unix())
300 388
 	if getDoubleCheckErr != nil {
301 389
 		this.ErrorLog("获取双人核对记录失败:%v", getDoubleCheckErr)
@@ -303,6 +391,7 @@ func (this *DialysisAPIController) DialysisRecord() {
303 391
 		return
304 392
 	}
305 393
 
394
+	// // 先走redis,没有走数据库
306 395
 	monitorRecords, getMonitorRecordsErr := service.MobileGetMonitorRecords(adminInfo.Org.Id, patientID, date.Unix())
307 396
 	if getMonitorRecordsErr != nil {
308 397
 		this.ErrorLog("获取透析监测记录失败:%v", getMonitorRecordsErr)
@@ -311,6 +400,7 @@ func (this *DialysisAPIController) DialysisRecord() {
311 400
 	}
312 401
 	var lastMonitorRecord *models.MonitoringRecord
313 402
 
403
+	// // 先走redis,没有走数据库
314 404
 	lastMonitorRecord, getLastErr := service.MobileGetLastMonitorRecord(adminInfo.Org.Id, patientID, date.Unix())
315 405
 	if getLastErr != nil {
316 406
 		this.ErrorLog("获取上一次透析的监测记录失败:%v", getLastErr)
@@ -318,6 +408,7 @@ func (this *DialysisAPIController) DialysisRecord() {
318 408
 		return
319 409
 	}
320 410
 
411
+	// // 先走redis,没有走数据库
321 412
 	assessmentAfterDislysis, getAADErr := service.MobileGetAssessmentAfterDislysis(adminInfo.Org.Id, patientID, date.Unix())
322 413
 	if getAADErr != nil {
323 414
 		this.ErrorLog("获取透后评估失败:%v", getAADErr)
@@ -325,6 +416,7 @@ func (this *DialysisAPIController) DialysisRecord() {
325 416
 		return
326 417
 	}
327 418
 
419
+	// // 先走redis,没有走数据库
328 420
 	lastAssessmentAfterDislysis, getLAADErr := service.MobileGetLastTimeAssessmentAfterDislysis(adminInfo.Org.Id, patientID, date.Unix())
329 421
 	if getLAADErr != nil {
330 422
 		this.ErrorLog("获取上一次透后评估失败:%v", getLAADErr)
@@ -332,6 +424,7 @@ func (this *DialysisAPIController) DialysisRecord() {
332 424
 		return
333 425
 	}
334 426
 
427
+	// // 先走redis,没有走数据库
335 428
 	treatmentSummary, getTreatmentSummaryErr := service.MobileGetTreatmentSummary(adminInfo.Org.Id, patientID, date.Unix())
336 429
 	if getTreatmentSummaryErr != nil {
337 430
 		this.ErrorLog("获取治疗小结失败:%v", getTreatmentSummaryErr)
@@ -339,66 +432,79 @@ func (this *DialysisAPIController) DialysisRecord() {
339 432
 		return
340 433
 	}
341 434
 
435
+	// // 先走redis,没有走数据库
342 436
 	dialysisPrescribe, _ := service.MobileGetDialysisPrescribeByModeId(adminInfo.Org.Id, patientID, date.Unix(), schedual.ModeId)
343 437
 
344
-	//if getDialysisPrescribeErr != nil {
345
-	//	this.ErrorLog("获取透析处方失败:%v", getDialysisPrescribeErr)
346
-	//	this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
347
-	//	return
348
-	//}
438
+	// //if getDialysisPrescribeErr != nil {
439
+	// //	this.ErrorLog("获取透析处方失败:%v", getDialysisPrescribeErr)
440
+	// //	this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
441
+	// //	return
442
+	// //}
349 443
 
444
+	// // 先走redis,没有走数据库
350 445
 	dialysisSolution, _ := service.MobileGetDialysisSolutionByModeId(adminInfo.Org.Id, patientID, schedual.ModeId)
351
-	//if getDialysisSolutionErr != nil {
352
-	//	this.ErrorLog("获取透析方案失败:%v", getDialysisSolutionErr)
353
-	//	this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
354
-	//	return
355
-	//}
356
-
357
-	lastDialysisPrescribe, _ := service.MobileGetLastDialysisPrescribeByModeId(adminInfo.Org.Id, patientID, schedual.ModeId)
358
-	//fmt.Println("上次透析处方",lastDialysisPrescribe.DialyzerPerfusionApparatus)
359
-	//if getDialysisPrescribeErr != nil {
360
-	//	this.ErrorLog("获取透析处方失败:%v", getDialysisPrescribeErr)
361
-	//	this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
362
-	//	return
363
-	//}
364
-
365
-	//获取系统透析处方模版
446
+	// //if getDialysisSolutionErr != nil {
447
+	// //	this.ErrorLog("获取透析方案失败:%v", getDialysisSolutionErr)
448
+	// //	this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
449
+	// //	return
450
+	// //}
451
+
452
+	// // 先走redis,没有走数据库
453
+	lastDialysisPrescribe, _ := service.MobileGetLastDialysisPrescribeByModeId(adminInfo.Org.Id, patientID,date.Unix(), schedual.ModeId)
454
+	// //fmt.Println("上次透析处方",lastDialysisPrescribe.DialyzerPerfusionApparatus)
455
+	// //if getDialysisPrescribeErr != nil {
456
+	// //	this.ErrorLog("获取透析处方失败:%v", getDialysisPrescribeErr)
457
+	// //	this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
458
+	// //	return
459
+	// //}
460
+
461
+	// //获取系统透析处方模版
462
+	// // 先走redis,没有走数据库
366 463
 	systemDialysisPrescribe, _ := service.MobileGetSystemDialysisPrescribeByModeId(adminInfo.Org.Id, schedual.ModeId)
367
-	//if getSystemDialysisPrescribeErr != nil {
368
-	//	this.ErrorLog("获取系统透析处方失败:%v", getSystemDialysisPrescribeErr)
369
-	//	this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
370
-	//	return
371
-	//}
464
+	// //if getSystemDialysisPrescribeErr != nil {
465
+	// //	this.ErrorLog("获取系统透析处方失败:%v", getSystemDialysisPrescribeErr)
466
+	// //	this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
467
+	// //	return
468
+	// //}
372 469
 
373
-	//dialysisSolution, getDialysisSolutionErr := service.MobileGetDialysisSolution(adminInfo.Org.Id, patientID)
470
+	// //dialysisSolution, getDialysisSolutionErr := service.MobileGetDialysisSolution(adminInfo.Org.Id, patientID)
374 471
 
375
-	//operators, _ := service.GetAllAdminUserES(adminInfo.Org.Id, adminInfo.App.Id)
472
+	// //operators, _ := service.GetAllAdminUserES(adminInfo.Org.Id, adminInfo.App.Id)
376 473
 
474
+	// 先走redis,没有走数据库
377 475
 	_, is_open_config := service.FindXTHisRecordByOrgId(adminInfo.Org.Id)
378 476
 
477
+	// 先走redis,没有走数据库
379 478
 	_, is_project_open_config := service.FindXTHisProjectByOrgId(adminInfo.Org.Id)
380 479
 
480
+	// 先走redis,没有走数据库
381 481
 	projects, _ := service.GetHisPrescriptionProjects(adminInfo.Org.Id, patientID, date.Unix())
382 482
 
483
+	// // 先走redis,没有走数据库
383 484
 	stockType, _ := service.GetStockType(adminInfo.Org.Id)
384 485
 
486
+	// 先走redis,没有走数据库
385 487
 	prepare, _ := service.GetDialyStockOut(adminInfo.Org.Id, date.Unix(), patientID)
386 488
 
387
-	//获取最后一次血管通路
388
-	lastAssessment, parseDateErr := service.GetLastPassWayAssessment(adminInfo.Org.Id, patientID)
489
+	// //获取最后一次血管通路
490
+	// 先走redis,没有走数据库
491
+	lastAssessment, _ := service.GetLastPassWayAssessment(adminInfo.Org.Id, patientID)
389 492
 
390
-	prescribeOne, parseDateErr := service.MobileGetDialysisPrescribeByModeIdOne(adminInfo.Org.Id, patientID, date.Unix())
493
+	// 先走redis,没有走数据库
494
+	prescribeOne, _ := service.MobileGetDialysisPrescribeByModeIdOne(adminInfo.Org.Id, patientID, date.Unix())
391 495
 	var his_advices []*models.HisDoctorAdviceInfo
392 496
 	if is_open_config.IsOpen == 1 {
497
+		// 先走redis,没有走数据库
393 498
 		his_advices, _ = service.GetAllHisDoctorAdvice(adminInfo.Org.Id, patientID, date.Unix())
394 499
 	}
395 500
 
396
-	if getLPEErr != nil {
397
-		this.ErrorLog("获取上一次透前评估失败:%v", getLPEErr)
398
-		this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
399
-		return
400
-	}
501
+	// if getLPEErr != nil {
502
+	// 	this.ErrorLog("获取上一次透前评估失败:%v", getLPEErr)
503
+	// 	this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
504
+	// 	return
505
+	// }
401 506
 
507
+	// 先走redis,没有走数据库
402 508
 	lastDryWeightDislysis, getDryErr := service.MobileGetLastDryWeight(adminInfo.Org.Id, patientID)
403 509
 	if getDryErr != nil {
404 510
 		this.ErrorLog("获取最后一条干体重失败:%v", getDryErr)
@@ -406,12 +512,14 @@ func (this *DialysisAPIController) DialysisRecord() {
406 512
 		return
407 513
 	}
408 514
 
409
-	//headNurses, _ := service.GetAllSpecialPermissionAdminUsersWithoutStatus(adminInfo.Org.Id, adminInfo.App.Id, models.SpecialPermissionTypeHeadNurse)
515
+	// //headNurses, _ := service.GetAllSpecialPermissionAdminUsersWithoutStatus(adminInfo.Org.Id, adminInfo.App.Id, models.SpecialPermissionTypeHeadNurse)
410 516
 
517
+	// 先走redis,没有走数据库
411 518
 	_, gobalConfig := service.FindAutomaticReduceRecordByOrgId(adminInfo.Org.Id)
412
-	//goodTypes, _ := service.FindAllGoodTypeByType(1)          //查出所有库存配置的系统类型
413
-	//goodInfos, _ := service.FindAllGoodInfo(adminInfo.Org.Id) //查出所有库存配置的系统类型
519
+	// //goodTypes, _ := service.FindAllGoodTypeByType(1)          //查出所有库存配置的系统类型
520
+	// //goodInfos, _ := service.FindAllGoodInfo(adminInfo.Org.Id) //查出所有库存配置的系统类型
414 521
 
522
+	// 先走redis,没有走数据库
415 523
 	operators, _ := service.GetAllStarfEs(adminInfo.Org.Id)
416 524
 
417 525
 	//consumables, _ := service.FindConsumablesByDate(adminInfo.Org.Id, patientID, date.Unix())

+ 2 - 3
controllers/mobile_api_controllers/mobile_api_base_controller.go Прегледај датотеку

@@ -61,10 +61,9 @@ func (this *MobileBaseAPIAuthController) Prepare() {
61 61
 	this.MobileBaseAPIController.Prepare()
62 62
 	adminUserInfo := this.GetMobileAdminUserInfo()
63 63
 
64
-	fmt.Println(token)
65 64
 	if len(token) == 0 {
66 65
 		this.DelSession("mobile_admin_user_info")
67
-		fmt.Println(logout_cookie)
66
+		// fmt.Println(logout_cookie)
68 67
 		if len(logout_cookie) == 1 {
69 68
 			this.Ctx.SetCookie("logout_cookie", "2")
70 69
 			this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeLogOut)
@@ -161,7 +160,7 @@ func (this *MobileBaseAPIAuthController) Prepare() {
161 160
 				userRolePurviewsArr = dat
162 161
 			}
163 162
 
164
-			fmt.Println(userRolePurviewsArr)
163
+			// fmt.Println(userRolePurviewsArr)
165 164
 
166 165
 			//系统所记录的权限列表
167 166
 			allPermission, _ := service.GetAllFunctionPurview()

+ 1 - 1
controllers/mobile_api_controllers/mobile_api_router_register.go Прегледај датотеку

@@ -122,7 +122,7 @@ func MobileAPIControllersRegisterRouters() {
122 122
 
123 123
 	beego.Router("/m/api/patient/search", &PatientApiController{}, "Get:GetSearchPatient")
124 124
 
125
-	beego.Router("/m/api/dialysis/schedule", &DialysisAPIController{}, "Get:GetDialysisSchedule")
125
+	beego.Router("/m/api/dialysis/schedule", &DialysisAPIController{}, "Get:Scheduals")
126 126
 
127 127
 	beego.Router("/m/api/doctoradvice/get", &DialysisAPIController{}, "Get:GetLastOrNextDoctorAdvice")
128 128
 

+ 11 - 0
models/device_models.go Прегледај датотеку

@@ -155,6 +155,17 @@ func (DeviceNumber) TableName() string {
155 155
 	return "xt_device_number"
156 156
 }
157 157
 
158
+type MDeviceNumberForList struct {
159
+	DeviceNumber
160
+
161
+	Zone *DeviceZone `gorm:"ForeignKey:ZoneID" json:"zone"`
162
+}
163
+
164
+func (MDeviceNumberForList) TableName() string {
165
+	return "xt_device_number"
166
+}
167
+
168
+
158 169
 type XtDeviceNumber struct {
159 170
 	ID      int64  `gorm:"column:bed_id" json:"bed_id" form:"bed_id"`
160 171
 	OrgId   int64  `gorm:"column:org_id" json:"org_id" form:"org_id"`

+ 69 - 0
models/patient_models.go Прегледај датотеку

@@ -9,6 +9,75 @@ func (PatientListForFaceList) TableName() string {
9 9
 	return "xt_patients"
10 10
 }
11 11
 
12
+type MSchedualPatientList struct {
13
+	ID                 int64  `gorm:"column:id" json:"id" form:"id"`
14
+	UserOrgId          int64  `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
15
+	UserId             int64  `gorm:"column:user_id" json:"user_id" form:"user_id"`
16
+	PatientType        int64  `gorm:"column:patient_type" json:"patient_type" form:"patient_type"`
17
+	DialysisNo         string `gorm:"column:dialysis_no" json:"dialysis_no" form:"dialysis_no"`
18
+	Avatar             string `gorm:"column:avatar" json:"avatar" form:"avatar"`
19
+	Gender             int64  `gorm:"column:gender" json:"gender" form:"gender"`
20
+	Birthday           int64  `gorm:"column:birthday" json:"birthday" form:"birthday"`
21
+	Age                int64  `gorm:"column:age" json:"age"`
22
+	Name               string `gorm:"column:name" json:"name" form:"name"`
23
+	IdCardNo           string `gorm:"column:id_card_no" json:"id_card_no" form:"id_card_no"`
24
+	UserSysBeforeCount int64  `gorm:"column:user_sys_before_count" json:"user_sys_before_count" form:"user_sys_before_count"`
25
+}
26
+
27
+func (MSchedualPatientList) TableName() string {
28
+	return "xt_patients"
29
+}
30
+
31
+type MDialysisOrderForList struct {
32
+	ID           int64 `gorm:"column:id" json:"id"`
33
+	DialysisDate int64 `gorm:"column:dialysis_date" json:"dialysis_date"`
34
+	UserOrgId    int64 `gorm:"column:user_org_id" json:"user_org_id"`
35
+	PatientId    int64 `gorm:"column:patient_id" json:"patient_id"`
36
+	// PrescriptionId int64  `gorm:"column:prescription_id" json:"prescription_id"`
37
+	Stage int64 `gorm:"column:stage" json:"stage"`
38
+	// Remark         string `gorm:"column:remark" json:"remark"`
39
+	BedID         int64            `gorm:"column:bed_id" json:"bed_id"`
40
+	StartNurse    int64            `gorm:"column:start_nurse" json:"start_nurse"`
41
+	Status        int64            `gorm:"column:status" json:"status"`
42
+	DeviceNumber  *MDeviceNumberForList `gorm:"ForeignKey:BedID" json:"device_number"`
43
+	Creator       int64            `gorm:"column:creator" json:"creator"`
44
+	WashpipeNurse int64            `gorm:"column:washpipe_nurse" json:"washpipe_nurse" form:"washpipe_nurse"`
45
+}
46
+
47
+func (MDialysisOrderForList) TableName() string {
48
+	return "xt_dialysis_order"
49
+}
50
+
51
+type VMTreatmentSummaryForList struct {
52
+	ID              int64  `gorm:"column:id" json:"id"`
53
+	UserOrgId       int64  `gorm:"column:user_org_id" json:"user_org_id"`
54
+	PatientId       int64  `gorm:"column:patient_id" json:"patient_id"`
55
+	AssessmentDate  int64  `gorm:"column:assessment_date" json:"assessment_date"`
56
+	DialysisSummary string `gorm:"column:dialysis_summary" json:"dialysis_summary" form:"dialysis_summary"`
57
+}
58
+
59
+func (VMTreatmentSummaryForList) TableName() string {
60
+	return "xt_treatment_summary"
61
+}
62
+
63
+type VMDoctorAdviceForList struct {
64
+	ID             int64 `gorm:"column:id" json:"id" form:"id"`
65
+	GroupNo        int64 `gorm:"column:groupno" json:"groupno" form:"groupno"`
66
+	UserOrgId      int64 `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
67
+	PatientId      int64 `gorm:"column:patient_id" json:"patient_id" form:"patient_id"`
68
+	AdviceDate     int64 `gorm:"column:advice_date" json:"advice_date" form:"advice_date"`
69
+	Status         int64 `gorm:"column:status" json:"status" form:"status"`
70
+	ExecutionState int64 `gorm:"column:execution_state" json:"execution_state" form:"execution_state"`
71
+	RecordDate     int64 `gorm:"column:record_date" json:"record_date"`
72
+	CheckTime      int64 `gorm:"column:check_time" json:"check_time" form:"check_time"`
73
+	CheckState     int64 `gorm:"column:check_state" json:"check_state" form:"check_state"`
74
+	ParentId       int64 `gorm:"column:parent_id" json:"parent_id" form:"parent_id"`
75
+}
76
+
77
+func (VMDoctorAdviceForList) TableName() string {
78
+	return "xt_doctor_advice"
79
+}
80
+
12 81
 type PatientListForFace struct {
13 82
 	ID          int64  `gorm:"column:id" json:"id" form:"id"`
14 83
 	UserOrgId   int64  `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`

+ 34 - 7
service/dialysis_service.go Прегледај датотеку

@@ -5,7 +5,8 @@ import (
5 5
 	"fmt"
6 6
 	"strings"
7 7
 	"time"
8
-
8
+	"strconv"
9
+	"encoding/json"
9 10
 	"github.com/jinzhu/gorm"
10 11
 )
11 12
 
@@ -771,12 +772,38 @@ func GetAllAdminUserES(orgID int64, appId int64) (es []*models.AdminUserElectron
771 772
 }
772 773
 
773 774
 func GetAllStarfEs(orgid int64) (es []*models.SgjUserAdminRoles, err error) {
774
-
775
-	db := readUserDb.Table("sgj_user_admin_role as x").Where("x.status = 1")
776
-	table := readUserDb.Table("sgj_user_admin_electronic_signature as s")
777
-	fmt.Println("table", table)
778
-	err = db.Select("x.id,x.admin_user_id,x.org_id,x.app_id,x.role_id,x.user_name,x.avatar,x.user_type,s.creator,s.url,s.hash").Joins("left join sgj_user_admin_electronic_signature as s on s.creator = x.admin_user_id and s.status = 1").Where("x.org_id = ?", orgid).Scan(&es).Error
779
-	return es, err
775
+	redis := RedisClient()
776
+	defer redis.Close()
777
+
778
+	// cur_date := time.Now().Format("2006-01-02")
779
+	key := strconv.FormatInt(orgid, 10) + ":starfes"
780
+	starfes_str, _ := redis.Get(key).Result()
781
+
782
+	if len(starfes_str) == 0 { //没有到缓存数据,从数据库中获取数据,进行缓存到redis
783
+		db := readUserDb.Table("sgj_user_admin_role as x").Where("x.status = 1")
784
+		err = db.Select("x.id,x.admin_user_id,x.org_id,x.app_id,x.role_id,x.user_name,x.avatar,x.user_type,s.creator,s.url,s.hash").Joins("left join sgj_user_admin_electronic_signature as s on s.creator = x.admin_user_id and s.status = 1").Where("x.org_id = ?", orgid).Scan(&es).Error
785
+		if err != nil {
786
+			if err == gorm.ErrRecordNotFound {
787
+				return nil, nil
788
+			} else {
789
+				return nil, err
790
+			}
791
+		} else {
792
+			if len(es) > 0 {
793
+				//缓存数据
794
+				starfes_str, err := json.Marshal(es)
795
+				if err == nil {
796
+					redis.Set(key, starfes_str, time.Second*60*60*18)
797
+				}
798
+			} else {
799
+				redis.Set(key, " ", time.Second*60*60*18)
800
+			}
801
+			return es, nil
802
+		}
803
+	} else { //缓存数据了数据,将redis缓存的json字符串转为map
804
+		json.Unmarshal([]byte(starfes_str), &es)
805
+		return es, nil
806
+	}
780 807
 }
781 808
 
782 809
 func FindLastMonitorRecord(patient_id int64, org_id int64) (record models.MonitoringRecord, err error) {

+ 95 - 6
service/gobal_config_service.go Прегледај датотеку

@@ -5,6 +5,8 @@ import (
5 5
 	"fmt"
6 6
 	"github.com/jinzhu/gorm"
7 7
 	"time"
8
+	"encoding/json"
9
+	"strconv"
8 10
 )
9 11
 
10 12
 func CreateAutomaticReduceRecord(config *models.GobalConfig) (err error) {
@@ -18,8 +20,37 @@ func CreateDrugAutomaticReduceRecord(config *models.DrugStockConfig) (err error)
18 20
 }
19 21
 
20 22
 func FindAutomaticReduceRecordByOrgId(org_id int64) (err error, config models.GobalConfig) {
21
-	err = readDb.Model(&models.GobalConfig{}).Where("status = 1 AND org_id = ?", org_id).Find(&config).Error
22
-	return
23
+	redis := RedisClient()
24
+	defer redis.Close()
25
+
26
+	// cur_date := time.Now().Format("2006-01-02")
27
+	key := strconv.FormatInt(org_id, 10) +  ":gobal_config"
28
+	gobal_config_str, _ := redis.Get(key).Result()
29
+
30
+	if len(gobal_config_str) == 0 { //没有到缓存数据,从数据库中获取数据,进行缓存到redis
31
+		err = readDb.Model(&models.GobalConfig{}).Where("status = 1 AND org_id = ?", org_id).Find(&config).Error
32
+		if err != nil {
33
+			if err == gorm.ErrRecordNotFound {
34
+				return nil,config
35
+			} else {
36
+				return err,config
37
+			}
38
+		} else {
39
+			if config.ID > 0 {
40
+				//缓存数据
41
+				gobal_config_str, err := json.Marshal(config)
42
+				if err == nil {
43
+					redis.Set(key, gobal_config_str, time.Second*60*60*18)
44
+				}
45
+			} else {
46
+				redis.Set(key, " ", time.Second*60*60*18)
47
+			}
48
+			return nil,config
49
+		}
50
+	} else { //缓存数据了数据,将redis缓存的json字符串转为map
51
+		json.Unmarshal([]byte(gobal_config_str), &config)
52
+		return nil,config
53
+	}
23 54
 }
24 55
 
25 56
 func FindDrugStockAutomaticReduceRecordByOrgId(org_id int64) (err error, config models.DrugStockConfig) {
@@ -181,8 +212,37 @@ func GetExportLogByType(org_id int64, log_type int64) (log []*models.ExportLog,
181 212
 }
182 213
 
183 214
 func FindXTHisRecordByOrgId(org_id int64) (err error, config models.XtHisConfig) {
184
-	err = readDb.Model(&models.XtHisConfig{}).Where("status = 1 AND user_org_id = ?", org_id).Find(&config).Error
185
-	return
215
+	redis := RedisClient()
216
+	defer redis.Close()
217
+
218
+	// cur_date := time.Now().Format("2006-01-02")
219
+	key := strconv.FormatInt(org_id, 10) + ":" + ":his_config"
220
+	his_config_str, _ := redis.Get(key).Result()
221
+
222
+	if len(his_config_str) == 0 { //没有到缓存数据,从数据库中获取数据,进行缓存到redis
223
+		err = readDb.Model(&models.XtHisConfig{}).Where("status = 1 AND user_org_id = ?", org_id).Find(&config).Error
224
+		if err != nil {
225
+			if err == gorm.ErrRecordNotFound {
226
+				return nil,config
227
+			} else {
228
+				return err,config
229
+			}
230
+		} else {
231
+			if config.ID > 0 {
232
+				//缓存数据
233
+				his_config_str, err := json.Marshal(config)
234
+				if err == nil {
235
+					redis.Set(key, his_config_str, time.Second*60*60*18)
236
+				}
237
+			} else {
238
+				redis.Set(key, " ", time.Second*60*60*18)
239
+			}
240
+			return nil,config
241
+		}
242
+	} else { //缓存数据了数据,将redis缓存的json字符串转为map
243
+		json.Unmarshal([]byte(his_config_str), &config)
244
+		return nil,config
245
+	}
186 246
 }
187 247
 
188 248
 func UpdateXTHisRecord(config *models.XtHisConfig) (err error) {
@@ -197,8 +257,37 @@ func CreateXTHisRecord(config *models.XtHisConfig) (err error) {
197 257
 
198 258
 //TODO:项目开关
199 259
 func FindXTHisProjectByOrgId(org_id int64) (err error, config models.XtHisProjectConfig) {
200
-	err = readDb.Model(&models.XtHisProjectConfig{}).Where("status = 1 AND user_org_id = ?", org_id).Find(&config).Error
201
-	return
260
+	redis := RedisClient()
261
+	defer redis.Close()
262
+
263
+	// cur_date := time.Now().Format("2006-01-02")
264
+	key := strconv.FormatInt(org_id, 10) + ":his_project_config"
265
+	his_project_config_str, _ := redis.Get(key).Result()
266
+
267
+	if len(his_project_config_str) == 0 { //没有到缓存数据,从数据库中获取数据,进行缓存到redis
268
+		err = readDb.Model(&models.XtHisProjectConfig{}).Where("status = 1 AND user_org_id = ?", org_id).Find(&config).Error
269
+		if err != nil {
270
+			if err == gorm.ErrRecordNotFound {
271
+				return nil, config
272
+			} else {
273
+				return err, config
274
+			}
275
+		} else {
276
+			if config.ID > 0 {
277
+				//缓存数据
278
+				his_project_config_str, err := json.Marshal(config)
279
+				if err == nil {
280
+					redis.Set(key, his_project_config_str, time.Second*60*60*18)
281
+				}
282
+			} else {
283
+				redis.Set(key, " ", time.Second*60*60*18)
284
+			}
285
+			return nil,config
286
+		}
287
+	} else { //缓存数据了数据,将redis缓存的json字符串转为map
288
+		json.Unmarshal([]byte(his_project_config_str), &config)
289
+		return nil,config
290
+	}
202 291
 }
203 292
 
204 293
 func UpdateXTHisProjectRecord(config *models.XtHisProjectConfig) (err error) {

+ 34 - 2
service/his_service.go Прегледај датотеку

@@ -6,6 +6,8 @@ import (
6 6
 	"github.com/jinzhu/gorm"
7 7
 	"strings"
8 8
 	"time"
9
+	"encoding/json"
10
+	"strconv"
9 11
 )
10 12
 
11 13
 type VMSchedule struct {
@@ -1984,8 +1986,38 @@ func GetHisPrescriptionProjectsByID(id int64) (projects []*models.HisPrescriptio
1984 1986
 }
1985 1987
 
1986 1988
 func GetHisPrescriptionProjects(user_org_id int64, patient_id int64, record_time int64) (projects []*models.HisPrescriptionProject, err error) {
1987
-	err = readDb.Model(&models.HisPrescriptionProject{}).Preload("HisProject", "status = 1").Preload("GoodInfo", "status = 1").Where("user_org_id = ? AND patient_id = ? AND record_date = ? AND  status = 1", user_org_id, patient_id, record_time).Find(&projects).Error
1988
-	return
1989
+	redis := RedisClient()
1990
+	defer redis.Close()
1991
+
1992
+	// cur_date := time.Now().Format("2006-01-02")
1993
+	key := strconv.FormatInt(user_org_id, 10) + ":"+ strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(record_time, 10) + ":his_prescription_project"
1994
+	his_prescription_project_str, _ := redis.Get(key).Result()
1995
+
1996
+	if len(his_prescription_project_str) == 0 { //没有到缓存数据,从数据库中获取数据,进行缓存到redis
1997
+		err = readDb.Model(&models.HisPrescriptionProject{}).Preload("HisProject", "status = 1").Preload("GoodInfo", "status = 1").Where("user_org_id = ? AND patient_id = ? AND record_date = ? AND  status = 1", user_org_id, patient_id, record_time).Find(&projects).Error
1998
+		if err != nil {
1999
+			if err == gorm.ErrRecordNotFound {
2000
+				return nil, nil
2001
+			} else {
2002
+				return nil, err
2003
+			}
2004
+		} else {
2005
+			if len(projects) > 0 {
2006
+				//缓存数据
2007
+				his_prescription_project_str, err := json.Marshal(projects)
2008
+				if err == nil {
2009
+					redis.Set(key, his_prescription_project_str, time.Second*60*60*18)
2010
+				}
2011
+			} else {
2012
+				redis.Set(key, " ", time.Second*60*60*18)
2013
+			}
2014
+			return projects, nil
2015
+		}
2016
+	} else { //缓存数据了数据,将redis缓存的json字符串转为map
2017
+		json.Unmarshal([]byte(his_prescription_project_str), &projects)
2018
+		return projects, nil
2019
+	}
2020
+
1989 2021
 }
1990 2022
 
1991 2023
 func GetHisPrescriptionProjectByID(id int64) (projects models.HisPrescriptionProject, err error) {

+ 36 - 7
service/login_service.go Прегледај датотеку

@@ -3,8 +3,10 @@ package service
3 3
 import (
4 4
 	"XT_New/models"
5 5
 	"XT_New/utils"
6
-
6
+	"strconv"
7 7
 	"github.com/jinzhu/gorm"
8
+	"encoding/json"
9
+	"time"
8 10
 )
9 11
 
10 12
 func IsSuperAdmin(mobile string) bool {
@@ -234,13 +236,40 @@ func IsMobileRegister(mobile string) bool {
234 236
 
235 237
 func FindAppRoleById(id int64) (*models.App_Role, error) {
236 238
 	var model models.App_Role
237
-	err := readUserDb.Model(&models.App_Role{}).Where("id = ? ", id).First(&model).Error
238
-	if err != nil {
239
-		if err == gorm.ErrRecordNotFound {
240
-			return nil, nil
239
+
240
+	redis := RedisClient()
241
+	defer redis.Close()
242
+
243
+	// cur_date := time.Now().Format("2006-01-02")
244
+	key := "user_admin_role:" + strconv.FormatInt(id, 10)
245
+	role_str, _ := redis.Get(key).Result()
246
+
247
+	if len(role_str) == 0 { //没有到缓存数据,从数据库中获取数据,进行缓存到redis
248
+		err := readUserDb.Model(&models.App_Role{}).Where("id = ? ", id).First(&model).Error
249
+		if err != nil {
250
+			if err == gorm.ErrRecordNotFound {
251
+				return nil, nil
252
+			} else {
253
+				return nil, err
254
+			}
241 255
 		} else {
242
-			return nil, err
256
+			if model.Id > 0 {
257
+				//缓存数据
258
+				role_json, err := json.Marshal(model)
259
+				if err == nil {
260
+					redis.Set(key, role_json, time.Second*60*60*18)
261
+				}
262
+			}
263
+			return &model, nil
264
+		}
265
+
266
+	} else { //缓存数据了数据,将redis缓存的json字符串转为map
267
+		if err := json.Unmarshal([]byte(role_str), &model); err == nil {
268
+
269
+		} else {
270
+
243 271
 		}
272
+		return &model, nil
244 273
 	}
245
-	return &model, nil
274
+
246 275
 }

+ 594 - 124
service/mobile_dialysis_service.go Прегледај датотеку

@@ -5,6 +5,8 @@ import (
5 5
 	"fmt"
6 6
 	"github.com/jinzhu/gorm"
7 7
 	"time"
8
+	"encoding/json"
9
+	"strconv"
8 10
 )
9 11
 
10 12
 // func GetSchedualPatients(orgID int64) ([]*MDialysisScheduleVM, error) {
@@ -23,21 +25,21 @@ import (
23 25
 // 	return vms, err
24 26
 // }
25 27
 
26
-func MobileGetDialysisScheduals(orgID int64, scheduleDate int64, scheduleType int64) ([]*MDialysisScheduleVM, error) {
27
-	var vms []*MDialysisScheduleVM
28
+func MobileGetDialysisScheduals(orgID int64, scheduleDate int64, scheduleType int64) ([]*MDialysisScheduleVMForList, error) {
29
+	var vms []*MDialysisScheduleVMForList
28 30
 	db := readDb.
29 31
 		Table("xt_schedule as sch").
30
-		Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
31
-		Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
32
-		Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
33
-		Preload("Advices", "status = 1 AND user_org_id = ? AND advice_type = 2 AND advice_date = ? ", orgID, scheduleDate).
34
-		Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
35
-		Preload("AssessmentBeforeDislysis", "status = 1 AND user_org_id = ? AND assessment_date = ? ", orgID, scheduleDate).
36
-		Preload("DialysisOrder", "status = 1 AND user_org_id = ? AND dialysis_date = ?", orgID, scheduleDate).
37
-		Preload("DialysisOrder.DeviceNumber", "status = 1 AND org_id = ?", orgID).
38
-		Preload("TreatmentSummary", "status = 1  AND user_org_id = ? AND assessment_date = ?", orgID, scheduleDate).
39
-		Preload("AssessmentAfterDislysis", "status = 1  AND user_org_id = ? AND assessment_date = ?", orgID, scheduleDate).
40
-		Preload("HisAdvices", "status = 1 AND user_org_id = ? AND advice_date = ? ", orgID, scheduleDate).
32
+		// Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
33
+		// Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
34
+		// Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
35
+		// Preload("Advices", "status = 1 AND user_org_id = ? AND advice_type = 2 AND advice_date = ? ", orgID, scheduleDate).
36
+		// Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
37
+		// Preload("AssessmentBeforeDislysis", "status = 1 AND user_org_id = ? AND assessment_date = ? ", orgID, scheduleDate).
38
+		// Preload("DialysisOrder", "status = 1 AND user_org_id = ? AND dialysis_date = ?", orgID, scheduleDate).
39
+		// Preload("DialysisOrder.DeviceNumber", "status = 1 AND org_id = ?", orgID).
40
+		// Preload("TreatmentSummary", "status = 1  AND user_org_id = ? AND assessment_date = ?", orgID, scheduleDate).
41
+		// Preload("AssessmentAfterDislysis", "status = 1  AND user_org_id = ? AND assessment_date = ?", orgID, scheduleDate).
42
+		// Preload("HisAdvices", "status = 1 AND user_org_id = ? AND advice_date = ? ", orgID, scheduleDate).
41 43
 		// Preload("DialysisOrder.MonitoringRecords", func(rdb *gorm.DB) *gorm.DB {
42 44
 		// 	return rdb.Where("status = 1 AND user_org_id = ?", orgID).Order("operate_time DESC")
43 45
 		// }).
@@ -127,6 +129,32 @@ func (MDialysisScheduleVM) TableName() string {
127 129
 	return "xt_schedule"
128 130
 }
129 131
 
132
+type MDialysisScheduleVMForList struct {
133
+	ID                       int64                             `gorm:"column:id" json:"id"`
134
+	UserOrgId                int64                             `gorm:"column:user_org_id" json:"user_org_id"`
135
+	PartitionId              int64                             `gorm:"column:partition_id" json:"partition_id"`
136
+	BedId                    int64                             `gorm:"column:bed_id" json:"bed_id"`
137
+	PatientId                int64                             `gorm:"column:patient_id" json:"patient_id"`
138
+	ScheduleDate             int64                             `gorm:"column:schedule_date" json:"schedule_date"`
139
+	ScheduleType             int64                             `gorm:"column:schedule_type" json:"schedule_type"`
140
+	ScheduleWeek             int64                             `gorm:"column:schedule_week" json:"schedule_week"`
141
+	ModeId                   int64                             `gorm:"column:mode_id" json:"mode_id"`
142
+	Status                   int64                             `gorm:"column:status" json:"status"`
143
+	SchedualPatient          *models.MSchedualPatientList      `gorm:"ForeignKey:PatientId" json:"patient"`
144
+	DeviceNumber             *models.MDeviceNumberForList      `gorm:"ForeignKey:BedId" json:"device_number"`
145
+	DialysisOrder            *models.MDialysisOrderForList     `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"dialysis_order"`
146
+	Prescription             *models.DialysisPrescriptionList  `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"prescription"`
147
+	AssessmentBeforeDislysis *models.PredialysisEvaluationList `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"assessment_before_dislysis"`
148
+	AssessmentAfterDislysis  *models.VMAssessmentAfterDislysis `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"assessment_after_dislysis"`
149
+	HisAdvices               []VMHisDoctorAdviceInfo          `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"his_doctor_advice"`
150
+	Advices                  []models.VMDoctorAdviceForList   `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"doctor_advice"`
151
+	TreatmentSummary         *models.VMTreatmentSummaryForList `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"treatment_summary"`
152
+}
153
+
154
+func (MDialysisScheduleVMForList) TableName() string {
155
+	return "xt_schedule"
156
+}
157
+
130 158
 type MDeviceNumberVM struct {
131 159
 	models.DeviceNumber
132 160
 
@@ -312,6 +340,19 @@ func (VMHisDoctorAdviceInfo) TableName() string {
312 340
 	return "his_doctor_advice_info"
313 341
 }
314 342
 
343
+type VMAssessmentAfterDislysis struct {
344
+	ID             int64   `gorm:"column:id" json:"id"`
345
+	UserOrgId      int64   `gorm:"column:user_org_id" json:"user_org_id"`
346
+	PatientId      int64   `gorm:"column:patient_id" json:"patient_id"`
347
+	AssessmentDate int64   `gorm:"column:assessment_date" json:"assessment_date"`
348
+	WeightAfter    float64 `gorm:"column:weight_after" json:"weight_after"`
349
+	Status         int64   `gorm:"column:status" json:"status"`
350
+}
351
+
352
+func (VMAssessmentAfterDislysis) TableName() string {
353
+	return "xt_assessment_after_dislysis"
354
+}
355
+
315 356
 // 获取透析记录
316 357
 func MobileGetDialysisRecord(orgID int64, patientID int64, recordDate int64) (*models.DialysisOrder, error) {
317 358
 	var record models.DialysisOrder
@@ -342,21 +383,45 @@ func MobileGetPatientDetail(orgID int64, patientID int64) (*MPatient, error) {
342 383
 
343 384
 // 用户排班信息
344 385
 func MobileGetSchedualDetail(orgID int64, patientID int64, schedualDate int64) (*MDialysisScheduleVM, error) {
386
+	redis := RedisClient()
387
+	defer redis.Close()
345 388
 	var vm MDialysisScheduleVM
346
-	err := readDb.
389
+
390
+	// cur_date := time.Now().Format("2006-01-02")
391
+	key := strconv.FormatInt(orgID, 10) + ":"+ strconv.FormatInt(patientID, 10) + ":" + strconv.FormatInt(schedualDate, 10) + ":schedual_detail"
392
+	schedual_detail_str, _ := redis.Get(key).Result()
393
+
394
+	if len(schedual_detail_str) == 0 { //没有到缓存数据,从数据库中获取数据,进行缓存到redis
395
+		err := readDb.
347 396
 		Table("xt_schedule").
348 397
 		// Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
349 398
 		Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
399
+		Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
350 400
 		Where("status = 1 AND user_org_id = ? AND schedule_date = ? AND patient_id = ?", orgID, schedualDate, patientID).
351 401
 		First(&vm).Error
352
-	if err != nil {
353
-		if err == gorm.ErrRecordNotFound {
354
-			return nil, nil
402
+		
403
+		if err != nil {
404
+			if err == gorm.ErrRecordNotFound {
405
+				return nil, nil
406
+			} else {
407
+				return nil, err
408
+			}
355 409
 		} else {
356
-			return nil, err
410
+			if vm.ID > 0 {
411
+				//缓存数据
412
+				schedual_detail_str, err := json.Marshal(vm)
413
+				if err == nil {
414
+					redis.Set(key, schedual_detail_str, time.Second*60*60*18)
415
+				}
416
+			} else {
417
+				redis.Set(key, " ", time.Second*60*60*18)
418
+			}
419
+			return &vm, nil
357 420
 		}
421
+	} else { //缓存数据了数据,将redis缓存的json字符串转为map
422
+		json.Unmarshal([]byte(schedual_detail_str), &vm)
423
+		return &vm, nil
358 424
 	}
359
-	return &vm, err
360 425
 }
361 426
 
362 427
 // 用户排班信息
@@ -457,44 +522,110 @@ func (MPatient) TableName() string {
457 522
 // 接诊评估
458 523
 func MobileGetReceiverTreatmentAccessRecord(orgID int64, patientID int64, recordDate int64) (*models.ReceiveTreatmentAsses, error) {
459 524
 	var record models.ReceiveTreatmentAsses
460
-	err = readDb.Model(&models.ReceiveTreatmentAsses{}).Where("patient_id = ? and user_org_id = ? and status = 1 and record_date = ?", patientID, orgID, recordDate).First(&record).Error
461
-	if err != nil {
462
-		if err == gorm.ErrRecordNotFound {
463
-			return nil, nil
525
+	redis := RedisClient()
526
+	defer redis.Close()
527
+
528
+	// cur_date := time.Now().Format("2006-01-02")
529
+	key := strconv.FormatInt(orgID, 10) + ":"+ strconv.FormatInt(patientID, 10) + ":" + strconv.FormatInt(recordDate, 10) + ":receive_treatment_asses"
530
+	receive_treatment_asses_str, _ := redis.Get(key).Result()
531
+
532
+	if len(receive_treatment_asses_str) == 0 { //没有到缓存数据,从数据库中获取数据,进行缓存到redis
533
+		err = readDb.Model(&models.ReceiveTreatmentAsses{}).Where("patient_id = ? and user_org_id = ? and status = 1 and record_date = ?", patientID, orgID, recordDate).First(&record).Error
534
+		if err != nil {
535
+			if err == gorm.ErrRecordNotFound {
536
+				return nil, nil
537
+			} else {
538
+				return nil, err
539
+			}
464 540
 		} else {
465
-			return nil, err
541
+			if record.ID > 0 {
542
+				//缓存数据
543
+				receive_treatment_asses_str, err := json.Marshal(record)
544
+				if err == nil {
545
+					redis.Set(key, receive_treatment_asses_str, time.Second*60*60*18)
546
+				}
547
+			} else {
548
+				redis.Set(key, " ", time.Second*60*60*18)
549
+			}
550
+			return &record, nil
466 551
 		}
552
+	} else { //缓存数据了数据,将redis缓存的json字符串转为map
553
+		json.Unmarshal([]byte(receive_treatment_asses_str), &record)
554
+		return &record, nil
467 555
 	}
468
-	return &record, nil
469 556
 }
470 557
 
471 558
 // 透前评估
472 559
 func MobileGetPredialysisEvaluation(orgID int64, patientID int64, recordDate int64) (*models.PredialysisEvaluation, error) {
473
-	fmt.Println("recordDate", recordDate)
560
+
474 561
 	var record models.PredialysisEvaluation
475
-	err := readDb.Model(&models.PredialysisEvaluation{}).Where("patient_id = ? and user_org_id = ? and status = 1 and assessment_date = ?", patientID, orgID, recordDate).First(&record).Error
476
-	if err != nil {
477
-		if err == gorm.ErrRecordNotFound {
478
-			return nil, nil
562
+	redis := RedisClient()
563
+	defer redis.Close()
564
+
565
+	// cur_date := time.Now().Format("2006-01-02")
566
+	key := strconv.FormatInt(orgID, 10) + ":"+ strconv.FormatInt(patientID, 10) + ":" + strconv.FormatInt(recordDate, 10) + ":assessment_before_dislysis"
567
+	assessment_before_dislysis_str, _ := redis.Get(key).Result()
568
+
569
+	if len(assessment_before_dislysis_str) == 0 { //没有到缓存数据,从数据库中获取数据,进行缓存到redis
570
+		err := readDb.Model(&models.PredialysisEvaluation{}).Where("patient_id = ? and user_org_id = ? and status = 1 and assessment_date = ?", patientID, orgID, recordDate).First(&record).Error
571
+		if err != nil {
572
+			if err == gorm.ErrRecordNotFound {
573
+				return nil, nil
574
+			} else {
575
+				return nil, err
576
+			}
479 577
 		} else {
480
-			return nil, err
578
+			if record.ID > 0 {
579
+				//缓存数据
580
+				assessment_before_dislysis_str, err := json.Marshal(record)
581
+				if err == nil {
582
+					redis.Set(key, assessment_before_dislysis_str, time.Second*60*60*18)
583
+				}
584
+			} else {
585
+				redis.Set(key, " ", time.Second*60*60*18)
586
+			}
587
+			return &record, nil
481 588
 		}
589
+	} else { //缓存数据了数据,将redis缓存的json字符串转为map
590
+		json.Unmarshal([]byte(assessment_before_dislysis_str), &record)
591
+		return &record, nil
482 592
 	}
483
-	return &record, nil
484 593
 }
485 594
 
486 595
 // 获取 maxDate 之前一次的透前评估记录
487 596
 func MobileGetLastTimePredialysisEvaluation(orgID int64, patientID int64, maxDate int64) (*models.PredialysisEvaluation, error) {
488 597
 	var record models.PredialysisEvaluation
489
-	err := readDb.Model(&models.PredialysisEvaluation{}).Where("patient_id = ? and user_org_id = ? and status = 1 and assessment_date < ?", patientID, orgID, maxDate).Order("assessment_date desc").First(&record).Error
490
-	if err != nil {
491
-		if err == gorm.ErrRecordNotFound {
492
-			return nil, nil
598
+	redis := RedisClient()
599
+	defer redis.Close()
600
+
601
+	// cur_date := time.Now().Format("2006-01-02")
602
+	key := strconv.FormatInt(orgID, 10) + ":"+ strconv.FormatInt(patientID, 10) + ":" + strconv.FormatInt(maxDate, 10) + ":assessment_before_dislysis_last"
603
+	assessment_before_dislysis_last_str, _ := redis.Get(key).Result()
604
+
605
+	if len(assessment_before_dislysis_last_str) == 0 { //没有到缓存数据,从数据库中获取数据,进行缓存到redis
606
+		err := readDb.Model(&models.PredialysisEvaluation{}).Where("patient_id = ? and user_org_id = ? and status = 1 and assessment_date < ?", patientID, orgID, maxDate).Order("assessment_date desc").First(&record).Error
607
+		if err != nil {
608
+			if err == gorm.ErrRecordNotFound {
609
+				return nil, nil
610
+			} else {
611
+				return nil, err
612
+			}
493 613
 		} else {
494
-			return nil, err
614
+			if record.ID > 0 {
615
+				//缓存数据
616
+				assessment_before_dislysis_last_str, err := json.Marshal(record)
617
+				if err == nil {
618
+					redis.Set(key, assessment_before_dislysis_last_str, time.Second*60*60*4)
619
+				}
620
+			} else {
621
+				redis.Set(key, " ", time.Second*60*60*18)
622
+			}
623
+			return &record, nil
495 624
 		}
625
+	} else { //缓存数据了数据,将redis缓存的json字符串转为map
626
+		json.Unmarshal([]byte(assessment_before_dislysis_last_str), &record)
627
+		return &record, nil
496 628
 	}
497
-	return &record, nil
498 629
 }
499 630
 
500 631
 // 临时医嘱
@@ -517,57 +648,150 @@ func MobileGetDoctorAdvices(orgID int64, patientID int64, recordDate int64) ([]*
517 648
 
518 649
 func MobileGetDoctorAdvicesByGroups(orgID int64, patientID int64, recordDate int64) ([]*models.DoctorAdvice, error) {
519 650
 	var records []*models.DoctorAdvice
520
-	// err := readDb.Model(&models.DoctorAdvice{}).Where("patient_id = ? and user_org_id = ? and status = 1 and record_date = ?", patientID, orgID, recordDate).Find(&records).Error
651
+	redis := RedisClient()
652
+	defer redis.Close()
521 653
 
522
-	err := readDb.
654
+	// cur_date := time.Now().Format("2006-01-02")
655
+	key := strconv.FormatInt(orgID, 10) + ":"+ strconv.FormatInt(patientID, 10) + ":" + strconv.FormatInt(recordDate, 10) + ":doctor_advices"
656
+	doctor_advices_str, _ := redis.Get(key).Result()
657
+
658
+	if len(doctor_advices_str) == 0 { //没有到缓存数据,从数据库中获取数据,进行缓存到redis
659
+		err := readDb.
523 660
 		Model(&models.DoctorAdvice{}).
524 661
 		Where("patient_id = ? and user_org_id = ? and status = 1 and record_date = ? and (advice_type = 2 || advice_type = 3)", patientID, orgID, recordDate).
525 662
 		Select("id, user_org_id, patient_id, advice_type, advice_date, record_date, start_time, advice_name,advice_desc, reminder_date, drug_spec, drug_spec_unit, single_dose, single_dose_unit, prescribing_number, prescribing_number_unit, delivery_way, execution_frequency, advice_doctor, status, created_time,updated_time, advice_affirm, remark, stop_time, stop_reason, stop_doctor, stop_state, parent_id, execution_time, execution_staff, execution_state, checker, check_state, check_time, groupno,way,drug_id,drug_name_id, IF(parent_id > 0, parent_id, id) as advice_order").
526 663
 		Order("start_time asc, groupno desc, advice_order desc, id asc").
527 664
 		Scan(&records).Error
528
-
529
-	if err != nil {
530
-		return nil, err
665
+		if err != nil {
666
+			if err == gorm.ErrRecordNotFound {
667
+				return nil, nil
668
+			} else {
669
+				return nil, err
670
+			}
671
+		} else {
672
+			if len(records) > 0 {
673
+				//缓存数据
674
+				doctor_advices_str, err := json.Marshal(records)
675
+				if err == nil {
676
+					redis.Set(key, doctor_advices_str, time.Second*60*60*18)
677
+				}
678
+			} else {
679
+				redis.Set(key, " ", time.Second*60*60*18)
680
+			}
681
+			return records, nil
682
+		}
683
+	} else { //缓存数据了数据,将redis缓存的json字符串转为map
684
+		json.Unmarshal([]byte(doctor_advices_str), &records)
685
+		return records, nil
531 686
 	}
532
-	return records, nil
533 687
 }
534 688
 
535 689
 // 透析记录
536 690
 func MobileGetSchedualDialysisRecord(orgID int64, patientID int64, recordDate int64) (*models.DialysisOrder, error) {
537 691
 	var record models.DialysisOrder
538
-	err := readDb.Model(&models.DialysisOrder{}).Preload("DeviceNumber", "org_id = ? AND  status = 1", orgID).Where("user_org_id = ? AND patient_id = ? AND  dialysis_date = ?", orgID, patientID, recordDate).First(&record).Error
539
-	if err != nil {
540
-		if err == gorm.ErrRecordNotFound {
541
-			return nil, nil
692
+	redis := RedisClient()
693
+	defer redis.Close()
694
+
695
+	// cur_date := time.Now().Format("2006-01-02")
696
+	key := strconv.FormatInt(orgID, 10) + ":"+ strconv.FormatInt(patientID, 10) + ":" + strconv.FormatInt(recordDate, 10) + ":dialysis_order"
697
+	dialysis_order_str, _ := redis.Get(key).Result()
698
+
699
+	if len(dialysis_order_str) == 0 { //没有到缓存数据,从数据库中获取数据,进行缓存到redis
700
+		err := readDb.Model(&models.DialysisOrder{}).Preload("DeviceNumber", "org_id = ? AND  status = 1", orgID).Where("user_org_id = ? AND patient_id = ? AND  dialysis_date = ?", orgID, patientID, recordDate).First(&record).Error
701
+		if err != nil {
702
+			if err == gorm.ErrRecordNotFound {
703
+				return nil, nil
704
+			} else {
705
+				return nil, err
706
+			}
542 707
 		} else {
543
-			return nil, err
708
+			if record.ID > 0 {
709
+				//缓存数据
710
+				dialysis_order_str, err := json.Marshal(record)
711
+				if err == nil {
712
+					redis.Set(key, dialysis_order_str, time.Second*60*60*18)
713
+				}
714
+			} else {
715
+				redis.Set(key, " ", time.Second*60*60*18)
716
+			}
717
+			return &record, nil
544 718
 		}
719
+	} else { //缓存数据了数据,将redis缓存的json字符串转为map
720
+		json.Unmarshal([]byte(dialysis_order_str), &record)
721
+		return &record, nil
545 722
 	}
546
-	return &record, nil
547 723
 }
548 724
 
549 725
 // 双人核对
550 726
 func MobileGetDoubleCheck(orgID int64, patientID int64, recordDate int64) (*models.DoubleCheck, error) {
551 727
 	var record models.DoubleCheck
552
-	err := readDb.Model(&models.DoubleCheck{}).Where("patient_id = ? and user_org_id = ? and status = 1 and check_date = ?", patientID, orgID, recordDate).First(&record).Error
553
-	if err != nil {
554
-		if err == gorm.ErrRecordNotFound {
555
-			return nil, nil
728
+	redis := RedisClient()
729
+	defer redis.Close()
730
+
731
+	// cur_date := time.Now().Format("2006-01-02")
732
+	key := strconv.FormatInt(orgID, 10) + ":"+ strconv.FormatInt(patientID, 10) + ":" + strconv.FormatInt(recordDate, 10) + ":double_check"
733
+	double_check_str, _ := redis.Get(key).Result()
734
+
735
+	if len(double_check_str) == 0 { //没有到缓存数据,从数据库中获取数据,进行缓存到redis
736
+		err := readDb.Model(&models.DoubleCheck{}).Where("patient_id = ? and user_org_id = ? and status = 1 and check_date = ?", patientID, orgID, recordDate).First(&record).Error
737
+		if err != nil {
738
+			if err == gorm.ErrRecordNotFound {
739
+				return nil, nil
740
+			} else {
741
+				return nil, err
742
+			}
556 743
 		} else {
557
-			return nil, err
744
+			if record.ID > 0 {
745
+				//缓存数据
746
+				double_check_str, err := json.Marshal(record)
747
+				if err == nil {
748
+					redis.Set(key, double_check_str, time.Second*60*60*18)
749
+				}
750
+			} else {
751
+				redis.Set(key, " ", time.Second*60*60*18)
752
+			}
753
+			return &record, nil
558 754
 		}
755
+	} else { //缓存数据了数据,将redis缓存的json字符串转为map
756
+		json.Unmarshal([]byte(double_check_str), &record)
757
+		return &record, nil
559 758
 	}
560
-	return &record, nil
561 759
 }
562 760
 
563 761
 // 透析监测记录
564 762
 func MobileGetMonitorRecords(orgID int64, patientID int64, recordDate int64) ([]*models.MonitoringRecord, error) {
565 763
 	var records []*models.MonitoringRecord
566
-	err := readDb.Model(&models.MonitoringRecord{}).Where("patient_id = ? and user_org_id = ? and status = 1 and monitoring_date = ?", patientID, orgID, recordDate).Order("operate_time asc").Find(&records).Error
567
-	if err != nil {
568
-		return nil, err
764
+	redis := RedisClient()
765
+	defer redis.Close()
766
+
767
+	// cur_date := time.Now().Format("2006-01-02")
768
+	key := strconv.FormatInt(orgID, 10) + ":"+ strconv.FormatInt(patientID, 10) + ":" + strconv.FormatInt(recordDate, 10) + ":monitor_records"
769
+	monitor_records_str, _ := redis.Get(key).Result()
770
+
771
+	if len(monitor_records_str) == 0 { //没有到缓存数据,从数据库中获取数据,进行缓存到redis
772
+		err := readDb.Model(&models.MonitoringRecord{}).Where("patient_id = ? and user_org_id = ? and status = 1 and monitoring_date = ?", patientID, orgID, recordDate).Order("operate_time asc").Find(&records).Error
773
+		if err != nil {
774
+			if err == gorm.ErrRecordNotFound {
775
+				return nil, nil
776
+			} else {
777
+				return nil, err
778
+			}
779
+		} else {
780
+			if len(records) > 0 {
781
+				//缓存数据
782
+				monitor_records_str, err := json.Marshal(records)
783
+				if err == nil {
784
+					redis.Set(key, monitor_records_str, time.Second*60*60*18)
785
+				}
786
+			} else {
787
+				redis.Set(key, " ", time.Second*60*60*18)
788
+			}
789
+			return records, nil
790
+		}
791
+	} else { //缓存数据了数据,将redis缓存的json字符串转为map
792
+		json.Unmarshal([]byte(monitor_records_str), &records)
793
+		return records, nil
569 794
 	}
570
-	return records, nil
571 795
 }
572 796
 
573 797
 func MobileGetMonitorRecordFirst(orgID int64, patientID int64, recordDate int64) (*models.MonitoringRecord, error) {
@@ -581,43 +805,109 @@ func MobileGetMonitorRecordFirst(orgID int64, patientID int64, recordDate int64)
581 805
 
582 806
 func MobileGetLastMonitorRecord(orgID int64, patientID int64, beforeDate int64) (*models.MonitoringRecord, error) {
583 807
 	var record models.MonitoringRecord
584
-	err := readDb.Model(&models.MonitoringRecord{}).Where("patient_id = ? and user_org_id = ? and status = 1 and monitoring_date = ?", patientID, orgID, beforeDate).Order("operate_time desc").First(&record).Error
585
-	if err != nil {
586
-		if err == gorm.ErrRecordNotFound {
587
-			return nil, nil
808
+	redis := RedisClient()
809
+	defer redis.Close()
810
+
811
+	// cur_date := time.Now().Format("2006-01-02")
812
+	key := strconv.FormatInt(orgID, 10) + ":"+ strconv.FormatInt(patientID, 10) + ":" + strconv.FormatInt(beforeDate, 10) + ":monitor_record_last"
813
+	monitor_record_last_str, _ := redis.Get(key).Result()
814
+
815
+	if len(monitor_record_last_str) == 0 { //没有到缓存数据,从数据库中获取数据,进行缓存到redis
816
+		err := readDb.Model(&models.MonitoringRecord{}).Where("patient_id = ? and user_org_id = ? and status = 1 and monitoring_date = ?", patientID, orgID, beforeDate).Order("operate_time desc").First(&record).Error
817
+		if err != nil {
818
+			if err == gorm.ErrRecordNotFound {
819
+				return nil, nil
820
+			} else {
821
+				return nil, err
822
+			}
588 823
 		} else {
589
-			return nil, err
824
+			if record.ID > 0 {
825
+				//缓存数据
826
+				monitor_record_last_str, err := json.Marshal(record)
827
+				if err == nil {
828
+					redis.Set(key, monitor_record_last_str, time.Second*60*60*18)
829
+				}
830
+			} else {
831
+				redis.Set(key, " ", time.Second*60*60*18)
832
+			}
833
+			return &record, nil
590 834
 		}
835
+	} else { //缓存数据了数据,将redis缓存的json字符串转为map
836
+		json.Unmarshal([]byte(monitor_record_last_str), &record)
837
+		return &record, nil
591 838
 	}
592
-	return &record, nil
593 839
 }
594 840
 
595 841
 // 透后评估
596 842
 func MobileGetAssessmentAfterDislysis(orgID int64, patientID int64, recordDate int64) (*models.AssessmentAfterDislysis, error) {
597 843
 	var record models.AssessmentAfterDislysis
598
-	err := readDb.Model(&models.AssessmentAfterDislysis{}).Where("patient_id = ? and user_org_id = ? and status = 1 and assessment_date = ?", patientID, orgID, recordDate).First(&record).Error
599
-	if err != nil {
600
-		if err == gorm.ErrRecordNotFound {
601
-			return nil, nil
844
+	redis := RedisClient()
845
+	defer redis.Close()
846
+
847
+	// cur_date := time.Now().Format("2006-01-02")
848
+	key := strconv.FormatInt(orgID, 10) + ":"+ strconv.FormatInt(patientID, 10) + ":" + strconv.FormatInt(recordDate, 10) + ":assessment_after_dislysis"
849
+	assessment_after_dislysis_str, _ := redis.Get(key).Result()
850
+
851
+	if len(assessment_after_dislysis_str) == 0 { //没有到缓存数据,从数据库中获取数据,进行缓存到redis
852
+		err := readDb.Model(&models.AssessmentAfterDislysis{}).Where("patient_id = ? and user_org_id = ? and status = 1 and assessment_date = ?", patientID, orgID, recordDate).First(&record).Error
853
+		if err != nil {
854
+			if err == gorm.ErrRecordNotFound {
855
+				return nil, nil
856
+			} else {
857
+				return nil, err
858
+			}
602 859
 		} else {
603
-			return nil, err
860
+			if record.ID > 0 {
861
+				//缓存数据
862
+				assessment_after_dislysis_str, err := json.Marshal(record)
863
+				if err == nil {
864
+					redis.Set(key, assessment_after_dislysis_str, time.Second*60*60*18)
865
+				}
866
+			} else {
867
+				redis.Set(key, " ", time.Second*60*60*18)
868
+			}
869
+			return &record, nil
604 870
 		}
871
+	} else { //缓存数据了数据,将redis缓存的json字符串转为map
872
+		json.Unmarshal([]byte(assessment_after_dislysis_str), &record)
873
+		return &record, nil
605 874
 	}
606
-	return &record, nil
607 875
 }
608 876
 
609 877
 // 获取 maxDate 之前一次的透后评估记录
610 878
 func MobileGetLastTimeAssessmentAfterDislysis(orgID int64, patientID int64, maxDate int64) (*models.AssessmentAfterDislysis, error) {
611 879
 	var record models.AssessmentAfterDislysis
612
-	err := readDb.Model(&models.AssessmentAfterDislysis{}).Where("patient_id = ? and user_org_id = ? and status = 1 and assessment_date < ?", patientID, orgID, maxDate).Order("assessment_date desc").First(&record).Error
613
-	if err != nil {
614
-		if err == gorm.ErrRecordNotFound {
615
-			return nil, nil
880
+	redis := RedisClient()
881
+	defer redis.Close()
882
+
883
+	// cur_date := time.Now().Format("2006-01-02")
884
+	key := strconv.FormatInt(orgID, 10) + ":"+ strconv.FormatInt(patientID, 10) + ":" + strconv.FormatInt(maxDate, 10) + ":assessment_after_dislysis_last"
885
+	assessment_after_dislysis_last_str, _ := redis.Get(key).Result()
886
+
887
+	if len(assessment_after_dislysis_last_str) == 0 { //没有到缓存数据,从数据库中获取数据,进行缓存到redis
888
+		err := readDb.Model(&models.AssessmentAfterDislysis{}).Where("patient_id = ? and user_org_id = ? and status = 1 and assessment_date < ?", patientID, orgID, maxDate).Order("assessment_date desc").First(&record).Error
889
+		if err != nil {
890
+			if err == gorm.ErrRecordNotFound {
891
+				return nil, nil
892
+			} else {
893
+				return nil, err
894
+			}
616 895
 		} else {
617
-			return nil, err
896
+			if record.ID > 0 {
897
+				//缓存数据
898
+				assessment_after_dislysis_last_str, err := json.Marshal(record)
899
+				if err == nil {
900
+					redis.Set(key, assessment_after_dislysis_last_str, time.Second*60*60*18)
901
+				}
902
+			} else {
903
+				redis.Set(key, " ", time.Second*60*60*18)
904
+			}
905
+			return &record, nil
618 906
 		}
907
+	} else { //缓存数据了数据,将redis缓存的json字符串转为map
908
+		json.Unmarshal([]byte(assessment_after_dislysis_last_str), &record)
909
+		return &record, nil
619 910
 	}
620
-	return &record, nil
621 911
 }
622 912
 func MobileGetLast(orgID int64, patientID int64, maxDate int64) (models.AssessmentAfterDislysis, error) {
623 913
 	dislysis := models.AssessmentAfterDislysis{}
@@ -628,15 +918,37 @@ func MobileGetLast(orgID int64, patientID int64, maxDate int64) (models.Assessme
628 918
 // 治疗小结
629 919
 func MobileGetTreatmentSummary(orgID int64, patientID int64, recordDate int64) (*models.TreatmentSummary, error) {
630 920
 	var record models.TreatmentSummary
631
-	err := readDb.Model(&models.TreatmentSummary{}).Where("patient_id = ? and user_org_id = ? and status = 1 and assessment_date = ?", patientID, orgID, recordDate).First(&record).Error
632
-	if err != nil {
633
-		if err == gorm.ErrRecordNotFound {
634
-			return nil, nil
921
+	redis := RedisClient()
922
+	defer redis.Close()
923
+
924
+	// cur_date := time.Now().Format("2006-01-02")
925
+	key := strconv.FormatInt(orgID, 10) + ":"+ strconv.FormatInt(patientID, 10) + ":" + strconv.FormatInt(recordDate, 10) + ":treatment_summary"
926
+	treatment_summary_str, _ := redis.Get(key).Result()
927
+
928
+	if len(treatment_summary_str) == 0 { //没有到缓存数据,从数据库中获取数据,进行缓存到redis
929
+		err := readDb.Model(&models.TreatmentSummary{}).Where("patient_id = ? and user_org_id = ? and status = 1 and assessment_date = ?", patientID, orgID, recordDate).First(&record).Error
930
+		if err != nil {
931
+			if err == gorm.ErrRecordNotFound {
932
+				return nil, nil
933
+			} else {
934
+				return nil, err
935
+			}
635 936
 		} else {
636
-			return nil, err
937
+			if record.ID > 0 {
938
+				//缓存数据
939
+				treatment_summary_str, err := json.Marshal(record)
940
+				if err == nil {
941
+					redis.Set(key, treatment_summary_str, time.Second*60*60*18)
942
+				}
943
+			} else {
944
+				redis.Set(key, " ", time.Second*60*60*18)
945
+			}
946
+			return &record, nil
637 947
 		}
948
+	} else { //缓存数据了数据,将redis缓存的json字符串转为map
949
+		json.Unmarshal([]byte(treatment_summary_str), &record)
950
+		return &record, nil
638 951
 	}
639
-	return &record, nil
640 952
 }
641 953
 
642 954
 // 透析处方
@@ -1450,56 +1762,144 @@ func ModifyFinishDialysisOrder(order *models.DialysisOrder) error {
1450 1762
 
1451 1763
 func MobileGetLastDryWeight(orgID int64, patientID int64) (*models.SgjPatientDryweight, error) {
1452 1764
 	var record models.SgjPatientDryweight
1453
-	err := readDb.Model(&models.SgjPatientDryweight{}).Where("patient_id = ? and user_org_id = ? and status = 1", patientID, orgID).Last(&record).Error
1454
-	if err != nil {
1455
-		if err == gorm.ErrRecordNotFound {
1456
-			return nil, nil
1765
+	redis := RedisClient()
1766
+	defer redis.Close()
1767
+
1768
+	// cur_date := time.Now().Format("2006-01-02")
1769
+	key := strconv.FormatInt(orgID, 10) + ":"+ strconv.FormatInt(patientID, 10) + ":last_dry_weight"
1770
+	last_dry_weight_str, _ := redis.Get(key).Result()
1771
+
1772
+	if len(last_dry_weight_str) == 0 { //没有到缓存数据,从数据库中获取数据,进行缓存到redis
1773
+		err := readDb.Model(&models.SgjPatientDryweight{}).Where("patient_id = ? and user_org_id = ? and status = 1", patientID, orgID).Last(&record).Error
1774
+		if err != nil {
1775
+			if err == gorm.ErrRecordNotFound {
1776
+				return nil, nil
1777
+			} else {
1778
+				return nil, err
1779
+			}
1457 1780
 		} else {
1458
-			return nil, err
1781
+			if record.ID > 0 {
1782
+				//缓存数据
1783
+				last_dry_weight_str, err := json.Marshal(record)
1784
+				if err == nil {
1785
+					redis.Set(key, last_dry_weight_str, time.Second*60*60*18)
1786
+				}
1787
+			} else {
1788
+				redis.Set(key, " ", time.Second*60*60*18)
1789
+			}
1790
+			return &record, nil
1459 1791
 		}
1792
+	} else { //缓存数据了数据,将redis缓存的json字符串转为map
1793
+		json.Unmarshal([]byte(last_dry_weight_str), &record)
1794
+		return &record, nil
1460 1795
 	}
1461
-	return &record, nil
1462 1796
 }
1463 1797
 
1464 1798
 // 透析方案
1465 1799
 func MobileGetDialysisSolutionByModeId(orgID int64, patientID int64, mode_id int64) (*models.DialysisSolution, error) {
1466 1800
 	var record models.DialysisSolution
1467
-	err := readDb.Model(&models.DialysisSolution{}).Where("patient_id = ? and user_org_id = ? and status = 1 AND mode_id = ?", patientID, orgID, mode_id).Last(&record).Error
1468
-	if err != nil {
1469
-		if err == gorm.ErrRecordNotFound {
1470
-			return nil, nil
1801
+	redis := RedisClient()
1802
+	defer redis.Close()
1803
+
1804
+	// cur_date := time.Now().Format("2006-01-02")
1805
+	key := strconv.FormatInt(orgID, 10) + ":"+ strconv.FormatInt(patientID, 10) +  ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_solution"
1806
+	dialysis_solution_str, _ := redis.Get(key).Result()
1807
+
1808
+	if len(dialysis_solution_str) == 0 { //没有到缓存数据,从数据库中获取数据,进行缓存到redis
1809
+		err := readDb.Model(&models.DialysisSolution{}).Where("patient_id = ? and user_org_id = ? and status = 1 AND mode_id = ?", patientID, orgID, mode_id).Last(&record).Error
1810
+		if err != nil {
1811
+			if err == gorm.ErrRecordNotFound {
1812
+				return nil, nil
1813
+			} else {
1814
+				return nil, err
1815
+			}
1471 1816
 		} else {
1472
-			return nil, err
1817
+			if record.ID > 0 {
1818
+				//缓存数据
1819
+				dialysis_solution_str, err := json.Marshal(record)
1820
+				if err == nil {
1821
+					redis.Set(key, dialysis_solution_str, time.Second*60*60*18)
1822
+				}
1823
+			} else {
1824
+				redis.Set(key, " ", time.Second*60*60*18)
1825
+			}
1826
+			return &record, nil
1473 1827
 		}
1828
+	} else { //缓存数据了数据,将redis缓存的json字符串转为map
1829
+		json.Unmarshal([]byte(dialysis_solution_str), &record)
1830
+		return &record, nil
1474 1831
 	}
1475
-	return &record, nil
1476 1832
 }
1477 1833
 
1478 1834
 // 透析处方
1479 1835
 func MobileGetDialysisPrescribeByModeId(orgID int64, patientID int64, recordDate int64, mode_id int64) (*models.DialysisPrescription, error) {
1480 1836
 	var record models.DialysisPrescription
1481
-	err := readDb.Model(&models.DialysisPrescription{}).Where("patient_id = ? and user_org_id = ? and status = 1 and record_date = ? AND mode_id = ?", patientID, orgID, recordDate, mode_id).First(&record).Error
1482
-	if err != nil {
1483
-		if err == gorm.ErrRecordNotFound {
1484
-			return nil, nil
1837
+	redis := RedisClient()
1838
+	defer redis.Close()
1839
+
1840
+	// cur_date := time.Now().Format("2006-01-02")
1841
+	key := strconv.FormatInt(orgID, 10) + ":"+ strconv.FormatInt(patientID, 10) + ":" + strconv.FormatInt(recordDate, 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_prescribe"
1842
+	dialysis_prescribe_str, _ := redis.Get(key).Result()
1843
+
1844
+	if len(dialysis_prescribe_str) == 0 { //没有到缓存数据,从数据库中获取数据,进行缓存到redis
1845
+		err := readDb.Model(&models.DialysisPrescription{}).Where("patient_id = ? and user_org_id = ? and status = 1 and record_date = ? AND mode_id = ?", patientID, orgID, recordDate, mode_id).First(&record).Error
1846
+		if err != nil {
1847
+			if err == gorm.ErrRecordNotFound {
1848
+				return nil, nil
1849
+			} else {
1850
+				return nil, err
1851
+			}
1485 1852
 		} else {
1486
-			return nil, err
1853
+			if record.ID > 0 {
1854
+				//缓存数据
1855
+				dialysis_prescribe_str, err := json.Marshal(record)
1856
+				if err == nil {
1857
+					redis.Set(key, dialysis_prescribe_str, time.Second*60*60*18)
1858
+				}
1859
+			} else {
1860
+				redis.Set(key, " ", time.Second*60*60*18)
1861
+			}
1862
+			return &record, nil
1487 1863
 		}
1864
+	} else { //缓存数据了数据,将redis缓存的json字符串转为map
1865
+		json.Unmarshal([]byte(dialysis_prescribe_str), &record)
1866
+		return &record, nil
1488 1867
 	}
1489
-	return &record, nil
1490 1868
 }
1491 1869
 
1492 1870
 func MobileGetDialysisPrescribeByModeIdOne(orgID int64, patientID int64, recordDate int64) (*models.DialysisPrescription, error) {
1493 1871
 	var record models.DialysisPrescription
1494
-	err := readDb.Model(&models.DialysisPrescription{}).Where("patient_id = ? and user_org_id = ? and status = 1 and record_date = ?", patientID, orgID, recordDate).First(&record).Error
1495
-	if err != nil {
1496
-		if err == gorm.ErrRecordNotFound {
1497
-			return nil, nil
1872
+	redis := RedisClient()
1873
+	defer redis.Close()
1874
+
1875
+	// cur_date := time.Now().Format("2006-01-02")
1876
+	key := strconv.FormatInt(orgID, 10) + ":"+ strconv.FormatInt(patientID, 10) + ":" + strconv.FormatInt(recordDate, 10) + ":dialysis_prescribe_by_mode"
1877
+	dialysis_prescribe_by_mode_str, _ := redis.Get(key).Result()
1878
+
1879
+	if len(dialysis_prescribe_by_mode_str) == 0 { //没有到缓存数据,从数据库中获取数据,进行缓存到redis
1880
+		err := readDb.Model(&models.DialysisPrescription{}).Where("patient_id = ? and user_org_id = ? and status = 1 and record_date = ?", patientID, orgID, recordDate).First(&record).Error
1881
+		if err != nil {
1882
+			if err == gorm.ErrRecordNotFound {
1883
+				return nil, nil
1884
+			} else {
1885
+				return nil, err
1886
+			}
1498 1887
 		} else {
1499
-			return nil, err
1888
+			if record.ID > 0 {
1889
+				//缓存数据
1890
+				dialysis_prescribe_by_mode_str, err := json.Marshal(record)
1891
+				if err == nil {
1892
+					redis.Set(key, dialysis_prescribe_by_mode_str, time.Second*60*60*18)
1893
+				}
1894
+			} else {
1895
+				redis.Set(key, " ", time.Second*60*60*18)
1896
+			}
1897
+			return &record, nil
1500 1898
 		}
1899
+	} else { //缓存数据了数据,将redis缓存的json字符串转为map
1900
+		json.Unmarshal([]byte(dialysis_prescribe_by_mode_str), &record)
1901
+		return &record, nil
1501 1902
 	}
1502
-	return &record, nil
1503 1903
 }
1504 1904
 
1505 1905
 func MobileGetLastDialysisPrescribe(orgID int64, patientID int64) (*models.DialysisPrescription, error) {
@@ -1515,17 +1915,39 @@ func MobileGetLastDialysisPrescribe(orgID int64, patientID int64) (*models.Dialy
1515 1915
 	return &record, nil
1516 1916
 }
1517 1917
 
1518
-func MobileGetLastDialysisPrescribeByModeId(orgID int64, patientID int64, mode_id int64) (*models.DialysisPrescription, error) {
1918
+func MobileGetLastDialysisPrescribeByModeId(orgID int64, patientID int64, recordDate int64,mode_id int64) (*models.DialysisPrescription, error) {
1519 1919
 	var record models.DialysisPrescription
1520
-	err := readDb.Model(&models.DialysisPrescription{}).Where("patient_id = ? and user_org_id = ? and status = 1  AND mode_id = ?", patientID, orgID, mode_id).Last(&record).Error
1521
-	if err != nil {
1522
-		if err == gorm.ErrRecordNotFound {
1523
-			return nil, nil
1920
+	redis := RedisClient()
1921
+	defer redis.Close()
1922
+
1923
+	// cur_date := time.Now().Format("2006-01-02")
1924
+	key := strconv.FormatInt(orgID, 10) + ":"+ strconv.FormatInt(patientID, 10) +  ":" + strconv.FormatInt(recordDate, 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_prescribe_last"
1925
+	dialysis_prescribe_last_str, _ := redis.Get(key).Result()
1926
+
1927
+	if len(dialysis_prescribe_last_str) == 0 { //没有到缓存数据,从数据库中获取数据,进行缓存到redis
1928
+		err := readDb.Model(&models.DialysisPrescription{}).Where("patient_id = ? and user_org_id = ? and status = 1  AND mode_id = ?  AND record_date < ?", patientID, orgID, mode_id,recordDate).Last(&record).Error
1929
+		if err != nil {
1930
+			if err == gorm.ErrRecordNotFound {
1931
+				return nil, nil
1932
+			} else {
1933
+				return nil, err
1934
+			}
1524 1935
 		} else {
1525
-			return nil, err
1936
+			if record.ID > 0 {
1937
+				//缓存数据
1938
+				dialysis_prescribe_last_str, err := json.Marshal(record)
1939
+				if err == nil {
1940
+					redis.Set(key, dialysis_prescribe_last_str, time.Second*60*60*18)
1941
+				}
1942
+			} else {
1943
+				redis.Set(key, " ", time.Second*60*60*18)
1944
+			}
1945
+			return &record, nil
1526 1946
 		}
1947
+	} else { //缓存数据了数据,将redis缓存的json字符串转为map
1948
+		json.Unmarshal([]byte(dialysis_prescribe_last_str), &record)
1949
+		return &record, nil
1527 1950
 	}
1528
-	return &record, nil
1529 1951
 }
1530 1952
 
1531 1953
 func GetAllAvaildDeviceNumbers(orgID int64, record_date int64, schedule_type int) ([]*DeviceNumberViewModel, error) {
@@ -1666,15 +2088,37 @@ func GetLastDryWeight(orgID int64, patientID int64) (*models.SgjPatientDryweight
1666 2088
 
1667 2089
 func MobileGetSystemDialysisPrescribeByModeId(orgID int64, mode_id int64) (*models.SystemPrescription, error) {
1668 2090
 	var record models.SystemPrescription
1669
-	err := readDb.Model(&models.SystemPrescription{}).Where("user_org_id = ? and status = 1  AND mode_id = ?", orgID, mode_id).First(&record).Error
1670
-	if err != nil {
1671
-		if err == gorm.ErrRecordNotFound {
1672
-			return nil, nil
2091
+	redis := RedisClient()
2092
+	defer redis.Close()
2093
+
2094
+	// cur_date := time.Now().Format("2006-01-02")
2095
+	key := strconv.FormatInt(orgID, 10) + ":" + strconv.FormatInt(mode_id, 10) + ":system_dialysis_prescribe"
2096
+	system_dialysis_prescribe_str, _ := redis.Get(key).Result()
2097
+
2098
+	if len(system_dialysis_prescribe_str) == 0 { //没有到缓存数据,从数据库中获取数据,进行缓存到redis
2099
+		err := readDb.Model(&models.SystemPrescription{}).Where("user_org_id = ? and status = 1  AND mode_id = ?", orgID, mode_id).First(&record).Error
2100
+		if err != nil {
2101
+			if err == gorm.ErrRecordNotFound {
2102
+				return nil, nil
2103
+			} else {
2104
+				return nil, err
2105
+			}
1673 2106
 		} else {
1674
-			return nil, err
2107
+			if record.ID > 0 {
2108
+				//缓存数据
2109
+				system_dialysis_prescribe_str, err := json.Marshal(record)
2110
+				if err == nil {
2111
+					redis.Set(key, system_dialysis_prescribe_str, time.Second*60*60*18)
2112
+				}
2113
+			} else {
2114
+				redis.Set(key, " ", time.Second*60*60*18)
2115
+			}
2116
+			return &record, nil
1675 2117
 		}
2118
+	} else { //缓存数据了数据,将redis缓存的json字符串转为map
2119
+		json.Unmarshal([]byte(system_dialysis_prescribe_str), &record)
2120
+		return &record, nil
1676 2121
 	}
1677
-	return &record, nil
1678 2122
 }
1679 2123
 
1680 2124
 func GetSystemDialysisPrescribeByModeId(orgID int64, mode_id int64) (*models.SystemPrescription, error) {
@@ -2007,9 +2451,35 @@ func GetAssessmentBefor(orgid int64, patientid int64, recorddate int64) (*models
2007 2451
 }
2008 2452
 
2009 2453
 func GetAllHisDoctorAdvice(orgid int64, patientid int64, recorddate int64) (his []*models.HisDoctorAdviceInfo, err error) {
2010
-	err = readDb.Model(&models.DialysisBeforePrepare{}).Where("patient_id = ? AND user_org_id = ? AND status=1 AND record_date = ?", patientid, orgid, recorddate).Find(&his).Error
2011
-	return
2012
-
2454
+	redis := RedisClient()
2455
+	defer redis.Close()
2456
+	key := strconv.FormatInt(orgid, 10) + ":"+ strconv.FormatInt(patientid, 10) + ":"+ strconv.FormatInt(recorddate, 10) + ":his_doctor_advice" 
2457
+	his_doctor_advice_str, _ := redis.Get(key).Result()
2458
+
2459
+	if len(his_doctor_advice_str) == 0 { //没有到缓存数据,从数据库中获取数据,进行缓存到redis
2460
+		err = readDb.Model(&models.DialysisBeforePrepare{}).Where("patient_id = ? AND user_org_id = ? AND status=1 AND record_date = ?", patientid, orgid, recorddate).Find(&his).Error
2461
+		if err != nil {
2462
+			if err == gorm.ErrRecordNotFound {
2463
+				return his, nil
2464
+			} else {
2465
+				return his, err
2466
+			}
2467
+		} else {
2468
+			if len(his) > 0 {
2469
+				//缓存数据
2470
+				his_doctor_advice_str, err := json.Marshal(his)
2471
+				if err == nil {
2472
+					redis.Set(key, his_doctor_advice_str, time.Second*60*60*18)
2473
+				}
2474
+			} else {
2475
+				redis.Set(key, " ", time.Second*60*60*18)
2476
+			}
2477
+			return his, nil
2478
+		}
2479
+	} else { //缓存数据了数据,将redis缓存的json字符串转为map
2480
+		json.Unmarshal([]byte(his_doctor_advice_str), &his)
2481
+		return his, nil
2482
+	}
2013 2483
 }
2014 2484
 
2015 2485
 func GetLastDialysisPrescriptionByPatientId(orgid int64, patientid int64, recorddate int64) (*models.DialysisPrescription, error) {

+ 299 - 3
service/patient_service.go Прегледај датотеку

@@ -5,7 +5,7 @@ import (
5 5
 	"strconv"
6 6
 	"strings"
7 7
 	"time"
8
-
8
+	"encoding/json"
9 9
 	"fmt"
10 10
 
11 11
 	"github.com/jinzhu/gorm"
@@ -80,6 +80,277 @@ func GetAllPatientList(orgID int64) (patients []*models.Patients, total int64, e
80 80
 	return
81 81
 }
82 82
 
83
+//GetAllPatientList 返回全部患者的列表
84
+func GetAllPatientListByList(orgID int64) (patients []*models.MSchedualPatientList, err error) {
85
+	redis := RedisClient()
86
+	defer redis.Close()
87
+	key := strconv.FormatInt(orgID, 10) + ":"+ ":patient_list_all" 
88
+	patient_info_str, _ := redis.Get(key).Result()
89
+
90
+	if len(patient_info_str) == 0 { //没有到缓存数据,从数据库中获取数据,进行缓存到redis
91
+		err = readDb.Model(&models.MSchedualPatientList{}).Where("user_org_id=? and status=1 and lapseto = 1", orgID).Find(&patients).Error
92
+		if err != nil {
93
+			if err == gorm.ErrRecordNotFound {
94
+				return nil, nil
95
+			} else {
96
+				return nil, err
97
+			}
98
+		} else {
99
+			if len(patients) > 0 {
100
+				//缓存数据
101
+				patient_info_json, err := json.Marshal(&patients)
102
+				if err == nil {
103
+					redis.Set(key, patient_info_json, time.Second*60*60*18)
104
+				}
105
+			}
106
+			return patients, nil
107
+		}
108
+	} else { //缓存数据了数据,将redis缓存的json字符串转为map
109
+		json.Unmarshal([]byte(patient_info_str), &patients)
110
+		return patients, nil
111
+	}
112
+}
113
+
114
+func GetAllDevicetByList(orgID int64) (devices []*models.MDeviceNumberForList, err error) {
115
+	redis := RedisClient()
116
+	defer redis.Close()
117
+	key := strconv.FormatInt(orgID, 10) + ":"+ ":device_list_all" 
118
+	device_list_str, _ := redis.Get(key).Result()
119
+
120
+	if len(device_list_str) == 0 { //没有到缓存数据,从数据库中获取数据,进行缓存到redis
121
+		err = readDb.Model(&models.MDeviceNumberForList{}).Preload("Zone", "status = 1 AND org_id = ?", orgID).Where("org_id=? and status=1 ", orgID).Find(&devices).Error
122
+		if err != nil {
123
+			if err == gorm.ErrRecordNotFound {
124
+				return nil, nil
125
+			} else {
126
+				return nil, err
127
+			}
128
+		} else {
129
+			if len(devices) > 0 {
130
+				//缓存数据
131
+				device_list_str, err := json.Marshal(&devices)
132
+				if err == nil {
133
+					redis.Set(key, device_list_str, time.Second*60*60*18)
134
+				}
135
+			}
136
+			return devices, nil
137
+		}
138
+	} else { //缓存数据了数据,将redis缓存的json字符串转为map
139
+		json.Unmarshal([]byte(device_list_str), &devices)
140
+		return devices, nil
141
+	}
142
+}
143
+
144
+func GetAllAdvicestByList(orgID int64,scheduleDate int64) (advices []models.VMDoctorAdviceForList, err error) {
145
+	redis := RedisClient()
146
+	defer redis.Close()
147
+	key := strconv.FormatInt(orgID, 10) + ":"+ ":advice_list_all" 
148
+	advice_list_str, _ := redis.Get(key).Result()
149
+
150
+	if len(advice_list_str) == 0 { //没有到缓存数据,从数据库中获取数据,进行缓存到redis
151
+		err = readDb.Model(&models.VMDoctorAdviceForList{}).Where("status = 1 AND user_org_id = ? AND advice_type = 2 AND advice_date = ? ", orgID, scheduleDate).Find(&advices).Error
152
+		if err != nil {
153
+			if err == gorm.ErrRecordNotFound {
154
+				return nil, nil
155
+			} else {
156
+				return nil, err
157
+			}
158
+		} else {
159
+			if len(advices) > 0 {
160
+				//缓存数据
161
+				advice_list_str, err := json.Marshal(&advices)
162
+				if err == nil {
163
+					redis.Set(key, advice_list_str, time.Second*60*60*18)
164
+				}
165
+			}
166
+			return advices, nil
167
+		}
168
+	} else { //缓存数据了数据,将redis缓存的json字符串转为map
169
+		json.Unmarshal([]byte(advice_list_str), &advices)
170
+		return advices, nil
171
+	}
172
+}
173
+
174
+func GetAllPrescriptionsByList(orgID int64,scheduleDate int64) (prescriptions []*models.DialysisPrescriptionList, err error) {
175
+	redis := RedisClient()
176
+	defer redis.Close()
177
+	key := strconv.FormatInt(orgID, 10) + ":"+ ":prescriptions_list_all" 
178
+	prescriptions_list_all, _ := redis.Get(key).Result()
179
+
180
+	if len(prescriptions_list_all) == 0 { //没有到缓存数据,从数据库中获取数据,进行缓存到redis
181
+		err = readDb.Model(&models.DialysisPrescriptionList{}).Where("status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).Find(&prescriptions).Error
182
+		if err != nil {
183
+			if err == gorm.ErrRecordNotFound {
184
+				return nil, nil
185
+			} else {
186
+				return nil, err
187
+			}
188
+		} else {
189
+			if len(prescriptions) > 0 {
190
+				//缓存数据
191
+				prescriptions_list_all, err := json.Marshal(&prescriptions)
192
+				if err == nil {
193
+					redis.Set(key, prescriptions_list_all, time.Second*60*60*18)
194
+				}
195
+			}
196
+			return prescriptions, nil
197
+		}
198
+	} else { //缓存数据了数据,将redis缓存的json字符串转为map
199
+		json.Unmarshal([]byte(prescriptions_list_all), &prescriptions)
200
+		return prescriptions, nil
201
+	}
202
+}
203
+
204
+func GetAllAssessmentBeforesByList(orgID int64,scheduleDate int64) (assessmentBefores []*models.PredialysisEvaluationList, err error) {
205
+	redis := RedisClient()
206
+	defer redis.Close()
207
+	key := strconv.FormatInt(orgID, 10) + ":"+ ":assessment_befores_list_all" 
208
+	assessment_befores_list_all, _ := redis.Get(key).Result()
209
+
210
+	if len(assessment_befores_list_all) == 0 { //没有到缓存数据,从数据库中获取数据,进行缓存到redis
211
+		err = readDb.Model(&models.PredialysisEvaluationList{}).Where( "status = 1 AND user_org_id = ? AND assessment_date = ? ", orgID, scheduleDate).Find(&assessmentBefores).Error
212
+		if err != nil {
213
+			if err == gorm.ErrRecordNotFound {
214
+				return nil, nil
215
+			} else {
216
+				return nil, err
217
+			}
218
+		} else {
219
+			if len(assessmentBefores) > 0 {
220
+				//缓存数据
221
+				assessment_befores_list_all, err := json.Marshal(&assessmentBefores)
222
+				if err == nil {
223
+					redis.Set(key, assessment_befores_list_all, time.Second*60*60*18)
224
+				}
225
+			}
226
+			return assessmentBefores, nil
227
+		}
228
+	} else { //缓存数据了数据,将redis缓存的json字符串转为map
229
+		json.Unmarshal([]byte(assessment_befores_list_all), &assessmentBefores)
230
+		return assessmentBefores, nil
231
+	}
232
+}
233
+
234
+func GetAllDialysisOrdersByList(orgID int64,scheduleDate int64) (dialysisOrders []*models.MDialysisOrderForList, err error) {
235
+	redis := RedisClient()
236
+	defer redis.Close()
237
+	key := strconv.FormatInt(orgID, 10) + ":"+ ":dialysis_orders_list_all" 
238
+	dialysis_orders_list_all, _ := redis.Get(key).Result()
239
+
240
+	if len(dialysis_orders_list_all) == 0 { //没有到缓存数据,从数据库中获取数据,进行缓存到redis
241
+		err = readDb.Model(&models.MDialysisOrderForList{}).Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).Where("status = 1 AND user_org_id = ? AND dialysis_date = ?", orgID, scheduleDate).Find(&dialysisOrders).Error
242
+		if err != nil {
243
+			if err == gorm.ErrRecordNotFound {
244
+				return nil, nil
245
+			} else {
246
+				return nil, err
247
+			}
248
+		} else {
249
+			if len(dialysisOrders) > 0 {
250
+				//缓存数据
251
+				dialysis_orders_list_all, err := json.Marshal(&dialysisOrders)
252
+				if err == nil {
253
+					redis.Set(key, dialysis_orders_list_all, time.Second*60*60*18)
254
+				}
255
+			}
256
+			return dialysisOrders, nil
257
+		}
258
+	} else { //缓存数据了数据,将redis缓存的json字符串转为map
259
+		json.Unmarshal([]byte(dialysis_orders_list_all), &dialysisOrders)
260
+		return dialysisOrders, nil
261
+	}
262
+}
263
+
264
+func GetAllTreatmentSummarysByList(orgID int64,scheduleDate int64) (treatmentSummarys []*models.VMTreatmentSummaryForList, err error) {
265
+	redis := RedisClient()
266
+	defer redis.Close()
267
+	key := strconv.FormatInt(orgID, 10) + ":"+ ":treatment_summarys_list_all" 
268
+	treatment_summarys_all, _ := redis.Get(key).Result()
269
+
270
+	if len(treatment_summarys_all) == 0 { //没有到缓存数据,从数据库中获取数据,进行缓存到redis
271
+		err = readDb.Model(&models.VMTreatmentSummaryForList{}).Where("status = 1  AND user_org_id = ? AND assessment_date = ?", orgID, scheduleDate).Find(&treatmentSummarys).Error
272
+		if err != nil {
273
+			if err == gorm.ErrRecordNotFound {
274
+				return nil, nil
275
+			} else {
276
+				return nil, err
277
+			}
278
+		} else {
279
+			if len(treatmentSummarys) > 0 {
280
+				//缓存数据
281
+				treatment_summarys_all, err := json.Marshal(&treatmentSummarys)
282
+				if err == nil {
283
+					redis.Set(key, treatment_summarys_all, time.Second*60*60*18)
284
+				}
285
+			}
286
+			return treatmentSummarys, nil
287
+		}
288
+	} else { //缓存数据了数据,将redis缓存的json字符串转为map
289
+		json.Unmarshal([]byte(treatment_summarys_all), &treatmentSummarys)
290
+		return treatmentSummarys, nil
291
+	}
292
+}
293
+
294
+func GetAllAssessmentAfterDislysisByList(orgID int64,scheduleDate int64) (assessmentAfterDislysis []*models.VMAssessmentAfterDislysis, err error) {
295
+	redis := RedisClient()
296
+	defer redis.Close()
297
+	key := strconv.FormatInt(orgID, 10) + ":"+ ":assessment_after_dislysis_list_all" 
298
+	assessment_after_dislysis__all, _ := redis.Get(key).Result()
299
+
300
+	if len(assessment_after_dislysis__all) == 0 { //没有到缓存数据,从数据库中获取数据,进行缓存到redis
301
+		err = readDb.Model(&models.VMAssessmentAfterDislysis{}).Where("status = 1  AND user_org_id = ? AND assessment_date = ?", orgID, scheduleDate).Find(&assessmentAfterDislysis).Error
302
+		if err != nil {
303
+			if err == gorm.ErrRecordNotFound {
304
+				return nil, nil
305
+			} else {
306
+				return nil, err
307
+			}
308
+		} else {
309
+			if len(assessmentAfterDislysis) > 0 {
310
+				//缓存数据
311
+				assessment_after_dislysis__all, err := json.Marshal(&assessmentAfterDislysis)
312
+				if err == nil {
313
+					redis.Set(key, assessment_after_dislysis__all, time.Second*60*60*18)
314
+				}
315
+			}
316
+			return assessmentAfterDislysis, nil
317
+		}
318
+	} else { //缓存数据了数据,将redis缓存的json字符串转为map
319
+		json.Unmarshal([]byte(assessment_after_dislysis__all), &assessmentAfterDislysis)
320
+		return assessmentAfterDislysis, nil
321
+	}
322
+}
323
+
324
+func GetAllHisAdvicesByList(orgID int64,scheduleDate int64) (hisAdvices []VMHisDoctorAdviceInfo, err error) {
325
+	redis := RedisClient()
326
+	defer redis.Close()
327
+	key := strconv.FormatInt(orgID, 10) + ":"+ ":his_advices_list_all" 
328
+	his_advices_all, _ := redis.Get(key).Result()
329
+
330
+	if len(his_advices_all) == 0 { //没有到缓存数据,从数据库中获取数据,进行缓存到redis
331
+		err = readDb.Model(&VMHisDoctorAdviceInfo{}).Where("status = 1 AND user_org_id = ? AND advice_date = ?", orgID, scheduleDate).Find(&hisAdvices).Error
332
+		if err != nil {
333
+			if err == gorm.ErrRecordNotFound {
334
+				return nil, nil
335
+			} else {
336
+				return nil, err
337
+			}
338
+		} else {
339
+			if len(hisAdvices) > 0 {
340
+				//缓存数据
341
+				his_advices_all, err := json.Marshal(&hisAdvices)
342
+				if err == nil {
343
+					redis.Set(key, his_advices_all, time.Second*60*60*18)
344
+				}
345
+			}
346
+			return hisAdvices, nil
347
+		}
348
+	} else { //缓存数据了数据,将redis缓存的json字符串转为map
349
+		json.Unmarshal([]byte(his_advices_all), &hisAdvices)
350
+		return hisAdvices, nil
351
+	}
352
+}
353
+
83 354
 func GetPatientListByUpdateTime(orgID int64, syncTime int64) (patients []*models.PatientListForFaceList, total int64, err error) {
84 355
 	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 356
 
@@ -156,8 +427,33 @@ func FindPatientByIdTwo(orgID int64, id int64) (patient models.XtPatientsNew, er
156 427
 }
157 428
 
158 429
 func FindPatientByIdWithDiseases(orgID int64, id int64) (patient models.Patients, err error) {
159
-	err = readDb.Model(&models.Patients{}).Preload("Contagions", "status = 1").Preload("Diseases", "status = 1").Where("id = ? and user_org_id=? and status=1", id, orgID).First(&patient).Error
160
-	return
430
+	redis := RedisClient()
431
+	defer redis.Close()
432
+	key := strconv.FormatInt(orgID, 10) + ":"+ strconv.FormatInt(id, 10) + ":patient_info" 
433
+	patient_info_str, _ := redis.Get(key).Result()
434
+
435
+	if len(patient_info_str) == 0 { //没有到缓存数据,从数据库中获取数据,进行缓存到redis
436
+		err = readDb.Model(&models.Patients{}).Preload("Contagions", "status = 1").Preload("Diseases", "status = 1").Where("id = ? and user_org_id=? and status=1", id, orgID).First(&patient).Error
437
+		if err != nil {
438
+			if err == gorm.ErrRecordNotFound {
439
+				return patient, nil
440
+			} else {
441
+				return patient, err
442
+			}
443
+		} else {
444
+			if patient.ID > 0 {
445
+				//缓存数据
446
+				patient_info_json, err := json.Marshal(&patient)
447
+				if err == nil {
448
+					redis.Set(key, patient_info_json, time.Second*60*60*18)
449
+				}
450
+			}
451
+			return patient, nil
452
+		}
453
+	} else { //缓存数据了数据,将redis缓存的json字符串转为map
454
+		json.Unmarshal([]byte(patient_info_str), &patient)
455
+		return patient, nil
456
+	}
161 457
 }
162 458
 
163 459
 func FindPatientWithDeviceByNo(orgID int64, no string, time int64) (patient models.SchedualPatient2, err error) {

+ 32 - 3
service/patientmanage_service.go Прегледај датотеку

@@ -7,6 +7,7 @@ import (
7 7
 	"strconv"
8 8
 	"strings"
9 9
 	"time"
10
+	"encoding/json"
10 11
 )
11 12
 
12 13
 func GetIllnessListTwo() (ills []*models.Illness, err error) {
@@ -1562,10 +1563,38 @@ func DeleteWayAssessment(id int64) error {
1562 1563
 }
1563 1564
 
1564 1565
 func GetLastPassWayAssessment(orgid int64, patientId int64) (models.XtPatientVascularAccess, error) {
1565
-
1566 1566
 	assessment := models.XtPatientVascularAccess{}
1567
-	err := XTReadDB().Model(&assessment).Where("user_org_id = ? and patient_id = ? and status =1 and user_status = 1", orgid, patientId).Order("start_time desc").Last(&assessment).Error
1568
-	return assessment, err
1567
+	redis := RedisClient()
1568
+	defer redis.Close()
1569
+
1570
+	// cur_date := time.Now().Format("2006-01-02")
1571
+	key := strconv.FormatInt(orgid, 10) + ":" + strconv.FormatInt(patientId, 10) + ":pass_way_assessment_last"
1572
+	pass_way_assessment_last_str, _ := redis.Get(key).Result()
1573
+
1574
+	if len(pass_way_assessment_last_str) == 0 { //没有到缓存数据,从数据库中获取数据,进行缓存到redis
1575
+		err := XTReadDB().Model(&assessment).Where("user_org_id = ? and patient_id = ? and status =1 and user_status = 1", orgid, patientId).Order("start_time desc").Last(&assessment).Error
1576
+		if err != nil {
1577
+			if err == gorm.ErrRecordNotFound {
1578
+				return assessment,nil
1579
+			} else {
1580
+				return assessment,err
1581
+			}
1582
+		} else {
1583
+			if assessment.ID > 0 {
1584
+				//缓存数据
1585
+				pass_way_assessment_last_str, err := json.Marshal(assessment)
1586
+				if err == nil {
1587
+					redis.Set(key, pass_way_assessment_last_str, time.Second*60*60*18)
1588
+				}
1589
+			} else {
1590
+				redis.Set(key, " ", time.Second*60*60*18)
1591
+			}
1592
+			return assessment,nil
1593
+		}
1594
+	} else { //缓存数据了数据,将redis缓存的json字符串转为map
1595
+		json.Unmarshal([]byte(pass_way_assessment_last_str), &assessment)
1596
+		return assessment,nil
1597
+	}
1569 1598
 }
1570 1599
 
1571 1600
 func GetAccessList(orgid int64) (*models.Dataconfig, error) {

+ 36 - 3
service/role_service.go Прегледај датотеку

@@ -6,7 +6,7 @@ import (
6 6
 	"strconv"
7 7
 	"strings"
8 8
 	"time"
9
-
9
+	"encoding/json"
10 10
 	"XT_New/models"
11 11
 	"XT_New/utils"
12 12
 
@@ -790,8 +790,41 @@ func SaveRoleFuncPurview(purview *models.SgjUserRoleFuncPurview) (err error) {
790 790
 }
791 791
 
792 792
 func GetUserAllRole(org_id int64, admin_user_id int64) (role models.App_Role, err error) {
793
-	err = readUserDb.Model(&models.App_Role{}).Where("status = 1 AND org_id = ? AND admin_user_id = ?", org_id, admin_user_id).First(&role).Error
794
-	return
793
+
794
+	redis := RedisClient()
795
+	defer redis.Close()
796
+
797
+	// cur_date := time.Now().Format("2006-01-02")
798
+	key := "user_all_role:" + strconv.FormatInt(org_id, 10) + ":"+ strconv.FormatInt(admin_user_id, 10)
799
+	role_str, _ := redis.Get(key).Result()
800
+
801
+	if len(role_str) == 0 { //没有到缓存数据,从数据库中获取数据,进行缓存到redis
802
+		err = readUserDb.Model(&models.App_Role{}).Where("status = 1 AND org_id = ? AND admin_user_id = ?", org_id, admin_user_id).First(&role).Error
803
+		if err != nil {
804
+			if err == gorm.ErrRecordNotFound {
805
+				return role, nil
806
+			} else {
807
+				return role, err
808
+			}
809
+		} else {
810
+			if role.Id > 0 {
811
+				//缓存数据
812
+				role_json, err := json.Marshal(role)
813
+				if err == nil {
814
+					redis.Set(key, role_json, time.Second*60*60*18)
815
+				}
816
+			}
817
+			return role, nil
818
+		}
819
+	} else { //缓存数据了数据,将redis缓存的json字符串转为map
820
+		if err := json.Unmarshal([]byte(role_str), &role); err == nil {
821
+
822
+		} else {
823
+
824
+		}
825
+		return role, nil
826
+	}
827
+
795 828
 }
796 829
 
797 830
 func GetAllFunctionPurview() (purview []models.SgjUserOperatePurview, err error) {

+ 71 - 13
service/stock_service.go Прегледај датотеку

@@ -6,6 +6,7 @@ import (
6 6
 	"github.com/jinzhu/gorm"
7 7
 	"strconv"
8 8
 	"strings"
9
+	"encoding/json"
9 10
 	"time"
10 11
 )
11 12
 
@@ -2797,25 +2798,82 @@ func PostSearchStock(keyword string, orgid int64) (goods []*models.GoodsType, er
2797 2798
 }
2798 2799
 
2799 2800
 func GetStockType(orgid int64) (goodstype []*models.GoodsTypeOne, err error) {
2800
-	err = XTReadDB().Where("org_id = ? and status = 1 and (stock_attribute = 2 or stock_attribute = 3)", orgid).
2801
+	redis := RedisClient()
2802
+	defer redis.Close()
2803
+
2804
+	// cur_date := time.Now().Format("2006-01-02")
2805
+	key := strconv.FormatInt(orgid, 10) + ":stock_type"
2806
+	stock_type_str, _ := redis.Get(key).Result()
2807
+
2808
+	if len(stock_type_str) == 0 { //没有到缓存数据,从数据库中获取数据,进行缓存到redis
2809
+		err = XTReadDB().Where("org_id = ? and status = 1 and (stock_attribute = 2 or stock_attribute = 3)", orgid).
2801 2810
 		Preload("GoodInfo", "org_id = ? and status = 1", orgid).Find(&goodstype).Error
2802
-	return goodstype, err
2811
+		if err != nil {
2812
+			if err == gorm.ErrRecordNotFound {
2813
+				return nil, nil
2814
+			} else {
2815
+				return nil, err
2816
+			}
2817
+		} else {
2818
+			if len(goodstype) > 0 {
2819
+				//缓存数据
2820
+				stock_type_str, err := json.Marshal(goodstype)
2821
+				if err == nil {
2822
+					redis.Set(key, stock_type_str, time.Second*60*60*18)
2823
+				}
2824
+			} else {
2825
+				redis.Set(key, " ", time.Second*60*60*18)
2826
+			}
2827
+			return goodstype, nil
2828
+		}
2829
+	} else { //缓存数据了数据,将redis缓存的json字符串转为map
2830
+		json.Unmarshal([]byte(stock_type_str), &goodstype)
2831
+		return goodstype, nil
2832
+	}
2803 2833
 }
2804 2834
 
2805 2835
 func GetDialyStockOut(orgid int64, recordtime int64, patientId int64) (prepare []*models.XtDialysisBeforePrepare, err error) {
2836
+	redis := RedisClient()
2837
+	defer redis.Close()
2806 2838
 
2807
-	db := XTReadDB().Table("dialysis_before_prepare as x").Where("x.status = 1")
2808
-	if orgid > 0 {
2809
-		db = db.Where("x.user_org_id = ?", orgid)
2810
-	}
2811
-	if recordtime > 0 {
2812
-		db = db.Where("x.record_date = ?", recordtime)
2813
-	}
2814
-	if patientId > 0 {
2815
-		db = db.Where("x.patient_id = ?", patientId)
2839
+	// cur_date := time.Now().Format("2006-01-02")
2840
+	key := strconv.FormatInt(orgid, 10) + ":" + strconv.FormatInt(patientId, 10) + ":" + strconv.FormatInt(recordtime, 10) + ":dialy_stock_out"
2841
+	dialy_stock_out_str, _ := redis.Get(key).Result()
2842
+
2843
+	if len(dialy_stock_out_str) == 0 { //没有到缓存数据,从数据库中获取数据,进行缓存到redis
2844
+		db := XTReadDB().Table("dialysis_before_prepare as x").Where("x.status = 1")
2845
+		if orgid > 0 {
2846
+			db = db.Where("x.user_org_id = ?", orgid)
2847
+		}
2848
+		if recordtime > 0 {
2849
+			db = db.Where("x.record_date = ?", recordtime)
2850
+		}
2851
+		if patientId > 0 {
2852
+			db = db.Where("x.patient_id = ?", patientId)
2853
+		}
2854
+		err = db.Select("x.id,x.user_org_id,x.patient_id,x.record_date,x.good_id,x.good_type_id,x.count,x.commdity_code,t.specification_name").Joins("left join xt_good_information as t on t.id = x.good_id and t.org_id = ? and t.status = 1", orgid).Scan(&prepare).Error
2855
+		if err != nil {
2856
+			if err == gorm.ErrRecordNotFound {
2857
+				return nil, nil
2858
+			} else {
2859
+				return nil, err
2860
+			}
2861
+		} else {
2862
+			if len(prepare) > 0 {
2863
+				//缓存数据
2864
+				dialy_stock_out_str, err := json.Marshal(prepare)
2865
+				if err == nil {
2866
+					redis.Set(key, dialy_stock_out_str, time.Second*60*60*18)
2867
+				}
2868
+			} else {
2869
+				redis.Set(key, " ", time.Second*60*60*18)
2870
+			}
2871
+			return prepare, nil
2872
+		}
2873
+	} else { //缓存数据了数据,将redis缓存的json字符串转为map
2874
+		json.Unmarshal([]byte(dialy_stock_out_str), &prepare)
2875
+		return prepare, nil
2816 2876
 	}
2817
-	err = db.Select("x.id,x.user_org_id,x.patient_id,x.record_date,x.good_id,x.good_type_id,x.count,x.commdity_code,t.specification_name").Joins("left join xt_good_information as t on t.id = x.good_id and t.org_id = ? and t.status = 1", orgid).Scan(&prepare).Error
2818
-	return prepare, err
2819 2877
 }
2820 2878
 
2821 2879
 func GetAutoReduceRecordInfoById(orgid int64, recordtime int64, goodid int64, goodtypeid int64) (*models.XtAutomaticReduceDetail, error) {