<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="cn.com.victorysoft.business.calc.dao.QualityDataSyncDao">

  <insert id="syncQualityData">
    insert into indi_quality_check
    (object_type, object_name, record_date, unitcode, oil_standard, oil_actual,
    suspension_standard, suspension_actual, srb_standard, srb_actual, particle_standard, particle_actual,
    corrosion_standard, corrosion_actual, auxiliary_standard, auxiliary_actual, auxiliary_name, create_on)
    select
    b.station_type OBJECT_TYPE,
    a.jcd OBJECT_NAME,
    trunc(a.qyrq) RECORD_DATE,
    b.area_code UNITCODE,
    30 OIL_STANDARD,
    a.hyl OIL_ACTUAL,
    10 SUSPENSION_STANDARD,
    a.xfgthl SUSPENSION_ACTUAL,
    null SRB_STANDARD,
    a.LSYHYJ SRB_ACTUAL,
    3 PARTICLE_STANDARD,
    a.XFWKLZJZ PARTICLE_ACTUAL,
    0.076 CORROSION_STANDARD,
    a.PJFSL CORROSION_ACTUAL,
    null AUXILIARY_STANDARD,
    null AUXILIARY_ACTUAL,
    null AUXILIARY_NAME,
    sysdate CREATE_ON
    from ys_dfc15 a, sys_station b
    where a.jcd = b.name
    and a.qyrq >= #{startDate}
    and a.qyrq &lt; #{endDate} + 1
    and not exists (select 1 from indi_quality_check where object_name = a.jcd and record_date = trunc(a.qyrq))
    order by a.qyrq, a.jcd
  </insert>

  <insert id="szjcsjQualityData">
    insert into indi_quality_check
    (object_type, object_name, record_date, unitcode, oil_standard, oil_actual,
    suspension_standard, suspension_actual, srb_standard, srb_actual, particle_standard, particle_actual,
    corrosion_standard, corrosion_actual, auxiliary_standard, auxiliary_actual, auxiliary_name, create_on)
    select
    'WATER_WELL' OBJECT_TYPE,
    a.jh OBJECT_NAME,
    a.syrq RECORD_DATE,
    b.UNITCODE_AREA UNITCODE,
    30 OIL_STANDARD,
    a.hyl OIL_ACTUAL,
    10 SUSPENSION_STANDARD,
    a.xfgt SUSPENSION_ACTUAL,
    null SRB_STANDARD,
    a.srbj SRB_ACTUAL,
    3 PARTICLE_STANDARD,
    a.XFWKLZJZZ PARTICLE_ACTUAL,
    0.076 CORROSION_STANDARD,
    a.PJFSL CORROSION_ACTUAL,
    null AUXILIARY_STANDARD,
    null AUXILIARY_ACTUAL,
    null AUXILIARY_NAME,
    sysdate CREATE_ON
    from
    (select a.*, row_number() over(partition by jh, syrq order by syrq) rn from
    v_ods_xchyfx_szjcsj a
    where jh is not null
    and a.syrq >= #{startDate}
    and a.syrq &lt; #{endDate} + 1) a,
    water_well_basic b
    where a.rn = 1
    and b.UNITCODE_AREA is not null
    and a.jh = b.wellname
    and not exists (select 1 from indi_quality_check where object_name = a.jh and record_date = a.syrq)
    order by a.syrq, a.jh
  </insert>

  <insert id="xchyfxQualityData">
    insert into indi_quality_check
    (object_type, object_name, record_date, unitcode, oil_standard, oil_actual,
    suspension_standard, suspension_actual, srb_standard, srb_actual, particle_standard, particle_actual,
    corrosion_standard, corrosion_actual, auxiliary_standard, auxiliary_actual, auxiliary_name, create_on)
    select
    b.station_type OBJECT_TYPE,
    a.zkmc OBJECT_NAME,
    a.syrq RECORD_DATE,
    b.area_code UNITCODE,
    30 OIL_STANDARD,
    a.hyl OIL_ACTUAL,
    10 SUSPENSION_STANDARD,
    a.xfgt SUSPENSION_ACTUAL,
    null SRB_STANDARD,
    a.srbj SRB_ACTUAL,
    3 PARTICLE_STANDARD,
    a.XFWKLZJZZ PARTICLE_ACTUAL,
    0.076 CORROSION_STANDARD,
    a.PJFSL CORROSION_ACTUAL,
    null AUXILIARY_STANDARD,
    null AUXILIARY_ACTUAL,
    null AUXILIARY_NAME,
    sysdate CREATE_ON
    from
    (select a.*, row_number() over(partition by zkmc, syrq order by syrq) rn from
    v_ods_xchyfx_szjcsj a
    where zkmc is not null
    and a.syrq >= #{startDate}
    and a.syrq &lt; #{endDate} + 1) a,
    sys_station b
    where a.rn = 1
    and a.zkmc = b.name
    and not exists (select 1 from indi_quality_check where object_name = a.zkmc and record_date = a.SYRQ)
    order by a.SYRQ, a.zkmc
  </insert>

</mapper>
