package com.dsh.account.service.impl;
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
import com.dsh.account.entity.TAppUser;
|
import com.dsh.account.entity.UserIntegral;
|
import com.dsh.account.entity.UserIntegralChanges;
|
import com.dsh.account.feignclient.activity.MerChandiseClient;
|
import com.dsh.account.mapper.TAppUserMapper;
|
import com.dsh.account.mapper.UserIntegralChangesMapper;
|
import com.dsh.account.model.IntegralListQuery;
|
import com.dsh.account.model.SaveUserIntegralChangesVo;
|
import com.dsh.account.model.vo.userBenefitDetail.ExchangeDetailsResponse;
|
import com.dsh.account.model.vo.userBenefitDetail.ExchangeDetailsVo;
|
import com.dsh.account.model.vo.userBenefitDetail.IntegralsData;
|
import com.dsh.account.model.vo.userBenefitDetail.PointDetailsVo;
|
import com.dsh.account.service.UserIntegralChangesService;
|
import com.dsh.account.util.DateTimeHelper;
|
import com.dsh.account.util.ToolUtil;
|
import org.springframework.stereotype.Service;
|
import org.springframework.util.StringUtils;
|
|
import javax.annotation.Resource;
|
import java.text.SimpleDateFormat;
|
import java.util.ArrayList;
|
import java.util.Date;
|
import java.util.List;
|
import java.util.Objects;
|
import java.util.stream.Collectors;
|
|
/**
|
* <p>
|
* 用户积分变动记录 服务实现类
|
* </p>
|
*
|
* @author jqs
|
* @since 2023-07-10
|
*/
|
@Service
|
public class UserIntegralChangesServiceImpl extends ServiceImpl<UserIntegralChangesMapper, UserIntegralChanges> implements UserIntegralChangesService {
|
|
@Resource
|
private TAppUserMapper tauMapper;
|
|
@Resource
|
private MerChandiseClient mcClient;
|
|
@Override
|
public List<IntegralsData> queryUserPointsDetails(String yearMonth, Integer recordId, Integer userIdFormRedis) {
|
List<IntegralsData> details = new ArrayList<>();
|
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("MM-dd HH:mm");
|
|
Date monthStart = null;
|
Date monthEnd = null;
|
if (StringUtils.hasText(yearMonth)) {
|
monthStart = DateTimeHelper.getCurrentIdetMouthStart(yearMonth);
|
monthEnd = DateTimeHelper.getCurrentIdeaMouthEnd(yearMonth);
|
} else {
|
monthStart = DateTimeHelper.getCurrentMouthStart();
|
monthEnd = DateTimeHelper.getCurrentMouthEnd();
|
}
|
List<UserIntegralChanges> userIntegralChanges = this.baseMapper.selectList(new QueryWrapper<UserIntegralChanges>()
|
.eq("appUserId",userIdFormRedis )
|
.between("insertTime",monthStart,monthEnd)
|
.orderByDesc("insertTime"));
|
if (userIntegralChanges.size() > 0 ){
|
for (UserIntegralChanges userIntegralChange : userIntegralChanges) {
|
IntegralsData detail= new IntegralsData();
|
switch (userIntegralChange.getType()){
|
case 1:
|
detail.setConsumeAmount("+"+(userIntegralChange.getNewIntegral() - userIntegralChange.getOldIntegral()));
|
detail.setConsumeName("赠送积分");
|
detail.setDetailsType(2);
|
break;
|
case 2:
|
detail.setConsumeAmount(""+(userIntegralChange.getNewIntegral() - userIntegralChange.getOldIntegral()));
|
detail.setConsumeName("兑换商品");
|
detail.setDetailsType(1);
|
break;
|
case 3:
|
detail.setConsumeAmount("+"+(userIntegralChange.getNewIntegral() - userIntegralChange.getOldIntegral()));
|
detail.setConsumeName("完成课后练习");
|
detail.setDetailsType(2);
|
break;
|
case 4:
|
detail.setConsumeAmount("+"+(userIntegralChange.getNewIntegral() - userIntegralChange.getOldIntegral()));
|
detail.setConsumeTime(simpleDateFormat.format(userIntegralChange.getInsertTime()));
|
detail.setConsumeName("观看教学视频");
|
detail.setDetailsType(2);
|
break;
|
case 5:
|
detail.setConsumeAmount(""+(userIntegralChange.getNewIntegral() - userIntegralChange.getOldIntegral()));
|
detail.setConsumeName("智慧球场开始游戏");
|
detail.setDetailsType(1);
|
break;
|
default:
|
break;
|
}
|
detail.setConsumeTime(simpleDateFormat.format(userIntegralChange.getInsertTime()));
|
details.add(detail);
|
}
|
if (null != recordId){
|
details = details.stream()
|
.filter(obj -> obj instanceof IntegralsData)
|
.filter(obj -> !Objects.equals(obj.getDetailsType(), recordId))
|
.collect(Collectors.toList());
|
}
|
}
|
return details;
|
}
|
|
|
/**
|
* 保存用户积分变动
|
* @param vo
|
* @throws Exception
|
*/
|
@Override
|
public void saveUserIntegralChanges(SaveUserIntegralChangesVo vo) throws Exception {
|
TAppUser appUser = tauMapper.selectById(vo.getAppUserId());
|
UserIntegralChanges userIntegralChanges = new UserIntegralChanges();
|
userIntegralChanges.setAppUserId(vo.getAppUserId());
|
userIntegralChanges.setOldIntegral(appUser.getIntegral());
|
userIntegralChanges.setType(vo.getType());
|
|
appUser.setIntegral(appUser.getIntegral() + vo.getIntegral());
|
tauMapper.updateById(appUser);
|
userIntegralChanges.setNewIntegral(appUser.getIntegral());
|
userIntegralChanges.setInsertTime(new Date());
|
userIntegralChanges.setCategory(1);
|
userIntegralChanges.setRemark(vo.getRemark());
|
this.save(userIntegralChanges);
|
}
|
|
@Override
|
public List<ExchangeDetailsResponse> queryExchangeGoodsdetails(Integer userIdFormRedis, Integer useType, Integer goodType) {
|
List<ExchangeDetailsResponse> detailsResponses = new ArrayList<>();
|
ExchangeDetailsVo integralExchangeDetails = mcClient.getIntegralExchangeDetails(userIdFormRedis);
|
if (ToolUtil.isNotEmpty(integralExchangeDetails.getDetailsResponses())){
|
detailsResponses = integralExchangeDetails.getDetailsResponses();
|
if (ToolUtil.isNotEmpty(useType)){
|
detailsResponses = integralExchangeDetails.getDetailsResponses().stream()
|
.filter(response -> Objects.equals(response.getUseStatus(), useType))
|
.collect(Collectors.toList());
|
}
|
if (ToolUtil.isNotEmpty(goodType)){
|
detailsResponses = integralExchangeDetails.getDetailsResponses().stream()
|
.filter(response -> Objects.equals(response.getGoodType(), goodType))
|
.collect(Collectors.toList());
|
}
|
}
|
return detailsResponses;
|
}
|
|
@Override
|
public PointDetailsVo queryRedemptionDetails(Long detailsId) {
|
PointDetailsVo specificsOfGoods = mcClient.getSpecificsOfGoods(detailsId);
|
return specificsOfGoods;
|
}
|
|
@Override
|
public Page<UserIntegral> listAll(Page<UserIntegral> userIntegralPage, IntegralListQuery integralListQuery) {
|
String sTime =null;
|
String eTime =null;
|
if(ToolUtil.isNotEmpty(integralListQuery.getTime())){
|
sTime = integralListQuery.getTime().split(" - ")[0]+" 00:00:00";
|
eTime = integralListQuery.getTime().split(" - ")[1]+" 23:59:59";
|
}
|
Page<UserIntegral> userIntegrals = this.baseMapper.listAll(userIntegralPage, integralListQuery, sTime, eTime);
|
for (UserIntegral userIntegral : userIntegrals.getRecords()) {
|
if(userIntegral.getCategory()==1){
|
userIntegral.setIntegral(userIntegral.getNewIntegral()-userIntegral.getOldIntegral());
|
}else {
|
userIntegral.setIntegral(userIntegral.getOldIntegral()-userIntegral.getNewIntegral());
|
}
|
}
|
return userIntegrals;
|
}
|
|
@Override
|
public List<ExchangeDetailsResponse> queryExchangeGoodsdetails1(Integer userIdFormRedis, Integer useType, Integer goodType, Integer page, Integer size) {
|
List<ExchangeDetailsResponse> detailsResponses = new ArrayList<>();
|
ExchangeDetailsVo integralExchangeDetails = mcClient.getIntegralExchangeDetails(userIdFormRedis);
|
|
|
if (ToolUtil.isNotEmpty(integralExchangeDetails.getDetailsResponses())){
|
detailsResponses = integralExchangeDetails.getDetailsResponses();
|
if (ToolUtil.isNotEmpty(useType)){
|
detailsResponses = detailsResponses.stream()
|
.filter(response -> Objects.equals(response.getUseStatus(), useType))
|
.collect(Collectors.toList());
|
}
|
if (ToolUtil.isNotEmpty(goodType)){
|
detailsResponses = detailsResponses.stream()
|
.filter(response -> Objects.equals(response.getGoodType(), goodType))
|
.collect(Collectors.toList());
|
}
|
}
|
|
|
|
|
int totalItems = detailsResponses.size();
|
int startIndex = (page - 1) * size;
|
int endIndex = Math.min(startIndex + size, totalItems);
|
|
if (startIndex <= endIndex) {
|
detailsResponses = detailsResponses.subList(startIndex, endIndex);
|
} else {
|
detailsResponses.clear();
|
}
|
|
|
|
|
return detailsResponses;
|
}
|
}
|