luofl
2025-03-20 40fd87c3e98f2a5054ef480fed31dbae7376bf49
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
package com.ruoyi.web.controller.api;
 
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.ruoyi.common.core.domain.R;
import com.ruoyi.system.model.TContract;
import com.ruoyi.system.service.TContractService;
import com.ruoyi.system.service.impl.ScreenService;
import com.ruoyi.system.vo.TenantCountTrendVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiModelProperty;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
 
import java.text.DateFormat;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.time.format.DateTimeFormatterBuilder;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
 
/**
 * @author mitao
 * @date 2025/3/19
 */
@Api(tags = {"大屏相关接口"})
@RestController
@RequestMapping("/screen")
@RequiredArgsConstructor
public class ScreenController {
    private final ScreenService screenService;
    private final TContractService contractService;
 
 
    @GetMapping("/getTenantCountTrend")
    @ApiModelProperty(value = "租户数量趋势统计")
    public R<?> getTenantCountTrend() {
        // 获取所有签约时间不为空的合同
        List<TContract> contracts = contractService.list(new LambdaQueryWrapper<TContract>()
                .isNotNull(TContract::getSignTime));
 
        // 使用年-月格式化日期,并按此分组计算每个时间段的合同数量
        DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yy-M");
 
        List<TenantCountTrendVO> trendData = contracts.stream()
                .collect(Collectors.groupingBy(contract -> contract.getSignTime().toLocalDate()
                        .withDayOfMonth(1) // 将日期调整为该月的第一天,以便正确分组
                        .atStartOfDay()))
                .entrySet().stream()
                .map(entry -> {
                    String period = entry.getKey().format(formatter);
                    long count = entry.getValue().size();
                    return new TenantCountTrendVO(period, count);
                })
                .collect(Collectors.toList());
 
        return R.ok(trendData);
    }
 
}