Browse Source

--add column scorePercent;update queryBaseInfo();add
updateScorePercent();

zzy.zhiyuan.foxmail 8 years ago
parent
commit
8ee5cfb075

+ 42 - 1
src/main/java/com/ekexiu/portal/dao/ProfessorDao.java

@ -9,6 +9,7 @@ import java.util.ArrayList;
9 9
import java.util.Collections;
10 10
import java.util.List;
11 11

12
import org.jfw.apt.annotation.DefaultValue;
12 13
import org.jfw.apt.annotation.Nullable;
13 14
import org.jfw.apt.orm.annotation.dao.Column;
14 15
import org.jfw.apt.orm.annotation.dao.DAO;
@ -21,12 +22,15 @@ import org.jfw.apt.orm.annotation.dao.method.operator.Insert;
21 22
import org.jfw.apt.orm.annotation.dao.method.operator.PageSelect;
22 23
import org.jfw.apt.orm.annotation.dao.method.operator.QueryOne;
23 24
import org.jfw.apt.orm.annotation.dao.method.operator.QueryVal;
25
import org.jfw.apt.orm.annotation.dao.method.operator.SelectList;
24 26
import org.jfw.apt.orm.annotation.dao.method.operator.SelectOne;
25 27
import org.jfw.apt.orm.annotation.dao.method.operator.Update;
26 28
import org.jfw.apt.orm.annotation.dao.method.operator.UpdateWith;
29
import org.jfw.apt.orm.annotation.dao.param.LessThan;
27 30
import org.jfw.apt.orm.annotation.dao.param.Set;
28 31
import org.jfw.apt.orm.annotation.dao.param.SqlColumn;
29 32
import org.jfw.apt.orm.core.defaultImpl.BigDecimalHandler;
33
import org.jfw.apt.orm.core.defaultImpl.IntHandler;
30 34
import org.jfw.apt.orm.core.defaultImpl.StringHandler;
31 35
import org.jfw.util.PageQueryResult;
32 36
import org.jfw.util.exception.JfwBaseException;
@ -134,6 +138,38 @@ public abstract class ProfessorDao {
134 138
	@From(Professor.class)
135 139
	public abstract int updateStarAvg(Connection con, String id, @Set BigDecimal starAvg) throws SQLException;
136 140
	
141
	@UpdateWith
142
	@From(Professor.class)
143
	public abstract int updateScorePercent(Connection con,String id,@Set String scorePercent)throws SQLException;
144
	
145
	/**
146
	 * 查用户总数
147
	 * @param con
148
	 * @return
149
	 * @throws SQLException
150
	 */
151
	@QueryVal
152
	@Column(handlerClass=IntHandler.class,value={"COUNT(1)"})
153
	@From(Professor.class)
154
	@DefaultValue("0")
155
	public abstract int queryCount(Connection con)throws SQLException;
156
	
157
	/**
158
	 * 查询积分值低于scoreValue的用户总数
159
	 * @param con
160
	 * @param scoreValue 积分值
161
	 * @return
162
	 * @throws SQLException
163
	 */
164
	@QueryVal
165
	@Column(handlerClass=IntHandler.class,value={"COUNT(1)"})
166
	@From(Professor.class)
167
	@DefaultValue("0")
168
	public abstract int queryCountLessThan(Connection con,@LessThan int scoreValue)throws SQLException;
169
	
170
	@SelectList
171
	public abstract List<Professor> queryList(Connection con)throws SQLException;
172
	
137 173
	public List<EditProfessor> queryInvite(Connection con, String id) throws SQLException{
138 174
		int index = 1;
139 175
        String sql = "SELECT OFFICE,ADDRESS,ORG_ID,O.NAME,TITLE,AUTHENTICATION,AUTH_TYPE,AUTH_STATUS,P.ID,P.NAME,ORG_AUTH "
@ -230,7 +266,7 @@ public abstract class ProfessorDao {
230 266
	 */
231 267
	public EditProfessor queryBaseInfo(Connection con, String id) throws SQLException {
232 268
		int index = 1;
233
        String sql = "SELECT P.OFFICE,P.DEPARTMENT,P.TITLE,AUTHENTICATION,AUTH_TYPE,P.AUTH_STATUS,P.ID,P.NAME,P.ADDRESS,P.ORG_AUTH,ORGANIZATION.NAME "
269
        String sql = "SELECT P.OFFICE,P.DEPARTMENT,P.TITLE,AUTHENTICATION,AUTH_TYPE,P.AUTH_STATUS,P.ID,P.NAME,P.ADDRESS,P.ORG_AUTH,ORGANIZATION.NAME,P.ORG_ID "
234 270
        		+ " FROM PROFESSOR P LEFT JOIN ORGANIZATION ON P.ORG_ID = ORGANIZATION.ID WHERE P.ID = ?";
235 271
        PreparedStatement ps = con.prepareStatement(sql);
236 272
        try{
@ -270,6 +306,11 @@ public abstract class ProfessorDao {
270 306
                    	orgName = null;
271 307
                    }
272 308
                    professor.setOrgName(orgName);
309
                    String orgId = rs.getString(12);
310
                    if(rs.wasNull()){
311
                    	orgId = null;
312
                    }
313
                    professor.setOrgId(orgId);
273 314
                    return professor;
274 315
                }else{
275 316
                    return null;

+ 10 - 0
src/main/java/com/ekexiu/portal/po/Professor.java

@ -53,6 +53,7 @@ public class Professor implements CreateTimeSupported, ModifyTimeSupported{
53 53
	private Integer sortFirst;
54 54
	private Integer scoreValue;
55 55
	private Integer growthValue;
56
	private String scorePercent;
56 57
	
57 58
	private Organization organization;
58 59
	private List<Resource> resources;
@ -323,4 +324,13 @@ public class Professor implements CreateTimeSupported, ModifyTimeSupported{
323 324
		this.growthValue = growthValue;
324 325
	}
325 326
327
	@Column(handlerClass=StringHandler.class,dbType="VARCHAR(10)",nullable=true,renewable=false)
328
	public String getScorePercent() {
329
		return scorePercent;
330
	}
331
332
	public void setScorePercent(String scorePercent) {
333
		this.scorePercent = scorePercent;
334
	}
335
326 336
}

+ 20 - 0
src/main/java/com/ekexiu/portal/service/ProfessorService.java

@ -5,6 +5,7 @@ import java.math.BigDecimal;
5 5
import java.net.URLEncoder;
6 6
import java.sql.Connection;
7 7
import java.sql.SQLException;
8
import java.text.DecimalFormat;
8 9
import java.util.List;
9 10

10 11
import org.jfw.apt.annotation.Autowrie;
@ -396,6 +397,25 @@ public class ProfessorService {
396 397
		}
397 398
	}
398 399
	
400
	public void updateScorePercent(Connection con) throws SQLException {
401
		List<Professor> professors = this.professorDao.queryList(con);
402
		int count = this.professorDao.queryCount(con);
403
		try {
404
			for (Professor professor : professors) {
405
				int lessThan = this.professorDao.queryCountLessThan(con, professor.getScoreValue());
406
				double value = 0;
407
				if(count != 0){
408
					value = (double)lessThan/(double)count;
409
				}
410
				DecimalFormat df = new DecimalFormat("#.##%");
411
				this.professorDao.updateScorePercent(con, professor.getId(), df.format(value));
412
			}
413
		} catch (Exception e) {
414
			con.rollback();
415
			e.printStackTrace();
416
		}
417
	}
418
	
399 419
	@Get
400 420
	@Path("/pqHot")
401 421
	public PageQueryResult<EditProfessor> queryHot(@JdbcConn Connection con,@DefaultValue("8") int pageSize,@DefaultValue("1") int pageNo) throws SQLException {