AttributeDao.xml 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  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.AttributeDao">
  4. <resultMap type="com.kmall.admin.entity.AttributeEntity" id="attributeMap">
  5. <result property="id" column="id"/>
  6. <result property="attributeCategoryId" column="attribute_category_id"/>
  7. <result property="name" column="name"/>
  8. <result property="inputType" column="input_type"/>
  9. <result property="value" column="value"/>
  10. <result property="sortOrder" column="sort_order"/>
  11. </resultMap>
  12. <select id="queryObject" resultType="com.kmall.admin.entity.AttributeEntity">
  13. select
  14. id,
  15. attribute_category_id,
  16. name,
  17. input_type,
  18. value,
  19. sort_order
  20. from mall_attribute
  21. where id = #{id}
  22. </select>
  23. <select id="queryList" resultType="com.kmall.admin.entity.AttributeEntity">
  24. SELECT
  25. a.id,
  26. a.attribute_category_id,
  27. a.NAME,
  28. a.input_type,
  29. a.VALUE,
  30. a.sort_order,
  31. c.NAME category_name
  32. FROM mall_attribute a
  33. LEFT JOIN mall_category c ON a.attribute_category_id = c.id
  34. WHERE 1=1
  35. <if test="name != null and name.trim() != ''">
  36. AND a.name LIKE concat('%', #{name},'%')
  37. </if>
  38. <if test="categoryName != null and categoryName.trim() != ''">
  39. AND c.name LIKE concat('%', #{categoryName},'%')
  40. </if>
  41. <if test="attributeCategoryId != null and attributeCategoryId.trim() != ''">
  42. AND a.attribute_category_id = #{attributeCategoryId}
  43. </if>
  44. <choose>
  45. <when test="sidx != null and sidx.trim() != ''">
  46. order by ${sidx} ${order}
  47. </when>
  48. <otherwise>
  49. order by a.attribute_category_id desc
  50. </otherwise>
  51. </choose>
  52. <if test="offset != null and limit != null">
  53. limit #{offset}, #{limit}
  54. </if>
  55. </select>
  56. <select id="queryTotal" resultType="int">
  57. select count(*) from mall_attribute a
  58. LEFT JOIN mall_category c ON a.attribute_category_id = c.id
  59. WHERE 1=1
  60. <if test="name != null and name.trim() != ''">
  61. AND a.name LIKE concat('%', #{name},'%')
  62. </if>
  63. <if test="categoryName != null and categoryName.trim() != ''">
  64. AND c.name LIKE concat('%', #{categoryName},'%')
  65. </if>
  66. <if test="attributeCategoryId != null and attributeCategoryId.trim() != ''">
  67. AND a.attribute_category_id = #{attributeCategoryId}
  68. </if>
  69. </select>
  70. <insert id="save" parameterType="com.kmall.admin.entity.AttributeEntity" useGeneratedKeys="true" keyProperty="id">
  71. insert into mall_attribute(
  72. `attribute_category_id`,
  73. `name`,
  74. `input_type`,
  75. `value`,
  76. `sort_order`)
  77. values(
  78. #{attributeCategoryId},
  79. #{name},
  80. #{inputType},
  81. #{value},
  82. #{sortOrder})
  83. </insert>
  84. <update id="update" parameterType="com.kmall.admin.entity.AttributeEntity">
  85. update mall_attribute
  86. <set>
  87. <if test="attributeCategoryId != null">`attribute_category_id` = #{attributeCategoryId},</if>
  88. <if test="name != null">`name` = #{name},</if>
  89. <if test="inputType != null">`input_type` = #{inputType},</if>
  90. <if test="value != null">`value` = #{value},</if>
  91. <if test="sortOrder != null">`sort_order` = #{sortOrder}</if>
  92. </set>
  93. where id = #{id}
  94. </update>
  95. <delete id="delete">
  96. delete from mall_attribute where id = #{value}
  97. </delete>
  98. <delete id="deleteBatch">
  99. delete from mall_attribute where id in
  100. <foreach item="id" collection="array" open="(" separator="," close=")">
  101. #{id}
  102. </foreach>
  103. </delete>
  104. </mapper>