12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733 |
- package controllers
-
- import (
- "XT_New/enums"
- "XT_New/models"
- "XT_New/service"
- "XT_New/utils"
- "encoding/json"
- "fmt"
- "github.com/jinzhu/gorm"
- "reflect"
- "strconv"
- "strings"
- "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,
- })
-
- }
-
- 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 failed_total int
- var total_schedule []interface{}
- var patients []*models.Patients
-
- patients, _, _ = service.GetAllPatientList(this.GetAdminUserInfo().CurrentOrgId)
-
- if dataBody["failed_schedule"] != nil || reflect.TypeOf(dataBody["failed_schedule"]).String() == "[]interface {}" {
- tempSchedule := dataBody["failed_schedule"].([]interface{})
- failed_total = len(tempSchedule)
-
- }
-
- 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 strings.Replace(item.Name, " ", "", -1) == 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) + "列,患者姓名为\"" + name + "\"在系统中不存在,请在系统中添加该患者",
- 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: "第" + strconv.FormatInt(int64(schMapM["index"].(float64)), 10) + "行,第" + schMapM["row"].(string) + "列" + "患者姓名为" + name + "在当前机构中存在重名,无法确定到具体患者",
-
- ErrMsg: "第" + strconv.FormatInt(int64(schMapM["index"].(float64)), 10) + "行,第" + schMapM["row"].(string) + "列,患者姓名为\"" + name + "\"在在当前机构中存在重名,无法确定到具体患者",
-
- 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) + failed_total),
- FailNum: 1 + int64(failed_total),
- 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) + failed_total),
- FailNum: 1 + int64(failed_total),
- 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) + failed_total),
- FailNum: 1 + int64(failed_total),
- 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) + failed_total),
- FailNum: 1 + int64(failed_total),
- 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) + failed_total),
- FailNum: 1 + int64(failed_total),
- 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) + failed_total),
- FailNum: 1 + int64(failed_total),
- 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) + failed_total),
- FailNum: 1 + int64(failed_total),
- 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) + failed_total),
- FailNum: 1 + int64(failed_total),
- 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) + failed_total),
- FailNum: 1 + int64(failed_total),
- 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) + failed_total),
- FailNum: 1 + int64(failed_total),
- 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 := time.Now().Format("2006-01-02")
- 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) + failed_total),
- FailNum: int64(len(errLogs) + failed_total),
- SuccessNum: int64(len(schedules)),
- CreateTime: time.Now().Unix(),
- UpdateTime: time.Now().Unix(),
- ExportTime: export_time,
- Status: 1,
- }
- service.CreateExportLog(&log)
-
- if failed_total > 0 {
- err_log := models.ExportErrLog{
- LogType: 2,
- UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
- ErrMsg: "当前日期(" + time.Now().Format("2006-01-02") + " " + GetWeekString(time.Now().Weekday().String()) +
- ")及以前的排班数据" + strconv.FormatInt(int64(failed_total), 10) + "条,不执行导入",
- Status: 1,
- CreateTime: time.Now().Unix(),
- UpdateTime: time.Now().Unix(),
- ExportTime: export_time,
- }
- service.CreateExportErrLog(&err_log)
- }
-
- this.ServeSuccessJSON(map[string]interface{}{
- "msg": "导入成功",
- "total_num": len(total_schedule) + failed_total,
- "success_num": len(schedules),
- "fail_num": int64(len(errLogs)),
- })
- } else {
- log := models.ExportLog{
- LogType: 2,
- UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
- TotalNum: int64(len(total_schedule) + failed_total),
- FailNum: int64(len(errLogs) + failed_total),
- SuccessNum: int64(len(schedules)),
- CreateTime: time.Now().Unix(),
- UpdateTime: time.Now().Unix(),
- ExportTime: export_time,
- Status: 1,
- }
- service.CreateExportLog(&log)
-
- if failed_total > 0 {
- err_log := models.ExportErrLog{
- LogType: 2,
- UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
- ErrMsg: "当前日期(" + time.Now().Format("2006-01-02") + " " + GetWeekString(time.Now().Weekday().String()) +
- ")及以前的排班数据" + strconv.FormatInt(int64(failed_total), 10) + "条,不执行导入",
- Status: 1,
- CreateTime: time.Now().Unix(),
- UpdateTime: time.Now().Unix(),
- ExportTime: export_time,
- }
- service.CreateExportErrLog(&err_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) + failed_total),
- FailNum: int64(len(errLogs) + failed_total),
- SuccessNum: int64(len(schedules)),
- CreateTime: time.Now().Unix(),
- UpdateTime: time.Now().Unix(),
- ExportTime: export_time,
- Status: 1,
- }
- service.CreateExportLog(&log)
-
- if failed_total > 0 {
- err_log := models.ExportErrLog{
- LogType: 2,
- UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
- ErrMsg: "当前日期(" + time.Now().Format("2006-01-02") + " " + GetWeekString(time.Now().Weekday().String()) +
- ")及以前的排班数据" + strconv.FormatInt(int64(failed_total), 10) + "条,不执行导入",
- Status: 1,
- CreateTime: time.Now().Unix(),
- UpdateTime: time.Now().Unix(),
- ExportTime: export_time,
- }
- service.CreateExportErrLog(&err_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 strings.Replace(item.Name, " ", "", -1) == 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) + "列的姓名在系统中不存在,请在系统中添加该病人",
- ErrMsg: "第" + strconv.FormatInt(int64(schMapM["index"].(float64)), 10) + "行,第" + schMapM["row"].(string) + "列患者姓名为\"" + name + "\"在系统中不存在,请在系统中添加该患者",
-
- 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: "第" + strconv.FormatInt(int64(schMapM["index"].(float64)), 10) + "行,第" + schMapM["row"].(string) + "列" + "患者姓名为" + name + "在当前机构中存在重名,无法确定到具体患者",
- ErrMsg: "第" + strconv.FormatInt(int64(schMapM["index"].(float64)), 10) + "行,第" + schMapM["row"].(string) + "列患者姓名为\"" + name + "\"在当前机构中存在重名,无法确定到具体患者",
-
- 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
- }
-
- func GetWeekString(week string) string {
- var weekStr string
- switch week {
- case "Sunday":
- weekStr = "周日"
- break
- case "Monday":
- weekStr = "周一"
- break
- case "Tuesday":
- weekStr = "周二"
- break
- case "Wednesday":
- weekStr = "周三"
- break
- case "Thursday":
- weekStr = "周四"
-
- break
- case "Friday":
- weekStr = "周五"
-
- break
- case "Saturday":
- weekStr = "周六"
- break
- default:
- weekStr = ""
- break
-
- }
- return weekStr
- }
|