package eVVM.apk.ui.home.uploadChip; import com.alibaba.fastjson.JSONArray; import com.allen.library.RxHttpUtils; import com.allen.library.interceptor.Transformer; import com.google.gson.Gson; import java.util.HashMap; import java.util.Map; import eVVM.apk.api.ApiService; import eVVM.apk.app.MyApplication; import eVVM.apk.common.MyDataObsever; import eVVM.apk.db.netteconnectdb.NetReConnectDaoOpe; import eVVM.apk.entity.NetReConnectEntity; import eVVM.apk.helper.SPUtils; import eVVM.apk.mvp.MvpModel; import eVVM.apk.ui.bean.VnDetailBean; /** * Created by Android Studio. * User: zbb * Date: 2019/6/1 * Describe: UploadChipModel */ public class UploadChipModel extends MvpModel { public UploadChipModel() { } //操作员提交数据 public void forFactoryOperator(String chipNumber, String cipherText, double longitude, double latitude) { Map map = new HashMap<>(); map.put("chipNumber", chipNumber); map.put("longitude", longitude); map.put("latitude", latitude); map.put("cipherText", cipherText); RxHttpUtils.createApi(ApiService.class) .saveChip(map) .compose(Transformer.switchSchedulers()) .subscribe(new MyDataObsever() { @Override protected void onError(String errorMsg) { getListener().onFail(errorMsg,false); } @Override protected void onSuccess(VnDetailBean data) { if (data.getCode() == 200) { getListener().onSucceed(data); } else { getListener().onFail(data.getMsg(),false); } } @Override protected boolean isHideToast() { return true; } }); } //医生提交数据 public void forDoctor(final String chipNumber, String cipherText, String inoculators, double longitude, double latitude, boolean again, final boolean isWarning, final String noNetMsg) { Map map = new HashMap<>(); map.put("chipNumber", chipNumber); map.put("inoculators", inoculators); map.put("longitude", longitude); map.put("latitude", latitude); map.put("vaccinationCipher", cipherText); map.put("agin", true); //Log.e("forDoctorinoculators",""+inoculators); final String setJsonmap = mapToJson(map); RxHttpUtils.createApi(ApiService.class) .uploadChip(map) .compose(Transformer.switchSchedulers()) .subscribe(new MyDataObsever() { @Override protected void onError(String errorMsg) { boolean noNetRepeatFlag = false; if ("网络连接异常,请检查您的网络状态,稍后重试!".equals(errorMsg)) { String noNetChipListstr = (String) SPUtils.get("noNetChipList", ""); JSONArray noNetChipList = (JSONArray) JSONArray.parse(noNetChipListstr); if (noNetChipList != null) { for (int i = 0; i < noNetChipList.size(); i++) { if (noNetChipList.get(i).toString().equals(chipNumber)) { noNetRepeatFlag = true; } } } if (noNetRepeatFlag || !noNetMsg.equals("正常")) { //已经使用过该芯片 } else { NetReConnectEntity netReConnectEntity = new NetReConnectEntity(); netReConnectEntity.setType(1); netReConnectEntity.setJsonmap(setJsonmap); netReConnectEntity.setIsWarning(isWarning); netReConnectEntity.setInterfaceName("chip"); netReConnectEntity.setInterfaceUrl("uploadChip"); NetReConnectDaoOpe.insertData(MyApplication.getAppContext(), netReConnectEntity); } } getListener().onFail(errorMsg,noNetRepeatFlag); } @Override protected void onSuccess(VnDetailBean data) { if (data.getCode() == 200) { getListener().onSucceed(data); } else { getListener().onFail(data.getMsg(),false); } } @Override protected boolean isHideToast() { return true; } }); } /** * string转map * * @param map * @return */ private String mapToJson(Map map) { String jsonString = new Gson().toJson(map); return jsonString; } }