fxkh-txl-service/src/main/java/com/whdc/controller/AutoCallController.java

136 lines
5.0 KiB
Java
Raw Normal View History

2025-07-14 11:23:11 +08:00
package com.whdc.controller;
2025-07-23 09:45:10 +08:00
import cn.hutool.http.HttpResponse;
2025-07-14 11:23:11 +08:00
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
2025-07-23 09:45:10 +08:00
import com.itextpdf.io.font.PdfEncodings;
import com.itextpdf.kernel.font.PdfFont;
import com.itextpdf.kernel.font.PdfFontFactory;
2025-07-14 11:23:11 +08:00
import com.whdc.model.dto.AutoCallDto;
import com.whdc.model.entity.AutoCallPerson;
import com.whdc.model.entity.AutoCallTask;
import com.whdc.model.entity.WarnCallMap;
import com.whdc.service.AutoCallApiService;
import com.whdc.service.AutoCallTaskService;
import com.whdc.service.AutoCallTaskService2;
import com.whdc.utils.ResultJson;
2025-07-23 09:45:10 +08:00
import org.apache.poi.util.IOUtils;
2025-07-14 11:23:11 +08:00
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
2025-07-23 09:45:10 +08:00
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.net.URLEncoder;
2025-07-14 11:23:11 +08:00
import java.text.ParseException;
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("/doCallTest2")
public ResultJson<List<AutoCallPerson>> doCallTest2() throws ParseException {
List<AutoCallPerson> personList = autoCallTaskService2.doCallTest();
return ResultJson.ok(personList);
}
@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));
}
@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("/setCallIsPut")
public ResultJson<Boolean> setCallIsPut(@RequestParam("taskId") Integer taskId) {
autoCallTaskService.setCallIsPut(taskId);
return ResultJson.ok(true);
}
2025-07-23 09:45:10 +08:00
@PostMapping("/exportPdf")
public void exportPDF(@RequestBody AutoCallDto dto,
HttpServletResponse response,
HttpServletRequest request) {
Page<AutoCallTask> autoCallTaskPage = autoCallApiService.page3(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);
}
}
2025-07-14 11:23:11 +08:00
}