1、修改组件使用情况统计的查询方法

This commit is contained in:
yitonglei 2022-06-28 10:33:09 +08:00
parent 9f704ea01d
commit ceb9c747e2
5 changed files with 54 additions and 24 deletions

View File

@ -335,23 +335,13 @@ public class CensusControllerV3 {
@GetMapping("/applicationUsedCapabilityNum")
@ApiOperation("贡献组件分别被多少应用使用")
@LogOperation("贡献组件分别被多少应用使用")
@ApiImplicitParams({
@ApiImplicitParam(name = "id", value = "部门id", paramType = "query", required = true, dataType = "long"),
@ApiImplicitParam(name = "resourceType",value = "资源类型(组件服务、应用资源、基础设施、数据资源、知识库)", paramType = "query", dataType = "String")
})
public Result<List<Map<String,Object>>> applicationUsedCapabilityNum(@ApiIgnore @RequestParam Map<String, Object> params){
List<Map<String,Object>> result = new ArrayList<>();
Object[] ps = {params.get("resourceType"),params.get("id")};
result = jdbcTemplate.queryForList("SELECT a.name,b.attr_value FROM tb_data_resource a INNER JOIN tb_data_attr b \n" +
"ON a.id = b.data_resource_id\n" +
"WHERE a.type = ? and a.dept_id = ?\n" +
"and b.attr_type = '应用领域'",ps);
result.forEach(r->{
String[] strArr = r.get("attr_value").toString().split(",");
r.put("usedNum",strArr.length);
});
@ApiImplicitParam(name = "keyId", value = "应用id", paramType = "query", required = true, dataType = "long")
public Result<List<Map<String,Object>>> applicationUsedCapabilityNum(Long keyId){
Object[] ps = {keyId};
List<Map<String, Object>> maps = jdbcTemplate.queryForList("select count(b.id) as useNum,c.name from (select reference_id from tb_data_resource_rel where del_flag = 0 and key_id = ? ) a inner join tb_data_resource_rel b on a.reference_id = b.reference_id inner join tb_data_resource c\n" +
"on a.reference_id = c.id where c.del_flag = 0 group by c.name", ps);
return new Result<List<Map<String,Object>>>().ok(result);
return new Result<List<Map<String,Object>>>().ok(maps);
}
//以下是基础设施和数据资源使用情况点击详情申请明细

View File

@ -122,4 +122,6 @@ public interface ResourceDao extends BaseDao<ResourceEntity> {
List<Map<String,Object>> applicationAreaCapabilityList(Map params);
List<Map<String,Object>> applicationUsedAreaCapabilityList(Map params);
List<Map<String,Object>> applicationAreaCapabilityUseList(Map params);
Map<String,Object> assemblyCarByDept(Map params);
Map<String,Object> assemblyUseByDept(Map params);
}

View File

@ -104,4 +104,5 @@ public interface ResourceService extends CrudService<ResourceEntity, ResourceDTO
List<Map<String, Object>> applicationAreaCapabilityList(Map params);
List<Map<String, Object>> applicationAreaCapabilityUseList(Map params);
}

View File

@ -1174,15 +1174,43 @@ public class ResourceServiceImpl extends CrudServiceImpl<ResourceDao, ResourceEn
// }
@Override
public List<Map<String, Object>> resourceBusinessUseDetails(Map<String, Object> params) {
List<Map<String, Object>> result = new CopyOnWriteArrayList<>();
params.put("pageNum", (Integer.parseInt(params.get("page").toString()) - 1) * Integer.parseInt(params.get("limit").toString()));
params.put("pageSize", params.get("limit"));
result = baseDao.selectResurceCarDetails(params);
List<Map<String, Object>> maps = new CopyOnWriteArrayList<>();
Object[] ps = {params.get("id"),params.get("id"),(Integer.parseInt(params.get("page").toString()) - 1) * Integer.parseInt(params.get("limit").toString()),Integer.parseInt(params.get("limit").toString())};
//获取部门列表
List<Map<String,Object>> list = jdbcTemplate.queryForList("SELECT id,name FROM sys_dept WHERE id = ? OR INSTR(pids,?) LIMIT ?,?",ps);
maps.addAll(list);
//分别根据部门获取应用组件数和收藏组件数
Map<String,Object> paraMap = new ConcurrentHashMap<>();
paraMap.put("resourceType",params.get("resourceType"));
CompletableFuture<Void> voidCompletableFuture01 = CompletableFuture.runAsync(() -> {
maps.forEach(m -> {
paraMap.put("id", m.get("id"));
Map<String, Object> maps1 = new HashMap<>();
maps1 = baseDao.assemblyCarByDept(paraMap);
if(maps1==null){
m.put("carNum",0);
}else{
m.put("carNum", maps1.get("carNum") == null ? 0:maps1.get("carNum"));
}
});
});
//还缺少调用总数
//CompletableFuture<Void> all = CompletableFuture.allOf(resourceCarNums);
//all.join();
return result;
CompletableFuture<Void> voidCompletableFuture02 = CompletableFuture.runAsync(() -> {
maps.forEach(m -> {
paraMap.put("id", m.get("id"));
Map<String, Object> maps2 = new HashMap<>();
maps2 = baseDao.assemblyUseByDept(paraMap);
if(maps2==null){
m.put("useNum",0);
}else{
m.put("useNum", maps2.get("useNum") == null ? 0 : maps2.get("useNum"));
}
});
});
CompletableFuture<Void> all = CompletableFuture.allOf(voidCompletableFuture01, voidCompletableFuture02);
all.join();
return maps;
}
@Override

View File

@ -1146,5 +1146,14 @@
LIMIT ${pageNum}, ${pageSize}
</select>
<select id = "assemblyCarByDept" parameterType="java.util.Map" resultType="java.util.Map">
SELECT COUNT(distinct(a.resource_id)) as carNum,c.id FROM tb_resource_car a INNER JOIN sys_user b ON a.creator = b.id INNER JOIN sys_dept c ON b.dept_id = c.id INNER JOIN tb_data_resource d on a.resource_id = d.id
WHERE a.del_flag = 0 AND d.type = #{resourceType} AND (c.id =#{id} or INSTR(c.pids,#{id})) group by c.id
</select>
<select id = "assemblyUseByDept" parameterType="java.util.Map" resultType="java.util.Map">
SELECT COUNT(distinct(a.key_id)) as useNum,c.id FROM tb_data_resource_rel a INNER JOIN sys_user b ON a.creator = b.id INNER JOIN sys_dept c ON b.dept_id = c.id INNER JOIN tb_data_resource d on a.key_id = d.id
WHERE a.del_flag = 0 AND d.type = #{resourceType} AND (c.id = #{id} or INSTR(c.pids,#{id} )) group by c.id
</select>
</mapper>