Bläddra i källkod

车牌验证接口

donglang 4 månader sedan
förälder
incheckning
44ab8df456

+ 12 - 4
iot-platform-manager/src/main/java/com/platform/api/controller/WeighbridgeController.java

@@ -1,17 +1,16 @@
 package com.platform.api.controller;
 
+import com.platform.api.request.LicensePlateValidateRequest;
 import com.platform.api.request.WeighbridgePushRequest;
 import com.platform.exception.BaseResult;
 import com.platform.manage.WeighbridgeRecordManage;
+import com.platform.response.LicensePlateValidateResponse;
 import io.swagger.v3.oas.annotations.Operation;
-import io.swagger.v3.oas.annotations.Parameter;
 import io.swagger.v3.oas.annotations.tags.Tag;
 import lombok.RequiredArgsConstructor;
 import lombok.extern.slf4j.Slf4j;
+import org.springframework.validation.annotation.Validated;
 import org.springframework.web.bind.annotation.*;
-import org.springframework.web.multipart.MultipartFile;
-
-import java.math.BigDecimal;
 
 /**
  * 地磅数据上报接口
@@ -36,4 +35,13 @@ public class WeighbridgeController {
         // 调用业务层处理;
         return BaseResult.success(weighbridgeRecordManage.handleWeighbridgePush(request));
     }
+
+    /**
+     * 车牌验证
+     */
+    @Operation(summary = "车牌验证", description = "用于验证车牌是否合法,允许上磅")
+    @PostMapping("/validateLicensePlate")
+    public LicensePlateValidateResponse validateLicensePlate(@RequestParam @Validated LicensePlateValidateRequest request, @RequestHeader("uuid") String uuid) {
+        return weighbridgeRecordManage.handleValidateLicensePlate(request);
+    }
 }

+ 34 - 0
iot-platform-manager/src/main/java/com/platform/api/request/LicensePlateValidateRequest.java

@@ -0,0 +1,34 @@
+package com.platform.api.request;
+
+import io.swagger.v3.oas.annotations.media.Schema;
+import jakarta.validation.constraints.NotBlank;
+import jakarta.validation.constraints.NotNull;
+import lombok.Data;
+
+/**
+ * 车牌验证请求参数
+ * @author PC
+ */
+@Data
+@Schema(description = "地磅过磅数据上报请求参数")
+public class LicensePlateValidateRequest {
+
+    /**
+     * 车牌号
+     */
+    @NotBlank(message = "车牌号不能为空")
+    private String licensePlate;
+
+    /**
+     * 地磅编码
+     */
+    @NotBlank(message = "地磅编码不能为空")
+    private String weighbridgeCode;
+
+    /**
+     * 时间
+     */
+    @NotNull(message = "时间不能为空")
+    private Integer timestamp;
+
+}

+ 47 - 0
iot-platform-manager/src/main/java/com/platform/entity/ValidateLicensePlate.java

@@ -0,0 +1,47 @@
+package com.platform.entity;
+
+import com.baomidou.mybatisplus.annotation.*;
+import lombok.Data;
+
+import java.time.LocalDateTime;
+
+/**
+ * 地磅过磅记录表实体类
+ *
+ * @author cxf
+ */
+@Data
+@TableName("validate_License_Plate")
+public class ValidateLicensePlate {
+
+    /**
+     * 主键ID
+     */
+    @TableId(value = "id", type = IdType.AUTO)
+    private Long id;
+
+    /**
+     * 车牌号
+     */
+    @TableField("license_plate")
+    private String licensePlate;
+
+    /**
+     * 状态,0=可用,1=不可用
+     */
+    @TableField("status")
+    private Integer status;
+
+    /**
+     * 记录创建时间
+     */
+    @TableField(value = "created_at", fill = FieldFill.INSERT)
+    private LocalDateTime createdAt;
+
+    /**
+     * 记录更新时间
+     */
+    @TableField(value = "updated_at", fill = FieldFill.INSERT_UPDATE)
+    private LocalDateTime updatedAt;
+
+}

+ 41 - 0
iot-platform-manager/src/main/java/com/platform/manage/WeighbridgeRecordManage.java

@@ -1,9 +1,13 @@
 package com.platform.manage;
 
+import com.platform.api.request.LicensePlateValidateRequest;
 import com.platform.api.request.WeighbridgePushRequest;
+import com.platform.entity.ValidateLicensePlate;
 import com.platform.entity.WeighbridgeRecord;
 import com.platform.enums.ErrorCodeEnum;
 import com.platform.exception.IotException;
+import com.platform.response.LicensePlateValidateResponse;
+import com.platform.service.ValidateLicensePlateService;
 import com.platform.service.WeighbridgeRecordService;
 import lombok.RequiredArgsConstructor;
 import lombok.extern.slf4j.Slf4j;
@@ -27,6 +31,8 @@ public class WeighbridgeRecordManage {
 
     private final WeighbridgeRecordService weighbridgeRecordService;
 
+    private final ValidateLicensePlateService validateLicensePlateService;
+
     /**
      * 处理地磅过磅数据上报
      * @param request 地磅上报请求参数
@@ -121,4 +127,39 @@ public class WeighbridgeRecordManage {
             throw new IotException(ErrorCodeEnum.PARAM_ERROR, "时间戳格式错误,仅支持10位秒级或13位毫秒级时间戳");
         }
     }
+
+    /**
+     * 车牌验证
+     * @param request 地磅上报请求参数
+     * @return 是否保存成功
+     */
+    public LicensePlateValidateResponse handleValidateLicensePlate(LicensePlateValidateRequest request) {
+        log.info("车牌验证, 车牌:{}, 地磅编号:{}, 时间戳:{}", request.getLicensePlate(), request.getWeighbridgeCode(), request.getTimestamp());
+        LicensePlateValidateResponse response = new LicensePlateValidateResponse();
+        //查询车牌是不存在
+        ValidateLicensePlate validateLicensePlate = validateLicensePlateService.queryByLicensePlate(request.getLicensePlate());
+        if (validateLicensePlate != null) {
+            response.setStatus(Boolean.TRUE);
+            response.setCode(200);
+            response.setMessage("上报成功,请放行");
+
+            response.setData(new LicensePlateValidateResponse.Data());
+            response.getData().setTimestamp(System.currentTimeMillis());
+            response.getData().setScreen_message("车辆请下磅");
+            response.getData().setVoice_message("车辆请下磅");
+            response.getData().setWarning(null);
+        } else {
+            response.setStatus(Boolean.FALSE);
+            response.setCode(400);
+            response.setMessage("上报异常,请稍后");
+
+            response.setData(new LicensePlateValidateResponse.Data());
+            response.getData().setTimestamp(System.currentTimeMillis());
+            response.getData().setScreen_message("数据上报异常,请联系管理员");
+            response.getData().setVoice_message("数据上报异常,请联系管理员");
+            response.getData().setWarning(null);
+        }
+        return response;
+    }
+
 }

+ 15 - 0
iot-platform-manager/src/main/java/com/platform/mapper/ValidateLicensePlateMapper.java

@@ -0,0 +1,15 @@
+package com.platform.mapper;
+
+import com.baomidou.mybatisplus.core.mapper.BaseMapper;
+import com.platform.entity.ValidateLicensePlate;
+import org.apache.ibatis.annotations.Mapper;
+
+/**
+ * @Author: cxf
+ * @CreateTime: 2026-01-21
+ * @Description: 地磅过磅记录Mapper接口
+ * @Version: 1.0
+ */
+@Mapper
+public interface ValidateLicensePlateMapper extends BaseMapper<ValidateLicensePlate> {
+}

+ 58 - 0
iot-platform-manager/src/main/java/com/platform/response/LicensePlateValidateResponse.java

@@ -0,0 +1,58 @@
+package com.platform.response;
+
+
+import lombok.Data;
+
+/**
+ * Author: donglang
+ * Time: 2026-01-21
+ * Des: 车牌验证通用返回模型
+ * Version: 1.0
+ */
+
+@Data
+public class LicensePlateValidateResponse {
+    /**
+     * 状态
+     */
+    private Boolean status;
+
+    /**
+     * 编码
+     */
+    private Integer code;
+
+    /**
+     * 信息
+     */
+    private String message;
+
+    /**
+     * 数据
+     */
+    private Data data;
+
+    @lombok.Data
+    public static class Data {
+
+        /**
+         * 时间搓
+         */
+        private Long timestamp;
+
+        /**
+         * 内容1
+         */
+        private String screen_message;
+
+        /**
+         * 内容2
+         */
+        private String voice_message;
+
+        /**
+         * 警告
+         */
+        private String warning;
+    }
+}

+ 16 - 0
iot-platform-manager/src/main/java/com/platform/service/ValidateLicensePlateService.java

@@ -0,0 +1,16 @@
+package com.platform.service;
+
+import com.baomidou.mybatisplus.extension.service.IService;
+import com.platform.entity.ValidateLicensePlate;
+
+/**
+ * @Author: cxf
+ * @CreateTime: 2026-01-21
+ * @Description: 地磅过磅记录Service接口
+ * @Version: 1.0
+ */
+public interface ValidateLicensePlateService extends IService<ValidateLicensePlate> {
+
+    ValidateLicensePlate queryByLicensePlate(String licensePlate);
+
+}

+ 27 - 0
iot-platform-manager/src/main/java/com/platform/service/impl/ValidateLicensePlateServiceImpl.java

@@ -0,0 +1,27 @@
+package com.platform.service.impl;
+
+import com.baomidou.mybatisplus.core.toolkit.Wrappers;
+import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
+import com.platform.entity.ValidateLicensePlate;
+import com.platform.mapper.ValidateLicensePlateMapper;
+import com.platform.service.ValidateLicensePlateService;
+import org.springframework.stereotype.Service;
+
+/**
+ * @Author: cxf
+ * @CreateTime: 2026-01-21
+ * @Description: 地磅过磅记录Service实现类
+ * @Version: 1.0
+ */
+@Service
+public class ValidateLicensePlateServiceImpl extends ServiceImpl<ValidateLicensePlateMapper, ValidateLicensePlate> implements ValidateLicensePlateService {
+
+    @Override
+    public ValidateLicensePlate queryByLicensePlate(String licensePlate) {
+        return getOne(Wrappers.<ValidateLicensePlate>lambdaQuery()
+                .eq(ValidateLicensePlate::getLicensePlate, licensePlate)
+                .eq(ValidateLicensePlate::getStatus, 0)
+                .last("limit 1"));
+    }
+
+}

+ 13 - 1
sql/2026/01/create_cxf.sql

@@ -13,4 +13,16 @@ CREATE TABLE weighbridge_records (
                                      KEY `idx_weighbridge_code` (`weighbridge_code`),
                                      KEY `idx_weighbridge_name` (`weighbridge_name`),
                                      KEY `idx_license_plate` (`license_plate`)
-) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='地磅过磅记录表';
+) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='地磅过磅记录表';
+
+
+
+CREATE TABLE validate_License_Plate (
+                                     `id` BIGINT UNSIGNED NOT NULL AUTO_INCREMENT COMMENT '主键ID',
+                                     license_plate VARCHAR(20) NOT NULL DEFAULT '' COMMENT '车牌号',
+                                     status tinyint NOT NULL DEFAULT '0' COMMENT '状态,0=可用,1=不可用',
+                                     created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP COMMENT '记录创建时间',
+                                     updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '记录更新时间',
+                                     PRIMARY KEY (`id`),
+                                     KEY `idx_license_plate` (`license_plate`)
+) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='车牌验证表';