All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.leazxl.cms.service.CmsFrontService Maven / Gradle / Ivy

There is a newer version: 1.0.3
Show newest version
package com.leazxl.cms.service;

import com.leazxl.cms.dao.CmsArticleDao;
import com.leazxl.cms.dao.CmsArticleDataDao;
import com.leazxl.cms.dao.CmsCategoryDao;
import com.leazxl.cms.dao.CmsSiteDao;
import com.leazxl.cms.model.CmsArticle;
import com.leazxl.cms.model.CmsCategory;
import com.leazxl.cms.model.CmsSite;
import com.leazxl.core.dto.DataRet;
import com.leazxl.core.dto.PageRet;
import com.leazxl.core.idservice.IdService;
import com.leazxl.core.util.Assert;
import com.leazxl.core.util.SecurityUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Sort;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.Date;
import java.util.List;

/**
 *
 */
@Service
public class CmsFrontService {
    @Autowired
    private CmsSiteDao cmsSiteDao;

    @Autowired
    private CmsCategoryDao categoryDao;

    @Autowired
    private CmsArticleDao articleDao;
    @Autowired
    private CmsArticleDataDao articleDataDao;

    /**
     * 获取站点信息
     *
     * @param siteId
     * @return
     */
    public CmsSite getSite(String siteId) {
        CmsSite cmsSite = cmsSiteDao.get(siteId);
        List list = categoryDao.queryByParentId(cmsSite.getId(), "1");
        list.forEach(c -> {
            c.setChildren(categoryDao.queryByParentId(cmsSite.getId(), c.getId()));
        });
        cmsSite.setCategories(list);
        return cmsSite;
    }

    /**
     * 获取文章列表的第一条
     *
     * @param categoryId
     * @return
     */
    public CmsArticle getArticle(String categoryId) {
        CmsArticle cmsArticle = new CmsArticle();
        cmsArticle.setCategoryId(categoryId);
        List list = articleDao.queryList(cmsArticle, 1, 1);
        if (list != null && list.size() > 0) {
            cmsArticle = list.get(0);
            cmsArticle.setArticleData(articleDataDao.get(cmsArticle.getId()));
            return cmsArticle;
        }
        return new CmsArticle();
    }

    /**
     * 获取文章列表
     *
     * @param categoryId 栏目ID
     * @return
     */
    public List queryArticleList(String categoryId) {
        CmsArticle cmsArticle = new CmsArticle();
        cmsArticle.setCategoryId(categoryId);
        List cmsArticles = articleDao.queryList(cmsArticle, Sort.by("create_date"));
        return cmsArticles;
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy