|
@@ -1,11 +1,19 @@
|
|
package pay.platform.api.system.servcie.impl;
|
|
package pay.platform.api.system.servcie.impl;
|
|
|
|
|
|
|
|
|
|
|
|
+import cn.bzvs.otp.OtpAuthUtil;
|
|
|
|
+import cn.hutool.core.bean.BeanUtil;
|
|
import com.mybatisflex.core.query.QueryWrapper;
|
|
import com.mybatisflex.core.query.QueryWrapper;
|
|
|
|
+import jakarta.annotation.Nonnull;
|
|
|
|
+import lombok.extern.slf4j.Slf4j;
|
|
import org.springframework.stereotype.Service;
|
|
import org.springframework.stereotype.Service;
|
|
import org.springframework.util.StringUtils;
|
|
import org.springframework.util.StringUtils;
|
|
|
|
+import pay.platform.api.system.model.vo.PayAgentVO;
|
|
|
|
+import pay.platform.api.system.model.vo.PayMerchantVO;
|
|
import pay.platform.api.system.servcie.PayMerchantService;
|
|
import pay.platform.api.system.servcie.PayMerchantService;
|
|
|
|
+import pay.platform.core.common.Result;
|
|
import pay.platform.core.common.domain.BaseService;
|
|
import pay.platform.core.common.domain.BaseService;
|
|
|
|
+import pay.platform.core.util.PasswordUtil;
|
|
import pay.platform.domain.PayMerchant;
|
|
import pay.platform.domain.PayMerchant;
|
|
import pay.platform.domain.table.PayAgentTableDef;
|
|
import pay.platform.domain.table.PayAgentTableDef;
|
|
import pay.platform.domain.table.PayMerchantTableDef;
|
|
import pay.platform.domain.table.PayMerchantTableDef;
|
|
@@ -20,6 +28,7 @@ import java.util.Optional;
|
|
* @since 1.0
|
|
* @since 1.0
|
|
*/
|
|
*/
|
|
@Service
|
|
@Service
|
|
|
|
+@Slf4j
|
|
public class PayMerchantServiceImpl extends BaseService<PayMerchantMapper, PayMerchant> implements PayMerchantService {
|
|
public class PayMerchantServiceImpl extends BaseService<PayMerchantMapper, PayMerchant> implements PayMerchantService {
|
|
|
|
|
|
/**
|
|
/**
|
|
@@ -44,4 +53,114 @@ public class PayMerchantServiceImpl extends BaseService<PayMerchantMapper, PayMe
|
|
PayMerchant sysUser = getById(id);
|
|
PayMerchant sysUser = getById(id);
|
|
return StringUtils.hasText(sysUser.getTpopCode());
|
|
return StringUtils.hasText(sysUser.getTpopCode());
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * 帐号是否存在
|
|
|
|
+ *
|
|
|
|
+ * @param username .
|
|
|
|
+ * @return .
|
|
|
|
+ */
|
|
|
|
+ public Result<Boolean> hashUsername(String username) {
|
|
|
|
+ return Result.OK(loadUserByUsername(username).isPresent());
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * 根据ID获取详情
|
|
|
|
+ *
|
|
|
|
+ * @param id .
|
|
|
|
+ * @return .
|
|
|
|
+ */
|
|
|
|
+ public Result<PayMerchantVO> detail(String id) {
|
|
|
|
+ PayMerchant user = getById(id);
|
|
|
|
+ PayMerchantVO res = BeanUtil.toBean(user, PayMerchantVO.class);
|
|
|
|
+ return Result.OK(res);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * 更新用户
|
|
|
|
+ *
|
|
|
|
+ * @param id .
|
|
|
|
+ * @param vo .
|
|
|
|
+ * @return .
|
|
|
|
+ */
|
|
|
|
+ public Result<PayAgentVO> updateById(String id, PayAgentVO vo) {
|
|
|
|
+ PayMerchant user = getById(id);
|
|
|
|
+ if (null == user) {
|
|
|
|
+ return Result.NG("用户不存在");
|
|
|
|
+ }
|
|
|
|
+ BeanUtil.copyProperties(vo, user);
|
|
|
|
+ updateById(user);
|
|
|
|
+ return Result.OK(vo);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * 重置密码
|
|
|
|
+ *
|
|
|
|
+ * @param username .
|
|
|
|
+ * @param passwd .
|
|
|
|
+ * @return .
|
|
|
|
+ */
|
|
|
|
+
|
|
|
|
+ public Result<String> resetPassword(@Nonnull String username, @Nonnull String passwd) {
|
|
|
|
+ String newPassword = PasswordUtil.encoder(passwd);
|
|
|
|
+ mapper.resetPassword(username, newPassword);
|
|
|
|
+ return Result.OK();
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * 修改密码
|
|
|
|
+ *
|
|
|
|
+ * @param username .
|
|
|
|
+ * @param oldPasswd .
|
|
|
|
+ * @param newPasswd .
|
|
|
|
+ * @return .
|
|
|
|
+ */
|
|
|
|
+ public Result<String> changePasswd(@Nonnull String username, @Nonnull String oldPasswd, @Nonnull String newPasswd) {
|
|
|
|
+ Optional<PayMerchant> sysUser = loadUserByUsername(username);
|
|
|
|
+ if (sysUser.isPresent()) {
|
|
|
|
+ return Result.NG("用户不存在");
|
|
|
|
+ }
|
|
|
|
+ PayMerchant user = sysUser.get();
|
|
|
|
+ if (!PasswordUtil.matches(oldPasswd, user.getPassword())) {
|
|
|
|
+ return Result.NG("原密码错误");
|
|
|
|
+ }
|
|
|
|
+ String newPassword = PasswordUtil.encoder(newPasswd);
|
|
|
|
+ user.setPassword(newPassword);
|
|
|
|
+ mapper.update(user);
|
|
|
|
+ return Result.OK();
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * 创建谷歌验证器
|
|
|
|
+ *
|
|
|
|
+ * @param id ID
|
|
|
|
+ * @return otp
|
|
|
|
+ */
|
|
|
|
+ public String createGoogleOtp(String id) {
|
|
|
|
+ PayMerchant sysUser = getById(id);
|
|
|
|
+ String secret = OtpAuthUtil.createSecret();
|
|
|
|
+ sysUser.setTpopCode(secret);
|
|
|
|
+ updateById(sysUser);
|
|
|
|
+ return OtpAuthUtil.getOtpQrCodeUrl("", secret);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * 校验谷歌验证器
|
|
|
|
+ *
|
|
|
|
+ * @param id ID
|
|
|
|
+ * @param code 验证码
|
|
|
|
+ * @return true/false
|
|
|
|
+ */
|
|
|
|
+ public boolean checkGoogleOtp(String id, String code) {
|
|
|
|
+ PayMerchant sysUser = getById(id);
|
|
|
|
+ String secret = sysUser.getTpopCode();
|
|
|
|
+ if (Boolean.FALSE.equals(StringUtils.hasText(secret))) {
|
|
|
|
+ log.warn("用户未设置谷歌验证器");
|
|
|
|
+ return false;
|
|
|
|
+ }
|
|
|
|
+ return OtpAuthUtil.validateCode(secret, code);
|
|
|
|
+ }
|
|
}
|
|
}
|