Ver código fonte

添加个人评论

liu 2 anos atrás
pai
commit
d8ef856537

+ 194 - 0
mhotel/src/com/happy/Model/BookingComment.java

@@ -0,0 +1,194 @@
+package com.happy.Model;
+
+
+import lombok.Builder;
+
+@Builder
+public class BookingComment {
+    //    主键
+    private Integer id;
+
+    //    回复评论id
+    private String commentId;
+
+    //    评论订单id
+    private String bookingId;
+
+    //    评论民宿id
+    private String hotelId;
+
+    //    评论房型id
+    private String houseId;
+
+    //    内容
+    private String content;
+
+    //    评价状态
+    private String commentStatus;
+
+    //    总评分
+    private Double score;
+
+    //    卫生评分
+    private Double scoreWs;
+
+    //    服务评分
+    private Double scoreFw;
+
+    //    设施评分
+    private Double scoreSs;
+
+    //    位置评分
+    private Double scoreWz;
+
+    //    创建人
+    private Integer createId;
+
+    private String createUsername;
+
+    //    创建时间
+    private String createDate;
+
+    //    修改时间
+    private String modifyDate;
+
+    //    状态(0删除 1正常)
+    private String status;
+
+
+    public Integer getId() {
+        return id;
+    }
+
+    public void setId(Integer id) {
+        this.id = id;
+    }
+
+    public String getCommentId() {
+        return commentId;
+    }
+
+    public void setCommentId(String commentId) {
+        this.commentId = commentId;
+    }
+
+    public String getBookingId() {
+        return bookingId;
+    }
+
+    public void setBookingId(String bookingId) {
+        this.bookingId = bookingId;
+    }
+
+    public String getHotelId() {
+        return hotelId;
+    }
+
+    public void setHotelId(String hotelId) {
+        this.hotelId = hotelId;
+    }
+
+    public String getHouseId() {
+        return houseId;
+    }
+
+    public void setHouseId(String houseId) {
+        this.houseId = houseId;
+    }
+
+    public String getContent() {
+        return content;
+    }
+
+    public void setContent(String content) {
+        this.content = content;
+    }
+
+    public String getCommentStatus() {
+        return commentStatus;
+    }
+
+    public void setCommentStatus(String commentStatus) {
+        this.commentStatus = commentStatus;
+    }
+
+    public Double getScore() {
+        return score;
+    }
+
+    public void setScore(Double score) {
+        this.score = score;
+    }
+
+    public Double getScoreWs() {
+        return scoreWs;
+    }
+
+    public void setScoreWs(Double scoreWs) {
+        this.scoreWs = scoreWs;
+    }
+
+    public Double getScoreFw() {
+        return scoreFw;
+    }
+
+    public void setScoreFw(Double scoreFw) {
+        this.scoreFw = scoreFw;
+    }
+
+    public Double getScoreSs() {
+        return scoreSs;
+    }
+
+    public void setScoreSs(Double scoreSs) {
+        this.scoreSs = scoreSs;
+    }
+
+    public Double getScoreWz() {
+        return scoreWz;
+    }
+
+    public void setScoreWz(Double scoreWz) {
+        this.scoreWz = scoreWz;
+    }
+
+    public Integer getCreateId() {
+        return createId;
+    }
+
+    public void setCreateId(Integer createId) {
+        this.createId = createId;
+    }
+
+    public String getCreateUsername() {
+        return createUsername;
+    }
+
+    public void setCreateUsername(String createUsername) {
+        this.createUsername = createUsername;
+    }
+
+    public String getCreateDate() {
+        return createDate;
+    }
+
+    public void setCreateDate(String createDate) {
+        this.createDate = createDate;
+    }
+
+    public String getModifyDate() {
+        return modifyDate;
+    }
+
+    public void setModifyDate(String modifyDate) {
+        this.modifyDate = modifyDate;
+    }
+
+    public String getStatus() {
+        return status;
+    }
+
+    public void setStatus(String status) {
+        this.status = status;
+    }
+}

+ 265 - 0
mhotel/src/com/happy/action/AppBookingCommentAction.java

@@ -0,0 +1,265 @@
+package com.happy.action;
+
+import com.happy.Model.BookingComment;
+import com.happy.Until.Func;
+import com.happy.Until.ResUtil;
+import com.happy.dto.OrderRateDto;
+import com.happy.service.BookingCommentService;
+import com.opensymphony.xwork2.ActionSupport;
+import com.alibaba.fastjson.JSONObject;
+import org.apache.struts2.ServletActionContext;
+import org.apache.struts2.interceptor.ServletRequestAware;
+import org.springframework.web.bind.annotation.RequestBody;
+
+
+import javax.annotation.Resource;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+import java.util.List;
+
+
+/**
+ * 评价
+ */
+
+public class AppBookingCommentAction extends ActionSupport implements ServletRequestAware {
+
+    private HttpServletRequest request;
+
+    public HttpServletResponse response;
+
+    public HttpServletRequest getRequest() {
+        return request;
+    }
+
+    public void setRequest(HttpServletRequest request) {
+        this.request = request;
+    }
+
+    @Override
+    public void setServletRequest(HttpServletRequest request) {
+        this.request = request;
+    }
+
+    public HttpServletResponse getResponse() {
+        return response;
+    }
+
+    public void setResponse(HttpServletResponse response) {
+        this.response = response;
+    }
+
+
+    @Resource
+    public BookingCommentService bookingCommentService;
+
+
+    //    评论订单id
+    public String bookingId;
+
+    //    评论民宿id
+    public String hotelId;
+
+    //    评论房型id
+    public String houseId;
+
+    //    内容
+    public String content;
+
+    //    总评分
+    public Double score;
+
+    //    卫生评分
+    public Double scoreWs;
+
+    //    服务评分
+    public Double scoreFw;
+
+    //    设施评分
+    public Double scoreSs;
+
+    //    位置评分
+    public Double scoreWz;
+
+    //    创建人
+    public Integer createId;
+
+    public String createUsername;
+
+    //    创建时间
+    public String createDate;
+
+    //    修改时间
+    public String modifyDate;
+
+    public List<String> pictureList;
+
+    public List<String> getPictureList() {
+        return pictureList;
+    }
+
+    public void setPictureList(List<String> pictureList) {
+        this.pictureList = pictureList;
+    }
+
+    public String getBookingId() {
+        return bookingId;
+    }
+
+    public void setBookingId(String bookingId) {
+        this.bookingId = bookingId;
+    }
+
+    public String getHotelId() {
+        return hotelId;
+    }
+
+    public void setHotelId(String hotelId) {
+        this.hotelId = hotelId;
+    }
+
+    public String getHouseId() {
+        return houseId;
+    }
+
+    public void setHouseId(String houseId) {
+        this.houseId = houseId;
+    }
+
+    public String getContent() {
+        return content;
+    }
+
+    public void setContent(String content) {
+        this.content = content;
+    }
+
+    public Double getScore() {
+        return score;
+    }
+
+    public void setScore(Double score) {
+        this.score = score;
+    }
+
+    public Double getScoreWs() {
+        return scoreWs;
+    }
+
+    public void setScoreWs(Double scoreWs) {
+        this.scoreWs = scoreWs;
+    }
+
+    public Double getScoreFw() {
+        return scoreFw;
+    }
+
+    public void setScoreFw(Double scoreFw) {
+        this.scoreFw = scoreFw;
+    }
+
+    public Double getScoreSs() {
+        return scoreSs;
+    }
+
+    public void setScoreSs(Double scoreSs) {
+        this.scoreSs = scoreSs;
+    }
+
+    public Double getScoreWz() {
+        return scoreWz;
+    }
+
+    public void setScoreWz(Double scoreWz) {
+        this.scoreWz = scoreWz;
+    }
+
+    public Integer getCreateId() {
+        return createId;
+    }
+
+    public void setCreateId(Integer createId) {
+        this.createId = createId;
+    }
+
+    public String getCreateUsername() {
+        return createUsername;
+    }
+
+    public void setCreateUsername(String createUsername) {
+        this.createUsername = createUsername;
+    }
+
+    public String getCreateDate() {
+        return createDate;
+    }
+
+    public void setCreateDate(String createDate) {
+        this.createDate = createDate;
+    }
+
+    public String getModifyDate() {
+        return modifyDate;
+    }
+
+    public void setModifyDate(String modifyDate) {
+        this.modifyDate = modifyDate;
+    }
+
+    /**
+     * 添加评论
+     */
+    public JSONObject orderRate() {
+        JSONObject jsonObject = new JSONObject();
+        if (score == null || score < 0 || scoreFw == null || scoreFw < 0 || scoreSs == null || scoreSs < 0 || scoreWs == null || scoreWs < 0 || scoreWz == null || scoreWz < 0 || bookingId == null || hotelId == null || houseId == null) {
+            jsonObject.put("code", 400);
+            jsonObject.put("message", "未传入orderRateDto数据---orderRate");
+            ResUtil.writeJson(ServletActionContext.getResponse(), jsonObject.toString());
+            return null;
+        }
+
+        BookingComment bookingComment = BookingComment.builder().bookingId(bookingId)
+                .hotelId(hotelId).houseId(houseId).content(content)
+                .score(score).scoreWs(scoreWs).scoreFw(scoreFw)
+                .scoreSs(scoreSs).scoreWz(scoreWz).createId(createId)
+                .createUsername(createUsername).createDate(createDate)
+                .modifyDate(modifyDate).build();
+
+
+        int a = bookingCommentService.orderRate(bookingComment,pictureList);
+
+
+        if (a>0) {
+            jsonObject.put("code", 200);
+            jsonObject.put("message", "添加成功");
+            ResUtil.writeJson(ServletActionContext.getResponse(), jsonObject.toString());
+            return null;
+        }
+        jsonObject.put("message", "未知异常");
+        jsonObject.put("code", 205);
+        ResUtil.writeJson(ServletActionContext.getResponse(), jsonObject.toString());
+        return null;
+    }
+
+
+    /**
+     * 评价列表
+     *
+     * @return
+     */
+    public JSONObject evaluateList() {
+        JSONObject jsonObject = new JSONObject();
+        if (Func.checkNull(hotelId)) {
+            jsonObject.put("code", 400);
+            jsonObject.put("message", "未传入hotel_id数据---evaluateList");
+            ResUtil.writeJson(ServletActionContext.getResponse(), jsonObject.toString());
+            return null;
+        }
+
+
+        return null;
+
+    }
+
+
+}

+ 8 - 0
mhotel/src/com/happy/dao/BookingCommentDao.java

@@ -0,0 +1,8 @@
+package com.happy.dao;
+
+import com.happy.Model.BookingComment;
+
+public interface BookingCommentDao {
+    String insertBookingComment(BookingComment bookingComment);
+
+}

+ 76 - 0
mhotel/src/com/happy/dao/impl/BookingCommentDaoImpl.java

@@ -0,0 +1,76 @@
+package com.happy.dao.impl;
+
+import com.happy.Model.BookingComment;
+import com.happy.Until.UUIDUtil;
+import com.happy.dao.BookingCommentDao;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.jdbc.core.namedparam.MapSqlParameterSource;
+import org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate;
+import org.springframework.stereotype.Repository;
+
+@Repository("BookingCommentDao")
+public class BookingCommentDaoImpl implements BookingCommentDao {
+    @Autowired
+    private NamedParameterJdbcTemplate namedParameterJdbcTemplate;
+
+    public NamedParameterJdbcTemplate getNamedParameterJdbcTemplate() {
+        return namedParameterJdbcTemplate;
+    }
+
+    public void setNamedParameterJdbcTemplate(
+            NamedParameterJdbcTemplate namedParameterJdbcTemplate) {
+        this.namedParameterJdbcTemplate = namedParameterJdbcTemplate;
+    }
+
+    /**
+     * Ìí¼ÓÆÀ¼Û£¬²¢·µ»ØÖ÷¼ü
+     * @param bookingComment
+     * @return
+     */
+    @Override
+    public String insertBookingComment(BookingComment bookingComment) {
+        String sql = "insert into `booking_comment`(id,comment_id,booking_id,hotel_id,house_id,content,comment_status,score, score_ws,score_fw,score_ss,score_wz,create_id,create_username,create_date,modify_date,status) values(:id,:comment_id,:booking_id,:hotel_id,:house_id,:content,:comment_status,:score,:score_ws,:score_fw,:score_ss,:score_wz,:create_id,:create_username,:create_date,:modify_date,:status) ";
+        MapSqlParameterSource sps = new MapSqlParameterSource();
+        sps.addValue("comment_id", bookingComment.getCommentId());
+        sps.addValue("booking_id",bookingComment.getBookingId());
+        sps.addValue("hotel_id", bookingComment.getHotelId());
+        sps.addValue("house_id", bookingComment.getHouseId());
+        sps.addValue("content", bookingComment.getContent());
+        sps.addValue("comment_status",bookingComment.getCommentStatus());
+        sps.addValue("score", bookingComment.getScore());
+        sps.addValue("score_ws", bookingComment.getScoreWs());
+        sps.addValue("score_fw", bookingComment.getScoreFw());
+        sps.addValue("score_ss", bookingComment.getScoreSs());
+        sps.addValue("score_wz", bookingComment.getScoreWz());
+        sps.addValue("create_id", bookingComment.getCreateId());
+        sps.addValue("create_username",bookingComment.getCreateUsername() );
+        sps.addValue("create_date",bookingComment.getCreateDate());
+        sps.addValue("modify_date",bookingComment.getModifyDate());
+        sps.addValue("status", 1);
+
+        String id ="";
+        if(bookingComment.getId()==null){
+            id = UUIDUtil.generateID()+"";
+            sps.addValue("id", id);
+        }else{
+            id=bookingComment.getId()+"";
+            sps.addValue("id", id);
+        }
+        int num = 0;
+        try{
+            num = namedParameterJdbcTemplate.update(sql, sps);
+        }
+        catch(Exception e){
+            e.printStackTrace();
+        }
+        if (num>0) {
+            return id;
+        }else {
+            id=num+"";
+        }
+        return id;
+    }
+
+
+
+}

+ 37 - 0
mhotel/src/com/happy/dto/OrderRateDto.java

@@ -0,0 +1,37 @@
+package com.happy.dto;
+
+import com.happy.Model.BookingComment;
+import com.happy.Model.FileInfo;
+
+import java.util.List;
+
+public class OrderRateDto {
+    //         ¸½¼þ
+    private List<FileInfo> fileInfoList;
+//  ÆÀ¼Û
+    private BookingComment bookingComment;
+
+    public List<FileInfo> getFileInfoList() {
+        return fileInfoList;
+    }
+
+    public void setFileInfoList(List<FileInfo> fileInfoList) {
+        this.fileInfoList = fileInfoList;
+    }
+
+    public BookingComment getBookingComment() {
+        return bookingComment;
+    }
+
+    public void setBookingComment(BookingComment bookingComment) {
+        this.bookingComment = bookingComment;
+    }
+
+    @Override
+    public String toString() {
+        return "OrderRateDto{" +
+                "fileInfoList=" + fileInfoList +
+                ", bookingComment=" + bookingComment +
+                '}';
+    }
+}

+ 12 - 0
mhotel/src/com/happy/service/BookingCommentService.java

@@ -0,0 +1,12 @@
+package com.happy.service;
+
+import com.happy.Model.BookingComment;
+import com.happy.Model.FileInfo;
+
+import java.util.List;
+
+public interface BookingCommentService {
+
+
+    int orderRate( BookingComment bookingComment,List<String> pictureList);
+}

+ 2 - 0
mhotel/src/com/happy/service/FileService.java

@@ -78,4 +78,6 @@ public interface FileService {
      * 描述:批量上传图片
      */
     void uploadImp(List<File> fileList, HttpServletRequest request);
+
+    int batchInsertFile(List<FileInfo> fileInfoList);
 }

+ 66 - 0
mhotel/src/com/happy/service/impl/BookingCommentImplService.java

@@ -0,0 +1,66 @@
+package com.happy.service.impl;
+
+import com.happy.Model.BookingComment;
+import com.happy.Model.FileInfo;
+import com.happy.dao.BookingCommentDao;
+import com.happy.service.BookingCommentService;
+import com.happy.service.FileService;
+import org.springframework.stereotype.Service;
+import org.springframework.transaction.annotation.Transactional;
+
+import javax.annotation.Resource;
+import java.util.ArrayList;
+import java.util.List;
+
+@Service("BookingCommentService")
+
+public class BookingCommentImplService implements BookingCommentService {
+
+    @Resource
+    BookingCommentDao bookingCommentDao;
+
+    @Resource
+    FileService fileService;
+
+
+
+    /**
+     * 添加评论
+     *
+     * @param pictureList
+     * @param bookingComment
+     * @return
+     */
+    @Override
+    @Transactional(rollbackFor = Exception.class)
+    public int orderRate( BookingComment bookingComment,List<String> pictureList) {
+
+//        添加评论表并返回主键
+
+        String id = bookingCommentDao.insertBookingComment(bookingComment);
+        int i = 1;
+        if (pictureList.size() > 0) {
+            List<FileInfo> fileInfoList = new ArrayList<>();
+            for (String s : pictureList) {
+                String[] split = s.split("/");
+                String s1 = split[split.length-1];
+                FileInfo fileInfo = new FileInfo();
+                fileInfo.setLinkId(id);
+                fileInfo.setName(s1);
+                fileInfo.setUrl(s);
+
+                fileInfoList.add(fileInfo);
+            }
+
+            i = fileService.batchInsertFile(fileInfoList);
+        }
+        if (Long.valueOf(id) > 0 && i > 0) {
+            return i;
+        }else {
+            return 0;
+        }
+
+    }
+
+
+}

+ 9 - 0
mhotel/src/com/happy/service/impl/FileImplService.java

@@ -116,4 +116,13 @@ public class FileImplService implements FileService {
             }
         }
     }
+
+    @Override
+    public int batchInsertFile(List<FileInfo> fileInfoList) {
+        int i=0;
+        for (FileInfo fileInfo : fileInfoList) {
+            i=fileDao.insertFile(fileInfo);
+        }
+        return i;
+    }
 }

+ 1 - 0
mhotel/src/struts.xml

@@ -42,6 +42,7 @@
 		<action name="abk*" method = "{1}" class="com.happy.action.AppBookingAction"></action>
 		<action name="ahp*" method = "{1}" class="com.happy.action.AppHomePageAction"></action>
 		<action name="amp*" method = "{1}" class="com.happy.action.AppMePageAction"></action>
+		<action name="abca*" method = "{1}" class="com.happy.action.AppBookingCommentAction"></action>
 
 	</package>
 	<package name="interfaces" namespace="/interfaces" extends="struts-default">