city_data_uoload_service.go 6.0KB

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