doctor_schedule_api_controller.go 16KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494
  1. package controllers
  2. import (
  3. "XT_New/enums"
  4. "XT_New/models"
  5. "XT_New/service"
  6. "fmt"
  7. "github.com/astaxie/beego"
  8. "github.com/jinzhu/gorm"
  9. "time"
  10. )
  11. type DoctorScheduleApiController struct {
  12. BaseAuthAPIController
  13. }
  14. func DoctorScheduleRouters() {
  15. beego.Router("/api/schedules/savedoctorschedules", &DoctorScheduleApiController{}, "Get:SaveDoctorSchedules")
  16. beego.Router("/api/schedules/getdoctorschedulelist", &DoctorScheduleApiController{}, "Get:GetDoctorScheduleList")
  17. beego.Router("/api/schedules/getscheduledetail", &DoctorScheduleApiController{}, "Get:GetScheduleDetail")
  18. beego.Router("/api/schedules/updateschedule", &DoctorScheduleApiController{}, "Get:UpdateSchedule")
  19. beego.Router("/api/schedule/deleteschedule", &DoctorScheduleApiController{}, "Get:DeleteSchedule")
  20. beego.Router("/api/schedule/getdoctorlist", &DoctorScheduleApiController{}, "Get:GetDoctorList")
  21. beego.Router("/api/schedule/getschedulelist", &DoctorScheduleApiController{}, "Get:GetScheduleList")
  22. beego.Router("/api/schedule/addschedule", &DoctorScheduleApiController{}, "Get:AddSchedule")
  23. beego.Router("/api/schedule/getstaffschedulelist", &DoctorScheduleApiController{}, "Get:GetStaffScheduleList")
  24. beego.Router("/api/schedule/getnextweeklist", &DoctorScheduleApiController{}, "Get:GetNextWeekList")
  25. beego.Router("/api/schedule/getschedulebydoctorid", &DoctorScheduleApiController{}, "Get:GetScheduleByDoctorId")
  26. beego.Router("/api/schedule/tosearchsechedulelist", &DoctorScheduleApiController{}, "Get:ToSearchScheduleList")
  27. beego.Router("api/schedule/deletestaffschedule", &DoctorScheduleApiController{}, "Get:DeleteStaffSchedule")
  28. beego.Router("/api/schedule/copystaffschedule", &DoctorScheduleApiController{}, "Get:CopyStaffSchedule")
  29. beego.Router("/api/scheudle/updatecontinusschedule", &DoctorScheduleApiController{}, "Get:UpdateContinusSchedule")
  30. }
  31. func (this *DoctorScheduleApiController) SaveDoctorSchedules() {
  32. adminUser := this.GetAdminUserInfo()
  33. orgId := adminUser.CurrentOrgId
  34. class_name := this.GetString("class_name")
  35. class_attributes, _ := this.GetInt64("class_attributes")
  36. timeone_start := this.GetString("timeone_start")
  37. timeone_type, _ := this.GetInt64("timeone_type")
  38. timeone_end := this.GetString("timeone_end")
  39. timetwo_start := this.GetString("timetwo_start")
  40. timetwo_type, _ := this.GetInt64("timetwo_type")
  41. timetwo_end := this.GetString("timetwo_end")
  42. work_time := this.GetString("work_time")
  43. remarks := this.GetString("remarks")
  44. schedules := models.DoctorSchedules{
  45. ClassName: class_name,
  46. ClassAttributes: class_attributes,
  47. TimeoneStart: timeone_start,
  48. TimeoneType: timeone_type,
  49. TimeoneEnd: timeone_end,
  50. TimetwoStart: timetwo_start,
  51. TimetwoEnd: timetwo_end,
  52. TimetwoType: timetwo_type,
  53. WorkTime: work_time,
  54. Remarks: remarks,
  55. UserOrgId: orgId,
  56. Status: 1,
  57. Ctime: time.Now().Unix(),
  58. }
  59. //查询班种名称是否存在
  60. _, errcode := service.GetClassName(orgId, class_name)
  61. //如果不存在
  62. if errcode == gorm.ErrRecordNotFound {
  63. err := service.CreateDotorSchedule(&schedules)
  64. if err != nil {
  65. this.ServeFailJsonSend(enums.ErrorCodeDataException, "添加设备失败")
  66. return
  67. }
  68. this.ServeSuccessJSON(map[string]interface{}{
  69. "schedules": schedules,
  70. })
  71. } else if errcode == nil {
  72. this.ServeFailJsonSend(enums.ErrorCodeDataException, "班种名称已存在")
  73. return
  74. }
  75. }
  76. func (this *DoctorScheduleApiController) GetDoctorScheduleList() {
  77. adminUserInfo := this.GetAdminUserInfo()
  78. orgId := adminUserInfo.CurrentOrgId
  79. page, _ := this.GetInt64("page")
  80. limit, _ := this.GetInt64("limit")
  81. schedules, total, err := service.GetDoctorScheduleList(orgId, page, limit)
  82. if err != nil {
  83. this.ServeFailJsonSend(enums.ErrorCodeDataException, "添加设备失败")
  84. return
  85. }
  86. this.ServeSuccessJSON(map[string]interface{}{
  87. "schedules": schedules,
  88. "total": total,
  89. })
  90. //查询该机构是否有班种,如果没有去读系统默认的
  91. //_, errcode := service.GetDoctorScheduleByOrgId(orgId)
  92. //if errcode == gorm.ErrRecordNotFound{
  93. // schedules, total, err := service.GetDoctorScheduleList(0,page, limit)
  94. // if err != nil {
  95. // this.ServeFailJsonSend(enums.ErrorCodeDataException, "添加设备失败")
  96. // return
  97. // }
  98. //
  99. // this.ServeSuccessJSON(map[string]interface{}{
  100. // "schedules": schedules,
  101. // "total":total,
  102. // })
  103. //}else if errcode == nil{
  104. // schedules, total, err := service.GetDoctorScheduleList(orgId, page, limit)
  105. // if err != nil {
  106. // this.ServeFailJsonSend(enums.ErrorCodeDataException, "添加设备失败")
  107. // return
  108. // }
  109. //
  110. // this.ServeSuccessJSON(map[string]interface{}{
  111. // "schedules": schedules,
  112. // "total":total,
  113. // })
  114. //}
  115. }
  116. func (this *DoctorScheduleApiController) GetScheduleDetail() {
  117. id, _ := this.GetInt64("id")
  118. scheduleDetail, err := service.GetScheduleDetail(id)
  119. if err != nil {
  120. this.ServeFailJsonSend(enums.ErrorCodeDataException, "添加设备失败")
  121. return
  122. }
  123. this.ServeSuccessJSON(map[string]interface{}{
  124. "scheduleDetail": scheduleDetail,
  125. })
  126. }
  127. func (this *DoctorScheduleApiController) UpdateSchedule() {
  128. id, _ := this.GetInt64("id")
  129. class_name := this.GetString("class_name")
  130. class_attributes, _ := this.GetInt64("class_attributes")
  131. timeone_start := this.GetString("timeone_start")
  132. timeone_type, _ := this.GetInt64("timeone_type")
  133. timeone_end := this.GetString("timeone_end")
  134. timetwo_start := this.GetString("timetwo_start")
  135. timetwo_type, _ := this.GetInt64("timetwo_type")
  136. timetwo_end := this.GetString("timetwo_end")
  137. work_time := this.GetString("work_time")
  138. remarks := this.GetString("remarks")
  139. user_org_id, _ := this.GetInt64("user_org_id")
  140. schedules := models.DoctorSchedules{
  141. ClassName: class_name,
  142. ClassAttributes: class_attributes,
  143. TimeoneStart: timeone_start,
  144. TimeoneType: timeone_type,
  145. TimeoneEnd: timeone_end,
  146. TimetwoStart: timetwo_start,
  147. TimetwoEnd: timetwo_end,
  148. TimetwoType: timetwo_type,
  149. WorkTime: work_time,
  150. Remarks: remarks,
  151. }
  152. if user_org_id == 0 {
  153. err := service.CreateDotorSchedule(&schedules)
  154. if err != nil {
  155. this.ServeFailJsonSend(enums.ErrorCodeDataException, "添加设备失败")
  156. return
  157. }
  158. } else {
  159. //查询是否班种名称已存在
  160. scheduledata, _ := service.GetClassNameIsExsit(class_name, user_org_id, id)
  161. if scheduledata.ID > 0 && scheduledata.ID != id {
  162. this.ServeFailJsonSend(enums.ErrorCodeDataException, "班种名称已存在")
  163. return
  164. }
  165. err := service.UpdateScheduleList(id, &schedules)
  166. if err != nil {
  167. this.ServeFailJsonSend(enums.ErrorCodeDataException, "添加设备失败")
  168. return
  169. }
  170. }
  171. this.ServeSuccessJSON(map[string]interface{}{
  172. "schedules": schedules,
  173. })
  174. }
  175. func (this *DoctorScheduleApiController) DeleteSchedule() {
  176. adminUserInfo := this.GetAdminUserInfo()
  177. orgId := adminUserInfo.CurrentOrgId
  178. id, _ := this.GetInt64("id")
  179. //产寻该班种是否存在排班,如果存在不能删除
  180. _, errcode := service.GetStaffScheduleByScheduleType(id, orgId)
  181. if errcode == gorm.ErrRecordNotFound {
  182. err := service.DeleteScheduleById(id)
  183. if err != nil {
  184. this.ServeFailJsonSend(enums.ErrorCodeDataException, "添加设备失败")
  185. return
  186. }
  187. returnData := make(map[string]interface{}, 0)
  188. returnData["msg"] = "ok"
  189. this.ServeSuccessJSON(returnData)
  190. return
  191. } else if errcode == nil {
  192. this.ServeFailJsonSend(enums.ErrorCodeDataException, "该班种已存在排班,不能删除")
  193. return
  194. }
  195. }
  196. func (this *DoctorScheduleApiController) GetDoctorList() {
  197. orgId := this.GetAdminUserInfo().CurrentOrgId
  198. appId := this.GetAdminUserInfo().CurrentAppId
  199. //admin_user_id := this.GetAdminUserInfo().AdminUser.Id
  200. list, err := service.GetDoctorList(orgId, appId)
  201. if err != nil {
  202. this.ServeFailJsonSend(enums.ErrorCodeDataException, "添加设备失败")
  203. return
  204. }
  205. this.ServeSuccessJSON(map[string]interface{}{
  206. "list": list,
  207. })
  208. }
  209. func (this *DoctorScheduleApiController) GetScheduleList() {
  210. orgId := this.GetAdminUserInfo().CurrentOrgId
  211. _, errcode := service.GetDoctorScheduleByOrgId(orgId)
  212. if errcode == gorm.ErrRecordNotFound {
  213. scheduleList, err := service.GetScheduleList(0)
  214. if err != nil {
  215. this.ServeFailJsonSend(enums.ErrorCodeDataException, "添加设备失败")
  216. return
  217. }
  218. this.ServeSuccessJSON(map[string]interface{}{
  219. "scheduleList": scheduleList,
  220. })
  221. } else {
  222. scheduleList, err := service.GetScheduleList(orgId)
  223. if err != nil {
  224. this.ServeFailJsonSend(enums.ErrorCodeDataException, "添加设备失败")
  225. return
  226. }
  227. this.ServeSuccessJSON(map[string]interface{}{
  228. "scheduleList": scheduleList,
  229. })
  230. }
  231. }
  232. func (this *DoctorScheduleApiController) AddSchedule() {
  233. orgId := this.GetAdminUserInfo().CurrentOrgId
  234. doctor_id, _ := this.GetInt64("doctor_id")
  235. fmt.Println("doctor_id", doctor_id)
  236. doctor_type, _ := this.GetInt64("doctor_type")
  237. fmt.Println("doctor_type", doctor_type)
  238. start_time, _ := this.GetInt64("start_time")
  239. fmt.Println("start_time", start_time)
  240. end_time, _ := this.GetInt64("end_time")
  241. fmt.Println("end_time", end_time)
  242. schedule_type, _ := this.GetInt64("schedule_type")
  243. fmt.Println("schedule_type", schedule_type)
  244. schedule_week, _ := this.GetInt64("schedule_week")
  245. fmt.Println("schedule_week", schedule_week)
  246. schedule_date, _ := this.GetInt64("schedule_date")
  247. schedule := models.StaffSchedule{
  248. DoctorId: doctor_id,
  249. DoctorType: doctor_type,
  250. ScheduleType: schedule_type,
  251. ScheduleWeek: schedule_week,
  252. UserOrgId: orgId,
  253. StartTime: start_time,
  254. EndTime: end_time,
  255. Status: 1,
  256. Ctime: time.Now().Unix(),
  257. ScheduleDate: schedule_date,
  258. }
  259. _, errcode := service.GetScheduleListDetail(doctor_id, orgId, schedule_date)
  260. fmt.Println("errcode-----", errcode)
  261. if errcode == gorm.ErrRecordNotFound {
  262. err := service.AddSchedule(&schedule)
  263. if err != nil {
  264. this.ServeFailJsonSend(enums.ErrorCodeDataException, "添加设备失败")
  265. return
  266. }
  267. this.ServeSuccessJSON(map[string]interface{}{
  268. "schedule": schedule,
  269. })
  270. } else if errcode == nil {
  271. schedules, _ := service.GetScheduleListDetail(doctor_id, orgId, schedule_date)
  272. err := service.UpdateStaffList(&schedule, schedules.ID)
  273. if err != nil {
  274. this.ServeFailJsonSend(enums.ErrorCodeDataException, "添加设备失败")
  275. return
  276. }
  277. this.ServeSuccessJSON(map[string]interface{}{
  278. "schedule": schedule,
  279. })
  280. }
  281. }
  282. func (this *DoctorScheduleApiController) GetStaffScheduleList() {
  283. start_time, _ := this.GetInt64("start_time")
  284. fmt.Println("start_time", start_time)
  285. end_time, _ := this.GetInt64("end_time")
  286. fmt.Println("end_time", end_time)
  287. orgId := this.GetAdminUserInfo().CurrentOrgId
  288. staffList, err := service.GetStaffScheduleList(orgId, start_time, end_time)
  289. if err != nil {
  290. this.ServeFailJsonSend(enums.ErrorCodeDataException, "添加设备失败")
  291. return
  292. }
  293. this.ServeSuccessJSON(map[string]interface{}{
  294. "staffList": staffList,
  295. })
  296. }
  297. func (this *DoctorScheduleApiController) GetNextWeekList() {
  298. start_time, _ := this.GetInt64("start_time")
  299. fmt.Println("start_time", start_time)
  300. end_time, _ := this.GetInt64("end_time")
  301. fmt.Println("end_time", end_time)
  302. orgId := this.GetAdminUserInfo().CurrentOrgId
  303. staffList, err := service.GetStaffScheduleList(orgId, start_time, end_time)
  304. if err != nil {
  305. this.ServeFailJsonSend(enums.ErrorCodeDataException, "添加设备失败")
  306. return
  307. }
  308. this.ServeSuccessJSON(map[string]interface{}{
  309. "staffList": staffList,
  310. })
  311. }
  312. func (this *DoctorScheduleApiController) GetScheduleByDoctorId() {
  313. doctor_id, _ := this.GetInt64("doctor_id")
  314. start_time, _ := this.GetInt64("start_time")
  315. end_time, _ := this.GetInt64("end_time")
  316. orgId := this.GetAdminUserInfo().CurrentOrgId
  317. staffList, err := service.GetScheduleByDoctorId(doctor_id, start_time, end_time, orgId)
  318. if err != nil {
  319. this.ServeFailJsonSend(enums.ErrorCodeDataException, "添加设备失败")
  320. return
  321. }
  322. this.ServeSuccessJSON(map[string]interface{}{
  323. "staffList": staffList,
  324. })
  325. }
  326. func (this *DoctorScheduleApiController) ToSearchScheduleList() {
  327. //doctor_id, _ := this.GetInt64("doctor_id")
  328. user_name := this.GetString("user_name")
  329. start_time, _ := this.GetInt64("start_time")
  330. end_time, _ := this.GetInt64("end_time")
  331. orgId := this.GetAdminUserInfo().CurrentOrgId
  332. staffList, err := service.ToSearchSeacheduleList(user_name, start_time, end_time, orgId)
  333. if err != nil {
  334. this.ServeFailJsonSend(enums.ErrorCodeDataException, "添加设备失败")
  335. return
  336. }
  337. this.ServeSuccessJSON(map[string]interface{}{
  338. "staffList": staffList,
  339. })
  340. }
  341. func (this *DoctorScheduleApiController) DeleteStaffSchedule() {
  342. adminUserInfo := this.GetAdminUserInfo()
  343. orgId := adminUserInfo.CurrentOrgId
  344. start_time, _ := this.GetInt64("start_time")
  345. fmt.Println("start_time", start_time)
  346. end_time, _ := this.GetInt64("end_time")
  347. err := service.DeleteStaffSchedule(orgId, start_time, end_time)
  348. if err != nil {
  349. this.ServeFailJsonSend(enums.ErrorCodeDataException, "添加设备失败")
  350. return
  351. }
  352. returnData := make(map[string]interface{}, 0)
  353. returnData["msg"] = "ok"
  354. this.ServeSuccessJSON(returnData)
  355. return
  356. }
  357. func (this *DoctorScheduleApiController) CopyStaffSchedule() {
  358. adminUserInfo := this.GetAdminUserInfo()
  359. orgId := adminUserInfo.CurrentOrgId
  360. start_time, _ := this.GetInt64("start_time")
  361. fmt.Println("start_time", start_time)
  362. end_time, _ := this.GetInt64("end_time")
  363. fmt.Println("end_time", end_time)
  364. copy_startime, _ := this.GetInt64("copy_startime")
  365. fmt.Println("copy_startime", copy_startime)
  366. copy_endtime, _ := this.GetInt64("copy_endtime")
  367. schedule, err := service.GetStaffScheduleListTwo(orgId, start_time, end_time)
  368. //查询选中日期的排班是否存在
  369. _, errcode := service.GetNextWeekSchedule(orgId, copy_startime, copy_endtime)
  370. if errcode == gorm.ErrRecordNotFound {
  371. for _, item := range schedule {
  372. //fmt.Println(item.StartTime+604800)
  373. //礼拜1
  374. if item.ScheduleWeek == 1 {
  375. item.ScheduleDate = copy_startime
  376. }
  377. if item.ScheduleWeek == 2 {
  378. item.ScheduleDate = copy_startime + 86400
  379. }
  380. if item.ScheduleWeek == 3 {
  381. item.ScheduleDate = copy_startime + 172800
  382. }
  383. if item.ScheduleWeek == 4 {
  384. item.ScheduleDate = copy_startime + 259200
  385. }
  386. if item.ScheduleWeek == 5 {
  387. item.ScheduleDate = copy_startime + 345600
  388. }
  389. if item.ScheduleWeek == 6 {
  390. item.ScheduleDate = copy_startime + 432000
  391. }
  392. //礼拜天
  393. if item.ScheduleWeek == 0 {
  394. item.ScheduleDate = copy_endtime
  395. }
  396. staffSchedule := models.StaffSchedule{
  397. DoctorId: item.DoctorId,
  398. DoctorType: item.DoctorType,
  399. ScheduleType: item.ScheduleType,
  400. ScheduleWeek: item.ScheduleWeek,
  401. UserOrgId: item.UserOrgId,
  402. StartTime: copy_startime,
  403. EndTime: copy_endtime,
  404. Status: 1,
  405. Ctime: time.Now().Unix(),
  406. ScheduleDate: item.ScheduleDate,
  407. }
  408. service.AddSchedule(&staffSchedule)
  409. }
  410. if err != nil {
  411. this.ServeFailJsonSend(enums.ErrorCodeDataException, "添加设备失败")
  412. return
  413. }
  414. returnData := make(map[string]interface{}, 0)
  415. returnData["msg"] = "ok"
  416. this.ServeSuccessJSON(returnData)
  417. return
  418. } else if errcode == nil {
  419. this.ServeFailJsonSend(enums.ErrorCodeDataException, "排班数据已存在")
  420. fmt.Print("下周排班已存在")
  421. return
  422. }
  423. }
  424. func (this *DoctorScheduleApiController) UpdateContinusSchedule() {
  425. adminUserInfo := this.GetAdminUserInfo()
  426. orgId := adminUserInfo.CurrentOrgId
  427. is_status, _ := this.GetInt64("is_status")
  428. fmt.Println("is_status", is_status)
  429. schedule := models.ContinueSchedule{
  430. IsStatus: is_status,
  431. }
  432. err := service.UpdateContinusSchedule(&schedule, orgId)
  433. if err != nil {
  434. this.ServeFailJsonSend(enums.ErrorCodeDataException, "添加设备失败")
  435. return
  436. }
  437. this.ServeSuccessJSON(map[string]interface{}{
  438. "schedule": schedule,
  439. })
  440. }