ProductDao.xml 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  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.ProductDao">
  4. <resultMap type="com.kmall.admin.entity.ProductEntity" id="productMap">
  5. <result property="id" column="id"/>
  6. <result property="goodsId" column="goods_id"/>
  7. <result property="goodsSpecificationIds" column="goods_specification_ids"/>
  8. <result property="goodsSpecificationNameValue" column="goods_specification_name_value"/>
  9. <result property="goodsSn" column="goods_sn"/>
  10. <result property="goodsNumber" column="goods_number"/>
  11. <result property="goodsDefault" column="goods_default"/>
  12. </resultMap>
  13. <select id="queryObject" resultType="com.kmall.admin.entity.ProductEntity">
  14. select
  15. id,
  16. goods_id,
  17. goods_specification_ids,
  18. goods_specification_name_value,
  19. goods_sn,
  20. goods_number,
  21. goods_default
  22. from mall_product
  23. where id = #{id}
  24. </select>
  25. <select id="queryObjectByGoodsId" resultType="com.kmall.admin.entity.ProductEntity">
  26. select
  27. *
  28. from mall_product
  29. where goods_id = #{goodsId}
  30. </select>
  31. <select id="queryList" resultType="com.kmall.admin.entity.ProductEntity">
  32. select
  33. mall_product.*,
  34. mall_goods.name goods_name
  35. from mall_product
  36. LEFT JOIN mall_goods ON mall_product.goods_id = mall_goods.id
  37. WHERE 1=1
  38. <if test="goodsId != null and goodsId != ''">
  39. AND mall_product.goods_id = #{goodsId}
  40. </if>
  41. <if test="goodsSpecificationIds != null and goodsSpecificationIds != ''">
  42. AND mall_product.goods_specification_ids = #{goodsSpecificationIds}
  43. </if>
  44. <if test="goodsName != null and goodsName.trim() != ''">
  45. AND mall_goods.name LIKE concat('%',#{goodsName},'%')
  46. </if>
  47. <choose>
  48. <when test="sidx != null and sidx.trim() != ''">
  49. order by ${sidx} ${order}
  50. </when>
  51. <otherwise>
  52. order by mall_product.id desc
  53. </otherwise>
  54. </choose>
  55. <if test="offset != null and limit != null">
  56. limit #{offset}, #{limit}
  57. </if>
  58. </select>
  59. <select id="queryTotal" resultType="int">
  60. select count(*) from mall_product
  61. LEFT JOIN mall_goods ON mall_product.goods_id = mall_goods.id
  62. WHERE 1=1
  63. <if test="goodsId != null and goodsId != ''">
  64. AND mall_product.goods_id = #{goodsId}
  65. </if>
  66. <if test="goodsName != null and goodsName.trim() != ''">
  67. AND mall_goods.name LIKE concat('%',#{goodsName},'%')
  68. </if>
  69. <if test="goodsSpecificationIds != null and goodsSpecificationIds != ''">
  70. AND mall_product.goods_specification_ids = #{goodsSpecificationIds}
  71. </if>
  72. </select>
  73. <insert id="save" parameterType="com.kmall.admin.entity.ProductEntity" useGeneratedKeys="true" keyProperty="id">
  74. insert into mall_product(
  75. `goods_id`,
  76. `goods_specification_ids`,
  77. `goods_specification_name_value`,
  78. `goods_sn`,
  79. `goods_number`,
  80. `goods_default`
  81. )
  82. values(
  83. #{goodsId},
  84. #{goodsSpecificationIds},
  85. #{goodsSpecificationNameValue},
  86. #{goodsSn},
  87. #{goodsNumber},
  88. #{goodsDefault}
  89. )
  90. </insert>
  91. <update id="update" parameterType="com.kmall.admin.entity.ProductEntity">
  92. update mall_product
  93. <set>
  94. <if test="goodsId != null">`goods_id` = #{goodsId},</if>
  95. <if test="goodsSpecificationIds != null">`goods_specification_ids` = #{goodsSpecificationIds},</if>
  96. <if test="goodsSpecificationNameValue != null">`goods_specification_name_value` =
  97. #{goodsSpecificationNameValue},
  98. </if>
  99. <if test="goodsSn != null">`goods_sn` = #{goodsSn},</if>
  100. <if test="goodsNumber != null">`goods_number` = #{goodsNumber},</if>
  101. <if test="goodsDefault != null">`goods_default` = #{goodsDefault},</if>
  102. </set>
  103. where id = #{id}
  104. </update>
  105. <delete id="delete">
  106. delete from mall_product where id = #{id}
  107. </delete>
  108. <delete id="deleteByGoodsId">
  109. delete from mall_product where goods_id = #{goodsId}
  110. </delete>
  111. <delete id="deleteBatch">
  112. delete from mall_product where id in
  113. <foreach item="id" collection="array" open="(" separator="," close=")">
  114. #{id}
  115. </foreach>
  116. </delete>
  117. </mapper>