Commit 2fa5e3eb by fuwenlei

修改定时任务

parent 325c986c
...@@ -110,7 +110,15 @@ public class CreateTableAuFile { ...@@ -110,7 +110,15 @@ public class CreateTableAuFile {
&& null != resultSet.getDate(i + 1)) { && null != resultSet.getDate(i + 1)) {
cal.setTime(resultSet.getDate(i + 1)); cal.setTime(resultSet.getDate(i + 1));
row.setDate(i, cal.get(cal.YEAR), cal.get(cal.MONTH) + 1, cal.get(cal.DAY_OF_MONTH)); row.setDate(i, cal.get(cal.YEAR), cal.get(cal.MONTH) + 1, cal.get(cal.DAY_OF_MONTH));
}else if ("NUMBER".equals(tableDef.getColumnType(i).toString())) {
row.setDouble(i, resultSet.getDouble(i + 1));
}else if ("DECIMAL".equals(tableDef.getColumnType(i).toString())) {
row.setDouble(i, resultSet.getDouble(i + 1));
}else if ("CHAR".equals(tableDef.getColumnType(i).toString())
&& StringUtil.isNotEmpty(resultSet.getString(i + 1))) {
row.setString(i, resultSet.getString(i + 1));
} }
} }
table.insert(row); table.insert(row);
} }
...@@ -260,11 +268,11 @@ public class CreateTableAuFile { ...@@ -260,11 +268,11 @@ public class CreateTableAuFile {
map.put("STRING", Type.UNICODE_STRING); map.put("STRING", Type.UNICODE_STRING);
map.put("BINARY", Type.UNICODE_STRING); map.put("BINARY", Type.UNICODE_STRING);
map.put("TIMESTAMP", Type.UNICODE_STRING); map.put("TIMESTAMP", Type.UNICODE_STRING);
map.put("DECIMAL", Type.UNICODE_STRING); map.put("DECIMAL", Type.DOUBLE);
map.put("DATE", Type.DATE); map.put("DATE", Type.DATE);
map.put("CHAR", Type.UNICODE_STRING); map.put("CHAR", Type.UNICODE_STRING);
map.put("VARCHAR", Type.UNICODE_STRING); map.put("VARCHAR", Type.UNICODE_STRING);
map.put("NUMBER", Type.UNICODE_STRING); map.put("NUMBER", Type.DOUBLE);
map.put("VARCHAR2", Type.UNICODE_STRING); map.put("VARCHAR2", Type.UNICODE_STRING);
return map; return map;
} }
......
...@@ -10,35 +10,45 @@ import com.alibaba.fastjson.JSONObject; ...@@ -10,35 +10,45 @@ import com.alibaba.fastjson.JSONObject;
import com.byit.utils.DecompressionFileZipUtl; import com.byit.utils.DecompressionFileZipUtl;
import com.byit.utils.HttpClient; import com.byit.utils.HttpClient;
import com.byit.utils.HyperSqlMap; import com.byit.utils.HyperSqlMap;
import com.byit.utils.PropertiesUtil;
@Component @Component
public class SchedulerJob { public class SchedulerJob {
@Scheduled(cron = "0 * * * * ?") @Scheduled(cron = "0 0 11 * * ?")
// @Scheduled(cron = "0 0 0/1 * * ?") // @Scheduled(cron = "0 0 0/1 * * ?")
public void upLoadReportByPositionIdScheduler() throws Exception { public void upLoadReportByPositionIdScheduler() throws Exception {
long a = System.currentTimeMillis(); //long a = System.currentTimeMillis();
System.out.println("开始时间:"+a); //System.out.println("开始时间:"+a);
//获取系统文件存放路径
DecompressionFileZipUtl.templatePath = PropertiesUtil.getValue(null, "templatePath");
DecompressionFileZipUtl.hyperPath = PropertiesUtil.getValue(null, "hyperPath");
DecompressionFileZipUtl.twbxPath = PropertiesUtil.getValue(null, "twbxPath");
// 获取岗位id的json字符串数组 // 获取岗位id的json字符串数组
String doGet = HttpClient.doGet("http://10.0.103.193:8080/portal/queryserve/queryPositionIdAndUserCode.do"); String postionJson = HttpClient.doGet("http://10.0.103.193:8080/portal/queryserve/queryPositionIdAndUserCode.do");
// json串转化成list // json串转化成list
Map<String,Object> map= JSONObject.parseObject(doGet); Map<String,Object> map= JSONObject.parseObject(postionJson);
//获取岗位数据 //获取岗位数据
List<String> positionIdList = (List<String>) map.get("postionids"); List<String> positionIdList = (List<String>) map.get("postionids");
// 循环获取岗位等级为1.2.3.4的岗位编号集合。 // 循环获取岗位等级为1.2.3.4的岗位编号集合。
for (String position:positionIdList) { for (String position:positionIdList) {
HyperSqlMap.position_code = new String(position.getBytes("gbk"),"UTF-8"); HyperSqlMap.position_code="";
DecompressionFileZipUtl.checkFile("D:\\test", ""); HyperSqlMap.empl_code="";
HyperSqlMap.position_code = position;
//HyperSqlMap.position_code = new String(position.getBytes("gbk"),"UTF-8");
DecompressionFileZipUtl.checkFile(DecompressionFileZipUtl.templatePath, "");
} }
//获取人员编号 //获取人员编号
List<String> userCodeList = (List<String>) map.get("usercodes"); List<String> userCodeList = (List<String>) map.get("usercodes");
// 循环获取岗位等级为1.2.3.4的岗位编号集合。 // 循环获取岗位等级为1.2.3.4的岗位编号集合。
for (String userCode:userCodeList) { for (String userCode:userCodeList) {
HyperSqlMap.position_code="";
HyperSqlMap.empl_code="";
HyperSqlMap.empl_code=userCode; HyperSqlMap.empl_code=userCode;
DecompressionFileZipUtl.checkFile("D:\\test", ""); DecompressionFileZipUtl.checkFile(DecompressionFileZipUtl.templatePath, "");
} }
//DecompressionFileZipUtl.checkFile("D:\\test", ""); //DecompressionFileZipUtl.checkFile("D:\\test", "");
System.out.println("结束时间:"+(System.currentTimeMillis()-a)/24/60/60/1000); //System.out.println("结束时间:"+(System.currentTimeMillis()-a)/24/60/60/1000);
} }
/** /**
......
...@@ -20,12 +20,12 @@ public class DecompressionFileZipUtl { ...@@ -20,12 +20,12 @@ public class DecompressionFileZipUtl {
private static final int buffer = 10240; private static final int buffer = 10240;
public static void main(String[] args) throws Exception { //模板路径
// TODO Auto-generated method stub public static String templatePath="";
String path = "D:\\test"; //hyper文件路径
checkFile(path, ""); public static String hyperPath="";
//twbx文件路径
} public static String twbxPath = "";
/** /**
* 1.将.twbx文件后缀名改为.zip 2.将zip文件解压 3.替换zip文件夹中的数据文件 4.将文件进行压缩 5.修改后缀名为twbx * 1.将.twbx文件后缀名改为.zip 2.将zip文件解压 3.替换zip文件夹中的数据文件 4.将文件进行压缩 5.修改后缀名为twbx
...@@ -88,8 +88,8 @@ public class DecompressionFileZipUtl { ...@@ -88,8 +88,8 @@ public class DecompressionFileZipUtl {
String sql = hyper.hyperSqlMap.get(hyperName).toString(); String sql = hyper.hyperSqlMap.get(hyperName).toString();
// 查询数据并写入hyper文件 并返还路径 // 查询数据并写入hyper文件 并返还路径
CreateTableAuFile createTableAuFile = new CreateTableAuFile(); CreateTableAuFile createTableAuFile = new CreateTableAuFile();
String newHyperName = createTableAuFile.createFile("D:\\", sql, hyperName); String newHyperName = createTableAuFile.createFile(hyperPath, sql, hyperName);
//String newHyperName = "D:\\"+name; //String newHyperName = hyperPath+name;
// 复制文件并替换源文件 // 复制文件并替换源文件
copyFile(newHyperName, filePath + System.getProperty("file.separator") + name); copyFile(newHyperName, filePath + System.getProperty("file.separator") + name);
} }
...@@ -98,13 +98,13 @@ public class DecompressionFileZipUtl { ...@@ -98,13 +98,13 @@ public class DecompressionFileZipUtl {
if(flag){ if(flag){
//filePath + System.getProperty("file.separator") //filePath + System.getProperty("file.separator")
// 压缩文件的路径 // 压缩文件的路径
File f = new File( "D:\\test\\"+ zipName); File f = new File( templatePath+ System.getProperty("file.separator")+ zipName);
// 压缩文件twbx文件名称 // 压缩文件twbx文件名称
String twbxName = f.getName() + ".zip"; String twbxName = f.getName() + ".zip";
//new CompressedFileZipUtil(new File(filePath, twbxName)).zipFiles(f); //new CompressedFileZipUtil(new File(filePath, twbxName)).zipFiles(f);
new CompressedFileZipUtil(new File("D:\\test\\", twbxName)).zipFiles(f); new CompressedFileZipUtil(new File(templatePath, twbxName)).zipFiles(f);
// 读取压缩文件 // 读取压缩文件
String zipPath ="D:\\test" + System.getProperty("file.separator"); String zipPath =templatePath + System.getProperty("file.separator");
f = new File(zipPath+twbxName); f = new File(zipPath+twbxName);
// 获取系统时间 // 获取系统时间
SimpleDateFormat sim = new SimpleDateFormat("YYYY-MM"); SimpleDateFormat sim = new SimpleDateFormat("YYYY-MM");
...@@ -113,7 +113,8 @@ public class DecompressionFileZipUtl { ...@@ -113,7 +113,8 @@ public class DecompressionFileZipUtl {
String newPath = zipPath+twbxName; String newPath = zipPath+twbxName;
f.renameTo(new File(newPath)); f.renameTo(new File(newPath));
// 根据岗位编号创建目录 // 根据岗位编号创建目录
File postFile = new File("F:\\test" + System.getProperty("file.separator") + System.getProperty("file.separator") + HyperSqlMap.position_code); if(!StringUtil.isEmpty(HyperSqlMap.position_code)){
File postFile = new File(twbxPath + System.getProperty("file.separator") + System.getProperty("file.separator") + HyperSqlMap.position_code);
if (!postFile.exists()) { if (!postFile.exists()) {
postFile.mkdir(); postFile.mkdir();
} }
...@@ -121,9 +122,24 @@ public class DecompressionFileZipUtl { ...@@ -121,9 +122,24 @@ public class DecompressionFileZipUtl {
String postCodeName = twbxName.substring(0, twbxName.indexOf(".twbx")) + sim.format(new Date())+".twbx"; String postCodeName = twbxName.substring(0, twbxName.indexOf(".twbx")) + sim.format(new Date())+".twbx";
// copy压缩文件 // copy压缩文件
copyFile(zipPath+twbxName, copyFile(zipPath+twbxName,
"F:\\test" + System.getProperty("file.separator")+HyperSqlMap.position_code+ System.getProperty("file.separator") + postCodeName); twbxPath + System.getProperty("file.separator")+HyperSqlMap.position_code+ System.getProperty("file.separator") + postCodeName);
// 删除解压文件生成的目录及文件
delAllFile(templatePath);
}else{
File userCodeFile = new File(twbxPath + System.getProperty("file.separator") + System.getProperty("file.separator") + HyperSqlMap.empl_code);
if (!userCodeFile.exists()) {
userCodeFile.mkdir();
}
//文件重命名
String postCodeName = twbxName.substring(0, twbxName.indexOf(".twbx")) + sim.format(new Date())+".twbx";
// copy压缩文件
copyFile(zipPath+twbxName,
twbxPath + System.getProperty("file.separator")+HyperSqlMap.empl_code+ System.getProperty("file.separator") + postCodeName);
// 删除解压文件生成的目录及文件 // 删除解压文件生成的目录及文件
delAllFile("D:\\test\\"); delAllFile(templatePath);
}
} }
} }
......
...@@ -15,7 +15,7 @@ public class HyperSqlMap { ...@@ -15,7 +15,7 @@ public class HyperSqlMap {
public HyperSqlMap(){ public HyperSqlMap(){
//key为hyper文件得名字,value为hyper文件得查询sql //key为hyper文件得名字,value为hyper文件得查询sql
hyperSqlMap.put("BI_HOS_SALES_CORR_V_B (BYIT)", "SELECT a1.* from BYIT.bi_hos_sales_curr_v a1 inner join " hyperSqlMap.put("BI_HOS_SALES_CURR_V_B (BYIT)", "SELECT a1.* from BYIT.bi_hos_sales_curr_v_b a1 inner join "
+"(select distinct subordinate_position_code " +"(select distinct subordinate_position_code "
+ "from BYIT.auth_hos_sales_curr " + "from BYIT.auth_hos_sales_curr "
+" where position_code like '%"+position_code+"%' )a2 " +" where position_code like '%"+position_code+"%' )a2 "
...@@ -25,7 +25,7 @@ public class HyperSqlMap { ...@@ -25,7 +25,7 @@ public class HyperSqlMap {
+"on a1.品牌名称=a3.brand_name"); +"on a1.品牌名称=a3.brand_name");
hyperSqlMap.put("BI_HOS_SALES_HIS_V_B (BYIT)", "SELECT a1.* " hyperSqlMap.put("BI_HOS_SALES_HIS_V_B (BYIT)", "SELECT a1.* "
+"from BYIT.bi_hos_sales_curr_v a1 inner join (" +"from BYIT.bi_hos_sales_curr_v_b a1 inner join ("
+"select distinct subordinate_position_code " +"select distinct subordinate_position_code "
+"from BYIT.auth_hos_sales_curr " +"from BYIT.auth_hos_sales_curr "
+"where position_code like '%"+position_code+"%' )a2 " +"where position_code like '%"+position_code+"%' )a2 "
......
...@@ -7,3 +7,9 @@ spring.datasource.password=byit ...@@ -7,3 +7,9 @@ spring.datasource.password=byit
spring.datasource.type=com.alibaba.druid.pool.DruidDataSource spring.datasource.type=com.alibaba.druid.pool.DruidDataSource
spring.datasource.driver-class-name=oracle.jdbc.driver.OracleDriver spring.datasource.driver-class-name=oracle.jdbc.driver.OracleDriver
#template file path###
templatePath=D:\\test
#hyper file path###
hyperPath=D:\\
#twbx file path###
twbxPath=F:\\test
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment