123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276 |
- package login_service
-
- import (
- "Kya_New/models"
- "Kya_New/service"
- "Kya_New/utils"
- "fmt"
- "github.com/astaxie/beego"
- "github.com/go-redis/redis"
- "github.com/jinzhu/gorm"
- "github.com/robfig/cron"
- "time"
- )
-
- func QueryLogin(tel string, psd string) (admin models.SgjUserAdmin, err error) {
- fmt.Println(service.UserReadDB())
- err = service.UserReadDB().Model(&models.SgjUserAdmin{}).Where("mobile = ? AND password = ? AND status = ?", tel, psd, 1).First(&admin).Error
- return
- }
-
- func GetQueryUserOrgId(creator int64) (*models.SgjUserOrg, error) {
- var org models.SgjUserOrg
- var err error
- err = service.UserReadDB().Where("creator = ? AND status = ?", creator, 1).Find(&org).Error
- if err == gorm.ErrRecordNotFound {
- return nil, err
- }
- if err != nil {
- return nil, err
- }
- return &org, nil
- }
-
- func init() {
- utils.InfoLog("开启更新数据")
- updateDefalutData := cron.New()
- spec := "*/1 * * * * ?"
- updateDefalutData.AddFunc(spec, func() {
-
- })
- }
-
- func GetQueryPhoneData(phone string) (models.SgjUserAdmin, error) {
- admin := models.SgjUserAdmin{}
- err := service.UserReadDB().Where("mobile = ? AND status = ?", phone, 1).Find(&admin).Error
- return admin, err
- }
-
- func RedisClient() *redis.Client {
- address := fmt.Sprintf("%s:%s", beego.AppConfig.String("redishost"), beego.AppConfig.String("redisport"))
- client := redis.NewClient(&redis.Options{
- Addr: address,
- Password: beego.AppConfig.String("redispasswrod"), // no password set
- DB: 0, // use default DB
- })
-
- pong, err := client.Ping().Result()
- fmt.Println(pong, err)
- return client
- }
-
- func GetQueryMobileData(phone string) (*models.SgjUserAdmin, error) {
-
- var user models.SgjUserAdmin
- var err error
- err = service.UserReadDB().Model(&models.SgjUserAdmin{}).Where("mobile = ? AND status = 1", phone).Find(&user).Error
- if err == gorm.ErrRecordNotFound {
- return nil, err
- }
- if err != nil {
- return nil, err
- }
- return &user, nil
-
- }
-
- func AddAdmin(admin *models.SgjUserAdmin) error {
-
- err := service.UserWriteDB().Create(&admin).Error
- return err
- }
-
- func GetAllProvince(id int64) (dist []*models.SgjUserDistrict, err error) {
-
- err = service.UserReadDB().Model(&models.SgjUserDistrict{}).Where("upid = ?", id).Find(&dist).Error
- return dist, err
- }
-
- func UpdatedPassword(phone string, admin *models.SgjUserAdmin) error {
- err := service.UserWriteDB().Model(&admin).Where("mobile = ?", phone).Update(map[string]interface{}{"password": admin.Password, "mtime": time.Now().Unix()}).Error
- return err
- }
-
- func GetAllOrgName(id int64) (orgs []*models.SgjUserOrg, err error) {
- fmt.Println("id是什么", id)
- err = service.UserReadDB().Model(&models.SgjUserOrg{}).Where("creator = ? AND status = ?", id, 1).Find(&orgs).Error
- fmt.Println("错误", err)
- fmt.Println("orgs", orgs)
- return orgs, err
- }
-
- func GetCityById(id int64) (ids []*models.SgjUserDistrict, err error) {
- err = service.UserReadDB().Model(&models.SgjUserDistrict{}).Where("upid = ?", id).Find(&ids).Error
- return ids, err
- }
-
- func GetAllOrgType() (orgType []*models.SgjUserOrgType, err error) {
-
- err = service.UserReadDB().Model(&models.SgjUserOrgType{}).Where("status= ? AND id = ? OR id = ? OR id = ? OR id = ? OR id = ? OR id = ?", 1, 1, 7, 12, 16, 21, 26).Order("sort_no").Find(&orgType).Error
- return
- }
-
- func AddUserOrgInfo(org *models.SgjUserOrg) error {
-
- err := service.UserWriteDB().Create(&org).Error
- return err
- }
-
- func CreateSubscibe(subscibe *models.ServeSubscibe) error {
-
- err := service.UserWriteDB().Create(&subscibe).Error
- return err
- }
-
- func GeLastUserOrgLastData(id int64) (models.SgjUserOrg, error) {
- userOrg := models.SgjUserOrg{}
- err := service.UserReadDB().Where("creator = ? AND status = ?", id, 1).Find(&userOrg).Error
- return userOrg, err
- }
-
- func AddRole(role *models.UserRole) error {
-
- err := service.UserWriteDB().Create(&role).Error
- return err
- }
-
- func GetRoleLastDate(orgid int64) (models.UserRole, error) {
- role := models.UserRole{}
- err := service.UserReadDB().Where("org_id = ? AND status = ?", orgid, 1).Last(&role).Error
- return role, err
- }
-
- func AddUserOrgApp(app *models.UserOrgApp) error {
-
- err := service.UserWriteDB().Create(&app).Error
- return err
- }
-
- func GetLastData(orgid int64) (models.UserOrgApp, error) {
- app := models.UserOrgApp{}
- err := service.UserReadDB().Where("org_id = ? AND status = 1", orgid).Last(&app).Error
- return app, err
- }
-
- func AddAdimnRole(role *models.UserAdminRole) error {
-
- err := service.UserWriteDB().Create(&role).Error
- return err
- }
-
- func GetProvinceByName(orgname string) (models.SgjUserDistrict, error) {
- dis := models.SgjUserDistrict{}
- err := service.UserReadDB().Where("name = ? AND upid = ? ", orgname, 0).Find(&dis).Error
- return dis, err
- }
-
- func GetCityByName(cityname string, proviceid int64) (models.SgjUserDistrict, error) {
- district := models.SgjUserDistrict{}
- err := service.UserReadDB().Where("name = ? AND upid = ?", cityname, proviceid).Find(&district).Error
- return district, err
- }
-
- func GetCountByName(countname string, cityid int64) (models.SgjUserDistrict, error) {
- district := models.SgjUserDistrict{}
- err := service.UserReadDB().Where("name = ? AND upid = ?", countname, cityid).Find(&district).Error
- return district, err
- }
-
- func GetOrgTypeByName(orgname string) (models.SgjUserOrgType, error) {
- org := models.SgjUserOrgType{}
- err := service.UserReadDB().Where("name = ? AND status = ?", orgname, 1).Find(&org).Error
- return org, err
- }
-
- func GetBloodDialysisPatient(orgid int64, page int64, limit int64) (patients []*models.Patients, total int64, err error) {
- db := service.XTReadDB().Table("xt_patients as x").Where("x.status = 1")
- if orgid > 0 {
- db = db.Where("x.user_org_id = ?", orgid)
- }
- offset := (page - 1) * limit
- err = db.Count(&total).Order("x.created_time desc").Offset(offset).Limit(limit).
- Select("x.id,x.user_org_id,x.user_id,x.avatar,x.patient_type,x.dialysis_no,x.admission_number,x.source,x.lapseto,x.partition_id,x.bed_id,x.name,x.alias,x.gender,x.marital_status,x.id_card_no,x.birthday,x.reimbursement_way_id,x.health_care_type,x.health_care_no,x.health_care_due_date,x.height,x.blood_type,x.rh,x.health_care_due_alert_date,x.education_level,x.profession,x.phone,x.home_telephone,x.relative_phone,x.relative_relations,x.home_address,x.work_unit,x.unit_address,x.children,x.receiving_date,x.is_hospital_first_dialysis,x.first_dialysis_date,x.first_dialysis_hospital,x.predialysis_condition,x.pre_hospital_dialysis_frequency,x.pre_hospital_dialysis_times,x.hospital_first_dialysis_date,x.induction_period,x.initial_dialysis,x.total_dialysis,x.attending_doctor_id,x.head_nurse_id,x.evaluate,x.diagnose,x.remark,x.registrars_id,x.registrars,x.qr_code,x.binding_state,x.patient_complains,x.present_history,x.past_history,x.temperature,x.pulse,x.respiratory,x.sbp,x.dbp,x.status,x.created_time,x.updated_time,x.nation,x.native_place,x.age").Find(&patients).Error
- fmt.Println("err是什么", err)
- return
- }
-
- func GetPatintsInfo(id int64, orgid int64) (models.Patients, error) {
- patients := models.Patients{}
- err := service.XTReadDB().Where("id = ? AND user_org_id = ? AND status = ?", id, orgid, 1).Find(&patients).Error
- return patients, err
- }
-
- func GetPatientInfectious(patientid int64) (patients []*models.PatientsInfectiousDiseases, err error) {
-
- err = service.XTReadDB().Where("patient_id = ? AND status = ?", patientid, 1).Find(&patients).Error
- return patients, err
- }
-
- func GetCreatorId(orgid int64) (models.SgjUserOrg, error) {
- org := models.SgjUserOrg{}
- err := service.UserReadDB().Where("id = ? AND status = ? ", orgid, 1).Find(&org).Error
- return org, err
- }
-
- func GetOrgAppId(creatorid int64, orgid int64) (models.UserOrgApp, error) {
- app := models.UserOrgApp{}
- err := service.UserReadDB().Where("creator = ? AND org_id = ? AND app_type = ?", creatorid, orgid, 3).Find(&app).Error
- return app, err
- }
-
- func GetAdvceDoctor(creatorid int64, orgid int64, appid int64) (models.UserAdminRole, error) {
- role := models.UserAdminRole{}
- err := service.UserReadDB().Where("admin_user_id = ? and org_id = ? and app_id = ?", creatorid, orgid, appid).Find(&role).Error
- return role, err
- }
-
- func GetDoctorAdvice(patientid int64, orgId int64, startime int64, endtime int64, keywords string) (doctoradvice []*models.DoctorAdvice, total int64, err error) {
-
- db := service.XTReadDB().Model(&models.DoctorAdvice{}).Where("status = 1")
- if orgId > 0 {
- db = db.Where("user_org_id = ?", orgId)
- }
-
- if patientid > 0 {
- db = db.Where("patient_id = ?", patientid)
- }
- if startime != 0 {
- db = db.Where("start_time>= ?", startime)
- }
- if endtime != 0 {
- db = db.Where("start_time<=?", endtime)
- }
-
- if len(keywords) > 0 {
- likeKey := "%" + keywords + "%"
- db = db.Where("advice_name LIKE ?", likeKey)
- }
- err = db.Count(&total).Select("id, user_org_id, patient_id, advice_type, advice_date, record_date, start_time, advice_name,advice_desc, reminder_date, drug_spec, drug_spec_unit, single_dose, single_dose_unit, prescribing_number, prescribing_number_unit, delivery_way, execution_frequency, advice_doctor, status, created_time,updated_time, advice_affirm, remark, stop_time, stop_reason, stop_doctor, stop_state, parent_id, execution_time, execution_staff, execution_state, checker, check_state, check_time, groupno,remind_type,frequency_type,day_count,week_day, IF(parent_id > 0, parent_id, id) as advice_order").Order("start_time desc, groupno desc, advice_order desc, id asc").Scan(&doctoradvice).Error
- return
-
- // db := service.XTReadDB().Model(&models.DoctorAdvice{}).Where("status = 1")
- // if orgId>0 {
- // db = db.Where("user_org_id = ?", orgId)
- // }
- // if patientid > 0 {
- // db = db.Where("patient_id = ?", patientid)
- // }
- // db = db.Where("advice_date >= ?", startime)
- // db = db.Where("advice_date <=?", endtime)
- // //db = db.Where("advice_type int (?)", []int{1, 3})
- // err = db.Find(&doctoradvice).Error
- // return doctoradvice,err
- }
-
- func SeacherDoctorAdviceByAdviceName(patientid int64, orgid int64, serchval string) (doctoradvice []*models.DoctorAdvice, err error) {
-
- err = service.XTReadDB().Where("patient_id = ? AND user_org_id = ? AND advice_name = ?", patientid, orgid, serchval).Find(&doctoradvice).Error
- return doctoradvice, err
- }
-
- func DeleteDoctorAdvice(id int64) error {
-
- err := service.XTWriteDB().Model(models.DoctorAdvice{}).Where("id= ?", id).Update(map[string]interface{}{"status": 0, "mtime": time.Now().Unix()}).Error
- return err
- }
|