liusheng
7 天以前 bd6c66c1a161e9f0fe94b94bed7935b2bde541f2
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
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;
import com.smartor.mapper.IvrLibaTargetoptionMapper;
import com.smartor.service.IIvrLibaTargetService;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.lang3.ObjectUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
 
import java.lang.reflect.Array;
import java.util.*;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import java.util.stream.Collectors;
 
/**
 * 指标选项库Service业务层处理
 *
 * @author ruoyi
 * @date 2023-12-14
 */
@Slf4j
@Service
public class IvrLibaTargetServiceImpl implements IIvrLibaTargetService {
    @Autowired
    private IvrLibaTargetMapper ivrLibaTargetMapper;
 
    @Autowired
    private IvrLibaTargetTagMapper ivrLibaTargetTagMapper;
 
    @Autowired
    private IvrLibaTargetoptionMapper ivrLibaTargetoptionMapper;
 
    /**
     * 查询指标选项库
     *
     * @param id 指标选项库主键
     * @return 指标选项库
     */
    @Override
    public IvrLibaTarget selectIvrLibaTargetByTargetID(Long id) {
        return ivrLibaTargetMapper.selectIvrLibaTargetByTargetID(id);
    }
 
    /**
     * 查询指标选项库列表
     *
     * @param ivrLibaTarget 指标选项库
     * @return 指标选项库
     */
    @Override
    public List<IvrLibaTarget> selectIvrLibaTargetList(IvrLibaTarget ivrLibaTarget) {
        return ivrLibaTargetMapper.selectIvrLibaTargetList(ivrLibaTarget);
    }
 
    @Override
    public List<IvrLibaTargetVO> targetInfo(IvrLibaTarget ivrLibaTarget) {
        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);
            }
            //获取该指标的标签
            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)
        return ivrLibaTargetVOS;
    }
 
    /**
     * 新增指标选项库
     *
     * @param ivrLibaTargetVO 指标选项库
     * @return 结果
     */
    @Override
    @Transactional(rollbackFor = Exception.class)
    public int insertIvrLibaTarget(IvrLibaTargetVO ivrLibaTargetVO) {
        //新增指标信息
        IvrLibaTarget ivrLibaTarget = DtoConversionUtils.sourceToTarget(ivrLibaTargetVO, IvrLibaTarget.class);
        ivrLibaTarget.setCreateTime(DateUtils.getNowDate());
        ivrLibaTargetMapper.insertIvrLibaTarget(ivrLibaTarget);
 
        //新增该指标对应的标签信息
        for (IvrLibaTargetTag ivrLibaTargetTag : ivrLibaTargetVO.getIvrLibaTargetTagList()) {
            ivrLibaTargetTag.setTargetid(ivrLibaTarget.getId());
            ivrLibaTargetTag.setGuid(ivrLibaTargetVO.getGuid());
            ivrLibaTargetTag.setOrgid(ivrLibaTargetVO.getOrgid());
            ivrLibaTargetTagMapper.insertIvrLibaTargetTag(ivrLibaTargetTag);
        }
 
        //新增该指标对应的指标选项信息
        for (IvrLibaTargetoption targetoption : ivrLibaTargetVO.getTargetoptionList()) {
            if (ObjectUtils.isEmpty(targetoption)) continue;
            log.info("targetoption的数据为:{}", targetoption);
            targetoption.setTargetid(ivrLibaTarget.getId());
            targetoption.setGuid(ivrLibaTargetVO.getGuid());
            targetoption.setOrgid(ivrLibaTargetVO.getOrgid());
            ivrLibaTargetoptionMapper.insertIvrLibaTargetoption(targetoption);
        }
 
        log.info("指标id为:{}", ivrLibaTarget.getId().intValue());
        return ivrLibaTarget.getId().intValue();
    }
 
    /**
     * 新增或修改指标选项库
     *
     * @param ivrLibaTargetVO 指标选项库
     * @return 结果
     */
    @Override
    @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.getIvrLibaTargetTagList())) {
            for (IvrLibaTargetTag ivrLibaTargetTag : ivrLibaTargetVO.getIvrLibaTargetTagList()) {
                ivrLibaTargetTag.setGuid(ivrLibaTargetVO.getGuid());
                ivrLibaTargetTag.setOrgid(ivrLibaTargetVO.getOrgid());
                if (ivrLibaTargetTag.getId() == null) {
                    //新增
                    ivrLibaTargetTag.setTargetid(ivrLibaTarget.getId());
                    ivrLibaTargetTagMapper.insertIvrLibaTargetTag(ivrLibaTargetTag);
                } else if (ivrLibaTargetTag.getId() != null) {
                    //前端页面应该没有修改
                    ivrLibaTargetTagMapper.updateIvrLibaTargetTag(ivrLibaTargetTag);
                }
            }
        }
        if (CollectionUtils.isNotEmpty(ivrLibaTargetVO.getTargetoptionList()) && ivrLibaTargetVO.getScriptType().equals("1") || CollectionUtils.isNotEmpty(ivrLibaTargetVO.getTargetoptionList()) && ivrLibaTargetVO.getScriptType().equals("2")) {
            //选项处理
            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()));
                }
 
                ivrLibaTargetoption.setGuid(ivrLibaTargetVO.getGuid());
                ivrLibaTargetoption.setOrgid(ivrLibaTargetVO.getOrgid());
                if (ivrLibaTargetoption.getIsoperation() != null && ivrLibaTargetoption.getIsoperation() == 1) {
                    //新增
                    ivrLibaTargetoption.setTargetid(ivrLibaTarget.getId());
                    ivrLibaTargetoptionMapper.insertIvrLibaTargetoption(ivrLibaTargetoption);
                } else if (ivrLibaTargetoption.getIsoperation() != null && ivrLibaTargetoption.getIsoperation() == 2) {
                    //修改
                    ivrLibaTargetoptionMapper.updateIvrLibaTargetoption(ivrLibaTargetoption);
                } else if (ivrLibaTargetoption.getIsoperation() != null && ivrLibaTargetoption.getIsoperation() == 3) {
                    // 删除
                    ivrLibaTargetoptionMapper.deleteIvrLibaTargetoptionByTargetoptionid(ivrLibaTargetoption.getTargetoptionid());
                }
 
            }
        } else if (ivrLibaTargetVO.getScriptType().equals("3") || ivrLibaTargetVO.getScriptType().equals("4")) {
            //这里先等等
        }
 
        return ivrLibaTarget.getId().intValue();
    }
 
 
    /**
     * 批量删除指标选项库
     *
     * @return 结果
     */
    @Override
    public int deleteIvrLibaTargetByTargetIDs(Long[] ids) {
        return ivrLibaTargetMapper.deleteIvrLibaTargetByTargetIDs(ids);
    }
 
    /**
     * 删除指标选项库信息
     *
     * @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;
    }
}