Browse Source

提交代码

陈少旭 1 year ago
parent
commit
c7257ffeab
2 changed files with 49 additions and 33 deletions
  1. 40 30
      controllers/inspection_api_controller.go
  2. 9 3
      service/inspection_service.go

+ 40 - 30
controllers/inspection_api_controller.go View File

645
 		c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInspectionDateNotExit)
645
 		c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInspectionDateNotExit)
646
 		return
646
 		return
647
 	}
647
 	}
648
-	inspMap := make(map[int64]*models.Inspection)
648
+	inspMap := make(map[string]models.Inspection)
649
 	for _, item := range insp {
649
 	for _, item := range insp {
650
-		inspMap[item.ID] = item
650
+		fmt.Println(item.ID)
651
+		a := strconv.FormatInt(item.ProjectId, 10) + "-" + strconv.FormatInt(item.ItemId, 10)
652
+		inspMap[a] = item
651
 	}
653
 	}
652
 
654
 
653
 	addinsp := make([]models.Inspection, 0)
655
 	addinsp := make([]models.Inspection, 0)
657
 
659
 
658
 	for _, item := range from.FormItem {
660
 	for _, item := range from.FormItem {
659
 		fmt.Println(item.ID)
661
 		fmt.Println(item.ID)
660
-		if item.ID == 0 {
661
-			var inspection models.Inspection
662
-			inspection.OrgId = adminUserInfo.CurrentOrgId
663
-			inspection.PatientId = patient
664
-			inspection.ProjectId = from.ProjectId
665
-			inspection.ItemId = item.ItemId
666
-			inspection.ItemName = item.ItemName
667
-			inspection.ProjectName = item.ProjectName
668
-			inspection.InspectType = item.RangeType
669
-			inspection.InspectValue = item.Value
670
-			inspection.InspectDate = date
671
-			inspection.Status = 1
672
-			inspection.CreatedTime = time.Now().Unix()
673
-			inspection.UpdatedTime = time.Now().Unix()
674
-			addinsp = append(addinsp, inspection)
675
-		} else {
676
-			inspection := *inspMap[item.ID]
677
-			inspection.InspectValue = item.Value
678
-			inspection.InspectDate = date
679
-			inspection.UpdatedTime = time.Now().Unix()
680
-			editinsp = append(editinsp, inspection)
681
-			noMap = append(noMap, item.ID)
682
-		}
683
 
662
 
684
-	}
663
+		ref, _ := service.GetInspectionReferenceById(item.ItemId)
664
+		//if item.ID == 0 {
665
+		//	var inspection models.Inspection
666
+		//	inspection.OrgId = adminUserInfo.CurrentOrgId
667
+		//	inspection.PatientId = patient
668
+		//	inspection.ProjectId = from.ProjectId
669
+		//	inspection.ItemId = item.ItemId
670
+		//	inspection.ItemName = item.ItemName
671
+		//	inspection.ProjectName = item.ProjectName
672
+		//	inspection.InspectType = item.RangeType
673
+		//	inspection.InspectValue = item.Value
674
+		//	inspection.InspectDate = date
675
+		//	inspection.Status = 1
676
+		//	inspection.CreatedTime = time.Now().Unix()
677
+		//	inspection.UpdatedTime = time.Now().Unix()
678
+		//	addinsp = append(addinsp, inspection)
679
+		//} else {
680
+		//fmt.Println(item.ID)
681
+		a := strconv.FormatInt(item.ProjectId, 10) + "-" + strconv.FormatInt(ref.ItemId, 10)
682
+		fmt.Println(a)
683
+		fmt.Println(inspMap)
684
+
685
+		inspection := inspMap[a]
686
+		inspection.InspectValue = item.Value
687
+		inspection.InspectDate = date
688
+		inspection.UpdatedTime = time.Now().Unix()
689
+		editinsp = append(editinsp, inspection)
690
+		noMap = append(noMap, item.ID)
691
+		//}
685
 
692
 
693
+	}
694
+	//fmt.Println(editinsp)
695
+	//return
686
 	err = service.EditPatientInspection(addinsp, editinsp, noMap, patient, adminUserInfo.CurrentOrgId, from.ProjectId, date)
696
 	err = service.EditPatientInspection(addinsp, editinsp, noMap, patient, adminUserInfo.CurrentOrgId, from.ProjectId, date)
687
 	if err != nil {
697
 	if err != nil {
688
 		utils.ErrorLog("%v", err)
698
 		utils.ErrorLog("%v", err)
894
 
904
 
895
 	switch upload_type {
905
 	switch upload_type {
896
 	case 1:
906
 	case 1:
897
-		var inspections []*models.Inspection
907
+		var inspections []models.Inspection
898
 
908
 
899
 		for _, item := range ids {
909
 		for _, item := range ids {
900
 			id, _ := strconv.ParseInt(item, 10, 64)
910
 			id, _ := strconv.ParseInt(item, 10, 64)
933
 
943
 
934
 		break
944
 		break
935
 	case 3:
945
 	case 3:
936
-		var inspections []*models.Inspection
946
+		var inspections []models.Inspection
937
 
947
 
938
 		for _, item := range ids {
948
 		for _, item := range ids {
939
 			id, _ := strconv.ParseInt(item, 10, 64)
949
 			id, _ := strconv.ParseInt(item, 10, 64)
992
 
1002
 
993
 		break
1003
 		break
994
 	case 6:
1004
 	case 6:
995
-		var inspections []*models.Inspection
1005
+		var inspections []models.Inspection
996
 
1006
 
997
 		for _, item := range ids {
1007
 		for _, item := range ids {
998
 			id, _ := strconv.ParseInt(item, 10, 64)
1008
 			id, _ := strconv.ParseInt(item, 10, 64)
1015
 
1025
 
1016
 		break
1026
 		break
1017
 	case 7:
1027
 	case 7:
1018
-		var inspections []*models.Inspection
1028
+		var inspections []models.Inspection
1019
 
1029
 
1020
 		for _, item := range ids {
1030
 		for _, item := range ids {
1021
 			id, _ := strconv.ParseInt(item, 10, 64)
1031
 			id, _ := strconv.ParseInt(item, 10, 64)

+ 9 - 3
service/inspection_service.go View File

33
 	return
33
 	return
34
 }
34
 }
35
 
35
 
36
-func GetPatientInspectionByDate(orgId, patientId, date, projectId int64) (inspections []*models.Inspection, err error) {
36
+func GetPatientInspectionByDate(orgId, patientId, date, projectId int64) (inspections []models.Inspection, err error) {
37
 	err = readDb.Model(&models.Inspection{}).Where("patient_id=? and org_id=? and project_id =? and inspect_date =? and status=1", patientId, orgId, projectId, date).Order("created_time desc").Find(&inspections).Error
37
 	err = readDb.Model(&models.Inspection{}).Where("patient_id=? and org_id=? and project_id =? and inspect_date =? and status=1", patientId, orgId, projectId, date).Order("created_time desc").Find(&inspections).Error
38
 	return
38
 	return
39
 }
39
 }
153
 	return
153
 	return
154
 }
154
 }
155
 
155
 
156
-func GetPatientInspections(orgId, patientId, projectId, page int64) (inspections []*models.Inspection, total int64, date int64, err error) {
156
+func GetPatientInspections(orgId, patientId, projectId, page int64) (inspections []models.Inspection, total int64, date int64, err error) {
157
 	var projectCount models.UserInspectionProjectCount
157
 	var projectCount models.UserInspectionProjectCount
158
 	err = readDb.Model(&models.Inspection{}).Where("patient_id=? and org_id=? and project_id=? and status=1", patientId, orgId, projectId).Select("count(distinct inspect_date) as count, project_id, patient_id").Order("inspect_date desc").Scan(&projectCount).Error
158
 	err = readDb.Model(&models.Inspection{}).Where("patient_id=? and org_id=? and project_id=? and status=1", patientId, orgId, projectId).Select("count(distinct inspect_date) as count, project_id, patient_id").Order("inspect_date desc").Scan(&projectCount).Error
159
 	if err != nil {
159
 	if err != nil {
218
 	return
218
 	return
219
 }
219
 }
220
 
220
 
221
-func GetAllPatientInspection(orgId, patientId, page int64, projectId int64, start_time int64, end_time int64) (inspections []*models.Inspection, date int64, err error) {
221
+func GetAllPatientInspection(orgId, patientId, page int64, projectId int64, start_time int64, end_time int64) (inspections []models.Inspection, date int64, err error) {
222
 
222
 
223
 	//var projectCount models.UserInspectionProjectCount
223
 	//var projectCount models.UserInspectionProjectCount
224
 	//err = readDb.Model(&models.Inspection{}).Where("patient_id=? and org_id=? and project_id in (?)  and status=1", patientId, orgId,projectId).Select("count(distinct inspect_date) as count, project_id, patient_id").Scan(&projectCount).Error
224
 	//err = readDb.Model(&models.Inspection{}).Where("patient_id=? and org_id=? and project_id in (?)  and status=1", patientId, orgId,projectId).Select("count(distinct inspect_date) as count, project_id, patient_id").Scan(&projectCount).Error
263
 	return insepciton, err
263
 	return insepciton, err
264
 }
264
 }
265
 
265
 
266
+func GetInspectionReferenceById(id int64) (insepciton models.XtInspectionReference, err error) {
267
+
268
+	err = readDb.Model(&insepciton).Where("id = ?", id).First(&insepciton).Error
269
+	return insepciton, err
270
+}
271
+
266
 func GetInspectionReferenceTwo(project_id int64) (reference []*models.InspectionReference, err error) {
272
 func GetInspectionReferenceTwo(project_id int64) (reference []*models.InspectionReference, err error) {
267
 	err = readDb.Model(&models.InspectionReference{}).Where("project_id = ? and status = 1", project_id).Order("project_id").Find(&reference).Error
273
 	err = readDb.Model(&models.InspectionReference{}).Where("project_id = ? and status = 1", project_id).Order("project_id").Find(&reference).Error
268
 	return
274
 	return