Commit 90a5aeab authored by 董建华's avatar 董建华

增加数据上报定时器

parent fd35fc81
......@@ -23,7 +23,7 @@ import javax.sql.DataSource;
* @version: 1.0
*/
@Configuration
@MapperScan(basePackages = "com.mapper.data",sqlSessionFactoryRef = "dataSqlSessionFactory")
@MapperScan(basePackages = "com.mapper.data", sqlSessionFactoryRef = "dataSqlSessionFactory")
public class DataDataSourceConfig {
@Value("${db.driver}")
......@@ -55,8 +55,8 @@ public class DataDataSourceConfig {
}
@Bean
public DataSourceTransactionManager reporDatasourceTransactionManager(@Qualifier("dataDataSource") DataSource datasource ) {
return new DataSourceTransactionManager(datasource);
public DataSourceTransactionManager reporDatasourceTransactionManager(@Qualifier("dataDataSource") DataSource datasource) {
return new DataSourceTransactionManager(datasource);
}
@Bean(name = "dataSqlSessionFactory")
......
......@@ -23,7 +23,7 @@ import javax.sql.DataSource;
* @version: 1.0
*/
@Configuration
@MapperScan(basePackages = "com.mapper.report",sqlSessionFactoryRef = "sqlSessionFactory")
@MapperScan(basePackages = "com.mapper.report", sqlSessionFactoryRef = "sqlSessionFactory")
public class ReportDataSourceConfig {
@Value("${db.driver}")
......@@ -56,8 +56,8 @@ public class ReportDataSourceConfig {
}
@Bean
public DataSourceTransactionManager reporDatasourceTransactionManager(@Qualifier("reportDataSource") DataSource datasource ) {
return new DataSourceTransactionManager(datasource);
public DataSourceTransactionManager reporDatasourceTransactionManager(@Qualifier("reportDataSource") DataSource datasource) {
return new DataSourceTransactionManager(datasource);
}
@Bean(name = "sqlSessionFactory")
......
......@@ -112,16 +112,17 @@ public class ReportController {
reportService.quaryReportedStatus(fileEntry);
} catch (QgException e) {
log.error("查询上报状态失败,e: {} ", e);
result.put("msg", e.alarm);
result.put("msg", e.alarm + e.message);
return result;
} catch (Exception e) {
log.error("查询上报状态异常,e: {} ", e);
result.put("msg", "查询上报状态异常");
return result;
}
result.put("msg","查询成功");
result.put("msg", "查询成功");
return result;
}
@RequestMapping("/upDataByFile")
public Map<String, Object> upDataByFile(@RequestParam("file") MultipartFile file, String type) {
Map<String, Object> result = new HashMap<>();
......@@ -138,7 +139,26 @@ public class ReportController {
reportService.reportData(fileEntry);
} catch (QgException e) {
log.error("数据上报失败: {} ,e: {}", e.alarm, e);
result.put("msg", "上报失败," + e.alarm);
result.put("msg", "上报失败," + e.alarm + e.message);
return result;
} catch (Exception e) {
log.error("数据上报失败,系统异常 ,e: {}", e);
result.put("msg", "上报失败,系统异常");
return result;
}
result.put("msg", "上报成功");
return result;
}
@RequestMapping("/upDataByZipFile")
public Map<String, Object> upDataByZipFile(FileEntry fileEntry) {
fileEntry.setFilePath(getPath(fileEntry.getFilePath()));
Map<String, Object> result = new HashMap<>();
try {
reportService.reportData(fileEntry);
} catch (QgException e) {
log.error("数据上报失败: {} ,e: {}", e.alarm, e);
result.put("msg", "上报失败," + e.alarm + e.message);
return result;
} catch (Exception e) {
log.error("数据上报失败,系统异常 ,e: {}", e);
......@@ -150,7 +170,7 @@ public class ReportController {
}
public String getPath(String old){
public String getPath(String old) {
String[] split = old.split("-");
StringBuffer sb = new StringBuffer();
for (String str : split) {
......
package com.mapper.data;
import com.entity.report.ReportRecord;
import org.apache.ibatis.annotations.Param;
import org.springframework.stereotype.Repository;
import org.springframework.web.bind.annotation.RequestParam;
import java.util.List;
import java.util.Map;
......@@ -9,11 +11,11 @@ import java.util.Map;
@Repository
public interface DataMapper {
//获取每日放款数据
List<Map<String,Object>>getLoanDayData();
List<Map<String,Object>>getLoanDayData(@Param("param") Map<String,String> param);
//获取每日还款数据
List<Map<String,Object>>getRepayDayData();
List<Map<String,Object>>getRepayDayData(@Param("param") Map<String,String> param);
//获取每日逾期数据
List<Map<String,Object>>getOverDayData();
List<Map<String,Object>>getOverDayData(@Param("param") Map<String,String> param);
//获取上月逾期数据
List<Map<String,Object>>getOverMonthData();
List<Map<String,Object>>getOverMonthData(@Param("param") Map<String,String> param);
}
\ No newline at end of file
......@@ -12,6 +12,13 @@ import java.util.Map;
public interface ReportService {
FileEntry creatZipFile(List<Map<String,Object>> dataList, InfoType infoType, BusinessType businessType) throws QgException;
FileEntry creatZipFile(String date,List<Map<String,Object>> dataList, InfoType infoType, BusinessType businessType) throws QgException;
void creatTxtFile(String filePath,List<Map<String,Object>> dataList, InfoType infoType, BusinessType businessType) throws QgException;
List<Map<String,Object>> getDataAsync(Map<String,String> param);
FileEntry creatZipFileByFile(MultipartFile file , InfoType infoType, BusinessType businessType) throws QgException;
void reportData(FileEntry fileEntry) throws QgException;
......
......@@ -40,9 +40,9 @@ public class ReportTimer {
//每天凌晨2点
@Scheduled(cron = "0 0 2 * * ?")
void reportDayData() {
if (!isRun) {
return;
}
// if (!isRun) {
// return;
// }
dayReportIsRunning = true;
try {
//上报日放款数据
......@@ -68,20 +68,20 @@ public class ReportTimer {
try {
//上报月逾期数据
reportService.reportOverMonthData();
}finally {
} finally {
monReportIsRunning = false;
}
}
//一小时一次
@Scheduled(fixedDelay = 1000 * 60 * 60)
//一小时一次 延迟10秒
@Scheduled(fixedDelay = 1000 * 60 * 60, initialDelay = 10000)
public void quaryReportedStatus() {
if (!isRun) {
return;
}
if(monReportIsRunning||dayReportIsRunning){
return ;
if (monReportIsRunning || dayReportIsRunning) {
return;
}
reportService.quaryReportedStatus();
}
......
package com.util;
import java.math.BigDecimal;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
......@@ -25,6 +26,30 @@ public class DateUtil {
public static final String YYYYMMDD = "yyyyMMdd";
public static String getCurrentDay(int day) {
Calendar calendar = Calendar.getInstance();
calendar.add(Calendar.DAY_OF_MONTH, day);
calendar.set(Calendar.HOUR_OF_DAY, 0);
calendar.set(Calendar.MINUTE, 0);
calendar.set(Calendar.SECOND, 0);
return new SimpleDateFormat(YYYY_MM_DD_MM_HH_SS).format(calendar.getTime());
}
public static String getCurrentDay(String date, int day) {
Date time = null;
try {
time = new SimpleDateFormat(YYYY_MM_DD_MM_HH_SS).parse(date);
}catch (Exception e){
e.printStackTrace();
}
Calendar calendar = Calendar.getInstance();
calendar.setTime(time);
calendar.add(Calendar.DAY_OF_MONTH, day);
calendar.set(Calendar.HOUR_OF_DAY, 0);
calendar.set(Calendar.MINUTE, 0);
calendar.set(Calendar.SECOND, 0);
return new SimpleDateFormat(YYYY_MM_DD_MM_HH_SS).format(calendar.getTime());
}
/**
* 获取当月月初日期
*
......@@ -42,6 +67,7 @@ public class DateUtil {
calendar.set(Calendar.DAY_OF_MONTH, 1);
return simpleDateFormat.format(calendar.getTime());
}
/**
* 获取当前服务器时间
*
......@@ -52,6 +78,7 @@ public class DateUtil {
SimpleDateFormat dateFormat = new SimpleDateFormat(format);
return dateFormat.format(Calendar.getInstance().getTime());
}
/**
* 获取当月月初日期
*
......@@ -62,4 +89,28 @@ public class DateUtil {
public static String getCurrentMonthFirstDay(String currentDate) throws ParseException {
return getCurrentMonthFirstDay(currentDate, YYYY_MM_DD);
}
public static String formatterDate(Object date, String pattern) {
SimpleDateFormat dateFormat = new SimpleDateFormat(pattern);
if(date instanceof Date){
return dateFormat.format(date);
}else {
return date.toString();
}
}
public static String formatterDate(String date, String oldPattern, String newPattern) {
SimpleDateFormat dateFormat = new SimpleDateFormat(oldPattern);
try {
SimpleDateFormat dateFormatNew = new SimpleDateFormat(newPattern);
return dateFormatNew.format(dateFormat.parse(date));
} catch (ParseException e) {
e.printStackTrace();
}
return null;
}
public static String getInt(Object val){
return new BigDecimal(String.valueOf(val)).setScale(0,BigDecimal.ROUND_HALF_UP).toString();
}
}
package com.util;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
/**
* @author :dongjianhua
* @date :Created in 2019/11/6 15:24
* @description:线程池类
* @modified By:
* @version: 1.0
*/
public class ThreadPoolUtil {
private static ExecutorService executorService = null ;
private ThreadPoolUtil(){}
public static ExecutorService getInstance(){
if(executorService != null){
return executorService;
}
return Executors.newFixedThreadPool(5);
}
}
......@@ -11,10 +11,9 @@ import org.codehaus.jettison.json.JSONObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.io.*;
import java.nio.MappedByteBuffer;
import java.nio.channels.FileChannel;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.util.Map;
......@@ -145,7 +144,7 @@ public class Utils {
//需要加密文件
File file = new File(sourceFile);
//把文件变成直接数组
byte[] b = CryptoUtil.readFile(file);
byte[] b = readFile(file);
//加密 返回密文数组
byte[] b2 = SMUtil.encryptBySM2(pubKey, b);
//加密写成.enc文件
......@@ -157,10 +156,33 @@ public class Utils {
} catch (Exception e) {
e.printStackTrace();
throw new QgException("zip转enc失败",e);
}finally {
System.gc();
}
return file2;
}
public static byte[] readFile(File f) throws IOException {
RandomAccessFile r = new RandomAccessFile(f, "r");
FileChannel fc = (r).getChannel();
byte[] var4;
try {
MappedByteBuffer bytebuffer = fc.map(FileChannel.MapMode.READ_ONLY, 0L, fc.size()).load();
byte[] result = new byte[(int)fc.size()];
if (bytebuffer.remaining() > 0) {
bytebuffer.get(result, 0, bytebuffer.remaining());
}
var4 = result;System.gc();
} catch (IOException var8) {
throw var8;
} finally {
fc.close();
r.close();
System.gc();
}
return var4;
}
/**
* 国密解密 env转zip
*
......@@ -170,10 +192,11 @@ public class Utils {
*/
public File deccryptFile(String sourceFile, String newFile) {//解密
File file3 = null;
File file4 = null;
try {
byte[] prvKey = CryptoUtil.toByteArray(reportConfig.getPrvKey());
//加密写成.enc文件
File file4 = new File(sourceFile);
file4 = new File(sourceFile);
//读取需要解密文件
byte[] prb = CryptoUtil.readFile(file4);
//解密 返回明文数组
......@@ -192,6 +215,9 @@ public class Utils {
} catch (Exception e) {
e.printStackTrace();
throw new QgException("国密解密 env转zip异常",e);
}finally {
//释放占用的文件
System.gc();
}
return file3;
}
......
......@@ -3,6 +3,8 @@
<configuration>
<settings>
<setting name="mapUnderscoreToCamelCase" value="true"/>
<!-- 打印查询语句 -->
<setting name="logImpl" value="STDOUT_LOGGING" />
</settings>
<typeAliases>
<typeAlias alias="Integer" type="java.lang.Integer"/>
......
......@@ -177,7 +177,7 @@
where status = 1
and
createtime &lt; date_add(NOW(),interval -10 minute)
and issearch !=1
and (issearch !=1 or feedback='正在处理' or feedback='等待处理')
</select>
</mapper>
\ 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