| | |
| | | package cn.com.basic.face.service;
|
| | |
|
| | | import android.widget.Toast;
|
| | |
|
| | | import cn.com.basic.face.base.BaseApplication;
|
| | | import cn.com.basic.face.base.MainActivity;
|
| | | import cn.com.basic.face.dialog.CountryDialog;
|
| | | import cn.com.basic.face.dialog.SelectDialog;
|
| | | import cn.com.basic.face.discern.query.condition.DictionaryQueryCondition;
|
| | | import cn.com.basic.face.discern.query.item.VistorTypeQueryItem;
|
| | | import cn.com.basic.face.util.AppApi;
|
| | |
|
| | | import org.xutils.http.RequestParams;
|
| | | import org.xutils.x;
|
| | |
|
| | | import java.util.ArrayList;
|
| | | import java.util.Collections;
|
| | | import java.util.Comparator;
|
| | | import java.util.HashMap;
|
| | | import java.util.List;
|
| | | import java.util.Map;
|
| | |
| | | import cn.com.basic.face.discern.common.BaseCommonCallBack;
|
| | | import cn.com.basic.face.discern.common.CommonVariables;
|
| | | import cn.com.basic.face.discern.entity.Dictionary;
|
| | | import cn.com.basic.face.util.CharacterParser;
|
| | | import cn.com.basic.face.util.Constant;
|
| | |
|
| | | public class DictionaryMng {
|
| | | public class DictionaryMng extends BaseMng {
|
| | |
|
| | | public static DictionaryMng instance = new DictionaryMng();
|
| | |
|
| | |
| | | return instance;
|
| | | }
|
| | |
|
| | | public Map<String, String> idMap = new HashMap<String, String>();
|
| | |
|
| | | public String getId(String name) {
|
| | | return idMap.get(name);
|
| | | }
|
| | |
|
| | | public void loadAllDictionaryData() {
|
| | | if (!BaseApplication.deviceAvailable) {
|
| | | return;
|
| | | }
|
| | | loadCountries();
|
| | | loadIdTypeList();
|
| | | loadGenderList();
|
| | | loadVisitReasonList();
|
| | | loadVisitorTypeList();
|
| | | loadResolutionList();
|
| | | loadProtocolList();
|
| | | loadCameraBrandList();
|
| | | DepartmentMng.getInstance().loadDepartmentDictionary();
|
| | | PostMng.getInstance().loadPostDictionary();
|
| | | }
|
| | |
|
| | | public void loadCountries() {
|
| | | if (!BaseApplication.deviceAvailable) {
|
| | | return;
|
| | | }
|
| | | RequestParams params = new RequestParams(AppApi.BASE_URL +AppApi.Query.DICTIONARY_QUERY);
|
| | | params.addParameter(DictionaryQueryCondition.FieldNames.type, CommonVariables.DictionaryType.COUNTRY);
|
| | | x.http().get(params, new BaseCommonCallBack() {
|
| | |
| | | int i=0;
|
| | | List<String> uniqueFirstLetterList = new ArrayList<String>();
|
| | | HashMap<String,List<String>> countriesGroupByFirstLetter = new HashMap<String,List<String>>();
|
| | | sortCountries(items);
|
| | | for (Dictionary item : items) {
|
| | | idMap.put(item.getName(), item.getId()+"");
|
| | | String firstLetter = item.getRemark();
|
| | | idMap.put(item.getName(), item.getDictId()+"");
|
| | |
|
| | | String firstLetter = item.getName();
|
| | | if (item.getName().length() > 0) {
|
| | | firstLetter = CharacterParser.getInstance().getSelling(item.getName()).substring(0, 1).toUpperCase();
|
| | | }
|
| | | List list = countriesGroupByFirstLetter.get(firstLetter);
|
| | | if (list == null) {
|
| | | list = new ArrayList();
|
| | |
| | | CountryDialog.setCountries(uniqueFirstLetterList, countriesGroupByFirstLetter);
|
| | | }
|
| | | });
|
| | | }
|
| | |
|
| | | private void sortCountries(List<Dictionary> countries) {
|
| | | if (!BaseApplication.deviceAvailable) {
|
| | | return;
|
| | | }
|
| | | Collections.sort(countries, new Comparator<Dictionary>() {
|
| | | @Override
|
| | | public int compare(Dictionary t1, Dictionary t2) {
|
| | | String name1 = t1.getName()==null?"":t1.getName();
|
| | | String name2 = t2.getName()==null?"":t2.getName();
|
| | | String dept1Name_a = name1.trim();
|
| | | String dept1Name_b = name2.trim();
|
| | | if (dept1Name_a.length() > 0 && dept1Name_b.length() > 0) {
|
| | | dept1Name_a = CharacterParser.getInstance().getSelling(name1).toLowerCase();
|
| | | dept1Name_b = CharacterParser.getInstance().getSelling(name2).toLowerCase();
|
| | | }
|
| | | return dept1Name_b.compareTo(dept1Name_a);
|
| | | }
|
| | | });
|
| | | }
|
| | |
|
| | | public void loadIdTypeList() {
|
| | | if (!BaseApplication.deviceAvailable) {
|
| | | return;
|
| | | }
|
| | | RequestParams params = new RequestParams(AppApi.BASE_URL +AppApi.Query.DICTIONARY_QUERY);
|
| | | params.addParameter(DictionaryQueryCondition.FieldNames.type, CommonVariables.DictionaryType.ID_TYPE);
|
| | | x.http().get(params, new BaseCommonCallBack() {
|
| | |
| | | }
|
| | |
|
| | | private void loadGenderList() {
|
| | | if (!BaseApplication.deviceAvailable) {
|
| | | return;
|
| | | }
|
| | | RequestParams params = new RequestParams(AppApi.BASE_URL +AppApi.Query.DICTIONARY_QUERY);
|
| | | params.addParameter(DictionaryQueryCondition.FieldNames.type, CommonVariables.DictionaryType.GENDER);
|
| | | x.http().get(params, new BaseCommonCallBack() {
|
| | |
| | | });
|
| | | }
|
| | |
|
| | | private void loadVisitReasonList() {
|
| | | public void loadVisitReasonList() {
|
| | | if (!BaseApplication.deviceAvailable) {
|
| | | return;
|
| | | }
|
| | | RequestParams params = new RequestParams(AppApi.BASE_URL +AppApi.Query.DICTIONARY_QUERY);
|
| | | params.addParameter(DictionaryQueryCondition.FieldNames.type, CommonVariables.DictionaryType.VISIT_REASON);
|
| | | x.http().get(params, new BaseCommonCallBack() {
|
| | |
| | | });
|
| | | }
|
| | |
|
| | | public List<String> getDictionaryNameList(List<Dictionary> dictionaryList) {
|
| | | List nameList = new ArrayList();
|
| | | for (Dictionary dictionary : dictionaryList) {
|
| | | idMap.put(dictionary.getName(), dictionary.getId()+"");
|
| | | nameList.add(dictionary.getName());
|
| | | public void loadResolutionList() {
|
| | | if (!BaseApplication.deviceAvailable) {
|
| | | return;
|
| | | }
|
| | | return nameList;
|
| | | RequestParams params = new RequestParams(AppApi.BASE_URL +AppApi.Query.DICTIONARY_QUERY);
|
| | | params.addParameter(DictionaryQueryCondition.FieldNames.type, CommonVariables.DictionaryType.RESOLUTION);
|
| | | x.http().get(params, new BaseCommonCallBack() {
|
| | | public void success() {
|
| | | SelectDialog.setResolutionList(getDictionaryNameList(getList(Dictionary.class)));
|
| | | }
|
| | | });
|
| | | }
|
| | |
|
| | | public void loadProtocolList() {
|
| | | if (!BaseApplication.deviceAvailable) {
|
| | | return;
|
| | | }
|
| | | RequestParams params = new RequestParams(AppApi.BASE_URL +AppApi.Query.DICTIONARY_QUERY);
|
| | | params.addParameter(DictionaryQueryCondition.FieldNames.type, CommonVariables.DictionaryType.PROTOCOL);
|
| | | x.http().get(params, new BaseCommonCallBack() {
|
| | | public void success() {
|
| | | SelectDialog.setProtocolList(getDictionaryNameList(getList(Dictionary.class)));
|
| | | }
|
| | | });
|
| | | }
|
| | |
|
| | | public void loadCameraBrandList() {
|
| | | if (!BaseApplication.deviceAvailable) {
|
| | | return;
|
| | | }
|
| | | RequestParams params = new RequestParams(AppApi.BASE_URL +AppApi.Query.DICTIONARY_QUERY);
|
| | | params.addParameter(DictionaryQueryCondition.FieldNames.type, CommonVariables.DictionaryType.CAMERA_BRAND);
|
| | | x.http().get(params, new BaseCommonCallBack() {
|
| | | public void success() {
|
| | | SelectDialog.setCameraBrandList(getDictionaryNameList(getList(Dictionary.class)));
|
| | | }
|
| | | });
|
| | | }
|
| | |
|
| | | private void loadVisitorTypeList() {
|
| | | if (!BaseApplication.deviceAvailable) {
|
| | | return;
|
| | | }
|
| | | RequestParams params = new RequestParams(AppApi.BASE_URL +AppApi.Query.DICTIONARY_QUERY);
|
| | | params.addParameter(DictionaryQueryCondition.FieldNames.type, CommonVariables.DictionaryType.VISIT_TYPE);
|
| | | params.addParameter(DictionaryQueryCondition.FieldNames.type, CommonVariables.DictionaryType.VISITOR_TYPE);
|
| | | x.http().get(params, new BaseCommonCallBack() {
|
| | | public void success() {
|
| | | SelectDialog.setVisitorTypeList(getDictionaryNameList(getList(Dictionary.class)));
|
| | |
| | | });
|
| | | }
|
| | |
|
| | |
|
| | | private void loadAttenderTypeList() {
|
| | | if (!BaseApplication.deviceAvailable) {
|
| | | return;
|
| | | }
|
| | | RequestParams params = new RequestParams(AppApi.BASE_URL +AppApi.Query.DICTIONARY_QUERY);
|
| | | params.addParameter(DictionaryQueryCondition.FieldNames.type, CommonVariables.DictionaryType.ATTENDER_TYPE);
|
| | | x.http().get(params, new BaseCommonCallBack() {
|
| | | public void success() {
|
| | | SelectDialog.setAttenderTypeList(getDictionaryNameList(getList(Dictionary.class)));
|
| | | }
|
| | | });
|
| | | }
|
| | |
|
| | | public void addDictionary(final int type, String type1, String name) {
|
| | | RequestParams params = new RequestParams(AppApi.BASE_URL +AppApi.DICTIONARY_ADD);
|
| | | params.addBodyParameter(Dictionary.FieldNames.type, type1);
|
| | | params.addBodyParameter(Dictionary.FieldNames.name, name);
|
| | | params.addBodyParameter(Dictionary.FieldNames.orderBy, "10");
|
| | | x.http().post(params, new BaseCommonCallBack() {
|
| | | public void success() {
|
| | | List<Dictionary> items = getList(Dictionary.class);
|
| | | switch (type) {
|
| | | case Constant.DialogSelectType.VISIT_REASON:
|
| | | break;
|
| | | case Constant.DialogSelectType.RESOLUTION:
|
| | | SelectDialog.setResolutionList(getDictionaryNameList(getList(Dictionary.class)));
|
| | | break;
|
| | | case Constant.DialogSelectType.PROTOCOL:
|
| | | SelectDialog.setProtocolList(getDictionaryNameList(getList(Dictionary.class)));
|
| | | break;
|
| | | case Constant.DialogSelectType.CAMERA_BRAND:
|
| | | SelectDialog.setCameraBrandList(getDictionaryNameList(getList(Dictionary.class)));
|
| | | break;
|
| | | }
|
| | | Toast.makeText(MainActivity.getInstance(), "添加成功", Toast.LENGTH_SHORT).show();
|
| | | }
|
| | | });
|
| | | }
|
| | |
|
| | | }
|