xieb
2024-06-19 26aea0b140a7b35bc530abba35c7f308916f2b2c
skjcmanager/skjcmanager-service/skjcmanager-sm/src/main/java/cn/gistack/sm/sjztmd/word/controller/DownTemplateController.java
@@ -2,8 +2,11 @@
import cn.gistack.alerts.sms.feign.ISmsRecordClient;
import cn.gistack.alerts.sms.vo.SmsResultVO;
import cn.gistack.sm.sjztmd.util.MyDateUtils;
import cn.gistack.sm.sjztmd.word.service.ISjztmdService;
import cn.gistack.sm.sjztmd.word.util.BriefReportUtil;
import cn.gistack.sm.sjztmd.word.util.ExcelUtil;
import cn.gistack.sm.sjztmd.word.util.WordUtil;
import cn.gistack.sm.sjztmd.word.vo.*;
@@ -11,6 +14,8 @@
import io.swagger.annotations.Api;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springblade.core.tool.api.R;
import org.springblade.core.tool.utils.DateUtil;
import org.springframework.core.io.InputStreamResource;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
@@ -23,6 +28,8 @@
import java.io.*;
import java.net.URLEncoder;
import java.text.SimpleDateFormat;
import java.time.LocalDate;
import java.time.format.DateTimeFormatter;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
@@ -42,6 +49,14 @@
public class DownTemplateController {
   private final ISjztmdService sjztmdService;
   private final ISmsRecordClient smsRecordClient;
   @GetMapping(value = "/getBriefReport")
   public R getBriefReport() {
      //获取总览、大中库、明细数据
      List<TotalInfo> totalList = sjztmdService.getTotalInfo("");
      return R.data(BriefReportUtil.formatTotalInfo(totalList));
   }
   @GetMapping("/download/{resGuid}")
   public ResponseEntity genera(HttpServletResponse response, @PathVariable String resGuid) throws Exception {
@@ -65,14 +80,29 @@
   @GetMapping("/download/overFloodInfo")
   public ResponseEntity overFloodInfo(String isShow) throws Exception{
      String time = new SimpleDateFormat("yyyy-MM-dd").format(new Date());
      String fileName =  time+ "全省水库防汛情况.docx";
      String time = new SimpleDateFormat("yyyy日MM月dd日HH时").format(new Date());
      String fileName =  time+ "报汛文件.docx";
      String fileNameURL = URLEncoder.encode(fileName, "UTF-8");
      //获取总览、大中库、明细数据
      List<TotalInfo> totalList = sjztmdService.getTotalInfo(isShow);
      List<DzkInfo> dzkList = sjztmdService.getDzkInfo(isShow);
      List<OverDetail> overDetailList = sjztmdService.getOverDetailInfo(isShow);
      List<SzInfo> szInfoList = sjztmdService.getSzInfo(isShow);
      //短信预警数量
      SmsResultVO vo = new SmsResultVO();
      // 获取当前日期
      LocalDate today = LocalDate.now();
      // 获取前一天日期
      LocalDate yesterday = today.minusDays(1);
      // 格式化日期并打印
      DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd");
      vo.setStartTime(yesterday.format(formatter));
      vo.setEndTime(yesterday.format(formatter));
      vo.setSmsType("2");
      vo.setResCode("0");
      vo.setIsExport(1);
      List<SmsResultVO> dxyjList = smsRecordClient.smsSuccessList(vo);
      HashMap<String,String> over10Params = new HashMap<>();
      //small_start_stag=0&small_end_stag=2&mid_start_stag=0&mid_end_stag=2&big_start_stag=0&big_end_stag=2
@@ -91,7 +121,7 @@
      List<TotalInfo> totalOver10List = sjztmdService.getTotalOverInfo(isShow,over10Params);
      byte[] data =  null;
      if (MyDateUtils.isTodayInFloodSeason()){
         data = WordUtil.GetOverInfo(totalList,dzkList,overDetailList,szInfoList);
         data = WordUtil.GetOverInfo(totalList,dzkList,overDetailList,szInfoList,dxyjList);
      }else {
         data= WordUtil.GetNotInSeasonOverInfo(totalList,dzkList,overDetailList,szInfoList,totalOverList,totalOver10List);
@@ -102,7 +132,7 @@
      // 将临时文件添加到响应中,以便用户下载
      return ResponseEntity.ok()
         .contentType(MediaType.valueOf("application/vnd.openxmlformats-officedocument.wordprocessingml.document")) // 设置响应的内容类型为二进制流(octet stream)
         .header("Content-Disposition", "attachment; filename=\"" + fileNameURL) // 设置响应的Content-Disposition头,以便浏览器提示用户下载文件
         .header("Content-Disposition", "attachment; filename=" + fileNameURL) // 设置响应的Content-Disposition头,以便浏览器提示用户下载文件
         .body(resource); // 将InputStreamResource对象作为响应体
   }