无关风月
2024-12-25 042fbcd557ef21ab256a542f1fef039269684340
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
package com.jilongda.optometrist.service.impl;
 
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.jilongda.common.basic.PageInfo;
import com.jilongda.optometrist.mapper.TCouponReceiveMapper;
import com.jilongda.optometrist.mapper.TStoreMapper;
import com.jilongda.optometrist.model.TCoupon;
import com.jilongda.optometrist.mapper.TCouponMapper;
import com.jilongda.optometrist.model.TCouponReceive;
import com.jilongda.optometrist.model.TOrder;
import com.jilongda.optometrist.model.TStore;
import com.jilongda.optometrist.query.TCouponQuery;
import com.jilongda.optometrist.service.TCouponService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.jilongda.optometrist.vo.TAppUserVO;
import com.jilongda.optometrist.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;
 
/**
 * <p>
 * 优惠券领取记录 服务实现类
 * </p>
 *
 * @author 无关风月
 * @since 2024-12-09
 */
@Service
public class TCouponServiceImpl extends ServiceImpl<TCouponMapper, TCoupon> implements TCouponService {
 
    @Resource
    private TStoreMapper storeMapper;
    @Resource
    private TCouponReceiveMapper couponReceiveMapper;
    @Override
    public PageInfo<TCouponVO> pageList(TCouponQuery query) {
        PageInfo<TCouponVO> pageInfo = new PageInfo<>(query.getPageNum(), query.getPageSize());
        List<TCouponVO> list = this.baseMapper.pageList(query,pageInfo);
        StringBuilder stringBuilder = new StringBuilder();
        for (TCouponVO tAppUserCouponVO : list) {
            if (StringUtils.hasLength(tAppUserCouponVO.getStoreId())) {
                List<TStore> tStores = storeMapper.selectList(new LambdaQueryWrapper<TStore>()
                        .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<TCouponReceive>()
                    .eq(TCouponReceive::getCouponId, tAppUserCouponVO.getId())).size();
            tAppUserCouponVO.setGrantCout(size);
            int size1 = couponReceiveMapper.selectList(new LambdaQueryWrapper<TCouponReceive>()
                    .eq(TCouponReceive::getCouponId, tAppUserCouponVO.getId())
                    .eq(TCouponReceive::getStatus, 2)).size();
            tAppUserCouponVO.setUseCount(size1);
        }
 
        pageInfo.setRecords(list);
        return pageInfo;
 
    }
}