login_service.go 10KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276
  1. package login_service
  2. import (
  3. "Kya_New/models"
  4. "Kya_New/service"
  5. "Kya_New/utils"
  6. "fmt"
  7. "github.com/astaxie/beego"
  8. "github.com/go-redis/redis"
  9. "github.com/jinzhu/gorm"
  10. "github.com/robfig/cron"
  11. "time"
  12. )
  13. func QueryLogin(tel string, psd string) (admin models.SgjUserAdmin, err error) {
  14. fmt.Println(service.UserReadDB())
  15. err = service.UserReadDB().Model(&models.SgjUserAdmin{}).Where("mobile = ? AND password = ? AND status = ?", tel, psd, 1).First(&admin).Error
  16. return
  17. }
  18. func GetQueryUserOrgId(creator int64) (*models.SgjUserOrg, error) {
  19. var org models.SgjUserOrg
  20. var err error
  21. err = service.UserReadDB().Where("creator = ? AND status = ?", creator, 1).Find(&org).Error
  22. if err == gorm.ErrRecordNotFound {
  23. return nil, err
  24. }
  25. if err != nil {
  26. return nil, err
  27. }
  28. return &org, nil
  29. }
  30. func init() {
  31. utils.InfoLog("开启更新数据")
  32. updateDefalutData := cron.New()
  33. spec := "*/1 * * * * ?"
  34. updateDefalutData.AddFunc(spec, func() {
  35. })
  36. }
  37. func GetQueryPhoneData(phone string) (models.SgjUserAdmin, error) {
  38. admin := models.SgjUserAdmin{}
  39. err := service.UserReadDB().Where("mobile = ? AND status = ?", phone, 1).Find(&admin).Error
  40. return admin, err
  41. }
  42. func RedisClient() *redis.Client {
  43. address := fmt.Sprintf("%s:%s", beego.AppConfig.String("redishost"), beego.AppConfig.String("redisport"))
  44. client := redis.NewClient(&redis.Options{
  45. Addr: address,
  46. Password: beego.AppConfig.String("redispasswrod"), // no password set
  47. DB: 0, // use default DB
  48. })
  49. pong, err := client.Ping().Result()
  50. fmt.Println(pong, err)
  51. return client
  52. }
  53. func GetQueryMobileData(phone string) (*models.SgjUserAdmin, error) {
  54. var user models.SgjUserAdmin
  55. var err error
  56. err = service.UserReadDB().Model(&models.SgjUserAdmin{}).Where("mobile = ? AND status = 1", phone).Find(&user).Error
  57. if err == gorm.ErrRecordNotFound {
  58. return nil, err
  59. }
  60. if err != nil {
  61. return nil, err
  62. }
  63. return &user, nil
  64. }
  65. func AddAdmin(admin *models.SgjUserAdmin) error {
  66. err := service.UserWriteDB().Create(&admin).Error
  67. return err
  68. }
  69. func GetAllProvince(id int64) (dist []*models.SgjUserDistrict, err error) {
  70. err = service.UserReadDB().Model(&models.SgjUserDistrict{}).Where("upid = ?", id).Find(&dist).Error
  71. return dist, err
  72. }
  73. func UpdatedPassword(phone string, admin *models.SgjUserAdmin) error {
  74. err := service.UserWriteDB().Model(&admin).Where("mobile = ?", phone).Update(map[string]interface{}{"password": admin.Password, "mtime": time.Now().Unix()}).Error
  75. return err
  76. }
  77. func GetAllOrgName(id int64) (orgs []*models.SgjUserOrg, err error) {
  78. fmt.Println("id是什么", id)
  79. err = service.UserReadDB().Model(&models.SgjUserOrg{}).Where("creator = ? AND status = ?", id, 1).Find(&orgs).Error
  80. fmt.Println("错误", err)
  81. fmt.Println("orgs", orgs)
  82. return orgs, err
  83. }
  84. func GetCityById(id int64) (ids []*models.SgjUserDistrict, err error) {
  85. err = service.UserReadDB().Model(&models.SgjUserDistrict{}).Where("upid = ?", id).Find(&ids).Error
  86. return ids, err
  87. }
  88. func GetAllOrgType() (orgType []*models.SgjUserOrgType, err error) {
  89. 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
  90. return
  91. }
  92. func AddUserOrgInfo(org *models.SgjUserOrg) error {
  93. err := service.UserWriteDB().Create(&org).Error
  94. return err
  95. }
  96. func CreateSubscibe(subscibe *models.ServeSubscibe) error {
  97. err := service.UserWriteDB().Create(&subscibe).Error
  98. return err
  99. }
  100. func GeLastUserOrgLastData(id int64) (models.SgjUserOrg, error) {
  101. userOrg := models.SgjUserOrg{}
  102. err := service.UserReadDB().Where("creator = ? AND status = ?", id, 1).Find(&userOrg).Error
  103. return userOrg, err
  104. }
  105. func AddRole(role *models.UserRole) error {
  106. err := service.UserWriteDB().Create(&role).Error
  107. return err
  108. }
  109. func GetRoleLastDate(orgid int64) (models.UserRole, error) {
  110. role := models.UserRole{}
  111. err := service.UserReadDB().Where("org_id = ? AND status = ?", orgid, 1).Last(&role).Error
  112. return role, err
  113. }
  114. func AddUserOrgApp(app *models.UserOrgApp) error {
  115. err := service.UserWriteDB().Create(&app).Error
  116. return err
  117. }
  118. func GetLastData(orgid int64) (models.UserOrgApp, error) {
  119. app := models.UserOrgApp{}
  120. err := service.UserReadDB().Where("org_id = ? AND status = 1", orgid).Last(&app).Error
  121. return app, err
  122. }
  123. func AddAdimnRole(role *models.UserAdminRole) error {
  124. err := service.UserWriteDB().Create(&role).Error
  125. return err
  126. }
  127. func GetProvinceByName(orgname string) (models.SgjUserDistrict, error) {
  128. dis := models.SgjUserDistrict{}
  129. err := service.UserReadDB().Where("name = ? AND upid = ? ", orgname, 0).Find(&dis).Error
  130. return dis, err
  131. }
  132. func GetCityByName(cityname string, proviceid int64) (models.SgjUserDistrict, error) {
  133. district := models.SgjUserDistrict{}
  134. err := service.UserReadDB().Where("name = ? AND upid = ?", cityname, proviceid).Find(&district).Error
  135. return district, err
  136. }
  137. func GetCountByName(countname string, cityid int64) (models.SgjUserDistrict, error) {
  138. district := models.SgjUserDistrict{}
  139. err := service.UserReadDB().Where("name = ? AND upid = ?", countname, cityid).Find(&district).Error
  140. return district, err
  141. }
  142. func GetOrgTypeByName(orgname string) (models.SgjUserOrgType, error) {
  143. org := models.SgjUserOrgType{}
  144. err := service.UserReadDB().Where("name = ? AND status = ?", orgname, 1).Find(&org).Error
  145. return org, err
  146. }
  147. func GetBloodDialysisPatient(orgid int64, page int64, limit int64) (patients []*models.Patients, total int64, err error) {
  148. db := service.XTReadDB().Table("xt_patients as x").Where("x.status = 1")
  149. if orgid > 0 {
  150. db = db.Where("x.user_org_id = ?", orgid)
  151. }
  152. offset := (page - 1) * limit
  153. err = db.Count(&total).Order("x.created_time desc").Offset(offset).Limit(limit).
  154. 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
  155. fmt.Println("err是什么", err)
  156. return
  157. }
  158. func GetPatintsInfo(id int64, orgid int64) (models.Patients, error) {
  159. patients := models.Patients{}
  160. err := service.XTReadDB().Where("id = ? AND user_org_id = ? AND status = ?", id, orgid, 1).Find(&patients).Error
  161. return patients, err
  162. }
  163. func GetPatientInfectious(patientid int64) (patients []*models.PatientsInfectiousDiseases, err error) {
  164. err = service.XTReadDB().Where("patient_id = ? AND status = ?", patientid, 1).Find(&patients).Error
  165. return patients, err
  166. }
  167. func GetCreatorId(orgid int64) (models.SgjUserOrg, error) {
  168. org := models.SgjUserOrg{}
  169. err := service.UserReadDB().Where("id = ? AND status = ? ", orgid, 1).Find(&org).Error
  170. return org, err
  171. }
  172. func GetOrgAppId(creatorid int64, orgid int64) (models.UserOrgApp, error) {
  173. app := models.UserOrgApp{}
  174. err := service.UserReadDB().Where("creator = ? AND org_id = ? AND app_type = ?", creatorid, orgid, 3).Find(&app).Error
  175. return app, err
  176. }
  177. func GetAdvceDoctor(creatorid int64, orgid int64, appid int64) (models.UserAdminRole, error) {
  178. role := models.UserAdminRole{}
  179. err := service.UserReadDB().Where("admin_user_id = ? and org_id = ? and app_id = ?", creatorid, orgid, appid).Find(&role).Error
  180. return role, err
  181. }
  182. func GetDoctorAdvice(patientid int64, orgId int64, startime int64, endtime int64, keywords string) (doctoradvice []*models.DoctorAdvice, total int64, err error) {
  183. db := service.XTReadDB().Model(&models.DoctorAdvice{}).Where("status = 1")
  184. if orgId > 0 {
  185. db = db.Where("user_org_id = ?", orgId)
  186. }
  187. if patientid > 0 {
  188. db = db.Where("patient_id = ?", patientid)
  189. }
  190. if startime != 0 {
  191. db = db.Where("start_time>= ?", startime)
  192. }
  193. if endtime != 0 {
  194. db = db.Where("start_time<=?", endtime)
  195. }
  196. if len(keywords) > 0 {
  197. likeKey := "%" + keywords + "%"
  198. db = db.Where("advice_name LIKE ?", likeKey)
  199. }
  200. 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
  201. return
  202. // db := service.XTReadDB().Model(&models.DoctorAdvice{}).Where("status = 1")
  203. // if orgId>0 {
  204. // db = db.Where("user_org_id = ?", orgId)
  205. // }
  206. // if patientid > 0 {
  207. // db = db.Where("patient_id = ?", patientid)
  208. // }
  209. // db = db.Where("advice_date >= ?", startime)
  210. // db = db.Where("advice_date <=?", endtime)
  211. // //db = db.Where("advice_type int (?)", []int{1, 3})
  212. // err = db.Find(&doctoradvice).Error
  213. // return doctoradvice,err
  214. }
  215. func SeacherDoctorAdviceByAdviceName(patientid int64, orgid int64, serchval string) (doctoradvice []*models.DoctorAdvice, err error) {
  216. err = service.XTReadDB().Where("patient_id = ? AND user_org_id = ? AND advice_name = ?", patientid, orgid, serchval).Find(&doctoradvice).Error
  217. return doctoradvice, err
  218. }
  219. func DeleteDoctorAdvice(id int64) error {
  220. err := service.XTWriteDB().Model(models.DoctorAdvice{}).Where("id= ?", id).Update(map[string]interface{}{"status": 0, "mtime": time.Now().Unix()}).Error
  221. return err
  222. }