DevicePowerMapper.xml 4.45 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.app.modules.mapper.DevicePowerMapper">
    <resultMap id="BaseResultMap" type="cn.com.glsx.app.modules.entity.DevicePower">
        <!--
          WARNING - @mbg.generated
        -->
        <id column="id" jdbcType="INTEGER" property="id"/>
        <result column="sn" jdbcType="VARCHAR" property="sn"/>
        <result column="vd_id" jdbcType="INTEGER" property="vdId"/>
        <result column="alarm_time" jdbcType="TIMESTAMP" property="alarmTime"/>
        <result column="soc" jdbcType="INTEGER" property="soc"/>
        <result column="del_flag" jdbcType="TINYINT" property="delFlag"/>
        <result column="created_date" jdbcType="TIMESTAMP" property="createdDate"/>
        <result column="created_by" jdbcType="INTEGER" property="createdBy"/>
        <result column="updated_date" jdbcType="TIMESTAMP" property="updatedDate"/>
        <result column="updated_by" jdbcType="INTEGER" property="updatedBy"/>
    </resultMap>

    <resultMap id="DevicePowerMap" type="cn.com.glsx.app.modules.model.domain.DevicePowerDO">
        <result column="sn" jdbcType="VARCHAR" property="sn"/>
        <result column="alarm_time" jdbcType="TIMESTAMP" property="alarmTime"/>
        <result column="soc" jdbcType="INTEGER" property="soc"/>
        <result column="owner_name" jdbcType="TINYINT" property="ownerName"/>
        <result column="vin" jdbcType="TIMESTAMP" property="vin"/>
        <result column="id" jdbcType="INTEGER" property="vehicleId"/>
        <result column="license_plate" jdbcType="VARCHAR" property="licensePlate"/>
    </resultMap>


    <sql id="Base_Column_List">
        <!--
          WARNING - @mbg.generated
        -->
        id, sn, vd_id, alarm_time, soc, del_flag, created_date, created_by, updated_date,
        updated_by
    </sql>

    <select id="selectBySn" resultMap="BaseResultMap">
        select
        <include refid="Base_Column_List"/>
        from t_device_power
        <where>
            and sn = #{sn}
            and vd_id = #{vdId}
            and del_flag = 0
        </where>
        limit 1
    </select>

    <select id="listBySn" resultMap="BaseResultMap">
        select
        <include refid="Base_Column_List"/>
        from t_device_power
        <where>
            and sn in
            <foreach collection="sns" item="item" index="index" open="(" close=")" separator=",">
                #{item}
            </foreach>
        </where>
    </select>

    <insert id="insertOrUpdateBatch" keyProperty="id" useGeneratedKeys="true">
        insert into t_device_power(sn, vd_id, alarm_time, soc, del_flag, created_date, created_by, updated_date,
        updated_by)
        values
        <foreach collection="entities" item="entity" separator=",">
            (#{entity.sn}, #{entity.vdId}, #{entity.alarmTime}, #{entity.soc}, #{entity.delFlag}, #{entity.createdDate},
            #{entity.createdBy}, #{entity.updatedDate}, #{entity.updatedBy})
        </foreach>
        on duplicate key update
        sn = values(sn),
        vd_id = values(vd_id),
        alarm_time = values(alarm_time),
        soc = values(soc),
        del_flag = values(del_flag),
        created_date = values(created_date),
        created_by = values(created_by),
        updated_date = values(updated_date),
        updated_by = values(updated_by)
    </insert>


    <select id="listBindDevicePowerByCondition" resultMap="DevicePowerMap">
        select tvd.sn,
        tv.owner_name,
        tv.vin,
        tv.id,
        tv.license_plate,
        tv.created_date as createdDate,
        tdp.alarm_time
        from t_vehicle tv
        left join t_vehicle_device tvd on tvd.vehicle_id = tv.id
        left join t_device_power tdp on tvd.id = tdp.vd_id
        <where>
            and tdp.id is not null
            and tvd.del_flag = 0
            and tvd.bind_status = 1
            <if test="startTime != null">
                and tdp.alarm_time <![CDATA[ >= ]]> #{startTime}
            </if>
            <if test="endTime != null">
                and tdp.alarm_time <![CDATA[ <= ]]> #{endTime}
            </if>
            <if test="minBattery != null">
                and tdp.soc <![CDATA[ >= ]]> #{minBattery}
            </if>
            <if test="maxBattery != null">
                and tdp.soc <![CDATA[ < ]]> #{maxBattery}
            </if>
        </where>
        order by createdDate desc
    </select>

</mapper>