liujie
2023-09-28 f0f6bd6f7499d1fa737f705091337befb98f5112
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
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(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(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(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(condition4.get(i));
        }
        hrService.updateBatchById(list4);
 
        return ResultUtil.success();
    }
 
    @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(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(hrs.getLevel()));
                    stuMedalVo.setNextLevel(Integer.parseInt(hrs.getLevel())+1);
                    stuMedalVo.setUpgradeConditions(hrs.getCondition());
                    stuMedalVo.setIsTopLevel(2);
                }else {
                    stuMedalVo.setIsTopLevel(1);
                }
                stuMedalVos.add(stuMedalVo);
            });
        }
 
        return stuMedalVos;
    }
 
 
}