|
|
@@ -17,6 +17,7 @@ import com.alibaba.fastjson.JSON;
|
|
|
import com.alibaba.fastjson.JSONArray;
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
import com.common.LogUtil;
|
|
|
+import com.common.config.BaseConfig;
|
|
|
import com.common.data.JSONUtil;
|
|
|
import com.common.data.ListUtils;
|
|
|
import com.common.data.StringUtil;
|
|
|
@@ -299,7 +300,7 @@ public class ViewUtil {
|
|
|
// }
|
|
|
|
|
|
}
|
|
|
-
|
|
|
+ @Deprecated
|
|
|
public static void showDialogB2B(final String phone, final String password, final List<LoginEntity.Spaces> models) {
|
|
|
String[] items = new String[models.size()];
|
|
|
// int select = 0;
|
|
|
@@ -335,17 +336,16 @@ public class ViewUtil {
|
|
|
// 登录B2B
|
|
|
public static void LoginB2BTask(String phone, String password, Integer spaceId) {
|
|
|
mdProcessDialog.setContent(MyApplication.getInstance().getString(R.string.login_progress_b2b));
|
|
|
- String url = ApiConfig.getInstance(ApiUtils.getApiModel()).getmApiBase().login;
|
|
|
+ String url = ApiConfig.getInstance(new ApiPlatform()).getmApiBase().login;
|
|
|
+ LogUtil.d("HttpLogs","b2b login url:"+url);
|
|
|
Map<String, String> params = new HashMap<String, String>();
|
|
|
params.put("appId", "b2b");
|
|
|
params.put("username", phone);
|
|
|
params.put("password", password);
|
|
|
- if (CommonUtil.isReleaseVersion()) {
|
|
|
+ if (BaseConfig.isDebug()) {
|
|
|
params.put("spaceId", String.valueOf(spaceId));
|
|
|
- Log.i("fang,url", String.valueOf(spaceId) + url + "");
|
|
|
} else {
|
|
|
params.put("spaceId", "76035");
|
|
|
- Log.i("fang,url", "76035," + url);
|
|
|
}
|
|
|
startNetThread(url, params, handler, Constants.SUCCESS_B2B, null, null, "post");
|
|
|
}
|
|
|
@@ -394,8 +394,6 @@ public class ViewUtil {
|
|
|
if (JSONUtil.validate(msg.getData().getString("result"))) {
|
|
|
ToastMessage(MyApplication.getInstance(),
|
|
|
JSON.parseObject(msg.getData().getString("result")).getString("exception"), Style.holoRedLight, 3000);
|
|
|
-// ToastMessage(MyApplication.getInstance(),"账号或密码错误,请重新输入");
|
|
|
-
|
|
|
} else {
|
|
|
boolean isNetHas = NetUtils.isNetWorkConnected(ct);
|
|
|
if (isNetHas)
|
|
|
@@ -480,7 +478,8 @@ public class ViewUtil {
|
|
|
CommonUtil.setSharedPreferences(ct, "user_password", erp_password);
|
|
|
}
|
|
|
if (ct == null) ct = MyApplication.getInstance();
|
|
|
- CommonUtil.setSharedPreferences(ct, "b2b_login", true);
|
|
|
+
|
|
|
+ CommonUtil.setSharedPreferences(ct, "erp_login", false);
|
|
|
CommonUtil.setSharedPreferences(ct, "b2b_uu", b2b_uu);
|
|
|
mdProcessDialog.setContent(MyApplication.getInstance().getString(R.string.login_success_b2b));
|
|
|
handler.postDelayed(new Runnable() {
|
|
|
@@ -489,14 +488,14 @@ public class ViewUtil {
|
|
|
mdProcessDialog.cancel();
|
|
|
}
|
|
|
}, 1500);
|
|
|
- if (!hasErp) {
|
|
|
if (ct instanceof Activity) {
|
|
|
-// if (!StringUtil.isEmpty(CommonUtil.getSharedPreferences(MyApplication.getInstance(),"erp_baseurl"))){
|
|
|
-// }else{
|
|
|
- ct.startActivity(new Intent("com.modular.main.DataDownloadActivity"));
|
|
|
-// }
|
|
|
- }
|
|
|
+ if (CommonUtil.getSharedPreferencesBoolean(MyApplication.getInstance(),"b2b_login")){
|
|
|
+ }else{
|
|
|
+ CommonUtil.setSharedPreferences(ct, "b2b_login", true);
|
|
|
+ ct.startActivity(new Intent("com.modular.main.DataDownloadActivity"));
|
|
|
+ }
|
|
|
}
|
|
|
+
|
|
|
sendBrodcast("B2B");
|
|
|
}
|
|
|
|
|
|
@@ -582,38 +581,102 @@ public class ViewUtil {
|
|
|
|
|
|
}
|
|
|
if (JSONUtil.validate(json)) {
|
|
|
- showDialogCompany(json, phone, password);
|
|
|
+ // showDialogCompany(json, phone, password);
|
|
|
+ showLoginDialog(json, phone, password);
|
|
|
} else {
|
|
|
ToastMessage(ct, "接口数据非法!", Style.holoRedLight, 3000);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- //TODO 针对于平台的测试、正式数据库不一致
|
|
|
- private static String getNameByB2b(String userName, String phone) {
|
|
|
- if (StringUtil.isEmpty(phone)) return userName;
|
|
|
- LogUtil.d("phone=" + phone);
|
|
|
- if (phone.equals("13111110001")) {
|
|
|
- return "吕全明";
|
|
|
- } else if (phone.equals("13111110002")) {
|
|
|
- return "曹秋莲";
|
|
|
- } else if (phone.equals("13111110003")) {
|
|
|
- return "陈爱平";
|
|
|
- } else if (phone.equals("13111110004")) {
|
|
|
- return "CS008";
|
|
|
- } else if (phone.equals("13111110005")) {
|
|
|
- return "CS009";
|
|
|
- } else if (phone.equals("15012345676")) {
|
|
|
- return "品质";
|
|
|
- } else if (phone.equals("15012345678")) {
|
|
|
- return "邓国超移动";
|
|
|
+
|
|
|
+
|
|
|
+ //解析登录信息
|
|
|
+ public static void showLoginDialog(String loginResult,final String phone,final String password){
|
|
|
+ List<LoginEntity> loginMsg = JSON.parseArray(loginResult, LoginEntity.class);
|
|
|
+ List<LoginEntity> loginEntities=new ArrayList<>();
|
|
|
+ if (!ListUtils.isEmpty(loginMsg)){
|
|
|
+ for (int i = 0; i <loginMsg.size() ; i++) {
|
|
|
+ LoginEntity model = loginMsg.get(i);
|
|
|
+ if (model.getPlatform().equals("ERP")) {
|
|
|
+ loginEntities.add(model);
|
|
|
+ } else if (model.getPlatform().equals("B2B")) {
|
|
|
+ List<LoginEntity.Spaces> sModel = model.getSpaces();
|
|
|
+ if (!ListUtils.isEmpty(sModel)){
|
|
|
+ for (int j = 0; j <sModel.size() ; j++) {
|
|
|
+ //去重逻辑
|
|
|
+ boolean isHas=false;
|
|
|
+ for (int k = 0; k <loginMsg.size() ; k++) {
|
|
|
+ if (sModel.get(j).getName().equals(loginMsg.get(k).getName())){
|
|
|
+ //存在 uas系统里面存在同名的
|
|
|
+ isHas=true;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (!isHas){
|
|
|
+ LoginEntity bModel=new LoginEntity();
|
|
|
+ bModel.setEnuu(Integer.valueOf(sModel.get(j).getEnuu()));
|
|
|
+ bModel.setName(sModel.get(j).getName());
|
|
|
+ bModel.setSpaceId(sModel.get(j).getId());
|
|
|
+ bModel.setPlatform("B2B");
|
|
|
+ loginEntities.add(bModel);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ //
|
|
|
+ LogUtil.d("HttpLogs","login dialog:"+JSON.toJSONString(loginEntities));
|
|
|
+ if (ListUtils.isEmpty(loginEntities))return;
|
|
|
+ erpEntities=loginEntities;
|
|
|
+ String[] items = new String[loginEntities.size()];
|
|
|
+ int select = 0;
|
|
|
+ for (int j = 0; j < loginEntities.size(); j++) {
|
|
|
+ items[j] = loginEntities.get(j).getName();
|
|
|
+ }
|
|
|
+ if (!DialogUtils.isDialogShowing(loginERPDialog)){
|
|
|
+ if (loginERPDialog!=null) {
|
|
|
+ select = loginERPDialog.getSelectedIndex();
|
|
|
+ }
|
|
|
+ loginERPDialog = new MaterialDialog.Builder(ct)
|
|
|
+ .title(ct.getString(R.string.user_dialog_company))
|
|
|
+ .items(items)
|
|
|
+ .itemsCallbackSingleChoice(select,
|
|
|
+ new MaterialDialog.ListCallbackSingleChoice() {
|
|
|
+ @Override
|
|
|
+ public boolean onSelection(MaterialDialog dialog,
|
|
|
+ View view, int which, CharSequence text) {
|
|
|
+ if (!StringUtil.isEmpty(text.toString())) {
|
|
|
+ LoginEntity entity = erpEntities.get(which);
|
|
|
+ if ("ERP".equals(entity.getPlatform())){
|
|
|
+ erp_phone = phone;
|
|
|
+ erp_password = password;
|
|
|
+ erp_username = entity.getAccount();
|
|
|
+ erp_master = entity.getMaster();
|
|
|
+ erp_baseurl = entity.getWebsite();
|
|
|
+ erp_company = entity.getName();
|
|
|
+ erp_uu = String.valueOf(entity.getEnuu());
|
|
|
+ erp_masterId = String.valueOf(entity.getMasterId());
|
|
|
+ CommonUtil.setSharedPreferences(MyApplication.getInstance(), "userRole", "2");
|
|
|
+ LoginERPTask(entity.getWebsite(), entity.getMaster(), phone, password);
|
|
|
+ CommonUtil.clearSharedPreferences(MyApplication.getInstance(), "erp_masterlist"); //清除账套列表缓存
|
|
|
+ }
|
|
|
+ if ("B2B".equals(entity.getPlatform())){
|
|
|
+ CommonUtil.setSharedPreferences(MyApplication.getInstance(), "spaceId", String.valueOf(entity.getSpaceId()));
|
|
|
+ CommonUtil.setSharedPreferences(MyApplication.getInstance(), "companyName", String.valueOf(entity.getName()));
|
|
|
+ CommonUtil.setSharedPreferences(MyApplication.getInstance(), "companyEnUu", String.valueOf(entity.getEnuu()));
|
|
|
+ CommonUtil.setSharedPreferences(MyApplication.getInstance(), "userRole", "3");
|
|
|
+ LoginB2BTask(phone, password, entity.getSpaceId());//登录B2B
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+ }).positiveText(ct.getString(R.string.common_sure)).show();
|
|
|
+
|
|
|
+ }
|
|
|
}
|
|
|
- return userName;
|
|
|
}
|
|
|
-
|
|
|
- /**
|
|
|
- * @desc:解析登录数据
|
|
|
- * @author:Arison on 2017/3/6
|
|
|
- */
|
|
|
+
|
|
|
+
|
|
|
+ @Deprecated
|
|
|
private static void showDialogCompany(String json, String phone, String password) {
|
|
|
List<LoginEntity> logMsg = JSON.parseArray(json, LoginEntity.class);
|
|
|
erpEntities = new ArrayList<>();
|
|
|
@@ -685,7 +748,27 @@ public class ViewUtil {
|
|
|
|
|
|
;
|
|
|
|
|
|
-
|
|
|
+ //TODO 针对于平台的测试、正式数据库不一致
|
|
|
+ private static String getNameByB2b(String userName, String phone) {
|
|
|
+ if (StringUtil.isEmpty(phone)) return userName;
|
|
|
+ LogUtil.d("phone=" + phone);
|
|
|
+ if (phone.equals("13111110001")) {
|
|
|
+ return "吕全明";
|
|
|
+ } else if (phone.equals("13111110002")) {
|
|
|
+ return "曹秋莲";
|
|
|
+ } else if (phone.equals("13111110003")) {
|
|
|
+ return "陈爱平";
|
|
|
+ } else if (phone.equals("13111110004")) {
|
|
|
+ return "CS008";
|
|
|
+ } else if (phone.equals("13111110005")) {
|
|
|
+ return "CS009";
|
|
|
+ } else if (phone.equals("15012345676")) {
|
|
|
+ return "品质";
|
|
|
+ } else if (phone.equals("15012345678")) {
|
|
|
+ return "邓国超移动";
|
|
|
+ }
|
|
|
+ return userName;
|
|
|
+ }
|
|
|
/**
|
|
|
* @author LiuJie
|
|
|
* @功能:比较两个日期大小
|