app_version.go 6.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227
  1. package service
  2. import (
  3. "XT_New/models"
  4. "github.com/jinzhu/gorm"
  5. "time"
  6. )
  7. func GetAppVersionByAppType(apptype int64) (*models.AppVersion, error) {
  8. var version models.AppVersion
  9. err := readDb.Model(&models.AppVersion{}).Where("app_type=?", apptype).First(&version).Error
  10. if err == gorm.ErrRecordNotFound {
  11. return nil, nil
  12. }
  13. if err != nil {
  14. return nil, err
  15. }
  16. return &version, nil
  17. }
  18. func GetAllAppOrg() ([]*models.OrgApp, error) {
  19. var app []*models.OrgApp
  20. err := readUserDb.Model(&models.OrgApp{}).Where("status = 1 AND org_id > 0").Group("org_id").Find(&app).Error
  21. if err == gorm.ErrRecordNotFound {
  22. return nil, nil
  23. }
  24. if err != nil {
  25. return nil, err
  26. }
  27. return app, nil
  28. }
  29. func GetSystemApp() ([]*models.OrgApp, error) {
  30. var app []*models.OrgApp
  31. err := readDb.Model(&models.OrgApp{}).Where("status = 1 AND org_id = 0 ").Find(&app).Error
  32. if err == gorm.ErrRecordNotFound {
  33. return nil, nil
  34. }
  35. if err != nil {
  36. return nil, err
  37. }
  38. return app, nil
  39. }
  40. func GetApp() ([]*models.OrgApp, error) {
  41. var app []*models.OrgApp
  42. err := readDb.Model(&models.OrgApp{}).Where("status = 1 AND org_id = 0").Find(&app).Error
  43. if err == gorm.ErrRecordNotFound {
  44. return nil, nil
  45. }
  46. if err != nil {
  47. return nil, err
  48. }
  49. return app, nil
  50. }
  51. func GetAppByType(orgID int64, app_type int) (*models.OrgApp, error) {
  52. var apps models.OrgApp
  53. err := readUserDb.Where("app_type = ? AND org_id = ? AND status = 1", app_type, orgID).First(&apps).Error
  54. if err != nil {
  55. return nil, err
  56. }
  57. return &apps, nil
  58. }
  59. func CreateOrgApp(app *models.OrgApp) {
  60. writeUserDb.Create(&app)
  61. }
  62. func GetAllUserRole(org_id int64) (appRole []*models.App_Role) {
  63. if org_id == 0 {
  64. readUserDb.Model(&models.App_Role{}).Where("status = 1").Find(&appRole)
  65. } else {
  66. readUserDb.Model(&models.App_Role{}).Where("status = 1 AND org_id = ? ", org_id).Find(&appRole)
  67. }
  68. return
  69. }
  70. func GetAllUserRoleByUserTypeOne(org_id int) (appRole []*models.App_Role) {
  71. readUserDb.Model(&models.App_Role{}).Where("status = 1 AND user_type = 1").Find(&appRole)
  72. return
  73. }
  74. func GetAllUserRoleByUserTypeOther() (appRole []*models.App_Role) {
  75. //app, _ := GetOrgApp(int64(org_id), 3)
  76. //if org_id == 0 {
  77. readUserDb.Model(&models.App_Role{}).Where("status = 1 AND user_type > 1").Find(&appRole)
  78. //
  79. //} else {
  80. // readUserDb.Model(&models.App_Role{}).Where("status = 1 AND org_id = ? AND user_type > 1 AND app_id = ? ", org_id, app.Id).Find(&appRole)
  81. //
  82. //}
  83. return
  84. }
  85. func FindRoleByUserTypeOne(org_id int64) (role models.Role) {
  86. readUserDb.Model(&models.Role{}).Where("status = 1 AND org_id = ? AND is_system = 2 AND role_name = '医生'", org_id).First(&role)
  87. return
  88. }
  89. func FindRoleByUserTypeTwo(org_id int64) (role models.Role) {
  90. readUserDb.Model(&models.Role{}).Where("status = 1 AND org_id = ? AND is_system = 3 AND role_name = '护士'", org_id).First(&role)
  91. return
  92. }
  93. func GetAllRole() ([]*models.Role, error) {
  94. var app []*models.Role
  95. err := readUserDb.Model(&models.Role{}).Where("status = 1 AND org_id > 0").Group("org_id").Find(&app).Error
  96. if err == gorm.ErrRecordNotFound {
  97. return nil, nil
  98. }
  99. if err != nil {
  100. return nil, err
  101. }
  102. return app, nil
  103. }
  104. func UpdateRoleIds(id int64, ids string) {
  105. writeUserDb.Model(&models.App_Role{}).Where("status = 1 AND id = ?", id).Updates(map[string]interface{}{"role_ids": ids, "mtime": time.Now().Unix()})
  106. }
  107. func GetOrgAppA(orgID int64, app_type int) (*models.OrgApp, error) {
  108. var apps models.OrgApp
  109. err := readUserDb.Where("app_type = ? AND org_id = ? AND status = 1", app_type, orgID).First(&apps).Error
  110. if err != nil {
  111. return nil, err
  112. }
  113. return &apps, nil
  114. }
  115. func GetOrgByIdB(orgID int64) (*models.Org, error) {
  116. var org models.Org
  117. err := readUserDb.Model(&models.Org{}).Where("id = ?", orgID).First(&org).Error
  118. if err != nil {
  119. if err == gorm.ErrRecordNotFound {
  120. return nil, nil
  121. } else {
  122. return nil, err
  123. }
  124. }
  125. return &org, nil
  126. }
  127. func GetOrgAppB(orgID int64, app_type int) (*models.OrgApp, error) {
  128. var apps models.OrgApp
  129. err := readUserDb.Where("app_type = ? AND org_id = ? AND status = 1", app_type, orgID).First(&apps).Error
  130. if err != nil {
  131. return nil, err
  132. }
  133. return &apps, nil
  134. }
  135. func CreateOrgRoleB(role *models.Role) (err error) {
  136. err = writeUserDb.Create(&role).Error
  137. return
  138. }
  139. func CreateRolePurviewB(purview *models.RolePurview) (err error) {
  140. err = writeUserDb.Create(&purview).Error
  141. return
  142. }
  143. func CreateFuncRolePurviewB(purview *models.SgjUserRoleFuncPurview) (err error) {
  144. err = writeUserDb.Create(&purview).Error
  145. return
  146. }
  147. func GetSystemRole(orgID int64) ([]*models.Role, error) {
  148. var roles []*models.Role
  149. err := readUserDb.Where(" org_id = ? AND status = 1 AND is_system > 1", orgID).First(&roles).Error
  150. if err != nil {
  151. return nil, err
  152. }
  153. return roles, nil
  154. }
  155. func HandleData() {
  156. var pe []*models.PredialysisEvaluation
  157. //readDb.Model(&models.DialysisPrescription{}).Where("user_org_id = 12 AND record_date <= 1587571200").Find(&prescription)
  158. //for _, item := range prescription {
  159. // writeDb.Model(&models.AssessmentAfterDislysis{}).Where("user_org_id =12 AND assessment_date = ?", item.RecordDate).Updates(map[string]interface{}{"mtime": time.Now().Unix(), "actual_ultrafiltration": item.Ultrafiltration})
  160. //}
  161. readDb.Model(&models.PredialysisEvaluation{}).Where("status = 1 AND user_org_id = 9538 AND dialysis_order_id > 0").Find(&pe)
  162. for _, item := range pe {
  163. var sch models.Schedule
  164. err := readDb.Model(&models.Schedule{}).Where("status = 1 AND schedule_date = ? AND patient_id = ? AND user_org_id = 9538", item.AssessmentDate, item.PatientId).First(&sch).Error
  165. if err == nil {
  166. if sch.ID > 0 {
  167. order := &models.DialysisOrder{
  168. DialysisDate: sch.ScheduleDate,
  169. UserOrgId: 9538,
  170. PatientId: sch.PatientId,
  171. Stage: 2,
  172. BedID: sch.BedId,
  173. StartNurse: 554,
  174. FinishNurse: 554,
  175. Status: 1,
  176. CreatedTime: sch.ScheduleDate,
  177. UpdatedTime: sch.ScheduleDate,
  178. StartTime: sch.ScheduleDate,
  179. EndTime: sch.ScheduleDate,
  180. PunctureNurse: 554,
  181. Creator: 554,
  182. Modifier: 554,
  183. FinishCreator: 554,
  184. FinishModifier: 554,
  185. SchedualType: sch.ScheduleType,
  186. }
  187. writeDb.Create(&order)
  188. }
  189. }
  190. }
  191. }