2
0

fix: update kyc user module

This commit is contained in:
zhangsz
2025-01-15 14:33:51 +08:00
parent 2deaac0c5b
commit 6eaf2bf471
14 changed files with 189 additions and 17 deletions

File diff suppressed because one or more lines are too long

View File

@@ -863,7 +863,8 @@ DROP TABLE IF EXISTS `u_kyc`;
CREATE TABLE `u_kyc` (
`kyc_id` bigint(20) NOT NULL AUTO_INCREMENT COMMENT 'ID',
`user_id` bigint(20) NULL DEFAULT NULL COMMENT 'link to user_id of u_user',
`birth_date` datetime NULL DEFAULT NULL,
`real_name` varchar(64) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT NULL,
`birth_date` date NULL DEFAULT NULL,
`id_type` enum('DRIVERS_LICENSE','PASSPORT','RESIDENCE_PERMIT','STUDENT_ID','MEDICARE_CARD','BIRTH_CERTIFICATE') CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT NULL COMMENT 'identify type',
`id_file` varchar(128) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT '' COMMENT 'ID file',
`identify_picture` varchar(128) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT NULL COMMENT 'identify picture',

View File

@@ -13,7 +13,6 @@ 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.constant.KycStatusEnum;
import org.wfc.user.domain.vo.UKycUserVo;
@@ -57,5 +56,6 @@ public class UKycController extends BaseController {
public AjaxResult edit(@Validated @RequestBody UKyc uKyc) {
uKyc.setStatus(KycStatusEnum.PENDING.getCode());
return toAjax(uKycService.updateUserKyc(uKyc));
}
}
}

View File

@@ -26,6 +26,9 @@ public class UKyc extends BaseData {
@Schema(description = "User ID")
private Long userId;
@Schema(description = "Real Name")
private String realName;
@Schema(description = "Birth Date")
private String birthDate;

View File

@@ -21,4 +21,12 @@ public enum IdTypeEnum {
private final Integer code;
private final String desc;
public static IdTypeEnum fromCode(Integer code) {
for (IdTypeEnum type : IdTypeEnum.values()) {
if (type.getCode().equals(code)) {
return type;
}
}
throw new IllegalArgumentException("Unknown code: " + code);
}
}

View File

@@ -18,4 +18,13 @@ public enum KycStatusEnum {
private final Integer code;
private final String desc;
public static KycStatusEnum fromCode(Integer code) {
for (KycStatusEnum type : KycStatusEnum.values()) {
if (type.getCode().equals(code)) {
return type;
}
}
throw new IllegalArgumentException("Unknown code: " + code);
}
}

View File

@@ -22,6 +22,9 @@ public class UKycUserVo {
@Schema(description = "ID Type")
private IdTypeEnum idType;
// @Schema(description = "ID Type")
// private Integer idType;
@Schema(description = "ID File")
private String idFile;
@@ -31,9 +34,21 @@ public class UKycUserVo {
@Schema(description = "KYC Status")
private KycStatusEnum status;
// @Schema(description = "KYC Status")
// private Integer status;
@Schema(description = "Description")
private String description;
@Schema(description = "Create By")
private String createBy;
@Schema(description = "Create Time")
private String createTime;
@Schema(description = "Update By")
private String updateBy;
@Schema(description = "Update Time")
private String updateTime;
}

View File

@@ -8,11 +8,18 @@ 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.api.domain.UUser;
import org.wfc.user.domain.UKyc;
import org.wfc.user.domain.vo.UKycUserVo;
import org.wfc.user.mapper.UKycMapper;
import org.wfc.user.service.IUKycService;
import org.wfc.user.service.IUUserService;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.Period;
import java.time.format.DateTimeFormatter;
import java.time.format.DateTimeParseException;
import java.util.List;
/**
@@ -26,11 +33,16 @@ import java.util.List;
@Service
public class UKycServiceImpl extends ServiceImpl<UKycMapper, UKyc> implements IUKycService {
private static final Logger log = LoggerFactory.getLogger(UKycServiceImpl.class);
private static final Logger logger = LoggerFactory.getLogger(UKycServiceImpl.class);
@Autowired
private UKycMapper uKycMapper;
@Autowired
private IUUserService uUserService;
private static final DateTimeFormatter DATE_FORMATTER = DateTimeFormatter.ofPattern("yyyy-MM-dd");
// @Override
// public List<UKycUserVo> selectKycByUserId(Long userId) {
// return this.baseMapper.selectKycByUserId(userId);
@@ -49,19 +61,19 @@ public class UKycServiceImpl extends ServiceImpl<UKycMapper, UKyc> implements IU
@Override
public int insertUserKyc(UKyc uKyc) {
log.debug("uKyc: {}", uKyc);
logger.debug("uKyc: {}", uKyc);
LoginUser<Object> loginUser = SecurityUtils.getLoginUser();
if (uKyc.getUserId() == null) {
uKyc.setUserId(loginUser.getUserid());
} else {
if (!loginUser.getUserid().equals(uKyc.getUserId())) {
log.error("The kyc user(userId={}) is not the logged in user(userId={})",
logger.error("The kyc user(userId={}) is not the logged in user(userId={})",
uKyc.getUserId(), loginUser.getUserid());
return 0;
}
}
updateUserByKyc(uKyc);
if (this.uKycMapper.isExistUserKyc(uKyc.getUserId()) == 0) {
return this.uKycMapper.insertUserKyc(uKyc);
} else {
@@ -77,12 +89,44 @@ public class UKycServiceImpl extends ServiceImpl<UKycMapper, UKyc> implements IU
uKyc.setUserId(loginUser.getUserid());
} else {
if (!loginUser.getUserid().equals(uKyc.getUserId())) {
log.error("The kyc user(userId={}) is not the logged in user(userId={})",
logger.error("The kyc user(userId={}) is not the logged in user(userId={})",
uKyc.getUserId(), loginUser.getUserid());
return 0;
}
}
updateUserByKyc(uKyc);
return this.uKycMapper.updateUserKyc(uKyc);
}
/**
* Updates the user information based on the KYC details.
*
* @param uKyc the KYC details
* @return the number of rows affected by the update
* @throws IllegalArgumentException if the birthDate is null or in an invalid format
*/
private int updateUserByKyc(UKyc uKyc) {
UUser uUser = uUserService.selectUserById(uKyc.getUserId());
uUser.setFullName(uKyc.getRealName());
if (uKyc.getBirthDate() == null) {
throw new IllegalArgumentException("BirthDate cannot be null");
}
// Parse birthDate and calculate age
try {
LocalDate birthDate = LocalDate.parse(uKyc.getBirthDate(), DATE_FORMATTER);
uUser.setAge(calculateAge(birthDate));
} catch (DateTimeParseException e) {
throw new IllegalArgumentException("Invalid birthDate format");
}
return uUserService.updateUser(uUser);
}
private int calculateAge(LocalDate birthDate) {
if (birthDate == null) {
return 0;
}
return Period.between(birthDate, LocalDate.now()).getYears();
}
}

View File

@@ -0,0 +1,37 @@
package org.wfc.user.typehandler;
import org.apache.ibatis.type.BaseTypeHandler;
import org.apache.ibatis.type.JdbcType;
import org.wfc.user.domain.constant.IdTypeEnum;
import java.sql.CallableStatement;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
public class IdTypeEnumTypeHandler extends BaseTypeHandler<IdTypeEnum> {
@Override
public void setNonNullParameter(PreparedStatement ps, int i, IdTypeEnum parameter, JdbcType jdbcType)
throws SQLException {
ps.setString(i, parameter.name());
}
@Override
public IdTypeEnum getNullableResult(ResultSet rs, String columnName) throws SQLException {
String name = rs.getString(columnName);
return name == null ? null : IdTypeEnum.valueOf(name);
}
@Override
public IdTypeEnum getNullableResult(ResultSet rs, int columnIndex) throws SQLException {
String name = rs.getString(columnIndex);
return name == null ? null : IdTypeEnum.valueOf(name);
}
@Override
public IdTypeEnum getNullableResult(CallableStatement cs, int columnIndex) throws SQLException {
String name = cs.getString(columnIndex);
return name == null ? null : IdTypeEnum.valueOf(name);
}
}

View File

@@ -0,0 +1,38 @@
package org.wfc.user.typehandler;
import org.apache.ibatis.type.BaseTypeHandler;
import org.apache.ibatis.type.JdbcType;
import org.wfc.user.domain.constant.KycStatusEnum;
import java.sql.CallableStatement;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
public class KycStatusEnumTypeHandler extends BaseTypeHandler<KycStatusEnum> {
@Override
public void setNonNullParameter(PreparedStatement ps, int i,
KycStatusEnum parameter, JdbcType jdbcType)
throws SQLException {
ps.setString(i, parameter.name());
}
@Override
public KycStatusEnum getNullableResult(ResultSet rs, String columnName) throws SQLException {
String name = rs.getString(columnName);
return name == null ? null : KycStatusEnum.valueOf(name);
}
@Override
public KycStatusEnum getNullableResult(ResultSet rs, int columnIndex) throws SQLException {
String name = rs.getString(columnIndex);
return name == null ? null : KycStatusEnum.valueOf(name);
}
@Override
public KycStatusEnum getNullableResult(CallableStatement cs, int columnIndex) throws SQLException {
String name = cs.getString(columnIndex);
return name == null ? null : KycStatusEnum.valueOf(name);
}
}

View File

@@ -46,6 +46,7 @@ spring:
mybatis-plus:
# 搜索指定包别名
type-aliases-package: org.wfc.user
config-location: classpath:mybatis-config.xml
# 配置mapper的扫描找到所有的mapper.xml映射文件
mapper-locations: classpath:mapper/**/*.xml
global-config:
@@ -62,7 +63,7 @@ swagger:
# Omada 配置
omada:
omada-url: 'https://192.168.2.248:8043'
omada-url: 'https://192.168.2.249:8043'
omadac-id: 'f3aa6e479b94222581523710cc2c2a9d'
client-id: '5036e77c81a74008821c694a715fe2b8'
client-secret: '29faa06fb7f244b094377b48eb3083a7'

View File

@@ -5,6 +5,7 @@
<resultMap type="UKyc" id="UKycResult">
<id property="kycId" column="kyc_id" />
<result property="userId" column="user_id" />
<result property="realName" column="real_name" />
<result property="birthDate" column="birth_date" />
<result property="idType" column="id_type" />
<result property="idFile" column="id_file" />
@@ -21,6 +22,7 @@
<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="realName != null and realName != ''">real_name,</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>
@@ -31,7 +33,8 @@
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="realName != null and realName != ''">#{realName},</if>
<if test="birthDate != null">STR_TO_DATE(#{birthDate}, '%Y-%m-%d'),</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>
@@ -45,7 +48,8 @@
<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="realName != null and realName != ''">real_name = #{realName},</if>
<if test="birthDate != null">birth_date = STR_TO_DATE(#{birthDate}, '%Y-%m-%d'),</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>
@@ -73,7 +77,7 @@
SELECT
k.kyc_id,
k.user_id,
u.full_name as realName,
u.full_name as real_name,
k.birth_date,
k.id_type,
k.id_file,

View File

@@ -50,7 +50,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
</resultMap>
<sql id="selectUserVo">
select u.user_id, u.dept_id, u.user_name, u.nick_name, u.email, u.avatar, u.phonenumber, u.password, u.sex, u.status, u.del_flag, u.login_ip, u.login_date, u.create_by, u.create_time, u.remark,
select u.user_id, u.dept_id, u.user_name, u.nick_name, u.full_name, u.email, u.avatar, u.phonenumber, u.password, u.sex, u.age, u.status, u.del_flag, u.login_ip, u.login_date, u.create_by, u.create_time, u.remark,
d.dept_id, d.parent_id, d.ancestors, d.dept_name, d.order_num, d.leader, d.status as dept_status,
r.role_id, r.role_name, r.role_key, r.role_sort, r.data_scope, r.status as role_status
from u_user u
@@ -60,7 +60,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
</sql>
<select id="selectUserList" parameterType="UUser" resultMap="UUserResult">
select u.user_id, u.dept_id, u.nick_name, u.user_name, u.email, u.avatar, u.phonenumber, u.sex, u.status, u.del_flag, u.login_ip, u.login_date, u.create_by, u.create_time, u.remark, d.dept_name, d.leader from u_user u
select u.user_id, u.dept_id, u.nick_name, u.user_name, u.full_name, u.email, u.avatar, u.phonenumber, u.sex, u.age, u.status, u.del_flag, u.login_ip, u.login_date, u.create_by, u.create_time, u.remark, d.dept_name, d.leader from u_user u
left join u_dept d on u.dept_id = d.dept_id
where u.del_flag = '0'
<if test="userId != null and userId != 0">
@@ -192,9 +192,11 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<if test="deptId != null and deptId != 0">dept_id = #{deptId},</if>
<if test="userName != null and userName != ''">user_name = #{userName},</if>
<if test="nickName != null and nickName != ''">nick_name = #{nickName},</if>
<if test="fullName != null and fullName != ''">full_name = #{fullName},</if>
<if test="email != null ">email = #{email},</if>
<if test="phonenumber != null ">phonenumber = #{phonenumber},</if>
<if test="sex != null and sex != ''">sex = #{sex},</if>
<if test="age != null and age != 0">age = #{age},</if>
<if test="avatar != null and avatar != ''">avatar = #{avatar},</if>
<if test="password != null and password != ''">password = #{password},</if>
<if test="status != null and status != ''">status = #{status},</if>

View File

@@ -0,0 +1,10 @@
<!DOCTYPE configuration
PUBLIC "-//mybatis.org//DTD Config 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-config.dtd">
<configuration>
<typeHandlers>
<typeHandler handler="org.wfc.user.typehandler.IdTypeEnumTypeHandler" javaType="org.wfc.user.domain.constant.IdTypeEnum"/>
<typeHandler handler="org.wfc.user.typehandler.KycStatusEnumTypeHandler" javaType="org.wfc.user.domain.constant.KycStatusEnum"/>
</typeHandlers>
</configuration>