liusheng
2 天以前 1e1814178edf84090b28492bbad340ab13e5c169
smartor/src/main/java/com/smartor/service/impl/ServiceSubtaskServiceImpl.java
@@ -1243,6 +1243,7 @@
                    }
                    break;
                }
                log.info("是否需要挂机:{}", les);
                if (ObjectUtils.isNotEmpty(les)) {
                    //对匹配的结果处理一下(看看是不是需要挂机)
                    if (les.getIsEnd() != null && les.getIsEnd() == 1) {
@@ -1301,6 +1302,7 @@
                    if (StringUtils.isNotEmpty(ivrTaskTemplateScriptVO.getIvrTaskScriptTargetoptionList().get(j).getTargetregex2()) && matcher2.matches() && StringUtils.isNotEmpty(ivrTaskTemplateScriptVO.getIvrTaskScriptTargetoptionList().get(j).getTargetregex()) && matcher.matches() || StringUtils.isEmpty(ivrTaskTemplateScriptVO.getIvrTaskScriptTargetoptionList().get(j).getTargetregex()) && StringUtils.isNotEmpty(ivrTaskTemplateScriptVO.getIvrTaskScriptTargetoptionList().get(j).getTargetregex2()) && matcher2.matches() || StringUtils.isEmpty(ivrTaskTemplateScriptVO.getIvrTaskScriptTargetoptionList().get(j).getTargetregex2()) && StringUtils.isNotEmpty(ivrTaskTemplateScriptVO.getIvrTaskScriptTargetoptionList().get(j).getTargetregex()) && matcher.matches()) {
                        //说明匹配正确了
                        //这里应该先判断类型,去再修改,设置IsUserOperation是单选题的改法
                        log.info("匹配正确了吗--------------");
                        ivrTaskTemplateScriptVO.getIvrTaskScriptTargetoptionList().get(j).setIsUserOperation(1);
                        serviceTaskScriptTargetoptionMapper.updateIvrTaskTemplateTargetoption(ivrTaskTemplateScriptVO.getIvrTaskScriptTargetoptionList().get(j));
@@ -1389,8 +1391,9 @@
                                if (script.getSort() == nextQuestion.intValue()) {
                                    phoneCallBackYQVO.setType("text");
                                    phoneCallBackYQVO.setSilent_interval(ivrTaskTemplate.getSilencetime().intValue());
                                    String scriptContent = script.getIvrtext();
                                    String scriptContent = StringUtils.isNotEmpty(script.getIvrtext()) ? script.getIvrtext() : script.getScriptContent();
                                    log.error("下一题问题:{}", scriptContent);
                                    log.error("下一题的子任务是:{}", serviceSubtask);
                                    phoneCallBackYQVO.setValue(phoneCallBackYQVO.getCommonValue() + getObject(serviceSubtask, scriptContent));
                                    //将该患者的Redis中的题目ID,进行修改
                                    redisCache.setCacheObject(phoneCallReqYQVO.getTaskid().trim() + "-" + phoneCallReqYQVO.getPhone().trim(), script.getId().toString(), 120, TimeUnit.MINUTES);
@@ -1429,6 +1432,7 @@
                        }
                    } else {
                        log.info("没有匹配上----------------------------");
                        //flag=0,说明没 匹配上,也要把患者说的话记录下来
                        if (j == ivrTaskTemplateScriptVO.getIvrTaskScriptTargetoptionList().size() - 1 && flag == 0) {
                            ServiceSubTaskDetailReq serviceSubTaskDetailReq = new ServiceSubTaskDetailReq();
@@ -1456,6 +1460,7 @@
                }
                //都没有匹配到
                if (StringUtils.isEmpty(phoneCallBackYQVO.getValue())) {
                    log.info("都没有匹配到-------------------------");
                    Integer count = null;
                    Object countObj = redisCache.getCacheObject(phoneCallReqYQVO.getTaskid().trim() + "&&" + "mate" + "&&" + phoneCallReqYQVO.getUuid());
                    if (ObjectUtils.isNotEmpty(countObj)) count = (Integer) countObj;
@@ -1486,9 +1491,11 @@
                            //去redis中,把该子任务ID删除
                            Long id = serviceSubtask.getId();
                            Map<String, String> map = delRedisValue(null, id.toString());
                            redisCache.setCacheObject(map.get("cacheName"), map.get("val"));
                            redisCache.deleteObject(serviceSubtask.getId() + "-" + serviceSubtask.getPhone());
                            redisCache.deleteObject(phoneCallReqYQVO.getUuid() + "SCORE");
                            if (ObjectUtils.isNotEmpty(map)) {
                                redisCache.setCacheObject(map.get("cacheName"), map.get("val"));
                                redisCache.deleteObject(serviceSubtask.getId() + "-" + serviceSubtask.getPhone());
                                redisCache.deleteObject(phoneCallReqYQVO.getUuid() + "SCORE");
                            }
//                            return phoneCallBackYQVO;
                        } else {
                            //根据ivrTaskTemplateScriptVO.getNextScriptno()获取下一题进行提问
@@ -1496,7 +1503,7 @@
                                if (script.getSort() == ivrTaskTemplateScriptVO.getNextScriptno().intValue()) {
                                    phoneCallBackYQVO.setType("text");
                                    phoneCallBackYQVO.setSilent_interval(ivrTaskTemplate.getSilencetime().intValue());
                                    String scriptContent = script.getIvrtext();
                                    String scriptContent = StringUtils.isNotEmpty(script.getIvrtext()) ? script.getIvrtext() : script.getScriptContent();
                                    phoneCallBackYQVO.setValue(phoneCallBackYQVO.getCommonValue() + getObject(serviceSubtask, scriptContent));
                                    //将该患者的Redis中的题目ID,进行修改
                                    redisCache.setCacheObject(phoneCallReqYQVO.getTaskid().trim() + "-" + phoneCallReqYQVO.getPhone().trim(), script.getId().toString(), 120, TimeUnit.MINUTES);
@@ -1550,7 +1557,8 @@
                        if (ivrTaskTemplateScriptVO.getNextScriptno().intValue() == ivrTaskTemplateScript1.getSort()) {
                            phoneCallBackYQVO.setType("text");
                            phoneCallBackYQVO.setSilent_interval(ivrTaskTemplate.getSilencetime().intValue());
                            String scriptContent = ivrTaskTemplateScript1.getIvrtext();
                            String scriptContent = StringUtils.isNotEmpty(ivrTaskTemplateScript1.getIvrtext()) ? ivrTaskTemplateScript1.getIvrtext() : ivrTaskTemplateScript1.getScriptContent();
                            phoneCallBackYQVO.setValue(phoneCallBackYQVO.getCommonValue() + getObject(serviceSubtask, scriptContent));
                            redisCache.deleteObject(phoneCallReqYQVO.getTaskid().trim() + "&&" + "mate" + "&&" + phoneCallReqYQVO.getUuid());
                            redisCache.setCacheObject(serviceSubtask.getId() + "-" + serviceSubtask.getPhone(), ivrTaskTemplateScript1.getId().toString());
@@ -1603,6 +1611,9 @@
            for (String key : map.keySet()) {
                scriptContent = scriptContent.replace(key, StringUtils.isNotEmpty(map.get(key)) ? map.get(key) : "");
            }
        }
        if (StringUtils.isEmpty(scriptContent)) {
            return scriptContent;
        }
        scriptContent = scriptContent.replace("${name}", StringUtils.isNotEmpty(serviceSubtask.getSendname()) ? serviceSubtask.getSendname() : "");
        scriptContent = scriptContent.replace("${dzz}", StringUtils.isNotEmpty(serviceSubtask.getAddr()) ? serviceSubtask.getAddr() : "");
@@ -1676,10 +1687,9 @@
        //必须等ache-exist全部打完才能拉取下一批(主要是怕所有的数据都堆在电话的缓存里,在规定的时间打不完)
        long existSize = listOps.size("cache-exist");
        if (existSize > 0) return pullTaskVOList;
        int count = 0;
        long size = listOps.size("cache-0");
        log.error("---------打电话之前缓存中的数据量:{}", size);
        int count = 0;
        if (size > 0) {
            //phoneCount()  通过给出的每个小时需要打出的电话量,算出到晚上8点一点能打出多少个电话,获取到总量
            //如果需要立即执行的数据量大于一天要执行的上限,则只取上限的数量,其它的则放回redis中
@@ -1688,6 +1698,7 @@
                cacheList = listOps.range("cache-0", 0, count - 1);
            }
        }
        log.error("任务拉取cache-0的值是多少:{}", cacheList);
        //  cache-0为立即发起的,其它的先推迟
@@ -1699,17 +1710,21 @@
        } else {
            for (int i = 1; i < 6; i++) {
                //取出从cache-1 到 cache-5的第一个子任务信息
                Long size1 = listOps.size("cache-" + i);
                if (size1 == null || size1 == 0) continue;
                int count1 = Math.min(phoneCount(), size1.intValue());
                List<String> value = listOps.range("cache-0" + i, 0, count1 - 1);
                try {
                    Long size1 = listOps.size("cache-" + i);
                    if (size1 == null || size1 == 0) continue;
                    int count1 = Math.min(phoneCount(), size1.intValue());
                    List<String> value = listOps.range("cache-0" + i, 0, count1 - 1);
                List<PullTaskVO> pullTaskVOList2 = getPullTaskList(value, "cache-" + i);
                if (CollectionUtils.isNotEmpty(pullTaskVOList2) && pullTaskVOList2.size() > 0) {
                    pullTaskVOList.addAll(pullTaskVOList2);
                    List<PullTaskVO> pullTaskVOList2 = getPullTaskList(value, "cache-" + i);
                    if (CollectionUtils.isNotEmpty(pullTaskVOList2) && pullTaskVOList2.size() > 0) {
                        pullTaskVOList.addAll(pullTaskVOList2);
                    }
                    //将处理过的数据删除
                    listOps.trim("cache-0" + i, count1, -1);
                } catch (Exception e) {
//                    log.error("看着烦");
                }
                //将处理过的数据删除
                listOps.trim("cache-0" + i, count1, -1);
            }
        }
        //existList用来记录接下来需要执行的子任务ID
@@ -2068,7 +2083,7 @@
                    ServiceSubtaskDetail ssd = new ServiceSubtaskDetail();
                    ssd.setSubId(serviceSubtaskDetail.getSubId());
                    ssd.setTaskid(serviceSubtaskDetail.getTaskid());
                    ssd.setTemplatequestionnum(serviceSubtaskDetail.getTemplatequestionnum());
                    ssd.setScriptid(serviceSubtaskDetail.getScriptid());
                    if (serviceSubtaskDetail.getSubId() != null) {
                        ServiceSubtask serviceSubtask = serviceSubtaskMapper.selectServiceSubtaskById(serviceSubtaskDetail.getSubId());
                        ssd.setGuid(serviceSubtask.getGuid());
@@ -2194,6 +2209,23 @@
                continue;
            }
            ServiceSubtaskStatistic statistic = getStatistic(serviceSubtaskList);
            //及时率
            ServiceSubtask ss = new ServiceSubtask();
            ss.setOrgid(serviceSubtaskList.get(0).getOrgid());
            if (CollectionUtils.isNotEmpty(serviceSubtaskCountReq.getLeavehospitaldistrictcodes())) {
                ss.setLeavehospitaldistrictcode(serviceSubtaskList.get(0).getLeavehospitaldistrictcode());
            } else {
                ss.setDeptcode(serviceSubtaskList.get(0).getDeptcode());
            }
            ss.setStarttime(serviceSubtaskCountReq.getStartTime());
            ss.setEndtime(serviceSubtaskCountReq.getEndTime());
            if (serviceSubtaskCountReq.getEndTime() != null && new Date().before(serviceSubtaskCountReq.getEndTime())) {
                ss.setEndtime(new Date());
            }
            Double jsRate = serviceSubtaskMapper.selectTimelyRate(ss);
            statistic.setRate(jsRate);
            if (ObjectUtils.isNotEmpty(statistic)) {
                serviceSubtaskStatistics.add(statistic);
            }
@@ -2220,6 +2252,7 @@
            if (serviceSubtask.getSendstate() != null && serviceSubtask.getSendstate() != 4) {
                serviceSubtaskStatistic.setFollowUpNeeded(serviceSubtaskStatistic.getFollowUpNeeded() + 1L);
            }
            //首次出院随访
            if (serviceSubtask.getVisitCount() != null && serviceSubtask.getVisitCount() == 1) {
                if (serviceSubtask.getSendstate() != null && serviceSubtask.getSendstate() != 4) {
@@ -2288,48 +2321,6 @@
        }
        /*serviceSubtaskStatistic.setServiceCount(serviceSubtaskList.size());
        for (ServiceSubtask serviceSubtask : serviceSubtaskList) {
            //不随访数量
            if (serviceSubtask.getSendstate() != null && serviceSubtask.getSendstate() == 4) {
                serviceSubtaskStatistic.setBzxCount(serviceSubtaskStatistic.getBzxCount() + 1L);
            }
            //应随访数量
            if (serviceSubtask.getSendstate() != null && serviceSubtask.getSendstate() != 4) {
                serviceSubtaskStatistic.setYsfCount(serviceSubtaskStatistic.getYsfCount() + 1L);
            }
            //发送失败数量
            if (serviceSubtask.getSendstate() != null && serviceSubtask.getSendstate() == 5) {
                serviceSubtaskStatistic.setFssbCount(serviceSubtaskStatistic.getFssbCount() + 1L);
            }
            //待发送数量
            if (serviceSubtask.getSendstate() != null && serviceSubtask.getSendstate() == 2) {
                serviceSubtaskStatistic.setDfsCount(serviceSubtaskStatistic.getDfsCount() + 1L);
            }
            //已发送数量
            if (serviceSubtask.getSendstate() != null && serviceSubtask.getSendstate() == 3) {
                serviceSubtaskStatistic.setYfsCount(serviceSubtaskStatistic.getYfsCount() + 1L);
            }
            //已完成数量
            if (serviceSubtask.getSendstate() != null && serviceSubtask.getSendstate() == 6) {
                //已发送,包含已完成
                serviceSubtaskStatistic.setYfsCount(serviceSubtaskStatistic.getYfsCount() + 1L);
                serviceSubtaskStatistic.setYwcCount(serviceSubtaskStatistic.getYwcCount() + 1L);
            }
            if (StringUtils.isNotEmpty(serviceSubtask.getExcep()) && serviceSubtask.getExcep().equals("1")) {
                //异常标识
                serviceSubtaskStatistic.setYczs(serviceSubtaskStatistic.getYczs() + 1L);
            }
        }
        //随访完成率=已完成/应随访量
        if (serviceSubtaskStatistic.getYwcCount() == 0 || CollectionUtils.isEmpty(serviceSubtaskList)) {
            serviceSubtaskStatistic.setSfwcl("0");
        } else {
//            BigDecimal multiply = BigDecimal.valueOf(serviceSubtaskStatistic.getYfsCount()).divide(BigDecimal.valueOf(serviceSubtaskList.size()), 2, BigDecimal.ROUND_HALF_UP);
            BigDecimal multiply = new BigDecimal(serviceSubtaskStatistic.getYwcCount().toString()).divide(new BigDecimal(serviceSubtaskStatistic.getYsfCount().toString()), 2, BigDecimal.ROUND_HALF_UP);
            serviceSubtaskStatistic.setSfwcl(multiply.toString());
        }*/
        return serviceSubtaskStatistic;
@@ -2347,6 +2338,8 @@
    }
    private ServiceSubtaskDetail getServiceSubtaskDetail(PhoneCallReqYQVO phoneCallReqYQVO, IvrTaskTemplateScriptVO ivrTaskTemplateScriptVO, ServiceSubtask serviceSubtask, IvrTaskTemplate ivrTaskTemplate) {
        log.info("-----------------phoneCallReqYQVO的值为:{}", phoneCallReqYQVO);
        ServiceSubtaskDetail serviceSubtaskDetail = new ServiceSubtaskDetail();
        serviceSubtaskDetail.setSubId(Long.valueOf(phoneCallReqYQVO.getTaskid()));
        ServiceSubtask serviceSubtask1 = serviceSubtaskMapper.selectServiceSubtaskById(Long.valueOf(phoneCallReqYQVO.getTaskid()));
@@ -2370,7 +2363,7 @@
        serviceSubtaskDetail.setSentEnd(1L);
        serviceSubtaskDetail.setTemplateid(ivrTaskTemplate.getId().toString());
        serviceSubtaskDetail.setTemplatequestionnum(ivrTaskTemplateScriptVO.getScriptno());
        serviceSubtaskDetail.setQuestiontext(ivrTaskTemplateScriptVO.getIvrtext());
        serviceSubtaskDetail.setQuestiontext(StringUtils.isNotEmpty(ivrTaskTemplateScriptVO.getIvrtext()) ? ivrTaskTemplateScriptVO.getIvrtext() : ivrTaskTemplateScriptVO.getScriptContent());
        serviceSubtaskDetail.setQuestionvoice(phoneCallReqYQVO.getRecordpath());
        serviceSubtaskDetail.setCategoryname(ivrTaskTemplateScriptVO.getScriptType());
        serviceSubtaskDetail.setTargetoptions(ivrTaskTemplateScriptVO.getTargetOptions());