city_data_uoload_service.go 21KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557
  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.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(hospital *sz.TempHdHospital) (err error) {
  66. err = writeDb.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.VMSchedule, err error) {
  74. db := readDb.Model(&models.VMSchedule{}).Where("status = 1 AND user_org_id = ? ", org_id).
  75. Preload("DeviceNumber", "status = 1").
  76. Preload("VMDialysisPrescription", "status = 1").
  77. Preload("AssessmentBeforeDislysis", "status = 1").
  78. Preload("AssessmentAfterDislysis", "status = 1").
  79. Preload("DialysisOrder", "status = 1").
  80. Preload("MonitoringRecord", "status = 1")
  81. if lastUploadTime != 0 && nowTime != 0 {
  82. db = db.Where("created_time >= ? AND created_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_shift (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_shift (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 BatchCreatePatientOut(patientOuts []*sz.TempHdPatientOut, rdb *gorm.DB) (err error) {
  300. if len(patientOuts) > 0 {
  301. utx := rdb.Begin()
  302. if len(patientOuts) > 0 {
  303. thisSQL := "INSERT INTO t_hd_patient_out (HOSPITAL_ID, PATIENT_NK,SEQUELAE_DATE,SEQUELAE_TYPE,CREATE_TIME,SJSCSJ,XGBZ) VALUES "
  304. insertParams := make([]string, 0)
  305. insertData := make([]interface{}, 0)
  306. for _, out := range patientOuts {
  307. insertParams = append(insertParams, "(?,?,?,?,?,?,?)")
  308. insertData = append(insertData, out.HospitalId)
  309. insertData = append(insertData, out.PatientNk)
  310. insertData = append(insertData, out.SequelaeDate)
  311. insertData = append(insertData, out.SequelaeType)
  312. insertData = append(insertData, out.CreateTime)
  313. insertData = append(insertData, out.Sjscsj)
  314. insertData = append(insertData, out.Xgbz)
  315. }
  316. thisSQL += strings.Join(insertParams, ", ")
  317. err = utx.Exec(thisSQL, insertData...).Error
  318. if err != nil {
  319. utx.Rollback()
  320. return
  321. }
  322. }
  323. utx.Commit()
  324. }
  325. return
  326. }
  327. func BatchCreateDoctorsAdvice(advices []*sz.TempHdDoctorsAdvice, rdb *gorm.DB) (err error) {
  328. if len(advices) > 0 {
  329. utx := rdb.Begin()
  330. if len(advices) > 0 {
  331. 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 "
  332. insertParams := make([]string, 0)
  333. insertData := make([]interface{}, 0)
  334. for _, advice := range advices {
  335. insertParams = append(insertParams, "(?,?,?,?,?,?,?,?,?,?)")
  336. insertData = append(insertData, advice.MedicalOrDerId)
  337. insertData = append(insertData, advice.HospitalId)
  338. insertData = append(insertData, advice.DialysisId)
  339. insertData = append(insertData, advice.OrderType)
  340. insertData = append(insertData, advice.PatientNk)
  341. insertData = append(insertData, advice.DialysisDuration)
  342. insertData = append(insertData, advice.BloodVol)
  343. insertData = append(insertData, advice.CreateTime)
  344. insertData = append(insertData, advice.Sjscsj)
  345. insertData = append(insertData, advice.Xgbz)
  346. }
  347. thisSQL += strings.Join(insertParams, ", ")
  348. err = utx.Exec(thisSQL, insertData...).Error
  349. if err != nil {
  350. utx.Rollback()
  351. return
  352. }
  353. }
  354. utx.Commit()
  355. }
  356. return
  357. }
  358. func BatchCreateMonitor(advices []*sz.TempHdMiddle, rdb *gorm.DB) (err error) {
  359. if len(advices) > 0 {
  360. utx := rdb.Begin()
  361. if len(advices) > 0 {
  362. thisSQL := "INSERT INTO t_hd_doctors_advice (HOSPITAL_ID, PATIENT_NK,DIALYSIS_ID,MONITOR_TIME,SBP,DBP,CREATE_TIME,SJSCSJ,XGBZ) VALUES "
  363. insertParams := make([]string, 0)
  364. insertData := make([]interface{}, 0)
  365. for _, advice := range advices {
  366. insertParams = append(insertParams, "(?,?,?,?,?,?,?,?,?,?)")
  367. insertData = append(insertData, advice.HospitalId)
  368. insertData = append(insertData, advice.PatientNk)
  369. insertData = append(insertData, advice.DialysisId)
  370. insertData = append(insertData, advice.MonitorTime)
  371. insertData = append(insertData, advice.Sbp)
  372. insertData = append(insertData, advice.Dbp)
  373. insertData = append(insertData, advice.CreateTime)
  374. insertData = append(insertData, advice.Sjscsj)
  375. insertData = append(insertData, advice.Xgbz)
  376. }
  377. thisSQL += strings.Join(insertParams, ", ")
  378. err = utx.Exec(thisSQL, insertData...).Error
  379. if err != nil {
  380. utx.Rollback()
  381. return
  382. }
  383. }
  384. utx.Commit()
  385. }
  386. return
  387. }
  388. func FindOrgOtherMachineData(org_id int64, lastUploadTime int64, nowTime int64) (waterMachine []*models.VMDeviceAddmacher, err error) {
  389. db := readUserDb.Model(&models.VMDeviceAddmacher{}).Where("status = 1 AND user_org_id = ? AND (device_type = 1 OR device_type = 3)", org_id)
  390. db = db.Where("ctime >= ? AND ctime <= ?", lastUploadTime, nowTime)
  391. err = db.Find(&waterMachine).Error
  392. return
  393. }
  394. func FindOrgMachineRepairData(org_id int64, lastUploadTime int64, nowTime int64) (waterMachine []*models.DeviceRepair, err error) {
  395. db := readUserDb.Model(&models.DeviceRepair{}).Where("status = 1 AND user_org_id = ?", org_id).Preload("VMDeviceAddmacher", "status = 1")
  396. db = db.Where("ctime >= ? AND ctime <= ?", lastUploadTime, nowTime)
  397. err = db.Find(&waterMachine).Error
  398. return
  399. }
  400. func BatchCreateOtherMachineRecord(wms []*sz.TempHdOtherMachine, rdb *gorm.DB) (err error) {
  401. if len(wms) > 0 {
  402. utx := rdb.Begin()
  403. if len(wms) > 0 {
  404. thisSQL := "INSERT INTO t_hd_wm (HOSPITAL_ID, EQUIPMENT_ID, EQUIPMENT_BRAND, EQUIPMENT_MODEL, ENABLE_TIME,DISCARDED_TIME,XGBZ,CREATE_TIME,UPDATE_TIME,SJSCSJ) VALUES "
  405. insertParams := make([]string, 0)
  406. insertData := make([]interface{}, 0)
  407. for _, wm := range wms {
  408. insertParams = append(insertParams, "(?,?,?,?,?,?,?,?,?,?,?)")
  409. insertData = append(insertData, wm.HospitalId)
  410. insertData = append(insertData, wm.EquipmentId)
  411. insertData = append(insertData, wm.EquipmentBrand)
  412. insertData = append(insertData, wm.EquipmentModel)
  413. insertData = append(insertData, wm.EnableTime)
  414. insertData = append(insertData, wm.DiscardedTime)
  415. insertData = append(insertData, wm.Xgbz)
  416. insertData = append(insertData, wm.CreateTime)
  417. insertData = append(insertData, wm.UpdateTime)
  418. insertData = append(insertData, wm.Sjscsj)
  419. }
  420. thisSQL += strings.Join(insertParams, ", ")
  421. err = utx.Exec(thisSQL, insertData...).Error
  422. if err != nil {
  423. utx.Rollback()
  424. return
  425. }
  426. }
  427. utx.Commit()
  428. }
  429. return
  430. }
  431. func BatchCreateMainTain(maintain []*sz.TempHdMaintain, rdb *gorm.DB) (err error) {
  432. if len(maintain) > 0 {
  433. utx := rdb.Begin()
  434. if len(maintain) > 0 {
  435. thisSQL := "INSERT INTO t_hd_maintain (HOSPITAL_ID, EQUIPMENT_ID, EQUIPMENT_TYPE, REPAIR_TIME, XGBZ,CREATE_TIME,SJSCSJ) VALUES "
  436. insertParams := make([]string, 0)
  437. insertData := make([]interface{}, 0)
  438. for _, wm := range maintain {
  439. insertParams = append(insertParams, "(?,?,?,?,?,?,?)")
  440. insertData = append(insertData, wm.HospitalId)
  441. insertData = append(insertData, wm.EquipmentId)
  442. insertData = append(insertData, wm.EquipmentType)
  443. insertData = append(insertData, wm.RepairTime)
  444. insertData = append(insertData, wm.Xgbz)
  445. insertData = append(insertData, wm.CreateTime)
  446. insertData = append(insertData, wm.Sjscsj)
  447. }
  448. thisSQL += strings.Join(insertParams, ", ")
  449. err = utx.Exec(thisSQL, insertData...).Error
  450. if err != nil {
  451. utx.Rollback()
  452. return
  453. }
  454. }
  455. utx.Commit()
  456. }
  457. return
  458. }
  459. func FindOrgMachineData(org_id int64, lastUploadTime int64, nowTime int64) (waterMachine []*models.VMDeviceAddmacher, err error) {
  460. db := readUserDb.Model(&models.VMDeviceAddmacher{}).Where("status = 1 AND user_org_id = ?", org_id).Preload("DeviceNumber", "status = 1")
  461. db = db.Where("ctime >= ? AND ctime <= ?", lastUploadTime, nowTime)
  462. err = db.Find(&waterMachine).Error
  463. return
  464. }
  465. func BatchCreateHDMRecord(wms []*sz.TempHdDm, rdb *gorm.DB) (err error) {
  466. if len(wms) > 0 {
  467. utx := rdb.Begin()
  468. if len(wms) > 0 {
  469. 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 "
  470. insertParams := make([]string, 0)
  471. insertData := make([]interface{}, 0)
  472. for _, wm := range wms {
  473. insertParams = append(insertParams, "(?,?,?,?,?,?,?,?,?,?,?,?,?)")
  474. insertData = append(insertData, wm.HospitalId)
  475. insertData = append(insertData, wm.EquipmentId)
  476. insertData = append(insertData, wm.SickbedNo)
  477. insertData = append(insertData, wm.EquipmentBrand)
  478. insertData = append(insertData, wm.EquipmentModel)
  479. insertData = append(insertData, wm.EnableTime)
  480. insertData = append(insertData, wm.DiscardedTime)
  481. insertData = append(insertData, wm.Status)
  482. insertData = append(insertData, wm.EquipmentType)
  483. insertData = append(insertData, wm.Xgbz)
  484. insertData = append(insertData, wm.CreateTime)
  485. insertData = append(insertData, wm.UpdateTime)
  486. insertData = append(insertData, wm.Sjscsj)
  487. }
  488. thisSQL += strings.Join(insertParams, ", ")
  489. err = utx.Exec(thisSQL, insertData...).Error
  490. if err != nil {
  491. utx.Rollback()
  492. return
  493. }
  494. }
  495. utx.Commit()
  496. }
  497. return
  498. }