-
Notifications
You must be signed in to change notification settings - Fork 5.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
16 changed files
with
310 additions
and
48 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
83 changes: 83 additions & 0 deletions
83
src/main/java/com/thinkgem/jeesite/modules/cms/service/StatsService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
/** | ||
* Copyright © 2012-2013 <a href="https://github.com/thinkgem/jeesite">JeeSite</a> All rights reserved. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
*/ | ||
package com.thinkgem.jeesite.modules.cms.service; | ||
|
||
import java.util.Date; | ||
import java.util.List; | ||
import java.util.Map; | ||
|
||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.stereotype.Service; | ||
import org.springframework.transaction.annotation.Transactional; | ||
import org.springframework.ui.Model; | ||
|
||
import com.google.common.collect.Lists; | ||
import com.thinkgem.jeesite.common.service.BaseService; | ||
import com.thinkgem.jeesite.common.utils.DateUtils; | ||
import com.thinkgem.jeesite.common.utils.StringUtils; | ||
import com.thinkgem.jeesite.modules.cms.dao.ArticleDao; | ||
import com.thinkgem.jeesite.modules.cms.entity.Site; | ||
|
||
/** | ||
* 统计Service | ||
* @author ThinkGem | ||
* @version 2013-05-21 | ||
*/ | ||
@Service | ||
@Transactional(readOnly = true) | ||
public class StatsService extends BaseService { | ||
|
||
@SuppressWarnings("unused") | ||
private static Logger logger = LoggerFactory.getLogger(StatsService.class); | ||
|
||
@Autowired | ||
private ArticleDao articleDao; | ||
|
||
public List<Map<String, Object>> article(Map<String, Object> paramMap, Model model) { | ||
|
||
StringBuilder ql = new StringBuilder(); | ||
List<Object> ps = Lists.newArrayList(); | ||
|
||
ql.append("select new map(max(c.id) as categoryId, max(c.name) as categoryName, max(cp.id) as categoryParentId, max(cp.name) as categoryParentName,"); | ||
ql.append(" count(*) as cnt, sum(a.hits) as hits, max(a.updateDate) as updateDate, max(o.id) as officeId, max(o.name) as officeName) "); | ||
ql.append(" from Article a join a.category c join c.office o join c.parent cp where c.site.id = ").append(Site.getCurrentSiteId()); | ||
|
||
Long categoryId = StringUtils.toLong(paramMap.get("categoryId")); | ||
if (categoryId > 0){ | ||
ql.append(" and (c.id = ? or c.parentIds like ?)"); | ||
ps.add(categoryId); | ||
ps.add("%,"+categoryId+",%"); | ||
} | ||
|
||
Long officeId = StringUtils.toLong(paramMap.get("officeId")); | ||
if (officeId > 0){ | ||
ql.append(" and (o.id = ? or o.parentIds like ?)"); | ||
ps.add(officeId); | ||
ps.add("%,"+officeId+",%"); | ||
} | ||
|
||
Date beginDate = DateUtils.parseDate(paramMap.get("beginDate")); | ||
if (beginDate == null){ | ||
beginDate = DateUtils.setDays(new Date(), 1); | ||
paramMap.put("beginDate", DateUtils.formatDate(beginDate, "yyyy-MM-dd")); | ||
} | ||
Date endDate = DateUtils.parseDate(paramMap.get("endDate")); | ||
if (endDate == null){ | ||
endDate = DateUtils.addDays(DateUtils.addMonths(beginDate, 1), -1); | ||
paramMap.put("endDate", DateUtils.formatDate(endDate, "yyyy-MM-dd")); | ||
} | ||
ql.append(" and a.updateDate between ? and ?"); | ||
ps.add(beginDate); | ||
ps.add(DateUtils.addDays(endDate, 1)); | ||
|
||
ql.append(" group by c.id order by cp.sort, cp.id, c.sort, c.id"); | ||
List<Map<String, Object>> list = articleDao.find(ql.toString(), ps.toArray()); | ||
return list; | ||
} | ||
|
||
} |
49 changes: 49 additions & 0 deletions
49
src/main/java/com/thinkgem/jeesite/modules/cms/web/StatsController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
/** | ||
* Copyright © 2012-2013 <a href="https://github.com/thinkgem/jeesite">JeeSite</a> All rights reserved. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
*/ | ||
package com.thinkgem.jeesite.modules.cms.web; | ||
|
||
import java.util.List; | ||
import java.util.Map; | ||
|
||
import org.apache.shiro.authz.annotation.RequiresPermissions; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.stereotype.Controller; | ||
import org.springframework.ui.Model; | ||
import org.springframework.web.bind.annotation.RequestMapping; | ||
import org.springframework.web.bind.annotation.RequestParam; | ||
|
||
import com.thinkgem.jeesite.common.config.Global; | ||
import com.thinkgem.jeesite.common.web.BaseController; | ||
import com.thinkgem.jeesite.modules.cms.service.StatsService; | ||
|
||
/** | ||
* 统计Controller | ||
* @author ThinkGem | ||
* @version 2013-5-21 | ||
*/ | ||
@Controller | ||
@RequestMapping(value = Global.ADMIN_PATH+"/cms/stats") | ||
public class StatsController extends BaseController { | ||
|
||
@Autowired | ||
private StatsService statsService; | ||
|
||
/** | ||
* 文章信息量 | ||
* @param map | ||
* @param model | ||
* @return | ||
*/ | ||
@RequiresPermissions("cms:stats:article") | ||
@RequestMapping(value = "article") | ||
public String article(@RequestParam Map<String, Object> paramMap, Model model) { | ||
List<Map<String, Object>> list = statsService.article(paramMap, model); | ||
model.addAttribute("list", list); | ||
model.addAttribute("paramMap", paramMap); | ||
return "modules/cms/statsArticle"; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.