This commit is contained in:
齐天大圣 2024-04-10 16:39:29 +08:00
parent 46a0106ab7
commit 25cf450810
6 changed files with 109 additions and 45 deletions

View File

@ -123,7 +123,7 @@
LEFT JOIN card_exchange ce ON cer.card_exchange_id = ce.id
WHERE
cer.mt_user_id = #{cardFavorableDTOS.id}
and ce.type = 0 or ce.type = 1
and ce.type = 0 or cer.mt_user_id = #{cardFavorableDTOS.id} and ce.type = 1
<if test="cardFavorableDTOS.useStatus!=null and cardFavorableDTOS.useStatus != ''">
and cer.status = #{cardFavorableDTOS.useStatus}
</if>

View File

@ -173,5 +173,10 @@ public class CardFuelRecordController extends BaseController {
public ResponseObject selectFuelRecordCount(@Param("cardFuelRecord") CardFuelRecord cardFuelRecord) {
return getSuccessResult(this.cardFuelRecordService.selectFuelRecordCount(cardFuelRecord));
}
@GetMapping("testgtr")
public void test() {
this.cardFuelRecordService.expireOilToBalance();
}
}

View File

@ -32,6 +32,7 @@ public class CardFuelRecord extends BaseEntity {
* 会员名字
*/
private String name;
private String enchangeStatus;
/**
* 会员手机号码
*/

View File

@ -45,6 +45,7 @@ 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;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.ObjectUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
@ -57,6 +58,7 @@ import org.springframework.transaction.annotation.Transactional;
import javax.annotation.Resource;
import java.math.BigDecimal;
import java.math.RoundingMode;
import java.text.SimpleDateFormat;
import java.time.LocalDate;
import java.util.*;
@ -69,6 +71,7 @@ import java.util.concurrent.TimeUnit;
* @since 2023-11-13 18:53:47
*/
@Service("cardFuelRecordService")
@Slf4j
public class CardFuelRecordServiceImpl implements CardFuelRecordService {
@Resource
private CardFuelRecordMapper cardFuelRecordMapper;
@ -701,36 +704,48 @@ public class CardFuelRecordServiceImpl implements CardFuelRecordService {
@Scheduled(cron = "0 0 1 * * ?")
public void expireOilToBalance() {
log.info("开始执行定时任务:过期油品转余额");
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");
Date date = new Date();
String format = simpleDateFormat.format(date);
//余额
List<UserBalance> list = userBalanceService.list();
// UserBalance userBalance = userBalanceService.getById(130);
for (UserBalance userBalance : list) {
LambdaQueryWrapper<UserBalance> queryWrapper1 = new LambdaQueryWrapper<>();
queryWrapper1.eq(UserBalance::getMtUserId, 125);
List<UserBalance> list1 = userBalanceService.list(queryWrapper1);
// UserBalance userBalance = userBalanceService.getById(125);
for (UserBalance userBalance : list1) {
String refuelMoney = userBalance.getRefuelMoney();
Double cardBalance = userBalance.getCardBalance();
if (ObjectUtils.isNotEmpty(userBalance.getChainStoreId()) && ObjectUtils.isNotEmpty(refuelMoney)) {
List<JSONObject> jsonObjectList = JSONArray.parseArray(refuelMoney, JSONObject.class);
String oilType = "";
String type = "";
double refuelMoney1 = 0.0;
for (JSONObject jsonObject : jsonObjectList) {
String oilType = jsonObject.getString("oilType");
String type = jsonObject.getString("type");
Integer refuelMoney1 = jsonObject.getInteger("refuelMoney");
oilType = jsonObject.getString("oilType");
type = jsonObject.getString("type");
refuelMoney1 = jsonObject.getDouble("refuelMoney");
}
if (ObjectUtils.isNotEmpty(oilType)) {
LambdaQueryWrapper<CardFuelRecord> queryWrapper = new LambdaQueryWrapper<>();
queryWrapper.eq(CardFuelRecord::getChainStoreId, userBalance.getChainStoreId())
.eq(CardFuelRecord::getMtUserId, userBalance.getMtUserId())
.eq(CardFuelRecord::getOilType, oilType)
.orderByAsc(CardFuelRecord::getCreateTime);
.orderByAsc(CardFuelRecord::getCreateTime)
.eq(CardFuelRecord::getEnchangeStatus, "0");
List<CardFuelRecord> cardFuelRecords = cardFuelRecordMapper.selectList(queryWrapper);
Double oil = 0.0;
double oils = 0.00;
double oil = 0.00;
Integer index = -1;
for (CardFuelRecord cardFuelRecord : cardFuelRecords) {
if(refuelMoney1 >= oil){
oil += cardFuelRecord.getPayAmount()/cardFuelRecord.getLockupPrice();
if(refuelMoney1 > oil){
oils += cardFuelRecord.getPayAmount()/cardFuelRecord.getLockupPrice();
BigDecimal bd3 = BigDecimal.valueOf(oils).setScale(2, RoundingMode.HALF_UP);
oil = bd3.doubleValue();
index += 1;
}else {
// if (ObjectUtils.isNotEmpty(cardFuelRecord.getExpireTime())){
@ -753,8 +768,60 @@ public class CardFuelRecordServiceImpl implements CardFuelRecordService {
// }
// }
}
if (CollectionUtil.isNotEmpty(cardFuelRecords) &&
ObjectUtils.isNotEmpty(cardFuelRecords.get(index).getExpireTime())){
String format1 = simpleDateFormat.format(cardFuelRecords.get(index).getExpireTime());
//如果到期 这次充值囤油的钱转到余额
if (format1.equals(format)){
CardFuelRecord cardFuelRecord1 = cardFuelRecords.get(index);
cardFuelRecord1.setEnchangeStatus("1");
cardFuelRecordMapper.updateById(cardFuelRecord1);
double restOils = 0.00;
if (oil > refuelMoney1){
restOils = cardFuelRecords.get(index).getIncomeLitres() - (oil - refuelMoney1);
}else {
restOils = cardFuelRecords.get(index).getIncomeLitres();
}
//升数对应减少
BigDecimal bd = BigDecimal.valueOf(restOils).setScale(2, RoundingMode.HALF_UP);
double restOil = bd.doubleValue();
Double lockupPrices = cardFuelRecords.get(index).getLockupPrice();
BigDecimal bd1 = BigDecimal.valueOf(lockupPrices).setScale(2, RoundingMode.HALF_UP);
double lockupPrice = bd1.doubleValue();
double restMoneys = restOil * lockupPrice;
BigDecimal bd2 = BigDecimal.valueOf(restMoneys).setScale(1, RoundingMode.HALF_UP);
double restMoney = bd2.doubleValue();
// JSONObject jsonObject1 = new JSONObject();
// jsonObject1.put("type", type);
// jsonObject1.put("oilType", oilType);
// jsonObject1.put("refuelMoney", refuelMoney1-restOil);
List<RefuelMoney> refuelMoneysList = new ArrayList<>();
for (JSONObject object : jsonObjectList) {
RefuelMoney refuelMoney2 = new RefuelMoney();
if (object.get("oilType").equals(oilType)){
refuelMoney2.setRefuelMoney(String.valueOf(refuelMoney1-restOil));
}else {
refuelMoney2.setRefuelMoney(object.get("refuelMoney").toString());
}
refuelMoney2.setType(object.get("type").toString());
refuelMoney2.setOilType(object.get("oilType").toString());
refuelMoneysList.add(refuelMoney2);
}
// jsonObjectList.add(jsonObject1);
String userBnlancce = jsonObjectList.toString();
userBalance.setRefuelMoney(com.alibaba.fastjson2.JSONObject.toJSONString(refuelMoneysList));
userBalance.setCardBalance(cardBalance + restMoney);
userBalanceService.updateUserBalance(userBalance);
}
}
}
if (CollectionUtil.isNotEmpty(cardFuelRecords) &&
/*if (CollectionUtil.isNotEmpty(cardFuelRecords) &&
ObjectUtils.isNotEmpty(cardFuelRecords.get(index).getExpireTime())){
String format1 = simpleDateFormat.format(cardFuelRecords.get(index).getExpireTime());
//如果到期 这次充值囤油的钱转到余额
@ -788,9 +855,9 @@ public class CardFuelRecordServiceImpl implements CardFuelRecordService {
userBalance.setCardBalance(cardBalance + restMoney);
userBalanceService.updateUserBalance(userBalance);
}
}
}*/
}
}
}
}
}

View File

@ -176,7 +176,10 @@ public class AllOrderInfoServiceImpl extends ServiceImpl<AllOrderInfoMapper,AllO
// BigDecimal payMoneyBig = new BigDecimal(allOrderInfo.getPayMoney().toString());
// BigDecimal payMoneyBefBig = payMoneyBig.multiply(new BigDecimal("100")).stripTrailingZeros();
// 退款金额(暂不支持部分退款)
BigDecimal refundAmtBig = new BigDecimal(map.get("refundAmt"));
BigDecimal refundAmtBig = new BigDecimal(allOrderInfo.getPayMoney());
if (ObjectUtil.isNotEmpty(map.get("refundAmt"))){
refundAmtBig = new BigDecimal(map.get("refundAmt"));
}
BigDecimal refundAmtBefBig = refundAmtBig.multiply(new BigDecimal("100"));
map.put("totalAmt",money.toString());
map.put("refundAmt",refundAmtBefBig.setScale(0, RoundingMode.DOWN).toString());

View File

@ -1036,11 +1036,9 @@ public class OilOrderServiceImpl extends ServiceImpl<OilOrderMapper, OilOrder> i
growthAfter = growth + addVal;
// 如果会员成长值达到会员等级成长值则修改会员的会员等级信息
for (int i = 0; i < records.size(); i++){
if ((growthAfter-records.get(i).getGrowthValue())<100){
balance.setGradeId(records.get(i).getId());
}
if (growthAfter>records.get(records.size()-1).getGrowthValue()){
balance.setGradeId(records.get(records.size()-1).getId());
if (growthAfter <records.get(i).getGrowthValue()){
balance.setGradeId(records.get(i-1).getId());
break;
}
}
balance.setGrowthValue(growthAfter);
@ -1051,11 +1049,9 @@ public class OilOrderServiceImpl extends ServiceImpl<OilOrderMapper, OilOrder> i
growthAfter = growth + addVal;
// 如果会员成长值达到会员等级成长值则修改会员的会员等级信息
for (int i = 0; i < records.size(); i++){
if ((growthAfter-records.get(i).getGrowthValue())<100 && (growthAfter-records.get(i).getGrowthValue())>0){
balance.setGradeId(records.get(i).getId());
}
if (growthAfter > records.get(records.size()-1).getGrowthValue()){
balance.setGradeId(records.get(records.size()-1).getId());
if (growthAfter <records.get(i).getGrowthValue()){
balance.setGradeId(records.get(i-1).getId());
break;
}
}
balance.setGrowthValue(growthAfter);
@ -1066,11 +1062,9 @@ public class OilOrderServiceImpl extends ServiceImpl<OilOrderMapper, OilOrder> i
growthAfter = growth + addVal;
// 如果会员成长值达到会员等级成长值则修改会员的会员等级信息
for (int i = 0; i < records.size(); i++){
if ((growthAfter-records.get(i).getGrowthValue())<100){
balance.setGradeId(records.get(i).getId());
}
if (growthAfter>records.get(records.size()-1).getGrowthValue()){
balance.setGradeId(records.get(records.size()-1).getId());
if (growthAfter <records.get(i).getGrowthValue()){
balance.setGradeId(records.get(i-1).getId());
break;
}
}
balance.setGrowthValue(growthAfter);
@ -1563,11 +1557,9 @@ public class OilOrderServiceImpl extends ServiceImpl<OilOrderMapper, OilOrder> i
growthAfter = growth + addVal;
// 如果会员成长值达到会员等级成长值则修改会员的会员等级信息
for (int i = 0; i < records.size(); i++){
if ((growthAfter-records.get(i).getGrowthValue())<100){
balance.setGradeId(records.get(i).getId());
}
if (growthAfter>records.get(records.size()-1).getGrowthValue()){
balance.setGradeId(records.get(records.size()-1).getId());
if (growthAfter <records.get(i).getGrowthValue()){
balance.setGradeId(records.get(i-1).getId());
break;
}
}
balance.setGrowthValue(growthAfter);
@ -1578,11 +1570,9 @@ public class OilOrderServiceImpl extends ServiceImpl<OilOrderMapper, OilOrder> i
growthAfter = growth + addVal;
// 如果会员成长值达到会员等级成长值则修改会员的会员等级信息
for (int i = 0; i < records.size(); i++){
if ((growthAfter-records.get(i).getGrowthValue())<100 && (growthAfter-records.get(i).getGrowthValue())>0){
balance.setGradeId(records.get(i).getId());
}
if (growthAfter > records.get(records.size()-1).getGrowthValue()){
balance.setGradeId(records.get(records.size()-1).getId());
if (growthAfter <records.get(i).getGrowthValue()){
balance.setGradeId(records.get(i-1).getId());
break;
}
}
balance.setGrowthValue(growthAfter);
@ -1593,11 +1583,9 @@ public class OilOrderServiceImpl extends ServiceImpl<OilOrderMapper, OilOrder> i
growthAfter = growth + addVal;
// 如果会员成长值达到会员等级成长值则修改会员的会员等级信息
for (int i = 0; i < records.size(); i++){
if ((growthAfter-records.get(i).getGrowthValue())<100){
balance.setGradeId(records.get(i).getId());
}
if (growthAfter>records.get(records.size()-1).getGrowthValue()){
balance.setGradeId(records.get(records.size()-1).getId());
if (growthAfter <records.get(i).getGrowthValue()){
balance.setGradeId(records.get(i-1).getId());
break;
}
}
balance.setGrowthValue(growthAfter);