<?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.spider.quartz.mapper.EuUnqualifiedGoodsMapper">
    
    <resultMap type="EuUnqualifiedGoods" id="EuUnqualifiedGoodsResult">
        <result property="id"    column="id"    />
        <result property="createUser"    column="create_user"    />
        <result property="createDept"    column="create_dept"    />
        <result property="createTime"    column="create_time"    />
        <result property="updateUser"    column="update_user"    />
        <result property="updateTime"    column="update_time"    />
        <result property="isDeleted"    column="is_deleted"    />
        <result property="status"    column="status"    />
        <result property="goodsName"    column="goods_name"    />
        <result property="noticeCountry"    column="notice_country"    />
        <result property="goodsCategory"    column="goods_category"    />
        <result property="goodsKinds"    column="goods_kinds"    />
        <result property="brand"    column="brand"    />
        <result property="originCountry"    column="origin_country"    />
        <result property="riskType"    column="risk_type"    />
        <result property="riskDescription"    column="risk_description"    />
        <result property="unqualifiedCause"    column="unqualified_cause"    />
        <result property="remedyMeasures"    column="remedy_measures"    />
        <result property="remark"    column="remark"    />
        <result property="recallTime"    column="recall_time"    />
        <result property="spiderTime" column="spider_time"/>
    </resultMap>

    <sql id="selectEuUnqualifiedGoodsVo">
        select id, create_user, create_dept, create_time, update_user, update_time, is_deleted, status, goods_name,
               notice_country, goods_category, goods_kinds, brand, origin_country, risk_type, risk_description,
               unqualified_cause, remedy_measures, remark, recall_time,spider_time  from bus_eu_unqualified_goods
    </sql>

    <select id="selectEuUnqualifiedGoodsList" parameterType="EuUnqualifiedGoods" resultMap="EuUnqualifiedGoodsResult">
        <include refid="selectEuUnqualifiedGoodsVo"/>
        <where>  
            <if test="createUser != null  and createUser != ''"> and create_user = #{createUser}</if>
            <if test="createDept != null  and createDept != ''"> and create_dept = #{createDept}</if>
            <if test="updateUser != null  and updateUser != ''"> and update_user = #{updateUser}</if>
            <if test="isDeleted != null "> and is_deleted = #{isDeleted}</if>
            <if test="status != null "> and status = #{status}</if>
            <if test="goodsName != null  and goodsName != ''"> and goods_name like concat('%', #{goodsName}, '%')</if>
            <if test="noticeCountry != null  and noticeCountry != ''"> and notice_country = #{noticeCountry}</if>
            <if test="goodsCategory != null  and goodsCategory != ''"> and goods_category = #{goodsCategory}</if>
            <if test="goodsKinds != null  and goodsKinds != ''"> and goods_kinds = #{goodsKinds}</if>
            <if test="brand != null  and brand != ''"> and brand = #{brand}</if>
            <if test="originCountry != null  and originCountry != ''"> and origin_country = #{originCountry}</if>
            <if test="riskType != null  and riskType != ''"> and risk_type = #{riskType}</if>
            <if test="riskDescription != null  and riskDescription != ''"> and risk_description = #{riskDescription}</if>
            <if test="unqualifiedCause != null  and unqualifiedCause != ''"> and unqualified_cause = #{unqualifiedCause}</if>
            <if test="remedyMeasures != null  and remedyMeasures != ''"> and remedy_measures = #{remedyMeasures}</if>
            <if test="recallTime != null "> and recall_time = #{recallTime}</if>
        </where>
        order by recall_time desc
    </select>
    
    <select id="selectEuUnqualifiedGoodsById" parameterType="Long" resultMap="EuUnqualifiedGoodsResult">
        <include refid="selectEuUnqualifiedGoodsVo"/>
        where id = #{id}
    </select>
    <select id="selectLatestRecallTime" resultType="java.util.Date">
        SELECT MAX(recall_time) FROM bus_eu_unqualified_goods WHERE status = 0
    </select>

    <insert id="insertEuUnqualifiedGoods" parameterType="EuUnqualifiedGoods" useGeneratedKeys="true" keyProperty="id">
        insert into bus_eu_unqualified_goods
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="id != null">id,</if>
            <if test="createUser != null">create_user,</if>
            <if test="createDept != null">create_dept,</if>
            <if test="createTime != null">create_time,</if>
            <if test="updateUser != null">update_user,</if>
            <if test="updateTime != null">update_time,</if>
            <if test="isDeleted != null">is_deleted,</if>
            <if test="status != null">status,</if>
            <if test="goodsName != null">goods_name,</if>
            <if test="noticeCountry != null">notice_country,</if>
            <if test="goodsCategory != null">goods_category,</if>
            <if test="goodsKinds != null">goods_kinds,</if>
            <if test="brand != null">brand,</if>
            <if test="originCountry != null">origin_country,</if>
            <if test="riskType != null">risk_type,</if>
            <if test="riskDescription != null">risk_description,</if>
            <if test="unqualifiedCause != null">unqualified_cause,</if>
            <if test="remedyMeasures != null">remedy_measures,</if>
            <if test="remark != null">remark,</if>
            <if test="recallTime != null">recall_time,</if>
            <if test="spiderTime != null">spider_time,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="id != null">#{id},</if>
            <if test="createUser != null">#{createUser},</if>
            <if test="createDept != null">#{createDept},</if>
            <if test="createTime != null">#{createTime},</if>
            <if test="updateUser != null">#{updateUser},</if>
            <if test="updateTime != null">#{updateTime},</if>
            <if test="isDeleted != null">#{isDeleted},</if>
            <if test="status != null">#{status},</if>
            <if test="goodsName != null">#{goodsName},</if>
            <if test="noticeCountry != null">#{noticeCountry},</if>
            <if test="goodsCategory != null">#{goodsCategory},</if>
            <if test="goodsKinds != null">#{goodsKinds},</if>
            <if test="brand != null">#{brand},</if>
            <if test="originCountry != null">#{originCountry},</if>
            <if test="riskType != null">#{riskType},</if>
            <if test="riskDescription != null">#{riskDescription},</if>
            <if test="unqualifiedCause != null">#{unqualifiedCause},</if>
            <if test="remedyMeasures != null">#{remedyMeasures},</if>
            <if test="remark != null">#{remark},</if>
            <if test="recallTime != null">#{recallTime},</if>
            <if test="spiderTime != null">#{spiderTime},</if>
         </trim>
    </insert>

    <update id="updateEuUnqualifiedGoods" parameterType="EuUnqualifiedGoods">
        update bus_eu_unqualified_goods
        <trim prefix="SET" suffixOverrides=",">
            <if test="createUser != null">create_user = #{createUser},</if>
            <if test="createDept != null">create_dept = #{createDept},</if>
            <if test="createTime != null">create_time = #{createTime},</if>
            <if test="updateUser != null">update_user = #{updateUser},</if>
            <if test="updateTime != null">update_time = #{updateTime},</if>
            <if test="isDeleted != null">is_deleted = #{isDeleted},</if>
            <if test="status != null">status = #{status},</if>
            <if test="goodsName != null">goods_name = #{goodsName},</if>
            <if test="noticeCountry != null">notice_country = #{noticeCountry},</if>
            <if test="goodsCategory != null">goods_category = #{goodsCategory},</if>
            <if test="goodsKinds != null">goods_kinds = #{goodsKinds},</if>
            <if test="brand != null">brand = #{brand},</if>
            <if test="originCountry != null">origin_country = #{originCountry},</if>
            <if test="riskType != null">risk_type = #{riskType},</if>
            <if test="riskDescription != null">risk_description = #{riskDescription},</if>
            <if test="unqualifiedCause != null">unqualified_cause = #{unqualifiedCause},</if>
            <if test="remedyMeasures != null">remedy_measures = #{remedyMeasures},</if>
            <if test="remark != null">remark = #{remark},</if>
            <if test="recallTime != null">recall_time = #{recallTime},</if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteEuUnqualifiedGoodsById" parameterType="Long">
        delete from bus_eu_unqualified_goods where id = #{id}
    </delete>

    <delete id="deleteEuUnqualifiedGoodsByIds" parameterType="String">
        delete from bus_eu_unqualified_goods where id in 
        <foreach item="id" collection="array" open="(" separator="," close=")">
            #{id}
        </foreach>
    </delete>
</mapper>