zhongrj
2023-04-28 d2f2faf246d45c7bbb0daccbbe005fab4597eb86
skjcmanager/skjcmanager-service/skjcmanager-sm/src/main/java/cn/gistack/sm/intelligentCall/service/impl/CallServiceImpl.java
@@ -1,9 +1,14 @@
package cn.gistack.sm.intelligentCall.service.impl;
import cn.gistack.sm.intelligentCall.constant.CallConstant;
import cn.gistack.sm.intelligentCall.mapper.CallTaskMapper;
import cn.gistack.sm.intelligentCall.service.CallService;
import cn.gistack.sm.intelligentCall.vo.CallTaskResultVO;
import cn.gistack.sm.intelligentCall.vo.CallTaskStatistic;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.dynamic.datasource.annotation.DS;
import com.baomidou.mybatisplus.core.metadata.IPage;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.RandomUtils;
import org.apache.commons.lang3.StringUtils;
@@ -15,15 +20,18 @@
import org.springframework.stereotype.Service;
import org.springframework.util.DigestUtils;
import org.springframework.web.client.RestTemplate;
import javax.annotation.Resource;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
@Slf4j
@Service
public class CallServiceImpl implements CallService {
   @Autowired
   private CallTaskMapper callTaskMapper;
   @Autowired
   private RestTemplate restTemplate;
@@ -53,16 +61,23 @@
   private final static String CREATE_TASK_URL = "/api/task/createTask.json";
   private final static String CALL_DETAIL_URL = "/api/task/callDetail.json";
   /**
    * 创建任务
    * @param map
    * @return
    */
   @Override
   public void createTask(List<Map<String, String>> params) {
   public Object createTask(Map<String,Object> map) {
      List<Map<String, String>> params = (List<Map<String, String>>) map.get("list");
      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")) + "智能外呼";
//      String taskName = now.format(DateTimeFormatter.ofPattern("yyyy年MM月dd日HH:mm")) + "智能外呼";
      String 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"));
      System.out.println("taskScheduleTime = " + taskScheduleTime);
//      String taskScheduleTime = LocalDateTime.now().plusHours(1).format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"));
      String taskScheduleTime = map.get("taskScheduleTime").toString();
      JSONArray arr = getCalleeInfo(params);
      HttpHeaders httpHeaders = new HttpHeaders();
      httpHeaders.add("Content-Type", CONTENT_TYPE);
@@ -91,8 +106,15 @@
      if (response.getStatusCode() != HttpStatus.OK) {
         log.error("创建智能外呼任务失败:{}", response.getStatusCode());
      }
      return response;
   }
   /**
    * 获取通话详情
    * @param taskId
    * @param calleeNumber
    * @return
    */
   @Override
   public Object getCallDetail(String taskId, String calleeNumber) {
      String requestUrl = url + CALL_DETAIL_URL;
@@ -116,7 +138,7 @@
         JSONObject responseJson = (JSONObject) JSONObject.parse(response.getBody());
         assert responseJson != null;
//         return JSONObject.parseObject(responseJson.getString("data"), CallBackDetailVO.class);
         return responseJson.getString("data");
         return response.getBody();
      }
      return null;
   }
@@ -169,4 +191,69 @@
      });
      return arr;
   }
   /**
    * 查詢任务列表数据
    * @param page
    * @param callTask
    * @return
    */
   @Override
   public IPage<CallTaskStatistic> getCallListPage(IPage<CallTaskStatistic> page, CallTaskStatistic callTask) {
      return page.setRecords(callTaskMapper.getCallListPage(page,callTask));
   }
   /**
    * 查询呼叫详情列表信息
    * @param callTaskResult
    * @param page
    * @return
    */
   @Override
   public IPage<CallTaskResultVO> getCallTaskResultListPage(IPage<CallTaskResultVO> page, CallTaskResultVO callTaskResult) {
      List<String> list = new ArrayList<>();
      if (null!= callTaskResult.getAreaName() && !callTaskResult.getAreaName().equals("")){
         // 查询所有下级区域code
         list = getWaterNameByAreaCode(callTaskResult.getAreaName());
      }
      List<CallTaskResultVO> resultListPage = callTaskMapper.getCallTaskResultListPage(page, callTaskResult,list);
      return page.setRecords(resultListPage);
   }
   /**
    * 导出呼叫详情列表信息
    * @param callTaskResult
    * @return
    */
   @Override
   public Object getCallTaskResultList(CallTaskResultVO callTaskResult) {
      List<String> list = new ArrayList<>();
      if (null!= callTaskResult.getAreaName() && !callTaskResult.getAreaName().equals("")){
         // 查询所有下级区域code
         list = getWaterNameByAreaCode(callTaskResult.getAreaName());
      }
      List<CallTaskResultVO> resultListPage = callTaskMapper.getCallTaskResultListPage(null, callTaskResult,list);
      // 返回
      return resultListPage;
   }
   /**
    * 通过水库编码获取行政区名称
    * @param adCode
    * @return
    */
   private String getAreaNameByAdCode(String adCode) {
      // 通过adCode查询区域名称
      return callTaskMapper.getAreaNameByAdCode(adCode);
   }
   /**
    * 通过行政区编号获取水库名称
    * @param areaCode
    * @return
    */
   private List<String> getWaterNameByAreaCode(String areaCode) {
      // 通过行政区编号获取水库名称
      return callTaskMapper.getWaterNameByAreaCode(areaCode);
   }
}