SearchHistoryDao.xml 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
  3. <mapper namespace="com.kmall.admin.dao.SearchHistoryDao">
  4. <!-- 可根据自己的需求,是否要使用 -->
  5. <resultMap type="com.kmall.admin.entity.SearchHistoryEntity" id="searchHistoryMap">
  6. <result property="id" column="id"/>
  7. <result property="keyword" column="keyword"/>
  8. <result property="from" column="from"/>
  9. <result property="addTime" column="add_time"/>
  10. <result property="userId" column="user_id"/>
  11. <result property="userName" column="user_name"/>
  12. </resultMap>
  13. <select id="queryObject" resultType="com.kmall.admin.entity.SearchHistoryEntity">
  14. select * from mall_search_history where id = #{value}
  15. </select>
  16. <select id="queryList" resultMap="searchHistoryMap">
  17. select distinct a.* ,b.nickname as user_name
  18. from mall_search_history a
  19. left join mall_user b on a.user_id = b.id
  20. LEFT JOIN mall_merch_user d ON a.user_id=d.user_id
  21. left join mall_store s on d.store_id = s.id
  22. where 1=1
  23. <if test="storeId != null">
  24. and d.store_id = #{storeId}
  25. </if>
  26. <if test="merchSn != null and merchSn.trim() != ''">
  27. and d.merch_sn = #{merchSn}
  28. </if>
  29. <if test="thirdPartyMerchCode != null and thirdPartyMerchCode.trim() != ''">
  30. AND s.third_party_merch_code = #{thirdPartyMerchCode}
  31. </if>
  32. <if test="keyword != null and keyword.trim() != ''">
  33. AND a.keyword LIKE CONCAT('%',#{keyword},'%')
  34. </if>
  35. <choose>
  36. <when test="sidx != null and sidx.trim() != ''">
  37. order by ${sidx} ${order}
  38. </when>
  39. <otherwise>
  40. order by a.id desc
  41. </otherwise>
  42. </choose>
  43. <if test="offset != null and limit != null">
  44. limit #{offset}, #{limit}
  45. </if>
  46. </select>
  47. <select id="queryTotal" resultType="int">
  48. select count(distinct a.id)
  49. from mall_search_history a
  50. LEFT JOIN mall_merch_user d ON a.user_id=d.user_id
  51. left join mall_store s on d.store_id = s.id
  52. where 1=1
  53. <if test="storeId != null">
  54. and d.store_id = #{storeId}
  55. </if>
  56. <if test="merchSn != null and merchSn.trim() != ''">
  57. and d.merch_sn = #{merchSn}
  58. </if>
  59. <if test="thirdPartyMerchCode != null and thirdPartyMerchCode.trim() != ''">
  60. AND s.third_party_merch_code = #{thirdPartyMerchCode}
  61. </if>
  62. </select>
  63. <insert id="save" parameterType="com.kmall.admin.entity.SearchHistoryEntity" useGeneratedKeys="true" keyProperty="id">
  64. insert into mall_search_history
  65. (
  66. `keyword`,
  67. `from`,
  68. `add_time`,
  69. `user_id`
  70. )
  71. values
  72. (
  73. #{keyword},
  74. #{from},
  75. #{addTime},
  76. #{userId}
  77. )
  78. </insert>
  79. <update id="update" parameterType="com.kmall.admin.entity.SearchHistoryEntity">
  80. update mall_search_history
  81. <set>
  82. <if test="keyword != null">`keyword` = #{keyword},</if>
  83. <if test="from != null">`from` = #{from},</if>
  84. <if test="addTime != null">`add_time` = #{addTime},</if>
  85. <if test="userId != null">`user_id` = #{userId}</if>
  86. </set>
  87. where id = #{id}
  88. </update>
  89. <delete id="delete">
  90. delete from mall_search_history where id = #{value}
  91. </delete>
  92. <delete id="deleteBatch">
  93. delete from mall_search_history where id in
  94. <foreach item="id" collection="array" open="(" separator="," close=")">
  95. #{id}
  96. </foreach>
  97. </delete>
  98. </mapper>