|
|
@@ -1,11 +1,10 @@
|
|
|
package cn.com.yusys.yusp.service.impl;
|
|
|
|
|
|
-import cn.com.yusys.yusp.commons.exception.BizException;
|
|
|
+import cn.com.yusys.yusp.commons.util.date.DateFormatEnum;
|
|
|
import cn.com.yusys.yusp.commons.util.date.DateUtils;
|
|
|
import cn.com.yusys.yusp.config.DataDictionary;
|
|
|
-import cn.com.yusys.yusp.domain.entity.AitagTagInfoEntity;
|
|
|
+import cn.com.yusys.yusp.domain.dto.TagLogDto;
|
|
|
import cn.com.yusys.yusp.domain.vo.*;
|
|
|
-import cn.com.yusys.yusp.mapper.AitagTagDailyAggDao;
|
|
|
import cn.com.yusys.yusp.mapper.AitagTagInfoDao;
|
|
|
import cn.com.yusys.yusp.mapper.AitagTagLogDao;
|
|
|
import cn.com.yusys.yusp.domain.entity.AitagTagLogEntity;
|
|
|
@@ -18,16 +17,20 @@ import com.baomidou.mybatisplus.core.toolkit.StringUtils;
|
|
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
-import org.apache.commons.io.output.UnsynchronizedByteArrayOutputStream;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
import java.math.BigDecimal;
|
|
|
import java.math.RoundingMode;
|
|
|
-import java.net.URL;
|
|
|
-import java.util.Date;
|
|
|
-import java.util.List;
|
|
|
-import java.util.Map;
|
|
|
+import java.time.LocalDate;
|
|
|
+import java.time.LocalDateTime;
|
|
|
+import java.time.YearMonth;
|
|
|
+import java.time.format.DateTimeFormatter;
|
|
|
+import java.time.temporal.ChronoUnit;
|
|
|
+import java.util.*;
|
|
|
+import java.util.stream.Collectors;
|
|
|
+import java.util.stream.IntStream;
|
|
|
+import java.util.stream.Stream;
|
|
|
|
|
|
import static cn.com.yusys.yusp.config.DataDictionary.*;
|
|
|
|
|
|
@@ -45,8 +48,11 @@ public class AitagTagLogServiceImpl extends ServiceImpl<AitagTagLogDao, AitagTag
|
|
|
@Autowired
|
|
|
private AitagTagInfoDao tagInfoDao;
|
|
|
|
|
|
- @Autowired
|
|
|
- private AitagTagDailyAggDao aggDao;
|
|
|
+
|
|
|
+ private static final DateTimeFormatter DAY_FORMATTER = DateTimeFormatter.ofPattern("yyyy-MM-dd");
|
|
|
+
|
|
|
+ private static final DateTimeFormatter DATETIME = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
|
|
|
+ private static final DateTimeFormatter MONTH_FORMATTER = DateTimeFormatter.ofPattern("yyyy-MM");
|
|
|
|
|
|
@Override
|
|
|
public DataOverviewVo dataOverview(SmartTaggingResultVo taggingResult) {
|
|
|
@@ -68,6 +74,7 @@ public class AitagTagLogServiceImpl extends ServiceImpl<AitagTagLogDao, AitagTag
|
|
|
}
|
|
|
queryWrapper.in(AitagTagLogEntity::getState, DataDictionary.RESULT_PUSHED,DataDictionary.MANAGER_CONFIRMED);
|
|
|
queryWrapper.eq(AitagTagLogEntity::getTagScope, PROD_DATA);
|
|
|
+ queryWrapper.eq(AitagTagLogEntity::getIsDelete, NON_DELETE);
|
|
|
Integer totalConfirmedCnt = this.baseMapper.selectCount(queryWrapper);
|
|
|
log.info("查询出符合条件的打标完成数据:{} 条",totalConfirmedCnt);
|
|
|
|
|
|
@@ -93,6 +100,7 @@ public class AitagTagLogServiceImpl extends ServiceImpl<AitagTagLogDao, AitagTag
|
|
|
return dataOverview;
|
|
|
}
|
|
|
|
|
|
+
|
|
|
@Override
|
|
|
public List<IconResVo> taggingTrend(TaggingTrendReqVo taggingTrendReqVo) {
|
|
|
String startTaggingTime = taggingTrendReqVo.getStartTaggingTime();
|
|
|
@@ -100,16 +108,95 @@ public class AitagTagLogServiceImpl extends ServiceImpl<AitagTagLogDao, AitagTag
|
|
|
|
|
|
int daysByTwoDatesDef = DateUtils.getDaysByTwoDatesDef(startTaggingTime, endTaggingTime);
|
|
|
List<IconResVo> taggingTrendResVo = null;
|
|
|
+ List<IconResVo> iconResVos = null;
|
|
|
if(daysByTwoDatesDef>=15){
|
|
|
- taggingTrendResVo = this.baseMapper.selectTagReportByDay(taggingTrendReqVo);
|
|
|
- }else{
|
|
|
taggingTrendResVo = this.baseMapper.selectTagReportByMonth(taggingTrendReqVo);
|
|
|
+ iconResVos = generateMonthlyStats(startTaggingTime, endTaggingTime);
|
|
|
+ }else{
|
|
|
+ taggingTrendResVo = this.baseMapper.selectTagReportByDay(taggingTrendReqVo);
|
|
|
+ iconResVos = generateDailyStats(startTaggingTime, endTaggingTime);
|
|
|
}
|
|
|
- return taggingTrendResVo;
|
|
|
+ return mergeLists(iconResVos,taggingTrendResVo);
|
|
|
}
|
|
|
|
|
|
+
|
|
|
+ public List<IconResVo> mergeLists(List<IconResVo> iconResVos, List<IconResVo> taggingTrendResVo) {
|
|
|
+ // 将taggingTrendResVo转换为Map,key为stat,value为IconResVo对象
|
|
|
+ Map<String, IconResVo> taggingMap = taggingTrendResVo.stream()
|
|
|
+ .collect(Collectors.toMap(
|
|
|
+ IconResVo::getStat,
|
|
|
+ item -> item,
|
|
|
+ (existing, replacement) -> replacement
|
|
|
+ ));
|
|
|
+
|
|
|
+ // 遍历iconResVos,如果stat在taggingMap中存在,则更新val值
|
|
|
+ return iconResVos.stream()
|
|
|
+ .map(iconRes -> {
|
|
|
+ IconResVo taggingRes = taggingMap.get(iconRes.getStat());
|
|
|
+ if (taggingRes != null) {
|
|
|
+ // 创建新对象或修改原对象(根据需要选择)
|
|
|
+ IconResVo merged = new IconResVo();
|
|
|
+ merged.setStat(iconRes.getStat());
|
|
|
+ merged.setVal(taggingRes.getVal());
|
|
|
+ merged.setStatType(iconRes.getStatType());
|
|
|
+ return merged;
|
|
|
+ }
|
|
|
+ return iconRes;
|
|
|
+ })
|
|
|
+ .collect(Collectors.toList());
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ /**
|
|
|
+ * Stream版本 - 按天生成
|
|
|
+ */
|
|
|
+ private List<IconResVo> generateDailyStats(String startDateStr, String endDateStr) {
|
|
|
+ return getDateStream(startDateStr.substring(0, 10), endDateStr.substring(0, 10))
|
|
|
+ .map(date -> new IconResVo(date.format(DAY_FORMATTER), 0,"day"))
|
|
|
+ .collect(Collectors.toList());
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 生成日期流(JDK 11 兼容)
|
|
|
+ */
|
|
|
+ private Stream<LocalDate> getDateStream(String startDateStr, String endDateStr) {
|
|
|
+ LocalDate startDate = LocalDate.parse(startDateStr.trim(), DAY_FORMATTER);
|
|
|
+ LocalDate endDate = LocalDate.parse(endDateStr.trim(), DAY_FORMATTER);
|
|
|
+ long daysBetween = ChronoUnit.DAYS.between(startDate, endDate) + 1;
|
|
|
+ return IntStream.iterate(0, i -> i + 1)
|
|
|
+ .limit(daysBetween)
|
|
|
+ .mapToObj(startDate::plusDays);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * Stream版本 - 按月生成
|
|
|
+ */
|
|
|
+ private List<IconResVo> generateMonthlyStats(String startDateStr, String endDateStr) {
|
|
|
+ LocalDateTime startTime = LocalDateTime.parse(startDateStr.trim(), DATETIME);
|
|
|
+ LocalDateTime endTime = LocalDateTime.parse(endDateStr.trim(), DATETIME);
|
|
|
+
|
|
|
+ List<IconResVo> result = new ArrayList<>();
|
|
|
+
|
|
|
+ // 获取开始和结束的年月
|
|
|
+ YearMonth startMonth = YearMonth.from(startTime);
|
|
|
+ YearMonth endMonth = YearMonth.from(endTime);
|
|
|
+
|
|
|
+ // 遍历每个月
|
|
|
+ for (YearMonth currentMonth = startMonth;
|
|
|
+ !currentMonth.isAfter(endMonth);
|
|
|
+ currentMonth = currentMonth.plusMonths(1)) {
|
|
|
+ String stat = currentMonth.format(MONTH_FORMATTER);
|
|
|
+ result.add(new IconResVo(stat, 0,"mother"));
|
|
|
+ // 如果当前月已经是结束月,则跳出循环
|
|
|
+ if (currentMonth.equals(endMonth)) {
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return result;
|
|
|
+ }
|
|
|
@Override
|
|
|
- public IPage<AitagTagLogEntity> taggingDetails(TaggingTransactionReqVo transactionReqVo) {
|
|
|
+ public IPage<TagLogDto> taggingDetails(TaggingTransactionReqVo transactionReqVo) {
|
|
|
LambdaQueryWrapper<AitagTagLogEntity> queryWrapper = new LambdaQueryWrapper<>();
|
|
|
if (StringUtils.isNotBlank(transactionReqVo.getCategoryId())) {
|
|
|
queryWrapper.apply("result @> '"+transactionReqVo.getCategoryExp()+"'");
|
|
|
@@ -121,52 +208,30 @@ public class AitagTagLogServiceImpl extends ServiceImpl<AitagTagLogDao, AitagTag
|
|
|
queryWrapper.le(AitagTagLogEntity::getInsertTime, transactionReqVo.getEndTaggingTime());
|
|
|
}
|
|
|
if (StringUtils.isNotBlank(transactionReqVo.getLoanApplicationNo())){
|
|
|
- queryWrapper.le(AitagTagLogEntity::getBusinessAttr, transactionReqVo.getLoanApplicationNo());
|
|
|
+ queryWrapper.eq(AitagTagLogEntity::getBusinessAttr, transactionReqVo.getLoanApplicationNo());
|
|
|
}
|
|
|
queryWrapper.eq(AitagTagLogEntity::getTagScope, PROD_DATA);
|
|
|
-
|
|
|
- return this.page(new Page<>(transactionReqVo.getPage() == null?0:transactionReqVo.getPage(),
|
|
|
- transactionReqVo.getSize() == null?10:transactionReqVo.getSize()),queryWrapper);
|
|
|
+ queryWrapper.eq(AitagTagLogEntity::getIsDelete, NON_DELETE);
|
|
|
+ queryWrapper.orderByDesc(AitagTagLogEntity::getInsertTime);
|
|
|
+ Page<AitagTagLogEntity> page = this.page(new Page<>(transactionReqVo.getPage() == null ? 0 : transactionReqVo.getPage(),
|
|
|
+ transactionReqVo.getSize() == null ? 10 : transactionReqVo.getSize()), queryWrapper);
|
|
|
+ List<AitagTagLogEntity> records = page.getRecords();
|
|
|
+ List<TagLogDto> tagLogDtos = JSONArray.parseArray(JSONArray.toJSONString(records), TagLogDto.class);
|
|
|
+ IPage<TagLogDto> iPage = new Page<TagLogDto>(page.getCurrent(),page.getSize(),page.getTotal());
|
|
|
+ iPage.setRecords(tagLogDtos);
|
|
|
+ return iPage;
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- public AitagTagLogEntity show(String id) {
|
|
|
+ public TagLogDto show(String id) {
|
|
|
AitagTagLogEntity aitagTagLog = this.baseMapper.selectById(id);
|
|
|
- if(aitagTagLog !=null){
|
|
|
- String result = "";
|
|
|
- String feedback = aitagTagLog.getFeedback();
|
|
|
- if(FEEDBACK_RESULT_REJECT.equals(feedback)){
|
|
|
- result = aitagTagLog.getFeedbackResult();
|
|
|
- result = this.getTagPath(result);
|
|
|
- aitagTagLog.setFeedbackResult(result);
|
|
|
- }else{
|
|
|
- result = aitagTagLog.getResult();
|
|
|
- result = getTagPath(result);
|
|
|
- aitagTagLog.setResult(result);
|
|
|
- }
|
|
|
- }
|
|
|
- return aitagTagLog;
|
|
|
+ return JSONObject.parseObject(JSONObject.toJSONString(aitagTagLog), TagLogDto.class);
|
|
|
}
|
|
|
|
|
|
- private String getTagPath(String result) {
|
|
|
- if(result == null){
|
|
|
- return "";
|
|
|
- }
|
|
|
- result = result.replace("\\", "");
|
|
|
- List<Map> results = JSONArray.parseArray(result, Map.class);
|
|
|
- for (Map resultMap: results){
|
|
|
- String tagId = resultMap.getOrDefault("id","").toString();
|
|
|
- AitagTagInfoEntity aitagTagInfoEntity = tagInfoDao.selectById(tagId);
|
|
|
- if(aitagTagInfoEntity!=null){
|
|
|
- resultMap.put("tag_path",aitagTagInfoEntity.getTagPath());
|
|
|
- }
|
|
|
- }
|
|
|
- return JSONArray.toJSONString(results);
|
|
|
- }
|
|
|
|
|
|
@Override
|
|
|
public List<IconResVo> tagDistStats(TagDistStatsReqVo resultVo) {
|
|
|
- return aggDao.selectTagDistStats(resultVo);
|
|
|
+ return this.baseMapper.selectTagDistStats(resultVo);
|
|
|
}
|
|
|
|
|
|
|
|
|
@@ -192,6 +257,8 @@ public class AitagTagLogServiceImpl extends ServiceImpl<AitagTagLogDao, AitagTag
|
|
|
}
|
|
|
query.in(AitagTagLogEntity::getState, DataDictionary.RESULT_PUSHED,DataDictionary.MANAGER_CONFIRMED);
|
|
|
query.eq(AitagTagLogEntity::getTagScope, PROD_DATA);
|
|
|
+ query.eq(AitagTagLogEntity::getIsDelete, NON_DELETE);
|
|
|
+ query.orderByDesc(AitagTagLogEntity::getInsertTime);
|
|
|
return this.baseMapper.selectList(query);
|
|
|
}
|
|
|
|