From 03f1f3372a10a08f96f3308bfa099e86a55046d0 Mon Sep 17 00:00:00 2001 From: puzhibing <393733352@qq.com> Date: 星期二, 30 一月 2024 09:32:38 +0800 Subject: [PATCH] 修改数据权限bug --- ruoyi-modules/ruoyi-member/src/main/java/com/ruoyi/member/service/impl/coupon/CouponServiceImpl.java | 192 ++++++++++++++++++++++++++++++++++++++++++------ 1 files changed, 168 insertions(+), 24 deletions(-) diff --git a/ruoyi-modules/ruoyi-member/src/main/java/com/ruoyi/member/service/impl/coupon/CouponServiceImpl.java b/ruoyi-modules/ruoyi-member/src/main/java/com/ruoyi/member/service/impl/coupon/CouponServiceImpl.java index d6d524e..8062e06 100644 --- a/ruoyi-modules/ruoyi-member/src/main/java/com/ruoyi/member/service/impl/coupon/CouponServiceImpl.java +++ b/ruoyi-modules/ruoyi-member/src/main/java/com/ruoyi/member/service/impl/coupon/CouponServiceImpl.java @@ -1,6 +1,7 @@ package com.ruoyi.member.service.impl.coupon; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; +import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import com.ruoyi.common.core.exception.ServiceException; @@ -19,6 +20,7 @@ import com.ruoyi.system.api.constant.AppErrorConstant; import com.ruoyi.system.api.constant.DelayTaskEnum; import com.ruoyi.system.api.domain.dto.*; +import com.ruoyi.system.api.domain.poji.activity.Activity; import com.ruoyi.system.api.domain.poji.config.DelayTask; import com.ruoyi.system.api.domain.poji.goods.Goods; import com.ruoyi.system.api.domain.poji.member.Member; @@ -31,6 +33,7 @@ import com.ruoyi.system.api.service.RemoteShopService; import org.springframework.scheduling.annotation.Async; import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; import javax.annotation.Resource; import java.math.BigDecimal; @@ -201,6 +204,14 @@ List<MgtCouponMemberListVo> relUserList = couponRelUserService.listCouponMemberVo(coupon.getCouponId()); mgtCouponGetVo.setRelUserList(relUserList); } + //获取活动名称 + if(coupon.getSendTarget()==5&&coupon.getRelationType()==2){ + Activity activity = remoteActivityService.getActivity(coupon.getRelationActivityId()).getData(); + mgtCouponGetVo.setRelationActivityName(activity.getActivityName()); + } + if(mgtCouponGetVo.getSendLimitFlag()==0){ + mgtCouponGetVo.setSendLimitNumber(null); + } return mgtCouponGetVo; } @@ -236,6 +247,9 @@ List<MgtCouponMemberListVo> relUserList = couponRelUserService.listCouponMemberVo(coupon.getCouponId()); merCouponGetVo.setRelUserList(relUserList); } + if(merCouponGetVo.getSendLimitFlag()==0){ + merCouponGetVo.setSendLimitNumber(null); + } return merCouponGetVo; } @@ -253,12 +267,103 @@ CouponTotal couponTotal; if(StringUtils.isNotBlank(mgtCouponEditDto.getCouponId())){ coupon = this.getById(mgtCouponEditDto.getCouponId()); - couponTotal = couponTotalService.getById(mgtCouponEditDto.getCouponId()); - if(couponTotal.getSendCount()!=null&&couponTotal.getSendCount()>0){ - throw new ServiceException(AppErrorConstant.COUPON_SENT_EDIT); +// couponTotal = couponTotalService.getById(mgtCouponEditDto.getCouponId()); +// if(couponTotal.getSendCount()!=null&&couponTotal.getSendCount()>0){ +// throw new ServiceException(AppErrorConstant.COUPON_SENT_EDIT); +// } + /** + * 一:不可修改 + * 1、优惠券类型 + * 2、发放方式 + * 3、优惠券金额 + * 4、使用期限类型 + * 5、有效时间段:开始时间不能修改,结束时间可以修改 + * 二:部分可修改 + * 1、发放方式为指定发放时 + * 定时发放:已到发放时间不可修改 + * 立即发放:不可修改 + * 2、适用范围 + * 全部商品:不可修改 + * 部分商品:只能增加商品 + * 3、发放数量:只能增加 + * 不限制:不可修改 + * 4、用户可领数量:只能增加 + * 三:可修改 + * 1、优惠券名称 + * 2、宣传海报 + * 四:发放对象 + * 1、未到发放时间都可以修改 + * 2、已到发放时间,只有自定义时可修改,且只能增加用户 + */ + if(!coupon.getCouponType().equals(mgtCouponEditDto.getCouponType())){ + throw new ServiceException("不能修改优惠券类型"); } + if(!coupon.getSendType().equals(mgtCouponEditDto.getSendType())){ + throw new ServiceException("不能修改优惠券发放方式"); + } + if(null != mgtCouponEditDto.getMoneyThreshold() && coupon.getMoneyThreshold().compareTo(mgtCouponEditDto.getMoneyThreshold()) != 0){ + throw new ServiceException("不能修改优惠券金额"); + } + if(null != mgtCouponEditDto.getDiscountMoney() && coupon.getDiscountMoney().compareTo(mgtCouponEditDto.getDiscountMoney()) != 0){ + throw new ServiceException("不能修改优惠券金额"); + } + if(null != mgtCouponEditDto.getDiscountPercent() && coupon.getDiscountPercent().compareTo(mgtCouponEditDto.getDiscountPercent()) != 0){ + throw new ServiceException("不能修改优惠券折扣"); + } + if(coupon.getSendType() == 2 && coupon.getSendTimeType() == 2 && mgtCouponEditDto.getSendTimeType() == 2 && System.currentTimeMillis() >= coupon.getSendTime().getTime() && null != mgtCouponEditDto.getValidTimeType() && !coupon.getValidTimeType().equals(mgtCouponEditDto.getValidTimeType())){ + throw new ServiceException("不能修改优惠券适用期限类型"); + } + if(coupon.getSendType() == 2 && coupon.getSendTimeType() == 2 && mgtCouponEditDto.getSendTimeType() == 2 && System.currentTimeMillis() >= coupon.getSendTime().getTime() && null != mgtCouponEditDto.getValidTimeType() && coupon.getValidTimeType() == 1 && !coupon.getValidStartTime().equals(mgtCouponEditDto.getValidStartTime())){ + throw new ServiceException("不能修改优惠券有效期开始时间"); + } + if(coupon.getSendType() == 2 && coupon.getSendTimeType() == 1 && mgtCouponEditDto.getSendTimeType() != 1){ + throw new ServiceException("不能修改优惠券发放方式"); + } + if(coupon.getSendType() == 2 && coupon.getSendTimeType() == 2 && mgtCouponEditDto.getSendTimeType() != 2 && System.currentTimeMillis() <= coupon.getSendTime().getTime()){ + throw new ServiceException("不能修改优惠券发放方式"); + } + if(coupon.getSendType() == 2 && coupon.getSendTimeType() == 2 && mgtCouponEditDto.getSendTimeType() == 2 && System.currentTimeMillis() >= coupon.getSendTime().getTime()){ + throw new ServiceException("不能修改优惠券发放时间"); + } + if(coupon.getSendType() == 2 && coupon.getSendTimeType() == 2 && mgtCouponEditDto.getSendTimeType() == 2 && System.currentTimeMillis() >= coupon.getSendTime().getTime() && coupon.getUseScope() == 1 && !coupon.getUseScope().equals(mgtCouponEditDto.getUseScope())){ + throw new ServiceException("不能修改优惠券适用范围"); + } + + if(coupon.getUseScope() == 2 && coupon.getUseScope().equals(mgtCouponEditDto.getUseScope())){ + List<String> relGoodsIdList = mgtCouponEditDto.getRelGoodsIdList(); + List<CouponRelGoods> list = couponRelGoodsService.list(new QueryWrapper<CouponRelGoods>().eq("coupon_id", coupon.getCouponId()).eq("del_flag", 0)); + for (CouponRelGoods couponRelGoods : list) { + if(!relGoodsIdList.contains(couponRelGoods.getGoodsId())){ + throw new ServiceException("不能删除优惠券适用商品"); + } + } + } + if(coupon.getSendLimitFlag() == 0 && mgtCouponEditDto.getSendLimitFlag() != 0){ + throw new ServiceException("不能修改优惠券发放数量限制"); + } + if(coupon.getSendLimitFlag() == 1 && mgtCouponEditDto.getSendLimitFlag() == 1 && coupon.getSendLimitNumber().compareTo(mgtCouponEditDto.getSendLimitNumber()) > 0){ + throw new ServiceException("不能修改优惠券发放数量限制"); + } + if(coupon.getLimitNumber().compareTo(mgtCouponEditDto.getLimitNumber()) > 0){ + throw new ServiceException("只能增加优惠券领取数量"); + } + List<CouponRelUser> list = couponRelUserService.list(new QueryWrapper<CouponRelUser>().eq("coupon_id", coupon.getCouponId()).eq("del_flag", 0)); + List<Long> relUserIdList = mgtCouponEditDto.getRelUserIdList(); + for (CouponRelUser couponRelUser : list) { + if(!relUserIdList.contains(couponRelUser.getUserId())){ + throw new ServiceException("只能增加优惠发放对象"); + } + } + if(relUserIdList.size() != list.size() && coupon.getSendType() == 2 && coupon.getSendTimeType() == 1){ + throw new ServiceException("只能修改优惠发放对象"); + } + if(relUserIdList.size() != list.size() && coupon.getSendType() == 2 && coupon.getSendTimeType() == 2 && System.currentTimeMillis() <= coupon.getSendTime().getTime()){ + throw new ServiceException("只能修改优惠发放对象"); + } + couponRelUserService.deleteCouponRelByCouponId(coupon.getCouponId()); couponRelGoodsService.deleteCouponRelByCouponId(coupon.getCouponId()); + }else{ coupon = new Coupon(); String couponId = IdUtils.simpleUUID(); @@ -299,8 +404,17 @@ coupon.setRelationActivityType(mgtCouponEditDto.getRelationActivityType()); coupon.setRelationActivityId(mgtCouponEditDto.getRelationActivityId()); coupon.setPropagandaPoster(mgtCouponEditDto.getPropagandaPoster()); - coupon.setSendLimitNumber(mgtCouponEditDto.getSendLimitNumber()); + //指定发放优惠券不做发放数限制 + if(coupon.getSendType()==2){ + mgtCouponEditDto.setSendLimitFlag(0); + } coupon.setSendLimitFlag(mgtCouponEditDto.getSendLimitFlag()); + if(mgtCouponEditDto.getSendLimitFlag()==1){ + coupon.setSendLimitNumber(mgtCouponEditDto.getSendLimitNumber()); + }else{ + coupon.setSendLimitNumber(0); + } + coupon.setLimitNumber(mgtCouponEditDto.getLimitNumber()); //判断是否指定商品 if(coupon.getUseScope()==2&&!mgtCouponEditDto.getRelGoodsIdList().isEmpty()){ List<String> relGoodsIdList = mgtCouponEditDto.getRelGoodsIdList(); @@ -336,7 +450,7 @@ coupon.setRelUserIds(userIdSj.toString()); } //处理优惠券发放 - if(coupon.getSendType()==2&&coupon.getSendTimeType()==1){ + if(coupon.getSendFlag() == 0 && coupon.getSendType()==2&&coupon.getSendTimeType()==1){ sendCoupon(coupon,relUserIdList); coupon.setSendFlag(1); this.saveOrUpdate(coupon); @@ -746,7 +860,10 @@ .collect(Collectors.toMap(MgtSimpleShopVo::getShopId, Function.identity())); for(MgtCouponAuditPageVo mgtCouponAuditPageVo : mgtCouponAuditPageVoList){ if(mgtCouponAuditPageVo.getShopId()!=null){ - mgtCouponAuditPageVo.setShopName(shopMap.get(mgtCouponAuditPageVo.getShopId()).getShopName()); + MgtSimpleShopVo mgtSimpleShopVo = shopMap.get(mgtCouponAuditPageVo.getShopId()); + if(null != mgtSimpleShopVo){ + mgtCouponAuditPageVo.setShopName(mgtSimpleShopVo.getShopName()); + } } } } @@ -1027,8 +1144,16 @@ coupon.setUpdateUserId(merCouponEditDto.getUserId()); coupon.setRelationType(1); coupon.setPropagandaPoster(merCouponEditDto.getPropagandaPoster()); - coupon.setSendLimitNumber(merCouponEditDto.getSendLimitNumber()); + //指定发放优惠券不做发放数限制 + if(coupon.getSendType()==2){ + merCouponEditDto.setSendLimitFlag(0); + } coupon.setSendLimitFlag(merCouponEditDto.getSendLimitFlag()); + if(merCouponEditDto.getSendLimitFlag()==1){ + coupon.setSendLimitNumber(merCouponEditDto.getSendLimitNumber()); + }else{ + coupon.setSendLimitNumber(0); + } //判断是否指定商品 if(coupon.getUseScope()==2&&!merCouponEditDto.getRelGoodsIdList().isEmpty()){ List<String> relGoodsIdList = merCouponEditDto.getRelGoodsIdList(); @@ -1188,26 +1313,35 @@ if(!getAbleCouponPageVoList.isEmpty()){ String relGoodsIds; HashSet<Long> shopIdSet = new HashSet<>(); - HashSet<Long> goodsIdSet = new HashSet<>(); + HashSet<String> goodsIdSet = new HashSet<>(); + String[] goodsIdArr; for(AppGetAbleCouponPageVo getAbleCouponPageVo : getAbleCouponPageVoList){ if(getAbleCouponPageVo.getShopId()!=null){ shopIdSet.add(getAbleCouponPageVo.getShopId()); } - if(StringUtils.isNotBlank(getAbleCouponPageVo.getRelGoodsIds())&&!getAbleCouponPageVo.getRelGoodsIds().contains(",")){ - goodsIdSet.add(Long.valueOf(getAbleCouponPageVo.getRelGoodsIds())); + if(StringUtils.isNotBlank(getAbleCouponPageVo.getRelGoodsIds())){ + relGoodsIds = getAbleCouponPageVo.getRelGoodsIds(); + goodsIdArr = relGoodsIds.split(","); + for(String str : goodsIdArr){ + goodsIdSet.add(str); + } } } //获取关联商户和商品信息并转换为Map - String shopJoinedString = String.join(",", shopIdSet.stream().map(Object::toString).collect(Collectors.toList())); + String shopJoinedString; + Map<Long, MgtSimpleShopVo> shopMap = null; + if(shopIdSet!=null&&!shopIdSet.isEmpty()) { + shopJoinedString = String.join(",", shopIdSet.stream().map(Object::toString).collect(Collectors.toList())); + MgtBaseBathDto mgtBaseBathDto = new MgtBaseBathDto(); + mgtBaseBathDto.setIds(shopJoinedString); + List<MgtSimpleShopVo> simpleShopVoList = remoteShopService.listShopSimpleVoByIds(mgtBaseBathDto).getData(); + shopMap = simpleShopVoList.stream() + .collect(Collectors.toMap(MgtSimpleShopVo::getShopId, Function.identity())); + } String goodsJoinedString = null; if(goodsIdSet!=null&&!goodsIdSet.isEmpty()){ goodsJoinedString = String.join(",", goodsIdSet.stream().map(Object::toString).collect(Collectors.toList())); } - MgtBaseBathDto mgtBaseBathDto = new MgtBaseBathDto(); - mgtBaseBathDto.setIds(shopJoinedString); - List<MgtSimpleShopVo> simpleShopVoList = remoteShopService.listShopSimpleVoByIds(mgtBaseBathDto).getData(); - Map<Long, MgtSimpleShopVo> shopMap = simpleShopVoList.stream() - .collect(Collectors.toMap(MgtSimpleShopVo::getShopId, Function.identity())); Map<String, Goods> goodsMap = null; if(goodsJoinedString!=null){ List<Goods> goodsList = remoteGoodsService.listGoodsByGoodsId(goodsJoinedString).getData(); @@ -1215,20 +1349,29 @@ .collect(Collectors.toMap(Goods::getGoodsId, Function.identity())); } //处理返回信息 - String shopLimit = "全场通用"; - String goodsLimit = null; + String shopLimit = "全门店通用"; + String goodsLimit; + StringJoiner goodsNameSj; for(AppGetAbleCouponPageVo getAbleCouponPageVo : getAbleCouponPageVoList){ + goodsLimit = null; + goodsNameSj = new StringJoiner(","); //商户限制 if(getAbleCouponPageVo.getShopId()!=null){ - if(!member.getRelationShopId().equals(getAbleCouponPageVo.getShopId())){ - shopLimit = shopMap.get(getAbleCouponPageVo.getShopId()).getShopName()+"可用"; - } + shopLimit = shopMap.get(getAbleCouponPageVo.getShopId()).getShopName()+"可用"; } getAbleCouponPageVo.setShopLimit(shopLimit); //商品限制 - relGoodsIds = getAbleCouponPageVo.getRelGoodsIds(); - if(StringUtils.isNotBlank(relGoodsIds)&&!relGoodsIds.contains(",")){ - goodsLimit = goodsMap.get(relGoodsIds).getGoodsName(); + if(StringUtils.isNotBlank(getAbleCouponPageVo.getRelGoodsIds())){ + relGoodsIds = getAbleCouponPageVo.getRelGoodsIds(); + goodsIdArr = relGoodsIds.split(","); + for(String goodsIs : goodsIdArr){ + if(goodsMap.get(goodsIs)!=null){ + goodsNameSj.add(goodsMap.get(goodsIs).getGoodsName()); + }else{ + log.debug("用户优惠券未找到关联商品"+getAbleCouponPageVo.getCouponId()+"-"+getAbleCouponPageVo.getRelGoodsIds()); + } + } + goodsLimit = goodsNameSj.toString(); } getAbleCouponPageVo.setGoodsLimit(goodsLimit); } @@ -1248,6 +1391,7 @@ * @return void */ @Override + @Transactional(rollbackFor = Exception.class) public void appGetCoupon(String couponId,Long userId,Long shopId){ Coupon coupon = this.getById(couponId); //判断优惠券状态 -- Gitblit v1.7.1