| | |
| | | package com.smartor.service.impl; |
| | | |
| | | import com.fasterxml.jackson.core.JsonProcessingException; |
| | | import com.fasterxml.jackson.databind.ObjectMapper; |
| | | import com.ruoyi.common.utils.DateUtils; |
| | | import com.ruoyi.common.utils.StringUtils; |
| | | import com.smartor.domain.ServiceSubtask; |
| | | import com.smartor.domain.ServiceSubtaskDetail; |
| | | import com.smartor.domain.ServiceSubtaskDetail; |
| | | import com.smartor.domain.ServiceTask; |
| | | import com.smartor.mapper.ServiceSubtaskDetailMapper; |
| | | import com.smartor.mapper.ServiceSubtaskMapper; |
| | | import com.smartor.service.IServiceSubtaskDetailService; |
| | | import com.smartor.service.IServiceTaskService; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.apache.commons.collections4.CollectionUtils; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.stereotype.Service; |
| | | |
| | | import java.util.List; |
| | | import java.util.*; |
| | | import java.util.stream.Collectors; |
| | | |
| | | /** |
| | | * 语音任务呼叫明细Service业务层处理 |
| | |
| | | private ServiceSubtaskDetailMapper ServiceSubtaskDetailMapper; |
| | | |
| | | @Autowired |
| | | private ServiceSubtaskMapper ivrTaskSingleMapper; |
| | | private ServiceSubtaskMapper serviceSubtaskMapper; |
| | | |
| | | @Autowired |
| | | private IServiceTaskService serviceTaskService; |
| | | |
| | | |
| | | /** |
| | |
| | | * @return 语音任务呼叫明细 |
| | | */ |
| | | @Override |
| | | public List<ServiceSubtaskDetail> selectServiceSubtaskDetailList(ServiceSubtaskDetail serviceSubtaskDetail) { |
| | | return ServiceSubtaskDetailMapper.selectServiceSubtaskDetailList(serviceSubtaskDetail); |
| | | public Map<String, Object> selectServiceSubtaskDetailList(ServiceSubtaskDetail serviceSubtaskDetail) { |
| | | List<ServiceSubtaskDetail> serviceSubtaskDetails = ServiceSubtaskDetailMapper.selectServiceSubtaskDetailList(serviceSubtaskDetail); |
| | | if (CollectionUtils.isNotEmpty(serviceSubtaskDetails)) { |
| | | //处理一下通配符 |
| | | for (ServiceSubtaskDetail serviceSubtaskDetail1 : serviceSubtaskDetails) { |
| | | ServiceSubtask serviceSubtask = serviceSubtaskMapper.selectServiceSubtaskById(serviceSubtaskDetail1.getSubId()); |
| | | serviceSubtaskDetail1.setQuestiontext(getObject(serviceSubtask, serviceSubtaskDetail1.getQuestiontext())); |
| | | } |
| | | } |
| | | //获取最后的总录音地址 |
| | | Map<String, Object> map = new HashMap<>(); |
| | | map.put("code", 200); |
| | | map.put("msg", "查询成功"); |
| | | Map<String, Object> map1 = new HashMap<>(); |
| | | map1.put("serviceSubtaskDetails", serviceSubtaskDetails); |
| | | map1.put("filteredDetails", null); |
| | | //用于存储去重的数据 |
| | | List<ServiceSubtaskDetail> serviceSubtaskDetailSET = new ArrayList<>(); |
| | | Boolean flag = false; |
| | | if (CollectionUtils.isNotEmpty(serviceSubtaskDetails)) { |
| | | for (ServiceSubtaskDetail serviceSubtaskDetail1 : serviceSubtaskDetails) { |
| | | if (serviceSubtaskDetailSET.size() == 0) { |
| | | serviceSubtaskDetailSET.add(serviceSubtaskDetail1); |
| | | } else { |
| | | // for (ServiceSubtaskDetail subtaskDetail : serviceSubtaskDetailSET) |
| | | for (int i = 0; i < serviceSubtaskDetailSET.size(); i++) { |
| | | ServiceSubtaskDetail subtaskDetail = serviceSubtaskDetailSET.get(i); |
| | | if (subtaskDetail.getPatid().equals(serviceSubtaskDetail1.getPatid()) && subtaskDetail.getSubId().equals(serviceSubtaskDetail1.getSubId()) && subtaskDetail.getTaskid().equals(serviceSubtaskDetail1.getTaskid()) && subtaskDetail.getQuestiontext().equals(serviceSubtaskDetail1.getQuestiontext())) { |
| | | if (StringUtils.isNotEmpty(serviceSubtaskDetail1.getMatchedtext())) { |
| | | serviceSubtaskDetailSET.set(i, serviceSubtaskDetail1); |
| | | } |
| | | //匹配到这个数据,将flag改成false |
| | | if (flag == true) flag = false; |
| | | } else if ((subtaskDetail.getPatid().equals(serviceSubtaskDetail1.getPatid()) && subtaskDetail.getSubId().equals(serviceSubtaskDetail1.getSubId()) && subtaskDetail.getTaskid().equals(serviceSubtaskDetail1.getTaskid()) && !subtaskDetail.getQuestiontext().equals(serviceSubtaskDetail1.getQuestiontext()))) { |
| | | //标识一下,暂时没有匹配到这个数据 |
| | | flag = true; |
| | | } else if ((subtaskDetail.getPatid() == serviceSubtaskDetail1.getPatid() && subtaskDetail.getSubId() != serviceSubtaskDetail1.getSubId() && subtaskDetail.getTaskid() == serviceSubtaskDetail1.getTaskid())) { |
| | | //标识一下,暂时没有匹配到这个数据 |
| | | flag = true; |
| | | } |
| | | } |
| | | if (flag == true) { |
| | | //如果去重循环都结束了,还没有匹配到这个数据,则往去重对象里新增一个 |
| | | serviceSubtaskDetailSET.add(serviceSubtaskDetail1); |
| | | flag = false; |
| | | } |
| | | } |
| | | } |
| | | } |
| | | Collections.sort(serviceSubtaskDetailSET, Comparator.comparingLong(ServiceSubtaskDetail::getTemplatequestionnum)); |
| | | map1.put("filteredDetails", serviceSubtaskDetailSET); |
| | | |
| | | map1.put("voice", ""); |
| | | if (CollectionUtils.isNotEmpty(serviceSubtaskDetails) && StringUtils.isNotEmpty(serviceSubtaskDetails.get(0).getQuestionvoice())) { |
| | | //获取完整语音 |
| | | String filePath = serviceSubtaskDetails.get(0).getQuestionvoice(); |
| | | int lastIndex = filePath.lastIndexOf('.'); |
| | | if (lastIndex != -1) { |
| | | int secondLastIndex = filePath.lastIndexOf('.', lastIndex - 1); |
| | | if (secondLastIndex != -1) { |
| | | String voicePath = filePath.substring(0, secondLastIndex) + filePath.substring(lastIndex); |
| | | map1.put("voice", voicePath); |
| | | } |
| | | } |
| | | } |
| | | map.put("data", map1); |
| | | return map; |
| | | } |
| | | |
| | | /** |
| | |
| | | return ServiceSubtaskDetailMapper.updateServiceSubtaskDetail(serviceSubtaskDetail); |
| | | } |
| | | |
| | | @Override |
| | | public int updateSSDByCondition(ServiceSubtaskDetail serviceSubtaskDetail) { |
| | | serviceSubtaskDetail.setUpdateTime(DateUtils.getNowDate()); |
| | | return ServiceSubtaskDetailMapper.updateSSDByCondition(serviceSubtaskDetail); |
| | | } |
| | | |
| | | /** |
| | | * 批量删除语音任务呼叫明细 |
| | | * |
| | |
| | | return ServiceSubtaskDetailMapper.deleteServiceSubtaskDetailByCalldetailid(calldetailid); |
| | | } |
| | | |
| | | private String getObject(ServiceSubtask serviceSubtask, String scriptContent) { |
| | | Map<String, Map<String, String>> param = getParam(serviceSubtask.getTaskid()); |
| | | for (Map<String, String> map : param.values()) { |
| | | for (String key : map.keySet()) { |
| | | scriptContent = scriptContent.replace(key, org.apache.commons.lang3.StringUtils.isNotEmpty(map.get(key)) ? map.get(key) : ""); |
| | | } |
| | | } |
| | | scriptContent = scriptContent.replace("${name}", org.apache.commons.lang3.StringUtils.isNotEmpty(serviceSubtask.getSendname()) ? serviceSubtask.getSendname() : ""); |
| | | scriptContent = scriptContent.replace("${dzz}", org.apache.commons.lang3.StringUtils.isNotEmpty(serviceSubtask.getAddr()) ? serviceSubtask.getAddr() : ""); |
| | | scriptContent = scriptContent.replace("${phone}", org.apache.commons.lang3.StringUtils.isNotEmpty(serviceSubtask.getTelcode()) ? serviceSubtask.getTelcode() : ""); |
| | | |
| | | return scriptContent; |
| | | } |
| | | |
| | | |
| | | /** |
| | | * 获取任务里的通配符 |
| | | * |
| | | * @param taskId |
| | | * @return |
| | | */ |
| | | private Map<String, Map<String, String>> getParam(Long taskId) { |
| | | ServiceTask serviceTask = serviceTaskService.selectServiceTaskByTaskid(taskId); |
| | | ObjectMapper objectMapper = new ObjectMapper(); |
| | | Map<String, Map<String, String>> serviceTaskMap = null; |
| | | try { |
| | | serviceTaskMap = objectMapper.readValue(serviceTask.getTextParam(), Map.class); |
| | | } catch (JsonProcessingException e) { |
| | | e.printStackTrace(); |
| | | } |
| | | return serviceTaskMap; |
| | | } |
| | | |
| | | } |