TOrderMidMapper.xml 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600
  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. <result column="legal_affairs_type" jdbcType="INTEGER" property="legalAffairsType" />
  25. <result column="operation_time" jdbcType="DATE" property="operationTime" />
  26. <result column="legal_affairs_status" jdbcType="INTEGER" property="legalAffairsStatus" />
  27. <result column="project_type" jdbcType="INTEGER" property="projectType" />
  28. <result column="service_type" jdbcType="VARCHAR" property="serviceType" />
  29. <result column="service_project" jdbcType="VARCHAR" property="serviceProject" />
  30. </resultMap>
  31. <sql id="Base_Column_List">
  32. id, order_no, salesman_id, finance_id, salesman_name, finance_name, final_receivables,
  33. final_Receivables_time, invoice_amount, create_time, buyer_name, order_receivables,
  34. order_arrears, payment_amount, cost_amount, dep_name, province_name, legal_affairs,
  35. dun_start_time, legal_affairs_type, operation_time, legal_affairs_status, project_type,
  36. service_type, service_project
  37. </sql>
  38. <select id="selectByPrimaryKey" parameterType="java.lang.Integer" resultMap="BaseResultMap">
  39. select
  40. <include refid="Base_Column_List" />
  41. from t_order_mid
  42. where id = #{id,jdbcType=INTEGER}
  43. </select>
  44. <delete id="deleteByPrimaryKey" parameterType="java.lang.Integer">
  45. delete from t_order_mid
  46. where id = #{id,jdbcType=INTEGER}
  47. </delete>
  48. <insert id="insert" keyColumn="id" keyProperty="id" parameterType="com.goafanti.common.model.TOrderMid" useGeneratedKeys="true">
  49. insert into t_order_mid (order_no, salesman_id, finance_id,
  50. salesman_name, finance_name, final_receivables,
  51. final_Receivables_time, invoice_amount,
  52. create_time, buyer_name, order_receivables,
  53. order_arrears, payment_amount, cost_amount,
  54. dep_name, province_name, legal_affairs,
  55. dun_start_time, legal_affairs_type, operation_time,
  56. legal_affairs_status, project_type, service_type,
  57. service_project)
  58. values (#{orderNo,jdbcType=VARCHAR}, #{salesmanId,jdbcType=VARCHAR}, #{financeId,jdbcType=VARCHAR},
  59. #{salesmanName,jdbcType=VARCHAR}, #{financeName,jdbcType=VARCHAR}, #{finalReceivables,jdbcType=DECIMAL},
  60. #{finalReceivablesTime,jdbcType=TIMESTAMP}, #{invoiceAmount,jdbcType=DECIMAL},
  61. #{createTime,jdbcType=TIMESTAMP}, #{buyerName,jdbcType=VARCHAR}, #{orderReceivables,jdbcType=DECIMAL},
  62. #{orderArrears,jdbcType=DECIMAL}, #{paymentAmount,jdbcType=DECIMAL}, #{costAmount,jdbcType=DECIMAL},
  63. #{depName,jdbcType=VARCHAR}, #{provinceName,jdbcType=VARCHAR}, #{legalAffairs,jdbcType=INTEGER},
  64. #{dunStartTime,jdbcType=TIMESTAMP}, #{legalAffairsType,jdbcType=INTEGER}, #{operationTime,jdbcType=DATE},
  65. #{legalAffairsStatus,jdbcType=INTEGER}, #{projectType,jdbcType=INTEGER}, #{serviceType,jdbcType=VARCHAR},
  66. #{serviceProject,jdbcType=VARCHAR})
  67. </insert>
  68. <insert id="insertSelective" keyColumn="id" keyProperty="id" parameterType="com.goafanti.common.model.TOrderMid" useGeneratedKeys="true">
  69. insert into t_order_mid
  70. <trim prefix="(" suffix=")" suffixOverrides=",">
  71. <if test="orderNo != null">
  72. order_no,
  73. </if>
  74. <if test="salesmanId != null">
  75. salesman_id,
  76. </if>
  77. <if test="financeId != null">
  78. finance_id,
  79. </if>
  80. <if test="salesmanName != null">
  81. salesman_name,
  82. </if>
  83. <if test="financeName != null">
  84. finance_name,
  85. </if>
  86. <if test="finalReceivables != null">
  87. final_receivables,
  88. </if>
  89. <if test="finalReceivablesTime != null">
  90. final_Receivables_time,
  91. </if>
  92. <if test="invoiceAmount != null">
  93. invoice_amount,
  94. </if>
  95. <if test="createTime != null">
  96. create_time,
  97. </if>
  98. <if test="buyerName != null">
  99. buyer_name,
  100. </if>
  101. <if test="orderReceivables != null">
  102. order_receivables,
  103. </if>
  104. <if test="orderArrears != null">
  105. order_arrears,
  106. </if>
  107. <if test="paymentAmount != null">
  108. payment_amount,
  109. </if>
  110. <if test="costAmount != null">
  111. cost_amount,
  112. </if>
  113. <if test="depName != null">
  114. dep_name,
  115. </if>
  116. <if test="provinceName != null">
  117. province_name,
  118. </if>
  119. <if test="legalAffairs != null">
  120. legal_affairs,
  121. </if>
  122. <if test="dunStartTime != null">
  123. dun_start_time,
  124. </if>
  125. <if test="legalAffairsType != null">
  126. legal_affairs_type,
  127. </if>
  128. <if test="operationTime != null">
  129. operation_time,
  130. </if>
  131. <if test="legalAffairsStatus != null">
  132. legal_affairs_status,
  133. </if>
  134. <if test="projectType != null">
  135. project_type,
  136. </if>
  137. <if test="serviceType != null">
  138. service_type,
  139. </if>
  140. <if test="serviceProject != null">
  141. service_project,
  142. </if>
  143. </trim>
  144. <trim prefix="values (" suffix=")" suffixOverrides=",">
  145. <if test="orderNo != null">
  146. #{orderNo,jdbcType=VARCHAR},
  147. </if>
  148. <if test="salesmanId != null">
  149. #{salesmanId,jdbcType=VARCHAR},
  150. </if>
  151. <if test="financeId != null">
  152. #{financeId,jdbcType=VARCHAR},
  153. </if>
  154. <if test="salesmanName != null">
  155. #{salesmanName,jdbcType=VARCHAR},
  156. </if>
  157. <if test="financeName != null">
  158. #{financeName,jdbcType=VARCHAR},
  159. </if>
  160. <if test="finalReceivables != null">
  161. #{finalReceivables,jdbcType=DECIMAL},
  162. </if>
  163. <if test="finalReceivablesTime != null">
  164. #{finalReceivablesTime,jdbcType=TIMESTAMP},
  165. </if>
  166. <if test="invoiceAmount != null">
  167. #{invoiceAmount,jdbcType=DECIMAL},
  168. </if>
  169. <if test="createTime != null">
  170. #{createTime,jdbcType=TIMESTAMP},
  171. </if>
  172. <if test="buyerName != null">
  173. #{buyerName,jdbcType=VARCHAR},
  174. </if>
  175. <if test="orderReceivables != null">
  176. #{orderReceivables,jdbcType=DECIMAL},
  177. </if>
  178. <if test="orderArrears != null">
  179. #{orderArrears,jdbcType=DECIMAL},
  180. </if>
  181. <if test="paymentAmount != null">
  182. #{paymentAmount,jdbcType=DECIMAL},
  183. </if>
  184. <if test="costAmount != null">
  185. #{costAmount,jdbcType=DECIMAL},
  186. </if>
  187. <if test="depName != null">
  188. #{depName,jdbcType=VARCHAR},
  189. </if>
  190. <if test="provinceName != null">
  191. #{provinceName,jdbcType=VARCHAR},
  192. </if>
  193. <if test="legalAffairs != null">
  194. #{legalAffairs,jdbcType=INTEGER},
  195. </if>
  196. <if test="dunStartTime != null">
  197. #{dunStartTime,jdbcType=TIMESTAMP},
  198. </if>
  199. <if test="legalAffairsType != null">
  200. #{legalAffairsType,jdbcType=INTEGER},
  201. </if>
  202. <if test="operationTime != null">
  203. #{operationTime,jdbcType=DATE},
  204. </if>
  205. <if test="legalAffairsStatus != null">
  206. #{legalAffairsStatus,jdbcType=INTEGER},
  207. </if>
  208. <if test="projectType != null">
  209. #{projectType,jdbcType=INTEGER},
  210. </if>
  211. <if test="serviceType != null">
  212. #{serviceType,jdbcType=VARCHAR},
  213. </if>
  214. <if test="serviceProject != null">
  215. #{serviceProject,jdbcType=VARCHAR},
  216. </if>
  217. </trim>
  218. </insert>
  219. <update id="updateByPrimaryKeySelective" parameterType="com.goafanti.common.model.TOrderMid">
  220. update t_order_mid
  221. <set>
  222. <if test="orderNo != null">
  223. order_no = #{orderNo,jdbcType=VARCHAR},
  224. </if>
  225. <if test="salesmanId != null">
  226. salesman_id = #{salesmanId,jdbcType=VARCHAR},
  227. </if>
  228. <if test="financeId != null">
  229. finance_id = #{financeId,jdbcType=VARCHAR},
  230. </if>
  231. <if test="salesmanName != null">
  232. salesman_name = #{salesmanName,jdbcType=VARCHAR},
  233. </if>
  234. <if test="financeName != null">
  235. finance_name = #{financeName,jdbcType=VARCHAR},
  236. </if>
  237. <if test="finalReceivables != null">
  238. final_receivables = #{finalReceivables,jdbcType=DECIMAL},
  239. </if>
  240. <if test="finalReceivablesTime != null">
  241. final_Receivables_time = #{finalReceivablesTime,jdbcType=TIMESTAMP},
  242. </if>
  243. <if test="invoiceAmount != null">
  244. invoice_amount = #{invoiceAmount,jdbcType=DECIMAL},
  245. </if>
  246. <if test="createTime != null">
  247. create_time = #{createTime,jdbcType=TIMESTAMP},
  248. </if>
  249. <if test="buyerName != null">
  250. buyer_name = #{buyerName,jdbcType=VARCHAR},
  251. </if>
  252. <if test="orderReceivables != null">
  253. order_receivables = #{orderReceivables,jdbcType=DECIMAL},
  254. </if>
  255. <if test="orderArrears != null">
  256. order_arrears = #{orderArrears,jdbcType=DECIMAL},
  257. </if>
  258. <if test="paymentAmount != null">
  259. payment_amount = #{paymentAmount,jdbcType=DECIMAL},
  260. </if>
  261. <if test="costAmount != null">
  262. cost_amount = #{costAmount,jdbcType=DECIMAL},
  263. </if>
  264. <if test="depName != null">
  265. dep_name = #{depName,jdbcType=VARCHAR},
  266. </if>
  267. <if test="provinceName != null">
  268. province_name = #{provinceName,jdbcType=VARCHAR},
  269. </if>
  270. <if test="legalAffairs != null">
  271. legal_affairs = #{legalAffairs,jdbcType=INTEGER},
  272. </if>
  273. <if test="dunStartTime != null">
  274. dun_start_time = #{dunStartTime,jdbcType=TIMESTAMP},
  275. </if>
  276. <if test="legalAffairsType != null">
  277. legal_affairs_type = #{legalAffairsType,jdbcType=INTEGER},
  278. </if>
  279. <if test="operationTime != null">
  280. operation_time = #{operationTime,jdbcType=DATE},
  281. </if>
  282. <if test="legalAffairsStatus != null">
  283. legal_affairs_status = #{legalAffairsStatus,jdbcType=INTEGER},
  284. </if>
  285. <if test="projectType != null">
  286. project_type = #{projectType,jdbcType=INTEGER},
  287. </if>
  288. <if test="serviceType != null">
  289. service_type = #{serviceType,jdbcType=VARCHAR},
  290. </if>
  291. <if test="serviceProject != null">
  292. service_project = #{serviceProject,jdbcType=VARCHAR},
  293. </if>
  294. </set>
  295. where id = #{id,jdbcType=INTEGER}
  296. </update>
  297. <update id="updateByPrimaryKey" parameterType="com.goafanti.common.model.TOrderMid">
  298. update t_order_mid
  299. set order_no = #{orderNo,jdbcType=VARCHAR},
  300. salesman_id = #{salesmanId,jdbcType=VARCHAR},
  301. finance_id = #{financeId,jdbcType=VARCHAR},
  302. salesman_name = #{salesmanName,jdbcType=VARCHAR},
  303. finance_name = #{financeName,jdbcType=VARCHAR},
  304. final_receivables = #{finalReceivables,jdbcType=DECIMAL},
  305. final_Receivables_time = #{finalReceivablesTime,jdbcType=TIMESTAMP},
  306. invoice_amount = #{invoiceAmount,jdbcType=DECIMAL},
  307. create_time = #{createTime,jdbcType=TIMESTAMP},
  308. buyer_name = #{buyerName,jdbcType=VARCHAR},
  309. order_receivables = #{orderReceivables,jdbcType=DECIMAL},
  310. order_arrears = #{orderArrears,jdbcType=DECIMAL},
  311. payment_amount = #{paymentAmount,jdbcType=DECIMAL},
  312. cost_amount = #{costAmount,jdbcType=DECIMAL},
  313. dep_name = #{depName,jdbcType=VARCHAR},
  314. province_name = #{provinceName,jdbcType=VARCHAR},
  315. legal_affairs = #{legalAffairs,jdbcType=INTEGER},
  316. dun_start_time = #{dunStartTime,jdbcType=TIMESTAMP},
  317. legal_affairs_type = #{legalAffairsType,jdbcType=INTEGER},
  318. operation_time = #{operationTime,jdbcType=DATE},
  319. legal_affairs_status = #{legalAffairsStatus,jdbcType=INTEGER},
  320. project_type = #{projectType,jdbcType=INTEGER},
  321. service_type = #{serviceType,jdbcType=VARCHAR},
  322. service_project = #{serviceProject,jdbcType=VARCHAR}
  323. where id = #{id,jdbcType=INTEGER}
  324. </update>
  325. <select id="selectByOrderNo" resultMap="BaseResultMap">
  326. select
  327. <include refid="Base_Column_List" />
  328. from t_order_mid
  329. where order_no = #{id,jdbcType=INTEGER}
  330. </select>
  331. <update id="updateSalesmanId">
  332. update t_order_mid a ,admin b set a.salesman_id=#{transferId},a.salesman_name=b.name
  333. where b.id=#{transferId} and a.salesman_id=#{aid}
  334. </update>
  335. <update id="updateFinanceId">
  336. update t_order_new a ,t_order_mid b,admin c set b.finance_id=#{financeId},b.finance_name=c.name
  337. where a.order_dep=#{id} and a.order_no=b.order_no and c.id= #{financeId}
  338. </update>
  339. <update id="updatefinalReceivables">
  340. update t_order_mid set final_receivables= #{amount},`final_Receivables_time`= #{receivablesTime},
  341. order_arrears=if(order_arrears- #{amount} &lt; 0,0,order_arrears- #{amount})
  342. where order_no= #{orderNo}
  343. </update>
  344. <update id="updateInvoice">
  345. update t_order_mid m,(select order_no,sum(amount)amount from t_order_invoice where status=2 group by order_no)b
  346. set m.invoice_amount=b.amount where m.order_no= #{orderNo} and m.order_no=b.order_no
  347. </update>
  348. <select id="selectDepNameByDepid" resultType="java.lang.String">
  349. select name from department where id= #{orderDep}
  350. </select>
  351. <update id="updateCostAmount">
  352. update t_order_task a ,t_order_mid b
  353. <set>
  354. <if test="cost !=null">
  355. b.cost_amount= #{cost},
  356. </if>
  357. <if test="payment !=null">
  358. b.payment_amount= #{payment},
  359. </if>
  360. </set>
  361. where a.order_no=b.order_no and a.id= #{tid}
  362. </update>
  363. <update id="updateAddCostAmount">
  364. update t_order_task a ,t_order_mid b
  365. <set>
  366. <if test="cost !=null">
  367. b.cost_amount= b.cost_amount+#{cost},
  368. </if>
  369. </set>
  370. where a.order_no=b.order_no and a.id= #{tid}
  371. </update>
  372. <update id="updateByOrderNo">
  373. update t_order_mid
  374. <set>
  375. <if test="salesmanId != null">
  376. salesman_id = #{salesmanId,jdbcType=VARCHAR},
  377. </if>
  378. <if test="financeId != null">
  379. finance_id = #{financeId,jdbcType=VARCHAR},
  380. </if>
  381. <if test="salesmanName != null">
  382. salesman_name = #{salesmanName,jdbcType=VARCHAR},
  383. </if>
  384. <if test="financeName != null">
  385. finance_name = #{financeName,jdbcType=VARCHAR},
  386. </if>
  387. <if test="finalReceivables != null">
  388. final_receivables = #{finalReceivables,jdbcType=DECIMAL},
  389. </if>
  390. <if test="finalReceivablesTime != null">
  391. final_Receivables_time = #{finalReceivablesTime,jdbcType=TIMESTAMP},
  392. </if>
  393. <if test="invoiceAmount != null">
  394. invoice_amount = #{invoiceAmount,jdbcType=DECIMAL},
  395. </if>
  396. <if test="createTime != null">
  397. create_time = #{createTime,jdbcType=TIMESTAMP},
  398. </if>
  399. <if test="buyerName != null">
  400. buyer_name = #{buyerName,jdbcType=VARCHAR},
  401. </if>
  402. <if test="orderReceivables != null">
  403. order_receivables = #{orderReceivables,jdbcType=DECIMAL},
  404. </if>
  405. <if test="orderArrears != null">
  406. order_arrears = #{orderArrears,jdbcType=DECIMAL},
  407. </if>
  408. <if test="paymentAmount != null">
  409. payment_amount = #{paymentAmount,jdbcType=DECIMAL},
  410. </if>
  411. <if test="costAmount != null">
  412. cost_amount = #{costAmount,jdbcType=DECIMAL},
  413. </if>
  414. <if test="depName != null">
  415. dep_name = #{depName,jdbcType=VARCHAR},
  416. </if>
  417. <if test="provinceName != null">
  418. province_name = #{provinceName,jdbcType=VARCHAR},
  419. </if>
  420. <if test="legalAffairs != null">
  421. legal_affairs = #{legalAffairs,jdbcType=INTEGER},
  422. </if>
  423. <if test="dunStartTime != null">
  424. dun_start_time = #{dunStartTime,jdbcType=TIMESTAMP},
  425. </if>
  426. <if test="legalAffairsType != null">
  427. legal_affairs_type = #{legalAffairsType,jdbcType=INTEGER},
  428. </if>
  429. <if test="operationTime != null">
  430. operation_time = #{operationTime,jdbcType=DATE},
  431. </if>
  432. <if test="legalAffairsStatus != null">
  433. legal_affairs_status = #{legalAffairsStatus,jdbcType=INTEGER},
  434. </if>
  435. <if test="projectType != null">
  436. project_type = #{projectType,jdbcType=INTEGER},
  437. </if>
  438. <if test="serviceType != null">
  439. service_type = #{serviceType,jdbcType=VARCHAR},
  440. </if>
  441. <if test="serviceProject != null">
  442. service_project = #{serviceProject,jdbcType=VARCHAR},
  443. </if>
  444. </set>
  445. where order_no = #{orderNo,jdbcType=VARCHAR}
  446. </update>
  447. <select id="legalAffairsOrderList" resultType="com.goafanti.order.bo.OutOrderLegalAffairsListBo">
  448. select a.order_no orderNo,a.contract_no contractNo,b.buyer_name buyerName,b.salesman_name salesmanName,b.dep_name depName,
  449. a.total_amount totalAmount ,a.settlement_amount settlementAmount ,b.order_receivables orderReceivables,b.legal_affairs legalAffairs,
  450. b.order_arrears orderArrears,b.dun_start_time dunStartTime,date_format(b.dun_start_time,'%Y-%m-%d %H:%i:%S')dunStartTimes
  451. <if test="type==1 or type==2 or type==3">
  452. ,b.operation_time operationTime,date_format(b.operation_time,'%Y-%m-%d')operationDate,b.legal_affairs_type `type`,
  453. b.legal_affairs_status status
  454. </if>
  455. from t_order_new a left join t_order_mid b on a.order_no =b.order_no
  456. <if test="shiro == 2">
  457. left join admin c on a.salesman_id =c.id
  458. </if>
  459. where 1=1 and a.delete_sign in (0,2)
  460. <if test="type==1 or type==2 or type==3">
  461. and b.legal_affairs =1
  462. and b.legal_affairs_type = (#{type}-1)
  463. </if>
  464. <if test="type==0">
  465. and b.order_receivables >0
  466. </if>
  467. <if test="status != null">
  468. and b.legal_affairs_status = #{status}
  469. </if>
  470. <if test="shiro ==2">
  471. and c.superior_id = #{sid}
  472. </if>
  473. <if test="userName != null">
  474. and b.buyer_name like concat('%',#{userName},'%')
  475. </if>
  476. <if test="legalAffairs != null">
  477. and b.legal_affairs = #{legalAffairs}
  478. </if>
  479. <if test="contractNo != null">
  480. and a.contract_no like concat('%',#{contractNo},'%')
  481. </if>
  482. <if test="aid != null">
  483. and b.salesman_id = #{aid}
  484. </if>
  485. <if test="deps != null">
  486. and a.order_dep in
  487. <foreach close=")" collection="deps" item="dep" open="(" separator=",">
  488. #{dep}
  489. </foreach>
  490. </if>
  491. <if test="type==0">
  492. <if test="startTime != null and endTime != null">
  493. and b.dun_start_time between #{startTime} and #{endTime}
  494. </if>
  495. </if>
  496. <if test="type==1 or type==2 or type==3">
  497. <if test="startTime != null and endTime != null">
  498. and b.operation_time between #{startTime} and #{endTime}
  499. </if>
  500. </if>
  501. order by b.dun_start_time
  502. <if test="page_sql != null">
  503. ${page_sql}
  504. </if>
  505. </select>
  506. <select id="legalAffairsOrderCount" resultType="integer">
  507. select count(*)
  508. from t_order_new a left join t_order_mid b on a.order_no =b.order_no
  509. <if test="shiro == 2">
  510. left join admin c on a.salesman_id =c.id
  511. </if>
  512. where 1=1 and a.delete_sign in (0,2)
  513. <if test="type==1 or type==2 or type==3">
  514. and b.legal_affairs =1
  515. and b.legal_affairs_type = (#{type}-1)
  516. </if>
  517. <if test="type==0">
  518. and b.order_receivables >0
  519. </if>
  520. <if test="status != null">
  521. and b.legal_affairs_status = #{status}
  522. </if>
  523. <if test="shiro ==2">
  524. and c.superior_id = #{sid}
  525. </if>
  526. <if test="userName != null">
  527. and b.buyer_name like concat('%',#{userName},'%')
  528. </if>
  529. <if test="legalAffairs != null">
  530. and b.legal_affairs = #{legalAffairs}
  531. </if>
  532. <if test="contractNo != null">
  533. and a.contract_no like concat('%',#{contractNo},'%')
  534. </if>
  535. <if test="aid != null">
  536. and b.salesman_id = #{aid}
  537. </if>
  538. <if test="deps != null">
  539. and a.order_dep in
  540. <foreach close=")" collection="deps" item="dep" open="(" separator=",">
  541. #{dep}
  542. </foreach>
  543. </if>
  544. <if test="type==0">
  545. <if test="startTime != null and endTime != null">
  546. and b.dun_start_time between #{startTime} and #{endTime}
  547. </if>
  548. </if>
  549. <if test="type==1 or type==2 or type==3">
  550. <if test="startTime != null and endTime != null">
  551. and b.operation_time between #{startTime} and #{endTime}
  552. </if>
  553. </if>
  554. </select>
  555. <update id="updateByList">
  556. update t_order_mid
  557. set legal_affairs=1,legal_affairs_type =0
  558. where order_no in(
  559. <foreach collection="list" index="index" item="item" separator=",">
  560. #{item}
  561. </foreach>
  562. )
  563. </update>
  564. <select id="selectErrorDun" resultType="com.goafanti.common.bo.ErrorDunListBo">
  565. select a.order_no orderNo,a.order_receivables orderReceivables ,a.order_arrears orderArrears,b.money,a.create_time createTime
  566. from t_order_mid a left join (select order_no ,ifnull(sum(money),0)money from new_order_dun where status =1 group by order_no)b
  567. on a.order_no =b.order_no
  568. where a.order_receivables !=b.money order by a.create_time;
  569. </select>
  570. <update id="updateErrorDun">
  571. update t_order_mid a ,(select order_no ,ifnull(sum(money),0)money from new_order_dun where status =1 group by order_no)b,
  572. t_order_new c
  573. set a.order_receivables=b.money,a.order_arrears =(b.money-c.settlement_amount)
  574. where a.order_no =b.order_no and a.order_no =c.order_no and a.order_receivables !=b.money;
  575. </update>
  576. <select id="judgeProjectType" resultType="java.lang.Integer">
  577. select count(*) from t_order_new a left join t_order_task b on a.order_no =b.order_no
  578. left join business_project c on b.commodity_id =c.id left join business_category d on c.cid =d.id
  579. where d.sort =6 and a.order_no = #{orderNo}
  580. </select>
  581. <update id="updateCountProjectAndType">
  582. update t_order_mid a ,(select a.order_no ,GROUP_CONCAT(DISTINCT a.commodity_name )pname, GROUP_CONCAT(DISTINCT c.cname )cname
  583. from t_order_task a left join business_project b on a.commodity_id =b.id
  584. left join business_category c on b.cid =c.id
  585. group by a.order_no )b
  586. set a.service_project =b.pname,a.service_type =b.cname
  587. where a.order_no=b.order_no and a.order_no = #{orderNo};
  588. </update>
  589. </mapper>