package cn.com.basic.face.service;
|
|
import android.widget.Toast;
|
|
import cn.com.basic.face.base.BaseApplication;
|
import cn.com.basic.face.discern.common.CommonVariables;
|
import cn.com.basic.face.discern.query.condition.CheckInQueryCondition;
|
import cn.com.basic.face.fragment.CheckInFragment;
|
import cn.com.basic.face.util.AppApi;
|
|
import org.xutils.http.RequestParams;
|
import org.xutils.x;
|
|
import java.util.ArrayList;
|
import java.util.Collections;
|
import java.util.Comparator;
|
import java.util.List;
|
|
import cn.com.basic.face.discern.common.BaseCommonCallBack;
|
import cn.com.basic.face.discern.query.item.CheckInQueryItem;
|
import cn.com.basic.face.util.CharacterParser;
|
|
public class CheckInMng extends BaseMng {
|
|
public static CheckInMng instance = new CheckInMng();
|
|
public static CheckInMng getInstance() {
|
return instance;
|
}
|
|
public void add(RequestParams params, final String visitReasonId) {
|
if (!BaseApplication.deviceAvailable) {
|
return;
|
}
|
params.setUri(AppApi.BASE_URL +AppApi.VISIT_ADD);
|
x.http().post(params, new BaseCommonCallBack() {
|
@Override
|
public void success() {
|
Toast.makeText(BaseApplication.getInstance(),"添加成功", Toast.LENGTH_SHORT).show();
|
CheckInFragment.getInstance().resetForm();
|
if (visitReasonId == null || "".equals(visitReasonId)) {
|
DictionaryMng.getInstance().loadVisitReasonList();
|
}
|
}
|
});
|
}
|
|
public void findCheckInLeftList(final boolean isVisitorList, final boolean isSortByDept, String searchText, final int pageNum, final boolean append) {
|
if (!BaseApplication.deviceAvailable) {
|
return;
|
}
|
RequestParams params = new RequestParams(AppApi.BASE_URL +AppApi.Query.CHECK_IN_QUERY);
|
String deviceCompanyId = BaseApplication.getInstance().getAndroidDevice().getCompanyId();
|
if (isVisitorList) {
|
params.addBodyParameter(CheckInQueryCondition.FieldNames.visitorCompanyId, deviceCompanyId);
|
} else {
|
params.addBodyParameter(CheckInQueryCondition.FieldNames.employeeCompanyId, deviceCompanyId);
|
}
|
params.addBodyParameter(CheckInQueryCondition.FieldNames.username, searchText);
|
params.addBodyParameter(CommonVariables.Page.PAGE_NUM, pageNum+"");
|
params.addBodyParameter(CommonVariables.Page.PAGE_SIZE, CommonVariables.Page.DEFAULT_PAGE_SIZE);
|
x.http().post(params, new BaseCommonCallBack() {
|
public void success() {
|
List<CheckInQueryItem> list = getList(CheckInQueryItem.class);
|
|
List prevList = null;
|
if (append) {
|
if (isVisitorList) {
|
prevList = CheckInFragment.getInstance().get_fragment_check_in_left_visitor().getPrevList();
|
} else {
|
prevList = CheckInFragment.getInstance().get_fragment_check_in_left_interviewee().getPrevList();
|
}
|
for (int i = 0; i < prevList.size(); i++) {
|
Object item = prevList.get(i);
|
if (item instanceof CheckInQueryItem) {
|
list.add(0, (CheckInQueryItem) item);
|
}
|
}
|
}
|
|
sort(list, isSortByDept);
|
List itemList = new ArrayList();
|
String name = "";
|
String prev = "";
|
for (int i = 0; i < list.size(); i++) {
|
CheckInQueryItem item = list.get(i);
|
if (isSortByDept) {
|
if (item.getDeptName() != null && item.getDeptName().length() > 0) {
|
name = CharacterParser.getInstance().getSelling(item.getDeptName()).substring(0, 1);
|
}
|
} else {
|
if (item.getUsername() != null && item.getUsername().length() > 0)
|
name = CharacterParser.getInstance().getSelling(item.getUsername()).substring(0, 1);
|
}
|
if (!name.equals(prev)) {
|
itemList.add(name);
|
}
|
itemList.add(item);
|
prev = name;
|
}
|
addPageFooter(hasMorePages(), getPageNum(), itemList);
|
if (isVisitorList) {
|
CheckInFragment.getInstance().get_fragment_check_in_left_visitor().show(itemList);
|
} else {
|
CheckInFragment.getInstance().get_fragment_check_in_left_interviewee().show(itemList, isSortByDept, append);
|
}
|
}
|
});
|
}
|
|
private void sort(List<CheckInQueryItem> list, final boolean sortedByDept) {
|
if (!BaseApplication.deviceAvailable) {
|
return;
|
}
|
Collections.sort(list, new Comparator<CheckInQueryItem>() {
|
@Override
|
public int compare(CheckInQueryItem item1, CheckInQueryItem item2) {
|
if (sortedByDept) {
|
String dept1Name = item1.getDeptName()==null?"":item1.getDeptName();
|
String dept2Name = item2.getDeptName()==null?"":item2.getDeptName();
|
if(!dept1Name.equals(dept2Name)) {
|
String dept1Name_a = dept1Name.trim();
|
String dept1Name_b = dept2Name.trim();
|
if (dept1Name_a.length() > 0 && dept1Name_b.length() > 0) {
|
dept1Name_a = CharacterParser.getInstance().getSelling(dept1Name).toLowerCase();
|
dept1Name_b = CharacterParser.getInstance().getSelling(dept2Name).toLowerCase();
|
}
|
return dept1Name_a.compareTo(dept1Name_b);
|
}
|
}
|
String username1 = item1.getUsername()==null?"":item1.getUsername();
|
String username2 = item2.getUsername()==null?"":item2.getUsername();
|
String dept1Name_a = username1.trim();
|
String dept1Name_b = username2.trim();
|
if (dept1Name_a.length() > 0 && dept1Name_b.length() > 0) {
|
dept1Name_a = CharacterParser.getInstance().getSelling(username1).toLowerCase();
|
dept1Name_b = CharacterParser.getInstance().getSelling(username2).toLowerCase();
|
}
|
return dept1Name_a.compareTo(dept1Name_b);
|
}
|
});
|
}
|
|
|
}
|