diff --git a/renren-admin/src/main/java/io/renren/common/controller/CensusController.java b/renren-admin/src/main/java/io/renren/common/controller/CensusController.java new file mode 100644 index 00000000..42eac9cd --- /dev/null +++ b/renren-admin/src/main/java/io/renren/common/controller/CensusController.java @@ -0,0 +1,68 @@ +package io.renren.common.controller; + + +import io.renren.common.utils.Result; +import io.renren.modules.resource.service.ResourceService; +import io.swagger.annotations.Api; +import io.swagger.annotations.ApiOperation; +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 java.util.Arrays; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.stream.Collectors; + +/** + * 统计 + */ +@Api(tags = "全局统计中心") +@RestController +@RequestMapping("/census/center") +public class CensusController { + + private static Logger logger = LoggerFactory.getLogger(CensusController.class); + + @Autowired + private ResourceService resourceService; + + @Value("${census.type}") + private String[] censusTypes; // 大数据局名称 + + + /** + * 获取各类资源数目 + * + * @return + */ + @GetMapping(value = "/resource_amount") + @ApiOperation("各类资源数目") + public Result>> resourceAmount() { + List> dbAmount = resourceService.getAmountGroupByType(); + List temp = dbAmount.stream().map(index -> index.get("type").toString()).collect(Collectors.toList()); + Arrays.stream(censusTypes).filter(index -> !temp.contains(index)).forEach(index -> { // 数据库内不存在的资源类型 + Map nullMap = new HashMap() { + { + put("amount", 0); + put("type", index); + } + }; + dbAmount.add(nullMap); + }); + Long sum = dbAmount.stream().mapToLong(index -> Long.valueOf(index.get("amount").toString())).sum(); + Map sumMap = new HashMap() { + { + put("amount", sum); + put("type", "资源汇聚总量"); + } + }; + dbAmount.add(sumMap); + return new Result>>().ok(dbAmount); + } +} diff --git a/renren-admin/src/main/java/io/renren/modules/activiti/service/ActHistoryService.java b/renren-admin/src/main/java/io/renren/modules/activiti/service/ActHistoryService.java index 4604ead3..82c3af1c 100644 --- a/renren-admin/src/main/java/io/renren/modules/activiti/service/ActHistoryService.java +++ b/renren-admin/src/main/java/io/renren/modules/activiti/service/ActHistoryService.java @@ -6,6 +6,8 @@ import io.renren.modules.activiti.dto.ProcessInstanceDTO; import io.renren.modules.activiti.dto.TaskDTO; import io.renren.modules.processForm.dto.TAbilityApplicationDTO; import io.renren.modules.processForm.service.TAbilityApplicationService; +import io.renren.modules.resource.dto.ResourceDTO; +import io.renren.modules.resource.service.ResourceService; import io.renren.modules.resourceMountApply.dto.TResourceMountApplyDTO; import io.renren.modules.resourceMountApply.service.TResourceMountApplyService; import io.renren.modules.security.user.SecurityUser; @@ -72,6 +74,8 @@ public class ActHistoryService { @Autowired private SysUserService sysUserService; + @Autowired + private ResourceService resourceService; @Autowired private TAbilityApplicationService tAbilityApplicationService; @@ -267,6 +271,12 @@ public class ActHistoryService { if (resourceMountApplyDTO != null) { dto.setName(resourceMountApplyDTO.getResourceDTO().getName()); dto.setResourceId(resourceMountApplyDTO.getResourceDTO().getId().toString()); + } else { + ResourceDTO resourceDTO = resourceService.get(Long.valueOf(dto.getBusinessKey())); + if (resourceDTO != null) { + dto.setName(resourceDTO.getName()); + dto.setResourceId(resourceDTO.getId().toString()); + } } } } diff --git a/renren-admin/src/main/java/io/renren/modules/resource/dao/ResourceDao.java b/renren-admin/src/main/java/io/renren/modules/resource/dao/ResourceDao.java index df9d23b0..f2da6ec5 100644 --- a/renren-admin/src/main/java/io/renren/modules/resource/dao/ResourceDao.java +++ b/renren-admin/src/main/java/io/renren/modules/resource/dao/ResourceDao.java @@ -3,6 +3,7 @@ package io.renren.modules.resource.dao; import io.renren.common.dao.BaseDao; import io.renren.modules.resource.dto.ResourceDTO; import io.renren.modules.resource.entity.ResourceEntity; +import org.apache.ibatis.annotations.MapKey; import org.apache.ibatis.annotations.Mapper; import org.apache.ibatis.annotations.Param; @@ -10,11 +11,11 @@ import java.util.List; import java.util.Map; /** -* 资源表 -* -* @author dg -* @since 1.0 2022-04-13 -*/ + * 资源表 + * + * @author dg + * @since 1.0 2022-04-13 + */ @Mapper public interface ResourceDao extends BaseDao { @@ -28,13 +29,21 @@ public interface ResourceDao extends BaseDao { List selectMostPopular(Map selectMap); - ResourceDTO selectDTOById(@Param("id") Long id,@Param("userId") Long userId); + ResourceDTO selectDTOById(@Param("id") Long id, @Param("userId") Long userId); - List selectDTOPage(@Param("dto")ResourceDTO resourceDTO, + List selectDTOPage(@Param("dto") ResourceDTO resourceDTO, @Param("pageNum") Integer pageNum, @Param("pageSize") Integer pageSize, - @Param("orderField")String orderField, + @Param("orderField") String orderField, @Param("orderType") String orderType); List selectApplyArea(Long userId); + + /** + * 获取各类资源数目 + * + * @return + */ + @MapKey("type") + List> getAmountGroupByType(); } \ No newline at end of file diff --git a/renren-admin/src/main/java/io/renren/modules/resource/service/ResourceService.java b/renren-admin/src/main/java/io/renren/modules/resource/service/ResourceService.java index 38bb0a81..b9a31045 100644 --- a/renren-admin/src/main/java/io/renren/modules/resource/service/ResourceService.java +++ b/renren-admin/src/main/java/io/renren/modules/resource/service/ResourceService.java @@ -7,11 +7,12 @@ import io.renren.modules.resource.entity.AttrEntity; import io.renren.modules.resource.entity.ResourceEntity; import java.util.List; +import java.util.Map; /** * 资源表 * - * @author dg + * @author dg * @since 1.0 2022-04-13 */ public interface ResourceService extends CrudService { @@ -38,4 +39,5 @@ public interface ResourceService extends CrudService> getAmountGroupByType(); } \ No newline at end of file diff --git a/renren-admin/src/main/java/io/renren/modules/resource/service/impl/ResourceServiceImpl.java b/renren-admin/src/main/java/io/renren/modules/resource/service/impl/ResourceServiceImpl.java index 84be6859..479bfe96 100644 --- a/renren-admin/src/main/java/io/renren/modules/resource/service/impl/ResourceServiceImpl.java +++ b/renren-admin/src/main/java/io/renren/modules/resource/service/impl/ResourceServiceImpl.java @@ -251,4 +251,10 @@ public class ResourceServiceImpl extends CrudServiceImpl> getAmountGroupByType() { + List> amountInfo = resourceDao.getAmountGroupByType(); + return amountInfo; + } } \ No newline at end of file diff --git a/renren-admin/src/main/java/io/renren/modules/security/config/ShiroConfig.java b/renren-admin/src/main/java/io/renren/modules/security/config/ShiroConfig.java index c07aa65d..9c6b1a12 100644 --- a/renren-admin/src/main/java/io/renren/modules/security/config/ShiroConfig.java +++ b/renren-admin/src/main/java/io/renren/modules/security/config/ShiroConfig.java @@ -77,6 +77,7 @@ public class ShiroConfig { */ filterMap.put("/upload", "anon"); filterMap.put("/upload/**", "anon"); + filterMap.put("/census/center/**", "anon"); // 全局各类统计 filterMap.put("/**", "oauth2"); shiroFilter.setFilterChainDefinitionMap(filterMap); diff --git a/renren-admin/src/main/java/io/renren/modules/sys/dao/SysUserDao.java b/renren-admin/src/main/java/io/renren/modules/sys/dao/SysUserDao.java index 77367991..a2976bd7 100644 --- a/renren-admin/src/main/java/io/renren/modules/sys/dao/SysUserDao.java +++ b/renren-admin/src/main/java/io/renren/modules/sys/dao/SysUserDao.java @@ -39,4 +39,6 @@ public interface SysUserDao extends BaseDao { * @return */ SysUserEntity getByDeptIdAndRoleId(@Param("deptId") Long deptId, @Param("roleId") Long roleId); + + Long countAllUser(); } \ No newline at end of file diff --git a/renren-admin/src/main/java/io/renren/modules/sys/service/SysUserService.java b/renren-admin/src/main/java/io/renren/modules/sys/service/SysUserService.java index a27655b1..f285c8e8 100644 --- a/renren-admin/src/main/java/io/renren/modules/sys/service/SysUserService.java +++ b/renren-admin/src/main/java/io/renren/modules/sys/service/SysUserService.java @@ -48,4 +48,11 @@ public interface SysUserService extends BaseService { SysUserDTO getByDeptIdAndRoleId(Long deptId, Long roleId); + /** + * 统计所有有效的用户 + * + * @return + */ + Long countAllUser(); + } diff --git a/renren-admin/src/main/java/io/renren/modules/sys/service/impl/SysUserServiceImpl.java b/renren-admin/src/main/java/io/renren/modules/sys/service/impl/SysUserServiceImpl.java index 7fdc78da..9dc62803 100644 --- a/renren-admin/src/main/java/io/renren/modules/sys/service/impl/SysUserServiceImpl.java +++ b/renren-admin/src/main/java/io/renren/modules/sys/service/impl/SysUserServiceImpl.java @@ -167,4 +167,14 @@ public class SysUserServiceImpl extends BaseServiceImpl #{item} @@ -104,14 +104,19 @@ IFNULL(trc.collectCount, 0) AS "collectCount", IFNULL(sd.name, '暂无部门信息') AS "deptName", IFNULL(trc2.isCollect, 'false') AS "isCollect", - (IFNULL(tdr.visits / 100, 0) + IFNULL(trs.score, 0) + IFNULL(taa.applyCount, 0)+ IFNULL(trc.collectCount, 0)) AS total + (IFNULL(tdr.visits / 100, 0) + IFNULL(trs.score, 0) + IFNULL(taa.applyCount, 0)+ IFNULL(trc.collectCount, 0)) AS + total FROM tb_data_resource tdr LEFT JOIN tb_data_attr tda ON tdr.id = tda.data_resource_id - LEFT JOIN ( SELECT resource_id, AVG(score) AS "score" FROM tb_resource_score WHERE 1 = 1 AND del_flag = 0 GROUP BY resource_id ) trs ON tdr.id = trs.resource_id - LEFT JOIN ( SELECT resource_id, COUNT(id) AS "applyCount" FROM t_ability_application WHERE 1 = 1 AND del_flag = 0 GROUP BY resource_id ) taa ON tdr.id = taa.resource_id - LEFT JOIN ( SELECT resource_id, COUNT(id) AS "collectCount" FROM tb_resource_collection WHERE 1 = 1 AND del_flag = 0 GROUP BY resource_id ) trc ON tdr.id = trc.resource_id - LEFT JOIN ( SELECT resource_id, user_id, ( CASE COUNT( id ) WHEN 1 THEN 'true' ELSE 'false' END ) AS "isCollect" FROM tb_resource_collection WHERE + LEFT JOIN ( SELECT resource_id, AVG(score) AS "score" FROM tb_resource_score WHERE 1 = 1 AND del_flag = 0 GROUP + BY resource_id ) trs ON tdr.id = trs.resource_id + LEFT JOIN ( SELECT resource_id, COUNT(id) AS "applyCount" FROM t_ability_application WHERE 1 = 1 AND del_flag = + 0 GROUP BY resource_id ) taa ON tdr.id = taa.resource_id + LEFT JOIN ( SELECT resource_id, COUNT(id) AS "collectCount" FROM tb_resource_collection WHERE 1 = 1 AND del_flag + = 0 GROUP BY resource_id ) trc ON tdr.id = trc.resource_id + LEFT JOIN ( SELECT resource_id, user_id, ( CASE COUNT( id ) WHEN 1 THEN 'true' ELSE 'false' END ) AS "isCollect" + FROM tb_resource_collection WHERE 1 = 1 AND del_flag = 0 AND user_id = #{dto.creator} @@ -121,18 +126,18 @@ WHERE 1 = 1 AND tdr.type = #{dto.type} AND tdr.del_flag = 0 - + AND tdr.name like CONCAT('%',#{dto.name},'%') - - AND tdr.district_id = #{dto.districtId} + + AND tdr.district_id = #{dto.districtId} - - AND tdr.dept_id = #{dto.deptId} + + AND tdr.dept_id = #{dto.deptId} AND - tda.data_resource_id IN ( + tda.data_resource_id IN ( SELECT data_resource_id FROM ( SELECT tb.data_resource_id @@ -153,102 +158,115 @@ SELECT - * + * FROM - ( - SELECT - attr_value, - IFNULL( COUNT( trc.id ), 0 ) AS "colCount", - IFNULL( COUNT( taa.id ), 0 ) AS "aplCount", - ( - IFNULL( COUNT( trc.id ), 0 ) + IFNULL( COUNT( taa.id ), 0 )) AS total - FROM - tb_data_attr tda - LEFT JOIN tb_resource_collection trc ON tda.data_resource_id = trc.resource_id - AND trc.del_flag = 0 - AND trc.user_id = #{userId} - LEFT JOIN t_ability_application taa ON tda.data_resource_id = taa.resource_id - AND taa.del_flag = 0 - AND taa.user_id = #{userId} + ( + SELECT + attr_value, + IFNULL( COUNT( trc.id ), 0 ) AS "colCount", + IFNULL( COUNT( taa.id ), 0 ) AS "aplCount", + ( + IFNULL( COUNT( trc.id ), 0 ) + IFNULL( COUNT( taa.id ), 0 )) AS total + FROM + tb_data_attr tda + LEFT JOIN tb_resource_collection trc ON tda.data_resource_id = trc.resource_id + AND trc.del_flag = 0 + AND trc.user_id = #{userId} + LEFT JOIN t_ability_application taa ON tda.data_resource_id = taa.resource_id + AND taa.del_flag = 0 + AND taa.user_id = #{userId} - WHERE - 1 = 1 - AND tda.attr_type = '应用领域' - AND tda.del_flag = 0 - AND ( attr_value != '' AND attr_value IS NOT NULL ) - GROUP BY - attr_value - ORDER BY - total DESC - ) temp WHERE - temp.total != 0 + 1 = 1 + AND tda.attr_type = '应用领域' + AND tda.del_flag = 0 + AND ( attr_value != '' AND attr_value IS NOT NULL ) + GROUP BY + attr_value + ORDER BY + total DESC + ) temp + WHERE + temp.total != 0 + + + \ No newline at end of file diff --git a/renren-admin/src/main/resources/mapper/sys/SysUserDao.xml b/renren-admin/src/main/resources/mapper/sys/SysUserDao.xml index 74716fed..425e7868 100644 --- a/renren-admin/src/main/resources/mapper/sys/SysUserDao.xml +++ b/renren-admin/src/main/resources/mapper/sys/SysUserDao.xml @@ -6,10 +6,10 @@ + \ No newline at end of file