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

key删除

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