xin
2025-09-05 6f3c170403f34d452b5dc733043145d8d760fe41
oying-system/src/main/java/com/oying/modules/rider/service/impl/RiderInfoServiceImpl.java
@@ -6,10 +6,13 @@
import com.oying.modules.rider.domain.RiderInfo;
import com.oying.modules.rider.domain.RiderSourceInfo;
import com.oying.modules.rider.domain.RiderSourceInfoHttp;
import com.oying.modules.rider.domain.RiderWalletInfo;
import com.oying.modules.rider.service.RiderWalletInfoService;
import com.oying.modules.rider.utils.Constants;
import com.oying.modules.rider.utils.RiderSourceHttpUtils;
import com.oying.utils.FileUtil;
import com.oying.utils.SecurityUtils;
import com.oying.modules.system.domain.User;
import com.oying.modules.system.service.UserService;
import com.oying.utils.*;
import lombok.RequiredArgsConstructor;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
@@ -18,13 +21,11 @@
import com.oying.modules.rider.mapper.RiderInfoMapper;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import com.oying.utils.PageUtil;
import java.math.BigDecimal;
import java.util.*;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;
import com.oying.utils.PageResult;
/**
 * @author pxb
@@ -36,6 +37,8 @@
public class RiderInfoServiceImpl extends ServiceImpl<RiderInfoMapper, RiderInfo> implements RiderInfoService {
    private final RiderInfoMapper riderInfoMapper;
    private final RiderWalletInfoService riderWalletInfoService;
    private final UserService userService;
    @Override
    public PageResult<RiderInfo> queryAll(RiderInfoQueryCriteria criteria, Page<Object> page) {
@@ -91,19 +94,24 @@
    }
    @Override
    public void syncRiderSourceInfo(String sourcePlatform) {
    @Transactional(rollbackFor = Exception.class)
    public R syncRiderSourceInfo(String sourcePlatform) {
        Long riderId = SecurityUtils.getCurrentUserId();
        // 添加请求参数
        List<String> phoneList = new ArrayList<>();
        phoneList.add(SecurityUtils.getCurrentUsername());
        // 查询其他平台的数据
        RiderSourceInfoHttp riderSourceInfoHttp = RiderSourceHttpUtils.getRiderSourceInfoHttp(SecurityUtils.getCurrentUsername(), sourcePlatform);
        RiderSourceInfoHttp riderSourceInfoHttp = RiderSourceHttpUtils.getRiderSourceInfoHttp(phoneList, sourcePlatform);
        // 请求成功
        if (riderSourceInfoHttp.getCode().equals(Constants.HTTP_CODE_SUCCESS)) {
            // 检查是否存在该平台的骑手信息
            QueryWrapper<RiderInfo> riderInfoQueryWrapper = new QueryWrapper<>();
            riderInfoQueryWrapper.eq(RiderInfo.COL_RIDER_ID, riderId);
            RiderInfo riderInfo = riderInfoMapper.selectOne(riderInfoQueryWrapper);
            // 获取骑手信息等于空
            if (null != riderSourceInfoHttp.getData()) {
                RiderSourceInfo infoHttpData = riderSourceInfoHttp.getData();
                // 检查是否存在该平台的骑手信息
                QueryWrapper<RiderInfo> riderInfoQueryWrapper = new QueryWrapper<>();
                riderInfoQueryWrapper.eq(RiderInfo.COL_RIDER_ID, riderId);
                RiderInfo riderInfo = riderInfoMapper.selectOne(riderInfoQueryWrapper);
            if (!riderSourceInfoHttp.getData().isEmpty()) {
                // 单个骑手信息同步只取第一条数据
                RiderSourceInfo infoHttpData = riderSourceInfoHttp.getData().get(0);
                // 如果存在该平台的骑手信息
                if (null == riderInfo) {
                    // 如果不存在,则创建新的骑手三方信息
@@ -112,6 +120,28 @@
                    newRiderInfo.setRiderId(riderId);
                    newRiderInfo.setSourcePlatform(sourcePlatform);
                    create(newRiderInfo);
                    // 覆盖骑手账号昵称信息
                    User user = new User();
                    user.setId(riderId);
                    user.setNickName(infoHttpData.getCardName());
                    userService.updateById(user);
                    // 创建骑手钱包信息 正常
                    RiderWalletInfo riderWalletInfo = new RiderWalletInfo();
                    riderWalletInfo.setRiderId(riderId);
                    riderWalletInfo.setAmount(new BigDecimal(0.00));
                    riderWalletInfo.setAvailableBalance(new BigDecimal(0.00));
                    riderWalletInfo.setPurchasingElectricityAmount(new BigDecimal(0.00));
                    riderWalletInfo.setWithdrawTotal(new BigDecimal(0.00));
                    riderWalletInfo.setIncomeTotal(new BigDecimal(0.00));
                    riderWalletInfo.setFrozenAmount(new BigDecimal(0.00));
                    riderWalletInfo.setRunTotal(Constants.ZERO);
                    riderWalletInfo.setCashWithdrawalTotal(Constants.ZERO);
                    riderWalletInfo.setPurchasingElectricityTotal(Constants.ZERO);
                    riderWalletInfo.setStatus(Constants.WALLET_STATUS_NORMAL);
                    riderWalletInfo.setPhone(infoHttpData.getPhone());
                    riderWalletInfo.setCardName(infoHttpData.getCardName());
                    riderWalletInfo.setCardNum(infoHttpData.getCardNum());
                    riderWalletInfoService.create(riderWalletInfo);
                } else {
                    // 是否相同平台
                    if (sourcePlatform.equals(riderInfo.getSourcePlatform())) {
@@ -131,9 +161,17 @@
                        // 添加变更记录...
                    }
                }
                return R.success(riderInfo, "获取骑手三方数据");
            } else {
                // 修改骑手信息为信息失效
                if(riderInfo != null) {
                    RiderInfo newRiderInfo = new RiderInfo();
                    newRiderInfo.setRiderId(riderId);
                    newRiderInfo.setEnabled(Constants.SOURCE_ENABLED_DFF);
                    updateById(newRiderInfo);
                }
                // 获取骑手三方数据为空,抛出异常
                throw new BadRequestException("获取骑手三方数据为空");
                return R.fail(null, "获取骑手三方数据为空");
            }
        } else {
            // 获取骑手三方数据失败,抛出异常
@@ -142,7 +180,7 @@
    }
    @Override
    public RiderInfo getRiderSourceInfo(String riderId) {
    public RiderInfo getRiderSourceInfo(Long riderId) {
        QueryWrapper<RiderInfo> riderInfoQueryWrapper = new QueryWrapper<>();
        riderInfoQueryWrapper.eq(RiderInfo.COL_RIDER_ID, riderId);
        return riderInfoMapper.selectOne(riderInfoQueryWrapper);