<?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.api.manage.dao.operationManagement.SysGreenAreaDao">

    <select id="list" parameterType="com.api.model.operationManagement.SearchGreenArea" resultType="com.api.vo.operationManagement.VoGreenArea">
        select sga.id,sga.name,su.actual_name as create_name,sga.create_date
        from sys_green_area as sga,sys_user as su
        <where>
            sga.create_id = su.id
            <if test="name != null and name != ''">
                and sga.name like concat('%',#{name},'%')
            </if>
            <if test="createName != null and createName != ''">
                and su.actual_name like concat('%',#{createName},'%')
            </if>
            <if test="createDateStart != null">
                and sga.create_date <![CDATA[ >= ]]> #{createDateStart}
            </if>
            <if test="createDateEnd != null">
                and sga.create_date <![CDATA[ <= ]]> #{createDateEnd}
            </if>
        </where>
        order by sga.create_date desc
    </select>

    <insert id="insert" parameterType="com.api.model.operationManagement.SysGreenArea">
        insert into sys_green_area(
            name,
            create_id,
            create_date
        )values (
            #{name},
            #{createId},
            #{createDate}
        )
    </insert>

    <select id="findById" parameterType="java.lang.Integer" resultType="com.api.vo.operationManagement.VoGreenArea">
        select sga.id,sga.name,su.actual_name as create_name,sga.create_date
        from sys_green_area as sga,sys_user as su
        where sga.create_id = su.id and sga.id = #{id}
    </select>


    <update id="update" parameterType="com.api.model.operationManagement.SysGreenArea">
        update sys_green_area
        set name = #{name},modify_id = #{modifyId},modify_date = #{modifyDate}
        where id = #{id}
    </update>

    <delete id="delete" parameterType="java.lang.Integer">
        delete from sys_green_area where id =#{id}
    </delete>

    <select id="countTaskByAreaId" parameterType="java.lang.Integer" resultType="java.lang.Integer">
        select count(*) from sys_green_task where green_area_id = #{id}
    </select>


</mapper>