city_data_uoload_service.go 22KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601
  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. db = db.Where("ctime >= ? AND ctime <= ?", lastUploadTime, nowTime)
  30. err = db.Find(&role).Error
  31. return
  32. }
  33. func FindOrgPatientData(org_id int64, lastUploadTime int64, nowTime int64) (patient []*models.Patients, err error) {
  34. db := readDb.Model(&models.Patients{}).Where("status = 1 AND user_org_id = ?", org_id)
  35. db = db.Where("created_time >= ? AND created_time <= ?", lastUploadTime, nowTime)
  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. db = db.Where("created_time >= ? AND created_time <= ?", lastUploadTime, nowTime)
  42. err = db.Find(&patient).Error
  43. return
  44. }
  45. func FindOrgScheduleData(org_id int64, lastUploadTime int64, nowTime int64) (sch []*models.Schedule, err error) {
  46. db := readDb.Model(&models.Schedule{}).Where("status = 1 AND user_org_id = ?", org_id).Preload("DeviceNumber", "status = 1")
  47. if lastUploadTime != 0 && nowTime != 0 {
  48. db = db.Where("created_time >= ? AND created_time <= ?", lastUploadTime, nowTime)
  49. }
  50. err = db.Find(&sch).Error
  51. return
  52. }
  53. func FindOrgDialysisPrescriptionData(org_id int64, lastUploadTime int64, nowTime int64) (ps []*models.DialysisPrescription, err error) {
  54. db := readDb.Model(&models.DialysisPrescription{}).Where("status = 1 AND user_org_id = ?", org_id).Preload("AssessmentBeforeDislysis", "status = 1").Preload("DialysisOrder", "status = 1")
  55. db = db.Where("created_time >= ? AND created_time <= ?", lastUploadTime, nowTime)
  56. err = db.Find(&ps).Error
  57. return
  58. }
  59. func FindOrgMonitorRecordData(org_id int64, lastUploadTime int64, nowTime int64) (monitor []*models.MonitoringRecord, err error) {
  60. db := readDb.Model(&models.MonitoringRecord{}).Where("status = 1 AND user_org_id = ?", org_id)
  61. db = db.Where("created_time >= ? AND created_time <= ?", lastUploadTime, nowTime)
  62. err = db.Find(&monitor).Error
  63. return
  64. }
  65. func CreateOrgRecord(rdb *gorm.DB, hospital *sz.TempHdHospital) (err error) {
  66. err = rdb.Model(&sz.TempHdHospital{}).Create(&hospital).Error
  67. return
  68. }
  69. func CreateUploadRecord(upload *sz.DataUpload) (err error) {
  70. err = writeDb.Model(&sz.DataUpload{}).Create(&upload).Error
  71. return
  72. }
  73. func FindOrgDialysisData(org_id int64, lastUploadTime int64, nowTime int64) (ps []*models.VMDialysisOrder, err error) {
  74. db := readDb.Model(&models.VMDialysisOrder{}).Where("status = 1 AND user_org_id = ? AND stage = 2 ", org_id).
  75. Preload("DeviceNumber", "status = 1").
  76. Preload("VMDialysisPrescription", "status = 1").
  77. Preload("AssessmentBeforeDislysis", "status = 1").
  78. Preload("AssessmentAfterDislysis", "status = 1").
  79. Preload("Schedule", "status = 1").
  80. Preload("MonitoringRecord", "status = 1")
  81. if lastUploadTime != 0 && nowTime != 0 {
  82. db = db.Where("updated_time >= ? AND updated_time <= ?", lastUploadTime, nowTime)
  83. }
  84. err = db.Find(&ps).Error
  85. return
  86. }
  87. func FindOrgDeviceZoneRecordData(org_id int64, lastUploadTime int64, nowTime int64) (zone []*models.DeviceZone, err error) {
  88. db := readDb.Model(&models.DeviceZone{}).Where("status = 1 AND org_id = ?", org_id)
  89. if lastUploadTime != 0 && nowTime != 0 {
  90. db = db.Where("ctime >= ? AND ctime <= ?", lastUploadTime, nowTime)
  91. }
  92. err = db.Find(&zone).Error
  93. return
  94. }
  95. func FindOrgWaterMachineData(org_id int64, lastUploadTime int64, nowTime int64) (waterMachine []*models.VMDeviceAddmacher, err error) {
  96. db := readUserDb.Model(&models.VMDeviceAddmacher{}).Where("status = 1 AND user_org_id = ? AND device_type = 2", org_id)
  97. db = db.Where("ctime >= ? AND ctime <= ?", lastUploadTime, nowTime)
  98. err = db.Find(&waterMachine).Error
  99. return
  100. }
  101. func BatchCreateWMsRecord(wms []*sz.TempHdWm, rdb *gorm.DB) (err error) {
  102. if len(wms) > 0 {
  103. utx := rdb.Begin()
  104. if len(wms) > 0 {
  105. thisSQL := "INSERT INTO t_hd_wm (HOSPITAL_ID, EQUIPMENT_ID, EQUIPMENT_BRAND, EQUIPMENT_MODEL, ENABLE_TIME,DISCARDED_TIME,EQUIPMENT_TYPE,XGBZ,CREATE_TIME,UPDATE_TIME,SJSCSJ) VALUES "
  106. insertParams := make([]string, 0)
  107. insertData := make([]interface{}, 0)
  108. for _, wm := range wms {
  109. insertParams = append(insertParams, "(?,?,?,?,?,?,?,?,?,?,?)")
  110. insertData = append(insertData, wm.HospitalId)
  111. insertData = append(insertData, wm.EquipmentId)
  112. insertData = append(insertData, wm.EquipmentBrand)
  113. insertData = append(insertData, wm.EquipmentModel)
  114. insertData = append(insertData, wm.EnableTime)
  115. insertData = append(insertData, wm.DiscardedTime)
  116. insertData = append(insertData, wm.EquipmentType)
  117. insertData = append(insertData, wm.Xgbz)
  118. insertData = append(insertData, wm.CreateTime)
  119. insertData = append(insertData, wm.UpdateTime)
  120. insertData = append(insertData, wm.Sjscsj)
  121. }
  122. thisSQL += strings.Join(insertParams, ", ")
  123. err = utx.Exec(thisSQL, insertData...).Error
  124. if err != nil {
  125. utx.Rollback()
  126. return
  127. }
  128. }
  129. utx.Commit()
  130. }
  131. return
  132. }
  133. func BatchCreateStaffRecord(staffs []*sz.TempHdStaff, rdb *gorm.DB) (err error) {
  134. if len(staffs) > 0 {
  135. utx := rdb.Begin()
  136. if len(staffs) > 0 {
  137. thisSQL := "INSERT INTO t_hd_staff (HOSPITAL_ID, STAFF_ID, STAFF_NAME, POSITION, PERMANENT_TYPE,CREATE_TIME,UPDATE_TIME,SJSCSJ,MJ) VALUES "
  138. insertParams := make([]string, 0)
  139. insertData := make([]interface{}, 0)
  140. for _, info := range staffs {
  141. insertParams = append(insertParams, "(?,?,?,?,?,?,?,?,?)")
  142. insertData = append(insertData, info.HospitalId)
  143. insertData = append(insertData, info.StaffId)
  144. insertData = append(insertData, info.StaffName)
  145. insertData = append(insertData, info.Position)
  146. insertData = append(insertData, info.PermanentType)
  147. insertData = append(insertData, info.CreateTime)
  148. insertData = append(insertData, info.UpdateTime)
  149. insertData = append(insertData, info.Sjscsj)
  150. insertData = append(insertData, info.Xgbz)
  151. }
  152. thisSQL += strings.Join(insertParams, ", ")
  153. err = utx.Exec(thisSQL, insertData...).Error
  154. if err != nil {
  155. utx.Rollback()
  156. return
  157. }
  158. }
  159. utx.Commit()
  160. }
  161. return
  162. }
  163. func BatchCreatePatinet(patients []*sz.TempHdPatient, rdb *gorm.DB) (err error) {
  164. if len(patients) > 0 {
  165. utx := rdb.Begin()
  166. if len(patients) > 0 {
  167. thisSQL := "INSERT INTO t_hd_patient (HOSPITAL_ID, PATIENT_NK, CARD_NO, CARD_TYPE, ID_NO,ID_TYPE,PATIENT_NAME,GENDER,BORN_DATE,DIAGNOSIS_SUMMARY,IS_CRF,CREATE_TIME,UPDATE_TIME,SJSCSJ,XGBZ) VALUES "
  168. insertParams := make([]string, 0)
  169. insertData := make([]interface{}, 0)
  170. for _, info := range patients {
  171. insertParams = append(insertParams, "(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)")
  172. insertData = append(insertData, info.HospitalId)
  173. insertData = append(insertData, info.PatientNk)
  174. insertData = append(insertData, info.CardNo)
  175. insertData = append(insertData, info.CardType)
  176. insertData = append(insertData, info.IdNo)
  177. insertData = append(insertData, info.IdType)
  178. insertData = append(insertData, info.PatientName)
  179. insertData = append(insertData, info.Gender)
  180. insertData = append(insertData, info.BornDate)
  181. insertData = append(insertData, info.DiagnosisSummary)
  182. insertData = append(insertData, info.IsCrf)
  183. insertData = append(insertData, info.CreatedTime)
  184. insertData = append(insertData, info.UpdateTime)
  185. insertData = append(insertData, info.Sjscsj)
  186. insertData = append(insertData, info.Xgbz)
  187. }
  188. thisSQL += strings.Join(insertParams, ", ")
  189. err = utx.Exec(thisSQL, insertData...).Error
  190. if err != nil {
  191. utx.Rollback()
  192. return
  193. }
  194. }
  195. utx.Commit()
  196. }
  197. return
  198. }
  199. func BatchCreateSchedual(patients []*sz.TempHdShift, rdb *gorm.DB) (err error) {
  200. if len(patients) > 0 {
  201. utx := rdb.Begin()
  202. if len(patients) > 0 {
  203. thisSQL := "INSERT INTO t_hd_shift (PS_ID, HOSPITAL_ID, PATIENT_NK, SCHEDULE_DATE, SHIFT_TYPE,SICKBED_NO,SCHEDULE_STATUS,CREATE_TIME,SJSCSJ,XGBZ) VALUES "
  204. insertParams := make([]string, 0)
  205. insertData := make([]interface{}, 0)
  206. for _, info := range patients {
  207. insertParams = append(insertParams, "(?,?,?,?,?,?,?,?,?,?)")
  208. insertData = append(insertData, info.PsId)
  209. insertData = append(insertData, info.HospitalId)
  210. insertData = append(insertData, info.PatientNk)
  211. insertData = append(insertData, info.ScheduleDate)
  212. insertData = append(insertData, info.ShiftType)
  213. insertData = append(insertData, info.SickbedNo)
  214. insertData = append(insertData, info.ScheduleStatus)
  215. insertData = append(insertData, info.CreateTime)
  216. insertData = append(insertData, info.Sjscsj)
  217. insertData = append(insertData, info.Xgbz)
  218. }
  219. thisSQL += strings.Join(insertParams, ", ")
  220. err = utx.Exec(thisSQL, insertData...).Error
  221. if err != nil {
  222. utx.Rollback()
  223. return
  224. }
  225. }
  226. utx.Commit()
  227. }
  228. return
  229. }
  230. func BatchCreatePs(patients []*sz.TempHdPs, rdb *gorm.DB) (err error) {
  231. if len(patients) > 0 {
  232. utx := rdb.Begin()
  233. if len(patients) > 0 {
  234. thisSQL := "INSERT INTO t_hd_ps (PRESCRIBE_ID, HOSPITAL_ID, PATIENT_NK, K, CA,NA,DIALYSIS_FREQUENCY,FREQUENCY_UNIT,DIALYSIS_DURATION,HDF,HP,HP_FREQUENCY,HP_FREQUENCY_UNIT,HP_DURATION,HDF_FREQUENCY_UNIT,HDF_FREQUENCY,HDF_DURATION,CREATE_TIME,SJSCSJ,XGBZ) VALUES "
  235. insertParams := make([]string, 0)
  236. insertData := make([]interface{}, 0)
  237. for _, info := range patients {
  238. insertParams = append(insertParams, "(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)")
  239. insertData = append(insertData, info.PrescribeId)
  240. insertData = append(insertData, info.HospitalId)
  241. insertData = append(insertData, info.PatientNk)
  242. insertData = append(insertData, info.K)
  243. insertData = append(insertData, info.Ca)
  244. insertData = append(insertData, info.Na)
  245. insertData = append(insertData, info.DialysisFrequency)
  246. insertData = append(insertData, info.FrequencyUnit)
  247. insertData = append(insertData, info.DialysisDuration)
  248. insertData = append(insertData, info.Hdf)
  249. insertData = append(insertData, info.Hp)
  250. insertData = append(insertData, info.HpFrequency)
  251. insertData = append(insertData, info.HpFrequencyUnit)
  252. insertData = append(insertData, info.HpDuration)
  253. insertData = append(insertData, info.HdfFrequencyUnit)
  254. insertData = append(insertData, info.HdfFrequency)
  255. insertData = append(insertData, info.HdfDuration)
  256. insertData = append(insertData, info.CreateTime)
  257. insertData = append(insertData, info.Sjscsj)
  258. insertData = append(insertData, info.Xgbz)
  259. }
  260. thisSQL += strings.Join(insertParams, ", ")
  261. err = utx.Exec(thisSQL, insertData...).Error
  262. if err != nil {
  263. utx.Rollback()
  264. return
  265. }
  266. }
  267. utx.Commit()
  268. }
  269. return
  270. }
  271. func BatchCreatePsm(psms []*sz.TempHdPsMedicine, rdb *gorm.DB) (err error) {
  272. if len(psms) > 0 {
  273. utx := rdb.Begin()
  274. if len(psms) > 0 {
  275. thisSQL := "INSERT INTO t_hd_ps_medicine (PRESCRIBE_ID, HOSPITAL_ID, MEDICINE_TYPE_ID,MEDICINE_ID,CREATE_TIME,SJSCSJ,XGBZ) VALUES "
  276. insertParams := make([]string, 0)
  277. insertData := make([]interface{}, 0)
  278. for _, psm := range psms {
  279. insertParams = append(insertParams, "(?,?,?,?,?,?,?)")
  280. insertData = append(insertData, psm.PrescribeId)
  281. insertData = append(insertData, psm.HospitalId)
  282. insertData = append(insertData, psm.MedicineTypeId)
  283. insertData = append(insertData, psm.MedicineId)
  284. insertData = append(insertData, psm.CreatedTime)
  285. insertData = append(insertData, psm.Sjscsj)
  286. insertData = append(insertData, psm.Xgbz)
  287. }
  288. thisSQL += strings.Join(insertParams, ", ")
  289. err = utx.Exec(thisSQL, insertData...).Error
  290. if err != nil {
  291. utx.Rollback()
  292. return
  293. }
  294. }
  295. utx.Commit()
  296. }
  297. return
  298. }
  299. func BatchCreateDialysis(psms []*sz.TempHdDialysis, rdb *gorm.DB) (err error) {
  300. if len(psms) > 0 {
  301. utx := rdb.Begin()
  302. if len(psms) > 0 {
  303. thisSQL := "INSERT INTO t_hd_dialysis (DIALYSIS_ID, HOSPITAL_ID, PATIENT_NK,PS_ID,DIALYSIS_DATE,SICKBED_NO,DIVISION_ID,EQUIPMENT_ID,ACTUALUF_ML,UFV,TOTAL_REPLACE,TOTAL_TREAT_DURATION,BEFORE_SBP,BEFORE_DBP,AFTER_SBP,AFTER_DBP,START_TIME,END_TIME,CREATE_TIME,SJSCSJ,XGBZ) VALUES "
  304. insertParams := make([]string, 0)
  305. insertData := make([]interface{}, 0)
  306. for _, psm := range psms {
  307. insertParams = append(insertParams, "(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)")
  308. insertData = append(insertData, psm.DialysisId)
  309. insertData = append(insertData, psm.HospitalId)
  310. insertData = append(insertData, psm.PatientNk)
  311. insertData = append(insertData, psm.PsId)
  312. insertData = append(insertData, psm.DialysisDate)
  313. insertData = append(insertData, psm.SickbedNo)
  314. insertData = append(insertData, psm.DivisionId)
  315. insertData = append(insertData, psm.EquipmentId)
  316. insertData = append(insertData, psm.ActualufMl)
  317. insertData = append(insertData, psm.Ufv)
  318. insertData = append(insertData, psm.TotalReplace)
  319. insertData = append(insertData, psm.TotalTreatDuration)
  320. insertData = append(insertData, psm.BeforeSbp)
  321. insertData = append(insertData, psm.BeforeDbp)
  322. insertData = append(insertData, psm.AfterSbp)
  323. insertData = append(insertData, psm.AfterDbp)
  324. insertData = append(insertData, psm.StartTime)
  325. insertData = append(insertData, psm.EndTime)
  326. insertData = append(insertData, psm.CreateTime)
  327. insertData = append(insertData, psm.Sjscsj)
  328. insertData = append(insertData, psm.Xgbz)
  329. }
  330. thisSQL += strings.Join(insertParams, ", ")
  331. err = utx.Exec(thisSQL, insertData...).Error
  332. if err != nil {
  333. utx.Rollback()
  334. return
  335. }
  336. }
  337. utx.Commit()
  338. }
  339. return
  340. }
  341. func BatchCreatePatientOut(patientOuts []*sz.TempHdPatientOut, rdb *gorm.DB) (err error) {
  342. if len(patientOuts) > 0 {
  343. utx := rdb.Begin()
  344. if len(patientOuts) > 0 {
  345. thisSQL := "INSERT INTO t_hd_patient_out (HOSPITAL_ID, PATIENT_NK,SEQUELAE_DATE,SEQUELAE_TYPE,CREATE_TIME,SJSCSJ,XGBZ) VALUES "
  346. insertParams := make([]string, 0)
  347. insertData := make([]interface{}, 0)
  348. for _, out := range patientOuts {
  349. insertParams = append(insertParams, "(?,?,?,?,?,?,?)")
  350. insertData = append(insertData, out.HospitalId)
  351. insertData = append(insertData, out.PatientNk)
  352. insertData = append(insertData, out.SequelaeDate)
  353. insertData = append(insertData, out.SequelaeType)
  354. insertData = append(insertData, out.CreateTime)
  355. insertData = append(insertData, out.Sjscsj)
  356. insertData = append(insertData, out.Xgbz)
  357. }
  358. thisSQL += strings.Join(insertParams, ", ")
  359. err = utx.Exec(thisSQL, insertData...).Error
  360. if err != nil {
  361. utx.Rollback()
  362. return
  363. }
  364. }
  365. utx.Commit()
  366. }
  367. return
  368. }
  369. func BatchCreateDoctorsAdvice(advices []*sz.TempHdDoctorsAdvice, rdb *gorm.DB) (err error) {
  370. if len(advices) > 0 {
  371. utx := rdb.Begin()
  372. if len(advices) > 0 {
  373. thisSQL := "INSERT INTO t_hd_doctors_advice (MEDICAL_ORDER_ID, HOSPITAL_ID,DIALYSIS_ID,ORDER_TYPE,PATIENT_NK,DIALYSIS_DURATION,BLOOD_VOL,CREATE_TIME,SJSCSJ,XGBZ) VALUES "
  374. insertParams := make([]string, 0)
  375. insertData := make([]interface{}, 0)
  376. for _, advice := range advices {
  377. insertParams = append(insertParams, "(?,?,?,?,?,?,?,?,?,?)")
  378. insertData = append(insertData, advice.MedicalOrDerId)
  379. insertData = append(insertData, advice.HospitalId)
  380. insertData = append(insertData, advice.DialysisId)
  381. insertData = append(insertData, advice.OrderType)
  382. insertData = append(insertData, advice.PatientNk)
  383. insertData = append(insertData, advice.DialysisDuration)
  384. insertData = append(insertData, advice.BloodVol)
  385. insertData = append(insertData, advice.CreateTime)
  386. insertData = append(insertData, advice.Sjscsj)
  387. insertData = append(insertData, advice.Xgbz)
  388. }
  389. thisSQL += strings.Join(insertParams, ", ")
  390. err = utx.Exec(thisSQL, insertData...).Error
  391. if err != nil {
  392. utx.Rollback()
  393. return
  394. }
  395. }
  396. utx.Commit()
  397. }
  398. return
  399. }
  400. func BatchCreateMonitor(advices []*sz.TempHdMiddle, rdb *gorm.DB) (err error) {
  401. if len(advices) > 0 {
  402. utx := rdb.Begin()
  403. if len(advices) > 0 {
  404. thisSQL := "INSERT INTO t_hd_middle (HOSPITAL_ID, PATIENT_NK,DIALYSIS_ID,MONITOR_TIME,SBP,DBP,CREATE_TIME,SJSCSJ,XGBZ) VALUES "
  405. insertParams := make([]string, 0)
  406. insertData := make([]interface{}, 0)
  407. for _, advice := range advices {
  408. insertParams = append(insertParams, "(?,?,?,?,?,?,?,?,?)")
  409. insertData = append(insertData, advice.HospitalId)
  410. insertData = append(insertData, advice.PatientNk)
  411. insertData = append(insertData, advice.DialysisId)
  412. insertData = append(insertData, advice.MonitorTime)
  413. insertData = append(insertData, advice.Sbp)
  414. insertData = append(insertData, advice.Dbp)
  415. insertData = append(insertData, advice.CreateTime)
  416. insertData = append(insertData, advice.Sjscsj)
  417. insertData = append(insertData, advice.Xgbz)
  418. }
  419. thisSQL += strings.Join(insertParams, ", ")
  420. err = utx.Exec(thisSQL, insertData...).Error
  421. if err != nil {
  422. utx.Rollback()
  423. return
  424. }
  425. }
  426. utx.Commit()
  427. }
  428. return
  429. }
  430. func FindOrgOtherMachineData(org_id int64, lastUploadTime int64, nowTime int64) (waterMachine []*models.VMDeviceAddmacher, err error) {
  431. db := readUserDb.Model(&models.VMDeviceAddmacher{}).Where("status = 1 AND user_org_id = ? AND (device_type = 1 OR device_type = 3)", org_id)
  432. db = db.Where("ctime >= ? AND ctime <= ?", lastUploadTime, nowTime)
  433. err = db.Find(&waterMachine).Error
  434. return
  435. }
  436. func FindOrgMachineRepairData(org_id int64, lastUploadTime int64, nowTime int64) (waterMachine []*models.DeviceRepair, err error) {
  437. db := readUserDb.Model(&models.DeviceRepair{}).Where("status = 1 AND user_org_id = ?", org_id).Preload("VMDeviceAddmacher", "status = 1")
  438. db = db.Where("ctime >= ? AND ctime <= ?", lastUploadTime, nowTime)
  439. err = db.Find(&waterMachine).Error
  440. return
  441. }
  442. func BatchCreateOtherMachineRecord(wms []*sz.TempHdOtherMachine, rdb *gorm.DB) (err error) {
  443. if len(wms) > 0 {
  444. utx := rdb.Begin()
  445. if len(wms) > 0 {
  446. thisSQL := "INSERT INTO t_hd_other_machine (HOSPITAL_ID, EQUIPMENT_ID, EQUIPMENT_BRAND, EQUIPMENT_MODEL, ENABLE_TIME,DISCARDED_TIME,XGBZ,CREATE_TIME,UPDATE_TIME,SJSCSJ) VALUES "
  447. insertParams := make([]string, 0)
  448. insertData := make([]interface{}, 0)
  449. for _, wm := range wms {
  450. insertParams = append(insertParams, "(?,?,?,?,?,?,?,?,?,?)")
  451. insertData = append(insertData, wm.HospitalId)
  452. insertData = append(insertData, wm.EquipmentId)
  453. insertData = append(insertData, wm.EquipmentBrand)
  454. insertData = append(insertData, wm.EquipmentModel)
  455. insertData = append(insertData, wm.EnableTime)
  456. insertData = append(insertData, wm.DiscardedTime)
  457. insertData = append(insertData, wm.Xgbz)
  458. insertData = append(insertData, wm.CreateTime)
  459. insertData = append(insertData, wm.UpdateTime)
  460. insertData = append(insertData, wm.Sjscsj)
  461. }
  462. thisSQL += strings.Join(insertParams, ", ")
  463. err = utx.Exec(thisSQL, insertData...).Error
  464. if err != nil {
  465. utx.Rollback()
  466. return
  467. }
  468. }
  469. utx.Commit()
  470. }
  471. return
  472. }
  473. func BatchCreateMainTain(maintain []*sz.TempHdMaintain, rdb *gorm.DB) (err error) {
  474. if len(maintain) > 0 {
  475. utx := rdb.Begin()
  476. if len(maintain) > 0 {
  477. thisSQL := "INSERT INTO t_hd_maintain (HOSPITAL_ID, EQUIPMENT_ID, EQUIPMENT_TYPE, REPAIR_TIME, XGBZ,CREATE_TIME,SJSCSJ) VALUES "
  478. insertParams := make([]string, 0)
  479. insertData := make([]interface{}, 0)
  480. for _, wm := range maintain {
  481. insertParams = append(insertParams, "(?,?,?,?,?,?,?)")
  482. insertData = append(insertData, wm.HospitalId)
  483. insertData = append(insertData, wm.EquipmentId)
  484. insertData = append(insertData, wm.EquipmentType)
  485. insertData = append(insertData, wm.RepairTime)
  486. insertData = append(insertData, wm.Xgbz)
  487. insertData = append(insertData, wm.CreateTime)
  488. insertData = append(insertData, wm.Sjscsj)
  489. }
  490. thisSQL += strings.Join(insertParams, ", ")
  491. err = utx.Exec(thisSQL, insertData...).Error
  492. if err != nil {
  493. utx.Rollback()
  494. return
  495. }
  496. }
  497. utx.Commit()
  498. }
  499. return
  500. }
  501. func FindOrgMachineData(org_id int64, lastUploadTime int64, nowTime int64) (waterMachine []*models.VMDeviceAddmacher, err error) {
  502. db := readUserDb.Model(&models.VMDeviceAddmacher{}).Where("status = 1 AND user_org_id = ?", org_id).Preload("DeviceNumber", "status = 1")
  503. db = db.Where("ctime >= ? AND ctime <= ?", lastUploadTime, nowTime)
  504. err = db.Find(&waterMachine).Error
  505. return
  506. }
  507. func BatchCreateHDMRecord(wms []*sz.TempHdDm, rdb *gorm.DB) (err error) {
  508. if len(wms) > 0 {
  509. utx := rdb.Begin()
  510. if len(wms) > 0 {
  511. thisSQL := "INSERT INTO t_hd_dm (HOSPITAL_ID, EQUIPMENT_ID,SICKBED_NO, EQUIPMENT_BRAND, EQUIPMENT_MODEL, ENABLE_TIME,DISCARDED_TIME,STATUS,EQUIPMENT_TYPE, XGBZ,CREATE_TIME,UPDATE_TIME,SJSCSJ) VALUES "
  512. insertParams := make([]string, 0)
  513. insertData := make([]interface{}, 0)
  514. for _, wm := range wms {
  515. insertParams = append(insertParams, "(?,?,?,?,?,?,?,?,?,?,?,?,?)")
  516. insertData = append(insertData, wm.HospitalId)
  517. insertData = append(insertData, wm.EquipmentId)
  518. insertData = append(insertData, wm.SickbedNo)
  519. insertData = append(insertData, wm.EquipmentBrand)
  520. insertData = append(insertData, wm.EquipmentModel)
  521. insertData = append(insertData, wm.EnableTime)
  522. insertData = append(insertData, wm.DiscardedTime)
  523. insertData = append(insertData, wm.Status)
  524. insertData = append(insertData, wm.EquipmentType)
  525. insertData = append(insertData, wm.Xgbz)
  526. insertData = append(insertData, wm.CreateTime)
  527. insertData = append(insertData, wm.UpdateTime)
  528. insertData = append(insertData, wm.Sjscsj)
  529. }
  530. thisSQL += strings.Join(insertParams, ", ")
  531. err = utx.Exec(thisSQL, insertData...).Error
  532. if err != nil {
  533. utx.Rollback()
  534. return
  535. }
  536. }
  537. utx.Commit()
  538. }
  539. return
  540. }