| | |
| | | package cn.com.basic.face.service.sqlite;
|
| | |
|
| | | /**
|
| | | * Created by xiuxi on 2017/7/17.
|
| | | */
|
| | | 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.entity.Dictionary;
|
| | |
|
| | | /**
|
| | | * 数据字典Dao
|
| | | */
|
| | | public class DictionaryDao {
|
| | |
|
| | | public static DictionaryDao instance = new DictionaryDao();
|
| | | public static DictionaryDao getInstance() {
|
| | | return instance;
|
| | | }
|
| | | private static StringBuffer sb = new StringBuffer("select dict_id, name from dictionary ");
|
| | |
|
| | |
|
| | |
|
| | | private static List<Dictionary>load(String type){
|
| | | List<Dictionary> list = new ArrayList<Dictionary>();
|
| | | SQLiteDatabase db = Config.sqlMap.getDb();
|
| | | db.beginTransaction();
|
| | | try {
|
| | | sb.append("where 1 = 1 and type = ");
|
| | | sb.append(type);
|
| | | Dictionary aqi = null;
|
| | | Cursor c = 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);
|
| | | }
|
| | | c.close();
|
| | | db.setTransactionSuccessful();
|
| | | }catch (Exception e) {
|
| | | e.printStackTrace();
|
| | | }finally {
|
| | | db.endTransaction();
|
| | | }
|
| | | 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) {
|
| | | SQLiteDatabase db = Config.sqlMap.getDb();
|
| | | List<Dictionary> list = new ArrayList<Dictionary>();
|
| | | db.beginTransaction();
|
| | | try {
|
| | | StringBuilder sb = new StringBuilder(40);
|
| | |
|
| | | sb.append("insert into dictionary ( dict_id, name) values (")
|
| | | .append(type)
|
| | | .append(" , ")
|
| | | .append(")");
|
| | | db.rawQuery(sb.toString(), new String[]{});
|
| | | Dictionary aqi = null;
|
| | | Cursor c = 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);
|
| | | }
|
| | | db.setTransactionSuccessful();
|
| | | } catch (Exception e) {
|
| | | e.printStackTrace();
|
| | | } finally {
|
| | | db.endTransaction();
|
| | | }
|
| | | return list;
|
| | | }
|
| | |
|
| | | }
|