|
|
@@ -0,0 +1,141 @@
|
|
|
+package com.platform.api.controller;
|
|
|
+
|
|
|
+import com.platform.api.manager.WeighbridgeRecordManage;
|
|
|
+import com.platform.api.request.LicensePlateValidateRequest;
|
|
|
+import com.platform.api.request.WeighbridgePushRequest;
|
|
|
+import com.platform.api.response.LicensePlateValidateResponse;
|
|
|
+import com.platform.config.XpCloudProperties;
|
|
|
+import com.platform.exception.IotException;
|
|
|
+import com.platform.external.request.CarInfoReq;
|
|
|
+import com.platform.external.request.WeighbridgeRecordReq;
|
|
|
+import io.swagger.v3.oas.annotations.Operation;
|
|
|
+import io.swagger.v3.oas.annotations.Parameter;
|
|
|
+import io.swagger.v3.oas.annotations.enums.ParameterIn;
|
|
|
+import io.swagger.v3.oas.annotations.tags.Tag;
|
|
|
+import lombok.RequiredArgsConstructor;
|
|
|
+import lombok.extern.slf4j.Slf4j;
|
|
|
+import org.apache.commons.lang3.StringUtils;
|
|
|
+import org.springframework.web.bind.annotation.*;
|
|
|
+import org.springframework.web.multipart.MultipartFile;
|
|
|
+
|
|
|
+import java.math.BigDecimal;
|
|
|
+import java.util.List;
|
|
|
+
|
|
|
+
|
|
|
+/**
|
|
|
+ * 地磅数据上报接口
|
|
|
+ * @author cxf
|
|
|
+ */
|
|
|
+@Tag(name = "地磅数据接口", description = "地磅过磅数据上报相关接口")
|
|
|
+@RestController
|
|
|
+@RequestMapping("/api/v2/device")
|
|
|
+@RequiredArgsConstructor
|
|
|
+@Slf4j
|
|
|
+public class WeighbridgeV2Controller {
|
|
|
+
|
|
|
+ private final WeighbridgeRecordManage weighbridgeRecordManage;
|
|
|
+
|
|
|
+ private static final String SIGNATURE = "Signature";
|
|
|
+ private final XpCloudProperties xpCloudProperties;
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 地磅过磅数据上报
|
|
|
+ */
|
|
|
+ @Operation(summary = "地磅过磅数据上报", description = "接收地磅设备上报的过磅数据和图片")
|
|
|
+ @PostMapping("/weighBridgePush")
|
|
|
+ public LicensePlateValidateResponse weighBridgePush(
|
|
|
+ @Parameter(description = "车牌号") @RequestParam("licensePlate") String licensePlate,
|
|
|
+ @Parameter(description = "地磅编号") @RequestParam("weighbridgeCode") String weighbridgeCode,
|
|
|
+ @Parameter(description = "称重重量(吨)") @RequestParam("grossWeight") String grossWeight,
|
|
|
+ @Parameter(description = "时间戳(秒或毫秒)") @RequestParam("timestamp") String timestamp,
|
|
|
+ @Parameter(description = "处理标签") @RequestParam(value = "tag", required = false) String tag,
|
|
|
+ @Parameter(description = "车辆照片") @RequestParam(value = "images[]", required = false) MultipartFile[] images
|
|
|
+ ) {
|
|
|
+ // 构建请求对象
|
|
|
+ WeighbridgePushRequest request = new WeighbridgePushRequest();
|
|
|
+ String lience = StringUtils.isNotBlank(licensePlate) ? licensePlate.trim().replace("\\r", "").replace("\\n", ""):"";
|
|
|
+ request.setLicensePlate(lience);
|
|
|
+ String weighCode =StringUtils.isNotBlank(weighbridgeCode) ? weighbridgeCode.trim().replace("\\r", "").replace("\\n", ""):"";
|
|
|
+ request.setWeighbridgeCode(weighCode);
|
|
|
+ String rossWeight = StringUtils.isNotBlank(grossWeight) ?grossWeight.trim().replace("\\r", "").replace("\\n", ""):"";
|
|
|
+ request.setGrossWeight(new BigDecimal(rossWeight));
|
|
|
+ String time = StringUtils.isNotBlank(timestamp) ? timestamp.trim().replace("\\r", "").replace("\\n", ""):"";
|
|
|
+ request.setTimestamp(Long.valueOf(time));
|
|
|
+ request.setTag(tag);
|
|
|
+ request.setImages(images);
|
|
|
+
|
|
|
+ // 调用业务层处理
|
|
|
+ return weighbridgeRecordManage.handleWeighbridgePush(request);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 车牌验证
|
|
|
+ */
|
|
|
+ @Operation(summary = "车牌验证", description = "用于验证车牌是否合法,允许上磅")
|
|
|
+ @PostMapping("/validateLicensePlate")
|
|
|
+ public LicensePlateValidateResponse validateLicensePlate(
|
|
|
+ @Parameter(
|
|
|
+ name = SIGNATURE,
|
|
|
+ in = ParameterIn.HEADER)
|
|
|
+ @RequestHeader(value = SIGNATURE, required = false) String printReceiptAuthSn,
|
|
|
+ @RequestBody CarInfoReq req
|
|
|
+ ) {
|
|
|
+ assertPrintReceiptAuthorized(printReceiptAuthSn);
|
|
|
+ LicensePlateValidateRequest request = new LicensePlateValidateRequest();
|
|
|
+ String replac2 = "";
|
|
|
+ if (StringUtils.isNotBlank(req.getLicensePlate())) {
|
|
|
+ String trim = req.getLicensePlate().trim();
|
|
|
+ String replace = trim.replace("\\r", "");
|
|
|
+ String replace1 = replace.replace("\\n", "");
|
|
|
+ replac2 = replace1.replace("\\r\\n", "");
|
|
|
+ }
|
|
|
+
|
|
|
+ request.setLicensePlate(replac2);
|
|
|
+ request.setUuid(req.getUuid());
|
|
|
+ return weighbridgeRecordManage.handleValidateLicensePlate(request);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Operation(summary = "地磅过磅数据上报", description = "接收地磅设备上报的过磅数据和图片")
|
|
|
+ @PostMapping("/weighBridgePushV2")
|
|
|
+ public LicensePlateValidateResponse weighBridgePushV2(
|
|
|
+ @Parameter(
|
|
|
+ name = SIGNATURE,
|
|
|
+ in = ParameterIn.HEADER)
|
|
|
+ @RequestHeader(value = SIGNATURE, required = false) String printReceiptAuthSn,
|
|
|
+ @RequestBody WeighbridgeRecordReq req
|
|
|
+ ) {
|
|
|
+ assertPrintReceiptAuthorized(printReceiptAuthSn);
|
|
|
+ // 构建请求对象
|
|
|
+ WeighbridgePushRequest request = new WeighbridgePushRequest();
|
|
|
+ String lience = StringUtils.isNotBlank(req.getLicensePlate()) ? req.getLicensePlate().trim().replace("\\r", "").replace("\\n", ""):"";
|
|
|
+ request.setLicensePlate(lience);
|
|
|
+ String weighCode =StringUtils.isNotBlank(req.getWeighbridgeCode()) ? req.getWeighbridgeCode().trim().replace("\\r", "").replace("\\n", ""):"";
|
|
|
+ request.setWeighbridgeCode(weighCode);
|
|
|
+ String rossWeight = StringUtils.isNotBlank(req.getGrossWeight()) ? req.getGrossWeight().trim().replace("\\r", "").replace("\\n", ""):"";
|
|
|
+ request.setGrossWeight(new BigDecimal(rossWeight));
|
|
|
+ String time = StringUtils.isNotBlank(req.getTimestamp()) ? req.getTimestamp().trim().replace("\\r", "").replace("\\n", ""):"";
|
|
|
+ request.setTimestamp(Long.valueOf(time));
|
|
|
+ request.setTag(request.getTag());
|
|
|
+ request.setBase64Images(req.getImages());
|
|
|
+
|
|
|
+ // 调用业务层处理
|
|
|
+ return weighbridgeRecordManage.handleWeighbridgePushV2(request);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 简单鉴权:当配置了允许的凭证时,请求头 {@link #SIGNATURE} 的值必须与其一致。
|
|
|
+ *
|
|
|
+ * @param headerSn 请求头 {@code X-Print-Receipt-Auth-Sn} 的取值
|
|
|
+ */
|
|
|
+ private void assertPrintReceiptAuthorized(String headerSn) {
|
|
|
+ if (!xpCloudProperties.isPrintReceiptAuthorizationConfigured()) {
|
|
|
+ log.debug("未配置 xp.dev.print-receipt-authorized-sn,跳过地磅请求头 {} 鉴权", SIGNATURE);
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ if (xpCloudProperties.isUnauthorizedForPrintReceipt(headerSn)) {
|
|
|
+ log.warn("地磅鉴权拒绝:请求头 {} 与配置不一致(已屏蔽具体值)", SIGNATURE);
|
|
|
+ throw new IotException("无权限调用地磅接口");
|
|
|
+
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|