portal web service

WatchService.java 6.8KB

    package com.ekexiu.portal.service; import java.sql.Connection; import java.sql.SQLException; import java.util.List; import org.jfw.apt.annotation.Autowrie; import org.jfw.apt.annotation.DefaultValue; import org.jfw.apt.web.annotation.Path; import org.jfw.apt.web.annotation.operate.Get; import org.jfw.apt.web.annotation.operate.Post; import org.jfw.apt.web.annotation.param.AfterCommit; import org.jfw.apt.web.annotation.param.JdbcConn; import org.jfw.util.PageQueryResult; import com.ekexiu.portal.dao.ArticleDao; import com.ekexiu.portal.dao.ImageDao; import com.ekexiu.portal.dao.OrgDao; import com.ekexiu.portal.dao.ProfessorDao; import com.ekexiu.portal.dao.ResearchAreaDao; import com.ekexiu.portal.dao.ResourceDao; import com.ekexiu.portal.dao.WatchDao; import com.ekexiu.portal.notify.NotifyService; import com.ekexiu.portal.notify.NotifyType; import com.ekexiu.portal.po.Article; import com.ekexiu.portal.po.Resource; import com.ekexiu.portal.po.Watch; import com.ekexiu.portal.pojo.EditProfessor; @Path("/watch") public class WatchService { @Autowrie private WatchDao watchDao; @Autowrie private ProfessorDao professorDao; @Autowrie private ResourceDao resourceDao; @Autowrie private ImageService imageService; @Autowrie private ResearchAreaDao researchAreaDao; @Autowrie private ArticleDao articleDao; @Autowrie private OrgDao orgDao; @Autowrie private ImageDao imageDao; @Autowrie private NotifyService notifyService; public NotifyService getNotifyService() { return notifyService; } public void setNotifyService(NotifyService notifyService) { this.notifyService = notifyService; } public WatchDao getWatchDao() { return watchDao; } public void setWatchDao(WatchDao watchDao) { this.watchDao = watchDao; } public ProfessorDao getProfessorDao() { return professorDao; } public void setProfessorDao(ProfessorDao professorDao) { this.professorDao = professorDao; } public ResourceDao getResourceDao() { return resourceDao; } public void setResourceDao(ResourceDao resourceDao) { this.resourceDao = resourceDao; } public ImageService getImageService() { return imageService; } public void setImageService(ImageService imageService) { this.imageService = imageService; } public ResearchAreaDao getResearchAreaDao() { return researchAreaDao; } public void setResearchAreaDao(ResearchAreaDao researchAreaDao) { this.researchAreaDao = researchAreaDao; } public ArticleDao getArticleDao() { return articleDao; } public void setArticleDao(ArticleDao articleDao) { this.articleDao = articleDao; } public OrgDao getOrgDao() { return orgDao; } public void setOrgDao(OrgDao orgDao) { this.orgDao = orgDao; } public ImageDao getImageDao() { return imageDao; } public void setImageDao(ImageDao imageDao) { this.imageDao = imageDao; } @Post @Path public String insert(@JdbcConn(true) Connection con, Watch watch, final String uname, @AfterCommit List<Runnable> runs) throws SQLException { this.watchDao.insert(con, watch); if (watch.getWatchType() == 1) { this.notifyService.notify(con, watch.getWatchObject(), watch.getProfessorId(), uname, watch.getWatchObject(), watch.getWatchObject(), NotifyType.WATCH_USER, runs); } return watch.getWatchObject(); } @Post @Path("/delete") public void delete(@JdbcConn(true) Connection con, String professorId, String watchObject) throws SQLException { this.watchDao.delete(con, professorId, watchObject); } @Get @Path("/hasWatch") public Watch queryOne(@JdbcConn Connection con, String professorId, String watchObject) throws SQLException { return this.watchDao.queryOne(con, professorId, watchObject); } @Get @Path("/qaPro") public PageQueryResult<Watch> queryPro(@JdbcConn Connection con, String professorId, short watchType, @DefaultValue("10") int pageSize, @DefaultValue("1") int pageNo) throws SQLException { PageQueryResult<Watch> queryResult = this.watchDao.queryPro(con, professorId, watchType, pageSize, pageNo); List<Watch> watchs = queryResult.getData(); if (1 == watchType) { for (Watch watch : watchs) { EditProfessor professor = this.professorDao.queryBaseInfo(con, watch.getWatchObject()); if (professor != null) { professor.setHasHeadImage(this.imageService.hasProfessorImage(watch.getWatchObject())); professor.setResearchAreas(this.researchAreaDao.query(con, watch.getWatchObject())); professor.setResources(this.resourceDao.queryList(con, watch.getWatchObject())); } watch.setProfessor(professor); } } else if (2 == watchType) { for (Watch watch : watchs) { Resource resource = this.resourceDao.queryOne(con, watch.getWatchObject()); if (resource != null) { resource.setImages(this.imageDao.queryRes(con, resource.getResourceId())); if ("1".equals(resource.getResourceType())) { resource.setEditProfessor(this.professorDao.queryBaseInfo(con, resource.getProfessorId())); } else if ("2".equals(resource.getResourceType())) { resource.setOrganization(this.orgDao.queryEditOrg(con, resource.getOrgId())); } } watch.setResource(resource); } } else if (3 == watchType) { for (Watch watch : watchs) { Article article = this.articleDao.queryOne(con, watch.getWatchObject()); if (article != null) { if ("1".equals(article.getArticleType())) { article.setProfessor(this.professorDao.queryBaseInfo(con, article.getProfessorId())); } else if ("2".equals(article.getArticleType())) { article.setOrganization(this.orgDao.query(con, article.getOrgId())); } } watch.setArticle(article); } } return queryResult; } @Get @Path("/qaWatch") public List<Watch> queryWatch(@JdbcConn Connection con, String watchObject) throws SQLException { List<Watch> watchs = this.watchDao.queryWatch(con, watchObject); for (Watch watch : watchs) { EditProfessor professor = this.professorDao.queryBaseInfo(con, watch.getProfessorId()); if (professor != null) { professor.setHasHeadImage(this.imageService.hasProfessorImage(watch.getProfessorId())); professor.setResearchAreas(this.researchAreaDao.query(con, watch.getProfessorId())); professor.setResources(this.resourceDao.queryList(con, watch.getProfessorId())); } watch.setProfessor(professor); } return watchs; } @Get @Path("/countObject") public int countObject(@JdbcConn Connection con, String id, short type) throws SQLException { return this.watchDao.countWatchObject(con, id, type); } @Get @Path("/countProfessor") public int countProfessor(@JdbcConn Connection con, String id, short type) throws SQLException { return this.watchDao.countProfessor(con, id, type); } }