staff_schedule_api_controller.go 11KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355
  1. package new_mobile_api_controllers
  2. import (
  3. "Xcx_New/controllers/mobile_api_controllers"
  4. "Xcx_New/enums"
  5. "Xcx_New/models"
  6. "Xcx_New/service"
  7. "fmt"
  8. "strings"
  9. "time"
  10. )
  11. type StaffScheduleApiController struct {
  12. mobile_api_controllers.MobileBaseAPIAuthController
  13. }
  14. func (this *StaffScheduleApiController) GetMobileDoctorList() {
  15. orgId := this.GetMobileAdminUserInfo().Org.Id
  16. appId := this.GetMobileAdminUserInfo().App.Id
  17. staffList, err := service.GetDoctorList(orgId, appId)
  18. //获取所有的医生
  19. doctorList, err := service.GetAllDoctorList(orgId, appId)
  20. //获取所有的护士
  21. nurseList, err := service.GetAllNurseList(orgId, appId)
  22. if err != nil {
  23. this.ServeFailJsonSend(enums.ErrorCodeDataException, "添加设备失败")
  24. return
  25. }
  26. if err != nil {
  27. this.ServeFailJsonSend(enums.ErrorCodeDataException, "添加设备失败")
  28. return
  29. }
  30. this.ServeSuccessJSON(map[string]interface{}{
  31. "staffList": staffList,
  32. "doctorList": doctorList,
  33. "nurseList": nurseList,
  34. })
  35. }
  36. func (this *StaffScheduleApiController) GetMobileStaffScheduleList() {
  37. orgId := this.GetMobileAdminUserInfo().Org.Id
  38. start_time, _ := this.GetInt64("start_time")
  39. fmt.Println("staft_time", start_time)
  40. end_time, _ := this.GetInt64("end_time")
  41. staffList, err := service.GetStaffScheduleList(orgId, start_time, end_time)
  42. if err != nil {
  43. this.ServeFailJsonSend(enums.ErrorCodeDataException, "添加设备失败")
  44. return
  45. }
  46. this.ServeSuccessJSON(map[string]interface{}{
  47. "staffList": staffList,
  48. })
  49. }
  50. func (this *StaffScheduleApiController) GetMobileNextWeekScheduleLIst() {
  51. orgId := this.GetMobileAdminUserInfo().Org.Id
  52. start_time, _ := this.GetInt64("start_time")
  53. end_time, _ := this.GetInt64("end_time")
  54. staffList, err := service.GetStaffScheduleList(orgId, start_time, end_time)
  55. if err != nil {
  56. this.ServeFailJsonSend(enums.ErrorCodeDataException, "添加设备失败")
  57. return
  58. }
  59. this.ServeSuccessJSON(map[string]interface{}{
  60. "staffList": staffList,
  61. })
  62. }
  63. func (this *StaffScheduleApiController) GetScheduleByUserType() {
  64. doctor_id, _ := this.GetInt64("doctor_id")
  65. start_time, _ := this.GetInt64("start_time")
  66. end_time, _ := this.GetInt64("end_time")
  67. orgId := this.GetMobileAdminUserInfo().Org.Id
  68. staffList, err := service.GetScheduleByDoctorId(doctor_id, start_time, end_time, orgId)
  69. if err != nil {
  70. this.ServeFailJsonSend(enums.ErrorCodeDataException, "添加设备失败")
  71. return
  72. }
  73. this.ServeSuccessJSON(map[string]interface{}{
  74. "staffList": staffList,
  75. })
  76. }
  77. func (this *StaffScheduleApiController) GetSearchPatientByDoctorId() {
  78. orgId := this.GetMobileAdminUserInfo().Org.Id
  79. user_name := this.GetString("user_name")
  80. start_time, _ := this.GetInt64("start_time")
  81. end_time, _ := this.GetInt64("end_time")
  82. staffList, err := service.ToSearchSeacheduleList(user_name, start_time, end_time, orgId)
  83. if err != nil {
  84. this.ServeFailJsonSend(enums.ErrorCodeDataException, "添加设备失败")
  85. return
  86. }
  87. this.ServeSuccessJSON(map[string]interface{}{
  88. "staffList": staffList,
  89. })
  90. }
  91. func (this *StaffScheduleApiController) GetMobileSchedulelist() {
  92. orgId := this.GetMobileAdminUserInfo().Org.Id
  93. list, err := service.GetScheduleList(orgId)
  94. if err != nil {
  95. this.ServeFailJsonSend(enums.ErrorCodeDataException, "添加设备失败")
  96. return
  97. }
  98. this.ServeSuccessJSON(map[string]interface{}{
  99. "list": list,
  100. })
  101. }
  102. func (this *StaffScheduleApiController) GetMobileScheduleListTotal() {
  103. start_time, _ := this.GetInt64("start_time")
  104. end_time, _ := this.GetInt64("end_time")
  105. orgId := this.GetMobileAdminUserInfo().Org.Id
  106. //统计班次
  107. scheudletotal, err := service.GetScheduleListTotal(orgId, start_time, end_time)
  108. //统计总工时
  109. list, err := service.GetTotalMinutes(orgId, start_time, end_time)
  110. //统计出勤天数
  111. workDay, err := service.GetTotalWorkDay(orgId, start_time, end_time)
  112. //统计缺勤天数
  113. noWorkDay, err := service.GetTotalNoWorkDay(orgId, start_time, end_time)
  114. if err != nil {
  115. this.ServeFailJsonSend(enums.ErrorCodeDataException, "添加设备失败")
  116. return
  117. }
  118. this.ServeSuccessJSON(map[string]interface{}{
  119. "scheudletotal": scheudletotal,
  120. "list": list,
  121. "workDay": workDay,
  122. "noWorkDay": noWorkDay,
  123. })
  124. }
  125. func (this *StaffScheduleApiController) GetMySchedule() {
  126. start_time, _ := this.GetInt64("start_time")
  127. end_time, _ := this.GetInt64("end_time")
  128. orgId := this.GetMobileAdminUserInfo().Org.Id
  129. creator, _ := this.GetInt64("creator")
  130. schedule, err := service.GetMySchedule(start_time, end_time, orgId, creator)
  131. if err != nil {
  132. this.ServeFailJsonSend(enums.ErrorCodeDataException, "添加设备失败")
  133. return
  134. }
  135. this.ServeSuccessJSON(map[string]interface{}{
  136. "schedule": schedule,
  137. })
  138. }
  139. func (this *StaffScheduleApiController) GetMobileChartList() {
  140. start_time, _ := this.GetInt64("start_time")
  141. end_time, _ := this.GetInt64("end_time")
  142. orgId := this.GetMobileAdminUserInfo().Org.Id
  143. //统计总工时
  144. list, err := service.GetTotalMinutesOne(orgId, start_time, end_time)
  145. //统计出勤的总工时
  146. workDaylist, err := service.GetTotalMinutesTwo(orgId, start_time, end_time)
  147. if err != nil {
  148. this.ServeFailJsonSend(enums.ErrorCodeDataException, "添加设备失败")
  149. return
  150. }
  151. this.ServeSuccessJSON(map[string]interface{}{
  152. "list": list,
  153. "workDaylist": workDaylist,
  154. })
  155. }
  156. func (this *StaffScheduleApiController) ToSearchMobileTotal() {
  157. start_time, _ := this.GetInt64("start_time")
  158. end_time, _ := this.GetInt64("end_time")
  159. orgId := this.GetMobileAdminUserInfo().Org.Id
  160. keyword := this.GetString("keyword")
  161. //统计表
  162. scheduletotal, err := service.GetSearchScheduleListTotal(orgId, start_time, end_time, keyword)
  163. list, err := service.GeSearchtTotalMinutes(orgId, start_time, end_time, keyword)
  164. workDay, err := service.GetSearchWorkDay(orgId, start_time, end_time, keyword)
  165. noWorkDay, err := service.GetSearchWorkNoDay(orgId, start_time, end_time, keyword)
  166. //统计图
  167. chartTotalMinute, err := service.GetChartTotalMinutesOne(orgId, start_time, end_time, keyword)
  168. chartWorkDayMinute, err := service.GetChartTotalMinutesTwo(orgId, start_time, end_time, keyword)
  169. if err != nil {
  170. this.ServeFailJsonSend(enums.ErrorCodeDataException, "添加设备失败")
  171. return
  172. }
  173. this.ServeSuccessJSON(map[string]interface{}{
  174. "scheduletotal": scheduletotal,
  175. "list": list,
  176. "workDay": workDay,
  177. "noWorkDay": noWorkDay,
  178. "chartTotalMinute": chartTotalMinute,
  179. "chartWorkDayMinute": chartWorkDayMinute,
  180. })
  181. }
  182. func (this *StaffScheduleApiController) ChangeMobileOption() {
  183. start_time, _ := this.GetInt64("start_time")
  184. end_time, _ := this.GetInt64("end_time")
  185. orgId := this.GetMobileAdminUserInfo().Org.Id
  186. doctor_type, _ := this.GetInt64("doctor_type")
  187. //统计图
  188. scheduletotal, err := service.ChagneScheduleListTotal(orgId, start_time, end_time, doctor_type)
  189. list, err := service.ChangeScheduleMinute(orgId, start_time, end_time, doctor_type)
  190. workday, err := service.ChangeWorkDay(orgId, start_time, end_time, doctor_type)
  191. worknoday, err := service.ChangeNoWorkDay(orgId, start_time, end_time, doctor_type)
  192. //统计表
  193. chartotalminute, err := service.ChartTotalMinute(orgId, start_time, end_time, doctor_type)
  194. chartworkdayminute, err := service.ChartWorkDayMinute(orgId, start_time, end_time, doctor_type)
  195. if err != nil {
  196. this.ServeFailJsonSend(enums.ErrorCodeDataException, "添加设备失败")
  197. return
  198. }
  199. this.ServeSuccessJSON(map[string]interface{}{
  200. "scheduletotal": scheduletotal,
  201. "list": list,
  202. "workday": workday,
  203. "worknoday": worknoday,
  204. "chartotalminute": chartotalminute,
  205. "chartworkdayminute": chartworkdayminute,
  206. })
  207. }
  208. func (this *StaffScheduleApiController) GetAllZone() {
  209. id := this.GetMobileAdminUserInfo().Org.Id
  210. zone, err := service.GetAllMobileZone(id)
  211. if err != nil {
  212. this.ServeFailJsonSend(enums.ErrorCodeDataException, "添加设备失败")
  213. return
  214. }
  215. this.ServeSuccessJSON(map[string]interface{}{
  216. "zone": zone,
  217. })
  218. }
  219. func (this *StaffScheduleApiController) GetPatientScheduleList() {
  220. orgid := this.GetMobileAdminUserInfo().Org.Id
  221. fmt.Println("orgid", orgid)
  222. timeLayout := "2006-01-02"
  223. loc, _ := time.LoadLocation("Local")
  224. start_time := this.GetString("start_time")
  225. var startTime int64
  226. if len(start_time) > 0 {
  227. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  228. if err != nil {
  229. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  230. return
  231. }
  232. startTime = theTime.Unix()
  233. }
  234. fmt.Println("时间搓", startTime)
  235. zoneid, _ := this.GetInt64("zoneid")
  236. fmt.Println(zoneid)
  237. classtype, _ := this.GetInt64("classtype")
  238. fmt.Println("classtype", classtype)
  239. //获取当天排班的病人情况
  240. schedule, err := service.GetPatientSchedule(startTime, zoneid, classtype, orgid)
  241. if err != nil {
  242. this.ServeFailJsonSend(enums.ErrorCodeDataException, "添加设备失败")
  243. return
  244. }
  245. this.ServeSuccessJSON(map[string]interface{}{
  246. "schedule": schedule,
  247. })
  248. }
  249. func (this *StaffScheduleApiController) DeleteSchedule() {
  250. id, _ := this.GetInt64("id")
  251. fmt.Println("id", id)
  252. err := service.DeleteSchedule(id)
  253. fmt.Println(err)
  254. returnData := make(map[string]interface{}, 0)
  255. returnData["msg"] = "ok"
  256. this.ServeSuccessJSON(returnData)
  257. return
  258. }
  259. func (this *StaffScheduleApiController) SearchPatient() {
  260. timeLayout := "2006-01-02"
  261. loc, _ := time.LoadLocation("Local")
  262. keyword := this.GetString("keyword")
  263. fmt.Println(keyword)
  264. orgId := this.GetMobileAdminUserInfo().Org.Id
  265. start_time := this.GetString("start_time")
  266. var startTime int64
  267. if len(start_time) > 0 {
  268. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  269. if err != nil {
  270. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  271. return
  272. }
  273. startTime = theTime.Unix()
  274. }
  275. schedule, err := service.GetSearchPatient(keyword, orgId, startTime)
  276. if err != nil {
  277. this.ServeFailJsonSend(enums.ErrorCodeDataException, "添加设备失败")
  278. return
  279. }
  280. this.ServeSuccessJSON(map[string]interface{}{
  281. "schedule": schedule,
  282. })
  283. }
  284. func (this *StaffScheduleApiController) UpdatePatientScheduleById() {
  285. ids := this.GetString("ids")
  286. idSplit := strings.Split(ids, ",")
  287. var err error
  288. //查询患者信息
  289. list, _ := service.GetStaffScheduleById(idSplit)
  290. if len(list) > 0 {
  291. for index, _ := range list {
  292. fmt.Println("index2322332", index)
  293. schedule := models.XtSchedule{
  294. PatientId: list[0].PatientId,
  295. ModeId: list[0].ModeId,
  296. }
  297. xtSchedule := models.WeekSchedule{
  298. PatientId: list[1].PatientId,
  299. ModeId: list[1].ModeId,
  300. }
  301. err = service.UpdateStaffSchedule(list[1].ID, schedule)
  302. fmt.Println("errrrrrrr2323323232323", err)
  303. service.UpdateStaffScheduleOne(list[0].ID, xtSchedule)
  304. }
  305. }
  306. fmt.Println(err)
  307. this.ServeSuccessJSON(map[string]interface{}{
  308. "msg": "切换成功",
  309. })
  310. }