package controllers import ( "Xcx_New/enums" "Xcx_New/models" "Xcx_New/service" "fmt" "github.com/astaxie/beego" "github.com/jinzhu/gorm" "time" ) type DoctorScheduleApiController struct { BaseAuthAPIController } func DoctorScheduleRouters() { beego.Router("/api/schedules/savedoctorschedules", &DoctorScheduleApiController{}, "Get:SaveDoctorSchedules") beego.Router("/api/schedules/getdoctorschedulelist", &DoctorScheduleApiController{}, "Get:GetDoctorScheduleList") beego.Router("/api/schedules/getscheduledetail", &DoctorScheduleApiController{}, "Get:GetScheduleDetail") beego.Router("/api/schedules/updateschedule", &DoctorScheduleApiController{}, "Get:UpdateSchedule") beego.Router("/api/schedule/deleteschedule", &DoctorScheduleApiController{}, "Get:DeleteSchedule") beego.Router("/api/schedule/getdoctorlist", &DoctorScheduleApiController{}, "Get:GetDoctorList") beego.Router("/api/schedule/getschedulelist", &DoctorScheduleApiController{}, "Get:GetScheduleList") beego.Router("/api/schedule/addschedule", &DoctorScheduleApiController{}, "Get:AddSchedule") beego.Router("/api/schedule/getstaffschedulelist", &DoctorScheduleApiController{}, "Get:GetStaffScheduleList") beego.Router("/api/schedule/getnextweeklist", &DoctorScheduleApiController{}, "Get:GetNextWeekList") beego.Router("/api/schedule/getschedulebydoctorid", &DoctorScheduleApiController{}, "Get:GetScheduleByDoctorId") beego.Router("/api/schedule/tosearchsechedulelist", &DoctorScheduleApiController{}, "Get:ToSearchScheduleList") beego.Router("api/schedule/deletestaffschedule", &DoctorScheduleApiController{}, "Get:DeleteStaffSchedule") beego.Router("/api/schedule/copystaffschedule", &DoctorScheduleApiController{}, "Get:CopyStaffSchedule") beego.Router("/api/scheudle/updatecontinusschedule", &DoctorScheduleApiController{}, "Get:UpdateContinusSchedule") beego.Router("/api/schedule/savenursesort", &DoctorScheduleApiController{}, "Get:SaveNureSort") beego.Router("/api/schedule/saveisschedule", &DoctorScheduleApiController{}, "Get:SaveIsSchedule") beego.Router("/api/schedule/getscheudlelisttotal", &DoctorScheduleApiController{}, "Get:GetScheduleListTotal") beego.Router("/api/schedule/tosearchtotal", &DoctorScheduleApiController{}, "Get:ToSeachTotal") beego.Router("/api/schedule/changeoption", &DoctorScheduleApiController{}, "Get:ChangeOption") beego.Router("/api/schedule/getchartlist", &DoctorScheduleApiController{}, "Get:GetChartlist") } func (this *DoctorScheduleApiController) SaveDoctorSchedules() { adminUser := this.GetAdminUserInfo() orgId := adminUser.CurrentOrgId class_name := this.GetString("class_name") class_attributes, _ := this.GetInt64("class_attributes") timeone_start := this.GetString("timeone_start") timeone_type, _ := this.GetInt64("timeone_type") timeone_end := this.GetString("timeone_end") timetwo_start := this.GetString("timetwo_start") timetwo_type, _ := this.GetInt64("timetwo_type") timetwo_end := this.GetString("timetwo_end") work_time := this.GetString("work_time") remarks := this.GetString("remarks") minute, _ := this.GetInt64("minute") schedules := models.DoctorSchedules{ ClassName: class_name, ClassAttributes: class_attributes, TimeoneStart: timeone_start, TimeoneType: timeone_type, TimeoneEnd: timeone_end, TimetwoStart: timetwo_start, TimetwoEnd: timetwo_end, TimetwoType: timetwo_type, WorkTime: work_time, Remarks: remarks, UserOrgId: orgId, Status: 1, Ctime: time.Now().Unix(), Minute: minute, } //查询班种名称是否存在 _, errcode := service.GetClassName(orgId, class_name) //如果不存在 if errcode == gorm.ErrRecordNotFound { err := service.CreateDotorSchedule(&schedules) if err != nil { this.ServeFailJsonSend(enums.ErrorCodeDataException, "添加设备失败") return } this.ServeSuccessJSON(map[string]interface{}{ "schedules": schedules, }) } else if errcode == nil { this.ServeFailJsonSend(enums.ErrorCodeDataException, "班种名称已存在") return } } func (this *DoctorScheduleApiController) GetDoctorScheduleList() { adminUserInfo := this.GetAdminUserInfo() orgId := adminUserInfo.CurrentOrgId page, _ := this.GetInt64("page") limit, _ := this.GetInt64("limit") schedules, total, err := service.GetDoctorScheduleList(orgId, page, limit) if err != nil { this.ServeFailJsonSend(enums.ErrorCodeDataException, "添加设备失败") return } this.ServeSuccessJSON(map[string]interface{}{ "schedules": schedules, "total": total, }) //查询该机构是否有班种,如果没有去读系统默认的 //_, errcode := service.GetDoctorScheduleByOrgId(orgId) //if errcode == gorm.ErrRecordNotFound{ // schedules, total, err := service.GetDoctorScheduleList(0,page, limit) // if err != nil { // this.ServeFailJsonSend(enums.ErrorCodeDataException, "添加设备失败") // return // } // // this.ServeSuccessJSON(map[string]interface{}{ // "schedules": schedules, // "total":total, // }) //}else if errcode == nil{ // schedules, total, err := service.GetDoctorScheduleList(orgId, page, limit) // if err != nil { // this.ServeFailJsonSend(enums.ErrorCodeDataException, "添加设备失败") // return // } // // this.ServeSuccessJSON(map[string]interface{}{ // "schedules": schedules, // "total":total, // }) //} } func (this *DoctorScheduleApiController) GetScheduleDetail() { id, _ := this.GetInt64("id") scheduleDetail, err := service.GetScheduleDetail(id) if err != nil { this.ServeFailJsonSend(enums.ErrorCodeDataException, "添加设备失败") return } this.ServeSuccessJSON(map[string]interface{}{ "scheduleDetail": scheduleDetail, }) } func (this *DoctorScheduleApiController) UpdateSchedule() { id, _ := this.GetInt64("id") class_name := this.GetString("class_name") class_attributes, _ := this.GetInt64("class_attributes") timeone_start := this.GetString("timeone_start") timeone_type, _ := this.GetInt64("timeone_type") timeone_end := this.GetString("timeone_end") timetwo_start := this.GetString("timetwo_start") timetwo_type, _ := this.GetInt64("timetwo_type") timetwo_end := this.GetString("timetwo_end") work_time := this.GetString("work_time") remarks := this.GetString("remarks") user_org_id, _ := this.GetInt64("user_org_id") minute, _ := this.GetInt64("minute") schedules := models.DoctorSchedules{ ClassName: class_name, ClassAttributes: class_attributes, TimeoneStart: timeone_start, TimeoneType: timeone_type, TimeoneEnd: timeone_end, TimetwoStart: timetwo_start, TimetwoEnd: timetwo_end, TimetwoType: timetwo_type, WorkTime: work_time, Remarks: remarks, Minute: minute, } if user_org_id == 0 { err := service.CreateDotorSchedule(&schedules) if err != nil { this.ServeFailJsonSend(enums.ErrorCodeDataException, "添加设备失败") return } } else { //查询是否班种名称已存在 scheduledata, _ := service.GetClassNameIsExsit(class_name, user_org_id, id) if scheduledata.ID > 0 && scheduledata.ID != id { this.ServeFailJsonSend(enums.ErrorCodeDataException, "班种名称已存在") return } err := service.UpdateScheduleList(id, &schedules) if err != nil { this.ServeFailJsonSend(enums.ErrorCodeDataException, "添加设备失败") return } } this.ServeSuccessJSON(map[string]interface{}{ "schedules": schedules, }) } func (this *DoctorScheduleApiController) DeleteSchedule() { adminUserInfo := this.GetAdminUserInfo() orgId := adminUserInfo.CurrentOrgId id, _ := this.GetInt64("id") //产寻该班种是否存在排班,如果存在不能删除 _, errcode := service.GetStaffScheduleByScheduleType(id, orgId) if errcode == gorm.ErrRecordNotFound { err := service.DeleteScheduleById(id) if err != nil { this.ServeFailJsonSend(enums.ErrorCodeDataException, "添加设备失败") return } returnData := make(map[string]interface{}, 0) returnData["msg"] = "ok" this.ServeSuccessJSON(returnData) return } else if errcode == nil { this.ServeFailJsonSend(enums.ErrorCodeDataException, "该班种已存在排班,不能删除") return } } func (this *DoctorScheduleApiController) GetDoctorList() { orgId := this.GetAdminUserInfo().CurrentOrgId appId := this.GetAdminUserInfo().CurrentAppId //admin_user_id := this.GetAdminUserInfo().AdminUser.Id list, err := service.GetDoctorList(orgId, appId) //获取所有的医生 doctorList, err := service.GetAllDoctorList(orgId, appId) //获取所有的护士 nurseList, err := service.GetAllNurseList(orgId, appId) if err != nil { this.ServeFailJsonSend(enums.ErrorCodeDataException, "添加设备失败") return } this.ServeSuccessJSON(map[string]interface{}{ "list": list, "doctorlist": doctorList, "nurselist": nurseList, }) } func (this *DoctorScheduleApiController) GetScheduleList() { orgId := this.GetAdminUserInfo().CurrentOrgId _, errcode := service.GetDoctorScheduleByOrgId(orgId) if errcode == gorm.ErrRecordNotFound { scheduleList, err := service.GetScheduleList(0) if err != nil { this.ServeFailJsonSend(enums.ErrorCodeDataException, "添加设备失败") return } this.ServeSuccessJSON(map[string]interface{}{ "scheduleList": scheduleList, }) } else { scheduleList, err := service.GetScheduleList(orgId) if err != nil { this.ServeFailJsonSend(enums.ErrorCodeDataException, "添加设备失败") return } this.ServeSuccessJSON(map[string]interface{}{ "scheduleList": scheduleList, }) } } func (this *DoctorScheduleApiController) AddSchedule() { orgId := this.GetAdminUserInfo().CurrentOrgId doctor_id, _ := this.GetInt64("doctor_id") fmt.Println("doctor_id", doctor_id) doctor_type, _ := this.GetInt64("doctor_type") fmt.Println("doctor_type", doctor_type) start_time, _ := this.GetInt64("start_time") fmt.Println("start_time", start_time) end_time, _ := this.GetInt64("end_time") fmt.Println("end_time", end_time) schedule_type, _ := this.GetInt64("schedule_type") fmt.Println("schedule_type", schedule_type) schedule_week, _ := this.GetInt64("schedule_week") fmt.Println("schedule_week", schedule_week) schedule_date, _ := this.GetInt64("schedule_date") schedule := models.StaffSchedule{ DoctorId: doctor_id, DoctorType: doctor_type, ScheduleType: schedule_type, ScheduleWeek: schedule_week, UserOrgId: orgId, StartTime: start_time, EndTime: end_time, Status: 1, Ctime: time.Now().Unix(), ScheduleDate: schedule_date, } _, errcode := service.GetScheduleListDetail(doctor_id, orgId, schedule_date) fmt.Println("errcode-----", errcode) if errcode == gorm.ErrRecordNotFound { err := service.AddSchedule(&schedule) if err != nil { this.ServeFailJsonSend(enums.ErrorCodeDataException, "添加设备失败") return } this.ServeSuccessJSON(map[string]interface{}{ "schedule": schedule, }) } else if errcode == nil { schedules, _ := service.GetScheduleListDetail(doctor_id, orgId, schedule_date) err := service.UpdateStaffList(&schedule, schedules.ID) if err != nil { this.ServeFailJsonSend(enums.ErrorCodeDataException, "添加设备失败") return } this.ServeSuccessJSON(map[string]interface{}{ "schedule": schedule, }) } } func (this *DoctorScheduleApiController) GetStaffScheduleList() { start_time, _ := this.GetInt64("start_time") fmt.Println("start_time", start_time) end_time, _ := this.GetInt64("end_time") fmt.Println("end_time", end_time) orgId := this.GetAdminUserInfo().CurrentOrgId staffList, err := service.GetStaffScheduleList(orgId, start_time, end_time) if err != nil { this.ServeFailJsonSend(enums.ErrorCodeDataException, "添加设备失败") return } this.ServeSuccessJSON(map[string]interface{}{ "staffList": staffList, }) } func (this *DoctorScheduleApiController) GetNextWeekList() { start_time, _ := this.GetInt64("start_time") fmt.Println("start_time", start_time) end_time, _ := this.GetInt64("end_time") fmt.Println("end_time", end_time) orgId := this.GetAdminUserInfo().CurrentOrgId staffList, err := service.GetStaffScheduleList(orgId, start_time, end_time) if err != nil { this.ServeFailJsonSend(enums.ErrorCodeDataException, "添加设备失败") return } this.ServeSuccessJSON(map[string]interface{}{ "staffList": staffList, }) } func (this *DoctorScheduleApiController) GetScheduleByDoctorId() { doctor_id, _ := this.GetInt64("doctor_id") start_time, _ := this.GetInt64("start_time") end_time, _ := this.GetInt64("end_time") orgId := this.GetAdminUserInfo().CurrentOrgId staffList, err := service.GetScheduleByDoctorId(doctor_id, start_time, end_time, orgId) if err != nil { this.ServeFailJsonSend(enums.ErrorCodeDataException, "添加设备失败") return } this.ServeSuccessJSON(map[string]interface{}{ "staffList": staffList, }) } func (this *DoctorScheduleApiController) ToSearchScheduleList() { //doctor_id, _ := this.GetInt64("doctor_id") user_name := this.GetString("user_name") start_time, _ := this.GetInt64("start_time") end_time, _ := this.GetInt64("end_time") orgId := this.GetAdminUserInfo().CurrentOrgId staffList, err := service.ToSearchSeacheduleList(user_name, start_time, end_time, orgId) if err != nil { this.ServeFailJsonSend(enums.ErrorCodeDataException, "添加设备失败") return } this.ServeSuccessJSON(map[string]interface{}{ "staffList": staffList, }) } func (this *DoctorScheduleApiController) DeleteStaffSchedule() { adminUserInfo := this.GetAdminUserInfo() orgId := adminUserInfo.CurrentOrgId start_time, _ := this.GetInt64("start_time") fmt.Println("start_time", start_time) end_time, _ := this.GetInt64("end_time") err := service.DeleteStaffSchedule(orgId, start_time, end_time) if err != nil { this.ServeFailJsonSend(enums.ErrorCodeDataException, "添加设备失败") return } returnData := make(map[string]interface{}, 0) returnData["msg"] = "ok" this.ServeSuccessJSON(returnData) return } func (this *DoctorScheduleApiController) CopyStaffSchedule() { adminUserInfo := this.GetAdminUserInfo() orgId := adminUserInfo.CurrentOrgId start_time, _ := this.GetInt64("start_time") fmt.Println("start_time", start_time) end_time, _ := this.GetInt64("end_time") fmt.Println("end_time", end_time) copy_startime, _ := this.GetInt64("copy_startime") fmt.Println("copy_startime", copy_startime) copy_endtime, _ := this.GetInt64("copy_endtime") schedule, err := service.GetStaffScheduleListTwo(orgId, start_time, end_time) //查询选中日期的排班是否存在 _, errcode := service.GetNextWeekSchedule(orgId, copy_startime, copy_endtime) if errcode == gorm.ErrRecordNotFound { for _, item := range schedule { //fmt.Println(item.StartTime+604800) //礼拜1 if item.ScheduleWeek == 1 { item.ScheduleDate = copy_startime } if item.ScheduleWeek == 2 { item.ScheduleDate = copy_startime + 86400 } if item.ScheduleWeek == 3 { item.ScheduleDate = copy_startime + 172800 } if item.ScheduleWeek == 4 { item.ScheduleDate = copy_startime + 259200 } if item.ScheduleWeek == 5 { item.ScheduleDate = copy_startime + 345600 } if item.ScheduleWeek == 6 { item.ScheduleDate = copy_startime + 432000 } //礼拜天 if item.ScheduleWeek == 0 { item.ScheduleDate = copy_endtime } staffSchedule := models.StaffSchedule{ DoctorId: item.DoctorId, DoctorType: item.DoctorType, ScheduleType: item.ScheduleType, ScheduleWeek: item.ScheduleWeek, UserOrgId: item.UserOrgId, StartTime: copy_startime, EndTime: copy_endtime, Status: 1, Ctime: time.Now().Unix(), ScheduleDate: item.ScheduleDate, } service.AddSchedule(&staffSchedule) } if err != nil { this.ServeFailJsonSend(enums.ErrorCodeDataException, "添加设备失败") return } returnData := make(map[string]interface{}, 0) returnData["msg"] = "ok" this.ServeSuccessJSON(returnData) return } else if errcode == nil { this.ServeFailJsonSend(enums.ErrorCodeDataException, "排班数据已存在") fmt.Print("下周排班已存在") return } } func (this *DoctorScheduleApiController) UpdateContinusSchedule() { adminUserInfo := this.GetAdminUserInfo() orgId := adminUserInfo.CurrentOrgId is_status, _ := this.GetInt64("is_status") fmt.Println("is_status", is_status) schedule := models.ContinueSchedule{ IsStatus: is_status, } err := service.UpdateContinusSchedule(&schedule, orgId) if err != nil { this.ServeFailJsonSend(enums.ErrorCodeDataException, "添加设备失败") return } this.ServeSuccessJSON(map[string]interface{}{ "schedule": schedule, }) } func (this *DoctorScheduleApiController) SaveNureSort() { id, _ := this.GetInt64("id") fmt.Println("id", id) sort, _ := this.GetInt64("sort") fmt.Println("sort", sort) role := models.App_Role{ Sort: sort, } err := service.SaveNurseSort(&role, id) if err != nil { this.ServeFailJsonSend(enums.ErrorCodeDataException, "添加设备失败") return } this.ServeSuccessJSON(map[string]interface{}{ "role": role, }) } func (this *DoctorScheduleApiController) SaveIsSchedule() { id, _ := this.GetInt64("id") fmt.Println("id", id) is_sort, _ := this.GetInt64("is_sort") fmt.Println("is_sort", is_sort) role := models.App_Role{ IsSort: is_sort, } err := service.SaveIsSchedule(id, &role) if err != nil { this.ServeFailJsonSend(enums.ErrorCodeDataException, "添加设备失败") return } this.ServeSuccessJSON(map[string]interface{}{ "role": role, }) } func (this *DoctorScheduleApiController) GetScheduleListTotal() { start_time, _ := this.GetInt64("start_time") fmt.Println(start_time) end_time, _ := this.GetInt64("end_time") fmt.Println("end_time", end_time) adminUserInfo := this.GetAdminUserInfo() orgId := adminUserInfo.CurrentOrgId //统计班次 scheudletotal, err := service.GetScheduleListTotal(orgId, start_time, end_time) //统计总工时 list, err := service.GetTotalMinutes(orgId, start_time, end_time) //统计出勤天数 workDay, err := service.GetTotalWorkDay(orgId, start_time, end_time) //统计缺勤天数 noWorkDay, err := service.GetTotalNoWorkDay(orgId, start_time, end_time) if err != nil { this.ServeFailJsonSend(enums.ErrorCodeDataException, "添加设备失败") return } this.ServeSuccessJSON(map[string]interface{}{ "scheudletotal": scheudletotal, "list": list, "workDay": workDay, "noWorkDay": noWorkDay, }) } func (this *DoctorScheduleApiController) ToSeachTotal() { start_time, _ := this.GetInt64("start_time") end_time, _ := this.GetInt64("end_time") adminUserInfo := this.GetAdminUserInfo() orgId := adminUserInfo.CurrentOrgId keyword := this.GetString("keyword") //统计表 scheduletotal, err := service.GetSearchScheduleListTotal(orgId, start_time, end_time, keyword) list, err := service.GeSearchtTotalMinutes(orgId, start_time, end_time, keyword) workDay, err := service.GetSearchWorkDay(orgId, start_time, end_time, keyword) noWorkDay, err := service.GetSearchWorkNoDay(orgId, start_time, end_time, keyword) //统计图 chartTotalMinute, err := service.GetChartTotalMinutesOne(orgId, start_time, end_time, keyword) chartWorkDayMinute, err := service.GetChartTotalMinutesTwo(orgId, start_time, end_time, keyword) if err != nil { this.ServeFailJsonSend(enums.ErrorCodeDataException, "添加设备失败") return } this.ServeSuccessJSON(map[string]interface{}{ "scheduletotal": scheduletotal, "list": list, "workDay": workDay, "noWorkDay": noWorkDay, "chartTotalMinute": chartTotalMinute, "chartWorkDayMinute": chartWorkDayMinute, }) } func (this *DoctorScheduleApiController) ChangeOption() { start_time, _ := this.GetInt64("start_time") end_time, _ := this.GetInt64("end_time") adminUserInfo := this.GetAdminUserInfo() orgId := adminUserInfo.CurrentOrgId doctor_type, _ := this.GetInt64("doctor_type") //统计图 scheduletotal, err := service.ChagneScheduleListTotal(orgId, start_time, end_time, doctor_type) list, err := service.ChangeScheduleMinute(orgId, start_time, end_time, doctor_type) workday, err := service.ChangeWorkDay(orgId, start_time, end_time, doctor_type) worknoday, err := service.ChangeNoWorkDay(orgId, start_time, end_time, doctor_type) //统计表 chartotalminute, err := service.ChartTotalMinute(orgId, start_time, end_time, doctor_type) chartworkdayminute, err := service.ChartWorkDayMinute(orgId, start_time, end_time, doctor_type) if err != nil { this.ServeFailJsonSend(enums.ErrorCodeDataException, "添加设备失败") return } this.ServeSuccessJSON(map[string]interface{}{ "scheduletotal": scheduletotal, "list": list, "workday": workday, "worknoday": worknoday, "chartotalminute": chartotalminute, "chartworkdayminute": chartworkdayminute, }) } func (this *DoctorScheduleApiController) GetChartlist() { start_time, _ := this.GetInt64("start_time") end_time, _ := this.GetInt64("end_time") adminUserInfo := this.GetAdminUserInfo() orgId := adminUserInfo.CurrentOrgId //统计总工时 list, err := service.GetTotalMinutesOne(orgId, start_time, end_time) //统计出勤的总工时 workDaylist, err := service.GetTotalMinutesTwo(orgId, start_time, end_time) if err != nil { this.ServeFailJsonSend(enums.ErrorCodeDataException, "添加设备失败") return } this.ServeSuccessJSON(map[string]interface{}{ "list": list, "workDaylist": workDaylist, }) }