更新9.20

This commit is contained in:
许允枞 2024-09-20 17:59:07 +08:00
parent f727da7ce3
commit a4c1320597
2 changed files with 67 additions and 38 deletions

View File

@ -1,6 +1,7 @@
package com.fuint.business.userManager.service.impl;
import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.util.ObjectUtil;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
@ -12,6 +13,9 @@ import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.fuint.business.marketingActivity.cardFavorable.entity.CardFavorableRecord;
import com.fuint.business.marketingActivity.cardFavorable.mapper.CardFavorableRecordMapper;
import com.fuint.business.marketingActivity.cardGift.entity.CardGift;
import com.fuint.business.marketingActivity.cardGift.mapper.CardGiftMapper;
import com.fuint.business.marketingActivity.cardGiftActive.mapper.CardGiftActiveMapper;
import com.fuint.business.marketingActivity.cardValue.entity.CardValueRecord;
import com.fuint.business.marketingActivity.cardValue.mapper.CardValueRecordMapper;
import com.fuint.business.order.mapper.AllOrderInfoMapper;
@ -44,6 +48,7 @@ import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.concurrent.TimeUnit;
import java.util.stream.Collectors;
/**
* 会员储值卡信息 业务层
@ -77,6 +82,10 @@ public class UserBalanceServiceImpl extends ServiceImpl<UserBalanceMapper, UserB
@Autowired
CardFavorableRecordMapper cardFavorableRecordMapper;
@Autowired
CardGiftMapper cardGiftMapper;
@Override
public IPage<UserBalanceVo> listByZt(Page page, UserBalanceVo user) {
if (ObjectUtil.isEmpty(user.getDeptId())) {
@ -98,12 +107,14 @@ public class UserBalanceServiceImpl extends ServiceImpl<UserBalanceMapper, UserB
LJUserGrade ljUserGrade = ljUserGradeMapper.selectById(record.getGradeId());
if (ObjectUtil.isNotEmpty(ljUserGrade)) {
record.setGradeName(ljUserGrade.getName());
}else {record.setGradeName("--");}
} else {
record.setGradeName("--");
}
// 累计充值金额
Map<String, Object> amountAndConsume = cardValueRecordMapper.getAmountAndConsume(record);
if (ObjectUtil.isNotEmpty(amountAndConsume)) {
record.setCountNum(amountAndConsume.get("consumeNum").toString()); // 累计重置次数
record.setAmount(ObjectUtil.isNotEmpty(amountAndConsume.get("amount"))?amountAndConsume.get("amount").toString():"0");
record.setAmount(ObjectUtil.isNotEmpty(amountAndConsume.get("amount")) ? amountAndConsume.get("amount").toString() : "0");
}
@ -131,7 +142,7 @@ public class UserBalanceServiceImpl extends ServiceImpl<UserBalanceMapper, UserB
return userBalanceVoIPage;
}
public Map<String,Object> getDataByZt(UserBalanceVo user) {
public Map<String, Object> getDataByZt(UserBalanceVo user) {
if (ObjectUtil.isEmpty(user.getDeptId())) {
AccountInfo nowAccountInfo = TokenUtil.getNowAccountInfo();
user.setDeptId(nowAccountInfo.getDeptId());
@ -143,17 +154,17 @@ public class UserBalanceServiceImpl extends ServiceImpl<UserBalanceMapper, UserB
Map<String, Object> dataByZt = userBalanceMapper.getDataByZt(user);
Map<String, Object> leiJiInfo = allOrderInfoMapper.getShuJuVipInfo(user);
if (ObjectUtil.isEmpty(dataByZt)){
if (ObjectUtil.isEmpty(dataByZt)) {
dataByZt = new HashMap<>();
}
if (ObjectUtil.isEmpty(leiJiInfo)) {
leiJiInfo = new HashMap<>();
leiJiInfo.put("tongjXfMoney","0");
leiJiInfo.put("tongjMoney","0");
leiJiInfo.put("tongjXfMoney", "0");
leiJiInfo.put("tongjMoney", "0");
}
dataByZt.put("tongjMoney",ObjectUtil.isNotEmpty(leiJiInfo.get("tongjMoney"))?convertYuanToWanYuan((BigDecimal) leiJiInfo.get("tongjMoney")):"0");
dataByZt.put("tongjXfMoney",ObjectUtil.isNotEmpty(leiJiInfo.get("tongjXfMoney"))?convertYuanToWanYuan((BigDecimal) leiJiInfo.get("tongjXfMoney")):"0");
dataByZt.put("tongjMoney", ObjectUtil.isNotEmpty(leiJiInfo.get("tongjMoney")) ? convertYuanToWanYuan((BigDecimal) leiJiInfo.get("tongjMoney")) : "0");
dataByZt.put("tongjXfMoney", ObjectUtil.isNotEmpty(leiJiInfo.get("tongjXfMoney")) ? convertYuanToWanYuan((BigDecimal) leiJiInfo.get("tongjXfMoney")) : "0");
return dataByZt;
}
@ -164,12 +175,12 @@ public class UserBalanceServiceImpl extends ServiceImpl<UserBalanceMapper, UserB
}
@Override
public void deleteUserBalanceByUserId(Integer userId,Integer storeId) {
public void deleteUserBalanceByUserId(Integer userId, Integer storeId) {
/*AccountInfo nowAccountInfo = TokenUtil.getNowAccountInfo();*/
LJStore store = storeService.selectStoreByStoreId(storeId);
QueryWrapper queryWrapper = new QueryWrapper<>();
queryWrapper.eq("mt_user_id",userId);
queryWrapper.eq("chain_store_id",store.getChainStoreId());
queryWrapper.eq("mt_user_id", userId);
queryWrapper.eq("chain_store_id", store.getChainStoreId());
baseMapper.delete(queryWrapper);
}
@ -180,8 +191,6 @@ public class UserBalanceServiceImpl extends ServiceImpl<UserBalanceMapper, UserB
}
public int addUserBalanceByLock(Integer oilId, Integer userId, Integer changeBalance) {
// int row = baseMapper.addUserBalance(balance);
@ -192,16 +201,17 @@ public class UserBalanceServiceImpl extends ServiceImpl<UserBalanceMapper, UserB
@Override
public int addUserOil(String oilId, Integer userId, Integer chainStoreId, Double changeOil) {
UserBalance userBalance = selectUserBalance(userId, chainStoreId);
if(ObjectUtil.isNotEmpty(userBalance)&& ObjectUtil.isNotEmpty(userBalance.getRefuelMoney())) {
if (ObjectUtil.isNotEmpty(userBalance) && ObjectUtil.isNotEmpty(userBalance.getRefuelMoney())) {
List<Map<String, Object>> resultMapList = JSON.parseObject(userBalance.getRefuelMoney(), new TypeReference<List<Map<String, Object>>>() {});
List<Map<String, Object>> resultMapList = JSON.parseObject(userBalance.getRefuelMoney(), new TypeReference<List<Map<String, Object>>>() {
});
if (ObjectUtil.isNotEmpty(resultMapList)) {
for (Map<String, Object> stringStringMap : resultMapList) {
if (oilId.equals(String.valueOf(stringStringMap.get("oilType")))) {
BigDecimal resRefuelMoney = new BigDecimal(String.valueOf(stringStringMap.get("refuelMoney")));
BigDecimal refuelMoney = resRefuelMoney.add(new BigDecimal(changeOil.toString()));
stringStringMap.put("refuelMoney",refuelMoney.toString());
stringStringMap.put("refuelMoney", refuelMoney.toString());
break;
}
}
@ -210,8 +220,6 @@ public class UserBalanceServiceImpl extends ServiceImpl<UserBalanceMapper, UserB
}
}
@ -234,11 +242,11 @@ public class UserBalanceServiceImpl extends ServiceImpl<UserBalanceMapper, UserB
public Double selectAllBalance(Integer storeId) {
LJStore ljStore = storeService.queryStoreById(storeId);
QueryWrapper queryWrapper = new QueryWrapper<>();
queryWrapper.eq("chain_store_id",ljStore.getChainStoreId());
queryWrapper.eq("chain_store_id", ljStore.getChainStoreId());
queryWrapper.select("SUM(card_balance) as cardBalance");
UserBalance userBalance = baseMapper.selectOne(queryWrapper);
Double cardBalance = 0.0;
if (ObjectUtil.isNotEmpty(userBalance) && ObjectUtil.isNotEmpty(userBalance.getCardBalance())){
if (ObjectUtil.isNotEmpty(userBalance) && ObjectUtil.isNotEmpty(userBalance.getCardBalance())) {
cardBalance = userBalance.getCardBalance();
}
return cardBalance;
@ -258,23 +266,23 @@ public class UserBalanceServiceImpl extends ServiceImpl<UserBalanceMapper, UserB
@Override
public int subtractUserBalanceByLock(UserBalanceVo balance) {
String lockKey = "userChangeBalance"+balance.getMtUserId()+balance.getChainStoreId();
String lockKey = "userChangeBalance" + balance.getMtUserId() + balance.getChainStoreId();
Boolean flag = redisLock.tryLock(lockKey, 5001, 5000, TimeUnit.MILLISECONDS);
if (flag) {
UserBalance userBalance = selectUserBalance(balance.getMtUserId(), balance.getChainStoreId());
if (ObjectUtil.isEmpty(userBalance)) throw new RuntimeException("暂无用户信息!");
if (ObjectUtil.isNotEmpty(balance.getChangeCardBalance())) {
if (balance.getChangeCardBalance().compareTo(userBalance.getCardBalance())>0) {
if (balance.getChangeCardBalance().compareTo(userBalance.getCardBalance()) > 0) {
throw new RuntimeException("用户余额不足!");
}
}
if (ObjectUtil.isNotEmpty(balance.getChangePoints())) {
if (balance.getChangeCardBalance().compareTo(userBalance.getCardBalance())>0) {
if (balance.getChangeCardBalance().compareTo(userBalance.getCardBalance()) > 0) {
throw new RuntimeException("用户积分不足!");
}
}
if (ObjectUtil.isNotEmpty(balance.getChangeGrowthValue())) {
if (balance.getChangeGrowthValue().compareTo(userBalance.getGrowthValue())>0) {
if (balance.getChangeGrowthValue().compareTo(userBalance.getGrowthValue()) > 0) {
throw new RuntimeException("用户成长值不足!");
}
}
@ -290,7 +298,7 @@ public class UserBalanceServiceImpl extends ServiceImpl<UserBalanceMapper, UserB
@Override
public List<UserBalance> selectUserBalance(int userId) {
QueryWrapper queryWrapper = new QueryWrapper<>();
queryWrapper.eq("mt_user_id",userId);
queryWrapper.eq("mt_user_id", userId);
return baseMapper.selectList(queryWrapper);
}
@ -298,7 +306,7 @@ public class UserBalanceServiceImpl extends ServiceImpl<UserBalanceMapper, UserB
public UserBalance selectUserBalanceByUserId() {
AccountInfo nowAccountInfo = TokenUtil.getNowAccountInfo();
QueryWrapper queryWrapper = new QueryWrapper<>();
queryWrapper.eq("mt_user_id",nowAccountInfo.getId());
queryWrapper.eq("mt_user_id", nowAccountInfo.getId());
UserBalance balance = baseMapper.selectOne(queryWrapper);
return balance;
}
@ -306,8 +314,8 @@ public class UserBalanceServiceImpl extends ServiceImpl<UserBalanceMapper, UserB
@Override
public UserBalance selectUserBalance(int userId, int chainStoreId) {
QueryWrapper queryWrapper = new QueryWrapper<>();
queryWrapper.eq("mt_user_id",userId);
queryWrapper.eq("chain_store_id",chainStoreId);
queryWrapper.eq("mt_user_id", userId);
queryWrapper.eq("chain_store_id", chainStoreId);
UserBalance balance = baseMapper.selectOne(queryWrapper);
return balance;
}
@ -315,57 +323,72 @@ public class UserBalanceServiceImpl extends ServiceImpl<UserBalanceMapper, UserB
@Override
public UserBalance selectUserBalanceByStorId(int userId, int storeId) {
QueryWrapper queryWrapper = new QueryWrapper<>();
queryWrapper.eq("mt_user_id",userId);
queryWrapper.eq("store_id",storeId);
queryWrapper.eq("mt_user_id", userId);
queryWrapper.eq("store_id", storeId);
UserBalance balance = baseMapper.selectOne(queryWrapper);
return balance;
}
/**
* 查询会员储值卡余额
*
* @return
*/
@Override
public UserBalance getUserBalance() {
AccountInfo nowAccountInfo = TokenUtil.getNowAccountInfo();
QueryWrapper queryWrapper = new QueryWrapper<>();
queryWrapper.eq("mt_user_id",nowAccountInfo.getId());
queryWrapper.eq("store_id",nowAccountInfo.getStoreId());
queryWrapper.eq("mt_user_id", nowAccountInfo.getId());
queryWrapper.eq("store_id", nowAccountInfo.getStoreId());
UserBalance balance = baseMapper.selectOne(queryWrapper);
return balance;
}
/**
* 查询会员储值卡余额
*
* @return
*/
@Override
public UserBlanceUniVo getUserBalanceApplet(UserBalance userBalance) {
AccountInfo nowAccountInfo = TokenUtil.getNowAccountInfo();
QueryWrapper queryWrapper = new QueryWrapper<>();
queryWrapper.eq("mt_user_id",nowAccountInfo.getId());
queryWrapper.eq("chain_store_id",userBalance.getChainStoreId());
queryWrapper.eq("mt_user_id", nowAccountInfo.getId());
queryWrapper.eq("chain_store_id", userBalance.getChainStoreId());
UserBalance balance = baseMapper.selectOne(queryWrapper);
UserBlanceUniVo userBlanceUniVo = new UserBlanceUniVo();
if (ObjectUtil.isNotEmpty(balance)) {
userBlanceUniVo = BeanUtil.copyProperties(balance,UserBlanceUniVo.class);
userBlanceUniVo = BeanUtil.copyProperties(balance, UserBlanceUniVo.class);
Double giveAmount = ObjectUtil.isNotEmpty(balance.getGiveAmount()) ? balance.getGiveAmount() : 0;
userBlanceUniVo.setAllBalance(balance.getCardBalance()+ giveAmount);
userBlanceUniVo.setAllBalance(balance.getCardBalance() + giveAmount);
//查询优惠券数量
Integer count = cardFavorableRecordMapper.selectCount(new LambdaQueryWrapper<CardFavorableRecord>()
.eq(CardFavorableRecord::getMtUserId, balance.getMtUserId())
.eq(CardFavorableRecord::getMtUserId, nowAccountInfo.getId())
.eq(CardFavorableRecord::getStatus, 0)
.eq(CardFavorableRecord::getStoreId, balance.getStoreId()));
userBlanceUniVo.setCardFavorableCount(count);
}else {
//查询礼品卡已兑换数量和金额
List<CardGift> cardGifts = cardGiftMapper.selectList(new LambdaQueryWrapper<CardGift>()
.eq(CardGift::getUserId, nowAccountInfo.getId())
.eq(CardGift::getStoreId, balance.getStoreId()));
if (CollUtil.isNotEmpty(cardGifts)) {
Double giftCardAmount = cardGifts.stream().mapToDouble(CardGift::getCardAmount).sum();
userBlanceUniVo.setGiftCardAmount(giftCardAmount);
}
userBlanceUniVo.setGiftCardCount(cardGifts.size());
} else {
userBlanceUniVo.setAllBalance(0.0);
userBlanceUniVo.setCardBalance(0.0);
userBlanceUniVo.setGiveAmount(0.0);
}
return userBlanceUniVo;
}
/**
* 初始化用户余额信息
*
* @param userId
* @param chainStoreId
* @return

View File

@ -10,4 +10,10 @@ public class UserBlanceUniVo extends UserBalance {
//卡券数量
private int cardFavorableCount;
//礼品卡数量
private int giftCardCount;
//礼品卡总金额
private Double giftCardAmount;
}