package com.rongwei.sfcommon.sys.dao;

import com.rongwe.scentity.domian.AspBoardLargeManualMaintenanceDo;
import com.rongwe.scentity.vo.BaoAnShiDaPingDataVo;
import com.rongwei.rwcommon.base.BaseDao;
import org.apache.ibatis.annotations.Select;

import java.util.List;

public interface AspBoardLargeManualMaintenanceDao extends BaseDao<AspBoardLargeManualMaintenanceDo> {
    @Select("WITH RankedRecords AS (\n" +
            "    SELECT \n" +
            "        *,\n" +
            "        ROW_NUMBER() OVER (PARTITION BY TENANTID ORDER BY MODIFYDATE DESC) AS rn\n" +
            "    FROM\n" +
            "        asp_board_large_manual_maintenance\n" +
            "    WHERE\n" +
            "        DELETED = '0' \n" +
            "\t\t\t\tAND ISITENABLED = 'y'\n" +
            ")\n" +
            "SELECT\n" +
            "    *\n" +
            "FROM\n" +
            "    RankedRecords\n" +
            "WHERE\n" +
            "    rn = 1;")
    List<AspBoardLargeManualMaintenanceDo> getLastest();

    @Select("WITH RankedRecords AS (\n" +
            "    SELECT \n" +
            "        *,\n" +
            "        ROW_NUMBER() OVER (PARTITION BY TENANTID ORDER BY MODIFYDATE DESC) AS rn\n" +
            "    FROM\n" +
            "        asp_board_large_manual_maintenance\n" +
            "    WHERE\n" +
            "        DELETED = '0'  AND TENANTID = #{tenantId}\n" +
            "\t\t\t\tAND ISITENABLED = 'y'\n" +
            ")\n" +
            "SELECT\n" +
            "    *\n" +
            "FROM\n" +
            "    RankedRecords\n" +
            "WHERE\n" +
            "    rn = 1;")
    List<AspBoardLargeManualMaintenanceDo> getLastestByTenantId(String tenantId);

    @Select("SELECT \n" +
            "    dhzy.dhzycount, \n" +
            "    tjdhzy.tjdhzycount,\n" +
            "\t\tyjdhzy.yjdhzycount,\n" +
            "\t\tejdhzy.ejdhzycount,\n" +
            "\t\tsxkjzy.sxkjzycount,\n" +
            "\t\tlsydzy.lsydzycount,\n" +
            "\t\tgczy.gczycount,\n" +
            "\t\tdzzy.dzzycount,\n" +
            "\t\tmbcdzy.mbcdzycount,\n" +
            "\t\tdtzy.dtzycount,\n" +
            "\t\tdlzz.dlzzcount\n" +
            "FROM \n" +
            "    (SELECT COUNT(*) AS dhzycount\n" +
            "     FROM asp_dhzy \n" +
            "     WHERE DELETED = 0 AND DQZT = '3' AND TENANTID = #{tenantId} AND DATE(ZYSQSJ) = CURDATE()) AS dhzy\n" +
            "CROSS JOIN \n" +
            "    (SELECT COUNT(*) AS tjdhzycount \n" +
            "     FROM asp_dhzy \n" +
            "     WHERE DELETED = 0 AND DQZT = '3' AND TENANTID = #{tenantId} AND DATE(ZYSQSJ) = CURDATE() AND DHZYJB = '1') AS tjdhzy\n" +
            "CROSS JOIN \n" +
            "    (SELECT COUNT(*) AS yjdhzycount \n" +
            "     FROM asp_dhzy \n" +
            "     WHERE DELETED = 0 AND DQZT = '3' AND TENANTID = #{tenantId} AND DATE(ZYSQSJ) = CURDATE() AND DHZYJB = '2') AS yjdhzy\n" +
            "CROSS JOIN \n" +
            "    (SELECT COUNT(*) AS ejdhzycount \n" +
            "     FROM asp_dhzy \n" +
            "     WHERE DELETED = 0 AND DQZT = '3' AND TENANTID = #{tenantId} AND DATE(ZYSQSJ) = CURDATE() AND DHZYJB = '3') AS ejdhzy\n" +
            "CROSS JOIN \n" +
            "    (SELECT COUNT(*) AS sxkjzycount \n" +
            "     FROM asp_sxkjzy \n" +
            "     WHERE DELETED = 0 AND DQZT = '3' AND TENANTID = #{tenantId} AND DATE(ZYSQSJ) = CURDATE()) AS sxkjzy\n" +
            "CROSS JOIN \n" +
            "    (SELECT COUNT(*) AS lsydzycount \n" +
            "     FROM asp_lsydzy\n" +
            "     WHERE DELETED = 0 AND DQZT = '3' AND TENANTID = #{tenantId} AND DATE(ZYSQSJ) = CURDATE()) AS lsydzy\n" +
            "CROSS JOIN \n" +
            "    (SELECT COUNT(*) AS gczycount \n" +
            "     FROM asp_gczy \n" +
            "     WHERE DELETED = 0 AND DQZT = '3' AND TENANTID = #{tenantId} AND DATE(ZYSQSJ) = CURDATE()) AS gczy\n" +
            "CROSS JOIN \n" +
            "    (SELECT COUNT(*) AS dzzycount \n" +
            "     FROM asp_dzzy\n" +
            "     WHERE DELETED = 0 AND DQZT = '3' AND TENANTID = #{tenantId} AND DATE(ZYSQSJ) = CURDATE()) AS dzzy\n" +
            "CROSS JOIN \n" +
            "    (SELECT COUNT(*) AS mbcdzycount \n" +
            "     FROM asp_mbcdzy\n" +
            "     WHERE DELETED = 0 AND DQZT = '3' AND TENANTID = #{tenantId} AND DATE(ZYSQSJ) = CURDATE()) AS mbcdzy\n" +
            "CROSS JOIN \n" +
            "    (SELECT COUNT(*) AS dtzycount \n" +
            "     FROM asp_dtzy\n" +
            "     WHERE DELETED = 0 AND DQZT = '3' AND TENANTID = #{tenantId} AND DATE(ZYSQSJ) = CURDATE()) AS dtzy\n" +
            "CROSS JOIN \n" +
            "    (SELECT COUNT(*) AS dlzzcount \n" +
            "     FROM asp_dlzz \n" +
            "     WHERE DELETED = 0 AND DQZT = '3' AND TENANTID = #{tenantId} AND DATE(ZYSQSJ) = CURDATE()) AS dlzz;")
    BaoAnShiDaPingDataVo getDaPingData(String tenantId);


}
