| | |
| | | package cn.com.basic.face.service.sqlite;
|
| | |
|
| | | /**
|
| | | * Created by xiuxi on 2017/7/17.
|
| | | */
|
| | | import android.content.ContentValues;
|
| | | import android.database.Cursor;
|
| | | import android.database.sqlite.SQLiteDatabase;
|
| | |
|
| | | public class PhoneCallDao {
|
| | | 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.MainActivity;
|
| | | 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 extends BaseDao{
|
| | |
|
| | | public static PhoneCallDao instance = new PhoneCallDao();
|
| | | public static PhoneCallDao getInstance() {
|
| | | return instance;
|
| | | }
|
| | |
|
| | | /**
|
| | | * 电话呼叫左边列表
|
| | | * @param searchText
|
| | | * @param pageNum
|
| | | * @return
|
| | | */
|
| | | public ResultBean findPhoneCallLeftList(String searchText, final int pageNum) {
|
| | | ResultBean resultBean = new ResultBean();
|
| | | SQLiteDatabase db = MainActivity.getInstance().db;
|
| | | 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_count.getInt(0);
|
| | | }
|
| | | resultBean.setTotalPages(getTotalPageSize(total));
|
| | | resultBean.setPageNum(pageNum);
|
| | | resultBean.setData(list);
|
| | | } catch (Exception e) {
|
| | | e.printStackTrace();
|
| | | }
|
| | | return resultBean;
|
| | | }
|
| | |
|
| | | /**
|
| | | * 添加电话呼叫
|
| | | * @param visitor
|
| | | * @param interviewee
|
| | | */
|
| | | public void addPhoneCall(CheckInQueryItem visitor, CheckInQueryItem interviewee) {
|
| | | SQLiteDatabase db = MainActivity.getInstance().db;
|
| | | try {
|
| | | StringBuilder sb = new StringBuilder(40);
|
| | | SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
| | | ContentValues cv = new ContentValues();
|
| | | cv.put("date",sdf.format(new Date()));
|
| | | cv.put("caller_id",visitor.getRegisterId());
|
| | | cv.put("callee_id",interviewee.getRegisterId());
|
| | | cv.put("device_id",BaseApplication.getInstance().getAndroidDevice().getDeviceId());
|
| | | db.insert("phone_call",null,cv);
|
| | | } catch (Exception e) {
|
| | | e.printStackTrace();
|
| | | }
|
| | | }
|
| | |
|
| | | }
|