2
0

feat: user portal support kyc certification

This commit is contained in:
zhangsz
2025-01-09 16:33:37 +08:00
parent 992c686882
commit 1d954bafc3
11 changed files with 458 additions and 3 deletions

View File

@@ -0,0 +1,59 @@
package org.wfc.user.controller;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
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.common.log.annotation.Log;
import org.wfc.common.log.enums.BusinessType;
import org.wfc.common.security.annotation.RequiresPermissions;
import org.wfc.user.domain.UKyc;
import org.wfc.user.domain.vo.UKycUserVo;
import org.wfc.user.service.IUKycService;
import java.util.List;
/**
* <p>
* 用户平台-账单表 前端控制器
* </p>
*
* @author sys
* @since 2025-01-06
*/
@RestController
@RequestMapping("/kyc")
public class UKycController extends BaseController {
@Autowired
private IUKycService uKycService;
@RequiresPermissions("Utem:kyc:query")
@GetMapping("/page")
public TableDataInfo page() {
startPage();
List<UKycUserVo> list = uKycService.selectKycByUserId();
return getDataTable(list);
}
@RequiresPermissions("Utem:kyc:add")
@Log(title = "User Management", businessType = BusinessType.INSERT)
@PostMapping("/verify")
public AjaxResult add(@Validated @RequestBody UKyc uKyc) {
return toAjax(uKycService.insertUserKyc(uKyc));
}
@RequiresPermissions("Utem:kyc:edit")
@Log(title = "User Management", businessType = BusinessType.UPDATE)
@PutMapping("/verify")
public AjaxResult edit(@Validated @RequestBody UKyc uKyc) {
return toAjax(uKycService.updateUserKyc(uKyc));
}
}

View File

@@ -0,0 +1,57 @@
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;
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;
// @Schema(description = "Create Time")
// private LocalDateTime createTime;
// @Schema(description = "Update Time")
// private LocalDateTime updateTime;
}

View File

@@ -0,0 +1,24 @@
package org.wfc.user.domain.constant;
import lombok.AllArgsConstructor;
import lombok.Getter;
/**
* @description: 证件类型枚举
* @since: 2025-01-08
*/
@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");
private final Integer code;
private final String desc;
}

View File

@@ -0,0 +1,20 @@
package org.wfc.user.domain.constant;
import lombok.AllArgsConstructor;
import lombok.Getter;
/**
* @description: KYC request status enum
* @since: 2025-01-08
*/
@Getter
@AllArgsConstructor
public enum KycRequestStatusEnum {
APPROVED(0, "approved"),
REJECTED(1, "rejected"),
PENDING(2, "pending");
private final Integer code;
private final String desc;
}

View File

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

View File

@@ -0,0 +1,39 @@
package org.wfc.user.domain.vo;
import org.wfc.user.domain.constant.*;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
@Data
public class UKycUserVo {
@Schema(description = "KYC ID")
private Long kycId;
@Schema(description = "User ID")
private Long userId;
@Schema(description = "Real Name")
private String userName;
@Schema(description = "Birth Date")
private String birthDate;
@Schema(description = "ID Type")
private IdTypeEnum idType;
@Schema(description = "ID File")
private String idFile;
@Schema(description = "Identify Picture")
private String identifyPicture;
@Schema(description = "KYC Request Status")
private KycRequestStatusEnum kycRequestStatus;
@Schema(description = "User KYC Status")
private UserKycStatusEnum userKycStatus;
@Schema(description = "Create Time")
private String createTime;
}

View File

@@ -0,0 +1,28 @@
package org.wfc.user.mapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Param;
import org.wfc.user.domain.UKyc;
import org.wfc.user.domain.vo.UKycUserVo;
import java.util.List;
/**
* <p>
* 用户平台-KYC表 Mapper 接口
* </p>
*
* @author sys
* @since 2025-01-08
*/
public interface UKycMapper extends BaseMapper<UKyc> {
public int isExistUserKyc(Long userId);
public int insertUserKyc(UKyc uKyc);
public int updateUserKyc(UKyc uKyc);
List<UKycUserVo> selectKycByUserId(@Param("userId") Long userId);
}

View File

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

View File

@@ -0,0 +1,71 @@
package org.wfc.user.service.impl;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
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;
/**
* <p>
* 用户平台-KYC表 服务实现类
* </p>
*
* @author sys
* @since 2025-01-08
*/
@Service
public class UKycServiceImpl extends ServiceImpl<UKycMapper, UKyc> implements IUKycService {
private static final Logger log = LoggerFactory.getLogger(UKycServiceImpl.class);
@Autowired
private UKycMapper uKycMapper;
// @Override
// public List<UKycUserVo> selectKycByUserId(Long userId) {
// return this.baseMapper.selectKycByUserId(userId);
// }
@Override
public List<UKycUserVo> selectKycByUserId() {
LoginUser<Object> loginUser = SecurityUtils.getLoginUser();
return this.uKycMapper.selectKycByUserId(loginUser.getUserid());
}
@Override
public int isExistUserKyc(Long userId) {
return this.uKycMapper.isExistUserKyc(userId);
}
@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);
} else {
return this.uKycMapper.updateUserKyc(uKyc);
}
}
@Override
public int updateUserKyc(UKyc uKyc) {
return this.uKycMapper.updateUserKyc(uKyc);
}
}

View File

@@ -0,0 +1,87 @@
<?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.user.mapper.UKycMapper">
<resultMap type="UKyc" id="UKycResult">
<id property="kycId" column="kyc_id" />
<result property="userId" column="user_id" />
<result property="birthDate" column="birth_date" />
<result property="idType" column="id_type" />
<result property="idFile" column="id_file" />
<result property="identifyPicture" column="identify_picture" />
<result property="status" column="status" />
<result property="description" column="description" />
<result property="delFlag" column="del_flag" />
<result property="createBy" column="create_by" />
<result property="createTime" column="create_time" />
<result property="updateBy" column="update_by" />
<result property="updateTime" column="update_time" />
</resultMap>
<insert id="insertUserKyc" parameterType="UKyc" useGeneratedKeys="true" keyProperty="kycId">
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>
<if test="idFile != null and idFile != ''">id_file,</if>
<if test="identifyPicture != null and identifyPicture != ''">identify_picture,</if>
<if test="status != null and status != ''">status,</if>
<if test="description != null and description != ''">description,</if>
<if test="createBy != null and createBy != ''">create_by,</if>
create_time
)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>
<if test="idFile != null and idFile != ''">#{idFile},</if>
<if test="identifyPicture != null and identifyPicture != ''">#{identifyPicture},</if>
<if test="status != null and status != ''">#{status},</if>
<if test="description != null and description != ''">#{description},</if>
<if test="createBy != null and createBy != ''">#{createBy},</if>
sysdate()
)
</insert>
<update id="updateUserKyc" parameterType="UKyc">
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>
<if test="idFile != null and idFile != ''">id_file = #{idFile},</if>
<if test="identifyPicture != null and identifyPicture != ''">identify_picture = #{identifyPicture},</if>
<if test="status != null and status != ''">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>
<select id="isExistUserKyc" parameterType="Long" resultType="int">
select count(1) from u_user where user_id = #{userId} and del_flag = '0'
</select>
<select id="selectKycByUserId" resultType="org.wfc.user.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` as kyc_request_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
AND k.user_id = #{userId}
</select>
</mapper>