package com.oying.modules.rider.service.impl; import cn.hutool.core.bean.BeanUtil; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.oying.exception.BadRequestException; 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.modules.system.domain.User; import com.oying.modules.system.service.UserService; import com.oying.utils.FileUtil; import com.oying.utils.SecurityUtils; import lombok.RequiredArgsConstructor; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import com.oying.modules.rider.service.RiderInfoService; import com.oying.modules.rider.domain.dto.RiderInfoQueryCriteria; 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 * @description 服务实现 * @date 2025-07-01 **/ @Service @RequiredArgsConstructor public class RiderInfoServiceImpl extends ServiceImpl implements RiderInfoService { private final RiderInfoMapper riderInfoMapper; private final RiderWalletInfoService riderWalletInfoService; private final UserService userService; @Override public PageResult queryAll(RiderInfoQueryCriteria criteria, Page page) { return PageUtil.toPage(riderInfoMapper.findAll(criteria, page)); } @Override public List queryAll(RiderInfoQueryCriteria criteria) { return riderInfoMapper.findAll(criteria); } @Override @Transactional(rollbackFor = Exception.class) public void create(RiderInfo resources) { riderInfoMapper.insert(resources); } @Override @Transactional(rollbackFor = Exception.class) public void update(RiderInfo resources) { RiderInfo riderInfo = getById(resources.getInfoId()); riderInfo.copy(resources); riderInfoMapper.updateById(riderInfo); } @Override @Transactional(rollbackFor = Exception.class) public void deleteAll(List ids) { riderInfoMapper.deleteBatchIds(ids); } @Override public void download(List all, HttpServletResponse response) throws IOException { List> list = new ArrayList<>(); for (RiderInfo riderInfo : all) { Map map = new LinkedHashMap<>(); map.put("骑手id", riderInfo.getRiderId()); map.put("数据来源id", riderInfo.getSourceId()); map.put("电话", riderInfo.getPhone()); map.put("乙方姓名", riderInfo.getCardName()); map.put("证件号", riderInfo.getCardNum()); map.put("数据来源编号", riderInfo.getSourceNum()); map.put("状态0不生效,1生效 其他平台的条件是否满足", riderInfo.getEnabled()); map.put("数据来源平台(LY,等)", riderInfo.getSourcePlatform()); map.put("地址", riderInfo.getAddress()); map.put("创建者", riderInfo.getCreateBy()); map.put("更新者", riderInfo.getUpdateBy()); map.put("创建日期", riderInfo.getCreateTime()); map.put("更新时间", riderInfo.getUpdateTime()); list.add(map); } FileUtil.downloadExcel(list, response); } @Override @Transactional(rollbackFor = Exception.class) public void syncRiderSourceInfo(String sourcePlatform) { Long riderId = SecurityUtils.getCurrentUserId(); // 查询其他平台的数据 RiderSourceInfoHttp riderSourceInfoHttp = RiderSourceHttpUtils.getRiderSourceInfoHttp(SecurityUtils.getCurrentUsername(), sourcePlatform); // 请求成功 if (riderSourceInfoHttp.getCode().equals(Constants.HTTP_CODE_SUCCESS)) { // 获取骑手信息等于空 if (null != riderSourceInfoHttp.getData()) { RiderSourceInfo infoHttpData = riderSourceInfoHttp.getData(); // 检查是否存在该平台的骑手信息 QueryWrapper riderInfoQueryWrapper = new QueryWrapper<>(); riderInfoQueryWrapper.eq(RiderInfo.COL_RIDER_ID, riderId); RiderInfo riderInfo = riderInfoMapper.selectOne(riderInfoQueryWrapper); // 如果存在该平台的骑手信息 if (null == riderInfo) { // 如果不存在,则创建新的骑手三方信息 RiderInfo newRiderInfo = new RiderInfo(); BeanUtil.copyProperties(infoHttpData, newRiderInfo); 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())) { // 如果存在,接单状态不同 更新接单状态 if (!infoHttpData.getEnabled().equals(riderInfo.getEnabled())) { riderInfo.setEnabled(infoHttpData.getEnabled()); // 更新骑手信息 updateById(riderInfo); } } else { // 骑手平台信息变更 RiderInfo newRiderInfo = new RiderInfo(); BeanUtil.copyProperties(infoHttpData, newRiderInfo); newRiderInfo.setRiderId(riderId); newRiderInfo.setSourcePlatform(sourcePlatform); updateById(newRiderInfo); // 添加变更记录... } } } else { // 获取骑手三方数据为空,抛出异常 throw new BadRequestException("获取骑手三方数据为空"); } } else { // 获取骑手三方数据失败,抛出异常 throw new BadRequestException("获取骑手三方数据失败"); } } @Override public RiderInfo getRiderSourceInfo(Long riderId) { QueryWrapper riderInfoQueryWrapper = new QueryWrapper<>(); riderInfoQueryWrapper.eq(RiderInfo.COL_RIDER_ID, riderId); return riderInfoMapper.selectOne(riderInfoQueryWrapper); } }