无关风月
14 小时以前 4c9035836c18886883d3f69d8443c53d15b068fc
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
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
package com.dsh.guns.modular.system.controller.code;
 
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.dsh.course.feignClient.activity.CouponClient;
import com.dsh.course.feignClient.activity.model.Coupon;
import com.dsh.course.feignClient.activity.model.CouponCity;
import com.dsh.course.feignClient.activity.model.TicketDetailVO;
import com.dsh.guns.core.base.controller.BaseController;
import com.dsh.guns.core.common.constant.factory.PageFactory;
import com.dsh.guns.modular.system.model.*;
import com.dsh.guns.modular.system.service.IProtocolService;
import com.dsh.guns.modular.system.service.IStoreService;
import com.dsh.guns.modular.system.service.IVipService;
import com.dsh.guns.modular.system.util.ResultUtil;
import org.apache.poi.ss.formula.functions.T;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;
 
import java.math.BigDecimal;
import java.text.SimpleDateFormat;
import java.util.*;
import java.util.stream.Collectors;
 
/**
 * @author zhibing.pu
 * @Date 2023/8/1 14:02
 */
@Controller
@RequestMapping("/vip")
public class TVipController extends BaseController {
 
    @Autowired
    private IVipService vipService;
    @Autowired
    private CouponClient couponClient;
    @Autowired
    private IStoreService storeService;
    private String PREFIX = "/system/vip/";
 
 
    /**
     * 跳转到优惠券管理首页
     */
    @RequestMapping("")
    public String index(Model model) {
 
        return PREFIX + "vip.html";
    }
    @RequestMapping("/add")
    public String add(Model model) {
 
        return PREFIX + "vip_add.html";
    }
    @RequestMapping("/edit/{id}")
    public String edit(@PathVariable("id")Integer id,Model model) {
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
 
        Vip vip = vipService.getById(id);
        model.addAttribute("vip",vip);
        if (vip.getCouponJson() != null && !vip.getCouponJson().isEmpty()){
            String couponJson = vip.getCouponJson();
            // 转化为jsonArray
            JSONArray couponJsonArray = JSONArray.parseArray(couponJson);
            List<Integer> couponIds = new ArrayList<>();
            Map<Integer, Integer> integerIntegerHashMap = new HashMap<>();
            // 收集里面得id
            for (Object o : couponJsonArray) {
                JSONObject couponJsonObject = (JSONObject) o;
                Integer couponId = couponJsonObject.getInteger("id");
                Integer count = couponJsonObject.getInteger("value");
                integerIntegerHashMap.put(couponId, count);
                couponIds.add(couponId);
            }
            List<Coupon> coupons = couponClient.queryCouponList();
 
            if (!couponIds.isEmpty()){
                coupons = coupons.stream().filter(coupon -> couponIds.contains(coupon.getId())).collect(Collectors.toList());
                for (Coupon coupon : coupons) {
                    Date startTime = coupon.getStartTime();
                    Date endTime = coupon.getEndTime();
                    coupon.setTimeValue(simpleDateFormat.format(startTime) + "至" + simpleDateFormat.format(endTime));
                    Integer orDefault = integerIntegerHashMap.getOrDefault(coupon.getId(), 0);
                    coupon.setCount(orDefault);
                    switch (coupon.getUseScope()){
                        case 1:
                            coupon.setUseScopeValue("全国");
                            break;
                        case 2:
                            coupon.setUseScopeValue("指定城市");
                            break;
                        case 3:
                            coupon.setUseScopeValue("指定门店");
                            break;
                    }
                    switch (coupon.getType()){
                        case 1:
                            coupon.setTypeValue("满减券");
                            break;
                        case 2:
                            coupon.setTypeValue("代金券");
                            break;
                        case 3:
                            coupon.setTypeValue("体验券");
                            break;
                    }
                    switch (coupon.getUserPopulation()){
                        case 1:
                            coupon.setUserPopulationValue("全部用户");
                            break;
                        case 2:
                            coupon.setUserPopulationValue("会员");
                            break;
                        case 3:
                            coupon.setUserPopulationValue("已有学员用户");
                            break;
                    }
                }
                model.addAttribute("couponList", coupons);
            }else{
                model.addAttribute("couponList", new ArrayList<Coupon>());
            }
        }
        if (vip.getTicketJson() != null && !vip.getTicketJson().isEmpty()){
            String ticketJson = vip.getTicketJson();
            // 转化为jsonArray
            JSONArray ticketJsonArray = JSONArray.parseArray(ticketJson);
            // 收集里面得id
            List<TicketDetailVO> ticketDetailVOS = new ArrayList<>();
 
            for (Object o : ticketJsonArray) {
                JSONObject couponJsonObject = (JSONObject) o;
                TicketDetailVO ticketDetailVO = new TicketDetailVO();
                ticketDetailVO.setName(couponJsonObject.getString("name"));
                ticketDetailVO.setTime(couponJsonObject.getInteger("time"));
                ticketDetailVO.setCount(couponJsonObject.getInteger("count"));
                ticketDetailVOS.add(ticketDetailVO);
            }
            model.addAttribute("ticketList", ticketDetailVOS);
        }
        return PREFIX + "vip_edit.html";
    }
 
    public static void main(String[] args) {
        String temp = "[{\"id\":\"36\",\"value\":\"1\"}]";
        JSONArray couponJsonArray = JSONArray.parseArray(temp);
        for (Object o : couponJsonArray) {
            JSONObject couponJsonObject = (JSONObject) o;
            Integer couponId = couponJsonObject.getInteger("id");
        }
    }
    @RequestMapping("/detail/{id}")
    public String detail(@PathVariable("id")Integer id, Model model) {
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
 
        Vip vip = vipService.getById(id);
        model.addAttribute("vip",vip);
        if (vip.getCouponJson() != null && !vip.getCouponJson().isEmpty()){
            String couponJson = vip.getCouponJson();
            // 转化为jsonArray
            JSONArray couponJsonArray = JSONArray.parseArray(couponJson);
            List<Integer> couponIds = new ArrayList<>();
            Map<Integer, Integer> integerIntegerHashMap = new HashMap<>();
            // 收集里面得id
            for (Object o : couponJsonArray) {
                JSONObject couponJsonObject = (JSONObject) o;
                Integer couponId = couponJsonObject.getInteger("id");
                Integer count = couponJsonObject.getInteger("value");
                integerIntegerHashMap.put(couponId, count);
                couponIds.add(couponId);
            }
            List<Coupon> coupons = couponClient.queryCouponList();
 
            if (!couponIds.isEmpty()){
                coupons = coupons.stream().filter(coupon -> couponIds.contains(coupon.getId())).collect(Collectors.toList());
                for (Coupon coupon : coupons) {
                    Date startTime = coupon.getStartTime();
                    Date endTime = coupon.getEndTime();
                    coupon.setTimeValue(simpleDateFormat.format(startTime) + "至" + simpleDateFormat.format(endTime));
                    Integer orDefault = integerIntegerHashMap.getOrDefault(coupon.getId(), 0);
                    coupon.setCount(orDefault);
                    switch (coupon.getUseScope()){
                        case 1:
                            coupon.setUseScopeValue("全国");
                            break;
                        case 2:
                            coupon.setUseScopeValue("指定城市");
                            break;
                        case 3:
                            coupon.setUseScopeValue("指定门店");
                            break;
                    }
                    switch (coupon.getType()){
                        case 1:
                            coupon.setTypeValue("满减券");
                            break;
                        case 2:
                            coupon.setTypeValue("代金券");
                            break;
                        case 3:
                            coupon.setTypeValue("体验券");
                            break;
                    }
                    switch (coupon.getUserPopulation()){
                        case 1:
                            coupon.setUserPopulationValue("全部用户");
                            break;
                        case 2:
                            coupon.setUserPopulationValue("会员");
                            break;
                        case 3:
                            coupon.setUserPopulationValue("已有学员用户");
                            break;
                    }
                }
                model.addAttribute("couponList", coupons);
            }else{
                model.addAttribute("couponList", new ArrayList<Coupon>());
            }
        }
        if (vip.getTicketJson() != null && !vip.getTicketJson().isEmpty()){
            String ticketJson = vip.getTicketJson();
            // 转化为jsonArray
            JSONArray ticketJsonArray = JSONArray.parseArray(ticketJson);
            // 收集里面得id
            List<TicketDetailVO> ticketDetailVOS = new ArrayList<>();
 
            for (Object o : ticketJsonArray) {
                JSONObject couponJsonObject = (JSONObject) o;
                TicketDetailVO ticketDetailVO = new TicketDetailVO();
                ticketDetailVO.setName(couponJsonObject.getString("name"));
                ticketDetailVO.setTime(couponJsonObject.getInteger("time"));
                ticketDetailVO.setCount(couponJsonObject.getInteger("count"));
                ticketDetailVOS.add(ticketDetailVO);
            }
            model.addAttribute("ticketList", ticketDetailVOS);
        }
 
        return PREFIX + "vip_detail.html";
    }
    /**
     * 跳转到门店管理列表页
     */
    @RequestMapping("/couponList")
    public String couponList(Model model) {
        return PREFIX + "TCoupon.html";
    }
    @RequestMapping(value = "/addVipInfo")
    @ResponseBody
    public ResultUtil addVipInfo(String vipName, Integer time, Integer timeType, String price,String couponJson, String ticketJson) {
        Vip vip = new Vip();
        vip.setVipName(vipName);
        vip.setTimeType(timeType);
        vip.setTime(time);
        vip.setPrice(new BigDecimal(price));
        vip.setStatus(1);
        vip.setInsertTime(new Date());
        vip.setCouponJson(couponJson);
        vip.setTicketJson(ticketJson);
        vipService.save(vip);
        return ResultUtil.success();
    }
    @RequestMapping(value = "/editVipInfo")
    @ResponseBody
    public ResultUtil addVipInfo(Integer id,String vipName, Integer time, Integer timeType, String price,String couponJson, String ticketJson) {
        Vip vip = vipService.getById(id);
        vip.setVipName(vipName);
        vip.setTimeType(timeType);
        vip.setTime(time);
        vip.setPrice(new BigDecimal(price));
        vip.setInsertTime(new Date());
        if (couponJson==null){
            couponJson = "";
        }
        vip.setCouponJson(couponJson);
        if (ticketJson==null){
            ticketJson = "";
        }
        vip.setTicketJson(ticketJson);
        vipService.updateById(vip);
        return ResultUtil.success();
    }
    @RequestMapping(value = "/offShelf")
    @ResponseBody
    public ResultUtil offShelf(Integer id) {
        Vip vip = vipService.getById(id);
        vip.setStatus(2);
        vipService.updateById(vip);
        return ResultUtil.success();
    }
    @RequestMapping(value = "/onShelf")
    @ResponseBody
    public ResultUtil onShelf(Integer id) {
        Vip vip = vipService.getById(id);
        vip.setStatus(1);
        vipService.updateById(vip);
        return ResultUtil.success();
    }
    /**
     * 获取 会员卡列表
     */
    @RequestMapping(value = "/list")
    @ResponseBody
    public List<Map<String, Object>> list(String vipName, Integer status) {
        Page<Map<String, Object>> page = new PageFactory<Map<String, Object>>().defaultPage();
        List<Map<String, Object>> maps = vipService.listOfPage(vipName, status, page);
        for (Map<String, Object> map : maps) {
            Object timeType = map.get("timeType");
            Object time = map.get("time");
            Integer timeTypeValue = Integer.valueOf(timeType.toString());
            Integer timeValue = Integer.valueOf(time.toString());
            switch (timeTypeValue) {
                case 1:
                    map.put("time",timeValue+"天");
                    break;
                case 2:
                    map.put("time",timeValue+"月");
                    break;
                case 3:
                    map.put("time",timeValue+"年");
                    break;
            }
        }
        return maps;
    }
 
    // APP查询所有上架的会员卡
 
    @Autowired
    private IProtocolService protocolService;
    @ResponseBody
    @PostMapping("/getAgreement")
    public String getAgreement() {
        Protocol one = protocolService.lambdaQuery().eq(Protocol::getType, 6).one();
        if (one==null){
            Protocol protocol = new Protocol();
            protocol.setType(6);
            protocol.setContent("");
            protocol.setInsertTime(new Date());
            protocolService.save( protocol);
            return  "";
        }else{
            return one.getContent();
 
        }
    }
 
    @ResponseBody
    @PostMapping("/getVipByIds")
    public List<Vip> getVipByIds(@RequestBody String ids) {
        List<Vip> list = vipService.lambdaQuery().in(Vip::getId, Arrays.asList(ids.split(","))).list();
        return list;
    }
}