|
|
@ -18,18 +18,31 @@ |
|
|
|
package com.epmet.service.evaluationindex.extract.impl; |
|
|
|
|
|
|
|
import com.epmet.commons.mybatis.service.impl.BaseServiceImpl; |
|
|
|
import com.epmet.commons.tools.constant.NumConstant; |
|
|
|
import com.epmet.commons.tools.utils.ConvertUtils; |
|
|
|
import com.epmet.commons.tools.utils.DateUtils; |
|
|
|
import com.epmet.constant.DimObjectActionConstant; |
|
|
|
import com.epmet.constant.IndexCalConstant; |
|
|
|
import com.epmet.dao.evaluationindex.extract.FactOriginTopicLogDailyDao; |
|
|
|
import com.epmet.dao.evaluationindex.extract.FactOriginTopicMainDailyDao; |
|
|
|
import com.epmet.dto.org.GridInfoDTO; |
|
|
|
import com.epmet.dto.topic.TopicOriginInfoDTO; |
|
|
|
import com.epmet.entity.evaluationindex.extract.FactOriginTopicLogDailyEntity; |
|
|
|
import com.epmet.entity.evaluationindex.extract.FactOriginTopicMainDailyEntity; |
|
|
|
import com.epmet.service.evaluationindex.extract.FactOriginTopicMainDailyService; |
|
|
|
import com.epmet.service.org.CustomerGridService; |
|
|
|
import com.epmet.service.topic.TopicService; |
|
|
|
import lombok.extern.slf4j.Slf4j; |
|
|
|
import net.bytebuddy.asm.Advice; |
|
|
|
import org.apache.commons.collections4.ListUtils; |
|
|
|
import org.springframework.beans.factory.annotation.Autowired; |
|
|
|
import org.springframework.stereotype.Service; |
|
|
|
import org.springframework.util.CollectionUtils; |
|
|
|
|
|
|
|
import java.util.ArrayList; |
|
|
|
import java.util.HashMap; |
|
|
|
import java.util.List; |
|
|
|
import java.util.Map; |
|
|
|
import java.util.stream.Collectors; |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
@ -43,7 +56,10 @@ import java.util.List; |
|
|
|
public class FactOriginTopicMainDailyServiceImpl extends BaseServiceImpl<FactOriginTopicMainDailyDao, FactOriginTopicMainDailyEntity> implements FactOriginTopicMainDailyService { |
|
|
|
@Autowired |
|
|
|
private TopicService topicService; |
|
|
|
|
|
|
|
@Autowired |
|
|
|
private CustomerGridService customerGridService; |
|
|
|
@Autowired |
|
|
|
private FactOriginTopicLogDailyDao factOriginTopicLogDailyDao; |
|
|
|
|
|
|
|
/** |
|
|
|
* @param customerId 客户id |
|
|
@ -55,28 +71,142 @@ public class FactOriginTopicMainDailyServiceImpl extends BaseServiceImpl<FactOri |
|
|
|
**/ |
|
|
|
@Override |
|
|
|
public Boolean topicCleaning(String customerId, String dateId) { |
|
|
|
//TODO
|
|
|
|
List<TopicOriginInfoDTO> topicOriginInfoList = topicService.queryTopicOriginInfoList(customerId, dateId); |
|
|
|
if (CollectionUtils.isEmpty(topicOriginInfoList)) { |
|
|
|
log.info(String.format("customerId%s,dateId%s,doesn't have any topic operation record",customerId,dateId)); |
|
|
|
return true; |
|
|
|
} |
|
|
|
|
|
|
|
Map<String,GridInfoDTO> gridMap=getGridInfoMap(customerId); |
|
|
|
Map<String, Object> map=this.constructFactOriginData(topicOriginInfoList,gridMap); |
|
|
|
List<FactOriginTopicMainDailyEntity> mainDailyEntityList= (List<FactOriginTopicMainDailyEntity>) map.get("main"); |
|
|
|
List<FactOriginTopicLogDailyEntity> logDailyEntityList= (List<FactOriginTopicLogDailyEntity>) map.get("log"); |
|
|
|
//删除之前统计的数据
|
|
|
|
deleteFactOriginData(customerId,dateId); |
|
|
|
//批量保存主表
|
|
|
|
saveFactOriginTopicMainDailyEntity(mainDailyEntityList); |
|
|
|
//批量保存明细表
|
|
|
|
saveFactOriginTopicLogDailyEntity(logDailyEntityList); |
|
|
|
return true; |
|
|
|
} |
|
|
|
|
|
|
|
private Map<String, GridInfoDTO> getGridInfoMap(String customerId) { |
|
|
|
Map<String ,GridInfoDTO> map=new HashMap<>(); |
|
|
|
List<GridInfoDTO> list=customerGridService.queryGridInfoList(customerId); |
|
|
|
if(!CollectionUtils.isEmpty(list)){ |
|
|
|
return list.stream().collect(Collectors.toMap(GridInfoDTO::getGridId, gridInfoDTO -> gridInfoDTO)); |
|
|
|
} |
|
|
|
return map; |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
* @param customerId 客户id |
|
|
|
* @param dateId yyyyMMdd |
|
|
|
* @return java.lang.Boolean |
|
|
|
* @return void |
|
|
|
* @param mainDailyEntityList |
|
|
|
* @author yinzuomei |
|
|
|
* @description 数据采集:话题的评论 |
|
|
|
* @Date 2020/9/15 17:56 |
|
|
|
* @description 批量插入 fact_origin_topic_main_daily |
|
|
|
* @Date 2020/9/16 11:21 |
|
|
|
**/ |
|
|
|
@Override |
|
|
|
public Boolean topicCommentCleaning(String customerId, String dateId) { |
|
|
|
//TODO
|
|
|
|
return true; |
|
|
|
private void saveFactOriginTopicMainDailyEntity(List<FactOriginTopicMainDailyEntity> mainDailyEntityList) { |
|
|
|
//批量插入
|
|
|
|
List<List<FactOriginTopicMainDailyEntity>> partition = ListUtils.partition(mainDailyEntityList, IndexCalConstant.INSERT_SIZE); |
|
|
|
partition.forEach(list -> { |
|
|
|
baseDao.insertBatchEntity(list); |
|
|
|
}); |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* @return void |
|
|
|
* @param logDailyEntityList |
|
|
|
* @author yinzuomei |
|
|
|
* @description 批量插入fact_origin_topic_log_daily |
|
|
|
* @Date 2020/9/16 12:53 |
|
|
|
**/ |
|
|
|
private void saveFactOriginTopicLogDailyEntity(List<FactOriginTopicLogDailyEntity> logDailyEntityList) { |
|
|
|
//批量插入
|
|
|
|
List<List<FactOriginTopicLogDailyEntity>> partition = ListUtils.partition(logDailyEntityList, IndexCalConstant.INSERT_SIZE); |
|
|
|
partition.forEach(list -> { |
|
|
|
factOriginTopicLogDailyDao.insertBatchEntity(list); |
|
|
|
}); |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* @return java.util.Map<java.lang.String,java.lang.Object> |
|
|
|
* @param topicOriginInfoList |
|
|
|
* @author yinzuomei |
|
|
|
* @description 构造好要插入的数据 |
|
|
|
* @Date 2020/9/16 11:21 |
|
|
|
**/ |
|
|
|
private Map<String, Object> constructFactOriginData(List<TopicOriginInfoDTO> topicOriginInfoList,Map<String,GridInfoDTO> gridMap) { |
|
|
|
Map<String, Object> map=new HashMap<>(); |
|
|
|
List<FactOriginTopicMainDailyEntity> mainDailyEntityList=new ArrayList<>(); |
|
|
|
List<FactOriginTopicLogDailyEntity> logDailyEntityList=new ArrayList<>(); |
|
|
|
for(TopicOriginInfoDTO topicOriginInfoDTO:topicOriginInfoList){ |
|
|
|
GridInfoDTO gridInfoDTO=gridMap.get(topicOriginInfoDTO.getGridId()); |
|
|
|
if(null==gridInfoDTO){ |
|
|
|
log.error("没有找到 gridId="+topicOriginInfoDTO.getGridId()+" 的基本信息"); |
|
|
|
continue; |
|
|
|
} |
|
|
|
// 一年的第几周
|
|
|
|
String weekId = DateUtils.format(topicOriginInfoDTO.getOriginalBusinessTime(), DateUtils.DATE_PATTERN_YYYY).concat("W").concat(String.valueOf(DateUtils.getWeekOfYear(topicOriginInfoDTO.getOriginalBusinessTime()))); |
|
|
|
String quarterId=DateUtils.getQuarterId(topicOriginInfoDTO.getMonthId()); |
|
|
|
if(DimObjectActionConstant.TOPIC_PUBLISH.equals(topicOriginInfoDTO.getActionCode())){ |
|
|
|
//如果是新发布的话题需要插入主表
|
|
|
|
FactOriginTopicMainDailyEntity mainDailyEntity=ConvertUtils.sourceToTarget(topicOriginInfoDTO, FactOriginTopicMainDailyEntity.class); |
|
|
|
mainDailyEntity.setId(topicOriginInfoDTO.getTopicId()); |
|
|
|
mainDailyEntity.setWeekId(weekId); |
|
|
|
mainDailyEntity.setQuarterId(quarterId); |
|
|
|
mainDailyEntity.setCreateTopicUserId(topicOriginInfoDTO.getOperateUserId()); |
|
|
|
//网格所属的组织id
|
|
|
|
mainDailyEntity.setAgencyId(gridInfoDTO.getAgencyId()); |
|
|
|
//网格的上上级组织id=街道id
|
|
|
|
mainDailyEntity.setPid(gridInfoDTO.getPid()); |
|
|
|
//TODO
|
|
|
|
//话题发布人是否是党员:1是党员0不是。 默认0
|
|
|
|
mainDailyEntity.setCreateTopicUserIsParty(false); |
|
|
|
|
|
|
|
mainDailyEntityList.add(mainDailyEntity); |
|
|
|
} |
|
|
|
FactOriginTopicLogDailyEntity logDailyEntity= ConvertUtils.sourceToTarget(topicOriginInfoDTO, FactOriginTopicLogDailyEntity.class); |
|
|
|
logDailyEntity.setCustomerId(topicOriginInfoDTO.getCustomerId()); |
|
|
|
logDailyEntity.setGridId(topicOriginInfoDTO.getGridId()); |
|
|
|
logDailyEntity.setWeekId(weekId); |
|
|
|
logDailyEntity.setQuarterId(quarterId); |
|
|
|
logDailyEntity.setAgencyId(gridInfoDTO.getAgencyId()); |
|
|
|
logDailyEntity.setPid(gridInfoDTO.getPid()); |
|
|
|
//TODO
|
|
|
|
logDailyEntity.setOperateUserIsParty(false); |
|
|
|
logDailyEntityList.add(logDailyEntity); |
|
|
|
} |
|
|
|
map.put("main",mainDailyEntityList); |
|
|
|
map.put("log",logDailyEntityList); |
|
|
|
return map; |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* @return void |
|
|
|
* @param customerId |
|
|
|
* @param dateId |
|
|
|
* @author yinzuomei |
|
|
|
* @description 删除之前统计过的数据 |
|
|
|
* @Date 2020/9/16 11:21 |
|
|
|
**/ |
|
|
|
private void deleteFactOriginData(String customerId, String dateId) { |
|
|
|
int mainDeleteNum; |
|
|
|
do { |
|
|
|
//一次删除50条
|
|
|
|
mainDeleteNum = baseDao.deleteByDateIdAndCustomerId(customerId, |
|
|
|
dateId, |
|
|
|
IndexCalConstant.DELETE_SIZE); |
|
|
|
} while (mainDeleteNum > NumConstant.ZERO); |
|
|
|
int logDeleteNum; |
|
|
|
do { |
|
|
|
//一次删除50条
|
|
|
|
logDeleteNum = factOriginTopicLogDailyDao.deleteByDateIdAndCustomerId(customerId, |
|
|
|
dateId, |
|
|
|
IndexCalConstant.DELETE_SIZE); |
|
|
|
} while (logDeleteNum > NumConstant.ZERO); |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} |