| | |
| | | package cn.com.basic.face.service;
|
| | |
|
| | | import android.database.Cursor;
|
| | | import android.database.sqlite.SQLiteDatabase;
|
| | | import android.widget.Toast;
|
| | |
|
| | | import cn.com.basic.face.base.BaseApplication;
|
| | | import cn.com.basic.face.base.MainActivity;
|
| | | 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.Visit;
|
| | | import cn.com.basic.face.discern.entity.VisitDetail;
|
| | | import cn.com.basic.face.discern.query.condition.AttendanceQueryCondition;
|
| | | import cn.com.basic.face.discern.query.condition.CheckInQueryCondition;
|
| | | import cn.com.basic.face.discern.query.item.OfflineAttenderRegisterItem;
|
| | | import cn.com.basic.face.discern.query.item.OfflineVisitItem;
|
| | | import cn.com.basic.face.fragment.CheckInFragment;
|
| | | import cn.com.basic.face.service.sqlite.CheckInDao;
|
| | | import cn.com.basic.face.service.sqlite.DictionaryDao;
|
| | | import cn.com.basic.face.util.AppApi;
|
| | |
|
| | | 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.discern.common.BaseCommonCallBack;
|
| | | import cn.com.basic.face.discern.query.condition.VisitorQueryCondition;
|
| | | import cn.com.basic.face.discern.query.item.CheckInQueryItem;
|
| | | import cn.com.basic.face.util.CharacterParser;
|
| | | import cn.com.basic.face.util.DateUtil;
|
| | | import cn.com.basic.face.util.SqliteSqlUtil;
|
| | |
|
| | | public class CheckInMng {
|
| | | //登记
|
| | | public class CheckInMng extends BaseMng {
|
| | |
|
| | | public static CheckInMng instance = new CheckInMng();
|
| | |
|
| | |
| | | return instance;
|
| | | }
|
| | |
|
| | | public void add(RequestParams params) {
|
| | | params.setUri(AppApi.BASE_URL +AppApi.CHECK_IN_ADD);
|
| | | x.http().post(params, new BaseCommonCallBack() {
|
| | | @Override
|
| | | public void success() {
|
| | | Toast.makeText(BaseApplication.getInstance(),"添加成功", Toast.LENGTH_SHORT).show();
|
| | | }
|
| | | });
|
| | | public void add(RequestParams params, final String visitReasonId, OfflineVisitItem offlineVisitItem) {
|
| | | if (!BaseApplication.deviceAvailable) {
|
| | | return;
|
| | | }
|
| | | if (BaseApplication.getInstance().networkAvailable()) {
|
| | | params.setUri(AppApi.BASE_URL +AppApi.VISIT_ADD);
|
| | | params.addBodyParameter(Visit.FieldNames.deviceCompanyId, BaseApplication.getInstance().getAndroidDevice().getCompanyId());
|
| | | x.http().post(params, new BaseCommonCallBack() {
|
| | | @Override
|
| | | public void success() {
|
| | | SqliteSqlUtil.insert(getExtraList(SqliteSqlBean.class));
|
| | | Toast.makeText(BaseApplication.getInstance(),"添加成功", Toast.LENGTH_SHORT).show();
|
| | | CheckInFragment.getInstance().resetForm();
|
| | | if (visitReasonId == null || "".equals(visitReasonId)) {
|
| | | DictionaryMng.getInstance().loadVisitReasonList();
|
| | | }
|
| | | }
|
| | | });
|
| | | } else {
|
| | | final long result = CheckInDao.getInstance().addOfflineVisit(offlineVisitItem);
|
| | |
|
| | | MainActivity.getInstance().runOnUiThread(new Runnable() {
|
| | | @Override
|
| | | public void run() {
|
| | | if (result > 0) {
|
| | | Toast.makeText(BaseApplication.getInstance(), "添加成功", Toast.LENGTH_SHORT).show();
|
| | | if (visitReasonId == null || "".equals(visitReasonId)) {
|
| | | DictionaryMng.getInstance().loadVisitReasonList();
|
| | | }
|
| | | CheckInFragment.getInstance().resetForm();
|
| | | } else {
|
| | | Toast.makeText(BaseApplication.getInstance(), "添加失败", Toast.LENGTH_SHORT).show();
|
| | | }
|
| | | }
|
| | | });
|
| | | }
|
| | | }
|
| | |
|
| | | public void findCheckInLeftList(final boolean isVisitorList, final boolean isSortByDept, String searchText) {
|
| | | RequestParams params = new RequestParams(AppApi.BASE_URL +AppApi.Query.REGISTER_QUERY);
|
| | | if (isVisitorList) {
|
| | | params.addBodyParameter(VisitorQueryCondition.FieldNames.notCompanyId, BaseApplication.getInstance().getPlace().getCompanyId());
|
| | | } else {
|
| | | params.addBodyParameter(VisitorQueryCondition.FieldNames.companyId, BaseApplication.getInstance().getPlace().getCompanyId());
|
| | | public void findCheckInLeftList(final boolean isVisitorList, final boolean isSortByDept, String searchText, final int pageNum, final boolean append) {
|
| | | if (!BaseApplication.deviceAvailable) {
|
| | | return;
|
| | | }
|
| | | params.addBodyParameter(VisitorQueryCondition.FieldNames.name, searchText);
|
| | | x.http().post(params, new BaseCommonCallBack() {
|
| | | public void success() {
|
| | | List<CheckInQueryItem> list = getList(CheckInQueryItem.class);
|
| | | sort(list, isSortByDept);
|
| | | List allItems = new ArrayList();
|
| | | String name = "";
|
| | | String prev = "";
|
| | | for (int i = 0; i < list.size(); i++) {
|
| | | CheckInQueryItem item = list.get(i);
|
| | | if (isSortByDept) {
|
| | | name = CharacterParser.getInstance().getSelling(item.getDeptName()).substring(0, 1);
|
| | | } else {
|
| | | name = CharacterParser.getInstance().getSelling(item.getUsername()).substring(0, 1);
|
| | | }
|
| | | if (!name.equals(prev)) {
|
| | | allItems.add(name);
|
| | | }
|
| | | allItems.add(item);
|
| | | prev = name;
|
| | | if (BaseApplication.getInstance().networkAvailable()) {
|
| | | 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);
|
| | | params.addBodyParameter("deviceCompanyId", BaseApplication.getInstance().getAndroidDevice().getCompanyId());
|
| | | x.http().post(params, new BaseCommonCallBack() {
|
| | | public void success() {
|
| | | findCheckInLeftListAfterReturn(resultBean, isVisitorList, isSortByDept, append);
|
| | | }
|
| | | if (isVisitorList) {
|
| | | CheckInFragment.getInstance().get_fragment_check_in_left_visitor().show(allItems);
|
| | | } else {
|
| | | CheckInFragment.getInstance().get_fragment_check_in_left_interviewee().show(allItems);
|
| | | });
|
| | | } else {
|
| | | findCheckInLeftListAfterReturn(CheckInDao.getInstance().findCheckInLeftList(isVisitorList, searchText, pageNum), isVisitorList, isSortByDept, append);
|
| | | }
|
| | | }
|
| | |
|
| | | public void findCheckInLeftListAfterReturn(ResultBean resultBean, final boolean isVisitorList, final boolean isSortByDept, final boolean append) {
|
| | | List<CheckInQueryItem> list = resultBean.getList(CheckInQueryItem.class);
|
| | | if (list == null) {
|
| | | list = new ArrayList<>();
|
| | | }
|
| | |
|
| | | 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);
|
| | | final 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(resultBean.hasMorePages(), resultBean.getPageNum(), itemList);
|
| | | if (BaseApplication.getInstance().networkAvailable()) {
|
| | | 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);
|
| | | }
|
| | | } else {
|
| | | MainActivity.getInstance().runOnUiThread(new Runnable() {
|
| | | @Override
|
| | | public void run() {
|
| | | 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;
|
| | | }
|
| | | if (list == null) {
|
| | | list = new ArrayList<>();
|
| | | }
|
| | | Collections.sort(list, new Comparator<CheckInQueryItem>() {
|
| | | @Override
|
| | | public int compare(CheckInQueryItem t1, CheckInQueryItem t2) {
|
| | | public int compare(CheckInQueryItem item1, CheckInQueryItem item2) {
|
| | | if (sortedByDept) {
|
| | | String dept1Name = t1.getDeptName()==null?"":t1.getDeptName();
|
| | | String dept2Name = t2.getDeptName()==null?"":t2.getDeptName();
|
| | | String dept1Name = item1.getDeptName()==null?"":item1.getDeptName();
|
| | | String dept2Name = item2.getDeptName()==null?"":item2.getDeptName();
|
| | | if(!dept1Name.equals(dept2Name)) {
|
| | | String dept1Name_a = CharacterParser.getInstance().getSelling(dept1Name).toLowerCase();
|
| | | String dept1Name_b = CharacterParser.getInstance().getSelling(dept2Name).toLowerCase();
|
| | | 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 name1 = t1.getUsername()==null?"":t1.getUsername();
|
| | | String name2 = t2.getUsername()==null?"":t2.getUsername();
|
| | | String dept1Name_a = CharacterParser.getInstance().getSelling(name1).toLowerCase();
|
| | | String dept1Name_b = CharacterParser.getInstance().getSelling(name2).toLowerCase();
|
| | | 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);
|
| | | }
|
| | | });
|
| | | }
|
| | |
|
| | |
|
| | | public void sendOfflineCheckInToServer(Integer mysqlVisitorId, long sqliteVisitorId) {
|
| | |
|
| | | }
|
| | |
|
| | | public boolean hasOfflineCheckInData() {
|
| | | return CheckInDao.getInstance().hasOfflineCheckInData();
|
| | | }
|
| | |
|
| | | public void removeVisitorLastMonthData() {
|
| | | try {
|
| | | SQLiteDatabase db = MainActivity.getInstance().db;
|
| | | String sql="SELECT" +
|
| | | " a.register_id," +
|
| | | "a.username," +
|
| | | "a.surveillance_photo," +
|
| | | "d.company_name," +
|
| | | "a.tel," +
|
| | | "a.identify_num," +
|
| | | "b.dept_name," +
|
| | | "d.company_id," +
|
| | | "e.post_name," +
|
| | | "a.mobile_phone," +
|
| | | "a.warning," +
|
| | | "a.company" +
|
| | | " FROM" +
|
| | | " register a" +
|
| | | " LEFT JOIN company d ON d.company_id = a.company_id" +
|
| | | " LEFT JOIN department b ON a.department_id = b.dept_id" +
|
| | | " LEFT JOIN post e ON e.post_id = a.post_id" +
|
| | | " LEFT JOIN ( SELECT register_id, device_company_id from employee ) f ON f.register_id = a.register_id" +
|
| | | " WHERE" +
|
| | | " 1 = 1";
|
| | | String deviceCompanyId = BaseApplication.getInstance().getAndroidDevice().getCompanyId();
|
| | | sql += " AND ( f.device_company_id != " + deviceCompanyId+" OR f.device_company_id IS NULL"+")";
|
| | |
|
| | | sql+=" order by a.name_en";
|
| | |
|
| | | String count = "select count(*) as count from (" + sql + " ) _table";
|
| | | sql += " LIMIT 0, 100000";
|
| | | List<CheckInQueryItem> list = new ArrayList<CheckInQueryItem>();
|
| | | int b = list.size();
|
| | | CheckInQueryItem cqi = null;
|
| | | Cursor c = db.rawQuery(sql,new String[]{});
|
| | | while (c.moveToNext()) {
|
| | | cqi = new CheckInQueryItem();
|
| | | cqi.setRegisterId(c.getString(c.getColumnIndex("register_id")));
|
| | | list.add(cqi);
|
| | | }
|
| | | for (CheckInQueryItem item : list) {
|
| | | String sql1 = "delete from register where 1=1 and register_id = '" + item.getRegisterId() + "'";
|
| | | MainActivity.getInstance().db.execSQL(sql1);
|
| | | }
|
| | | } catch (Exception e) {
|
| | | e.printStackTrace();
|
| | | }
|
| | | }
|
| | |
|
| | | }
|