Bläddra i källkod

【CHG】导出DXF文件时图片加载失败

ZhaoMn 4 år sedan
förälder
incheckning
ca470e2b34

+ 169 - 151
railway-admin/src/main/java/com/railway/web/controller/business/catenary/BusJcbFdfxjyqController.java

@@ -19,174 +19,192 @@ import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
 import javax.validation.Valid;
+import lombok.extern.slf4j.Slf4j;
 import org.springframework.beans.factory.annotation.Value;
 import org.springframework.validation.annotation.Validated;
-import org.springframework.web.bind.annotation.*;
+import org.springframework.web.bind.annotation.DeleteMapping;
+import org.springframework.web.bind.annotation.GetMapping;
+import org.springframework.web.bind.annotation.PathVariable;
+import org.springframework.web.bind.annotation.PostMapping;
+import org.springframework.web.bind.annotation.PutMapping;
+import org.springframework.web.bind.annotation.RequestBody;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RequestParam;
+import org.springframework.web.bind.annotation.RestController;
 import org.springframework.web.multipart.MultipartFile;
 
 /**
  * @author wuhonghao
  */
+@Slf4j
 @Api(value = "rest/catenary/bus/jcb/fdfxjyq", tags = "检查表 - dxf分选绝缘器检查表 ")
 @RestController
 @Validated
 @RequestMapping(value = "business/catenary/bus/jcb/fdfxjyq")
 public class BusJcbFdfxjyqController extends BaseController {
 
-    private final IBusJcbFdfxjyqService busJcbFdfxjyqService;
-    private final ISysFileService sysFileService;
-
-    @Value("${railway.filePath}")
-    public String filePath;
-
-    public BusJcbFdfxjyqController(IBusJcbFdfxjyqService busJcbFdfxjyqService,
-        ISysFileService sysFileService) {
-        this.busJcbFdfxjyqService = busJcbFdfxjyqService;
-        this.sysFileService = sysFileService;
-    }
-
-    @ApiOperation(value = "新增")
-    @PostMapping("/add")
-    public AjaxResult add(@Validated @RequestBody BusJcbFdfxjyq busJcbFdfxjyq) throws Exception {
-        //将文件转成base64
-        if(busJcbFdfxjyq.getPicUrl()!=null&&!"".equals(busJcbFdfxjyq.getPicUrl())){
-            MultipartFile multipartFile = BASE64DecodedMultipartFile.base64ToMultipart(busJcbFdfxjyq.getPicUrl());
-            String path = sysFileService.uploadFile(multipartFile);
-            busJcbFdfxjyq.setPicUrl(path);
-        }
-        return toAjax(busJcbFdfxjyqService.create(busJcbFdfxjyq));
-    }
-
-    @ApiOperation(value = "删除")
-    @DeleteMapping("/{ids}")
-    public AjaxResult delete(@RequestParam String[] ids) {
-        return toAjax(busJcbFdfxjyqService.delete(ids));
-    }
-
-    @ApiOperation(value = "更新")
-    @PutMapping("/update")
-    public AjaxResult update(@RequestBody @Valid BusJcbFdfxjyq busJcbFdfxjyq) throws Exception {
-        //将文件转成base64
-        if(busJcbFdfxjyq.getPicUrl()!=null&&!"".equals(busJcbFdfxjyq.getPicUrl())){
-            MultipartFile multipartFile = BASE64DecodedMultipartFile.base64ToMultipart(busJcbFdfxjyq.getPicUrl());
-            String path = sysFileService.uploadFile(multipartFile);
-            busJcbFdfxjyq.setPicUrl(path);
-        }
-        return toAjax(busJcbFdfxjyqService.update(busJcbFdfxjyq));
-    }
-
-    @ApiOperation(value = "单个")
-    @GetMapping(value = {"/", "/{id}"})
-    public AjaxResult getInfo(@PathVariable String id) {
-        BusJcbFdfxjyq info = busJcbFdfxjyqService.getInfo(id);
-        AjaxResult ajax = AjaxResult.success();
-        ajax.put("info",info);
-        return ajax;
-    }
-
-    @ApiOperation(value = "列表")
-    @GetMapping(value = "list")
-    public TableDataInfo getList(BusJcbFdfxjyq busJcbFdfxjyq) {
-        startPage();
-        List<BusJcbFdfxjyq> list = busJcbFdfxjyqService.getList(busJcbFdfxjyq);
-        return getDataTable(list);
-    }
-
-    @ApiOperation(value = "获取上次检测值")
-    @GetMapping(value = "getLastOne")
-    public AjaxResult getLastOne(BusJcbFdfxjyq busJcbFdfxjyq) {
-        BusJcbFdfxjyq info = busJcbFdfxjyqService.getLastOne(busJcbFdfxjyq);
-        AjaxResult ajax = AjaxResult.success();
-        ajax.put("info",info);
-        return ajax;
+  private final IBusJcbFdfxjyqService busJcbFdfxjyqService;
+  private final ISysFileService sysFileService;
+
+  @Value("${railway.filePath}")
+  public String filePath;
+
+  public BusJcbFdfxjyqController(IBusJcbFdfxjyqService busJcbFdfxjyqService,
+      ISysFileService sysFileService) {
+    this.busJcbFdfxjyqService = busJcbFdfxjyqService;
+    this.sysFileService = sysFileService;
+  }
+
+  @ApiOperation(value = "新增")
+  @PostMapping("/add")
+  public AjaxResult add(@Validated @RequestBody BusJcbFdfxjyq busJcbFdfxjyq) throws Exception {
+    //将文件转成base64
+    if (busJcbFdfxjyq.getPicUrl() != null && !"".equals(busJcbFdfxjyq.getPicUrl())) {
+      MultipartFile multipartFile = BASE64DecodedMultipartFile.base64ToMultipart(
+          busJcbFdfxjyq.getPicUrl());
+      String path = sysFileService.uploadFile(multipartFile);
+      busJcbFdfxjyq.setPicUrl(path);
     }
-
-    @ApiOperation(value = "提交")
-    @PutMapping("/submit")
-    public AjaxResult submit(@RequestBody BusJcbFdfxjyq busJcbFdfxjyq) throws Exception {
-        busJcbFdfxjyq.setUpdateBy(getUsername());
-        //将文件转成base64
-        if(busJcbFdfxjyq.getPicUrl()!=null&&!"".equals(busJcbFdfxjyq.getPicUrl())){
-            MultipartFile multipartFile = BASE64DecodedMultipartFile.base64ToMultipart(busJcbFdfxjyq.getPicUrl());
-            String path = sysFileService.uploadFile(multipartFile);
-            busJcbFdfxjyq.setPicUrl(path);
-        }
-        return toAjax(busJcbFdfxjyqService.submit(busJcbFdfxjyq));
+    return toAjax(busJcbFdfxjyqService.create(busJcbFdfxjyq));
+  }
+
+  @ApiOperation(value = "删除")
+  @DeleteMapping("/{ids}")
+  public AjaxResult delete(@RequestParam String[] ids) {
+    return toAjax(busJcbFdfxjyqService.delete(ids));
+  }
+
+  @ApiOperation(value = "更新")
+  @PutMapping("/update")
+  public AjaxResult update(@RequestBody @Valid BusJcbFdfxjyq busJcbFdfxjyq) throws Exception {
+    //将文件转成base64
+    if (busJcbFdfxjyq.getPicUrl() != null && !"".equals(busJcbFdfxjyq.getPicUrl())) {
+      MultipartFile multipartFile = BASE64DecodedMultipartFile.base64ToMultipart(
+          busJcbFdfxjyq.getPicUrl());
+      String path = sysFileService.uploadFile(multipartFile);
+      busJcbFdfxjyq.setPicUrl(path);
     }
-
-    @ApiOperation(value = "退回")
-    @PutMapping("/reject")
-    public AjaxResult reject(@RequestBody BusJcbFdfxjyq busJcbFdfxjyq) throws Exception {
-        busJcbFdfxjyq.setUpdateBy(getUsername());
-        return toAjax(busJcbFdfxjyqService.reject(busJcbFdfxjyq));
+    return toAjax(busJcbFdfxjyqService.update(busJcbFdfxjyq));
+  }
+
+  @ApiOperation(value = "单个")
+  @GetMapping(value = {"/", "/{id}"})
+  public AjaxResult getInfo(@PathVariable String id) {
+    BusJcbFdfxjyq info = busJcbFdfxjyqService.getInfo(id);
+    AjaxResult ajax = AjaxResult.success();
+    ajax.put("info", info);
+    return ajax;
+  }
+
+  @ApiOperation(value = "列表")
+  @GetMapping(value = "list")
+  public TableDataInfo getList(BusJcbFdfxjyq busJcbFdfxjyq) {
+    startPage();
+    List<BusJcbFdfxjyq> list = busJcbFdfxjyqService.getList(busJcbFdfxjyq);
+    return getDataTable(list);
+  }
+
+  @ApiOperation(value = "获取上次检测值")
+  @GetMapping(value = "getLastOne")
+  public AjaxResult getLastOne(BusJcbFdfxjyq busJcbFdfxjyq) {
+    BusJcbFdfxjyq info = busJcbFdfxjyqService.getLastOne(busJcbFdfxjyq);
+    AjaxResult ajax = AjaxResult.success();
+    ajax.put("info", info);
+    return ajax;
+  }
+
+  @ApiOperation(value = "提交")
+  @PutMapping("/submit")
+  public AjaxResult submit(@RequestBody BusJcbFdfxjyq busJcbFdfxjyq) throws Exception {
+    busJcbFdfxjyq.setUpdateBy(getUsername());
+    //将文件转成base64
+    if (busJcbFdfxjyq.getPicUrl() != null && !"".equals(busJcbFdfxjyq.getPicUrl())) {
+      MultipartFile multipartFile = BASE64DecodedMultipartFile.base64ToMultipart(
+          busJcbFdfxjyq.getPicUrl());
+      String path = sysFileService.uploadFile(multipartFile);
+      busJcbFdfxjyq.setPicUrl(path);
     }
-
-    @ApiOperation(value = "确认")
-    @PutMapping("/confirm")
-    public AjaxResult confirm(@RequestBody BusJcbFdfxjyq busJcbFdfxjyq) throws Exception {
-        busJcbFdfxjyq.setUpdateBy(getUsername());
-        return toAjax(busJcbFdfxjyqService.confirm(busJcbFdfxjyq));
-    }
-
-    @ApiOperation(value = "导出")
-    @GetMapping("/export")
-    public AjaxResult export(@RequestParam String id) throws InterruptedException {
-        //获取基础数据
-        BusJcbFdfxjyq info = busJcbFdfxjyqService.getInfo(id);
-        WordUtils wordUtil=new WordUtils();
-        //填充变量
-        Map<String, Object> params = new HashMap<>();
-        params.put("${fdh}", info.getFdh());
-        params.put("${qj}", info.getStationName());
-        params.put("${jcrq}", DateUtils.parseCheckDate(info.getCheckDate()));
-        params.put("${wd}", info.getTemperature());
-        params.put("${jcr}", info.getCheckUser());
-        params.put("${pointB}", info.getPointB().toString());
-        params.put("${pointG}", info.getPointG().toString());
-        params.put("${fcd}", info.getFcd().toString());
-        params.put("${fddmpsd}", info.getFddmpsd().toString());
-        params.put("${jybjFdjyqzjyzt}", StringUtils.yesOrNo(info.getJybjFdjyqzjyzt()));
-        params.put("${jybjClsjyzzt}", StringUtils.yesOrNo(info.getJybjClsjyzzt()));
-        params.put("${lbjztLs}", StringUtils.yesOrNo(info.getLbjztLs()));
-        params.put("${lbjztXdx}", StringUtils.yesOrNo(info.getLbjztXdx()));
-        params.put("${lbjztPhzj}", StringUtils.yesOrNo(info.getLbjztPhzj()));
-        params.put("${lbjztJcxjt}", StringUtils.yesOrNo(info.getLbjztJcxjt()));
-        params.put("${lbjztXhj}", StringUtils.yesOrNo(info.getLbjztXhj()));
-        params.put("${sbzt}", StringUtils.YES_VALUE.equals(info.getSbzt()) ? "合格" : "不合格");
-        params.put("${xlfdXlpd}", info.getXlfdXlpd().toString());
-        params.put("${xlfdWgdg}", info.getXlfdWgdg().toString());
-        params.put("${xlfdFdsxlqj}", info.getXlfdFdsxlqj().toString());
-        params.put("${xlfdFdczxlqj}", info.getXlfdFdczxlqj().toString());
-        params.put("${sdgjcztSddg}", StringUtils.yesOrNo(info.getSdgjcztSddg()));
-        params.put("${confirmUser}", StringUtils.isEmpty(info.getConfirmUserRealName())?"":info.getConfirmUserRealName());
-        params.put("${czwt}", info.getCzwtAll());
-        //填充图片信息
-        Map<String,Object> header = new HashMap<>();
-        header.put("width", 450);
-        header.put("height", 110);
-        header.put("type", "jpg");
-        InputStream inputStream = HttpUtils.sendGetStream(info.getPicUrl());
-        //解决网络传输造成流读取不全问题
-        Thread.sleep(200);
-        if(null != inputStream) {
-            header.put("content", WordUtils.inputStream2ByteArray(inputStream, true));
-        }
-        params.put("${header}",header);
-
-        //生成word文件的文件名
-        String fileName = "DXF分段绝缘器手册.docx";
-        String template = "word/template/DXF分段绝缘器手册.docx";
-        String localFilePath = wordUtil.getWord(params, template, fileName);
-        return sysFileService.uploadFile(localFilePath);
-
-    }
-
-    @ApiOperation(value = "导出excel")
-    @GetMapping(value = "exportExcel")
-    public AjaxResult exportExcel(JcebQueryVo query) {
-        String localFilePath = busJcbFdfxjyqService.exportExcel(query);
-        return sysFileService.uploadFile(localFilePath);
+    return toAjax(busJcbFdfxjyqService.submit(busJcbFdfxjyq));
+  }
+
+  @ApiOperation(value = "退回")
+  @PutMapping("/reject")
+  public AjaxResult reject(@RequestBody BusJcbFdfxjyq busJcbFdfxjyq) throws Exception {
+    busJcbFdfxjyq.setUpdateBy(getUsername());
+    return toAjax(busJcbFdfxjyqService.reject(busJcbFdfxjyq));
+  }
+
+  @ApiOperation(value = "确认")
+  @PutMapping("/confirm")
+  public AjaxResult confirm(@RequestBody BusJcbFdfxjyq busJcbFdfxjyq) throws Exception {
+    busJcbFdfxjyq.setUpdateBy(getUsername());
+    return toAjax(busJcbFdfxjyqService.confirm(busJcbFdfxjyq));
+  }
+
+  @ApiOperation(value = "导出")
+  @GetMapping("/export")
+  public AjaxResult export(@RequestParam String id) throws InterruptedException {
+    //获取基础数据
+    BusJcbFdfxjyq info = busJcbFdfxjyqService.getInfo(id);
+    WordUtils wordUtil = new WordUtils();
+    //填充变量
+    Map<String, Object> params = new HashMap<>();
+    params.put("${fdh}", info.getFdh());
+    params.put("${qj}", info.getStationName());
+    params.put("${jcrq}", DateUtils.parseCheckDate(info.getCheckDate()));
+    params.put("${wd}", info.getTemperature());
+    params.put("${jcr}", info.getCheckUser());
+    params.put("${pointB}", info.getPointB().toString());
+    params.put("${pointG}", info.getPointG().toString());
+    params.put("${fcd}", info.getFcd().toString());
+    params.put("${fddmpsd}", info.getFddmpsd().toString());
+    params.put("${jybjFdjyqzjyzt}", StringUtils.yesOrNo(info.getJybjFdjyqzjyzt()));
+    params.put("${jybjClsjyzzt}", StringUtils.yesOrNo(info.getJybjClsjyzzt()));
+    params.put("${lbjztLs}", StringUtils.yesOrNo(info.getLbjztLs()));
+    params.put("${lbjztXdx}", StringUtils.yesOrNo(info.getLbjztXdx()));
+    params.put("${lbjztPhzj}", StringUtils.yesOrNo(info.getLbjztPhzj()));
+    params.put("${lbjztJcxjt}", StringUtils.yesOrNo(info.getLbjztJcxjt()));
+    params.put("${lbjztXhj}", StringUtils.yesOrNo(info.getLbjztXhj()));
+    params.put("${sbzt}", StringUtils.YES_VALUE.equals(info.getSbzt()) ? "合格" : "不合格");
+    params.put("${xlfdXlpd}", info.getXlfdXlpd().toString());
+    params.put("${xlfdWgdg}", info.getXlfdWgdg().toString());
+    params.put("${xlfdFdsxlqj}", info.getXlfdFdsxlqj().toString());
+    params.put("${xlfdFdczxlqj}", info.getXlfdFdczxlqj().toString());
+    params.put("${sdgjcztSddg}", StringUtils.yesOrNo(info.getSdgjcztSddg()));
+    params.put("${confirmUser}",
+        StringUtils.isEmpty(info.getConfirmUserRealName()) ? "" : info.getConfirmUserRealName());
+    params.put("${czwt}", info.getCzwtAll());
+    //填充图片信息
+    Map<String, Object> header = new HashMap<>();
+    header.put("width", 450);
+    header.put("height", 110);
+    header.put("type", "jpg");
+    InputStream inputStream = HttpUtils.sendGetStream(info.getPicUrl());
+    log.info("inputStream - {}", inputStream);
+    //解决网络传输造成流读取不全问题
+    Thread.sleep(200);
+    if (null != inputStream) {
+      byte[] byteArray = WordUtils.inputStream2ByteArray(inputStream, true);
+      log.info("byteArray.length - {}", byteArray.length);
+      header.put("content", byteArray);
     }
+    log.info("header.size() - {}", header.size());
+    params.put("${header}", header);
+
+    //生成word文件的文件名
+    String fileName = "DXF分段绝缘器手册.docx";
+    String template = "word/template/DXF分段绝缘器手册.docx";
+    String localFilePath = wordUtil.getWord(params, template, fileName);
+    return sysFileService.uploadFile(localFilePath);
+
+  }
+
+  @ApiOperation(value = "导出excel")
+  @GetMapping(value = "exportExcel")
+  public AjaxResult exportExcel(JcebQueryVo query) {
+    String localFilePath = busJcbFdfxjyqService.exportExcel(query);
+    return sysFileService.uploadFile(localFilePath);
+  }
 
 
 }