This commit is contained in:
dzc committed 2025-08-14 20:05:31 +08:00
commit b738fdc654
10 files changed
+424 -8

No files matched your search

@@ -124,4 +124,20 @@ public class BoxesInfoEntity extends Model<BoxesInfoEntity> {
@Schema(description="部门id")
private Long deptId;
/**
* 获取餐桌类型
* @return 餐桌类型
*/
public Integer getTableType() {
return tableType;
}
/**
* 设置餐桌类型
* @param tableType 餐桌类型
*/
public void setTableType(Integer tableType) {
this.tableType = tableType;
}
}
@@ -185,4 +185,18 @@ public class CanteenOnlineSpuEntity extends Model<CanteenOnlineSpuEntity> {
@Schema(description="关联每日菜谱id")
private Long linkSpuId;
/**
* 菜品类型 1-常驻菜品 2-每日菜品
*/
@Schema(description="菜品类型 1-常驻菜品 2-每日菜品")
@TableField(exist = false)
private Integer dishType;
/**
* 菜品类型名称
*/
@Schema(description="菜品类型名称")
@TableField(exist = false)
private String dishTypeName;
}
@@ -54,6 +54,12 @@ public class AppBoxesInfoVO {
*/
private Integer tableType;
/**
* 餐桌类型名称
*/
@Schema(description="餐桌类型名称")
private String tableTypeName;
/**
* 商户id
*/
@@ -164,14 +164,45 @@ public class BoxesInfoController {
wrapper.eq(StrUtil.isNotBlank(boxesInfo.getName()), BoxesInfoEntity::getName, boxesInfo.getName());
wrapper.eq(ObjectUtil.isNotEmpty(boxesInfo.getStatus()), BoxesInfoEntity::getStatus, boxesInfo.getStatus());
wrapper.eq(ObjectUtil.isNotEmpty(boxesInfo.getTableType()), BoxesInfoEntity::getTableType, boxesInfo.getTableType());
Page pageResult = boxesInfo.selectPage(page, wrapper);
// 使用service的分页方法
Page<BoxesInfoEntity> pageResult = boxesInfoService.page(page, wrapper);
List<AppBoxesInfoVO> appInfoRespVOS = new ArrayList<>();
pageResult.getRecords().forEach(x -> {
AppBoxesInfoVO appBoxesInfoVO = com.bsd.pjcloud.common.core.util.BeanUtils.toBean(x, AppBoxesInfoVO.class);
// 转换餐桌类型
Integer tableType = x.getTableType();
if (tableType != null) {
switch (tableType) {
case 1:
appBoxesInfoVO.setTableTypeName("小桌(2-4人)");
break;
case 2:
appBoxesInfoVO.setTableTypeName("中桌(4-6人)");
break;
case 3:
appBoxesInfoVO.setTableTypeName("大桌(6-8人)");
break;
case 4:
appBoxesInfoVO.setTableTypeName("包间(8人以上)");
break;
default:
appBoxesInfoVO.setTableTypeName("未知类型");
break;
}
}
appInfoRespVOS.add(appBoxesInfoVO);
});
pageResult.setRecords(appInfoRespVOS);
return R.ok(pageResult);
// 创建新的Page对象,避免类型转换问题
Page<AppBoxesInfoVO> resultPage = new Page<>();
resultPage.setCurrent(pageResult.getCurrent());
resultPage.setSize(pageResult.getSize());
resultPage.setTotal(pageResult.getTotal());
resultPage.setRecords(appInfoRespVOS);
return R.ok(resultPage);
}
@PostMapping("/createBooking")
@@ -50,15 +50,30 @@ public class CanteenOnlineSpuController {
*
* @param page 分页对象
* @param canteenOnlineSpu 在线点餐spu
* @param dishType 菜品类型筛选:1-常驻菜品(linkSpuId为空),2-每日菜品(linkSpuId不为空)
* @return
*/
@Operation(summary = "分页查询", description = "分页查询")
@Operation(summary = "分页查询", description = "分页查询,支持按菜品类型筛选:1-常驻菜品,2-每日菜品")
@GetMapping("/page")
@PreAuthorize("@pms.hasPermission('canteen_canteenOnlineSpu_view')")
public R getCanteenOnlineSpuPage(@ParameterObject Page page, @ParameterObject CanteenOnlineSpuEntity canteenOnlineSpu) {
public R getCanteenOnlineSpuPage(@ParameterObject Page page,
@ParameterObject CanteenOnlineSpuEntity canteenOnlineSpu,
@RequestParam(value = "dishType", required = false) Integer dishType) {
LambdaQueryWrapper<CanteenOnlineSpuEntity> wrapper = Wrappers.lambdaQuery();
wrapper.like(StrUtil.isNotBlank(canteenOnlineSpu.getName()), CanteenOnlineSpuEntity::getName, canteenOnlineSpu.getName());
wrapper.eq(Objects.nonNull(canteenOnlineSpu.getCategoryId()), CanteenOnlineSpuEntity::getCategoryId, canteenOnlineSpu.getCategoryId());
// 根据菜品类型筛选
if (Objects.nonNull(dishType)) {
if (dishType == 1) {
// 1-常驻菜品:linkSpuId为空
wrapper.isNull(CanteenOnlineSpuEntity::getLinkSpuId);
} else if (dishType == 2) {
// 2-每日菜品:linkSpuId不为空
wrapper.isNotNull(CanteenOnlineSpuEntity::getLinkSpuId);
}
}
return R.ok(canteenOnlineSpuService.pageScope(page, wrapper));
}
@@ -156,7 +171,7 @@ public class CanteenOnlineSpuController {
@Operation(summary = "获取在线点餐的菜品列表", description = "1.通过分类id,可以不填,默认查全部,2.商户id,必传")
public R<List<APPOnlineSpuVO>> getCanteenSpuList(@RequestParam(value = "categoryId", required = false) String categoryId,
@RequestParam(value = "merchantId") String merchantId,
@RequestParam(value = "time")String time) {
@RequestParam(value = "time",required = false)String time) {
return canteenOnlineSpuService.getCanteenOnlineSpuList(categoryId, merchantId,time);
}
@@ -25,11 +25,14 @@ import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.time.LocalDate;
import java.time.format.DateTimeFormatter;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.stream.Collectors;
import java.util.Objects;
import cn.hutool.core.collection.CollUtil;
/**
* 在线点餐spu
@@ -58,7 +61,12 @@ public class CanteenOnlineSpuServiceImpl extends ServiceImpl<CanteenOnlineSpuMap
//根据商户查询当前日期的每日菜谱,查询每日菜谱上架的菜的id,然后在从在线订餐的列表筛选出今天有上新的数据
LambdaQueryWrapper<CanteenDailyMenuEntity> dailyMenuEntityLambdaQueryWrapper = new LambdaQueryWrapper<>();
dailyMenuEntityLambdaQueryWrapper.eq(CanteenDailyMenuEntity::getMerchantId, merchantId);
dailyMenuEntityLambdaQueryWrapper.eq(CanteenDailyMenuEntity::getStartTime,time);
if (!StringUtils.isEmpty(time)){
dailyMenuEntityLambdaQueryWrapper.eq(CanteenDailyMenuEntity::getStartTime,time);
}else {
time = LocalDate.now().format(DateTimeFormatter.ISO_LOCAL_DATE); // 格式化为 yyyy-MM-dd
dailyMenuEntityLambdaQueryWrapper.eq(CanteenDailyMenuEntity::getStartTime,time);
}
List<CanteenDailyMenuEntity> dailyMenuEntities = canteenDailyMenuMapper.selectList(dailyMenuEntityLambdaQueryWrapper);
List<Long> linkSpuIds = dailyMenuEntities.stream().map(d -> d.getSpuId()).collect(Collectors.toList());
//从canteenSpuEntities中筛选出今天有上新的数据
@@ -160,6 +168,22 @@ public class CanteenOnlineSpuServiceImpl extends ServiceImpl<CanteenOnlineSpuMap
@Override
public Object pageScope(Page page, LambdaQueryWrapper<CanteenOnlineSpuEntity> wrapper) {
return baseMapper.selectPageByScope(page, wrapper, DataScope.of());
Page pageData = baseMapper.selectPageByScope(page, wrapper, DataScope.of());
List<CanteenOnlineSpuEntity> records = pageData.getRecords();
if (CollUtil.isNotEmpty(records)) {
// 为每条记录添加菜品类型标识
records.forEach(record -> {
if (record.getLinkSpuId() == null) {
record.setDishTypeName("常驻菜品");
record.setDishType(1);
} else {
record.setDishTypeName("每日菜品");
record.setDishType(2);
}
});
}
return pageData;
}
}
@@ -0,0 +1,217 @@
# 通知公告过期时间功能使用指南
## 📋 功能概述
通知公告系统新增过期时间功能,支持为公告设置具体的过期时间。到期后,公告将自动下架,不再在前端显示,无需手动操作。
## ✨ 主要特性
- **自动过期**: 支持设置具体过期时间,到期自动下架
- **灵活配置**: 可选择设置过期时间或永不过期
- **自动处理**: 系统定时任务自动处理过期公告
- **智能过滤**: 所有查询接口自动过滤已过期公告
- **性能优化**: 添加数据库索引,提高查询效率
## 🗄️ 数据库变更
### 新增字段
```sql
ALTER TABLE notice ADD COLUMN expire_time DATETIME COMMENT '过期时间,到期后公告自动下架';
```
### 新增索引
```sql
-- 过期时间索引
CREATE INDEX idx_notice_expire_time ON notice(expire_time);
-- 状态+过期时间复合索引
CREATE INDEX idx_notice_status_expire ON notice(status, expire_time);
```
## 🔧 配置说明
### 1. 启用定时任务
在启动类或配置类上添加注解:
```java
@EnableScheduling
```
### 2. 定时任务配置
系统默认每天凌晨2点执行过期处理:
```java
@Scheduled(cron = "0 0 2 * * ?")
```
如需调整执行时间,可修改 `NoticeExpirationTask` 中的 cron 表达式。
## 💻 使用方法
### 1. 创建公告时设置过期时间
#### 前端表单示例
```html
<div class="form-group">
<label>过期时间</label>
<input type="datetime-local" name="expireTime" class="form-control">
<small class="form-text text-muted">
不设置表示永不过期,设置后到期自动下架
</small>
</div>
```
#### 后端实体字段
```java
@Schema(description="过期时间,到期后公告自动下架")
private LocalDateTime expireTime;
```
### 2. 过期时间设置建议
#### 短期公告(1-7天)
- 活动通知
- 临时维护公告
- 节日祝福
#### 中期公告(1-30天)
- 功能更新通知
- 政策变更公告
- 培训通知
#### 长期公告(30天以上)
- 规章制度
- 长期政策
- 重要通知
#### 永不过期
- 系统说明文档
- 基础操作指南
- 重要规章制度
## 🔍 查询逻辑
### 自动过滤规则
所有查询接口都会自动过滤已过期公告:
```java
// 过滤已过期的公告
wrapper.and(w -> w.isNull(NoticeEntity::getExpireTime)
.or()
.gt(NoticeEntity::getExpireTime, LocalDateTime.now()));
```
### 查询逻辑说明
- `expireTime IS NULL`: 永不过期的公告
- `expireTime > NOW()`: 未过期的公告
- `expireTime <= NOW()`: 已过期的公告(自动过滤)
## ⏰ 定时任务详情
### 执行时间
- **频率**: 每天执行一次
- **时间**: 凌晨2点(可配置)
- **时区**: 系统默认时区
### 处理逻辑
1. 查询已过期但状态仍为"已发布"的公告
2. 批量更新状态为"已下架"
3. 记录处理日志
4. 异常处理和错误日志
### 日志示例
```
2025-01-27 02:00:00 INFO - 开始执行通知公告过期处理任务
2025-01-27 02:00:01 INFO - 发现 3 条过期公告,开始处理
2025-01-27 02:00:01 INFO - 公告 [系统维护通知] 已过期,状态已更新为已下架
2025-01-27 02:00:01 INFO - 通知公告过期处理任务执行完成,共处理 3 条过期公告
```
## 🚀 性能优化
### 数据库索引
- 过期时间字段索引,提高过期查询性能
- 状态+过期时间复合索引,优化常用查询
### 查询优化
- 使用 MyBatis-Plus 的 Lambda 查询
- 批量更新过期公告状态
- 避免 N+1 查询问题
## 📊 监控和维护
### 1. 日志监控
- 定时任务执行日志
- 过期公告处理数量
- 异常错误日志
### 2. 数据统计
```sql
-- 统计过期公告数量
SELECT COUNT(*) FROM notice
WHERE expire_time IS NOT NULL
AND expire_time <= NOW()
AND status = '0';
-- 统计即将过期的公告
SELECT COUNT(*) FROM notice
WHERE expire_time IS NOT NULL
AND expire_time BETWEEN NOW() AND DATE_ADD(NOW(), INTERVAL 7 DAY)
AND status = '0';
```
### 3. 定期维护
- 清理过期的过期时间记录
- 监控定时任务执行情况
- 优化数据库查询性能
## ⚠️ 注意事项
### 1. 时区问题
- 确保系统时区设置正确
- 过期时间以系统时区为准
- 考虑跨时区部署的情况
### 2. 性能考虑
- 大量公告时,定时任务执行时间可能较长
- 建议在业务低峰期执行
- 监控数据库性能影响
### 3. 数据一致性
- 定时任务执行期间,公告状态可能短暂不一致
- 查询接口始终过滤过期公告,保证显示一致性
- 建议在定时任务执行期间避免重要操作
## 🔧 故障排除
### 1. 定时任务未执行
**检查项**:
- 是否启用 `@EnableScheduling`
- 定时任务类是否被 Spring 管理
- cron 表达式是否正确
- 系统时间是否正确
### 2. 过期公告仍显示
**检查项**:
- 过期时间字段是否正确设置
- 数据库索引是否创建
- 查询逻辑是否正确
- 定时任务是否正常执行
### 3. 性能问题
**优化建议**:
- 检查数据库索引使用情况
- 优化查询语句
- 调整定时任务执行时间
- 考虑分页处理大量数据
## 📞 技术支持
如遇到问题,请联系技术支持并提供以下信息:
- 错误日志
- 数据库表结构
- 定时任务配置
- 系统环境信息
---
*最后更新时间: 2025-01-27*
*版本: v1.0*
@@ -0,0 +1,16 @@
package com.bsd.pjcloud.integrated.config;
import org.springframework.context.annotation.Configuration;
import org.springframework.scheduling.annotation.EnableScheduling;
/**
* 定时任务配置
* 启用定时任务功能,支持通知公告自动过期处理
*
* @author zjf
* @date 2025-01-27
*/
@Configuration
@EnableScheduling
public class SchedulingConfig {
}
@@ -0,0 +1,65 @@
package com.bsd.pjcloud.integrated.task;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.bsd.pjcloud.integrated.entity.NoticeEntity;
import com.bsd.pjcloud.integrated.service.NoticeService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
import java.time.LocalDateTime;
import java.util.List;
/**
* 通知公告过期处理定时任务
* 自动将过期的公告状态设置为已下架
*
* @author zjf
* @date 2025-01-27
*/
@Slf4j
@Component
@RequiredArgsConstructor
public class NoticeExpirationTask {
private final NoticeService noticeService;
/**
* 每天凌晨2点执行,处理过期的公告
*/
@Scheduled(cron = "0 0 2 * * ?")
public void handleExpiredNotices() {
log.info("开始执行通知公告过期处理任务");
try {
// 查询已过期但状态仍为已发布的公告
LambdaQueryWrapper<NoticeEntity> wrapper = Wrappers.lambdaQuery();
wrapper.eq(NoticeEntity::getStatus, "0") // 状态为已发布
.lt(NoticeEntity::getExpireTime, LocalDateTime.now()) // 过期时间小于当前时间
.isNotNull(NoticeEntity::getExpireTime); // 过期时间不为空
List<NoticeEntity> expiredNotices = noticeService.list(wrapper);
if (expiredNotices.isEmpty()) {
log.info("没有发现过期的公告");
return;
}
log.info("发现 {} 条过期公告,开始处理", expiredNotices.size());
// 批量更新过期公告状态为已下架
for (NoticeEntity notice : expiredNotices) {
notice.setStatus("1"); // 设置为已下架
noticeService.updateById(notice);
log.info("公告 [{}] 已过期,状态已更新为已下架", notice.getTitle());
}
log.info("通知公告过期处理任务执行完成,共处理 {} 条过期公告", expiredNotices.size());
} catch (Exception e) {
log.error("执行通知公告过期处理任务时发生错误", e);
}
}
}
@@ -0,0 +1,12 @@
-- 为通知公告表添加过期时间字段
-- 版本: V1.0.1
-- 描述: 添加过期时间字段,支持公告自动过期功能
ALTER TABLE notice ADD COLUMN expire_time DATETIME COMMENT '过期时间,到期后公告自动下架';
-- 添加索引以提高查询性能
CREATE INDEX idx_notice_expire_time ON notice(expire_time);
CREATE INDEX idx_notice_status_expire ON notice(status, expire_time);
-- 更新现有公告的过期时间为空(表示永不过期)
UPDATE notice SET expire_time = NULL WHERE expire_time IS NULL;