|  |  |  | 
|---|
|  |  |  | package cc.mrbird.febs.vip.controller; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | import cc.mrbird.febs.common.entity.FebsConstant; | 
|---|
|  |  |  | import cc.mrbird.febs.common.enumerates.DataDictionaryEnum; | 
|---|
|  |  |  | import cc.mrbird.febs.common.utils.FebsUtil; | 
|---|
|  |  |  | import cc.mrbird.febs.mall.entity.DataDictionaryCustom; | 
|---|
|  |  |  | import cc.mrbird.febs.mall.entity.MallGoods; | 
|---|
|  |  |  | import cc.mrbird.febs.mall.entity.MallGoodsCoupon; | 
|---|
|  |  |  | import cc.mrbird.febs.mall.mapper.DataDictionaryCustomMapper; | 
|---|
|  |  |  | import cc.mrbird.febs.mall.mapper.MallGoodsCouponMapper; | 
|---|
|  |  |  | import cc.mrbird.febs.mall.service.IApiMallGoodsService; | 
|---|
|  |  |  | import cc.mrbird.febs.vip.VipSettingUnAliveSettingBo; | 
|---|
|  |  |  | import cc.mrbird.febs.vip.entity.MallVipBenefits; | 
|---|
|  |  |  | import cc.mrbird.febs.vip.entity.MallVipConfig; | 
|---|
|  |  |  | import cc.mrbird.febs.vip.entity.MallVipConfigBenefits; | 
|---|
|  |  |  | import cc.mrbird.febs.vip.service.IMallVipBenefitsService; | 
|---|
|  |  |  | import cc.mrbird.febs.vip.service.IMallVipConfigBenefitsService; | 
|---|
|  |  |  | import cc.mrbird.febs.vip.service.IMallVipConfigService; | 
|---|
|  |  |  | import cc.mrbird.febs.vip.vo.VipSettingVo; | 
|---|
|  |  |  | import cn.hutool.core.collection.CollUtil; | 
|---|
|  |  |  | import cn.hutool.core.util.StrUtil; | 
|---|
|  |  |  | import com.alibaba.fastjson.JSONObject; | 
|---|
|  |  |  | import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; | 
|---|
|  |  |  | import lombok.RequiredArgsConstructor; | 
|---|
|  |  |  | import org.springframework.stereotype.Controller; | 
|---|
|  |  |  | import org.springframework.ui.Model; | 
|---|
|  |  |  | 
|---|
|  |  |  | 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; | 
|---|
|  |  |  | private final IMallVipConfigService mallVipConfigService; | 
|---|
|  |  |  | private final IMallVipConfigBenefitsService mallVipConfigBenefitsService; | 
|---|
|  |  |  | private final DataDictionaryCustomMapper dataDictionaryCustomMapper; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @GetMapping(value = "/benefitsList") | 
|---|
|  |  |  | public String benefitsList() { | 
|---|
|  |  |  | 
|---|
|  |  |  | 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 (StrUtil.isBlank(item.getContent())) { | 
|---|
|  |  |  | return; | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | 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 (StrUtil.isBlank(item.getContent())) { | 
|---|
|  |  |  | return; | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | 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/{id}") | 
|---|
|  |  |  | public String levelEdit(@PathVariable("id") Long id, Model model) { | 
|---|
|  |  |  | MallVipConfig vipConfig = mallVipConfigService.getById(id); | 
|---|
|  |  |  | if (vipConfig.getType() == 1) { | 
|---|
|  |  |  | MallGoods goods = apiMallGoodsService.getById(vipConfig.getTargetId()); | 
|---|
|  |  |  | vipConfig.setTargetId(goods.getId()); | 
|---|
|  |  |  | vipConfig.setTargetName(goods.getGoodsName()); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | LambdaQueryWrapper<MallVipConfigBenefits> configBenefitsQuery = new LambdaQueryWrapper<>(); | 
|---|
|  |  |  | configBenefitsQuery.eq(MallVipConfigBenefits::getConfigId, vipConfig.getId()); | 
|---|
|  |  |  | List<MallVipConfigBenefits> list = mallVipConfigBenefitsService.list(configBenefitsQuery); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | List<Long> benefitsIds = list.stream().map(MallVipConfigBenefits::getBenefitsId).collect(Collectors.toList()); | 
|---|
|  |  |  | vipConfig.setBenefitsIdList(benefitsIds); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | model.addAttribute("configData", vipConfig); | 
|---|
|  |  |  | return FebsUtil.view("modules/vip/vipConfig-edit"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @GetMapping(value = "/vipSetting") | 
|---|
|  |  |  | public String vipSetting(Model model) { | 
|---|
|  |  |  | DataDictionaryCustom data = dataDictionaryCustomMapper.selectDicDataByTypeAndCode(DataDictionaryEnum.VIP_DATE.getType(), DataDictionaryEnum.VIP_DATE.getCode()); | 
|---|
|  |  |  | VipSettingVo setting = new VipSettingVo(); | 
|---|
|  |  |  | setting.setVipDate(data.getValue()); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | DataDictionaryCustom couponData = dataDictionaryCustomMapper.selectDicDataByTypeAndCode(DataDictionaryEnum.UNALIVE_COUPON.getType(), DataDictionaryEnum.UNALIVE_COUPON.getCode()); | 
|---|
|  |  |  | if (couponData != null && StrUtil.isNotBlank(couponData.getValue())) { | 
|---|
|  |  |  | List<VipSettingUnAliveSettingBo> items = JSONObject.parseArray(couponData.getValue(), VipSettingUnAliveSettingBo.class); | 
|---|
|  |  |  | setting.setItems(items); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | DataDictionaryCustom rule = dataDictionaryCustomMapper.selectDicDataByTypeAndCode(DataDictionaryEnum.VIP_SCORE_RULE.getType(), DataDictionaryEnum.VIP_SCORE_RULE.getCode()); | 
|---|
|  |  |  | setting.setRule(rule.getValue()); | 
|---|
|  |  |  | model.addAttribute("vipSetting", setting); | 
|---|
|  |  |  | return FebsUtil.view("modules/vip/vip-setting"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|