浏览代码

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

zzy.zhiyuan.foxmail 8 年之前
父节点
当前提交
8ee5cfb075

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

9
import java.util.Collections;
9
import java.util.Collections;
10
import java.util.List;
10
import java.util.List;
11

11

12
import org.jfw.apt.annotation.DefaultValue;
12
import org.jfw.apt.annotation.Nullable;
13
import org.jfw.apt.annotation.Nullable;
13
import org.jfw.apt.orm.annotation.dao.Column;
14
import org.jfw.apt.orm.annotation.dao.Column;
14
import org.jfw.apt.orm.annotation.dao.DAO;
15
import org.jfw.apt.orm.annotation.dao.DAO;
21
import org.jfw.apt.orm.annotation.dao.method.operator.PageSelect;
22
import org.jfw.apt.orm.annotation.dao.method.operator.PageSelect;
22
import org.jfw.apt.orm.annotation.dao.method.operator.QueryOne;
23
import org.jfw.apt.orm.annotation.dao.method.operator.QueryOne;
23
import org.jfw.apt.orm.annotation.dao.method.operator.QueryVal;
24
import org.jfw.apt.orm.annotation.dao.method.operator.QueryVal;
25
import org.jfw.apt.orm.annotation.dao.method.operator.SelectList;
24
import org.jfw.apt.orm.annotation.dao.method.operator.SelectOne;
26
import org.jfw.apt.orm.annotation.dao.method.operator.SelectOne;
25
import org.jfw.apt.orm.annotation.dao.method.operator.Update;
27
import org.jfw.apt.orm.annotation.dao.method.operator.Update;
26
import org.jfw.apt.orm.annotation.dao.method.operator.UpdateWith;
28
import org.jfw.apt.orm.annotation.dao.method.operator.UpdateWith;
29
import org.jfw.apt.orm.annotation.dao.param.LessThan;
27
import org.jfw.apt.orm.annotation.dao.param.Set;
30
import org.jfw.apt.orm.annotation.dao.param.Set;
28
import org.jfw.apt.orm.annotation.dao.param.SqlColumn;
31
import org.jfw.apt.orm.annotation.dao.param.SqlColumn;
29
import org.jfw.apt.orm.core.defaultImpl.BigDecimalHandler;
32
import org.jfw.apt.orm.core.defaultImpl.BigDecimalHandler;
33
import org.jfw.apt.orm.core.defaultImpl.IntHandler;
30
import org.jfw.apt.orm.core.defaultImpl.StringHandler;
34
import org.jfw.apt.orm.core.defaultImpl.StringHandler;
31
import org.jfw.util.PageQueryResult;
35
import org.jfw.util.PageQueryResult;
32
import org.jfw.util.exception.JfwBaseException;
36
import org.jfw.util.exception.JfwBaseException;
134
	@From(Professor.class)
138
	@From(Professor.class)
135
	public abstract int updateStarAvg(Connection con, String id, @Set BigDecimal starAvg) throws SQLException;
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
	public List<EditProfessor> queryInvite(Connection con, String id) throws SQLException{
173
	public List<EditProfessor> queryInvite(Connection con, String id) throws SQLException{
138
		int index = 1;
174
		int index = 1;
139
        String sql = "SELECT OFFICE,ADDRESS,ORG_ID,O.NAME,TITLE,AUTHENTICATION,AUTH_TYPE,AUTH_STATUS,P.ID,P.NAME,ORG_AUTH "
175
        String sql = "SELECT OFFICE,ADDRESS,ORG_ID,O.NAME,TITLE,AUTHENTICATION,AUTH_TYPE,AUTH_STATUS,P.ID,P.NAME,ORG_AUTH "
230
	 */
266
	 */
231
	public EditProfessor queryBaseInfo(Connection con, String id) throws SQLException {
267
	public EditProfessor queryBaseInfo(Connection con, String id) throws SQLException {
232
		int index = 1;
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
        		+ " FROM PROFESSOR P LEFT JOIN ORGANIZATION ON P.ORG_ID = ORGANIZATION.ID WHERE P.ID = ?";
270
        		+ " FROM PROFESSOR P LEFT JOIN ORGANIZATION ON P.ORG_ID = ORGANIZATION.ID WHERE P.ID = ?";
235
        PreparedStatement ps = con.prepareStatement(sql);
271
        PreparedStatement ps = con.prepareStatement(sql);
236
        try{
272
        try{
270
                    	orgName = null;
306
                    	orgName = null;
271
                    }
307
                    }
272
                    professor.setOrgName(orgName);
308
                    professor.setOrgName(orgName);
309
                    String orgId = rs.getString(12);
310
                    if(rs.wasNull()){
311
                    	orgId = null;
312
                    }
313
                    professor.setOrgId(orgId);
273
                    return professor;
314
                    return professor;
274
                }else{
315
                }else{
275
                    return null;
316
                    return null;

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

53
	private Integer sortFirst;
53
	private Integer sortFirst;
54
	private Integer scoreValue;
54
	private Integer scoreValue;
55
	private Integer growthValue;
55
	private Integer growthValue;
56
	private String scorePercent;
56
	
57
	
57
	private Organization organization;
58
	private Organization organization;
58
	private List<Resource> resources;
59
	private List<Resource> resources;
323
		this.growthValue = growthValue;
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
import java.net.URLEncoder;
5
import java.net.URLEncoder;
6
import java.sql.Connection;
6
import java.sql.Connection;
7
import java.sql.SQLException;
7
import java.sql.SQLException;
8
import java.text.DecimalFormat;
8
import java.util.List;
9
import java.util.List;
9

10

10
import org.jfw.apt.annotation.Autowrie;
11
import org.jfw.apt.annotation.Autowrie;
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
	@Get
419
	@Get
400
	@Path("/pqHot")
420
	@Path("/pqHot")
401
	public PageQueryResult<EditProfessor> queryHot(@JdbcConn Connection con,@DefaultValue("8") int pageSize,@DefaultValue("1") int pageNo) throws SQLException {
421
	public PageQueryResult<EditProfessor> queryHot(@JdbcConn Connection con,@DefaultValue("8") int pageSize,@DefaultValue("1") int pageNo) throws SQLException {