From d117d3af15dddc4f07baffa8b5bf6b727c05de7c Mon Sep 17 00:00:00 2001 From: cjl <276999030@qq.com> Date: Wed, 15 Nov 2023 15:48:14 +0800 Subject: [PATCH] fix:补充提交 --- screen-api/src/main/java/com/moral/api/controller/CruiserController.java | 343 +++++++++++++++++++++++++++++++++++++++++++++++++++++++-- 1 files changed, 330 insertions(+), 13 deletions(-) diff --git a/screen-api/src/main/java/com/moral/api/controller/CruiserController.java b/screen-api/src/main/java/com/moral/api/controller/CruiserController.java index ac6fdb9..31908f5 100644 --- a/screen-api/src/main/java/com/moral/api/controller/CruiserController.java +++ b/screen-api/src/main/java/com/moral/api/controller/CruiserController.java @@ -1,26 +1,50 @@ package com.moral.api.controller; +import cn.afterturn.easypoi.word.WordExportUtil; +import cn.hutool.poi.word.WordUtil; +import com.deepoove.poi.XWPFTemplate; +import com.deepoove.poi.config.Configure; +import com.deepoove.poi.data.RowRenderData; +import com.deepoove.poi.data.TextRenderData; +import com.deepoove.poi.policy.HackLoopTableRenderPolicy; +import com.moral.api.entity.Dustld; +import com.moral.api.exception.BusinessException; +import com.moral.api.pojo.bo.ExcelBO; +import com.moral.api.pojo.dto.historySecondCruiser.HistorySecondCruiserResultDTO; +import com.moral.api.pojo.dust.DustForm; +import com.moral.api.pojo.vo.excel.DailyVo; +import com.moral.api.service.DustldService; +import com.moral.api.service.SpecialDeviceService; +import com.moral.constant.ResponseCodeEnum; +import com.moral.constant.ResultMessage; +import com.moral.util.WebUtils; import io.swagger.annotations.Api; import io.swagger.annotations.ApiImplicitParam; import io.swagger.annotations.ApiImplicitParams; import io.swagger.annotations.ApiOperation; import lombok.extern.slf4j.Slf4j; +import org.apache.commons.io.FileUtils; +import org.apache.poi.xwpf.usermodel.XWPFDocument; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.transaction.annotation.Transactional; 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.RequestMapping; -import org.springframework.web.bind.annotation.RestController; +import org.springframework.util.ResourceUtils; +import org.springframework.web.bind.annotation.*; +import org.springframework.web.multipart.MultipartFile; +import org.springframework.web.multipart.MultipartHttpServletRequest; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; +import java.io.*; +import java.net.URL; +import java.net.URLEncoder; +import java.text.ParseException; +import java.util.ArrayList; +import java.util.HashMap; import java.util.List; import java.util.Map; -import javax.servlet.http.HttpServletRequest; - -import com.moral.api.service.SpecialDeviceService; -import com.moral.constant.ResponseCodeEnum; -import com.moral.constant.ResultMessage; -import com.moral.util.WebUtils; +import static com.moral.api.controller.SysTestController.getPath; @Slf4j @Api(tags = {"���������"}) @@ -69,15 +93,308 @@ @ApiImplicitParams(value = { @ApiImplicitParam(name = "token", value = "token", required = true, paramType = "header", dataType = "String"), @ApiImplicitParam(name = "mac", value = "������mac", required = true, paramType = "query", dataType = "String"), - @ApiImplicitParam(name = "time", value = "���������2021-08-18", required = true, paramType = "query", dataType = "String") + @ApiImplicitParam(name = "time1", value = "���������2021-08-18", required = true, paramType = "query", dataType = "String"), + @ApiImplicitParam(name = "time2", value = "���������2021-08-18", required = true, paramType = "query", dataType = "String") }) public ResultMessage carTrajectory(HttpServletRequest request) { Map<String, Object> params = WebUtils.getParametersStartingWith(request, null); - if (!params.containsKey("mac") || !params.containsKey("time")) { + if (!params.containsKey("mac") || !params.containsKey("time1")|| !params.containsKey("time2")) { return ResultMessage.fail(ResponseCodeEnum.PARAMETERS_IS_MISSING.getCode(), ResponseCodeEnum.PARAMETERS_IS_MISSING.getMsg()); } - List<Map<String, Object>> response = specialDeviceService.carTrajectory(params); + List<Map<String, Object>> response = specialDeviceService.carTrajectory(params,true); return ObjectUtils.isEmpty(response) ? ResultMessage.ok() : ResultMessage.ok(response); } + @GetMapping("carTrajectoryNewAvg") + @ApiOperation(value = "���������������", notes = "���������������") + @ApiImplicitParams(value = { + @ApiImplicitParam(name = "token", value = "token", required = true, paramType = "header", dataType = "String"), + @ApiImplicitParam(name = "mac", value = "������mac", required = true, paramType = "query", dataType = "String"), + @ApiImplicitParam(name = "time1", value = "���������2021-08-18", required = true, paramType = "query", dataType = "String"), + @ApiImplicitParam(name = "time2", value = "���������2021-08-18", required = true, paramType = "query", dataType = "String"), + @ApiImplicitParam(name = "type", value = "������������", required = true, paramType = "query", dataType = "String"), + @ApiImplicitParam(name = "range", value = "������", required = true, paramType = "query", dataType = "int") + }) + public ResultMessage carTrajectoryNewAvg(HttpServletRequest request) { + Map<String, Object> params = WebUtils.getParametersStartingWith(request, null); + if (!params.containsKey("mac") || !params.containsKey("time1")||!params.containsKey("range")|| !params.containsKey("type")|| !params.containsKey("time2")) { + return ResultMessage.fail(ResponseCodeEnum.PARAMETERS_IS_MISSING.getCode(), ResponseCodeEnum.PARAMETERS_IS_MISSING.getMsg()); + } + List<HistorySecondCruiserResultDTO> response = specialDeviceService.carTrajectoryNewAvg(params); + + //������������������ + + return ObjectUtils.isEmpty(response) ? ResultMessage.ok() : ResultMessage.ok(response); + + } + + /** + * ��������������� + * @param request + * @return + */ + @PostMapping("getDaily") + @ApiOperation(value = "���������������", notes = "���������������") + @ApiImplicitParams(value = { + @ApiImplicitParam(name = "token", value = "token", required = true, paramType = "header", dataType = "String"), + @ApiImplicitParam(name = "mac", value = "������mac", required = true, paramType = "query", dataType = "String"), + @ApiImplicitParam(name = "time1", value = "���������������2021-08-18", required = true, paramType = "query", dataType = "String"), + @ApiImplicitParam(name = "time2", value = "���������������2021-08-18", required = true, paramType = "query", dataType = "String") + }) + public ResultMessage getDaily(HttpServletRequest request) throws ParseException { + Map<String, Object> params = WebUtils.getParametersStartingWith(request, null); + if (!params.containsKey("mac") || !params.containsKey("time1")|| !params.containsKey("time2")) { + return ResultMessage.fail(ResponseCodeEnum.PARAMETERS_IS_MISSING.getCode(), ResponseCodeEnum.PARAMETERS_IS_MISSING.getMsg()); + } + List<MultipartFile> files = ((MultipartHttpServletRequest) request).getFiles("files"); + ExcelBO daily = specialDeviceService.getDaily(params, files); + if (daily==null){ + return ResultMessage.fail(ResponseCodeEnum.TARGET_IS_NULL.getCode(), ResponseCodeEnum.TARGET_IS_NULL.getMsg()); + } + return ObjectUtils.isEmpty(daily) ? ResultMessage.ok() : ResultMessage.ok(daily); + } + + /** + * ��������������������� + * @param id + * @return + */ + @GetMapping("loadDaily") + public ResultMessage loadDaily(Integer id){ + + DailyVo dailyVo = specialDeviceService.loadDaily(id); + if (dailyVo==null){ + return ResultMessage.fail(ResponseCodeEnum.TARGET_IS_NULL.getCode(), ResponseCodeEnum.TARGET_IS_NULL.getMsg()); + } + return new ResultMessage(ResponseCodeEnum.SUCCESS.getCode(), ResponseCodeEnum.SUCCESS.getMsg(),dailyVo); + } + + /** + * ������������ + * @param request + * @return + */ + @GetMapping("selectDaily") + public ResultMessage selectDaily(HttpServletRequest request){ + Map<String, Object> params = WebUtils.getParametersStartingWith(request, null); + if ( !params.containsKey("startTime")|| !params.containsKey("endTime")) { + return ResultMessage.fail(ResponseCodeEnum.PARAMETERS_IS_MISSING.getCode(), ResponseCodeEnum.PARAMETERS_IS_MISSING.getMsg()); + } + List<ExcelBO> excelBOS = specialDeviceService.selectDaily(params); + if (excelBOS==null){ + return ResultMessage.fail(ResponseCodeEnum.TARGET_IS_NULL.getCode(), ResponseCodeEnum.TARGET_IS_NULL.getMsg()); + } + return new ResultMessage(ResponseCodeEnum.SUCCESS.getCode(), ResponseCodeEnum.SUCCESS.getMsg(),excelBOS); + } + + @Autowired + private DustldService dustldService; + + /** + * ��������������� + * @param request + * @return + */ + @PostMapping("getDailyDustld") + public ResultMessage getDailyDustld(HttpServletRequest request) { + Map<String, Object> params = WebUtils.getParametersStartingWith(request, null); + if (!params.containsKey("mac") || !params.containsKey("road") || !params.containsKey("table")){ + return ResultMessage.fail(ResponseCodeEnum.PARAMETERS_IS_MISSING.getCode(), ResponseCodeEnum.PARAMETERS_IS_MISSING.getMsg()); + } + MultipartFile file = ((MultipartHttpServletRequest) request).getFile("files"); + + Integer dailyDustld = null; + try { + dailyDustld = dustldService.getDailyDustld(params,file); + } catch (ParseException e) { + log.error("{������}"+e.getMessage()); + } + if (ObjectUtils.isEmpty(dailyDustld)){ + return ResultMessage.fail(ResponseCodeEnum.TARGET_IS_NULL.getCode(), ResponseCodeEnum.TARGET_IS_NULL.getMsg()); + } + return new ResultMessage(ResponseCodeEnum.SUCCESS.getCode(),ResponseCodeEnum.SUCCESS.getMsg(),dailyDustld); + } + + /** + * ��������������������� + * @return + */ + @PostMapping("dailyDustld") + public ResultMessage dailyDustld(HttpServletRequest request,Integer id){ + List<MultipartFile> files = ((MultipartHttpServletRequest) request).getFiles("files"); + + Map<String, Object> map = dustldService.dailyDustld(id,files); + 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 + */ + @PostMapping("dailyDustlds") + @Transactional + public void dailyDustlds(@RequestBody Map<String,Object> params, HttpServletResponse response,HttpServletRequest request) throws IOException { + +// Map<String, Object> params = WebUtils.getParametersStartingWith(request, null); + if (!params.containsKey("mac") || !params.containsKey("startTime") || !params.containsKey("endTime")){ + return; + } + Map<String, Object> map = dustldService.dailyDustlds(params); + if (ObjectUtils.isEmpty(map)){ + throw new BusinessException("���������������������"); + } + test(map,response,request); + + + } + + + + + /** + * ������������������ + * @param id + * @return + */ + @GetMapping("selectDust") + public ResultMessage selectDust(Integer id){ + Map<String, Object> map = null; + try { + map = dustldService.selectDust(id); + } catch (Exception e) { + log.error("{������}"+e.getMessage()); + } + return new ResultMessage(ResponseCodeEnum.SUCCESS.getCode(),ResponseCodeEnum.SUCCESS.getMsg(),map); + } + + /** + * ��������������������������������� + * @param request + * @return + */ + @GetMapping("selectAll") + public ResultMessage selectAll(HttpServletRequest request){ + Map<String, Object> params = WebUtils.getParametersStartingWith(request, null); + List<Dustld> dustlds = null; + try { + dustlds = dustldService.selectAll(params); + } catch (Exception e) { + log.error("{������}"+e.getMessage()); + } + return new ResultMessage(ResponseCodeEnum.SUCCESS.getCode(),ResponseCodeEnum.SUCCESS.getMsg(),dustlds); + + } + + + + public static void downloadWord(String fileName, Map<String, Object> params, HttpServletResponse response, String newFileName) { + String path = getPath(fileName);//��������� resources������ + try { + //������������������ + OutputStream out = new FileOutputStream("G:\\home\\mon1\\" + newFileName); + File rootFile = new File(ResourceUtils.getURL("classpath:").getPath()); + File file= new File(rootFile, path); + XWPFDocument word = WordExportUtil.exportWord07(file.getPath(), params); + response.setCharacterEncoding("utf-8"); + response.setContentType("multipart/form-data"); + response.setHeader("Content-Disposition", "attachment;filename=" + URLEncoder.encode(newFileName, "utf-8")); + //OutputStream out = response.getOutputStream(); + word.write(out); + out.flush(); + out.close(); + } catch (Exception e) { + log.error ("������������������������������������������", e); + } + } + + + public void test( Map<String, Object> params,HttpServletResponse response,HttpServletRequest request) throws IOException { + + try { + //InputStream inputStream = WordUtil.class.getClassLoader().getResourceAsStream("word/���������������������.docx"); + InputStream stream = WordUtil.class.getClassLoader().getResourceAsStream("word/���������������������.docx"); + //������������������ + File file = new File("word/���������������������.docx"); + //��������������������������������������������������������������������������������������������� + FileUtils.copyInputStreamToFile(stream, file); + //��������������������������������������������� ������������������������ + String filePath = file.getAbsolutePath(); + + + + //������������������������������������������������������{{}}������������������������,map������������key������������������������������������������ + HashMap<String, Object> map = new HashMap<>(); + //������������������������ + //RowRenderData header1 = RowRenderData.build(new TextRenderData("6495ED", "������"), new TextRenderData("6495ED", "������"),new TextRenderData("6495ED", "���������������������/������������")); + + //���������������������������������������������������������list������������������������������foreach������������������ + List<DustForm> list1 = (List<DustForm>) params.get("list1"); + + List<Map<String, Object>> mapArrayList = (ArrayList<Map<String, Object>>) params.get("list3"); + ArrayList<RowRenderData> rsList1 = new ArrayList<>(); + ArrayList<RowRenderData> rsList3 = new ArrayList<>(); + List<Map> detailList = new ArrayList<>(); + for (int i = 0; i < list1.size(); i++) { + DustForm dustForm = list1.get(i); + Map maps = new HashMap(); + maps.put("table1", i+1); + maps.put("table2", dustForm.getRoad()); + maps.put("table3", dustForm.getValue()); + detailList.add(maps); + } + List<Map> detailList2 = new ArrayList<>(); + Map maps = new HashMap(); + /* maps.put("table4", ""); + maps.put("table5", ""); + maps.put("table6", ""); + maps.put("table7", map.get("date1")); + maps.put("table8", map.get("date2")); + detailList2.add(maps);*/ + for (int i = 0; i < mapArrayList.size(); i++) { + Map<String, Object> map1 = mapArrayList.get(i); + maps = new HashMap(); + maps.put("time4", i+1); + maps.put("time5", map1.get("road").toString()); + maps.put("time6", map1.get("value1").toString()); + maps.put("time7", map1.get("value2").toString()); + maps.put("time8", map1.get("value3").toString()); + detailList2.add(maps); + } + String data = params.get("data").toString(); + map.put("data",data); + map.put("time",params.get("time").toString()); + map.put("date1",params.get("date1").toString()); + map.put("date2",params.get("date2").toString()); + HackLoopTableRenderPolicy policy = new HackLoopTableRenderPolicy(); + Configure config = Configure.newBuilder().bind("detailList", policy).bind("detailList2", policy).build(); + XWPFTemplate compile = XWPFTemplate.compile(filePath,config).render(new HashMap<String, Object>(){{ + put("time",map.get("time")); + put("data",map.get("data")); + put("time1",map.get("date1").toString()); + put("time2",map.get("date2").toString()); + put("detailList", detailList); + put("detailList2", detailList2); + }}); + + response.setContentType("multipart/form-data"); + // ��������������� + response.addHeader("Content-Disposition", "attachment;fileName=ce.docx" ); + response.setCharacterEncoding("UTF-8"); + OutputStream out = response.getOutputStream(); + compile.write(out); + out.flush(); + out.close(); + compile.close(); + } catch (IOException e) { + log.error ("������������������������������������������", e); + } catch (Exception e) { + throw new RuntimeException(e); + } + + } + } -- Gitblit v1.8.0