统计类接口

文章介绍了用于统计每日、每周、每月以及近30天疫苗接种数据的接口设计,包括查询接种管理列表和折线图统计功能。内容涉及Service层方法、Mapper层的SQL查询和数据处理逻辑。
摘要由CSDN通过智能技术生成

统计当天的数据,统计本周的数据,统计本月的数据,统计近30天的数据

  /**
         * 查询接种管理统计
         */
        @GetMapping("/count")
        public IndexCount listCount()
        {
            IndexCount indexCount = vaccinesIndexService.selectVaccinesInoculationList();
            return indexCount;
        }

        /**
         * 折线图统计
         */
        @GetMapping("/lineChart")
        public List<Map> lineChart()
        {
            List<Map> maps = vaccinesIndexService.selectDiscountStatistics();
            return maps;
        }










接口Service 层

public interface VaccinesIndexService extends IService<VaccineOrder> {
    /**
     * 查询接种管理列表
     * @return 接种管理集合
     */
    public IndexCount selectVaccinesInoculationList();


    /**
     * @param
     * @return com.vaccine.system.domain.IndexCount
     * @描述:折现统计图
     * @创建时间:2024/3/22 14:32
     */
    public List<Map> selectDiscountStatistics();
}



@Service
public class VaccinesIndexServiceImpl extends ServiceImpl<VaccinesIndexMapper, VaccineOrder> implements VaccinesIndexService {

    /**
     * 查询接种管理列表
     * @return 接种管理
     */
    @Override
    public IndexCount selectVaccinesInoculationList() {

        IndexCount indexCount = new IndexCount();

        // 查寻今日
        int subscribeTimeCount = baseMapper.selectTodayList1();
        int subscribeTimeOverCount = baseMapper.selectTodayList2();
        int timeTodayCount = baseMapper.selectTodayList3();

        System.out.println("统计今日待接种: " + subscribeTimeCount + ",统计今日已接种" + subscribeTimeOverCount + ",今日新增预约量: " + timeTodayCount);


        // 统计本周的数据
        int weekOnrCount = baseMapper.selectWeekList1();
        int weekTwoCount = baseMapper.selectWeekList2();
        System.out.println("本周待接种: " + weekOnrCount + ",本周已接种" + weekTwoCount);

        // 统计月数据
        int monthOneCount = baseMapper.selectMouthList1();
        int monthTwoCount = baseMapper.selectMouthList2();

        indexCount.setSubscribeTimeCount(subscribeTimeCount);
        indexCount.setSubscribeTimeOverCount(subscribeTimeOverCount);
        indexCount.setTimeTodayCount(timeTodayCount);
        indexCount.setWeekOnrCount(weekOnrCount);
        indexCount.setWeekTwoCount(weekTwoCount);
        indexCount.setMonthOneCount(monthOneCount);
        indexCount.setMonthTwoCount(monthTwoCount);

        return indexCount;
    }



    /**
     * @描述: 折线图统计
     * @创建人:Lixueying
     * @创建时间:2024/3/25 18:06
     * @param
     * @return com.vaccine.system.domain.DiscountStatistics
     */
    @Override
    public List<Map> selectDiscountStatistics() {

        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");
        // 统计近三十天数据(过去式)
        List<Map> vaccineOrders = baseMapper.selectThirtyDaysList();
        return vaccineOrders;
    }
}

Mapper 层

public interface VaccinesIndexMapper extends BaseMapperPlus<VaccinesIndexMapper, VaccineOrder, VaccineOrder> {

    /**
     * 查询接种管理
     * @return 接种管理
     */
    public int selectMouthList1();
    public int selectMouthList2();
    public int selectWeekList1();
    public int selectWeekList2();
    public int selectTodayList1();
    public int selectTodayList2();
    public int selectTodayList3();

    public List<Map> selectThirtyDaysList();
}



Sql 层

    <sql id="selectVaccineOrderVo">
        select pk_id, id, patient_id, name, phone, age, id_card, vaccine_id, vaccine_num, dept_id, org_id, user_id, book_time, book_status, affirm_time, cancel_reason, cancel_time, ack_time, is_deleted, gmt_deleted, gmt_created, gmt_modified, user_created, user_modified from vaccine_order
    </sql>

    <select id="selectMouthList1"  resultType="int">
        SELECT
            count(*)
        FROM
            `vaccine_order`
        WHERE
            book_time >= DATE_FORMAT(NOW(),'%Y-%m-01')
          and book_time &lt;= LAST_DAY(NOW())
          AND book_status = 1;
    </select>

    <select id="selectMouthList2"  resultType="int">
        SELECT
        count(*)
        FROM
        `vaccine_order`
        WHERE
        book_time >= DATE_FORMAT(NOW(),'%Y-%m-01')
        and book_time &lt;= LAST_DAY(NOW())
        AND book_status = 2;
    </select>

    <select id="selectWeekList1"  resultType="int">
        SELECT
            count(*)
        FROM
            `vaccine_order`
        WHERE
            WEEK ( book_time, 1 ) = WEEK ( CURRENT_DATE, 1 )
          AND book_status = 1;;
    </select>


    <select id="selectWeekList2"  resultType="int">
        SELECT
            count(*)
        FROM
            `vaccine_order`
        WHERE
            WEEK ( book_time, 1 ) = WEEK ( CURRENT_DATE, 1 )
          AND book_status = 2;;
    </select>

    <select id="selectTodayList1"  resultType="int">
        SELECT
            COUNT(*)
        FROM
            vaccine_order
        WHERE
            book_status = 1
          AND  DATE (book_time) = CURDATE()
    </select>

    <select id="selectTodayList2"  resultType="int">
        SELECT
            COUNT(*)
        FROM
            vaccine_order
        WHERE
            book_status = 2
          AND  DATE (book_time) = CURDATE()
    </select>

    <select id="selectTodayList3"  resultType="int">
        SELECT
            COUNT(*)
        FROM
            vaccine_order
        WHERE
             DATE(book_time) = CURDATE()
          AND  DATE(gmt_created) = CURDATE()
    </select>

    <select id="selectThirtyDaysList" resultType="java.util.Map">
        SELECT
            a.create_time "time",
            count( b.id ) "num"
        FROM
            ( SELECT DATE_SUB( CURRENT_DATE, INTERVAL num - 1 DAY ) create_time FROM sys_num WHERE num BETWEEN 0 AND 31 ) a
                LEFT JOIN vaccine_order b ON a.create_time = DATE_FORMAT( b.affirm_time, '%Y-%m-%d' )
                AND b.book_status = 2
        GROUP BY
            a.create_time DESC
    </select>

统计Java接口的调用次数,可以使用AOP(面向切面编程)技术,在接口调用时拦截请求,并记录接口调用次数。 具体实现步骤如下: 1. 定义一个注解,用于标记需要统计调用次数的接口方法。 例如: ```java @Target(ElementType.METHOD) @Retention(RetentionPolicy.RUNTIME) public @interface Count { } ``` 2. 创建一个切面,使用@Aspect注解标记,并在中定义一个切点,用于匹配被@Count注解标记的方法。 例如: ```java @Aspect @Component public class CountAspect { private Map<String, Integer> countMap = new ConcurrentHashMap<>(); @Pointcut("@annotation(com.example.demo.annotation.Count)") public void countPointcut() { } @Around("countPointcut()") public Object countAround(ProceedingJoinPoint joinPoint) throws Throwable { String methodName = joinPoint.getSignature().getName(); String className = joinPoint.getSignature().getDeclaringTypeName(); String key = className + "." + methodName; Integer count = countMap.get(key); if (count == null) { count = 1; } else { count++; } countMap.put(key, count); Object result = joinPoint.proceed(); return result; } } ``` 在上述代码中,我们使用了ConcurrentHashMap来存储每个接口方法的调用次数,初始值为1,每次调用自增1。 3. 在需要统计调用次数的接口方法上添加@Count注解。 例如: ```java @RestController @RequestMapping("/demo") public class DemoController { @Autowired private DemoService demoService; @Count @GetMapping("/hello") public String hello() { return "hello"; } @GetMapping("/count") public Map<String, Integer> count() { return demoService.getCountMap(); } } ``` 在上述代码中,我们在hello()方法上添加了@Count注解,表示需要统计该方法的调用次数。 4. 创建一个服务,用于获取调用次数的统计结果。 例如: ```java @Service public class DemoService { @Autowired private CountAspect countAspect; public Map<String, Integer> getCountMap() { return countAspect.getCountMap(); } } ``` 在上述代码中,我们通过@Autowired注解注入了CountAspect切面,并通过该的getCountMap()方法获取到统计结果。 最后,启动应用程序,在浏览器中访问/hello接口,多次刷新页面,然后访问/count接口,即可获取到接口方法调用次数的统计结果。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值