2
0

feat: support kyc on user and system module

This commit is contained in:
zhangsz
2025-01-10 11:03:34 +08:00
parent 832b5a86a8
commit 55e7c22469
19 changed files with 405 additions and 40 deletions

View File

@@ -724,7 +724,6 @@ CREATE TABLE `u_user` (
`age` int(11) NULL DEFAULT NULL COMMENT '年龄',
`address` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT NULL COMMENT '地址',
`status` char(1) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT '0' COMMENT '帐号状态0正常 1停用',
`kyc_status` enum('VERIFIED','UNVERIFIED') CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT 'UNVERIFIED',
`del_flag` char(1) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT '0' COMMENT '删除标志0代表存在 2代表删除',
`login_ip` varchar(128) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT '' COMMENT '最后登录IP',
`login_date` datetime NULL DEFAULT NULL COMMENT '最后登录时间',
@@ -739,9 +738,9 @@ CREATE TABLE `u_user` (
-- ----------------------------
-- Records of u_user
-- ----------------------------
INSERT INTO `u_user` VALUES (1, 100, 'super', '超级用户', '超级用户', '00', 'super@mail.com', '123456', '1', '', '$2a$10$XF99QEWn2MjEE3pbFVvHuOyMi/YVIrQbdenEleJN5dYxAfgXFaaqG', 1, '', '0', 'UNVERIFIED', '0', '192.168.88.14', '2024-12-06 10:36:35', 'system', '2024-05-08 21:50:54', '', '2024-12-06 10:36:35', 'super');
INSERT INTO `u_user` VALUES (2, 100, 'demo', 'demo user', 'demo user', '00', 'demo@mail.com', '123456', '1', '', '$2a$10$XF99QEWn2MjEE3pbFVvHuOyMi/YVIrQbdenEleJN5dYxAfgXFaaqG', 1, '', '0', 'UNVERIFIED', '0', '192.168.88.14', '2024-12-06 10:36:35', 'system', '2024-12-06 10:30:54', '', '2024-12-06 10:36:35', 'demo');
INSERT INTO `u_user` VALUES (3, NULL, '123456', 'general user', 'general user', '00', '12345678@mail.com', '1234567', '1', '', '$2a$10$XF99QEWn2MjEE3pbFVvHuOyMi/YVIrQbdenEleJN5dYxAfgXFaaqG', 1, '', '0', 'UNVERIFIED', '0', '192.168.2.94', '2024-12-16 17:36:08', 'system', '2024-05-08 21:50:54', '123456', '2024-12-16 17:36:08', '');
INSERT INTO `u_user` VALUES (1, 100, 'super', '超级用户', '超级用户', '00', 'super@mail.com', '123456', '1', '', '$2a$10$XF99QEWn2MjEE3pbFVvHuOyMi/YVIrQbdenEleJN5dYxAfgXFaaqG', 1, '', '0', '0', '192.168.88.14', '2024-12-06 10:36:35', 'system', '2024-05-08 21:50:54', '', '2024-12-06 10:36:35', 'super');
INSERT INTO `u_user` VALUES (2, 100, 'demo', 'demo user', 'demo user', '00', 'demo@mail.com', '123456', '1', '', '$2a$10$XF99QEWn2MjEE3pbFVvHuOyMi/YVIrQbdenEleJN5dYxAfgXFaaqG', 1, '', '0', '0', '192.168.88.14', '2024-12-06 10:36:35', 'system', '2024-12-06 10:30:54', '', '2024-12-06 10:36:35', 'demo');
INSERT INTO `u_user` VALUES (3, NULL, '123456', 'general user', 'general user', '00', '12345678@mail.com', '1234567', '1', '', '$2a$10$XF99QEWn2MjEE3pbFVvHuOyMi/YVIrQbdenEleJN5dYxAfgXFaaqG', 1, '', '0', '0', '192.168.2.94', '2024-12-16 17:36:08', 'system', '2024-05-08 21:50:54', '123456', '2024-12-16 17:36:08', '');
-- ----------------------------
-- Table structure for u_user_post

View File

@@ -0,0 +1,79 @@
package org.wfc.system.controller;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.wfc.common.core.web.controller.BaseController;
import org.wfc.common.core.web.domain.AjaxResult;
import org.wfc.common.core.web.page.TableDataInfo;
import org.wfc.system.domain.UKyc;
import org.wfc.system.domain.bo.UKycUserBo;
import org.wfc.system.domain.constant.KycStatusEnum;
import org.wfc.system.domain.vo.UKycUserVo;
import org.wfc.system.service.IUKycService;
import java.util.List;
/**
* <p>
* User Portal-User KYC table contorller
* </p>
*
* @author sys
* @since 2025-01-08
*/
@RestController
@RequestMapping("/kyc")
public class UKycController extends BaseController {
private static final Logger log = LoggerFactory.getLogger(UKycController.class);
@Autowired
private IUKycService uKycService;
@GetMapping("/page")
public TableDataInfo selectKycByUserId(UKycUserBo item) {
log.debug("item: {}", item);
startPage();
List<UKycUserVo> list = uKycService.selectKycByUserId(item);
return getDataTable(list);
}
@GetMapping("/list")
public AjaxResult list(UKycUserBo item) {
startPage();
List<UKycUserVo> list = uKycService.selectKycByUserId(item);
return success(list);
}
@GetMapping(value = "/{id}")
public AjaxResult getById(@PathVariable("id") Long id) {
return success(uKycService.getById(id));
}
@PutMapping("/approve")
public AjaxResult approve(@RequestBody UKyc uKyc) {
// set user kyc status to verified
uKyc.setStatus(KycStatusEnum.VERIFIED.getCode());
log.debug("uKyc: {}", uKyc);
return toAjax(uKycService.updateKycByUserId(uKyc));
}
@PutMapping("/reject")
public AjaxResult reject(@RequestBody UKyc uKyc) {
// set kyc request status to rejected and put the description in the database
uKyc.setStatus(KycStatusEnum.REJECTED.getCode());
return toAjax(uKycService.updateKycByUserId(uKyc));
}
// @DeleteMapping("/{ids}")
// public AjaxResult remove(@PathVariable Long[] ids) {
// return toAjax(uKycService.removeByIds(CollUtil.newArrayList(ids)));
// }
}

View File

@@ -0,0 +1,48 @@
package org.wfc.system.domain;
import com.baomidou.mybatisplus.annotation.TableName;
import org.wfc.common.mybatis.domain.BaseData;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.NoArgsConstructor;
@Data
@NoArgsConstructor
@AllArgsConstructor
@Builder
@EqualsAndHashCode(callSuper = true)
@TableName("u_kyc")
@Schema(name = "UKyc", description = "User portal: u_kyc table")
public class UKyc extends BaseData {
private static final long serialVersionUID = 1L;
@Schema(description = "KYC ID")
private Long kycId;
@Schema(description = "User ID")
private Long userId;
@Schema(description = "Birth Date")
private String birthDate;
@Schema(description = "Identify Type")
private Integer idType;
@Schema(description = "Identify File")
private String idFile;
@Schema(description = "Identify Picture")
private String identifyPicture;
@Schema(description = "Status")
private Integer status;
@Schema(description = "Description")
private String description;
}

View File

@@ -0,0 +1,16 @@
package org.wfc.system.domain.bo;
import lombok.Data;
/**
* @description: Kyc User Bo
* @since: 2025-01-09
*/
@Data
public class UKycUserBo {
private Long userId;
private String userName;
private Integer status;
private String createTimeStart;
private String createTimeEnd;
}

View File

@@ -0,0 +1,24 @@
package org.wfc.system.domain.constant;
import lombok.AllArgsConstructor;
import lombok.Getter;
/**
* @description: 证件类型枚举
* @since: 2025-01-08
*/
@Getter
@AllArgsConstructor
public enum IdTypeEnum {
DRIVERS_LICENSE(1, "driver's license"),
PASSPORT(2, "passport"),
RESIDENCE_PERMIT(3, "residence permit"),
STUDENT_ID(4, "student ID"),
MEDICARE_CARD(5, "medicare card"),
BIRTH_CERTIFICATE(6, "birth certificate");
private final Integer code;
private final String desc;
}

View File

@@ -0,0 +1,21 @@
package org.wfc.system.domain.constant;
import lombok.AllArgsConstructor;
import lombok.Getter;
/**
* @description: KYC request status enum
* @since: 2025-01-08
*/
@Getter
@AllArgsConstructor
public enum KycStatusEnum {
VERIFIED(1, "verified"),
UNVERIFIED(2, "unverified"),
PENDING(3, "pending"),
REJECTED(4, "rejected");
private final Integer code;
private final String desc;
}

View File

@@ -0,0 +1,19 @@
package org.wfc.system.domain.constant;
import lombok.AllArgsConstructor;
import lombok.Getter;
/**
* @description: User KYC status enum
* @since: 2025-01-08
*/
@Getter
@AllArgsConstructor
public enum UserKycStatusEnum {
VERIFIED(1, "verified"),
UNVERIFIED(2, "unverified");
private final Integer code;
private final String desc;
}

View File

@@ -0,0 +1,20 @@
package org.wfc.system.domain.vo;
import lombok.Data;
import org.wfc.system.domain.constant.IdTypeEnum;
import org.wfc.system.domain.constant.KycStatusEnum;
@Data
public class UKycUserVo {
private Long kycId;
private Long userId;
private String userName;
private String birthDate;
private IdTypeEnum idType;
private String idFile;
private String identifyPicture;
private KycStatusEnum status;
private String description;
private String createTime;
}

View File

@@ -0,0 +1,24 @@
package org.wfc.system.mapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import java.util.List;
import com.baomidou.dynamic.datasource.annotation.DS;
import org.apache.ibatis.annotations.Param;
import org.wfc.system.domain.UKyc;
import org.wfc.system.domain.vo.UKycUserVo;
import org.wfc.system.domain.bo.UKycUserBo;
/**
* <p>
* 用户平台-KYC表 Mapper 接口
* </p>
*
* @author sys
* @since 2025-01-08
*/
@DS("user")
public interface UKycMapper extends BaseMapper<UKyc> {
List<UKycUserVo> selectKycByUserId(@Param("item") UKycUserBo item);
public int updateKycByUserId(UKyc uKyc);
}

View File

@@ -0,0 +1,23 @@
package org.wfc.system.service;
import com.baomidou.mybatisplus.extension.service.IService;
import java.util.List;
import org.wfc.system.domain.UKyc;
import org.wfc.system.domain.bo.UKycUserBo;
import org.wfc.system.domain.vo.UKycUserVo;
/**
* <p>
* 用户平台-KYC表 服务类
* </p>
*
* @author sys
* @since 2025-01-08
*/
public interface IUKycService extends IService<UKyc> {
List<UKycUserVo> selectKycByUserId(UKycUserBo item);
public int updateKycByUserId(UKyc uKyc);
}

View File

@@ -0,0 +1,39 @@
package org.wfc.system.service.impl;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.wfc.system.domain.UKyc;
import org.wfc.system.domain.vo.UKycUserVo;
import org.wfc.system.domain.bo.UKycUserBo;
import org.wfc.system.mapper.UKycMapper;
import org.wfc.system.service.IUKycService;
/**
* <p>
* 用户平台-KYC表 服务实现类
* </p>
*
* @author sys
* @since 2025-01-09
*/
@Service
public class UKycServiceImpl extends ServiceImpl<UKycMapper, UKyc> implements IUKycService {
@Autowired
private UKycMapper uKycMapper;
@Override
public List<UKycUserVo> selectKycByUserId(UKycUserBo item) {
return this.uKycMapper.selectKycByUserId(item);
}
@Override
public int updateKycByUserId(UKyc uKyc) {
return this.uKycMapper.updateKycByUserId(uKyc);
}
}

View File

@@ -0,0 +1,57 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="org.wfc.system.mapper.UKycMapper">
<select id="selectKycByUserId" resultType="org.wfc.system.domain.vo.UKycUserVo">
SELECT
k.kyc_id,
k.user_id,
u.user_name,
k.birth_date,
k.id_type,
k.id_file,
k.identify_picture,
k.`status`,
<!-- u.`kyc_status` as user_kyc_status, -->
k.create_time,
k.update_time
FROM
u_kyc k
LEFT JOIN u_user u ON u.user_id = k.user_id
WHERE
u.del_flag = 0
AND k.del_flag = 0
<if test="item.userId != null and item.userId != ''">
AND k.user_id = #{item.userId}
</if>
<if test="item.userName != null and item.userName != ''">
AND u.user_name like concat('%', #{item.userName}, '%')
</if>
<if test="item.userName != null and item.userName != ''">
AND u.user_name like concat('%', #{item.userName}, '%')
</if>
<if test="item.status != null and item.status != ''">
AND k.`status` = #{item.status}
</if>
<if test="item.createTimeStart != null and item.createTimeStart != ''">
AND k.create_time &gt;= #{item.createTimeStart}
</if>
<if test="item.createTimeEnd != null and item.createTimeEnd != ''">
AND k.create_time &lt;= #{item.createTimeEnd}
</if>
ORDER BY
k.create_time DESC
</select>
<update id="updateKycByUserId" parameterType="UKyc">
UPDATE u_kyc
<set>
<if test="status != null and status != 0">status = #{status},</if>
<if test="description != null and description != ''">description = #{description},</if>
<if test="updateBy != null and updateBy != ''">update_by = #{updateBy},</if>
update_time = sysdate()
</set>
WHERE user_id = #{userId}
</update>
</mapper>

View File

@@ -1,12 +1,7 @@
package org.wfc.user.domain;
import java.time.LocalDateTime;
import com.baomidou.mybatisplus.annotation.TableName;
import org.wfc.common.mybatis.domain.BaseData;
import org.wfc.user.domain.constant.IdTypeEnum;
import org.wfc.user.domain.constant.KycRequestStatusEnum;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.AllArgsConstructor;
import lombok.Builder;

View File

@@ -11,12 +11,12 @@ import lombok.Getter;
@AllArgsConstructor
public enum IdTypeEnum {
DRIVERS_LICENSE(0, "driver's license"),
PASSPORT(1, "passport"),
RESIDENCE_PERMIT(2, "residence permit"),
STUDENT_ID(3, "student ID"),
MEDICARE_CARD(4, "medicare card"),
BIRTH_CERTIFICATE(5, "birth certificate");
DRIVERS_LICENSE(1, "driver's license"),
PASSPORT(2, "passport"),
RESIDENCE_PERMIT(3, "residence permit"),
STUDENT_ID(4, "student ID"),
MEDICARE_CARD(5, "medicare card"),
BIRTH_CERTIFICATE(6, "birth certificate");
private final Integer code;
private final String desc;

View File

@@ -9,11 +9,12 @@ import lombok.Getter;
*/
@Getter
@AllArgsConstructor
public enum KycRequestStatusEnum {
public enum KycStatusEnum {
APPROVED(0, "approved"),
REJECTED(1, "rejected"),
PENDING(2, "pending");
VERIFIED(1, "verified"),
UNVERIFIED(2, "unverified"),
PENDING(3, "pending"),
REJECTED(4, "rejected");
private final Integer code;
private final String desc;

View File

@@ -11,8 +11,8 @@ import lombok.Getter;
@AllArgsConstructor
public enum UserKycStatusEnum {
VERIFIED(0, "verified"),
UNVERIFIED(1, "unverified");
VERIFIED(1, "verified"),
UNVERIFIED(2, "unverified");
private final Integer code;
private final String desc;

View File

@@ -28,11 +28,11 @@ public class UKycUserVo {
@Schema(description = "Identify Picture")
private String identifyPicture;
@Schema(description = "KYC Request Status")
private KycRequestStatusEnum kycRequestStatus;
@Schema(description = "KYC Status")
private KycStatusEnum status;
@Schema(description = "User KYC Status")
private UserKycStatusEnum userKycStatus;
@Schema(description = "Description")
private String description;
@Schema(description = "Create Time")
private String createTime;

View File

@@ -9,11 +9,8 @@ import org.springframework.stereotype.Service;
import org.wfc.common.core.domain.LoginUser;
import org.wfc.common.security.utils.SecurityUtils;
import org.wfc.user.domain.UKyc;
import org.wfc.user.domain.constant.IdTypeEnum;
import org.wfc.user.domain.constant.KycRequestStatusEnum;
import org.wfc.user.domain.vo.UKycUserVo;
import org.wfc.user.mapper.UKycMapper;
import org.wfc.user.mapper.UUserMapper;
import org.wfc.user.service.IUKycService;
import java.util.List;
@@ -52,10 +49,6 @@ public class UKycServiceImpl extends ServiceImpl<UKycMapper, UKyc> implements IU
@Override
public int insertUserKyc(UKyc uKyc) {
// // Convert string to enum
// uKyc.setIdType(uKyc.getIdType());
// uKyc.setStatus(uKyc.getStatus());
log.debug("uKyc: {}", uKyc);
if (this.uKycMapper.isExistUserKyc(uKyc.getUserId()) == 0) {
return this.uKycMapper.insertUserKyc(uKyc);

View File

@@ -19,7 +19,7 @@
</resultMap>
<insert id="insertUserKyc" parameterType="UKyc" useGeneratedKeys="true" keyProperty="kycId">
insert into u_kyc(
INSERT INTO u_kyc(
<if test="userId != null and userId != 0">user_id,</if>
<if test="birthDate != null">birth_date,</if>
<if test="idType != null and idType != ''">id_type,</if>
@@ -29,7 +29,7 @@
<if test="description != null and description != ''">description,</if>
<if test="createBy != null and createBy != ''">create_by,</if>
create_time
)values(
)VALUES(
<if test="userId != null and userId != ''">#{userId},</if>
<if test="birthDate != null">STR_TO_DATE(#{birthDate}, '%Y-%m-%d %H:%i:%s'),</if>
<if test="idType != null and idType != ''">#{idType},</if>
@@ -43,7 +43,7 @@
</insert>
<update id="updateUserKyc" parameterType="UKyc">
update u_kyc
UPDATE u_kyc
<set>
<if test="birthDate != null">birth_date = STR_TO_DATE(#{birthDate}, '%Y-%m-%d %H:%i:%s'),</if>
<if test="idType != null and idType != ''">id_type = #{idType},</if>
@@ -54,11 +54,19 @@
<if test="updateBy != null and updateBy != ''">update_by = #{updateBy},</if>
update_time = sysdate()
</set>
where user_id = #{userId}
WHERE user_id = #{userId}
</update>
<select id="isExistUserKyc" parameterType="Long" resultType="int">
select count(1) from u_user where user_id = #{userId} and del_flag = '0'
SELECT
count(1)
FROM
u_kyc k
LEFT JOIN u_user u ON u.user_id = k.user_id
WHERE
k.user_id = #{userId}
AND k.del_flag = '0'
AND u.del_flag = '0'
</select>
<select id="selectKycByUserId" resultType="org.wfc.user.domain.vo.UKycUserVo">
@@ -70,8 +78,8 @@
k.id_type,
k.id_file,
k.identify_picture,
k.`status` as kyc_request_status,
u.`kyc_status` as user_kyc_status,
k.`status`,
<!-- u.`kyc_status` as user_kyc_status, -->
k.create_time,
k.update_time
FROM
@@ -83,5 +91,4 @@
AND k.user_id = #{userId}
</select>
</mapper>