Commit fb127706 authored by 陈宏杰's avatar 陈宏杰

key删除

parent c6357105
......@@ -3,12 +3,9 @@ package cn.quantgroup.report.controller;
import cn.quantgroup.report.response.GlobalResponse;
import cn.quantgroup.report.service.baihang.BaiHangFileReportService;
import cn.quantgroup.report.service.baihang.BaiHangZhuDaiService;
import cn.quantgroup.report.service.common.CommonQueryService;
import cn.quantgroup.report.service.manualTool.CleanningTransactionLogService;
import cn.quantgroup.report.service.manualTool.ManualToolService;
import cn.quantgroup.report.utils.DateUtils;
import com.alibaba.fastjson.JSON;
import com.google.common.base.Stopwatch;
import com.google.common.collect.ImmutableMap;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
......@@ -16,9 +13,7 @@ import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import java.io.File;
import java.util.Date;
import java.util.Map;
import java.util.concurrent.TimeUnit;
@Slf4j
@RestController
......@@ -180,4 +175,14 @@ public class ManualToolController {
}
}
@RequestMapping("/deleteRedisKey")
public String deleteRedisKey(String keyStr) {
try {
fileReportService.deleteRedisKey(keyStr);
return "SUCCESS";
} catch (Exception e) {
return e.getMessage();
}
}
}
......@@ -85,30 +85,36 @@ public class BaiHangFileReportService {
*/
@Async
public void createReportFile(String type, String start, String end,int daySplitCount, String loanStartDateStr, String loanEndDateStr) {
if (!increment(Constant.QG_ZHU_DAI_CREATE_REPORT_FILE_LOCK_KEY)) {
log.error("创建报送文件任务已经开始执行...请勿重复操作");
return ;
}
redisTemplate.expire(Constant.QG_ZHU_DAI_CREATE_REPORT_FILE_LOCK_KEY, 5, TimeUnit.MINUTES);
if (StringUtils.isAnyBlank(type, start, end, loanStartDateStr, loanEndDateStr)) {
throw new QGException(COMMON_ILLEGAL_PARAM_TOAST,"存在为空参数");
}
daySplitCount = Objects.isNull(daySplitCount) ? 10 : daySplitCount;
String dateFormat = "yyyy-MM-dd";
Date stepStartDate = DateUtils.parseDate(dateFormat,start);
Date stepEndDate = org.apache.commons.lang3.time.DateUtils.addDays(stepStartDate,daySplitCount);
Date endDate = DateUtils.parseDate(dateFormat,end);
Date loanStartDate = DateUtils.parseDate(dateFormat,loanStartDateStr);
Date loanEndDate = DateUtils.parseDate(dateFormat,loanEndDateStr);
Stopwatch stopwatch = Stopwatch.createStarted();
while (stepEndDate.getTime() <= endDate.getTime()){
createReportFile(type,stepStartDate,stepEndDate,loanStartDate,loanEndDate);
stepStartDate = new Date(stepEndDate.getTime());
stepEndDate = org.apache.commons.lang3.time.DateUtils.addDays(stepEndDate,daySplitCount);
}
log.info("当前 {} -- {}--{} 任务执行结束 总耗时 : {}",type,start,end,stopwatch.elapsed(TimeUnit.MILLISECONDS));
if (stepEndDate.getTime() > endDate.getTime()){
createReportFile(type,stepStartDate,endDate,loanStartDate,loanEndDate);
try {
if (!increment(Constant.QG_ZHU_DAI_CREATE_REPORT_FILE_LOCK_KEY)) {
log.error("创建报送文件任务已经开始执行...请勿重复操作");
return ;
}
redisTemplate.expire(Constant.QG_ZHU_DAI_CREATE_REPORT_FILE_LOCK_KEY, 15, TimeUnit.MINUTES);
if (StringUtils.isAnyBlank(type, start, end, loanStartDateStr, loanEndDateStr)) {
throw new QGException(COMMON_ILLEGAL_PARAM_TOAST,"存在为空参数");
}
daySplitCount = Objects.isNull(daySplitCount) ? 10 : daySplitCount;
String dateFormat = "yyyy-MM-dd";
Date stepStartDate = DateUtils.parseDate(dateFormat,start);
Date stepEndDate = org.apache.commons.lang3.time.DateUtils.addDays(stepStartDate,daySplitCount);
Date endDate = DateUtils.parseDate(dateFormat,end);
Date loanStartDate = DateUtils.parseDate(dateFormat,loanStartDateStr);
Date loanEndDate = DateUtils.parseDate(dateFormat,loanEndDateStr);
Stopwatch stopwatch = Stopwatch.createStarted();
while (stepEndDate.getTime() <= endDate.getTime()){
createReportFile(type,stepStartDate,stepEndDate,loanStartDate,loanEndDate);
stepStartDate = new Date(stepEndDate.getTime());
stepEndDate = org.apache.commons.lang3.time.DateUtils.addDays(stepEndDate,daySplitCount);
}
log.info("当前 {} -- {}--{} 任务执行结束 总耗时 : {}",type,start,end,stopwatch.elapsed(TimeUnit.MILLISECONDS));
if (stepEndDate.getTime() > endDate.getTime()){
createReportFile(type,stepStartDate,endDate,loanStartDate,loanEndDate);
}
} catch (Exception e) {
log.error("创建报送文件异常!",e);
} finally {
deleteRedisKey(Constant.QG_ZHU_DAI_CREATE_REPORT_FILE_LOCK_KEY);
}
}
......@@ -597,9 +603,15 @@ public class BaiHangFileReportService {
}
}
private Boolean increment(String key){
private Boolean increment(String key) {
Long increment = redisTemplate.opsForValue().increment(key, 1);
return increment <= 1;
}
public void deleteRedisKey(String keyStr) {
if (redisTemplate.hasKey(keyStr)) {
redisTemplate.delete(keyStr);
}
}
}
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