package site_service import ( "SCRM/models" "SCRM/service" "fmt" "time" ) func AddPatientModel(model *models.SgjPatientModel)error{ err := service.PatientWriteDB().Create(&model).Error fmt.Println("插入错误",err) return err } func QueryModel(orgID int64)( models.SgjPatientModel,error) { model := models.SgjPatientModel{} err := service.PatientReadDB().Where("user_org_id = ? AND status = ?", orgID, 1).Last(&model).Error return model,err } func AddRotation(rotation models.SgjPatientRotation) error { err := service.PatientWriteDB().Create(&rotation).Error fmt.Println("插入数据",err) return err } func AddRotationUpload(connecmodel *models.SgjPatientConnecmodel) error { err := service.PatientWriteDB().Create(&connecmodel).Error fmt.Println("错误是什么,err",err) return err } func AddHispital(newmodel models.SgjPatientHospital) error { err := service.PatientWriteDB().Create(&newmodel).Error return err } func AddOffices(offices models.SgjPatientOffices) error { err := service.PatientWriteDB().Create(&offices).Error return err } func AddDoctor(doctor models.SgjPatientDoctor) error { err := service.PatientWriteDB().Create(&doctor).Error return err } func AddDoctorInfo(doctor models.SgjPatientDoctor) error{ err := service.PatientWriteDB().Create(&doctor).Error return err } func AddOffEnvironment(officenviroment models.SgjPatientOffenvironment) error { err := service.PatientWriteDB().Create(&officenviroment).Error return err } func GetRationImages(orgID int64)(rot []*models.SgjPatientRotation, err error){ err = service.PatientReadDB().Where("user_org_id = ? AND status = ?", orgID, 1).Order("sort").Find(&rot).Error fmt.Println("错误是什么",err) return } func GetHospitalInfo(orgID int64)(models.SgjPatientHospital,error) { hospital := models.SgjPatientHospital{} err := service.PatientReadDB().Where("user_org_id = ? AND status = ?", orgID, 1).Last(&hospital).Error fmt.Println("错误是什么",err) return hospital,err } func GetOfficeInfo(orgID int64)(models.SgjPatientOffices,error) { offices := models.SgjPatientOffices{} err := service.PatientReadDB().Where("user_org_id = ? AND status = ?", orgID, 1).Last(&offices).Error fmt.Println("错误是什么",err) return offices,err } func GetDoctorInfo(orgID int64)(doc []*models.SgjPatientDoctor,err error) { err = service.PatientReadDB().Where("user_org_id = ? AND status = ?", orgID, 1).Limit(2).Find(&doc).Error fmt.Println("错误是什么",err) return } func GetQueryDocInfo(orgID int64)(doc []*models.SgjUserStaffInfo,err error) { err = service.UserReadDB().Where("user_org_id = ? AND status = ?", orgID, 1).Find(&doc).Error fmt.Println("错误是什么",err) return } func GetQueryDocHead(orgID int64) (doc []*models.SgjPatientDoctor,err error) { err = service.PatientReadDB().Where("user_org_id = ? AND status = ?", orgID, 1).Order("doc_sort").Find(&doc).Error return } func GetOffEnvironment(orgID int64)(models.SgjPatientOffenvironment,error) { offenvironment := models.SgjPatientOffenvironment{} err := service.PatientReadDB().Where("user_org_id = ? AND status = ?", orgID, 1).Last(&offenvironment).Error fmt.Println("错误是什么",err) return offenvironment,err } func AddWorkTime(connecmodel models.SgjPatientConnecmodel) error { err := service.PatientWriteDB().Create(&connecmodel).Error return err } func AddRideWay(connecmodel models.SgjPatientConnecmodel) error { err := service.PatientWriteDB().Create(&connecmodel).Error return err } func AddConnetion(connection models.SgjPatientConnection) error { err := service.PatientWriteDB().Create(&connection).Error return err } func GetQueryConnection( orgID int64)(conection []*models.SgjPatientConnection,err error) { err = service.PatientReadDB().Where("user_org_id = ? AND status = ?", orgID, 1).Find(&conection).Error return } func DeleteConnecWay(orgid int64,id int64)(error){ err := service.PatientWriteDB().Model(&models.SgjPatientConnection{}).Where("user_org_id =? AND id = ?", orgid, id).Update(map[string]interface{}{"status": 0, "mtime": time.Now().Unix()}).Error return err } func EditConnecWay(orgid int64,id int64)(models.SgjPatientConnection,error){ sgj := models.SgjPatientConnection{} err := service.PatientReadDB().Model(&sgj).Where("user_org_id = ? AND id =?", orgid, id).Find(&sgj).Error return sgj,err; } func UpadateConnec(connection *models.SgjPatientConnection,orgID int64,id int64) { service.PatientWriteDB().Model(connection).Where("user_org_id = ? AND id = ? AND status = ?",orgID,id,1).Update(map[string]interface{}{"title":connection.Title,"connecway":connection.Connecway,"content":connection.Content,}) } func GetUserModel(orgid int64)(model []*models.SgjPatientConnecmodel,err error){ err = service.PatientReadDB().Where("user_org_id = ? AND status = ?", orgid, 1).Order("sort").Find(&model).Error return } func GetQueryNewModel(orgid int64)(model []*models.SgjPatientModel,err error) { err = service.PatientReadDB().Where("user_org_id = ? AND status = ?", orgid, 1).Order("sort").Find(&model).Error fmt.Println("错误是什么",err) return } func GetEditModel(orgid int64,id int64)(models.SgjPatientConnecmodel,error){ connecmodel := models.SgjPatientConnecmodel{} err := service.PatientReadDB().Model(&connecmodel).Where("user_org_id = ? AND id = ?", orgid, id).Find(&connecmodel).Error return connecmodel,err; } func UpdateWorkTime(id int64,orgID int64,connecmodel models.SgjPatientConnecmodel) { service.PatientWriteDB().Model(connecmodel).Where("id = ? AND user_org_id = ? AND status = ?",id,orgID,1).Update(map[string]interface{}{"title":connecmodel.Title,"sort":connecmodel.Sort,"worktime":connecmodel.Worktime,"mtime":time.Now().Unix()}) } func UpdateRideWay(id int64,orgID int64,connecmodel models.SgjPatientConnecmodel) error { err := service.PatientWriteDB().Model(connecmodel).Where("id = ? AND user_org_id = ? AND status =?", id, orgID, 1).Update(map[string]interface{}{"title": connecmodel.Title, "sort": connecmodel.Sort, "rideway": connecmodel.Rideway, "mtime": time.Now().Unix()}).Error return err } func QueryDocById(orgID int64,id int64)(models.SgjUserStaffInfo,error) { info := models.SgjUserStaffInfo{} err := service.UserWriteDB().Model(&info).Where("user_org_id = ? AND id = ?",orgID ,id ).Find(&info).Error return info,err } func EditDoctorInfo(id int64,orgID int64)(models.SgjPatientDoctor,error) { doctor := models.SgjPatientDoctor{} err := service.PatientReadDB().Model(&doctor).Where("id = ? AND user_org_id = ?", id, orgID).Find(&doctor).Error return doctor,err } func UpdateDocInfo(id int64,orgID int64,doctor models.SgjPatientDoctor) error { err := service.PatientWriteDB().Model(doctor).Where("id = ? AND user_org_id = ? AND status = ?", id, orgID, 1).Update(map[string]interface{}{"docname": doctor.Docname, "doc_position": doctor.DocPosition, "dochead": doctor.Dochead, "doc_sort": doctor.DocSort, "docintroduction": doctor.Docintroduction, "mtime": time.Now().Unix()}).Error return err } func DeleteDoctor(id int64,orgID int64)(error) { err := service.PatientWriteDB().Model(&models.SgjPatientDoctor{}).Where("id = ? AND user_org_id = ?", id, orgID).Update(map[string]interface{}{"status": 0, "mtime": time.Now().Unix()}).Error return err } func EditHospital(mid int64,orgID int64)(models.SgjPatientHospital,error) { hospital := models.SgjPatientHospital{} err := service.PatientReadDB().Model(&hospital).Where("modleid = ? AND user_org_id = ? AND status = ?", mid, orgID, 1).Find(&hospital).Error return hospital,err } func UpdateHospital(id int64,OrgId int64,hospital models.SgjPatientHospital) error { err := service.PatientWriteDB().Model(hospital).Where("id = ? AND user_org_id = ? AND status = ?", id, OrgId, 1).Update(map[string]interface{}{"title": hospital.Title, "sort": hospital.Sort, "introduction": hospital.Introduction, "mtime": time.Now().Unix()}).Error return err } func UpdateModel(modelid int64,orgId int64 ,model models.SgjPatientModel) error { err := service.PatientWriteDB().Model(model).Where("id = ? AND user_org_id = ? AND status = ?", modelid, orgId, 1).Update(map[string]interface{}{"title": model.Title, "sort": model.Sort, "mtime": time.Now().Unix()}).Error return err } func EditOffice(mid int64,orgID int64)(models.SgjPatientOffices,error) { offices := models.SgjPatientOffices{} err := service.PatientReadDB().Model(&offices).Where("modleid = ? AND user_org_id = ? AND status = ?", mid, orgID, 1).Find(&offices).Error return offices,err } func DeletemodleById(id int64,orgID int64)(error) { err:= service.PatientWriteDB().Model(models.SgjPatientModel{}).Where("id = ? AND user_org_id = ?", id, orgID).Update(map[string]interface{}{"status": 0, "mtime": time.Now().Unix()}).Error return err } func DeleteHospitalByModelid(mid int64,orgID int64)(error) { err := service.PatientWriteDB().Model(models.SgjPatientHospital{}).Where("modleid = ? AND user_org_id = ?", mid, orgID).Update(map[string]interface{}{"status": 0, "mtime": time.Now().Unix()}).Error return err } func DeleteOfficeByModelid(mid int64,orgID int64)(error) { err := service.PatientWriteDB().Model(models.SgjPatientOffices{}).Where("modleid = ? AND user_org_id = ?", mid, orgID).Update(map[string]interface{}{"status": 0, "mtime": time.Now().Unix()}).Error return err } func UpdateOffices(id int64,orgID int64,offices models.SgjPatientOffices) error { err := service.PatientWriteDB().Model(offices).Where("id = ? AND user_org_id = ? AND status = ?", id, orgID, 1).Update(map[string]interface{}{"title": offices.Title, "sort": offices.Sort, "introduction": offices.Introduction, "mtime": time.Now().Unix()}).Error return err } func GetHospital(Orgid int64)(hostital []*models.SgjPatientHospital,err error) { err = service.PatientReadDB().Where("user_org_id = ? AND status = ?", Orgid, 1).Order("sort").Find(&hostital).Error return } func GetData(orgid int64)(model []*models.SgjPatientModel,err error) { db := service.PatientReadDB().Table("sgj_patient_model as m").Where(" m.status = ?", 1) if(orgid > 0){ db = db.Where("user_org_id = ? ", orgid) } err = db.Preload("Hospitals").Preload("Offices").Select("m.id,m.title,m.sort,m.ctime,m.mtime,m.user_org_id,m.status,m.mode_type").Order("sort").Find(&model).Error return }