<?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.ConstructionLedgerMapper">

    <!-- 通用查询映射结果 -->
    <resultMap id="constructionLedgerResultMap" type="org.springblade.business.entity.ConstructionLedger">
        <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="station" property="station"/>
        <result column="site" property="site"/>
        <result column="site_start_time" property="siteStartTime"/>
        <result column="site_end_time" property="siteEndTime"/>
        <result column="detection_start_time" property="detectionStartTime"/>
        <result column="detection_end_time" property="detectionEndTime"/>
        <result column="design_volume" property="designVolume"/>
        <result column="actual_volume" property="actualVolume"/>
        <result column="is_beton" property="isBeton"/>
        <result column="wbs_id" property="wbsId"/>
        <result column="contract_id" property="contractId"/>
        <result column="project_id" property="projectId"/>
    </resultMap>


    <select id="selectConstructionLedgerPage" resultMap="constructionLedgerResultMap">
        select
            id,
            station,
            site,
            site_start_time,
            site_end_time,
            detection_start_time,
            detection_end_time,
            design_volume,
            actual_volume,
            is_beton
        from u_construction_ledger
        where
            is_deleted = 0
        <if test="param.wbsIds != null and param.wbsIds.size > 0">
            and wbs_id in
            <foreach collection="param.wbsIds" item="wbsId" open="(" separator="," close=")">#{wbsId}</foreach>
        </if>
        <if test="param.siteStartTimeStr != null and param.siteEndTimeStr">
            and site_start_time between #{param.siteStartTimeStr} and #{param.siteEndTimeStr}
        </if>
        limit ${size}
    </select>

    <update id="updateByIdNotAll">
        update u_construction_ledger set is_deleted = 0
        <if test="param.siteStartTime != null">
            ,site_start_time = #{param.siteStartTime}
        </if>
        <if test="param.siteEndTime != null">
            ,site_end_time = #{param.siteEndTime}
        </if>
        <if test="param.detectionStartTime != null">
            ,detection_start_time = #{param.detectionStartTime}
        </if>
        <if test="param.detectionEndTime != null">
            ,detection_end_time = #{param.detectionEndTime}
        </if>
        <if test="param.designVolume != null and param.designVolume != ''">
            ,design_volume = #{param.designVolume}
        </if>
        <if test="param.actualVolume != null and param.actualVolume != ''">
            ,actual_volume = #{param.actualVolume}
        </if>
        <if test="param.updateUser != null and param.updateUser != null">
            ,update_user = #{param.updateUser},update_time = #{param.updateTime}
        </if>
        <if test="param.projectId != null and param.projectId != null">
            ,project_id = #{param.projectId}
        </if>
        <if test="param.contractId != null and param.contractId != null">
            ,contract_id = #{param.contractId}
        </if>
        where id = #{param.id}
    </update>

</mapper>
