diff --git a/src/main/java/com/travel/servlet/TopHotServlet.java b/src/main/java/com/travel/servlet/TopHotServlet.java index 953b3ed2decea5a3d76df7d37193890a852548c7..eb971c069c46e5fb9bdea863ef4133ecd87ab972 100644 --- a/src/main/java/com/travel/servlet/TopHotServlet.java +++ b/src/main/java/com/travel/servlet/TopHotServlet.java @@ -1,7 +1,6 @@ package com.travel.servlet; import java.io.IOException; -import java.util.Collections; import java.util.List; import javax.servlet.ServletException; @@ -25,7 +24,6 @@ import com.travel.entities.GoodsEntity; import com.travel.entities.Hotel; import com.travel.entities.Restaurant; import com.travel.entities.Spot; -import com.travel.struts.form.UserForm; /** * Servlet implementation class TopHotServlet @@ -38,20 +36,18 @@ public class TopHotServlet extends HttpServlet { */ public TopHotServlet() { super(); - // TODO Auto-generated constructor stub } /** - * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse - * response) + * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response) */ + @Override protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { - // TODO Auto-generated method stub -// String type = request.getParameter("type"); + // String type = request.getParameter("type"); String sqlSpot1 = "SELECT AVG(a.rating) spotAvgRating, COUNT(1) spotRatingCount, b.shop_url spotUrl, a.spotId spotId, a.spotName spotName FROM tour a, spot b WHERE 1=1 and a.spotId=b.shop_id and a.date >= DATE('2017-03-01') AND a.date <= DATE('2017-03-31') GROUP BY a.spotId, a.spotName,b.shop_url ORDER BY spotAvgRating DESC LIMIT 0,10"; String sqlSpot2 = "SELECT AVG(a.rating) spotAvgRating, COUNT(1) spotRatingCount, b.shop_url spotUrl, a.spotId spotId, a.spotName spotName FROM tour a, spot b WHERE 1=1 and a.spotId=b.shop_id and a.date >= DATE('2017-03-01') AND a.date <= DATE('2017-03-31') GROUP BY a.spotId, a.spotName,b.shop_url ORDER BY spotRatingCount DESC LIMIT 0,10"; - + String sqlRestaurant1 = "select a.shopName shopName, a.shopUrl shopUrl,a.shopAddress shopAddress, a.shopTell shopTell, a.shopLat shopLat, a.shopLng shopLng, a.shopOpenTime shopOpenTime, a.shopPersonAve shopPersonAve, a.shopTaste shopTaste, a.shopEnvironment shopEnvironment, a.shopService shopService, a.shopStar shopStar, a.shopRecommendCook shopRecommendCook from shopbaseinfo a where 1=1 and a.shopPersonAve >1 order by a.shopTaste DESC limit 0,10"; String sqlRestaurant2 = "select a.shopName shopName, a.shopUrl shopUrl,a.shopAddress shopAddress, a.shopTell shopTell, a.shopLat shopLat, a.shopLng shopLng, a.shopOpenTime shopOpenTime, a.shopPersonAve shopPersonAve, a.shopTaste shopTaste, a.shopEnvironment shopEnvironment, a.shopService shopService, a.shopStar shopStar, a.shopRecommendCook shopRecommendCook from shopbaseinfo a where 1=1 and a.shopPersonAve >1 order by a.shopEnvironment DESC limit 0,10"; String sqlRestaurant3 = "select a.shopName shopName, a.shopUrl shopUrl,a.shopAddress shopAddress, a.shopTell shopTell, a.shopLat shopLat, a.shopLng shopLng, a.shopOpenTime shopOpenTime, a.shopPersonAve shopPersonAve, a.shopTaste shopTaste, a.shopEnvironment shopEnvironment, a.shopService shopService, a.shopStar shopStar, a.shopRecommendCook shopRecommendCook from shopbaseinfo a where 1=1 and a.shopPersonAve >1 order by a.shopService DESC limit 0,10"; @@ -59,7 +55,7 @@ public class TopHotServlet extends HttpServlet { String sqlHotel1 = "select a.hotel_name hotelName, a.url hotelUrl,a.comment_point hotelCommentPoint, a.comment_score hotelCommentScore, a.comment_count hotelCommentCount from hotel a where 1=1 and a.comment_count >1 order by a.comment_point DESC limit 0,10"; String sqlHotel2 = "select a.hotel_name hotelName, a.url hotelUrl,a.comment_point hotelCommentPoint, a.comment_score hotelCommentScore, a.comment_count hotelCommentCount from hotel a where 1=1 and a.comment_count >1 order by a.comment_score DESC limit 0,10"; String sqlHotel3 = "select a.hotel_name hotelName, a.url hotelUrl,a.comment_point hotelCommentPoint, a.comment_score hotelCommentScore, a.comment_count hotelCommentCount from hotel a where 1=1 and a.comment_count >1 order by a.comment_count DESC limit 0,10"; - + String sqlLocalGoods1 = "select a.shop_name shopName, a.shop_url shopUrl,a.item_name itemName, a.item_url itemUrl, a.item_sale itemSale, a.item_rate_num itemRateNum from good_item a where 1=1 and a.item_sale >1 order by a.item_sale DESC limit 0,14"; String sqlLocalGoods2 = "select a.shop_name shopName, a.shop_url shopUrl,a.item_name itemName, a.item_url itemUrl, a.item_sale itemSale, a.item_rate_num itemRateNum from good_item a where 1=1 and a.item_sale >1 order by a.item_rate_num DESC limit 0,14"; @@ -70,26 +66,24 @@ public class TopHotServlet extends HttpServlet { List spots1 = spotDao.getTopSpots(sqlSpot1); List spots2 = spotDao.getTopSpots(sqlSpot2); - - + List restaurants1 = restaurantDao.getTopResturant(sqlRestaurant1); List restaurants2 = restaurantDao.getTopResturant(sqlRestaurant2); List restaurants3 = restaurantDao.getTopResturant(sqlRestaurant3); - + List hotels1 = hotelDao.getTopHotels(sqlHotel1); List hotels2 = hotelDao.getTopHotels(sqlHotel2); List hotels3 = hotelDao.getTopHotels(sqlHotel3); - + List goodsEntities1 = localSpecialGoods.getTopGoods(sqlLocalGoods1); List goodsEntities2 = localSpecialGoods.getTopGoods(sqlLocalGoods2); - - JSONArray jsonArray = new JSONArray();//最外层json - + + JSONArray jsonArray = new JSONArray();// 最外层json + JSONArray jsonArray11 = new JSONArray(); JSONArray jsonArray12 = new JSONArray(); - - for (Spot u : spots1) { + for (Spot u : spots1) { JSONObject json = new JSONObject(); try { json.put("spotName", u.getSpotName()); @@ -100,7 +94,6 @@ public class TopHotServlet extends HttpServlet { } catch (Exception e) { e.printStackTrace(); } - jsonArray11.put(json); } for (Spot u : spots2) { @@ -115,13 +108,11 @@ public class TopHotServlet extends HttpServlet { } catch (Exception e) { e.printStackTrace(); } - jsonArray12.put(json); } - + JSONArray jsonArray21 = new JSONArray(); for (Restaurant u : restaurants1) { - JSONObject json = new JSONObject(); try { json.put("shopName", u.getShopName()); @@ -137,10 +128,9 @@ public class TopHotServlet extends HttpServlet { } catch (Exception e) { e.printStackTrace(); } - jsonArray21.put(json); } - + JSONArray jsonArray22 = new JSONArray(); for (Restaurant u : restaurants2) { @@ -159,10 +149,9 @@ public class TopHotServlet extends HttpServlet { } catch (Exception e) { e.printStackTrace(); } - jsonArray22.put(json); } - + JSONArray jsonArray23 = new JSONArray(); for (Restaurant u : restaurants3) { @@ -181,10 +170,9 @@ public class TopHotServlet extends HttpServlet { } catch (Exception e) { e.printStackTrace(); } - jsonArray23.put(json); } - + JSONArray jsonArray31 = new JSONArray(); for (Hotel u : hotels1) { @@ -201,7 +189,7 @@ public class TopHotServlet extends HttpServlet { jsonArray31.put(json); } - + JSONArray jsonArray32 = new JSONArray(); for (Hotel u : hotels2) { @@ -218,7 +206,7 @@ public class TopHotServlet extends HttpServlet { jsonArray32.put(json); } - + JSONArray jsonArray33 = new JSONArray(); for (Hotel u : hotels3) { @@ -235,7 +223,7 @@ public class TopHotServlet extends HttpServlet { jsonArray33.put(json); } - + JSONArray jsonArray41 = new JSONArray(); for (GoodsEntity u : goodsEntities1) { @@ -253,7 +241,7 @@ public class TopHotServlet extends HttpServlet { jsonArray41.put(json); } - + JSONArray jsonArray42 = new JSONArray(); for (GoodsEntity u : goodsEntities2) { @@ -271,8 +259,7 @@ public class TopHotServlet extends HttpServlet { jsonArray42.put(json); } - - + JSONObject jbSpot = new JSONObject(); JSONObject jbRestaurant = new JSONObject(); JSONObject jbHotel = new JSONObject(); @@ -280,11 +267,11 @@ public class TopHotServlet extends HttpServlet { try { jbSpot.put("spotAvgRatingQuery", jsonArray11); jbSpot.put("spotRatingCountQuery", jsonArray12); - + jbRestaurant.put("shopTasteQuery", jsonArray21); jbRestaurant.put("shopEnvironmentQuery", jsonArray22); jbRestaurant.put("shopServiceQuery", jsonArray23); - + jbHotel.put("commentPointQuery", jsonArray31); jbHotel.put("commentScoreQuery", jsonArray32); jbHotel.put("commentCountQuery", jsonArray33); @@ -301,16 +288,16 @@ public class TopHotServlet extends HttpServlet { jsonArray.put(jbHotel); jsonArray.put(jbGoods); response.setCharacterEncoding("utf-8"); - -// System.out.println(jsonArray.toString()); + + // System.out.println(jsonArray.toString()); response.getWriter().append(jsonArray.toString()); -// response.getWriter().append("Served at: ").append(request.getContextPath()); + // response.getWriter().append("Served at: ").append(request.getContextPath()); } /** - * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse - * response) + * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response) */ + @Override protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { // TODO Auto-generated method stub