feat(quality): 添加业务分析控制器实现数据统计功能
- 新增 QualityBusinessAnalyticsController 控制器类 - 实现分页查询业务分析数据接口 /page - 实现新增业务分析记录接口 /add - 实现业务统计数据汇总接口 /summary - 集成分页查询和条件筛选功能 - 添加事务管理确保数据一致性
This commit is contained in:
@@ -0,0 +1,62 @@
|
||||
package com.healthlink.his.web.quality.controller;
|
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.core.common.core.domain.R;
|
||||
import com.healthlink.his.quality.domain.BusinessAnalytics;
|
||||
import com.healthlink.his.quality.service.IBusinessAnalyticsService;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
import org.springframework.util.StringUtils;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.util.*;
|
||||
|
||||
@RestController
|
||||
@RequestMapping("/business-analytics")
|
||||
@Slf4j
|
||||
@AllArgsConstructor
|
||||
public class QualityBusinessAnalyticsController {
|
||||
|
||||
private final IBusinessAnalyticsService analyticsService;
|
||||
|
||||
@GetMapping("/page")
|
||||
public R<?> getPage(
|
||||
@RequestParam(value = "departmentName", required = false) String deptName,
|
||||
@RequestParam(value = "pageNo", defaultValue = "1") Integer pageNo,
|
||||
@RequestParam(value = "pageSize", defaultValue = "20") Integer pageSize) {
|
||||
LambdaQueryWrapper<BusinessAnalytics> w = new LambdaQueryWrapper<>();
|
||||
w.like(StringUtils.hasText(deptName), BusinessAnalytics::getDepartmentName, deptName)
|
||||
.orderByDesc(BusinessAnalytics::getStatDate);
|
||||
return R.ok(analyticsService.page(new Page<>(pageNo, pageSize), w));
|
||||
}
|
||||
|
||||
@PostMapping("/add")
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public R<?> add(@RequestBody BusinessAnalytics analytics) {
|
||||
analytics.setCreateTime(new Date());
|
||||
analyticsService.save(analytics);
|
||||
return R.ok(analytics);
|
||||
}
|
||||
|
||||
@GetMapping("/summary")
|
||||
public R<?> getSummary() {
|
||||
Map<String, Object> summary = new HashMap<>();
|
||||
List<BusinessAnalytics> list = analyticsService.list();
|
||||
BigDecimal totalRevenue = BigDecimal.ZERO, totalCost = BigDecimal.ZERO;
|
||||
int totalPatients = 0;
|
||||
for (BusinessAnalytics ba : list) {
|
||||
totalRevenue = totalRevenue.add(ba.getRevenue() != null ? ba.getRevenue() : BigDecimal.ZERO);
|
||||
totalCost = totalCost.add(ba.getCost() != null ? ba.getCost() : BigDecimal.ZERO);
|
||||
totalPatients += ba.getPatientCount() != null ? ba.getPatientCount() : 0;
|
||||
}
|
||||
summary.put("totalRecords", list.size());
|
||||
summary.put("totalRevenue", totalRevenue);
|
||||
summary.put("totalCost", totalCost);
|
||||
summary.put("totalProfit", totalRevenue.subtract(totalCost));
|
||||
summary.put("totalPatients", totalPatients);
|
||||
return R.ok(summary);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user