nickchange
2023-11-17 a9564eae9f0169ca39329b2f14a8f13d13358a0a
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
package com.dsh.other.controller;
 
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.dsh.other.entity.HonorRules;
import com.dsh.other.feignclient.model.StuMedalVo;
import com.dsh.other.model.vo.honorVo.EditHonorVO;
import com.dsh.other.service.HonorRulesService;
import com.dsh.other.util.ResultUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
 
import java.util.*;
import java.util.stream.Collectors;
 
@RestController
@RequestMapping("")
public class HonorController {
 
    @Autowired
    private HonorRulesService hrService;
 
    /**
     * 获取 荣誉规则列表
     */
    @RequestMapping(value = "/base/honor/list")
    public Map<Integer, List<HonorRules>> getList() {
        List<HonorRules> list= hrService.getList();
        return list.stream().collect(Collectors.groupingBy(HonorRules::getType));
    }
 
    /**
     * 修改荣誉规则 并返回新的荣誉规则列表
     */
    @RequestMapping(value = "/base/honor/edit")
    @ResponseBody
    public Object edit(@RequestBody EditHonorVO vo) {
        Integer type1 = vo.getType1().getType();
        List<String> condition1 = vo.getType1().getCondition();
        QueryWrapper<HonorRules> wrapper1 = new QueryWrapper<>();
        wrapper1.eq("type",type1);
        List<HonorRules> list1 = hrService.list(wrapper1);
        for (int i = 0; i < list1.size(); i++) {
            list1.get(i).setCondition(Integer.valueOf(condition1.get(i)));
        }
        hrService.updateBatchById(list1);
 
        Integer type2 = vo.getType2().getType();
        List<String> condition2 = vo.getType2().getCondition();
        QueryWrapper<HonorRules> wrapper2 = new QueryWrapper<>();
        wrapper2.eq("type",type2);
        List<HonorRules> list2 = hrService.list(wrapper2);
        for (int i = 0; i < list1.size(); i++) {
            list2.get(i).setCondition(Integer.valueOf(condition2.get(i)));
        }
        hrService.updateBatchById(list2);
 
        Integer type3 = vo.getType3().getType();
        List<String> condition3 = vo.getType3().getCondition();
        QueryWrapper<HonorRules> wrapper3 = new QueryWrapper<>();
        wrapper3.eq("type",type3);
        List<HonorRules> list3 = hrService.list(wrapper3);
        for (int i = 0; i < list1.size(); i++) {
            list3.get(i).setCondition(Integer.valueOf(condition3.get(i)));
        }
        hrService.updateBatchById(list3);
 
        Integer type4 = vo.getType4().getType();
        List<String> condition4 = vo.getType4().getCondition();
        QueryWrapper<HonorRules> wrapper4 = new QueryWrapper<>();
        wrapper4.eq("type",type4);
        List<HonorRules> list4 = hrService.list(wrapper4);
        for (int i = 0; i < list1.size(); i++) {
            list4.get(i).setCondition(Integer.valueOf(condition4.get(i)));
        }
        hrService.updateBatchById(list4);
 
        return ResultUtil.success();
    }
 
    @Autowired
    private HonorRulesService honorRulesService;
    @PostMapping("/base/honor/getHonor")
    public HonorRules getHonor(@RequestBody List<Integer> integers){
//        HonorRules one = honorRulesService.getOne(new QueryWrapper<HonorRules>().eq("type", integers.get(0)).le("condition", String.valueOf(integers.get(1))).last("limit 1"));
        HonorRules one = honorRulesService.getOne(new QueryWrapper<HonorRules>()
                .eq("type", integers.get(0))
                .le("`condition`",integers.get(1)).orderByDesc("level")
                .last("LIMIT 1"));
 
        if (one ==null){
         HonorRules one1 = honorRulesService.getOne(new QueryWrapper<HonorRules>()
                    .eq("type", integers.get(0))
                    .eq("level",1)
                    .last("LIMIT 1"));
         return one1;
        }
 
        if (one.getLevel()==10){
            return one;
        }
        HonorRules one2 = honorRulesService.getOne(new QueryWrapper<HonorRules>().eq("type", integers.get(0)).eq("level", Integer.valueOf(one.getLevel()) + 1));
            return  one2;
    }
 
    @PostMapping("/base/honor/stuHonors")
    public List<StuMedalVo> getStuHonors(@RequestBody List<Integer> honorIds){
        List<StuMedalVo> stuMedalVos = new ArrayList<>();
        List<HonorRules> honorRules = hrService.querylistOfIds(honorIds);
 
 
 
        if (honorRules.size() > 0){
            honorRules.forEach(hrs -> {
                StuMedalVo stuMedalVo = new StuMedalVo();
                stuMedalVo.setLevelNum(Integer.getInteger(String.valueOf(hrs.getLevel())));
                stuMedalVo.setMedalType(hrs.getType());
                switch (hrs.getType()){
                    case 1:
                        stuMedalVo.setMedalName("俱乐部之星");
                        break;
                    case 2:
                        stuMedalVo.setMedalName("运动达人");
                        break;
                    case 3:
                        stuMedalVo.setMedalName("社区之王");
                        break;
                    case 4:
                        stuMedalVo.setMedalName("深度玩家");
                        break;
                    default:
                        break;
                }
                if (!Objects.equals(hrs.getLevel(), "10")){
                    stuMedalVo.setLevelNum(Integer.parseInt(String.valueOf(hrs.getLevel())));
                    stuMedalVo.setNextLevel(Integer.parseInt(String.valueOf(hrs.getLevel()))+1);
                    stuMedalVo.setUpgradeConditions(String.valueOf(hrs.getCondition()));
                    stuMedalVo.setIsTopLevel(2);
                }else {
                    stuMedalVo.setIsTopLevel(1);
                }
                stuMedalVos.add(stuMedalVo);
            });
        }
 
        return stuMedalVos;
    }
 
 
}