From db7fa6a91b9534ac90e219b6f554c54c43c83a5a Mon Sep 17 00:00:00 2001 From: liujie <liujie> Date: 星期三, 16 八月 2023 09:28:15 +0800 Subject: [PATCH] update --- driver/guns-admin/src/main/java/com/supersavedriving/driver/modular/system/service/impl/YouTuiDriverServiceImpl.java | 148 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 files changed, 147 insertions(+), 1 deletions(-) diff --git a/driver/guns-admin/src/main/java/com/supersavedriving/driver/modular/system/service/impl/YouTuiDriverServiceImpl.java b/driver/guns-admin/src/main/java/com/supersavedriving/driver/modular/system/service/impl/YouTuiDriverServiceImpl.java index 557bd0a..93d0138 100644 --- a/driver/guns-admin/src/main/java/com/supersavedriving/driver/modular/system/service/impl/YouTuiDriverServiceImpl.java +++ b/driver/guns-admin/src/main/java/com/supersavedriving/driver/modular/system/service/impl/YouTuiDriverServiceImpl.java @@ -1,10 +1,26 @@ package com.supersavedriving.driver.modular.system.service.impl; import com.baomidou.mybatisplus.service.impl.ServiceImpl; -import com.supersavedriving.driver.modular.system.dao.YouTuiDriverMapper; +import com.supersavedriving.driver.modular.system.model.AccountChangeDetail; +import com.supersavedriving.driver.modular.system.model.Driver; +import com.supersavedriving.driver.modular.system.model.YouTui; import com.supersavedriving.driver.modular.system.model.YouTuiDriver; +import com.supersavedriving.driver.modular.system.dao.YouTuiDriverMapper; +import com.supersavedriving.driver.modular.system.service.IAccountChangeDetailService; +import com.supersavedriving.driver.modular.system.service.IDriverService; import com.supersavedriving.driver.modular.system.service.IYouTuiDriverService; +import com.supersavedriving.driver.modular.system.service.IYouTuiService; +import com.supersavedriving.driver.modular.system.util.ResultUtil; +import com.supersavedriving.driver.modular.system.util.UUIDUtil; +import com.supersavedriving.driver.modular.system.warpper.DriverYouTuiListWarpper; +import com.supersavedriving.driver.modular.system.warpper.DriverYouTuiWarpper; +import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; + +import java.util.ArrayList; +import java.util.Date; +import java.util.List; +import java.util.Map; /** * 用户优推数据 @@ -13,4 +29,134 @@ */ @Service public class YouTuiDriverServiceImpl extends ServiceImpl<YouTuiDriverMapper, YouTuiDriver> implements IYouTuiDriverService { + + @Autowired + private IYouTuiService youTuiService; + + @Autowired + private IDriverService driverService; + + @Autowired + private IAccountChangeDetailService accountChangeDetailService; + + + + + + + /** + * 获取司机兑换优推记录 + * @param driverId + * @return + * @throws Exception + */ + @Override + public List<DriverYouTuiListWarpper> queryDriverYouTuiList(Integer driverId) throws Exception { + List<Map<String, String>> list = this.baseMapper.queryRedemptionDate(driverId); + List<DriverYouTuiListWarpper> driverYouTuiListWarppers = new ArrayList<>(); + for (Map<String, String> map : list) { + String createTime = map.get("createTime"); + List<DriverYouTuiWarpper> driverYouTuiWarppers = this.baseMapper.queryYouTuiDriverList(driverId, createTime); + DriverYouTuiListWarpper driverYouTuiListWarpper = new DriverYouTuiListWarpper(); + driverYouTuiListWarpper.setMonth(createTime); + driverYouTuiListWarpper.setList(driverYouTuiWarppers); + driverYouTuiListWarppers.add(driverYouTuiListWarpper); + } + return driverYouTuiListWarppers; + } + + /** + * 获取司机兑换优推记录 + * @param driverId + * @return + * @throws Exception + */ + @Override + public List<DriverYouTuiWarpper> queryDriverYouTuiList1(Integer driverId) throws Exception { + return this.baseMapper.queryYouTuiDriverList(driverId, null); + } + + + /** + * 获取司机优推数据 + * @param driverId + * @param pageNum + * @param pageSize + * @return + * @throws Exception + */ + @Override + public List<DriverYouTuiWarpper> queryDriverYouTui(Integer driverId, Integer pageNum, Integer pageSize) throws Exception { + pageNum = (pageNum - 1) * pageSize; + return this.baseMapper.queryDriverYouTui(driverId, pageNum, pageSize); + } + + + /** + * 获取待兑换的优推数据 + * @param pageNum + * @param pageSize + * @return + * @throws Exception + */ + @Override + public List<DriverYouTuiWarpper> queryAllYouTui(Integer pageNum, Integer pageSize) throws Exception { + pageNum = (pageNum - 1) * pageSize; + return this.baseMapper.queryAllYouTui(pageNum, pageSize); + } + + + /** + * 司机兑换优推数据 + * @param driverId + * @param id + * @return + * @throws Exception + */ + @Override + public ResultUtil redeemBenefits(Integer driverId, Integer id) throws Exception { + YouTui youTui = youTuiService.selectById(id); + if(youTui.getStatus() != 1){ + return ResultUtil.error("优推已下架"); + } + Driver driver = driverService.selectById(driverId); + if(null == driver.getIntegral() || youTui.getIntegral() > driver.getIntegral()){ + return ResultUtil.error("积分不足"); + } + + AccountChangeDetail accountChangeDetail = new AccountChangeDetail(); + accountChangeDetail.setCode(System.currentTimeMillis() + UUIDUtil.getNumberRandom(5)); + accountChangeDetail.setUserType(2); + accountChangeDetail.setUserId(driverId); + accountChangeDetail.setType(2); + accountChangeDetail.setOldData(driver.getIntegral().doubleValue()); + accountChangeDetail.setExplain("兑换优推"); + accountChangeDetail.setCreateTime(new Date()); + driver.setIntegral(driver.getIntegral() - youTui.getIntegral()); + accountChangeDetail.setNewData(driver.getIntegral().doubleValue()); + driverService.updateById(driver); + accountChangeDetailService.insert(accountChangeDetail); + + YouTuiDriver youTuiDriver = new YouTuiDriver(); + youTuiDriver.setDriverId(driverId); + youTuiDriver.setYouTuiId(id); + youTuiDriver.setIntegral(youTui.getIntegral()); + youTuiDriver.setType(youTui.getType()); + if(youTui.getType() == 1){//次数 + youTuiDriver.setSurplusQuantity(youTui.getNumber()); + } + if(youTui.getType() == 2){//小时 + youTuiDriver.setEndTime(new Date(System.currentTimeMillis() + (youTui.getNumber() * 60 * 60 * 1000))); + } + youTuiDriver.setState(1); + youTuiDriver.setFailureTime(new Date(System.currentTimeMillis() + (youTui.getEffectiveTime() * 24 * 60 * 60 * 1000))); + youTuiDriver.setCreateTime(new Date()); + this.insert(youTuiDriver); + return ResultUtil.success(); + } + + @Override + public void editState() throws Exception { + this.baseMapper.editState(); + } } -- Gitblit v1.7.1