Log.error("No such in measure energy media:"+inMeasure.getEnergyMedia().getId());
continue;
}else{
energyMediaID = energyMedia.getId();
MeasureTable measureTable = null;
String measureTableIDHash = process.getId()+energyMedia.getId()+date;
if(measureHash.containsKey(measureTableIDHash)){
measureTable = measureHash.get(measureTableIDHash);
}else{
measureTable = new MeasureTable();//创建事实表中记录
measureTable.setId(new MeasureTableId(date,entHierarchyID,energyMediaID));
measureHash.put(measureTableIDHash, measureTable);
}
//获得指定计量点的指定时间的计量值
double value = getMeasureData(inMeasure,date);
String corType = inMeasure.getCorType();
//根据计量点类型进行计量校正,在计算时,输入为正,输出为负。
/**!
* mvalue:计量值
* svalue:人工调整量
* cvalue:计量折标量
* value: 计量总量
*/
if("P".equalsIgnoreCase(corType)){
//百分比校正
measureTable.setMValue(value);
measureTable.setSValue(value+value*Double.parseDouble(inMeasure.getCorValue()));
}else if("O".equalsIgnoreCase(corType)){
//绝对值校正
measureTable.setMValue(value);
measureTable.setSValue(value+Double.parseDouble(inMeasure.getCorValue()));
}else if("U".equalsIgnoreCase(corType)){
//计算公式校正
measureTable.setMValue(value);
try{
Object uresult = ScriptEvaluator.evalWithMVEL(inMeasure.getCorValue(), measureTable);
measureTable.setSValue((Double)uresult);
}catch(Exception e){
e.printStackTrace();
}
}else{
//不校正
measureTable.setMValue(value);
measureTable.setSValue(0.0);
}
//根据计量值和校正值设置对应的计量总量和计量折标量
measureTable.setValue(measureTable.getMValue()+measureTable.getSValue());
measureTable.setCValue(measureTable.getValue()*energyMedia.getScc());
}
}
}
List<POutMeasure> outs = pOutMeasureDAO.findByProperty("process", process);
// Set<POutMeasure> outs = process.getPOutMeasures();
for(POutMeasure out:outs){//对于所有工艺关联的输出计量点OutMeasure
Measure outMeasure = measureDAO.findById(out.getId().getMId());
// Measure outMeasure = out.getMeasure();
if(outMeasure==null){
Log.error("No such out measure:"+out.getMeasure().getId());
continue;
}else{
//得到对应的计量点的能源介质类型
// EnergyMedia energyMedia = outMeasure.getEnergyMedia();
EnergyMedia energyMedia = energyMediaDAO.findById(outMeasure.getEnergyMedia().getId());
if(energyMedia==null){
Log.error("No such out measure energy media:"+outMeasure.getEnergyMedia().getId());
continue;
}else{
energyMediaID = energyMedia.getId();
MeasureTable measureTable = null;
String measureTableIDHash = process.getId()+energyMedia.getId()+date;
if(measureHash.containsKey(measureTableIDHash)){
measureTable = measureHash.get(measureTableIDHash);
}else{
measureTable = new MeasureTable();
measureTable.setId(new MeasureTableId(date,entHierarchyID,energyMediaID));
measureHash.put(measureTableIDHash, measureTable);
}
// MeasureTable measureTable = null;
// if(measureHash.containsKey(process.getId()+energyMedia.getId()+date)){
// measureTable = measureHash.get(process.getId()+energyMedia.getId()+date);
// }else{
// measureTable = new MeasureTable();
// measureTable.setId(new MeasureTableId(date,entHierarchyID,energyMediaID));
// measureHash.put(process.getId()+energyMedia.getId()+date, measureTable);
// }
//获得指定计量点的指定时间的计量值
double value = getMeasureData(outMeasure,date);
String corType = outMeasure.getCorType();
//根据计量点类型进行计量校正,在计算时,输入为正,输出为负。
if("P".equalsIgnoreCase(corType)){
//百分比校正
measureTable.setMValue(-value);
measureTable.setSValue(-value-value*Double.parseDouble(outMeasure.getCorValue()));
}else if("O".equalsIgnoreCase(corType)){
//绝对值校正
measureTable.setMValue(-value);
measureTable.setSValue(-value-Double.parseDouble(outMeasure.getCorValue()));
}else if("U".equalsIgnoreCase(corType)){
//计算公式校正
measureTable.setMValue(value);
try{
Object uresult = ScriptEvaluator.evalWithMVEL(outMeasure.getCorValue(), measureTable);
measureTable.setSValue((Double)uresult);
}catch(Exception e){
e.printStackTrace();
}
}else{
//不校正
measureTable.setMValue(-value);
measureTable.setSValue(0.0);
}
//根据计量值和校正值设置对应的计量总量和计量折标量
measureTable.setValue(measureTable.getMValue()+measureTable.getSValue());
measureTable.setCValue(measureTable.getValue()*energyMedia.getScc());
}
}
}
}
}
/**!
* 处理MeasureHash中的所有对象并入库,暂时采用逐条的方式,需要改!!
*/
int i=0;
int total = measureHash.size();
for(MeasureTable measureTable:measureHash.values()){
try{
measureTableDAO.merge(measureTable);
i++;
Log.info("Merge measure table "+i+"/"+total);
}catch(Exception e){
log.error(new StringBuilder().append("Merge error for measure table record\nDepartment ID:").append(measureTable.getId().getHierarchyId())
.append("\nEM ID:").append(measureTable.getId().getEMId())
.append("\nDate ID:").append(measureTable.getId().getTimeId())
.append("\nMeasure Value:").append(measureTable.getMValue())
.append("\nCorrect Value:").append(measureTable.getSValue())
.append("\nTotal Value:").append(measureTable.getValue())
.append("\nSCC Value:").append(measureTable.getCValue()).toString());
log.error(e.getMessage());
e.printStackTrace();
}
}
if(i!=total){