package com.whdc.controller; import cn.hutool.http.HttpResponse; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.itextpdf.io.font.PdfEncodings; import com.itextpdf.kernel.font.PdfFont; import com.itextpdf.kernel.font.PdfFontFactory; import com.whdc.model.dto.AutoCallDto; import com.whdc.model.dto.CallPutDto; 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; 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.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 doCallTest() throws ParseException { autoCallTaskService.generateFakeCall(); return ResultJson.ok("resp"); } @GetMapping("/doGenerateTest2") public ResultJson doGenerateTest2() throws ParseException { autoCallTaskService2.generateFakeCall(); return ResultJson.ok("resp"); } @GetMapping("/doCallTest2") public ResultJson> doCallTest2() throws ParseException { List personList = autoCallTaskService2.doCallTest(); return ResultJson.ok(personList); } @GetMapping("/getToken") public ResultJson getToken() { return ResultJson.ok(autoCallTaskService.getToken()); } @GetMapping("/queryTaskResult") public ResultJson queryTaskResult(@RequestParam("requestId") String requestId, @RequestParam("custId") String custId) { return ResultJson.ok(autoCallTaskService.queryTaskResult(requestId, custId)); } @PostMapping("/page") public ResultJson> newList(@RequestBody AutoCallDto dto) { return ResultJson.ok(autoCallApiService.page(dto)); } /** * 查询所有未接通的数据 * @return */ @GetMapping("/listCallIsNotPass") public ResultJson> listCallIsNotPass() { return ResultJson.ok(autoCallApiService.listCallIsNotPass()); } /** * 分页查询所有未接通的数据 * @return */ @GetMapping("/listCallIsNotPassPage") public ResultJson> listCallIsNotPassPage(@RequestBody AutoCallDto dto) { return ResultJson.ok(autoCallApiService.listCallIsNotPassPage(dto)); } @PostMapping("/page2") public ResultJson> page2(@RequestBody AutoCallDto dto) { return ResultJson.ok(autoCallApiService.page2(dto)); } @GetMapping("/listCallIsNotPut") public ResultJson> listCallIsNotPut() { return ResultJson.ok(autoCallApiService.listCallIsNotPut()); } @GetMapping("/isEnable") public ResultJson isEnable() { return ResultJson.ok(autoCallTaskService.isEnable()); } @GetMapping("/setEnable") public ResultJson setEnable(@RequestParam("enable") Boolean enable) { autoCallTaskService.setEnable(enable); return ResultJson.ok(true); } /** * 根据ID关闭预警 * @param taskId * @return */ @GetMapping("/setCallIsPut") public ResultJson setCallIsPut(@RequestParam("taskId") Integer taskId) { autoCallTaskService.setCallIsPut(taskId); return ResultJson.ok(true); } /** * 预警的批量关闭 * @param dto * @return */ @PostMapping("/setCallIsPutList") public ResultJson setCallIsPutList(@RequestBody CallPutDto dto) { autoCallTaskService.setCallIsPutList(dto); return ResultJson.ok(true); } @PostMapping("/exportPdf") public void exportPDF(@RequestBody AutoCallDto dto, HttpServletResponse response, HttpServletRequest request) { Page autoCallTaskPage = autoCallApiService.page3(dto); List 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); } } }