<?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.yunfeiyun.agmp.fms.mapper.FmsSolarMapper">
    
    <resultMap type="FmsSolar" id="FmsSolarResult">
        <result property="solarId"    column="solarId"    />
        <result property="solarName"    column="solarName"    />
        <result property="solarRemark"    column="solarRemark"    />
        <result property="solarStartdate"    column="solarStartdate"    />
        <result property="solarDigest"    column="solarDigest"    />
    </resultMap>

    <sql id="selectFmsSolarVo">
        select solarId, solarName, solarRemark, solarStartdate, solarDigest from FmsSolar
    </sql>

    <select id="selectFmsSolarList" parameterType="FmsSolar" resultMap="FmsSolarResult">
        <include refid="selectFmsSolarVo"/>
        <where>  
            <if test="solarName != null  and solarName != ''"> and solarName like concat('%', #{solarName}, '%')</if>
            <if test="solarRemark != null  and solarRemark != ''"> and solarRemark = #{solarRemark}</if>
            <if test="solarStartdate != null  and solarStartdate != ''"> and solarStartdate = #{solarStartdate}</if>
            <if test="solarDigest != null  and solarDigest != ''"> and solarDigest = #{solarDigest}</if>
        </where>
    </select>

    <select id="selectFmsSolarBySolarId" parameterType="String" resultMap="FmsSolarResult">
        <include refid="selectFmsSolarVo"/>
        where solarId = #{solarId}
    </select>
    <select id="selectFmsSolarBySolarName" parameterType="String" resultMap="FmsSolarResult">
        <include refid="selectFmsSolarVo"/>
        where solarName = #{solarName}
    </select>

    <select id="getFmsSolarByDate" parameterType="String" resultMap="FmsSolarResult">
        <include refid="selectFmsSolarVo"/>
        <where>
            <if test="date != null and date != ''">and solarStartdate &lt;= #{date}</if>
        </where>
        order by solarStartdate desc limit 1
    </select>

    <select id="getSysZoneByZoneCode" parameterType="String" resultType="map">
        select zoneCode, zoneProvincezh, zoneCapitalzh from SysZone where zoneCode = #{zoneCode}
    </select>
        
    <insert id="insertFmsSolar" parameterType="FmsSolar">
        insert into FmsSolar
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="solarId != null">solarId,</if>
            <if test="solarName != null">solarName,</if>
            <if test="solarRemark != null">solarRemark,</if>
            <if test="solarStartdate != null">solarStartdate,</if>
            <if test="solarDigest != null">solarDigest,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="solarId != null">#{solarId},</if>
            <if test="solarName != null">#{solarName},</if>
            <if test="solarRemark != null">#{solarRemark},</if>
            <if test="solarStartdate != null">#{solarStartdate},</if>
            <if test="solarDigest != null">#{solarDigest},</if>
         </trim>
    </insert>

    <update id="updateFmsSolar" parameterType="FmsSolar">
        update FmsSolar
        <trim prefix="SET" suffixOverrides=",">
            <if test="solarRemark != null">solarRemark = #{solarRemark},</if>
            <if test="solarStartdate != null">solarStartdate = #{solarStartdate},</if>
            <if test="solarDigest != null">solarDigest = #{solarDigest},</if>
        </trim>
        where solarName = #{solarName}
    </update>
    <update id="updateFmsSolarByBatch" parameterType="FmsSolar">
        <foreach collection="fmsSolarList" item="item" >
        update FmsSolar
        <trim prefix="SET" suffixOverrides=",">
            <if test="item.solarRemark != null">solarRemark = #{item.solarRemark},</if>
            <if test="item.solarStartdate != null">solarStartdate = #{item.solarStartdate},</if>
            <if test="item.solarDigest != null">solarDigest = #{item.solarDigest},</if>
        </trim>
        where solarName = #{item.solarName};
        </foreach>
    </update>

    <delete id="deleteFmsSolarBySolarId" parameterType="String">
        delete from FmsSolar where solarId = #{solarId}
    </delete>

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