| | |
| | | package com.xiaopeng.operation.service.impl; |
| | | |
| | | import com.alibaba.fastjson.JSON; |
| | | import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
| | | import com.xiaopeng.api.model.operation.XpActivity; |
| | | import com.xiaopeng.operation.mapper.XpActicityMapper; |
| | | import com.xiaopeng.operation.service.IXpActicityService; |
| | | import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
| | | import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
| | | import com.xiaopeng.api.dto.account.UcUserInfo; |
| | | import com.xiaopeng.api.dto.operation.XpActivityDto; |
| | | import com.xiaopeng.api.feignClient.account.UserResourcesClient; |
| | | import com.xiaopeng.api.feignClient.account.XpAppUserCouponClient; |
| | | import com.xiaopeng.api.feignClient.order.XpOrderClient; |
| | | import com.xiaopeng.api.model.account.XpAppUserCoupon; |
| | | import com.xiaopeng.api.model.operation.*; |
| | | import com.xiaopeng.api.query.operation.XpActivityPageListQuery; |
| | | import com.xiaopeng.api.vo.account.AppUserCouponSaveBatchVo; |
| | | import com.xiaopeng.common.core.utils.bean.BeanUtils; |
| | | import com.xiaopeng.common.core.web.page.PageInfo; |
| | | import com.xiaopeng.operation.mapper.XpActicityMapper; |
| | | import com.xiaopeng.operation.service.*; |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.transaction.annotation.Transactional; |
| | | |
| | | import javax.annotation.Resource; |
| | | import java.time.LocalDateTime; |
| | | import java.time.format.DateTimeFormatter; |
| | | import java.util.ArrayList; |
| | | import java.util.Arrays; |
| | | import java.util.List; |
| | | import java.util.Random; |
| | | import java.util.Map; |
| | | import java.util.function.Function; |
| | | import java.util.stream.Collectors; |
| | | |
| | | /** |
| | | * <p> |
| | |
| | | @Service |
| | | public class XpActicityServiceImpl extends ServiceImpl<XpActicityMapper, XpActivity> implements IXpActicityService { |
| | | |
| | | @Resource |
| | | private IXpActicityStrategyService strategyService; |
| | | |
| | | @Resource |
| | | private IXpActicityUserService userService; |
| | | |
| | | @Resource |
| | | private XpOrderClient xpOrderClient; |
| | | |
| | | @Resource |
| | | private IXpActicityStrategyService xpActicityStrategyService; |
| | | |
| | | @Resource |
| | | private IXpActicityService xpActicityService; |
| | | |
| | | @Resource |
| | | private IXpActicityUserService xpActicityUserService; |
| | | |
| | | @Resource |
| | | private IXpWhitelistService xpWhitelistService; |
| | | |
| | | @Resource |
| | | private IXpActicityCouponService xpActicityCouponService; |
| | | |
| | | @Resource |
| | | private IXpCouponService xpCouponService; |
| | | |
| | | @Resource |
| | | private XpAppUserCouponClient xpAppUserCouponClient; |
| | | |
| | | @Resource |
| | | private UserResourcesClient userResourcesClient; |
| | | |
| | | |
| | | |
| | | @Override |
| | | public PageInfo<XpActivityDto> pageList(XpActivityPageListQuery query) { |
| | | PageInfo<XpActivityDto> pageInfo = new PageInfo<>(query.getPageNum(),query.getPageSize()); |
| | | List<XpActivityDto> list = this.baseMapper.pageList(pageInfo,query); |
| | | pageInfo.setRecords(list); |
| | | return pageInfo; |
| | | } |
| | | |
| | | @Override |
| | | public List<String> findListToIds(String acticityName){ |
| | |
| | | query.like(XpActivity::getActicityName, acticityName); |
| | | return listObjs(query, Object::toString); |
| | | } |
| | | |
| | | @Override |
| | | public XpActivity activiting() { |
| | | LambdaQueryWrapper<XpActivity> query = new LambdaQueryWrapper<>(); |
| | | LocalDateTime now = LocalDateTime.now(); |
| | | query.le(XpActivity::getStartTime, now) |
| | | .ge(XpActivity::getEndTime, now); |
| | | List<XpActivity> list = list(query); |
| | | if(!list.isEmpty()){ |
| | | return list.get(new Random().nextInt(list.size())); |
| | | } |
| | | return null; |
| | | public List<XpActivity> activiting(Long uid) { |
| | | //获取当前用户可参与的活动 |
| | | List<Integer> actitctiyIds = new ArrayList<>(); |
| | | //全部用户 |
| | | List<XpActicityUser> list = userService.list(new QueryWrapper<XpActicityUser>().eq("is_deleted", 0).eq("user_type", 1)); |
| | | actitctiyIds.addAll(list.stream().map(XpActicityUser::getActitcityId).collect(Collectors.toList())); |
| | | //判断用户类型 2=老用户,3=新用户,4=流失用户 |
| | | Integer userType = xpOrderClient.determineUserType(uid).getData(); |
| | | list = userService.list(new QueryWrapper<XpActicityUser>().eq("is_deleted", 0).eq("user_type", userType)); |
| | | actitctiyIds.addAll(list.stream().map(XpActicityUser::getActitcityId).collect(Collectors.toList())); |
| | | //指定用户 |
| | | list = userService.list(new QueryWrapper<XpActicityUser>().eq("is_deleted", 0).eq("user_type", 5) |
| | | .last(" and JSON_CONTAINS(user_list, '" + uid + "', '$')")); |
| | | actitctiyIds.addAll(list.stream().map(XpActicityUser::getActitcityId).collect(Collectors.toList())); |
| | | |
| | | List<XpActivity> one = this.list(new QueryWrapper<XpActivity>().eq("status", 2).eq("is_deleted", 0) |
| | | .eq("mini_program_notification", 1).in(!actitctiyIds.isEmpty(), "id", actitctiyIds) |
| | | .last(" and now() between start_time and end_time")); |
| | | return one; |
| | | } |
| | | |
| | | @Override |
| | | public void save(XpActivityDto dto) { |
| | | |
| | | XpActivity activity = new XpActivity(); |
| | | BeanUtils.copyBeanProp(activity, dto); |
| | | activity.setActicityType(dto.getActivityType()); |
| | | activity.setAggregateLimit(dto.getEnableTotalLimit() ? 1 : 0); |
| | | activity.setLimitation(dto.getTotalLimit()); |
| | | activity.setCoverImage(dto.getImg()); |
| | | activity.setRemarks(dto.getRichText()); |
| | | save(activity); |
| | | |
| | | List<XpActicityStrategy> strategy = dto.getStrategy(); |
| | | List<XpActicityUser> activityUser = dto.getActivityUser(); |
| | | for (XpActicityStrategy xpActicityStrategy : strategy) { |
| | | xpActicityStrategy.setActitcityId(activity.getId().intValue()); |
| | | xpActicityStrategy.setDeleted(false); |
| | | strategyService.save(xpActicityStrategy); |
| | | |
| | | List<Long> couponIds = xpActicityStrategy.getCouponIds(); |
| | | for (Long couponId : couponIds) { |
| | | XpActicityCoupon xpActicityCoupon = new XpActicityCoupon(); |
| | | xpActicityCoupon.setActicityStrategyId(xpActicityStrategy.getId().longValue()); |
| | | xpActicityCoupon.setCouponId(couponId); |
| | | xpActicityCoupon.setActivityId(activity.getId()); |
| | | xpActicityCouponService.save(xpActicityCoupon); |
| | | } |
| | | |
| | | } |
| | | Map<String, XpActicityStrategy> strategyMap = strategy.stream().collect(Collectors.toMap( |
| | | XpActicityStrategy::getName, |
| | | Function.identity() |
| | | )); |
| | | for (XpActicityUser xpActicityUser : activityUser) { |
| | | xpActicityUser.setActitcityId(activity.getId().intValue()); |
| | | xpActicityUser.setActitcityStrategeId(strategyMap.get(xpActicityUser.getStrategyName()).getId()); |
| | | userService.save(xpActicityUser); |
| | | } |
| | | |
| | | //执行修改活动状态 |
| | | updateStatus(activity.getId()); |
| | | } |
| | | |
| | | @Override |
| | | public XpActivityDto detail(Long id) { |
| | | XpActivity byId = getById(id); |
| | | XpActivityDto ret = new XpActivityDto(); |
| | | BeanUtils.copyBeanProp(ret, byId); |
| | | ret.setActicityType(byId.getActicityType()); |
| | | ret.setEnableTotalLimit(byId.getAggregateLimit() == 1); |
| | | ret.setTotalLimit(byId.getLimitation()); |
| | | ret.setImg(byId.getCoverImage()); |
| | | ret.setRichText(byId.getRemarks()); |
| | | ret.setStrategy(strategyService.listByActicityId(id)); |
| | | ret.setActivityUser(userService.listByActicityId(id)); |
| | | return ret; |
| | | } |
| | | |
| | | |
| | | /** |
| | | * 获取悬浮弹窗活动数据 |
| | | * @param uid |
| | | * @return |
| | | */ |
| | | @Override |
| | | public XpActivity getFloatActicity(Long uid) { |
| | | //获取当前用户可参与的活动 |
| | | List<Integer> actitctiyIds = new ArrayList<>(); |
| | | //全部用户 |
| | | List<XpActicityUser> list = userService.list(new QueryWrapper<XpActicityUser>().eq("is_deleted", 0).eq("user_type", 1)); |
| | | actitctiyIds.addAll(list.stream().map(XpActicityUser::getActitcityId).collect(Collectors.toList())); |
| | | //判断用户类型 2=老用户,3=新用户,4=流失用户 |
| | | Integer userType = xpOrderClient.determineUserType(uid).getData(); |
| | | list = userService.list(new QueryWrapper<XpActicityUser>().eq("is_deleted", 0).eq("user_type", userType)); |
| | | actitctiyIds.addAll(list.stream().map(XpActicityUser::getActitcityId).collect(Collectors.toList())); |
| | | //指定用户 |
| | | list = userService.list(new QueryWrapper<XpActicityUser>().eq("is_deleted", 0).eq("user_type", 5) |
| | | .last(" and JSON_CONTAINS(user_list, '" + uid + "', '$')")); |
| | | actitctiyIds.addAll(list.stream().map(XpActicityUser::getActitcityId).collect(Collectors.toList())); |
| | | |
| | | XpActivity one = this.getOne(new QueryWrapper<XpActivity>().eq("status", 2).eq("is_deleted", 0) |
| | | .eq("enable_float_window", 1).in(!actitctiyIds.isEmpty(), "id", actitctiyIds) |
| | | .last(" and now() between start_time and end_time order by float_window_priority desc limit 1")); |
| | | return one; |
| | | } |
| | | |
| | | |
| | | public void updateStatus(Long activityId) { |
| | | XpActivity xpActivity = xpActicityService.getById(activityId); |
| | | Integer status = xpActivity.getStatus(); |
| | | //即将开始的活动推送socket给前端用户 |
| | | if(1 == status && LocalDateTime.now().isBefore(xpActivity.getStartTime())){ |
| | | |
| | | } |
| | | |
| | | //即将结束的活动推送给前端用户 |
| | | |
| | | //生效的活动修改状态和发放一次优惠券 |
| | | if(1 == status && LocalDateTime.now().isAfter(xpActivity.getStartTime()) && LocalDateTime.now().isBefore(xpActivity.getEndTime())){ |
| | | xpActivity.setStatus(2); |
| | | //发放优惠券-发放一次的优惠券 |
| | | List<XpActicityStrategy> list1 = xpActicityStrategyService.list(new QueryWrapper<XpActicityStrategy>().eq("actitcity_id", xpActivity.getId()) |
| | | .eq("distribution_rules", 2)); |
| | | for (XpActicityStrategy xpActicityStrategy : list1) { |
| | | pushCoupon(xpActivity, xpActicityStrategy); |
| | | } |
| | | |
| | | } |
| | | xpActicityService.updateById(xpActivity); |
| | | } |
| | | |
| | | |
| | | @Override |
| | | public void updateStatus() { |
| | | List<XpActivity> list = xpActicityService.list(new QueryWrapper<XpActivity>().in("status", Arrays.asList(1, 2)).eq("is_deleted", 0)); |
| | | for (XpActivity xpActivity : list) { |
| | | Integer status = xpActivity.getStatus(); |
| | | //即将开始的活动推送socket给前端用户 |
| | | if(1 == status && LocalDateTime.now().isBefore(xpActivity.getStartTime())){ |
| | | |
| | | } |
| | | |
| | | //即将结束的活动推送给前端用户 |
| | | |
| | | //生效的活动修改状态和发放一次优惠券 |
| | | if(1 == status && LocalDateTime.now().isAfter(xpActivity.getStartTime()) && LocalDateTime.now().isBefore(xpActivity.getEndTime())){ |
| | | xpActivity.setStatus(2); |
| | | //发放优惠券-发放一次的优惠券 |
| | | List<XpActicityStrategy> list1 = xpActicityStrategyService.list(new QueryWrapper<XpActicityStrategy>().eq("actitcity_id", xpActivity.getId()) |
| | | .eq("distribution_rules", 2)); |
| | | for (XpActicityStrategy xpActicityStrategy : list1) { |
| | | pushCoupon(xpActivity, xpActicityStrategy); |
| | | } |
| | | |
| | | } |
| | | //到期的活动修改状态为已结束 |
| | | if(2 == status & LocalDateTime.now().isAfter(xpActivity.getEndTime())){ |
| | | xpActivity.setStatus(3); |
| | | } |
| | | xpActicityService.updateById(xpActivity); |
| | | } |
| | | } |
| | | |
| | | |
| | | /** |
| | | * 发放优惠券 |
| | | * @param xpActivity |
| | | * @param xpActicityStrategy |
| | | */ |
| | | public void pushCoupon(XpActivity xpActivity, XpActicityStrategy xpActicityStrategy){ |
| | | List<XpActicityCoupon> acticityCoupons = xpActicityCouponService.list(new QueryWrapper<XpActicityCoupon>().eq("acticity_strategy_id", xpActicityStrategy.getId())); |
| | | List<XpCoupon> xpCoupons = xpCouponService.listByIds(acticityCoupons.stream().map(XpActicityCoupon::getCouponId).collect(Collectors.toList())); |
| | | //总发放数量 |
| | | Integer distributionsTotal = xpActicityStrategy.getDistributionsTotal(); |
| | | //没人限量数量 |
| | | Integer limitNumber = xpActicityStrategy.getLimitNumber(); |
| | | List<XpActicityUser> list2 = xpActicityUserService.list(new QueryWrapper<XpActicityUser>().eq("actitcity_stratege_id", xpActicityStrategy.getId())); |
| | | for (XpActicityUser xpActicityUser : list2) { |
| | | Integer userType = xpActicityUser.getUserType(); |
| | | //全部白名单用户 |
| | | if(1 == userType){ |
| | | List<XpWhitelist> list3 = xpWhitelistService.list(new QueryWrapper<XpWhitelist>().eq("is_deleted", 0).eq("status", 1)); |
| | | List<XpAppUserCoupon> xpAppUserCoupons = new ArrayList<>(); |
| | | for (XpWhitelist xpWhitelist : list3) { |
| | | for (XpActicityCoupon acticityCoupon : acticityCoupons) { |
| | | XpCoupon xpCoupon = xpCoupons.stream().filter(s -> s.getId().equals(acticityCoupon.getCouponId())).findFirst().orElse(null); |
| | | if(null != xpCoupon){ |
| | | for (Integer i = 0; i < limitNumber; i++) { |
| | | XpAppUserCoupon xpAppUserCoupon = new XpAppUserCoupon(); |
| | | xpAppUserCoupon.setFullMoney(xpCoupon.getConditionalAmount()); |
| | | xpAppUserCoupon.setMoney(xpCoupon.getAmount()); |
| | | |
| | | Integer effectiveRules = xpActicityStrategy.getEffectiveRules(); |
| | | // 领取后生效 |
| | | if(1 == effectiveRules){ |
| | | xpAppUserCoupon.setEffectiveTime(LocalDateTime.now()); |
| | | } |
| | | // 指定日期生效 |
| | | if(2 == effectiveRules){ |
| | | String format = xpActicityStrategy.getEffectiveDays().format(DateTimeFormatter.ofPattern("yyyy-MM-dd")); |
| | | xpAppUserCoupon.setEffectiveTime(LocalDateTime.parse(format + " 23:59:59", DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"))); |
| | | } |
| | | |
| | | Integer expireRules = xpActicityStrategy.getExpireRules(); |
| | | //次日0点失效 |
| | | if(1 == expireRules){ |
| | | LocalDateTime now = LocalDateTime.now(); |
| | | LocalDateTime localDateTime = now.plusDays(1); |
| | | LocalDateTime localDateTime1 = localDateTime.withHour(0).withMinute(0).withSecond(0); |
| | | xpAppUserCoupon.setExpirationTime(localDateTime1); |
| | | } |
| | | //指定有效天数 |
| | | if(2 == expireRules){ |
| | | LocalDateTime now = LocalDateTime.now(); |
| | | xpAppUserCoupon.setExpirationTime(now.plusDays(xpActicityStrategy.getExpireDays())); |
| | | } |
| | | //指定日期失效 |
| | | if(3 == expireRules){ |
| | | String format = xpActicityStrategy.getExpireDate().format(DateTimeFormatter.ofPattern("yyyy-MM-dd")); |
| | | LocalDateTime localDateTime = LocalDateTime.parse(format + " 23:59:59", DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")); |
| | | xpAppUserCoupon.setExpirationTime(localDateTime); |
| | | } |
| | | |
| | | xpAppUserCoupon.setCouponId(acticityCoupon.getCouponId()); |
| | | xpAppUserCoupon.setAppUserId(xpWhitelist.getAppUserId()); |
| | | xpAppUserCoupon.setStatus(1); |
| | | xpAppUserCoupon.setActivityId(xpActivity.getId()); |
| | | xpAppUserCoupon.setCouponName(xpCoupon.getCouponName()); |
| | | xpAppUserCoupon.setDeleted(false); |
| | | xpAppUserCoupon.setCreateTime(LocalDateTime.now()); |
| | | xpAppUserCoupon.setUpdateTime(LocalDateTime.now()); |
| | | xpAppUserCoupon.setPhone(xpWhitelist.getAccount()); |
| | | xpAppUserCoupon.setTimeJson(JSON.toJSONString(xpActicityStrategy.getUsagePeriod())); |
| | | xpAppUserCoupons.add(xpAppUserCoupon); |
| | | if(null == distributionsTotal){ |
| | | continue; |
| | | } |
| | | distributionsTotal--; |
| | | if(distributionsTotal <= 0){ |
| | | break; |
| | | } |
| | | } |
| | | |
| | | } |
| | | } |
| | | if(null == distributionsTotal){ |
| | | continue; |
| | | } |
| | | if(distributionsTotal <= 0){ |
| | | break; |
| | | } |
| | | } |
| | | if(!xpAppUserCoupons.isEmpty()){ |
| | | AppUserCouponSaveBatchVo vo = new AppUserCouponSaveBatchVo(); |
| | | vo.setXpAppUserCoupons(xpAppUserCoupons); |
| | | xpAppUserCouponClient.saveBatch(vo); |
| | | } |
| | | if(null == distributionsTotal){ |
| | | continue; |
| | | } |
| | | if(distributionsTotal <= 0){ |
| | | break; |
| | | } |
| | | } |
| | | //老用户 |
| | | if(2 == userType || 3 == userType || 4 == userType){ |
| | | List<Long> longList = xpOrderClient.getUserTypeIdList(userType).getData(); |
| | | List<XpAppUserCoupon> xpAppUserCoupons = new ArrayList<>(); |
| | | for (Long userId : longList) { |
| | | UcUserInfo baseUserByUid = userResourcesClient.getBaseUserByUid(userId.toString()); |
| | | for (XpActicityCoupon acticityCoupon : acticityCoupons) { |
| | | XpCoupon xpCoupon = xpCoupons.stream().filter(s -> s.getId().equals(acticityCoupon.getCouponId())).findFirst().orElse(null); |
| | | if(null != xpCoupon){ |
| | | for (Integer i = 0; i < limitNumber; i++) { |
| | | XpAppUserCoupon xpAppUserCoupon = new XpAppUserCoupon(); |
| | | xpAppUserCoupon.setFullMoney(xpCoupon.getConditionalAmount()); |
| | | xpAppUserCoupon.setMoney(xpCoupon.getAmount()); |
| | | |
| | | Integer expireRules = xpActicityStrategy.getExpireRules(); |
| | | //次日0点失效 |
| | | if(1 == expireRules){ |
| | | LocalDateTime now = LocalDateTime.now(); |
| | | LocalDateTime localDateTime = now.plusDays(1); |
| | | LocalDateTime localDateTime1 = localDateTime.withHour(0).withMinute(0).withSecond(0); |
| | | xpAppUserCoupon.setExpirationTime(localDateTime1); |
| | | } |
| | | //指定有效天数 |
| | | if(2 == expireRules){ |
| | | LocalDateTime now = LocalDateTime.now(); |
| | | xpAppUserCoupon.setExpirationTime(now.plusDays(xpActicityStrategy.getExpireDays())); |
| | | } |
| | | //指定日期失效 |
| | | if(3 == expireRules){ |
| | | String format = xpActicityStrategy.getExpireDate().format(DateTimeFormatter.ofPattern("yyyy-MM-dd")); |
| | | LocalDateTime localDateTime = LocalDateTime.parse(format + " 23:59:59", DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")); |
| | | xpAppUserCoupon.setExpirationTime(localDateTime); |
| | | } |
| | | |
| | | xpAppUserCoupon.setCouponId(acticityCoupon.getCouponId()); |
| | | xpAppUserCoupon.setAppUserId(userId); |
| | | xpAppUserCoupon.setStatus(1); |
| | | xpAppUserCoupon.setActivityId(xpActivity.getId()); |
| | | xpAppUserCoupon.setCouponName(xpCoupon.getCouponName()); |
| | | xpAppUserCoupon.setDeleted(false); |
| | | xpAppUserCoupon.setCreateTime(LocalDateTime.now()); |
| | | xpAppUserCoupon.setUpdateTime(LocalDateTime.now()); |
| | | xpAppUserCoupon.setPhone(baseUserByUid.getMobile()); |
| | | xpAppUserCoupon.setTimeJson(JSON.toJSONString(xpActicityStrategy.getUsagePeriod())); |
| | | xpAppUserCoupons.add(xpAppUserCoupon); |
| | | if(null == distributionsTotal){ |
| | | continue; |
| | | } |
| | | distributionsTotal--; |
| | | if(distributionsTotal <= 0){ |
| | | break; |
| | | } |
| | | } |
| | | } |
| | | if(null == distributionsTotal){ |
| | | continue; |
| | | } |
| | | if(distributionsTotal <= 0){ |
| | | break; |
| | | } |
| | | } |
| | | } |
| | | if(!xpAppUserCoupons.isEmpty()){ |
| | | AppUserCouponSaveBatchVo vo = new AppUserCouponSaveBatchVo(); |
| | | vo.setXpAppUserCoupons(xpAppUserCoupons); |
| | | xpAppUserCouponClient.saveBatch(vo); |
| | | } |
| | | if(null == distributionsTotal){ |
| | | continue; |
| | | } |
| | | if(distributionsTotal <= 0){ |
| | | break; |
| | | } |
| | | } |
| | | //指定用户 |
| | | if(5 == userType){ |
| | | List<Integer> userList = xpActicityUser.getUserList(); |
| | | List<XpAppUserCoupon> xpAppUserCoupons = new ArrayList<>(); |
| | | for (Integer userId : userList) { |
| | | UcUserInfo baseUserByUid = userResourcesClient.getBaseUserByUid(userId.toString()); |
| | | for (XpActicityCoupon acticityCoupon : acticityCoupons) { |
| | | XpCoupon xpCoupon = xpCoupons.stream().filter(s -> s.getId().equals(acticityCoupon.getCouponId())).findFirst().orElse(null); |
| | | if(null != xpCoupon){ |
| | | for (Integer i = 0; i < limitNumber; i++) { |
| | | XpAppUserCoupon xpAppUserCoupon = new XpAppUserCoupon(); |
| | | xpAppUserCoupon.setFullMoney(xpCoupon.getConditionalAmount()); |
| | | xpAppUserCoupon.setMoney(xpCoupon.getAmount()); |
| | | |
| | | Integer expireRules = xpActicityStrategy.getExpireRules(); |
| | | //次日0点失效 |
| | | if(1 == expireRules){ |
| | | LocalDateTime now = LocalDateTime.now(); |
| | | LocalDateTime localDateTime = now.plusDays(1); |
| | | LocalDateTime localDateTime1 = localDateTime.withHour(0).withMinute(0).withSecond(0); |
| | | xpAppUserCoupon.setExpirationTime(localDateTime1); |
| | | } |
| | | //指定有效天数 |
| | | if(2 == expireRules){ |
| | | LocalDateTime now = LocalDateTime.now(); |
| | | xpAppUserCoupon.setExpirationTime(now.plusDays(xpActicityStrategy.getExpireDays())); |
| | | } |
| | | //指定日期失效 |
| | | if(3 == expireRules){ |
| | | String format = xpActicityStrategy.getExpireDate().format(DateTimeFormatter.ofPattern("yyyy-MM-dd")); |
| | | LocalDateTime localDateTime = LocalDateTime.parse(format + " 23:59:59", DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")); |
| | | xpAppUserCoupon.setExpirationTime(localDateTime); |
| | | } |
| | | |
| | | xpAppUserCoupon.setCouponId(acticityCoupon.getCouponId()); |
| | | xpAppUserCoupon.setAppUserId(userId.longValue()); |
| | | xpAppUserCoupon.setStatus(1); |
| | | xpAppUserCoupon.setActivityId(xpActivity.getId()); |
| | | xpAppUserCoupon.setCouponName(xpCoupon.getCouponName()); |
| | | xpAppUserCoupon.setDeleted(false); |
| | | xpAppUserCoupon.setCreateTime(LocalDateTime.now()); |
| | | xpAppUserCoupon.setUpdateTime(LocalDateTime.now()); |
| | | xpAppUserCoupon.setPhone(baseUserByUid.getMobile()); |
| | | xpAppUserCoupon.setTimeJson(JSON.toJSONString(xpActicityStrategy.getUsagePeriod())); |
| | | xpAppUserCoupons.add(xpAppUserCoupon); |
| | | if(null == distributionsTotal){ |
| | | continue; |
| | | } |
| | | distributionsTotal--; |
| | | if(distributionsTotal <= 0){ |
| | | break; |
| | | } |
| | | } |
| | | |
| | | } |
| | | if(null == distributionsTotal){ |
| | | continue; |
| | | } |
| | | if(distributionsTotal <= 0){ |
| | | break; |
| | | } |
| | | } |
| | | |
| | | if(null == distributionsTotal){ |
| | | continue; |
| | | } |
| | | if(distributionsTotal <= 0){ |
| | | break; |
| | | } |
| | | } |
| | | if(!xpAppUserCoupons.isEmpty()){ |
| | | AppUserCouponSaveBatchVo vo = new AppUserCouponSaveBatchVo(); |
| | | vo.setXpAppUserCoupons(xpAppUserCoupons); |
| | | xpAppUserCouponClient.saveBatch(vo); |
| | | } |
| | | } |
| | | } |
| | | } |
| | | } |