|
|
@@ -1,8 +1,12 @@
|
|
|
package space.apps.moudules.website.services.flow;
|
|
|
|
|
|
+import java.sql.Timestamp;
|
|
|
+import java.text.SimpleDateFormat;
|
|
|
+import java.util.Date;
|
|
|
import java.util.HashMap;
|
|
|
import java.util.HashSet;
|
|
|
import java.util.List;
|
|
|
+import java.util.Locale;
|
|
|
import java.util.Map;
|
|
|
import java.util.Set;
|
|
|
|
|
|
@@ -515,14 +519,11 @@ public class ArticleFlowService extends BaseTransaction {
|
|
|
|
|
|
BpmProcessPageBeanUtil.updatePageBeanForReject(gdba, article);
|
|
|
|
|
|
- // 已发布文章发起变动后被退回,应继续保留原发布状态;
|
|
|
- // 通用退回逻辑会把 dcode=31 改回 11,导致公网文章被隐藏。
|
|
|
+ // 已发布文章发起变动后被退回,应恢复变动前的完整发布快照,
|
|
|
+ // 不能只改回 dcode,否则公网会显示这次未获批准的变动内容。
|
|
|
String flowKey = bpmApp.getApply() == null ? null : bpmApp.getApply().getFlowKey();
|
|
|
if (StringUtil.notNull(flowKey) && flowKey.toLowerCase().contains("articlechange")) {
|
|
|
- article.setDcode(dataStatusCode.USE.getCode());
|
|
|
- Set<String> updateSet = new HashSet<String>();
|
|
|
- updateSet.add("dcode");
|
|
|
- gdba.updateById(article, updateSet);
|
|
|
+ restoreRejectedChangeArticle(gdba, article, articleid);
|
|
|
restoreRejectedChangeArticleCopy(gdba, articleid);
|
|
|
}
|
|
|
|
|
|
@@ -531,6 +532,113 @@ public class ArticleFlowService extends BaseTransaction {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ private void restoreRejectedChangeArticle(GeneralDBAccess gdba, Article article, Long articleid) throws Exception {
|
|
|
+ String sql = "select content from change_log where object = :object and objectid = :articleid "
|
|
|
+ + "order by change_logid desc limit 1 ";
|
|
|
+ SqlCommandImpl sqlCmd = new SqlCommandImpl(sql);
|
|
|
+ sqlCmd.setString("object", "Article");
|
|
|
+ sqlCmd.setInt("articleid", articleid);
|
|
|
+ Map<String, Object> changeLog = gdba.selectAsMap(sqlCmd);
|
|
|
+ if (StringUtil.isNull(changeLog) || StringUtil.isNull(changeLog.get("content"))) {
|
|
|
+ throw new Exception("未找到文章变动前快照");
|
|
|
+ }
|
|
|
+
|
|
|
+ Map<String, Object> snapshot = GsonUtil.jsonToMap2(changeLog.get("content").toString());
|
|
|
+ if (StringUtil.isNull(snapshot)) {
|
|
|
+ throw new Exception("文章变动前快照格式错误");
|
|
|
+ }
|
|
|
+
|
|
|
+ article.setDcode(dataStatusCode.USE.getCode());
|
|
|
+ article.setAscode(articleStatusCode.HAS_RELEASE.getCode());
|
|
|
+ article.setWebsiteid(getSnapshotLong(snapshot, "websiteid"));
|
|
|
+ article.setUnitid(getSnapshotLong(snapshot, "unitid"));
|
|
|
+ article.setNavigationid(getSnapshotLong(snapshot, "navigationid"));
|
|
|
+ article.setTitle(getSnapshotString(snapshot, "title"));
|
|
|
+ article.setAjtcode(getSnapshotLong(snapshot, "ajtcode"));
|
|
|
+ article.setDesc(getSnapshotString(snapshot, "desc"));
|
|
|
+ article.setSource(getSnapshotString(snapshot, "source"));
|
|
|
+ article.setThumbnail(getSnapshotString(snapshot, "thumbnail"));
|
|
|
+ article.setSticktop(getSnapshotLong(snapshot, "sticktop"));
|
|
|
+ article.setSticktopEndTime(getSnapshotTimestamp(snapshot, "sticktopEndTime"));
|
|
|
+ article.setSticktopSchedulesid(getSnapshotLong(snapshot, "sticktopSchedulesid"));
|
|
|
+ article.setRelease(getSnapshotLong(snapshot, "release"));
|
|
|
+ article.setReleaseTime(getSnapshotTimestamp(snapshot, "releaseTime"));
|
|
|
+ article.setReleaseTaskSchedulesid(getSnapshotLong(snapshot, "releaseTaskSchedulesid"));
|
|
|
+ article.setContent(getSnapshotPublishedFile(snapshot, "publishedContentSnapshot", "content"));
|
|
|
+ article.setEditContent(getSnapshotPublishedFile(snapshot, "publishedEditContentSnapshot", "editContent"));
|
|
|
+ article.setUrl(getSnapshotString(snapshot, "url"));
|
|
|
+ article.setSortNumber(getSnapshotLong(snapshot, "sortNumber"));
|
|
|
+ article.setGuestAccessFlag(getSnapshotLong(snapshot, "guestAccessFlag"));
|
|
|
+
|
|
|
+ Set<String> updateSet = new HashSet<String>();
|
|
|
+ updateSet.add("dcode");
|
|
|
+ updateSet.add("ascode");
|
|
|
+ updateSet.add("websiteid");
|
|
|
+ updateSet.add("unitid");
|
|
|
+ updateSet.add("navigationid");
|
|
|
+ updateSet.add("title");
|
|
|
+ updateSet.add("ajtcode");
|
|
|
+ updateSet.add("desc");
|
|
|
+ updateSet.add("source");
|
|
|
+ updateSet.add("thumbnail");
|
|
|
+ updateSet.add("sticktop");
|
|
|
+ updateSet.add("sticktopEndTime");
|
|
|
+ updateSet.add("sticktopSchedulesid");
|
|
|
+ updateSet.add("release");
|
|
|
+ updateSet.add("releaseTime");
|
|
|
+ updateSet.add("releaseTaskSchedulesid");
|
|
|
+ updateSet.add("content");
|
|
|
+ updateSet.add("editContent");
|
|
|
+ updateSet.add("url");
|
|
|
+ updateSet.add("sortNumber");
|
|
|
+ updateSet.add("guestAccessFlag");
|
|
|
+ gdba.updateById(article, updateSet);
|
|
|
+ }
|
|
|
+
|
|
|
+ private String getSnapshotPublishedFile(Map<String, Object> snapshot, String snapshotField, String fallbackField) {
|
|
|
+ String snapshotPath = getSnapshotString(snapshot, snapshotField);
|
|
|
+ return StringUtil.notNull(snapshotPath) ? snapshotPath : getSnapshotString(snapshot, fallbackField);
|
|
|
+ }
|
|
|
+
|
|
|
+ private String getSnapshotString(Map<String, Object> snapshot, String key) {
|
|
|
+ Object value = snapshot.get(key);
|
|
|
+ return value == null ? null : value.toString();
|
|
|
+ }
|
|
|
+
|
|
|
+ private Long getSnapshotLong(Map<String, Object> snapshot, String key) {
|
|
|
+ Object value = snapshot.get(key);
|
|
|
+ if (StringUtil.isNull(value)) {
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+ if (value instanceof Number) {
|
|
|
+ return ((Number) value).longValue();
|
|
|
+ }
|
|
|
+ return Long.valueOf(value.toString());
|
|
|
+ }
|
|
|
+
|
|
|
+ private Timestamp getSnapshotTimestamp(Map<String, Object> snapshot, String key) {
|
|
|
+ String value = getSnapshotString(snapshot, 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;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
private void restoreRejectedChangeArticleCopy(GeneralDBAccess gdba, Long articleid) throws Exception {
|
|
|
String sql = "select * from article_copy where articleid = :articleid and dcode in (21, 31, 41, 51) ";
|
|
|
SqlCommandImpl sqlCmd = new SqlCommandImpl(sql);
|