| | |
| | | package com.xiaopeng.operation.service.impl; |
| | | |
| | | import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
| | | import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
| | | import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
| | | import com.xiaopeng.api.dto.operation.XpActivityDto; |
| | | import com.xiaopeng.api.model.operation.XpActicityStrategy; |
| | | import com.xiaopeng.api.model.operation.XpActicityUser; |
| | | import com.xiaopeng.api.model.operation.XpActivity; |
| | | import com.xiaopeng.api.model.operation.XpActivityNotice; |
| | | import com.xiaopeng.api.feignClient.order.XpOrderClient; |
| | | import com.xiaopeng.api.model.operation.*; |
| | | import com.xiaopeng.api.query.operation.XpActivityPageListQuery; |
| | | 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.IXpActicityService; |
| | | import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
| | | import com.xiaopeng.operation.service.IXpActicityStrategyService; |
| | | import com.xiaopeng.operation.service.IXpActicityUserService; |
| | | import com.xiaopeng.operation.service.IXpActivityNoticeService; |
| | | 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.util.ArrayList; |
| | | import java.util.List; |
| | | import java.util.Map; |
| | | import java.util.Random; |
| | | import java.util.function.Function; |
| | | import java.util.stream.Collectors; |
| | | |
| | |
| | | @Resource |
| | | private IXpActivityNoticeService activityNotice; |
| | | |
| | | @Resource |
| | | private XpOrderClient xpOrderClient; |
| | | |
| | | @Resource |
| | | private IXpActicityCouponService xpActicityCouponService; |
| | | |
| | | |
| | | |
| | | @Override |
| | | public PageInfo<XpActivity> pageList(XpActivityPageListQuery query) { |
| | | PageInfo<XpActivity> pageInfo = new PageInfo<>(query.getPageNum(),query.getPageSize()); |
| | | List<XpActivity> list = this.baseMapper.pageList(pageInfo,query); |
| | | 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; |
| | | } |
| | |
| | | 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 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())); |
| | | |
| | | XpActivity one = this.getOne(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 order by float_window_priority desc limit 1")); |
| | | return one; |
| | | } |
| | | |
| | | @Override |
| | | @Transactional |
| | | 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(); |
| | | XpActivityNotice notice = dto.getNotice(); |
| | | strategy.forEach(e -> e.setActitcityId(activity.getId().intValue())); |
| | | strategyService.saveBatch(strategy); |
| | | 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() |
| | | )); |
| | | activityUser.forEach(item -> { |
| | | item.setActitcityId(activity.getId().intValue()); |
| | | item.setActitcityStrategeId(strategyMap.get(item.getStrategyName()).getId()); |
| | | }); |
| | | notice.setActivityId(activity.getId()); |
| | | userService.saveBatch(activityUser); |
| | | activityNotice.save(notice); |
| | | for (XpActicityUser xpActicityUser : activityUser) { |
| | | xpActicityUser.setActitcityId(activity.getId().intValue()); |
| | | xpActicityUser.setActitcityStrategeId(strategyMap.get(xpActicityUser.getStrategyName()).getId()); |
| | | userService.save(xpActicityUser); |
| | | } |
| | | } |
| | | |
| | | @Override |
| | |
| | | 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; |
| | | } |
| | | } |