一/自定义类
package cn.com.mycompany.InsertAndUpdate.a_calc_day_power;
import java.math.BigDecimal;
public class A_calc_day_power {
private BigDecimal id;
private String area_code;
private String org_no;
private String cons_no;
private String tmnl_asset_no;
private String asset_no;
private BigDecimal mp_type;
private String data_src ;
private String stat_date;
private BigDecimal pt ;
private BigDecimal ct ;
private BigDecimal self_factor ;
private BigDecimal pap_r_s ;
private BigDecimal pap_r_e ;
private BigDecimal pap_e ;
private BigDecimal pap_r1_s ;
private BigDecimal pap_r1_e ;
private BigDecimal pap_e1 ;
private BigDecimal pap_r2_s ;
private BigDecimal pap_r2_e ;
private BigDecimal pap_e2 ;
private BigDecimal pap_r3_s ;
private BigDecimal pap_r3_e ;
private BigDecimal pap_e3 ;
private BigDecimal pap_r4_s ;
private BigDecimal pap_r4_e ;
private BigDecimal pap_e4 ;
private BigDecimal rap_r_s ;
private BigDecimal rap_r_e ;
private BigDecimal rap_e ;
private BigDecimal rap_r1_s ;
private BigDecimal rap_r1_e ;
private BigDecimal rap_e1 ;
private BigDecimal rap_r2_s ;
private BigDecimal rap_r2_e ;
private BigDecimal rap_e2 ;
private BigDecimal rap_r3_s ;
private BigDecimal rap_r3_e ;
private BigDecimal rap_e3 ;
private BigDecimal rap_r4_s ;
private BigDecimal rap_r4_e ;
private BigDecimal rap_e4 ;
private BigDecimal prp_r_s ;
private BigDecimal prp_r_e ;
private BigDecimal prp_e ;
private BigDecimal rrp_r_s ;
private BigDecimal rrp_r_e ;
private BigDecimal rrp_e ;
private BigDecimal rp1_r_s ;
private BigDecimal rp1_r_e ;
private BigDecimal rp1_e ;
private BigDecimal rp4_r_s ;
private BigDecimal rp4_r_e ;
private BigDecimal rp4_e ;
private BigDecimal rp2_r_s ;
private BigDecimal rp2_r_e ;
private BigDecimal rp2_e ;
private BigDecimal rp3_r_s ;
private BigDecimal rp3_r_e ;
private BigDecimal rp3_e ;
private BigDecimal rp_r_s ;
private BigDecimal rp_r_e ;
private BigDecimal rp_e ;
private BigDecimal factor_s ;
private BigDecimal factor_e ;
private BigDecimal pap_demand_e ;
private String pap_demand_time_e ;
private BigDecimal pap_demand_s ;
private String pap_demand_time_s ;
private String cons_sort;
private BigDecimal calc_mode ;
private BigDecimal mp_sn ;
private BigDecimal ins_flag ;
private String ins_date ;
private String staff_no ;
private BigDecimal gpq ;
private BigDecimal ppq ;
private BigDecimal spq ;
private BigDecimal gpq_repair ;
private BigDecimal ppq_repair ;
private BigDecimal spq_repair ;
private BigDecimal both_meas ;
private BigDecimal mp_level ;
private BigDecimal t_factor ;
private BigDecimal ori_pap_e ;
private BigDecimal ori_pap_e1 ;
private BigDecimal ori_pap_e2 ;
private BigDecimal ori_pap_e3 ;
private BigDecimal ori_pap_e4 ;
private BigDecimal ori_prp_e ;
private BigDecimal ori_rap_e ;
private BigDecimal ori_rap_e1 ;
private BigDecimal ori_rap_e2 ;
private BigDecimal ori_rap_e3 ;
private BigDecimal ori_rap_e4 ;
private BigDecimal ori_rrp_e ;
private BigDecimal ori_rp1_e ;
private BigDecimal orirp4_e ;
private BigDecimal ori_rp2_e ;
private BigDecimal ori_rp3_e ;
private String mark ;
private BigDecimal meter_id ;
private BigDecimal contract_cap ;
private BigDecimal fc_gc_flag ;
private BigDecimal ori_rp4_e ;
private String op_type;
private String op_time;
private String cur_time;
public A_calc_day_power(BigDecimal id, String area_code, String org_no, String cons_no, String tmnl_asset_no, String asset_no, BigDecimal mp_type, String data_src, String stat_date, BigDecimal pt, BigDecimal ct, BigDecimal self_factor, BigDecimal pap_r_s, BigDecimal pap_r_e, BigDecimal pap_e, BigDecimal pap_r1_s, BigDecimal pap_r1_e, BigDecimal pap_e1, BigDecimal pap_r2_s, BigDecimal pap_r2_e, BigDecimal pap_e2, BigDecimal pap_r3_s, BigDecimal pap_r3_e, BigDecimal pap_e3, BigDecimal pap_r4_s, BigDecimal pap_r4_e, BigDecimal pap_e4, BigDecimal rap_r_s, BigDecimal rap_r_e, BigDecimal rap_e, BigDecimal rap_r1_s, BigDecimal rap_r1_e, BigDecimal rap_e1, BigDecimal rap_r2_s, BigDecimal rap_r2_e, BigDecimal rap_e2, BigDecimal rap_r3_s, BigDecimal rap_r3_e, BigDecimal rap_e3, BigDecimal rap_r4_s, BigDecimal rap_r4_e, BigDecimal rap_e4, BigDecimal prp_r_s, BigDecimal prp_r_e, BigDecimal prp_e, BigDecimal rrp_r_s, BigDecimal rrp_r_e, BigDecimal rrp_e, BigDecimal rp1_r_s, BigDecimal rp1_r_e, BigDecimal rp1_e, BigDecimal rp4_r_s, BigDecimal rp4_r_e, BigDecimal rp4_e, BigDecimal rp2_r_s, BigDecimal rp2_r_e, BigDecimal rp2_e, BigDecimal rp3_r_s, BigDecimal rp3_r_e, BigDecimal rp3_e, BigDecimal rp_r_s, BigDecimal rp_r_e, BigDecimal rp_e, BigDecimal factor_s, BigDecimal factor_e, BigDecimal pap_demand_e, String pap_demand_time_e, BigDecimal pap_demand_s, String pap_demand_time_s, String cons_sort, BigDecimal calc_mode, BigDecimal mp_sn, BigDecimal ins_flag, String ins_date, String staff_no, BigDecimal gpq, BigDecimal ppq, BigDecimal spq, BigDecimal gpq_repair, BigDecimal ppq_repair, BigDecimal spq_repair, BigDecimal both_meas, BigDecimal mp_level, BigDecimal t_factor, BigDecimal ori_pap_e, BigDecimal ori_pap_e1, BigDecimal ori_pap_e2, BigDecimal ori_pap_e3, BigDecimal ori_pap_e4, BigDecimal ori_prp_e, BigDecimal ori_rap_e, BigDecimal ori_rap_e1, BigDecimal ori_rap_e2, BigDecimal ori_rap_e3, BigDecimal ori_rap_e4, BigDecimal ori_rrp_e, BigDecimal ori_rp1_e, BigDecimal orirp4_e, BigDecimal ori_rp2_e, BigDecimal ori_rp3_e, String mark, BigDecimal meter_id, BigDecimal contract_cap, BigDecimal fc_gc_flag, BigDecimal ori_rp4_e, String op_type, String op_time, String cur_time) {
this.id = id;
this.area_code = area_code;
this.org_no = org_no;
this.cons_no = cons_no;
this.tmnl_asset_no = tmnl_asset_no;
this.asset_no = asset_no;
this.mp_type = mp_type;
this.data_src = data_src;
this.stat_date = stat_date;
this.pt = pt;
this.ct = ct;
this.self_factor = self_factor;
this.pap_r_s = pap_r_s;
this.pap_r_e = pap_r_e;
this.pap_e = pap_e;
this.pap_r1_s = pap_r1_s;
this.pap_r1_e = pap_r1_e;
this.pap_e1 = pap_e1;
this.pap_r2_s = pap_r2_s;
this.pap_r2_e = pap_r2_e;
this.pap_e2 = pap_e2;
this.pap_r3_s = pap_r3_s;
this.pap_r3_e = pap_r3_e;
this.pap_e3 = pap_e3;
this.pap_r4_s = pap_r4_s;
this.pap_r4_e = pap_r4_e;
this.pap_e4 = pap_e4;
this.rap_r_s = rap_r_s;
this.rap_r_e = rap_r_e;
this.rap_e = rap_e;
this.rap_r1_s = rap_r1_s;
this.rap_r1_e = rap_r1_e;
this.rap_e1 = rap_e1;
this.rap_r2_s = rap_r2_s;
this.rap_r2_e = rap_r2_e;
this.rap_e2 = rap_e2;
this.rap_r3_s = rap_r3_s;
this.rap_r3_e = rap_r3_e;
this.rap_e3 = rap_e3;
this.rap_r4_s = rap_r4_s;
this.rap_r4_e = rap_r4_e;
this.rap_e4 = rap_e4;
this.prp_r_s = prp_r_s;
this.prp_r_e = prp_r_e;
this.prp_e = prp_e;
this.rrp_r_s = rrp_r_s;
this.rrp_r_e = rrp_r_e;
this.rrp_e = rrp_e;
this.rp1_r_s = rp1_r_s;
this.rp1_r_e = rp1_r_e;
this.rp1_e = rp1_e;
this.rp4_r_s = rp4_r_s;
this.rp4_r_e = rp4_r_e;
this.rp4_e = rp4_e;
this.rp2_r_s = rp2_r_s;
this.rp2_r_e = rp2_r_e;
this.rp2_e = rp2_e;
this.rp3_r_s = rp3_r_s;
this.rp3_r_e = rp3_r_e;
this.rp3_e = rp3_e;
this.rp_r_s = rp_r_s;
this.rp_r_e = rp_r_e;
this.rp_e = rp_e;
this.factor_s = factor_s;
this.factor_e = factor_e;
this.pap_demand_e = pap_demand_e;
this.pap_demand_time_e = pap_demand_time_e;
this.pap_demand_s = pap_demand_s;
this.pap_demand_time_s = pap_demand_time_s;
this.cons_sort = cons_sort;
this.calc_mode = calc_mode;
this.mp_sn = mp_sn;
this.ins_flag = ins_flag;
this.ins_date = ins_date;
this.staff_no = staff_no;
this.gpq = gpq;
this.ppq = ppq;
this.spq = spq;
this.gpq_repair = gpq_repair;
this.ppq_repair = ppq_repair;
this.spq_repair = spq_repair;
this.both_meas = both_meas;
this.mp_level = mp_level;
this.t_factor = t_factor;
this.ori_pap_e = ori_pap_e;
this.ori_pap_e1 = ori_pap_e1;
this.ori_pap_e2 = ori_pap_e2;
this.ori_pap_e3 = ori_pap_e3;
this.ori_pap_e4 = ori_pap_e4;
this.ori_prp_e = ori_prp_e;
this.ori_rap_e = ori_rap_e;
this.ori_rap_e1 = ori_rap_e1;
this.ori_rap_e2 = ori_rap_e2;
this.ori_rap_e3 = ori_rap_e3;
this.ori_rap_e4 = ori_rap_e4;
this.ori_rrp_e = ori_rrp_e;
this.ori_rp1_e = ori_rp1_e;
this.orirp4_e = orirp4_e;
this.ori_rp2_e = ori_rp2_e;
this.ori_rp3_e = ori_rp3_e;
this.mark = mark;
this.meter_id = meter_id;
this.contract_cap = contract_cap;
this.fc_gc_flag = fc_gc_flag;
this.ori_rp4_e = ori_rp4_e;
this.op_type = op_type;
this.op_time = op_time;
this.cur_time = cur_time;
}
public BigDecimal getId() {
return id;
}
public String getArea_code() {
return area_code;
}
public String getOrg_no() {
return org_no;
}
public String getCons_no() {
return cons_no;
}
public String getTmnl_asset_no() {
return tmnl_asset_no;
}
public String getAsset_no() {
return asset_no;
}
public BigDecimal getMp_type() {
return mp_type;
}
public String getData_src() {
return data_src;
}
public String getStat_date() {
return stat_date;
}
public BigDecimal getPt() {
return pt;
}
public BigDecimal getCt() {
return ct;
}
public BigDecimal getSelf_factor() {
return self_factor;
}
public BigDecimal getPap_r_s() {
return pap_r_s;
}
public BigDecimal getPap_r_e() {
return pap_r_e;
}
public BigDecimal getPap_e() {
return pap_e;
}
public BigDecimal getPap_r1_s() {
return pap_r1_s;
}
public BigDecimal getPap_r1_e() {
return pap_r1_e;
}
public BigDecimal getPap_e1() {
return pap_e1;
}
public BigDecimal getPap_r2_s() {
return pap_r2_s;
}
public BigDecimal getPap_r2_e() {
return pap_r2_e;
}
public BigDecimal getPap_e2() {
return pap_e2;
}
public BigDecimal getPap_r3_s() {
return pap_r3_s;
}
public BigDecimal getPap_r3_e() {
return pap_r3_e;
}
public BigDecimal getPap_e3() {
return pap_e3;
}
public BigDecimal getPap_r4_s() {
return pap_r4_s;
}
public BigDecimal getPap_r4_e() {
return pap_r4_e;
}
public BigDecimal getPap_e4() {
return pap_e4;
}
public BigDecimal getRap_r_s() {
return rap_r_s;
}
public BigDecimal getRap_r_e() {
return rap_r_e;
}
public BigDecimal getRap_e() {
return rap_e;
}
public BigDecimal getRap_r1_s() {
return rap_r1_s;
}
public BigDecimal getRap_r1_e() {
return rap_r1_e;
}
public BigDecimal getRap_e1() {
return rap_e1;
}
public BigDecimal getRap_r2_s() {
return rap_r2_s;
}
public BigDecimal getRap_r2_e() {
return rap_r2_e;
}
public BigDecimal getRap_e2() {
return rap_e2;
}
public BigDecimal getRap_r3_s() {
return rap_r3_s;
}
public BigDecimal getRap_r3_e() {
return rap_r3_e;
}
public BigDecimal getRap_e3() {
return rap_e3;
}
public BigDecimal getRap_r4_s() {
return rap_r4_s;
}
public BigDecimal getRap_r4_e() {
return rap_r4_e;
}
public BigDecimal getRap_e4() {
return rap_e4;
}
public BigDecimal getPrp_r_s() {
return prp_r_s;
}
public BigDecimal getPrp_r_e() {
return prp_r_e;
}
public BigDecimal getPrp_e() {
return prp_e;
}
public BigDecimal getRrp_r_s() {
return rrp_r_s;
}
public BigDecimal getRrp_r_e() {
return rrp_r_e;
}
public BigDecimal getRrp_e() {
return rrp_e;
}
public BigDecimal getRp1_r_s() {
return rp1_r_s;
}
public BigDecimal getRp1_r_e() {
return rp1_r_e;
}
public BigDecimal getRp1_e() {
return rp1_e;
}
public BigDecimal getRp4_r_s() {
return rp4_r_s;
}
public BigDecimal getRp4_r_e() {
return rp4_r_e;
}
public BigDecimal getRp4_e() {
return rp4_e;
}
public BigDecimal getRp2_r_s() {
return rp2_r_s;
}
public BigDecimal getRp2_r_e() {
return rp2_r_e;
}
public BigDecimal getRp2_e() {
return rp2_e;
}
public BigDecimal getRp3_r_s() {
return rp3_r_s;
}
public BigDecimal getRp3_r_e() {
return rp3_r_e;
}
public BigDecimal getRp3_e() {
return rp3_e;
}
public BigDecimal getRp_r_s() {
return rp_r_s;
}
public BigDecimal getRp_r_e() {
return rp_r_e;
}
public BigDecimal getRp_e() {
return rp_e;
}
public BigDecimal getFactor_s() {
return factor_s;
}
public BigDecimal getFactor_e() {
return factor_e;
}
public BigDecimal getPap_demand_e() {
return pap_demand_e;
}
public String getPap_demand_time_e() {
return pap_demand_time_e;
}
public BigDecimal getPap_demand_s() {
return pap_demand_s;
}
public String getPap_demand_time_s() {
return pap_demand_time_s;
}
public String getCons_sort() {
return cons_sort;
}
public BigDecimal getCalc_mode() {
return calc_mode;
}
public BigDecimal getMp_sn() {
return mp_sn;
}
public BigDecimal getIns_flag() {
return ins_flag;
}
public String getIns_date() {
return ins_date;
}
public String getStaff_no() {
return staff_no;
}
public BigDecimal getGpq() {
return gpq;
}
public BigDecimal getPpq() {
return ppq;
}
public BigDecimal getSpq() {
return spq;
}
public BigDecimal getGpq_repair() {
return gpq_repair;
}
public BigDecimal getPpq_repair() {
return ppq_repair;
}
public BigDecimal getSpq_repair() {
return spq_repair;
}
public BigDecimal getBoth_meas() {
return both_meas;
}
public BigDecimal getMp_level() {
return mp_level;
}
public BigDecimal getT_factor() {
return t_factor;
}
public BigDecimal getOri_pap_e() {
return ori_pap_e;
}
public BigDecimal getOri_pap_e1() {
return ori_pap_e1;
}
public BigDecimal getOri_pap_e2() {
return ori_pap_e2;
}
public BigDecimal getOri_pap_e3() {
return ori_pap_e3;
}
public BigDecimal getOri_pap_e4() {
return ori_pap_e4;
}
public BigDecimal getOri_prp_e() {
return ori_prp_e;
}
public BigDecimal getOri_rap_e() {
return ori_rap_e;
}
public BigDecimal getOri_rap_e1() {
return ori_rap_e1;
}
public BigDecimal getOri_rap_e2() {
return ori_rap_e2;
}
public BigDecimal getOri_rap_e3() {
return ori_rap_e3;
}
public BigDecimal getOri_rap_e4() {
return ori_rap_e4;
}
public BigDecimal getOri_rrp_e() {
return ori_rrp_e;
}
public BigDecimal getOri_rp1_e() {
return ori_rp1_e;
}
public BigDecimal getOrirp4_e() {
return orirp4_e;
}
public BigDecimal getOri_rp2_e() {
return ori_rp2_e;
}
public BigDecimal getOri_rp3_e() {
return ori_rp3_e;
}
public String getMark() {
return mark;
}
public BigDecimal getMeter_id() {
return meter_id;
}
public BigDecimal getContract_cap() {
return contract_cap;
}
public BigDecimal getFc_gc_flag() {
return fc_gc_flag;
}
public BigDecimal getOri_rp4_e() {
return ori_rp4_e;
}
public String getOp_type() {
return op_type;
}
public String getOp_time() {
return op_time;
}
public String getCur_time() {
return cur_time;
}
@Override
public String toString() {
return "A_calc_day_power{" +
"id=" + id +
", area_code='" + area_code + '\'' +
", org_no='" + org_no + '\'' +
", cons_no='" + cons_no + '\'' +
", tmnl_asset_no='" + tmnl_asset_no + '\'' +
", asset_no='" + asset_no + '\'' +
", mp_type=" + mp_type +
", data_src='" + data_src + '\'' +
", stat_date='" + stat_date + '\'' +
", pt=" + pt +
", ct=" + ct +
", self_factor=" + self_factor +
", pap_r_s=" + pap_r_s +
", pap_r_e=" + pap_r_e +
", pap_e=" + pap_e +
", pap_r1_s=" + pap_r1_s +
", pap_r1_e=" + pap_r1_e +
", pap_e1=" + pap_e1 +
", pap_r2_s=" + pap_r2_s +
", pap_r2_e=" + pap_r2_e +
", pap_e2=" + pap_e2 +
", pap_r3_s=" + pap_r3_s +
", pap_r3_e=" + pap_r3_e +
", pap_e3=" + pap_e3 +
", pap_r4_s=" + pap_r4_s +
", pap_r4_e=" + pap_r4_e +
", pap_e4=" + pap_e4 +
", rap_r_s=" + rap_r_s +
", rap_r_e=" + rap_r_e +
", rap_e=" + rap_e +
", rap_r1_s=" + rap_r1_s +
", rap_r1_e=" + rap_r1_e +
", rap_e1=" + rap_e1 +
", rap_r2_s=" + rap_r2_s +
", rap_r2_e=" + rap_r2_e +
", rap_e2=" + rap_e2 +
", rap_r3_s=" + rap_r3_s +
", rap_r3_e=" + rap_r3_e +
", rap_e3=" + rap_e3 +
", rap_r4_s=" + rap_r4_s +
", rap_r4_e=" + rap_r4_e +
", rap_e4=" + rap_e4 +
", prp_r_s=" + prp_r_s +
", prp_r_e=" + prp_r_e +
", prp_e=" + prp_e +
", rrp_r_s=" + rrp_r_s +
", rrp_r_e=" + rrp_r_e +
", rrp_e=" + rrp_e +
", rp1_r_s=" + rp1_r_s +
", rp1_r_e=" + rp1_r_e +
", rp1_e=" + rp1_e +
", rp4_r_s=" + rp4_r_s +
", rp4_r_e=" + rp4_r_e +
", rp4_e=" + rp4_e +
", rp2_r_s=" + rp2_r_s +
", rp2_r_e=" + rp2_r_e +
", rp2_e=" + rp2_e +
", rp3_r_s=" + rp3_r_s +
", rp3_r_e=" + rp3_r_e +
", rp3_e=" + rp3_e +
", rp_r_s=" + rp_r_s +
", rp_r_e=" + rp_r_e +
", rp_e=" + rp_e +
", factor_s=" + factor_s +
", factor_e=" + factor_e +
", pap_demand_e=" + pap_demand_e +
", pap_demand_time_e='" + pap_demand_time_e + '\'' +
", pap_demand_s=" + pap_demand_s +
", pap_demand_time_s='" + pap_demand_time_s + '\'' +
", cons_sort='" + cons_sort + '\'' +
", calc_mode=" + calc_mode +
", mp_sn=" + mp_sn +
", ins_flag=" + ins_flag +
", ins_date='" + ins_date + '\'' +
", staff_no='" + staff_no + '\'' +
", gpq=" + gpq +
", ppq=" + ppq +
", spq=" + spq +
", gpq_repair=" + gpq_repair +
", ppq_repair=" + ppq_repair +
", spq_repair=" + spq_repair +
", both_meas=" + both_meas +
", mp_level=" + mp_level +
", t_factor=" + t_factor +
", ori_pap_e=" + ori_pap_e +
", ori_pap_e1=" + ori_pap_e1 +
", ori_pap_e2=" + ori_pap_e2 +
", ori_pap_e3=" + ori_pap_e3 +
", ori_pap_e4=" + ori_pap_e4 +
", ori_prp_e=" + ori_prp_e +
", ori_rap_e=" + ori_rap_e +
", ori_rap_e1=" + ori_rap_e1 +
", ori_rap_e2=" + ori_rap_e2 +
", ori_rap_e3=" + ori_rap_e3 +
", ori_rap_e4=" + ori_rap_e4 +
", ori_rrp_e=" + ori_rrp_e +
", ori_rp1_e=" + ori_rp1_e +
", orirp4_e=" + orirp4_e +
", ori_rp2_e=" + ori_rp2_e +
", ori_rp3_e=" + ori_rp3_e +
", mark='" + mark + '\'' +
", meter_id=" + meter_id +
", contract_cap=" + contract_cap +
", fc_gc_flag=" + fc_gc_flag +
", ori_rp4_e=" + ori_rp4_e +
", op_type='" + op_type + '\'' +
", op_time='" + op_time + '\'' +
", cur_time='" + cur_time + '\'' +
'}';
}
}
二/读取kafka数据信息,解析成自定义类可以接收的形式
package cn.com.mycompany.InsertAndUpdate.a_calc_day_power;
import cn.com.mycompany.InsertAndUpdate.e_mp_cur_curve.E_mp_cur_curve;
import cn.com.mycompany.my.util.FinalID;
import cn.com.mycompany.my.util.PropertyUtil;
import cn.com.mycompany.my.util.isBigDecimal;
import org.apache.commons.lang3.StringUtils;
import org.apache.flink.api.common.functions.FilterFunction;
import org.apache.flink.api.common.functions.MapFunction;
import org.apache.flink.api.common.restartstrategy.RestartStrategies;
import org.apache.flink.streaming.api.datastream.DataStream;
import org.apache.flink.streaming.api.environment.StreamExecutionEnvironment;
import org.apache.flink.streaming.connectors.kafka.FlinkKafkaConsumer08;
import org.apache.flink.streaming.util.serialization.SimpleStringSchema;
import java.math.BigDecimal;
import java.text.SimpleDateFormat;
import java.util.Properties;
//import org.springframework.stereotype.Component;
/**
* @author 杨迎春
* kafka to A_CALC_DAY_POWER 表
*/
//@Component
public class KafkaToA_calc_day_power {
//@PostConstruct
public static void main(String[] args) {
System.out.println("================kafka to sync_A_CALC_DAY_POWER start============");
Properties pro = new Properties();
pro.put("bootstrap.servers", PropertyUtil.get("kafka.hosts"));
pro.put("zookeeper.connect", PropertyUtil.get("kafka.zookper"));
pro.put("group.id", PropertyUtil.get("kafka.group"));
StreamExecutionEnvironment env = StreamExecutionEnvironment.getExecutionEnvironment();
env.getConfig().disableSysoutLogging();
env.getConfig().setRestartStrategy(RestartStrategies.fixedDelayRestart(4, 10000));
env.enableCheckpointing(5000);
final DataStream sourceStream = env.addSource(
new FlinkKafkaConsumer08(PropertyUtil.get("kafka.topic_A_CALC_DAY_POWER"),new SimpleStringSchema(), pro));
DataStream
sourceStreamTra = sourceStream
.filter(new FilterFunction() {
public boolean filter(String value) throws Exception {
return StringUtils.isNotBlank(value)
&&value.split("\t").length==108
&&(value.split("\t")[3].equals(FinalID.id1)
||value.split("\t")[3].equals(FinalID.id2))
||(value.split("\t")[3].equals(FinalID.id3))
||(value.split("\t")[3].equals(FinalID.id4))
||(value.split("\t")[3].equals(FinalID.id5))
||(value.split("\t")[3].equals(FinalID.id6))
||(value.split("\t")[3].equals(FinalID.id7))
||(value.split("\t")[3].equals(FinalID.id8))
||(value.split("\t")[3].equals(FinalID.id9))
||(value.split("\t")[3].equals(FinalID.id10))
||(value.split("\t")[3].equals(FinalID.id11))
||(value.split("\t")[3].equals(FinalID.id12));
}
}).map(new MapFunction() {
private static final long serialVersionUID = 1L;
public A_calc_day_power map(String value) throws Exception {
String[] args = value.split("\t");
SimpleDateFormat f=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
return new A_calc_day_power(
isBigDecimal.isbigdecimal(args[3].trim())?new BigDecimal(args[3]):null,
args[4].equals("NULL") ? null : args[4].trim(),
args[5].equals("NULL") ? null : args[5].trim(),
args[6].equals("NULL") ? null : args[6].trim(),
args[7].equals("NULL") ? null : args[7].trim(),
args[8].equals("NULL") ? null : args[8].trim(),
isBigDecimal.isbigdecimal(args[9])?new BigDecimal(args[9]):null,
args[10].equals("NULL") ? null : args[10].trim(),
args[11].equals("NULL") ? null : args[11].trim(),
isBigDecimal.isbigdecimal(args[12])?new BigDecimal(args[12]):null,
isBigDecimal.isbigdecimal(args[13])?new BigDecimal(args[13]):null,
isBigDecimal.isbigdecimal(args[14])?new BigDecimal(args[14]):null,
isBigDecimal.isbigdecimal(args[15])?new BigDecimal(args[15]):null,
isBigDecimal.isbigdecimal(args[16])?new BigDecimal(args[16]):null,
isBigDecimal.isbigdecimal(args[17])?new BigDecimal(args[17]):null,
isBigDecimal.isbigdecimal(args[18])?new BigDecimal(args[18]):null,
isBigDecimal.isbigdecimal(args[19])?new BigDecimal(args[19]):null,
isBigDecimal.isbigdecimal(args[20])?new BigDecimal(args[20]):null,
isBigDecimal.isbigdecimal(args[21])?new BigDecimal(args[21]):null,
isBigDecimal.isbigdecimal(args[22])?new BigDecimal(args[22]):null,
isBigDecimal.isbigdecimal(args[23])?new BigDecimal(args[23]):null,
isBigDecimal.isbigdecimal(args[24])?new BigDecimal(args[24]):null,
isBigDecimal.isbigdecimal(args[25])?new BigDecimal(args[25]):null,
isBigDecimal.isbigdecimal(args[26])?new BigDecimal(args[26]):null,
isBigDecimal.isbigdecimal(args[27])?new BigDecimal(args[27]):null,
isBigDecimal.isbigdecimal(args[28])?new BigDecimal(args[28]):null,
isBigDecimal.isbigdecimal(args[29])?new BigDecimal(args[29]):null,
isBigDecimal.isbigdecimal(args[30])?new BigDecimal(args[30]):null,
isBigDecimal.isbigdecimal(args[31])?new BigDecimal(args[31]):null,
isBigDecimal.isbigdecimal(args[32])?new BigDecimal(args[32]):null,
isBigDecimal.isbigdecimal(args[33])?new BigDecimal(args[33]):null,
isBigDecimal.isbigdecimal(args[34])?new BigDecimal(args[34]):null,
isBigDecimal.isbigdecimal(args[35])?new BigDecimal(args[35]):null,
isBigDecimal.isbigdecimal(args[36])?new BigDecimal(args[36]):null,
isBigDecimal.isbigdecimal(args[37])?new BigDecimal(args[37]):null,
isBigDecimal.isbigdecimal(args[38])?new BigDecimal(args[38]):null,
isBigDecimal.isbigdecimal(args[39])?new BigDecimal(args[39]):null,
isBigDecimal.isbigdecimal(args[40])?new BigDecimal(args[40]):null,
isBigDecimal.isbigdecimal(args[41])?new BigDecimal(args[41]):null,
isBigDecimal.isbigdecimal(args[42])?new BigDecimal(args[42]):null,
isBigDecimal.isbigdecimal(args[43])?new BigDecimal(args[43]):null,
isBigDecimal.isbigdecimal(args[44])?new BigDecimal(args[44]):null,
isBigDecimal.isbigdecimal(args[45])?new BigDecimal(args[45]):null,
isBigDecimal.isbigdecimal(args[46])?new BigDecimal(args[46]):null,
isBigDecimal.isbigdecimal(args[47])?new BigDecimal(args[47]):null,
isBigDecimal.isbigdecimal(args[48])?new BigDecimal(args[48]):null,
isBigDecimal.isbigdecimal(args[49])?new BigDecimal(args[49]):null,
isBigDecimal.isbigdecimal(args[50])?new BigDecimal(args[50]):null,
isBigDecimal.isbigdecimal(args[51])?new BigDecimal(args[51]):null,
isBigDecimal.isbigdecimal(args[52])?new BigDecimal(args[52]):null,
isBigDecimal.isbigdecimal(args[53])?new BigDecimal(args[53]):null,
isBigDecimal.isbigdecimal(args[54])?new BigDecimal(args[54]):null,
isBigDecimal.isbigdecimal(args[55])?new BigDecimal(args[55]):null,
isBigDecimal.isbigdecimal(args[56])?new BigDecimal(args[56]):null,
isBigDecimal.isbigdecimal(args[57])?new BigDecimal(args[57]):null,
isBigDecimal.isbigdecimal(args[58])?new BigDecimal(args[58]):null,
isBigDecimal.isbigdecimal(args[59])?new BigDecimal(args[59]):null,
isBigDecimal.isbigdecimal(args[60])?new BigDecimal(args[60]):null,
isBigDecimal.isbigdecimal(args[61])?new BigDecimal(args[61]):null,
isBigDecimal.isbigdecimal(args[62])?new BigDecimal(args[62]):null,
isBigDecimal.isbigdecimal(args[63])?new BigDecimal(args[63]):null,
isBigDecimal.isbigdecimal(args[64])?new BigDecimal(args[64]):null,
isBigDecimal.isbigdecimal(args[65])?new BigDecimal(args[65]):null,
isBigDecimal.isbigdecimal(args[66])?new BigDecimal(args[66]):null,
isBigDecimal.isbigdecimal(args[67])?new BigDecimal(args[67]):null,
isBigDecimal.isbigdecimal(args[68])?new BigDecimal(args[68]):null,
args[69].equals("NULL") ? null : args[69].trim(),
isBigDecimal.isbigdecimal(args[70])?new BigDecimal(args[70]):null,
args[71].equals("NULL") ? null : args[71].trim(),
args[72].equals("NULL") ? null : args[72].trim(),
isBigDecimal.isbigdecimal(args[73])?new BigDecimal(args[73]):null,
isBigDecimal.isbigdecimal(args[74])?new BigDecimal(args[74]):null,
isBigDecimal.isbigdecimal(args[75])?new BigDecimal(args[75]):null,
args[76].equals("NULL") ? null : args[76].trim(),
args[77].equals("NULL") ? null : args[77].trim(),
isBigDecimal.isbigdecimal(args[78])?new BigDecimal(args[78]):null,
isBigDecimal.isbigdecimal(args[79])?new BigDecimal(args[79]):null,
isBigDecimal.isbigdecimal(args[80])?new BigDecimal(args[80]):null,
isBigDecimal.isbigdecimal(args[81])?new BigDecimal(args[81]):null,
isBigDecimal.isbigdecimal(args[82])?new BigDecimal(args[82]):null,
isBigDecimal.isbigdecimal(args[83])?new BigDecimal(args[83]):null,
isBigDecimal.isbigdecimal(args[84])?new BigDecimal(args[84]):null,
isBigDecimal.isbigdecimal(args[85])?new BigDecimal(args[85]):null,
isBigDecimal.isbigdecimal(args[86])?new BigDecimal(args[86]):null,
isBigDecimal.isbigdecimal(args[87])?new BigDecimal(args[87]):null,
isBigDecimal.isbigdecimal(args[88])?new BigDecimal(args[88]):null,
isBigDecimal.isbigdecimal(args[89])?new BigDecimal(args[89]):null,
isBigDecimal.isbigdecimal(args[90])?new BigDecimal(args[90]):null,
isBigDecimal.isbigdecimal(args[91])?new BigDecimal(args[91]):null,
isBigDecimal.isbigdecimal(args[92])?new BigDecimal(args[92]):null,
isBigDecimal.isbigdecimal(args[93])?new BigDecimal(args[93]):null,
isBigDecimal.isbigdecimal(args[94])?new BigDecimal(args[94]):null,
isBigDecimal.isbigdecimal(args[95])?new BigDecimal(args[95]):null,
isBigDecimal.isbigdecimal(args[96])?new BigDecimal(args[96]):null,
isBigDecimal.isbigdecimal(args[97])?new BigDecimal(args[97]):null,
isBigDecimal.isbigdecimal(args[98])?new BigDecimal(args[98]):null,
isBigDecimal.isbigdecimal(args[99])?new BigDecimal(args[99]):null,
isBigDecimal.isbigdecimal(args[100])?new BigDecimal(args[100]):null,
isBigDecimal.isbigdecimal(args[101])?new BigDecimal(args[101]):null,
isBigDecimal.isbigdecimal(args[102])?new BigDecimal(args[102]):null,
args[103].equals("NULL") ? null : args[103].trim(),
isBigDecimal.isbigdecimal(args[104])?new BigDecimal(args[104]):null,
isBigDecimal.isbigdecimal(args[105])?new BigDecimal(args[105]):null,
isBigDecimal.isbigdecimal(args[106])?new BigDecimal(args[106]):null,
isBigDecimal.isbigdecimal(args[107])?new BigDecimal(args[107]):null,
args[0].equals("NULL") ? null : args[0].trim(),
args[1].equals("NULL") ? null : args[1].trim(),
args[2].equals("NULL") ? null : args[2].trim()
);
}
});
System.out.println("===============!数据拉取成功标志!===============");
sourceStreamTra.addSink(new A_calc_day_powerSink());
try {
env.execute("data to sync_E_mp_cur_curve start");
} catch (Exception e) {
e.printStackTrace();
}
}
}
三/自定义oracleSink
package cn.com.mycompany.InsertAndUpdate.a_calc_day_power;
import cn.com.mycompany.InsertAndUpdate.e_mp_cur_curve.E_mp_cur_curve;
import cn.com.mycompany.InsertAndUpdate.utils.PreparedStatementProcess;
import cn.com.mycompany.my.util.PropertyUtil;
import cn.com.mycompany.my.util.isDateRight;
import org.apache.flink.streaming.api.functions.sink.RichSinkFunction;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.SQLException;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
public class A_calc_day_powerSink extends RichSinkFunction {
private static final long serialVersionUID = 1L;
private Connection connection;
private PreparedStatement preparedStatement;
String username = PropertyUtil.get("oracle.user");
String password = PropertyUtil.get("oracle.pwd");;
String drivername = PropertyUtil.get("oracle.driver");
String dburl = PropertyUtil.get("oracle.url");
private int rows =0;
@Override
public void invoke(A_calc_day_power a_calc_day_power) throws Exception {
Class.forName(drivername);
connection = DriverManager.getConnection(dburl, username, password);
insert(preparedStatement,connection,a_calc_day_power);
// I为新插入数据
if (a_calc_day_power.getOp_type().equals("I")){
insert(preparedStatement,connection,a_calc_day_power);
//U需找道对应的时间点和id,先删除再插入新的数据
}else if(a_calc_day_power.getOp_type().equals("U")){
PreparedStatementProcess.delete(preparedStatement,connection,a_calc_day_power);
insert(this.preparedStatement,connection,a_calc_day_power);
//即D找到对应时间点和id,删除该数据
}else{
PreparedStatementProcess.delete(preparedStatement,connection,a_calc_day_power);
}
if (preparedStatement != null) {
preparedStatement.close();
}
if (connection != null) {
connection.close();
}
}
public static void insert(PreparedStatement preparedStatement,
Connection connection,
A_calc_day_power a_calc_day_power){
try {
String sql = "insert into JBBDKF.SYNC_YX_A_CALC_DAY_POWER(" +
"id,area_code,org_no,cons_no,tmnl_asset_no,\n" +
"asset_no,mp_type,data_src,stat_date,pt,\n" +
"ct,self_factor,pap_r_s,pap_r_e,pap_e,\n" +
"pap_r1_s,pap_r1_e,pap_e1,pap_r2_s,pap_r2_e,\n" +
"pap_e2,pap_r3_s,pap_r3_e,pap_e3,pap_r4_s,\n" +
"pap_r4_e,pap_e4,rap_r_s,rap_r_e,rap_e,\n" +
"rap_r1_s,rap_r1_e,rap_e1,rap_r2_s,rap_r2_e,\n" +
"rap_e2,rap_r3_s,rap_r3_e,rap_e3,rap_r4_s,\n" +
"rap_r4_e,rap_e4,prp_r_s,prp_r_e,prp_e,\n" +
"rrp_r_s,rrp_r_e,rrp_e,rp1_r_s,rp1_r_e,\n" +
"rp1_e,rp4_r_s,rp4_r_e,rp4_e,rp2_r_s,\n" +
"rp2_r_e,rp2_e,rp3_r_s,rp3_r_e,rp3_e,\n" +
"rp_r_s,rp_r_e,rp_e,factor_s,factor_e,\n" +
"pap_demand_e,pap_demand_time_e,pap_demand_s,pap_demand_time_s,cons_sort,\n" +
"calc_mode,mp_sn,ins_flag,ins_date,staff_no,\n" +
"gpq,ppq,spq,gpq_repair,ppq_repair,\n" +
"spq_repair,both_meas,mp_level,t_factor,ori_pap_e,\n" +
"ori_pap_e1,ori_pap_e2,ori_pap_e3,ori_pap_e4,ori_prp_e,\n" +
"ori_rap_e,ori_rap_e1,ori_rap_e2,ori_rap_e3,ori_rap_e4,\n" +
"ori_rrp_e,ori_rp1_e,orirp4_e,ori_rp2_e,ori_rp3_e,\n" +
"mark,meter_id,contract_cap,fc_gc_flag,ori_rp4_e,\n" +
"op_type,op_time,cur_time) " +
"values(?,?,?,?,?,?,?,?,?,?," +
"?,?,?,?,?,?,?,?,?,?," +
"?,?,?,?,?,?,?,?,?,?," +
"?,?,?,?,?,?,?,?,?,?," +
"?,?,?,?,?,?,?,?,?,?," +
"?,?,?,?,?,?,?,?,?,?," +
"?,?,?,?,?,?,?,?,?,?," +
"?,?,?,?,?,?,?,?,?,?," +
"?,?,?,?,?,?,?,?,?,?," +
"?,?,?,?,?,?,?,?,?,?," +
"?,?,?,?,?,?," +
"?,?)";
SimpleDateFormat sDateFormat=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
preparedStatement = connection.prepareStatement(sql);
preparedStatement.setBigDecimal(1,a_calc_day_power.getId());
preparedStatement.setString(2,a_calc_day_power.getArea_code());
preparedStatement.setString(3,a_calc_day_power.getOrg_no());
preparedStatement.setString(4,a_calc_day_power.getCons_no());
preparedStatement.setString(5,a_calc_day_power.getTmnl_asset_no());
preparedStatement.setString(6,a_calc_day_power.getAsset_no());
preparedStatement.setBigDecimal(7,a_calc_day_power.getMp_type());
preparedStatement.setString(8,a_calc_day_power.getData_src ());
preparedStatement.setTimestamp(9,isDateRight.isDatetime(a_calc_day_power.getStat_date())?
new java.sql.Timestamp(sDateFormat.parse(a_calc_day_power.getStat_date()).getTime()):
new java.sql.Timestamp(sDateFormat.parse(sDateFormat.format(new Date())).getTime()));
preparedStatement.setBigDecimal(10,a_calc_day_power.getPt());
preparedStatement.setBigDecimal(11,a_calc_day_power.getCt());
preparedStatement.setBigDecimal(12,a_calc_day_power.getSelf_factor());
preparedStatement.setBigDecimal(13,a_calc_day_power.getPap_r_s());
preparedStatement.setBigDecimal(14,a_calc_day_power.getPap_r_e());
preparedStatement.setBigDecimal(15,a_calc_day_power.getPap_e ());
preparedStatement.setBigDecimal(16,a_calc_day_power.getPap_r1_s());
preparedStatement.setBigDecimal(17,a_calc_day_power.getPap_r1_e());
preparedStatement.setBigDecimal(18,a_calc_day_power.getPap_e1 ());
preparedStatement.setBigDecimal(19,a_calc_day_power.getPap_r2_s());
preparedStatement.setBigDecimal(20,a_calc_day_power.getPap_r2_e());
preparedStatement.setBigDecimal(21,a_calc_day_power.getPap_e2 ());
preparedStatement.setBigDecimal(22,a_calc_day_power.getPap_r3_s());
preparedStatement.setBigDecimal(23,a_calc_day_power.getPap_r3_e());
preparedStatement.setBigDecimal(24,a_calc_day_power.getPap_e3 ());
preparedStatement.setBigDecimal(25,a_calc_day_power.getPap_r4_s());
preparedStatement.setBigDecimal(26,a_calc_day_power.getPap_r4_e());
preparedStatement.setBigDecimal(27,a_calc_day_power.getPap_e4 ());
preparedStatement.setBigDecimal(28,a_calc_day_power.getRap_r_s());
preparedStatement.setBigDecimal(29,a_calc_day_power.getRap_r_e());
preparedStatement.setBigDecimal(30,a_calc_day_power.getRap_e ());
preparedStatement.setBigDecimal(31,a_calc_day_power.getRap_r1_s());
preparedStatement.setBigDecimal(32,a_calc_day_power.getRap_r1_e());
preparedStatement.setBigDecimal(33,a_calc_day_power.getRap_e1 ());
preparedStatement.setBigDecimal(34,a_calc_day_power.getRap_r2_s());
preparedStatement.setBigDecimal(35,a_calc_day_power.getRap_r2_e());
preparedStatement.setBigDecimal(36,a_calc_day_power.getRap_e2 ());
preparedStatement.setBigDecimal(37,a_calc_day_power.getRap_r3_s());
preparedStatement.setBigDecimal(38,a_calc_day_power.getRap_r3_e());
preparedStatement.setBigDecimal(39,a_calc_day_power.getRap_e3 ());
preparedStatement.setBigDecimal(40,a_calc_day_power.getRap_r4_s());
preparedStatement.setBigDecimal(41,a_calc_day_power.getRap_r4_e());
preparedStatement.setBigDecimal(42,a_calc_day_power.getRap_e4 ());
preparedStatement.setBigDecimal(43,a_calc_day_power.getPrp_r_s());
preparedStatement.setBigDecimal(44,a_calc_day_power.getPrp_r_e());
preparedStatement.setBigDecimal(45,a_calc_day_power.getPrp_e ());
preparedStatement.setBigDecimal(46,a_calc_day_power.getRrp_r_s());
preparedStatement.setBigDecimal(47,a_calc_day_power.getRrp_r_e());
preparedStatement.setBigDecimal(48,a_calc_day_power.getRrp_e ());
preparedStatement.setBigDecimal(49,a_calc_day_power.getRp1_r_s());
preparedStatement.setBigDecimal(50,a_calc_day_power.getRp1_r_e());
preparedStatement.setBigDecimal(51,a_calc_day_power.getRp1_e ());
preparedStatement.setBigDecimal(52,a_calc_day_power.getRp4_r_s());
preparedStatement.setBigDecimal(53,a_calc_day_power.getRp4_r_e());
preparedStatement.setBigDecimal(54,a_calc_day_power.getRp4_e ());
preparedStatement.setBigDecimal(55,a_calc_day_power.getRp2_r_s());
preparedStatement.setBigDecimal(56,a_calc_day_power.getRp2_r_e());
preparedStatement.setBigDecimal(57,a_calc_day_power.getRp2_e ());
preparedStatement.setBigDecimal(58,a_calc_day_power.getRp3_r_s());
preparedStatement.setBigDecimal(59,a_calc_day_power.getRp3_r_e());
preparedStatement.setBigDecimal(60,a_calc_day_power.getRp3_e ());
preparedStatement.setBigDecimal(61,a_calc_day_power.getRp_r_s ());
preparedStatement.setBigDecimal(62,a_calc_day_power.getRp_r_e ());
preparedStatement.setBigDecimal(63,a_calc_day_power.getRp_e ());
preparedStatement.setBigDecimal(64,a_calc_day_power.getFactor_s());
preparedStatement.setBigDecimal(65,a_calc_day_power.getFactor_e());
preparedStatement.setBigDecimal(66,a_calc_day_power.getPap_demand_e());
preparedStatement.setTimestamp(67,isDateRight.isDatetime(a_calc_day_power.getPap_demand_time_e ())?
new java.sql.Timestamp(sDateFormat.parse(a_calc_day_power.getPap_demand_time_e ()).getTime()):
new java.sql.Timestamp(sDateFormat.parse(sDateFormat.format(new Date())).getTime()));
preparedStatement.setBigDecimal(68,a_calc_day_power.getPap_demand_s ());
preparedStatement.setTimestamp(69,isDateRight.isDatetime(a_calc_day_power.getPap_demand_time_s ())?
new java.sql.Timestamp(sDateFormat.parse(a_calc_day_power.getPap_demand_time_s ()).getTime()):
new java.sql.Timestamp(sDateFormat.parse(sDateFormat.format(new Date())).getTime()));
preparedStatement.setString(70,a_calc_day_power.getCons_sort());
preparedStatement.setBigDecimal(71,a_calc_day_power.getCalc_mode ());
preparedStatement.setBigDecimal(72,a_calc_day_power.getMp_sn ());
preparedStatement.setBigDecimal(73,a_calc_day_power.getIns_flag());
preparedStatement.setTimestamp(74,isDateRight.isDatetime(a_calc_day_power.getIns_date())?
new java.sql.Timestamp(sDateFormat.parse(a_calc_day_power.getIns_date ()).getTime()):
new java.sql.Timestamp(sDateFormat.parse(sDateFormat.format(new Date())).getTime()));
preparedStatement.setString(75,a_calc_day_power.getStaff_no());
preparedStatement.setBigDecimal(76,a_calc_day_power.getGpq ());
preparedStatement.setBigDecimal(77,a_calc_day_power.getPpq ());
preparedStatement.setBigDecimal(78,a_calc_day_power.getSpq ());
preparedStatement.setBigDecimal(79,a_calc_day_power.getGpq_repair ());
preparedStatement.setBigDecimal(80,a_calc_day_power.getPpq_repair ());
preparedStatement.setBigDecimal(81,a_calc_day_power.getSpq_repair ());
preparedStatement.setBigDecimal(82,a_calc_day_power.getBoth_meas ());
preparedStatement.setBigDecimal(83,a_calc_day_power.getMp_level());
preparedStatement.setBigDecimal(84,a_calc_day_power.getT_factor());
preparedStatement.setBigDecimal(85,a_calc_day_power.getOri_pap_e ());
preparedStatement.setBigDecimal(86,a_calc_day_power.getOri_pap_e1 ());
preparedStatement.setBigDecimal(87,a_calc_day_power.getOri_pap_e2 ());
preparedStatement.setBigDecimal(88,a_calc_day_power.getOri_pap_e3 ());
preparedStatement.setBigDecimal(89,a_calc_day_power.getOri_pap_e4 ());
preparedStatement.setBigDecimal(90,a_calc_day_power.getOri_prp_e ());
preparedStatement.setBigDecimal(91,a_calc_day_power.getOri_rap_e ());
preparedStatement.setBigDecimal(92,a_calc_day_power.getOri_rap_e1 ());
preparedStatement.setBigDecimal(93,a_calc_day_power.getOri_rap_e2 ());
preparedStatement.setBigDecimal(94,a_calc_day_power.getOri_rap_e3 ());
preparedStatement.setBigDecimal(95,a_calc_day_power.getOri_rap_e4 ());
preparedStatement.setBigDecimal(96,a_calc_day_power.getOri_rrp_e ());
preparedStatement.setBigDecimal(97,a_calc_day_power.getOri_rp1_e ());
preparedStatement.setBigDecimal(98,a_calc_day_power.getOrirp4_e());
preparedStatement.setBigDecimal(99,a_calc_day_power.getOri_rp2_e ());
preparedStatement.setBigDecimal(100,a_calc_day_power.getOri_rp3_e ());
preparedStatement.setString(101,a_calc_day_power.getMark());
preparedStatement.setBigDecimal(102,a_calc_day_power.getMeter_id());
preparedStatement.setBigDecimal(103,a_calc_day_power.getContract_cap ());
preparedStatement.setBigDecimal(104,a_calc_day_power.getFc_gc_flag ());
preparedStatement.setBigDecimal(105,a_calc_day_power.getOri_rp4_e ());
preparedStatement.setString(106,a_calc_day_power.getOp_type());
preparedStatement.setTimestamp(107,isDateRight.isDatetime(a_calc_day_power.getOp_time())?
new java.sql.Timestamp(sDateFormat.parse(a_calc_day_power.getOp_time()).getTime()):
new java.sql.Timestamp(sDateFormat.parse(sDateFormat.format(new Date())).getTime()));
preparedStatement.setTimestamp(108,isDateRight.isDatetime(a_calc_day_power.getCur_time())?
new java.sql.Timestamp(sDateFormat.parse(a_calc_day_power.getCur_time()).getTime()):
new java.sql.Timestamp(sDateFormat.parse(sDateFormat.format(new Date())).getTime()));
preparedStatement.executeUpdate();
} catch (SQLException e) {
e.printStackTrace();
System.out.println(a_calc_day_power);
} catch (ParseException e) {
e.printStackTrace();
System.out.println(a_calc_day_power);
}
}
}
四/工具类
package cn.com.mycompany.my.util;
import java.util.regex.Pattern;
/**
* 判断字符串是否时正确的日期格式 yyyy-MM-dd HH:mm:ss
*/
public class isDateRight {
public static Boolean isDatetime(String datetime){
if (datetime!=null){
Pattern p = Pattern.compile("^((\\d{2}(([02468][048])|([13579][26]))[\\-\\/\\s]?((((0?[13578])|(1[02]))[\\-\\/\\s]?((0?[1-9])|([1-2][0-9])|(3[01])))|(((0?[469])|(11))[\\-\\/\\s]?((0?[1-9])|([1-2][0-9])|(30)))|(0?2[\\-\\/\\s]?((0?[1-9])|([1-2][0-9])))))|(\\d{2}(([02468][1235679])|([13579][01345789]))[\\-\\/\\s]?((((0?[13578])|(1[02]))[\\-\\/\\s]?((0?[1-9])|([1-2][0-9])|(3[01])))|(((0?[469])|(11))[\\-\\/\\s]?((0?[1-9])|([1-2][0-9])|(30)))|(0?2[\\-\\/\\s]?((0?[1-9])|(1[0-9])|(2[0-8]))))))(\\s(((0?[0-9])|([1][0-9])|([2][0-4]))\\:([0-5]?[0-9])((\\s)|(\\:([0-5]?[0-9])))))?$");
return p.matcher(datetime).matches();
}else{
return false;
}
}
}
package cn.com.mycompany.my.util;
import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;
public class PropertyUtil {
public static String env = "prd";
public static Properties properties = new Properties();
static {
properties = new Properties();
InputStream in = PropertyUtil.class.getResourceAsStream("/config_"+env+".properties");
try {
properties.load(in);
} catch (IOException e) {
e.printStackTrace();
}
}
public static String get(String key){
String value = (String)properties.get(key);
return value;
}
}
package cn.com.mycompany.my.util;
import org.apache.flink.api.common.typeutils.base.BigDecComparator;
import java.math.BigDecimal;
import java.util.regex.Pattern;
public class isBigDecimal {
public static void main(String[] args) {
boolean isbigdecimal = isbigdecimal("+.99999");
System.out.println(new BigDecimal("+.999"));
System.out.println(isbigdecimal);
}
//Bigdecimal(18,5) 正负均可以
public static boolean isbigdecimal(String number){
if (number!=null&&!number.equals("")){
//正常数字
Pattern p = Pattern.compile("^(\\-|\\+)?[0-9]\\d{0,13}(\\.\\d{0,10})?$");
Pattern p2 = Pattern.compile("^(\\-|\\+)?(\\.\\d{0,10})?$");
//科学计数法
Pattern p1 = Pattern.compile("^[\\+\\-]?[\\d]+([\\.][\\d]*)?([Ee][+-]?[\\d]+)?$");
//System.out.println("number=》"+number+"是否可以转成number(22,10):"+p.matcher(number).matches());
return p.matcher(number).matches()||p1.matcher(number).matches()||p2.matcher(number).matches();
}else {
//System.out.println("number=》"+number+"是否可以转成number(22,10):"+false);
return false;
}
}
}
package cn.com.mycompany.InsertAndUpdate.utils;
import cn.com.mycompany.InsertAndUpdate.e_mp_cur_curve.E_mp_cur_curve;
import cn.com.mycompany.InsertAndUpdate.e_mp_curve.E_mp_curve;
import cn.com.mycompany.InsertAndUpdate.e_mp_curve.E_mp_curveSink;
import cn.com.mycompany.InsertAndUpdate.e_mp_day_demand.E_mp_day_demand;
import cn.com.mycompany.InsertAndUpdate.e_mp_day_istat.E_mp_day_istat;
import cn.com.mycompany.InsertAndUpdate.e_mp_day_read.E_mp_day_read;
import cn.com.mycompany.InsertAndUpdate.e_mp_day_unbalance.E_mp_day_unbalance;
import cn.com.mycompany.InsertAndUpdate.e_mp_day_vstat.E_mp_day_vstat;
import cn.com.mycompany.InsertAndUpdate.e_mp_energy_curve.E_mp_energy_curve;
import cn.com.mycompany.InsertAndUpdate.e_mp_power_curve.E_mp_power_curve;
import cn.com.mycompany.InsertAndUpdate.e_mp_read.E_mp_read;
import cn.com.mycompany.InsertAndUpdate.e_mp_read_curve.E_mp_read_curve;
import cn.com.mycompany.InsertAndUpdate.e_mp_vol_curve.E_mp_vol_curve;
import cn.com.mycompany.jibei.util.isDateRight;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
public class PreparedStatementProcess {
static SimpleDateFormat sDateFormat=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
static SimpleDateFormat s1DateFormat=new SimpleDateFormat("yyyy-MM-dd");
public static void delete(PreparedStatement preparedStatement,
Connection connection,
Object o) {
try {
String sql_d = null;
//1.E_mp_day_demand
if (o instanceof E_mp_day_demand) {
sql_d = "DELETE FROM JBBDKF.SYNC_YX_E_MP_DAY_DEMAND WHERE ID=? AND AREA_CODE=? " +
"AND TO_CHAR(DATA_DATE,'yyyy-MM-dd hh24:mi:ss')=?";
preparedStatement = connection.prepareStatement(sql_d);
preparedStatement.setBigDecimal(1, ((E_mp_day_demand) o).getId());
preparedStatement.setString(2, ((E_mp_day_demand) o).getArea_code());
preparedStatement.setString(3, isDateRight.isDatetime(((E_mp_day_demand) o).getData_date()) ?
sDateFormat.format(sDateFormat.parse(((E_mp_day_demand) o).getData_date())) :
sDateFormat.format(new Date()));
//2.E_mp_curve
} else if (o instanceof E_mp_curve) {
sql_d = "DELETE FROM JBBDKF.SYNC_YX_E_MP_CURVE WHERE ID=? AND AREA_CODE=? " +
"AND TO_CHAR(DATA_TIME,'yyyy-MM-dd hh24:mi:ss')=?";
preparedStatement = connection.prepareStatement(sql_d);
preparedStatement.setBigDecimal(1, ((E_mp_curve) o).getId());
preparedStatement.setString(2, ((E_mp_curve) o).getArea_code());
preparedStatement.setString(3, isDateRight.isDatetime(((E_mp_curve) o).getData_time()) ?
sDateFormat.format(sDateFormat.parse(((E_mp_curve) o).getData_time())) :
sDateFormat.format(new Date()));
//3.E_mp_day_istat
} else if (o instanceof E_mp_day_istat) {
sql_d = "DELETE FROM JBBDKF.SYNC_YX_E_MP_DAY_ISTAT WHERE ID=? AND AREA_CODE=? " +
"AND TO_CHAR(DATA_DATE,'yyyy-MM-dd hh24:mi:ss')=?";
preparedStatement = connection.prepareStatement(sql_d);
preparedStatement.setBigDecimal(1, ((E_mp_day_istat) o).getId());
preparedStatement.setString(2, ((E_mp_day_istat) o).getArea_code());
preparedStatement.setString(3, isDateRight.isDatetime(((E_mp_day_istat) o).getData_date()) ?
sDateFormat.format(sDateFormat.parse(((E_mp_day_istat) o).getData_date())) :
sDateFormat.format(new Date()));
//4.E_mp_day_unbalance
} else if (o instanceof E_mp_day_unbalance) {
sql_d = "DELETE FROM JBBDKF.SYNC_YX_E_MP_DAY_UNBALANCE WHERE ID=? AND AREA_CODE=? " +
"AND TO_CHAR(DATA_DATE,'yyyy-MM-dd hh24:mi:ss')=?";
preparedStatement = connection.prepareStatement(sql_d);
preparedStatement.setBigDecimal(1, ((E_mp_day_unbalance) o).getId());
preparedStatement.setString(2, ((E_mp_day_unbalance) o).getArea_code());
preparedStatement.setString(3, isDateRight.isDatetime(((E_mp_day_unbalance) o).getData_date()) ?
sDateFormat.format(sDateFormat.parse(((E_mp_day_unbalance) o).getData_date())) :
sDateFormat.format(new Date()));
//5.E_mp_energy_curve
} else if (o instanceof E_mp_energy_curve) {
sql_d = "DELETE FROM JBBDKF.SYNC_YX_E_MP_ENERGY_CURVE WHERE ID=? AND DATA_TYPE=? " +
"AND AREA_CODE=?" +
"AND TO_CHAR(DATA_DATE,'yyyy-MM-dd hh24:mi:ss')=?";
preparedStatement = connection.prepareStatement(sql_d);
preparedStatement.setBigDecimal(1, ((E_mp_energy_curve) o).getId());
preparedStatement.setBigDecimal(2, ((E_mp_energy_curve) o).getData_type());
preparedStatement.setString(3, ((E_mp_energy_curve) o).getArea_code());
preparedStatement.setString(4, isDateRight.isDatetime(((E_mp_energy_curve) o).getData_date()) ?
sDateFormat.format(sDateFormat.parse(((E_mp_energy_curve) o).getData_date())) :
sDateFormat.format(new Date()));
//6.E_mp_read
} else if (o instanceof E_mp_read) {
sql_d = "DELETE FROM JBBDKF.SYNC_YX_E_MP_READ WHERE ID=? AND AREA_CODE=? " +
"AND TO_CHAR(DATA_TIME,'yyyy-MM-dd hh24:mi:ss')=?";
preparedStatement = connection.prepareStatement(sql_d);
preparedStatement.setBigDecimal(1, ((E_mp_read) o).getId());
preparedStatement.setString(2, ((E_mp_read) o).getArea_code());
preparedStatement.setString(3, isDateRight.isDatetime(((E_mp_read) o).getData_time()) ?
sDateFormat.format(sDateFormat.parse(((E_mp_read) o).getData_time())) :
sDateFormat.format(new Date()));
//7.E_mp_read_curve
} else if (o instanceof E_mp_read_curve) {
sql_d = "DELETE FROM JBBDKF.SYNC_YX_E_MP_READ_CURVE WHERE ID=? AND DATA_TYPE=? " +
"AND AREA_CODE=?" +
"AND TO_CHAR(DATA_DATE,'yyyy-MM-dd hh24:mi:ss')=?";
preparedStatement = connection.prepareStatement(sql_d);
preparedStatement.setBigDecimal(1, ((E_mp_read_curve) o).getId());
preparedStatement.setBigDecimal(2, ((E_mp_read_curve) o).getData_type());
preparedStatement.setString(3, ((E_mp_read_curve) o).getArea_code());
preparedStatement.setString(4, isDateRight.isDatetime(((E_mp_read_curve) o).getData_date()) ?
sDateFormat.format(sDateFormat.parse(((E_mp_read_curve) o).getData_date())) :
sDateFormat.format(new Date()));
//8.E_mp_cur_curve
} else if (o instanceof E_mp_cur_curve) {
sql_d = "DELETE FROM JBBDKF.SYNC_YX_E_MP_CUR_CURVE WHERE ID=? AND PHASE_FLAG=? AND " +
"AREA_CODE=? AND TO_CHAR(DATA_DATE,'yyyy-MM-dd hh24:mi:ss')=?";
preparedStatement = connection.prepareStatement(sql_d);
preparedStatement.setBigDecimal(1, ((E_mp_cur_curve) o).getId());
preparedStatement.setBigDecimal(2, ((E_mp_cur_curve) o).getPhase_flag());
preparedStatement.setString(3, ((E_mp_cur_curve) o).getArea_code());
preparedStatement.setString(4, isDateRight.isDatetime(((E_mp_cur_curve) o).getData_date()) ?
sDateFormat.format(sDateFormat.parse(((E_mp_cur_curve) o).getData_date())) :
sDateFormat.format(new Date()));
//9.E_mp_day_read
} else if (o instanceof E_mp_day_read) {
sql_d = "DELETE FROM JBBDKF.SYNC_YX_E_MP_DAY_READ WHERE ID=? AND AREA_CODE=? " +
"AND TO_CHAR(DATA_DATE,'yyyy-MM-dd hh24:mi:ss')=?";
preparedStatement = connection.prepareStatement(sql_d);
preparedStatement.setBigDecimal(1, ((E_mp_day_read) o).getId());
preparedStatement.setString(2, ((E_mp_day_read) o).getArea_code());
preparedStatement.setString(3, isDateRight.isDatetime(((E_mp_day_read) o).getData_date()) ?
sDateFormat.format(sDateFormat.parse(((E_mp_day_read) o).getData_date())) :
sDateFormat.format(new Date()));
//10.E_mp_day_vstat
} else if (o instanceof E_mp_day_vstat) {
sql_d = "DELETE FROM JBBDKF.SYNC_YX_E_MP_DAY_VSTAT WHERE ID=? AND AREA_CODE=? " +
"AND TO_CHAR(DATA_DATE,'yyyy-MM-dd hh24:mi:ss')=?";
preparedStatement = connection.prepareStatement(sql_d);
preparedStatement.setBigDecimal(1, ((E_mp_day_vstat) o).getId());
preparedStatement.setString(2, ((E_mp_day_vstat) o).getArea_code());
preparedStatement.setString(3, isDateRight.isDatetime(((E_mp_day_vstat) o).getData_date()) ?
sDateFormat.format(sDateFormat.parse(((E_mp_day_vstat) o).getData_date())) :
sDateFormat.format(new Date()));
//11.E_mp_power_curve
} else if (o instanceof E_mp_power_curve) {
sql_d = "DELETE FROM JBBDKF.SYNC_YX_E_MP_POWER_CURVE WHERE ID=? AND DATA_TYPE=? " +
"AND AREA_CODE=?" +
"AND TO_CHAR(DATA_DATE,'yyyy-MM-dd hh24:mi:ss')=?";
preparedStatement = connection.prepareStatement(sql_d);
preparedStatement.setBigDecimal(1, ((E_mp_power_curve) o).getId());
preparedStatement.setBigDecimal(2, ((E_mp_power_curve) o).getData_type());
preparedStatement.setString(3, ((E_mp_power_curve) o).getArea_code());
preparedStatement.setString(4, isDateRight.isDatetime(((E_mp_power_curve) o).getData_date()) ?
sDateFormat.format(sDateFormat.parse(((E_mp_power_curve) o).getData_date())) :
sDateFormat.format(new Date()));
//12.E_mp_vol_curve
} else if (o instanceof E_mp_vol_curve) {
sql_d = "DELETE FROM JBBDKF.SYNC_YX_E_MP_VOL_CURVE WHERE ID=? AND PHASE_FLAG=? AND " +
"AREA_CODE=? AND TO_CHAR(DATA_DATE,'yyyy-MM-dd hh24:mi:ss')=?";
preparedStatement = connection.prepareStatement(sql_d);
preparedStatement.setBigDecimal(1, ((E_mp_vol_curve) o).getId());
preparedStatement.setBigDecimal(2, ((E_mp_vol_curve) o).getPhase_flage());
preparedStatement.setString(3, ((E_mp_vol_curve) o).getArea_code());
preparedStatement.setString(4, isDateRight.isDatetime(((E_mp_vol_curve) o).getData_date()) ?
sDateFormat.format(sDateFormat.parse(((E_mp_vol_curve) o).getData_date())) :
sDateFormat.format(new Date()));
}
preparedStatement.executeUpdate();
}catch (SQLException e) {
e.printStackTrace();
System.out.println(o);
} catch (ParseException e) {
e.printStackTrace();
System.out.println(o);
}
}
}