| | |
| | | package com.smartor.service.impl; |
| | | |
| | | import java.util.List; |
| | | import java.text.SimpleDateFormat; |
| | | import java.util.*; |
| | | import java.util.concurrent.TimeUnit; |
| | | |
| | | import com.alibaba.fastjson2.JSON; |
| | | import com.fasterxml.jackson.core.JsonProcessingException; |
| | | import com.fasterxml.jackson.core.type.TypeReference; |
| | | import com.fasterxml.jackson.databind.ObjectMapper; |
| | | import com.ruoyi.common.core.redis.RedisCache; |
| | | import com.ruoyi.common.exception.base.BaseException; |
| | | import com.ruoyi.common.utils.DateUtils; |
| | | import com.ruoyi.common.utils.DtoConversionUtils; |
| | | import org.apache.commons.lang3.StringUtils; |
| | | import com.smartor.domain.*; |
| | | import com.smartor.mapper.*; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.apache.commons.collections4.CollectionUtils; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.stereotype.Service; |
| | | import com.smartor.mapper.IvrTaskMapper; |
| | | import com.smartor.domain.IvrTask; |
| | | import com.smartor.service.IIvrTaskService; |
| | | import org.springframework.transaction.annotation.Transactional; |
| | | |
| | | /** |
| | | * 语音任务Service业务层处理 |
| | | * |
| | | * |
| | | * @author smartor |
| | | * @date 2023-03-24 |
| | | */ |
| | | @Slf4j |
| | | @Service |
| | | public class IvrTaskServiceImpl implements IIvrTaskService |
| | | { |
| | | public class IvrTaskServiceImpl implements IIvrTaskService { |
| | | @Autowired |
| | | private IvrTaskMapper ivrTaskMapper; |
| | | |
| | | @Autowired |
| | | private IvrTaskSingleMapper ivrTaskcallMapper; |
| | | |
| | | @Autowired |
| | | private IvrLibaTemplateScriptMapper ivrLibaTemplateScriptMapper; |
| | | |
| | | @Autowired |
| | | private PatArchiveMapper patArchiveMapper; |
| | | |
| | | @Autowired |
| | | private IvrLibaTemplateTargetoptionMapper ivrLibaTemplateTargetOptionMapper; |
| | | |
| | | @Autowired |
| | | private RedisCache redisCache; |
| | | |
| | | /** |
| | | * 查询语音任务 |
| | | * |
| | | * |
| | | * @param taskid 语音任务主键 |
| | | * @return 语音任务 |
| | | */ |
| | | @Override |
| | | public IvrTask selectIvrTaskByTaskid(Long taskid) |
| | | { |
| | | public IvrTask selectIvrTaskByTaskid(Long taskid) { |
| | | return ivrTaskMapper.selectIvrTaskByTaskid(taskid); |
| | | } |
| | | |
| | | /** |
| | | * 查询语音任务列表 |
| | | * |
| | | * |
| | | * @param ivrTask 语音任务 |
| | | * @return 语音任务 |
| | | */ |
| | | @Override |
| | | public List<IvrTask> selectIvrTaskList(IvrTask ivrTask) |
| | | { |
| | | public List<IvrTask> selectIvrTaskList(IvrTask ivrTask) { |
| | | return ivrTaskMapper.selectIvrTaskList(ivrTask); |
| | | } |
| | | |
| | | /** |
| | | * 新增语音任务 |
| | | * |
| | | * |
| | | * @param ivrTask 语音任务 |
| | | * @return 结果 |
| | | */ |
| | | @Override |
| | | public int insertIvrTask(IvrTask ivrTask) |
| | | { |
| | | public int insertIvrTask(IvrTask ivrTask) { |
| | | ivrTask.setCreateTime(DateUtils.getNowDate()); |
| | | return ivrTaskMapper.insertIvrTask(ivrTask); |
| | | } |
| | | |
| | | /** |
| | | * 修改语音任务 |
| | | * |
| | | * |
| | | * @param ivrTask 语音任务 |
| | | * @return 结果 |
| | | */ |
| | | @Override |
| | | public int updateIvrTask(IvrTask ivrTask) |
| | | { |
| | | public int updateIvrTask(IvrTask ivrTask) { |
| | | ivrTask.setUpdateTime(DateUtils.getNowDate()); |
| | | return ivrTaskMapper.updateIvrTask(ivrTask); |
| | | } |
| | | |
| | | /** |
| | | * 批量删除语音任务 |
| | | * |
| | | * |
| | | * @param taskids 需要删除的语音任务主键 |
| | | * @return 结果 |
| | | */ |
| | | @Override |
| | | public int deleteIvrTaskByTaskids(Long[] taskids) |
| | | { |
| | | public int deleteIvrTaskByTaskids(Long[] taskids) { |
| | | return ivrTaskMapper.deleteIvrTaskByTaskids(taskids); |
| | | } |
| | | |
| | | /** |
| | | * 删除语音任务信息 |
| | | * |
| | | * |
| | | * @param taskid 语音任务主键 |
| | | * @return 结果 |
| | | */ |
| | | @Transactional(rollbackFor = Exception.class) |
| | | @Override |
| | | public int deleteIvrTaskByTaskid(Long taskid) |
| | | { |
| | | return ivrTaskMapper.deleteIvrTaskByTaskid(taskid); |
| | | public Boolean deleteIvrTaskByTaskid(Long taskid) { |
| | | IvrTaskSingle ivrTaskcall = new IvrTaskSingle(); |
| | | ivrTaskcall.setTaskid(taskid); |
| | | ivrTaskcall.setDelFlag("1"); |
| | | Boolean aBoolean = ivrTaskcallMapper.updateIvrTaskcall(ivrTaskcall); |
| | | Boolean isSuccess = false; |
| | | if (!aBoolean) { |
| | | new BaseException("任务删除失败"); |
| | | } |
| | | isSuccess = ivrTaskMapper.deleteIvrTaskByTaskid(taskid); |
| | | return isSuccess; |
| | | } |
| | | |
| | | @Override |
| | | public List<IvrLibaTemplateScriptVO> getScriptInfoByCondition(Long taskid, Long patid) { |
| | | //通过任务ID获取模板ID |
| | | IvrTask ivrTask = selectIvrTaskByTaskid(taskid); |
| | | |
| | | //通过模板ID获取问题信息 |
| | | IvrLibaTemplateScript ivrLibaTemplateScript = new IvrLibaTemplateScript(); |
| | | ivrLibaTemplateScript.setTemplateID(ivrTask.getTemplateid()); |
| | | ivrLibaTemplateScript.setDelFlag("0"); |
| | | List<IvrLibaTemplateScript> ivrLibaTemplateScripts = ivrLibaTemplateScriptMapper.selectIvrLibaTemplateScriptList(ivrLibaTemplateScript); |
| | | if (CollectionUtils.isEmpty(ivrLibaTemplateScripts) || ivrLibaTemplateScripts.size() == 0) { |
| | | log.info("ivrLibaTemplateScripts为空了,请尽快联系管理员处理"); |
| | | return new ArrayList<>(); |
| | | } |
| | | List<IvrLibaTemplateScriptVO> ivrLibaTemplateScriptVOS = DtoConversionUtils.sourceToTarget(ivrLibaTemplateScripts, IvrLibaTemplateScriptVO.class); |
| | | |
| | | //获取患者信息 |
| | | PatArchive patArchive = patArchiveMapper.selectPatArchiveByPatid(patid); |
| | | |
| | | //通过患者信息和任务信息中的textParam对问题中的变量进行填充 |
| | | ObjectMapper objectMapper = new ObjectMapper(); |
| | | Map<String, Map<String, String>> ivrTaskMap = null; |
| | | try { |
| | | ivrTaskMap = objectMapper.readValue(ivrTask.getTextParam(), Map.class); |
| | | } catch (JsonProcessingException e) { |
| | | e.printStackTrace(); |
| | | } |
| | | List<Map<String, String>> mapList = new ArrayList<>(); |
| | | |
| | | for (Map<String, String> map : ivrTaskMap.values()) { |
| | | mapList.add(map); |
| | | } |
| | | |
| | | //将模板问题话术里的通配符替换 |
| | | for (IvrLibaTemplateScriptVO ivrLibaTemplateScriptVO : ivrLibaTemplateScriptVOS) { |
| | | if (StringUtils.isNotEmpty(ivrLibaTemplateScriptVO.getQuestionText())) { |
| | | for (Map<String, String> map : mapList) { |
| | | for (String key : map.keySet()) { |
| | | |
| | | ivrLibaTemplateScriptVO.setQuestionText(ivrLibaTemplateScriptVO.getQuestionText().replace(key, StringUtils.isNotEmpty(map.get(key)) ? map.get(key) : "")); |
| | | } |
| | | } |
| | | //替换患者个人信息数据 |
| | | ivrLibaTemplateScriptVO.setQuestionText(ivrLibaTemplateScriptVO.getQuestionText().replace("${name}", StringUtils.isNotEmpty(patArchive.getName()) ? patArchive.getName() : "")); |
| | | ivrLibaTemplateScriptVO.setQuestionText(ivrLibaTemplateScriptVO.getQuestionText().replace("${dzz}", StringUtils.isNotEmpty(patArchive.getPlaceOfResidence()) ? patArchive.getPlaceOfResidence() : "")); |
| | | ivrLibaTemplateScriptVO.setQuestionText(ivrLibaTemplateScriptVO.getQuestionText().replace("${dhh}", StringUtils.isNotEmpty(patArchive.getTelcode()) ? patArchive.getTelcode() : "")); |
| | | |
| | | //获取问题选项 |
| | | IvrLibaTemplateTargetoption ivrLibaTemplateTargetoption = new IvrLibaTemplateTargetoption(); |
| | | ivrLibaTemplateTargetoption.setScriptid(ivrLibaTemplateScriptVO.getID()); |
| | | List<IvrLibaTemplateTargetoption> ivrLibaTemplateTargetoptions = ivrLibaTemplateTargetOptionMapper.selectIvrLibaTemplateTargetoptionList(ivrLibaTemplateTargetoption); |
| | | ivrLibaTemplateScriptVO.setIvrLibaScriptTargetoptionList(ivrLibaTemplateTargetoptions); |
| | | } |
| | | } |
| | | |
| | | |
| | | return ivrLibaTemplateScriptVOS; |
| | | } |
| | | |
| | | |
| | | } |