|
|
@@ -7,6 +7,8 @@ import android.os.Handler;
|
|
|
import android.os.Message;
|
|
|
import android.support.v7.widget.RecyclerView;
|
|
|
import android.view.LayoutInflater;
|
|
|
+import android.view.Menu;
|
|
|
+import android.view.MenuItem;
|
|
|
import android.view.View;
|
|
|
import android.view.ViewGroup;
|
|
|
import android.widget.Button;
|
|
|
@@ -21,12 +23,14 @@ import com.xzjmyk.pm.activity.ui.base.BaseActivity;
|
|
|
import com.xzjmyk.pm.activity.ui.erp.entity.MissionLocationEntity;
|
|
|
import com.xzjmyk.pm.activity.ui.erp.entity.MissionPlanEntity;
|
|
|
import com.xzjmyk.pm.activity.ui.erp.net.ViewUtil;
|
|
|
+import com.xzjmyk.pm.activity.ui.erp.util.CodeUtil;
|
|
|
import com.xzjmyk.pm.activity.ui.erp.util.CommonUtil;
|
|
|
import com.xzjmyk.pm.activity.ui.erp.util.ListUtils;
|
|
|
import com.xzjmyk.pm.activity.ui.erp.util.StringUtils;
|
|
|
import com.xzjmyk.pm.activity.util.BaiduMapUtil;
|
|
|
import com.xzjmyk.pm.activity.util.TimeUtils;
|
|
|
import com.xzjmyk.pm.activity.view.MostLinearLayoutManager;
|
|
|
+import com.xzjmyk.pm.activity.view.crouton.Crouton;
|
|
|
import com.xzjmyk.pm.activity.view.crouton.Style;
|
|
|
|
|
|
import java.util.ArrayList;
|
|
|
@@ -53,7 +57,22 @@ public class MissionPlanActivity extends BaseActivity implements View.OnClickLis
|
|
|
private Handler handler = new Handler() {
|
|
|
@Override
|
|
|
public void handleMessage(Message msg) {
|
|
|
-
|
|
|
+ progressDialog.dismiss();
|
|
|
+ String message = msg.getData().getString("result");
|
|
|
+ switch (msg.what) {
|
|
|
+ case 0x11://保存外勤计划
|
|
|
+ int position = msg.getData().getInt("position", -1);//成功保存第几个目标
|
|
|
+ Crouton.makeText(ct, "保存成功");
|
|
|
+ if (ListUtils.isEmpty(entitys) || entitys.size() <= position) return;
|
|
|
+ entitys.get(position).setStaatus(1);
|
|
|
+ adapter.notifyItemChanged(position);
|
|
|
+ break;
|
|
|
+ case 0x12://保存目的地
|
|
|
+
|
|
|
+ break;
|
|
|
+ default:
|
|
|
+ break;
|
|
|
+ }
|
|
|
|
|
|
}
|
|
|
};
|
|
|
@@ -67,6 +86,31 @@ public class MissionPlanActivity extends BaseActivity implements View.OnClickLis
|
|
|
initEvent();
|
|
|
}
|
|
|
|
|
|
+ @Override
|
|
|
+ public boolean onCreateOptionsMenu(Menu menu) {
|
|
|
+ return super.onCreateOptionsMenu(menu);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void onBackPressed() {
|
|
|
+ super.onBackPressed();
|
|
|
+ endActivity();
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public boolean onOptionsItemSelected(MenuItem item) {
|
|
|
+ if (item.getItemId() == android.R.id.home) {
|
|
|
+ endActivity();
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+ return super.onOptionsItemSelected(item);
|
|
|
+ }
|
|
|
+
|
|
|
+ private void endActivity() {
|
|
|
+ setResult(0x20);
|
|
|
+ finish();
|
|
|
+ }
|
|
|
+
|
|
|
private void initView() {
|
|
|
entitys = new ArrayList<>();
|
|
|
addEntity(entitys);
|
|
|
@@ -98,6 +142,9 @@ public class MissionPlanActivity extends BaseActivity implements View.OnClickLis
|
|
|
if (ListUtils.isEmpty(entitys) || entitys.size() <= position) return;
|
|
|
entitys.get(position).setCompanyName(StringUtils.isEmpty(entity.getCompany()) ? "" : entity.getCompany());
|
|
|
entitys.get(position).setCompanyAddr(StringUtils.isEmpty(entity.getAddress()) ? "" : entity.getAddress());
|
|
|
+ entitys.get(position).setVisitcount(1 + entity.getVisitcount());
|
|
|
+ entitys.get(position).setLatLng(entity.getLatLng());
|
|
|
+ entitys.get(position).setDistances(entity.getDistances());
|
|
|
adapter.notifyItemChanged(position);
|
|
|
} else if (requestCode == 0x21) {//选择地址
|
|
|
PoiInfo info = data.getParcelableExtra("resultName");
|
|
|
@@ -107,8 +154,9 @@ public class MissionPlanActivity extends BaseActivity implements View.OnClickLis
|
|
|
String distance = BaiduMapUtil.getInstence().getDistance(info.location);
|
|
|
if (StringUtils.isEmpty(distance)) return;
|
|
|
if (ListUtils.isEmpty(entitys) || entitys.size() <= position) return;
|
|
|
- entitys.get(position).setLength(Float.valueOf(distance));
|
|
|
+ entitys.get(position).setDistances(Float.valueOf(distance));
|
|
|
entitys.get(position).setCompanyAddr(info.address);
|
|
|
+ entitys.get(position).setLatLng(info.location);
|
|
|
adapter.notifyItemChanged(position);
|
|
|
}
|
|
|
}
|
|
|
@@ -135,49 +183,123 @@ public class MissionPlanActivity extends BaseActivity implements View.OnClickLis
|
|
|
MissionPlanEntity e = entitys.get(i);
|
|
|
if (canSubmit(e)) {
|
|
|
submit(e, i);
|
|
|
+ } else {
|
|
|
+ Crouton.makeText(ct, "不满足提交 item=" + i);
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
//判断是否符合提交 公司名称 公司地址 里程 预计到达时间
|
|
|
private boolean canSubmit(MissionPlanEntity e) {
|
|
|
- if (e == null || StringUtils.isEmpty(e.getCompanyName()) ||
|
|
|
- StringUtils.isEmpty(e.getCompanyAddr()) ||
|
|
|
- e.getLength() != 0 ||
|
|
|
- StringUtils.isEmpty(e.getReckonTime())) return false;
|
|
|
+ if (e == null) return false;
|
|
|
+ else if (StringUtils.isEmpty(e.getCompanyName())) {
|
|
|
+// Crouton.makeText(ct,R.string.add_company_name);
|
|
|
+ return false;
|
|
|
+ } else if (StringUtils.isEmpty(e.getCompanyAddr())) {
|
|
|
+// Crouton.makeText(ct,R.string.add_company_name);
|
|
|
+ return false;
|
|
|
+ } else if (e.getDistances() == 0) {
|
|
|
+ return false;
|
|
|
+ } else if (StringUtils.isEmpty(e.getReckonTime())) {
|
|
|
+ return false;
|
|
|
+ }
|
|
|
return true;
|
|
|
}
|
|
|
|
|
|
+
|
|
|
//提交到服务器
|
|
|
- private void submit(MissionPlanEntity entity, int position) {
|
|
|
+ private void submit(final MissionPlanEntity entity, final int position) {
|
|
|
if (!MyApplication.getInstance().isNetworkActive()) {
|
|
|
ViewUtil.ToastMessage(ct, ct.getResources().getString(R.string.networks_out), Style.holoRedLight, 2000);
|
|
|
return;
|
|
|
}
|
|
|
+ saveOutAddress(entity);
|
|
|
+ progressDialog.show();
|
|
|
+ CodeUtil.getInstance().getId(ct, "MOBILE_OUTPLAN_SEQ", new CodeUtil.OnCodeLinstener() {
|
|
|
+ @Override
|
|
|
+ public void callBack(String code) {
|
|
|
+ try {
|
|
|
+ if (StringUtils.isEmpty(code)) {
|
|
|
+ Crouton.makeText(ct, "获取id错误");
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ final int id = Integer.valueOf(code);
|
|
|
+ CodeUtil.getInstance().getCode(ct, "MOBILE_OUTPLAN", new CodeUtil.OnCodeLinstener() {
|
|
|
+ @Override
|
|
|
+ public void callBack(String code) {
|
|
|
+ if (StringUtils.isEmpty(code)) {
|
|
|
+ Crouton.makeText(ct, "获取编号错误");
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ submit(id, code, entity, position);
|
|
|
+ }
|
|
|
+ });
|
|
|
+ } catch (Exception e) {
|
|
|
+ }
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
+ //保存外勤计划目的地
|
|
|
+ private void saveOutAddress(MissionPlanEntity entity) {
|
|
|
+ if (entity.getLatLng() == null || entity.getLatLng().latitude == 0 || entity.getLatLng().longitude == 0)
|
|
|
+ return;
|
|
|
+ //获取网络数据
|
|
|
+ String url = CommonUtil.getSharedPreferences(ct, "erp_baseurl") + "mobile/saveOutAddress.action";
|
|
|
+ Map<String, Object> param = new HashMap<>();
|
|
|
+ Map<String, Object> formStore = new HashMap<>();
|
|
|
+ param.put("caller", "lp");
|
|
|
+ /***formStore***/
|
|
|
+ formStore.put("Md_id", "");//请求的id MOBILE_OUTPLAN_SEQ
|
|
|
+ formStore.put("Md_company", entity.getCompanyName());//拜访公司
|
|
|
+ formStore.put("Mo_address", entity.getCompanyAddr());//拜访地址
|
|
|
+ formStore.put("Mo_visitcount", entity.getVisitcount());//拜访次数
|
|
|
+ formStore.put("Mo_visittime", entity.getReckonTime());//预计时间
|
|
|
+ formStore.put("mo_longitude", entity.getLatLng().longitude);//经度
|
|
|
+ formStore.put("mo_latitude", entity.getLatLng().latitude);//纬度
|
|
|
+ param.put("formStore", StringUtils.mapToJson(formStore));
|
|
|
+ LinkedHashMap<String, Object> headers = new LinkedHashMap<>();
|
|
|
+ headers.put("Cookie", "JSESSIONID=" + CommonUtil.getSharedPreferences(this, "sessionId"));
|
|
|
+ Message message = new Message();
|
|
|
+ Bundle bundle = new Bundle();
|
|
|
+ ViewUtil.httpSendRequest(ct, url, param, handler, headers, 0x12, message, bundle, "post");
|
|
|
+ }
|
|
|
+
|
|
|
+ //保存外勤计划接口
|
|
|
+ private void submit(int id, String code, MissionPlanEntity entity, int position) {
|
|
|
//获取网络数据
|
|
|
- //TODO 未完成
|
|
|
String url = CommonUtil.getSharedPreferences(ct, "erp_baseurl") + "mobile/saveOutPlan.action";
|
|
|
- final Map<String, Object> param = new HashMap<>();
|
|
|
- final Map<String, Object> formStore = new HashMap<>();
|
|
|
- final Map<String, Object> params = new HashMap<>();
|
|
|
- formStore.put("mp_id","625");//请求的id MOBILE_OUTPLAN_SEQ
|
|
|
- formStore.put("mp_code","625");//请求的id MOBILE_OUTPLAN_SEQ
|
|
|
+ Map<String, Object> param = new HashMap<>();
|
|
|
+ Map<String, Object> formStore = new HashMap<>();
|
|
|
+ Map<String, Object> params = new HashMap<>();
|
|
|
+ String name = CommonUtil.getSharedPreferences(ct, "erp_emname");
|
|
|
+ if (StringUtils.isEmpty(name)) {
|
|
|
+ name = MyApplication.getInstance().mLoginUser.getNickName();
|
|
|
+ }
|
|
|
+ /***formStore***/
|
|
|
+ formStore.put("mp_id", id);//请求的id MOBILE_OUTPLAN_SEQ
|
|
|
+ formStore.put("mp_code", code);//请求的id MOBILE_OUTPLAN_SEQ
|
|
|
formStore.put("mp_visittime", entity.getReckonTime());
|
|
|
- formStore.put("mp_recorder","name");//用户名
|
|
|
- formStore.put("mo_address",entity.getCompanyAddr());//用户名
|
|
|
-
|
|
|
+ formStore.put("mp_recorder", name);//用户名
|
|
|
+ formStore.put("mo_address", MyApplication.getInstance().getBdLocationHelper().getAddress());//当前地址
|
|
|
+ /***params***/
|
|
|
+ params.put("mpd_detno", position + 1);
|
|
|
+ params.put("mpd_id", "");
|
|
|
+ params.put("mpd_mpid", id);
|
|
|
+ params.put("mpd_company", entity.getCompanyName());
|
|
|
+ params.put("mpd_address", entity.getCompanyAddr());
|
|
|
param.put("caller", "lp");
|
|
|
param.put("formStore", StringUtils.mapToJson(formStore));
|
|
|
- param.put("param", "["+StringUtils.mapToJson(params)+"]");
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
+ param.put("param", "[" + StringUtils.mapToJson(params) + "]");
|
|
|
LinkedHashMap<String, Object> headers = new LinkedHashMap<>();
|
|
|
headers.put("Cookie", "JSESSIONID=" + CommonUtil.getSharedPreferences(this, "sessionId"));
|
|
|
- ViewUtil.httpSendRequest(this, url, param, handler, headers, 0x11, null, null, "post");
|
|
|
+ Message message = new Message();
|
|
|
+ Bundle bundle = new Bundle();
|
|
|
+ bundle.putInt("position", position);
|
|
|
+ ViewUtil.httpSendRequest(ct, url, param, handler, headers, 0x11, message, bundle, "post");
|
|
|
}
|
|
|
|
|
|
+
|
|
|
//适配器
|
|
|
public class MissonPlanAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {
|
|
|
@Override
|
|
|
@@ -202,7 +324,8 @@ public class MissionPlanActivity extends BaseActivity implements View.OnClickLis
|
|
|
MissionPlanEntity entity = entitys.get(position);
|
|
|
if (entity == null) return;
|
|
|
holder.item_title_tv.setText("目的地 " + position);
|
|
|
- holder.item_length_tv.setText(getStringByNumber(entity.getLength()));
|
|
|
+ holder.item_delete_tv.setVisibility(entity.getStaatus() != 1 ? View.VISIBLE : View.GONE);
|
|
|
+ holder.item_length_tv.setText(getStringByNumber(entity.getDistances()));
|
|
|
holder.item_reckontime_tv.setText(getStringNotNull(entity.getReckonTime()));
|
|
|
holder.item_realtime_tv.setText(getStringNotNull(entity.getRealTime()));
|
|
|
holder.item_realleave_tv.setText(getStringNotNull(entity.getRealLeave()));
|
|
|
@@ -288,13 +411,12 @@ public class MissionPlanActivity extends BaseActivity implements View.OnClickLis
|
|
|
|
|
|
private String getStringByNumber(float num) {
|
|
|
if (num == 0) return "";
|
|
|
- return String.valueOf(num) + "公里";
|
|
|
+ return String.valueOf(num / 1000) + "公里";
|
|
|
}
|
|
|
|
|
|
private String getStringNotNull(String str) {
|
|
|
if (StringUtils.isEmpty(str)) return "";
|
|
|
return str;
|
|
|
}
|
|
|
-
|
|
|
}
|
|
|
}
|