gobal_config_service.go 6.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
  1. package service
  2. import (
  3. "XT_New/models"
  4. "github.com/jinzhu/gorm"
  5. )
  6. func CreateAutomaticReduceRecord(config *models.GobalConfig) (err error) {
  7. err = writeDb.Model(&models.GobalConfig{}).Create(config).Error
  8. return
  9. }
  10. func FindAutomaticReduceRecordByOrgId(org_id int64) (err error, config models.GobalConfig) {
  11. err = readDb.Model(&models.GobalConfig{}).Where("status = 1 AND org_id = ?", org_id).Find(&config).Error
  12. return
  13. }
  14. func UpdateAutomaticReduceRecord(config *models.GobalConfig) (err error) {
  15. err = writeDb.Save(config).Error
  16. return
  17. }
  18. func CreatePrintTemplateRecord(template *models.GobalTemplate) (err error) {
  19. err = writeDb.Model(&models.GobalTemplate{}).Create(template).Error
  20. return
  21. }
  22. func FindPrintTemplateByOrgId(org_id int64) (err error, template models.GobalTemplate) {
  23. err = readDb.Model(&models.GobalTemplate{}).Where("status = 1 AND org_id = ?", org_id).Find(&template).Error
  24. return
  25. }
  26. func UpdatePrintTemplate(template *models.GobalTemplate) (err error) {
  27. err = writeDb.Save(template).Error
  28. return
  29. }
  30. func CreateConfigData(config *models.DataUploadConfig) (err error) {
  31. err = writeDb.Create(config).Error
  32. return
  33. }
  34. func SaveConfigData(config *models.DataUploadConfig) (err error) {
  35. err = writeDb.Save(config).Error
  36. return
  37. }
  38. func GetConfigData(org_id int64, config_type int64) (config models.DataUploadConfig, err error) {
  39. err = readDb.Model(&models.DataUploadConfig{}).Where("status = 1 AND org_id = ? AND config_type = ?", org_id, config_type).First(&config).Error
  40. return
  41. }
  42. func GetDockingStatus(config_type int64, province int64, city int64) (config models.DockingStatus, err error) {
  43. err = readDb.Model(&models.DockingStatus{}).Where("status = 1 AND docking_type = ? AND province_id = ? AND city_id = ?", config_type, province, city).First(&config).Error
  44. return
  45. }
  46. func GetConfigDataById(id int64) (config models.DataUploadConfig, err error) {
  47. err = readDb.Model(&models.DataUploadConfig{}).Where("id = ?", id).First(&config).Error
  48. return
  49. }
  50. func FindDoctorAdviceRecordByOrgId(org_id int64) (err error, config models.DoctorAdviceConfig) {
  51. err = readDb.Model(&models.DoctorAdviceConfig{}).Where("status = 1 AND user_org_id = ?", org_id).Find(&config).Error
  52. return
  53. }
  54. func CreateDoctorAdviceRecord(config *models.DoctorAdviceConfig) (err error) {
  55. err = writeDb.Model(&models.DoctorAdviceConfig{}).Create(config).Error
  56. return
  57. }
  58. func UpdateDoctorAdviceRecord(config *models.DoctorAdviceConfig) (err error) {
  59. err = writeDb.Save(config).Error
  60. return
  61. }
  62. func UpdateFiledConfig(org_id int64) (err error) {
  63. err = writeDb.Model(&models.FiledConfig{}).Where("org_id = ? AND sys_module = 0", org_id).Updates(map[string]interface{}{"is_show": 1}).Error
  64. return
  65. }
  66. func FindAllHideFiledConfig(template_id int64) (err error, config []*models.FiledConfig) {
  67. err = readDb.Model(&models.FiledConfig{}).Where("sys_module = ? AND is_show = 2", template_id).Find(&config).Error
  68. return
  69. }
  70. func UpdateShowFieldConfig(org_id int64, fileds []string) (err error) {
  71. err = writeDb.Model(&models.FiledConfig{}).Where("org_id = ? AND filed_name in (?) AND sys_module = 0 ", org_id, fileds).Updates(map[string]interface{}{"is_show": 2}).Error
  72. return
  73. }
  74. func FindAllAdviceParentTemplate(org_id int64) (template []*models.DoctorAdviceParentTemplate) {
  75. readDb.Model(&models.DoctorAdviceParentTemplate{}).Preload("DoctorAdviceTemplate", func(db *gorm.DB) *gorm.DB {
  76. return db.Preload("SubDoctorAdviceTemplate", "status = 1 AND org_id = ?", org_id).Where("status = 1 AND parent_id = 0 AND org_id = ?", org_id)
  77. }).Where("status = 1 AND org_id = ? ", org_id).Find(&template)
  78. return
  79. }
  80. func CreateDoctorParentTemplate(template *models.DoctorAdviceParentTemplate) (err error) {
  81. err = writeDb.Create(&template).Error
  82. return
  83. }
  84. func FindAllAdviceTemplates(org_id int64, parent_template_id int64) (template []*models.DoctorAdviceTemplate, err error) {
  85. err = readDb.Model(&models.DoctorAdviceTemplate{}).Where("status = 1 AND org_id = ? AND template_id = ?", org_id, parent_template_id).Find(&template).Error
  86. return
  87. }
  88. func CreateDoctorTemplate(template *models.DoctorAdviceTemplate) (err error) {
  89. err = writeDb.Create(&template).Error
  90. return
  91. }
  92. func CreateSystemDialysisSolution(solution *models.SystemPrescription) (err error) {
  93. err = writeDb.Create(solution).Error
  94. return
  95. }
  96. func UpdateSystemDialysisSolution(solution *models.SystemPrescription) (err error) {
  97. err = writeDb.Save(solution).Error
  98. return
  99. }
  100. func FindSystemDialysisSolution(orgID int64, id int64) (solution models.SystemPrescription, err error) {
  101. err = readDb.Model(&models.SystemPrescription{}).Where("id = ? and status=1 and user_org_id=?", id, orgID).First(&solution).Error
  102. return
  103. }
  104. func FindAllSystemPrescription(orgID int64) (solution []*models.SystemPrescription, err error) {
  105. err = readDb.Model(&models.SystemPrescription{}).Where("status=1 and user_org_id=?", orgID).Find(&solution).Error
  106. return
  107. }
  108. func FindSystemDialysisPrescriptionByMode(orgID int64, id int64) (solution models.SystemPrescription, err error) {
  109. err = readDb.Model(&models.SystemPrescription{}).Where("mode_id = ? and status=1 and user_org_id=?", id, orgID).First(&solution).Error
  110. return
  111. }
  112. func CreateAdviceInitConfig(adviceInit *models.AdviceInit) (err error) {
  113. err = writeDb.Create(&adviceInit).Error
  114. return
  115. }
  116. func FindAdviceInitConfig(org_id int64) (adviceInit models.AdviceInit, err error) {
  117. err = readDb.Model(&models.AdviceInit{}).Where("user_org_id = ? AND status = 1 ", org_id).First(&adviceInit).Error
  118. return
  119. }
  120. func GetPrint(ids []int64, orgid int64) (doctor []*models.DoctorAdvice, err error) {
  121. if len(ids) == 1 {
  122. err = XTReadDB().Model(&doctor).Where("groupno = ? and user_org_id = ?", ids[0], orgid).Find(&doctor).Error
  123. } else {
  124. err = XTReadDB().Model(&doctor).Where("groupno IN(?) and user_org_id = ?", ids, orgid).Find(&doctor).Error
  125. }
  126. return doctor, err
  127. }
  128. func GetExportLogByType(org_id int64, log_type int64) (log []*models.ExportLog, err error) {
  129. err = readDb.Model(&models.ExportLog{}).Where("user_org_id = ? AND status = 1 AND log_type = ?", org_id, log_type).
  130. Preload("ExportErrLog", "status = 1").Order("export_time desc").Find(&log).Error
  131. return
  132. }