<?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.syzy.mapper.BBusiWishRecordsMapper">

  <resultMap type="BBusiWishRecords" id="BBusiWishRecordsResult">
    <result property="id" column="id" />
    <result property="customerCode" column="customerCode" />
    <result property="type" column="type" />
    <result property="code" column="code" />
    <result property="name" column="name" />
    <result property="batch" column="batch" />
    <result property="batchName" column="batchName" />
    <result property="detail" column="detail" />
    <result property="userSnapshot" column="userSnapshot" />
    <result property="createTime" column="createTime" />
    <result property="status" column="status" />
    <result property="obsoleted" column="obsoleted" />
  </resultMap>

  <sql id="selectBBusiWishRecordsVo">
    select id, customerCode, type, code, name, batch,batchName, userSnapshot,detail, createTime, status,obsoleted from b_busi_wish_records
  </sql>

  <select id="selectBBusiWishRecordsList" parameterType="BBusiWishRecords" resultMap="BBusiWishRecordsResult">
    <include refid="selectBBusiWishRecordsVo" />
    <where>
      <if test="id != null"> and id = #{id}</if>
      <if test="customerCode != null  and customerCode != ''"> and customerCode = #{customerCode}</if>
      <if test="type != null "> and type = #{type}</if>
      <if test="code != null  and code != ''"> and code = #{code}</if>
      <if test="name != null  and name != '' and !exactName"> and name like concat('%', #{name}, '%')</if>
      <if test="name != null  and name != '' and exactName"> and name = #{name}</if>
      <if test="batch != null  and batch != ''"> and batch = #{batch}</if>
      <if test="batchName != null  and batchName != ''"> and batchName = #{batchName}</if>
      <if test="userSnapshot != null  and userSnapshot != ''"> and userSnapshot = #{userSnapshot}</if>
      <if test="detail != null  and detail != ''"> and detail = #{detail}</if>
      <if test="createTime != null "> and createTime = #{createTime}</if>
      <if test="status != null "> and status = #{status}</if>
      <if test="obsoleted != null "> and obsoleted = #{obsoleted}</if>
    </where>
    order by id desc
  </select>

  <select id="selectBBusiWishRecordsById" parameterType="Long" resultMap="BBusiWishRecordsResult">
    <include refid="selectBBusiWishRecordsVo" />
    where id = #{id}
  </select>

  <insert id="insertBBusiWishRecords" parameterType="BBusiWishRecords" useGeneratedKeys="true" keyProperty="id">
    insert into b_busi_wish_records
    <trim prefix="(" suffix=")" suffixOverrides=",">
      <if test="customerCode != null and customerCode != ''">customerCode,</if>
      <if test="type != null">type,</if>
      <if test="code != null">code,</if>
      <if test="name != null">name,</if>
      <if test="batch != null">batch,</if>
      <if test="batchName != null">batchName,</if>
      <if test="userSnapshot != null">userSnapshot,</if>
      <if test="detail != null">detail,</if>
      <if test="createTime != null">createTime,</if>
      <if test="status != null">status,</if>
      <if test="obsoleted != null">obsoleted,</if>
    </trim>
    <trim prefix="values (" suffix=")" suffixOverrides=",">
      <if test="customerCode != null and customerCode != ''">#{customerCode},</if>
      <if test="type != null">#{type},</if>
      <if test="code != null">#{code},</if>
      <if test="name != null">#{name},</if>
      <if test="batch != null">#{batch},</if>
      <if test="batchName != null">#{batchName},</if>
      <if test="userSnapshot != null">#{userSnapshot},</if>
      <if test="detail != null">#{detail},</if>
      <if test="createTime != null">#{createTime},</if>
      <if test="status != null">#{status},</if>
      <if test="obsoleted != null">#{obsoleted},</if>
    </trim>
  </insert>

  <update id="updateBBusiWishRecords" parameterType="BBusiWishRecords">
    update b_busi_wish_records
    <trim prefix="SET" suffixOverrides=",">
      <if test="customerCode != null and customerCode != ''">customerCode = #{customerCode},</if>
      <if test="type != null">type = #{type},</if>
      <if test="code != null">code = #{code},</if>
      <if test="name != null">name = #{name},</if>
      <if test="batch != null">batch = #{batch},</if>
      <if test="batchName != null">batchName = #{batchName},</if>
      <if test="userSnapshot != null">userSnapshot = #{userSnapshot},</if>
      <if test="detail != null">detail = #{detail},</if>
      <if test="createTime != null">createTime = #{createTime},</if>
      <if test="status != null">status = #{status},</if>
      <if test="obsoleted != null">obsoleted = #{obsoleted},</if>
    </trim>
    where id = #{id}
  </update>

  <update id="updateObsoleteByUser" parameterType="Long">
    update b_busi_wish_records wr set wr.obsoleted = true where wr.customerCode  = #{userId}
  </update>

  <delete id="deleteBBusiWishRecordsById" parameterType="Long">
    delete from b_busi_wish_records where id = #{id}
  </delete>

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