SubjectGoodsMapperMapper.xml 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  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. <result column="tenant_id_" property="tenantId"/>
  17. </resultMap>
  18. <!-- 根据主键查询一条记录 -->
  19. <select id="get" resultMap="SubjectGoodsMapper">
  20. SELECT * FROM subject_goods_mapper WHERE id_ = #{id}
  21. </select>
  22. <!-- 全查询 -->
  23. <select id="findAll" resultMap="SubjectGoodsMapper">
  24. SELECT * FROM subject_goods_mapper where tenant_id_ = #{tenantId} ORDER BY id_
  25. </select>
  26. <!-- 向数据库增加一条记录 -->
  27. <insert id="insert" parameterType="com.ym.mec.biz.dal.entity.SubjectGoodsMapper" useGeneratedKeys="true"
  28. keyColumn="id" keyProperty="id">
  29. INSERT INTO subject_goods_mapper (subject_id_,goods_category_id_,create_time_,update_time_,type_,goods_id_list_,tenant_id_)
  30. VALUES(#{subjectId},#{goodsCategoryId},now(),now(),#{type,typeHandler=com.ym.mec.common.dal.CustomEnumTypeHandler},#{goodsIdList},#{tenantId})
  31. </insert>
  32. <insert id="batchAdd">
  33. INSERT INTO subject_goods_mapper (subject_id_,goods_category_id_,create_time_,update_time_,tenant_id_)
  34. VALUES
  35. <foreach collection="subjectIds" item="item" index="index" separator=",">
  36. (#{item},#{goodsCategoryId},now(),now(),#{tenantId})
  37. </foreach>
  38. </insert>
  39. <!-- 根据主键查询一条记录 -->
  40. <update id="update" parameterType="com.ym.mec.biz.dal.entity.SubjectGoodsMapper">
  41. UPDATE subject_goods_mapper
  42. <set>
  43. <if test="subjectId != null">
  44. subject_id_ = #{subjectId},
  45. </if>
  46. <if test="updateTime != null">
  47. update_time_ = NOW(),
  48. </if>
  49. <if test="goodsCategoryId != null">
  50. goods_category_id_ = #{goodsCategoryId},
  51. </if>
  52. <if test="type != null">
  53. type_ = #{type,typeHandler=com.ym.mec.common.dal.CustomEnumTypeHandler},
  54. </if>
  55. <if test="goodsIdList != null">
  56. goods_id_list_ = #{goodsIdList},
  57. </if>
  58. </set>
  59. WHERE id_ = #{id} and tenant_id_ = #{tenantId}
  60. </update>
  61. <!-- 根据主键删除一条记录 -->
  62. <delete id="delete">
  63. DELETE FROM subject_goods_mapper WHERE id_ = #{id}
  64. </delete>
  65. <delete id="delByGoodsCategoryId">
  66. DELETE FROM subject_goods_mapper WHERE goods_category_id_ = #{goodsCategoryId}
  67. </delete>
  68. <!-- 分页查询 -->
  69. <select id="queryPage" resultMap="SubjectGoodsMapper" parameterType="map">
  70. SELECT * FROM subject_goods_mapper where tenant_id_ = #{tenantId} ORDER BY id_
  71. <include refid="global.limit"/>
  72. </select>
  73. <!-- 查询当前表的总记录数 -->
  74. <select id="queryCount" resultType="int">
  75. SELECT COUNT(*) FROM subject_goods_mapper where tenant_id_ = #{tenantId}
  76. </select>
  77. <select id="countSubjectGoods" resultType="java.lang.Integer">
  78. SELECT COUNT(sgm.id_) FROM subject_goods_mapper sgm where sgm.tenant_id_ = #{tenantId}
  79. </select>
  80. <select id="querySubjectGoods" resultMap="querySubjectGoodsMap">
  81. SELECT sgc.*,g.type_ goods_type_,g.name_ goods_name_,g.id_ goods_id_ FROM
  82. (SELECT s.name_ subject_name_,s.id_ subject_id_,sgm.goods_category_id_ goods_category_id_,
  83. sgm.goods_id_list_,sgm.id_ subject_goods_mapper_id_
  84. FROM subject_goods_mapper sgm
  85. LEFT JOIN `subject` s ON s.id_ = sgm.subject_id_
  86. <!-- LEFT JOIN goods_category gc ON gc.id_ = sgm.goods_category_id_ -->
  87. <include refid="global.limit"/>) sgc
  88. LEFT JOIN goods g ON FIND_IN_SET(g.id_,sgc.goods_id_list_)
  89. where g.tenant_id_ = #{tenantId}
  90. </select>
  91. <resultMap id="querySubjectGoodsMap" type="com.ym.mec.biz.dal.dto.SubjectGoodsDto">
  92. <result property="subjectName" column="subject_name_"/>
  93. <result property="subjectGoodsMapperId" column="subject_goods_mapper_id_"/>
  94. <result property="subjectId" column="subject_id_"/>
  95. <result property="goodsCategoryId" column="goods_category_id_"/>
  96. <result property="goodsCategoryName" column="goods_category_name_"/>
  97. <collection property="goodsList" ofType="com.ym.mec.biz.dal.entity.Goods">
  98. <result property="id" column="goods_id_"/>
  99. <result property="name" column="goods_name_"/>
  100. <result property="type" column="goods_type_"/>
  101. </collection>
  102. </resultMap>
  103. <select id="queryByCategoryIds" resultMap="SubjectGoodsMapper">
  104. select t.* from subject_goods_mapper t
  105. where t.goods_category_id_ in
  106. <foreach collection="categoryIdList" item="item" separator="," open="(" close=")">
  107. #{item}
  108. </foreach>
  109. </select>
  110. </mapper>