bug
This commit is contained in:
@ -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();
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
@ -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);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user