|
|
@@ -0,0 +1,196 @@
|
|
|
+package cn.com.yusys.yusp.service.impl;
|
|
|
+
|
|
|
+import cn.com.yusys.yusp.commons.exception.BizException;
|
|
|
+import cn.com.yusys.yusp.config.DataDictionary;
|
|
|
+import cn.com.yusys.yusp.domain.dto.TagSumDto;
|
|
|
+import cn.com.yusys.yusp.domain.entity.AitagTagInfoEntity;
|
|
|
+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;
|
|
|
+import cn.com.yusys.yusp.service.AitagTagLogService;
|
|
|
+import com.alibaba.fastjson.JSONArray;
|
|
|
+import com.alibaba.fastjson.JSONObject;
|
|
|
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
+import com.baomidou.mybatisplus.core.metadata.IPage;
|
|
|
+import com.baomidou.mybatisplus.core.toolkit.StringUtils;
|
|
|
+import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
|
+import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.stereotype.Service;
|
|
|
+
|
|
|
+import java.math.BigDecimal;
|
|
|
+import java.math.RoundingMode;
|
|
|
+import java.util.List;
|
|
|
+import java.util.Map;
|
|
|
+
|
|
|
+import static cn.com.yusys.yusp.config.DataDictionary.*;
|
|
|
+
|
|
|
+/**
|
|
|
+ *
|
|
|
+ *
|
|
|
+ * @author 2507040827
|
|
|
+ * @date 2026-02-25 14:56:45
|
|
|
+ */
|
|
|
+
|
|
|
+@Service("aitagTagLogService")
|
|
|
+public class AitagTagLogServiceImpl extends ServiceImpl<AitagTagLogDao, AitagTagLogEntity> implements AitagTagLogService {
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private AitagTagInfoDao tagInfoDao;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private AitagTagDailyAggDao aggDao;
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public DataOverviewVo dataOverview(SmartTaggingResultVo taggingResult) {
|
|
|
+ DataOverviewVo dataOverview = new DataOverviewVo();
|
|
|
+ TagSumDto tagSumVo = this.baseMapper.selectTagCount(taggingResult);
|
|
|
+ dataOverview.setCountNum(tagSumVo.getTotalCount());
|
|
|
+ if(tagSumVo.getTotalDuration() !=0){
|
|
|
+ BigDecimal result = new BigDecimal(tagSumVo.getTotalDuration())
|
|
|
+ .divide(new BigDecimal(tagSumVo.getTotalCount()), 10, RoundingMode.HALF_UP);
|
|
|
+ dataOverview.setAvgProcessingDuration(result.toString());
|
|
|
+ }else{
|
|
|
+ dataOverview.setAvgProcessingDuration("0");
|
|
|
+ }
|
|
|
+
|
|
|
+ LambdaQueryWrapper<AitagTagLogEntity> queryCount = new LambdaQueryWrapper<>();
|
|
|
+ LambdaQueryWrapper<AitagTagLogEntity> queryAccurateMarks = new LambdaQueryWrapper<>();
|
|
|
+ if (StringUtils.isNotBlank(taggingResult.getCategoryCode())) {
|
|
|
+ queryCount.eq(AitagTagLogEntity::getCategoryCode, taggingResult.getCategoryCode());
|
|
|
+ queryAccurateMarks.eq(AitagTagLogEntity::getCategoryCode, taggingResult.getCategoryCode());
|
|
|
+ }
|
|
|
+ if (StringUtils.isNotBlank(taggingResult.getStartTaggingTime())){
|
|
|
+ queryCount.ge(AitagTagLogEntity::getInsertTime, taggingResult.getStartTaggingTime());
|
|
|
+ queryAccurateMarks.ge(AitagTagLogEntity::getInsertTime, taggingResult.getStartTaggingTime());
|
|
|
+ }
|
|
|
+ if (StringUtils.isNotBlank(taggingResult.getEndTaggingTime())){
|
|
|
+ queryCount.le(AitagTagLogEntity::getInsertTime, taggingResult.getEndTaggingTime());
|
|
|
+ queryAccurateMarks.le(AitagTagLogEntity::getInsertTime, taggingResult.getEndTaggingTime());
|
|
|
+ }
|
|
|
+ queryCount.in(AitagTagLogEntity::getState, DataDictionary.RESULT_PUSHED,DataDictionary.MANAGER_CONFIRMED);
|
|
|
+ queryAccurateMarks.in(AitagTagLogEntity::getState, DataDictionary.RESULT_PUSHED,DataDictionary.MANAGER_CONFIRMED);
|
|
|
+
|
|
|
+ Integer countNum = this.baseMapper.selectCount(queryCount);
|
|
|
+
|
|
|
+ queryAccurateMarks.eq(AitagTagLogEntity::getFeedback,FEEDBACK_RESULT_AGREE);
|
|
|
+ Integer accurateMarksNum = this.baseMapper.selectCount(queryAccurateMarks);
|
|
|
+ BigDecimal accurateRate = calculateAccuracy(accurateMarksNum, countNum);
|
|
|
+
|
|
|
+ dataOverview.setAccurateNum(countNum);
|
|
|
+ dataOverview.setAccurateRate(accurateRate+"%");
|
|
|
+ if(countNum == 0){
|
|
|
+ dataOverview.setManualAdjustRate("0%");
|
|
|
+ }else{
|
|
|
+ dataOverview.setManualAdjustRate(BigDecimal.valueOf(100).subtract(accurateRate)
|
|
|
+ .setScale(2, RoundingMode.HALF_UP)+"%");
|
|
|
+ }
|
|
|
+ dataOverview.setManualAdjustCount(countNum-accurateMarksNum);
|
|
|
+
|
|
|
+ return dataOverview;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public List<IconResVo> taggingTrend(TaggingTrendReqVo taggingTrendReqVo) {
|
|
|
+ String statisticalPeriod = taggingTrendReqVo.getStatisticalPeriod();
|
|
|
+ List<IconResVo> taggingTrendResVo = null;
|
|
|
+ switch (statisticalPeriod){
|
|
|
+ case DAY:
|
|
|
+ taggingTrendResVo = this.baseMapper.selectTagReportByDay(taggingTrendReqVo);
|
|
|
+ break;
|
|
|
+ case MONTH:
|
|
|
+ taggingTrendResVo = this.baseMapper.selectTagReportByMonth(taggingTrendReqVo);
|
|
|
+ break;
|
|
|
+ default:
|
|
|
+ throw BizException.of("NO_DATA_PERIOD");
|
|
|
+ }
|
|
|
+ return taggingTrendResVo;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public IPage<AitagTagLogEntity> taggingDetails(TaggingTransactionReqVo aitagTagLogEntity) {
|
|
|
+ LambdaQueryWrapper<AitagTagLogEntity> queryCount = new LambdaQueryWrapper<>();
|
|
|
+ if (StringUtils.isNotBlank(aitagTagLogEntity.getCategoryCode())) {
|
|
|
+ queryCount.eq(AitagTagLogEntity::getCategoryCode, aitagTagLogEntity.getCategoryCode());
|
|
|
+ }
|
|
|
+ if (StringUtils.isNotBlank(aitagTagLogEntity.getStartTaggingTime())){
|
|
|
+ queryCount.ge(AitagTagLogEntity::getInsertTime, aitagTagLogEntity.getStartTaggingTime());
|
|
|
+ }
|
|
|
+ if (StringUtils.isNotBlank(aitagTagLogEntity.getEndTaggingTime())){
|
|
|
+ queryCount.le(AitagTagLogEntity::getInsertTime, aitagTagLogEntity.getEndTaggingTime());
|
|
|
+ }
|
|
|
+ if (StringUtils.isNotBlank(aitagTagLogEntity.getLoanApplicationNo())){
|
|
|
+ queryCount.le(AitagTagLogEntity::getBusinessAttr, aitagTagLogEntity.getLoanApplicationNo());
|
|
|
+ }
|
|
|
+ return this.baseMapper.selectPage(new Page<>(aitagTagLogEntity.getPage(),
|
|
|
+ aitagTagLogEntity.getSize()),queryCount);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public AitagTagLogEntity 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;
|
|
|
+ }
|
|
|
+
|
|
|
+ private String getTagPath(String result) {
|
|
|
+ List<Map> results = JSONArray.parseArray(result, Map.class);
|
|
|
+ for (Map resultMap: results){
|
|
|
+ String tagCode = resultMap.getOrDefault("tag_code","").toString();
|
|
|
+ LambdaQueryWrapper<AitagTagInfoEntity> queryCount = new LambdaQueryWrapper<>();
|
|
|
+ queryCount.eq(AitagTagInfoEntity::getTagCode,tagCode);
|
|
|
+ List<AitagTagInfoEntity> aitagTagInfoEntities = tagInfoDao.selectList(queryCount);
|
|
|
+ if(!aitagTagInfoEntities.isEmpty()){
|
|
|
+ AitagTagInfoEntity aitagTagInfoEntity = aitagTagInfoEntities.get(0);
|
|
|
+ resultMap.put("tag_path",aitagTagInfoEntity.getTagPath());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return JSONArray.toJSONString(results);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public List<IconResVo> tagDistStats(TagDistStatsReqVo resultVo) {
|
|
|
+ return aggDao.selectTagDistStats(resultVo);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 计算准确率
|
|
|
+ * @param correctCount 正确数
|
|
|
+ * @param totalCount 总数
|
|
|
+ * @return 准确率(百分比形式,保留两位小数)
|
|
|
+ * @throws IllegalArgumentException 当总数为0时抛出异常
|
|
|
+ */
|
|
|
+ public static BigDecimal calculateAccuracy(int correctCount, int totalCount) {
|
|
|
+ if (totalCount == 0) {
|
|
|
+ return new BigDecimal(0);
|
|
|
+ }
|
|
|
+
|
|
|
+ // 将整数转换为BigDecimal
|
|
|
+ BigDecimal correct = BigDecimal.valueOf(correctCount);
|
|
|
+ BigDecimal total = BigDecimal.valueOf(totalCount);
|
|
|
+
|
|
|
+ // 计算准确率:(正确数 / 总数) * 100,保留两位小数,四舍五入
|
|
|
+ BigDecimal accuracy = correct.divide(total, 4, RoundingMode.HALF_UP)
|
|
|
+ .multiply(BigDecimal.valueOf(100))
|
|
|
+ .setScale(2, RoundingMode.HALF_UP);
|
|
|
+
|
|
|
+ return accuracy;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+}
|