StatisticsDriveMapper.xml 1.85 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="cn.com.glsx.stdinterface.modules.mapper.StatisticsDriveMapper">

    <resultMap id="BaseResultMap" type="cn.com.glsx.stdinterface.modules.entity.StatisticsDrive">
        <id property="id" column="id" jdbcType="INTEGER"/>
        <result property="sn" column="sn" jdbcType="VARCHAR"/>
        <result property="driveNum" column="drive_num" jdbcType="INTEGER"/>
        <result property="driveTotal" column="drive_total" jdbcType="INTEGER"/>
        <result property="driveTime" column="drive_time" jdbcType="VARCHAR"/>
        <result property="createdTime" column="created_time" jdbcType="TIMESTAMP"/>
        <result property="updatedTime" column="updated_time" jdbcType="TIMESTAMP"/>
    </resultMap>

    <sql id="Base_Column_List">
        id,sn,drive_num,
        drive_time,created_time,updated_time
    </sql>

    <select id="statisticsDriveDataEveryDay" resultType="cn.com.glsx.stdinterface.dto.StatisticsDriveDto">
        select sn,
        sum(case when percent >= 50 then 1 else 0 end) as driveNum,
        count(1) as driveTotal,
        left(journey_time,10) as driveTime
        from t_electric_fence_drive
        where left(journey_time,10) = #{yesterDayFormat}
        GROUP BY sn
    </select>

    <insert id="statisticsAndInsertDriveDataEveryDay">
        INSERT t_statistics_fence_drive (sn ,drive_num ,drive_total ,drive_time ,vd_id ,created_time)
        select sn ,
        sum(case when percent >= 50 then 1 else 0 end) as driveNum ,
        count(1) as driveTotal ,
        left(journey_time,10) as driveTime ,
        vd_id ,
        NOW()
        from t_electric_fence_drive
        where left(journey_time,10) = #{yesterDayFormat}
        GROUP BY sn;
    </insert>
</mapper>