<?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.steerinfo.ems.tcm0325.mapper.TCm0325Mapper">
  <resultMap id="BaseResultMap" type="com.steerinfo.ems.tcm0325.model.TCm0325">
    <!-- <id column="TIMEGRANID" jdbcType="VARCHAR" property="timegranid" />
        <id column="ITEMID" jdbcType="VARCHAR" property="itemid" /> -->
    <result column="RECORDID" jdbcType="VARCHAR" property="recordid" />
    <result column="USESTATE" jdbcType="VARCHAR" property="usestate" />
    <result column="POWERCODE" jdbcType="VARCHAR" property="powercode" />
    <result column="POWERNAME" jdbcType="VARCHAR" property="powername" />
    <result column="POWERDETECDEPARTMENT" jdbcType="VARCHAR" property="powerdetecdepartment" />
    <result column="SORT" jdbcType="DECIMAL" property="sort" />
  </resultMap>

  <select id="selectByParameters" parameterType="java.util.HashMap" resultMap="BaseResultMap">
    select RECORDID, USESTATE, POWERCODE, POWERNAME, POWERDETECDEPARTMENT, SORT
      from T_CM_0325
    <where>
      <if test="powercode != null and powercode != ''">
          and POWERCODE like '%${powercode}%'
        </if>
      <if test="powername != null and powername != ''">
          and POWERNAME like '%${powername}%'
        </if>
      <if test="powerdetecdepartment != null and powerdetecdepartment != ''">
          and POWERDETECDEPARTMENT = #{powerdetecdepartment}
        </if>
      <if test="usestate != null and usestate != ''">
        and USESTATE = #{usestate}
      </if>
    </where>
    order by SORT
  </select>

  <select id="selectLikeByParameters" parameterType="java.util.HashMap" resultMap="BaseResultMap">
    select RECORDID, USESTATE, POWERCODE, POWERNAME, POWERDETECDEPARTMENT, SORT
      from T_CM_0325
    <where>
      <if test="recordid != null and recordid != ''">
        and RECORDID LIKE '%${recordid}%'
      </if>
      <if test="usestate != null and usestate != ''">
        and USESTATE = #{usestate}
      </if>
      <if test="powercode != null and powercode != ''">
        and POWERCODE LIKE '%${powercode}%'
      </if>
      <if test="powername != null and powername != ''">
        and POWERNAME LIKE '%${powername}%'
      </if>
      <if test="powerdetecdepartment != null and powerdetecdepartment != ''">
        and POWERDETECDEPARTMENT = #{powerdetecdepartment}
      </if>
      <if test="sort != null and sort != ''">
        and SORT = #{sort}
      </if>
    </where>
    order by SORT
  </select>

  <select id="selectByPrimaryKey" parameterType="java.lang.String" resultMap="BaseResultMap">
    select RECORDID, USESTATE, POWERCODE, POWERNAME, POWERDETECDEPARTMENT, SORT
    from T_CM_0325
    where POWERCODE = #{powercode,jdbcType=VARCHAR}
  </select>

  <select id="getCodeAndName" parameterType="java.lang.String" resultMap="BaseResultMap">
    select POWERCODE, POWERNAME
    from T_CM_0325
  </select>

  <insert id="insert" parameterType="com.steerinfo.ems.tcm0325.model.TCm0325">
    insert into T_CM_0325
    <trim prefix="(" suffix=")" suffixOverrides=",">
      <if test="recordid != null">
        RECORDID,
      </if>
      <if test="usestate != null">
        USESTATE,
      </if>
      <if test="powercode != null">
        POWERCODE,
      </if>
      <if test="powername != null">
        POWERNAME,
      </if>
      <if test="powerdetecdepartment != null">
        POWERDETECDEPARTMENT,
      </if>
      <if test="sort != null">
        SORT,
      </if>
    </trim>
    <trim prefix="values (" suffix=")" suffixOverrides=",">
      <if test="recordid != null">
        #{recordid,jdbcType=VARCHAR},
      </if>
      <if test="usestate != null">
        #{usestate,jdbcType=VARCHAR},
      </if>
      <if test="powercode != null">
        #{powercode,jdbcType=VARCHAR},
      </if>
      <if test="powername != null">
        #{powername,jdbcType=VARCHAR},
      </if>
      <if test="powerdetecdepartment != null">
        #{powerdetecdepartment,jdbcType=VARCHAR},
      </if>
      <if test="sort != null">
        #{sort,jdbcType=DECIMAL},
      </if>
    </trim>
  </insert>

  <update id="updateByPrimaryKeySelective" parameterType="com.steerinfo.ems.tcm0325.model.TCm0325">
    update T_CM_0325
    <set>
      <!-- <if test="recordid != null">
        RECORDID = #{recordid,jdbcType=VARCHAR},
      </if> -->
      <if test="usestate != null">
        USESTATE = #{usestate,jdbcType=VARCHAR},
      </if>
      <!-- <if test="powercode != null">
        POWERCODE = #{powercode,jdbcType=VARCHAR},
      </if> -->
      <if test="powername != null">
        POWERNAME = #{powername,jdbcType=VARCHAR},
      </if>
      <if test="powerdetecdepartment != null">
        POWERDETECDEPARTMENT = #{powerdetecdepartment,jdbcType=VARCHAR},
      </if>
      <if test="sort != null">
        SORT = #{sort,jdbcType=DECIMAL},
      </if>
    </set>
    where POWERCODE = #{powercode,jdbcType=VARCHAR}
  </update>

  <delete id="deleteByPrimaryKey" parameterType="java.lang.String">
    delete from T_CM_0325
    where POWERCODE = #{powercode,jdbcType=VARCHAR}
  </delete>

  <delete id="batchDelete" parameterType="java.util.List">
    delete from T_CM_0325
    where POWERCODE in 
    <foreach collection="list" item="id" open="(" close=")" separator=",">
      #{id}
    </foreach>
  </delete>

  <select id="getusestate" parameterType="java.util.HashMap" resultMap="BaseResultMap">
    select * from T_CM_0325 t join T_CM_0315 t2 on t.POWERCODE = t2.POWERSYSTEMNAME
    where t.USESTATE = 'Use'
    <if test="powercode != null and powercode !=''">
      and t.POWERCODE = #{powercode, jdbcType=VARCHAR}
    </if>
  </select>
  <select id="getMaxSort" resultType="java.lang.Long">
    select MAX(SORT) from T_CM_0325
  </select>
</mapper>