liusheng
2024-07-03 3fc51e7cbdabb7dcd1615c6efac52323f6ca8adb
smartor/src/main/java/com/smartor/service/impl/IvrLibaTargetServiceImpl.java
@@ -1,7 +1,13 @@
package com.smartor.service.impl;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.google.gson.Gson;
import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.common.utils.DtoConversionUtils;
import com.ruoyi.common.utils.StringUtils;
import com.smartor.domain.*;
import com.smartor.mapper.IvrLibaTargetMapper;
import com.smartor.mapper.IvrLibaTargetTagMapper;
@@ -14,7 +20,13 @@
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.lang.reflect.Array;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import java.util.stream.Collectors;
/**
 * 指标选项库Service业务层处理
@@ -61,11 +73,24 @@
        List<IvrLibaTarget> ivrLibaTargets = ivrLibaTargetMapper.selectIvrLibaTargetList(ivrLibaTarget);
        List<IvrLibaTargetVO> ivrLibaTargetVOS = DtoConversionUtils.sourceToTarget(ivrLibaTargets, IvrLibaTargetVO.class);
        for (IvrLibaTargetVO ivrLibaTarget1 : ivrLibaTargetVOS) {
            ivrLibaTarget1.setSuitWayList(JSONArray.parseArray(ivrLibaTarget1.getSuitWay(), String.class));
            IvrLibaTargetoption ivrLibaTargetoption = new IvrLibaTargetoption();
            ivrLibaTargetoption.setTargetid(ivrLibaTarget1.getId());
            //获取该指标的选项
            List<IvrLibaTargetoption> ivrLibaTargetoptions = ivrLibaTargetoptionMapper.selectIvrLibaTargetoptionList(ivrLibaTargetoption);
            if (CollectionUtils.isNotEmpty(ivrLibaTargetoptions)) {
                for (IvrLibaTargetoption ivrLibaTargetoption1 : ivrLibaTargetoptions) {
                    ObjectMapper objectMapper = new ObjectMapper();
                    try {
                        if (StringUtils.isNotEmpty(ivrLibaTargetoption1.getDynamiccruxsJson()))
                            ivrLibaTargetoption1.setDynamiccruxs(objectMapper.readValue(ivrLibaTargetoption1.getDynamiccruxsJson(), List.class));
                        if (StringUtils.isNotEmpty(ivrLibaTargetoption1.getNodynamiccruxsJson()))
                            ivrLibaTargetoption1.setNodynamiccruxs(objectMapper.readValue(ivrLibaTargetoption1.getNodynamiccruxsJson(), List.class));
                    } catch (JsonProcessingException e) {
                        e.printStackTrace();
                    }
                }
                ivrLibaTarget1.setTargetoptionList(ivrLibaTargetoptions);
            }
            //获取该指标的标签
@@ -123,6 +148,8 @@
    @Transactional(rollbackFor = Exception.class)
    public int saveOrupdateIvrLibaTarget(IvrLibaTargetVO ivrLibaTargetVO) {
        IvrLibaTarget ivrLibaTarget = DtoConversionUtils.sourceToTarget(ivrLibaTargetVO, IvrLibaTarget.class);
        if (ObjectUtils.isNotEmpty(ivrLibaTargetVO.getSuitWayList()))
            ivrLibaTarget.setSuitWay(JSON.toJSONString(ivrLibaTargetVO.getSuitWayList()));
        ivrLibaTarget.setUpdateTime(DateUtils.getNowDate());
        if (ivrLibaTargetVO.getIsoperation() != null && ivrLibaTargetVO.getIsoperation() == 1) {
            //新增
@@ -150,8 +177,16 @@
                }
            }
        }
        if (CollectionUtils.isNotEmpty(ivrLibaTargetVO.getTargetoptionList())) {
        if (CollectionUtils.isNotEmpty(ivrLibaTargetVO.getTargetoptionList()) && ivrLibaTargetVO.getValueType() == 1) {
            //选项处理
            for (IvrLibaTargetoption ivrLibaTargetoption : ivrLibaTargetVO.getTargetoptionList()) {
                if (CollectionUtils.isNotEmpty(ivrLibaTargetoption.getNodynamiccruxs())) {
                    ivrLibaTargetoption.setNodynamiccruxsJson(new Gson().toJson(ivrLibaTargetoption.getNodynamiccruxs()));
                }
                if (CollectionUtils.isNotEmpty(ivrLibaTargetoption.getDynamiccruxs())) {
                    ivrLibaTargetoption.setDynamiccruxsJson(new Gson().toJson(ivrLibaTargetoption.getDynamiccruxs()));
                }
                if (ivrLibaTargetoption.getIsoperation() != null && ivrLibaTargetoption.getIsoperation() == 1) {
                    //新增
                    ivrLibaTargetoption.setTargetid(ivrLibaTarget.getId());
@@ -165,6 +200,7 @@
                }
            }
        } else if (ivrLibaTargetVO.getValueType() == 2 || ivrLibaTargetVO.getValueType() == 3) {
        }
        return ivrLibaTarget.getId().intValue();
@@ -174,7 +210,6 @@
    /**
     * 批量删除指标选项库
     *
     * @param targetIDs 需要删除的指标选项库主键
     * @return 结果
     */
    @Override
@@ -185,11 +220,37 @@
    /**
     * 删除指标选项库信息
     *
     * @param targetID 指标选项库主键
     * @return 结果
     */
    @Override
    public int deleteIvrLibaTargetByTargetID(Long id) {
        return ivrLibaTargetMapper.deleteIvrLibaTargetByTargetID(id);
    }
    /**
     * 指标测试问题匹配
     */
    @Override
    public String targetQuesMate(IvrLibaTargetVO ivrLibaTargetVO) {
        for (IvrLibaTargetoption ivrLibaTargetoption : ivrLibaTargetVO.getTargetoptionList()) {
            Matcher matcher = null;
            if (StringUtils.isNotEmpty(ivrLibaTargetoption.getTargetregex())) {
                Pattern pattern = Pattern.compile(ivrLibaTargetoption.getTargetregex());
                matcher = pattern.matcher(ivrLibaTargetVO.getContent());
            }
            //不包含
            Matcher matcher2 = null;
            if (StringUtils.isNotEmpty(ivrLibaTargetoption.getTargetregex2())) {
                Pattern pattern2 = Pattern.compile(ivrLibaTargetoption.getTargetregex2());
                matcher2 = pattern2.matcher(ivrLibaTargetVO.getContent());
            }
            if (StringUtils.isNotEmpty(ivrLibaTargetoption.getTargetregex2()) && matcher2.matches() && StringUtils.isNotEmpty(ivrLibaTargetoption.getTargetregex()) && matcher.matches() || StringUtils.isEmpty(ivrLibaTargetoption.getTargetregex2()) && StringUtils.isNotEmpty(ivrLibaTargetoption.getTargetregex()) && matcher.matches()) {
                return ivrLibaTargetoption.getTargetvalue();
            }
        }
        return null;
    }
}