Add: Com.springsource.org.apache.commons.logging-1.1.1.jar, Org.json.jar, and jquery-1.10.0.min.js packages
<form class= "Form-inline" > Sweep code: <input id= "Txtqrcode" type= "text" > <button id= "btnreceive" > OK </
button> </form> <script type= "Text/javascript" >//Scan two-dimensional code $ (' #btnReceive '). Click (function () {$.ajax ({ Type: "Get", url: "<%=basepath%>asynchronous/receive.do", data:{qrcode:$ (' #txtQRCode '). Val ()}, DataType: "JSON
", Cache:false, Success:function (msg) {//var json = eval (' (' +msg+ ') ');//concatenation of the JSON string var flag = Msg.flag;
var info = msg.info;
if (flag) {alert (info);
$ (' #txtQRCode '). Val ("");
} else{alert (info);
}, Error:function (Error) {alert (error);}
});
});
});
</script> package Com.utcsoft.pcapps.selfservice.controller;
Import java.io.IOException;
Import Java.io.PrintWriter;
Import java.net.UnknownHostException;
Import Javax.servlet.http.HttpServletRequest;
Import Javax.servlet.http.HttpServletResponse;
Import Org.apache.commons.logging.Log;
Import Org.apache.commons.logging.LogFactory; Import org.json.JSONException;
Import Org.json.JSONObject;
Import Org.springframework.stereotype.Controller;
Import org.springframework.web.bind.annotation.RequestMapping;
Import Com.utcsoft.common.attributes.YesNoEnum;
Import Com.utcsoft.common.util.DateOperate;
Import com.utcsoft.pcapps.selfservice.attributes.KeyRequestAttr;
Import Com.utcsoft.pcapps.selfservice.dao.FlowDao;
Import Com.utcsoft.pcapps.selfservice.dao.KeyRequestDao;
Import Com.utcsoft.pcapps.selfservice.entity.Flow;
Import Com.utcsoft.pcapps.selfservice.entity.KeyRequest;
Import Com.utcsoft.pcapps.selfservice.entity.UtcUsers; @Controller @RequestMapping (value = "/asynchronous") public class Asynchronouscontroller {Private final static log log
GER = Logfactory.getlog (Asynchronouscontroller.class); /** * Scan Two-dimensional code to change the order to UTC audit * @param request * @param response * @throws IOException * @throws jsonexception * * @Request Mapping (value= "/receive") public void receive (HttpServletRequest request,httpservletresponse response) throws IoexCeption, jsonexception{String rets = "";
Boolean B = false;
try{String QRCode = Request.getparameter ("QRCode") ==null? "": Request.getparameter ("QRCode"). ToString (). Trim ();
Logger.info (QRCode); if (! "".
Equals (QRCode)) {Jsonobject obj = new Jsonobject (QRCode);
String OrderID = obj.getstring ("OrderID"). Trim (); if (! "".
Equals (OrderID)) {Keyrequestdao Keydao = new Keyrequestdao ();
Keyrequest k = new Keyrequest ();//comprehensive information k = Keydao.findonebyorderid (OrderID); if (k!=null) {///Modify order status to audit int n = keydao.updatestate (OrderID, string.valueof (
KeyRequestAttr.KqStateEnum.verify.getStep ()));
Flow flow = new flow ();
Flowdao Flowdao = new Flowdao ();
Utcusers users = (utcusers) request.getsession (). getattribute ("Utcusers");
Insert the record into the Flwo table flow.setkq_id (OrderID);
Flow.setkq_state (String.valueof (KeyRequestAttr.KqStateEnum.cus_send.getStep ()));
Flow.setkq_state_to (String.valueof (KeyRequestAttr.KqStateEnum.verify.getStep ()));
Flow.setis_pass (Yesnoenum.y.getcode ()); FLOW.SETUSER_ID (users.getusER_ID ());
Flow.setuser_id_from (users.getuser_id ());
Flow.setoptimer (Dateoperate.getdatetime ());
int flownum = Flowdao.save (flow);
Logger.info ("Scan two-dimensional code submission result: n=" +n+ "; flownum=" +flownum);
if (n>0) {b = true;
RETs = "Receive Order success in UTC";
Logger.info ("Receive order successfully in UTC");
else{RETs = "Failed to receive order in UTC";
Logger.info ("Failed to receive order in UTC");
} else{RETs = "Order query failed";
Logger.info ("Order query failed");
} else{RETs = "The order number in two-dimensional code is empty";
Logger.error ("The order number in two-dimensional code is empty");
} else{rets = "Two-dimensional code content is empty";
Logger.error ("Two-dimensional code content is empty");
} catch (Exception e) {e.printstacktrace ();
RETs = E.getmessage ();
Logger.error (E.getmessage ());
jsonobject ret = new Jsonobject ();
Ret.put ("flag", b);
Ret.put ("info", rets);
PrintWriter write = Response.getwriter ();
Write.write (Ret.tostring ());
Write.flush (); }
}