portal web service

ArticleService.java 33KB

    package com.ekexiu.portal.service; import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; import java.io.File; import java.io.FileInputStream; import java.io.FileOutputStream; import java.io.IOException; import java.io.InputStream; import java.sql.Connection; import java.sql.SQLException; import java.text.SimpleDateFormat; import java.util.Collections; import java.util.Date; import java.util.List; import org.jfw.apt.annotation.Autowrie; import org.jfw.apt.annotation.DefaultValue; import org.jfw.apt.annotation.Nullable; 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.JdbcConn; import org.jfw.util.DateUtil; import org.jfw.util.JpgUtil; import org.jfw.util.PageQueryResult; import org.jfw.util.StringUtil; import org.jfw.util.exception.JfwBaseException; import org.jfw.util.io.IoUtil; import com.ekexiu.portal.cms.ContentType; import com.ekexiu.portal.cms.TemplateService; import com.ekexiu.portal.dao.ArticleAgreeDao; import com.ekexiu.portal.dao.ArticleDao; import com.ekexiu.portal.dao.ArticleOrgDao; import com.ekexiu.portal.dao.ArticleProDao; import com.ekexiu.portal.dao.ArticleResDao; import com.ekexiu.portal.dao.LeaveWordDao; 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.po.Article; import com.ekexiu.portal.po.ArticleAgree; import com.ekexiu.portal.po.ArticleOrg; import com.ekexiu.portal.po.ArticlePro; import com.ekexiu.portal.po.ArticleRes; import com.ekexiu.portal.po.Image; import com.ekexiu.portal.pojo.EditOrganization; import com.ekexiu.portal.pojo.EditProfessor; import com.ekexiu.portal.pojo.FindInfo; import com.ekexiu.portal.pojo.SelfArticle; @Path("/article") public class ArticleService { private File tmpPath; private File articlePath; private String dateFormat = "yyyyMMdd"; private String timeFormat = "yyyyMMddHHmmss"; private int artMaxLen = 70; private static final String JPG = "jpg"; public static final String MAX_MODIFYTIME = "9"; @Autowrie private ArticleDao articleDao; @Autowrie private ArticleAgreeDao articleAgreeDao; @Autowrie private ProfessorDao professorDao; @Autowrie private ResourceDao resourceDao; @Autowrie private ImageService imageService; @Autowrie private ImagesService imagesService; @Autowrie private ResearchAreaDao researchAreaDao; @Autowrie private LeaveWordDao leaveWordDao; @Autowrie private OrgDao orgDao; @Autowrie private WatchDao watchDao; @Autowrie private ArticleProDao articleProDao; @Autowrie private ArticleResDao articleResDao; @Autowrie private ArticleOrgDao articleOrgDao; @Autowrie private KeyWordService keyWordService; @Autowrie private TemplateService templateService; public TemplateService getTemplateService() { return templateService; } public void setTemplateService(TemplateService templateService) { this.templateService = templateService; } public KeyWordService getKeyWordService() { return keyWordService; } public void setKeyWordService(KeyWordService keyWordService) { this.keyWordService = keyWordService; } public ArticleOrgDao getArticleOrgDao() { return articleOrgDao; } public void setArticleOrgDao(ArticleOrgDao articleOrgDao) { this.articleOrgDao = articleOrgDao; } public String getDateFormat() { return dateFormat; } public void setDateFormat(String dateFormat) { this.dateFormat = dateFormat; } public String getTimeFormat() { return timeFormat; } public void setTimeFormat(String timeFormat) { this.timeFormat = timeFormat; } public File getTmpPath() { return tmpPath; } public void setTmpPath(File tmpPath) { this.tmpPath = tmpPath; } public File getArticlePath() { return articlePath; } public void setArticlePath(File articlePath) { this.articlePath = articlePath; } public int getArtMaxLen() { return artMaxLen; } public void setArtMaxLen(int artMaxLen) { this.artMaxLen = artMaxLen; } public ArticleDao getArticleDao() { return articleDao; } public void setArticleDao(ArticleDao articleDao) { this.articleDao = articleDao; } public ArticleAgreeDao getArticleAgreeDao() { return articleAgreeDao; } public void setArticleAgreeDao(ArticleAgreeDao articleAgreeDao) { this.articleAgreeDao = articleAgreeDao; } 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 ImagesService getImagesService() { return imagesService; } public void setImagesService(ImagesService imagesService) { this.imagesService = imagesService; } public ResearchAreaDao getResearchAreaDao() { return researchAreaDao; } public void setResearchAreaDao(ResearchAreaDao researchAreaDao) { this.researchAreaDao = researchAreaDao; } public LeaveWordDao getLeaveWordDao() { return leaveWordDao; } public void setLeaveWordDao(LeaveWordDao leaveWordDao) { this.leaveWordDao = leaveWordDao; } public OrgDao getOrgDao() { return orgDao; } public void setOrgDao(OrgDao orgDao) { this.orgDao = orgDao; } public WatchDao getWatchDao() { return watchDao; } public void setWatchDao(WatchDao watchDao) { this.watchDao = watchDao; } public ArticleProDao getArticleProDao() { return articleProDao; } public void setArticleProDao(ArticleProDao articleProDao) { this.articleProDao = articleProDao; } public ArticleResDao getArticleResDao() { return articleResDao; } public void setArticleResDao(ArticleResDao articleResDao) { this.articleResDao = articleResDao; } private byte[] resImage(byte[] src, int maxLen) throws IOException { ByteArrayInputStream in = new ByteArrayInputStream(src); ByteArrayOutputStream out = new ByteArrayOutputStream(); JpgUtil.scalingZoom(in, out, maxLen); out.flush(); return out.toByteArray(); } private byte[] readTmpFile(String fn) throws JfwBaseException { File file = new File(this.tmpPath, fn); if (!file.exists()) throw new JfwBaseException(90, "resource image not exists"); try { InputStream in = new FileInputStream(file); ByteArrayOutputStream out = new ByteArrayOutputStream(); IoUtil.copy(in, out, true, true); return out.toByteArray(); } catch (IOException e) { throw new JfwBaseException(91, "read temp resource image error", e); } } private void saveArtImg(String fn, String id) throws JfwBaseException, IOException { byte[] src = this.readTmpFile(fn); src = JpgUtil.read(src); byte[] shareResImage = this.resImage(src, this.artMaxLen); String savePath = this.articlePath + "/" + this.createDate(); File dateFile = new File(savePath); if (!dateFile.exists()) { // 创建日期目录 dateFile.mkdirs(); } IoUtil.saveStream(new FileOutputStream(new File(dateFile, id + "." + JPG)), src, true); IoUtil.saveStream(new FileOutputStream(new File(dateFile, id + "_s." + JPG)), shareResImage, true); } private String createDate() { SimpleDateFormat df = new SimpleDateFormat(this.dateFormat); String date = df.format(new Date()); return date; } private String publishTime() { SimpleDateFormat df = new SimpleDateFormat(this.timeFormat); String publishTime = df.format(new Date()); return publishTime; } @Post @Path public String insert(@JdbcConn(false) Connection con, Article article) throws SQLException, IOException, JfwBaseException { String articleId = StringUtil.buildUUID(); try { if (article.getArticleImg() != null) { this.saveArtImg(article.getArticleImg(), articleId); article.setArticleImg(this.createDate() + "/" + articleId + "." + JPG); } article.setArticleId(articleId); article.setArticleAgree(0); article.setPageViews(0); article.setStatus("1"); article.setPublishTime(this.publishTime()); if (article.getProfessorId() != null && article.getOrgId() == null) { article.setArticleType("1"); } else if (article.getProfessorId() == null && article.getOrgId() != null) { article.setArticleType("2"); } else { throw new JfwBaseException(-1, "错误参数:文章发布者ID"); } this.articleDao.insert(con, article); con.commit(); this.templateService.push(ContentType.Article, article.getArticleId()); } catch (SQLException e) { try { con.rollback(); } catch (SQLException ee) { } throw e; } return articleId; } @Post @Path("/save") public String saveArticle(@JdbcConn(false) Connection con, Article article, @Nullable String[] professors, @Nullable String[] resources, @Nullable String[] orgs) throws SQLException, IOException, JfwBaseException { String articleId = null; try { if (article.getArticleId() == null) { articleId = StringUtil.buildUUID(); if (article.getArticleImg() != null) { this.saveArtImg(article.getArticleImg(), articleId); article.setArticleImg(this.createDate() + "/" + articleId + "." + JPG); } article.setArticleId(articleId); article.setArticleAgree(0); article.setPageViews(0); article.setStatus("1"); article.setPublishTime(this.publishTime()); if (article.getProfessorId() != null && article.getOrgId() == null) { article.setArticleType("1"); } else if (article.getProfessorId() == null && article.getOrgId() != null) { article.setArticleType("2"); } else { throw new JfwBaseException(-1, "错误参数:文章发布者ID"); } this.articleDao.insert(con, article); this.keyWordService.refreshArticle(con, articleId, KeyWordService.splitKeyWord(article.getSubject())); if (professors != null) { for (String professor : professors) { ArticlePro articlePro = new ArticlePro(); articlePro.setArticleId(articleId); articlePro.setProfessorId(professor); this.articleProDao.insert(con, articlePro); } } if (resources != null) { for (String resource : resources) { ArticleRes articleRes = new ArticleRes(); articleRes.setArticleId(articleId); articleRes.setResourceId(resource); this.articleResDao.insert(con, articleRes); } } if (orgs != null && orgs.length > 0) { for (String org : orgs) { ArticleOrg articleOrg = new ArticleOrg(); articleOrg.setArticleId(articleId); articleOrg.setOrgId(org); this.articleOrgDao.insert(con, articleOrg); } } } else if (article.getArticleId().trim().length() == 32) { articleId = article.getArticleId(); if (article.getArticleImg() != null) { this.saveArtImg(article.getArticleImg(), article.getArticleId()); article.setArticleImg(this.createDate() + "/" + article.getArticleId() + "." + JPG); } this.articleDao.update(con, article); this.articleDao.updatePublishTime(con, article.getArticleId(), "1", this.publishTime()); this.keyWordService.refreshArticle(con, article.getArticleId(), KeyWordService.splitKeyWord(article.getSubject())); this.articleProDao.delete(con, article.getArticleId()); this.articleResDao.delete(con, article.getArticleId()); this.articleOrgDao.delete(con, article.getArticleId()); if (professors != null) { for (String professor : professors) { ArticlePro articlePro = new ArticlePro(); articlePro.setArticleId(article.getArticleId()); articlePro.setProfessorId(professor); this.articleProDao.insert(con, articlePro); } } if (resources != null) { for (String resource : resources) { ArticleRes articleRes = new ArticleRes(); articleRes.setArticleId(article.getArticleId()); articleRes.setResourceId(resource); this.articleResDao.insert(con, articleRes); } } if (orgs != null && orgs.length > 0) { for (String org : orgs) { ArticleOrg articleOrg = new ArticleOrg(); articleOrg.setArticleId(article.getArticleId()); articleOrg.setOrgId(org); this.articleOrgDao.insert(con, articleOrg); } } } else { throw new JfwBaseException(-2, "bad parameter:articleId"); } con.commit(); this.templateService.push(ContentType.Article, article.getArticleId()); } catch (SQLException | IOException | JfwBaseException e) { try { con.rollback(); } catch (SQLException ee) { } throw e; } return articleId; } @Post @Path("/draft") public String draft(@JdbcConn(false) Connection con, Article article, @Nullable String[] professors, @Nullable String[] resources, @Nullable String[] orgs) throws SQLException, IOException, JfwBaseException { String articleId = null; try { if (article.getArticleId() == null) { articleId = StringUtil.buildUUID(); if (article.getArticleImg() != null) { this.saveArtImg(article.getArticleImg(), articleId); article.setArticleImg(this.createDate() + "/" + articleId + "." + JPG); } article.setArticleId(articleId); article.setArticleAgree(0); article.setPageViews(0); article.setStatus("0"); if (article.getProfessorId() != null && article.getOrgId() == null) { article.setArticleType("1"); } else if (article.getProfessorId() == null && article.getOrgId() != null) { article.setArticleType("2"); } else { throw new JfwBaseException(-1, "错误参数:文章发布者ID"); } this.articleDao.insert(con, article); this.keyWordService.refreshArticle(con, articleId, null); if (professors != null) { for (String professor : professors) { ArticlePro articlePro = new ArticlePro(); articlePro.setArticleId(articleId); articlePro.setProfessorId(professor); this.articleProDao.insert(con, articlePro); } } if (resources != null) { for (String resource : resources) { ArticleRes articleRes = new ArticleRes(); articleRes.setArticleId(articleId); articleRes.setResourceId(resource); this.articleResDao.insert(con, articleRes); } } if (orgs != null && orgs.length > 0) { for (String org : orgs) { ArticleOrg articleOrg = new ArticleOrg(); articleOrg.setArticleId(articleId); articleOrg.setOrgId(org); this.articleOrgDao.insert(con, articleOrg); } } } else if (article.getArticleId().trim().length() == 32) { articleId = article.getArticleId(); if (article.getArticleImg() != null) { this.saveArtImg(article.getArticleImg(), article.getArticleId()); article.setArticleImg(this.createDate() + "/" + article.getArticleId() + "." + JPG); } this.articleDao.update(con, article); this.articleDao.updateStatus(con, article.getArticleId(), "0"); this.keyWordService.refreshArticle(con, article.getArticleId(), null); this.articleProDao.delete(con, article.getArticleId()); this.articleResDao.delete(con, article.getArticleId()); this.articleOrgDao.delete(con, article.getArticleId()); if (professors != null) { for (String professor : professors) { ArticlePro articlePro = new ArticlePro(); articlePro.setArticleId(article.getArticleId()); articlePro.setProfessorId(professor); this.articleProDao.insert(con, articlePro); } } if (resources != null) { for (String resource : resources) { ArticleRes articleRes = new ArticleRes(); articleRes.setArticleId(article.getArticleId()); articleRes.setResourceId(resource); this.articleResDao.insert(con, articleRes); } } if (orgs != null && orgs.length > 0) { for (String org : orgs) { ArticleOrg articleOrg = new ArticleOrg(); articleOrg.setArticleId(article.getArticleId()); articleOrg.setOrgId(org); this.articleOrgDao.insert(con, articleOrg); } } } else { throw new JfwBaseException(-2, "bad parameter:articleId"); } con.commit(); this.templateService.push(ContentType.Article, articleId); } catch (SQLException | IOException | JfwBaseException e) { try { con.rollback(); } catch (SQLException ee) { } throw e; } return articleId; } @Post @Path("/timing") public String timingPublish(@JdbcConn(false) Connection con, Article article, @Nullable String[] professors, @Nullable String[] resources, @Nullable String[] orgs) throws SQLException, IOException, JfwBaseException { String articleId = null; try { if (article.getPublishTime() == null) { throw new JfwBaseException(-3, "no parameter found:publishTime"); } if (article.getArticleId() == null) { articleId = StringUtil.buildUUID(); if (article.getArticleImg() != null) { this.saveArtImg(article.getArticleImg(), articleId); article.setArticleImg(this.createDate() + "/" + articleId + "." + JPG); } article.setArticleId(articleId); article.setArticleAgree(0); article.setPageViews(0); article.setStatus("2"); if (article.getProfessorId() != null && article.getOrgId() == null) { article.setArticleType("1"); } else if (article.getProfessorId() == null && article.getOrgId() != null) { article.setArticleType("2"); } else { throw new JfwBaseException(-1, "错误参数:文章发布者ID"); } this.articleDao.insert(con, article); if (professors != null) { for (String professor : professors) { ArticlePro articlePro = new ArticlePro(); articlePro.setArticleId(articleId); articlePro.setProfessorId(professor); this.articleProDao.insert(con, articlePro); } } if (resources != null) { for (String resource : resources) { ArticleRes articleRes = new ArticleRes(); articleRes.setArticleId(articleId); articleRes.setResourceId(resource); this.articleResDao.insert(con, articleRes); } } if (orgs != null && orgs.length > 0) { for (String org : orgs) { ArticleOrg articleOrg = new ArticleOrg(); articleOrg.setArticleId(articleId); articleOrg.setOrgId(org); this.articleOrgDao.insert(con, articleOrg); } } } else if (article.getArticleId().trim().length() == 32) { articleId = article.getArticleId(); if (article.getArticleImg() != null) { this.saveArtImg(article.getArticleImg(), article.getArticleId()); article.setArticleImg(this.createDate() + "/" + article.getArticleId() + "." + JPG); } this.articleDao.update(con, article); this.articleDao.updatePublishTime(con, article.getArticleId(), "2", article.getPublishTime()); this.keyWordService.refreshArticle(con, article.getArticleId(), null); this.articleResDao.delete(con, article.getArticleId()); this.articleProDao.delete(con, article.getArticleId()); this.articleOrgDao.delete(con, article.getArticleId()); if (professors != null) { for (String professor : professors) { ArticlePro articlePro = new ArticlePro(); articlePro.setArticleId(article.getArticleId()); articlePro.setProfessorId(professor); this.articleProDao.insert(con, articlePro); } } if (resources != null) { for (String resource : resources) { ArticleRes articleRes = new ArticleRes(); articleRes.setArticleId(article.getArticleId()); articleRes.setResourceId(resource); this.articleResDao.insert(con, articleRes); } } if (orgs != null && orgs.length > 0) { for (String org : orgs) { ArticleOrg articleOrg = new ArticleOrg(); articleOrg.setArticleId(article.getArticleId()); articleOrg.setOrgId(org); this.articleOrgDao.insert(con, articleOrg); } } return article.getArticleId(); } else { throw new JfwBaseException(-2, "bad parameter:articleId"); } con.commit(); this.templateService.push(ContentType.Article, articleId); } catch (SQLException | IOException | JfwBaseException e) { try { con.rollback(); } catch (SQLException ee) { } throw e; } return articleId; } @Post @Path("/updateArt") public void update(@JdbcConn(false) Connection con, Article article) throws SQLException, JfwBaseException, IOException { try { if (article.getArticleImg() != null) { this.saveArtImg(article.getArticleImg(), article.getArticleId()); article.setArticleImg(this.createDate() + "/" + article.getArticleId() + "." + JPG); } this.articleDao.update(con, article); con.commit(); this.templateService.push(ContentType.Article, article.getArticleId()); } catch (SQLException | IOException | JfwBaseException e) { try { con.rollback(); } catch (SQLException ee) { } throw e; } } @Post @Path("/pageViews") public void pageViews(@JdbcConn(true) Connection con, String articleId) throws SQLException { this.articleDao.incPageViews(con, articleId); } @Post @Path("/updateDraft") public void updateDraft(@JdbcConn(false) Connection con, String articleId) throws SQLException { // 修改文章状态为草稿 try { this.articleDao.updateStatus(con, articleId, "0"); this.keyWordService.refreshArticle(con, articleId, null); con.commit(); this.templateService.push(ContentType.Article, articleId); } catch (SQLException e) { try { con.rollback(); } catch (SQLException ee) { } throw e; } } @Post @Path("/publish") public void publish(@JdbcConn(false) Connection con, String articleId) throws SQLException { // 修改文章状态为发布 try { this.articleDao.updateStatus(con, articleId, "1"); Article a = this.articleDao.queryOne(con, articleId); if (a != null) { this.keyWordService.refreshArticle(con, articleId, KeyWordService.splitKeyWord(a.getSubject())); } con.commit(); this.templateService.push(ContentType.Article, articleId); } catch (SQLException e) { try { con.rollback(); } catch (SQLException ee) { } throw e; } } @Post @Path("/deleteArticle") public void deleteArticle(@JdbcConn(false) Connection con, String articleId) throws SQLException { // 修改文章状态为删除 try { this.articleDao.updateStatus(con, articleId, "3"); this.keyWordService.refreshArticle(con, articleId, null); con.commit(); this.templateService.push(ContentType.Article, articleId); } catch (SQLException e) { try { con.rollback(); } catch (SQLException ee) { } throw e; } } @Post @Path("/close") public void closeArticle(@JdbcConn(true) Connection con, String articleId) throws SQLException { // 修改文章状态为关闭 try{ this.articleDao.updateStatus(con, articleId, "4"); con.commit(); this.templateService.push(ContentType.Article,articleId); } catch (SQLException e) { try { con.rollback(); } catch (SQLException ee) { } throw e; } } @Post @Path("/agree") public void agree(@JdbcConn(true) Connection con, String operateId, String articleId) throws SQLException { if (this.articleDao.incAgree(con, articleId) > 0) { ArticleAgree articleAgree = new ArticleAgree(); articleAgree.setOperateId(operateId); articleAgree.setArticleId(articleId); this.articleAgreeDao.insert(con, articleAgree); } } @Post @Path("/unAgree") public void unAgree(@JdbcConn(true) Connection con, String operateId, String articleId) throws SQLException { if (this.articleDao.decAgree(con, articleId) > 0) { this.articleAgreeDao.deleteAgree(con, operateId, articleId); } } @Get @Path("/isAgree") public ArticleAgree queryAgree(@JdbcConn Connection con, String operateId, String articleId) throws SQLException { return this.articleAgreeDao.queryOne(con, operateId, articleId); } @Get @Path("/agreeList") public List<ArticleAgree> queryAgreeList(@JdbcConn Connection con, String articleId) throws SQLException { return this.articleAgreeDao.query(con, articleId); } @Get @Path("/qaPro") public List<Article> queryPro(@JdbcConn Connection con, String professorId) throws SQLException { return this.articleDao.queryPro(con, professorId); } @Get @Path("/qaProPublish") public List<Article> queryProPublish(@JdbcConn Connection con, String professorId) throws SQLException { return this.articleDao.queryProPublish(con, professorId); } @Get @Path("/pqProPublish") public PageQueryResult<Article> pageQueryProPublish(@JdbcConn Connection con, String professorId, @DefaultValue("10") int pageSize, @DefaultValue("1") int pageNo) throws SQLException { return this.articleDao.pageQueryProPublish(con, professorId, pageSize, pageNo); } @Get @Path("/qaForDesk") public List<Article> queryForDesk(@JdbcConn Connection con, String professorId) throws SQLException { return this.articleDao.queryForDesk(con, professorId); } @Get @Path("/qaOrg") public List<Article> queryOrg(@JdbcConn Connection con, String orgId) throws SQLException { return this.articleDao.queryOrg(con, orgId); } @Get @Path("/qaOrgPublish") public List<Article> queryOrgPublish(@JdbcConn Connection con, String orgId) throws SQLException { return this.articleDao.queryOrgPublish(con, orgId); } @Get @Path("/pqOrgPublish") public PageQueryResult<Article> pageQueryOrgPublish(@JdbcConn Connection con, String orgId, @DefaultValue("10") int pageSize, @DefaultValue("1") int pageNo) throws SQLException { return this.articleDao.pageQueryOrgPublish(con, orgId, pageSize, pageNo); } @Get @Path("/qlOrg") public List<Article> queryLimitOrg(@JdbcConn Connection con, String orgId, @DefaultValue("com.ekexiu.portal.service.ArticleService.MAX_MODIFYTIME") String modifyTime, @DefaultValue("20") int rows) throws SQLException { return this.articleDao.queryLimit(con, orgId, modifyTime, rows); } @Get @Path("/query") public Article queryOne(@JdbcConn Connection con, String articleId) throws SQLException { return this.articleDao.queryOne(con, articleId); } @Get @Path("/pqpublish") public PageQueryResult<Article> queryPagePublish(@JdbcConn Connection con, @Nullable String articleTitle, @DefaultValue("10") int pageSize, @DefaultValue("1") int pageNo) throws SQLException { if (articleTitle != null) { articleTitle = "%" + articleTitle + "%"; } return this.articleDao.queryPageForPublish(con, articleTitle, pageSize, pageNo); } @Get @Path("/firstpq") public PageQueryResult<Article> firstPageQuery(@JdbcConn Connection con, @Nullable String key, @DefaultValue("20") int pageSize, @DefaultValue("1") int pageNo) throws SQLException { if (key != null) { key = "%" + key + "%"; } PageQueryResult<Article> queryResult = this.articleDao.firstPageQuery(con, key, pageSize, pageNo); List<Article> articles = queryResult.getData(); if (!articles.isEmpty()) { for (Article article : articles) { if ("1".equals(article.getArticleType())) { EditProfessor professor = this.professorDao.queryBaseInfo(con, article.getProfessorId()); if (professor != null) { professor.setHasHeadImage(this.imageService.hasProfessorImage(professor.getId())); } article.setProfessor(professor); } else if ("2".equals(article.getArticleType())) { EditOrganization organization = this.orgDao.queryEditOrg(con, article.getOrgId()); if (organization != null) { organization.setHasOrgLogo(this.imageService.hasOrgLogo(organization.getId())); } article.setEditOrganization(organization); } } } return queryResult; } @Get @Path("/pqself") public PageQueryResult<SelfArticle> queryPageSelf(@JdbcConn Connection con, @Nullable String professorId, @Nullable String orgId, @Nullable String articleTitle, @DefaultValue("10") int pageSize, @DefaultValue("1") int pageNo) throws SQLException { if (articleTitle != null) { articleTitle = "%" + articleTitle + "%"; } return this.articleDao.queryPageForSelf(con, professorId, orgId, articleTitle, pageSize, pageNo); } @Get @Path("/pqFind") public PageQueryResult<FindInfo> queryPage(@JdbcConn Connection con, @DefaultValue("10") int pageSize, @DefaultValue("1") int pageNo) throws SQLException { PageQueryResult<FindInfo> queryResult = this.articleDao.queryPage(con, pageSize, pageNo); List<FindInfo> findInfos = queryResult.getData(); for (FindInfo findInfo : findInfos) { if ("3".equals(findInfo.getType())) { List<Image> images = this.imagesService.queryRes(con, findInfo.getId()); if (images.size() > 0) { findInfo.setImage(findInfo.getId() + ".jpg"); } } } queryResult.setData(findInfos); return queryResult; } @Get @Path("/findHot") public PageQueryResult<FindInfo> queryFindHot(@JdbcConn Connection con, @DefaultValue("10") int pageSize, @DefaultValue("1") int pageNo) throws SQLException { PageQueryResult<FindInfo> queryResult = this.articleDao.queryFindHot(con, pageSize, pageNo); List<FindInfo> findInfos = queryResult.getData(); if (!findInfos.isEmpty()) { for (FindInfo findInfo : findInfos) { if ("3".equals(findInfo.getType()) || "4".equals(findInfo.getType())) { List<Image> images = this.imagesService.queryRes(con, findInfo.getId()); if (images.size() > 0) { findInfo.setImage(images.get(0).getImageSrc()); } } } queryResult.setData(findInfos); } return queryResult; } @Get @Path("/ralatePro") public List<ArticlePro> ralatePro(@JdbcConn Connection con, String articleId) throws SQLException { return this.articleProDao.query(con, articleId); } @Get @Path("/ralateRes") public List<ArticleRes> ralateRes(@JdbcConn Connection con, String articleId) throws SQLException { return this.articleResDao.query(con, articleId); } @Get @Path("/ralateOrg") public List<ArticleOrg> ralateOrg(@JdbcConn Connection con, String articleId) throws SQLException { return this.articleOrgDao.query(con, articleId); } @Get @Path("/ralateArticles") public List<Article> ralateArticles(@JdbcConn Connection con, @Nullable String[] keys, @Nullable String professorId, @Nullable String orgId, String articleId, @DefaultValue("5") int rows) throws SQLException { String[] ids = this.articleDao.queryArticleIdWithSameKeyWord(con, articleId, rows); if (ids != null) { return this.articleDao.query(con, ids); } return Collections.<Article> emptyList(); } @Get @Path("/byAssProfessor") public List<Article> byAssProfessor(@JdbcConn Connection con, String id, @DefaultValue("5") int rows) throws SQLException { List<ArticlePro> pros = this.articleProDao.queryByProfessorId(con, id); if (pros == null || pros.isEmpty()) { return Collections.<Article> emptyList(); } String[] ids = new String[pros.size()]; int i = 0; for (ArticlePro ar : pros) { ids[i++] = ar.getArticleId(); } return this.articleDao.limitQueryPublish(con, ids, rows); } @Get @Path("/byAssOrg") public List<Article> byAssOrg(@JdbcConn Connection con, String id, @DefaultValue("5") int rows) throws SQLException { List<ArticleOrg> pros = this.articleOrgDao.queryByOrgId(con, id); if (pros == null || pros.isEmpty()) { return Collections.<Article> emptyList(); } String[] ids = new String[pros.size()]; int i = 0; for (ArticleOrg ar : pros) { ids[i++] = ar.getArticleId(); } return this.articleDao.limitQueryPublish(con, ids, rows); } @Get @Path("/byAssResource") public List<Article> byAssResource(@JdbcConn Connection con, String id, @DefaultValue("5") int rows) throws SQLException { List<ArticleRes> pros = this.articleResDao.queryByResourceId(con, id); if (pros == null || pros.isEmpty()) { return Collections.<Article> emptyList(); } String[] ids = new String[pros.size()]; int i = 0; for (ArticleRes ar : pros) { ids[i++] = ar.getArticleId(); } return this.articleDao.limitQueryPublish(con, ids, rows); } @Path("/byShareId") @Get public Article query(@JdbcConn Connection con, long id) throws SQLException { return this.articleDao.query(con, id); } @Path("/find") @Get public PageQueryResult<Article> find(@JdbcConn Connection con, @DefaultValue("0") int col, @Nullable String[] exclude, @DefaultValue("20") int pageSize, @DefaultValue("1") int pageNo) throws SQLException { return this.articleDao.queryFind(con, col > 0 ? col : null, exclude, pageSize, pageNo); } @Path("/lastestPublished") @Get public List<Article> lastet(@JdbcConn Connection con, @Nullable String time, @DefaultValue("10") int rows) throws SQLException { if (time == null) { time = DateUtil.formatDate(System.currentTimeMillis() - 7 * 24 * 60 * 60 * 1000) + "000000"; } return this.articleDao.lasterByPublishTime(con, time, rows); } public static void main(String[] args) { System.out.println(DateUtil.formatDate(System.currentTimeMillis() - 7 * 24 * 60 * 60 * 1000)); } }