|
@@ -1,122 +0,0 @@
|
|
|
-package cn.com.yusys.yusp.service;
|
|
|
|
|
-
|
|
|
|
|
-
|
|
|
|
|
-import cn.com.yusys.yusp.commons.util.StringUtils;
|
|
|
|
|
-import cn.com.yusys.yusp.domain.dto.TagResultDto;
|
|
|
|
|
-import cn.com.yusys.yusp.domain.entity.AitagTagDailyAggEntity;
|
|
|
|
|
-import cn.com.yusys.yusp.domain.entity.AitagTagLogEntity;
|
|
|
|
|
-import cn.com.yusys.yusp.mapper.AitagTagDailyAggDao;
|
|
|
|
|
-import cn.com.yusys.yusp.mapper.AitagTagLogDao;
|
|
|
|
|
-import com.alibaba.fastjson.JSONArray;
|
|
|
|
|
-import com.alibaba.fastjson.JSONObject;
|
|
|
|
|
-import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
|
|
-import lombok.extern.slf4j.Slf4j;
|
|
|
|
|
-import org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
|
-import org.springframework.data.redis.core.RedisTemplate;
|
|
|
|
|
-import org.springframework.data.redis.core.StringRedisTemplate;
|
|
|
|
|
-import org.springframework.scheduling.annotation.Scheduled;
|
|
|
|
|
-import org.springframework.stereotype.Component;
|
|
|
|
|
-
|
|
|
|
|
-import java.time.LocalDate;
|
|
|
|
|
-import java.util.HashMap;
|
|
|
|
|
-import java.util.List;
|
|
|
|
|
-import java.util.Map;
|
|
|
|
|
-import java.util.UUID;
|
|
|
|
|
-import java.util.concurrent.TimeUnit;
|
|
|
|
|
-
|
|
|
|
|
-import static cn.com.yusys.yusp.config.DataDictionary.FEEDBACK_RESULT_AGREE;
|
|
|
|
|
-import static cn.com.yusys.yusp.config.DataDictionary.FEEDBACK_RESULT_REJECT;
|
|
|
|
|
-
|
|
|
|
|
-@Component
|
|
|
|
|
-@Slf4j
|
|
|
|
|
-public class DistributedScheduledTask {
|
|
|
|
|
-
|
|
|
|
|
-
|
|
|
|
|
-
|
|
|
|
|
- @Autowired
|
|
|
|
|
- private StringRedisTemplate redisTemplate;
|
|
|
|
|
-
|
|
|
|
|
-
|
|
|
|
|
- @Autowired
|
|
|
|
|
- private AitagTagLogDao aitagTagLogDao;
|
|
|
|
|
-
|
|
|
|
|
- @Autowired
|
|
|
|
|
- private AitagTagDailyAggDao aitagTagDailyAggDao;
|
|
|
|
|
-
|
|
|
|
|
- /**
|
|
|
|
|
- * 每天凌晨统计昨天打标数据
|
|
|
|
|
- */
|
|
|
|
|
- @Scheduled(cron = "#{@environment.getProperty('application.scheduled.task-cron')}")
|
|
|
|
|
- public void syncDataTask() {
|
|
|
|
|
- log.info("智能标签统计,准备获取redis锁");
|
|
|
|
|
- Boolean taskCron = redisTemplate.opsForValue().setIfAbsent("taskCron", "1", 4, TimeUnit.HOURS);
|
|
|
|
|
- if(Boolean.TRUE.equals(taskCron)){
|
|
|
|
|
- try{
|
|
|
|
|
- log.info("获取redis锁成功,智能标签开始统计");
|
|
|
|
|
- LambdaQueryWrapper<AitagTagDailyAggEntity> queryWrapper = new LambdaQueryWrapper<>();
|
|
|
|
|
- String yesterday = LocalDate.now().minusDays(1).toString();
|
|
|
|
|
- queryWrapper.eq(AitagTagDailyAggEntity::getAggDate,yesterday);
|
|
|
|
|
- int count = aitagTagDailyAggDao.selectCount(queryWrapper);
|
|
|
|
|
- if(count == 0){
|
|
|
|
|
- executeBusinessLogic(yesterday);
|
|
|
|
|
- }
|
|
|
|
|
- log.info("智能标签统计任务结束");
|
|
|
|
|
- }finally {
|
|
|
|
|
- log.info("删除redis锁信息");
|
|
|
|
|
- redisTemplate.delete("taskCron");
|
|
|
|
|
- }
|
|
|
|
|
- }else{
|
|
|
|
|
- log.warn("智能标签统计任务已有节点执行--本次执行跳过");
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- private void executeBusinessLogic(String yesterday) {
|
|
|
|
|
- List<AitagTagLogEntity> aitagTagLogEntities = aitagTagLogDao.selectByInsertTime(yesterday);
|
|
|
|
|
- if(aitagTagLogEntities != null){
|
|
|
|
|
- Map<String,Integer> count = new HashMap<>();
|
|
|
|
|
- for (AitagTagLogEntity aitagTagLog:aitagTagLogEntities){
|
|
|
|
|
- String feedback = aitagTagLog.getFeedback();
|
|
|
|
|
- String result = null;
|
|
|
|
|
- if(FEEDBACK_RESULT_REJECT.equals(feedback)){
|
|
|
|
|
- result = aitagTagLog.getFeedbackResult();
|
|
|
|
|
- }else{
|
|
|
|
|
- result = aitagTagLog.getResult();
|
|
|
|
|
- }
|
|
|
|
|
- if(StringUtils.isBlank(result)){
|
|
|
|
|
- continue;
|
|
|
|
|
- }
|
|
|
|
|
- duCount(result, count);
|
|
|
|
|
- }
|
|
|
|
|
- AitagTagDailyAggEntity aitagTagLog = new AitagTagDailyAggEntity();
|
|
|
|
|
- for (String key : count.keySet()){
|
|
|
|
|
- aitagTagLog.setId(StringUtils.getUUID());
|
|
|
|
|
- aitagTagLog.setAggDate(yesterday);
|
|
|
|
|
- aitagTagLog.setTagCount(count.get(key));
|
|
|
|
|
- String[] split = key.split(":");
|
|
|
|
|
- if(split.length==2){
|
|
|
|
|
- aitagTagLog.setCategoryId(split[1]);
|
|
|
|
|
- }
|
|
|
|
|
- aitagTagLog.setTagNm(split[0]);
|
|
|
|
|
- aitagTagDailyAggDao.insert(aitagTagLog);
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- private static void duCount(String result, Map<String, Integer> count) {
|
|
|
|
|
- List<TagResultDto> results = JSONArray.parseArray(result, TagResultDto.class);
|
|
|
|
|
- for (int i = 0 ;i<results.size();i++){
|
|
|
|
|
- TagResultDto resultMap = results.get(i);
|
|
|
|
|
- String labe = resultMap.getTag_name()+":"
|
|
|
|
|
- + resultMap.getCategory_id();
|
|
|
|
|
- if(count.containsKey(labe)){
|
|
|
|
|
- Integer integer = count.get(labe);
|
|
|
|
|
- count.put(labe,integer+1);
|
|
|
|
|
- }else{
|
|
|
|
|
- count.put(labe,1);
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
-
|
|
|
|
|
-}
|
|
|