package com.jilongda.manage.service.impl;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.jilongda.common.basic.PageInfo;
import com.jilongda.manage.mapper.TCouponReceiveMapper;
import com.jilongda.manage.mapper.TStoreMapper;
import com.jilongda.manage.model.TCoupon;
import com.jilongda.manage.mapper.TCouponMapper;
import com.jilongda.manage.model.TCouponReceive;
import com.jilongda.manage.model.TOrder;
import com.jilongda.manage.model.TStore;
import com.jilongda.manage.query.TCouponQuery;
import com.jilongda.manage.service.TCouponService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.jilongda.manage.vo.TAppUserVO;
import com.jilongda.manage.vo.TCouponVO;
import org.apache.ibatis.annotations.ResultType;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;
import javax.annotation.Resource;
import java.util.Arrays;
import java.util.List;
/**
*
* 优惠券领取记录 服务实现类
*
*
* @author 无关风月
* @since 2024-12-09
*/
@Service
public class TCouponServiceImpl extends ServiceImpl implements TCouponService {
@Resource
private TStoreMapper storeMapper;
@Resource
private TCouponReceiveMapper couponReceiveMapper;
@Override
public PageInfo pageList(TCouponQuery query) {
PageInfo pageInfo = new PageInfo<>(query.getPageNum(), query.getPageSize());
List list = this.baseMapper.pageList(query,pageInfo);
StringBuilder stringBuilder = new StringBuilder();
for (TCouponVO tAppUserCouponVO : list) {
if (StringUtils.hasLength(tAppUserCouponVO.getStoreId())) {
List tStores = storeMapper.selectList(new LambdaQueryWrapper()
.in(TStore::getId, Arrays.asList(tAppUserCouponVO.getStoreId().split(","))));
for (TStore tStoreVO : tStores) {
stringBuilder.append(tStoreVO.getName()).append(",");
}
tAppUserCouponVO.setStoreName(stringBuilder.substring(0, stringBuilder.length() - 1));
} else {
tAppUserCouponVO.setStoreName("不限");
}
// 查询发放数量和使用数量
int size = couponReceiveMapper.selectList(new LambdaQueryWrapper()
.eq(TCouponReceive::getCouponId, tAppUserCouponVO.getId())).size();
tAppUserCouponVO.setGrantCout(size);
int size1 = couponReceiveMapper.selectList(new LambdaQueryWrapper()
.eq(TCouponReceive::getCouponId, tAppUserCouponVO.getId())
.eq(TCouponReceive::getStatus, 2)).size();
tAppUserCouponVO.setUseCount(size1);
}
pageInfo.setRecords(list);
return pageInfo;
}
}