Commit 057b0bfd by zhengnw@sobot.com

common 1.4.0 登录信息使用单例

parent c07bc985
......@@ -9,8 +9,6 @@ import android.net.Uri;
import android.widget.ImageView;
import com.sobot.common.utils.SobotImageUtils;
import com.sobot.network.apiUtils.SobotHttpUtils;
import com.sobot.network.http.HttpBaseUtils;
import com.sobot.pictureframe.SobotBitmapUtil;
import com.sobot.utils.SobotLogUtils;
import com.sobot.utils.SobotSDCardUtils;
......@@ -133,21 +131,21 @@ public class MainActivity extends SobotBaseActivity {
Map<String, String> headers = new HashMap<>();
headers.put("version", "2.9.7");
headers.put("from", "2");
SobotHttpUtils.doPost(MainActivity.this, "https://api.sobot.com/chat-sdk/sdk/user/v2/robotGuide.action", 5000,map, headers, new HttpBaseUtils.StringCallBack() {
@Override
public void onResponse(String result) {
}
@Override
public void onError(Exception e, String msg, int responseCode) {
}
@Override
public void inProgress(int progress) {
}
});
// SobotHttpUtils.doPost(MainActivity.this, "https://api.sobot.com/chat-sdk/sdk/user/v2/robotGuide.action", 5000,map, headers, new HttpBaseUtils.StringCallBack() {
// @Override
// public void onResponse(String result) {
// }
//
// @Override
// public void onError(Exception e, String msg, int responseCode) {
//
// }
//
// @Override
// public void inProgress(int progress) {
//
// }
// });
String languageFileName = "sobot_android_strings_en.json";
String languagePath = SobotSDCardUtils.getPrivatePath(MainActivity.this) + File.separator + "sobot_language" + File.separator + languageFileName;
File file = new File(languagePath);
......@@ -198,6 +196,30 @@ public class MainActivity extends SobotBaseActivity {
// });
// }
Map<String, Object> map1 = new HashMap<>();
map1.put("email", "zhengnawei@sobot.com");
map1.put("passwd", "znw123456");
map1.put("loginStatus", "1");
map1.put("from", 2 + "");
map1.put("way", "10");
map1.put("ack", "1");
Map<String, String> headers1 = new HashMap<>();
headers1.put("language", "zh");
// SobotLoginTools.getInstance().doAppLogin(MainActivity.this, MainActivity.this, "https://api-c.soboten.com/text", 8000, map1, headers1, new SobotResultBlock() {
// @Override
// public void resultBolok(SobotResultCode code, String msg, Object obj) {
// SobotLoginTools.getInstance().checkExpiresToken();
// SobotLogUtils.i(SobotLoginTools.getInstance().getAccessToken()+"");
// SobotLogUtils.i(SobotLoginTools.getInstance().getTempId());
// SobotLogUtils.i(SobotLoginTools.getInstance().getToken()+"");
// }
// });
// LoginUserEntity sa=new LoginUserEntity();
// sa.setLogin_time(System.currentTimeMillis());
// SobotLoginTools.getInstance().setLoginUser(sa);
// SobotServiceInfoModel ccc=new SobotServiceInfoModel();
// SobotLoginTools.getInstance().setServiceInfo(ccc);
}
@Override
......
......@@ -19,7 +19,7 @@ public class MyApp extends MultiDexApplication {
// Fresco.initialize(this);
// 主要是添加下面这句代码
// MultiDex.install(this);
SobotCommonApi.init(this, "https://sobot.com");
SobotCommonApi.init(this, "https://api-c.sobot.com");
SobotCommonApi.setShowLogDebug(true);
SobotWidgetApi.setSwitchMarkStatus(SobotMarkConfig.LANDSCAPE_SCREEN, false);
SobotWidgetApi.setSwitchMarkStatus(SobotMarkConfig.DISPLAY_INNOTCH, false);
......
......@@ -11,7 +11,7 @@ android {
//这里就是打jar包
task makeJar(type: Copy) {
//删除旧的jar包
delete 'build/libs/sobot_common_1.3.4.jar'
delete 'build/libs/sobot_common_1.4.0.jar'
//原地址
from('build/intermediates/packaged-classes/release/')
//导出jar包的地址
......@@ -19,7 +19,7 @@ android {
//包含的jar包
include('classes.jar')
//重命名jar包为mysdk
rename ('classes.jar', 'sobot_common_1.3.4.jar')
rename ('classes.jar', 'sobot_common_1.4.0.jar')
}
makeJar.dependsOn(build)
}
......
......@@ -13,7 +13,7 @@ ext {
PUBLISH_GROUP_ID = "com.sobot.library" //项目包名
PUBLISH_ARTIFACT_ID = 'sobotcommon' //项目名
// PUBLISH_ARTIFACT_ID = 'sobotcommon_x' //项目名
PUBLISH_VERSION = '1.3.9' //版本号
PUBLISH_VERSION = '1.3.9.5' //版本号
}
......
......@@ -6,7 +6,7 @@ import android.text.TextUtils;
import com.sobot.common.login.callback.SobotResultBlock;
import com.sobot.common.login.callback.SobotResultCode;
import com.sobot.common.login.db.HostManager;
import com.sobot.common.login.db.LoginUserInfoUtils;
import com.sobot.common.login.db.LoginUserManager;
import com.sobot.common.login.db.ServiceInfoManager;
import com.sobot.common.login.model.HostModel;
import com.sobot.common.login.model.LoginUserEntity;
......@@ -16,6 +16,7 @@ import com.sobot.gson.SobotGsonUtil;
import com.sobot.network.apiUtils.SobotBaseCode;
import com.sobot.network.apiUtils.SobotHttpUtils;
import com.sobot.network.http.HttpBaseUtils;
import com.sobot.utils.SobotLogUtils;
import com.sobot.utils.SobotSharedPreferencesUtil;
import com.sobot.utils.SobotStringUtils;
......@@ -31,40 +32,169 @@ import java.util.Map;
*/
public class SobotLoginTools {
/**
* 获取登录信息
*/
public static LoginUserEntity getLoginInfo() {
return LoginUserInfoUtils.getUser();
//内部类单例
private SobotLoginTools() {
}
/**
* 获取坐席信息
*/
public static SobotServiceInfoModel getServiceInfoModel() {
return ServiceInfoManager.getInstance().getInfo();
public static SobotLoginTools getInstance() {
return SobotLoginTools.SobotLoginToolsHolder.instance;
}
private static class SobotLoginToolsHolder {
private static final SobotLoginTools instance = new SobotLoginTools();
}
private LoginUserEntity user;
public LoginUserEntity getLoginUser() {
if (user == null || user.getAid() == null) {
user = LoginUserManager.getInstance().getCurUser();
}
return user;
}
public void setLoginUser(LoginUserEntity newUser) {
LoginUserManager.getInstance().deleteAll();
user = newUser;
if (user != null) {
user.setLogin_time(System.currentTimeMillis());
LoginUserManager.getInstance().insert(user);
} else {
HostManager.getInstance().deleteAll();
ServiceInfoManager.getInstance().deleteAll();
}
}
private SobotServiceInfoModel mServiceInfoModel;
public SobotServiceInfoModel getServiceInfo() {
if (mServiceInfoModel == null) {
mServiceInfoModel = ServiceInfoManager.getInstance().getInfo();
}
return mServiceInfoModel;
}
public void setServiceInfo(SobotServiceInfoModel newServiceInfo) {
ServiceInfoManager.getInstance().deleteAll();
mServiceInfoModel = newServiceInfo;
if (mServiceInfoModel != null) {
ServiceInfoManager.getInstance().insert(mServiceInfoModel);
} else {
ServiceInfoManager.getInstance().deleteAll();
}
}
//呼叫 v6 获取 accessToken
public String getAccessToken() {
if (getLoginUser() != null) {
return SobotStringUtils.checkStringIsNull(getLoginUser().getAccess_token());
}
return "";
}
//呼叫 v6 获取 accessToken
public String getTempId() {
if (getLoginUser() != null) {
return SobotStringUtils.checkStringIsNull(getLoginUser().getTempId());
}
return "";
}
//呼叫 v6 获取 accessToken
public String getToken() {
if (getLoginUser() != null) {
return SobotStringUtils.checkStringIsNull(getLoginUser().getToken());
}
return "";
}
// 检查token是否过期 12个小时 返回true 有效; false 过期
public boolean checkExpiresToken() {
if (getLoginUser() != null) {
long difference = System.currentTimeMillis() - getLoginUser().getLogin_time();
SobotLogUtils.d("检查token是否过期:上次登录距离当前的时间" + difference);
if (getLoginUser().getLogin_time() > 0 && (difference > 12 * 60 * 60 * 1000)) {
return false;
}
}
return true;
}
public boolean isLogin() {
if (getLoginUser() != null && !SobotStringUtils.isEmpty(getLoginUser().getToken()) && checkExpiresToken()) {
return true;
} else {
return false;
}
}
/**
* 获取域名信息
*/
public static HostModel getHostModel() {
public HostModel getHostModel() {
return HostManager.getInstance().getHost();
}
// 执行APP登录接口
public static void doAppLogin(final Object cancelTag, final Context mContext, final String host, long timeout, Map<String, Object> params, Map<String, String> headers, final SobotResultBlock resultBlock) {
public void doAppLogin(final Object cancelTag, final Context mContext, final String host, long timeout, Map<String, Object> params, Map<String, String> headers, final SobotResultBlock resultBlock) {
SobotHttpUtils.doPost(cancelTag, host + "/chat-sdk/sdk/admin/v1/login.action", timeout, params, headers, new HttpBaseUtils.StringCallBack() {
@Override
public void onResponse(String result) {
if (!TextUtils.isEmpty(result)) {
SobotBaseCode<LoginUserEntity> baseModel = SobotGsonUtil.jsonToBeans(result, new com.sobot.gson.reflect.TypeToken<SobotBaseCode<LoginUserEntity>>() {
final SobotBaseCode<LoginUserEntity> baseModel = SobotGsonUtil.jsonToBeans(result, new com.sobot.gson.reflect.TypeToken<SobotBaseCode<LoginUserEntity>>() {
}.getType());
if (baseModel != null) {
//登录接口和获取坐席信息权限接口都成功才算真正登录成功
if ("1".equals(baseModel.getCode()) && baseModel.getData() != null) {
LoginUserInfoUtils.setUser(baseModel.getData());
getLoginUserInfo(cancelTag, mContext, baseModel.getData(), host, baseModel.getData().getToken(), baseModel.getData().getLanguage(), resultBlock);
final LoginUserEntity userEntity = baseModel.getData();
getLoginUserInfo(cancelTag, mContext, baseModel.getData(), host, baseModel.getData().getToken(), baseModel.getData().getLanguage(), new SobotResultBlock() {
@Override
public void resultBolok(SobotResultCode code, String msg, Object obj) {
if (code == SobotResultCode.CODE_SUCCEEDED) {
SobotServiceInfoModel serviceInfoModel = (SobotServiceInfoModel) obj;
if (serviceInfoModel != null) {
if (serviceInfoModel.getCallV6Flag() == 1) {
if (userEntity != null && !SobotStringUtils.isEmpty(userEntity.getToken())) {
//如果是v6呼叫
String tempHost = host;
if (tempHost.contains("/text")) {
tempHost = tempHost.replace("/text", "");
}
doAccessToken(cancelTag, tempHost, userEntity.getToken(), new SobotResultBlock() {
@Override
public void resultBolok(SobotResultCode code, String msg, Object obj) {
if (code == SobotResultCode.CODE_SUCCEEDED) {
LoginUserEntity tempUserEntity = userEntity;
String accessToken = (String) obj;
tempUserEntity.setLogin_time(System.currentTimeMillis());
tempUserEntity.setAccess_token(accessToken);
tempUserEntity.setLogin_time(System.currentTimeMillis());
setLoginUser(tempUserEntity);
resultBlock.resultBolok(SobotResultCode.CODE_SUCCEEDED, "登录成功", tempUserEntity);
} else {
resultBlock.resultBolok(SobotResultCode.CODE_FAILED, "登录失败", null);
}
}
});
} else {
resultBlock.resultBolok(SobotResultCode.CODE_FAILED, "登录失败", null);
}
} else {
userEntity.setLogin_time(System.currentTimeMillis());
setLoginUser(userEntity);
resultBlock.resultBolok(SobotResultCode.CODE_SUCCEEDED, "登录成功", userEntity);
}
}else{
resultBlock.resultBolok(SobotResultCode.CODE_FAILED, "登录失败", null);
}
}
}
});
} else {
resultBlock.resultBolok(SobotResultCode.CODE_FAILED, baseModel.getMsg(), baseModel.getCode());
}
......@@ -95,7 +225,7 @@ public class SobotLoginTools {
* @param token
* @param resultBlock 返回坐席信息
*/
public static void getLoginUserInfo(Object cancelTag, Context mContext, String host, String token, String language, SobotResultBlock resultBlock) {
public void getLoginUserInfo(Object cancelTag, Context mContext, String host, String token, String language, SobotResultBlock resultBlock) {
getLoginUserInfo(cancelTag, mContext, null, host, token, language, resultBlock);
}
......@@ -109,7 +239,7 @@ public class SobotLoginTools {
* @param token
* @param resultBlock
*/
public static void getLoginUserInfo(Object cancelTag, final Context mContext, final LoginUserEntity loginUser, String host, String token, String language, final SobotResultBlock resultBlock) {
public void getLoginUserInfo(final Object cancelTag, final Context mContext, final LoginUserEntity loginUser, final String host, String token, String language, final SobotResultBlock resultBlock) {
final String url = host + "/basic-config-service/consoleAuth/queryAppAgentMenus";
Map<String, String> headerMap = new HashMap<>();
if (!TextUtils.isEmpty(token)) {
......@@ -131,25 +261,23 @@ public class SobotLoginTools {
List<ServiceFunctionVoModel> functions = new ArrayList<>();
JSONArray items = resonseObj.optJSONArray("items");
getListByObj(functions, items);
if (serviceInfoModel.getGlobalPermissions() != null) {
//全局权限
for (int i = 0; i < serviceInfoModel.getGlobalPermissions().size(); i++) {
if (!SobotStringUtils.isEmpty(serviceInfoModel.getGlobalPermissions().get(i))) {
ServiceFunctionVoModel functionVoModel = new ServiceFunctionVoModel();
functionVoModel.setCode(serviceInfoModel.getGlobalPermissions().get(i));
functions.add(functionVoModel);
}
if (serviceInfoModel != null) {
if (serviceInfoModel.getGlobalPermissions() != null) {
//全局权限
for (int i = 0; i < serviceInfoModel.getGlobalPermissions().size(); i++) {
if (!SobotStringUtils.isEmpty(serviceInfoModel.getGlobalPermissions().get(i))) {
ServiceFunctionVoModel functionVoModel = new ServiceFunctionVoModel();
functionVoModel.setCode(serviceInfoModel.getGlobalPermissions().get(i));
functions.add(functionVoModel);
}
}
}
}
serviceInfoModel.setFunctionStr(functions);
//保存在数据库
ServiceInfoManager.getInstance().saveInfo(serviceInfoModel);
SobotSharedPreferencesUtil.getInstance(mContext).put(SobotLoginConstant.SOBOT_LOGIN_USER_INFO, serviceInfoModel);
if (loginUser != null) {
resultBlock.resultBolok(SobotResultCode.CODE_SUCCEEDED, "登录成功", loginUser);
} else {
resultBlock.resultBolok(SobotResultCode.CODE_SUCCEEDED, "登录成功", serviceInfoModel);
serviceInfoModel.setFunctionStr(functions);
//保存在数据库
setServiceInfo(serviceInfoModel);
SobotSharedPreferencesUtil.getInstance(mContext).put(SobotLoginConstant.SOBOT_LOGIN_USER_INFO, serviceInfoModel);
resultBlock.resultBolok(SobotResultCode.CODE_SUCCEEDED, "获取成功", serviceInfoModel);
}
} else {
resultBlock.resultBolok(SobotResultCode.CODE_FAILED, retMsg == null ? "" : retMsg, null);
......@@ -173,7 +301,7 @@ public class SobotLoginTools {
}
private static void getListByObj(List<ServiceFunctionVoModel> list, JSONArray items) {
private void getListByObj(List<ServiceFunctionVoModel> list, JSONArray items) {
try {
if (null != items) {
for (int i = 0; i < items.length(); i++) {
......@@ -195,4 +323,43 @@ public class SobotLoginTools {
e.printStackTrace();
}
}
/**
* 获取accessToken
*/
public void doAccessToken(Object cancelTag, String host, String token, final SobotResultBlock resultBlock) {
Map<String, String> headerMap = new HashMap<>();
if (!TextUtils.isEmpty(token)) {
headerMap.put("temp-id", token);
}
SobotHttpUtils.doPost(cancelTag, host + "/tokens/getToken", null, headerMap, new HttpBaseUtils.StringCallBack() {
@Override
public void onResponse(String result) {
if (!TextUtils.isEmpty(result)) {
Map map = SobotGsonUtil.jsonToMaps((String) result);
if (map != null && map.containsKey("accessToken")) {
String accessToken = (String) map.get("accessToken");
resultBlock.resultBolok(SobotResultCode.CODE_SUCCEEDED, "", accessToken);
} else {
resultBlock.resultBolok(SobotResultCode.CODE_FAILED, "", null);
}
} else {
resultBlock.resultBolok(SobotResultCode.CODE_FAILED, "", null);
}
}
@Override
public void onError(Exception e, String msg, int responseCode) {
resultBlock.resultBolok(SobotResultCode.CODE_FAILED, msg, null);
}
@Override
public void inProgress(int progress) {
}
});
}
}
package com.sobot.common.login.db;
import com.sobot.common.login.model.LoginUserEntity;
/**
* 获取当前登录用户信息
*/
public class LoginUserInfoUtils {
private static LoginUserEntity user;
public synchronized static LoginUserEntity getUser() {
if (user == null || user.getAid() == null) {
user = LoginUserManager.getInstance().getCurUser();
}
return user;
}
public static void setUser(LoginUserEntity newUser) {
LoginUserManager.getInstance().deleteAll();
user = newUser;
if (user != null) {
LoginUserManager.getInstance().insert(user);
} else {
HostManager.getInstance().deleteAll();
ServiceInfoManager.getInstance().deleteAll();
}
}
}
......@@ -7,6 +7,7 @@ import android.database.Cursor;
import com.sobot.common.login.model.LoginUserEntity;
import com.sobot.common.utils.SobotGlobalContext;
import com.sobot.gson.SobotGsonUtil;
import com.sobot.utils.SobotStringUtils;
import java.util.List;
import java.util.Map;
......@@ -55,8 +56,10 @@ public class LoginUserManager extends SobotCommonDao<LoginUserEntity> {
model.setMaxServiceCount(cursor.getInt(cursor.getColumnIndex("maxServiceCount")));
model.setBlackFunction(cursor.getInt(cursor.getColumnIndex("blackFunction")));
String transferFunction = cursor.getString(cursor.getColumnIndex("transferFunction"));
Map<String, Boolean> map = SobotGsonUtil.jsonToMaps(transferFunction);
model.setTicketFunction(map);
if (!SobotStringUtils.isEmpty(transferFunction)){
Map<String, Boolean> map = SobotGsonUtil.jsonToMaps(transferFunction);
model.setTicketFunction(map);
}
model.setFace(cursor.getString(cursor.getColumnIndex("face")));
model.setCompanyName(cursor.getString(cursor.getColumnIndex("companyName")));
model.setAppKey(cursor.getString(cursor.getColumnIndex("appKey")));
......@@ -80,6 +83,8 @@ public class LoginUserManager extends SobotCommonDao<LoginUserEntity> {
model.setKbVersion(cursor.getInt(cursor.getColumnIndex("kbVersion")) + "");
model.setCompanyId(cursor.getString(cursor.getColumnIndex("companyId")));
model.setLanguage(cursor.getString(cursor.getColumnIndex("local_language")));
model.setAccess_token(cursor.getString(cursor.getColumnIndex(LoginUserEntity.ACCESS_TOKEN)));
model.setLogin_time(cursor.getLong(cursor.getColumnIndex(LoginUserEntity.LOGIN_TIME)));
return model;
}
......@@ -93,7 +98,9 @@ public class LoginUserManager extends SobotCommonDao<LoginUserEntity> {
contentValues.put("maxServiceCount", userAccount.getMaxServiceCount());
contentValues.put("blackFunction", userAccount.getBlackFunction());
contentValues.put("transferFunction", userAccount.getTransferFunction());
contentValues.put("ticketFunction", SobotGsonUtil.beanToJson(userAccount.getTicketFunction()));
if (userAccount.getTicketFunction() != null) {
contentValues.put("ticketFunction", SobotGsonUtil.beanToJson(userAccount.getTicketFunction()));
}
contentValues.put("face", userAccount.getFace());
contentValues.put("companyName", userAccount.getCompanyName());
contentValues.put("appKey", userAccount.getAppKey());
......@@ -115,12 +122,14 @@ public class LoginUserManager extends SobotCommonDao<LoginUserEntity> {
contentValues.put("callV1Flag", userAccount.getCallV1Flag());
contentValues.put("transferAuditFlag", userAccount.getTransferAuditFlag());
int kbVersion = 1;
if ("6".contains(userAccount.getKbVersion())) {
if ("6".contains(SobotStringUtils.checkStringIsNull(userAccount.getKbVersion()))) {
kbVersion = 6;
}
contentValues.put("kbVersion", kbVersion);
contentValues.put("companyId", userAccount.getCompanyId());
contentValues.put("local_language", userAccount.getLanguage());
contentValues.put(LoginUserEntity.ACCESS_TOKEN, userAccount.getAccess_token());
contentValues.put(LoginUserEntity.LOGIN_TIME, userAccount.getLogin_time());
return contentValues;
}
......
......@@ -9,6 +9,7 @@ import com.sobot.common.login.model.SobotServiceInfoModel;
import com.sobot.common.utils.SobotGlobalContext;
import com.sobot.gson.SobotGsonUtil;
import com.sobot.gson.reflect.TypeToken;
import com.sobot.utils.SobotStringUtils;
import java.util.List;
......@@ -58,18 +59,21 @@ public class ServiceInfoManager extends SobotCommonDao<SobotServiceInfoModel> {
model.setNewBossSwitch(cursor.getInt(cursor.getColumnIndex("newBossSwitch")));
model.setRegion(cursor.getInt(cursor.getColumnIndex("region")));
String functionStr = cursor.getString(cursor.getColumnIndex("functionStr"));
List<ServiceFunctionVoModel> list = SobotGsonUtil.jsonToBeans(functionStr, new TypeToken<List<ServiceFunctionVoModel>>() {
}.getType());
model.setFunctionStr(list);
if (!SobotStringUtils.isEmpty(functionStr)) {
List<ServiceFunctionVoModel> list = SobotGsonUtil.jsonToBeans(functionStr, new TypeToken<List<ServiceFunctionVoModel>>() {
}.getType());
model.setFunctionStr(list);
}
model.setCompanyId(cursor.getString(cursor.getColumnIndex("companyId")));
model.setCallV6Flag(cursor.getInt(cursor.getColumnIndex("callV6Flag")));
model.setLanguage(cursor.getString(cursor.getColumnIndex("language")));
model.setPhoneNo(cursor.getString(cursor.getColumnIndex("phoneNo")));
String globalPermissions = cursor.getString(cursor.getColumnIndex("globalPermissions"));
List<String> globalPermissionslist = SobotGsonUtil.jsonToBeans(globalPermissions, new TypeToken<List<String>>() {
}.getType());
model.setGlobalPermissions(globalPermissionslist);
if (!SobotStringUtils.isEmpty(globalPermissions)) {
List<String> globalPermissionslist = SobotGsonUtil.jsonToBeans(globalPermissions, new TypeToken<List<String>>() {
}.getType());
model.setGlobalPermissions(globalPermissionslist);
}
return model;
}
......@@ -83,12 +87,16 @@ public class ServiceInfoManager extends SobotCommonDao<SobotServiceInfoModel> {
contentValues.put("serviceLanguage", infoModel.getServiceLanguage());
contentValues.put("newBossSwitch", infoModel.getNewBossSwitch());
contentValues.put("region", infoModel.getRegion());
contentValues.put("functionStr", SobotGsonUtil.beanToJson(infoModel.getFunctionStr()));
if (!SobotStringUtils.isEmpty(infoModel.getFunctionStr())) {
contentValues.put("functionStr", SobotGsonUtil.beanToJson(infoModel.getFunctionStr()));
}
contentValues.put("companyId", infoModel.getCompanyId());
contentValues.put("callV6Flag",infoModel.getCallV6Flag());
contentValues.put("callV6Flag", infoModel.getCallV6Flag());
contentValues.put("language", infoModel.getLanguage());
contentValues.put("phoneNo", infoModel.getPhoneNo());
contentValues.put("globalPermissions", SobotGsonUtil.beanToJson(infoModel.getGlobalPermissions()));
if (!SobotStringUtils.isEmpty(infoModel.getGlobalPermissions())) {
contentValues.put("globalPermissions", SobotGsonUtil.beanToJson(infoModel.getGlobalPermissions()));
}
return contentValues;
}
......
......@@ -4,6 +4,8 @@ import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
import com.sobot.common.login.model.LoginUserEntity;
import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReentrantLock;
......@@ -13,7 +15,8 @@ import java.util.concurrent.locks.ReentrantLock;
class SobotCommonDBHelper extends SQLiteOpenHelper {
private static final String DB_CACHE_NAME = "sobot_common.db";
private static final int DB_CACHE_VERSION = 1;
// private static final int DB_CACHE_VERSION = 1;
private static final int DB_CACHE_VERSION = 2;
static final String TABLE_LOGIN_USER = "login_user";
static final String TABLE_SOBOT_HOST = "sobot_host";
static final String TABLE_SERVICE_INFO = "sobot_service";
......@@ -69,7 +72,7 @@ class SobotCommonDBHelper extends SQLiteOpenHelper {
"sid varchar(40), " +
"pu varchar(40), " +
"puid varchar(40), " +
"token varchar(300), " +
"token varchar(500), " +
"cusRoleName varchar(200), " +
"aid varchar(40), " +
"centerNumber varchar(40), " +
......@@ -124,9 +127,17 @@ class SobotCommonDBHelper extends SQLiteOpenHelper {
*/
private void upgradeDB(SQLiteDatabase db, int oldVersion, int newVersion) {
switch (oldVersion) {
case 1:
String sql = "ALTER TABLE " + TABLE_LOGIN_USER
+ " ADD COLUMN " + LoginUserEntity.ACCESS_TOKEN + " VARCHAR(700)";
db.execSQL(sql); // 执行修改表,添加字段的逻辑。
String sql1 = "ALTER TABLE " + TABLE_LOGIN_USER
+ " ADD COLUMN " + LoginUserEntity.LOGIN_TIME + " INTEGER";
db.execSQL(sql1); // 执行修改表,添加字段的逻辑。
break;
default:
break;
}
}
}
......@@ -48,6 +48,14 @@ public class LoginUserEntity implements Serializable {
private String language;//国际化指定语言 3.1.3新增 为空时,默认中文
private String access_token;//呼叫v6
public static final String ACCESS_TOKEN = "access_token";//呼叫v6 accessToken
private long login_time;//登录时间戳
public static final String LOGIN_TIME = "login_time";
public String getCompanyName() {
return companyName;
}
......@@ -312,4 +320,19 @@ public class LoginUserEntity implements Serializable {
this.language = language;
}
public String getAccess_token() {
return access_token;
}
public void setAccess_token(String access_token) {
this.access_token = access_token;
}
public long getLogin_time() {
return login_time;
}
public void setLogin_time(long login_time) {
this.login_time = login_time;
}
}
......@@ -2,8 +2,7 @@ package com.sobot.common.login.permission;
import android.text.TextUtils;
import com.sobot.common.login.db.LoginUserInfoUtils;
import com.sobot.common.login.db.ServiceInfoManager;
import com.sobot.common.login.SobotLoginTools;
import com.sobot.common.login.model.LoginUserEntity;
import com.sobot.common.login.model.ServiceFunctionVoModel;
import com.sobot.common.login.model.SobotServiceInfoModel;
......@@ -27,8 +26,8 @@ public class SobotPermissionManager {
private static SobotPermissionApi getInstance() {
if (instance == null) {
if (LoginUserInfoUtils.getUser() != null) {
switch (LoginUserInfoUtils.getUser().getCusRoleId()) {
if (SobotLoginTools.getInstance().getLoginUser() != null) {
switch (SobotLoginTools.getInstance().getLoginUser().getCusRoleId()) {
case ONLINE_CUSTOMER_SERVICE://在线客服
instance = new PermissionOnLineCustomerService();
break;
......@@ -63,7 +62,7 @@ public class SobotPermissionManager {
}
public static boolean checkPermission(int type) {
SobotServiceInfoModel serviceInfoModel = ServiceInfoManager.getInstance().getInfo();
SobotServiceInfoModel serviceInfoModel = SobotLoginTools.getInstance().getServiceInfo();
if (serviceInfoModel != null) {
if (serviceInfoModel.getNewBossSwitch() > 0) {
return isHasPermission(type + "");
......@@ -265,7 +264,7 @@ public class SobotPermissionManager {
}
public static boolean isHasPermission(String type) {
SobotServiceInfoModel serviceInfoModel = ServiceInfoManager.getInstance().getInfo();
SobotServiceInfoModel serviceInfoModel = SobotLoginTools.getInstance().getServiceInfo();
if (serviceInfoModel != null) {
if (serviceInfoModel.getNewBossSwitch() > 0) {
if (!TextUtils.isEmpty(type) && serviceInfoModel != null && serviceInfoModel.getFunctionStr() != null) {
......@@ -277,7 +276,7 @@ public class SobotPermissionManager {
}
}
} else {
LoginUserEntity customerServiceInfoModel = LoginUserInfoUtils.getUser();
LoginUserEntity customerServiceInfoModel = SobotLoginTools.getInstance().getLoginUser();
if (!TextUtils.isEmpty(type) && customerServiceInfoModel != null && customerServiceInfoModel.getTicketFunction() != null && customerServiceInfoModel.getTicketFunction().containsKey(type)) {
return customerServiceInfoModel.getTicketFunction().get(type);
}
......@@ -287,7 +286,7 @@ public class SobotPermissionManager {
}
public static boolean isHasNewPermission(String type) {
SobotServiceInfoModel serviceInfoModel = ServiceInfoManager.getInstance().getInfo();
SobotServiceInfoModel serviceInfoModel = SobotLoginTools.getInstance().getServiceInfo();
if (serviceInfoModel != null) {
if (serviceInfoModel.getNewBossSwitch() > 0) {
if (!TextUtils.isEmpty(type) && serviceInfoModel != null && serviceInfoModel.getFunctionStr() != null) {
......
......@@ -11,7 +11,7 @@ android {
//这里就是打jar包
task makeJar(type: Copy) {
//删除旧的jar包
delete 'build/libs/picture_1.1.jar'
delete 'build/libs/sobot_picture_1.1.4.jar'
//原地址
from('build/intermediates/packaged-classes/release/')
//导出jar包的地址
......@@ -19,7 +19,7 @@ android {
//包含的jar包
include('classes.jar')
//重命名jar包为mysdk
rename ('classes.jar', 'picture_1.1.jar')
rename ('classes.jar', 'sobot_picture_1.1.4.jar')
}
makeJar.dependsOn(build)
......
......@@ -8,6 +8,23 @@ android {
defaultConfig {
minSdkVersion 14
}
//这里就是打jar包
task makeJar(type: Copy) {
//删除旧的jar包
delete 'build/libs/sobot_utils_1.1.2.jar'
//原地址
from('build/intermediates/packaged-classes/release/')
//导出jar包的地址
into('build/libs/')
//包含的jar包
include('classes.jar')
//重命名jar包为mysdk
rename ('classes.jar', 'sobot_utils_1.1.2.jar')
}
makeJar.dependsOn(build)
lintOptions{ abortOnError false }
}
dependencies {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment