<?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.UsUnqualifiedGoodsMapper">
    
    <resultMap type="UsUnqualifiedGoods" id="UsUnqualifiedGoodsResult">
        <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="dangerDescription"    column="danger_description"    />
        <result property="remedyDescription"    column="remedy_description"    />
        <result property="recallTime"    column="recall_time"    />
        <result property="recallAmount"    column="recall_amount"    />
        <result property="recallCause"    column="recall_cause"    />
        <result property="pointSale"    column="point_sale"    />
        <result property="producers"    column="producers"    />
        <result property="origin"    column="origin"    />
        <result property="remark"    column="remark"    />
        <result property="accidentDescription"    column="accident_description"    />
        <result property="accidentDescription"    column="accident_description"    />
        <result property="spiderTime" column="spider_time"/>
    </resultMap>

    <sql id="selectUsUnqualifiedGoodsVo">
        select id, create_user, create_dept, create_time, update_user, update_time, is_deleted, status,
               goods_name, danger_description, remedy_description, recall_time, recall_amount,
               recall_cause, point_sale, producers, origin, remark,
               accident_description ,spider_time  from bus_us_unqualified_goods
    </sql>

    <select id="selectUsUnqualifiedGoodsList" parameterType="UsUnqualifiedGoods" resultMap="UsUnqualifiedGoodsResult">
        <include refid="selectUsUnqualifiedGoodsVo"/>
        <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="dangerDescription != null  and dangerDescription != ''"> and danger_description = #{dangerDescription}</if>
            <if test="remedyDescription != null  and remedyDescription != ''"> and remedy_description = #{remedyDescription}</if>
            <if test="recallTime != null "> and recall_time = #{recallTime}</if>
            <if test="recallAmount != null  and recallAmount != ''"> and recall_amount = #{recallAmount}</if>
            <if test="recallCause != null  and recallCause != ''"> and recall_cause = #{recallCause}</if>
            <if test="pointSale != null  and pointSale != ''"> and point_sale = #{pointSale}</if>
            <if test="producers != null  and producers != ''"> and producers = #{producers}</if>
            <if test="origin != null  and origin != ''"> and origin = #{origin}</if>
            <if test="accidentDescription != null  and accidentDescription != ''"> and accident_description = #{accidentDescription}</if>
        </where>
        order by recall_time desc
    </select>
    
    <select id="selectUsUnqualifiedGoodsById" parameterType="Long" resultMap="UsUnqualifiedGoodsResult">
        <include refid="selectUsUnqualifiedGoodsVo"/>
        where id = #{id}
    </select>
    <select id="selectLatestSpiderTime" resultType="java.util.Date">
        SELECT MAX(recall_time) FROM bus_us_unqualified_goods WHERE status = 0
    </select>

    <insert id="insertUsUnqualifiedGoods" parameterType="UsUnqualifiedGoods" useGeneratedKeys="true" keyProperty="id">
        insert into bus_us_unqualified_goods
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <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="dangerDescription != null">danger_description,</if>
            <if test="remedyDescription != null">remedy_description,</if>
            <if test="recallTime != null">recall_time,</if>
            <if test="recallAmount != null">recall_amount,</if>
            <if test="recallCause != null">recall_cause,</if>
            <if test="pointSale != null">point_sale,</if>
            <if test="producers != null">producers,</if>
            <if test="origin != null">origin,</if>
            <if test="remark != null">remark,</if>
            <if test="accidentDescription != null">accident_description,</if>
            <if test="spiderTime != null">spider_time,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <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="dangerDescription != null">#{dangerDescription},</if>
            <if test="remedyDescription != null">#{remedyDescription},</if>
            <if test="recallTime != null">#{recallTime},</if>
            <if test="recallAmount != null">#{recallAmount},</if>
            <if test="recallCause != null">#{recallCause},</if>
            <if test="pointSale != null">#{pointSale},</if>
            <if test="producers != null">#{producers},</if>
            <if test="origin != null">#{origin},</if>
            <if test="remark != null">#{remark},</if>
            <if test="accidentDescription != null">#{accidentDescription},</if>
            <if test="spiderTime != null">#{spiderTime},</if>
         </trim>
    </insert>

    <update id="updateUsUnqualifiedGoods" parameterType="UsUnqualifiedGoods">
        update bus_us_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="dangerDescription != null">danger_description = #{dangerDescription},</if>
            <if test="remedyDescription != null">remedy_description = #{remedyDescription},</if>
            <if test="recallTime != null">recall_time = #{recallTime},</if>
            <if test="recallAmount != null">recall_amount = #{recallAmount},</if>
            <if test="recallCause != null">recall_cause = #{recallCause},</if>
            <if test="pointSale != null">point_sale = #{pointSale},</if>
            <if test="producers != null">producers = #{producers},</if>
            <if test="origin != null">origin = #{origin},</if>
            <if test="remark != null">remark = #{remark},</if>
            <if test="accidentDescription != null">accident_description = #{accidentDescription},</if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteUsUnqualifiedGoodsById" parameterType="Long">
        delete from bus_us_unqualified_goods where id = #{id}
    </delete>

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