auto_create_week_plan.go 5.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  1. package service
  2. import (
  3. "XT_New/models"
  4. "XT_New/utils"
  5. "fmt"
  6. "github.com/jinzhu/gorm"
  7. "github.com/robfig/cron"
  8. "strconv"
  9. "time"
  10. )
  11. var createWeekPlanCronJob *cron.Cron
  12. func init() {
  13. utils.InfoLog("第二次开启自动消毒时任务")
  14. spec := "0 0 22 * * ?" // 每天22点执行一次
  15. //spec := "0 */1 * * * ?" // 每1分钟执行一次
  16. createWeekPlanCronJob = cron.New()
  17. createWeekDisinfectionCronJob.AddFunc(spec, func() {
  18. AutoCreateWeekPlanJob()
  19. })
  20. }
  21. func BeginAutoCreatePlanJob() {
  22. createWeekPlanCronJob.Start()
  23. }
  24. func AutoCreateWeekPlanJob() {
  25. timeStr := time.Now().Format("2006-01-02")
  26. timeLayout := "2006-01-02 15:04:05"
  27. fmt.Println("timeStr:", timeStr)
  28. timeStringToTime, _ := utils.ParseTimeStringToTime(timeLayout, timeStr+" 00:00:00")
  29. timenow := timeStringToTime.Unix()
  30. fmt.Println("timenow是什么", timenow)
  31. //查询当天排班所有机构
  32. org, errs := GetAllOrgID(timenow)
  33. fmt.Print("错误是什么", errs)
  34. fmt.Println("查询有机构失败", err)
  35. for _, item := range org {
  36. //查询机构是否开启自动使用登记
  37. remander, errs := GetRemanderDatas(item.UserOrgId)
  38. fmt.Print("查询自动使用登记错误", errs)
  39. //开启
  40. if remander.IsRun == 1 {
  41. fmt.Println("机构id", item.UserOrgId)
  42. //查询当天机构的所有下机病人id
  43. order, _ := GetAllPatientByOrgID(item.UserOrgId, timenow)
  44. for _, it := range order {
  45. fmt.Println("病人", it.PatientId)
  46. //查询病人信息
  47. patients, err := GetPatientInformation(it.PatientId, it.UserOrgId)
  48. fmt.Println("查询病人信息报错", err)
  49. var con = ""
  50. if patients.IsInfectious == 0 {
  51. con = ""
  52. }
  53. if patients.IsInfectious == 1 {
  54. con = "无"
  55. }
  56. if patients.IsInfectious == 2 {
  57. con = "有"
  58. }
  59. //查询病人的班次
  60. //schedules, _ := GetAllPatientSchedule(it.PatientId, it.UserOrgId,timenow)
  61. schedules, _ := GetAllPatientSchedule(it.PatientId, it.UserOrgId, timenow)
  62. fmt.Println("班次", schedules.ScheduleType)
  63. //查询病人今日的透析模式
  64. prescription, _ := GetDialysisPrescription(it.PatientId, it.UserOrgId, timenow)
  65. fmt.Println("透析模式", prescription.ModeId)
  66. //查询病人今日透后评估数据
  67. dislysis, err := GetAssessmentAfterDissData(it.PatientId, it.UserOrgId, timenow)
  68. fmt.Println("透后", err)
  69. // //根据床位号获取设备id
  70. addmacher, _ := GetEquimentID(schedules.BedId, it.UserOrgId)
  71. unitype, err := strconv.ParseInt(addmacher.UnitType, 10, 64)
  72. fmt.Println(" 设备id", addmacher.ID)
  73. //根据设备id获取设备类型
  74. //equimentname, _ := GetAddmacher(addmacher.ID, it.UserOrgId)
  75. fmt.Println("班次", it.SchedualType)
  76. //查看该设备是否有消毒计划,无怎返回,有则添加
  77. plan, errplan := GetDisinfection(unitype, it.SchedualType, it.UserOrgId)
  78. fmt.Print("plan", plan)
  79. fmt.Println("错误", errplan)
  80. if errplan == gorm.ErrRecordNotFound {
  81. fmt.Println("该设备无消毒计划")
  82. return
  83. } else if errplan == nil {
  84. //查询该病人是否有记录,无记录的则添加
  85. information, errcode := GetInfor(it.PatientId, timenow, it.UserOrgId, it.SchedualType)
  86. fmt.Println("errcode是什么", errcode)
  87. fmt.Println("information", information)
  88. if errcode == gorm.ErrRecordNotFound {
  89. information := models.DeviceInformation{
  90. Date: timenow,
  91. Zone: schedules.PartitionId,
  92. Class: it.SchedualType,
  93. BedNumber: schedules.BedId,
  94. PatientId: schedules.PatientId,
  95. DialysisMode: prescription.ModeId,
  96. LongTime: strconv.FormatInt(plan.DisinfecTime, 10),
  97. Disinfection: 1,
  98. DialysisConcentration: 1,
  99. DisinfectionStatus: 1,
  100. Move: 1,
  101. UserOrgId: it.UserOrgId,
  102. DisinfectType: plan.Way, //基表消毒方式
  103. DisinfectantType: plan.MachineDisinfectant, //基表消毒液
  104. FluidPath: plan.DisinfectanWay, //液路消毒方式
  105. Disinfectant: plan.Disinfectant, //液路消毒液
  106. Ctime: time.Now().Unix(),
  107. Status: 1,
  108. SignName: it.FinishNurse,
  109. EquimentId: addmacher.ID,
  110. DisinfectionResidue: 2,
  111. Bed: addmacher.BedNumber,
  112. StartTime: it.StartTime,
  113. EndTime: it.EndTime,
  114. Contagion: con,
  115. WeightLoss: strconv.FormatFloat(dislysis.WeightLoss, 'f', -1, 64),
  116. Hyperfiltratio: strconv.FormatFloat(dislysis.ActualUltrafiltration, 'f', -1, 64),
  117. DialysisHour: strconv.FormatInt(dislysis.ActualTreatmentHour, 10),
  118. MachineRun: 1,
  119. }
  120. err := CreateInformation(&information)
  121. fmt.Println("报错", err)
  122. } else if errcode == nil {
  123. } else {
  124. }
  125. } else {
  126. return
  127. }
  128. }
  129. }
  130. //关闭
  131. if remander.IsRun == 2 {
  132. fmt.Print("已关闭")
  133. }
  134. }
  135. }