| | |
| | | package cn.gistack.sm.intelligentCall.controller; |
| | | |
| | | import cn.gistack.sm.intelligentCall.constant.CallConstant; |
| | | import cn.gistack.sm.intelligentCall.entity.User; |
| | | import cn.gistack.sm.intelligentCall.util.HttpClientUtils; |
| | | import com.alibaba.fastjson.JSON; |
| | | import cn.gistack.sm.intelligentCall.entity.CallTaskResult; |
| | | import cn.gistack.sm.intelligentCall.entity.Scene; |
| | | import cn.gistack.sm.intelligentCall.excel.CallExcel; |
| | | import cn.gistack.sm.intelligentCall.listener.ExcelListener; |
| | | import cn.gistack.sm.intelligentCall.service.CallService; |
| | | import cn.gistack.sm.intelligentCall.service.ICallSmsNoticeTaskService; |
| | | import cn.gistack.sm.intelligentCall.vo.CallTaskResultVO; |
| | | import cn.gistack.sm.intelligentCall.vo.CallTaskStatistic; |
| | | import com.alibaba.excel.EasyExcel; |
| | | import io.swagger.annotations.Api; |
| | | import io.swagger.annotations.ApiOperation; |
| | | import lombok.AllArgsConstructor; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.springblade.core.excel.util.ExcelUtil; |
| | | import org.springblade.core.mp.support.Condition; |
| | | import org.springblade.core.mp.support.Query; |
| | | import org.springblade.core.tool.api.R; |
| | | import org.springframework.web.bind.annotation.GetMapping; |
| | | import org.springframework.web.bind.annotation.RequestMapping; |
| | | import org.springframework.web.bind.annotation.RestController; |
| | | import java.security.MessageDigest; |
| | | import java.security.NoSuchAlgorithmException; |
| | | import java.text.SimpleDateFormat; |
| | | import org.springframework.web.bind.annotation.*; |
| | | import org.springframework.web.multipart.MultipartFile; |
| | | |
| | | import javax.servlet.http.HttpServletResponse; |
| | | import java.io.IOException; |
| | | import java.util.*; |
| | | |
| | | /** |
| | |
| | | @AllArgsConstructor |
| | | public class CallController { |
| | | |
| | | /** |
| | | * 创建任务 |
| | | * @return |
| | | */ |
| | | @GetMapping("/createCall2") |
| | | public R createCall2(){ |
| | | String url2 = CallConstant.HOST + CallConstant.createTaskUrl1; |
| | | // 请求2 |
| | | Map<String, Object> map = new HashMap<>(); |
| | | map.put("p2",createCall(url2)); |
| | | // 返回 |
| | | return R.data(map); |
| | | } |
| | | private final CallService callService; |
| | | |
| | | private final ICallSmsNoticeTaskService callSmsNoticeTaskService; |
| | | |
| | | /** |
| | | * 创建任务 |
| | | * @param url |
| | | * @return |
| | | */ |
| | | public String createCall(String url){ |
| | | // 计算token |
| | | Date date = new Date(); |
| | | String dateFormat0 = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(date); |
| | | String dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss SSS").format(date); |
| | | String dateFormats = new SimpleDateFormat("yyyyMMddHHmmssSSS").format(date); |
| | | Random random = new Random(); |
| | | //把随机生成的数字转成字符串 |
| | | String str = String.valueOf(random.nextInt(9)); |
| | | for (int i = 0; i < 5; i++) { |
| | | str += random.nextInt(9); |
| | | } |
| | | String formatString ="appId" + CallConstant.AppKey |
| | | + "timestamp" + dateFormat |
| | | + "transId" + dateFormats |
| | | + str; |
| | | // 请求参数拼接 |
| | | Map<String, Object> map = new HashMap<>(); |
| | | map.put("taskName","测试"); |
| | | map.put("sceneId",1); |
| | | map.put("callingNumbers", Arrays.asList(101,102)); |
| | | map.put("taskScheduleTime",dateFormat0); |
| | | List<User> list = new ArrayList<>(); |
| | | User user = new User(); |
| | | user.setName("张三"); |
| | | user.setPhone("15170720695"); |
| | | user.setName("先生"); |
| | | list.add(user); |
| | | map.put("calleeData",list); |
| | | String jsonString = JSON.toJSONString(map); |
| | | String lastString = formatString + jsonString + CallConstant.AppSecret; |
| | | // md5 小写,md5 生成token |
| | | String encryption = encryption(lastString); |
| | | |
| | | String httpPost = HttpClientUtils.httpPost(url, CallConstant.AppKey, dateFormat, dateFormats + str, encryption, map); |
| | | @PostMapping("/createCall") |
| | | public R createCall(@RequestBody Map<String,Object> map){ |
| | | List<String> task = callService.createTask(map); |
| | | // 创建外呼短信发送任务记录 |
| | | createCallSmsNoticeTask(task); |
| | | // 返回 |
| | | return httpPost; |
| | | return R.data(task); |
| | | } |
| | | |
| | | |
| | | |
| | | // /** |
| | | // * 测试 |
| | | // * @param args |
| | | // */ |
| | | // public static void main(String[] args) { |
| | | // // 计算token |
| | | // Date date = new Date(); |
| | | // String dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss SSS").format(date); |
| | | // String dateFormats = new SimpleDateFormat("yyyyMMddHHmmssSSS").format(date); |
| | | // Random random = new Random(); |
| | | // //把随机生成的数字转成字符串 |
| | | // String str = String.valueOf(random.nextInt(9)); |
| | | // for (int i = 0; i < 5; i++) { |
| | | // str += random.nextInt(9); |
| | | // } |
| | | // String formatString ="appId" + CallConstant.AppKey |
| | | // + "timestamp" + dateFormat |
| | | // + "transId" + dateFormats |
| | | // + str; |
| | | // // 请求参数拼接 |
| | | // Map<String, Object> map = new HashMap<>(); |
| | | // map.put("taskName","测试"); |
| | | // map.put("sceneId",1); |
| | | // map.put("callingNumbers", Arrays.asList(101,102)); |
| | | // map.put("taskScheduleTime","2020-02-29 14:00:00"); |
| | | // List<User> list = new ArrayList<>(); |
| | | // User user = new User(); |
| | | // user.setName("张三"); |
| | | // user.setPhone("15170720695"); |
| | | // user.setName("先生"); |
| | | // list.add(user); |
| | | // map.put("calleeData",list); |
| | | // String jsonString = JSON.toJSONString(map); |
| | | // String lastString = formatString + jsonString + CallConstant.AppSecret; |
| | | // // md5 小写,md5 生成token |
| | | // String encryption = encryption(lastString); |
| | | // String url = CallConstant.HOST + CallConstant.createTaskUrl; |
| | | // String httpPost = HttpClientUtils.httpPost(url, CallConstant.AppKey, dateFormat, dateFormats + str, encryption, map); |
| | | // |
| | | // |
| | | // System.out.println("encryption = " + encryption); |
| | | // |
| | | // } |
| | | |
| | | /** |
| | | * md5加密 32位 小写 |
| | | * @param plainText |
| | | * @return |
| | | * 创建外呼短信发送任务记录 |
| | | * @param result |
| | | */ |
| | | public static String encryption(String plainText) { |
| | | String re_md5 = new String(); |
| | | try { |
| | | MessageDigest md = MessageDigest.getInstance("MD5"); |
| | | md.update(plainText.getBytes()); |
| | | byte b[] = md.digest(); |
| | | int i; |
| | | StringBuffer buf = new StringBuffer(""); |
| | | for (int offset = 0; offset < b.length; offset++) { |
| | | i = b[offset]; |
| | | if (i < 0) { |
| | | i += 256; |
| | | } |
| | | if (i < 16) { |
| | | buf.append("0"); |
| | | } |
| | | buf.append(Integer.toHexString(i)); |
| | | private Boolean createCallSmsNoticeTask(List<String> result) { |
| | | Boolean flag = false; |
| | | if (null != result && result.size() > 0) { |
| | | if (result.get(2).equals("true")) { |
| | | // 获取任务id |
| | | String taskId = result.get(1); |
| | | flag = callSmsNoticeTaskService.createCallSmsNoticeTask(taskId); |
| | | } |
| | | re_md5 = buf.toString(); |
| | | } catch (NoSuchAlgorithmException e) { |
| | | } |
| | | return flag; |
| | | } |
| | | |
| | | /** |
| | | * 获取通话详情 |
| | | * @return |
| | | */ |
| | | @GetMapping("/getCallDetail") |
| | | public R getCallDetail(String taskId,String calleeNumber){ |
| | | // 返回 |
| | | return R.data(callService.getCallDetail(taskId,calleeNumber)); |
| | | } |
| | | |
| | | |
| | | /** |
| | | * 查询呼叫列表信息 |
| | | * @param callTask |
| | | * @param query |
| | | * @return |
| | | */ |
| | | @GetMapping("/getCallListPage") |
| | | public R getCallListPage(CallTaskStatistic callTask, Query query){ |
| | | // 返回 |
| | | return R.data(callService.getCallListPage(Condition.getPage(query),callTask)); |
| | | } |
| | | |
| | | |
| | | /** |
| | | * 查询呼叫详情列表信息 |
| | | * @param callTaskResult |
| | | * @param query |
| | | * @return |
| | | */ |
| | | @GetMapping("/getCallTaskResultListPage") |
| | | public R getCallTaskResultListPage(CallTaskResultVO callTaskResult, Query query){ |
| | | // 返回 |
| | | return R.data(callService.getCallTaskResultListPage(Condition.getPage(query),callTaskResult)); |
| | | } |
| | | |
| | | /** |
| | | * 导出呼叫详情列表信息 |
| | | * @param callTaskResult |
| | | * @return |
| | | */ |
| | | @GetMapping("/getCallTaskResultList") |
| | | public R getCallTaskResultList(CallTaskResultVO callTaskResult){ |
| | | // 返回 |
| | | return R.data(callService.getCallTaskResultList(callTaskResult)); |
| | | } |
| | | |
| | | /** |
| | | * 查询智能外呼统计数据-按日期-行政区统计 |
| | | * @param callTaskStatistic |
| | | * @param query |
| | | * @return |
| | | */ |
| | | @GetMapping("/getOutgoingStatisticList") |
| | | public R getOutgoingStatisticList(CallTaskStatistic callTaskStatistic, Query query){ |
| | | // 返回 |
| | | return R.data(callService.getOutgoingStatisticList(Condition.getPage(query),callTaskStatistic)); |
| | | } |
| | | |
| | | /** |
| | | * 查询智能外呼统计数据-行政区统计 |
| | | * @param callTaskStatistic |
| | | * @return |
| | | */ |
| | | @GetMapping("/getOutgoingStatisticByArea") |
| | | public R getOutgoingStatisticByArea(CallTaskStatistic callTaskStatistic){ |
| | | // 返回 |
| | | return R.data(callService.getOutgoingStatisticByArea(callTaskStatistic)); |
| | | } |
| | | |
| | | /** |
| | | * 根据条件自动创建外呼任务 |
| | | * @param params |
| | | * @return |
| | | */ |
| | | @PostMapping("/createCallTaskByParams") |
| | | public R createCallTaskByParam(@RequestBody Map<String, Object> params){ |
| | | // 返回 |
| | | return R.data(callService.createCallTaskByParam(params)); |
| | | } |
| | | |
| | | /** |
| | | * 查询未接通,拒接的呼叫结果详情列表信息 |
| | | * @param callTaskStatistic |
| | | * @param query |
| | | * @return |
| | | */ |
| | | @GetMapping("/getCallNotConnectResultList") |
| | | public R getCallNotConnectResultList(CallTaskStatistic callTaskStatistic, Query query){ |
| | | // 返回 |
| | | return R.data(callService.getCallNotConnectResultList(Condition.getPage(query),callTaskStatistic)); |
| | | } |
| | | |
| | | /** |
| | | * 按日期行政区呼叫结果详情列表信息 |
| | | * @param callTaskStatistic |
| | | * @param query |
| | | * @return |
| | | */ |
| | | @GetMapping("/getCallResultList") |
| | | public R getCallResultList(CallTaskStatistic callTaskStatistic, Query query){ |
| | | // 返回 |
| | | return R.data(callService.getCallResultList(Condition.getPage(query),callTaskStatistic)); |
| | | } |
| | | |
| | | /** |
| | | * 详情导出临时接口 |
| | | * @param callTaskResult |
| | | * @param query |
| | | * @return |
| | | */ |
| | | @GetMapping("/getCallResultListTemp") |
| | | public R getCallResultListTemp(CallTaskResultVO callTaskResult, Query query){ |
| | | // 返回 |
| | | return R.data(callService.getCallResultListTemp(Condition.getPage(query),callTaskResult)); |
| | | } |
| | | |
| | | |
| | | /** |
| | | * 导入表格发送智能外呼 |
| | | * @param file excel文件 |
| | | * @param time 呼叫时间(空的话默认选择当前时间) |
| | | * @return |
| | | */ |
| | | @PostMapping("/import-call") |
| | | public R importCall(MultipartFile file,String time){ |
| | | ExcelListener<CallExcel> listener = new ExcelListener<>(); |
| | | //headRowNumber(1)从第2行开始读取,使用getDatas()方法取出数据 |
| | | try { |
| | | EasyExcel.read(file.getInputStream(), CallExcel.class, listener).headRowNumber(1).sheet(0).doRead(); |
| | | } catch (IOException e) { |
| | | e.printStackTrace(); |
| | | } |
| | | return re_md5; |
| | | List<CallExcel> list = listener.getDatas(); |
| | | // 导入并返回 |
| | | return R.data(callService.importCall(list,time)); |
| | | } |
| | | |
| | | /** |
| | | * 导出模板 |
| | | */ |
| | | @GetMapping("/export-template") |
| | | @ApiOperation(value = "导出模板") |
| | | public void exportTemplate(HttpServletResponse response) { |
| | | List<CallExcel> list = new ArrayList<>(); |
| | | ExcelUtil.export(response, "智能外呼数据模板", "智能外呼数据表", list, CallExcel.class); |
| | | } |
| | | } |