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");
|
}
|
}
|