<?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.fastbee.project.mapper.ProjectMapper">

    <resultMap type="Project" id="ProjectResult">
        <result property="id"    column="id"    />
        <result property="projectName"    column="project_name"    />
        <result property="sysShowName"    column="sys_show_name"    />
        <result property="centralCoordinates"    column="central_coordinates"    />
        <result property="scope"    column="scope"    />
        <result property="administrativeArea"    column="administrative_area"    />
        <result property="owner"    column="owner"    />
        <result property="logo"    column="logo"    />
        <result property="image"    column="image"    />
        <result property="videoIntroduction"    column="video_introduction"    />
        <result property="remark"    column="remark"    />
        <result property="pParams"    column="p_params"    />
        <result property="introduce"    column="introduce"    />
        <result property="delFlag"    column="del_flag"    />
        <result property="createTime"    column="create_time"    />
        <result property="createBy"    column="create_by"    />
        <result property="updateTime"    column="update_time"    />
        <result property="remarks"    column="remarks"    />
        <result property="tenantId"    column="tenant_id"    />
        <result property="tenantName"    column="tenant_name"    />
        <result property="ownerId"    column="owner_id"    />
        <result property="parentId"    column="parent_id"    />
        <result property="deptId"    column="dept_id"    />
        <result property="administrativeAreaCode"    column="administrative_area_code"    />
        <result property="deptName"    column="dept_name"    />
        <result property="level"    column="level"    />
        <result property="provinceCode"    column="province_code"    />
        <result property="cityCode"    column="city_code"    />
        <result property="countyCode"    column="county_code"    />
        <result property="townCode"    column="town_code"    />
        <result property="villageCode"    column="village_code"    />
    </resultMap>

    <sql id="selectProjectVo">
        select id, project_name, sys_show_name, central_coordinates, scope, administrative_area, owner, logo, image, video_introduction, remark, p_params, introduce, del_flag, create_time, create_by, update_time, remarks, tenant_id, tenant_name, owner_id, parent_id, dept_id, administrative_area_code, dept_name, level, province_code, city_code, county_code, town_code, village_code from project
    </sql>

    <select id="selectProjectList" parameterType="Project" resultMap="ProjectResult">
        <include refid="selectProjectVo"/>
        <where>
            <if test="projectName != null  and projectName != ''"> and project_name like concat('%', #{projectName}, '%')</if>
            <if test="sysShowName != null  and sysShowName != ''"> and sys_show_name like concat('%', #{sysShowName}, '%')</if>
            <if test="centralCoordinates != null  and centralCoordinates != ''"> and central_coordinates = #{centralCoordinates}</if>
            <if test="scope != null  and scope != ''"> and scope = #{scope}</if>
            <if test="administrativeArea != null  and administrativeArea != ''"> and administrative_area = #{administrativeArea}</if>
            <if test="owner != null  and owner != ''"> and owner = #{owner}</if>
            <if test="logo != null  and logo != ''"> and logo = #{logo}</if>
            <if test="image != null  and image != ''"> and image = #{image}</if>
            <if test="videoIntroduction != null  and videoIntroduction != ''"> and video_introduction = #{videoIntroduction}</if>
            <if test="pParams != null  and pParams != ''"> and p_params = #{pParams}</if>
            <if test="introduce != null  and introduce != ''"> and introduce = #{introduce}</if>
            <if test="remarks != null  and remarks != ''"> and remarks = #{remarks}</if>
            <if test="tenantId != null "> and tenant_id = #{tenantId}</if>
            <if test="tenantName != null  and tenantName != ''"> and tenant_name like concat('%', #{tenantName}, '%')</if>
            <if test="ownerId != null "> and owner_id = #{ownerId}</if>
            <if test="parentId != null "> and parent_id = #{parentId}</if>
            <if test="deptId != null "> and dept_id = #{deptId}</if>
            <if test="administrativeAreaCode != null  and administrativeAreaCode != ''"> and administrative_area_code = #{administrativeAreaCode}</if>
            <if test="deptName != null  and deptName != ''"> and dept_name like concat('%', #{deptName}, '%')</if>
            <if test="level != null  and level != ''"> and level = #{level}</if>
            <if test="provinceCode != null  and provinceCode != ''"> and province_code = #{provinceCode}</if>
            <if test="cityCode != null  and cityCode != ''"> and city_code = #{cityCode}</if>
            <if test="countyCode != null  and countyCode != ''"> and county_code = #{countyCode}</if>
            <if test="townCode != null  and townCode != ''"> and town_code = #{townCode}</if>
            <if test="villageCode != null  and villageCode != ''"> and village_code = #{villageCode}</if>
        </where>
    </select>

    <select id="selectProjectById" parameterType="Long" resultMap="ProjectResult">
        <include refid="selectProjectVo"/>
        where id = #{id}
    </select>

    <insert id="insertProject" parameterType="Project" useGeneratedKeys="true" keyProperty="id">
        insert into project
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="projectName != null and projectName != ''">project_name,</if>
            <if test="sysShowName != null and sysShowName != ''">sys_show_name,</if>
            <if test="centralCoordinates != null and centralCoordinates != ''">central_coordinates,</if>
            <if test="scope != null and scope != ''">scope,</if>
            <if test="administrativeArea != null and administrativeArea != ''">administrative_area,</if>
            <if test="owner != null and owner != ''">owner,</if>
            <if test="logo != null and logo != ''">logo,</if>
            <if test="image != null and image != ''">image,</if>
            <if test="videoIntroduction != null and videoIntroduction != ''">video_introduction,</if>
            <if test="remark != null and remark != ''">remark,</if>
            <if test="pParams != null and pParams != ''">p_params,</if>
            <if test="introduce != null">introduce,</if>
            <if test="delFlag != null">del_flag,</if>
            <if test="createTime != null">create_time,</if>
            <if test="createBy != null">create_by,</if>
            <if test="updateTime != null">update_time,</if>
            <if test="remarks != null">remarks,</if>
            <if test="tenantId != null">tenant_id,</if>
            <if test="tenantName != null">tenant_name,</if>
            <if test="ownerId != null">owner_id,</if>
            <if test="parentId != null">parent_id,</if>
            <if test="deptId != null">dept_id,</if>
            <if test="administrativeAreaCode != null">administrative_area_code,</if>
            <if test="deptName != null">dept_name,</if>
            <if test="level != null">level,</if>
            <if test="provinceCode != null">province_code,</if>
            <if test="cityCode != null">city_code,</if>
            <if test="countyCode != null">county_code,</if>
            <if test="townCode != null">town_code,</if>
            <if test="villageCode != null">village_code,</if>
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="projectName != null and projectName != ''">#{projectName},</if>
            <if test="sysShowName != null and sysShowName != ''">#{sysShowName},</if>
            <if test="centralCoordinates != null and centralCoordinates != ''">#{centralCoordinates},</if>
            <if test="scope != null and scope != ''">#{scope},</if>
            <if test="administrativeArea != null and administrativeArea != ''">#{administrativeArea},</if>
            <if test="owner != null and owner != ''">#{owner},</if>
            <if test="logo != null and logo != ''">#{logo},</if>
            <if test="image != null and image != ''">#{image},</if>
            <if test="videoIntroduction != null and videoIntroduction != ''">#{videoIntroduction},</if>
            <if test="remark != null and remark != ''">#{remark},</if>
            <if test="pParams != null and pParams != ''">#{pParams},</if>
            <if test="introduce != null">#{introduce},</if>
            <if test="delFlag != null">#{delFlag},</if>
            <if test="createTime != null">#{createTime},</if>
            <if test="createBy != null">#{createBy},</if>
            <if test="updateTime != null">#{updateTime},</if>
            <if test="remarks != null">#{remarks},</if>
            <if test="tenantId != null">#{tenantId},</if>
            <if test="tenantName != null">#{tenantName},</if>
            <if test="ownerId != null">#{ownerId},</if>
            <if test="parentId != null">#{parentId},</if>
            <if test="deptId != null">#{deptId},</if>
            <if test="administrativeAreaCode != null">#{administrativeAreaCode},</if>
            <if test="deptName != null">#{deptName},</if>
            <if test="level != null">#{level},</if>
            <if test="provinceCode != null">#{provinceCode},</if>
            <if test="cityCode != null">#{cityCode},</if>
            <if test="countyCode != null">#{countyCode},</if>
            <if test="townCode != null">#{townCode},</if>
            <if test="villageCode != null">#{villageCode},</if>
        </trim>
    </insert>

    <update id="updateProject" parameterType="Project">
        update project
        <trim prefix="SET" suffixOverrides=",">
            <if test="projectName != null and projectName != ''">project_name = #{projectName},</if>
            <if test="sysShowName != null and sysShowName != ''">sys_show_name = #{sysShowName},</if>
            <if test="centralCoordinates != null and centralCoordinates != ''">central_coordinates = #{centralCoordinates},</if>
            <if test="scope != null and scope != ''">scope = #{scope},</if>
            <if test="administrativeArea != null and administrativeArea != ''">administrative_area = #{administrativeArea},</if>
            <if test="owner != null and owner != ''">owner = #{owner},</if>
            <if test="logo != null and logo != ''">logo = #{logo},</if>
            <if test="image != null and image != ''">image = #{image},</if>
            <if test="videoIntroduction != null and videoIntroduction != ''">video_introduction = #{videoIntroduction},</if>
            <if test="remark != null and remark != ''">remark = #{remark},</if>
            <if test="pParams != null and pParams != ''">p_params = #{pParams},</if>
            <if test="introduce != null">introduce = #{introduce},</if>
            <if test="delFlag != null">del_flag = #{delFlag},</if>
            <if test="createTime != null">create_time = #{createTime},</if>
            <if test="createBy != null">create_by = #{createBy},</if>
            <if test="updateTime != null">update_time = #{updateTime},</if>
            <if test="remarks != null">remarks = #{remarks},</if>
            <if test="tenantId != null">tenant_id = #{tenantId},</if>
            <if test="tenantName != null">tenant_name = #{tenantName},</if>
            <if test="ownerId != null">owner_id = #{ownerId},</if>
            <if test="parentId != null">parent_id = #{parentId},</if>
            <if test="deptId != null">dept_id = #{deptId},</if>
            <if test="administrativeAreaCode != null">administrative_area_code = #{administrativeAreaCode},</if>
            <if test="deptName != null">dept_name = #{deptName},</if>
            <if test="level != null">level = #{level},</if>
            <if test="provinceCode != null">province_code = #{provinceCode},</if>
            <if test="cityCode != null">city_code = #{cityCode},</if>
            <if test="countyCode != null">county_code = #{countyCode},</if>
            <if test="townCode != null">town_code = #{townCode},</if>
            <if test="villageCode != null">village_code = #{villageCode},</if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteProjectById" parameterType="Long">
        delete from project where id = #{id}
    </delete>

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