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

    <resultMap type="Project" id="ProjectResult">
            <result property="id" column="id"/>
            <result property="groupId" column="group_id"/>
            <result property="groupName" column="group_name"/>
            <result property="projectName" column="project_name"/>
            <result property="projectCode" column="project_code"/>
            <result property="projectAlias" column="project_alias"/>
            <result property="enableStatus" column="enable_status"/>
            <result property="judgeMode" column="judge_mode"/>
            <result property="maxValue" column="max_value"/>
            <result property="minValue" column="min_value"/>
            <result property="defaultValue" column="default_value"/>
            <result property="lisCompare" column="lis_compare"/>
            <result property="projectUnit" column="project_unit"/>
            <result property="projectSort" column="project_sort"/>
            <result property="projectRemark" column="project_remark"/>
            <result property="delFlag" column="del_flag"/>
            <result property="createBy" column="create_by"/>
            <result property="createTime" column="create_time"/>
            <result property="updateBy" column="update_by"/>
            <result property="updateTime" column="update_time"/>
    </resultMap>

    <sql id="selectProjectVo">
        select id, group_id, group_name, project_name, project_code, project_alias, enable_status, judge_mode, max_value, min_value, default_value, lis_compare, project_unit, project_sort, project_remark, del_flag, create_by, create_time, update_by, update_time from project
    </sql>

    <select id="selectProjectList" parameterType="Project" resultMap="ProjectResult">
        <include refid="selectProjectVo"/>
        <where>
			del_flag = 0
            <if test="groupId != null ">
                and group_id = #{groupId}
            </if>
            <if test="groupName != null  and groupName != ''">
                and group_name like concat('%', #{groupName}, '%')
            </if>
            <if test="projectName != null  and projectName != ''">
                and project_name like concat('%', #{projectName}, '%')
            </if>
            <if test="projectCode != null  and projectCode != ''">
                and project_code = #{projectCode}
            </if>
            <if test="projectAlias != null  and projectAlias != ''">
                and project_alias = #{projectAlias}
            </if>
            <if test="enableStatus != null ">
                and enable_status = #{enableStatus}
            </if>
            <if test="judgeMode != null  and judgeMode != ''">
                and judge_mode = #{judgeMode}
            </if>
            <if test="maxValue != null ">
                and max_value = #{maxValue}
            </if>
            <if test="minValue != null ">
                and min_value = #{minValue}
            </if>
            <if test="defaultValue != null  and defaultValue != ''">
                and default_value = #{defaultValue}
            </if>
            <if test="lisCompare != null  and lisCompare != ''">
                and lis_compare = #{lisCompare}
            </if>
            <if test="projectUnit != null  and projectUnit != ''">
                and project_unit = #{projectUnit}
            </if>
            <if test="projectSort != null ">
                and project_sort = #{projectSort}
            </if>
            <if test="projectRemark != null  and projectRemark != ''">
                and project_remark = #{projectRemark}
            </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="groupId != null">group_id,
            </if>
            <if test="groupName != null">group_name,
            </if>
            <if test="projectName != null">project_name,
            </if>
            <if test="projectCode != null">project_code,
            </if>
            <if test="projectAlias != null">project_alias,
            </if>
            <if test="enableStatus != null">enable_status,
            </if>
            <if test="judgeMode != null">judge_mode,
            </if>
            <if test="maxValue != null">max_value,
            </if>
            <if test="minValue != null">min_value,
            </if>
            <if test="defaultValue != null">default_value,
            </if>
            <if test="lisCompare != null">lis_compare,
            </if>
            <if test="projectUnit != null">project_unit,
            </if>
            <if test="projectSort != null">project_sort,
            </if>
            <if test="projectRemark != null">project_remark,
            </if>
            <if test="delFlag != null">del_flag,
            </if>
            <if test="createBy != null">create_by,
            </if>
            <if test="createTime != null">create_time,
            </if>
            <if test="updateBy != null">update_by,
            </if>
            <if test="updateTime != null">update_time,
            </if>
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="groupId != null">#{groupId},
            </if>
            <if test="groupName != null">#{groupName},
            </if>
            <if test="projectName != null">#{projectName},
            </if>
            <if test="projectCode != null">#{projectCode},
            </if>
            <if test="projectAlias != null">#{projectAlias},
            </if>
            <if test="enableStatus != null">#{enableStatus},
            </if>
            <if test="judgeMode != null">#{judgeMode},
            </if>
            <if test="maxValue != null">#{maxValue},
            </if>
            <if test="minValue != null">#{minValue},
            </if>
            <if test="defaultValue != null">#{defaultValue},
            </if>
            <if test="lisCompare != null">#{lisCompare},
            </if>
            <if test="projectUnit != null">#{projectUnit},
            </if>
            <if test="projectSort != null">#{projectSort},
            </if>
            <if test="projectRemark != null">#{projectRemark},
            </if>
            <if test="delFlag != null">#{delFlag},
            </if>
            <if test="createBy != null">#{createBy},
            </if>
            <if test="createTime != null">#{createTime},
            </if>
            <if test="updateBy != null">#{updateBy},
            </if>
            <if test="updateTime != null">#{updateTime},
            </if>
        </trim>
    </insert>

    <update id="updateProject" parameterType="Project">
        update project
        <trim prefix="SET" suffixOverrides=",">
            <if test="groupId != null">group_id =
                #{groupId},
            </if>
            <if test="groupName != null">group_name =
                #{groupName},
            </if>
            <if test="projectName != null">project_name =
                #{projectName},
            </if>
            <if test="projectCode != null">project_code =
                #{projectCode},
            </if>
            <if test="projectAlias != null">project_alias =
                #{projectAlias},
            </if>
            <if test="enableStatus != null">enable_status =
                #{enableStatus},
            </if>
            <if test="judgeMode != null">judge_mode =
                #{judgeMode},
            </if>
            <if test="maxValue != null">max_value =
                #{maxValue},
            </if>
            <if test="minValue != null">min_value =
                #{minValue},
            </if>
            <if test="defaultValue != null">default_value =
                #{defaultValue},
            </if>
            <if test="lisCompare != null">lis_compare =
                #{lisCompare},
            </if>
            <if test="projectUnit != null">project_unit =
                #{projectUnit},
            </if>
            <if test="projectSort != null">project_sort =
                #{projectSort},
            </if>
            <if test="projectRemark != null">project_remark =
                #{projectRemark},
            </if>
            <if test="delFlag != null">del_flag =
                #{delFlag},
            </if>
            <if test="createBy != null">create_by =
                #{createBy},
            </if>
            <if test="createTime != null">create_time =
                #{createTime},
            </if>
            <if test="updateBy != null">update_by =
                #{updateBy},
            </if>
            <if test="updateTime != null">update_time =
                #{updateTime},
            </if>
        </trim>
        where id = #{id}
    </update>

    <update id="deleteProjectById" parameterType="Long">
	    update project set del_flag = 1 where id = #{id}
    </update>

    <update id="deleteProjectByIds" parameterType="String">
        update project set del_flag = 1 where id in
        <foreach item="id" collection="array" open="(" separator="," close=")">
            #{id}
        </foreach>
    </update>
	<select id="hasSameCodeProject" parameterType="Long"
		resultMap="ProjectResult">
		<include refid="selectProjectVo"/>
		<where>
			del_flag = 0
			<if test="id != null">
				and id != #{id}
			</if>
			<if test="groupId != null">
				and group_id = #{groupId}
			</if>
			<if test="projectCode != null  and projectCode != ''">
				and project_code = #{projectCode}
			</if>
		</where>
	</select>
</mapper>