| | |
| | | package cn.com.basic.face.service.sqlite;
|
| | |
|
| | | /**
|
| | | * Created by xiuxi on 2017/7/17.
|
| | | */
|
| | | import android.database.Cursor;
|
| | |
|
| | | import java.util.ArrayList;
|
| | | import java.util.List;
|
| | |
|
| | | import cn.com.basic.face.base.MainActivity;
|
| | | import cn.com.basic.face.discern.common.CommonVariables;
|
| | | import cn.com.basic.face.discern.entity.Dictionary;
|
| | |
|
| | | /**
|
| | | * 数据字典Dao
|
| | | */
|
| | | public class DictionaryDao {
|
| | | }
|
| | |
|
| | | public static DictionaryDao instance = new DictionaryDao();
|
| | | public static DictionaryDao getInstance() {
|
| | | return instance;
|
| | | }
|
| | |
|
| | | private static List<Dictionary>load(String type){
|
| | | List<Dictionary> list = new ArrayList<Dictionary>();
|
| | | StringBuffer sb = new StringBuffer("select dict_id, name from dictionary ");
|
| | | try {
|
| | | sb.append("where 1 = 1 and type = ");
|
| | | sb.append("'");
|
| | | sb.append(type);
|
| | | sb.append("'");
|
| | | Dictionary aqi = null;
|
| | | Cursor c = MainActivity.getInstance().db.rawQuery(sb.toString(), new String[]{});
|
| | | while (c.moveToNext()) {
|
| | | aqi = new Dictionary();
|
| | | aqi.setDictId(c.getString(c.getColumnIndex("dict_id")));
|
| | | aqi.setName(c.getString((c.getColumnIndex("name"))));
|
| | | list.add(aqi);
|
| | | }
|
| | | }catch (Exception e) {
|
| | | e.printStackTrace();
|
| | | }
|
| | | return list;
|
| | | }
|
| | |
|
| | | /**
|
| | | * 加载国家
|
| | | * @return
|
| | | */
|
| | | public List<Dictionary> loadCountries() {
|
| | |
|
| | | return load(CommonVariables.DictionaryType.COUNTRY);
|
| | | }
|
| | |
|
| | | /**
|
| | | * 加载证件类型
|
| | | * @return
|
| | | */
|
| | | public List<Dictionary> loadIdTypeList() {
|
| | |
|
| | | return load(CommonVariables.DictionaryType.ID_TYPE);
|
| | |
|
| | | }
|
| | |
|
| | | /**
|
| | | * 加载性别
|
| | | * @return
|
| | | */
|
| | | public List<Dictionary> loadGenderList() {
|
| | | return load(CommonVariables.DictionaryType.GENDER);
|
| | | }
|
| | |
|
| | | /**
|
| | | * 加载访问事由
|
| | | * @return
|
| | | */
|
| | | public List<Dictionary> loadVisitReasonList() {
|
| | | return load(CommonVariables.DictionaryType.VISIT_REASON);
|
| | | }
|
| | |
|
| | | /**
|
| | | * 加载分辨率
|
| | | * @return
|
| | | */
|
| | | public List<Dictionary> loadResolutionList() {
|
| | | return load(CommonVariables.DictionaryType.RESOLUTION);
|
| | | }
|
| | |
|
| | | /**
|
| | | * 加载通讯协议
|
| | | * @return
|
| | | */
|
| | | public List<Dictionary> loadProtocolList() {
|
| | | return load(CommonVariables.DictionaryType.PROTOCOL);
|
| | | }
|
| | |
|
| | | /**
|
| | | * 加载摄像机品牌
|
| | | * @return
|
| | | */
|
| | | public List<Dictionary> loadCameraBrandList() {
|
| | | return load(CommonVariables.DictionaryType.CAMERA_BRAND);
|
| | | }
|
| | |
|
| | | /**
|
| | | * 加载访客类型
|
| | | * @return
|
| | | */
|
| | | public List<Dictionary> loadVisitorTypeList() {
|
| | | return load(CommonVariables.DictionaryType.VISITOR_TYPE);
|
| | | }
|
| | |
|
| | | /**
|
| | | * 加载考勤类型
|
| | | * @return
|
| | | */
|
| | | public List<Dictionary> loadAttenderTypeList() {
|
| | | return load(CommonVariables.DictionaryType.ATTENDER_TYPE);
|
| | | }
|
| | |
|
| | | public List<Dictionary> addDictionary(String type, String name) {
|
| | | List<Dictionary> list = new ArrayList<Dictionary>();
|
| | | try {
|
| | | StringBuilder sb = new StringBuilder(40);
|
| | |
|
| | | sb.append("insert into dictionary ( dict_id, name) values (")
|
| | | .append("'")
|
| | | .append(type)
|
| | | .append("'")
|
| | | .append(" , ")
|
| | | .append(")");
|
| | | MainActivity.getInstance().db.rawQuery(sb.toString(), new String[]{});
|
| | | Dictionary aqi = null;
|
| | | Cursor c = MainActivity.getInstance().db.rawQuery("select dict_id,name from dictionary", new String[]{});
|
| | | while (c.moveToNext()) {
|
| | | aqi = new Dictionary();
|
| | | aqi.setDictId(c.getString(c.getColumnIndex("dict_id")));
|
| | | aqi.setName(c.getString((c.getColumnIndex("name"))));
|
| | | list.add(aqi);
|
| | | }
|
| | | } catch (Exception e) {
|
| | | e.printStackTrace();
|
| | | }
|
| | | return list;
|
| | | }
|
| | |
|
| | | //加载需要同步的数据
|
| | | public List<Dictionary> getDictionayList(String deviceCompanyId){
|
| | | String sql="select * from dictionary WHERE is_synchron='N' and device_company_id="+Integer.parseInt(deviceCompanyId);
|
| | | Cursor c =MainActivity.getInstance().db.rawQuery(sql,new String[]{});
|
| | | List<Dictionary> result=new ArrayList<Dictionary>();
|
| | | Dictionary dic=null;
|
| | | if(c.moveToFirst()){
|
| | | dic=new Dictionary();
|
| | | dic.setSn(c.getString(c.getColumnIndex("sn")));
|
| | | dic.setType(c.getString(c.getColumnIndex("type")));
|
| | | dic.setCompnayId(c.getString(c.getColumnIndex("compnay_id")));
|
| | | dic.setDeviceCompanyId(c.getString(c.getColumnIndex("device_company_id")));
|
| | | dic.setDictId(c.getString(c.getColumnIndex("dict_id")));
|
| | | dic.setIsSynchron(c.getString(c.getColumnIndex("is_synchron")));
|
| | | dic.setUpdateTime(c.getString(c.getColumnIndex("update_time")));
|
| | | dic.setName(c.getString(c.getColumnIndex("name")));
|
| | | dic.setOrderBy(c.getString(c.getColumnIndex("order_by")));
|
| | | dic.setPid(c.getString(c.getColumnIndex("pid")));
|
| | | dic.setRemark(c.getString(c.getColumnIndex("remark")));
|
| | | result.add(dic);
|
| | | }
|
| | | return result;
|
| | | }
|
| | |
|
| | | //删除已经上传到服务器的数据
|
| | | public void delDictionary(){
|
| | | String sql="delete from dictionary where is_synchron='N'";
|
| | | MainActivity.getInstance().db.execSQL(sql);
|
| | |
|
| | | }
|
| | | //获取未同步数据总数
|
| | | public int getSynDataCount(){
|
| | | String sql="select count(*) from dictionary where is_synchron='N' ";
|
| | | Cursor c =MainActivity.getInstance().db.rawQuery(sql,new String[]{});
|
| | | return c.getCount();
|
| | | }
|
| | |
|
| | | }
|
| | |
|