com.ajaxjs.website.service.ArticleService Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of ajaxjs-framework2 Show documentation
Show all versions of ajaxjs-framework2 Show documentation
AJAXJS aims to full-stack, not only the server-side framework,
but also integrates the front-end library. It's written in HTML5 + Java, a successor to the JVM platform, efficient, secure, stable, cross-platform and many other advantages, but it abandoned the traditional enterprise architecture brought about by the large and bloated,
emphasizing the lightweight, and fast, very suitable for the Internet fast application.
The newest version!
package com.ajaxjs.website.service;
import java.util.List;
import java.util.Map;
import java.util.function.Function;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import com.ajaxjs.config.GetConfig;
import com.ajaxjs.framework.BaseService;
import com.ajaxjs.framework.CommonConstant;
import com.ajaxjs.sql.annotation.Select;
import com.ajaxjs.sql.annotation.TableName;
import com.ajaxjs.sql.orm.IBaseDao;
import com.ajaxjs.sql.orm.PageResult;
import com.ajaxjs.sql.orm.Repository;
import com.ajaxjs.website.model.Article;
import com.ajaxjs.website.section.TreeLikeService;
@Component
public class ArticleService extends BaseService {
@TableName(value = "cms_article", beanClass = Map.class)
public interface ArticleDao extends IBaseDao {
@Select("SELECT e.id, e.name, e.createDate, e.updateDate, e.catalogId, e.intro, e.cover, e.stat FROM ${tableName} e " + WHERE_REMARK_ORDER)
public PageResult list(int start, int limit, Function sqlHandler);
@Select("SELECT e.id, e.name, e.createDate, e.cover, e.intro FROM ${tableName} e " + WHERE_REMARK_ORDER)
public List simpleList(Function sqlHandler);
@Select("SELECT YEAR(`createDate`) year , MONTH(`createDate`) month FROM ${tableName} e "
+ "WHERE (e.catalogId IN ( SELECT id FROM common_catalog WHERE `path` LIKE ( CONCAT (( SELECT `path` FROM common_catalog WHERE id = ? ) , '%')))) "
+ "GROUP BY YEAR(`createDate`), MONTH(`createDate`) ORDER BY YEAR(`createDate`) DESC, MONTH(`createDate`) DESC LIMIT 0, ?")
public List groupByMonth(int catalogId, int maxMonth);
}
public static ArticleDao DAO = new Repository().bind(ArticleDao.class);
{
setUiName("文章");
setShortName("article");
setDao(DAO);
}
public PageResult list(int catalogId, int start, int limit, int status) {
return list(catalogId, start, limit, status, false);
}
public PageResult list(int catalogId, int start, int limit, int status, boolean isOrderByCreateDate) {
Function handler = TreeLikeService.setCatalog(catalogId, getDomainCatalogId()).andThen(setStatus(status)).andThen(BaseService::searchQuery)
.andThen(BaseService::betweenCreateDate);
if (isOrderByCreateDate)
handler = handler.andThen(sql -> sql.replace("ORDER BY id", "ORDER BY createDate"));
return DAO.list(start, limit, handler);
}
@Autowired
private GetConfig cfg;
public int getDomainCatalogId() {
return cfg.getInt("data.articleCatalog_Id");
}
public List findListTop(int top) {
return DAO.simpleList(TreeLikeService.setCatalog(getDomainCatalogId(), getDomainCatalogId())
.andThen(BaseService.setStatus(CommonConstant.ON_LINE).andThen(sql -> sql + " LIMIT 0, " + top)));
}
/**
* 获取最近 x 个月的月份
*
* @param maxMonth 最近 x 个月
* @return
*/
public List groupByMonth(int maxMonth) {
List list = DAO.groupByMonth(getDomainCatalogId(), maxMonth);
// for (Article map : list) {
// int year = (int) map.get("year"), month = (int) map.get("month");
//
// map.put("startDate", year + "-" + month + "-1"); // 某个月份的第一天
//
// Calendar calendar = Calendar.getInstance();
// calendar.set(year, month, 1); // 这里先设置要获取月份的下月的第一天
// calendar.add(Calendar.DATE, -1);// 这里将日期值减去一天,从而获取到要求的月份最后一天
//
// String end = CommonUtil.simpleDateFormatFactory(CommonUtil.DATE_FORMAT_SHORTER).format(calendar.getTime());
// map.put("endDate", end);
// }
return list;
}
}