123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227 |
- package service
-
- import (
- "XT_New/models"
- "github.com/jinzhu/gorm"
- "time"
- )
-
- func GetAppVersionByAppType(apptype int64) (*models.AppVersion, error) {
- var version models.AppVersion
- err := readDb.Model(&models.AppVersion{}).Where("app_type=?", apptype).First(&version).Error
- if err == gorm.ErrRecordNotFound {
- return nil, nil
- }
-
- if err != nil {
- return nil, err
- }
- return &version, nil
- }
-
- func GetAllAppOrg() ([]*models.OrgApp, error) {
- var app []*models.OrgApp
- err := readUserDb.Model(&models.OrgApp{}).Where("status = 1 AND org_id > 0").Group("org_id").Find(&app).Error
- if err == gorm.ErrRecordNotFound {
- return nil, nil
- }
-
- if err != nil {
- return nil, err
- }
- return app, nil
- }
-
- func GetSystemApp() ([]*models.OrgApp, error) {
- var app []*models.OrgApp
- err := readDb.Model(&models.OrgApp{}).Where("status = 1 AND org_id = 0 ").Find(&app).Error
- if err == gorm.ErrRecordNotFound {
- return nil, nil
- }
-
- if err != nil {
- return nil, err
- }
- return app, nil
- }
-
- func GetApp() ([]*models.OrgApp, error) {
- var app []*models.OrgApp
- err := readDb.Model(&models.OrgApp{}).Where("status = 1 AND org_id = 0").Find(&app).Error
- if err == gorm.ErrRecordNotFound {
- return nil, nil
- }
-
- if err != nil {
- return nil, err
- }
- return app, nil
- }
-
- func GetAppByType(orgID int64, app_type int) (*models.OrgApp, error) {
- var apps models.OrgApp
- err := readUserDb.Where("app_type = ? AND org_id = ? AND status = 1", app_type, orgID).First(&apps).Error
- if err != nil {
- return nil, err
- }
- return &apps, nil
- }
-
- func CreateOrgApp(app *models.OrgApp) {
- writeUserDb.Create(&app)
-
- }
-
- func GetAllUserRole(org_id int64) (appRole []*models.App_Role) {
- if org_id == 0 {
- readUserDb.Model(&models.App_Role{}).Where("status = 1").Find(&appRole)
-
- } else {
- readUserDb.Model(&models.App_Role{}).Where("status = 1 AND org_id = ? ", org_id).Find(&appRole)
-
- }
- return
- }
-
- func GetAllUserRoleByUserTypeOne(org_id int) (appRole []*models.App_Role) {
- readUserDb.Model(&models.App_Role{}).Where("status = 1 AND user_type = 1").Find(&appRole)
- return
- }
-
- func GetAllUserRoleByUserTypeOther() (appRole []*models.App_Role) {
- //app, _ := GetOrgApp(int64(org_id), 3)
-
- //if org_id == 0 {
- readUserDb.Model(&models.App_Role{}).Where("status = 1 AND user_type > 1").Find(&appRole)
- //
- //} else {
- // readUserDb.Model(&models.App_Role{}).Where("status = 1 AND org_id = ? AND user_type > 1 AND app_id = ? ", org_id, app.Id).Find(&appRole)
- //
- //}
- return
- }
-
- func FindRoleByUserTypeOne(org_id int64) (role models.Role) {
- readUserDb.Model(&models.Role{}).Where("status = 1 AND org_id = ? AND is_system = 2 AND role_name = '医生'", org_id).First(&role)
- return
- }
-
- func FindRoleByUserTypeTwo(org_id int64) (role models.Role) {
- readUserDb.Model(&models.Role{}).Where("status = 1 AND org_id = ? AND is_system = 3 AND role_name = '护士'", org_id).First(&role)
- return
- }
-
- func GetAllRole() ([]*models.Role, error) {
- var app []*models.Role
- err := readUserDb.Model(&models.Role{}).Where("status = 1 AND org_id > 0").Group("org_id").Find(&app).Error
- if err == gorm.ErrRecordNotFound {
- return nil, nil
- }
- if err != nil {
- return nil, err
- }
- return app, nil
- }
-
- func UpdateRoleIds(id int64, ids string) {
- writeUserDb.Model(&models.App_Role{}).Where("status = 1 AND id = ?", id).Updates(map[string]interface{}{"role_ids": ids, "mtime": time.Now().Unix()})
-
- }
-
- func GetOrgAppA(orgID int64, app_type int) (*models.OrgApp, error) {
- var apps models.OrgApp
- err := readUserDb.Where("app_type = ? AND org_id = ? AND status = 1", app_type, orgID).First(&apps).Error
- if err != nil {
- return nil, err
- }
- return &apps, nil
- }
-
- func GetOrgByIdB(orgID int64) (*models.Org, error) {
- var org models.Org
- err := readUserDb.Model(&models.Org{}).Where("id = ?", orgID).First(&org).Error
- if err != nil {
- if err == gorm.ErrRecordNotFound {
- return nil, nil
- } else {
- return nil, err
- }
- }
- return &org, nil
- }
-
- func GetOrgAppB(orgID int64, app_type int) (*models.OrgApp, error) {
- var apps models.OrgApp
- err := readUserDb.Where("app_type = ? AND org_id = ? AND status = 1", app_type, orgID).First(&apps).Error
- if err != nil {
- return nil, err
- }
- return &apps, nil
- }
-
- func CreateOrgRoleB(role *models.Role) (err error) {
- err = writeUserDb.Create(&role).Error
- return
- }
-
- func CreateRolePurviewB(purview *models.RolePurview) (err error) {
- err = writeUserDb.Create(&purview).Error
- return
- }
-
- func CreateFuncRolePurviewB(purview *models.SgjUserRoleFuncPurview) (err error) {
- err = writeUserDb.Create(&purview).Error
- return
- }
-
- func GetSystemRole(orgID int64) ([]*models.Role, error) {
- var roles []*models.Role
- err := readUserDb.Where(" org_id = ? AND status = 1 AND is_system > 1", orgID).First(&roles).Error
- if err != nil {
- return nil, err
- }
- return roles, nil
- }
-
- func HandleData() {
- var pe []*models.PredialysisEvaluation
- //readDb.Model(&models.DialysisPrescription{}).Where("user_org_id = 12 AND record_date <= 1587571200").Find(&prescription)
- //for _, item := range prescription {
- // 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})
- //}
- readDb.Model(&models.PredialysisEvaluation{}).Where("status = 1 AND user_org_id = 9538 AND dialysis_order_id > 0").Find(&pe)
-
- for _, item := range pe {
- var sch models.Schedule
- 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
-
- if err == nil {
- if sch.ID > 0 {
- order := &models.DialysisOrder{
- DialysisDate: sch.ScheduleDate,
- UserOrgId: 9538,
- PatientId: sch.PatientId,
- Stage: 2,
- BedID: sch.BedId,
- StartNurse: 554,
- FinishNurse: 554,
- Status: 1,
- CreatedTime: sch.ScheduleDate,
- UpdatedTime: sch.ScheduleDate,
- StartTime: sch.ScheduleDate,
- EndTime: sch.ScheduleDate,
- PunctureNurse: 554,
- Creator: 554,
- Modifier: 554,
- FinishCreator: 554,
- FinishModifier: 554,
- SchedualType: sch.ScheduleType,
- }
- writeDb.Create(&order)
- }
- }
-
- }
-
- }
|