Bladeren bron

11月8日库存管理

XMLWAN 3 jaren geleden
bovenliggende
commit
5cfa7ec060
2 gewijzigde bestanden met toevoegingen van 70 en 5 verwijderingen
  1. 28 4
      controllers/schedule_api_controller.go
  2. 42 1
      service/schedule_service.go

+ 28 - 4
controllers/schedule_api_controller.go Bestand weergeven

@@ -949,6 +949,7 @@ func Struct2Map(obj interface{}) map[string]interface{} {
949 949
 }
950 950
 
951 951
 func (this *ScheduleApiController) ExportSchedule() {
952
+
952 953
 	dataBody := make(map[string]interface{}, 0)
953 954
 	err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
954 955
 	if err != nil {
@@ -964,6 +965,20 @@ func (this *ScheduleApiController) ExportSchedule() {
964 965
 
965 966
 	patients, _, _ = service.GetAllPatientList(this.GetAdminUserInfo().CurrentOrgId)
966 967
 
968
+	start_time := dataBody["start_time"].(string)
969
+
970
+	end_time := dataBody["end_time"].(string)
971
+
972
+	delete_type := int64(dataBody["delete_type"].(float64))
973
+
974
+	timeLayout := "2006-01-02"
975
+	loc, _ := time.LoadLocation("Local")
976
+	theTimeStart, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
977
+	theTimeEnd, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 00:00:00", loc)
978
+
979
+	fmt.Println("theTimeStart23232322332322323", theTimeStart.Unix())
980
+	fmt.Println("theTimeStart23232322332322323", theTimeEnd.Unix())
981
+
967 982
 	if dataBody["failed_schedule"] != nil || reflect.TypeOf(dataBody["failed_schedule"]).String() == "[]interface {}" {
968 983
 		tempSchedule := dataBody["failed_schedule"].([]interface{})
969 984
 		failed_total = len(tempSchedule)
@@ -1403,15 +1418,24 @@ func (this *ScheduleApiController) ExportSchedule() {
1403 1418
 			//clear_schedule_date := date.Unix() //根据日期去清除,该日期未来的排班数据
1404 1419
 			//err := service.UpdateScheduleStatus(clear_schedule_date, this.GetAdminUserInfo().CurrentOrgId)
1405 1420
 			if err == nil {
1421
+				//清除该机构的排班
1422
+				if delete_type == 1 {
1423
+					service.ModeScheduleByTimeOne(theTimeStart.Unix(), theTimeEnd.Unix(), this.GetAdminUserInfo().CurrentOrgId)
1424
+				}
1425
+				if delete_type == 0 {
1426
+					service.ModeScheduleByTime(theTimeStart.Unix(), theTimeEnd.Unix(), this.GetAdminUserInfo().CurrentOrgId)
1427
+				}
1428
+
1406 1429
 				for _, item := range schedules {
1407 1430
 					//删除当天的日期排班
1408
-					service.DeleteScheduleExist(item.ScheduleDate, item.UserOrgId)
1431
+					/*service.DeleteScheduleExist(item.ScheduleDate, item.UserOrgId)*/
1409 1432
 					//查找当天日期是否存在
1410
-					_, errcode := service.GetTodayScheduleIsExist(item.PatientId, item.ScheduleDate, item.UserOrgId, item.ModeId, item.ScheduleType)
1433
+					_, errcode := service.GetTodayScheduleIsExistOne(item.PatientId, item.ScheduleDate, item.UserOrgId)
1411 1434
 					if errcode == gorm.ErrRecordNotFound {
1435
+						//清除当天该床位已有的患者
1436
+						// service.ModeFyScheduleById(item.ScheduleDate,item.BedId,item.ScheduleType)
1412 1437
 						service.CreateSchedule(item)
1413 1438
 					} else if errcode == nil {
1414
-
1415 1439
 						schedule := models.XtSchedule{
1416 1440
 							PartitionId:  item.PartitionId,
1417 1441
 							BedId:        item.BedId,
@@ -1423,7 +1447,7 @@ func (this *ScheduleApiController) ExportSchedule() {
1423 1447
 							Status:       1,
1424 1448
 						}
1425 1449
 
1426
-						service.UpdateScheduleByOrgId(item.PatientId, item.ScheduleDate, item.UserOrgId, item.ModeId, item.ScheduleType, &schedule)
1450
+						service.UpdateScheduleByOrgIdOne(item.PatientId, item.ScheduleDate, item.UserOrgId, &schedule)
1427 1451
 					}
1428 1452
 
1429 1453
 				}

+ 42 - 1
service/schedule_service.go Bestand weergeven

@@ -169,7 +169,7 @@ func CreateSchedule(m *models.Schedule) error {
169 169
 
170 170
 func DeleteScheduleExist(scheduleData int64, user_org_id int64) (models.XtSchedule, error) {
171 171
 	schedule := models.XtSchedule{}
172
-	err := XTWriteDB().Where("schedule_date= ? and user_org_id = ? and status = 1", scheduleData, user_org_id).Updates(map[string]interface{}{"status": 0}).Error
172
+	err := XTWriteDB().Model(&schedule).Where("schedule_date= ? and user_org_id = ? and status = 1", scheduleData, user_org_id).Updates(map[string]interface{}{"status": 0}).Error
173 173
 	return schedule, err
174 174
 }
175 175
 
@@ -186,11 +186,52 @@ func GetTodayScheduleIsExist(patientid int64, schedudate int64, orgid int64, mod
186 186
 	return &scheudle, nil
187 187
 }
188 188
 
189
+func GetTodayScheduleIsExistOne(patientid int64, schedudate int64, orgid int64) (*models.XtSchedule, error) {
190
+	var scheudle models.XtSchedule
191
+	var err error
192
+	err = XTReadDB().Model(&scheudle).Where("patient_id = ? and schedule_date= ? and user_org_id = ? and status = 1", patientid, schedudate, orgid).Find(&scheudle).Error
193
+	if err == gorm.ErrRecordNotFound {
194
+		return nil, err
195
+	}
196
+	if err != nil {
197
+		return nil, err
198
+	}
199
+	return &scheudle, nil
200
+}
201
+
202
+func ModeFyScheduleById(schedule_date int64, bedid int64, scheduletype int64) error {
203
+
204
+	schedule := models.XtSchedule{}
205
+	err := XTWriteDB().Model(&schedule).Where("schedule_date = ? and bed_id =? and schedule_type = ? and status = 1", schedule_date, bedid, scheduletype).Updates(map[string]interface{}{"status": 0}).Error
206
+	return err
207
+}
208
+
209
+func ModeScheduleByTime(startime int64, endtime int64, orgid int64) error {
210
+
211
+	schedule := models.XtSchedule{}
212
+
213
+	err := XTWriteDB().Model(&schedule).Where("schedule_date >? and schedule_date<=? and status = 1 and user_org_id = ?", startime, endtime, orgid).Updates(map[string]interface{}{"status": 0}).Error
214
+	return err
215
+}
216
+
217
+func ModeScheduleByTimeOne(startime int64, endtime int64, orgid int64) error {
218
+
219
+	schedule := models.XtSchedule{}
220
+
221
+	err := XTWriteDB().Model(&schedule).Where("schedule_date >=? and schedule_date<=? and status = 1 and user_org_id = ?", startime, endtime, orgid).Updates(map[string]interface{}{"status": 0}).Error
222
+	return err
223
+}
224
+
189 225
 func UpdateScheduleByOrgId(patientid int64, scheduledate int64, orgid int64, mode_id int64, schedule_type int64, sch *models.XtSchedule) error {
190 226
 	err := XTWriteDB().Model(&sch).Where("patient_id = ? and schedule_date= ? and user_org_id = ? and status = 1 and mode_id = ? and schedule_type = ?", patientid, scheduledate, orgid, mode_id, schedule_type).Updates(map[string]interface{}{"partition_id": sch.PartitionId, "bed_id": sch.BedId, "schedule_type": sch.ScheduleType, "schedule_week": sch.ScheduleWeek, "mode_id": sch.ModeId, "updated_time": time.Now().Unix()}).Error
191 227
 	return err
192 228
 }
193 229
 
230
+func UpdateScheduleByOrgIdOne(patientid int64, scheduledate int64, orgid int64, sch *models.XtSchedule) error {
231
+	err := XTWriteDB().Model(&sch).Where("patient_id = ? and schedule_date= ? and user_org_id = ? and status = 1", patientid, scheduledate, orgid).Updates(map[string]interface{}{"partition_id": sch.PartitionId, "bed_id": sch.BedId, "schedule_type": sch.ScheduleType, "schedule_week": sch.ScheduleWeek, "mode_id": sch.ModeId, "updated_time": time.Now().Unix()}).Error
232
+	return err
233
+}
234
+
194 235
 func GetSchedule(orgID, id int64) (*models.Schedule, error) {
195 236
 	var schedule models.Schedule
196 237
 	var err error