puzhibing
2024-03-05 6c6d51775200fc1c17b0cd5fc9464016aed13327
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
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
package com.dsh.communityWorldCup.service.impl;
 
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.dsh.communityWorldCup.entity.WorldCup;
import com.dsh.communityWorldCup.entity.WorldCupPayment;
import com.dsh.communityWorldCup.entity.WorldCupPaymentParticipant;
import com.dsh.communityWorldCup.entity.WorldCupStore;
import com.dsh.communityWorldCup.feignclient.account.StudentClient;
import com.dsh.communityWorldCup.feignclient.account.model.TStudent;
import com.dsh.communityWorldCup.feignclient.competition.ParticipantClient;
import com.dsh.communityWorldCup.feignclient.competition.model.Participant;
import com.dsh.communityWorldCup.feignclient.other.StoreClient;
import com.dsh.communityWorldCup.feignclient.other.model.Store;
import com.dsh.communityWorldCup.mapper.WorldCupPaymentParticipantMapper;
import com.dsh.communityWorldCup.model.MyWorldCupInfo;
import com.dsh.communityWorldCup.model.MyWorldCupList;
import com.dsh.communityWorldCup.model.WorldCupListVo;
import com.dsh.communityWorldCup.model.*;
import com.dsh.communityWorldCup.service.IWorldCupPaymentParticipantService;
import com.dsh.communityWorldCup.service.IWorldCupPaymentService;
import com.dsh.communityWorldCup.service.IWorldCupService;
import com.dsh.communityWorldCup.service.IWorldCupStoreService;
import com.dsh.communityWorldCup.util.GeodesyUtil;
import com.dsh.communityWorldCup.util.ToolUtil;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
 
import javax.annotation.Resource;
import java.math.BigDecimal;
import java.math.RoundingMode;
import java.text.SimpleDateFormat;
import java.util.*;
import java.util.stream.Collectors;
 
/**
 * @author zhibing.pu
 * @Date 2024/2/19 11:07
 */
@Service
public class WorldCupPaymentParticipantServiceImpl extends ServiceImpl<WorldCupPaymentParticipantMapper, WorldCupPaymentParticipant> implements IWorldCupPaymentParticipantService {
 
    @Autowired
    private IWorldCupPaymentService worldCupPaymentService;
 
    @Resource
    private StudentClient studentClient;
 
    @Resource
    private ParticipantClient participantClient;
 
    @Autowired
    private IWorldCupService worldCupService;
 
    @Autowired
    private IWorldCupPaymentParticipantService worldCupPaymentParticipantService;
 
    @Autowired
    private IWorldCupStoreService worldCupStoreService;
 
    @Resource
    private StoreClient storeClient;
 
 
 
 
    /**
     * 获取报名数据
     * @param worldCupId
     * @param participantType
     * @param participantId
     * @return
     */
    @Override
    public WorldCupPaymentParticipant getWorldCupPaymentParticipant(Integer worldCupId, Integer participantType, Integer participantId) {
        return this.baseMapper.getWorldCupPaymentParticipant(worldCupId, participantType, participantId);
    }
 
 
    /**
     * 获取社区世界杯我的报名列表
     * @param myWorldCupList
     * @return
     */
    @Override
    public List<WorldCupListVo> getMyWorldCupList(MyWorldCupList myWorldCupList) {
        int pageNo = (myWorldCupList.getPageNo() - 1) * myWorldCupList.getPageSize();
        myWorldCupList.setPageNo(pageNo);
        myWorldCupList.setIsStudent(myWorldCupList.getIsStudent() == 0 ? 2 : 1);
        List<WorldCupListVo> myWorldCupList1 = this.baseMapper.getMyWorldCupList(myWorldCupList);
        for (WorldCupListVo worldCupListVo : myWorldCupList1) {
            Integer worldCupId = worldCupListVo.getWorldCupId();
            List<WorldCupPayment> list = worldCupPaymentService.list(new QueryWrapper<WorldCupPayment>().eq("worldCupId", worldCupId).eq("payStatus", 2).eq("state", 1));
            List<Long> collect = list.stream().map(WorldCupPayment::getId).collect(Collectors.toList());
            Integer heat = worldCupListVo.getHeat();
            if(collect.size() > 0){
                int count = worldCupPaymentParticipantService.count(new QueryWrapper<WorldCupPaymentParticipant>().in("worldCupPaymentId", collect));
                heat += count;
            }
            worldCupListVo.setHeat(heat);
        }
        return myWorldCupList1;
    }
 
 
    /**
     * 获取已报名的世界杯详情
     * @param id    社区世界杯支付对应的参与者记录id
     * @return
     */
    @Override
    public MyWorldCupInfo getMyWorldCupInfo(String id, String lon, String lat) {
        WorldCupPaymentParticipant worldCupPaymentParticipant = this.getById(id);
        Integer worldCupId = worldCupPaymentParticipant.getWorldCupId();
        WorldCupPayment worldCupPayment = worldCupPaymentService.getById(worldCupPaymentParticipant.getWorldCupPaymentId());
        WorldCupInfo worldCupInfo = worldCupService.getWorldCupInfo(worldCupId, null, null);
        WorldCup worldCup = worldCupService.getById(worldCupId);
        MyWorldCupInfo myWorldCupInfo = new MyWorldCupInfo();
        BeanUtils.copyProperties(worldCupInfo, myWorldCupInfo);
        myWorldCupInfo.setUnitPrice(worldCupPayment.getUnitPrice().doubleValue());
        myWorldCupInfo.setExpense(worldCupPayment.getAmount().doubleValue());
        myWorldCupInfo.setStatus(worldCup.getStatus());
        myWorldCupInfo.setRevocable(1);
        myWorldCupInfo.setProvince(worldCup.getProvince());
        myWorldCupInfo.setCity(worldCup.getCity());
        myWorldCupInfo.setPayType(worldCupPayment.getPayType());
        //开始前一天不能取消
        if(worldCup.getStartTime().getTime() < System.currentTimeMillis() + 86400000L){
            myWorldCupInfo.setRevocable(0);
        }
        List<ParticipantVo> datas = new ArrayList<>();
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy");
        List<WorldCupPaymentParticipant> list1 = this.list(new QueryWrapper<WorldCupPaymentParticipant>().eq("worldCupPaymentId", worldCupPaymentParticipant.getWorldCupPaymentId()));
        for (WorldCupPaymentParticipant wcpp : list1) {
            Integer participantType = wcpp.getParticipantType();
            Integer participantId = wcpp.getParticipantId();
            ParticipantVo participantVo = new ParticipantVo();
            //学员
            if(1 == participantType){
                TStudent tStudent = studentClient.queryById(participantId);
                participantVo.setId(tStudent.getId());
                participantVo.setName(tStudent.getName());
                int age = Integer.valueOf(sdf.format(new Date())) - Integer.valueOf(sdf.format(tStudent.getBirthday()));
                participantVo.setAge(age);
                participantVo.setIdcard(tStudent.getIdCard());
                participantVo.setPhone(tStudent.getPhone());
                participantVo.setIsStudent(1);
                datas.add(participantVo);
            }
            //参赛人员
            if(2 == participantType){
                Participant participant = participantClient.getParticipant(participantId);
                participantVo.setId(participant.getId());
                participantVo.setName(participant.getName());
                int age = Integer.valueOf(sdf.format(new Date())) - Integer.valueOf(sdf.format(participant.getBirthday()));
                participantVo.setAge(age);
                participantVo.setIdcard(participant.getIdcard());
                participantVo.setPhone(participant.getPhone());
                participantVo.setIsStudent(0);
                datas.add(participantVo);
            }
        }
 
        myWorldCupInfo.setParticipants(datas);
        List<WorldCupStore> worldCupStores = worldCupStoreService.list(new QueryWrapper<WorldCupStore>().eq("worldCupId", id));
        ArrayList<Map<String, Object>> objects = new ArrayList<>();
        for (WorldCupStore worldCupStore : worldCupStores) {
            HashMap<String, Object> map = new HashMap<>();
            Store store = storeClient.queryStoreById(worldCupStore.getStoreId());
            map.put("name", store.getName());
 
 
            String str = store.getAddress();
            str = str.substring(str.indexOf("省") + 1);
 
            // 去掉第一个“市”及之前的字符串
            str = str.substring(str.indexOf("市") + 1);
 
            // 去掉第一个“区”及之前的字符串
            str = str.substring(str.indexOf("区") + 1);
 
            map.put("address", str);
            map.put("storeLon", store.getLon());
            map.put("storeLat", store.getLat());
            map.put("storeCoverDrawing", store.getCoverDrawing());
            if (ToolUtil.isNotEmpty(lon) && ToolUtil.isNotEmpty(lat)) {
                Map<String, Double> distance = GeodesyUtil.getDistance(lon + "," + lat, store.getLon() + "," + store.getLat());
                double wgs84 = new BigDecimal(distance.get("WGS84")).divide(new BigDecimal(1000)).setScale(2, RoundingMode.HALF_EVEN).doubleValue();
                map.put("distance", wgs84);
            }
            objects.add(map);
        }
        worldCupInfo.setStoreInfos(objects);
        return myWorldCupInfo;
    }
 
 
    /**
     * 获取已报过名的参赛人员
     * @param uid   当前用户
     * @return
     */
    @Override
    public List<ParticipantVo> getParticipant(Integer uid) {
        List<WorldCupPayment> list = worldCupPaymentService.list(new QueryWrapper<WorldCupPayment>().eq("appUserId", uid)
                .eq("payStatus", 2).eq("state", 1));
        List<Long> collect = list.stream().map(WorldCupPayment::getId).collect(Collectors.toList());
        List<ParticipantVo> datas = new ArrayList<>();
        Set<Integer> csry = new HashSet<>();
        Set<Integer> xy = new HashSet<>();
        if(collect.size() > 0){
            SimpleDateFormat sdf = new SimpleDateFormat("yyyy");
            List<WorldCupPaymentParticipant> list1 = this.list(new QueryWrapper<WorldCupPaymentParticipant>().in("worldCupPaymentId", collect));
            for (WorldCupPaymentParticipant worldCupPaymentParticipant : list1) {
                Integer participantType = worldCupPaymentParticipant.getParticipantType();
                Integer participantId = worldCupPaymentParticipant.getParticipantId();
                ParticipantVo participantVo = new ParticipantVo();
                //学员
                if(1 == participantType && !xy.contains(participantId)){
                    TStudent tStudent = studentClient.queryById(participantId);
                    participantVo.setId(tStudent.getId());
                    participantVo.setName(tStudent.getName());
                    int age = Integer.valueOf(sdf.format(new Date())) - Integer.valueOf(sdf.format(tStudent.getBirthday()));
                    participantVo.setAge(age);
                    participantVo.setIdcard(tStudent.getIdCard());
                    participantVo.setPhone(tStudent.getPhone());
                    participantVo.setIsStudent(1);
                    datas.add(participantVo);
                }
                //参赛人员
                if(2 == participantType && !csry.contains(participantId)){
                    Participant participant = participantClient.getParticipant(participantId);
                    participantVo.setId(participant.getId());
                    participantVo.setName(participant.getName());
                    int age = Integer.valueOf(sdf.format(new Date())) - Integer.valueOf(sdf.format(participant.getBirthday()));
                    participantVo.setAge(age);
                    participantVo.setIdcard(participant.getIdcard());
                    participantVo.setPhone(participant.getPhone());
                    participantVo.setIsStudent(0);
                    datas.add(participantVo);
                }
            }
        }
        return datas;
    }
}