Selaa lähdekoodia

Merge branch 'master' of http://git.shengws.com/csx/XT_New

XMLWAN 4 vuotta sitten
vanhempi
commit
7545b85c18

+ 50 - 50
controllers/device_api_controller.go Näytä tiedosto

@@ -652,21 +652,21 @@ func (this *DeviceAPIController) CreateGroup() {
652 652
 	}
653 653
 
654 654
 	adminInfo := this.GetAdminUserInfo()
655
-  _, errcode := service.GetDeviceGroupName(name, adminInfo.CurrentOrgId)
656
-  if errcode == gorm.ErrRecordNotFound{
657
-    group, createErr := service.CreateDeviceGroup(adminInfo.CurrentOrgId, name)
658
-    if createErr != nil {
659
-      this.ErrorLog("创建设备分组失败:%v", createErr)
660
-      this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDBCreate)
661
-      return
662
-    }
663
-    this.ServeSuccessJSON(map[string]interface{}{
664
-      "group": group,
665
-    })
666
-  }else if errcode == nil{
667
-    this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDBCreate)
668
-    return
669
-  }
655
+	_, errcode := service.GetDeviceGroupName(name, adminInfo.CurrentOrgId)
656
+	if errcode == gorm.ErrRecordNotFound {
657
+		group, createErr := service.CreateDeviceGroup(adminInfo.CurrentOrgId, name)
658
+		if createErr != nil {
659
+			this.ErrorLog("创建设备分组失败:%v", createErr)
660
+			this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDBCreate)
661
+			return
662
+		}
663
+		this.ServeSuccessJSON(map[string]interface{}{
664
+			"group": group,
665
+		})
666
+	} else if errcode == nil {
667
+		this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDBCreate)
668
+		return
669
+	}
670 670
 
671 671
 }
672 672
 
@@ -694,12 +694,12 @@ func (this *DeviceAPIController) ModifyGroup() {
694 694
 
695 695
 	group.Name = name
696 696
 	group.ModifyTime = time.Now().Unix()
697
-  byName, getGroupErr := service.GetUpdateDeviceGroupByName(name, adminInfo.CurrentOrgId)
698
-  if byName.ID > 0 && byName.ID != id {
699
-    this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
700
-    return
701
-  }
702
-  updateErr := service.UpdateDeviceGroup(group)
697
+	byName, getGroupErr := service.GetUpdateDeviceGroupByName(name, adminInfo.CurrentOrgId)
698
+	if byName.ID > 0 && byName.ID != id {
699
+		this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
700
+		return
701
+	}
702
+	updateErr := service.UpdateDeviceGroup(group)
703 703
 	if updateErr != nil {
704 704
 		this.ErrorLog("修改设备分组失败:%v", updateErr)
705 705
 		this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDBUpdate)
@@ -798,29 +798,29 @@ func (this *DeviceAPIController) CreateNumber() {
798 798
 		return
799 799
 	}
800 800
 
801
-  _, errcode := service.GetCreateDeviceNumber(num, adminInfo.CurrentOrgId)
802
-  if errcode == gorm.ErrRecordNotFound{
803
-    number, createErr := service.CreateDeviceNumber(adminInfo.CurrentOrgId, num, zoneID, groupID)
804
-    if createErr != nil {
805
-      this.ErrorLog("创建机号失败:%v", createErr)
806
-      this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDBCreate)
807
-      return
808
-    }
809
-    numberJson := map[string]interface{}{
810
-      "id":         number.ID,
811
-      "number":     number.Number,
812
-      "zone_id":    number.ZoneID,
813
-      "group_id":   number.GroupID,
814
-      "zone_name":  zone.Name,
815
-      "group_name": group.Name,
816
-    }
817
-    this.ServeSuccessJSON(map[string]interface{}{
818
-      "number": numberJson,
819
-    })
820
-  }else if errcode == nil{
821
-    this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDBCreate)
822
-    return
823
-  }
801
+	_, errcode := service.GetCreateDeviceNumber(num, adminInfo.CurrentOrgId)
802
+	if errcode == gorm.ErrRecordNotFound {
803
+		number, createErr := service.CreateDeviceNumber(adminInfo.CurrentOrgId, num, zoneID, groupID)
804
+		if createErr != nil {
805
+			this.ErrorLog("创建机号失败:%v", createErr)
806
+			this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDBCreate)
807
+			return
808
+		}
809
+		numberJson := map[string]interface{}{
810
+			"id":         number.ID,
811
+			"number":     number.Number,
812
+			"zone_id":    number.ZoneID,
813
+			"group_id":   number.GroupID,
814
+			"zone_name":  zone.Name,
815
+			"group_name": group.Name,
816
+		}
817
+		this.ServeSuccessJSON(map[string]interface{}{
818
+			"number": numberJson,
819
+		})
820
+	} else if errcode == nil {
821
+		this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDBCreate)
822
+		return
823
+	}
824 824
 
825 825
 }
826 826
 
@@ -874,12 +874,12 @@ func (this *DeviceAPIController) ModifyNumber() {
874 874
 	number.Number = num
875 875
 	number.ZoneID = zoneID
876 876
 	number.GroupID = groupID
877
-  byName, _ := service.GetDeviceNumberByName(num, adminInfo.CurrentOrgId)
878
-  if byName.ID > 0 && byName.ID != id {
879
-    this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
880
-    return
881
-  }
882
-  updateErr := service.UpdateDeviceNumber(number)
877
+	byName, _ := service.GetDeviceNumberByName(num, adminInfo.CurrentOrgId)
878
+	if byName.ID > 0 && byName.ID != id {
879
+		this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
880
+		return
881
+	}
882
+	updateErr := service.UpdateDeviceNumber(number)
883 883
 	if updateErr != nil {
884 884
 		this.ErrorLog("修改机号失败:%v", updateErr)
885 885
 		this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDBUpdate)

+ 15 - 0
controllers/gobal_config_api_controller.go Näytä tiedosto

@@ -57,6 +57,8 @@ func GobalConfigRegistRouters() {
57 57
 	beego.Router("/api/public/orgs", &GobalConfigApiController{}, "get:GetOrgs")
58 58
 	beego.Router("/api/org/change", &GobalConfigApiController{}, "post:ChangeOrg")
59 59
 
60
+	beego.Router("/api/log/generate", &GobalConfigApiController{}, "get:GenerateLog")
61
+
60 62
 }
61 63
 
62 64
 //provinces, _ := service.GetDistrictsByUpid(0)21
@@ -1170,3 +1172,16 @@ func RemoveRepeatedOrgElement(orgs []*models.Org) (newOrgs []*models.Org) {
1170 1172
 	}
1171 1173
 	return
1172 1174
 }
1175
+
1176
+func (this *GobalConfigApiController) GenerateLog() {
1177
+	log_type, _ := this.GetInt64("log_type", 0)
1178
+	logs, err := service.GetExportLogByType(this.GetAdminUserInfo().CurrentOrgId, log_type)
1179
+	if err != nil {
1180
+		this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
1181
+		return
1182
+	}
1183
+	this.ServeSuccessJSON(map[string]interface{}{
1184
+		"logs": logs,
1185
+	})
1186
+
1187
+}

+ 1 - 0
controllers/mobile_api_controllers/mobile_api_base_controller.go Näytä tiedosto

@@ -16,6 +16,7 @@ type MobileBaseAPIController struct {
16 16
 
17 17
 func (this *MobileBaseAPIController) Prepare() {
18 18
 	this.BaseAPIController.Prepare()
19
+
19 20
 	// beego.Trace("============================================================")
20 21
 	// beego.Trace("session ID: %v", this.Ctx.Input.Cookie("beegosessionID"))
21 22
 	// beego.Trace("session : %v", this.GetSession("info"))

+ 410 - 79
controllers/patient_api_controller.go Näytä tiedosto

@@ -6,7 +6,9 @@ import (
6 6
 	"XT_New/service"
7 7
 	"XT_New/utils"
8 8
 	"encoding/json"
9
+	"log"
9 10
 	"reflect"
11
+	"regexp"
10 12
 	"strconv"
11 13
 	"strings"
12 14
 	"time"
@@ -63,6 +65,9 @@ func PatientApiRegistRouters() {
63 65
 
64 66
 	beego.Router("/api/remind/is_open", &PatientApiController{}, "Post:PostIsOpenRemind")
65 67
 	beego.Router("/api/patients/advices/getpatientschedules", &PatientApiController{}, "Get:GetPatientScheduleOne")
68
+
69
+	beego.Router("/api/patients/export", &PatientApiController{}, "Post:ExportPatients")
70
+
66 71
 	beego.Router("/api/patients/advices/saveditadvices", &PatientApiController{}, "Get:SaveEditAdvices")
67 72
 }
68 73
 
@@ -244,29 +249,29 @@ func (c *PatientApiController) CreatePatient() {
244 249
 	//获取老表的最后一条数据
245 250
 	patients, err := service.GetLastPatientData(adminUserInfo.CurrentOrgId)
246 251
 	patientsNew := models.XtPatientsNew{
247
-		UserOrgId:                    adminUserInfo.CurrentOrgId,
248
-		UserId:                       0,
249
-		Avatar:                       patients.Avatar,
250
-		PatientType:                  patients.PatientType,
251
-		DialysisNo:                   patients.DialysisNo,
252
-		AdmissionNumber:              patients.AdmissionNumber,
253
-		Source:                       patients.Source,
254
-		Lapseto:                      patients.Lapseto,
255
-		PartitionId:                  patients.PartitionId,
256
-		BedId:                        patients.BedId,
257
-		Name:                         patients.Name,
258
-		Alias:                        patients.Alias,
259
-		Gender:                       patients.Gender,
260
-		MaritalStatus:                patients.MaritalStatus,
261
-		IdCardNo:                     patients.IdCardNo,
262
-		Birthday:                     patients.Birthday,
263
-		ReimbursementWayId:           patients.ReimbursementWayId,
264
-		HealthCareType:               patients.HealthCareType,
265
-		HealthCareNo:                 patients.HealthCareNo,
266
-		HealthCareDueDate:            patients.HealthCareDueDate,
267
-		Height:                       patients.Height,
268
-		BloodType:                    patients.BloodType,
269
-		Rh:                           patients.Rh,
252
+		UserOrgId:          adminUserInfo.CurrentOrgId,
253
+		UserId:             0,
254
+		Avatar:             patients.Avatar,
255
+		PatientType:        patients.PatientType,
256
+		DialysisNo:         patients.DialysisNo,
257
+		AdmissionNumber:    patients.AdmissionNumber,
258
+		Source:             patients.Source,
259
+		Lapseto:            patients.Lapseto,
260
+		PartitionId:        patients.PartitionId,
261
+		BedId:              patients.BedId,
262
+		Name:               patients.Name,
263
+		Alias:              patients.Alias,
264
+		Gender:             patients.Gender,
265
+		MaritalStatus:      patients.MaritalStatus,
266
+		IdCardNo:           patients.IdCardNo,
267
+		Birthday:           patients.Birthday,
268
+		ReimbursementWayId: patients.ReimbursementWayId,
269
+		HealthCareType:     patients.HealthCareType,
270
+		HealthCareNo:       patients.HealthCareNo,
271
+		HealthCareDueDate:  patients.HealthCareDueDate,
272
+		Height:             patients.Height,
273
+		BloodType:          patients.BloodType,
274
+		Rh:                 patients.Rh,
270 275
 		HealthCareDueAlertDate:       patients.HealthCareDueAlertDate,
271 276
 		EducationLevel:               patients.EducationLevel,
272 277
 		Profession:                   patients.Profession,
@@ -312,28 +317,28 @@ func (c *PatientApiController) CreatePatient() {
312 317
 		Nation:                       patients.Nation,
313 318
 		NativePlace:                  patients.NativePlace,
314 319
 		Age:                          patients.Age,
315
-		InfectiousNextRecordTime:     patients.InfectiousNextRecordTime,
316
-		IsInfectious:                 patients.IsInfectious,
317
-		RemindCycle:                  patients.RemindCycle,
318
-		ResponseResult:               patients.ResponseResult,
319
-		IsOpenRemind:                 patients.IsOpenRemind,
320
-		FirstTreatmentDate:           patients.FirstTreatmentDate,
321
-		DialysisAge:                  patients.DialysisAge,
322
-		ExpenseKind:                  patients.ExpenseKind,
323
-		TellPhone:                    patients.TellPhone,
324
-		ContactName:                  patients.ContactName,
325
-		BloodPatients:                1,
326
-		SlowPatients:                 0,
327
-		MemberPatients:               0,
328
-		EcommerPatients:              "",
329
-		BloodId:                      patients.ID,
330
-		SlowId:                       0,
331
-		MemberId:                     0,
332
-		MemberFistdate:               0,
333
-		MemberPatienttype:            0,
334
-		MemberTreatement:             0,
335
-		EquitmentId:                  "",
336
-		UserSysBeforeCount:           patient.UserSysBeforeCount,
320
+		InfectiousNextRecordTime: patients.InfectiousNextRecordTime,
321
+		IsInfectious:             patients.IsInfectious,
322
+		RemindCycle:              patients.RemindCycle,
323
+		ResponseResult:           patients.ResponseResult,
324
+		IsOpenRemind:             patients.IsOpenRemind,
325
+		FirstTreatmentDate:       patients.FirstTreatmentDate,
326
+		DialysisAge:              patients.DialysisAge,
327
+		ExpenseKind:              patients.ExpenseKind,
328
+		TellPhone:                patients.TellPhone,
329
+		ContactName:              patients.ContactName,
330
+		BloodPatients:            1,
331
+		SlowPatients:             0,
332
+		MemberPatients:           0,
333
+		EcommerPatients:          "",
334
+		BloodId:                  patients.ID,
335
+		SlowId:                   0,
336
+		MemberId:                 0,
337
+		MemberFistdate:           0,
338
+		MemberPatienttype:        0,
339
+		MemberTreatement:         0,
340
+		EquitmentId:              "",
341
+		UserSysBeforeCount:       patient.UserSysBeforeCount,
337 342
 	}
338 343
 
339 344
 	err = service.CreatePatientsNew(&patientsNew)
@@ -461,29 +466,29 @@ func (c *PatientApiController) EditPatient() {
461 466
 	}
462 467
 	fmt.Println("病人--------------------------------------------------------------", patient.Name, patient.Age)
463 468
 	patientsNew := models.XtPatientsNew{
464
-		UserOrgId:                 patient.UserOrgId,
465
-		UserId:                    patient.UserId,
466
-		Avatar:                    patient.Avatar,
467
-		PatientType:               patient.PatientType,
468
-		DialysisNo:                patient.DialysisNo,
469
-		AdmissionNumber:           patient.AdmissionNumber,
470
-		Source:                    patient.Source,
471
-		Lapseto:                   patient.Lapseto,
472
-		PartitionId:               patient.PartitionId,
473
-		BedId:                     patient.BedId,
474
-		Name:                      patient.Name,
475
-		Alias:                     patient.Alias,
476
-		Gender:                    patient.Gender,
477
-		MaritalStatus:             patient.MaritalStatus,
478
-		IdCardNo:                  patient.IdCardNo,
479
-		Birthday:                  patient.Birthday,
480
-		ReimbursementWayId:        patient.ReimbursementWayId,
481
-		HealthCareType:            patient.HealthCareType,
482
-		HealthCareNo:              patient.HealthCareNo,
483
-		HealthCareDueDate:         patient.HealthCareDueDate,
484
-		Height:                    patient.Height,
485
-		BloodType:                 patient.BloodType,
486
-		Rh:                        patient.Rh,
469
+		UserOrgId:          patient.UserOrgId,
470
+		UserId:             patient.UserId,
471
+		Avatar:             patient.Avatar,
472
+		PatientType:        patient.PatientType,
473
+		DialysisNo:         patient.DialysisNo,
474
+		AdmissionNumber:    patient.AdmissionNumber,
475
+		Source:             patient.Source,
476
+		Lapseto:            patient.Lapseto,
477
+		PartitionId:        patient.PartitionId,
478
+		BedId:              patient.BedId,
479
+		Name:               patient.Name,
480
+		Alias:              patient.Alias,
481
+		Gender:             patient.Gender,
482
+		MaritalStatus:      patient.MaritalStatus,
483
+		IdCardNo:           patient.IdCardNo,
484
+		Birthday:           patient.Birthday,
485
+		ReimbursementWayId: patient.ReimbursementWayId,
486
+		HealthCareType:     patient.HealthCareType,
487
+		HealthCareNo:       patient.HealthCareNo,
488
+		HealthCareDueDate:  patient.HealthCareDueDate,
489
+		Height:             patient.Height,
490
+		BloodType:          patient.BloodType,
491
+		Rh:                 patient.Rh,
487 492
 		HealthCareDueAlertDate:    patient.HealthCareDueAlertDate,
488 493
 		EducationLevel:            patient.EducationLevel,
489 494
 		Profession:                patient.Profession,
@@ -525,17 +530,17 @@ func (c *PatientApiController) EditPatient() {
525 530
 		Nation:                    patient.Nation,
526 531
 		NativePlace:               patient.NativePlace,
527 532
 		Age:                       patient.Age,
528
-		InfectiousNextRecordTime:  patient.InfectiousNextRecordTime,
529
-		IsInfectious:              patient.IsInfectious,
530
-		RemindCycle:               patient.RemindCycle,
531
-		ResponseResult:            patient.ResponseResult,
532
-		IsOpenRemind:              patient.IsOpenRemind,
533
-		FirstTreatmentDate:        patient.FirstTreatmentDate,
534
-		DialysisAge:               patient.DialysisAge,
535
-		ExpenseKind:               patient.ExpenseKind,
536
-		TellPhone:                 patient.TellPhone,
537
-		ContactName:               patient.ContactName,
538
-		UpdatedTime:               time.Now().Unix(),
533
+		InfectiousNextRecordTime: patient.InfectiousNextRecordTime,
534
+		IsInfectious:             patient.IsInfectious,
535
+		RemindCycle:              patient.RemindCycle,
536
+		ResponseResult:           patient.ResponseResult,
537
+		IsOpenRemind:             patient.IsOpenRemind,
538
+		FirstTreatmentDate:       patient.FirstTreatmentDate,
539
+		DialysisAge:              patient.DialysisAge,
540
+		ExpenseKind:              patient.ExpenseKind,
541
+		TellPhone:                patient.TellPhone,
542
+		ContactName:              patient.ContactName,
543
+		UpdatedTime:              time.Now().Unix(),
539 544
 	}
540 545
 	//	//更新病人ID获取新表病人ID
541 546
 	err = service.UpdatepatientTwo(&patientsNew, id)
@@ -3376,6 +3381,332 @@ func (c *PatientApiController) GetPatientScheduleOne() {
3376 3381
 	})
3377 3382
 }
3378 3383
 
3384
+func (c *PatientApiController) ExportPatients() {
3385
+	dataBody := make(map[string]interface{}, 0)
3386
+	err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
3387
+	if err != nil {
3388
+		utils.ErrorLog(err.Error())
3389
+		return
3390
+	}
3391
+	utils.ErrorLog("%v", dataBody)
3392
+	export_time := time.Now().Unix()
3393
+	var patients []*models.Patients
3394
+	var total_patients []interface{}
3395
+
3396
+	if dataBody["patients"] != nil || reflect.TypeOf(dataBody["patients"]).String() == "[]interface {}" {
3397
+		tempPatients := dataBody["patients"].([]interface{})
3398
+		total_patients = tempPatients
3399
+		for index, patientMap := range tempPatients {
3400
+			patientNameM := patientMap.(map[string]interface{})
3401
+			var patient models.Patients
3402
+
3403
+			if patientNameM["name"] == nil || reflect.TypeOf(patientNameM["name"]).String() != "string" {
3404
+				utils.ErrorLog("name")
3405
+				return
3406
+			}
3407
+			name, _ := patientNameM["name"].(string)
3408
+			if len(name) == 0 { //名字为空则生成一条导入错误日志
3409
+				err_log := models.ExportErrLog{
3410
+					LogType:    1,
3411
+					UserOrgId:  c.GetAdminUserInfo().CurrentOrgId,
3412
+					ErrMsg:     "第" + strconv.Itoa(index+2) + "行" + "的姓名不能为空",
3413
+					Status:     1,
3414
+					CreateTime: time.Now().Unix(),
3415
+					UpdateTime: time.Now().Unix(),
3416
+					ExportTime: export_time,
3417
+				}
3418
+				service.CreateExportErrLog(&err_log)
3419
+				continue
3420
+			}
3421
+			patient.Name = name
3422
+
3423
+			if patientNameM["gender"] != nil || reflect.TypeOf(patientNameM["gender"]).String() == "string" {
3424
+				gender, _ := strconv.ParseInt(patientNameM["gender"].(string), 10, 64)
3425
+				if gender == 0 { //性别不符合要求则生成一条导入错误日志
3426
+					err_log := models.ExportErrLog{
3427
+						LogType:    1,
3428
+						UserOrgId:  c.GetAdminUserInfo().CurrentOrgId,
3429
+						ErrMsg:     "第" + strconv.Itoa(index+2) + "行" + "的性别不符合要求",
3430
+						Status:     1,
3431
+						CreateTime: time.Now().Unix(),
3432
+						UpdateTime: time.Now().Unix(),
3433
+						ExportTime: export_time,
3434
+					}
3435
+					service.CreateExportErrLog(&err_log)
3436
+					continue
3437
+				} else {
3438
+					patient.Gender = gender
3439
+				}
3440
+			}
3441
+
3442
+			if patientNameM["phone"] != nil || reflect.TypeOf(patientNameM["phone"]).String() == "string" {
3443
+				phone, _ := patientNameM["phone"].(string)
3444
+				if VerifyMobileFormat(phone) == false { //手机号码不符合要求则生成一条导入错误日志
3445
+					err_log := models.ExportErrLog{
3446
+						LogType:    1,
3447
+						UserOrgId:  c.GetAdminUserInfo().CurrentOrgId,
3448
+						ErrMsg:     "第" + strconv.Itoa(index+2) + "行" + "的手机号码格式不符合要求",
3449
+						Status:     1,
3450
+						CreateTime: time.Now().Unix(),
3451
+						UpdateTime: time.Now().Unix(),
3452
+						ExportTime: export_time,
3453
+					}
3454
+					service.CreateExportErrLog(&err_log)
3455
+					continue
3456
+				} else {
3457
+					//需要判断该号码是否已经在系统内存在了,存在了则生成一条导入错误日志
3458
+					count := service.FindPatientPhoneIsExist(phone, c.GetAdminUserInfo().CurrentOrgId)
3459
+					if count > 0 {
3460
+						err_log := models.ExportErrLog{
3461
+							LogType:    1,
3462
+							UserOrgId:  c.GetAdminUserInfo().CurrentOrgId,
3463
+							ErrMsg:     "第" + strconv.Itoa(index+2) + "行" + "的手机号码在系统中已经存在",
3464
+							Status:     1,
3465
+							CreateTime: time.Now().Unix(),
3466
+							UpdateTime: time.Now().Unix(),
3467
+							ExportTime: export_time,
3468
+						}
3469
+						service.CreateExportErrLog(&err_log)
3470
+						continue
3471
+					}
3472
+					patient.Phone = phone
3473
+				}
3474
+			}
3475
+
3476
+			if patientNameM["id_card_no"] != nil || reflect.TypeOf(patientNameM["id_card_no"]).String() == "string" {
3477
+				id_card_no, _ := patientNameM["id_card_no"].(string)
3478
+				fmt.Println(id_card_no)
3479
+
3480
+				if IsIdCard(id_card_no) == false { //身份证号码不符合要求则生成一条导入错误日志
3481
+					err_log := models.ExportErrLog{
3482
+						LogType:    1,
3483
+						UserOrgId:  c.GetAdminUserInfo().CurrentOrgId,
3484
+						ErrMsg:     "第" + strconv.Itoa(index+2) + "行" + "的身份证号码格式不符合要求",
3485
+						Status:     1,
3486
+						CreateTime: time.Now().Unix(),
3487
+						UpdateTime: time.Now().Unix(),
3488
+						ExportTime: export_time,
3489
+					}
3490
+					service.CreateExportErrLog(&err_log)
3491
+					continue
3492
+				} else {
3493
+					count := service.FindPatientIdCardNoIsExist(id_card_no, c.GetAdminUserInfo().CurrentOrgId)
3494
+					if count > 0 {
3495
+						err_log := models.ExportErrLog{
3496
+							LogType:    1,
3497
+							UserOrgId:  c.GetAdminUserInfo().CurrentOrgId,
3498
+							ErrMsg:     "第" + strconv.Itoa(index+2) + "行" + "的身份证号码在系统中已经存在",
3499
+							Status:     1,
3500
+							CreateTime: time.Now().Unix(),
3501
+							UpdateTime: time.Now().Unix(),
3502
+							ExportTime: export_time,
3503
+						}
3504
+						service.CreateExportErrLog(&err_log)
3505
+						continue
3506
+					}
3507
+					patient.IdCardNo = id_card_no
3508
+					patient.Birthday = GetBirthDay(id_card_no).Unix()
3509
+				}
3510
+			}
3511
+
3512
+			if patientNameM["first_treatment_date"] != nil || reflect.TypeOf(patientNameM["first_treatment_date"]).String() == "string" {
3513
+				first_treatment_date, _ := patientNameM["first_treatment_date"].(string)
3514
+				timeLayout := "2006/01/02"
3515
+				loc, _ := time.LoadLocation("Local")
3516
+				first_dialysis_date, err := time.ParseInLocation(timeLayout, first_treatment_date, loc)
3517
+
3518
+				if err != nil { //首次肾脏治疗时间不符合要求则生成一条导入错误日志
3519
+					err_log := models.ExportErrLog{
3520
+						LogType:    1,
3521
+						UserOrgId:  c.GetAdminUserInfo().CurrentOrgId,
3522
+						ErrMsg:     "第" + strconv.Itoa(index+2) + "行" + "的首次肾脏治疗时间格式不符合要求",
3523
+						Status:     1,
3524
+						CreateTime: time.Now().Unix(),
3525
+						UpdateTime: time.Now().Unix(),
3526
+						ExportTime: export_time,
3527
+					}
3528
+					service.CreateExportErrLog(&err_log)
3529
+					continue
3530
+
3531
+				} else {
3532
+					if first_dialysis_date.Unix() == 0 { //首次肾脏治疗时间不符合要求则生成一条导入错误日志
3533
+						err_log := models.ExportErrLog{
3534
+							LogType:    1,
3535
+							UserOrgId:  c.GetAdminUserInfo().CurrentOrgId,
3536
+							ErrMsg:     "第" + strconv.Itoa(index+2) + "行" + "的首次肾脏治疗时间格式不符合要求",
3537
+							Status:     1,
3538
+							CreateTime: time.Now().Unix(),
3539
+							UpdateTime: time.Now().Unix(),
3540
+							ExportTime: export_time,
3541
+						}
3542
+						service.CreateExportErrLog(&err_log)
3543
+						continue
3544
+					} else {
3545
+						patient.FirstDialysisDate = first_dialysis_date.Unix()
3546
+					}
3547
+				}
3548
+			}
3549
+
3550
+			if patientNameM["source"] != nil || reflect.TypeOf(patientNameM["source"]).String() == "string" {
3551
+				source, _ := strconv.ParseInt(patientNameM["source"].(string), 10, 64)
3552
+				if source == 0 { //患者来源不符合要求则生成一条导入错误日志
3553
+					err_log := models.ExportErrLog{
3554
+						LogType:    1,
3555
+						UserOrgId:  c.GetAdminUserInfo().CurrentOrgId,
3556
+						ErrMsg:     "第" + strconv.Itoa(index+2) + "行" + "的患者来源不符合要求",
3557
+						Status:     1,
3558
+						CreateTime: time.Now().Unix(),
3559
+						UpdateTime: time.Now().Unix(),
3560
+						ExportTime: export_time,
3561
+					}
3562
+					service.CreateExportErrLog(&err_log)
3563
+					continue
3564
+				} else {
3565
+					patient.Source = source
3566
+				}
3567
+			}
3568
+
3569
+			if patientNameM["lapseto"] != nil || reflect.TypeOf(patientNameM["lapseto"]).String() == "string" {
3570
+				lapseto, _ := strconv.ParseInt(patientNameM["lapseto"].(string), 10, 64)
3571
+				if lapseto == 0 { //治疗状态不符合要求则生成一条导入错误日志
3572
+					err_log := models.ExportErrLog{
3573
+						LogType:    1,
3574
+						UserOrgId:  c.GetAdminUserInfo().CurrentOrgId,
3575
+						ErrMsg:     "第" + strconv.Itoa(index+2) + "行" + "的治疗状态不符合要求",
3576
+						Status:     1,
3577
+						CreateTime: time.Now().Unix(),
3578
+						UpdateTime: time.Now().Unix(),
3579
+						ExportTime: export_time,
3580
+					}
3581
+					service.CreateExportErrLog(&err_log)
3582
+					continue
3583
+				} else {
3584
+					patient.Lapseto = lapseto
3585
+				}
3586
+			}
3587
+
3588
+			if patientNameM["is_infectious"] != nil || reflect.TypeOf(patientNameM["is_infectious"]).String() == "string" {
3589
+				is_infectious, _ := strconv.ParseInt(patientNameM["is_infectious"].(string), 10, 64)
3590
+				if is_infectious == 0 { //传染病不符合要求则生成一条导入错误日志
3591
+					err_log := models.ExportErrLog{
3592
+						LogType:    1,
3593
+						UserOrgId:  c.GetAdminUserInfo().CurrentOrgId,
3594
+						ErrMsg:     "第" + strconv.Itoa(index+2) + "行" + "的传染病状态不符合要求",
3595
+						Status:     1,
3596
+						CreateTime: time.Now().Unix(),
3597
+						UpdateTime: time.Now().Unix(),
3598
+						ExportTime: export_time,
3599
+					}
3600
+					service.CreateExportErrLog(&err_log)
3601
+					continue
3602
+				} else {
3603
+					patient.IsInfectious = is_infectious
3604
+				}
3605
+			}
3606
+
3607
+			if patientNameM["contagions"] != nil && reflect.TypeOf(patientNameM["contagions"]).String() == "[]interface {}" {
3608
+				var contagions []int64
3609
+				thisContagions, _ := patientNameM["contagions"].([]interface{})
3610
+				if len(thisContagions) > 0 {
3611
+					for _, item := range thisContagions {
3612
+						if reflect.TypeOf(item).String() != "float64" {
3613
+							continue
3614
+						}
3615
+						contagion := int64(item.(float64))
3616
+						if contagion > 0 {
3617
+							contagions = append(contagions, contagion)
3618
+						}
3619
+					}
3620
+				}
3621
+				patient.ContagionIds = contagions
3622
+			}
3623
+
3624
+			if patientNameM["diagnose"] != nil || reflect.TypeOf(patientNameM["diagnose"]).String() == "string" {
3625
+				diagnose, _ := patientNameM["diagnose"].(string)
3626
+				patient.Diagnose = diagnose
3627
+
3628
+			}
3629
+			patient.CreatedTime = time.Now().Unix()
3630
+			patient.UpdatedTime = time.Now().Unix()
3631
+			patient.Status = 1
3632
+			patient.UserOrgId = c.GetAdminUserInfo().CurrentOrgId
3633
+			patient.IsExcelExport = 1
3634
+			patient.PatientType = 1
3635
+			patients = append(patients, &patient)
3636
+		}
3637
+	}
3638
+	errLogs, _ := service.FindPatientExportLog(c.GetAdminUserInfo().CurrentOrgId, export_time)
3639
+
3640
+	if len(patients) > 0 {
3641
+		for _, item := range patients {
3642
+			service.CreateExportPatient(item, item.ContagionIds)
3643
+		}
3644
+
3645
+		log := models.ExportLog{
3646
+			LogType:    1,
3647
+			UserOrgId:  c.GetAdminUserInfo().CurrentOrgId,
3648
+			TotalNum:   int64(len(total_patients)),
3649
+			FailNum:    int64(len(errLogs)),
3650
+			SuccessNum: int64(len(patients)),
3651
+			CreateTime: time.Now().Unix(),
3652
+			UpdateTime: time.Now().Unix(),
3653
+			ExportTime: export_time,
3654
+			Status:     1,
3655
+		}
3656
+		service.CreateExportLog(&log)
3657
+
3658
+		c.ServeSuccessJSON(map[string]interface{}{
3659
+			"msg":         "导入成功",
3660
+			"total_num":   len(total_patients),
3661
+			"success_num": len(patients),
3662
+			"fail_num":    int64(len(errLogs)),
3663
+		})
3664
+	} else {
3665
+		log := models.ExportLog{
3666
+			LogType:    1,
3667
+			UserOrgId:  c.GetAdminUserInfo().CurrentOrgId,
3668
+			TotalNum:   int64(len(total_patients)),
3669
+			FailNum:    int64(len(errLogs)),
3670
+			SuccessNum: int64(len(patients)),
3671
+			CreateTime: time.Now().Unix(),
3672
+			UpdateTime: time.Now().Unix(),
3673
+			ExportTime: export_time,
3674
+			Status:     1,
3675
+		}
3676
+		service.CreateExportLog(&log)
3677
+
3678
+		c.ServeSuccessJSON(map[string]interface{}{
3679
+			"msg":         "导入成功",
3680
+			"total_num":   len(total_patients),
3681
+			"success_num": len(patients),
3682
+			"fail_num":    int64(len(errLogs)),
3683
+		})
3684
+	}
3685
+}
3686
+
3687
+func GetBirthDay(IDCardNo string) *time.Time {
3688
+	dayStr := IDCardNo[6:14] + "000001"
3689
+	birthDay, err := time.Parse("20060102150405", dayStr)
3690
+	if err != nil {
3691
+		log.Fatal(err)
3692
+		return nil
3693
+	}
3694
+
3695
+	return &birthDay
3696
+}
3697
+
3698
+func VerifyMobileFormat(mobileNum string) bool {
3699
+	regular := "^((13[0-9])|(14[5,7])|(15[0-3,5-9])|(17[0,3,5-8])|(18[0-9])|166|198|199|(147))\\d{8}$"
3700
+
3701
+	reg := regexp.MustCompile(regular)
3702
+	return reg.MatchString(mobileNum)
3703
+}
3704
+
3705
+func IsIdCard(idCard string) (res bool) {
3706
+	res, _ = regexp.Match("^[1-9]\\d{7}((0\\d)|(1[0-2]))(([0|1|2]\\d)|3[0-1])\\d{3}$|^[1-9]\\d{5}[1-9]\\d{3}((0\\d)|(1[0-2]))(([0|1|2]\\d)|3[0-1])\\d{3}([0-9]|X)$", []byte(idCard))
3707
+	return
3708
+}
3709
+
3379 3710
 func (c *PatientApiController) SaveEditAdvices() {
3380 3711
 	adminInfo := c.GetAdminUserInfo()
3381 3712
 	orgid := adminInfo.CurrentOrgId

+ 1 - 1
controllers/public_api_controller.go Näytä tiedosto

@@ -163,7 +163,7 @@ func (this *PublicApiController) GetJson() {
163 163
 }
164 164
 
165 165
 func (c *PublicApiController) HandleData() {
166
-	service.HandleData()
166
+	//service.HandleData()
167 167
 
168 168
 	//org_app, _ := service.GetAllAppOrg()
169 169
 	//org_role, _ := service.GetAllRole()

+ 943 - 3
controllers/schedule_api_controller.go Näytä tiedosto

@@ -7,6 +7,7 @@ import (
7 7
 	"XT_New/utils"
8 8
 	"encoding/json"
9 9
 	"fmt"
10
+	"github.com/jinzhu/gorm"
10 11
 	"reflect"
11 12
 	"strconv"
12 13
 	"time"
@@ -21,17 +22,18 @@ type ScheduleApiController struct {
21 22
 func ScheduleApiRegistRouters() {
22 23
 	beego.Router("/api/schedule/weekpanel", &ScheduleApiController{}, "Get:GetWeekPanels")
23 24
 	beego.Router("/api/schedule/schedules", &ScheduleApiController{}, "Get:GetSchedules")
25
+	beego.Router("/api/excel_date/init", &ScheduleApiController{}, "Get:GetInitExcelInitDate")
26
+
24 27
 	beego.Router("/api/schedule/patients", &ScheduleApiController{}, "Get:GetPatients")
25 28
 	beego.Router("/api/schedule/create", &ScheduleApiController{}, "Post:CreateSchedule")
26 29
 	beego.Router("/api/schedule/delete", &ScheduleApiController{}, "Delete:DeleteSchedule")
27 30
 	beego.Router("/api/schedule/change", &ScheduleApiController{}, "Put:ChangeSchedule")
28 31
 	beego.Router("/api/schedule/urgentinit", &ScheduleApiController{}, "Get:UrgentScheduleData")
29
-
30 32
 	beego.Router("/api/schedule/print/initdata", &ScheduleApiController{}, "get:PrintInitData")
31
-
32 33
 	beego.Router("/api/schedule/search", &ScheduleApiController{}, "get:SearchSchedulePatients")
33
-
34 34
 	beego.Router("/api/schedule/week", &ScheduleApiController{}, "get:GetWeekDaySchedule")
35
+	beego.Router("/api/schedule/export", &ScheduleApiController{}, "post:ExportSchedule")
36
+	beego.Router("/api/schedule_template/export", &ScheduleApiController{}, "post:ExportScheduleTemplate")
35 37
 
36 38
 }
37 39
 
@@ -702,3 +704,941 @@ func Struct2Map(obj interface{}) map[string]interface{} {
702 704
 	}
703 705
 	return data
704 706
 }
707
+
708
+func (this *ScheduleApiController) ExportSchedule() {
709
+	dataBody := make(map[string]interface{}, 0)
710
+	err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
711
+	if err != nil {
712
+		utils.ErrorLog(err.Error())
713
+		return
714
+	}
715
+	utils.ErrorLog("%v", dataBody)
716
+	export_time := time.Now().Unix()
717
+	var schedules []*models.Schedule
718
+	var total_schedule []interface{}
719
+
720
+	var patients []*models.Patients
721
+
722
+	patients, _, _ = service.GetAllPatientList(this.GetAdminUserInfo().CurrentOrgId)
723
+
724
+	if dataBody["schedule"] != nil || reflect.TypeOf(dataBody["schedule"]).String() == "[]interface {}" {
725
+		tempSchedule := dataBody["schedule"].([]interface{})
726
+		total_schedule = tempSchedule
727
+		for _, schMap := range tempSchedule {
728
+			schMapM := schMap.(map[string]interface{})
729
+			var sch models.Schedule
730
+
731
+			if schMapM["name"] == nil || reflect.TypeOf(schMapM["name"]).String() != "string" {
732
+				utils.ErrorLog("name")
733
+				return
734
+			}
735
+
736
+			name, _ := schMapM["name"].(string)
737
+			fmt.Println(name)
738
+			if len(name) == 0 { //名字为空则生成一条导入错误日志
739
+				err_log := models.ExportErrLog{
740
+					LogType:    2,
741
+					UserOrgId:  this.GetAdminUserInfo().CurrentOrgId,
742
+					ErrMsg:     "第" + strconv.FormatInt(int64(schMapM["index"].(float64)), 10) + "行,第" + schMapM["row"].(string) + "列的姓名不能为空",
743
+					Status:     1,
744
+					CreateTime: time.Now().Unix(),
745
+					UpdateTime: time.Now().Unix(),
746
+					ExportTime: export_time,
747
+				}
748
+				service.CreateExportErrLog(&err_log)
749
+				continue
750
+
751
+			} else {
752
+				var patient []*models.Patients
753
+				for _, item := range patients {
754
+					if item.Name == name {
755
+						patient = append(patient, item)
756
+					}
757
+				}
758
+				if len(patient) == 0 { //错误日志
759
+					err_log := models.ExportErrLog{
760
+						LogType:    2,
761
+						UserOrgId:  this.GetAdminUserInfo().CurrentOrgId,
762
+						ErrMsg:     "第" + strconv.FormatInt(int64(schMapM["index"].(float64)), 10) + "行,第" + schMapM["row"].(string) + "列的姓名在系统中不存在,请在系统中添加该病人",
763
+						Status:     1,
764
+						CreateTime: time.Now().Unix(),
765
+						UpdateTime: time.Now().Unix(),
766
+						ExportTime: export_time,
767
+					}
768
+					service.CreateExportErrLog(&err_log)
769
+					continue
770
+
771
+				} else if len(patient) == 1 { //
772
+					sch.PatientId = patient[0].ID
773
+
774
+				} else if len(patient) > 2 { //出现同名的情况
775
+
776
+					err_log := models.ExportErrLog{
777
+						LogType:    2,
778
+						UserOrgId:  this.GetAdminUserInfo().CurrentOrgId,
779
+						ErrMsg:     "存在同名同姓的两个病人",
780
+						Status:     1,
781
+						CreateTime: time.Now().Unix(),
782
+						UpdateTime: time.Now().Unix(),
783
+						ExportTime: export_time,
784
+					}
785
+					service.CreateExportErrLog(&err_log)
786
+					continue
787
+
788
+				}
789
+			}
790
+
791
+			if schMapM["schedule_type"] == nil && reflect.TypeOf(schMapM["schedule_type"]).String() != "float64" {
792
+				utils.ErrorLog("schedule_type")
793
+				return
794
+			}
795
+			schedule_type := int64(schMapM["schedule_type"].(float64))
796
+			if schedule_type <= 0 { //班次格式有误,插入日志
797
+
798
+				log := models.ExportLog{
799
+					LogType:    2,
800
+					UserOrgId:  this.GetAdminUserInfo().CurrentOrgId,
801
+					TotalNum:   int64(len(total_schedule)),
802
+					FailNum:    1,
803
+					SuccessNum: int64(len(schedules)),
804
+					CreateTime: time.Now().Unix(),
805
+					UpdateTime: time.Now().Unix(),
806
+					ExportTime: export_time,
807
+					Status:     1,
808
+				}
809
+				service.CreateExportLog(&log)
810
+
811
+				err_log := models.ExportErrLog{
812
+					LogType:    2,
813
+					UserOrgId:  this.GetAdminUserInfo().CurrentOrgId,
814
+					ErrMsg:     "第2行第" + schMapM["row"].(string) + "列的班次格式有误",
815
+					Status:     1,
816
+					CreateTime: time.Now().Unix(),
817
+					UpdateTime: time.Now().Unix(),
818
+					ExportTime: export_time,
819
+				}
820
+				service.CreateExportErrLog(&err_log)
821
+				this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeExportError)
822
+				return
823
+
824
+			} else {
825
+				sch.ScheduleType = schedule_type
826
+			}
827
+
828
+			if schMapM["partition_name"] == nil || reflect.TypeOf(schMapM["partition_name"]).String() != "string" {
829
+				utils.ErrorLog("partition_name")
830
+				return
831
+			}
832
+
833
+			partition_name, _ := schMapM["partition_name"].(string)
834
+			if len(partition_name) == 0 { //分区为空
835
+				log := models.ExportLog{
836
+					LogType:    2,
837
+					UserOrgId:  this.GetAdminUserInfo().CurrentOrgId,
838
+					TotalNum:   int64(len(total_schedule)),
839
+					FailNum:    1,
840
+					SuccessNum: int64(len(schedules)),
841
+					CreateTime: time.Now().Unix(),
842
+					UpdateTime: time.Now().Unix(),
843
+					ExportTime: export_time,
844
+					Status:     1,
845
+				}
846
+				service.CreateExportLog(&log)
847
+
848
+				err_log := models.ExportErrLog{
849
+					LogType:   2,
850
+					UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
851
+					//ErrMsg:     "第" + 	strconv.FormatInt(int64(schMapM["index"].(float64)) ,10)+ "行" + "的姓名不能为空",
852
+					ErrMsg:     "第" + strconv.FormatInt(int64(schMapM["index"].(float64)), 10) + "行第1列所属的分区格式有误",
853
+					Status:     1,
854
+					CreateTime: time.Now().Unix(),
855
+					UpdateTime: time.Now().Unix(),
856
+					ExportTime: export_time,
857
+				}
858
+				service.CreateExportErrLog(&err_log)
859
+				this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeExportError)
860
+				return
861
+
862
+			} else {
863
+				zone, err := service.FindDeviceZoneByName(partition_name, this.GetAdminUserInfo().CurrentOrgId)
864
+				if err == nil {
865
+					sch.PartitionId = zone.ID
866
+				} else if err == gorm.ErrRecordNotFound { //查不到数据,插入错误日志
867
+
868
+					log := models.ExportLog{
869
+						LogType:    2,
870
+						UserOrgId:  this.GetAdminUserInfo().CurrentOrgId,
871
+						TotalNum:   int64(len(total_schedule)),
872
+						FailNum:    1,
873
+						SuccessNum: int64(len(schedules)),
874
+						CreateTime: time.Now().Unix(),
875
+						UpdateTime: time.Now().Unix(),
876
+						ExportTime: export_time,
877
+						Status:     1,
878
+					}
879
+					service.CreateExportLog(&log)
880
+
881
+					err_log := models.ExportErrLog{
882
+						LogType:   2,
883
+						UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
884
+						//ErrMsg:     "第" + 	strconv.FormatInt(int64(schMapM["index"].(float64)) ,10)+ "行" + "的姓名不能为空",
885
+						ErrMsg:     "第" + strconv.FormatInt(int64(schMapM["index"].(float64)), 10) + "行第1列所属的分区格式有误",
886
+						Status:     1,
887
+						CreateTime: time.Now().Unix(),
888
+						UpdateTime: time.Now().Unix(),
889
+						ExportTime: export_time,
890
+					}
891
+					service.CreateExportErrLog(&err_log)
892
+					this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeExportError)
893
+					return
894
+
895
+				}
896
+
897
+			}
898
+
899
+			if schMapM["device_number_name"] == nil || reflect.TypeOf(schMapM["device_number_name"]).String() != "string" {
900
+				utils.ErrorLog("device_number_name")
901
+				return
902
+			}
903
+
904
+			device_number_name, _ := schMapM["device_number_name"].(string)
905
+			if len(device_number_name) == 0 { //分区为空
906
+
907
+				log := models.ExportLog{
908
+					LogType:    2,
909
+					UserOrgId:  this.GetAdminUserInfo().CurrentOrgId,
910
+					TotalNum:   int64(len(total_schedule)),
911
+					FailNum:    1,
912
+					SuccessNum: int64(len(schedules)),
913
+					CreateTime: time.Now().Unix(),
914
+					UpdateTime: time.Now().Unix(),
915
+					ExportTime: export_time,
916
+					Status:     1,
917
+				}
918
+				service.CreateExportLog(&log)
919
+
920
+				err_log := models.ExportErrLog{
921
+					LogType:   2,
922
+					UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
923
+					//ErrMsg:     "第" + 	strconv.FormatInt(int64(schMapM["index"].(float64)) ,10)+ "行" + "的姓名不能为空",
924
+					ErrMsg: "第" + strconv.FormatInt(int64(schMapM["index"].(float64)), 10) + "行第2列机号格式有误",
925
+
926
+					Status:     1,
927
+					CreateTime: time.Now().Unix(),
928
+					UpdateTime: time.Now().Unix(),
929
+					ExportTime: export_time,
930
+				}
931
+				service.CreateExportErrLog(&err_log)
932
+				this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeExportError)
933
+				return
934
+
935
+			} else {
936
+				device, err := service.FindDeviceByName(device_number_name, this.GetAdminUserInfo().CurrentOrgId, sch.PartitionId)
937
+				if err == nil {
938
+					if len(device) == 0 { //没查到数据,插入错误日志
939
+
940
+						log := models.ExportLog{
941
+							LogType:    2,
942
+							UserOrgId:  this.GetAdminUserInfo().CurrentOrgId,
943
+							TotalNum:   int64(len(total_schedule)),
944
+							FailNum:    1,
945
+							SuccessNum: int64(len(schedules)),
946
+							CreateTime: time.Now().Unix(),
947
+							UpdateTime: time.Now().Unix(),
948
+							ExportTime: export_time,
949
+							Status:     1,
950
+						}
951
+						service.CreateExportLog(&log)
952
+
953
+						err_log := models.ExportErrLog{
954
+							LogType:    2,
955
+							UserOrgId:  this.GetAdminUserInfo().CurrentOrgId,
956
+							ErrMsg:     "第" + strconv.FormatInt(int64(schMapM["index"].(float64)), 10) + "行第2列机号格式有误",
957
+							Status:     1,
958
+							CreateTime: time.Now().Unix(),
959
+							UpdateTime: time.Now().Unix(),
960
+							ExportTime: export_time,
961
+						}
962
+						service.CreateExportErrLog(&err_log)
963
+						this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeExportError)
964
+						return
965
+
966
+					} else if len(device) == 1 {
967
+						sch.BedId = device[0].ID
968
+
969
+					} else if len(device) > 1 { //出现重名,插入错误日志
970
+
971
+						log := models.ExportLog{
972
+							LogType:    2,
973
+							UserOrgId:  this.GetAdminUserInfo().CurrentOrgId,
974
+							TotalNum:   int64(len(total_schedule)),
975
+							FailNum:    1,
976
+							SuccessNum: int64(len(schedules)),
977
+							CreateTime: time.Now().Unix(),
978
+							UpdateTime: time.Now().Unix(),
979
+							ExportTime: export_time,
980
+							Status:     1,
981
+						}
982
+						service.CreateExportLog(&log)
983
+
984
+						err_log := models.ExportErrLog{
985
+							LogType:    2,
986
+							UserOrgId:  this.GetAdminUserInfo().CurrentOrgId,
987
+							ErrMsg:     "出现两个床位号相同的床位",
988
+							Status:     1,
989
+							CreateTime: time.Now().Unix(),
990
+							UpdateTime: time.Now().Unix(),
991
+							ExportTime: export_time,
992
+						}
993
+						service.CreateExportErrLog(&err_log)
994
+						this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeExportError)
995
+						return
996
+
997
+					}
998
+				}
999
+			}
1000
+
1001
+			if schMapM["schedule_week"] == nil || reflect.TypeOf(schMapM["schedule_week"]).String() != "string" {
1002
+				utils.ErrorLog("schedule_week")
1003
+				return
1004
+			}
1005
+			schedule_week, _ := schMapM["schedule_week"].(string)
1006
+			if len(schedule_week) == 0 { //周几为空则生成一条导入错误日志
1007
+
1008
+				log := models.ExportLog{
1009
+					LogType:    2,
1010
+					UserOrgId:  this.GetAdminUserInfo().CurrentOrgId,
1011
+					TotalNum:   int64(len(total_schedule)),
1012
+					FailNum:    1,
1013
+					SuccessNum: int64(len(schedules)),
1014
+					CreateTime: time.Now().Unix(),
1015
+					UpdateTime: time.Now().Unix(),
1016
+					ExportTime: export_time,
1017
+					Status:     1,
1018
+				}
1019
+				service.CreateExportLog(&log)
1020
+
1021
+				err_log := models.ExportErrLog{
1022
+					LogType:   2,
1023
+					UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
1024
+					//ErrMsg:     "第" + 	strconv.FormatInt(int64(schMapM["index"].(float64)) ,10)+ "行" + "的姓名不能为空",
1025
+					ErrMsg: "第1行第" + schMapM["row"].(string) + "列的星期名格式有误",
1026
+
1027
+					Status:     1,
1028
+					CreateTime: time.Now().Unix(),
1029
+					UpdateTime: time.Now().Unix(),
1030
+					ExportTime: export_time,
1031
+				}
1032
+				service.CreateExportErrLog(&err_log)
1033
+				this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeExportError)
1034
+				return
1035
+
1036
+			} else if schedule_week == "0" { //周几不符合格式则生成一条导入错误日志
1037
+
1038
+				log := models.ExportLog{
1039
+					LogType:    2,
1040
+					UserOrgId:  this.GetAdminUserInfo().CurrentOrgId,
1041
+					TotalNum:   int64(len(total_schedule)),
1042
+					FailNum:    1,
1043
+					SuccessNum: int64(len(schedules)),
1044
+					CreateTime: time.Now().Unix(),
1045
+					UpdateTime: time.Now().Unix(),
1046
+					ExportTime: export_time,
1047
+					Status:     1,
1048
+				}
1049
+				service.CreateExportLog(&log)
1050
+
1051
+				err_log := models.ExportErrLog{
1052
+					LogType:    2,
1053
+					UserOrgId:  this.GetAdminUserInfo().CurrentOrgId,
1054
+					ErrMsg:     "第1行第" + schMapM["row"].(string) + "列的星期名格式有误",
1055
+					Status:     1,
1056
+					CreateTime: time.Now().Unix(),
1057
+					UpdateTime: time.Now().Unix(),
1058
+					ExportTime: export_time,
1059
+				}
1060
+				service.CreateExportErrLog(&err_log)
1061
+				this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeExportError)
1062
+				return
1063
+
1064
+			} else {
1065
+				schedule_week, _ := strconv.ParseInt(schedule_week, 10, 64)
1066
+				sch.ScheduleWeek = schedule_week
1067
+
1068
+			}
1069
+
1070
+			if schMapM["schedule_date"] == nil || reflect.TypeOf(schMapM["schedule_date"]).String() != "string" {
1071
+				utils.ErrorLog("schedule_date")
1072
+				return
1073
+			}
1074
+			schedule_date, _ := schMapM["schedule_date"].(string)
1075
+
1076
+			if len(schedule_date) == 0 { //周几为空则生成一条导入错误日志
1077
+
1078
+				log := models.ExportLog{
1079
+					LogType:    2,
1080
+					UserOrgId:  this.GetAdminUserInfo().CurrentOrgId,
1081
+					TotalNum:   int64(len(total_schedule)),
1082
+					FailNum:    1,
1083
+					SuccessNum: int64(len(schedules)),
1084
+					CreateTime: time.Now().Unix(),
1085
+					UpdateTime: time.Now().Unix(),
1086
+					ExportTime: export_time,
1087
+					Status:     1,
1088
+				}
1089
+				service.CreateExportLog(&log)
1090
+
1091
+				err_log := models.ExportErrLog{
1092
+					LogType:    2,
1093
+					UserOrgId:  this.GetAdminUserInfo().CurrentOrgId,
1094
+					ErrMsg:     "第1行第" + schMapM["row"].(string) + "列的星期名格式有误",
1095
+					Status:     1,
1096
+					CreateTime: time.Now().Unix(),
1097
+					UpdateTime: time.Now().Unix(),
1098
+					ExportTime: export_time,
1099
+				}
1100
+				service.CreateExportErrLog(&err_log)
1101
+				this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeExportError)
1102
+				return
1103
+
1104
+			} else if schedule_date == "0" { //周几不符合格式则生成一条导入错误日志
1105
+
1106
+				log := models.ExportLog{
1107
+					LogType:    2,
1108
+					UserOrgId:  this.GetAdminUserInfo().CurrentOrgId,
1109
+					TotalNum:   int64(len(total_schedule)),
1110
+					FailNum:    1,
1111
+					SuccessNum: int64(len(schedules)),
1112
+					CreateTime: time.Now().Unix(),
1113
+					UpdateTime: time.Now().Unix(),
1114
+					ExportTime: export_time,
1115
+					Status:     1,
1116
+				}
1117
+				service.CreateExportLog(&log)
1118
+
1119
+				err_log := models.ExportErrLog{
1120
+					LogType:    2,
1121
+					UserOrgId:  this.GetAdminUserInfo().CurrentOrgId,
1122
+					ErrMsg:     "第1行第" + schMapM["row"].(string) + "列的星期名格式有误",
1123
+					Status:     1,
1124
+					CreateTime: time.Now().Unix(),
1125
+					UpdateTime: time.Now().Unix(),
1126
+					ExportTime: export_time,
1127
+				}
1128
+				service.CreateExportErrLog(&err_log)
1129
+				this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeExportError)
1130
+				return
1131
+
1132
+			} else {
1133
+				date, _ := utils.ParseTimeStringToTime("2006-01-02", schedule_date)
1134
+				sch.ScheduleDate = date.Unix()
1135
+			}
1136
+			sch.CreatedTime = time.Now().Unix()
1137
+			sch.UpdatedTime = time.Now().Unix()
1138
+			sch.ModeId = 1
1139
+			sch.Status = 1
1140
+			sch.UserOrgId = this.GetAdminUserInfo().CurrentOrgId
1141
+			sch.IsExport = 1
1142
+			schedules = append(schedules, &sch)
1143
+		}
1144
+
1145
+		errLogs, _ := service.FindSchedualExportLog(this.GetAdminUserInfo().CurrentOrgId, export_time)
1146
+
1147
+		if len(schedules) > 0 {
1148
+			schedule_date := this.GetString("date")
1149
+			date, _ := utils.ParseTimeStringToTime("2006-01-02", schedule_date)
1150
+			clear_schedule_date := date.Unix() //根据日期去清除,该日期以及未来的排班数据
1151
+			err := service.UpdateScheduleStatus(clear_schedule_date, this.GetAdminUserInfo().CurrentOrgId)
1152
+			if err == nil {
1153
+				for _, item := range schedules {
1154
+					service.CreateSchedule(item)
1155
+				}
1156
+
1157
+				log := models.ExportLog{
1158
+					LogType:    2,
1159
+					UserOrgId:  this.GetAdminUserInfo().CurrentOrgId,
1160
+					TotalNum:   int64(len(total_schedule)),
1161
+					FailNum:    int64(len(errLogs)),
1162
+					SuccessNum: int64(len(schedules)),
1163
+					CreateTime: time.Now().Unix(),
1164
+					UpdateTime: time.Now().Unix(),
1165
+					ExportTime: export_time,
1166
+					Status:     1,
1167
+				}
1168
+				service.CreateExportLog(&log)
1169
+
1170
+				this.ServeSuccessJSON(map[string]interface{}{
1171
+					"msg":         "导入成功",
1172
+					"total_num":   len(total_schedule),
1173
+					"success_num": len(schedules),
1174
+					"fail_num":    int64(len(errLogs)),
1175
+				})
1176
+			} else {
1177
+				log := models.ExportLog{
1178
+					LogType:    2,
1179
+					UserOrgId:  this.GetAdminUserInfo().CurrentOrgId,
1180
+					TotalNum:   int64(len(total_schedule)),
1181
+					FailNum:    int64(len(errLogs)),
1182
+					SuccessNum: int64(len(schedules)),
1183
+					CreateTime: time.Now().Unix(),
1184
+					UpdateTime: time.Now().Unix(),
1185
+					ExportTime: export_time,
1186
+					Status:     1,
1187
+				}
1188
+				service.CreateExportLog(&log)
1189
+
1190
+				this.ServeSuccessJSON(map[string]interface{}{
1191
+					"msg":         "导入成功",
1192
+					"total_num":   len(total_schedule),
1193
+					"success_num": len(schedules),
1194
+					"fail_num":    int64(len(errLogs)),
1195
+				})
1196
+			}
1197
+		} else {
1198
+			log := models.ExportLog{
1199
+				LogType:    2,
1200
+				UserOrgId:  this.GetAdminUserInfo().CurrentOrgId,
1201
+				TotalNum:   int64(len(total_schedule)),
1202
+				FailNum:    int64(len(errLogs)),
1203
+				SuccessNum: int64(len(schedules)),
1204
+				CreateTime: time.Now().Unix(),
1205
+				UpdateTime: time.Now().Unix(),
1206
+				ExportTime: export_time,
1207
+				Status:     1,
1208
+			}
1209
+			service.CreateExportLog(&log)
1210
+
1211
+			this.ServeSuccessJSON(map[string]interface{}{
1212
+				"msg":         "导入成功",
1213
+				"total_num":   len(total_schedule),
1214
+				"success_num": len(schedules),
1215
+				"fail_num":    int64(len(errLogs)),
1216
+			})
1217
+		}
1218
+	}
1219
+
1220
+}
1221
+
1222
+func (this *ScheduleApiController) ExportScheduleTemplate() {
1223
+	dataBody := make(map[string]interface{}, 0)
1224
+	err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
1225
+	if err != nil {
1226
+		utils.ErrorLog(err.Error())
1227
+		return
1228
+	}
1229
+	utils.ErrorLog("%v", dataBody)
1230
+	export_time := time.Now().Unix()
1231
+	var schedules []*models.PatientScheduleTemplateItem
1232
+	var total_schedule []interface{}
1233
+
1234
+	patients, _, _ := service.GetAllPatientList(this.GetAdminUserInfo().CurrentOrgId)
1235
+
1236
+	if dataBody["schedule"] != nil || reflect.TypeOf(dataBody["schedule"]).String() == "[]interface {}" {
1237
+		tempSchedule := dataBody["schedule"].([]interface{})
1238
+		total_schedule = tempSchedule
1239
+		for _, schMap := range tempSchedule {
1240
+			schMapM := schMap.(map[string]interface{})
1241
+			var sch models.PatientScheduleTemplateItem
1242
+
1243
+			if schMapM["name"] == nil || reflect.TypeOf(schMapM["name"]).String() != "string" {
1244
+				utils.ErrorLog("name")
1245
+				return
1246
+			}
1247
+
1248
+			name, _ := schMapM["name"].(string)
1249
+			fmt.Println(name)
1250
+			if len(name) == 0 { //名字为空则生成一条导入错误日志
1251
+				err_log := models.ExportErrLog{
1252
+					LogType:    3,
1253
+					UserOrgId:  this.GetAdminUserInfo().CurrentOrgId,
1254
+					ErrMsg:     "第" + strconv.FormatInt(int64(schMapM["index"].(float64)), 10) + "行,第" + schMapM["row"].(string) + "列的姓名不能为空",
1255
+					Status:     1,
1256
+					CreateTime: time.Now().Unix(),
1257
+					UpdateTime: time.Now().Unix(),
1258
+					ExportTime: export_time,
1259
+				}
1260
+				service.CreateExportErrLog(&err_log)
1261
+				continue
1262
+
1263
+			} else {
1264
+				var patient []*models.Patients
1265
+				for _, item := range patients {
1266
+					if item.Name == name {
1267
+						patient = append(patient, item)
1268
+					}
1269
+				}
1270
+				if len(patient) == 0 { //错误日志
1271
+					err_log := models.ExportErrLog{
1272
+						LogType:    3,
1273
+						UserOrgId:  this.GetAdminUserInfo().CurrentOrgId,
1274
+						ErrMsg:     "第" + strconv.FormatInt(int64(schMapM["index"].(float64)), 10) + "行,第" + schMapM["row"].(string) + "列的姓名在系统中不存在,请在系统中添加该病人",
1275
+						Status:     1,
1276
+						CreateTime: time.Now().Unix(),
1277
+						UpdateTime: time.Now().Unix(),
1278
+						ExportTime: export_time,
1279
+					}
1280
+					service.CreateExportErrLog(&err_log)
1281
+					continue
1282
+
1283
+				} else if len(patient) == 1 { //
1284
+					sch.PatientID = patient[0].ID
1285
+
1286
+				} else if len(patient) > 2 { //出现同名的情况
1287
+
1288
+					err_log := models.ExportErrLog{
1289
+						LogType:    3,
1290
+						UserOrgId:  this.GetAdminUserInfo().CurrentOrgId,
1291
+						ErrMsg:     "存在同名同姓的两个病人",
1292
+						Status:     1,
1293
+						CreateTime: time.Now().Unix(),
1294
+						UpdateTime: time.Now().Unix(),
1295
+						ExportTime: export_time,
1296
+					}
1297
+					service.CreateExportErrLog(&err_log)
1298
+					continue
1299
+
1300
+				}
1301
+			}
1302
+
1303
+			if schMapM["schedule_type"] == nil && reflect.TypeOf(schMapM["schedule_type"]).String() != "float64" {
1304
+				utils.ErrorLog("schedule_type")
1305
+				return
1306
+			}
1307
+			schedule_type := int64(schMapM["schedule_type"].(float64))
1308
+			if schedule_type <= 0 { //班次格式有误,插入日志
1309
+				log := models.ExportLog{
1310
+					LogType:    3,
1311
+					UserOrgId:  this.GetAdminUserInfo().CurrentOrgId,
1312
+					TotalNum:   int64(len(total_schedule)),
1313
+					FailNum:    1,
1314
+					SuccessNum: int64(len(schedules)),
1315
+					CreateTime: time.Now().Unix(),
1316
+					UpdateTime: time.Now().Unix(),
1317
+					ExportTime: export_time,
1318
+					Status:     1,
1319
+				}
1320
+				service.CreateExportLog(&log)
1321
+
1322
+				err_log := models.ExportErrLog{
1323
+					LogType:    3,
1324
+					UserOrgId:  this.GetAdminUserInfo().CurrentOrgId,
1325
+					ErrMsg:     "第2行第" + schMapM["row"].(string) + "列的班次格式有误",
1326
+					Status:     1,
1327
+					CreateTime: time.Now().Unix(),
1328
+					UpdateTime: time.Now().Unix(),
1329
+					ExportTime: export_time,
1330
+				}
1331
+				service.CreateExportErrLog(&err_log)
1332
+				this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeExportError)
1333
+				return
1334
+
1335
+			} else {
1336
+				sch.TimeType = int8(schedule_type)
1337
+			}
1338
+
1339
+			if schMapM["template_id"] == nil && reflect.TypeOf(schMapM["template_id"]).String() != "float64" {
1340
+				utils.ErrorLog("template_id")
1341
+				return
1342
+			}
1343
+
1344
+			template_id := int64(schMapM["template_id"].(float64))
1345
+			sch.TemplateID = template_id
1346
+
1347
+			if schMapM["device_number_name"] == nil || reflect.TypeOf(schMapM["device_number_name"]).String() != "string" {
1348
+				utils.ErrorLog("device_number_name")
1349
+				return
1350
+			}
1351
+
1352
+			device_number_name, _ := schMapM["device_number_name"].(string)
1353
+			if len(device_number_name) == 0 { //分区为空
1354
+				log := models.ExportLog{
1355
+					LogType:    3,
1356
+					UserOrgId:  this.GetAdminUserInfo().CurrentOrgId,
1357
+					TotalNum:   int64(len(total_schedule)),
1358
+					FailNum:    1,
1359
+					SuccessNum: int64(len(schedules)),
1360
+					CreateTime: time.Now().Unix(),
1361
+					UpdateTime: time.Now().Unix(),
1362
+					ExportTime: export_time,
1363
+					Status:     1,
1364
+				}
1365
+				service.CreateExportLog(&log)
1366
+
1367
+				err_log := models.ExportErrLog{
1368
+					LogType:   3,
1369
+					UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
1370
+					//ErrMsg:     "第" + 	strconv.FormatInt(int64(schMapM["index"].(float64)) ,10)+ "行" + "的姓名不能为空",
1371
+					ErrMsg: "第" + strconv.FormatInt(int64(schMapM["index"].(float64)), 10) + "行第2列机号格式有误",
1372
+
1373
+					Status:     1,
1374
+					CreateTime: time.Now().Unix(),
1375
+					UpdateTime: time.Now().Unix(),
1376
+					ExportTime: export_time,
1377
+				}
1378
+				service.CreateExportErrLog(&err_log)
1379
+				this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeExportError)
1380
+				return
1381
+
1382
+			} else {
1383
+				device, err := service.FindDeviceByNameTwo(device_number_name, this.GetAdminUserInfo().CurrentOrgId)
1384
+				if err == nil {
1385
+					if len(device) == 0 { //没查到数据,插入错误日志
1386
+						log := models.ExportLog{
1387
+							LogType:    3,
1388
+							UserOrgId:  this.GetAdminUserInfo().CurrentOrgId,
1389
+							TotalNum:   int64(len(total_schedule)),
1390
+							FailNum:    1,
1391
+							SuccessNum: int64(len(schedules)),
1392
+							CreateTime: time.Now().Unix(),
1393
+							UpdateTime: time.Now().Unix(),
1394
+							ExportTime: export_time,
1395
+							Status:     1,
1396
+						}
1397
+						service.CreateExportLog(&log)
1398
+
1399
+						err_log := models.ExportErrLog{
1400
+							LogType:    3,
1401
+							UserOrgId:  this.GetAdminUserInfo().CurrentOrgId,
1402
+							ErrMsg:     "第" + strconv.FormatInt(int64(schMapM["index"].(float64)), 10) + "行第2列机号格式有误",
1403
+							Status:     1,
1404
+							CreateTime: time.Now().Unix(),
1405
+							UpdateTime: time.Now().Unix(),
1406
+							ExportTime: export_time,
1407
+						}
1408
+						service.CreateExportErrLog(&err_log)
1409
+						this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeExportError)
1410
+						return
1411
+
1412
+					} else if len(device) == 1 {
1413
+						sch.DeviceNumberID = device[0].ID
1414
+
1415
+					} else if len(device) > 1 { //出现重名,插入错误日志
1416
+						log := models.ExportLog{
1417
+							LogType:    3,
1418
+							UserOrgId:  this.GetAdminUserInfo().CurrentOrgId,
1419
+							TotalNum:   int64(len(total_schedule)),
1420
+							FailNum:    1,
1421
+							SuccessNum: int64(len(schedules)),
1422
+							CreateTime: time.Now().Unix(),
1423
+							UpdateTime: time.Now().Unix(),
1424
+							ExportTime: export_time,
1425
+							Status:     1,
1426
+						}
1427
+						service.CreateExportLog(&log)
1428
+
1429
+						err_log := models.ExportErrLog{
1430
+							LogType:    3,
1431
+							UserOrgId:  this.GetAdminUserInfo().CurrentOrgId,
1432
+							ErrMsg:     "出现两个床位号相同的床位",
1433
+							Status:     1,
1434
+							CreateTime: time.Now().Unix(),
1435
+							UpdateTime: time.Now().Unix(),
1436
+							ExportTime: export_time,
1437
+						}
1438
+						service.CreateExportErrLog(&err_log)
1439
+						this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeExportError)
1440
+						return
1441
+
1442
+					}
1443
+				}
1444
+			}
1445
+
1446
+			if schMapM["schedule_week"] == nil || reflect.TypeOf(schMapM["schedule_week"]).String() != "string" {
1447
+				utils.ErrorLog("schedule_week")
1448
+				return
1449
+			}
1450
+			schedule_week, _ := schMapM["schedule_week"].(string)
1451
+			if len(schedule_week) == 0 { //周几为空则生成一条导入错误日志
1452
+
1453
+				log := models.ExportLog{
1454
+					LogType:    3,
1455
+					UserOrgId:  this.GetAdminUserInfo().CurrentOrgId,
1456
+					TotalNum:   int64(len(total_schedule)),
1457
+					FailNum:    1,
1458
+					SuccessNum: int64(len(schedules)),
1459
+					CreateTime: time.Now().Unix(),
1460
+					UpdateTime: time.Now().Unix(),
1461
+					ExportTime: export_time,
1462
+					Status:     1,
1463
+				}
1464
+				service.CreateExportLog(&log)
1465
+
1466
+				err_log := models.ExportErrLog{
1467
+					LogType:   3,
1468
+					UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
1469
+					//ErrMsg:     "第" + 	strconv.FormatInt(int64(schMapM["index"].(float64)) ,10)+ "行" + "的姓名不能为空",
1470
+					ErrMsg: "第1行第" + schMapM["row"].(string) + "列的星期名格式有误",
1471
+
1472
+					Status:     1,
1473
+					CreateTime: time.Now().Unix(),
1474
+					UpdateTime: time.Now().Unix(),
1475
+					ExportTime: export_time,
1476
+				}
1477
+				service.CreateExportErrLog(&err_log)
1478
+				this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeExportError)
1479
+				return
1480
+
1481
+			} else if schedule_week == "0" { //周几不符合格式则生成一条导入错误日志
1482
+
1483
+				log := models.ExportLog{
1484
+					LogType:    3,
1485
+					UserOrgId:  this.GetAdminUserInfo().CurrentOrgId,
1486
+					TotalNum:   int64(len(total_schedule)),
1487
+					FailNum:    1,
1488
+					SuccessNum: int64(len(schedules)),
1489
+					CreateTime: time.Now().Unix(),
1490
+					UpdateTime: time.Now().Unix(),
1491
+					ExportTime: export_time,
1492
+					Status:     1,
1493
+				}
1494
+				service.CreateExportLog(&log)
1495
+
1496
+				err_log := models.ExportErrLog{
1497
+					LogType:    3,
1498
+					UserOrgId:  this.GetAdminUserInfo().CurrentOrgId,
1499
+					ErrMsg:     "第1行第" + schMapM["row"].(string) + "列的星期名格式有误",
1500
+					Status:     1,
1501
+					CreateTime: time.Now().Unix(),
1502
+					UpdateTime: time.Now().Unix(),
1503
+					ExportTime: export_time,
1504
+				}
1505
+				service.CreateExportErrLog(&err_log)
1506
+				this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeExportError)
1507
+				return
1508
+
1509
+			} else {
1510
+				schedule_week, _ := strconv.ParseInt(schedule_week, 10, 64)
1511
+				sch.Weekday = int8(schedule_week)
1512
+
1513
+			}
1514
+
1515
+			sch.CreateTime = time.Now().Unix()
1516
+			sch.ModifyTime = time.Now().Unix()
1517
+			sch.TreatMode = 1
1518
+			sch.Status = 1
1519
+			sch.OrgID = this.GetAdminUserInfo().CurrentOrgId
1520
+			sch.IsExport = 1
1521
+			schedules = append(schedules, &sch)
1522
+		}
1523
+
1524
+		errLogs, _ := service.FindSchedualTemplateExportLog(this.GetAdminUserInfo().CurrentOrgId, export_time)
1525
+
1526
+		if len(schedules) > 0 {
1527
+			err := service.UpdateScheduleTemplateStatus(this.GetAdminUserInfo().CurrentOrgId)
1528
+			if err == nil {
1529
+				for _, item := range schedules {
1530
+					service.CreateScheduleTemplate(item)
1531
+				}
1532
+
1533
+				log := models.ExportLog{
1534
+					LogType:    3,
1535
+					UserOrgId:  this.GetAdminUserInfo().CurrentOrgId,
1536
+					TotalNum:   int64(len(total_schedule)),
1537
+					FailNum:    int64(len(errLogs)),
1538
+					SuccessNum: int64(len(schedules)),
1539
+					CreateTime: time.Now().Unix(),
1540
+					UpdateTime: time.Now().Unix(),
1541
+					ExportTime: export_time,
1542
+					Status:     1,
1543
+				}
1544
+				service.CreateExportLog(&log)
1545
+
1546
+				this.ServeSuccessJSON(map[string]interface{}{
1547
+					"msg":         "导入成功",
1548
+					"total_num":   len(total_schedule),
1549
+					"success_num": len(schedules),
1550
+					"fail_num":    int64(len(errLogs)),
1551
+				})
1552
+			} else {
1553
+				log := models.ExportLog{
1554
+					LogType:    3,
1555
+					UserOrgId:  this.GetAdminUserInfo().CurrentOrgId,
1556
+					TotalNum:   int64(len(total_schedule)),
1557
+					FailNum:    int64(len(errLogs)),
1558
+					SuccessNum: int64(len(schedules)),
1559
+					CreateTime: time.Now().Unix(),
1560
+					UpdateTime: time.Now().Unix(),
1561
+					ExportTime: export_time,
1562
+					Status:     1,
1563
+				}
1564
+				service.CreateExportLog(&log)
1565
+
1566
+				this.ServeSuccessJSON(map[string]interface{}{
1567
+					"msg":         "导入成功",
1568
+					"total_num":   len(total_schedule),
1569
+					"success_num": len(schedules),
1570
+					"fail_num":    int64(len(errLogs)),
1571
+				})
1572
+			}
1573
+		} else {
1574
+			log := models.ExportLog{
1575
+				LogType:    3,
1576
+				UserOrgId:  this.GetAdminUserInfo().CurrentOrgId,
1577
+				TotalNum:   int64(len(total_schedule)),
1578
+				FailNum:    int64(len(errLogs)),
1579
+				SuccessNum: int64(len(schedules)),
1580
+				CreateTime: time.Now().Unix(),
1581
+				UpdateTime: time.Now().Unix(),
1582
+				ExportTime: export_time,
1583
+				Status:     1,
1584
+			}
1585
+			service.CreateExportLog(&log)
1586
+
1587
+			this.ServeSuccessJSON(map[string]interface{}{
1588
+				"msg":         "导入成功",
1589
+				"total_num":   len(total_schedule),
1590
+				"success_num": len(schedules),
1591
+				"fail_num":    int64(len(errLogs)),
1592
+			})
1593
+		}
1594
+	}
1595
+
1596
+}
1597
+
1598
+func (c *ScheduleApiController) GetInitExcelInitDate() {
1599
+
1600
+	thisTime := time.Now()
1601
+	thisTime1 := time.Now()
1602
+	thisTime2 := time.Now()
1603
+
1604
+	thisTime1 = thisTime1.AddDate(0, 0, 7)
1605
+	thisTime2 = thisTime2.AddDate(0, 0, 14)
1606
+
1607
+	weekDay := int(thisTime.Weekday())
1608
+	if weekDay == 0 {
1609
+		weekDay = 7
1610
+	}
1611
+	weekEnd := 7 - weekDay
1612
+	weekStart := weekEnd - 6
1613
+	days := make([]string, 0)
1614
+	for index := weekStart; index <= weekEnd; index++ {
1615
+		theDay := thisTime.AddDate(0, 0, index)
1616
+		days = append(days, theDay.Format("2006-01-02"))
1617
+	}
1618
+
1619
+	weekDay1 := int(thisTime1.Weekday())
1620
+	if weekDay1 == 0 {
1621
+		weekDay1 = 7
1622
+	}
1623
+	weekEnd1 := 7 - weekDay1
1624
+	weekStart1 := weekEnd1 - 6
1625
+	for index := weekStart1; index <= weekEnd1; index++ {
1626
+		theDay := thisTime1.AddDate(0, 0, index)
1627
+		days = append(days, theDay.Format("2006-01-02"))
1628
+	}
1629
+
1630
+	weekDay2 := int(thisTime2.Weekday())
1631
+	if weekDay2 == 0 {
1632
+		weekDay2 = 7
1633
+	}
1634
+	weekEnd2 := 7 - weekDay2
1635
+	weekStart2 := weekEnd2 - 6
1636
+	for index := weekStart2; index <= weekEnd2; index++ {
1637
+		theDay := thisTime2.AddDate(0, 0, index)
1638
+		days = append(days, theDay.Format("2006-01-02"))
1639
+	}
1640
+	c.ServeSuccessJSON(map[string]interface{}{
1641
+		"days": days,
1642
+	})
1643
+	return
1644
+}

+ 4 - 1
enums/error_code.go Näytä tiedosto

@@ -196,6 +196,8 @@ const ( // ErrorCode
196 196
 	ErrorCodePhone = 20039
197 197
 
198 198
 	ErrorCodeLogOut = 20049
199
+
200
+	ErrorCodeExportError = 20050
199 201
 )
200 202
 
201 203
 var ErrCodeMsgs = map[int]string{
@@ -389,7 +391,8 @@ var ErrCodeMsgs = map[int]string{
389 391
 	ErrorCodeAdminUserIsExit: "用户不存在",
390 392
 	ErrorCodePhone:           "请填写正确的联系电话",
391 393
 
392
-	ErrorCodeLogOut: "退出",
394
+	ErrorCodeLogOut:      "退出",
395
+	ErrorCodeExportError: "导入出错,请下载并查看相关日志",
393 396
 }
394 397
 
395 398
 type SGJError struct {

+ 1 - 1
models/device_models.go Näytä tiedosto

@@ -142,7 +142,7 @@ func (DeviceGroup) TableName() string {
142 142
 type DeviceNumber struct {
143 143
 	ID         int64  `gorm:"column:id" json:"id"`
144 144
 	OrgID      int64  `gorm:"column:org_id" json:"-"`
145
-	Number     string `json:"number"`
145
+	Number     string `gorm:"column:number" json:"number"`
146 146
 	GroupID    int64  `gorm:"column:group_id" json:"group_id"`
147 147
 	ZoneID     int64  `gorm:"column:zone_id" json:"zone_id"`
148 148
 	Status     int8   `json:"-"`

+ 36 - 0
models/patient_models.go Näytä tiedosto

@@ -86,6 +86,9 @@ type Patients struct {
86 86
 	FirstTreatmentDate       int64  `gorm:"column:first_treatment_date" json:"first_treatment_date" form:"first_treatment_date"`
87 87
 	ContactName              string `gorm:"column:contact_name" json:"contact_name" form:"contact_name"`
88 88
 	UserSysBeforeCount       int64  `gorm:"column:user_sys_before_count" json:"user_sys_before_count" form:"user_sys_before_count"`
89
+	IsExcelExport            int64  `gorm:"column:is_excel_export" json:"is_excel_export" form:"is_excel_export"`
90
+
91
+	ContagionIds []int64 `gorm:"-"`
89 92
 }
90 93
 
91 94
 func (Patients) TableName() string {
@@ -864,3 +867,36 @@ func (SgjUserRole) TableName() string {
864 867
 
865 868
 	return "sgj_user_role"
866 869
 }
870
+
871
+type ExportErrLog struct {
872
+	ID         int64  `gorm:"column:id" json:"id" form:"id"`
873
+	LogType    int64  `gorm:"column:log_type" json:"log_type" form:"log_type"`
874
+	UserOrgId  int64  `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
875
+	ErrMsg     string `gorm:"column:err_msg" json:"err_msg" form:"err_msg"`
876
+	CreateTime int64  `gorm:"column:create_time" json:"create_time" form:"create_time"`
877
+	UpdateTime int64  `gorm:"column:update_time" json:"update_time" form:"update_time"`
878
+	Status     int64  `gorm:"column:status" json:"status" form:"status"`
879
+	ExportTime int64  `gorm:"column:export_time" json:"export_time" form:"export_time"`
880
+}
881
+
882
+func (ExportErrLog) TableName() string {
883
+	return "xt_export_err_log"
884
+}
885
+
886
+type ExportLog struct {
887
+	ID           int64           `gorm:"column:id" json:"id" form:"id"`
888
+	LogType      int64           `gorm:"column:log_type" json:"log_type" form:"log_type"`
889
+	UserOrgId    int64           `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
890
+	TotalNum     int64           `gorm:"column:total_num" json:"total_num" form:"total_num"`
891
+	FailNum      int64           `gorm:"column:fail_num" json:"fail_num" form:"fail_num"`
892
+	SuccessNum   int64           `gorm:"column:success_num" json:"success_num" form:"success_num"`
893
+	CreateTime   int64           `gorm:"column:create_time" json:"create_time" form:"create_time"`
894
+	UpdateTime   int64           `gorm:"column:update_time" json:"update_time" form:"update_time"`
895
+	ExportTime   int64           `gorm:"column:export_time" json:"export_time" form:"export_time"`
896
+	Status       int64           `gorm:"column:status" json:"status" form:"status"`
897
+	ExportErrLog []*ExportErrLog `json:"err_logs" gorm:"foreignkey:ExportTime;AssociationForeignKey:ExportTime;"`
898
+}
899
+
900
+func (ExportLog) TableName() string {
901
+	return "xt_export_log"
902
+}

+ 1 - 0
models/patient_schedule_template_models.go Näytä tiedosto

@@ -38,6 +38,7 @@ type PatientScheduleTemplateItem struct {
38 38
 	Status         int8  `gorm:"column:status" json:"-" form:"status"`
39 39
 	CreateTime     int64 `gorm:"column:ctime" json:"-" form:"ctime"`
40 40
 	ModifyTime     int64 `gorm:"column:mtime" json:"-" form:"mtime"`
41
+	IsExport       int64 `gorm:"column:is_export" json:"is_export" form:"is_export"`
41 42
 }
42 43
 
43 44
 func (PatientScheduleTemplateItem) TableName() string {

+ 3 - 0
models/schedule_models.go Näytä tiedosto

@@ -13,6 +13,7 @@ type Schedule struct {
13 13
 	Status       int64 `gorm:"column:status" json:"status" form:"status"`
14 14
 	CreatedTime  int64 `gorm:"column:created_time" json:"created_time" form:"created_time"`
15 15
 	UpdatedTime  int64 `gorm:"column:updated_time" json:"updated_time" form:"updated_time"`
16
+	IsExport     int64 `gorm:"column:is_export" json:"is_export" form:"is_export"`
16 17
 
17 18
 	Patient       string        `gorm:"-" json:"patient" form:"patient"`
18 19
 	DeviceZone    DeviceZone    `json:"zone" gorm:"foreignkey:ID;AssociationForeignKey:PartitionId;"`
@@ -57,6 +58,7 @@ type Search_Schedule struct {
57 58
 	Status       int64 `gorm:"column:status" json:"status" form:"status"`
58 59
 	CreatedTime  int64 `gorm:"column:created_time" json:"created_time" form:"created_time"`
59 60
 	UpdatedTime  int64 `gorm:"column:updated_time" json:"updated_time" form:"updated_time"`
61
+	IsExport     int64 `gorm:"column:is_export" json:"is_export" form:"is_export"`
60 62
 
61 63
 	Patient string `gorm:"-" json:"patient" form:"patient"`
62 64
 }
@@ -78,6 +80,7 @@ type WeekSchedule struct {
78 80
 	Status       int64 `gorm:"column:status" json:"status" form:"status"`
79 81
 	CreatedTime  int64 `gorm:"column:created_time" json:"created_time" form:"created_time"`
80 82
 	UpdatedTime  int64 `gorm:"column:updated_time" json:"updated_time" form:"updated_time"`
83
+	IsExport     int64 `gorm:"column:is_export" json:"is_export" form:"is_export"`
81 84
 
82 85
 	Patient              string           `gorm:"-" json:"patient" form:"patient"`
83 86
 	DeviceZone           DeviceZone       `json:"zone" gorm:"foreignkey:ID;AssociationForeignKey:PartitionId;"`

+ 1 - 0
models/vm_models.go Näytä tiedosto

@@ -147,6 +147,7 @@ type VMSchedule struct {
147 147
 	Status       int64 `gorm:"column:status" json:"status" form:"status"`
148 148
 	CreatedTime  int64 `gorm:"column:created_time" json:"created_time" form:"created_time"`
149 149
 	UpdatedTime  int64 `gorm:"column:updated_time" json:"updated_time" form:"updated_time"`
150
+	IsExport     int64 `gorm:"column:is_export" json:"is_export" form:"is_export"`
150 151
 }
151 152
 
152 153
 func (VMSchedule) TableName() string {

+ 38 - 4
service/app_version.go Näytä tiedosto

@@ -184,9 +184,43 @@ func GetSystemRole(orgID int64) ([]*models.Role, error) {
184 184
 }
185 185
 
186 186
 func HandleData() {
187
-	var prescription []*models.DialysisPrescription
188
-	readDb.Model(&models.DialysisPrescription{}).Where("user_org_id = 12 AND record_date <= 1587571200").Find(&prescription)
189
-	for _, item := range prescription {
190
-		writeDb.Model(&models.AssessmentAfterDislysis{}).Where("user_org_id =12 AND assessment_date = ?", item.RecordDate).Updates(map[string]interface{}{"mtime": time.Now().Unix(), "actual_ultrafiltration": item.Ultrafiltration})
187
+	var pe []*models.PredialysisEvaluation
188
+	//readDb.Model(&models.DialysisPrescription{}).Where("user_org_id = 12 AND record_date <= 1587571200").Find(&prescription)
189
+	//for _, item := range prescription {
190
+	//	writeDb.Model(&models.AssessmentAfterDislysis{}).Where("user_org_id =12 AND assessment_date = ?", item.RecordDate).Updates(map[string]interface{}{"mtime": time.Now().Unix(), "actual_ultrafiltration": item.Ultrafiltration})
191
+	//}
192
+	readDb.Model(&models.PredialysisEvaluation{}).Where("status = 1 AND user_org_id = 9538 AND dialysis_order_id > 0").Find(&pe)
193
+
194
+	for _, item := range pe {
195
+		var sch models.Schedule
196
+		err := readDb.Model(&models.Schedule{}).Where("status = 1 AND schedule_date = ? AND patient_id = ? AND user_org_id = 9538", item.AssessmentDate, item.PatientId).First(&sch).Error
197
+
198
+		if err == nil {
199
+			if sch.ID > 0 {
200
+				order := &models.DialysisOrder{
201
+					DialysisDate:   sch.ScheduleDate,
202
+					UserOrgId:      9538,
203
+					PatientId:      sch.PatientId,
204
+					Stage:          2,
205
+					BedID:          sch.BedId,
206
+					StartNurse:     554,
207
+					FinishNurse:    554,
208
+					Status:         1,
209
+					CreatedTime:    sch.ScheduleDate,
210
+					UpdatedTime:    sch.ScheduleDate,
211
+					StartTime:      sch.ScheduleDate,
212
+					EndTime:        sch.ScheduleDate,
213
+					PunctureNurse:  554,
214
+					Creator:        554,
215
+					Modifier:       554,
216
+					FinishCreator:  554,
217
+					FinishModifier: 554,
218
+					SchedualType:   sch.ScheduleType,
219
+				}
220
+				writeDb.Create(&order)
221
+			}
222
+		}
223
+
191 224
 	}
225
+
192 226
 }

+ 26 - 26
service/device_service.go Näytä tiedosto

@@ -337,17 +337,17 @@ func GetDeviceGroupByID(orgID int64, groupID int64) (*models.DeviceGroup, error)
337 337
 	return &group, nil
338 338
 }
339 339
 
340
-func GetDeviceGroupName(name string,orgid int64)(*models.DeviceGroup,error)  {
341
-  group := models.DeviceGroup{}
342
-  err := XTReadDB().Model(&group).Where("name = ? and org_id = ? and status =1", name, orgid).Find(&group).Error
343
-  if err == gorm.ErrRecordNotFound {
344
-    return nil, err
345
-  }
346
-  if err != nil {
347
-    return nil, err
348
-  }
340
+func GetDeviceGroupName(name string, orgid int64) (*models.DeviceGroup, error) {
341
+	group := models.DeviceGroup{}
342
+	err := XTReadDB().Model(&group).Where("name = ? and org_id = ? and status =1", name, orgid).Find(&group).Error
343
+	if err == gorm.ErrRecordNotFound {
344
+		return nil, err
345
+	}
346
+	if err != nil {
347
+		return nil, err
348
+	}
349 349
 
350
-  return &group, nil
350
+	return &group, nil
351 351
 
352 352
 }
353 353
 
@@ -367,9 +367,9 @@ func CreateDeviceGroup(orgID int64, name string) (*models.DeviceGroup, error) {
367 367
 	return &group, nil
368 368
 }
369 369
 
370
-func GetUpdateDeviceGroupByName(name string,orgid int64)(group models.DeviceGroup,err error)  {
371
-  err = XTReadDB().Model(&group).Where("name = ? and org_id = ? and status =1",name,orgid).Find(&group).Error
372
-  return group,err
370
+func GetUpdateDeviceGroupByName(name string, orgid int64) (group models.DeviceGroup, err error) {
371
+	err = XTReadDB().Model(&group).Where("name = ? and org_id = ? and status =1", name, orgid).Find(&group).Error
372
+	return group, err
373 373
 }
374 374
 
375 375
 func UpdateDeviceGroup(group *models.DeviceGroup) error {
@@ -446,17 +446,17 @@ func GetDeviceNumberByID(orgID int64, numberID int64) (*models.DeviceNumber, err
446 446
 	return &number, nil
447 447
 }
448 448
 
449
-func GetCreateDeviceNumber(num string,orgid int64)(*models.DeviceNumber,error)  {
450
-  number := models.DeviceNumber{}
451
-  err := XTReadDB().Model(&number).Where("number = ? and org_id = ? and status = 1", num, orgid).Find(&number).Error
452
-  if err == gorm.ErrRecordNotFound {
453
-    return nil, err
454
-  }
455
-  if err != nil {
456
-    return nil, err
457
-  }
449
+func GetCreateDeviceNumber(num string, orgid int64) (*models.DeviceNumber, error) {
450
+	number := models.DeviceNumber{}
451
+	err := XTReadDB().Model(&number).Where("number = ? and org_id = ? and status = 1", num, orgid).Find(&number).Error
452
+	if err == gorm.ErrRecordNotFound {
453
+		return nil, err
454
+	}
455
+	if err != nil {
456
+		return nil, err
457
+	}
458 458
 
459
-  return &number, nil
459
+	return &number, nil
460 460
 }
461 461
 
462 462
 func CreateDeviceNumber(orgID int64, number string, zoneID int64, groupID int64) (*models.DeviceNumber, error) {
@@ -477,10 +477,10 @@ func CreateDeviceNumber(orgID int64, number string, zoneID int64, groupID int64)
477 477
 	return &numberModel, nil
478 478
 }
479 479
 
480
-func GetDeviceNumberByName(num string,orgid int64)(number models.DeviceNumber,err error)  {
480
+func GetDeviceNumberByName(num string, orgid int64) (number models.DeviceNumber, err error) {
481 481
 
482
-  err = XTReadDB().Model(&number).Where("number = ? and org_id = ? and status =1",num,orgid).First(&number).Error
483
-  return number,err
482
+	err = XTReadDB().Model(&number).Where("number = ? and org_id = ? and status =1", num, orgid).First(&number).Error
483
+	return number, err
484 484
 }
485 485
 
486 486
 func UpdateDeviceNumber(number *models.DeviceNumber) error {

+ 6 - 0
service/gobal_config_service.go Näytä tiedosto

@@ -157,3 +157,9 @@ func GetPrint(ids []int64, orgid int64) (doctor []*models.DoctorAdvice, err erro
157 157
 
158 158
 	return doctor, err
159 159
 }
160
+
161
+func GetExportLogByType(org_id int64, log_type int64) (log []*models.ExportLog, err error) {
162
+	err = readDb.Model(&models.ExportLog{}).Where("user_org_id = ? AND status = 1 AND log_type = ?", org_id, log_type).
163
+		Preload("ExportErrLog", "status = 1").Find(&log).Error
164
+	return
165
+}

+ 123 - 3
service/patient_service.go Näytä tiedosto

@@ -1162,8 +1162,128 @@ func GetPatientScheduleOne(patientid int64, nowdate int64, orgid int64) (models.
1162 1162
 	return schedule, err
1163 1163
 }
1164 1164
 
1165
-func UpdateDoctorEditAdvice(advice models.XtDoctorAdvice,orgid int64,groupno int64,date int64,patientid int64)error {
1165
+func CreateExportPatient(patient *models.Patients, contagions []int64) (err error) {
1166
+	user, _ := GetSgjUserByMobild(patient.Phone)
1167
+	customer, _ := GetSgjCoustomerByMobile(patient.UserOrgId, patient.Phone)
1168
+	utx := writeDb.Begin()
1169
+	btx := writeUserDb.Begin()
1170
+	if user.ID == 0 {
1171
+		user.Mobile = patient.Phone
1172
+		user.Avatar = patient.Avatar
1173
+		user.AvatarThumb = patient.Avatar
1174
+		user.Birthday = patient.Birthday
1175
+		user.Username = patient.Name
1176
+		user.Gender = patient.Gender
1177
+		user.Sources = 11
1178
+		user.Introduce = patient.Remark
1179
+		user.Status = 1
1180
+		user.UpdatedTime = patient.UpdatedTime
1181
+		user.CreatedTime = patient.CreatedTime
1182
+		err = btx.Create(&user).Error
1183
+		if err != nil {
1184
+			utx.Rollback()
1185
+			btx.Rollback()
1186
+			return
1187
+		}
1188
+	}
1189
+	patient.UserId = user.ID
1190
+
1191
+	if customer == nil {
1192
+		err = btx.Create(&models.SgjCustomer{
1193
+			UserOrgId:   patient.UserOrgId,
1194
+			UserId:      user.ID,
1195
+			Mobile:      patient.Phone,
1196
+			Name:        patient.Name,
1197
+			Gender:      patient.Gender,
1198
+			Birthday:    patient.Birthday,
1199
+			Sources:     11,
1200
+			Status:      1,
1201
+			CreatedTime: patient.CreatedTime,
1202
+			UpdatedTime: patient.UpdatedTime,
1203
+			Avatar:      patient.Avatar,
1204
+			Remark:      patient.Remark,
1205
+		}).Error
1206
+		if err != nil {
1207
+			utx.Rollback()
1208
+			btx.Rollback()
1209
+			return
1210
+		}
1211
+	}
1212
+
1213
+	err = utx.Create(patient).Error
1214
+	if err != nil {
1215
+		utx.Rollback()
1216
+		btx.Rollback()
1217
+		return
1218
+	}
1219
+
1220
+	var lapseto models.PatientLapseto
1221
+	lapseto.PatientId = patient.ID
1222
+	lapseto.LapsetoType = patient.Lapseto
1223
+	lapseto.CreatedTime = patient.CreatedTime
1224
+	lapseto.UpdatedTime = patient.CreatedTime
1225
+	lapseto.Status = 1
1226
+	lapseto.LapsetoTime = patient.CreatedTime
1227
+
1228
+	err = utx.Create(&lapseto).Error
1229
+	if err != nil {
1230
+		utx.Rollback()
1231
+		btx.Rollback()
1232
+		return
1233
+	}
1166 1234
 
1167
-  err := XTWriteDB().Model(&advice).Where("user_org_id = ? and groupno = ? and advice_date = ? and patient_id = ?", orgid, groupno, date, patientid).Update(map[string]interface{}{"start_time": advice.StartTime, "updated_time": advice.UpdatedTime}).Error
1168
-  return err
1235
+	if len(contagions) > 0 {
1236
+		thisSQL := "INSERT INTO xt_patients_infectious_diseases (patient_id, disease_id, status, created_time, updated_time) VALUES "
1237
+		insertParams := make([]string, 0)
1238
+		insertData := make([]interface{}, 0)
1239
+		for _, contagion := range contagions {
1240
+			insertParams = append(insertParams, "(?, ?, ?, ?, ?)")
1241
+			insertData = append(insertData, patient.ID)
1242
+			insertData = append(insertData, contagion)
1243
+			insertData = append(insertData, 1)
1244
+			insertData = append(insertData, patient.CreatedTime)
1245
+			insertData = append(insertData, patient.UpdatedTime)
1246
+		}
1247
+		thisSQL += strings.Join(insertParams, ", ")
1248
+		err = utx.Exec(thisSQL, insertData...).Error
1249
+		if err != nil {
1250
+			utx.Rollback()
1251
+			btx.Rollback()
1252
+			return
1253
+		}
1254
+	}
1255
+	utx.Commit()
1256
+	btx.Commit()
1257
+
1258
+	return
1259
+}
1260
+
1261
+func FindPatientPhoneIsExist(phone string, org_id int64) (count int64) {
1262
+	readDb.Model(&models.Patients{}).Where("user_org_id = ? AND phone = ? AND status = 1", org_id, phone).Count(&count)
1263
+	return
1264
+}
1265
+
1266
+func FindPatientIdCardNoIsExist(id_card_no string, org_id int64) (count int64) {
1267
+	readDb.Model(&models.Patients{}).Where("user_org_id = ? AND id_card_no = ? AND status = 1", org_id, id_card_no).Count(&count)
1268
+	return
1269
+}
1270
+
1271
+func CreateExportErrLog(log *models.ExportErrLog) {
1272
+	writeDb.Create(&log)
1273
+	return
1274
+}
1275
+
1276
+func FindPatientExportLog(org_id int64, export_time int64) (errLogs []*models.ExportErrLog, err error) {
1277
+	err = readDb.Model(&models.ExportErrLog{}).Where("user_org_id = ? AND export_time = ? AND log_type = 1", org_id, export_time).Find(&errLogs).Error
1278
+	return
1279
+}
1280
+
1281
+func CreateExportLog(log *models.ExportLog) {
1282
+	writeDb.Create(&log)
1283
+}
1284
+
1285
+func UpdateDoctorEditAdvice(advice models.XtDoctorAdvice, orgid int64, groupno int64, date int64, patientid int64) error {
1286
+
1287
+	err := XTWriteDB().Model(&advice).Where("user_org_id = ? and groupno = ? and advice_date = ? and patient_id = ?", orgid, groupno, date, patientid).Update(map[string]interface{}{"start_time": advice.StartTime, "updated_time": advice.UpdatedTime}).Error
1288
+	return err
1169 1289
 }

+ 44 - 0
service/schedule_service.go Näytä tiedosto

@@ -349,3 +349,47 @@ func FindAllDoctorAdviceByTimeOther(now int64, end int64, patient_id int64, orgI
349 349
 	err = readDb.Model(&models.DoctorAdvice{}).Where("status = 1 AND user_org_id = ? AND patient_id = ? AND advice_type = 2   AND frequency_type = 2 AND advice_date > ? AND advice_date < ? AND template_id = ?  ", orgId, patient_id, end, now, temp_id).Preload("ChildDoctorAdvice", "status = 1").Find(&advice).Error
350 350
 	return
351 351
 }
352
+
353
+func FindSchPatientNameByName(name string, user_org_id int64) (patient []*models.Patients, err error) {
354
+	err = readDb.Model(&models.Patients{}).Where("user_org_id = ? AND name = ? AND status = 1", user_org_id, name).Find(&patient).Error
355
+	return
356
+}
357
+
358
+func UpdateScheduleStatus(date int64, org_id int64) (err error) {
359
+	err = readDb.Model(&models.Schedule{}).Where("user_org_id = ? AND schedule_date >= ? AND status = 1", org_id, date).Updates(map[string]interface{}{"status": 0, "mtime": time.Now().Unix()}).Error
360
+	return
361
+}
362
+
363
+func FindDeviceZoneByName(name string, org_id int64) (zone models.DeviceZone, err error) {
364
+	err = readDb.Model(&models.DeviceZone{}).Where("org_id = ? AND name = ? AND status = 1", org_id, name).First(&zone).Error
365
+	return
366
+}
367
+
368
+func FindDeviceByName(device_name string, org_id int64, zone_id int64) (devices []*models.DeviceNumber, err error) {
369
+	err = readDb.Model(&models.DeviceNumber{}).Where("org_id = ? AND number = ? AND zone_id = ? AND status = 1", org_id, device_name, zone_id).Find(&devices).Error
370
+	return
371
+}
372
+
373
+func FindSchedualExportLog(org_id int64, export_time int64) (errLogs []*models.ExportErrLog, err error) {
374
+	err = readDb.Model(&models.ExportErrLog{}).Where("user_org_id = ? AND export_time = ? AND log_type = 2", org_id, export_time).Find(&errLogs).Error
375
+	return
376
+}
377
+
378
+func FindDeviceByNameTwo(device_name string, org_id int64) (devices []*models.DeviceNumber, err error) {
379
+	err = readDb.Model(&models.DeviceNumber{}).Where("org_id = ? AND number = ? AND status = 1", org_id, device_name).Find(&devices).Error
380
+	return
381
+}
382
+
383
+func UpdateScheduleTemplateStatus(org_id int64) (err error) {
384
+	err = readDb.Model(&models.PatientScheduleTemplateItem{}).Where("org_id = ? AND status = 1", org_id).Updates(map[string]interface{}{"status": 0, "mtime": time.Now().Unix()}).Error
385
+	return
386
+}
387
+
388
+func CreateScheduleTemplate(m *models.PatientScheduleTemplateItem) error {
389
+	return writeDb.Model(&models.PatientScheduleTemplateItem{}).Create(&m).Error
390
+}
391
+
392
+func FindSchedualTemplateExportLog(org_id int64, export_time int64) (errLogs []*models.ExportErrLog, err error) {
393
+	err = readDb.Model(&models.ExportErrLog{}).Where("user_org_id = ? AND export_time = ? AND log_type = 3", org_id, export_time).Find(&errLogs).Error
394
+	return
395
+}

+ 21 - 0
utils/regex_helper.go Näytä tiedosto

@@ -3,6 +3,7 @@ package utils
3 3
 import (
4 4
 	"fmt"
5 5
 	"regexp"
6
+	"strings"
6 7
 )
7 8
 
8 9
 // 正整数正则
@@ -73,3 +74,23 @@ func TelPhoneRegexpTest() {
73 74
 	fmt.Println("020-390069171 是否匹配:", reg.MatchString("020-390069171"))
74 75
 	fmt.Println("020-3900691 是否匹配:", reg.MatchString("020-3900691"))
75 76
 }
77
+
78
+var (
79
+	coefficient []int32 = []int32{7, 9, 10, 5, 8, 4, 2, 1, 6, 3, 7, 9, 10, 5, 8, 4, 2}
80
+	code        []byte  = []byte{'1', '0', 'X', '9', '8', '7', '6', '5', '4', '3', '2'}
81
+)
82
+
83
+// 校验一个身份证是否是合法的身份证
84
+func Verification(idCardNo string) bool {
85
+	if len(idCardNo) != 18 {
86
+		return false
87
+	}
88
+
89
+	idByte := []byte(strings.ToUpper(idCardNo))
90
+
91
+	sum := int32(0)
92
+	for i := 0; i < 17; i++ {
93
+		sum += int32(byte(idByte[i])-byte('0')) * coefficient[i]
94
+	}
95
+	return code[sum%11] == idByte[17]
96
+}