From 14e3193145926180944cef01bb0ee4cbba362b88 Mon Sep 17 00:00:00 2001 From: CR7 <1965214192@qq.com> Date: Sun, 15 Dec 2024 23:48:15 +0800 Subject: [PATCH] =?UTF-8?q?=E6=8F=90=E4=BA=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../shop/service/impl/AreaServiceImpl.java | 73 +++++++++++++++++++ 1 file changed, 73 insertions(+) create mode 100644 yami-shop-service/src/main/java/com/yami/shop/service/impl/AreaServiceImpl.java diff --git a/yami-shop-service/src/main/java/com/yami/shop/service/impl/AreaServiceImpl.java b/yami-shop-service/src/main/java/com/yami/shop/service/impl/AreaServiceImpl.java new file mode 100644 index 0000000..17fa7f3 --- /dev/null +++ b/yami-shop-service/src/main/java/com/yami/shop/service/impl/AreaServiceImpl.java @@ -0,0 +1,73 @@ +/* + * Copyright (c) 2018-2999 广州市蓝海创新科技有限公司 All rights reserved. + * + * https://www.mall4j.com/ + * + * 未经允许,不可做商业用途! + * + * 版权所有,侵权必究! + */ + +// 定义了一个名为com.yami.shop.service.impl的包,用于组织代码 +package com.yami.shop.service.impl; + +// 导入了MyBatis Plus框架中的LambdaQueryWrapper类,用于构建条件查询 +import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; +// 导入了MyBatis Plus框架中的ServiceImpl类,用于提供基础的CRUD操作实现 +import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; +// 导入了Area实体类,这个类代表了数据库中的一个表 +import com.yami.shop.bean.model.Area; +// 导入了AreaMapper接口,用于数据库操作 +import com.yami.shop.dao.AreaMapper; +// 导入了AreaService接口,用于定义业务操作 +import com.yami.shop.service.AreaService; +// 导入了Spring框架的注解,用于注入依赖和定义服务 +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.cache.annotation.CacheEvict; +import org.springframework.cache.annotation.Cacheable; +import org.springframework.stereotype.Service; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.stream.Collectors; + +/** + * 这是一个服务实现类,用于实现AreaService接口中定义的业务操作。 + * + * @author lgh on 2018/10/26 表示这个类的作者是lgh,创建时间为2018年10月26日。 + */ +@Service +public class AreaServiceImpl extends ServiceImpl implements AreaService { + + // 使用Spring的@Autowired注解自动注入AreaMapper + @Autowired + private AreaMapper areaMapper; + + /** + * 通过父id查找地址列表的方法实现。 + * 使用了MyBatis Plus的LambdaQueryWrapper来构建查询条件,查询父id为pid的地址。 + * 使用了Spring的@Cacheable注解,表示这个方法的结果会被缓存,缓存名称为"area",键为方法参数pid。 + * + * @param pid 父id,用于指定要查找的地址的父级地址 + * @return 返回一个Area对象的列表,包含了所有父id为pid的地址信息 + */ + @Override + @Cacheable(cacheNames = "area", key = "#pid") + public List listByPid(Long pid) { + return areaMapper.selectList(new LambdaQueryWrapper().eq(Area::getParentId, pid)); + } + + /** + * 通过父id清除地址缓存的方法实现。 + * 使用了Spring的@CacheEvict注解,表示这个方法会清除缓存,缓存名称为"area",键为方法参数pid。 + * + * @param pid 父id,用于指定要清除缓存的地址的父级地址 + */ + @Override + @CacheEvict(cacheNames = "area", key = "#pid") + public void removeAreaCacheByParentId(Long pid) { + // 方法体为空,清除缓存的逻辑由Spring Cache自动处理 + } +}