admin_service.go 36KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742
  1. // 统计后台的 service
  2. package service
  3. import (
  4. "XT_Admin_Api/models"
  5. "XT_Admin_Api/models/admin_models"
  6. "time"
  7. "github.com/jinzhu/gorm"
  8. )
  9. func GetAdminAccount(account string, password string) (*admin_models.AdminAccount, error) {
  10. var model admin_models.AdminAccount
  11. err := readUserDb.Where("account = ? AND pwd = ? AND status = 1", account, password).First(&model).Error
  12. if err != nil {
  13. if err == gorm.ErrRecordNotFound {
  14. return nil, nil
  15. }
  16. return nil, err
  17. }
  18. return &model, nil
  19. }
  20. // 获取总机构数
  21. func GetTotalOrgCount() (int, error) {
  22. var count int
  23. err := readUserDb.Model(&models.Org{}).Where("status <> 0").Count(&count).Error
  24. if err != nil {
  25. return 0, err
  26. }
  27. return count, nil
  28. }
  29. // 获取一段时间内注册的机构数量
  30. func GetRegistedOrgCountFromDayToDay(from time.Time, to time.Time) (int, error) {
  31. var count int
  32. err := readUserDb.Model(&models.Org{}).Where("status <> 0 AND ctime >= ? AND ctime <= ?", from.Unix(), to.Unix()).Count(&count).Error
  33. if err != nil {
  34. return 0, err
  35. }
  36. return count, nil
  37. }
  38. // 获取一段时间内注册的机构
  39. func GetRegistedOrgsFromDayToDay(from time.Time, to time.Time) ([]*models.Org, error) {
  40. var orgs []*models.Org
  41. err := readUserDb.Model(&models.Org{}).Where("status <> 0 AND ctime >= ? AND ctime <= ?", from.Unix(), to.Unix()).Find(&orgs).Error
  42. if err != nil {
  43. return nil, err
  44. }
  45. return orgs, nil
  46. }
  47. // 获取一段时间内的活跃机构数
  48. func GetActiveOrgCountFromDayToDay(from time.Time, to time.Time) (int, error) {
  49. var count int
  50. rows, err := readUserDb.Raw("SELECT COUNT(DISTINCT org_id) AS count FROM sgj_user_admin_login_log WHERE ctime >= ? AND ctime <= ?", from.Unix(), to.Unix()).Rows()
  51. if err != nil {
  52. return 0, err
  53. }
  54. if rows.Next() {
  55. rows.Scan(&count)
  56. }
  57. return count, nil
  58. }
  59. type ActiveOrgListVM struct {
  60. models.Org
  61. ActiveTime int64 `gorm:"column:active_time" json:"active_time"`
  62. }
  63. // 获取一段时间内的活跃机构
  64. func GetActiveOrgsFromDayToDay(from time.Time, to time.Time) ([]*ActiveOrgListVM, error) {
  65. var orgs []*ActiveOrgListVM
  66. err := readUserDb.Raw("select * from (select log.org_id, org.*, log.ctime as active_time from sgj_user_admin_login_log as log left join sgj_user_org as org on log.org_id = org.id where log.ctime >= ? AND log.ctime <= ? AND org.status <> 0 order by log.ctime desc) as t group by t.org_id;", from.Unix(), to.Unix()).Scan(&orgs).Error
  67. if err != nil {
  68. return nil, err
  69. }
  70. return orgs, nil
  71. }
  72. // 获取一段时间内的活跃账户数
  73. func GetActiveAdminUserCountFromDayToDay(from time.Time, to time.Time) (int, error) {
  74. var count int
  75. rows, err := readUserDb.Raw("SELECT COUNT(DISTINCT admin_user_id) AS count FROM sgj_user_admin_login_log WHERE ctime >= ? AND ctime <= ? AND operate_type = 1", from.Unix(), to.Unix()).Rows()
  76. if err != nil {
  77. return 0, err
  78. }
  79. if rows.Next() {
  80. rows.Scan(&count)
  81. }
  82. return count, nil
  83. }
  84. type ActiveAdminUserListVM struct {
  85. models.App_Role
  86. OrgName string `gorm:"column:org_name" json:"org_name"`
  87. ActiveTime int64 `gorm:"column:active_time" json:"active_time"`
  88. }
  89. // 获取一段时间内的活跃账户
  90. func GetActiveAdminUsersFromDayToDay(from time.Time, to time.Time) ([]*ActiveAdminUserListVM, error) {
  91. var users []*ActiveAdminUserListVM
  92. err := readUserDb.Raw("select * from (select log.admin_user_id as uid, admin.*, org.org_name, log.ctime as active_time from sgj_user_admin_login_log as log left join sgj_user_admin_role as admin on log.admin_user_id = admin.admin_user_id left join sgj_user_org as org on log.org_id = org.id where log.ctime >= ? AND log.ctime <= ? AND log.operate_type = 1 AND admin.status > 0 order by log.ctime desc) as t group by t.uid;", from.Unix(), to.Unix()).Scan(&users).Error
  93. if err != nil {
  94. return nil, err
  95. }
  96. return users, nil
  97. }
  98. // 获取即将到期机构数
  99. func GetWillExpireOrgCountFromDayToDay(from time.Time, to time.Time) (int, error) {
  100. var count int
  101. rows, err := readUserDb.Raw("SELECT COUNT(DISTINCT org_id) AS count FROM sgj_serve_subscibe WHERE period_end >= ? AND period_end <= ? AND state <> 9 GROUP BY org_id;", from.Unix(), to.Unix()).Rows()
  102. if err != nil {
  103. return 0, err
  104. }
  105. if rows.Next() {
  106. rows.Scan(&count)
  107. }
  108. return count, nil
  109. }
  110. // 获取已到期机构数
  111. func GetDidExpiredOrgCountFromDayToDay(from time.Time, to time.Time) (int, error) {
  112. var count int
  113. rows, err := readUserDb.Raw("SELECT COUNT(DISTINCT org_id) AS count FROM sgj_serve_subscibe WHERE period_end >= ? AND period_end <= ? AND state <> 9 GROUP BY org_id;", from.Unix(), to.Unix()).Rows()
  114. if err != nil {
  115. return 0, err
  116. }
  117. if rows.Next() {
  118. rows.Scan(&count)
  119. }
  120. return count, nil
  121. }
  122. type ExpireOrgListVM struct {
  123. OrgID int64 `gorm:"column:org_id" json:"org_id"`
  124. OrgName string `gorm:"column:org_name" json:"org_name"`
  125. PeriodEnd int64 `gorm:"column:period_end" json:"period_end"`
  126. Telephone string `gorm:"column:telephone" json:"telephone"`
  127. ExpireDays int `gorm:"-" json:"expire_days"`
  128. }
  129. // 获取即将到期机构
  130. func GetWillExpireOrgsFromDayToDay(from time.Time, to time.Time) ([]*ExpireOrgListVM, error) {
  131. var vms []*ExpireOrgListVM
  132. err := readUserDb.Raw("select s_o.org_id, s_o.period_end, o.org_name, o.telephone from (select ss.* from (select s.org_id as org_id, s.id as sid, s.period_end from sgj_serve_subscibe as s where s.period_end <= ? AND s.period_end >= ? AND s.state <> 9 order by s.id desc) as ss group by ss.org_id) as s_o left join sgj_user_org as o on o.id = s_o.org_id", to.Unix(), from.Unix()).Scan(&vms).Error
  133. if err != nil {
  134. return nil, err
  135. }
  136. for _, vm := range vms {
  137. vm.ExpireDays = time.Unix(vm.PeriodEnd, 0).Day() - from.Day()
  138. }
  139. return vms, nil
  140. }
  141. // 获取已到期机构
  142. func GetDidExpireOrgsFromDayToDay(from time.Time, to time.Time) ([]*ExpireOrgListVM, error) {
  143. var vms []*ExpireOrgListVM
  144. err := readUserDb.Raw("select s_o.org_id, s_o.period_end, o.org_name, o.telephone from (select ss.* from (select s.org_id as org_id, s.id as sid, s.period_end from sgj_serve_subscibe as s where s.period_end >= ? AND s.period_end <= ? AND s.state <> 9 order by s.id desc) as ss group by ss.org_id) as s_o left join sgj_user_org as o on o.id = s_o.org_id", from.Unix(), to.Unix()).Scan(&vms).Error
  145. if err != nil {
  146. return nil, err
  147. }
  148. for _, vm := range vms {
  149. vm.ExpireDays = to.Day() - time.Unix(vm.PeriodEnd, 0).Day()
  150. }
  151. return vms, nil
  152. }
  153. // 获取一段时间内的透析次数
  154. func GetDialysisTimesFromDayToDay(from time.Time, to time.Time) (int, error) {
  155. var count int
  156. err := readDb.Model(&models.DialysisOrder{}).Where("status > 0 AND dialysis_date >= ? AND dialysis_date <= ?", from.Unix(), to.Unix()).Count(&count).Error
  157. if err != nil {
  158. return 0, err
  159. }
  160. return count, nil
  161. }
  162. // 获取一段时间内的监控次数
  163. func GetMonitoringTimesFromDayToDay(from time.Time, to time.Time) (int, error) {
  164. var count int
  165. err := readDb.Model(&models.MonitoringRecord{}).Where("status > 0 AND monitoring_date >= ? AND monitoring_date <= ?", from.Unix(), to.Unix()).Count(&count).Error
  166. if err != nil {
  167. return 0, err
  168. }
  169. return count, nil
  170. }
  171. // 获取一段时间内新增病人数量
  172. func GetNewPatientCountFromDayToDay(from time.Time, to time.Time) (int, error) {
  173. var count int
  174. err := readDb.Model(&models.Patients{}).Where("status > 0 AND created_time >= ? AND created_time <= ?", from.Unix(), to.Unix()).Count(&count).Error
  175. if err != nil {
  176. return 0, err
  177. }
  178. return count, nil
  179. }
  180. // 获取病人性别分布
  181. func GetPatientGenderDistribution() (int, int, int, error) {
  182. var maleCount, femaleCount, unknowGenderCount int
  183. rows, err := readDb.Raw("SELECT count(id), gender FROM xt_patients WHERE (status > 0) group by gender;").Rows()
  184. if err != nil {
  185. return 0, 0, 0, err
  186. }
  187. for rows.Next() {
  188. var gender, count int
  189. rows.Scan(&count, &gender)
  190. if gender == 1 {
  191. maleCount = count
  192. } else if gender == 2 {
  193. femaleCount = count
  194. } else {
  195. unknowGenderCount = count
  196. }
  197. }
  198. return maleCount, femaleCount, unknowGenderCount, nil
  199. }
  200. // 获取某种传染病的病人数,diseaseType = 0时为没有传染病
  201. // 1乙肝 2丙肝 3艾滋病 4肺结核 5梅毒
  202. func GetInfectiousDiseasePatientCount(diseaseType int) (int, error) {
  203. if diseaseType == 0 {
  204. var count int
  205. rows, err := readDb.Raw("select count(p.id) from xt_patients as p where id not in (select p_d.patient_id from xt_patients_infectious_diseases as p_d where status = 1 group by p_d.patient_id) and status = 1;").Rows()
  206. if err != nil {
  207. return 0, err
  208. }
  209. if rows.Next() {
  210. rows.Scan(&count)
  211. }
  212. return count, nil
  213. } else {
  214. var count int
  215. rows, err := readDb.Raw("select count(distinct patient_id) from xt_patients_infectious_diseases where status = 1 and disease_id = ?;", diseaseType).Rows()
  216. if err != nil {
  217. return 0, err
  218. }
  219. if rows.Next() {
  220. rows.Scan(&count)
  221. }
  222. return count, nil
  223. }
  224. }
  225. // 获取患者年龄分布
  226. func GetPatientAgeDistribution() ([]*PatientAgeCountStruct, error) {
  227. var counts []*PatientAgeCountStruct
  228. err := readDb.Raw(`SELECT nnd AS 'age',COUNT(*) AS 'count' FROM (
  229. SELECT
  230. CASE
  231. WHEN (YEAR(NOW())-DATE_FORMAT(DATE_ADD(FROM_UNIXTIME(0), INTERVAL birthday SECOND),'%Y')-1) + (DATE_FORMAT(DATE_ADD(FROM_UNIXTIME(0), INTERVAL birthday SECOND),'%m%d') <= DATE_FORMAT(NOW(), '%m%d'))<10 THEN '10'
  232. WHEN (YEAR(NOW())-DATE_FORMAT(DATE_ADD(FROM_UNIXTIME(0), INTERVAL birthday SECOND),'%Y')-1) + (DATE_FORMAT(DATE_ADD(FROM_UNIXTIME(0), INTERVAL birthday SECOND),'%m%d') <= DATE_FORMAT(NOW(), '%m%d') )>=10 AND (YEAR(NOW())-DATE_FORMAT(DATE_ADD(FROM_UNIXTIME(0), INTERVAL birthday SECOND),'%Y')-1) + (DATE_FORMAT(DATE_ADD(FROM_UNIXTIME(0), INTERVAL birthday SECOND),'%m%d') <= DATE_FORMAT(NOW(), '%m%d') )<20 THEN '20'
  233. WHEN (YEAR(NOW())-DATE_FORMAT(DATE_ADD(FROM_UNIXTIME(0), INTERVAL birthday SECOND),'%Y')-1) + (DATE_FORMAT(DATE_ADD(FROM_UNIXTIME(0), INTERVAL birthday SECOND),'%m%d') <= DATE_FORMAT(NOW(), '%m%d') )>=20 AND (YEAR(NOW())-DATE_FORMAT(DATE_ADD(FROM_UNIXTIME(0), INTERVAL birthday SECOND),'%Y')-1) + (DATE_FORMAT(DATE_ADD(FROM_UNIXTIME(0), INTERVAL birthday SECOND),'%m%d') <= DATE_FORMAT(NOW(), '%m%d') )<30 THEN '30'
  234. WHEN (YEAR(NOW())-DATE_FORMAT(DATE_ADD(FROM_UNIXTIME(0), INTERVAL birthday SECOND),'%Y')-1) + (DATE_FORMAT(DATE_ADD(FROM_UNIXTIME(0), INTERVAL birthday SECOND),'%m%d') <= DATE_FORMAT(NOW(), '%m%d') )>=30 AND (YEAR(NOW())-DATE_FORMAT(DATE_ADD(FROM_UNIXTIME(0), INTERVAL birthday SECOND),'%Y')-1) + (DATE_FORMAT(DATE_ADD(FROM_UNIXTIME(0), INTERVAL birthday SECOND),'%m%d') <= DATE_FORMAT(NOW(), '%m%d') )<40 THEN '40'
  235. WHEN (YEAR(NOW())-DATE_FORMAT(DATE_ADD(FROM_UNIXTIME(0), INTERVAL birthday SECOND),'%Y')-1) + (DATE_FORMAT(DATE_ADD(FROM_UNIXTIME(0), INTERVAL birthday SECOND),'%m%d') <= DATE_FORMAT(NOW(), '%m%d') )>=40 AND (YEAR(NOW())-DATE_FORMAT(DATE_ADD(FROM_UNIXTIME(0), INTERVAL birthday SECOND),'%Y')-1) + (DATE_FORMAT(DATE_ADD(FROM_UNIXTIME(0), INTERVAL birthday SECOND),'%m%d') <= DATE_FORMAT(NOW(), '%m%d') )<50 THEN '50'
  236. WHEN (YEAR(NOW())-DATE_FORMAT(DATE_ADD(FROM_UNIXTIME(0), INTERVAL birthday SECOND),'%Y')-1) + (DATE_FORMAT(DATE_ADD(FROM_UNIXTIME(0), INTERVAL birthday SECOND),'%m%d') <= DATE_FORMAT(NOW(), '%m%d') )>=50 AND (YEAR(NOW())-DATE_FORMAT(DATE_ADD(FROM_UNIXTIME(0), INTERVAL birthday SECOND),'%Y')-1) + (DATE_FORMAT(DATE_ADD(FROM_UNIXTIME(0), INTERVAL birthday SECOND),'%m%d') <= DATE_FORMAT(NOW(), '%m%d') )<60 THEN '60'
  237. WHEN (YEAR(NOW())-DATE_FORMAT(DATE_ADD(FROM_UNIXTIME(0), INTERVAL birthday SECOND),'%Y')-1) + (DATE_FORMAT(DATE_ADD(FROM_UNIXTIME(0), INTERVAL birthday SECOND),'%m%d') <= DATE_FORMAT(NOW(), '%m%d') )>=60 AND (YEAR(NOW())-DATE_FORMAT(DATE_ADD(FROM_UNIXTIME(0), INTERVAL birthday SECOND),'%Y')-1) + (DATE_FORMAT(DATE_ADD(FROM_UNIXTIME(0), INTERVAL birthday SECOND),'%m%d') <= DATE_FORMAT(NOW(), '%m%d') )<70 THEN '70'
  238. WHEN (YEAR(NOW())-DATE_FORMAT(DATE_ADD(FROM_UNIXTIME(0), INTERVAL birthday SECOND),'%Y')-1) + (DATE_FORMAT(DATE_ADD(FROM_UNIXTIME(0), INTERVAL birthday SECOND),'%m%d') <= DATE_FORMAT(NOW(), '%m%d') )>=70 AND (YEAR(NOW())-DATE_FORMAT(DATE_ADD(FROM_UNIXTIME(0), INTERVAL birthday SECOND),'%Y')-1) + (DATE_FORMAT(DATE_ADD(FROM_UNIXTIME(0), INTERVAL birthday SECOND),'%m%d') <= DATE_FORMAT(NOW(), '%m%d') )<80 THEN '80'
  239. WHEN (YEAR(NOW())-DATE_FORMAT(DATE_ADD(FROM_UNIXTIME(0), INTERVAL birthday SECOND),'%Y')-1) + (DATE_FORMAT(DATE_ADD(FROM_UNIXTIME(0), INTERVAL birthday SECOND),'%m%d') <= DATE_FORMAT(NOW(), '%m%d') )>=80 AND (YEAR(NOW())-DATE_FORMAT(DATE_ADD(FROM_UNIXTIME(0), INTERVAL birthday SECOND),'%Y')-1) + (DATE_FORMAT(DATE_ADD(FROM_UNIXTIME(0), INTERVAL birthday SECOND),'%m%d') <= DATE_FORMAT(NOW(), '%m%d') )<90 THEN '90'
  240. WHEN (YEAR(NOW())-DATE_FORMAT(DATE_ADD(FROM_UNIXTIME(0), INTERVAL birthday SECOND),'%Y')-1) + (DATE_FORMAT(DATE_ADD(FROM_UNIXTIME(0), INTERVAL birthday SECOND),'%m%d') <= DATE_FORMAT(NOW(), '%m%d') )>=90 AND (YEAR(NOW())-DATE_FORMAT(DATE_ADD(FROM_UNIXTIME(0), INTERVAL birthday SECOND),'%Y')-1) + (DATE_FORMAT(DATE_ADD(FROM_UNIXTIME(0), INTERVAL birthday SECOND),'%m%d') <= DATE_FORMAT(NOW(), '%m%d') )<100 THEN '100'
  241. ELSE '-1'
  242. END
  243. AS nnd FROM xt_patients where status=1
  244. ) a GROUP BY nnd;`).Scan(&counts).Error
  245. if err != nil {
  246. return nil, err
  247. }
  248. return counts, nil
  249. }
  250. func GetAdminUserElectronicSignature(orgID int64, appID int64, userID int64) (*models.AdminUserElectronicSignature, error) {
  251. var es models.AdminUserElectronicSignature
  252. err := readUserDb.Model(&models.AdminUserElectronicSignature{}).Where("org_id=? and app_id=? and creator=? and status=1", orgID, appID, userID).First(&es).Error
  253. if err == gorm.ErrRecordNotFound {
  254. return nil, nil
  255. }
  256. if err != nil {
  257. return nil, err
  258. }
  259. return &es, nil
  260. }
  261. func CreateAdminUserElectronicSignature(es *models.AdminUserElectronicSignature) error {
  262. err := writeUserDb.Create(es).Error
  263. return err
  264. }
  265. func SaveAdminUserElectronicSignature(es *models.AdminUserElectronicSignature) error {
  266. err := writeUserDb.Save(es).Error
  267. return err
  268. }
  269. func GetAdminUserSpecialPermission(orgID int64, appID int64, adminUserID int64, permissionType models.SpecialPermissionType) (*models.AdminUserSpecialPermission, error) {
  270. var record models.AdminUserSpecialPermission
  271. err := readDb.Model(&models.AdminUserSpecialPermission{}).Where("org_id = ? AND app_id = ? AND admin_user_id = ? AND permission = ? AND status = 1", orgID, appID, adminUserID, permissionType).First(&record).Error
  272. if err != nil {
  273. if err == gorm.ErrRecordNotFound {
  274. return nil, nil
  275. } else {
  276. return nil, err
  277. }
  278. }
  279. return &record, nil
  280. }
  281. func SaveAdminUserSpecialPermission(permission *models.AdminUserSpecialPermission) error {
  282. err := writeDb.Save(permission).Error
  283. return err
  284. }
  285. func GetAllValidAdminUsersWithSpecialPermission(orgID int64, appID int64, permissionType models.SpecialPermissionType) ([]*models.AdminUserSpecialPermission, error) {
  286. var records []*models.AdminUserSpecialPermission
  287. err := readDb.Model(&models.AdminUserSpecialPermission{}).Where("org_id = ? AND app_id = ? AND permission = ? AND status = 1", orgID, appID, permissionType).Find(&records).Error
  288. if err != nil {
  289. return nil, err
  290. }
  291. return records, nil
  292. }
  293. func GetAllSpecialPermissionAdminUsersWithoutStatus(orgID int64, appID int64, permissionType models.SpecialPermissionType) ([]*models.AdminUserSpecialPermission, error) {
  294. var records []*models.AdminUserSpecialPermission
  295. err := readDb.Model(&models.AdminUserSpecialPermission{}).Where("org_id = ? AND app_id = ? AND permission = ?", orgID, appID, permissionType).Find(&records).Error
  296. if err != nil {
  297. return nil, err
  298. }
  299. return records, nil
  300. }
  301. func CancelAllSpecialPermissionAdminUsers(orgID int64, appID int64, permissionType models.SpecialPermissionType) error {
  302. tx := writeDb.Begin()
  303. updateTime := time.Now().Unix()
  304. err := tx.Model(&models.AdminUserSpecialPermission{}).Where("org_id = ? AND app_id = ? AND status = 1 AND permission = ?", orgID, appID, permissionType).Updates(map[string]interface{}{"status": 0, "mtime": updateTime}).Error
  305. if err != nil {
  306. tx.Rollback()
  307. return err
  308. }
  309. tx.Commit()
  310. return nil
  311. }
  312. func BatchSaveSpecialPermissionAdminUsers(users []*models.AdminUserSpecialPermission) error {
  313. tx := writeDb.Begin()
  314. for _, user := range users {
  315. tx.Save(user)
  316. }
  317. return tx.Commit().Error
  318. }
  319. // 获取一段时间内新增病人数量
  320. func GetNewPatientCount(from int64, to int64) (int, error) {
  321. var count int
  322. rows, err := readDb.Raw("SELECT COUNT(DISTINCT id_card_no) AS count FROM xt_patients WHERE status > 0 AND created_time >= ? AND created_time <= ?", from, to).Rows()
  323. if err != nil {
  324. return 0, err
  325. }
  326. if rows.Next() {
  327. rows.Scan(&count)
  328. }
  329. return count, nil
  330. }
  331. // 获取所有机构病人数量
  332. func GetPatientTotalCount() (int64, error) {
  333. var count int64
  334. rows, err := readDb.Raw("SELECT COUNT(DISTINCT id_card_no) AS count FROM xt_patients").Rows()
  335. if err != nil {
  336. return 0, err
  337. }
  338. if rows.Next() {
  339. rows.Scan(&count)
  340. }
  341. return count, nil
  342. }
  343. // 获取一段时间内的活跃账户数
  344. func GetActiveAdminUserCount(from int64, to int64) (int64, error) {
  345. var count int64
  346. rows, err := readUserDb.Raw("SELECT COUNT(DISTINCT admin_user_id) AS count FROM sgj_user_admin_login_log WHERE ctime >= ? AND ctime <= ? AND operate_type = 1", from, to).Rows()
  347. if err != nil {
  348. return 0, err
  349. }
  350. if rows.Next() {
  351. rows.Scan(&count)
  352. }
  353. return count, nil
  354. }
  355. // 获取所有机构账户数量
  356. func GetAdminUserTotalCount() (int64, error) {
  357. var count int64
  358. rows, err := readUserDb.Raw("SELECT COUNT(DISTINCT id) AS count FROM sgj_user_admin_login_log").Rows()
  359. if err != nil {
  360. return 0, err
  361. }
  362. if rows.Next() {
  363. rows.Scan(&count)
  364. }
  365. return count, nil
  366. }
  367. // 获取一段时间内注册的机构数量
  368. func GetRegistedOrgCount(from int64, to int64) (int64, error) {
  369. var count int64
  370. err := readUserDb.Model(&models.Org{}).Where("status <> 0 AND ctime >= ? AND ctime <= ?", from, to).Count(&count).Error
  371. if err != nil {
  372. return 0, err
  373. }
  374. return count, nil
  375. }
  376. // 获取一段时间内的活跃机构数
  377. func GetActiveOrgCount(from int64, to int64) (int64, error) {
  378. var count int64
  379. rows, err := readUserDb.Raw("SELECT COUNT(DISTINCT org_id) AS count FROM sgj_user_admin_login_log WHERE ctime >= ? AND ctime <= ?", from, to).Joins("JOIN sgj_xt.xt_dialysis_order as order ON sgj_user_admin_login_log.org_id = order.user_org_id").Rows()
  380. if err != nil {
  381. return 0, err
  382. }
  383. if rows.Next() {
  384. rows.Scan(&count)
  385. }
  386. return count, nil
  387. }
  388. // 获取所有活跃机构数
  389. func GetActiveOrgTotalCount() (int64, error) {
  390. var count int64
  391. rows, err := readUserDb.Raw("SELECT COUNT(DISTINCT org_id) AS count FROM sgj_user_admin_login_log").Joins("JOIN sgj_xt.xt_dialysis_order as order ON sgj_user_admin_login_log.org_id = order.user_org_id").Rows()
  392. if err != nil {
  393. return 0, err
  394. }
  395. if rows.Next() {
  396. rows.Scan(&count)
  397. }
  398. return count, nil
  399. }
  400. //获取近七天每天的注册机构总量
  401. func GetWeekRegistedOrgCount() (weekStatistics []*admin_models.Statistics, err error) {
  402. err = readUserDb.Raw("select count(id) as count, DATE_FORMAT(date(from_unixtime(ctime)) ,'%Y-%m-%d') as times from sgj_user_org where DATE_SUB(CURDATE(), INTERVAL 7 DAY) <= date(from_unixtime(sgj_user_org.ctime)) GROUP BY date(from_unixtime(ctime));").Scan(&weekStatistics).Error
  403. return
  404. }
  405. //func GetWeekActiveOrgCount() (weekStatistics []*admin_models.WeekStatistics, err error) {
  406. // err = readUserDb.Raw("select count(id) as count, date(from_unixtime(ctime)) as times from sgj_user_org where DATE_SUB(CURDATE(), INTERVAL 7 DAY) <= date(from_unixtime(sgj_user_org.ctime)) GROUP BY date(from_unixtime(ctime));").Scan(&weekStatistics).Error
  407. // return
  408. //}
  409. //获取近七天每天的机构活跃总量
  410. func GetWeekActiveOrgCount() (weekStatistics []*admin_models.Statistics, err error) {
  411. db := readUserDb.Raw("select count(DISTINCT(org_id)) as count, DATE_FORMAT(date(from_unixtime(ctime)) ,'%Y-%m-%d') as times from sgj_user_admin_login_log join sgj_xt.xt_dialysis_order ON sgj_xt.xt_dialysis_order.user_org_id = sgj_user_admin_login_log.org_id AND DATE_FORMAT(date(from_unixtime(sgj_user_admin_login_log.ctime)) ,'%Y-%m-%d') = DATE_FORMAT(date(from_unixtime(sgj_xt.xt_dialysis_order.dialysis_date)) ,'%Y-%m-%d') where DATE_SUB(CURDATE(), INTERVAL 7 DAY) <= date(from_unixtime(sgj_user_admin_login_log.ctime)) AND operate_type = 1 GROUP BY date(from_unixtime(ctime));")
  412. err = db.Scan(&weekStatistics).Error
  413. return
  414. }
  415. //获取近七天每天的机构活跃账号总量
  416. func GetWeekActiveAdminUserCount() (weekStatistics []*admin_models.Statistics, err error) {
  417. err = readUserDb.Raw("select count(DISTINCT(admin_user_id)) as count, DATE_FORMAT(date(from_unixtime(ctime)) ,'%Y-%m-%d') as times from sgj_user_admin_login_log where DATE_SUB(CURDATE(), INTERVAL 7 DAY) <= date(from_unixtime(sgj_user_admin_login_log.ctime)) AND operate_type = 1 GROUP BY date(from_unixtime(ctime));").Scan(&weekStatistics).Error
  418. return
  419. }
  420. //获取近七天每天的机构新增病人总量
  421. func GetWeekNewPatientCount() (weekStatistics []*admin_models.Statistics, err error) {
  422. err = readDb.Raw("select count(DISTINCT(id_card_no)) as count, DATE_FORMAT(date(from_unixtime(created_time)) ,'%Y-%m-%d') as times from xt_patients where DATE_SUB(CURDATE(), INTERVAL 7 DAY) <= date(from_unixtime(created_time)) GROUP BY date(from_unixtime(created_time));").Scan(&weekStatistics).Error
  423. return
  424. }
  425. //获取近七天每天的注册机构总量
  426. func GetWeekRegistedOrgTotalCount() (int64, error) {
  427. var result admin_models.Count
  428. var err error
  429. err = readUserDb.Raw("select count(id) as count from sgj_user_org where DATE_SUB(CURDATE(), INTERVAL 7 DAY) <= date(from_unixtime(sgj_user_org.ctime))").Scan(&result).Error
  430. return result.Count,err
  431. }
  432. //获取近七天每天的机构活跃账号总量
  433. func GetWeekActiveAdminUserTotalCount() (int64, error) {
  434. var result admin_models.Count
  435. var err error
  436. err = readUserDb.Raw("select count(DISTINCT(admin_user_id)) as count from sgj_user_admin_login_log where DATE_SUB(CURDATE(), INTERVAL 7 DAY) <= date(from_unixtime(sgj_user_admin_login_log.ctime)) AND operate_type = 1 ").Scan(&result).Error
  437. return result.Count,err
  438. }
  439. //获取近七天新增病人总量
  440. func GetWeekPatientTotalCount() (int64, error) {
  441. var result admin_models.Count
  442. var err error
  443. err = readDb.Raw("select count(DISTINCT(id_card_no)) as count from xt_patients where DATE_SUB(CURDATE(), INTERVAL 7 DAY) <= date(from_unixtime(created_time))").Scan(&result).Error
  444. return result.Count,err
  445. }
  446. //获取近30天每天的注册机构总量
  447. func GetMonthRegistedOrgCount() (weekStatistics []*admin_models.Statistics, err error) {
  448. err = readUserDb.Raw("select count(id) as count,DATE_FORMAT(date(from_unixtime(ctime)) ,'%Y-%m-%d') as times from sgj_user_org where DATE_SUB(CURDATE(), INTERVAL 30 DAY) <= date(from_unixtime(sgj_user_org.ctime)) GROUP BY date(from_unixtime(ctime));").Scan(&weekStatistics).Error
  449. return
  450. }
  451. //获取近30天每天的机构活跃总量
  452. func GetMonthActiveOrgCount() (weekStatistics []*admin_models.Statistics, err error) {
  453. err = readUserDb.Raw("select DATE_FORMAT(date(from_unixtime(ctime)) ,'%Y-%m') as month,count(DISTINCT(org_id)) as count From (select ctime,org_id FROM sgj_user_admin_login_log where app_type = 3 AND org_id > 0 ) T join sgj_xt.xt_dialysis_order ON sgj_xt.xt_dialysis_order.user_org_id = T.org_id AND DATE_FORMAT(date(from_unixtime(T.ctime)) ,'%Y-%m') =DATE_FORMAT(date(from_unixtime(sgj_xt.xt_dialysis_order.dialysis_date)) ,'%Y-%m') where DATE_FORMAT(date(from_unixtime(T.ctime)),'%Y-%m')>DATE_FORMAT(date_sub(curdate(), interval 1 month),'%Y-%m') group by month").Scan(&weekStatistics).Error
  454. return
  455. }
  456. //获取近30天每天的机构活跃账号总量
  457. func GetMonthActiveAdminUserCount() (weekStatistics []*admin_models.Statistics, err error) {
  458. err = readUserDb.Raw("select count(DISTINCT(admin_user_id)) as count, DATE_FORMAT(date(from_unixtime(ctime)) ,'%Y-%m-%d')as times from sgj_user_admin_login_log where DATE_SUB(CURDATE(), INTERVAL 30 DAY) <= date(from_unixtime(sgj_user_admin_login_log.ctime)) AND operate_type = 1 GROUP BY date(from_unixtime(ctime));").Scan(&weekStatistics).Error
  459. return
  460. }
  461. //获取近30天每天的机构新增病人总量
  462. func GetMonthNewPatientCount() (weekStatistics []*admin_models.Statistics, err error) {
  463. err = readDb.Raw("select count(DISTINCT(id_card_no)) as count, DATE_FORMAT(date(from_unixtime(created_time)) ,'%Y-%m-%d') as times from xt_patients where DATE_SUB(CURDATE(), INTERVAL 30 DAY) <= date(from_unixtime(created_time)) GROUP BY date(from_unixtime(created_time));").Scan(&weekStatistics).Error
  464. return
  465. }
  466. //获取近30天每天的注册机构总量
  467. func GetMonthRegistedOrgTotalCount() (int64, error) {
  468. var result admin_models.Count
  469. var err error
  470. err = readUserDb.Raw("select count(id) as count from sgj_user_org where DATE_SUB(CURDATE(), INTERVAL 30 DAY) <= date(from_unixtime(sgj_user_org.ctime))").Scan(&result).Error
  471. return result.Count,err
  472. }
  473. //获取近30天每天的机构活跃账号总量
  474. func GetMonthActiveAdminUserTotalCount() (int64, error) {
  475. var result admin_models.Count
  476. var err error
  477. err = readUserDb.Raw("select count(DISTINCT(admin_user_id)) as count from sgj_user_admin_login_log where DATE_SUB(CURDATE(), INTERVAL 30 DAY) <= date(from_unixtime(sgj_user_admin_login_log.ctime)) AND operate_type = 1 ").Scan(&result).Error
  478. return result.Count,err
  479. }
  480. //获取近30天每天的机构新增病人总量
  481. func GetMonthNewPatientTotalCount() (int64, error) {
  482. var result admin_models.Count
  483. var err error
  484. err = readDb.Raw("select count(DISTINCT(id_card_no)) as count from xt_patients where DATE_SUB(CURDATE(), INTERVAL 30 DAY) <= date(from_unixtime(created_time)) ").Scan(&result).Error
  485. return result.Count,err
  486. }
  487. //获取近3个月每个月的注册机构总量
  488. func GetThreeMonthRegistedOrgCount() (weekStatistics []*admin_models.Statistics, err error) {
  489. err = readUserDb.Raw("select DATE_FORMAT(date(from_unixtime(sgj_user_org.ctime)) ,'%Y-%m') as times,count(DISTINCT(id)) as count from sgj_user_org where DATE_FORMAT(date(from_unixtime(sgj_user_org.ctime)),'%Y-%m')>DATE_FORMAT(date_sub(curdate(), interval 3 month),'%Y-%m') group by times").Scan(&weekStatistics).Error
  490. return
  491. }
  492. //获取近3个月每个月的机构活跃账号总量
  493. func GetThreeMonthActiveAdminUserCount() (weekStatistics []*admin_models.Statistics, err error) {
  494. err = readUserDb.Raw("select DATE_FORMAT(date(from_unixtime(sgj_user_admin_login_log.ctime)) ,'%Y-%m') as times,count(DISTINCT(admin_user_id)) as count from sgj_user_admin_login_log where DATE_FORMAT(date(from_unixtime(sgj_user_admin_login_log.ctime)),'%Y-%m')>DATE_FORMAT(date_sub(curdate(), interval 3 month),'%Y-%m') AND operate_type = 1 group by times").Scan(&weekStatistics).Error
  495. return
  496. }
  497. //获取近3个月每个月的机构活跃总量
  498. func GetThreeMonthActiveOrgCount() (weekStatistics []*admin_models.Statistics, err error) {
  499. err = readUserDb.Raw("select DATE_FORMAT(date(from_unixtime(ctime)) ,'%Y-%m') as month,count(DISTINCT(org_id)) as count From (select ctime,org_id FROM sgj_user_admin_login_log where app_type = 3 AND org_id > 0 ) T join sgj_xt.xt_dialysis_order ON sgj_xt.xt_dialysis_order.user_org_id = T.org_id AND DATE_FORMAT(date(from_unixtime(T.ctime)) ,'%Y-%m') =DATE_FORMAT(date(from_unixtime(sgj_xt.xt_dialysis_order.dialysis_date)) ,'%Y-%m') where DATE_FORMAT(date(from_unixtime(T.ctime)),'%Y-%m')>DATE_FORMAT(date_sub(curdate(), interval 3 month),'%Y-%m') group by month").Scan(&weekStatistics).Error
  500. return
  501. }
  502. //获取近3个月每个月机构新增病人总量
  503. func GetThreeMonthNewPatientCount() (weekStatistics []*admin_models.Statistics, err error) {
  504. err = readDb.Raw("select DATE_FORMAT(date(from_unixtime(xt_patients.created_time)) ,'%Y-%m') as times,count(DISTINCT(id_card_no)) as count from xt_patients where DATE_FORMAT(date(from_unixtime(xt_patients.created_time)),'%Y-%m')>DATE_FORMAT(date_sub(curdate(), interval 3 month),'%Y-%m') group by times").Scan(&weekStatistics).Error
  505. return
  506. }
  507. //获取近3个月每个月的注册机构总量
  508. func GetThreeMonthRegistedOrgTotalCount() (int64, error) {
  509. var result admin_models.Count
  510. var err error
  511. err = readUserDb.Raw("select count(DISTINCT(id)) as count from sgj_user_org where DATE_FORMAT(date(from_unixtime(sgj_user_org.ctime)),'%Y-%m')>DATE_FORMAT(date_sub(curdate(), interval 3 month),'%Y-%m')").Scan(&result).Error
  512. return result.Count,err
  513. }
  514. //获取近3个月每个月的机构活跃账号总量
  515. func GetThreeMonthActiveAdminUserTotalCount() (int64, error) {
  516. var result admin_models.Count
  517. var err error
  518. err = readUserDb.Raw("select count(DISTINCT(admin_user_id)) as count from sgj_user_admin_login_log where DATE_FORMAT(date(from_unixtime(sgj_user_admin_login_log.ctime)),'%Y-%m')>DATE_FORMAT(date_sub(curdate(), interval 3 month),'%Y-%m') AND operate_type = 1 ").Scan(&result).Error
  519. return result.Count,err
  520. }
  521. //获取近3个月每个月机构新增病人总量
  522. func GetThreeMonthNewPatientTotalCount() (int64, error) {
  523. var result admin_models.Count
  524. var err error
  525. err = readDb.Raw("select count(DISTINCT(id_card_no)) as count from xt_patients where DATE_FORMAT(date(from_unixtime(xt_patients.created_time)),'%Y-%m')>DATE_FORMAT(date_sub(curdate(), interval 3 month),'%Y-%m')").Scan(&result).Error
  526. return result.Count,err
  527. }
  528. //获取近半年每个月的注册机构总量
  529. func GetSixMonthRegistedOrgCount() (weekStatistics []*admin_models.Statistics, err error) {
  530. err = readUserDb.Raw("select DATE_FORMAT(date(from_unixtime(sgj_user_org.ctime)) ,'%Y-%m') as times,count(DISTINCT(id)) as count from sgj_user_org where DATE_FORMAT(date(from_unixtime(sgj_user_org.ctime)),'%Y-%m')>DATE_FORMAT(date_sub(curdate(), interval 6 month),'%Y-%m') group by times").Scan(&weekStatistics).Error
  531. return
  532. }
  533. //获取近半年每个月的机构活跃账号总量
  534. func GetSixMonthActiveAdminUserCount() (weekStatistics []*admin_models.Statistics, err error) {
  535. err = readUserDb.Raw("select DATE_FORMAT(date(from_unixtime(sgj_user_admin_login_log.ctime)) ,'%Y-%m') as times,count(DISTINCT(admin_user_id)) as count from sgj_user_admin_login_log where DATE_FORMAT(date(from_unixtime(sgj_user_admin_login_log.ctime)),'%Y-%m')>DATE_FORMAT(date_sub(curdate(), interval 6 month),'%Y-%m') group by times").Scan(&weekStatistics).Error
  536. return
  537. }
  538. //获取近半年每个月的机构活跃总量
  539. func GetSixMonthActiveOrgCount() (weekStatistics []*admin_models.Statistics, err error) {
  540. err = readUserDb.Raw("select DATE_FORMAT(date(from_unixtime(ctime)) ,'%Y-%m') as month,count(DISTINCT(org_id)) as count From (select ctime,org_id FROM sgj_user_admin_login_log where app_type = 3 AND org_id > 0 ) T join sgj_xt.xt_dialysis_order ON sgj_xt.xt_dialysis_order.user_org_id = T.org_id AND DATE_FORMAT(date(from_unixtime(T.ctime)) ,'%Y-%m') =DATE_FORMAT(date(from_unixtime(sgj_xt.xt_dialysis_order.dialysis_date)) ,'%Y-%m') where DATE_FORMAT(date(from_unixtime(T.ctime)),'%Y-%m')>DATE_FORMAT(date_sub(curdate(), interval 6 month),'%Y-%m') group by month").Scan(&weekStatistics).Error
  541. return
  542. }
  543. //获取近半年每个月机构新增病人总量
  544. func GetSixMonthNewPatientCount() (weekStatistics []*admin_models.Statistics, err error) {
  545. err = readDb.Raw("select DATE_FORMAT(date(from_unixtime(xt_patients.created_time)) ,'%Y-%m') as times,count(DISTINCT(id_card_no)) as count from xt_patients where DATE_FORMAT(date(from_unixtime(xt_patients.created_time)),'%Y-%m')>DATE_FORMAT(date_sub(curdate(), interval 6 month),'%Y-%m') group by times").Scan(&weekStatistics).Error
  546. return
  547. }
  548. //获取近半年每个月的注册机构总量
  549. func GetSixMonthRegistedOrgTotalCount() (int64, error) {
  550. var result admin_models.Count
  551. var err error
  552. err = readUserDb.Raw("select DATE_FORMAT(date(from_unixtime(sgj_user_org.ctime)) ,'%Y-%m') as times,count(DISTINCT(id)) as count from sgj_user_org where DATE_FORMAT(date(from_unixtime(sgj_user_org.ctime)),'%Y-%m')>DATE_FORMAT(date_sub(curdate(), interval 6 month),'%Y-%m')").Scan(&result).Error
  553. return result.Count, err
  554. }
  555. //获取近半年每个月的机构活跃账号总量
  556. func GetSixMonthActiveAdminUserTotalCount() (int64, error) {
  557. var result admin_models.Count
  558. var err error
  559. err = readUserDb.Raw("select DATE_FORMAT(date(from_unixtime(sgj_user_admin_login_log.ctime)) ,'%Y-%m') as times,count(DISTINCT(admin_user_id)) as count from sgj_user_admin_login_log where DATE_FORMAT(date(from_unixtime(sgj_user_admin_login_log.ctime)),'%Y-%m')>DATE_FORMAT(date_sub(curdate(), interval 6 month),'%Y-%m')").Scan(&result).Error
  560. return result.Count, err
  561. }
  562. //获取近半年每个月机构新增病人总量
  563. func GetSixMonthNewPatientTotalCount() (int64, error) {
  564. var result admin_models.Count
  565. var err error
  566. err = readDb.Raw("select DATE_FORMAT(date(from_unixtime(xt_patients.created_time)) ,'%Y-%m') as times,count(DISTINCT(id_card_no)) as count from xt_patients where DATE_FORMAT(date(from_unixtime(xt_patients.created_time)),'%Y-%m')>DATE_FORMAT(date_sub(curdate(), interval 6 month),'%Y-%m')").Scan(&result).Error
  567. return result.Count, err
  568. }
  569. //获取近1年每个月的注册机构总量
  570. func GetYearRegistedOrgCount() (weekStatistics []*admin_models.Statistics, err error) {
  571. err = readUserDb.Raw("select DATE_FORMAT(date(from_unixtime(sgj_user_org.ctime)) ,'%Y-%m') as times,count(DISTINCT(id)) as count from sgj_user_org where DATE_FORMAT(date(from_unixtime(sgj_user_org.ctime)),'%Y-%m')>DATE_FORMAT(date_sub(curdate(), interval 12 month),'%Y-%m') group by times").Scan(&weekStatistics).Error
  572. return
  573. }
  574. //获取近1年每个月的机构活跃账号总量
  575. func GetYearActiveAdminUserCount() (weekStatistics []*admin_models.Statistics, err error) {
  576. err = readUserDb.Raw("select DATE_FORMAT(date(from_unixtime(sgj_user_admin_login_log.ctime)) ,'%Y-%m') as times,count(DISTINCT(admin_user_id)) as count from sgj_user_admin_login_log where DATE_FORMAT(date(from_unixtime(sgj_user_admin_login_log.ctime)),'%Y-%m')>DATE_FORMAT(date_sub(curdate(), interval 12 month),'%Y-%m') group by times").Scan(&weekStatistics).Error
  577. return
  578. }
  579. //获取近1年每个月的机构活跃总量
  580. func GetYearActiveOrgCount() (weekStatistics []*admin_models.Statistics, err error) {
  581. err = readUserDb.Raw("select DATE_FORMAT(date(from_unixtime(ctime)) ,'%Y-%m') as month,count(DISTINCT(org_id)) as count From (select ctime,org_id FROM sgj_user_admin_login_log where app_type = 3 AND org_id > 0 ) T join sgj_xt.xt_dialysis_order ON sgj_xt.xt_dialysis_order.user_org_id = T.org_id AND DATE_FORMAT(date(from_unixtime(T.ctime)) ,'%Y-%m') =DATE_FORMAT(date(from_unixtime(sgj_xt.xt_dialysis_order.dialysis_date)) ,'%Y-%m') where DATE_FORMAT(date(from_unixtime(T.ctime)),'%Y-%m')>DATE_FORMAT(date_sub(curdate(), interval 12 month),'%Y-%m') group by month").Scan(&weekStatistics).Error
  582. return
  583. }
  584. //获取近1年每个月机构新增病人总量
  585. func GetYearNewPatientCount() (weekStatistics []*admin_models.Statistics, err error) {
  586. err = readDb.Raw("select DATE_FORMAT(date(from_unixtime(xt_patients.created_time)) ,'%Y-%m') as times,count(DISTINCT(id_card_no)) as count from xt_patients where DATE_FORMAT(date(from_unixtime(xt_patients.created_time)),'%Y-%m')>DATE_FORMAT(date_sub(curdate(), interval 12 month),'%Y-%m') AND status > 0 group by times").Scan(&weekStatistics).Error
  587. return
  588. }
  589. //获取近1年每个月的注册机构总量
  590. func GetYearRegistedOrgTotalCount() (int64, error) {
  591. var result admin_models.Count
  592. var err error
  593. err = readUserDb.Raw("select DATE_FORMAT(date(from_unixtime(sgj_user_org.ctime)) ,'%Y-%m') as times,count(DISTINCT(id)) as count from sgj_user_org where DATE_FORMAT(date(from_unixtime(sgj_user_org.ctime)),'%Y-%m')>DATE_FORMAT(date_sub(curdate(), interval 12 month),'%Y-%m')").Scan(&result).Error
  594. return result.Count, err
  595. }
  596. //获取近1年每个月的机构活跃账号总量
  597. func GetYearActiveAdminUserTotalCount() (int64, error) {
  598. var result admin_models.Count
  599. var err error
  600. err = readUserDb.Raw("select DATE_FORMAT(date(from_unixtime(sgj_user_admin_login_log.ctime)) ,'%Y-%m') as times,count(DISTINCT(admin_user_id)) as count from sgj_user_admin_login_log where DATE_FORMAT(date(from_unixtime(sgj_user_admin_login_log.ctime)),'%Y-%m')>DATE_FORMAT(date_sub(curdate(), interval 12 month),'%Y-%m')").Scan(&result).Error
  601. return result.Count, err
  602. }
  603. //获取近1年每个月机构新增病人总量
  604. func GetYearNewPatientTotalCount() (int64, error) {
  605. var result admin_models.Count
  606. var err error
  607. err = readDb.Raw("select count(DISTINCT(id_card_no)) as count from xt_patients where DATE_FORMAT(date(from_unixtime(xt_patients.created_time)),'%Y-%m')>DATE_FORMAT(date_sub(curdate(), interval 12 month),'%Y-%m') AND status > 0").Scan(&result).Error
  608. return result.Count, err
  609. }