puzhibing
2024-02-05 640ff18d2d7f4be02ddb7f8f75e899f05545eb98
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
package com.dsh.account.service.impl;
 
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.dsh.account.entity.HonorRules;
import com.dsh.account.entity.StudentHonor;
import com.dsh.account.entity.TStudent;
import com.dsh.account.feignclient.competition.ParticipantClient;
import com.dsh.account.feignclient.course.CoursePackageClient;
import com.dsh.account.feignclient.course.model.CoursePackage;
import com.dsh.account.feignclient.other.HonorDeClient;
import com.dsh.account.feignclient.other.HonorRulesClient;
import com.dsh.account.feignclient.other.SiteClient;
import com.dsh.account.mapper.StudentHonorMapper;
import com.dsh.account.model.vo.medalDetail.GongVo;
import com.dsh.account.model.vo.medalDetail.StuMedalVo;
import com.dsh.account.service.StudentHonorService;
import com.dsh.account.service.TAppUserService;
import com.dsh.account.service.TStudentService;
import io.swagger.models.auth.In;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
 
import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;
 
/**
 * <p>
 * 学员-荣耀中间表 服务实现类
 * </p>
 *
 * @author jqs
 * @since 2023-07-04
 */
@Service
public class StudentHonorServiceImpl extends ServiceImpl<StudentHonorMapper, StudentHonor> implements StudentHonorService {
 
    @Resource
    private CoursePackageClient coursePackageClient;
 
    @Resource
    private ParticipantClient participantClient;
 
    @Resource
    private SiteClient siteClient;
 
    @Autowired
    private HonorDeClient honorDeClient;
 
    @Autowired
    private TStudentService studentService;
 
    @Autowired
    private HonorRulesClient honorRulesClient;
 
 
 
 
 
 
    @Override
    public List<GongVo> queryStuOfMedalData(Integer stuId) {
        List<GongVo> voList = new ArrayList<>();
//        List<StudentHonor> studentHonors = this.baseMapper.selectList(new QueryWrapper<StudentHonor>()
//                .eq("stuId", stuId));
//
        TStudent student = studentService.getById(stuId);
//
//
//        if (studentHonors.size() > 0){
//            studentHonors.forEach( stuoHo -> {
//                GongVo vo = new GongVo();
//                vo.setMedalType(stuoHo.getHonorType());
//                switch (stuoHo.getHonorType()){
//                    case 1:
//                        vo.setMedalName("俱乐部之星");
//                        break;
//                    case 2:
//                        vo.setMedalName("运动达人");
//                        break;
//                    case 3:
//                        vo.setMedalName("社区之王");
//                        break;
//                    case 4:
//                        vo.setMedalName("深度玩家");
//                        break;
//                    default:
//                        break;
//                }
//                voList.add(vo);
//            });
//        }
        Integer count1 = coursePackageClient.counts(stuId);
        if (count1 > 0) {
            GongVo vo = new GongVo();
            vo.setMedalType(1);
            vo.setMedalName("俱乐部之星");
            voList.add(vo);
        }
 
        Integer count2 = participantClient.counts(stuId);
        if (count2 > 0) {
            GongVo vo = new GongVo();
            vo.setMedalType(2);
            vo.setMedalName("运动达人");
            voList.add(vo);
        }
 
        Integer count3 = siteClient.counts(student.getAppUserId());
        if (count3 > 0) {
            GongVo vo = new GongVo();
            vo.setMedalType(3);
            vo.setMedalName("社区之王");
            voList.add(vo);
        }
 
 
        Integer count4 = coursePackageClient.counts1(stuId);
        if (count4 > 0) {
            GongVo vo = new GongVo();
            vo.setMedalType(4);
            vo.setMedalName("深度玩家");
            voList.add(vo);
        }
 
 
        return voList;
    }
 
 
    @Override
    public List<StuMedalVo> queryHonorDetails(Integer appUserId) {
        List<StuMedalVo> list = new ArrayList<>();
        List<StudentHonor> studentHonors = this.list(new QueryWrapper<StudentHonor>().eq("appUserId", appUserId));
        for (StudentHonor studentHonor : studentHonors) {
            StuMedalVo vo = new StuMedalVo();
            vo.setMedalType(studentHonor.getHonorType());
            switch (studentHonor.getHonorType()){
                case 1:
                    vo.setMedalName("俱乐部之星");
                    break;
                case 2:
                    vo.setMedalName("运动达人");
                    break;
                case 3:
                    vo.setMedalName("社区之王");
                    break;
                case 4:
                    vo.setMedalName("深度玩家");
                    break;
            }
            //拿到当前对应的rule对象
            List<Integer> integers = new ArrayList<>();
            integers.add(studentHonor.getHonorType());
            integers.add(studentHonor.getNumber());
            HonorRules honorRules = honorDeClient.getHonor(integers);
            if (studentHonor.getNumber() < Integer.valueOf(honorRules.getCondition())) {
                vo.setLevelNum(Integer.valueOf(honorRules.getLevel()) - 1);
                vo.setNextLevel(Integer.valueOf(honorRules.getLevel()));
                vo.setUpgradeConditions(String.valueOf(Integer.valueOf(honorRules.getCondition()) - studentHonor.getNumber()));
                vo.setIsTopLevel(0);
            } else {
                vo.setIsTopLevel(1);
            }
            list.add(vo);
        }
        return list;
    }
}