<?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.matrix.system.shopXcx.dao.ShopSearchRecordDao">
|
<!-- 定义ShopSearchRecord 的复杂关联map -->
|
<resultMap type="com.matrix.system.shopXcx.bean.ShopSearchRecord" id="ShopSearchRecordMap">
|
<id property="searchId" column="search_id" />
|
<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="userId" column="user_id" />
|
<result property="searchContent" column="search_content" />
|
<result property="searchBrand" column="search_brand" />
|
<result property="searchPriceStart" column="search_price_start" />
|
<result property="searchPriceEnd" column="search_price_end" />
|
<result property="searchAttrs" column="search_attrs" />
|
<result property="searchType" column="search_type" />
|
<result property="searchDel" column="search_del" />
|
</resultMap>
|
|
|
<!-- 定义ShopSearchRecord 的简单map ,本map不添加其他的关联属性 -->
|
<resultMap type="com.matrix.system.shopXcx.bean.ShopSearchRecord" id="ShopSearchRecordSimpleMap">
|
<id property="searchId" column="search_id" />
|
<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="userId" column="user_id" />
|
<result property="searchContent" column="search_content" />
|
<result property="searchBrand" column="search_brand" />
|
<result property="searchPriceStart" column="search_price_start" />
|
<result property="searchPriceEnd" column="search_price_end" />
|
<result property="searchAttrs" column="search_attrs" />
|
<result property="searchType" column="search_type" />
|
<result property="searchDel" column="search_del" />
|
</resultMap>
|
|
<!-- 字段sql -->
|
<sql id="columns">
|
create_by,
|
create_time,
|
update_by,
|
update_time,
|
search_id,
|
user_id,
|
search_content,
|
search_brand,
|
search_price_start,
|
search_price_end,
|
search_attrs,
|
search_type,
|
search_del
|
</sql>
|
|
<!-- 属性sql -->
|
<sql id="propertys">
|
#{item.createBy},
|
now(),
|
#{item.updateBy},
|
now(),
|
#{item.searchId},
|
#{item.userId},
|
#{item.searchContent},
|
#{item.searchBrand},
|
#{item.searchPriceStart},
|
#{item.searchPriceEnd},
|
#{item.searchAttrs},
|
#{item.searchType},
|
#{item.searchDel}
|
</sql>
|
|
<!-- where sql -->
|
<sql id="where_sql">
|
|
<if test="record!=null">
|
<if test="(record.searchId!=null and record.searchId!='') or (record.searchId!='' and record.searchId==0) ">
|
and search_id = #{record.searchId}
|
</if>
|
<if test="(record.userId!=null and record.userId!='') or (record.userId!='' and record.userId==0) ">
|
and user_id = #{record.userId}
|
</if>
|
<if test="(record.searchContent!=null and record.searchContent!='') or (record.searchContent!='' and record.searchContent==0) ">
|
and search_content = #{record.searchContent}
|
</if>
|
<if test="(record.searchBrand!=null and record.searchBrand!='') or (record.searchBrand!='' and record.searchBrand==0) ">
|
and search_brand = #{record.searchBrand}
|
</if>
|
<if test="(record.searchPriceStart!=null and record.searchPriceStart!='') or (record.searchPriceStart!='' and record.searchPriceStart==0) ">
|
and search_price_start = #{record.searchPriceStart}
|
</if>
|
<if test="(record.searchPriceEnd!=null and record.searchPriceEnd!='') or (record.searchPriceEnd!='' and record.searchPriceEnd==0) ">
|
and search_price_end = #{record.searchPriceEnd}
|
</if>
|
<if test="(record.searchAttrs!=null and record.searchAttrs!='') or (record.searchAttrs!='' and record.searchAttrs==0) ">
|
and search_attrs = #{record.searchAttrs}
|
</if>
|
<if test="(record.searchType!=null and record.searchType!='') or (record.searchType!='' and record.searchType==0) ">
|
and search_type = #{record.searchType}
|
</if>
|
<if test="(record.searchDel!=null and record.searchDel!='') or (record.searchDel!='' and record.searchDel==0) ">
|
and search_del = #{record.searchDel}
|
</if>
|
</if>
|
|
</sql>
|
|
<!-- 插入方法 -->
|
<insert id="insert" parameterType="com.matrix.system.shopXcx.bean.ShopSearchRecord"
|
useGeneratedKeys="true" keyProperty="item.searchId">
|
INSERT INTO shop_search_record (
|
<include refid="columns"></include>
|
)
|
VALUES (
|
<include refid="propertys"></include>
|
)
|
</insert>
|
|
|
|
<!-- 批量插入 -->
|
<insert id="batchInsert" parameterType="java.util.List">
|
INSERT INTO shop_search_record (
|
<include refid="columns"></include>
|
)
|
VALUES
|
<foreach collection="list" item="item" index="index" separator=",">(
|
<include refid="propertys"></include>
|
)</foreach>
|
</insert>
|
|
|
|
|
|
<!-- 根据Map更新 部分更新 -->
|
<update id="updateByMap" parameterType="java.util.HashMap" >
|
UPDATE shop_search_record
|
<set>
|
<if test="_parameter.containsKey('userId')">
|
user_id = #{userId},
|
</if>
|
<if test="_parameter.containsKey('searchContent')">
|
search_content = #{searchContent},
|
</if>
|
<if test="_parameter.containsKey('searchBrand')">
|
search_brand = #{searchBrand},
|
</if>
|
<if test="_parameter.containsKey('searchPriceStart')">
|
search_price_start = #{searchPriceStart},
|
</if>
|
<if test="_parameter.containsKey('searchPriceEnd')">
|
search_price_end = #{searchPriceEnd},
|
</if>
|
<if test="_parameter.containsKey('searchAttrs')">
|
search_attrs = #{searchAttrs},
|
</if>
|
<if test="_parameter.containsKey('searchType')">
|
search_type = #{searchType},
|
</if>
|
<if test="_parameter.containsKey('searchDel')">
|
search_del = #{searchDel},
|
</if>
|
</set>
|
WHERE search_id=#{searchId}
|
</update>
|
|
|
<!-- 根据对象更新 部分更新 -->
|
<update id="updateByModel" parameterType="Integer">
|
UPDATE shop_search_record
|
<set>
|
<if test="record.userId != null and record.userId != '' ">
|
user_id = #{record.userId},
|
</if>
|
<if test="record.searchContent != null and record.searchContent != '' ">
|
search_content = #{record.searchContent},
|
</if>
|
<if test="record.searchBrand != null and record.searchBrand != '' ">
|
search_brand = #{record.searchBrand},
|
</if>
|
<if test="record.searchPriceStart != null ">
|
search_price_start = #{record.searchPriceStart},
|
</if>
|
<if test="record.searchPriceEnd != null ">
|
search_price_end = #{record.searchPriceEnd},
|
</if>
|
<if test="record.searchAttrs != null and record.searchAttrs != '' ">
|
search_attrs = #{record.searchAttrs},
|
</if>
|
<if test="record.searchType != null ">
|
search_type = #{record.searchType},
|
</if>
|
<if test="record.searchDel != null ">
|
search_del = #{record.searchDel},
|
</if>
|
</set>
|
WHERE search_id=#{record.searchId}
|
</update>
|
|
<!-- 批量删除 -->
|
<delete id="deleteByIds" parameterType="java.util.List">
|
delete from shop_search_record where search_id in
|
<foreach collection="list" index="index" item="item" open="("
|
separator="," close=")">
|
#{item}
|
</foreach>
|
</delete>
|
|
<!-- 根据id删除-->
|
<delete id="deleteById" parameterType="Integer">
|
DELETE FROM shop_search_record
|
where search_id=#{searchId}
|
</delete>
|
|
<!-- 根据对象删除-->
|
<delete id="deleteByModel" parameterType="com.matrix.system.shopXcx.bean.ShopSearchRecord">
|
DELETE FROM shop_search_record
|
<where>
|
<include refid="where_sql" ></include>
|
</where>
|
</delete>
|
|
|
|
<!-- 分页查询 -->
|
<select id="selectInPage" resultMap="ShopSearchRecordMap">
|
select
|
<include refid="columns" ></include>
|
from shop_search_record
|
<where>
|
<include refid="where_sql"></include>
|
</where>
|
<if test="pageVo !=null"><!-- 判断pageVo对象是否为空 -->
|
<if test="pageVo.sort !=null and pageVo.order !=null">
|
order by
|
${pageVo.sort} ${pageVo.order}
|
</if>
|
<if test="pageVo.offset >=0 and pageVo.limit >0">
|
limit
|
#{pageVo.offset},#{pageVo.limit}
|
</if>
|
</if>
|
</select>
|
|
<!-- 查询总条数 -->
|
<select id="selectTotalRecord" parameterType="long" resultType="java.lang.Integer">
|
select count(*)
|
from shop_search_record
|
<where>
|
<include refid="where_sql"></include>
|
</where>
|
</select>
|
|
<!-- 根据id查询-->
|
<select id="selectById" resultMap="ShopSearchRecordMap">
|
select
|
<include refid="columns" ></include>
|
from shop_search_record
|
where search_id=#{searchId}
|
</select>
|
|
|
<!-- 根据id 锁表查询-->
|
<select id="selectForUpdate" resultMap="ShopSearchRecordMap">
|
select
|
<include refid="columns" ></include>
|
from shop_search_record
|
where search_id=#{search_id}
|
for update
|
</select>
|
|
|
|
<!-- 根据对象查询-->
|
<select id="selectByModel" resultMap="ShopSearchRecordMap">
|
select
|
<include refid="columns" ></include>
|
from shop_search_record
|
<where>
|
<include refid="where_sql"></include>
|
</where>
|
</select>
|
|
<!-- 根据用户ID查询搜索记录-->
|
<select id="selectByUserId" resultType="java.lang.String">
|
select DISTINCT search_content
|
from shop_search_record
|
where user_id = #{userId}
|
and search_type = 1
|
and search_del = 2
|
order by create_time desc
|
limit 0,10
|
</select>
|
|
<update id="deleteByUserId" parameterType="String">
|
UPDATE shop_search_record
|
set search_del = 1
|
where user_id = #{userId}
|
</update>
|
</mapper>
|