?? articlemngimpl.java
字號:
bean.setMember(member);
bean = save(bean);
// 寫文章內容
bean.writeContent(contextPvd.getAppRoot(), 0);
// 欄目文檔數量
CmsChannel chnl = bean.getChannel();
chnl.setDocCount(chnl.getDocCount() + 1);
// 新增附件
addAttachment(bean, rule, member.getMember().getUser(), member);
return bean;
}
private Updater createUpdater(Article bean) {
Updater updater = Updater.create(bean);
// 控制不能更新的字段
updater.exclude(Article.PROP_WEBSITE);
updater.exclude(Article.PROP_CONFIG);
updater.exclude(Article.PROP_CONTENT_RES_PATH);
updater.exclude(Article.PROP_ADMIN_CHECK);
updater.exclude(Article.PROP_ADMIN_DISABLE);
updater.exclude(Article.PROP_ADMIN_INPUT);
updater.exclude(Article.PROP_CHECK);
updater.exclude(Article.PROP_CHECK_OPINION);
updater.exclude(Article.PROP_CHECK_STEP);
updater.exclude(Article.PROP_CHECK_TIME);
updater.exclude(Article.PROP_CONTENT_RES_PATH);
updater.exclude(Article.PROP_DISABLE_TIME);
updater.exclude(Article.PROP_REJECT);
return updater;
}
private void handleTopTimeForUpdate(Article entity, long topTime) {
if (topTime == -1) {
// 清空置頂時間
entity.setSortDate(entity.getReleaseDate());
} else if (topTime > 0) {
// 增加指定時間,將小時轉換成毫秒
topTime *= 60 * 60 * 1000;
entity.setSortDate(new Timestamp(entity.getSortDate().getTime()
+ topTime));
} else {
// do nothing
}
}
private void handleTitleImg(Article arti) {
// 如果標題圖為空,則設置沒有標題圖片。
if (StringUtils.isBlank(arti.getTitleImg())) {
arti.setTitleImg("");
arti.setHasTitleImg(false);
} else {
arti.setHasTitleImg(true);
}
}
private void initDefValue(Article arti) {
arti.setDisabled(false);
arti.setReject(false);
arti.setCheck(false);
arti.setHasTitleImg(false);
arti.setCheckStep(-1);
arti.setCheckOpinion("");
if (arti.getContent() == null) {
arti.setContent("");
}
if (arti.getBold() == null) {
arti.setBold(false);
}
if (arti.getTopLevel() == null) {
arti.setTopLevel(0);
}
if (arti.getAllowComment() == null) {
arti.setAllowComment(true);
}
if (arti.getDraft() == null) {
arti.setDraft(false);
}
if (arti.getRecommend() == null) {
arti.setRecommend(false);
}
arti.setCommentCount(0);
arti.setVisitTotal(0L);
arti.setStatDate(ComUtils.now());
arti.setVisitToday(0L);
arti.setVisitWeek(0L);
arti.setVisitMonth(0L);
arti.setVisitQuarter(0L);
arti.setVisitYear(0L);
}
private void handleDate(Article arti, long topTime) {
Date now = ComUtils.now();
arti.setReleaseSysDate(now);
// 如果沒有輸入發布時間,則取系統時間;
Date relDate = arti.getReleaseDate();
if (relDate == null) {
relDate = now;
arti.setReleaseDate(relDate);
}
// 置頂時間
topTime *= 60 * 60 * 1000;
arti.setSortDate(new Date(relDate.getTime() + topTime));
}
/**
* 管理員審核權限作為文章審核級數,然后判斷文章是否審核通過。
*
* @param arti
* @param admin
* @param checkCount
* 站點審核步驟數
*/
private void handleCheckRight(Article arti, CmsAdmin admin, int checkCount) {
int checkRight = admin.getCheckRight();
// 審核步驟為自己
arti.setCheckStep(checkRight);
// 草稿不能為審核通過
if (arti.getDraft() || checkCount > checkRight) {
arti.setCheck(false);
} else {
arti.setCheck(true);
}
// 修改和添加的時候退回和審核意見都為空
arti.setReject(false);
arti.setCheckOpinion("");
// 修改可以認為是一種審核
arti.setAdminCheck(admin);
arti.setCheckTime(ComUtils.now());
}
private void addSideArticle(Article entity) {
// 處理上一篇、下一篇
if (!entity.getCheck() && entity.getDisabled()) {
return;
}
Long webId = entity.getWebsite().getId();
Long chnlId = entity.getChannel().getId();
Article pre = getDao().getSideArticle(webId, chnlId, entity.getId(),
false);
if (pre != null) {
Article next = pre.getNext();
pre.setNext(entity);
entity.setPre(pre);
entity.setNext(next);
} else {
Article next = getDao().getSideArticle(webId, chnlId,
entity.getId(), true);
if (next != null) {
next.setPre(entity);
entity.setNext(next);
}
}
}
private void removeSideArticle(Article entity) {
Article pre = entity.getPre();
Article next = entity.getNext();
if (pre != null) {
pre.setNext(next);
}
if (next != null) {
next.setPre(pre);
}
}
/**
* 新增附件
*
* @param entity
* @param rule
* @param web
* @param user
*/
private void addAttachment(Article entity, UploadRule rule, User user,
CmsMember member) {
Website web = entity.getWebsite();
Map<String, UploadFile> uploadFiles = rule.getUploadFiles();
if (uploadFiles != null) {
String content = entity.getContent();
String titleImg = entity.getTitleImg();
String contentImg = entity.getContentImg();
Set<String> rmFile = new HashSet<String>();
Attachment attach;
UploadFile uf;
String rootPath = contextPvd.getAppRealPath(web.getUploadRoot()
.toString());
for (String name : uploadFiles.keySet()) {
if (StringUtils.contains(content, name)
|| StringUtils.contains(titleImg, name)
|| StringUtils.contains(contentImg, name)) {
rmFile.add(name);
attach = new Attachment();
uf = uploadFiles.get(name);
attach.setWebsite(web);
attach.setUser(user);
attach.setName(uf.getOrigName());
attach.setFileName(uf.getFileName());
attach.setFilePath(uf.getRelPath(rootPath));
attach.setFileSize((int) (uf.getSize() / 1024) + 1);
attach.setOwnerCtg(Article.ATTACHMENT_CTG);
attach.setOwnerId(entity.getId());
attach.setOwnerName(entity.getTitle());
attach.setOwnerUrl(entity.getUrl());
attach.setDownCount(0L);
attach.setCreateTime(ComUtils.now());
if (entity.getGroup() == null) {
attach.setFree(true);
} else {
attach.setFree(false);
}
attach.setLost(false);
entity.addToAttachments(attach);
if (member != null) {
member.addUploadSize((int) uf.getSize());
}
}
}
for (String name : rmFile) {
rule.removeUploadFile(name);
}
}
}
private void removeAttachment(Article entity, boolean removeAll) {
Set<Attachment> attachs = entity.getAttachments();
String content = entity.getContentFromFile();
String titleImg = entity.getTitleImg();
String contentImg = entity.getContentImg();
Set<Attachment> rmAttachs = new HashSet<Attachment>();
String filename;
for (Attachment attach : attachs) {
filename = attach.getFileName();
if (removeAll
|| (!StringUtils.contains(content, filename)
&& !StringUtils.contains(titleImg, filename) && !StringUtils
.contains(contentImg, filename))) {
String realPath = contextPvd
.getAppRealPath(attach.getRelPath());
if (new File(realPath).delete()) {
log.info("刪除附件:{}", realPath);
} else {
log.warn("刪除附件失敗:{}", realPath);
}
rmAttachs.add(attach);
}
}
attachs.removeAll(rmAttachs);
}
public Article findById(Serializable id) {
Article arti = super.findById(id);
if (arti == null) {
return null;
}
// 用于操作文件
arti.setRootReal(contextPvd.getAppRoot());
return arti;
}
public Article findAndCheckResPath(Serializable id) {
Article arti = super.findById(id);
if (arti == null) {
return null;
}
// 用于操作文件
arti.setRootReal(contextPvd.getAppRoot());
if (arti.isResPathChannge()) {
arti.updateResPath();
}
return arti;
}
@Autowired
private ContextPvd contextPvd;
@Autowired
private CmsAdminMng cmsAdminMng;
@Autowired
private ContentCtgMng contentCtgMng;
@Autowired
private CmsConfigMng cmsConfigMng;
@Autowired
public void setDao(ArticleDao dao) {
super.setDao(dao);
}
protected ArticleDao getDao() {
return (ArticleDao) super.getDao();
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -