| | |
| | | import io.swagger.annotations.ApiImplicitParams; |
| | | import io.swagger.annotations.ApiOperation; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.apache.poi.ss.formula.functions.Rows; |
| | | import org.apache.poi.xwpf.usermodel.XWPFDocument; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.util.ObjectUtils; |
| | |
| | | import org.springframework.web.bind.annotation.CrossOrigin; |
| | | import org.springframework.web.bind.annotation.GetMapping; |
| | | import org.springframework.web.bind.annotation.PostMapping; |
| | | import org.springframework.web.bind.annotation.RequestBody; |
| | | import org.springframework.web.bind.annotation.RequestMapping; |
| | | import org.springframework.web.bind.annotation.RestController; |
| | | import org.springframework.web.multipart.MultipartFile; |
| | |
| | | * @return |
| | | */ |
| | | @PostMapping("dailyDustlds") |
| | | public ResultMessage dailyDustlds(HttpServletRequest request) throws IOException { |
| | | // List<MultipartFile> files = ((MultipartHttpServletRequest) request).getFiles("files"); |
| | | Map<String, Object> params = WebUtils.getParametersStartingWith(request, null); |
| | | public ResultMessage dailyDustlds(@RequestBody Map<String,Object> params, HttpServletResponse response) throws IOException { |
| | | |
| | | // Map<String, Object> params = WebUtils.getParametersStartingWith(request, null); |
| | | if (!params.containsKey("mac") || !params.containsKey("startTime") || !params.containsKey("endTime")){ |
| | | return ResultMessage.fail(ResponseCodeEnum.PARAMETERS_IS_MISSING.getCode(), ResponseCodeEnum.PARAMETERS_IS_MISSING.getMsg()); |
| | | } |
| | | |
| | | Map<String, Object> map = dustldService.dailyDustlds(null,params); |
| | | test(map); |
| | | test(map,response); |
| | | if (ObjectUtils.isEmpty(map)){ |
| | | return ResultMessage.fail(ResponseCodeEnum.TARGET_IS_NULL.getCode(), ResponseCodeEnum.TARGET_IS_NULL.getMsg()); |
| | | } |
| | | return new ResultMessage(ResponseCodeEnum.SUCCESS.getCode(),ResponseCodeEnum.SUCCESS.getMsg(),map); |
| | | // return new ResultMessage(ResponseCodeEnum.SUCCESS.getCode(),ResponseCodeEnum.SUCCESS.getMsg(),map); |
| | | return ResultMessage.ok(); |
| | | } |
| | | |
| | | |
| | |
| | | } |
| | | |
| | | |
| | | public void test( Map<String, Object> params) throws IOException { |
| | | public void test( Map<String, Object> params,HttpServletResponse response) throws IOException { |
| | | // String path="D:\\尘负荷监测报告.docx"; |
| | | String path = getPath("尘负荷监测报告.docx"); |
| | | //获取当前模板的路径 |
| | |
| | | map.put("data",params.get("data").toString()); |
| | | map.put("time",params.get("time").toString()); |
| | | |
| | | |
| | | compile.render(map); |
| | | // compile.write(new FileOutptStream("尘负荷监测报告"+paramsu.get("time").toString()+".docx")); |
| | | compile.writeToFile("G:\\home\\mon1\\" + "尘负荷监测报告"+params.get("time").toString()+".docx"); |
| | | // response.setCharacterEncoding("utf-8"); |
| | | // response.setContentType("multipart/form-data"); |
| | | // response.setHeader("Content-Disposition", "attachment;filename=" + URLEncoder.encode("尘负荷监测报告" + params.get("time").toString() + ".docx", "utf-8")); |
| | | // FileOutputStream fileOutputStream = new FileOutputStream("尘负荷监测报告" + params.get("time").toString() + ".docx"); |
| | | // compile.write(fileOutputStream); |
| | | // compile.writeToFile("G:\\hme\\mon1\\" + "尘负荷监测报告"+params.get("time").toString()+".docx"); |
| | | |
| | | // FileOutputStream out = new FileOutputStream("尘负荷监测报告" + params.get("time").toString() + ".docx"); |
| | | compile.write(response.getOutputStream()); |
| | | compile.close(); |
| | | // return compile; |
| | | } |
| | | |
| | | |