schedule_api_controller.go 53KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730
  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. "time"
  13. "github.com/astaxie/beego"
  14. )
  15. type ScheduleApiController struct {
  16. BaseAuthAPIController
  17. }
  18. func ScheduleApiRegistRouters() {
  19. beego.Router("/api/schedule/weekpanel", &ScheduleApiController{}, "Get:GetWeekPanels")
  20. beego.Router("/api/schedule/schedules", &ScheduleApiController{}, "Get:GetSchedules")
  21. beego.Router("/api/excel_date/init", &ScheduleApiController{}, "Get:GetInitExcelInitDate")
  22. beego.Router("/api/schedule/patients", &ScheduleApiController{}, "Get:GetPatients")
  23. beego.Router("/api/schedule/create", &ScheduleApiController{}, "Post:CreateSchedule")
  24. beego.Router("/api/schedule/delete", &ScheduleApiController{}, "Delete:DeleteSchedule")
  25. beego.Router("/api/schedule/change", &ScheduleApiController{}, "Put:ChangeSchedule")
  26. beego.Router("/api/schedule/urgentinit", &ScheduleApiController{}, "Get:UrgentScheduleData")
  27. beego.Router("/api/schedule/print/initdata", &ScheduleApiController{}, "get:PrintInitData")
  28. beego.Router("/api/schedule/search", &ScheduleApiController{}, "get:SearchSchedulePatients")
  29. beego.Router("/api/schedule/week", &ScheduleApiController{}, "get:GetWeekDaySchedule")
  30. beego.Router("/api/schedule/export", &ScheduleApiController{}, "post:ExportSchedule")
  31. beego.Router("/api/schedule_template/export", &ScheduleApiController{}, "post:ExportScheduleTemplate")
  32. }
  33. func (c *ScheduleApiController) GetWeekPanels() {
  34. data, _ := c.GetInt64("data", 1)
  35. adminInfo := c.GetAdminUserInfo()
  36. thisTime := time.Now()
  37. year, monthTime, day := thisTime.Date()
  38. month := int(monthTime)
  39. _, theWeek := thisTime.ISOWeek()
  40. weekDay := int(thisTime.Weekday())
  41. if weekDay == 0 {
  42. weekDay = 7
  43. }
  44. weekEnd := 7 - weekDay
  45. weekStart := weekEnd - 6
  46. weekDays := make([]string, 0)
  47. for index := weekStart; index <= weekEnd; index++ {
  48. theDay := thisTime.AddDate(0, 0, index)
  49. indexYear, indexMonthTime, indexDay := theDay.Date()
  50. indexMonth := int(indexMonthTime)
  51. indexWeek := strconv.Itoa(indexYear) + "." + strconv.Itoa(indexMonth) + "." + strconv.Itoa(indexDay)
  52. weekDays = append(weekDays, indexWeek)
  53. }
  54. returnData := map[string]interface{}{
  55. "year": year,
  56. "month": month,
  57. "day": day,
  58. "theWeek": theWeek,
  59. "weekDay": weekDay,
  60. "weekDays": weekDays,
  61. }
  62. if data == 1 {
  63. partitions, _ := service.GetSchedulePartitionPanel(adminInfo.CurrentOrgId)
  64. returnData["partitions"] = partitions
  65. }
  66. c.ServeSuccessJSON(returnData)
  67. return
  68. }
  69. func (c *ScheduleApiController) GetSchedules() {
  70. week, _ := c.GetInt64("weekTime", 0) //1:last, 2:this 3:next 4 nextTwo
  71. adminInfo := c.GetAdminUserInfo()
  72. thisTime := time.Now()
  73. today := thisTime.Format("2006-01-02")
  74. if week < 1 || week > 4 {
  75. week = 2
  76. }
  77. if week == 1 {
  78. thisTime = thisTime.AddDate(0, 0, -7)
  79. } else if week == 3 {
  80. thisTime = thisTime.AddDate(0, 0, 7)
  81. } else if week == 4 {
  82. thisTime = thisTime.AddDate(0, 0, 14)
  83. }
  84. weekDay := int(thisTime.Weekday())
  85. if weekDay == 0 {
  86. weekDay = 7
  87. }
  88. weekEnd := 7 - weekDay
  89. weekStart := weekEnd - 6
  90. weekTitle := make([]string, 0)
  91. days := make([]string, 0)
  92. for index := weekStart; index <= weekEnd; index++ {
  93. theDay := thisTime.AddDate(0, 0, index)
  94. indexYear, indexMonthTime, indexDay := theDay.Date()
  95. indexMonth := int(indexMonthTime)
  96. indexWeek := strconv.Itoa(indexYear) + "." + strconv.Itoa(indexMonth) + "." + strconv.Itoa(indexDay)
  97. weekTitle = append(weekTitle, indexWeek)
  98. days = append(days, theDay.Format("2006-01-02"))
  99. }
  100. weekStartDay := thisTime.AddDate(0, 0, weekStart)
  101. weekEndDay := thisTime.AddDate(0, 0, weekEnd)
  102. weekStartTime := weekStartDay.Format("2006-01-02") + " 00:00:00"
  103. weekEndTime := weekEndDay.Format("2006-01-02") + " 23:59:59"
  104. timeLayout := "2006-01-02 15:04:05"
  105. loc, _ := time.LoadLocation("Local")
  106. theStarTime, _ := time.ParseInLocation(timeLayout, weekStartTime, loc)
  107. theEndTime, _ := time.ParseInLocation(timeLayout, weekEndTime, loc)
  108. weekStartPoint := theStarTime.Unix()
  109. weekEndPoint := theEndTime.Unix()
  110. schdules, _ := service.GetWeekSchedule(adminInfo.CurrentOrgId, weekStartPoint, weekEndPoint)
  111. c.ServeSuccessJSON(map[string]interface{}{
  112. "days": days,
  113. "weekTitle": weekTitle,
  114. "schdules": schdules,
  115. "today": today,
  116. })
  117. return
  118. }
  119. func (c *ScheduleApiController) GetPatients() {
  120. keywords := c.GetString("keywords", "")
  121. schedule, _ := c.GetInt64("schedule", 0) //1已2未
  122. contagion, _ := c.GetInt64("contagion", 0)
  123. adminInfo := c.GetAdminUserInfo()
  124. thisTime := time.Now()
  125. weekDay := int(thisTime.Weekday())
  126. if weekDay == 0 {
  127. weekDay = 7
  128. }
  129. thisWeekEnd := 7 - weekDay
  130. weekStartPoint := thisWeekEnd - 6
  131. weekStartDay := thisTime.AddDate(0, 0, weekStartPoint)
  132. weekEndPoint := thisWeekEnd + 7
  133. weekEndDay := thisTime.AddDate(0, 0, weekEndPoint)
  134. fmt.Println(weekStartPoint, weekStartDay, weekEndPoint, weekEndDay)
  135. weekStartTime := weekStartDay.Format("2006-01-02") + " 00:00:00"
  136. weekEndTime := weekEndDay.Format("2006-01-02") + " 23:59:59"
  137. fmt.Println(weekStartTime, weekEndTime)
  138. timeLayout := "2006-01-02 15:04:05"
  139. loc, _ := time.LoadLocation("Local")
  140. theStarTime, _ := time.ParseInLocation(timeLayout, weekStartTime, loc)
  141. theEndTime, _ := time.ParseInLocation(timeLayout, weekEndTime, loc)
  142. weekStart := theStarTime.Unix()
  143. weekEnd := theEndTime.Unix()
  144. patients, _ := service.GetPatientWithScheduleAndSolution(adminInfo.CurrentOrgId, keywords, weekStart, weekEnd, schedule, contagion)
  145. c.ServeSuccessJSON(map[string]interface{}{
  146. "patients": patients,
  147. })
  148. return
  149. }
  150. func (c *ScheduleApiController) CreateSchedule() {
  151. patientID, _ := c.GetInt64("patient_id", 0)
  152. if patientID <= 0 {
  153. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  154. return
  155. }
  156. adminUserInfo := c.GetAdminUserInfo()
  157. patientInfo, _ := service.FindPatientById(adminUserInfo.CurrentOrgId, patientID)
  158. if patientInfo.ID == 0 {
  159. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  160. return
  161. }
  162. var schedule models.Schedule
  163. dataBody := make(map[string]interface{}, 0)
  164. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  165. if err != nil {
  166. utils.ErrorLog(err.Error())
  167. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  168. return
  169. }
  170. if dataBody["schedule_date"] == nil || reflect.TypeOf(dataBody["schedule_date"]).String() != "string" {
  171. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  172. return
  173. }
  174. scheduleDate, _ := dataBody["schedule_date"].(string)
  175. if len(scheduleDate) == 0 {
  176. utils.ErrorLog("len(schedule_date) == 0")
  177. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  178. return
  179. }
  180. timeLayout := "2006-01-02"
  181. loc, _ := time.LoadLocation("Local")
  182. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", scheduleDate+" 00:00:00", loc)
  183. if err != nil {
  184. utils.ErrorLog(err.Error())
  185. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  186. return
  187. }
  188. schedule.ScheduleDate = theTime.Unix()
  189. timeNow := time.Now().Format("2006-01-02")
  190. if timeNow > scheduleDate {
  191. utils.ErrorLog(timeNow)
  192. utils.ErrorLog(scheduleDate)
  193. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCantSetScheduleBeforeNow)
  194. return
  195. }
  196. if dataBody["schedule_type"] == nil || reflect.TypeOf(dataBody["schedule_type"]).String() != "float64" {
  197. utils.ErrorLog("schedule_type")
  198. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  199. return
  200. }
  201. scheduleType := int64(dataBody["schedule_type"].(float64))
  202. if scheduleType < 1 || scheduleType > 3 {
  203. utils.ErrorLog("scheduleType < 3")
  204. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  205. return
  206. }
  207. schedule.ScheduleType = scheduleType
  208. if dataBody["bed_id"] == nil || reflect.TypeOf(dataBody["bed_id"]).String() != "float64" {
  209. utils.ErrorLog("bed_id")
  210. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  211. return
  212. }
  213. bedId := int64(dataBody["bed_id"].(float64))
  214. if bedId < 1 {
  215. utils.ErrorLog("bedId < 1")
  216. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  217. return
  218. }
  219. schedule.BedId = bedId
  220. if dataBody["partition_id"] == nil || reflect.TypeOf(dataBody["partition_id"]).String() != "float64" {
  221. utils.ErrorLog("partition_id")
  222. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  223. return
  224. }
  225. partitionId := int64(dataBody["partition_id"].(float64))
  226. if partitionId < 1 {
  227. utils.ErrorLog("partitionId < 1")
  228. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  229. return
  230. }
  231. schedule.PartitionId = partitionId
  232. if dataBody["schedule_week"] == nil || reflect.TypeOf(dataBody["schedule_week"]).String() != "float64" {
  233. utils.ErrorLog("schedule_week")
  234. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  235. return
  236. }
  237. scheduleWeek := int64(dataBody["schedule_week"].(float64))
  238. if scheduleWeek < 1 || scheduleWeek > 7 {
  239. utils.ErrorLog("scheduleWeek < 1")
  240. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  241. return
  242. }
  243. schedule.ScheduleWeek = scheduleWeek
  244. if dataBody["mode_id"] == nil || reflect.TypeOf(dataBody["mode_id"]).String() != "float64" {
  245. utils.ErrorLog("mode_id")
  246. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  247. return
  248. }
  249. modeId := int64(dataBody["mode_id"].(float64))
  250. if modeId < 1 && modeId > 14 {
  251. utils.ErrorLog("modeId < 1")
  252. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  253. return
  254. }
  255. schedule.ModeId = modeId
  256. schedule.PatientId = patientID
  257. schedule.CreatedTime = time.Now().Unix()
  258. schedule.UpdatedTime = time.Now().Unix()
  259. schedule.Status = 1
  260. schedule.UserOrgId = adminUserInfo.CurrentOrgId
  261. bed, _ := service.GetDeviceNumberByID(adminUserInfo.CurrentOrgId, schedule.BedId)
  262. if bed == nil {
  263. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeviceNumberNotExist)
  264. return
  265. }
  266. if bed.ZoneID != schedule.PartitionId {
  267. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeviceNumberNotTheZone)
  268. return
  269. }
  270. scheduleDateStart := scheduleDate + " 00:00:00"
  271. scheduleDateEnd := scheduleDate + " 23:59:59"
  272. timeLayout = "2006-01-02 15:04:05"
  273. theStartTime, _ := time.ParseInLocation(timeLayout, scheduleDateStart, loc)
  274. theEndTime, _ := time.ParseInLocation(timeLayout, scheduleDateEnd, loc)
  275. startTime := theStartTime.Unix()
  276. endTime := theEndTime.Unix()
  277. //一天只有排班一次
  278. daySchedule, err := service.GetDaySchedule(adminUserInfo.CurrentOrgId, startTime, endTime, patientID)
  279. if daySchedule.ID > 0 {
  280. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCantSetScheduleAgainOneDay)
  281. return
  282. }
  283. //同天同位置只能排一个
  284. pointSchedule, err := service.GetPointSchedule(adminUserInfo.CurrentOrgId, schedule.ScheduleDate, schedule.ScheduleWeek, schedule.ScheduleType, schedule.BedId)
  285. if err != nil {
  286. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  287. return
  288. }
  289. if pointSchedule.ID > 0 {
  290. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePointScheduleExist)
  291. return
  292. }
  293. err = service.CreateSchedule(&schedule)
  294. fmt.Println(err)
  295. if err != nil {
  296. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateScheduleFail)
  297. return
  298. }
  299. schedule.Patient = patientInfo.Name
  300. c.ServeSuccessJSON(map[string]interface{}{
  301. "msg": "ok",
  302. "schedule": schedule,
  303. })
  304. return
  305. }
  306. func (c *ScheduleApiController) DeleteSchedule() {
  307. id, _ := c.GetInt64("id", 0)
  308. if id <= 0 {
  309. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  310. return
  311. }
  312. adminINfo := c.GetAdminUserInfo()
  313. schedule, _ := service.GetSchedule(adminINfo.CurrentOrgId, id)
  314. if schedule == nil {
  315. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeScheduleNotExist)
  316. return
  317. }
  318. order, err := service.GetOneDialysisOrder(adminINfo.CurrentOrgId, schedule.ScheduleDate, schedule.PatientId)
  319. if err != nil {
  320. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  321. return
  322. }
  323. if order != nil {
  324. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDelScheduleFailByDialysis)
  325. return
  326. }
  327. schedule.Status = 0
  328. schedule.UpdatedTime = time.Now().Unix()
  329. err = service.UpdateSchedule(schedule)
  330. if err != nil {
  331. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeleteScheduleFail)
  332. return
  333. }
  334. c.ServeSuccessJSON(map[string]interface{}{
  335. "msg": "ok",
  336. "schedule": &schedule,
  337. })
  338. }
  339. func (c *ScheduleApiController) ChangeSchedule() {
  340. id, _ := c.GetInt64("id", 0)
  341. if id <= 0 {
  342. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  343. return
  344. }
  345. adminINfo := c.GetAdminUserInfo()
  346. schedule, _ := service.GetSchedule(adminINfo.CurrentOrgId, id)
  347. if schedule == nil {
  348. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeScheduleNotExist)
  349. return
  350. }
  351. dataBody := make(map[string]interface{}, 0)
  352. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  353. if err != nil {
  354. utils.ErrorLog(err.Error())
  355. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  356. return
  357. }
  358. if dataBody["change_action"] == nil || reflect.TypeOf(dataBody["change_action"]).String() != "string" {
  359. utils.ErrorLog("change_action")
  360. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  361. return
  362. }
  363. changeAction := dataBody["change_action"].(string)
  364. if changeAction == "change_mode" {
  365. if dataBody["mode_id"] == nil || reflect.TypeOf(dataBody["mode_id"]).String() != "float64" {
  366. utils.ErrorLog("mode_id")
  367. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  368. return
  369. }
  370. modeId := int64(dataBody["mode_id"].(float64))
  371. if modeId < 1 {
  372. utils.ErrorLog("modeId < 1")
  373. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  374. return
  375. }
  376. schedule.ModeId = modeId
  377. order, err := service.GetOneDialysisOrder(adminINfo.CurrentOrgId, schedule.ScheduleDate, schedule.PatientId)
  378. if err != nil {
  379. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  380. return
  381. }
  382. if order != nil {
  383. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeChangeMode)
  384. return
  385. }
  386. } else if changeAction == "change_device" {
  387. order, err := service.GetOneDialysisOrder(adminINfo.CurrentOrgId, schedule.ScheduleDate, schedule.PatientId)
  388. if err != nil {
  389. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  390. return
  391. }
  392. if order != nil {
  393. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeChangeDeviceNumber)
  394. return
  395. }
  396. if dataBody["schedule_type"] == nil || reflect.TypeOf(dataBody["schedule_type"]).String() != "float64" {
  397. utils.ErrorLog("schedule_type")
  398. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  399. return
  400. }
  401. scheduleType := int64(dataBody["schedule_type"].(float64))
  402. if scheduleType < 1 || scheduleType > 3 {
  403. utils.ErrorLog("scheduleType < 3")
  404. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  405. return
  406. }
  407. schedule.ScheduleType = scheduleType
  408. if dataBody["bed_id"] == nil || reflect.TypeOf(dataBody["bed_id"]).String() != "float64" {
  409. utils.ErrorLog("bed_id")
  410. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  411. return
  412. }
  413. bedId := int64(dataBody["bed_id"].(float64))
  414. if bedId < 1 {
  415. utils.ErrorLog("bedId < 1")
  416. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  417. return
  418. }
  419. schedule.BedId = bedId
  420. if dataBody["partition_id"] == nil || reflect.TypeOf(dataBody["partition_id"]).String() != "float64" {
  421. utils.ErrorLog("partition_id")
  422. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  423. return
  424. }
  425. partitionId := int64(dataBody["partition_id"].(float64))
  426. if partitionId < 1 {
  427. utils.ErrorLog("partitionId < 1")
  428. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  429. return
  430. }
  431. schedule.PartitionId = partitionId
  432. bed, _ := service.GetDeviceNumberByID(adminINfo.CurrentOrgId, schedule.BedId)
  433. if bed == nil {
  434. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeviceNumberNotExist)
  435. return
  436. }
  437. if bed.ZoneID != schedule.PartitionId {
  438. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeviceNumberNotTheZone)
  439. return
  440. }
  441. startTime := schedule.ScheduleDate
  442. endTime := startTime + 86399
  443. //一天只有排班一次
  444. daySchedule, err := service.GetDaySchedule(adminINfo.CurrentOrgId, startTime, endTime, schedule.PatientId)
  445. if daySchedule.ID > 0 && daySchedule.ID != schedule.ID {
  446. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCantSetScheduleAgainOneDay)
  447. return
  448. }
  449. //同天同位置只能排一个
  450. pointSchedule, err := service.GetPointSchedule(adminINfo.CurrentOrgId, schedule.ScheduleDate, schedule.ScheduleWeek, schedule.ScheduleType, schedule.BedId)
  451. if err != nil {
  452. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  453. return
  454. }
  455. if pointSchedule.ID > 0 {
  456. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePointScheduleExist)
  457. return
  458. }
  459. } else {
  460. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  461. return
  462. }
  463. schedule.UpdatedTime = time.Now().Unix()
  464. err = service.UpdateSchedule(schedule)
  465. if err != nil {
  466. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeChangeScheduleFail)
  467. return
  468. }
  469. c.ServeSuccessJSON(map[string]interface{}{
  470. "msg": "ok",
  471. "schedule": &schedule,
  472. })
  473. }
  474. // /api/schedule/print/initdata [get]
  475. // @param date:string yyyy-MM-dd 要打印的那一周中的任一天
  476. func (this *ScheduleApiController) PrintInitData() {
  477. dateStr := this.GetString("date")
  478. var date *time.Time
  479. if len(dateStr) == 0 {
  480. now := time.Now()
  481. date = &now
  482. } else {
  483. var parseErr error
  484. date, parseErr = utils.ParseTimeStringToTime("2006-01-02", dateStr)
  485. if parseErr != nil {
  486. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  487. return
  488. }
  489. }
  490. adminUserInfo := this.GetAdminUserInfo()
  491. // 获取本周的排班
  492. monday, sunday := utils.GetMondayAndSundayOfWeekDate(date)
  493. schedules, getScheduleErr := service.GetPrinitWeekSchedules(adminUserInfo.CurrentOrgId, monday.Unix(), sunday.Unix())
  494. if getScheduleErr != nil {
  495. this.ErrorLog("获取周排班失败:%v", getScheduleErr)
  496. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  497. return
  498. }
  499. this.ServeSuccessJSON(map[string]interface{}{
  500. "schedules": schedules,
  501. "monday": monday.Unix(),
  502. })
  503. }
  504. func (this *ScheduleApiController) UrgentScheduleData() {
  505. schedule_type, _ := this.GetInt("type", 0)
  506. schedule_date := this.GetString("date")
  507. var date *time.Time
  508. if len(schedule_date) == 0 {
  509. now := time.Now()
  510. date = &now
  511. } else {
  512. var parseErr error
  513. date, parseErr = utils.ParseTimeStringToTime("2006-01-02", schedule_date)
  514. if parseErr != nil {
  515. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  516. return
  517. }
  518. }
  519. adminUserInfo := this.GetAdminUserInfo()
  520. deviceNumbers, getDeviceNumbersErr := service.MobileGetAllDeviceNumbersForUrgentSchedule(adminUserInfo.CurrentOrgId, date.Unix(), schedule_type)
  521. if getDeviceNumbersErr != nil {
  522. this.ErrorLog("获取所有床位失败:%v", getDeviceNumbersErr)
  523. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  524. return
  525. }
  526. // today := utils.ZeroHourTimeOfDay(time.Now())
  527. schedules, getSchedulesErr := service.MobileGetOtherSchedulesForUrgentSchedule(adminUserInfo.CurrentOrgId, date.Unix(), schedule_type)
  528. if getSchedulesErr != nil {
  529. this.ErrorLog("获取所有排班失败:%v", getSchedulesErr)
  530. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  531. return
  532. }
  533. this.ServeSuccessJSON(map[string]interface{}{
  534. "device_numbers": deviceNumbers,
  535. "schedules": schedules,
  536. })
  537. }
  538. func (this *ScheduleApiController) SearchSchedulePatients() {
  539. keywords := this.GetString("keywords")
  540. adminUserInfo := this.GetAdminUserInfo()
  541. list, _ := service.GetSchedualPatientsByKeywords(keywords, adminUserInfo.CurrentOrgId)
  542. this.ServeSuccessJSON(map[string]interface{}{
  543. "schdules": list,
  544. })
  545. }
  546. type aa struct {
  547. b int64
  548. c int64
  549. }
  550. func (this *ScheduleApiController) GetWeekDaySchedule() {
  551. week_type, _ := this.GetInt64("week_type", -1)
  552. fmt.Println(week_type)
  553. thisTime := time.Now()
  554. weekDay := int(thisTime.Weekday())
  555. if weekDay == 0 {
  556. weekDay = 7
  557. }
  558. weekEnd := 7 - weekDay
  559. weekStart := weekEnd - 6
  560. weekTitle := make([]string, 0)
  561. days := make([]string, 0)
  562. for index := weekStart; index <= weekEnd; index++ {
  563. theDay := thisTime.AddDate(0, 0, index)
  564. indexYear, indexMonthTime, indexDay := theDay.Date()
  565. indexMonth := int(indexMonthTime)
  566. indexWeek := strconv.Itoa(indexYear) + "." + strconv.Itoa(indexMonth) + "." + strconv.Itoa(indexDay)
  567. weekTitle = append(weekTitle, indexWeek)
  568. days = append(days, theDay.Format("2006-01-02"))
  569. }
  570. fmt.Println(days)
  571. var targetDayStr string
  572. switch week_type {
  573. case 1:
  574. targetDayStr = days[0]
  575. break
  576. case 2:
  577. targetDayStr = days[1]
  578. break
  579. case 3:
  580. targetDayStr = days[2]
  581. break
  582. case 4:
  583. targetDayStr = days[3]
  584. break
  585. case 5:
  586. targetDayStr = days[4]
  587. break
  588. case 6:
  589. targetDayStr = days[5]
  590. break
  591. case 7:
  592. targetDayStr = days[6]
  593. break
  594. }
  595. targetDay, parseErr := utils.ParseTimeStringToTime("2006-01-02", targetDayStr)
  596. if parseErr != nil {
  597. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  598. return
  599. }
  600. adminUserInfo := this.GetAdminUserInfo()
  601. list, _ := service.GetWeekDaySchedule(adminUserInfo.CurrentOrgId, targetDay.Unix(), targetDay)
  602. this.ServeSuccessJSON(map[string]interface{}{
  603. "schdules": list,
  604. "day": targetDayStr,
  605. })
  606. }
  607. func Struct2Map(obj interface{}) map[string]interface{} {
  608. t := reflect.TypeOf(obj)
  609. v := reflect.ValueOf(obj)
  610. var data = make(map[string]interface{})
  611. for i := 0; i < t.NumField(); i++ {
  612. data[t.Field(i).Name] = v.Field(i).Interface()
  613. }
  614. return data
  615. }
  616. func (this *ScheduleApiController) ExportSchedule() {
  617. dataBody := make(map[string]interface{}, 0)
  618. err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
  619. if err != nil {
  620. utils.ErrorLog(err.Error())
  621. return
  622. }
  623. utils.ErrorLog("%v", dataBody)
  624. export_time := time.Now().Unix()
  625. var schedules []*models.Schedule
  626. var failed_total int
  627. var total_schedule []interface{}
  628. var patients []*models.Patients
  629. patients, _, _ = service.GetAllPatientList(this.GetAdminUserInfo().CurrentOrgId)
  630. if dataBody["failed_schedule"] != nil || reflect.TypeOf(dataBody["failed_schedule"]).String() == "[]interface {}" {
  631. tempSchedule := dataBody["failed_schedule"].([]interface{})
  632. failed_total = len(tempSchedule)
  633. }
  634. if dataBody["schedule"] != nil || reflect.TypeOf(dataBody["schedule"]).String() == "[]interface {}" {
  635. tempSchedule := dataBody["schedule"].([]interface{})
  636. total_schedule = tempSchedule
  637. for _, schMap := range tempSchedule {
  638. schMapM := schMap.(map[string]interface{})
  639. var sch models.Schedule
  640. if schMapM["name"] == nil || reflect.TypeOf(schMapM["name"]).String() != "string" {
  641. utils.ErrorLog("name")
  642. return
  643. }
  644. name, _ := schMapM["name"].(string)
  645. fmt.Println(name)
  646. if len(name) == 0 { //名字为空则生成一条导入错误日志
  647. err_log := models.ExportErrLog{
  648. LogType: 2,
  649. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  650. ErrMsg: "第" + strconv.FormatInt(int64(schMapM["index"].(float64)), 10) + "行,第" + schMapM["row"].(string) + "列的姓名不能为空",
  651. Status: 1,
  652. CreateTime: time.Now().Unix(),
  653. UpdateTime: time.Now().Unix(),
  654. ExportTime: export_time,
  655. }
  656. service.CreateExportErrLog(&err_log)
  657. continue
  658. } else {
  659. var patient []*models.Patients
  660. for _, item := range patients {
  661. if item.Name == name {
  662. patient = append(patient, item)
  663. }
  664. }
  665. if len(patient) == 0 { //错误日志
  666. err_log := models.ExportErrLog{
  667. LogType: 2,
  668. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  669. ErrMsg: "第" + strconv.FormatInt(int64(schMapM["index"].(float64)), 10) + "行,第" + schMapM["row"].(string) + "列的姓名在系统中不存在,请在系统中添加该病人",
  670. Status: 1,
  671. CreateTime: time.Now().Unix(),
  672. UpdateTime: time.Now().Unix(),
  673. ExportTime: export_time,
  674. }
  675. service.CreateExportErrLog(&err_log)
  676. continue
  677. } else if len(patient) == 1 { //
  678. sch.PatientId = patient[0].ID
  679. } else if len(patient) > 1 { //出现同名的情况
  680. err_log := models.ExportErrLog{
  681. LogType: 2,
  682. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  683. ErrMsg: "存在同名同姓的两个病人",
  684. Status: 1,
  685. CreateTime: time.Now().Unix(),
  686. UpdateTime: time.Now().Unix(),
  687. ExportTime: export_time,
  688. }
  689. service.CreateExportErrLog(&err_log)
  690. continue
  691. }
  692. }
  693. if schMapM["schedule_type"] == nil && reflect.TypeOf(schMapM["schedule_type"]).String() != "float64" {
  694. utils.ErrorLog("schedule_type")
  695. return
  696. }
  697. schedule_type := int64(schMapM["schedule_type"].(float64))
  698. if schedule_type <= 0 { //班次格式有误,插入日志
  699. log := models.ExportLog{
  700. LogType: 2,
  701. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  702. TotalNum: int64(len(total_schedule) + failed_total),
  703. FailNum: 1 + int64(failed_total),
  704. SuccessNum: int64(len(schedules)),
  705. CreateTime: time.Now().Unix(),
  706. UpdateTime: time.Now().Unix(),
  707. ExportTime: export_time,
  708. Status: 1,
  709. }
  710. service.CreateExportLog(&log)
  711. err_log := models.ExportErrLog{
  712. LogType: 2,
  713. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  714. ErrMsg: "第2行第" + schMapM["row"].(string) + "列的班次格式有误",
  715. Status: 1,
  716. CreateTime: time.Now().Unix(),
  717. UpdateTime: time.Now().Unix(),
  718. ExportTime: export_time,
  719. }
  720. service.CreateExportErrLog(&err_log)
  721. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeExportError)
  722. return
  723. } else {
  724. sch.ScheduleType = schedule_type
  725. }
  726. if schMapM["partition_name"] == nil || reflect.TypeOf(schMapM["partition_name"]).String() != "string" {
  727. utils.ErrorLog("partition_name")
  728. return
  729. }
  730. partition_name, _ := schMapM["partition_name"].(string)
  731. if len(partition_name) == 0 { //分区为空
  732. log := models.ExportLog{
  733. LogType: 2,
  734. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  735. TotalNum: int64(len(total_schedule) + failed_total),
  736. FailNum: 1 + int64(failed_total),
  737. SuccessNum: int64(len(schedules)),
  738. CreateTime: time.Now().Unix(),
  739. UpdateTime: time.Now().Unix(),
  740. ExportTime: export_time,
  741. Status: 1,
  742. }
  743. service.CreateExportLog(&log)
  744. err_log := models.ExportErrLog{
  745. LogType: 2,
  746. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  747. //ErrMsg: "第" + strconv.FormatInt(int64(schMapM["index"].(float64)) ,10)+ "行" + "的姓名不能为空",
  748. ErrMsg: "第" + strconv.FormatInt(int64(schMapM["index"].(float64)), 10) + "行第1列所属的分区格式有误",
  749. Status: 1,
  750. CreateTime: time.Now().Unix(),
  751. UpdateTime: time.Now().Unix(),
  752. ExportTime: export_time,
  753. }
  754. service.CreateExportErrLog(&err_log)
  755. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeExportError)
  756. return
  757. } else {
  758. zone, err := service.FindDeviceZoneByName(partition_name, this.GetAdminUserInfo().CurrentOrgId)
  759. if err == nil {
  760. sch.PartitionId = zone.ID
  761. } else if err == gorm.ErrRecordNotFound { //查不到数据,插入错误日志
  762. log := models.ExportLog{
  763. LogType: 2,
  764. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  765. TotalNum: int64(len(total_schedule) + failed_total),
  766. FailNum: 1 + int64(failed_total),
  767. SuccessNum: int64(len(schedules)),
  768. CreateTime: time.Now().Unix(),
  769. UpdateTime: time.Now().Unix(),
  770. ExportTime: export_time,
  771. Status: 1,
  772. }
  773. service.CreateExportLog(&log)
  774. err_log := models.ExportErrLog{
  775. LogType: 2,
  776. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  777. //ErrMsg: "第" + strconv.FormatInt(int64(schMapM["index"].(float64)) ,10)+ "行" + "的姓名不能为空",
  778. ErrMsg: "第" + strconv.FormatInt(int64(schMapM["index"].(float64)), 10) + "行第1列所属的分区格式有误",
  779. Status: 1,
  780. CreateTime: time.Now().Unix(),
  781. UpdateTime: time.Now().Unix(),
  782. ExportTime: export_time,
  783. }
  784. service.CreateExportErrLog(&err_log)
  785. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeExportError)
  786. return
  787. }
  788. }
  789. if schMapM["device_number_name"] == nil || reflect.TypeOf(schMapM["device_number_name"]).String() != "string" {
  790. utils.ErrorLog("device_number_name")
  791. return
  792. }
  793. device_number_name, _ := schMapM["device_number_name"].(string)
  794. if len(device_number_name) == 0 { //分区为空
  795. log := models.ExportLog{
  796. LogType: 2,
  797. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  798. TotalNum: int64(len(total_schedule) + failed_total),
  799. FailNum: 1 + int64(failed_total),
  800. SuccessNum: int64(len(schedules)),
  801. CreateTime: time.Now().Unix(),
  802. UpdateTime: time.Now().Unix(),
  803. ExportTime: export_time,
  804. Status: 1,
  805. }
  806. service.CreateExportLog(&log)
  807. err_log := models.ExportErrLog{
  808. LogType: 2,
  809. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  810. //ErrMsg: "第" + strconv.FormatInt(int64(schMapM["index"].(float64)) ,10)+ "行" + "的姓名不能为空",
  811. ErrMsg: "第" + strconv.FormatInt(int64(schMapM["index"].(float64)), 10) + "行第2列机号格式有误",
  812. Status: 1,
  813. CreateTime: time.Now().Unix(),
  814. UpdateTime: time.Now().Unix(),
  815. ExportTime: export_time,
  816. }
  817. service.CreateExportErrLog(&err_log)
  818. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeExportError)
  819. return
  820. } else {
  821. device, err := service.FindDeviceByName(device_number_name, this.GetAdminUserInfo().CurrentOrgId, sch.PartitionId)
  822. if err == nil {
  823. if len(device) == 0 { //没查到数据,插入错误日志
  824. log := models.ExportLog{
  825. LogType: 2,
  826. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  827. TotalNum: int64(len(total_schedule) + failed_total),
  828. FailNum: 1 + int64(failed_total),
  829. SuccessNum: int64(len(schedules)),
  830. CreateTime: time.Now().Unix(),
  831. UpdateTime: time.Now().Unix(),
  832. ExportTime: export_time,
  833. Status: 1,
  834. }
  835. service.CreateExportLog(&log)
  836. err_log := models.ExportErrLog{
  837. LogType: 2,
  838. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  839. ErrMsg: "第" + strconv.FormatInt(int64(schMapM["index"].(float64)), 10) + "行第2列机号格式有误",
  840. Status: 1,
  841. CreateTime: time.Now().Unix(),
  842. UpdateTime: time.Now().Unix(),
  843. ExportTime: export_time,
  844. }
  845. service.CreateExportErrLog(&err_log)
  846. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeExportError)
  847. return
  848. } else if len(device) == 1 {
  849. sch.BedId = device[0].ID
  850. } else if len(device) > 1 { //出现重名,插入错误日志
  851. log := models.ExportLog{
  852. LogType: 2,
  853. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  854. TotalNum: int64(len(total_schedule) + failed_total),
  855. FailNum: 1 + int64(failed_total),
  856. SuccessNum: int64(len(schedules)),
  857. CreateTime: time.Now().Unix(),
  858. UpdateTime: time.Now().Unix(),
  859. ExportTime: export_time,
  860. Status: 1,
  861. }
  862. service.CreateExportLog(&log)
  863. err_log := models.ExportErrLog{
  864. LogType: 2,
  865. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  866. ErrMsg: "出现两个床位号相同的床位",
  867. Status: 1,
  868. CreateTime: time.Now().Unix(),
  869. UpdateTime: time.Now().Unix(),
  870. ExportTime: export_time,
  871. }
  872. service.CreateExportErrLog(&err_log)
  873. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeExportError)
  874. return
  875. }
  876. }
  877. }
  878. if schMapM["schedule_week"] == nil || reflect.TypeOf(schMapM["schedule_week"]).String() != "string" {
  879. utils.ErrorLog("schedule_week")
  880. return
  881. }
  882. schedule_week, _ := schMapM["schedule_week"].(string)
  883. if len(schedule_week) == 0 { //周几为空则生成一条导入错误日志
  884. log := models.ExportLog{
  885. LogType: 2,
  886. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  887. TotalNum: int64(len(total_schedule) + failed_total),
  888. FailNum: 1 + int64(failed_total),
  889. SuccessNum: int64(len(schedules)),
  890. CreateTime: time.Now().Unix(),
  891. UpdateTime: time.Now().Unix(),
  892. ExportTime: export_time,
  893. Status: 1,
  894. }
  895. service.CreateExportLog(&log)
  896. err_log := models.ExportErrLog{
  897. LogType: 2,
  898. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  899. //ErrMsg: "第" + strconv.FormatInt(int64(schMapM["index"].(float64)) ,10)+ "行" + "的姓名不能为空",
  900. ErrMsg: "第1行第" + schMapM["row"].(string) + "列的星期名格式有误",
  901. Status: 1,
  902. CreateTime: time.Now().Unix(),
  903. UpdateTime: time.Now().Unix(),
  904. ExportTime: export_time,
  905. }
  906. service.CreateExportErrLog(&err_log)
  907. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeExportError)
  908. return
  909. } else if schedule_week == "0" { //周几不符合格式则生成一条导入错误日志
  910. log := models.ExportLog{
  911. LogType: 2,
  912. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  913. TotalNum: int64(len(total_schedule) + failed_total),
  914. FailNum: 1 + int64(failed_total),
  915. SuccessNum: int64(len(schedules)),
  916. CreateTime: time.Now().Unix(),
  917. UpdateTime: time.Now().Unix(),
  918. ExportTime: export_time,
  919. Status: 1,
  920. }
  921. service.CreateExportLog(&log)
  922. err_log := models.ExportErrLog{
  923. LogType: 2,
  924. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  925. ErrMsg: "第1行第" + schMapM["row"].(string) + "列的星期名格式有误",
  926. Status: 1,
  927. CreateTime: time.Now().Unix(),
  928. UpdateTime: time.Now().Unix(),
  929. ExportTime: export_time,
  930. }
  931. service.CreateExportErrLog(&err_log)
  932. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeExportError)
  933. return
  934. } else {
  935. schedule_week, _ := strconv.ParseInt(schedule_week, 10, 64)
  936. sch.ScheduleWeek = schedule_week
  937. }
  938. if schMapM["schedule_date"] == nil || reflect.TypeOf(schMapM["schedule_date"]).String() != "string" {
  939. utils.ErrorLog("schedule_date")
  940. return
  941. }
  942. schedule_date, _ := schMapM["schedule_date"].(string)
  943. if len(schedule_date) == 0 { //周几为空则生成一条导入错误日志
  944. log := models.ExportLog{
  945. LogType: 2,
  946. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  947. TotalNum: int64(len(total_schedule) + failed_total),
  948. FailNum: 1 + int64(failed_total),
  949. SuccessNum: int64(len(schedules)),
  950. CreateTime: time.Now().Unix(),
  951. UpdateTime: time.Now().Unix(),
  952. ExportTime: export_time,
  953. Status: 1,
  954. }
  955. service.CreateExportLog(&log)
  956. err_log := models.ExportErrLog{
  957. LogType: 2,
  958. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  959. ErrMsg: "第1行第" + schMapM["row"].(string) + "列的星期名格式有误",
  960. Status: 1,
  961. CreateTime: time.Now().Unix(),
  962. UpdateTime: time.Now().Unix(),
  963. ExportTime: export_time,
  964. }
  965. service.CreateExportErrLog(&err_log)
  966. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeExportError)
  967. return
  968. } else if schedule_date == "0" { //周几不符合格式则生成一条导入错误日志
  969. log := models.ExportLog{
  970. LogType: 2,
  971. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  972. TotalNum: int64(len(total_schedule) + failed_total),
  973. FailNum: 1 + int64(failed_total),
  974. SuccessNum: int64(len(schedules)),
  975. CreateTime: time.Now().Unix(),
  976. UpdateTime: time.Now().Unix(),
  977. ExportTime: export_time,
  978. Status: 1,
  979. }
  980. service.CreateExportLog(&log)
  981. err_log := models.ExportErrLog{
  982. LogType: 2,
  983. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  984. ErrMsg: "第1行第" + schMapM["row"].(string) + "列的星期名格式有误",
  985. Status: 1,
  986. CreateTime: time.Now().Unix(),
  987. UpdateTime: time.Now().Unix(),
  988. ExportTime: export_time,
  989. }
  990. service.CreateExportErrLog(&err_log)
  991. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeExportError)
  992. return
  993. } else {
  994. date, _ := utils.ParseTimeStringToTime("2006-01-02", schedule_date)
  995. sch.ScheduleDate = date.Unix()
  996. }
  997. sch.CreatedTime = time.Now().Unix()
  998. sch.UpdatedTime = time.Now().Unix()
  999. sch.ModeId = 1
  1000. sch.Status = 1
  1001. sch.UserOrgId = this.GetAdminUserInfo().CurrentOrgId
  1002. sch.IsExport = 1
  1003. schedules = append(schedules, &sch)
  1004. }
  1005. errLogs, _ := service.FindSchedualExportLog(this.GetAdminUserInfo().CurrentOrgId, export_time)
  1006. if len(schedules) > 0 {
  1007. schedule_date := this.GetString("date")
  1008. date, _ := utils.ParseTimeStringToTime("2006-01-02", schedule_date)
  1009. clear_schedule_date := date.Unix() //根据日期去清除,该日期以及未来的排班数据
  1010. err := service.UpdateScheduleStatus(clear_schedule_date, this.GetAdminUserInfo().CurrentOrgId)
  1011. if err == nil {
  1012. for _, item := range schedules {
  1013. service.CreateSchedule(item)
  1014. }
  1015. log := models.ExportLog{
  1016. LogType: 2,
  1017. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  1018. TotalNum: int64(len(total_schedule) + failed_total),
  1019. FailNum: int64(len(errLogs) + 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. if failed_total > 0 {
  1028. err_log := models.ExportErrLog{
  1029. LogType: 2,
  1030. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  1031. ErrMsg: "当前日期(" + this.GetString("date") + " " + GetWeekString(time.Now().Weekday().String()) +
  1032. ")及以前的排班数据" + strconv.FormatInt(int64(failed_total), 10) + "条,不执行导入",
  1033. Status: 1,
  1034. CreateTime: time.Now().Unix(),
  1035. UpdateTime: time.Now().Unix(),
  1036. ExportTime: export_time,
  1037. }
  1038. service.CreateExportErrLog(&err_log)
  1039. }
  1040. this.ServeSuccessJSON(map[string]interface{}{
  1041. "msg": "导入成功",
  1042. "total_num": len(total_schedule) + failed_total,
  1043. "success_num": len(schedules),
  1044. "fail_num": int64(len(errLogs)),
  1045. })
  1046. } else {
  1047. log := models.ExportLog{
  1048. LogType: 2,
  1049. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  1050. TotalNum: int64(len(total_schedule) + failed_total),
  1051. FailNum: int64(len(errLogs) + failed_total),
  1052. SuccessNum: int64(len(schedules)),
  1053. CreateTime: time.Now().Unix(),
  1054. UpdateTime: time.Now().Unix(),
  1055. ExportTime: export_time,
  1056. Status: 1,
  1057. }
  1058. service.CreateExportLog(&log)
  1059. if failed_total > 0 {
  1060. err_log := models.ExportErrLog{
  1061. LogType: 2,
  1062. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  1063. ErrMsg: "当前日期(" + this.GetString("date") + " " + GetWeekString(time.Now().Weekday().String()) +
  1064. ")及以前的排班数据" + strconv.FormatInt(int64(failed_total), 10) + "条,不执行导入",
  1065. Status: 1,
  1066. CreateTime: time.Now().Unix(),
  1067. UpdateTime: time.Now().Unix(),
  1068. ExportTime: export_time,
  1069. }
  1070. service.CreateExportErrLog(&err_log)
  1071. }
  1072. this.ServeSuccessJSON(map[string]interface{}{
  1073. "msg": "导入成功",
  1074. "total_num": len(total_schedule),
  1075. "success_num": len(schedules),
  1076. "fail_num": int64(len(errLogs)),
  1077. })
  1078. }
  1079. } else {
  1080. log := models.ExportLog{
  1081. LogType: 2,
  1082. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  1083. TotalNum: int64(len(total_schedule) + failed_total),
  1084. FailNum: int64(len(errLogs) + failed_total),
  1085. SuccessNum: int64(len(schedules)),
  1086. CreateTime: time.Now().Unix(),
  1087. UpdateTime: time.Now().Unix(),
  1088. ExportTime: export_time,
  1089. Status: 1,
  1090. }
  1091. service.CreateExportLog(&log)
  1092. if failed_total > 0 {
  1093. err_log := models.ExportErrLog{
  1094. LogType: 2,
  1095. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  1096. ErrMsg: "当前日期(" + this.GetString("date") + " " + GetWeekString(time.Now().Weekday().String()) +
  1097. ")及以前的排班数据" + strconv.FormatInt(int64(failed_total), 10) + "条,不执行导入",
  1098. Status: 1,
  1099. CreateTime: time.Now().Unix(),
  1100. UpdateTime: time.Now().Unix(),
  1101. ExportTime: export_time,
  1102. }
  1103. service.CreateExportErrLog(&err_log)
  1104. }
  1105. this.ServeSuccessJSON(map[string]interface{}{
  1106. "msg": "导入成功",
  1107. "total_num": len(total_schedule),
  1108. "success_num": len(schedules),
  1109. "fail_num": int64(len(errLogs)),
  1110. })
  1111. }
  1112. }
  1113. }
  1114. func (this *ScheduleApiController) ExportScheduleTemplate() {
  1115. dataBody := make(map[string]interface{}, 0)
  1116. err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
  1117. if err != nil {
  1118. utils.ErrorLog(err.Error())
  1119. return
  1120. }
  1121. utils.ErrorLog("%v", dataBody)
  1122. export_time := time.Now().Unix()
  1123. var schedules []*models.PatientScheduleTemplateItem
  1124. var total_schedule []interface{}
  1125. patients, _, _ := service.GetAllPatientList(this.GetAdminUserInfo().CurrentOrgId)
  1126. if dataBody["schedule"] != nil || reflect.TypeOf(dataBody["schedule"]).String() == "[]interface {}" {
  1127. tempSchedule := dataBody["schedule"].([]interface{})
  1128. total_schedule = tempSchedule
  1129. for _, schMap := range tempSchedule {
  1130. schMapM := schMap.(map[string]interface{})
  1131. var sch models.PatientScheduleTemplateItem
  1132. if schMapM["name"] == nil || reflect.TypeOf(schMapM["name"]).String() != "string" {
  1133. utils.ErrorLog("name")
  1134. return
  1135. }
  1136. name, _ := schMapM["name"].(string)
  1137. fmt.Println(name)
  1138. if len(name) == 0 { //名字为空则生成一条导入错误日志
  1139. err_log := models.ExportErrLog{
  1140. LogType: 3,
  1141. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  1142. ErrMsg: "第" + strconv.FormatInt(int64(schMapM["index"].(float64)), 10) + "行,第" + schMapM["row"].(string) + "列的姓名不能为空",
  1143. Status: 1,
  1144. CreateTime: time.Now().Unix(),
  1145. UpdateTime: time.Now().Unix(),
  1146. ExportTime: export_time,
  1147. }
  1148. service.CreateExportErrLog(&err_log)
  1149. continue
  1150. } else {
  1151. var patient []*models.Patients
  1152. for _, item := range patients {
  1153. if item.Name == name {
  1154. patient = append(patient, item)
  1155. }
  1156. }
  1157. if len(patient) == 0 { //错误日志
  1158. err_log := models.ExportErrLog{
  1159. LogType: 3,
  1160. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  1161. ErrMsg: "第" + strconv.FormatInt(int64(schMapM["index"].(float64)), 10) + "行,第" + schMapM["row"].(string) + "列的姓名在系统中不存在,请在系统中添加该病人",
  1162. Status: 1,
  1163. CreateTime: time.Now().Unix(),
  1164. UpdateTime: time.Now().Unix(),
  1165. ExportTime: export_time,
  1166. }
  1167. service.CreateExportErrLog(&err_log)
  1168. continue
  1169. } else if len(patient) == 1 { //
  1170. sch.PatientID = patient[0].ID
  1171. } else if len(patient) > 1 { //出现同名的情况
  1172. err_log := models.ExportErrLog{
  1173. LogType: 3,
  1174. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  1175. ErrMsg: "存在同名同姓的两个病人",
  1176. Status: 1,
  1177. CreateTime: time.Now().Unix(),
  1178. UpdateTime: time.Now().Unix(),
  1179. ExportTime: export_time,
  1180. }
  1181. service.CreateExportErrLog(&err_log)
  1182. continue
  1183. }
  1184. }
  1185. if schMapM["schedule_type"] == nil && reflect.TypeOf(schMapM["schedule_type"]).String() != "float64" {
  1186. utils.ErrorLog("schedule_type")
  1187. return
  1188. }
  1189. schedule_type := int64(schMapM["schedule_type"].(float64))
  1190. if schedule_type <= 0 { //班次格式有误,插入日志
  1191. log := models.ExportLog{
  1192. LogType: 3,
  1193. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  1194. TotalNum: int64(len(total_schedule)),
  1195. FailNum: 1,
  1196. SuccessNum: int64(len(schedules)),
  1197. CreateTime: time.Now().Unix(),
  1198. UpdateTime: time.Now().Unix(),
  1199. ExportTime: export_time,
  1200. Status: 1,
  1201. }
  1202. service.CreateExportLog(&log)
  1203. err_log := models.ExportErrLog{
  1204. LogType: 3,
  1205. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  1206. ErrMsg: "第2行第" + schMapM["row"].(string) + "列的班次格式有误",
  1207. Status: 1,
  1208. CreateTime: time.Now().Unix(),
  1209. UpdateTime: time.Now().Unix(),
  1210. ExportTime: export_time,
  1211. }
  1212. service.CreateExportErrLog(&err_log)
  1213. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeExportError)
  1214. return
  1215. } else {
  1216. sch.TimeType = int8(schedule_type)
  1217. }
  1218. if schMapM["template_id"] == nil && reflect.TypeOf(schMapM["template_id"]).String() != "float64" {
  1219. utils.ErrorLog("template_id")
  1220. return
  1221. }
  1222. template_id := int64(schMapM["template_id"].(float64))
  1223. sch.TemplateID = template_id
  1224. if schMapM["device_number_name"] == nil || reflect.TypeOf(schMapM["device_number_name"]).String() != "string" {
  1225. utils.ErrorLog("device_number_name")
  1226. return
  1227. }
  1228. partition_name, _ := schMapM["partition_name"].(string)
  1229. zone, _ := service.FindDeviceZoneByName(partition_name, this.GetAdminUserInfo().CurrentOrgId)
  1230. device_number_name, _ := schMapM["device_number_name"].(string)
  1231. if len(device_number_name) == 0 { //分区为空
  1232. log := models.ExportLog{
  1233. LogType: 3,
  1234. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  1235. TotalNum: int64(len(total_schedule)),
  1236. FailNum: 1,
  1237. SuccessNum: int64(len(schedules)),
  1238. CreateTime: time.Now().Unix(),
  1239. UpdateTime: time.Now().Unix(),
  1240. ExportTime: export_time,
  1241. Status: 1,
  1242. }
  1243. service.CreateExportLog(&log)
  1244. err_log := models.ExportErrLog{
  1245. LogType: 3,
  1246. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  1247. //ErrMsg: "第" + strconv.FormatInt(int64(schMapM["index"].(float64)) ,10)+ "行" + "的姓名不能为空",
  1248. ErrMsg: "第" + strconv.FormatInt(int64(schMapM["index"].(float64)), 10) + "行第2列机号格式有误",
  1249. Status: 1,
  1250. CreateTime: time.Now().Unix(),
  1251. UpdateTime: time.Now().Unix(),
  1252. ExportTime: export_time,
  1253. }
  1254. service.CreateExportErrLog(&err_log)
  1255. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeExportError)
  1256. return
  1257. } else {
  1258. device, err := service.FindDeviceByNameTwo(device_number_name, this.GetAdminUserInfo().CurrentOrgId, zone.ID)
  1259. if err == nil {
  1260. if len(device) == 0 { //没查到数据,插入错误日志
  1261. log := models.ExportLog{
  1262. LogType: 3,
  1263. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  1264. TotalNum: int64(len(total_schedule)),
  1265. FailNum: 1,
  1266. SuccessNum: int64(len(schedules)),
  1267. CreateTime: time.Now().Unix(),
  1268. UpdateTime: time.Now().Unix(),
  1269. ExportTime: export_time,
  1270. Status: 1,
  1271. }
  1272. service.CreateExportLog(&log)
  1273. err_log := models.ExportErrLog{
  1274. LogType: 3,
  1275. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  1276. ErrMsg: "第" + strconv.FormatInt(int64(schMapM["index"].(float64)), 10) + "行第2列机号格式有误",
  1277. Status: 1,
  1278. CreateTime: time.Now().Unix(),
  1279. UpdateTime: time.Now().Unix(),
  1280. ExportTime: export_time,
  1281. }
  1282. service.CreateExportErrLog(&err_log)
  1283. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeExportError)
  1284. return
  1285. } else if len(device) == 1 {
  1286. sch.DeviceNumberID = device[0].ID
  1287. } else if len(device) > 1 { //出现重名,插入错误日志
  1288. log := models.ExportLog{
  1289. LogType: 3,
  1290. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  1291. TotalNum: int64(len(total_schedule)),
  1292. FailNum: 1,
  1293. SuccessNum: int64(len(schedules)),
  1294. CreateTime: time.Now().Unix(),
  1295. UpdateTime: time.Now().Unix(),
  1296. ExportTime: export_time,
  1297. Status: 1,
  1298. }
  1299. service.CreateExportLog(&log)
  1300. err_log := models.ExportErrLog{
  1301. LogType: 3,
  1302. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  1303. ErrMsg: "出现两个床位号相同的床位",
  1304. Status: 1,
  1305. CreateTime: time.Now().Unix(),
  1306. UpdateTime: time.Now().Unix(),
  1307. ExportTime: export_time,
  1308. }
  1309. service.CreateExportErrLog(&err_log)
  1310. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeExportError)
  1311. return
  1312. }
  1313. }
  1314. }
  1315. if schMapM["schedule_week"] == nil || reflect.TypeOf(schMapM["schedule_week"]).String() != "string" {
  1316. utils.ErrorLog("schedule_week")
  1317. return
  1318. }
  1319. schedule_week, _ := schMapM["schedule_week"].(string)
  1320. if len(schedule_week) == 0 { //周几为空则生成一条导入错误日志
  1321. log := models.ExportLog{
  1322. LogType: 3,
  1323. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  1324. TotalNum: int64(len(total_schedule)),
  1325. FailNum: 1,
  1326. SuccessNum: int64(len(schedules)),
  1327. CreateTime: time.Now().Unix(),
  1328. UpdateTime: time.Now().Unix(),
  1329. ExportTime: export_time,
  1330. Status: 1,
  1331. }
  1332. service.CreateExportLog(&log)
  1333. err_log := models.ExportErrLog{
  1334. LogType: 3,
  1335. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  1336. //ErrMsg: "第" + strconv.FormatInt(int64(schMapM["index"].(float64)) ,10)+ "行" + "的姓名不能为空",
  1337. ErrMsg: "第1行第" + schMapM["row"].(string) + "列的星期名格式有误",
  1338. Status: 1,
  1339. CreateTime: time.Now().Unix(),
  1340. UpdateTime: time.Now().Unix(),
  1341. ExportTime: export_time,
  1342. }
  1343. service.CreateExportErrLog(&err_log)
  1344. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeExportError)
  1345. return
  1346. } else if schedule_week == "0" { //周几不符合格式则生成一条导入错误日志
  1347. log := models.ExportLog{
  1348. LogType: 3,
  1349. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  1350. TotalNum: int64(len(total_schedule)),
  1351. FailNum: 1,
  1352. SuccessNum: int64(len(schedules)),
  1353. CreateTime: time.Now().Unix(),
  1354. UpdateTime: time.Now().Unix(),
  1355. ExportTime: export_time,
  1356. Status: 1,
  1357. }
  1358. service.CreateExportLog(&log)
  1359. err_log := models.ExportErrLog{
  1360. LogType: 3,
  1361. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  1362. ErrMsg: "第1行第" + schMapM["row"].(string) + "列的星期名格式有误",
  1363. Status: 1,
  1364. CreateTime: time.Now().Unix(),
  1365. UpdateTime: time.Now().Unix(),
  1366. ExportTime: export_time,
  1367. }
  1368. service.CreateExportErrLog(&err_log)
  1369. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeExportError)
  1370. return
  1371. } else {
  1372. schedule_week, _ := strconv.ParseInt(schedule_week, 10, 64)
  1373. sch.Weekday = int8(schedule_week)
  1374. }
  1375. sch.CreateTime = time.Now().Unix()
  1376. sch.ModifyTime = time.Now().Unix()
  1377. sch.TreatMode = 1
  1378. sch.Status = 1
  1379. sch.OrgID = this.GetAdminUserInfo().CurrentOrgId
  1380. sch.IsExport = 1
  1381. schedules = append(schedules, &sch)
  1382. }
  1383. errLogs, _ := service.FindSchedualTemplateExportLog(this.GetAdminUserInfo().CurrentOrgId, export_time)
  1384. if len(schedules) > 0 {
  1385. err := service.UpdateScheduleTemplateStatus(this.GetAdminUserInfo().CurrentOrgId)
  1386. if err == nil {
  1387. for _, item := range schedules {
  1388. service.CreateScheduleTemplate(item)
  1389. }
  1390. log := models.ExportLog{
  1391. LogType: 3,
  1392. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  1393. TotalNum: int64(len(total_schedule)),
  1394. FailNum: int64(len(errLogs)),
  1395. SuccessNum: int64(len(schedules)),
  1396. CreateTime: time.Now().Unix(),
  1397. UpdateTime: time.Now().Unix(),
  1398. ExportTime: export_time,
  1399. Status: 1,
  1400. }
  1401. service.CreateExportLog(&log)
  1402. this.ServeSuccessJSON(map[string]interface{}{
  1403. "msg": "导入成功",
  1404. "total_num": len(total_schedule),
  1405. "success_num": len(schedules),
  1406. "fail_num": int64(len(errLogs)),
  1407. })
  1408. } else {
  1409. log := models.ExportLog{
  1410. LogType: 3,
  1411. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  1412. TotalNum: int64(len(total_schedule)),
  1413. FailNum: int64(len(errLogs)),
  1414. SuccessNum: int64(len(schedules)),
  1415. CreateTime: time.Now().Unix(),
  1416. UpdateTime: time.Now().Unix(),
  1417. ExportTime: export_time,
  1418. Status: 1,
  1419. }
  1420. service.CreateExportLog(&log)
  1421. this.ServeSuccessJSON(map[string]interface{}{
  1422. "msg": "导入成功",
  1423. "total_num": len(total_schedule),
  1424. "success_num": len(schedules),
  1425. "fail_num": int64(len(errLogs)),
  1426. })
  1427. }
  1428. } else {
  1429. log := models.ExportLog{
  1430. LogType: 3,
  1431. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  1432. TotalNum: int64(len(total_schedule)),
  1433. FailNum: int64(len(errLogs)),
  1434. SuccessNum: int64(len(schedules)),
  1435. CreateTime: time.Now().Unix(),
  1436. UpdateTime: time.Now().Unix(),
  1437. ExportTime: export_time,
  1438. Status: 1,
  1439. }
  1440. service.CreateExportLog(&log)
  1441. this.ServeSuccessJSON(map[string]interface{}{
  1442. "msg": "导入成功",
  1443. "total_num": len(total_schedule),
  1444. "success_num": len(schedules),
  1445. "fail_num": int64(len(errLogs)),
  1446. })
  1447. }
  1448. }
  1449. }
  1450. func (c *ScheduleApiController) GetInitExcelInitDate() {
  1451. thisTime := time.Now()
  1452. thisTime1 := time.Now()
  1453. thisTime2 := time.Now()
  1454. thisTime1 = thisTime1.AddDate(0, 0, 7)
  1455. thisTime2 = thisTime2.AddDate(0, 0, 14)
  1456. weekDay := int(thisTime.Weekday())
  1457. if weekDay == 0 {
  1458. weekDay = 7
  1459. }
  1460. weekEnd := 7 - weekDay
  1461. weekStart := weekEnd - 6
  1462. days := make([]string, 0)
  1463. for index := weekStart; index <= weekEnd; index++ {
  1464. theDay := thisTime.AddDate(0, 0, index)
  1465. days = append(days, theDay.Format("2006-01-02"))
  1466. }
  1467. weekDay1 := int(thisTime1.Weekday())
  1468. if weekDay1 == 0 {
  1469. weekDay1 = 7
  1470. }
  1471. weekEnd1 := 7 - weekDay1
  1472. weekStart1 := weekEnd1 - 6
  1473. for index := weekStart1; index <= weekEnd1; index++ {
  1474. theDay := thisTime1.AddDate(0, 0, index)
  1475. days = append(days, theDay.Format("2006-01-02"))
  1476. }
  1477. weekDay2 := int(thisTime2.Weekday())
  1478. if weekDay2 == 0 {
  1479. weekDay2 = 7
  1480. }
  1481. weekEnd2 := 7 - weekDay2
  1482. weekStart2 := weekEnd2 - 6
  1483. for index := weekStart2; index <= weekEnd2; index++ {
  1484. theDay := thisTime2.AddDate(0, 0, index)
  1485. days = append(days, theDay.Format("2006-01-02"))
  1486. }
  1487. c.ServeSuccessJSON(map[string]interface{}{
  1488. "days": days,
  1489. })
  1490. return
  1491. }
  1492. func GetWeekString(week string) string {
  1493. var weekStr string
  1494. switch week {
  1495. case "Sunday":
  1496. weekStr = "周日"
  1497. break
  1498. case "Monday":
  1499. weekStr = "周一"
  1500. break
  1501. case "Tuesday":
  1502. weekStr = "周二"
  1503. break
  1504. case "Wednesday":
  1505. weekStr = "周三"
  1506. break
  1507. case "Thursday":
  1508. weekStr = "周四"
  1509. break
  1510. case "Friday":
  1511. weekStr = "周五"
  1512. break
  1513. case "Saturday":
  1514. weekStr = "周六"
  1515. break
  1516. default:
  1517. weekStr = ""
  1518. break
  1519. }
  1520. return weekStr
  1521. }