SearchHistoryDao.xml 3.1 KB

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