SubjectGoodsMapperMapper.xml 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  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. <!--
  4. 这个文件是自动生成的。
  5. 不要修改此文件。所有改动将在下次重新自动生成时丢失。
  6. -->
  7. <mapper namespace="com.ym.mec.biz.dal.dao.SubjectGoodsMapperDao">
  8. <resultMap type="com.ym.mec.biz.dal.entity.SubjectGoodsMapper" id="SubjectGoodsMapper">
  9. <result column="id_" property="id"/>
  10. <result column="subject_id_" property="subjectId"/>
  11. <result column="type_" property="type" typeHandler="com.ym.mec.common.dal.CustomEnumTypeHandler"/>
  12. <result column="goods_category_id_" property="goodsCategoryId"/>
  13. <result column="goods_id_list_" property="goodsIdList"/>
  14. <result column="create_time_" property="createTime"/>
  15. <result column="update_time_" property="updateTime"/>
  16. </resultMap>
  17. <!-- 根据主键查询一条记录 -->
  18. <select id="get" resultMap="SubjectGoodsMapper">
  19. SELECT * FROM subject_goods_mapper WHERE id_ = #{id}
  20. </select>
  21. <!-- 全查询 -->
  22. <select id="findAll" resultMap="SubjectGoodsMapper">
  23. SELECT * FROM subject_goods_mapper ORDER BY id_
  24. </select>
  25. <!-- 向数据库增加一条记录 -->
  26. <insert id="insert" parameterType="com.ym.mec.biz.dal.entity.SubjectGoodsMapper" useGeneratedKeys="true"
  27. keyColumn="id" keyProperty="id">
  28. INSERT INTO subject_goods_mapper (subject_id_,goods_category_id_,create_time_,update_time_,type_,goods_id_list_)
  29. VALUES(#{subjectId},#{goodsCategoryId},now(),now(),#{type,typeHandler=com.ym.mec.common.dal.CustomEnumTypeHandler},#{goodsIdList})
  30. </insert>
  31. <insert id="batchAdd">
  32. INSERT INTO subject_goods_mapper (subject_id_,goods_category_id_,create_time_,update_time_)
  33. VALUES
  34. <foreach collection="subjectIds" item="item" index="index" separator=",">
  35. (#{item},#{goodsCategoryId},now(),now())
  36. </foreach>
  37. </insert>
  38. <!-- 根据主键查询一条记录 -->
  39. <update id="update" parameterType="com.ym.mec.biz.dal.entity.SubjectGoodsMapper">
  40. UPDATE subject_goods_mapper
  41. <set>
  42. <if test="subjectId != null">
  43. subject_id_ = #{subjectId},
  44. </if>
  45. <if test="updateTime != null">
  46. update_time_ = NOW(),
  47. </if>
  48. <if test="goodsCategoryId != null">
  49. goods_category_id_ = #{goodsCategoryId},
  50. </if>
  51. <if test="type != null">
  52. type_ = #{type,typeHandler=com.ym.mec.common.dal.CustomEnumTypeHandler},
  53. </if>
  54. <if test="goodsIdList != null">
  55. goods_id_list_ = #{goodsIdList},
  56. </if>
  57. </set>
  58. WHERE id_ = #{id}
  59. </update>
  60. <!-- 根据主键删除一条记录 -->
  61. <delete id="delete">
  62. DELETE FROM subject_goods_mapper WHERE id_ = #{id}
  63. </delete>
  64. <delete id="delByGoodsCategoryId">
  65. DELETE FROM subject_goods_mapper WHERE goods_category_id_ = #{goodsCategoryId}
  66. </delete>
  67. <!-- 分页查询 -->
  68. <select id="queryPage" resultMap="SubjectGoodsMapper" parameterType="map">
  69. SELECT * FROM subject_goods_mapper ORDER BY id_
  70. <include refid="global.limit"/>
  71. </select>
  72. <!-- 查询当前表的总记录数 -->
  73. <select id="queryCount" resultType="int">
  74. SELECT COUNT(*) FROM subject_goods_mapper
  75. </select>
  76. <select id="countSubjectGoods" resultType="java.lang.Integer">
  77. SELECT COUNT(sgm.id_) FROM subject_goods_mapper sgm
  78. </select>
  79. <select id="querySubjectGoods" resultMap="querySubjectGoodsMap">
  80. SELECT sgc.*,g.type_ goods_type_,g.name_ goods_name_,g.id_ goods_id_ FROM
  81. (SELECT s.name_ subject_name_,s.id_ subject_id_,gc.id_ goods_category_id_,gc.name_ goods_category_name_,
  82. sgm.goods_id_list_,sgm.id_ subject_goods_mapper_id_
  83. FROM subject_goods_mapper sgm
  84. LEFT JOIN `subject` s ON s.id_ = sgm.subject_id_
  85. LEFT JOIN goods_category gc ON gc.id_ = sgm.goods_category_id_ <include refid="global.limit"/>) sgc
  86. LEFT JOIN goods g ON FIND_IN_SET(g.id_,sgc.goods_id_list_)
  87. </select>
  88. <resultMap id="querySubjectGoodsMap" type="com.ym.mec.biz.dal.dto.SubjectGoodsDto">
  89. <result property="subjectName" column="subject_name_"/>
  90. <result property="subjectGoodsMapperId" column="subject_goods_mapper_id_"/>
  91. <result property="subjectId" column="subject_id_"/>
  92. <result property="goodsCategoryId" column="goods_category_id_"/>
  93. <result property="goodsCategoryName" column="goods_category_name_"/>
  94. <collection property="goodsList" ofType="com.ym.mec.biz.dal.entity.Goods">
  95. <result property="id" column="goods_id_"/>
  96. <result property="name" column="goods_name_"/>
  97. <result property="type" column="goods_type_"/>
  98. </collection>
  99. </resultMap>
  100. </mapper>