city_data_uoload_service.go 5.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  1. // 统计后台的 service
  2. package service
  3. import (
  4. "Data_Upload_Api/models"
  5. "Data_Upload_Api/models/sz"
  6. "github.com/jinzhu/gorm"
  7. "strings"
  8. )
  9. func FindAllDataUploadConfigOrgInfo(province_id int64, city_id int64, config_type int64) (data []*sz.DataUploadConfig, err error) {
  10. err = readDb.Model(&sz.DataUploadConfig{}).Where("status = 1 AND province_id = ? AND city_id = ? AND config_type = ?", province_id, city_id, config_type).Find(&data).Error
  11. return
  12. }
  13. func FindDataUploadOrgInfo(org_id int64, module_type int64) (data sz.DataUpload, err error) {
  14. err = readDb.Model(&sz.DataUpload{}).Where(" org_id = ? AND module_type = ?", org_id, module_type).Last(&data).Error
  15. return
  16. }
  17. func FindOrgData(org_id int64) (org models.UserOrg, err error) {
  18. err = readUserDb.Model(&models.UserOrg{}).Where("status = 1 AND id = ?", org_id).Preload("DeviceNumber", func(db *gorm.DB) *gorm.DB {
  19. return readDb.Where("status = 1")
  20. }).Find(&org).Error
  21. return
  22. }
  23. func FindOrgRolesData(org_id int64, lastUploadTime int64, nowTime int64) (role []*models.UserAdminRole, err error) {
  24. db := readUserDb.Model(&models.UserAdminRole{}).Where("status = 1 AND org_id = ? ", org_id)
  25. if lastUploadTime != 0 && nowTime != 0 {
  26. db.Where("ctime >= ? AND ctime <= ?", lastUploadTime, nowTime)
  27. }
  28. err = db.Find(&role).Error
  29. return
  30. }
  31. func FindOrgPatientData(org_id int64, lastUploadTime int64, nowTime int64) (patient []*models.Patients, err error) {
  32. db := readDb.Model(&models.Patients{}).Where("status = 1 AND user_org_id = ?", org_id)
  33. if lastUploadTime != 0 && nowTime != 0 {
  34. db = db.Where("created_time >= ? AND created_time <= ?", lastUploadTime, nowTime)
  35. }
  36. err = db.Find(&patient).Error
  37. return
  38. }
  39. func FindOrgPatientOutData(org_id int64, lastUploadTime int64, nowTime int64) (patient []*models.Patients, err error) {
  40. db := readDb.Model(&models.Patients{}).Where("status = 1 AND user_org_id = ? AND lapseto = 2 ", org_id).Preload("PatientLapseto", "status = 1")
  41. if lastUploadTime != 0 && nowTime != 0 {
  42. db = db.Where("created_time >= ? AND created_time <= ?", lastUploadTime, nowTime)
  43. }
  44. err = db.Find(&patient).Error
  45. return
  46. }
  47. func FindOrgScheduleData(org_id int64, lastUploadTime int64, nowTime int64) (sch []*models.Schedule, err error) {
  48. db := readDb.Model(&models.Schedule{}).Where("status = 1 AND user_org_id = ?", org_id).Preload("DeviceNumber", "status = 1")
  49. if lastUploadTime != 0 && nowTime != 0 {
  50. db = db.Where("created_time >= ? AND created_time <= ?", lastUploadTime, nowTime)
  51. }
  52. err = db.Find(&sch).Error
  53. return
  54. }
  55. func FindOrgDialysisPrescriptionData(org_id int64, lastUploadTime int64, nowTime int64) (ps []*models.DialysisPrescription, err error) {
  56. db := readDb.Model(&models.DialysisPrescription{}).Where("status = 1 AND user_org_id = ?", org_id).Preload("AssessmentBeforeDislysis", "status = 1").Preload("DialysisOrder", "status = 1")
  57. if lastUploadTime != 0 && nowTime != 0 {
  58. db = db.Where("created_time >= ? AND created_time <= ?", lastUploadTime, nowTime)
  59. }
  60. err = db.Find(&ps).Error
  61. return
  62. }
  63. func FindOrgMonitorRecordData(org_id int64, lastUploadTime int64, nowTime int64) (monitor []*models.MonitoringRecord, err error) {
  64. db := readDb.Model(&models.MonitoringRecord{}).Where("status = 1 AND user_org_id = ?", org_id)
  65. if lastUploadTime != 0 && nowTime != 0 {
  66. db = db.Where("created_time >= ? AND created_time <= ?", lastUploadTime, nowTime)
  67. }
  68. err = db.Find(&monitor).Error
  69. return
  70. }
  71. func CreateOrgRecord(hospital *sz.TempHdHospital) (err error) {
  72. err = writeDb.Model(&sz.TempHdHospital{}).Create(&hospital).Error
  73. return
  74. }
  75. func CreateUploadRecord(upload *sz.DataUpload) (err error) {
  76. err = writeDb.Model(&sz.DataUpload{}).Create(&upload).Error
  77. return
  78. }
  79. func BatchCreateStaffRecord(staffs []*sz.TempHdStaff) (err error) {
  80. if len(staffs) > 0 {
  81. utx := writeDb.Begin()
  82. if len(staffs) > 0 {
  83. thisSQL := "INSERT INTO temp_hd_staff (hospital_id, staff_id, staff_name, position, permanent_type,create_time,update_time,sjscsj,mj) VALUES "
  84. insertParams := make([]string, 0)
  85. insertData := make([]interface{}, 0)
  86. for _, info := range staffs {
  87. insertParams = append(insertParams, "(?,?,?,?,?,?,?,?,?)")
  88. insertData = append(insertData, info.HospitalId)
  89. insertData = append(insertData, info.StaffId)
  90. insertData = append(insertData, info.StaffName)
  91. insertData = append(insertData, info.Position)
  92. insertData = append(insertData, info.PermanentType)
  93. insertData = append(insertData, info.CreateTime)
  94. insertData = append(insertData, info.UpdateTime)
  95. insertData = append(insertData, info.Sjscsj)
  96. insertData = append(insertData, info.Xgbz)
  97. }
  98. thisSQL += strings.Join(insertParams, ", ")
  99. err = utx.Exec(thisSQL, insertData...).Error
  100. if err != nil {
  101. utx.Rollback()
  102. return
  103. }
  104. }
  105. utx.Commit()
  106. }
  107. return
  108. }
  109. func FindOrgDialysisData(org_id int64, lastUploadTime int64, nowTime int64) (ps []*models.VMSchedule, err error) {
  110. db := readDb.Model(&models.VMSchedule{}).Where("status = 1 AND user_org_id = ? ", org_id).
  111. Preload("DeviceNumber", "status = 1").
  112. Preload("VMDialysisPrescription", "status = 1").
  113. Preload("AssessmentBeforeDislysis", "status = 1").
  114. Preload("AssessmentAfterDislysis", "status = 1").
  115. Preload("DialysisOrder", "status = 1").
  116. Preload("MonitoringRecord", "status = 1")
  117. if lastUploadTime != 0 && nowTime != 0 {
  118. db = db.Where("created_time >= ? AND created_time <= ?", lastUploadTime, nowTime)
  119. }
  120. err = db.Find(&ps).Error
  121. return
  122. }
  123. func FindOrgDeviceZoneRecordData(org_id int64, lastUploadTime int64, nowTime int64) (zone []*models.DeviceZone, err error) {
  124. db := readDb.Model(&models.DeviceZone{}).Where("status = 1 AND org_id = ?", org_id)
  125. if lastUploadTime != 0 && nowTime != 0 {
  126. db = db.Where("ctime >= ? AND ctime <= ?", lastUploadTime, nowTime)
  127. }
  128. err = db.Find(&zone).Error
  129. return
  130. }