Browse Source

我的关注功能。

zzy.zhiyuan.foxmail 8 years ago
parent
commit
0c1acb26ca

+ 45 - 0
src/main/java/com/ekexiu/portal/dao/ResourceDao.java

@ -72,6 +72,51 @@ public abstract class ResourceDao {
72 72
	@From(Resource.class)
73 73
	public abstract int updateCooperationNotes(Connection con,String resourceId,@Set String cooperationNotes) throws SQLException;
74 74
	
75
	/**
76
	 * 查询资源基础信息(ID,名称,学术领域,应用行业,可提供服务,发布者ID,资源图片)
77
	 * @param con
78
	 * @param resourceId 资源ID
79
	 * @return 返回资源基础信息
80
	 * @throws SQLException
81
	 */
82
	public Resource queryBaseInfo(Connection con,String resourceId) throws SQLException{
83
        List<Image> images = this.imageDao.queryRes(con, resourceId);
84
        String sql = "SELECT RESOURCE_ID,RESOURCE_NAME,SUBJECT,INDUSTRY,SUPPORTED_SERVICES,PROFESSOR_ID"
85
        		+ " FROM RESOURCE WHERE RESOURCE_ID = ?";
86
        PreparedStatement ps = con.prepareStatement(sql);
87
        try{
88
            ps.setString(1,resourceId);
89
            ResultSet rs = ps.executeQuery();
90
            try{
91
                if(rs.next()){
92
                    Resource resource = new Resource();
93
                    resource.setResourceId(rs.getString(1));
94
                    resource.setResourceName(rs.getString(2));
95
                    String m1 = rs.getString(3);
96
                    if(rs.wasNull()){
97
                        m1 = null;
98
                    }
99
                    resource.setSubject(m1);
100
                    String m2 = rs.getString(4);
101
                    if(rs.wasNull()){
102
                        m2 = null;
103
                    }
104
                    resource.setIndustry(m2);
105
                    resource.setSupportedServices(rs.getString(5));
106
                    resource.setProfessorId(rs.getString(6));
107
                    resource.setImages(images);
108
                    return resource;
109
                }else{
110
                    return null;
111
                }
112
            }finally{
113
                try{rs.close();}catch(Exception e1){}
114
            }
115
        }finally{
116
            try{ps.close();}catch(Exception e2){}
117
        }
118
    }
119
	
75 120
	public Resource query(Connection con,String resourceId) throws SQLException{
76 121
        List<Image> images = this.imageDao.queryRes(con, resourceId);
77 122
		int _m_1 = 1;

+ 45 - 0
src/main/java/com/ekexiu/portal/dao/WatchDao.java

@ -0,0 +1,45 @@
1
package com.ekexiu.portal.dao;
2

3
import java.sql.Connection;
4
import java.sql.SQLException;
5
import java.util.List;
6

7
import org.jfw.apt.orm.annotation.dao.DAO;
8
import org.jfw.apt.orm.annotation.dao.method.From;
9
import org.jfw.apt.orm.annotation.dao.method.OrderBy;
10
import org.jfw.apt.orm.annotation.dao.method.operator.DeleteWith;
11
import org.jfw.apt.orm.annotation.dao.method.operator.Insert;
12
import org.jfw.apt.orm.annotation.dao.method.operator.SelectList;
13

14
import com.ekexiu.portal.po.Watch;
15

16
@DAO
17
public abstract class WatchDao {
18
	@Insert
19
	public abstract int insert(Connection con, Watch watch) throws SQLException;
20
	
21
	@DeleteWith
22
	@From(Watch.class)
23
	public abstract int delete(Connection con, String professorId, String watchObject) throws SQLException;
24
	
25
	@DeleteWith
26
	@From(Watch.class)
27
	public abstract int deletePro(Connection con, String professorId) throws SQLException;
28
	
29
	@DeleteWith
30
	@From(Watch.class)
31
	public abstract int deleteWatch(Connection con, String watchObject) throws SQLException;
32
	
33
//	@Nullable
34
//	@SelectOne
35
//	public abstract Watch queryOne(Connection con, String professorId, String watchObject) throws SQLException;
36
	
37
	@SelectList
38
	@OrderBy(" ORDER BY CREATE_TIME DESC ")
39
	public abstract List<Watch> queryPro(Connection con, String professorId, Integer watchType) throws SQLException;
40
	
41
	@SelectList
42
	@OrderBy(" ORDER BY CREATE_TIME DESC ")
43
	public abstract List<Watch> queryWatch(Connection con, String watchObject) throws SQLException;
44
	
45
}

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

@ -218,7 +218,7 @@ public class Professor implements CreateTimeSupported, ModifyTimeSupported{
218 218
		this.starLevel = starLevel;
219 219
	}
220 220
221
	@Column(handlerClass=WIntHandler.class,dbType="INT",insertable=false,nullable=true,renewable=true,queryable=true)
221
	@Column(handlerClass=WIntHandler.class,dbType="INT",insertable=false,nullable=false,renewable=true,queryable=true)
222 222
	public Integer getConsultCount() {
223 223
		return consultCount;
224 224
	}

+ 69 - 0
src/main/java/com/ekexiu/portal/po/Watch.java

@ -0,0 +1,69 @@
1
package com.ekexiu.portal.po;
2

3
import org.jfw.apt.orm.annotation.entry.Column;
4
import org.jfw.apt.orm.annotation.entry.PrimaryKey;
5
import org.jfw.apt.orm.annotation.entry.Table;
6
import org.jfw.apt.orm.annotation.entry.Unique;
7
import org.jfw.apt.orm.annotation.entry.Uniques;
8
import org.jfw.apt.orm.core.defaultImpl.WIntHandler;
9
import org.jfw.apt.orm.core.enums.DE;
10

11
import com.ekexiu.portal.basepo.CreateTimeSupported;
12
import com.ekexiu.portal.pojo.EditProfessor;
13

14
@Uniques(@Unique(clolumns = { "professorId","watchObject","watchType" }, name = "WATCH_RELATION_UQ"))
15
@PrimaryKey({"professorId","watchObject"})
16
@Table
17
public class Watch implements CreateTimeSupported {
18
	private String professorId;
19
	private String watchObject;
20
	private String createTime;
21
	private Integer watchType;
22
	private EditProfessor professor;
23
	private Resource resource;
24
	
25
	public EditProfessor getProfessor() {
26
		return professor;
27
	}
28
	public void setProfessor(EditProfessor professor) {
29
		this.professor = professor;
30
	}
31
	public Resource getResource() {
32
		return resource;
33
	}
34
	public void setResource(Resource resource) {
35
		this.resource = resource;
36
	}
37
	
38
	@Column(DE.id_32)
39
	public String getProfessorId() {
40
		return professorId;
41
	}
42
	public void setProfessorId(String professorId) {
43
		this.professorId = professorId;
44
	}
45
	
46
	@Column(DE.id_32)
47
	public String getWatchObject() {
48
		return watchObject;
49
	}
50
	public void setWatchObject(String watchObject) {
51
		this.watchObject = watchObject;
52
	}
53
	
54
	public String getCreateTime() {
55
		return createTime;
56
	}
57
	public void setCreateTime(String createTime) {
58
		this.createTime = createTime;
59
	}
60
	
61
	@Column(handlerClass=WIntHandler.class,dbType="INT",insertable=true,nullable=false,renewable=true,queryable=true)
62
	public Integer getWatchType() {
63
		return watchType;
64
	}
65
	public void setWatchType(Integer watchType) {
66
		this.watchType = watchType;
67
	}
68
	
69
}

+ 31 - 14
src/main/java/com/ekexiu/portal/service/ProfessorService.java

@ -32,6 +32,7 @@ import com.ekexiu.portal.dao.ProjectDao;
32 32
import com.ekexiu.portal.dao.ResearchAreaDao;
33 33
import com.ekexiu.portal.dao.ResearchAreaLogDao;
34 34
import com.ekexiu.portal.dao.ResourceDao;
35
import com.ekexiu.portal.dao.WatchDao;
35 36
import com.ekexiu.portal.po.Professor;
36 37
import com.ekexiu.portal.pojo.EditProfessor;
37 38
import com.ekexiu.portal.pojo.ProfessorInfo;
@ -39,6 +40,8 @@ import com.ekexiu.portal.util.Calculate;
39 40

40 41
@Path("/professor")
41 42
public class ProfessorService {
43
	@Autowrie
44
	private WatchDao watchDao;
42 45
	@Autowrie
43 46
	private Calculate calculate;
44 47
	@Autowrie
@ -69,6 +72,14 @@ public class ProfessorService {
69 72
	private ProjectDao projectDao;
70 73

71 74
	
75
	public WatchDao getWatchDao() {
76
		return watchDao;
77
	}
78

79
	public void setWatchDao(WatchDao watchDao) {
80
		this.watchDao = watchDao;
81
	}
82

72 83
	public Calculate getCalculate() {
73 84
		return calculate;
74 85
	}
@ -247,21 +258,25 @@ public class ProfessorService {
247 258
		return this.professorDao.query(con);
248 259
	}
249 260
	
250
	@Post
251
	@Path("/updateStarAvg")
252
	public boolean updateStarAvg(@JdbcConn(true) Connection con) throws SQLException {
253
		List<Professor> professors = this.professorDao.queryStar(con);
254
		BigDecimal bigStar = this.professorDao.queryBigStar(con);
255
		BigDecimal smallStar = this.professorDao.querySmallStar(con);
256
		BigDecimal bigConsult = this.professorDao.queryBigConsult(con);
257
		BigDecimal smallConsult = this.professorDao.querySmallConsult(con);
258
		for (Professor professor : professors) {
259
			BigDecimal star = professor.getStarLevel();
260
			BigDecimal consult = new BigDecimal(professor.getConsultCount());
261
			BigDecimal avgStar = this.calculate.calcAvgStar(bigStar, smallStar, bigConsult, smallConsult, star, consult);
262
			this.professorDao.updateStarAvg(con, professor.getId(), avgStar);
261
	public boolean updateStarAvg(Connection con) throws SQLException {
262
		try {
263
			List<Professor> professors = this.professorDao.queryStar(con);
264
			BigDecimal bigStar = this.professorDao.queryBigStar(con);
265
			BigDecimal smallStar = this.professorDao.querySmallStar(con);
266
			BigDecimal bigConsult = this.professorDao.queryBigConsult(con);
267
			BigDecimal smallConsult = this.professorDao.querySmallConsult(con);
268
			for (Professor professor : professors) {
269
				BigDecimal star = professor.getStarLevel();
270
				BigDecimal consult = new BigDecimal(professor.getConsultCount());
271
				BigDecimal avgStar = this.calculate.calcAvgStar(bigStar, smallStar, bigConsult, smallConsult, star, consult);
272
				this.professorDao.updateStarAvg(con, professor.getId(), avgStar);
273
			}
274
			return true;
275
		} catch (Exception e) {
276
			con.rollback();
277
			e.printStackTrace();
278
			return false;
263 279
		}
264
		return true;
265 280
	}
266 281
	
267 282
	@Get
@ -345,6 +360,8 @@ public class ProfessorService {
345 360
		this.patentDao.delete(con, id);
346 361
		this.honorDao.delete(con, id);
347 362
		this.projectDao.delete(con, id);
363
		this.watchDao.deletePro(con, id);
364
		this.watchDao.deleteWatch(con, id);
348 365
	}
349 366
	
350 367
	@Get

+ 12 - 0
src/main/java/com/ekexiu/portal/service/ResourceService.java

@ -20,11 +20,14 @@ import org.jfw.util.StringUtil;
20 20
import com.ekexiu.portal.dao.ImageDao;
21 21
import com.ekexiu.portal.dao.OperationDao;
22 22
import com.ekexiu.portal.dao.ResourceDao;
23
import com.ekexiu.portal.dao.WatchDao;
23 24
import com.ekexiu.portal.po.Operation;
24 25
import com.ekexiu.portal.po.Resource;
25 26

26 27
@Path("/resource")
27 28
public class ResourceService {
29
	@Autowrie
30
	private WatchDao watchDao;
28 31
	@Autowrie
29 32
	private ImageDao imageDao;
30 33
	@Autowrie
@ -34,6 +37,14 @@ public class ResourceService {
34 37
	@Autowrie
35 38
	private OperationDao operationDao;
36 39

40
	public WatchDao getWatchDao() {
41
		return watchDao;
42
	}
43

44
	public void setWatchDao(WatchDao watchDao) {
45
		this.watchDao = watchDao;
46
	}
47

37 48
	public OperationDao getOperationDao() {
38 49
		return operationDao;
39 50
	}
@ -145,6 +156,7 @@ public class ResourceService {
145 156
		if(operations.isEmpty()){
146 157
			this.imageDao.deleteRes(con, resourceId);
147 158
			this.resourceDao.delete(con, resourceId);
159
			this.watchDao.deleteWatch(con, resourceId);
148 160
			return true;
149 161
		}else{
150 162
			return false;

+ 115 - 0
src/main/java/com/ekexiu/portal/service/WatchService.java

@ -0,0 +1,115 @@
1
package com.ekexiu.portal.service;
2

3
import java.sql.Connection;
4
import java.sql.SQLException;
5
import java.util.List;
6

7
import org.jfw.apt.annotation.Autowrie;
8
import org.jfw.apt.web.annotation.Path;
9
import org.jfw.apt.web.annotation.operate.Delete;
10
import org.jfw.apt.web.annotation.operate.Get;
11
import org.jfw.apt.web.annotation.operate.Post;
12
import org.jfw.apt.web.annotation.param.JdbcConn;
13

14
import com.ekexiu.portal.dao.ProfessorDao;
15
import com.ekexiu.portal.dao.ResearchAreaDao;
16
import com.ekexiu.portal.dao.ResourceDao;
17
import com.ekexiu.portal.dao.WatchDao;
18
import com.ekexiu.portal.po.Resource;
19
import com.ekexiu.portal.po.Watch;
20
import com.ekexiu.portal.pojo.EditProfessor;
21

22
@Path("/watch")
23
public class WatchService {
24
	@Autowrie
25
	private WatchDao watchDao;
26
	@Autowrie
27
	private ProfessorDao professorDao;
28
	@Autowrie
29
	private ResourceDao resourceDao;
30
	@Autowrie
31
	private ImageService imageService;
32
	@Autowrie
33
	private ResearchAreaDao researchAreaDao;
34
	
35
	public WatchDao getWatchDao() {
36
		return watchDao;
37
	}
38
	public void setWatchDao(WatchDao watchDao) {
39
		this.watchDao = watchDao;
40
	}
41
	public ProfessorDao getProfessorDao() {
42
		return professorDao;
43
	}
44
	public void setProfessorDao(ProfessorDao professorDao) {
45
		this.professorDao = professorDao;
46
	}
47
	public ResourceDao getResourceDao() {
48
		return resourceDao;
49
	}
50
	public void setResourceDao(ResourceDao resourceDao) {
51
		this.resourceDao = resourceDao;
52
	}
53
	public ImageService getImageService() {
54
		return imageService;
55
	}
56
	public void setImageService(ImageService imageService) {
57
		this.imageService = imageService;
58
	}
59
	public ResearchAreaDao getResearchAreaDao() {
60
		return researchAreaDao;
61
	}
62
	public void setResearchAreaDao(ResearchAreaDao researchAreaDao) {
63
		this.researchAreaDao = researchAreaDao;
64
	}
65
	
66
	@Post
67
	@Path
68
	public String insert(@JdbcConn(true) Connection con, Watch watch) throws SQLException{
69
		this.watchDao.insert(con, watch);
70
		return watch.getWatchObject();
71
	}
72
	
73
	@Delete
74
	@Path("/delete")
75
	public void delete(@JdbcConn(true) Connection con, String professorId, String watchObject) throws SQLException{
76
		this.watchDao.delete(con, professorId, watchObject);
77
	}
78
	
79
	@Get
80
	@Path("/qaPro")
81
	public List<Watch> queryPro(@JdbcConn Connection con, String professorId, Integer watchType) throws SQLException{
82
		List<Watch> watchs = this.watchDao.queryPro(con, professorId, watchType);
83
		if(1 == watchType){
84
			for (Watch watch : watchs) {
85
				EditProfessor professor = this.professorDao.queryBaseInfo(con, watch.getWatchObject());
86
				professor.setHasHeadImage(this.imageService.hasProfessorImage(watch.getWatchObject()));
87
				professor.setResearchAreas(this.researchAreaDao.query(con, watch.getWatchObject()));
88
				professor.setResources(this.resourceDao.queryList(con, watch.getWatchObject()));
89
				watch.setProfessor(professor);
90
			}
91
		}else if(2 == watchType){
92
			for (Watch watch : watchs) {
93
				Resource resource = this.resourceDao.queryBaseInfo(con, watch.getWatchObject());
94
				resource.setProfessor(this.professorDao.queryBaseInfo(con, resource.getProfessorId()));
95
				watch.setResource(resource);
96
			}
97
		}
98
		return watchs;
99
	}
100
	
101
	@Get
102
	@Path("/qaWatch")
103
	public List<Watch> queryWatch(@JdbcConn Connection con, String watchObject) throws SQLException{
104
		List<Watch> watchs = this.watchDao.queryWatch(con, watchObject);
105
		for (Watch watch : watchs) {
106
			EditProfessor professor = this.professorDao.queryBaseInfo(con, watch.getProfessorId());
107
			professor.setHasHeadImage(this.imageService.hasProfessorImage(watch.getProfessorId()));
108
			professor.setResearchAreas(this.researchAreaDao.query(con, watch.getProfessorId()));
109
			professor.setResources(this.resourceDao.queryList(con, watch.getProfessorId()));
110
			watch.setProfessor(professor);
111
		}
112
		return watchs;
113
	}
114
	
115
}