parent
3f1b46cc57
commit
9b47491db2
21 changed files with 371 additions and 63 deletions
@ -0,0 +1,43 @@ |
||||
package org.springblade.modules.business.controller; |
||||
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage; |
||||
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport; |
||||
import io.swagger.annotations.*; |
||||
import lombok.AllArgsConstructor; |
||||
import org.springblade.common.constant.BusinessConstant; |
||||
import org.springblade.common.constant.CommonConstant; |
||||
import org.springblade.common.utils.CommonDateUtil; |
||||
import org.springblade.core.boot.ctrl.BladeController; |
||||
import org.springblade.core.mp.support.Condition; |
||||
import org.springblade.core.mp.support.Query; |
||||
import org.springblade.core.tenant.annotation.TenantDS; |
||||
import org.springblade.core.tool.api.R; |
||||
import org.springblade.core.tool.utils.Func; |
||||
import org.springblade.modules.business.entity.Article; |
||||
import org.springblade.modules.business.service.IArticleService; |
||||
import org.springblade.modules.business.vo.ArticleVO; |
||||
import org.springblade.modules.business.wrapper.ArticleWrapper; |
||||
import org.springframework.web.bind.annotation.*; |
||||
|
||||
/** |
||||
* 控制器 |
||||
* |
||||
* @author Chill |
||||
*/ |
||||
@TenantDS |
||||
@RestController |
||||
@RequestMapping(CommonConstant.APPLICATION_BUSINESS_NAME + "/common-api") |
||||
@AllArgsConstructor |
||||
@Api(value = "公共接口", tags = "公共接口") |
||||
public class CommonApiController extends BladeController { |
||||
|
||||
/** |
||||
* 获取系统时间 |
||||
*/ |
||||
@GetMapping("/get-system-datetime") |
||||
@ApiOperationSupport(order = 1) |
||||
@ApiOperation(value = "获取系统时间", notes = "获取系统时间") |
||||
public R getSystemDatetime() { |
||||
return R.data(CommonDateUtil.getNowString()); |
||||
} |
||||
} |
||||
@ -0,0 +1,93 @@ |
||||
package org.springblade.modules.business.timer; |
||||
|
||||
import com.baomidou.mybatisplus.core.toolkit.Wrappers; |
||||
import lombok.RequiredArgsConstructor; |
||||
import lombok.extern.slf4j.Slf4j; |
||||
import org.quartz.JobExecutionContext; |
||||
import org.quartz.JobExecutionException; |
||||
import org.springblade.common.cache.DictBizCache; |
||||
import org.springblade.common.constant.BusinessConstant; |
||||
import org.springblade.common.utils.CommonDateUtil; |
||||
import org.springblade.core.tool.utils.DateUtil; |
||||
import org.springblade.modules.business.entity.ApmRecord; |
||||
import org.springblade.modules.business.entity.Blacklist; |
||||
import org.springblade.modules.business.service.IApmRecordService; |
||||
import org.springblade.modules.business.service.IBlacklistService; |
||||
import org.springframework.scheduling.quartz.QuartzJobBean; |
||||
import org.springframework.stereotype.Component; |
||||
|
||||
import java.util.ArrayList; |
||||
import java.util.Arrays; |
||||
import java.util.List; |
||||
import java.util.Map; |
||||
|
||||
/** |
||||
* 黑名单定时任务处理 |
||||
* |
||||
* @author Administrator |
||||
*/ |
||||
@Component |
||||
@Slf4j |
||||
@RequiredArgsConstructor |
||||
public class BlacklistTimerJob extends QuartzJobBean { |
||||
private final IBlacklistService blacklistService; |
||||
private final IApmRecordService recordService; |
||||
|
||||
@Override |
||||
protected void executeInternal(JobExecutionContext context) throws JobExecutionException { |
||||
addToBlacklist(); |
||||
} |
||||
|
||||
/** |
||||
* 添加黑名单 |
||||
*/ |
||||
public void addToBlacklist() { |
||||
// 获取配置的加入黑名单违约次数
|
||||
int configRenegedTimes = DictBizCache.getDictValueWithOffset(BusinessConstant.DICT_KEY_RENEGED_TIMES_TO_BLACKLIST); |
||||
|
||||
// 1. 查询所有违约预约记录, 查询条件: blacklistFlag = 0 and apmTime < DateUtil.now() and apmStatus = 2
|
||||
// 2. 若未记录的违约记录 >= renegedTimes, 添加黑名单, 更新违约记录的 blacklistFlag = 1
|
||||
List<ApmRecord> renegedList = recordService.list(Wrappers.<ApmRecord>lambdaQuery() |
||||
.eq(ApmRecord::getBlacklistFlag, BusinessConstant.BOOLEAN_INT_FALSE) |
||||
.eq(ApmRecord::getApmStatus, BusinessConstant.RECORD_STATUS_UNREGISTER) |
||||
.le(ApmRecord::getApmTime, DateUtil.now())); |
||||
|
||||
List<ApmRecord> recordUpdateList = new ArrayList<>(); |
||||
List<Blacklist> blacklists = new ArrayList<>(); |
||||
|
||||
|
||||
List<Map<String, Object>> renegedCountList = recordService.getRenegedCountList(); |
||||
for (Map<String, Object> item : renegedCountList) { |
||||
Long createDept = (Long) item.get("createDept"); |
||||
String cupName = (String) item.get("cupName"); |
||||
String cupCardNo = (String) item.get("cupCardNo"); |
||||
String cupPhone = (String) item.get("cupPhone"); |
||||
int renegedTimes = (Integer) item.get("renegedTimes"); |
||||
|
||||
// 若未达到
|
||||
if (renegedTimes < configRenegedTimes) { |
||||
continue; |
||||
} |
||||
|
||||
// 2. 若未记录的违约记录 >= renegedTimes, 添加黑名单,
|
||||
Blacklist blacklist = new Blacklist(); |
||||
blacklist.setCreateDept(createDept); |
||||
blacklist.setCupName(cupName); |
||||
blacklist.setCupCardNo(cupCardNo); |
||||
blacklist.setCupPhone(cupPhone); |
||||
blacklist.setApmTime(DateUtil.now()); |
||||
blacklists.add(blacklist); |
||||
|
||||
// 更新违约记录的 blacklistFlag = 1
|
||||
for (ApmRecord record : renegedList) { |
||||
if (record.getCupCardNo().equals(cupCardNo)) { |
||||
record.setBlacklistFlag(BusinessConstant.BOOLEAN_INT_TRUE); |
||||
recordUpdateList.add(record); |
||||
} |
||||
} |
||||
|
||||
blacklistService.saveBatch(blacklists); |
||||
recordService.updateBatchById(recordUpdateList); |
||||
} |
||||
} |
||||
} |
||||
@ -0,0 +1,44 @@ |
||||
package org.springblade.modules.business.timer; |
||||
|
||||
import org.quartz.*; |
||||
import org.springframework.context.annotation.Bean; |
||||
import org.springframework.context.annotation.Configuration; |
||||
|
||||
@Configuration |
||||
public class QuartzConfig { |
||||
/** |
||||
* 添加黑名单定时任务表达式, 每天23:00执行 |
||||
*/ |
||||
private String CRON_BLACKLIST_JOB = "0 0 23 * * ?"; |
||||
|
||||
/** |
||||
* 创建定时任务 |
||||
*/ |
||||
@Bean |
||||
public JobDetail blacklistTimerJobDetail() { |
||||
JobDetail jobDetail = JobBuilder.newJob(BlacklistTimerJob.class) |
||||
.withIdentity("blacklistTimerJobDetail", "blacklist_job") |
||||
.usingJobData("userName", "admin") |
||||
.storeDurably() |
||||
.build(); |
||||
return jobDetail; |
||||
} |
||||
|
||||
/** |
||||
* 创建触发器 |
||||
*/ |
||||
@Bean |
||||
public Trigger blacklistTimerJobTrigger() { |
||||
//每隔5秒执行一次
|
||||
CronScheduleBuilder cronScheduleBuilder = CronScheduleBuilder.cronSchedule(CRON_BLACKLIST_JOB); |
||||
|
||||
//创建触发器
|
||||
Trigger trigger = TriggerBuilder.newTrigger() |
||||
.forJob(blacklistTimerJobDetail()) |
||||
.withIdentity("blacklistTimerJobTrigger", "BLACKLIST_JOB_TRIGGER") |
||||
.withSchedule(cronScheduleBuilder) |
||||
.build(); |
||||
|
||||
return trigger; |
||||
} |
||||
} |
||||
Loading…
Reference in new issue