|
楼主 |
发表于 2014-11-18 10:19:37
|
显示全部楼层
- package com.pushdata.quartz;
- import java.util.ArrayList;
- import java.util.Date;
- import java.util.HashMap;
- import java.util.Iterator;
- import java.util.List;
- import java.util.Map;
- import org.apache.log4j.Logger;
- import org.quartz.Job;
- import org.quartz.JobExecutionContext;
- import org.quartz.JobExecutionException;
- import com.bjinfotech.wzjc.check.CalcUtil;
- import com.bjinfotech.wzjc.util.CommonUtil;
- import com.bjinfotech.wzjc.util.DicUtil;
- import com.bjinfotech.wzjc.util.TabTypeUtil;
- import com.justep.system.data.KSQL;
- import com.justep.system.data.Row;
- import com.justep.system.data.SQL;
- import com.justep.system.data.Table;
- import com.justep.system.util.CommonUtils;
- public class ReportOfDayJob implements Job {
- private static Logger log = Logger.getLogger(ReportOfDayJob.class);
- public void execute(JobExecutionContext context) throws JobExecutionException {
- Map<String, Object> varMap = new HashMap<String, Object>(); //更新参数
- CommonUtil util = new CommonUtil();
- String[]tabId = util.getString("job_day_report").split(","); //获取日报报表号
- String[]tabNumber = new String[tabId.length];
- int index = 0;
- for (String string : tabId) {
- if(index == tabNumber.length){
- break;
- }
- tabNumber[index] = DicUtil.getTabNumberByTabTypeId(Integer.parseInt(string)).toString();
- index ++;
- }
- List<String> param = new ArrayList<String>();
- String procName = "";
- param.add("0");
- for (int i = 0; i < tabNumber.length; i++) {
- procName = "proc_" + tabNumber[i] + "GD" + "(?)"; //拼存储过程
- log.info("[" + CommonUtils.getCurrentDate().toString().substring(0,10) + "] exec " + procName);
- //除重
- TabTypeUtil.fileManager(Integer.parseInt(tabId[i]));
- //归档
- CalcUtil.execProc(procName, null, param); //执行存储过程
- //生成新报告期
- varMap = new HashMap<String, Object>(); //更新参数
- String ksqls = "update Tab_Type t1 set t1.Report_Interval=:currentDate where t1=:tab_type_id";
- String currentDate = CommonUtils.getFirstDateOfMonth(CommonUtils.getCurrentDateTime()).toString();
- String tab_type_id = util.getString(tabNumber[i]);
- varMap.put("currentDate", currentDate);
- varMap.put("tab_type_id", tab_type_id);
- KSQL.executeUpdate(ksqls, varMap, "/wzjc/xzbb/data", null);
-
- String filterDW = new CommonUtil().getString("fDW");
- varMap = new HashMap<String, Object>();
- //问题 开始 调用 DicUtil.getTabNumberByTabTypeId(tab_type_id);时报错未解决 java.lang.NoClassDefFoundError
- varMap.put("tab_type_id", tab_type_id);
- Object o = KSQL.select("select t1.Report_Period from Tab_Type t1 where t1=:tab_type_id", varMap, "/wzjc/common/data", null).iterator().next().getValue(0);
- String tabType = o.toString();
- //问题 结束
-
- String tab_time = DicUtil.getReportIntervalByTabTypeId(tab_type_id).toString().substring(0, 10);
- Date curr_date = CommonUtils.toDate(tab_time);
- Date firstDayOfDate = CommonUtils.getFirstDateOfMonth(curr_date);
-
- List<String> ogns = new ArrayList<String>();
-
- StringBuffer ksql = new StringBuffer("");
- ksql.append(" select t1.Affiliation_ID as unit from tab_unit t1, tab_function_user t2 ");
- ksql.append(" where t1.Tab_Type_ID=t2.Tab_Type_ID and t1.statu='1' and t2.statu='1' and t2.function_code='B01' and Affiliation_ID not in ("+filterDW+") and t1.Tab_Type_ID="+tab_type_id+" ");
- varMap = new HashMap<String, Object>();
- varMap.put("tab_type_id", tab_type_id);
- Map<String, String> sql = new HashMap<String, String>();
- sql.put("MSSQL", ksql.toString());
- Table table = SQL.select(sql, null, "/wzjc/xzbb/data"); //KSQL.select(ksql.toString(), varMap, "/wzjc/xzbb/data", null);
- for (Iterator<Row> iterator = table.iterator(); iterator.hasNext();) {
- String unit = "" + iterator.next().getValue(0);
- if(!ogns.contains(unit)){
- ogns.add(unit);
- }
- }
-
- ksql = new StringBuffer("");
- ksql.append(" insert into Base_Tab_Affiliation_Stat t1 ");
- ksql.append(" (t1, t1.Unit_Tab_ID, t1.Tab_Type_ID, t1.Affiliation_ID, t1.SYNC_ID, t1.Tab_time) ");
- ksql.append(" values ( ");
- ksql.append(" :nextSeq('Base_Tab_Affiliation_Stat'), :unit_tab_id, :tab_type_id, :af_unit_tab_id, :uuid, :curr_date ");
- ksql.append(" ) ");
- //进入日期循环
-
- String query = "select t1.* from Base_Tab_Affiliation_Stat t1 where t1.Unit_Tab_ID=:unit_tab_id and t1.Tab_Type_ID=:tab_type_id and t1.Affiliation_ID = :af_unit_tab_id and t1.Tab_time=:curr_date";
-
- if("日报".equals(tabType)){
- int totalDay = CommonUtils.getDay(CommonUtils.getLastDateOfMonth(curr_date));
- for (int dw = 0; dw < ogns.size(); dw++) {
- for (int day = 1; day <= totalDay; day++) {
- varMap = new HashMap<String, Object>();
- varMap.put("unit_tab_id", ogns.get(dw).concat("_" + (day < 10 ? "0" : "") + day));
- varMap.put("tab_type_id", tab_type_id);
- varMap.put("af_unit_tab_id", ogns.get(dw));
- varMap.put("uuid", CommonUtils.createGUID());
- varMap.put("curr_date", CommonUtils.addDays(firstDayOfDate, (day - 1)));
- Table tab = KSQL.select(query, varMap, "/wzjc/sjtb/data", null);
- if(tab.size()>0){
- System.out.println("["+ogns.get(dw).concat("_" + (day < 10 ? "0" : "") + day)+"]["+CommonUtils.addDays(firstDayOfDate, (day - 1))+"][had]已有记录,无需再次添加");
- }else{
- KSQL.executeUpdate(ksql.toString(), varMap, "/wzjc/sjtb/data", null);
- }
- }
- }
- }else if("旬报".equals(tabType)){
- for (int dw = 0; dw < ogns.size(); dw++) {
- for (int tenday = 1; tenday <= 3; tenday++) {
- varMap = new HashMap<String, Object>();
- varMap.put("unit_tab_id", ogns.get(dw).concat("_0" + tenday));
- varMap.put("tab_type_id", tab_type_id);
- varMap.put("af_unit_tab_id", ogns.get(dw));
- varMap.put("uuid", CommonUtils.createGUID());
- varMap.put("curr_date", CommonUtils.addDays(firstDayOfDate, (tenday - 1) * 10));
- Table tab = KSQL.select(query, varMap, "/wzjc/sjtb/data", null);
- if(tab.size()>0){
- System.out.println("["+ogns.get(dw).concat("_0" + tenday)+"]["+CommonUtils.addDays(firstDayOfDate, (tenday - 1) * 10)+"][had]已有记录,无需再次添加");
- }else{
- KSQL.executeUpdate(ksql.toString(), varMap, "/wzjc/sjtb/data", null);
- }
- }
- }
- }else{
- for (int dw = 0; dw < ogns.size(); dw++) {
- varMap = new HashMap<String, Object>();
- varMap.put("unit_tab_id", ogns.get(dw));
- varMap.put("tab_type_id", tab_type_id);
- varMap.put("af_unit_tab_id", ogns.get(dw));
- varMap.put("uuid", CommonUtils.createGUID());
- varMap.put("curr_date", firstDayOfDate);
- Table tab = KSQL.select(query, varMap, "/wzjc/sjtb/data", null);
- if(tab.size()>0){
- System.out.println("["+ogns.get(dw)+"]["+firstDayOfDate+"][had]已有记录,无需再次添加");
- }else{
- KSQL.executeUpdate(ksql.toString(), varMap, "/wzjc/sjtb/data", null);
- }
- }
- }
- }
-
- }
- }
复制代码 |
|