fix
Helius
2024-01-23 0e2a59c08cf8797fbbb1acc2669773bea7de1711
src/main/java/cc/mrbird/febs/vip/controller/ViewVipConfigController.java
@@ -2,6 +2,13 @@
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;
@@ -9,11 +16,19 @@
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() {
@@ -38,4 +53,75 @@
        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");
    }
}