<?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.shkj.wms.mapper.BusinContainerUpkeepMapper">

    <select id="getContainerUpkeepDate" resultType="com.shkj.wms.vo.BusinContainerUpkeepVo"
            parameterType="com.shkj.wms.bo.BusinContainerUpkeepQueryBo">
        select conttainer.id as container_id, upkeep.id,conttainer.container_name,conttainer.container_code,
        next_upkeep,ifnull(upkeep_time,create_time) as upkeep_time,DATEDIFF(CURTIME(),ifnull(upkeep_time,create_time)) days_used  from base_container conttainer
        left join
        (
        select id, container_id,next_upkeep,upkeep_time
        from busin_container_upkeep
        where ifnull(is_upkeep,0) =0
        )upkeep on conttainer.id=upkeep.container_id
        <where>
            <if test="containerId !=null  ">
                conttainer.id =#{containerId}
            </if>
            <if test="containerCode !=null  ">
                conttainer.container_code =#{containerCode}
            </if>
            <if test="branchId != null">
                and conttainer.branch_id = #{branchId}
            </if>
        </where>
        limit 1
    </select>
 </mapper>
