包头bug修复
This commit is contained in:
parent
a1feaf56fa
commit
fd1383959b
@ -65,5 +65,9 @@ public class ProjectHomeManage implements Serializable {
|
||||
private java.lang.Integer type;
|
||||
@ApiModelProperty(value = "1作业文件2制度文件")
|
||||
private java.lang.Integer fileType;
|
||||
@ApiModelProperty(value = "标题")
|
||||
private java.lang.String title;
|
||||
@ApiModelProperty(value = "图片或视频")
|
||||
private java.lang.String picVideoUrl;
|
||||
|
||||
}
|
||||
|
||||
@ -24,8 +24,8 @@ import org.springframework.web.multipart.MultipartFile;
|
||||
import javax.annotation.Resource;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.io.*;
|
||||
import java.net.URL;
|
||||
import java.net.URLConnection;
|
||||
import java.net.*;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
@ -119,28 +119,54 @@ public class UploadFileController {
|
||||
@ApiImplicitParam(name = "fileUrl", value = "下载地址", paramType = "query", required = true, dataType = "String"),
|
||||
@ApiImplicitParam(name = "fileName", value = "修改名称", paramType = "query", required = true, dataType = "String")
|
||||
})
|
||||
public void getRenameFile(@RequestParam("fileUrl") String fileUrl, @RequestParam("fileName") String fileName, HttpServletResponse response) {
|
||||
public void getRenameFile(
|
||||
@RequestParam("fileUrl") String fileUrl,
|
||||
@RequestParam("fileName") String fileName,
|
||||
HttpServletResponse response) {
|
||||
try {
|
||||
URL url = new URL(fileUrl);
|
||||
int index = fileUrl.indexOf("?");//第一个问号的位置
|
||||
if (index > -1) {
|
||||
fileUrl = fileUrl.substring(0, index);
|
||||
}
|
||||
String[] split = fileUrl.split("\\.");
|
||||
// 不同文件的MimeType参考后续链接
|
||||
response.setContentType("application/x-download");//下面三行是关键代码,处理乱码问题
|
||||
response.setCharacterEncoding("utf-8");
|
||||
response.setHeader("Content-Disposition", "attachment;filename=" + new String(fileName.getBytes("utf-8"), "iso8859-1") + "." + split[split.length - 1]);
|
||||
// 检查 fileName 有效性
|
||||
// if (fileName == null || fileName.isEmpty() || "undefined".equals(fileName)) {
|
||||
// response.sendError(HttpServletResponse.SC_BAD_REQUEST, "文件名无效");
|
||||
// return;
|
||||
// }
|
||||
|
||||
// 解码客户端传递的 fileUrl(确保客户端已正确编码)
|
||||
String decodedFileUrl = URLDecoder.decode(fileUrl, StandardCharsets.UTF_8.name());
|
||||
|
||||
// 再次编码路径中的特殊字符(处理空格、汉字等)
|
||||
URI uri = new URI(decodedFileUrl.replace(" ", "%20")); // 显式替换空格为%20
|
||||
URL url = uri.toURL();
|
||||
|
||||
// 提取文件扩展名
|
||||
String[] split = decodedFileUrl.split("\\.");
|
||||
String fileExtension = split.length > 1 ? split[split.length - 1] : "";
|
||||
|
||||
// 设置响应头
|
||||
response.setContentType("application/x-download");
|
||||
response.setCharacterEncoding("UTF-8");
|
||||
String encodedFileName = URLEncoder.encode(fileName, StandardCharsets.UTF_8.name())
|
||||
.replace("+", "%20");
|
||||
String contentDisposition = String.format(
|
||||
"attachment; filename=\"%s.%s\"; filename*=UTF-8''%s.%s",
|
||||
encodedFileName, fileExtension, encodedFileName, fileExtension);
|
||||
response.setHeader("Content-Disposition", contentDisposition);
|
||||
|
||||
// 配置 URL 连接
|
||||
URLConnection conn = url.openConnection();
|
||||
InputStream inStream = conn.getInputStream();
|
||||
OutputStream fos = response.getOutputStream();
|
||||
// 读取路径下面的文件
|
||||
FileCopyUtils.copy(inStream, fos);
|
||||
response.getOutputStream().flush();
|
||||
response.getOutputStream().close();
|
||||
response.flushBuffer();
|
||||
conn.setRequestProperty("User-Agent", "Mozilla/5.0");
|
||||
|
||||
// 复制流到响应输出
|
||||
try (InputStream inStream = conn.getInputStream();
|
||||
OutputStream outStream = response.getOutputStream()) {
|
||||
FileCopyUtils.copy(inStream, outStream);
|
||||
}
|
||||
|
||||
} catch (URISyntaxException e) {
|
||||
log.error("URL 格式错误: {}", fileUrl, e);
|
||||
response.setStatus(HttpServletResponse.SC_BAD_REQUEST);
|
||||
} catch (Exception e) {
|
||||
log.error("err:", e);
|
||||
log.error("下载文件失败: ", e);
|
||||
response.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -61,7 +61,8 @@ public class ConcreteMonitorCurrentData implements Serializable {
|
||||
private Double temperature;
|
||||
@ApiModelProperty(value = "1自动采集2手动采集")
|
||||
private Integer uploadType;
|
||||
|
||||
@ApiModelProperty(value = "设备名称")
|
||||
private String devName;
|
||||
@TableField(exist = false)
|
||||
@ApiModelProperty(value = "报警等级,1 紧急告警,2 重要告警,3 次要告警,4 提示告警,5 正常")
|
||||
private Integer alarmLevel;
|
||||
|
||||
@ -73,7 +73,6 @@
|
||||
select * from (
|
||||
select t.*
|
||||
,cmdpp.point_name
|
||||
,cmd.dev_name
|
||||
,cmd.point_num
|
||||
from concrete_monitor_current_data t
|
||||
join concrete_monitor_dev_point_position cmdpp on t.point_no = cmdpp.point_no and cmdpp.dev_sn=t.dev_sn
|
||||
@ -86,7 +85,6 @@
|
||||
<select id="queryDetailList" resultType="com.zhgd.xmgl.modules.concrete.entity.ConcreteMonitorCurrentData">
|
||||
select t.*
|
||||
,cmdpp.point_name
|
||||
,cmd.dev_name
|
||||
,cmd.point_num
|
||||
from concrete_monitor_current_data t
|
||||
join concrete_monitor_dev_point_position cmdpp on t.point_no = cmdpp.point_no and cmdpp.dev_sn=t.dev_sn
|
||||
|
||||
@ -83,6 +83,7 @@ public class ConcreteMonitorCurrentDataServiceImpl extends ServiceImpl<ConcreteM
|
||||
currentData.setUploadType(concreteMonitorCurrentDataVo.getUploadType());
|
||||
}
|
||||
currentData.setId(null);
|
||||
currentData.setDevName(dev.getDevName());
|
||||
concreteMonitorCurrentDataMapper.insert(currentData);
|
||||
QueryWrapper<ConcreteMonitorDevPointPosition> qu = new QueryWrapper<>();
|
||||
qu.lambda().eq(ConcreteMonitorDevPointPosition::getProjectSn, projectSn)
|
||||
|
||||
@ -2,6 +2,7 @@ package com.zhgd.xmgl.util;
|
||||
|
||||
import cn.hutool.core.collection.CollUtil;
|
||||
import cn.hutool.core.date.DateUtil;
|
||||
import cn.hutool.http.HttpUtil;
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.alibaba.fastjson.JSONArray;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
@ -19,6 +20,7 @@ import com.zhgd.xmgl.call.entity.ChargeDeletionParam;
|
||||
import com.zhgd.xmgl.modules.project.entity.Project;
|
||||
import com.zhgd.xmgl.modules.worker.entity.WorkerInfo;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.commons.codec.binary.Base64;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.context.annotation.Lazy;
|
||||
import org.springframework.stereotype.Component;
|
||||
@ -643,8 +645,10 @@ public class HikvisionUtil {
|
||||
String host = "https://" + project.getArtemisConfigHost();
|
||||
JSONObject jo = new JSONObject();
|
||||
jo.put("personId", String.valueOf(workerInfo.getId()));
|
||||
MinioUtils.downloadFile(workerInfo.getFieldAcquisitionUrl());
|
||||
jo.put("faceData", Base64Util.convertFileToBase64(PathUtil.reviseSlash(PathUtil.getBasePath() + "/" + workerInfo.getFieldAcquisitionUrl())));
|
||||
// MinioUtils.downloadFile(workerInfo.getFieldAcquisitionUrl());
|
||||
// jo.put("faceData", Base64Util.convertFileToBase64(PathUtil.reviseSlash(PathUtil.getBasePath() + "/" + workerInfo.getFieldAcquisitionUrl())));
|
||||
byte[] imageBytes = HttpUtil.downloadBytes(PathUtil.getDomain() + workerInfo.getFieldAcquisitionUrl());
|
||||
jo.put("faceData", Base64.encodeBase64String(imageBytes));
|
||||
return doPost(host, path, jo.toJSONString(), null, project.getArtemisConfigAppKey(), project.getArtemisConfigAppSecret());
|
||||
}
|
||||
|
||||
@ -976,4 +980,9 @@ public class HikvisionUtil {
|
||||
}
|
||||
|
||||
|
||||
public static void main(String[] args) {
|
||||
// byte[] imageBytes = HttpUtil.downloadBytes("http://219.147.96.219:9809/image/temp/2025-04-15/b4887e9e3a194dfa9ffc8b9af3e39953/人员入场模板 25.04.16/人脸采集图片/67fe351f4f0c36762fbd52ef.jpg");
|
||||
byte[] imageBytes = HttpUtil.downloadBytes("http://219.147.96.219:9809/image/6800a7e04f0ce189ab266826.jpg");
|
||||
System.out.println(Base64.encodeBase64String(imageBytes));
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user