|
|
@@ -1,6 +1,11 @@
|
|
|
package space.apps.moudules.website.template.util;
|
|
|
|
|
|
+import java.sql.Timestamp;
|
|
|
+import java.text.SimpleDateFormat;
|
|
|
+import java.util.Date;
|
|
|
+import java.util.Iterator;
|
|
|
import java.util.List;
|
|
|
+import java.util.Locale;
|
|
|
import java.util.Map;
|
|
|
|
|
|
import javax.servlet.http.HttpServletRequest;
|
|
|
@@ -13,6 +18,7 @@ import space.common.exception.SpaceNullPointerException;
|
|
|
import space.core.common.CommonVars;
|
|
|
import space.core.common.utils.DateTimeUtil;
|
|
|
import space.core.common.utils.FileUtil;
|
|
|
+import space.core.common.utils.GsonUtil;
|
|
|
import space.core.common.utils.StringUtil;
|
|
|
import space.core.db.bean.base.PageBean;
|
|
|
import space.core.db.jdbc.GeneralDBAccess;
|
|
|
@@ -26,6 +32,13 @@ import space.core.db.jdbc.SqlCommandImpl;
|
|
|
*/
|
|
|
public class WebsiteTemplateArticleUtil {
|
|
|
|
|
|
+ private static final Long ARTICLE_DCODE_USE = 61L;
|
|
|
+ private static final Long ARTICLE_DCODE_CHANGING = 31L;
|
|
|
+ private static final Long ARTICLE_ASCODE_RELEASED = 10010L;
|
|
|
+ private static final String CHANGE_LOG_OBJECT_ARTICLE = "Article";
|
|
|
+ private static final String PUBLISHED_CONTENT_SNAPSHOT_FIELD = "publishedContentSnapshot";
|
|
|
+ private static final String PUBLISHED_EDIT_CONTENT_SNAPSHOT_FIELD = "publishedEditContentSnapshot";
|
|
|
+
|
|
|
/**
|
|
|
* 获取栏目的子栏目文章列表
|
|
|
*
|
|
|
@@ -41,17 +54,20 @@ public class WebsiteTemplateArticleUtil {
|
|
|
public static List<Map<String, Object>> getAllChildrenArticleList(GeneralDBAccess gdba, Long navId,
|
|
|
boolean isThumbnailFlag, PageBean pb) throws Exception {
|
|
|
|
|
|
- String sql = "SELECT a.*, w.protocol, w.port, w.domains FROM article a left join website w on a.websiteid = w.websiteid where w.dcode = 61 and a.dcode = 61 "
|
|
|
- + " and a.ascode = '10010' and (a.navigationid in (Select navigationid from website_navigation where parent_nid = :navigationid1 ) "
|
|
|
- + " or a.articleid in (Select ac.articleid from article_copy ac, article a where a.articleid = ac.articleid and ac.dcode = 61 "
|
|
|
- + " and a.dcode = 61 and a.ascode = '10010' and ac.navigationid in (Select navigationid from website_navigation where parent_nid = :navigationid2 ) ))"
|
|
|
+ String sql = "SELECT a.*, w.protocol, w.port, w.domains FROM article a left join website w on a.websiteid = w.websiteid where w.dcode = 61 and "
|
|
|
+ + getPublishedOrChangingArticleSql("a")
|
|
|
+ + " and (a.navigationid in (Select navigationid from website_navigation where parent_nid = :navigationid1 ) "
|
|
|
+ + " or a.articleid in (Select ac.articleid from article_copy ac, article ca where ca.articleid = ac.articleid and ac.dcode = 61 "
|
|
|
+ + " and " + getPublishedOrChangingArticleSql("ca")
|
|
|
+ + " and ac.navigationid in (Select navigationid from website_navigation where parent_nid = :navigationid2 ) ))"
|
|
|
+ (isThumbnailFlag ? " and a.thumbnail is not null" : "") // thumbnail
|
|
|
- + "order by a.sticktop desc, a.release_time desc, a.articleid desc";
|
|
|
+ + " order by a.sticktop desc, a.release_time desc, a.articleid desc";
|
|
|
|
|
|
SqlCommandImpl sqlCmd = new SqlCommandImpl(sql);
|
|
|
sqlCmd.setString("navigationid1", navId).setString("navigationid2", navId);
|
|
|
List<Map<String, Object>> articleList = gdba.selectAsMapList(sqlCmd, pb);
|
|
|
|
|
|
+ restoreChangingArticleListPublishedVersion(gdba, articleList);
|
|
|
transformArticleURL(articleList);
|
|
|
|
|
|
return articleList;
|
|
|
@@ -90,7 +106,7 @@ public class WebsiteTemplateArticleUtil {
|
|
|
SqlCommandImpl sqlCmd = new SqlCommandImpl(sql);
|
|
|
sqlCmd.setString("websiteid", website.getWebsiteid()).setString("uri", uri);
|
|
|
Article a = (Article) gdba.selectAsBean(sqlCmd, Article.class);
|
|
|
- return a;
|
|
|
+ return a == null ? getChangingArticlePublishedVersionByURI(gdba, website, uri) : a;
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
@@ -138,9 +154,11 @@ public class WebsiteTemplateArticleUtil {
|
|
|
PageBean pb) throws Exception {
|
|
|
|
|
|
String sql = "SELECT a.*, w.protocol, w.port, w.domains FROM article a left join website w on a.websiteid = w.websiteid "
|
|
|
- + "where w.dcode = 61 and a.dcode = 61 and a.ascode = '10010' and (a.navigationid = :navigationid1 "
|
|
|
- + "or a.articleid in (Select ac.articleid from article_copy ac, article a "
|
|
|
- + "where a.articleid = ac.articleid and ac.dcode = 61 and a.dcode = 61 and a.ascode = '10010' and ac.navigationid = :navigationid2 ))"
|
|
|
+ + "where w.dcode = 61 and " + getPublishedOrChangingArticleSql("a")
|
|
|
+ + " and (a.navigationid = :navigationid1 "
|
|
|
+ + "or a.articleid in (Select ac.articleid from article_copy ac, article ca "
|
|
|
+ + "where ca.articleid = ac.articleid and ac.dcode = 61 and "
|
|
|
+ + getPublishedOrChangingArticleSql("ca") + " and ac.navigationid = :navigationid2 ))"
|
|
|
+ (isThumbnailFlag ? " and a.thumbnail is not null" : "") // thumbnail
|
|
|
+ " order by a.sticktop desc, a.release_time desc ";
|
|
|
|
|
|
@@ -148,6 +166,7 @@ public class WebsiteTemplateArticleUtil {
|
|
|
sqlCmd.setString("navigationid1", navId).setString("navigationid2", navId);
|
|
|
List<Map<String, Object>> articleList = gdba.selectAsMapList(sqlCmd, pb);
|
|
|
|
|
|
+ restoreChangingArticleListPublishedVersion(gdba, articleList);
|
|
|
transformArticleURL(articleList);
|
|
|
|
|
|
return articleList;
|
|
|
@@ -183,13 +202,15 @@ public class WebsiteTemplateArticleUtil {
|
|
|
public static List<Map<String, Object>> getArticleList(GeneralDBAccess gdba, String keyword, PageBean pb)
|
|
|
throws Exception {
|
|
|
|
|
|
- String sql = "SELECT a.*, w.protocol, w.port, w.domains FROM article a left join website w on a.websiteid = w.websiteid where w.dcode = 61 and a.dcode = 61"
|
|
|
- + " and a.ascode = '10010' and title like :keyword order by a.sticktop desc, a.release_time desc";
|
|
|
+ String sql = "SELECT a.*, w.protocol, w.port, w.domains FROM article a left join website w on a.websiteid = w.websiteid where w.dcode = 61 and "
|
|
|
+ + getPublishedOrChangingArticleSql("a")
|
|
|
+ + " and title like :keyword order by a.sticktop desc, a.release_time desc";
|
|
|
|
|
|
SqlCommandImpl sqlCmd = new SqlCommandImpl(sql);
|
|
|
sqlCmd.setString("keyword", "%" + keyword + "%");
|
|
|
List<Map<String, Object>> articleList = gdba.selectAsMapList(sqlCmd, pb);
|
|
|
|
|
|
+ restoreChangingArticleListPublishedVersion(gdba, articleList);
|
|
|
transformArticleURL(articleList);
|
|
|
|
|
|
return articleList;
|
|
|
@@ -213,7 +234,7 @@ public class WebsiteTemplateArticleUtil {
|
|
|
+ "FROM article a "
|
|
|
+ "left join website w on a.websiteid = w.websiteid "
|
|
|
+ "left join website_navigation wn on a.navigationid = wn.navigationid "
|
|
|
- + "where w.dcode = 61 and a.dcode = 61 and a.ascode = '10010' "
|
|
|
+ + "where w.dcode = 61 and " + getPublishedOrChangingArticleSql("a") + " "
|
|
|
+ "and (w.websiteid = :rootWebsiteId1 "
|
|
|
+ "or w.parent_wid = :rootWebsiteId2 "
|
|
|
+ "or w.parent_wid in (select sw.websiteid from website sw where sw.dcode = 61 and sw.parent_wid = :rootWebsiteId3) "
|
|
|
@@ -228,11 +249,200 @@ public class WebsiteTemplateArticleUtil {
|
|
|
.setString("keyword1", "%" + keyword + "%").setString("keyword2", "%" + keyword + "%");
|
|
|
List<Map<String, Object>> articleList = gdba.selectAsMapList(sqlCmd, pb);
|
|
|
|
|
|
+ restoreChangingArticleListPublishedVersion(gdba, articleList);
|
|
|
transformArticleURL(articleList);
|
|
|
|
|
|
return articleList;
|
|
|
}
|
|
|
|
|
|
+ private static String getPublishedOrChangingArticleSql(String alias) {
|
|
|
+ return "((" + alias + ".dcode = 61 and " + alias + ".ascode = '10010') or " + alias + ".dcode = 31)";
|
|
|
+ }
|
|
|
+
|
|
|
+ private static Article getChangingArticlePublishedVersionByURI(GeneralDBAccess gdba, Website website, String uri)
|
|
|
+ throws Exception {
|
|
|
+ String sql = "SELECT cl.content FROM change_log cl where cl.object = :object and cl.content like :uriLike "
|
|
|
+ + "and cl.objectid in (select ca.articleid from article ca where ca.dcode = :changingDcode) "
|
|
|
+ + "order by cl.change_logid desc limit 0,20";
|
|
|
+ SqlCommandImpl sqlCmd = new SqlCommandImpl(sql);
|
|
|
+ sqlCmd.setString("object", CHANGE_LOG_OBJECT_ARTICLE).setString("uriLike", "%" + uri + "%")
|
|
|
+ .setString("changingDcode", ARTICLE_DCODE_CHANGING);
|
|
|
+ List<Map<String, Object>> logList = gdba.selectAsMapList(sqlCmd);
|
|
|
+ if (logList == null || logList.size() == 0) {
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+
|
|
|
+ for (Map<String, Object> log : logList) {
|
|
|
+ Article article = buildPublishedArticleFromChangeLog(log.get("content"), website.getWebsiteid(), uri);
|
|
|
+ if (article != null) {
|
|
|
+ return article;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+
|
|
|
+ private static Article getChangingArticlePublishedVersionByArticleID(GeneralDBAccess gdba, Long articleid)
|
|
|
+ throws Exception {
|
|
|
+ String sql = "SELECT content FROM change_log where object = :object and objectid = :articleid "
|
|
|
+ + "order by change_logid desc limit 0,20";
|
|
|
+ SqlCommandImpl sqlCmd = new SqlCommandImpl(sql);
|
|
|
+ sqlCmd.setString("object", CHANGE_LOG_OBJECT_ARTICLE).setString("articleid", articleid);
|
|
|
+ List<Map<String, Object>> logList = gdba.selectAsMapList(sqlCmd);
|
|
|
+ if (logList == null || logList.size() == 0) {
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+
|
|
|
+ for (Map<String, Object> log : logList) {
|
|
|
+ Article article = buildPublishedArticleFromChangeLog(log.get("content"), null, null);
|
|
|
+ if (article != null) {
|
|
|
+ return article;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+
|
|
|
+ private static Article buildPublishedArticleFromChangeLog(Object logContent, Long websiteid, String uri) {
|
|
|
+ if (StringUtil.isNull(logContent)) {
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+
|
|
|
+ Map<String, Object> articleMap = GsonUtil.jsonToMap(logContent.toString());
|
|
|
+ if (!ARTICLE_DCODE_USE.equals(getLongValue(articleMap, "dcode"))
|
|
|
+ || !ARTICLE_ASCODE_RELEASED.equals(getLongValue(articleMap, "ascode"))) {
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+ if (websiteid != null && !websiteid.equals(getLongValue(articleMap, "websiteid"))) {
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+ if (uri != null && !uri.equals(getStringValue(articleMap, "url"))) {
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+
|
|
|
+ Article article = new Article();
|
|
|
+ article.setArticleid(getLongValue(articleMap, "articleid"));
|
|
|
+ article.setDcode(ARTICLE_DCODE_USE);
|
|
|
+ article.setWebsiteid(getLongValue(articleMap, "websiteid"));
|
|
|
+ article.setUnitid(getLongValue(articleMap, "unitid"));
|
|
|
+ article.setAscode(ARTICLE_ASCODE_RELEASED);
|
|
|
+ article.setNavigationid(getLongValue(articleMap, "navigationid"));
|
|
|
+ article.setTitle(getStringValue(articleMap, "title"));
|
|
|
+ article.setAjtcode(getLongValue(articleMap, "ajtcode"));
|
|
|
+ article.setDesc(getStringValue(articleMap, "desc"));
|
|
|
+ article.setSource(getStringValue(articleMap, "source"));
|
|
|
+ article.setThumbnail(getStringValue(articleMap, "thumbnail"));
|
|
|
+ article.setSticktop(getLongValue(articleMap, "sticktop"));
|
|
|
+ article.setSticktopEndTime(getTimestampValue(articleMap, "sticktopEndTime"));
|
|
|
+ article.setSticktopSchedulesid(getLongValue(articleMap, "sticktopSchedulesid"));
|
|
|
+ article.setRelease(getLongValue(articleMap, "release"));
|
|
|
+ article.setReleaseTime(getTimestampValue(articleMap, "releaseTime"));
|
|
|
+ article.setReleaseTaskSchedulesid(getLongValue(articleMap, "releaseTaskSchedulesid"));
|
|
|
+ article.setContent(getStringValue(articleMap, PUBLISHED_CONTENT_SNAPSHOT_FIELD));
|
|
|
+ if (StringUtil.isNull(article.getContent())) {
|
|
|
+ article.setContent(getStringValue(articleMap, "content"));
|
|
|
+ }
|
|
|
+ article.setEditContent(getStringValue(articleMap, PUBLISHED_EDIT_CONTENT_SNAPSHOT_FIELD));
|
|
|
+ if (StringUtil.isNull(article.getEditContent())) {
|
|
|
+ article.setEditContent(getStringValue(articleMap, "editContent"));
|
|
|
+ }
|
|
|
+ article.setUrl(getStringValue(articleMap, "url"));
|
|
|
+ article.setReadCount(getLongValue(articleMap, "readCount"));
|
|
|
+ article.setCreateTime(getTimestampValue(articleMap, "createTime"));
|
|
|
+ article.setLastChangeTime(getTimestampValue(articleMap, "lastChangeTime"));
|
|
|
+ article.setCreatePid(getLongValue(articleMap, "createPid"));
|
|
|
+ article.setLastChangePid(getLongValue(articleMap, "lastChangePid"));
|
|
|
+ return article;
|
|
|
+ }
|
|
|
+
|
|
|
+ private static void restoreChangingArticleListPublishedVersion(GeneralDBAccess gdba,
|
|
|
+ List<Map<String, Object>> articleList) throws Exception {
|
|
|
+ if (articleList == null || articleList.size() == 0) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ Iterator<Map<String, Object>> iterator = articleList.iterator();
|
|
|
+ while (iterator.hasNext()) {
|
|
|
+ Map<String, Object> articleMap = iterator.next();
|
|
|
+ if (!ARTICLE_DCODE_CHANGING.equals(getLongValue(articleMap, "dcode"))) {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+
|
|
|
+ Article article = getChangingArticlePublishedVersionByArticleID(gdba, getLongValue(articleMap, "articleid"));
|
|
|
+ if (article == null) {
|
|
|
+ iterator.remove();
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+
|
|
|
+ putArticleValueToMap(articleMap, article);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private static void putArticleValueToMap(Map<String, Object> articleMap, Article article) {
|
|
|
+ articleMap.put("articleid", article.getArticleid());
|
|
|
+ articleMap.put("dcode", article.getDcode());
|
|
|
+ articleMap.put("websiteid", article.getWebsiteid());
|
|
|
+ articleMap.put("unitid", article.getUnitid());
|
|
|
+ articleMap.put("ascode", article.getAscode());
|
|
|
+ articleMap.put("navigationid", article.getNavigationid());
|
|
|
+ articleMap.put("title", article.getTitle());
|
|
|
+ articleMap.put("ajtcode", article.getAjtcode());
|
|
|
+ articleMap.put("desc", article.getDesc());
|
|
|
+ articleMap.put("source", article.getSource());
|
|
|
+ articleMap.put("thumbnail", article.getThumbnail());
|
|
|
+ articleMap.put("sticktop", article.getSticktop());
|
|
|
+ articleMap.put("sticktop_end_time", article.getSticktopEndTime());
|
|
|
+ articleMap.put("sticktop_schedulesid", article.getSticktopSchedulesid());
|
|
|
+ articleMap.put("release", article.getRelease());
|
|
|
+ articleMap.put("release_time", article.getReleaseTime());
|
|
|
+ articleMap.put("release_task_schedulesid", article.getReleaseTaskSchedulesid());
|
|
|
+ articleMap.put("content", article.getContent());
|
|
|
+ articleMap.put("edit_content", article.getEditContent());
|
|
|
+ articleMap.put("url", article.getUrl());
|
|
|
+ articleMap.put("read_count", article.getReadCount());
|
|
|
+ articleMap.put("create_time", article.getCreateTime());
|
|
|
+ articleMap.put("last_change_time", article.getLastChangeTime());
|
|
|
+ articleMap.put("create_pid", article.getCreatePid());
|
|
|
+ articleMap.put("last_change_pid", article.getLastChangePid());
|
|
|
+ }
|
|
|
+
|
|
|
+ private static String getStringValue(Map<String, Object> map, String key) {
|
|
|
+ Object value = map.get(key);
|
|
|
+ return StringUtil.isNull(value) ? null : value.toString();
|
|
|
+ }
|
|
|
+
|
|
|
+ private static Long getLongValue(Map<String, Object> map, String key) {
|
|
|
+ Object value = map.get(key);
|
|
|
+ if (StringUtil.isNull(value)) {
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+ if (value instanceof Number) {
|
|
|
+ return ((Number) value).longValue();
|
|
|
+ }
|
|
|
+ return Long.valueOf(value.toString());
|
|
|
+ }
|
|
|
+
|
|
|
+ private static Timestamp getTimestampValue(Map<String, Object> map, String key) {
|
|
|
+ String value = getStringValue(map, key);
|
|
|
+ if (StringUtil.isNull(value)) {
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+
|
|
|
+ String[] patterns = new String[] { "MMM d, yyyy h:mm:ss a", "yyyy-MM-dd HH:mm:ss", "yyyy-MM-dd HH:mm" };
|
|
|
+ for (String pattern : patterns) {
|
|
|
+ try {
|
|
|
+ Date date = new SimpleDateFormat(pattern, Locale.ENGLISH).parse(value);
|
|
|
+ return new Timestamp(date.getTime());
|
|
|
+ } catch (Exception e) {
|
|
|
+ // 尝试下一种历史日志里的时间格式。
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ try {
|
|
|
+ return Timestamp.valueOf(value);
|
|
|
+ } catch (Exception e) {
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* 获取文章列表
|
|
|
*
|