nickchange
2023-11-09 c036557db88c6297b9a626a892dce35c14ab8ee5
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
package com.dsh.competition.controller;
 
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
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.ResultUtil;
import com.dsh.competition.util.TokenUtil;
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.util.ArrayList;
import java.util.List;
 
 
/**
 * @author zhibing.pu
 * @date 2023/7/7 9:43
 */
@RestController
@RequestMapping("")
public class ParticipantController {
 
    @Autowired
    private IParticipantService participantService;
 
    @Autowired
    private TokenUtil tokenUtil;
 
 
 
 
    @ResponseBody
    @PostMapping("/api/participant/addParticipant")
    @ApiOperation(value = "添加参赛人员", 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-赛事活动列表", ""})
    @ApiImplicitParams({
            @ApiImplicitParam(name = "Authorization", value = "用户token(Bearer +token)", required = true, dataType = "String", paramType = "header", defaultValue = "Bearer eyJhbGciOiJIUzUxMiJ9....."),
            @ApiImplicitParam(value = "isPre(1过滤)", name = "是否过滤未实名", required = true, dataType = "int")
    })
    public ResultUtil<List<ParticipantVo>> queryParticipantList(Integer isPre){
        try {
            Integer uid = tokenUtil.getUserIdFormRedis();
            if(null == uid){
                return ResultUtil.tokenErr();
            }
            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);
                    }
                }
            return ResultUtil.success(filteredParticipants);
            }
 
            return ResultUtil.success(participantVos);
        }catch (Exception e){
            e.printStackTrace();
            return ResultUtil.runErr();
        }
    }
 
 
 
 
   @Resource
   private StudentClient studentClient;
 
    @Resource
    private AppUserClient appUserClient;
    @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();
            }
            int numDigits = String.valueOf(editParticipant.getId()).length();
 
 
 
            if (numDigits==9){
            return participantService.editParticipant(uid, editParticipant);
            }
            else {
 
 
                TStudent student = new TStudent();
                student.setId(editParticipant.getId());
                student.setName(editParticipant.getName());
                student.setIdCard(editParticipant.getIdcard());
                student.setHeight(Double.valueOf(editParticipant.getHeight()));
                student.setWeight(editParticipant.getWeight());
                student.setPhone(editParticipant.getPhone());
                studentClient.updateAppUser(student);
                return ResultUtil.success();
            }
        }catch (Exception e){
            e.printStackTrace();
            return ResultUtil.runErr();
        }
    }
 
 
 
    @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){
        try {
            Integer uid = tokenUtil.getUserIdFormRedis();
            if(null == uid){
                return ResultUtil.tokenErr();
            }
            return participantService.delParticipant(id);
        }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();
        }
    }
 
    @Autowired
    private UserCompetitionService userCompetitionService;
 
 
    @ResponseBody
    @PostMapping("/participant/counts")
    public Integer counts(@RequestBody Integer stuId){
       return userCompetitionService.count(new QueryWrapper<UserCompetition>().eq("participantId",stuId));
    }
}