StudentGoodsSellMapper.xml 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211
  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.StudentGoodsSellDao">
  8. <resultMap type="com.ym.mec.biz.dal.entity.StudentGoodsSell" id="StudentGoodsSell">
  9. <result column="id_" property="id" />
  10. <result column="user_id_" property="userId" />
  11. <result column="teacher_id_" property="teacherId" />
  12. <result column="goods_json_" property="goodsJson" />
  13. <result column="total_amount_" property="totalAmount" />
  14. <result column="market_amount_" property="marketAmount" />
  15. <result column="coupon_market_amount_" property="couponMarketAmount" />
  16. <result column="order_no_" property="orderNo" />
  17. <result column="username_" property="userName" />
  18. <result column="organ_id_" property="organId" />
  19. <result column="author_user_" property="authorUser" />
  20. <result column="cooperation_organ_id_" property="cooperationOrganId" />
  21. <result column="create_time_" property="createTime" />
  22. <result column="update_time_" property="updateTime" />
  23. <result column="coupon_ids_" property="couponIds" />
  24. <result column="tenant_id_" property="tenantId"/>
  25. </resultMap>
  26. <!-- 根据主键查询一条记录 -->
  27. <select id="get" resultMap="StudentGoodsSell" >
  28. SELECT sgs.*,su.username_ FROM student_goods_sell sgs
  29. LEFT JOIN sys_user su ON su.id_ = sgs.user_id_
  30. WHERE sgs.id_ = #{id}
  31. </select>
  32. <!-- 全查询 -->
  33. <select id="findAll" resultMap="StudentGoodsSell">
  34. SELECT * FROM student_goods_sell where tenant_id_ = #{tenantId} ORDER BY id_
  35. </select>
  36. <!-- 向数据库增加一条记录 -->
  37. <insert id="insert" parameterType="com.ym.mec.biz.dal.entity.StudentGoodsSell" useGeneratedKeys="true" keyColumn="id" keyProperty="id">
  38. INSERT INTO student_goods_sell (user_id_,teacher_id_,goods_json_,total_amount_,market_amount_,
  39. create_time_,update_time_,order_no_,organ_id_,author_user_,cooperation_organ_id_,coupon_market_amount_,coupon_ids_,tenant_id_,goods_type_)
  40. VALUES(#{userId},#{teacherId},#{goodsJson},#{totalAmount},#{marketAmount},
  41. NOW(),NOW(),#{orderNo},#{organId},#{authorUser},#{cooperationOrganId},#{couponMarketAmount},#{couponIds},#{tenantId},#{goodsType})
  42. </insert>
  43. <!-- 根据主键查询一条记录 -->
  44. <update id="update" parameterType="com.ym.mec.biz.dal.entity.StudentGoodsSell">
  45. UPDATE student_goods_sell <set>
  46. <if test="couponIds != null">
  47. coupon_ids_ = #{couponIds},
  48. </if>
  49. <if test="couponMarketAmount != null">
  50. coupon_market_amount_ = #{couponMarketAmount},
  51. </if>
  52. <if test="cooperationOrganId != null">
  53. cooperation_organ_id_ = #{cooperationOrganId},
  54. </if>
  55. <if test="authorUser != null">
  56. author_user_ = #{authorUser},
  57. </if>
  58. <if test="organId != null">
  59. organ_id_ = #{organId},
  60. </if>
  61. <if test="orderNo != null">
  62. order_no_ = #{orderNo},
  63. </if>
  64. <if test="userId != null">
  65. user_id_ = #{userId},
  66. </if>
  67. <if test="totalAmount != null">
  68. total_amount_ = #{totalAmount},
  69. </if>
  70. <if test="marketAmount != null">
  71. market_amount_ = #{marketAmount},
  72. </if>
  73. <if test="teacherId != null">
  74. teacher_id_ = #{teacherId},
  75. </if>
  76. <if test="goodsJson != null">
  77. goods_json_ = #{goodsJson},
  78. </if>
  79. <if test="goodsType != null">
  80. goods_type_ = #{goodsType},
  81. </if>
  82. update_time_ = NOW()
  83. </set> WHERE id_ = #{id} and tenant_id_ = #{tenantId}
  84. </update>
  85. <update id="autoAffirmReceive">
  86. UPDATE student_payment_order SET receive_status_ = #{status},update_time_ = NOW() WHERE FIND_IN_SET(order_no_,#{orderNo})
  87. </update>
  88. <!-- 根据主键删除一条记录 -->
  89. <delete id="delete" >
  90. DELETE FROM student_goods_sell WHERE id_ = #{id}
  91. </delete>
  92. <!-- 分页查询 -->
  93. <select id="queryPage" resultMap="StudentGoodsSell" parameterType="map">
  94. SELECT * FROM student_goods_sell where tenant_id_ = #{tenantId} ORDER BY id_ <include refid="global.limit"/>
  95. </select>
  96. <!-- 查询当前表的总记录数 -->
  97. <select id="queryCount" resultType="int">
  98. SELECT COUNT(*) FROM student_goods_sell where tenant_id_ = #{tenantId}
  99. </select>
  100. <select id="countStudentGoodsOrders" resultType="java.lang.Integer">
  101. SELECT COUNT(spo.id_) FROM student_payment_order spo
  102. LEFT JOIN student_goods_sell sgs ON spo.order_no_ = sgs.order_no_
  103. LEFT JOIN sys_user su ON sgs.user_id_ = su.id_
  104. <include refid="queryStudentGoodsOrdersSql"/>
  105. </select>
  106. <resultMap type="com.ym.mec.biz.dal.dto.StudentGoodsSellDto" id="StudentGoodsSellDto" extends="com.ym.mec.biz.dal.dao.StudentPaymentOrderDao.StudentPaymentOrder">
  107. <result column="goods_json_" property="goodsJson" />
  108. <result column="goods_type_" property="goodsType" />
  109. <result column="total_amount_" property="totalAmount" />
  110. <result column="market_amount_" property="marketAmount" />
  111. <result column="username_" property="userName" />
  112. <result column="author_user_" property="authorUser" />
  113. </resultMap>
  114. <sql id="queryStudentGoodsOrdersSql">
  115. <where>
  116. sgs.tenant_id_ = #{tenantId}
  117. <choose>
  118. <when test="goodsType != null and goodsType =='MALL'">
  119. and sgs.goods_type_ = 'MALL'
  120. </when>
  121. <otherwise>
  122. and sgs.goods_type_ is null
  123. </otherwise>
  124. </choose>
  125. <if test="teacherId != null">
  126. AND sgs.teacher_id_ = #{teacherId}
  127. </if>
  128. <if test="studentId != null">
  129. AND sgs.user_id_ = #{studentId}
  130. </if>
  131. <if test="status != null">
  132. AND spo.status_ = #{status}
  133. </if>
  134. <if test="receiveStatus != null and receiveStatus != ''">
  135. AND spo.receive_status_ = #{receiveStatus}
  136. </if>
  137. <if test="search != null and search != ''">
  138. AND (su.username_ LIKE CONCAT('%',#{search},'%') OR su.phone_ LIKE CONCAT('%',#{search},'%'))
  139. </if>
  140. </where>
  141. </sql>
  142. <select id="queryStudentGoodsOrders" resultMap="StudentGoodsSellDto">
  143. SELECT spo.*,sgs.goods_json_,sgs.total_amount_,sgs.market_amount_,su.username_,sgs.author_user_,sgs.goods_type_
  144. FROM student_payment_order spo
  145. LEFT JOIN student_goods_sell sgs ON spo.order_no_ = sgs.order_no_
  146. LEFT JOIN sys_user su ON sgs.user_id_ = su.id_
  147. <include refid="queryStudentGoodsOrdersSql"/>
  148. ORDER BY spo.create_time_ DESC
  149. <include refid="global.limit"/>
  150. </select>
  151. <select id="findByOrderNo" resultMap="StudentGoodsSell">
  152. SELECT * FROM student_goods_sell WHERE order_no_ = #{orderNo} LIMIT 1
  153. </select>
  154. <select id="getStudentGoodsSellDto" resultMap="StudentGoodsSellDto">
  155. SELECT spo.*,sgs.goods_json_,sgs.total_amount_,sgs.market_amount_ FROM student_payment_order spo
  156. LEFT JOIN student_goods_sell sgs ON spo.order_no_ = sgs.order_no_
  157. WHERE spo.order_no_ = #{orderNo} LIMIT 1
  158. </select>
  159. <select id="queryNoAffirmOrderNo" resultType="java.lang.String">
  160. SELECT GROUP_CONCAT(DISTINCT so.order_no_) FROM sell_order so
  161. LEFT JOIN student_payment_order spo ON spo.order_no_ = so.order_no_
  162. WHERE spo.status_ = 'SUCCESS' AND spo.receive_status_ = 'NO_RECEIVE' and spo.tenant_id_ = #{tenantId}
  163. <if test="autoAffirmReceiveTime != null and autoAffirmReceiveTime != ''">
  164. AND TIMESTAMPDIFF(DAY,spo.pay_time_,NOW()) >= #{autoAffirmReceiveTime}
  165. </if>
  166. </select>
  167. <resultMap type="com.ym.mec.biz.dal.dto.StudentPaymentOrderDto" id="StudentPaymentOrderDto" extends="com.ym.mec.biz.dal.dao.StudentPaymentOrderDao.StudentPaymentOrder">
  168. <result column="goods_image_" property="image" />
  169. <result column="goods_name_" property="goodsName" />
  170. <result column="goods_num_" property="goodsNum" />
  171. <result column="goods_amount_" property="goodsAmount" />
  172. </resultMap>
  173. <sql id="queryStudentPaymentOrdersSql">
  174. <where>
  175. spo.type_ IN ('GOODS_SELL','APPLY','SUBJECT_CHANGE') AND so.id_ IS NOT NULL and spo.tenant_id_ = #{tenantId}
  176. <if test="status != null">
  177. AND spo.status_ = #{status}
  178. </if>
  179. <if test="receiveStatus != null and receiveStatus != ''">
  180. AND spo.receive_status_ = #{receiveStatus}
  181. </if>
  182. <if test="studentId != null">
  183. AND spo.user_id_ = #{studentId}
  184. </if>
  185. </where>
  186. </sql>
  187. <select id="queryStudentPaymentOrders" resultMap="StudentPaymentOrderDto">
  188. SELECT spo.*,g.image_ goods_image_,g.name_ goods_name_,so.num_ goods_num_,so.expect_amount_ goods_amount_
  189. FROM student_payment_order spo
  190. LEFT JOIN sell_order so ON so.order_no_ = spo.order_no_
  191. LEFT JOIN goods g ON g.id_ = so.goods_id_
  192. <include refid="queryStudentPaymentOrdersSql"/>
  193. ORDER BY spo.pay_time_ DESC
  194. <include refid="global.limit"/>
  195. </select>
  196. <select id="countStudentPaymentOrders" resultType="java.lang.Integer">
  197. SELECT COUNT(DISTINCT spo.id_)
  198. FROM student_payment_order spo
  199. LEFT JOIN sell_order so ON so.order_no_ = spo.order_no_
  200. <include refid="queryStudentPaymentOrdersSql"/>
  201. </select>
  202. </mapper>