<?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="org.springblade.business.mapper.ContractLogMapper">

    <!-- 通用查询映射结果 -->
    <resultMap id="contractLogResultMap" type="org.springblade.business.entity.ContractLog">
        <result column="id" property="id"/>
        <result column="create_user" property="createUser"/>
        <result column="create_dept" property="createDept"/>
        <result column="create_time" property="createTime"/>
        <result column="update_user" property="updateUser"/>
        <result column="update_time" property="updateTime"/>
        <result column="status" property="status"/>
        <result column="is_deleted" property="isDeleted"/>
        <result column="project_id" property="projectId"/>
        <result column="contract_id" property="contractId"/>
        <result column="wbs_node_id" property="wbsNodeId"/>
        <result column="wbs_node_type" property="wbsNodeType"/>
        <result column="record_time" property="recordTime"/>
        <result column="record_number" property="recordNumber"/>
        <result column="project_pileno" property="projectPileno"/>
        <result column="project_part" property="projectPart"/>
        <result column="data_id" property="dataId"/>
        <result column="create_user_name" property="createUserName"/>
    </resultMap>

    <select id="queryFillUser" resultMap="contractLogResultMap">
      select create_user, create_user_name from u_contract_log where is_deleted = 0 and wbs_node_id = #{vo.wbsNodeId}
    </select>

    <select id="constructionLogPage" resultMap="contractLogResultMap">
        select
          id,
          record_time,
          record_number,
          project_pileno,
          project_part,
          data_id,
          create_user_name
        from
          u_contract_log
        where
        is_deleted = 0
        and wbs_node_id = #{vo.wbsNodeId}
        <if test="vo.queryValue != null and vo.queryValue != ''">
            and
            (
            project_pileno like concat('%',#{vo.queryValue},'%')
            or
            project_part like concat('%',#{vo.queryValue},'%')
            or
            record_number like concat('%',#{vo.queryValue},'%')
            )
        </if>
        <if test="vo.createUser != null and vo.createUser != ''">
            and create_user = #{vo.createUser}
        </if>
        <if test="vo.startTime != null and vo.startTime != '' and vo.endTime != null and vo.endTime != ''">
            and record_time between #{startTime} and #{endTime}
        </if>
        order by record_time DESC limit #{current}, #{size}
    </select>

    <select id="selectPageCount" resultType="java.lang.Integer">
        select count(id) from u_contract_log
        where
          is_deleted = 0
        and wbs_node_id = #{vo.wbsNodeId}
        <if test="vo.queryValue != null and vo.queryValue != ''">
          and
            (
                project_pileno like concat('%',#{vo.queryValue},'%')
                  or
                project_part like concat('%',#{vo.queryValue},'%')
                  or
                record_number like concat('%',#{vo.queryValue},'%')
            )
        </if>
        <if test="vo.createUser != null and vo.createUser != ''">
            and create_user = #{vo.createUser}
        </if>
        <if test="vo.startTime != null and vo.startTime != '' and vo.endTime != null and vo.endTime != ''">
            and record_time between #{startTime} and #{endTime}
        </if>
    </select>

    <select id="selectContractLogPage" resultMap="contractLogResultMap">
        select * from u_contract_log where is_deleted = 0
    </select>

</mapper>
