定时任务框架修改
This commit is contained in:
parent
81dddc2e09
commit
b90f1642cc
@ -36,7 +36,7 @@ public class LisInterfaceUtil {
|
||||
* @return
|
||||
*/
|
||||
@Log(title = "接口调用",businessType = BusinessType.INTERFACE_INVOKE)
|
||||
public Result invokeLisInterface(String type,String inValue) {
|
||||
public Result invokeLisInterface(String type, String inValue) {
|
||||
String interfaceType = commonUtil.getComOptValue("HISOPT","SP_INTER");
|
||||
log.info("开始调用{}接口,入参:{}",type,interfaceType);
|
||||
switch (interfaceType){
|
||||
@ -57,9 +57,10 @@ public class LisInterfaceUtil {
|
||||
*/
|
||||
//@Transactional(rollbackFor = Exception.class)
|
||||
private Result invokeSP(String type,String inValue){
|
||||
Map<String,Object> map = new HashMap<>();
|
||||
|
||||
//为了兼容老接口,存储过程方式使用的是xml,这里需要把入参转成xml格式
|
||||
String xmlStr = changeXml(inValue);
|
||||
Map<String,Object> map = new HashMap<>();
|
||||
map.put("invalue",xmlStr);
|
||||
map.put("retcode","");
|
||||
map.put("retmsg","");
|
||||
@ -137,7 +138,7 @@ public class LisInterfaceUtil {
|
||||
* @param inValue
|
||||
* @return
|
||||
*/
|
||||
public String changeXml(String inValue){
|
||||
private String changeXml(String inValue){
|
||||
JSONObject jsonObj = JSONUtil.parseObj(inValue);
|
||||
Map<String,Object> map = jsonObj.toBean(Map.class);
|
||||
return XmlUtil.mapToXmlStr(map, "Request");
|
||||
|
||||
@ -29,7 +29,7 @@
|
||||
<!-- 通用工具-->
|
||||
<dependency>
|
||||
<groupId>com.czlis</groupId>
|
||||
<artifactId>lis-common</artifactId>
|
||||
<artifactId>lis-interfaceCommon</artifactId>
|
||||
</dependency>
|
||||
|
||||
</dependencies>
|
||||
|
||||
80
lis-quartz/src/main/java/com/czlis/quartz/task/LisTask.java
Normal file
80
lis-quartz/src/main/java/com/czlis/quartz/task/LisTask.java
Normal file
@ -0,0 +1,80 @@
|
||||
package com.czlis.quartz.task;
|
||||
|
||||
import cn.hutool.json.JSONUtil;
|
||||
import com.czlis.common.core.domain.Result;
|
||||
import com.czlis.interfaceCommon.constants.LisinterfaceNameConstants;
|
||||
import com.czlis.interfaceCommon.pojo.inter.SetDict;
|
||||
import com.czlis.interfaceCommon.utils.LisInterfaceUtil;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
/**
|
||||
* lis的定时任务类
|
||||
* 这里定义的定时任务都是系统级的,建议把sql语句也放到更新文件当中,
|
||||
* 如果是临时性的定时任务,建议都写到后台接口当中。
|
||||
* 这里的方法,返回值统一给的是import com.czlis.common.core.domain.Result;其他的返回值都报错,
|
||||
* 默认new Result("0","") 返回0是成功,其他都是失败
|
||||
* 如果不给返回值,则以方法是否返回异常为执行成功的标志,没异常就代表执行成功。有异常就代表执行失败
|
||||
*/
|
||||
@Component("lisTask")
|
||||
public class LisTask {
|
||||
|
||||
@Autowired
|
||||
private LisInterfaceUtil lisInterfaceUtil;
|
||||
|
||||
/**
|
||||
* 获取his科室信息接口定时任务
|
||||
* @return
|
||||
*/
|
||||
public Result getDictDP(){
|
||||
SetDict setDict = new SetDict();
|
||||
setDict.setZdlb("DP");
|
||||
setDict.setIp("");
|
||||
setDict.setUserid("admin");
|
||||
setDict.setYljg("1");
|
||||
String jsonStr = JSONUtil.toJsonStr(setDict);
|
||||
return lisInterfaceUtil.invokeLisInterface(LisinterfaceNameConstants.SETDICT, jsonStr);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取his人员信息接口定时任务
|
||||
* @return
|
||||
*/
|
||||
public Result getDictSRD(){
|
||||
SetDict setDict = new SetDict();
|
||||
setDict.setZdlb("SRD");
|
||||
setDict.setIp("");
|
||||
setDict.setUserid("admin");
|
||||
setDict.setYljg("1");
|
||||
String jsonStr = JSONUtil.toJsonStr(setDict);
|
||||
return lisInterfaceUtil.invokeLisInterface(LisinterfaceNameConstants.SETDICT, jsonStr);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取his病区信息接口定时任务
|
||||
* @return
|
||||
*/
|
||||
public Result getDictWR(){
|
||||
SetDict setDict = new SetDict();
|
||||
setDict.setZdlb("WR");
|
||||
setDict.setIp("");
|
||||
setDict.setUserid("admin");
|
||||
setDict.setYljg("1");
|
||||
String jsonStr = JSONUtil.toJsonStr(setDict);
|
||||
return lisInterfaceUtil.invokeLisInterface(LisinterfaceNameConstants.SETDICT, jsonStr);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取his收费项目定时任务
|
||||
* @return
|
||||
*/
|
||||
public Result getXmFee(){
|
||||
SetDict setDict = new SetDict();
|
||||
setDict.setZdlb("FEE");
|
||||
setDict.setIp("");
|
||||
setDict.setUserid("admin");
|
||||
setDict.setYljg("1");
|
||||
String jsonStr = JSONUtil.toJsonStr(setDict);
|
||||
return lisInterfaceUtil.invokeLisInterface(LisinterfaceNameConstants.SETDICT, jsonStr);
|
||||
}
|
||||
}
|
||||
@ -2,6 +2,7 @@ package com.czlis.quartz.util;
|
||||
|
||||
import com.czlis.common.constant.Constants;
|
||||
import com.czlis.common.constant.ScheduleConstants;
|
||||
import com.czlis.common.core.domain.Result;
|
||||
import com.czlis.common.utils.ExceptionUtil;
|
||||
import com.czlis.common.utils.StringUtils;
|
||||
import com.czlis.common.utils.bean.BeanUtils;
|
||||
@ -35,15 +36,16 @@ public abstract class AbstractQuartzJob implements Job {
|
||||
public void execute(JobExecutionContext context) throws JobExecutionException {
|
||||
SysJob sysJob = new SysJob();
|
||||
BeanUtils.copyBeanProp(sysJob, context.getMergedJobDataMap().get(ScheduleConstants.TASK_PROPERTIES));
|
||||
Result result = null;
|
||||
try {
|
||||
before(context, sysJob);
|
||||
if (sysJob != null) {
|
||||
doExecute(context, sysJob);
|
||||
result = doExecute(context, sysJob);
|
||||
}
|
||||
after(context, sysJob, null);
|
||||
after(context, sysJob, null,result);
|
||||
} catch (Exception e) {
|
||||
log.error("任务执行异常 - :", e);
|
||||
after(context, sysJob, e);
|
||||
after(context, sysJob, e,result);
|
||||
}
|
||||
}
|
||||
|
||||
@ -63,7 +65,7 @@ public abstract class AbstractQuartzJob implements Job {
|
||||
* @param context 工作执行上下文对象
|
||||
* @param sysJob 系统计划任务
|
||||
*/
|
||||
protected void after(JobExecutionContext context, SysJob sysJob, Exception e) {
|
||||
protected void after(JobExecutionContext context, SysJob sysJob, Exception e,Result result) {
|
||||
Date startTime = threadLocal.get();
|
||||
threadLocal.remove();
|
||||
|
||||
@ -75,8 +77,9 @@ public abstract class AbstractQuartzJob implements Job {
|
||||
sysJobLog.setStopTime(new Date());
|
||||
long runMs = sysJobLog.getStopTime().getTime() - sysJobLog.getStartTime().getTime();
|
||||
sysJobLog.setJobMessage(sysJobLog.getJobName() + " 总共耗时:" + runMs + "毫秒");
|
||||
if (e != null) {
|
||||
sysJobLog.setStatus(Constants.FAIL);
|
||||
if (e != null && !result.getCode().equals("0")) {
|
||||
//sysJobLog.setStatus(Constants.FAIL);
|
||||
sysJobLog.setStatus(result.getCode());
|
||||
String errorMsg = StringUtils.substring(ExceptionUtil.getExceptionMessage(e), 0, 2000);
|
||||
sysJobLog.setExceptionInfo(errorMsg);
|
||||
} else {
|
||||
@ -94,5 +97,5 @@ public abstract class AbstractQuartzJob implements Job {
|
||||
* @param sysJob 系统计划任务
|
||||
* @throws Exception 执行过程中的异常
|
||||
*/
|
||||
protected abstract void doExecute(JobExecutionContext context, SysJob sysJob) throws Exception;
|
||||
protected abstract Result doExecute(JobExecutionContext context, SysJob sysJob) throws Exception;
|
||||
}
|
||||
|
||||
@ -1,5 +1,6 @@
|
||||
package com.czlis.quartz.util;
|
||||
|
||||
import com.czlis.common.core.domain.Result;
|
||||
import com.czlis.common.utils.StringUtils;
|
||||
import com.czlis.common.utils.spring.SpringUtils;
|
||||
import com.czlis.quartz.domain.SysJob;
|
||||
@ -20,7 +21,7 @@ public class JobInvokeUtil {
|
||||
*
|
||||
* @param sysJob 系统任务
|
||||
*/
|
||||
public static void invokeMethod(SysJob sysJob) throws Exception {
|
||||
public static Result invokeMethod(SysJob sysJob) throws Exception {
|
||||
String invokeTarget = sysJob.getInvokeTarget();
|
||||
String beanName = getBeanName(invokeTarget);
|
||||
String methodName = getMethodName(invokeTarget);
|
||||
@ -28,29 +29,56 @@ public class JobInvokeUtil {
|
||||
|
||||
if (!isValidClassName(beanName)) {
|
||||
Object bean = SpringUtils.getBean(beanName);
|
||||
invokeMethod(bean, methodName, methodParams);
|
||||
return invokeMethod(bean, methodName, methodParams);
|
||||
} else {
|
||||
Object bean = Class.forName(beanName).getDeclaredConstructor().newInstance();
|
||||
invokeMethod(bean, methodName, methodParams);
|
||||
return invokeMethod(bean, methodName, methodParams);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 调用任务方法
|
||||
*
|
||||
* 增加返回值类型处理
|
||||
* @param bean 目标对象
|
||||
* @param methodName 方法名称
|
||||
* @param methodParams 方法参数
|
||||
*/
|
||||
private static void invokeMethod(Object bean, String methodName, List<Object[]> methodParams)
|
||||
private static Result invokeMethod(Object bean, String methodName, List<Object[]> methodParams)
|
||||
throws NoSuchMethodException, SecurityException, IllegalAccessException, IllegalArgumentException,
|
||||
InvocationTargetException {
|
||||
Object result = null;
|
||||
Method method = null;
|
||||
if (StringUtils.isNotNull(methodParams) && methodParams.size() > 0) {
|
||||
Method method = bean.getClass().getMethod(methodName, getMethodParamsType(methodParams));
|
||||
method.invoke(bean, getMethodParamsValue(methodParams));
|
||||
//有参的方法
|
||||
method = bean.getClass().getMethod(methodName, getMethodParamsType(methodParams));
|
||||
result = method.invoke(bean, getMethodParamsValue(methodParams));
|
||||
} else {
|
||||
Method method = bean.getClass().getMethod(methodName);
|
||||
method.invoke(bean);
|
||||
//无参的方法
|
||||
method = bean.getClass().getMethod(methodName);
|
||||
result = method.invoke(bean);
|
||||
}
|
||||
//获取方法的返回类型
|
||||
Class<?> returnType = method.getReturnType();
|
||||
if (returnType == void.class) {
|
||||
// 无返回值的情况
|
||||
return new Result("0","执行成功!");
|
||||
} else if (returnType == String.class) {
|
||||
// 处理String类型返回值
|
||||
return new Result("1","执行失败,String类型的返回值是无效的返回值类型!");
|
||||
// 这里可以添加对strResult的业务处理
|
||||
} else if (returnType == Integer.class || returnType == int.class) {
|
||||
// 处理int/Integer类型返回值(基本类型会自动装箱为包装类)
|
||||
return new Result("1","执行失败,Integer类型的返回值是无效的返回值类型!");
|
||||
// 这里可以添加对intResult的业务处理
|
||||
} else {
|
||||
// 其他自定义类型(假设有一个User类)
|
||||
if (returnType == Result.class) {
|
||||
Result result1 = (Result)result;
|
||||
return result1;
|
||||
} else {
|
||||
// 未知类型的通用处理
|
||||
return new Result("1","执行失败,未知的返回值类型!");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -1,5 +1,6 @@
|
||||
package com.czlis.quartz.util;
|
||||
|
||||
import com.czlis.common.core.domain.Result;
|
||||
import com.czlis.quartz.domain.SysJob;
|
||||
import org.quartz.DisallowConcurrentExecution;
|
||||
import org.quartz.JobExecutionContext;
|
||||
@ -12,7 +13,7 @@ import org.quartz.JobExecutionContext;
|
||||
@DisallowConcurrentExecution
|
||||
public class QuartzDisallowConcurrentExecution extends AbstractQuartzJob {
|
||||
@Override
|
||||
protected void doExecute(JobExecutionContext context, SysJob sysJob) throws Exception {
|
||||
JobInvokeUtil.invokeMethod(sysJob);
|
||||
protected Result doExecute(JobExecutionContext context, SysJob sysJob) throws Exception {
|
||||
return JobInvokeUtil.invokeMethod(sysJob);
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,5 +1,6 @@
|
||||
package com.czlis.quartz.util;
|
||||
|
||||
import com.czlis.common.core.domain.Result;
|
||||
import com.czlis.quartz.domain.SysJob;
|
||||
import org.quartz.JobExecutionContext;
|
||||
|
||||
@ -10,7 +11,7 @@ import org.quartz.JobExecutionContext;
|
||||
*/
|
||||
public class QuartzJobExecution extends AbstractQuartzJob {
|
||||
@Override
|
||||
protected void doExecute(JobExecutionContext context, SysJob sysJob) throws Exception {
|
||||
JobInvokeUtil.invokeMethod(sysJob);
|
||||
protected Result doExecute(JobExecutionContext context, SysJob sysJob) throws Exception {
|
||||
return JobInvokeUtil.invokeMethod(sysJob);
|
||||
}
|
||||
}
|
||||
|
||||
@ -733,6 +733,7 @@ if not exists(SELECT 1 FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_NAME = 'sys_
|
||||
-- ----------------------------
|
||||
-- 初始化-用户和角色关联表数据
|
||||
-- ----------------------------
|
||||
|
||||
if not exists(select 1 from dbo.sys_user_role where user_id = '1' and role_id = '1')
|
||||
begin
|
||||
INSERT INTO dbo.sys_user_role (user_id, role_id)
|
||||
@ -797,6 +798,7 @@ if not exists(SELECT 1 FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_NAME = 'sys_
|
||||
-- ----------------------------
|
||||
-- 初始化-部门表数据
|
||||
-- ----------------------------
|
||||
SET IDENTITY_INSERT dbo.sys_dept ON;
|
||||
if not exists(select 1 from dbo.sys_dept where dept_id = '100' and parent_id = '0')
|
||||
begin
|
||||
INSERT INTO dbo.sys_dept (dept_id, parent_id, ancestors, dept_name, order_num, leader, phone, email, status, del_flag, create_by, create_time, update_by, update_time)
|
||||
@ -815,7 +817,7 @@ if not exists(select 1 from dbo.sys_dept where dept_id = '103' and parent_id = '
|
||||
VALUES (103, 101, '0,100,101', '临检组', 1, 'lis', '15888888888', null, '0', '0', 'admin', '2025-05-05 11:09:44.197', '', NULL)
|
||||
end
|
||||
|
||||
|
||||
SET IDENTITY_INSERT dbo.sys_dept OFF;
|
||||
-- ----------------------------
|
||||
-- 2、用户信息表
|
||||
-- ----------------------------
|
||||
@ -848,7 +850,7 @@ if not exists(SELECT 1 FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_NAME = 'sys_
|
||||
-- ----------------------------
|
||||
-- 初始化-用户信息表数据
|
||||
-- ----------------------------
|
||||
|
||||
SET IDENTITY_INSERT dbo.sys_user ON;
|
||||
if not exists(select 1 from dbo.sys_user where user_id = '1')
|
||||
begin
|
||||
INSERT INTO dbo.sys_user (user_id, dept_id, user_name, nick_name, user_type, email, phonenumber, sex, avatar, password, status, del_flag, login_ip, login_date, create_by, create_time, update_by, update_time, remark)
|
||||
@ -862,7 +864,7 @@ if not exists(select 1 from dbo.sys_user where user_id = '2')
|
||||
VALUES (2, 103, 'ry', '管理员1', '00', 'ry@qq.com', '15666666666', '1', '', '$2a$10$7JB720yubVSZvUI0rEqK/.VqGOZTH.ulu33dHOiBE8ByOhJIrdAu2', '0', '0', '127.0.0.1', '2025-05-05 11:37:08.193', 'admin', '2025-05-05 11:37:08.193', '', NULL, '测试员')
|
||||
end
|
||||
|
||||
|
||||
SET IDENTITY_INSERT dbo.sys_user OFF;
|
||||
-- ----------------------------
|
||||
-- 3、岗位信息表
|
||||
-- ----------------------------
|
||||
@ -887,7 +889,7 @@ if not exists(SELECT 1 FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_NAME = 'sys_
|
||||
-- ----------------------------
|
||||
-- 初始化-岗位信息表数据
|
||||
-- ----------------------------
|
||||
|
||||
SET IDENTITY_INSERT dbo.sys_post ON;
|
||||
if not exists(select 1 from dbo.sys_post where post_id = '1')
|
||||
begin
|
||||
INSERT INTO dbo.sys_post (post_id, post_code, post_name, post_sort, status, create_by, create_time, update_by, update_time, remark)
|
||||
@ -915,7 +917,7 @@ if not exists(select 1 from dbo.sys_post where post_id = '4')
|
||||
VALUES (4, 'user', '普通员工', 4, '0', 'admin', '2025-05-05 11:38:34.44', '', NULL, '')
|
||||
|
||||
end
|
||||
|
||||
SET IDENTITY_INSERT dbo.sys_post OFF;
|
||||
-- ----------------------------
|
||||
-- 8、角色和部门关联表 角色1-N部门
|
||||
-- ----------------------------
|
||||
@ -931,6 +933,7 @@ if not exists(SELECT 1 FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_NAME = 'sys_
|
||||
-- ----------------------------
|
||||
-- 初始化-角色和部门关联表数据
|
||||
-- ----------------------------
|
||||
|
||||
if not exists(select 1 from dbo.sys_role_dept where role_id = '2' and dept_id = '100')
|
||||
begin
|
||||
insert into sys_role_dept values ('2', '100');
|
||||
@ -963,6 +966,7 @@ if not exists(SELECT 1 FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_NAME = 'sys_
|
||||
-- ----------------------------
|
||||
-- 初始化-用户与岗位关联表数据
|
||||
-- ----------------------------
|
||||
|
||||
if not exists(select 1 from dbo.sys_user_post where user_id = '1' and post_id = '1')
|
||||
begin
|
||||
insert into sys_user_post values ('1', '1');
|
||||
@ -1563,3 +1567,28 @@ if not exists(SELECT 1 FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_NAME = 'gen_
|
||||
primary key (column_id)
|
||||
)
|
||||
end
|
||||
|
||||
if not exists(select 1 from dbo.sys_job where invoke_target = 'lisTask.getDictDP' )
|
||||
begin
|
||||
INSERT INTO dbo.sys_job (job_name, job_group, invoke_target, cron_expression, misfire_policy, concurrent, status, create_by, create_time, update_by, update_time, remark)
|
||||
VALUES ('获取his科室信息', 'SYSTEM', 'lisTask.getDictDP', '0 0 23 * * ?', '3', '1', '1', 'admin', '2025-08-15 11:55:07.413', '', NULL, '')
|
||||
end
|
||||
|
||||
if not exists(select 1 from dbo.sys_job where invoke_target = 'lisTask.getDictSRD' )
|
||||
begin
|
||||
INSERT INTO dbo.sys_job (job_name, job_group, invoke_target, cron_expression, misfire_policy, concurrent, status, create_by, create_time, update_by, update_time, remark)
|
||||
VALUES ('获取his人员信息', 'SYSTEM', 'lisTask.getDictSRD', '0 0 23 * * ?', '3', '1', '1', 'admin', '2025-08-15 11:56:04.073', '', NULL, '')
|
||||
end
|
||||
|
||||
if not exists(select 1 from dbo.sys_job where invoke_target = 'lisTask.getDictWR' )
|
||||
begin
|
||||
INSERT INTO dbo.sys_job (job_name, job_group, invoke_target, cron_expression, misfire_policy, concurrent, status, create_by, create_time, update_by, update_time, remark)
|
||||
VALUES ('获取his病区信息', 'SYSTEM', 'lisTask.getDictWR', '0 0 23 * * ?', '3', '1', '1', 'admin', '2025-08-15 11:57:18.94', '', NULL, '')
|
||||
end
|
||||
|
||||
if not exists(select 1 from dbo.sys_job where invoke_target = 'lisTask.getXmFee' )
|
||||
begin
|
||||
INSERT INTO dbo.sys_job (job_name, job_group, invoke_target, cron_expression, misfire_policy, concurrent, status, create_by, create_time, update_by, update_time, remark)
|
||||
VALUES ('获取his收费项目', 'DEFAULT', 'lisTask.getXmFee', '0 0 23 * * ?', '3', '1', '1', 'admin', '2025-08-15 11:58:04.853', '', NULL, '')
|
||||
end
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user