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.

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

报告相同问题?

悬赏问题

  • ¥15 #MATLAB仿真#车辆换道路径规划
  • ¥15 java 操作 elasticsearch 8.1 实现 索引的重建
  • ¥15 数据可视化Python
  • ¥15 要给毕业设计添加扫码登录的功能!!有偿
  • ¥15 kafka 分区副本增加会导致消息丢失或者不可用吗?
  • ¥15 微信公众号自制会员卡没有收款渠道啊
  • ¥100 Jenkins自动化部署—悬赏100元
  • ¥15 关于#python#的问题:求帮写python代码
  • ¥20 MATLAB画图图形出现上下震荡的线条
  • ¥15 关于#windows#的问题:怎么用WIN 11系统的电脑 克隆WIN NT3.51-4.0系统的硬盘