|
|
@@ -1,5 +1,6 @@
|
|
|
package org.dromara.fulfiller.service.impl;
|
|
|
|
|
|
+import org.dromara.common.core.exception.ServiceException;
|
|
|
import org.dromara.common.core.utils.MapstructUtils;
|
|
|
import org.dromara.common.core.utils.StringUtils;
|
|
|
import org.dromara.common.mybatis.core.page.TableDataInfo;
|
|
|
@@ -11,12 +12,7 @@ import cn.hutool.crypto.digest.BCrypt;
|
|
|
import lombok.RequiredArgsConstructor;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
import org.apache.dubbo.config.annotation.DubboReference;
|
|
|
-import org.dromara.common.core.enums.UserType;
|
|
|
-import org.dromara.common.platform.Platform;
|
|
|
import org.dromara.common.satoken.utils.LoginHelper;
|
|
|
-import org.dromara.common.tenant.helper.TenantHelper;
|
|
|
-import org.dromara.system.api.RemoteUserService;
|
|
|
-import org.dromara.system.api.domain.bo.RemoteUserBo;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
import org.dromara.fulfiller.domain.FlfAudit;
|
|
|
@@ -70,14 +66,11 @@ public class FlfFulfillerServiceImpl implements IFlfFulfillerService {
|
|
|
private final SysTagRelMapper tagRelMapper;
|
|
|
|
|
|
@DubboReference
|
|
|
- private RemoteUserService remoteUserService;
|
|
|
+ private RemoteAreaStationService remoteAreaStationService;
|
|
|
|
|
|
@DubboReference
|
|
|
private RemoteFileService remoteFileService;
|
|
|
|
|
|
- @DubboReference
|
|
|
- private RemoteAreaStationService remoteAreaStationService;
|
|
|
-
|
|
|
@Override
|
|
|
public FlfFulfillerVo queryById(Long id) {
|
|
|
FlfFulfillerVo vo = baseMapper.selectVoById(id);
|
|
|
@@ -128,26 +121,14 @@ public class FlfFulfillerServiceImpl implements IFlfFulfillerService {
|
|
|
@Override
|
|
|
@Transactional(rollbackFor = Exception.class)
|
|
|
public Boolean insertByBo(FlfFulfillerBo bo) {
|
|
|
- // 1. 先创建 sys_user 账号(用于App登录)
|
|
|
- RemoteUserBo userBo = new RemoteUserBo();
|
|
|
- userBo.setUserName(bo.getPhone());
|
|
|
- userBo.setNickName(bo.getName());
|
|
|
+ // 创建 flf_fulfiller 记录(不再创建 sys_user) @author steelwei
|
|
|
// 密码需要BCrypt加密
|
|
|
- String encryptedPwd = StringUtils.isNotBlank(bo.getPassword())
|
|
|
- ? BCrypt.hashpw(bo.getPassword())
|
|
|
+ String encryptedPwd = StringUtils.isNotBlank(bo.getPassword())
|
|
|
+ ? BCrypt.hashpw(bo.getPassword())
|
|
|
: BCrypt.hashpw("123456"); // 默认密码
|
|
|
- userBo.setPassword(encryptedPwd);
|
|
|
- userBo.setPhonenumber(bo.getPhone());
|
|
|
- userBo.setSex(bo.getGender());
|
|
|
- userBo.setUserType(UserType.FULFILLER_USER.getUserType());
|
|
|
- userBo.setPlatformId(Platform.FULFILLER.getId());
|
|
|
- userBo.setStatus("0");
|
|
|
- userBo.setTenantId(TenantHelper.getTenantId());
|
|
|
- Long sysUserId = remoteUserService.createUser(userBo);
|
|
|
-
|
|
|
- // 2. 创建 flf_fulfiller 记录并关联 userId
|
|
|
+
|
|
|
FlfFulfiller add = MapstructUtils.convert(bo, FlfFulfiller.class);
|
|
|
- add.setUserId(sysUserId);
|
|
|
+ add.setUserId(null); // 不再关联 sys_user
|
|
|
add.setPassword(encryptedPwd);
|
|
|
validEntityBeforeSave(add);
|
|
|
boolean flag = baseMapper.insert(add) > 0;
|
|
|
@@ -182,7 +163,7 @@ public class FlfFulfillerServiceImpl implements IFlfFulfillerService {
|
|
|
public Boolean resetPwd(Long id, String password) {
|
|
|
FlfFulfiller fulfiller = baseMapper.selectById(id);
|
|
|
if (fulfiller == null) {
|
|
|
- throw new RuntimeException("履约者不存在");
|
|
|
+ throw new ServiceException("履约者不存在");
|
|
|
}
|
|
|
String encryptedPwd = BCrypt.hashpw(password);
|
|
|
// 更新 flf_fulfiller 表密码
|
|
|
@@ -190,10 +171,7 @@ public class FlfFulfillerServiceImpl implements IFlfFulfillerService {
|
|
|
update.setId(id);
|
|
|
update.setPassword(encryptedPwd);
|
|
|
baseMapper.updateById(update);
|
|
|
- // 同步更新 sys_user 表密码
|
|
|
- if (fulfiller.getUserId() != null) {
|
|
|
- remoteUserService.resetUserPwd(fulfiller.getUserId(), encryptedPwd);
|
|
|
- }
|
|
|
+ // 不再同步更新 sys_user 表密码 @author steelwei
|
|
|
return true;
|
|
|
}
|
|
|
|
|
|
@@ -202,7 +180,7 @@ public class FlfFulfillerServiceImpl implements IFlfFulfillerService {
|
|
|
public Boolean reward(FlfRewardBo bo) {
|
|
|
FlfFulfiller fulfiller = baseMapper.selectById(bo.getFulfillerId());
|
|
|
if (fulfiller == null) {
|
|
|
- throw new RuntimeException("履约者不存在");
|
|
|
+ throw new ServiceException("履约者不存在");
|
|
|
}
|
|
|
|
|
|
int delta = "punish".equals(bo.getType()) ? -bo.getAmount() : bo.getAmount();
|
|
|
@@ -262,7 +240,7 @@ public class FlfFulfillerServiceImpl implements IFlfFulfillerService {
|
|
|
public Boolean adjustPoints(FlfAdjustPointsBo bo) {
|
|
|
FlfFulfiller fulfiller = baseMapper.selectById(bo.getFulfillerId());
|
|
|
if (fulfiller == null) {
|
|
|
- throw new RuntimeException("履约者不存在");
|
|
|
+ throw new ServiceException("履约者不存在");
|
|
|
}
|
|
|
|
|
|
int newPoints = fulfiller.getPoints() + bo.getAmount();
|
|
|
@@ -289,7 +267,7 @@ public class FlfFulfillerServiceImpl implements IFlfFulfillerService {
|
|
|
public Boolean adjustBalance(FlfAdjustBalanceBo bo) {
|
|
|
FlfFulfiller fulfiller = baseMapper.selectById(bo.getFulfillerId());
|
|
|
if (fulfiller == null) {
|
|
|
- throw new RuntimeException("履约者不存在");
|
|
|
+ throw new ServiceException("履约者不存在");
|
|
|
}
|
|
|
|
|
|
long newBalance = fulfiller.getBalance() + bo.getAmount();
|
|
|
@@ -324,9 +302,8 @@ public class FlfFulfillerServiceImpl implements IFlfFulfillerService {
|
|
|
|
|
|
@Override
|
|
|
public FlfFulfillerVo queryByUserId(Long userId) {
|
|
|
- FlfFulfillerVo vo = baseMapper.selectVoOne(
|
|
|
- Wrappers.lambdaQuery(FlfFulfiller.class).eq(FlfFulfiller::getUserId, userId)
|
|
|
- );
|
|
|
+ // userId 现在是 flf_fulfiller.id @author steelwei
|
|
|
+ FlfFulfillerVo vo = baseMapper.selectVoById(userId);
|
|
|
if (vo != null) {
|
|
|
vo.setTags(queryTagsByTargetId(vo.getId(), "fulfiller"));
|
|
|
enrichVo(vo);
|
|
|
@@ -449,9 +426,8 @@ public class FlfFulfillerServiceImpl implements IFlfFulfillerService {
|
|
|
|
|
|
@Override
|
|
|
public Boolean updateAvatarByUserId(Long userId, String avatar) {
|
|
|
- FlfFulfiller fulfiller = baseMapper.selectOne(
|
|
|
- Wrappers.lambdaQuery(FlfFulfiller.class).eq(FlfFulfiller::getUserId, userId)
|
|
|
- );
|
|
|
+ // userId 现在是 flf_fulfiller.id @author steelwei
|
|
|
+ FlfFulfiller fulfiller = baseMapper.selectById(userId);
|
|
|
if (fulfiller == null) {
|
|
|
return false;
|
|
|
}
|
|
|
@@ -461,9 +437,8 @@ public class FlfFulfillerServiceImpl implements IFlfFulfillerService {
|
|
|
|
|
|
@Override
|
|
|
public Boolean updateNameByUserId(Long userId, String name) {
|
|
|
- FlfFulfiller fulfiller = baseMapper.selectOne(
|
|
|
- Wrappers.lambdaQuery(FlfFulfiller.class).eq(FlfFulfiller::getUserId, userId)
|
|
|
- );
|
|
|
+ // userId 现在是 flf_fulfiller.id @author steelwei
|
|
|
+ FlfFulfiller fulfiller = baseMapper.selectById(userId);
|
|
|
if (fulfiller == null) {
|
|
|
return false;
|
|
|
}
|
|
|
@@ -473,9 +448,8 @@ public class FlfFulfillerServiceImpl implements IFlfFulfillerService {
|
|
|
|
|
|
@Override
|
|
|
public Boolean updateStatusByUserId(Long userId, String status) {
|
|
|
- FlfFulfiller fulfiller = baseMapper.selectOne(
|
|
|
- Wrappers.lambdaQuery(FlfFulfiller.class).eq(FlfFulfiller::getUserId, userId)
|
|
|
- );
|
|
|
+ // userId 现在是 flf_fulfiller.id @author steelwei
|
|
|
+ FlfFulfiller fulfiller = baseMapper.selectById(userId);
|
|
|
if (fulfiller == null) {
|
|
|
return false;
|
|
|
}
|
|
|
@@ -485,9 +459,8 @@ public class FlfFulfillerServiceImpl implements IFlfFulfillerService {
|
|
|
|
|
|
@Override
|
|
|
public Boolean updateCityByUserId(Long userId, String cityCode, String cityName) {
|
|
|
- FlfFulfiller fulfiller = baseMapper.selectOne(
|
|
|
- Wrappers.lambdaQuery(FlfFulfiller.class).eq(FlfFulfiller::getUserId, userId)
|
|
|
- );
|
|
|
+ // userId 现在是 flf_fulfiller.id @author steelwei
|
|
|
+ FlfFulfiller fulfiller = baseMapper.selectById(userId);
|
|
|
if (fulfiller == null) {
|
|
|
return false;
|
|
|
}
|
|
|
@@ -498,9 +471,8 @@ public class FlfFulfillerServiceImpl implements IFlfFulfillerService {
|
|
|
|
|
|
@Override
|
|
|
public Boolean updatePhoneByUserId(Long userId, String phone) {
|
|
|
- FlfFulfiller fulfiller = baseMapper.selectOne(
|
|
|
- Wrappers.lambdaQuery(FlfFulfiller.class).eq(FlfFulfiller::getUserId, userId)
|
|
|
- );
|
|
|
+ // userId 现在是 flf_fulfiller.id @author steelwei
|
|
|
+ FlfFulfiller fulfiller = baseMapper.selectById(userId);
|
|
|
if (fulfiller == null) {
|
|
|
return false;
|
|
|
}
|
|
|
@@ -511,7 +483,7 @@ public class FlfFulfillerServiceImpl implements IFlfFulfillerService {
|
|
|
.ne(FlfFulfiller::getId, fulfiller.getId())
|
|
|
);
|
|
|
if (count > 0) {
|
|
|
- throw new RuntimeException("该手机号已被使用");
|
|
|
+ throw new ServiceException("该手机号已被使用");
|
|
|
}
|
|
|
fulfiller.setPhone(phone);
|
|
|
return baseMapper.updateById(fulfiller) > 0;
|
|
|
@@ -519,15 +491,14 @@ public class FlfFulfillerServiceImpl implements IFlfFulfillerService {
|
|
|
|
|
|
@Override
|
|
|
public Boolean updatePasswordByUserId(Long userId, String oldPassword, String newPassword) {
|
|
|
- FlfFulfiller fulfiller = baseMapper.selectOne(
|
|
|
- Wrappers.lambdaQuery(FlfFulfiller.class).eq(FlfFulfiller::getUserId, userId)
|
|
|
- );
|
|
|
+ // userId 现在是 flf_fulfiller.id @author steelwei
|
|
|
+ FlfFulfiller fulfiller = baseMapper.selectById(userId);
|
|
|
if (fulfiller == null) {
|
|
|
return false;
|
|
|
}
|
|
|
// 验证旧密码
|
|
|
if (!BCrypt.checkpw(oldPassword, fulfiller.getPassword())) {
|
|
|
- throw new RuntimeException("原密码错误");
|
|
|
+ throw new ServiceException("原密码错误");
|
|
|
}
|
|
|
// 加密新密码
|
|
|
String hashedPassword = BCrypt.hashpw(newPassword);
|
|
|
@@ -538,9 +509,8 @@ public class FlfFulfillerServiceImpl implements IFlfFulfillerService {
|
|
|
@Override
|
|
|
@Transactional(rollbackFor = Exception.class)
|
|
|
public Boolean deleteAccountByUserId(Long userId) {
|
|
|
- FlfFulfiller fulfiller = baseMapper.selectOne(
|
|
|
- Wrappers.lambdaQuery(FlfFulfiller.class).eq(FlfFulfiller::getUserId, userId)
|
|
|
- );
|
|
|
+ // userId 现在是 flf_fulfiller.id @author steelwei
|
|
|
+ FlfFulfiller fulfiller = baseMapper.selectById(userId);
|
|
|
if (fulfiller == null) {
|
|
|
return false;
|
|
|
}
|
|
|
@@ -551,13 +521,12 @@ public class FlfFulfillerServiceImpl implements IFlfFulfillerService {
|
|
|
@Override
|
|
|
@Transactional(rollbackFor = Exception.class)
|
|
|
public Boolean updateAuthInfoByUserId(Long userId, java.util.Map<String, String> params) {
|
|
|
- FlfFulfiller fulfiller = baseMapper.selectOne(
|
|
|
- Wrappers.lambdaQuery(FlfFulfiller.class).eq(FlfFulfiller::getUserId, userId)
|
|
|
- );
|
|
|
+ // userId 现在是 flf_fulfiller.id @author steelwei
|
|
|
+ FlfFulfiller fulfiller = baseMapper.selectById(userId);
|
|
|
if (fulfiller == null) {
|
|
|
return false;
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
// 检查是否已有待审核记录,避免重复提交
|
|
|
Long pendingCount = auditMapper.selectCount(
|
|
|
Wrappers.lambdaQuery(FlfAudit.class)
|
|
|
@@ -565,9 +534,9 @@ public class FlfFulfillerServiceImpl implements IFlfFulfillerService {
|
|
|
.eq(FlfAudit::getStatus, 0)
|
|
|
);
|
|
|
if (pendingCount > 0) {
|
|
|
- throw new RuntimeException("您的认证信息正在审核中,请等待审核完成后再修改");
|
|
|
+ throw new ServiceException("您的认证信息正在审核中,请等待审核完成后再修改");
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
// 查找该履约者已有的审核记录(取最新一条)
|
|
|
FlfAudit audit = auditMapper.selectOne(
|
|
|
Wrappers.lambdaQuery(FlfAudit.class)
|
|
|
@@ -575,11 +544,11 @@ public class FlfFulfillerServiceImpl implements IFlfFulfillerService {
|
|
|
.orderByDesc(FlfAudit::getCreateTime)
|
|
|
.last("LIMIT 1")
|
|
|
);
|
|
|
-
|
|
|
+
|
|
|
if (audit == null) {
|
|
|
return false;
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
// 在原有审核记录上更新信息和状态
|
|
|
if (params.containsKey("idCardFront")) {
|
|
|
audit.setIdCardFront(Long.parseLong(params.get("idCardFront")));
|
|
|
@@ -593,13 +562,13 @@ public class FlfFulfillerServiceImpl implements IFlfFulfillerService {
|
|
|
if (params.containsKey("qualifications")) {
|
|
|
audit.setQualifications(params.get("qualifications"));
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
// 重置为待审核状态
|
|
|
audit.setStatus(0);
|
|
|
audit.setRejectReason(null);
|
|
|
audit.setAuditBy(null);
|
|
|
audit.setAuditTime(null);
|
|
|
-
|
|
|
+
|
|
|
return auditMapper.updateById(audit) > 0;
|
|
|
}
|
|
|
|