schedule_api_controller.go 84KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734
  1. package controllers
  2. import (
  3. "XT_New/enums"
  4. "XT_New/models"
  5. "XT_New/service"
  6. "XT_New/utils"
  7. "encoding/json"
  8. "fmt"
  9. "github.com/jinzhu/gorm"
  10. "reflect"
  11. "strconv"
  12. "strings"
  13. "time"
  14. "github.com/astaxie/beego"
  15. )
  16. type ScheduleApiController struct {
  17. BaseAuthAPIController
  18. }
  19. func ScheduleApiRegistRouters() {
  20. beego.Router("/api/schedule/weekpanel", &ScheduleApiController{}, "Get:GetWeekPanels")
  21. beego.Router("/api/schedule/schedules", &ScheduleApiController{}, "Get:GetSchedules")
  22. beego.Router("/api/excel_date/init", &ScheduleApiController{}, "Get:GetInitExcelInitDate")
  23. beego.Router("/api/schedule/patients", &ScheduleApiController{}, "Get:GetPatients")
  24. beego.Router("/api/schedule/create", &ScheduleApiController{}, "Post:CreateSchedule")
  25. beego.Router("/api/schedule/delete", &ScheduleApiController{}, "Delete:DeleteSchedule")
  26. beego.Router("/api/schedule/change", &ScheduleApiController{}, "Put:ChangeSchedule")
  27. beego.Router("/api/schedule/urgentinit", &ScheduleApiController{}, "Get:UrgentScheduleData")
  28. beego.Router("/api/schedule/print/initdata", &ScheduleApiController{}, "get:PrintInitData")
  29. beego.Router("/api/schedule/search", &ScheduleApiController{}, "get:SearchSchedulePatients")
  30. beego.Router("/api/schedule/week", &ScheduleApiController{}, "get:GetWeekDaySchedule")
  31. beego.Router("/api/schedule/export", &ScheduleApiController{}, "post:ExportSchedule")
  32. beego.Router("/api/schedule_template/export", &ScheduleApiController{}, "post:ExportScheduleTemplate")
  33. beego.Router("/api/schedule_template/search", &ScheduleApiController{}, "get:SearchTemplateSchedulePatients")
  34. beego.Router("/api/schedule_template/cancel", &ScheduleApiController{}, "post:CancelScheduleTemplate")
  35. beego.Router("/api/schedule/getnextscheduleweekday", &ScheduleApiController{}, "Get:GetNextWeekDaySchedule")
  36. beego.Router("/api/schedule/getthreeweeklist", &ScheduleApiController{}, "Get:GetThreeWeekList")
  37. beego.Router("/api/schedule/getallzones", &ScheduleApiController{}, "Get:GetAllZones")
  38. beego.Router("/api/schedule/copypatientschedules", &ScheduleApiController{}, "Get:GetCopyPatientSchedules")
  39. beego.Router("/api/schedule/saveremindprint", &ScheduleApiController{}, "Get:SaveRemindPrint")
  40. beego.Router("/api/schedule/getremindprintlist", &ScheduleApiController{}, "Get:GetRemindPrintList")
  41. beego.Router("/api/schedule/getbloodschedulelist", &ScheduleApiController{}, "Get:GetBloodScheduleList")
  42. beego.Router("/api/schedule/getprintlist", &ScheduleApiController{}, "Get:GetPrintList")
  43. beego.Router("/api/schedule/getallzonelist", &ScheduleApiController{}, "Get:GetAllZoneList")
  44. beego.Router("/api/schedule/getpatientschedulecount", &ScheduleApiController{}, "Get:GetPatientScheduleCount")
  45. beego.Router("/api/schedule/weekpanelone", &ScheduleApiController{}, "Get:GetWeekPanelsOne")
  46. beego.Router("/api/schedule/schedulesone", &ScheduleApiController{}, "Get:GetScheduleOne")
  47. beego.Router("/api/schedule/postscheduletemplate", &ScheduleApiController{}, "Get:SaveScheduleTemplate")
  48. beego.Router("/api/schedule/getscheduletemplate", &ScheduleApiController{}, "Get:GetScheduleTemplate")
  49. beego.Router("/api/order/changefuncprint", &ScheduleApiController{}, "Get:ChangeFuncPrint")
  50. beego.Router("/api/order/getdataprint", &ScheduleApiController{}, "Get:GetDataPrint")
  51. beego.Router("/api/schedule/getnextweekpanels", &ScheduleApiController{}, "Get:GetNextWeekPanels")
  52. }
  53. func (c *ScheduleApiController) GetWeekPanels() {
  54. data, _ := c.GetInt64("data", 1)
  55. patitionId, _ := c.GetInt64("patitionid")
  56. adminInfo := c.GetAdminUserInfo()
  57. thisTime := time.Now()
  58. year, monthTime, day := thisTime.Date()
  59. month := int(monthTime)
  60. _, theWeek := thisTime.ISOWeek()
  61. weekDay := int(thisTime.Weekday())
  62. if weekDay == 0 {
  63. weekDay = 7
  64. }
  65. weekEnd := 7 - weekDay
  66. weekStart := weekEnd - 6
  67. weekDays := make([]string, 0)
  68. for index := weekStart; index <= weekEnd; index++ {
  69. theDay := thisTime.AddDate(0, 0, index)
  70. indexYear, indexMonthTime, indexDay := theDay.Date()
  71. indexMonth := int(indexMonthTime)
  72. indexWeek := strconv.Itoa(indexYear) + "." + strconv.Itoa(indexMonth) + "." + strconv.Itoa(indexDay)
  73. weekDays = append(weekDays, indexWeek)
  74. }
  75. returnData := map[string]interface{}{
  76. "year": year,
  77. "month": month,
  78. "day": day,
  79. "theWeek": theWeek,
  80. "weekDay": weekDay,
  81. "weekDays": weekDays,
  82. }
  83. if data == 1 {
  84. partitions, _ := service.GetSchedulePartitionPanelOne(adminInfo.CurrentOrgId, patitionId)
  85. returnData["partitions"] = partitions
  86. }
  87. c.ServeSuccessJSON(returnData)
  88. return
  89. }
  90. func (c *ScheduleApiController) GetSchedules() {
  91. week, _ := c.GetInt64("weekTime", 0) //1:last, 2:this 3:next 4 nextTwo
  92. partition_id, _ := c.GetInt64("partition_id")
  93. schedule_type, _ := c.GetInt64("schedule_type")
  94. adminInfo := c.GetAdminUserInfo()
  95. thisTime := time.Now()
  96. today := thisTime.Format("2006-01-02")
  97. if week < 1 || week > 4 {
  98. week = 2
  99. }
  100. if week == 1 {
  101. thisTime = thisTime.AddDate(0, 0, -7)
  102. } else if week == 3 {
  103. thisTime = thisTime.AddDate(0, 0, 7)
  104. } else if week == 4 {
  105. thisTime = thisTime.AddDate(0, 0, 14)
  106. }
  107. weekDay := int(thisTime.Weekday())
  108. if weekDay == 0 {
  109. weekDay = 7
  110. }
  111. weekEnd := 7 - weekDay
  112. weekStart := weekEnd - 6
  113. weekTitle := make([]string, 0)
  114. days := make([]string, 0)
  115. for index := weekStart; index <= weekEnd; index++ {
  116. theDay := thisTime.AddDate(0, 0, index)
  117. indexYear, indexMonthTime, indexDay := theDay.Date()
  118. indexMonth := int(indexMonthTime)
  119. indexWeek := strconv.Itoa(indexYear) + "." + strconv.Itoa(indexMonth) + "." + strconv.Itoa(indexDay)
  120. weekTitle = append(weekTitle, indexWeek)
  121. days = append(days, theDay.Format("2006-01-02"))
  122. }
  123. weekStartDay := thisTime.AddDate(0, 0, weekStart)
  124. weekEndDay := thisTime.AddDate(0, 0, weekEnd)
  125. weekStartTime := weekStartDay.Format("2006-01-02") + " 00:00:00"
  126. weekEndTime := weekEndDay.Format("2006-01-02") + " 23:59:59"
  127. timeLayout := "2006-01-02 15:04:05"
  128. loc, _ := time.LoadLocation("Local")
  129. theStarTime, _ := time.ParseInLocation(timeLayout, weekStartTime, loc)
  130. theEndTime, _ := time.ParseInLocation(timeLayout, weekEndTime, loc)
  131. weekStartPoint := theStarTime.Unix()
  132. weekEndPoint := theEndTime.Unix()
  133. schdules, _ := service.GetWeekScheduleOne(adminInfo.CurrentOrgId, weekStartPoint, weekEndPoint, partition_id, schedule_type)
  134. c.ServeSuccessJSON(map[string]interface{}{
  135. "days": days,
  136. "weekTitle": weekTitle,
  137. "schdules": schdules,
  138. "today": today,
  139. })
  140. return
  141. }
  142. func (c *ScheduleApiController) GetPatients() {
  143. keywords := c.GetString("keywords", "")
  144. schedule, _ := c.GetInt64("schedule", 0) //1已2未
  145. contagion, _ := c.GetInt64("contagion", 0)
  146. adminInfo := c.GetAdminUserInfo()
  147. thisTime := time.Now()
  148. weekDay := int(thisTime.Weekday())
  149. if weekDay == 0 {
  150. weekDay = 7
  151. }
  152. thisWeekEnd := 7 - weekDay
  153. weekStartPoint := thisWeekEnd - 6
  154. weekStartDay := thisTime.AddDate(0, 0, weekStartPoint)
  155. weekEndPoint := thisWeekEnd + 7
  156. weekEndDay := thisTime.AddDate(0, 0, weekEndPoint)
  157. fmt.Println(weekStartPoint, weekStartDay, weekEndPoint, weekEndDay)
  158. weekStartTime := weekStartDay.Format("2006-01-02") + " 00:00:00"
  159. weekEndTime := weekEndDay.Format("2006-01-02") + " 23:59:59"
  160. fmt.Println(weekStartTime, weekEndTime)
  161. timeLayout := "2006-01-02 15:04:05"
  162. loc, _ := time.LoadLocation("Local")
  163. theStarTime, _ := time.ParseInLocation(timeLayout, weekStartTime, loc)
  164. theEndTime, _ := time.ParseInLocation(timeLayout, weekEndTime, loc)
  165. weekStart := theStarTime.Unix()
  166. weekEnd := theEndTime.Unix()
  167. patients, _ := service.GetPatientWithScheduleAndSolution(adminInfo.CurrentOrgId, keywords, weekStart, weekEnd, schedule, contagion)
  168. c.ServeSuccessJSON(map[string]interface{}{
  169. "patients": patients,
  170. })
  171. return
  172. }
  173. func (c *ScheduleApiController) CreateSchedule() {
  174. patientID, _ := c.GetInt64("patient_id", 0)
  175. if patientID <= 0 {
  176. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  177. return
  178. }
  179. adminUserInfo := c.GetAdminUserInfo()
  180. patientInfo, _ := service.FindPatientById(adminUserInfo.CurrentOrgId, patientID)
  181. if patientInfo.ID == 0 {
  182. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  183. return
  184. }
  185. var schedule models.Schedule
  186. dataBody := make(map[string]interface{}, 0)
  187. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  188. if err != nil {
  189. utils.ErrorLog(err.Error())
  190. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  191. return
  192. }
  193. if dataBody["schedule_date"] == nil || reflect.TypeOf(dataBody["schedule_date"]).String() != "string" {
  194. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  195. return
  196. }
  197. scheduleDate, _ := dataBody["schedule_date"].(string)
  198. if len(scheduleDate) == 0 {
  199. utils.ErrorLog("len(schedule_date) == 0")
  200. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  201. return
  202. }
  203. timeLayout := "2006-01-02"
  204. loc, _ := time.LoadLocation("Local")
  205. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", scheduleDate+" 00:00:00", loc)
  206. if err != nil {
  207. utils.ErrorLog(err.Error())
  208. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  209. return
  210. }
  211. schedule.ScheduleDate = theTime.Unix()
  212. timeNow := time.Now().Format("2006-01-02")
  213. if timeNow > scheduleDate {
  214. utils.ErrorLog(timeNow)
  215. utils.ErrorLog(scheduleDate)
  216. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCantSetScheduleBeforeNow)
  217. return
  218. }
  219. if dataBody["schedule_type"] == nil || reflect.TypeOf(dataBody["schedule_type"]).String() != "float64" {
  220. utils.ErrorLog("schedule_type")
  221. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  222. return
  223. }
  224. scheduleType := int64(dataBody["schedule_type"].(float64))
  225. if scheduleType < 1 || scheduleType > 3 {
  226. utils.ErrorLog("scheduleType < 3")
  227. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  228. return
  229. }
  230. schedule.ScheduleType = scheduleType
  231. if dataBody["bed_id"] == nil || reflect.TypeOf(dataBody["bed_id"]).String() != "float64" {
  232. utils.ErrorLog("bed_id")
  233. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  234. return
  235. }
  236. bedId := int64(dataBody["bed_id"].(float64))
  237. if bedId < 1 {
  238. utils.ErrorLog("bedId < 1")
  239. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  240. return
  241. }
  242. schedule.BedId = bedId
  243. if dataBody["partition_id"] == nil || reflect.TypeOf(dataBody["partition_id"]).String() != "float64" {
  244. utils.ErrorLog("partition_id")
  245. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  246. return
  247. }
  248. partitionId := int64(dataBody["partition_id"].(float64))
  249. if partitionId < 1 {
  250. utils.ErrorLog("partitionId < 1")
  251. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  252. return
  253. }
  254. schedule.PartitionId = partitionId
  255. if dataBody["schedule_week"] == nil || reflect.TypeOf(dataBody["schedule_week"]).String() != "float64" {
  256. utils.ErrorLog("schedule_week")
  257. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  258. return
  259. }
  260. scheduleWeek := int64(dataBody["schedule_week"].(float64))
  261. if scheduleWeek < 1 || scheduleWeek > 7 {
  262. utils.ErrorLog("scheduleWeek < 1")
  263. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  264. return
  265. }
  266. schedule.ScheduleWeek = scheduleWeek
  267. if dataBody["mode_id"] == nil || reflect.TypeOf(dataBody["mode_id"]).String() != "float64" {
  268. utils.ErrorLog("mode_id")
  269. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  270. return
  271. }
  272. modeId := int64(dataBody["mode_id"].(float64))
  273. if modeId < 1 && modeId > 14 {
  274. utils.ErrorLog("modeId < 1")
  275. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  276. return
  277. }
  278. schedule.ModeId = modeId
  279. schedule.PatientId = patientID
  280. schedule.CreatedTime = time.Now().Unix()
  281. schedule.UpdatedTime = time.Now().Unix()
  282. schedule.Status = 1
  283. schedule.UserOrgId = adminUserInfo.CurrentOrgId
  284. bed, _ := service.GetDeviceNumberByID(adminUserInfo.CurrentOrgId, schedule.BedId)
  285. if bed == nil {
  286. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeviceNumberNotExist)
  287. return
  288. }
  289. if bed.ZoneID != schedule.PartitionId {
  290. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeviceNumberNotTheZone)
  291. return
  292. }
  293. scheduleDateStart := scheduleDate + " 00:00:00"
  294. scheduleDateEnd := scheduleDate + " 23:59:59"
  295. timeLayout = "2006-01-02 15:04:05"
  296. theStartTime, _ := time.ParseInLocation(timeLayout, scheduleDateStart, loc)
  297. theEndTime, _ := time.ParseInLocation(timeLayout, scheduleDateEnd, loc)
  298. startTime := theStartTime.Unix()
  299. endTime := theEndTime.Unix()
  300. //一天只有排班一次
  301. daySchedule, err := service.GetDaySchedule(adminUserInfo.CurrentOrgId, startTime, endTime, patientID)
  302. if daySchedule.ID > 0 {
  303. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCantSetScheduleAgainOneDay)
  304. return
  305. }
  306. //同天同位置只能排一个
  307. pointSchedule, err := service.GetPointSchedule(adminUserInfo.CurrentOrgId, schedule.ScheduleDate, schedule.ScheduleWeek, schedule.ScheduleType, schedule.BedId)
  308. if err != nil {
  309. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  310. return
  311. }
  312. if pointSchedule.ID > 0 {
  313. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePointScheduleExist)
  314. return
  315. }
  316. redis := service.RedisClient()
  317. err = service.CreateSchedule(&schedule)
  318. key := "scheduals_" + scheduleDate + "_" + strconv.FormatInt(adminUserInfo.CurrentOrgId, 10)
  319. redis.Set(key, "", time.Second)
  320. //处方
  321. keyOne := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(schedule.ScheduleDate, 10) + ":prescriptions_list_all"
  322. redis.Set(keyOne, "", time.Second)
  323. //医嘱
  324. keyTwo := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(schedule.ScheduleDate, 10) + ":advice_list_all"
  325. redis.Set(keyTwo, "", time.Second)
  326. keySix := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(schedule.ScheduleDate, 10) + ":assessment_befores_list_all"
  327. redis.Set(keySix, "", time.Second)
  328. keyThree := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(schedule.ScheduleDate, 10) + ":assessment_after_dislysis_list_all"
  329. redis.Set(keyThree, "", time.Second)
  330. keyFour := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(schedule.ScheduleDate, 10) + ":monitor_record_list_all"
  331. redis.Set(keyFour, "", time.Second)
  332. keyFive := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(schedule.ScheduleDate, 10) + ":treatment_summarys_list_all"
  333. redis.Set(keyFive, "", time.Second)
  334. keySeven := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(schedule.ScheduleDate, 10) + ":dialysis_orders_list_all"
  335. redis.Set(keySeven, "", time.Second)
  336. fmt.Println(err)
  337. defer redis.Close()
  338. if err != nil {
  339. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateScheduleFail)
  340. return
  341. }
  342. schedule.Patient = patientInfo.Name
  343. c.ServeSuccessJSON(map[string]interface{}{
  344. "msg": "ok",
  345. "schedule": schedule,
  346. })
  347. return
  348. }
  349. func (c *ScheduleApiController) DeleteSchedule() {
  350. id, _ := c.GetInt64("id", 0)
  351. if id <= 0 {
  352. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  353. return
  354. }
  355. adminINfo := c.GetAdminUserInfo()
  356. schedule, _ := service.GetSchedule(adminINfo.CurrentOrgId, id)
  357. if schedule == nil {
  358. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeScheduleNotExist)
  359. return
  360. }
  361. order, err := service.GetOneDialysisOrder(adminINfo.CurrentOrgId, schedule.ScheduleDate, schedule.PatientId)
  362. if err != nil {
  363. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  364. return
  365. }
  366. if order != nil {
  367. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDelScheduleFailByDialysis)
  368. return
  369. }
  370. schedule.Status = 0
  371. schedule.UpdatedTime = time.Now().Unix()
  372. err = service.UpdateSchedule(schedule)
  373. redis := service.RedisClient()
  374. //处方
  375. keyOne := strconv.FormatInt(adminINfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(schedule.ScheduleDate, 10) + ":prescriptions_list_all"
  376. redis.Set(keyOne, "", time.Second)
  377. //医嘱
  378. keyTwo := strconv.FormatInt(adminINfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(schedule.ScheduleDate, 10) + ":advice_list_all"
  379. redis.Set(keyTwo, "", time.Second)
  380. keySix := strconv.FormatInt(adminINfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(schedule.ScheduleDate, 10) + ":assessment_befores_list_all"
  381. redis.Set(keySix, "", time.Second)
  382. keyThree := strconv.FormatInt(adminINfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(schedule.ScheduleDate, 10) + ":assessment_after_dislysis_list_all"
  383. redis.Set(keyThree, "", time.Second)
  384. keyFour := strconv.FormatInt(adminINfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(schedule.ScheduleDate, 10) + ":monitor_record_list_all"
  385. redis.Set(keyFour, "", time.Second)
  386. keyFive := strconv.FormatInt(adminINfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(schedule.ScheduleDate, 10) + ":treatment_summarys_list_all"
  387. redis.Set(keyFive, "", time.Second)
  388. keySeven := strconv.FormatInt(adminINfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(schedule.ScheduleDate, 10) + ":dialysis_orders_list_all"
  389. redis.Set(keySeven, "", time.Second)
  390. fmt.Println(err)
  391. defer redis.Close()
  392. if err != nil {
  393. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeleteScheduleFail)
  394. return
  395. }
  396. c.ServeSuccessJSON(map[string]interface{}{
  397. "msg": "ok",
  398. "schedule": &schedule,
  399. })
  400. }
  401. func (c *ScheduleApiController) ChangeSchedule() {
  402. id, _ := c.GetInt64("id", 0)
  403. if id <= 0 {
  404. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  405. return
  406. }
  407. adminINfo := c.GetAdminUserInfo()
  408. schedule, _ := service.GetSchedule(adminINfo.CurrentOrgId, id)
  409. if schedule == nil {
  410. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeScheduleNotExist)
  411. return
  412. }
  413. dataBody := make(map[string]interface{}, 0)
  414. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  415. if err != nil {
  416. utils.ErrorLog(err.Error())
  417. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  418. return
  419. }
  420. if dataBody["change_action"] == nil || reflect.TypeOf(dataBody["change_action"]).String() != "string" {
  421. utils.ErrorLog("change_action")
  422. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  423. return
  424. }
  425. changeAction := dataBody["change_action"].(string)
  426. if changeAction == "change_mode" {
  427. if dataBody["mode_id"] == nil || reflect.TypeOf(dataBody["mode_id"]).String() != "float64" {
  428. utils.ErrorLog("mode_id")
  429. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  430. return
  431. }
  432. modeId := int64(dataBody["mode_id"].(float64))
  433. if modeId < 1 {
  434. utils.ErrorLog("modeId < 1")
  435. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  436. return
  437. }
  438. schedule.ModeId = modeId
  439. order, err := service.GetOneDialysisOrder(adminINfo.CurrentOrgId, schedule.ScheduleDate, schedule.PatientId)
  440. if err != nil {
  441. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  442. return
  443. }
  444. if order != nil {
  445. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeChangeMode)
  446. return
  447. }
  448. } else if changeAction == "change_device" {
  449. order, err := service.GetOneDialysisOrder(adminINfo.CurrentOrgId, schedule.ScheduleDate, schedule.PatientId)
  450. if err != nil {
  451. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  452. return
  453. }
  454. if order != nil {
  455. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeChangeDeviceNumber)
  456. return
  457. }
  458. if dataBody["schedule_type"] == nil || reflect.TypeOf(dataBody["schedule_type"]).String() != "float64" {
  459. utils.ErrorLog("schedule_type")
  460. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  461. return
  462. }
  463. scheduleType := int64(dataBody["schedule_type"].(float64))
  464. if scheduleType < 1 || scheduleType > 3 {
  465. utils.ErrorLog("scheduleType < 3")
  466. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  467. return
  468. }
  469. schedule.ScheduleType = scheduleType
  470. if dataBody["bed_id"] == nil || reflect.TypeOf(dataBody["bed_id"]).String() != "float64" {
  471. utils.ErrorLog("bed_id")
  472. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  473. return
  474. }
  475. bedId := int64(dataBody["bed_id"].(float64))
  476. if bedId < 1 {
  477. utils.ErrorLog("bedId < 1")
  478. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  479. return
  480. }
  481. schedule.BedId = bedId
  482. if dataBody["partition_id"] == nil || reflect.TypeOf(dataBody["partition_id"]).String() != "float64" {
  483. utils.ErrorLog("partition_id")
  484. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  485. return
  486. }
  487. partitionId := int64(dataBody["partition_id"].(float64))
  488. if partitionId < 1 {
  489. utils.ErrorLog("partitionId < 1")
  490. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  491. return
  492. }
  493. schedule.PartitionId = partitionId
  494. bed, _ := service.GetDeviceNumberByID(adminINfo.CurrentOrgId, schedule.BedId)
  495. if bed == nil {
  496. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeviceNumberNotExist)
  497. return
  498. }
  499. if bed.ZoneID != schedule.PartitionId {
  500. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeviceNumberNotTheZone)
  501. return
  502. }
  503. startTime := schedule.ScheduleDate
  504. endTime := startTime + 86399
  505. //一天只有排班一次
  506. daySchedule, err := service.GetDaySchedule(adminINfo.CurrentOrgId, startTime, endTime, schedule.PatientId)
  507. if daySchedule.ID > 0 && daySchedule.ID != schedule.ID {
  508. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCantSetScheduleAgainOneDay)
  509. return
  510. }
  511. //同天同位置只能排一个
  512. pointSchedule, err := service.GetPointSchedule(adminINfo.CurrentOrgId, schedule.ScheduleDate, schedule.ScheduleWeek, schedule.ScheduleType, schedule.BedId)
  513. if err != nil {
  514. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  515. return
  516. }
  517. if pointSchedule.ID > 0 {
  518. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePointScheduleExist)
  519. return
  520. }
  521. } else {
  522. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  523. return
  524. }
  525. schedule.UpdatedTime = time.Now().Unix()
  526. err = service.UpdateSchedule(schedule)
  527. prescription := models.DialysisPrescription{
  528. ModeId: schedule.ModeId,
  529. }
  530. _, errcode := service.GetDialysisPrescribe(schedule.UserOrgId, schedule.PatientId, schedule.ScheduleDate)
  531. if errcode == gorm.ErrRecordNotFound {
  532. if err != nil {
  533. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeChangeScheduleFail)
  534. return
  535. }
  536. c.ServeSuccessJSON(map[string]interface{}{
  537. "msg": "ok",
  538. "schedule": &schedule,
  539. })
  540. } else if errcode == nil {
  541. err = service.UpdatedDialysisPrescription(&prescription, schedule.ScheduleDate, schedule.PatientId, schedule.UserOrgId)
  542. if err != nil {
  543. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeChangeScheduleFail)
  544. return
  545. }
  546. c.ServeSuccessJSON(map[string]interface{}{
  547. "msg": "ok",
  548. "schedule": &schedule,
  549. })
  550. }
  551. }
  552. // /api/schedule/print/initdata [get]
  553. // @param date:string yyyy-MM-dd 要打印的那一周中的任一天
  554. func (this *ScheduleApiController) PrintInitData() {
  555. dateStr := this.GetString("date")
  556. //week_type, _ := this.GetInt64("type", 0)
  557. var date *time.Time
  558. if len(dateStr) == 0 {
  559. now := time.Now()
  560. date = &now
  561. } else {
  562. var parseErr error
  563. date, parseErr = utils.ParseTimeStringToTime("2006-01-02", dateStr)
  564. if parseErr != nil {
  565. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  566. return
  567. }
  568. }
  569. adminUserInfo := this.GetAdminUserInfo()
  570. // 获取本周的排班
  571. var monday time.Time
  572. var sunday time.Time
  573. //switch week_type {
  574. //case 1:
  575. monday, sunday = utils.GetMondayAndSundayOfWeekDate(date)
  576. // break
  577. //case 2:
  578. // monday, sunday = utils.GetMondayAndSundayOfNextWeekDate(date)
  579. //
  580. // break
  581. //case 3:
  582. // monday, sunday = utils.GetMondayAndSundayOfNextNextWeekDate(date)
  583. // break
  584. //}
  585. schedules, getScheduleErr := service.GetPrinitWeekSchedules(adminUserInfo.CurrentOrgId, monday.Unix(), sunday.Unix())
  586. total, getScheduleErr := service.GetPrinitWeekTotal(adminUserInfo.CurrentOrgId, monday.Unix(), sunday.Unix())
  587. if getScheduleErr != nil {
  588. this.ErrorLog("获取周排班失败:%v", getScheduleErr)
  589. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  590. return
  591. }
  592. thisTime := date
  593. weekDay := int(thisTime.Weekday())
  594. if weekDay == 0 {
  595. weekDay = 7
  596. }
  597. weekEnd := 7 - weekDay
  598. weekStart := weekEnd - 6
  599. days := make([]string, 0)
  600. for index := weekStart; index <= weekEnd; index++ {
  601. theDay := thisTime.AddDate(0, 0, index)
  602. days = append(days, theDay.Format("2006-01-02"))
  603. }
  604. this.ServeSuccessJSON(map[string]interface{}{
  605. "total": total,
  606. "schedules": schedules,
  607. "monday": monday.Unix(),
  608. "days": days,
  609. })
  610. }
  611. func (this *ScheduleApiController) UrgentScheduleData() {
  612. schedule_type, _ := this.GetInt("type", 0)
  613. schedule_date := this.GetString("date")
  614. var date *time.Time
  615. if len(schedule_date) == 0 {
  616. now := time.Now()
  617. date = &now
  618. } else {
  619. var parseErr error
  620. date, parseErr = utils.ParseTimeStringToTime("2006-01-02", schedule_date)
  621. if parseErr != nil {
  622. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  623. return
  624. }
  625. }
  626. adminUserInfo := this.GetAdminUserInfo()
  627. deviceNumbers, getDeviceNumbersErr := service.MobileGetAllDeviceNumbersForUrgentSchedule(adminUserInfo.CurrentOrgId, date.Unix(), schedule_type)
  628. if getDeviceNumbersErr != nil {
  629. this.ErrorLog("获取所有床位失败:%v", getDeviceNumbersErr)
  630. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  631. return
  632. }
  633. // today := utils.ZeroHourTimeOfDay(time.Now())
  634. schedules, getSchedulesErr := service.MobileGetOtherSchedulesForUrgentSchedule(adminUserInfo.CurrentOrgId, date.Unix(), schedule_type)
  635. if getSchedulesErr != nil {
  636. this.ErrorLog("获取所有排班失败:%v", getSchedulesErr)
  637. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  638. return
  639. }
  640. this.ServeSuccessJSON(map[string]interface{}{
  641. "device_numbers": deviceNumbers,
  642. "schedules": schedules,
  643. })
  644. }
  645. func (this *ScheduleApiController) SearchSchedulePatients() {
  646. keywords := this.GetString("keywords")
  647. week_type, _ := this.GetInt64("week_type", 0)
  648. thisTime1 := time.Now()
  649. thisTime2 := time.Now()
  650. thisTime1 = thisTime1.AddDate(0, 0, 7)
  651. thisTime2 = thisTime2.AddDate(0, 0, 14)
  652. var start_time string
  653. var end_time string
  654. switch week_type {
  655. case 1:
  656. adminUserInfo := this.GetAdminUserInfo()
  657. list, _ := service.GetSchedualPatientsByKeywords(keywords, adminUserInfo.CurrentOrgId)
  658. this.ServeSuccessJSON(map[string]interface{}{
  659. "schdules": list,
  660. })
  661. break
  662. case 2:
  663. days := make([]string, 0)
  664. weekDay1 := int(thisTime1.Weekday())
  665. if weekDay1 == 0 {
  666. weekDay1 = 7
  667. }
  668. weekEnd1 := 7 - weekDay1
  669. weekStart1 := weekEnd1 - 6
  670. for index := weekStart1; index <= weekEnd1; index++ {
  671. fmt.Println(index)
  672. theDay := thisTime1.AddDate(0, 0, index)
  673. days = append(days, theDay.Format("2006-01-02"))
  674. }
  675. fmt.Println(days)
  676. start_time = days[0]
  677. end_time = days[len(days)-1]
  678. timeLayout := "2006-01-02"
  679. loc, _ := time.LoadLocation("Local")
  680. var theStartTime int64
  681. if len(start_time) > 0 {
  682. theTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  683. theStartTime = theTime.Unix()
  684. }
  685. var theEndtTime int64
  686. if len(end_time) > 0 {
  687. theTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  688. theEndtTime = theTime.Unix()
  689. }
  690. adminUserInfo := this.GetAdminUserInfo()
  691. list, _ := service.GetSchedualPatientsByKeywordsAndWeek(keywords, adminUserInfo.CurrentOrgId, theStartTime, theEndtTime)
  692. this.ServeSuccessJSON(map[string]interface{}{
  693. "schdules": list,
  694. })
  695. break
  696. case 3:
  697. days := make([]string, 0)
  698. weekDay2 := int(thisTime2.Weekday())
  699. if weekDay2 == 0 {
  700. weekDay2 = 7
  701. }
  702. weekEnd2 := 7 - weekDay2
  703. weekStart2 := weekEnd2 - 6
  704. for index := weekStart2; index <= weekEnd2; index++ {
  705. theDay := thisTime2.AddDate(0, 0, index)
  706. days = append(days, theDay.Format("2006-01-02"))
  707. }
  708. start_time = days[0]
  709. end_time = days[len(days)-1]
  710. timeLayout := "2006-01-02"
  711. loc, _ := time.LoadLocation("Local")
  712. var theStartTime int64
  713. if len(start_time) > 0 {
  714. theTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  715. theStartTime = theTime.Unix()
  716. }
  717. var theEndtTime int64
  718. if len(end_time) > 0 {
  719. theTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  720. theEndtTime = theTime.Unix()
  721. }
  722. adminUserInfo := this.GetAdminUserInfo()
  723. list, _ := service.GetSchedualPatientsByKeywordsAndWeek(keywords, adminUserInfo.CurrentOrgId, theStartTime, theEndtTime)
  724. this.ServeSuccessJSON(map[string]interface{}{
  725. "schdules": list,
  726. })
  727. break
  728. }
  729. }
  730. func (this *ScheduleApiController) GetWeekDaySchedule() {
  731. week_type, _ := this.GetInt64("week_type", -1)
  732. week_time, _ := this.GetInt64("week_time")
  733. thisTime := time.Now()
  734. weekDay := int(thisTime.Weekday())
  735. if weekDay == 0 {
  736. weekDay = 7
  737. }
  738. weekEnd := 7 - weekDay
  739. weekStart := weekEnd - 6
  740. weekTitle := make([]string, 0)
  741. days := make([]string, 0)
  742. for index := weekStart; index <= weekEnd; index++ {
  743. theDay := thisTime.AddDate(0, 0, index)
  744. indexYear, indexMonthTime, indexDay := theDay.Date()
  745. indexMonth := int(indexMonthTime)
  746. indexWeek := strconv.Itoa(indexYear) + "." + strconv.Itoa(indexMonth) + "." + strconv.Itoa(indexDay)
  747. weekTitle = append(weekTitle, indexWeek)
  748. days = append(days, theDay.Format("2006-01-02"))
  749. }
  750. fmt.Println(days)
  751. var targetDayStr string
  752. var startTime string
  753. var endTime string
  754. switch week_type {
  755. case 0:
  756. {
  757. startTime = days[0]
  758. endTime = days[6]
  759. }
  760. case 1:
  761. targetDayStr = days[0]
  762. break
  763. case 2:
  764. targetDayStr = days[1]
  765. break
  766. case 3:
  767. targetDayStr = days[2]
  768. break
  769. case 4:
  770. targetDayStr = days[3]
  771. break
  772. case 5:
  773. targetDayStr = days[4]
  774. break
  775. case 6:
  776. targetDayStr = days[5]
  777. break
  778. case 7:
  779. targetDayStr = days[6]
  780. break
  781. }
  782. targetDay, parseErr := utils.ParseTimeStringToTime("2006-01-02", targetDayStr)
  783. startDay, _ := utils.ParseTimeStringToTime("2006-01-02", startTime)
  784. endDay, _ := utils.ParseTimeStringToTime("2006-01-02", endTime)
  785. fmt.Println(startDay, endDay)
  786. if parseErr != nil {
  787. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  788. return
  789. }
  790. orgId := this.GetAdminUserInfo().CurrentOrgId
  791. list, _ := service.GetWeekDayScheduleTwo(orgId, targetDay.Unix(), targetDay, week_time)
  792. this.ServeSuccessJSON(map[string]interface{}{
  793. "schdules": list,
  794. "day": targetDayStr,
  795. })
  796. }
  797. func Struct2Map(obj interface{}) map[string]interface{} {
  798. t := reflect.TypeOf(obj)
  799. v := reflect.ValueOf(obj)
  800. var data = make(map[string]interface{})
  801. for i := 0; i < t.NumField(); i++ {
  802. data[t.Field(i).Name] = v.Field(i).Interface()
  803. }
  804. return data
  805. }
  806. func (this *ScheduleApiController) ExportSchedule() {
  807. dataBody := make(map[string]interface{}, 0)
  808. err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
  809. if err != nil {
  810. utils.ErrorLog(err.Error())
  811. return
  812. }
  813. utils.ErrorLog("%v", dataBody)
  814. export_time := time.Now().Unix()
  815. var schedules []*models.Schedule
  816. var failed_total int
  817. var total_schedule []interface{}
  818. var patients []*models.Patients
  819. patients, _, _ = service.GetAllPatientList(this.GetAdminUserInfo().CurrentOrgId)
  820. if dataBody["failed_schedule"] != nil || reflect.TypeOf(dataBody["failed_schedule"]).String() == "[]interface {}" {
  821. tempSchedule := dataBody["failed_schedule"].([]interface{})
  822. failed_total = len(tempSchedule)
  823. }
  824. if dataBody["schedule"] != nil || reflect.TypeOf(dataBody["schedule"]).String() == "[]interface {}" {
  825. tempSchedule := dataBody["schedule"].([]interface{})
  826. total_schedule = tempSchedule
  827. for _, schMap := range tempSchedule {
  828. schMapM := schMap.(map[string]interface{})
  829. var sch models.Schedule
  830. if schMapM["name"] == nil || reflect.TypeOf(schMapM["name"]).String() != "string" {
  831. utils.ErrorLog("name")
  832. return
  833. }
  834. name, _ := schMapM["name"].(string)
  835. fmt.Println(name)
  836. if len(name) == 0 { //名字为空则生成一条导入错误日志
  837. err_log := models.ExportErrLog{
  838. LogType: 2,
  839. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  840. ErrMsg: "第" + strconv.FormatInt(int64(schMapM["index"].(float64)), 10) + "行,第" + schMapM["row"].(string) + "列的姓名不能为空",
  841. Status: 1,
  842. CreateTime: time.Now().Unix(),
  843. UpdateTime: time.Now().Unix(),
  844. ExportTime: export_time,
  845. }
  846. service.CreateExportErrLog(&err_log)
  847. continue
  848. } else {
  849. var patient []*models.Patients
  850. for _, item := range patients {
  851. if strings.Replace(item.Name, " ", "", -1) == name {
  852. patient = append(patient, item)
  853. }
  854. }
  855. if len(patient) == 0 { //错误日志
  856. err_log := models.ExportErrLog{
  857. LogType: 2,
  858. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  859. ErrMsg: "第" + strconv.FormatInt(int64(schMapM["index"].(float64)), 10) + "行,第" + schMapM["row"].(string) + "列,患者姓名为\"" + name + "\"在系统中不存在,请在系统中添加该患者",
  860. Status: 1,
  861. CreateTime: time.Now().Unix(),
  862. UpdateTime: time.Now().Unix(),
  863. ExportTime: export_time,
  864. }
  865. service.CreateExportErrLog(&err_log)
  866. continue
  867. } else if len(patient) == 1 { //
  868. sch.PatientId = patient[0].ID
  869. } else if len(patient) > 1 { //出现同名的情况
  870. err_log := models.ExportErrLog{
  871. LogType: 2,
  872. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  873. //ErrMsg: "第" + strconv.FormatInt(int64(schMapM["index"].(float64)), 10) + "行,第" + schMapM["row"].(string) + "列" + "患者姓名为" + name + "在当前机构中存在重名,无法确定到具体患者",
  874. ErrMsg: "第" + strconv.FormatInt(int64(schMapM["index"].(float64)), 10) + "行,第" + schMapM["row"].(string) + "列,患者姓名为\"" + name + "\"在在当前机构中存在重名,无法确定到具体患者",
  875. Status: 1,
  876. CreateTime: time.Now().Unix(),
  877. UpdateTime: time.Now().Unix(),
  878. ExportTime: export_time,
  879. }
  880. service.CreateExportErrLog(&err_log)
  881. continue
  882. }
  883. }
  884. if schMapM["schedule_type"] == nil && reflect.TypeOf(schMapM["schedule_type"]).String() != "float64" {
  885. utils.ErrorLog("schedule_type")
  886. return
  887. }
  888. schedule_type := int64(schMapM["schedule_type"].(float64))
  889. if schedule_type <= 0 { //班次格式有误,插入日志
  890. log := models.ExportLog{
  891. LogType: 2,
  892. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  893. TotalNum: int64(len(total_schedule) + failed_total),
  894. FailNum: 1 + int64(failed_total),
  895. SuccessNum: int64(len(schedules)),
  896. CreateTime: time.Now().Unix(),
  897. UpdateTime: time.Now().Unix(),
  898. ExportTime: export_time,
  899. Status: 1,
  900. }
  901. service.CreateExportLog(&log)
  902. err_log := models.ExportErrLog{
  903. LogType: 2,
  904. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  905. ErrMsg: "第2行第" + schMapM["row"].(string) + "列的班次格式有误",
  906. Status: 1,
  907. CreateTime: time.Now().Unix(),
  908. UpdateTime: time.Now().Unix(),
  909. ExportTime: export_time,
  910. }
  911. service.CreateExportErrLog(&err_log)
  912. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeExportError)
  913. return
  914. } else {
  915. sch.ScheduleType = schedule_type
  916. }
  917. if schMapM["partition_name"] == nil || reflect.TypeOf(schMapM["partition_name"]).String() != "string" {
  918. utils.ErrorLog("partition_name")
  919. return
  920. }
  921. partition_name, _ := schMapM["partition_name"].(string)
  922. if len(partition_name) == 0 { //分区为空
  923. log := models.ExportLog{
  924. LogType: 2,
  925. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  926. TotalNum: int64(len(total_schedule) + failed_total),
  927. FailNum: 1 + int64(failed_total),
  928. SuccessNum: int64(len(schedules)),
  929. CreateTime: time.Now().Unix(),
  930. UpdateTime: time.Now().Unix(),
  931. ExportTime: export_time,
  932. Status: 1,
  933. }
  934. service.CreateExportLog(&log)
  935. err_log := models.ExportErrLog{
  936. LogType: 2,
  937. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  938. //ErrMsg: "第" + strconv.FormatInt(int64(schMapM["index"].(float64)) ,10)+ "行" + "的姓名不能为空",
  939. ErrMsg: "第" + strconv.FormatInt(int64(schMapM["index"].(float64)), 10) + "行第1列所属的分区格式有误",
  940. Status: 1,
  941. CreateTime: time.Now().Unix(),
  942. UpdateTime: time.Now().Unix(),
  943. ExportTime: export_time,
  944. }
  945. service.CreateExportErrLog(&err_log)
  946. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeExportError)
  947. return
  948. } else {
  949. zone, err := service.FindDeviceZoneByName(partition_name, this.GetAdminUserInfo().CurrentOrgId)
  950. if err == nil {
  951. sch.PartitionId = zone.ID
  952. } else if err == gorm.ErrRecordNotFound { //查不到数据,插入错误日志
  953. log := models.ExportLog{
  954. LogType: 2,
  955. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  956. TotalNum: int64(len(total_schedule) + failed_total),
  957. FailNum: 1 + int64(failed_total),
  958. SuccessNum: int64(len(schedules)),
  959. CreateTime: time.Now().Unix(),
  960. UpdateTime: time.Now().Unix(),
  961. ExportTime: export_time,
  962. Status: 1,
  963. }
  964. service.CreateExportLog(&log)
  965. err_log := models.ExportErrLog{
  966. LogType: 2,
  967. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  968. //ErrMsg: "第" + strconv.FormatInt(int64(schMapM["index"].(float64)) ,10)+ "行" + "的姓名不能为空",
  969. ErrMsg: "第" + strconv.FormatInt(int64(schMapM["index"].(float64)), 10) + "行第1列所属的分区格式有误",
  970. Status: 1,
  971. CreateTime: time.Now().Unix(),
  972. UpdateTime: time.Now().Unix(),
  973. ExportTime: export_time,
  974. }
  975. service.CreateExportErrLog(&err_log)
  976. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeExportError)
  977. return
  978. }
  979. }
  980. if schMapM["device_number_name"] == nil || reflect.TypeOf(schMapM["device_number_name"]).String() != "string" {
  981. utils.ErrorLog("device_number_name")
  982. return
  983. }
  984. device_number_name, _ := schMapM["device_number_name"].(string)
  985. if len(device_number_name) == 0 { //分区为空
  986. log := models.ExportLog{
  987. LogType: 2,
  988. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  989. TotalNum: int64(len(total_schedule) + failed_total),
  990. FailNum: 1 + int64(failed_total),
  991. SuccessNum: int64(len(schedules)),
  992. CreateTime: time.Now().Unix(),
  993. UpdateTime: time.Now().Unix(),
  994. ExportTime: export_time,
  995. Status: 1,
  996. }
  997. service.CreateExportLog(&log)
  998. err_log := models.ExportErrLog{
  999. LogType: 2,
  1000. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  1001. //ErrMsg: "第" + strconv.FormatInt(int64(schMapM["index"].(float64)) ,10)+ "行" + "的姓名不能为空",
  1002. ErrMsg: "第" + strconv.FormatInt(int64(schMapM["index"].(float64)), 10) + "行第2列机号格式有误",
  1003. Status: 1,
  1004. CreateTime: time.Now().Unix(),
  1005. UpdateTime: time.Now().Unix(),
  1006. ExportTime: export_time,
  1007. }
  1008. service.CreateExportErrLog(&err_log)
  1009. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeExportError)
  1010. return
  1011. } else {
  1012. device, err := service.FindDeviceByName(device_number_name, this.GetAdminUserInfo().CurrentOrgId, sch.PartitionId)
  1013. if err == nil {
  1014. if len(device) == 0 { //没查到数据,插入错误日志
  1015. log := models.ExportLog{
  1016. LogType: 2,
  1017. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  1018. TotalNum: int64(len(total_schedule) + failed_total),
  1019. FailNum: 1 + int64(failed_total),
  1020. SuccessNum: int64(len(schedules)),
  1021. CreateTime: time.Now().Unix(),
  1022. UpdateTime: time.Now().Unix(),
  1023. ExportTime: export_time,
  1024. Status: 1,
  1025. }
  1026. service.CreateExportLog(&log)
  1027. err_log := models.ExportErrLog{
  1028. LogType: 2,
  1029. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  1030. ErrMsg: "第" + strconv.FormatInt(int64(schMapM["index"].(float64)), 10) + "行第2列机号格式有误",
  1031. Status: 1,
  1032. CreateTime: time.Now().Unix(),
  1033. UpdateTime: time.Now().Unix(),
  1034. ExportTime: export_time,
  1035. }
  1036. service.CreateExportErrLog(&err_log)
  1037. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeExportError)
  1038. return
  1039. } else if len(device) == 1 {
  1040. sch.BedId = device[0].ID
  1041. } else if len(device) > 1 { //出现重名,插入错误日志
  1042. log := models.ExportLog{
  1043. LogType: 2,
  1044. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  1045. TotalNum: int64(len(total_schedule) + failed_total),
  1046. FailNum: 1 + int64(failed_total),
  1047. SuccessNum: int64(len(schedules)),
  1048. CreateTime: time.Now().Unix(),
  1049. UpdateTime: time.Now().Unix(),
  1050. ExportTime: export_time,
  1051. Status: 1,
  1052. }
  1053. service.CreateExportLog(&log)
  1054. err_log := models.ExportErrLog{
  1055. LogType: 2,
  1056. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  1057. ErrMsg: "出现两个床位号相同的床位",
  1058. Status: 1,
  1059. CreateTime: time.Now().Unix(),
  1060. UpdateTime: time.Now().Unix(),
  1061. ExportTime: export_time,
  1062. }
  1063. service.CreateExportErrLog(&err_log)
  1064. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeExportError)
  1065. return
  1066. }
  1067. }
  1068. }
  1069. if schMapM["schedule_week"] == nil || reflect.TypeOf(schMapM["schedule_week"]).String() != "string" {
  1070. utils.ErrorLog("schedule_week")
  1071. return
  1072. }
  1073. schedule_week, _ := schMapM["schedule_week"].(string)
  1074. if len(schedule_week) == 0 { //周几为空则生成一条导入错误日志
  1075. log := models.ExportLog{
  1076. LogType: 2,
  1077. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  1078. TotalNum: int64(len(total_schedule) + failed_total),
  1079. FailNum: 1 + int64(failed_total),
  1080. SuccessNum: int64(len(schedules)),
  1081. CreateTime: time.Now().Unix(),
  1082. UpdateTime: time.Now().Unix(),
  1083. ExportTime: export_time,
  1084. Status: 1,
  1085. }
  1086. service.CreateExportLog(&log)
  1087. err_log := models.ExportErrLog{
  1088. LogType: 2,
  1089. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  1090. //ErrMsg: "第" + strconv.FormatInt(int64(schMapM["index"].(float64)) ,10)+ "行" + "的姓名不能为空",
  1091. ErrMsg: "第1行第" + schMapM["row"].(string) + "列的星期名格式有误",
  1092. Status: 1,
  1093. CreateTime: time.Now().Unix(),
  1094. UpdateTime: time.Now().Unix(),
  1095. ExportTime: export_time,
  1096. }
  1097. service.CreateExportErrLog(&err_log)
  1098. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeExportError)
  1099. return
  1100. } else if schedule_week == "0" { //周几不符合格式则生成一条导入错误日志
  1101. log := models.ExportLog{
  1102. LogType: 2,
  1103. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  1104. TotalNum: int64(len(total_schedule) + failed_total),
  1105. FailNum: 1 + int64(failed_total),
  1106. SuccessNum: int64(len(schedules)),
  1107. CreateTime: time.Now().Unix(),
  1108. UpdateTime: time.Now().Unix(),
  1109. ExportTime: export_time,
  1110. Status: 1,
  1111. }
  1112. service.CreateExportLog(&log)
  1113. err_log := models.ExportErrLog{
  1114. LogType: 2,
  1115. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  1116. ErrMsg: "第1行第" + schMapM["row"].(string) + "列的星期名格式有误",
  1117. Status: 1,
  1118. CreateTime: time.Now().Unix(),
  1119. UpdateTime: time.Now().Unix(),
  1120. ExportTime: export_time,
  1121. }
  1122. service.CreateExportErrLog(&err_log)
  1123. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeExportError)
  1124. return
  1125. } else {
  1126. schedule_week, _ := strconv.ParseInt(schedule_week, 10, 64)
  1127. sch.ScheduleWeek = schedule_week
  1128. }
  1129. if schMapM["schedule_date"] == nil || reflect.TypeOf(schMapM["schedule_date"]).String() != "string" {
  1130. utils.ErrorLog("schedule_date")
  1131. return
  1132. }
  1133. schedule_date, _ := schMapM["schedule_date"].(string)
  1134. if len(schedule_date) == 0 { //周几为空则生成一条导入错误日志
  1135. log := models.ExportLog{
  1136. LogType: 2,
  1137. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  1138. TotalNum: int64(len(total_schedule) + failed_total),
  1139. FailNum: 1 + int64(failed_total),
  1140. SuccessNum: int64(len(schedules)),
  1141. CreateTime: time.Now().Unix(),
  1142. UpdateTime: time.Now().Unix(),
  1143. ExportTime: export_time,
  1144. Status: 1,
  1145. }
  1146. service.CreateExportLog(&log)
  1147. err_log := models.ExportErrLog{
  1148. LogType: 2,
  1149. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  1150. ErrMsg: "第1行第" + schMapM["row"].(string) + "列的星期名格式有误",
  1151. Status: 1,
  1152. CreateTime: time.Now().Unix(),
  1153. UpdateTime: time.Now().Unix(),
  1154. ExportTime: export_time,
  1155. }
  1156. service.CreateExportErrLog(&err_log)
  1157. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeExportError)
  1158. return
  1159. } else if schedule_date == "0" { //周几不符合格式则生成一条导入错误日志
  1160. log := models.ExportLog{
  1161. LogType: 2,
  1162. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  1163. TotalNum: int64(len(total_schedule) + failed_total),
  1164. FailNum: 1 + int64(failed_total),
  1165. SuccessNum: int64(len(schedules)),
  1166. CreateTime: time.Now().Unix(),
  1167. UpdateTime: time.Now().Unix(),
  1168. ExportTime: export_time,
  1169. Status: 1,
  1170. }
  1171. service.CreateExportLog(&log)
  1172. err_log := models.ExportErrLog{
  1173. LogType: 2,
  1174. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  1175. ErrMsg: "第1行第" + schMapM["row"].(string) + "列的星期名格式有误",
  1176. Status: 1,
  1177. CreateTime: time.Now().Unix(),
  1178. UpdateTime: time.Now().Unix(),
  1179. ExportTime: export_time,
  1180. }
  1181. service.CreateExportErrLog(&err_log)
  1182. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeExportError)
  1183. return
  1184. } else {
  1185. date, _ := utils.ParseTimeStringToTime("2006-01-02", schedule_date)
  1186. sch.ScheduleDate = date.Unix()
  1187. }
  1188. sch.CreatedTime = time.Now().Unix()
  1189. sch.UpdatedTime = time.Now().Unix()
  1190. sch.ModeId = 1
  1191. sch.Status = 1
  1192. sch.UserOrgId = this.GetAdminUserInfo().CurrentOrgId
  1193. sch.IsExport = 1
  1194. schedules = append(schedules, &sch)
  1195. }
  1196. errLogs, _ := service.FindSchedualExportLog(this.GetAdminUserInfo().CurrentOrgId, export_time)
  1197. if len(schedules) > 0 {
  1198. //schedule_date := time.Now().Format("2006-01-02")
  1199. //date, _ := utils.ParseTimeStringToTime("2006-01-02", schedule_date)
  1200. //clear_schedule_date := date.Unix() //根据日期去清除,该日期未来的排班数据
  1201. //err := service.UpdateScheduleStatus(clear_schedule_date, this.GetAdminUserInfo().CurrentOrgId)
  1202. if err == nil {
  1203. for _, item := range schedules {
  1204. //查找当天日期是否存在
  1205. _, errcode := service.GetTodayScheduleIsExist(item.PatientId, item.ScheduleDate, item.UserOrgId, item.ModeId, item.ScheduleType)
  1206. if errcode == gorm.ErrRecordNotFound {
  1207. service.CreateSchedule(item)
  1208. } else if errcode == nil {
  1209. schedule := models.XtSchedule{
  1210. PartitionId: item.PartitionId,
  1211. BedId: item.BedId,
  1212. PatientId: item.PatientId,
  1213. ScheduleDate: item.ScheduleDate,
  1214. ScheduleType: item.ScheduleType,
  1215. ScheduleWeek: item.ScheduleWeek,
  1216. ModeId: item.ModeId,
  1217. Status: 1,
  1218. }
  1219. service.UpdateScheduleByOrgId(item.PatientId, item.ScheduleDate, item.UserOrgId, item.ModeId, item.ScheduleType, &schedule)
  1220. }
  1221. }
  1222. log := models.ExportLog{
  1223. LogType: 2,
  1224. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  1225. TotalNum: int64(len(total_schedule) + failed_total),
  1226. FailNum: int64(len(errLogs) + failed_total),
  1227. SuccessNum: int64(len(schedules)),
  1228. CreateTime: time.Now().Unix(),
  1229. UpdateTime: time.Now().Unix(),
  1230. ExportTime: export_time,
  1231. Status: 1,
  1232. }
  1233. service.CreateExportLog(&log)
  1234. if failed_total > 0 {
  1235. err_log := models.ExportErrLog{
  1236. LogType: 2,
  1237. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  1238. ErrMsg: "当前日期(" + time.Now().Format("2006-01-02") + " " + GetWeekString(time.Now().Weekday().String()) +
  1239. ")及以前的排班数据" + strconv.FormatInt(int64(failed_total), 10) + "条,不执行导入",
  1240. Status: 1,
  1241. CreateTime: time.Now().Unix(),
  1242. UpdateTime: time.Now().Unix(),
  1243. ExportTime: export_time,
  1244. }
  1245. service.CreateExportErrLog(&err_log)
  1246. }
  1247. this.ServeSuccessJSON(map[string]interface{}{
  1248. "msg": "导入成功",
  1249. "total_num": len(total_schedule) + failed_total,
  1250. "success_num": len(schedules),
  1251. "fail_num": int64(len(errLogs)),
  1252. })
  1253. } else {
  1254. log := models.ExportLog{
  1255. LogType: 2,
  1256. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  1257. TotalNum: int64(len(total_schedule) + failed_total),
  1258. FailNum: int64(len(errLogs) + failed_total),
  1259. SuccessNum: int64(len(schedules)),
  1260. CreateTime: time.Now().Unix(),
  1261. UpdateTime: time.Now().Unix(),
  1262. ExportTime: export_time,
  1263. Status: 1,
  1264. }
  1265. service.CreateExportLog(&log)
  1266. if failed_total > 0 {
  1267. err_log := models.ExportErrLog{
  1268. LogType: 2,
  1269. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  1270. ErrMsg: "当前日期(" + time.Now().Format("2006-01-02") + " " + GetWeekString(time.Now().Weekday().String()) +
  1271. ")及以前的排班数据" + strconv.FormatInt(int64(failed_total), 10) + "条,不执行导入",
  1272. Status: 1,
  1273. CreateTime: time.Now().Unix(),
  1274. UpdateTime: time.Now().Unix(),
  1275. ExportTime: export_time,
  1276. }
  1277. service.CreateExportErrLog(&err_log)
  1278. }
  1279. this.ServeSuccessJSON(map[string]interface{}{
  1280. "msg": "导入成功",
  1281. "total_num": len(total_schedule),
  1282. "success_num": len(schedules),
  1283. "fail_num": int64(len(errLogs)),
  1284. })
  1285. }
  1286. } else {
  1287. log := models.ExportLog{
  1288. LogType: 2,
  1289. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  1290. TotalNum: int64(len(total_schedule) + failed_total),
  1291. FailNum: int64(len(errLogs) + failed_total),
  1292. SuccessNum: int64(len(schedules)),
  1293. CreateTime: time.Now().Unix(),
  1294. UpdateTime: time.Now().Unix(),
  1295. ExportTime: export_time,
  1296. Status: 1,
  1297. }
  1298. service.CreateExportLog(&log)
  1299. if failed_total > 0 {
  1300. err_log := models.ExportErrLog{
  1301. LogType: 2,
  1302. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  1303. ErrMsg: "当前日期(" + time.Now().Format("2006-01-02") + " " + GetWeekString(time.Now().Weekday().String()) +
  1304. ")及以前的排班数据" + strconv.FormatInt(int64(failed_total), 10) + "条,不执行导入",
  1305. Status: 1,
  1306. CreateTime: time.Now().Unix(),
  1307. UpdateTime: time.Now().Unix(),
  1308. ExportTime: export_time,
  1309. }
  1310. service.CreateExportErrLog(&err_log)
  1311. }
  1312. this.ServeSuccessJSON(map[string]interface{}{
  1313. "msg": "导入成功",
  1314. "total_num": len(total_schedule),
  1315. "success_num": len(schedules),
  1316. "fail_num": int64(len(errLogs)),
  1317. })
  1318. }
  1319. }
  1320. }
  1321. func (this *ScheduleApiController) ExportScheduleTemplate() {
  1322. dataBody := make(map[string]interface{}, 0)
  1323. err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
  1324. if err != nil {
  1325. utils.ErrorLog(err.Error())
  1326. return
  1327. }
  1328. utils.ErrorLog("%v", dataBody)
  1329. export_time := time.Now().Unix()
  1330. var schedules []*models.PatientScheduleTemplateItem
  1331. var total_schedule []interface{}
  1332. patients, _, _ := service.GetAllPatientList(this.GetAdminUserInfo().CurrentOrgId)
  1333. if dataBody["schedule"] != nil || reflect.TypeOf(dataBody["schedule"]).String() == "[]interface {}" {
  1334. tempSchedule := dataBody["schedule"].([]interface{})
  1335. total_schedule = tempSchedule
  1336. for _, schMap := range tempSchedule {
  1337. schMapM := schMap.(map[string]interface{})
  1338. var sch models.PatientScheduleTemplateItem
  1339. if schMapM["name"] == nil || reflect.TypeOf(schMapM["name"]).String() != "string" {
  1340. utils.ErrorLog("name")
  1341. return
  1342. }
  1343. name, _ := schMapM["name"].(string)
  1344. fmt.Println(name)
  1345. if len(name) == 0 { //名字为空则生成一条导入错误日志
  1346. err_log := models.ExportErrLog{
  1347. LogType: 3,
  1348. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  1349. ErrMsg: "第" + strconv.FormatInt(int64(schMapM["index"].(float64)), 10) + "行,第" + schMapM["row"].(string) + "列的姓名不能为空",
  1350. Status: 1,
  1351. CreateTime: time.Now().Unix(),
  1352. UpdateTime: time.Now().Unix(),
  1353. ExportTime: export_time,
  1354. }
  1355. service.CreateExportErrLog(&err_log)
  1356. continue
  1357. } else {
  1358. var patient []*models.Patients
  1359. for _, item := range patients {
  1360. if strings.Replace(item.Name, " ", "", -1) == name {
  1361. patient = append(patient, item)
  1362. }
  1363. }
  1364. if len(patient) == 0 { //错误日志
  1365. err_log := models.ExportErrLog{
  1366. LogType: 3,
  1367. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  1368. //ErrMsg: "第" + strconv.FormatInt(int64(schMapM["index"].(float64)), 10) + "行,第" + schMapM["row"].(string) + "列的姓名在系统中不存在,请在系统中添加该病人",
  1369. ErrMsg: "第" + strconv.FormatInt(int64(schMapM["index"].(float64)), 10) + "行,第" + schMapM["row"].(string) + "列患者姓名为\"" + name + "\"在系统中不存在,请在系统中添加该患者",
  1370. Status: 1,
  1371. CreateTime: time.Now().Unix(),
  1372. UpdateTime: time.Now().Unix(),
  1373. ExportTime: export_time,
  1374. }
  1375. service.CreateExportErrLog(&err_log)
  1376. continue
  1377. } else if len(patient) == 1 { //
  1378. sch.PatientID = patient[0].ID
  1379. } else if len(patient) > 1 { //出现同名的情况
  1380. err_log := models.ExportErrLog{
  1381. LogType: 3,
  1382. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  1383. //ErrMsg: "第" + strconv.FormatInt(int64(schMapM["index"].(float64)), 10) + "行,第" + schMapM["row"].(string) + "列" + "患者姓名为" + name + "在当前机构中存在重名,无法确定到具体患者",
  1384. ErrMsg: "第" + strconv.FormatInt(int64(schMapM["index"].(float64)), 10) + "行,第" + schMapM["row"].(string) + "列患者姓名为\"" + name + "\"在当前机构中存在重名,无法确定到具体患者",
  1385. Status: 1,
  1386. CreateTime: time.Now().Unix(),
  1387. UpdateTime: time.Now().Unix(),
  1388. ExportTime: export_time,
  1389. }
  1390. service.CreateExportErrLog(&err_log)
  1391. continue
  1392. }
  1393. }
  1394. if schMapM["schedule_type"] == nil && reflect.TypeOf(schMapM["schedule_type"]).String() != "float64" {
  1395. utils.ErrorLog("schedule_type")
  1396. return
  1397. }
  1398. schedule_type := int64(schMapM["schedule_type"].(float64))
  1399. if schedule_type <= 0 { //班次格式有误,插入日志
  1400. log := models.ExportLog{
  1401. LogType: 3,
  1402. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  1403. TotalNum: int64(len(total_schedule)),
  1404. FailNum: 1,
  1405. SuccessNum: int64(len(schedules)),
  1406. CreateTime: time.Now().Unix(),
  1407. UpdateTime: time.Now().Unix(),
  1408. ExportTime: export_time,
  1409. Status: 1,
  1410. }
  1411. service.CreateExportLog(&log)
  1412. err_log := models.ExportErrLog{
  1413. LogType: 3,
  1414. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  1415. ErrMsg: "第2行第" + schMapM["row"].(string) + "列的班次格式有误",
  1416. Status: 1,
  1417. CreateTime: time.Now().Unix(),
  1418. UpdateTime: time.Now().Unix(),
  1419. ExportTime: export_time,
  1420. }
  1421. service.CreateExportErrLog(&err_log)
  1422. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeExportError)
  1423. return
  1424. } else {
  1425. sch.TimeType = int8(schedule_type)
  1426. }
  1427. if schMapM["template_id"] == nil && reflect.TypeOf(schMapM["template_id"]).String() != "float64" {
  1428. utils.ErrorLog("template_id")
  1429. return
  1430. }
  1431. template_id := int64(schMapM["template_id"].(float64))
  1432. sch.TemplateID = template_id
  1433. if schMapM["device_number_name"] == nil || reflect.TypeOf(schMapM["device_number_name"]).String() != "string" {
  1434. utils.ErrorLog("device_number_name")
  1435. return
  1436. }
  1437. partition_name, _ := schMapM["partition_name"].(string)
  1438. zone, _ := service.FindDeviceZoneByName(partition_name, this.GetAdminUserInfo().CurrentOrgId)
  1439. device_number_name, _ := schMapM["device_number_name"].(string)
  1440. if len(device_number_name) == 0 { //分区为空
  1441. log := models.ExportLog{
  1442. LogType: 3,
  1443. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  1444. TotalNum: int64(len(total_schedule)),
  1445. FailNum: 1,
  1446. SuccessNum: int64(len(schedules)),
  1447. CreateTime: time.Now().Unix(),
  1448. UpdateTime: time.Now().Unix(),
  1449. ExportTime: export_time,
  1450. Status: 1,
  1451. }
  1452. service.CreateExportLog(&log)
  1453. err_log := models.ExportErrLog{
  1454. LogType: 3,
  1455. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  1456. //ErrMsg: "第" + strconv.FormatInt(int64(schMapM["index"].(float64)) ,10)+ "行" + "的姓名不能为空",
  1457. ErrMsg: "第" + strconv.FormatInt(int64(schMapM["index"].(float64)), 10) + "行第2列机号格式有误",
  1458. Status: 1,
  1459. CreateTime: time.Now().Unix(),
  1460. UpdateTime: time.Now().Unix(),
  1461. ExportTime: export_time,
  1462. }
  1463. service.CreateExportErrLog(&err_log)
  1464. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeExportError)
  1465. return
  1466. } else {
  1467. device, err := service.FindDeviceByNameTwo(device_number_name, this.GetAdminUserInfo().CurrentOrgId, zone.ID)
  1468. if err == nil {
  1469. if len(device) == 0 { //没查到数据,插入错误日志
  1470. log := models.ExportLog{
  1471. LogType: 3,
  1472. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  1473. TotalNum: int64(len(total_schedule)),
  1474. FailNum: 1,
  1475. SuccessNum: int64(len(schedules)),
  1476. CreateTime: time.Now().Unix(),
  1477. UpdateTime: time.Now().Unix(),
  1478. ExportTime: export_time,
  1479. Status: 1,
  1480. }
  1481. service.CreateExportLog(&log)
  1482. err_log := models.ExportErrLog{
  1483. LogType: 3,
  1484. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  1485. ErrMsg: "第" + strconv.FormatInt(int64(schMapM["index"].(float64)), 10) + "行第2列机号格式有误",
  1486. Status: 1,
  1487. CreateTime: time.Now().Unix(),
  1488. UpdateTime: time.Now().Unix(),
  1489. ExportTime: export_time,
  1490. }
  1491. service.CreateExportErrLog(&err_log)
  1492. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeExportError)
  1493. return
  1494. } else if len(device) == 1 {
  1495. sch.DeviceNumberID = device[0].ID
  1496. } else if len(device) > 1 { //出现重名,插入错误日志
  1497. log := models.ExportLog{
  1498. LogType: 3,
  1499. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  1500. TotalNum: int64(len(total_schedule)),
  1501. FailNum: 1,
  1502. SuccessNum: int64(len(schedules)),
  1503. CreateTime: time.Now().Unix(),
  1504. UpdateTime: time.Now().Unix(),
  1505. ExportTime: export_time,
  1506. Status: 1,
  1507. }
  1508. service.CreateExportLog(&log)
  1509. err_log := models.ExportErrLog{
  1510. LogType: 3,
  1511. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  1512. ErrMsg: "出现两个床位号相同的床位",
  1513. Status: 1,
  1514. CreateTime: time.Now().Unix(),
  1515. UpdateTime: time.Now().Unix(),
  1516. ExportTime: export_time,
  1517. }
  1518. service.CreateExportErrLog(&err_log)
  1519. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeExportError)
  1520. return
  1521. }
  1522. }
  1523. }
  1524. if schMapM["schedule_week"] == nil || reflect.TypeOf(schMapM["schedule_week"]).String() != "string" {
  1525. utils.ErrorLog("schedule_week")
  1526. return
  1527. }
  1528. schedule_week, _ := schMapM["schedule_week"].(string)
  1529. if len(schedule_week) == 0 { //周几为空则生成一条导入错误日志
  1530. log := models.ExportLog{
  1531. LogType: 3,
  1532. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  1533. TotalNum: int64(len(total_schedule)),
  1534. FailNum: 1,
  1535. SuccessNum: int64(len(schedules)),
  1536. CreateTime: time.Now().Unix(),
  1537. UpdateTime: time.Now().Unix(),
  1538. ExportTime: export_time,
  1539. Status: 1,
  1540. }
  1541. service.CreateExportLog(&log)
  1542. err_log := models.ExportErrLog{
  1543. LogType: 3,
  1544. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  1545. //ErrMsg: "第" + strconv.FormatInt(int64(schMapM["index"].(float64)) ,10)+ "行" + "的姓名不能为空",
  1546. ErrMsg: "第1行第" + schMapM["row"].(string) + "列的星期名格式有误",
  1547. Status: 1,
  1548. CreateTime: time.Now().Unix(),
  1549. UpdateTime: time.Now().Unix(),
  1550. ExportTime: export_time,
  1551. }
  1552. service.CreateExportErrLog(&err_log)
  1553. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeExportError)
  1554. return
  1555. } else if schedule_week == "0" { //周几不符合格式则生成一条导入错误日志
  1556. log := models.ExportLog{
  1557. LogType: 3,
  1558. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  1559. TotalNum: int64(len(total_schedule)),
  1560. FailNum: 1,
  1561. SuccessNum: int64(len(schedules)),
  1562. CreateTime: time.Now().Unix(),
  1563. UpdateTime: time.Now().Unix(),
  1564. ExportTime: export_time,
  1565. Status: 1,
  1566. }
  1567. service.CreateExportLog(&log)
  1568. err_log := models.ExportErrLog{
  1569. LogType: 3,
  1570. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  1571. ErrMsg: "第1行第" + schMapM["row"].(string) + "列的星期名格式有误",
  1572. Status: 1,
  1573. CreateTime: time.Now().Unix(),
  1574. UpdateTime: time.Now().Unix(),
  1575. ExportTime: export_time,
  1576. }
  1577. service.CreateExportErrLog(&err_log)
  1578. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeExportError)
  1579. return
  1580. } else {
  1581. schedule_week, _ := strconv.ParseInt(schedule_week, 10, 64)
  1582. sch.Weekday = int8(schedule_week)
  1583. }
  1584. sch.CreateTime = time.Now().Unix()
  1585. sch.ModifyTime = time.Now().Unix()
  1586. sch.TreatMode = 1
  1587. sch.Status = 1
  1588. sch.OrgID = this.GetAdminUserInfo().CurrentOrgId
  1589. sch.IsExport = 1
  1590. schedules = append(schedules, &sch)
  1591. }
  1592. errLogs, _ := service.FindSchedualTemplateExportLog(this.GetAdminUserInfo().CurrentOrgId, export_time)
  1593. if len(schedules) > 0 {
  1594. err := service.UpdateScheduleTemplateStatus(this.GetAdminUserInfo().CurrentOrgId)
  1595. if err == nil {
  1596. for _, item := range schedules {
  1597. service.CreateScheduleTemplate(item)
  1598. }
  1599. log := models.ExportLog{
  1600. LogType: 3,
  1601. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  1602. TotalNum: int64(len(total_schedule)),
  1603. FailNum: int64(len(errLogs)),
  1604. SuccessNum: int64(len(schedules)),
  1605. CreateTime: time.Now().Unix(),
  1606. UpdateTime: time.Now().Unix(),
  1607. ExportTime: export_time,
  1608. Status: 1,
  1609. }
  1610. service.CreateExportLog(&log)
  1611. this.ServeSuccessJSON(map[string]interface{}{
  1612. "msg": "导入成功",
  1613. "total_num": len(total_schedule),
  1614. "success_num": len(schedules),
  1615. "fail_num": int64(len(errLogs)),
  1616. })
  1617. } else {
  1618. log := models.ExportLog{
  1619. LogType: 3,
  1620. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  1621. TotalNum: int64(len(total_schedule)),
  1622. FailNum: int64(len(errLogs)),
  1623. SuccessNum: int64(len(schedules)),
  1624. CreateTime: time.Now().Unix(),
  1625. UpdateTime: time.Now().Unix(),
  1626. ExportTime: export_time,
  1627. Status: 1,
  1628. }
  1629. service.CreateExportLog(&log)
  1630. this.ServeSuccessJSON(map[string]interface{}{
  1631. "msg": "导入成功",
  1632. "total_num": len(total_schedule),
  1633. "success_num": len(schedules),
  1634. "fail_num": int64(len(errLogs)),
  1635. })
  1636. }
  1637. } else {
  1638. log := models.ExportLog{
  1639. LogType: 3,
  1640. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  1641. TotalNum: int64(len(total_schedule)),
  1642. FailNum: int64(len(errLogs)),
  1643. SuccessNum: int64(len(schedules)),
  1644. CreateTime: time.Now().Unix(),
  1645. UpdateTime: time.Now().Unix(),
  1646. ExportTime: export_time,
  1647. Status: 1,
  1648. }
  1649. service.CreateExportLog(&log)
  1650. this.ServeSuccessJSON(map[string]interface{}{
  1651. "msg": "导入成功",
  1652. "total_num": len(total_schedule),
  1653. "success_num": len(schedules),
  1654. "fail_num": int64(len(errLogs)),
  1655. })
  1656. }
  1657. }
  1658. }
  1659. func (c *ScheduleApiController) GetInitExcelInitDate() {
  1660. thisTime := time.Now()
  1661. thisTime1 := time.Now()
  1662. thisTime2 := time.Now()
  1663. thisTime1 = thisTime1.AddDate(0, 0, 7)
  1664. thisTime2 = thisTime2.AddDate(0, 0, 14)
  1665. weekDay := int(thisTime.Weekday())
  1666. if weekDay == 0 {
  1667. weekDay = 7
  1668. }
  1669. weekEnd := 7 - weekDay
  1670. weekStart := weekEnd - 6
  1671. days := make([]string, 0)
  1672. for index := weekStart; index <= weekEnd; index++ {
  1673. theDay := thisTime.AddDate(0, 0, index)
  1674. days = append(days, theDay.Format("2006-01-02"))
  1675. }
  1676. weekDay1 := int(thisTime1.Weekday())
  1677. if weekDay1 == 0 {
  1678. weekDay1 = 7
  1679. }
  1680. weekEnd1 := 7 - weekDay1
  1681. weekStart1 := weekEnd1 - 6
  1682. for index := weekStart1; index <= weekEnd1; index++ {
  1683. theDay := thisTime1.AddDate(0, 0, index)
  1684. days = append(days, theDay.Format("2006-01-02"))
  1685. }
  1686. weekDay2 := int(thisTime2.Weekday())
  1687. if weekDay2 == 0 {
  1688. weekDay2 = 7
  1689. }
  1690. weekEnd2 := 7 - weekDay2
  1691. weekStart2 := weekEnd2 - 6
  1692. for index := weekStart2; index <= weekEnd2; index++ {
  1693. theDay := thisTime2.AddDate(0, 0, index)
  1694. days = append(days, theDay.Format("2006-01-02"))
  1695. }
  1696. c.ServeSuccessJSON(map[string]interface{}{
  1697. "days": days,
  1698. })
  1699. return
  1700. }
  1701. func GetWeekString(week string) string {
  1702. var weekStr string
  1703. switch week {
  1704. case "Sunday":
  1705. weekStr = "周日"
  1706. break
  1707. case "Monday":
  1708. weekStr = "周一"
  1709. break
  1710. case "Tuesday":
  1711. weekStr = "周二"
  1712. break
  1713. case "Wednesday":
  1714. weekStr = "周三"
  1715. break
  1716. case "Thursday":
  1717. weekStr = "周四"
  1718. break
  1719. case "Friday":
  1720. weekStr = "周五"
  1721. break
  1722. case "Saturday":
  1723. weekStr = "周六"
  1724. break
  1725. default:
  1726. weekStr = ""
  1727. break
  1728. }
  1729. return weekStr
  1730. }
  1731. func (c *ScheduleApiController) SearchTemplateSchedulePatients() {
  1732. template_id, _ := c.GetInt64("template_id", 0)
  1733. keywords := c.GetString("keywords")
  1734. adminInfo := c.GetAdminUserInfo()
  1735. scheduleItems, _ := service.GetTemplateSchedualPatientsByKeywords(keywords, adminInfo.CurrentOrgId, template_id)
  1736. c.ServeSuccessJSON(map[string]interface{}{
  1737. "schdules": scheduleItems,
  1738. })
  1739. }
  1740. func (c *ScheduleApiController) CancelScheduleTemplate() {
  1741. item_id, _ := c.GetInt64("id")
  1742. adminInfo := c.GetAdminUserInfo()
  1743. err := service.UpdateNewScheduleTemplateStatus(item_id, adminInfo.CurrentOrgId)
  1744. if err == nil {
  1745. c.ServeSuccessJSON(map[string]interface{}{
  1746. "msg": "取消成功",
  1747. })
  1748. return
  1749. } else {
  1750. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeExportError)
  1751. return
  1752. }
  1753. }
  1754. func (this *ScheduleApiController) GetNextWeekDaySchedule() {
  1755. week_type, _ := this.GetInt64("week_type", -1)
  1756. week_time, _ := this.GetInt64("week_time")
  1757. start_time, _ := this.GetInt64("start_time")
  1758. end_time, _ := this.GetInt64("end_time")
  1759. //zone, _ := this.GetInt64("zone")
  1760. zons := this.GetString("zone")
  1761. zone := strings.Split(zons, ",")
  1762. adminUserInfo := this.GetAdminUserInfo()
  1763. schedule, err := service.GetNextWeekDaySchedule(week_type, week_time, start_time, end_time, adminUserInfo.CurrentOrgId, zone)
  1764. if err != nil {
  1765. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1766. return
  1767. }
  1768. this.ServeSuccessJSON(map[string]interface{}{
  1769. "schedule": schedule,
  1770. })
  1771. }
  1772. func (this *ScheduleApiController) GetThreeWeekList() {
  1773. start_time := this.GetString("start_time")
  1774. end_time := this.GetString("end_time")
  1775. partition_id, _ := this.GetInt64("partition_id")
  1776. schedule_type, _ := this.GetInt64("schedule_type")
  1777. fmt.Println(partition_id, schedule_type)
  1778. timeLayout := "2006-01-02"
  1779. loc, _ := time.LoadLocation("Local")
  1780. var theStartTIme int64
  1781. if len(start_time) > 0 {
  1782. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  1783. if err != nil {
  1784. utils.ErrorLog(err.Error())
  1785. }
  1786. theStartTIme = theTime.Unix()
  1787. }
  1788. var theEndtTIme int64
  1789. if len(end_time) > 0 {
  1790. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 00:00:00", loc)
  1791. if err != nil {
  1792. utils.ErrorLog(err.Error())
  1793. }
  1794. theEndtTIme = theTime.Unix()
  1795. }
  1796. adminUserInfo := this.GetAdminUserInfo()
  1797. orgId := adminUserInfo.CurrentOrgId
  1798. partitions, _ := service.GetSchedulePartitionPanel(orgId)
  1799. list, err := service.GetThreeWeekList(theStartTIme, theEndtTIme, orgId, schedule_type, partition_id)
  1800. if err != nil {
  1801. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1802. return
  1803. }
  1804. this.ServeSuccessJSON(map[string]interface{}{
  1805. "list": list,
  1806. "partitions": partitions,
  1807. })
  1808. }
  1809. func (this *ScheduleApiController) GetAllZones() {
  1810. adminUserInfo := this.GetAdminUserInfo()
  1811. orgId := adminUserInfo.CurrentOrgId
  1812. zones, err := service.GetAllZoneOne(orgId)
  1813. if err != nil {
  1814. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1815. return
  1816. }
  1817. this.ServeSuccessJSON(map[string]interface{}{
  1818. "zones": zones,
  1819. })
  1820. }
  1821. func (this *ScheduleApiController) GetCopyPatientSchedules() {
  1822. adminUserInfo := this.GetAdminUserInfo()
  1823. orgId := adminUserInfo.CurrentOrgId
  1824. start_time, _ := this.GetInt64("start_time")
  1825. fmt.Println("start_time", start_time)
  1826. end_time, _ := this.GetInt64("end_time")
  1827. fmt.Println("end_time", end_time)
  1828. copy_startime, _ := this.GetInt64("copy_startime")
  1829. fmt.Println("copy_startime", copy_startime)
  1830. copy_endtime, _ := this.GetInt64("copy_endtime")
  1831. //获取本周患者排班
  1832. schedules, _ := service.GetWeekSchedules(orgId, start_time, end_time)
  1833. //先清除复制周的排班
  1834. errcode := service.UpdatePatientSchedule(orgId, copy_startime, copy_endtime)
  1835. fmt.Println(errcode)
  1836. for _, item := range schedules {
  1837. //fmt.Println(item.StartTime+604800)
  1838. //礼拜1
  1839. if item.ScheduleWeek == 1 {
  1840. item.ScheduleDate = copy_startime
  1841. }
  1842. if item.ScheduleWeek == 2 {
  1843. item.ScheduleDate = copy_startime + 86400
  1844. }
  1845. if item.ScheduleWeek == 3 {
  1846. item.ScheduleDate = copy_startime + 172800
  1847. }
  1848. if item.ScheduleWeek == 4 {
  1849. item.ScheduleDate = copy_startime + 259200
  1850. }
  1851. if item.ScheduleWeek == 5 {
  1852. item.ScheduleDate = copy_startime + 345600
  1853. }
  1854. if item.ScheduleWeek == 6 {
  1855. item.ScheduleDate = copy_startime + 432000
  1856. }
  1857. //礼拜天
  1858. if item.ScheduleWeek == 7 {
  1859. item.ScheduleDate = copy_endtime
  1860. }
  1861. schedule := models.XtSchedule{
  1862. UserOrgId: item.UserOrgId,
  1863. PartitionId: item.PartitionId,
  1864. BedId: item.BedId,
  1865. PatientId: item.PatientId,
  1866. ScheduleDate: item.ScheduleDate,
  1867. ScheduleType: item.ScheduleType,
  1868. ScheduleWeek: item.ScheduleWeek,
  1869. ModeId: item.ModeId,
  1870. Status: 1,
  1871. CreatedTime: time.Now().Unix(),
  1872. }
  1873. err := service.AddPatientSchedule(&schedule)
  1874. if err != nil {
  1875. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1876. return
  1877. }
  1878. this.ServeSuccessJSON(map[string]interface{}{
  1879. "schedule": schedule,
  1880. })
  1881. }
  1882. //查询复制中的排班日期是否存在
  1883. //_, errcode := service.GetLastWeekSchedule(orgId, copy_startime, copy_endtime)
  1884. //
  1885. //if errcode == gorm.ErrRecordNotFound {
  1886. // //如果没有直接新增
  1887. //
  1888. // for _, item := range schedules {
  1889. // //fmt.Println(item.StartTime+604800)
  1890. // //礼拜1
  1891. // if item.ScheduleWeek == 1 {
  1892. // item.ScheduleDate = copy_startime
  1893. // }
  1894. // if item.ScheduleWeek == 2 {
  1895. // item.ScheduleDate = copy_startime + 86400
  1896. // }
  1897. // if item.ScheduleWeek == 3 {
  1898. // item.ScheduleDate = copy_startime + 172800
  1899. // }
  1900. // if item.ScheduleWeek == 4 {
  1901. // item.ScheduleDate = copy_startime + 259200
  1902. // }
  1903. // if item.ScheduleWeek == 5 {
  1904. // item.ScheduleDate = copy_startime + 345600
  1905. // }
  1906. //
  1907. // if item.ScheduleWeek == 6 {
  1908. // item.ScheduleDate = copy_startime + 432000
  1909. // }
  1910. // //礼拜天
  1911. // if item.ScheduleWeek == 0 {
  1912. // item.ScheduleDate = copy_endtime
  1913. // }
  1914. // schedule := models.XtSchedule{
  1915. // UserOrgId: item.UserOrgId,
  1916. // PartitionId: item.PartitionId,
  1917. // BedId: item.BedId,
  1918. // PatientId: item.PatientId,
  1919. // ScheduleDate: item.ScheduleDate,
  1920. // ScheduleType: item.ScheduleType,
  1921. // ScheduleWeek: item.ScheduleWeek,
  1922. // ModeId: item.ModeId,
  1923. // Status: 1,
  1924. // CreatedTime: time.Now().Unix(),
  1925. // }
  1926. //
  1927. // err := service.AddPatientSchedule(&schedule)
  1928. // if err != nil {
  1929. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1930. // return
  1931. // }
  1932. // this.ServeSuccessJSON(map[string]interface{}{
  1933. // "schedule": schedule,
  1934. // })
  1935. // }
  1936. //} else if errcode == nil {
  1937. //
  1938. // //先清除复制周的排班
  1939. // errcode := service.UpdatePatientSchedule(orgId, copy_startime, copy_endtime)
  1940. // fmt.Println(errcode)
  1941. // for _, item := range schedules {
  1942. // //fmt.Println(item.StartTime+604800)
  1943. // //礼拜1
  1944. // if item.ScheduleWeek == 1 {
  1945. // item.ScheduleDate = copy_startime
  1946. // }
  1947. // if item.ScheduleWeek == 2 {
  1948. // item.ScheduleDate = copy_startime + 86400
  1949. // }
  1950. // if item.ScheduleWeek == 3 {
  1951. // item.ScheduleDate = copy_startime + 172800
  1952. // }
  1953. // if item.ScheduleWeek == 4 {
  1954. // item.ScheduleDate = copy_startime + 259200
  1955. // }
  1956. // if item.ScheduleWeek == 5 {
  1957. // item.ScheduleDate = copy_startime + 345600
  1958. // }
  1959. //
  1960. // if item.ScheduleWeek == 6 {
  1961. // item.ScheduleDate = copy_startime + 432000
  1962. // }
  1963. // //礼拜天
  1964. // if item.ScheduleWeek == 0 {
  1965. // item.ScheduleDate = copy_endtime
  1966. // }
  1967. // schedule := models.XtSchedule{
  1968. // UserOrgId: item.UserOrgId,
  1969. // PartitionId: item.PartitionId,
  1970. // BedId: item.BedId,
  1971. // PatientId: item.PatientId,
  1972. // ScheduleDate: item.ScheduleDate,
  1973. // ScheduleType: item.ScheduleType,
  1974. // ScheduleWeek: item.ScheduleWeek,
  1975. // ModeId: item.ModeId,
  1976. // Status: 1,
  1977. // CreatedTime: time.Now().Unix(),
  1978. // }
  1979. //
  1980. // err := service.AddPatientSchedule(&schedule)
  1981. // if err != nil {
  1982. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1983. // return
  1984. // }
  1985. // this.ServeSuccessJSON(map[string]interface{}{
  1986. // "schedule": schedule,
  1987. // })
  1988. // }
  1989. //}
  1990. }
  1991. func (this *ScheduleApiController) SaveRemindPrint() {
  1992. id, _ := this.GetInt64("id")
  1993. anticoagulants, _ := this.GetInt64("anticoagulant")
  1994. anticoagulant_zongliang, _ := this.GetInt64("anticoagulant_zongliang")
  1995. classes, _ := this.GetInt64("classes")
  1996. dialyzers, _ := this.GetInt64("dialyzers")
  1997. doctor_advice, _ := this.GetInt64("doctor_advice")
  1998. mode, _ := this.GetInt64("mode")
  1999. name, _ := this.GetInt64("name")
  2000. number, _ := this.GetInt64("number")
  2001. perfusion_apparatus, _ := this.GetInt64("perfusion_apparatus")
  2002. prescription_status, _ := this.GetInt64("prescription_status")
  2003. week, _ := this.GetInt64("week")
  2004. zone, _ := this.GetInt64("zone")
  2005. adminUserInfo := this.GetAdminUserInfo()
  2006. orgId := adminUserInfo.CurrentOrgId
  2007. setting := models.XtRemindPrintSetting{
  2008. Anticoagulant: anticoagulants,
  2009. Classes: classes,
  2010. AnticoagulantZongliang: anticoagulant_zongliang,
  2011. Dialyzers: dialyzers,
  2012. DoctorAdvice: doctor_advice,
  2013. Mode: mode,
  2014. Name: name,
  2015. Number: number,
  2016. PerfusionApparatus: perfusion_apparatus,
  2017. PrescriptionStatus: prescription_status,
  2018. Week: week,
  2019. Zone: zone,
  2020. UserOrgId: orgId,
  2021. Status: 1,
  2022. Ctime: time.Now().Unix(),
  2023. }
  2024. _, errcode := service.GetSettingById(id)
  2025. if errcode == gorm.ErrRecordNotFound {
  2026. err := service.CreateSetting(&setting)
  2027. if err != nil {
  2028. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2029. return
  2030. }
  2031. this.ServeSuccessJSON(map[string]interface{}{
  2032. "setting": setting,
  2033. })
  2034. } else if errcode == nil {
  2035. err := service.UpdatedRemindPrint(&setting, id)
  2036. if err != nil {
  2037. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2038. return
  2039. }
  2040. this.ServeSuccessJSON(map[string]interface{}{
  2041. "setting": setting,
  2042. })
  2043. }
  2044. }
  2045. func (this *ScheduleApiController) GetRemindPrintList() {
  2046. adminUserInfo := this.GetAdminUserInfo()
  2047. orgId := adminUserInfo.CurrentOrgId
  2048. list, err := service.GetRemindPrintList(orgId)
  2049. if err != nil {
  2050. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2051. return
  2052. }
  2053. this.ServeSuccessJSON(map[string]interface{}{
  2054. "list": list,
  2055. })
  2056. }
  2057. func (this *ScheduleApiController) GetBloodScheduleList() {
  2058. week_type, _ := this.GetInt64("week_type", -1)
  2059. week_time, _ := this.GetInt64("week_time")
  2060. //zone, _ := this.GetInt64("zone")
  2061. zones := this.GetString("zone")
  2062. zone := strings.Split(zones, ",")
  2063. thisTime := time.Now()
  2064. weekDay := int(thisTime.Weekday())
  2065. if weekDay == 0 {
  2066. weekDay = 7
  2067. }
  2068. weekEnd := 7 - weekDay
  2069. weekStart := weekEnd - 6
  2070. weekTitle := make([]string, 0)
  2071. days := make([]string, 0)
  2072. for index := weekStart; index <= weekEnd; index++ {
  2073. theDay := thisTime.AddDate(0, 0, index)
  2074. indexYear, indexMonthTime, indexDay := theDay.Date()
  2075. indexMonth := int(indexMonthTime)
  2076. indexWeek := strconv.Itoa(indexYear) + "." + strconv.Itoa(indexMonth) + "." + strconv.Itoa(indexDay)
  2077. weekTitle = append(weekTitle, indexWeek)
  2078. days = append(days, theDay.Format("2006-01-02"))
  2079. }
  2080. fmt.Println(days)
  2081. var targetDayStr string
  2082. var startTime string
  2083. switch week_type {
  2084. case 0:
  2085. startTime = days[0]
  2086. targetDayStr = days[6]
  2087. break
  2088. case 1:
  2089. targetDayStr = days[0]
  2090. break
  2091. case 2:
  2092. targetDayStr = days[1]
  2093. break
  2094. case 3:
  2095. targetDayStr = days[2]
  2096. break
  2097. case 4:
  2098. targetDayStr = days[3]
  2099. break
  2100. case 5:
  2101. targetDayStr = days[4]
  2102. break
  2103. case 6:
  2104. targetDayStr = days[5]
  2105. break
  2106. case 7:
  2107. targetDayStr = days[6]
  2108. break
  2109. }
  2110. targetDay, parseErr := utils.ParseTimeStringToTime("2006-01-02", targetDayStr)
  2111. if parseErr != nil {
  2112. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2113. return
  2114. }
  2115. orgId := this.GetAdminUserInfo().CurrentOrgId
  2116. if week_type > 0 {
  2117. list, err := service.GetWeekDayScheduleByIdThee(orgId, targetDay.Unix(), week_time, zone)
  2118. if err != nil {
  2119. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2120. return
  2121. }
  2122. this.ServeSuccessJSON(map[string]interface{}{
  2123. "list": list,
  2124. "day": targetDayStr,
  2125. })
  2126. }
  2127. if week_type == 0 {
  2128. startDate, _ := utils.ParseTimeStringToTime("2006-01-02", startTime)
  2129. list, err := service.GetWeekDayScheduleByIdTwo(orgId, targetDay.Unix(), week_time, startDate.Unix(), zone)
  2130. if err != nil {
  2131. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2132. return
  2133. }
  2134. this.ServeSuccessJSON(map[string]interface{}{
  2135. "list": list,
  2136. "day": targetDayStr,
  2137. })
  2138. }
  2139. }
  2140. func (this *ScheduleApiController) GetPrintList() {
  2141. adminUserInfo := this.GetAdminUserInfo()
  2142. orgId := adminUserInfo.CurrentOrgId
  2143. list, err := service.GetRemindPrintList(orgId)
  2144. if err != nil {
  2145. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2146. return
  2147. }
  2148. this.ServeSuccessJSON(map[string]interface{}{
  2149. "list": list,
  2150. })
  2151. }
  2152. func (this *ScheduleApiController) GetAllZoneList() {
  2153. adminUserInfo := this.GetAdminUserInfo()
  2154. orgId := adminUserInfo.CurrentOrgId
  2155. zoneList, err := service.GetAllZoneOne(orgId)
  2156. if err != nil {
  2157. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2158. return
  2159. }
  2160. this.ServeSuccessJSON(map[string]interface{}{
  2161. "zoneList": zoneList,
  2162. })
  2163. }
  2164. func (this *ScheduleApiController) GetPatientScheduleCount() {
  2165. patitionIdStr := this.GetString("partition_id")
  2166. week, _ := this.GetInt64("weekTime", 0) //1:last, 2:this 3:next 4 nextTwo
  2167. ids := strings.Split(patitionIdStr, ",")
  2168. adminUserInfo := this.GetAdminUserInfo()
  2169. orgId := adminUserInfo.CurrentOrgId
  2170. thisTime := time.Now()
  2171. weekDay := int(thisTime.Weekday())
  2172. if week < 1 || week > 4 {
  2173. week = 2
  2174. }
  2175. if week == 1 {
  2176. thisTime = thisTime.AddDate(0, 0, -7)
  2177. } else if week == 3 {
  2178. thisTime = thisTime.AddDate(0, 0, 7)
  2179. } else if week == 4 {
  2180. thisTime = thisTime.AddDate(0, 0, 14)
  2181. }
  2182. if weekDay == 0 {
  2183. weekDay = 7
  2184. }
  2185. weekEnd := 7 - weekDay
  2186. weekStart := weekEnd - 6
  2187. weekTitle := make([]string, 0)
  2188. days := make([]string, 0)
  2189. for index := weekStart; index <= weekEnd; index++ {
  2190. theDay := thisTime.AddDate(0, 0, index)
  2191. indexYear, indexMonthTime, indexDay := theDay.Date()
  2192. indexMonth := int(indexMonthTime)
  2193. indexWeek := strconv.Itoa(indexYear) + "." + strconv.Itoa(indexMonth) + "." + strconv.Itoa(indexDay)
  2194. weekTitle = append(weekTitle, indexWeek)
  2195. days = append(days, theDay.Format("2006-01-02"))
  2196. }
  2197. weekStartDay := thisTime.AddDate(0, 0, weekStart)
  2198. weekEndDay := thisTime.AddDate(0, 0, weekEnd)
  2199. weekStartTime := weekStartDay.Format("2006-01-02") + " 00:00:00"
  2200. weekEndTime := weekEndDay.Format("2006-01-02") + " 23:59:59"
  2201. timeLayout := "2006-01-02 15:04:05"
  2202. loc, _ := time.LoadLocation("Local")
  2203. theStarTime, _ := time.ParseInLocation(timeLayout, weekStartTime, loc)
  2204. theEndTime, _ := time.ParseInLocation(timeLayout, weekEndTime, loc)
  2205. weekStartPoint := theStarTime.Unix()
  2206. weekEndPoint := theEndTime.Unix()
  2207. fmt.Println("startTime222222222222222", weekStartPoint)
  2208. fmt.Println("endtime33333333333333", weekEndPoint)
  2209. list, err := service.GetPatientScheduleCount(orgId, weekStartPoint, weekEndPoint, ids)
  2210. _, total, _ := service.GetTotalBedNumber(orgId, ids)
  2211. if err != nil {
  2212. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2213. return
  2214. }
  2215. this.ServeSuccessJSON(map[string]interface{}{
  2216. "list": list,
  2217. "total": total,
  2218. })
  2219. }
  2220. func (c *ScheduleApiController) GetWeekPanelsOne() {
  2221. data, _ := c.GetInt64("data", 1)
  2222. patitionIdStr := c.GetString("patitionid")
  2223. ids := strings.Split(patitionIdStr, ",")
  2224. adminInfo := c.GetAdminUserInfo()
  2225. thisTime := time.Now()
  2226. year, monthTime, day := thisTime.Date()
  2227. month := int(monthTime)
  2228. _, theWeek := thisTime.ISOWeek()
  2229. weekDay := int(thisTime.Weekday())
  2230. if weekDay == 0 {
  2231. weekDay = 7
  2232. }
  2233. weekEnd := 7 - weekDay
  2234. weekStart := weekEnd - 6
  2235. weekDays := make([]string, 0)
  2236. for index := weekStart; index <= weekEnd; index++ {
  2237. theDay := thisTime.AddDate(0, 0, index)
  2238. indexYear, indexMonthTime, indexDay := theDay.Date()
  2239. indexMonth := int(indexMonthTime)
  2240. indexWeek := strconv.Itoa(indexYear) + "." + strconv.Itoa(indexMonth) + "." + strconv.Itoa(indexDay)
  2241. weekDays = append(weekDays, indexWeek)
  2242. }
  2243. returnData := map[string]interface{}{
  2244. "year": year,
  2245. "month": month,
  2246. "day": day,
  2247. "theWeek": theWeek,
  2248. "weekDay": weekDay,
  2249. "weekDays": weekDays,
  2250. }
  2251. if data == 1 {
  2252. partitions, _ := service.GetSchedulePartitionPanelTwo(adminInfo.CurrentOrgId, ids)
  2253. returnData["partitions"] = partitions
  2254. }
  2255. c.ServeSuccessJSON(returnData)
  2256. return
  2257. }
  2258. func (c *ScheduleApiController) GetScheduleOne() {
  2259. week, _ := c.GetInt64("weekTime", 0) //1:last, 2:this 3:next 4 nextTwo
  2260. patitionIdStr := c.GetString("patitionid")
  2261. ids := strings.Split(patitionIdStr, ",")
  2262. fmt.Println("patitonStr", ids)
  2263. schedule_type, _ := c.GetInt64("schedule_type")
  2264. adminInfo := c.GetAdminUserInfo()
  2265. thisTime := time.Now()
  2266. today := thisTime.Format("2006-01-02")
  2267. if week < 1 || week > 4 {
  2268. week = 2
  2269. }
  2270. if week == 1 {
  2271. thisTime = thisTime.AddDate(0, 0, -7)
  2272. } else if week == 3 {
  2273. thisTime = thisTime.AddDate(0, 0, 7)
  2274. } else if week == 4 {
  2275. thisTime = thisTime.AddDate(0, 0, 14)
  2276. }
  2277. weekDay := int(thisTime.Weekday())
  2278. if weekDay == 0 {
  2279. weekDay = 7
  2280. }
  2281. weekEnd := 7 - weekDay
  2282. weekStart := weekEnd - 6
  2283. weekTitle := make([]string, 0)
  2284. days := make([]string, 0)
  2285. for index := weekStart; index <= weekEnd; index++ {
  2286. theDay := thisTime.AddDate(0, 0, index)
  2287. indexYear, indexMonthTime, indexDay := theDay.Date()
  2288. indexMonth := int(indexMonthTime)
  2289. indexWeek := strconv.Itoa(indexYear) + "." + strconv.Itoa(indexMonth) + "." + strconv.Itoa(indexDay)
  2290. weekTitle = append(weekTitle, indexWeek)
  2291. days = append(days, theDay.Format("2006-01-02"))
  2292. }
  2293. weekStartDay := thisTime.AddDate(0, 0, weekStart)
  2294. weekEndDay := thisTime.AddDate(0, 0, weekEnd)
  2295. weekStartTime := weekStartDay.Format("2006-01-02") + " 00:00:00"
  2296. weekEndTime := weekEndDay.Format("2006-01-02") + " 23:59:59"
  2297. timeLayout := "2006-01-02 15:04:05"
  2298. loc, _ := time.LoadLocation("Local")
  2299. theStarTime, _ := time.ParseInLocation(timeLayout, weekStartTime, loc)
  2300. theEndTime, _ := time.ParseInLocation(timeLayout, weekEndTime, loc)
  2301. weekStartPoint := theStarTime.Unix()
  2302. weekEndPoint := theEndTime.Unix()
  2303. schdules, _ := service.GetWeekScheduleTwo(adminInfo.CurrentOrgId, weekStartPoint, weekEndPoint, ids, schedule_type)
  2304. c.ServeSuccessJSON(map[string]interface{}{
  2305. "days": days,
  2306. "weekTitle": weekTitle,
  2307. "schdules": schdules,
  2308. "today": today,
  2309. })
  2310. return
  2311. }
  2312. func (c *ScheduleApiController) SaveScheduleTemplate() {
  2313. template_id, _ := c.GetInt64("template_id")
  2314. orgId := c.GetAdminUserInfo().CurrentOrgId
  2315. template := models.ScheduleTemplate{
  2316. TemplateId: template_id,
  2317. UserOrgId: orgId,
  2318. Status: 1,
  2319. Ctime: time.Now().Unix(),
  2320. }
  2321. _, errcodes := service.GetScheudleTemplateById(orgId)
  2322. if errcodes == gorm.ErrRecordNotFound {
  2323. service.CreateXtscheduleTemplate(&template)
  2324. } else if errcodes == nil {
  2325. service.UpdateXtScheduleTemplate(&template, orgId)
  2326. }
  2327. c.ServeSuccessJSON(map[string]interface{}{
  2328. "template": template,
  2329. })
  2330. return
  2331. }
  2332. func (c *ScheduleApiController) GetScheduleTemplate() {
  2333. adminUserInfo := c.GetAdminUserInfo()
  2334. orgId := adminUserInfo.CurrentOrgId
  2335. template, _ := service.GetScheduleTemplate(orgId)
  2336. c.ServeSuccessJSON(map[string]interface{}{
  2337. "template": template,
  2338. })
  2339. return
  2340. }
  2341. func (c *ScheduleApiController) ChangeFuncPrint() {
  2342. adminUserInfo := c.GetAdminUserInfo()
  2343. orgId := adminUserInfo.CurrentOrgId
  2344. is_open, _ := c.GetInt64("is_open")
  2345. dataPrint := models.XtDataPrint{
  2346. UserOrgId: orgId,
  2347. IsOpen: is_open,
  2348. Status: 1,
  2349. Ctime: time.Now().Unix(),
  2350. }
  2351. _, errcode := service.GetDataPrintByOrgId(orgId)
  2352. fmt.Println("errcode222234444555556t66", errcode)
  2353. if errcode == gorm.ErrRecordNotFound {
  2354. service.CreateDataPrint(&dataPrint)
  2355. c.ServeSuccessJSON(map[string]interface{}{
  2356. "dataPrint": dataPrint,
  2357. })
  2358. return
  2359. } else if errcode == nil {
  2360. service.UpdteDataPrint(orgId, &dataPrint)
  2361. c.ServeSuccessJSON(map[string]interface{}{
  2362. "dataPrint": dataPrint,
  2363. })
  2364. return
  2365. }
  2366. }
  2367. func (c *ScheduleApiController) GetDataPrint() {
  2368. adminUserInfo := c.GetAdminUserInfo()
  2369. orgId := adminUserInfo.CurrentOrgId
  2370. dataPrint, _ := service.GetDataPrint(orgId)
  2371. c.ServeSuccessJSON(map[string]interface{}{
  2372. "dataPrint": dataPrint,
  2373. })
  2374. return
  2375. }
  2376. func (c *ScheduleApiController) GetNextWeekPanels() {
  2377. start_time, _ := c.GetInt64("start_time")
  2378. fmt.Println("start_time", start_time)
  2379. end_time, _ := c.GetInt64("end_time")
  2380. fmt.Println("end_time", end_time)
  2381. orgId := c.GetAdminUserInfo().CurrentOrgId
  2382. schedule, _ := service.GetNextWeekPanels(start_time, end_time, orgId)
  2383. c.ServeSuccessJSON(map[string]interface{}{
  2384. "schedule": schedule,
  2385. })
  2386. }