feat: 更新项目配置及业务模块
- 添加热部署依赖(spring-boot-devtools) - 更新数据库配置(192.168.1.203/oademo) - 添加新业务模块(TpClientFund, TpDeptCost, TpDeptReport) - 更新MySQL驱动版本到8.4.0 - 完善工作流模块及其他业务代码
This commit is contained in:
@@ -1,38 +1,38 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<parent>
|
||||
<groupId>org.dromara</groupId>
|
||||
<artifactId>ruoyi-modules</artifactId>
|
||||
<version>${revision}</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<packaging>jar</packaging>
|
||||
<artifactId>ruoyi-job</artifactId>
|
||||
|
||||
<description>
|
||||
任务调度
|
||||
</description>
|
||||
|
||||
<dependencies>
|
||||
|
||||
<!-- 通用工具-->
|
||||
<dependency>
|
||||
<groupId>org.dromara</groupId>
|
||||
<artifactId>ruoyi-common-json</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.dromara</groupId>
|
||||
<artifactId>ruoyi-common-job</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.dromara</groupId>
|
||||
<artifactId>ruoyi-work</artifactId>
|
||||
</dependency>
|
||||
|
||||
</dependencies>
|
||||
|
||||
</project>
|
||||
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<parent>
|
||||
<groupId>org.dromara</groupId>
|
||||
<artifactId>ruoyi-modules</artifactId>
|
||||
<version>${revision}</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<packaging>jar</packaging>
|
||||
<artifactId>ruoyi-job</artifactId>
|
||||
|
||||
<description>
|
||||
任务调度
|
||||
</description>
|
||||
|
||||
<dependencies>
|
||||
|
||||
<!-- 通用工具-->
|
||||
<dependency>
|
||||
<groupId>org.dromara</groupId>
|
||||
<artifactId>ruoyi-common-json</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.dromara</groupId>
|
||||
<artifactId>ruoyi-common-job</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.dromara</groupId>
|
||||
<artifactId>ruoyi-work</artifactId>
|
||||
</dependency>
|
||||
|
||||
</dependencies>
|
||||
|
||||
</project>
|
||||
|
||||
|
||||
@@ -1 +1 @@
|
||||
package org.dromara.job;
|
||||
package org.dromara.job;
|
||||
|
||||
@@ -1,135 +1,135 @@
|
||||
package org.dromara.job.snailjob;
|
||||
|
||||
import com.aizuda.snailjob.client.job.core.annotation.JobExecutor;
|
||||
import com.aizuda.snailjob.client.job.core.dto.JobArgs;
|
||||
import com.aizuda.snailjob.client.model.ExecuteResult;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.dromara.work.domain.TpClient;
|
||||
import org.dromara.work.domain.TpOrder;
|
||||
import org.dromara.work.service.ITpClientService;
|
||||
import org.dromara.work.service.ITpOrderService;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.time.LocalDate;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author opensnail
|
||||
* @date 2024-05-17
|
||||
*/
|
||||
@Component
|
||||
@RequiredArgsConstructor
|
||||
@JobExecutor(name = "testJobExecutor")
|
||||
public class TestAnnoJobExecutor {
|
||||
|
||||
private final ITpOrderService tpOrderService;
|
||||
|
||||
private final ITpClientService tpClientService;
|
||||
|
||||
/**
|
||||
* 执行工作任务的方法
|
||||
* 根据客户在特定时间范围内的订单活动情况,更新客户的健康状态
|
||||
* 客户的健康状态根据其最近的订单活动分为三个等级:
|
||||
* 1 - 在过去180天内有订单
|
||||
* 2 - 在过去365天内有订单,但不是在过去180天内
|
||||
* 3 - 在过去365天内没有订单
|
||||
*
|
||||
* @param jobArgs 工作参数,用于执行任务
|
||||
* @return ExecuteResult 类型的执行结果,表示任务执行是否成功
|
||||
*/
|
||||
public ExecuteResult jobExecute(JobArgs jobArgs) {
|
||||
// 获取当前日期前180天和365天的日期
|
||||
String dateMinus180Days = getDateBeforeCurrent(180L);
|
||||
String dateMinus365Days = getDateBeforeCurrent(365L);
|
||||
|
||||
// 查询所有客户列表
|
||||
List<TpClient> list = tpClientService.queryAllList();
|
||||
// 如果客户列表为空,直接返回执行成功
|
||||
if (list.isEmpty()) {
|
||||
return ExecuteResult.success("执行成功");
|
||||
}
|
||||
|
||||
// 初始化需要更新的客户列表
|
||||
List<TpClient> newList = new ArrayList<>();
|
||||
for (TpClient tpClient : list) {
|
||||
Long clientId = tpClient.getId();
|
||||
// 构建查询条件,查找未删除且属于当前客户的订单
|
||||
LambdaQueryWrapper<TpOrder> baseWrapper = new LambdaQueryWrapper<TpOrder>()
|
||||
.eq(TpOrder::getIsDel, 1)
|
||||
.eq(TpOrder::getKid, clientId);
|
||||
|
||||
// 检查客户在过去180天内是否有订单
|
||||
boolean hasRecentOrderIn180Days = tpOrderService.exists(
|
||||
baseWrapper.clone().ge(TpOrder::getAddTime, dateMinus180Days));
|
||||
|
||||
if (hasRecentOrderIn180Days) {
|
||||
// 如果客户健康状态不是1,则设置为1并添加到更新列表
|
||||
if (tpClient.getHealth() != 1) {
|
||||
tpClient.setHealth(1);
|
||||
newList.add(tpClient);
|
||||
}
|
||||
continue;
|
||||
}
|
||||
|
||||
// 检查客户在过去365天内是否有订单
|
||||
boolean hasRecentOrderIn365Days = tpOrderService.exists(
|
||||
baseWrapper.clone().ge(TpOrder::getAddTime, dateMinus365Days));
|
||||
|
||||
if (hasRecentOrderIn365Days) {
|
||||
// 如果客户健康状态不是2,则设置为2并添加到更新列表
|
||||
if (tpClient.getHealth() != 2) {
|
||||
tpClient.setHealth(2);
|
||||
newList.add(tpClient);
|
||||
}
|
||||
continue;
|
||||
}
|
||||
|
||||
// 如果客户在过去365天内没有订单,且健康状态不是3,则设置为3并添加到更新列表
|
||||
if (tpClient.getHealth() != 3) {
|
||||
tpClient.setHealth(3);
|
||||
newList.add(tpClient);
|
||||
}
|
||||
}
|
||||
|
||||
try {
|
||||
// 如果有需要更新的客户,尝试批量更新
|
||||
if (!newList.isEmpty()) {
|
||||
tpClientService.updateBatchById(newList);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
// 如果更新失败,打印错误信息
|
||||
System.err.println("批量更新客户健康状态失败: " + e.getMessage());
|
||||
}
|
||||
|
||||
// 返回执行成功
|
||||
return ExecuteResult.success("执行成功");
|
||||
}
|
||||
|
||||
|
||||
private static String getDateBeforeCurrent(Long days) {
|
||||
LocalDate currentDate = LocalDate.now();
|
||||
LocalDate targetDate = currentDate.minusDays(days);
|
||||
return targetDate.format(DateTimeFormatter.ISO_DATE);
|
||||
}
|
||||
|
||||
|
||||
|
||||
public static String getCurrentDateMinus180Days(Long days) {
|
||||
try {
|
||||
// 获取当前日期
|
||||
LocalDate currentDate = LocalDate.now();
|
||||
// 计算当前日期减去180天的日期
|
||||
LocalDate dateMinus180Days = currentDate.minusDays(days);
|
||||
// 格式化日期为字符串
|
||||
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd");
|
||||
return dateMinus180Days.format(formatter);
|
||||
} catch (Exception e) {
|
||||
// 处理异常情况
|
||||
e.printStackTrace();
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
package org.dromara.job.snailjob;
|
||||
|
||||
import com.aizuda.snailjob.client.job.core.annotation.JobExecutor;
|
||||
import com.aizuda.snailjob.client.job.core.dto.JobArgs;
|
||||
import com.aizuda.snailjob.client.model.ExecuteResult;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.dromara.work.domain.TpClient;
|
||||
import org.dromara.work.domain.TpOrder;
|
||||
import org.dromara.work.service.ITpClientService;
|
||||
import org.dromara.work.service.ITpOrderService;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.time.LocalDate;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author opensnail
|
||||
* @date 2024-05-17
|
||||
*/
|
||||
@Component
|
||||
@RequiredArgsConstructor
|
||||
@JobExecutor(name = "testJobExecutor")
|
||||
public class TestAnnoJobExecutor {
|
||||
|
||||
private final ITpOrderService tpOrderService;
|
||||
|
||||
private final ITpClientService tpClientService;
|
||||
|
||||
/**
|
||||
* 执行工作任务的方法
|
||||
* 根据客户在特定时间范围内的订单活动情况,更新客户的健康状态
|
||||
* 客户的健康状态根据其最近的订单活动分为三个等级:
|
||||
* 1 - 在过去180天内有订单
|
||||
* 2 - 在过去365天内有订单,但不是在过去180天内
|
||||
* 3 - 在过去365天内没有订单
|
||||
*
|
||||
* @param jobArgs 工作参数,用于执行任务
|
||||
* @return ExecuteResult 类型的执行结果,表示任务执行是否成功
|
||||
*/
|
||||
public ExecuteResult jobExecute(JobArgs jobArgs) {
|
||||
// 获取当前日期前180天和365天的日期
|
||||
String dateMinus180Days = getDateBeforeCurrent(180L);
|
||||
String dateMinus365Days = getDateBeforeCurrent(365L);
|
||||
|
||||
// 查询所有客户列表
|
||||
List<TpClient> list = tpClientService.queryAllList();
|
||||
// 如果客户列表为空,直接返回执行成功
|
||||
if (list.isEmpty()) {
|
||||
return ExecuteResult.success("执行成功");
|
||||
}
|
||||
|
||||
// 初始化需要更新的客户列表
|
||||
List<TpClient> newList = new ArrayList<>();
|
||||
for (TpClient tpClient : list) {
|
||||
Long clientId = tpClient.getId();
|
||||
// 构建查询条件,查找未删除且属于当前客户的订单
|
||||
LambdaQueryWrapper<TpOrder> baseWrapper = new LambdaQueryWrapper<TpOrder>()
|
||||
.eq(TpOrder::getIsDel, 1)
|
||||
.eq(TpOrder::getKid, clientId);
|
||||
|
||||
// 检查客户在过去180天内是否有订单
|
||||
boolean hasRecentOrderIn180Days = tpOrderService.exists(
|
||||
baseWrapper.clone().ge(TpOrder::getAddTime, dateMinus180Days));
|
||||
|
||||
if (hasRecentOrderIn180Days) {
|
||||
// 如果客户健康状态不是1,则设置为1并添加到更新列表
|
||||
if (tpClient.getHealth() != 1) {
|
||||
tpClient.setHealth(1);
|
||||
newList.add(tpClient);
|
||||
}
|
||||
continue;
|
||||
}
|
||||
|
||||
// 检查客户在过去365天内是否有订单
|
||||
boolean hasRecentOrderIn365Days = tpOrderService.exists(
|
||||
baseWrapper.clone().ge(TpOrder::getAddTime, dateMinus365Days));
|
||||
|
||||
if (hasRecentOrderIn365Days) {
|
||||
// 如果客户健康状态不是2,则设置为2并添加到更新列表
|
||||
if (tpClient.getHealth() != 2) {
|
||||
tpClient.setHealth(2);
|
||||
newList.add(tpClient);
|
||||
}
|
||||
continue;
|
||||
}
|
||||
|
||||
// 如果客户在过去365天内没有订单,且健康状态不是3,则设置为3并添加到更新列表
|
||||
if (tpClient.getHealth() != 3) {
|
||||
tpClient.setHealth(3);
|
||||
newList.add(tpClient);
|
||||
}
|
||||
}
|
||||
|
||||
try {
|
||||
// 如果有需要更新的客户,尝试批量更新
|
||||
if (!newList.isEmpty()) {
|
||||
tpClientService.updateBatchById(newList);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
// 如果更新失败,打印错误信息
|
||||
System.err.println("批量更新客户健康状态失败: " + e.getMessage());
|
||||
}
|
||||
|
||||
// 返回执行成功
|
||||
return ExecuteResult.success("执行成功");
|
||||
}
|
||||
|
||||
|
||||
private static String getDateBeforeCurrent(Long days) {
|
||||
LocalDate currentDate = LocalDate.now();
|
||||
LocalDate targetDate = currentDate.minusDays(days);
|
||||
return targetDate.format(DateTimeFormatter.ISO_DATE);
|
||||
}
|
||||
|
||||
|
||||
|
||||
public static String getCurrentDateMinus180Days(Long days) {
|
||||
try {
|
||||
// 获取当前日期
|
||||
LocalDate currentDate = LocalDate.now();
|
||||
// 计算当前日期减去180天的日期
|
||||
LocalDate dateMinus180Days = currentDate.minusDays(days);
|
||||
// 格式化日期为字符串
|
||||
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd");
|
||||
return dateMinus180Days.format(formatter);
|
||||
} catch (Exception e) {
|
||||
// 处理异常情况
|
||||
e.printStackTrace();
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,19 +1,19 @@
|
||||
package org.dromara.job.snailjob;
|
||||
|
||||
import com.aizuda.snailjob.client.job.core.dto.JobArgs;
|
||||
import com.aizuda.snailjob.client.job.core.executor.AbstractJobExecutor;
|
||||
import com.aizuda.snailjob.client.model.ExecuteResult;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
/**
|
||||
* @author opensnail
|
||||
* @date 2024-05-17
|
||||
*/
|
||||
@Component
|
||||
public class TestClassJobExecutor extends AbstractJobExecutor {
|
||||
|
||||
@Override
|
||||
protected ExecuteResult doJobExecute(JobArgs jobArgs) {
|
||||
return ExecuteResult.success("TestJobExecutor测试成功");
|
||||
}
|
||||
}
|
||||
package org.dromara.job.snailjob;
|
||||
|
||||
import com.aizuda.snailjob.client.job.core.dto.JobArgs;
|
||||
import com.aizuda.snailjob.client.job.core.executor.AbstractJobExecutor;
|
||||
import com.aizuda.snailjob.client.model.ExecuteResult;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
/**
|
||||
* @author opensnail
|
||||
* @date 2024-05-17
|
||||
*/
|
||||
@Component
|
||||
public class TestClassJobExecutor extends AbstractJobExecutor {
|
||||
|
||||
@Override
|
||||
protected ExecuteResult doJobExecute(JobArgs jobArgs) {
|
||||
return ExecuteResult.success("TestJobExecutor测试成功");
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user