<?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.zehong.system.mapper.TMaintainPlanMapper">
    
    <resultMap type="TMaintainPlanVo" id="TMaintainPlanResult">
        <result property="id"    column="id"    />
        <result property="planName"    column="plan_name"    />
        <result property="planCode"    column="plan_code"    />
        <result property="deviceId"    column="device_id"    />
        <result property="planStartTime"    column="plan_start_time"    />
        <result property="planEndTime"    column="plan_end_time"    />
        <result property="maintainContent"    column="maintain_content"    />
        <result property="planStatus"    column="plan_status"    />
        <result property="isDel"    column="is_del"    />
        <result property="createTime"    column="create_time"    />
        <result property="updateTime"    column="update_time"    />
        <result property="remarks"    column="remarks"    />
    </resultMap>

    <select id="getMaintainPlanCode" resultType="String">
        select nextval('seq_maintain_plan_code') as plan_code
    </select>

    <sql id="selectTMaintainPlanVo">
        select id, plan_name, plan_code, device_id, plan_start_time, plan_end_time, maintain_content, plan_status, is_del, create_time, update_time, remarks from t_maintain_plan
    </sql>

    <select id="selectTMaintainPlanList" parameterType="TMaintainPlan" resultMap="TMaintainPlanResult">
        <include refid="selectTMaintainPlanVo"/>
        <where>  is_del = '0'
            <if test="planName != null  and planName != ''"> and plan_name like concat('%', #{planName}, '%')</if>
            <if test="planCode != null  and planCode != ''"> and plan_code like concat('%', #{planCode}, '%')</if>
            <if test="planStartTime != null "> and plan_start_time = #{planStartTime}</if>
            <if test="planEndTime != null "> and plan_end_time = #{planEndTime}</if>
            <if test="maintainContent != null  and maintainContent != ''"> and maintain_content = #{maintainContent}</if>
            <if test="planStatus != null  and planStatus != ''"> and plan_status = #{planStatus}</if>
            <if test="params.beginTime != null and params.beginTime != ''"><!-- 开始时间检索 -->
                AND date_format(create_time,'%y%m%d') &gt;= date_format(#{params.beginTime},'%y%m%d')
            </if>
            <if test="params.endTime != null and params.endTime != ''"><!-- 结束时间检索 -->
                AND date_format(create_time,'%y%m%d') &lt;= date_format(#{params.endTime},'%y%m%d')
            </if>
        </where>
    </select>
    
    <select id="selectTMaintainPlanById" parameterType="Long" resultMap="TMaintainPlanResult">
        <include refid="selectTMaintainPlanVo"/>
        where id = #{id}
    </select>
        
    <insert id="insertTMaintainPlan" parameterType="TMaintainPlan" useGeneratedKeys="true" keyProperty="id">
        insert into t_maintain_plan
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="planName != null">plan_name,</if>
            <if test="planCode != null">plan_code,</if>
            <if test="deviceId != null">device_id,</if>
            <if test="planStartTime != null">plan_start_time,</if>
            <if test="planEndTime != null">plan_end_time,</if>
            <if test="maintainContent != null">maintain_content,</if>
            <if test="planStatus != null">plan_status,</if>
            <if test="isDel != null">is_del,</if>
            <if test="createTime != null">create_time,</if>
            <if test="updateTime != null">update_time,</if>
            <if test="remarks != null">remarks,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="planName != null">#{planName},</if>
            <if test="planCode != null">#{planCode},</if>
            <if test="deviceId != null">#{deviceId},</if>
            <if test="planStartTime != null">#{planStartTime},</if>
            <if test="planEndTime != null">#{planEndTime},</if>
            <if test="maintainContent != null">#{maintainContent},</if>
            <if test="planStatus != null">#{planStatus},</if>
            <if test="isDel != null">#{isDel},</if>
            <if test="createTime != null">#{createTime},</if>
            <if test="updateTime != null">#{updateTime},</if>
            <if test="remarks != null">#{remarks},</if>
         </trim>
    </insert>

    <update id="updateTMaintainPlan" parameterType="TMaintainPlan">
        update t_maintain_plan
        <trim prefix="SET" suffixOverrides=",">
            <if test="planName != null">plan_name = #{planName},</if>
            <if test="planCode != null">plan_code = #{planCode},</if>
            <if test="deviceId != null">device_id = #{deviceId},</if>
            <if test="planStartTime != null">plan_start_time = #{planStartTime},</if>
            <if test="planEndTime != null">plan_end_time = #{planEndTime},</if>
            <if test="maintainContent != null">maintain_content = #{maintainContent},</if>
            <if test="planStatus != null">plan_status = #{planStatus},</if>
            <if test="isDel != null">is_del = #{isDel},</if>
            <if test="createTime != null">create_time = #{createTime},</if>
            <if test="updateTime != null">update_time = #{updateTime},</if>
            <if test="remarks != null">remarks = #{remarks},</if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteTMaintainPlanById" parameterType="Long">
        delete from t_maintain_plan where id = #{id}
    </delete>

    <delete id="deleteTMaintainPlanByIds" parameterType="String">
        delete from t_maintain_plan where id in 
        <foreach item="id" collection="array" open="(" separator="," close=")">
            #{id}
        </foreach>
    </delete>
</mapper>