SellOrderMapper.xml 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293
  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.ym.mec.biz.dal.dao.SellOrderDao">
  4. <resultMap id="SellOrder" type="com.ym.mec.biz.dal.entity.SellOrder">
  5. <!--@mbg.generated-->
  6. <!--@Table sell_order-->
  7. <id column="id_" property="id"/>
  8. <result column="organ_id_" property="organId"/>
  9. <result column="cooperation_organ_id_" property="cooperationOrganId"/>
  10. <result column="school_name_" property="schoolName"/>
  11. <result column="trans_no_" property="transNo"/>
  12. <result column="order_no_" property="orderNo"/>
  13. <result column="order_id_" property="orderId"/>
  14. <result column="expect_amount_" property="expectAmount"/>
  15. <result column="actual_amount_" property="actualAmount"/>
  16. <result column="balance_amount_" property="balanceAmount"/>
  17. <result column="type_" property="type"/>
  18. <result column="goods_id_" property="goodsId"/>
  19. <result column="goods_name_" property="goodsName"/>
  20. <result column="sell_cost_" property="sellCost"/>
  21. <result column="sell_cost2_" property="sellCost2"/>
  22. <result column="num_" property="num"/>
  23. <result column="user_id_" property="userId"/>
  24. <result column="user_name_" property="userName"/>
  25. <result column="phone_" property="phone"/>
  26. <result column="organ_name_" property="organName"/>
  27. <result column="user_id_" property="userId"/>
  28. <result column="payment_channel_" property="paymentChannel"/>
  29. <result column="mer_no_" property="merNo"/>
  30. <result column="sell_time_" property="sellTime"/>
  31. <result column="create_ime_" property="createIme"/>
  32. <result column="update_time_" property="updateTime"/>
  33. </resultMap>
  34. <sql id="Base_Column_List">
  35. <!--@mbg.generated-->
  36. id_, organ_id_, cooperation_organ_id_, trans_no_,order_id_, order_no_, expect_amount_, actual_amount_,
  37. balance_amount_, sell_cost_, sell_cost2_, type_, goods_id_,goods_name_, num_, user_id_, payment_channel_,
  38. mer_no_, sell_time_, create_ime_, update_time_
  39. </sql>
  40. <select id="get" parameterType="java.lang.Integer" resultMap="SellOrder">
  41. <!--@mbg.generated-->
  42. select
  43. <include refid="Base_Column_List"/>
  44. from sell_order
  45. where id_ = #{id}
  46. </select>
  47. <delete id="delete" parameterType="java.lang.Integer">
  48. <!--@mbg.generated-->
  49. delete from sell_order
  50. where id_ = #{id}
  51. </delete>
  52. <insert id="insert" keyColumn="id_" keyProperty="id" parameterType="com.ym.mec.biz.dal.entity.SellOrder"
  53. useGeneratedKeys="true">
  54. <!--@mbg.generated-->
  55. insert into sell_order (organ_id_, cooperation_organ_id_, trans_no_,order_id_, order_no_, expect_amount_, actual_amount_,
  56. balance_amount_, type_, goods_id_,goods_name_, sell_cost_, sell_cost2_, num_, user_id_, payment_channel_,
  57. mer_no_, sell_time_, create_ime_, update_time_)
  58. values (#{organId}, #{cooperationOrganId}, #{transNo}, #{orderNo},#{orderId}, #{expectAmount}, #{actualAmount},
  59. #{balanceAmount}, #{type}, #{goodsId}, #{goodsName}, #{sellCost}, #{sellCost2}, #{num}, #{userId},
  60. #{paymentChannel},
  61. #{merNo}, #{sellTime}, #{createIme}, #{updateTime})
  62. </insert>
  63. <update id="update" parameterType="com.ym.mec.biz.dal.entity.SellOrder">
  64. <!--@mbg.generated-->
  65. update sell_order
  66. <set>
  67. <if test="organId != null">
  68. organ_id_ = #{organId},
  69. </if>
  70. <if test="cooperationOrganId != null">
  71. cooperation_organ_id_ = #{cooperationOrganId},
  72. </if>
  73. <if test="transNo != null">
  74. trans_no_ = #{transNo},
  75. </if>
  76. <if test="orderId != null">
  77. order_id_ = #{orderId},
  78. </if>
  79. <if test="orderNo != null">
  80. order_no_ = #{orderNo},
  81. </if>
  82. <if test="expectAmount != null">
  83. expect_amount_ = #{expectAmount},
  84. </if>
  85. <if test="actualAmount != null">
  86. actual_amount_ = #{actualAmount},
  87. </if>
  88. <if test="balanceAmount != null">
  89. balance_amount_ = #{balanceAmount},
  90. </if>
  91. <if test="type != null">
  92. type_ = #{type},
  93. </if>
  94. <if test="goodsId != null">
  95. goods_id_ = #{goodsId},
  96. </if>
  97. <if test="goodsName != null">
  98. goods_name_ = #{goodsName},
  99. </if>
  100. <if test="sellCost != null">
  101. sell_cost_ = #{sellCost},
  102. </if>
  103. <if test="sellCost2 != null">
  104. sell_cost2_ = #{sellCost2},
  105. </if>
  106. <if test="num != null">
  107. num_ = #{num},
  108. </if>
  109. <if test="userId != null">
  110. user_id_ = #{userId},
  111. </if>
  112. <if test="paymentChannel != null">
  113. payment_channel_ = #{paymentChannel},
  114. </if>
  115. <if test="merNo != null">
  116. mer_no_ = #{merNo},
  117. </if>
  118. <if test="sellTime != null">
  119. sell_time_ = #{sellTime},
  120. </if>
  121. <if test="createIme != null">
  122. create_ime_ = #{createIme},
  123. </if>
  124. <if test="updateTime != null">
  125. update_time_ = #{updateTime},
  126. </if>
  127. </set>
  128. where id_ = #{id}
  129. </update>
  130. <insert id="batchInsert" parameterType="java.util.List" useGeneratedKeys="true" keyProperty="id_">
  131. insert into sell_order (organ_id_, cooperation_organ_id_, trans_no_,order_id_, order_no_, expect_amount_, actual_amount_,
  132. balance_amount_, type_, goods_id_,goods_name_, sell_cost_, sell_cost2_, num_, user_id_, payment_channel_,
  133. mer_no_, sell_time_, create_ime_, update_time_)
  134. VALUE
  135. <foreach collection="sellOrders" separator="," item="sellOrder">
  136. (#{sellOrder.organId},#{sellOrder.cooperationOrganId},#{sellOrder.transNo},#{sellOrder.orderId},#{sellOrder.orderNo},
  137. #{sellOrder.expectAmount},#{sellOrder.actualAmount},#{sellOrder.balanceAmount},#{sellOrder.type},#{sellOrder.goodsId},
  138. #{sellOrder.goodsName},#{sellOrder.sellCost},#{sellOrder.sellCost2},#{sellOrder.num},#{sellOrder.userId},
  139. #{sellOrder.paymentChannel},#{sellOrder.merNo},#{sellOrder.sellTime},#{sellOrder.createIme},#{sellOrder.updateTime})
  140. </foreach>
  141. </insert>
  142. <!-- 分页查询 -->
  143. <select id="queryPage" resultMap="SellOrder" parameterType="map">
  144. SELECT so.*,su.username_ user_name_,su.phone_,o.name_ organ_name_,co.name_ school_name_ FROM sell_order so
  145. LEFT JOIN sys_user su ON so.user_id_ = su.id_
  146. LEFT JOIN organization o ON o.id_ = so.organ_id_
  147. LEFT JOIN cooperation_organ co ON co.id_= so.cooperation_organ_id_
  148. <include refid="queryPageSql"/>
  149. ORDER BY so.sell_time_ DESC
  150. <include refid="global.limit"/>
  151. </select>
  152. <!-- 查询当前表的总记录数 -->
  153. <select id="queryCount" resultType="int">
  154. SELECT COUNT(*) FROM sell_order so
  155. <include refid="queryPageSql"/>
  156. </select>
  157. <sql id="queryPageSql">
  158. <where>
  159. <if test="search != null and search != ''">
  160. AND (so.order_no_ = #{search} OR so.trans_no_ = #{search})
  161. </if>
  162. <if test="organIdList != null and organIdList != ''">
  163. AND FIND_IN_SET(so.organ_id_,#{organIdList})
  164. </if>
  165. <if test="goodsName != null and goodsName != ''">
  166. AND so.goods_name_ = #{goodsName}
  167. </if>
  168. <if test="cooperationOrganId != null">
  169. AND so.cooperation_organ_id_ = #{cooperationOrganId}
  170. </if>
  171. <if test="type != null">
  172. AND so.type_ = #{type}
  173. </if>
  174. <if test="startTime != null">
  175. AND so.sell_time_ >= #{startTime}
  176. </if>
  177. <if test="endTime != null">
  178. AND so.sell_time_ &lt;= #{endTime}
  179. </if>
  180. </where>
  181. </sql>
  182. <!-- 获取分部学校的收入支出(乐团订单) -->
  183. <select id="getMusicGroupMonthReport" resultMap="com.ym.mec.biz.dal.dao.OperatingReportDao.OperatingReport"><![CDATA[
  184. SELECT spo.organ_id_,
  185. co.id_ cooperation_organ_id_,
  186. SUM(spo.actual_amount_) income_total_,
  187. SUM(so.actual_amount_) sell_amount_,
  188. SUM(so.sell_cost_) sellCost
  189. FROM student_payment_order spo
  190. LEFT JOIN sell_order so on so.order_id_ = spo.id_
  191. LEFT JOIN music_group mg ON mg.id_ = spo.music_group_id_
  192. LEFT JOIN cooperation_organ co ON co.id_ = mg.cooperation_organ_id_
  193. WHERE spo.status_ = 'SUCCESS'
  194. AND spo.group_type_ = 'MUSIC'
  195. AND spo.create_time_ >= #{startTime}
  196. AND spo.create_time_ <= #{endTime}
  197. GROUP BY spo.organ_id_, co.id_
  198. ]]></select>
  199. <!-- 获取分部学校的收入支出(VIP,网管课) -->
  200. <select id="getMusicVipPracticeMonthReport" resultMap="com.ym.mec.biz.dal.dao.OperatingReportDao.OperatingReport"><![CDATA[
  201. SELECT spo.organ_id_,
  202. co.id_ cooperation_organ_id_,
  203. SUM(spo.actual_amount_) income_total_
  204. FROM student_payment_order spo
  205. LEFT JOIN
  206. (SELECT MIN(music_group_id_) music_group_id_, user_id_
  207. FROM student_registration
  208. WHERE music_group_status_ = 'NORMAL'
  209. GROUP BY user_id_) sr
  210. ON sr.user_id_ = spo.user_id_
  211. LEFT JOIN music_group mg ON mg.id_ = sr.music_group_id_
  212. LEFT JOIN cooperation_organ co ON co.id_ = mg.cooperation_organ_id_
  213. WHERE spo.status_ = 'SUCCESS'
  214. AND spo.group_type_ IN ('VIP', 'PRACTICE')
  215. AND spo.create_time_ >= #{startTime}
  216. AND spo.create_time_ <= #{endTime}
  217. GROUP BY spo.organ_id_, co.id_
  218. ]]></select>
  219. <!-- 获取分部学校的收入支出(外部添加订单) -->
  220. <select id="getOutOrderMonthReport" resultMap="com.ym.mec.biz.dal.dao.OperatingReportDao.OperatingReport"><![CDATA[
  221. SELECT spo.organ_id_,
  222. co.id_ cooperation_organ_id_,
  223. SUM(spo.actual_amount_) income_total_,
  224. SUM(so.actual_amount_) sell_amount_,
  225. SUM(so.sell_cost_) sellCost
  226. FROM student_payment_order spo
  227. LEFT JOIN sell_order so on so.order_id_ = spo.id_
  228. LEFT JOIN cooperation_organ co ON co.id_ = spo.music_group_id_
  229. WHERE spo.status_ = 'SUCCESS'
  230. AND spo.group_type_ = 'OUTORDER'
  231. AND spo.create_time_ >= #{startTime}
  232. AND spo.create_time_ <= #{endTime}
  233. GROUP BY spo.organ_id_, co.id_
  234. ]]></select>
  235. <!-- 获取分部学校的收入(充值) -->
  236. <select id="getRechargeMonthReport" resultMap="com.ym.mec.biz.dal.dao.OperatingReportDao.OperatingReport"><![CDATA[
  237. SELECT spo.organ_id_,
  238. co.id_ cooperation_organ_id_,
  239. SUM(spo.actual_amount_) income_total_
  240. FROM student_payment_order spo
  241. LEFT JOIN sporadic_charge_info sci ON sci.id_ = spo.music_group_id_
  242. LEFT JOIN music_group mg ON mg.id_ = sci.music_group_id_
  243. LEFT JOIN cooperation_organ co ON co.id_ = mg.cooperation_organ_id_
  244. WHERE spo.status_ = 'SUCCESS'
  245. AND spo.group_type_ = 'SPORADIC'
  246. AND sci.charge_type_ = '9'
  247. AND spo.create_time_ >= #{startTime}
  248. AND spo.create_time_ <= #{endTime}
  249. GROUP BY spo.organ_id_, co.id_
  250. ]]></select>
  251. <!-- 获取分部学校的收入(零星支付) -->
  252. <select id="getSporadicMonthReport" resultMap="com.ym.mec.biz.dal.dao.OperatingReportDao.OperatingReport"><![CDATA[
  253. SELECT spo.organ_id_,
  254. co.id_ cooperation_organ_id_,
  255. SUM(spo.actual_amount_) income_total_
  256. FROM student_payment_order spo
  257. LEFT JOIN sporadic_charge_info sci ON sci.id_ = spo.music_group_id_
  258. LEFT JOIN music_group mg ON mg.id_ = sci.music_group_id_
  259. LEFT JOIN cooperation_organ co ON co.id_ = mg.cooperation_organ_id_
  260. WHERE spo.status_ = 'SUCCESS'
  261. AND spo.group_type_ = 'SPORADIC'
  262. AND sci.charge_type_ != '9'
  263. AND spo.create_time_ >= #{startTime}
  264. AND spo.create_time_ <= #{endTime}
  265. GROUP BY spo.organ_id_, co.id_
  266. ]]></select>
  267. <!-- 获取分部学校的收入支出(维修、商品销售订单) -->
  268. <select id="getRepairGoodsSellGroupMonthReport" resultMap="com.ym.mec.biz.dal.dao.OperatingReportDao.OperatingReport"><![CDATA[
  269. SELECT spo.organ_id_,
  270. SUM(spo.actual_amount_) income_total_,
  271. SUM(so.actual_amount_) sell_amount_,
  272. SUM(so.sell_cost_) sellCost
  273. FROM student_payment_order spo
  274. LEFT JOIN sell_order so on so.order_id_ = spo.id_
  275. WHERE spo.status_ = 'SUCCESS'
  276. AND spo.group_type_ IN ('REPAIR','GOODS_SELL')
  277. AND spo.create_time_ >= #{startTime}
  278. AND spo.create_time_ <= #{endTime}
  279. GROUP BY spo.organ_id_
  280. ]]></select>
  281. </mapper>