<?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="cn.wisenergy.mapper.WorkProjectChangeMapper">

    <!-- 通用查询映射结果 -->
    <resultMap id="BaseResultMap" type="cn.wisenergy.model.app.WorkProjectChange">
        <id column="id" property="id" />
        <result column="project_id" property="projectId" />
        <result column="change_type" property="changeType" />
        <result column="modify_after" property="modifyAfter" />
        <result column="modify_before" property="modifyBefore" />
        <result column="reason" property="reason" />
        <result column="modify_time" property="modifyTime" />
        <result column="reviser_id" property="reviserId"/>
        <result column="operation_type" property="operationType"/>
    </resultMap>

    <!-- 通用查询结果列 -->
    <sql id="Base_Column_List">
        id, project_id, change_type, modify_after,modify_before, reason, modify_time,reviser_id,operation_type
    </sql>

    <sql id="not_id_Column_List">
        project_id, change_type, modify_after,modify_before, reason, modify_time,reviser_id,operation_type
    </sql>
    <insert id="insertBatch">
        INSERT INTO work_project_change
        (<include refid="not_id_Column_List"/> )
        VALUES
        <foreach collection ="workProjectChanges" item="workProjectChange" separator =",">
            (#{workProjectChange.projectId}, #{workProjectChange.changeType},#{workProjectChange.modifyAfter},#{workProjectChange.modifyBefore},#{workProjectChange.reason},#{workProjectChange.modifyTime},#{workProjectChange.reviserId},#{workProjectChange.operationType})
        </foreach >


    </insert>
    <select id="getByProjectId" resultType="cn.wisenergy.model.app.WorkProjectChange">
        SELECT c.id,c.project_id,c.change_type,c.modify_after,c.modify_before,c.reason,c.modify_time,c.reviser_id,c.operation_type,u.name as 'reviser_name'
        FROM work_project_change c LEFT JOIN work_user u on c.reviser_id = u.id
        WHERE c.project_id = #{projectId}
        ORDER BY c.modify_time DESC
    </select>

</mapper>
