liusheng
2025-03-03 88c5064877fa22316d794c225fff3ceced4371f3
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
package com.smartor.service.impl;
 
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.google.gson.Gson;
import com.ruoyi.common.exception.base.BaseException;
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.IvrLibaScriptMapper;
import com.smartor.mapper.IvrLibaScriptTagMapper;
import com.smartor.mapper.IvrLibaScriptTargetMapper;
import com.smartor.mapper.IvrLibaScriptTargetoptionMapper;
import com.smartor.service.IIvrLibaScriptService;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections4.CollectionUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
 
import java.util.List;
 
/**
 * 问题话术库Service业务层处理
 *
 * @author ruoyi
 * @date 2023-12-21
 */
@Slf4j
@Service
public class IvrLibaScriptServiceImpl implements IIvrLibaScriptService {
    @Autowired
    private IvrLibaScriptMapper ivrLibaScriptMapper;
 
    @Autowired
    private IvrLibaScriptTagMapper ivrLibaScriptTagMapper;
 
    @Autowired
    private IvrLibaScriptTargetoptionMapper ivrLibaScriptTargetoptionMapper;
 
    @Autowired
    private IvrLibaScriptTargetMapper ivrLibaScriptTargetMapper;
 
    /**
     * 查询问题话术库
     *
     * @param questionid 问题话术库主键
     * @return 问题话术库
     */
    @Override
    public IvrLibaScript selectIvrLibaScriptByQuestionid(String questionid) {
        return ivrLibaScriptMapper.selectIvrLibaScriptByQuestionid(questionid);
    }
 
    /**
     * 查询问题话术库列表
     *
     * @param ivrLibaScript 问题话术库
     * @return 问题话术库
     */
    @Override
    public List<IvrLibaScript> selectIvrLibaScriptList(IvrLibaScript ivrLibaScript) {
        return ivrLibaScriptMapper.selectIvrLibaScriptList(ivrLibaScript);
    }
 
    /**
     * 查询问题话术详情根据条件
     */
    @Override
    public IvrLibaScriptVO selectInfoByCondition(IvrLibaScriptVO ivrLibaScriptVO) {
        log.info("查询问题话术详情根据条件的入参为 : {}", ivrLibaScriptVO);
        //先根据条件查询问题表信息
        IvrLibaScript ivrLibaScript = DtoConversionUtils.sourceToTarget(ivrLibaScriptVO, IvrLibaScript.class);
        List<IvrLibaScript> ivrLibaScripts = selectIvrLibaScriptList(ivrLibaScript);
        if (CollectionUtils.isEmpty(ivrLibaScripts)) {
            log.info("提供的条件,查询数据为空:{}", ivrLibaScript);
            return null;
        }
        log.info("ivrLibaScript的查询结果为:{},数量为 : {}", ivrLibaScripts.get(0), ivrLibaScripts.size());
        //定义IvrLibaScriptVO 用于返参
        IvrLibaScriptVO scriptVO = DtoConversionUtils.sourceToTarget(ivrLibaScripts.get(0), IvrLibaScriptVO.class);
 
        //获取tag信息
        IvrLibaScriptTag ivrLibaScriptTag = new IvrLibaScriptTag();
        ivrLibaScriptTag.setScriptid(ivrLibaScripts.get(0).getId());
        List<IvrLibaScriptTag> ivrLibaScriptTags = ivrLibaScriptTagMapper.selectIvrLibaScriptTagList(ivrLibaScriptTag);
        scriptVO.setIvrLibaScriptTagList(ivrLibaScriptTags);
 
        //获取option信息
        IvrLibaScriptTargetoption ivrLibaScriptTargetoption = new IvrLibaScriptTargetoption();
        ivrLibaScriptTargetoption.setScriptid(ivrLibaScripts.get(0).getId());
        List<IvrLibaScriptTargetoption> ivrLibaScriptTargetoptions = ivrLibaScriptTargetoptionMapper.selectIvrLibaScriptTargetoptionList(ivrLibaScriptTargetoption);
        for (IvrLibaScriptTargetoption ivrLibaScriptTargetoption1 : ivrLibaScriptTargetoptions) {
            ObjectMapper objectMapper = new ObjectMapper();
            try {
                if (StringUtils.isNotEmpty(ivrLibaScriptTargetoption1.getDynamiccruxsJson()))
                    ivrLibaScriptTargetoption1.setDynamiccruxs(objectMapper.readValue(ivrLibaScriptTargetoption1.getDynamiccruxsJson(), List.class));
                if (StringUtils.isNotEmpty(ivrLibaScriptTargetoption1.getNodynamiccruxsJson()))
                    ivrLibaScriptTargetoption1.setNodynamiccruxs(objectMapper.readValue(ivrLibaScriptTargetoption1.getNodynamiccruxsJson(), List.class));
            } catch (JsonProcessingException e) {
                e.printStackTrace();
            }
        }
 
 
        scriptVO.setIvrLibaScriptTargetoptionList(ivrLibaScriptTargetoptions);
 
//        //查询问题指标接口
//        IvrLibaScriptTarget ivrLibaScriptTarget = new IvrLibaScriptTarget();
//        ivrLibaScriptTarget.setScriptid(ivrLibaScripts.get(0).getId());
//        List<IvrLibaScriptTarget> ivrLibaScriptTargets = ivrLibaScriptTargetMapper.selectIvrLibaScriptTargetList(ivrLibaScriptTarget);
//        scriptVO.setIvrLibaScriptTargetList(ivrLibaScriptTargets);
 
        return scriptVO;
    }
 
    /**
     * 新增或修改问题详情
     *
     * @param ivrLibaScriptVO
     * @return
     */
    @Transactional(rollbackFor = Exception.class)
    @Override
    public Integer saveOrUpdateScript(IvrLibaScriptVO ivrLibaScriptVO) {
        IvrLibaScript ivrLibaScript = DtoConversionUtils.sourceToTarget(ivrLibaScriptVO, IvrLibaScript.class);
        //对问题表进行数据处理
        Integer i = null;
        if (ivrLibaScriptVO.getIsoperation() != null && ivrLibaScriptVO.getIsoperation() == 1) {
            i = ivrLibaScriptMapper.insertIvrLibaScript(ivrLibaScript);
        } else if (ivrLibaScriptVO.getIsoperation() != null && ivrLibaScriptVO.getIsoperation() == 2) {
            i = ivrLibaScriptMapper.updateIvrLibaScript(ivrLibaScript);
        }
        log.info("问题表对应的id为:{}", ivrLibaScript.getId());
        if (ivrLibaScript.getId() == null) {
            throw new BaseException("话术ID为空,请检查话术入参信息是否完整");
        }
 
        //对问题指标选项进行处理
        if (CollectionUtils.isNotEmpty(ivrLibaScriptVO.getIvrLibaScriptTargetoptionList())) {
            for (IvrLibaScriptTargetoption ivrLibaScriptTargetoption : ivrLibaScriptVO.getIvrLibaScriptTargetoptionList()) {
                if (CollectionUtils.isNotEmpty(ivrLibaScriptTargetoption.getNodynamiccruxs())) {
                    ivrLibaScriptTargetoption.setNodynamiccruxsJson(new Gson().toJson(ivrLibaScriptTargetoption.getNodynamiccruxs()));
                }
                if (CollectionUtils.isNotEmpty(ivrLibaScriptTargetoption.getDynamiccruxs())) {
                    ivrLibaScriptTargetoption.setDynamiccruxsJson(new Gson().toJson(ivrLibaScriptTargetoption.getDynamiccruxs()));
                }
 
                ivrLibaScriptTargetoption.setGuid(ivrLibaScriptVO.getGuid());
                ivrLibaScriptTargetoption.setOrgid(ivrLibaScriptVO.getOrgid());
                if (ivrLibaScriptTargetoption.getIsoperation() != null && ivrLibaScriptTargetoption.getIsoperation() == 1) {
                    //新增
                    ivrLibaScriptTargetoption.setScriptid(ivrLibaScript.getId());
                    ivrLibaScriptTargetoptionMapper.insertIvrLibaScriptTargetoption(ivrLibaScriptTargetoption);
                }
                if (ivrLibaScriptTargetoption.getIsoperation() != null && ivrLibaScriptTargetoption.getIsoperation() == 2) {
                    //修改
                    ivrLibaScriptTargetoption.setScriptid(ivrLibaScript.getId());
                    ivrLibaScriptTargetoptionMapper.updateIvrLibaScriptTargetoption(ivrLibaScriptTargetoption);
                    //如果要给正则置空,则需要单独调修改方法
                    if (CollectionUtils.isEmpty(ivrLibaScriptTargetoption.getNodynamiccruxs())) {
                        ivrLibaScriptTargetoption.setNodynamiccruxsJson(null);
                        ivrLibaScriptTargetoptionMapper.updateDynam(ivrLibaScriptTargetoption);
                    }
                    if (CollectionUtils.isEmpty(ivrLibaScriptTargetoption.getDynamiccruxs())) {
                        ivrLibaScriptTargetoption.setDynamiccruxsJson(null);
                        ivrLibaScriptTargetoptionMapper.updateDynam(ivrLibaScriptTargetoption);
                    }
 
                }
                if (ivrLibaScriptTargetoption.getIsoperation() != null && ivrLibaScriptTargetoption.getIsoperation() == 3) {
                    //删除
                    if (ivrLibaScriptTargetoption.getId() == null) {
                        log.info("删除失败,问题指标选项id为空");
                    } else {
                        Boolean aBoolean = ivrLibaScriptTargetoptionMapper.deleteIvrLibaScriptTargetoptionByTargetoptionid(ivrLibaScriptTargetoption.getId());
                        log.info("aBoolean的值为:{}", aBoolean);
                    }
                }
            }
        }
 
        //对问题标签进行处理
        if (CollectionUtils.isNotEmpty(ivrLibaScriptVO.getIvrLibaScriptTagList())) {
            for (IvrLibaScriptTag ivrLibaScriptTag : ivrLibaScriptVO.getIvrLibaScriptTagList()) {
                ivrLibaScriptTag.setGuid(ivrLibaScriptVO.getGuid());
                ivrLibaScriptTag.setOrgid(ivrLibaScriptVO.getOrgid());
                if (ivrLibaScriptTag.getIsoperation() != null && ivrLibaScriptTag.getIsoperation() == 1) {
                    //新增
                    ivrLibaScriptTag.setScriptid(ivrLibaScript.getId());
                    ivrLibaScriptTagMapper.insertIvrLibaScriptTag(ivrLibaScriptTag);
                }
                if (ivrLibaScriptTag.getIsoperation() != null && ivrLibaScriptTag.getIsoperation() == 2) {
                    //修改
                    ivrLibaScriptTag.setScriptid(ivrLibaScript.getId());
                    ivrLibaScriptTagMapper.updateIvrLibaScriptTag(ivrLibaScriptTag);
                }
                if (ivrLibaScriptTag.getIsoperation() != null && ivrLibaScriptTag.getIsoperation() == 3) {
                    //删除
                    if (ivrLibaScriptTag.getId() == null) {
                        log.info("删除失败,问题标签id为空");
                    } else {
                        ivrLibaScriptTagMapper.deleteIvrLibaScriptTagById(ivrLibaScriptTag.getId());
                    }
                }
            }
        }
        return i;
    }
 
    /**
     * 新增问题话术库
     *
     * @param ivrLibaScript 问题话术库
     * @return 结果
     */
    @Override
    public int insertIvrLibaScript(IvrLibaScript ivrLibaScript) {
        ivrLibaScript.setCreateTime(DateUtils.getNowDate());
        return ivrLibaScriptMapper.insertIvrLibaScript(ivrLibaScript);
    }
 
    /**
     * 修改问题话术库
     *
     * @param ivrLibaScript 问题话术库
     * @return 结果
     */
    @Override
    public int updateIvrLibaScript(IvrLibaScript ivrLibaScript) {
        ivrLibaScript.setUpdateTime(DateUtils.getNowDate());
        return ivrLibaScriptMapper.updateIvrLibaScript(ivrLibaScript);
    }
 
    /**
     * 批量删除问题话术库
     *
     * @param questionids 需要删除的问题话术库主键
     * @return 结果
     */
    @Override
    public int deleteIvrLibaScriptByQuestionids(String[] questionids) {
        Integer i = null;
        for (String id : questionids) {
            i = ivrLibaScriptMapper.deleteIvrLibaScriptByQuestionid(Integer.valueOf(id));
        }
        return i;
    }
 
}