From e030255c23c7ba3e2cbad1036a810d6d72fa864f Mon Sep 17 00:00:00 2001
From: liujie <liujie>
Date: 星期四, 26 十月 2023 18:04:58 +0800
Subject: [PATCH] 修改bug

---
 cloud-server-other/src/main/java/com/dsh/other/controller/HonorController.java |   78 ++++++++++++++++++++++++++++++++++-----
 1 files changed, 68 insertions(+), 10 deletions(-)

diff --git a/cloud-server-other/src/main/java/com/dsh/other/controller/HonorController.java b/cloud-server-other/src/main/java/com/dsh/other/controller/HonorController.java
index f7b218a..39a8f85 100644
--- a/cloud-server-other/src/main/java/com/dsh/other/controller/HonorController.java
+++ b/cloud-server-other/src/main/java/com/dsh/other/controller/HonorController.java
@@ -1,18 +1,18 @@
 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.PostMapping;
-import org.springframework.web.bind.annotation.RequestBody;
-import org.springframework.web.bind.annotation.RequestMapping;
-import org.springframework.web.bind.annotation.RestController;
+import org.springframework.web.bind.annotation.*;
 
-import java.util.ArrayList;
-import java.util.List;
-import java.util.Objects;
+import java.util.*;
+import java.util.stream.Collectors;
 
 @RestController
 @RequestMapping("")
@@ -21,16 +21,73 @@
     @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));
+    }
 
-    @PostMapping("/honor/stuHonors")
+    /**
+     * 修改荣誉规则 并返回新的荣誉规则列表
+     */
+    @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.list(new QueryWrapper<HonorRules>()
-                .in("id", honorIds));
+        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("俱乐部之星");
@@ -48,6 +105,7 @@
                         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);

--
Gitblit v1.7.1