Explorar el Código

--update queryScore();

zzy.zhiyuan.foxmail %!s(int64=8) %!d(string=hace) años
padre
commit
c0f65cebc5

+ 28 - 16
src/main/java/com/ekexiu/portal/dao/GrowthLogDao.java

@ -5,9 +5,7 @@ import java.sql.PreparedStatement;
5 5
import java.sql.ResultSet;
6 6
import java.sql.SQLException;
7 7
import java.util.ArrayList;
8
import java.util.HashMap;
9 8
import java.util.List;
10
import java.util.Map;
11 9

12 10
import org.jfw.apt.annotation.Nullable;
13 11
import org.jfw.apt.orm.annotation.dao.DAO;
@ -64,26 +62,40 @@ public abstract class GrowthLogDao {
64 62
        }
65 63
    }
66 64
	
67
	public Map<String, Integer> queryScore(Connection con,String professorId)throws SQLException{
65
	public int queryInviteScore(Connection con,String professorId)throws SQLException{
68 66
		int index = 1;
69
		String sql = "SELECT INVITE_PRO,SUM(SCORE) FROM GROWTH_LOG WHERE PROFESSOR_ID = ? GROUP BY INVITE_PRO ORDER BY INVITE_PRO";
67
		String sql = "SELECT SUM(SCORE) FROM GROWTH_LOG WHERE PROFESSOR_ID = ? AND INVITE_PRO IS NOT NULL";
70 68
		PreparedStatement ps = con.prepareStatement(sql);
71 69
		try{
72 70
			ps.setString(index++, professorId);
73 71
			ResultSet rs = ps.executeQuery();
74 72
			try{
75
				Map<String, Integer> map = new HashMap<String, Integer>();
76
				while(rs.next()){
77
					String invitePro = rs.getString(1);
78
					if(rs.wasNull()){
79
						invitePro = "myScore";
80
					}else{
81
						invitePro = "inviteScore";
82
					}
83
					Integer sum = rs.getInt(2);
84
					map.put(invitePro, sum);
85
				}
86
				return map;
73
				if(rs.next()){
74
                    return rs.getInt(1);
75
                }else{
76
                    return 0;
77
                }
78
			}finally{
79
				try{rs.close();}catch(Exception e1){}
80
			}
81
		}finally{
82
			try{ps.close();}catch(Exception e2){}
83
		}
84
	}
85
	
86
	public int queryMyScore(Connection con,String professorId)throws SQLException{
87
		int index = 1;
88
		String sql = "SELECT SUM(SCORE) FROM GROWTH_LOG WHERE PROFESSOR_ID = ? AND INVITE_PRO IS NULL";
89
		PreparedStatement ps = con.prepareStatement(sql);
90
		try{
91
			ps.setString(index++, professorId);
92
			ResultSet rs = ps.executeQuery();
93
			try{
94
				if(rs.next()){
95
                    return rs.getInt(1);
96
                }else{
97
                    return 0;
98
                }
87 99
			}finally{
88 100
				try{rs.close();}catch(Exception e1){}
89 101
			}

+ 7 - 1
src/main/java/com/ekexiu/portal/service/GrowthLogService.java

@ -5,6 +5,7 @@ import java.sql.SQLException;
5 5
import java.text.SimpleDateFormat;
6 6
import java.util.Calendar;
7 7
import java.util.Date;
8
import java.util.HashMap;
8 9
import java.util.List;
9 10
import java.util.Map;
10 11

@ -108,7 +109,12 @@ public class GrowthLogService {
108 109
	@Get
109 110
	@Path("/queryScore")
110 111
	public Map<String, Integer> queryScore(@JdbcConn Connection con,String professorId)throws SQLException{
111
		return this.growthLogDao.queryScore(con, professorId);
112
		int myScore = this.growthLogDao.queryMyScore(con, professorId);
113
		int inviteScore= this.growthLogDao.queryInviteScore(con, professorId);
114
		Map<String, Integer> map = new HashMap<String, Integer>();
115
		map.put("myScore", myScore);
116
		map.put("inviteScore", inviteScore);
117
		return map;
112 118
	}
113 119

114 120
	/**