package cn.gistack.sm.sjztmd.word.controller;
|
|
|
|
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.*;
|
import com.deepoove.poi.XWPFTemplate;
|
import io.swagger.annotations.Api;
|
import lombok.AllArgsConstructor;
|
import lombok.extern.slf4j.Slf4j;
|
import org.springblade.core.tool.api.R;
|
import org.springframework.core.io.InputStreamResource;
|
import org.springframework.http.MediaType;
|
import org.springframework.http.ResponseEntity;
|
import org.springframework.web.bind.annotation.GetMapping;
|
import org.springframework.web.bind.annotation.PathVariable;
|
import org.springframework.web.bind.annotation.RequestMapping;
|
import org.springframework.web.bind.annotation.RestController;
|
|
import javax.servlet.http.HttpServletResponse;
|
import java.io.*;
|
import java.net.URLEncoder;
|
import java.text.SimpleDateFormat;
|
import java.util.Date;
|
import java.util.HashMap;
|
import java.util.List;
|
import java.util.Map;
|
|
/**
|
* @PROJECT_NAME: skjcmanager
|
* @DESCRIPTION:
|
* @USER: aix
|
* @DATE: 2023/11/23 10:08
|
*/
|
@Slf4j
|
@Api(tags = "填报导出")
|
@RestController
|
@RequestMapping("/sjztmd/word")
|
@AllArgsConstructor
|
public class DownTemplateController {
|
|
private final ISjztmdService sjztmdService;
|
|
@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 {
|
HashMap<String,Object> obj = sjztmdService.getTbWordVO(resGuid);
|
|
TbWordVO tbWordVO = (TbWordVO) obj.get("tbWordVO");
|
Map<String,Object> tableMap= (Map<String, Object>) obj.get("tableMap");
|
|
String fileName = resGuid + ".docx";
|
byte[] data = WordUtil.compileTemplateAndRenderData(tbWordVO,tableMap);
|
|
// 创建响应实体并设置响应头,将输出流作为响应体返回给客户端
|
InputStreamResource resource = new InputStreamResource(new ByteArrayInputStream(data));
|
|
// 将临时文件添加到响应中,以便用户下载
|
return ResponseEntity.ok()
|
.contentType(MediaType.APPLICATION_OCTET_STREAM) // 设置响应的内容类型为二进制流(octet stream)
|
.header("Content-Disposition", "attachment; filename=\"" + fileName) // 设置响应的Content-Disposition头,以便浏览器提示用户下载文件
|
.body(resource); // 将InputStreamResource对象作为响应体
|
}
|
|
@GetMapping("/download/overFloodInfo")
|
public ResponseEntity overFloodInfo(String isShow) throws Exception{
|
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);
|
|
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
|
over10Params.put("small_start_stag", "0.1");
|
over10Params.put("mid_start_stag", "0.1");
|
over10Params.put("big_start_stag", "0.1");
|
|
HashMap<String,String> normalParams = 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
|
normalParams.put("small_start_stag", "0");
|
normalParams.put("mid_start_stag", "0");
|
normalParams.put("big_start_stag", "0");
|
|
|
List<TotalInfo> totalOverList = sjztmdService.getTotalOverInfo(isShow,normalParams);
|
List<TotalInfo> totalOver10List = sjztmdService.getTotalOverInfo(isShow,over10Params);
|
byte[] data = null;
|
if (MyDateUtils.isTodayInFloodSeason()){
|
data = WordUtil.GetOverInfo(totalList,dzkList,overDetailList,szInfoList);
|
}else {
|
data= WordUtil.GetNotInSeasonOverInfo(totalList,dzkList,overDetailList,szInfoList,totalOverList,totalOver10List);
|
|
}
|
// 创建响应实体并设置响应头,将输出流作为响应体返回给客户端
|
InputStreamResource resource = new InputStreamResource(new ByteArrayInputStream(data));
|
|
// 将临时文件添加到响应中,以便用户下载
|
return ResponseEntity.ok()
|
.contentType(MediaType.valueOf("application/vnd.openxmlformats-officedocument.wordprocessingml.document")) // 设置响应的内容类型为二进制流(octet stream)
|
.header("Content-Disposition", "attachment; filename=" + fileNameURL) // 设置响应的Content-Disposition头,以便浏览器提示用户下载文件
|
.body(resource); // 将InputStreamResource对象作为响应体
|
}
|
|
@GetMapping("/download/getOverFloodInfoExcel")
|
public void getOverFloodInfoExcel(HttpServletResponse response,String isShow) throws Exception {
|
|
//获取总览、大中库、明细数据
|
List<TotalInfo> totalList = sjztmdService.getTotalInfo(isShow);
|
List<DzkInfo> dzkList = sjztmdService.getDzkInfo(isShow);
|
List<OverDetail> overDetailList = sjztmdService.getOverDetailInfo(isShow);
|
|
ExcelUtil.generateExcel(response,totalList,dzkList,overDetailList);
|
}
|
|
}
|