<?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.ezhizao.project.business.mapper.BizTaksStockCertificateLotMapper">

    <resultMap type="cn.ezhizao.project.business.domain.BizTaksStockCertificateLot" id="BizTaksStockCertificateLotResult">
        <id column="id" property="id"/>
    </resultMap>


    <select id="getList" parameterType="BizTaksStockCertificateLot" resultMap="BizTaksStockCertificateLotResult">
        SELECT * FROM biz_taks_stock_certificate_lot
        <trim prefix=" WHERE" suffix="" suffixOverrides="AND">
            deleted = 0
            <if test="startCode != null  and startCode != ''"> AND start_code = #{startCode}</if>
            <if test="endCode != null  and endCode != ''"> AND end_code = #{endCode}</if>
            <if test="printDate != null "> AND print_date = #{printDate}</if>
            <if test="qrcode != null  and qrcode != ''"> AND qrcode = #{qrcode}</if>
            <if test="qrcodeUrl != null  and qrcodeUrl != ''"> AND qrcode_url = #{qrcodeUrl}</if>
            <if test="barcode != null  and barcode != ''"> AND barcode = #{barcode}</if>
            <if test="barcodeUrl != null  and barcodeUrl != ''"> AND barcode_url = #{barcodeUrl}</if>
            <if test="lotCode != null  and lotCode != ''"> AND lot_code = #{lotCode}</if>
            <if test="prodNum != null "> AND prod_num = #{prodNum}</if>
            <if test="companyCode != null  and companyCode != ''"> AND company_code = #{companyCode}</if>
            <if test="companyName != null  and companyName != ''"> AND company_name like concat('%', #{companyName}, '%')</if>
            <if test="isTaksStock != null "> AND is_taks_stock = #{isTaksStock}</if>
            <if test="stockYear != null  and stockYear != ''"> AND stock_year = #{stockYear}</if>
            <if test="stockMonth != null  and stockMonth != ''"> AND stock_month = #{stockMonth}</if>
            <if test="deptName != null  and deptName != ''"> AND dept_name like concat('%', #{deptName}, '%')</if>
        </trim>
    </select>
    <select id="getNotInboundInfo" resultType="BizTaksStockCertificateLot">
        SELECT *,
        GROUP_CONCAT(barcode SEPARATOR ',') AS barcodes
        FROM
        biz_taks_stock_certificate_lot
        <trim prefix=" WHERE" suffix="" suffixOverrides="AND">
        deleted = 0
        <if test="barcode != null  and barcode != ''"> AND
            lot_code IN (SELECT lot_code FROM biz_taks_stock_certificate_lot WHERE barcode like concat ('%', #{barcode}, '%') and deleted = 0)
            </if>
            <if test="takeStockPeriodId != null and takeStockPeriodId != ''"> AND take_stock_period_id = #{takeStockPeriodId}</if>

        <if test="lotCode != null  and lotCode != ''"> AND lot_code like concat('%', #{lotCode}, '%')</if>
       </trim>
        GROUP BY
        lot_code
    </select>

    <delete id="physicalDelete">
        DELETE FROM biz_taks_stock_certificate_lot
        <trim prefix=" WHERE" suffix="" suffixOverrides="AND">
            <if test="id != null">
                id = #{id} AND
            </if>
       <!-- 删除条件为其他外键可以在这里加 -->
        </trim>
    </delete>
</mapper>
