Pu Zhibing
8 天以前 41d7465a87e2a52740936a5969c5b182e5eb09b3
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
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);
//    }
}