package login

import (
	"Kya_New/controllers"
	"Kya_New/enums"
	"Kya_New/models"
	"Kya_New/service/login_service"
	"Kya_New/service/patient_service"
	"Kya_New/sms_service"
	"Kya_New/utils"
	"encoding/json"
	"fmt"
	"github.com/astaxie/beego"
	"github.com/jinzhu/gorm"
	"strconv"
	"strings"
	"time"
)

func LoginRouter() {
	beego.Router("/api/qiniu/uptoken", &LoginManagement{}, "Get:GetQNUpToken")
	beego.Router("/api/site/gettologin", &LoginManagement{}, "Post:GetToLogin")
	beego.Router("/api/password/code", &LoginManagement{}, "Post:CodeOfModifyPwd")
	beego.Router("/api/save/register", &LoginManagement{}, "Post:SaveRegisterData")
	beego.Router("/api/login/getallprovince", &LoginManagement{}, "Get:GetAllProvince")
	beego.Router("/api/login/nopasslogin", &LoginManagement{}, "Get:NoPassLogin")
	beego.Router("/api/login/getcode", &LoginManagement{}, "Post:GetCode")
	beego.Router("/api/login/nextstep", &LoginManagement{}, "Get:NextStep")
	beego.Router("/api/login/accomplish", &LoginManagement{}, "Post:Accomplish")
	beego.Router("/api/login/getallorgname", &LoginManagement{}, "Get:GetAllOrgName")
	beego.Router("/api/login/getcitybyid", &LoginManagement{}, "Get:GetCityById")
	beego.Router("/api/login/getallorgtype", &LoginManagement{}, "Get:GetAllOrgType")
	beego.Router("/api/login/saveorginformation", &LoginManagement{}, "Post:SaveOrginInformation")
	beego.Router("/api/patient/getneratedialysisno", &LoginManagement{}, "Get:GetneratedDialysisNo")
	beego.Router("/api/login/getblooddialysispatient", &LoginManagement{}, "Get:GetBloodDialysisPatient")
	beego.Router("/api/site/getdoctoradvice", &LoginManagement{}, "Get:GetDoctorAdvice")
	beego.Router("/api/site/savesearch", &LoginManagement{}, "Get:SaveSearch")
	beego.Router("/api/site/toseacherdoctoradvice", &LoginManagement{}, "Get:ToSeacherDoctorAdvice")
	beego.Router("/api/site/deleteDoctorAdvice", &LoginManagement{}, "Get:DeleteDoctorAdvice")
}

type LoginManagement struct {
	controllers.BaseAPIController
}

func (this *LoginManagement) GetQNUpToken() {
	redisClient := login_service.RedisClient()
	fmt.Println("redisClient", redisClient)
	defer redisClient.Close()
	token, err := redisClient.Get("qn_token").Result()
	fmt.Println("token是什么", token)
	fmt.Println("错误", err)
	fmt.Println("token", token)
	if err != nil {
		defer fmt.Println(err)
		this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeGetQiniuUpToken)
		return
	}
	this.ServeSuccessJSON(map[string]interface{}{
		"uptoken": token,
	})
	return
}

func (this *LoginManagement) ServeFailJsonSend(code int, msg string) {
	fmt.Println("code", code)
	this.Data["json"] = enums.MakeFailResponseJSON(msg, code)
	this.ServeJSON()
}

func (this *LoginManagement) ServeSuccessJSON(data map[string]interface{}) {
	this.Data["json"] = enums.MakeSuccessResponseJSON(data)
	this.ServeJSON()
}

func (this *LoginManagement) GetToLogin() {
	tel := this.GetString("tel")
	fmt.Println("账号啊", tel)
	psd := this.GetString("psd")
	fmt.Println("密码哈", psd)
	admin, err := login_service.QueryLogin(tel, psd)
	fmt.Println("admin", admin)
	fmt.Println("err", err)
	if err != nil {
		fmt.Println("代码进来了没哟u")
		this.ServeFailJsonSend(enums.ErrorCodeDataException, "账号密码错误")
		return
	} else {
		fmt.Println("admin", admin.ID)
		org, error := login_service.GetQueryUserOrgId(admin.ID)
		fmt.Println("error", error)
		if error == gorm.ErrRecordNotFound {
			this.ServeSuccessJSON(map[string]interface{}{
				"org":  org,
				"info": admin,
			})
		} else if error == nil {
			fmt.Println("heeeee")
			this.ServeSuccessJSON(map[string]interface{}{
				"admin": admin,
			})
		}
	}

	//fmt.Println("==============================================",admin.ID)
	//org, errcode := login_service.GetQueryUserOrgId(admin.ID)
	//fmt.Println("org是什么",org)
	//fmt.Println("errcode",errcode)
	//fmt.Println("org",org)

	//if err == gorm.ErrRecordNotFound{
	//	this.ServeSuccessJSON(map[string]interface{}{
	//		"Userorg":admin,
	//	})
	//}else if err == nil {
	//	if(admin.Mobile != tel && admin.Mobile != psd){
	//		this.ServeFailJsonSend(enums.ErrorCodeDataException, "登录失败")
	//		return
	//	}
	//	this.ServeSuccessJSON(map[string]interface{}{
	//		"admin":admin,
	//	})
	//}

}

func (this *LoginManagement) CodeOfModifyPwd() {

	redisClient := login_service.RedisClient()
	defer redisClient.Close()
	mobile := this.GetString("phone")
	fmt.Println("错误错误错误错误错误错误错误错误错误错误错误错误错误错误错误错误错误错误错误错误错误错误", mobile)
	//var  mobile = "13318464642"
	admin, errcode := login_service.GetQueryMobileData(mobile)
	fmt.Println("admin是设么", admin)
	fmt.Println("errcode是设么", errcode)
	if errcode == gorm.ErrRecordNotFound {
		cur_date := time.Now().Format("2006-01-02")
		moblie_count, _ := redisClient.Get("scrm_verification_code_" + mobile + "_" + cur_date).Result()
		fmt.Println("moblie_count", moblie_count)
		moblie_count_int, _ := strconv.Atoi(moblie_count)
		if moblie_max := 5; moblie_count_int >= moblie_max {
			this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeVerificationCodeLimit)
			return
		}

		if code, err := sms_service.SMSSendVerificationCode(mobile); err != nil {
			//this.ErrorLog("修改密码发送验证码失败:%v", err)
			this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
			return

		} else {
			cur_date := time.Now().Format("2006-01-02")
			set := redisClient.Set("scrm_verification_code_"+mobile, code, time.Minute*10)
			fmt.Println("set", set)
			Incr, _ := redisClient.Incr("scrm_verification_code_" + mobile + "_" + cur_date).Result()
			fmt.Println("Incr", Incr)

			this.ServeSuccessJSON(map[string]interface{}{
				"msg": "短信发送成功,有效期为10分钟",
			})
		}
		returnData := make(map[string]interface{}, 0)
		returnData["admin"] = admin
		this.ServeSuccessJSON(returnData)
	} else if errcode == nil {
		returnData := make(map[string]interface{}, 0)
		returnData["admin"] = admin
		this.ServeSuccessJSON(returnData)
	}
}

func (this *LoginManagement) SaveRegisterData() {
	phone := this.GetString("phone")
	fmt.Println("电话是多少", phone)
	password := this.GetString("password")
	fmt.Println("密码是多少", password)
	code := this.GetString("code")
	fmt.Println("code", code)
	redisClient := login_service.RedisClient()
	fmt.Println("redisClient", redisClient)
	defer redisClient.Close()
	cachedCode, err := redisClient.Get("scrm_verification_code_" + phone).Result()
	fmt.Println("错误是设么", err)
	fmt.Println("cachedCode", cachedCode)

	//admin := models.SgjUserAdmin{
	//	Mobile:       phone,
	//	Password:     password,
	//	Status:       1,
	//	IsSuperAdmin: 1,
	//	Ctime:        time.Now().Unix(),
	//}
	//err := login_service.AddAdmin(&admin)
	//fmt.Println("错误",err)
	//returnData := make(map[string]interface{}, 0)
	//returnData["admin"] = admin
	//this.ServeSuccessJSON(returnData)
	//if err != nil {
	//	this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAccountOrVerCodeWrong)
	//	return
	//}
	if code != cachedCode {
		this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAccountOrVerCodeWrong)
		return
	} else {
		admin := models.SgjUserAdmin{
			Mobile:       phone,
			Password:     password,
			Status:       1,
			IsSuperAdmin: 1,
			Ctime:        time.Now().Unix(),
		}
		err = login_service.AddAdmin(&admin)
		fmt.Println("错误", err)
		returnData := make(map[string]interface{}, 0)
		returnData["admin"] = admin
		this.ServeSuccessJSON(returnData)
	}

}

func (this *LoginManagement) GetAllProvince() {
	provice, err := login_service.GetAllProvince(0)
	fmt.Println("错误", err)
	//returnData := make(map[string]interface{}, 0)
	//returnData["provice"] = provice
	//this.ServeSuccessJSON(returnData)

	this.ServeSuccessJSON(map[string]interface{}{
		"provice": provice,
	})
}

func (this *LoginManagement) NoPassLogin() {
	phone := this.GetString("phone")
	fmt.Println("phone是什么", phone)
	code := this.GetString("code")
	fmt.Println("code是什么", code)
	admin, err := login_service.GetQueryPhoneData(phone)
	fmt.Println("admin", admin)
	if err != nil {
		this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAccountOrVerCodeWrong)
		return
	}
	redisClient := login_service.RedisClient()
	defer redisClient.Close()
	cachedCode, err := redisClient.Get("scrm_verification_code_" + phone).Result()
	fmt.Println("cachedCode", cachedCode)
	if err != nil {
		this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAccountOrVerCodeWrong)
		return
	}
	if code == cachedCode {
		returnData := make(map[string]interface{}, 0)
		returnData["msg"] = "ok"
		this.ServeSuccessJSON(returnData)
	}

	if code != cachedCode {
		this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAccountOrVerCodeWrong)
		return
	}
}

func (this *LoginManagement) GetCode() {
	phone := this.GetString("phone")
	fmt.Println("phone", phone)
	redisClient := login_service.RedisClient()
	defer redisClient.Close()
	cur_date := time.Now().Format("2006-01-02")
	moblie_count, _ := redisClient.Get("scrm_verification_code_" + phone + "_" + cur_date).Result()
	moblie_count_int, _ := strconv.Atoi(moblie_count)
	if moblie_max := 5; moblie_count_int >= moblie_max {
		this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeVerificationCodeLimit)
		return
	}
	if code, err := sms_service.SMSSendVerificationCode(phone); err != nil {
		//this.ErrorLog("修改密码发送验证码失败:%v", err)
		this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
		return

	} else {
		cur_date := time.Now().Format("2006-01-02")
		redisClient.Set("scrm_verification_code_"+phone, code, time.Minute*10)
		redisClient.Incr("scrm_verification_code_" + phone + "_" + cur_date).Result()

		this.ServeSuccessJSON(map[string]interface{}{
			"msg": "短信发送成功,有效期为10分钟",
		})
	}
}

func (this *LoginManagement) NextStep() {
	phone := this.GetString("phone")
	fmt.Println("电话", phone)
	code := this.GetString("code")
	fmt.Println("code", code)
	redisClient := login_service.RedisClient()
	defer redisClient.Close()
	cachedCode, err := redisClient.Get("scrm_verification_code_" + phone).Result()
	fmt.Println("cachedCode", cachedCode)
	if err != nil {
		this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAccountOrVerCodeWrong)
		return
	}
	if code == cachedCode {
		returnData := make(map[string]interface{}, 0)
		returnData["msg"] = "ok"
		this.ServeSuccessJSON(returnData)
	}

	if code != cachedCode {
		fmt.Println("hehehhhhhhhhhheheh")
		this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAccountOrVerCodeWrong)
		return
	}
}

func (this *LoginManagement) Accomplish() {
	phone := this.GetString("phone")
	fmt.Println("phone", phone)
	newpassword := this.GetString("newpassword")
	fmt.Println("newpassword", newpassword)
	confirmpassword := this.GetString("confirmpassword")
	fmt.Println("confirmpassword", confirmpassword)
	if newpassword != confirmpassword {
		this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAccountOrVerCodeWrong)
		return
	}
	if newpassword == confirmpassword {
		admin := models.SgjUserAdmin{
			Password: newpassword,
		}
		err := login_service.UpdatedPassword(phone, &admin)
		fmt.Println("错误", err)
		returnData := make(map[string]interface{}, 0)
		returnData["admin"] = admin
		this.ServeSuccessJSON(returnData)
	}
}

func (this *LoginManagement) GetAllOrgName() {
	id, _ := this.GetInt64("id")
	org, err := login_service.GetAllOrgName(id)
	fmt.Println("错误", err)
	returnData := make(map[string]interface{}, 0)
	returnData["org"] = org
	this.ServeSuccessJSON(returnData)
}
func (this *LoginManagement) GetCityById() {
	id, _ := this.GetInt64("id")
	//fmt.Println("id是什么",id)
	ids, err := login_service.GetCityById(id)
	fmt.Println("err是设么", err)
	returnData := make(map[string]interface{}, 0)
	returnData["ids"] = ids
	this.ServeSuccessJSON(returnData)
}

func (this *LoginManagement) GetAllOrgType() {
	orgtypes, err := login_service.GetAllOrgType()
	fmt.Println("err是什么", err)
	fmt.Println("orgtypes", orgtypes)
	returnData := make(map[string]interface{}, 0)
	returnData["orgtypes"] = orgtypes
	this.ServeSuccessJSON(returnData)
}

func (this *LoginManagement) SaveOrginInformation() {
	id, _ := this.GetInt64("id")
	fmt.Println("id", id)
	dataBody := make(map[string]interface{}, 0)
	err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
	fmt.Println("视频发布是什么呢", err)
	//orgname := this.GetString("org_name")
	orgname := dataBody["org_name"].(string)
	fmt.Println("orgname", orgname)
	address := dataBody["address"].(string)
	fmt.Println("address", address)
	contactname := dataBody["contact_name"].(string)
	fmt.Println("contactname", contactname)
	telephone := dataBody["telephone"].(string)
	fmt.Println("telephone", telephone)
	provincesName := dataBody["provinces_name"].(string)
	fmt.Println("provincesName", provincesName)
	district, err := login_service.GetProvinceByName(provincesName)
	fmt.Println("district", district)
	cityname := dataBody["city_name"].(string)
	fmt.Println("cityname", cityname)
	cityDistrict, err := login_service.GetCityByName(cityname, district.ID)
	fmt.Println("err", err)
	fmt.Println("cityDistrict", cityDistrict)
	countname := dataBody["count_name"].(string)
	fmt.Println("countname", countname)
	orgtype := dataBody["org_type"].(string)
	fmt.Println("orgtype", orgtype)
	Orgtype, err := login_service.GetOrgTypeByName(orgtype)
	userDistrict, err := login_service.GetCountByName(countname, cityDistrict.ID)
	fmt.Println("错误", err)
	fmt.Println("userDistrict", userDistrict)
	org := models.SgjUserOrg{
		OrgName:     orgname,
		Address:     address,
		ContactName: contactname,
		Telephone:   telephone,
		Ctime:       time.Now().Unix(),
		Status:      1,
		Province:    district.ID,
		City:        cityDistrict.ID,
		District:    userDistrict.ID,
		OrgType:     Orgtype.ID,
		Creator:     id,
	}

	fmt.Println("org", org)
	err = login_service.AddUserOrgInfo(&org)
	userOrg, err := login_service.GeLastUserOrgLastData(id)
	fmt.Println("uerOrg", userOrg)
	fmt.Println("heeeeeeeeeeeeeeee", userOrg.ID)
	fmt.Println("err", err)
	nextMonthDate := time.Now().AddDate(0, 0, 30)
	subscibe := models.ServeSubscibe{
		OrgId:       userOrg.ID,
		PeriodStart: time.Now().Unix(),
		PeriodEnd:   nextMonthDate.Unix(),
		Status:      1,
		State:       9,
		CreatedTime: time.Now().Unix(),
		UpdatedTime: time.Now().Unix(),
	}
	err = login_service.CreateSubscibe(&subscibe)

	fmt.Println("err", err)
	role := models.UserRole{
		RoleName:     "超级管理员",
		Creator:      id,
		OrgId:        userOrg.ID,
		IsSuperAdmin: 1,
		Status:       1,
		Ctime:        time.Now().Unix(),
		Mtime:        time.Now().Unix(),
	}

	err = login_service.AddRole(&role)
	userRole, err := login_service.GetRoleLastDate(userOrg.ID)
	fmt.Println("添加权限", err)
	orgApp := models.UserOrgApp{
		AppType:    1,
		Creator:    id,
		OrgId:      userOrg.ID,
		OpenStatus: 0,
		Status:     1,
		Ctime:      time.Now().Unix(),
		Mtime:      time.Now().Unix(),
	}
	errcode := login_service.AddUserOrgApp(&orgApp)
	fmt.Println("addUserOrgApp", errcode)

	orgApp, _ = login_service.GetLastData(userOrg.ID)
	fmt.Println("oooooooooooooooooooooooooooooooooooooooooo")
	fmt.Println("orgApp是什么东西", orgApp)
	fmt.Println("orgapp", orgApp.ID)
	adminRole := models.UserAdminRole{
		AdminUserId: id,
		OrgId:       userOrg.ID,
		AppId:       orgApp.ID,
		RoleId:      userRole.ID,
		UserType:    1,
		UserTitle:   1,
		Status:      1,
		UserName:    telephone,
		Ctime:       time.Now().Unix(),
	}
	err = login_service.AddAdimnRole(&adminRole)

	app := models.UserOrgApp{
		AppType:    3,
		Creator:    id,
		OrgId:      userOrg.ID,
		OpenStatus: 1,
		Status:     1,
		Ctime:      time.Now().Unix(),
		Mtime:      time.Now().Unix(),
	}
	err = login_service.AddUserOrgApp(&app)

	getLastDatas, _ := login_service.GetLastData(userOrg.ID)
	adminRolethee := models.UserAdminRole{
		AdminUserId: id,
		OrgId:       userOrg.ID,
		AppId:       getLastDatas.ID,
		RoleId:      userRole.ID,
		UserType:    1,
		UserTitle:   1,
		Status:      1,
		UserName:    telephone,
		Ctime:       time.Now().Unix(),
	}
	err = login_service.AddAdimnRole(&adminRolethee)

	userOrgApp := models.UserOrgApp{
		AppType:    4,
		Creator:    id,
		OrgId:      userOrg.ID,
		OpenStatus: 0,
		Status:     1,
		Ctime:      time.Now().Unix(),
		Mtime:      time.Now().Unix(),
	}
	err = login_service.AddUserOrgApp(&userOrgApp)
	data, _ := login_service.GetLastData(userOrg.ID)
	adminRoleone := models.UserAdminRole{
		AdminUserId: id,
		OrgId:       userOrg.ID,
		AppId:       data.ID,
		RoleId:      userRole.ID,
		UserType:    1,
		UserTitle:   1,
		Status:      1,
		UserName:    telephone,
		Ctime:       time.Now().Unix(),
	}
	err = login_service.AddAdimnRole(&adminRoleone)

	iuser := models.UserOrgApp{
		AppType:    5,
		Creator:    id,
		OrgId:      userOrg.ID,
		OpenStatus: 0,
		Status:     1,
		Ctime:      time.Now().Unix(),
		Mtime:      time.Now().Unix(),
	}
	err = login_service.AddUserOrgApp(&iuser)
	fmt.Println("错误", err)
	lastData, _ := login_service.GetLastData(userOrg.ID)
	adminRoletwo := models.UserAdminRole{
		AdminUserId: id,
		OrgId:       userOrg.ID,
		AppId:       lastData.ID,
		RoleId:      userRole.ID,
		UserType:    1,
		UserTitle:   1,
		Status:      1,
		UserName:    telephone,
		Ctime:       time.Now().Unix(),
	}
	err = login_service.AddAdimnRole(&adminRoletwo)
	returnData := make(map[string]interface{}, 0)
	returnData["org"] = org
	this.ServeSuccessJSON(returnData)
}

func (this *LoginManagement) GetneratedDialysisNo() {
	phone := this.GetString("phone")
	fmt.Println("phone是什么", phone)
	admin, err := patient_service.GetCreatorId(phone)
	fmt.Println("获取注册id错误", err)
	org, err := patient_service.GetOrgId(admin.ID)
	fmt.Println("获取机构id错误", err)
	fmt.Println("机构id", org.ID)
	dialysisNo := patient_service.GetneratedDialysisNo(org.ID)
	fmt.Println("dialysisNo是什么", dialysisNo)
	if dialysisNo == 0 {
		dialysisNo = 1
	} else {
		dialysisNo++
	}
	no := strconv.FormatInt(dialysisNo, 10)
	fmt.Println("no", no)
	rep := 3 - len(no)
	if rep > 0 {
		no = strings.Repeat("0", rep) + no
	}
	this.ServeSuccessJSON(map[string]interface{}{
		"no": no,
	})
	returnData := make(map[string]interface{}, 0)
	returnData["no"] = no
	this.ServeSuccessJSON(returnData)
}

func (this *LoginManagement) GetBloodDialysisPatient() {
	page, _ := this.GetInt64("page")
	fmt.Println("page", page)
	limit, _ := this.GetInt64("limit")
	fmt.Println("limit", limit)
	id, _ := this.GetInt64("id")
	org, _ := patient_service.GetOrgId(id)
	fmt.Println("org是什么", org.ID)
	patients, total, err := login_service.GetBloodDialysisPatient(org.ID, page, limit)
	fmt.Println("patients", patients)
	fmt.Println("err", err)
	returnData := make(map[string]interface{}, 0)
	returnData["patients"] = patients
	returnData["total"] = total
	this.ServeSuccessJSON(returnData)
	if err != nil {
		this.ServeFailJsonSend(enums.ErrorCodeDataException, "添加医院失败")
		return
	}
	this.ServeSuccessJSON(map[string]interface{}{
		"patients": patients,
		"total":    total,
	})

}

func (this *LoginManagement) GetDoctorAdvice() {
	patientid, _ := this.GetInt64("patientid")
	fmt.Println("patientid", patientid)
	starttime := this.GetString("starttime")
	fmt.Println("starttime", starttime)
	timeLayout := "2006-01-02 15:04:05"
	theTime, _ := utils.ParseTimeStringToTime(timeLayout, starttime+" 00:00:00")
	fmt.Println("err")
	star := theTime.Unix()
	fmt.Println("star", star)
	orgid, _ := this.GetInt64("orgid")
	fmt.Println("orgid是什么", orgid)
	endtime := this.GetString("endtime")
	fmt.Println("endtime", endtime)
	toTime, _ := utils.ParseTimeStringToTime(timeLayout, endtime+" 00:00:00")
	end := toTime.Unix()
	fmt.Println("end", end)
	searchval := this.GetString("searchval")
	fmt.Println("searchval", searchval)
	patients, err := login_service.GetPatintsInfo(patientid, orgid)
	diseases, err := login_service.GetPatientInfectious(patientid)
	fmt.Println("徐欧文", err)
	//根据机构id获取创建者id
	org, _ := login_service.GetCreatorId(orgid)
	fmt.Println("创建者", org)
	//根据创建者id获取apptype id
	app, _ := login_service.GetOrgAppId(org.Creator, orgid)
	fmt.Println("appid", app.ID)
	//获取开嘱医生
	role, _ := login_service.GetAdvceDoctor(org.Creator, orgid, app.ID)
	doctoradvice, total, err := login_service.GetDoctorAdvice(patientid, orgid, star, end, searchval)
	fmt.Println("err", err)
	fmt.Println("doctorradvice", doctoradvice)
	if err != nil {
		this.ServeFailJsonSend(enums.ErrorCodeDataException, "添加医院失败")
		return
	}
	this.ServeSuccessJSON(map[string]interface{}{
		"doctoradvice": doctoradvice,
		"patients":     patients,
		"diseases":     diseases,
		"role":         role,
		"total":        total,
	})
}

func (this *LoginManagement) SaveSearch() {
	searchval := this.GetString("searchval")
	fmt.Println("searchval", searchval)
}

func (this *LoginManagement) ToSeacherDoctorAdvice() {
	patientid, _ := this.GetInt64("patientid")
	fmt.Println("patientid", patientid)
	orgid, _ := this.GetInt64("orgid")
	fmt.Println("orgid", orgid)
	searchval := this.GetString("searchval")
	fmt.Println("searchval", searchval)
	doctoradvice, err := login_service.SeacherDoctorAdviceByAdviceName(patientid, orgid, searchval)
	if err != nil {
		this.ServeFailJsonSend(enums.ErrorCodeDataException, "添加医院失败")
		return
	}
	this.ServeSuccessJSON(map[string]interface{}{
		"doctoradvice": doctoradvice,
	})
}

func (this *LoginManagement) DeleteDoctorAdvice() {
	id, _ := this.GetInt64("id")
	fmt.Println("id是什么", id)
	err := login_service.DeleteDoctorAdvice(id)
	fmt.Println("err", err)
	returnData := make(map[string]interface{}, 0)
	returnData["msg"] = "ok"
	this.ServeSuccessJSON(returnData)
	return
}