peng
2025-06-14 59e297cc9d51ef9c6df0dac71664bf1b492fc941
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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
package cn.lili.test.promotion;
 
import cn.lili.common.enums.PromotionTypeEnum;
import cn.lili.common.vo.PageVO;
import cn.lili.modules.goods.entity.enums.GoodsStatusEnum;
import cn.lili.modules.promotion.entity.dos.Coupon;
import cn.lili.modules.promotion.entity.dos.PromotionGoods;
import cn.lili.modules.promotion.entity.dto.search.CouponSearchParams;
import cn.lili.modules.promotion.entity.enums.CouponGetEnum;
import cn.lili.modules.promotion.entity.enums.CouponTypeEnum;
import cn.lili.modules.promotion.entity.enums.PromotionsScopeTypeEnum;
import cn.lili.modules.promotion.entity.vos.CouponVO;
import cn.lili.modules.promotion.service.CouponService;
import com.baomidou.mybatisplus.core.metadata.IPage;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit.jupiter.SpringExtension;
 
import java.util.ArrayList;
import java.util.List;
 
/**
 * @author paulG
 * @since 2020/10/29
 **/
@ExtendWith(SpringExtension.class)
@SpringBootTest
class CouponTest {
 
    @Autowired
    private CouponService couponService;
 
    @Test
    void addCoupon() {
        CouponVO couponVO = new CouponVO();
        couponVO.setCouponName("Coupon V" + couponVO.getId());
        couponVO.setCouponType(CouponTypeEnum.DISCOUNT.name());
        couponVO.setDescription(couponVO.getCouponName() + " are expensive");
        couponVO.setGetType(CouponGetEnum.FREE.name());
//       couponVO.setStoreId("0");
//       couponVO.setStoreName("platform");
        couponVO.setStoreId("131");
        couponVO.setStoreName("小米自营旗舰店");
        couponVO.setPublishNum(1000);
        couponVO.setCouponLimitNum(0);
        couponVO.setConsumeThreshold(500D);
//       couponVO.setPrice(200D);
        couponVO.setCouponDiscount(0.1D);
 
        couponVO.setScopeType(PromotionsScopeTypeEnum.PORTION_GOODS.name());
        couponVO.setScopeId("121");
        couponVO.setStartTime(cn.hutool.core.date.DateUtil.parse("2020-11-30 15:58:00"));
        couponVO.setEndTime(cn.hutool.core.date.DateUtil.parse("2020-12-30 23:50:00"));
 
        if (couponVO.getCouponType().equals(CouponTypeEnum.DISCOUNT.name())) {
            couponVO.setPromotionName(couponVO.getCouponDiscount() + "折券");
        } else {
            couponVO.setPromotionName(couponVO.getPrice() + "元券");
        }
        List<PromotionGoods> promotionGoodsList = new ArrayList<>();
//       GoodsSku sku121 = goodsSkuService.getGoodsSkuByIdFromCache("121");
        PromotionGoods promotionGoods = new PromotionGoods();
        promotionGoods.setPrice(0.0);
        promotionGoods.setLimitNum(0);
        promotionGoods.setNum(1000);
        promotionGoods.setStartTime(couponVO.getStartTime());
        promotionGoods.setEndTime(couponVO.getEndTime());
        promotionGoods.setTitle(couponVO.getPromotionName());
        promotionGoods.setPromotionId(couponVO.getId());
        promotionGoods.setQuantity(1000);
        promotionGoods.setPromotionType(PromotionTypeEnum.COUPON.name());
        promotionGoodsList.add(promotionGoods);
//
//       GoodsSku sku50112 = goodsSkuService.getGoodsSkuByIdFromCache("50112");
//       promotionGoods = new PromotionGoods(sku50112);
//       promotionGoods.setPrice(80000d);
//       promotionGoods.setLimitNum(0);
//       promotionGoods.setPromotionQuantity(1000);
//       promotionGoods.setNum(1000);
//       promotionGoods.setStartTime(couponVO.getStartTime());
//       promotionGoods.setEndTime(couponVO.getEndTime());
//       promotionGoods.setTitle(couponVO.getPromotionName());
//       promotionGoods.setPromotionStatus(couponVO.getPromotionStatus());
//       promotionGoodsList.add(promotionGoods);
//
        couponVO.setPromotionGoodsList(promotionGoodsList);
        Assertions.assertNotNull(couponService.savePromotions(couponVO));
    }
 
    @Test
    void update() {
        CouponVO couponVO = new CouponVO();
        couponVO.setId("1326081397400297472");
        couponVO.setCouponName("Coupon V" + couponVO.getId());
        couponVO.setCouponType(CouponTypeEnum.DISCOUNT.name());
        couponVO.setDescription(couponVO.getId() + " is expensive");
        couponVO.setGetType(CouponGetEnum.FREE.name());
        couponVO.setStoreId("132");
        couponVO.setStoreName("联想自营旗舰店");
        couponVO.setStoreCommission(99.99D);
        couponVO.setPublishNum(1000);
        couponVO.setCouponLimitNum(0);
        couponVO.setCouponDiscount(10D);
        couponVO.setPrice(0D);
 
        couponVO.setScopeType(PromotionsScopeTypeEnum.PORTION_GOODS.name());
        couponVO.setScopeId("134,133");
        couponVO.setStartTime(cn.hutool.core.date.DateUtil.parse("2020-11-10 17:01:00"));
        couponVO.setEndTime(cn.hutool.core.date.DateUtil.parse("2020-11-10 17:10:00"));
 
        if (couponVO.getCouponType().equals(CouponTypeEnum.DISCOUNT.name())) {
            couponVO.setPromotionName(couponVO.getCouponDiscount() + "折券");
        } else {
            couponVO.setPromotionName(couponVO.getPrice() + "元券");
        }
 
        List<PromotionGoods> promotionGoodsList = new ArrayList<>();
        PromotionGoods promotionGoods = new PromotionGoods();
        promotionGoods.setSkuId("134");
        promotionGoods.setGoodsName("联想(Lenovo)YOGA S740商务办公本 英特尔酷睿i5 14英寸超轻薄笔记本电脑(i5 16G 512G 独显 雷电3 WiFi6)灰");
        promotionGoods.setPrice(20000d);
        promotionGoods.setStoreId("132");
        promotionGoods.setStoreName("联想自营旗舰店");
        promotionGoods.setLimitNum(0);
        promotionGoods.setQuantity(1000);
        promotionGoods.setThumbnail("thumbnail");
        promotionGoods.setNum(1000);
        promotionGoods.setStartTime(couponVO.getStartTime());
        promotionGoods.setEndTime(couponVO.getEndTime());
        promotionGoods.setTitle(couponVO.getPromotionName());
        promotionGoodsList.add(promotionGoods);
 
        promotionGoods = new PromotionGoods();
        promotionGoods.setSkuId("133");
        promotionGoods.setGoodsName("联想(Lenovo)小新Pro13s“锦绣前程”故宫文创版13.3英寸轻薄笔记本电脑(I5 16G 512G 2.5K 100%sRGB)");
        promotionGoods.setPrice(100000d);
        promotionGoods.setStoreId("132");
        promotionGoods.setStoreName("联想自营旗舰店");
        promotionGoods.setLimitNum(0);
        promotionGoods.setQuantity(1000);
        promotionGoods.setThumbnail("thumbnail");
        promotionGoods.setNum(1000);
        promotionGoods.setStartTime(couponVO.getStartTime());
        promotionGoods.setEndTime(couponVO.getEndTime());
        promotionGoods.setTitle(couponVO.getPromotionName());
        promotionGoodsList.add(promotionGoods);
 
        couponVO.setPromotionGoodsList(promotionGoodsList);
        Assertions.assertTrue(couponService.updatePromotions(couponVO));
    }
 
    @Test
    void search() {
        CouponSearchParams queryParam = new CouponSearchParams();
        queryParam.setStoreId("");
        PageVO pageVo = new PageVO();
        pageVo.setPageNumber(0);
        pageVo.setPageSize(10);
        IPage<Coupon> couponsByPage = couponService.pageFindAll(queryParam, pageVo);
        Assertions.assertNotNull(couponsByPage);
        couponsByPage.getRecords().forEach(System.out::println);
    }
 
    @Test
    void delete() {
//       Assertions.assertTrue(couponService.deleteCoupon("1326001296591577088"));
        GoodsStatusEnum goodsStatusEnum = GoodsStatusEnum.DOWN;
        System.out.println("name::  " + goodsStatusEnum.name());
        System.out.println("description::  " + goodsStatusEnum.description());
        Assertions.assertTrue(true);
    }
 
 
}