package com.stylefeng.guns.modular.system.service.impl;
|
|
import com.baomidou.mybatisplus.mapper.EntityWrapper;
|
import com.baomidou.mybatisplus.mapper.Wrapper;
|
import com.baomidou.mybatisplus.plugins.Page;
|
import com.baomidou.mybatisplus.service.impl.ServiceImpl;
|
import com.stylefeng.guns.core.node.ZTreeNode;
|
import com.stylefeng.guns.modular.system.dao.*;
|
import com.stylefeng.guns.modular.system.model.*;
|
import com.stylefeng.guns.modular.system.service.IDeptService;
|
import com.stylefeng.guns.modular.system.service.ITActivityService;
|
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.stereotype.Service;
|
import org.springframework.transaction.annotation.Transactional;
|
import org.springframework.util.CollectionUtils;
|
|
import javax.annotation.Resource;
|
import java.math.BigDecimal;
|
import java.util.ArrayList;
|
import java.util.List;
|
import java.util.Map;
|
import java.util.Objects;
|
import java.util.stream.Collectors;
|
|
@Service
|
@Transactional
|
public class TActivityServiceImpl extends ServiceImpl<TActivityMapper, TActivity> implements ITActivityService {
|
|
@Autowired
|
private TActivityAreaMapper activityAreaMapper;
|
@Autowired
|
private TActivityCouponMapper activityCouponMapper;
|
@Autowired
|
private TCouponMapper couponMapper;
|
@Autowired
|
private TUserToCouponMapper userToCouponMapper;
|
@Override
|
public List<TActivity> getList(Page<TActivity> page,String beginTime, String endTime, String branchOfficeName, Integer roleType, Integer objectId, String activityName, String provinceCode, String cityCode, String areaCode, Integer status) {
|
List<TActivity> list = this.baseMapper.getList(page,beginTime, endTime, branchOfficeName, roleType, objectId, activityName, provinceCode, cityCode, areaCode, status);
|
List<Integer> activityIds = list.stream().map(TActivity::getId).collect(Collectors.toList());
|
List<TActivityArea> activityAreas = activityAreaMapper.selectList(new EntityWrapper<TActivityArea>()
|
.in("activityId", activityIds));
|
|
// 查询活动优惠券
|
List<TActivityCoupon> activityCoupons = activityCouponMapper.selectList(new EntityWrapper<TActivityCoupon>().in("activityId", activityIds));
|
List<Integer> couponIds = activityCoupons.stream().map(TActivityCoupon::getCouponId).collect(Collectors.toList());
|
List<TCoupon> coupons;
|
if(!CollectionUtils.isEmpty(couponIds)){
|
coupons = couponMapper.selectList(new EntityWrapper<TCoupon>().in("id", couponIds));
|
} else {
|
coupons = new ArrayList<>();
|
}
|
List<TCoupon> coupons1 = couponMapper.selectList(new EntityWrapper<TCoupon>());
|
// 查询活动领取数据
|
List<TUserToCoupon> userToCoupons = userToCouponMapper.selectList(new EntityWrapper<TUserToCoupon>().in("activityId", activityIds));
|
|
for (TActivity activity : list) {
|
if(!CollectionUtils.isEmpty(activityAreas)){
|
StringBuilder sb = new StringBuilder();
|
activityAreas.stream().filter(e -> e.getActivityId().equals(activity.getId())).forEach(e -> {
|
sb.append(e.getProvinceName() + "-" + e.getCityName() + "-" + e.getAreaName() + "\n");
|
});
|
activity.setActivityArea(sb.toString());
|
}
|
if (!CollectionUtils.isEmpty(activityCoupons)){
|
StringBuilder couponStr = new StringBuilder();
|
activityCoupons.stream().filter(e -> e.getActivityId().equals(activity.getId())).forEach(e -> {
|
coupons.stream().filter(d -> e.getCouponId().equals(d.getId())).forEach(d -> {
|
couponStr.append(d.getCouponName()+ ";");
|
});
|
});
|
activity.setActivityCoupon(couponStr.toString());
|
}
|
if(!CollectionUtils.isEmpty(userToCoupons)){
|
List<TUserToCoupon> tUserToCoupons = userToCoupons.stream().filter(e -> e.getActivityId().equals(activity.getId())).collect(Collectors.toList());
|
BigDecimal activityCouponMoney = new BigDecimal(0);
|
for (TUserToCoupon tUserToCoupon : tUserToCoupons) {
|
List<TCoupon> couponList = coupons1.stream().filter(e -> e.getId().equals(tUserToCoupon.getCouponId())).collect(Collectors.toList());
|
for (TCoupon tCoupon : couponList) {
|
activityCouponMoney = activityCouponMoney.add(tCoupon.getCouponPreferentialAmount().multiply(new BigDecimal(tUserToCoupon.getCouponTotal())));
|
}
|
}
|
activity.setActivityCouponMoney(activityCouponMoney);
|
}
|
switch (activity.getStatus()){
|
case 1:
|
activity.setStatusStr("待审核");
|
break;
|
case 2:
|
if(activity.getStartTime().getTime() > System.currentTimeMillis()){
|
activity.setStatusStr("待开始");
|
}
|
if(activity.getStartTime().getTime() < System.currentTimeMillis() && activity.getEndTime().getTime() > System.currentTimeMillis()){
|
activity.setStatusStr("进行中");
|
}
|
if(activity.getEndTime().getTime() < System.currentTimeMillis()){
|
activity.setStatusStr("已结束");
|
}
|
break;
|
case 3:
|
activity.setStatusStr("已驳回");
|
break;
|
}
|
}
|
return list;
|
}
|
// @Override
|
// public List<Map<String, Object>> getList(Page<Map<String, Object>> page, String beginTime, String endTime, String branchOfficeName, Integer roleType, Integer objectId, String activityName, String provinceCode, String cityCode, String areaCode, Integer status) {
|
// return this.baseMapper.getList(page,beginTime,endTime,branchOfficeName,roleType,objectId,activityName,provinceCode,cityCode,areaCode,status);
|
// }
|
}
|