tangchuanxing_branch
CR7 9 months ago
parent b5953fadbb
commit 5e2327cce2

@ -0,0 +1,103 @@
/*
* Copyright (c) 2018-2999 广 All rights reserved.
*
* https://www.mall4j.com/
*
*
*
*
*/
package com.yami.shop.service.impl;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.yami.shop.bean.app.dto.NoticeDto;
import com.yami.shop.bean.model.Notice;
import com.yami.shop.dao.NoticeMapper;
import com.yami.shop.service.NoticeService;
import lombok.AllArgsConstructor;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;
import java.util.List;
/**
* NoticeServiceImpl NoticeService
* MyBatis-Plus ServiceImpl NoticeService
* Notice
*
* @author hzm
* @date 2019-04-18 21:21:40
*/
@Service
@AllArgsConstructor // Lombok 注解,自动生成所有构造函数,简化依赖注入
public class NoticeServiceImpl extends ServiceImpl<NoticeMapper, Notice> implements NoticeService {
private final NoticeMapper noticeMapper; // 使用构造器注入 DAO 层组件
/**
* listNotice
* 使 @Cacheable
*
* @return
*/
@Override
@Cacheable(cacheNames = "notices", key = "'notices'")
public List<Notice> listNotice() {
return noticeMapper.selectList(new LambdaQueryWrapper<Notice>()
.eq(Notice::getStatus, 1) // 状态为1表示有效
.eq(Notice::getIsTop, 1) // 是否置顶为1表示置顶
.orderByDesc(Notice::getPublishTime)); // 按发布时间降序排序
}
/**
* removeNoticeList
* 使 @CacheEvict
*/
@Override
@CacheEvict(cacheNames = "notices", key = "'notices'")
public void removeNoticeList() {
// 方法体为空,因为实际的缓存清除工作由 @CacheEvict 注解完成。
}
/**
* pageNotice
*
* @param page
*
* @return IPage<NoticeDto>
*
*/
@Override
public Page<NoticeDto> pageNotice(Page<NoticeDto> page) {
return noticeMapper.pageNotice(page);
}
/**
* getNoticeById ID
* 使 @Cacheable
*
* @param noticeId
* @return Notice ID
*/
@Override
@Cacheable(cacheNames = "notice", key = "#noticeId")
public Notice getNoticeById(Long noticeId) {
return noticeMapper.selectById(noticeId);
}
/**
* removeNoticeById ID
* 使 @CacheEvict
*
* @param noticeId
*/
@Override
@CacheEvict(cacheNames = "notice", key = "#noticeId")
public void removeNoticeById(Long noticeId) {
// 方法体为空,因为实际的缓存清除工作由 @CacheEvict 注解完成。
}
}
Loading…
Cancel
Save