jinpengyong
2023-09-08 acd8bc764569dcd6a89df4186537e210ffafb283
screen-api/src/main/java/com/moral/api/controller/CruiserController.java
@@ -6,12 +6,14 @@
import com.deepoove.poi.data.TextRenderData;
import com.moral.api.pojo.dto.historySecondCruiser.HistorySecondCruiserResultDTO;
import cn.afterturn.easypoi.exception.word.WordExportException;
import cn.afterturn.easypoi.word.WordExportUtil;
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.poi.ss.formula.functions.Rows;
import org.apache.poi.xwpf.usermodel.XWPFDocument;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.ObjectUtils;
@@ -19,6 +21,7 @@
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;
@@ -36,6 +39,7 @@
import java.util.List;
import java.util.Map;
import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
@@ -240,17 +244,20 @@
     * @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();
    }
@@ -313,7 +320,7 @@
    }
    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");
        //获取当前模板的路径
@@ -348,9 +355,20 @@
        map.put("table2", new MiniTableRenderData(header2, rsList2));
        map.put("data",params.get("data").toString());
        map.put("time",params.get("time").toString());
        compile.render(map);
        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;
    }