schedule_api_controller.go 54KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733
  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. this.ServeSuccessJSON(map[string]interface{}{
  501. "schedules": schedules,
  502. "monday": monday.Unix(),
  503. })
  504. }
  505. func (this *ScheduleApiController) UrgentScheduleData() {
  506. schedule_type, _ := this.GetInt("type", 0)
  507. schedule_date := this.GetString("date")
  508. var date *time.Time
  509. if len(schedule_date) == 0 {
  510. now := time.Now()
  511. date = &now
  512. } else {
  513. var parseErr error
  514. date, parseErr = utils.ParseTimeStringToTime("2006-01-02", schedule_date)
  515. if parseErr != nil {
  516. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  517. return
  518. }
  519. }
  520. adminUserInfo := this.GetAdminUserInfo()
  521. deviceNumbers, getDeviceNumbersErr := service.MobileGetAllDeviceNumbersForUrgentSchedule(adminUserInfo.CurrentOrgId, date.Unix(), schedule_type)
  522. if getDeviceNumbersErr != nil {
  523. this.ErrorLog("获取所有床位失败:%v", getDeviceNumbersErr)
  524. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  525. return
  526. }
  527. // today := utils.ZeroHourTimeOfDay(time.Now())
  528. schedules, getSchedulesErr := service.MobileGetOtherSchedulesForUrgentSchedule(adminUserInfo.CurrentOrgId, date.Unix(), schedule_type)
  529. if getSchedulesErr != nil {
  530. this.ErrorLog("获取所有排班失败:%v", getSchedulesErr)
  531. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  532. return
  533. }
  534. this.ServeSuccessJSON(map[string]interface{}{
  535. "device_numbers": deviceNumbers,
  536. "schedules": schedules,
  537. })
  538. }
  539. func (this *ScheduleApiController) SearchSchedulePatients() {
  540. keywords := this.GetString("keywords")
  541. adminUserInfo := this.GetAdminUserInfo()
  542. list, _ := service.GetSchedualPatientsByKeywords(keywords, adminUserInfo.CurrentOrgId)
  543. this.ServeSuccessJSON(map[string]interface{}{
  544. "schdules": list,
  545. })
  546. }
  547. func (this *ScheduleApiController) GetWeekDaySchedule() {
  548. week_type, _ := this.GetInt64("week_type", -1)
  549. fmt.Println(week_type)
  550. thisTime := time.Now()
  551. weekDay := int(thisTime.Weekday())
  552. if weekDay == 0 {
  553. weekDay = 7
  554. }
  555. weekEnd := 7 - weekDay
  556. weekStart := weekEnd - 6
  557. weekTitle := make([]string, 0)
  558. days := make([]string, 0)
  559. for index := weekStart; index <= weekEnd; index++ {
  560. theDay := thisTime.AddDate(0, 0, index)
  561. indexYear, indexMonthTime, indexDay := theDay.Date()
  562. indexMonth := int(indexMonthTime)
  563. indexWeek := strconv.Itoa(indexYear) + "." + strconv.Itoa(indexMonth) + "." + strconv.Itoa(indexDay)
  564. weekTitle = append(weekTitle, indexWeek)
  565. days = append(days, theDay.Format("2006-01-02"))
  566. }
  567. fmt.Println(days)
  568. var targetDayStr string
  569. switch week_type {
  570. case 1:
  571. targetDayStr = days[0]
  572. break
  573. case 2:
  574. targetDayStr = days[1]
  575. break
  576. case 3:
  577. targetDayStr = days[2]
  578. break
  579. case 4:
  580. targetDayStr = days[3]
  581. break
  582. case 5:
  583. targetDayStr = days[4]
  584. break
  585. case 6:
  586. targetDayStr = days[5]
  587. break
  588. case 7:
  589. targetDayStr = days[6]
  590. break
  591. }
  592. targetDay, parseErr := utils.ParseTimeStringToTime("2006-01-02", targetDayStr)
  593. if parseErr != nil {
  594. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  595. return
  596. }
  597. adminUserInfo := this.GetAdminUserInfo()
  598. list, _ := service.GetWeekDaySchedule(adminUserInfo.CurrentOrgId, targetDay.Unix(), targetDay)
  599. this.ServeSuccessJSON(map[string]interface{}{
  600. "schdules": list,
  601. "day": targetDayStr,
  602. })
  603. }
  604. func Struct2Map(obj interface{}) map[string]interface{} {
  605. t := reflect.TypeOf(obj)
  606. v := reflect.ValueOf(obj)
  607. var data = make(map[string]interface{})
  608. for i := 0; i < t.NumField(); i++ {
  609. data[t.Field(i).Name] = v.Field(i).Interface()
  610. }
  611. return data
  612. }
  613. func (this *ScheduleApiController) ExportSchedule() {
  614. dataBody := make(map[string]interface{}, 0)
  615. err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
  616. if err != nil {
  617. utils.ErrorLog(err.Error())
  618. return
  619. }
  620. utils.ErrorLog("%v", dataBody)
  621. export_time := time.Now().Unix()
  622. var schedules []*models.Schedule
  623. var failed_total int
  624. var total_schedule []interface{}
  625. var patients []*models.Patients
  626. patients, _, _ = service.GetAllPatientList(this.GetAdminUserInfo().CurrentOrgId)
  627. if dataBody["failed_schedule"] != nil || reflect.TypeOf(dataBody["failed_schedule"]).String() == "[]interface {}" {
  628. tempSchedule := dataBody["failed_schedule"].([]interface{})
  629. failed_total = len(tempSchedule)
  630. }
  631. if dataBody["schedule"] != nil || reflect.TypeOf(dataBody["schedule"]).String() == "[]interface {}" {
  632. tempSchedule := dataBody["schedule"].([]interface{})
  633. total_schedule = tempSchedule
  634. for _, schMap := range tempSchedule {
  635. schMapM := schMap.(map[string]interface{})
  636. var sch models.Schedule
  637. if schMapM["name"] == nil || reflect.TypeOf(schMapM["name"]).String() != "string" {
  638. utils.ErrorLog("name")
  639. return
  640. }
  641. name, _ := schMapM["name"].(string)
  642. fmt.Println(name)
  643. if len(name) == 0 { //名字为空则生成一条导入错误日志
  644. err_log := models.ExportErrLog{
  645. LogType: 2,
  646. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  647. ErrMsg: "第" + strconv.FormatInt(int64(schMapM["index"].(float64)), 10) + "行,第" + schMapM["row"].(string) + "列的姓名不能为空",
  648. Status: 1,
  649. CreateTime: time.Now().Unix(),
  650. UpdateTime: time.Now().Unix(),
  651. ExportTime: export_time,
  652. }
  653. service.CreateExportErrLog(&err_log)
  654. continue
  655. } else {
  656. var patient []*models.Patients
  657. for _, item := range patients {
  658. if strings.Replace(item.Name, " ", "", -1) == name {
  659. patient = append(patient, item)
  660. }
  661. }
  662. if len(patient) == 0 { //错误日志
  663. err_log := models.ExportErrLog{
  664. LogType: 2,
  665. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  666. ErrMsg: "第" + strconv.FormatInt(int64(schMapM["index"].(float64)), 10) + "行,第" + schMapM["row"].(string) + "列,患者姓名为\"" + name + "\"在系统中不存在,请在系统中添加该患者",
  667. Status: 1,
  668. CreateTime: time.Now().Unix(),
  669. UpdateTime: time.Now().Unix(),
  670. ExportTime: export_time,
  671. }
  672. service.CreateExportErrLog(&err_log)
  673. continue
  674. } else if len(patient) == 1 { //
  675. sch.PatientId = patient[0].ID
  676. } else if len(patient) > 1 { //出现同名的情况
  677. err_log := models.ExportErrLog{
  678. LogType: 2,
  679. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  680. //ErrMsg: "第" + strconv.FormatInt(int64(schMapM["index"].(float64)), 10) + "行,第" + schMapM["row"].(string) + "列" + "患者姓名为" + name + "在当前机构中存在重名,无法确定到具体患者",
  681. ErrMsg: "第" + strconv.FormatInt(int64(schMapM["index"].(float64)), 10) + "行,第" + schMapM["row"].(string) + "列,患者姓名为\"" + name + "\"在在当前机构中存在重名,无法确定到具体患者",
  682. Status: 1,
  683. CreateTime: time.Now().Unix(),
  684. UpdateTime: time.Now().Unix(),
  685. ExportTime: export_time,
  686. }
  687. service.CreateExportErrLog(&err_log)
  688. continue
  689. }
  690. }
  691. if schMapM["schedule_type"] == nil && reflect.TypeOf(schMapM["schedule_type"]).String() != "float64" {
  692. utils.ErrorLog("schedule_type")
  693. return
  694. }
  695. schedule_type := int64(schMapM["schedule_type"].(float64))
  696. if schedule_type <= 0 { //班次格式有误,插入日志
  697. log := models.ExportLog{
  698. LogType: 2,
  699. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  700. TotalNum: int64(len(total_schedule) + failed_total),
  701. FailNum: 1 + int64(failed_total),
  702. SuccessNum: int64(len(schedules)),
  703. CreateTime: time.Now().Unix(),
  704. UpdateTime: time.Now().Unix(),
  705. ExportTime: export_time,
  706. Status: 1,
  707. }
  708. service.CreateExportLog(&log)
  709. err_log := models.ExportErrLog{
  710. LogType: 2,
  711. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  712. ErrMsg: "第2行第" + schMapM["row"].(string) + "列的班次格式有误",
  713. Status: 1,
  714. CreateTime: time.Now().Unix(),
  715. UpdateTime: time.Now().Unix(),
  716. ExportTime: export_time,
  717. }
  718. service.CreateExportErrLog(&err_log)
  719. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeExportError)
  720. return
  721. } else {
  722. sch.ScheduleType = schedule_type
  723. }
  724. if schMapM["partition_name"] == nil || reflect.TypeOf(schMapM["partition_name"]).String() != "string" {
  725. utils.ErrorLog("partition_name")
  726. return
  727. }
  728. partition_name, _ := schMapM["partition_name"].(string)
  729. if len(partition_name) == 0 { //分区为空
  730. log := models.ExportLog{
  731. LogType: 2,
  732. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  733. TotalNum: int64(len(total_schedule) + failed_total),
  734. FailNum: 1 + int64(failed_total),
  735. SuccessNum: int64(len(schedules)),
  736. CreateTime: time.Now().Unix(),
  737. UpdateTime: time.Now().Unix(),
  738. ExportTime: export_time,
  739. Status: 1,
  740. }
  741. service.CreateExportLog(&log)
  742. err_log := models.ExportErrLog{
  743. LogType: 2,
  744. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  745. //ErrMsg: "第" + strconv.FormatInt(int64(schMapM["index"].(float64)) ,10)+ "行" + "的姓名不能为空",
  746. ErrMsg: "第" + strconv.FormatInt(int64(schMapM["index"].(float64)), 10) + "行第1列所属的分区格式有误",
  747. Status: 1,
  748. CreateTime: time.Now().Unix(),
  749. UpdateTime: time.Now().Unix(),
  750. ExportTime: export_time,
  751. }
  752. service.CreateExportErrLog(&err_log)
  753. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeExportError)
  754. return
  755. } else {
  756. zone, err := service.FindDeviceZoneByName(partition_name, this.GetAdminUserInfo().CurrentOrgId)
  757. if err == nil {
  758. sch.PartitionId = zone.ID
  759. } else if err == gorm.ErrRecordNotFound { //查不到数据,插入错误日志
  760. log := models.ExportLog{
  761. LogType: 2,
  762. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  763. TotalNum: int64(len(total_schedule) + failed_total),
  764. FailNum: 1 + int64(failed_total),
  765. SuccessNum: int64(len(schedules)),
  766. CreateTime: time.Now().Unix(),
  767. UpdateTime: time.Now().Unix(),
  768. ExportTime: export_time,
  769. Status: 1,
  770. }
  771. service.CreateExportLog(&log)
  772. err_log := models.ExportErrLog{
  773. LogType: 2,
  774. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  775. //ErrMsg: "第" + strconv.FormatInt(int64(schMapM["index"].(float64)) ,10)+ "行" + "的姓名不能为空",
  776. ErrMsg: "第" + strconv.FormatInt(int64(schMapM["index"].(float64)), 10) + "行第1列所属的分区格式有误",
  777. Status: 1,
  778. CreateTime: time.Now().Unix(),
  779. UpdateTime: time.Now().Unix(),
  780. ExportTime: export_time,
  781. }
  782. service.CreateExportErrLog(&err_log)
  783. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeExportError)
  784. return
  785. }
  786. }
  787. if schMapM["device_number_name"] == nil || reflect.TypeOf(schMapM["device_number_name"]).String() != "string" {
  788. utils.ErrorLog("device_number_name")
  789. return
  790. }
  791. device_number_name, _ := schMapM["device_number_name"].(string)
  792. if len(device_number_name) == 0 { //分区为空
  793. log := models.ExportLog{
  794. LogType: 2,
  795. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  796. TotalNum: int64(len(total_schedule) + failed_total),
  797. FailNum: 1 + int64(failed_total),
  798. SuccessNum: int64(len(schedules)),
  799. CreateTime: time.Now().Unix(),
  800. UpdateTime: time.Now().Unix(),
  801. ExportTime: export_time,
  802. Status: 1,
  803. }
  804. service.CreateExportLog(&log)
  805. err_log := models.ExportErrLog{
  806. LogType: 2,
  807. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  808. //ErrMsg: "第" + strconv.FormatInt(int64(schMapM["index"].(float64)) ,10)+ "行" + "的姓名不能为空",
  809. ErrMsg: "第" + strconv.FormatInt(int64(schMapM["index"].(float64)), 10) + "行第2列机号格式有误",
  810. Status: 1,
  811. CreateTime: time.Now().Unix(),
  812. UpdateTime: time.Now().Unix(),
  813. ExportTime: export_time,
  814. }
  815. service.CreateExportErrLog(&err_log)
  816. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeExportError)
  817. return
  818. } else {
  819. device, err := service.FindDeviceByName(device_number_name, this.GetAdminUserInfo().CurrentOrgId, sch.PartitionId)
  820. if err == nil {
  821. if len(device) == 0 { //没查到数据,插入错误日志
  822. log := models.ExportLog{
  823. LogType: 2,
  824. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  825. TotalNum: int64(len(total_schedule) + failed_total),
  826. FailNum: 1 + int64(failed_total),
  827. SuccessNum: int64(len(schedules)),
  828. CreateTime: time.Now().Unix(),
  829. UpdateTime: time.Now().Unix(),
  830. ExportTime: export_time,
  831. Status: 1,
  832. }
  833. service.CreateExportLog(&log)
  834. err_log := models.ExportErrLog{
  835. LogType: 2,
  836. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  837. ErrMsg: "第" + strconv.FormatInt(int64(schMapM["index"].(float64)), 10) + "行第2列机号格式有误",
  838. Status: 1,
  839. CreateTime: time.Now().Unix(),
  840. UpdateTime: time.Now().Unix(),
  841. ExportTime: export_time,
  842. }
  843. service.CreateExportErrLog(&err_log)
  844. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeExportError)
  845. return
  846. } else if len(device) == 1 {
  847. sch.BedId = device[0].ID
  848. } else if len(device) > 1 { //出现重名,插入错误日志
  849. log := models.ExportLog{
  850. LogType: 2,
  851. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  852. TotalNum: int64(len(total_schedule) + failed_total),
  853. FailNum: 1 + int64(failed_total),
  854. SuccessNum: int64(len(schedules)),
  855. CreateTime: time.Now().Unix(),
  856. UpdateTime: time.Now().Unix(),
  857. ExportTime: export_time,
  858. Status: 1,
  859. }
  860. service.CreateExportLog(&log)
  861. err_log := models.ExportErrLog{
  862. LogType: 2,
  863. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  864. ErrMsg: "出现两个床位号相同的床位",
  865. Status: 1,
  866. CreateTime: time.Now().Unix(),
  867. UpdateTime: time.Now().Unix(),
  868. ExportTime: export_time,
  869. }
  870. service.CreateExportErrLog(&err_log)
  871. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeExportError)
  872. return
  873. }
  874. }
  875. }
  876. if schMapM["schedule_week"] == nil || reflect.TypeOf(schMapM["schedule_week"]).String() != "string" {
  877. utils.ErrorLog("schedule_week")
  878. return
  879. }
  880. schedule_week, _ := schMapM["schedule_week"].(string)
  881. if len(schedule_week) == 0 { //周几为空则生成一条导入错误日志
  882. log := models.ExportLog{
  883. LogType: 2,
  884. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  885. TotalNum: int64(len(total_schedule) + failed_total),
  886. FailNum: 1 + int64(failed_total),
  887. SuccessNum: int64(len(schedules)),
  888. CreateTime: time.Now().Unix(),
  889. UpdateTime: time.Now().Unix(),
  890. ExportTime: export_time,
  891. Status: 1,
  892. }
  893. service.CreateExportLog(&log)
  894. err_log := models.ExportErrLog{
  895. LogType: 2,
  896. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  897. //ErrMsg: "第" + strconv.FormatInt(int64(schMapM["index"].(float64)) ,10)+ "行" + "的姓名不能为空",
  898. ErrMsg: "第1行第" + schMapM["row"].(string) + "列的星期名格式有误",
  899. Status: 1,
  900. CreateTime: time.Now().Unix(),
  901. UpdateTime: time.Now().Unix(),
  902. ExportTime: export_time,
  903. }
  904. service.CreateExportErrLog(&err_log)
  905. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeExportError)
  906. return
  907. } else if schedule_week == "0" { //周几不符合格式则生成一条导入错误日志
  908. log := models.ExportLog{
  909. LogType: 2,
  910. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  911. TotalNum: int64(len(total_schedule) + failed_total),
  912. FailNum: 1 + int64(failed_total),
  913. SuccessNum: int64(len(schedules)),
  914. CreateTime: time.Now().Unix(),
  915. UpdateTime: time.Now().Unix(),
  916. ExportTime: export_time,
  917. Status: 1,
  918. }
  919. service.CreateExportLog(&log)
  920. err_log := models.ExportErrLog{
  921. LogType: 2,
  922. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  923. ErrMsg: "第1行第" + schMapM["row"].(string) + "列的星期名格式有误",
  924. Status: 1,
  925. CreateTime: time.Now().Unix(),
  926. UpdateTime: time.Now().Unix(),
  927. ExportTime: export_time,
  928. }
  929. service.CreateExportErrLog(&err_log)
  930. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeExportError)
  931. return
  932. } else {
  933. schedule_week, _ := strconv.ParseInt(schedule_week, 10, 64)
  934. sch.ScheduleWeek = schedule_week
  935. }
  936. if schMapM["schedule_date"] == nil || reflect.TypeOf(schMapM["schedule_date"]).String() != "string" {
  937. utils.ErrorLog("schedule_date")
  938. return
  939. }
  940. schedule_date, _ := schMapM["schedule_date"].(string)
  941. if len(schedule_date) == 0 { //周几为空则生成一条导入错误日志
  942. log := models.ExportLog{
  943. LogType: 2,
  944. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  945. TotalNum: int64(len(total_schedule) + failed_total),
  946. FailNum: 1 + int64(failed_total),
  947. SuccessNum: int64(len(schedules)),
  948. CreateTime: time.Now().Unix(),
  949. UpdateTime: time.Now().Unix(),
  950. ExportTime: export_time,
  951. Status: 1,
  952. }
  953. service.CreateExportLog(&log)
  954. err_log := models.ExportErrLog{
  955. LogType: 2,
  956. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  957. ErrMsg: "第1行第" + schMapM["row"].(string) + "列的星期名格式有误",
  958. Status: 1,
  959. CreateTime: time.Now().Unix(),
  960. UpdateTime: time.Now().Unix(),
  961. ExportTime: export_time,
  962. }
  963. service.CreateExportErrLog(&err_log)
  964. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeExportError)
  965. return
  966. } else if schedule_date == "0" { //周几不符合格式则生成一条导入错误日志
  967. log := models.ExportLog{
  968. LogType: 2,
  969. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  970. TotalNum: int64(len(total_schedule) + failed_total),
  971. FailNum: 1 + int64(failed_total),
  972. SuccessNum: int64(len(schedules)),
  973. CreateTime: time.Now().Unix(),
  974. UpdateTime: time.Now().Unix(),
  975. ExportTime: export_time,
  976. Status: 1,
  977. }
  978. service.CreateExportLog(&log)
  979. err_log := models.ExportErrLog{
  980. LogType: 2,
  981. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  982. ErrMsg: "第1行第" + schMapM["row"].(string) + "列的星期名格式有误",
  983. Status: 1,
  984. CreateTime: time.Now().Unix(),
  985. UpdateTime: time.Now().Unix(),
  986. ExportTime: export_time,
  987. }
  988. service.CreateExportErrLog(&err_log)
  989. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeExportError)
  990. return
  991. } else {
  992. date, _ := utils.ParseTimeStringToTime("2006-01-02", schedule_date)
  993. sch.ScheduleDate = date.Unix()
  994. }
  995. sch.CreatedTime = time.Now().Unix()
  996. sch.UpdatedTime = time.Now().Unix()
  997. sch.ModeId = 1
  998. sch.Status = 1
  999. sch.UserOrgId = this.GetAdminUserInfo().CurrentOrgId
  1000. sch.IsExport = 1
  1001. schedules = append(schedules, &sch)
  1002. }
  1003. errLogs, _ := service.FindSchedualExportLog(this.GetAdminUserInfo().CurrentOrgId, export_time)
  1004. if len(schedules) > 0 {
  1005. schedule_date := time.Now().Format("2006-01-02")
  1006. date, _ := utils.ParseTimeStringToTime("2006-01-02", schedule_date)
  1007. clear_schedule_date := date.Unix() //根据日期去清除,该日期以及未来的排班数据
  1008. err := service.UpdateScheduleStatus(clear_schedule_date, this.GetAdminUserInfo().CurrentOrgId)
  1009. if err == nil {
  1010. for _, item := range schedules {
  1011. service.CreateSchedule(item)
  1012. }
  1013. log := models.ExportLog{
  1014. LogType: 2,
  1015. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  1016. TotalNum: int64(len(total_schedule) + failed_total),
  1017. FailNum: int64(len(errLogs) + failed_total),
  1018. SuccessNum: int64(len(schedules)),
  1019. CreateTime: time.Now().Unix(),
  1020. UpdateTime: time.Now().Unix(),
  1021. ExportTime: export_time,
  1022. Status: 1,
  1023. }
  1024. service.CreateExportLog(&log)
  1025. if failed_total > 0 {
  1026. err_log := models.ExportErrLog{
  1027. LogType: 2,
  1028. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  1029. ErrMsg: "当前日期(" + time.Now().Format("2006-01-02") + " " + GetWeekString(time.Now().Weekday().String()) +
  1030. ")及以前的排班数据" + strconv.FormatInt(int64(failed_total), 10) + "条,不执行导入",
  1031. Status: 1,
  1032. CreateTime: time.Now().Unix(),
  1033. UpdateTime: time.Now().Unix(),
  1034. ExportTime: export_time,
  1035. }
  1036. service.CreateExportErrLog(&err_log)
  1037. }
  1038. this.ServeSuccessJSON(map[string]interface{}{
  1039. "msg": "导入成功",
  1040. "total_num": len(total_schedule) + failed_total,
  1041. "success_num": len(schedules),
  1042. "fail_num": int64(len(errLogs)),
  1043. })
  1044. } else {
  1045. log := models.ExportLog{
  1046. LogType: 2,
  1047. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  1048. TotalNum: int64(len(total_schedule) + failed_total),
  1049. FailNum: int64(len(errLogs) + failed_total),
  1050. SuccessNum: int64(len(schedules)),
  1051. CreateTime: time.Now().Unix(),
  1052. UpdateTime: time.Now().Unix(),
  1053. ExportTime: export_time,
  1054. Status: 1,
  1055. }
  1056. service.CreateExportLog(&log)
  1057. if failed_total > 0 {
  1058. err_log := models.ExportErrLog{
  1059. LogType: 2,
  1060. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  1061. ErrMsg: "当前日期(" + time.Now().Format("2006-01-02") + " " + GetWeekString(time.Now().Weekday().String()) +
  1062. ")及以前的排班数据" + strconv.FormatInt(int64(failed_total), 10) + "条,不执行导入",
  1063. Status: 1,
  1064. CreateTime: time.Now().Unix(),
  1065. UpdateTime: time.Now().Unix(),
  1066. ExportTime: export_time,
  1067. }
  1068. service.CreateExportErrLog(&err_log)
  1069. }
  1070. this.ServeSuccessJSON(map[string]interface{}{
  1071. "msg": "导入成功",
  1072. "total_num": len(total_schedule),
  1073. "success_num": len(schedules),
  1074. "fail_num": int64(len(errLogs)),
  1075. })
  1076. }
  1077. } else {
  1078. log := models.ExportLog{
  1079. LogType: 2,
  1080. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  1081. TotalNum: int64(len(total_schedule) + failed_total),
  1082. FailNum: int64(len(errLogs) + failed_total),
  1083. SuccessNum: int64(len(schedules)),
  1084. CreateTime: time.Now().Unix(),
  1085. UpdateTime: time.Now().Unix(),
  1086. ExportTime: export_time,
  1087. Status: 1,
  1088. }
  1089. service.CreateExportLog(&log)
  1090. if failed_total > 0 {
  1091. err_log := models.ExportErrLog{
  1092. LogType: 2,
  1093. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  1094. ErrMsg: "当前日期(" + time.Now().Format("2006-01-02") + " " + GetWeekString(time.Now().Weekday().String()) +
  1095. ")及以前的排班数据" + strconv.FormatInt(int64(failed_total), 10) + "条,不执行导入",
  1096. Status: 1,
  1097. CreateTime: time.Now().Unix(),
  1098. UpdateTime: time.Now().Unix(),
  1099. ExportTime: export_time,
  1100. }
  1101. service.CreateExportErrLog(&err_log)
  1102. }
  1103. this.ServeSuccessJSON(map[string]interface{}{
  1104. "msg": "导入成功",
  1105. "total_num": len(total_schedule),
  1106. "success_num": len(schedules),
  1107. "fail_num": int64(len(errLogs)),
  1108. })
  1109. }
  1110. }
  1111. }
  1112. func (this *ScheduleApiController) ExportScheduleTemplate() {
  1113. dataBody := make(map[string]interface{}, 0)
  1114. err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
  1115. if err != nil {
  1116. utils.ErrorLog(err.Error())
  1117. return
  1118. }
  1119. utils.ErrorLog("%v", dataBody)
  1120. export_time := time.Now().Unix()
  1121. var schedules []*models.PatientScheduleTemplateItem
  1122. var total_schedule []interface{}
  1123. patients, _, _ := service.GetAllPatientList(this.GetAdminUserInfo().CurrentOrgId)
  1124. if dataBody["schedule"] != nil || reflect.TypeOf(dataBody["schedule"]).String() == "[]interface {}" {
  1125. tempSchedule := dataBody["schedule"].([]interface{})
  1126. total_schedule = tempSchedule
  1127. for _, schMap := range tempSchedule {
  1128. schMapM := schMap.(map[string]interface{})
  1129. var sch models.PatientScheduleTemplateItem
  1130. if schMapM["name"] == nil || reflect.TypeOf(schMapM["name"]).String() != "string" {
  1131. utils.ErrorLog("name")
  1132. return
  1133. }
  1134. name, _ := schMapM["name"].(string)
  1135. fmt.Println(name)
  1136. if len(name) == 0 { //名字为空则生成一条导入错误日志
  1137. err_log := models.ExportErrLog{
  1138. LogType: 3,
  1139. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  1140. ErrMsg: "第" + strconv.FormatInt(int64(schMapM["index"].(float64)), 10) + "行,第" + schMapM["row"].(string) + "列的姓名不能为空",
  1141. Status: 1,
  1142. CreateTime: time.Now().Unix(),
  1143. UpdateTime: time.Now().Unix(),
  1144. ExportTime: export_time,
  1145. }
  1146. service.CreateExportErrLog(&err_log)
  1147. continue
  1148. } else {
  1149. var patient []*models.Patients
  1150. for _, item := range patients {
  1151. if strings.Replace(item.Name, " ", "", -1) == name {
  1152. patient = append(patient, item)
  1153. }
  1154. }
  1155. if len(patient) == 0 { //错误日志
  1156. err_log := models.ExportErrLog{
  1157. LogType: 3,
  1158. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  1159. //ErrMsg: "第" + strconv.FormatInt(int64(schMapM["index"].(float64)), 10) + "行,第" + schMapM["row"].(string) + "列的姓名在系统中不存在,请在系统中添加该病人",
  1160. ErrMsg: "第" + strconv.FormatInt(int64(schMapM["index"].(float64)), 10) + "行,第" + schMapM["row"].(string) + "列患者姓名为\"" + name + "\"在系统中不存在,请在系统中添加该患者",
  1161. Status: 1,
  1162. CreateTime: time.Now().Unix(),
  1163. UpdateTime: time.Now().Unix(),
  1164. ExportTime: export_time,
  1165. }
  1166. service.CreateExportErrLog(&err_log)
  1167. continue
  1168. } else if len(patient) == 1 { //
  1169. sch.PatientID = patient[0].ID
  1170. } else if len(patient) > 1 { //出现同名的情况
  1171. err_log := models.ExportErrLog{
  1172. LogType: 3,
  1173. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  1174. //ErrMsg: "第" + strconv.FormatInt(int64(schMapM["index"].(float64)), 10) + "行,第" + schMapM["row"].(string) + "列" + "患者姓名为" + name + "在当前机构中存在重名,无法确定到具体患者",
  1175. ErrMsg: "第" + strconv.FormatInt(int64(schMapM["index"].(float64)), 10) + "行,第" + schMapM["row"].(string) + "列患者姓名为\"" + name + "\"在当前机构中存在重名,无法确定到具体患者",
  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. }