244 lines
9.8 KiB
Java
244 lines
9.8 KiB
Java
package com.whdc.controller;
|
||
|
||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||
import com.whdc.mapper.WarningResponderMapper;
|
||
import com.whdc.model.dto.AutoCallDto;
|
||
import com.whdc.model.dto.CallPutDto;
|
||
import com.whdc.model.dto.FindPageDto;
|
||
import com.whdc.model.entity.AutoCallPerson;
|
||
import com.whdc.model.entity.AutoCallTask;
|
||
import com.whdc.model.entity.WarnCallMap;
|
||
import com.whdc.model.entity.WarningResponder;
|
||
import com.whdc.service.AutoCallApiService;
|
||
import com.whdc.service.AutoCallTaskService;
|
||
import com.whdc.service.AutoCallTaskService2;
|
||
import com.whdc.utils.ResultJson;
|
||
import com.whdc.utils.SmsHelper;
|
||
import org.apache.poi.util.IOUtils;
|
||
import org.springframework.beans.factory.annotation.Autowired;
|
||
import org.springframework.web.bind.annotation.*;
|
||
|
||
import javax.servlet.http.HttpServletRequest;
|
||
import javax.servlet.http.HttpServletResponse;
|
||
import java.io.ByteArrayInputStream;
|
||
import java.io.IOException;
|
||
import java.net.URLEncoder;
|
||
import java.text.ParseException;
|
||
import java.util.ArrayList;
|
||
import java.util.Collections;
|
||
import java.util.List;
|
||
|
||
/**
|
||
* @author lyf
|
||
* @since 2025-06-17
|
||
*/
|
||
@RestController
|
||
@RequestMapping("/autocall")
|
||
public class AutoCallController {
|
||
@Autowired
|
||
private AutoCallApiService autoCallApiService;
|
||
@Autowired
|
||
private AutoCallTaskService autoCallTaskService;
|
||
@Autowired
|
||
private AutoCallTaskService2 autoCallTaskService2;
|
||
|
||
@GetMapping("/doCallTest")
|
||
public ResultJson<String> doCallTest() throws ParseException {
|
||
autoCallTaskService.generateFakeCall();
|
||
return ResultJson.ok("resp");
|
||
}
|
||
|
||
@GetMapping("/doGenerateTest2")
|
||
public ResultJson<String> doGenerateTest2() throws ParseException {
|
||
autoCallTaskService2.generateFakeCall();
|
||
return ResultJson.ok("resp");
|
||
}
|
||
|
||
@GetMapping("/getToken")
|
||
public ResultJson<String> getToken() {
|
||
return ResultJson.ok(autoCallTaskService.getToken());
|
||
}
|
||
|
||
@GetMapping("/queryTaskResult")
|
||
public ResultJson<String> queryTaskResult(@RequestParam("requestId") String requestId, @RequestParam("custId") String custId) {
|
||
return ResultJson.ok(autoCallTaskService.queryTaskResult(requestId, custId));
|
||
}
|
||
|
||
@PostMapping("/page")
|
||
public ResultJson<Page<WarnCallMap>> newList(@RequestBody AutoCallDto dto) {
|
||
return ResultJson.ok(autoCallApiService.page(dto));
|
||
}
|
||
|
||
/**
|
||
* 查询所有未接通的数据
|
||
* @return
|
||
*/
|
||
@GetMapping("/listCallIsNotPass")
|
||
public ResultJson<List<AutoCallTask>> listCallIsNotPass() {
|
||
return ResultJson.ok(autoCallApiService.listCallIsNotPass());
|
||
}
|
||
|
||
/**
|
||
* 分页查询所有未接通的数据
|
||
* @return
|
||
*/
|
||
@GetMapping("/listCallIsNotPassPage")
|
||
public ResultJson<Page<AutoCallTask>> listCallIsNotPassPage(@RequestBody AutoCallDto dto) {
|
||
return ResultJson.ok(autoCallApiService.listCallIsNotPassPage(dto));
|
||
}
|
||
|
||
@PostMapping("/page2")
|
||
public ResultJson<Page<AutoCallTask>> page2(@RequestBody AutoCallDto dto) {
|
||
return ResultJson.ok(autoCallApiService.page2(dto));
|
||
}
|
||
|
||
@GetMapping("/listCallIsNotPut")
|
||
public ResultJson<List<WarnCallMap>> listCallIsNotPut() {
|
||
return ResultJson.ok(autoCallApiService.listCallIsNotPut());
|
||
}
|
||
|
||
@GetMapping("/isEnable")
|
||
public ResultJson<Boolean> isEnable() {
|
||
return ResultJson.ok(autoCallTaskService.isEnable());
|
||
}
|
||
|
||
@GetMapping("/setEnable")
|
||
public ResultJson<Boolean> setEnable(@RequestParam("enable") Boolean enable) {
|
||
autoCallTaskService.setEnable(enable);
|
||
return ResultJson.ok(true);
|
||
}
|
||
|
||
@GetMapping("/manualClose")
|
||
public ResultJson<Boolean> manualClose(@RequestParam("taskId") Integer taskId, @RequestParam("personId") Integer personId) {
|
||
return ResultJson.ok(autoCallTaskService2.manualClose(taskId, personId));
|
||
}
|
||
|
||
/**
|
||
* 根据ID关闭预警
|
||
* @param taskId
|
||
* @return
|
||
*/
|
||
@Deprecated
|
||
@GetMapping("/setCallIsPut")
|
||
public ResultJson<Boolean> setCallIsPut(@RequestParam("taskId") Integer taskId) {
|
||
autoCallTaskService.setCallIsPut(taskId);
|
||
return ResultJson.ok(true);
|
||
}
|
||
|
||
/**
|
||
* 预警的批量关闭
|
||
* @param dto
|
||
* @return
|
||
*/
|
||
@Deprecated
|
||
@PostMapping("/setCallIsPutList")
|
||
public ResultJson<Boolean> setCallIsPutList(@RequestBody CallPutDto dto) {
|
||
autoCallTaskService.setCallIsPutList(dto);
|
||
return ResultJson.ok(true);
|
||
}
|
||
|
||
@PostMapping("/exportPdf")
|
||
public void exportPDF(@RequestBody AutoCallDto dto,
|
||
HttpServletResponse response,
|
||
HttpServletRequest request) {
|
||
Page<AutoCallTask> autoCallTaskPage = autoCallApiService.pageForPdf(dto);
|
||
List<AutoCallTask> records = autoCallTaskPage.getRecords();
|
||
ByteArrayInputStream pdfStream = autoCallApiService.exportPDF(records, response, dto.getStm(), dto.getEtm());
|
||
// 3. 设置响应头
|
||
try {
|
||
// 设置响应头
|
||
response.setContentType("application/pdf");
|
||
String fileName = "智能呼叫记录_" + dto.getStm().toString().replace(":", "-") + "_to_"
|
||
+ dto.getEtm().toString().replace(":", "-") + ".pdf";
|
||
|
||
// 获取User-Agent判断浏览器类型
|
||
String userAgent = request.getHeader("User-Agent");
|
||
|
||
// 针对不同浏览器设置不同的Content-Disposition
|
||
if (userAgent != null && userAgent.toLowerCase().contains("firefox")) {
|
||
// Firefox浏览器
|
||
response.setHeader("Content-Disposition",
|
||
"attachment; filename*=UTF-8''" + URLEncoder.encode(fileName, "UTF-8"));
|
||
} else {
|
||
// 其他浏览器(Chrome, Edge, Safari等)
|
||
response.setHeader("Content-Disposition",
|
||
"attachment; filename=\"" + new String(fileName.getBytes("GBK"), "ISO-8859-1") + "\"");
|
||
}
|
||
IOUtils.copy(pdfStream,response.getOutputStream());
|
||
response.flushBuffer();
|
||
} catch (IOException e) {
|
||
throw new RuntimeException(e);
|
||
}
|
||
}
|
||
|
||
@GetMapping("/getPdf")
|
||
//{"etm":"2025-08-07","stm":"2025-07-31","page":{"pageNumber":1,"pageSize":20}}
|
||
public void getPdf(@RequestParam("stm")String stm, @RequestParam("etm")String etm, HttpServletResponse response,
|
||
HttpServletRequest request) {
|
||
AutoCallDto dto = new AutoCallDto();
|
||
dto.setStm(stm);
|
||
dto.setEtm(etm);
|
||
dto.setPage(new FindPageDto());
|
||
Page<AutoCallTask> autoCallTaskPage = autoCallApiService.pageForPdf(dto);
|
||
List<AutoCallTask> records = autoCallTaskPage.getRecords();
|
||
ByteArrayInputStream pdfStream = autoCallApiService.exportPDF(records, response, dto.getStm(), dto.getEtm());
|
||
// 3. 设置响应头
|
||
try {
|
||
// 设置响应头
|
||
response.setContentType("application/pdf");
|
||
String fileName = "智能呼叫记录_" + dto.getStm().toString().replace(":", "-") + "_to_"
|
||
+ dto.getEtm().toString().replace(":", "-") + ".pdf";
|
||
|
||
// 获取User-Agent判断浏览器类型
|
||
String userAgent = request.getHeader("User-Agent");
|
||
|
||
// 针对不同浏览器设置不同的Content-Disposition
|
||
if (userAgent != null && userAgent.toLowerCase().contains("firefox")) {
|
||
// Firefox浏览器
|
||
response.setHeader("Content-Disposition",
|
||
"attachment; filename*=UTF-8''" + URLEncoder.encode(fileName, "UTF-8"));
|
||
} else {
|
||
// 其他浏览器(Chrome, Edge, Safari等)
|
||
response.setHeader("Content-Disposition",
|
||
"attachment; filename=\"" + new String(fileName.getBytes("GBK"), "ISO-8859-1") + "\"");
|
||
}
|
||
IOUtils.copy(pdfStream,response.getOutputStream());
|
||
response.flushBuffer();
|
||
} catch (IOException e) {
|
||
throw new RuntimeException(e);
|
||
}
|
||
}
|
||
|
||
@GetMapping("/newPerson")
|
||
public ResultJson newPerson(@RequestParam("taskId")Integer taskId) {
|
||
AutoCallTask task = autoCallTaskService2.getTaskMapper().selectById(taskId);
|
||
return ResultJson.ok(autoCallTaskService2.newPerson(task));
|
||
}
|
||
|
||
@GetMapping("/getUploadedPerson")
|
||
public ResultJson getUploadedPerson() {
|
||
return ResultJson.ok(autoCallTaskService2.step2GetOneUnUploadedPerson());
|
||
}
|
||
// @Autowired
|
||
// private WarningResponderMapper wrm;
|
||
// @Autowired
|
||
// private SmsHelper smsHelper;
|
||
// @GetMapping("/temp")
|
||
// public ResultJson temp() {
|
||
// String content = "领导您好!省防汛抗旱指挥部办公室将于8月7日启用预警叫应智能外呼系统。收到橙色以上气象预警后,系统将自动根据预警级别叫应相关责任人,来电显示“省防办值班室”,电话接通后,系统将播报AI预警信息并询问“如您已知晓上述信息,请按#号键”。请领导在收到预警叫应后,收听完整预警信息并根据语音提示按“#”号键进行确认。若未完成操作,系统将在1分钟内重拨,两次失败后将呼叫上一级责任人。特此报告。\n" +
|
||
// "\n" +
|
||
// "湖北省防汛抗旱指挥部办公室\n" +
|
||
// "2025年8月6日";
|
||
// List<WarningResponder> wrs = wrm.selectList(new QueryWrapper<WarningResponder>()
|
||
// .ge("level", 0));
|
||
// List<String> ret = new ArrayList<>();
|
||
// wrs.forEach(wr -> {
|
||
// wr.decryptPhone();
|
||
// String s = smsHelper.send(Collections.singletonList(wr.getPhone()), content);
|
||
// ret.add(wr.getPhone() + "-" + s);
|
||
// });
|
||
// return ResultJson.ok(wrs);
|
||
// }
|
||
}
|