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 }