csx před 3 roky
rodič
revize
e0cad53991
8 změnil soubory, kde provedl 1201 přidání a 93 odebrání
  1. 9 0
      conf/app.conf
  2. 67 63
      controllers/lis.go
  3. 5 2
      main.go
  4. 3 0
      routers/router.go
  5. 983 0
      service/bl_service.go
  6. 48 27
      service/cron.go
  7. 37 1
      service/db.go
  8. 49 0
      service/ms_db.go

+ 9 - 0
conf/app.conf Zobrazit soubor

@@ -86,6 +86,15 @@ redispasswrod = TZtBW098WId3i27clkpj3q8dnUaVFP
86 86
 redisdb = 2
87 87
 
88 88
 
89
+blmysqlhost = 127.0.0.1
90
+blmysqlport = 3306
91
+blmysqluser = lindialy
92
+blmysqlpass = 123456
93
+blmysqlname = kuyicloud
94
+
95
+
96
+
97
+
89 98
 
90 99
 
91 100
 niprocart =  63

+ 67 - 63
controllers/lis.go Zobrazit soubor

@@ -1,16 +1,16 @@
1 1
 package controllers
2 2
 
3 3
 import (
4
-	"IC/service"
5 4
 	"IC/enums"
6
-	_"strconv"
7
-	"encoding/json"
8 5
 	"IC/models"
6
+	"IC/service"
9 7
 	"IC/utils"
8
+	"encoding/json"
9
+	_ "fmt"
10
+	_ "github.com/astaxie/beego"
11
+	_ "github.com/jinzhu/gorm"
12
+	_ "strconv"
10 13
 	"time"
11
-	_"fmt"
12
-	_"github.com/jinzhu/gorm"
13
-	_"github.com/astaxie/beego"
14 14
 )
15 15
 
16 16
 // LisController operations for Lis
@@ -18,18 +18,18 @@ type LisController struct {
18 18
 	BaseAPIController
19 19
 }
20 20
 
21
-func (c *LisController) SyncAdvice(){
21
+func (c *LisController) SyncAdvice() {
22 22
 	// 获取备份库里所有的医嘱信息
23
-	advices,_ := service.GetAllAdvice()
24
-	for _,advice := range advices {
23
+	advices, _ := service.GetAllAdvice()
24
+	for _, advice := range advices {
25 25
 		// if index > 50 {
26 26
 		// 	break
27 27
 		// }
28 28
 		tempAdvice := models.DoctorAdvice{
29
-			ID			: advice.ID,
30
-			Checker		: advice.Checker,
31
-			CheckTime	: advice.CheckTime,
32
-			CheckState	: advice.CheckState,
29
+			ID:         advice.ID,
30
+			Checker:    advice.Checker,
31
+			CheckTime:  advice.CheckTime,
32
+			CheckState: advice.CheckState,
33 33
 		}
34 34
 		service.SyncAdvice(&tempAdvice)
35 35
 	}
@@ -41,23 +41,23 @@ func (c *LisController) SyncAdvice(){
41 41
 
42 42
 }
43 43
 
44
-func (c *LisController) FiledConfigSys(){
45
-	orgs,_ := service.GetfiledConfigOrg()
46
-	sysFiledConfig,_ := service.GetfiledConfigSys()
44
+func (c *LisController) FiledConfigSys() {
45
+	orgs, _ := service.GetfiledConfigOrg()
46
+	sysFiledConfig, _ := service.GetfiledConfigSys()
47 47
 
48 48
 	if len(orgs) > 0 {
49
-		for _,org := range orgs {
50
-			for _,filed := range sysFiledConfig {
51
-				filedConfig,_ := service.GetfiledConfigByOrgId(org.OrgId,filed.Module,filed.FiledName)	
49
+		for _, org := range orgs {
50
+			for _, filed := range sysFiledConfig {
51
+				filedConfig, _ := service.GetfiledConfigByOrgId(org.OrgId, filed.Module, filed.FiledName)
52 52
 				if filedConfig.ID > 0 {
53 53
 					continue
54 54
 				} else {
55
-					tempfiled := models.FiledConfig {
56
-						OrgId       : org.OrgId,
57
-						Module      : filed.Module,
58
-						FiledName   : filed.FiledName,
59
-						FiledNameCn : filed.FiledNameCn,
60
-						IsShow      : 2,
55
+					tempfiled := models.FiledConfig{
56
+						OrgId:       org.OrgId,
57
+						Module:      filed.Module,
58
+						FiledName:   filed.FiledName,
59
+						FiledNameCn: filed.FiledNameCn,
60
+						IsShow:      2,
61 61
 					}
62 62
 					service.CreatefiledConfig(&tempfiled)
63 63
 				}
@@ -72,25 +72,25 @@ func (c *LisController) FiledConfigSys(){
72 72
 }
73 73
 
74 74
 func (c *LisController) SyncToBase() {
75
-	org_id, _:= c.GetInt64("org_id",0) 
75
+	org_id, _ := c.GetInt64("org_id", 0)
76 76
 	if org_id <= 0 {
77 77
 		c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
78 78
 		return
79 79
 	}
80
-	
80
+
81 81
 	// 第一步:跟进org_id 去中间库查出需要同步的数据
82
-	inspection_references,_ := service.GetSyncInspectionReferenceByOrgId(org_id)
83
-	inspections,_ := service.GetSyncInspectionByOrgId(org_id)
82
+	inspection_references, _ := service.GetSyncInspectionReferenceByOrgId(org_id)
83
+	inspections, _ := service.GetSyncInspectionByOrgId(org_id)
84 84
 
85 85
 	// 第二步:将数据同步到业务库
86 86
 	if len(inspection_references) > 0 {
87
-		for _,inspection_reference := range inspection_references {
87
+		for _, inspection_reference := range inspection_references {
88 88
 			service.SyncInspectionReference(&inspection_reference)
89 89
 		}
90 90
 	}
91 91
 
92 92
 	if len(inspections) > 0 {
93
-		for _,inspection := range inspections {
93
+		for _, inspection := range inspections {
94 94
 			service.SyncInspection(&inspection)
95 95
 		}
96 96
 	}
@@ -109,17 +109,17 @@ func (c *LisController) GetList() {
109 109
 	}
110 110
 
111 111
 	// 第一步:根据机构id获取对应机构所有病人的his_user_id
112
-	patients,patientError := service.GetHisUserIdByOrgID(org_id)
112
+	patients, patientError := service.GetHisUserIdByOrgID(org_id)
113 113
 	if patientError != nil {
114 114
 		utils.ErrorLog("获取用户His_user_id信息失败:%v", patientError)
115 115
 		c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
116 116
 		return
117 117
 	}
118 118
 
119
-	patientStr:= make([]interface{},0)
119
+	patientStr := make([]interface{}, 0)
120 120
 	if len(patients) > 0 {
121
-	// 第二步:根据病人的his_user_id来查询上次同步时间	
122
-		for _ , patient := range patients {
121
+		// 第二步:根据病人的his_user_id来查询上次同步时间
122
+		for _, patient := range patients {
123 123
 			if len(patient.HisUserId) <= 0 {
124 124
 				continue
125 125
 			}
@@ -127,12 +127,12 @@ func (c *LisController) GetList() {
127 127
 			// 	continue
128 128
 			// }
129 129
 
130
-			syncLastInfo,_ := service.GetSyncTimeByOrgID(org_id,patient.HisUserId)
130
+			syncLastInfo, _ := service.GetSyncTimeByOrgID(org_id, patient.HisUserId)
131 131
 			var sync_time int64
132 132
 			if syncLastInfo.ID > 0 {
133 133
 				sync_time = syncLastInfo.SyncTime
134 134
 			} else {
135
-				inspectionLastInfo,_ := service.GetInspectionLastInfoByOrgID(org_id,patient.HisUserId)
135
+				inspectionLastInfo, _ := service.GetInspectionLastInfoByOrgID(org_id, patient.HisUserId)
136 136
 				if inspectionLastInfo.ID > 0 {
137 137
 					sync_time = inspectionLastInfo.CreatedTime
138 138
 				} else {
@@ -140,13 +140,13 @@ func (c *LisController) GetList() {
140 140
 				}
141 141
 			}
142 142
 
143
-			syncTimes := time.Unix(sync_time,0).Format("2006-01-02 15:04")
144
-			utils.InfoLog("syncTimes:%v",syncTimes)
143
+			syncTimes := time.Unix(sync_time, 0).Format("2006-01-02 15:04")
144
+			utils.InfoLog("syncTimes:%v", syncTimes)
145 145
 
146 146
 			// 第三步:跟进上次同步时间和指定的his_user_id,获取上次同步到现在指定人的检验检查记录
147
-			resultList, _ := service.GetListByHisUserID(patient.HisUserId,syncTimes,patient.SelectType)
147
+			resultList, _ := service.GetListByHisUserID(patient.HisUserId, syncTimes, patient.SelectType)
148 148
 			var syncInfo models.MiddleSyncInfo
149
-	
149
+
150 150
 			if len(resultList) > 0 {
151 151
 				// 如果有数据,则把同步过来的详情插入一条数据到同步详情表中
152 152
 				syncInfo.OrgId = org_id
@@ -156,7 +156,7 @@ func (c *LisController) GetList() {
156 156
 				syncInfo.SyncRsultRemark = "同步成功"
157 157
 				syncInfo.SyncTotalNum = int64(len(resultList))
158 158
 				syncInfo.SyncSuccessNum = 0
159
-				SyncInfos,_ := json.Marshal(resultList)
159
+				SyncInfos, _ := json.Marshal(resultList)
160 160
 				syncInfo.SyncInfo = string(SyncInfos)
161 161
 				syncInfo.CreateTime = time.Now().Unix()
162 162
 				syncInfo.UpdateTime = time.Now().Unix()
@@ -185,18 +185,18 @@ func (c *LisController) GetList() {
185 185
 				}
186 186
 				// utils.InfoLog("同步信息详情:%v",syncInfo)
187 187
 				c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
188
-				continue 
188
+				continue
189 189
 			}
190 190
 
191 191
 			// 第四部:将同步过来的数据插入到中间库对应的表
192 192
 			syncSuccessNum := 0
193 193
 			for _, result := range resultList {
194 194
 				utils.ErrorLog("result:%v", result)
195
-				if (result.HisUserId == patient.HisUserId) || (result.PatientName ==  patient.HisUserId) {
195
+				if (result.HisUserId == patient.HisUserId) || (result.PatientName == patient.HisUserId) {
196 196
 					patientId := patient.XtPatientId
197 197
 					if patientId > 0 {
198
-						inspection_reference,inspection,_ := service.Sync(result,org_id,patientId)
199
-						if (inspection_reference.ID > 0 || inspection.ID > 0 ) {
198
+						inspection_reference, inspection, _ := service.Sync(result, org_id, patientId)
199
+						if inspection_reference.ID > 0 || inspection.ID > 0 {
200 200
 							syncSuccessNum++
201 201
 						}
202 202
 					}
@@ -206,7 +206,7 @@ func (c *LisController) GetList() {
206 206
 			service.UpdateSyncInfo(&syncInfo)
207 207
 
208 208
 			// patientStr = append(patientStr,patient.HisUserId)
209
-			// utils.InfoLog("patientStr:%v",patientStr)	
209
+			// utils.InfoLog("patientStr:%v",patientStr)
210 210
 		}
211 211
 	} else {
212 212
 		var syncInfo models.MiddleSyncInfo
@@ -224,13 +224,12 @@ func (c *LisController) GetList() {
224 224
 			c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
225 225
 			return
226 226
 		}
227
-		utils.InfoLog("同步信息详情:%v",syncInfo)
227
+		utils.InfoLog("同步信息详情:%v", syncInfo)
228 228
 		c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
229
-		return 
229
+		return
230 230
 	}
231 231
 
232
-	utils.InfoLog("patientStr:%v",patientStr) 
233
-
232
+	utils.InfoLog("patientStr:%v", patientStr)
234 233
 
235 234
 	// // 第一步:根据机构id获取上次同步时间
236 235
 	// syncLastInfo,_ := service.GetSyncTimeByOrgID(org_id)
@@ -256,7 +255,7 @@ func (c *LisController) GetList() {
256 255
 	// if len(patients) > 0 {
257 256
 	// 	for _ , patient := range patients {
258 257
 	// 		patientStr = append(patientStr,patient.HisUserId)
259
-	// 		utils.InfoLog("patientStr:%v",patientStr)	
258
+	// 		utils.InfoLog("patientStr:%v",patientStr)
260 259
 	// 	}
261 260
 	// } else {
262 261
 	// 	// 如果没有数据,则插入一条数据到同步详情表中
@@ -275,14 +274,14 @@ func (c *LisController) GetList() {
275 274
 	// 	}
276 275
 	// 	utils.InfoLog("同步信息详情:%v",syncInfo)
277 276
 	// 	c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
278
-	// 	return 
277
+	// 	return
279 278
 	// }
280 279
 
281
-	// utils.InfoLog("patientStr:%v",patientStr) 
280
+	// utils.InfoLog("patientStr:%v",patientStr)
282 281
 
283 282
 	// // 第三步:跟进上次同步时间和指定的his_user_id,获取上次同步到现在指定人的检验检查记录
284 283
 	// resultList, _ := service.GetList(patientStr,syncTimes)
285
-	
284
+
286 285
 	// if len(resultList) > 0 {
287 286
 	// 	// 如果有数据,则把同步过来的详情插入一条数据到同步详情表中
288 287
 	// 	syncInfo.OrgId = org_id
@@ -319,7 +318,7 @@ func (c *LisController) GetList() {
319 318
 	// 	}
320 319
 	// 	// utils.InfoLog("同步信息详情:%v",syncInfo)
321 320
 	// 	c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
322
-	// 	return 
321
+	// 	return
323 322
 	// }
324 323
 
325 324
 	// // 第四部:将同步过来的数据插入到中间库对应的表
@@ -349,7 +348,7 @@ func (c *LisController) GetList() {
349 348
 
350 349
 }
351 350
 
352
-func (c *LisController) SyncLgth(){
351
+func (c *LisController) SyncLgth() {
353 352
 	service.SyncLisLgty()
354 353
 	c.ServeSuccessJSON(map[string]interface{}{
355 354
 		"resultList": "12345",
@@ -357,7 +356,7 @@ func (c *LisController) SyncLgth(){
357 356
 	return
358 357
 }
359 358
 
360
-func (c *LisController) SyncYstx(){
359
+func (c *LisController) SyncYstx() {
361 360
 	service.SyncLisYstx()
362 361
 	c.ServeSuccessJSON(map[string]interface{}{
363 362
 		"resultList": "12345",
@@ -365,7 +364,7 @@ func (c *LisController) SyncYstx(){
365 364
 	return
366 365
 }
367 366
 
368
-func (c *LisController) SyncGzjhyz(){
367
+func (c *LisController) SyncGzjhyz() {
369 368
 	service.SyncGzjhyz()
370 369
 	c.ServeSuccessJSON(map[string]interface{}{
371 370
 		"resultList": "12345",
@@ -373,7 +372,7 @@ func (c *LisController) SyncGzjhyz(){
373 372
 	return
374 373
 }
375 374
 
376
-func (c *LisController) SyncGzjhLis(){
375
+func (c *LisController) SyncGzjhLis() {
377 376
 	service.SyncGzjhLis()
378 377
 	c.ServeSuccessJSON(map[string]interface{}{
379 378
 		"resultList": "12345",
@@ -381,7 +380,7 @@ func (c *LisController) SyncGzjhLis(){
381 380
 	return
382 381
 }
383 382
 
384
-func (c *LisController) SyncHbJldyyz(){
383
+func (c *LisController) SyncHbJldyyz() {
385 384
 	service.SyncHbJldyyz()
386 385
 	c.ServeSuccessJSON(map[string]interface{}{
387 386
 		"resultList": "12345",
@@ -389,10 +388,15 @@ func (c *LisController) SyncHbJldyyz(){
389 388
 	return
390 389
 }
391 390
 
392
-func (c *LisController) SyncHbJldyLis(){
391
+func (c *LisController) SyncHbJldyLis() {
393 392
 	service.SyncHbdyLis()
394 393
 	c.ServeSuccessJSON(map[string]interface{}{
395 394
 		"resultList": "12345",
396 395
 	})
397 396
 	return
398
-}
397
+}
398
+
399
+func (c *LisController) SyncBlLis() {
400
+	service.GetDataInsertDB(10138)
401
+
402
+}

+ 5 - 2
main.go Zobrazit soubor

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

+ 3 - 0
routers/router.go Zobrazit soubor

@@ -17,4 +17,7 @@ func init() {
17 17
 	beego.Router("/api/lis/gzjhlissync", &controllers.LisController{}, "get:SyncGzjhLis")
18 18
 	beego.Router("/api/lis/hbdyyzsync", &controllers.LisController{}, "get:SyncHbJldyyz")
19 19
 	beego.Router("/api/lis/hbdylissync", &controllers.LisController{}, "get:SyncHbJldyLis")
20
+
21
+	beego.Router("/api/lis/bltest", &controllers.LisController{}, "get:SyncBlLis")
22
+
20 23
 }

+ 983 - 0
service/bl_service.go Zobrazit soubor

@@ -0,0 +1,983 @@
1
+package service
2
+
3
+import (
4
+	"fmt"
5
+	"github.com/jinzhu/gorm"
6
+	"strconv"
7
+	"strings"
8
+	"time"
9
+)
10
+
11
+type HisOrder struct {
12
+	ID                 int64        `gorm:"column:id" json:"id" form:"id"`
13
+	UserOrgId          int64        `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
14
+	HisPatientId       int64        `gorm:"column:his_patient_id" json:"his_patient_id" form:"his_patient_id"`
15
+	SettleAccountsDate int64        `gorm:"column:settle_accounts_date" json:"settle_accounts_date" form:"settle_accounts_date"`
16
+	Ctime              int64        `gorm:"column:ctime" json:"ctime" form:"ctime"`
17
+	Mtime              int64        `gorm:"column:mtime" json:"mtime" form:"mtime"`
18
+	Status             int64        `gorm:"column:status" json:"status" form:"status"`
19
+	Number             string       `gorm:"column:number" json:"number" form:"number"`
20
+	PatientId          int64        `gorm:"column:patient_id" json:"patient_id" form:"patient_id"`
21
+	OrderStatus        int64        `gorm:"column:order_status" json:"order_status" form:"order_status"`
22
+	MdtrtId            string       `gorm:"column:mdtrt_id" json:"mdtrt_id" form:"mdtrt_id"`
23
+	XtHisPatient       XtHisPatient `gorm:"ForeignKey:MdtrtId;AssociationForeignKey:Number" json:"his_patient"`
24
+}
25
+
26
+func (HisOrder) TableName() string {
27
+	return "his_order"
28
+}
29
+
30
+type XtHisPatient struct {
31
+	ID                     int64   `gorm:"column:id" json:"id" form:"id"`
32
+	BalanceAccountsType    int64   `gorm:"column:balance_accounts_type" json:"balance_accounts_type" form:"balance_accounts_type"`
33
+	MedicalInsuranceNumber string  `gorm:"column:medical_insurance_number" json:"medical_insurance_number" form:"medical_insurance_number"`
34
+	Name                   string  `gorm:"column:name" json:"name" form:"name"`
35
+	Gender                 int64   `gorm:"column:gender" json:"gender" form:"gender"`
36
+	IdType                 int64   `gorm:"column:id_type" json:"id_type" form:"id_type"`
37
+	MedicalTreatmentType   int64   `gorm:"column:medical_treatment_type" json:"medical_treatment_type" form:"medical_treatment_type"`
38
+	Birthday               int64   `gorm:"column:birthday" json:"birthday" form:"birthday"`
39
+	RecordDate             int64   `gorm:"column:record_date" json:"record_date" form:"record_date"`
40
+	Age                    int64   `gorm:"column:age" json:"age" form:"age"`
41
+	PhoneNumber            string  `gorm:"column:phone_number" json:"phone_number" form:"phone_number"`
42
+	IdCardNo               string  `gorm:"column:id_card_no" json:"id_card_no" form:"id_card_no"`
43
+	RegisterType           int64   `gorm:"column:register_type" json:"register_type" form:"register_type"`
44
+	AdminUserId            int64   `gorm:"column:admin_user_id" json:"admin_user_id" form:"admin_user_id"`
45
+	Departments            int64   `gorm:"column:departments" json:"departments" form:"departments"`
46
+	IsNeedCostOfProduction int64   `gorm:"column:is_need_cost_of_production" json:"is_need_cost_of_production" form:"is_need_cost_of_production"`
47
+	RegisterCost           float64 `gorm:"column:register_cost" json:"register_cost" form:"register_cost"`
48
+	TreatmentCost          float64 `gorm:"column:treatment_cost" json:"treatment_cost" form:"treatment_cost"`
49
+	CostOfProduction       float64 `gorm:"column:cost_of_production" json:"cost_of_production" form:"cost_of_production"`
50
+	Total                  float64 `gorm:"column:total" json:"total" form:"total"`
51
+	UserOrgId              int64   `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
52
+	Status                 int64   `gorm:"column:status" json:"status" form:"status"`
53
+	Ctime                  int64   `gorm:"column:ctime" json:"ctime" form:"ctime"`
54
+	Mtime                  int64   `gorm:"column:mtime" json:"mtime" form:"mtime"`
55
+	PatientId              int64   `gorm:"column:patient_id" json:"patient_id" form:"patient_id"`
56
+	Number                 string  `gorm:"column:number" json:"number" form:"number"`
57
+	Doctor                 int64   `gorm:"column:doctor" json:"doctor" form:"doctor"`
58
+	IsReturn               int64   `gorm:"column:is_return" json:"is_return" form:"is_return"`
59
+	Phone                  string  `gorm:"column:phone" json:"phone" form:"phone"`
60
+	SocialType             int64   `gorm:"column:social_type" json:"social_type" form:"social_type"`
61
+	IdCardType             int64   `gorm:"column:id_card_type" json:"id_card_type" form:"id_card_type"`
62
+	PType                  string  `gorm:"column:p_type" json:"p_type" form:"p_type"`
63
+	Diagnosis              string  `gorm:"column:diagnosis" json:"diagnosis" form:"diagnosis"`
64
+	SickType               int64   `gorm:"column:sick_type" json:"sick_type" form:"sick_type"`
65
+}
66
+
67
+func (XtHisPatient) TableName() string {
68
+	return "his_patient"
69
+}
70
+
71
+type HisPrescription struct {
72
+	ID                 int64    `gorm:"column:id" json:"id" form:"id"`
73
+	UserOrgId          int64    `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
74
+	RecordDate         int64    `gorm:"column:record_date" json:"record_date" form:"record_date"`
75
+	PatientId          int64    `gorm:"column:patient_id" json:"patient_id" form:"patient_id"`
76
+	HisPatientId       int64    `gorm:"column:his_patient_id" json:"his_patient_id" form:"his_patient_id"`
77
+	Status             int64    `gorm:"column:status" json:"status" form:"status"`
78
+	Ctime              int64    `gorm:"column:ctime" json:"ctime" form:"ctime"`
79
+	Mtime              int64    `gorm:"column:mtime" json:"mtime" form:"mtime"`
80
+	Number             string   `gorm:"column:number" json:"number" form:"number"`
81
+	Type               int64    `gorm:"column:type" json:"type" form:"type"`
82
+	Doctor             string   `gorm:"column:doctor" json:"doctor" form:"doctor"`
83
+	Creator            int64    `gorm:"column:creator" json:"creator" form:"creator"`
84
+	Modifier           int64    `gorm:"column:modifier" json:"modifier" form:"modifier"`
85
+	OrderStatus        int64    `gorm:"column:order_status" json:"order_status" form:"order_status"`
86
+	PreTime            int64    `gorm:"column:pre_time" json:"pre_time" form:"pre_time"`
87
+	BatchNumber        string   `gorm:"column:batch_number" json:"batch_number" form:"batch_number"`
88
+	PrescriptionNumber string   `gorm:"column:prescription_number" json:"prescription_number" form:"prescription_number"`
89
+	HisOrder           HisOrder `gorm:"ForeignKey:Number;AssociationForeignKey:BatchNumber" json:"order"`
90
+	Total              string   `gorm:"-" json:"total" form:"total"`
91
+	PType              int64    `gorm:"column:p_type" json:"p_type" form:"p_type"`
92
+	MedType            string   `gorm:"column:med_type" json:"med_type" form:"med_type"`
93
+}
94
+
95
+func (HisPrescription) TableName() string {
96
+	return "his_prescription"
97
+}
98
+
99
+type CmSample struct {
100
+	HospitalBarcode   string    `gorm:"column:hospital_barcode" json:"hospital_barcode" form:"hospital_barcode"`
101
+	Hospsamplenumber  string    `gorm:"column:hospsamplenumber" json:"hospsamplenumber" form:"hospsamplenumber"`
102
+	Pno               string    `gorm:"column:pno" json:"pno" form:"pno"`
103
+	Ptype             string    `gorm:"column:ptype" json:"ptype" form:"ptype"`
104
+	Bedno             string    `gorm:"column:bedno" json:"bedno" form:"bedno"`
105
+	Pname             string    `gorm:"column:pname" json:"pname" form:"pname"`
106
+	Psex              string    `gorm:"column:psex" json:"psex" form:"psex"`
107
+	Page              string    `gorm:"column:page" json:"page" form:"page"`
108
+	Pageunit          string    `gorm:"column:pageunit" json:"pageunit" form:"pageunit"`
109
+	Ptel              string    `gorm:"column:ptel" json:"ptel" form:"ptel"`
110
+	Stature           string    `gorm:"column:stature" json:"stature" form:"stature"`
111
+	Avoirdupois       string    `gorm:"column:avoirdupois" json:"avoirdupois" form:"avoirdupois"`
112
+	Gravweek          string    `gorm:"column:gravweek" json:"gravweek" form:"gravweek"`
113
+	Collectiongravday string    `gorm:"column:collectiongravday" json:"collectiongravday" form:"collectiongravday"`
114
+	Birthday          time.Time `gorm:"column:birthday" json:"birthday" form:"birthday"`
115
+	Departname        string    `gorm:"column:departname" json:"departname" form:"departname"`
116
+	Docname           string    `gorm:"column:docname" json:"docname" form:"docname"`
117
+	Doctortel         string    `gorm:"column:doctortel" json:"doctortel" form:"doctortel"`
118
+	Diagnosis         string    `gorm:"column:diagnosis" json:"diagnosis" form:"diagnosis"`
119
+	Stype             string    `gorm:"column:stype" json:"stype" form:"stype"`
120
+	Samstate          string    `gorm:"column:samstate" json:"samstate" form:"samstate"`
121
+	Desccode          string    `gorm:"column:desccode" json:"desccode" form:"desccode"`
122
+	Descr             string    `gorm:"column:descr" json:"descr" form:"descr"`
123
+	Sampletime        time.Time `gorm:"column:sampletime" json:"sampletime" form:"sampletime"`
124
+	Senddate          time.Time `gorm:"column:senddate" json:"senddate" form:"senddate"`
125
+	Remark            string    `gorm:"column:remark" json:"remark" form:"remark"`
126
+	Idcard            string    `gorm:"column:idcard" json:"idcard" form:"idcard"`
127
+	CardClass         string    `gorm:"column:cardclass" json:"cardclass" form:"cardclass"`
128
+}
129
+
130
+func (CmSample) TableName() string {
131
+	return "v_cm_sample"
132
+}
133
+
134
+type CmLisitems struct {
135
+	ItemCode       string `gorm:"column:item_code" json:"item_code" form:"item_code"`
136
+	ItemName       string `gorm:"column:item_name" json:"item_name" form:"item_name"`
137
+	Testmethod     string `gorm:"column:testmethod" json:"testmethod" form:"testmethod"`
138
+	Iscompound     string `gorm:"column:iscmpound" json:"iscmpound" form:"iscmpound"`
139
+	DepartmentName string `gorm:"column:department_name" json:"department_name" form:"department_name"`
140
+}
141
+
142
+func (CmLisitems) TableName() string {
143
+	return "v_cm_listtems"
144
+}
145
+
146
+type HisLabelPrintInfo struct {
147
+	ID                     int64                  `gorm:"column:id" json:"id" form:"id"`
148
+	PatientId              int64                  `gorm:"column:patient_id" json:"patient_id" form:"patient_id"`
149
+	Number                 string                 `gorm:"column:number" json:"number" form:"number"`
150
+	Ctime                  int64                  `gorm:"column:ctime" json:"ctime" form:"ctime"`
151
+	Mtime                  int64                  `gorm:"column:mtime" json:"mtime" form:"mtime"`
152
+	DoctorId               int64                  `gorm:"column:doctor_id" json:"doctor_id" form:"doctor_id"`
153
+	Status                 int64                  `gorm:"column:status" json:"status" form:"status"`
154
+	ProjectName            string                 `gorm:"column:project_name" json:"project_name" form:"project_name"`
155
+	ProjectId              int64                  `gorm:"column:project_id" json:"project_id" form:"project_id"`
156
+	IsPrint                int64                  `gorm:"column:is_print" json:"is_print" form:"is_print"`
157
+	RecordDate             int64                  `gorm:"column:record_date" json:"record_date" form:"record_date"`
158
+	ItemId                 int64                  `gorm:"column:item_id" json:"item_id" form:"item_id"`
159
+	PProjectId             int64                  `gorm:"column:p_project_id" json:"p_project_id" form:"p_project_id"`
160
+	UserOrgId              int64                  `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
161
+	DoctorName             string                 `gorm:"column:doctor_name" json:"doctor_name" form:"doctor_name"`
162
+	PatientName            string                 `gorm:"column:patient_name" json:"patient_name" form:"patient_name"`
163
+	FeedetlSn              string                 `gorm:"column:feedetl_sn" json:"feedetl_sn" form:"feedetl_sn"`
164
+	PrescriptionId         int64                  `gorm:"column:prescription_id" json:"prescription_id" form:"prescription_id"`
165
+	HisPrescriptionProject HisPrescriptionProject `gorm:"ForeignKey:ID;AssociationForeignKey:PProjectId" json:"project"`
166
+}
167
+
168
+func (HisLabelPrintInfo) TableName() string {
169
+	return "his_label_print_info"
170
+}
171
+
172
+type LisSyncProcessStatusInfo struct {
173
+	ID         int64 `gorm:"column:id" json:"id" form:"id"`
174
+	Ctime      int64 `gorm:"column:ctime" json:"ctime" form:"ctime"`
175
+	Mtime      int64 `gorm:"column:mtime" json:"mtime" form:"mtime"`
176
+	Status     int64 `gorm:"column:status" json:"status" form:"status"`
177
+	LastId     int64 `gorm:"column:last_id" json:"last_id" form:"last_id"`
178
+	OrgId      int64 `gorm:"column:org_id" json:"org_id" form:"org_id"`
179
+	IsInsert   int64 `gorm:"column:is_insert" json:"is_insert" form:"is_insert"`
180
+	IsResult   int64 `gorm:"column:is_result" json:"is_result" form:"is_result"`
181
+	ResultDate int64 `gorm:"column:result_date" json:"result_date" form:"result_date"`
182
+}
183
+
184
+func (LisSyncProcessStatusInfo) TableName() string {
185
+	return "lis_sync_process_status_info"
186
+}
187
+
188
+type CmResult struct {
189
+	Barcode   string `gorm:"column:barcode" json:"barcode" form:"barcode"`
190
+	Itemcode  string `gorm:"column:itemcode" json:"itemcode" form:"itemcode"`
191
+	Itemname  string `gorm:"column:itemname" json:"itemname" form:"itemname"`
192
+	Unit      string `gorm:"column:unit" json:"unit" form:"unit"`
193
+	Result    string `gorm:"column:result" json:"result" form:"result"`
194
+	Refrange  string `gorm:"column:refrange" json:"refrange" form:"refrange"`
195
+	Ts        string `gorm:"column:ts" json:"ts" form:"ts"`
196
+	Jyys      string `gorm:"column:jyys" json:"jyys" form:"jyys"`
197
+	Shys      string `gorm:"column:shys" json:"shys" form:"shys"`
198
+	Hycode    string `gorm:"column:hycode" json:"hycode" form:"hycode"`
199
+	Reptype   string `gorm:"column:reptype" json:"reptype" form:"reptype"`
200
+	TJH       string `gorm:"column:tjh" json:"tjh" form:"tjh"`
201
+	Repdate   string `gorm:"column:repdate" json:"repdate" form:"repdate"`
202
+	Groupname string `gorm:"column:groupname" json:"groupname" form:"groupname"`
203
+	Groupcode string `gorm:"column:groupcode" json:"groupcode" form:"groupcode"`
204
+	Brkb      string `gorm:"column:brkb" json:"brkb" form:"brkb"`
205
+	Mic       string `gorm:"column:mic" json:"mic" form:"mic"`
206
+	Yjjy      string `gorm:"column:yjjy" json:"yjjy" form:"yjjy"`
207
+	Name      string `gorm:"column:name" json:"name" form:"name"`
208
+}
209
+
210
+func (CmResult) TableName() string {
211
+	return "v_cm_result"
212
+}
213
+
214
+type LisSyncResultStatusInfo struct {
215
+	ID         int64 `gorm:"column:id" json:"id" form:"id"`
216
+	Ctime      int64 `gorm:"column:ctime" json:"ctime" form:"ctime"`
217
+	Mtime      int64 `gorm:"column:mtime" json:"mtime" form:"mtime"`
218
+	Status     int64 `gorm:"column:status" json:"status" form:"status"`
219
+	LastId     int64 `gorm:"column:last_id" json:"last_id" form:"last_id"`
220
+	OrgId      int64 `gorm:"column:org_id" json:"org_id" form:"org_id"`
221
+	IsResult   int64 `gorm:"column:is_result" json:"is_result" form:"is_result"`
222
+	ResultDate int64 `gorm:"column:result_date" json:"result_date" form:"result_date"`
223
+}
224
+
225
+func (LisSyncResultStatusInfo) TableName() string {
226
+	return "lis_sync_result_status_info"
227
+}
228
+
229
+func GetLastSyncRecord(org_id int64) (record LisSyncProcessStatusInfo, err error) {
230
+	err = readMiddleDb.Model(&LisSyncProcessStatusInfo{}).Where("org_id = ? AND status = 1", org_id).Last(&record).Error
231
+	return
232
+}
233
+
234
+func GetLastSyncResultRecord(org_id int64) (record LisSyncResultStatusInfo, err error) {
235
+	err = readDb.Model(&LisSyncResultStatusInfo{}).Where("org_id = ? AND status = 1", org_id).Last(&record).Error
236
+	return
237
+}
238
+
239
+func GetResultRecord() (record []*CmResult, err error) {
240
+	err = dataBase.Model(&CmResult{}).Order("barcode desc").Find(&record).Error
241
+	return
242
+}
243
+
244
+func GetResultRecordByID(id int64) (record []*CmResult, err error) {
245
+	err = readDb.Model(&CmResult{}).Where("barcode > ?", id).Order("barcode desc").Find(&record).Error
246
+	return
247
+}
248
+
249
+func GetSaveResultRecord(record LisSyncResultStatusInfo) (err error) {
250
+	err = dataBase.Save(record).Error
251
+	return
252
+}
253
+
254
+func GetLisDataById(org_id int64, last_id int64) (list []*HisLabelPrintInfo, err error) {
255
+	//err = readDb.Model(&HisLabelPrintInfo{}).Where("id > ? AND user_org_id = ? AND status = 1", last_id, org_id).Find(&list).Error
256
+
257
+	err = readDb.Model(&HisLabelPrintInfo{}).Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
258
+		return db.Preload("HisPrescription", func(db *gorm.DB) *gorm.DB {
259
+			return db.Preload("HisOrder", func(db *gorm.DB) *gorm.DB {
260
+				return db.Preload("XtHisPatient", func(db *gorm.DB) *gorm.DB {
261
+					return db.Where("status = 1")
262
+				}).Where("status = 1")
263
+			}).Where("status = 1")
264
+		}).Where("status = 1")
265
+	}).Where("id > ? AND user_org_id = ? AND status = 1", last_id, org_id).Limit(100).Find(&list).Error
266
+	return
267
+}
268
+
269
+func GetAllLisData(org_id int64) (list []*HisLabelPrintInfo, err error) {
270
+	err = readDb.Model(&HisLabelPrintInfo{}).Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
271
+		return db.Preload("HisPrescription", func(db *gorm.DB) *gorm.DB {
272
+			return db.Preload("HisOrder", func(db *gorm.DB) *gorm.DB {
273
+				return db.Preload("XtHisPatient", func(db *gorm.DB) *gorm.DB {
274
+					return db.Where("status = 1")
275
+				}).Where("status = 1")
276
+			}).Where("status = 1")
277
+		}).Where("status = 1")
278
+	}).Where("user_org_id = ? AND status = 1", org_id).Limit(100).Find(&list).Error
279
+	return
280
+}
281
+
282
+func GetAllLisResultData(org_id int64) (list []*CmResult, err error) {
283
+	err = readDb.Model(&CmResult{}).Where("user_org_id = ? AND status = 1 ", org_id).Find(&list).Error
284
+	return
285
+}
286
+
287
+func GetLisResultDataByRecord(org_id int64) (list []*CmResult, err error) {
288
+	err = readDb.Model(&CmResult{}).Where("user_org_id = ? AND status = 1", org_id).Find(&list).Error
289
+	return
290
+}
291
+
292
+//插入中间件逻辑
293
+func GetDataInsertDB(org_id int64) {
294
+	record, _ := GetLastSyncRecord(org_id)
295
+	if record.ID == 0 {
296
+		var cms_arr []CmSample
297
+		list, _ := GetAllLisData(org_id)
298
+		//插入中间库中
299
+		for _, item := range list {
300
+			fmt.Println(item.HisPrescriptionProject)
301
+
302
+			if item.ItemId > 0 {
303
+
304
+				var cms CmSample
305
+				cms.HospitalBarcode = strconv.FormatInt(item.ID, 10)
306
+				cms.Pno = item.HisPrescriptionProject.HisPrescription.HisOrder.MdtrtId
307
+				cms.Ptype = "门诊"
308
+				cms.Pname = item.HisPrescriptionProject.HisPrescription.HisOrder.XtHisPatient.Name
309
+				if item.HisPrescriptionProject.HisPrescription.HisOrder.XtHisPatient.Gender == 1 {
310
+					cms.Psex = "男"
311
+				} else if item.HisPrescriptionProject.HisPrescription.HisOrder.XtHisPatient.Gender == 2 {
312
+					cms.Psex = "女"
313
+				}
314
+				cms.Page = strconv.FormatInt(item.HisPrescriptionProject.HisPrescription.HisOrder.XtHisPatient.Age, 10)
315
+				cms.Pageunit = "岁"
316
+				cms.Departname = "肾病学专业"
317
+				role, _ := GetAdminUserInfoByID(org_id, item.HisPrescriptionProject.HisPrescription.HisOrder.XtHisPatient.Doctor)
318
+				cms.Docname = role.UserName
319
+
320
+				diagnosis_ids := strings.Split(item.HisPrescriptionProject.HisPrescription.HisOrder.XtHisPatient.Diagnosis, ",")
321
+
322
+				//var config []*models.HisXtDiagnoseConfig
323
+				var name string
324
+				for _, item := range diagnosis_ids {
325
+					id, _ := strconv.ParseInt(item, 10, 64)
326
+					diagnosisConfig, _ := FindDiagnoseById(id)
327
+					if len(name) == 0 {
328
+						name = diagnosisConfig.ClassName
329
+
330
+					} else {
331
+						name = name + "," + diagnosisConfig.ClassName
332
+					}
333
+				}
334
+
335
+				cms.Diagnosis = name
336
+				cms.Stype = ""
337
+				cms.Samstate = ""
338
+				cms.Desccode = strconv.FormatInt(item.ID, 10)
339
+				cms.Descr = item.ProjectName
340
+
341
+				data, _ := strconv.ParseInt(strconv.FormatInt(item.Ctime, 10), 10, 64)
342
+				datatime := time.Unix(data/1000, 0)
343
+				cms.Sampletime = datatime
344
+				cms.Senddate = time.Now()
345
+				cms_arr = append(cms_arr, cms)
346
+
347
+			} else {
348
+				var cms CmSample
349
+				cms.HospitalBarcode = strconv.FormatInt(item.ID, 10)
350
+				cms.Pno = item.HisPrescriptionProject.HisPrescription.HisOrder.MdtrtId
351
+				cms.Ptype = "门诊"
352
+				cms.Pname = item.HisPrescriptionProject.HisPrescription.HisOrder.XtHisPatient.Name
353
+				if item.HisPrescriptionProject.HisPrescription.HisOrder.XtHisPatient.Gender == 1 {
354
+					cms.Psex = "男"
355
+				} else if item.HisPrescriptionProject.HisPrescription.HisOrder.XtHisPatient.Gender == 2 {
356
+					cms.Psex = "女"
357
+				}
358
+				cms.Page = strconv.FormatInt(item.HisPrescriptionProject.HisPrescription.HisOrder.XtHisPatient.Age, 10)
359
+				cms.Pageunit = "岁"
360
+				cms.Departname = "肾病学专业"
361
+				role, _ := GetAdminUserInfoByID(org_id, item.HisPrescriptionProject.HisPrescription.HisOrder.XtHisPatient.Doctor)
362
+				cms.Docname = role.UserName
363
+
364
+				diagnosis_ids := strings.Split(item.HisPrescriptionProject.HisPrescription.HisOrder.XtHisPatient.Diagnosis, ",")
365
+
366
+				//var config []*models.HisXtDiagnoseConfig
367
+				var name string
368
+				for _, item := range diagnosis_ids {
369
+					id, _ := strconv.ParseInt(item, 10, 64)
370
+					diagnosisConfig, _ := FindDiagnoseById(id)
371
+					if len(name) == 0 {
372
+						name = diagnosisConfig.ClassName
373
+
374
+					} else {
375
+						name = name + "," + diagnosisConfig.ClassName
376
+					}
377
+				}
378
+
379
+				cms.Diagnosis = name
380
+				cms.Stype = ""
381
+				cms.Samstate = ""
382
+				cms.Desccode = strconv.FormatInt(item.ID, 10)
383
+				cms.Descr = item.ProjectName
384
+
385
+				tm := time.Unix(item.Ctime, 0)
386
+				//data, _ := strconv.ParseInt(strconv.FormatInt(item.Ctime, 10), 10, 64)
387
+				//datatime := time.Unix(data/1000, 0)
388
+				cms.Sampletime = tm
389
+				cms.Senddate = time.Now()
390
+				cms_arr = append(cms_arr, cms)
391
+			}
392
+		}
393
+		//插入到中间库
394
+		for _, item := range cms_arr {
395
+			if len(item.Pno) > 0 {
396
+				blDb.Save(item)
397
+			}
398
+		}
399
+		//插入一条插入中间库记录数据
400
+		var info LisSyncProcessStatusInfo
401
+		info.Ctime = time.Now().Unix()
402
+		info.Status = 1
403
+		info.Mtime = time.Now().Unix()
404
+		info.OrgId = org_id
405
+		info.IsInsert = 1
406
+		info.IsResult = 0
407
+		info.LastId = list[len(list)-1].ID
408
+		info.ResultDate = 0
409
+		writeMiddleDb.Save(&info)
410
+
411
+	} else {
412
+		var cms_arr []CmSample
413
+		if record.LastId != 0 {
414
+			list, _ := GetLisDataById(org_id, record.LastId)
415
+
416
+			//插入中间库中
417
+			for _, item := range list {
418
+				if item.ItemId > 0 {
419
+					fmt.Println()
420
+					//teams, _ := GetProjectTeamList(org_id, item.ItemId, item.PrescriptionId)
421
+					//for _, subItem := range teams {
422
+					var cms CmSample
423
+					cms.HospitalBarcode = strconv.FormatInt(item.ID, 10)
424
+					//cms.Hospsamplenumber = strconv.FormatInt(item.ID, 10)
425
+					cms.Pno = item.HisPrescriptionProject.HisPrescription.HisOrder.MdtrtId
426
+					cms.Ptype = "门诊"
427
+					cms.Pname = item.HisPrescriptionProject.HisPrescription.HisOrder.XtHisPatient.Name
428
+					if item.HisPrescriptionProject.HisPrescription.HisOrder.XtHisPatient.Gender == 1 {
429
+						cms.Psex = "男"
430
+					} else if item.HisPrescriptionProject.HisPrescription.HisOrder.XtHisPatient.Gender == 2 {
431
+						cms.Psex = "女"
432
+					}
433
+					cms.Page = strconv.FormatInt(item.HisPrescriptionProject.HisPrescription.HisOrder.XtHisPatient.Age, 10)
434
+					cms.Pageunit = "岁"
435
+					cms.Departname = "肾病学专业"
436
+					role, _ := GetAdminUserInfoByID(org_id, item.HisPrescriptionProject.HisPrescription.HisOrder.XtHisPatient.Doctor)
437
+					cms.Docname = role.UserName
438
+					diagnosis_ids := strings.Split(item.HisPrescriptionProject.HisPrescription.HisOrder.XtHisPatient.Diagnosis, ",")
439
+					//var config []*models.HisXtDiagnoseConfig
440
+					var name string
441
+					for _, item := range diagnosis_ids {
442
+						id, _ := strconv.ParseInt(item, 10, 64)
443
+						diagnosisConfig, _ := FindDiagnoseById(id)
444
+						if len(name) == 0 {
445
+							name = diagnosisConfig.ClassName
446
+
447
+						} else {
448
+							name = name + "," + diagnosisConfig.ClassName
449
+						}
450
+					}
451
+					cms.Diagnosis = name
452
+					cms.Stype = ""
453
+					cms.Samstate = ""
454
+					cms.Desccode = strconv.FormatInt(item.ID, 10)
455
+					cms.Descr = item.ProjectName
456
+
457
+					//data, _ := strconv.ParseInt(strconv.FormatInt(item.Ctime, 10), 10, 64)
458
+					//datatime := time.Unix(data/1000, 0)
459
+					//cms.Sampletime = datatime
460
+					tm := time.Unix(item.Ctime, 0)
461
+					cms.Sampletime = tm
462
+					cms.Senddate = time.Now()
463
+					cms_arr = append(cms_arr, cms)
464
+				} else {
465
+					var cms CmSample
466
+					cms.HospitalBarcode = strconv.FormatInt(item.ID, 10)
467
+					//cms.Hospsamplenumber = strconv.FormatInt(item.ID, 10)
468
+					cms.Pno = item.HisPrescriptionProject.HisPrescription.HisOrder.MdtrtId
469
+					cms.Ptype = "门诊"
470
+					cms.Pname = item.HisPrescriptionProject.HisPrescription.HisOrder.XtHisPatient.Name
471
+					if item.HisPrescriptionProject.HisPrescription.HisOrder.XtHisPatient.Gender == 1 {
472
+						cms.Psex = "男"
473
+					} else if item.HisPrescriptionProject.HisPrescription.HisOrder.XtHisPatient.Gender == 2 {
474
+						cms.Psex = "女"
475
+					}
476
+					cms.Page = strconv.FormatInt(item.HisPrescriptionProject.HisPrescription.HisOrder.XtHisPatient.Age, 10)
477
+					cms.Pageunit = "岁"
478
+					cms.Departname = "肾病学专业"
479
+					role, _ := GetAdminUserInfoByID(org_id, item.HisPrescriptionProject.HisPrescription.HisOrder.XtHisPatient.Doctor)
480
+					cms.Docname = role.UserName
481
+					diagnosis_ids := strings.Split(item.HisPrescriptionProject.HisPrescription.HisOrder.XtHisPatient.Diagnosis, ",")
482
+					var name string
483
+					for _, item := range diagnosis_ids {
484
+						id, _ := strconv.ParseInt(item, 10, 64)
485
+						diagnosisConfig, _ := FindDiagnoseById(id)
486
+						if len(name) == 0 {
487
+							name = diagnosisConfig.ClassName
488
+
489
+						} else {
490
+							name = name + "," + diagnosisConfig.ClassName
491
+						}
492
+					}
493
+
494
+					cms.Diagnosis = name
495
+					cms.Stype = ""
496
+					cms.Samstate = ""
497
+					cms.Desccode = strconv.FormatInt(item.ID, 10)
498
+					cms.Descr = item.ProjectName
499
+					tm := time.Unix(item.Ctime, 0)
500
+					cms.Sampletime = tm
501
+					cms.Senddate = time.Now()
502
+					cms_arr = append(cms_arr, cms)
503
+				}
504
+			}
505
+			//插入一条插入中间库记录数据
506
+			for _, item := range cms_arr {
507
+				if len(item.Pno) > 0 {
508
+					blDb.Save(item)
509
+				}
510
+			}
511
+			//插入一条插入中间库记录数据
512
+			var info LisSyncProcessStatusInfo
513
+			info.Ctime = time.Now().Unix()
514
+			info.Status = 1
515
+			info.Mtime = time.Now().Unix()
516
+			info.OrgId = org_id
517
+			info.IsInsert = 1
518
+			info.IsResult = 0
519
+			info.LastId = list[len(list)-1].ID
520
+			info.ResultDate = 0
521
+			writeMiddleDb.Save(&info)
522
+		}
523
+	}
524
+}
525
+
526
+//获取lis返回检验检查结果数据
527
+func GetResultDataInsertDB(org_id int64) (result []*CmResult) {
528
+	record, _ := GetLastSyncResultRecord(org_id)
529
+	if record.ID == 0 {
530
+		list, err := GetResultRecord()
531
+		if err == nil {
532
+			//插入一条查询检验检查结果记录状态数据
533
+			var info LisSyncResultStatusInfo
534
+			info.Ctime = time.Now().Unix()
535
+			info.Status = 1
536
+			info.Mtime = time.Now().Unix()
537
+			info.OrgId = org_id
538
+			info.IsResult = 1
539
+			code, _ := strconv.ParseInt(list[0].Barcode, 10, 64)
540
+			info.LastId = code
541
+			info.ResultDate = time.Now().Unix()
542
+			writeMiddleDb.Save(&info)
543
+			//插入到系统检验检查数据
544
+			//for _, item  := range list{}
545
+			//for _, item := range list {
546
+			//
547
+			//	project_id := int64(0)
548
+			//	if len(item.Barcode) > 0 {
549
+			//		project_id, _ = GetGzjhProjectID(org_id, item.Groupname)
550
+			//	} else {
551
+			//		continue
552
+			//	}
553
+			//	printInfo, _ := GetHisLabelPrintInfoById(item.Barcode)
554
+			//
555
+			//	item_id, _ := GetItemID(org_id, item.Groupname, item.Itemname, project_id)
556
+			//
557
+			//	tx := writeMiddleDb.Begin()
558
+			//	var inspection models.MiddleInspection
559
+			//	var inspection_reference models.MiddleInspectionReference
560
+			//
561
+			//	recordDateStr := ""
562
+			//
563
+			//	if len(item.Repdate) == 0 {
564
+			//		recordDateStr = time.Now().Format("2006-01-02 15:04")
565
+			//	}
566
+			//
567
+			//	inspect_date := item.Repdate
568
+			//	date, _ := utils.ParseTimeStringToTime("2006-01-02 15:04", recordDateStr)
569
+			//	record_date, _ := utils.ParseTimeStringToTime("2006-01-02", date.Format("2006-01-02"))
570
+			//	var total int
571
+			//	var RangeOptions string
572
+			//	var RangeMin string
573
+			//	var RangeMax string
574
+			//	// 判断检查类型
575
+			//	var ItemType int
576
+			//	if strings.Contains(item.Refrange, "[") && strings.Contains(item.Refrange, "]") {
577
+			//		ItemType = 1
578
+			//
579
+			//	} else {
580
+			//		ItemType = 2
581
+			//
582
+			//	}
583
+			//
584
+			//	if ItemType == 1 {
585
+			//		item.Refrange = strings.Trim(item.Refrange, "[")
586
+			//		item.Refrange = strings.Trim(item.Refrange, "]")
587
+			//		Range := strings.Split(item.Refrange, "-")
588
+			//		RangeMin = Range[0]
589
+			//		RangeMax = Range[1]
590
+			//	} else {
591
+			//		RangeOptions = item.Refrange
592
+			//	}
593
+			//
594
+			//	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
595
+			//	if inspection_reference.ID > 0 {
596
+			//		ItemType = inspection_reference.RangeType
597
+			//	}
598
+			//	if total <= 0 {
599
+			//		inspection_reference.OrgId = org_id
600
+			//		inspection_reference.ProjectName = item.Groupname
601
+			//		inspection_reference.Project = item.Groupname
602
+			//		inspection_reference.ProjectId = project_id
603
+			//		inspection_reference.ItemName = item.Itemname
604
+			//		inspection_reference.ItemNameAddition = item.Barcode
605
+			//		inspection_reference.ItemId = item_id
606
+			//		inspection_reference.RangeType = ItemType
607
+			//		inspection_reference.RangeMin = RangeMin
608
+			//		inspection_reference.RangeMax = RangeMax
609
+			//		inspection_reference.RangeOptions = RangeOptions
610
+			//		inspection_reference.Unit = item.Unit
611
+			//		inspection_reference.Status = 1
612
+			//		inspection_reference.CreatedTime = time.Now().Unix()
613
+			//		inspection_reference.UpdatedTime = time.Now().Unix()
614
+			//		inspection_reference.InspectDate = inspect_date
615
+			//		inspection_reference.UTime = inspect_date
616
+			//		err = tx.Model(&models.MiddleInspectionReference{}).Create(&inspection_reference).Error
617
+			//		if err != nil {
618
+			//			tx.Rollback()
619
+			//		}
620
+			//	}
621
+			//
622
+			//	var itotal int
623
+			//	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, printInfo.PatientId).Find(&inspection).Count(&itotal).Error
624
+			//	if itotal <= 0 {
625
+			//		//item.Result = strings.Replace(item.Result, "&gt;", ">", -1)
626
+			//		//item.Result = strings.Replace(item.Result, "&lt;", "<", -1)
627
+			//		inspection.PatientId = printInfo.PatientId
628
+			//		inspection.OrgId = org_id
629
+			//		inspection.ProjectId = project_id
630
+			//		inspection.ItemName = inspection_reference.ItemName
631
+			//		inspection.ProjectName = inspection_reference.ProjectName
632
+			//		inspection.InspectType = ItemType
633
+			//		inspection.ItemId = item_id
634
+			//		inspection.InspectValue = item.Result
635
+			//		inspection.InspectDate = inspect_date
636
+			//		inspection.RecordDate = record_date.Unix()
637
+			//		inspection.Status = 1
638
+			//		inspection.CreatedTime = time.Now().Unix()
639
+			//		inspection.UpdatedTime = time.Now().Unix()
640
+			//		inspection.UTime = inspect_date
641
+			//		inspection.HisUserId = strconv.FormatInt(printInfo.PatientId, 10)
642
+			//		err = tx.Model(&models.MiddleInspection{}).Create(&inspection).Error
643
+			//		if err != nil {
644
+			//			tx.Rollback()
645
+			//		}
646
+			//	}
647
+			//
648
+			//	tx.Commit()
649
+			//
650
+			//}
651
+
652
+		}
653
+
654
+	} else {
655
+		if record.LastId != 0 {
656
+			list, err := GetResultRecordByID(record.LastId)
657
+			//插入中间库中
658
+			//插入一条插入中间库记录数据
659
+			if err == nil {
660
+
661
+				//插入一条查询检验检查结果记录状态数据
662
+				var info LisSyncResultStatusInfo
663
+				info.Ctime = time.Now().Unix()
664
+				info.Status = 1
665
+				info.Mtime = time.Now().Unix()
666
+				info.OrgId = org_id
667
+				info.IsResult = 1
668
+				code, _ := strconv.ParseInt(list[0].Barcode, 10, 64)
669
+				info.LastId = code
670
+				info.ResultDate = time.Now().Unix()
671
+				writeMiddleDb.Save(&info)
672
+				//插入到系统检验检查数据
673
+				//for _, item := range list {
674
+				//
675
+				//	project_id := int64(0)
676
+				//	if len(item.Barcode) > 0 {
677
+				//		project_id, _ = GetGzjhProjectID(org_id, item.Groupname)
678
+				//	} else {
679
+				//		continue
680
+				//	}
681
+				//	printInfo, _ := GetHisLabelPrintInfoById(item.Barcode)
682
+				//
683
+				//	item_id, _ := GetItemID(org_id, item.Groupname, item.Itemname, project_id)
684
+				//
685
+				//	tx := writeMiddleDb.Begin()
686
+				//	var inspection models.MiddleInspection
687
+				//	var inspection_reference models.MiddleInspectionReference
688
+				//
689
+				//	recordDateStr := ""
690
+				//
691
+				//	if len(item.Repdate) == 0 {
692
+				//		recordDateStr = time.Now().Format("2006-01-02 15:04")
693
+				//	}
694
+				//
695
+				//	inspect_date := item.Repdate
696
+				//	date, _ := utils.ParseTimeStringToTime("2006-01-02 15:04", recordDateStr)
697
+				//	record_date, _ := utils.ParseTimeStringToTime("2006-01-02", date.Format("2006-01-02"))
698
+				//	var total int
699
+				//	var RangeOptions string
700
+				//	var RangeMin string
701
+				//	var RangeMax string
702
+				//	// 判断检查类型
703
+				//	var ItemType int
704
+				//	if strings.Contains(item.Refrange, "[") && strings.Contains(item.Refrange, "]") {
705
+				//		ItemType = 1
706
+				//
707
+				//	} else {
708
+				//		ItemType = 2
709
+				//
710
+				//	}
711
+				//
712
+				//	if ItemType == 1 {
713
+				//		item.Refrange = strings.Trim(item.Refrange, "[")
714
+				//		item.Refrange = strings.Trim(item.Refrange, "]")
715
+				//		Range := strings.Split(item.Refrange, "-")
716
+				//		RangeMin = Range[0]
717
+				//		RangeMax = Range[1]
718
+				//	} else {
719
+				//		RangeOptions = item.Refrange
720
+				//	}
721
+				//
722
+				//	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
723
+				//	if inspection_reference.ID > 0 {
724
+				//		ItemType = inspection_reference.RangeType
725
+				//	}
726
+				//	if total <= 0 {
727
+				//		inspection_reference.OrgId = org_id
728
+				//		inspection_reference.ProjectName = item.Groupname
729
+				//		inspection_reference.Project = item.Groupname
730
+				//		inspection_reference.ProjectId = project_id
731
+				//		inspection_reference.ItemName = item.Itemname
732
+				//		inspection_reference.ItemNameAddition = item.Barcode
733
+				//		inspection_reference.ItemId = item_id
734
+				//		inspection_reference.RangeType = ItemType
735
+				//		inspection_reference.RangeMin = RangeMin
736
+				//		inspection_reference.RangeMax = RangeMax
737
+				//		inspection_reference.RangeOptions = RangeOptions
738
+				//		inspection_reference.Unit = item.Unit
739
+				//		inspection_reference.Status = 1
740
+				//		inspection_reference.CreatedTime = time.Now().Unix()
741
+				//		inspection_reference.UpdatedTime = time.Now().Unix()
742
+				//		inspection_reference.InspectDate = inspect_date
743
+				//		inspection_reference.UTime = inspect_date
744
+				//		err = tx.Model(&models.MiddleInspectionReference{}).Create(&inspection_reference).Error
745
+				//		if err != nil {
746
+				//			tx.Rollback()
747
+				//		}
748
+				//	}
749
+				//
750
+				//	var itotal int
751
+				//	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, printInfo.PatientId).Find(&inspection).Count(&itotal).Error
752
+				//	if itotal <= 0 {
753
+				//		//item.Result = strings.Replace(item.Result, "&gt;", ">", -1)
754
+				//		//item.Result = strings.Replace(item.Result, "&lt;", "<", -1)
755
+				//		inspection.PatientId = printInfo.PatientId
756
+				//		inspection.OrgId = org_id
757
+				//		inspection.ProjectId = project_id
758
+				//		inspection.ItemName = inspection_reference.ItemName
759
+				//		inspection.ProjectName = inspection_reference.ProjectName
760
+				//		inspection.InspectType = ItemType
761
+				//		inspection.ItemId = item_id
762
+				//		inspection.InspectValue = item.Result
763
+				//		inspection.InspectDate = inspect_date
764
+				//		inspection.RecordDate = record_date.Unix()
765
+				//		inspection.Status = 1
766
+				//		inspection.CreatedTime = time.Now().Unix()
767
+				//		inspection.UpdatedTime = time.Now().Unix()
768
+				//		inspection.UTime = inspect_date
769
+				//		inspection.HisUserId = strconv.FormatInt(printInfo.PatientId, 10)
770
+				//		err = tx.Model(&models.MiddleInspection{}).Create(&inspection).Error
771
+				//		if err != nil {
772
+				//			tx.Rollback()
773
+				//		}
774
+				//	}
775
+				//
776
+				//	tx.Commit()
777
+				//
778
+				//}
779
+
780
+			}
781
+
782
+		}
783
+
784
+	}
785
+	return
786
+
787
+}
788
+
789
+func GetAdminUserInfoByID(org_id int64, admin_user_id int64) (role UserAdminRole, err error) {
790
+	err = readUserDb.Model(&UserAdminRole{}).Where("org_id = ? AND status = 1 AND admin_user_id = ?", org_id, admin_user_id).First(&role).Error
791
+	return
792
+}
793
+
794
+type UserAdminRole struct {
795
+	ID                                      int64  `gorm:"column:id" json:"id" form:"id"`
796
+	AdminUserId                             int64  `gorm:"column:admin_user_id" json:"admin_user_id" form:"admin_user_id"`
797
+	OrgId                                   int64  `gorm:"column:org_id" json:"org_id" form:"org_id"`
798
+	AppId                                   int64  `gorm:"column:app_id" json:"app_id" form:"app_id"`
799
+	RoleId                                  int64  `gorm:"column:role_id" json:"role_id" form:"role_id"`
800
+	UserName                                string `gorm:"column:user_name" json:"user_name" form:"user_name"`
801
+	Avatar                                  string `gorm:"column:avatar" json:"avatar" form:"avatar"`
802
+	UserType                                int64  `gorm:"column:user_type" json:"user_type" form:"user_type"`
803
+	UserTitle                               int64  `gorm:"column:user_title" json:"user_title" form:"user_title"`
804
+	Intro                                   string `gorm:"column:intro" json:"intro" form:"intro"`
805
+	Status                                  int64  `gorm:"column:status" json:"status" form:"status"`
806
+	Ctime                                   int64  `gorm:"column:ctime" json:"ctime" form:"ctime"`
807
+	Mtime                                   int64  `gorm:"column:mtime" json:"mtime" form:"mtime"`
808
+	UserTitleName                           string `gorm:"column:user_title_name" json:"user_title_name" form:"user_title_name"`
809
+	RoleIds                                 string `gorm:"column:role_ids" json:"role_ids" form:"role_ids"`
810
+	Message                                 string `gorm:"column:message" json:"message" form:"message"`
811
+	Sex                                     int64  `gorm:"column:sex" json:"sex" form:"sex"`
812
+	Birthday                                int64  `gorm:"column:birthday" json:"birthday" form:"birthday"`
813
+	Sort                                    int64  `gorm:"column:sort" json:"sort" form:"sort"`
814
+	IsSort                                  int64  `gorm:"column:is_sort" json:"is_sort" form:"is_sort"`
815
+	Department                              string `gorm:"column:department" json:"department" form:"department"`
816
+	DepartmentId                            int64  `gorm:"column:department_id" json:"department_id" form:"department_id"`
817
+	Age                                     int64  `gorm:"column:age" json:"age" form:"age"`
818
+	Nation                                  string `gorm:"column:nation" json:"nation" form:"nation"`
819
+	CardType                                int64  `gorm:"column:card_type" json:"card_type" form:"card_type"`
820
+	IdCard                                  string `gorm:"column:id_card" json:"id_card" form:"id_card"`
821
+	Education                               int64  `gorm:"column:education" json:"education" form:"education"`
822
+	StudyMajorName                          string `gorm:"column:study_major_name" json:"study_major_name" form:"study_major_name"`
823
+	WorkMajorName                           string `gorm:"column:work_major_name" json:"work_major_name" form:"work_major_name"`
824
+	RoleType                                int64  `gorm:"column:role_type" json:"role_type" form:"role_type"`
825
+	MedicalCode                             string `gorm:"column:medical_code" json:"medical_code" form:"medical_code"`
826
+	DoctorCode                              string `gorm:"column:doctor_code" json:"doctor_code" form:"doctor_code"`
827
+	Licensing                               int64  `gorm:"column:licensing" json:"licensing" form:"licensing"`
828
+	JobNumber                               string `gorm:"column:job_number" json:"job_number" form:"job_number"`
829
+	PrescriptionQualificationIdentification int64  `gorm:"column:prescription_qualification_identification" json:"prescription_qualification_identification" form:"prescription_qualification_identification"`
830
+	IdentificationOutpatients               int64  `gorm:"column:identification_outpatients" json:"identification_outpatients" form:"identification_outpatients"`
831
+	StartTime                               int64  `gorm:"column:start_time" json:"start_time" form:"start_time"`
832
+	MedicalRangeCode                        int64  `gorm:"column:medical_range_code" json:"medical_range_code" form:"medical_range_code"`
833
+	MedicalLevel                            int64  `gorm:"column:medical_level" json:"medical_level" form:"medical_level"`
834
+	MedicalTypeJob                          int64  `gorm:"column:medical_type_job" json:"medical_type_job" form:"medical_type_job"`
835
+	PharmacistRegistrationNumber            string `gorm:"column:pharmacist_registration_number" json:"pharmacist_registration_number" form:"pharmacist_registration_number"`
836
+	DoctorRangeCode                         int64  `gorm:"column:doctor_range_code" json:"doctor_range_code" form:"doctor_range_code"`
837
+	DoctorLevel                             int64  `gorm:"column:doctor_level" json:"doctor_level" form:"doctor_level"`
838
+	DoctorTypeJob                           int64  `gorm:"column:doctor_type_job" json:"doctor_type_job" form:"doctor_type_job"`
839
+	DoctorNumber                            string `gorm:"column:doctor_number" json:"doctor_number" form:"doctor_number"`
840
+	OutpatientIllnessCategory               string `gorm:"column:outpatient_illness_category" json:"outpatient_illness_category" form:"outpatient_illness_category"`
841
+	IsActive                                int64  `gorm:"column:is_active" json:"is_active" form:"is_active"`
842
+	ActiveStatus                            int64  `gorm:"column:active_status" json:"active_status" form:"active_status"`
843
+}
844
+
845
+func (UserAdminRole) TableName() string {
846
+	return "sgj_user_admin_role"
847
+}
848
+
849
+func FindDiagnoseById(id int64) (*HisXtDiagnoseConfig, error) {
850
+	dealer := &HisXtDiagnoseConfig{}
851
+	err := readDb.Model(&HisXtDiagnoseConfig{}).Where("id = ? AND status = 1", id).First(&dealer).Error
852
+	return dealer, err
853
+}
854
+
855
+type HisXtDiagnoseConfig struct {
856
+	ID                 int64  `gorm:"column:id" json:"id" form:"id"`
857
+	ClassName          string `gorm:"column:class_name" json:"class_name" form:"class_name"`
858
+	Pinyin             string `gorm:"column:pinyin" json:"pinyin" form:"pinyin"`
859
+	Wubi               string `gorm:"column:wubi" json:"wubi" form:"wubi"`
860
+	ContentCode        string `gorm:"column:content_code" json:"content_code" form:"content_code"`
861
+	CountryCode        string `gorm:"column:country_code" json:"country_code" form:"country_code"`
862
+	CountryContentName string `gorm:"column:country_content_name" json:"country_content_name" form:"country_content_name"`
863
+	Remark             string `gorm:"column:remark" json:"remark" form:"remark"`
864
+	UserOrgId          int64  `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
865
+	Status             int64  `gorm:"column:status" json:"status" form:"status"`
866
+	Ctime              int64  `gorm:"column:ctime" json:"ctime" form:"ctime"`
867
+	Mtime              int64  `gorm:"column:mtime" json:"mtime" form:"mtime"`
868
+}
869
+
870
+func (HisXtDiagnoseConfig) TableName() string {
871
+	return "his_xt_diagnose_config"
872
+}
873
+
874
+type VMHisProjectTeam struct {
875
+	ID                int64                `gorm:"column:id" json:"id" form:"id"`
876
+	ProjectTeam       string               `gorm:"column:project_team" json:"project_team" form:"project_team"`
877
+	Price             float64              `gorm:"column:price" json:"price" form:"price"`
878
+	Pinyin            string               `gorm:"column:pinyin" json:"pinyin" form:"pinyin"`
879
+	Wubi              string               `gorm:"column:wubi" json:"wubi" form:"wubi"`
880
+	TubeColor         int64                `gorm:"column:tube_color" json:"tube_color" form:"tube_color"`
881
+	TeamType          int64                `gorm:"column:team_type" json:"team_type" form:"team_type"`
882
+	Remark            string               `gorm:"column:remark" json:"remark" form:"remark"`
883
+	UserOrgId         int64                `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
884
+	Status            int64                `gorm:"column:status" json:"status" form:"status"`
885
+	CreatedTime       int64                `gorm:"column:created_time" json:"created_time" form:"created_time"`
886
+	UpdatedTime       int64                `gorm:"column:updated_time" json:"updated_time" form:"updated_time"`
887
+	ProjectId         string               `gorm:"column:project_id" json:"project_id" form:"project_id"`
888
+	VMItemProjectList []*VMItemProjectList `gorm:"-" json:"list" form:"list"`
889
+	ItemId            string               `gorm:"column:item_id" json:"item_id" form:"item_id"`
890
+}
891
+
892
+func (VMHisProjectTeam) TableName() string {
893
+	return "xt_his_project_team"
894
+}
895
+
896
+type VMItemProjectList struct {
897
+	ID           int64        `gorm:"column:id" json:"id" form:"id"`
898
+	Number       int64        `gorm:"column:number" json:"number" form:"number"`
899
+	UserOrgId    int64        `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
900
+	ProjectId    int64        `gorm:"column:project_id" json:"project_id" form:"project_id"`
901
+	Status       int64        `gorm:"column:status" json:"status" form:"status"`
902
+	CreatedTime  int64        `gorm:"column:created_time" json:"created_time" form:"created_time"`
903
+	UpdatedTime  int64        `gorm:"column:updated_time" json:"updated_time" form:"updated_time"`
904
+	TeamId       int64        `gorm:"column:team_id" json:"team_id" form:"team_id"`
905
+	Type         int64        `gorm:"column:type" json:"type" form:"type"`
906
+	VMHisProject VMHisProject `gorm:"ForeignKey:ID;AssociationForeignKey:ProjectId" json:"project"`
907
+}
908
+
909
+func (VMItemProjectList) TableName() string {
910
+	return "xt_his_project_list"
911
+}
912
+
913
+type VMHisProject struct {
914
+	ID                        int64   `gorm:"column:id" json:"id" form:"id"`
915
+	ProjectName               string  `gorm:"column:project_name" json:"project_name" form:"project_name"`
916
+	Price                     float64 `gorm:"column:price" json:"price" form:"price"`
917
+	Unit                      string  `gorm:"column:unit" json:"unit" form:"unit"`
918
+	CostClassify              int64   `gorm:"column:cost_classify" json:"cost_classify" form:"cost_classify"`
919
+	StatisticalClassification int64   `gorm:"column:statistical_classification" json:"statistical_classification" form:"statistical_classification"`
920
+	UserOrgId                 int64   `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
921
+	Status                    int64   `gorm:"column:status" json:"status" form:"status"`
922
+	SingleDose                string  `gorm:"column:single_dose" json:"single_dose" form:"single_dose"`
923
+	ExecutionFrequency        string  `gorm:"column:execution_frequency" json:"execution_frequency" form:"execution_frequency"`
924
+	DeliveryWay               string  `gorm:"column:delivery_way" json:"delivery_way" form:"delivery_way"`
925
+	NumberDays                string  `gorm:"column:number_days" json:"number_days" form:"number_days"`
926
+	MedicalCode               string  `gorm:"column:medical_code" json:"medical_code" form:"medical_code"`
927
+}
928
+
929
+func (VMHisProject) TableName() string {
930
+	return "xt_his_project"
931
+}
932
+
933
+type HisPrescriptionProject struct {
934
+	ID                 int64        `gorm:"column:id" json:"id" form:"id"`
935
+	ProjectId          int64        `gorm:"column:project_id" json:"project_id" form:"project_id"`
936
+	Price              float64      `gorm:"column:price" json:"price" form:"price"`
937
+	UserOrgId          int64        `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
938
+	Status             int64        `gorm:"column:status" json:"status" form:"status"`
939
+	Ctime              int64        `gorm:"column:ctime" json:"ctime" form:"ctime"`
940
+	Mtime              int64        `gorm:"column:mtime" json:"mtime" form:"mtime"`
941
+	PatientId          int64        `gorm:"column:patient_id" json:"patient_id" form:"patient_id"`
942
+	HisPatientId       int64        `gorm:"column:his_patient_id" json:"his_patient_id" form:"his_patient_id"`
943
+	RecordDate         int64        `gorm:"column:record_date" json:"record_date" form:"record_date"`
944
+	PrescriptionId     int64        `gorm:"column:prescription_id" json:"prescription_id" form:"prescription_id"`
945
+	Count              int64        `gorm:"column:count" json:"count" form:"count"`
946
+	FeedetlSn          string       `gorm:"column:feedetl_sn" json:"feedetl_sn" form:"feedetl_sn"`
947
+	MedListCodg        string       `gorm:"column:med_list_codg" json:"med_list_codg" form:"med_list_codg"`
948
+	SingleDose         string       `gorm:"column:single_dose" json:"single_dose" form:"single_dose"`
949
+	DeliveryWay        string       `gorm:"column:delivery_way" json:"delivery_way" form:"delivery_way"`
950
+	ExecutionFrequency string       `gorm:"column:execution_frequency" json:"execution_frequency" form:"execution_frequency"`
951
+	Day                string       `gorm:"column:day" json:"day" form:"day"`
952
+	VMHisProject       VMHisProject `gorm:"ForeignKey:ProjectId;AssociationForeignKey:ID" json:"project"`
953
+	Remark             string       `gorm:"column:remark" json:"remark" form:"remark"`
954
+	Unit               string       `gorm:"column:unit" json:"unit" form:"unit"`
955
+	Type               int64        `gorm:"column:type" json:"type" form:"type"`
956
+	Doctor             int64        `gorm:"column:doctor" json:"doctor" form:"doctor"`
957
+	ExecutionTime      int64        `gorm:"column:execution_time" json:"execution_time" form:"execution_time"`
958
+	ExecutionStaff     int64        `gorm:"column:execution_staff" json:"execution_staff" form:"execution_staff"`
959
+	ExecutionState     int64        `gorm:"column:execution_state" json:"execution_state" form:"execution_state"`
960
+	CheckTime          int64        `gorm:"column:check_time" json:"check_time" form:"check_time"`
961
+	CheckState         int64        `gorm:"column:check_state" json:"check_state" form:"check_state"`
962
+	Checker            int64        `gorm:"column:checker" json:"checker" form:"checker"`
963
+	StartTime          int64        `gorm:"column:start_time" json:"start_time" form:"start_time"`
964
+	TeamId             int64        `gorm:"column:team_id" json:"team_id" form:"team_id"`
965
+
966
+	FrequencyType   int64           `gorm:"column:frequency_type" json:"frequency_type" form:"frequency_type"`
967
+	DayCount        int64           `gorm:"column:day_count" json:"day_count" form:"day_count"`
968
+	WeekDay         string          `gorm:"column:week_day" json:"week_day" form:"week_day"`
969
+	HisPrescription HisPrescription `gorm:"ForeignKey:ID;AssociationForeignKey:PrescriptionId" json:"his_prescription"`
970
+}
971
+
972
+func (HisPrescriptionProject) TableName() string {
973
+	return "his_prescription_project"
974
+}
975
+func GetProjectTeamList(orgid int64, id int64, p_id int64) (project []*HisPrescriptionProject, err error) {
976
+	err = readDb.Model(&HisPrescriptionProject{}).Where("user_org_id = ? AND status = 1 AND team_id = ? AND prescription_id = ?", orgid, id, p_id).Find(&project).Error
977
+	return
978
+}
979
+
980
+func GetHisLabelPrintInfoById(id string) (info HisLabelPrintInfo, err error) {
981
+	err = readDb.Model(&HisLabelPrintInfo{}).Where("id = ?", id).First(&info).Error
982
+	return
983
+}

+ 48 - 27
service/cron.go Zobrazit soubor

@@ -1,14 +1,14 @@
1 1
 package service
2 2
 
3 3
 import (
4
-	_"fmt"
5
-	_"strings"
6
-	"time"
7 4
 	"IC/models"
8 5
 	"IC/utils"
9 6
 	"encoding/json"
10
-	_"github.com/jinzhu/gorm"
7
+	_ "fmt"
8
+	_ "github.com/jinzhu/gorm"
11 9
 	"github.com/robfig/cron"
10
+	_ "strings"
11
+	"time"
12 12
 )
13 13
 
14 14
 // cron表达式 https://www.cnblogs.com/zuxingyu/p/6023919.html
@@ -41,6 +41,16 @@ func init() {
41 41
 	createLisSyncCronJob.AddFunc(specgzjhlis, func() {
42 42
 		SyncGzjhLis()
43 43
 	})
44
+
45
+	specszbllis := "0 30 4 * * ?" // 每天凌晨4点30同步 广州暨华
46
+	createLisSyncCronJob.AddFunc(specszbllis, func() {
47
+		SyncSZblLis()
48
+	})
49
+
50
+	specszbllisResult := "0 0 2 * * ?" // 每天凌晨3点00同步 广州暨华
51
+	createLisSyncCronJob.AddFunc(specszbllisResult, func() {
52
+		SyncSZblLisResult()
53
+	})
44 54
 }
45 55
 
46 56
 func BeginAutoSyncLis() {
@@ -52,7 +62,7 @@ func AutoSyncLis() {
52 62
 	org_id := int64(9538)
53 63
 
54 64
 	// 第一步:根据机构id获取对应机构所有病人的his_user_id
55
-	patients,patientError := GetHisUserIdByOrgID(org_id)
65
+	patients, patientError := GetHisUserIdByOrgID(org_id)
56 66
 	if patientError != nil {
57 67
 		utils.ErrorLog("获取用户His_user_id信息失败:%v", patientError)
58 68
 		return
@@ -60,17 +70,17 @@ func AutoSyncLis() {
60 70
 
61 71
 	// patientStr:= make([]interface{},0)
62 72
 	if len(patients) > 0 {
63
-	// 第二步:根据病人的his_user_id来查询上次同步时间	
64
-		for _ , patient := range patients {
73
+		// 第二步:根据病人的his_user_id来查询上次同步时间
74
+		for _, patient := range patients {
65 75
 			if len(patient.HisUserId) <= 0 {
66 76
 				continue
67 77
 			}
68
-			syncLastInfo,_ := GetSyncTimeByOrgID(org_id,patient.HisUserId)
78
+			syncLastInfo, _ := GetSyncTimeByOrgID(org_id, patient.HisUserId)
69 79
 			var sync_time int64
70 80
 			if syncLastInfo.ID > 0 {
71 81
 				sync_time = syncLastInfo.SyncTime
72 82
 			} else {
73
-				inspectionLastInfo,_ := GetInspectionLastInfoByOrgID(org_id,patient.HisUserId)
83
+				inspectionLastInfo, _ := GetInspectionLastInfoByOrgID(org_id, patient.HisUserId)
74 84
 				if inspectionLastInfo.ID > 0 {
75 85
 					sync_time = inspectionLastInfo.CreatedTime
76 86
 				} else {
@@ -78,13 +88,13 @@ func AutoSyncLis() {
78 88
 				}
79 89
 			}
80 90
 
81
-			syncTimes := time.Unix(sync_time,0).Format("2006-01-02 15:04")
82
-			utils.InfoLog("syncTimes:%v",syncTimes)
91
+			syncTimes := time.Unix(sync_time, 0).Format("2006-01-02 15:04")
92
+			utils.InfoLog("syncTimes:%v", syncTimes)
83 93
 
84 94
 			// 第三步:跟进上次同步时间和指定的his_user_id,获取上次同步到现在指定人的检验检查记录
85
-			resultList, _ := GetListByHisUserID(patient.HisUserId,syncTimes,patient.SelectType)
95
+			resultList, _ := GetListByHisUserID(patient.HisUserId, syncTimes, patient.SelectType)
86 96
 			var syncInfo models.MiddleSyncInfo
87
-	
97
+
88 98
 			if len(resultList) > 0 {
89 99
 				// 如果有数据,则把同步过来的详情插入一条数据到同步详情表中
90 100
 				syncInfo.OrgId = org_id
@@ -94,7 +104,7 @@ func AutoSyncLis() {
94 104
 				syncInfo.SyncRsultRemark = "同步成功"
95 105
 				syncInfo.SyncTotalNum = int64(len(resultList))
96 106
 				syncInfo.SyncSuccessNum = 0
97
-				SyncInfos,_ := json.Marshal(resultList)
107
+				SyncInfos, _ := json.Marshal(resultList)
98 108
 				syncInfo.SyncInfo = string(SyncInfos)
99 109
 				syncInfo.CreateTime = time.Now().Unix()
100 110
 				syncInfo.UpdateTime = time.Now().Unix()
@@ -120,17 +130,17 @@ func AutoSyncLis() {
120 130
 					return
121 131
 				}
122 132
 				// utils.InfoLog("同步信息详情:%v",syncInfo)
123
-				continue 
133
+				continue
124 134
 			}
125 135
 
126 136
 			// 第四部:将同步过来的数据插入到中间库对应的表
127 137
 			syncSuccessNum := 0
128 138
 			for _, result := range resultList {
129
-				if (result.HisUserId == patient.HisUserId) || (result.PatientName ==  patient.HisUserId) {
139
+				if (result.HisUserId == patient.HisUserId) || (result.PatientName == patient.HisUserId) {
130 140
 					patientId := patient.XtPatientId
131 141
 					if patientId > 0 {
132
-						inspection_reference,inspection,_ := Sync(result,org_id,patientId)
133
-						if (inspection_reference.ID > 0 || inspection.ID > 0 ) {
142
+						inspection_reference, inspection, _ := Sync(result, org_id, patientId)
143
+						if inspection_reference.ID > 0 || inspection.ID > 0 {
134 144
 							syncSuccessNum++
135 145
 						}
136 146
 					}
@@ -140,7 +150,7 @@ func AutoSyncLis() {
140 150
 			UpdateSyncInfo(&syncInfo)
141 151
 
142 152
 			// patientStr = append(patientStr,patient.HisUserId)
143
-			// utils.InfoLog("patientStr:%v",patientStr)	
153
+			// utils.InfoLog("patientStr:%v",patientStr)
144 154
 		}
145 155
 	} else {
146 156
 		var syncInfo models.MiddleSyncInfo
@@ -157,34 +167,45 @@ func AutoSyncLis() {
157 167
 			utils.ErrorLog("创建同步信息失败:%v", err)
158 168
 			return
159 169
 		}
160
-		utils.InfoLog("同步信息详情:%v",syncInfo)
161
-		return 
170
+		utils.InfoLog("同步信息详情:%v", syncInfo)
171
+		return
162 172
 	}
163 173
 
164 174
 	SyncToBase()
165 175
 	utils.SuccessLog("检验检查任务完成")
166 176
 }
167 177
 
168
-
169
-func  SyncToBase() {
178
+func SyncToBase() {
170 179
 	utils.TraceLog("检验检查同步任务开始执行")
171 180
 	org_id := int64(9538)
172 181
 
173 182
 	// 第一步:跟进org_id 去中间库查出需要同步的数据
174
-	inspection_references,_ := GetSyncInspectionReferenceByOrgId(org_id)
175
-	inspections,_ := GetSyncInspectionByOrgId(org_id)
183
+	inspection_references, _ := GetSyncInspectionReferenceByOrgId(org_id)
184
+	inspections, _ := GetSyncInspectionByOrgId(org_id)
176 185
 
177 186
 	// 第二步:将数据同步到业务库
178 187
 	if len(inspection_references) > 0 {
179
-		for _,inspection_reference := range inspection_references {
188
+		for _, inspection_reference := range inspection_references {
180 189
 			SyncInspectionReference(&inspection_reference)
181 190
 		}
182 191
 	}
183 192
 
184 193
 	if len(inspections) > 0 {
185
-		for _,inspection := range inspections {
194
+		for _, inspection := range inspections {
186 195
 			SyncInspection(&inspection)
187 196
 		}
188 197
 	}
189 198
 	utils.SuccessLog("检验检查同步任务完成")
190 199
 }
200
+
201
+func SyncSZblLis() {
202
+	utils.TraceLog("检验检查同步任务开始执行")
203
+	org_id := int64(10138)
204
+	GetDataInsertDB(org_id)
205
+}
206
+
207
+func SyncSZblLisResult() {
208
+	utils.TraceLog("获取检验检查结果任务开始执行")
209
+	org_id := int64(10138)
210
+	GetResultDataInsertDB(org_id)
211
+}

+ 37 - 1
service/db.go Zobrazit soubor

@@ -21,21 +21,25 @@ import (
21 21
 
22 22
 	"github.com/astaxie/beego"
23 23
 	"github.com/jinzhu/gorm"
24
-	_ "github.com/jinzhu/gorm/dialects/mysql" // mysql
25 24
 	_ "github.com/jinzhu/gorm/dialects/mssql" // mssql
25
+	_ "github.com/jinzhu/gorm/dialects/mysql" // mysql
26 26
 )
27 27
 
28 28
 var readDb *gorm.DB
29 29
 var writeDb *gorm.DB
30 30
 var readRemoteDb *gorm.DB
31 31
 var writeUserDb *gorm.DB
32
+var readUserDb *gorm.DB
32 33
 
33 34
 var readMiddleDb *gorm.DB
34 35
 var writeMiddleDb *gorm.DB
35 36
 var backupDb *gorm.DB
36 37
 var err error
37 38
 
39
+var blDb *gorm.DB
40
+
38 41
 func ConnectDB() {
42
+
39 43
 	readHost := beego.AppConfig.String("readmysqlhost")
40 44
 	readPort := beego.AppConfig.String("readmysqlport")
41 45
 	readUser := beego.AppConfig.String("readmysqluser")
@@ -48,6 +52,12 @@ func ConnectDB() {
48 52
 	writePass := beego.AppConfig.String("writemysqlpass")
49 53
 	writeName := beego.AppConfig.String("writemysqlname")
50 54
 
55
+	readUserHost := beego.AppConfig.String("readuserhost")
56
+	readUserPort := beego.AppConfig.String("readuserport")
57
+	readUserUser := beego.AppConfig.String("readuseruser")
58
+	readUserPass := beego.AppConfig.String("readuserpass")
59
+	readUserName := beego.AppConfig.String("readusername")
60
+
51 61
 	// readRemoteHost := beego.AppConfig.String("readremotehost")
52 62
 	// readRemotePort := beego.AppConfig.String("readremoteport")
53 63
 	// readRemoteUser := beego.AppConfig.String("readremoteuser")
@@ -78,6 +88,12 @@ func ConnectDB() {
78 88
 	// backupPass := beego.AppConfig.String("backuppass")
79 89
 	// backupName := beego.AppConfig.String("backupname")
80 90
 
91
+	blHost := beego.AppConfig.String("blmysqlhost")
92
+	blPort := beego.AppConfig.String("blmysqlport")
93
+	blUser := beego.AppConfig.String("blmysqluser")
94
+	blPass := beego.AppConfig.String("blmysqlpass")
95
+	blName := beego.AppConfig.String("blmysqlname")
96
+
81 97
 	rdsn := fmt.Sprintf("%s:%s@tcp(%s:%s)/%s?charset=utf8mb4&parseTime=true", readUser, readPass, readHost, readPort, readName)
82 98
 	wdsn := fmt.Sprintf("%s:%s@tcp(%s:%s)/%s?charset=utf8mb4&parseTime=true", writeUser, writePass, writeHost, writePort, writeName)
83 99
 
@@ -86,6 +102,9 @@ func ConnectDB() {
86 102
 
87 103
 	rmdsn := fmt.Sprintf("%s:%s@tcp(%s:%s)/%s?charset=utf8mb4&parseTime=true", readMiddleUser, readMiddlePass, readMiddleHost, readMiddlePort, readMiddleName)
88 104
 	wmdsn := fmt.Sprintf("%s:%s@tcp(%s:%s)/%s?charset=utf8mb4&parseTime=true", writeMiddleUser, writeMiddlePass, writeMiddleHost, writeMiddlePort, writeMiddleName)
105
+	rudsn := fmt.Sprintf("%s:%s@tcp(%s:%s)/%s?charset=utf8mb4&parseTime=true", readUserUser, readUserPass, readUserHost, readUserPort, readUserName)
106
+
107
+	bldsn := fmt.Sprintf("%s:%s@tcp(%s:%s)/%s?charset=utf8mb4&parseTime=true", blUser, blPass, blHost, blPort, blName)
89 108
 
90 109
 	// bdsn := fmt.Sprintf("%s:%s@tcp(%s:%s)/%s?charset=utf8mb4&parseTime=true", backupUser, backupPass, backupHost, backupPort, backupName)
91 110
 
@@ -147,6 +166,22 @@ func ConnectDB() {
147 166
 	writeMiddleDb.DB().SetMaxOpenConns(100)
148 167
 	writeMiddleDb.LogMode(true)
149 168
 
169
+	readUserDb, err = gorm.Open("mysql", rudsn)
170
+	if err != nil {
171
+		//beego.Error(err)
172
+	}
173
+	readUserDb.DB().SetMaxIdleConns(10)
174
+	readUserDb.DB().SetMaxOpenConns(100)
175
+	readUserDb.LogMode(true)
176
+
177
+	blDb, err = gorm.Open("mysql", bldsn)
178
+	if err != nil {
179
+		//beego.Error(err)
180
+	}
181
+	blDb.DB().SetMaxIdleConns(10)
182
+	blDb.DB().SetMaxOpenConns(100)
183
+	blDb.LogMode(true)
184
+
150 185
 }
151 186
 
152 187
 //func DisconnectDB() {
@@ -161,6 +196,7 @@ func XTReadDB() *gorm.DB {
161 196
 func XTWriteDB() *gorm.DB {
162 197
 	return writeDb
163 198
 }
199
+
164 200
 // func RemoteReadDB() *gorm.DB {
165 201
 // 	return readRemoteDb
166 202
 // }

+ 49 - 0
service/ms_db.go Zobrazit soubor

@@ -0,0 +1,49 @@
1
+// Pipe - A small and beautiful blogging platform written in golang.
2
+// Copyright (C) 2017-2018, b3log.org
3
+//
4
+// This program is free software: you can redistribute it and/or modify
5
+// it under the terms of the GNU General Public License as published by
6
+// the Free Software Foundation, either version 3 of the License, or
7
+// (at your option) any later version.
8
+//
9
+// This program is distributed in the hope that it will be useful,
10
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
11
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12
+// GNU General Public License for more details.
13
+//
14
+// You should have received a copy of the GNU General Public License
15
+// along with this program.  If not, see <http://www.gnu.org/licenses/>.
16
+
17
+package service
18
+
19
+import (
20
+	"fmt"
21
+	"github.com/astaxie/beego"
22
+	"github.com/jinzhu/gorm"
23
+	_ "github.com/jinzhu/gorm/dialects/mssql" // mssql
24
+	_ "github.com/jinzhu/gorm/dialects/mysql" // mysql
25
+)
26
+
27
+var dataBase *gorm.DB
28
+
29
+var (
30
+	dbName   = "local"
31
+	user     = beego.AppConfig.DefaultString(dbName+"::user", "sa")
32
+	password = beego.AppConfig.DefaultString(dbName+"::password", "hy123456")
33
+	host     = beego.AppConfig.DefaultString(dbName+"::host", "127.0.0.1")
34
+	port     = beego.AppConfig.DefaultInt(dbName+"::port", 1633)
35
+	dbname   = beego.AppConfig.DefaultString(dbName+"::dbname", "local")
36
+)
37
+
38
+func ConnectMSDB() {
39
+	connectionString := fmt.Sprintf("server=%s;user id=%s;password=%s;port=%d;database=%s",
40
+		host, user, password, port, dbname)
41
+	db, err := gorm.Open("mssql", connectionString)
42
+	if err != nil {
43
+		panic("failed to connect database")
44
+	}
45
+	db.LogMode(true)
46
+	db.CommonDB()
47
+	dataBase = db
48
+
49
+}