<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd" >
<mapper namespace="cn.iocoder.yudao.module.knowledge.mapper.KnowledgeStatisticsMapper">
    <resultMap id="BaseResultMap" type="cn.iocoder.yudao.module.knowledge.entity.TLaws">
        <id column="ID" property="id" jdbcType="BIGINT"/>
        <result column="CODE" property="code" jdbcType="VARCHAR"/>
        <result column="NAME" property="name" jdbcType="VARCHAR"/>
        <result column="VERSION" property="version" jdbcType="VARCHAR"/>
        <result column="FILE_URL" property="fileUrl" jdbcType="VARCHAR"/>
        <result column="FILE_SIZE" property="fileSize" jdbcType="VARCHAR"/>
        <result column="FILE_NAME" property="fileName" jdbcType="VARCHAR"/>
        <result column="FILE_TIME" property="filingTime" jdbcType="DATE"/>
        <result column="IS_FILING" property="isFiling" jdbcType="INTEGER"/>
        <result column="DELETED" property="deleted" jdbcType="INTEGER"/>
        <result column="CREATOR" property="creator" jdbcType="VARCHAR"/>
        <result column="CREATOR_ID" property="creatorId" jdbcType="BIGINT"/>
        <result column="CREATE_TIME" property="createTime" jdbcType="DATE"/>
        <result column="UPDATE_TIME" property="updateTime" jdbcType="DATE"/>

    </resultMap>
    <sql id="columns">
        id,template_info_id,template_data_sort,template_data_code,template_data_name,template_data_type,create_people,create_time,update_time,deleted,identity_id,dept_id,tenant_id
    </sql>
    <select id="findSum" resultType="cn.iocoder.yudao.module.knowledge.controller.responsevo.KnowledgeStatisticsvo">
        SELECT
                ( SELECT COUNT(*) FROM t_operation_document WHERE deleted = 0 ) AS "operationSum",
                ( SELECT COUNT(*) FROM t_violation_image WHERE deleted = 0 ) AS "violationSum",
                ( SELECT COUNT(*) FROM t_laws_records WHERE deleted = 0 ) AS "lawsSum",
                ( SELECT COUNT(*) FROM t_regulatory_framework_records WHERE deleted = 0 ) AS "rulesSum"
    </select>

    <select id="findCompare" resultType="cn.iocoder.yudao.module.knowledge.controller.responsevo.KnowledgeStatisticsvo">
        SELECT
            ( SELECT COUNT(*) FROM t_operation_document WHERE DATE_FORMAT( create_time, '%Y-%m' ) = DATE_FORMAT( NOW(), '%Y-%m' ) AND deleted = 0 ) AS "curMonthOperationSum",
            ( SELECT COUNT(*) FROM t_operation_document WHERE DATE_FORMAT( create_time, '%Y-%m' ) = DATE_FORMAT( NOW() - INTERVAL 1 MONTH, '%Y-%m' ) AND deleted = 0 ) AS "lastMonthOperationSum",
            ( SELECT COUNT(*) FROM t_violation_image WHERE DATE_FORMAT( create_time, '%Y-%m' ) = DATE_FORMAT( NOW(), '%Y-%m' ) AND deleted = 0 ) AS "curMonthViolationSum",
            ( SELECT COUNT(*) FROM t_violation_image WHERE DATE_FORMAT( create_time, '%Y-%m' ) = DATE_FORMAT( NOW() - INTERVAL 1 MONTH, '%Y-%m' ) AND deleted = 0 ) AS "lastMonthViolationSum",
            ( SELECT COUNT(*) FROM t_laws_records WHERE DATE_FORMAT( create_time, '%Y-%m' ) = DATE_FORMAT( NOW(), '%Y-%m' ) AND deleted = 0 ) AS "curMonthLawsSum",
            ( SELECT COUNT(*) FROM t_laws_records WHERE DATE_FORMAT( create_time, '%Y-%m' ) = DATE_FORMAT( NOW() - INTERVAL 1 MONTH, '%Y-%m' ) AND deleted = 0 ) AS "lastMonthLawsSum",
            ( SELECT COUNT(*) FROM t_regulatory_framework_records WHERE DATE_FORMAT( create_time, '%Y-%m' ) = DATE_FORMAT( NOW(), '%Y-%m' ) AND deleted = 0 ) AS "curMonthRulesSum",
            ( SELECT COUNT(*) FROM t_regulatory_framework_records WHERE DATE_FORMAT( create_time, '%Y-%m' ) = DATE_FORMAT( NOW() - INTERVAL 1 MONTH, '%Y-%m' ) AND deleted = 0 ) AS "lastMonthRulesSum"
    </select>

    <select id="learningProgressCount" resultType="cn.iocoder.yudao.module.knowledge.controller.responsevo.KnowledgeStatisticsvo">
        SELECT NOW() AS "date" ,
               1 AS completed,
               100 AS notCompleted
    </select>

    <select id="trainingStatistics" resultType="cn.iocoder.yudao.module.knowledge.controller.responsevo.KnowledgeStatisticsvo">
        SELECT
            10 AS num,
            100 AS percentOfPass
    </select>

    <select id="headCardListStatistics" resultType="cn.iocoder.yudao.module.knowledge.controller.responsevo.KnowledgeHeadCardListStatisticsvo">
        SELECT
                ( SELECT COUNT(*) FROM t_course WHERE deleted = 0 ) AS "numberOfCourses",
                ( SELECT COUNT(*) FROM t_laws_records WHERE deleted = 0 ) AS "numberOfStudents",
                ( ( SELECT COUNT(*) FROM t_bid_confirmation WHERE deleted = 0)+( SELECT COUNT(*) FROM t_bid_plan WHERE deleted = 0)) AS "numberOfBids",
                ( SELECT COUNT(*) FROM t_test_paper_answer_sheet WHERE deleted = 0 ) AS "numberOfExams",
                ( SELECT COUNT(*) FROM t_train_record WHERE deleted = 0 ) AS "numberOfTrainings"
    </select>


    <select id="violationStatistics" resultType="cn.iocoder.yudao.module.knowledge.controller.responsevo.KnowledgeChartsStatisticsvo">
        SELECT DATE_FORMAT(months.month, '%m月') AS name,
               COUNT(t_violation.violation_time) AS value
        FROM (
            SELECT DATE_SUB(DATE_FORMAT(CURRENT_DATE(), '%Y-%m-01'), INTERVAL n MONTH) AS month
            FROM (
            SELECT 0 AS n UNION ALL SELECT 1 UNION ALL SELECT 2 UNION ALL SELECT 3 UNION ALL SELECT 4 UNION ALL SELECT 5
            ) AS months
            ) AS months
            LEFT JOIN t_violation ON DATE_FORMAT(t_violation.violation_time, '%Y-%m') = DATE_FORMAT(months.month, '%Y-%m') AND t_violation.deleted = 0
        GROUP BY DATE_FORMAT(months.month, '%m月')
        ORDER BY name DESC
    </select>
    <select id="lawsStatistics" resultType="cn.iocoder.yudao.module.knowledge.controller.responsevo.KnowledgeChartsStatisticsvo">
        SELECT DATE_FORMAT(months.month, '%m月') AS name,
               COUNT(t_laws.create_time) AS value
        FROM (
                 SELECT DATE_SUB(DATE_FORMAT(CURRENT_DATE(), '%Y-%m-01'), INTERVAL n MONTH) AS month
                 FROM (
                          SELECT 0 AS n UNION ALL SELECT 1 UNION ALL SELECT 2 UNION ALL SELECT 3 UNION ALL SELECT 4 UNION ALL SELECT 5
                      ) AS months
             ) AS months
                 LEFT JOIN t_laws ON DATE_FORMAT(t_laws.create_time, '%Y-%m') = DATE_FORMAT(months.month, '%Y-%m') AND t_laws.deleted = 0
        GROUP BY DATE_FORMAT(months.month, '%m月')
        ORDER BY name DESC
    </select>
    <select id="regulationsStatistics" resultType="cn.iocoder.yudao.module.knowledge.controller.responsevo.KnowledgeChartsStatisticsvo">
        SELECT DATE_FORMAT(months.month, '%m月') AS name,
               COUNT(t_regulatory_framework.create_time) AS value
        FROM (
                 SELECT DATE_SUB(DATE_FORMAT(CURRENT_DATE(), '%Y-%m-01'), INTERVAL n MONTH) AS month
                 FROM (
                          SELECT 0 AS n UNION ALL SELECT 1 UNION ALL SELECT 2 UNION ALL SELECT 3 UNION ALL SELECT 4 UNION ALL SELECT 5
                      ) AS months
             ) AS months
                 LEFT JOIN t_regulatory_framework ON DATE_FORMAT(t_regulatory_framework.create_time, '%Y-%m') = DATE_FORMAT(months.month, '%Y-%m') AND t_regulatory_framework.deleted = 0
        GROUP BY DATE_FORMAT(months.month, '%m月')
        ORDER BY name DESC
    </select>
    <select id="lawsStatisticsNew" resultType="cn.iocoder.yudao.module.knowledge.controller.responsevo.KnowledgeChartsStatisticsvo">
        SELECT
            type_label AS name,
            type_count AS value
        FROM
            (SELECT
                 CASE
                     WHEN type = 1 THEN '法律'
                     WHEN type = 2 THEN '行政法规'
                     WHEN type = 3 THEN '部门规章'
                     WHEN type = 4 THEN '地方法规'
                     WHEN type = 5 THEN '地方规章'
                     ELSE '其他'
                     END AS type_label,
                 COUNT(*) AS type_count
             FROM t_laws
             WHERE deleted = 0
             GROUP BY type_label) AS t
    </select>
    <select id="regulationsStatisticsNew" resultType="cn.iocoder.yudao.module.knowledge.controller.responsevo.KnowledgeChartsStatisticsvo">
        SELECT
            type_label AS name,
            type_count AS value
        FROM
            (SELECT
                 CASE
                 WHEN type = 1 THEN '安全环保职业健康消防'
                     WHEN type = 2 THEN '财务与资产管理'
                     WHEN type = 3 THEN '采购销售'
                     WHEN type = 4 THEN '党、工、团、纪律监督'
                     WHEN type = 5 THEN '法律合规内审内控'
                     WHEN type = 6 THEN '科技与投资'
                     WHEN type = 7 THEN '企业文化与宣传'
                     WHEN type = 8 THEN '人力资源'
                     WHEN type = 9 THEN '社会责任'
                     WHEN type = 10 THEN '生产管理'
                     WHEN type = 11 THEN '行政管理'
                     ELSE '其他'
                     END AS type_label,
                 COUNT(*) AS type_count
             FROM t_regulatory_framework
             WHERE deleted = 0
             GROUP BY type_label) AS t
    </select>
    <select id="bidConfirmationStatistics" resultType="cn.iocoder.yudao.module.knowledge.controller.responsevo.KnowledgeChartsStatisticsvo">
        SELECT DATE_FORMAT(months.month, '%m月') AS name,
               COUNT(t_bid_confirmation.create_time) AS value
        FROM (
                 SELECT DATE_SUB(DATE_FORMAT(CURRENT_DATE(), '%Y-%m-01'), INTERVAL n MONTH) AS month
                 FROM (
                          SELECT 0 AS n UNION ALL SELECT 1 UNION ALL SELECT 2 UNION ALL SELECT 3 UNION ALL SELECT 4 UNION ALL SELECT 5
                      ) AS months
             ) AS months
                 LEFT JOIN t_bid_confirmation ON DATE_FORMAT(t_bid_confirmation.create_time, '%Y-%m') = DATE_FORMAT(months.month, '%Y-%m') AND t_bid_confirmation.deleted = 0
        GROUP BY DATE_FORMAT(months.month, '%m月')
        ORDER BY name DESC
    </select>
    <select id="bidPlanStatistics" resultType="cn.iocoder.yudao.module.knowledge.controller.responsevo.KnowledgeChartsStatisticsvo">
        SELECT DATE_FORMAT(months.month, '%m月') AS name,
               COUNT(t_bid_plan.create_time) AS value
        FROM (
                 SELECT DATE_SUB(DATE_FORMAT(CURRENT_DATE(), '%Y-%m-01'), INTERVAL n MONTH) AS month
                 FROM (
                          SELECT 0 AS n UNION ALL SELECT 1 UNION ALL SELECT 2 UNION ALL SELECT 3 UNION ALL SELECT 4 UNION ALL SELECT 5
                      ) AS months
             ) AS months
                 LEFT JOIN t_bid_plan ON DATE_FORMAT(t_bid_plan.create_time, '%Y-%m') = DATE_FORMAT(months.month, '%Y-%m') AND t_bid_plan.deleted = 0
        GROUP BY DATE_FORMAT(months.month, '%m月')
        ORDER BY name DESC
    </select>
    <select id="lessonDailyStatistics" resultType="HashMap">
        SELECT
            ttpas.score AS score,
            ttpi.pass_score AS passScore
        FROM
            t_test_paper_answer_sheet ttpas
        LEFT JOIN
            t_test_paper_info ttpi ON ttpas.test_paper_info_id = ttpi.id
        WHERE
              ttpas.deleted = 0
    </select>

    <select id="lessonDailyCompleteStatistics" resultType="HashMap">
        SELECT
            ttpas.score AS score
        FROM
            t_test_paper_answer_sheet ttpas
        WHERE
              ttpas.deleted = 0
    </select>

    <select id="lessonDailyCompleteSstatistics" resultType="HashMap">
        SELECT
            ttpas.score AS score,
            ttpi.pass_score AS passScore
        FROM
            t_test_paper_answer_sheet ttpas
                LEFT JOIN
            t_test_paper_info ttpi ON ttpas.test_paper_info_id = ttpi.id
        WHERE
            ttpas.deleted = 0
    </select>
</mapper>

