mirror of
https://github.com/hpd840321/craftlabs-authorization-sdk.git
synced 2026-06-09 10:00:30 +08:00
fix(report): implement getProjectHealth with real data queries
This commit is contained in:
+43
-2
@@ -8,6 +8,8 @@ import cn.craftlabs.platform.api.persistence.contract.PlatformContractLineMapper
|
|||||||
import cn.craftlabs.platform.api.persistence.contract.PlatformContractMapper;
|
import cn.craftlabs.platform.api.persistence.contract.PlatformContractMapper;
|
||||||
import cn.craftlabs.platform.api.persistence.customer.PlatformCustomer;
|
import cn.craftlabs.platform.api.persistence.customer.PlatformCustomer;
|
||||||
import cn.craftlabs.platform.api.persistence.customer.PlatformCustomerMapper;
|
import cn.craftlabs.platform.api.persistence.customer.PlatformCustomerMapper;
|
||||||
|
import cn.craftlabs.platform.api.persistence.delivery.PlatformDeliveryBatch;
|
||||||
|
import cn.craftlabs.platform.api.persistence.delivery.PlatformDeliveryBatchMapper;
|
||||||
import cn.craftlabs.platform.api.persistence.license.PlatformLicenseSn;
|
import cn.craftlabs.platform.api.persistence.license.PlatformLicenseSn;
|
||||||
import cn.craftlabs.platform.api.persistence.license.PlatformLicenseSnMapper;
|
import cn.craftlabs.platform.api.persistence.license.PlatformLicenseSnMapper;
|
||||||
import cn.craftlabs.platform.api.persistence.project.PlatformProject;
|
import cn.craftlabs.platform.api.persistence.project.PlatformProject;
|
||||||
@@ -35,6 +37,7 @@ public class ReportService {
|
|||||||
private final PlatformCallbackInboxMapper callbackInboxMapper;
|
private final PlatformCallbackInboxMapper callbackInboxMapper;
|
||||||
private final PlatformProjectMapper projectMapper;
|
private final PlatformProjectMapper projectMapper;
|
||||||
private final PlatformCustomerMapper customerMapper;
|
private final PlatformCustomerMapper customerMapper;
|
||||||
|
private final PlatformDeliveryBatchMapper deliveryBatchMapper;
|
||||||
|
|
||||||
public ReportService(
|
public ReportService(
|
||||||
PlatformContractMapper contractMapper,
|
PlatformContractMapper contractMapper,
|
||||||
@@ -42,13 +45,15 @@ public class ReportService {
|
|||||||
PlatformLicenseSnMapper licenseSnMapper,
|
PlatformLicenseSnMapper licenseSnMapper,
|
||||||
PlatformCallbackInboxMapper callbackInboxMapper,
|
PlatformCallbackInboxMapper callbackInboxMapper,
|
||||||
PlatformProjectMapper projectMapper,
|
PlatformProjectMapper projectMapper,
|
||||||
PlatformCustomerMapper customerMapper) {
|
PlatformCustomerMapper customerMapper,
|
||||||
|
PlatformDeliveryBatchMapper deliveryBatchMapper) {
|
||||||
this.contractMapper = contractMapper;
|
this.contractMapper = contractMapper;
|
||||||
this.contractLineMapper = contractLineMapper;
|
this.contractLineMapper = contractLineMapper;
|
||||||
this.licenseSnMapper = licenseSnMapper;
|
this.licenseSnMapper = licenseSnMapper;
|
||||||
this.callbackInboxMapper = callbackInboxMapper;
|
this.callbackInboxMapper = callbackInboxMapper;
|
||||||
this.projectMapper = projectMapper;
|
this.projectMapper = projectMapper;
|
||||||
this.customerMapper = customerMapper;
|
this.customerMapper = customerMapper;
|
||||||
|
this.deliveryBatchMapper = deliveryBatchMapper;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Transactional(readOnly = true)
|
@Transactional(readOnly = true)
|
||||||
@@ -118,7 +123,43 @@ public class ReportService {
|
|||||||
|
|
||||||
@Transactional(readOnly = true)
|
@Transactional(readOnly = true)
|
||||||
public List<ProjectHealthRow> getProjectHealth() {
|
public List<ProjectHealthRow> getProjectHealth() {
|
||||||
return new ArrayList<>();
|
List<PlatformProject> projects = projectMapper.selectList(null);
|
||||||
|
return projects.stream().map(project -> {
|
||||||
|
ProjectHealthRow row = new ProjectHealthRow();
|
||||||
|
row.setProjectId(project.getId());
|
||||||
|
row.setProjectName(project.getName());
|
||||||
|
|
||||||
|
LambdaQueryWrapper<PlatformDeliveryBatch> deliveryQuery = Wrappers.lambdaQuery(PlatformDeliveryBatch.class)
|
||||||
|
.eq(PlatformDeliveryBatch::getProjectId, project.getId());
|
||||||
|
List<PlatformDeliveryBatch> batches = deliveryBatchMapper.selectList(deliveryQuery);
|
||||||
|
long totalBatches = batches.size();
|
||||||
|
long deliveredBatches = batches.stream().filter(b -> "DELIVERED".equals(b.getStatus())).count();
|
||||||
|
double deliveryRate = totalBatches > 0 ? deliveredBatches * 100.0 / totalBatches : 0;
|
||||||
|
|
||||||
|
LambdaQueryWrapper<PlatformLicenseSn> snQuery = Wrappers.lambdaQuery(PlatformLicenseSn.class)
|
||||||
|
.eq(PlatformLicenseSn::getProjectId, project.getId());
|
||||||
|
List<PlatformLicenseSn> sns = licenseSnMapper.selectList(snQuery);
|
||||||
|
long totalSns = sns.size();
|
||||||
|
long activatedSns = sns.stream().filter(sn -> "ACTIVATED".equals(sn.getStatus())).count();
|
||||||
|
double activationRate = totalSns > 0 ? activatedSns * 100.0 / totalSns : 0;
|
||||||
|
double snIssuedRate = totalSns > 0 ? 100.0 : 0;
|
||||||
|
|
||||||
|
row.setDeliveryRate(deliveryRate);
|
||||||
|
row.setSnIssuedRate(snIssuedRate);
|
||||||
|
row.setActivationRate(activationRate);
|
||||||
|
|
||||||
|
String healthLevel;
|
||||||
|
if (deliveryRate < 50 || activationRate < 50) {
|
||||||
|
healthLevel = "RED";
|
||||||
|
} else if (deliveryRate < 80 || activationRate < 80) {
|
||||||
|
healthLevel = "YELLOW";
|
||||||
|
} else {
|
||||||
|
healthLevel = "GREEN";
|
||||||
|
}
|
||||||
|
row.setHealthLevel(healthLevel);
|
||||||
|
|
||||||
|
return row;
|
||||||
|
}).collect(Collectors.toList());
|
||||||
}
|
}
|
||||||
|
|
||||||
private String resolveCustomerName(Long customerId) {
|
private String resolveCustomerName(Long customerId) {
|
||||||
|
|||||||
Reference in New Issue
Block a user