Skip to content

Commit

Permalink
完成了用户评价功能
Browse files Browse the repository at this point in the history
  • Loading branch information
lishangpeng committed Oct 14, 2018
1 parent 122b703 commit befe2cf
Show file tree
Hide file tree
Showing 8 changed files with 124 additions and 12 deletions.
2 changes: 1 addition & 1 deletion .recommenders/caches/identified-project-coordinates.json
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{}
[[{"location":"C:\\Users\\12149\\.m2\\repository\\javax\\servlet\\javax.servlet-api\\3.1.0\\javax.servlet-api-3.1.0.jar","type":"JAR","hints":{}},"javax.servlet:javax.servlet-api:3.1.0"],[{"location":"E:\\DingcanXitong\\lsp-Service","type":"PROJECT","hints":{"PROJECT_NAME":"lsp-Service"}},"lspa.top:lsp-Service:0.0.1"],[{"location":"E:\\D\\Java\\jdk1.8.0_51","type":"JRE","hints":{}},"jre:jre:1.8.0"],[{"location":"C:\\Users\\12149\\.m2\\repository\\org\\springframework\\spring-webmvc\\4.3.2.RELEASE\\spring-webmvc-4.3.2.RELEASE.jar","type":"JAR","hints":{}},"ABSENT"],[{"location":"E:\\DingcanXitong\\lsp-Pojo","type":"PROJECT","hints":{"PROJECT_NAME":"lsp-Pojo"}},"lspa.top:lsp-Pojo:0.0.1"]]
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,9 @@
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;
import java.util.UUID;

import javax.servlet.http.Cookie;
Expand All @@ -25,22 +23,28 @@
import org.apache.solr.common.SolrDocument;
import org.apache.solr.common.SolrDocumentList;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.propertyeditors.CustomDateEditor;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.WebDataBinder;
import org.springframework.web.bind.annotation.InitBinder;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.ModelAndViewDefiningException;

import com.github.pagehelper.PageInfo;

import top.lsp.util.AjaxResult;
import top.lsp.util.CommonUtils;
import top.lsp.util.ImageCodeUtils;
import top.lsp.util.JedisUtils;
import top.lspa.pojo.Comment;
import top.lspa.pojo.Hotel;
import top.lspa.pojo.Order;
import top.lspa.pojo.Room;
import top.lspa.pojo.User;
import top.lspa.service.CommentService;
import top.lspa.service.HotelService;
import top.lspa.service.OrderService;
import top.lspa.service.RoomService;
Expand All @@ -62,6 +66,9 @@ public class UserController {
@Autowired
private RoomService roomService;

@Autowired
private CommentService commentService;

@RequestMapping(value="/register",method=RequestMethod.GET)
public ModelAndView registerPage() {
ModelAndView modelAndView = new ModelAndView("user/register");
Expand Down Expand Up @@ -301,6 +308,7 @@ public ModelAndView userOrder(HttpServletRequest req,Integer curr) throws ParseE
}

//提供一个方法判断订单状态(已经废弃)
@Deprecated
private Map<String,String> orderType(List<Order> orderList){
Map<String,String> orderType = new HashMap<>();
//orderId type
Expand Down Expand Up @@ -345,4 +353,64 @@ private Map<String,String> orderType(List<Order> orderList){

return orderType;
}

@InitBinder
protected void initBinder(WebDataBinder binder) {
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
binder.registerCustomEditor(Date.class, new CustomDateEditor(dateFormat, true));
}

@RequestMapping(value="/comment",method=RequestMethod.GET)
public ModelAndView commentPage(Long hotelId,Long roomId,Date checkInDate,Date checkOutDate) {
ModelAndView modelAndView = new ModelAndView("/user/comment");
modelAndView.addObject("hotelId", hotelId);
modelAndView.addObject("roomId",roomId);
modelAndView.addObject("checkInDate",checkInDate);
modelAndView.addObject("checkOutDate", checkOutDate);
return modelAndView;
}

@RequestMapping(value="/comment",method=RequestMethod.POST)
public ModelAndView commentSubmit(Order order,String comment,HttpServletResponse resp,HttpServletRequest req) throws IOException {
resp.setCharacterEncoding("UTF-8");
resp.setContentType("text/html;charset=UTF-8");
if (comment == null) {
resp.getWriter().print("<script type='text/javascript'>alert('评论不能为空');history.go(-1);</script>");
return null;
}
//判断这个用户能否评价这个酒店
User user = (User) req.getSession().getAttribute("user");
if (user == null) {
resp.getWriter().print("<script type='text/javascript'>alert('请点击下方登录');history.go(-1);</script>");
return null;
}

order.setUserId(user.getId());
List<Boolean> list = orderService.selectPayOrNot(order);
boolean flag = false;
for(Boolean b : list) {
if (b) {
flag = true;
break;
}
}
if (!flag) {
resp.getWriter().print("<script type='text/javascript'>alert('你不能评价该酒店');history.go(-1);</script>");
return null;
}

Comment pojo = new Comment();
pojo.setComment(comment);
pojo.setCreateTime(new Date());
pojo.setHotelId(order.getHotelId());
pojo.setPhoneNum(user.getPhoneNum());
pojo.setRoomId(order.getRoomId());
Room room = roomService.selectOne(order.getRoomId());
pojo.setRoomName(room.getRoomName());
pojo.setUserId(user.getId());
commentService.insert(pojo);

ModelAndView modelAndView = new ModelAndView("redirect:/user/userOrder");
return modelAndView;
}
}
52 changes: 45 additions & 7 deletions lsp-Front/src/main/webapp/WEB-INF/jsp/user/comment.jsp
Original file line number Diff line number Diff line change
@@ -1,12 +1,50 @@
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>评论</title>
</head>
<%@taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<%@include file="../header.jsp" %>
<script type="text/javascript">
$(function(){
$("#commit").click(function(){
$("form").submit();
})
})
</script>
<style type="text/css">
input[type="file"]{
height:100px;
width:100%;
}
input[type="text"]{
word-break: break-all;
}
</style>
<body>


<div class="header">
<a href="<%=contxtPath %>/" class="home">
<span class="header-icon header-icon-home"></span>
<span class="header-name">主页</span>
</a>
<div class="title" id="titleString"></div>
<a href="javascript:history.go(-1);" class="back">
<span class="header-icon header-icon-return"></span>
<span class="header-name">返回</span>
</a>
</div>
<div class="container width80 pt20">
<form action="<%=contxtPath%>/user/comment" method="post">
<input type="hidden" name="hotelId" value="${hotelId }"/>
<input type="hidden" name="roomId" value="${roomId }"/>
<fmt:formatDate value="${checkInDate }" var="inDate" pattern="yyyy-MM-dd"/>
<fmt:formatDate value="${checkOutDate }" var="outDate" pattern="yyyy-MM-dd"/>
<input type="hidden" name="checkInDate" value="${inDate }"/>
<input type="hidden" name="checkOutDate" value="${outDate }"/>
<label>评论:</label><textarea style="width:98%;height:100px" name="comment" id="comment"></textarea>
<div class="control-group">
<button onClick="commit" id="commit" class="btn-large green button width100" style="margin-top:30px" >评论</button>
</div>
</form>
<%@include file="../footer.jsp" %>
</div>
</body>
</html>
2 changes: 1 addition & 1 deletion lsp-Front/src/main/webapp/WEB-INF/jsp/user/register.jsp
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
</div>


<div class="container width80 pt20">
<div class="container width80 pt20">
<form name="aspnetForm" method="post" action="<%=contxtPath %>/user/register" id="aspnetForm" class="form-horizontal">

<!-- 利用腾讯api 获取用户的地理位置 -->
Expand Down
2 changes: 1 addition & 1 deletion lsp-Front/src/main/webapp/WEB-INF/jsp/user/userOrder.jsp
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@
<a href="javascript:void(0)">
<c:out value="${order.orderType }"></c:out>
</a>
<a href="#">评论</a>
<a href="<%=contxtPath %>/user/comment?hotelId=${order.hotelId }&roomId=${order.roomId }&checkInDate=${inDate }&checkOutDate=${outDate}">评论</a>
<br/>
</c:if>
<c:if test="${order.orderType eq '已失效' }">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,9 @@
<if test="roomId!=null">and roomId=#{roomId}</if>
<if test="roomName!=null">and roomName like #{roomName}</if>
</select>

<insert id="insert" parameterType="Comment">
insert into t_comments(hotelId,userId,createTime,comment,roomId,isDeleted,roomName,phoneNum)
values(#{hotelId},#{userId},#{createTime},#{comment},#{roomId},0,#{roomName},#{phoneNum})
</insert>
</mapper>
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
public class CommentService extends BaseService<Comment>{

public PageInfo<Comment> page(Integer curr,int pageSize,Long hotelId){
PageHelper.orderBy("createTime desc");
PageHelper.startPage(curr, pageSize);
Comment comment = new Comment();
comment.setHotelId(hotelId);
Expand Down

0 comments on commit befe2cf

Please sign in to comment.