Merge remote-tracking branch 'origin/test' into dev
# Conflicts: # firstleg/src/main/java/com/baiyue/firstleg/loading/service/CabinetLoadingEvidenceService.java # firstleg/src/test/java/com/baiyue/firstleg/loading/service/CabinetLoadingEvidenceServiceTest.java # scripts/admin-test-env-modules/ocean-bookings.mjs # scripts/admin-test-env-modules/phase3-container-customs-fixture.mjs # scripts/admin-test-env-modules/phase3-container-documents-contract.test.mjs # scripts/admin-test-env-modules/phase3-container-loading.mjs # scripts/admin-test-env-modules/phase3-customs.mjs # scripts/admin-test-env-modules/phase3-loading-finalize.mjs # scripts/admin-test-env-modules/phase3-loading.mjs # scripts/admin-test-env-modules/phase3-port-schedules.mjs # scripts/admin-test-env-modules/service-center-flow.mjs
This commit is contained in:
+23
-19
@@ -24,8 +24,8 @@ import org.springframework.transaction.annotation.Transactional;
|
||||
import org.springframework.util.StringUtils;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.io.IOException;
|
||||
import java.security.MessageDigest;
|
||||
import java.security.NoSuchAlgorithmException;
|
||||
import java.util.HexFormat;
|
||||
@@ -45,13 +45,13 @@ public class CabinetLoadingEvidenceService {
|
||||
|
||||
@Transactional
|
||||
public EvidenceList upsert(long taskId, String key, UpsertRequest request, long operatorId, String operatorName) {
|
||||
Scope scope = scope(taskId, request.warehouseId(), operatorId, true);
|
||||
requireKey(key);
|
||||
return persist(scope, taskId, key, request, hash(request), operatorId, operatorName);
|
||||
return upsert(taskId, key, request, operatorId, operatorName, hash(request));
|
||||
}
|
||||
|
||||
private EvidenceList persist(Scope scope, long taskId, String key, UpsertRequest request,
|
||||
String requestHash, long operatorId, String operatorName) {
|
||||
private EvidenceList upsert(long taskId, String key, UpsertRequest request, long operatorId,
|
||||
String operatorName, String requestHash) {
|
||||
Scope scope = scope(taskId, request.warehouseId(), operatorId, true);
|
||||
requireKey(key);
|
||||
CabinetLoadingEvidenceEntity replay = mapper.byOperation(taskId, key);
|
||||
if (replay != null) {
|
||||
if (!Objects.equals(requestHash, replay.getRequestHash())) throw conflict("相同幂等键的请求内容不一致");
|
||||
@@ -93,22 +93,20 @@ public class CabinetLoadingEvidenceService {
|
||||
long operatorId, String operatorName) {
|
||||
Scope scope = scope(taskId, warehouseId, operatorId, true);
|
||||
requireKey(key);
|
||||
String type = evidenceType.trim();
|
||||
if (!LoadingEvidenceType.VALUES.contains(type)) throw bad("不支持的装柜证据类型");
|
||||
String normalizedSealNo = LoadingEvidenceType.SEAL.equals(type) ? normalizedSeal(sealNo) : null;
|
||||
String requestHash = hash(new UploadHashRequest(warehouseId, expectedVersion, type,
|
||||
normalizedSealNo, remark, multipartHash(multipart)));
|
||||
String requestHash = uploadHash(warehouseId, expectedVersion, evidenceType, sealNo, remark, multipart);
|
||||
CabinetLoadingEvidenceEntity replay = mapper.byOperation(taskId, key);
|
||||
if (replay != null) {
|
||||
if (!Objects.equals(requestHash, replay.getRequestHash())) throw conflict("相同幂等键的请求内容不一致");
|
||||
if (!Objects.equals(requestHash, replay.getRequestHash())) {
|
||||
throw conflict("相同幂等键的请求内容不一致");
|
||||
}
|
||||
return view(scope);
|
||||
}
|
||||
try {
|
||||
var response = files.upload(internalToken, operatorId, scope.containerBookingId(), type, multipart);
|
||||
var response = files.upload(internalToken, operatorId, scope.containerBookingId(), evidenceType, multipart);
|
||||
var uploaded = response == null ? null : response.data();
|
||||
if (uploaded == null) throw new BizException(ResultCode.SERVICE_UNAVAILABLE, "装柜证据文件上传失败");
|
||||
return persist(scope, taskId, key, new UpsertRequest(warehouseId, expectedVersion, type,
|
||||
uploaded.fileId(), normalizedSealNo, remark), requestHash, operatorId, operatorName);
|
||||
return upsert(taskId, key, new UpsertRequest(warehouseId, expectedVersion, evidenceType,
|
||||
uploaded.fileId(), sealNo, remark), operatorId, operatorName, requestHash);
|
||||
} catch (FeignException exception) {
|
||||
throw new BizException(ResultCode.SERVICE_UNAVAILABLE, "文件服务暂不可用");
|
||||
}
|
||||
@@ -197,9 +195,17 @@ public class CabinetLoadingEvidenceService {
|
||||
objectMapper.writeValueAsString(value).getBytes(StandardCharsets.UTF_8))); }
|
||||
catch (JsonProcessingException | NoSuchAlgorithmException exception) { throw new IllegalStateException(exception); }
|
||||
}
|
||||
private static String multipartHash(MultipartFile file) {
|
||||
private static String uploadHash(long warehouseId, int expectedVersion, String evidenceType,
|
||||
String sealNo, String remark, MultipartFile multipart) {
|
||||
try {
|
||||
return HexFormat.of().formatHex(MessageDigest.getInstance("SHA-256").digest(file.getBytes()));
|
||||
MessageDigest digest = MessageDigest.getInstance("SHA-256");
|
||||
String metadata = warehouseId + "|" + expectedVersion + "|" + evidenceType + "|"
|
||||
+ Objects.toString(sealNo, "") + "|" + Objects.toString(remark, "") + "|"
|
||||
+ Objects.toString(multipart.getOriginalFilename(), "") + "|"
|
||||
+ Objects.toString(multipart.getContentType(), "") + "|" + multipart.getSize() + "|";
|
||||
digest.update(metadata.getBytes(StandardCharsets.UTF_8));
|
||||
digest.update(multipart.getBytes());
|
||||
return HexFormat.of().formatHex(digest.digest());
|
||||
} catch (IOException exception) {
|
||||
throw bad("装柜证据文件读取失败");
|
||||
} catch (NoSuchAlgorithmException exception) {
|
||||
@@ -214,7 +220,5 @@ public class CabinetLoadingEvidenceService {
|
||||
private static BizException bad(String message) { return new BizException(ResultCode.BAD_REQUEST, message); }
|
||||
private static BizException conflict(String message) { return new BizException(ResultCode.CONFLICT, message); }
|
||||
private static String id(Long value) { return value == null ? null : value.toString(); }
|
||||
private record UploadHashRequest(long warehouseId, int expectedVersion, String evidenceType,
|
||||
String sealNo, String remark, String fileHash) {}
|
||||
private record Scope(LoadingPickTaskEntity task, long containerBookingId) {}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user