package org.dromara.biz.mapper;

import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.toolkit.Constants;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.dromara.biz.domain.StatDept;
import org.dromara.biz.domain.vo.StatDeptVo;
import org.dromara.common.mybatis.annotation.DataColumn;
import org.dromara.common.mybatis.annotation.DataPermission;
import org.dromara.common.mybatis.core.mapper.BaseMapperPlus;

/**
 * 单位每日数据统计Mapper接口
 *
 * @author YIN
 * @date 2025-05-21
 */
public interface StatDeptMapper extends BaseMapperPlus<StatDept, StatDeptVo> {

    @Select("select * from stat_dept where dept_id = ${deptId} and tjrq = ${tjrq}")
    StatDept selectByDeptId(String deptId, String tjrq);

    StatDept statByDeptId(Long deptId);

    StatDept statYesterdayByDeptId(Long deptId);

    @Delete("delete from stat_dept where dept_id = ${deptId} and tjrq = CURDATE() - INTERVAL 1 DAY")
    int deleteYesterdayData(Long deptId);

    @Delete("delete from stat_dept where dept_id = ${deptId} and tjrq = CURDATE()")
    int deleteTodayData(Long deptId);

    @DataPermission({
            @DataColumn(key = "deptName", value = "dept_id")
    })
    Page<StatDeptVo> queryPageStat(@Param("page")Page<StatDeptVo> page, @Param(Constants.WRAPPER) Wrapper<StatDept> queryWrapper);

    StatDept statByDept(Long deptId);
}
