Package com.narirelays.ems.applogic

Examples of com.narirelays.ems.applogic.OperResult


//    }
//    return false;
//  }
 
  public OperResult importPCS9000Data(String date){
    OperResult result = new OperResult();
    String entHierarchyID = null;
    String energyMediaID = null;

//    /**!
//     * 首先检测月表是否存在如果不存在的话那就重建月表
//     */
//    String tableName = null;
//    try {
//      Date dateYMD = sdfYMD.parse(date);
//      String dateYM = sdfYM.format(dateYMD);
//      tableName = "measure_table"+dateYM;
//      if(!isTableExist(tableName)){
//        result = createMeasureTable(tableName);
//        if(result.isFAILED()){
//          return result;
//        }
//      }
//    } catch (ParseException e1) {
//      // TODO Auto-generated catch block
//      e1.printStackTrace();
//      result = new OperResult();
//      result.setFailed(e1.getMessage());
//      return result;
//    }
   
    List<Process> processes = processDAO.findAll();
    Hashtable<String,MeasureTable> measureHash = new Hashtable<String,MeasureTable>();
    for(Process process:processes){
      EntHierarchy entHierarchy = process.getEntHierarchy();
      if(entHierarchy==null){
        Log.error("No such department:"+process.getEntHierarchy().getId());//bug!!exception
        continue;
      }else{
        entHierarchyID = entHierarchy.getId();
        List<PInMeasure> ins = pInMeasureDAO.findByProperty("process", process);
//        Set<PInMeasure> ins = process.getPInMeasures();
        for(PInMeasure in:ins){//对于所有工艺关联的输入计量点InMeasure
//          Measure inMeasure = in.getMeasure();
          Measure inMeasure = measureDAO.findById(in.getId().getMId());
          if(inMeasure==null){
            Log.error("No such in measure:"+in.getId().getMId());
            continue;
          }else{
            //得到对应的计量点的能源介质类型
//            EnergyMedia energyMedia = inMeasure.getEnergyMedia();
            EnergyMedia energyMedia = energyMediaDAO.findById(inMeasure.getEnergyMedia().getId());//bug!!exception
            if(energyMedia==null){
              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){
      log.error("Not all measure table record is saved to database, Please check log!");
    }else{
      Log.info("Merge measure table "+i+"/"+total);
    }
    if(i>0){
      result.setSucceed();
      result.setSucceed(MEASURE_TABLE_SAVE_OK, i,total);
    }
    return result;
  }
View Full Code Here


    +       "\"PLAN_VALUE\"         FLOAT(24),"
    +       "\"TOTAL_VALUE\"        FLOAT(24),"
    +       "CONSTRAINT PK_MEASURE_TABLE PRIMARY KEY (\"TIME_ID\", \"HIERARCHY_ID\", \"E_M_ID\")"
    +    ")";
    jdbcTemplate.execute(createQuery);
    OperResult result = new OperResult();
    if(SQLUtility.isTableExist(jdbcTemplate,tableName)){
      result.setSucceed();
    }else{
      result.setFailed(TABLE_CREATE_FAILED,tableName);
    }
    return result;
  }
View Full Code Here

  public OperResult modifyMeasureTable(Object dep_id,Object media_id,Object time_id,Map properties){
    return basicInfomationManagement.modifyMeasureTable(stringValue(dep_id), stringValue(media_id), stringValue(time_id), properties);
  }
  public OperResult queryMeasureTable(Object dep_id,Object time_id){
    MeasureTable output = new MeasureTable();
    OperResult result =  basicInfomationManagement.queryMeasureTable(stringValue(dep_id), stringValue(time_id), output);
    if(result.isSUCCEED()){
      JSONObject jsonObject = JSONObject.fromObject(output, jsonConfig);
      result.setInfoMSG(jsonObject.toString());
    }
   
    return result;
  }
View Full Code Here

    // }
    return result;
  }

  public OperResult deleteTaskParamV(String jobid, String param_name) {
    OperResult result = new OperResult();
    if (param_name == null) {
      result.setFailed(TASK_PARAM_REQUIRE_ID);
    } else {
      if (jobid == null) {
        result.setFailed(TASK_INFO_REQUIRE_ID);
      } else {
        TaskParamV taskParamV = taskParamVDAO
            .findById(new TaskParamVId(jobid, param_name));
        if (taskParamV == null) {
          result.setFailed(TASK_PARAM_V_NOTEXIST, jobid, param_name);
        } else {
          taskParamVDAO.delete(taskParamV);
          result.setSucceed();
        }
      }
    }
    return result;
  }
View Full Code Here

    return result;
  }

  public OperResult modifyTaskParamV(String jobid, String param_name,
      Map properties) {
    OperResult result = new OperResult();
    if (param_name == null) {
      result.setFailed(TASK_PARAM_REQUIRE_ID);
    } else {
      if (jobid == null) {
        result.setFailed(TASK_INFO_REQUIRE_ID);
      } else {
        TaskInfo taskInfo = taskInfoDAO.findById(jobid);
        if(taskInfo==null){
          result.setFailed(TASK_INFO_NOTEXIST,jobid);
        }else{
          TaskParamV taskParamV = taskParamVDAO
              .findById(new TaskParamVId(jobid, param_name));
          try {
            if (taskParamV == null) {
              taskParamV = new TaskParamV();
              BeanUtils.populate(taskParamV, properties);
              taskParamV.setId(new TaskParamVId(jobid, param_name));
              taskParamV.setTaskInfo(taskInfo);
              taskParamVDAO.merge(taskParamV);
            } else {
              BeanUtils.populate(taskParamV, properties);
              taskParamVDAO.merge(taskParamV);
            }
            result = QuartzHelper.modifyJobParameters(taskParamV);
          } catch (IllegalAccessException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
            result.setFailed(e.getMessage());
          } catch (InvocationTargetException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
            result.setFailed(e.getMessage());
          }
        }
      }
    }
    return result;
View Full Code Here

    }
    return result;
  }

  public OperResult queryTaskParamV(String jobid) {
    OperResult result = new OperResult();
    if (jobid == null) {
      result.setFailed(TASK_INFO_REQUIRE_ID);
    } else {
      TaskInfo taskInfo = taskInfoDAO.findById(jobid);
      if (taskInfo == null) {
        result.setFailed(TASK_INFO_NOTEXIST, jobid);
      } else {
        ClassRegister classRegister = taskInfo.getClassRegister();
        if (classRegister.getClassname() != null) {
          try {
            Class c = Class.forName(classRegister.getClassname());
            List<PropertyDescriptor> pros = ObjectListConvert2DynaBeanList
                .getClassProperties(c);
            List<LazyDynaBean> beans = new ArrayList<LazyDynaBean>();
            Set<TaskParamV> taskVs = taskInfo.getTaskParamVs();
            for (PropertyDescriptor pro : pros) {
              LazyDynaBean bean = ObjectListConvert2DynaBeanList
                  .convert(pro);
              bean.set("type", pro.getPropertyType()
                  .getName());
              for (TaskParamV taskV : taskVs) {
                if (StringUtils.equals(taskV.getId()
                    .getParamName(), pro.getName())) {
                  bean.set("value", taskV.getValue());
                  break;
                }
              }
              if (bean.get("value")==null) {
                bean.set("value", "");
              }
              beans.add(bean);
            }
            result.setSucceed();
            result.setData(beans);
          } catch (ClassNotFoundException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
            result.setFailed(e.getMessage());
          }
        }
        //       
        //       
        //       
View Full Code Here

      throws JobExecutionException {
    DataImporter4PCS9000ManagementService dataImporter4PCS9000ManagementService = (DataImporter4PCS9000ManagementService)StorageService.ctx.getBean("dataImporter4PCS9000ManagementService");
    if(dataImporter4PCS9000ManagementService==null){
      log.error("DataImporter4PCS9000ManagementService is null");
    }else{
      OperResult result = dataImporter4PCS9000ManagementService.importPCS9000Data(WebVariable.measureDF.format(new Date()));
      if(result.isSUCCEED()){
        OLAPManagementService oLAPManagementService = (OLAPManagementService)StorageService.ctx.getBean("oLAPManagementService");
        if(oLAPManagementService!=null){
          result = oLAPManagementService.maintainCube(true,"ems");
        }
      }
View Full Code Here

    }
    return result;
  }

  public OperResult deleteAllJob() {
    OperResult result = new OperResult();
    try {
      List<String> groupNames = SchedulerProvider.scheduler
          .getJobGroupNames();
      for (String groupName : groupNames) {
        Set<JobKey> jobKeys = SchedulerProvider.scheduler
            .getJobKeys(GroupMatcher.groupEquals(groupName));
        for (JobKey jobKey : jobKeys) {
          SchedulerProvider.scheduler.deleteJob(jobKey);
          TaskInfo taskInfo = taskInfoDAO.findById(jobKey.getName());
          if (taskInfo != null) {
            taskInfoDAO.delete(taskInfo);
          }
          Log.error("delete " + jobKey.toString());
        }
      }
      result.setSucceed();
    } catch (SchedulerException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
      result.setFailed(e.getMessage());
    }
    return result;
  }
View Full Code Here

    }
    return result;
  }

  public OperResult addJob(String jobclass_id, Map properties) {
    OperResult result = new OperResult();
    if (jobclass_id == null) {
      result.setFailed(CLASS_REGISTER_REQUIRE_ID);
    } else {
      ClassRegister classRegister = classRegisterDAO
          .findById(jobclass_id);
      if (classRegister == null) {
        result.setFailed(CLASS_REGISTER_NOTEXIST, jobclass_id);
      } else {
        TaskInfo taskInfo = new TaskInfo();
        try {
          BeanUtils.populate(taskInfo, properties);
          taskInfo.setId(MyUUIDGen.getUUID());
          taskInfo.setVersion(classRegister.getVersion());
          taskInfo.setClassRegister(classRegister);
          taskInfoDAO.merge(taskInfo);
          result = QuartzHelper.addJob(taskInfo);
          if (result.isSUCCEED()) {
            result.setData(taskInfo.getId());
          }
          if (!setTaskInfos()) {
            Log.error("cache not available for addJob");
          }
        } catch (IllegalAccessException e) {
          // TODO Auto-generated catch block
          e.printStackTrace();
          result.setFailed(e.getMessage());
        } catch (InvocationTargetException e) {
          // TODO Auto-generated catch block
          e.printStackTrace();
          result.setFailed(e.getMessage());
        }
      }
    }
    return result;
  }
View Full Code Here

    }
    return result;
  }

  public OperResult modifyJob(String jobid, Map properties) {
    OperResult result = new OperResult();
    if (jobid == null) {
      result.setFailed(TASK_INFO_REQUIRE_ID);
    } else {
      TaskInfo taskInfo = taskInfoDAO.findById(jobid);
      if (taskInfo == null) {
        result.setFailed(TASK_INFO_NOTEXIST, jobid);
      } else {
        try {
          BeanUtils.populate(taskInfo, properties);
          taskInfoDAO.merge(taskInfo);
          result.setSucceed();
          if (!setTaskInfos()) {
            Log.error("cache not available for addJob");
          }
        } catch (IllegalAccessException e) {
          // TODO Auto-generated catch block
          e.printStackTrace();
          result.setFailed(e.getMessage());
        } catch (InvocationTargetException e) {
          // TODO Auto-generated catch block
          e.printStackTrace();
          result.setFailed(e.getMessage());
        }
      }
    }
    return result;
  }
View Full Code Here

TOP

Related Classes of com.narirelays.ems.applogic.OperResult

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.