liusheng
2024-09-18 907641e56c2085aaa81f267946dc3e3e9fca73e7
smartor/src/main/java/com/smartor/service/impl/IvrLibaTargetServiceImpl.java
@@ -1,5 +1,7 @@
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;
@@ -18,7 +20,11 @@
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.util.List;
import java.lang.reflect.Array;
import java.util.*;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import java.util.stream.Collectors;
/**
 * 指标选项库Service业务层处理
@@ -65,6 +71,8 @@
        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());
            //获取该指标的选项
@@ -84,8 +92,25 @@
                ivrLibaTarget1.setTargetoptionList(ivrLibaTargetoptions);
            }
            //获取该指标的标签
            List<BaseTag> baseTags = ivrLibaTargetTagMapper.selectTagName(ivrLibaTarget1.getId());
            ivrLibaTarget1.setBaseTagList(baseTags);
            IvrLibaTargetTag ivrLibaTargetTag = new IvrLibaTargetTag();
            ivrLibaTargetTag.setTargetid(ivrLibaTarget1.getId());
            List<IvrLibaTargetTag> ivrLibaTargetTags = ivrLibaTargetTagMapper.selectIvrLibaTargetTagList(ivrLibaTargetTag);
            ivrLibaTarget1.setIvrLibaTargetTagList(ivrLibaTargetTags);
        }
        //判断入参条件中,tagName是否有值,如果有值,则需要根据给的值进行标签过滤
        if (StringUtils.isNotEmpty(ivrLibaTarget.getTagName())) {
            List<IvrLibaTargetVO> ivrLibaTargetVOList = new ArrayList<>();
            aa:
            for (IvrLibaTargetVO ivrLibaTarget1 : ivrLibaTargetVOS) {
                for (IvrLibaTargetTag ivrLibaTargetTag1 : ivrLibaTarget1.getIvrLibaTargetTagList()) {
                    if (ivrLibaTargetTag1.getTagname().contains(ivrLibaTarget.getTagName().trim())) {
                        ivrLibaTargetVOList.add(ivrLibaTarget1);
                        continue aa;
                    }
                }
            }
            ivrLibaTargetVOS = ivrLibaTargetVOList;
        }
        //下面用左外感觉有点问题,where中的option的del会导致左边的查询不全,先不用吧
//        ivrLibaTargetMapper.targetInfo(ivrLibaTarget)
@@ -107,12 +132,8 @@
        ivrLibaTargetMapper.insertIvrLibaTarget(ivrLibaTarget);
        //新增该指标对应的标签信息
        for (BaseTag baseTag : ivrLibaTargetVO.getBaseTagList()) {
            IvrLibaTargetTag ivrLibaTargetTag = new IvrLibaTargetTag();
            ivrLibaTargetTag.setTagcategoryid(baseTag.getTagcategoryid());
        for (IvrLibaTargetTag ivrLibaTargetTag : ivrLibaTargetVO.getIvrLibaTargetTagList()) {
            ivrLibaTargetTag.setTargetid(ivrLibaTarget.getId());
            //前端传来的baseTag的tagid就是指标标签的主键id,不是baseTag的主键
            ivrLibaTargetTag.setTagid(baseTag.getTagid());
            ivrLibaTargetTagMapper.insertIvrLibaTargetTag(ivrLibaTargetTag);
        }
@@ -138,34 +159,34 @@
    @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) {
            //新增
            ivrLibaTarget.setCreateTime(new Date());
            ivrLibaTarget.setUpdateTime(new Date());
            ivrLibaTargetMapper.insertIvrLibaTarget(ivrLibaTarget);
        } else if (ivrLibaTargetVO.getIsoperation() != null && ivrLibaTargetVO.getIsoperation() == 2) {
            //修改
            ivrLibaTarget.setUpdateTime(new Date());
            ivrLibaTargetMapper.updateIvrLibaTarget(ivrLibaTarget);
        }
        if (CollectionUtils.isNotEmpty(ivrLibaTargetVO.getBaseTagList())) {
            for (BaseTag baseTag : ivrLibaTargetVO.getBaseTagList()) {
                if (baseTag.getIsoperation() != null && baseTag.getIsoperation() == 1) {
        if (CollectionUtils.isNotEmpty(ivrLibaTargetVO.getIvrLibaTargetTagList())) {
            for (IvrLibaTargetTag ivrLibaTargetTag : ivrLibaTargetVO.getIvrLibaTargetTagList()) {
                if (ivrLibaTargetTag.getId() == null) {
                    //新增
                    IvrLibaTargetTag ivrLibaTargetTag = new IvrLibaTargetTag();
                    ivrLibaTargetTag.setTagcategoryid(baseTag.getTagcategoryid());
                    ivrLibaTargetTag.setTargetid(ivrLibaTarget.getId());
                    //前端传来的baseTag的tagid就是指标标签的主键id,不是baseTag的主键
                    ivrLibaTargetTag.setTagid(baseTag.getTagid());
                    ivrLibaTargetTagMapper.insertIvrLibaTargetTag(ivrLibaTargetTag);
                } else if (baseTag.getIsoperation() != null && baseTag.getIsoperation() == 2) {
                } else if (ivrLibaTargetTag.getId() != null) {
                    //前端页面应该没有修改
                } else if (baseTag.getIsoperation() != null && baseTag.getIsoperation() == 3) {
                    //删除
                    ivrLibaTargetTagMapper.deleteIvrLibaTargetTagById(baseTag.getTagid());
                    ivrLibaTargetTagMapper.updateIvrLibaTargetTag(ivrLibaTargetTag);
                }
            }
        }
        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()));
@@ -187,6 +208,7 @@
                }
            }
        } else if (ivrLibaTargetVO.getValueType() == 2 || ivrLibaTargetVO.getValueType() == 3) {
        }
        return ivrLibaTarget.getId().intValue();
@@ -212,4 +234,31 @@
    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;
    }
}