饭店点菜系统部分代码展示(简历用)

订单消息监听模块图:
饭店点菜系统部分代码展示(简历用)_第1张图片
饭店管理端订单消息监听模块前端ajax代码:

setInterval(reloadNews, 5000);
function reloadNews(){
$.ajax({
url: "reloadnews",
type: "get",
success: function(data){
data = data.split("-----");
var orders = JSON.parse(data[0]);
var notes = JSON.parse(data[1]);

var ots = '订单编号:'
+ '桌号:'
+ '订单总价:'
+ '操作:';
$.each(orders, function(i, order){
ots += ''+order.oid+''
+''+order.tid+''
+'¥'+order.tprice+''
+''
+'+order.oid+'&tid='+order.tid+'">查看'
+'';
});

var nts = '消息编号:'
+'消息内容:'
+'操作:';
$.each(notes, function(i, note){
nts += ''+note.nid+''
+''+note.info+''
+''
+'';
});
$(".orders").html(ots);
$(".notes").html(nts);
}
});
}

饭店管理端订单消息监听模块后端代码:
servlet:

public class ReloadNewsServlet extends HttpServlet {

private static final long serialVersionUID = 1L;
private IOrderService orderservice = new IOrderServiceImpl();
private INotesService notesservice = new INotesServiceImpl();

//后端获取消息页面需要的消息信息

@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
req.setCharacterEncoding("utf-8");
resp.setContentType("text/html;charset=utf-8");

List<Order> orders = orderservice.getNotPayOrder();
List<Notes> notes = notesservice.getNotes();

JSONArray ojsonArray = JSONArray.fromObject(orders);
JSONArray njsonArray = JSONArray.fromObject(notes);
String data = ojsonArray.toString()+"-----"+njsonArray.toString();
resp.getWriter().println(data);
}
}

service:

//把dao的到的数据库信息转化为JavaBean

public List<Order> getNotPayOrder() {
List<Map<String, Object>> os = orderdao.getNotPayOrder();
List<Order> orders = new ArrayList<Order>();
if(os.isEmpty()) return orders;

for(Map<String, Object> o : os) {
int oid = (int)o.get("oid");
int uid = (int)o.get("uid");
int tid = (int)o.get("tid");
int tprice = (int)o.get("totalprice");
Date orderdate = new Date(((java.sql.Date)o.get("orderdate")).getTime());
int orderstatus = (int)o.get("orderstatus");

Order order = new Order(oid,uid,tid,tprice,orderdate,orderstatus); 
orders.add(order);
}
return orders;
}

//把dao的到的数据库信息转化为JavaBean

public List<Notes> getNotes() {
List<Map<String, Object>> ns = notesdao.getNotes();
List<Notes> notes = new ArrayList<Notes>();
for(Map<String, Object> n:ns) {
int nid = (int)n.get("nid");
String noteinfo = (String)n.get("noteinfo");

notes.add(new Notes(nid, noteinfo));
}
return notes;
}

dao:

//从数据库获取尚未支付的订单
public List<Map<String, Object>> getNotPayOrder() {
String sql = "select oid,uid,tid,totalprice,orderdate,orderstatus from orders where orderstatus=0";
List<Map<String, Object>> orders = DBHelper.doQuery(sql);
return orders;
}

//从数据库获取未处理的消息
public List<Map<String, Object>> getNotes() {
String sql = "select nid,noteinfo from notes where notestatus=0";
List<Map<String, Object>> notes = DBHelper.doQuery(sql);
return notes;
}

你可能感兴趣的:(J2EE)