<?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.ty.lift.ud.templateBase.mapper.MaintenanceSetMapper">
    <resultMap id="BaseResultMap" type="cn.com.ty.lift.ud.templateBase.mapper.entity.MaintenanceSetEntity">
        <id column="id" property="id" jdbcType="INTEGER"/>
        <result column="type" property="type" jdbcType="INTEGER"/>
        <result column="company_id" property="companyId" jdbcType="INTEGER"/>
        <result column="name" property="name" jdbcType="VARCHAR"/>
        <result column="amount" property="amount" jdbcType="INTEGER"/>
        <result column="drive_type" property="driveType" jdbcType="VARCHAR"/>
        <result column="valid_time" property="validTime" jdbcType="VARCHAR"/>
        <result column="statuz" property="statuz" jdbcType="VARCHAR"/>
        <result column="create_by" property="createBy" jdbcType="VARCHAR"/>
        <result column="create_time" property="createTime" jdbcType="TIMESTAMP"/>
        <result column="update_by" property="updateBy" jdbcType="VARCHAR"/>
        <result column="update_time" property="updateTime" jdbcType="TIMESTAMP"/>
    </resultMap>
    <sql id="Base_Column_List">
    id, type, company_id, name, amount, drive_type, valid_time,statuz,
    create_by, create_time, update_by, update_time
  </sql>


    <!--分页查询-->
    <select id="selectByQuery" resultType="cn.com.ty.lift.ud.templateBase.mapper.entity.MaintenanceSetEntity">
        select  *  from maintenance_set
        <where>
            ${ew.sqlSegment}
        </where>
        limit #{page.pageIndex},#{page.pageSize}
    </select>

    <!--查询总数量-->
    <select id="countByQuery" resultType="java.lang.Integer">
        select  count(0)  from maintenance_set
        <where>
            ${ew.sqlSegment}
        </where>
    </select>

    <!--新增-->
    <insert id="saveInfo" parameterType="cn.com.ty.lift.ud.templateBase.mapper.entity.MaintenanceSetEntity">
             insert into maintenance_set
             <trim prefix="(" suffix=")" suffixOverrides=",">
                 <if test="type != null">
                     type,
                 </if>
                 <if test="name != null">
                     name,
                 </if>
                 <if test="amount != null">
                     amount,
                 </if>
                 <if test="driveType != null">
                     drive_type,
                 </if>
                 <if test="validTime != null">
                     valid_time,
                 </if>
                 <if test="statuz != null">
                     statuz,
                 </if>
                 <if test="createBy != null">
                     create_by,
                 </if>
                 <if test="createTime != null">
                     create_time
                 </if>

             </trim>
             <trim prefix="values (" suffix=")" suffixOverrides="," >
                 <if test="type != null">
                     #{type,jdbcType=INTEGER},
                 </if>
                 <if test="name != null">
                     #{name,jdbcType=VARCHAR},
                 </if>
                 <if test="amount != null">
                     #{amount,jdbcType=INTEGER},
                 </if>
                 <if test="driveType != null">
                     #{driveType,jdbcType=VARCHAR},
                 </if>
                 <if test="validTime != null">
                     #{validTime,jdbcType=VARCHAR},
                 </if>
                 <if test="statuz != null">
                     #{statuz,jdbcType=VARCHAR},
                 </if>
                 <if test="createBy != null">
                     #{createBy,jdbcType=INTEGER},
                 </if>
                 <if test="createTime != null">
                     #{createTime,jdbcType=TIMESTAMP}
                 </if>
             </trim>
        <!-- keyProperty="id"表示把 返回的主键值 赋值给 方法实体参数 msEntity 的id属性，通过 msEntity.getId()获取 -->
              <selectKey  resultType="long" keyProperty="id" order="AFTER"  >
                  SELECT LAST_INSERT_ID()
              </selectKey>
          </insert>

    <!--根据ID查询详情-->
    <select id="getInfoById" resultType="cn.com.ty.lift.ud.templateBase.mapper.entity.MaintenanceSetEntity">
        select se.id,se.`name` as setName,se.drive_type as driveType ,se.valid_time as validTime,
        op.item as opt,op.content as requirement,op.id as opId
        from maintenance_set se
        left join  maintenance_set_option sp on sp.set_id = se.id
        left join  maintenance_option op on op.id = sp.option_id
        where se.id = #{id}
    </select>

</mapper>



