package controllers import ( "XT_New/enums" "XT_New/models" "XT_New/service" "encoding/json" "fmt" "strconv" "strings" "time" "github.com/astaxie/beego" ) func PatientScheduleTemplateAPIControllerRegistRouters() { beego.Router("/api/schtemp/p/initdata", &PatientScheduleTemplateAPIController{}, "get:InitData") beego.Router("/api/schtemp/p/setmode", &PatientScheduleTemplateAPIController{}, "post:SetMode") beego.Router("/api/schtemp/p/update_sch", &PatientScheduleTemplateAPIController{}, "post:UpdateSchedules") beego.Router("/api/patients/list", &PatientScheduleTemplateAPIController{}, "get:GetPatientList") beego.Router("/api/schedule/update_schtemplate", &PatientScheduleTemplateAPIController{}, "post:UpdateSchedulesTemplate") beego.Router("/api/schtemplate_device/get", &ScheduleApiController{}, "Get:GetTemplateDevicesNumbers") beego.Router("/api/schtemplate/exchange", &ScheduleApiController{}, "Get:ExchangeSchTemplate") beego.Router("/api/schtemplate/coversch", &ScheduleApiController{}, "Get:CoverSchTemplate") beego.Router("/api/schtemplate/change", &ScheduleApiController{}, "post:DeleteAndAddScheduleTemplateTwo") beego.Router("/api/schtemplate/save", &ScheduleApiController{}, "post:SaveSchTemplate") } func (c *ScheduleApiController) SaveSchTemplate() { templates, _ := service.GetOrgPatientScheduleTemplateIDs(c.GetAdminUserInfo().CurrentOrgId) mode, _ := service.GetPatientScheduleTempalate(c.GetAdminUserInfo().CurrentOrgId) t := time.Now() yearDay := t.YearDay() yearFirstDay := t.AddDate(0, 0, -yearDay+1) firstDayInWeek := int(yearFirstDay.Weekday()) //今年第一周有几天 firstWeekDays := 1 if firstDayInWeek != 0 { firstWeekDays = 7 - firstDayInWeek + 1 } var week int if yearDay <= firstWeekDays { week = 1 } else { week = (yearDay-firstWeekDays)/7 + 2 } var schedules []models.Schedule fmt.Println(week) if mode.Mode == 1 { for _, item := range templates { if item.Week > 0 { timeArr := WeekIntervalTime(0) //获取本周的周一到周日 nextTimeArr := WeekIntervalTime(1) //获取下周的周一到周日 nextnextTimeArr := WeekIntervalTime(2) //获取下下周的周一到周日 t := time.Now() week_day, _ := strconv.Atoi(t.Weekday().String()) if week_day == 0 { week_day = 7 } items, _ := service.GetTemplateListByTemplateId(item.ID, item.OrgID) //处理本周,先判断当前属于周几 for _, item := range items { var schedule models.Schedule if int(item.Weekday) > week_day { schedule.IsExport = 400000 var DialysisMachineName string so, _ := service.GetDialysisSolutionTwo(item.OrgID, item.PatientID, item.TreatMode) filedRecordOne, _ := service.FindFiledBy(item.OrgID, "透析器") filedRecordTwo, _ := service.FindFiledBy(item.OrgID, "灌流器") filedRecordThree, _ := service.FindFiledBy(item.OrgID, "透析器/灌流器") if filedRecordOne.IsShow == 1 { DialysisMachineName = so.DialysisDialyszers } if filedRecordThree.IsShow == 1 { if len(DialysisMachineName) > 0 { DialysisMachineName = DialysisMachineName + "*" + so.DialyzerPerfusionApparatus } else { DialysisMachineName = so.DialyzerPerfusionApparatus } } if filedRecordTwo.IsShow == 1 { if len(DialysisMachineName) > 0 { DialysisMachineName = DialysisMachineName + "*" + so.DialysisIrrigation } else { DialysisMachineName = so.DialysisIrrigation } } schedule.DialysisMachineName = DialysisMachineName schedule.ScheduleType = item.TimeType schedule.ModeId = item.TreatMode schedule.ScheduleWeek = item.Weekday schedule.BedId = item.DeviceNumberID formatTime, _ := time.Parse("2006-01-02", timeArr[int(item.Weekday)]) schedule.ScheduleDate = formatTime.Unix() schedule.UserOrgId = item.OrgID schedule.Status = 1 schedule.CreatedTime = time.Now().Unix() schedule.UpdatedTime = time.Now().Unix() device, _ := service.GetDeviceByID(item.OrgID, item.DeviceNumberID) schedule.PartitionId = device.DeviceZoneID schedules = append(schedules, schedule) } } //处理下周 for _, item := range items { var schedule models.Schedule schedule.IsExport = 400000 var DialysisMachineName string so, _ := service.GetDialysisSolutionTwo(item.OrgID, item.PatientID, item.TreatMode) filedRecordOne, _ := service.FindFiledBy(item.OrgID, "透析器") filedRecordTwo, _ := service.FindFiledBy(item.OrgID, "灌流器") filedRecordThree, _ := service.FindFiledBy(item.OrgID, "透析器/灌流器") if filedRecordOne.IsShow == 1 { DialysisMachineName = so.DialysisDialyszers } if filedRecordThree.IsShow == 1 { if len(DialysisMachineName) > 0 { DialysisMachineName = DialysisMachineName + "*" + so.DialyzerPerfusionApparatus } else { DialysisMachineName = so.DialyzerPerfusionApparatus } } if filedRecordTwo.IsShow == 1 { if len(DialysisMachineName) > 0 { DialysisMachineName = DialysisMachineName + "*" + so.DialysisIrrigation } else { DialysisMachineName = so.DialysisIrrigation } } schedule.DialysisMachineName = DialysisMachineName schedule.ScheduleType = item.TimeType schedule.ModeId = item.TreatMode schedule.ScheduleWeek = item.Weekday schedule.BedId = item.DeviceNumberID formatTime, _ := time.Parse("2006-01-02", nextTimeArr[int(item.Weekday)]) schedule.ScheduleDate = formatTime.Unix() schedule.UserOrgId = item.OrgID schedule.Status = 1 schedule.CreatedTime = time.Now().Unix() schedule.UpdatedTime = time.Now().Unix() device, _ := service.GetDeviceByID(item.OrgID, item.DeviceNumberID) schedule.PartitionId = device.DeviceZoneID schedules = append(schedules, schedule) } //处理下下周,先判断当前属于周几 for _, item := range items { var schedule models.Schedule schedule.IsExport = 400000 var DialysisMachineName string so, _ := service.GetDialysisSolutionTwo(item.OrgID, item.PatientID, item.TreatMode) filedRecordOne, _ := service.FindFiledBy(item.OrgID, "透析器") filedRecordTwo, _ := service.FindFiledBy(item.OrgID, "灌流器") filedRecordThree, _ := service.FindFiledBy(item.OrgID, "透析器/灌流器") if filedRecordOne.IsShow == 1 { DialysisMachineName = so.DialysisDialyszers } if filedRecordThree.IsShow == 1 { if len(DialysisMachineName) > 0 { DialysisMachineName = DialysisMachineName + "*" + so.DialyzerPerfusionApparatus } else { DialysisMachineName = so.DialyzerPerfusionApparatus } } if filedRecordTwo.IsShow == 1 { if len(DialysisMachineName) > 0 { DialysisMachineName = DialysisMachineName + "*" + so.DialysisIrrigation } else { DialysisMachineName = so.DialysisIrrigation } } schedule.DialysisMachineName = DialysisMachineName schedule.ScheduleType = item.TimeType schedule.ModeId = item.TreatMode schedule.ScheduleWeek = item.Weekday schedule.BedId = item.DeviceNumberID formatTime, _ := time.Parse("2006-01-02", nextnextTimeArr[int(item.Weekday)]) schedule.ScheduleDate = formatTime.Unix() schedule.UserOrgId = item.OrgID schedule.Status = 1 schedule.CreatedTime = time.Now().Unix() schedule.UpdatedTime = time.Now().Unix() device, _ := service.GetDeviceByID(item.OrgID, item.DeviceNumberID) schedule.PartitionId = device.DeviceZoneID schedules = append(schedules, schedule) } } } } else if mode.Mode == 2 { for _, item := range templates { if item.Week > 0 { switch item.Week - week { case -1: //当前模板是上周的模板 ////根据模板类型,来判断需要修改哪几周数据,模板类型:单周模板,双周模板,三周模板,四周模板 ////如果是单周模板:则修改本周除了当天未来的数据,下周,下下周数据 ////如果是双周模板:则修改下周数据 ////如果是三周模板:则修改下下周数据 ////如果是四周模板:则不用修改数据 //nextTimeArr := WeekIntervalTime(1) //获取下周的周一到周日 //t := time.Now() //week_day,_ := strconv.Atoi(t.Weekday().String()) //if week_day == 0{ // week_day = 7 //} //items, _ := service.GetTemplateListByTemplateId(item.ID,item.OrgID) //var schedules []models.Schedule ////处理下周 //for _,item := range items{ // var schedule models.Schedule // schedule.IsExport = 400000 // var DialysisMachineName string // so, _ := service.GetDialysisSolutionTwo(item.OrgID, item.PatientID, item.TreatMode) // filedRecordOne, _ := service.FindFiledBy(item.OrgID, "透析器") // filedRecordTwo, _ := service.FindFiledBy(item.OrgID, "灌流器") // filedRecordThree, _ := service.FindFiledBy(item.OrgID, "透析器/灌流器") // if filedRecordOne.IsShow == 1 { // DialysisMachineName = so.DialysisDialyszers // } // if filedRecordThree.IsShow == 1 { // if len(DialysisMachineName) > 0 { // DialysisMachineName = DialysisMachineName + "*" + so.DialyzerPerfusionApparatus // } else { // DialysisMachineName = so.DialyzerPerfusionApparatus // } // } // if filedRecordTwo.IsShow == 1 { // if len(DialysisMachineName) > 0 { // DialysisMachineName = DialysisMachineName + "*" + so.DialysisIrrigation // } else { // DialysisMachineName = so.DialysisIrrigation // } // } // schedule.DialysisMachineName = DialysisMachineName // schedule.ScheduleType = item.TimeType // schedule.ModeId = item.TreatMode // schedule.ScheduleWeek = item.Weekday // schedule.BedId = item.DeviceNumberID // formatTime,_:=time.Parse("2006-01-02", nextTimeArr[int(item.Weekday)]) // schedule.ScheduleDate =formatTime.Unix() // schedule.UserOrgId = item.OrgID // schedule.Status = 1 // schedule.CreatedTime = time.Now().Unix() // schedule.UpdatedTime = time.Now().Unix() // device,_ := service.GetDeviceByID(item.OrgID,item.DeviceNumberID) // schedule.PartitionId = device.DeviceZoneID // schedules = append(schedules,schedule) //} break case 0: //当前修改的模板是本周的模板 //根据模板类型,来判断需要修改哪几周数据,模板类型:单周模板,双周模板,三周模板,四周模板 //如果是单周模板:则修改本周除了当天未来的数据,下周,下下周数据 //如果是双周模板:则修改下下周数据 //如果是三周模板:则修改本周除了当天未来的数据 //如果是四周模板:则修改本周除了当天未来的数据 //TimeArr :=WeekIntervalTime(0) t := time.Now() week_day, _ := strconv.Atoi(t.Weekday().String()) if week_day == 0 { week_day = 7 } timeArr := WeekIntervalTime(0) //获取本周的周一到周日 items_two, _ := service.GetTemplateListByTemplateId(item.ID, item.OrgID) //处理本周,先判断当前属于周几 for _, item := range items_two { var schedule models.Schedule if int(item.Weekday) > week_day { schedule.IsExport = 400000 var DialysisMachineName string so, _ := service.GetDialysisSolutionTwo(item.OrgID, item.PatientID, item.TreatMode) filedRecordOne, _ := service.FindFiledBy(item.OrgID, "透析器") filedRecordTwo, _ := service.FindFiledBy(item.OrgID, "灌流器") filedRecordThree, _ := service.FindFiledBy(item.OrgID, "透析器/灌流器") if filedRecordOne.IsShow == 1 { DialysisMachineName = so.DialysisDialyszers } if filedRecordThree.IsShow == 1 { if len(DialysisMachineName) > 0 { DialysisMachineName = DialysisMachineName + "*" + so.DialyzerPerfusionApparatus } else { DialysisMachineName = so.DialyzerPerfusionApparatus } } if filedRecordTwo.IsShow == 1 { if len(DialysisMachineName) > 0 { DialysisMachineName = DialysisMachineName + "*" + so.DialysisIrrigation } else { DialysisMachineName = so.DialysisIrrigation } } schedule.DialysisMachineName = DialysisMachineName schedule.ScheduleType = item.TimeType schedule.ModeId = item.TreatMode schedule.ScheduleWeek = item.Weekday schedule.BedId = item.DeviceNumberID formatTime, _ := time.Parse("2006-01-02", timeArr[int(item.Weekday)]) schedule.ScheduleDate = formatTime.Unix() schedule.UserOrgId = item.OrgID schedule.Status = 1 schedule.CreatedTime = time.Now().Unix() schedule.UpdatedTime = time.Now().Unix() device, _ := service.GetDeviceByID(item.OrgID, item.DeviceNumberID) schedule.PartitionId = device.DeviceZoneID schedules = append(schedules, schedule) } } nextnextTimeArr := WeekIntervalTime(2) //获取下下周的周一到周日 items, _ := service.GetTemplateListByTemplateId(item.ID, item.OrgID) //处理下下周 for _, item := range items { var schedule models.Schedule schedule.IsExport = 400000 var DialysisMachineName string so, _ := service.GetDialysisSolutionTwo(item.OrgID, item.PatientID, item.TreatMode) filedRecordOne, _ := service.FindFiledBy(item.OrgID, "透析器") filedRecordTwo, _ := service.FindFiledBy(item.OrgID, "灌流器") filedRecordThree, _ := service.FindFiledBy(item.OrgID, "透析器/灌流器") if filedRecordOne.IsShow == 1 { DialysisMachineName = so.DialysisDialyszers } if filedRecordThree.IsShow == 1 { if len(DialysisMachineName) > 0 { DialysisMachineName = DialysisMachineName + "*" + so.DialyzerPerfusionApparatus } else { DialysisMachineName = so.DialyzerPerfusionApparatus } } if filedRecordTwo.IsShow == 1 { if len(DialysisMachineName) > 0 { DialysisMachineName = DialysisMachineName + "*" + so.DialysisIrrigation } else { DialysisMachineName = so.DialysisIrrigation } } schedule.DialysisMachineName = DialysisMachineName schedule.ScheduleType = item.TimeType schedule.ModeId = item.TreatMode schedule.ScheduleWeek = item.Weekday schedule.BedId = item.DeviceNumberID formatTime, _ := time.Parse("2006-01-02", nextnextTimeArr[int(item.Weekday)]) schedule.ScheduleDate = formatTime.Unix() schedule.UserOrgId = item.OrgID schedule.Status = 1 schedule.CreatedTime = time.Now().Unix() schedule.UpdatedTime = time.Now().Unix() device, _ := service.GetDeviceByID(item.OrgID, item.DeviceNumberID) schedule.PartitionId = device.DeviceZoneID schedules = append(schedules, schedule) } break case 1: //当前修改的模板是本周的模板 //根据模板类型,来判断需要修改哪几周数据,模板类型:单周模板,双周模板,三周模板,四周模板 //如果是单周模板:则修改本周除了当天未来的数据,下周,下下周数据 //如果是双周模板:则修改下下周数据 //如果是三周模板:则修改本周除了当天未来的数据 //如果是四周模板:则修改本周除了当天未来的数据 //TimeArr :=WeekIntervalTime(0) nextTimeArr := WeekIntervalTime(1) //获取下下周的周一到周日 t := time.Now() week_day, _ := strconv.Atoi(t.Weekday().String()) if week_day == 0 { week_day = 7 } items, _ := service.GetTemplateListByTemplateId(item.ID, item.OrgID) //处理下下周 for _, item := range items { var schedule models.Schedule schedule.IsExport = 400000 var DialysisMachineName string so, _ := service.GetDialysisSolutionTwo(item.OrgID, item.PatientID, item.TreatMode) filedRecordOne, _ := service.FindFiledBy(item.OrgID, "透析器") filedRecordTwo, _ := service.FindFiledBy(item.OrgID, "灌流器") filedRecordThree, _ := service.FindFiledBy(item.OrgID, "透析器/灌流器") if filedRecordOne.IsShow == 1 { DialysisMachineName = so.DialysisDialyszers } if filedRecordThree.IsShow == 1 { if len(DialysisMachineName) > 0 { DialysisMachineName = DialysisMachineName + "*" + so.DialyzerPerfusionApparatus } else { DialysisMachineName = so.DialyzerPerfusionApparatus } } if filedRecordTwo.IsShow == 1 { if len(DialysisMachineName) > 0 { DialysisMachineName = DialysisMachineName + "*" + so.DialysisIrrigation } else { DialysisMachineName = so.DialysisIrrigation } } schedule.DialysisMachineName = DialysisMachineName schedule.ScheduleType = item.TimeType schedule.ModeId = item.TreatMode schedule.ScheduleWeek = item.Weekday schedule.BedId = item.DeviceNumberID formatTime, _ := time.Parse("2006-01-02", nextTimeArr[int(item.Weekday)]) schedule.ScheduleDate = formatTime.Unix() schedule.UserOrgId = item.OrgID schedule.Status = 1 schedule.CreatedTime = time.Now().Unix() schedule.UpdatedTime = time.Now().Unix() device, _ := service.GetDeviceByID(item.OrgID, item.DeviceNumberID) schedule.PartitionId = device.DeviceZoneID schedules = append(schedules, schedule) } break case 2: //当前修改的模板是下下周的模板 //根据模板类型,来判断需要修改哪几周数据,模板类型:单周模板,双周模板,三周模板,四周模板 //如果是单周模板:则修改本周除了当天未来的数据,下周,下下周数据 //如果是双周模板:则修改本周数据,下下周数据 //如果是三周模板:则修改下下周的数据 //如果是四周模板:则修改本周除了当天未来的数据 //nextTwoTimeArr :=WeekIntervalTime(2) timeArr := WeekIntervalTime(0) //获取本周的周一到周日 t := time.Now() week_day, _ := strconv.Atoi(t.Weekday().String()) if week_day == 0 { week_day = 7 } items, _ := service.GetTemplateListByTemplateId(item.ID, item.OrgID) var schedules []models.Schedule //处理本周,先判断当前属于周几 for _, item := range items { var schedule models.Schedule if int(item.Weekday) > week_day { schedule.IsExport = 400000 var DialysisMachineName string so, _ := service.GetDialysisSolutionTwo(item.OrgID, item.PatientID, item.TreatMode) filedRecordOne, _ := service.FindFiledBy(item.OrgID, "透析器") filedRecordTwo, _ := service.FindFiledBy(item.OrgID, "灌流器") filedRecordThree, _ := service.FindFiledBy(item.OrgID, "透析器/灌流器") if filedRecordOne.IsShow == 1 { DialysisMachineName = so.DialysisDialyszers } if filedRecordThree.IsShow == 1 { if len(DialysisMachineName) > 0 { DialysisMachineName = DialysisMachineName + "*" + so.DialyzerPerfusionApparatus } else { DialysisMachineName = so.DialyzerPerfusionApparatus } } if filedRecordTwo.IsShow == 1 { if len(DialysisMachineName) > 0 { DialysisMachineName = DialysisMachineName + "*" + so.DialysisIrrigation } else { DialysisMachineName = so.DialysisIrrigation } } schedule.DialysisMachineName = DialysisMachineName schedule.ScheduleType = item.TimeType schedule.ModeId = item.TreatMode schedule.ScheduleWeek = item.Weekday schedule.BedId = item.DeviceNumberID formatTime, _ := time.Parse("2006-01-02", timeArr[int(item.Weekday)]) schedule.ScheduleDate = formatTime.Unix() schedule.UserOrgId = item.OrgID schedule.Status = 1 schedule.CreatedTime = time.Now().Unix() schedule.UpdatedTime = time.Now().Unix() device, _ := service.GetDeviceByID(item.OrgID, item.DeviceNumberID) schedule.PartitionId = device.DeviceZoneID schedules = append(schedules, schedule) } } nextnextTimeArr := WeekIntervalTime(2) //获取下下周的周一到周日 items_two, _ := service.GetTemplateListByTemplateId(item.ID, item.OrgID) //处理下下周 for _, item := range items_two { var schedule models.Schedule schedule.IsExport = 400000 var DialysisMachineName string so, _ := service.GetDialysisSolutionTwo(item.OrgID, item.PatientID, item.TreatMode) filedRecordOne, _ := service.FindFiledBy(item.OrgID, "透析器") filedRecordTwo, _ := service.FindFiledBy(item.OrgID, "灌流器") filedRecordThree, _ := service.FindFiledBy(item.OrgID, "透析器/灌流器") if filedRecordOne.IsShow == 1 { DialysisMachineName = so.DialysisDialyszers } if filedRecordThree.IsShow == 1 { if len(DialysisMachineName) > 0 { DialysisMachineName = DialysisMachineName + "*" + so.DialyzerPerfusionApparatus } else { DialysisMachineName = so.DialyzerPerfusionApparatus } } if filedRecordTwo.IsShow == 1 { if len(DialysisMachineName) > 0 { DialysisMachineName = DialysisMachineName + "*" + so.DialysisIrrigation } else { DialysisMachineName = so.DialysisIrrigation } } schedule.DialysisMachineName = DialysisMachineName schedule.ScheduleType = item.TimeType schedule.ModeId = item.TreatMode schedule.ScheduleWeek = item.Weekday schedule.BedId = item.DeviceNumberID formatTime, _ := time.Parse("2006-01-02", nextnextTimeArr[int(item.Weekday)]) schedule.ScheduleDate = formatTime.Unix() schedule.UserOrgId = item.OrgID schedule.Status = 1 schedule.CreatedTime = time.Now().Unix() schedule.UpdatedTime = time.Now().Unix() device, _ := service.GetDeviceByID(item.OrgID, item.DeviceNumberID) schedule.PartitionId = device.DeviceZoneID schedules = append(schedules, schedule) } break } } } } else if mode.Mode == 3 { for _, item := range templates { if item.Week > 0 { switch item.Week - week { //case -1: // //当前模板是上周的模板 // //根据模板类型,来判断需要修改哪几周数据,模板类型:单周模板,双周模板,三周模板,四周模板 // //如果是单周模板:则修改本周除了当天未来的数据,下周,下下周数据 // //如果是双周模板:则修改下周数据 // //如果是三周模板:则修改下下周数据 // //如果是四周模板:则不用修改数据 // //TimeArr :=WeekIntervalTime(0) // nextnextTimeArr := WeekIntervalTime(2) //获取下下周的周一到周日 // t := time.Now() // week_day,_ := strconv.Atoi(t.Weekday().String()) // if week_day == 0{ // week_day = 7 // } // items, _ := service.GetTemplateListByTemplateId(item.ID,item.OrgID) // var schedules []models.Schedule // //处理下周 // for _,item := range items{ // var schedule models.Schedule // schedule.IsExport = 400000 // var DialysisMachineName string // so, _ := service.GetDialysisSolutionTwo(item.OrgID, item.PatientID, item.TreatMode) // filedRecordOne, _ := service.FindFiledBy(item.OrgID, "透析器") // filedRecordTwo, _ := service.FindFiledBy(item.OrgID, "灌流器") // filedRecordThree, _ := service.FindFiledBy(item.OrgID, "透析器/灌流器") // if filedRecordOne.IsShow == 1 { // DialysisMachineName = so.DialysisDialyszers // } // if filedRecordThree.IsShow == 1 { // if len(DialysisMachineName) > 0 { // DialysisMachineName = DialysisMachineName + "*" + so.DialyzerPerfusionApparatus // } else { // DialysisMachineName = so.DialyzerPerfusionApparatus // } // } // if filedRecordTwo.IsShow == 1 { // if len(DialysisMachineName) > 0 { // DialysisMachineName = DialysisMachineName + "*" + so.DialysisIrrigation // } else { // DialysisMachineName = so.DialysisIrrigation // } // } // schedule.DialysisMachineName = DialysisMachineName // schedule.ScheduleType = item.TimeType // schedule.ModeId = item.TreatMode // schedule.ScheduleWeek = item.Weekday // schedule.BedId = item.DeviceNumberID // formatTime,_:=time.Parse("2006-01-02", nextnextTimeArr[int(item.Weekday)]) // schedule.ScheduleDate =formatTime.Unix() // schedule.UserOrgId = item.OrgID // schedule.Status = 1 // schedule.CreatedTime = time.Now().Unix() // schedule.UpdatedTime = time.Now().Unix() // device,_ := service.GetDeviceByID(item.OrgID,item.DeviceNumberID) // schedule.PartitionId = device.DeviceZoneID // schedules = append(schedules,schedule) // } // // break case 0: timeArr := WeekIntervalTime(0) //获取本周的周一到周日 t := time.Now() week_day, _ := strconv.Atoi(t.Weekday().String()) if week_day == 0 { week_day = 7 } items, _ := service.GetTemplateListByTemplateId(item.ID, item.OrgID) var schedules []models.Schedule //处理本周,先判断当前属于周几 for _, item := range items { var schedule models.Schedule if int(item.Weekday) > week_day { schedule.IsExport = 400000 var DialysisMachineName string so, _ := service.GetDialysisSolutionTwo(item.OrgID, item.PatientID, item.TreatMode) filedRecordOne, _ := service.FindFiledBy(item.OrgID, "透析器") filedRecordTwo, _ := service.FindFiledBy(item.OrgID, "灌流器") filedRecordThree, _ := service.FindFiledBy(item.OrgID, "透析器/灌流器") if filedRecordOne.IsShow == 1 { DialysisMachineName = so.DialysisDialyszers } if filedRecordThree.IsShow == 1 { if len(DialysisMachineName) > 0 { DialysisMachineName = DialysisMachineName + "*" + so.DialyzerPerfusionApparatus } else { DialysisMachineName = so.DialyzerPerfusionApparatus } } if filedRecordTwo.IsShow == 1 { if len(DialysisMachineName) > 0 { DialysisMachineName = DialysisMachineName + "*" + so.DialysisIrrigation } else { DialysisMachineName = so.DialysisIrrigation } } schedule.DialysisMachineName = DialysisMachineName schedule.ScheduleType = item.TimeType schedule.ModeId = item.TreatMode schedule.ScheduleWeek = item.Weekday schedule.BedId = item.DeviceNumberID formatTime, _ := time.Parse("2006-01-02", timeArr[int(item.Weekday)]) schedule.ScheduleDate = formatTime.Unix() schedule.UserOrgId = item.OrgID schedule.Status = 1 schedule.CreatedTime = time.Now().Unix() schedule.UpdatedTime = time.Now().Unix() device, _ := service.GetDeviceByID(item.OrgID, item.DeviceNumberID) schedule.PartitionId = device.DeviceZoneID schedules = append(schedules, schedule) } } break case 1: nexttimeArr := WeekIntervalTime(1) //获取本周的周一到周日 items, _ := service.GetTemplateListByTemplateId(item.ID, item.OrgID) var schedules []models.Schedule //处理下周 for _, item := range items { var schedule models.Schedule schedule.IsExport = 400000 var DialysisMachineName string so, _ := service.GetDialysisSolutionTwo(item.OrgID, item.PatientID, item.TreatMode) filedRecordOne, _ := service.FindFiledBy(item.OrgID, "透析器") filedRecordTwo, _ := service.FindFiledBy(item.OrgID, "灌流器") filedRecordThree, _ := service.FindFiledBy(item.OrgID, "透析器/灌流器") if filedRecordOne.IsShow == 1 { DialysisMachineName = so.DialysisDialyszers } if filedRecordThree.IsShow == 1 { if len(DialysisMachineName) > 0 { DialysisMachineName = DialysisMachineName + "*" + so.DialyzerPerfusionApparatus } else { DialysisMachineName = so.DialyzerPerfusionApparatus } } if filedRecordTwo.IsShow == 1 { if len(DialysisMachineName) > 0 { DialysisMachineName = DialysisMachineName + "*" + so.DialysisIrrigation } else { DialysisMachineName = so.DialysisIrrigation } } schedule.DialysisMachineName = DialysisMachineName schedule.ScheduleType = item.TimeType schedule.ModeId = item.TreatMode schedule.ScheduleWeek = item.Weekday schedule.BedId = item.DeviceNumberID formatTime, _ := time.Parse("2006-01-02", nexttimeArr[int(item.Weekday)]) schedule.ScheduleDate = formatTime.Unix() schedule.UserOrgId = item.OrgID schedule.Status = 1 schedule.CreatedTime = time.Now().Unix() schedule.UpdatedTime = time.Now().Unix() device, _ := service.GetDeviceByID(item.OrgID, item.DeviceNumberID) schedule.PartitionId = device.DeviceZoneID schedules = append(schedules, schedule) } break case 2: //当前修改的模板是下下周的模板 //根据模板类型,来判断需要修改哪几周数据,模板类型:单周模板,双周模板,三周模板,四周模板 //如果是单周模板:则修改本周除了当天未来的数据,下周,下下周数据 //如果是双周模板:则修改本周数据,下下周数据 //如果是三周模板:则修改下下周的数据 //如果是四周模板:则修改本周除了当天未来的数据 //nextTwoTimeArr :=WeekIntervalTime(2) nextnexttimeArr := WeekIntervalTime(2) //获取本周的周一到周日 t := time.Now() week_day, _ := strconv.Atoi(t.Weekday().String()) if week_day == 0 { week_day = 7 } items, _ := service.GetTemplateListByTemplateId(item.ID, item.OrgID) var schedules []models.Schedule //处理下下周 for _, item := range items { var schedule models.Schedule schedule.IsExport = 400000 var DialysisMachineName string so, _ := service.GetDialysisSolutionTwo(item.OrgID, item.PatientID, item.TreatMode) filedRecordOne, _ := service.FindFiledBy(item.OrgID, "透析器") filedRecordTwo, _ := service.FindFiledBy(item.OrgID, "灌流器") filedRecordThree, _ := service.FindFiledBy(item.OrgID, "透析器/灌流器") if filedRecordOne.IsShow == 1 { DialysisMachineName = so.DialysisDialyszers } if filedRecordThree.IsShow == 1 { if len(DialysisMachineName) > 0 { DialysisMachineName = DialysisMachineName + "*" + so.DialyzerPerfusionApparatus } else { DialysisMachineName = so.DialyzerPerfusionApparatus } } if filedRecordTwo.IsShow == 1 { if len(DialysisMachineName) > 0 { DialysisMachineName = DialysisMachineName + "*" + so.DialysisIrrigation } else { DialysisMachineName = so.DialysisIrrigation } } schedule.DialysisMachineName = DialysisMachineName schedule.ScheduleType = item.TimeType schedule.ModeId = item.TreatMode schedule.ScheduleWeek = item.Weekday schedule.BedId = item.DeviceNumberID formatTime, _ := time.Parse("2006-01-02", nextnexttimeArr[int(item.Weekday)]) schedule.ScheduleDate = formatTime.Unix() schedule.UserOrgId = item.OrgID schedule.Status = 1 schedule.CreatedTime = time.Now().Unix() schedule.UpdatedTime = time.Now().Unix() device, _ := service.GetDeviceByID(item.OrgID, item.DeviceNumberID) schedule.PartitionId = device.DeviceZoneID schedules = append(schedules, schedule) } break } } } } else if mode.Mode == 4 { for _, item := range templates { if item.Week > 0 { switch item.Week - week { case 0: timeArr := WeekIntervalTime(0) //获取本周的周一到周日 t := time.Now() week_day, _ := strconv.Atoi(t.Weekday().String()) if week_day == 0 { week_day = 7 } items, _ := service.GetTemplateListByTemplateId(item.ID, item.OrgID) var schedules []models.Schedule //处理本周,先判断当前属于周几 for _, item := range items { var schedule models.Schedule if int(item.Weekday) > week_day { schedule.IsExport = 400000 var DialysisMachineName string so, _ := service.GetDialysisSolutionTwo(item.OrgID, item.PatientID, item.TreatMode) filedRecordOne, _ := service.FindFiledBy(item.OrgID, "透析器") filedRecordTwo, _ := service.FindFiledBy(item.OrgID, "灌流器") filedRecordThree, _ := service.FindFiledBy(item.OrgID, "透析器/灌流器") if filedRecordOne.IsShow == 1 { DialysisMachineName = so.DialysisDialyszers } if filedRecordThree.IsShow == 1 { if len(DialysisMachineName) > 0 { DialysisMachineName = DialysisMachineName + "*" + so.DialyzerPerfusionApparatus } else { DialysisMachineName = so.DialyzerPerfusionApparatus } } if filedRecordTwo.IsShow == 1 { if len(DialysisMachineName) > 0 { DialysisMachineName = DialysisMachineName + "*" + so.DialysisIrrigation } else { DialysisMachineName = so.DialysisIrrigation } } schedule.DialysisMachineName = DialysisMachineName schedule.ScheduleType = item.TimeType schedule.ModeId = item.TreatMode schedule.ScheduleWeek = item.Weekday schedule.BedId = item.DeviceNumberID formatTime, _ := time.Parse("2006-01-02", timeArr[int(item.Weekday)]) schedule.ScheduleDate = formatTime.Unix() schedule.UserOrgId = item.OrgID schedule.Status = 1 schedule.CreatedTime = time.Now().Unix() schedule.UpdatedTime = time.Now().Unix() device, _ := service.GetDeviceByID(item.OrgID, item.DeviceNumberID) schedule.PartitionId = device.DeviceZoneID schedules = append(schedules, schedule) } } break case 1: nexttimeArr := WeekIntervalTime(1) //获取本周的周一到周日 items, _ := service.GetTemplateListByTemplateId(item.ID, item.OrgID) var schedules []models.Schedule //处理下周,先判断当前属于周几 for _, item := range items { var schedule models.Schedule schedule.IsExport = 400000 var DialysisMachineName string so, _ := service.GetDialysisSolutionTwo(item.OrgID, item.PatientID, item.TreatMode) filedRecordOne, _ := service.FindFiledBy(item.OrgID, "透析器") filedRecordTwo, _ := service.FindFiledBy(item.OrgID, "灌流器") filedRecordThree, _ := service.FindFiledBy(item.OrgID, "透析器/灌流器") if filedRecordOne.IsShow == 1 { DialysisMachineName = so.DialysisDialyszers } if filedRecordThree.IsShow == 1 { if len(DialysisMachineName) > 0 { DialysisMachineName = DialysisMachineName + "*" + so.DialyzerPerfusionApparatus } else { DialysisMachineName = so.DialyzerPerfusionApparatus } } if filedRecordTwo.IsShow == 1 { if len(DialysisMachineName) > 0 { DialysisMachineName = DialysisMachineName + "*" + so.DialysisIrrigation } else { DialysisMachineName = so.DialysisIrrigation } } schedule.DialysisMachineName = DialysisMachineName schedule.ScheduleType = item.TimeType schedule.ModeId = item.TreatMode schedule.ScheduleWeek = item.Weekday schedule.BedId = item.DeviceNumberID formatTime, _ := time.Parse("2006-01-02", nexttimeArr[int(item.Weekday)]) schedule.ScheduleDate = formatTime.Unix() schedule.UserOrgId = item.OrgID schedule.Status = 1 schedule.CreatedTime = time.Now().Unix() schedule.UpdatedTime = time.Now().Unix() device, _ := service.GetDeviceByID(item.OrgID, item.DeviceNumberID) schedule.PartitionId = device.DeviceZoneID schedules = append(schedules, schedule) } break case 2: nextnexttimeArr := WeekIntervalTime(2) //获取本周的周一到周日 items, _ := service.GetTemplateListByTemplateId(item.ID, item.OrgID) var schedules []models.Schedule //处理下下周,先判断当前属于周几 for _, item := range items { var schedule models.Schedule schedule.IsExport = 400000 var DialysisMachineName string so, _ := service.GetDialysisSolutionTwo(item.OrgID, item.PatientID, item.TreatMode) filedRecordOne, _ := service.FindFiledBy(item.OrgID, "透析器") filedRecordTwo, _ := service.FindFiledBy(item.OrgID, "灌流器") filedRecordThree, _ := service.FindFiledBy(item.OrgID, "透析器/灌流器") if filedRecordOne.IsShow == 1 { DialysisMachineName = so.DialysisDialyszers } if filedRecordThree.IsShow == 1 { if len(DialysisMachineName) > 0 { DialysisMachineName = DialysisMachineName + "*" + so.DialyzerPerfusionApparatus } else { DialysisMachineName = so.DialyzerPerfusionApparatus } } if filedRecordTwo.IsShow == 1 { if len(DialysisMachineName) > 0 { DialysisMachineName = DialysisMachineName + "*" + so.DialysisIrrigation } else { DialysisMachineName = so.DialysisIrrigation } } schedule.DialysisMachineName = DialysisMachineName schedule.ScheduleType = item.TimeType schedule.ModeId = item.TreatMode schedule.ScheduleWeek = item.Weekday schedule.BedId = item.DeviceNumberID formatTime, _ := time.Parse("2006-01-02", nextnexttimeArr[int(item.Weekday)]) schedule.ScheduleDate = formatTime.Unix() schedule.UserOrgId = item.OrgID schedule.Status = 1 schedule.CreatedTime = time.Now().Unix() schedule.UpdatedTime = time.Now().Unix() device, _ := service.GetDeviceByID(item.OrgID, item.DeviceNumberID) schedule.PartitionId = device.DeviceZoneID schedules = append(schedules, schedule) } break } } } } //清除今天以后的排班数据病并同步数据 err := service.ClearAndCreateSyncSch(c.GetAdminUserInfo().CurrentOrgId, time.Now().Unix(), schedules) if err == nil { c.ServeSuccessJSON(map[string]interface{}{ "msg": "同步成功", }) } else { c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSyncWrong) return } } func (c *ScheduleApiController) CoverSchTemplate() { templateID, _ := c.GetInt64("template_id") week_type_one, _ := c.GetInt64("week_type_one") time_type_one, _ := c.GetInt64("time_type_one") device_id_one, _ := c.GetInt64("device_id_one") patient_id_one, _ := c.GetInt64("patient_id_one") week_type_two, _ := c.GetInt64("week_type_two") time_type_two, _ := c.GetInt64("time_type_two") device_id_two, _ := c.GetInt64("device_id_two") patient_id_two, _ := c.GetInt64("patient_id_two") sch, _ := service.GetScheduleTemplateForDeviceNumberTwo(c.GetAdminUserInfo().CurrentOrgId, device_id_one, templateID, week_type_one, time_type_one, patient_id_one) sch_two, _ := service.GetScheduleTemplateForDeviceNumberTwo(c.GetAdminUserInfo().CurrentOrgId, device_id_two, templateID, week_type_two, time_type_two, patient_id_two) if sch.ID == 0 { c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeScheduleNotExist) return } if sch_two.ID == 0 { c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeScheduleNotExist) return } //替换者和被替换的排班日期不是同一天,则进行一个患者一天不能有多个排班提醒 if sch.Weekday != sch_two.Weekday && sch.PatientID != sch_two.PatientID { count, _ := service.GetScheduleTemplateCountByDate(c.GetAdminUserInfo().CurrentOrgId, sch_two.Weekday, sch.PatientID, sch.TemplateID) if count > 0 { c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientScheduleRepeat) return } } var new_sch models.PatientScheduleTemplateItem new_sch = sch new_sch.DeviceNumberID = sch_two.DeviceNumberID new_sch.Weekday = sch_two.Weekday new_sch.TimeType = sch_two.TimeType new_sch.ID = 0 //删除原来的排班并生成新的排班 err := service.SaveSchTemplateTwo(sch, sch_two, new_sch) if err == nil { templates, getTemplateItemsErr := service.GetOrgPatientScheduleTemplateItems(c.GetAdminUserInfo().CurrentOrgId) if getTemplateItemsErr != nil { c.ErrorLog("获取排班模板排班失败:%v", getTemplateItemsErr) } c.ServeSuccessJSON(map[string]interface{}{ "items": templates, "msg": "覆盖成功", }) } else { c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError) return } } func (c *ScheduleApiController) ExchangeSchTemplate() { templateID, _ := c.GetInt64("template_id") week_type_one, _ := c.GetInt64("week_type_one") time_type_one, _ := c.GetInt64("time_type_one") device_id_one, _ := c.GetInt64("device_id_one") patient_id_one, _ := c.GetInt64("patient_id_one") week_type_two, _ := c.GetInt64("week_type_two") time_type_two, _ := c.GetInt64("time_type_two") device_id_two, _ := c.GetInt64("device_id_two") patient_id_two, _ := c.GetInt64("patient_id_two") sch, _ := service.GetScheduleTemplateForDeviceNumberTwo(c.GetAdminUserInfo().CurrentOrgId, device_id_one, templateID, week_type_one, time_type_one, patient_id_one) sch_two, _ := service.GetScheduleTemplateForDeviceNumberTwo(c.GetAdminUserInfo().CurrentOrgId, device_id_two, templateID, week_type_two, time_type_two, patient_id_two) if sch.ID == 0 { c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeScheduleNotExist) return } if sch_two.ID == 0 { c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeScheduleNotExist) return } //替换者和被替换的排班日期不是同一天,则进行一个患者一天不能有多个排班提醒 if sch.Weekday != sch_two.Weekday && sch.PatientID != sch_two.PatientID { count, _ := service.GetScheduleTemplateCountByDate(c.GetAdminUserInfo().CurrentOrgId, sch_two.Weekday, sch.PatientID, sch.TemplateID) if count > 0 { c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientScheduleRepeat) return } count1, _ := service.GetScheduleTemplateCountByDate(c.GetAdminUserInfo().CurrentOrgId, sch.Weekday, sch_two.PatientID, sch_two.TemplateID) if count1 > 0 { c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientScheduleRepeat) return } } err := service.UpdateScheduleTemplateThree(sch, sch_two) if err == nil { templates, getTemplateItemsErr := service.GetOrgPatientScheduleTemplateItems(c.GetAdminUserInfo().CurrentOrgId) if getTemplateItemsErr != nil { c.ErrorLog("获取排班模板排班失败:%v", getTemplateItemsErr) } c.ServeSuccessJSON(map[string]interface{}{ "items": templates, "msg": "交换成功", }) } else { c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError) return } } func (c *ScheduleApiController) DeleteAndAddScheduleTemplateTwo() { templateID, _ := c.GetInt64("template_id") week_type_one, _ := c.GetInt64("week_type_one") time_type_one, _ := c.GetInt64("time_type_one") device_id_one, _ := c.GetInt64("device_id_one") patient_id_one, _ := c.GetInt64("patient_id_one") week_type_two, _ := c.GetInt8("week_type_two") time_type_two, _ := c.GetInt8("time_type_two") device_id_two, _ := c.GetInt64("device_id_two") patient_id_two, _ := c.GetInt64("patient_id_two") mode_id, _ := c.GetInt64("mode_id") sch, _ := service.GetScheduleTemplateForDeviceNumberTwo(c.GetAdminUserInfo().CurrentOrgId, device_id_one, templateID, week_type_one, time_type_one, patient_id_one) if sch.ID == 0 { c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeScheduleNotExist) return } // 先删除后新增 sch.Status = 0 //service.SaveSchTemplate(sch) item := models.PatientScheduleTemplateItem{ DeviceNumberID: device_id_two, PatientID: patient_id_two, TreatMode: mode_id, Weekday: week_type_two, TimeType: time_type_two, Status: 1, OrgID: c.GetAdminUserInfo().CurrentOrgId, TemplateID: templateID, CreateTime: time.Now().Unix(), ModifyTime: 0, IsExport: 40000, } err := service.SaveSchTemplate(sch, item) if err == nil { templates, getTemplateItemsErr := service.GetOrgPatientScheduleTemplateItems(c.GetAdminUserInfo().CurrentOrgId) if getTemplateItemsErr != nil { c.ErrorLog("获取排班模板排班失败:%v", getTemplateItemsErr) } c.ServeSuccessJSON(map[string]interface{}{ "items": templates, }) } else { c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError) return } } func (c *ScheduleApiController) GetTemplateDevicesNumbers() { sch_type, _ := c.GetInt("sch_type", 0) zone_id, _ := c.GetInt64("zone_id", 0) patient_id, _ := c.GetInt64("patient_id", 0) template_id, _ := c.GetInt64("template_id", 0) weekday, _ := c.GetInt64("weekday") deviceNumbers, getDeviceNumbersErr := service.GetAllAvaildTemplateDeviceNumbersByZone(c.GetAdminUserInfo().CurrentOrgId, weekday, sch_type, zone_id, patient_id, template_id) if getDeviceNumbersErr != nil { c.ErrorLog("获取所有床位失败:%v", getDeviceNumbersErr) c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException) return } c.ServeSuccessJSON(map[string]interface{}{ "devices": deviceNumbers, }) } // type TestCtr struct { // BaseAPIController // } // func (this *TestCtr) Test() { // now := time.Now().AddDate(0, 0, 7) // weekday := int(now.Weekday()) // if weekday == 0 { // weekday = 7 // } // monday := now.AddDate(0, 0, 1-weekday) // sunday := now.AddDate(0, 0, 7-weekday) // // this.TraceLog("%v", weekday) // this.ServeSuccessJSON(map[string]interface{}{ // "weekday": weekday, // "monday": monday.Format("2006-01-02"), // "sunday": sunday.Format("2006-01-02"), // }) // } // ------- 患者排班模板 -------- type PatientScheduleTemplateAPIController struct { BaseAuthAPIController } // /api/schtemp/p/initdata [get] func (this *PatientScheduleTemplateAPIController) InitData() { adminUserInfo := this.GetAdminUserInfo() patitionIdStr := this.GetString("patitionid") var ids []string if len(patitionIdStr) > 0 { ids = strings.Split(patitionIdStr, ",") } mode, getModeErr := service.GetOrgPatientScheduleTemplateMode(adminUserInfo.CurrentOrgId) if getModeErr != nil { this.ErrorLog("获取排班模板启用模式失败:%v", getModeErr) this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException) return } now := time.Now() if mode == nil { mode = &models.PatientScheduleTemplateMode{ OrgID: adminUserInfo.CurrentOrgId, Mode: 0, ExecuteTimes: 0, Status: 1, CreateTime: now.Unix(), ModifyTime: now.Unix(), } createModeErr := service.SavePatientScheduleTemplateMode(mode) if createModeErr != nil { this.ErrorLog("创建排班模板启用模式失败:%v", createModeErr) this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException) return } } deviceNumbers, getDeviceNumbersErr := service.GetScheduleValidDeviceNumbers(adminUserInfo.CurrentOrgId, ids) fmt.Println("deviceNumbers233323232332232323223233223323232323", deviceNumbers) if getDeviceNumbersErr != nil { this.ErrorLog("获取床位号失败:%v", getDeviceNumbersErr) this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException) return } templates, getTemplatesErr := service.GetOrgPatientScheduleTemplateItems(adminUserInfo.CurrentOrgId) if getTemplatesErr != nil { this.ErrorLog("获取排班模板及其排班列表失败:%v", getTemplatesErr) this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException) return } if len(templates) == 0 { firstTemp, secondTemp, thirdTemp, fourTemp, createTempErr := service.CreateTwoPatientScheduleTemplates(adminUserInfo.CurrentOrgId) if createTempErr != nil { this.ErrorLog("创建4个排班模板失败:%v", createTempErr) this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException) return } templates = append(templates, firstTemp, secondTemp, thirdTemp, fourTemp) } else if len(templates) == 1 { temp, thirdTemp, fourTemp, createTempErr := service.CreatePatientScheduleTemplate(adminUserInfo.CurrentOrgId) if createTempErr != nil { this.ErrorLog("创建3个排班模板失败:%v", createTempErr) this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException) return } templates = append(templates, temp, thirdTemp, fourTemp) } else if len(templates) == 2 { thirdTemp, fourTemp, createTempErr := service.CreatePatientScheduleTemplateTwo(adminUserInfo.CurrentOrgId) if createTempErr != nil { this.ErrorLog("创建2个排班模板失败:%v", createTempErr) this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException) return } templates = append(templates, thirdTemp, fourTemp) } else if len(templates) == 3 { temp, createTempErr := service.CreatePatientScheduleTemplateThree(adminUserInfo.CurrentOrgId) if createTempErr != nil { this.ErrorLog("创建1个排班模板失败:%v", createTempErr) this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException) return } templates = append(templates, temp) } patients, getPatientsErr := service.PatientScheduleTemplateGetAllValidPatient(adminUserInfo.CurrentOrgId) if getPatientsErr != nil { this.ErrorLog("获取患者列表失败失败:%v", getPatientsErr) this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException) return } // 获取本周的排班 //monday, sunday := utils.GetMondayAndSundayOfWeekDate(&now) //schedules, getScheduleErr := service.GetWeekSchedule(adminUserInfo.CurrentOrgId, monday.Unix(), sunday.Unix()) //if getScheduleErr != nil { // this.ErrorLog("获取本周排班失败:%v", getScheduleErr) // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException) // return //} this.ServeSuccessJSON(map[string]interface{}{ "template_mode": mode, "device_numbers": deviceNumbers, "templates": templates, "patients": patients, //"schedules": schedules, }) } // /api/schtemp/p/setmode [post] // @param mode:int 0.不启用模板 1.单周模板 2.双周模板 3.三周模版 4.四周模版 func (this *PatientScheduleTemplateAPIController) SetMode() { mode, _ := this.GetInt8("mode") week_time, _ := this.GetInt8("week_time") if mode != 1 && mode != 2 && mode != 0 && mode != 3 && mode != 4 { this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong) return } if mode > 0 { if week_time == 0 { this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong) return } } adminUserInfo := this.GetAdminUserInfo() templateMode, getTemplateModeErr := service.GetOrgPatientScheduleTemplateMode(adminUserInfo.CurrentOrgId) if getTemplateModeErr != nil { this.ErrorLog("获取排班模板启用模式失败:%v", getTemplateModeErr) this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException) return } else if templateMode == nil { this.ErrorLog("获取不到排班模板启用模式") this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException) return } templateMode.Week = int64(week_time) templateMode.OriginalWeek = int64(week_time) if mode != templateMode.Mode { if templateMode.Mode == 0 { // 0 -> 1 或 0 -> 2 则直接清除下四周的排班 templateMode.Mode = mode templateMode.ExecuteTimes = 0 templateMode.ModifyTime = time.Now().Unix() updateErr := service.SavePatientScheduleTemplateModeAndClearNextTwoWeekSchedules(templateMode) if updateErr != nil { this.ErrorLog("更新排班模板启用方式(0 -> 1 或 0 -> 2)时失败:%v", updateErr) this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException) return } } else if mode == 0 { // 1 -> 0 或 2 -> 0 则不处理排班,但清除所有模板item templateMode.Mode = mode templateMode.ExecuteTimes = 0 templateMode.ModifyTime = time.Now().Unix() updateErr := service.SavePatientScheduleTemplateModeAndClearAllTemplateItems(templateMode) if updateErr != nil { this.ErrorLog("更新排班模板启用方式(1 -> 0 或 2 -> 0)时失败:%v", updateErr) this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException) return } } else if templateMode.Mode == 1 && mode == 2 { // 1 -> 2 清除第二周排班 templateMode.Mode = mode templateMode.ExecuteTimes = 0 templateMode.ModifyTime = time.Now().Unix() updateErr := service.SavePatientScheduleTemplateModeAndClearNextTwoWeekSchedules(templateMode) if updateErr != nil { this.ErrorLog("更新排班模板启用方式(1 -> 2)时失败:%v", updateErr) this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException) return } } else if templateMode.Mode == 1 && mode == 3 { templateMode.Mode = mode templateMode.ExecuteTimes = 0 templateMode.ModifyTime = time.Now().Unix() updateErr := service.SaveTemplateMode(templateMode) if updateErr != nil { this.ErrorLog("更新排班模板启用方式(1 -> 3)时失败:%v", updateErr) this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException) return } } else if templateMode.Mode == 1 && mode == 4 { templateMode.Mode = mode templateMode.ExecuteTimes = 0 templateMode.ModifyTime = time.Now().Unix() updateErr := service.SaveTemplateMode(templateMode) if updateErr != nil { this.ErrorLog("更新排班模板启用方式(1 -> 4)时失败:%v", updateErr) this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException) return } } else if templateMode.Mode == 2 && mode == 1 { // 2 -> 1 清除第二周模板item,清除第二周排班 templateIDs, getTemplateIDsErr := service.GetOrgPatientScheduleTemplateIDs(adminUserInfo.CurrentOrgId) if getTemplateIDsErr != nil { this.ErrorLog("获取排班模板失败:%v", getTemplateIDsErr) this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException) return } firstWeekItems, getFirstWeekItemsErr := service.GetOrgPatientScheduleTemplateItemsWithoutPatientByTemplateID(adminUserInfo.CurrentOrgId, templateIDs[0].ID) if getFirstWeekItemsErr != nil { this.ErrorLog("获取排班模板排班失败:%v", getFirstWeekItemsErr) this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException) return } templateMode.Mode = mode templateMode.ExecuteTimes = 0 templateMode.ModifyTime = time.Now().Unix() updateErr := service.SavePatientScheduleTemplateMode2To1(templateMode, templateIDs[1].ID, firstWeekItems) if updateErr != nil { this.ErrorLog("更新排班模板启用方式(1 -> 2)时失败:%v", updateErr) this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException) return } } else if templateMode.Mode == 2 && mode == 3 { // templateMode.Mode = mode templateMode.ExecuteTimes = 0 templateMode.ModifyTime = time.Now().Unix() updateErr := service.SaveTemplateMode(templateMode) if updateErr != nil { this.ErrorLog("更新排班模板启用方式(1 -> 4)时失败:%v", updateErr) this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException) return } } else if templateMode.Mode == 2 && mode == 4 { // templateMode.Mode = mode templateMode.ExecuteTimes = 0 templateMode.ModifyTime = time.Now().Unix() updateErr := service.SaveTemplateMode(templateMode) if updateErr != nil { this.ErrorLog("更新排班模板启用方式(1 -> 4)时失败:%v", updateErr) this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException) return } } else if templateMode.Mode == 3 && mode == 1 { // 3 -> 1 清除第三,二周模板item,清除第三,二周排班 templateIDs, getTemplateIDsErr := service.GetOrgPatientScheduleTemplateIDs(adminUserInfo.CurrentOrgId) if getTemplateIDsErr != nil { this.ErrorLog("获取排班模板失败:%v", getTemplateIDsErr) this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException) return } templateMode.Mode = mode templateMode.ExecuteTimes = 0 templateMode.ModifyTime = time.Now().Unix() updateErr := service.SavePatientScheduleTemplateMode3To1(templateMode, templateIDs[1].ID, templateIDs[2].ID) if updateErr != nil { this.ErrorLog("更新排班模板启用方式(1 -> 3)时失败:%v", updateErr) this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException) return } } else if templateMode.Mode == 3 && mode == 2 { // 3 -> 1 清除第三周模板item,清除第三周排班,将第一周的排班重复到第二周 templateIDs, getTemplateIDsErr := service.GetOrgPatientScheduleTemplateIDs(adminUserInfo.CurrentOrgId) if getTemplateIDsErr != nil { this.ErrorLog("获取排班模板失败:%v", getTemplateIDsErr) this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException) return } templateMode.Mode = mode templateMode.ExecuteTimes = 0 templateMode.ModifyTime = time.Now().Unix() updateErr := service.SavePatientScheduleTemplateMode3To2(templateMode, templateIDs[2].ID) if updateErr != nil { this.ErrorLog("更新排班模板启用方式(2 -> 3)时失败:%v", updateErr) this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException) return } } else if templateMode.Mode == 3 && mode == 4 { // 2 -> 1 清除第二周模板item,清除第二周排班 templateMode.Mode = mode templateMode.ExecuteTimes = 0 templateMode.ModifyTime = time.Now().Unix() updateErr := service.SaveTemplateMode(templateMode) if updateErr != nil { this.ErrorLog("更新排班模板启用方式(1 -> 4)时失败:%v", updateErr) this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException) return } } else if templateMode.Mode == 4 && mode == 1 { // 4 -> 1 清除第三周模板item,清除第三周排班,将第一周的排班重复到第二周 templateIDs, getTemplateIDsErr := service.GetOrgPatientScheduleTemplateIDs(adminUserInfo.CurrentOrgId) if getTemplateIDsErr != nil { this.ErrorLog("获取排班模板失败:%v", getTemplateIDsErr) this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException) return } templateMode.Mode = mode templateMode.ExecuteTimes = 0 templateMode.ModifyTime = time.Now().Unix() updateErr := service.SavePatientScheduleTemplateMode4To1(templateMode, templateIDs[1].ID, templateIDs[2].ID, templateIDs[3].ID) if updateErr != nil { this.ErrorLog("更新排班模板启用方式(1 -> 4)时失败:%v", updateErr) this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException) return } } else if templateMode.Mode == 4 && mode == 2 { // 4 -> 2 templateIDs, getTemplateIDsErr := service.GetOrgPatientScheduleTemplateIDs(adminUserInfo.CurrentOrgId) if getTemplateIDsErr != nil { this.ErrorLog("获取排班模板失败:%v", getTemplateIDsErr) this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException) return } templateMode.Mode = mode templateMode.ExecuteTimes = 0 templateMode.ModifyTime = time.Now().Unix() updateErr := service.SavePatientScheduleTemplateMode4To2(templateMode, templateIDs[2].ID, templateIDs[3].ID) if updateErr != nil { this.ErrorLog("更新排班模板启用方式(2 -> 4)时失败:%v", updateErr) this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException) return } } else if templateMode.Mode == 4 && mode == 3 { // 4 -> 3 templateIDs, getTemplateIDsErr := service.GetOrgPatientScheduleTemplateIDs(adminUserInfo.CurrentOrgId) if getTemplateIDsErr != nil { this.ErrorLog("获取排班模板失败:%v", getTemplateIDsErr) this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException) return } templateMode.Mode = mode templateMode.ExecuteTimes = 0 templateMode.ModifyTime = time.Now().Unix() updateErr := service.SavePatientScheduleTemplateMode4To3(templateMode, templateIDs[3].ID) if updateErr != nil { this.ErrorLog("更新排班模板启用方式(3 -> 4)时失败:%v", updateErr) this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException) return } } templates, _ := service.GetOrgPatientScheduleTemplateIDs(adminUserInfo.CurrentOrgId) //处理第几周数问题 if mode == 0 { service.UpdateTemplateItemWeek(templates[0].OrgID, templates[0].ID, 0) service.UpdateTemplateItemWeek(templates[1].OrgID, templates[1].ID, 0) service.UpdateTemplateItemWeek(templates[2].OrgID, templates[2].ID, 0) service.UpdateTemplateItemWeek(templates[3].OrgID, templates[3].ID, 0) } else if mode == 1 { service.UpdateTemplateItemWeek(templates[0].OrgID, templates[0].ID, week_time) service.UpdateTemplateItemWeek(templates[1].OrgID, templates[1].ID, 0) service.UpdateTemplateItemWeek(templates[2].OrgID, templates[2].ID, 0) service.UpdateTemplateItemWeek(templates[3].OrgID, templates[3].ID, 0) } else if mode == 2 { service.UpdateTemplateItemWeek(templates[0].OrgID, templates[0].ID, week_time) service.UpdateTemplateItemWeek(templates[1].OrgID, templates[1].ID, week_time+1) service.UpdateTemplateItemWeek(templates[2].OrgID, templates[2].ID, 0) service.UpdateTemplateItemWeek(templates[3].OrgID, templates[3].ID, 0) } else if mode == 3 { service.UpdateTemplateItemWeek(templates[0].OrgID, templates[0].ID, week_time) service.UpdateTemplateItemWeek(templates[1].OrgID, templates[1].ID, week_time+1) service.UpdateTemplateItemWeek(templates[2].OrgID, templates[2].ID, week_time+2) service.UpdateTemplateItemWeek(templates[3].OrgID, templates[3].ID, 0) } else if mode == 4 { service.UpdateTemplateItemWeek(templates[0].OrgID, templates[0].ID, week_time) service.UpdateTemplateItemWeek(templates[1].OrgID, templates[1].ID, week_time+1) service.UpdateTemplateItemWeek(templates[2].OrgID, templates[2].ID, week_time+2) service.UpdateTemplateItemWeek(templates[3].OrgID, templates[3].ID, week_time+3) } } else { fmt.Println("~~~~~~~~") service.UpdateTemplateItemModeWeek(adminUserInfo.CurrentOrgId, templateMode.ID, templateMode.OriginalWeek) } this.ServeSuccessJSON(nil) } // /api/schtemp/p/update_sch [post] // @param template_id:int // @param add_schs:array'json ([ {device_number_id, patient_id, mode(treat_mode), weekday, time_type} ]) // @param del_schs:array'json ([ {device_number_id, weekday, time_type} ]) // @param change_schs:array'json ([ {device_number_id, patient_id, mode(treat_mode), weekday, time_type} ]) func (this *PatientScheduleTemplateAPIController) UpdateSchedules() { templateID, _ := this.GetInt64("template_id") addSchedulesJSON := this.GetString("add_schs") delSchedulesJSON := this.GetString("del_schs") changeSchedulesJSON := this.GetString("change_schs") var addSchedules []*ParamModelSchedule var delSchedules []*ParamModelSchedule var changeSchedules []*ParamModelSchedule parseErr := json.Unmarshal([]byte(addSchedulesJSON), &addSchedules) if parseErr != nil { this.ErrorLog("解析增加排班的数组参数失败:%v", parseErr) this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong) return } parseErr = json.Unmarshal([]byte(delSchedulesJSON), &delSchedules) if parseErr != nil { this.ErrorLog("解析删除排班的数组参数失败:%v", parseErr) this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong) return } parseErr = json.Unmarshal([]byte(changeSchedulesJSON), &changeSchedules) if parseErr != nil { this.ErrorLog("解析修改排班的数组参数失败:%v", parseErr) this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong) return } adminUserInfo := this.GetAdminUserInfo() templateIDs, getTemplateIDsErr := service.GetOrgPatientScheduleTemplateIDs(adminUserInfo.CurrentOrgId) if getTemplateIDsErr != nil { this.ErrorLog("获取排班模板失败:%v", getTemplateIDsErr) this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException) return } else { isTemplateIDExist := false for _, templateIDObject := range templateIDs { if templateIDObject.ID == templateID { isTemplateIDExist = true break } } if isTemplateIDExist == false { this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeScheduleTemplateNotExist) return } } addTemplateItems := make([]*models.PatientScheduleTemplateItem, 0, len(addSchedules)) delTemplateItems := make([]*models.PatientScheduleTemplateItem, 0, len(delSchedules)) changeTemplateItems := make([]*models.PatientScheduleTemplateItem, 0, len(changeSchedules)) for _, sch := range addSchedules { if sch.DeviceNumberID <= 0 || sch.PatientID <= 0 || sch.Weekday < 1 || sch.Weekday > 7 || sch.TimeType < 1 || sch.TimeType > 3 { this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong) return } addTemplateItems = append(addTemplateItems, &models.PatientScheduleTemplateItem{ DeviceNumberID: sch.DeviceNumberID, PatientID: sch.PatientID, TreatMode: sch.Mode, Weekday: sch.Weekday, TimeType: sch.TimeType, }) } for _, sch := range delSchedules { if sch.DeviceNumberID <= 0 || sch.Weekday < 1 || sch.Weekday > 7 || sch.TimeType < 1 || sch.TimeType > 3 { this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong) return } delTemplateItems = append(delTemplateItems, &models.PatientScheduleTemplateItem{ DeviceNumberID: sch.DeviceNumberID, Weekday: sch.Weekday, TimeType: sch.TimeType, }) } for _, sch := range changeSchedules { if sch.DeviceNumberID <= 0 || sch.PatientID <= 0 || sch.Weekday < 1 || sch.Weekday > 7 || sch.TimeType < 1 || sch.TimeType > 3 { this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong) return } changeTemplateItems = append(changeTemplateItems, &models.PatientScheduleTemplateItem{ DeviceNumberID: sch.DeviceNumberID, PatientID: sch.PatientID, TreatMode: sch.Mode, Weekday: sch.Weekday, TimeType: sch.TimeType, }) } templateMode, getTemplateModeErr := service.GetOrgPatientScheduleTemplateMode(adminUserInfo.CurrentOrgId) if getTemplateModeErr != nil { this.ErrorLog("获取排班模板启用模式失败:%v", getTemplateModeErr) this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException) return } else if templateMode == nil { this.ErrorLog("获取不到排班模板启用模式") this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException) return } //shouldUpdateNextWeekSchedules := false //shouldUpdateNextSecondWeekSchedules := false //shouldUpdateNextThirdWeekSchedules := false //shouldUpdateNextFourWeekSchedules := false // if templateMode.Mode == 0 { this.ErrorLog("当前未开启排班模板,所以更新模板的操作将被无视") this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong) return } //判断当前用的是模版几 //templateIDIndex := 1 //for index, templateIDObject := range templateIDs { // if templateIDObject.ID == templateID { // //templateIDIndex = index + 1 // } //} //if templateMode.Mode == 1 { // if templateIDIndex == 1 { // shouldUpdateNextWeekSchedules = true // shouldUpdateNextSecondWeekSchedules = true // } else { // this.ErrorLog("当前开启的是单周模板,所以不会更新第二个模板") // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong) // return // } // //} else if templateMode.Mode == 2 { // mode == 2 => 开启双周模板时,只需更新一周排班 // if templateIDIndex == 1 { // if templateMode.ExecuteTimes%2 == 0 { // shouldUpdateNextWeekSchedules = true // shouldUpdateNextSecondWeekSchedules = false // } else { // shouldUpdateNextWeekSchedules = false // shouldUpdateNextSecondWeekSchedules = true // } // // } else { // if templateMode.ExecuteTimes%2 == 0 { // shouldUpdateNextWeekSchedules = false // shouldUpdateNextSecondWeekSchedules = true // } else { // shouldUpdateNextWeekSchedules = true // shouldUpdateNextSecondWeekSchedules = false // } // // } //} else if templateMode.Mode == 3 { // mode == 2 => 开启双周模板时,只需更新一周排班 // if templateIDIndex == 1 { //当前修改的是第一个模版 // if templateMode.ExecuteTimes%3 == 0 { // shouldUpdateNextWeekSchedules = true // shouldUpdateNextSecondWeekSchedules = false // shouldUpdateNextThirdWeekSchedules = false // } else if templateMode.ExecuteTimes%3 == 1 { // shouldUpdateNextWeekSchedules = false // shouldUpdateNextSecondWeekSchedules = true // shouldUpdateNextThirdWeekSchedules = false // } else { // shouldUpdateNextWeekSchedules = false // shouldUpdateNextSecondWeekSchedules = false // shouldUpdateNextThirdWeekSchedules = true // } // } else if templateIDIndex == 2 { // if templateMode.ExecuteTimes%2 == 0 { // shouldUpdateNextWeekSchedules = false // shouldUpdateNextSecondWeekSchedules = true // } else { // shouldUpdateNextWeekSchedules = true // shouldUpdateNextSecondWeekSchedules = false // } // // } else { // // } //} updateErr := service.UpdateScheduleTemplate(adminUserInfo.CurrentOrgId, templateID, addTemplateItems, delTemplateItems, changeTemplateItems, false, false) if updateErr != nil { this.ErrorLog("更新排班模板排班失败:%v", updateErr) this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDBUpdate) return } templates, getTemplateItemsErr := service.GetOrgPatientScheduleTemplateItems(adminUserInfo.CurrentOrgId) if getTemplateItemsErr != nil { this.ErrorLog("获取排班模板排班失败:%v", getTemplateItemsErr) this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException) return } this.ServeSuccessJSON(map[string]interface{}{ "items": templates, }) } func WeekIntervalTime(week int) []string { now := time.Now() offset := int(time.Monday - now.Weekday()) //周日做特殊判断 因为time.Monday = 0 if offset > 0 { offset = -6 } var timeArr []string year, month, day := now.Date() thisWeek := time.Date(year, month, day, 0, 0, 0, 0, time.Local) startTime := thisWeek.AddDate(0, 0, offset+7*week).Format("2006-01-02") + " 00:00:00" twoTime := thisWeek.AddDate(0, 0, offset+1+7*week).Format("2006-01-02") + " 00:00:00" threeTime := thisWeek.AddDate(0, 0, offset+2+7*week).Format("2006-01-02") + " 00:00:00" fourTime := thisWeek.AddDate(0, 0, offset+3+7*week).Format("2006-01-02") + " 00:00:00" fiveTime := thisWeek.AddDate(0, 0, offset+4+7*week).Format("2006-01-02") + " 00:00:00" SixTime := thisWeek.AddDate(0, 0, offset+5+7*week).Format("2006-01-02") + " 00:00:00" endTime := thisWeek.AddDate(0, 0, offset+6+7*week).Format("2006-01-02") + " 00:00:00" timeArr = append(timeArr, startTime) timeArr = append(timeArr, twoTime) timeArr = append(timeArr, threeTime) timeArr = append(timeArr, fourTime) timeArr = append(timeArr, fiveTime) timeArr = append(timeArr, SixTime) timeArr = append(timeArr, endTime) return timeArr } type ParamModelSchedule struct { DeviceNumberID int64 `json:"device_number_id"` PatientID int64 `json:"patient_id"` Mode int64 `json:"mode"` Weekday int8 `json:"weekday"` TimeType int8 `json:"time_type"` } func (this *PatientScheduleTemplateAPIController) GetPatientList() { patients, err := service.GetSchTemplatePatientList(this.GetAdminUserInfo().CurrentOrgId) if err != nil { this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException) } this.ServeSuccessJSON(map[string]interface{}{ "list": patients, }) } type ParamModelEditSchedule struct { ID int64 `json:"sch_id"` DeviceNumberID int64 `json:"jihao_id"` PatientID int64 `json:"patient_id"` Mode int64 `json:"mode_id"` Weekday int64 `json:"schedule_week"` TimeType int64 `json:"time_type"` TemplateID int64 `json:"t_id"` Title string `json:"title"` } func (this *PatientScheduleTemplateAPIController) UpdateSchedulesTemplate() { addOrEditSchedulesJSON := this.GetString("edit_schs") delSchedulesJSON := this.GetString("del_schs") fmt.Println(addOrEditSchedulesJSON) var addOrEditSchedules []*ParamModelEditSchedule var delSchedules []*ParamModelEditSchedule parseErr := json.Unmarshal([]byte(addOrEditSchedulesJSON), &addOrEditSchedules) json.Unmarshal([]byte(delSchedulesJSON), &delSchedules) fmt.Println(parseErr) if parseErr != nil { this.ErrorLog("解析增加编辑排班的数组参数失败:%v", parseErr) this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong) return } //if parseDelErr != nil { // this.ErrorLog("解析删除排班的数组参数失败:%v", parseErr) // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong) // return //} for _, item := range delSchedules { src_template, _ := service.GetScheduleTemplateItem(item.ID) src_template.Status = 0 service.SaveSchTemplateItem(src_template) } for _, item := range addOrEditSchedules { if item.ID > 0 { //已经存在的数据 src_template, _ := service.GetScheduleTemplateItem(item.ID) src_template.DeviceNumberID = item.DeviceNumberID src_template.TimeType = int8(item.TimeType) src_template.TreatMode = item.Mode schItem, _ := service.GetScheduleTemplateThree(this.GetAdminUserInfo().CurrentOrgId, src_template.DeviceNumberID, src_template.TemplateID, int64(src_template.Weekday), int64(src_template.TimeType), src_template.PatientID) if schItem.ID > 0 { json := make(map[string]interface{}) json["msg"] = item.Title + "周" + strconv.FormatInt(item.Weekday, 10) + "的床位已经有人排班无法保存,可能存在重复排班" json["state"] = 0 this.Data["json"] = json this.ServeJSON() break } service.SaveSchTemplateItem(src_template) } else { schItemTwo, _ := service.GetScheduleTemplateTwo(this.GetAdminUserInfo().CurrentOrgId, item.TemplateID, item.Weekday, item.PatientID) fmt.Println("222222") if schItemTwo.ID > 0 { //当天存在排班,存在则为修改 fmt.Println("333333333") src_template, _ := service.GetScheduleTemplateItem(schItemTwo.ID) src_template.DeviceNumberID = item.DeviceNumberID src_template.TimeType = int8(item.TimeType) src_template.TreatMode = item.Mode service.SaveSchTemplateItem(src_template) } else { schItem, _ := service.GetScheduleTemplateOne(this.GetAdminUserInfo().CurrentOrgId, item.DeviceNumberID, item.TemplateID, item.Weekday, item.TimeType) if schItem.ID == 0 { //床位未被占用 var template models.PatientScheduleTemplateItem template.TreatMode = item.Mode template.TemplateID = int64(item.TemplateID) template.TimeType = int8(item.TimeType) template.DeviceNumberID = item.DeviceNumberID template.CreateTime = time.Now().Unix() template.ModifyTime = time.Now().Unix() template.OrgID = this.GetAdminUserInfo().CurrentOrgId template.PatientID = item.PatientID template.Weekday = int8(item.Weekday) template.Status = 1 service.SaveSchTemplateItem(template) } else { //床位被占用 1.被自己占用,2。被别人占用 if schItem.PatientID != 0 && schItem.PatientID == item.PatientID { //当天该患者已经存在排班则设为修改操作 src_template, _ := service.GetScheduleTemplateItem(schItem.ID) src_template.DeviceNumberID = item.DeviceNumberID src_template.TimeType = int8(item.TimeType) src_template.TreatMode = item.Mode service.SaveSchTemplateItem(src_template) } else if schItem.PatientID != 0 && schItem.PatientID != item.PatientID { //当天该床位被其他人占用,则无法保存 //fmt.Println("7777777") json := make(map[string]interface{}) json["msg"] = item.Title + "周" + strconv.FormatInt(item.Weekday, 10) + "的床位已经有人排班,无法保存" json["state"] = 0 this.Data["json"] = json this.ServeJSON() break } } } } } templates, _ := service.GetOrgPatientScheduleTemplateItems(this.GetAdminUserInfo().CurrentOrgId) this.ServeSuccessJSON(map[string]interface{}{ "items": templates, }) } //func (c *ScheduleApiController) DeleteScheduleTemplateTwo() { // id, _ := c.GetInt64("id", 0) // if id <= 0 { // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong) // return // } // // adminINfo := c.GetAdminUserInfo() // // schedule, _ := service.GetSc(adminINfo.CurrentOrgId, id) // timeNow := time.Now().Format("2006-01-02") // timeTemplate := "2006-01-02" // // tm := time.Unix(int64(schedule.ScheduleDate), 0) // timeStr := tm.Format(timeTemplate) // if timeNow > timeStr { // // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCantSetScheduleBeforeNow) // return // } // if schedule == nil { // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeScheduleNotExist) // return // } // // order, err := service.GetOneDialysisOrder(adminINfo.CurrentOrgId, schedule.ScheduleDate, schedule.PatientId) // if err != nil { // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException) // return // } // // if order != nil { // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDelScheduleFailByDialysisTwo) // return // } // // schedule.Status = 0 // schedule.UpdatedTime = time.Now().Unix() // err = service.UpdateSchedule(schedule) // redis := service.RedisClient() // // //处方 // keyOne := strconv.FormatInt(adminINfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(schedule.ScheduleDate, 10) + ":prescriptions_list_all" // redis.Set(keyOne, "", time.Second) // // //医嘱 // keyTwo := strconv.FormatInt(adminINfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(schedule.ScheduleDate, 10) + ":advice_list_all" // redis.Set(keyTwo, "", time.Second) // // keySix := strconv.FormatInt(adminINfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(schedule.ScheduleDate, 10) + ":assessment_befores_list_all" // redis.Set(keySix, "", time.Second) // keyThree := strconv.FormatInt(adminINfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(schedule.ScheduleDate, 10) + ":assessment_after_dislysis_list_all" // redis.Set(keyThree, "", time.Second) // // keyFour := strconv.FormatInt(adminINfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(schedule.ScheduleDate, 10) + ":monitor_record_list_all" // redis.Set(keyFour, "", time.Second) // // keyFive := strconv.FormatInt(adminINfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(schedule.ScheduleDate, 10) + ":treatment_summarys_list_all" // redis.Set(keyFive, "", time.Second) // // keySeven := strconv.FormatInt(adminINfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(schedule.ScheduleDate, 10) + ":dialysis_orders_list_all" // redis.Set(keySeven, "", time.Second) // fmt.Println(err) // defer redis.Close() // if err != nil { // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeleteScheduleFail) // return // } // // c.ServeSuccessJSON(map[string]interface{}{ // "msg": "ok", // "schedule": &schedule, // }) //}