| | |
| | | package cn.com.basic.face.service.sqlite;
|
| | |
|
| | | import java.util.ArrayList;
|
| | | import android.database.Cursor;
|
| | | import android.database.sqlite.SQLiteDatabase;
|
| | |
|
| | | import java.text.SimpleDateFormat;
|
| | | import java.util.ArrayList;
|
| | | import java.util.Date;
|
| | | import java.util.List;
|
| | |
|
| | | import cn.com.basic.face.base.BaseApplication;
|
| | | import cn.com.basic.face.base.Config;
|
| | | import cn.com.basic.face.discern.common.CommonVariables;
|
| | | import cn.com.basic.face.discern.common.ResultBean;
|
| | | import cn.com.basic.face.discern.query.item.CheckInQueryItem;
|
| | | import cn.com.basic.face.discern.query.item.PhoneCallQueryItem;
|
| | |
|
| | | public class PhoneCallDao {
|
| | | public class PhoneCallDao extends BaseDao{
|
| | |
|
| | | public static PhoneCallDao instance = new PhoneCallDao();
|
| | | public static PhoneCallDao getInstance() {
|
| | |
| | | */
|
| | | public ResultBean findPhoneCallLeftList(String searchText, final int pageNum) {
|
| | | ResultBean resultBean = new ResultBean();
|
| | | resultBean.setData(new ArrayList<PhoneCallQueryItem>());
|
| | | return null;
|
| | | SQLiteDatabase db = Config.sqlMap.getDb();
|
| | | db.beginTransaction();
|
| | | try {
|
| | | StringBuilder sb = new StringBuilder(40);
|
| | | sb.append("SELECT b.username caller,c.username callee,d.dept_name caller_dept,e.dept_name callee_dept,")
|
| | | .append(" f.post_name,b.surveillance_photo caller_image,c.surveillance_photo callee_image,")
|
| | | .append(" c.mobile_phone,c.tel ").append(" FROM ").append(" phone_call a")
|
| | | .append(" LEFT JOIN register b ON b.register_id = a.caller_id")
|
| | | .append(" LEFT JOIN register c ON c.register_id = a.callee_id")
|
| | | .append(" LEFT JOIN department d ON d.dept_id = b.department_id")
|
| | | .append(" LEFT JOIN department e ON e.dept_id = c.department_id")
|
| | | .append(" LEFT JOIN post f ON f.post_id = b.post_id")
|
| | | .append(" WHERE ").append(" 1 = 1 ");
|
| | | if(searchText != null && !searchText.trim().isEmpty()) {
|
| | | sb.append(" AND b.username LIKE '%").append(searchText).append("%'");
|
| | | }
|
| | | sb.append("group by c.register_id");
|
| | | StringBuilder count = new StringBuilder(sb.length()*2);
|
| | | count.append("select count(*) as count from (").append(sb).append(" ) _table");
|
| | | sb.append(" LIMIT ").append(getStartIndex(pageNum)).append(",").append(CommonVariables.Page.DEFAULT_PAGE_SIZE);
|
| | | List<PhoneCallQueryItem> list = new ArrayList<PhoneCallQueryItem>();
|
| | | PhoneCallQueryItem aqi = null;
|
| | | Cursor c = db.rawQuery(sb.toString(),new String[]{});
|
| | | Cursor c_count = db.rawQuery(count.toString(),new String[]{});
|
| | | while (c.moveToNext()) {
|
| | | aqi = new PhoneCallQueryItem();
|
| | | aqi.setCaller(c.getString(c.getColumnIndex("caller")));
|
| | | aqi.setCallee(c.getString(c.getColumnIndex("callee")));
|
| | | aqi.setCallerDept(c.getString(c.getColumnIndex("caller_dept")));
|
| | | aqi.setCalleeDept(c.getString(c.getColumnIndex("callee_dept")));
|
| | | aqi.setPostName(c.getString(c.getColumnIndex("post_name")));
|
| | | aqi.setCallerImage(c.getString(c.getColumnIndex("caller_image")));
|
| | | aqi.setCalleeImage(c.getString(c.getColumnIndex("callee_image")));
|
| | | aqi.setMobilePhone(c.getString(c.getColumnIndex("mobile_phone")));
|
| | | aqi.setTel(c.getString(c.getColumnIndex("tel")));
|
| | | list.add(aqi);
|
| | | }
|
| | | Integer total = null;
|
| | | while (c_count.moveToNext()) {
|
| | | total = c.getInt(c.getColumnIndex("count"));
|
| | | }
|
| | | resultBean.setTotalPages(getTotalPageSize(total));
|
| | | resultBean.setPageNum(pageNum);
|
| | | resultBean.setData(list);
|
| | | c.close();
|
| | | c_count.close();
|
| | | db.setTransactionSuccessful();
|
| | | } catch (Exception e) {
|
| | | e.printStackTrace();
|
| | | } finally {
|
| | | db.endTransaction();
|
| | | if(db != null && db.isOpen()){
|
| | | db.close();
|
| | | }
|
| | | }
|
| | | return resultBean;
|
| | | }
|
| | |
|
| | | /**
|
| | |
| | | * @param interviewee
|
| | | */
|
| | | public void addPhoneCall(CheckInQueryItem visitor, CheckInQueryItem interviewee) {
|
| | |
|
| | | SQLiteDatabase db = Config.sqlMap.getDb();
|
| | | db.beginTransaction();
|
| | | try {
|
| | | StringBuilder sb = new StringBuilder(40);
|
| | | SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
| | | sb.append("insert into phone_call (date,caller_id,callee_id,device_id) values (")
|
| | | .append(sdf.format(new Date()))
|
| | | .append(" , ").append(visitor.getRegisterId()).append(" , ")
|
| | | .append(interviewee.getRegisterId())
|
| | | .append(" , ")
|
| | | .append(BaseApplication.getInstance().getAndroidDevice().getDeviceId())
|
| | | .append(")");
|
| | | db.rawQuery(sb.toString(),new String[]{});
|
| | | db.setTransactionSuccessful();
|
| | | } catch (Exception e) {
|
| | | e.printStackTrace();
|
| | | } finally {
|
| | | db.endTransaction();
|
| | | if(db != null && db.isOpen()){
|
| | | db.close();
|
| | | }
|
| | | }
|
| | | }
|
| | |
|
| | | }
|