|
|
@@ -1,41 +1,562 @@
|
|
|
package com.xzjmyk.pm.activity.ui.erp.fragment;
|
|
|
|
|
|
+import android.content.BroadcastReceiver;
|
|
|
+import android.content.Context;
|
|
|
+import android.content.Intent;
|
|
|
+import android.content.IntentFilter;
|
|
|
import android.os.Bundle;
|
|
|
+import android.os.Handler;
|
|
|
+import android.os.Message;
|
|
|
+import android.text.Editable;
|
|
|
+import android.text.TextUtils;
|
|
|
+import android.text.TextWatcher;
|
|
|
+import android.view.LayoutInflater;
|
|
|
+import android.view.Menu;
|
|
|
+import android.view.MenuInflater;
|
|
|
+import android.view.MenuItem;
|
|
|
import android.view.View;
|
|
|
+import android.widget.AdapterView;
|
|
|
+import android.widget.ListView;
|
|
|
+import android.widget.TextView;
|
|
|
|
|
|
+import com.alibaba.fastjson.JSON;
|
|
|
+import com.alibaba.fastjson.JSONObject;
|
|
|
+import com.handmark.pulltorefresh.library.PullToRefreshBase;
|
|
|
+import com.handmark.pulltorefresh.library.PullToRefreshListView;
|
|
|
import com.lidroid.xutils.ViewUtils;
|
|
|
+import com.lidroid.xutils.view.annotation.ViewInject;
|
|
|
+import com.xzjmyk.pm.activity.AppConstant;
|
|
|
+import com.xzjmyk.pm.activity.MyApplication;
|
|
|
import com.xzjmyk.pm.activity.R;
|
|
|
+import com.xzjmyk.pm.activity.adapter.FriendSortAdapter;
|
|
|
+import com.xzjmyk.pm.activity.bean.Friend;
|
|
|
+import com.xzjmyk.pm.activity.sortlist.BaseComparator;
|
|
|
+import com.xzjmyk.pm.activity.sortlist.BaseSortModel;
|
|
|
+import com.xzjmyk.pm.activity.sortlist.PingYinUtil;
|
|
|
+import com.xzjmyk.pm.activity.sortlist.SideBar;
|
|
|
import com.xzjmyk.pm.activity.ui.base.EasyFragment;
|
|
|
+import com.xzjmyk.pm.activity.ui.circle.BasicInfoActivity;
|
|
|
+import com.xzjmyk.pm.activity.ui.erp.activity.CommonFragmentActivity;
|
|
|
+import com.xzjmyk.pm.activity.ui.erp.activity.CompanyContactsActivity;
|
|
|
+import com.xzjmyk.pm.activity.ui.erp.activity.MyFriendActivity;
|
|
|
+import com.xzjmyk.pm.activity.ui.erp.db.DBManager;
|
|
|
+import com.xzjmyk.pm.activity.ui.erp.entity.EmployeesEntity;
|
|
|
+import com.xzjmyk.pm.activity.ui.erp.entity.HrorgsEntity;
|
|
|
+import com.xzjmyk.pm.activity.ui.erp.util.CommonUtil;
|
|
|
+import com.xzjmyk.pm.activity.ui.erp.util.Constants;
|
|
|
+import com.xzjmyk.pm.activity.ui.erp.util.ListUtils;
|
|
|
+import com.xzjmyk.pm.activity.ui.erp.util.StringUtils;
|
|
|
+import com.xzjmyk.pm.activity.ui.erp.view.CustomProgressDialog;
|
|
|
+import com.xzjmyk.pm.activity.ui.message.ChatActivity;
|
|
|
+import com.xzjmyk.pm.activity.ui.message.NewFriendActivity;
|
|
|
+import com.xzjmyk.pm.activity.ui.nearby.UserSearchActivity;
|
|
|
+import com.xzjmyk.pm.activity.ui.tool.ThreadPool;
|
|
|
+import com.xzjmyk.pm.activity.view.ClearEditText;
|
|
|
+
|
|
|
+import java.text.ParseException;
|
|
|
+import java.text.SimpleDateFormat;
|
|
|
+import java.util.ArrayList;
|
|
|
+import java.util.Calendar;
|
|
|
+import java.util.Collections;
|
|
|
+import java.util.Date;
|
|
|
+import java.util.HashMap;
|
|
|
+import java.util.LinkedHashMap;
|
|
|
+import java.util.List;
|
|
|
+import java.util.Map;
|
|
|
|
|
|
|
|
|
/**
|
|
|
* Created by pengminggong on 2016/10/12.
|
|
|
*/
|
|
|
|
|
|
-public class ContactFragment extends EasyFragment {
|
|
|
-// @ViewInject(R.id.sidebar)
|
|
|
-// private SideBar sidebar;
|
|
|
-// @ViewInject(R.id.text_dialog)
|
|
|
-// private TextView text_dialog;
|
|
|
-// @ViewInject(listview)
|
|
|
-// private PullToRefreshListView refreshListView;
|
|
|
-// private ListView listView;
|
|
|
-// private View headerView;
|
|
|
+public class ContactFragment extends EasyFragment implements View.OnClickListener {
|
|
|
+ @ViewInject(R.id.sidebar)
|
|
|
+ private SideBar sidebar;
|
|
|
+ @ViewInject(R.id.text_dialog)
|
|
|
+ private TextView text_dialog;
|
|
|
+ @ViewInject(R.id.pull_refresh_list)
|
|
|
+ private PullToRefreshListView refreshListView;
|
|
|
+
|
|
|
+
|
|
|
+ private FriendSortAdapter adapter;
|
|
|
+ private DBManager manager;
|
|
|
+ private String loginUserId;
|
|
|
+ private List<BaseSortModel<Friend>> showDatas;//显示的数据
|
|
|
+ private List<BaseSortModel<Friend>> allDatas;//获取到的全部数据
|
|
|
+ private BaseComparator comparator;
|
|
|
+ private ClearEditText search_edit;
|
|
|
+ private CustomProgressDialog mcProgressDialog;
|
|
|
+
|
|
|
+ private Handler handler = new Handler() {
|
|
|
+ @Override
|
|
|
+ public void handleMessage(Message msg) {
|
|
|
+ switch (msg.what) {
|
|
|
+ case 0x11:
|
|
|
+ writeData(msg);
|
|
|
+ loadDataInThread();
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ };
|
|
|
+ private IntentFilter inputFilter;
|
|
|
+ private BroadcastReceiver receiver = new BroadcastReceiver() {
|
|
|
+ @Override
|
|
|
+ public void onReceive(Context context, Intent intent) {
|
|
|
+ if ("home".equals(intent.getStringExtra("falg"))) {
|
|
|
+ loadDataInThread();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ };
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void onCreate(Bundle savedInstanceState) {
|
|
|
+ super.onCreate(savedInstanceState);
|
|
|
+ inputFilter = new IntentFilter("com.app.home.update");
|
|
|
+ getActivity().registerReceiver(receiver, inputFilter);
|
|
|
+ setHasOptionsMenu(true);
|
|
|
+ }
|
|
|
|
|
|
@Override
|
|
|
protected int inflateLayoutId() {
|
|
|
- return R.layout.header_fragment_contact;
|
|
|
+ return R.layout.fragment_contact;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void onDestroy() {
|
|
|
+ getActivity().unregisterReceiver(receiver);
|
|
|
+ super.onDestroyView();
|
|
|
+ if (manager != null)
|
|
|
+ manager.closeDB();
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
|
|
|
+ super.onCreateOptionsMenu(menu, inflater);
|
|
|
+ inflater.inflate(R.menu.menu_nearby, menu);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public boolean onOptionsItemSelected(MenuItem item) {
|
|
|
+ if (item.getItemId() == R.id.search) {
|
|
|
+ startActivity(new Intent(getActivity(), UserSearchActivity.class));
|
|
|
+ }
|
|
|
+ return super.onOptionsItemSelected(item);
|
|
|
+
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
protected void onCreateView(Bundle savedInstanceState, boolean createView) {
|
|
|
- ViewUtils.inject(getmRootView());
|
|
|
+ if (createView) {
|
|
|
+ ViewUtils.inject(getmRootView());
|
|
|
+ initView();
|
|
|
+ initEvent();
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
+ private void initEvent() {
|
|
|
+ //侧边栏检索
|
|
|
+ sidebar.setOnTouchingLetterChangedListener(new SideBar.OnTouchingLetterChangedListener() {
|
|
|
+ @Override
|
|
|
+ public void onTouchingLetterChanged(String s) {
|
|
|
+ // 该字母首次出现的位置
|
|
|
+ int position = adapter.getPositionForSection(s.charAt(0));
|
|
|
+ if (position != -1) {
|
|
|
+ int count = refreshListView.getRefreshableView().getHeaderViewsCount();
|
|
|
+ refreshListView.getRefreshableView().setSelection(position + count);
|
|
|
+ }
|
|
|
+ if ("↑".equals(s)) {
|
|
|
+ refreshListView.getRefreshableView().setSelection(1);
|
|
|
+ }
|
|
|
+ }
|
|
|
|
|
|
+ @Override
|
|
|
+ public void onTouchingUp() {
|
|
|
+ }
|
|
|
+ });
|
|
|
+ refreshListView.setOnRefreshListener(new PullToRefreshBase.OnRefreshListener<ListView>() {
|
|
|
+ @Override
|
|
|
+ public void onRefresh(PullToRefreshBase<ListView> refreshView) {
|
|
|
+ loadDataInThread();
|
|
|
+ }
|
|
|
+ });
|
|
|
+ //item点击事件处理
|
|
|
+ refreshListView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
|
|
|
+ @Override
|
|
|
+ public void onItemClick(AdapterView<?> adapterView, View view, int i, long id) {
|
|
|
+ List<BaseSortModel<Friend>> list = adapter.getmSortFriends();
|
|
|
+ if (!ListUtils.isEmpty(list)) {
|
|
|
+ Friend friend = list.get((int) id).getBean();
|
|
|
+ clickFriend(friend);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ });
|
|
|
+ //搜索框处理
|
|
|
+ if (search_edit == null) return;
|
|
|
+ search_edit.addTextChangedListener(new TextWatcher() {
|
|
|
+ @Override
|
|
|
+ public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) {
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void onTextChanged(CharSequence charSequence, int i, int i1, int i2) {
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void afterTextChanged(Editable editable) {
|
|
|
+ String str = editable == null ? "" : editable.toString();
|
|
|
+ upDataBySearch(str);
|
|
|
+ adapter.setData(showDatas);
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
|
|
|
- public void setHeaderView(View headerView) {
|
|
|
-// listView.addHeaderView(headerView);
|
|
|
|
|
|
+ private void initView() {
|
|
|
+ showDatas = new ArrayList<>();
|
|
|
+ allDatas = new ArrayList<>();
|
|
|
+ mcProgressDialog = CustomProgressDialog.createDialog(ct);
|
|
|
+ comparator = new BaseComparator();
|
|
|
+ loginUserId = MyApplication.getInstance().mLoginUser.getUserId();
|
|
|
+ setHeaderView();
|
|
|
+ refreshListView.setMode(PullToRefreshBase.Mode.PULL_FROM_START);
|
|
|
+ sidebar.setTextView(text_dialog);
|
|
|
+ adapter = new FriendSortAdapter(ct, showDatas);
|
|
|
+ refreshListView.getRefreshableView().setAdapter(adapter);
|
|
|
+ loadDataInThread();
|
|
|
+ mcProgressDialog.show();
|
|
|
+ }
|
|
|
+
|
|
|
+ /*设置头文件*/
|
|
|
+ private void setHeaderView() {
|
|
|
+ View headview = LayoutInflater.from(ct).inflate(R.layout.header_fragment_contact, null);
|
|
|
+ refreshListView.getRefreshableView().addHeaderView(headview);
|
|
|
+ search_edit = (ClearEditText) headview.findViewById(R.id.search_edit);
|
|
|
+ headview.findViewById(R.id.company).setOnClickListener(this);//企业结构
|
|
|
+ headview.findViewById(R.id.group).setOnClickListener(this);//商务群
|
|
|
+ headview.findViewById(R.id.uu_friend).setOnClickListener(this);//我的好友
|
|
|
+ headview.findViewById(R.id.peculiar_tv).setOnClickListener(this);//我的好友
|
|
|
+ }
|
|
|
+
|
|
|
+ private void clickFriend(Friend friend) {
|
|
|
+ Intent intent = null;
|
|
|
+ if (friend.getUserId().equals(Friend.ID_NEW_FRIEND_MESSAGE)) {// 新朋友消息
|
|
|
+ intent = new Intent(getActivity(), NewFriendActivity.class);
|
|
|
+ } else if (friend.getUserId().equals(Friend.ID_SYSTEM_MESSAGE)) {// 新朋友消息
|
|
|
+ intent = new Intent(getActivity(), ChatActivity.class);
|
|
|
+ intent.putExtra(ChatActivity.FRIEND, friend);
|
|
|
+ } else {
|
|
|
+ intent = new Intent(getActivity(), BasicInfoActivity.class);
|
|
|
+ intent.putExtra(AppConstant.EXTRA_NICK_CODE, friend.getPhone());
|
|
|
+ intent.putExtra(AppConstant.EXTRA_USER_ID, friend.getUserId());
|
|
|
+ intent.putExtra(AppConstant.EXTRA_NICK_NAME, friend.getNickName());
|
|
|
+ intent.putExtra("friend", friend);
|
|
|
+ }
|
|
|
+ startActivity(intent);
|
|
|
+ }
|
|
|
+
|
|
|
+ //将企业架构写入数据库
|
|
|
+ public void writeData(android.os.Message msg) {
|
|
|
+ String result = msg.getData().getString("result");
|
|
|
+ JSONObject jsonobject = JSON.parseObject(result);
|
|
|
+ String server_time = jsonobject.getString("sysdate");//服务器系统时间
|
|
|
+ //实体类
|
|
|
+ List<HrorgsEntity> hrorgsEntities = JSON.parseArray(jsonobject.getString("hrorgs"), HrorgsEntity.class);
|
|
|
+ List<EmployeesEntity> employeesEntities = JSON.parseArray(jsonobject.getString("employees"), EmployeesEntity.class);
|
|
|
+ String master = CommonUtil.getSharedPreferences(ct, "erp_master");
|
|
|
+ HrorgsEntity hrEntity = manager.select_getRootData(new String[]{master}, "whichsys=?");
|
|
|
+ boolean isFristLoad = true;//是否第一次加载
|
|
|
+ if (hrEntity != null) {
|
|
|
+ isFristLoad = false;
|
|
|
+ }
|
|
|
+ if (!hrorgsEntities.isEmpty() || !employeesEntities.isEmpty()) {
|
|
|
+ insertDataSqlite(isFristLoad, hrorgsEntities, employeesEntities,
|
|
|
+ server_time);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 将数据插入数据库
|
|
|
+ *
|
|
|
+ * @param isFristLoad 是否第一次插入数据
|
|
|
+ * @param hrorgsEntities
|
|
|
+ * @param employeesEntities
|
|
|
+ * @param servertime
|
|
|
+ */
|
|
|
+ public void insertDataSqlite(boolean isFristLoad, List<HrorgsEntity> hrorgsEntities, List<EmployeesEntity> employeesEntities
|
|
|
+ , String servertime) {
|
|
|
+ if (isFristLoad) {
|
|
|
+ manager.saveHrogrs(hrorgsEntities);
|
|
|
+ manager.saveEmployees(employeesEntities);
|
|
|
+ } else {
|
|
|
+ synSqliteDataforServer(hrorgsEntities, employeesEntities);
|
|
|
+ }
|
|
|
+ manager.deleteHrogrsAndEmployees();
|
|
|
+ Map<String, Object> dateCaches = new HashMap<String, Object>();
|
|
|
+ String time = dateMinute(servertime);
|
|
|
+ dateCaches.put("ed_lastdate", time);
|
|
|
+ dateCaches.put("ed_kind", "通讯录");
|
|
|
+ dateCaches.put("ed_company", CommonUtil.getSharedPreferences(ct, "erp_commpany"));
|
|
|
+ dateCaches.put("ed_whichsys", CommonUtil.getSharedPreferences(ct, "erp_master"));
|
|
|
+ String db_time = manager.select_getCacheTime(new String[]{}, "ed_company=? and ed_whichsys=?");
|
|
|
+ if (db_time != null) {
|
|
|
+ manager.updateCacheTime(dateCaches);
|
|
|
+ } else {
|
|
|
+ manager.saveCacheTime(dateCaches);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * @功能:时间减法
|
|
|
+ */
|
|
|
+ private String dateMinute(String datetime) {
|
|
|
+ String str = datetime;
|
|
|
+ SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
|
|
+ Date date = new Date();
|
|
|
+ try {
|
|
|
+ date = sdf.parse(str);
|
|
|
+ } catch (ParseException e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ System.out.println(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(date));
|
|
|
+ Calendar calendar = Calendar.getInstance();
|
|
|
+ calendar.setTime(date);
|
|
|
+ calendar.set(Calendar.MINUTE, calendar.get(Calendar.MINUTE) - 2);
|
|
|
+ System.out.println(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(calendar.getTime()));
|
|
|
+ return new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(calendar.getTime());
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * @功能:同步数据
|
|
|
+ */
|
|
|
+ private void synSqliteDataforServer(List<HrorgsEntity> hrorgsEntities, List<EmployeesEntity> employeesEntities) {
|
|
|
+ if (!hrorgsEntities.isEmpty()) {
|
|
|
+ List<HrorgsEntity> insertHrorgsList = new ArrayList<HrorgsEntity>();
|
|
|
+ List<HrorgsEntity> updateHrorgsList = new ArrayList<HrorgsEntity>();
|
|
|
+ for (int i = 0; i < hrorgsEntities.size(); i++) {
|
|
|
+ HrorgsEntity entity = hrorgsEntities.get(i);
|
|
|
+ String or_code = entity.getOr_code();
|
|
|
+ String whichsys = entity.getWhichsys();
|
|
|
+ if ("UPDATE".equals(entity.getFlag())) {
|
|
|
+ HrorgsEntity hentity = manager.select_getRootData(new String[]{or_code, whichsys}, "or_code=? and whichsys=?");
|
|
|
+ if (hentity != null) {
|
|
|
+ updateHrorgsList.add(entity);
|
|
|
+ } else {
|
|
|
+ insertHrorgsList.add(entity);
|
|
|
+ }
|
|
|
+ } else if ("INSERT".equals(entity.getFlag())) {
|
|
|
+ insertHrorgsList.add(entity);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ manager.saveHrogrs(insertHrorgsList);
|
|
|
+ manager.updateHrogrs(updateHrorgsList);
|
|
|
+ }
|
|
|
+ if (!employeesEntities.isEmpty()) {
|
|
|
+ List<EmployeesEntity> insertEmployeesList = new ArrayList<>();
|
|
|
+ List<EmployeesEntity> updateEmployeesList = new ArrayList<EmployeesEntity>();
|
|
|
+ for (int i = 0; i < employeesEntities.size(); i++) {
|
|
|
+ EmployeesEntity eEntity = employeesEntities.get(i);
|
|
|
+ String em_code = eEntity.getEM_CODE();
|
|
|
+ String whichsys = eEntity.getWHICHSYS();
|
|
|
+ if (com.xzjmyk.pm.activity.util.StringUtils.isEmpty(em_code)) return;
|
|
|
+ if ("UPDATE".equals(eEntity.getFLAG())) {
|
|
|
+ List<EmployeesEntity> tempEntity = manager.select_getEmployee(new String[]{em_code, whichsys}, "em_code=? and whichsys=?");
|
|
|
+ if (tempEntity.isEmpty()) {
|
|
|
+ insertEmployeesList.add(eEntity);
|
|
|
+ } else {
|
|
|
+ updateEmployeesList.add(eEntity);
|
|
|
+ }
|
|
|
+ } else if ("INSERT".equals(eEntity.getFLAG())) {
|
|
|
+ insertEmployeesList.add(eEntity);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ manager.saveEmployees(insertEmployeesList);
|
|
|
+ manager.updateEmployees(updateEmployeesList);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /*开启线程获取数据*/
|
|
|
+ private void loadDataInThread() {
|
|
|
+ ThreadPool.getThreadPool().addTask(new Runnable() {
|
|
|
+ @Override
|
|
|
+ public void run() {
|
|
|
+ List<BaseSortModel<Friend>> chche = getFriendsByErpDB();//通过数据库获取数据
|
|
|
+ if (ListUtils.isEmpty(chche))
|
|
|
+ //TODO 通过网络获取数据
|
|
|
+ handler.post(new Runnable() {
|
|
|
+ @Override
|
|
|
+ public void run() {
|
|
|
+ loadFriendsByNet();
|
|
|
+ }
|
|
|
+ });
|
|
|
+ else
|
|
|
+ loadDataInThread(chche);
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
+ /*在线程中处理数据
|
|
|
+ * 1.数据库获取
|
|
|
+ * 2.网络获取
|
|
|
+ * */
|
|
|
+ private void loadDataInThread(List<BaseSortModel<Friend>> chche) {
|
|
|
+ allDatas = chche;
|
|
|
+
|
|
|
+ if (search_edit == null || TextUtils.isEmpty(search_edit.getText())) {//没有搜索数据
|
|
|
+ showDatas = chche;
|
|
|
+ } else {//
|
|
|
+ String str = search_edit.getText().toString();
|
|
|
+ upDataBySearch(str);
|
|
|
+ }
|
|
|
+ handler.post(new Runnable() {
|
|
|
+ @Override
|
|
|
+ public void run() {
|
|
|
+ adapter.setData(showDatas);
|
|
|
+ refreshListView.onRefreshComplete();
|
|
|
+ if (mcProgressDialog.isShowing())
|
|
|
+ mcProgressDialog.dismiss();
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 当搜索框有字时候获取
|
|
|
+ *
|
|
|
+ * @param str 搜索框文字
|
|
|
+ */
|
|
|
+ private void upDataBySearch(String str) {
|
|
|
+ if (ListUtils.isEmpty(allDatas)) return;
|
|
|
+ showDatas = new ArrayList<>();
|
|
|
+ for (BaseSortModel<Friend> e : allDatas) {
|
|
|
+ String text = e.getBean().getShowName() + e.getBean().getDepart() + e.getBean().getPosition() + e.getBean().getPhone();
|
|
|
+ if (StringUtils.isInclude(text, str)) {
|
|
|
+ showDatas.add(e);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 通过数据库获取数据显示
|
|
|
+ *
|
|
|
+ * @return 查询到数据列表
|
|
|
+ */
|
|
|
+ private List<BaseSortModel<Friend>> getFriendsByErpDB() {
|
|
|
+ if (manager == null)
|
|
|
+ manager = new DBManager(MyApplication.getInstance());
|
|
|
+ String master = CommonUtil.getSharedPreferences(ct, "erp_master");
|
|
|
+ List<EmployeesEntity> emList = null;
|
|
|
+ if (!StringUtils.isEmpty(master)) {
|
|
|
+ emList = manager.select_getEmployee(new String[]{master}, "whichsys=?");
|
|
|
+ }
|
|
|
+ if (ListUtils.isEmpty(emList)) return null;
|
|
|
+ List<BaseSortModel<Friend>> list = new ArrayList<>();
|
|
|
+ for (EmployeesEntity e : emList) {
|
|
|
+ if (e.getEm_IMID() != 0 && String.valueOf(e.getEm_IMID()).equals(loginUserId))
|
|
|
+ continue;
|
|
|
+ list.add(getFriendByErp(e));
|
|
|
+ }
|
|
|
+
|
|
|
+ if (ListUtils.isEmpty(list)) {
|
|
|
+ list = new ArrayList<>();
|
|
|
+ } else {
|
|
|
+ Collections.sort(list, comparator);
|
|
|
+ }
|
|
|
+ return list;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 将Rep转化为Friend对象
|
|
|
+ *
|
|
|
+ * @param e 员工对象
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ private BaseSortModel<Friend> getFriendByErp(EmployeesEntity e) {
|
|
|
+ Friend friend = new Friend();
|
|
|
+ friend.setTimeCreate((int) (System.currentTimeMillis() / 1000));
|
|
|
+ friend.setOwnerId(loginUserId);
|
|
|
+ friend.setUserId(String.valueOf(e.getEm_IMID()));
|
|
|
+ friend.setNickName(e.getEM_NAME());
|
|
|
+ friend.setPhone(e.getEM_MOBILE());
|
|
|
+ friend.setDepart(e.getEM_DEPART());
|
|
|
+ friend.setPosition(e.getEM_POSITION());
|
|
|
+ friend.setEmCode(e.getEM_CODE());
|
|
|
+ friend.setPrivacy(e.getEM_EMAIL());
|
|
|
+ friend.setCompanyId(0);
|
|
|
+ friend.setRoomFlag(0);// 0朋友 1群组
|
|
|
+ friend.setStatus(Friend.STATUS_UNKNOW);
|
|
|
+ BaseSortModel<Friend> mode = new BaseSortModel<>();
|
|
|
+ mode.setBean(friend);
|
|
|
+ setSortCondition(mode);
|
|
|
+ return mode;
|
|
|
+ }
|
|
|
+
|
|
|
+ /*设置当前mode所在的索引值*/
|
|
|
+ private final void setSortCondition(BaseSortModel<Friend> mode) {
|
|
|
+ Friend friend = mode.getBean();
|
|
|
+ if (friend == null) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ String name = friend.getShowName();
|
|
|
+ String wholeSpell = PingYinUtil.getPingYin(name);
|
|
|
+ if (!TextUtils.isEmpty(wholeSpell)) {
|
|
|
+ String firstLetter = Character.toString(wholeSpell.charAt(0));
|
|
|
+ sidebar.addExist(firstLetter);
|
|
|
+ mode.setWholeSpell(wholeSpell);
|
|
|
+ mode.setFirstLetter(firstLetter);
|
|
|
+ mode.setSimpleSpell(PingYinUtil.converterToFirstSpell(name));
|
|
|
+ } else {// 如果全拼为空,理论上是一种错误情况,因为这代表着昵称为空
|
|
|
+ mode.setWholeSpell("#");
|
|
|
+ mode.setFirstLetter("#");
|
|
|
+ mode.setSimpleSpell("#");
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 通过网络获取数据
|
|
|
+ *
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ public void loadFriendsByNet() {
|
|
|
+ String master = CommonUtil.getSharedPreferences(ct, "erp_master");
|
|
|
+ String commpany = CommonUtil.getSharedPreferences(ct, "erp_commpany");
|
|
|
+ if (StringUtils.isEmpty(master)) return;
|
|
|
+ String date = manager.select_getCacheTime(
|
|
|
+ new String[]{commpany, master},
|
|
|
+ "ed_company=? and ed_whichsys=?");
|
|
|
+ String url = Constants.getAppBaseUrl(ct) + "mobile/getAllHrorgEmps.action";
|
|
|
+ final Map<String, Object> param = new HashMap<>();
|
|
|
+ param.put("master", master);
|
|
|
+ if (date == null) {
|
|
|
+ date = "";
|
|
|
+ }
|
|
|
+ param.put("lastdate", date);
|
|
|
+ LinkedHashMap<String, Object> headers = new LinkedHashMap<>();
|
|
|
+ headers.put("Cookie", "JSESSIONID=" + CommonUtil.getSharedPreferences(ct, "sessionId"));
|
|
|
+ com.xzjmyk.pm.activity.ui.erp.net.
|
|
|
+ ViewUtil.httpSendRequest(ct, url, param, handler, headers, 0x11, null, null, "get");
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void onClick(View view) {
|
|
|
+ Intent intent = null;
|
|
|
+ switch (view.getId()) {
|
|
|
+ case R.id.company://企业架构
|
|
|
+ intent = new Intent(ct, CompanyContactsActivity.class);
|
|
|
+ ct.startActivity(intent);
|
|
|
+ break;
|
|
|
+ case R.id.group://群
|
|
|
+ intent = new Intent(ct, CommonFragmentActivity.class);
|
|
|
+ intent.putExtra("type", Constants.TYPE_CHAT_All);
|
|
|
+ ct.startActivity(intent);
|
|
|
+ break;
|
|
|
+ case R.id.uu_friend://uu好友
|
|
|
+ intent = new Intent(ct, MyFriendActivity.class);
|
|
|
+ ct.startActivity(intent);
|
|
|
+ break;
|
|
|
+ case R.id.peculiar_tv://常用联系人
|
|
|
+ intent = new Intent(ct, MyFriendActivity.class);
|
|
|
+ intent.putExtra("isPeculiar", true);
|
|
|
+ ct.startActivity(intent);
|
|
|
+ break;
|
|
|
+ }
|
|
|
}
|
|
|
}
|