系统催款修改
This commit is contained in:
+6
-6
@@ -92,18 +92,18 @@ public class HuaWeiSmsUtil {
|
||||
}
|
||||
switch (codeType) {
|
||||
case "1":
|
||||
//中汽标协-登录检查验证码
|
||||
// 中汽中心标准所-登录验证码内容
|
||||
sender = "8821092414481";
|
||||
signature = "中汽中心标准所";
|
||||
templateId = "9fbee7166af24bbfacc178e417345a21";
|
||||
templateParas = "[" + randomNumber + "," + phone + "," + verificationTime + "]";
|
||||
templateId = "93c8a63236734e0ca0bc89f8b2413e7f";
|
||||
templateParas = "[" + randomNumber + "]";
|
||||
break;
|
||||
case "2":
|
||||
//中汽标协-忘记密码
|
||||
// 中汽中心标准所-忘记密码
|
||||
sender = "8821092414481";
|
||||
signature = "中汽中心标准所";
|
||||
templateId = "6f8573c5adc54df2a56a6e48556c3044";
|
||||
templateParas = "[" + randomNumber + "," + phone + "," + verificationTime + "]";
|
||||
templateId = "ac6749d4a3134c39997b4342695ddc01";
|
||||
templateParas = "[" + randomNumber +"]";
|
||||
break;
|
||||
default:
|
||||
throw new JeroBootException("codeType flase.");
|
||||
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
package com.jero.system;
|
||||
package com.jero.system.common;
|
||||
|
||||
public class SystemRemindersCommon {
|
||||
/**
|
||||
+85
-18
@@ -3,19 +3,23 @@ package com.jero.system.controller;
|
||||
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
|
||||
import com.jero.common.api.vo.Result;
|
||||
import com.jero.common.aspect.annotation.AutoLog;
|
||||
import com.jero.mail.service.IPayMailBillService;
|
||||
import com.jero.common.constant.CommonConstant;
|
||||
import com.jero.common.exception.JeroBootException;
|
||||
import com.jero.modules.quartz.entity.QuartzJob;
|
||||
import com.jero.modules.quartz.service.IQuartzJobService;
|
||||
import com.jero.payment.service.IPayPaymentRecordService;
|
||||
import com.jero.system.SystemRemindersCommon;
|
||||
import com.jero.system.common.SystemRemindersCommon;
|
||||
import com.jero.system.vo.SystemRemindersVO;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.quartz.*;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.text.ParseException;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.time.LocalDate;
|
||||
import java.util.Calendar;
|
||||
import java.util.Date;
|
||||
@@ -35,12 +39,9 @@ import java.util.Objects;
|
||||
public class SystemRemindersController {
|
||||
|
||||
@Resource
|
||||
private IPayPaymentRecordService payPaymentRecordService;
|
||||
private Scheduler scheduler;
|
||||
|
||||
@Resource
|
||||
private IQuartzJobService quartzJobService;
|
||||
|
||||
private static final String id = "1442663790058471425";
|
||||
private static final String jobName = "com.jero.quartz.job.RemindersAllJob";
|
||||
|
||||
/**
|
||||
* 系统催款
|
||||
@@ -54,9 +55,10 @@ public class SystemRemindersController {
|
||||
// 每年
|
||||
String year = "0 0 0 ${day} ${month} ? *";
|
||||
// 每月
|
||||
String month = "0 0 0 ${day} * ?";
|
||||
String month = "0 0 0 ${day} * ? *";
|
||||
// 指定日期执行一次
|
||||
String day = "0 0 0 ${day} ${month} ? ${year}";
|
||||
|
||||
if(Objects.isNull(systemRemindersVO.getFrequency())){
|
||||
return Result.error("频率不能为空");
|
||||
}
|
||||
@@ -64,21 +66,86 @@ public class SystemRemindersController {
|
||||
return Result.error("催款时间不能为空");
|
||||
}
|
||||
String cron = "";
|
||||
// 频率 (1:仅一此,2:每月一次,3:每年一次)
|
||||
// 频率 (1:仅一此,3:每月一次,2:每年一次)
|
||||
if(Objects.equals(systemRemindersVO.getFrequency(),SystemRemindersCommon.FREQUENCY1)){
|
||||
String[] t = systemRemindersVO.getTime().split("-");
|
||||
Calendar now = Calendar.getInstance();
|
||||
cron = day.replace("${day}",t[1]).replace("${month}",t[0]).replace("${year}",String.valueOf(now.get(Calendar.YEAR)));
|
||||
}else if(Objects.equals(systemRemindersVO.getFrequency(),SystemRemindersCommon.FREQUENCY2)){
|
||||
cron = month.replace("${day}",systemRemindersVO.getTime());
|
||||
if(t.length != 3){
|
||||
return Result.error("催款时间格式不正确");
|
||||
}
|
||||
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyyMMdd");
|
||||
String dateFirst = systemRemindersVO.getTime().replace("-","");
|
||||
String dateLast = dateFormat.format(new Date());
|
||||
int dateFirstIntVal = Integer.parseInt(dateFirst);
|
||||
int dateLastIntVal = Integer.parseInt(dateLast);
|
||||
if (dateFirstIntVal <= dateLastIntVal) {
|
||||
return Result.error("催款日期必须大于当前日期");
|
||||
}
|
||||
cron = day.replace("${day}",String.valueOf(Integer.parseInt(t[2]))).replace("${month}",String.valueOf(Integer.parseInt(t[1]))).replace("${year}",String.valueOf(Integer.parseInt(t[0])));
|
||||
}else if(Objects.equals(systemRemindersVO.getFrequency(),SystemRemindersCommon.FREQUENCY3)){
|
||||
String[] t = systemRemindersVO.getTime().split("-");
|
||||
cron = year.replace("${day}",t[1]).replace("${month}",t[0]);
|
||||
if(t.length != 1){
|
||||
return Result.error("催款时间格式不正确");
|
||||
}
|
||||
cron = month.replace("${day}",String.valueOf(Integer.parseInt(t[0])));
|
||||
}else if(Objects.equals(systemRemindersVO.getFrequency(),SystemRemindersCommon.FREQUENCY2)){
|
||||
String[] t = systemRemindersVO.getTime().split("-");
|
||||
if(t.length != 2){
|
||||
return Result.error("催款时间格式不正确");
|
||||
}
|
||||
cron = year.replace("${day}",String.valueOf(Integer.parseInt(t[1]))).replace("${month}",String.valueOf(Integer.parseInt(t[0])));
|
||||
}
|
||||
LambdaUpdateWrapper<QuartzJob> update = new LambdaUpdateWrapper<>();
|
||||
update.eq(QuartzJob::getId,id);
|
||||
update.set(QuartzJob::getCronExpression,cron);
|
||||
quartzJobService.update(update);
|
||||
schedulerDelete(jobName.trim());
|
||||
schedulerAdd(jobName.trim(), cron.trim(), "");
|
||||
return Result.OK("操作成功");
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除定时任务
|
||||
*
|
||||
* @param jobClassName
|
||||
*/
|
||||
private void schedulerDelete(String jobClassName) {
|
||||
try {
|
||||
scheduler.pauseTrigger(TriggerKey.triggerKey(jobClassName));
|
||||
scheduler.unscheduleJob(TriggerKey.triggerKey(jobClassName));
|
||||
scheduler.deleteJob(JobKey.jobKey(jobClassName));
|
||||
} catch (Exception e) {
|
||||
log.error(e.getMessage(), e);
|
||||
throw new JeroBootException("删除定时任务失败");
|
||||
}
|
||||
}
|
||||
/**
|
||||
* 添加定时任务
|
||||
*
|
||||
* @param jobClassName
|
||||
* @param cronExpression
|
||||
* @param parameter
|
||||
*/
|
||||
private void schedulerAdd(String jobClassName, String cronExpression, String parameter) {
|
||||
try {
|
||||
// 启动调度器
|
||||
scheduler.start();
|
||||
|
||||
// 构建job信息
|
||||
JobDetail jobDetail = JobBuilder.newJob(getClass(jobClassName).getClass()).withIdentity(jobClassName).usingJobData("parameter", parameter).build();
|
||||
|
||||
// 表达式调度构建器(即任务执行的时间)
|
||||
CronScheduleBuilder scheduleBuilder = CronScheduleBuilder.cronSchedule(cronExpression);
|
||||
|
||||
// 按新的cronExpression表达式构建一个新的trigger
|
||||
CronTrigger trigger = TriggerBuilder.newTrigger().withIdentity(jobClassName).withSchedule(scheduleBuilder).build();
|
||||
|
||||
scheduler.scheduleJob(jobDetail, trigger);
|
||||
} catch (SchedulerException e) {
|
||||
throw new JeroBootException("创建定时任务失败", e);
|
||||
} catch (RuntimeException e) {
|
||||
throw new JeroBootException(e.getMessage(), e);
|
||||
}catch (Exception e) {
|
||||
throw new JeroBootException("后台找不到该类名:" + jobClassName, e);
|
||||
}
|
||||
}
|
||||
private static Job getClass(String classname) throws Exception {
|
||||
Class<?> class1 = Class.forName(classname);
|
||||
return (Job) class1.newInstance();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,7 +7,7 @@ import java.io.Serializable;
|
||||
@Data
|
||||
public class SystemRemindersVO implements Serializable {
|
||||
/**
|
||||
* 频率 (1:仅一此,2:每月一次,3:每年一次)
|
||||
* 频率 (1:仅一此,3:每月一次,2:每年一次)
|
||||
*/
|
||||
@ApiModelProperty(value = "频率")
|
||||
private Integer frequency;
|
||||
|
||||
Reference in New Issue
Block a user