?? articlemngimpl.java
字號:
package com.jeecms.article.manager.impl;
import java.io.File;
import java.io.Serializable;
import java.sql.Timestamp;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.Assert;
import com.jeecms.article.dao.ArticleDao;
import com.jeecms.article.entity.Article;
import com.jeecms.article.manager.ArticleMng;
import com.jeecms.cms.entity.CmsAdmin;
import com.jeecms.cms.entity.CmsChannel;
import com.jeecms.cms.entity.CmsComment;
import com.jeecms.cms.entity.CmsMember;
import com.jeecms.cms.entity.ContentCtg;
import com.jeecms.cms.manager.CmsAdminMng;
import com.jeecms.cms.manager.CmsCommentMng;
import com.jeecms.cms.manager.CmsConfigMng;
import com.jeecms.cms.manager.ContentCtgMng;
import com.jeecms.core.JeeCoreManagerImpl;
import com.jeecms.core.entity.Attachment;
import com.jeecms.core.entity.User;
import com.jeecms.core.entity.Website;
import com.jeecms.core.service.LuceneSvc;
import com.jeecms.core.util.UploadRule;
import com.jeecms.core.util.UploadRule.UploadFile;
import com.ponyjava.common.hibernate3.Updater;
import com.ponyjava.common.page.Pagination;
import com.ponyjava.common.struts2.ContextPvd;
import com.ponyjava.common.util.ComUtils;
@Service
@Transactional
public class ArticleMngImpl extends JeeCoreManagerImpl<Article> implements
ArticleMng {
public Pagination getForTag(Long webId, Long chnlId, Long ctgId,
String searchKey, Boolean hasTitleImg, boolean recommend,
int orderBy, boolean isPage, int firstResult, int pageNo,
int pageSize) {
return getDao().getForTag(webId, chnlId, ctgId, searchKey, hasTitleImg,
recommend, orderBy, isPage, firstResult, pageNo, pageSize);
}
public Pagination getRightArticle(Long webId, Long chnlId, Long adminId,
Long inputAdminId, Long contentCtgId, boolean disabled,
boolean topTime, Integer topLevel, int status, String title,
int order, int pageNo, int pageSize) {
return getDao().getRightArticle(webId, chnlId, adminId, inputAdminId,
contentCtgId, disabled, topTime, topLevel, status, title,
order, pageNo, pageSize);
}
public Pagination getArticleForMember(Long memberId, Long webId,
Boolean draft, Boolean check, Boolean reject, int pageNo,
int pageSize) {
return getDao().getArticleForMember(memberId, webId, draft, check,
reject, pageNo, pageSize);
}
public Pagination getUncheckArticle(Long adminId, int pageNo, int pageSize) {
return getDao().getUncheckArticle(adminId, pageNo, pageSize);
}
public Pagination getUnsigninArticle(Long adminId, int pageNo, int pageSize) {
return getDao().getUnsigninArticle(adminId, pageNo, pageSize);
}
public Article saveArticle(Article bean, CmsAdmin admin, UploadRule rule,
String resUrl, int checkCount, long topTime) {
Assert.notNull(bean);
Assert.notNull(admin);
Assert.notNull(rule);
Assert.notNull(resUrl);
initDefValue(bean);
handleTitleImg(bean);
handleDate(bean, topTime);
handleCheckRight(bean, admin, checkCount);
// 文章頁數(shù)
bean.calculatePageCount();
bean.setContentResPath(resUrl);
bean.setAdminInput(admin);
bean = save(bean);
// 寫文章內(nèi)容
bean.writeContent(contextPvd.getAppRoot(), 0);
// 欄目文檔數(shù)量
CmsChannel chnl = bean.getChannel();
chnl.setDocCount(chnl.getDocCount() + 1);
// 處理上一篇、下一篇
addSideArticle(bean);
// 新增附件
addAttachment(bean, rule, admin.getAdmin().getUser(), null);
// 增加全文檢索
// addToLucene(bean);
return bean;
}
public Article updateArticle(Article arti, CmsAdmin admin, UploadRule rule,
String resUrl, long topTime) {
Assert.notNull(arti);
Assert.notNull(admin);
Assert.notNull(rule);
Assert.notNull(resUrl);
Article entity = findById(arti.getId());
Website web = entity.getWebsite();
User user = admin.getAdmin().getUser();
admin = cmsAdminMng.getAdminByUserId(web.getId(), user.getId());
handleTitleImg(arti);
arti.calculatePageCount();
int origCount = entity.getPageCount();
CmsChannel origChnl = entity.getChannel();
boolean origCheck = entity.getCheck();
updateByUpdater(createUpdater(arti));
entity.writeContent(contextPvd.getAppRoot(), origCount);
handleTopTimeForUpdate(entity, topTime);
handleCheckRight(entity, admin, entity.getConfig().getCheckCount());
if (entity.getAdminInput() == null) {
entity.setAdminInput(admin);
}
boolean currCheck = entity.getCheck();
if (currCheck != origCheck) {
if (currCheck) {
addSideArticle(entity);
} else {
removeSideArticle(entity);
}
}
CmsChannel currChnl = entity.getChannel();
if (!currChnl.equals(origChnl)) {
// 欄目文檔數(shù)量
currChnl.setDocCount(currChnl.getDocCount() + 1);
origChnl.setDocCount(origChnl.getDocCount() - 1);
removeSideArticle(entity);
addSideArticle(entity);
}
// 附件
removeAttachment(entity, false);
addAttachment(entity, rule, user, null);
return entity;
}
@Override
public Article deleteById(Serializable id) {
// 處理上一篇、下一篇
Article entity = findById(id);
CmsChannel chnl = entity.getChannel();
removeSideArticle(entity);
delete(entity);
chnl.setDocCount(chnl.getDocCount() - 1);
// 刪除評論
CmsCommentMng.deleteComment(entity.getId(), CmsComment.DOC_ARTICLE);
removeAttachment(entity, true);
entity.deleteContentFile(contextPvd.getAppRoot());
return entity;
}
public Article disableArticle(Long id, CmsAdmin admin, boolean disable) {
Article entity = findById(id);
if (disable) {
removeSideArticle(entity);
} else {
addSideArticle(entity);
}
entity.setDisabled(disable);
entity.setAdminDisable(admin);
entity.setDisableTime(ComUtils.now());
return entity;
}
public List<Article> disableArticle(Long[] ids, CmsAdmin admin,
boolean disable) {
List<Article> dts = new ArrayList<Article>();
Article entity = null;
if (ids != null && ids.length > 0) {
for (Long id : ids) {
entity = disableArticle(id, admin, disable);
if (entity != null) {
dts.add(entity);
}
}
}
return dts;
}
public Article checkArticle(Long id, CmsAdmin admin) {
Article entity = findById(id);
admin = cmsAdminMng.getAdminByUserId(entity.getWebsite().getId(), admin
.getAdmin().getUser().getId());
handleCheckRight(entity, admin, entity.getConfig().getCheckCount());
removeSideArticle(entity);
return entity;
}
public List<Article> checkArticle(Long[] ids, CmsAdmin admin) {
List<Article> dts = new ArrayList<Article>();
Article entity = null;
if (ids != null && ids.length > 0) {
for (Long id : ids) {
entity = checkArticle(id, admin);
if (entity != null) {
dts.add(entity);
}
}
}
return dts;
}
public Article rejectArticle(Long id, CmsAdmin admin, String opinion) {
Article entity = findById(id);
admin = cmsAdminMng.getAdminByUserId(entity.getWebsite().getId(), admin
.getAdmin().getUser().getId());
if (entity.getCheckStep() >= admin.getCheckRight()) {
return entity;
}
entity.setAdminCheck(admin);
entity.setReject(true);
entity.setCheckTime(ComUtils.now());
entity.setCheckOpinion(opinion);
return entity;
}
public List<Article> rejectArticle(Long[] ids, CmsAdmin admin,
String opinion) {
List<Article> dts = new ArrayList<Article>();
Article entity = null;
if (ids != null && ids.length > 0) {
for (Long id : ids) {
entity = rejectArticle(id, admin, opinion);
if (entity != null) {
dts.add(entity);
}
}
}
return dts;
}
public Article signinArticle(Long id, CmsAdmin admin) {
Article entity = findById(id);
admin = cmsAdminMng.getAdminByUserId(entity.getWebsite().getId(), admin
.getAdmin().getUser().getId());
if (entity.getCheckStep() >= admin.getCheckRight()) {
return entity;
}
entity.setAdminInput(admin);
handleCheckRight(entity, admin, entity.getConfig().getCheckCount());
return entity;
}
public List<Article> signinArticle(Long[] ids, CmsAdmin admin) {
List<Article> dts = new ArrayList<Article>();
Article entity = null;
if (ids != null && ids.length > 0) {
for (Long id : ids) {
entity = signinArticle(id, admin);
if (entity != null) {
dts.add(entity);
}
}
}
return dts;
}
public Article memberSave(Article bean, CmsMember member, UploadRule rule) {
Assert.notNull(bean);
Assert.notNull(member);
Assert.notNull(rule);
Website web = bean.getWebsite();
// 第一個內(nèi)容屬性
ContentCtg ctg = contentCtgMng.getFirstCtg(web.getRootWebId());
bean.setContentCtg(ctg);
// cms配置
bean.setConfig(cmsConfigMng.findById(web.getId()));
initDefValue(bean);
handleDate(bean, 0);
// 文章頁數(shù)
bean.calculatePageCount();
bean.setContentResPath(web.getResUrl());
bean.setAdminInput(null);
bean.setMember(member);
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -