按数值排序

This commit is contained in:
周源 2021-08-03 14:45:46 +08:00
parent b43f72c5e1
commit 7a52d87558
2 changed files with 53 additions and 12 deletions

View File

@ -28,10 +28,8 @@ import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import java.text.DecimalFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.Iterator;
import java.util.List;
import java.util.*;
import java.util.stream.Collectors;
@RestController
@RequestMapping("/api/statistics/office")
@ -113,9 +111,27 @@ public class ApiStatisticsOfficeController extends ApiBaseController {
String countryStr = config.getParamValue();
String countStr = config.getRemarks();
if (StrUtil.isNotBlank(countryStr) && StrUtil.isNotBlank(countStr)) {
String[] countryArr = countryStr.split(",");
String[] countArr = countStr.split(",");
Dict dict = Dict.create().set("countryArr", countryArr).set("countArr", countArr);
List<Map> list = new ArrayList<>();
List<String> regionList = Arrays.asList(config.getParamValue().split(","));
List<String> regionNumList = Arrays.asList(config.getRemarks().split(","));
for (int i = 0; i < regionList.size(); i++) {
Map<String, Object> map = new HashMap<>();
map.put("region", regionList.get(i));
map.put("regionNum", regionNumList.get(i));
list.add(map);
}
List<Map> sortedList = list.stream().sorted((t1, t2) -> {
int result = Convert.toInt(t2.get("regionNum")) - Convert.toInt(t1.get("regionNum"));
return result;
}).collect(Collectors.toList());
List<Object> sortedRegionList = new ArrayList<>();
List<Object> sortedRegionNumList = new ArrayList<>();
sortedList.forEach(item -> {
sortedRegionList.add(item.get("region"));
sortedRegionNumList.add(item.get("regionNum"));
});
Dict dict = Dict.create().set("countryArr", sortedRegionList).set("countArr", sortedRegionNumList);
render(Ret.ok().data(dict));
}
}

View File

@ -1,6 +1,7 @@
package com.ydool.boot.modules.rddb.web;
import cn.hutool.core.convert.Convert;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.ydool.boot.common.cache.SysCacheName;
import com.ydool.boot.common.result.Ret;
@ -20,6 +21,9 @@ import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import java.util.*;
import java.util.stream.Collectors;
/**
* <p>
* 文件审批 前端控制器
@ -81,9 +85,30 @@ public class ShowController extends BaseAdminController {
@GetMapping("office")
public String office(Model model) {
List<Map> list = new ArrayList<>();
Config config = getConfigByCode("screen_office_country_rank");
model.addAttribute("region", config.getParamValue().split(","));
model.addAttribute("regionNum", config.getRemarks().split(","));
List<String> regionList = Arrays.asList(config.getParamValue().split(","));
List<String> regionNumList = Arrays.asList(config.getRemarks().split(","));
for (int i = 0; i < regionList.size(); i++) {
Map<String, Object> map = new HashMap<>();
map.put("region", regionList.get(i));
map.put("regionNum", regionNumList.get(i));
list.add(map);
}
List<Map> sortedList = list.stream().sorted((t1, t2) -> {
int result = Convert.toInt(t2.get("regionNum")) - Convert.toInt(t1.get("regionNum"));
return result;
}).collect(Collectors.toList());
List<Object> sortedRegionList = new ArrayList<>();
List<Object> sortedRegionNumList = new ArrayList<>();
sortedList.forEach(item->{
sortedRegionList.add(item.get("region"));
sortedRegionNumList.add(item.get("regionNum"));
});
model.addAttribute("region", sortedRegionList);
model.addAttribute("regionNum", sortedRegionNumList);
return "modules/rddb/show/office.html";
}
@ -108,7 +133,7 @@ public class ShowController extends BaseAdminController {
boolean flag4 = configService.updateById(cycleRateConfig);
boolean flag5 = configService.updateById(sameRateConfig);
CacheUtils.clear(SysCacheName.SYS_DICT_CACHE);
CacheUtils.clear(SysCacheName.SYS_CONFIG_CACHE);
render((flag1 && flag2 && flag3 && flag4 && flag5) ? Ret.ok() : Ret.fail("操作失败"));
}
@ -142,7 +167,7 @@ public class ShowController extends BaseAdminController {
boolean flag7 = configService.updateById(handleAnalyzeConfig);
boolean flag8 = configService.updateById(handleAnalyzeStatusConfig);
CacheUtils.clear(SysCacheName.SYS_DICT_CACHE);
CacheUtils.clear(SysCacheName.SYS_CONFIG_CACHE);
render((flag1 && flag2 && flag3 && flag4 && flag5 && flag6 && flag7 && flag8) ? Ret.ok() : Ret.fail("操作失败"));
}
@ -155,7 +180,7 @@ public class ShowController extends BaseAdminController {
config.setRemarks(showOfficeBo.getRegionNum());
boolean flag = configService.updateById(config);
CacheUtils.clear(SysCacheName.SYS_DICT_CACHE);
CacheUtils.clear(SysCacheName.SYS_CONFIG_CACHE);
render(flag ? Ret.ok() : Ret.fail("操作失败"));
}