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' //版本号
}
......
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