public void insertMonthP(String params) {//日产量转月产量
JSONObject p = JSON.parseObject(params);
JSONArray uwiList = p.getJSONArray("uwiList");
List<String> list = uwiList.toJavaList(String.class);
Double cumg = 0d;
Double cumo = 0d;
Double cumw = 0d;
Integer cumproHours = 0;
Integer cumproDays = 0;
Long wellId = 0l;
String uwi = "";
// String date1 = "";
String date2 = "";
if (list != null) {
for (String s : list) {
wellId = wellInfoService.getWellIdByUwi(s);
//方法已被修改不能提交
List<DailyProduction> dailyProductions = dailyProductionMapper.listByCompanyIdAndUwi(1L, s);
date2 = dailyProductions.get(0).getDate().substring(0,7);
for (int i = 0; i < dailyProductions.size(); i++) {
String date = dailyProductions.get(i).getDate();
uwi = dailyProductions.get(i).getUwi();
Double gas = dailyProductions.get(i).getGas();
Double oil = dailyProductions.get(i).getOil();
Double water = dailyProductions.get(i).getWater();
String[] split = date.split("-");
String date1 = date.substring(0, 7);
if (date1.equals(date2)){
if (gas != null && gas!=0) {
cumproDays++;
}
if (gas != null) {
cumg += gas;
}
if (oil != null) {
cumo += oil;
}
if (water != null) {
cumw += water;
}
}else {
MonthProduction monthProduction = new MonthProduction();
monthProduction.setWellId(wellId);
monthProduction.setUserId(UserContext.getUserId());
monthProduction.setCompanyId(UserContext.getCompanyId());
monthProduction.setUwi(uwi);
monthProduction.setOilRate(cumo);
monthProduction.setWaterRate(cumw);
monthProduction.setGasRate(cumg);
monthProduction.setDate(date2);
monthProduction.setProdDays(cumproDays);
if (wellId != null) {
pdsMonthProductionMapper.insert(monthProduction);
}
date2 = date1;
cumproDays = 0;
cumg = 0d;
cumo = 0d;
cumw = 0d;
cumproDays ++;
cumg = gas;
cumo = oil;
cumw = water;
}
if (i == (dailyProductions.size()-1)){
if (date1.equals(date2)){
MonthProduction monthProduction = new MonthProduction();
monthProduction.setWellId(wellId);
monthProduction.setUserId(UserContext.getUserId());
monthProduction.setCompanyId(UserContext.getCompanyId());
monthProduction.setUwi(uwi);
monthProduction.setOilRate(cumo);
monthProduction.setWaterRate(cumw);
monthProduction.setGasRate(cumg);
monthProduction.setDate(date2);
monthProduction.setProdDays(cumproDays);
if (wellId != null) {
pdsMonthProductionMapper.insert(monthProduction);
}
}else {
MonthProduction monthProduction = new MonthProduction();
monthProduction.setWellId(wellId);
monthProduction.setUserId(UserContext.getUserId());
monthProduction.setCompanyId(UserContext.getCompanyId());
monthProduction.setUwi(uwi);
monthProduction.setOilRate(cumo);
monthProduction.setWaterRate(cumw);
monthProduction.setGasRate(cumg);
monthProduction.setDate(date2);
monthProduction.setProdDays(cumproDays);
if (wellId != null) {
pdsMonthProductionMapper.insert(monthProduction);
}
}
}
}
cumproDays = 0;
cumg = 0d;
cumo = 0d;
cumw = 0d;
}
}
}