<?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.ruoyi.system.mapper.DoumuProductInfoMapper">

    <resultMap type="DoumuProductInfo" id="DoumuProductInfoResult">
        <result property="productId"    column="product_id"    />
        <result property="productId"    column="product_id"    />
        <result property="openid"    column="openid"    />
        <result property="orderNumber"    column="order_number"    />
        <result property="name"    column="name"    />
        <result property="deliveryType"    column="delivery_type"    />
        <result property="phonenumber"    column="phonenumber"    />
        <result property="quantity"    column="quantity"    />
        <result property="provinceId"    column="province_id"    />
        <result property="province"    column="province"    />
        <result property="cityId"    column="city_id"    />
        <result property="city"    column="city"    />
        <result property="countyId"    column="county_id"    />
        <result property="county"    column="county"    />
        <result property="address"    column="address"    />
        <result property="lon"    column="lon"    />
        <result property="lat"    column="lat"    />
        <result property="flowType"    column="flow_type"    />
        <result property="status"    column="status"    />
        <result property="goodsName"    column="goods_name"    />
        <result property="totalPrice"    column="total_price"    />
        <result property="mailNo"    column="mail_no"    />
        <result property="createBy"    column="create_by"    />
        <result property="createTime"    column="create_time"    />
        <result property="updateBy"    column="update_by"    />
        <result property="updateTime"    column="update_time"    />
        <result property="remark"    column="remark"    />

        <result property="beginTime"    column="beginTime"    />
        <result property="endTime"    column="endTime"    />
    </resultMap>

    <sql id="selectDoumuProductInfoVo">
        select product_id,openid,order_number, name, delivery_type, phonenumber,quantity,province_id,province,city_id,city,county_id,county,lon,lat,status, address,
               flow_type,goods_name,total_price, mail_no, create_by, create_time, update_by, update_time, remark from doumu_product_info
    </sql>

    <select id="selectDoumuProductInfoList" parameterType="DoumuProductInfo" resultMap="DoumuProductInfoResult">
        <include refid="selectDoumuProductInfoVo"/>
        <where>
            <if test="orderNumber != null  and orderNumber != ''"> and order_number = #{orderNumber}</if>
            <if test="name != null  and name != ''"> and name like concat('%', #{name}, '%')</if>
            <if test="deliveryType != null  and deliveryType != ''"> and delivery_type = #{deliveryType}</if>
            <if test="phonenumber != null  and phonenumber != ''"> and phonenumber = #{phonenumber}</if>
            <if test="address != null  and address != ''"> and address = #{address}</if>
            <if test="flowType != null  and flowType != ''"> and flow_type = #{flowType}</if>
            <if test="status != null  and status != ''"> and status = #{status}</if>
            <if test="mailNo != null  and mailNo != ''"> and mailNo = #{mailNo}</if>
            <if test="beginTime != null and beginTime != ''"><!-- 开始时间检索 -->
                AND date_format(create_time,'%y%m%d') &gt;= date_format(#{beginTime},'%y%m%d')
            </if>
            <if test="endTime != null and endTime != ''"><!-- 结束时间检索 -->
                AND date_format(create_time,'%y%m%d') &lt;= date_format(#{endTime},'%y%m%d')
            </if>
        </where>
        order by create_time desc
    </select>

    <select id="selectDoumuProductInfoByProductId" parameterType="Long" resultMap="DoumuProductInfoResult">
        <include refid="selectDoumuProductInfoVo"/>
        where product_id = #{productId}
    </select>

    <insert id="insertDoumuProductInfo" parameterType="DoumuProductInfo" useGeneratedKeys="true" keyProperty="productId">
        insert into doumu_product_info
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="openid != null "> openid,</if>
            <if test="orderNumber != null "> order_number,</if>
            <if test="name != null and name != ''">name,</if>
            <if test="deliveryType != null">delivery_type,</if>
            <if test="phonenumber != null">phonenumber,</if>
            <if test="quantity != null">quantity,</if>
            <if test="provinceId != null">province_id,</if>
            <if test="province != null">province,</if>
            <if test="cityId != null">city_id,</if>
            <if test="city != null">city,</if>
            <if test="countyId != null">county_id,</if>
            <if test="county != null">county,</if>
            <if test="address != null">address,</if>
            <if test="lon != null">lon,</if>
            <if test="lat != null">lat,</if>
            <if test="flowType != null">flow_type,</if>
            <if test="status != null">status,</if>
            <if test="goodsName != null">goods_name,</if>
            <if test="totalPrice != null and totalPrice != 0">total_price,</if>
            <if test="mailNo != null">mailNo,</if>
            <if test="createBy != null">create_by,</if>
            <if test="createTime != null">create_time,</if>
            <if test="updateBy != null">update_by,</if>
            <if test="updateTime != null">update_time,</if>
            <if test="remark != null">remark,</if>
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="openid != null "> #{openid},</if>
            <if test="orderNumber != null ">#{orderNumber},</if>
            <if test="name != null and name != ''">#{name},</if>
            <if test="deliveryType != null">#{deliveryType},</if>
            <if test="phonenumber != null">#{phonenumber},</if>
            <if test="quantity != null">#{quantity},</if>
            <if test="provinceId != null">#{provinceId},</if>
            <if test="province != null">#{province},</if>
            <if test="cityId != null">#{cityId},</if>
            <if test="city != null">#{city},</if>
            <if test="countyId != null">#{countyId},</if>
            <if test="county != null">#{county},</if>
            <if test="address != null">#{address},</if>
            <if test="lon != null">#{lon},</if>
            <if test="lat != null">#{lat},</if>
            <if test="flowType != null">#{flowType},</if>
            <if test="status != null">#{status},</if>
            <if test="goodsName != null">#{goodsName},</if>
            <if test="totalPrice != null and totalPrice != 0">#{totalPrice},</if>
            <if test="mailNo != null">#{mailNo},</if>
            <if test="createBy != null">#{createBy},</if>
            <if test="createTime != null">#{createTime},</if>
            <if test="updateBy != null">#{updateBy},</if>
            <if test="updateTime != null">#{updateTime},</if>
            <if test="remark != null">#{remark},</if>
        </trim>
    </insert>

    <update id="updateDoumuProductInfo" parameterType="DoumuProductInfo">
        update doumu_product_info
        <trim prefix="SET" suffixOverrides=",">
            <if test="openid != null "> openid = #{openid},</if>
            <if test="orderNumber != null  and orderNumber != ''"> order_number = #{orderNumber},</if>
            <if test="name != null and name != ''">name = #{name},</if>
            <if test="deliveryType != null">delivery_type = #{deliveryType},</if>
            <if test="phonenumber != null">phonenumber = #{phonenumber},</if>
            <if test="quantity != null">quantity = #{quantity},</if>
            <if test="provinceId != null">province_id = #{provinceId},</if>
            <if test="province != null">province = #{province},</if>
            <if test="cityId != null">city_id = #{cityId},</if>
            <if test="city != null">city = #{city},</if>
            <if test="countyId != null">county_id = #{countyId},</if>
            <if test="county != null">county = #{county},</if>
            <if test="address != null">address = #{address},</if>
            <if test="lon != null">lon = #{lon},</if>
            <if test="lat != null">lat = #{lat},</if>
            <if test="flowType != null">flow_type = #{flowType},</if>
            <if test="status != null">status = #{status},</if>
            <if test="goodsName != null">goods_name = #{goodsName},</if>
            <if test="totalPrice != null and totalPrice != 0">total_price = #{totalPrice},</if>
            <if test="mailNo != null">mailNo = #{mailNo},</if>
            <if test="createBy != null">create_by = #{createBy},</if>
            <if test="createTime != null">create_time = #{createTime},</if>
            <if test="updateBy != null">update_by = #{updateBy},</if>
            <if test="updateTime != null">update_time = #{updateTime},</if>
            <if test="remark != null">remark = #{remark},</if>
        </trim>
        where product_id = #{productId}
    </update>

    <update id="updateDoumuProductInfoFlowList">
        update doumu_product_info set flow_type = #{flowType} where product_id in
        <foreach collection="productIdList" index="index" item="productId" open="(" separator="," close=")">
            #{productId}
        </foreach>
    </update>

    <delete id="deleteDoumuProductInfoByProductId" parameterType="Long">
        delete from doumu_product_info where product_id = #{productId}
    </delete>

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