TOrderMidMapper.xml 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410
  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.goafanti.common.dao.TOrderMidMapper">
  4. <resultMap id="BaseResultMap" type="com.goafanti.common.model.TOrderMid">
  5. <id column="id" jdbcType="INTEGER" property="id" />
  6. <result column="order_no" jdbcType="VARCHAR" property="orderNo" />
  7. <result column="salesman_id" jdbcType="VARCHAR" property="salesmanId" />
  8. <result column="finance_id" jdbcType="VARCHAR" property="financeId" />
  9. <result column="salesman_name" jdbcType="VARCHAR" property="salesmanName" />
  10. <result column="finance_name" jdbcType="VARCHAR" property="financeName" />
  11. <result column="final_receivables" jdbcType="DECIMAL" property="finalReceivables" />
  12. <result column="final_Receivables_time" jdbcType="TIMESTAMP" property="finalReceivablesTime" />
  13. <result column="invoice_amount" jdbcType="DECIMAL" property="invoiceAmount" />
  14. <result column="create_time" jdbcType="TIMESTAMP" property="createTime" />
  15. <result column="buyer_name" jdbcType="VARCHAR" property="buyerName" />
  16. <result column="order_receivables" jdbcType="DECIMAL" property="orderReceivables" />
  17. <result column="order_arrears" jdbcType="DECIMAL" property="orderArrears" />
  18. <result column="payment_amount" jdbcType="DECIMAL" property="paymentAmount" />
  19. <result column="cost_amount" jdbcType="DECIMAL" property="costAmount" />
  20. <result column="dep_name" jdbcType="VARCHAR" property="depName" />
  21. <result column="province_name" jdbcType="VARCHAR" property="provinceName" />
  22. <result column="legal_affairs" jdbcType="INTEGER" property="legalAffairs" />
  23. <result column="dun_start_time" jdbcType="TIMESTAMP" property="dunStartTime" />
  24. </resultMap>
  25. <sql id="Base_Column_List">
  26. id, order_no, salesman_id, finance_id, salesman_name, finance_name, final_receivables,
  27. final_Receivables_time, invoice_amount, create_time, buyer_name, order_receivables,
  28. order_arrears, payment_amount, cost_amount, dep_name, province_name, legal_affairs,
  29. dun_start_time
  30. </sql>
  31. <select id="selectByPrimaryKey" parameterType="java.lang.Integer" resultMap="BaseResultMap">
  32. select
  33. <include refid="Base_Column_List" />
  34. from t_order_mid
  35. where id = #{id,jdbcType=INTEGER}
  36. </select>
  37. <delete id="deleteByPrimaryKey" parameterType="java.lang.Integer">
  38. delete from t_order_mid
  39. where id = #{id,jdbcType=INTEGER}
  40. </delete>
  41. <insert id="insert" keyColumn="id" keyProperty="id" parameterType="com.goafanti.common.model.TOrderMid" useGeneratedKeys="true">
  42. insert into t_order_mid (order_no, salesman_id, finance_id,
  43. salesman_name, finance_name, final_receivables,
  44. final_Receivables_time, invoice_amount,
  45. create_time, buyer_name, order_receivables,
  46. order_arrears, payment_amount, cost_amount,
  47. dep_name, province_name, legal_affairs,
  48. dun_start_time)
  49. values (#{orderNo,jdbcType=VARCHAR}, #{salesmanId,jdbcType=VARCHAR}, #{financeId,jdbcType=VARCHAR},
  50. #{salesmanName,jdbcType=VARCHAR}, #{financeName,jdbcType=VARCHAR}, #{finalReceivables,jdbcType=DECIMAL},
  51. #{finalReceivablesTime,jdbcType=TIMESTAMP}, #{invoiceAmount,jdbcType=DECIMAL},
  52. #{createTime,jdbcType=TIMESTAMP}, #{buyerName,jdbcType=VARCHAR}, #{orderReceivables,jdbcType=DECIMAL},
  53. #{orderArrears,jdbcType=DECIMAL}, #{paymentAmount,jdbcType=DECIMAL}, #{costAmount,jdbcType=DECIMAL},
  54. #{depName,jdbcType=VARCHAR}, #{provinceName,jdbcType=VARCHAR}, #{legalAffairs,jdbcType=INTEGER},
  55. #{dunStartTime,jdbcType=TIMESTAMP})
  56. </insert>
  57. <insert id="insertSelective" keyColumn="id" keyProperty="id" parameterType="com.goafanti.common.model.TOrderMid" useGeneratedKeys="true">
  58. insert into t_order_mid
  59. <trim prefix="(" suffix=")" suffixOverrides=",">
  60. <if test="orderNo != null">
  61. order_no,
  62. </if>
  63. <if test="salesmanId != null">
  64. salesman_id,
  65. </if>
  66. <if test="financeId != null">
  67. finance_id,
  68. </if>
  69. <if test="salesmanName != null">
  70. salesman_name,
  71. </if>
  72. <if test="financeName != null">
  73. finance_name,
  74. </if>
  75. <if test="finalReceivables != null">
  76. final_receivables,
  77. </if>
  78. <if test="finalReceivablesTime != null">
  79. final_Receivables_time,
  80. </if>
  81. <if test="invoiceAmount != null">
  82. invoice_amount,
  83. </if>
  84. <if test="createTime != null">
  85. create_time,
  86. </if>
  87. <if test="buyerName != null">
  88. buyer_name,
  89. </if>
  90. <if test="orderReceivables != null">
  91. order_receivables,
  92. </if>
  93. <if test="orderArrears != null">
  94. order_arrears,
  95. </if>
  96. <if test="paymentAmount != null">
  97. payment_amount,
  98. </if>
  99. <if test="costAmount != null">
  100. cost_amount,
  101. </if>
  102. <if test="depName != null">
  103. dep_name,
  104. </if>
  105. <if test="provinceName != null">
  106. province_name,
  107. </if>
  108. <if test="legalAffairs != null">
  109. legal_affairs,
  110. </if>
  111. <if test="dunStartTime != null">
  112. dun_start_time,
  113. </if>
  114. </trim>
  115. <trim prefix="values (" suffix=")" suffixOverrides=",">
  116. <if test="orderNo != null">
  117. #{orderNo,jdbcType=VARCHAR},
  118. </if>
  119. <if test="salesmanId != null">
  120. #{salesmanId,jdbcType=VARCHAR},
  121. </if>
  122. <if test="financeId != null">
  123. #{financeId,jdbcType=VARCHAR},
  124. </if>
  125. <if test="salesmanName != null">
  126. #{salesmanName,jdbcType=VARCHAR},
  127. </if>
  128. <if test="financeName != null">
  129. #{financeName,jdbcType=VARCHAR},
  130. </if>
  131. <if test="finalReceivables != null">
  132. #{finalReceivables,jdbcType=DECIMAL},
  133. </if>
  134. <if test="finalReceivablesTime != null">
  135. #{finalReceivablesTime,jdbcType=TIMESTAMP},
  136. </if>
  137. <if test="invoiceAmount != null">
  138. #{invoiceAmount,jdbcType=DECIMAL},
  139. </if>
  140. <if test="createTime != null">
  141. #{createTime,jdbcType=TIMESTAMP},
  142. </if>
  143. <if test="buyerName != null">
  144. #{buyerName,jdbcType=VARCHAR},
  145. </if>
  146. <if test="orderReceivables != null">
  147. #{orderReceivables,jdbcType=DECIMAL},
  148. </if>
  149. <if test="orderArrears != null">
  150. #{orderArrears,jdbcType=DECIMAL},
  151. </if>
  152. <if test="paymentAmount != null">
  153. #{paymentAmount,jdbcType=DECIMAL},
  154. </if>
  155. <if test="costAmount != null">
  156. #{costAmount,jdbcType=DECIMAL},
  157. </if>
  158. <if test="depName != null">
  159. #{depName,jdbcType=VARCHAR},
  160. </if>
  161. <if test="provinceName != null">
  162. #{provinceName,jdbcType=VARCHAR},
  163. </if>
  164. <if test="legalAffairs != null">
  165. #{legalAffairs,jdbcType=INTEGER},
  166. </if>
  167. <if test="dunStartTime != null">
  168. #{dunStartTime,jdbcType=TIMESTAMP},
  169. </if>
  170. </trim>
  171. </insert>
  172. <update id="updateByPrimaryKeySelective" parameterType="com.goafanti.common.model.TOrderMid">
  173. update t_order_mid
  174. <set>
  175. <if test="orderNo != null">
  176. order_no = #{orderNo,jdbcType=VARCHAR},
  177. </if>
  178. <if test="salesmanId != null">
  179. salesman_id = #{salesmanId,jdbcType=VARCHAR},
  180. </if>
  181. <if test="financeId != null">
  182. finance_id = #{financeId,jdbcType=VARCHAR},
  183. </if>
  184. <if test="salesmanName != null">
  185. salesman_name = #{salesmanName,jdbcType=VARCHAR},
  186. </if>
  187. <if test="financeName != null">
  188. finance_name = #{financeName,jdbcType=VARCHAR},
  189. </if>
  190. <if test="finalReceivables != null">
  191. final_receivables = #{finalReceivables,jdbcType=DECIMAL},
  192. </if>
  193. <if test="finalReceivablesTime != null">
  194. final_Receivables_time = #{finalReceivablesTime,jdbcType=TIMESTAMP},
  195. </if>
  196. <if test="invoiceAmount != null">
  197. invoice_amount = #{invoiceAmount,jdbcType=DECIMAL},
  198. </if>
  199. <if test="createTime != null">
  200. create_time = #{createTime,jdbcType=TIMESTAMP},
  201. </if>
  202. <if test="buyerName != null">
  203. buyer_name = #{buyerName,jdbcType=VARCHAR},
  204. </if>
  205. <if test="orderReceivables != null">
  206. order_receivables = #{orderReceivables,jdbcType=DECIMAL},
  207. </if>
  208. <if test="orderArrears != null">
  209. order_arrears = #{orderArrears,jdbcType=DECIMAL},
  210. </if>
  211. <if test="paymentAmount != null">
  212. payment_amount = #{paymentAmount,jdbcType=DECIMAL},
  213. </if>
  214. <if test="costAmount != null">
  215. cost_amount = #{costAmount,jdbcType=DECIMAL},
  216. </if>
  217. <if test="depName != null">
  218. dep_name = #{depName,jdbcType=VARCHAR},
  219. </if>
  220. <if test="provinceName != null">
  221. province_name = #{provinceName,jdbcType=VARCHAR},
  222. </if>
  223. <if test="legalAffairs != null">
  224. legal_affairs = #{legalAffairs,jdbcType=INTEGER},
  225. </if>
  226. <if test="dunStartTime != null">
  227. dun_start_time = #{dunStartTime,jdbcType=TIMESTAMP},
  228. </if>
  229. </set>
  230. where id = #{id,jdbcType=INTEGER}
  231. </update>
  232. <update id="updateByPrimaryKey" parameterType="com.goafanti.common.model.TOrderMid">
  233. update t_order_mid
  234. set order_no = #{orderNo,jdbcType=VARCHAR},
  235. salesman_id = #{salesmanId,jdbcType=VARCHAR},
  236. finance_id = #{financeId,jdbcType=VARCHAR},
  237. salesman_name = #{salesmanName,jdbcType=VARCHAR},
  238. finance_name = #{financeName,jdbcType=VARCHAR},
  239. final_receivables = #{finalReceivables,jdbcType=DECIMAL},
  240. final_Receivables_time = #{finalReceivablesTime,jdbcType=TIMESTAMP},
  241. invoice_amount = #{invoiceAmount,jdbcType=DECIMAL},
  242. create_time = #{createTime,jdbcType=TIMESTAMP},
  243. buyer_name = #{buyerName,jdbcType=VARCHAR},
  244. order_receivables = #{orderReceivables,jdbcType=DECIMAL},
  245. order_arrears = #{orderArrears,jdbcType=DECIMAL},
  246. payment_amount = #{paymentAmount,jdbcType=DECIMAL},
  247. cost_amount = #{costAmount,jdbcType=DECIMAL},
  248. dep_name = #{depName,jdbcType=VARCHAR},
  249. province_name = #{provinceName,jdbcType=VARCHAR},
  250. legal_affairs = #{legalAffairs,jdbcType=INTEGER},
  251. dun_start_time = #{dunStartTime,jdbcType=TIMESTAMP}
  252. where id = #{id,jdbcType=INTEGER}
  253. </update>
  254. <select id="selectByOrderNo" resultMap="BaseResultMap">
  255. select
  256. <include refid="Base_Column_List" />
  257. from t_order_mid
  258. where order_no = #{id,jdbcType=INTEGER}
  259. </select>
  260. <update id="updateSalesmanId">
  261. update t_order_mid a ,admin b set a.salesman_id=#{transferId},a.salesman_name=b.name
  262. where b.id=#{transferId} and a.salesman_id=#{aid}
  263. </update>
  264. <update id="updateFinanceId">
  265. update t_order_new a ,t_order_mid b,admin c set b.finance_id=#{financeId},b.finance_name=c.name
  266. where a.order_dep=#{id} and a.order_no=b.order_no and c.id= #{financeId}
  267. </update>
  268. <update id="updatefinalReceivables">
  269. update t_order_mid set final_receivables= #{amount},`final_Receivables_time`= #{receivablesTime},
  270. order_arrears=if(order_arrears- #{amount} &lt; 0,0,order_arrears- #{amount})
  271. where order_no= #{orderNo}
  272. </update>
  273. <update id="updateInvoice">
  274. update t_order_mid m,(select order_no,sum(amount)amount from t_order_invoice where status=2 group by order_no)b
  275. set m.invoice_amount=b.amount where m.order_no= #{orderNo} and m.order_no=b.order_no
  276. </update>
  277. <update id="addOrderReceivables">
  278. update t_order_mid set order_receivables=order_receivables+#{money},
  279. order_arrears=order_arrears+#{money}
  280. where order_no=#{orderNo}
  281. </update>
  282. <select id="selectDepNameByDepid" resultType="java.lang.String">
  283. select name from department where id= #{orderDep}
  284. </select>
  285. <update id="updateCostAmount">
  286. update t_order_task a ,t_order_mid b
  287. <set>
  288. <if test="cost !=null">
  289. b.cost_amount= #{cost},
  290. </if>
  291. <if test="payment !=null">
  292. b.payment_amount= #{payment},
  293. </if>
  294. </set>
  295. where a.order_no=b.order_no and a.id= #{tid}
  296. </update>
  297. <update id="updateAddCostAmount">
  298. update t_order_task a ,t_order_mid b
  299. <set>
  300. <if test="cost !=null">
  301. b.cost_amount= b.cost_amount+#{cost},
  302. </if>
  303. </set>
  304. where a.order_no=b.order_no and a.id= #{tid}
  305. </update>
  306. <update id="updateByOrderNo">
  307. update t_order_mid
  308. <set>
  309. <if test="salesmanId != null">
  310. salesman_id = #{salesmanId,jdbcType=VARCHAR},
  311. </if>
  312. <if test="financeId != null">
  313. finance_id = #{financeId,jdbcType=VARCHAR},
  314. </if>
  315. <if test="salesmanName != null">
  316. salesman_name = #{salesmanName,jdbcType=VARCHAR},
  317. </if>
  318. <if test="financeName != null">
  319. finance_name = #{financeName,jdbcType=VARCHAR},
  320. </if>
  321. <if test="finalReceivables != null">
  322. final_receivables = #{finalReceivables,jdbcType=DECIMAL},
  323. </if>
  324. <if test="finalReceivablesTime != null">
  325. final_Receivables_time = #{finalReceivablesTime,jdbcType=TIMESTAMP},
  326. </if>
  327. <if test="invoiceAmount != null">
  328. invoice_amount = #{invoiceAmount,jdbcType=DECIMAL},
  329. </if>
  330. <if test="createTime != null">
  331. create_time = #{createTime,jdbcType=TIMESTAMP},
  332. </if>
  333. <if test="buyerName != null">
  334. buyer_name = #{buyerName,jdbcType=VARCHAR},
  335. </if>
  336. <if test="orderReceivables != null">
  337. order_receivables = #{orderReceivables,jdbcType=DECIMAL},
  338. </if>
  339. <if test="orderArrears != null">
  340. order_arrears = #{orderArrears,jdbcType=DECIMAL},
  341. </if>
  342. <if test="paymentAmount != null">
  343. payment_amount = #{paymentAmount,jdbcType=DECIMAL},
  344. </if>
  345. <if test="costAmount != null">
  346. cost_amount = #{costAmount,jdbcType=DECIMAL},
  347. </if>
  348. <if test="depName != null">
  349. dep_name = #{depName,jdbcType=VARCHAR},
  350. </if>
  351. <if test="provinceName != null">
  352. province_name = #{provinceName,jdbcType=VARCHAR},
  353. </if>
  354. <if test="legalAffairs != null">
  355. legal_affairs = #{legalAffairs,jdbcType=INTEGER},
  356. </if>
  357. </set>
  358. where order_no = #{orderNo,jdbcType=VARCHAR}
  359. </update>
  360. <select id="legalAffairsOrderList" resultType="com.goafanti.order.bo.OutOrderLegalAffairsListBo">
  361. select a.order_no orderNo,a.contract_no contractNo,b.buyer_name buyerName,b.salesman_name salesmanName,b.dep_name depName,
  362. a.total_amount totalAmount ,a.settlement_amount settlementAmount ,b.order_receivables orderReceivables,
  363. b.order_arrears orderArrears,b.dun_start_time dunStartTime,date_format(b.dun_start_time,'%Y-%m-%d %H:%i:%S')dunStartTimes
  364. from t_order_new a left join t_order_mid b on a.order_no =b.order_no
  365. where b.order_receivables >0
  366. <if test="userName != null">
  367. and b.buyer_name like concat('%',#{userName},'%')
  368. </if>
  369. <if test="legalAffairs != null">
  370. and b.legal_affairs = #{legalAffairs}
  371. </if>
  372. <if test="contractNo != null">
  373. and a.contract_no like concat('%',#{contractNo},'%')
  374. </if>
  375. <if test="aid != null">
  376. and b.salesman_id = #{aid}
  377. </if>
  378. <if test="depId != null">
  379. and a.order_dep = #{depId}
  380. </if>
  381. order by b.dun_start_time desc
  382. <if test="page_sql != null">
  383. ${page_sql}
  384. </if>
  385. </select>
  386. <select id="legalAffairsOrderCount" resultType="integer">
  387. select count(*)
  388. from t_order_new a left join t_order_mid b on a.order_no =b.order_no
  389. where b.order_receivables >0
  390. <if test="userName != null">
  391. and b.buyer_name like concat('%',#{userName},'%')
  392. </if>
  393. <if test="legalAffairs != null">
  394. and b.legal_affairs = #{legalAffairs}
  395. </if>
  396. <if test="contractNo != null">
  397. and a.contract_no like concat('%',#{contractNo},'%')
  398. </if>
  399. <if test="aid != null">
  400. and b.salesman_id = #{aid}
  401. </if>
  402. <if test="depId != null">
  403. and a.order_dep = #{depId}
  404. </if>
  405. </select>
  406. </mapper>