陈少旭 1 gadu atpakaļ
vecāks
revīzija
7fb48fa895
2 mainītis faili ar 54 papildinājumiem un 0 dzēšanām
  1. 36 0
      controllers/schedule_api_controller.go
  2. 18 0
      service/schedule_service.go

+ 36 - 0
controllers/schedule_api_controller.go Parādīt failu

@@ -130,6 +130,11 @@ func (c *ScheduleApiController) CoverSch() {
130 130
 	if err == nil {
131 131
 		err2 := service.SaveSch(&new_sch)
132 132
 		if err2 == nil {
133
+			//去除当天患者排班中重复数据,保留最后一条数据
134
+			service.UpdateRepeatSchStatus(sch.UserOrgId, sch.ScheduleDate)
135
+			service.UpdateRepeatSchStatus(sch_two.UserOrgId, sch_two.ScheduleDate)
136
+			service.UpdateRepeatSchStatus(new_sch.UserOrgId, new_sch.ScheduleDate)
137
+
133 138
 			c.ServeSuccessJSON(map[string]interface{}{
134 139
 				"msg":     "覆盖成功",
135 140
 				"new_sch": new_sch,
@@ -176,6 +181,11 @@ func (c *ScheduleApiController) ExchangeSch() {
176 181
 
177 182
 	err := service.UpdateScheduleThree(sch, sch_two)
178 183
 	if err == nil {
184
+
185
+		//去除当天患者排班中重复数据,保留最后一条数据
186
+		service.UpdateRepeatSchStatus(sch.UserOrgId, sch.ScheduleDate)
187
+		service.UpdateRepeatSchStatus(sch_two.UserOrgId, sch_two.ScheduleDate)
188
+
179 189
 		c.ServeSuccessJSON(map[string]interface{}{
180 190
 			"msg": "交换成功",
181 191
 		})
@@ -684,8 +694,13 @@ func (c *ScheduleApiController) BatchPostSmartSch() {
684 694
 					service.SaveSch(&schedule)
685 695
 				}
686 696
 				HandleRedis(adminInfo.CurrentOrgId, schedule.ScheduleDate)
697
+				//去除当天患者排班中重复数据,保留最后一条数据
698
+				service.UpdateRepeatSchStatus(adminInfo.CurrentOrgId, schedule.ScheduleDate)
699
+
687 700
 			}
701
+
688 702
 		}
703
+
689 704
 	}
690 705
 	////修改或保存数据
691 706
 	if dataBody["smart_schs"] != nil && reflect.TypeOf(dataBody["smart_schs"]).String() == "[]interface {}" {
@@ -835,6 +850,10 @@ func (c *ScheduleApiController) BatchPostSmartSch() {
835 850
 					schedule.DialysisMachineName = DialysisMachineName
836 851
 					schedule.IsExport = 3000
837 852
 					service.SaveSch(&schedule)
853
+
854
+					//去除当天患者排班中重复数据,保留最后一条数据
855
+					service.UpdateRepeatSchStatus(schedule.UserOrgId, schedule.ScheduleDate)
856
+
838 857
 				} else { //新的排班信息
839 858
 
840 859
 					if items["schedule_date"] == nil || reflect.TypeOf(items["schedule_date"]).String() != "string" {
@@ -1024,6 +1043,9 @@ func (c *ScheduleApiController) BatchPostSmartSch() {
1024 1043
 					}
1025 1044
 				}
1026 1045
 
1046
+				//去除当天患者排班中重复数据,保留最后一条数据
1047
+				service.UpdateRepeatSchStatus(schedule.UserOrgId, schedule.ScheduleDate)
1048
+
1027 1049
 				c.ServeSuccessJSON(map[string]interface{}{
1028 1050
 					"msg": "保存成功",
1029 1051
 				})
@@ -1608,6 +1630,8 @@ func (c *ScheduleApiController) CreateSchedule() {
1608 1630
 	}
1609 1631
 	schedule.Patient = patientInfo.Name
1610 1632
 
1633
+	service.UpdateRepeatSchStatus(schedule.UserOrgId, schedule.ScheduleDate)
1634
+
1611 1635
 	c.ServeSuccessJSON(map[string]interface{}{
1612 1636
 		"msg":      "ok",
1613 1637
 		"schedule": schedule,
@@ -1867,6 +1891,10 @@ func (c *ScheduleApiController) CreateScheduleTwo() {
1867 1891
 		redis.Set(keySeven, "", time.Second)
1868 1892
 		defer redis.Close()
1869 1893
 		schedule.Patient = patientInfo.Name
1894
+
1895
+		//去除当天患者排班中重复数据,保留最后一条数据
1896
+		service.UpdateRepeatSchStatus(schedule.UserOrgId, schedule.ScheduleDate)
1897
+
1870 1898
 		c.ServeSuccessJSON(map[string]interface{}{
1871 1899
 			"msg":          "ok",
1872 1900
 			"schedule":     schedule,
@@ -2197,6 +2225,8 @@ func (c *ScheduleApiController) ChangeSchedule() {
2197 2225
 			c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeChangeScheduleFail)
2198 2226
 			return
2199 2227
 		}
2228
+		service.UpdateRepeatSchStatus(schedule.UserOrgId, schedule.ScheduleDate)
2229
+
2200 2230
 		c.ServeSuccessJSON(map[string]interface{}{
2201 2231
 			"msg":      "ok",
2202 2232
 			"schedule": &schedule,
@@ -2208,6 +2238,8 @@ func (c *ScheduleApiController) ChangeSchedule() {
2208 2238
 			c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeChangeScheduleFail)
2209 2239
 			return
2210 2240
 		}
2241
+		service.UpdateRepeatSchStatus(schedule.UserOrgId, schedule.ScheduleDate)
2242
+
2211 2243
 		c.ServeSuccessJSON(map[string]interface{}{
2212 2244
 			"msg":      "ok",
2213 2245
 			"schedule": &schedule,
@@ -5164,7 +5196,11 @@ func (c *ScheduleApiController) ChangeScheduleTen() {
5164 5196
 
5165 5197
 		}
5166 5198
 	}
5199
+	//去除当天患者排班中重复数据,保留最后一条数据
5200
+	service.UpdateRepeatSchStatus(schedule.UserOrgId, schedule.ScheduleDate)
5201
+
5167 5202
 	scheduletwo, _ := service.GetSchedule(adminINfo.CurrentOrgId, id)
5203
+
5168 5204
 	c.ServeSuccessJSON(map[string]interface{}{
5169 5205
 		"msg":      "ok",
5170 5206
 		"schedule": scheduletwo,

+ 18 - 0
service/schedule_service.go Parādīt failu

@@ -1739,3 +1739,21 @@ func GetLastSchedule(patient_id int64, user_org_id int64) (models.XtSchedule, er
1739 1739
 	err := XTReadDB().Where("patient_id = ? and status =1 and user_org_id = ?", patient_id, user_org_id).Find(&schedule).Error
1740 1740
 	return schedule, err
1741 1741
 }
1742
+
1743
+func UpdateRepeatSchStatus(user_org_id int64, schedule_date int64) {
1744
+	var schedules []models.XtSchedule
1745
+	// Find duplicate records based on patient_id, schedule_date, and user_org_id
1746
+	XTReadDB().Where("user_org_id = ? AND schedule_date = ? AND status = ?", user_org_id, schedule_date, 1).
1747
+		Group("patient_id, schedule_date").
1748
+		Having("COUNT(*) > 1").
1749
+		Select("patient_id, schedule_date, MAX(id) as max_id").
1750
+		Find(&schedules)
1751
+
1752
+	for _, schedule := range schedules {
1753
+		// Update records with status = 0 where id is less than max_id
1754
+		XTReadDB().Model(&models.XtSchedule{}).
1755
+			Where("patient_id = ? AND schedule_date = ? AND id < ?", schedule.PatientId, schedule.ScheduleDate, schedule.MaxId).
1756
+			Update("status", 0)
1757
+	}
1758
+
1759
+}