Browse Source

新功能

csx 3 years ago
parent
commit
13445f3ef9

+ 60 - 60
controllers/base_api_controller.go View File

@@ -2,7 +2,7 @@ package controllers
2 2
 
3 3
 import (
4 4
 	"XT_New/enums"
5
-	//"XT_New/models"
5
+	"XT_New/models"
6 6
 	"XT_New/service"
7 7
 	"fmt"
8 8
 	"strconv"
@@ -65,36 +65,36 @@ type BaseAuthAPIController struct {
65 65
 func (this *BaseAuthAPIController) Prepare() {
66 66
 	this.BaseAPIController.Prepare()
67 67
 	if this.GetAdminUserInfo() == nil {
68
-		//var userAdmin models.AdminUser
69
-		//userAdmin.Id = 400
70
-		//userAdmin.Mobile = "13535547901"
71
-		//
72
-		//userAdmin.Id = 597
73
-		//userAdmin.Mobile = "19874122664"
74
-		//userAdmin.IsSuperAdmin = false
75
-		//userAdmin.Status = 1
76
-		//userAdmin.CreateTime = 1530786071
77
-		//userAdmin.ModifyTime = 1530786071
78
-		//var subscibe models.ServeSubscibe
79
-		//subscibe.ID = 1
80
-		//subscibe.OrgId = 9538
81
-		//subscibe.PeriodStart = 1538035409
82
-		//subscibe.PeriodEnd = 1569571409
83
-		//subscibe.State = 1
84
-		//subscibe.Status = 1
85
-		//subscibe.CreatedTime = 1538035409
86
-		//subscibe.UpdatedTime = 1538035409
87
-		//subscibes := make(map[int64]*models.ServeSubscibe, 0)
88
-		//subscibes[4] = &subscibe
89
-		//var adminUserInfo service.AdminUserInfo
90
-		//adminUserInfo.CurrentOrgId = 9538
91
-		//adminUserInfo.CurrentAppId = 18
92
-		//adminUserInfo.AdminUser = &userAdmin
93
-		//adminUserInfo.Subscibes = subscibes
94
-		//this.SetSession("admin_user_info", &adminUserInfo)
95
-
96
-		this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeNotLogin)
97
-		this.StopRun()
68
+		var userAdmin models.AdminUser
69
+		userAdmin.Id = 400
70
+		userAdmin.Mobile = "13535547901"
71
+
72
+		userAdmin.Id = 597
73
+		userAdmin.Mobile = "19874122664"
74
+		userAdmin.IsSuperAdmin = false
75
+		userAdmin.Status = 1
76
+		userAdmin.CreateTime = 1530786071
77
+		userAdmin.ModifyTime = 1530786071
78
+		var subscibe models.ServeSubscibe
79
+		subscibe.ID = 1
80
+		subscibe.OrgId = 12
81
+		subscibe.PeriodStart = 1538035409
82
+		subscibe.PeriodEnd = 1569571409
83
+		subscibe.State = 1
84
+		subscibe.Status = 1
85
+		subscibe.CreatedTime = 1538035409
86
+		subscibe.UpdatedTime = 1538035409
87
+		subscibes := make(map[int64]*models.ServeSubscibe, 0)
88
+		subscibes[4] = &subscibe
89
+		var adminUserInfo service.AdminUserInfo
90
+		adminUserInfo.CurrentOrgId = 12
91
+		adminUserInfo.CurrentAppId = 18
92
+		adminUserInfo.AdminUser = &userAdmin
93
+		adminUserInfo.Subscibes = subscibes
94
+		this.SetSession("admin_user_info", &adminUserInfo)
95
+
96
+		//this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeNotLogin)
97
+		//this.StopRun()
98 98
 	}
99 99
 
100 100
 	adminUserInfo := this.GetAdminUserInfo()
@@ -316,35 +316,35 @@ type BaseServeAPIController struct {
316 316
 func (this *BaseServeAPIController) Prepare() {
317 317
 	this.BaseAPIController.Prepare()
318 318
 	if this.GetAdminUserInfo() == nil {
319
-		//var userAdmin models.AdminUser
320
-		//userAdmin.Id = 400
321
-		//userAdmin.Mobile = "13535547901"
322
-		////userAdmin.Id = 597
323
-		////userAdmin.Mobile = "19874122664"
324
-		//userAdmin.IsSuperAdmin = false
325
-		//userAdmin.Status = 1
326
-		//userAdmin.CreateTime = 1530786071
327
-		//userAdmin.ModifyTime = 1530786071
328
-		//var subscibe models.ServeSubscibe
329
-		//subscibe.ID = 1
330
-		//subscibe.OrgId = 9538
331
-		//subscibe.PeriodStart = 1538035409
332
-		//subscibe.PeriodEnd = 1569571409
333
-		//subscibe.State = 1
334
-		//subscibe.Status = 1
335
-		//subscibe.CreatedTime = 1538035409
336
-		//subscibe.UpdatedTime = 1538035409
337
-		//subscibes := make(map[int64]*models.ServeSubscibe, 0)
338
-		//subscibes[4] = &subscibe
339
-		//var adminUserInfo service.AdminUserInfo
340
-		//adminUserInfo.CurrentOrgId = 9538
341
-		//adminUserInfo.CurrentAppId = 18
342
-		//adminUserInfo.AdminUser = &userAdmin
343
-		//adminUserInfo.Subscibes = subscibes
344
-		//this.SetSession("admin_user_info", &adminUserInfo)
345
-
346
-		this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeNotLogin)
347
-		this.StopRun()
319
+		var userAdmin models.AdminUser
320
+		userAdmin.Id = 400
321
+		userAdmin.Mobile = "13535547901"
322
+		//userAdmin.Id = 597
323
+		//userAdmin.Mobile = "19874122664"
324
+		userAdmin.IsSuperAdmin = false
325
+		userAdmin.Status = 1
326
+		userAdmin.CreateTime = 1530786071
327
+		userAdmin.ModifyTime = 1530786071
328
+		var subscibe models.ServeSubscibe
329
+		subscibe.ID = 1
330
+		subscibe.OrgId = 12
331
+		subscibe.PeriodStart = 1538035409
332
+		subscibe.PeriodEnd = 1569571409
333
+		subscibe.State = 1
334
+		subscibe.Status = 1
335
+		subscibe.CreatedTime = 1538035409
336
+		subscibe.UpdatedTime = 1538035409
337
+		subscibes := make(map[int64]*models.ServeSubscibe, 0)
338
+		subscibes[4] = &subscibe
339
+		var adminUserInfo service.AdminUserInfo
340
+		adminUserInfo.CurrentOrgId = 12
341
+		adminUserInfo.CurrentAppId = 18
342
+		adminUserInfo.AdminUser = &userAdmin
343
+		adminUserInfo.Subscibes = subscibes
344
+		this.SetSession("admin_user_info", &adminUserInfo)
345
+
346
+		//this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeNotLogin)
347
+		//this.StopRun()
348 348
 	}
349 349
 
350 350
 	//if adminUserInfo.AppRole != nil {

+ 15 - 0
controllers/gobal_config_api_controller.go View File

@@ -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
+}

+ 24 - 24
controllers/mobile_api_controllers/dialysis_api_controller.go View File

@@ -335,34 +335,34 @@ func (this *DialysisAPIController) DialysisRecord() {
335 335
 		return
336 336
 	}
337 337
 
338
-	dialysisPrescribe, getDialysisPrescribeErr := service.MobileGetDialysisPrescribeByModeId(adminInfo.Org.Id, patientID, date.Unix(), schedual.ModeId)
339
-	if getDialysisPrescribeErr != nil {
340
-		this.ErrorLog("获取透析处方失败:%v", getDialysisPrescribeErr)
341
-		this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
342
-		return
343
-	}
338
+	dialysisPrescribe, _ := service.MobileGetDialysisPrescribeByModeId(adminInfo.Org.Id, patientID, date.Unix(), schedual.ModeId)
339
+	//if getDialysisPrescribeErr != nil {
340
+	//	this.ErrorLog("获取透析处方失败:%v", getDialysisPrescribeErr)
341
+	//	this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
342
+	//	return
343
+	//}
344 344
 
345
-	dialysisSolution, getDialysisSolutionErr := service.MobileGetDialysisSolutionByModeId(adminInfo.Org.Id, patientID, schedual.ModeId)
346
-	if getDialysisSolutionErr != nil {
347
-		this.ErrorLog("获取透析方案失败:%v", getDialysisSolutionErr)
348
-		this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
349
-		return
350
-	}
345
+	dialysisSolution, _ := service.MobileGetDialysisSolutionByModeId(adminInfo.Org.Id, patientID, schedual.ModeId)
346
+	//if getDialysisSolutionErr != nil {
347
+	//	this.ErrorLog("获取透析方案失败:%v", getDialysisSolutionErr)
348
+	//	this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
349
+	//	return
350
+	//}
351 351
 
352
-	lastDialysisPrescribe, getDialysisPrescribeErr := service.MobileGetLastDialysisPrescribeByModeId(adminInfo.Org.Id, patientID, schedual.ModeId)
353
-	if getDialysisPrescribeErr != nil {
354
-		this.ErrorLog("获取透析处方失败:%v", getDialysisPrescribeErr)
355
-		this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
356
-		return
357
-	}
352
+	lastDialysisPrescribe, _ := service.MobileGetLastDialysisPrescribeByModeId(adminInfo.Org.Id, patientID, schedual.ModeId)
353
+	//if getDialysisPrescribeErr != nil {
354
+	//	this.ErrorLog("获取透析处方失败:%v", getDialysisPrescribeErr)
355
+	//	this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
356
+	//	return
357
+	//}
358 358
 
359 359
 	//获取系统透析处方模版
360
-	systemDialysisPrescribe, getSystemDialysisPrescribeErr := service.MobileGetSystemDialysisPrescribeByModeId(adminInfo.Org.Id, schedual.ModeId)
361
-	if getSystemDialysisPrescribeErr != nil {
362
-		this.ErrorLog("获取系统透析处方失败:%v", getSystemDialysisPrescribeErr)
363
-		this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
364
-		return
365
-	}
360
+	systemDialysisPrescribe, _ := service.MobileGetSystemDialysisPrescribeByModeId(adminInfo.Org.Id, schedual.ModeId)
361
+	//if getSystemDialysisPrescribeErr != nil {
362
+	//	this.ErrorLog("获取系统透析处方失败:%v", getSystemDialysisPrescribeErr)
363
+	//	this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
364
+	//	return
365
+	//}
366 366
 
367 367
 	//dialysisSolution, getDialysisSolutionErr := service.MobileGetDialysisSolution(adminInfo.Org.Id, patientID)
368 368
 

+ 1 - 0
controllers/mobile_api_controllers/mobile_api_base_controller.go View File

@@ -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"))

+ 408 - 78
controllers/patient_api_controller.go View File

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

+ 1 - 1
controllers/public_api_controller.go View File

@@ -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 View File

@@ -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 View File

@@ -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 View File

@@ -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 View File

@@ -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 {
@@ -863,3 +866,36 @@ func (SgjUserRole) TableName() string {
863 866
 
864 867
 	return "sgj_user_role"
865 868
 }
869
+
870
+type ExportErrLog struct {
871
+	ID         int64  `gorm:"column:id" json:"id" form:"id"`
872
+	LogType    int64  `gorm:"column:log_type" json:"log_type" form:"log_type"`
873
+	UserOrgId  int64  `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
874
+	ErrMsg     string `gorm:"column:err_msg" json:"err_msg" form:"err_msg"`
875
+	CreateTime int64  `gorm:"column:create_time" json:"create_time" form:"create_time"`
876
+	UpdateTime int64  `gorm:"column:update_time" json:"update_time" form:"update_time"`
877
+	Status     int64  `gorm:"column:status" json:"status" form:"status"`
878
+	ExportTime int64  `gorm:"column:export_time" json:"export_time" form:"export_time"`
879
+}
880
+
881
+func (ExportErrLog) TableName() string {
882
+	return "xt_export_err_log"
883
+}
884
+
885
+type ExportLog struct {
886
+	ID           int64           `gorm:"column:id" json:"id" form:"id"`
887
+	LogType      int64           `gorm:"column:log_type" json:"log_type" form:"log_type"`
888
+	UserOrgId    int64           `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
889
+	TotalNum     int64           `gorm:"column:total_num" json:"total_num" form:"total_num"`
890
+	FailNum      int64           `gorm:"column:fail_num" json:"fail_num" form:"fail_num"`
891
+	SuccessNum   int64           `gorm:"column:success_num" json:"success_num" form:"success_num"`
892
+	CreateTime   int64           `gorm:"column:create_time" json:"create_time" form:"create_time"`
893
+	UpdateTime   int64           `gorm:"column:update_time" json:"update_time" form:"update_time"`
894
+	ExportTime   int64           `gorm:"column:export_time" json:"export_time" form:"export_time"`
895
+	Status       int64           `gorm:"column:status" json:"status" form:"status"`
896
+	ExportErrLog []*ExportErrLog `json:"err_logs" gorm:"foreignkey:ExportTime;AssociationForeignKey:ExportTime;"`
897
+}
898
+
899
+func (ExportLog) TableName() string {
900
+	return "xt_export_log"
901
+}

+ 1 - 0
models/patient_schedule_template_models.go View File

@@ -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 View File

@@ -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 View File

@@ -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 View File

@@ -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
 }

+ 6 - 0
service/gobal_config_service.go View File

@@ -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
+}

+ 120 - 0
service/patient_service.go View File

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

+ 44 - 0
service/schedule_service.go View File

@@ -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 View File

@@ -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
+}