csx vor 2 Jahren
Ursprung
Commit
2277d92f31
4 geänderte Dateien mit 461 neuen und 95 gelöschten Zeilen
  1. 4 3
      main.go
  2. 1 0
      models/lis_model.go
  3. 423 91
      service/ystx_service.go
  4. 33 1
      utils/log.go

+ 4 - 3
main.go Datei anzeigen

@@ -8,14 +8,15 @@ import (
8 8
 
9 9
 func init() {
10 10
 	service.ConnectDB()
11
-	service.ConnectMSDB2()
12
-	service.ConnectMSDB()
11
+	//service.ConnectMSDB2()
12
+	//service.ConnectMSDB()
13 13
 }
14 14
 
15 15
 func main() {
16 16
 	//service.BeginAutoSyncLis()
17 17
 	//service.GetDataInsertDB(10138)
18 18
 	//service.GetResultDataInsertDB(10138)
19
-	service.GetSHResultDataInsertDB(10215)
19
+	//service.GetSHResultDataInsertDB(10215)
20
+	service.Synctfyz()
20 21
 	beego.Run()
21 22
 }

+ 1 - 0
models/lis_model.go Datei anzeigen

@@ -356,6 +356,7 @@ type XtDoctorAdvice struct {
356 356
 	Modifier              int64   `gorm:"column:modifier" json:"modifier" form:"modifier"`
357 357
 	SyncAdviceId          int64   `gorm:"column:sync_advice_id" json:"sync_advice_id" form:"sync_advice_id"`
358 358
 	IsSync                int64   `gorm:"column:is_sync" json:"is_sync" form:"is_sync"`
359
+	SyncId                string  `gorm:"column:sync_id" json:"sync_id" form:"sync_id"`
359 360
 }
360 361
 
361 362
 func (XtDoctorAdvice) TableName() string {

+ 423 - 91
service/ystx_service.go Datei anzeigen

@@ -4,18 +4,91 @@ import (
4 4
 	"IC/models"
5 5
 	"IC/utils"
6 6
 	_ "IC/utils"
7
+	"bytes"
7 8
 	"encoding/json"
8 9
 	_ "encoding/json"
9 10
 	"encoding/xml"
11
+	"fmt"
10 12
 	_ "fmt"
11 13
 	"github.com/astaxie/beego/httplib"
12 14
 	_ "github.com/jinzhu/gorm"
15
+	"io/ioutil"
16
+	"net/http"
13 17
 	"net/url"
18
+	"os"
14 19
 	"strconv"
15 20
 	"strings"
16 21
 	"time"
17 22
 )
18 23
 
24
+type RequestResult struct {
25
+	Msg    string `json:"msg"`
26
+	Result []struct {
27
+		AdviceId               int64   `json:"医嘱ID"`
28
+		OtherId                int64   `json:"相关ID"`
29
+		Source                 int     `json:"病人来源"`
30
+		PatientId              int64   `json:"病人ID"`
31
+		JzId                   int64   `json:"就诊ID"`
32
+		BabyId                 int     `json:"婴儿ID"`
33
+		PatientDepartmentId    int     `json:"病人科室ID"`
34
+		OrderId                int     `json:"次序"`
35
+		AdviceStatus           int     `json:"医嘱状态"`
36
+		AdviceType             int     `json:"医嘱类型"`
37
+		DiagnosisType          string  `json:"诊疗类型"`
38
+		DiagnosisItemId        int     `json:"诊疗项目ID"`
39
+		CheckMethd             string  `json:"检查方法"`
40
+		ChargeItemId           int     `json:"收费项目ID"`
41
+		Day                    int     `json:"天数"`
42
+		JiLiang                float64 `json:"剂量"`
43
+		YongLiang              string  `json:"用量"`
44
+		DanLiang               float64 `json:"单量"`
45
+		Shuliang               float64 `json:"数量"`
46
+		Advice                 string  `json:"医嘱"`
47
+		GeiYaoTuJing           string  `json:"给药途径"`
48
+		ShuoMing               string  `json:"说明"`
49
+		ZhiXingKeShiId         int     `json:"执行科室ID"`
50
+		ZhiXingKeShi           string  `json:"执行科室"`
51
+		PN                     string  `json:"P(+)或N(-)表示阳性或阴性"`
52
+		ZhiXingPinCi           string  `json:"执行频次"`
53
+		PinLvCiShu             int     `json:"频率次数"`
54
+		PinLvJianGe            int     `json:"频率间隔"`
55
+		JianGeDanWei           string  `json:"间隔单位"`
56
+		ZhiXingShiJianFangAn   string  `json:"执行时间方案"`
57
+		JiJiaTeXing            int     `json:"计价特性"`
58
+		ZhiXingXingZhi         int     `json:"执行性质"`
59
+		ZhiXingBiaoZhi         int     `json:"执行标记"`
60
+		KeFouFenLing           int     `json:"可否分零"`
61
+		JinJiBiaoZhi           int     `json:"紧急标志"`
62
+		KaiShiZhiXingShiJian   int64   `json:"开始执行时间"`
63
+		ZhiXingZhongZhiShiJian int64   `json:"执行终止时间"`
64
+		ShangCiZhiXingShiJian  int64   `json:"上次执行时间"`
65
+		KaiZhuKeShiId          int     `json:"开嘱科室ID"`
66
+		DoctorCode             string  `json:"医师编码"`
67
+		Doctor                 string  `json:"开嘱医师"`
68
+		AdviceTime             int64   `json:"开嘱时间"`
69
+		StopTime               int64   `json:"停嘱时间"`
70
+		ApplyId                int     `json:"申请ID"`
71
+		UploadLable            int     `json:"上传标志"`
72
+		CheckResult            int     `json:"审查结果"`
73
+		NoPrint                int     `json:"忽略打印"`
74
+		Summary                string  `json:"摘要"`
75
+		AdviceOrderId          int64   `json:"医嘱单id"`
76
+		GeiYaoKeShi            int     `json:"给药科室"`
77
+		GeiYaoXingZhi          int     `json:"给药性质"`
78
+		GroupNo                int     `json:"组号"`
79
+		Speed                  string  `json:"滴速"`
80
+		ShouRiCiShu            float64 `json:"首日次数"`
81
+		MoRiCiShu              float64 `json:"末日次数"`
82
+		AdviceDoctorId         int     `json:"开嘱医师ID"`
83
+		AdviceNurseId          int     `json:"开嘱护士ID"`
84
+		OperaId                int     `json:"操作员ID"`
85
+		Opera                  string  `json:"操作员"`
86
+		CheckTime              int64   `json:"审核时间"`
87
+		ReplyAdviceTime        int64   `json:"重整医嘱时间"`
88
+	} `json:"result"`
89
+	Code string `json:"code"`
90
+}
91
+
19 92
 type XmlKey struct {
20 93
 	XMLName    xml.Name `xml:"string"`
21 94
 	StringName string   `xml:"name,attr"`
@@ -521,6 +594,83 @@ func GetAdviceBySyncAdviceId(orgId int64, sync_advice_id int64) (advice models.X
521 594
 	return
522 595
 }
523 596
 
597
+func GetAdviceBySyncAdviceIdTwo(orgId int64, sync_advice_id int64) (advice models.XtDoctorAdvice, err error) {
598
+	err = readDb.Model(&models.XtDoctorAdvice{}).Where("status = 1 AND user_org_id = ? AND sync_id = ?", orgId, sync_advice_id).First(&advice).Error
599
+	return
600
+}
601
+
602
+func HttpGetTfData(id_card_no string, advice_time string) (string, string) {
603
+
604
+	inputData := make(map[string]interface{})
605
+
606
+	inputData["病人来源"] = "1"
607
+	inputData["身份证号"] = id_card_no
608
+	inputData["开嘱时间"] = "2022-07-26 17:41:22"
609
+
610
+	var inputLog string
611
+	bytesData, err := json.Marshal(inputData)
612
+	inputLog = string(bytesData)
613
+	fmt.Println(string(bytesData))
614
+	if err != nil {
615
+		fmt.Println(err.Error())
616
+		return err.Error(), ""
617
+	}
618
+	reader := bytes.NewReader(bytesData)
619
+	var url string
620
+	gdyb_url := "http://hip.zptfyy.com/esb/listener/getVaf"
621
+	url = gdyb_url
622
+
623
+	//url := "http://igb.hsa.gdgov.cn/ebus/gdyb_inf/poc/hsa/hgs/1101"
624
+	request, err := http.NewRequest("POST", url, reader)
625
+	if err != nil {
626
+		fmt.Println(err.Error())
627
+		return err.Error(), ""
628
+	}
629
+
630
+	request.Header.Set("Content-Type", "application/json;charset=UTF-8")
631
+	request.Header.Set("code", "xt")
632
+
633
+	client := http.Client{}
634
+	resp, err := client.Do(request)
635
+	if err != nil {
636
+		fmt.Println(err.Error())
637
+		return err.Error(), ""
638
+	}
639
+	respBytes, err := ioutil.ReadAll(resp.Body)
640
+	if err != nil {
641
+		fmt.Println(err.Error())
642
+		return err.Error(), ""
643
+	}
644
+	fmt.Println(string(respBytes))
645
+	str := string(respBytes)
646
+	return str, inputLog
647
+
648
+}
649
+
650
+//func GettfYz(sync_time int64, id_card_no string, advice_time string) (str gzjhResult, checkStr string) {
651
+//
652
+//	api := "http://10.129.128.51:8803/esb/listener/getVaf" + "?病人来源=" + "1" + "&身份证号=" + "350623196810011858" + "&开嘱时间=" + "2022-03-30 01:47:51"
653
+//	resp, requestErr := http.Get(api)
654
+//	fmt.Println(requestErr)
655
+//	defer resp.Body.Close()
656
+//	body, ioErr := ioutil.ReadAll(resp.Body)
657
+//	fmt.Println(ioErr)
658
+//	fmt.Println(body)
659
+//
660
+//	//apiurl := "http://10.129.128.51:8803/esb/listener/getVaf"
661
+//	//rep := httplib.Get(apiurl)
662
+//	//rep.Param("病人来源", strconv.FormatInt(1, 10))
663
+//	//rep.Param("身份证号", id_card_no)
664
+//	//rep.Param("开嘱时间", advice_time)
665
+//	//
666
+//	//xmlKey := XmlKey{}
667
+//	//rep.ToXML(&xmlKey)
668
+//	//
669
+//	//var checkJSON gzjhResult
670
+//	//json.Unmarshal([]byte(xmlKey.InnerText), &checkJSON)
671
+//	return nil, ""
672
+//}
673
+
524 674
 // 广州暨华透析中心医嘱同步
525 675
 func SyncGzjhyz() (err error) {
526 676
 	// 第一步:获取上次同步时间
@@ -542,19 +692,16 @@ func SyncGzjhyz() (err error) {
542 692
 	schedulesDateStr := time.Now().Format("2006-01-02")
543 693
 	schedulesDate, _ := utils.ParseTimeStringToTime("2006-01-02", schedulesDateStr)
544 694
 	schedulesTime := schedulesDate.Unix()
545
-	var patient_zy_ids string
695
+	var patient_zy_ids []string
546 696
 	// patient_zy_ids, _ := redisClient.Get(redisClient.Context(),"gdjh_patient_zy_ids").Result()
547 697
 	// if len(patient_zy_ids) == 0 {
548 698
 	schedules, _ := GetPatientGzjhList(org_id, schedulesTime)
549 699
 	if len(schedules) > 0 {
550 700
 		for _, item := range schedules {
551 701
 			// if len(item.Patients.AdmissionNumber) > 0 {
552
-			if len(patient_zy_ids) == 0 {
553
-				patient_zy_ids = item.Patients.IdCardNo + "-" + strconv.FormatInt(item.Patients.ID, 10) + "-" + item.Patients.AdmissionNumber
554
-			} else {
555
-				patient_zy_ids = patient_zy_ids + "," + item.Patients.IdCardNo + "-" + strconv.FormatInt(item.Patients.ID, 10) + "-" + item.Patients.AdmissionNumber
556
-			}
557
-			// }
702
+			patient_zy_ids = append(patient_zy_ids, item.Patients.IdCardNo)
703
+
704
+			//
558 705
 		}
559 706
 		// redisClient.Set(redisClient.Context(),"gdjh_patient_zy_ids", patient_zy_ids, time.Minute*5)
560 707
 	}
@@ -562,90 +709,87 @@ func SyncGzjhyz() (err error) {
562 709
 	utils.InfoLog("2gdjh_patient_zy_ids:%v", patient_zy_ids)
563 710
 
564 711
 	// 第三步: 根据获取的同步时间,同步人员,去获取医嘱信息
565
-	idArray := strings.Split(patient_zy_ids, ",")
566
-	for _, idStr := range idArray {
567
-		temp_id := strings.Split(idStr, "-")
568
-		id := temp_id[0]
569
-		patient_id := temp_id[1]
570
-		admission_number := temp_id[2]
571
-		gzjhyz, yzstr := GetGzjhYz(sync_time, id)
572
-		if len(gzjhyz.Result) == 0 && len(admission_number) > 0 {
573
-			utils.InfoLog("admission_number:%v", admission_number)
574
-			gzjhyz, yzstr = GetGzjhYz(sync_time, admission_number)
575
-		}
576
-		utils.InfoLog("sync_time:%v", sync_time)
577
-		utils.InfoLog("yzstr:%v", yzstr)
578
-		if len(gzjhyz.Result) > 0 {
579
-			timeLayout := "2006010215:04:05"     //转化所需模板
580
-			loc, _ := time.LoadLocation("Local") //重要:获取时区
581
-			for _, yz := range gzjhyz.Result {
582
-				// 根据姓名获取医生ID
583
-				var doctor_id int64
584
-				temp_doctor_id, _ := redisClient.Get("gdjh_doctor_id_" + yz.DoctorId).Result()
585
-				if len(temp_doctor_id) == 0 {
586
-					doctor, _ := GetAdminUserId(org_id, yz.DoctorId)
587
-					doctor_id = doctor.AdminUserId
588
-					if doctor_id > 0 {
589
-						redisClient.Set("gdjh_doctor_id_"+yz.DoctorId, doctor_id, time.Minute*60*2)
590
-					} else {
591
-						continue
592
-					}
593
-				} else {
594
-					doctor_id, _ = strconv.ParseInt(temp_doctor_id, 10, 64)
595
-				}
596
-				theTime, _ := time.ParseInLocation(timeLayout, yz.StartTime, loc) //使用模板在对应时区转化为time.time类型
597
-				start_time := theTime.Unix()
598
-				temp_patient_id, _ := strconv.ParseInt(patient_id, 10, 64)
599
-				SingleDose, _ := strconv.ParseFloat(yz.SingleDose, 64)
600
-				PrescribingNumber, _ := strconv.ParseFloat(yz.PrescribingNumber, 64)
601
-				advice := models.XtDoctorAdvice{
602
-					UserOrgId:             org_id,
603
-					PatientId:             temp_patient_id,
604
-					AdviceType:            2,
605
-					AdviceDate:            schedulesTime,
606
-					StartTime:             start_time,
607
-					AdviceName:            yz.AdviceName,
608
-					AdviceDesc:            yz.AdviceDesc,
609
-					RecordDate:            schedulesTime,
610
-					SingleDose:            SingleDose,
611
-					SingleDoseUnit:        yz.SingleDoseUnit,
612
-					PrescribingNumber:     PrescribingNumber,
613
-					PrescribingNumberUnit: yz.PrescribingNumberUnit,
614
-					DeliveryWay:           yz.DeliveryWay,
615
-					ExecutionFrequency:    yz.ExecutionFrequency,
616
-					AdviceDoctor:          doctor_id,
617
-					CreatedTime:           time.Now().Unix(),
618
-					UpdatedTime:           time.Now().Unix(),
619
-					SyncAdviceId:          yz.AdviceId,
620
-					ExecutionState:        2,
621
-					Status:                1,
622
-					IsSync:                1,
623
-				}
624
-				utils.InfoLog("advice:%v", advice)
625
-				// 根据同步来的 advice_id 来查询库里是否已经存在
626
-				advice_info, _ := GetAdviceBySyncAdviceId(org_id, yz.AdviceId)
627
-				utils.InfoLog("advice_info:%v", advice_info)
628
-				if advice_info.ID > 0 {
629
-					key := strconv.FormatInt(org_id, 10) + ":" + strconv.FormatInt(temp_patient_id, 10) + ":" + strconv.FormatInt(schedulesTime, 10) + ":doctor_advices"
630
-					//清空key 值
631
-					redisClient.Set(key, "", time.Second)
632
-					keyOne := strconv.FormatInt(org_id, 10) + ":" + strconv.FormatInt(schedulesTime, 10) + ":advice_list_all"
633
-					redisClient.Set(keyOne, "", time.Second)
634
-					continue
635
-				} else {
636
-					if len(yz.AdviceName) > 0 {
637
-						handleerr := CreateDoctorAdviceHandle(&advice)
638
-						if handleerr != nil {
639
-							utils.ErrorLog("添加医嘱信息失败:%v", handleerr)
640
-							continue
641
-						}
642
-					} else {
643
-						continue
644
-					}
645
-				}
646
-			}
647
-		}
648
-	}
712
+	//idArray := strings.Split(patient_zy_ids, ",")
713
+	//for _, idStr := range patient_zy_ids {
714
+	//	temp_id := strings.Split(idStr, "-")
715
+	//	gzjhyz, yzstr := GetGzjhYz(sync_time, id)
716
+	//	if len(gzjhyz.Result) == 0 && len(admission_number) > 0 {
717
+	//		utils.InfoLog("admission_number:%v", admission_number)
718
+	//		gzjhyz, yzstr = GetGzjhYz(sync_time, admission_number)
719
+	//	}
720
+	//	utils.InfoLog("sync_time:%v", sync_time)
721
+	//	utils.InfoLog("yzstr:%v", yzstr)
722
+	//	if len(gzjhyz.Result) > 0 {
723
+	//		timeLayout := "2006010215:04:05"     //转化所需模板
724
+	//		loc, _ := time.LoadLocation("Local") //重要:获取时区
725
+	//		for _, yz := range gzjhyz.Result {
726
+	//			// 根据姓名获取医生ID
727
+	//			var doctor_id int64
728
+	//			temp_doctor_id, _ := redisClient.Get("gdjh_doctor_id_" + yz.DoctorId).Result()
729
+	//			if len(temp_doctor_id) == 0 {
730
+	//				doctor, _ := GetAdminUserId(org_id, yz.DoctorId)
731
+	//				doctor_id = doctor.AdminUserId
732
+	//				if doctor_id > 0 {
733
+	//					redisClient.Set("gdjh_doctor_id_"+yz.DoctorId, doctor_id, time.Minute*60*2)
734
+	//				} else {
735
+	//					continue
736
+	//				}
737
+	//			} else {
738
+	//				doctor_id, _ = strconv.ParseInt(temp_doctor_id, 10, 64)
739
+	//			}
740
+	//			theTime, _ := time.ParseInLocation(timeLayout, yz.StartTime, loc) //使用模板在对应时区转化为time.time类型
741
+	//			start_time := theTime.Unix()
742
+	//			temp_patient_id, _ := strconv.ParseInt(patient_id, 10, 64)
743
+	//			SingleDose, _ := strconv.ParseFloat(yz.SingleDose, 64)
744
+	//			PrescribingNumber, _ := strconv.ParseFloat(yz.PrescribingNumber, 64)
745
+	//			advice := models.XtDoctorAdvice{
746
+	//				UserOrgId:             org_id,
747
+	//				PatientId:             temp_patient_id,
748
+	//				AdviceType:            2,
749
+	//				AdviceDate:            schedulesTime,
750
+	//				StartTime:             start_time,
751
+	//				AdviceName:            yz.AdviceName,
752
+	//				AdviceDesc:            yz.AdviceDesc,
753
+	//				RecordDate:            schedulesTime,
754
+	//				SingleDose:            SingleDose,
755
+	//				SingleDoseUnit:        yz.SingleDoseUnit,
756
+	//				PrescribingNumber:     PrescribingNumber,
757
+	//				PrescribingNumberUnit: yz.PrescribingNumberUnit,
758
+	//				DeliveryWay:           yz.DeliveryWay,
759
+	//				ExecutionFrequency:    yz.ExecutionFrequency,
760
+	//				AdviceDoctor:          doctor_id,
761
+	//				CreatedTime:           time.Now().Unix(),
762
+	//				UpdatedTime:           time.Now().Unix(),
763
+	//				SyncAdviceId:          yz.AdviceId,
764
+	//				ExecutionState:        2,
765
+	//				Status:                1,
766
+	//				IsSync:                1,
767
+	//			}
768
+	//			utils.InfoLog("advice:%v", advice)
769
+	//			// 根据同步来的 advice_id 来查询库里是否已经存在
770
+	//			advice_info, _ := GetAdviceBySyncAdviceId(org_id, yz.AdviceId)
771
+	//			utils.InfoLog("advice_info:%v", advice_info)
772
+	//			if advice_info.ID > 0 {
773
+	//				key := strconv.FormatInt(org_id, 10) + ":" + strconv.FormatInt(temp_patient_id, 10) + ":" + strconv.FormatInt(schedulesTime, 10) + ":doctor_advices"
774
+	//				//清空key 值
775
+	//				redisClient.Set(key, "", time.Second)
776
+	//				keyOne := strconv.FormatInt(org_id, 10) + ":" + strconv.FormatInt(schedulesTime, 10) + ":advice_list_all"
777
+	//				redisClient.Set(keyOne, "", time.Second)
778
+	//				continue
779
+	//			} else {
780
+	//				if len(yz.AdviceName) > 0 {
781
+	//					handleerr := CreateDoctorAdviceHandle(&advice)
782
+	//					if handleerr != nil {
783
+	//						utils.ErrorLog("添加医嘱信息失败:%v", handleerr)
784
+	//						continue
785
+	//					}
786
+	//				} else {
787
+	//					continue
788
+	//				}
789
+	//			}
790
+	//		}
791
+	//	}
792
+	//}
649 793
 	return
650 794
 }
651 795
 
@@ -1433,3 +1577,191 @@ func GetShItemID(org_id int64, project_name string, item_name string, project_id
1433 1577
 		}
1434 1578
 	}
1435 1579
 }
1580
+
1581
+func Synctfyz() (err error) {
1582
+
1583
+	// 第一步:获取上次同步时间
1584
+	org_id := int64(10330)
1585
+
1586
+	redisClient := RedisClient()
1587
+	defer redisClient.Close()
1588
+	sync_time_tt, _ := redisClient.Get("tf_sync_time").Result()
1589
+
1590
+	sync_time, _ := strconv.ParseInt(sync_time_tt, 10, 64)
1591
+	if sync_time == 0 {
1592
+		sync_time = time.Now().Unix()
1593
+	}
1594
+	new_sync_time := time.Now().Unix()
1595
+	utils.InfoLog("new_sync_time:%v", new_sync_time)
1596
+	// 切换为当前时间
1597
+	redisClient.Set("tf_sync_time", new_sync_time, time.Minute*60*24)
1598
+	// 第二步: 获取当天排班患者的住院号
1599
+	schedulesDateStr := time.Now().Format("2006-01-02")
1600
+	schedulesDate, _ := utils.ParseTimeStringToTime("2006-01-02", schedulesDateStr)
1601
+	schedulesTime := schedulesDate.Unix()
1602
+	var patient_zy_ids string
1603
+	// patient_zy_ids, _ := redisClient.Get(redisClient.Context(),"gdjh_patient_zy_ids").Result()
1604
+	// if len(patient_zy_ids) == 0 {
1605
+	schedules, _ := GetPatientGzjhList(org_id, schedulesTime)
1606
+	if len(schedules) > 0 {
1607
+		for _, item := range schedules {
1608
+			// if len(item.Patients.AdmissionNumber) > 0 {
1609
+			if len(patient_zy_ids) == 0 {
1610
+				patient_zy_ids = item.Patients.IdCardNo
1611
+			} else {
1612
+				patient_zy_ids = patient_zy_ids + "," + item.Patients.IdCardNo
1613
+			}
1614
+			// }
1615
+		}
1616
+		// redisClient.Set(redisClient.Context(),"gdjh_patient_zy_ids", patient_zy_ids, time.Minute*5)
1617
+	}
1618
+	// }
1619
+	utils.InfoLog("2gdjh_patient_zy_ids:%v", patient_zy_ids)
1620
+
1621
+	// 第三步: 根据获取的同步时间,同步人员,去获取医嘱信息
1622
+	idArray := strings.Split(patient_zy_ids, ",")
1623
+	for _, idStr := range idArray {
1624
+		//temp_id := strings.Split(idStr, "-")
1625
+		id := idStr
1626
+		printInfo, _ := GetPatientsInfoByIDCardNo(id, 10330)
1627
+		timeNow := time.Unix(sync_time, 0) //2017-08-30 16:19:19 +0800 CST
1628
+
1629
+		timeString := timeNow.Format("2006-01-02 15:04:05") //2015-06-15 08:52:32
1630
+
1631
+		result, requestLog := HttpGetTfData(id, timeString)
1632
+		saveLog(result, requestLog, "tf", "tf", "tf")
1633
+		//fmt.Println(result)
1634
+		//fmt.Println(requestLog)
1635
+		var res RequestResult
1636
+		if err := json.Unmarshal([]byte(result), &res); err != nil {
1637
+			utils.ErrorLog("解析失败:%v", err)
1638
+		}
1639
+		fmt.Println(res)
1640
+		//saveLog(result, requestLog, "tf", "tf", "tf")
1641
+
1642
+		//
1643
+		//if len(gzjhyz.Result) == 0 && len(admission_number) > 0 {
1644
+		//	utils.InfoLog("admission_number:%v", admission_number)
1645
+		//	gzjhyz, yzstr = GetGzjhYz(sync_time, admission_number)
1646
+		//}
1647
+		//utils.InfoLog("sync_time:%v", sync_time)
1648
+		//utils.InfoLog("yzstr:%v", yzstr)
1649
+		if len(res.Result) > 0 {
1650
+			//timeLayout := "2006010215:04:05"     //转化所需模板
1651
+			//loc, _ := time.LoadLocation("Local") //重要:获取时区
1652
+			for _, yz := range res.Result {
1653
+				// 根据姓名获取医生ID
1654
+				var doctor_id int64
1655
+				//doctor_id, _ = strconv.ParseInt(yz.AdviceDoctorId, 10, 64)
1656
+
1657
+				temp_doctor_id, _ := redisClient.Get("tf_doctor_id_" + yz.Doctor).Result()
1658
+				if len(temp_doctor_id) == 0 {
1659
+					doctor, _ := GetAdminUserId(org_id, yz.Doctor)
1660
+					doctor_id = doctor.AdminUserId
1661
+					if doctor_id > 0 {
1662
+						redisClient.Set("tf_doctor_id_"+yz.Doctor, doctor_id, time.Minute*60*2)
1663
+					} else {
1664
+						continue
1665
+					}
1666
+				} else {
1667
+					doctor_id, _ = strconv.ParseInt(temp_doctor_id, 10, 64)
1668
+				}
1669
+				//theTime, _ := time.ParseInLocation(timeLayout, , loc) //使用模板在对应时区转化为time.time类型
1670
+				start_time := yz.AdviceTime / 1000
1671
+				fmt.Println(start_time)
1672
+				temp_patient_id := printInfo.ID
1673
+				SingleDose := yz.DanLiang
1674
+				PrescribingNumber := yz.Shuliang
1675
+				advice := models.XtDoctorAdvice{
1676
+					UserOrgId:  3877,
1677
+					PatientId:  temp_patient_id,
1678
+					AdviceType: 2,
1679
+					AdviceDate: schedulesTime,
1680
+					StartTime:  start_time,
1681
+					AdviceName: yz.Advice,
1682
+					//AdviceDesc:            yz.AdviceDesc,
1683
+					RecordDate:         schedulesTime,
1684
+					SingleDose:         SingleDose,
1685
+					PrescribingNumber:  PrescribingNumber,
1686
+					DeliveryWay:        yz.GeiYaoTuJing,
1687
+					ExecutionFrequency: yz.ZhiXingPinCi,
1688
+					AdviceDoctor:       doctor_id,
1689
+					CreatedTime:        time.Now().Unix(),
1690
+					UpdatedTime:        time.Now().Unix(),
1691
+					SyncAdviceId:       0,
1692
+					ExecutionState:     2,
1693
+					Status:             1,
1694
+					IsSync:             1,
1695
+					SyncId:             strconv.FormatInt(yz.AdviceId, 10),
1696
+				}
1697
+				utils.InfoLog("advice:%v", advice)
1698
+				// 根据同步来的 advice_id 来查询库里是否已经存在
1699
+				advice_info, _ := GetAdviceBySyncAdviceIdTwo(3877, yz.AdviceId)
1700
+				utils.InfoLog("advice_info:%v", advice_info)
1701
+				if advice_info.ID > 0 {
1702
+					key := strconv.FormatInt(org_id, 10) + ":" + strconv.FormatInt(temp_patient_id, 10) + ":" + strconv.FormatInt(schedulesTime, 10) + ":doctor_advices"
1703
+					//清空key 值
1704
+					redisClient.Set(key, "", time.Second)
1705
+					keyOne := strconv.FormatInt(org_id, 10) + ":" + strconv.FormatInt(schedulesTime, 10) + ":advice_list_all"
1706
+					redisClient.Set(keyOne, "", time.Second)
1707
+					continue
1708
+				} else {
1709
+					if len(yz.Advice) > 0 {
1710
+						handleerr := CreateDoctorAdviceHandle(&advice)
1711
+						if handleerr != nil {
1712
+							utils.ErrorLog("添加医嘱信息失败:%v", handleerr)
1713
+							continue
1714
+						}
1715
+					} else {
1716
+						continue
1717
+					}
1718
+				}
1719
+			}
1720
+		}
1721
+	}
1722
+	return
1723
+}
1724
+
1725
+//
1726
+
1727
+func saveLog(result string, request string, infno string, desc string, org_name string) {
1728
+
1729
+	//org_id, _ := beego.AppConfig.Int64("org_id")
1730
+	//miConfig, _ := service.FindMedicalInsuranceInfo(org_id)
1731
+	dir := org_name + "日志"
1732
+	utils.Mkdir(dir)
1733
+	month := time.Unix(1557042972, 0).Format("1")
1734
+	year := time.Now().Format("2006")
1735
+	month = time.Now().Format("01")
1736
+	day := time.Now().Format("02")
1737
+	hour := time.Now().Format("15")
1738
+	min := time.Now().Format("04")
1739
+	sec := time.Now().Format("05")
1740
+
1741
+	result_time := year + "-" + month + "-" + day + " " + hour + ":" + min + ":" + sec
1742
+
1743
+	file := org_name + "_" + year + month + day + "_log"
1744
+	file_name := file + ".txt"
1745
+	file_path := org_name + "日志" + "/" + file_name
1746
+	exist, _ := utils.PathExists(file_path)
1747
+	if exist { //存在
1748
+		fmt.Println("存在")
1749
+		f, err := os.OpenFile(file_path, os.O_WRONLY, 0644)
1750
+		if err != nil {
1751
+			fmt.Println("read fail")
1752
+		}
1753
+		content := "\r\n" + "\r\n" + "\r\n" + result_time + " " + "【 " + desc + infno + "入参" + " 】:" + "\r\n" + request + "\r\n" + result_time + " " + "【 " + desc + infno + "出参" + " 】:" + "\r\n" + result
1754
+		n, _ := f.Seek(0, 2)
1755
+		_, err = f.WriteAt([]byte(content), n)
1756
+
1757
+	} else { //不存在
1758
+		fmt.Println("文件不存在,创建文件")
1759
+		f, err := os.Create(org_name + "日志" + "/" + file_name)
1760
+		defer f.Close()
1761
+		if err != nil {
1762
+		} else {
1763
+			_, err = f.Write([]byte("记录日志"))
1764
+		}
1765
+	}
1766
+
1767
+}

+ 33 - 1
utils/log.go Datei anzeigen

@@ -2,6 +2,7 @@ package utils
2 2
 
3 3
 import (
4 4
 	"fmt"
5
+	"os"
5 6
 	"time"
6 7
 )
7 8
 
@@ -63,4 +64,35 @@ func magenta(s string) string {
63 64
 
64 65
 func formatLog(prefix string) string {
65 66
 	return time.Now().Format("[2006/01/02 15:04:05]") + " " + prefix + " "
66
-}
67
+}
68
+
69
+func Mkdir(dir string) {
70
+	// 创建文件夹
71
+	exist, err := PathExists(dir)
72
+	if err != nil {
73
+		fmt.Println(err.Error())
74
+	} else {
75
+		if exist {
76
+			fmt.Println(dir + "文件夹已存在!")
77
+		} else {
78
+			// 文件夹名称,权限
79
+			err := os.Mkdir(dir, os.ModePerm)
80
+			if err != nil {
81
+				fmt.Println(dir+"文件夹创建失败:", err.Error())
82
+			} else {
83
+				fmt.Println(dir + "文件夹创建成功!")
84
+			}
85
+		}
86
+	}
87
+}
88
+
89
+func PathExists(path string) (bool, error) {
90
+	_, err := os.Stat(path)
91
+	if err == nil {
92
+		return true, nil
93
+	}
94
+	if os.IsNotExist(err) {
95
+		return false, nil
96
+	}
97
+	return false, err
98
+}