diff --git a/epmet-module/data-statistical/data-statistical-client/src/main/java/com/epmet/dto/stats/ArticleGridPublishedSummaryDTO.java b/epmet-module/data-statistical/data-statistical-client/src/main/java/com/epmet/dto/stats/ArticleGridPublishedSummaryDTO.java index 138ae7efec..bcd0beaed9 100644 --- a/epmet-module/data-statistical/data-statistical-client/src/main/java/com/epmet/dto/stats/ArticleGridPublishedSummaryDTO.java +++ b/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; } diff --git a/epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/controller/PublicityController.java b/epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/controller/PublicityController.java deleted file mode 100644 index a8860b0cff..0000000000 --- a/epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/controller/PublicityController.java +++ /dev/null @@ -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 publicitySummaryStatsjob(){ - return null; - } -} diff --git a/epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/controller/StatsPublicityController.java b/epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/controller/StatsPublicityController.java new file mode 100644 index 0000000000..78ee2a3f11 --- /dev/null +++ b/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 publicitySummaryStatsjob(Date statsDate) { + return new Result().ok(statsPublicityService.publicitySummary(statsDate)); + } +} diff --git a/epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/dao/stats/FactArticlePublishedGridDailyDao.java b/epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/dao/stats/FactArticlePublishedGridDailyDao.java index bbbaf288b9..24b8ca6115 100644 --- a/epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/dao/stats/FactArticlePublishedGridDailyDao.java +++ b/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 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); } \ No newline at end of file diff --git a/epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/service/impl/StatsPublicityServiceImpl.java b/epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/service/impl/StatsPublicityServiceImpl.java index b86c1ee772..4e182db209 100644 --- a/epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/service/impl/StatsPublicityServiceImpl.java +++ b/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 customerIdList = null; do { customerIdList = dimCustomerService.selectCustomerIdPage(pageNo++, pageSize); if (!CollectionUtils.isEmpty(customerIdList)) { - for (String customerId : customerIdList) {//获取所有网格 - List gridDTOList = dimGridService.getGridListByCustomerId(customerId); - if (!CollectionUtils.isEmpty(gridDTOList)) { - List 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 statsPublishArticle(String customerId, Date statsDate) { - List articleCount = articlePublishRangeService.getAllPublishedCount(customerId, statsDate); + /** + * desc:按日统计 网格纬度的 文章总数数据 + * + * @param statsDate + * @param dimIdBean + * @param customerId + */ + private void statsPublishedGridDaily(Date statsDate, DimIdGenerator.DimIdBean dimIdBean, String customerId) { + //获取所有网格 + List gridDTOList = dimGridService.getGridListByCustomerId(customerId); + if (CollectionUtils.isEmpty(gridDTOList)) { + log.warn("publicitySummary getGridListByCustomerId return empty,customerId:{}", customerId); + return; + } + //转换为 需要插入的Entity + Map gridDailyEntityMap = convertGridDailyEntity(gridDTOList, dimIdBean); + //获取当天的业务数据 + List 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 convertGridDailyEntity(List dimGridEntities, DimIdGenerator.DimIdBean dimIdBean) { + Map 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; } } diff --git a/epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/service/stats/FactArticlePublishedGridDailyService.java b/epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/service/stats/FactArticlePublishedGridDailyService.java index 3f52f8679e..d19038fa4e 100644 --- a/epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/service/stats/FactArticlePublishedGridDailyService.java +++ b/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 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 values); + + } \ No newline at end of file diff --git a/epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/service/stats/impl/FactArticlePublishedGridDailyServiceImpl.java b/epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/service/stats/impl/FactArticlePublishedGridDailyServiceImpl.java index 3e8fe9bc65..38688c191a 100644 --- a/epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/service/stats/impl/FactArticlePublishedGridDailyServiceImpl.java +++ b/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 values) { + int i = baseDao.deleteByDateId(customerId, dateId); + log.debug("deleteAndInsertBatch delete customerId:{},rows:{}", customerId,i); + this.insertBatch(values, 100); + return true; + } } \ No newline at end of file diff --git a/epmet-module/data-statistical/data-statistical-server/src/main/resources/mapper/stats/FactArticlePublishedGridDailyDao.xml b/epmet-module/data-statistical/data-statistical-server/src/main/resources/mapper/stats/FactArticlePublishedGridDailyDao.xml index 6c66ecec83..b265d0b0c9 100644 --- a/epmet-module/data-statistical/data-statistical-server/src/main/resources/mapper/stats/FactArticlePublishedGridDailyDao.xml +++ b/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} + + DELETE FROM fact_article_published_grid_daily WHERE CUSTOMER_ID = #{customerId,jdbcType=VARCHAR} AND DATE_ID = #{dateId,jdbcType=VARCHAR} + \ No newline at end of file diff --git a/epmet-module/data-statistical/data-statistical-server/src/main/resources/mapper/voice/ArticlePublishRangeDao.xml b/epmet-module/data-statistical/data-statistical-server/src/main/resources/mapper/voice/ArticlePublishRangeDao.xml index db2c1131a0..6330c003b8 100644 --- a/epmet-module/data-statistical/data-statistical-server/src/main/resources/mapper/voice/ArticlePublishRangeDao.xml +++ b/epmet-module/data-statistical/data-statistical-server/src/main/resources/mapper/voice/ArticlePublishRangeDao.xml @@ -24,8 +24,8 @@