diff --git a/fuintBackend/fuint-application/src/main/java/com/fuint/business/marketingActivity/cardFule/controller/CardFuelRecordController.java b/fuintBackend/fuint-application/src/main/java/com/fuint/business/marketingActivity/cardFule/controller/CardFuelRecordController.java index cf706efde..216b3c774 100644 --- a/fuintBackend/fuint-application/src/main/java/com/fuint/business/marketingActivity/cardFule/controller/CardFuelRecordController.java +++ b/fuintBackend/fuint-application/src/main/java/com/fuint/business/marketingActivity/cardFule/controller/CardFuelRecordController.java @@ -174,5 +174,13 @@ public class CardFuelRecordController extends BaseController { return getSuccessResult(this.cardFuelRecordService.selectFuelRecordCount(cardFuelRecord)); } + /** + * 统计接口 + */ + @GetMapping("testss") + public ResponseObject test() { + this.cardFuelRecordService.expireOilToBalance(); + return getSuccessResult("11"); + } } diff --git a/fuintBackend/fuint-application/src/main/java/com/fuint/business/marketingActivity/cardFule/entity/CardFuelDiesel.java b/fuintBackend/fuint-application/src/main/java/com/fuint/business/marketingActivity/cardFule/entity/CardFuelDiesel.java index 44c51f9ee..d5d66a9c8 100644 --- a/fuintBackend/fuint-application/src/main/java/com/fuint/business/marketingActivity/cardFule/entity/CardFuelDiesel.java +++ b/fuintBackend/fuint-application/src/main/java/com/fuint/business/marketingActivity/cardFule/entity/CardFuelDiesel.java @@ -47,6 +47,9 @@ public class CardFuelDiesel extends Model { //活动开始时间 @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss" , timezone = "GMT+8") private Date startTime; + //活动到期时间 + @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss" , timezone = "GMT+8") + private Date expireTime; //活动结束时间 @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss" , timezone = "GMT+8") private Date endTime; diff --git a/fuintBackend/fuint-application/src/main/java/com/fuint/business/marketingActivity/cardFule/entity/CardFuelRecord.java b/fuintBackend/fuint-application/src/main/java/com/fuint/business/marketingActivity/cardFule/entity/CardFuelRecord.java index 3aaa5a7da..b5e29cded 100644 --- a/fuintBackend/fuint-application/src/main/java/com/fuint/business/marketingActivity/cardFule/entity/CardFuelRecord.java +++ b/fuintBackend/fuint-application/src/main/java/com/fuint/business/marketingActivity/cardFule/entity/CardFuelRecord.java @@ -111,6 +111,9 @@ public class CardFuelRecord extends BaseEntity { */ @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss" , timezone = "GMT+8") private Date updateTime; + //活动到期时间 + @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss" , timezone = "GMT+8") + private Date expireTime; /** * 支付状态 */ diff --git a/fuintBackend/fuint-application/src/main/java/com/fuint/business/marketingActivity/cardFule/mapper/CardFuelRecordMapper.java b/fuintBackend/fuint-application/src/main/java/com/fuint/business/marketingActivity/cardFule/mapper/CardFuelRecordMapper.java index 2c94e7fa0..b57df1d93 100644 --- a/fuintBackend/fuint-application/src/main/java/com/fuint/business/marketingActivity/cardFule/mapper/CardFuelRecordMapper.java +++ b/fuintBackend/fuint-application/src/main/java/com/fuint/business/marketingActivity/cardFule/mapper/CardFuelRecordMapper.java @@ -1,7 +1,9 @@ package com.fuint.business.marketingActivity.cardFule.mapper; +import com.baomidou.mybatisplus.core.mapper.BaseMapper; import com.baomidou.mybatisplus.core.metadata.IPage; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; +import com.fuint.business.marketingActivity.activeApplet.entity.ActiveApplet; import com.fuint.business.marketingActivity.cardFule.dto.CardFuelRecordDTO; import com.fuint.business.marketingActivity.cardFule.entity.CardFuelRecord; import com.fuint.business.marketingActivity.cardFule.vo.CardFuelRecordCount; @@ -16,7 +18,7 @@ import java.util.Map; * @author wangh * @since 2023-11-13 18:53:32 */ -public interface CardFuelRecordMapper { +public interface CardFuelRecordMapper extends BaseMapper { /** * 通过ID查询单条数据 diff --git a/fuintBackend/fuint-application/src/main/java/com/fuint/business/marketingActivity/cardFule/service/CardFuelRecordService.java b/fuintBackend/fuint-application/src/main/java/com/fuint/business/marketingActivity/cardFule/service/CardFuelRecordService.java index afd41e5b5..4fd993ca7 100644 --- a/fuintBackend/fuint-application/src/main/java/com/fuint/business/marketingActivity/cardFule/service/CardFuelRecordService.java +++ b/fuintBackend/fuint-application/src/main/java/com/fuint/business/marketingActivity/cardFule/service/CardFuelRecordService.java @@ -110,4 +110,5 @@ public interface CardFuelRecordService { * @return */ List selectFuelRecordCount(CardFuelRecord cardFuelRecord); + public void expireOilToBalance(); } diff --git a/fuintBackend/fuint-application/src/main/java/com/fuint/business/marketingActivity/cardFule/service/impl/CardFuelRecordServiceImpl.java b/fuintBackend/fuint-application/src/main/java/com/fuint/business/marketingActivity/cardFule/service/impl/CardFuelRecordServiceImpl.java index e757f8428..8b7ee4d5f 100644 --- a/fuintBackend/fuint-application/src/main/java/com/fuint/business/marketingActivity/cardFule/service/impl/CardFuelRecordServiceImpl.java +++ b/fuintBackend/fuint-application/src/main/java/com/fuint/business/marketingActivity/cardFule/service/impl/CardFuelRecordServiceImpl.java @@ -5,6 +5,7 @@ import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSONArray; import com.alibaba.fastjson.JSONObject; import com.alibaba.fastjson.TypeReference; +import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.core.metadata.IPage; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.fasterxml.jackson.core.JsonProcessingException; @@ -38,6 +39,7 @@ import com.fuint.business.storeInformation.entity.LJStore; import com.fuint.business.storeInformation.service.ILJStoreService; import com.fuint.business.userManager.entity.UserBalance; import com.fuint.business.userManager.mapper.LJUserMapper; +import com.fuint.business.userManager.mapper.UserBalanceMapper; import com.fuint.business.userManager.service.UserBalanceService; import com.fuint.business.userManager.vo.LJUserVo; import com.fuint.common.util.RedisLock; @@ -53,6 +55,7 @@ import org.springframework.transaction.annotation.Transactional; import javax.annotation.Resource; import java.math.BigDecimal; import java.text.SimpleDateFormat; +import java.time.LocalDate; import java.util.*; import java.util.concurrent.TimeUnit; @@ -469,6 +472,7 @@ public class CardFuelRecordServiceImpl implements CardFuelRecordService { //查询囤油卡信息 CardFuelDiesel cardFuelDiesel = cardFuelDieselService.getById(cardFuelRecordDTO.getId()); cardFuleOrders.setCardFuleId(cardFuelDiesel.getId()); + cardFuleOrders.setExpireTime(cardFuelDiesel.getExpireTime()); cardFuleOrders.setAmount(cardFuelDiesel.getRechargeBalance()); cardFuleOrders.setPayAmount(cardFuelDiesel.getRechargeBalance()); cardFuleOrders.setPoints(cardFuelDiesel.getPoints()); @@ -658,9 +662,70 @@ public class CardFuelRecordServiceImpl implements CardFuelRecordService { cardFuelRecord.setType(cardFuleOrders.getType()); cardFuelRecord.setOilType(cardFuleOrders.getOilType()+ cardFuleOrders.getOilName()); cardFuelRecord.setOilName(cardFuleOrders.getOilName()); + cardFuelRecord.setExpireTime(cardFuleOrders.getExpireTime()); cardFuelRecordMapper.insert(cardFuelRecord); } + + @Override + public void expireOilToBalance() { + SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd"); + Date date = new Date(); + String format = simpleDateFormat.format(date); + + //余额 + List list = userBalanceService.list(); + for (UserBalance userBalance : list) { + String refuelMoney = userBalance.getRefuelMoney(); + Double cardBalance = userBalance.getCardBalance(); + if (ObjectUtils.isNotEmpty(userBalance.getStoreId()) && ObjectUtils.isNotEmpty(refuelMoney)) { + List jsonObjectList = JSONArray.parseArray(refuelMoney, JSONObject.class); + + for (JSONObject jsonObject : jsonObjectList) { + String oilType = jsonObject.getString("oilType"); + String type = jsonObject.getString("type"); + Integer refuelMoney1 = jsonObject.getInteger("refuelMoney"); + if (ObjectUtils.isNotEmpty(oilType)) { + LambdaQueryWrapper queryWrapper = new LambdaQueryWrapper<>(); + queryWrapper.eq(CardFuelRecord::getStoreId, userBalance.getStoreId()) + .eq(CardFuelRecord::getMtUserId, userBalance.getMtUserId()) + .eq(CardFuelRecord::getOilType, oilType) + .orderByAsc(CardFuelRecord::getCreateTime); + List cardFuelRecords = cardFuelRecordMapper.selectList(queryWrapper); + + Double oil = 0.0; + for (CardFuelRecord cardFuelRecord : cardFuelRecords) { + if(refuelMoney1 > oil){ + oil += cardFuelRecord.getPayAmount()/cardFuelRecord.getLockupPrice(); + }else { + if (ObjectUtils.isNotEmpty(cardFuelRecord.getExpireTime())){ + String format1 = simpleDateFormat.format(cardFuelRecord.getExpireTime()); + //如果到期 这次充值囤油的钱转到余额 + if (format1.equals(format)){ + double restOil = cardFuelRecord.getPayAmount() - (oil - refuelMoney1); + //升数对应减少 + Double lockupPrice = cardFuelRecord.getLockupPrice(); + double restMoney = oil * lockupPrice; + + JSONObject jsonObject1 = new JSONObject(); + jsonObject1.put("type", type); + jsonObject1.put("oilType", oilType); + jsonObject1.put("refuelMoney", refuelMoney1-restOil); + jsonObjectList.add(jsonObject1); + String userBnlancce = jsonObjectList.toString(); + userBalance.setRefuelMoney(userBnlancce); + userBalance.setCardBalance(cardBalance + restMoney); + } + } + + } + } + } + } + } + } + } + /** * 统计接口 * @param cardFuelRecord diff --git a/fuintBackend/fuint-application/src/main/java/com/fuint/business/marketingActivity/cardFuleOrders/entity/CardFuleOrders.java b/fuintBackend/fuint-application/src/main/java/com/fuint/business/marketingActivity/cardFuleOrders/entity/CardFuleOrders.java index 756b8895d..0671ee3eb 100644 --- a/fuintBackend/fuint-application/src/main/java/com/fuint/business/marketingActivity/cardFuleOrders/entity/CardFuleOrders.java +++ b/fuintBackend/fuint-application/src/main/java/com/fuint/business/marketingActivity/cardFuleOrders/entity/CardFuleOrders.java @@ -80,5 +80,8 @@ public class CardFuleOrders extends Model { //更新时间 @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss" , timezone = "GMT+8") private Date updateTime; + //活动到期时间 + @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss" , timezone = "GMT+8") + private Date expireTime; } diff --git a/fuintBackend/fuint-application/src/main/java/com/fuint/business/marketingActivity/cardValue/controller/CardValueController.java b/fuintBackend/fuint-application/src/main/java/com/fuint/business/marketingActivity/cardValue/controller/CardValueController.java index 734f71ecd..76300b76d 100644 --- a/fuintBackend/fuint-application/src/main/java/com/fuint/business/marketingActivity/cardValue/controller/CardValueController.java +++ b/fuintBackend/fuint-application/src/main/java/com/fuint/business/marketingActivity/cardValue/controller/CardValueController.java @@ -2,7 +2,6 @@ package com.fuint.business.marketingActivity.cardValue.controller; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; -import com.fuint.business.marketingActivity.activeConsumption.entity.ActiveConsumption; import com.fuint.business.marketingActivity.cardValue.dto.CardValueDTO; import com.fuint.business.marketingActivity.cardValue.entity.CardValue; import com.fuint.business.marketingActivity.cardValue.service.CardValueService;