luodangjia
2024-10-08 4c96637a005891c709662ae84edd072ad9a4a57d
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
package com.ruoyi.other.service.impl;
 
import com.ruoyi.account.api.feignClient.AppCouponClient;
import com.ruoyi.common.core.web.page.PageInfo;
import com.ruoyi.other.api.domain.TCoupon;
import com.ruoyi.other.api.domain.TGoods;
import com.ruoyi.other.mapper.TCouponMapper;
import com.ruoyi.other.query.CouponQuery;
import com.ruoyi.other.service.TCouponService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;
 
import java.util.List;
 
/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author 无关风月
 * @since 2024-08-06
 */
@Service
public class TCouponServiceImpl extends ServiceImpl<TCouponMapper, TCoupon> implements TCouponService {
 
    @Autowired
    private AppCouponClient appCouponClient;
    @Override
    public PageInfo<TCoupon> pageList(CouponQuery dto) {
        PageInfo<TCoupon> pageInfo = new PageInfo<>(dto.getPageCurr(),dto.getPageSize());
        List<TCoupon> list = this.baseMapper.pageList(pageInfo,dto);
        StringBuilder couponIds = new StringBuilder();
        for (TCoupon tCoupon : list) {
            couponIds.append(tCoupon.getId()).append(",");
            // 如果优惠券库存为0 那么将优惠券状态改为下架 不启用
            if (tCoupon.getInventoryQuantity()==0){
                tCoupon.setStatus(2);
                this.baseMapper.updateById(tCoupon);
 
            }
 
        }
        if (!list.isEmpty()){
            if (StringUtils.hasLength(couponIds)){
                // 去除最后一个字符
                couponIds.deleteCharAt(couponIds.length()-1);
            }
            List<Integer> data = appCouponClient.getCountByCouponIds(couponIds.toString()).getData();
            for (int i = 0; i < list.size(); i++) {
                list.get(i).setCount(data.get(i));
            }
        }
        pageInfo.setRecords(list);
        return pageInfo;
    }
}