Browse Source

按日统计文章总数

dev_shibei_match
jianjun 5 years ago
parent
commit
2aa5532b36
  1. 4
      epmet-module/data-statistical/data-statistical-client/src/main/java/com/epmet/dto/stats/ArticleGridPublishedSummaryDTO.java
  2. 29
      epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/controller/PublicityController.java
  3. 36
      epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/controller/StatsPublicityController.java
  4. 9
      epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/dao/stats/FactArticlePublishedGridDailyDao.java
  5. 79
      epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/service/impl/StatsPublicityServiceImpl.java
  6. 15
      epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/service/stats/FactArticlePublishedGridDailyService.java
  7. 11
      epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/service/stats/impl/FactArticlePublishedGridDailyServiceImpl.java
  8. 5
      epmet-module/data-statistical/data-statistical-server/src/main/resources/mapper/stats/FactArticlePublishedGridDailyDao.xml
  9. 4
      epmet-module/data-statistical/data-statistical-server/src/main/resources/mapper/voice/ArticlePublishRangeDao.xml

4
epmet-module/data-statistical/data-statistical-client/src/main/java/com/epmet/dto/stats/ArticleGridPublishedSummaryDTO.java

@ -30,9 +30,9 @@ public class ArticleGridPublishedSummaryDTO implements Serializable {
/**
* 发布文章总数
*/
private Integer publishedCount;
private Integer articleTotalCount;
/**
* 状态为发布中的文章总数
*/
private Integer publishingCount;
private Integer articlePublishedCount;
}

29
epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/controller/PublicityController.java

@ -1,29 +0,0 @@
package com.epmet.controller;
import com.epmet.commons.tools.utils.Result;
import com.epmet.service.StatsDemoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import java.util.concurrent.ExecutorService;
/**
* desc:宣传能力controller
*/
@RequestMapping("publicity")
@RestController
public class PublicityController {
@Autowired
private StatsDemoService demoService;
@Autowired
private ExecutorService executorService;
@PostMapping(value = "publicitySummaryStatsjob")
public Result<Boolean> publicitySummaryStatsjob(){
return null;
}
}

36
epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/controller/StatsPublicityController.java

@ -0,0 +1,36 @@
package com.epmet.controller;
import com.epmet.commons.tools.utils.Result;
import com.epmet.service.StatsPublicityService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import java.util.Date;
import java.util.concurrent.ExecutorService;
/**
* desc:宣传能力controller
*/
@RequestMapping("statspublicity")
@RestController
public class StatsPublicityController {
@Autowired
private StatsPublicityService statsPublicityService;
@Autowired
private ExecutorService executorService;
/**
* desc:统计文章总数及在线文章总数
*
* @param statsDate 默认为T-1天如果传 则统计的是statsDate的数据
* @return
*/
@PostMapping(value = "publicitySummaryStatsjob")
public Result<Boolean> publicitySummaryStatsjob(Date statsDate) {
return new Result<Boolean>().ok(statsPublicityService.publicitySummary(statsDate));
}
}

9
epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/dao/stats/FactArticlePublishedGridDailyDao.java

@ -42,4 +42,13 @@ public interface FactArticlePublishedGridDailyDao extends BaseDao<FactArticlePub
* @return
*/
List<FactArticlePublishedAgencyDailyEntity> getByBeforeDay(@Param("customerId") String customerId, @Param("dateId") String dateId);
/**
* desc:根据日期删除 数据
*
* @param customerId
* @param dateId
* @return
*/
int deleteByDateId(@Param("customerId") String customerId, @Param("dateId") String dateId);
}

79
epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/service/impl/StatsPublicityServiceImpl.java

@ -1,25 +1,32 @@
package com.epmet.service.impl;
import com.epmet.commons.tools.utils.ConvertUtils;
import com.epmet.commons.tools.utils.DateUtils;
import com.epmet.dto.stats.ArticleGridPublishedSummaryDTO;
import com.epmet.entity.stats.DimGridEntity;
import com.epmet.entity.stats.FactArticlePublishedGridDailyEntity;
import com.epmet.service.StatsPublicityService;
import com.epmet.service.stats.*;
import com.epmet.service.voice.ArticlePublishRangeService;
import com.epmet.util.DimIdGenerator;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ExecutorService;
/**
* desc: 宣传能力数据统计 service
*
* @date: 2020/6/17 16:08
* @author: jianjun liu
* email:liujianjun@git.elinkit.com.cn
*/
@Slf4j
@Service
public class StatsPublicityServiceImpl implements StatsPublicityService {
@ -45,33 +52,83 @@ public class StatsPublicityServiceImpl implements StatsPublicityService {
@Autowired
private FactArticlePublishedGridDailyService factArticlePublishedGridDailyService;
@Autowired
private ExecutorService executorService;
@Override
public Boolean publicitySummary(Date statsDate) {
if (statsDate == null) {
statsDate = DateUtils.addDateDays(new Date(), -1);
}
DimIdGenerator.DimIdBean dimIdBean = DimIdGenerator.getDimIdBean(statsDate);
int pageNo = 1;
int pageSize = 100;
List<String> customerIdList = null;
do {
customerIdList = dimCustomerService.selectCustomerIdPage(pageNo++, pageSize);
if (!CollectionUtils.isEmpty(customerIdList)) {
for (String customerId : customerIdList) {//获取所有网格
List<DimGridEntity> gridDTOList = dimGridService.getGridListByCustomerId(customerId);
if (!CollectionUtils.isEmpty(gridDTOList)) {
List<ArticleGridPublishedSummaryDTO> publishedArticleCount = articlePublishRangeService.getAllPublishedCount(customerId, statsDate);
}
for (String customerId : customerIdList) {
/*executorService.submit(()->{
});*/
statsPublishedGridDaily(statsDate, dimIdBean, customerId);
}
}
} while (!CollectionUtils.isEmpty(customerIdList) || customerIdList.size() >= pageSize);
return null;
} while (!CollectionUtils.isEmpty(customerIdList) && customerIdList.size() >= pageSize);
return true;
}
private List<ArticleGridPublishedSummaryDTO> statsPublishArticle(String customerId, Date statsDate) {
List<ArticleGridPublishedSummaryDTO> articleCount = articlePublishRangeService.getAllPublishedCount(customerId, statsDate);
/**
* desc:按日统计 网格纬度的 文章总数数据
*
* @param statsDate
* @param dimIdBean
* @param customerId
*/
private void statsPublishedGridDaily(Date statsDate, DimIdGenerator.DimIdBean dimIdBean, String customerId) {
//获取所有网格
List<DimGridEntity> gridDTOList = dimGridService.getGridListByCustomerId(customerId);
if (CollectionUtils.isEmpty(gridDTOList)) {
log.warn("publicitySummary getGridListByCustomerId return empty,customerId:{}", customerId);
return;
}
//转换为 需要插入的Entity
Map<String, FactArticlePublishedGridDailyEntity> gridDailyEntityMap = convertGridDailyEntity(gridDTOList, dimIdBean);
//获取当天的业务数据
List<ArticleGridPublishedSummaryDTO> publishedArticleCount = articlePublishRangeService.getAllPublishedCount(customerId, statsDate);
if (!CollectionUtils.isEmpty(publishedArticleCount)) {
for (ArticleGridPublishedSummaryDTO summaryDTO : publishedArticleCount) {
FactArticlePublishedGridDailyEntity gridDailyEntities = gridDailyEntityMap.get(summaryDTO.getGridId());
if (gridDailyEntities == null) {
log.error("publicitySummary bizData gridId:{} not exist in dimGrid", summaryDTO.getGridId());
continue;
}
gridDailyEntities.setArticleTotalCount(summaryDTO.getArticleTotalCount());
gridDailyEntities.setArticlePublishedCount(summaryDTO.getArticlePublishedCount());
}
}
boolean b = factArticlePublishedGridDailyService.deleteAndInsertBatch(customerId, dimIdBean.getDateId(), gridDailyEntityMap.values());
}
return articleCount;
/**
* desc:将网格对象构建为 gridDaily 对象
*
* @param dimGridEntities
* @param dimIdBean
* @return
*/
private Map<String, FactArticlePublishedGridDailyEntity> convertGridDailyEntity(List<DimGridEntity> dimGridEntities, DimIdGenerator.DimIdBean dimIdBean) {
Map<String, FactArticlePublishedGridDailyEntity> result = new HashMap<>();
dimGridEntities.forEach(dimGridEntity -> {
FactArticlePublishedGridDailyEntity entity = ConvertUtils.sourceToTarget(dimIdBean, FactArticlePublishedGridDailyEntity.class);
entity.setCustomerId(dimGridEntity.getCustomerId());
entity.setAgencyId(dimGridEntity.getAgencyId());
entity.setGridId(dimGridEntity.getId());
entity.setArticleTotalCount(0);
entity.setArticlePublishedCount(0);
result.put(dimGridEntity.getId(), entity);
});
return result;
}
}

15
epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/service/stats/FactArticlePublishedGridDailyService.java

@ -21,6 +21,7 @@ import com.epmet.commons.mybatis.service.BaseService;
import com.epmet.entity.stats.FactArticlePublishedAgencyDailyEntity;
import com.epmet.entity.stats.FactArticlePublishedGridDailyEntity;
import java.util.Collection;
import java.util.List;
/**
@ -40,5 +41,19 @@ public interface FactArticlePublishedGridDailyService extends BaseService<FactAr
* @date: 2020/6/18 9:53
* @author: jianjun liu
*/
@Deprecated
List<FactArticlePublishedAgencyDailyEntity> getByBeforeDay(String customerId, String dateId);
/**
* desc: 删除并插入数据
*
* @param dateId
* @param values
* @return:
* @date: 2020/6/18 14:54
* @author: jianjun liu
*/
boolean deleteAndInsertBatch(String customerId, String dateId, Collection<FactArticlePublishedGridDailyEntity> values);
}

11
epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/service/stats/impl/FactArticlePublishedGridDailyServiceImpl.java

@ -27,7 +27,9 @@ import com.epmet.service.stats.FactArticlePublishedGridDailyService;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.util.Collection;
import java.util.List;
/**
@ -49,4 +51,13 @@ public class FactArticlePublishedGridDailyServiceImpl extends BaseServiceImpl<Fa
}
return baseDao.getByBeforeDay(customerId,dateId);
}
@Override
@Transactional(rollbackFor = Exception.class)
public boolean deleteAndInsertBatch(String customerId,String dateId, Collection<FactArticlePublishedGridDailyEntity> values) {
int i = baseDao.deleteByDateId(customerId, dateId);
log.debug("deleteAndInsertBatch delete customerId:{},rows:{}", customerId,i);
this.insertBatch(values, 100);
return true;
}
}

5
epmet-module/data-statistical/data-statistical-server/src/main/resources/mapper/stats/FactArticlePublishedGridDailyDao.xml

@ -35,8 +35,11 @@
WHERE
DEL_FLAG = 0
AND CUSTOMER_ID = #{customerId,jdbcType=VARCHAR}
AND DATE_ID = #{dateId,jdbcType=TIMESTAMP}
AND DATE_ID = #{dateId,jdbcType=VARCHAR}
</select>
<delete id="deleteByDateId">
DELETE FROM fact_article_published_grid_daily WHERE CUSTOMER_ID = #{customerId,jdbcType=VARCHAR} AND DATE_ID = #{dateId,jdbcType=VARCHAR}
</delete>
</mapper>

4
epmet-module/data-statistical/data-statistical-server/src/main/resources/mapper/voice/ArticlePublishRangeDao.xml

@ -24,8 +24,8 @@
<select id="getAllPublishedCount" resultType="com.epmet.dto.stats.ArticleGridPublishedSummaryDTO">
SELECT
GRID_ID,
count(ID) publishedCount,
sum( CASE PUBLISH_STATUS WHEN 'published' THEN 1 ELSE 0 END ) publishingCount
count(ID) articleTotalCount,
sum( CASE PUBLISH_STATUS WHEN 'published' THEN 1 ELSE 0 END ) articlePublishedCount
FROM
article_publish_range
WHERE

Loading…
Cancel
Save