From 7ee9bc8fb2e42ce2e82cd1eacb57ba584611dfc5 Mon Sep 17 00:00:00 2001 From: puzhibing <393733352@qq.com> Date: 星期五, 23 六月 2023 11:04:32 +0800 Subject: [PATCH] 修改bug --- driver/guns-admin/src/main/java/com/supersavedriving/driver/modular/system/service/impl/AccountChangeDetailServiceImpl.java | 110 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 files changed, 109 insertions(+), 1 deletions(-) diff --git a/driver/guns-admin/src/main/java/com/supersavedriving/driver/modular/system/service/impl/AccountChangeDetailServiceImpl.java b/driver/guns-admin/src/main/java/com/supersavedriving/driver/modular/system/service/impl/AccountChangeDetailServiceImpl.java index 527f2a5..55527ce 100644 --- a/driver/guns-admin/src/main/java/com/supersavedriving/driver/modular/system/service/impl/AccountChangeDetailServiceImpl.java +++ b/driver/guns-admin/src/main/java/com/supersavedriving/driver/modular/system/service/impl/AccountChangeDetailServiceImpl.java @@ -1,13 +1,22 @@ package com.supersavedriving.driver.modular.system.service.impl; +import com.alibaba.fastjson.JSON; +import com.alibaba.fastjson.JSONObject; +import com.baomidou.mybatisplus.mapper.EntityWrapper; import com.baomidou.mybatisplus.service.impl.ServiceImpl; import com.supersavedriving.driver.modular.system.dao.AccountChangeDetailMapper; import com.supersavedriving.driver.modular.system.model.AccountChangeDetail; -import com.supersavedriving.driver.modular.system.service.IAccountChangeDetailService; +import com.supersavedriving.driver.modular.system.model.Driver; +import com.supersavedriving.driver.modular.system.model.RechargeRecord; +import com.supersavedriving.driver.modular.system.model.SystemConfig; +import com.supersavedriving.driver.modular.system.service.*; +import com.supersavedriving.driver.modular.system.util.ResultUtil; +import com.supersavedriving.driver.modular.system.util.UUIDUtil; import com.supersavedriving.driver.modular.system.warpper.BalanceDetailWarpper; import com.supersavedriving.driver.modular.system.warpper.CommissionDetailListWarpper; import com.supersavedriving.driver.modular.system.warpper.CommissionDetailWarpper; import com.supersavedriving.driver.modular.system.warpper.IntegralIncomeAndExpensesWarpper; +import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import java.util.Date; @@ -20,6 +29,21 @@ */ @Service public class AccountChangeDetailServiceImpl extends ServiceImpl<AccountChangeDetailMapper, AccountChangeDetail> implements IAccountChangeDetailService { + + @Autowired + private IDriverService driverService; + + @Autowired + private ISystemConfigService systemConfigService; + + @Autowired + private IRechargeRecordService rechargeRecordService; + + @Autowired + private IOrderService orderService; + + + /** @@ -86,4 +110,88 @@ List<BalanceDetailWarpper> balanceDetailWarppers = this.baseMapper.queryBalanceDetail(driverId, time, type, pageNum, pageSize); return balanceDetailWarppers; } + + + /** + * 处理司机保险 + */ + @Override + public void deductionInsurance() { + SystemConfig systemConfig = systemConfigService.selectOne(new EntityWrapper<SystemConfig>().eq("type", 3)); + if(null == systemConfig){ + return; + } + JSONObject jsonObject = JSON.parseObject(systemConfig.getContent()); + Double num1 = jsonObject.getDouble("num1"); + List<Driver> drivers = driverService.selectList(new EntityWrapper<Driver>().eq("approvalStatus", 2).eq("status", 1)); + for (Driver driver : drivers) { + Double backgroundBalance = driver.getBackgroundBalance(); + Double balance = driver.getBalance(); + double all = backgroundBalance + balance; + if(num1 > all){ + continue; + } + + double d = num1.doubleValue(); + if(backgroundBalance > 0 && backgroundBalance < d){ + d -= backgroundBalance; + driver.setBackgroundBalance(0D); + }else if(backgroundBalance >= d){ + AccountChangeDetail accountChangeDetail = new AccountChangeDetail(); + accountChangeDetail.setCode(System.currentTimeMillis() + UUIDUtil.getNumberRandom(3)); + accountChangeDetail.setUserType(2); + accountChangeDetail.setUserId(driver.getId()); + accountChangeDetail.setType(1); + accountChangeDetail.setChangeType(8); + accountChangeDetail.setOldData(all); + driver.setBackgroundBalance(driver.getBackgroundBalance() - d); + accountChangeDetail.setNewData(driver.getBalance() + driver.getBackgroundBalance()); + accountChangeDetail.setExplain("收取保险费"); + accountChangeDetail.setCreateTime(new Date()); + this.insert(accountChangeDetail); + d = 0; + } + if(d > 0){ + if(balance > 0 && balance >= d){ + AccountChangeDetail accountChangeDetail = new AccountChangeDetail(); + accountChangeDetail.setCode(System.currentTimeMillis() + UUIDUtil.getNumberRandom(3)); + accountChangeDetail.setUserType(2); + accountChangeDetail.setUserId(driver.getId()); + accountChangeDetail.setType(1); + accountChangeDetail.setChangeType(8); + accountChangeDetail.setOldData(all); + driver.setBalance(driver.getBalance() - d); + accountChangeDetail.setNewData(driver.getBalance() + driver.getBackgroundBalance()); + accountChangeDetail.setExplain("收取保险费"); + accountChangeDetail.setCreateTime(new Date()); + this.insert(accountChangeDetail); + + List<RechargeRecord> rechargeRecords = rechargeRecordService.selectList(new EntityWrapper<RechargeRecord>().eq("type", 2).eq("userId", driver.getId()).eq("payStatus", 2).gt("surplusDividedAmount", 0).orderBy("createTime")); + for (RechargeRecord rechargeRecord : rechargeRecords) { + Double surplusDividedAmount = rechargeRecord.getSurplusDividedAmount(); + if(surplusDividedAmount.compareTo(d) >= 0){ + ResultUtil fengzhang = orderService.fengzhang(3, null, "553021440975", null, rechargeRecord.getId(), rechargeRecord.getOrderNumber(), d, 1); + if(fengzhang.getCode() == 10000){ + rechargeRecord.setSurplusDividedAmount(rechargeRecord.getSurplusDividedAmount() - d); + rechargeRecordService.updateById(rechargeRecord); + } + break; + }else{ + ResultUtil fengzhang = orderService.fengzhang(3, null, "553021440975", null, rechargeRecord.getId(), rechargeRecord.getOrderNumber(), surplusDividedAmount, 1); + if(fengzhang.getCode() == 10000){ + rechargeRecord.setSurplusDividedAmount(0d); + rechargeRecordService.updateById(rechargeRecord); + d -= surplusDividedAmount; + }else{ + break; + } + } + } + + } + } + + driverService.updateById(driver); + } + } } -- Gitblit v1.7.1