FlushDataSync.xml 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  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="cn.com.victorysoft.business.calc.dao.FlushDataSyncDao">
  4. <insert id="syncFlushRecord">
  5. insert into con_flush_record
  6. (wellname, record_date, unitcode, start_time, range_time, in_water, out_water, displacement, reason, type_id, created_on)
  7. select jh, rq, dwdm, xjrq, xjys, jksl, cksl, jkpl, xjyy, xjfs, created_on
  8. from (select t.*, row_number() over(partition by jh, rq order by xjrq desc) rn
  9. from (select jh, trunc(xjrq) rq, dwdm, xjrq, xjys, jksl, cksl, jkpl, xjyy, xjfs, sysdate created_on
  10. from YS_DGC12 t
  11. where xjrq >= #{startDate} and xjrq &lt; #{endDate} + 1
  12. and not exists (select 1 from CON_FLUSH_RECORD where wellname = t.jh and record_date = trunc(t.xjrq))
  13. order by jh, xjrq desc) t) t where rn = 1
  14. </insert>
  15. <insert id="insertFlushDaily">
  16. insert into CON_FLUSH_DAILY
  17. (WELLNAME,
  18. RECORD_DATE,
  19. UNITCODE,
  20. RANGE_TIME,
  21. DISPLACEMENT,
  22. REASON,
  23. TYPE_ID,
  24. EFFECTIVE,
  25. CREATED_ON,
  26. MODIFIED_ON,
  27. before_date,
  28. BEFORE_PT,
  29. BEFORE_PLAN_WATER,
  30. BEFORE_WATER,
  31. after_date,
  32. AFTER_PT,
  33. AFTER_PLAN_WATER,
  34. AFTER_WATER,
  35. AFTER_WATER_RATE)
  36. SELECT WELLNAME,
  37. RECORD_DATE,
  38. UNITCODE,
  39. RANGE_TIME,
  40. DISPLACEMENT,
  41. REASON,
  42. TYPE_ID,
  43. EFFECTIVE,
  44. CREATED_ON,
  45. MODIFIED_ON,
  46. before_date,
  47. A.YY BEFORE_PT,
  48. A.RPZSL BEFORE_PLAN_WATER,
  49. A.RZSL BEFORE_WATER,
  50. after_date,
  51. B.YY AFTER_PT,
  52. B.RPZSL AFTER_PLAN_WATER,
  53. B.RZSL AFTER_WATER,
  54. DECODE(B.RPZSL, 0, NULL, ROUND(B.RZSL / B.RPZSL, 2)) AFTER_WATER_RATE
  55. from
  56. (SELECT t.*,
  57. (select max(rq) from YS_DBA02 where jh = t.wellname and rq &lt; t.record_date and scsj = 24) before_date,
  58. (select min(rq) from YS_DBA02 where jh = t.wellname and rq > t.record_date and scsj = 24) after_date
  59. FROM CON_FLUSH_RECORD T
  60. where not exists (select 1 from CON_FLUSH_DAILY where wellname = t.wellname and record_date = t.record_date)
  61. ) t
  62. LEFT JOIN YS_DBA02 A ON T.WELLNAME = A.JH AND T.before_date = A.RQ
  63. LEFT JOIN YS_DBA02 B ON T.WELLNAME = B.JH AND T.after_date = B.RQ
  64. </insert>
  65. <update id="updateFlushDaily">
  66. merge into CON_FLUSH_DAILY a
  67. using (
  68. select WELLNAME,
  69. RECORD_DATE,
  70. after_date2,
  71. B.YY AFTER_PT,
  72. B.RPZSL AFTER_PLAN_WATER,
  73. B.RZSL AFTER_WATER,
  74. DECODE(B.RPZSL, 0, NULL, ROUND(B.RZSL / B.RPZSL, 2)) AFTER_WATER_RATE
  75. from
  76. (SELECT t.*,
  77. (select min(rq) from YS_DBA02 where jh = t.wellname and rq > t.record_date and scsj = 24) after_date2
  78. FROM CON_FLUSH_DAILY T
  79. where after_date is null
  80. ) t
  81. JOIN YS_DBA02 B ON T.WELLNAME = B.JH AND T.after_date2 = B.RQ
  82. ) t
  83. on (a.WELLNAME = t.WELLNAME and a.RECORD_DATE = t.RECORD_DATE)
  84. when matched then
  85. update set
  86. a.after_date = t.after_date2,
  87. a.AFTER_PT = t.AFTER_PT,
  88. a.AFTER_PLAN_WATER = t.AFTER_PLAN_WATER,
  89. a.AFTER_WATER = t.AFTER_WATER,
  90. a.AFTER_WATER_RATE = t.AFTER_WATER_RATE
  91. </update>
  92. </mapper>