<?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.hw.mes.mapper.MesProjectInfoMapper">
    
    <resultMap type="MesProjectInfo" id="MesProjectInfoResult">
        <result property="projectId"    column="project_id"    />
        <result property="erpId"    column="erp_id"    />
        <result property="projectNo"    column="project_no"    />
        <result property="projectName"    column="project_name"    />
        <result property="documentStatus"    column="document_status"    />
        <result property="forbidStatus"    column="forbid_status"    />
        <result property="auditDate"    column="audit_date"    />
        <result property="erpModifyDate"    column="erp_modify_date"    />
        <result property="beginDate"    column="begin_date"    />
        <result property="endDate"    column="end_date"    />
        <result property="orderStatus"    column="order_status"    />
        <result property="completeDate"    column="complete_date"    />
        <result property="isFlag"    column="is_flag"    />
        <result property="remark"    column="remark"    />
        <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="selectMesProjectInfoVo">
        select project_id, erp_id, project_no, project_name, document_status, forbid_status, audit_date, erp_modify_date, begin_date, end_date, order_status, complete_date, is_flag, remark, create_by, create_time, update_by, update_time from mes_project_info
    </sql>

    <select id="selectMesProjectInfoList" parameterType="MesProjectInfo" resultMap="MesProjectInfoResult">
        <include refid="selectMesProjectInfoVo"/>
        <where>  
            <if test="erpId != null "> and erp_id = #{erpId}</if>
            <if test="projectNo != null  and projectNo != ''"> and project_no = #{projectNo}</if>
            <if test="projectName != null  and projectName != ''"> and project_name like concat('%', #{projectName}, '%')</if>
            <if test="documentStatus != null  and documentStatus != ''"> and document_status = #{documentStatus}</if>
            <if test="forbidStatus != null  and forbidStatus != ''"> and forbid_status = #{forbidStatus}</if>
            <if test="auditDate != null "> and audit_date = #{auditDate}</if>
            <if test="erpModifyDate != null "> and erp_modify_date = #{erpModifyDate}</if>
            <if test="beginDate != null "> and begin_date = #{beginDate}</if>
            <if test="endDate != null "> and end_date = #{endDate}</if>
            <if test="orderStatus != null  and orderStatus != ''"> and order_status = #{orderStatus}</if>
            <if test="completeDate != null "> and complete_date = #{completeDate}</if>
            <if test="isFlag != null  and isFlag != ''"> and is_flag = #{isFlag}</if>
        </where>
    </select>
    
    <select id="selectMesProjectInfoByProjectId" parameterType="Long" resultMap="MesProjectInfoResult">
        <include refid="selectMesProjectInfoVo"/>
        where project_id = #{projectId}
    </select>
        
    <insert id="insertMesProjectInfo" parameterType="MesProjectInfo" useGeneratedKeys="true" keyProperty="projectId">
        insert into mes_project_info
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="erpId != null">erp_id,</if>
            <if test="projectNo != null">project_no,</if>
            <if test="projectName != null">project_name,</if>
            <if test="documentStatus != null">document_status,</if>
            <if test="forbidStatus != null">forbid_status,</if>
            <if test="auditDate != null">audit_date,</if>
            <if test="erpModifyDate != null">erp_modify_date,</if>
            <if test="beginDate != null">begin_date,</if>
            <if test="endDate != null">end_date,</if>
            <if test="orderStatus != null">order_status,</if>
            <if test="completeDate != null">complete_date,</if>
            <if test="isFlag != null and isFlag != ''">is_flag,</if>
            <if test="remark != null">remark,</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="erpId != null">#{erpId},</if>
            <if test="projectNo != null">#{projectNo},</if>
            <if test="projectName != null">#{projectName},</if>
            <if test="documentStatus != null">#{documentStatus},</if>
            <if test="forbidStatus != null">#{forbidStatus},</if>
            <if test="auditDate != null">#{auditDate},</if>
            <if test="erpModifyDate != null">#{erpModifyDate},</if>
            <if test="beginDate != null">#{beginDate},</if>
            <if test="endDate != null">#{endDate},</if>
            <if test="orderStatus != null">#{orderStatus},</if>
            <if test="completeDate != null">#{completeDate},</if>
            <if test="isFlag != null and isFlag != ''">#{isFlag},</if>
            <if test="remark != null">#{remark},</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="updateMesProjectInfo" parameterType="MesProjectInfo">
        update mes_project_info
        <trim prefix="SET" suffixOverrides=",">
            <if test="erpId != null">erp_id = #{erpId},</if>
            <if test="projectNo != null">project_no = #{projectNo},</if>
            <if test="projectName != null">project_name = #{projectName},</if>
            <if test="documentStatus != null">document_status = #{documentStatus},</if>
            <if test="forbidStatus != null">forbid_status = #{forbidStatus},</if>
            <if test="auditDate != null">audit_date = #{auditDate},</if>
            <if test="erpModifyDate != null">erp_modify_date = #{erpModifyDate},</if>
            <if test="beginDate != null">begin_date = #{beginDate},</if>
            <if test="endDate != null">end_date = #{endDate},</if>
            <if test="orderStatus != null">order_status = #{orderStatus},</if>
            <if test="completeDate != null">complete_date = #{completeDate},</if>
            <if test="isFlag != null and isFlag != ''">is_flag = #{isFlag},</if>
            <if test="remark != null">remark = #{remark},</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 project_id = #{projectId}
    </update>

    <delete id="deleteMesProjectInfoByProjectId" parameterType="Long">
        delete from mes_project_info where project_id = #{projectId}
    </delete>

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