portal web service

ArticleService.java 43KB

    package com.ekexiu.portal.service; import com.ekexiu.portal.article.file.ArticleFileService; 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.notify.NotifyService; import com.ekexiu.portal.notify.NotifyType; 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.ArticleProduct; import com.ekexiu.portal.po.ArticleRes; import com.ekexiu.portal.po.ArticleWare; 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; 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.AfterCommit; 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 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; @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; @Autowrie private NotifyService notifyService; @Autowrie private GrowthLogService growthLogService; @Autowrie private ArticleFileService articleFileService; public GrowthLogService getGrowthLogService() { return growthLogService; } public void setGrowthLogService(GrowthLogService growthLogService) { this.growthLogService = growthLogService; } public NotifyService getNotifyService() { return notifyService; } public void setNotifyService(NotifyService notifyService) { this.notifyService = notifyService; } 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; } public ArticleFileService getArticleFileService() { return articleFileService; } public void setArticleFileService(ArticleFileService articleFileService) { this.articleFileService = articleFileService; } 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.getOwnerId() == null) { throw new JfwBaseException(-1, "错误参数:文章发布者ID"); } if (article.getArticleType() == null) { throw new JfwBaseException(-2, "错误参数:文章类型"); } 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("/save1") public String saveArticle(@JdbcConn(false) Connection con, Article article,@Nullable String[] files,@Nullable String[] professors, @Nullable String[] resources, @Nullable String[] orgs, @Nullable String[] wares,@Nullable String[] products) 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.getOwnerId() == null) { throw new JfwBaseException(-1, "错误参数:文章发布者ID"); } if (article.getArticleType() == null) { throw new JfwBaseException(-2, "错误参数:文章类型"); } this.articleDao.insert(con, article); this.articleFileService.update(con,articleId,files); 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); } } articleDao.deleteWare(con, article.getArticleId()); if (wares != null && wares.length > 0) { for (String wid : wares) { ArticleWare aw = new ArticleWare(); aw.setId(articleId); aw.setWare(wid); articleDao.insert(con, aw); } } articleDao.deleteProduct(con, article.getArticleId()); if (products != null && products.length > 0) { for (String pid : products) { ArticleProduct ap = new ArticleProduct(); ap.setId(articleId); ap.setProduct(pid); articleDao.insert(con, ap); } } } 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.articleFileService.update(con,articleId,files); 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); } } articleDao.deleteWare(con, article.getArticleId()); if (wares != null && wares.length > 0) { for (String wid : wares) { ArticleWare aw = new ArticleWare(); aw.setId(articleId); aw.setWare(wid); articleDao.insert(con, aw); } } articleDao.deleteProduct(con, article.getArticleId()); if (products != null && products.length > 0) { for (String pid : products) { ArticleProduct ap = new ArticleProduct(); ap.setId(articleId); ap.setProduct(pid); articleDao.insert(con, ap); } } } 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("/draft1") public String draft(@JdbcConn(false) Connection con, Article article,@Nullable String[] files, @Nullable String[] professors, @Nullable String[] resources, @Nullable String[] orgs, @Nullable String[] wares,@Nullable String[] products) 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.getOwnerId() == null) { throw new JfwBaseException(-1, "错误参数:文章发布者ID"); } if (article.getArticleType() == null) { throw new JfwBaseException(-2, "错误参数:文章类型"); } this.articleDao.insert(con, article); this.articleFileService.update(con,articleId,files); 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); } } articleDao.deleteWare(con, article.getArticleId()); if (wares != null && wares.length > 0) { for (String wid : wares) { ArticleWare aw = new ArticleWare(); aw.setId(articleId); aw.setWare(wid); articleDao.insert(con, aw); } } articleDao.deleteProduct(con, article.getArticleId()); if (products != null && products.length > 0) { for (String pid : products) { ArticleProduct ap = new ArticleProduct(); ap.setId(articleId); ap.setProduct(pid); articleDao.insert(con, ap); } } } 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.articleFileService.update(con,articleId,files); 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); } } articleDao.deleteWare(con, article.getArticleId()); if (wares != null && wares.length > 0) { for (String wid : wares) { ArticleWare aw = new ArticleWare(); aw.setId(articleId); aw.setWare(wid); articleDao.insert(con, aw); } } articleDao.deleteProduct(con, article.getArticleId()); if (products != null && products.length > 0) { for (String pid : products) { ArticleProduct ap = new ArticleProduct(); ap.setId(articleId); ap.setProduct(pid); articleDao.insert(con, ap); } } } 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("/timing1") public String timingPublish(@JdbcConn(false) Connection con, Article article,@Nullable String[] files, @Nullable String[] professors, @Nullable String[] resources, @Nullable String[] orgs, @Nullable String[] wares,@Nullable String[] products) 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.getOwnerId() == null) { throw new JfwBaseException(-1, "错误参数:文章发布者ID"); } if (article.getArticleType() == null) { throw new JfwBaseException(-2, "错误参数:文章类型"); } this.articleDao.insert(con, article); this.articleFileService.update(con,articleId,files); 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); } } articleDao.deleteWare(con, article.getArticleId()); if (wares != null && wares.length > 0) { for (String wid : wares) { ArticleWare aw = new ArticleWare(); aw.setId(articleId); aw.setWare(wid); articleDao.insert(con, aw); } } articleDao.deleteProduct(con, article.getArticleId()); if (products != null && products.length > 0) { for (String pid : products) { ArticleProduct ap = new ArticleProduct(); ap.setId(articleId); ap.setProduct(pid); articleDao.insert(con, ap); } } } 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.articleFileService.update(con,articleId,files); 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); } } articleDao.deleteWare(con, article.getArticleId()); if (wares != null && wares.length > 0) { for (String wid : wares) { ArticleWare aw = new ArticleWare(); aw.setId(articleId); aw.setWare(wid); articleDao.insert(con, aw); } } articleDao.deleteProduct(con, article.getArticleId()); if (products != null && products.length > 0) { for (String pid : products) { ArticleProduct ap = new ArticleProduct(); ap.setId(articleId); ap.setProduct(pid); articleDao.insert(con, ap); } } } 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); watchDao.deleteWatch(con, (short)3,articleId); 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, @Nullable String uname, @AfterCommit List<Runnable> runs) throws SQLException { final Article article = this.articleDao.queryOne(con, articleId); if (article == null) { throw new IllegalArgumentException("not found article[" + articleId + "]"); } if (this.articleDao.incAgree(con, articleId) > 0) { ArticleAgree articleAgree = new ArticleAgree(); articleAgree.setOperateId(operateId); articleAgree.setArticleId(articleId); this.articleAgreeDao.insert(con, articleAgree); this.growthLogService.agree(con, operateId); if (uname != null) { if (article.getArticleType().equals("1") && (!operateId.equals(article.getOwnerId()))) { this.notifyService.notify(con, article.getOwnerId(), operateId, uname, articleId, article.getArticleTitle(), NotifyType.AGREE_ARTICLE, runs); } } } } @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 ownerId) throws SQLException { return this.articleDao.queryPro(con, ownerId); } @Get @Path("/qaProPublish") public List<Article> queryProPublish(@JdbcConn Connection con, String ownerId) throws SQLException { return this.articleDao.queryProPublish(con, ownerId); } @Get @Path("/pqProPublish1") public PageQueryResult<Article> pageQueryProPublish(@JdbcConn Connection con, String ownerId, @DefaultValue("10") int pageSize, @DefaultValue("1") int pageNo) throws SQLException { return this.articleDao.pageQueryProPublish(con, ownerId, pageSize, pageNo); } @Get @Path("/publish1") public List<Article> proPublish(@JdbcConn Connection con, String category, String owner, @DefaultValue("\"9\"") String publishTime,@DefaultValue("Long.MAX_VALUE")long shareId, int rows)throws SQLException { return this.articleDao.publish(con,category, owner, publishTime,shareId, rows); } @Get @Path("/publishInPlatform") public List<Article> publishInPlatform(@JdbcConn Connection con,String pid, @DefaultValue("\"9\"") String publishTime,@DefaultValue("Long.MAX_VALUE")long shareId, int rows)throws SQLException { return this.articleDao.publishInPlatform(con,pid, publishTime,shareId, rows); } @Get @Path("/pgPublishInPlatform") public PageQueryResult<Article> pgPublishInPlatform(@JdbcConn Connection con,String pid,@Nullable String key,@DefaultValue("10") int pageSize,@DefaultValue("1") int pageNo)throws SQLException { return this.articleDao.publishInPlatform(con,pid, key == null ? null : ("%" + key + "%"),pageSize,pageNo); } @Get @Path("/pgPublishNotInPlatform") public PageQueryResult<Article> pgPublishNotInPlatform(@JdbcConn Connection con,String pid,@Nullable String key,@DefaultValue("10") int pageSize,@DefaultValue("1") int pageNo)throws SQLException { return this.articleDao.publishNotInPlatform(con,pid, key == null ? null : ("%" + key + "%"), pageSize,pageNo); } @Get @Path("/pageQuery1") public PageQueryResult<Article> pageQueryPublish(@JdbcConn Connection con, String ownerId,String articleType,@Nullable String[] status,@Nullable String key, @DefaultValue("10") int pageSize, @DefaultValue("1") int pageNo) throws SQLException { return this.articleDao.pageQueryPublish(con, ownerId,articleType,status, key == null ? null : ("%" + key + "%"), pageSize, pageNo); } @Get @Path("/qa1") public List<Article> queryPublish(@JdbcConn Connection con, String ownerId, @DefaultValue("\"z\"")String publishTime, @DefaultValue("\"z\"") String articleId,String articleType,@Nullable String[] status,@Nullable String key, int rows) throws SQLException { return this.articleDao.queryPublish(con, ownerId, publishTime, articleId, articleType,status, key == null ? null : ("%" + key + "%"), rows); } @Get @Path("/qaForDesk") public List<Article> queryForDesk(@JdbcConn Connection con, String ownerId) throws SQLException { return this.articleDao.queryForDesk(con, ownerId); } @Get @Path("/qaOrg") public List<Article> queryOrg(@JdbcConn Connection con, String ownerId) throws SQLException { return this.articleDao.queryOrg(con, ownerId); } @Get @Path("/qaOrgPublish") public List<Article> queryOrgPublish(@JdbcConn Connection con, String ownerId) throws SQLException { return this.articleDao.queryOrgPublish(con, ownerId); } @Get @Path("/pqOrgPublish1") public PageQueryResult<Article> pageQueryOrgPublish(@JdbcConn Connection con, String ownerId, @DefaultValue("10") int pageSize, @DefaultValue("1") int pageNo) throws SQLException { return this.articleDao.pageQueryOrgPublish(con, ownerId, pageSize, pageNo); } @Get @Path("/qlOrg") public List<Article> queryLimitOrg(@JdbcConn Connection con, String ownerId, @DefaultValue("com.ekexiu.portal.service.ArticleService.MAX_MODIFYTIME") String modifyTime, @DefaultValue("20") int rows) throws SQLException { return this.articleDao.queryLimit(con, ownerId, modifyTime, rows); } @Get @Path("/query1") public Article queryOne(@JdbcConn Connection con, String articleId) throws SQLException { return this.articleDao.queryOne(con, articleId); } @Get @Path("/pqpublish1") 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.getOwnerId()); 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.getOwnerId()); if (organization != null) { organization.setHasOrgLogo(this.imageService.hasOrgLogo(organization.getId())); } article.setEditOrganization(organization); } } } return queryResult; } @Get @Path("/index/search1") public List<Article> indexSearch(@JdbcConn Connection con, @Nullable String key, @DefaultValue("Long.MAX_VALUE") long sortNum, @DefaultValue("\"9\"") String publishTime, @DefaultValue("\"G\"") String id, @DefaultValue("10000000") int rows) throws SQLException { if (key != null) { key = "%" + key + "%"; } List<Article> articles = this.articleDao.indexSearch(con, key, sortNum, publishTime, id, rows); if (!articles.isEmpty()) { for (Article article : articles) { if ("1".equals(article.getArticleType())) { EditProfessor professor = this.professorDao.queryBaseInfo(con, article.getOwnerId()); 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.getOwnerId()); if (organization != null) { organization.setHasOrgLogo(this.imageService.hasOrgLogo(organization.getId())); } article.setEditOrganization(organization); } } } return articles; } @Get @Path("/pqself1") public PageQueryResult<SelfArticle> queryPageSelf(@JdbcConn Connection con, String articleType, String ownerId, @Nullable String key, @DefaultValue("10") int pageSize, @DefaultValue("1") int pageNo) throws SQLException { if (key != null) { key = "%" + key + "%"; } return this.articleDao.queryPageForSelf(con,articleType,ownerId, key, 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("/ralateArticles1") 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,"1"); } return Collections.<Article> emptyList(); } @Get @Path("/byAssProfessor1") 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("/byAssOrg1") 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("/byAssResource1") 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("/byShareId1") @Get public Article query(@JdbcConn Connection con, long id) throws SQLException { return this.articleDao.query(con, id); } @Path("/find1") @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("/lastestPublished1") @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); } @Path("/lq/byWare1") @Get public List<Article> byWare(@JdbcConn Connection con,String ware,int rows) throws SQLException{ return articleDao.queryByWareId(con, ware, rows); } @Get @Path("/ware") public List<ArticleWare> queryWares(@JdbcConn Connection con,String id)throws SQLException{ return articleDao.queryWares(con, id); } @Get @Path("/lq/byProduct1") public List<Article> byProduct(@JdbcConn Connection con, String product,int rows)throws SQLException { return articleDao.queryByProductId(con, product, rows); } @Get @Path("/product1") public List<ArticleProduct> queryProducts(@JdbcConn Connection con,String id)throws SQLException { return articleDao.queryProduct(con, id); } @Get @Path("/count/publish1") public long countPublish(@JdbcConn Connection con,String category,String owner)throws SQLException { return articleDao.countPublish(con, category, owner); } @Get @Path("/qm1") public List<Article> query(@JdbcConn Connection con,String[] id)throws SQLException { return this.articleDao.query(con, id,null); } public static void main(String[] args) { System.out.println(DateUtil.formatDate(System.currentTimeMillis() - 7 * 24 * 60 * 60 * 1000)); } }