区市、委办局 两类应用资源排名接口
This commit is contained in:
parent
46de17be45
commit
593516266a
|
@ -2,11 +2,14 @@ package io.renren.common.controller;
|
|||
|
||||
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import io.renren.common.annotation.LogOperation;
|
||||
import io.renren.common.utils.Result;
|
||||
import io.renren.modules.processForm.service.TAbilityApplicationService;
|
||||
import io.renren.modules.resource.service.ResourceService;
|
||||
import io.renren.modules.resourceBrowse.service.ResourceBrowseService;
|
||||
import io.renren.modules.sys.dto.SysDeptDTO;
|
||||
import io.renren.modules.sys.service.SysDeptService;
|
||||
import io.renren.modules.sys.service.SysUserService;
|
||||
import io.swagger.annotations.Api;
|
||||
|
@ -138,10 +141,23 @@ public class CensusControllerV2 {
|
|||
|
||||
@GetMapping("/districtResourceRank")
|
||||
@ApiOperation("应用资源区县市排名")
|
||||
@LogOperation("应用资源数量统计")
|
||||
@LogOperation("应用资源区县市排名")
|
||||
public Result<List<Map<String, Object>>> districtResourceRank() {
|
||||
List<Map<String, Object>> result = resourceRank(3);
|
||||
return new Result().ok(result);
|
||||
}
|
||||
|
||||
@GetMapping("/cityResourceRank")
|
||||
@ApiOperation("应用资源委办局排名")
|
||||
@LogOperation("应用资源委办局排名")
|
||||
public Result<List<Map<String, Object>>> cityResourceRank() {
|
||||
List<Map<String, Object>> result = resourceRank(2);
|
||||
return new Result().ok(result);
|
||||
}
|
||||
|
||||
private List<Map<String, Object>> resourceRank(Integer type) {
|
||||
List<Map<String, Object>> result = Collections.synchronizedList(new ArrayList<>());
|
||||
List<Map<String, Object>> district = jdbcTemplate.queryForList("SELECT * FROM sys_dept WHERE type = 2");
|
||||
List<Map<String, Object>> district = jdbcTemplate.queryForList("SELECT * FROM sys_dept WHERE type = " + type);
|
||||
List<Map<String, Long>> listMap =
|
||||
district.stream().map(index -> {
|
||||
Map<String, Long> re = new LinkedHashMap<>();
|
||||
|
@ -149,22 +165,37 @@ public class CensusControllerV2 {
|
|||
logger.info(sql);
|
||||
Long count = jdbcTemplate.queryForObject(sql, Long.class);
|
||||
if (!"0".equals(index.get("pid").toString())) { // 有上级部门
|
||||
re.put(index.get("pid").toString(), count);
|
||||
Optional<SysDeptDTO> sysDeptDTO =
|
||||
Optional.ofNullable(sysDeptService.get(Long.valueOf(index.get("pid").toString())));
|
||||
if (sysDeptDTO.isPresent() && sysDeptDTO.get().getType() != null && sysDeptDTO.get().getType() >= 2) {
|
||||
re.put(index.get("id").toString(), count);
|
||||
} else {
|
||||
re.put(index.get("pid").toString(), count);
|
||||
}
|
||||
} else {
|
||||
re.put(index.get("id").toString(), count);
|
||||
}
|
||||
return re;
|
||||
}).distinct().collect(Collectors.toList());
|
||||
}).collect(Collectors.toList());
|
||||
Map<String, List<Map<String, Long>>> i =
|
||||
listMap.stream().collect(Collectors.groupingBy(m -> m.keySet().stream().findFirst().toString()));
|
||||
listMap.stream().collect(Collectors.groupingBy(m -> m.keySet().stream().findFirst().get()));
|
||||
result = i.keySet().stream().map(index -> {
|
||||
Map<String, Object> re = new LinkedHashMap<>();
|
||||
re.put("deptId", index);
|
||||
re.put("deptName", sysDeptService.get(Long.valueOf(index)).getName());
|
||||
re.put("count", i.get(index).stream().mapToLong(index_ -> index_.values().stream().mapToLong(count_ -> count_).sum()).sum());
|
||||
return re;
|
||||
}).collect(Collectors.toList());
|
||||
|
||||
return new Result().ok(result);
|
||||
result.sort(Comparator.comparing(x -> {
|
||||
ObjectMapper mapper = new ObjectMapper();
|
||||
try {
|
||||
Map m = mapper.readValue(mapper.writeValueAsString(x), Map.class);
|
||||
return Long.valueOf(m.get("count").toString());
|
||||
} catch (JsonProcessingException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
).reversed());
|
||||
return result;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue