feat: 首页统计数量

This commit is contained in:
caiyuchao
2025-10-09 14:53:02 +08:00
parent 68cc385961
commit 9698036637
4 changed files with 48 additions and 9 deletions

View File

@@ -21,6 +21,9 @@ public class DashboardRespVO {
@Schema(description = "license数量") @Schema(description = "license数量")
private Long licenseCount; private Long licenseCount;
@Schema(description = "永久license数量")
private Long permanentCount;
@Schema(description = "用户数量") @Schema(description = "用户数量")
private Long userCount; private Long userCount;

View File

@@ -5,6 +5,7 @@ import org.agt.framework.mybatis.core.mapper.BaseMapperX;
import org.agt.framework.mybatis.core.query.LambdaQueryWrapperX; import org.agt.framework.mybatis.core.query.LambdaQueryWrapperX;
import org.agt.module.license.controller.admin.customer.vo.CustomerPageReqVO; import org.agt.module.license.controller.admin.customer.vo.CustomerPageReqVO;
import org.agt.module.license.controller.admin.customer.vo.CustomerRespVO; import org.agt.module.license.controller.admin.customer.vo.CustomerRespVO;
import org.agt.module.license.controller.admin.customer.vo.DashboardRespVO;
import org.agt.module.license.dal.dataobject.customer.CustomerDO; import org.agt.module.license.dal.dataobject.customer.CustomerDO;
import org.apache.ibatis.annotations.Mapper; import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param; import org.apache.ibatis.annotations.Param;
@@ -51,4 +52,8 @@ public interface CustomerMapper extends BaseMapperX<CustomerDO> {
Integer selectOldMaxCode(); Integer selectOldMaxCode();
List<CustomerRespVO> getLicenseCustomers(); List<CustomerRespVO> getLicenseCustomers();
DashboardRespVO getLicenseCount();
DashboardRespVO getProjectCount();
} }

View File

@@ -32,7 +32,6 @@ import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
import java.util.LinkedHashMap; import java.util.LinkedHashMap;
import java.util.List; import java.util.List;
import java.util.stream.Collectors;
import static org.agt.framework.common.exception.util.ServiceExceptionUtil.exception; import static org.agt.framework.common.exception.util.ServiceExceptionUtil.exception;
import static org.agt.module.license.enums.ErrorCodeConstants.CUSTOMER_CODE_DUPLICATE; import static org.agt.module.license.enums.ErrorCodeConstants.CUSTOMER_CODE_DUPLICATE;
@@ -70,15 +69,12 @@ public class CustomerServiceImpl implements CustomerService {
@Override @Override
public DashboardRespVO dashboard() { public DashboardRespVO dashboard() {
Long customerCount = customerMapper.selectCount(Wrappers.<CustomerDO>lambdaQuery().notIn(CustomerDO::getName, Arrays.asList("AGT", "BA", "Blue Arcus"))); Long customerCount = customerMapper.selectCount(Wrappers.<CustomerDO>lambdaQuery().notIn(CustomerDO::getName, Arrays.asList("AGT", "BA", "Blue Arcus")));
List<CustomerDO> customerDOS = customerMapper.selectList(Wrappers.<CustomerDO>lambdaQuery().in(CustomerDO::getName, Arrays.asList("AGT", "BA", "Blue Arcus"))); DashboardRespVO projectRespVO = customerMapper.getProjectCount();
List<Long> customerIds = customerDOS.stream().map(CustomerDO::getId).collect(Collectors.toList()); Long projectCount = projectRespVO.getProjectCount();
Long projectCount = projectMapper.selectCount(Wrappers.<ProjectDO>lambdaQuery().notIn(CollUtil.isNotEmpty(customerIds), ProjectDO::getCustomerId, customerIds)); Long contractCount = projectRespVO.getContractCount();
Long contractCount = projectMapper.selectCount(Wrappers.<ProjectDO>lambdaQuery().ne(ProjectDO::getContractCode, "0")); DashboardRespVO dashboardRespVO = customerMapper.getLicenseCount();
Long licenseCount = licenseMapper.selectCount();
DashboardRespVO dashboardRespVO = new DashboardRespVO();
dashboardRespVO.setCustomerCount(customerCount); dashboardRespVO.setCustomerCount(customerCount);
dashboardRespVO.setProjectCount(projectCount); dashboardRespVO.setProjectCount(projectCount);
dashboardRespVO.setLicenseCount(licenseCount);
dashboardRespVO.setContractCount(contractCount); dashboardRespVO.setContractCount(contractCount);
dashboardRespVO.setUserCount(customerMapper.selectUserCount()); dashboardRespVO.setUserCount(customerMapper.selectUserCount());
if (projectCount == 0) { if (projectCount == 0) {
@@ -87,10 +83,11 @@ public class CustomerServiceImpl implements CustomerService {
dashboardRespVO.setSigningRate(BigDecimal.valueOf(contractCount).multiply(BigDecimal.valueOf(100)) dashboardRespVO.setSigningRate(BigDecimal.valueOf(contractCount).multiply(BigDecimal.valueOf(100))
.divide(BigDecimal.valueOf(projectCount), 0, RoundingMode.HALF_UP).longValue()); .divide(BigDecimal.valueOf(projectCount), 0, RoundingMode.HALF_UP).longValue());
} }
Long licenseCount = dashboardRespVO.getLicenseCount();
if (licenseCount == 0) { if (licenseCount == 0) {
dashboardRespVO.setCompletionRate(0L); dashboardRespVO.setCompletionRate(0L);
} else { } else {
dashboardRespVO.setCompletionRate(BigDecimal.valueOf(contractCount).multiply(BigDecimal.valueOf(100)) dashboardRespVO.setCompletionRate(BigDecimal.valueOf(dashboardRespVO.getPermanentCount()).multiply(BigDecimal.valueOf(100))
.divide(BigDecimal.valueOf(licenseCount), 0, RoundingMode.HALF_UP).longValue()); .divide(BigDecimal.valueOf(licenseCount), 0, RoundingMode.HALF_UP).longValue());
} }

View File

@@ -39,4 +39,38 @@
AND l.id IS NULL AND l.id IS NULL
AND c.id IS NOT NULL AND c.id IS NOT NULL
</select> </select>
<select id="getLicenseCount" resultType="org.agt.module.license.controller.admin.customer.vo.DashboardRespVO">
SELECT
count( 1 ) license_count,
count( CASE WHEN date( l.expiry_date ) = '2099-12-31' THEN 1 END ) permanent_count
FROM
crm_license_server l
LEFT JOIN crm_project p ON l.project_id = p.id
AND p.deleted = 0
LEFT JOIN crm_customer c ON p.customer_id = c.id
AND c.deleted = 0
WHERE
l.deleted = 0
AND c.`name` NOT IN (
"AGT",
"BA",
"Blue Arcus")
</select>
<select id="getProjectCount" resultType="org.agt.module.license.controller.admin.customer.vo.DashboardRespVO">
SELECT
count( 1 ) project_count,
count( CASE WHEN p.contract_code != '0' THEN 1 END ) contract_count
FROM
crm_project p
LEFT JOIN crm_customer c ON p.customer_id = c.id
AND c.deleted = 0
WHERE
p.deleted = 0
AND c.`name` NOT IN (
"AGT",
"BA",
"Blue Arcus")
</select>
</mapper> </mapper>