com.leazxl.cms.service.CmsArticleService Maven / Gradle / Ivy
package com.leazxl.cms.service;
import com.leazxl.cms.dao.CmsArticleDao;
import com.leazxl.cms.dao.CmsArticleDataDao;
import com.leazxl.cms.dao.CmsLinkDao;
import com.leazxl.cms.model.CmsArticle;
import com.leazxl.cms.model.CmsArticleData;
import com.leazxl.cms.model.CmsLink;
import com.leazxl.core.dto.PageRet;
import com.leazxl.core.exception.BaseException;
import com.leazxl.core.idservice.IdService;
import com.leazxl.core.orm.BaseDao;
import com.leazxl.core.util.SecurityUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.util.Date;
/**
* 文章管理
*/
@Service
public class CmsArticleService {
@Autowired
private CmsArticleDao articleDao;
@Autowired
private CmsArticleDataDao articleDataDao;
@Autowired
private CmsLinkDao linkDao;
@Autowired
private IdService idService;
public PageRet getArticleList(CmsArticle cmsArticle, Pageable pageable) {
return articleDao.queryPage(cmsArticle, pageable);
}
/**
* @param cmsArticle
* @param cmsArticleData
*/
@Transactional(rollbackFor = BaseException.class)
public void saveArcticle(CmsArticle cmsArticle, CmsArticleData cmsArticleData) {
if (cmsArticle.getId() == null || "".equals(cmsArticle.getId())) {
cmsArticle.setId(idService.getId());
cmsArticle.setCreateBy(SecurityUtils.getUserId());
cmsArticle.setCreateDate(new Date());
cmsArticle.setUpdateBy(SecurityUtils.getUserId());
cmsArticle.setUpdateDate(new Date());
cmsArticle.setDelFlag("0");
cmsArticleData.setId(cmsArticle.getId());
if (cmsArticleData.getAllowComment() == null) {
cmsArticleData.setAllowComment(true);
}
articleDao.save(cmsArticle);
articleDataDao.save(cmsArticleData);
} else {
cmsArticle.setUpdateBy(SecurityUtils.getUserId());
cmsArticle.setUpdateDate(new Date());
articleDao.updateTemplateById(cmsArticle);
articleDataDao.updateTemplateById(cmsArticleData);
}
}
/**
* 获取文章信息
*
* @param id
* @return
*/
public CmsArticle getArticle(String id) {
CmsArticle cmsArticle = articleDao.get(id);
cmsArticle.setArticleData(articleDataDao.get(id));
return cmsArticle;
}
/**
* 获取文章信息
*
* @param id
* @return
*/
public void deleteArticle(String id) {
articleDao.deleteById(id);
articleDataDao.deleteById(id);
}
public PageRet getLinkList(CmsLink cmsLink, Pageable pageable) {
return linkDao.queryPage(cmsLink, pageable);
}
public CmsLink getLink(String id) {
return linkDao.get(id);
}
public void saveLink(CmsLink cmsLink) {
if (cmsLink.getId() == null || "".equals(cmsLink.getId())) {
cmsLink.setId(idService.getId());
cmsLink.setCreateBy(SecurityUtils.getUserId());
cmsLink.setCreateDate(new Date());
cmsLink.setUpdateBy(SecurityUtils.getUserId());
cmsLink.setUpdateDate(new Date());
cmsLink.setDelFlag("0");
cmsLink.setId(cmsLink.getId());
linkDao.save(cmsLink);
} else {
cmsLink.setUpdateBy(SecurityUtils.getUserId());
cmsLink.setUpdateDate(new Date());
linkDao.updateTemplateById(cmsLink);
}
}
/**
* 删除链接信息
*
* @param id
*/
public void delteLink(String id) {
linkDao.deleteById(id);
}
}