自定义任务类示例- 调度功能客户化-客户化文档
目录

自定义任务类示例

import static com.runqian.mis2.util.ResTypeConst.COMPLEX_REPORT;
import static com.runqian.mis2.util.ResTypeConst.FAST_REPORT;
import static com.runqian.mis2.util.ResTypeConst.FREEDOM_REPORT;
import static com.runqian.mis2.util.ResTypeConst.PIVOT_REPORT;
import java.sql.ResultSet;
import java.util.Arrays;
import java.util.Map;
import com.runqian.mis2.util.ReadConfInfo;
import com.runqian.report4.cache.ReportCache;
import com.runqian.report4.input.RowReportSaver;
import com.runqian.report4.model.engine2.RowReport;
import com.runqian.report4.usermodel.Context;
import com.runqian.report4.usermodel.INormalCell;
import com.runqian.report4.usermodel.IReport;
import com.runqian.report4.usermodel.input.InputProperty;
import com.runqianapp.schedule.TaskThread;
import com.runqianapp.schedule.interfaces.BaseTask;
import com.runqianapp.schedule.interfaces.IDBAccess;
import com.runqianapp.schedule.task.ReportCalcUtil;
import com.runqianapp.schedule.task.ReportTask;
import com.runqianapp.schedule.utils.PathUtils;
import com.runqianapp.schedule.utils.RequestUtil;
import com.runqianapp.schedule.utils.ScheduleConfig;
import com.runqianapp.util.report.Reports;

/**
 * 通过行式填报表将数据从A表备份到B表
 * @author DYC
 *
 */
public class BackUpTask extends BaseTask {
 private String reportFile; //报表
 private TaskThread taskThread;//当前任务线程
 
 public static final String REPORTFILE = "reportFile";
 
 public String getReportFile() {
  return reportFile;
 }

 public void setReportFile(String reportFile) {
  this.reportFile = reportFile;
 }
 
 public BackUpTask(Map params) {
  this.reportFile = (String) params.get(ReportTask.REPORTFILE);
  this.taskThread = (TaskThread) params.get(ReportTask.EXPORT_INST_TASKTHREAD);
 }
 
 /**
  * 提交填报表的数据
  */
 public Object execute(Map params) throws Exception {
  String[] reports=reportFile.split(";");
  for(int i=0;i<reports.length;i++){
   String[] temp=reports[i].split(",");
   //将报表文件的相对路径转化成绝对路径(根据sch_file_path配置)
   String report = null;
   if(temp[0].charAt(0)=='0'){
    report =PathUtils.getAppRealPath()+Context.getMainDir()+"\\"+temp[1];
   }else if(temp[0].charAt(0)=='2'){
       String sql = "select res_path,res_Type,res_server_Path from t_res where res_id="+temp[1];
       IDBAccess idba=getRunDBA();
       try{
          ResultSet rs = idba.executeQuery(sql);
          if(rs.next()){
           String str=rs.getString(1);
           int type=rs.getInt(2);
           int[] serverPathTypes = new int[] {FAST_REPORT, PIVOT_REPORT, FREEDOM_REPORT, COMPLEX_REPORT};
           if(Arrays.binarySearch(serverPathTypes, type) != -1){
            String reportName=rs.getString(3);
            report=PathUtils.getAppRealPath()+reportName;
           }else{
          String[] sss=str.split("raq=");
          sss= sss[1].split(".raq");
            str=sss[0];
            String reportName ="/"+str+".raq";
            report=PathUtils.getAppRealPath()+Context.getMainDir()+reportName;
           }
        }
       }catch(Exception e){
        idba.close();
       }
   }else{
    report = temp[1];
   }
   
   Context ctx = new Context();
   IReport rd = null;
   //设置ctx和rd中的参数等(调度器本身必须进行处理的)
   rd = ReportCalcUtil.configReportDefine(report);
   ctx = ReportCalcUtil.configReportContext(params, ctx, rd);
   
   String appType = ReadConfInfo.getPropery("conf_appType");
   if(!"0".equals(appType))
    Reports.setDataSource(rd, ctx);
   
   ReportCache rc = ReportCalcUtil.configReportCache(report, this.taskThread, params, ctx,rd);
   IReport ireport = rc.getReport();
   //处理填报表保存
   RowReportSaver rowSaver = new RowReportSaver((RowReport) ireport, null, ctx);
   //rowSaver.setRequest(RequestUtil.getCommonReq());
   rowSaver.save();
  }
  return null;
 }
 

}