TaskStatisticsMapper.xml 1.25 KB
<?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="com.huaheng.pc.inventory.report.mapper.TaskStatisticsMapper">

    <select id="select" resultType="com.huaheng.pc.inventory.report.domain.TaskStatisticsRep">
        select d.created,
        d.taskType,
        IFNULL(count,0)  count
        FROM
        (select created,taskType from (
        (SELECT
        @date := DATE_ADD( @date, INTERVAL + 1 DAY ) created
        FROM
        ( SELECT @date := DATE_ADD( #{startTime}, INTERVAL - 1 DAY ) FROM task_header ) time
        WHERE
        to_days( @date )  &lt; to_days( #{endTime} ) - 1) a 	INNER JOIN (select taskType from taskType) type  )  where 1=1
        <if test="taskType != null">
            and taskType = #{taskType}
        </if>
        ORDER BY	created,taskType) d
        LEFT JOIN (
        SELECT
        DATE_FORMAT( created, '%Y-%m-%d' ) created,
        taskType,
        count(1) count
        FROM
        task_header b
        GROUP BY
        DATE_FORMAT( created, '%Y-%m-%d' ),
        taskType
        ) t ON t.created = d.created 	and t.taskType = d.taskType
        ORDER BY
        d.created
    </select>
</mapper>