Commit 3f4f75e7 by dengshichuan

Merge branch 'dsc' into 'develop'

Dsc

See merge request 8timerv2/8timerapiv200!35
parents f656c582 71cdf363
package cn.timer.api.bean.quartz;
import java.math.BigInteger;
import lombok.Data;
@Data
public class JobAndTrigger {
private String JOB_NAME;
private String JOB_GROUP;
private String JOB_CLASS_NAME;
private String TRIGGER_NAME;
private String TRIGGER_GROUP;
private BigInteger REPEAT_INTERVAL;
private BigInteger TIMES_TRIGGERED;
private String CRON_EXPRESSION;
private String TIME_ZONE_ID;
}
package cn.timer.api.bean.sche;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.Table;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.extension.activerecord.Model;
import io.swagger.annotations.ApiModel;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
@Data
@AllArgsConstructor
@NoArgsConstructor
@Builder
@Entity
@Table(name = "schedule_task")
@ApiModel(value = "任务调度表")
public class ScheduleTask extends Model<ScheduleTask>{
private static final long serialVersionUID = 9109546668048881081L;
@Id
@GeneratedValue
@TableId(type = IdType.AUTO)
private Integer id;
private String cron;
private String className;
private String methodName;
}
...@@ -39,11 +39,11 @@ import cn.timer.api.dao.qyzx.QyzxEmpLoginMapper; ...@@ -39,11 +39,11 @@ import cn.timer.api.dao.qyzx.QyzxEmpLoginMapper;
import cn.timer.api.dao.zzgl.ZzglBmgwMMapper; import cn.timer.api.dao.zzgl.ZzglBmgwMMapper;
import cn.timer.api.dto.login.QysDto; import cn.timer.api.dto.login.QysDto;
import cn.timer.api.dto.qyzx.EntRegisterDto; import cn.timer.api.dto.qyzx.EntRegisterDto;
import cn.timer.api.utils.AliyunSMS;
import cn.timer.api.utils.Md5; import cn.timer.api.utils.Md5;
import cn.timer.api.utils.Result; import cn.timer.api.utils.Result;
import cn.timer.api.utils.ResultUtil; import cn.timer.api.utils.ResultUtil;
import cn.timer.api.utils.UserIp; import cn.timer.api.utils.UserIp;
import cn.timer.api.utils.aliyun.AliyunSMS;
import io.swagger.annotations.Api; import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation; import io.swagger.annotations.ApiOperation;
......
...@@ -45,9 +45,9 @@ import cn.timer.api.controller.dzht.cn.tign.hz.constant.ConfigConstant; ...@@ -45,9 +45,9 @@ import cn.timer.api.controller.dzht.cn.tign.hz.constant.ConfigConstant;
import cn.timer.api.controller.dzht.cn.tign.hz.enums.RequestType; import cn.timer.api.controller.dzht.cn.tign.hz.enums.RequestType;
import cn.timer.api.controller.dzht.cn.tign.hz.exception.DefineException; import cn.timer.api.controller.dzht.cn.tign.hz.exception.DefineException;
import cn.timer.api.dto.dzht.DzhtRzDto; import cn.timer.api.dto.dzht.DzhtRzDto;
import cn.timer.api.utils.QueryUtil;
import cn.timer.api.utils.Result; import cn.timer.api.utils.Result;
import cn.timer.api.utils.ResultUtil; import cn.timer.api.utils.ResultUtil;
import cn.timer.api.utils.query.QueryUtil;
import io.swagger.annotations.Api; import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation; import io.swagger.annotations.ApiOperation;
......
...@@ -14,9 +14,9 @@ import org.springframework.web.multipart.MultipartFile; ...@@ -14,9 +14,9 @@ import org.springframework.web.multipart.MultipartFile;
import cn.timer.api.config.annotation.CurrentUser; import cn.timer.api.config.annotation.CurrentUser;
import cn.timer.api.config.annotation.UserBean; import cn.timer.api.config.annotation.UserBean;
import cn.timer.api.utils.OSSUtil;
import cn.timer.api.utils.Result; import cn.timer.api.utils.Result;
import cn.timer.api.utils.ResultUtil; import cn.timer.api.utils.ResultUtil;
import cn.timer.api.utils.aliyun.OSSUtil;
import io.swagger.annotations.Api; import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation; import io.swagger.annotations.ApiOperation;
......
//package cn.timer.api.controller.quartz;
//
//import java.util.HashMap;
//import java.util.Map;
//
//import org.quartz.CronScheduleBuilder;
//import org.quartz.CronTrigger;
//import org.quartz.JobBuilder;
//import org.quartz.JobDetail;
//import org.quartz.JobKey;
//import org.quartz.Scheduler;
//import org.quartz.SchedulerException;
//import org.quartz.TriggerBuilder;
//import org.quartz.TriggerKey;
//import org.springframework.beans.factory.annotation.Autowired;
//import org.springframework.web.bind.annotation.GetMapping;
//import org.springframework.web.bind.annotation.PostMapping;
//import org.springframework.web.bind.annotation.RequestMapping;
//import org.springframework.web.bind.annotation.RequestParam;
//import org.springframework.web.bind.annotation.RestController;
//
//import com.github.pagehelper.PageInfo;
//
//import cn.timer.api.bean.quartz.JobAndTrigger;
//import cn.timer.api.config.quartz.TestJob;
//import cn.timer.api.dao.quartz.JobAndTriggerMapper;
//import cn.timer.api.utils.Result;
//import cn.timer.api.utils.ResultUtil;
//import io.swagger.annotations.Api;
//import io.swagger.annotations.ApiOperation;
//
//@Api(tags = "99.0 Quartz")
//@RestController
//@RequestMapping(value = "/quartz", produces = { "application/json" })
//public class JobController {
//
// @Autowired
// private Scheduler scheduler;
//
// @PostMapping(value = "/addjob")
// @ApiOperation(value = "新增任务", httpMethod = "POST", notes = "接口发布说明")
// public Result<Void> addjob(@RequestParam(value = "jobClassName") String jobClassName,
// @RequestParam(value = "jobGroupName") String jobGroupName,
// @RequestParam(value = "cronExpression") String cronExpression) throws Exception {
// addJob(jobClassName, jobGroupName, cronExpression);
// return ResultUtil.success("新增定时任务成功");
// }
//
// public void addJob(String jobClassName, String jobGroupName, String cronExpression) throws Exception {
//
// // 启动调度器
// scheduler.start();
//
// // 构建job信息
// JobDetail jobDetail = JobBuilder.newJob(TestJob.class)
// .withIdentity(jobClassName, jobGroupName).build();
//
// // 表达式调度构建器(即任务执行的时间)
// CronScheduleBuilder scheduleBuilder = CronScheduleBuilder.cronSchedule(cronExpression);
//
// // 按新的cronExpression表达式构建一个新的trigger
// CronTrigger trigger = TriggerBuilder.newTrigger().withIdentity(jobClassName, jobGroupName)
// .withSchedule(scheduleBuilder).build();
//
// try {
// scheduler.scheduleJob(jobDetail, trigger);
//
// } catch (SchedulerException e) {
// System.out.println("创建定时任务失败" + e);
// throw new Exception("创建定时任务失败");
// }
// }
//
// @PostMapping(value = "/pausejob")
// @ApiOperation(value = "暂停任务", httpMethod = "POST", notes = "接口发布说明")
// public Result<Void> pausejob(@RequestParam(value = "jobClassName") String jobClassName,
// @RequestParam(value = "jobGroupName") String jobGroupName) throws Exception {
// jobPause(jobClassName, jobGroupName);
// return ResultUtil.success("暂停定时任务成功");
// }
//
// public void jobPause(String jobClassName, String jobGroupName) throws Exception {
// scheduler.pauseJob(JobKey.jobKey(jobClassName, jobGroupName));
// }
//
// @PostMapping(value = "/resumejob")
// @ApiOperation(value = "恢复任务", httpMethod = "POST", notes = "接口发布说明")
// public Result<Void> resumejob(@RequestParam(value = "jobClassName") String jobClassName,
// @RequestParam(value = "jobGroupName") String jobGroupName) throws Exception {
// jobresume(jobClassName, jobGroupName);
// return ResultUtil.success("恢复定时任务成功");
// }
//
// public void jobresume(String jobClassName, String jobGroupName) throws Exception {
// scheduler.resumeJob(JobKey.jobKey(jobClassName, jobGroupName));
// }
//
// @PostMapping(value = "/reschedulejob")
// @ApiOperation(value = "重新设置任务", httpMethod = "POST", notes = "接口发布说明")
// public Result<Void> rescheduleJob(@RequestParam(value = "jobClassName") String jobClassName,
// @RequestParam(value = "jobGroupName") String jobGroupName,
// @RequestParam(value = "cronExpression") String cronExpression) throws Exception {
// jobreschedule(jobClassName, jobGroupName, cronExpression);
// return ResultUtil.success("重设定时任务成功");
// }
//
// public void jobreschedule(String jobClassName, String jobGroupName, String cronExpression) throws Exception {
// try {
// TriggerKey triggerKey = TriggerKey.triggerKey(jobClassName, jobGroupName);
// // 表达式调度构建器
// CronScheduleBuilder scheduleBuilder = CronScheduleBuilder.cronSchedule(cronExpression);
//
// CronTrigger trigger = (CronTrigger) scheduler.getTrigger(triggerKey);
//
// // 按新的cronExpression表达式重新构建trigger
// trigger = trigger.getTriggerBuilder().withIdentity(triggerKey).withSchedule(scheduleBuilder).build();
//
// // 按新的trigger重新设置job执行
// scheduler.rescheduleJob(triggerKey, trigger);
// } catch (SchedulerException e) {
// System.out.println("更新定时任务失败" + e);
// throw new Exception("更新定时任务失败");
// }
// }
//
// @PostMapping(value = "/deletejob")
// @ApiOperation(value = "删除任务", httpMethod = "POST", notes = "接口发布说明")
// public Result<Void> deletejob(@RequestParam(value = "jobClassName") String jobClassName,
// @RequestParam(value = "jobGroupName") String jobGroupName) throws Exception {
// jobdelete(jobClassName, jobGroupName);
// return ResultUtil.success("删除成功");
// }
//
// public void jobdelete(String jobClassName, String jobGroupName) throws Exception {
// scheduler.pauseTrigger(TriggerKey.triggerKey(jobClassName, jobGroupName));
// scheduler.unscheduleJob(TriggerKey.triggerKey(jobClassName, jobGroupName));
// scheduler.deleteJob(JobKey.jobKey(jobClassName, jobGroupName));
// }
//
//}
package cn.timer.api.dao.sche;
import org.springframework.stereotype.Repository;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import cn.timer.api.bean.sche.ScheduleTask;
@Repository
public interface ScheduleTaskMapper extends BaseMapper<ScheduleTask>{
}
package cn.timer.api.utils; package cn.timer.api.utils.aliyun;
import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.RequestParam;
......
package cn.timer.api.utils; package cn.timer.api.utils.aliyun;
import java.io.BufferedReader; import java.io.BufferedReader;
import java.io.File; import java.io.File;
...@@ -21,6 +21,8 @@ import com.aliyun.oss.model.OSSObject; ...@@ -21,6 +21,8 @@ import com.aliyun.oss.model.OSSObject;
import com.aliyun.oss.model.PutObjectRequest; import com.aliyun.oss.model.PutObjectRequest;
import cn.hutool.core.util.StrUtil; import cn.hutool.core.util.StrUtil;
import cn.timer.api.utils.Result;
import cn.timer.api.utils.ResultUtil;
/** /**
* OSS接口操作示例 1.创建空间 2.上传文件 3.下载文件 * OSS接口操作示例 1.创建空间 2.上传文件 3.下载文件
......
package cn.timer.api.utils; package cn.timer.api.utils.query;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
......
package cn.timer.api.utils.schedule;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import cn.timer.api.bean.sche.ScheduleTask;
public class CronUtil {
// 默认cron 10秒一次
private static String cron = "0/10 * * * * ?";
// 数据库cron
public static String getCron(String className, String methodName) {
ScheduleTask task = ScheduleTask.builder().build().selectOne(new LambdaQueryWrapper<ScheduleTask>()
.eq(ScheduleTask::getClassName, className).eq(ScheduleTask::getMethodName, methodName)); // 数据库查询
System.err.println(task);
if (task != null && task.getCron() != null) {
cron = task.getCron();
}
return cron;
}
}
\ No newline at end of file
package cn.timer.api.utils; package cn.timer.api.utils.schedule;
import java.text.SimpleDateFormat; import java.text.SimpleDateFormat;
import java.util.Date; import java.util.Date;
...@@ -7,6 +7,9 @@ import java.util.List; ...@@ -7,6 +7,9 @@ import java.util.List;
import org.springframework.context.annotation.Lazy; import org.springframework.context.annotation.Lazy;
import org.springframework.scheduling.annotation.EnableScheduling; import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.annotation.Scheduled; import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.scheduling.annotation.SchedulingConfigurer;
import org.springframework.scheduling.config.ScheduledTaskRegistrar;
import org.springframework.scheduling.support.CronTrigger;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
...@@ -15,6 +18,7 @@ import cn.hutool.core.date.DateUnit; ...@@ -15,6 +18,7 @@ import cn.hutool.core.date.DateUnit;
import cn.hutool.core.date.DateUtil; import cn.hutool.core.date.DateUtil;
import cn.timer.api.bean.htzz.HtzzAdminZzda; import cn.timer.api.bean.htzz.HtzzAdminZzda;
import cn.timer.api.bean.htzz.HtzzAssoHtgx; import cn.timer.api.bean.htzz.HtzzAssoHtgx;
import cn.timer.api.utils.aliyun.AliyunSMS;
/** /**
* 记录当前时间循环输出 遍历合同提醒关系表,每天固定时间(8点)查询是否提醒 * 记录当前时间循环输出 遍历合同提醒关系表,每天固定时间(8点)查询是否提醒
...@@ -25,9 +29,23 @@ import cn.timer.api.bean.htzz.HtzzAssoHtgx; ...@@ -25,9 +29,23 @@ import cn.timer.api.bean.htzz.HtzzAssoHtgx;
@Component @Component
@Lazy(false) @Lazy(false)
@EnableScheduling @EnableScheduling
public class RemindUtil { public class RemindUtil implements SchedulingConfigurer {
private static final SimpleDateFormat dateFormat = new SimpleDateFormat("HH:mm:ss"); private static final SimpleDateFormat dateFormat = new SimpleDateFormat("HH:mm:ss");
static String className = new Exception().getStackTrace()[0].getClassName();
static String methodName = null;
// 数据库动态更改定时配置
@Override
public void configureTasks(ScheduledTaskRegistrar taskRegistrar) {
taskRegistrar.addTriggerTask(() -> {
// 任务逻辑
methodName = reportCurrentTime();
}, triggerContext -> {
CronTrigger cronTrigger = new CronTrigger(CronUtil.getCron(className, methodName)); // cron配置
return cronTrigger.nextExecutionTime(triggerContext); // 下次执行任务的时间
});
}
/** /**
* 间隔时间提醒 30min/次 * 间隔时间提醒 30min/次
...@@ -40,18 +58,13 @@ public class RemindUtil { ...@@ -40,18 +58,13 @@ public class RemindUtil {
/** /**
* 每天固定时间提醒 * 每天固定时间提醒
*/ */
@Scheduled(cron = "0 0 8 * * ?") // 每天8点扫一下看有没要提醒的,有就发一个 // @Scheduled(cron = "0 0 8 * * ?") // 每天8点扫一下看有没要提醒的,有就发一个
// @Scheduled(cron = "0 8 15 * * ?") // 测试合同提醒 public static String reportCurrentTime() {
public static void reportCurrentTime() {
List<HtzzAssoHtgx> htgxs = HtzzAssoHtgx.builder().build().selectAll(); List<HtzzAssoHtgx> htgxs = HtzzAssoHtgx.builder().build().selectAll();
for (HtzzAssoHtgx htgx : htgxs) { for (HtzzAssoHtgx htgx : htgxs) {
QueryWrapper<HtzzAdminZzda> q = new QueryWrapper<HtzzAdminZzda>(); QueryWrapper<HtzzAdminZzda> q = new QueryWrapper<HtzzAdminZzda>();
q.select("id", "zjmc", "txkg_type", "yxdqr").eq("id", htgx.getHtid()).eq("is_delete", 0).eq("txkg_type", 0); q.select("id", "zjmc", "txkg_type", "yxdqr").eq("id", htgx.getHtid()).eq("is_delete", 0).eq("txkg_type", 0);
HtzzAdminZzda zzda = HtzzAdminZzda.builder().build().selectOne(q); HtzzAdminZzda zzda = HtzzAdminZzda.builder().build().selectOne(q);
if (zzda != null) { if (zzda != null) {
String name = htgx.getName(); // 员工姓名 String name = htgx.getName(); // 员工姓名
String phone = htgx.getPhone(); // 员工手机 String phone = htgx.getPhone(); // 员工手机
...@@ -72,14 +85,13 @@ public class RemindUtil { ...@@ -72,14 +85,13 @@ public class RemindUtil {
} else if (betweenDay == 30) { } else if (betweenDay == 30) {
AliyunSMS.remind(name, htname, time, phone); // 少于30天短信提醒 AliyunSMS.remind(name, htname, time, phone); // 少于30天短信提醒
} }
} else { } else {
zzda.setTxkgType(1); // 关闭提醒 zzda.setTxkgType(1); // 关闭提醒
zzda.updateById(); zzda.updateById();
} }
} }
} }
return new Exception().getStackTrace()[0].getMethodName();
} }
} }
\ No newline at end of file
package cn.timer.api.utils; package cn.timer.api.utils.schedule;
import cn.hutool.core.date.DateTime; import cn.hutool.core.date.DateTime;
import cn.hutool.cron.CronUtil; import cn.hutool.cron.CronUtil;
......
...@@ -88,6 +88,8 @@ spring: ...@@ -88,6 +88,8 @@ spring:
######### Spring boot应用健康监控 ######### Spring boot应用健康监控
management: management:
server:
port: 9090 # 如果设置端口号为-1,则隐藏监控短点
endpoints: endpoints:
web: web:
exposure: exposure:
...@@ -107,6 +109,7 @@ info: ...@@ -107,6 +109,7 @@ info:
git: git:
mode: full mode: full
############################## ##############################
# mybatis-plus # mybatis-plus
mybatis-plus: mybatis-plus:
mapper-locations: classpath:mapping/**/*Mapper.xml # dao到xml文件映射 mapper-locations: classpath:mapping/**/*Mapper.xml # dao到xml文件映射
......
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