|
|
@@ -0,0 +1,524 @@
|
|
|
+package org.dromara.fulfiller.service.impl;
|
|
|
+
|
|
|
+import org.dromara.common.core.utils.MapstructUtils;
|
|
|
+import org.dromara.common.core.utils.StringUtils;
|
|
|
+import org.dromara.common.mybatis.core.page.TableDataInfo;
|
|
|
+import org.dromara.common.mybatis.core.page.PageQuery;
|
|
|
+import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
|
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
+import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
|
|
+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.satoken.utils.LoginHelper;
|
|
|
+import org.dromara.system.api.RemoteUserService;
|
|
|
+import org.springframework.stereotype.Service;
|
|
|
+import org.springframework.transaction.annotation.Transactional;
|
|
|
+import org.dromara.fulfiller.domain.FlfFulfiller;
|
|
|
+import org.dromara.fulfiller.domain.FlfPointsLog;
|
|
|
+import org.dromara.fulfiller.domain.FlfBalanceLog;
|
|
|
+import org.dromara.fulfiller.domain.FlfRewardLog;
|
|
|
+import org.dromara.fulfiller.domain.SysTag;
|
|
|
+import org.dromara.fulfiller.domain.SysTagRel;
|
|
|
+import org.dromara.fulfiller.domain.bo.FlfFulfillerBo;
|
|
|
+import org.dromara.fulfiller.domain.bo.FlfAdjustBalanceBo;
|
|
|
+import org.dromara.fulfiller.domain.bo.FlfAdjustPointsBo;
|
|
|
+import org.dromara.fulfiller.domain.bo.FlfRewardBo;
|
|
|
+import org.dromara.fulfiller.domain.vo.FlfFulfillerVo;
|
|
|
+import org.dromara.fulfiller.domain.vo.SysTagVo;
|
|
|
+import org.dromara.fulfiller.mapper.FlfFulfillerMapper;
|
|
|
+import org.dromara.fulfiller.mapper.FlfPointsLogMapper;
|
|
|
+import org.dromara.fulfiller.mapper.FlfBalanceLogMapper;
|
|
|
+import org.dromara.fulfiller.mapper.FlfRewardLogMapper;
|
|
|
+import org.dromara.fulfiller.mapper.SysTagMapper;
|
|
|
+import org.dromara.fulfiller.mapper.SysTagRelMapper;
|
|
|
+import org.dromara.fulfiller.service.IFlfFulfillerService;
|
|
|
+
|
|
|
+import org.dromara.resource.api.RemoteFileService;
|
|
|
+import org.dromara.resource.api.domain.RemoteFile;
|
|
|
+import org.dromara.system.api.RemoteAreaStationService;
|
|
|
+
|
|
|
+import java.util.ArrayList;
|
|
|
+import java.util.Collections;
|
|
|
+import java.util.List;
|
|
|
+import java.util.stream.Collectors;
|
|
|
+
|
|
|
+/**
|
|
|
+ * 履约者信息Service业务层处理
|
|
|
+ *
|
|
|
+ * @author steelwei
|
|
|
+ * @date 2026-03-01
|
|
|
+ */
|
|
|
+@Slf4j
|
|
|
+@RequiredArgsConstructor
|
|
|
+@Service
|
|
|
+public class FlfFulfillerServiceImpl implements IFlfFulfillerService {
|
|
|
+
|
|
|
+ private final FlfFulfillerMapper baseMapper;
|
|
|
+ private final FlfPointsLogMapper pointsLogMapper;
|
|
|
+ private final FlfBalanceLogMapper balanceLogMapper;
|
|
|
+ private final FlfRewardLogMapper rewardLogMapper;
|
|
|
+ private final SysTagMapper tagMapper;
|
|
|
+ private final SysTagRelMapper tagRelMapper;
|
|
|
+
|
|
|
+ @DubboReference
|
|
|
+ private RemoteUserService remoteUserService;
|
|
|
+
|
|
|
+ @DubboReference
|
|
|
+ private RemoteFileService remoteFileService;
|
|
|
+
|
|
|
+ @DubboReference
|
|
|
+ private RemoteAreaStationService remoteAreaStationService;
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public FlfFulfillerVo queryById(Long id) {
|
|
|
+ FlfFulfillerVo vo = baseMapper.selectVoById(id);
|
|
|
+ if (vo != null) {
|
|
|
+ vo.setTags(queryTagsByTargetId(id, "fulfiller"));
|
|
|
+ enrichVo(vo);
|
|
|
+ }
|
|
|
+ return vo;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public TableDataInfo<FlfFulfillerVo> queryPageList(FlfFulfillerBo bo, PageQuery pageQuery) {
|
|
|
+ LambdaQueryWrapper<FlfFulfiller> lqw = buildQueryWrapper(bo);
|
|
|
+ Page<FlfFulfillerVo> result = baseMapper.selectVoPage(pageQuery.build(), lqw);
|
|
|
+ result.getRecords().forEach(vo -> {
|
|
|
+ vo.setTags(queryTagsByTargetId(vo.getId(), "fulfiller"));
|
|
|
+ enrichVo(vo);
|
|
|
+ });
|
|
|
+ return TableDataInfo.build(result);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public List<FlfFulfillerVo> queryList(FlfFulfillerBo bo) {
|
|
|
+ LambdaQueryWrapper<FlfFulfiller> lqw = buildQueryWrapper(bo);
|
|
|
+ List<FlfFulfillerVo> list = baseMapper.selectVoList(lqw);
|
|
|
+ list.forEach(vo -> vo.setTags(queryTagsByTargetId(vo.getId(), "fulfiller")));
|
|
|
+ return list;
|
|
|
+ }
|
|
|
+
|
|
|
+ private LambdaQueryWrapper<FlfFulfiller> buildQueryWrapper(FlfFulfillerBo bo) {
|
|
|
+ LambdaQueryWrapper<FlfFulfiller> lqw = Wrappers.lambdaQuery();
|
|
|
+ lqw.and(StringUtils.isNotBlank(bo.getKeyword()), w ->
|
|
|
+ w.like(FlfFulfiller::getName, bo.getKeyword())
|
|
|
+ .or().like(FlfFulfiller::getPhone, bo.getKeyword())
|
|
|
+ .or().like(FlfFulfiller::getIdCard, bo.getKeyword())
|
|
|
+ );
|
|
|
+ lqw.eq(StringUtils.isNotBlank(bo.getStatus()), FlfFulfiller::getStatus, bo.getStatus());
|
|
|
+ lqw.eq(StringUtils.isNotBlank(bo.getWorkType()), FlfFulfiller::getWorkType, bo.getWorkType());
|
|
|
+ lqw.eq(StringUtils.isNotBlank(bo.getCityCode()), FlfFulfiller::getCityCode, bo.getCityCode());
|
|
|
+ lqw.eq(bo.getStationId() != null, FlfFulfiller::getStationId, bo.getStationId());
|
|
|
+ lqw.eq(bo.getLevelId() != null, FlfFulfiller::getLevelId, bo.getLevelId());
|
|
|
+ lqw.eq(bo.getAuthId() != null, FlfFulfiller::getAuthId, bo.getAuthId());
|
|
|
+ lqw.eq(bo.getAuthQual() != null, FlfFulfiller::getAuthQual, bo.getAuthQual());
|
|
|
+ lqw.orderByDesc(FlfFulfiller::getCreateTime);
|
|
|
+ return lqw;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
+ public Boolean insertByBo(FlfFulfillerBo bo) {
|
|
|
+ FlfFulfiller add = MapstructUtils.convert(bo, FlfFulfiller.class);
|
|
|
+ validEntityBeforeSave(add);
|
|
|
+ boolean flag = baseMapper.insert(add) > 0;
|
|
|
+ if (flag) {
|
|
|
+ bo.setId(add.getId());
|
|
|
+ saveTagRels(add.getId(), bo.getTagIds(), "fulfiller");
|
|
|
+ }
|
|
|
+ return flag;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
+ public Boolean updateByBo(FlfFulfillerBo bo) {
|
|
|
+ FlfFulfiller update = MapstructUtils.convert(bo, FlfFulfiller.class);
|
|
|
+ validEntityBeforeSave(update);
|
|
|
+ boolean flag = baseMapper.updateById(update) > 0;
|
|
|
+ if (flag) {
|
|
|
+ saveTagRels(bo.getId(), bo.getTagIds(), "fulfiller");
|
|
|
+ }
|
|
|
+ return flag;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public Boolean changeStatus(Long id, String status) {
|
|
|
+ FlfFulfiller update = new FlfFulfiller();
|
|
|
+ update.setId(id);
|
|
|
+ update.setStatus(status);
|
|
|
+ return baseMapper.updateById(update) > 0;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public Boolean resetPwd(Long id, String password) {
|
|
|
+ FlfFulfiller fulfiller = baseMapper.selectById(id);
|
|
|
+ if (fulfiller == null) {
|
|
|
+ throw new RuntimeException("履约者不存在");
|
|
|
+ }
|
|
|
+ String encryptedPwd = BCrypt.hashpw(password);
|
|
|
+ // 更新 flf_fulfiller 表密码
|
|
|
+ FlfFulfiller update = new FlfFulfiller();
|
|
|
+ update.setId(id);
|
|
|
+ update.setPassword(encryptedPwd);
|
|
|
+ baseMapper.updateById(update);
|
|
|
+ // 同步更新 sys_user 表密码
|
|
|
+ if (fulfiller.getUserId() != null) {
|
|
|
+ remoteUserService.resetUserPwd(fulfiller.getUserId(), encryptedPwd);
|
|
|
+ }
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
+ public Boolean reward(FlfRewardBo bo) {
|
|
|
+ FlfFulfiller fulfiller = baseMapper.selectById(bo.getFulfillerId());
|
|
|
+ if (fulfiller == null) {
|
|
|
+ throw new RuntimeException("履约者不存在");
|
|
|
+ }
|
|
|
+
|
|
|
+ int delta = "punish".equals(bo.getType()) ? -bo.getAmount() : bo.getAmount();
|
|
|
+
|
|
|
+ if ("points".equals(bo.getTarget())) {
|
|
|
+ int newPoints = fulfiller.getPoints() + delta;
|
|
|
+ FlfFulfiller update = new FlfFulfiller();
|
|
|
+ update.setId(fulfiller.getId());
|
|
|
+ update.setPoints(newPoints);
|
|
|
+ baseMapper.updateById(update);
|
|
|
+
|
|
|
+ // 记录积分日志
|
|
|
+ FlfPointsLog plog = new FlfPointsLog();
|
|
|
+ plog.setFulfillerId(fulfiller.getId());
|
|
|
+ plog.setType(bo.getType());
|
|
|
+ plog.setBizType("admin_" + bo.getType());
|
|
|
+ plog.setAmount(delta);
|
|
|
+ plog.setPointsAfter(newPoints);
|
|
|
+ plog.setReason(bo.getReason());
|
|
|
+ plog.setOperatorId(LoginHelper.getUserId());
|
|
|
+ pointsLogMapper.insert(plog);
|
|
|
+ } else if ("balance".equals(bo.getTarget())) {
|
|
|
+ long longDelta = (long) delta;
|
|
|
+ long newBalance = fulfiller.getBalance() + longDelta;
|
|
|
+ FlfFulfiller update = new FlfFulfiller();
|
|
|
+ update.setId(fulfiller.getId());
|
|
|
+ update.setBalance(newBalance);
|
|
|
+ baseMapper.updateById(update);
|
|
|
+
|
|
|
+ // 记录余额日志
|
|
|
+ FlfBalanceLog blog = new FlfBalanceLog();
|
|
|
+ blog.setFulfillerId(fulfiller.getId());
|
|
|
+ blog.setType(bo.getType());
|
|
|
+ blog.setSubType("admin_" + bo.getType());
|
|
|
+ blog.setAmount(longDelta);
|
|
|
+ blog.setBalanceAfter(newBalance);
|
|
|
+ blog.setReason(bo.getReason());
|
|
|
+ blog.setOperatorId(LoginHelper.getUserId());
|
|
|
+ balanceLogMapper.insert(blog);
|
|
|
+ }
|
|
|
+
|
|
|
+ // 记录奖惩日志
|
|
|
+ FlfRewardLog rlog = new FlfRewardLog();
|
|
|
+ rlog.setFulfillerId(fulfiller.getId());
|
|
|
+ rlog.setType(bo.getType());
|
|
|
+ rlog.setTarget(bo.getTarget());
|
|
|
+ rlog.setAmount(bo.getAmount());
|
|
|
+ rlog.setReason(bo.getReason());
|
|
|
+ rlog.setOperatorId(LoginHelper.getUserId());
|
|
|
+ rewardLogMapper.insert(rlog);
|
|
|
+
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
+ public Boolean adjustPoints(FlfAdjustPointsBo bo) {
|
|
|
+ FlfFulfiller fulfiller = baseMapper.selectById(bo.getFulfillerId());
|
|
|
+ if (fulfiller == null) {
|
|
|
+ throw new RuntimeException("履约者不存在");
|
|
|
+ }
|
|
|
+
|
|
|
+ int newPoints = fulfiller.getPoints() + bo.getAmount();
|
|
|
+ FlfFulfiller update = new FlfFulfiller();
|
|
|
+ update.setId(fulfiller.getId());
|
|
|
+ update.setPoints(newPoints);
|
|
|
+ baseMapper.updateById(update);
|
|
|
+
|
|
|
+ FlfPointsLog plog = new FlfPointsLog();
|
|
|
+ plog.setFulfillerId(fulfiller.getId());
|
|
|
+ plog.setType(bo.getAmount() > 0 ? "increase" : "decrease");
|
|
|
+ plog.setBizType("admin_adjust");
|
|
|
+ plog.setAmount(bo.getAmount());
|
|
|
+ plog.setPointsAfter(newPoints);
|
|
|
+ plog.setReason(bo.getReason());
|
|
|
+ plog.setOperatorId(LoginHelper.getUserId());
|
|
|
+ pointsLogMapper.insert(plog);
|
|
|
+
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
+ public Boolean adjustBalance(FlfAdjustBalanceBo bo) {
|
|
|
+ FlfFulfiller fulfiller = baseMapper.selectById(bo.getFulfillerId());
|
|
|
+ if (fulfiller == null) {
|
|
|
+ throw new RuntimeException("履约者不存在");
|
|
|
+ }
|
|
|
+
|
|
|
+ long newBalance = fulfiller.getBalance() + bo.getAmount();
|
|
|
+ FlfFulfiller update = new FlfFulfiller();
|
|
|
+ update.setId(fulfiller.getId());
|
|
|
+ update.setBalance(newBalance);
|
|
|
+ baseMapper.updateById(update);
|
|
|
+
|
|
|
+ FlfBalanceLog blog = new FlfBalanceLog();
|
|
|
+ blog.setFulfillerId(fulfiller.getId());
|
|
|
+ blog.setType(bo.getAmount() > 0 ? "increase" : "decrease");
|
|
|
+ blog.setSubType("admin_adjust");
|
|
|
+ blog.setAmount(bo.getAmount());
|
|
|
+ blog.setBalanceAfter(newBalance);
|
|
|
+ blog.setReason(bo.getReason());
|
|
|
+ blog.setOperatorId(LoginHelper.getUserId());
|
|
|
+ balanceLogMapper.insert(blog);
|
|
|
+
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public FlfFulfillerVo queryByPhone(String phone) {
|
|
|
+ FlfFulfillerVo vo = baseMapper.selectVoOne(
|
|
|
+ Wrappers.lambdaQuery(FlfFulfiller.class).eq(FlfFulfiller::getPhone, phone)
|
|
|
+ );
|
|
|
+ if (vo != null) {
|
|
|
+ vo.setTags(queryTagsByTargetId(vo.getId(), "fulfiller"));
|
|
|
+ }
|
|
|
+ return vo;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public FlfFulfillerVo queryByUserId(Long userId) {
|
|
|
+ FlfFulfillerVo vo = baseMapper.selectVoOne(
|
|
|
+ Wrappers.lambdaQuery(FlfFulfiller.class).eq(FlfFulfiller::getUserId, userId)
|
|
|
+ );
|
|
|
+ if (vo != null) {
|
|
|
+ vo.setTags(queryTagsByTargetId(vo.getId(), "fulfiller"));
|
|
|
+ enrichVo(vo);
|
|
|
+ }
|
|
|
+ return vo;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 填充VO的图片URL、站点名称、服务类型列表等
|
|
|
+ * @author steelwei
|
|
|
+ */
|
|
|
+ private void enrichVo(FlfFulfillerVo vo) {
|
|
|
+ try {
|
|
|
+ // 解析站点名称
|
|
|
+ if (vo.getStationId() != null) {
|
|
|
+ vo.setStationName(remoteAreaStationService.selectNameById(vo.getStationId()));
|
|
|
+ }
|
|
|
+ // 解析服务类型 JSON
|
|
|
+ if (StringUtils.isNotBlank(vo.getServiceTypes())) {
|
|
|
+ vo.setServiceTypeList(com.alibaba.fastjson2.JSON.parseArray(vo.getServiceTypes(), String.class));
|
|
|
+ }
|
|
|
+ // 计算注册天数
|
|
|
+ if (vo.getCreateTime() != null) {
|
|
|
+ long days = java.time.temporal.ChronoUnit.DAYS.between(
|
|
|
+ vo.getCreateTime().toInstant().atZone(java.time.ZoneId.systemDefault()).toLocalDate(),
|
|
|
+ java.time.LocalDate.now()
|
|
|
+ );
|
|
|
+ vo.setRegisterDays(Math.max(days, 0));
|
|
|
+ } else {
|
|
|
+ vo.setRegisterDays(0L);
|
|
|
+ }
|
|
|
+ // 是否已设置密码(查数据库原始记录判断)
|
|
|
+ FlfFulfiller entity = baseMapper.selectById(vo.getId());
|
|
|
+ vo.setHasPassword(entity != null && StringUtils.isNotBlank(entity.getPassword()));
|
|
|
+
|
|
|
+ // 收集所有需要查询URL的OSS ID
|
|
|
+ List<String> ossIds = new ArrayList<>();
|
|
|
+ if (vo.getAvatar() != null) ossIds.add(String.valueOf(vo.getAvatar()));
|
|
|
+ if (vo.getIdCardFront() != null) ossIds.add(String.valueOf(vo.getIdCardFront()));
|
|
|
+ if (vo.getIdCardBack() != null) ossIds.add(String.valueOf(vo.getIdCardBack()));
|
|
|
+ // 解析资质图片 OSS IDs
|
|
|
+ List<String> qualOssIds = new ArrayList<>();
|
|
|
+ if (StringUtils.isNotBlank(vo.getQualImages())) {
|
|
|
+ qualOssIds = com.alibaba.fastjson2.JSON.parseArray(vo.getQualImages(), String.class);
|
|
|
+ ossIds.addAll(qualOssIds);
|
|
|
+ }
|
|
|
+ // 批量查询 OSS URL
|
|
|
+ if (!ossIds.isEmpty()) {
|
|
|
+ String idsStr = String.join(",", ossIds);
|
|
|
+ List<RemoteFile> files = remoteFileService.selectByIds(idsStr);
|
|
|
+ for (RemoteFile f : files) {
|
|
|
+ if (vo.getAvatar() != null && f.getOssId().equals(vo.getAvatar())) {
|
|
|
+ vo.setAvatarUrl(f.getUrl());
|
|
|
+ }
|
|
|
+ if (vo.getIdCardFront() != null && f.getOssId().equals(vo.getIdCardFront())) {
|
|
|
+ vo.setIdCardFrontUrl(f.getUrl());
|
|
|
+ }
|
|
|
+ if (vo.getIdCardBack() != null && f.getOssId().equals(vo.getIdCardBack())) {
|
|
|
+ vo.setIdCardBackUrl(f.getUrl());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ // 资质图片URL
|
|
|
+ List<String> qualUrls = new ArrayList<>();
|
|
|
+ for (String qId : qualOssIds) {
|
|
|
+ for (RemoteFile f : files) {
|
|
|
+ if (String.valueOf(f.getOssId()).equals(qId)) {
|
|
|
+ qualUrls.add(f.getUrl());
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ vo.setQualImageUrls(qualUrls);
|
|
|
+ }
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.warn("enrichVo失败: {}", e.getMessage());
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private void validEntityBeforeSave(FlfFulfiller entity) {
|
|
|
+ //TODO 做一些数据校验,如手机号唯一约束
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 查询目标关联的标签列表
|
|
|
+ */
|
|
|
+ private List<SysTagVo> queryTagsByTargetId(Long targetId, String targetType) {
|
|
|
+ List<SysTagRel> rels = tagRelMapper.selectList(
|
|
|
+ Wrappers.lambdaQuery(SysTagRel.class)
|
|
|
+ .eq(SysTagRel::getTargetId, targetId)
|
|
|
+ .eq(SysTagRel::getTargetType, targetType)
|
|
|
+ );
|
|
|
+ if (rels.isEmpty()) {
|
|
|
+ return Collections.emptyList();
|
|
|
+ }
|
|
|
+ List<Long> tagIds = rels.stream().map(SysTagRel::getTagId).collect(Collectors.toList());
|
|
|
+ return tagMapper.selectVoList(
|
|
|
+ Wrappers.lambdaQuery(SysTag.class).in(SysTag::getId, tagIds)
|
|
|
+ );
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 保存标签关联(先删后增)
|
|
|
+ */
|
|
|
+ private void saveTagRels(Long targetId, List<Long> tagIds, String targetType) {
|
|
|
+ tagRelMapper.delete(
|
|
|
+ Wrappers.lambdaQuery(SysTagRel.class)
|
|
|
+ .eq(SysTagRel::getTargetId, targetId)
|
|
|
+ .eq(SysTagRel::getTargetType, targetType)
|
|
|
+ );
|
|
|
+ if (tagIds != null && !tagIds.isEmpty()) {
|
|
|
+ tagIds.forEach(tagId -> {
|
|
|
+ SysTagRel rel = new SysTagRel();
|
|
|
+ rel.setTagId(tagId);
|
|
|
+ rel.setTargetId(targetId);
|
|
|
+ rel.setTargetType(targetType);
|
|
|
+ tagRelMapper.insert(rel);
|
|
|
+ });
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public Boolean updateAvatarByUserId(Long userId, String avatar) {
|
|
|
+ FlfFulfiller fulfiller = baseMapper.selectOne(
|
|
|
+ Wrappers.lambdaQuery(FlfFulfiller.class).eq(FlfFulfiller::getUserId, userId)
|
|
|
+ );
|
|
|
+ if (fulfiller == null) {
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ fulfiller.setAvatar(avatar);
|
|
|
+ return baseMapper.updateById(fulfiller) > 0;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public Boolean updateNameByUserId(Long userId, String name) {
|
|
|
+ FlfFulfiller fulfiller = baseMapper.selectOne(
|
|
|
+ Wrappers.lambdaQuery(FlfFulfiller.class).eq(FlfFulfiller::getUserId, userId)
|
|
|
+ );
|
|
|
+ if (fulfiller == null) {
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ fulfiller.setRealName(name);
|
|
|
+ return baseMapper.updateById(fulfiller) > 0;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public Boolean updateStatusByUserId(Long userId, String status) {
|
|
|
+ FlfFulfiller fulfiller = baseMapper.selectOne(
|
|
|
+ Wrappers.lambdaQuery(FlfFulfiller.class).eq(FlfFulfiller::getUserId, userId)
|
|
|
+ );
|
|
|
+ if (fulfiller == null) {
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ fulfiller.setStatus(status);
|
|
|
+ return baseMapper.updateById(fulfiller) > 0;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public Boolean updateCityByUserId(Long userId, String cityCode, String cityName) {
|
|
|
+ FlfFulfiller fulfiller = baseMapper.selectOne(
|
|
|
+ Wrappers.lambdaQuery(FlfFulfiller.class).eq(FlfFulfiller::getUserId, userId)
|
|
|
+ );
|
|
|
+ if (fulfiller == null) {
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ fulfiller.setCityCode(cityCode);
|
|
|
+ fulfiller.setCityName(cityName);
|
|
|
+ return baseMapper.updateById(fulfiller) > 0;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public Boolean updatePhoneByUserId(Long userId, String phone) {
|
|
|
+ FlfFulfiller fulfiller = baseMapper.selectOne(
|
|
|
+ Wrappers.lambdaQuery(FlfFulfiller.class).eq(FlfFulfiller::getUserId, userId)
|
|
|
+ );
|
|
|
+ if (fulfiller == null) {
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ // 检查手机号是否已被使用
|
|
|
+ Long count = baseMapper.selectCount(
|
|
|
+ Wrappers.lambdaQuery(FlfFulfiller.class)
|
|
|
+ .eq(FlfFulfiller::getPhone, phone)
|
|
|
+ .ne(FlfFulfiller::getId, fulfiller.getId())
|
|
|
+ );
|
|
|
+ if (count > 0) {
|
|
|
+ throw new RuntimeException("该手机号已被使用");
|
|
|
+ }
|
|
|
+ fulfiller.setPhone(phone);
|
|
|
+ return baseMapper.updateById(fulfiller) > 0;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public Boolean updatePasswordByUserId(Long userId, String oldPassword, String newPassword) {
|
|
|
+ FlfFulfiller fulfiller = baseMapper.selectOne(
|
|
|
+ Wrappers.lambdaQuery(FlfFulfiller.class).eq(FlfFulfiller::getUserId, userId)
|
|
|
+ );
|
|
|
+ if (fulfiller == null) {
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ // 验证旧密码
|
|
|
+ if (!BCrypt.checkpw(oldPassword, fulfiller.getPassword())) {
|
|
|
+ throw new RuntimeException("原密码错误");
|
|
|
+ }
|
|
|
+ // 加密新密码
|
|
|
+ String hashedPassword = BCrypt.hashpw(newPassword);
|
|
|
+ fulfiller.setPassword(hashedPassword);
|
|
|
+ return baseMapper.updateById(fulfiller) > 0;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
+ public Boolean deleteAccountByUserId(Long userId) {
|
|
|
+ FlfFulfiller fulfiller = baseMapper.selectOne(
|
|
|
+ Wrappers.lambdaQuery(FlfFulfiller.class).eq(FlfFulfiller::getUserId, userId)
|
|
|
+ );
|
|
|
+ if (fulfiller == null) {
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ // 逻辑删除履约者信息
|
|
|
+ return baseMapper.deleteById(fulfiller.getId()) > 0;
|
|
|
+ }
|
|
|
+
|
|
|
+}
|