SearchHistoryDao.xml 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  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. <choose>
  33. <when test="sidx != null and sidx.trim() != ''">
  34. order by ${sidx} ${order}
  35. </when>
  36. <otherwise>
  37. order by a.id desc
  38. </otherwise>
  39. </choose>
  40. <if test="offset != null and limit != null">
  41. limit #{offset}, #{limit}
  42. </if>
  43. </select>
  44. <select id="queryTotal" resultType="int">
  45. select count(distinct a.id)
  46. from mall_search_history a
  47. LEFT JOIN mall_merch_user d ON a.user_id=d.user_id
  48. left join mall_store s on d.store_id = s.id
  49. where 1=1
  50. <if test="storeId != null">
  51. and d.store_id = #{storeId}
  52. </if>
  53. <if test="merchSn != null and merchSn.trim() != ''">
  54. and d.merch_sn = #{merchSn}
  55. </if>
  56. <if test="thirdPartyMerchCode != null and thirdPartyMerchCode.trim() != ''">
  57. AND s.third_party_merch_code = #{thirdPartyMerchCode}
  58. </if>
  59. </select>
  60. <insert id="save" parameterType="com.kmall.admin.entity.SearchHistoryEntity" useGeneratedKeys="true" keyProperty="id">
  61. insert into mall_search_history
  62. (
  63. `keyword`,
  64. `from`,
  65. `add_time`,
  66. `user_id`
  67. )
  68. values
  69. (
  70. #{keyword},
  71. #{from},
  72. #{addTime},
  73. #{userId}
  74. )
  75. </insert>
  76. <update id="update" parameterType="com.kmall.admin.entity.SearchHistoryEntity">
  77. update mall_search_history
  78. <set>
  79. <if test="keyword != null">`keyword` = #{keyword},</if>
  80. <if test="from != null">`from` = #{from},</if>
  81. <if test="addTime != null">`add_time` = #{addTime},</if>
  82. <if test="userId != null">`user_id` = #{userId}</if>
  83. </set>
  84. where id = #{id}
  85. </update>
  86. <delete id="delete">
  87. delete from mall_search_history where id = #{value}
  88. </delete>
  89. <delete id="deleteBatch">
  90. delete from mall_search_history where id in
  91. <foreach item="id" collection="array" open="(" separator="," close=")">
  92. #{id}
  93. </foreach>
  94. </delete>
  95. </mapper>