| | |
| | | package cn.com.basic.face.service;
|
| | |
|
| | | import android.widget.Toast;
|
| | |
|
| | | import org.xutils.http.RequestParams;
|
| | | import org.xutils.x;
|
| | |
|
| | | import java.text.SimpleDateFormat;
|
| | | import java.util.ArrayList;
|
| | | import java.util.Collections;
|
| | | import java.util.Comparator;
|
| | | import java.util.Date;
|
| | | import java.util.List;
|
| | |
|
| | | import cn.com.basic.face.base.BaseApplication;
|
| | | import cn.com.basic.face.base.MainActivity;
|
| | | import cn.com.basic.face.discern.common.BaseCommonCallBack;
|
| | | import cn.com.basic.face.discern.common.CommonVariables;
|
| | | import cn.com.basic.face.discern.common.ResultBean;
|
| | | import cn.com.basic.face.discern.common.SqliteSqlBean;
|
| | | import cn.com.basic.face.discern.entity.PhoneCall;
|
| | | import cn.com.basic.face.discern.query.condition.PhoneCallQueryCondition;
|
| | | import cn.com.basic.face.discern.query.item.CheckInQueryItem;
|
| | | import cn.com.basic.face.discern.query.item.PhoneCallQueryItem;
|
| | | import cn.com.basic.face.fragment.PhoneCallFragment;
|
| | | import cn.com.basic.face.service.sqlite.PhoneCallDao;
|
| | | import cn.com.basic.face.util.AppApi;
|
| | | import cn.com.basic.face.util.CharacterParser;
|
| | | import cn.com.basic.face.util.SqliteSqlUtil;
|
| | |
|
| | | public class PhoneCallMng {
|
| | | public class PhoneCallMng extends BaseMng {
|
| | |
|
| | | private static PhoneCallMng instance = new PhoneCallMng();
|
| | | public static PhoneCallMng getInstance() {
|
| | |
| | | if (!BaseApplication.deviceAvailable) {
|
| | | return;
|
| | | }
|
| | | RequestParams params = new RequestParams(AppApi.BASE_URL +AppApi.Query.PHONE_CALL_QUERY);
|
| | | params.addBodyParameter(PhoneCallQueryCondition.FieldNames.username, searchText);
|
| | | x.http().post(params, new BaseCommonCallBack() {
|
| | | public void success() {
|
| | | List<PhoneCallQueryItem> list = getList(PhoneCallQueryItem.class);
|
| | | sort(list, isSortByDept);
|
| | | List allItems = new ArrayList();
|
| | | String name = "";
|
| | | String prev = "";
|
| | | for (int i = 0; i < list.size(); i++) {
|
| | | PhoneCallQueryItem item = list.get(i);
|
| | | try {
|
| | | if (isSortByDept) {
|
| | | if (item.getCallerDept() != null && item.getCallerDept().length() > 0) {
|
| | | name = CharacterParser.getInstance().getSelling(item.getCallerDept()).substring(0, 1);
|
| | | }
|
| | | } else {
|
| | | if (item.getCaller() != null && item.getCaller().length() > 0) {
|
| | | name = CharacterParser.getInstance().getSelling(item.getCaller()).substring(0, 1);
|
| | | }
|
| | | }
|
| | | } catch (Exception e) {
|
| | | if (BaseApplication.getInstance().networkAvailable()) {
|
| | | RequestParams params = new RequestParams(AppApi.BASE_URL +AppApi.Query.PHONE_CALL_QUERY);
|
| | | params.addBodyParameter(PhoneCallQueryCondition.FieldNames.username, searchText);
|
| | | params.addBodyParameter(CommonVariables.Page.PAGE_SIZE, CommonVariables.Page.DEFAULT_PAGE_SIZE);
|
| | | params.addBodyParameter(CommonVariables.Page.PAGE_NUM, pageNum+"");
|
| | | params.addBodyParameter("deviceCompanyId", BaseApplication.getInstance().getAndroidDevice().getCompanyId());
|
| | | x.http().post(params, new BaseCommonCallBack() {
|
| | | public void success() {
|
| | | findPhoneCallLeftListAfterReturn(resultBean, isSortByDept, append);
|
| | | }
|
| | | });
|
| | | } else {
|
| | | findPhoneCallLeftListAfterReturn(PhoneCallDao.getInstance().findPhoneCallLeftList(searchText, pageNum), isSortByDept, append);
|
| | | }
|
| | | }
|
| | |
|
| | | }
|
| | | if (!name.equals(prev)) {
|
| | | allItems.add(name);
|
| | | }
|
| | | allItems.add(item);
|
| | | prev = name;
|
| | | }
|
| | | if (hasMorePages()) {
|
| | | allItems.add(CommonVariables.Page.hasMorePages);
|
| | | } else {
|
| | | if (getPageNum() > 1) {
|
| | | allItems.add(CommonVariables.Page.reachBottom);
|
| | | } else {
|
| | | if (allItems.size() > 0) {
|
| | | allItems.add(CommonVariables.Page.reachBottom);
|
| | | } else {
|
| | | allItems.add(CommonVariables.Page.noMorePage);
|
| | | }
|
| | | private void findPhoneCallLeftListAfterReturn(ResultBean resultBean, final boolean isSortByDept, final boolean append) {
|
| | | List<PhoneCallQueryItem> list = resultBean.getList(PhoneCallQueryItem.class);
|
| | |
|
| | | if (append) {
|
| | | List prevList = PhoneCallFragment.getInstance().get_fragment_phone_call_left_list_view().getPrevList();
|
| | | if (prevList != null && prevList.size() > 0) {
|
| | | for (int i = 0; i < prevList.size(); i++) {
|
| | | Object item = prevList.get(i);
|
| | | if (item instanceof PhoneCallQueryItem) {
|
| | | list.add((PhoneCallQueryItem)item);
|
| | | }
|
| | | }
|
| | | PhoneCallFragment.getInstance().get_fragment_phone_call_left_list_view().show(isSortByDept, allItems, append);
|
| | | }
|
| | | });
|
| | | }
|
| | | sort(list, isSortByDept);
|
| | | final List itemList = new ArrayList();
|
| | | String name = "";
|
| | | String prev = "";
|
| | | for (int i = 0; i < list.size(); i++) {
|
| | | PhoneCallQueryItem item = list.get(i);
|
| | | try {
|
| | | if (isSortByDept) {
|
| | | if (item.getCalleeDept() != null && item.getCalleeDept().length() > 0) {
|
| | | name = CharacterParser.getInstance().getSelling(item.getCalleeDept()).substring(0, 1);
|
| | | }
|
| | | } else {
|
| | | if (item.getCallee() != null && item.getCallee().length() > 0) {
|
| | | name = CharacterParser.getInstance().getSelling(item.getCallee()).substring(0, 1);
|
| | | }
|
| | | }
|
| | | } catch (Exception e) {
|
| | |
|
| | | }
|
| | | if (!name.equals(prev)) {
|
| | | itemList.add(name);
|
| | | }
|
| | | itemList.add(item);
|
| | | prev = name;
|
| | | }
|
| | | addPageFooter(resultBean.hasMorePages(), resultBean.getPageNum(), itemList);
|
| | | if (BaseApplication.getInstance().networkAvailable()) {
|
| | | PhoneCallFragment.getInstance().get_fragment_phone_call_left_list_view().show(isSortByDept, itemList, append);
|
| | | } else {
|
| | | MainActivity.getInstance().runOnUiThread(new Runnable() {
|
| | | @Override
|
| | | public void run() {
|
| | | PhoneCallFragment.getInstance().get_fragment_phone_call_left_list_view().show(isSortByDept, itemList, append);
|
| | | }
|
| | | });
|
| | | }
|
| | | }
|
| | |
|
| | | private void sort(List<PhoneCallQueryItem> list, final boolean sortedByDept) {
|
| | |
| | | @Override
|
| | | public int compare(PhoneCallQueryItem t1, PhoneCallQueryItem t2) {
|
| | | if (sortedByDept) {
|
| | | String dept1Name = t1.getCallerDept()==null?"":t1.getCallerDept();
|
| | | String dept2Name = t2.getCallerDept()==null?"":t2.getCallerDept();
|
| | | String dept1Name = t1.getCalleeDept()==null?"":t1.getCalleeDept();
|
| | | String dept2Name = t2.getCalleeDept()==null?"":t2.getCalleeDept();
|
| | | if(!dept1Name.equals(dept2Name)) {
|
| | | String dept1Name_a = dept1Name.trim();
|
| | | String dept1Name_b = dept2Name.trim();
|
| | |
| | | return dept1Name_a.compareTo(dept1Name_b);
|
| | | }
|
| | | }
|
| | | String name1 = t1.getCaller()==null?"":t1.getCaller();
|
| | | String name2 = t2.getCaller()==null?"":t2.getCaller();
|
| | | String name1 = t1.getCallee()==null?"":t1.getCallee();
|
| | | String name2 = t2.getCallee()==null?"":t2.getCallee();
|
| | | String dept1Name_a = name1.trim();
|
| | | String dept1Name_b = name2.trim();
|
| | | if (dept1Name_a.length() > 0 && dept1Name_b.length() > 0) {
|
| | |
| | | });
|
| | | }
|
| | |
|
| | | public void addPhoneCall(CheckInQueryItem visitor, CheckInQueryItem interviewee) {
|
| | | if (visitor == null) {
|
| | | Toast.makeText(MainActivity.getInstance(), "请先选择来访人", Toast.LENGTH_SHORT).show();
|
| | | return;
|
| | | }
|
| | | if (interviewee == null) {
|
| | | Toast.makeText(MainActivity.getInstance(), "请先选择被访人", Toast.LENGTH_SHORT).show();
|
| | | return;
|
| | | }
|
| | | if (BaseApplication.getInstance().networkAvailable()) {
|
| | | Toast.makeText(MainActivity.getInstance(), "已添加到呼叫记录", Toast.LENGTH_SHORT).show();
|
| | | SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
| | | RequestParams params = new RequestParams(AppApi.BASE_URL +AppApi.PHONE_CALL_ADD);
|
| | | params.addBodyParameter(PhoneCall.FieldNames.date, sdf.format(new Date()));
|
| | | params.addBodyParameter(PhoneCall.FieldNames.calleeId, interviewee.getRegisterId());
|
| | | params.addBodyParameter(PhoneCall.FieldNames.deviceId, BaseApplication.getInstance().getAndroidDevice().getDeviceId());
|
| | | params.addBodyParameter(PhoneCall.FieldNames.callerId, visitor.getRegisterId());
|
| | | params.addBodyParameter("deviceCompanyId", BaseApplication.getInstance().getAndroidDevice().getCompanyId());
|
| | | x.http().post(params, new BaseCommonCallBack() {
|
| | | public void success() {
|
| | | SqliteSqlUtil.insert(getExtraList(SqliteSqlBean.class));
|
| | | }
|
| | | });
|
| | | } else {
|
| | | PhoneCallDao.getInstance().addPhoneCall(visitor, interviewee);
|
| | | }
|
| | | }
|
| | |
|
| | | }
|