123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738 |
- package service
-
- import (
- "XT_Admin_Api/models"
- "XT_Admin_Api/models/admin_models"
- "XT_Admin_Api/utils"
- "fmt"
- "github.com/jinzhu/gorm"
- "time"
- )
-
- func GetAllOrgList(active_status int64, depth_active_status int64, start_time int64, end_time int64, province int64, city int64, district int64, follow int64, keyword string, page int64, limit int64, is_super_admin int64) (list []*models.Org, err error, total int64) {
-
- fmt.Println(follow)
- offset := (page - 1) * limit
- fmt.Println(offset)
- db := readUserDb.Model(&models.Org{})
-
- if len(keyword) > 0 {
- likeKey := "%" + keyword + "%"
- db = db.Where("contact_name LIKE ? Or org_name LIKE ? Or org_short_name Like ? ", likeKey, likeKey, likeKey)
- } else {
-
- switch active_status {
- case 1:
- now := time.Now()
- zeroHourTimeOfToday := utils.ZeroHourTimeOfDay(now)
- db = db.Joins("JOIN sgj_user_admin_login_log on sgj_user_admin_login_log.org_id = sgj_user_org.id AND sgj_user_admin_login_log.ctime >= ? AND sgj_user_admin_login_log.ctime <= ? AND sgj_user_admin_login_log.app_type = 3", zeroHourTimeOfToday.Unix(), now.Unix())
- break
- case 2:
- db = db.Joins("JOIN sgj_user_admin_login_log on sgj_user_admin_login_log.org_id = sgj_user_org.id AND DATE_SUB(CURDATE(), INTERVAL 7 DAY) <= date(from_unixtime(sgj_user_admin_login_log.ctime)) AND sgj_user_admin_login_log.app_type = 3 AND sgj_user_admin_login_log.operate_type = 1 ")
- break
- case 3:
- db = db.Joins("JOIN sgj_user_admin_login_log on sgj_user_admin_login_log.org_id = sgj_user_org.id AND DATE_SUB(CURDATE(), INTERVAL 1 MONTH) <= date(from_unixtime(sgj_user_admin_login_log.ctime)) AND sgj_user_admin_login_log.app_type = 3 AND sgj_user_admin_login_log.operate_type = 1 ")
- break
- case 4:
- db = db.Joins("JOIN sgj_user_admin_login_log on sgj_user_admin_login_log.org_id = sgj_user_org.id AND DATE_SUB(CURDATE(), INTERVAL 1 Year) <= date(from_unixtime(sgj_user_admin_login_log.ctime)) AND sgj_user_admin_login_log.app_type = 3 AND sgj_user_admin_login_log.operate_type = 1 ")
- break
- }
-
- switch depth_active_status {
- case 1:
- now := time.Now()
- zeroHourTimeOfToday := utils.ZeroHourTimeOfDay(now)
- db = db.Joins("JOIN sgj_xt.xt_dialysis_order ON sgj_xt.xt_dialysis_order.user_org_id = sgj_user_org.id AND sgj_xt.xt_dialysis_order.created_time >= ? AND sgj_xt.xt_dialysis_order.created_time <= ?", zeroHourTimeOfToday.Unix(), now.Unix())
-
- break
- case 2:
- db = db.Joins("JOIN sgj_xt.xt_dialysis_order ON sgj_xt.xt_dialysis_order.user_org_id = sgj_user_org.id AND DATE_SUB(CURDATE(), INTERVAL 7 DAY) <= date(from_unixtime(sgj_xt.xt_dialysis_order.created_time)) AND sgj_xt.xt_dialysis_order.status = 1")
-
- break
- case 3:
- db = db.Joins("JOIN sgj_xt.xt_dialysis_order ON sgj_xt.xt_dialysis_order.user_org_id = sgj_user_org.id AND DATE_SUB(CURDATE(), INTERVAL 30 DAY) <= date(from_unixtime(sgj_xt.xt_dialysis_order.created_time)) AND sgj_xt.xt_dialysis_order.status = 1")
-
- break
- case 4:
- db = db.Joins("JOIN sgj_xt.xt_dialysis_order on sgj_xt.xt_dialysis_order.user_org_id = sgj_user_org.id AND DATE_SUB(CURDATE(), INTERVAL 1 Year) <= date(from_unixtime(sgj_xt.xt_dialysis_order.created_time)) AND sgj_xt.xt_dialysis_order.status = 1")
- break
- }
-
- if province > 0 {
- db = db.Where("sgj_user_org.province = ?", province)
- }
-
- if city > 0 {
- db = db.Where("sgj_user_org.city = ?", city)
- }
-
- if district > 0 {
- db = db.Where("sgj_user_org.district = ?", district)
- }
-
- if start_time != 0 {
- db = db.Where("sgj_user_org.ctime>=?", start_time)
- }
- if end_time != 0 {
- db = db.Where("sgj_user_org.ctime<=?", end_time)
- }
-
- if follow != 0 {
- db = db.Joins("JOIN sgj_org_follow on sgj_org_follow.org_id = sgj_user_org.id AND sgj_org_follow.admin_user_id = ? AND sgj_org_follow.status = 1", follow)
- }
-
- }
- //if is_super_admin == 1 {
- db = db.Where("sgj_user_org.status = 1 AND sgj_user_org.import <> 1").Group("sgj_user_org.id")
- //
- //} else {
- // db = db.Where("sgj_user_org.status = 1 AND sgj_user_org.import <> 1 AND DATE_SUB(CURDATE(), INTERVAL 15 DAY) <= date(from_unixtime(sgj_user_org.ctime))").Group("sgj_user_org.id")
- //}
-
- db = db.Count(&total)
- err = db.Preload("OrgFollow", func(db *gorm.DB) *gorm.DB {
- return db.Model(&models.OrgFollow{}).Where("status = 1").Preload("AdminAccount", "status = 1")
- }).Preload("AdminUserLoginLog", func(db *gorm.DB) *gorm.DB {
- return db.Model(&models.AdminUserLoginLog{}).Where("id = (SELECT max(id))")
- }).Preload("Citys").Offset(offset).Limit(limit).Order("sgj_user_org.ctime DESC").Find(&list).Error
- return
- }
-
- func GetOrgDetailInfo(org_id int64) (info models.Org, err error) {
- err = readUserDb.Model(&models.Org{}).Where("id = ? AND status = 1 AND import <> 1", org_id).Preload("AdminUserLoginLog", func(db *gorm.DB) *gorm.DB {
- return db.Model(&models.AdminUserLoginLog{}).Where("id = (SELECT max(id))")
- }).Preload("AdminUser", "status = 1").Find(&info).Error
- return
- }
-
- func GetDistrictsById(id int64) (district models.District, err error) {
- err = readUserDb.Model(&models.District{}).Where("id = ? ", id).First(&district).Error
- return
- }
-
- func GetAllOrgType() (types []*models.OrgType, err error) {
- err = readUserDb.Model(&models.OrgType{}).Find(&types).Error
- return
- }
-
- //设置今天
- func GetOrgDialysisCount(statices_type int64, org_id int64, from int64, to int64) (count int64, err error) {
- var counts int64
-
- switch statices_type {
- case 1: //病人管理
- rows, err := readDb.Raw("SELECT COUNT(DISTINCT id) AS count FROM xt_patients WHERE user_org_id = ? AND created_time >= ? AND created_time <= ? AND status = 1", org_id, from, to).Rows()
- defer rows.Close()
- if err != nil {
- return 0, err
- }
- if rows.Next() {
- rows.Scan(&counts)
- }
- break
- case 2: //透析处方
- rows, err := readDb.Raw("SELECT COUNT(DISTINCT id) AS count FROM xt_dialysis_prescription WHERE user_org_id = ? AND created_time >= ? AND created_time <= ? AND status = 1", org_id, from, to).Rows()
- defer rows.Close()
-
- if err != nil {
- return 0, err
- }
- if rows.Next() {
- rows.Scan(&counts)
- }
- break
- case 3: //接诊评估
- rows, err := readDb.Raw("SELECT COUNT(DISTINCT id) AS count FROM xt_receive_treatment_asses WHERE user_org_id = ? AND created_time >= ? AND created_time <= ? AND status = 1", org_id, from, to).Rows()
- defer rows.Close()
-
- if err != nil {
- return 0, err
- }
- if rows.Next() {
- rows.Scan(&counts)
- }
- break
- case 4: //透前评估
- rows, err := readDb.Raw("SELECT COUNT(DISTINCT id) AS count FROM xt_assessment_before_dislysis WHERE user_org_id = ? AND created_time >= ? AND created_time <= ? AND status = 1", org_id, from, to).Rows()
- defer rows.Close()
-
- if err != nil {
- return 0, err
- }
- if rows.Next() {
- rows.Scan(&counts)
- }
- break
- case 5: //临时医嘱
- rows, err := readDb.Raw("SELECT COUNT(DISTINCT patient_id) AS count FROM xt_doctor_advice WHERE user_org_id = ? AND created_time >= ? AND created_time <= ? AND status = 1", org_id, from, to).Rows()
- defer rows.Close()
-
- if err != nil {
- return 0, err
- }
- if rows.Next() {
- rows.Scan(&counts)
- }
- break
- case 6: //双人核对
- rows, err := readDb.Raw("SELECT COUNT(DISTINCT id) AS count FROM xt_double_check WHERE user_org_id = ? AND created_time >= ? AND created_time <= ? AND status = 1", org_id, from, to).Rows()
- defer rows.Close()
-
- if err != nil {
- return 0, err
- }
- if rows.Next() {
- rows.Scan(&counts)
- }
- break
- case 7: //透析上机
- rows, err := readDb.Raw("SELECT COUNT(DISTINCT id) AS count FROM xt_dialysis_order WHERE user_org_id = ? AND created_time >= ? AND created_time <= ? AND status = 1 AND (stage = 2 OR stage = 1)", org_id, from, to).Rows()
- defer rows.Close()
-
- if err != nil {
- return 0, err
- }
- if rows.Next() {
- rows.Scan(&counts)
- }
- break
-
- case 8: //透析监测
- rows, err := readDb.Raw("SELECT COUNT(DISTINCT patient_id) AS count FROM xt_monitoring_record WHERE user_org_id = ? AND created_time >= ? AND created_time <= ? AND status = 1", org_id, from, to).Rows()
- defer rows.Close()
-
- if err != nil {
- return 0, err
- }
- if rows.Next() {
- rows.Scan(&counts)
- }
- break
- case 9: //透析下机
- rows, err := readDb.Raw("SELECT COUNT(DISTINCT id) AS count FROM xt_dialysis_order WHERE user_org_id = ? AND created_time >= ? AND created_time <= ? AND stage = 2 AND status = 1", org_id, from, to).Rows()
- defer rows.Close()
-
- if err != nil {
- return 0, err
- }
- if rows.Next() {
- rows.Scan(&counts)
- }
- break
- case 10: //透后评估
- rows, err := readDb.Raw("SELECT COUNT(DISTINCT id) AS count FROM xt_assessment_after_dislysis WHERE user_org_id = ? AND created_time >= ? AND created_time <= ? AND status = 1", org_id, from, to).Rows()
- defer rows.Close()
-
- if err != nil {
- return 0, err
- }
- if rows.Next() {
- rows.Scan(&counts)
- }
- break
- case 11: //入库单
- rows, err := readDb.Raw("SELECT COUNT(DISTINCT id) AS count FROM xt_warehouse WHERE org_id = ? AND ctime >= ? AND mtime <= ? AND status = 1", org_id, from, to).Rows()
- defer rows.Close()
-
- if err != nil {
- return 0, err
- }
- if rows.Next() {
- rows.Scan(&counts)
- }
- break
- case 12: //出库单
- rows, err := readDb.Raw("SELECT COUNT(DISTINCT id) AS count FROM xt_warehouse_out WHERE org_id = ? AND ctime >= ? AND mtime <= ? AND status = 1", org_id, from, to).Rows()
- defer rows.Close()
-
- if err != nil {
- return 0, err
- }
- if rows.Next() {
- rows.Scan(&counts)
- }
- break
- }
- return counts, nil
- }
-
- //获取昨天的数据
- func GetYesterDayOrgDialysisCount(statices_type int64, org_id int64) (weekStatistics []*admin_models.Statistics, err error) {
- fmt.Println(statices_type)
-
- switch statices_type {
- case 1: //病人管理
- err = readDb.Raw("select count(distinct id) as count, DATE_FORMAT(date(from_unixtime(created_time)) ,'%Y-%m-%d') as times from xt_patients where DATE_SUB(CURDATE(), INTERVAL 1 DAY) = date(from_unixtime(created_time)) AND status = 1 AND user_org_id = ? GROUP BY times", org_id).Scan(&weekStatistics).Error
-
- break
- case 2: //透析处方
- err = readDb.Raw("select count(distinct id) as count, DATE_FORMAT(date(from_unixtime(created_time)) ,'%Y-%m-%d') as times from xt_dialysis_prescription where DATE_SUB(CURDATE(), INTERVAL 1 DAY) = date(from_unixtime(created_time)) AND status = 1 AND user_org_id = ? GROUP BY times", org_id).Scan(&weekStatistics).Error
-
- break
- case 3: //接诊评估
- err = readDb.Raw("select count(distinct id) as count, DATE_FORMAT(date(from_unixtime(created_time)) ,'%Y-%m-%d') as times from xt_receive_treatment_asses where DATE_SUB(CURDATE(), INTERVAL 1 DAY) = date(from_unixtime(created_time)) AND status = 1 AND user_org_id = ? GROUP BY times", org_id).Scan(&weekStatistics).Error
-
- break
- case 4: //透前评估
- err = readDb.Raw("select count(distinct id) as count, DATE_FORMAT(date(from_unixtime(created_time)) ,'%Y-%m-%d') as times from xt_assessment_before_dislysis where DATE_SUB(CURDATE(), INTERVAL 1 DAY) = date(from_unixtime(created_time)) AND status = 1 AND user_org_id = ? GROUP BY times", org_id).Scan(&weekStatistics).Error
- break
-
- case 5: //临时医嘱
- err = readDb.Raw("select count(distinct patient_id) as count, DATE_FORMAT(date(from_unixtime(created_time)) ,'%Y-%m-%d') as times from xt_doctor_advice where DATE_SUB(CURDATE(), INTERVAL 1 DAY) = date(from_unixtime(created_time)) AND status = 1 AND user_org_id = ? GROUP BY times", org_id).Scan(&weekStatistics).Error
-
- break
- case 6: //双人核对
- err = readDb.Raw("select count(distinct id) as count, DATE_FORMAT(date(from_unixtime(created_time)) ,'%Y-%m-%d') as times from xt_double_check where DATE_SUB(CURDATE(), INTERVAL 1 DAY) = date(from_unixtime(created_time)) AND status = 1 AND user_org_id = ? GROUP BY times", org_id).Scan(&weekStatistics).Error
-
- break
- case 7: //透析上机
- err = readDb.Raw("select count(distinct id) as count, DATE_FORMAT(date(from_unixtime(created_time)) ,'%Y-%m-%d') as times from xt_dialysis_order where DATE_SUB(CURDATE(), INTERVAL 1 DAY) = date(from_unixtime(created_time)) AND status = 1 AND user_org_id = ? AND (stage = 2 OR stage = 1) GROUP BY times", org_id).Scan(&weekStatistics).Error
- break
-
- case 8: //透析监测
- err = readDb.Raw("select count(distinct patient_id) as count, DATE_FORMAT(date(from_unixtime(created_time)) ,'%Y-%m-%d') as times from xt_monitoring_record where DATE_SUB(CURDATE(), INTERVAL 1 DAY) = date(from_unixtime(created_time)) AND status = 1 AND user_org_id = ? GROUP BY times", org_id).Scan(&weekStatistics).Error
- break
- case 9: //透析下机
- err = readDb.Raw("select count(distinct id) as count, DATE_FORMAT(date(from_unixtime(created_time)) ,'%Y-%m-%d') as times from xt_dialysis_order where DATE_SUB(CURDATE(), INTERVAL 1 DAY) = date(from_unixtime(created_time)) AND stage = 2 AND status = 1 AND user_org_id = ? GROUP BY times", org_id).Scan(&weekStatistics).Error
-
- break
- case 10: //透后评估
- err = readDb.Raw("select count(distinct id) as count, DATE_FORMAT(date(from_unixtime(created_time)) ,'%Y-%m-%d') as times from xt_assessment_after_dislysis where DATE_SUB(CURDATE(), INTERVAL 1 DAY) = date(from_unixtime(created_time)) AND status = 1 AND user_org_id = ? GROUP BY times", org_id).Scan(&weekStatistics).Error
- break
- case 11: //入库单
- err = readDb.Raw("select count(distinct id) as count, DATE_FORMAT(date(from_unixtime(ctime)) ,'%Y-%m-%d') as times from xt_warehouse where DATE_SUB(CURDATE(), INTERVAL 1 DAY) = date(from_unixtime(ctime)) AND status = 1 AND org_id = ? GROUP BY times", org_id).Scan(&weekStatistics).Error
- break
- case 12: //出库单
- err = readDb.Raw("select count(distinct id) as count, DATE_FORMAT(date(from_unixtime(ctime)) ,'%Y-%m-%d') as times from xt_warehouse_out where DATE_SUB(CURDATE(), INTERVAL 1 DAY) = date(from_unixtime(ctime)) AND status = 1 AND org_id = ? GROUP BY times", org_id).Scan(&weekStatistics).Error
- break
- }
-
- return
- }
-
- //获取近七天的数据
- func GetWeekOrgDialysisCount(statices_type int64, org_id int64) (weekStatistics []*admin_models.Statistics, err error) {
- fmt.Println(statices_type)
-
- switch statices_type {
- case 1: //病人管理
- err = readDb.Raw("select count(distinct id) 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)) AND status = 1 AND user_org_id = ? GROUP BY times", org_id).Scan(&weekStatistics).Error
-
- break
- case 2: //透析处方
- err = readDb.Raw("select count(distinct id) as count, DATE_FORMAT(date(from_unixtime(created_time)) ,'%Y-%m-%d') as times from xt_dialysis_prescription where DATE_SUB(CURDATE(), INTERVAL 7 DAY) <= date(from_unixtime(created_time)) AND status = 1 AND user_org_id = ? GROUP BY times", org_id).Scan(&weekStatistics).Error
-
- break
- case 3: //接诊评估
- err = readDb.Raw("select count(distinct id) as count, DATE_FORMAT(date(from_unixtime(created_time)) ,'%Y-%m-%d') as times from xt_receive_treatment_asses where DATE_SUB(CURDATE(), INTERVAL 7 DAY) <= date(from_unixtime(created_time)) AND status = 1 AND user_org_id = ? GROUP BY times", org_id).Scan(&weekStatistics).Error
-
- break
- case 4: //透前评估
- err = readDb.Raw("select count(distinct id) as count, DATE_FORMAT(date(from_unixtime(created_time)) ,'%Y-%m-%d') as times from xt_assessment_before_dislysis where DATE_SUB(CURDATE(), INTERVAL 7 DAY) <= date(from_unixtime(created_time)) AND status = 1 AND user_org_id = ? GROUP BY times", org_id).Scan(&weekStatistics).Error
- break
-
- case 5: //临时医嘱
- err = readDb.Raw("select count(distinct patient_id) as count, DATE_FORMAT(date(from_unixtime(created_time)) ,'%Y-%m-%d') as times from xt_doctor_advice where DATE_SUB(CURDATE(), INTERVAL 7 DAY) <= date(from_unixtime(created_time)) AND status = 1 AND user_org_id = ? GROUP BY times", org_id).Scan(&weekStatistics).Error
-
- break
- case 6: //双人核对
- err = readDb.Raw("select count(distinct id) as count, DATE_FORMAT(date(from_unixtime(created_time)) ,'%Y-%m-%d') as times from xt_double_check where DATE_SUB(CURDATE(), INTERVAL 7 DAY) <= date(from_unixtime(created_time)) AND status = 1 AND user_org_id = ? GROUP BY times", org_id).Scan(&weekStatistics).Error
-
- break
- case 7: //透析上机
- err = readDb.Raw("select count(distinct id) as count, DATE_FORMAT(date(from_unixtime(created_time)) ,'%Y-%m-%d') as times from xt_dialysis_order where DATE_SUB(CURDATE(), INTERVAL 7 DAY) <= date(from_unixtime(created_time)) AND status = 1 AND user_org_id = ? AND (stage = 2 OR stage = 1) GROUP BY times", org_id).Scan(&weekStatistics).Error
- break
-
- case 8: //透析监测
- err = readDb.Raw("select count(distinct patient_id) as count, DATE_FORMAT(date(from_unixtime(created_time)) ,'%Y-%m-%d') as times from xt_monitoring_record where DATE_SUB(CURDATE(), INTERVAL 7 DAY) <= date(from_unixtime(created_time)) AND status = 1 AND user_org_id = ? GROUP BY times", org_id).Scan(&weekStatistics).Error
- break
- case 9: //透析下机
- err = readDb.Raw("select count(distinct id) as count, DATE_FORMAT(date(from_unixtime(created_time)) ,'%Y-%m-%d') as times from xt_dialysis_order where DATE_SUB(CURDATE(), INTERVAL 7 DAY) <= date(from_unixtime(created_time)) AND stage = 2 AND status = 1 AND user_org_id = ? GROUP BY times", org_id).Scan(&weekStatistics).Error
-
- break
- case 10: //透后评估
- err = readDb.Raw("select count(distinct id) as count, DATE_FORMAT(date(from_unixtime(created_time)) ,'%Y-%m-%d') as times from xt_assessment_after_dislysis where DATE_SUB(CURDATE(), INTERVAL 7 DAY) <= date(from_unixtime(created_time)) AND status = 1 AND user_org_id = ? GROUP BY times", org_id).Scan(&weekStatistics).Error
- break
- case 11: //入库单
- err = readDb.Raw("select count(distinct id) as count, DATE_FORMAT(date(from_unixtime(ctime)) ,'%Y-%m-%d') as times from xt_warehouse where DATE_SUB(CURDATE(), INTERVAL 7 DAY) <= date(from_unixtime(ctime)) AND status = 1 AND org_id = ? GROUP BY times", org_id).Scan(&weekStatistics).Error
- break
- case 12: //出库单
- err = readDb.Raw("select count(distinct id) as count, DATE_FORMAT(date(from_unixtime(ctime)) ,'%Y-%m-%d') as times from xt_warehouse_out where DATE_SUB(CURDATE(), INTERVAL 7 DAY) <= date(from_unixtime(ctime)) AND status = 1 AND org_id = ? GROUP BY times", org_id).Scan(&weekStatistics).Error
- break
- }
-
- return
- }
-
- func GetMonthOrgDialysisCount(statices_type int64, org_id int64) (weekStatistics []*admin_models.Statistics, err error) {
- switch statices_type {
- case 1: //病人管理
- err = readDb.Raw("select count(distinct id) 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)) AND status = 1 AND user_org_id = ? GROUP BY times", org_id).Scan(&weekStatistics).Error
-
- break
- case 2: //透析处方
- err = readDb.Raw("select count(distinct id) as count, DATE_FORMAT(date(from_unixtime(created_time)) ,'%Y-%m-%d') as times from xt_dialysis_prescription where DATE_SUB(CURDATE(), INTERVAL 30 DAY) <= date(from_unixtime(created_time)) AND status = 1 AND user_org_id = ? GROUP BY times", org_id).Scan(&weekStatistics).Error
-
- break
- case 3: //接诊评估
- err = readDb.Raw("select count(distinct id) as count, DATE_FORMAT(date(from_unixtime(created_time)) ,'%Y-%m-%d') as times from xt_receive_treatment_asses where DATE_SUB(CURDATE(), INTERVAL 30 DAY) <= date(from_unixtime(created_time)) AND status = 1 AND user_org_id = ? GROUP BY times", org_id).Scan(&weekStatistics).Error
-
- break
- case 4: //透前评估
- err = readDb.Raw("select count(distinct id) as count, DATE_FORMAT(date(from_unixtime(created_time)) ,'%Y-%m-%d') as times from xt_assessment_before_dislysis where DATE_SUB(CURDATE(), INTERVAL 30 DAY) <= date(from_unixtime(created_time)) AND status = 1 AND user_org_id = ? GROUP BY times", org_id).Scan(&weekStatistics).Error
- break
-
- case 5: //临时医嘱
- err = readDb.Raw("select count(distinct patient_id) as count, DATE_FORMAT(date(from_unixtime(created_time)) ,'%Y-%m-%d') as times from xt_doctor_advice where DATE_SUB(CURDATE(), INTERVAL 30 DAY) <= date(from_unixtime(created_time)) AND status = 1 AND user_org_id = ? GROUP BY times", org_id).Scan(&weekStatistics).Error
-
- break
- case 6: //双人核对
- err = readDb.Raw("select count(distinct id) as count, DATE_FORMAT(date(from_unixtime(created_time)) ,'%Y-%m-%d') as times from xt_double_check where DATE_SUB(CURDATE(), INTERVAL 30 DAY) <= date(from_unixtime(created_time)) AND status = 1 AND user_org_id = ? GROUP BY times", org_id).Scan(&weekStatistics).Error
-
- break
- case 7: //透析下机
- err = readDb.Raw("select count(distinct id) as count, DATE_FORMAT(date(from_unixtime(created_time)) ,'%Y-%m-%d') as times from xt_dialysis_order where DATE_SUB(CURDATE(), INTERVAL 30 DAY) <= date(from_unixtime(created_time)) AND status = 1 AND user_org_id = ? AND (stage = 2 OR stage = 1) GROUP BY times", org_id).Scan(&weekStatistics).Error
- break
-
- case 8: //透析监测
- err = readDb.Raw("select count(distinct patient_id) as count, DATE_FORMAT(date(from_unixtime(created_time)) ,'%Y-%m-%d') as times from xt_monitoring_record where DATE_SUB(CURDATE(), INTERVAL 30 DAY) <= date(from_unixtime(created_time)) AND status = 1 AND user_org_id = ? GROUP BY times", org_id).Scan(&weekStatistics).Error
- break
- case 9: //透析下机
- err = readDb.Raw("select count(distinct id) as count, DATE_FORMAT(date(from_unixtime(created_time)) ,'%Y-%m-%d') as times from xt_dialysis_order where DATE_SUB(CURDATE(), INTERVAL 30 DAY) <= date(from_unixtime(created_time)) AND stage = 2 AND status = 1 AND user_org_id = ? GROUP BY times", org_id).Scan(&weekStatistics).Error
-
- break
- case 10: //透后评估
- err = readDb.Raw("select count(distinct id) as count, DATE_FORMAT(date(from_unixtime(created_time)) ,'%Y-%m-%d') as times from xt_assessment_after_dislysis where DATE_SUB(CURDATE(), INTERVAL 30 DAY) <= date(from_unixtime(created_time)) AND status = 1 AND user_org_id = ? GROUP BY times", org_id).Scan(&weekStatistics).Error
- break
- case 11: //入库单
- err = readDb.Raw("select count(distinct id) as count, DATE_FORMAT(date(from_unixtime(ctime)) ,'%Y-%m-%d') as times from xt_warehouse where DATE_SUB(CURDATE(), INTERVAL 30 DAY) <= date(from_unixtime(ctime)) AND status = 1 AND org_id = ? GROUP BY times", org_id).Scan(&weekStatistics).Error
- break
- case 12: //出库单
- err = readDb.Raw("select count(distinct id) as count, DATE_FORMAT(date(from_unixtime(ctime)) ,'%Y-%m-%d') as times from xt_warehouse_out where DATE_SUB(CURDATE(), INTERVAL 30 DAY) <= date(from_unixtime(ctime)) AND status = 1 AND org_id = ? GROUP BY times", org_id).Scan(&weekStatistics).Error
- break
- }
- return
- }
-
- func GetThreeMonthOrgDialysisCount(statices_type int64, org_id int64) (weekStatistics []*admin_models.Statistics, err error) {
- switch statices_type {
- case 1: //病人管理
- err = readDb.Raw("select count(distinct id) as count, DATE_FORMAT(date(from_unixtime(created_time)) ,'%Y-%m') as times from xt_patients where DATE_SUB(CURDATE(), INTERVAL 3 MONTH) <= date(from_unixtime(created_time)) AND status = 1 AND user_org_id = ? GROUP BY times", org_id).Scan(&weekStatistics).Error
-
- break
- case 2: //透析处方
- err = readDb.Raw("select count(distinct id) as count, DATE_FORMAT(date(from_unixtime(created_time)) ,'%Y-%m') as times from xt_dialysis_prescription where DATE_SUB(CURDATE(), INTERVAL 3 MONTH) <= date(from_unixtime(created_time)) AND status = 1 AND user_org_id = ? GROUP BY times", org_id).Scan(&weekStatistics).Error
-
- break
- case 3: //接诊评估
- err = readDb.Raw("select count(distinct id) as count, DATE_FORMAT(date(from_unixtime(created_time)) ,'%Y-%m') as times from xt_receive_treatment_asses where DATE_SUB(CURDATE(), INTERVAL 3 MONTH) <= date(from_unixtime(created_time)) AND status = 1 AND user_org_id = ? GROUP BY times", org_id).Scan(&weekStatistics).Error
-
- break
- case 4: //透前评估
- err = readDb.Raw("select count(distinct id) as count, DATE_FORMAT(date(from_unixtime(created_time)) ,'%Y-%m') as times from xt_assessment_before_dislysis where DATE_SUB(CURDATE(), INTERVAL 3 MONTH) <= date(from_unixtime(created_time)) AND status = 1 AND user_org_id = ? GROUP BY times", org_id).Scan(&weekStatistics).Error
- break
-
- case 5: //临时医嘱
- err = readDb.Raw("select count(distinct patient_id) as count, DATE_FORMAT(date(from_unixtime(created_time)) ,'%Y-%m') as times from xt_doctor_advice where DATE_SUB(CURDATE(),INTERVAL 3 MONTH) <= date(from_unixtime(created_time)) AND status = 1 AND user_org_id = ? GROUP BY times", org_id).Scan(&weekStatistics).Error
-
- break
- case 6: //双人核对
- err = readDb.Raw("select count(distinct id) as count, DATE_FORMAT(date(from_unixtime(created_time)) ,'%Y-%m') as times from xt_double_check where DATE_SUB(CURDATE(), INTERVAL 3 MONTH) <= date(from_unixtime(created_time)) AND status = 1 AND user_org_id = ? GROUP BY times", org_id).Scan(&weekStatistics).Error
-
- break
- case 7: //透析上机
- err = readDb.Raw("select count(distinct id) as count, DATE_FORMAT(date(from_unixtime(created_time)) ,'%Y-%m') as times from xt_dialysis_order where DATE_SUB(CURDATE(), INTERVAL 3 MONTH) <= date(from_unixtime(created_time)) AND status = 1 AND user_org_id = ? AND (stage = 2 OR stage = 1) GROUP BY times", org_id).Scan(&weekStatistics).Error
- break
-
- case 8: //透析监测
- err = readDb.Raw("select count(distinct patient_id) as count, DATE_FORMAT(date(from_unixtime(created_time)) ,'%Y-%m') as times from xt_monitoring_record where DATE_SUB(CURDATE(), INTERVAL 3 MONTH) <= date(from_unixtime(created_time)) AND status = 1 AND user_org_id = ? GROUP BY times ", org_id).Scan(&weekStatistics).Error
- break
- case 9: //透析下机
- err = readDb.Raw("select count(distinct id) as count, DATE_FORMAT(date(from_unixtime(created_time)) ,'%Y-%m') as times from xt_dialysis_order where DATE_SUB(CURDATE(), INTERVAL 3 MONTH) <= date(from_unixtime(created_time)) AND stage = 2 AND status = 1 AND user_org_id = ? GROUP BY times", org_id).Scan(&weekStatistics).Error
-
- break
- case 10: //透后评估
- err = readDb.Raw("select count(distinct id) as count, DATE_FORMAT(date(from_unixtime(created_time)) ,'%Y-%m') as times from xt_assessment_after_dislysis where DATE_SUB(CURDATE(),INTERVAL 3 MONTH) <= date(from_unixtime(created_time)) AND status = 1 AND user_org_id = ? GROUP BY times", org_id).Scan(&weekStatistics).Error
- break
- case 11: //入库单
- err = readDb.Raw("select count(distinct id) as count, DATE_FORMAT(date(from_unixtime(ctime)) ,'%Y-%m') as times from xt_warehouse where DATE_SUB(CURDATE(), INTERVAL 3 MONTH) <= date(from_unixtime(ctime)) AND status = 1 AND org_id = ? GROUP BY times ", org_id).Scan(&weekStatistics).Error
- break
- case 12: //出库单
- err = readDb.Raw("select count(distinct id) as count, DATE_FORMAT(date(from_unixtime(ctime)) ,'%Y-%m') as times from xt_warehouse_out where DATE_SUB(CURDATE(), INTERVAL 3 MONTH) <= date(from_unixtime(ctime)) AND status = 1 AND org_id = ? GROUP BY times", org_id).Scan(&weekStatistics).Error
- break
- }
- return
- }
-
- func GetSixMonthOrgDialysisCount(statices_type int64, org_id int64) (weekStatistics []*admin_models.Statistics, err error) {
- switch statices_type {
- case 1: //病人管理
- err = readDb.Raw("select count(distinct id) as count, DATE_FORMAT(date(from_unixtime(created_time)) ,'%Y-%m') as times from xt_patients where DATE_SUB(CURDATE(), INTERVAL 6 MONTH) <= date(from_unixtime(created_time)) AND status = 1 AND user_org_id = ? GROUP BY times", org_id).Scan(&weekStatistics).Error
-
- break
- case 2: //透析处方
- err = readDb.Raw("select count(distinct id) as count, DATE_FORMAT(date(from_unixtime(created_time)) ,'%Y-%m') as times from xt_dialysis_prescription where DATE_SUB(CURDATE(), INTERVAL 6 MONTH) <= date(from_unixtime(created_time)) AND status = 1 AND user_org_id = ? GROUP BY times", org_id).Scan(&weekStatistics).Error
-
- break
- case 3: //接诊评估
- err = readDb.Raw("select count(distinct id) as count, DATE_FORMAT(date(from_unixtime(created_time)) ,'%Y-%m') as times from xt_receive_treatment_asses where DATE_SUB(CURDATE(), INTERVAL 6 MONTH) <= date(from_unixtime(created_time)) AND status = 1 AND user_org_id = ? GROUP BY times", org_id).Scan(&weekStatistics).Error
-
- break
- case 4: //透前评估
- err = readDb.Raw("select count(distinct id) as count, DATE_FORMAT(date(from_unixtime(created_time)) ,'%Y-%m') as times from xt_assessment_before_dislysis where DATE_SUB(CURDATE(), INTERVAL 6 MONTH) <= date(from_unixtime(created_time)) AND status = 1 AND user_org_id = ? GROUP BY times", org_id).Scan(&weekStatistics).Error
- break
-
- case 5: //临时医嘱
- err = readDb.Raw("select count(distinct patient_id) as count, DATE_FORMAT(date(from_unixtime(created_time)) ,'%Y-%m') as times from xt_doctor_advice where DATE_SUB(CURDATE(),INTERVAL 6 MONTH) <= date(from_unixtime(created_time)) AND status = 1 AND user_org_id = ? GROUP BY times", org_id).Scan(&weekStatistics).Error
-
- break
- case 6: //双人核对
- err = readDb.Raw("select count(distinct id) as count, DATE_FORMAT(date(from_unixtime(created_time)) ,'%Y-%m') as times from xt_double_check where DATE_SUB(CURDATE(), INTERVAL 6 MONTH) <= date(from_unixtime(created_time)) AND status = 1 AND user_org_id = ? GROUP BY times", org_id).Scan(&weekStatistics).Error
-
- break
- case 7: //透析上机
- err = readDb.Raw("select count(distinct id) as count, DATE_FORMAT(date(from_unixtime(created_time)) ,'%Y-%m') as times from xt_dialysis_order where DATE_SUB(CURDATE(), INTERVAL 6 MONTH) <= date(from_unixtime(created_time)) AND status = 1 AND user_org_id = ? AND (stage = 2 OR stage = 1) GROUP BY times", org_id).Scan(&weekStatistics).Error
- break
-
- case 8: //透析监测
- err = readDb.Raw("select count(distinct patient_id) as count, DATE_FORMAT(date(from_unixtime(created_time)) ,'%Y-%m') as times from xt_monitoring_record where DATE_SUB(CURDATE(), INTERVAL 6 MONTH) <= date(from_unixtime(created_time)) AND status = 1 AND user_org_id = ? GROUP BY times ", org_id).Scan(&weekStatistics).Error
- break
- case 9: //透析下机
- err = readDb.Raw("select count(distinct id) as count, DATE_FORMAT(date(from_unixtime(created_time)) ,'%Y-%m') as times from xt_dialysis_order where DATE_SUB(CURDATE(), INTERVAL 6 MONTH) <= date(from_unixtime(created_time)) AND stage = 2 AND status = 1 AND user_org_id = ? GROUP BY times", org_id).Scan(&weekStatistics).Error
-
- break
- case 10: //透后评估
- err = readDb.Raw("select count(distinct id) as count, DATE_FORMAT(date(from_unixtime(created_time)) ,'%Y-%m') as times from xt_assessment_after_dislysis where DATE_SUB(CURDATE(),INTERVAL 6 MONTH) <= date(from_unixtime(created_time)) AND status = 1 AND user_org_id = ? GROUP BY times", org_id).Scan(&weekStatistics).Error
- break
- case 11: //入库单
- err = readDb.Raw("select count(distinct id) as count, DATE_FORMAT(date(from_unixtime(ctime)) ,'%Y-%m') as times from xt_warehouse where DATE_SUB(CURDATE(), INTERVAL 6 MONTH) <= date(from_unixtime(ctime)) AND status = 1 AND org_id = ? GROUP BY times ", org_id).Scan(&weekStatistics).Error
- break
- case 12: //出库单
- err = readDb.Raw("select count(distinct id) as count, DATE_FORMAT(date(from_unixtime(ctime)) ,'%Y-%m') as times from xt_warehouse_out where DATE_SUB(CURDATE(), INTERVAL 6 MONTH) <= date(from_unixtime(ctime)) AND status = 1 AND org_id = ? GROUP BY times", org_id).Scan(&weekStatistics).Error
- break
- }
- return
- }
-
- func GetYearOrgDialysisCount(statices_type int64, org_id int64) (weekStatistics []*admin_models.Statistics, err error) {
- switch statices_type {
- case 1: //病人管理
- err = readDb.Raw("select count(distinct id) as count, DATE_FORMAT(date(from_unixtime(created_time)) ,'%Y-%m') as times from xt_patients where DATE_SUB(CURDATE(), INTERVAL 12 MONTH) <= date(from_unixtime(created_time)) AND status = 1 AND user_org_id = ? GROUP BY times", org_id).Scan(&weekStatistics).Error
-
- break
- case 2: //透析处方
- err = readDb.Raw("select count(distinct id) as count, DATE_FORMAT(date(from_unixtime(created_time)) ,'%Y-%m') as times from xt_dialysis_prescription where DATE_SUB(CURDATE(), INTERVAL 12 MONTH) <= date(from_unixtime(created_time)) AND status = 1 AND user_org_id = ? GROUP BY times", org_id).Scan(&weekStatistics).Error
-
- break
- case 3: //接诊评估
- err = readDb.Raw("select count(distinct id) as count, DATE_FORMAT(date(from_unixtime(created_time)) ,'%Y-%m') as times from xt_receive_treatment_asses where DATE_SUB(CURDATE(), INTERVAL 12 MONTH) <= date(from_unixtime(created_time)) AND status = 1 AND user_org_id = ? GROUP BY times", org_id).Scan(&weekStatistics).Error
-
- break
- case 4: //透前评估
- err = readDb.Raw("select count(distinct id) as count, DATE_FORMAT(date(from_unixtime(created_time)) ,'%Y-%m') as times from xt_assessment_before_dislysis where DATE_SUB(CURDATE(), INTERVAL 12 MONTH) <= date(from_unixtime(created_time)) AND status = 1 AND user_org_id = ? GROUP BY times", org_id).Scan(&weekStatistics).Error
- break
-
- case 5: //临时医嘱
- err = readDb.Raw("select count(distinct patient_id) as count, DATE_FORMAT(date(from_unixtime(created_time)) ,'%Y-%m') as times from xt_doctor_advice where DATE_SUB(CURDATE(),INTERVAL 12 MONTH) <= date(from_unixtime(created_time)) AND status = 1 AND user_org_id = ? GROUP BY times", org_id).Scan(&weekStatistics).Error
-
- break
- case 6: //双人核对
- err = readDb.Raw("select count(distinct id) as count, DATE_FORMAT(date(from_unixtime(created_time)) ,'%Y-%m') as times from xt_double_check where DATE_SUB(CURDATE(), INTERVAL 12 MONTH) <= date(from_unixtime(created_time)) AND status = 1 AND user_org_id = ? GROUP BY times", org_id).Scan(&weekStatistics).Error
-
- break
- case 7: //透析上机
- err = readDb.Raw("select count(distinct id) as count, DATE_FORMAT(date(from_unixtime(created_time)) ,'%Y-%m') as times from xt_dialysis_order where DATE_SUB(CURDATE(), INTERVAL 12 MONTH) <= date(from_unixtime(created_time)) AND status = 1 AND user_org_id = ? AND (stage = 2 OR stage = 1) GROUP BY times", org_id).Scan(&weekStatistics).Error
- break
-
- case 8: //透析监测
- err = readDb.Raw("select count(distinct patient_id) as count, DATE_FORMAT(date(from_unixtime(created_time)) ,'%Y-%m') as times from xt_monitoring_record where DATE_SUB(CURDATE(), INTERVAL 12 MONTH) <= date(from_unixtime(created_time)) AND status = 1 AND user_org_id = ? GROUP BY times ", org_id).Scan(&weekStatistics).Error
- break
- case 9: //透析下机
- err = readDb.Raw("select count(distinct id) as count, DATE_FORMAT(date(from_unixtime(created_time)) ,'%Y-%m') as times from xt_dialysis_order where DATE_SUB(CURDATE(), INTERVAL 12 MONTH) <= date(from_unixtime(created_time)) AND stage = 2 AND status = 1 AND user_org_id = ? GROUP BY times", org_id).Scan(&weekStatistics).Error
-
- break
- case 10: //透后评估
- err = readDb.Raw("select count(distinct id) as count, DATE_FORMAT(date(from_unixtime(created_time)) ,'%Y-%m') as times from xt_assessment_after_dislysis where DATE_SUB(CURDATE(),INTERVAL 12 MONTH) <= date(from_unixtime(created_time)) AND status = 1 AND user_org_id = ? GROUP BY times", org_id).Scan(&weekStatistics).Error
- break
- case 11: //入库单
- err = readDb.Raw("select count(distinct id) as count, DATE_FORMAT(date(from_unixtime(ctime)) ,'%Y-%m') as times from xt_warehouse where DATE_SUB(CURDATE(), INTERVAL 12 MONTH) <= date(from_unixtime(ctime)) AND status = 1 AND org_id = ? GROUP BY times ", org_id).Scan(&weekStatistics).Error
- break
- case 12: //出库单
- err = readDb.Raw("select count(distinct id) as count, DATE_FORMAT(date(from_unixtime(ctime)) ,'%Y-%m') as times from xt_warehouse_out where DATE_SUB(CURDATE(), INTERVAL 12 MONTH) <= date(from_unixtime(ctime)) AND status = 1 AND org_id = ? GROUP BY times", org_id).Scan(&weekStatistics).Error
- break
- }
- return
- }
-
- func GetDistrictsByUpid(id int64) (dis []*models.District, err error) {
- err = readUserDb.Model(&models.District{}).Where("upid=?", id).Find(&dis).Error
- return
- }
-
- func FindAllFollower() (follower []*admin_models.AdminAccount, err error) {
- err = readUserDb.Model(&admin_models.AdminAccount{}).Where("status = 1 AND is_super_admin <> 1").Find(&follower).Error
- return
-
- }
-
- func FindPatientById(id int64, page int64, limit int64) (patients []*models.Patients, err error, total int64) {
- offset := (page - 1) * limit
- db := readDb.Model(&models.Patients{}).Where("user_org_id=? AND status = 1", id)
- db = db.Count(&total)
- err = db.Offset(offset).Limit(limit).Find(&patients).Error
- return
- }
-
- func GetAppTypeByOrgId(org_id int64) (appType models.OrgApp, err error) {
- err = readUserDb.Model(&models.OrgApp{}).Where("app_type = 3 AND org_id = ?", org_id).First(&appType).Error
- return
- }
-
- func GetRoles(orgID int64, appID int64, page int, count int) ([]*models.Role, int, error) {
- var roles []*models.Role
- var totalCount int
- err := readUserDb.Model(&models.Role{}).
- Where("org_id = ? AND app_id = ?", orgID, appID).
- Count(&totalCount).
- Order("ctime asc").Limit(count).Offset((page - 1) * count).
- Find(&roles).
- Error
- if err != nil {
- if err == gorm.ErrRecordNotFound {
- return make([]*models.Role, 0), 0, nil
- } else {
- return nil, 0, err
- }
- }
- return roles, totalCount, nil
- }
-
- type AdminUserManageViewModel struct {
- AdminUserId int `gorm:"admin_user_id" json:"user_id"`
- UserName string `gorm:"user_name" json:"user_name"`
- RoleName string `gorm:"role_name" json:"role_name"`
- UserTitle int `gorm:"user_title" json:"user_title"`
- Ip string `gorm:"ip" json:"ip"`
- LastTime int64 `gorm:"ctime" json:"last_login_time"`
- Status int `gorm:"status" json:"status"`
- Mobile string `gorm:"mobile" json:"mobile"`
-
- // LastLoginTimeStr string `gorm:"-" json:"last_login_time_formatted"`
- TitleName string `gorm:"-" json:"title_name"`
- }
-
- func GetAdminUsersAndLoginInfo(orgID int64, appID int64, page int64, count int64) ([]*AdminUserManageViewModel, int, error) {
- if count <= 0 {
- return []*AdminUserManageViewModel{}, 0, nil
- }
- if page < 1 {
- page = 1
- }
- var viewModels []*AdminUserManageViewModel = make([]*AdminUserManageViewModel, 0)
- rows, err := readUserDb.Raw("SELECT u_a_r.admin_user_id, u_a_r.user_name, u_r.role_name, u_a_r.user_title, u_l.ip, u_l.last_time, u_a_r.status, admin.mobile FROM sgj_user_admin_role AS u_a_r JOIN sgj_user_admin AS admin ON admin.id = u_a_r.admin_user_id INNER JOIN sgj_user_role AS u_r ON u_a_r.org_id = u_r.org_id AND u_a_r.app_id = u_r.app_id AND u_r.id = u_a_r.role_id LEFT JOIN (SELECT * FROM (SELECT admin_user_id, org_id, app_id, ip, MAX(ctime) as last_time FROM sgj_user_admin_login_log WHERE org_id = ? AND app_id = ? GROUP BY admin_user_id ORDER BY ctime DESC) AS t GROUP BY admin_user_id) AS u_l ON u_a_r.org_id = u_l.org_id AND u_a_r.app_id = u_l.app_id AND u_a_r.admin_user_id = u_l.admin_user_id WHERE u_a_r.org_id = ? AND u_a_r.app_id = ? GROUP BY u_a_r.admin_user_id LIMIT ? OFFSET ?;", orgID, appID, orgID, appID, count, (page-1)*count).Rows()
- defer rows.Close()
- if err != nil {
- if err == gorm.ErrRecordNotFound {
- return viewModels, 0, nil
- } else {
- return nil, 0, err
- }
- }
- for rows.Next() {
- var viewModel AdminUserManageViewModel
- readUserDb.ScanRows(rows, &viewModel)
- title, _ := models.UserTitle[viewModel.UserTitle]
- viewModel.TitleName = title
- viewModels = append(viewModels, &viewModel)
- }
- total := 0
- readUserDb.Table("sgj_user_admin_role as u_a_r").Joins("join sgj_user_role as u_r on u_r.org_id = u_a_r.org_id AND u_r.app_id = u_a_r.app_id AND u_r.id = u_a_r.role_id").Where("u_a_r.org_id = ? AND u_a_r.app_id = ?", orgID, appID).Count(&total)
- return viewModels, total, nil
- }
-
- func GetAllValidDeviceZones(orgID int64) ([]*models.DeviceZone, error) {
- var zones []*models.DeviceZone
- err := readDb.Model(&models.DeviceZone{}).Where("org_id = ? AND status = 1", orgID).Find(&zones).Error
- if err != nil {
- return nil, err
- }
- return zones, nil
- }
-
- func GetAllValidDeviceGroups(orgID int64) ([]*models.DeviceGroup, error) {
- var groups []*models.DeviceGroup
- err := readDb.Model(&models.DeviceGroup{}).Where("org_id = ? AND status = 1", orgID).Find(&groups).Error
- if err != nil {
- return nil, err
- }
- return groups, nil
- }
-
- type DeviceNumberViewModel struct {
- models.DeviceNumber
- ZoneName string `gorm:"column:zone_name" json:"zone_name"`
- GroupName string `gorm:"column:group_name" json:"group_name"`
- }
-
- func GetAllValidDeviceNumbers(orgID int64) ([]*DeviceNumberViewModel, error) {
- var vms []*DeviceNumberViewModel = make([]*DeviceNumberViewModel, 0)
- rows, err := readDb.Raw("SELECT n.*, z.name as zone_name, g.name as group_name FROM xt_device_number as n join xt_device_zone as z on z.id = n.zone_id join xt_device_group as g on g.id = n.group_id WHERE (n.org_id = ? AND n.status = 1)", orgID).Rows()
- defer rows.Close()
- if err != nil {
- return nil, err
- }
- for rows.Next() {
- var vm DeviceNumberViewModel
- readDb.ScanRows(rows, &vm)
- vms = append(vms, &vm)
- }
- return vms, nil
- }
-
- func GetFollowOrgList(follow int64) (list []*models.Org, err error) {
-
- err = readUserDb.Model(&models.Org{}).Where("NOT EXISTS (Select * FROM sgj_org_follow Where sgj_org_follow.org_id = sgj_user_org.id AND sgj_org_follow.status = 1) AND import <> 1 AND DATE_SUB(CURDATE(), INTERVAL 15 DAY) <= date(from_unixtime(sgj_user_org.ctime)) AND status = 1").Preload("OrgFollow", func(db *gorm.DB) *gorm.DB {
- return db.Model(&models.OrgFollow{}).Where("status = 1").Preload("AdminAccount", "status = 1")
- }).Preload("AdminUserLoginLog", func(db *gorm.DB) *gorm.DB {
- return db.Model(&models.AdminUserLoginLog{}).Where("id = (SELECT max(id))")
- }).Preload("Citys").Order("ctime desc").Scan(&list).Error
-
- return
-
- }
-
- type ActiveOrg struct {
- OrgId int64 `gorm:"org_id" json:"org_id"`
- OrgName string `gorm:"org_name" json:"org_name"`
- }
-
- func GetActiveOrgList(from int64, to int64) (list []*ActiveOrg, err error) {
- err = readUserDb.Raw("Select a.org_id as org_id, org.org_name as org_name from (Select org_id from sgj_user_admin_login_log log JOIN (Select d.user_org_id from (Select new_role.user_org_id from (Select count(*) as count,org_id as user_org_id from sgj_users.sgj_user_admin_role role where role.`user_type` = 2 OR role.`user_type` = 3 Group by role.org_id) new_role where new_role.count > 2) d JOIN (Select user_org_id from (Select count(*) as count,user_org_id from sgj_xt.xt_patients where status = 1 Group by user_org_id) new_patient where new_patient.count > 3) c On d.user_org_id = c.user_org_id) new_user_org ON new_user_org.user_org_id = log.org_id where ctime >= ? AND ctime <= ? Group by log.org_id) a JOIN sgj_users.sgj_user_org org On a.org_id = org.id", from, to).Scan(&list).Error
- return
- }
-
- func GetNewCreateOrgList(from int64, to int64) (list []*ActiveOrg, err error) {
- err = readUserDb.Raw("select org.id as org_id, org.org_name as org_name from sgj_user_org org where org.status = 1 AND org.import <> 1 AND org.ctime >= ? AND org.ctime <= ?", from, to).Scan(&list).Error
- return
- }
-
- type DoctorNurse struct {
- Date string `gorm:"date" json:"date"`
- Mobile string `gorm:"mobile" json:"mobile"`
- }
-
- func GetNewDoctorNurseList(from int64, to int64) (list []*DoctorNurse, err error) {
- err = readUserDb.Raw("select from_unixtime(log.`ctime`, '%Y-%m-%d %H:%m:%s') as date, admin.mobile as mobile from sgj_user_admin_login_log log Join `sgj_user_admin` admin on log.`admin_user_id` = admin.`id` Where log.`operate_type` = 1 and log.`app_type` = 3 and log.ctime >= ? and log.ctime <= ?", from, to).Scan(&list).Error
- return
- }
-
- type Patient struct {
- CreatedTime string `gorm:"created_time" json:"created_time"`
- Name string `gorm:"name" json:"name"`
- }
-
- func GetNewPatientList(from int64, to int64) (list []*Patient, err error) {
- err = readDb.Raw("select name, from_unixtime(created_time, '%Y-%m-%d %H:%m:%s') as created_time from xt_patients where created_time >= ? AND created_time <= ? AND status = 1", from, to).Scan(&list).Error
- return
- }
|