schedule_api_controller.go 55KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764
  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. //week_type, _ := this.GetInt64("type", 0)
  480. var date *time.Time
  481. if len(dateStr) == 0 {
  482. now := time.Now()
  483. date = &now
  484. } else {
  485. var parseErr error
  486. date, parseErr = utils.ParseTimeStringToTime("2006-01-02", dateStr)
  487. if parseErr != nil {
  488. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  489. return
  490. }
  491. }
  492. adminUserInfo := this.GetAdminUserInfo()
  493. // 获取本周的排班
  494. var monday time.Time
  495. var sunday time.Time
  496. //switch week_type {
  497. //case 1:
  498. monday, sunday = utils.GetMondayAndSundayOfWeekDate(date)
  499. // break
  500. //case 2:
  501. // monday, sunday = utils.GetMondayAndSundayOfNextWeekDate(date)
  502. //
  503. // break
  504. //case 3:
  505. // monday, sunday = utils.GetMondayAndSundayOfNextNextWeekDate(date)
  506. // break
  507. //}
  508. schedules, getScheduleErr := service.GetPrinitWeekSchedules(adminUserInfo.CurrentOrgId, monday.Unix(), sunday.Unix())
  509. if getScheduleErr != nil {
  510. this.ErrorLog("获取周排班失败:%v", getScheduleErr)
  511. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  512. return
  513. }
  514. thisTime := date
  515. weekDay := int(thisTime.Weekday())
  516. if weekDay == 0 {
  517. weekDay = 7
  518. }
  519. weekEnd := 7 - weekDay
  520. weekStart := weekEnd - 6
  521. days := make([]string, 0)
  522. for index := weekStart; index <= weekEnd; index++ {
  523. theDay := thisTime.AddDate(0, 0, index)
  524. days = append(days, theDay.Format("2006-01-02"))
  525. }
  526. this.ServeSuccessJSON(map[string]interface{}{
  527. "schedules": schedules,
  528. "monday": monday.Unix(),
  529. "days": days,
  530. })
  531. }
  532. func (this *ScheduleApiController) UrgentScheduleData() {
  533. schedule_type, _ := this.GetInt("type", 0)
  534. schedule_date := this.GetString("date")
  535. var date *time.Time
  536. if len(schedule_date) == 0 {
  537. now := time.Now()
  538. date = &now
  539. } else {
  540. var parseErr error
  541. date, parseErr = utils.ParseTimeStringToTime("2006-01-02", schedule_date)
  542. if parseErr != nil {
  543. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  544. return
  545. }
  546. }
  547. adminUserInfo := this.GetAdminUserInfo()
  548. deviceNumbers, getDeviceNumbersErr := service.MobileGetAllDeviceNumbersForUrgentSchedule(adminUserInfo.CurrentOrgId, date.Unix(), schedule_type)
  549. if getDeviceNumbersErr != nil {
  550. this.ErrorLog("获取所有床位失败:%v", getDeviceNumbersErr)
  551. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  552. return
  553. }
  554. // today := utils.ZeroHourTimeOfDay(time.Now())
  555. schedules, getSchedulesErr := service.MobileGetOtherSchedulesForUrgentSchedule(adminUserInfo.CurrentOrgId, date.Unix(), schedule_type)
  556. if getSchedulesErr != nil {
  557. this.ErrorLog("获取所有排班失败:%v", getSchedulesErr)
  558. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  559. return
  560. }
  561. this.ServeSuccessJSON(map[string]interface{}{
  562. "device_numbers": deviceNumbers,
  563. "schedules": schedules,
  564. })
  565. }
  566. func (this *ScheduleApiController) SearchSchedulePatients() {
  567. keywords := this.GetString("keywords")
  568. adminUserInfo := this.GetAdminUserInfo()
  569. list, _ := service.GetSchedualPatientsByKeywords(keywords, adminUserInfo.CurrentOrgId)
  570. this.ServeSuccessJSON(map[string]interface{}{
  571. "schdules": list,
  572. })
  573. }
  574. func (this *ScheduleApiController) GetWeekDaySchedule() {
  575. week_type, _ := this.GetInt64("week_type", -1)
  576. fmt.Println(week_type)
  577. thisTime := time.Now()
  578. weekDay := int(thisTime.Weekday())
  579. if weekDay == 0 {
  580. weekDay = 7
  581. }
  582. weekEnd := 7 - weekDay
  583. weekStart := weekEnd - 6
  584. weekTitle := make([]string, 0)
  585. days := make([]string, 0)
  586. for index := weekStart; index <= weekEnd; index++ {
  587. theDay := thisTime.AddDate(0, 0, index)
  588. indexYear, indexMonthTime, indexDay := theDay.Date()
  589. indexMonth := int(indexMonthTime)
  590. indexWeek := strconv.Itoa(indexYear) + "." + strconv.Itoa(indexMonth) + "." + strconv.Itoa(indexDay)
  591. weekTitle = append(weekTitle, indexWeek)
  592. days = append(days, theDay.Format("2006-01-02"))
  593. }
  594. fmt.Println(days)
  595. var targetDayStr string
  596. switch week_type {
  597. case 1:
  598. targetDayStr = days[0]
  599. break
  600. case 2:
  601. targetDayStr = days[1]
  602. break
  603. case 3:
  604. targetDayStr = days[2]
  605. break
  606. case 4:
  607. targetDayStr = days[3]
  608. break
  609. case 5:
  610. targetDayStr = days[4]
  611. break
  612. case 6:
  613. targetDayStr = days[5]
  614. break
  615. case 7:
  616. targetDayStr = days[6]
  617. break
  618. }
  619. targetDay, parseErr := utils.ParseTimeStringToTime("2006-01-02", targetDayStr)
  620. if parseErr != nil {
  621. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  622. return
  623. }
  624. adminUserInfo := this.GetAdminUserInfo()
  625. list, _ := service.GetWeekDaySchedule(adminUserInfo.CurrentOrgId, targetDay.Unix(), targetDay)
  626. this.ServeSuccessJSON(map[string]interface{}{
  627. "schdules": list,
  628. "day": targetDayStr,
  629. })
  630. }
  631. func Struct2Map(obj interface{}) map[string]interface{} {
  632. t := reflect.TypeOf(obj)
  633. v := reflect.ValueOf(obj)
  634. var data = make(map[string]interface{})
  635. for i := 0; i < t.NumField(); i++ {
  636. data[t.Field(i).Name] = v.Field(i).Interface()
  637. }
  638. return data
  639. }
  640. func (this *ScheduleApiController) ExportSchedule() {
  641. dataBody := make(map[string]interface{}, 0)
  642. err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
  643. if err != nil {
  644. utils.ErrorLog(err.Error())
  645. return
  646. }
  647. utils.ErrorLog("%v", dataBody)
  648. export_time := time.Now().Unix()
  649. var schedules []*models.Schedule
  650. var failed_total int
  651. var total_schedule []interface{}
  652. var patients []*models.Patients
  653. patients, _, _ = service.GetAllPatientList(this.GetAdminUserInfo().CurrentOrgId)
  654. if dataBody["failed_schedule"] != nil || reflect.TypeOf(dataBody["failed_schedule"]).String() == "[]interface {}" {
  655. tempSchedule := dataBody["failed_schedule"].([]interface{})
  656. failed_total = len(tempSchedule)
  657. }
  658. if dataBody["schedule"] != nil || reflect.TypeOf(dataBody["schedule"]).String() == "[]interface {}" {
  659. tempSchedule := dataBody["schedule"].([]interface{})
  660. total_schedule = tempSchedule
  661. for _, schMap := range tempSchedule {
  662. schMapM := schMap.(map[string]interface{})
  663. var sch models.Schedule
  664. if schMapM["name"] == nil || reflect.TypeOf(schMapM["name"]).String() != "string" {
  665. utils.ErrorLog("name")
  666. return
  667. }
  668. name, _ := schMapM["name"].(string)
  669. fmt.Println(name)
  670. if len(name) == 0 { //名字为空则生成一条导入错误日志
  671. err_log := models.ExportErrLog{
  672. LogType: 2,
  673. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  674. ErrMsg: "第" + strconv.FormatInt(int64(schMapM["index"].(float64)), 10) + "行,第" + schMapM["row"].(string) + "列的姓名不能为空",
  675. Status: 1,
  676. CreateTime: time.Now().Unix(),
  677. UpdateTime: time.Now().Unix(),
  678. ExportTime: export_time,
  679. }
  680. service.CreateExportErrLog(&err_log)
  681. continue
  682. } else {
  683. var patient []*models.Patients
  684. for _, item := range patients {
  685. if strings.Replace(item.Name, " ", "", -1) == name {
  686. patient = append(patient, item)
  687. }
  688. }
  689. if len(patient) == 0 { //错误日志
  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. Status: 1,
  695. CreateTime: time.Now().Unix(),
  696. UpdateTime: time.Now().Unix(),
  697. ExportTime: export_time,
  698. }
  699. service.CreateExportErrLog(&err_log)
  700. continue
  701. } else if len(patient) == 1 { //
  702. sch.PatientId = patient[0].ID
  703. } else if len(patient) > 1 { //出现同名的情况
  704. err_log := models.ExportErrLog{
  705. LogType: 2,
  706. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  707. //ErrMsg: "第" + strconv.FormatInt(int64(schMapM["index"].(float64)), 10) + "行,第" + schMapM["row"].(string) + "列" + "患者姓名为" + name + "在当前机构中存在重名,无法确定到具体患者",
  708. ErrMsg: "第" + strconv.FormatInt(int64(schMapM["index"].(float64)), 10) + "行,第" + schMapM["row"].(string) + "列,患者姓名为\"" + name + "\"在在当前机构中存在重名,无法确定到具体患者",
  709. Status: 1,
  710. CreateTime: time.Now().Unix(),
  711. UpdateTime: time.Now().Unix(),
  712. ExportTime: export_time,
  713. }
  714. service.CreateExportErrLog(&err_log)
  715. continue
  716. }
  717. }
  718. if schMapM["schedule_type"] == nil && reflect.TypeOf(schMapM["schedule_type"]).String() != "float64" {
  719. utils.ErrorLog("schedule_type")
  720. return
  721. }
  722. schedule_type := int64(schMapM["schedule_type"].(float64))
  723. if schedule_type <= 0 { //班次格式有误,插入日志
  724. log := models.ExportLog{
  725. LogType: 2,
  726. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  727. TotalNum: int64(len(total_schedule) + failed_total),
  728. FailNum: 1 + int64(failed_total),
  729. SuccessNum: int64(len(schedules)),
  730. CreateTime: time.Now().Unix(),
  731. UpdateTime: time.Now().Unix(),
  732. ExportTime: export_time,
  733. Status: 1,
  734. }
  735. service.CreateExportLog(&log)
  736. err_log := models.ExportErrLog{
  737. LogType: 2,
  738. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  739. ErrMsg: "第2行第" + schMapM["row"].(string) + "列的班次格式有误",
  740. Status: 1,
  741. CreateTime: time.Now().Unix(),
  742. UpdateTime: time.Now().Unix(),
  743. ExportTime: export_time,
  744. }
  745. service.CreateExportErrLog(&err_log)
  746. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeExportError)
  747. return
  748. } else {
  749. sch.ScheduleType = schedule_type
  750. }
  751. if schMapM["partition_name"] == nil || reflect.TypeOf(schMapM["partition_name"]).String() != "string" {
  752. utils.ErrorLog("partition_name")
  753. return
  754. }
  755. partition_name, _ := schMapM["partition_name"].(string)
  756. if len(partition_name) == 0 { //分区为空
  757. log := models.ExportLog{
  758. LogType: 2,
  759. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  760. TotalNum: int64(len(total_schedule) + failed_total),
  761. FailNum: 1 + int64(failed_total),
  762. SuccessNum: int64(len(schedules)),
  763. CreateTime: time.Now().Unix(),
  764. UpdateTime: time.Now().Unix(),
  765. ExportTime: export_time,
  766. Status: 1,
  767. }
  768. service.CreateExportLog(&log)
  769. err_log := models.ExportErrLog{
  770. LogType: 2,
  771. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  772. //ErrMsg: "第" + strconv.FormatInt(int64(schMapM["index"].(float64)) ,10)+ "行" + "的姓名不能为空",
  773. ErrMsg: "第" + strconv.FormatInt(int64(schMapM["index"].(float64)), 10) + "行第1列所属的分区格式有误",
  774. Status: 1,
  775. CreateTime: time.Now().Unix(),
  776. UpdateTime: time.Now().Unix(),
  777. ExportTime: export_time,
  778. }
  779. service.CreateExportErrLog(&err_log)
  780. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeExportError)
  781. return
  782. } else {
  783. zone, err := service.FindDeviceZoneByName(partition_name, this.GetAdminUserInfo().CurrentOrgId)
  784. if err == nil {
  785. sch.PartitionId = zone.ID
  786. } else if err == gorm.ErrRecordNotFound { //查不到数据,插入错误日志
  787. log := models.ExportLog{
  788. LogType: 2,
  789. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  790. TotalNum: int64(len(total_schedule) + failed_total),
  791. FailNum: 1 + int64(failed_total),
  792. SuccessNum: int64(len(schedules)),
  793. CreateTime: time.Now().Unix(),
  794. UpdateTime: time.Now().Unix(),
  795. ExportTime: export_time,
  796. Status: 1,
  797. }
  798. service.CreateExportLog(&log)
  799. err_log := models.ExportErrLog{
  800. LogType: 2,
  801. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  802. //ErrMsg: "第" + strconv.FormatInt(int64(schMapM["index"].(float64)) ,10)+ "行" + "的姓名不能为空",
  803. ErrMsg: "第" + strconv.FormatInt(int64(schMapM["index"].(float64)), 10) + "行第1列所属的分区格式有误",
  804. Status: 1,
  805. CreateTime: time.Now().Unix(),
  806. UpdateTime: time.Now().Unix(),
  807. ExportTime: export_time,
  808. }
  809. service.CreateExportErrLog(&err_log)
  810. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeExportError)
  811. return
  812. }
  813. }
  814. if schMapM["device_number_name"] == nil || reflect.TypeOf(schMapM["device_number_name"]).String() != "string" {
  815. utils.ErrorLog("device_number_name")
  816. return
  817. }
  818. device_number_name, _ := schMapM["device_number_name"].(string)
  819. if len(device_number_name) == 0 { //分区为空
  820. log := models.ExportLog{
  821. LogType: 2,
  822. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  823. TotalNum: int64(len(total_schedule) + failed_total),
  824. FailNum: 1 + int64(failed_total),
  825. SuccessNum: int64(len(schedules)),
  826. CreateTime: time.Now().Unix(),
  827. UpdateTime: time.Now().Unix(),
  828. ExportTime: export_time,
  829. Status: 1,
  830. }
  831. service.CreateExportLog(&log)
  832. err_log := models.ExportErrLog{
  833. LogType: 2,
  834. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  835. //ErrMsg: "第" + strconv.FormatInt(int64(schMapM["index"].(float64)) ,10)+ "行" + "的姓名不能为空",
  836. ErrMsg: "第" + strconv.FormatInt(int64(schMapM["index"].(float64)), 10) + "行第2列机号格式有误",
  837. Status: 1,
  838. CreateTime: time.Now().Unix(),
  839. UpdateTime: time.Now().Unix(),
  840. ExportTime: export_time,
  841. }
  842. service.CreateExportErrLog(&err_log)
  843. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeExportError)
  844. return
  845. } else {
  846. device, err := service.FindDeviceByName(device_number_name, this.GetAdminUserInfo().CurrentOrgId, sch.PartitionId)
  847. if err == nil {
  848. if len(device) == 0 { //没查到数据,插入错误日志
  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: "第" + strconv.FormatInt(int64(schMapM["index"].(float64)), 10) + "行第2列机号格式有误",
  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. } else if len(device) == 1 {
  874. sch.BedId = device[0].ID
  875. } else if len(device) > 1 { //出现重名,插入错误日志
  876. log := models.ExportLog{
  877. LogType: 2,
  878. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  879. TotalNum: int64(len(total_schedule) + failed_total),
  880. FailNum: 1 + int64(failed_total),
  881. SuccessNum: int64(len(schedules)),
  882. CreateTime: time.Now().Unix(),
  883. UpdateTime: time.Now().Unix(),
  884. ExportTime: export_time,
  885. Status: 1,
  886. }
  887. service.CreateExportLog(&log)
  888. err_log := models.ExportErrLog{
  889. LogType: 2,
  890. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  891. ErrMsg: "出现两个床位号相同的床位",
  892. Status: 1,
  893. CreateTime: time.Now().Unix(),
  894. UpdateTime: time.Now().Unix(),
  895. ExportTime: export_time,
  896. }
  897. service.CreateExportErrLog(&err_log)
  898. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeExportError)
  899. return
  900. }
  901. }
  902. }
  903. if schMapM["schedule_week"] == nil || reflect.TypeOf(schMapM["schedule_week"]).String() != "string" {
  904. utils.ErrorLog("schedule_week")
  905. return
  906. }
  907. schedule_week, _ := schMapM["schedule_week"].(string)
  908. if len(schedule_week) == 0 { //周几为空则生成一条导入错误日志
  909. log := models.ExportLog{
  910. LogType: 2,
  911. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  912. TotalNum: int64(len(total_schedule) + failed_total),
  913. FailNum: 1 + int64(failed_total),
  914. SuccessNum: int64(len(schedules)),
  915. CreateTime: time.Now().Unix(),
  916. UpdateTime: time.Now().Unix(),
  917. ExportTime: export_time,
  918. Status: 1,
  919. }
  920. service.CreateExportLog(&log)
  921. err_log := models.ExportErrLog{
  922. LogType: 2,
  923. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  924. //ErrMsg: "第" + strconv.FormatInt(int64(schMapM["index"].(float64)) ,10)+ "行" + "的姓名不能为空",
  925. ErrMsg: "第1行第" + schMapM["row"].(string) + "列的星期名格式有误",
  926. Status: 1,
  927. CreateTime: time.Now().Unix(),
  928. UpdateTime: time.Now().Unix(),
  929. ExportTime: export_time,
  930. }
  931. service.CreateExportErrLog(&err_log)
  932. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeExportError)
  933. return
  934. } else if schedule_week == "0" { //周几不符合格式则生成一条导入错误日志
  935. log := models.ExportLog{
  936. LogType: 2,
  937. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  938. TotalNum: int64(len(total_schedule) + failed_total),
  939. FailNum: 1 + int64(failed_total),
  940. SuccessNum: int64(len(schedules)),
  941. CreateTime: time.Now().Unix(),
  942. UpdateTime: time.Now().Unix(),
  943. ExportTime: export_time,
  944. Status: 1,
  945. }
  946. service.CreateExportLog(&log)
  947. err_log := models.ExportErrLog{
  948. LogType: 2,
  949. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  950. ErrMsg: "第1行第" + schMapM["row"].(string) + "列的星期名格式有误",
  951. Status: 1,
  952. CreateTime: time.Now().Unix(),
  953. UpdateTime: time.Now().Unix(),
  954. ExportTime: export_time,
  955. }
  956. service.CreateExportErrLog(&err_log)
  957. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeExportError)
  958. return
  959. } else {
  960. schedule_week, _ := strconv.ParseInt(schedule_week, 10, 64)
  961. sch.ScheduleWeek = schedule_week
  962. }
  963. if schMapM["schedule_date"] == nil || reflect.TypeOf(schMapM["schedule_date"]).String() != "string" {
  964. utils.ErrorLog("schedule_date")
  965. return
  966. }
  967. schedule_date, _ := schMapM["schedule_date"].(string)
  968. if len(schedule_date) == 0 { //周几为空则生成一条导入错误日志
  969. log := models.ExportLog{
  970. LogType: 2,
  971. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  972. TotalNum: int64(len(total_schedule) + failed_total),
  973. FailNum: 1 + int64(failed_total),
  974. SuccessNum: int64(len(schedules)),
  975. CreateTime: time.Now().Unix(),
  976. UpdateTime: time.Now().Unix(),
  977. ExportTime: export_time,
  978. Status: 1,
  979. }
  980. service.CreateExportLog(&log)
  981. err_log := models.ExportErrLog{
  982. LogType: 2,
  983. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  984. ErrMsg: "第1行第" + schMapM["row"].(string) + "列的星期名格式有误",
  985. Status: 1,
  986. CreateTime: time.Now().Unix(),
  987. UpdateTime: time.Now().Unix(),
  988. ExportTime: export_time,
  989. }
  990. service.CreateExportErrLog(&err_log)
  991. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeExportError)
  992. return
  993. } else if schedule_date == "0" { //周几不符合格式则生成一条导入错误日志
  994. log := models.ExportLog{
  995. LogType: 2,
  996. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  997. TotalNum: int64(len(total_schedule) + failed_total),
  998. FailNum: 1 + int64(failed_total),
  999. SuccessNum: int64(len(schedules)),
  1000. CreateTime: time.Now().Unix(),
  1001. UpdateTime: time.Now().Unix(),
  1002. ExportTime: export_time,
  1003. Status: 1,
  1004. }
  1005. service.CreateExportLog(&log)
  1006. err_log := models.ExportErrLog{
  1007. LogType: 2,
  1008. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  1009. ErrMsg: "第1行第" + schMapM["row"].(string) + "列的星期名格式有误",
  1010. Status: 1,
  1011. CreateTime: time.Now().Unix(),
  1012. UpdateTime: time.Now().Unix(),
  1013. ExportTime: export_time,
  1014. }
  1015. service.CreateExportErrLog(&err_log)
  1016. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeExportError)
  1017. return
  1018. } else {
  1019. date, _ := utils.ParseTimeStringToTime("2006-01-02", schedule_date)
  1020. sch.ScheduleDate = date.Unix()
  1021. }
  1022. sch.CreatedTime = time.Now().Unix()
  1023. sch.UpdatedTime = time.Now().Unix()
  1024. sch.ModeId = 1
  1025. sch.Status = 1
  1026. sch.UserOrgId = this.GetAdminUserInfo().CurrentOrgId
  1027. sch.IsExport = 1
  1028. schedules = append(schedules, &sch)
  1029. }
  1030. errLogs, _ := service.FindSchedualExportLog(this.GetAdminUserInfo().CurrentOrgId, export_time)
  1031. if len(schedules) > 0 {
  1032. schedule_date := time.Now().Format("2006-01-02")
  1033. date, _ := utils.ParseTimeStringToTime("2006-01-02", schedule_date)
  1034. clear_schedule_date := date.Unix() //根据日期去清除,该日期以及未来的排班数据
  1035. err := service.UpdateScheduleStatus(clear_schedule_date, this.GetAdminUserInfo().CurrentOrgId)
  1036. if err == nil {
  1037. for _, item := range schedules {
  1038. service.CreateSchedule(item)
  1039. }
  1040. log := models.ExportLog{
  1041. LogType: 2,
  1042. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  1043. TotalNum: int64(len(total_schedule) + failed_total),
  1044. FailNum: int64(len(errLogs) + failed_total),
  1045. SuccessNum: int64(len(schedules)),
  1046. CreateTime: time.Now().Unix(),
  1047. UpdateTime: time.Now().Unix(),
  1048. ExportTime: export_time,
  1049. Status: 1,
  1050. }
  1051. service.CreateExportLog(&log)
  1052. if failed_total > 0 {
  1053. err_log := models.ExportErrLog{
  1054. LogType: 2,
  1055. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  1056. ErrMsg: "当前日期(" + time.Now().Format("2006-01-02") + " " + GetWeekString(time.Now().Weekday().String()) +
  1057. ")及以前的排班数据" + strconv.FormatInt(int64(failed_total), 10) + "条,不执行导入",
  1058. Status: 1,
  1059. CreateTime: time.Now().Unix(),
  1060. UpdateTime: time.Now().Unix(),
  1061. ExportTime: export_time,
  1062. }
  1063. service.CreateExportErrLog(&err_log)
  1064. }
  1065. this.ServeSuccessJSON(map[string]interface{}{
  1066. "msg": "导入成功",
  1067. "total_num": len(total_schedule) + failed_total,
  1068. "success_num": len(schedules),
  1069. "fail_num": int64(len(errLogs)),
  1070. })
  1071. } else {
  1072. log := models.ExportLog{
  1073. LogType: 2,
  1074. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  1075. TotalNum: int64(len(total_schedule) + failed_total),
  1076. FailNum: int64(len(errLogs) + failed_total),
  1077. SuccessNum: int64(len(schedules)),
  1078. CreateTime: time.Now().Unix(),
  1079. UpdateTime: time.Now().Unix(),
  1080. ExportTime: export_time,
  1081. Status: 1,
  1082. }
  1083. service.CreateExportLog(&log)
  1084. if failed_total > 0 {
  1085. err_log := models.ExportErrLog{
  1086. LogType: 2,
  1087. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  1088. ErrMsg: "当前日期(" + time.Now().Format("2006-01-02") + " " + GetWeekString(time.Now().Weekday().String()) +
  1089. ")及以前的排班数据" + strconv.FormatInt(int64(failed_total), 10) + "条,不执行导入",
  1090. Status: 1,
  1091. CreateTime: time.Now().Unix(),
  1092. UpdateTime: time.Now().Unix(),
  1093. ExportTime: export_time,
  1094. }
  1095. service.CreateExportErrLog(&err_log)
  1096. }
  1097. this.ServeSuccessJSON(map[string]interface{}{
  1098. "msg": "导入成功",
  1099. "total_num": len(total_schedule),
  1100. "success_num": len(schedules),
  1101. "fail_num": int64(len(errLogs)),
  1102. })
  1103. }
  1104. } else {
  1105. log := models.ExportLog{
  1106. LogType: 2,
  1107. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  1108. TotalNum: int64(len(total_schedule) + failed_total),
  1109. FailNum: int64(len(errLogs) + failed_total),
  1110. SuccessNum: int64(len(schedules)),
  1111. CreateTime: time.Now().Unix(),
  1112. UpdateTime: time.Now().Unix(),
  1113. ExportTime: export_time,
  1114. Status: 1,
  1115. }
  1116. service.CreateExportLog(&log)
  1117. if failed_total > 0 {
  1118. err_log := models.ExportErrLog{
  1119. LogType: 2,
  1120. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  1121. ErrMsg: "当前日期(" + time.Now().Format("2006-01-02") + " " + GetWeekString(time.Now().Weekday().String()) +
  1122. ")及以前的排班数据" + strconv.FormatInt(int64(failed_total), 10) + "条,不执行导入",
  1123. Status: 1,
  1124. CreateTime: time.Now().Unix(),
  1125. UpdateTime: time.Now().Unix(),
  1126. ExportTime: export_time,
  1127. }
  1128. service.CreateExportErrLog(&err_log)
  1129. }
  1130. this.ServeSuccessJSON(map[string]interface{}{
  1131. "msg": "导入成功",
  1132. "total_num": len(total_schedule),
  1133. "success_num": len(schedules),
  1134. "fail_num": int64(len(errLogs)),
  1135. })
  1136. }
  1137. }
  1138. }
  1139. func (this *ScheduleApiController) ExportScheduleTemplate() {
  1140. dataBody := make(map[string]interface{}, 0)
  1141. err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
  1142. if err != nil {
  1143. utils.ErrorLog(err.Error())
  1144. return
  1145. }
  1146. utils.ErrorLog("%v", dataBody)
  1147. export_time := time.Now().Unix()
  1148. var schedules []*models.PatientScheduleTemplateItem
  1149. var total_schedule []interface{}
  1150. patients, _, _ := service.GetAllPatientList(this.GetAdminUserInfo().CurrentOrgId)
  1151. if dataBody["schedule"] != nil || reflect.TypeOf(dataBody["schedule"]).String() == "[]interface {}" {
  1152. tempSchedule := dataBody["schedule"].([]interface{})
  1153. total_schedule = tempSchedule
  1154. for _, schMap := range tempSchedule {
  1155. schMapM := schMap.(map[string]interface{})
  1156. var sch models.PatientScheduleTemplateItem
  1157. if schMapM["name"] == nil || reflect.TypeOf(schMapM["name"]).String() != "string" {
  1158. utils.ErrorLog("name")
  1159. return
  1160. }
  1161. name, _ := schMapM["name"].(string)
  1162. fmt.Println(name)
  1163. if len(name) == 0 { //名字为空则生成一条导入错误日志
  1164. err_log := models.ExportErrLog{
  1165. LogType: 3,
  1166. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  1167. ErrMsg: "第" + strconv.FormatInt(int64(schMapM["index"].(float64)), 10) + "行,第" + schMapM["row"].(string) + "列的姓名不能为空",
  1168. Status: 1,
  1169. CreateTime: time.Now().Unix(),
  1170. UpdateTime: time.Now().Unix(),
  1171. ExportTime: export_time,
  1172. }
  1173. service.CreateExportErrLog(&err_log)
  1174. continue
  1175. } else {
  1176. var patient []*models.Patients
  1177. for _, item := range patients {
  1178. if strings.Replace(item.Name, " ", "", -1) == name {
  1179. patient = append(patient, item)
  1180. }
  1181. }
  1182. if len(patient) == 0 { //错误日志
  1183. err_log := models.ExportErrLog{
  1184. LogType: 3,
  1185. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  1186. //ErrMsg: "第" + strconv.FormatInt(int64(schMapM["index"].(float64)), 10) + "行,第" + schMapM["row"].(string) + "列的姓名在系统中不存在,请在系统中添加该病人",
  1187. ErrMsg: "第" + strconv.FormatInt(int64(schMapM["index"].(float64)), 10) + "行,第" + schMapM["row"].(string) + "列患者姓名为\"" + name + "\"在系统中不存在,请在系统中添加该患者",
  1188. Status: 1,
  1189. CreateTime: time.Now().Unix(),
  1190. UpdateTime: time.Now().Unix(),
  1191. ExportTime: export_time,
  1192. }
  1193. service.CreateExportErrLog(&err_log)
  1194. continue
  1195. } else if len(patient) == 1 { //
  1196. sch.PatientID = patient[0].ID
  1197. } else if len(patient) > 1 { //出现同名的情况
  1198. err_log := models.ExportErrLog{
  1199. LogType: 3,
  1200. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  1201. //ErrMsg: "第" + strconv.FormatInt(int64(schMapM["index"].(float64)), 10) + "行,第" + schMapM["row"].(string) + "列" + "患者姓名为" + name + "在当前机构中存在重名,无法确定到具体患者",
  1202. ErrMsg: "第" + strconv.FormatInt(int64(schMapM["index"].(float64)), 10) + "行,第" + schMapM["row"].(string) + "列患者姓名为\"" + name + "\"在当前机构中存在重名,无法确定到具体患者",
  1203. Status: 1,
  1204. CreateTime: time.Now().Unix(),
  1205. UpdateTime: time.Now().Unix(),
  1206. ExportTime: export_time,
  1207. }
  1208. service.CreateExportErrLog(&err_log)
  1209. continue
  1210. }
  1211. }
  1212. if schMapM["schedule_type"] == nil && reflect.TypeOf(schMapM["schedule_type"]).String() != "float64" {
  1213. utils.ErrorLog("schedule_type")
  1214. return
  1215. }
  1216. schedule_type := int64(schMapM["schedule_type"].(float64))
  1217. if schedule_type <= 0 { //班次格式有误,插入日志
  1218. log := models.ExportLog{
  1219. LogType: 3,
  1220. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  1221. TotalNum: int64(len(total_schedule)),
  1222. FailNum: 1,
  1223. SuccessNum: int64(len(schedules)),
  1224. CreateTime: time.Now().Unix(),
  1225. UpdateTime: time.Now().Unix(),
  1226. ExportTime: export_time,
  1227. Status: 1,
  1228. }
  1229. service.CreateExportLog(&log)
  1230. err_log := models.ExportErrLog{
  1231. LogType: 3,
  1232. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  1233. ErrMsg: "第2行第" + schMapM["row"].(string) + "列的班次格式有误",
  1234. Status: 1,
  1235. CreateTime: time.Now().Unix(),
  1236. UpdateTime: time.Now().Unix(),
  1237. ExportTime: export_time,
  1238. }
  1239. service.CreateExportErrLog(&err_log)
  1240. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeExportError)
  1241. return
  1242. } else {
  1243. sch.TimeType = int8(schedule_type)
  1244. }
  1245. if schMapM["template_id"] == nil && reflect.TypeOf(schMapM["template_id"]).String() != "float64" {
  1246. utils.ErrorLog("template_id")
  1247. return
  1248. }
  1249. template_id := int64(schMapM["template_id"].(float64))
  1250. sch.TemplateID = template_id
  1251. if schMapM["device_number_name"] == nil || reflect.TypeOf(schMapM["device_number_name"]).String() != "string" {
  1252. utils.ErrorLog("device_number_name")
  1253. return
  1254. }
  1255. partition_name, _ := schMapM["partition_name"].(string)
  1256. zone, _ := service.FindDeviceZoneByName(partition_name, this.GetAdminUserInfo().CurrentOrgId)
  1257. device_number_name, _ := schMapM["device_number_name"].(string)
  1258. if len(device_number_name) == 0 { //分区为空
  1259. log := models.ExportLog{
  1260. LogType: 3,
  1261. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  1262. TotalNum: int64(len(total_schedule)),
  1263. FailNum: 1,
  1264. SuccessNum: int64(len(schedules)),
  1265. CreateTime: time.Now().Unix(),
  1266. UpdateTime: time.Now().Unix(),
  1267. ExportTime: export_time,
  1268. Status: 1,
  1269. }
  1270. service.CreateExportLog(&log)
  1271. err_log := models.ExportErrLog{
  1272. LogType: 3,
  1273. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  1274. //ErrMsg: "第" + strconv.FormatInt(int64(schMapM["index"].(float64)) ,10)+ "行" + "的姓名不能为空",
  1275. ErrMsg: "第" + strconv.FormatInt(int64(schMapM["index"].(float64)), 10) + "行第2列机号格式有误",
  1276. Status: 1,
  1277. CreateTime: time.Now().Unix(),
  1278. UpdateTime: time.Now().Unix(),
  1279. ExportTime: export_time,
  1280. }
  1281. service.CreateExportErrLog(&err_log)
  1282. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeExportError)
  1283. return
  1284. } else {
  1285. device, err := service.FindDeviceByNameTwo(device_number_name, this.GetAdminUserInfo().CurrentOrgId, zone.ID)
  1286. if err == nil {
  1287. if len(device) == 0 { //没查到数据,插入错误日志
  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: "第" + strconv.FormatInt(int64(schMapM["index"].(float64)), 10) + "行第2列机号格式有误",
  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. } else if len(device) == 1 {
  1313. sch.DeviceNumberID = device[0].ID
  1314. } else if len(device) > 1 { //出现重名,插入错误日志
  1315. log := models.ExportLog{
  1316. LogType: 3,
  1317. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  1318. TotalNum: int64(len(total_schedule)),
  1319. FailNum: 1,
  1320. SuccessNum: int64(len(schedules)),
  1321. CreateTime: time.Now().Unix(),
  1322. UpdateTime: time.Now().Unix(),
  1323. ExportTime: export_time,
  1324. Status: 1,
  1325. }
  1326. service.CreateExportLog(&log)
  1327. err_log := models.ExportErrLog{
  1328. LogType: 3,
  1329. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  1330. ErrMsg: "出现两个床位号相同的床位",
  1331. Status: 1,
  1332. CreateTime: time.Now().Unix(),
  1333. UpdateTime: time.Now().Unix(),
  1334. ExportTime: export_time,
  1335. }
  1336. service.CreateExportErrLog(&err_log)
  1337. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeExportError)
  1338. return
  1339. }
  1340. }
  1341. }
  1342. if schMapM["schedule_week"] == nil || reflect.TypeOf(schMapM["schedule_week"]).String() != "string" {
  1343. utils.ErrorLog("schedule_week")
  1344. return
  1345. }
  1346. schedule_week, _ := schMapM["schedule_week"].(string)
  1347. if len(schedule_week) == 0 { //周几为空则生成一条导入错误日志
  1348. log := models.ExportLog{
  1349. LogType: 3,
  1350. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  1351. TotalNum: int64(len(total_schedule)),
  1352. FailNum: 1,
  1353. SuccessNum: int64(len(schedules)),
  1354. CreateTime: time.Now().Unix(),
  1355. UpdateTime: time.Now().Unix(),
  1356. ExportTime: export_time,
  1357. Status: 1,
  1358. }
  1359. service.CreateExportLog(&log)
  1360. err_log := models.ExportErrLog{
  1361. LogType: 3,
  1362. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  1363. //ErrMsg: "第" + strconv.FormatInt(int64(schMapM["index"].(float64)) ,10)+ "行" + "的姓名不能为空",
  1364. ErrMsg: "第1行第" + schMapM["row"].(string) + "列的星期名格式有误",
  1365. Status: 1,
  1366. CreateTime: time.Now().Unix(),
  1367. UpdateTime: time.Now().Unix(),
  1368. ExportTime: export_time,
  1369. }
  1370. service.CreateExportErrLog(&err_log)
  1371. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeExportError)
  1372. return
  1373. } else if schedule_week == "0" { //周几不符合格式则生成一条导入错误日志
  1374. log := models.ExportLog{
  1375. LogType: 3,
  1376. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  1377. TotalNum: int64(len(total_schedule)),
  1378. FailNum: 1,
  1379. SuccessNum: int64(len(schedules)),
  1380. CreateTime: time.Now().Unix(),
  1381. UpdateTime: time.Now().Unix(),
  1382. ExportTime: export_time,
  1383. Status: 1,
  1384. }
  1385. service.CreateExportLog(&log)
  1386. err_log := models.ExportErrLog{
  1387. LogType: 3,
  1388. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  1389. ErrMsg: "第1行第" + schMapM["row"].(string) + "列的星期名格式有误",
  1390. Status: 1,
  1391. CreateTime: time.Now().Unix(),
  1392. UpdateTime: time.Now().Unix(),
  1393. ExportTime: export_time,
  1394. }
  1395. service.CreateExportErrLog(&err_log)
  1396. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeExportError)
  1397. return
  1398. } else {
  1399. schedule_week, _ := strconv.ParseInt(schedule_week, 10, 64)
  1400. sch.Weekday = int8(schedule_week)
  1401. }
  1402. sch.CreateTime = time.Now().Unix()
  1403. sch.ModifyTime = time.Now().Unix()
  1404. sch.TreatMode = 1
  1405. sch.Status = 1
  1406. sch.OrgID = this.GetAdminUserInfo().CurrentOrgId
  1407. sch.IsExport = 1
  1408. schedules = append(schedules, &sch)
  1409. }
  1410. errLogs, _ := service.FindSchedualTemplateExportLog(this.GetAdminUserInfo().CurrentOrgId, export_time)
  1411. if len(schedules) > 0 {
  1412. err := service.UpdateScheduleTemplateStatus(this.GetAdminUserInfo().CurrentOrgId)
  1413. if err == nil {
  1414. for _, item := range schedules {
  1415. service.CreateScheduleTemplate(item)
  1416. }
  1417. log := models.ExportLog{
  1418. LogType: 3,
  1419. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  1420. TotalNum: int64(len(total_schedule)),
  1421. FailNum: int64(len(errLogs)),
  1422. SuccessNum: int64(len(schedules)),
  1423. CreateTime: time.Now().Unix(),
  1424. UpdateTime: time.Now().Unix(),
  1425. ExportTime: export_time,
  1426. Status: 1,
  1427. }
  1428. service.CreateExportLog(&log)
  1429. this.ServeSuccessJSON(map[string]interface{}{
  1430. "msg": "导入成功",
  1431. "total_num": len(total_schedule),
  1432. "success_num": len(schedules),
  1433. "fail_num": int64(len(errLogs)),
  1434. })
  1435. } else {
  1436. log := models.ExportLog{
  1437. LogType: 3,
  1438. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  1439. TotalNum: int64(len(total_schedule)),
  1440. FailNum: int64(len(errLogs)),
  1441. SuccessNum: int64(len(schedules)),
  1442. CreateTime: time.Now().Unix(),
  1443. UpdateTime: time.Now().Unix(),
  1444. ExportTime: export_time,
  1445. Status: 1,
  1446. }
  1447. service.CreateExportLog(&log)
  1448. this.ServeSuccessJSON(map[string]interface{}{
  1449. "msg": "导入成功",
  1450. "total_num": len(total_schedule),
  1451. "success_num": len(schedules),
  1452. "fail_num": int64(len(errLogs)),
  1453. })
  1454. }
  1455. } else {
  1456. log := models.ExportLog{
  1457. LogType: 3,
  1458. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  1459. TotalNum: int64(len(total_schedule)),
  1460. FailNum: int64(len(errLogs)),
  1461. SuccessNum: int64(len(schedules)),
  1462. CreateTime: time.Now().Unix(),
  1463. UpdateTime: time.Now().Unix(),
  1464. ExportTime: export_time,
  1465. Status: 1,
  1466. }
  1467. service.CreateExportLog(&log)
  1468. this.ServeSuccessJSON(map[string]interface{}{
  1469. "msg": "导入成功",
  1470. "total_num": len(total_schedule),
  1471. "success_num": len(schedules),
  1472. "fail_num": int64(len(errLogs)),
  1473. })
  1474. }
  1475. }
  1476. }
  1477. func (c *ScheduleApiController) GetInitExcelInitDate() {
  1478. thisTime := time.Now()
  1479. thisTime1 := time.Now()
  1480. thisTime2 := time.Now()
  1481. thisTime1 = thisTime1.AddDate(0, 0, 7)
  1482. thisTime2 = thisTime2.AddDate(0, 0, 14)
  1483. weekDay := int(thisTime.Weekday())
  1484. if weekDay == 0 {
  1485. weekDay = 7
  1486. }
  1487. weekEnd := 7 - weekDay
  1488. weekStart := weekEnd - 6
  1489. days := make([]string, 0)
  1490. for index := weekStart; index <= weekEnd; index++ {
  1491. theDay := thisTime.AddDate(0, 0, index)
  1492. days = append(days, theDay.Format("2006-01-02"))
  1493. }
  1494. weekDay1 := int(thisTime1.Weekday())
  1495. if weekDay1 == 0 {
  1496. weekDay1 = 7
  1497. }
  1498. weekEnd1 := 7 - weekDay1
  1499. weekStart1 := weekEnd1 - 6
  1500. for index := weekStart1; index <= weekEnd1; index++ {
  1501. theDay := thisTime1.AddDate(0, 0, index)
  1502. days = append(days, theDay.Format("2006-01-02"))
  1503. }
  1504. weekDay2 := int(thisTime2.Weekday())
  1505. if weekDay2 == 0 {
  1506. weekDay2 = 7
  1507. }
  1508. weekEnd2 := 7 - weekDay2
  1509. weekStart2 := weekEnd2 - 6
  1510. for index := weekStart2; index <= weekEnd2; index++ {
  1511. theDay := thisTime2.AddDate(0, 0, index)
  1512. days = append(days, theDay.Format("2006-01-02"))
  1513. }
  1514. c.ServeSuccessJSON(map[string]interface{}{
  1515. "days": days,
  1516. })
  1517. return
  1518. }
  1519. func GetWeekString(week string) string {
  1520. var weekStr string
  1521. switch week {
  1522. case "Sunday":
  1523. weekStr = "周日"
  1524. break
  1525. case "Monday":
  1526. weekStr = "周一"
  1527. break
  1528. case "Tuesday":
  1529. weekStr = "周二"
  1530. break
  1531. case "Wednesday":
  1532. weekStr = "周三"
  1533. break
  1534. case "Thursday":
  1535. weekStr = "周四"
  1536. break
  1537. case "Friday":
  1538. weekStr = "周五"
  1539. break
  1540. case "Saturday":
  1541. weekStr = "周六"
  1542. break
  1543. default:
  1544. weekStr = ""
  1545. break
  1546. }
  1547. return weekStr
  1548. }