1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648 |
- 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
- }
|