Browse Source

新增多个上传类型

csx 4 years ago
parent
commit
f6dbf2741b

+ 623 - 18
controllers/sync.go View File

@@ -1,37 +1,39 @@
1 1
 package controllers
2 2
 
3 3
 import (
4
-	"github.com/jinzhu/gorm"
4
+	"Data_Upload_Api/enums"
5 5
 	"Data_Upload_Api/models/sz"
6
-	"github.com/astaxie/beego"
7 6
 	"Data_Upload_Api/service"
8
-	"Data_Upload_Api/enums"
9 7
 	"Data_Upload_Api/utils"
8
+	"github.com/astaxie/beego"
9
+	"github.com/jinzhu/gorm"
10
+	"math"
10 11
 	"strconv"
12
+	"strings"
13
+	_ "strings"
11 14
 	"time"
12
-	_"strings"
13 15
 )
14 16
 
15 17
 type SyncController struct {
16 18
 	BaseAPIController
17 19
 }
18 20
 
19
-func (c *SyncController)SyncToSZIC() {
21
+func (c *SyncController) SyncToSZIC() {
20 22
 	// 第一步:到上报配置表中找到深圳需要上报的机构
21 23
 	sz_province, _ := beego.AppConfig.Int64("sz_province")
22 24
 	sz_city, _ := beego.AppConfig.Int64("sz_city")
23 25
 	configs, _ := service.FindAllDataUploadConfigOrgInfo(sz_province, sz_city, 3)
24 26
 	for _, org := range configs {
25 27
 		// 第二步:跟进配置,创建数据库连接
26
-		if (len(org.DbHost) > 0 && len(org.DbUser) > 0 && len(org.DbPort) > 0 && len(org.DbPass) > 0 && len(org.DbName) > 0) {
27
-			orgDb,err := service.CreateDB(org.DbHost,org.DbPort,org.DbUser,org.DbPass,org.DbName)
28
+		if len(org.DbHost) > 0 && len(org.DbUser) > 0 && len(org.DbPort) > 0 && len(org.DbPass) > 0 && len(org.DbName) > 0 {
29
+			orgDb, err := service.CreateDB(org.DbHost, org.DbPort, org.DbUser, org.DbPass, org.DbName)
28 30
 			if err != nil {
29 31
 				utils.ErrorLog("创建数据库连接失败:%v", err)
30 32
 				c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
31 33
 				return
32 34
 			}
33 35
 			// 第三步:开始同步数据
34
-			c.SyncHospital(orgDb,org.OrgId,org.HospitalId,org.InstType,org.DepartmentName)
36
+			c.SyncHospital(orgDb, org.OrgId, org.HospitalId, org.InstType, org.DepartmentName)
35 37
 
36 38
 			// 第四步:关闭数据库连接
37 39
 			service.CloseDB(orgDb)
@@ -40,9 +42,9 @@ func (c *SyncController)SyncToSZIC() {
40 42
 }
41 43
 
42 44
 // 同步医院信息
43
-func (c *SyncController)SyncHospital(rdb *gorm.DB,org_id int64,hospital_id int64,inst_type int64,department_name string) {
45
+func (c *SyncController) SyncHospital(rdb *gorm.DB, org_id int64, hospital_id int64, inst_type int64, department_name string) {
44 46
 	// 第一步:根据机构id获取上次同步时间
45
-	syncLastInfo,_ := service.GetSyncTimeByOrgId(org_id,1)
47
+	syncLastInfo, _ := service.GetSyncTimeByOrgId(org_id, 1)
46 48
 	var sync_time int64
47 49
 	if syncLastInfo.ID > 0 {
48 50
 		sync_time = syncLastInfo.SyncTime
@@ -51,12 +53,12 @@ func (c *SyncController)SyncHospital(rdb *gorm.DB,org_id int64,hospital_id int64
51 53
 	}
52 54
 
53 55
 	// 第二步:跟进上次同步时间找出这个时间段内增加的数据
54
-	org, _ := service.FindOrgData(org_id,sync_time)
56
+	org, _ := service.FindOrgData(org_id, sync_time)
55 57
 	if org.ID > 0 {
56 58
 		hospital := &sz.TempHdHospital{
57 59
 			HospitalId:     strconv.FormatInt(hospital_id, 10),
58 60
 			InstType:       strconv.FormatInt(inst_type, 10),
59
-			DepartMentName:	department_name,
61
+			DepartMentName: department_name,
60 62
 			AuthorizedBeds: int64(len(org.DeviceNumber)),
61 63
 			CreateTime:     time.Now(),
62 64
 			UpdateTime:     time.Now(),
@@ -67,12 +69,12 @@ func (c *SyncController)SyncHospital(rdb *gorm.DB,org_id int64,hospital_id int64
67 69
 		if err == nil {
68 70
 			// 第三步:同步成功后,添加同步记录
69 71
 			upload := &sz.DataUpload{
70
-				SyncType:   		1,
71
-				OrgId:        		org_id,
72
-				SyncTime:   		time.Now().Unix(),
73
-				sync_result_type: 	1,
74
-				CreateTime:   		time.Now().Unix(),
75
-				UpdateTime:   		time.Now().Unix()
72
+				SyncType:       1,
73
+				OrgId:          org_id,
74
+				SyncTime:       time.Now().Unix(),
75
+				SyncResultType: 1,
76
+				CreateTime:     time.Now().Unix(),
77
+				UpdateTime:     time.Now().Unix(),
76 78
 			}
77 79
 			err := service.CreateUploadRecord(upload)
78 80
 			if err != nil {
@@ -80,5 +82,608 @@ func (c *SyncController)SyncHospital(rdb *gorm.DB,org_id int64,hospital_id int64
80 82
 			}
81 83
 		}
82 84
 	}
85
+
86
+}
87
+
88
+// 同步水处理器
89
+func (c *SyncController) SyncWMS(rdb *gorm.DB, org_id int64, hospital_id int64) {
90
+	// 第一步:根据机构id获取上次同步时间
91
+	syncLastInfo, _ := service.GetSyncTimeByOrgId(org_id, 22)
92
+	var sync_time int64
93
+	if syncLastInfo.ID > 0 {
94
+		sync_time = syncLastInfo.SyncTime
95
+	} else {
96
+		sync_time = 0
97
+	}
98
+
99
+	//同步水处理机
100
+	waterMachine, _ := service.FindOrgWaterMachineData(org_id, sync_time, time.Now().Unix())
101
+	var wms []*sz.TempHdWm
102
+	for _, item := range waterMachine {
103
+		wm := &sz.TempHdWm{
104
+			HospitalId:     strconv.FormatInt(hospital_id, 10),
105
+			EquipmentId:    strconv.FormatInt(item.ID, 10),
106
+			EquipmentBrand: item.ManufactureFactory,
107
+			EquipmentModel: strconv.FormatInt(item.UnitType, 10),
108
+			EnableTime:     time.Unix(item.StartDate, 0),
109
+			DiscardedTime:  time.Unix(item.RubbishDate, 0),
110
+			EquipmentType:  strconv.FormatInt(item.DeviceType, 10),
111
+			CreateTime:     time.Now(),
112
+			UpdateTime:     time.Now(),
113
+			Sjscsj:         time.Now(),
114
+			Xgbz:           strconv.FormatInt(0, 10),
115
+		}
116
+
117
+		wms = append(wms, wm)
118
+	}
119
+
120
+	err := service.BatchCreateWMsRecord(wms, rdb)
121
+	if err == nil {
122
+		// 第三步:同步成功后,添加同步记录
123
+		upload := &sz.DataUpload{
124
+			SyncType:       22,
125
+			OrgId:          org_id,
126
+			SyncTime:       time.Now().Unix(),
127
+			SyncResultType: 1,
128
+			CreateTime:     time.Now().Unix(),
129
+			UpdateTime:     time.Now().Unix(),
130
+		}
131
+		err := service.CreateUploadRecord(upload)
132
+		if err != nil {
133
+			utils.ErrorLog("%v", err)
134
+		}
135
+	} else {
136
+		//错误处理
137
+
138
+	}
139
+
140
+}
141
+
142
+// 同步员工
143
+func (c *SyncController) SyncStaff(rdb *gorm.DB, org_id int64, hospital_id int64) {
144
+	// 第一步:根据机构id获取上次同步时间
145
+	syncLastInfo, _ := service.GetSyncTimeByOrgId(org_id, 21)
146
+	var sync_time int64
147
+	if syncLastInfo.ID > 0 {
148
+		sync_time = syncLastInfo.SyncTime
149
+	} else {
150
+		sync_time = 0
151
+	}
152
+
153
+	//同步员工信息
154
+	roles, _ := service.FindOrgRolesData(org_id, sync_time, time.Now().Unix())
155
+
156
+	//waterMachine, _ := service.FindOrgWaterMachineData(org_id, sync_time, time.Now().Unix())
157
+	var staffs []*sz.TempHdStaff
158
+	for _, role := range roles {
159
+		var title string
160
+		switch role.UserType {
161
+		case 2:
162
+			title = strconv.FormatInt(1, 10)
163
+			break
164
+		case 3:
165
+			title = strconv.FormatInt(2, 10)
166
+			break
167
+		}
168
+
169
+		staff := &sz.TempHdStaff{
170
+			HospitalId:    strconv.FormatInt(hospital_id, 10),
171
+			StaffId:       strconv.FormatInt(role.ID, 10),
172
+			StaffName:     role.UserName,
173
+			Position:      title,
174
+			PermanentType: strconv.FormatInt(1, 10),
175
+			CreateTime:    time.Now(),
176
+			UpdateTime:    time.Now(),
177
+			Sjscsj:        time.Now(),
178
+			Xgbz:          strconv.FormatInt(0, 10),
179
+		}
180
+		staffs = append(staffs, staff)
181
+
182
+	}
183
+
184
+	err := service.BatchCreateStaffRecord(staffs, rdb)
185
+	if err == nil {
186
+		// 第三步:同步成功后,添加同步记录
187
+		upload := &sz.DataUpload{
188
+			SyncType:       21,
189
+			OrgId:          org_id,
190
+			SyncTime:       time.Now().Unix(),
191
+			SyncResultType: 1,
192
+			CreateTime:     time.Now().Unix(),
193
+			UpdateTime:     time.Now().Unix(),
194
+		}
195
+		err := service.CreateUploadRecord(upload)
196
+		if err != nil {
197
+			utils.ErrorLog("%v", err)
198
+		}
199
+	} else {
200
+		//错误处理
201
+
202
+	}
203
+
204
+}
205
+
206
+// 同步病人
207
+func (c *SyncController) SyncPatient(rdb *gorm.DB, org_id int64, hospital_id int64) {
208
+	// 第一步:根据机构id获取上次同步时间
209
+	syncLastInfo, _ := service.GetSyncTimeByOrgId(org_id, 15)
210
+	var sync_time int64
211
+	if syncLastInfo.ID > 0 {
212
+		sync_time = syncLastInfo.SyncTime
213
+	} else {
214
+		sync_time = 0
215
+	}
216
+
217
+	//同步员工信息
218
+	patients, _ := service.FindOrgPatientData(org_id, sync_time, time.Now().Unix())
219
+
220
+	//waterMachine, _ := service.FindOrgWaterMachineData(org_id, sync_time, time.Now().Unix())
221
+	var hdPatients []*sz.TempHdPatient
222
+	for _, patient := range patients {
223
+
224
+		idcard_year, _ := strconv.Atoi(Substr(patient.IdCardNo, 6, 4)) // 年
225
+		idcard_mo, _ := strconv.Atoi(Substr(patient.IdCardNo, 10, 2))  // 月
226
+		idcard_day, _ := strconv.Atoi(Substr(patient.IdCardNo, 12, 2)) // 日
227
+
228
+		date := strconv.Itoa(idcard_year) + "-" + strconv.Itoa(idcard_mo) + "-" + strconv.Itoa(idcard_day)
229
+
230
+		local, _ := time.LoadLocation("Local")
231
+		birthday, _ := time.ParseInLocation("2006-01-02", date, local)
232
+
233
+		var isCKD int
234
+
235
+		value := strings.Index(patient.Diagnose, "慢性肾脏病")
236
+		value2 := strings.Index(patient.Diagnose, "CKD")
237
+		value3 := strings.Index(patient.Diagnose, "慢性肾衰竭")
238
+
239
+		if value != -1 || value2 != -1 || value3 != -1 {
240
+			isCKD = 1
241
+		} else {
242
+			isCKD = 0
243
+		}
244
+
245
+		p := &sz.TempHdPatient{
246
+			HospitalId:       strconv.FormatInt(hospital_id, 10),
247
+			PatientNk:        strconv.FormatInt(patient.ID, 10),
248
+			CardNo:           "000000000000000000",
249
+			CardType:         "01",
250
+			IdNo:             patient.IdCardNo,
251
+			IdType:           "01",
252
+			PatientName:      patient.Name,
253
+			Gender:           strconv.FormatInt(patient.Gender, 10),
254
+			BornDate:         birthday,
255
+			DiagnosisSummary: patient.Diagnose,
256
+			IsCrf:            strconv.Itoa(isCKD),
257
+			CreatedTime:      time.Now(),
258
+			UpdateTime:       time.Now(),
259
+			Sjscsj:           time.Now(),
260
+			Xgbz:             strconv.FormatInt(0, 10),
261
+		}
262
+
263
+		if patient.FirstDialysisDate != 0 {
264
+			p.DialysisStartTime = time.Unix(patient.FirstDialysisDate, 0)
265
+		}
266
+		if patient.HospitalFirstDialysisDate != 0 {
267
+			p.LocalStartTime = time.Unix(patient.HospitalFirstDialysisDate, 0)
268
+		}
269
+
270
+		hdPatients = append(hdPatients, p)
271
+	}
272
+
273
+	err := service.BatchCreatePatinet(hdPatients, rdb)
274
+	if err == nil {
275
+		// 第三步:同步成功后,添加同步记录
276
+		upload := &sz.DataUpload{
277
+			SyncType:       15,
278
+			OrgId:          org_id,
279
+			SyncTime:       time.Now().Unix(),
280
+			SyncResultType: 1,
281
+			CreateTime:     time.Now().Unix(),
282
+			UpdateTime:     time.Now().Unix(),
283
+		}
284
+		err := service.CreateUploadRecord(upload)
285
+		if err != nil {
286
+			utils.ErrorLog("%v", err)
287
+		}
288
+	} else {
289
+		//错误处理
290
+
291
+	}
292
+
293
+}
294
+
295
+func Substr(str string, start, length int) string {
296
+	rs := []rune(str)
297
+	rl := len(rs)
298
+	end := 0
299
+	if start < 0 {
300
+		start = rl - 1 + start
301
+	}
302
+	end = start + length
303
+	if start > end {
304
+		start, end = end, start
305
+	}
306
+	if start < 0 {
307
+		start = 0
308
+	}
309
+	if start > rl {
310
+		start = rl
311
+	}
312
+	if end < 0 {
313
+		end = 0
314
+	}
315
+	if end > rl {
316
+		end = rl
317
+	}
318
+	return string(rs[start:end])
319
+
320
+}
321
+
322
+// 同步排班
323
+func (c *SyncController) SyncShift(rdb *gorm.DB, org_id int64, hospital_id int64) {
324
+	// 第一步:根据机构id获取上次同步时间
325
+	syncLastInfo, _ := service.GetSyncTimeByOrgId(org_id, 19)
326
+	var sync_time int64
327
+	if syncLastInfo.ID > 0 {
328
+		sync_time = syncLastInfo.SyncTime
329
+	} else {
330
+		sync_time = 0
331
+	}
332
+
333
+	var hdShift []*sz.TempHdShift
334
+	schs, _ := service.FindOrgScheduleData(org_id, sync_time, time.Now().Unix())
335
+
336
+	for _, sch := range schs {
337
+		shift := &sz.TempHdShift{
338
+			PsId:           strconv.FormatInt(sch.ID, 10),
339
+			HospitalId:     strconv.FormatInt(sch.UserOrgId, 10),
340
+			PatientNk:      strconv.FormatInt(sch.PatientId, 10),
341
+			ScheduleDate:   time.Unix(sch.ScheduleDate, 0),
342
+			ShiftType:      strconv.FormatInt(sch.ScheduleType, 10),
343
+			SickbedNo:      sch.DeviceNumber.Number,
344
+			ScheduleStatus: "1",
345
+			CreateTime:     time.Now(),
346
+			Sjscsj:         time.Now(),
347
+			Xgbz:           0,
348
+		}
349
+
350
+		hdShift = append(hdShift, shift)
351
+	}
352
+	err := service.BatchCreateSchedual(hdShift, rdb)
353
+	if err == nil {
354
+		// 第三步:同步成功后,添加同步记录
355
+		upload := &sz.DataUpload{
356
+			SyncType:       19,
357
+			OrgId:          org_id,
358
+			SyncTime:       time.Now().Unix(),
359
+			SyncResultType: 1,
360
+			CreateTime:     time.Now().Unix(),
361
+			UpdateTime:     time.Now().Unix(),
362
+		}
363
+		err := service.CreateUploadRecord(upload)
364
+		if err != nil {
365
+			utils.ErrorLog("%v", err)
366
+		}
367
+	} else {
368
+		//错误处理
369
+
370
+	}
371
+
372
+}
373
+
374
+// 同步处方
375
+func (c *SyncController) SyncPs(rdb *gorm.DB, org_id int64, hospital_id int64) {
376
+	// 第一步:根据机构id获取上次同步时间
377
+	syncLastInfo, _ := service.GetSyncTimeByOrgId(org_id, 17)
378
+	var sync_time int64
379
+	if syncLastInfo.ID > 0 {
380
+		sync_time = syncLastInfo.SyncTime
381
+	} else {
382
+		sync_time = 0
383
+	}
384
+
385
+	var hdPrescription []*sz.TempHdPs
386
+	prescriptions, _ := service.FindOrgDialysisPrescriptionData(org_id, sync_time, time.Now().Unix())
387
+	for _, item := range prescriptions {
388
+
389
+		ps := &sz.TempHdPs{
390
+			PrescribeId:   strconv.FormatInt(item.ID, 10),
391
+			HospitalId:    strconv.FormatInt(hospital_id, 10),
392
+			PatientNk:     strconv.FormatInt(item.PatientId, 10),
393
+			K:             item.Kalium,
394
+			Ca:            item.Calcium,
395
+			Na:            item.Sodium,
396
+			CreateTime:    time.Now(),
397
+			Sjscsj:        time.Now(),
398
+			Xgbz:          0,
399
+			PrescribeTime: time.Unix(item.RecordDate, 0),
400
+		}
401
+
402
+		switch item.ModeId {
403
+		case 1:
404
+			ps.DialysisFrequency = item.AssessmentBeforeDislysis.DialysisCount
405
+			ps.FrequencyUnit = 1
406
+			ps.DialysisDuration = item.DialysisDuration
407
+			ps.Hdf = "0"
408
+			ps.Hp = "0"
409
+
410
+			break
411
+		case 2:
412
+			ps.Hdf = "1"
413
+			ps.Hp = "0"
414
+			ps.HdfFrequency = item.AssessmentBeforeDislysis.DialysisCount
415
+			ps.HdfFrequencyUnit = 1
416
+			ps.HpDuration = item.DialysisDuration
417
+			break
418
+		case 4:
419
+			ps.Hdf = "0"
420
+			ps.Hp = "1"
421
+			ps.HpFrequency = item.AssessmentBeforeDislysis.DialysisCount
422
+			ps.HpFrequencyUnit = 1
423
+			ps.HpDuration = item.DialysisDuration
424
+			break
425
+		}
426
+
427
+		hdPrescription = append(hdPrescription, ps)
428
+	}
429
+
430
+	err := service.BatchCreatePs(hdPrescription, rdb)
431
+
432
+	if err == nil {
433
+		// 第三步:同步成功后,添加同步记录
434
+		upload := &sz.DataUpload{
435
+			SyncType:       17,
436
+			OrgId:          org_id,
437
+			SyncTime:       time.Now().Unix(),
438
+			SyncResultType: 1,
439
+			CreateTime:     time.Now().Unix(),
440
+			UpdateTime:     time.Now().Unix(),
441
+		}
442
+		err := service.CreateUploadRecord(upload)
443
+		if err != nil {
444
+			utils.ErrorLog("%v", err)
445
+		}
446
+	} else {
447
+		//错误处理
448
+
449
+	}
450
+
451
+}
452
+
453
+// 同步处方药物
454
+func (c *SyncController) SyncPsMedicine(rdb *gorm.DB, org_id int64, hospital_id int64) {
455
+	// 第一步:根据机构id获取上次同步时间
456
+	syncLastInfo, _ := service.GetSyncTimeByOrgId(org_id, 18)
457
+	var sync_time int64
458
+	if syncLastInfo.ID > 0 {
459
+		sync_time = syncLastInfo.SyncTime
460
+	} else {
461
+		sync_time = 0
462
+	}
463
+
464
+	var tempPsmedicine []*sz.TempHdPsMedicine
465
+	prescriptions, _ := service.FindOrgDialysisPrescriptionData(org_id, sync_time, time.Now().Unix())
466
+
467
+	for _, item := range prescriptions {
468
+
469
+		psm := &sz.TempHdPsMedicine{
470
+			PrescribeId:    strconv.FormatInt(item.ID, 10),
471
+			HospitalId:     strconv.FormatInt(item.UserOrgId, 10),
472
+			MedicineTypeId: "2",
473
+			CreatedTime:    time.Now(),
474
+			Sjscsj:         time.Now(),
475
+			Xgbz:           0,
476
+		}
477
+
478
+		switch item.Anticoagulant {
479
+		case 1:
480
+			psm.MedicineId = "3"
481
+
482
+			break
483
+		case 2:
484
+			psm.MedicineId = "1"
485
+
486
+			break
487
+		case 3:
488
+			psm.MedicineId = "2"
489
+
490
+			break
491
+		case 4:
492
+			psm.MedicineId = "5"
493
+
494
+			break
495
+		case 5:
496
+			psm.MedicineId = "4"
497
+
498
+			break
499
+		}
500
+
501
+		tempPsmedicine = append(tempPsmedicine, psm)
502
+	}
503
+
504
+	err := service.BatchCreatePsm(tempPsmedicine, rdb)
505
+
506
+	if err == nil {
507
+		// 第三步:同步成功后,添加同步记录
508
+		upload := &sz.DataUpload{
509
+			SyncType:       18,
510
+			OrgId:          org_id,
511
+			SyncTime:       time.Now().Unix(),
512
+			SyncResultType: 1,
513
+			CreateTime:     time.Now().Unix(),
514
+			UpdateTime:     time.Now().Unix(),
515
+		}
516
+		err := service.CreateUploadRecord(upload)
517
+		if err != nil {
518
+			utils.ErrorLog("%v", err)
519
+		}
520
+	} else {
521
+		//错误处理
522
+
523
+	}
524
+
525
+}
526
+
527
+// 同步转院信息
528
+func (c *SyncController) SyncPatientOut(rdb *gorm.DB, org_id int64, hospital_id int64) {
529
+	// 第一步:根据机构id获取上次同步时间
530
+	syncLastInfo, _ := service.GetSyncTimeByOrgId(org_id, 16)
531
+	var sync_time int64
532
+	if syncLastInfo.ID > 0 {
533
+		sync_time = syncLastInfo.SyncTime
534
+	} else {
535
+		sync_time = 0
536
+	}
537
+
538
+	var hdPatientOuts []*sz.TempHdPatientOut
539
+	patients, _ := service.FindOrgPatientOutData(org_id, sync_time, time.Now().Unix())
540
+	//
541
+	for _, patient := range patients {
542
+
543
+		p := &sz.TempHdPatientOut{
544
+			HospitalId:   strconv.FormatInt(patient.UserOrgId, 10),
545
+			PatientNk:    strconv.FormatInt(patient.ID, 10),
546
+			SequelaeType: "99",
547
+			CreateTime:   time.Now(),
548
+			Sjscsj:       time.Now(),
549
+			Xgbz:         0,
550
+		}
551
+
552
+		if len(patient.PatientLapseto) > 0 {
553
+			p.SequelaeDate = time.Unix(patient.PatientLapseto[len(patient.PatientLapseto)].LapsetoTime, 0)
554
+		}
555
+
556
+		hdPatientOuts = append(hdPatientOuts, p)
557
+	}
558
+
559
+	err := service.BatchCreatePatientOut(hdPatientOuts, rdb)
560
+
561
+	if err == nil {
562
+		// 第三步:同步成功后,添加同步记录
563
+		upload := &sz.DataUpload{
564
+			SyncType:       16,
565
+			OrgId:          org_id,
566
+			SyncTime:       time.Now().Unix(),
567
+			SyncResultType: 1,
568
+			CreateTime:     time.Now().Unix(),
569
+			UpdateTime:     time.Now().Unix(),
570
+		}
571
+		err := service.CreateUploadRecord(upload)
572
+		if err != nil {
573
+			utils.ErrorLog("%v", err)
574
+		}
575
+	} else {
576
+		//错误处理
577
+
578
+	}
579
+
83 580
 }
84 581
 
582
+// 同步处方信息
583
+func (c *SyncController) SyncDoctorAdvice(rdb *gorm.DB, org_id int64, hospital_id int64) {
584
+	// 第一步:根据机构id获取上次同步时间
585
+	syncLastInfo, _ := service.GetSyncTimeByOrgId(org_id, 6)
586
+	var sync_time int64
587
+	if syncLastInfo.ID > 0 {
588
+		sync_time = syncLastInfo.SyncTime
589
+	} else {
590
+		sync_time = 0
591
+	}
592
+
593
+	var hdDoctorAdvices []*sz.TempHdDoctorsAdvice
594
+	dialysisPrescriptions, _ := service.FindOrgDialysisPrescriptionData(org_id, sync_time, time.Now().Unix())
595
+
596
+	for _, dp := range dialysisPrescriptions {
597
+		advice := &sz.TempHdDoctorsAdvice{
598
+			MedicalOrDerId:   strconv.FormatInt(dp.ID, 10),
599
+			HospitalId:       strconv.FormatInt(dp.UserOrgId, 10),
600
+			DialysisId:       strconv.FormatInt(dp.DialysisOrder.ID, 10),
601
+			OrderType:        "1",
602
+			PatientNk:        strconv.FormatInt(dp.PatientId, 10),
603
+			DialysisDuration: dp.DialysisDurationHour*60 + dp.DialysisDurationMinute,
604
+			BloodVol:         int64(math.Floor(dp.BloodFlowVolume + 0/5)),
605
+			CreateTime:       time.Now(),
606
+			Sjscsj:           time.Now(),
607
+			Xgbz:             0,
608
+		}
609
+		hdDoctorAdvices = append(hdDoctorAdvices, advice)
610
+
611
+	}
612
+
613
+	err := service.BatchCreateDoctorsAdvice(hdDoctorAdvices, rdb)
614
+
615
+	if err == nil {
616
+		// 第三步:同步成功后,添加同步记录
617
+		upload := &sz.DataUpload{
618
+			SyncType:       6,
619
+			OrgId:          org_id,
620
+			SyncTime:       time.Now().Unix(),
621
+			SyncResultType: 1,
622
+			CreateTime:     time.Now().Unix(),
623
+			UpdateTime:     time.Now().Unix(),
624
+		}
625
+		err := service.CreateUploadRecord(upload)
626
+		if err != nil {
627
+			utils.ErrorLog("%v", err)
628
+		}
629
+	} else {
630
+		//错误处理
631
+
632
+	}
633
+
634
+}
635
+
636
+//
637
+func (c *SyncController) SyncMiddle(rdb *gorm.DB, org_id int64, hospital_id int64) {
638
+	// 第一步:根据机构id获取上次同步时间
639
+	syncLastInfo, _ := service.GetSyncTimeByOrgId(org_id, 6)
640
+	var sync_time int64
641
+	if syncLastInfo.ID > 0 {
642
+		sync_time = syncLastInfo.SyncTime
643
+	} else {
644
+		sync_time = 0
645
+	}
646
+
647
+	var hdMiddle []*sz.TempHdMiddle
648
+	monitors, _ := service.FindOrgMonitorRecordData(org_id, sync_time, time.Now().Unix())
649
+
650
+	for _, item := range monitors {
651
+
652
+		mid := &sz.TempHdMiddle{
653
+			HospitalId:  strconv.FormatInt(hospital_id, 10),
654
+			DialysisId:  strconv.FormatInt(item.DialysisOrder.ID, 10),
655
+			MonitorTime: time.Unix(item.OperateTime, 0),
656
+			Sbp:         int64(math.Floor(item.SystolicBloodPressure + 0/5)),
657
+			Dbp:         int64(math.Floor(item.DiastolicBloodPressure + 0/5)),
658
+			PatientNk:   strconv.FormatInt(item.PatientId, 10),
659
+			CreateTime:  time.Now(),
660
+			Sjscsj:      time.Now(),
661
+			Xgbz:        0,
662
+		}
663
+
664
+		hdMiddle = append(hdMiddle, mid)
665
+
666
+	}
667
+
668
+	err := service.BatchCreateMonitor(hdMiddle, rdb)
669
+
670
+	if err == nil {
671
+		// 第三步:同步成功后,添加同步记录
672
+		upload := &sz.DataUpload{
673
+			SyncType:       6,
674
+			OrgId:          org_id,
675
+			SyncTime:       time.Now().Unix(),
676
+			SyncResultType: 1,
677
+			CreateTime:     time.Now().Unix(),
678
+			UpdateTime:     time.Now().Unix(),
679
+		}
680
+		err := service.CreateUploadRecord(upload)
681
+		if err != nil {
682
+			utils.ErrorLog("%v", err)
683
+		}
684
+	} else {
685
+		//错误处理
686
+
687
+	}
688
+
689
+}

+ 48 - 10
models/src_data.go View File

@@ -1,17 +1,17 @@
1 1
 package models
2 2
 
3 3
 type XTSyncInfo struct {
4
-	ID             	int64 `gorm:"column:id" json:"id" form:"id"`
5
-	OrgId       	int64 `gorm:"column:org_id" json:"org_id" form:"org_id"`
6
-	SyncType       	int64 `gorm:"column:sync_type" json:"sync_type" form:"sync_type"`
7
-	SyncTime       	int64 `gorm:"column:sync_time" json:"sync_time" form:"sync_time"`
8
-	SyncResultType  int	  `gorm:"column:sync_result_type" json:"sync_result_type" form:"sync_result_type"`
4
+	ID              int64  `gorm:"column:id" json:"id" form:"id"`
5
+	OrgId           int64  `gorm:"column:org_id" json:"org_id" form:"org_id"`
6
+	SyncType        int64  `gorm:"column:sync_type" json:"sync_type" form:"sync_type"`
7
+	SyncTime        int64  `gorm:"column:sync_time" json:"sync_time" form:"sync_time"`
8
+	SyncResultType  int    `gorm:"column:sync_result_type" json:"sync_result_type" form:"sync_result_type"`
9 9
 	SyncRsultRemark string `gorm:"column:sync_result_remark" json:"sync_result_remark" form:"sync_result_remark"`
10
-	SyncTotalNum    int64 `gorm:"column:sync_total_num" json:"sync_total_num" form:"sync_total_num"`
11
-	SyncSuccessNum  int64 `gorm:"column:sync_success_num" json:"sync_success_num" form:"sync_success_num"`
12
-	SyncInfo      	string `gorm:"column:sync_info" json:"sync_info" form:"sync_info"`
13
-	CreateTime      int64 `gorm:"column:create_time" json:"create_time" form:"create_time"`
14
-	UpdateTime    	int64 `gorm:"column:update_time" json:"update_time" form:"update_time"`
10
+	SyncTotalNum    int64  `gorm:"column:sync_total_num" json:"sync_total_num" form:"sync_total_num"`
11
+	SyncSuccessNum  int64  `gorm:"column:sync_success_num" json:"sync_success_num" form:"sync_success_num"`
12
+	SyncInfo        string `gorm:"column:sync_info" json:"sync_info" form:"sync_info"`
13
+	CreateTime      int64  `gorm:"column:create_time" json:"create_time" form:"create_time"`
14
+	UpdateTime      int64  `gorm:"column:update_time" json:"update_time" form:"update_time"`
15 15
 }
16 16
 
17 17
 func (XTSyncInfo) TableName() string {
@@ -671,3 +671,41 @@ type VMDialysisPrescription struct {
671 671
 func (VMDialysisPrescription) TableName() string {
672 672
 	return "xt_dialysis_prescription"
673 673
 }
674
+
675
+type VMDeviceAddmacher struct {
676
+	ID                  int64  `gorm:"column:id" json:"id" form:"id"`
677
+	SerialNumber        string `gorm:"column:serial_number" json:"serial_number" form:"serial_number"`
678
+	DeviceType          int64  `gorm:"column:device_type" json:"device_type" form:"device_type"`
679
+	BedNumber           string `gorm:"column:bed_number" json:"bed_number" form:"bed_number"`
680
+	DeviceName          string `gorm:"column:device_name" json:"device_name" form:"device_name"`
681
+	ManufactureFactory  string `gorm:"column:manufacture_factory" json:"manufacture_factory" form:"manufacture_factory"`
682
+	ServiceManufacturer string `gorm:"column:service_manufacturer" json:"service_manufacturer" form:"service_manufacturer"`
683
+	UnitType            int64  `gorm:"column:unit_type" json:"unit_type" form:"unit_type"`
684
+	UseSection          string `gorm:"column:use_section" json:"use_section" form:"use_section"`
685
+	SectionNumber       string `gorm:"column:section_number" json:"section_number" form:"section_number"`
686
+	BuyDate             int64  `gorm:"column:buy_date" json:"buy_date" form:"buy_date"`
687
+	InstallDate         int64  `gorm:"column:install_date" json:"install_date" form:"install_date"`
688
+	StartDate           int64  `gorm:"column:start_date" json:"start_date" form:"start_date"`
689
+	MaintenaceEngineer  string `gorm:"column:maintenace_engineer" json:"maintenace_engineer" form:"maintenace_engineer"`
690
+	Telephone           string `gorm:"column:telephone" json:"telephone" form:"telephone"`
691
+	GuaranteeDate       string `gorm:"column:guarantee_date" json:"guarantee_date" form:"guarantee_date"`
692
+	MachineStatus       int64  `gorm:"column:machine_status" json:"machine_status" form:"machine_status"`
693
+	UserTotal           string `gorm:"column:user_total" json:"user_total" form:"user_total"`
694
+	DisinfectionMode    int64  `gorm:"column:disinfection_mode" json:"disinfection_mode" form:"disinfection_mode"`
695
+	Remarks             string `gorm:"column:remarks" json:"remarks" form:"remarks"`
696
+	RubbishDate         int64  `gorm:"column:rubbish_date" json:"rubbish_date" form:"rubbish_date"`
697
+	RubbishReason       int64  `gorm:"column:rubbish_reason" json:"rubbish_reason" form:"rubbish_reason"`
698
+	UserYear            string `gorm:"column:user_year" json:"user_year" form:"user_year"`
699
+	WorkTime            string `gorm:"column:work_time" json:"work_time" form:"work_time"`
700
+	ReversMode          int64  `gorm:"column:revers_mode" json:"revers_mode" form:"revers_mode"`
701
+	UserOrgId           int64  `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
702
+	Status              int64  `gorm:"column:status" json:"status" form:"status"`
703
+	Ctime               int64  `gorm:"column:ctime" json:"ctime" form:"ctime"`
704
+	Mtime               int64  `gorm:"column:mtime" json:"mtime" form:"mtime"`
705
+	ZoneId              int64  `gorm:"column:zone_id" json:"zone_id" form:"zone_id"`
706
+	BedId               int64  `gorm:"column:bed_id" json:"bed_id" form:"bed_id"`
707
+}
708
+
709
+func (VMDeviceAddmacher) TableName() string {
710
+	return "xt_device_addmacher"
711
+}

+ 137 - 139
models/sz/target_data.go View File

@@ -50,7 +50,6 @@ type TempHdStaff struct {
50 50
 	Mj                           string    `gorm:"column:MJ" json:"MJ"`
51 51
 	Ylyl1                        string    `gorm:"column:YLYL1" json:"YLYL1"`
52 52
 	Ylyl2                        string    `gorm:"column:YLYL2" json:"YLYL2"`
53
-	
54 53
 }
55 54
 
56 55
 func (TempHdStaff) TableName() string {
@@ -58,48 +57,47 @@ func (TempHdStaff) TableName() string {
58 57
 }
59 58
 
60 59
 type TempHdLayout struct {
61
-	ID             	int64     `gorm:"column:id" json:"id"`
62
-	HospitalId     	string    `gorm:"column:HOSPITAL_ID" json:"HOSPITAL_ID"`
63
-	PartitionName   string    `gorm:"column:PARTITION_NAME" json:"PARTITION_NAME"`
64
-	PartitionImg 	string    `gorm:"column:PARTITION_IMG" json:"PARTITION_IMG"`
65
-	FunctionArea 	string    `gorm:"column:FUNCTION_AREA" json:"FUNCTION_AREA"`
66
-	Xgbz           	int64     `gorm:"column:XGBZ" json:"XGBZ"`
67
-	CreateTime     time.Time `gorm:"column:CREATE_TIME" json:"CREATE_TIME"`
68
-	Sjscsj         time.Time `gorm:"column:SJSCSJ" json:"SJSCSJ"`
69
-	Mj             string    `gorm:"column:MJ" json:"MJ"`
70
-	Ylyl1          string    `gorm:"column:YLYL1" json:"YLYL1"`
71
-	Ylyl2          string    `gorm:"column:YLYL2" json:"YLYL2"`
60
+	ID            int64     `gorm:"column:id" json:"id"`
61
+	HospitalId    string    `gorm:"column:HOSPITAL_ID" json:"HOSPITAL_ID"`
62
+	PartitionName string    `gorm:"column:PARTITION_NAME" json:"PARTITION_NAME"`
63
+	PartitionImg  string    `gorm:"column:PARTITION_IMG" json:"PARTITION_IMG"`
64
+	FunctionArea  string    `gorm:"column:FUNCTION_AREA" json:"FUNCTION_AREA"`
65
+	Xgbz          int64     `gorm:"column:XGBZ" json:"XGBZ"`
66
+	CreateTime    time.Time `gorm:"column:CREATE_TIME" json:"CREATE_TIME"`
67
+	Sjscsj        time.Time `gorm:"column:SJSCSJ" json:"SJSCSJ"`
68
+	Mj            string    `gorm:"column:MJ" json:"MJ"`
69
+	Ylyl1         string    `gorm:"column:YLYL1" json:"YLYL1"`
70
+	Ylyl2         string    `gorm:"column:YLYL2" json:"YLYL2"`
72 71
 }
73 72
 
74 73
 func (TempHdLayout) TableName() string {
75 74
 	return "t_hd_layout"
76 75
 }
77 76
 
78
-
79 77
 type TempHdDm struct {
80 78
 	ID             int64     `gorm:"column:id" json:"id"`
81
-	HospitalId     	string    `gorm:"column:HOSPITAL_ID" json:"HOSPITAL_ID"`
82
-	EquipmentId    	string    `gorm:"column:EQUIPMENT_ID" json:"EQUIPMENT_ID"`
83
-	SickbedNo      	string    `gorm:"column:SICKBED_NO" json:"SICKBED_NO"`
84
-	EquipmentBrand 	string    `gorm:"column:EQUIPMENT_BRAND" json:"EQUIPMENT_BRAND"`
85
-	EquipmentModel 	string    `gorm:"column:EQUIPMENT_MODEL" json:"EQUIPMENT_MODEL"`
86
-	EnableTime     	time.Time `gorm:"column:ENABLE_TIME" json:"ENABLE_TIME"`
87
-	DiscardedTime  	time.Time `gorm:"column:DISCARDED_TIME" json:"DISCARDED_TIME"`
88
-	Status         	string    `gorm:"column:STATUS" json:"STATUS"`
89
-	EquipmentType  	string    `gorm:"column:EQUIPMENT_TYPE" json:"EQUIPMENT_TYPE"`
90
-	Temperature    	string    `gorm:"column:TEMPERATURE" json:"TEMPERATURE"`
91
-	Humidity   		string    `gorm:"column:HUMIDITY" json:"HUMIDITY"`
92
-	Pressure       	string    `gorm:"column:PRESSURE" json:"PRESSURE"`
93
-	PressureUnit   	string    `gorm:"column:PRESSURE_UNIT" json:"PRESSURE_UNIT"`
94
-	WorkingVoltage 	string    `gorm:"column:WORKING_VOLTAGE" json:"WORKING_VOLTAGE"`
95
-	Xgbz           	string    `gorm:"column:XGBZ" json:"XGBZ"`
96
-	Bbp            	string    `gorm:"column:BBP" json:"BBP"`
97
-	CreateTime     	time.Time `gorm:"column:CREATE_TIME" json:"CREATE_TIME"`
98
-	UpdateTime     	time.Time `gorm:"column:UPDATE_TIME" json:"UPDATE_TIME"`
99
-	Sjscsj         	time.Time `gorm:"column:SJSCSJ" json:"SJSCSJ"`
100
-	Mj            	string    `gorm:"column:MJ" json:"MJ"`
101
-	Ylyl1          	string    `gorm:"column:YLYL1" json:"YLYL1"`
102
-	Ylyl2          	string    `gorm:"column:YLYL2" json:"YLYL2"`
79
+	HospitalId     string    `gorm:"column:HOSPITAL_ID" json:"HOSPITAL_ID"`
80
+	EquipmentId    string    `gorm:"column:EQUIPMENT_ID" json:"EQUIPMENT_ID"`
81
+	SickbedNo      string    `gorm:"column:SICKBED_NO" json:"SICKBED_NO"`
82
+	EquipmentBrand string    `gorm:"column:EQUIPMENT_BRAND" json:"EQUIPMENT_BRAND"`
83
+	EquipmentModel string    `gorm:"column:EQUIPMENT_MODEL" json:"EQUIPMENT_MODEL"`
84
+	EnableTime     time.Time `gorm:"column:ENABLE_TIME" json:"ENABLE_TIME"`
85
+	DiscardedTime  time.Time `gorm:"column:DISCARDED_TIME" json:"DISCARDED_TIME"`
86
+	Status         string    `gorm:"column:STATUS" json:"STATUS"`
87
+	EquipmentType  string    `gorm:"column:EQUIPMENT_TYPE" json:"EQUIPMENT_TYPE"`
88
+	Temperature    string    `gorm:"column:TEMPERATURE" json:"TEMPERATURE"`
89
+	Humidity       string    `gorm:"column:HUMIDITY" json:"HUMIDITY"`
90
+	Pressure       string    `gorm:"column:PRESSURE" json:"PRESSURE"`
91
+	PressureUnit   string    `gorm:"column:PRESSURE_UNIT" json:"PRESSURE_UNIT"`
92
+	WorkingVoltage string    `gorm:"column:WORKING_VOLTAGE" json:"WORKING_VOLTAGE"`
93
+	Xgbz           string    `gorm:"column:XGBZ" json:"XGBZ"`
94
+	Bbp            string    `gorm:"column:BBP" json:"BBP"`
95
+	CreateTime     time.Time `gorm:"column:CREATE_TIME" json:"CREATE_TIME"`
96
+	UpdateTime     time.Time `gorm:"column:UPDATE_TIME" json:"UPDATE_TIME"`
97
+	Sjscsj         time.Time `gorm:"column:SJSCSJ" json:"SJSCSJ"`
98
+	Mj             string    `gorm:"column:MJ" json:"MJ"`
99
+	Ylyl1          string    `gorm:"column:YLYL1" json:"YLYL1"`
100
+	Ylyl2          string    `gorm:"column:YLYL2" json:"YLYL2"`
103 101
 }
104 102
 
105 103
 func (TempHdDm) TableName() string {
@@ -107,26 +105,26 @@ func (TempHdDm) TableName() string {
107 105
 }
108 106
 
109 107
 type TempHdWm struct {
110
-	ID             int64     `gorm:"column:id" json:"id"`
111
-	HospitalId     	string    `gorm:"column:HOSPITAL_ID" json:"HOSPITAL_ID"`
112
-	EquipmentId    	string    `gorm:"column:EQUIPMENT_ID" json:"EQUIPMENT_ID"`
113
-	EquipmentBrand 	string    `gorm:"column:EQUIPMENT_BRAND" json:"EQUIPMENT_BRAND"`
114
-	EquipmentModel 	string    `gorm:"column:EQUIPMENT_MODEL" json:"EQUIPMENT_MODEL"`
115
-	EnableTime     	time.Time `gorm:"column:ENABLE_TIME" json:"ENABLE_TIME"`
116
-	DiscardedTime  	time.Time `gorm:"column:DISCARDED_TIME" json:"DISCARDED_TIME"`
117
-	EquipmentType  	string    `gorm:"column:EQUIPMENT_TYPE" json:"EQUIPMENT_TYPE"`
118
-	Temperature    	string    `gorm:"column:TEMPERATURE" json:"TEMPERATURE"`
119
-	Humidity   		string    `gorm:"column:HUMIDITY" json:"HUMIDITY"`
120
-	Pressure       	string    `gorm:"column:PRESSURE" json:"PRESSURE"`
121
-	PressureUnit   	string    `gorm:"column:PRESSURE_UNIT" json:"PRESSURE_UNIT"`
108
+	ID              int64     `gorm:"column:id" json:"id"`
109
+	HospitalId      string    `gorm:"column:HOSPITAL_ID" json:"HOSPITAL_ID"`
110
+	EquipmentId     string    `gorm:"column:EQUIPMENT_ID" json:"EQUIPMENT_ID"`
111
+	EquipmentBrand  string    `gorm:"column:EQUIPMENT_BRAND" json:"EQUIPMENT_BRAND"`
112
+	EquipmentModel  string    `gorm:"column:EQUIPMENT_MODEL" json:"EQUIPMENT_MODEL"`
113
+	EnableTime      time.Time `gorm:"column:ENABLE_TIME" json:"ENABLE_TIME"`
114
+	DiscardedTime   time.Time `gorm:"column:DISCARDED_TIME" json:"DISCARDED_TIME"`
115
+	EquipmentType   string    `gorm:"column:EQUIPMENT_TYPE" json:"EQUIPMENT_TYPE"`
116
+	Temperature     string    `gorm:"column:TEMPERATURE" json:"TEMPERATURE"`
117
+	Humidity        string    `gorm:"column:HUMIDITY" json:"HUMIDITY"`
118
+	Pressure        string    `gorm:"column:PRESSURE" json:"PRESSURE"`
119
+	PressureUnit    string    `gorm:"column:PRESSURE_UNIT" json:"PRESSURE_UNIT"`
122 120
 	QualityStandard string    `gorm:"column:QUALITY_STANDARD" json:"QUALITY_STANDARD"`
123
-	Xgbz           	string    `gorm:"column:XGBZ" json:"XGBZ"`
124
-	CreateTime     	time.Time `gorm:"column:CREATE_TIME" json:"CREATE_TIME"`
125
-	UpdateTime     	time.Time `gorm:"column:UPDATE_TIME" json:"UPDATE_TIME"`
126
-	Sjscsj         	time.Time `gorm:"column:SJSCSJ" json:"SJSCSJ"`
127
-	Mj            	string    `gorm:"column:MJ" json:"MJ"`
128
-	Ylyl1          	string    `gorm:"column:YLYL1" json:"YLYL1"`
129
-	Ylyl2          	string    `gorm:"column:YLYL2" json:"YLYL2"`
121
+	Xgbz            string    `gorm:"column:XGBZ" json:"XGBZ"`
122
+	CreateTime      time.Time `gorm:"column:CREATE_TIME" json:"CREATE_TIME"`
123
+	UpdateTime      time.Time `gorm:"column:UPDATE_TIME" json:"UPDATE_TIME"`
124
+	Sjscsj          time.Time `gorm:"column:SJSCSJ" json:"SJSCSJ"`
125
+	Mj              string    `gorm:"column:MJ" json:"MJ"`
126
+	Ylyl1           string    `gorm:"column:YLYL1" json:"YLYL1"`
127
+	Ylyl2           string    `gorm:"column:YLYL2" json:"YLYL2"`
130 128
 }
131 129
 
132 130
 func (TempHdWm) TableName() string {
@@ -134,18 +132,18 @@ func (TempHdWm) TableName() string {
134 132
 }
135 133
 
136 134
 type TempHdMaintain struct {
137
-	ID             	int64     `gorm:"column:id" json:"id"`
138
-	SN				string    `gorm:"column:SN" json:"SN"`
139
-	HospitalId     	string    `gorm:"column:HOSPITAL_ID" json:"HOSPITAL_ID"`
140
-	EquipmentId    	string    `gorm:"column:EQUIPMENT_ID" json:"EQUIPMENT_ID"`
141
-	EquipmentType  	string    `gorm:"column:EQUIPMENT_TYPE" json:"EQUIPMENT_TYPE"`
142
-	RepairTime    	time.Time `gorm:"column:REPAIR_TIME" json:"REPAIR_TIME"`
143
-	Xgbz           	string    `gorm:"column:XGBZ" json:"XGBZ"`
144
-	CreateTime     	time.Time `gorm:"column:CREATE_TIME" json:"CREATE_TIME"`
145
-	Sjscsj         	time.Time `gorm:"column:SJSCSJ" json:"SJSCSJ"`
146
-	Mj            	string    `gorm:"column:MJ" json:"MJ"`
147
-	Ylyl1          	string    `gorm:"column:YLYL1" json:"YLYL1"`
148
-	Ylyl2          	string    `gorm:"column:YLYL2" json:"YLYL2"`
135
+	ID            int64     `gorm:"column:id" json:"id"`
136
+	SN            string    `gorm:"column:SN" json:"SN"`
137
+	HospitalId    string    `gorm:"column:HOSPITAL_ID" json:"HOSPITAL_ID"`
138
+	EquipmentId   string    `gorm:"column:EQUIPMENT_ID" json:"EQUIPMENT_ID"`
139
+	EquipmentType string    `gorm:"column:EQUIPMENT_TYPE" json:"EQUIPMENT_TYPE"`
140
+	RepairTime    time.Time `gorm:"column:REPAIR_TIME" json:"REPAIR_TIME"`
141
+	Xgbz          string    `gorm:"column:XGBZ" json:"XGBZ"`
142
+	CreateTime    time.Time `gorm:"column:CREATE_TIME" json:"CREATE_TIME"`
143
+	Sjscsj        time.Time `gorm:"column:SJSCSJ" json:"SJSCSJ"`
144
+	Mj            string    `gorm:"column:MJ" json:"MJ"`
145
+	Ylyl1         string    `gorm:"column:YLYL1" json:"YLYL1"`
146
+	Ylyl2         string    `gorm:"column:YLYL2" json:"YLYL2"`
149 147
 }
150 148
 
151 149
 func (TempHdMaintain) TableName() string {
@@ -153,23 +151,23 @@ func (TempHdMaintain) TableName() string {
153 151
 }
154 152
 
155 153
 type TempHdDisinfectMethod struct {
156
-	ID             	int64     `gorm:"column:id" json:"id"`
157
-	SN				string    `gorm:"column:SN" json:"SN"`
158
-	HospitalId     	string    `gorm:"column:HOSPITAL_ID" json:"HOSPITAL_ID"`
159
-	EquipmentId    	string    `gorm:"column:EQUIPMENT_ID" json:"EQUIPMENT_ID"`
160
-	EquipmentType  	string    `gorm:"column:EQUIPMENT_TYPE" json:"EQUIPMENT_TYPE"`
161
-	EquipmentModel 	string    `gorm:"column:EQUIPMENT_MODEL" json:"EQUIPMENT_MODEL"`
162
-	DisinfectMethod	string    `gorm:"column:DISINFECT_METHOD" json:"DISINFECT_METHOD"`
163
-	Disinfector		string    `gorm:"column:DISINFECTOR" json:"DISINFECTOR"`
164
-	Concentration	string    `gorm:"column:CONCENTRATION" json:"CONCENTRATION"`
165
-	Frequency		string    `gorm:"column:FREQUENCY" json:"FREQUENCY"`
166
-	Xgbz           	string    `gorm:"column:XGBZ" json:"XGBZ"`
167
-	CreateTime     	time.Time `gorm:"column:CREATE_TIME" json:"CREATE_TIME"`
168
-	UpdateTime     	time.Time `gorm:"column:UPDATE_TIME" json:"UPDATE_TIME"`
169
-	Sjscsj         	time.Time `gorm:"column:SJSCSJ" json:"SJSCSJ"`
170
-	Mj            	string    `gorm:"column:MJ" json:"MJ"`
171
-	Ylyl1          	string    `gorm:"column:YLYL1" json:"YLYL1"`
172
-	Ylyl2          	string    `gorm:"column:YLYL2" json:"YLYL2"`
154
+	ID              int64     `gorm:"column:id" json:"id"`
155
+	SN              string    `gorm:"column:SN" json:"SN"`
156
+	HospitalId      string    `gorm:"column:HOSPITAL_ID" json:"HOSPITAL_ID"`
157
+	EquipmentId     string    `gorm:"column:EQUIPMENT_ID" json:"EQUIPMENT_ID"`
158
+	EquipmentType   string    `gorm:"column:EQUIPMENT_TYPE" json:"EQUIPMENT_TYPE"`
159
+	EquipmentModel  string    `gorm:"column:EQUIPMENT_MODEL" json:"EQUIPMENT_MODEL"`
160
+	DisinfectMethod string    `gorm:"column:DISINFECT_METHOD" json:"DISINFECT_METHOD"`
161
+	Disinfector     string    `gorm:"column:DISINFECTOR" json:"DISINFECTOR"`
162
+	Concentration   string    `gorm:"column:CONCENTRATION" json:"CONCENTRATION"`
163
+	Frequency       string    `gorm:"column:FREQUENCY" json:"FREQUENCY"`
164
+	Xgbz            string    `gorm:"column:XGBZ" json:"XGBZ"`
165
+	CreateTime      time.Time `gorm:"column:CREATE_TIME" json:"CREATE_TIME"`
166
+	UpdateTime      time.Time `gorm:"column:UPDATE_TIME" json:"UPDATE_TIME"`
167
+	Sjscsj          time.Time `gorm:"column:SJSCSJ" json:"SJSCSJ"`
168
+	Mj              string    `gorm:"column:MJ" json:"MJ"`
169
+	Ylyl1           string    `gorm:"column:YLYL1" json:"YLYL1"`
170
+	Ylyl2           string    `gorm:"column:YLYL2" json:"YLYL2"`
173 171
 }
174 172
 
175 173
 func (TempHdDisinfectMethod) TableName() string {
@@ -178,20 +176,20 @@ func (TempHdDisinfectMethod) TableName() string {
178 176
 
179 177
 type TempHdOtherMachine struct {
180 178
 	ID             int64     `gorm:"column:id" json:"id"`
181
-	HospitalId     	string    `gorm:"column:HOSPITAL_ID" json:"HOSPITAL_ID"`
182
-	EquipmentId    	string    `gorm:"column:EQUIPMENT_ID" json:"EQUIPMENT_ID"`
183
-	EquipmentBrand 	string    `gorm:"column:EQUIPMENT_BRAND" json:"EQUIPMENT_BRAND"`
184
-	EquipmentModel 	string    `gorm:"column:EQUIPMENT_MODEL" json:"EQUIPMENT_MODEL"`
185
-	EnableTime     	time.Time `gorm:"column:ENABLE_TIME" json:"ENABLE_TIME"`
186
-	DiscardedTime  	time.Time `gorm:"column:DISCARDED_TIME" json:"DISCARDED_TIME"`
187
-	Status         	string    `gorm:"column:STATUS" json:"STATUS"`
188
-	Xgbz           	string    `gorm:"column:XGBZ" json:"XGBZ"`
189
-	CreateTime     	time.Time `gorm:"column:CREATE_TIME" json:"CREATE_TIME"`
190
-	UpdateTime     	time.Time `gorm:"column:UPDATE_TIME" json:"UPDATE_TIME"`
191
-	Sjscsj         	time.Time `gorm:"column:SJSCSJ" json:"SJSCSJ"`
192
-	Mj            	string    `gorm:"column:MJ" json:"MJ"`
193
-	Ylyl1          	string    `gorm:"column:YLYL1" json:"YLYL1"`
194
-	Ylyl2          	string    `gorm:"column:YLYL2" json:"YLYL2"`
179
+	HospitalId     string    `gorm:"column:HOSPITAL_ID" json:"HOSPITAL_ID"`
180
+	EquipmentId    string    `gorm:"column:EQUIPMENT_ID" json:"EQUIPMENT_ID"`
181
+	EquipmentBrand string    `gorm:"column:EQUIPMENT_BRAND" json:"EQUIPMENT_BRAND"`
182
+	EquipmentModel string    `gorm:"column:EQUIPMENT_MODEL" json:"EQUIPMENT_MODEL"`
183
+	EnableTime     time.Time `gorm:"column:ENABLE_TIME" json:"ENABLE_TIME"`
184
+	DiscardedTime  time.Time `gorm:"column:DISCARDED_TIME" json:"DISCARDED_TIME"`
185
+	Status         string    `gorm:"column:STATUS" json:"STATUS"`
186
+	Xgbz           string    `gorm:"column:XGBZ" json:"XGBZ"`
187
+	CreateTime     time.Time `gorm:"column:CREATE_TIME" json:"CREATE_TIME"`
188
+	UpdateTime     time.Time `gorm:"column:UPDATE_TIME" json:"UPDATE_TIME"`
189
+	Sjscsj         time.Time `gorm:"column:SJSCSJ" json:"SJSCSJ"`
190
+	Mj             string    `gorm:"column:MJ" json:"MJ"`
191
+	Ylyl1          string    `gorm:"column:YLYL1" json:"YLYL1"`
192
+	Ylyl2          string    `gorm:"column:YLYL2" json:"YLYL2"`
195 193
 }
196 194
 
197 195
 func (TempHdOtherMachine) TableName() string {
@@ -225,7 +223,7 @@ type TempHdPatient struct {
225 223
 }
226 224
 
227 225
 func (TempHdPatient) TableName() string {
228
-	return "temp_hd_patient"
226
+	return "t_hd_patient"
229 227
 }
230 228
 
231 229
 type TempHdPatientOut struct {
@@ -246,7 +244,7 @@ type TempHdPatientOut struct {
246 244
 }
247 245
 
248 246
 func (TempHdPatientOut) TableName() string {
249
-	return "temp_hd_patient_out"
247
+	return "t_hd_patient_out"
250 248
 }
251 249
 
252 250
 type TempHdPs struct {
@@ -284,7 +282,7 @@ type TempHdPs struct {
284 282
 }
285 283
 
286 284
 func (TempHdPs) TableName() string {
287
-	return "temp_hd_ps"
285
+	return "t_hd_ps"
288 286
 }
289 287
 
290 288
 type TempHdPsMedicine struct {
@@ -303,7 +301,7 @@ type TempHdPsMedicine struct {
303 301
 }
304 302
 
305 303
 func (TempHdPsMedicine) TableName() string {
306
-	return "temp_hd_ps_medicine"
304
+	return "t_hd_ps_medicine"
307 305
 }
308 306
 
309 307
 type TempHdInfection struct {
@@ -329,7 +327,7 @@ type TempHdInfection struct {
329 327
 }
330 328
 
331 329
 func (TempHdInfection) TableName() string {
332
-	return "temp_hd_infection"
330
+	return "t_hd_infection"
333 331
 }
334 332
 
335 333
 type TempHdInhospital struct {
@@ -347,7 +345,7 @@ type TempHdInhospital struct {
347 345
 }
348 346
 
349 347
 func (TempHdInhospital) TableName() string {
350
-	return "temp_hd_inhospital"
348
+	return "t_hd_inhospital"
351 349
 }
352 350
 
353 351
 type TempHdOuthospital struct {
@@ -364,47 +362,47 @@ type TempHdOuthospital struct {
364 362
 }
365 363
 
366 364
 func (TempHdOuthospital) TableName() string {
367
-	return "temp_hd_outhospital"
365
+	return "t_hd_outhospital"
368 366
 }
369 367
 
370 368
 type DataUpload struct {
371
-	ID             	int64 `gorm:"column:id" json:"id" form:"id"`
372
-	OrgId       	int64 `gorm:"column:org_id" json:"org_id" form:"org_id"`
373
-	SyncType       	int64 `gorm:"column:sync_type" json:"sync_type" form:"sync_type"`
374
-	SyncTime       	int64 `gorm:"column:sync_time" json:"sync_time" form:"sync_time"`
375
-	SyncResultType  int	  `gorm:"column:sync_result_type" json:"sync_result_type" form:"sync_result_type"`
369
+	ID              int64  `gorm:"column:id" json:"id" form:"id"`
370
+	OrgId           int64  `gorm:"column:org_id" json:"org_id" form:"org_id"`
371
+	SyncType        int64  `gorm:"column:sync_type" json:"sync_type" form:"sync_type"`
372
+	SyncTime        int64  `gorm:"column:sync_time" json:"sync_time" form:"sync_time"`
373
+	SyncResultType  int    `gorm:"column:sync_result_type" json:"sync_result_type" form:"sync_result_type"`
376 374
 	SyncRsultRemark string `gorm:"column:sync_result_remark" json:"sync_result_remark" form:"sync_result_remark"`
377
-	SyncTotalNum    int64 `gorm:"column:sync_total_num" json:"sync_total_num" form:"sync_total_num"`
378
-	SyncSuccessNum  int64 `gorm:"column:sync_success_num" json:"sync_success_num" form:"sync_success_num"`
379
-	SyncInfo      	string `gorm:"column:sync_info" json:"sync_info" form:"sync_info"`
380
-	CreateTime      int64 `gorm:"column:create_time" json:"create_time" form:"create_time"`
381
-	UpdateTime    	int64 `gorm:"column:update_time" json:"update_time" form:"update_time"`
375
+	SyncTotalNum    int64  `gorm:"column:sync_total_num" json:"sync_total_num" form:"sync_total_num"`
376
+	SyncSuccessNum  int64  `gorm:"column:sync_success_num" json:"sync_success_num" form:"sync_success_num"`
377
+	SyncInfo        string `gorm:"column:sync_info" json:"sync_info" form:"sync_info"`
378
+	CreateTime      int64  `gorm:"column:create_time" json:"create_time" form:"create_time"`
379
+	UpdateTime      int64  `gorm:"column:update_time" json:"update_time" form:"update_time"`
382 380
 }
383 381
 
384 382
 func (DataUpload) TableName() string {
385
-	return "data_upload"
383
+	return "data_sync_info"
386 384
 }
387 385
 
388 386
 type DataUploadConfig struct {
389
-	ID             	int64  `gorm:"column:id" json:"id"`
390
-	OrgId          	int64  `gorm:"column:org_id" json:"org_id"`
391
-	ProvinceId     	int64  `gorm:"column:province_id" json:"province_id"`
392
-	CityId         	int64  `gorm:"column:city_id" json:"city_id"`
393
-	GatewayAddress 	string `gorm:"column:gateway_address" json:"gateway_address"`
394
-	AppId          	string `gorm:"column:app_id" json:"app_id"`
395
-	Key            	string `gorm:"column:key" json:"key"`
396
-	Status         	int64  `gorm:"column:status" json:"status"`
397
-	CreateTime     	int64  `gorm:"column:create_time" json:"create_time"`
398
-	ModifyTime     	int64  `gorm:"column:modify_time" json:"modify_time"`
399
-	TimeQuantum    	int64  `gorm:"column:time_quantum" json:"time_quantum"`
400
-	DepartmentName  string `gorm:"column:department_name" json:"department_name"`
401
-	HospitalId 		int64  `gorm:"column:hospital_id" json:"hospital_id"`
402
-	InstType    	int64  `gorm:"column:inst_type" json:"inst_type"`
403
-	DbHost			string `gorm:"column:db_host" json:"db_host"`
404
-	DbPort			string `gorm:"column:db_port" json:"db_port"`
405
-	DbUser			string `gorm:"column:db_user" json:"db_user"`
406
-	DbPass			string `gorm:"column:db_pass" json:"db_pass"`
407
-	DbName			string `gorm:"column:db_name" json:"db_name"`
387
+	ID             int64  `gorm:"column:id" json:"id"`
388
+	OrgId          int64  `gorm:"column:org_id" json:"org_id"`
389
+	ProvinceId     int64  `gorm:"column:province_id" json:"province_id"`
390
+	CityId         int64  `gorm:"column:city_id" json:"city_id"`
391
+	GatewayAddress string `gorm:"column:gateway_address" json:"gateway_address"`
392
+	AppId          string `gorm:"column:app_id" json:"app_id"`
393
+	Key            string `gorm:"column:key" json:"key"`
394
+	Status         int64  `gorm:"column:status" json:"status"`
395
+	CreateTime     int64  `gorm:"column:create_time" json:"create_time"`
396
+	ModifyTime     int64  `gorm:"column:modify_time" json:"modify_time"`
397
+	TimeQuantum    int64  `gorm:"column:time_quantum" json:"time_quantum"`
398
+	DepartmentName string `gorm:"column:department_name" json:"department_name"`
399
+	HospitalId     int64  `gorm:"column:hospital_id" json:"hospital_id"`
400
+	InstType       int64  `gorm:"column:inst_type" json:"inst_type"`
401
+	DbHost         string `gorm:"column:db_host" json:"db_host"`
402
+	DbPort         string `gorm:"column:db_port" json:"db_port"`
403
+	DbUser         string `gorm:"column:db_user" json:"db_user"`
404
+	DbPass         string `gorm:"column:db_pass" json:"db_pass"`
405
+	DbName         string `gorm:"column:db_name" json:"db_name"`
408 406
 }
409 407
 
410 408
 func (DataUploadConfig) TableName() string {
@@ -429,7 +427,7 @@ type TempHdShift struct {
429 427
 }
430 428
 
431 429
 func (TempHdShift) TableName() string {
432
-	return "temp_hd_shift"
430
+	return "t_hd_shift"
433 431
 }
434 432
 
435 433
 type TempHdDoctorsAdvice struct {
@@ -452,7 +450,7 @@ type TempHdDoctorsAdvice struct {
452 450
 }
453 451
 
454 452
 func (TempHdDoctorsAdvice) TableName() string {
455
-	return "temp_hd_doctors_advice"
453
+	return "t_hd_doctors_advice"
456 454
 }
457 455
 
458 456
 type TempHdDialysis struct {
@@ -494,7 +492,7 @@ type TempHdDialysis struct {
494 492
 }
495 493
 
496 494
 func (TempHdDialysis) TableName() string {
497
-	return "temp_hd_dialysis"
495
+	return "t_hd_dialysis"
498 496
 }
499 497
 
500 498
 type TempHdMiddle struct {
@@ -528,7 +526,7 @@ type TempHdMiddle struct {
528 526
 }
529 527
 
530 528
 func (TempHdMiddle) TableName() string {
531
-	return "temp_hd_middle"
529
+	return "t_hd_middle"
532 530
 }
533 531
 
534 532
 type TempHdDivision struct {
@@ -547,5 +545,5 @@ type TempHdDivision struct {
547 545
 }
548 546
 
549 547
 func (TempHdDivision) TableName() string {
550
-	return "temp_hd_division"
548
+	return "t_hd_division"
551 549
 }

+ 3 - 3
service/city/auto_create_week_schedules_service.go View File

@@ -104,7 +104,7 @@ func AutoSZUploadData() {
104 104
 					staffs = append(staffs, staff)
105 105
 				}
106 106
 
107
-				err := service.BatchCreateStaffRecord(staffs)
107
+				err := service.BatchCreateStaffRecord(staffs, r)
108 108
 				if err == nil {
109 109
 					upload := &sz.DataUpload{
110 110
 						ModuleType:   2,
@@ -317,7 +317,7 @@ func AutoSZUploadData() {
317 317
 		//
318 318
 		//		var hdPatientOuts []*sz.TempHdPatientOut
319 319
 		//		patients, _ := service.FindOrgPatientOutData(config.OrgId, 0, 0)
320
-		//
320
+		////
321 321
 		//		for _, patient := range patients {
322 322
 		//
323 323
 		//			p := &sz.TempHdPatientOut{
@@ -748,7 +748,7 @@ func AutoSZUploadData() {
748 748
 			if GetDiffDay(config) <= 0 {
749 749
 
750 750
 				var hdDoctorAdvices []*sz.TempHdDoctorsAdvice
751
-				dialysisPrescriptions, _ := service.FindOrgDialysisPrescriptionData(config.OrgId, 0, 0)
751
+				dialysisPrescriptions, _ := service.FindOrgDialysisPrescriptionData(or, 0, 0)
752 752
 
753 753
 				for _, dp := range dialysisPrescriptions {
754 754
 

+ 312 - 38
service/city_data_uoload_service.go View File

@@ -10,8 +10,8 @@ import (
10 10
 	"strings"
11 11
 )
12 12
 
13
-func GetSyncTimeByOrgId(org_id int64,sync_type int64) (sync_info models.XTSyncInfo,err error) {
14
-	err = readDb.Model(&models.XTSyncInfo{}).Where("org_id = ? and sync_type = ? ", org_id,sync_type).Last(&sync_info).Error
13
+func GetSyncTimeByOrgId(org_id int64, sync_type int64) (sync_info models.XTSyncInfo, err error) {
14
+	err = readDb.Model(&models.XTSyncInfo{}).Where("org_id = ? and sync_type = ? ", org_id, sync_type).Last(&sync_info).Error
15 15
 	return
16 16
 }
17 17
 
@@ -25,25 +25,21 @@ func FindDataUploadOrgInfo(org_id int64, module_type int64) (data sz.DataUpload,
25 25
 	return
26 26
 }
27 27
 
28
-func FindOrgData(org_id int64,sync_time int64) (org models.UserOrg, err error) {
29
-	err = readUserDb.Model(&models.UserOrg{}).Where("status = 1 AND id = ? AND ctime > ?", org_id,sync_time).Preload("DeviceNumber", func(db *gorm.DB) *gorm.DB {
28
+func FindOrgData(org_id int64, sync_time int64) (org models.UserOrg, err error) {
29
+	err = readUserDb.Model(&models.UserOrg{}).Where("status = 1 AND id = ? AND ctime > ?", org_id, sync_time).Preload("DeviceNumber", func(db *gorm.DB) *gorm.DB {
30 30
 		return readDb.Where("status = 1")
31 31
 	}).Find(&org).Error
32 32
 	return
33 33
 }
34 34
 func FindOrgRolesData(org_id int64, lastUploadTime int64, nowTime int64) (role []*models.UserAdminRole, err error) {
35 35
 	db := readUserDb.Model(&models.UserAdminRole{}).Where("status = 1 AND org_id = ?  ", org_id)
36
-	if lastUploadTime != 0 && nowTime != 0 {
37
-		db.Where("ctime >= ? AND ctime <= ?", lastUploadTime, nowTime)
38
-	}
36
+	db.Where("ctime >= ? AND ctime <= ?", lastUploadTime, nowTime)
39 37
 	err = db.Find(&role).Error
40 38
 	return
41 39
 }
42 40
 func FindOrgPatientData(org_id int64, lastUploadTime int64, nowTime int64) (patient []*models.Patients, err error) {
43 41
 	db := readDb.Model(&models.Patients{}).Where("status = 1 AND user_org_id = ?", org_id)
44
-	if lastUploadTime != 0 && nowTime != 0 {
45
-		db = db.Where("created_time >= ? AND created_time <= ?", lastUploadTime, nowTime)
46
-	}
42
+	db = db.Where("created_time >= ? AND created_time <= ?", lastUploadTime, nowTime)
47 43
 	err = db.Find(&patient).Error
48 44
 
49 45
 	return
@@ -51,9 +47,7 @@ func FindOrgPatientData(org_id int64, lastUploadTime int64, nowTime int64) (pati
51 47
 
52 48
 func FindOrgPatientOutData(org_id int64, lastUploadTime int64, nowTime int64) (patient []*models.Patients, err error) {
53 49
 	db := readDb.Model(&models.Patients{}).Where("status = 1 AND user_org_id = ? AND lapseto = 2 ", org_id).Preload("PatientLapseto", "status = 1")
54
-	if lastUploadTime != 0 && nowTime != 0 {
55
-		db = db.Where("created_time >= ? AND created_time <= ?", lastUploadTime, nowTime)
56
-	}
50
+	db = db.Where("created_time >= ? AND created_time <= ?", lastUploadTime, nowTime)
57 51
 	err = db.Find(&patient).Error
58 52
 	return
59 53
 }
@@ -70,9 +64,7 @@ func FindOrgScheduleData(org_id int64, lastUploadTime int64, nowTime int64) (sch
70 64
 
71 65
 func FindOrgDialysisPrescriptionData(org_id int64, lastUploadTime int64, nowTime int64) (ps []*models.DialysisPrescription, err error) {
72 66
 	db := readDb.Model(&models.DialysisPrescription{}).Where("status = 1 AND user_org_id = ?", org_id).Preload("AssessmentBeforeDislysis", "status = 1").Preload("DialysisOrder", "status = 1")
73
-	if lastUploadTime != 0 && nowTime != 0 {
74
-		db = db.Where("created_time >= ? AND created_time <= ?", lastUploadTime, nowTime)
75
-	}
67
+	db = db.Where("created_time >= ? AND created_time <= ?", lastUploadTime, nowTime)
76 68
 	err = db.Find(&ps).Error
77 69
 	return
78 70
 }
@@ -80,9 +72,7 @@ func FindOrgDialysisPrescriptionData(org_id int64, lastUploadTime int64, nowTime
80 72
 func FindOrgMonitorRecordData(org_id int64, lastUploadTime int64, nowTime int64) (monitor []*models.MonitoringRecord, err error) {
81 73
 	db := readDb.Model(&models.MonitoringRecord{}).Where("status = 1 AND user_org_id = ?", org_id)
82 74
 
83
-	if lastUploadTime != 0 && nowTime != 0 {
84
-		db = db.Where("created_time >= ? AND created_time <= ?", lastUploadTime, nowTime)
85
-	}
75
+	db = db.Where("created_time >= ? AND created_time <= ?", lastUploadTime, nowTime)
86 76
 	err = db.Find(&monitor).Error
87 77
 
88 78
 	return
@@ -98,11 +88,81 @@ func CreateUploadRecord(upload *sz.DataUpload) (err error) {
98 88
 	return
99 89
 }
100 90
 
101
-func BatchCreateStaffRecord(staffs []*sz.TempHdStaff) (err error) {
91
+func FindOrgDialysisData(org_id int64, lastUploadTime int64, nowTime int64) (ps []*models.VMSchedule, err error) {
92
+	db := readDb.Model(&models.VMSchedule{}).Where("status = 1 AND user_org_id = ? ", org_id).
93
+		Preload("DeviceNumber", "status = 1").
94
+		Preload("VMDialysisPrescription", "status = 1").
95
+		Preload("AssessmentBeforeDislysis", "status = 1").
96
+		Preload("AssessmentAfterDislysis", "status = 1").
97
+		Preload("DialysisOrder", "status = 1").
98
+		Preload("MonitoringRecord", "status = 1")
99
+
100
+	if lastUploadTime != 0 && nowTime != 0 {
101
+		db = db.Where("created_time >= ? AND created_time <= ?", lastUploadTime, nowTime)
102
+	}
103
+	err = db.Find(&ps).Error
104
+	return
105
+}
106
+func FindOrgDeviceZoneRecordData(org_id int64, lastUploadTime int64, nowTime int64) (zone []*models.DeviceZone, err error) {
107
+	db := readDb.Model(&models.DeviceZone{}).Where("status = 1 AND  org_id = ?", org_id)
108
+	if lastUploadTime != 0 && nowTime != 0 {
109
+		db = db.Where("ctime >= ? AND ctime <= ?", lastUploadTime, nowTime)
110
+	}
111
+	err = db.Find(&zone).Error
112
+
113
+	return
114
+}
115
+
116
+func FindOrgWaterMachineData(org_id int64, lastUploadTime int64, nowTime int64) (waterMachine []*models.VMDeviceAddmacher, err error) {
117
+
118
+	db := readDb.Model(&models.VMDeviceAddmacher{}).Where("status = 1 AND  user_org_id = ?", org_id)
119
+
120
+	db = db.Where("ctime >= ? AND ctime <= ?", lastUploadTime, nowTime)
121
+
122
+	err = db.Find(&waterMachine).Error
123
+
124
+	return
125
+}
126
+
127
+func BatchCreateWMsRecord(wms []*sz.TempHdWm, rdb *gorm.DB) (err error) {
128
+	if len(wms) > 0 {
129
+		utx := rdb.Begin()
130
+		if len(wms) > 0 {
131
+			thisSQL := "INSERT INTO t_hd_wm (HOSPITAL_ID, EQUIPMENT_ID, EQUIPMENT_BRAND, EQUIPMENT_MODEL, ENABLE_TIME,DISCARDED_TIME,EQUIPMENT_TYPE,XGBZ,CREATE_TIME,UPDATE_TIME,SJSCSJ) VALUES "
132
+			insertParams := make([]string, 0)
133
+			insertData := make([]interface{}, 0)
134
+			for _, wm := range wms {
135
+				insertParams = append(insertParams, "(?,?,?,?,?,?,?,?,?,?,?)")
136
+				insertData = append(insertData, wm.HospitalId)
137
+				insertData = append(insertData, wm.EquipmentId)
138
+				insertData = append(insertData, wm.EquipmentBrand)
139
+				insertData = append(insertData, wm.EquipmentModel)
140
+				insertData = append(insertData, wm.EnableTime)
141
+				insertData = append(insertData, wm.DiscardedTime)
142
+				insertData = append(insertData, wm.EquipmentType)
143
+				insertData = append(insertData, wm.Xgbz)
144
+				insertData = append(insertData, wm.CreateTime)
145
+				insertData = append(insertData, wm.UpdateTime)
146
+				insertData = append(insertData, wm.Sjscsj)
147
+
148
+			}
149
+			thisSQL += strings.Join(insertParams, ", ")
150
+			err = utx.Exec(thisSQL, insertData...).Error
151
+			if err != nil {
152
+				utx.Rollback()
153
+				return
154
+			}
155
+		}
156
+		utx.Commit()
157
+	}
158
+	return
159
+}
160
+
161
+func BatchCreateStaffRecord(staffs []*sz.TempHdStaff, rdb *gorm.DB) (err error) {
102 162
 	if len(staffs) > 0 {
103
-		utx := writeDb.Begin()
163
+		utx := rdb.Begin()
104 164
 		if len(staffs) > 0 {
105
-			thisSQL := "INSERT INTO temp_hd_staff (hospital_id, staff_id, staff_name, position, permanent_type,create_time,update_time,sjscsj,mj) VALUES "
165
+			thisSQL := "INSERT INTO t_hd_staff (HOSPITAL_ID, STAFF_ID, STAFF_NAME, POSITION, PERMANENT_TYPE,CREATE_TIME,UPDATE_TIME,SJSCSJ,MJ) VALUES "
106 166
 			insertParams := make([]string, 0)
107 167
 			insertData := make([]interface{}, 0)
108 168
 			for _, info := range staffs {
@@ -128,27 +188,241 @@ func BatchCreateStaffRecord(staffs []*sz.TempHdStaff) (err error) {
128 188
 	}
129 189
 	return
130 190
 }
131
-func FindOrgDialysisData(org_id int64, lastUploadTime int64, nowTime int64) (ps []*models.VMSchedule, err error) {
132
-	db := readDb.Model(&models.VMSchedule{}).Where("status = 1 AND user_org_id = ? ", org_id).
133
-		Preload("DeviceNumber", "status = 1").
134
-		Preload("VMDialysisPrescription", "status = 1").
135
-		Preload("AssessmentBeforeDislysis", "status = 1").
136
-		Preload("AssessmentAfterDislysis", "status = 1").
137
-		Preload("DialysisOrder", "status = 1").
138
-		Preload("MonitoringRecord", "status = 1")
139 191
 
140
-	if lastUploadTime != 0 && nowTime != 0 {
141
-		db = db.Where("created_time >= ? AND created_time <= ?", lastUploadTime, nowTime)
192
+func BatchCreatePatinet(patients []*sz.TempHdPatient, rdb *gorm.DB) (err error) {
193
+	if len(patients) > 0 {
194
+		utx := rdb.Begin()
195
+		if len(patients) > 0 {
196
+			thisSQL := "INSERT INTO t_hd_patient (HOSPITAL_ID, PATIENT_NK, CARD_NO, CARD_TYPE, ID_NO,ID_TYPE,PATIENT_NAME,GENDER,BORN_DATE,DIAGNOSIS_SUMMARY,IS_CRF,CREATE_TIME,UPDATE_TIME,SJSCSJ,XGBZ) VALUES "
197
+			insertParams := make([]string, 0)
198
+			insertData := make([]interface{}, 0)
199
+			for _, info := range patients {
200
+				insertParams = append(insertParams, "(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)")
201
+				insertData = append(insertData, info.HospitalId)
202
+				insertData = append(insertData, info.PatientNk)
203
+				insertData = append(insertData, info.CardNo)
204
+				insertData = append(insertData, info.CardType)
205
+				insertData = append(insertData, info.IdNo)
206
+				insertData = append(insertData, info.IdType)
207
+				insertData = append(insertData, info.PatientName)
208
+				insertData = append(insertData, info.Gender)
209
+				insertData = append(insertData, info.BornDate)
210
+				insertData = append(insertData, info.DiagnosisSummary)
211
+				insertData = append(insertData, info.IsCrf)
212
+				insertData = append(insertData, info.CreatedTime)
213
+				insertData = append(insertData, info.UpdateTime)
214
+				insertData = append(insertData, info.Sjscsj)
215
+				insertData = append(insertData, info.Xgbz)
216
+
217
+			}
218
+			thisSQL += strings.Join(insertParams, ", ")
219
+			err = utx.Exec(thisSQL, insertData...).Error
220
+			if err != nil {
221
+				utx.Rollback()
222
+				return
223
+			}
224
+		}
225
+		utx.Commit()
142 226
 	}
143
-	err = db.Find(&ps).Error
144 227
 	return
145 228
 }
146
-func FindOrgDeviceZoneRecordData(org_id int64, lastUploadTime int64, nowTime int64) (zone []*models.DeviceZone, err error) {
147
-	db := readDb.Model(&models.DeviceZone{}).Where("status = 1 AND  org_id = ?", org_id)
148
-	if lastUploadTime != 0 && nowTime != 0 {
149
-		db = db.Where("ctime >= ? AND ctime <= ?", lastUploadTime, nowTime)
229
+
230
+func BatchCreateSchedual(patients []*sz.TempHdShift, rdb *gorm.DB) (err error) {
231
+	if len(patients) > 0 {
232
+		utx := rdb.Begin()
233
+		if len(patients) > 0 {
234
+			thisSQL := "INSERT INTO t_hd_shift (PS_ID, HOSPITAL_ID, PATIENT_NK, SCHEDULE_DATE, SHIFT_TYPE,SICKBED_NO,SCHEDULE_STATUS,CREATE_TIME,SJSCSJ,XGBZ) VALUES "
235
+			insertParams := make([]string, 0)
236
+			insertData := make([]interface{}, 0)
237
+			for _, info := range patients {
238
+				insertParams = append(insertParams, "(?,?,?,?,?,?,?,?,?,?)")
239
+				insertData = append(insertData, info.PsId)
240
+				insertData = append(insertData, info.HospitalId)
241
+				insertData = append(insertData, info.PatientNk)
242
+				insertData = append(insertData, info.ScheduleDate)
243
+				insertData = append(insertData, info.ShiftType)
244
+				insertData = append(insertData, info.SickbedNo)
245
+				insertData = append(insertData, info.ScheduleStatus)
246
+				insertData = append(insertData, info.CreateTime)
247
+				insertData = append(insertData, info.Sjscsj)
248
+				insertData = append(insertData, info.Xgbz)
249
+
250
+			}
251
+			thisSQL += strings.Join(insertParams, ", ")
252
+			err = utx.Exec(thisSQL, insertData...).Error
253
+			if err != nil {
254
+				utx.Rollback()
255
+				return
256
+			}
257
+		}
258
+		utx.Commit()
150 259
 	}
151
-	err = db.Find(&zone).Error
260
+	return
261
+}
262
+
263
+func BatchCreatePs(patients []*sz.TempHdPs, rdb *gorm.DB) (err error) {
264
+	if len(patients) > 0 {
265
+		utx := rdb.Begin()
266
+		if len(patients) > 0 {
267
+			thisSQL := "INSERT INTO t_hd_shift (PRESCRIBE_ID, HOSPITAL_ID, PATIENT_NK, K, CA,NA,DIALYSIS_FREQUENCY,FREQUENCY_UNIT,DIALYSIS_DURATION,HDF,HP,HP_FREQUENCY,HP_FREQUENCY_UNIT,HP_DURATION,HDF_FREQUENCY_UNIT,HDF_FREQUENCY,HDF_DURATION,CREATE_TIME,SJSCSJ,XGBZ) VALUES "
268
+			insertParams := make([]string, 0)
269
+			insertData := make([]interface{}, 0)
270
+			for _, info := range patients {
271
+				insertParams = append(insertParams, "(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)")
272
+				insertData = append(insertData, info.PrescribeId)
273
+				insertData = append(insertData, info.HospitalId)
274
+				insertData = append(insertData, info.PatientNk)
275
+				insertData = append(insertData, info.K)
276
+				insertData = append(insertData, info.Ca)
277
+				insertData = append(insertData, info.Na)
278
+				insertData = append(insertData, info.DialysisFrequency)
279
+				insertData = append(insertData, info.FrequencyUnit)
280
+				insertData = append(insertData, info.DialysisDuration)
281
+				insertData = append(insertData, info.Hdf)
282
+				insertData = append(insertData, info.Hp)
283
+				insertData = append(insertData, info.HpFrequency)
284
+				insertData = append(insertData, info.HpFrequencyUnit)
285
+				insertData = append(insertData, info.HpDuration)
286
+				insertData = append(insertData, info.HdfFrequencyUnit)
287
+				insertData = append(insertData, info.HdfFrequency)
288
+				insertData = append(insertData, info.HdfDuration)
289
+				insertData = append(insertData, info.CreateTime)
290
+				insertData = append(insertData, info.Sjscsj)
291
+				insertData = append(insertData, info.Xgbz)
292
+
293
+			}
294
+			thisSQL += strings.Join(insertParams, ", ")
295
+			err = utx.Exec(thisSQL, insertData...).Error
296
+			if err != nil {
297
+				utx.Rollback()
298
+				return
299
+			}
300
+		}
301
+		utx.Commit()
302
+	}
303
+	return
304
+}
305
+
306
+func BatchCreatePsm(psms []*sz.TempHdPsMedicine, rdb *gorm.DB) (err error) {
307
+	if len(psms) > 0 {
308
+		utx := rdb.Begin()
309
+		if len(psms) > 0 {
310
+			thisSQL := "INSERT INTO t_hd_shift (PRESCRIBE_ID, HOSPITAL_ID, MEDICINE_TYPE_ID,MEDICINE_ID,CREATE_TIME,SJSCSJ,XGBZ) VALUES "
311
+			insertParams := make([]string, 0)
312
+			insertData := make([]interface{}, 0)
313
+			for _, psm := range psms {
314
+				insertParams = append(insertParams, "(?,?,?,?,?,?,?)")
315
+				insertData = append(insertData, psm.PrescribeId)
316
+				insertData = append(insertData, psm.HospitalId)
317
+				insertData = append(insertData, psm.MedicineTypeId)
318
+				insertData = append(insertData, psm.MedicineId)
319
+				insertData = append(insertData, psm.CreatedTime)
320
+				insertData = append(insertData, psm.Sjscsj)
321
+				insertData = append(insertData, psm.Xgbz)
322
+
323
+			}
324
+			thisSQL += strings.Join(insertParams, ", ")
325
+			err = utx.Exec(thisSQL, insertData...).Error
326
+			if err != nil {
327
+				utx.Rollback()
328
+				return
329
+			}
330
+		}
331
+		utx.Commit()
332
+	}
333
+	return
334
+}
335
+
336
+func BatchCreatePatientOut(patientOuts []*sz.TempHdPatientOut, rdb *gorm.DB) (err error) {
337
+	if len(patientOuts) > 0 {
338
+		utx := rdb.Begin()
339
+		if len(patientOuts) > 0 {
340
+			thisSQL := "INSERT INTO t_hd_patient_out (HOSPITAL_ID, PATIENT_NK,SEQUELAE_DATE,SEQUELAE_TYPE,CREATE_TIME,SJSCSJ,XGBZ) VALUES "
341
+			insertParams := make([]string, 0)
342
+			insertData := make([]interface{}, 0)
343
+			for _, out := range patientOuts {
344
+				insertParams = append(insertParams, "(?,?,?,?,?,?,?)")
345
+				insertData = append(insertData, out.HospitalId)
346
+				insertData = append(insertData, out.PatientNk)
347
+				insertData = append(insertData, out.SequelaeDate)
348
+				insertData = append(insertData, out.SequelaeType)
349
+				insertData = append(insertData, out.CreateTime)
350
+				insertData = append(insertData, out.Sjscsj)
351
+				insertData = append(insertData, out.Xgbz)
352
+
353
+			}
354
+			thisSQL += strings.Join(insertParams, ", ")
355
+			err = utx.Exec(thisSQL, insertData...).Error
356
+			if err != nil {
357
+				utx.Rollback()
358
+				return
359
+			}
360
+		}
361
+		utx.Commit()
362
+	}
363
+	return
364
+}
365
+
366
+func BatchCreateDoctorsAdvice(advices []*sz.TempHdDoctorsAdvice, rdb *gorm.DB) (err error) {
367
+	if len(advices) > 0 {
368
+		utx := rdb.Begin()
369
+		if len(advices) > 0 {
370
+			thisSQL := "INSERT INTO t_hd_doctors_advice (MEDICAL_ORDER_ID, HOSPITAL_ID,DIALYSIS_ID,ORDER_TYPE,PATIENT_NK,DIALYSIS_DURATION,BLOOD_VOL,CREATE_TIME,SJSCSJ,XGBZ) VALUES "
371
+			insertParams := make([]string, 0)
372
+			insertData := make([]interface{}, 0)
373
+			for _, advice := range advices {
374
+				insertParams = append(insertParams, "(?,?,?,?,?,?,?,?,?,?)")
375
+				insertData = append(insertData, advice.MedicalOrDerId)
376
+				insertData = append(insertData, advice.HospitalId)
377
+				insertData = append(insertData, advice.DialysisId)
378
+				insertData = append(insertData, advice.OrderType)
379
+				insertData = append(insertData, advice.PatientNk)
380
+				insertData = append(insertData, advice.DialysisDuration)
381
+				insertData = append(insertData, advice.BloodVol)
382
+				insertData = append(insertData, advice.CreateTime)
383
+				insertData = append(insertData, advice.Sjscsj)
384
+				insertData = append(insertData, advice.Xgbz)
385
+
386
+			}
387
+			thisSQL += strings.Join(insertParams, ", ")
388
+			err = utx.Exec(thisSQL, insertData...).Error
389
+			if err != nil {
390
+				utx.Rollback()
391
+				return
392
+			}
393
+		}
394
+		utx.Commit()
395
+	}
396
+	return
397
+}
152 398
 
399
+func BatchCreateMonitor(advices []*sz.TempHdMiddle, rdb *gorm.DB) (err error) {
400
+	if len(advices) > 0 {
401
+		utx := rdb.Begin()
402
+		if len(advices) > 0 {
403
+			thisSQL := "INSERT INTO t_hd_doctors_advice (HOSPITAL_ID, PATIENT_NK,DIALYSIS_ID,MONITOR_TIME,SBP,DBP,CREATE_TIME,SJSCSJ,XGBZ) VALUES "
404
+			insertParams := make([]string, 0)
405
+			insertData := make([]interface{}, 0)
406
+			for _, advice := range advices {
407
+				insertParams = append(insertParams, "(?,?,?,?,?,?,?,?,?,?)")
408
+				insertData = append(insertData, advice.HospitalId)
409
+				insertData = append(insertData, advice.PatientNk)
410
+				insertData = append(insertData, advice.DialysisId)
411
+				insertData = append(insertData, advice.MonitorTime)
412
+				insertData = append(insertData, advice.Sbp)
413
+				insertData = append(insertData, advice.Dbp)
414
+				insertData = append(insertData, advice.CreateTime)
415
+				insertData = append(insertData, advice.Sjscsj)
416
+				insertData = append(insertData, advice.Xgbz)
417
+			}
418
+			thisSQL += strings.Join(insertParams, ", ")
419
+			err = utx.Exec(thisSQL, insertData...).Error
420
+			if err != nil {
421
+				utx.Rollback()
422
+				return
423
+			}
424
+		}
425
+		utx.Commit()
426
+	}
153 427
 	return
154 428
 }