TemporaryReceivablesMapper.xml 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394
  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.TemporaryReceivablesMapper">
  4. <resultMap id="BaseResultMap" type="com.goafanti.common.model.TemporaryReceivables">
  5. <id column="id" jdbcType="INTEGER" property="id" />
  6. <result column="order_no" jdbcType="VARCHAR" property="orderNo" />
  7. <result column="corporate_name" jdbcType="VARCHAR" property="corporateName" />
  8. <result column="amount" jdbcType="DECIMAL" property="amount" />
  9. <result column="receivables_time" jdbcType="TIMESTAMP" property="receivablesTime" />
  10. <result column="aid" jdbcType="VARCHAR" property="aid" />
  11. <result column="remarks" jdbcType="VARCHAR" property="remarks" />
  12. <result column="status" jdbcType="INTEGER" property="status" />
  13. <result column="create_time" jdbcType="TIMESTAMP" property="createTime" />
  14. <result column="financial_pay_no" jdbcType="VARCHAR" property="financialPayNo" />
  15. <result column="merge_Status" jdbcType="INTEGER" property="mergeStatus" />
  16. </resultMap>
  17. <sql id="Base_Column_List">
  18. id, order_no, corporate_name, amount, receivables_time, aid, remarks, `status`, create_time,
  19. financial_pay_no, merge_Status
  20. </sql>
  21. <select id="selectByPrimaryKey" parameterType="java.lang.Integer" resultMap="BaseResultMap">
  22. select
  23. <include refid="Base_Column_List" />
  24. from temporary_receivables
  25. where id = #{id,jdbcType=INTEGER}
  26. </select>
  27. <delete id="deleteByPrimaryKey" parameterType="java.lang.Integer">
  28. delete from temporary_receivables
  29. where id = #{id,jdbcType=INTEGER}
  30. </delete>
  31. <insert id="insert" keyColumn="id" keyProperty="id" parameterType="com.goafanti.common.model.TemporaryReceivables" useGeneratedKeys="true">
  32. insert into temporary_receivables (order_no, corporate_name, amount,
  33. receivables_time, aid, remarks,
  34. `status`, create_time, financial_pay_no,
  35. merge_Status)
  36. values (#{orderNo,jdbcType=VARCHAR}, #{corporateName,jdbcType=VARCHAR}, #{amount,jdbcType=DECIMAL},
  37. #{receivablesTime,jdbcType=TIMESTAMP}, #{aid,jdbcType=VARCHAR}, #{remarks,jdbcType=VARCHAR},
  38. #{status,jdbcType=INTEGER}, #{createTime,jdbcType=TIMESTAMP}, #{financialPayNo,jdbcType=VARCHAR},
  39. #{mergeStatus,jdbcType=INTEGER})
  40. </insert>
  41. <insert id="insertSelective" keyColumn="id" keyProperty="id" parameterType="com.goafanti.common.model.TemporaryReceivables" useGeneratedKeys="true">
  42. insert into temporary_receivables
  43. <trim prefix="(" suffix=")" suffixOverrides=",">
  44. <if test="orderNo != null">
  45. order_no,
  46. </if>
  47. <if test="corporateName != null">
  48. corporate_name,
  49. </if>
  50. <if test="amount != null">
  51. amount,
  52. </if>
  53. <if test="receivablesTime != null">
  54. receivables_time,
  55. </if>
  56. <if test="aid != null">
  57. aid,
  58. </if>
  59. <if test="remarks != null">
  60. remarks,
  61. </if>
  62. <if test="status != null">
  63. `status`,
  64. </if>
  65. <if test="createTime != null">
  66. create_time,
  67. </if>
  68. <if test="financialPayNo != null">
  69. financial_pay_no,
  70. </if>
  71. <if test="mergeStatus != null">
  72. merge_Status,
  73. </if>
  74. </trim>
  75. <trim prefix="values (" suffix=")" suffixOverrides=",">
  76. <if test="orderNo != null">
  77. #{orderNo,jdbcType=VARCHAR},
  78. </if>
  79. <if test="corporateName != null">
  80. #{corporateName,jdbcType=VARCHAR},
  81. </if>
  82. <if test="amount != null">
  83. #{amount,jdbcType=DECIMAL},
  84. </if>
  85. <if test="receivablesTime != null">
  86. #{receivablesTime,jdbcType=TIMESTAMP},
  87. </if>
  88. <if test="aid != null">
  89. #{aid,jdbcType=VARCHAR},
  90. </if>
  91. <if test="remarks != null">
  92. #{remarks,jdbcType=VARCHAR},
  93. </if>
  94. <if test="status != null">
  95. #{status,jdbcType=INTEGER},
  96. </if>
  97. <if test="createTime != null">
  98. #{createTime,jdbcType=TIMESTAMP},
  99. </if>
  100. <if test="financialPayNo != null">
  101. #{financialPayNo,jdbcType=VARCHAR},
  102. </if>
  103. <if test="mergeStatus != null">
  104. #{mergeStatus,jdbcType=INTEGER},
  105. </if>
  106. </trim>
  107. </insert>
  108. <update id="updateByPrimaryKeySelective" parameterType="com.goafanti.common.model.TemporaryReceivables">
  109. update temporary_receivables
  110. <set>
  111. <if test="orderNo != null">
  112. order_no = #{orderNo,jdbcType=VARCHAR},
  113. </if>
  114. <if test="corporateName != null">
  115. corporate_name = #{corporateName,jdbcType=VARCHAR},
  116. </if>
  117. <if test="amount != null">
  118. amount = #{amount,jdbcType=DECIMAL},
  119. </if>
  120. <if test="receivablesTime != null">
  121. receivables_time = #{receivablesTime,jdbcType=TIMESTAMP},
  122. </if>
  123. <if test="aid != null">
  124. aid = #{aid,jdbcType=VARCHAR},
  125. </if>
  126. <if test="remarks != null">
  127. remarks = #{remarks,jdbcType=VARCHAR},
  128. </if>
  129. <if test="status != null">
  130. `status` = #{status,jdbcType=INTEGER},
  131. </if>
  132. <if test="createTime != null">
  133. create_time = #{createTime,jdbcType=TIMESTAMP},
  134. </if>
  135. <if test="financialPayNo != null">
  136. financial_pay_no = #{financialPayNo,jdbcType=VARCHAR},
  137. </if>
  138. <if test="mergeStatus != null">
  139. merge_Status = #{mergeStatus,jdbcType=INTEGER},
  140. </if>
  141. </set>
  142. where id = #{id,jdbcType=INTEGER}
  143. </update>
  144. <update id="updateByPrimaryKey" parameterType="com.goafanti.common.model.TemporaryReceivables">
  145. update temporary_receivables
  146. set order_no = #{orderNo,jdbcType=VARCHAR},
  147. corporate_name = #{corporateName,jdbcType=VARCHAR},
  148. amount = #{amount,jdbcType=DECIMAL},
  149. receivables_time = #{receivablesTime,jdbcType=TIMESTAMP},
  150. aid = #{aid,jdbcType=VARCHAR},
  151. remarks = #{remarks,jdbcType=VARCHAR},
  152. `status` = #{status,jdbcType=INTEGER},
  153. create_time = #{createTime,jdbcType=TIMESTAMP},
  154. financial_pay_no = #{financialPayNo,jdbcType=VARCHAR},
  155. merge_Status = #{mergeStatus,jdbcType=INTEGER}
  156. where id = #{id,jdbcType=INTEGER}
  157. </update>
  158. <delete id="deleteByids" parameterType="java.util.List">
  159. delete from temporary_receivables
  160. where id in
  161. <foreach close=")" collection="list" index="index" item="item" open="(" separator=",">
  162. #{item}
  163. </foreach>
  164. </delete>
  165. <delete id="deleteByaid" parameterType="java.lang.String">
  166. delete from temporary_receivables
  167. where aid = #{aid}
  168. </delete>
  169. <delete id="deleteNormalByaid">
  170. delete from temporary_receivables
  171. where aid = #{aid} and status &lt; 2
  172. </delete>
  173. <select id="selectByaid" resultMap="BaseResultMap">
  174. select
  175. <include refid="Base_Column_List" />
  176. from temporary_receivables
  177. where aid = #{aid}
  178. and merge_status= #{mergeStatus}
  179. </select>
  180. <select id="selectReceivablesList" parameterType="java.lang.String" resultType="com.goafanti.order.bo.ReceivablesListBo">
  181. select a.id,a.order_no orderNo,b.contract_no contractNo,a.corporate_name corporateName,c.nickname,
  182. b.total_amount totalAmount,d.name depName,a.status ,b.settlement_amount settlementAmount,
  183. a.financial_pay_no financialPayNo,a.amount,date_format(a.receivables_time, '%Y-%m-%d')receivablesTimes,
  184. date_format(a.create_time, '%Y-%m-%d %H:%i:%S')createTimes,a.remarks,c.username
  185. from temporary_receivables a left join t_order_new b on a.order_no=b.order_no left join user c on b.buyer_id=c.id
  186. left join department d on b.order_dep=d.id left join admin e on b.salesman_id=e.id
  187. where 1=1
  188. <if test="aid != null">
  189. and a.aid= #{aid}
  190. </if>
  191. <if test="mergeStatus != null">
  192. and merge_status = #{mergeStatus}
  193. </if>
  194. <if test="contractNo != null">
  195. and b.contract_no like concat('%',#{contractNo},'%')
  196. </if>
  197. <if test="orderNo != null">
  198. and a.order_no = #{orderNo}
  199. </if>
  200. <if test="adminName != null">
  201. and e.name like concat('%',#{adminName},'%')
  202. </if>
  203. <if test="nickname != null">
  204. and c.nickname like concat('%',#{nickname},'%')
  205. </if>
  206. <if test="corporateName != null">
  207. and a.corporate_name like concat('%',#{corporateName},'%')
  208. </if>
  209. <if test="orderDeps != null">
  210. and b.order_dep in
  211. <foreach close=")" collection="orderDeps" item="depId" open="(" separator=",">
  212. #{depId}
  213. </foreach>
  214. </if>
  215. <if test="adminDeps != null">
  216. and e.department_id in
  217. <foreach close=")" collection="adminDeps" item="depId" open="(" separator=",">
  218. #{depId}
  219. </foreach>
  220. </if>
  221. <if test="status != null">
  222. and a.status= #{status}
  223. </if>
  224. order by a.status desc,b.contract_no,a.create_time desc
  225. <if test="page_sql!=null">
  226. ${page_sql}
  227. </if>
  228. </select>
  229. <select id="selectReceivablesCount" resultType="java.lang.Integer">
  230. select count(*) from temporary_receivables a left join t_order_new b on a.order_no=b.order_no left join user c on b.buyer_id=c.id left join department d on b.order_dep=d.id
  231. left join admin e on b.salesman_id=e.id
  232. where 1=1
  233. <if test="aid != null">
  234. and a.aid= #{aid}
  235. </if>
  236. <if test="mergeStatus != null">
  237. and merge_status = #{mergeStatus}
  238. </if>
  239. <if test="contractNo != null">
  240. and b.contract_no like concat('%',#{contractNo},'%')
  241. </if>
  242. <if test="orderNo != null">
  243. and a.order_no = #{orderNo}
  244. </if>
  245. <if test="adminName != null">
  246. and e.name like concat('%',#{adminName},'%')
  247. </if>
  248. <if test="nickname != null">
  249. and c.nickname like concat('%',#{nickname},'%')
  250. </if>
  251. <if test="corporateName != null">
  252. and a.corporate_name like concat('%',#{corporateName},'%')
  253. </if>
  254. <if test="orderDeps != null">
  255. and b.order_dep in
  256. <foreach close=")" collection="orderDeps" item="depId" open="(" separator=",">
  257. #{depId}
  258. </foreach>
  259. </if>
  260. <if test="adminDeps != null">
  261. and e.department_id in
  262. <foreach close=")" collection="adminDeps" item="depId" open="(" separator=",">
  263. #{depId}
  264. </foreach>
  265. </if>
  266. <if test="status != null">
  267. and a.status= #{status}
  268. </if>
  269. </select>
  270. <select id="getCountlistReceivablesAmount" parameterType="Map" resultType="java.lang.String">
  271. select ifnull(sum(a.amount),0) amount from temporary_receivables a left join t_order_new b on a.order_no=b.order_no
  272. left join user c on b.buyer_id=c.id left join department d on b.order_dep=d.id left join admin e on b.salesman_id=e.id
  273. where 1=1
  274. <if test="aid != null">
  275. and a.aid= #{aid}
  276. </if>
  277. <if test="contractNo != null">
  278. and b.contract_no like concat('%',#{contractNo},'%')
  279. </if>
  280. <if test="orderNo != null">
  281. and a.order_no = #{orderNo}
  282. </if>
  283. <if test="adminName != null">
  284. and b.salesman_id like concat('%',#{adminName},'%')
  285. </if>
  286. <if test="nickname != null">
  287. and c.nickname like concat('%',#{nickname},'%')
  288. </if>
  289. <if test="corporateName != null">
  290. and a.corporate_name like concat('%',#{corporateName},'%')
  291. </if>
  292. <if test="mergeStatus != null">
  293. and a.merge_status = #{mergeStatus}
  294. </if>
  295. <if test="orderDeps != null">
  296. and b.order_dep in
  297. <foreach close=")" collection="orderDeps" item="depId" open="(" separator=",">
  298. #{depId}
  299. </foreach>
  300. </if>
  301. <if test="adminDeps != null">
  302. and e.department_id in
  303. <foreach close=")" collection="adminDeps" item="depId" open="(" separator=",">
  304. #{depId}
  305. </foreach>
  306. </if>
  307. <if test="status != null">
  308. and a.status= #{status}
  309. </if>
  310. </select>
  311. <select id="getCountlistReceivablesTotalAmount" parameterType="Map" resultType="java.lang.String">
  312. select ifnull(sum(x.total_amount),0) from (select b.order_no,b.total_amount from temporary_receivables a
  313. left join t_order_new b on a.order_no=b.order_no left join user c on b.buyer_id=c.id left join department d on b.order_dep=d.id
  314. left join admin e on b.salesman_id=e.id
  315. where 1=1
  316. <if test="aid != null">
  317. and a.aid= #{aid}
  318. </if>
  319. <if test="contractNo != null">
  320. and b.contract_no like concat('%',#{contractNo},'%')
  321. </if>
  322. <if test="orderNo != null">
  323. and a.order_no = #{orderNo}
  324. </if>
  325. <if test="adminName != null">
  326. and b.salesman_id like concat('%',#{adminName},'%')
  327. </if>
  328. <if test="nickname != null">
  329. and c.nickname like concat('%',#{nickname},'%')
  330. </if>
  331. <if test="corporateName != null">
  332. and a.corporate_name like concat('%',#{corporateName},'%')
  333. </if>
  334. <if test="mergeStatus != null">
  335. and a.merge_status = #{mergeStatus}
  336. </if>
  337. <if test="orderDeps != null">
  338. and b.order_dep in
  339. <foreach close=")" collection="orderDeps" item="depId" open="(" separator=",">
  340. #{depId}
  341. </foreach>
  342. </if>
  343. <if test="adminDeps != null">
  344. and e.department_id in
  345. <foreach close=")" collection="adminDeps" item="depId" open="(" separator=",">
  346. #{depId}
  347. </foreach>
  348. </if>
  349. <if test="status != null">
  350. and a.status= #{status}
  351. </if>
  352. group by b.order_no)x
  353. </select>
  354. <insert id="insertBatch" parameterType="com.goafanti.common.model.TemporaryReceivables">
  355. insert into temporary_receivables (id, order_no, corporate_name, amount, receivables_time,
  356. aid, remarks, status, create_time, financial_pay_no) values
  357. <foreach item="item" index="index" collection="list" separator=",">
  358. (#{item.id,jdbcType=INTEGER}, #{item.orderNo,jdbcType=VARCHAR}, #{item.corporateName,jdbcType=VARCHAR},
  359. #{item.amount,jdbcType=DECIMAL}, #{item.receivablesTime,jdbcType=TIMESTAMP}, #{item.aid,jdbcType=VARCHAR},
  360. #{item.remarks,jdbcType=VARCHAR}, #{item.status,jdbcType=INTEGER}, #{item.createTime,jdbcType=TIMESTAMP},
  361. #{item.financialPayNo,jdbcType=VARCHAR})
  362. </foreach>
  363. </insert>
  364. <update id="updateRepeatOrderNo" >
  365. update temporary_receivables x ,(select a.order_no,a.amount,a.receivables_time,a.nickname
  366. from (select a.order_no,a.corporate_name,a.amount,a.receivables_time,b.nickname,count(1) counts
  367. from temporary_receivables a left join (select x1.order_no,y1.nickname from t_order_new x1
  368. left join user y1 on x1.buyer_id=y1.id )b on a.order_no=b.order_no where a.corporate_name=b.nickname
  369. group by a.order_no,a.corporate_name,a.amount,a.receivables_time)a where a.counts>1 )y set x.status=1
  370. where x.order_no=y.order_no and x.amount=y.amount and x.receivables_time=y.receivables_time
  371. and x.corporate_name=y.nickname and x.aid= #{aid}
  372. </update>
  373. <select id="selectReceivablesNumberRepeats" parameterType="com.goafanti.common.model.TemporaryReceivables" resultType="java.lang.Integer">
  374. select count(*) from t_order_bill_new a left join user b on a.payer_id=b.id
  375. where a.order_no= #{orderNo}
  376. and b.nickname= #{corporateName}
  377. and a.transaction_amount= #{amount}
  378. and a.financial_pay_time= #{receivablesTime}
  379. </select>
  380. <select id="waitngMerge">
  381. update temporary_receivables
  382. set merge_Status=1
  383. where id in
  384. <foreach close=")" collection="list" item="id" open="(" separator=",">
  385. #{id}
  386. </foreach>
  387. </select>
  388. </mapper>