You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

93 lines
2.4 KiB

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

package AuthDAO
import (
"dsDataex/GenXorm/models"
"dsDataex/Utils/CacheUtil"
"dsDataex/Utils/DbUtil"
"dsDataex/Utils/ErrorConst"
"dsDataex/Utils/LogUtil"
"html"
)
//数据库
var db = DbUtil.Engine
/**
* @Author zhangjun
* @Description
* @Date 2020-06-12 09:43
* @Param id string 接入系统ID
* @return bool 成功/失败
* @return string 结果说明
* @return map 数据
* @return error 异常
**/
func GetbyID(id string) (bool, string, map[string]interface{}, error){
ids:=[]string{id}
result := CacheUtil.GetListByIds( ids ,CacheUtil.GetBean("t_app_base"))
if len(result)==1 {
return true, "数据获取成功", result[0],nil
}else {
return false, "接入系统数据获取失败systemID不存在", nil,nil
}
}
/**
* @Author zhangjun
* @Description
* @Date 2020-06-12 09:40
* @Param code string 接入系统code
* @return bool 成功/失败
* @return string 结果说明
* @return map 数据
* @return error 异常
**/
func GetbyCode(code string) (bool, string, map[string]interface{}, error){
sql := "SELECT app_id from t_app_base where b_use = 1 and app_code = '" + html.EscapeString(code) + "'"
//通过SQL获取带缓存的数据
list, count, _ := CacheUtil.Page(sql, 10,0)
if count==1 {
return true, "数据获取成功", list[0],nil
}else {
return false, "接入系统数据获取失败systemID不存在", nil,nil
}
}
/**
* @Author zhangjun
* @Description 更新接入系统信息Token
* @Date 2020-06-12 09:40
* @Param id string 接入系统ID
* @Param authToken string 接入系统票据
* @Param authTime time 票据生成时间
* @return bool 成功/失败
* @return string 结果说明
* @return error 异常
**/
func Update(appId string, authToken string) (bool, string, error){
business := new(models.TAppBase)
//清除Redis缓存
var ids = []string{appId}
var selector = CacheUtil.GetBean("t_app_base")
CacheUtil.DeleteCacheByIds(ids, selector)
business.AppId = html.EscapeString(appId)
business.AppToken = html.EscapeString(authToken)
//通过添加Cols函数指定需要更新结构体中的哪些值未指定的将不更新指定了的即使为0也会更新。
_, err := db.Where(" app_id = ?", appId ).Cols("app_token").Update(business)
if err != nil {
LogUtil.Error(ErrorConst.SqlUpdateError, "接入系统authToken Update数据库操作发生严重错误"+err.Error())
return false, "数据库操作失败", err
}
return true, "修改成功!", nil
}