dtxzwdl08169 2018-09-03 14:22 采纳率: 0%
浏览 40
已采纳

成千上万的插页和我有重复的价值,为什么?

I have an application that is a car parking system, my clients use it a lot to send to my database entries of data from the car.

here is the code to send to my server :

 public void sendEntradaRotativaDataToServer(String url){

    pDialog = new ProgressDialog(getActivity());
    pDialog.setMessage("Processando entrada..");
    pDialog.setIndeterminate(false);
    pDialog.setCancelable(false);
    pDialog.show();

    JsonObject json = new JsonObject();
    json.addProperty("placa",  entradaObj.getPlaca());
    json.addProperty("dataemissao",  entradaObj.getDataemissao());
    json.addProperty("tipo",   entradaObj.getTipo());
    json.addProperty("valor",  entradaObj.getValor());
    json.addProperty("area",   entradaObj.getArea().getId());
    json.addProperty("observacao",  entradaObj.getObservacao());
    json.addProperty("user_id",  entradaObj.getUser_id());

    Ion.with(getActivity())
            .load(url)
            .setTimeout(5000)
            .setJsonObjectBody(json)
            .asJsonObject()
            .setCallback(new FutureCallback<JsonObject>() {
                @Override
                public void onCompleted(Exception e, JsonObject result) {

                    if (e != null) {

                        newMsgWarn("Atenção","Não foi possível fazer uma conexão por favor tente novamente");

                        if(pDialog != null && pDialog.isShowing()){
                            pDialog.dismiss();
                        }

                    } else {

                        success   = result.get(TAG_SUCCESS).getAsInt();
                        message   = result.get(TAG_MESSAGE).getAsString();

                        entradaObj.set_id(result.get("entradaid").getAsString());

                        (new SyncEntrada()).execute(new String[0]);

                        if(pDialog != null && pDialog.isShowing()){
                            pDialog.dismiss();
                        }

                    }

                }


            });

}

it is a simple post request with the Ion library and this is the code on the server ( i'm using laravel on the project ) :

public function insertDataRotativa(Request $request) {


    if(isset($request)) {

        $dataentradaini = Carbon::parse($request->input('dataemissao'));           
        $evento   = $this->mdUtil->getEventByDataEmissao($dataentradaini);

        if (!empty($evento)) {

          foreach ($evento as $value) {  

              $this->mdEntrada                 = new Entrada; 
              $this->mdEntrada->placa          = $request->input('placa');
              $this->mdEntrada->created_at     = $dataentradaini;
              $this->mdEntrada->updated_at     = $dataentradaini;
              $this->mdEntrada->tipo           = $request->input('tipo');
              $this->mdEntrada->valor          = $request->input('valor');
              $this->mdEntrada->area           = $request->input('area');
              $this->mdEntrada->observacao     = $request->input('observacao');
              $this->mdEntrada->user_id        = $request->input('user_id');
              $this->mdEntrada->evento_id      = $value->id;    
              $this->mdEntrada->flag           = "U";                  
              $this->mdEntrada->save();

          }             

       }else {


              $this->mdEntrada                 = new Entrada; 
              $this->mdEntrada->placa          = $request->input('placa');
              $this->mdEntrada->created_at     = $dataentradaini;
              $this->mdEntrada->updated_at     = $dataentradaini;
              $this->mdEntrada->tipo           = $request->input('tipo');
              $this->mdEntrada->valor          = $request->input('valor');
              $this->mdEntrada->area           = $request->input('area');
              $this->mdEntrada->observacao     = $request->input('observacao');
              $this->mdEntrada->user_id        = $request->input('user_id');                 
              $this->mdEntrada->flag           = "U";                  
              $this->mdEntrada->save();


       }    

        $response["success"]             = 1;
        $response["message"]             = "Entrada efetuada com sucesso.TIPO:1";
        $response["entradaid"]           = $this->mdEntrada->id;

        return $response;       

}

I'm guessing that is the user that press so many times the button to send but I put a time to enable and not enable on the button that will not make many requests in the same time, here is the code for the button :

 sendButton.setOnClickListener(new View.OnClickListener() {
        public void onClick(View v) {


            YoYo.with(Techniques.BounceIn)
                    .duration(500)
                    .playOn(v.findViewById(R.id.entradabt));


            if (SystemClock.elapsedRealtime() - mLastClickTime < 3000){
                return;
            }
            mLastClickTime = SystemClock.elapsedRealtime();
            enviarEntrada();

        }
    });

Why am i having this kind of duplicate records? Any tips?

here is the new image from database

Here my schema

my schema

  • 写回答

1条回答 默认 最新

  • dph58509 2018-09-03 15:12
    关注

    Unique_Key

    Add a unique Key on Created_at, Updated_at and Placa Seeing as this might be the Unique identifier for this table. This prevent at exactly the same time insertions.

    Also check if one request sends the SAME request multiple time and filter these out by PLACA (carplate?) (only 1 placa can be send in a single request).

    Might be handy? If the same PLACA sends within 1 minute of paying the same request, ignore it. (SQL Query filter, request all transactions within last minute and check if (carplate)placa is there). result = SQL Query select all where placa is within 1 and or 2 min; if(result is same PLACA as request){ return; and ignore request)

    Bit of pseudocode to help.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度