This commit is contained in:
zt
2025-09-18 10:56:17 +08:00
parent bf6ea00b26
commit b8f223aea1
2 changed files with 56 additions and 11 deletions

View File

@ -4,16 +4,26 @@ import cn.hutool.core.collection.CollectionUtil;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.dromara.contractor.domain.SubConstructionUser;
import org.dromara.contractor.service.ISubConstructionUserService;
import org.dromara.project.domain.BusAttendanceRule;
import org.dromara.system.domain.vo.SysOssVo;
import org.dromara.transferData.domain.ConstructionUserCopy;
import org.dromara.transferData.domain.OldAttendance;
import org.dromara.transferData.mapper.TransferDataMapper;
import org.dromara.project.domain.BusAttendance;
import org.dromara.project.service.IBusAttendanceRuleService;
import org.dromara.transferData.service.TransferDataService;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import java.io.InputStream;
import java.net.URI;
import java.net.http.HttpRequest;
import java.net.http.HttpResponse;
import java.nio.file.Paths;
import java.time.Duration;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.LocalTime;
@ -40,6 +50,7 @@ public class TransferDataController {
// 两个候选基础URL
private static final String[] BASE_URLS = {
"http://xny.yj-3d.com:7464",
@ -184,4 +195,13 @@ public class TransferDataController {
}
}
}
@GetMapping("/transferSpecialWorkPic")
private void handleFaceImage() {
transferDataService.handleSpecialWorkPic();
}
}

View File

@ -1,5 +1,6 @@
package org.dromara.transferData.service;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import jakarta.activation.MimetypesFileTypeMap;
import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
@ -17,6 +18,7 @@ import org.dromara.system.service.ISysOssService;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Service;
import org.springframework.web.bind.annotation.GetMapping;
import java.io.InputStream;
import java.net.URI;
@ -162,13 +164,16 @@ public class TransferDataService {
try (InputStream inputStream = httpClient.send(request, HttpResponse.BodyHandlers.ofInputStream()).body()) {
// 从响应头获取真实Content-Type比文件名解析更准确
HttpResponse<?> response = httpClient.send(request, HttpResponse.BodyHandlers.discarding());
contentType = response.headers().firstValue("Content-Type").orElse(contentType);
long contentLength = response.headers().firstValueAsLong("Content-Length").orElse(-1);
if(response.statusCode() == 200){
contentType = response.headers().firstValue("Content-Type").orElse(contentType);
long contentLength = response.headers().firstValueAsLong("Content-Length").orElse(-1);
// 上传OSS此时流已通过try-with-resources自动关闭
SysOssVo ossVo = ossService.upload(inputStream, filename, contentType, contentLength);
attendance.setFacePic(ossVo.getOssId() == null ? "" : ossVo.getOssId().toString());
return; // 成功则跳出所有循环
}
// 上传OSS此时流已通过try-with-resources自动关闭
SysOssVo ossVo = ossService.upload(inputStream, filename, contentType, contentLength);
attendance.setFacePic(ossVo.getOssId() == null ? "" : ossVo.getOssId().toString());
return; // 成功则跳出所有循环
}
} catch (Exception e) {
log.warn("尝试URL失败重试{}次): {}", retry + 1, fullUrl, e);
@ -267,12 +272,15 @@ public class TransferDataService {
try (InputStream inputStream = httpClient.send(request, HttpResponse.BodyHandlers.ofInputStream()).body()) {
// 从响应头获取真实Content-Type比文件名解析更准确
HttpResponse<?> response = httpClient.send(request, HttpResponse.BodyHandlers.discarding());
contentType = response.headers().firstValue("Content-Type").orElse(contentType);
long contentLength = response.headers().firstValueAsLong("Content-Length").orElse(-1);
if(response.statusCode() == 200){
contentType = response.headers().firstValue("Content-Type").orElse(contentType);
long contentLength = response.headers().firstValueAsLong("Content-Length").orElse(-1);
// 上传OSS此时流已通过try-with-resources自动关闭
SysOssVo ossVo = ossService.upload(inputStream, filename, contentType, contentLength);
return ossVo.getOssId(); // 成功则跳出所有循环
}
// 上传OSS此时流已通过try-with-resources自动关闭
SysOssVo ossVo = ossService.upload(inputStream, filename, contentType, contentLength);
return ossVo.getOssId(); // 成功则跳出所有循环
}
} catch (Exception e) {
log.warn("尝试URL失败重试{}次): {}", retry + 1, fullUrl, e);
@ -285,4 +293,21 @@ public class TransferDataService {
log.error("照片处理失败所有URL重试完毕relativePath={}", normalizedPath);
return null;
}
public void handleSpecialWorkPic() {
List<SubConstructionUser> list = constructionUserService.list(Wrappers.<SubConstructionUser>lambdaQuery()
.isNotNull(SubConstructionUser::getSpecialWorkPic));
for (SubConstructionUser constructionUser : list) {
String facePicRelativePath = constructionUser.getSpecialWorkPic();
Long l = handleSinglePhoto1(facePicRelativePath);
constructionUser.setSpecialWorkPic(l==null?"":l.toString());
}
constructionUserService.updateBatchById(list);
}
}