陈少旭 il y a 2 mois
Parent
révision
dff9ab80df

+ 213 - 55
controllers/fapiao_controller.go Voir le fichier

@@ -8,6 +8,7 @@ import (
8 8
 	"XT_New/service"
9 9
 	"XT_New/service/fapiao"
10 10
 	"XT_New/utils"
11
+	"encoding/base64"
11 12
 	"encoding/json"
12 13
 	"fmt"
13 14
 	"github.com/astaxie/beego"
@@ -270,55 +271,164 @@ func (c *FapiaoApiController) GetOrderFaPiaoList() {
270 271
 }
271 272
 
272 273
 func (c *FapiaoApiController) GetLoginUploadCode() {
273
-	sdk := invoice.NewSdk(common.HMAC_SHA256, "8ca4ee7b152c0abceff9", "17402aff152dbeedf7a7b30be553f4c4", "", "test")
274
+	sdk := invoice.NewSdk(common.HMAC_SHA256, "5058f0defd12047ee2a7", "51440fbee667ea9a53aaa68c9c408367", "", "test")
274 275
 	var config models.FapiaoConfig
275 276
 	config, _ = service.FindFaPiaoConfigInfo(c.GetAdminUserInfo().CurrentOrgId)
276 277
 	routerAddress, postData := fapiao.GetSMSCode(config) //发票开具
277
-	r, err := sdk.HttpPost("https://apigw-test.goldentec.com", routerAddress, postData)
278
+	fmt.Println(routerAddress)
279
+	fmt.Println(postData)
280
+	r, err := sdk.HttpPost("https://apigw.goldentec.com", routerAddress, postData)
278 281
 	if err != nil {
279 282
 		fmt.Println(err)
280 283
 	} else {
281
-		fmt.Println(string(r))
284
+		var resp SmsCode
285
+		// 将 byte 切片转换为结构体
286
+		json.Unmarshal(r, &resp)
287
+		if resp.Code == 0 {
288
+			c.ServeSuccessJSON(map[string]interface{}{
289
+				"msg": resp.Message,
290
+			})
291
+		}
282 292
 	}
283 293
 }
284 294
 
295
+type SmsCode struct {
296
+	Code    int    `json:"code"`
297
+	Message string `json:"message"`
298
+}
299
+
285 300
 func (c *FapiaoApiController) Login() {
286
-	GetQRStatus(c.GetAdminUserInfo().CurrentOrgId)
287 301
 	code := c.GetString("code")
288 302
 	var config models.FapiaoConfig
289 303
 	config, _ = service.FindFaPiaoConfigInfo(c.GetAdminUserInfo().CurrentOrgId)
290
-	sdk := invoice.NewSdk(common.HMAC_SHA256, "8ca4ee7b152c0abceff9", "17402aff152dbeedf7a7b30be553f4c4", "", "test")
304
+	sdk := invoice.NewSdk(common.HMAC_SHA256, "5058f0defd12047ee2a7", "51440fbee667ea9a53aaa68c9c408367", "", "test")
291 305
 	routerAddress, postData := fapiao.Login(code, config) //发票开具
292
-	r, err := sdk.HttpPost("https://apigw-test.goldentec.com", routerAddress, postData)
306
+	r, err := sdk.HttpPost("https://apigw.goldentec.com", routerAddress, postData)
293 307
 	if err != nil {
294 308
 		fmt.Println(err)
295 309
 	} else {
296
-		fmt.Println(string(r))
310
+		var resp SmsCode
311
+		// 将 byte 切片转换为结构体
312
+		json.Unmarshal(r, &resp)
313
+		if resp.Code == 0 {
314
+			c.ServeSuccessJSON(map[string]interface{}{
315
+				"msg": resp.Message,
316
+			})
317
+		}
297 318
 	}
298 319
 }
299
-
300 320
 func (c *FapiaoApiController) GetQRCode() {
301
-	sdk := invoice.NewSdk(common.HMAC_SHA256, "8ca4ee7b152c0abceff9", "17402aff152dbeedf7a7b30be553f4c4", "", "test")
321
+	sdk := invoice.NewSdk(common.HMAC_SHA256, "5058f0defd12047ee2a7", "51440fbee667ea9a53aaa68c9c408367", "", "test")
302 322
 	var config models.FapiaoConfig
303 323
 	config, _ = service.FindFaPiaoConfigInfo(c.GetAdminUserInfo().CurrentOrgId)
304 324
 	routerAddress, postData := fapiao.GetQRCode(config) //发票开具
305
-	r, err := sdk.HttpPost("https://apigw-test.goldentec.com", routerAddress, postData)
325
+	r, err := sdk.HttpPost("https://apigw.goldentec.com", routerAddress, postData)
306 326
 	if err != nil {
307 327
 		fmt.Println(err)
308 328
 	} else {
309
-		fmt.Println(string(r))
329
+		var resp QRAuth
330
+		// 将 byte 切片转换为结构体
331
+		err := json.Unmarshal(r, &resp)
332
+		fmt.Println(resp)
333
+		if err != nil {
334
+			fmt.Println("Error unmarshalling:", err)
335
+		} else {
336
+			if resp.Code == 0 {
337
+				decodedBytes, _ := base64.StdEncoding.DecodeString(resp.Data.QrCode)
338
+				if len(resp.Data.AuthId) == 0 { //还没进行授权,则获取二维码信息
339
+					c.ServeSuccessJSON(map[string]interface{}{
340
+						"cus_status": 1,
341
+						"qr_code":    string(decodedBytes),
342
+					})
343
+
344
+				} else {
345
+					status := GetQRStatus(c.GetAdminUserInfo().CurrentOrgId, resp.Data.AuthId)
346
+					if status == "UNDEFINE" {
347
+						c.ServeSuccessJSON(map[string]interface{}{
348
+							"cus_status": -1,
349
+							"msg":        "未定义",
350
+						})
351
+					} else if status == "UNHANDLED" {
352
+						c.ServeSuccessJSON(map[string]interface{}{
353
+							"cus_status": 1,
354
+							"qr_code":    string(decodedBytes),
355
+						})
356
+					} else if status == "REAL_AUTH_SUCCESS" {
357
+						c.ServeSuccessJSON(map[string]interface{}{
358
+							"cus_status": 2,
359
+							"msg":        "已经实名认证成功",
360
+						})
361
+					} else if status == "REFRESH" {
362
+						c.ServeSuccessJSON(map[string]interface{}{
363
+							"cus_status": 1,
364
+							"qr_code":    string(decodedBytes),
365
+						})
366
+					} else if status == "NEED_RELOGIN_BUREAU" {
367
+						c.ServeSuccessJSON(map[string]interface{}{
368
+							"cus_status": -3,
369
+							"msg":        "登录失效,请重新短信登录税局",
370
+						})
371
+
372
+					}
373
+				}
374
+
375
+			} else {
376
+				c.ServeSuccessJSON(map[string]interface{}{
377
+					"cus_status": -4,
378
+					"msg":        resp.Message,
379
+				})
380
+			}
381
+
382
+		}
383
+		//fmt.Println(string(r))
310 384
 	}
311 385
 }
312
-
313 386
 func (c *FapiaoApiController) OpenFaPiao() {
387
+	//var config models.FapiaoConfig
388
+	//config, _ = service.FindFaPiaoConfigInfo(c.GetAdminUserInfo().CurrentOrgId)
389
+
314 390
 	//认证接口
391
+	sdk := invoice.NewSdk(common.HMAC_SHA256, "5058f0defd12047ee2a7", "51440fbee667ea9a53aaa68c9c408367", "", "test")
392
+	status := GetQRStatusTwo(c.GetAdminUserInfo().CurrentOrgId)
393
+	fmt.Println("11112222")
394
+
395
+	fmt.Println(status)
396
+	if status == 0 {
397
+		c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAuthWrong)
398
+		return
399
+	}
315 400
 	//查询余量接口
401
+	//routerAddress, postData := fapiao.QueryStock(config)
402
+	//r, err := sdk.HttpPost("https://apigw.goldentec.com", routerAddress, postData)
403
+	//fmt.Println(string(r))
404
+	//if err != nil {
405
+	//	fmt.Println(err)
406
+	//} else {
407
+	//	var resp2 FapiaoStock
408
+	//	// 将 byte 切片转换为结构体
409
+	//	err2 := json.Unmarshal(r, &resp2)
410
+	//	if err2 != nil {
411
+	//		fmt.Println(err2)
412
+	//
413
+	//	} else {
414
+	//		if resp2.Code == 0 {
415
+	//			if resp2.Data.LeftQuantity <= 0 {
416
+	//				c.ServeSuccessJSON(map[string]interface{}{
417
+	//					"msg":    "发票余量不足,请登录高灯平台申领发票",
418
+	//					"status": -1,
419
+	//				})
420
+	//				return
421
+	//			}
422
+	//		}
423
+	//	}
424
+	//}
425
+	//return
426
+
427
+	//开蓝票逻辑
316 428
 	order_ids := c.GetString("order_ids")
317 429
 	admin_user_id, _ := c.GetInt64("admin_user_id")
318
-
319 430
 	ids := strings.Split(order_ids, ",")
320 431
 	orders, _ := service.GetFaPiaoOrderByIDS(ids)
321
-
322 432
 	var MedfeeSumamt float64 = 0  //治疗费用
323 433
 	var PsnCashPay float64 = 0    //治疗费用
324 434
 	var FundPaySumamt float64 = 0 //治疗费用
@@ -334,9 +444,8 @@ func (c *FapiaoApiController) OpenFaPiao() {
334 444
 		numbers = append(numbers, oss.Number)
335 445
 	}
336 446
 	details, _ = service.GetFaPiaoOrderInfoByNumbers(numbers)
337
-	//orders, _ := service.GetFaPiaoOrderByIDS(ids)
338 447
 	role, _ := service.GetAdminUserRole(admin_user_id, c.GetAdminUserInfo().CurrentOrgId)
339
-	role.UserName = "王毅"
448
+	role.UserName = "邹碧琳"
340 449
 	type CostType struct {
341 450
 		name  string
342 451
 		price float64
@@ -473,14 +582,14 @@ func (c *FapiaoApiController) OpenFaPiao() {
473 582
 
474 583
 	}
475 584
 	fmt.Println(cts)
476
-	config, _ := service.FindMedicalInsuranceInfo(c.GetAdminUserInfo().CurrentOrgId)
585
+	org_config, _ := service.FindMedicalInsuranceInfo(c.GetAdminUserInfo().CurrentOrgId)
477 586
 	var config2 models.FapiaoConfig
478 587
 	config2, _ = service.FindFaPiaoConfigInfo(c.GetAdminUserInfo().CurrentOrgId)
479 588
 	number := strconv.FormatInt(time.Now().Unix(), 10) + "_" + strconv.FormatInt(orders[0].UserOrgId, 10) + "_" + strconv.FormatInt(orders[0].PatientId, 10)
480 589
 	amountWithoutTax, _, taxAmount, amountHasTax := CalculatePriceDetails(MedfeeSumamt, 1, 0.13)
481 590
 
482
-	postData := map[string]interface{}{
483
-		"seller_name":          config.OrgName,
591
+	postData3 := map[string]interface{}{
592
+		"seller_name":          org_config.OrgName,
484 593
 		"seller_taxpayer_num":  config2.SellerTaxpayerNum,
485 594
 		"seller_address":       config2.SellerAddress,
486 595
 		"seller_tel":           config2.SellerTel,
@@ -500,7 +609,7 @@ func (c *FapiaoApiController) OpenFaPiao() {
500 609
 		"drawer":               role.UserName,
501 610
 		"payee":                "",
502 611
 		"checker":              "",
503
-		"terminal_code":        "140301195503104110",
612
+		"terminal_code":        config2.TerminalCode,
504 613
 		"user_openid":          "",
505 614
 		"special_invoice_kind": "",
506 615
 		"zsfs":                 "",
@@ -532,16 +641,13 @@ func (c *FapiaoApiController) OpenFaPiao() {
532 641
 		items = append(items, item)
533 642
 	}
534 643
 
535
-	postData["items"] = items
536
-	fmt.Println("postData")
537
-	fmt.Println(postData)
538
-	sdk := invoice.NewSdk(common.HMAC_SHA256, "8ca4ee7b152c0abceff9", "17402aff152dbeedf7a7b30be553f4c4", "", "test")
539
-	routerAddress, postData := fapiao.Blue(postData) //发票开具
540
-	r, err := sdk.HttpPost("https://apigw-test.goldentec.com", routerAddress, postData)
644
+	postData3["items"] = items
645
+	routerAddress, postData4 := fapiao.Blue(postData3) //发票开具
646
+	r, err4 := sdk.HttpPost("https://apigw.goldentec.com", routerAddress, postData4)
541 647
 	fmt.Println("blue")
542 648
 	fmt.Println(string(r))
543
-	if err != nil {
544
-		fmt.Println(err)
649
+	if err4 != nil {
650
+		fmt.Println(err4)
545 651
 	} else {
546 652
 		var resp OpenFaPiaoResultResponse
547 653
 		// 将 byte 切片转换为结构体
@@ -555,7 +661,7 @@ func (c *FapiaoApiController) OpenFaPiao() {
555 661
 			if resp.Code == 0 {
556 662
 				//开具蓝票成功,请求查询接口,获取发票相关数据
557 663
 				routerAddress2, postData2 := fapiao.Query(config2.SellerTaxpayerNum, resp.Data.OrderSn, number)
558
-				r3, err2 := sdk.HttpPost("https://apigw-test.goldentec.com", routerAddress2, postData2)
664
+				r3, err2 := sdk.HttpPost("https://apigw.goldentec.com", routerAddress2, postData2)
559 665
 				fmt.Println("query")
560 666
 				fmt.Println(string(r3))
561 667
 				if err2 != nil {
@@ -596,42 +702,38 @@ func (c *FapiaoApiController) OpenFaPiao() {
596 702
 								"msg": "开具成功",
597 703
 							})
598 704
 						}
705
+					} else {
706
+						//错误处理
707
+
599 708
 					}
600 709
 				}
710
+			} else {
711
+				//错误处理
712
+
601 713
 			}
602 714
 		}
603 715
 	}
604 716
 }
605 717
 func (c *FapiaoApiController) RedFaPiao() {
606
-	////1.开发发票前先检查是否已经登录到税局和已经实名认证
607
-	//status := GetQRStatus(c.GetAdminUserInfo().CurrentOrgId)
608
-	//if status == "REAL_AUTH_SUCCESS" { //实人认证成功
609
-	//	GetQRStatus(c.GetAdminUserInfo().CurrentOrgId)
610
-	//	sdk := invoice.NewSdk(common.HMAC_SHA256, "8ca4ee7b152c0abceff9", "17402aff152dbeedf7a7b30be553f4c4", "", "test")
611
-	//	var config models.FapiaoConfig
612
-	//	config, _ = service.FindFaPiaoConfigInfo(c.GetAdminUserInfo().CurrentOrgId)
613
-	//
614
-	//	routerAddress, postData := fapiao.Red() //发票开具
615
-	//	_, err := sdk.HttpPost("https://apigw-test.goldentec.com", routerAddress, postData)
616
-	//	if err != nil {
617
-	//		fmt.Println(err)
618
-	//	} else {
619
-	//
620
-	//	}
621
-	//}
622
-	//order_ids := c.GetString("order_ids")
718
+	//认证
719
+	status := GetQRStatusTwo(c.GetAdminUserInfo().CurrentOrgId)
720
+	if status == 0 {
721
+		c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAuthWrong)
722
+		return
723
+	}
724
+
623 725
 	id, _ := c.GetInt64("id")
624 726
 	admin_user_id, _ := c.GetInt64("admin_user_id")
625 727
 	role2, _ := service.GetAdminUserRole(admin_user_id, c.GetAdminUserInfo().CurrentOrgId)
626 728
 	fapiao_config, _ := service.GetFaPiaoOrderById(id)
627 729
 	var config models.FapiaoConfig
628 730
 	config, _ = service.FindFaPiaoConfigInfo(c.GetAdminUserInfo().CurrentOrgId)
629
-	sdk := invoice.NewSdk(common.HMAC_SHA256, "8ca4ee7b152c0abceff9", "17402aff152dbeedf7a7b30be553f4c4", "", "test")
731
+	sdk := invoice.NewSdk(common.HMAC_SHA256, "5058f0defd12047ee2a7", "51440fbee667ea9a53aaa68c9c408367", "", "test")
630 732
 	routerAddress, postData := fapiao.Red(config.SellerTaxpayerNum, "", fapiao_config.OrderSn) //发票开具
631 733
 	fmt.Println("postData")
632 734
 	fmt.Println(postData)
633 735
 	fmt.Println("postData")
634
-	red, err := sdk.HttpPost("https://apigw-test.goldentec.com", routerAddress, postData)
736
+	red, err := sdk.HttpPost("https://apigw.goldentec.com", routerAddress, postData)
635 737
 	fmt.Println("red")
636 738
 	fmt.Println(red)
637 739
 	fmt.Println("red")
@@ -651,7 +753,7 @@ func (c *FapiaoApiController) RedFaPiao() {
651 753
 			if resp.Data[0].State == 1 {
652 754
 				//查询红票开具情况
653 755
 				routerAddress2, postData2 := fapiao.Query(config.SellerTaxpayerNum, fapiao_config.OrderSn, "")
654
-				r3, _ := sdk.HttpPost("https://apigw-test.goldentec.com", routerAddress2, postData2)
756
+				r3, _ := sdk.HttpPost("https://apigw.goldentec.com", routerAddress2, postData2)
655 757
 				var resp3 QueryFaPiaoResultResponse
656 758
 				// 将 byte 切片转换为结构体
657 759
 				json.Unmarshal(r3, &resp3)
@@ -695,6 +797,44 @@ func (c *FapiaoApiController) RedFaPiao() {
695 797
 		}
696 798
 	}
697 799
 }
800
+func GetQRStatusTwo(org_id int64) (status int64) {
801
+	sdk := invoice.NewSdk(common.HMAC_SHA256, "5058f0defd12047ee2a7", "51440fbee667ea9a53aaa68c9c408367", "", "test")
802
+	var config models.FapiaoConfig
803
+	config, _ = service.FindFaPiaoConfigInfo(org_id)
804
+	routerAddress, postData := fapiao.GetQRCode(config) //发票开具
805
+	r, err := sdk.HttpPost("https://apigw.goldentec.com", routerAddress, postData)
806
+	if err != nil {
807
+		fmt.Println(err)
808
+	} else {
809
+		var resp QRAuth
810
+		// 将 byte 切片转换为结构体
811
+		err := json.Unmarshal(r, &resp)
812
+		fmt.Println(resp)
813
+		if err != nil {
814
+			fmt.Println("Error unmarshalling:", err)
815
+		} else {
816
+			if len(resp.Data.AuthId) == 0 { //还没实名认证
817
+
818
+			} else {
819
+				status = 1
820
+				status_str := GetQRStatus(org_id, resp.Data.AuthId)
821
+				if status_str == "UNDEFINE" {
822
+					status = 0
823
+				} else if status_str == "UNHANDLED" {
824
+					status = 0
825
+				} else if status_str == "REAL_AUTH_SUCCESS" {
826
+					status = 1
827
+				} else if status_str == "REFRESH" {
828
+					status = 0
829
+				} else if status_str == "NEED_RELOGIN_BUREAU" {
830
+					status = 0
831
+
832
+				}
833
+			}
834
+		}
835
+	}
836
+	return
837
+}
698 838
 
699 839
 type RedResult struct {
700 840
 	Code int `json:"code"`
@@ -706,7 +846,6 @@ type RedResult struct {
706 846
 	} `json:"data"`
707 847
 	Message string `json:"message"`
708 848
 }
709
-
710 849
 type QueryFaPiaoResultResponse struct {
711 850
 	Code int `json:"code"`
712 851
 	Data struct {
@@ -736,7 +875,6 @@ type OpenFaPiaoResultResponse struct {
736 875
 		InvoiceId string `json:"invoice_id"`
737 876
 	} `json:"data"`
738 877
 }
739
-
740 878
 type SurplusStockResponse struct {
741 879
 	Code    int    `json:"code"`
742 880
 	Message string `json:"message"`
@@ -776,14 +914,16 @@ type Response struct {
776 914
 	} `json:"data"`
777 915
 }
778 916
 
779
-func GetQRStatus(org_id int64) (status string) {
780
-	sdk := invoice.NewSdk(common.HMAC_SHA256, "8ca4ee7b152c0abceff9", "17402aff152dbeedf7a7b30be553f4c4", "", "test")
917
+func GetQRStatus(org_id int64, auth_id string) (status string) {
918
+	sdk := invoice.NewSdk(common.HMAC_SHA256, "5058f0defd12047ee2a7", "51440fbee667ea9a53aaa68c9c408367", "", "test")
781 919
 	fmt.Println(sdk)
782 920
 	var config models.FapiaoConfig
783 921
 	config, _ = service.FindFaPiaoConfigInfo(org_id)
784 922
 	fmt.Println(config)
785
-	routerAddress, postData := fapiao.GetQRStatus("", config) //发票开具
786
-	r, err := sdk.HttpPost("https://apigw-test.goldentec.com", routerAddress, postData)
923
+	routerAddress, postData := fapiao.GetQRStatus(auth_id, config) //发票开具
924
+	fmt.Println(routerAddress)
925
+	fmt.Println(postData)
926
+	r, err := sdk.HttpPost("https://apigw.goldentec.com", routerAddress, postData)
787 927
 	if err != nil {
788 928
 		status = "FAILD"
789 929
 		fmt.Println(err)
@@ -794,6 +934,7 @@ func GetQRStatus(org_id int64) (status string) {
794 934
 
795 935
 		// 将 byte 切片转换为结构体
796 936
 		err := json.Unmarshal(r, &resp)
937
+		fmt.Println(string(r))
797 938
 		if err != nil {
798 939
 			status = "FAILD"
799 940
 			fmt.Println("Error unmarshalling:", err)
@@ -828,3 +969,20 @@ func roundTo(value float64, places int) float64 {
828 969
 	scale := math.Pow(10, float64(places))
829 970
 	return math.Round(value*scale) / scale
830 971
 }
972
+
973
+type QRAuth struct {
974
+	Code    int    `json:"code"`
975
+	Message string `json:"message"`
976
+	Data    struct {
977
+		AuthId string `json:"auth_id"`
978
+		QrCode string `json:"qr_code"`
979
+	} `json:"data"`
980
+}
981
+
982
+type FapiaoStock struct {
983
+	Code int `json:"code"`
984
+	Data struct {
985
+		LeftQuantity int `json:"left_quantity"`
986
+	} `json:"data"`
987
+	Message string `json:"message"`
988
+}

+ 3 - 0
controllers/statistics_api_controller.go Voir le fichier

@@ -87,6 +87,9 @@ func (c *StatisticsApiController) GetPatientWeightDetail() {
87 87
 	end_time := c.GetString("end_time")
88 88
 	add_type, _ := c.GetInt64("add_type")
89 89
 	dry_type, _ := c.GetInt64("dry_type")
90
+	fmt.Println("dry_type")
91
+	fmt.Println(dry_type)
92
+
90 93
 	after_type, _ := c.GetInt64("after_type")
91 94
 	page, _ := c.GetInt64("page")
92 95
 	limit, _ := c.GetInt64("limit")

+ 3 - 0
enums/error_code.go Voir le fichier

@@ -285,6 +285,8 @@ const ( // ErrorCode
285 285
 	ErrorAdivceCode = 600000010
286 286
 
287 287
 	ErrorTimeCodeParamWrong = 600000012
288
+
289
+	ErrorCodeAuthWrong = 600000013
288 290
 )
289 291
 
290 292
 var ErrCodeMsgs = map[int]string{
@@ -549,6 +551,7 @@ var ErrCodeMsgs = map[int]string{
549 551
 	ErrorAdivceCode:                       "该患者已开药,请先删除药品或耗材",
550 552
 
551 553
 	ErrorTimeCodeParamWrong: "时间跨度不能超过一个月",
554
+	ErrorCodeAuthWrong:      "尚未实名认证,请先认证",
552 555
 }
553 556
 
554 557
 type SGJError struct {

+ 1 - 1
service/fapiao/qrcode.go Voir le fichier

@@ -15,7 +15,7 @@ func GetQRCode(config models.FapiaoConfig) (routerAddress string, postData map[s
15 15
 
16 16
 func GetQRStatus(auth_id string, config models.FapiaoConfig) (routerAddress string, postData map[string]interface{}) {
17 17
 
18
-	routerAddress = "tax-api/invoice/auth/query-qrcode-status/v1"
18
+	routerAddress = "/tax-api/invoice/auth/query-qrcode-status/v1"
19 19
 	postData = map[string]interface{}{
20 20
 		"taxpayer_id":   config.TaxpayerId,
21 21
 		"terminal_code": config.TerminalCode,

+ 1 - 1
service/fapiao/query.go Voir le fichier

@@ -21,7 +21,7 @@ func QueryStock(config models.FapiaoConfig) (routerAddress string, postData map[
21 21
 	postData = map[string]interface{}{
22 22
 		"taxpayer_id":       config.TaxpayerId,
23 23
 		"terminal_code":     config.TerminalCode,
24
-		"invoice_type_code": "007",
24
+		"invoice_type_code": "026",
25 25
 	}
26 26
 	return routerAddress, postData
27 27
 }

+ 446 - 183
service/statistis_qc_service.go Voir le fichier

@@ -1772,105 +1772,265 @@ type DialysisDataTwo struct {
1772 1772
 	WeightStatus      string   `json:"weight_status"`
1773 1773
 }
1774 1774
 
1775
-func GetNewDialysisWeightDetailTableTen(user_org_id int64, start_time int64, end_time int64, addType, dryType, afterType, page, limit int64) ([]DialysisDataTwo, int64, error) {
1775
+//func GetNewDialysisWeightDetailTableTen(user_org_id int64, start_time int64, end_time int64, addType, dryType, afterType, page, limit int64) ([]DialysisDataTwo, int64, error) {
1776
+//	offset := (page - 1) * limit
1777
+//	var dialysisData []DialysisDataTwo
1778
+//	var total int64
1779
+//	// 构建基本查询
1780
+//	query := readDb.Table("xt_assessment_before_dislysis b").
1781
+//		Select(`
1782
+//			p.dialysis_no AS dialysis_no,
1783
+//			p.name AS patient_name,
1784
+//			p.gender AS gender,
1785
+//			FLOOR((YEAR(CURDATE()) - SUBSTRING(p.id_card_no, 7, 4))) AS age,
1786
+//			b.assessment_date AS assessment_date,
1787
+//			b.dry_weight AS dry_weight,
1788
+//			b.weight_before AS weight_before,
1789
+//			a.weight_after AS weight_after,
1790
+//			(
1791
+//				SELECT a2.weight_after
1792
+//				FROM xt_assessment_after_dislysis a2
1793
+//				JOIN xt_assessment_before_dislysis b2
1794
+//				ON a2.patient_id = b2.patient_id
1795
+//				AND a2.assessment_date = b2.assessment_date
1796
+//				WHERE b2.patient_id = b.patient_id
1797
+//				AND b2.assessment_date < b.assessment_date
1798
+//				ORDER BY b2.assessment_date DESC LIMIT 1
1799
+//			) AS last_weight_after,
1800
+//			CASE
1801
+//				WHEN (
1802
+//					SELECT a2.weight_after
1803
+//					FROM xt_assessment_after_dislysis a2
1804
+//					JOIN xt_assessment_before_dislysis b2
1805
+//					ON a2.patient_id = b2.patient_id
1806
+//					AND a2.assessment_date = b2.assessment_date
1807
+//					WHERE b2.patient_id = b.patient_id
1808
+//					AND b2.assessment_date < b.assessment_date
1809
+//					ORDER BY b2.assessment_date DESC LIMIT 1
1810
+//				) IS NOT NULL
1811
+//				THEN (b.weight_before - (
1812
+//					SELECT a2.weight_after
1813
+//					FROM xt_assessment_after_dislysis a2
1814
+//					JOIN xt_assessment_before_dislysis b2
1815
+//					ON a2.patient_id = b2.patient_id
1816
+//					AND a2.assessment_date = b2.assessment_date
1817
+//					WHERE b2.patient_id = b.patient_id
1818
+//					AND b2.assessment_date < b.assessment_date
1819
+//					ORDER BY b2.assessment_date DESC LIMIT 1
1820
+//				)) / (
1821
+//					SELECT a2.weight_after
1822
+//					FROM xt_assessment_after_dislysis a2
1823
+//					JOIN xt_assessment_before_dislysis b2
1824
+//					ON a2.patient_id = b2.patient_id
1825
+//					AND a2.assessment_date = b2.assessment_date
1826
+//					WHERE b2.patient_id = b.patient_id
1827
+//					AND b2.assessment_date < b.assessment_date
1828
+//					ORDER BY b2.assessment_date DESC LIMIT 1
1829
+//				)
1830
+//				ELSE NULL
1831
+//			END AS weight_add,
1832
+//			CASE
1833
+//				WHEN b.dry_weight IS NOT NULL THEN
1834
+//					CASE
1835
+//						WHEN b.dry_weight < 40 THEN '小于40'
1836
+//						WHEN b.dry_weight BETWEEN 40 AND 50 THEN '40~50'
1837
+//						WHEN b.dry_weight BETWEEN 50 AND 60 THEN '50~60'
1838
+//						WHEN b.dry_weight BETWEEN 60 AND 70 THEN '60~70'
1839
+//						WHEN b.dry_weight > 70 THEN '大于70'
1840
+//					END
1841
+//				ELSE '其他'
1842
+//			END AS dry_weight_category,
1843
+//			CASE
1844
+//				WHEN b.dry_weight IS NOT NULL THEN
1845
+//					CASE
1846
+//						WHEN ABS(a.weight_after - b.dry_weight) <= 0.3 THEN '达标'
1847
+//						ELSE '不达标'
1848
+//					END
1849
+//				ELSE '其他'
1850
+//			END AS weight_status
1851
+//		`).
1852
+//		Joins("JOIN xt_patients p ON p.id = b.patient_id").
1853
+//		Joins("JOIN xt_assessment_after_dislysis a ON p.id = a.patient_id AND b.assessment_date = a.assessment_date AND a.status = 1").
1854
+//		Where("b.user_org_id = ?", user_org_id).
1855
+//		Where("b.assessment_date >= ?", start_time).
1856
+//		Where("b.assessment_date <= ?", end_time).
1857
+//		Where("b.status = ?", 1)
1858
+//
1859
+//	fmt.Println("dry_type")
1860
+//	fmt.Println(dryType)
1861
+//	switch dryType {
1862
+//	case 1:
1863
+//		query.Where("dry_weight_category = '小于40'")
1864
+//	case 2:
1865
+//		query.Where("dry_weight_category = '40~50'")
1866
+//	case 3:
1867
+//		query.Where("dry_weight_category = '50~60'")
1868
+//	case 4:
1869
+//		query.Where("dry_weight_category = '60~70'")
1870
+//	case 5:
1871
+//		query.Where("dry_weight_category = '大于70'")
1872
+//	}
1873
+//
1874
+//	// 根据传入的 add_type 值动态构建条件
1875
+//	addTypeCondition(query, addType)
1876
+//	// 根据传入的 dry_type 值动态构建条件
1877
+//	//fmt.Println("dry_type")
1878
+//	//fmt.Println(dryType)
1879
+//
1880
+//	//dryTypeCondition(query, dryType)
1881
+//	// 根据传入的 after_type 值动态构建条件
1882
+//	afterTypeCondition(query, afterType)
1883
+//	// 获取总记录数
1884
+//	if err := query.Count(&total).Error; err != nil {
1885
+//		return nil, 0, fmt.Errorf("count query failed: %v", err)
1886
+//	}
1887
+//	// 获取分页数据
1888
+//	rows, err := query.Order("p.id, b.assessment_date").Offset(int(offset)).Limit(int(limit)).Rows()
1889
+//	if err != nil {
1890
+//		return nil, 0, fmt.Errorf("pagination query failed: %v", err)
1891
+//	}
1892
+//	defer rows.Close()
1893
+//	// 处理结果集
1894
+//	for rows.Next() {
1895
+//		var data DialysisDataTwo
1896
+//		if err := rows.Scan(
1897
+//			&data.DialysisNo,
1898
+//			&data.PatientName,
1899
+//			&data.Gender,
1900
+//			&data.Age,
1901
+//			&data.AssessmentDate,
1902
+//			&data.DryWeight,
1903
+//			&data.WeightBefore,
1904
+//			&data.WeightAfter,
1905
+//			&data.LastWeightAfter,
1906
+//			&data.WeightAdd,
1907
+//			&data.DryWeightCategory,
1908
+//			&data.WeightStatus,
1909
+//		); err != nil {
1910
+//			return nil, 0, fmt.Errorf("row scan failed: %v", err)
1911
+//		}
1912
+//		// 将每一行结果追加到切片中
1913
+//		dialysisData = append(dialysisData, data)
1914
+//	}
1915
+//	return dialysisData, total, nil
1916
+//}
1917
+
1918
+func GetNewDialysisWeightDetailTableTen(
1919
+	user_org_id int64,
1920
+	start_time int64,
1921
+	end_time int64,
1922
+	addType, dryType, afterType, page, limit int64,
1923
+) ([]DialysisDataTwo, int64, error) {
1776 1924
 	offset := (page - 1) * limit
1777 1925
 	var dialysisData []DialysisDataTwo
1778 1926
 	var total int64
1927
+
1779 1928
 	// 构建基本查询
1780 1929
 	query := readDb.Table("xt_assessment_before_dislysis b").
1781 1930
 		Select(`
1782
-			p.dialysis_no AS dialysis_no, 
1783
-			p.name AS patient_name, 
1784
-			p.gender AS gender, 
1785
-			FLOOR((YEAR(CURDATE()) - SUBSTRING(p.id_card_no, 7, 4))) AS age,
1786
-			b.assessment_date AS assessment_date, 
1787
-			b.dry_weight AS dry_weight, 
1788
-			b.weight_before AS weight_before, 
1789
-			a.weight_after AS weight_after,
1790
-			(
1791
-				SELECT a2.weight_after 
1792
-				FROM xt_assessment_after_dislysis a2
1793
-				JOIN xt_assessment_before_dislysis b2 
1794
-				ON a2.patient_id = b2.patient_id 
1795
-				AND a2.assessment_date = b2.assessment_date
1796
-				WHERE b2.patient_id = b.patient_id 
1797
-				AND b2.assessment_date < b.assessment_date
1798
-				ORDER BY b2.assessment_date DESC LIMIT 1
1799
-			) AS last_weight_after,
1800
-			CASE 
1801
-				WHEN (
1802
-					SELECT a2.weight_after 
1803
-					FROM xt_assessment_after_dislysis a2
1804
-					JOIN xt_assessment_before_dislysis b2 
1805
-					ON a2.patient_id = b2.patient_id 
1806
-					AND a2.assessment_date = b2.assessment_date
1807
-					WHERE b2.patient_id = b.patient_id 
1808
-					AND b2.assessment_date < b.assessment_date
1809
-					ORDER BY b2.assessment_date DESC LIMIT 1
1810
-				) IS NOT NULL
1811
-				THEN (b.weight_before - (
1812
-					SELECT a2.weight_after 
1813
-					FROM xt_assessment_after_dislysis a2
1814
-					JOIN xt_assessment_before_dislysis b2 
1815
-					ON a2.patient_id = b2.patient_id 
1816
-					AND a2.assessment_date = b2.assessment_date
1817
-					WHERE b2.patient_id = b.patient_id 
1818
-					AND b2.assessment_date < b.assessment_date
1819
-					ORDER BY b2.assessment_date DESC LIMIT 1
1820
-				)) / (
1821
-					SELECT a2.weight_after 
1822
-					FROM xt_assessment_after_dislysis a2
1823
-					JOIN xt_assessment_before_dislysis b2 
1824
-					ON a2.patient_id = b2.patient_id 
1825
-					AND a2.assessment_date = b2.assessment_date
1826
-					WHERE b2.patient_id = b.patient_id 
1827
-					AND b2.assessment_date < b.assessment_date
1828
-					ORDER BY b2.assessment_date DESC LIMIT 1
1829
-				)
1830
-				ELSE NULL
1831
-			END AS weight_add,
1832
-			CASE 
1833
-				WHEN b.dry_weight IS NOT NULL THEN 
1834
-					CASE 
1835
-						WHEN b.dry_weight < 40 THEN '小于40'
1836
-						WHEN b.dry_weight BETWEEN 40 AND 50 THEN '40~50'
1837
-						WHEN b.dry_weight BETWEEN 50 AND 60 THEN '50~60'
1838
-						WHEN b.dry_weight BETWEEN 60 AND 70 THEN '60~70'
1839
-						WHEN b.dry_weight > 70 THEN '大于70'
1840
-					END
1841
-				ELSE '其他'
1842
-			END AS dry_weight_category,
1843
-			CASE 
1844
-				WHEN b.dry_weight IS NOT NULL THEN 
1845
-					CASE 
1846
-						WHEN ABS(a.weight_after - b.dry_weight) <= 0.3 THEN '达标'
1847
-						ELSE '不达标'
1848
-					END
1849
-				ELSE '其他'
1850
-			END AS weight_status
1851
-		`).
1931
+            p.dialysis_no AS dialysis_no, 
1932
+            p.name AS patient_name, 
1933
+            p.gender AS gender, 
1934
+            FLOOR((YEAR(CURDATE()) - SUBSTRING(p.id_card_no, 7, 4))) AS age,
1935
+            b.assessment_date AS assessment_date, 
1936
+            b.dry_weight AS dry_weight, 
1937
+            b.weight_before AS weight_before, 
1938
+            a.weight_after AS weight_after,
1939
+            (
1940
+                SELECT a2.weight_after 
1941
+                FROM xt_assessment_after_dislysis a2
1942
+                JOIN xt_assessment_before_dislysis b2 
1943
+                ON a2.patient_id = b2.patient_id 
1944
+                AND a2.assessment_date = b2.assessment_date
1945
+                WHERE b2.patient_id = b.patient_id 
1946
+                AND b2.assessment_date < b.assessment_date
1947
+                ORDER BY b2.assessment_date DESC LIMIT 1
1948
+            ) AS last_weight_after,
1949
+            CASE 
1950
+                WHEN (
1951
+                    SELECT a2.weight_after 
1952
+                    FROM xt_assessment_after_dislysis a2
1953
+                    JOIN xt_assessment_before_dislysis b2 
1954
+                    ON a2.patient_id = b2.patient_id 
1955
+                    AND a2.assessment_date = b2.assessment_date
1956
+                    WHERE b2.patient_id = b.patient_id 
1957
+                    AND b2.assessment_date < b.assessment_date
1958
+                    ORDER BY b2.assessment_date DESC LIMIT 1
1959
+                ) IS NOT NULL
1960
+                THEN (b.weight_before - (
1961
+                    SELECT a2.weight_after 
1962
+                    FROM xt_assessment_after_dislysis a2
1963
+                    JOIN xt_assessment_before_dislysis b2 
1964
+                    ON a2.patient_id = b2.patient_id 
1965
+                    AND a2.assessment_date = b2.assessment_date
1966
+                    WHERE b2.patient_id = b.patient_id 
1967
+                    AND b2.assessment_date < b.assessment_date
1968
+                    ORDER BY b2.assessment_date DESC LIMIT 1
1969
+                )) / (
1970
+                    SELECT a2.weight_after 
1971
+                    FROM xt_assessment_after_dislysis a2
1972
+                    JOIN xt_assessment_before_dislysis b2 
1973
+                    ON a2.patient_id = b2.patient_id 
1974
+                    AND a2.assessment_date = b2.assessment_date
1975
+                    WHERE b2.patient_id = b.patient_id 
1976
+                    AND b2.assessment_date < b.assessment_date
1977
+                    ORDER BY b2.assessment_date DESC LIMIT 1
1978
+                )
1979
+                ELSE NULL
1980
+            END AS weight_add,
1981
+            CASE 
1982
+                WHEN b.dry_weight IS NOT NULL THEN 
1983
+                    CASE 
1984
+                        WHEN ABS(a.weight_after - b.dry_weight) <= 0.3 THEN '达标'
1985
+                        ELSE '不达标'
1986
+                    END
1987
+                ELSE '其他'
1988
+            END AS weight_status
1989
+        `).
1852 1990
 		Joins("JOIN xt_patients p ON p.id = b.patient_id").
1853 1991
 		Joins("JOIN xt_assessment_after_dislysis a ON p.id = a.patient_id AND b.assessment_date = a.assessment_date AND a.status = 1").
1854 1992
 		Where("b.user_org_id = ?", user_org_id).
1855 1993
 		Where("b.assessment_date >= ?", start_time).
1856 1994
 		Where("b.assessment_date <= ?", end_time).
1857 1995
 		Where("b.status = ?", 1)
1858
-	// 根据传入的 add_type 值动态构建条件
1859
-	addTypeCondition(query, addType)
1996
+
1860 1997
 	// 根据传入的 dry_type 值动态构建条件
1861
-	dryTypeCondition(query, dryType)
1862
-	// 根据传入的 after_type 值动态构建条件
1998
+	fmt.Println("00=-----11111")
1999
+	fmt.Println(dryType)
2000
+
2001
+	switch dryType {
2002
+	case 1:
2003
+		fmt.Println("00=-----11111")
2004
+		fmt.Println(dryType)
2005
+		query = query.Where("b.dry_weight < ?", 40)
2006
+	case 2:
2007
+		query = query.Where("b.dry_weight BETWEEN ? AND ?", 40, 50)
2008
+	case 3:
2009
+		query = query.Where("b.dry_weight BETWEEN ? AND ?", 50, 60)
2010
+	case 4:
2011
+		query = query.Where("b.dry_weight BETWEEN ? AND ?", 60, 70)
2012
+	case 5:
2013
+		query = query.Where("b.dry_weight > ?", 70)
2014
+	}
2015
+
2016
+	//// 根据传入的 add_type 值动态构建条件
2017
+	addTypeCondition(query, addType)
2018
+	//
2019
+	//// 根据传入的 after_type 值动态构建条件
1863 2020
 	afterTypeCondition(query, afterType)
2021
+
1864 2022
 	// 获取总记录数
1865 2023
 	if err := query.Count(&total).Error; err != nil {
1866 2024
 		return nil, 0, fmt.Errorf("count query failed: %v", err)
1867 2025
 	}
2026
+
1868 2027
 	// 获取分页数据
1869 2028
 	rows, err := query.Order("p.id, b.assessment_date").Offset(int(offset)).Limit(int(limit)).Rows()
1870 2029
 	if err != nil {
1871 2030
 		return nil, 0, fmt.Errorf("pagination query failed: %v", err)
1872 2031
 	}
1873 2032
 	defer rows.Close()
2033
+
1874 2034
 	// 处理结果集
1875 2035
 	for rows.Next() {
1876 2036
 		var data DialysisDataTwo
@@ -1885,7 +2045,6 @@ func GetNewDialysisWeightDetailTableTen(user_org_id int64, start_time int64, end
1885 2045
 			&data.WeightAfter,
1886 2046
 			&data.LastWeightAfter,
1887 2047
 			&data.WeightAdd,
1888
-			&data.DryWeightCategory,
1889 2048
 			&data.WeightStatus,
1890 2049
 		); err != nil {
1891 2050
 			return nil, 0, fmt.Errorf("row scan failed: %v", err)
@@ -1900,41 +2059,30 @@ func GetNewDialysisWeightDetailTableTen(user_org_id int64, start_time int64, end
1900 2059
 func addTypeCondition(query *gorm.DB, addType int64) {
1901 2060
 	switch addType {
1902 2061
 	case 1:
1903
-		query.Where("weight_add <= 0.03")
2062
+		query = query.Where("weight_add <= 0.03")
1904 2063
 	case 2:
1905
-		query.Where("weight_add > 0.03 AND weight_add < 0.05")
2064
+		query = query.Where("weight_add > 0.03 AND weight_add < 0.05")
1906 2065
 	case 3:
1907
-		query.Where("weight_add >= 0.05")
2066
+		query = query.Where("weight_add >= 0.05")
1908 2067
 	case 4:
1909
-		query.Where("weight_add IS NULL")
2068
+		query = query.Where("weight_add IS NULL")
1910 2069
 	}
1911 2070
 }
1912 2071
 
1913 2072
 // dryType 条件处理
1914 2073
 func dryTypeCondition(query *gorm.DB, dryType int64) {
1915
-	switch dryType {
1916
-	case 1:
1917
-		query.Where("dry_weight_category = '小于40'")
1918
-	case 2:
1919
-		query.Where("dry_weight_category = '40~50'")
1920
-	case 3:
1921
-		query.Where("dry_weight_category = '50~60'")
1922
-	case 4:
1923
-		query.Where("dry_weight_category = '60~70'")
1924
-	case 5:
1925
-		query.Where("dry_weight_category = '大于70'")
1926
-	}
2074
+
1927 2075
 }
1928 2076
 
1929 2077
 // afterType 条件处理
1930 2078
 func afterTypeCondition(query *gorm.DB, afterType int64) {
1931 2079
 	switch afterType {
1932 2080
 	case 1:
1933
-		query.Where("weight_status = '达标'")
2081
+		query = query.Where("weight_status = '达标'")
1934 2082
 	case 2:
1935
-		query.Where("weight_status = '不达标'")
2083
+		query = query.Where("weight_status = '不达标'")
1936 2084
 	case 3:
1937
-		query.Where("weight_status = '其他'")
2085
+		query = query.Where("weight_status = '其他'")
1938 2086
 	}
1939 2087
 }
1940 2088
 
@@ -1953,102 +2101,217 @@ type DialysisDataThree struct {
1953 2101
 	BPStatus            string  `json:"血压达标状态"`
1954 2102
 }
1955 2103
 
1956
-func GetNewDialysisBPDetailTableTen(user_org_id int64, start_time int64, end_time int64, addType, page, limit int64) ([]DialysisDataThree, int64, error) {
2104
+//	func GetNewDialysisBPDetailTableTen(user_org_id int64, start_time int64, end_time int64, addType, page, limit int64) ([]DialysisDataThree, int64, error) {
2105
+//		offset := (page - 1) * limit
2106
+//		var total int64
2107
+//		var results []DialysisDataThree
2108
+//		// SQL 查询
2109
+//		query := `
2110
+//			SELECT
2111
+//				p.dialysis_no AS 透析号,
2112
+//				p.name AS 患者姓名,
2113
+//				p.gender AS 性别,
2114
+//				FLOOR((YEAR(CURDATE()) - SUBSTRING(p.id_card_no, 7, 4))) AS 年龄,
2115
+//				b.assessment_date AS 透析日期,
2116
+//				b.dry_weight AS 干体重,
2117
+//				CONCAT(b.systolic_blood_pressure, '/', b.diastolic_blood_pressure) AS 透前血压,
2118
+//				CONCAT(a.systolic_blood_pressure, '/', a.diastolic_blood_pressure) AS 透后血压,
2119
+//				GROUP_CONCAT(CONCAT(m.systolic_blood_pressure, '/', m.diastolic_blood_pressure) ORDER BY m.monitoring_date ASC SEPARATOR ',') AS 监测记录血压,
2120
+//				(SELECT mr.ultrafiltration_rate
2121
+//				 FROM xt_monitoring_record mr
2122
+//				 WHERE mr.patient_id = p.id AND mr.monitoring_date = b.assessment_date
2123
+//				 ORDER BY mr.operate_time DESC
2124
+//				 LIMIT 1) AS 超滤率,
2125
+//				(SELECT mr.ultrafiltration_volume
2126
+//				 FROM xt_monitoring_record mr
2127
+//				 WHERE mr.patient_id = p.id AND mr.monitoring_date = b.assessment_date
2128
+//				 ORDER BY mr.operate_time DESC
2129
+//				 LIMIT 1) AS 超滤总量,
2130
+//				CASE
2131
+//					WHEN FLOOR((YEAR(CURDATE()) - SUBSTRING(p.id_card_no, 7, 4))) < 60 THEN
2132
+//						CASE
2133
+//							WHEN b.systolic_blood_pressure < 140 OR b.diastolic_blood_pressure < 90 THEN '达标'
2134
+//							ELSE '不达标'
2135
+//						END
2136
+//					WHEN FLOOR((YEAR(CURDATE()) - SUBSTRING(p.id_card_no, 7, 4))) >= 60 THEN
2137
+//						CASE
2138
+//							WHEN b.systolic_blood_pressure < 160 OR b.diastolic_blood_pressure < 90 THEN '达标'
2139
+//							ELSE '不达标'
2140
+//						END
2141
+//				END AS 血压达标状态
2142
+//			FROM
2143
+//				xt_patients p
2144
+//			JOIN
2145
+//				xt_assessment_before_dislysis b ON p.id = b.patient_id
2146
+//			JOIN
2147
+//				xt_assessment_after_dislysis a ON p.id = a.patient_id AND b.assessment_date = a.assessment_date
2148
+//			JOIN
2149
+//				xt_monitoring_record m ON p.id = m.patient_id AND m.monitoring_date = b.assessment_date
2150
+//			WHERE
2151
+//				b.user_org_id = ?
2152
+//				AND b.assessment_date >= ?
2153
+//				AND b.assessment_date <= ?
2154
+//				AND (
2155
+//					(? = 1 AND CASE
2156
+//						WHEN FLOOR((YEAR(CURDATE()) - SUBSTRING(p.id_card_no, 7, 4))) < 60 THEN
2157
+//							CASE
2158
+//								WHEN b.systolic_blood_pressure < 140 OR b.diastolic_blood_pressure < 90 THEN 1
2159
+//								ELSE 0
2160
+//							END
2161
+//						WHEN FLOOR((YEAR(CURDATE()) - SUBSTRING(p.id_card_no, 7, 4))) >= 60 THEN
2162
+//							CASE
2163
+//								WHEN b.systolic_blood_pressure < 160 OR b.diastolic_blood_pressure < 90 THEN 1
2164
+//								ELSE 0
2165
+//							END
2166
+//					END = 1)
2167
+//					OR
2168
+//					(? = 2 AND CASE
2169
+//						WHEN FLOOR((YEAR(CURDATE()) - SUBSTRING(p.id_card_no, 7, 4))) < 60 THEN
2170
+//							CASE
2171
+//								WHEN b.systolic_blood_pressure >= 140 AND b.diastolic_blood_pressure >= 90 THEN 1
2172
+//								ELSE 0
2173
+//							END
2174
+//						WHEN FLOOR((YEAR(CURDATE()) - SUBSTRING(p.id_card_no, 7, 4))) >= 60 THEN
2175
+//							CASE
2176
+//								WHEN b.systolic_blood_pressure >= 160 AND b.diastolic_blood_pressure >= 90 THEN 1
2177
+//								ELSE 0
2178
+//							END
2179
+//					END = 1)
2180
+//				)
2181
+//			GROUP BY
2182
+//				p.id, b.assessment_date
2183
+//			ORDER BY
2184
+//				p.id, b.assessment_date
2185
+//			LIMIT ? OFFSET ?;
2186
+//		`
2187
+//
2188
+//		// 计算总数
2189
+//		countQuery := `
2190
+//			SELECT COUNT(*)
2191
+//			FROM
2192
+//				xt_patients p
2193
+//			JOIN
2194
+//				xt_assessment_before_dislysis b ON p.id = b.patient_id
2195
+//			WHERE
2196
+//				b.user_org_id = ?
2197
+//				AND b.assessment_date >= ?
2198
+//				AND b.assessment_date <= ?
2199
+//		`
2200
+//
2201
+//		// 执行统计查询
2202
+//		if err := readDb.Raw(countQuery, user_org_id, start_time, end_time).Scan(&total).Error; err != nil {
2203
+//			return nil, 0, fmt.Errorf("error calculating total count: %v", err)
2204
+//		}
2205
+//
2206
+//		// 执行数据查询
2207
+//		if err := readDb.Raw(query, user_org_id, start_time, end_time, addType, addType, limit, offset).Scan(&results).Error; err != nil {
2208
+//			return nil, 0, fmt.Errorf("error executing query: %v", err)
2209
+//		}
2210
+//
2211
+//		return results, total, nil
2212
+//	}
2213
+func GetNewDialysisBPDetailTableTen(
2214
+	user_org_id int64,
2215
+	start_time int64,
2216
+	end_time int64,
2217
+	addType, page, limit int64,
2218
+) ([]DialysisDataThree, int64, error) {
1957 2219
 	offset := (page - 1) * limit
1958 2220
 	var total int64
1959 2221
 	var results []DialysisDataThree
2222
+
1960 2223
 	// SQL 查询
1961 2224
 	query := `
1962
-		SELECT
1963
-			p.dialysis_no AS 透析号,
1964
-			p.name AS 患者姓名,
1965
-			p.gender AS 性别,
1966
-			FLOOR((YEAR(CURDATE()) - SUBSTRING(p.id_card_no, 7, 4))) AS 年龄,
1967
-			b.assessment_date AS 透析日期,
1968
-			b.dry_weight AS 干体重,
1969
-			CONCAT(b.systolic_blood_pressure, '/', b.diastolic_blood_pressure) AS 透前血压,
1970
-			CONCAT(a.systolic_blood_pressure, '/', a.diastolic_blood_pressure) AS 透后血压,
1971
-			GROUP_CONCAT(CONCAT(m.systolic_blood_pressure, '/', m.diastolic_blood_pressure) ORDER BY m.monitoring_date ASC SEPARATOR ',') AS 监测记录血压,
1972
-			(SELECT mr.ultrafiltration_rate
1973
-			 FROM xt_monitoring_record mr
1974
-			 WHERE mr.patient_id = p.id AND mr.monitoring_date = b.assessment_date
1975
-			 ORDER BY mr.operate_time DESC
1976
-			 LIMIT 1) AS 超滤率,
1977
-			(SELECT mr.ultrafiltration_volume
1978
-			 FROM xt_monitoring_record mr
1979
-			 WHERE mr.patient_id = p.id AND mr.monitoring_date = b.assessment_date
1980
-			 ORDER BY mr.operate_time DESC
1981
-			 LIMIT 1) AS 超滤总量,
1982
-			CASE 
1983
-				WHEN FLOOR((YEAR(CURDATE()) - SUBSTRING(p.id_card_no, 7, 4))) < 60 THEN
1984
-					CASE 
1985
-						WHEN b.systolic_blood_pressure < 140 OR b.diastolic_blood_pressure < 90 THEN '达标'
1986
-						ELSE '不达标'
1987
-					END
1988
-				WHEN FLOOR((YEAR(CURDATE()) - SUBSTRING(p.id_card_no, 7, 4))) >= 60 THEN
1989
-					CASE 
1990
-						WHEN b.systolic_blood_pressure < 160 OR b.diastolic_blood_pressure < 90 THEN '达标'
1991
-						ELSE '不达标'
1992
-					END
1993
-			END AS 血压达标状态
1994
-		FROM
1995
-			xt_patients p
1996
-		JOIN
1997
-			xt_assessment_before_dislysis b ON p.id = b.patient_id
1998
-		JOIN
1999
-			xt_assessment_after_dislysis a ON p.id = a.patient_id AND b.assessment_date = a.assessment_date
2000
-		JOIN
2001
-			xt_monitoring_record m ON p.id = m.patient_id AND m.monitoring_date = b.assessment_date
2002
-		WHERE
2003
-			b.user_org_id = ?
2004
-			AND b.assessment_date >= ?
2005
-			AND b.assessment_date <= ?
2006
-			AND (
2007
-				(? = 1 AND CASE 
2008
-					WHEN FLOOR((YEAR(CURDATE()) - SUBSTRING(p.id_card_no, 7, 4))) < 60 THEN
2009
-						CASE 
2010
-							WHEN b.systolic_blood_pressure < 140 OR b.diastolic_blood_pressure < 90 THEN 1
2011
-							ELSE 0
2012
-						END
2013
-					WHEN FLOOR((YEAR(CURDATE()) - SUBSTRING(p.id_card_no, 7, 4))) >= 60 THEN
2014
-						CASE 
2015
-							WHEN b.systolic_blood_pressure < 160 OR b.diastolic_blood_pressure < 90 THEN 1
2016
-							ELSE 0
2017
-						END
2018
-				END = 1)
2019
-				OR
2020
-				(? = 2 AND CASE 
2021
-					WHEN FLOOR((YEAR(CURDATE()) - SUBSTRING(p.id_card_no, 7, 4))) < 60 THEN
2022
-						CASE 
2023
-							WHEN b.systolic_blood_pressure >= 140 AND b.diastolic_blood_pressure >= 90 THEN 1
2024
-							ELSE 0
2025
-						END
2026
-					WHEN FLOOR((YEAR(CURDATE()) - SUBSTRING(p.id_card_no, 7, 4))) >= 60 THEN
2027
-						CASE 
2028
-							WHEN b.systolic_blood_pressure >= 160 AND b.diastolic_blood_pressure >= 90 THEN 1
2029
-							ELSE 0
2030
-						END
2031
-				END = 1)
2032
-			)
2033
-		GROUP BY
2034
-			p.id, b.assessment_date
2035
-		ORDER BY
2036
-			p.id, b.assessment_date
2037
-		LIMIT ? OFFSET ?;
2038
-	`
2225
+        SELECT
2226
+            p.dialysis_no AS DialysisNo,
2227
+            p.name AS PatientName,
2228
+            p.gender AS Gender,
2229
+            FLOOR((YEAR(CURDATE()) - SUBSTRING(p.id_card_no, 7, 4))) AS Age,
2230
+            b.assessment_date AS AssessmentDate,
2231
+            b.dry_weight AS DryWeight,
2232
+            CONCAT(b.systolic_blood_pressure, '/', b.diastolic_blood_pressure) AS PreDialysisBP,
2233
+            CONCAT(a.systolic_blood_pressure, '/', a.diastolic_blood_pressure) AS PostDialysisBP,
2234
+            GROUP_CONCAT(CONCAT(m.systolic_blood_pressure, '/', m.diastolic_blood_pressure) ORDER BY m.monitoring_date ASC SEPARATOR ',') AS MonitoringBP,
2235
+            (SELECT mr.ultrafiltration_rate
2236
+             FROM xt_monitoring_record mr
2237
+             WHERE mr.patient_id = p.id AND mr.monitoring_date = b.assessment_date
2238
+             ORDER BY mr.operate_time DESC
2239
+             LIMIT 1) AS UltrafiltrationRate,
2240
+            (SELECT mr.ultrafiltration_volume
2241
+             FROM xt_monitoring_record mr
2242
+             WHERE mr.patient_id = p.id AND mr.monitoring_date = b.assessment_date
2243
+             ORDER BY mr.operate_time DESC
2244
+             LIMIT 1) AS UltrafiltrationVol,
2245
+            CASE 
2246
+                WHEN FLOOR((YEAR(CURDATE()) - SUBSTRING(p.id_card_no, 7, 4))) < 60 THEN
2247
+                    CASE 
2248
+                        WHEN b.systolic_blood_pressure < 140 OR b.diastolic_blood_pressure < 90 THEN '达标'
2249
+                        ELSE '不达标'
2250
+                    END
2251
+                WHEN FLOOR((YEAR(CURDATE()) - SUBSTRING(p.id_card_no, 7, 4))) >= 60 THEN
2252
+                    CASE 
2253
+                        WHEN b.systolic_blood_pressure < 160 OR b.diastolic_blood_pressure < 90 THEN '达标'
2254
+                        ELSE '不达标'
2255
+                    END
2256
+            END AS BPStatus
2257
+        FROM
2258
+            xt_patients p
2259
+        JOIN
2260
+            xt_assessment_before_dislysis b ON p.id = b.patient_id
2261
+        JOIN
2262
+            xt_assessment_after_dislysis a ON p.id = a.patient_id AND b.assessment_date = a.assessment_date
2263
+        JOIN
2264
+            xt_monitoring_record m ON p.id = m.patient_id AND m.monitoring_date = b.assessment_date
2265
+        WHERE
2266
+            b.user_org_id = ?
2267
+            AND b.assessment_date >= ?
2268
+            AND b.assessment_date <= ?
2269
+            AND (
2270
+                (? = 1 AND CASE 
2271
+                    WHEN FLOOR((YEAR(CURDATE()) - SUBSTRING(p.id_card_no, 7, 4))) < 60 THEN
2272
+                        CASE 
2273
+                            WHEN b.systolic_blood_pressure < 140 OR b.diastolic_blood_pressure < 90 THEN 1
2274
+                            ELSE 0
2275
+                        END
2276
+                    WHEN FLOOR((YEAR(CURDATE()) - SUBSTRING(p.id_card_no, 7, 4))) >= 60 THEN
2277
+                        CASE 
2278
+                            WHEN b.systolic_blood_pressure < 160 OR b.diastolic_blood_pressure < 90 THEN 1
2279
+                            ELSE 0
2280
+                        END
2281
+                END = 1)
2282
+                OR
2283
+                (? = 2 AND CASE 
2284
+                    WHEN FLOOR((YEAR(CURDATE()) - SUBSTRING(p.id_card_no, 7, 4))) < 60 THEN
2285
+                        CASE 
2286
+                            WHEN b.systolic_blood_pressure >= 140 AND b.diastolic_blood_pressure >= 90 THEN 1
2287
+                            ELSE 0
2288
+                        END
2289
+                    WHEN FLOOR((YEAR(CURDATE()) - SUBSTRING(p.id_card_no, 7, 4))) >= 60 THEN
2290
+                        CASE 
2291
+                            WHEN b.systolic_blood_pressure >= 160 AND b.diastolic_blood_pressure >= 90 THEN 1
2292
+                            ELSE 0
2293
+                        END
2294
+                END = 1)
2295
+            )
2296
+        GROUP BY
2297
+            p.id, b.assessment_date
2298
+        ORDER BY
2299
+            p.id, b.assessment_date
2300
+        LIMIT ? OFFSET ?;
2301
+    `
2039 2302
 
2040 2303
 	// 计算总数
2041 2304
 	countQuery := `
2042
-		SELECT COUNT(*)
2043
-		FROM
2044
-			xt_patients p
2045
-		JOIN
2046
-			xt_assessment_before_dislysis b ON p.id = b.patient_id
2047
-		WHERE
2048
-			b.user_org_id = ?
2049
-			AND b.assessment_date >= ?
2050
-			AND b.assessment_date <= ?
2051
-	`
2305
+        SELECT COUNT(*)
2306
+        FROM
2307
+            xt_patients p
2308
+        JOIN
2309
+            xt_assessment_before_dislysis b ON p.id = b.patient_id
2310
+        WHERE
2311
+            b.user_org_id = ?
2312
+            AND b.assessment_date >= ?
2313
+            AND b.assessment_date <= ?
2314
+    `
2052 2315
 
2053 2316
 	// 执行统计查询
2054 2317
 	if err := readDb.Raw(countQuery, user_org_id, start_time, end_time).Scan(&total).Error; err != nil {