新加一个统计控制器
This commit is contained in:
parent
089e507426
commit
8138361207
|
@ -1,6 +1,8 @@
|
|||
package io.renren.common.controller;
|
||||
|
||||
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
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;
|
||||
|
@ -13,12 +15,12 @@ import org.slf4j.Logger;
|
|||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
import org.springframework.jdbc.core.JdbcTemplate;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
|
||||
/**
|
||||
|
@ -41,6 +43,9 @@ public class CensusControllerV2 {
|
|||
@Autowired
|
||||
private SysDeptService sysDeptService;
|
||||
|
||||
@Autowired
|
||||
private JdbcTemplate jdbcTemplate;
|
||||
|
||||
@Value("${census.type}")
|
||||
private String[] censusTypes; // 需要进行统计的资源类型
|
||||
|
||||
|
@ -76,7 +81,80 @@ public class CensusControllerV2 {
|
|||
return new Result<List<Map<String, Object>>>().ok(result);
|
||||
}
|
||||
|
||||
public Result<List<Map<String, Object>>> visitTrend() {
|
||||
return null;
|
||||
@PostMapping("/trafficStatistics")
|
||||
@ApiOperation("浏览量统计")
|
||||
@LogOperation("浏览量统计")
|
||||
public Result trafficStatistics(@RequestBody JSONObject jsonObject) {
|
||||
HashMap<String, Object> resultMap = new HashMap<>();
|
||||
String startDate = jsonObject.getString("startDate");
|
||||
String endDate = jsonObject.getString("endDate");
|
||||
resultMap.put("browseAvg", resourceBrowseService.selectDayAvg());
|
||||
resultMap.put("browseMax", resourceBrowseService.selectDayMax());
|
||||
resultMap.put("browseDayList", resourceBrowseService.selectDayList(startDate, endDate));
|
||||
return new Result().ok(resultMap);
|
||||
}
|
||||
|
||||
|
||||
@GetMapping("/applicationNum")
|
||||
@ApiOperation("应用资源数量统计")
|
||||
@LogOperation("应用资源数量统计")
|
||||
public Result<List<Map<String, Object>>> applicationNum() {
|
||||
List<Map<String, Object>> result = Collections.synchronizedList(new ArrayList<>());
|
||||
|
||||
CompletableFuture<Void> allApplicationAmount = CompletableFuture.supplyAsync(() -> { // 获取平台总应用数目
|
||||
return jdbcTemplate.queryForObject("SELECT COUNT(id) FROM tb_data_resource WHERE type ='应用资源';", Long.class);
|
||||
}).thenAccept(sum -> {
|
||||
result.add(new HashMap<String, Object>() {
|
||||
{
|
||||
put("amount", sum);
|
||||
put("type", "总应用数");
|
||||
}
|
||||
});
|
||||
});
|
||||
CompletableFuture<Void> buildingApplicationAmount = CompletableFuture.supplyAsync(() -> { // 获取平台建设中数目
|
||||
return jdbcTemplate.queryForObject("SELECT COUNT(DISTINCT data_resource_id) FROM tb_data_attr WHERE attr_type = '应用状态' AND attr_value = '建设中';", Long.class);
|
||||
}).thenAccept(sum -> {
|
||||
result.add(new HashMap<String, Object>() {
|
||||
{
|
||||
put("amount", sum);
|
||||
put("type", "建设中应用数");
|
||||
}
|
||||
});
|
||||
});
|
||||
CompletableFuture<Void> endApplicationAmount = CompletableFuture.supplyAsync(() -> { // 获取平台建设中数目
|
||||
return jdbcTemplate.queryForObject("SELECT COUNT(DISTINCT data_resource_id) FROM tb_data_attr WHERE attr_type = '应用状态' AND attr_value = '停用';", Long.class);
|
||||
}).thenAccept(sum -> {
|
||||
result.add(new HashMap<String, Object>() {
|
||||
{
|
||||
put("amount", sum);
|
||||
put("type", "停用应用数");
|
||||
}
|
||||
});
|
||||
});
|
||||
CompletableFuture<Void> all = CompletableFuture.allOf(allApplicationAmount, buildingApplicationAmount, endApplicationAmount);
|
||||
all.join();
|
||||
return new Result().ok(result);
|
||||
}
|
||||
|
||||
@GetMapping("/applicationNum")
|
||||
@ApiOperation("应用资源区县市排名")
|
||||
@LogOperation("应用资源数量统计")
|
||||
public Result<List<Map<String, Object>>> districtResourceRank() {
|
||||
List<Map<String, Object>> result = Collections.synchronizedList(new ArrayList<>());
|
||||
List<Map<String, Object>> district = jdbcTemplate.queryForList("SELECT * FROM sys_dept WHERE type = 2");
|
||||
// Map<String, List<Map<String, Object>>> listMap
|
||||
// =
|
||||
district.stream().map(index -> {
|
||||
Map<String, Long> re = new LinkedHashMap<>();
|
||||
Long count = jdbcTemplate.queryForObject(String.format("SELECT COUNT(id) FROM tb_data_resource WHERE dept_id = %s AND type = '应用资源' AND del_flag = 0;", index.get("id").toString()), Long.class);
|
||||
if (!"0".equals(index.get("pid").toString())) { // 有上级部门
|
||||
re.put(index.get("pid").toString(), count);
|
||||
} else {
|
||||
re.put(index.get("id").toString(), count);
|
||||
}
|
||||
return re;
|
||||
}).distinct().collect(Collectors.groupingBy(m -> m.keySet().stream().findFirst().get()));
|
||||
return new Result().ok(result);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue