Skip to content

Commit

Permalink
Merge pull request yzwish#9 from Tanviw/topic
Browse files Browse the repository at this point in the history
add function :send message to the questioner when question be answered
  • Loading branch information
Tanviw authored Jul 4, 2017
2 parents a6bccad + d4250c6 commit 1c16691
Show file tree
Hide file tree
Showing 15 changed files with 117 additions and 33 deletions.
13 changes: 2 additions & 11 deletions WebContent/css/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -172,13 +172,7 @@ i.googlepluse{
.top-menu ul li a.active{
color:#83774A;
}
.header-top {
background: rgba(255, 255, 255, 0.32);
padding: 2em 30px;
float: left;
width: 92%;
height:100px;
}

.banner-info h1 a{
color:#fff;
font-family: 'Niconne', cursive;
Expand Down Expand Up @@ -1244,10 +1238,7 @@ a.thumbnail.active, a.thumbnail:focus, a.thumbnail:hover {
.btn-primary {
border-color: #fff !important;
}
.btn-primary:hover, .btn-primary:focus, .btn-primary.focus, .btn-primary:active, .btn-primary.active, .open > .dropdown-toggle.btn-primary {
border-color: #FFF !important;
background-color: #a6192e !important;
}

.cmnt-icon-left a img {
width: 100%;
}
Expand Down
1 change: 1 addition & 0 deletions WebContent/css/topic.css
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
font-family: "Helvetica Neue", Helvetica, Arial, sans-serif;

}

#fix-modal-open{
padding-right:0 !important;
}
Expand Down
4 changes: 3 additions & 1 deletion WebContent/js/topic.js
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,9 @@ function answerQuestion(){
var thisQuesId=$("#questionId").val();
answer.answerUserId=$("#answerUserId").val();
answer.questionId=thisQuesId;
answer.answerContent=$("#answerContent").val()
answer.answerContent=$("#answerContent").val();
answer.questionUserId=$("#questionUserId").html();
answer.questionTitle=$("#question-title-for-mess").html();
var info = JSON.stringify(answer);
$.ajax({
type: "POST",
Expand Down
13 changes: 13 additions & 0 deletions WebContent/jsp/failed.jsp
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>发起话题失败</title>
</head>
<body>
同名话题已存在哦~
<a href="/yzwish/topic/showHotTopic">点此返回</a>
</body>
</html>
9 changes: 5 additions & 4 deletions WebContent/jsp/questionDetail.jsp
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@
</head>

<body id="fix-modal-open">
<div class="container" style="margin-top: 0">
<div class="container" style="margin-top: 0 ;min-height:600px;">
<div class="question-header">
<div class="row clearfix">
<div class="col-md-12 column">
Expand All @@ -76,10 +76,10 @@
<div class="row clearfix">
<div class="col-md-2 column">
<img src="../topicImages/avatar.jpg" width="100" height="100">
<p>${question.userId }</p>
<p><a id="questionUserId" href="/yzwish/comment/getUser.do?visitId=${question.userId }" target="_blank">${question.userId }</a></p>
</div>
<div class="col-md-7 column">
<h3>${question.quesTitle }</h3>
<h3 id="question-title-for-mess">${question.quesTitle }</h3>
<p>${question.quesContent }</p>
</div>
<div class="col-md-3 column">
Expand Down Expand Up @@ -173,7 +173,7 @@
style='background-color:${colors[colorIndex] }'>
<div class="answer-username">

<a href="#"> ${answer.answerUserId } </a>
<a href="/yzwish/comment/getUser.do?visitId=${answer.answerUserId }" target="_blank">${answer.answerUserId }</a>
<span>

<a id='modal-report-ans-${answer.answerId }' href='#modal-container-report-ans-${answer.answerId }'
Expand Down Expand Up @@ -302,6 +302,7 @@
</div>
</div>
</div>
<jsp:include page="down.jsp" />
<script src="../js/bootstrap.min.js"></script>
<script src="../js/topic.js"></script>
</body>
Expand Down
4 changes: 2 additions & 2 deletions WebContent/jsp/success.jsp
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
<title>发起话题成功</title>
</head>
<body>
发起话题成功!请等待管理员审核..
<a href="/yzwish/jsp/topicHome.jsp">点此返回</a>
<a href="/yzwish/topic/showHotTopic">点此返回</a>
</body>
</html>
6 changes: 3 additions & 3 deletions WebContent/jsp/topicDetail.jsp
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ $(document).ready(function(){
</head>

<body id="fix-modal-open">
<div class="container" style="margin-top:0">
<div class="container" style="margin-top:0;min-height:600px;">
<div class="row clearfix">
<div class="col-md-12 column topic-detail-banner">
<img src="${topic.topicBanner }" alt="banner" height="280" />
Expand Down Expand Up @@ -201,7 +201,7 @@ $(document).ready(function(){
</div>
<div class="col-md-2 column">
<span> <i class=" glyphicon glyphicon-user"></i> <span>
<a href="#" target="_blank">${question.userId }</a>
<a href="/yzwish/comment/getUser.do?visitId=${question.userId }" target="_blank">${question.userId }</a>
</span>
</span>
</div>
Expand Down Expand Up @@ -247,7 +247,7 @@ $(document).ready(function(){
</form>
</div>
</div>

<jsp:include page="down.jsp" />
<script src="../js/bootstrap.min.js"></script>
<script src="../js/topic.js"></script>
</body>
Expand Down
3 changes: 2 additions & 1 deletion WebContent/jsp/topicHome.jsp
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
</head>

<body id="fix-modal-open">
<div class="container">
<div class="container" style="min-height:600px;">
<div class="row clearfix">
<div class="col-md-2 colmn topic-lists-left">
<span class="topic-head-title"
Expand Down Expand Up @@ -172,6 +172,7 @@
</div>
</div>
</div>
<jsp:include page="down.jsp" />
<script src="../js/jquery.min.js"></script>
<script src="../js/bootstrap.min.js"></script>
<script src="../js/uploadPreview.js" type="text/javascript"></script>
Expand Down
1 change: 1 addition & 0 deletions WebContent/jsp/up.jsp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
<html lang="en">
<head>
<link rel="stylesheet" type="text/css" href="<%=request.getContextPath()%>/css/bootstrap.min.css">
<link href="../css/style.css" rel="stylesheet">
<link href="<%=request.getContextPath()%>/css/navf.css" rel='stylesheet' type='text/css' />
<link href="<%=request.getContextPath()%>/css/colrankf.css" rel='stylesheet' type='text/css' />
<link href="<%=request.getContextPath()%>/css/lbtf.css" rel='stylesheet' type='text/css' />
Expand Down
Binary file modified build/classes/com/controller/TopicController.class
Binary file not shown.
Binary file modified build/classes/com/dao/TopicDao.class
Binary file not shown.
Binary file modified build/classes/com/model/Answer.class
Binary file not shown.
8 changes: 7 additions & 1 deletion src/com/controller/TopicController.java
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,10 @@ public ModelAndView createTopic(Topic topic,HttpServletRequest request,HttpSessi
String result = TopicDao.createTopic(topic, userId);
if(result == "ok"){
return new ModelAndView("redirect:/jsp/success.jsp");
}else if(result =="error"){
return new ModelAndView("/showHotTopic");
}else{
return new ModelAndView("/jsp/topicHome");
return new ModelAndView("redirect:/jsp/failed.jsp");
}
}

Expand Down Expand Up @@ -137,6 +139,10 @@ public ModelAndView showQA(HttpServletRequest request,HttpSession session){
public @ResponseBody String answerQuestion(@RequestBody Answer answer, HttpSession session){
int duty = Integer.parseInt((String)session.getAttribute("duty"));
String result = TopicDao.answerQuestion(answer,duty);




return result;
}

Expand Down
72 changes: 64 additions & 8 deletions src/com/dao/TopicDao.java
Original file line number Diff line number Diff line change
Expand Up @@ -48,17 +48,32 @@ public static boolean uploadTopicPic(Topic topic){
}

}


//发起话题
public static String createTopic(Topic topic,String userId){

String sql2="SELECT * FROM topic WHERE topicName=?";
Connection conn = ConnectionManager.getInstance().getConnection();
PreparedStatement ptmt=null;
ResultSet rst=null;
try {
ptmt = conn.prepareStatement(sql2);
ptmt.setString(1, topic.getTopicName());
rst = ptmt.executeQuery();
//服务器错误
if(rst.next()){
return "topicName already exist!";
}
} catch (SQLException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
//上传话题banner和头像
if(!uploadTopicPic(topic)){
return "error";
}

Connection conn = ConnectionManager.getInstance().getConnection();
PreparedStatement ptmt=null;
ResultSet rst=null;
String sql="INSERT INTO topic VALUES (null,?,?,0,0,?,?,?)";
try{
ptmt = conn.prepareStatement(sql);
Expand Down Expand Up @@ -90,7 +105,7 @@ public static String createTopic(Topic topic,String userId){
public static String searchTopic(Topic topic){

String sql="SELECT topicId,topicName FROM topic WHERE topicState=1"
+ " AND topicName LIKE '%"+topic.getTopicName()+"%'";
+ " AND topicName LIKE '%"+topic.getTopicName()+"%' LIMIT 15 ;";
Connection conn = ConnectionManager.getInstance().getConnection();
PreparedStatement ptmt=null;
ResultSet rst=null;
Expand Down Expand Up @@ -431,10 +446,15 @@ public static ArrayList<Answer> showQA(int questionId){

}


//回答问题
public static String answerQuestion(Answer answer,int duty){
String sql="INSERT INTO answer VALUES (null,?,?,?,now(),0);";

String sqlMess="INSERT INTO message VALUES (null,?,?,now(),0);";
String messUserId=answer.getQuestionUserId();
String context="您的提问有新的回答:<a href='/yzwish/topic/showQA?questionId="+answer.getQuestionId()+"' target='_blank'>"+
answer.getQuestionTitle()+"</a>";
String result="";
Connection conn = ConnectionManager.getInstance().getConnection();
PreparedStatement ptmt=null;
ResultSet rst=null;
Expand Down Expand Up @@ -469,8 +489,18 @@ public static String answerQuestion(Answer answer,int duty){
double num = rst.getDouble("totalCurrency");
//每月奖励虚拟币上限100
if(num>=100){
//通知提问用户
ptmt = conn.prepareStatement(sqlMess);
ptmt.setString(1,messUserId);
ptmt.setString(2,context);
int res1=ptmt.executeUpdate();
if(res1==0){
return "error";
}else{

return "overflow";
}

return "overflow";
}


Expand All @@ -485,12 +515,38 @@ public static String answerQuestion(Answer answer,int duty){

return "error";
}else{
return "award";

//通知提问用户
ptmt = conn.prepareStatement(sqlMess);
ptmt.setString(1,messUserId);
ptmt.setString(2,context);
int res2=ptmt.executeUpdate();
if(res2==0){
return "error";
}else{

return "award";
}


}


}else{
return "ok";

//通知提问用户
ptmt = conn.prepareStatement(sqlMess);
ptmt.setString(1,messUserId);
ptmt.setString(2,context);
int res3=ptmt.executeUpdate();
if(res3==0){
return "error";
}else{

return "ok";
}


}

}
Expand Down
16 changes: 14 additions & 2 deletions src/com/model/Answer.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,20 @@ public class Answer {

//
private int questionId; //所属问题ID


private String questionUserId;//所属问题提问人ID
private String questionTitle;//所属问题标题
public String getQuestionTitle() {
return questionTitle;
}
public void setQuestionTitle(String questionTitle) {
this.questionTitle = questionTitle;
}
public String getQuestionUserId() {
return questionUserId;
}
public void setQuestionUserId(String questionUserId) {
this.questionUserId = questionUserId;
}
public int getQuestionId() {
return questionId;
}
Expand Down

0 comments on commit 1c16691

Please sign in to comment.