刘帅
2026-09-22 474724c0e016be419fe84967fdcb085722e6b444
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
package com.dsh.competition.controller;
 
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.dsh.competition.entity.Participant;
import com.dsh.competition.entity.UserCompetition;
import com.dsh.competition.feignclient.account.AppUserClient;
import com.dsh.competition.feignclient.account.StudentClient;
import com.dsh.competition.feignclient.account.model.AppUser;
import com.dsh.competition.feignclient.account.model.Student;
import com.dsh.competition.feignclient.account.model.TStudent;
import com.dsh.competition.model.AddParticipant;
import com.dsh.competition.model.EditParticipant;
import com.dsh.competition.model.ParticipantVo;
import com.dsh.competition.model.SaveParticipant;
import com.dsh.competition.service.IParticipantService;
import com.dsh.competition.service.UserCompetitionService;
import com.dsh.competition.util.JuHeUtil;
import com.dsh.competition.util.ResultUtil;
import com.dsh.competition.util.TokenUtil;
import com.dsh.competition.util.ToolUtil;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
 
import javax.annotation.Resource;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;
 
 
/**
 * @author zhibing.pu
 * @date 2023/7/7 9:43
 */
@RestController
@RequestMapping("")
public class ParticipantController {
 
    @Autowired
    private IParticipantService participantService;
 
    @Autowired
    private TokenUtil tokenUtil;
 
    @Resource
    private StudentClient studentClient;
 
    @Autowired
    private UserCompetitionService userCompetitionService;
 
 
 
 
 
    @ResponseBody
    @PostMapping("/api/participant/addParticipant")
    @ApiOperation(value = "添加参赛人员【2.0】", tags = {"APP-赛事活动列表", "人员管理"})
    @ApiImplicitParams({
            @ApiImplicitParam(name = "Authorization", value = "用户token(Bearer +token)", required = true, dataType = "String", paramType = "header", defaultValue = "Bearer eyJhbGciOiJIUzUxMiJ9.....")
    })
    public ResultUtil addParticipant(AddParticipant addParticipant) {
        try {
            Integer uid = tokenUtil.getUserIdFormRedis();
            if (null == uid) {
                return ResultUtil.tokenErr();
            }
            return participantService.addParticipant(uid, addParticipant);
        } catch (Exception e) {
            e.printStackTrace();
            return ResultUtil.runErr();
        }
    }
 
 
    @ResponseBody
    @PostMapping("/api/participant/queryParticipantList")
    @ApiOperation(value = "获取参赛人员列表", tags = {"APP-赛事活动列表", "我的二维码", "人员管理", "APP-社区世界杯"})
    @ApiImplicitParams({
            @ApiImplicitParam(name = "Authorization", value = "用户token(Bearer +token)", required = true, dataType = "String", paramType = "header", defaultValue = "Bearer eyJhbGciOiJIUzUxMiJ9....."),
    })
    public ResultUtil<List<ParticipantVo>> queryParticipantList() {
        try {
            Integer uid = tokenUtil.getUserIdFormRedis();
            if (null == uid) {
                return ResultUtil.tokenErr();
            }
            System.err.println("查询人员列表");
            List<ParticipantVo> participantVos = participantService.queryParticipantList(uid);
//            if (isPre != null) {
                List<ParticipantVo> filteredParticipants = new ArrayList<>();
 
                for (ParticipantVo participant : participantVos) {
//                    if (participant.getIdcard() != null && !participant.getIdcard().isEmpty()) {
                        filteredParticipants.add(participant);
//                    }
                }
            List<ParticipantVo> collect = filteredParticipants.stream().distinct().collect(Collectors.toList());
            return ResultUtil.success(collect);
//            }
 
//            return ResultUtil.success(participantVos);
        } catch (Exception e) {
            e.printStackTrace();
            return ResultUtil.runErr();
        }
    }
 
 
 
 
    @ResponseBody
    @PostMapping("/api/participant/editParticipant")
    @ApiOperation(value = "编辑参赛人员", tags = {"APP-赛事活动列表", "人员管理"})
    @ApiImplicitParams({
            @ApiImplicitParam(name = "Authorization", value = "用户token(Bearer +token)", required = true, dataType = "String", paramType = "header", defaultValue = "Bearer eyJhbGciOiJIUzUxMiJ9.....")
    })
    public ResultUtil editParticipant(EditParticipant editParticipant) {
        try {
            Integer uid = tokenUtil.getUserIdFormRedis();
            if (null == uid) {
                return ResultUtil.tokenErr();
            }
            if (null != editParticipant.getIsStudent() && 0 == editParticipant.getIsStudent()) {
                Participant byId = participantService.getById(editParticipant.getId());
                editParticipant.setName(byId.getName());
                return participantService.editParticipant(uid, editParticipant);
            } else {
                TStudent student = new TStudent();
                student.setId(editParticipant.getId());
                student.setName(editParticipant.getName());
                student.setIdCard(editParticipant.getIdcard());
                student.setHeadImg(editParticipant.getHeadImg());
                if (editParticipant.getHeight() != null) {
                    student.setHeight(Double.valueOf(editParticipant.getHeight()));
                }
                if (editParticipant.getWeight() != null) {
                    student.setWeight(editParticipant.getWeight());
                }
                if (ToolUtil.isNotEmpty(editParticipant.getName()) && ToolUtil.isNotEmpty(student.getIdCard())) {
                    Boolean aBoolean = JuHeUtil.idcardAuthentication(student.getIdCard(), student.getName());
                    if (!aBoolean) {
                        return ResultUtil.error("身份证和姓名不匹配");
                    }
                    // 根据身份证号获取生日
                    String birthday18 = extractBirthdayFromIdCard(student.getIdCard());
                    SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");
                    student.setBirthday(simpleDateFormat.parse(birthday18));
                }
                student.setPhone(editParticipant.getPhone());
                studentClient.updateAppUser(student);
                return ResultUtil.success();
            }
        } catch (Exception e) {
            e.printStackTrace();
            return ResultUtil.runErr();
        }
    }
    /**
     * 根据身份证号码提取生日
     * @param idCard 身份证号码
     * @return 生日字符串 YYYY-MM-DD格式
     */
    public static String extractBirthdayFromIdCard(String idCard) {
        if (idCard == null || idCard.isEmpty()) {
            return null;
        }
 
        String birthday;
        if (idCard.length() == 18) {
            // 18位身份证:截取第7-14位
            birthday = idCard.substring(6, 14);
        } else if (idCard.length() == 15) {
            // 15位身份证:截取第7-12位,并补上前缀"19"
            birthday = "19" + idCard.substring(6, 12);
        } else {
            return null;
        }
 
        // 格式化为YYYY-MM-DD格式
        return birthday.substring(0, 4) + "-" +
                birthday.substring(4, 6) + "-" +
                birthday.substring(6, 8);
    }
 
    @ResponseBody
    @PostMapping("/api/participant/delParticipant")
    @ApiOperation(value = "删除参赛人员", tags = {"APP-赛事活动列表", "人员管理"})
    @ApiImplicitParams({
            @ApiImplicitParam(name = "Authorization", value = "用户token(Bearer +token)", required = true, dataType = "String", paramType = "header", defaultValue = "Bearer eyJhbGciOiJIUzUxMiJ9.....")
    })
    public ResultUtil delParticipant(Integer id, Integer isStudent) {
        try {
            Integer uid = tokenUtil.getUserIdFormRedis();
            if (null == uid) {
                return ResultUtil.tokenErr();
            }
            return participantService.delParticipant(id, isStudent);
        } catch (Exception e) {
            e.printStackTrace();
            return ResultUtil.runErr();
        }
    }
 
 
    /**
     * 保存学员后同步参赛人员信息
     *
     * @param saveParticipant
     */
    @ResponseBody
    @PostMapping("/participant/saveParticipant")
    public void saveParticipant(@RequestBody SaveParticipant saveParticipant) {
        try {
            participantService.saveParticipant(saveParticipant);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
 
 
 
 
    @ResponseBody
    @PostMapping("/participant/counts")
    public Integer counts(@RequestBody Integer stuId) {
        return userCompetitionService.count(new QueryWrapper<UserCompetition>().eq("participantId", stuId));
    }
 
 
    @ResponseBody
    @PostMapping("/participant/getParticipant")
    public Participant getParticipant(@RequestBody Long id){
        return participantService.getById(id);
    }
}