贡献值
This commit is contained in:
@@ -191,4 +191,43 @@ public class UserDao {
|
||||
|
||||
return num;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 返回贡献值
|
||||
*/
|
||||
public int contributionValueReturn(String name) {
|
||||
Connection conn = null;
|
||||
PreparedStatement preparedStatement = null;
|
||||
ResultSet rs = null;
|
||||
String sql = "SELECT * FROM `user` t1,article t2 WHERE t1.userId = t2.userId AND t1.userId = ?";
|
||||
int Value = 0;
|
||||
try{
|
||||
conn = JdbcUtils.getConnection();
|
||||
preparedStatement = conn.prepareStatement(sql);
|
||||
preparedStatement.setString(1, name);
|
||||
rs = preparedStatement.executeQuery();
|
||||
if(rs.next()){
|
||||
while(rs.next()){
|
||||
int projectNum = rs.getInt(6);
|
||||
Value = Value+projectNum;
|
||||
Value++;
|
||||
}
|
||||
return Value;
|
||||
}else{
|
||||
return 0;
|
||||
}
|
||||
}catch(Exception e){
|
||||
e.printStackTrace();
|
||||
return 0;
|
||||
}finally {
|
||||
try{
|
||||
conn.close();
|
||||
preparedStatement.close();
|
||||
rs.close();
|
||||
}catch(Exception e){
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -30,6 +30,8 @@ public class userEntity {
|
||||
|
||||
private String searchHistory;
|
||||
|
||||
private Integer contributionValue;
|
||||
|
||||
public userEntity() {
|
||||
|
||||
}
|
||||
@@ -39,7 +41,7 @@ public class userEntity {
|
||||
this.userPassword = userPassword;
|
||||
}
|
||||
|
||||
public userEntity(Integer userId, String userName, String userPassword, Date creatTime, Integer isValid, Integer projectNum, String searchHistory) {
|
||||
public userEntity(Integer userId, String userName, String userPassword, Date creatTime, Integer isValid, Integer projectNum, String searchHistory, Integer contributionValue) {
|
||||
this.userId = userId;
|
||||
this.userName = userName;
|
||||
this.userPassword = userPassword;
|
||||
@@ -47,6 +49,7 @@ public class userEntity {
|
||||
this.isValid = isValid;
|
||||
this.projectNum = projectNum;
|
||||
this.searchHistory = searchHistory;
|
||||
this.contributionValue = contributionValue;
|
||||
}
|
||||
|
||||
public Integer getUserId() {
|
||||
@@ -105,6 +108,10 @@ public class userEntity {
|
||||
this.searchHistory = searchHistory;
|
||||
}
|
||||
|
||||
public Integer getContributionValue(){return contributionValue;}
|
||||
|
||||
public void setContributionValue(Integer contributionValue){this.contributionValue = contributionValue; }
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "UserEntity{" +
|
||||
@@ -115,6 +122,7 @@ public class userEntity {
|
||||
", isValid=" + isValid +
|
||||
", projectNum=" + projectNum +
|
||||
", searchHistory='" + searchHistory + '\'' +
|
||||
", contributionValue='" + contributionValue +
|
||||
'}';
|
||||
}
|
||||
long num;
|
||||
|
@@ -55,4 +55,6 @@ public class UserService {
|
||||
* */
|
||||
public int dedleteAllLabel(String name){return userDao.dedleteAllLabel(name);}
|
||||
public long queryUserCount(){return userDao.queryUserCount();}
|
||||
|
||||
public int contributionValueReturn(String name){return userDao.contributionValueReturn(name);}
|
||||
}
|
||||
|
46
src/com/hellogithub/servlet/contributionValueSevlet.java
Normal file
46
src/com/hellogithub/servlet/contributionValueSevlet.java
Normal file
@@ -0,0 +1,46 @@
|
||||
package com.hellogithub.servlet;
|
||||
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.hellogithub.entity.userEntity;
|
||||
import com.hellogithub.service.UserService;
|
||||
import jakarta.servlet.ServletException;
|
||||
import jakarta.servlet.annotation.WebServlet;
|
||||
import jakarta.servlet.http.HttpServlet;
|
||||
import jakarta.servlet.http.HttpServletRequest;
|
||||
import jakarta.servlet.http.HttpServletResponse;
|
||||
import jakarta.servlet.http.HttpSession;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.PrintWriter;
|
||||
|
||||
@WebServlet("/contributionValue")
|
||||
public class contributionValueSevlet extends HttpServlet {
|
||||
private UserService userService = new UserService();
|
||||
@Override
|
||||
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
|
||||
doPost(req, resp);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
|
||||
resp.setCharacterEncoding("UTF-8");
|
||||
// 设置响应头允许ajax跨域访问
|
||||
String curOrigin = req.getHeader("Origin");
|
||||
resp.setHeader("Access-Control-Allow-Origin", curOrigin == null ? "true" : curOrigin);
|
||||
resp.setHeader("Access-Control-Allow-Credentials", "true");
|
||||
resp.setHeader("Access-Control-Allow-Methods", "POST, GET, OPTIONS, DELETE, HEAD");
|
||||
resp.setHeader("Access-Control-Max-Age", "3600");
|
||||
resp.setHeader("Access-Control-Allow-Headers", "access-control-allow-origin, authority, content-type, version-info, X-Requested-With");
|
||||
resp.setContentType("application/json;charset=UTF-8");
|
||||
|
||||
|
||||
|
||||
PrintWriter writer = resp.getWriter();
|
||||
HttpSession session = req.getSession();
|
||||
userEntity user = (userEntity)session.getAttribute("user");
|
||||
String userName = user.getUserName();
|
||||
int Value = userService.contributionValueReturn(userName);
|
||||
writer.println(Value);
|
||||
writer.close();
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user