Commit 27eddd52 authored by duanruiming's avatar duanruiming

[add] 绿波诱导查询历史下发文件

parent f40d31e4
......@@ -24,6 +24,7 @@ import org.springframework.web.bind.annotation.*;
import javax.ws.rs.core.MediaType;
import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.time.LocalDateTime;
import java.util.Date;
import java.util.List;
import java.util.Objects;
......@@ -153,6 +154,45 @@ public class InduceSendController {
.body("程序查询错误请联系管理员".getBytes(StandardCharsets.UTF_8));
}
}
@ApiOperation(value = "根据设备编号和发布时间获取诱导发布图片", notes = "根据设备编号和发布时间获取诱导发布图片")
@GetMapping(value = "/fileCodeHist")
public ResponseEntity<byte[]> ftpFileByCodeAndTime(@RequestParam("equipCode") String equipCode, @RequestParam("date") Date date) {
LambdaQueryWrapper<InduceHist> queryWrapper = new LambdaQueryWrapper<>();
queryWrapper.eq(InduceHist::getEquipCode, equipCode);
queryWrapper.le(InduceHist::getCreateTime, date);
queryWrapper.orderByDesc(InduceHist::getCreateTime);
queryWrapper.last("limit 1");
InduceHist pictureFile = this.induceHistService.getOne(queryWrapper,false);
if (Objects.isNull(pictureFile) || pictureFile.getFilePath() == null) {
return ResponseEntity.status(HttpStatus.OK)
.body("无效的文件ID".getBytes(StandardCharsets.UTF_8));
}
try {
// 获取ftp服务器图片
byte[] imageBytes = this.induceSendService.downloadImage(pictureFile.getFilePath());
if (imageBytes != null && imageBytes.length > 0) {
// 设置响应头
HttpHeaders headers = new HttpHeaders();
// 图片类型
headers.set("Content-Type", "image/jpeg");
// 设置内容长度
headers.set("Content-Length", String.valueOf(imageBytes.length));
// 设置文件名
headers.set("Content-Disposition", "inline; filename=\"" + pictureFile.getSourceId() + ".bmp\"");
// 返回响应
return new ResponseEntity<>(imageBytes, headers, HttpStatus.OK);
} else {
return ResponseEntity.status(HttpStatus.OK)
.body("未查询到对应文件".getBytes(StandardCharsets.UTF_8));
}
} catch (IOException e) {
log.error("ftp文件下载失败: ", e.getMessage());
return ResponseEntity.status(HttpStatus.OK)
.body("程序查询错误请联系管理员".getBytes(StandardCharsets.UTF_8));
}
}
/**
* 获取ftp图片
*/
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment