schedule_api_controller.go 54KB

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