package controllers import ( "XT_New/enums" "XT_New/models" "XT_New/service" "XT_New/utils" "encoding/json" "fmt" "github.com/jinzhu/gorm" "reflect" "strconv" "time" "github.com/astaxie/beego" ) type ScheduleApiController struct { BaseAuthAPIController } func ScheduleApiRegistRouters() { beego.Router("/api/schedule/weekpanel", &ScheduleApiController{}, "Get:GetWeekPanels") beego.Router("/api/schedule/schedules", &ScheduleApiController{}, "Get:GetSchedules") beego.Router("/api/excel_date/init", &ScheduleApiController{}, "Get:GetInitExcelInitDate") beego.Router("/api/schedule/patients", &ScheduleApiController{}, "Get:GetPatients") beego.Router("/api/schedule/create", &ScheduleApiController{}, "Post:CreateSchedule") beego.Router("/api/schedule/delete", &ScheduleApiController{}, "Delete:DeleteSchedule") beego.Router("/api/schedule/change", &ScheduleApiController{}, "Put:ChangeSchedule") beego.Router("/api/schedule/urgentinit", &ScheduleApiController{}, "Get:UrgentScheduleData") beego.Router("/api/schedule/print/initdata", &ScheduleApiController{}, "get:PrintInitData") beego.Router("/api/schedule/search", &ScheduleApiController{}, "get:SearchSchedulePatients") beego.Router("/api/schedule/week", &ScheduleApiController{}, "get:GetWeekDaySchedule") beego.Router("/api/schedule/export", &ScheduleApiController{}, "post:ExportSchedule") beego.Router("/api/schedule_template/export", &ScheduleApiController{}, "post:ExportScheduleTemplate") } func (c *ScheduleApiController) GetWeekPanels() { data, _ := c.GetInt64("data", 1) adminInfo := c.GetAdminUserInfo() thisTime := time.Now() year, monthTime, day := thisTime.Date() month := int(monthTime) _, theWeek := thisTime.ISOWeek() weekDay := int(thisTime.Weekday()) if weekDay == 0 { weekDay = 7 } weekEnd := 7 - weekDay weekStart := weekEnd - 6 weekDays := make([]string, 0) for index := weekStart; index <= weekEnd; index++ { theDay := thisTime.AddDate(0, 0, index) indexYear, indexMonthTime, indexDay := theDay.Date() indexMonth := int(indexMonthTime) indexWeek := strconv.Itoa(indexYear) + "." + strconv.Itoa(indexMonth) + "." + strconv.Itoa(indexDay) weekDays = append(weekDays, indexWeek) } returnData := map[string]interface{}{ "year": year, "month": month, "day": day, "theWeek": theWeek, "weekDay": weekDay, "weekDays": weekDays, } if data == 1 { partitions, _ := service.GetSchedulePartitionPanel(adminInfo.CurrentOrgId) returnData["partitions"] = partitions } c.ServeSuccessJSON(returnData) return } func (c *ScheduleApiController) GetSchedules() { week, _ := c.GetInt64("weekTime", 0) //1:last, 2:this 3:next 4 nextTwo adminInfo := c.GetAdminUserInfo() thisTime := time.Now() today := thisTime.Format("2006-01-02") if week < 1 || week > 4 { week = 2 } if week == 1 { thisTime = thisTime.AddDate(0, 0, -7) } else if week == 3 { thisTime = thisTime.AddDate(0, 0, 7) } else if week == 4 { thisTime = thisTime.AddDate(0, 0, 14) } weekDay := int(thisTime.Weekday()) if weekDay == 0 { weekDay = 7 } weekEnd := 7 - weekDay weekStart := weekEnd - 6 weekTitle := make([]string, 0) days := make([]string, 0) for index := weekStart; index <= weekEnd; index++ { theDay := thisTime.AddDate(0, 0, index) indexYear, indexMonthTime, indexDay := theDay.Date() indexMonth := int(indexMonthTime) indexWeek := strconv.Itoa(indexYear) + "." + strconv.Itoa(indexMonth) + "." + strconv.Itoa(indexDay) weekTitle = append(weekTitle, indexWeek) days = append(days, theDay.Format("2006-01-02")) } weekStartDay := thisTime.AddDate(0, 0, weekStart) weekEndDay := thisTime.AddDate(0, 0, weekEnd) weekStartTime := weekStartDay.Format("2006-01-02") + " 00:00:00" weekEndTime := weekEndDay.Format("2006-01-02") + " 23:59:59" timeLayout := "2006-01-02 15:04:05" loc, _ := time.LoadLocation("Local") theStarTime, _ := time.ParseInLocation(timeLayout, weekStartTime, loc) theEndTime, _ := time.ParseInLocation(timeLayout, weekEndTime, loc) weekStartPoint := theStarTime.Unix() weekEndPoint := theEndTime.Unix() schdules, _ := service.GetWeekSchedule(adminInfo.CurrentOrgId, weekStartPoint, weekEndPoint) c.ServeSuccessJSON(map[string]interface{}{ "days": days, "weekTitle": weekTitle, "schdules": schdules, "today": today, }) return } func (c *ScheduleApiController) GetPatients() { keywords := c.GetString("keywords", "") schedule, _ := c.GetInt64("schedule", 0) //1已2未 contagion, _ := c.GetInt64("contagion", 0) adminInfo := c.GetAdminUserInfo() thisTime := time.Now() weekDay := int(thisTime.Weekday()) if weekDay == 0 { weekDay = 7 } thisWeekEnd := 7 - weekDay weekStartPoint := thisWeekEnd - 6 weekStartDay := thisTime.AddDate(0, 0, weekStartPoint) weekEndPoint := thisWeekEnd + 7 weekEndDay := thisTime.AddDate(0, 0, weekEndPoint) fmt.Println(weekStartPoint, weekStartDay, weekEndPoint, weekEndDay) weekStartTime := weekStartDay.Format("2006-01-02") + " 00:00:00" weekEndTime := weekEndDay.Format("2006-01-02") + " 23:59:59" fmt.Println(weekStartTime, weekEndTime) timeLayout := "2006-01-02 15:04:05" loc, _ := time.LoadLocation("Local") theStarTime, _ := time.ParseInLocation(timeLayout, weekStartTime, loc) theEndTime, _ := time.ParseInLocation(timeLayout, weekEndTime, loc) weekStart := theStarTime.Unix() weekEnd := theEndTime.Unix() patients, _ := service.GetPatientWithScheduleAndSolution(adminInfo.CurrentOrgId, keywords, weekStart, weekEnd, schedule, contagion) c.ServeSuccessJSON(map[string]interface{}{ "patients": patients, }) return } func (c *ScheduleApiController) CreateSchedule() { patientID, _ := c.GetInt64("patient_id", 0) if patientID <= 0 { c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong) return } adminUserInfo := c.GetAdminUserInfo() patientInfo, _ := service.FindPatientById(adminUserInfo.CurrentOrgId, patientID) if patientInfo.ID == 0 { c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist) return } var schedule models.Schedule dataBody := make(map[string]interface{}, 0) err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody) if err != nil { utils.ErrorLog(err.Error()) c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong) return } if dataBody["schedule_date"] == nil || reflect.TypeOf(dataBody["schedule_date"]).String() != "string" { c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong) return } scheduleDate, _ := dataBody["schedule_date"].(string) if len(scheduleDate) == 0 { utils.ErrorLog("len(schedule_date) == 0") c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong) return } timeLayout := "2006-01-02" loc, _ := time.LoadLocation("Local") theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", scheduleDate+" 00:00:00", loc) if err != nil { utils.ErrorLog(err.Error()) c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong) return } schedule.ScheduleDate = theTime.Unix() timeNow := time.Now().Format("2006-01-02") if timeNow > scheduleDate { utils.ErrorLog(timeNow) utils.ErrorLog(scheduleDate) c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCantSetScheduleBeforeNow) return } if dataBody["schedule_type"] == nil || reflect.TypeOf(dataBody["schedule_type"]).String() != "float64" { utils.ErrorLog("schedule_type") c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong) return } scheduleType := int64(dataBody["schedule_type"].(float64)) if scheduleType < 1 || scheduleType > 3 { utils.ErrorLog("scheduleType < 3") c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong) return } schedule.ScheduleType = scheduleType if dataBody["bed_id"] == nil || reflect.TypeOf(dataBody["bed_id"]).String() != "float64" { utils.ErrorLog("bed_id") c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong) return } bedId := int64(dataBody["bed_id"].(float64)) if bedId < 1 { utils.ErrorLog("bedId < 1") c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong) return } schedule.BedId = bedId if dataBody["partition_id"] == nil || reflect.TypeOf(dataBody["partition_id"]).String() != "float64" { utils.ErrorLog("partition_id") c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong) return } partitionId := int64(dataBody["partition_id"].(float64)) if partitionId < 1 { utils.ErrorLog("partitionId < 1") c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong) return } schedule.PartitionId = partitionId if dataBody["schedule_week"] == nil || reflect.TypeOf(dataBody["schedule_week"]).String() != "float64" { utils.ErrorLog("schedule_week") c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong) return } scheduleWeek := int64(dataBody["schedule_week"].(float64)) if scheduleWeek < 1 || scheduleWeek > 7 { utils.ErrorLog("scheduleWeek < 1") c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong) return } schedule.ScheduleWeek = scheduleWeek if dataBody["mode_id"] == nil || reflect.TypeOf(dataBody["mode_id"]).String() != "float64" { utils.ErrorLog("mode_id") c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong) return } modeId := int64(dataBody["mode_id"].(float64)) if modeId < 1 && modeId > 14 { utils.ErrorLog("modeId < 1") c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong) return } schedule.ModeId = modeId schedule.PatientId = patientID schedule.CreatedTime = time.Now().Unix() schedule.UpdatedTime = time.Now().Unix() schedule.Status = 1 schedule.UserOrgId = adminUserInfo.CurrentOrgId bed, _ := service.GetDeviceNumberByID(adminUserInfo.CurrentOrgId, schedule.BedId) if bed == nil { c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeviceNumberNotExist) return } if bed.ZoneID != schedule.PartitionId { c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeviceNumberNotTheZone) return } scheduleDateStart := scheduleDate + " 00:00:00" scheduleDateEnd := scheduleDate + " 23:59:59" timeLayout = "2006-01-02 15:04:05" theStartTime, _ := time.ParseInLocation(timeLayout, scheduleDateStart, loc) theEndTime, _ := time.ParseInLocation(timeLayout, scheduleDateEnd, loc) startTime := theStartTime.Unix() endTime := theEndTime.Unix() //一天只有排班一次 daySchedule, err := service.GetDaySchedule(adminUserInfo.CurrentOrgId, startTime, endTime, patientID) if daySchedule.ID > 0 { c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCantSetScheduleAgainOneDay) return } //同天同位置只能排一个 pointSchedule, err := service.GetPointSchedule(adminUserInfo.CurrentOrgId, schedule.ScheduleDate, schedule.ScheduleWeek, schedule.ScheduleType, schedule.BedId) if err != nil { c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException) return } if pointSchedule.ID > 0 { c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePointScheduleExist) return } err = service.CreateSchedule(&schedule) fmt.Println(err) if err != nil { c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateScheduleFail) return } schedule.Patient = patientInfo.Name c.ServeSuccessJSON(map[string]interface{}{ "msg": "ok", "schedule": schedule, }) return } func (c *ScheduleApiController) DeleteSchedule() { id, _ := c.GetInt64("id", 0) if id <= 0 { c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong) return } adminINfo := c.GetAdminUserInfo() schedule, _ := service.GetSchedule(adminINfo.CurrentOrgId, id) 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.ErrorCodeDelScheduleFailByDialysis) return } schedule.Status = 0 schedule.UpdatedTime = time.Now().Unix() err = service.UpdateSchedule(schedule) if err != nil { c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeleteScheduleFail) return } c.ServeSuccessJSON(map[string]interface{}{ "msg": "ok", "schedule": &schedule, }) } func (c *ScheduleApiController) ChangeSchedule() { id, _ := c.GetInt64("id", 0) if id <= 0 { c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong) return } adminINfo := c.GetAdminUserInfo() schedule, _ := service.GetSchedule(adminINfo.CurrentOrgId, id) if schedule == nil { c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeScheduleNotExist) return } dataBody := make(map[string]interface{}, 0) err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody) if err != nil { utils.ErrorLog(err.Error()) c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong) return } if dataBody["change_action"] == nil || reflect.TypeOf(dataBody["change_action"]).String() != "string" { utils.ErrorLog("change_action") c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong) return } changeAction := dataBody["change_action"].(string) if changeAction == "change_mode" { if dataBody["mode_id"] == nil || reflect.TypeOf(dataBody["mode_id"]).String() != "float64" { utils.ErrorLog("mode_id") c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong) return } modeId := int64(dataBody["mode_id"].(float64)) if modeId < 1 { utils.ErrorLog("modeId < 1") c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong) return } schedule.ModeId = modeId order, err := service.GetOneDialysisOrder(adminINfo.CurrentOrgId, schedule.ScheduleDate, schedule.PatientId) if err != nil { c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException) return } if order != nil { c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeChangeMode) return } } else if changeAction == "change_device" { order, err := service.GetOneDialysisOrder(adminINfo.CurrentOrgId, schedule.ScheduleDate, schedule.PatientId) if err != nil { c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException) return } if order != nil { c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeChangeDeviceNumber) return } if dataBody["schedule_type"] == nil || reflect.TypeOf(dataBody["schedule_type"]).String() != "float64" { utils.ErrorLog("schedule_type") c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong) return } scheduleType := int64(dataBody["schedule_type"].(float64)) if scheduleType < 1 || scheduleType > 3 { utils.ErrorLog("scheduleType < 3") c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong) return } schedule.ScheduleType = scheduleType if dataBody["bed_id"] == nil || reflect.TypeOf(dataBody["bed_id"]).String() != "float64" { utils.ErrorLog("bed_id") c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong) return } bedId := int64(dataBody["bed_id"].(float64)) if bedId < 1 { utils.ErrorLog("bedId < 1") c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong) return } schedule.BedId = bedId if dataBody["partition_id"] == nil || reflect.TypeOf(dataBody["partition_id"]).String() != "float64" { utils.ErrorLog("partition_id") c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong) return } partitionId := int64(dataBody["partition_id"].(float64)) if partitionId < 1 { utils.ErrorLog("partitionId < 1") c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong) return } schedule.PartitionId = partitionId bed, _ := service.GetDeviceNumberByID(adminINfo.CurrentOrgId, schedule.BedId) if bed == nil { c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeviceNumberNotExist) return } if bed.ZoneID != schedule.PartitionId { c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeviceNumberNotTheZone) return } startTime := schedule.ScheduleDate endTime := startTime + 86399 //一天只有排班一次 daySchedule, err := service.GetDaySchedule(adminINfo.CurrentOrgId, startTime, endTime, schedule.PatientId) if daySchedule.ID > 0 && daySchedule.ID != schedule.ID { c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCantSetScheduleAgainOneDay) return } //同天同位置只能排一个 pointSchedule, err := service.GetPointSchedule(adminINfo.CurrentOrgId, schedule.ScheduleDate, schedule.ScheduleWeek, schedule.ScheduleType, schedule.BedId) if err != nil { c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException) return } if pointSchedule.ID > 0 { c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePointScheduleExist) return } } else { c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong) return } schedule.UpdatedTime = time.Now().Unix() err = service.UpdateSchedule(schedule) if err != nil { c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeChangeScheduleFail) return } c.ServeSuccessJSON(map[string]interface{}{ "msg": "ok", "schedule": &schedule, }) } // /api/schedule/print/initdata [get] // @param date:string yyyy-MM-dd 要打印的那一周中的任一天 func (this *ScheduleApiController) PrintInitData() { dateStr := this.GetString("date") var date *time.Time if len(dateStr) == 0 { now := time.Now() date = &now } else { var parseErr error date, parseErr = utils.ParseTimeStringToTime("2006-01-02", dateStr) if parseErr != nil { this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong) return } } adminUserInfo := this.GetAdminUserInfo() // 获取本周的排班 monday, sunday := utils.GetMondayAndSundayOfWeekDate(date) schedules, getScheduleErr := service.GetPrinitWeekSchedules(adminUserInfo.CurrentOrgId, monday.Unix(), sunday.Unix()) if getScheduleErr != nil { this.ErrorLog("获取周排班失败:%v", getScheduleErr) this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException) return } this.ServeSuccessJSON(map[string]interface{}{ "schedules": schedules, "monday": monday.Unix(), }) } func (this *ScheduleApiController) UrgentScheduleData() { schedule_type, _ := this.GetInt("type", 0) schedule_date := this.GetString("date") var date *time.Time if len(schedule_date) == 0 { now := time.Now() date = &now } else { var parseErr error date, parseErr = utils.ParseTimeStringToTime("2006-01-02", schedule_date) if parseErr != nil { this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong) return } } adminUserInfo := this.GetAdminUserInfo() deviceNumbers, getDeviceNumbersErr := service.MobileGetAllDeviceNumbersForUrgentSchedule(adminUserInfo.CurrentOrgId, date.Unix(), schedule_type) if getDeviceNumbersErr != nil { this.ErrorLog("获取所有床位失败:%v", getDeviceNumbersErr) this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException) return } // today := utils.ZeroHourTimeOfDay(time.Now()) schedules, getSchedulesErr := service.MobileGetOtherSchedulesForUrgentSchedule(adminUserInfo.CurrentOrgId, date.Unix(), schedule_type) if getSchedulesErr != nil { this.ErrorLog("获取所有排班失败:%v", getSchedulesErr) this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException) return } this.ServeSuccessJSON(map[string]interface{}{ "device_numbers": deviceNumbers, "schedules": schedules, }) } func (this *ScheduleApiController) SearchSchedulePatients() { keywords := this.GetString("keywords") adminUserInfo := this.GetAdminUserInfo() list, _ := service.GetSchedualPatientsByKeywords(keywords, adminUserInfo.CurrentOrgId) this.ServeSuccessJSON(map[string]interface{}{ "schdules": list, }) } type aa struct { b int64 c int64 } func (this *ScheduleApiController) GetWeekDaySchedule() { week_type, _ := this.GetInt64("week_type", -1) fmt.Println(week_type) thisTime := time.Now() weekDay := int(thisTime.Weekday()) if weekDay == 0 { weekDay = 7 } weekEnd := 7 - weekDay weekStart := weekEnd - 6 weekTitle := make([]string, 0) days := make([]string, 0) for index := weekStart; index <= weekEnd; index++ { theDay := thisTime.AddDate(0, 0, index) indexYear, indexMonthTime, indexDay := theDay.Date() indexMonth := int(indexMonthTime) indexWeek := strconv.Itoa(indexYear) + "." + strconv.Itoa(indexMonth) + "." + strconv.Itoa(indexDay) weekTitle = append(weekTitle, indexWeek) days = append(days, theDay.Format("2006-01-02")) } fmt.Println(days) var targetDayStr string switch week_type { case 1: targetDayStr = days[0] break case 2: targetDayStr = days[1] break case 3: targetDayStr = days[2] break case 4: targetDayStr = days[3] break case 5: targetDayStr = days[4] break case 6: targetDayStr = days[5] break case 7: targetDayStr = days[6] break } targetDay, parseErr := utils.ParseTimeStringToTime("2006-01-02", targetDayStr) if parseErr != nil { this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong) return } adminUserInfo := this.GetAdminUserInfo() list, _ := service.GetWeekDaySchedule(adminUserInfo.CurrentOrgId, targetDay.Unix(), targetDay) this.ServeSuccessJSON(map[string]interface{}{ "schdules": list, "day": targetDayStr, }) } func Struct2Map(obj interface{}) map[string]interface{} { t := reflect.TypeOf(obj) v := reflect.ValueOf(obj) var data = make(map[string]interface{}) for i := 0; i < t.NumField(); i++ { data[t.Field(i).Name] = v.Field(i).Interface() } return data } func (this *ScheduleApiController) ExportSchedule() { dataBody := make(map[string]interface{}, 0) err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody) if err != nil { utils.ErrorLog(err.Error()) return } utils.ErrorLog("%v", dataBody) export_time := time.Now().Unix() var schedules []*models.Schedule var total_schedule []interface{} var patients []*models.Patients patients, _, _ = service.GetAllPatientList(this.GetAdminUserInfo().CurrentOrgId) if dataBody["schedule"] != nil || reflect.TypeOf(dataBody["schedule"]).String() == "[]interface {}" { tempSchedule := dataBody["schedule"].([]interface{}) total_schedule = tempSchedule for _, schMap := range tempSchedule { schMapM := schMap.(map[string]interface{}) var sch models.Schedule if schMapM["name"] == nil || reflect.TypeOf(schMapM["name"]).String() != "string" { utils.ErrorLog("name") return } name, _ := schMapM["name"].(string) fmt.Println(name) if len(name) == 0 { //名字为空则生成一条导入错误日志 err_log := models.ExportErrLog{ LogType: 2, UserOrgId: this.GetAdminUserInfo().CurrentOrgId, ErrMsg: "第" + strconv.FormatInt(int64(schMapM["index"].(float64)), 10) + "行,第" + schMapM["row"].(string) + "列的姓名不能为空", Status: 1, CreateTime: time.Now().Unix(), UpdateTime: time.Now().Unix(), ExportTime: export_time, } service.CreateExportErrLog(&err_log) continue } else { var patient []*models.Patients for _, item := range patients { if item.Name == name { patient = append(patient, item) } } if len(patient) == 0 { //错误日志 err_log := models.ExportErrLog{ LogType: 2, UserOrgId: this.GetAdminUserInfo().CurrentOrgId, ErrMsg: "第" + strconv.FormatInt(int64(schMapM["index"].(float64)), 10) + "行,第" + schMapM["row"].(string) + "列的姓名在系统中不存在,请在系统中添加该病人", Status: 1, CreateTime: time.Now().Unix(), UpdateTime: time.Now().Unix(), ExportTime: export_time, } service.CreateExportErrLog(&err_log) continue } else if len(patient) == 1 { // sch.PatientId = patient[0].ID } else if len(patient) > 1 { //出现同名的情况 err_log := models.ExportErrLog{ LogType: 2, UserOrgId: this.GetAdminUserInfo().CurrentOrgId, ErrMsg: "存在同名同姓的两个病人", Status: 1, CreateTime: time.Now().Unix(), UpdateTime: time.Now().Unix(), ExportTime: export_time, } service.CreateExportErrLog(&err_log) continue } } if schMapM["schedule_type"] == nil && reflect.TypeOf(schMapM["schedule_type"]).String() != "float64" { utils.ErrorLog("schedule_type") return } schedule_type := int64(schMapM["schedule_type"].(float64)) if schedule_type <= 0 { //班次格式有误,插入日志 log := models.ExportLog{ LogType: 2, UserOrgId: this.GetAdminUserInfo().CurrentOrgId, TotalNum: int64(len(total_schedule)), FailNum: 1, SuccessNum: int64(len(schedules)), CreateTime: time.Now().Unix(), UpdateTime: time.Now().Unix(), ExportTime: export_time, Status: 1, } service.CreateExportLog(&log) err_log := models.ExportErrLog{ LogType: 2, UserOrgId: this.GetAdminUserInfo().CurrentOrgId, ErrMsg: "第2行第" + schMapM["row"].(string) + "列的班次格式有误", Status: 1, CreateTime: time.Now().Unix(), UpdateTime: time.Now().Unix(), ExportTime: export_time, } service.CreateExportErrLog(&err_log) this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeExportError) return } else { sch.ScheduleType = schedule_type } if schMapM["partition_name"] == nil || reflect.TypeOf(schMapM["partition_name"]).String() != "string" { utils.ErrorLog("partition_name") return } partition_name, _ := schMapM["partition_name"].(string) if len(partition_name) == 0 { //分区为空 log := models.ExportLog{ LogType: 2, UserOrgId: this.GetAdminUserInfo().CurrentOrgId, TotalNum: int64(len(total_schedule)), FailNum: 1, SuccessNum: int64(len(schedules)), CreateTime: time.Now().Unix(), UpdateTime: time.Now().Unix(), ExportTime: export_time, Status: 1, } service.CreateExportLog(&log) err_log := models.ExportErrLog{ LogType: 2, UserOrgId: this.GetAdminUserInfo().CurrentOrgId, //ErrMsg: "第" + strconv.FormatInt(int64(schMapM["index"].(float64)) ,10)+ "行" + "的姓名不能为空", ErrMsg: "第" + strconv.FormatInt(int64(schMapM["index"].(float64)), 10) + "行第1列所属的分区格式有误", Status: 1, CreateTime: time.Now().Unix(), UpdateTime: time.Now().Unix(), ExportTime: export_time, } service.CreateExportErrLog(&err_log) this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeExportError) return } else { zone, err := service.FindDeviceZoneByName(partition_name, this.GetAdminUserInfo().CurrentOrgId) if err == nil { sch.PartitionId = zone.ID } else if err == gorm.ErrRecordNotFound { //查不到数据,插入错误日志 log := models.ExportLog{ LogType: 2, UserOrgId: this.GetAdminUserInfo().CurrentOrgId, TotalNum: int64(len(total_schedule)), FailNum: 1, SuccessNum: int64(len(schedules)), CreateTime: time.Now().Unix(), UpdateTime: time.Now().Unix(), ExportTime: export_time, Status: 1, } service.CreateExportLog(&log) err_log := models.ExportErrLog{ LogType: 2, UserOrgId: this.GetAdminUserInfo().CurrentOrgId, //ErrMsg: "第" + strconv.FormatInt(int64(schMapM["index"].(float64)) ,10)+ "行" + "的姓名不能为空", ErrMsg: "第" + strconv.FormatInt(int64(schMapM["index"].(float64)), 10) + "行第1列所属的分区格式有误", Status: 1, CreateTime: time.Now().Unix(), UpdateTime: time.Now().Unix(), ExportTime: export_time, } service.CreateExportErrLog(&err_log) this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeExportError) return } } if schMapM["device_number_name"] == nil || reflect.TypeOf(schMapM["device_number_name"]).String() != "string" { utils.ErrorLog("device_number_name") return } device_number_name, _ := schMapM["device_number_name"].(string) if len(device_number_name) == 0 { //分区为空 log := models.ExportLog{ LogType: 2, UserOrgId: this.GetAdminUserInfo().CurrentOrgId, TotalNum: int64(len(total_schedule)), FailNum: 1, SuccessNum: int64(len(schedules)), CreateTime: time.Now().Unix(), UpdateTime: time.Now().Unix(), ExportTime: export_time, Status: 1, } service.CreateExportLog(&log) err_log := models.ExportErrLog{ LogType: 2, UserOrgId: this.GetAdminUserInfo().CurrentOrgId, //ErrMsg: "第" + strconv.FormatInt(int64(schMapM["index"].(float64)) ,10)+ "行" + "的姓名不能为空", ErrMsg: "第" + strconv.FormatInt(int64(schMapM["index"].(float64)), 10) + "行第2列机号格式有误", Status: 1, CreateTime: time.Now().Unix(), UpdateTime: time.Now().Unix(), ExportTime: export_time, } service.CreateExportErrLog(&err_log) this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeExportError) return } else { device, err := service.FindDeviceByName(device_number_name, this.GetAdminUserInfo().CurrentOrgId, sch.PartitionId) if err == nil { if len(device) == 0 { //没查到数据,插入错误日志 log := models.ExportLog{ LogType: 2, UserOrgId: this.GetAdminUserInfo().CurrentOrgId, TotalNum: int64(len(total_schedule)), FailNum: 1, SuccessNum: int64(len(schedules)), CreateTime: time.Now().Unix(), UpdateTime: time.Now().Unix(), ExportTime: export_time, Status: 1, } service.CreateExportLog(&log) err_log := models.ExportErrLog{ LogType: 2, UserOrgId: this.GetAdminUserInfo().CurrentOrgId, ErrMsg: "第" + strconv.FormatInt(int64(schMapM["index"].(float64)), 10) + "行第2列机号格式有误", Status: 1, CreateTime: time.Now().Unix(), UpdateTime: time.Now().Unix(), ExportTime: export_time, } service.CreateExportErrLog(&err_log) this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeExportError) return } else if len(device) == 1 { sch.BedId = device[0].ID } else if len(device) > 1 { //出现重名,插入错误日志 log := models.ExportLog{ LogType: 2, UserOrgId: this.GetAdminUserInfo().CurrentOrgId, TotalNum: int64(len(total_schedule)), FailNum: 1, SuccessNum: int64(len(schedules)), CreateTime: time.Now().Unix(), UpdateTime: time.Now().Unix(), ExportTime: export_time, Status: 1, } service.CreateExportLog(&log) err_log := models.ExportErrLog{ LogType: 2, UserOrgId: this.GetAdminUserInfo().CurrentOrgId, ErrMsg: "出现两个床位号相同的床位", Status: 1, CreateTime: time.Now().Unix(), UpdateTime: time.Now().Unix(), ExportTime: export_time, } service.CreateExportErrLog(&err_log) this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeExportError) return } } } if schMapM["schedule_week"] == nil || reflect.TypeOf(schMapM["schedule_week"]).String() != "string" { utils.ErrorLog("schedule_week") return } schedule_week, _ := schMapM["schedule_week"].(string) if len(schedule_week) == 0 { //周几为空则生成一条导入错误日志 log := models.ExportLog{ LogType: 2, UserOrgId: this.GetAdminUserInfo().CurrentOrgId, TotalNum: int64(len(total_schedule)), FailNum: 1, SuccessNum: int64(len(schedules)), CreateTime: time.Now().Unix(), UpdateTime: time.Now().Unix(), ExportTime: export_time, Status: 1, } service.CreateExportLog(&log) err_log := models.ExportErrLog{ LogType: 2, UserOrgId: this.GetAdminUserInfo().CurrentOrgId, //ErrMsg: "第" + strconv.FormatInt(int64(schMapM["index"].(float64)) ,10)+ "行" + "的姓名不能为空", ErrMsg: "第1行第" + schMapM["row"].(string) + "列的星期名格式有误", Status: 1, CreateTime: time.Now().Unix(), UpdateTime: time.Now().Unix(), ExportTime: export_time, } service.CreateExportErrLog(&err_log) this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeExportError) return } else if schedule_week == "0" { //周几不符合格式则生成一条导入错误日志 log := models.ExportLog{ LogType: 2, UserOrgId: this.GetAdminUserInfo().CurrentOrgId, TotalNum: int64(len(total_schedule)), FailNum: 1, SuccessNum: int64(len(schedules)), CreateTime: time.Now().Unix(), UpdateTime: time.Now().Unix(), ExportTime: export_time, Status: 1, } service.CreateExportLog(&log) err_log := models.ExportErrLog{ LogType: 2, UserOrgId: this.GetAdminUserInfo().CurrentOrgId, ErrMsg: "第1行第" + schMapM["row"].(string) + "列的星期名格式有误", Status: 1, CreateTime: time.Now().Unix(), UpdateTime: time.Now().Unix(), ExportTime: export_time, } service.CreateExportErrLog(&err_log) this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeExportError) return } else { schedule_week, _ := strconv.ParseInt(schedule_week, 10, 64) sch.ScheduleWeek = schedule_week } if schMapM["schedule_date"] == nil || reflect.TypeOf(schMapM["schedule_date"]).String() != "string" { utils.ErrorLog("schedule_date") return } schedule_date, _ := schMapM["schedule_date"].(string) if len(schedule_date) == 0 { //周几为空则生成一条导入错误日志 log := models.ExportLog{ LogType: 2, UserOrgId: this.GetAdminUserInfo().CurrentOrgId, TotalNum: int64(len(total_schedule)), FailNum: 1, SuccessNum: int64(len(schedules)), CreateTime: time.Now().Unix(), UpdateTime: time.Now().Unix(), ExportTime: export_time, Status: 1, } service.CreateExportLog(&log) err_log := models.ExportErrLog{ LogType: 2, UserOrgId: this.GetAdminUserInfo().CurrentOrgId, ErrMsg: "第1行第" + schMapM["row"].(string) + "列的星期名格式有误", Status: 1, CreateTime: time.Now().Unix(), UpdateTime: time.Now().Unix(), ExportTime: export_time, } service.CreateExportErrLog(&err_log) this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeExportError) return } else if schedule_date == "0" { //周几不符合格式则生成一条导入错误日志 log := models.ExportLog{ LogType: 2, UserOrgId: this.GetAdminUserInfo().CurrentOrgId, TotalNum: int64(len(total_schedule)), FailNum: 1, SuccessNum: int64(len(schedules)), CreateTime: time.Now().Unix(), UpdateTime: time.Now().Unix(), ExportTime: export_time, Status: 1, } service.CreateExportLog(&log) err_log := models.ExportErrLog{ LogType: 2, UserOrgId: this.GetAdminUserInfo().CurrentOrgId, ErrMsg: "第1行第" + schMapM["row"].(string) + "列的星期名格式有误", Status: 1, CreateTime: time.Now().Unix(), UpdateTime: time.Now().Unix(), ExportTime: export_time, } service.CreateExportErrLog(&err_log) this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeExportError) return } else { date, _ := utils.ParseTimeStringToTime("2006-01-02", schedule_date) sch.ScheduleDate = date.Unix() } sch.CreatedTime = time.Now().Unix() sch.UpdatedTime = time.Now().Unix() sch.ModeId = 1 sch.Status = 1 sch.UserOrgId = this.GetAdminUserInfo().CurrentOrgId sch.IsExport = 1 schedules = append(schedules, &sch) } errLogs, _ := service.FindSchedualExportLog(this.GetAdminUserInfo().CurrentOrgId, export_time) if len(schedules) > 0 { schedule_date := this.GetString("date") date, _ := utils.ParseTimeStringToTime("2006-01-02", schedule_date) clear_schedule_date := date.Unix() //根据日期去清除,该日期以及未来的排班数据 err := service.UpdateScheduleStatus(clear_schedule_date, this.GetAdminUserInfo().CurrentOrgId) if err == nil { for _, item := range schedules { service.CreateSchedule(item) } log := models.ExportLog{ LogType: 2, UserOrgId: this.GetAdminUserInfo().CurrentOrgId, TotalNum: int64(len(total_schedule)), FailNum: int64(len(errLogs)), SuccessNum: int64(len(schedules)), CreateTime: time.Now().Unix(), UpdateTime: time.Now().Unix(), ExportTime: export_time, Status: 1, } service.CreateExportLog(&log) this.ServeSuccessJSON(map[string]interface{}{ "msg": "导入成功", "total_num": len(total_schedule), "success_num": len(schedules), "fail_num": int64(len(errLogs)), }) } else { log := models.ExportLog{ LogType: 2, UserOrgId: this.GetAdminUserInfo().CurrentOrgId, TotalNum: int64(len(total_schedule)), FailNum: int64(len(errLogs)), SuccessNum: int64(len(schedules)), CreateTime: time.Now().Unix(), UpdateTime: time.Now().Unix(), ExportTime: export_time, Status: 1, } service.CreateExportLog(&log) this.ServeSuccessJSON(map[string]interface{}{ "msg": "导入成功", "total_num": len(total_schedule), "success_num": len(schedules), "fail_num": int64(len(errLogs)), }) } } else { log := models.ExportLog{ LogType: 2, UserOrgId: this.GetAdminUserInfo().CurrentOrgId, TotalNum: int64(len(total_schedule)), FailNum: int64(len(errLogs)), SuccessNum: int64(len(schedules)), CreateTime: time.Now().Unix(), UpdateTime: time.Now().Unix(), ExportTime: export_time, Status: 1, } service.CreateExportLog(&log) this.ServeSuccessJSON(map[string]interface{}{ "msg": "导入成功", "total_num": len(total_schedule), "success_num": len(schedules), "fail_num": int64(len(errLogs)), }) } } } func (this *ScheduleApiController) ExportScheduleTemplate() { dataBody := make(map[string]interface{}, 0) err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody) if err != nil { utils.ErrorLog(err.Error()) return } utils.ErrorLog("%v", dataBody) export_time := time.Now().Unix() var schedules []*models.PatientScheduleTemplateItem var total_schedule []interface{} patients, _, _ := service.GetAllPatientList(this.GetAdminUserInfo().CurrentOrgId) if dataBody["schedule"] != nil || reflect.TypeOf(dataBody["schedule"]).String() == "[]interface {}" { tempSchedule := dataBody["schedule"].([]interface{}) total_schedule = tempSchedule for _, schMap := range tempSchedule { schMapM := schMap.(map[string]interface{}) var sch models.PatientScheduleTemplateItem if schMapM["name"] == nil || reflect.TypeOf(schMapM["name"]).String() != "string" { utils.ErrorLog("name") return } name, _ := schMapM["name"].(string) fmt.Println(name) if len(name) == 0 { //名字为空则生成一条导入错误日志 err_log := models.ExportErrLog{ LogType: 3, UserOrgId: this.GetAdminUserInfo().CurrentOrgId, ErrMsg: "第" + strconv.FormatInt(int64(schMapM["index"].(float64)), 10) + "行,第" + schMapM["row"].(string) + "列的姓名不能为空", Status: 1, CreateTime: time.Now().Unix(), UpdateTime: time.Now().Unix(), ExportTime: export_time, } service.CreateExportErrLog(&err_log) continue } else { var patient []*models.Patients for _, item := range patients { if item.Name == name { patient = append(patient, item) } } if len(patient) == 0 { //错误日志 err_log := models.ExportErrLog{ LogType: 3, UserOrgId: this.GetAdminUserInfo().CurrentOrgId, ErrMsg: "第" + strconv.FormatInt(int64(schMapM["index"].(float64)), 10) + "行,第" + schMapM["row"].(string) + "列的姓名在系统中不存在,请在系统中添加该病人", Status: 1, CreateTime: time.Now().Unix(), UpdateTime: time.Now().Unix(), ExportTime: export_time, } service.CreateExportErrLog(&err_log) continue } else if len(patient) == 1 { // sch.PatientID = patient[0].ID } else if len(patient) > 1 { //出现同名的情况 err_log := models.ExportErrLog{ LogType: 3, UserOrgId: this.GetAdminUserInfo().CurrentOrgId, ErrMsg: "存在同名同姓的两个病人", Status: 1, CreateTime: time.Now().Unix(), UpdateTime: time.Now().Unix(), ExportTime: export_time, } service.CreateExportErrLog(&err_log) continue } } if schMapM["schedule_type"] == nil && reflect.TypeOf(schMapM["schedule_type"]).String() != "float64" { utils.ErrorLog("schedule_type") return } schedule_type := int64(schMapM["schedule_type"].(float64)) if schedule_type <= 0 { //班次格式有误,插入日志 log := models.ExportLog{ LogType: 3, UserOrgId: this.GetAdminUserInfo().CurrentOrgId, TotalNum: int64(len(total_schedule)), FailNum: 1, SuccessNum: int64(len(schedules)), CreateTime: time.Now().Unix(), UpdateTime: time.Now().Unix(), ExportTime: export_time, Status: 1, } service.CreateExportLog(&log) err_log := models.ExportErrLog{ LogType: 3, UserOrgId: this.GetAdminUserInfo().CurrentOrgId, ErrMsg: "第2行第" + schMapM["row"].(string) + "列的班次格式有误", Status: 1, CreateTime: time.Now().Unix(), UpdateTime: time.Now().Unix(), ExportTime: export_time, } service.CreateExportErrLog(&err_log) this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeExportError) return } else { sch.TimeType = int8(schedule_type) } if schMapM["template_id"] == nil && reflect.TypeOf(schMapM["template_id"]).String() != "float64" { utils.ErrorLog("template_id") return } template_id := int64(schMapM["template_id"].(float64)) sch.TemplateID = template_id if schMapM["device_number_name"] == nil || reflect.TypeOf(schMapM["device_number_name"]).String() != "string" { utils.ErrorLog("device_number_name") return } partition_name, _ := schMapM["partition_name"].(string) zone, _ := service.FindDeviceZoneByName(partition_name, this.GetAdminUserInfo().CurrentOrgId) device_number_name, _ := schMapM["device_number_name"].(string) if len(device_number_name) == 0 { //分区为空 log := models.ExportLog{ LogType: 3, UserOrgId: this.GetAdminUserInfo().CurrentOrgId, TotalNum: int64(len(total_schedule)), FailNum: 1, SuccessNum: int64(len(schedules)), CreateTime: time.Now().Unix(), UpdateTime: time.Now().Unix(), ExportTime: export_time, Status: 1, } service.CreateExportLog(&log) err_log := models.ExportErrLog{ LogType: 3, UserOrgId: this.GetAdminUserInfo().CurrentOrgId, //ErrMsg: "第" + strconv.FormatInt(int64(schMapM["index"].(float64)) ,10)+ "行" + "的姓名不能为空", ErrMsg: "第" + strconv.FormatInt(int64(schMapM["index"].(float64)), 10) + "行第2列机号格式有误", Status: 1, CreateTime: time.Now().Unix(), UpdateTime: time.Now().Unix(), ExportTime: export_time, } service.CreateExportErrLog(&err_log) this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeExportError) return } else { device, err := service.FindDeviceByNameTwo(device_number_name, this.GetAdminUserInfo().CurrentOrgId, zone.ID) if err == nil { if len(device) == 0 { //没查到数据,插入错误日志 log := models.ExportLog{ LogType: 3, UserOrgId: this.GetAdminUserInfo().CurrentOrgId, TotalNum: int64(len(total_schedule)), FailNum: 1, SuccessNum: int64(len(schedules)), CreateTime: time.Now().Unix(), UpdateTime: time.Now().Unix(), ExportTime: export_time, Status: 1, } service.CreateExportLog(&log) err_log := models.ExportErrLog{ LogType: 3, UserOrgId: this.GetAdminUserInfo().CurrentOrgId, ErrMsg: "第" + strconv.FormatInt(int64(schMapM["index"].(float64)), 10) + "行第2列机号格式有误", Status: 1, CreateTime: time.Now().Unix(), UpdateTime: time.Now().Unix(), ExportTime: export_time, } service.CreateExportErrLog(&err_log) this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeExportError) return } else if len(device) == 1 { sch.DeviceNumberID = device[0].ID } else if len(device) > 1 { //出现重名,插入错误日志 log := models.ExportLog{ LogType: 3, UserOrgId: this.GetAdminUserInfo().CurrentOrgId, TotalNum: int64(len(total_schedule)), FailNum: 1, SuccessNum: int64(len(schedules)), CreateTime: time.Now().Unix(), UpdateTime: time.Now().Unix(), ExportTime: export_time, Status: 1, } service.CreateExportLog(&log) err_log := models.ExportErrLog{ LogType: 3, UserOrgId: this.GetAdminUserInfo().CurrentOrgId, ErrMsg: "出现两个床位号相同的床位", Status: 1, CreateTime: time.Now().Unix(), UpdateTime: time.Now().Unix(), ExportTime: export_time, } service.CreateExportErrLog(&err_log) this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeExportError) return } } } if schMapM["schedule_week"] == nil || reflect.TypeOf(schMapM["schedule_week"]).String() != "string" { utils.ErrorLog("schedule_week") return } schedule_week, _ := schMapM["schedule_week"].(string) if len(schedule_week) == 0 { //周几为空则生成一条导入错误日志 log := models.ExportLog{ LogType: 3, UserOrgId: this.GetAdminUserInfo().CurrentOrgId, TotalNum: int64(len(total_schedule)), FailNum: 1, SuccessNum: int64(len(schedules)), CreateTime: time.Now().Unix(), UpdateTime: time.Now().Unix(), ExportTime: export_time, Status: 1, } service.CreateExportLog(&log) err_log := models.ExportErrLog{ LogType: 3, UserOrgId: this.GetAdminUserInfo().CurrentOrgId, //ErrMsg: "第" + strconv.FormatInt(int64(schMapM["index"].(float64)) ,10)+ "行" + "的姓名不能为空", ErrMsg: "第1行第" + schMapM["row"].(string) + "列的星期名格式有误", Status: 1, CreateTime: time.Now().Unix(), UpdateTime: time.Now().Unix(), ExportTime: export_time, } service.CreateExportErrLog(&err_log) this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeExportError) return } else if schedule_week == "0" { //周几不符合格式则生成一条导入错误日志 log := models.ExportLog{ LogType: 3, UserOrgId: this.GetAdminUserInfo().CurrentOrgId, TotalNum: int64(len(total_schedule)), FailNum: 1, SuccessNum: int64(len(schedules)), CreateTime: time.Now().Unix(), UpdateTime: time.Now().Unix(), ExportTime: export_time, Status: 1, } service.CreateExportLog(&log) err_log := models.ExportErrLog{ LogType: 3, UserOrgId: this.GetAdminUserInfo().CurrentOrgId, ErrMsg: "第1行第" + schMapM["row"].(string) + "列的星期名格式有误", Status: 1, CreateTime: time.Now().Unix(), UpdateTime: time.Now().Unix(), ExportTime: export_time, } service.CreateExportErrLog(&err_log) this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeExportError) return } else { schedule_week, _ := strconv.ParseInt(schedule_week, 10, 64) sch.Weekday = int8(schedule_week) } sch.CreateTime = time.Now().Unix() sch.ModifyTime = time.Now().Unix() sch.TreatMode = 1 sch.Status = 1 sch.OrgID = this.GetAdminUserInfo().CurrentOrgId sch.IsExport = 1 schedules = append(schedules, &sch) } errLogs, _ := service.FindSchedualTemplateExportLog(this.GetAdminUserInfo().CurrentOrgId, export_time) if len(schedules) > 0 { err := service.UpdateScheduleTemplateStatus(this.GetAdminUserInfo().CurrentOrgId) if err == nil { for _, item := range schedules { service.CreateScheduleTemplate(item) } log := models.ExportLog{ LogType: 3, UserOrgId: this.GetAdminUserInfo().CurrentOrgId, TotalNum: int64(len(total_schedule)), FailNum: int64(len(errLogs)), SuccessNum: int64(len(schedules)), CreateTime: time.Now().Unix(), UpdateTime: time.Now().Unix(), ExportTime: export_time, Status: 1, } service.CreateExportLog(&log) this.ServeSuccessJSON(map[string]interface{}{ "msg": "导入成功", "total_num": len(total_schedule), "success_num": len(schedules), "fail_num": int64(len(errLogs)), }) } else { log := models.ExportLog{ LogType: 3, UserOrgId: this.GetAdminUserInfo().CurrentOrgId, TotalNum: int64(len(total_schedule)), FailNum: int64(len(errLogs)), SuccessNum: int64(len(schedules)), CreateTime: time.Now().Unix(), UpdateTime: time.Now().Unix(), ExportTime: export_time, Status: 1, } service.CreateExportLog(&log) this.ServeSuccessJSON(map[string]interface{}{ "msg": "导入成功", "total_num": len(total_schedule), "success_num": len(schedules), "fail_num": int64(len(errLogs)), }) } } else { log := models.ExportLog{ LogType: 3, UserOrgId: this.GetAdminUserInfo().CurrentOrgId, TotalNum: int64(len(total_schedule)), FailNum: int64(len(errLogs)), SuccessNum: int64(len(schedules)), CreateTime: time.Now().Unix(), UpdateTime: time.Now().Unix(), ExportTime: export_time, Status: 1, } service.CreateExportLog(&log) this.ServeSuccessJSON(map[string]interface{}{ "msg": "导入成功", "total_num": len(total_schedule), "success_num": len(schedules), "fail_num": int64(len(errLogs)), }) } } } func (c *ScheduleApiController) GetInitExcelInitDate() { thisTime := time.Now() thisTime1 := time.Now() thisTime2 := time.Now() thisTime1 = thisTime1.AddDate(0, 0, 7) thisTime2 = thisTime2.AddDate(0, 0, 14) weekDay := int(thisTime.Weekday()) if weekDay == 0 { weekDay = 7 } weekEnd := 7 - weekDay weekStart := weekEnd - 6 days := make([]string, 0) for index := weekStart; index <= weekEnd; index++ { theDay := thisTime.AddDate(0, 0, index) days = append(days, theDay.Format("2006-01-02")) } weekDay1 := int(thisTime1.Weekday()) if weekDay1 == 0 { weekDay1 = 7 } weekEnd1 := 7 - weekDay1 weekStart1 := weekEnd1 - 6 for index := weekStart1; index <= weekEnd1; index++ { theDay := thisTime1.AddDate(0, 0, index) days = append(days, theDay.Format("2006-01-02")) } weekDay2 := int(thisTime2.Weekday()) if weekDay2 == 0 { weekDay2 = 7 } weekEnd2 := 7 - weekDay2 weekStart2 := weekEnd2 - 6 for index := weekStart2; index <= weekEnd2; index++ { theDay := thisTime2.AddDate(0, 0, index) days = append(days, theDay.Format("2006-01-02")) } c.ServeSuccessJSON(map[string]interface{}{ "days": days, }) return }