data.go 7.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193
  1. package service
  2. import (
  3. "XT_New/models"
  4. _ "github.com/astaxie/beego"
  5. _ "strconv"
  6. _ "strings"
  7. "time"
  8. )
  9. //GetPatientList 返回患者的列表
  10. func GetConfigList(orgID int64) (dataconfig interface{}, err error) {
  11. var configList []*models.Dataconfig
  12. err = readDb.Model(&models.Dataconfig{}).Where("(org_id in (0,?) and status = 1) or (status = 0 and delete_id_system > 0 and org_id = ?)", orgID, orgID).Order("orders desc, id asc").Find(&configList).Error
  13. if err != nil {
  14. return nil, err
  15. }
  16. // configResult := make([]*ConfigViewModel,0)
  17. childConfig := make(map[int64][]*models.Dataconfig)
  18. resultConfig := make(map[string][]*models.ConfigViewModel)
  19. deleteSystemChilds := make([]*models.Dataconfig, 0)
  20. editSystemChilds := make([]*models.Dataconfig, 0)
  21. for _, config := range configList {
  22. if config.Status == 1 && config.DeleteIdSystem > 0 {
  23. editSystemChilds = append(editSystemChilds, config)
  24. }
  25. if config.Status == 0 && config.DeleteIdSystem > 0 {
  26. deleteSystemChilds = append(deleteSystemChilds, config)
  27. }
  28. }
  29. continueFlag := false
  30. for _, config := range configList {
  31. continueFlag = false
  32. if config.ParentId == 0 {
  33. newConfig := &models.ConfigViewModel{
  34. ID: config.ID,
  35. ParentId: config.ParentId,
  36. Module: config.Module,
  37. OrgId: config.OrgId,
  38. Name: config.Name,
  39. FieldName: config.FieldName,
  40. Value: config.Value,
  41. CreateUserId: config.CreateUserId,
  42. Status: config.Status,
  43. Remark: config.Remark,
  44. Title: config.Title,
  45. Content: config.Content,
  46. }
  47. // configResult = append(configResult,newConfig)
  48. result := resultConfig[config.Module]
  49. if result == nil {
  50. result = make([]*models.ConfigViewModel, 0)
  51. }
  52. for _, vm := range editSystemChilds {
  53. if vm.DeleteIdSystem == config.ID {
  54. continueFlag = true
  55. break
  56. }
  57. }
  58. for _, _vm := range deleteSystemChilds {
  59. if _vm.DeleteIdSystem == config.ID {
  60. continueFlag = true
  61. break
  62. }
  63. }
  64. if config.OrgId != 0 && config.Status == 0 && config.DeleteIdSystem > 0 {
  65. continue
  66. }
  67. if continueFlag {
  68. continue
  69. }
  70. result = append(result, newConfig)
  71. resultConfig[config.Module] = result
  72. } else {
  73. childs := childConfig[config.ParentId]
  74. if childs == nil {
  75. childs = make([]*models.Dataconfig, 0)
  76. }
  77. continueFlag := false
  78. for _, vm := range editSystemChilds {
  79. if vm.DeleteIdSystem == config.ID {
  80. continueFlag = true
  81. break
  82. }
  83. }
  84. for _, _vm := range deleteSystemChilds {
  85. if _vm.DeleteIdSystem == config.ID {
  86. continueFlag = true
  87. break
  88. }
  89. }
  90. if config.OrgId != 0 && config.Status == 0 && config.DeleteIdSystem > 0 {
  91. continue
  92. }
  93. if continueFlag {
  94. continue
  95. }
  96. childs = append(childs, config)
  97. childConfig[config.ParentId] = childs
  98. }
  99. }
  100. for _, vm := range resultConfig {
  101. for _, _vm := range vm {
  102. _vm.Childs = childConfig[_vm.ID]
  103. }
  104. // vm.Childs = childConfig[vm.ID]
  105. }
  106. return resultConfig, err
  107. }
  108. func FindConfigByFieldname(module string, field_name string, org_id int64) (dataconfig models.Dataconfig, err error) {
  109. err = readDb.Model(&models.Dataconfig{}).Where("module=? and field_name=? and org_id in (0,?) and status = 1", module, field_name, org_id).First(&dataconfig).Error
  110. return
  111. }
  112. func FindConfigByTitle(module string, title string, org_id int64) (dataconfig models.Dataconfig, err error) {
  113. err = readDb.Model(&models.Dataconfig{}).Where("module=? and title=? and org_id in (0,?) and status = 1", module, title, org_id).First(&dataconfig).Error
  114. return
  115. }
  116. func FindConfigByName(module string, name string, parent_id int64, org_id int64) (dataconfig models.Dataconfig, err error) {
  117. err = readDb.Model(&models.Dataconfig{}).Where("module=? and name=? and parent_id=? and org_id in (0,?) and status = 1", module, name, parent_id, org_id).First(&dataconfig).Error
  118. return
  119. }
  120. func FindConfigByNameForUpdate(module string, name string, parent_id int64, org_id int64, id int64) (dataconfig models.Dataconfig, err error) {
  121. err = readDb.Model(&models.Dataconfig{}).Where("module=? and name=? and parent_id=? and org_id in (0,?) and id != ? and status = 1", module, name, parent_id, org_id, id).First(&dataconfig).Error
  122. return
  123. }
  124. func FindConfigByTitleForUpdate(module string, title string, org_id int64, id int64) (dataconfig models.Dataconfig, err error) {
  125. err = readDb.Model(&models.Dataconfig{}).Where("module=? and title=? and org_id in (0,?) and id != ? and status = 1", module, title, org_id, id).First(&dataconfig).Error
  126. return
  127. }
  128. func UpdateChildConfig(dataconfig *models.Dataconfig) (err error) {
  129. err = readDb.Model(&models.Dataconfig{}).Where("id =?", dataconfig.ID).Update(map[string]interface{}{"name": dataconfig.Name, "update_time": dataconfig.UpdatedTime, "remark": dataconfig.Remark, "orders": dataconfig.Order}).Error
  130. return
  131. }
  132. func UpdateTemplate(dataconfig *models.Dataconfig) (err error) {
  133. err = readDb.Model(&models.Dataconfig{}).Where("id =?", dataconfig.ID).Update(map[string]interface{}{"title": dataconfig.Title, "content": dataconfig.Content, "update_time": dataconfig.UpdatedTime, "remark": dataconfig.Remark}).Error
  134. return
  135. }
  136. func CreateConfig(dataconfig *models.Dataconfig) (err error) {
  137. // readDb.Model(&models.Dataconfig{}).Where("module = ? and parent_id = 0 and org_id in (0,?)",dataconfig.Module,dataconfig.OrgId).Count(&total)
  138. err = readDb.Create(&dataconfig).Error
  139. return
  140. }
  141. func GetChildValue(module string, parent_id int64, org_id int64) (value int) {
  142. readDb.Model(&models.Dataconfig{}).Where("module=? and parent_id=? and org_id in (0,?)", module, parent_id, org_id).Count(&value)
  143. return
  144. }
  145. func DeleteChildConfig(dataconfig *models.Dataconfig) (err error) {
  146. err = readDb.Model(&models.Dataconfig{}).Where("id =?", dataconfig.ID).Update(map[string]interface{}{"status": dataconfig.Status, "update_time": dataconfig.UpdatedTime}).Error
  147. return
  148. }
  149. func FindFiledByOrgId(org_id int64) (filedConfig []*models.FiledConfig, err error) {
  150. err = readDb.Model(&models.FiledConfig{}).Where("org_id =? AND sys_module = 0", org_id).Find(&filedConfig).Error
  151. return
  152. }
  153. func BatchInsertFiledConfig(org_id int64) (err error) {
  154. err = readDb.Exec("INSERT INTO sgj_xt.xt_filed_config ( org_id, module, filed_name, filed_name_cn, is_show ) SELECT ?, module, filed_name, filed_name_cn, is_show FROM sgj_xt.xt_filed_config WHERE org_id = 0 AND is_show = 1", org_id).Error
  155. return
  156. }
  157. func ShowFiledConfig(org_id int64, isShow int, id int64) (err error) {
  158. err = readDb.Model(&models.FiledConfig{}).Where("org_id = ? AND id = ?", org_id, id).Updates(map[string]interface{}{"ctime": time.Now().Unix(), "mtime": time.Now().Unix(), "is_show": isShow}).Error
  159. return
  160. }
  161. func FindSysDialysisFiledByOrgId() (filedConfig []*models.FiledConfig, err error) {
  162. err = readDb.Model(&models.FiledConfig{}).Where("org_id =? AND id in (11250,11251,11252,11253,11254,11255,11256,11257,11258,11259,11260,11261,11262)", 0).Find(&filedConfig).Error
  163. return
  164. }
  165. func BatchInsertFiledSystemConfig(org_id int64) (err error) {
  166. err = readDb.Exec("INSERT INTO sgj_xt.xt_filed_config ( org_id, module, filed_name, filed_name_cn, is_show ) SELECT ?, module, filed_name, filed_name_cn, is_show FROM sgj_xt.xt_filed_config WHERE org_id = 9442", org_id).Error
  167. return
  168. }