<?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.ruoyi.system.mapper_shate.SeedingSuccessMapper">
    <resultMap id="RM_Seeding" type="com.ruoyi.system.domain_shate.SeedingSuccessRate">

        <result property="id" column="id"/>
        <result property="zone" column="zone"/>
        <result property="plantingArea" column="Planting_area"/>
        <result property="seedingSuccessArea" column="Seeding_success_area"/>
        <result property="seedingSuccess" column="seeding_success"/>
        <result property="imageDate" column="Image_date"/>
        <result property="productCode1" column="productCode1"/>
        <result property="productCode2" column="Product_code2"/>
        <result property="productCode3" column="Product_code3"/>
        <result property="year" column="year1"/>
        <result property="createdBy" column="created_by"/>
        <result property="createdTime" column="created_time"/>

    </resultMap>

    <sql id="columns">
	    <![CDATA[
        ID,zone,year1,Planting_area,Seeding_success_area,seeding_success,Image_date,Product_code1,Product_code2,Product_code3,created_by,created_time
        ]]>
	</sql>

    <select id="sqlSeeding" resultMap="RM_Seeding">
        select distinct a.product_code2 as Product_code2,
                        a.zone as zone,
                        a.seeding_success_rate as seeding_success,
                        a.product_code1 as productCode1,
                        a.image_date as Image_date,
                        b.seeding_success_area as Seeding_success_area,
                        b.product_code2 as Product_code3,
                        a.year1 as year1
        from "seed_Success" a
            left join "vegetation_Distribution" b
            on a.image_date=b.image_date
            and a.zone=b.zone
        WHERE 1=1
        <if test="zone!= null and zone !=''">
            AND a.zone = #{zone}
        </if>
        <if test="year!= null and year !=''">
            AND a.year1 = #{year}
        </if>
    </select>

    <select id="sqlYear" resultMap="RM_Seeding">
        SELECT  distinct year1,ZONE  FROM  "seed_Success"
    </select>

    <insert id="InsertSeeding2">
        <![CDATA[
        INSERT INTO "vegetation_Distribution" (
            zone ,
            Seeding_success_area ,
            image_date,
            Product_code1 ,
            Product_code2
        ) VALUES (
                     #{zone,jdbcType=VARCHAR},
                     #{seedingSuccessArea,jdbcType=DOUBLE},
                     #{imageDate,jdbcType=VARCHAR},
                     #{productCode1,jdbcType=VARCHAR},
                     #{productCode2,jdbcType=VARCHAR}
                 )
        ]]>
    </insert>

    <insert id="InsertSeeding1">
        <![CDATA[
        INSERT INTO "seed_Success" (
            zone ,
            seeding_Success_Rate ,
            Image_date ,
            Product_code1 ,
            year1 ,
            Product_code2
        ) VALUES (
                     #{zone,jdbcType=VARCHAR},
                     #{seedingSuccess,jdbcType=DOUBLE},
                     #{imageDate,jdbcType=VARCHAR},
                     #{productCode1,jdbcType=VARCHAR},
                     #{year,jdbcType=VARCHAR},
                     #{productCode2,jdbcType=VARCHAR}
                 )
        ]]>
    </insert>

    <delete id="Delete">
        DELETE FROM #{name}
        WHERE zone = #{zone}
        and image_date =#{imageDate}
    </delete>
</mapper>