csx 2 anni fa
parent
commit
fcb8ed4bf5
2 ha cambiato i file con 149 aggiunte e 143 eliminazioni
  1. 1 1
      main.go
  2. 148 142
      service/sh_service.go

+ 1 - 1
main.go Vedi File

@@ -8,7 +8,7 @@ import (
8 8
 
9 9
 func init() {
10 10
 	service.ConnectDB()
11
-	service.ConnectSHMSDB()
11
+	service.ConnectMSDB2()
12 12
 	service.ConnectMSDB()
13 13
 }
14 14
 

+ 148 - 142
service/sh_service.go Vedi File

@@ -1,8 +1,13 @@
1 1
 package service
2 2
 
3 3
 import (
4
+	"IC/models"
5
+	"IC/utils"
4 6
 	"fmt"
5 7
 	"regexp"
8
+	"strconv"
9
+	"strings"
10
+	"time"
6 11
 	"unicode"
7 12
 )
8 13
 
@@ -67,132 +72,133 @@ func (KMResult) TableName() string {
67 72
 func GetSHResultDataInsertDB(org_id int64) (result []*KMResult) {
68 73
 	record, _ := GetLastSyncResultRecord(org_id)
69 74
 	fmt.Println(record)
70
-	//if record.ID == 0 {
71
-	//	list, err := GetSHResultRecord()
72
-	//	if err == nil {
73
-	//		fmt.Println(list)
74
-	//
75
-	//		//插入到系统检验检查数据
76
-	//		for _, item := range list {
77
-	//			project_id := int64(0)
78
-	//			if len(item.FIDCardNo) > 0 {
79
-	//				project_id, _ = GetShjhProjectID(org_id, item.FCompoundItemName)
80
-	//			} else {
81
-	//				continue
82
-	//			}
83
-	//			printInfo, _ := GetPatientsInfoByIDCardNo(item.FIDCardNo, 10215)
84
-	//
85
-	//			if printInfo.ID == 0 {
86
-	//				fmt.Println(item)
87
-	//				fmt.Println(printInfo)
88
-	//				fmt.Println("暂无该患者")
89
-	//				continue
90
-	//			}
91
-	//
92
-	//			item_id, _ := GetShItemID(org_id, item.FCompoundItemName, item.FSingleItemName, project_id)
93
-	//
94
-	//			tx := writeMiddleDb.Begin()
95
-	//			var inspection models.MiddleInspection
96
-	//			var inspection_reference models.MiddleInspectionReference
97
-	//
98
-	//			recordDateStr := ""
99
-	//			//inspect_date := item.FRecordTime.Format("2006-01-02 15:04")
100
-	//
101
-	//			recordDateStr = item.FRecordTime
102
-	//			date, _ := utils.ParseTimeStringToTime("2006-01-02 15:04", recordDateStr)
103
-	//			record_date, _ := utils.ParseTimeStringToTime("2006-01-02", date.Format("2006-01-02"))
104
-	//			var total int
105
-	//			var RangeOptions string
106
-	//			var RangeMin string
107
-	//			var RangeMax string
108
-	//			// 判断检查类型
109
-	//			var ItemType int
110
-	//			if IsChineseChar(item.FReference) || strings.Contains(item.FReference, "|") || strings.Contains(item.FReference, "≤") {
111
-	//				ItemType = 2
112
-	//			} else {
113
-	//				if strings.Contains(item.FReference, "-") {
114
-	//					ItemType = 1
115
-	//				} else {
116
-	//					ItemType = 2
117
-	//				}
118
-	//			}
119
-	//
120
-	//			if ItemType == 1 {
121
-	//				Range := strings.Split(item.FReference, "-")
122
-	//				RangeMin = Range[0]
123
-	//				RangeMax = Range[1]
124
-	//			} else {
125
-	//				RangeOptions = item.FReference
126
-	//			}
127
-	//
128
-	//			err = readMiddleDb.Model(&models.MiddleInspectionReference{}).Where("org_id = ? and project_id = ? and item_id = ? and status = 1", org_id, project_id, item_id).Find(&inspection_reference).Count(&total).Error
129
-	//			if inspection_reference.ID > 0 {
130
-	//				ItemType = inspection_reference.RangeType
131
-	//			}
132
-	//			if total <= 0 {
133
-	//				inspection_reference.OrgId = org_id
134
-	//				inspection_reference.ProjectName = item.FCompoundItemName
135
-	//				inspection_reference.Project = item.FCompoundItemName
136
-	//				inspection_reference.ProjectId = project_id
137
-	//				inspection_reference.ItemName = item.FSingleItemName
138
-	//				inspection_reference.ItemNameAddition = ""
139
-	//				inspection_reference.ItemId = item_id
140
-	//				inspection_reference.RangeType = ItemType
141
-	//				inspection_reference.RangeMin = RangeMin
142
-	//				inspection_reference.RangeMax = RangeMax
143
-	//				inspection_reference.RangeOptions = RangeOptions
144
-	//				inspection_reference.Unit = item.FUnit
145
-	//				inspection_reference.Status = 1
146
-	//				inspection_reference.CreatedTime = time.Now().Unix()
147
-	//				inspection_reference.UpdatedTime = time.Now().Unix()
148
-	//				inspection_reference.InspectDate = item.FCheckTime
149
-	//				inspection_reference.UTime = item.FCheckTime
150
-	//				err = tx.Model(&models.MiddleInspectionReference{}).Create(&inspection_reference).Error
151
-	//				if err != nil {
152
-	//					tx.Rollback()
153
-	//				}
154
-	//			}
155
-	//
156
-	//			var itotal int
157
-	//			err = readMiddleDb.Model(&models.MiddleInspection{}).Where("org_id = ? and project_id = ? and item_id = ? and record_date = ? and patient_id = ?  and status = 1", org_id, project_id, item_id, record_date.Unix(), printInfo.ID).Find(&inspection).Count(&itotal).Error
158
-	//			if itotal <= 0 {
159
-	//				inspection.PatientId = printInfo.ID
160
-	//				inspection.OrgId = org_id
161
-	//				inspection.ProjectId = project_id
162
-	//				inspection.ItemName = inspection_reference.ItemName
163
-	//				inspection.ProjectName = inspection_reference.ProjectName
164
-	//				inspection.InspectType = ItemType
165
-	//				inspection.ItemId = item_id
166
-	//				inspection.InspectValue = item.FResult
167
-	//				inspection.InspectDate = item.FCheckTime
168
-	//				inspection.RecordDate = record_date.Unix()
169
-	//				inspection.Status = 1
170
-	//				inspection.CreatedTime = time.Now().Unix()
171
-	//				inspection.UpdatedTime = time.Now().Unix()
172
-	//				inspection.UTime = item.FCheckTime
173
-	//				inspection.HisUserId = strconv.FormatInt(printInfo.ID, 10)
174
-	//				err = tx.Model(&models.MiddleInspection{}).Create(&inspection).Error
175
-	//				if err != nil {
176
-	//					tx.Rollback()
177
-	//				}
178
-	//			}
179
-	//
180
-	//			tx.Commit()
181
-	//
182
-	//		}
183
-	//		//插入一条查询检验检查结果记录状态数据
184
-	//		var info LisSyncResultStatusInfo
185
-	//		info.Ctime = time.Now().Unix()
186
-	//		info.Status = 1
187
-	//		info.Mtime = time.Now().Unix()
188
-	//		info.OrgId = org_id
189
-	//		info.IsResult = 1
190
-	//		info.LastId = int64(len(list))
191
-	//		info.ResultDate = time.Now().Unix()
192
-	//		writeMiddleDb.Save(&info)
193
-	//	}
194
-	//
195
-	//} else
75
+	if record.ID == 0 {
76
+		list, err := GetSHResultRecord()
77
+		if err == nil {
78
+			fmt.Println(list)
79
+
80
+			//插入到系统检验检查数据
81
+			for _, item := range list {
82
+				project_id := int64(0)
83
+				if len(item.FIDCardNo) > 0 {
84
+					project_id, _ = GetShjhProjectID(org_id, item.FCompoundItemName)
85
+				} else {
86
+					continue
87
+				}
88
+				printInfo, _ := GetPatientsInfoByIDCardNo(item.FIDCardNo, 10215)
89
+
90
+				if printInfo.ID == 0 {
91
+					fmt.Println(item)
92
+					fmt.Println(printInfo)
93
+					fmt.Println("暂无该患者")
94
+					continue
95
+				}
96
+
97
+				item_id, _ := GetShItemID(org_id, item.FCompoundItemName, item.FSingleItemName, project_id)
98
+
99
+				tx := writeMiddleDb.Begin()
100
+				var inspection models.MiddleInspection
101
+				var inspection_reference models.MiddleInspectionReference
102
+
103
+				recordDateStr := ""
104
+				//inspect_date := item.FRecordTime.Format("2006-01-02 15:04")
105
+
106
+				recordDateStr = item.FRecordTime
107
+				date, _ := utils.ParseTimeStringToTime("2006-01-02 15:04", recordDateStr)
108
+				record_date, _ := utils.ParseTimeStringToTime("2006-01-02", date.Format("2006-01-02"))
109
+				var total int
110
+				var RangeOptions string
111
+				var RangeMin string
112
+				var RangeMax string
113
+				// 判断检查类型
114
+				var ItemType int
115
+				if IsChineseChar(item.FReference) || strings.Contains(item.FReference, "|") || strings.Contains(item.FReference, "≤") {
116
+					ItemType = 2
117
+				} else {
118
+					if strings.Contains(item.FReference, "-") {
119
+						ItemType = 1
120
+					} else {
121
+						ItemType = 2
122
+					}
123
+				}
124
+
125
+				if ItemType == 1 {
126
+					Range := strings.Split(item.FReference, "-")
127
+					RangeMin = Range[0]
128
+					RangeMax = Range[1]
129
+				} else {
130
+					RangeOptions = item.FReference
131
+				}
132
+
133
+				err = readMiddleDb.Model(&models.MiddleInspectionReference{}).Where("org_id = ? and project_id = ? and item_id = ? and status = 1", org_id, project_id, item_id).Find(&inspection_reference).Count(&total).Error
134
+				if inspection_reference.ID > 0 {
135
+					ItemType = inspection_reference.RangeType
136
+				}
137
+				if total <= 0 {
138
+					inspection_reference.OrgId = org_id
139
+					inspection_reference.ProjectName = item.FCompoundItemName
140
+					inspection_reference.Project = item.FCompoundItemName
141
+					inspection_reference.ProjectId = project_id
142
+					inspection_reference.ItemName = item.FSingleItemName
143
+					inspection_reference.ItemNameAddition = ""
144
+					inspection_reference.ItemId = item_id
145
+					inspection_reference.RangeType = ItemType
146
+					inspection_reference.RangeMin = RangeMin
147
+					inspection_reference.RangeMax = RangeMax
148
+					inspection_reference.RangeOptions = RangeOptions
149
+					inspection_reference.Unit = item.FUnit
150
+					inspection_reference.Status = 1
151
+					inspection_reference.CreatedTime = time.Now().Unix()
152
+					inspection_reference.UpdatedTime = time.Now().Unix()
153
+					inspection_reference.InspectDate = item.FCheckTime
154
+					inspection_reference.UTime = item.FCheckTime
155
+					err = tx.Model(&models.MiddleInspectionReference{}).Create(&inspection_reference).Error
156
+					if err != nil {
157
+						tx.Rollback()
158
+					}
159
+				}
160
+
161
+				var itotal int
162
+				err = readMiddleDb.Model(&models.MiddleInspection{}).Where("org_id = ? and project_id = ? and item_id = ? and record_date = ? and patient_id = ?  and status = 1", org_id, project_id, item_id, record_date.Unix(), printInfo.ID).Find(&inspection).Count(&itotal).Error
163
+				if itotal <= 0 {
164
+					inspection.PatientId = printInfo.ID
165
+					inspection.OrgId = org_id
166
+					inspection.ProjectId = project_id
167
+					inspection.ItemName = inspection_reference.ItemName
168
+					inspection.ProjectName = inspection_reference.ProjectName
169
+					inspection.InspectType = ItemType
170
+					inspection.ItemId = item_id
171
+					inspection.InspectValue = item.FResult
172
+					inspection.InspectDate = item.FCheckTime
173
+					inspection.RecordDate = record_date.Unix()
174
+					inspection.Status = 1
175
+					inspection.CreatedTime = time.Now().Unix()
176
+					inspection.UpdatedTime = time.Now().Unix()
177
+					inspection.UTime = item.FCheckTime
178
+					inspection.HisUserId = strconv.FormatInt(printInfo.ID, 10)
179
+					err = tx.Model(&models.MiddleInspection{}).Create(&inspection).Error
180
+					if err != nil {
181
+						tx.Rollback()
182
+					}
183
+				}
184
+
185
+				tx.Commit()
186
+
187
+			}
188
+			//插入一条查询检验检查结果记录状态数据
189
+			var info LisSyncResultStatusInfo
190
+			info.Ctime = time.Now().Unix()
191
+			info.Status = 1
192
+			info.Mtime = time.Now().Unix()
193
+			info.OrgId = org_id
194
+			info.IsResult = 1
195
+			info.LastId = int64(len(list))
196
+			info.ResultDate = time.Now().Unix()
197
+			writeMiddleDb.Save(&info)
198
+		}
199
+
200
+	}
201
+	//else
196 202
 	//{
197 203
 	//	if record.LastId != 0 {
198 204
 	//		list, err := GetResultRecordByID(record.LastId)
@@ -322,22 +328,22 @@ func GetSHResultDataInsertDB(org_id int64) (result []*KMResult) {
322 328
 	//
323 329
 	//}
324 330
 	//
325
-	//// 第一步:跟进org_id 去中间库查出需要同步的数据
326
-	//inspection_references, _ := GetSyncInspectionReferenceByOrgId(org_id)
327
-	//inspections, _ := GetSyncInspectionByOrgId(org_id)
328
-	//
329
-	//// 第二步:将数据同步到业务库
330
-	//if len(inspection_references) > 0 {
331
-	//	for _, inspection_reference := range inspection_references {
332
-	//		SyncInspectionReference(&inspection_reference)
333
-	//	}
334
-	//}
335
-	//
336
-	//if len(inspections) > 0 {
337
-	//	for _, inspection := range inspections {
338
-	//		SyncInspection(&inspection)
339
-	//	}
340
-	//}
331
+	// 第一步:跟进org_id 去中间库查出需要同步的数据
332
+	inspection_references, _ := GetSyncInspectionReferenceByOrgId(org_id)
333
+	inspections, _ := GetSyncInspectionByOrgId(org_id)
334
+
335
+	// 第二步:将数据同步到业务库
336
+	if len(inspection_references) > 0 {
337
+		for _, inspection_reference := range inspection_references {
338
+			SyncInspectionReference(&inspection_reference)
339
+		}
340
+	}
341
+
342
+	if len(inspections) > 0 {
343
+		for _, inspection := range inspections {
344
+			SyncInspection(&inspection)
345
+		}
346
+	}
341 347
 	return
342 348
 
343 349
 }