Quellcode durchsuchen

提交注册对象修改

chenxiaofei vor 17 Stunden
Ursprung
Commit
34f26ab07c

+ 74 - 0
sckw-modules/sckw-fleet/src/main/java/com/sckw/fleet/model/vo/DriverRegisterResultVo.java

@@ -0,0 +1,74 @@
+package com.sckw.fleet.model.vo;
+
+import com.sckw.fleet.model.KwfDriver;
+import lombok.Data;
+
+import java.io.Serializable;
+
+/**
+ * 司机自助注册响应对象。
+ * <p>
+ * 仅返回前端注册成功后需要的司机基础信息,避免直接暴露司机实体中的密码、盐值等内部字段。
+ * </p>
+ */
+@Data
+public class DriverRegisterResultVo implements Serializable {
+
+    private static final long serialVersionUID = 1L;
+
+    /**
+     * 司机ID。
+     */
+    private Long driverId;
+
+    /**
+     * 所属企业ID。
+     */
+    private Long entId;
+
+    /**
+     * 司机姓名。
+     */
+    private String name;
+
+    /**
+     * 手机号。
+     */
+    private String phone;
+
+    /**
+     * 身份证号。
+     */
+    private String idcard;
+
+    /**
+     * 认证状态。
+     */
+    private Integer authStatus;
+
+    /**
+     * 账号状态。
+     */
+    private Integer status;
+
+    /**
+     * 根据司机实体构建注册响应对象。
+     *
+     * @param driver 司机实体
+     * @return 注册响应对象
+     */
+    public static DriverRegisterResultVo from(KwfDriver driver) {
+        if (driver == null) {
+            return null;
+        }
+        DriverRegisterResultVo resultVo = new DriverRegisterResultVo();
+        resultVo.setDriverId(driver.getId());
+        resultVo.setEntId(driver.getEntId());
+        resultVo.setName(driver.getName());
+        resultVo.setPhone(driver.getPhone());
+        resultVo.setIdcard(driver.getIdcard());
+        resultVo.setAuthStatus(driver.getAuthStatus());
+        resultVo.setStatus(driver.getStatus());
+        return resultVo;
+    }
+}

+ 2 - 2
sckw-modules/sckw-fleet/src/main/java/com/sckw/fleet/service/KwfDriverService.java

@@ -597,7 +597,7 @@ public class KwfDriverService {
      * </p>
      *
      * @param params 注册入参(物流企业、姓名、身份证号、手机号、短信验证码)
-     * @return 注册成功返回司机档案;校验失败返回对应错误信息
+     * @return 注册成功返回司机注册响应对象;校验失败返回对应错误信息
      */
     @Transactional(rollbackFor = Exception.class)
     public HttpResult register(DriverRegisterDto params) {
@@ -674,7 +674,7 @@ public class KwfDriverService {
 
         log.info("司机自助注册成功,driverId={}, phone={}, entId={}, firmName={}",
                 driver.getId(), maskPhone(params.getPhone()), params.getEntId(), entCache.getFirmName());
-        return HttpResult.ok("注册成功", driver);
+        return HttpResult.ok("注册成功", DriverRegisterResultVo.from(driver));
     }
 
     /**

+ 47 - 0
sckw-modules/sckw-fleet/src/test/java/com/sckw/fleet/model/DriverRegisterResultVoTest.java

@@ -0,0 +1,47 @@
+package com.sckw.fleet.model;
+
+import com.sckw.fleet.model.vo.DriverRegisterResultVo;
+import org.junit.Assert;
+import org.junit.Test;
+
+/**
+ * 司机自助注册响应对象单元测试。
+ */
+public class DriverRegisterResultVoTest {
+
+    /**
+     * 司机实体应转换为注册响应对象,避免接口直接返回 KwfDriver 实体。
+     */
+    @Test
+    public void fromWhenDriverExists() {
+        KwfDriver driver = new KwfDriver();
+        driver.setId(1001L);
+        driver.setEntId(2001L);
+        driver.setName("张三");
+        driver.setPhone("13800000000");
+        driver.setIdcard("110101199001010011");
+        driver.setAuthStatus(2);
+        driver.setStatus(0);
+        driver.setPassword("secret");
+        driver.setSalt("salt");
+
+        DriverRegisterResultVo resultVo = DriverRegisterResultVo.from(driver);
+
+        Assert.assertNotNull(resultVo);
+        Assert.assertEquals(Long.valueOf(1001L), resultVo.getDriverId());
+        Assert.assertEquals(Long.valueOf(2001L), resultVo.getEntId());
+        Assert.assertEquals("张三", resultVo.getName());
+        Assert.assertEquals("13800000000", resultVo.getPhone());
+        Assert.assertEquals("110101199001010011", resultVo.getIdcard());
+        Assert.assertEquals(Integer.valueOf(2), resultVo.getAuthStatus());
+        Assert.assertEquals(Integer.valueOf(0), resultVo.getStatus());
+    }
+
+    /**
+     * 空司机实体应返回空,调用方可按原有空值逻辑处理。
+     */
+    @Test
+    public void fromWhenDriverIsNull() {
+        Assert.assertNull(DriverRegisterResultVo.from(null));
+    }
+}