zhongrj
2023-08-09 fd57a072cb58d7a4ff8a142e2585979a4c584b6b
skjcmanager/skjcmanager-service/skjcmanager-sm/src/main/java/cn/gistack/sm/intelligentCall/service/impl/CallServiceImpl.java
@@ -154,6 +154,91 @@
   }
   /**
    * 创建告警外呼任务
    * @param map
    * @return
    */
   @Override
   public List<String> createOutCallTaskByAlarm(Map<String, Object> map) {
      List<Map<String, String>> params = (List<Map<String, String>>) map.get("list");
      JSONArray arr = getCalleeInfoAlarm(params,(List<String>) map.get("titles"));
      String requestUrl = url + CREATE_TASK_URL;
      LocalDateTime now = LocalDateTime.now();
      String timestamp = now.format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss SSS"));
      String transId = generateTransId(now);
      String taskName = now.format(DateTimeFormatter.ofPattern("yyyy年MM月dd日HH:mm:ss")) + "智能外呼";
      if(null!= map.get("taskName") && !map.get("taskName").equals("")){
         taskName = map.get("taskName").toString();
      }
      String[] numbers = StringUtils.split(callingNumbers,",");
      String taskScheduleTime = LocalDateTime.now().plusHours(1).format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"));
      if (null!=map.get("taskScheduleTime") && !map.get("taskScheduleTime").equals("")){
         taskScheduleTime = map.get("taskScheduleTime").toString();
      }
      String scenesIds = scenesId;
      if (null!=map.get("scenesId") && !map.get("scenesId").equals("")){
         scenesIds = map.get("scenesId").toString();
      }
      HttpHeaders httpHeaders = new HttpHeaders();
      httpHeaders.add("Content-Type", CONTENT_TYPE);
      httpHeaders.add("Accept", ACCEPT_TYPE);
      httpHeaders.add("Accept-Encoding", ACCEPT_ENCODING);
      JSONObject paramJson = new JSONObject();
      paramJson.put("taskName", taskName);
      paramJson.put("scenesId", scenesIds);
      paramJson.put("callingNumbers", numbers);
      paramJson.put("taskScheduleTime", taskScheduleTime);
      paramJson.put("calleeData", arr);
      paramJson.put("empId", empId);
      String token = getToken(appId, timestamp, transId, appSecret, paramJson.toJSONString());
      JSONObject headerJson = new JSONObject();
      headerJson.put("appId", appId);
      headerJson.put("timestamp", timestamp);
      headerJson.put("transId", transId);
      headerJson.put("token", token);
      JSONObject bodyJson = new JSONObject();
      bodyJson.put("head", headerJson);
      bodyJson.put("body", paramJson);
      HttpEntity<String> stringHttpEntity = new HttpEntity<>(bodyJson.toJSONString(), httpHeaders);
      log.info("创建超汛限智能外呼任务请求参数:{}", bodyJson.toJSONString());
      ResponseEntity<String> response = restTemplate.postForEntity(requestUrl, stringHttpEntity, String.class);
      log.info("创建外呼任务请求结果:{}", response.getBody());
      if (response.getStatusCode() != HttpStatus.OK) {
         log.error("创建智能外呼任务失败:{}", response.getStatusCode());
      }
      JSONObject jsonObject = JSON.parseObject(response.getBody());
      Boolean success = jsonObject.getBoolean("success");
      String taskId = "";
      if (success){
         //通过任务名称查询taskId
         taskId = callTaskMapper.getTaskIdByTaskName(taskName);
      }
      List<String> list = new ArrayList<>();
      list.add(response.getBody());
      list.add(taskId);
      list.add(success.toString());
      // 返回
      return list;
   }
   /**
    * 外呼动态数据封装
    * @param params
    * @return
    */
   private JSONArray getCalleeInfoAlarm(List<Map<String, String>> params,List<String> titles) {
      JSONArray arr = new JSONArray();
      params.forEach(map -> {
         JSONObject json = new JSONObject();
         for (String title : titles) {
            json.put(title, map.get(title));
         }
         arr.add(json);
      });
      return arr;
   }
   /**
    * 获取通话详情
    * @param taskId
    * @param calleeNumber
@@ -392,21 +477,21 @@
      Integer totalCalleeNumberCount = 0;
      Integer totalConnectionCount = 0;
      Integer totalThreeNoConnectCount = 0;
      Integer totalTwoNoConnectCount = 0;
//      Integer totalTwoNoConnectCount = 0;
      Integer totalRefuseConnectCount = 0;
      // 遍历
      for (CallTaskStatistic taskStatistic : callTaskStatistics) {
         totalCalleeNumberCount += Integer.parseInt(taskStatistic.getCalleeNumberCount());
         totalConnectionCount += Integer.parseInt(taskStatistic.getConnectionCount());
         totalThreeNoConnectCount += taskStatistic.getThreeNoConnectCount();
         totalTwoNoConnectCount += taskStatistic.getTwoNoConnectCount();
//         totalTwoNoConnectCount += taskStatistic.getTwoNoConnectCount();
         totalRefuseConnectCount += taskStatistic.getRefuseConnectCount();
      }
      // 设置数据
      callTaskStatistic.setCalleeNumberCount(totalCalleeNumberCount.toString());
      callTaskStatistic.setConnectionCount(totalConnectionCount.toString());
      callTaskStatistic.setThreeNoConnectCount(totalThreeNoConnectCount);
      callTaskStatistic.setTwoNoConnectCount(totalTwoNoConnectCount);
//      callTaskStatistic.setTwoNoConnectCount(totalTwoNoConnectCount);
      callTaskStatistic.setRefuseConnectCount(totalRefuseConnectCount);
      callTaskStatistic.setCreateTime(callTaskStatistics.get(0).getCreateTime());
      // 查询当前行政区名称
@@ -582,7 +667,46 @@
    */
   @Override
   public Object getOutgoingStatisticByArea(CallTaskStatistic callTaskStatistic) {
      return callTaskMapper.getOutgoingStatisticByArea(callTaskStatistic);
      if (null==callTaskStatistic.getCreateTime() || callTaskStatistic.getCreateTime().equals("")){
         long l = System.currentTimeMillis();
         // 设置当前时间的前一天
         callTaskStatistic.setCreateTime(new SimpleDateFormat("yyyy-MM-dd").format(new Date(l - 60*60*24*1000)));
      }
      if (null==callTaskStatistic.getStartTime() || callTaskStatistic.getStartTime().equals("")){
         long l = System.currentTimeMillis();
         String format = new SimpleDateFormat("yyyy-MM-dd").format(new Date(l - 60 * 60 * 24 * 1000));
         // 设置当前时间的前一天
         callTaskStatistic.setStartTime(format);
         callTaskStatistic.setEndTime(format);
      }
      ThreadPoolExecutor executor = myThreadPoolConfig.threadPoolExecutor();
      callTaskStatistic.setIsPage(1);
      // 异步查询当前天日常呼叫(3次)统计数据
      CompletableFuture<List<CallTaskStatistic>> callTaskStatisticCompletableFuture = getListCompletableFuture(null, callTaskStatistic, executor);
      // 查询当前天除去日常呼叫外的统计数据
      CompletableFuture<List<CallTaskStatistic>> notCallConnect = getListCompletableFuture(callTaskStatistic,executor);
      //等待所有任务执行完成
      try {
         CompletableFuture.allOf(callTaskStatisticCompletableFuture,notCallConnect).get();
         // 数据处理
         List<CallTaskStatistic> callTaskStatistics = getCallTaskStatistics(callTaskStatisticCompletableFuture,null,null,null, notCallConnect,callTaskStatistic);
         // 取当前行政区总数据
//         List<CallTaskStatistic> totalList = getTotalCallTaskStatistics(callTaskStatistics,callTaskStatistic);
         List<CallTaskStatistic> totalList = new ArrayList<>();
         // 排序
         callTaskStatistics = getCallTaskStatisticsByOrder(callTaskStatistic, callTaskStatistics);
         // 合并数据
         totalList.addAll(callTaskStatistics);
         // 返回数据
         return totalList;
      } catch (InterruptedException e) {
         e.printStackTrace();
      } catch (ExecutionException e) {
         e.printStackTrace();
      }
      // 返回
      return null;
//      return callTaskMapper.getOutgoingStatisticByArea(callTaskStatistic);
   }
   /**