<?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.gyee.wisdom.alarm.sharding.mapper.WindturbineMapper">
    <resultMap id="BaseResultMap" type="com.gyee.wisdom.alarm.sharding.entity.Windturbine">
        <result column="id" jdbcType="VARCHAR" property="id" />
        <result column="code" jdbcType="VARCHAR" property="code" />
        <result column="windpowerstationid" jdbcType="VARCHAR" property="windpowerstationid" />
        <result column="longitude" jdbcType="DECIMAL" property="longitude" />
        <result column="latitude" jdbcType="DECIMAL" property="latitude" />
        <result column="modelid" jdbcType="VARCHAR" property="modelid" />
        <result column="status" jdbcType="VARCHAR" property="status" />
        <result column="projectid" jdbcType="VARCHAR" property="projectid" />
        <result column="lineid" jdbcType="VARCHAR" property="lineid" />
        <result column="firstintegratedtime" jdbcType="TIMESTAMP" property="firstintegratedtime" />
        <result column="photo" jdbcType="VARCHAR" property="photo" />
        <result column="name" jdbcType="VARCHAR" property="name" />
        <result column="standardid" jdbcType="INTEGER" property="standardid" />
    </resultMap>

    <sql id="Base_Column_List">
        id,
       	  	      	code,
       	  	      	windpowerstationid,
       	  	      	longitude,
       	  	      	latitude,
       	  	      	modelid,
       	  	      	status,
       	  	      	projectid,
       	  	      	lineid,
       	  	      	firstintegratedtime,
       	  	      	photo,
       	  	      	name,
       	  	    	  	standardid
    </sql>

    <select id="selectWindturbines" parameterType="java.util.Map" resultType="com.gyee.wisdom.alarm.sharding.entity.Windturbine"  >
        select * from windturbine
    </select>

    <select id="selectByPrimaryKey" parameterType="java.lang.String" resultMap="BaseResultMap">
        select
        <include refid="Base_Column_List" />
        from windturbine
        where id = #{id,jdbcType=VARCHAR}
    </select>

    <select id="selectWindturbineByCondition" parameterType="java.util.Map" resultType="com.gyee.wisdom.alarm.sharding.entity.Windturbine"  >
        select * from windturbine a

        <where>
            1=1
            <if test="stationId !=null and stationId !=''">
                and a.windpowerstationid = #{stationId}
            </if>
            <if test="modelId !=null and modelId !=''">
                and a.modelId = #{modelId}
            </if>
        </where>
    </select>

    <select id="selectWindturbineByCondition2" parameterType="java.util.Map"  resultType="com.gyee.wisdom.alarm.sharding.entity.Windturbine"  >
        select * from windturbine a
        <where>
            <if test="stationId !=null and stationId !=''">
                 a.windpowerstationid = #{stationId}
            </if>
        </where>
    </select>

    <select id="selectByExample" parameterType="com.gyee.wisdom.alarm.sharding.model.WindturbineExample" resultMap="BaseResultMap">
        select
        <if test="distinct">
            distinct
        </if>
        <include refid="Base_Column_List" />
        from windturbine
        <if test="_parameter != null">
            <include refid="Example_Where_Clause" />
        </if>
        <if test="orderByClause != null">
            order by ${orderByClause}
        </if>
    </select>

    <sql id="Example_Where_Clause">
        <where>
            <foreach collection="oredCriteria" item="criteria" separator="or">
                <if test="criteria.valid">
                    <trim prefix="(" prefixOverrides="and" suffix=")">
                        <foreach collection="criteria.criteria" item="criterion">
                            <choose>
                                <when test="criterion.noValue">
                                    and ${criterion.condition}
                                </when>
                                <when test="criterion.singleValue">
                                    and ${criterion.condition} #{criterion.value}
                                </when>
                                <when test="criterion.betweenValue">
                                    and ${criterion.condition} #{criterion.value} and #{criterion.secondValue}
                                </when>
                                <when test="criterion.listValue">
                                    and ${criterion.condition}
                                    <foreach close=")" collection="criterion.value" item="listItem" open="(" separator=",">
                                        #{listItem}
                                    </foreach>
                                </when>
                            </choose>
                        </foreach>
                    </trim>
                </if>
            </foreach>
        </where>
    </sql>
</mapper>
