fix
Hentua
2024-01-23 b67cb476a3de3eb720bc4c295e8fcd9c29825df7
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
package cc.mrbird.febs.vip.controller;
 
import cc.mrbird.febs.common.entity.FebsConstant;
import cc.mrbird.febs.common.utils.FebsUtil;
import cc.mrbird.febs.mall.entity.MallGoods;
import cc.mrbird.febs.mall.entity.MallGoodsCoupon;
import cc.mrbird.febs.mall.mapper.MallGoodsCouponMapper;
import cc.mrbird.febs.mall.service.IApiMallGoodsService;
import cc.mrbird.febs.vip.entity.MallVipBenefits;
import cc.mrbird.febs.vip.service.IMallVipBenefitsService;
import cn.hutool.core.collection.CollUtil;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
 
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
 
@Controller("mallVipConfig")
@RequestMapping(FebsConstant.VIEW_PREFIX + "modules/vip/config")
@RequiredArgsConstructor
public class ViewVipConfigController {
 
    private final IMallVipBenefitsService mallVipBenefitsService;
    private final IApiMallGoodsService apiMallGoodsService;
    private final MallGoodsCouponMapper mallGoodsCouponMapper;
 
    @GetMapping(value = "/benefitsList")
    public String benefitsList() {
        return FebsUtil.view("modules/vip/vipBenefits-list");
    }
 
    @GetMapping(value = "/vipBenefitsAdd")
    public String vipBenefitsAdd() {
        return FebsUtil.view("modules/vip/vipBenefits-add");
    }
 
 
    @GetMapping(value = "/goodsSelect/{index}")
    public String goodsSelect(@PathVariable("index") String index, Model model) {
        model.addAttribute("tableIndex", index);
        return FebsUtil.view("modules/vip/goods-select-list");
    }
 
 
    @GetMapping(value = "/couponSelect/{index}")
    public String couponSelect(@PathVariable("index") String index, Model model) {
        model.addAttribute("tableIndex", index);
        return FebsUtil.view("modules/vip/coupon-select");
    }
 
    @GetMapping("/editBenefits/{id}")
    public String editBenefits(@PathVariable("id") Long id, Model model) {
        MallVipBenefits vipBenefits = mallVipBenefitsService.findVipBenefitsById(id);
 
        List<Long> goodsIds = new ArrayList<>();
        List<Long> couponIds = new ArrayList<>();
        vipBenefits.getDetails().forEach(item -> {
            if (item.getIsClick() == 2) {
                return;
            }
 
            if (item.getLinkType() == 2) {
                goodsIds.add(Long.parseLong(item.getContent()));
            }
 
            if (item.getLinkType() == 3) {
                couponIds.add(Long.parseLong(item.getContent()));
            }
        });
 
        List<MallGoods> goodsList = new ArrayList<>();
        if (CollUtil.isNotEmpty(goodsIds)) {
            goodsList = apiMallGoodsService.listByIds(goodsIds);
        }
 
        List<MallGoodsCoupon> coupons = new ArrayList<>();
        if (CollUtil.isNotEmpty(couponIds)) {
            coupons = mallGoodsCouponMapper.selectBatchIds(couponIds);
        }
 
        Map<Long, MallGoods> goodsMap = goodsList.stream().collect(Collectors.toMap(MallGoods::getId, MallGoods -> MallGoods));
        Map<Long, MallGoodsCoupon> couponMap = coupons.stream().collect(Collectors.toMap(MallGoodsCoupon::getId, MallGoodsCoupon -> MallGoodsCoupon));
 
        vipBenefits.getDetails().forEach(item -> {
            if (item.getIsClick() == 2) {
                return;
            }
 
            if (item.getLinkType() == 2) {
                MallGoods mallGoods = goodsMap.get(Long.parseLong(item.getContent()));
                if (mallGoods != null) {
                    item.setContentName(mallGoods.getGoodsName());
                }
            }
 
            if (item.getLinkType() == 3) {
                MallGoodsCoupon coupon = couponMap.get(Long.parseLong(item.getContent()));
                if (coupon != null) {
                    item.setContentName(coupon.getName());
                }
            }
        });
        model.addAttribute("benefitsData", vipBenefits);
        return FebsUtil.view("modules/vip/vipBenefits-edit");
    }
 
    @GetMapping(value = "/levelList")
    public String levelList() {
        return FebsUtil.view("modules/vip/vipConfig-list");
    }
 
    @GetMapping(value = "/levelAdd")
    public String levelAdd() {
        return FebsUtil.view("modules/vip/vipConfig-add");
    }
 
    @GetMapping(value = "/levelEdit")
    public String levelEdit() {
        return FebsUtil.view("modules/vip/vipLevel-list");
    }
}