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

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);
}
}