diff --git a/.gitignore b/.gitignore index 5ff6309..2ebe1c7 100644 --- a/.gitignore +++ b/.gitignore @@ -35,4 +35,6 @@ build/ .vscode/ ### Mac OS ### -.DS_Store \ No newline at end of file +.DS_Store + +logs \ No newline at end of file diff --git a/.idea/dataSources.xml b/.idea/dataSources.xml new file mode 100644 index 0000000..2f95d82 --- /dev/null +++ b/.idea/dataSources.xml @@ -0,0 +1,61 @@ + + + + + mysql.8 + true + true + com.mysql.cj.jdbc.Driver + jdbc:mysql://106.15.251.123:3305/shequ-acl?serverTimezone=GMT + + + + + + + $ProjectFileDir$ + + + mysql.8 + true + true + $PROJECT_DIR$/service/service-sys/src/main/resources/application.yml + com.mysql.cj.jdbc.Driver + jdbc:mysql://106.15.251.123:3305/shequ-sys?serverTimezone=GMT + + + + + + + $ProjectFileDir$ + + + mysql.8 + true + true + $PROJECT_DIR$/service/service-product/src/main/resources/application.yml + com.mysql.cj.jdbc.Driver + jdbc:mysql://106.15.251.123:3305/shequ-product?serverTimezone=GMT + + + + + + $ProjectFileDir$ + + + redis + true + true + jdbc.RedisDriver + jdbc:redis://47.120.65.66:6379/0 + + + + + + $ProjectFileDir$ + + + \ No newline at end of file diff --git a/.idea/deployment.xml b/.idea/deployment.xml deleted file mode 100644 index 0ebb202..0000000 --- a/.idea/deployment.xml +++ /dev/null @@ -1,6 +0,0 @@ - - - - - \ No newline at end of file diff --git a/.idea/encodings.xml b/.idea/encodings.xml index 69af3a4..5cb313d 100644 --- a/.idea/encodings.xml +++ b/.idea/encodings.xml @@ -4,6 +4,7 @@ + @@ -13,7 +14,15 @@ + + + + + + + + diff --git a/.idea/misc.xml b/.idea/misc.xml index 5755a99..7b89c3a 100644 --- a/.idea/misc.xml +++ b/.idea/misc.xml @@ -1,9 +1,11 @@ + diff --git a/.idea/uiDesigner.xml b/.idea/uiDesigner.xml new file mode 100644 index 0000000..2b63946 --- /dev/null +++ b/.idea/uiDesigner.xml @@ -0,0 +1,124 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/common/common-util/src/main/java/com/atguigu/common/utils/MD5.java b/common/common-util/src/main/java/com/atguigu/common/utils/MD5.java new file mode 100644 index 0000000..6f7230d --- /dev/null +++ b/common/common-util/src/main/java/com/atguigu/common/utils/MD5.java @@ -0,0 +1,30 @@ +package com.atguigu.common.utils; + +import java.security.MessageDigest; +import java.security.NoSuchAlgorithmException; + + +public final class MD5 { + public static String encrypt(String strSrc) { + try { + char[] hexChars = {'0', '1', '2', '3', '4', '5', '6', '7', '8', + '9', 'a', 'b', 'c', 'd', 'e', 'f'}; + byte[] bytes = strSrc.getBytes(); + MessageDigest md = MessageDigest.getInstance("MD5"); + md.update(bytes); + bytes = md.digest(); + int j = bytes.length; + char[] chars = new char[j * 2]; + int k = 0; + for (int i = 0; i < bytes.length; i++) { + byte b = bytes[i]; + chars[k++] = hexChars[b >>> 4 & 0xf]; + chars[k++] = hexChars[b & 0xf]; + } + return new String(chars); + } catch (NoSuchAlgorithmException e) { + e.printStackTrace(); + throw new RuntimeException("MD5加密出错!!+" + e); + } + } +} diff --git a/common/common-util/src/main/java/com/atguigu/common/utils/PermissionHelper.java b/common/common-util/src/main/java/com/atguigu/common/utils/PermissionHelper.java new file mode 100644 index 0000000..f0ab2f7 --- /dev/null +++ b/common/common-util/src/main/java/com/atguigu/common/utils/PermissionHelper.java @@ -0,0 +1,40 @@ +package com.atguigu.common.utils; + +import com.atguigu.ssyx.model.acl.Permission; + +import java.util.ArrayList; +import java.util.List; + +public class PermissionHelper { + public static List buildPermissions(List permissionList) { + ArrayList trees = new ArrayList<>(); + + permissionList.forEach(permission -> { + if (permission.getPid() == 0) { + permission.setLevel(1); + trees.add(findChildren(permission, permissionList)); + } + }); + + return trees; + } + + private static Permission findChildren(Permission permission, List allList) { + permission.setChildren(new ArrayList<>()); + + allList.forEach(p -> { + if (p.getId().equals(permission.getPid())) { + int level = permission.getLevel() + 1; + p.setLevel(level); + + if (permission.getChildren() == null) { + permission.setChildren(new ArrayList<>()); + } + // 封装下层数据 + permission.getChildren().add(findChildren(p, allList)); + } + }); + + return permission; + } +} diff --git a/common/pom.xml b/common/pom.xml index f90885c..721a070 100644 --- a/common/pom.xml +++ b/common/pom.xml @@ -15,6 +15,7 @@ common-util service-util + rabbit-util @@ -50,5 +51,11 @@ org.springframework.cloud spring-cloud-starter-openfeign + + + + io.minio + minio + diff --git a/common/rabbit-util/pom.xml b/common/rabbit-util/pom.xml new file mode 100644 index 0000000..1878dfd --- /dev/null +++ b/common/rabbit-util/pom.xml @@ -0,0 +1,26 @@ + + 4.0.0 + + com.atguigu + common + 1.0-SNAPSHOT + + rabbit-util + Archetype - rabbit-util + https://maven.apache.org + + + + + org.springframework.cloud + spring-cloud-starter-bus-amqp + + + + com.fasterxml.jackson.dataformat + jackson-dataformat-xml + 2.16.0-rc1 + + + diff --git a/common/rabbit-util/src/main/java/com/atguigu/ssyx/mq/config/RabbitMQConfiguration.java b/common/rabbit-util/src/main/java/com/atguigu/ssyx/mq/config/RabbitMQConfiguration.java new file mode 100644 index 0000000..056e457 --- /dev/null +++ b/common/rabbit-util/src/main/java/com/atguigu/ssyx/mq/config/RabbitMQConfiguration.java @@ -0,0 +1,28 @@ +package com.atguigu.ssyx.mq.config; + +import org.springframework.amqp.support.converter.Jackson2JsonMessageConverter; +import org.springframework.amqp.support.converter.MessageConverter; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; + +@Configuration +public class RabbitMQConfiguration { + /** + * * 重写,并引入消息转换器 + * + * com.fasterxml.jackson.dataformat + * jackson-dataformat-xml + * 2.16.0-rc1 + * + * + * @return MessageConverter + */ + @Bean + public MessageConverter jsonMessageConverter() { + // 1.定义消息转换器 + Jackson2JsonMessageConverter converter = new Jackson2JsonMessageConverter(); + // 2.配置自动创建消息id,用于识别不同消息,也可以在业务中基于ID判断是否是重复消息 + converter.setCreateMessageIds(true); + return converter; + } +} \ No newline at end of file diff --git a/common/rabbit-util/src/main/java/com/atguigu/ssyx/mq/constant/MqConst.java b/common/rabbit-util/src/main/java/com/atguigu/ssyx/mq/constant/MqConst.java new file mode 100644 index 0000000..abaf16e --- /dev/null +++ b/common/rabbit-util/src/main/java/com/atguigu/ssyx/mq/constant/MqConst.java @@ -0,0 +1,53 @@ +package com.atguigu.ssyx.mq.constant; + +public class MqConst { + // 消息补偿 + public static final String MQ_KEY_PREFIX = "ssyx.mq:list"; + public static final int RETRY_COUNT = 3; + + // 商品上下架 + public static final String EXCHANGE_GOODS_DIRECT = "ssyx.goods.direct"; + public static final String ROUTING_GOODS_UPPER = "ssyx.goods.upper"; + public static final String ROUTING_GOODS_LOWER = "ssyx.goods.lower"; + // 队列 + public static final String QUEUE_GOODS_UPPER = "ssyx.goods.upper"; + public static final String QUEUE_GOODS_LOWER = "ssyx.goods.lower"; + + // 团长上下线 + public static final String EXCHANGE_LEADER_DIRECT = "ssyx.leader.direct"; + public static final String ROUTING_LEADER_UPPER = "ssyx.leader.upper"; + public static final String ROUTING_LEADER_LOWER = "ssyx.leader.lower"; + // 队列 + public static final String QUEUE_LEADER_UPPER = "ssyx.leader.upper"; + public static final String QUEUE_LEADER_LOWER = "ssyx.leader.lower"; + + // 订单 + public static final String EXCHANGE_ORDER_DIRECT = "ssyx.order.direct"; + public static final String ROUTING_ROLLBACK_STOCK = "ssyx.rollback.stock"; + public static final String ROUTING_MINUS_STOCK = "ssyx.minus.stock"; + + public static final String ROUTING_DELETE_CART = "ssyx.delete.cart"; + // 解锁普通商品库存 + public static final String QUEUE_ROLLBACK_STOCK = "ssyx.rollback.stock"; + public static final String QUEUE_SECKILL_ROLLBACK_STOCK = "ssyx.seckill.rollback.stock"; + public static final String QUEUE_MINUS_STOCK = "ssyx.minus.stock"; + public static final String QUEUE_DELETE_CART = "ssyx.delete.cart"; + + // 支付 + public static final String EXCHANGE_PAY_DIRECT = "ssyx.pay.direct"; + public static final String ROUTING_PAY_SUCCESS = "ssyx.pay.success"; + public static final String QUEUE_ORDER_PAY = "ssyx.order.pay"; + public static final String QUEUE_LEADER_BILL = "ssyx.leader.bill"; + + // 取消订单 + public static final String EXCHANGE_CANCEL_ORDER_DIRECT = "ssyx.cancel.order.direct"; + public static final String ROUTING_CANCEL_ORDER = "ssyx.cancel.order"; + // 延迟取消订单队列 + public static final String QUEUE_CANCEL_ORDER = "ssyx.cancel.order"; + + // 定时任务 + public static final String EXCHANGE_DIRECT_TASK = "ssyx.exchange.direct.task"; + public static final String ROUTING_TASK_23 = "ssyx.task.23"; + // 队列 + public static final String QUEUE_TASK_23 = "ssyx.queue.task.23"; +} \ No newline at end of file diff --git a/common/rabbit-util/src/main/java/com/atguigu/ssyx/mq/service/RabbitService.java b/common/rabbit-util/src/main/java/com/atguigu/ssyx/mq/service/RabbitService.java new file mode 100644 index 0000000..2b88788 --- /dev/null +++ b/common/rabbit-util/src/main/java/com/atguigu/ssyx/mq/service/RabbitService.java @@ -0,0 +1,22 @@ +package com.atguigu.ssyx.mq.service; + +import org.springframework.amqp.rabbit.core.RabbitTemplate; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +@Service +public class RabbitService { + @Autowired + private RabbitTemplate rabbitTemplate; + + /** + * 发送消息 + * + * @param exchange 交换机 + * @param routerKey 路由 + * @param message 消息 + */ + public void sendMessage(String exchange, String routerKey, Object message) { + rabbitTemplate.convertAndSend(exchange, routerKey, message); + } +} \ No newline at end of file diff --git a/common/service-util/pom.xml b/common/service-util/pom.xml index 42c8fe1..8662030 100644 --- a/common/service-util/pom.xml +++ b/common/service-util/pom.xml @@ -55,5 +55,23 @@ mybatis-plus-boot-starter provided + + + com.baomidou + mybatis-plus-generator + 3.4.1 + + + + org.apache.velocity + velocity-engine-core + 2.0 + + + + + mysql + mysql-connector-java + diff --git a/common/service-util/src/main/java/com/atguigu/ssyx/common/CodeGet.java b/common/service-util/src/main/java/com/atguigu/ssyx/common/CodeGet.java new file mode 100644 index 0000000..4119363 --- /dev/null +++ b/common/service-util/src/main/java/com/atguigu/ssyx/common/CodeGet.java @@ -0,0 +1,70 @@ +package com.atguigu.ssyx.common; + +import com.baomidou.mybatisplus.annotation.DbType; +import com.baomidou.mybatisplus.generator.AutoGenerator; +import com.baomidou.mybatisplus.generator.config.DataSourceConfig; +import com.baomidou.mybatisplus.generator.config.GlobalConfig; +import com.baomidou.mybatisplus.generator.config.PackageConfig; +import com.baomidou.mybatisplus.generator.config.StrategyConfig; +import com.baomidou.mybatisplus.generator.config.rules.NamingStrategy; +import org.jetbrains.annotations.NotNull; + +public class CodeGet { + + public static void main(String[] args) { + // 1、创建代码生成器 + AutoGenerator mpg = new AutoGenerator(); + + // 2、全局配置 + // 全局配置 + GlobalConfig gc = new GlobalConfig(); + // TODO 需要修改路径名称 + gc.setOutputDir("G:\\File\\Java\\ssyx\\ssyx-parent\\service\\service-activity" + "/src/main/java"); + + gc.setServiceName("%sService"); // 去掉Service接口的首字母I + gc.setAuthor("bunny"); + gc.setOpen(false); + mpg.setGlobalConfig(gc); + + // 3、数据源配置 + DataSourceConfig dsc = new DataSourceConfig(); + // TODO 需要修改数据库 + dsc.setUrl("jdbc:mysql://106.15.251.123:3305/shequ-activity?serverTimezone=GMT%2B8&useSSL=false&characterEncoding=utf-8&allowPublicKeyRetrieval=true"); + dsc.setDriverName("com.mysql.cj.jdbc.Driver"); + dsc.setUsername("root"); + dsc.setPassword("02120212"); + dsc.setDbType(DbType.MYSQL); + mpg.setDataSource(dsc); + + // 4、包配置 + PackageConfig pc = new PackageConfig(); + pc.setParent("com.atguigu.ssyx"); + // TODO 需要修改模块名 + pc.setModuleName("activity"); + pc.setController("controller"); + pc.setService("service"); + pc.setMapper("mapper"); + mpg.setPackageInfo(pc); + + // 5、策略配置 + StrategyConfig strategy = getStrategyConfig(); + + mpg.setStrategy(strategy); + + // 6、执行 + mpg.execute(); + } + + @NotNull + private static StrategyConfig getStrategyConfig() { + StrategyConfig strategy = new StrategyConfig(); + + strategy.setInclude("activity_info", "activity_rule", "activity_sku", "coupon_info", "coupon_range", "coupon_use"); + strategy.setNaming(NamingStrategy.underline_to_camel);// 数据库表映射到实体的命名策略 + strategy.setColumnNaming(NamingStrategy.underline_to_camel);// 数据库表字段映射到实体的命名策略 + strategy.setEntityLombokModel(true); // lombok 模型 @Accessors(chain = true) setter链式操作 + strategy.setRestControllerStyle(true); // restful api风格控制器 + strategy.setControllerMappingHyphenStyle(true); // url中驼峰转连字符 + return strategy; + } +} diff --git a/common/service-util/src/main/java/com/atguigu/ssyx/common/config/MybatisPlusConfig.java b/common/service-util/src/main/java/com/atguigu/ssyx/common/config/MybatisPlusConfig.java index 4448f6b..3f95846 100644 --- a/common/service-util/src/main/java/com/atguigu/ssyx/common/config/MybatisPlusConfig.java +++ b/common/service-util/src/main/java/com/atguigu/ssyx/common/config/MybatisPlusConfig.java @@ -6,6 +6,7 @@ import com.baomidou.mybatisplus.extension.plugins.inner.BlockAttackInnerIntercep import com.baomidou.mybatisplus.extension.plugins.inner.OptimisticLockerInnerInterceptor; import com.baomidou.mybatisplus.extension.plugins.inner.PaginationInnerInterceptor; import lombok.extern.slf4j.Slf4j; +import org.mybatis.spring.annotation.MapperScan; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.transaction.annotation.EnableTransactionManagement; @@ -14,6 +15,7 @@ import org.springframework.transaction.annotation.EnableTransactionManagement; * MybatisPlus配置类 */ @EnableTransactionManagement +@MapperScan("com.atguigu.ssyx.*.mapper") @Configuration @Slf4j public class MybatisPlusConfig { @@ -24,7 +26,7 @@ public class MybatisPlusConfig { @Bean public MybatisPlusInterceptor optimisticLockerInnerInterceptor() { log.info("注入MybatisPlus配置类..."); - + MybatisPlusInterceptor interceptor = new MybatisPlusInterceptor(); // 向Mybatis过滤器链中添加分页拦截器 interceptor.addInnerInterceptor(new PaginationInnerInterceptor(DbType.MYSQL)); diff --git a/common/service-util/src/main/java/com/atguigu/ssyx/common/config/RedisConfiguration.java b/common/service-util/src/main/java/com/atguigu/ssyx/common/config/RedisConfiguration.java new file mode 100644 index 0000000..c3d6ca5 --- /dev/null +++ b/common/service-util/src/main/java/com/atguigu/ssyx/common/config/RedisConfiguration.java @@ -0,0 +1,99 @@ +package com.atguigu.ssyx.common.config; + +import com.fasterxml.jackson.annotation.JsonAutoDetect; +import com.fasterxml.jackson.annotation.PropertyAccessor; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.databind.SerializationFeature; +import com.fasterxml.jackson.databind.jsontype.impl.LaissezFaireSubTypeValidator; +import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule; +import com.fasterxml.jackson.datatype.jsr310.deser.LocalDateDeserializer; +import com.fasterxml.jackson.datatype.jsr310.deser.LocalDateTimeDeserializer; +import com.fasterxml.jackson.datatype.jsr310.ser.LocalDateSerializer; +import com.fasterxml.jackson.datatype.jsr310.ser.LocalDateTimeSerializer; +import lombok.extern.slf4j.Slf4j; +import org.springframework.cache.CacheManager; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import org.springframework.data.redis.cache.RedisCacheConfiguration; +import org.springframework.data.redis.cache.RedisCacheManager; +import org.springframework.data.redis.connection.RedisConnectionFactory; +import org.springframework.data.redis.connection.lettuce.LettuceConnectionFactory; +import org.springframework.data.redis.core.RedisTemplate; +import org.springframework.data.redis.serializer.GenericJackson2JsonRedisSerializer; +import org.springframework.data.redis.serializer.Jackson2JsonRedisSerializer; +import org.springframework.data.redis.serializer.RedisSerializationContext; +import org.springframework.data.redis.serializer.StringRedisSerializer; + +import java.time.LocalDate; +import java.time.LocalDateTime; +import java.time.format.DateTimeFormatter; + +@Configuration +@Slf4j +public class RedisConfiguration { + /** + * 使用StringRedisSerializer序列化为字符串 + */ + @Bean + public RedisTemplate redisTemplate(LettuceConnectionFactory connectionFactory) { + log.info("RedisConfiguration===>使用StringRedisSerializer序列化为字符串"); + + RedisTemplate redisTemplate = new RedisTemplate<>(); + redisTemplate.setConnectionFactory(connectionFactory); + // 设置key序列化为string + redisTemplate.setKeySerializer(new StringRedisSerializer()); + // 设置value序列化为JSON,使用GenericJackson2JsonRedisSerializer替换默认序列化 + redisTemplate.setValueSerializer(new GenericJackson2JsonRedisSerializer()); + redisTemplate.setHashKeySerializer(new StringRedisSerializer()); + redisTemplate.setHashValueSerializer(new GenericJackson2JsonRedisSerializer()); + + return redisTemplate; + } + + /** + * 解决cache(@Cacheable)把数据缓存到redis中的value是乱码问题 + */ + @Bean + @SuppressWarnings("all") + public CacheManager cacheManager(RedisConnectionFactory factory) { + log.info("RedisConfiguration===>解决cache(@Cacheable)把数据缓存到redis中的value是乱码问题"); + + StringRedisSerializer redisSerializer = new StringRedisSerializer(); + // 配置序列化 + RedisCacheConfiguration config = RedisCacheConfiguration.defaultCacheConfig(); + RedisCacheConfiguration redisCacheConfiguration = config + .serializeKeysWith(RedisSerializationContext.SerializationPair.fromSerializer(redisSerializer)) + .serializeValuesWith(RedisSerializationContext.SerializationPair.fromSerializer(jsonRedisSerializer())); + + RedisCacheManager cacheManager = RedisCacheManager.builder(factory) + .cacheDefaults(redisCacheConfiguration).build(); + return cacheManager; + } + + /** + * 指定的日期模式 + */ + public Jackson2JsonRedisSerializer jsonRedisSerializer() { + log.info("RedisConfiguration===>指定的日期模式"); + + Jackson2JsonRedisSerializer serializer = new Jackson2JsonRedisSerializer<>(Object.class); + ObjectMapper mapper = new ObjectMapper(); + // 设置ObjectMapper访问权限 + mapper.setVisibility(PropertyAccessor.ALL, JsonAutoDetect.Visibility.ANY); + // 记录序列化之后的数据类型,方便反序列化 + mapper.activateDefaultTyping(LaissezFaireSubTypeValidator.instance, ObjectMapper.DefaultTyping.NON_FINAL); + // LocalDatetime序列化,默认不兼容jdk8日期序列化 + JavaTimeModule timeModule = new JavaTimeModule(); + timeModule.addDeserializer(LocalDate.class, new LocalDateDeserializer(DateTimeFormatter.ofPattern("yyyy-MM-dd"))); + timeModule.addSerializer(LocalDate.class, new LocalDateSerializer(DateTimeFormatter.ofPattern("yyyy-MM-dd"))); + + timeModule.addDeserializer(LocalDateTime.class, new LocalDateTimeDeserializer(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"))); + timeModule.addSerializer(LocalDateTime.class, new LocalDateTimeSerializer(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"))); + // 关闭默认的日期格式化方式,默认UTC日期格式 yyyy-MM-dd’T’HH:mm:ss.SSS + mapper.disable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS); + mapper.registerModule(timeModule); + + serializer.setObjectMapper(mapper); + return serializer; + } +} \ No newline at end of file diff --git a/common/service-util/src/main/java/com/atguigu/ssyx/common/config/WebMvcConfiguration.java b/common/service-util/src/main/java/com/atguigu/ssyx/common/config/WebMvcConfiguration.java index 23ad6be..8827deb 100644 --- a/common/service-util/src/main/java/com/atguigu/ssyx/common/config/WebMvcConfiguration.java +++ b/common/service-util/src/main/java/com/atguigu/ssyx/common/config/WebMvcConfiguration.java @@ -2,24 +2,10 @@ package com.atguigu.ssyx.common.config; import lombok.extern.slf4j.Slf4j; import org.springframework.context.annotation.Configuration; -import org.springframework.web.servlet.config.annotation.CorsRegistry; import org.springframework.web.servlet.config.annotation.WebMvcConfigurer; @Configuration @Slf4j public class WebMvcConfiguration implements WebMvcConfigurer { - /** - * * 解决跨域 - * - * @param registry 跨域注册表 - */ - @Override - public void addCorsMappings(CorsRegistry registry) { - log.info("WebMvcConfiguration===>开始跨域注册表..."); - registry.addMapping("/admin/**")// 添加路径规则 - .allowCredentials(true)// 是否允许在跨域的情况下传递Cookie - .allowedOrigins("*")// 允许请求来源的域规则 - .allowedMethods("*").allowedHeaders("*");// 允许所有的请求头 - } } \ No newline at end of file diff --git a/common/service-util/src/main/java/com/atguigu/ssyx/common/properties/MinioProperties.java b/common/service-util/src/main/java/com/atguigu/ssyx/common/properties/MinioProperties.java new file mode 100644 index 0000000..9605787 --- /dev/null +++ b/common/service-util/src/main/java/com/atguigu/ssyx/common/properties/MinioProperties.java @@ -0,0 +1,27 @@ +package com.atguigu.ssyx.common.properties; + +import io.minio.MinioClient; +import lombok.Data; +import lombok.extern.slf4j.Slf4j; +import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; +import org.springframework.boot.context.properties.ConfigurationProperties; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; + +@Configuration +@ConfigurationProperties(prefix = "bunny.minio") +@ConditionalOnProperty(name = "bunny.minio.bucket-name")// 当属性有值时这个配置才生效 +@Data +@Slf4j +public class MinioProperties { + private String endpointUrl; + private String accessKey; + private String secretKey; + private String bucketName; + + @Bean + public MinioClient minioClient() { + log.info("注册MinioClient..."); + return MinioClient.builder().endpoint(endpointUrl).credentials(accessKey, secretKey).build(); + } +} diff --git a/common/service-util/src/main/java/com/atguigu/ssyx/common/result/ResultCodeEnum.java b/common/service-util/src/main/java/com/atguigu/ssyx/common/result/ResultCodeEnum.java index 1fd6b5b..850005c 100644 --- a/common/service-util/src/main/java/com/atguigu/ssyx/common/result/ResultCodeEnum.java +++ b/common/service-util/src/main/java/com/atguigu/ssyx/common/result/ResultCodeEnum.java @@ -8,7 +8,7 @@ import lombok.Getter; @Getter public enum ResultCodeEnum { - SUCCESS(200, "成功"), + SUCCESS(200, "操作成功"), FAIL(201, "失败"), SERVICE_ERROR(2012, "服务异常"), DATA_ERROR(204, "数据异常"), diff --git a/model/pom.xml b/model/pom.xml index 2a1b98a..bda3779 100644 --- a/model/pom.xml +++ b/model/pom.xml @@ -33,8 +33,7 @@ com.github.xiaoymin knife4j-spring-boot-starter - - provided + 3.0.3 diff --git a/model/src/main/java/com/atguigu/ssyx/model/acl/AdminRole.java b/model/src/main/java/com/atguigu/ssyx/model/acl/AdminRole.java index a6d6c42..6fa3fd4 100644 --- a/model/src/main/java/com/atguigu/ssyx/model/acl/AdminRole.java +++ b/model/src/main/java/com/atguigu/ssyx/model/acl/AdminRole.java @@ -19,16 +19,14 @@ import lombok.Data; @ApiModel(description = "用户角色") @TableName("admin_role") public class AdminRole extends BaseEntity { - - private static final long serialVersionUID = 1L; - - @ApiModelProperty(value = "角色id") - @TableField("role_id") - private Long roleId; + private static final long serialVersionUID = 1L; - @ApiModelProperty(value = "用户id") - @TableField("admin_id") - private Long adminId; + @ApiModelProperty(value = "角色id") + @TableField("role_id") + private Long roleId; + @ApiModelProperty(value = "用户id") + @TableField("admin_id") + private Long adminId; } diff --git a/model/src/main/java/com/atguigu/ssyx/model/product/SkuInfo.java b/model/src/main/java/com/atguigu/ssyx/model/product/SkuInfo.java index 591e27f..11ae897 100644 --- a/model/src/main/java/com/atguigu/ssyx/model/product/SkuInfo.java +++ b/model/src/main/java/com/atguigu/ssyx/model/product/SkuInfo.java @@ -13,78 +13,77 @@ import java.math.BigDecimal; @ApiModel(description = "SkuInfo") @TableName("sku_info") public class SkuInfo extends BaseEntity { + private static final long serialVersionUID = 1L; - private static final long serialVersionUID = 1L; + @ApiModelProperty(value = "分类id") + @TableField("category_id") + private Long categoryId; - @ApiModelProperty(value = "分类id") - @TableField("category_id") - private Long categoryId; + @ApiModelProperty(value = "平台属性分组id") + @TableField("attr_group_id") + private Long attrGroupId; - @ApiModelProperty(value = "平台属性分组id") - @TableField("attr_group_id") - private Long attrGroupId; + @ApiModelProperty(value = "商品类型:0->普通商品 1->秒杀商品") + @TableField("sku_type") + private Integer skuType; - @ApiModelProperty(value = "商品类型:0->普通商品 1->秒杀商品") - @TableField("sku_type") - private Integer skuType; + @ApiModelProperty(value = "spu名称") + @TableField("sku_name") + private String skuName; - @ApiModelProperty(value = "spu名称") - @TableField("sku_name") - private String skuName; + @ApiModelProperty(value = "展示图片") + @TableField("img_url") + private String imgUrl; - @ApiModelProperty(value = "展示图片") - @TableField("img_url") - private String imgUrl; + @ApiModelProperty(value = "限购个数/每天(0:不限购)") + @TableField("per_limit") + private Integer perLimit; - @ApiModelProperty(value = "限购个数/每天(0:不限购)") - @TableField("per_limit") - private Integer perLimit; + @ApiModelProperty(value = "上架状态:0->下架;1->上架") + @TableField("publish_status") + private Integer publishStatus; - @ApiModelProperty(value = "上架状态:0->下架;1->上架") - @TableField("publish_status") - private Integer publishStatus; + @ApiModelProperty(value = "审核状态:0->未审核;1->审核通过") + @TableField("check_status") + private Integer checkStatus; - @ApiModelProperty(value = "审核状态:0->未审核;1->审核通过") - @TableField("check_status") - private Integer checkStatus; + @ApiModelProperty(value = "是否新人专享:0->否;1->是") + @TableField("is_new_person") + private Integer isNewPerson; - @ApiModelProperty(value = "是否新人专享:0->否;1->是") - @TableField("is_new_person") - private Integer isNewPerson; + @ApiModelProperty(value = "排序") + @TableField("sort") + private Integer sort; - @ApiModelProperty(value = "排序") - @TableField("sort") - private Integer sort; + @ApiModelProperty(value = "sku编码") + @TableField("sku_code") + private String skuCode; - @ApiModelProperty(value = "sku编码") - @TableField("sku_code") - private String skuCode; + @ApiModelProperty(value = "价格") + @TableField("price") + private BigDecimal price; - @ApiModelProperty(value = "价格") - @TableField("price") - private BigDecimal price; + @ApiModelProperty(value = "市场价") + @TableField("market_price") + private BigDecimal marketPrice; - @ApiModelProperty(value = "市场价") - @TableField("market_price") - private BigDecimal marketPrice; + @ApiModelProperty(value = "库存") + @TableField("stock") + private Integer stock; - @ApiModelProperty(value = "库存") - @TableField("stock") - private Integer stock; + @ApiModelProperty(value = "锁定库存") + @TableField("lock_stock") + private Integer lockStock; - @ApiModelProperty(value = "锁定库存") - @TableField("lock_stock") - private Integer lockStock; + @ApiModelProperty(value = "预警库存") + @TableField("low_stock") + private Integer lowStock; - @ApiModelProperty(value = "预警库存") - @TableField("low_stock") - private Integer lowStock; + @ApiModelProperty(value = "销量") + @TableField("sale") + private Integer sale; - @ApiModelProperty(value = "销量") - @TableField("sale") - private Integer sale; - - @ApiModelProperty(value = "仓库") - @TableField("ware_id") - private Long wareId; + @ApiModelProperty(value = "仓库") + @TableField("ware_id") + private Long wareId; } \ No newline at end of file diff --git a/model/src/main/java/com/atguigu/ssyx/model/search/SkuEs.java b/model/src/main/java/com/atguigu/ssyx/model/search/SkuEs.java index 4fdd392..fe1a27b 100644 --- a/model/src/main/java/com/atguigu/ssyx/model/search/SkuEs.java +++ b/model/src/main/java/com/atguigu/ssyx/model/search/SkuEs.java @@ -1,22 +1,16 @@ package com.atguigu.ssyx.model.search; -import com.baomidou.mybatisplus.annotation.TableField; -import com.fasterxml.jackson.annotation.JsonFormat; -import io.swagger.annotations.ApiModelProperty; import lombok.Data; import org.springframework.data.annotation.Id; -import org.springframework.data.elasticsearch.annotations.DateFormat; import org.springframework.data.elasticsearch.annotations.Document; import org.springframework.data.elasticsearch.annotations.Field; import org.springframework.data.elasticsearch.annotations.FieldType; -import java.util.Date; import java.util.List; @Data -@Document(indexName = "skues" ,shards = 3,replicas = 1) +@Document(indexName = "skues", shards = 3, replicas = 1) public class SkuEs { - // 商品Id= skuId @Id private Long id; @@ -64,5 +58,4 @@ public class SkuEs { @Field(type = FieldType.Object, index = false) private List ruleList; - } diff --git a/model/src/main/java/com/atguigu/ssyx/vo/acl/AssignAdminRoleVo.java b/model/src/main/java/com/atguigu/ssyx/vo/acl/AssignAdminRoleVo.java new file mode 100644 index 0000000..d8939b8 --- /dev/null +++ b/model/src/main/java/com/atguigu/ssyx/vo/acl/AssignAdminRoleVo.java @@ -0,0 +1,24 @@ +package com.atguigu.ssyx.vo.acl; + +import com.atguigu.ssyx.model.acl.Role; +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Data; +import lombok.NoArgsConstructor; + +import java.util.List; + +@Data +@Builder +@AllArgsConstructor +@NoArgsConstructor +@ApiModel(description = "所有角色数据") +public class AssignAdminRoleVo { + @ApiModelProperty(value = "角色列表数据") + private List assignRoles; + + @ApiModelProperty(value = "所有角色数据") + private List allRolesList; +} diff --git a/model/src/main/java/com/atguigu/ssyx/vo/acl/LoginInfoVo.java b/model/src/main/java/com/atguigu/ssyx/vo/acl/LoginInfoVo.java new file mode 100644 index 0000000..e66ce22 --- /dev/null +++ b/model/src/main/java/com/atguigu/ssyx/vo/acl/LoginInfoVo.java @@ -0,0 +1,21 @@ +package com.atguigu.ssyx.vo.acl; + +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Data; +import lombok.NoArgsConstructor; + +@Data +@Builder +@AllArgsConstructor +@NoArgsConstructor +@ApiModel(description = "返回用户信息") +public class LoginInfoVo { + @ApiModelProperty(value = "用户名") + private String name; + + @ApiModelProperty(value = "头像") + private String avatar; +} diff --git a/model/src/main/java/com/atguigu/ssyx/vo/acl/LoginVo.java b/model/src/main/java/com/atguigu/ssyx/vo/acl/LoginVo.java new file mode 100644 index 0000000..e7a00b2 --- /dev/null +++ b/model/src/main/java/com/atguigu/ssyx/vo/acl/LoginVo.java @@ -0,0 +1,18 @@ +package com.atguigu.ssyx.vo.acl; + +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Data; +import lombok.NoArgsConstructor; + +@Data +@Builder +@AllArgsConstructor +@NoArgsConstructor +@ApiModel(description = "登录成功后返回") +public class LoginVo { + @ApiModelProperty(value = "token") + private String token; +} diff --git a/model/src/main/java/com/atguigu/ssyx/vo/acl/RoleQueryVo.java b/model/src/main/java/com/atguigu/ssyx/vo/acl/RoleQueryVo.java index 2c1195a..8ada138 100644 --- a/model/src/main/java/com/atguigu/ssyx/vo/acl/RoleQueryVo.java +++ b/model/src/main/java/com/atguigu/ssyx/vo/acl/RoleQueryVo.java @@ -19,11 +19,9 @@ import java.io.Serializable; @Data @ApiModel(description = "角色查询实体") public class RoleQueryVo implements Serializable { - - private static final long serialVersionUID = 1L; - - @ApiModelProperty(value = "角色名称") - private String roleName; + private static final long serialVersionUID = 1L; + @ApiModelProperty(value = "角色名称") + private String roleName; } diff --git a/model/src/main/java/com/atguigu/ssyx/vo/product/SkuInfoVo.java b/model/src/main/java/com/atguigu/ssyx/vo/product/SkuInfoVo.java index 840474d..9a6d846 100644 --- a/model/src/main/java/com/atguigu/ssyx/vo/product/SkuInfoVo.java +++ b/model/src/main/java/com/atguigu/ssyx/vo/product/SkuInfoVo.java @@ -1,26 +1,25 @@ package com.atguigu.ssyx.vo.product; -import com.atguigu.ssyx.model.product.*; import com.atguigu.ssyx.model.product.SkuAttrValue; import com.atguigu.ssyx.model.product.SkuImage; import com.atguigu.ssyx.model.product.SkuInfo; import com.atguigu.ssyx.model.product.SkuPoster; import io.swagger.annotations.ApiModelProperty; import lombok.Data; +import lombok.EqualsAndHashCode; import java.util.List; +@EqualsAndHashCode(callSuper = true) @Data public class SkuInfoVo extends SkuInfo { + @ApiModelProperty(value = "海报列表") + private List skuPosterList; - @ApiModelProperty(value = "海报列表") - private List skuPosterList; - - @ApiModelProperty(value = "属性值") - private List skuAttrValueList; - - @ApiModelProperty(value = "图片") - private List skuImagesList; + @ApiModelProperty(value = "属性值") + private List skuAttrValueList; + @ApiModelProperty(value = "图片") + private List skuImagesList; } diff --git a/pom.xml b/pom.xml index c927133..999a7f3 100644 --- a/pom.xml +++ b/pom.xml @@ -18,6 +18,7 @@ common model service + service-client @@ -37,6 +38,7 @@ 2.0.8 2.10.1 2.3.0 + 8.4.3 @@ -108,30 +110,49 @@ xxl-job-core ${xxl-job.version} + + + io.minio + minio + ${minio.version} + + + + com.squareup.okhttp3 + okhttp + 4.9.3 + + + + + cn.hutool + hutool-all + 5.8.25 + - - - nexus-aliyun - Nexus aliyun - default - https://maven.aliyun.com/repository/public - - false - - - true - - - - spring - https://maven.aliyun.com/repository/spring - - true - - - true - - - + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/service-client/pom.xml b/service-client/pom.xml new file mode 100644 index 0000000..b6ad079 --- /dev/null +++ b/service-client/pom.xml @@ -0,0 +1,53 @@ + + 4.0.0 + + com.atguigu + guigu-ssyx-parent + 1.0-SNAPSHOT + + + service-client + pom + + service-client + https://maven.apache.org + + service-product-client + + + + UTF-8 + + + + + com.atguigu + service-util + 1.0-SNAPSHOT + + + + com.atguigu + model + 1.0-SNAPSHOT + + + + org.springframework.boot + spring-boot-starter-web + + + + + org.springframework.cloud + spring-cloud-starter-openfeign + + + + + org.springframework.cloud + spring-cloud-loadbalancer + + + diff --git a/service-client/service-product-client/pom.xml b/service-client/service-product-client/pom.xml new file mode 100644 index 0000000..f56182b --- /dev/null +++ b/service-client/service-product-client/pom.xml @@ -0,0 +1,23 @@ + + 4.0.0 + + com.atguigu + service-client + 1.0-SNAPSHOT + + + service-product-client + jar + + service-product-client + https://maven.apache.org + + + UTF-8 + + + + + + diff --git a/service-client/service-product-client/src/main/java/com/atguigu/ssyx/client/product/ProductFeignClient.java b/service-client/service-product-client/src/main/java/com/atguigu/ssyx/client/product/ProductFeignClient.java new file mode 100644 index 0000000..fb684ca --- /dev/null +++ b/service-client/service-product-client/src/main/java/com/atguigu/ssyx/client/product/ProductFeignClient.java @@ -0,0 +1,17 @@ +package com.atguigu.ssyx.client.product; + +import com.atguigu.ssyx.common.result.Result; +import com.atguigu.ssyx.model.product.Category; +import com.atguigu.ssyx.model.product.SkuInfo; +import org.springframework.cloud.openfeign.FeignClient; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PathVariable; + +@FeignClient(value = "service-product", path = "/api/product") +public interface ProductFeignClient { + @GetMapping("inner/getCategory/{categoryId}") + Result getCategory(@PathVariable Long categoryId); + + @GetMapping("inner/getSkuInfo/{skuId}") + Result getSkuInfo(@PathVariable Long skuId); +} diff --git a/service-gateway/Dockerfile b/service-gateway/Dockerfile new file mode 100644 index 0000000..ef109ac --- /dev/null +++ b/service-gateway/Dockerfile @@ -0,0 +1,21 @@ +FROM openjdk:17 +MAINTAINER bunny + +#系统编码 +ENV LANG=C.UTF-8 LC_ALL=C.UTF-8 + +# 设置时区,构建镜像时执行的命令 +RUN ln -sf /usr/share/zoneinfo/Asia/Shanghai /etc/localtime +RUN echo "Asia/Shanghai" > /etc/timezone + +# 设定工作目录 +WORKDIR /home/bunny + +# 复制jar包 +COPY target/*.jar /home/bunny/app.jar + +#启动容器时的进程 +ENTRYPOINT ["java","-jar","/home/bunny/app.jar"] + +#暴露 8080 端口 +EXPOSE 8080 \ No newline at end of file diff --git a/service-gateway/pom.xml b/service-gateway/pom.xml new file mode 100644 index 0000000..0a956dd --- /dev/null +++ b/service-gateway/pom.xml @@ -0,0 +1,47 @@ + + 4.0.0 + + com.atguigu + guigu-ssyx-parent + 1.0-SNAPSHOT + + + service-gateway + jar + + service-gateway + https://maven.apache.org + + + UTF-8 + + + + + com.atguigu + service-util + 1.0-SNAPSHOT + + + + com.alibaba.cloud + spring-cloud-starter-alibaba-sentinel + + + + org.springframework.cloud + spring-cloud-loadbalancer + + + + org.springframework.cloud + spring-cloud-starter-gateway + + + + com.alibaba.cloud + spring-cloud-starter-alibaba-nacos-discovery + + + diff --git a/service-gateway/src/main/java/com/atguigu/ssyx/geteway/ServiceGatewayApplication.java b/service-gateway/src/main/java/com/atguigu/ssyx/geteway/ServiceGatewayApplication.java new file mode 100644 index 0000000..7eed74e --- /dev/null +++ b/service-gateway/src/main/java/com/atguigu/ssyx/geteway/ServiceGatewayApplication.java @@ -0,0 +1,11 @@ +package com.atguigu.ssyx.geteway; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; + +@SpringBootApplication +public class ServiceGatewayApplication { + public static void main(String[] args) { + SpringApplication.run(ServiceGatewayApplication.class, args); + } +} \ No newline at end of file diff --git a/service-gateway/src/main/java/com/atguigu/ssyx/geteway/config/GateWayCorsConfig.java b/service-gateway/src/main/java/com/atguigu/ssyx/geteway/config/GateWayCorsConfig.java new file mode 100644 index 0000000..7ba1d65 --- /dev/null +++ b/service-gateway/src/main/java/com/atguigu/ssyx/geteway/config/GateWayCorsConfig.java @@ -0,0 +1,29 @@ +package com.atguigu.ssyx.geteway.config; + +import lombok.extern.slf4j.Slf4j; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import org.springframework.web.cors.CorsConfiguration; +import org.springframework.web.cors.reactive.CorsWebFilter; +import org.springframework.web.cors.reactive.UrlBasedCorsConfigurationSource; + +@Configuration +@Slf4j +public class GateWayCorsConfig { + @Bean + protected CorsWebFilter addCorsMappings() { + log.info("CorsConfig===>开始跨域注册表..."); + + CorsConfiguration config = new CorsConfiguration(); + // 设置跨域请求地址 + config.addAllowedMethod("*"); + config.addAllowedHeader("*"); + config.addAllowedOrigin("*"); + config.setAllowCredentials(true); + + UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource(); + source.registerCorsConfiguration("/**", config); + + return new CorsWebFilter(source); + } +} \ No newline at end of file diff --git a/service-gateway/src/main/java/com/atguigu/ssyx/geteway/controller/IndexController.java b/service-gateway/src/main/java/com/atguigu/ssyx/geteway/controller/IndexController.java new file mode 100644 index 0000000..02b40f8 --- /dev/null +++ b/service-gateway/src/main/java/com/atguigu/ssyx/geteway/controller/IndexController.java @@ -0,0 +1,17 @@ +package com.atguigu.ssyx.geteway.controller; + +import com.atguigu.ssyx.common.result.Result; +import lombok.extern.slf4j.Slf4j; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +@RequestMapping("/") +@RestController +@Slf4j +public class IndexController { + @GetMapping() + public Result index() { + return Result.success("欢迎访问。。。"); + } +} diff --git a/service-gateway/src/main/resources/application-dev.yml b/service-gateway/src/main/resources/application-dev.yml new file mode 100644 index 0000000..c6a69d7 --- /dev/null +++ b/service-gateway/src/main/resources/application-dev.yml @@ -0,0 +1,8 @@ +server: + port: 8200 + +bunny: + nacos: + server-addr: z-bunny.cn:8848 + discovery: + namespace: ssyx \ No newline at end of file diff --git a/service-gateway/src/main/resources/application.yml b/service-gateway/src/main/resources/application.yml new file mode 100644 index 0000000..aa8f6fe --- /dev/null +++ b/service-gateway/src/main/resources/application.yml @@ -0,0 +1,82 @@ +server: + port: 8200 + +spring: + application: + name: server-gateway + main: + web-application-type: reactive + profiles: + active: dev + cloud: + sentinel: + log: + dir: logs/${spring.application.name}/sentinel + nacos: + discovery: + namespace: ${bunny.nacos.discovery.namespace} + server-addr: ${bunny.nacos.server-addr} + log-name: logs/${spring.application.name} + gateway: + discovery: + locator: + enabled: true + routes: + - id: service-acl + uri: lb://service-acl + predicates: + - Path=/*/acl/** + + - id: service-sys + uri: lb://service-sys + predicates: + - Path=/*/sys/** + + - id: service-product + uri: lb://service-product + predicates: + - Path=/*/product/** + + - id: service-activity + uri: lb://service-activity + predicates: + - Path=/*/activity/** + + - id: service-order + uri: lb://service-order + predicates: + - Path=/*/order/** + + - id: service-payment + uri: lb://service-payment + predicates: + - Path=/*/payment/** + + - id: service-user + uri: lb://service-user + predicates: + - Path=/*/user/** + + - id: service-search + uri: lb://service-search + predicates: + - Path=/*/search/** + + - id: service-home + uri: lb://service-home + predicates: + - Path=/*/home/** + + - id: service-cart + uri: lb://service-cart + predicates: + - Path=/*/cart/** +logging: + level: + com.atguigu.ssyx.acl.mapper: debug + com.atguigu.ssyx.acl.controller: info + com.atguigu.ssyx.acl.service: info + pattern: + dateformat: HH:mm:ss:SSS + file: + path: "logs/${spring.application.name}" \ No newline at end of file diff --git a/service-gateway/src/main/resources/banner.txt b/service-gateway/src/main/resources/banner.txt new file mode 100644 index 0000000..cc77fc2 --- /dev/null +++ b/service-gateway/src/main/resources/banner.txt @@ -0,0 +1,16 @@ +-----------------▄██-█▄--------- +-----------------███▄██▄-------- +-----------------███████-------- +-----------------▀███████------- +-------------------██████▄▄----- +-------------------█████████▄--- +-------------------██████▄████-- +-------▄███████████████████████- +-----▄███████████████████████▀-- +---▄██████████████████████------ +---███████████████████████------ +---███████████████████████------ +-▄▄██████████████████████▀------ +-█████████████████▀█████-------- +-▀██████████████▀▀-▀█████▄------ +-------▀▀▀▀▀▀▀▀▀------▀▀▀▀------ \ No newline at end of file diff --git a/service-gateway/src/main/resources/favicon.ico b/service-gateway/src/main/resources/favicon.ico new file mode 100644 index 0000000..1ba397c Binary files /dev/null and b/service-gateway/src/main/resources/favicon.ico differ diff --git a/service/pom.xml b/service/pom.xml index 09b45e7..a87cbe4 100644 --- a/service/pom.xml +++ b/service/pom.xml @@ -14,6 +14,10 @@ https://maven.apache.org service-acl + service-sys + service-product + service-search + service-activity @@ -69,12 +73,5 @@ com.alibaba.cloud spring-cloud-starter-alibaba-sentinel - - - - org.springframework.boot - spring-boot-devtools - true - diff --git a/service/service-acl/pom.xml b/service/service-acl/pom.xml index 60b15ee..8c4ed7e 100644 --- a/service/service-acl/pom.xml +++ b/service/service-acl/pom.xml @@ -14,10 +14,62 @@ https://maven.apache.org + 192.168.1.4:1100 + ssyx UTF-8 - + + com.github.xiaoymin + knife4j-spring-boot-starter + + + + + + org.springframework.boot + spring-boot-maven-plugin + + + org.apache.maven.plugins + maven-surefire-plugin + + true + + + + com.spotify + docker-maven-plugin + 1.2.2 + + + + build-image + + package + + build + push + + + + + harbor + http://${docker.repostory} + + http://192.168.1.4:2375 + + + ${docker.repostory}/${docker.registry.name}/${project.artifactId}:${project.version} + + + ${project.basedir} + + false + + + + diff --git a/service/service-acl/src/main/java/com/atguigu/ssyx/acl/ServiceAclApplication.java b/service/service-acl/src/main/java/com/atguigu/ssyx/acl/ServiceAclApplication.java index 676c091..7c3f112 100644 --- a/service/service-acl/src/main/java/com/atguigu/ssyx/acl/ServiceAclApplication.java +++ b/service/service-acl/src/main/java/com/atguigu/ssyx/acl/ServiceAclApplication.java @@ -1,13 +1,13 @@ package com.atguigu.ssyx.acl; -import org.mybatis.spring.annotation.MapperScan; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.context.annotation.ComponentScan; +import org.springframework.transaction.annotation.EnableTransactionManagement; @SpringBootApplication -@ComponentScan("com.atguigu.ssyx.common") -@MapperScan("com.atguigu.ssyx.*.mapper") +@ComponentScan(basePackages = {"com.atguigu.ssyx.common", "com.atguigu.ssyx.acl"}) +@EnableTransactionManagement public class ServiceAclApplication { public static void main(String[] args) { SpringApplication.run(ServiceAclApplication.class, args); diff --git a/service/service-acl/src/main/java/com/atguigu/ssyx/acl/config/Knife4jConfig.java b/service/service-acl/src/main/java/com/atguigu/ssyx/acl/config/Knife4jConfig.java new file mode 100644 index 0000000..94da04c --- /dev/null +++ b/service/service-acl/src/main/java/com/atguigu/ssyx/acl/config/Knife4jConfig.java @@ -0,0 +1,54 @@ +package com.atguigu.ssyx.acl.config; + +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import springfox.documentation.builders.ApiInfoBuilder; +import springfox.documentation.builders.ParameterBuilder; +import springfox.documentation.builders.PathSelectors; +import springfox.documentation.builders.RequestHandlerSelectors; +import springfox.documentation.schema.ModelRef; +import springfox.documentation.service.ApiInfo; +import springfox.documentation.service.Contact; +import springfox.documentation.service.Parameter; +import springfox.documentation.spi.DocumentationType; +import springfox.documentation.spring.web.plugins.Docket; +import springfox.documentation.swagger2.annotations.EnableSwagger2WebMvc; + +import java.util.ArrayList; +import java.util.List; + +@Configuration +@EnableSwagger2WebMvc +public class Knife4jConfig { + @Bean + public Docket adminApiConfig() { + List pars = new ArrayList<>(); + ParameterBuilder tokenPar = new ParameterBuilder(); + tokenPar.name("adminId") + .description("用户token") + .defaultValue("1") + .modelRef(new ModelRef("string")) + .parameterType("header") + .required(false) + .build(); + pars.add(tokenPar.build()); + + return new Docket(DocumentationType.SWAGGER_2) + .groupName("adminApi") + .apiInfo(adminApiInfo()) + .select() + .apis(RequestHandlerSelectors.basePackage("com.atguigu.ssyx.acl.controller")) + .paths(PathSelectors.regex("/admin/.*")) + .build() + .globalOperationParameters(pars); + } + + private ApiInfo adminApiInfo() { + return new ApiInfoBuilder() + .title("后台管理系统-API文档") + .description("本文档描述了尚上优选后台系统服务接口定义") + .version("1.0") + .contact(new Contact("atguigu", "http://atguigu.com", "atguigu")) + .build(); + } +} \ No newline at end of file diff --git a/service/service-acl/src/main/java/com/atguigu/ssyx/acl/controller/AdminController.java b/service/service-acl/src/main/java/com/atguigu/ssyx/acl/controller/AdminController.java index aead02e..7fb0017 100644 --- a/service/service-acl/src/main/java/com/atguigu/ssyx/acl/controller/AdminController.java +++ b/service/service-acl/src/main/java/com/atguigu/ssyx/acl/controller/AdminController.java @@ -1,12 +1,73 @@ package com.atguigu.ssyx.acl.controller; +import com.atguigu.ssyx.acl.service.AdminService; +import com.atguigu.ssyx.common.result.Result; +import com.atguigu.ssyx.model.acl.Admin; +import com.atguigu.ssyx.vo.acl.AdminQueryVo; +import com.baomidou.mybatisplus.core.metadata.IPage; import io.swagger.annotations.Api; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RestController; +import io.swagger.annotations.ApiOperation; +import io.swagger.annotations.ApiParam; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.web.bind.annotation.*; + +import java.util.List; @RestController @RequestMapping("/admin/acl/user") @Api(tags = "用户管理") public class AdminController { + @Autowired + private AdminService adminService; + @ApiOperation(value = "获取管理用户分页列表") + @GetMapping("{page}/{limit}") + public Result> index( + @ApiParam(name = "page", value = "当前页码", required = true) + @PathVariable Long page, + + @ApiParam(name = "limit", value = "每页记录数", required = true) + @PathVariable Long limit, + + @ApiParam(name = "userQueryVo", value = "查询对象") + AdminQueryVo userQueryVo + ) { + IPage pageModel = adminService.selectPage(page, limit, userQueryVo); + return Result.success(pageModel); + } + + @ApiOperation(value = "获取管理用户") + @GetMapping("get/{id}") + public Result get(@PathVariable Long id) { + Admin admin = adminService.getById(id); + return Result.success(admin); + } + + @ApiOperation(value = "新增管理用户") + @PostMapping("save") + public Result save(@RequestBody Admin admin) { + boolean isSuccess = adminService.saveByAdmin(admin); + return isSuccess ? Result.success() : Result.error(); + } + + @ApiOperation(value = "修改管理用户") + @PutMapping("update") + public Result updateById(@RequestBody Admin admin) { + adminService.updateById(admin); + return Result.success(); + } + + @ApiOperation(value = "删除管理用户") + @DeleteMapping("remove/{id}") + public Result remove(@PathVariable Long id) { + adminService.removeById(id); + return Result.success(); + } + + @ApiOperation(value = "根据id列表删除管理用户") + @DeleteMapping("batchRemove") + public Result> batchRemove(@RequestBody List ids) { + adminService.removeByIds(ids); + return Result.success(); + } } \ No newline at end of file diff --git a/service/service-acl/src/main/java/com/atguigu/ssyx/acl/controller/AdminRoleController.java b/service/service-acl/src/main/java/com/atguigu/ssyx/acl/controller/AdminRoleController.java new file mode 100644 index 0000000..c6277b7 --- /dev/null +++ b/service/service-acl/src/main/java/com/atguigu/ssyx/acl/controller/AdminRoleController.java @@ -0,0 +1,31 @@ +package com.atguigu.ssyx.acl.controller; + +import com.atguigu.ssyx.acl.service.AdminRoleService; +import com.atguigu.ssyx.common.result.Result; +import com.atguigu.ssyx.vo.acl.AssignAdminRoleVo; +import io.swagger.annotations.Api; +import io.swagger.annotations.ApiOperation; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.web.bind.annotation.*; + +@RestController +@RequestMapping("/admin/acl/user") +@Api(tags = "用户和角色管理") +public class AdminRoleController { + @Autowired + private AdminRoleService adminRoleService; + + @ApiOperation(value = "根据用户获取角色数据") + @GetMapping("/toAssign/{adminId}") + public Result toAssign(@PathVariable Long adminId) { + AssignAdminRoleVo vo = adminRoleService.findRoleByUserId(adminId); + return Result.success(vo); + } + + @ApiOperation(value = "根据用户分配角色") + @PostMapping("/doAssign") + public Result doAssign(@RequestParam Long adminId, @RequestParam Long[] roleId) { + adminRoleService.saveUserRoleShip(adminId, roleId); + return Result.success(); + } +} diff --git a/service/service-acl/src/main/java/com/atguigu/ssyx/acl/controller/IndexController.java b/service/service-acl/src/main/java/com/atguigu/ssyx/acl/controller/IndexController.java index d072253..459c039 100644 --- a/service/service-acl/src/main/java/com/atguigu/ssyx/acl/controller/IndexController.java +++ b/service/service-acl/src/main/java/com/atguigu/ssyx/acl/controller/IndexController.java @@ -1,22 +1,36 @@ package com.atguigu.ssyx.acl.controller; import com.atguigu.ssyx.common.result.Result; +import com.atguigu.ssyx.vo.acl.LoginInfoVo; +import com.atguigu.ssyx.vo.acl.LoginVo; import io.swagger.annotations.Api; +import io.swagger.annotations.ApiOperation; +import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; -import java.util.HashMap; -import java.util.Map; - @Api(tags = "登录相关管理") @RestController @RequestMapping("/admin/acl/index") public class IndexController { + @ApiOperation(value = "请求登陆的login") @PostMapping("login") - public Result> login() { - Map map = new HashMap<>(); - map.put("token", "admin-token"); - return Result.success(map); + public Result login() { + LoginVo vo = LoginVo.builder().token("admin-token").build(); + return Result.success(vo); + } + + @ApiOperation(value = "获取用户信息") + @GetMapping("info") + public Result info() { + LoginInfoVo vo = LoginInfoVo.builder().name("admin").avatar("").build(); + return Result.success(vo); + } + + @ApiOperation(value = "退出登录") + @PostMapping("logout") + public Result logout() { + return Result.success(); } } \ No newline at end of file diff --git a/service/service-acl/src/main/java/com/atguigu/ssyx/acl/controller/PermissionController.java b/service/service-acl/src/main/java/com/atguigu/ssyx/acl/controller/PermissionController.java new file mode 100644 index 0000000..6dde174 --- /dev/null +++ b/service/service-acl/src/main/java/com/atguigu/ssyx/acl/controller/PermissionController.java @@ -0,0 +1,49 @@ +package com.atguigu.ssyx.acl.controller; + +import com.atguigu.ssyx.acl.service.PermissionService; +import com.atguigu.ssyx.common.result.Result; +import com.atguigu.ssyx.model.acl.Permission; +import io.swagger.annotations.Api; +import io.swagger.annotations.ApiOperation; +import lombok.extern.slf4j.Slf4j; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.web.bind.annotation.*; + +import java.util.List; + +@RestController +@RequestMapping("/admin/acl/permission") +@Api(tags = "菜单管理") +@Slf4j +public class PermissionController { + @Autowired + private PermissionService permissionService; + + @ApiOperation(value = "获取菜单") + @GetMapping + public Result> index() { + List list = permissionService.queryAllMenu(); + return Result.success(list); + } + + @ApiOperation(value = "新增菜单") + @PostMapping("save") + public Result save(@RequestBody Permission permission) { + permissionService.save(permission); + return Result.success(); + } + + @ApiOperation(value = "修改菜单") + @PutMapping("update") + public Result updateById(@RequestBody Permission permission) { + permissionService.updateById(permission); + return Result.success(); + } + + @ApiOperation(value = "递归删除菜单") + @DeleteMapping("remove/{id}") + public Result remove(@PathVariable Long id) { + permissionService.removeChildById(id); + return Result.success(); + } +} diff --git a/service/service-acl/src/main/java/com/atguigu/ssyx/acl/controller/RoleController.java b/service/service-acl/src/main/java/com/atguigu/ssyx/acl/controller/RoleController.java new file mode 100644 index 0000000..d3c51cf --- /dev/null +++ b/service/service-acl/src/main/java/com/atguigu/ssyx/acl/controller/RoleController.java @@ -0,0 +1,73 @@ +package com.atguigu.ssyx.acl.controller; + +import com.atguigu.ssyx.acl.service.RoleService; +import com.atguigu.ssyx.common.result.Result; +import com.atguigu.ssyx.model.acl.Role; +import com.atguigu.ssyx.vo.acl.RoleQueryVo; +import com.baomidou.mybatisplus.core.metadata.IPage; +import io.swagger.annotations.Api; +import io.swagger.annotations.ApiOperation; +import io.swagger.annotations.ApiParam; +import lombok.extern.slf4j.Slf4j; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.web.bind.annotation.*; + +import java.util.List; + +@RestController +@RequestMapping("/admin/acl/role") +@Api(tags = "角色管理") +@Slf4j +public class RoleController { + @Autowired + private RoleService roleService; + + @ApiOperation(value = "获取角色分页列表") + @GetMapping("{page}/{limit}") + public Result> index(@ApiParam(name = "page", value = "当前页码", required = true) + @PathVariable Long page, + + @ApiParam(name = "limit", value = "每页记录数", required = true) + @PathVariable Long limit, + + @ApiParam(name = "roleQueryVo", value = "查询对象") + RoleQueryVo vo) { + IPage roleIPage = roleService.selectPage(page, limit, vo); + return Result.success(roleIPage); + } + + @ApiOperation(value = "获取角色") + @GetMapping("get/{id}") + public Result getRole(@PathVariable Long id) { + Role role = roleService.getById(id); + return Result.success(role); + } + + @ApiOperation(value = "新增角色") + @PostMapping("save") + public Result saveRole(@RequestBody Role role) { + roleService.save(role); + return Result.success(); + } + + @ApiOperation(value = "更新角色") + @PutMapping("update") + public Result updateRole(@RequestBody Role role) { + boolean isSuccess = roleService.updateById(role); + return isSuccess ? Result.success() : Result.error(); + } + + @ApiOperation(value = "删除角色") + @DeleteMapping("remove/{id}") + public Result removeRole(@PathVariable Long id) { + roleService.removeById(id); + return Result.success(); + } + + @ApiOperation(value = "根据id列表删除角色") + @DeleteMapping("batchRemove") + public Result> batchRemove(@RequestBody List ids) { + roleService.removeByIds(ids); + return Result.success(); + } +} diff --git a/service/service-acl/src/main/java/com/atguigu/ssyx/acl/mapper/AdminRoleMapper.java b/service/service-acl/src/main/java/com/atguigu/ssyx/acl/mapper/AdminRoleMapper.java new file mode 100644 index 0000000..da34f49 --- /dev/null +++ b/service/service-acl/src/main/java/com/atguigu/ssyx/acl/mapper/AdminRoleMapper.java @@ -0,0 +1,17 @@ +package com.atguigu.ssyx.acl.mapper; + +import com.atguigu.ssyx.model.acl.AdminRole; +import com.atguigu.ssyx.model.acl.Role; +import com.baomidou.mybatisplus.core.mapper.BaseMapper; + +import java.util.List; + +public interface AdminRoleMapper extends BaseMapper { + /** + * * 根据用户ID查找角色 + * + * @param adminId 用户ID + * @return 角色列表 + */ + List findRoleByUserId(Long adminId); +} diff --git a/service/service-acl/src/main/java/com/atguigu/ssyx/acl/mapper/PermissionMapper.java b/service/service-acl/src/main/java/com/atguigu/ssyx/acl/mapper/PermissionMapper.java new file mode 100644 index 0000000..5fc8c5a --- /dev/null +++ b/service/service-acl/src/main/java/com/atguigu/ssyx/acl/mapper/PermissionMapper.java @@ -0,0 +1,10 @@ +package com.atguigu.ssyx.acl.mapper; + +import com.atguigu.ssyx.model.acl.Permission; +import com.baomidou.mybatisplus.core.mapper.BaseMapper; +import org.springframework.stereotype.Repository; + +@Repository +public interface PermissionMapper extends BaseMapper { + +} \ No newline at end of file diff --git a/service/service-acl/src/main/java/com/atguigu/ssyx/acl/service/AdminRoleService.java b/service/service-acl/src/main/java/com/atguigu/ssyx/acl/service/AdminRoleService.java new file mode 100644 index 0000000..dfbc256 --- /dev/null +++ b/service/service-acl/src/main/java/com/atguigu/ssyx/acl/service/AdminRoleService.java @@ -0,0 +1,23 @@ +package com.atguigu.ssyx.acl.service; + +import com.atguigu.ssyx.model.acl.AdminRole; +import com.atguigu.ssyx.vo.acl.AssignAdminRoleVo; +import com.baomidou.mybatisplus.extension.service.IService; + +public interface AdminRoleService extends IService { + /** + * * 根据用户获取角色数据 + * + * @param adminId 用户ID + * @return 分配集合 + */ + AssignAdminRoleVo findRoleByUserId(Long adminId); + + /** + * * 根据用户分配角色 + * + * @param adminId 用户ID + * @param roleId 角色ID + */ + void saveUserRoleShip(Long adminId, Long[] roleId); +} diff --git a/service/service-acl/src/main/java/com/atguigu/ssyx/acl/service/AdminService.java b/service/service-acl/src/main/java/com/atguigu/ssyx/acl/service/AdminService.java index 47cfd0c..c53fa1b 100644 --- a/service/service-acl/src/main/java/com/atguigu/ssyx/acl/service/AdminService.java +++ b/service/service-acl/src/main/java/com/atguigu/ssyx/acl/service/AdminService.java @@ -1,8 +1,26 @@ package com.atguigu.ssyx.acl.service; import com.atguigu.ssyx.model.acl.Admin; +import com.atguigu.ssyx.vo.acl.AdminQueryVo; +import com.baomidou.mybatisplus.core.metadata.IPage; import com.baomidou.mybatisplus.extension.service.IService; public interface AdminService extends IService { + /** + * * 条件分页查询 + * + * @param page 当前页码 + * @param limit 每页记录数 + * @param userQueryVo 查询对象 + * @return 分页结果 + */ + IPage selectPage(Long page, Long limit, AdminQueryVo userQueryVo); + + /** + * 新增管理用户 + * + * @param admin 用户管理员 + */ + Boolean saveByAdmin(Admin admin); } \ No newline at end of file diff --git a/service/service-acl/src/main/java/com/atguigu/ssyx/acl/service/PermissionService.java b/service/service-acl/src/main/java/com/atguigu/ssyx/acl/service/PermissionService.java new file mode 100644 index 0000000..7cc67b0 --- /dev/null +++ b/service/service-acl/src/main/java/com/atguigu/ssyx/acl/service/PermissionService.java @@ -0,0 +1,23 @@ +package com.atguigu.ssyx.acl.service; + +import com.atguigu.ssyx.model.acl.Permission; +import com.baomidou.mybatisplus.extension.service.IService; + +import java.util.List; + +public interface PermissionService extends IService { + + /** + * 获取所有菜单列表 + * + * @return 权限列表 + */ + List queryAllMenu(); + + /** + * 递归删除 + * + * @param id 删除ID + */ + void removeChildById(Long id); +} \ No newline at end of file diff --git a/service/service-acl/src/main/java/com/atguigu/ssyx/acl/service/RoleService.java b/service/service-acl/src/main/java/com/atguigu/ssyx/acl/service/RoleService.java index 163b99c..efa866f 100644 --- a/service/service-acl/src/main/java/com/atguigu/ssyx/acl/service/RoleService.java +++ b/service/service-acl/src/main/java/com/atguigu/ssyx/acl/service/RoleService.java @@ -1,7 +1,18 @@ package com.atguigu.ssyx.acl.service; import com.atguigu.ssyx.model.acl.Role; +import com.atguigu.ssyx.vo.acl.RoleQueryVo; +import com.baomidou.mybatisplus.core.metadata.IPage; import com.baomidou.mybatisplus.extension.service.IService; public interface RoleService extends IService { + /** + * * 获取角色分页列表 + * + * @param page 当前页码 + * @param limit 每页记录数 + * @param vo 角色查询实体 + * @return 分页结果 + */ + IPage selectPage(Long page, Long limit, RoleQueryVo vo); } diff --git a/service/service-acl/src/main/java/com/atguigu/ssyx/acl/service/impl/AdminRoleServiceImpl.java b/service/service-acl/src/main/java/com/atguigu/ssyx/acl/service/impl/AdminRoleServiceImpl.java new file mode 100644 index 0000000..7ee0cd8 --- /dev/null +++ b/service/service-acl/src/main/java/com/atguigu/ssyx/acl/service/impl/AdminRoleServiceImpl.java @@ -0,0 +1,68 @@ +package com.atguigu.ssyx.acl.service.impl; + +import com.atguigu.ssyx.acl.mapper.AdminRoleMapper; +import com.atguigu.ssyx.acl.service.AdminRoleService; +import com.atguigu.ssyx.acl.service.RoleService; +import com.atguigu.ssyx.model.acl.AdminRole; +import com.atguigu.ssyx.model.acl.Role; +import com.atguigu.ssyx.vo.acl.AssignAdminRoleVo; +import com.baomidou.mybatisplus.core.toolkit.Wrappers; +import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; + +import java.util.ArrayList; +import java.util.List; + +@Service +public class AdminRoleServiceImpl extends ServiceImpl implements AdminRoleService { + @Autowired + private RoleService roleService; + + /** + * 根据用户获取角色数据 + * + * @param adminId 用户ID + * @return 分配集合 + */ + @Override + public AssignAdminRoleVo findRoleByUserId(Long adminId) { + // 查询所有的角色 + List allRolesList = roleService.list(null); + // 根据用户id查询角色 + List roleList = baseMapper.findRoleByUserId(adminId); + + // 返回全部角色和当前用户查询的角色 + return AssignAdminRoleVo.builder() + .assignRoles(roleList) + .allRolesList(allRolesList).build(); + } + + /** + * * 根据用户分配角色 + * + * @param adminId 用户ID + * @param roleIds 角色ID + */ + @Override + @Transactional + public void saveUserRoleShip(Long adminId, Long[] roleIds) { + // 先删除这个用户id下所有的角色信息 + remove(Wrappers.lambdaQuery().eq(AdminRole::getAdminId, adminId)); + // 创建集合,遍历完成后一次性插入 + ArrayList adminRoles = new ArrayList<>(); + + // 循环遍历并插入 + for (Long roleId : roleIds) { + // 为用户设置角色id + AdminRole adminRole = new AdminRole(); + adminRole.setAdminId(adminId); + adminRole.setRoleId(roleId); + adminRoles.add(adminRole); + } + + // 插入整体数据 + saveBatch(adminRoles); + } +} diff --git a/service/service-acl/src/main/java/com/atguigu/ssyx/acl/service/impl/AdminServiceImpl.java b/service/service-acl/src/main/java/com/atguigu/ssyx/acl/service/impl/AdminServiceImpl.java index 074c580..c2b88a6 100644 --- a/service/service-acl/src/main/java/com/atguigu/ssyx/acl/service/impl/AdminServiceImpl.java +++ b/service/service-acl/src/main/java/com/atguigu/ssyx/acl/service/impl/AdminServiceImpl.java @@ -3,15 +3,53 @@ package com.atguigu.ssyx.acl.service.impl; import com.atguigu.ssyx.acl.mapper.AdminMapper; import com.atguigu.ssyx.acl.service.AdminService; import com.atguigu.ssyx.model.acl.Admin; +import com.atguigu.ssyx.vo.acl.AdminQueryVo; +import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; +import com.baomidou.mybatisplus.core.metadata.IPage; +import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import lombok.extern.slf4j.Slf4j; import org.springframework.stereotype.Service; +import org.springframework.util.DigestUtils; +import org.springframework.util.StringUtils; @Service @Slf4j public class AdminServiceImpl extends ServiceImpl implements AdminService { + /** + * * 条件分页查询 + * + * @param page 当前页码 + * @param limit 每页记录数 + * @param vo 查询对象 + * @return 分页结果 + */ @Override - public boolean save(Admin entity) { - return super.save(entity); + public IPage selectPage(Long page, Long limit, AdminQueryVo vo) { + Page pageParam = new Page(page, limit); + String name = vo.getName(); + String username = vo.getUsername(); + + // 封装条件进行返回 + LambdaQueryWrapper wrapper = new LambdaQueryWrapper<>(); + wrapper.eq(!StringUtils.isEmpty(username), Admin::getUsername, username); + wrapper.like(!StringUtils.isEmpty(name), Admin::getName, name); + + return baseMapper.selectPage(pageParam, wrapper); + } + + /** + * 新增管理用户 + * + * @param admin 用户管理员 + */ + @Override + public Boolean saveByAdmin(Admin admin) { + // 获取密码并加密 + String password = admin.getPassword(); + String encryptPassword = DigestUtils.md5DigestAsHex(password.getBytes()); + // 设置密码 + admin.setPassword(encryptPassword); + return save(admin); } } \ No newline at end of file diff --git a/service/service-acl/src/main/java/com/atguigu/ssyx/acl/service/impl/PermissionServiceImpl.java b/service/service-acl/src/main/java/com/atguigu/ssyx/acl/service/impl/PermissionServiceImpl.java new file mode 100644 index 0000000..5239d4e --- /dev/null +++ b/service/service-acl/src/main/java/com/atguigu/ssyx/acl/service/impl/PermissionServiceImpl.java @@ -0,0 +1,46 @@ +package com.atguigu.ssyx.acl.service.impl; + +import com.atguigu.common.utils.PermissionHelper; +import com.atguigu.ssyx.acl.mapper.PermissionMapper; +import com.atguigu.ssyx.acl.service.PermissionService; +import com.atguigu.ssyx.acl.service.module.PermissionServiceModule; +import com.atguigu.ssyx.model.acl.Permission; +import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +import java.util.ArrayList; +import java.util.List; + +@Service +public class PermissionServiceImpl extends ServiceImpl implements PermissionService { + @Autowired + private PermissionServiceModule permissionServiceModule; + + /** + * 获取所有菜单列表 + * + * @return 权限列表 + */ + @Override + public List queryAllMenu() { + // 转换要求数据格式 + return PermissionHelper.buildPermissions(list()); + } + + /** + * 递归删除 + * + * @param id 删除ID + */ + @Override + public void removeChildById(Long id) { + ArrayList idList = new ArrayList<>(); + + // 获取菜单下子菜单 + permissionServiceModule.getAllPermissionId(id, idList); + + // 调用方法根据多个菜单ID删除 + baseMapper.deleteBatchIds(idList); + } +} diff --git a/service/service-acl/src/main/java/com/atguigu/ssyx/acl/service/impl/RoleServiceImpl.java b/service/service-acl/src/main/java/com/atguigu/ssyx/acl/service/impl/RoleServiceImpl.java index 5b83ba0..b93e32d 100644 --- a/service/service-acl/src/main/java/com/atguigu/ssyx/acl/service/impl/RoleServiceImpl.java +++ b/service/service-acl/src/main/java/com/atguigu/ssyx/acl/service/impl/RoleServiceImpl.java @@ -3,11 +3,38 @@ package com.atguigu.ssyx.acl.service.impl; import com.atguigu.ssyx.acl.mapper.RoleMapper; import com.atguigu.ssyx.acl.service.RoleService; import com.atguigu.ssyx.model.acl.Role; +import com.atguigu.ssyx.vo.acl.RoleQueryVo; +import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; +import com.baomidou.mybatisplus.core.metadata.IPage; +import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import lombok.extern.slf4j.Slf4j; +import org.apache.commons.lang.StringUtils; import org.springframework.stereotype.Service; @Service @Slf4j public class RoleServiceImpl extends ServiceImpl implements RoleService { + /** + * 获取角色分页列表 + * + * @param page 当前页码 + * @param limit 每页记录数 + * @param vo 角色查询实体 + * @return 分页结果 + */ + @Override + public IPage selectPage(Long page, Long limit, RoleQueryVo vo) { + Page roleParam = new Page<>(page, limit); + // 获取条件值 + String roleName = vo.getRoleName(); + // 创建mp对象 + LambdaQueryWrapper wrapper = new LambdaQueryWrapper<>(); + // 判断条件值是否为空 + if (!StringUtils.isEmpty(roleName)) { + wrapper.like(Role::getRoleName, roleParam); + } + // 调用犯法实现分页查询 + return baseMapper.selectPage(roleParam, wrapper); + } } diff --git a/service/service-acl/src/main/java/com/atguigu/ssyx/acl/service/module/PermissionServiceModule.java b/service/service-acl/src/main/java/com/atguigu/ssyx/acl/service/module/PermissionServiceModule.java new file mode 100644 index 0000000..abef83b --- /dev/null +++ b/service/service-acl/src/main/java/com/atguigu/ssyx/acl/service/module/PermissionServiceModule.java @@ -0,0 +1,31 @@ +package com.atguigu.ssyx.acl.service.module; + +import com.atguigu.ssyx.acl.mapper.PermissionMapper; +import com.atguigu.ssyx.model.acl.Permission; +import com.baomidou.mybatisplus.core.toolkit.Wrappers; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +import java.util.ArrayList; +import java.util.List; + +@Service +public class PermissionServiceModule { + @Autowired + private PermissionMapper permissionMapper; + + /** + * 获取菜单下子菜单 + * + * @param id 菜单ID + * @param idList IDList + */ + public void getAllPermissionId(Long id, ArrayList idList) { + List permissions = permissionMapper.selectList(Wrappers.lambdaQuery().eq(Permission::getId, id)); + + permissions.forEach(item -> { + idList.add(item.getId()); + getAllPermissionId(item.getId(), idList); + }); + } +} diff --git a/service/service-acl/src/main/resources/application-dev.yml b/service/service-acl/src/main/resources/application-dev.yml index fbcd6bf..7a15ab8 100644 --- a/service/service-acl/src/main/resources/application-dev.yml +++ b/service/service-acl/src/main/resources/application-dev.yml @@ -14,18 +14,8 @@ bunny: discovery: namespace: ssyx - redis: - host: 47.120.65.66 - port: 6379 - database: 2 - password: "02120212" - -logging: - level: - com.atguigu.ssyx.acl.mapper: debug - com.atguigu.ssyx.acl.controller: info - com.atguigu.ssyx.acl.service: info - pattern: - dateformat: HH:mm:ss:SSS - file: - path: "logs/${spring.application.name}" \ No newline at end of file + minio: + endpointUrl: "http://129.211.31.58:9000" + bucket-name: ssyx + accessKey: bunny + secretKey: "02120212" \ No newline at end of file diff --git a/service/service-acl/src/main/resources/application.yml b/service/service-acl/src/main/resources/application.yml index 0c1c95a..6d0694c 100644 --- a/service/service-acl/src/main/resources/application.yml +++ b/service/service-acl/src/main/resources/application.yml @@ -1,5 +1,5 @@ server: - port: 8291 + port: 8201 spring: application: name: service-acl @@ -11,7 +11,7 @@ spring: driver-class-name: com.mysql.cj.jdbc.Driver url: jdbc:mysql://${bunny.datasource.host}:${bunny.datasource.port}/${bunny.datasource.sqlData}?serverTimezone=GMT%2B8&useSSL=false&characterEncoding=utf-8&allowPublicKeyRetrieval=true username: ${bunny.datasource.username} - password: "${bunny.datasource.password}" + password: ${bunny.datasource.password} cloud: sentinel: @@ -34,14 +34,29 @@ mybatis-plus: map-underscore-to-camel-case: true auto-mapping-behavior: full log-impl: org.apache.ibatis.logging.stdout.StdOutImpl # 查看日志 - # global-config: - # db-config: + global-config: + db-config: # 设置表名前缀,不用在每个tableName添加前缀 # table-prefix: t_ # 全局配置主键值方式 - # id-type: assign_id - # 指定逻辑删除-未删除 - # logic-not-delete-value: 0 # 未删除默认为0 - # 指定逻辑删除-删除 - # logic-delete-value: 1 # 删除 - # logic-delete-field: deleted # 全局配置逻辑删除 \ No newline at end of file + id-type: assign_id + logic-not-delete-value: 0 # 未删除默认为0 + logic-delete-value: 1 # 删除 + logic-delete-field: deleted # 全局配置逻辑删除 + +logging: + level: + com.atguigu.ssyx.acl.mapper: debug + com.atguigu.ssyx.acl.controller: info + com.atguigu.ssyx.acl.service: info + pattern: + dateformat: HH:mm:ss:SSS + file: + path: "logs/${spring.application.name}" + +bunny: + minio: + endpointUrl: ${bunny.minio.endpointUrl} + accessKey: ${bunny.minio.accessKey} + secretKey: ${bunny.minio.secretKey} + bucket-name: ${bunny.minio.bucket-name} \ No newline at end of file diff --git a/service/service-acl/src/main/resources/mapper/AdminRoleMapper.xml b/service/service-acl/src/main/resources/mapper/AdminRoleMapper.xml new file mode 100644 index 0000000..b8f52fe --- /dev/null +++ b/service/service-acl/src/main/resources/mapper/AdminRoleMapper.xml @@ -0,0 +1,12 @@ + + + + + + diff --git a/service/service-activity/Dockerfile b/service/service-activity/Dockerfile new file mode 100644 index 0000000..ef109ac --- /dev/null +++ b/service/service-activity/Dockerfile @@ -0,0 +1,21 @@ +FROM openjdk:17 +MAINTAINER bunny + +#系统编码 +ENV LANG=C.UTF-8 LC_ALL=C.UTF-8 + +# 设置时区,构建镜像时执行的命令 +RUN ln -sf /usr/share/zoneinfo/Asia/Shanghai /etc/localtime +RUN echo "Asia/Shanghai" > /etc/timezone + +# 设定工作目录 +WORKDIR /home/bunny + +# 复制jar包 +COPY target/*.jar /home/bunny/app.jar + +#启动容器时的进程 +ENTRYPOINT ["java","-jar","/home/bunny/app.jar"] + +#暴露 8080 端口 +EXPOSE 8080 \ No newline at end of file diff --git a/service/service-activity/pom.xml b/service/service-activity/pom.xml new file mode 100644 index 0000000..dd04d1b --- /dev/null +++ b/service/service-activity/pom.xml @@ -0,0 +1,23 @@ + + 4.0.0 + + com.atguigu + service + 1.0-SNAPSHOT + + + service-activity + jar + + service-activity + https://maven.apache.org + + + UTF-8 + + + + + + diff --git a/service/service-activity/src/main/java/com/atguigu/ssyx/activity/ServiceActivityApplication.java b/service/service-activity/src/main/java/com/atguigu/ssyx/activity/ServiceActivityApplication.java new file mode 100644 index 0000000..9959687 --- /dev/null +++ b/service/service-activity/src/main/java/com/atguigu/ssyx/activity/ServiceActivityApplication.java @@ -0,0 +1,17 @@ +package com.atguigu.ssyx.activity; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.context.annotation.ComponentScan; +import org.springframework.transaction.annotation.EnableTransactionManagement; + +@SpringBootApplication +@ComponentScan(basePackages = { + "com.atguigu.ssyx.common", + "com.atguigu.ssyx.activity"}) +@EnableTransactionManagement +public class ServiceActivityApplication { + public static void main(String[] args) { + SpringApplication.run(ServiceActivityApplication.class, args); + } +} \ No newline at end of file diff --git a/service/service-activity/src/main/java/com/atguigu/ssyx/activity/controller/ActivityInfoController.java b/service/service-activity/src/main/java/com/atguigu/ssyx/activity/controller/ActivityInfoController.java new file mode 100644 index 0000000..2d6eecb --- /dev/null +++ b/service/service-activity/src/main/java/com/atguigu/ssyx/activity/controller/ActivityInfoController.java @@ -0,0 +1,24 @@ +package com.atguigu.ssyx.activity.controller; + + +import com.atguigu.ssyx.activity.service.ActivityInfoService; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +/** + *

+ * 活动表 前端控制器 + *

+ * + * @author bunny + * @since 2024-04-04 + */ +@RestController +@RequestMapping("/admin/activity/activityInfo") +public class ActivityInfoController { + @Autowired + private ActivityInfoService activityInfoService; + +} + diff --git a/service/service-activity/src/main/java/com/atguigu/ssyx/activity/controller/CouponInfoController.java b/service/service-activity/src/main/java/com/atguigu/ssyx/activity/controller/CouponInfoController.java new file mode 100644 index 0000000..c0970a3 --- /dev/null +++ b/service/service-activity/src/main/java/com/atguigu/ssyx/activity/controller/CouponInfoController.java @@ -0,0 +1,21 @@ +package com.atguigu.ssyx.activity.controller; + + +import org.springframework.web.bind.annotation.RequestMapping; + +import org.springframework.web.bind.annotation.RestController; + +/** + *

+ * 优惠券信息 前端控制器 + *

+ * + * @author bunny + * @since 2024-04-04 + */ +@RestController +@RequestMapping("/activity/coupon-info") +public class CouponInfoController { + +} + diff --git a/service/service-activity/src/main/java/com/atguigu/ssyx/activity/mapper/ActivityInfoMapper.java b/service/service-activity/src/main/java/com/atguigu/ssyx/activity/mapper/ActivityInfoMapper.java new file mode 100644 index 0000000..7658569 --- /dev/null +++ b/service/service-activity/src/main/java/com/atguigu/ssyx/activity/mapper/ActivityInfoMapper.java @@ -0,0 +1,16 @@ +package com.atguigu.ssyx.activity.mapper; + +import com.atguigu.ssyx.model.activity.ActivityInfo; +import com.baomidou.mybatisplus.core.mapper.BaseMapper; + +/** + *

+ * 活动表 Mapper 接口 + *

+ * + * @author bunny + * @since 2024-04-04 + */ +public interface ActivityInfoMapper extends BaseMapper { + +} diff --git a/service/service-activity/src/main/java/com/atguigu/ssyx/activity/mapper/CouponInfoMapper.java b/service/service-activity/src/main/java/com/atguigu/ssyx/activity/mapper/CouponInfoMapper.java new file mode 100644 index 0000000..2b88f12 --- /dev/null +++ b/service/service-activity/src/main/java/com/atguigu/ssyx/activity/mapper/CouponInfoMapper.java @@ -0,0 +1,16 @@ +package com.atguigu.ssyx.activity.mapper; + +import com.atguigu.ssyx.model.activity.CouponInfo; +import com.baomidou.mybatisplus.core.mapper.BaseMapper; + +/** + *

+ * 优惠券信息 Mapper 接口 + *

+ * + * @author bunny + * @since 2024-04-04 + */ +public interface CouponInfoMapper extends BaseMapper { + +} diff --git a/service/service-activity/src/main/java/com/atguigu/ssyx/activity/service/ActivityInfoService.java b/service/service-activity/src/main/java/com/atguigu/ssyx/activity/service/ActivityInfoService.java new file mode 100644 index 0000000..3e1ac81 --- /dev/null +++ b/service/service-activity/src/main/java/com/atguigu/ssyx/activity/service/ActivityInfoService.java @@ -0,0 +1,16 @@ +package com.atguigu.ssyx.activity.service; + +import com.atguigu.ssyx.model.activity.ActivityInfo; +import com.baomidou.mybatisplus.extension.service.IService; + +/** + *

+ * 活动表 服务类 + *

+ * + * @author bunny + * @since 2024-04-04 + */ +public interface ActivityInfoService extends IService { + +} diff --git a/service/service-activity/src/main/java/com/atguigu/ssyx/activity/service/CouponInfoService.java b/service/service-activity/src/main/java/com/atguigu/ssyx/activity/service/CouponInfoService.java new file mode 100644 index 0000000..43bef9d --- /dev/null +++ b/service/service-activity/src/main/java/com/atguigu/ssyx/activity/service/CouponInfoService.java @@ -0,0 +1,16 @@ +package com.atguigu.ssyx.activity.service; + +import com.atguigu.ssyx.model.activity.CouponInfo; +import com.baomidou.mybatisplus.extension.service.IService; + +/** + *

+ * 优惠券信息 服务类 + *

+ * + * @author bunny + * @since 2024-04-04 + */ +public interface CouponInfoService extends IService { + +} diff --git a/service/service-activity/src/main/java/com/atguigu/ssyx/activity/service/impl/ActivityInfoServiceImpl.java b/service/service-activity/src/main/java/com/atguigu/ssyx/activity/service/impl/ActivityInfoServiceImpl.java new file mode 100644 index 0000000..66b80b8 --- /dev/null +++ b/service/service-activity/src/main/java/com/atguigu/ssyx/activity/service/impl/ActivityInfoServiceImpl.java @@ -0,0 +1,20 @@ +package com.atguigu.ssyx.activity.service.impl; + +import com.atguigu.ssyx.activity.mapper.ActivityInfoMapper; +import com.atguigu.ssyx.activity.service.ActivityInfoService; +import com.atguigu.ssyx.model.activity.ActivityInfo; +import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; +import org.springframework.stereotype.Service; + +/** + *

+ * 活动表 服务实现类 + *

+ * + * @author bunny + * @since 2024-04-04 + */ +@Service +public class ActivityInfoServiceImpl extends ServiceImpl implements ActivityInfoService { + +} diff --git a/service/service-activity/src/main/java/com/atguigu/ssyx/activity/service/impl/CouponInfoServiceImpl.java b/service/service-activity/src/main/java/com/atguigu/ssyx/activity/service/impl/CouponInfoServiceImpl.java new file mode 100644 index 0000000..b0a0ca5 --- /dev/null +++ b/service/service-activity/src/main/java/com/atguigu/ssyx/activity/service/impl/CouponInfoServiceImpl.java @@ -0,0 +1,20 @@ +package com.atguigu.ssyx.activity.service.impl; + +import com.atguigu.ssyx.activity.mapper.CouponInfoMapper; +import com.atguigu.ssyx.activity.service.CouponInfoService; +import com.atguigu.ssyx.model.activity.CouponInfo; +import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; +import org.springframework.stereotype.Service; + +/** + *

+ * 优惠券信息 服务实现类 + *

+ * + * @author bunny + * @since 2024-04-04 + */ +@Service +public class CouponInfoServiceImpl extends ServiceImpl implements CouponInfoService { + +} diff --git a/service/service-activity/src/main/resources/application-dev.yml b/service/service-activity/src/main/resources/application-dev.yml new file mode 100644 index 0000000..1e840b2 --- /dev/null +++ b/service/service-activity/src/main/resources/application-dev.yml @@ -0,0 +1,15 @@ +server: + port: 8204 + +bunny: + datasource: + host: 106.15.251.123 + port: 3305 + sqlData: shequ-activity + username: root + password: "02120212" + + nacos: + server-addr: z-bunny.cn:8848 + discovery: + namespace: ssyx diff --git a/service/service-activity/src/main/resources/application.yml b/service/service-activity/src/main/resources/application.yml new file mode 100644 index 0000000..e426921 --- /dev/null +++ b/service/service-activity/src/main/resources/application.yml @@ -0,0 +1,54 @@ +server: + port: 8204 +spring: + application: + name: service-activity + profiles: + active: dev + + datasource: + type: com.zaxxer.hikari.HikariDataSource + driver-class-name: com.mysql.cj.jdbc.Driver + url: jdbc:mysql://${bunny.datasource.host}:${bunny.datasource.port}/${bunny.datasource.sqlData}?serverTimezone=GMT%2B8&useSSL=false&characterEncoding=utf-8&allowPublicKeyRetrieval=true + username: ${bunny.datasource.username} + password: ${bunny.datasource.password} + + cloud: + sentinel: + log: + dir: logs/${spring.application.name}/sentinel + nacos: + discovery: + namespace: ${bunny.nacos.discovery.namespace} + server-addr: ${bunny.nacos.server-addr} + + jackson: + date-format: yyyy-MM-dd HH:mm:ss + time-zone: GMT+8 + +mybatis-plus: + type-aliases-package: com.atguigu.model # 配置每个包前缀 + mapper-locations: classpath:mapper/*.xml + configuration: + map-underscore-to-camel-case: true + auto-mapping-behavior: full + log-impl: org.apache.ibatis.logging.stdout.StdOutImpl # 查看日志 + global-config: + db-config: + # 设置表名前缀,不用在每个tableName添加前缀 + # table-prefix: t_ + # 全局配置主键值方式 + id-type: assign_id + logic-not-delete-value: 0 # 未删除默认为0 + logic-delete-value: 1 # 删除 + logic-delete-field: deleted # 全局配置逻辑删除 + +logging: + level: + com.atguigu.ssyx.activity.mapper: debug + com.atguigu.ssyx.activity.controller: info + com.atguigu.ssyx.activity.service: info + pattern: + dateformat: HH:mm:ss:SSS + file: + path: "logs/${spring.application.name}" diff --git a/service/service-activity/src/main/resources/banner.txt b/service/service-activity/src/main/resources/banner.txt new file mode 100644 index 0000000..cc77fc2 --- /dev/null +++ b/service/service-activity/src/main/resources/banner.txt @@ -0,0 +1,16 @@ +-----------------▄██-█▄--------- +-----------------███▄██▄-------- +-----------------███████-------- +-----------------▀███████------- +-------------------██████▄▄----- +-------------------█████████▄--- +-------------------██████▄████-- +-------▄███████████████████████- +-----▄███████████████████████▀-- +---▄██████████████████████------ +---███████████████████████------ +---███████████████████████------ +-▄▄██████████████████████▀------ +-█████████████████▀█████-------- +-▀██████████████▀▀-▀█████▄------ +-------▀▀▀▀▀▀▀▀▀------▀▀▀▀------ \ No newline at end of file diff --git a/service/service-activity/src/main/resources/favicon.ico b/service/service-activity/src/main/resources/favicon.ico new file mode 100644 index 0000000..1ba397c Binary files /dev/null and b/service/service-activity/src/main/resources/favicon.ico differ diff --git a/service/service-activity/src/main/resources/mapper/ActivityInfoMapper.xml b/service/service-activity/src/main/resources/mapper/ActivityInfoMapper.xml new file mode 100644 index 0000000..10789a7 --- /dev/null +++ b/service/service-activity/src/main/resources/mapper/ActivityInfoMapper.xml @@ -0,0 +1,5 @@ + + + + + diff --git a/service/service-activity/src/main/resources/mapper/CouponInfoMapper.xml b/service/service-activity/src/main/resources/mapper/CouponInfoMapper.xml new file mode 100644 index 0000000..da11c25 --- /dev/null +++ b/service/service-activity/src/main/resources/mapper/CouponInfoMapper.xml @@ -0,0 +1,5 @@ + + + + + diff --git a/service/service-product/Dockerfile b/service/service-product/Dockerfile new file mode 100644 index 0000000..ef109ac --- /dev/null +++ b/service/service-product/Dockerfile @@ -0,0 +1,21 @@ +FROM openjdk:17 +MAINTAINER bunny + +#系统编码 +ENV LANG=C.UTF-8 LC_ALL=C.UTF-8 + +# 设置时区,构建镜像时执行的命令 +RUN ln -sf /usr/share/zoneinfo/Asia/Shanghai /etc/localtime +RUN echo "Asia/Shanghai" > /etc/timezone + +# 设定工作目录 +WORKDIR /home/bunny + +# 复制jar包 +COPY target/*.jar /home/bunny/app.jar + +#启动容器时的进程 +ENTRYPOINT ["java","-jar","/home/bunny/app.jar"] + +#暴露 8080 端口 +EXPOSE 8080 \ No newline at end of file diff --git a/service/service-product/pom.xml b/service/service-product/pom.xml new file mode 100644 index 0000000..7f9b4ff --- /dev/null +++ b/service/service-product/pom.xml @@ -0,0 +1,32 @@ + + 4.0.0 + + com.atguigu + service + 1.0-SNAPSHOT + + + service-product + jar + + service-product + https://maven.apache.org + + + UTF-8 + + + + + com.atguigu + rabbit-util + 1.0-SNAPSHOT + + + + cn.hutool + hutool-all + + + diff --git a/service/service-product/src/main/java/com/atguigu/ssyx/product/ServiceProductApplication.java b/service/service-product/src/main/java/com/atguigu/ssyx/product/ServiceProductApplication.java new file mode 100644 index 0000000..2a967b3 --- /dev/null +++ b/service/service-product/src/main/java/com/atguigu/ssyx/product/ServiceProductApplication.java @@ -0,0 +1,18 @@ +package com.atguigu.ssyx.product; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.context.annotation.ComponentScan; +import org.springframework.transaction.annotation.EnableTransactionManagement; + +@SpringBootApplication +@ComponentScan(basePackages = { + "com.atguigu.ssyx.common", + "com.atguigu.ssyx.mq", + "com.atguigu.ssyx.product"}) +@EnableTransactionManagement +public class ServiceProductApplication { + public static void main(String[] args) { + SpringApplication.run(ServiceProductApplication.class, args); + } +} \ No newline at end of file diff --git a/service/service-product/src/main/java/com/atguigu/ssyx/product/api/ProductInnerController.java b/service/service-product/src/main/java/com/atguigu/ssyx/product/api/ProductInnerController.java new file mode 100644 index 0000000..11f852b --- /dev/null +++ b/service/service-product/src/main/java/com/atguigu/ssyx/product/api/ProductInnerController.java @@ -0,0 +1,38 @@ +package com.atguigu.ssyx.product.api; + +import com.atguigu.ssyx.common.result.Result; +import com.atguigu.ssyx.model.product.Category; +import com.atguigu.ssyx.model.product.SkuInfo; +import com.atguigu.ssyx.product.service.CategoryService; +import com.atguigu.ssyx.product.service.SkuInfoService; +import io.swagger.annotations.Api; +import io.swagger.annotations.ApiOperation; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +@Api(value = "远程调用接口", tags = "远程调用接口") +@RestController +@RequestMapping("/api/product") +public class ProductInnerController { + @Autowired + private CategoryService categoryService; + @Autowired + private SkuInfoService skuInfoService; + + @ApiOperation(value = "根据分类id获取分类信息") + @GetMapping("inner/getCategory/{categoryId}") + public Result getCategory(@PathVariable Long categoryId) { + Category category = categoryService.getById(categoryId); + return Result.success(category); + } + + @ApiOperation(value = "根据skuId获取sku信息") + @GetMapping("inner/getSkuInfo/{skuId}") + public Result getSkuInfo(@PathVariable Long skuId) { + SkuInfo skuInfo = skuInfoService.getById(skuId); + return Result.success(skuInfo); + } +} diff --git a/service/service-product/src/main/java/com/atguigu/ssyx/product/config/Knife4jConfig.java b/service/service-product/src/main/java/com/atguigu/ssyx/product/config/Knife4jConfig.java new file mode 100644 index 0000000..5ae9d31 --- /dev/null +++ b/service/service-product/src/main/java/com/atguigu/ssyx/product/config/Knife4jConfig.java @@ -0,0 +1,54 @@ +package com.atguigu.ssyx.product.config; + +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import springfox.documentation.builders.ApiInfoBuilder; +import springfox.documentation.builders.ParameterBuilder; +import springfox.documentation.builders.PathSelectors; +import springfox.documentation.builders.RequestHandlerSelectors; +import springfox.documentation.schema.ModelRef; +import springfox.documentation.service.ApiInfo; +import springfox.documentation.service.Contact; +import springfox.documentation.service.Parameter; +import springfox.documentation.spi.DocumentationType; +import springfox.documentation.spring.web.plugins.Docket; +import springfox.documentation.swagger2.annotations.EnableSwagger2WebMvc; + +import java.util.ArrayList; +import java.util.List; + +@Configuration +@EnableSwagger2WebMvc +public class Knife4jConfig { + @Bean + public Docket adminApiConfig() { + List pars = new ArrayList<>(); + ParameterBuilder tokenPar = new ParameterBuilder(); + tokenPar.name("adminId") + .description("用户token") + .defaultValue("1") + .modelRef(new ModelRef("string")) + .parameterType("header") + .required(false) + .build(); + pars.add(tokenPar.build()); + + return new Docket(DocumentationType.SWAGGER_2) + .groupName("商品相关API") + .apiInfo(adminApiInfo()) + .select() + .apis(RequestHandlerSelectors.basePackage("com.atguigu.ssyx.product.controller")) + .paths(PathSelectors.regex("/admin/.*")) + .build() + .globalOperationParameters(pars); + } + + private ApiInfo adminApiInfo() { + return new ApiInfoBuilder() + .title("后台管理系统-API文档") + .description("本文档描述了尚上优选后台系统服务接口定义") + .version("1.0") + .contact(new Contact("atguigu", "http://atguigu.com", "atguigu")) + .build(); + } +} \ No newline at end of file diff --git a/service/service-product/src/main/java/com/atguigu/ssyx/product/controller/AttrController.java b/service/service-product/src/main/java/com/atguigu/ssyx/product/controller/AttrController.java new file mode 100644 index 0000000..4054b24 --- /dev/null +++ b/service/service-product/src/main/java/com/atguigu/ssyx/product/controller/AttrController.java @@ -0,0 +1,74 @@ +package com.atguigu.ssyx.product.controller; + + +import com.atguigu.ssyx.common.result.Result; +import com.atguigu.ssyx.model.product.Attr; +import com.atguigu.ssyx.product.service.AttrService; +import io.swagger.annotations.Api; +import io.swagger.annotations.ApiOperation; +import io.swagger.annotations.ApiParam; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.web.bind.annotation.*; + +import java.util.List; + +/** + *

+ * 商品属性 前端控制器 + *

+ * + * @author bunny + * @since 2024-04-03 + */ +@Api(value = "Attr管理", tags = "平台属性管理") +@RestController +@RequestMapping(value = "/admin/product/attr") +public class AttrController { + @Autowired + private AttrService attrService; + + @ApiOperation(value = "获取列表") + @GetMapping("{attrGroupId}") + public Result> index( + @ApiParam(name = "attrGroupId", value = "分组id", required = true) + @PathVariable Long attrGroupId) { + List attrList = attrService.findByAttrGroupId(attrGroupId); + return Result.success(attrList); + } + + @ApiOperation(value = "获取") + @GetMapping("get/{id}") + public Result get(@PathVariable Long id) { + Attr attr = attrService.getById(id); + return Result.success(attr); + } + + @ApiOperation(value = "新增") + @PostMapping("save") + public Result save(@RequestBody Attr attr) { + attrService.save(attr); + return Result.success(); + } + + @ApiOperation(value = "修改") + @PutMapping("update") + public Result updateById(@RequestBody Attr attr) { + attrService.updateById(attr); + return Result.success(); + } + + @ApiOperation(value = "删除") + @DeleteMapping("remove/{id}") + public Result remove(@PathVariable Long id) { + attrService.removeById(id); + return Result.success(); + } + + @ApiOperation(value = "根据id列表删除") + @DeleteMapping("batchRemove") + public Result batchRemove(@RequestBody List ids) { + attrService.removeByIds(ids); + return Result.success(); + } +} + diff --git a/service/service-product/src/main/java/com/atguigu/ssyx/product/controller/AttrGroupController.java b/service/service-product/src/main/java/com/atguigu/ssyx/product/controller/AttrGroupController.java new file mode 100644 index 0000000..b9ba035 --- /dev/null +++ b/service/service-product/src/main/java/com/atguigu/ssyx/product/controller/AttrGroupController.java @@ -0,0 +1,90 @@ +package com.atguigu.ssyx.product.controller; + + +import com.atguigu.ssyx.common.result.Result; +import com.atguigu.ssyx.model.product.AttrGroup; +import com.atguigu.ssyx.product.service.AttrGroupService; +import com.atguigu.ssyx.vo.product.AttrGroupQueryVo; +import com.baomidou.mybatisplus.core.metadata.IPage; +import com.baomidou.mybatisplus.extension.plugins.pagination.Page; +import io.swagger.annotations.Api; +import io.swagger.annotations.ApiOperation; +import io.swagger.annotations.ApiParam; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.web.bind.annotation.*; + +import java.util.List; + +/** + *

+ * 属性分组 前端控制器 + *

+ * + * @author bunny + * @since 2024-04-03 + */ +@Api(value = "AttrGroup管理", tags = "平台属性分组管理") +@RestController +@RequestMapping(value = "/admin/product/attrGroup") +public class AttrGroupController { + @Autowired + private AttrGroupService attrGroupService; + + @ApiOperation(value = "获取分页列表") + @GetMapping("{page}/{limit}") + public Result> index( + @ApiParam(name = "page", value = "当前页码", required = true) + @PathVariable Long page, + + @ApiParam(name = "limit", value = "每页记录数", required = true) + @PathVariable Long limit, + + @ApiParam(name = "attrGroupQueryVo", value = "查询对象", required = false) + AttrGroupQueryVo attrGroupQueryVo) { + Page pageParam = new Page<>(page, limit); + IPage pageModel = attrGroupService.selectPage(pageParam, attrGroupQueryVo); + return Result.success(pageModel); + } + + @ApiOperation(value = "获取") + @GetMapping("get/{id}") + public Result get(@PathVariable Long id) { + AttrGroup attrGroup = attrGroupService.getById(id); + return Result.success(attrGroup); + } + + @ApiOperation(value = "新增") + @PostMapping("save") + public Result save(@RequestBody AttrGroup group) { + attrGroupService.save(group); + return Result.success(); + } + + @ApiOperation(value = "修改") + @PutMapping("update") + public Result updateById(@RequestBody AttrGroup attrGroup) { + attrGroupService.updateById(attrGroup); + return Result.success(); + } + + @ApiOperation(value = "删除") + @DeleteMapping("remove/{id}") + public Result remove(@PathVariable Long id) { + attrGroupService.removeById(id); + return Result.success(); + } + + @ApiOperation(value = "根据id列表删除") + @DeleteMapping("batchRemove") + public Result batchRemove(@RequestBody List ids) { + attrGroupService.removeByIds(ids); + return Result.success(); + } + + @ApiOperation(value = "获取全部属性分组") + @GetMapping("findAllList") + public Result> findAllList() { + return Result.success(attrGroupService.list()); + } +} + diff --git a/service/service-product/src/main/java/com/atguigu/ssyx/product/controller/CategoryController.java b/service/service-product/src/main/java/com/atguigu/ssyx/product/controller/CategoryController.java new file mode 100644 index 0000000..d0557de --- /dev/null +++ b/service/service-product/src/main/java/com/atguigu/ssyx/product/controller/CategoryController.java @@ -0,0 +1,82 @@ +package com.atguigu.ssyx.product.controller; + + +import com.atguigu.ssyx.common.result.Result; +import com.atguigu.ssyx.model.product.Category; +import com.atguigu.ssyx.product.service.CategoryService; +import com.atguigu.ssyx.vo.product.CategoryQueryVo; +import com.baomidou.mybatisplus.core.metadata.IPage; +import com.baomidou.mybatisplus.extension.plugins.pagination.Page; +import io.swagger.annotations.Api; +import io.swagger.annotations.ApiOperation; +import io.swagger.annotations.ApiParam; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.web.bind.annotation.*; + +import java.util.List; + +@Api(value = "Category管理", tags = "商品分类管理") +@RestController +@RequestMapping(value = "/admin/product/category") +public class CategoryController { + @Autowired + private CategoryService categoryService; + + @ApiOperation(value = "获取商品分类分页列表") + @GetMapping("{page}/{limit}") + public Result> index( + @ApiParam(name = "page", value = "当前页码", required = true) + @PathVariable Long page, + @ApiParam(name = "limit", value = "每页记录数", required = true) + @PathVariable Long limit, + @ApiParam(name = "categoryQueryVo", value = "查询对象", required = false) + CategoryQueryVo categoryQueryVo) { + Page pageParam = new Page<>(page, limit); + IPage pageModel = categoryService.selectPage(pageParam, categoryQueryVo); + + return Result.success(pageModel); + } + + @ApiOperation(value = "获取商品分类信息") + @GetMapping("get/{id}") + public Result get(@PathVariable Long id) { + Category category = categoryService.getById(id); + return Result.success(category); + } + + @ApiOperation(value = "新增商品分类") + @PostMapping("save") + public Result save(@RequestBody Category category) { + categoryService.save(category); + return Result.success(); + } + + @ApiOperation(value = "修改商品分类") + @PutMapping("update") + public Result updateById(@RequestBody Category category) { + categoryService.updateById(category); + return Result.success(); + } + + @ApiOperation(value = "删除商品分类") + @DeleteMapping("remove/{id}") + public Result remove(@PathVariable Long id) { + categoryService.removeById(id); + return Result.success(); + } + + @ApiOperation(value = "根据id列表删除商品分类") + @DeleteMapping("batchRemove") + public Result batchRemove(@RequestBody List ids) { + categoryService.removeByIds(ids); + return Result.success(); + } + + @ApiOperation(value = "获取全部商品分类") + @GetMapping("findAllList") + public Result> findAllList() { + List categoryList = categoryService.findAllList(); + return Result.success(categoryList); + } +} + diff --git a/service/service-product/src/main/java/com/atguigu/ssyx/product/controller/FileUploadController.java b/service/service-product/src/main/java/com/atguigu/ssyx/product/controller/FileUploadController.java new file mode 100644 index 0000000..c45a19d --- /dev/null +++ b/service/service-product/src/main/java/com/atguigu/ssyx/product/controller/FileUploadController.java @@ -0,0 +1,27 @@ +package com.atguigu.ssyx.product.controller; + +import com.atguigu.ssyx.common.result.Result; +import com.atguigu.ssyx.product.service.FileUploadService; +import io.swagger.annotations.Api; +import io.swagger.annotations.ApiOperation; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; +import org.springframework.web.multipart.MultipartFile; + +@Api(tags = "文件上传接口") +@RestController +@RequestMapping("/admin/product") +public class FileUploadController { + @Autowired + private FileUploadService fileUploadService; + + @ApiOperation(value = "文件上传") + @PostMapping("fileUpload") + public Result fileUpload(@RequestBody MultipartFile file) { + String filename = fileUploadService.uploadFile(file); + return Result.success(filename); + } +} \ No newline at end of file diff --git a/service/service-product/src/main/java/com/atguigu/ssyx/product/controller/SkuAttrValueController.java b/service/service-product/src/main/java/com/atguigu/ssyx/product/controller/SkuAttrValueController.java new file mode 100644 index 0000000..a18f928 --- /dev/null +++ b/service/service-product/src/main/java/com/atguigu/ssyx/product/controller/SkuAttrValueController.java @@ -0,0 +1,20 @@ +package com.atguigu.ssyx.product.controller; + + +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +/** + *

+ * spu属性值 前端控制器 + *

+ * + * @author bunny + * @since 2024-04-03 + */ +@RestController +@RequestMapping("/admin/product/sku-attr-value") +public class SkuAttrValueController { + +} + diff --git a/service/service-product/src/main/java/com/atguigu/ssyx/product/controller/SkuImageController.java b/service/service-product/src/main/java/com/atguigu/ssyx/product/controller/SkuImageController.java new file mode 100644 index 0000000..5632796 --- /dev/null +++ b/service/service-product/src/main/java/com/atguigu/ssyx/product/controller/SkuImageController.java @@ -0,0 +1,20 @@ +package com.atguigu.ssyx.product.controller; + + +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +/** + *

+ * 商品图片 前端控制器 + *

+ * + * @author bunny + * @since 2024-04-03 + */ +@RestController +@RequestMapping("/admin/product/sku-image") +public class SkuImageController { + +} + diff --git a/service/service-product/src/main/java/com/atguigu/ssyx/product/controller/SkuInfoController.java b/service/service-product/src/main/java/com/atguigu/ssyx/product/controller/SkuInfoController.java new file mode 100644 index 0000000..1f69e01 --- /dev/null +++ b/service/service-product/src/main/java/com/atguigu/ssyx/product/controller/SkuInfoController.java @@ -0,0 +1,107 @@ +package com.atguigu.ssyx.product.controller; + + +import com.atguigu.ssyx.common.result.Result; +import com.atguigu.ssyx.model.product.SkuInfo; +import com.atguigu.ssyx.product.service.SkuInfoService; +import com.atguigu.ssyx.vo.product.SkuInfoQueryVo; +import com.atguigu.ssyx.vo.product.SkuInfoVo; +import com.baomidou.mybatisplus.core.metadata.IPage; +import com.baomidou.mybatisplus.extension.plugins.pagination.Page; +import io.swagger.annotations.Api; +import io.swagger.annotations.ApiOperation; +import io.swagger.annotations.ApiParam; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.web.bind.annotation.*; + +import java.util.List; + +/** + *

+ * sku信息 前端控制器 + *

+ * + * @author bunny + * @since 2024-04-03 + */ +@Api(value = "SkuInfo管理", tags = "商品Sku管理") +@RestController +@RequestMapping(value = "/admin/product/skuInfo") +public class SkuInfoController { + @Autowired + private SkuInfoService skuInfoService; + + @ApiOperation(value = "获取sku分页列表") + @GetMapping("{page}/{limit}") + public Result> index( + @ApiParam(name = "page", value = "当前页码", required = true) + @PathVariable Long page, + + @ApiParam(name = "limit", value = "每页记录数", required = true) + @PathVariable Long limit, + + @ApiParam(name = "skuInfoQueryVo", value = "查询对象", required = false) + SkuInfoQueryVo skuInfoQueryVo) { + Page pageParam = new Page<>(page, limit); + IPage pageModel = skuInfoService.selectPage(pageParam, skuInfoQueryVo); + return Result.success(pageModel); + } + + @ApiOperation(value = "商品添加方法") + @PostMapping("save") + public Result save(@RequestBody SkuInfoVo skuInfoVo) { + skuInfoService.saveSkuInfo(skuInfoVo); + return Result.success(); + } + + @ApiOperation(value = "获取商品SKU信息") + @GetMapping("get/{id}") + public Result get(@PathVariable Long id) { + SkuInfoVo skuInfoVo = skuInfoService.getSkuInfoVo(id); + return Result.success(skuInfoVo); + } + + @ApiOperation(value = "修改商品sku信息") + @PutMapping("update") + public Result updateById(@RequestBody SkuInfoVo skuInfoVo) { + skuInfoService.updateSkuInfo(skuInfoVo); + return Result.success(); + } + + @ApiOperation(value = "商品SKU删除") + @DeleteMapping("remove/{id}") + public Result remove(@PathVariable Long id) { + skuInfoService.removeById(id); + return Result.success(); + } + + @ApiOperation(value = "根据id列表删除") + @DeleteMapping("batchRemove") + public Result batchRemove(@RequestBody List ids) { + skuInfoService.removeByIds(ids); + return Result.success(); + } + + @ApiOperation(value = "商品审核") + @GetMapping("check/{skuId}/{status}") + public Result check(@PathVariable Long skuId, @PathVariable Integer status) { + skuInfoService.check(skuId, status); + return Result.success(); + } + + @ApiOperation(value = "商品上架") + @GetMapping("publish/{skuId}/{status}") + public Result publish(@PathVariable("skuId") Long skuId, + @PathVariable("status") Integer status) { + skuInfoService.publish(skuId, status); + return Result.success(); + } + + @ApiOperation(value = "新人专享") + @GetMapping("isNewPerson/{skuId}/{status}") + public Result isNewPerson(@PathVariable Long skuId, @PathVariable Integer status) { + skuInfoService.isNewPerson(skuId, status); + return Result.success(); + } +} + diff --git a/service/service-product/src/main/java/com/atguigu/ssyx/product/controller/SkuPosterController.java b/service/service-product/src/main/java/com/atguigu/ssyx/product/controller/SkuPosterController.java new file mode 100644 index 0000000..d0f0ccc --- /dev/null +++ b/service/service-product/src/main/java/com/atguigu/ssyx/product/controller/SkuPosterController.java @@ -0,0 +1,20 @@ +package com.atguigu.ssyx.product.controller; + + +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +/** + *

+ * 商品海报表 前端控制器 + *

+ * + * @author bunny + * @since 2024-04-03 + */ +@RestController +@RequestMapping("/admin/product/sku-poster") +public class SkuPosterController { + +} + diff --git a/service/service-product/src/main/java/com/atguigu/ssyx/product/mapper/AttrGroupMapper.java b/service/service-product/src/main/java/com/atguigu/ssyx/product/mapper/AttrGroupMapper.java new file mode 100644 index 0000000..45a30dc --- /dev/null +++ b/service/service-product/src/main/java/com/atguigu/ssyx/product/mapper/AttrGroupMapper.java @@ -0,0 +1,16 @@ +package com.atguigu.ssyx.product.mapper; + +import com.atguigu.ssyx.model.product.AttrGroup; +import com.baomidou.mybatisplus.core.mapper.BaseMapper; + +/** + *

+ * 属性分组 Mapper 接口 + *

+ * + * @author bunny + * @since 2024-04-03 + */ +public interface AttrGroupMapper extends BaseMapper { + +} diff --git a/service/service-product/src/main/java/com/atguigu/ssyx/product/mapper/AttrMapper.java b/service/service-product/src/main/java/com/atguigu/ssyx/product/mapper/AttrMapper.java new file mode 100644 index 0000000..4ed243d --- /dev/null +++ b/service/service-product/src/main/java/com/atguigu/ssyx/product/mapper/AttrMapper.java @@ -0,0 +1,16 @@ +package com.atguigu.ssyx.product.mapper; + +import com.atguigu.ssyx.model.product.Attr; +import com.baomidou.mybatisplus.core.mapper.BaseMapper; + +/** + *

+ * 商品属性 Mapper 接口 + *

+ * + * @author bunny + * @since 2024-04-03 + */ +public interface AttrMapper extends BaseMapper { + +} diff --git a/service/service-product/src/main/java/com/atguigu/ssyx/product/mapper/CategoryMapper.java b/service/service-product/src/main/java/com/atguigu/ssyx/product/mapper/CategoryMapper.java new file mode 100644 index 0000000..5ad4010 --- /dev/null +++ b/service/service-product/src/main/java/com/atguigu/ssyx/product/mapper/CategoryMapper.java @@ -0,0 +1,16 @@ +package com.atguigu.ssyx.product.mapper; + +import com.atguigu.ssyx.model.product.Category; +import com.baomidou.mybatisplus.core.mapper.BaseMapper; + +/** + *

+ * 商品三级分类 Mapper 接口 + *

+ * + * @author bunny + * @since 2024-04-03 + */ +public interface CategoryMapper extends BaseMapper { + +} diff --git a/service/service-product/src/main/java/com/atguigu/ssyx/product/mapper/SkuAttrValueMapper.java b/service/service-product/src/main/java/com/atguigu/ssyx/product/mapper/SkuAttrValueMapper.java new file mode 100644 index 0000000..50f336c --- /dev/null +++ b/service/service-product/src/main/java/com/atguigu/ssyx/product/mapper/SkuAttrValueMapper.java @@ -0,0 +1,16 @@ +package com.atguigu.ssyx.product.mapper; + +import com.atguigu.ssyx.model.product.SkuAttrValue; +import com.baomidou.mybatisplus.core.mapper.BaseMapper; + +/** + *

+ * spu属性值 Mapper 接口 + *

+ * + * @author bunny + * @since 2024-04-03 + */ +public interface SkuAttrValueMapper extends BaseMapper { + +} diff --git a/service/service-product/src/main/java/com/atguigu/ssyx/product/mapper/SkuImageMapper.java b/service/service-product/src/main/java/com/atguigu/ssyx/product/mapper/SkuImageMapper.java new file mode 100644 index 0000000..06f12b0 --- /dev/null +++ b/service/service-product/src/main/java/com/atguigu/ssyx/product/mapper/SkuImageMapper.java @@ -0,0 +1,16 @@ +package com.atguigu.ssyx.product.mapper; + +import com.atguigu.ssyx.model.product.SkuImage; +import com.baomidou.mybatisplus.core.mapper.BaseMapper; + +/** + *

+ * 商品图片 Mapper 接口 + *

+ * + * @author bunny + * @since 2024-04-03 + */ +public interface SkuImageMapper extends BaseMapper { + +} diff --git a/service/service-product/src/main/java/com/atguigu/ssyx/product/mapper/SkuInfoMapper.java b/service/service-product/src/main/java/com/atguigu/ssyx/product/mapper/SkuInfoMapper.java new file mode 100644 index 0000000..7eff652 --- /dev/null +++ b/service/service-product/src/main/java/com/atguigu/ssyx/product/mapper/SkuInfoMapper.java @@ -0,0 +1,16 @@ +package com.atguigu.ssyx.product.mapper; + +import com.atguigu.ssyx.model.product.SkuInfo; +import com.baomidou.mybatisplus.core.mapper.BaseMapper; + +/** + *

+ * sku信息 Mapper 接口 + *

+ * + * @author bunny + * @since 2024-04-03 + */ +public interface SkuInfoMapper extends BaseMapper { + +} diff --git a/service/service-product/src/main/java/com/atguigu/ssyx/product/mapper/SkuPosterMapper.java b/service/service-product/src/main/java/com/atguigu/ssyx/product/mapper/SkuPosterMapper.java new file mode 100644 index 0000000..d9290f0 --- /dev/null +++ b/service/service-product/src/main/java/com/atguigu/ssyx/product/mapper/SkuPosterMapper.java @@ -0,0 +1,16 @@ +package com.atguigu.ssyx.product.mapper; + +import com.atguigu.ssyx.model.product.SkuPoster; +import com.baomidou.mybatisplus.core.mapper.BaseMapper; + +/** + *

+ * 商品海报表 Mapper 接口 + *

+ * + * @author bunny + * @since 2024-04-03 + */ +public interface SkuPosterMapper extends BaseMapper { + +} diff --git a/service/service-product/src/main/java/com/atguigu/ssyx/product/service/AttrGroupService.java b/service/service-product/src/main/java/com/atguigu/ssyx/product/service/AttrGroupService.java new file mode 100644 index 0000000..c1a9580 --- /dev/null +++ b/service/service-product/src/main/java/com/atguigu/ssyx/product/service/AttrGroupService.java @@ -0,0 +1,27 @@ +package com.atguigu.ssyx.product.service; + +import com.atguigu.ssyx.model.product.AttrGroup; +import com.atguigu.ssyx.vo.product.AttrGroupQueryVo; +import com.baomidou.mybatisplus.core.metadata.IPage; +import com.baomidou.mybatisplus.extension.plugins.pagination.Page; +import com.baomidou.mybatisplus.extension.service.IService; + +/** + *

+ * 属性分组 服务类 + *

+ * + * @author bunny + * @since 2024-04-03 + */ +public interface AttrGroupService extends IService { + + /** + * 获取分页列表 + * + * @param pageParam 分页查询条件 + * @param vo 查询分页参数 + * @return 分页查询结果 + */ + IPage selectPage(Page pageParam, AttrGroupQueryVo vo); +} diff --git a/service/service-product/src/main/java/com/atguigu/ssyx/product/service/AttrService.java b/service/service-product/src/main/java/com/atguigu/ssyx/product/service/AttrService.java new file mode 100644 index 0000000..d37b885 --- /dev/null +++ b/service/service-product/src/main/java/com/atguigu/ssyx/product/service/AttrService.java @@ -0,0 +1,22 @@ +package com.atguigu.ssyx.product.service; + +import com.atguigu.ssyx.model.product.Attr; +import com.baomidou.mybatisplus.extension.service.IService; + +import java.util.List; + +/** + *

+ * 商品属性 服务类 + *

+ * + * @author bunny + * @since 2024-04-03 + */ +public interface AttrService extends IService { + + /** + * 获取列表 + */ + List findByAttrGroupId(Long attrGroupId); +} diff --git a/service/service-product/src/main/java/com/atguigu/ssyx/product/service/CategoryService.java b/service/service-product/src/main/java/com/atguigu/ssyx/product/service/CategoryService.java new file mode 100644 index 0000000..a1c6764 --- /dev/null +++ b/service/service-product/src/main/java/com/atguigu/ssyx/product/service/CategoryService.java @@ -0,0 +1,30 @@ +package com.atguigu.ssyx.product.service; + +import com.atguigu.ssyx.model.product.Category; +import com.atguigu.ssyx.vo.product.CategoryQueryVo; +import com.baomidou.mybatisplus.core.metadata.IPage; +import com.baomidou.mybatisplus.extension.plugins.pagination.Page; +import com.baomidou.mybatisplus.extension.service.IService; + +import java.util.List; + +/** + *

+ * 商品三级分类 服务类 + *

+ * + * @author bunny + * @since 2024-04-03 + */ +public interface CategoryService extends IService { + + /** + * 获取商品分类分页列表 + */ + IPage selectPage(Page pageParam, CategoryQueryVo categoryQueryVo); + + /** + * 获取全部商品分类 + */ + List findAllList(); +} diff --git a/service/service-product/src/main/java/com/atguigu/ssyx/product/service/FileUploadService.java b/service/service-product/src/main/java/com/atguigu/ssyx/product/service/FileUploadService.java new file mode 100644 index 0000000..4822e1a --- /dev/null +++ b/service/service-product/src/main/java/com/atguigu/ssyx/product/service/FileUploadService.java @@ -0,0 +1,13 @@ +package com.atguigu.ssyx.product.service; + +import org.springframework.web.multipart.MultipartFile; + +public interface FileUploadService { + /** + * 文件上传 + * + * @param file 上传的文件 + * @return 文件路径 + */ + String uploadFile(MultipartFile file); +} diff --git a/service/service-product/src/main/java/com/atguigu/ssyx/product/service/SkuAttrValueService.java b/service/service-product/src/main/java/com/atguigu/ssyx/product/service/SkuAttrValueService.java new file mode 100644 index 0000000..bf55e8e --- /dev/null +++ b/service/service-product/src/main/java/com/atguigu/ssyx/product/service/SkuAttrValueService.java @@ -0,0 +1,25 @@ +package com.atguigu.ssyx.product.service; + +import com.atguigu.ssyx.model.product.SkuAttrValue; +import com.baomidou.mybatisplus.extension.service.IService; + +import java.util.List; + +/** + *

+ * spu属性值 服务类 + *

+ * + * @author bunny + * @since 2024-04-03 + */ +public interface SkuAttrValueService extends IService { + + /** + * 根据id查询商品属性信息列表 + * + * @param id 商品id + * @return 图片列表 + */ + List getAttrValueListBySkuId(Long id); +} diff --git a/service/service-product/src/main/java/com/atguigu/ssyx/product/service/SkuImageService.java b/service/service-product/src/main/java/com/atguigu/ssyx/product/service/SkuImageService.java new file mode 100644 index 0000000..5ce3529 --- /dev/null +++ b/service/service-product/src/main/java/com/atguigu/ssyx/product/service/SkuImageService.java @@ -0,0 +1,25 @@ +package com.atguigu.ssyx.product.service; + +import com.atguigu.ssyx.model.product.SkuImage; +import com.baomidou.mybatisplus.extension.service.IService; + +import java.util.List; + +/** + *

+ * 商品图片 服务类 + *

+ * + * @author bunny + * @since 2024-04-03 + */ +public interface SkuImageService extends IService { + + /** + * 根据id查询商品图片列表 + * + * @param id 商品id + * @return 商品图片列表 + */ + List getImageListBySkuId(Long id); +} diff --git a/service/service-product/src/main/java/com/atguigu/ssyx/product/service/SkuInfoService.java b/service/service-product/src/main/java/com/atguigu/ssyx/product/service/SkuInfoService.java new file mode 100644 index 0000000..a76aa13 --- /dev/null +++ b/service/service-product/src/main/java/com/atguigu/ssyx/product/service/SkuInfoService.java @@ -0,0 +1,74 @@ +package com.atguigu.ssyx.product.service; + +import com.atguigu.ssyx.model.product.SkuInfo; +import com.atguigu.ssyx.vo.product.SkuInfoQueryVo; +import com.atguigu.ssyx.vo.product.SkuInfoVo; +import com.baomidou.mybatisplus.core.metadata.IPage; +import com.baomidou.mybatisplus.extension.plugins.pagination.Page; +import com.baomidou.mybatisplus.extension.service.IService; + +/** + *

+ * sku信息 服务类 + *

+ * + * @author bunny + * @since 2024-04-03 + */ +public interface SkuInfoService extends IService { + + /** + * 获取sku分页列表 + * + * @param pageParam 分页查询条件 + * @param skuInfoQueryVo 商品查询条件 + * @return 分页结果 + */ + IPage selectPage(Page pageParam, SkuInfoQueryVo skuInfoQueryVo); + + /** + * 商品添加方法 + * + * @param skuInfoVo 商品信息 + */ + void saveSkuInfo(SkuInfoVo skuInfoVo); + + /** + * 获取商品SKU信息 + * + * @param id 商品id + * @return 商品信息 + */ + SkuInfoVo getSkuInfoVo(Long id); + + /** + * 修改商品sku信息 + * + * @param skuInfoVo 商品信息 + */ + void updateSkuInfo(SkuInfoVo skuInfoVo); + + /** + * 商品审核 + * + * @param skuId 商品ID + * @param status 商品状态 + */ + void check(Long skuId, Integer status); + + /** + * 商品上架 + * + * @param skuId 商品ID + * @param status 商品状态 + */ + void publish(Long skuId, Integer status); + + /** + * 新人专享 + * + * @param skuId 商品ID + * @param status 商品状态 + */ + void isNewPerson(Long skuId, Integer status); +} diff --git a/service/service-product/src/main/java/com/atguigu/ssyx/product/service/SkuPosterService.java b/service/service-product/src/main/java/com/atguigu/ssyx/product/service/SkuPosterService.java new file mode 100644 index 0000000..52be52b --- /dev/null +++ b/service/service-product/src/main/java/com/atguigu/ssyx/product/service/SkuPosterService.java @@ -0,0 +1,25 @@ +package com.atguigu.ssyx.product.service; + +import com.atguigu.ssyx.model.product.SkuPoster; +import com.baomidou.mybatisplus.extension.service.IService; + +import java.util.List; + +/** + *

+ * 商品海报表 服务类 + *

+ * + * @author bunny + * @since 2024-04-03 + */ +public interface SkuPosterService extends IService { + + /** + * 根据id查询商品海报列表 + * + * @param id 商品id + * @return 图片列表 + */ + List getPosterListBySkuId(Long id); +} diff --git a/service/service-product/src/main/java/com/atguigu/ssyx/product/service/impl/AttrGroupServiceImpl.java b/service/service-product/src/main/java/com/atguigu/ssyx/product/service/impl/AttrGroupServiceImpl.java new file mode 100644 index 0000000..70a4ead --- /dev/null +++ b/service/service-product/src/main/java/com/atguigu/ssyx/product/service/impl/AttrGroupServiceImpl.java @@ -0,0 +1,38 @@ +package com.atguigu.ssyx.product.service.impl; + +import com.atguigu.ssyx.model.product.AttrGroup; +import com.atguigu.ssyx.product.mapper.AttrGroupMapper; +import com.atguigu.ssyx.product.service.AttrGroupService; +import com.atguigu.ssyx.vo.product.AttrGroupQueryVo; +import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; +import com.baomidou.mybatisplus.core.metadata.IPage; +import com.baomidou.mybatisplus.extension.plugins.pagination.Page; +import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; +import org.springframework.stereotype.Service; + +/** + *

+ * 属性分组 服务实现类 + *

+ * + * @author bunny + * @since 2024-04-03 + */ +@Service +public class AttrGroupServiceImpl extends ServiceImpl implements AttrGroupService { + + /** + * 获取分页列表 + * + * @param pageParam 分页查询条件 + * @param vo 查询分页参数 + * @return 分页查询结果 + */ + @Override + public IPage selectPage(Page pageParam, AttrGroupQueryVo vo) { + QueryWrapper wrapper = new QueryWrapper<>(); + + wrapper.orderByDesc("id"); + return baseMapper.selectPage(pageParam, wrapper); + } +} diff --git a/service/service-product/src/main/java/com/atguigu/ssyx/product/service/impl/AttrServiceImpl.java b/service/service-product/src/main/java/com/atguigu/ssyx/product/service/impl/AttrServiceImpl.java new file mode 100644 index 0000000..acb2602 --- /dev/null +++ b/service/service-product/src/main/java/com/atguigu/ssyx/product/service/impl/AttrServiceImpl.java @@ -0,0 +1,31 @@ +package com.atguigu.ssyx.product.service.impl; + +import com.atguigu.ssyx.model.product.Attr; +import com.atguigu.ssyx.product.mapper.AttrMapper; +import com.atguigu.ssyx.product.service.AttrService; +import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; +import com.baomidou.mybatisplus.core.toolkit.Wrappers; +import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; +import org.springframework.stereotype.Service; + +import java.util.List; + +/** + *

+ * 商品属性 服务实现类 + *

+ * + * @author bunny + * @since 2024-04-03 + */ +@Service +public class AttrServiceImpl extends ServiceImpl implements AttrService { + /** + * 获取列表 + */ + @Override + public List findByAttrGroupId(Long attrGroupId) { + LambdaQueryWrapper wrapper = Wrappers.lambdaQuery().eq(Attr::getAttrGroupId, attrGroupId); + return baseMapper.selectList(wrapper); + } +} diff --git a/service/service-product/src/main/java/com/atguigu/ssyx/product/service/impl/CategoryServiceImpl.java b/service/service-product/src/main/java/com/atguigu/ssyx/product/service/impl/CategoryServiceImpl.java new file mode 100644 index 0000000..f4c8264 --- /dev/null +++ b/service/service-product/src/main/java/com/atguigu/ssyx/product/service/impl/CategoryServiceImpl.java @@ -0,0 +1,47 @@ +package com.atguigu.ssyx.product.service.impl; + +import com.atguigu.ssyx.model.product.Category; +import com.atguigu.ssyx.product.mapper.CategoryMapper; +import com.atguigu.ssyx.product.service.CategoryService; +import com.atguigu.ssyx.vo.product.CategoryQueryVo; +import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; +import com.baomidou.mybatisplus.core.metadata.IPage; +import com.baomidou.mybatisplus.core.toolkit.Wrappers; +import com.baomidou.mybatisplus.extension.plugins.pagination.Page; +import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; +import org.apache.commons.lang3.StringUtils; +import org.springframework.stereotype.Service; + +import java.util.List; + +/** + *

+ * 商品三级分类 服务实现类 + *

+ * + * @author bunny + * @since 2024-04-03 + */ +@Service +public class CategoryServiceImpl extends ServiceImpl implements CategoryService { + + /** + * 获取商品分类分页列表 + */ + @Override + public IPage selectPage(Page pageParam, CategoryQueryVo vo) { + String name = vo.getName(); + LambdaQueryWrapper wrapper = new LambdaQueryWrapper<>(); + wrapper.like(!StringUtils.isEmpty(name), Category::getName, name); + + return baseMapper.selectPage(pageParam, wrapper); + } + + /** + * 获取全部商品分类 + */ + @Override + public List findAllList() { + return list(Wrappers.lambdaQuery().orderByAsc(Category::getSort)); + } +} diff --git a/service/service-product/src/main/java/com/atguigu/ssyx/product/service/impl/FileUploadServiceImpl.java b/service/service-product/src/main/java/com/atguigu/ssyx/product/service/impl/FileUploadServiceImpl.java new file mode 100644 index 0000000..e00268b --- /dev/null +++ b/service/service-product/src/main/java/com/atguigu/ssyx/product/service/impl/FileUploadServiceImpl.java @@ -0,0 +1,58 @@ +package com.atguigu.ssyx.product.service.impl; + +import cn.hutool.core.date.DateUtil; +import com.atguigu.ssyx.common.properties.MinioProperties; +import com.atguigu.ssyx.product.service.FileUploadService; +import io.minio.BucketExistsArgs; +import io.minio.MakeBucketArgs; +import io.minio.MinioClient; +import io.minio.PutObjectArgs; +import lombok.extern.slf4j.Slf4j; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; +import org.springframework.web.multipart.MultipartFile; + +import java.util.Date; +import java.util.UUID; + + +@Service +@Slf4j +public class FileUploadServiceImpl implements FileUploadService { + @Autowired + private MinioProperties properties; + @Autowired + private MinioClient minioClient; + + /** + * 文件上传 + * + * @param file 上传的文件 + * @return 文件路径 + */ + @Override + public String uploadFile(MultipartFile file) { + String bucketName = properties.getBucketName(); + String dir = DateUtil.format(new Date(), "yyyy-MM-dd"); + String uuid = UUID.randomUUID().toString(); + String filename = dir + "/" + uuid + "-" + file.getOriginalFilename(); + + try { + boolean bucketExists = minioClient.bucketExists(BucketExistsArgs.builder().bucket(bucketName).build()); + if (!bucketExists) { + log.warn("minio桶不存在:{}", bucketName); + minioClient.makeBucket(MakeBucketArgs.builder().bucket(bucketName).build()); + } + + // 存入图片 + minioClient.putObject(PutObjectArgs.builder() + .bucket(bucketName) + .object(filename) + .stream(file.getInputStream(), file.getSize(), -1).build()); + + return properties.getEndpointUrl() + "/" + properties.getBucketName() + "/" + filename; + } catch (Exception e) { + throw new RuntimeException(e); + } + } +} diff --git a/service/service-product/src/main/java/com/atguigu/ssyx/product/service/impl/SkuAttrValueServiceImpl.java b/service/service-product/src/main/java/com/atguigu/ssyx/product/service/impl/SkuAttrValueServiceImpl.java new file mode 100644 index 0000000..e65d7c0 --- /dev/null +++ b/service/service-product/src/main/java/com/atguigu/ssyx/product/service/impl/SkuAttrValueServiceImpl.java @@ -0,0 +1,33 @@ +package com.atguigu.ssyx.product.service.impl; + +import com.atguigu.ssyx.model.product.SkuAttrValue; +import com.atguigu.ssyx.product.mapper.SkuAttrValueMapper; +import com.atguigu.ssyx.product.service.SkuAttrValueService; +import com.baomidou.mybatisplus.core.toolkit.Wrappers; +import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; +import org.springframework.stereotype.Service; + +import java.util.List; + +/** + *

+ * spu属性值 服务实现类 + *

+ * + * @author bunny + * @since 2024-04-03 + */ +@Service +public class SkuAttrValueServiceImpl extends ServiceImpl implements SkuAttrValueService { + + /** + * 根据id查询商品属性信息列表 + * + * @param id 商品id + * @return 图片列表 + */ + @Override + public List getAttrValueListBySkuId(Long id) { + return baseMapper.selectList(Wrappers.lambdaQuery().eq(SkuAttrValue::getSkuId, id)); + } +} diff --git a/service/service-product/src/main/java/com/atguigu/ssyx/product/service/impl/SkuImageServiceImpl.java b/service/service-product/src/main/java/com/atguigu/ssyx/product/service/impl/SkuImageServiceImpl.java new file mode 100644 index 0000000..b6a363a --- /dev/null +++ b/service/service-product/src/main/java/com/atguigu/ssyx/product/service/impl/SkuImageServiceImpl.java @@ -0,0 +1,32 @@ +package com.atguigu.ssyx.product.service.impl; + +import com.atguigu.ssyx.model.product.SkuImage; +import com.atguigu.ssyx.product.mapper.SkuImageMapper; +import com.atguigu.ssyx.product.service.SkuImageService; +import com.baomidou.mybatisplus.core.toolkit.Wrappers; +import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; +import org.springframework.stereotype.Service; + +import java.util.List; + +/** + *

+ * 商品图片 服务实现类 + *

+ * + * @author bunny + * @since 2024-04-03 + */ +@Service +public class SkuImageServiceImpl extends ServiceImpl implements SkuImageService { + /** + * 根据id查询商品图片列表 + * + * @param id 商品id + * @return 商品图片列表 + */ + @Override + public List getImageListBySkuId(Long id) { + return baseMapper.selectList(Wrappers.lambdaQuery().eq(SkuImage::getSkuId, id)); + } +} diff --git a/service/service-product/src/main/java/com/atguigu/ssyx/product/service/impl/SkuInfoServiceImpl.java b/service/service-product/src/main/java/com/atguigu/ssyx/product/service/impl/SkuInfoServiceImpl.java new file mode 100644 index 0000000..26f0f20 --- /dev/null +++ b/service/service-product/src/main/java/com/atguigu/ssyx/product/service/impl/SkuInfoServiceImpl.java @@ -0,0 +1,226 @@ +package com.atguigu.ssyx.product.service.impl; + +import com.atguigu.ssyx.model.product.SkuAttrValue; +import com.atguigu.ssyx.model.product.SkuImage; +import com.atguigu.ssyx.model.product.SkuInfo; +import com.atguigu.ssyx.model.product.SkuPoster; +import com.atguigu.ssyx.mq.constant.MqConst; +import com.atguigu.ssyx.mq.service.RabbitService; +import com.atguigu.ssyx.product.mapper.SkuInfoMapper; +import com.atguigu.ssyx.product.service.SkuAttrValueService; +import com.atguigu.ssyx.product.service.SkuImageService; +import com.atguigu.ssyx.product.service.SkuInfoService; +import com.atguigu.ssyx.product.service.SkuPosterService; +import com.atguigu.ssyx.vo.product.SkuInfoQueryVo; +import com.atguigu.ssyx.vo.product.SkuInfoVo; +import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; +import com.baomidou.mybatisplus.core.metadata.IPage; +import com.baomidou.mybatisplus.core.toolkit.Wrappers; +import com.baomidou.mybatisplus.extension.plugins.pagination.Page; +import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; +import io.jsonwebtoken.lang.Collections; +import org.springframework.beans.BeanUtils; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; +import org.springframework.util.CollectionUtils; +import org.springframework.util.StringUtils; + +import java.util.List; + +/** + *

+ * sku信息 服务实现类 + *

+ * + * @author bunny + * @since 2024-04-03 + */ +@Service +public class SkuInfoServiceImpl extends ServiceImpl implements SkuInfoService { + @Autowired + private SkuAttrValueService skuAttrValueService; + @Autowired + private SkuImageService skuImageService; + @Autowired + private SkuPosterService skuPosterService; + @Autowired + private RabbitService rabbitService; + + /** + * 获取sku分页列表 + * + * @param pageParam 分页查询条件 + * @param vo 商品查询条件 + * @return 分页结果 + */ + @Override + public IPage selectPage(Page pageParam, SkuInfoQueryVo vo) { + String keyword = vo.getKeyword(); + String skuType = vo.getSkuType(); + Long categoryId = vo.getCategoryId(); + + // 封装查询条件 + LambdaQueryWrapper wrapper = new LambdaQueryWrapper<>(); + wrapper.like(!StringUtils.isEmpty(keyword), SkuInfo::getSkuName, keyword); + wrapper.eq(!StringUtils.isEmpty(skuType), SkuInfo::getSkuType, skuType); + wrapper.eq(categoryId != null, SkuInfo::getCategoryId, categoryId); + + // 返回结果 + return page(pageParam, wrapper); + } + + /** + * 商品添加方法 + * + * @param skuInfoVo 商品信息 + */ + @Override + public void saveSkuInfo(SkuInfoVo skuInfoVo) { + // 添加sku基本信息 + SkuInfo skuInfo = new SkuInfo(); + BeanUtils.copyProperties(skuInfoVo, skuInfo); + baseMapper.insert(skuInfo); + // 保存sku海报 + List skuPosterList = skuInfoVo.getSkuPosterList(); + if (!Collections.isEmpty(skuPosterList)) { + skuPosterList.forEach(skuPoster -> skuPoster.setSkuId(skuInfo.getId())); + skuPosterService.saveBatch(skuPosterList); + } + // 保存sku图片 + List skuImagesList = skuInfoVo.getSkuImagesList(); + if (!Collections.isEmpty(skuImagesList)) { + skuImagesList.forEach(skuImage -> skuImage.setSkuId(skuImage.getId())); + skuImageService.saveBatch(skuImagesList); + } + // 保存sku属性 + List skuAttrValueList = skuInfoVo.getSkuAttrValueList(); + if (!Collections.isEmpty(skuImagesList)) { + skuAttrValueList.forEach(skuAttrValue -> skuAttrValue.setSkuId(skuInfo.getId())); + skuAttrValueService.saveBatch(skuAttrValueList); + } + } + + /** + * 获取商品SKU信息 + * + * @param id 商品id + * @return 商品信息 + */ + @Override + public SkuInfoVo getSkuInfoVo(Long id) { + SkuInfoVo skuInfoVo = new SkuInfoVo(); + + // 根据id查询sku基本信息 + SkuInfo skuInfo = baseMapper.selectById(id); + + // 根据id查询商品图片列表 + List skuImageList = skuImageService.getImageListBySkuId(id); + + // 根据id查询商品海报列表 + List skuPosterList = skuPosterService.getPosterListBySkuId(id); + + // 根据id查询商品属性信息列表 + List skuAttrValueList = skuAttrValueService.getAttrValueListBySkuId(id); + + BeanUtils.copyProperties(skuInfo, skuInfoVo); + skuInfoVo.setSkuAttrValueList(skuAttrValueList); + skuInfoVo.setSkuImagesList(skuImageList); + skuInfoVo.setSkuPosterList(skuPosterList); + + // 封装数据返回 + return skuInfoVo; + } + + /** + * 修改商品sku信息 + * + * @param skuInfoVo 商品信息 + */ + @Override + public void updateSkuInfo(SkuInfoVo skuInfoVo) { + // 修改sku基本信息 + SkuInfo skuInfo = new SkuInfo(); + BeanUtils.copyProperties(skuInfo, skuInfo); + baseMapper.updateById(skuInfo); + + // 海报信息 + Long skuId = skuInfoVo.getId(); + // 创建查询条件,并删除之前的海报内容 + LambdaQueryWrapper wrapper = new LambdaQueryWrapper<>(); + wrapper.eq(SkuPoster::getSkuId, skuId); + skuPosterService.remove(wrapper); + + // 设置海报图片skuId值,并完成添加 + List skuPosterList = skuInfoVo.getSkuPosterList(); + if (!CollectionUtils.isEmpty(skuPosterList)) { + skuPosterList.forEach(skuPoster -> skuPoster.setSkuId(skuId)); + skuPosterService.saveBatch(skuPosterList); + } + + // 商品图片 + skuImageService.remove(Wrappers.lambdaQuery().eq(SkuImage::getSkuId, skuId)); + List skuImagesList = skuInfoVo.getSkuImagesList(); + if (!Collections.isEmpty(skuImagesList)) { + skuImagesList.forEach(skuImage -> skuImage.setSkuId(skuId)); + skuImageService.saveBatch(skuImagesList); + } + + // 商品属性 + skuAttrValueService.remove(Wrappers.lambdaQuery().eq(SkuAttrValue::getSkuId, skuId)); + List skuAttrValueList = skuInfoVo.getSkuAttrValueList(); + if (!Collections.isEmpty(skuAttrValueList)) { + skuAttrValueList.forEach(skuAttrValue -> skuAttrValue.setSkuId(skuId)); + skuAttrValueService.saveBatch(skuAttrValueList); + } + } + + /** + * 商品审核 + * + * @param skuId 商品ID + * @param status 商品状态 + */ + @Override + public void check(Long skuId, Integer status) { + SkuInfo skuInfo = new SkuInfo(); + skuInfo.setId(skuId); + skuInfo.setCheckStatus(status); + updateById(skuInfo); + } + + /** + * 商品上架 + * + * @param skuId 商品ID + * @param status 商品状态 + */ + @Override + public void publish(Long skuId, Integer status) { + SkuInfo skuInfo = new SkuInfo(); + skuInfo.setId(skuId); + if (status == 1) { + skuInfo.setPublishStatus(status); + // 商品上架,发送MQ消息 + rabbitService.sendMessage(MqConst.EXCHANGE_GOODS_DIRECT, MqConst.ROUTING_GOODS_UPPER, skuId); + } else { + skuInfo.setPublishStatus(0); + // 商品下架:发送mq消息同步es + rabbitService.sendMessage(MqConst.EXCHANGE_GOODS_DIRECT, MqConst.ROUTING_GOODS_LOWER, skuId); + } + baseMapper.updateById(skuInfo); + } + + /** + * 新人专享 + * + * @param skuId 商品ID + * @param status 商品状态 + */ + @Override + public void isNewPerson(Long skuId, Integer status) { + SkuInfo skuInfo = new SkuInfo(); + skuInfo.setId(skuId); + skuInfo.setIsNewPerson(status); + baseMapper.updateById(skuInfo); + } +} diff --git a/service/service-product/src/main/java/com/atguigu/ssyx/product/service/impl/SkuPosterServiceImpl.java b/service/service-product/src/main/java/com/atguigu/ssyx/product/service/impl/SkuPosterServiceImpl.java new file mode 100644 index 0000000..c7bba8c --- /dev/null +++ b/service/service-product/src/main/java/com/atguigu/ssyx/product/service/impl/SkuPosterServiceImpl.java @@ -0,0 +1,32 @@ +package com.atguigu.ssyx.product.service.impl; + +import com.atguigu.ssyx.model.product.SkuPoster; +import com.atguigu.ssyx.product.mapper.SkuPosterMapper; +import com.atguigu.ssyx.product.service.SkuPosterService; +import com.baomidou.mybatisplus.core.toolkit.Wrappers; +import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; +import org.springframework.stereotype.Service; + +import java.util.List; + +/** + *

+ * 商品海报表 服务实现类 + *

+ * + * @author bunny + * @since 2024-04-03 + */ +@Service +public class SkuPosterServiceImpl extends ServiceImpl implements SkuPosterService { + /** + * 根据id查询商品海报列表 + * + * @param id 商品id + * @return 图片列表 + */ + @Override + public List getPosterListBySkuId(Long id) { + return baseMapper.selectList(Wrappers.lambdaQuery().eq(SkuPoster::getSkuId, id)); + } +} diff --git a/service/service-product/src/main/resources/application-dev.yml b/service/service-product/src/main/resources/application-dev.yml new file mode 100644 index 0000000..189e4ce --- /dev/null +++ b/service/service-product/src/main/resources/application-dev.yml @@ -0,0 +1,27 @@ +server: + port: 8203 + +bunny: + rabbitmq: + host: 192.168.1.4 + port: 5672 + username: bunny + password: "02120212" + + datasource: + host: 106.15.251.123 + port: 3305 + sqlData: shequ-product + username: root + password: "02120212" + + nacos: + server-addr: z-bunny.cn:8848 + discovery: + namespace: ssyx + + minio: + endpointUrl: "http://129.211.31.58:9000" + bucket-name: ssyx + accessKey: bunny + secretKey: "02120212" \ No newline at end of file diff --git a/service/service-product/src/main/resources/application.yml b/service/service-product/src/main/resources/application.yml new file mode 100644 index 0000000..4399515 --- /dev/null +++ b/service/service-product/src/main/resources/application.yml @@ -0,0 +1,80 @@ +server: + port: 8203 +spring: + application: + name: service-product + profiles: + active: dev + + datasource: + type: com.zaxxer.hikari.HikariDataSource + driver-class-name: com.mysql.cj.jdbc.Driver + url: jdbc:mysql://${bunny.datasource.host}:${bunny.datasource.port}/${bunny.datasource.sqlData}?serverTimezone=GMT%2B8&useSSL=false&characterEncoding=utf-8&allowPublicKeyRetrieval=true + username: ${bunny.datasource.username} + password: ${bunny.datasource.password} + + cloud: + sentinel: + log: + dir: logs/${spring.application.name}/sentinel + nacos: + discovery: + namespace: ${bunny.nacos.discovery.namespace} + server-addr: ${bunny.nacos.server-addr} + + jackson: + date-format: yyyy-MM-dd HH:mm:ss + time-zone: GMT+8 + + rabbitmq: + host: ${bunny.rabbitmq.host} + port: ${bunny.rabbitmq.port} + username: ${bunny.rabbitmq.username} + password: ${bunny.rabbitmq.password} + publisher-confirm-type: CORRELATED + publisher-returns: true + listener: + simple: + prefetch: 1 + concurrency: 3 + acknowledge-mode: manual + retry: + enabled: true # 开启消费者失败重试 + initial-interval: 1000ms # 初始失败等待时长 + multiplier: 1 # 下次失败等待时间被树,下次等待时长 multiplier * last-interval + max-attempts: 3 # 最大重试次数 + stateless: true # true 无状态 false 有状态。如果业务中包含事务,这里改为false + +mybatis-plus: + type-aliases-package: com.atguigu.model # 配置每个包前缀 + mapper-locations: classpath:mapper/*.xml + configuration: + map-underscore-to-camel-case: true + auto-mapping-behavior: full + log-impl: org.apache.ibatis.logging.stdout.StdOutImpl # 查看日志 + global-config: + db-config: + # 设置表名前缀,不用在每个tableName添加前缀 + # table-prefix: t_ + # 全局配置主键值方式 + id-type: assign_id + logic-not-delete-value: 0 # 未删除默认为0 + logic-delete-value: 1 # 删除 + logic-delete-field: deleted # 全局配置逻辑删除 + +logging: + level: + com.atguigu.ssyx.product.mapper: debug + com.atguigu.ssyx.product.controller: info + com.atguigu.ssyx.product.service: info + pattern: + dateformat: HH:mm:ss:SSS + file: + path: "logs/${spring.application.name}" + +bunny: + minio: + endpointUrl: ${bunny.minio.endpointUrl} + accessKey: ${bunny.minio.accessKey} + secretKey: ${bunny.minio.secretKey} + bucket-name: ${bunny.minio.bucket-name} \ No newline at end of file diff --git a/service/service-product/src/main/resources/banner.txt b/service/service-product/src/main/resources/banner.txt new file mode 100644 index 0000000..cc77fc2 --- /dev/null +++ b/service/service-product/src/main/resources/banner.txt @@ -0,0 +1,16 @@ +-----------------▄██-█▄--------- +-----------------███▄██▄-------- +-----------------███████-------- +-----------------▀███████------- +-------------------██████▄▄----- +-------------------█████████▄--- +-------------------██████▄████-- +-------▄███████████████████████- +-----▄███████████████████████▀-- +---▄██████████████████████------ +---███████████████████████------ +---███████████████████████------ +-▄▄██████████████████████▀------ +-█████████████████▀█████-------- +-▀██████████████▀▀-▀█████▄------ +-------▀▀▀▀▀▀▀▀▀------▀▀▀▀------ \ No newline at end of file diff --git a/service/service-product/src/main/resources/favicon.ico b/service/service-product/src/main/resources/favicon.ico new file mode 100644 index 0000000..1ba397c Binary files /dev/null and b/service/service-product/src/main/resources/favicon.ico differ diff --git a/service/service-product/src/main/resources/mapper/AttrGroupMapper.xml b/service/service-product/src/main/resources/mapper/AttrGroupMapper.xml new file mode 100644 index 0000000..bef7818 --- /dev/null +++ b/service/service-product/src/main/resources/mapper/AttrGroupMapper.xml @@ -0,0 +1,5 @@ + + + + + diff --git a/service/service-product/src/main/resources/mapper/AttrMapper.xml b/service/service-product/src/main/resources/mapper/AttrMapper.xml new file mode 100644 index 0000000..55a85a3 --- /dev/null +++ b/service/service-product/src/main/resources/mapper/AttrMapper.xml @@ -0,0 +1,5 @@ + + + + + diff --git a/service/service-product/src/main/resources/mapper/BaseCategoryTrademarkMapper.xml b/service/service-product/src/main/resources/mapper/BaseCategoryTrademarkMapper.xml new file mode 100644 index 0000000..61edfa2 --- /dev/null +++ b/service/service-product/src/main/resources/mapper/BaseCategoryTrademarkMapper.xml @@ -0,0 +1,5 @@ + + + + + diff --git a/service/service-product/src/main/resources/mapper/CategoryMapper.xml b/service/service-product/src/main/resources/mapper/CategoryMapper.xml new file mode 100644 index 0000000..ed9278f --- /dev/null +++ b/service/service-product/src/main/resources/mapper/CategoryMapper.xml @@ -0,0 +1,5 @@ + + + + + diff --git a/service/service-product/src/main/resources/mapper/CommentMapper.xml b/service/service-product/src/main/resources/mapper/CommentMapper.xml new file mode 100644 index 0000000..90b190c --- /dev/null +++ b/service/service-product/src/main/resources/mapper/CommentMapper.xml @@ -0,0 +1,5 @@ + + + + + diff --git a/service/service-product/src/main/resources/mapper/CommentReplayMapper.xml b/service/service-product/src/main/resources/mapper/CommentReplayMapper.xml new file mode 100644 index 0000000..564d57b --- /dev/null +++ b/service/service-product/src/main/resources/mapper/CommentReplayMapper.xml @@ -0,0 +1,5 @@ + + + + + diff --git a/service/service-product/src/main/resources/mapper/MqRepeatRecordMapper.xml b/service/service-product/src/main/resources/mapper/MqRepeatRecordMapper.xml new file mode 100644 index 0000000..b961147 --- /dev/null +++ b/service/service-product/src/main/resources/mapper/MqRepeatRecordMapper.xml @@ -0,0 +1,5 @@ + + + + + diff --git a/service/service-product/src/main/resources/mapper/RegionWareMapper.xml b/service/service-product/src/main/resources/mapper/RegionWareMapper.xml new file mode 100644 index 0000000..ee53825 --- /dev/null +++ b/service/service-product/src/main/resources/mapper/RegionWareMapper.xml @@ -0,0 +1,5 @@ + + + + + diff --git a/service/service-product/src/main/resources/mapper/SkuAttrValueMapper.xml b/service/service-product/src/main/resources/mapper/SkuAttrValueMapper.xml new file mode 100644 index 0000000..bcf744e --- /dev/null +++ b/service/service-product/src/main/resources/mapper/SkuAttrValueMapper.xml @@ -0,0 +1,5 @@ + + + + + diff --git a/service/service-product/src/main/resources/mapper/SkuDetailMapper.xml b/service/service-product/src/main/resources/mapper/SkuDetailMapper.xml new file mode 100644 index 0000000..7df959c --- /dev/null +++ b/service/service-product/src/main/resources/mapper/SkuDetailMapper.xml @@ -0,0 +1,5 @@ + + + + + diff --git a/service/service-product/src/main/resources/mapper/SkuImageMapper.xml b/service/service-product/src/main/resources/mapper/SkuImageMapper.xml new file mode 100644 index 0000000..b144efe --- /dev/null +++ b/service/service-product/src/main/resources/mapper/SkuImageMapper.xml @@ -0,0 +1,5 @@ + + + + + diff --git a/service/service-product/src/main/resources/mapper/SkuInfoMapper.xml b/service/service-product/src/main/resources/mapper/SkuInfoMapper.xml new file mode 100644 index 0000000..5052dec --- /dev/null +++ b/service/service-product/src/main/resources/mapper/SkuInfoMapper.xml @@ -0,0 +1,5 @@ + + + + + diff --git a/service/service-product/src/main/resources/mapper/SkuPosterMapper.xml b/service/service-product/src/main/resources/mapper/SkuPosterMapper.xml new file mode 100644 index 0000000..010e3dd --- /dev/null +++ b/service/service-product/src/main/resources/mapper/SkuPosterMapper.xml @@ -0,0 +1,5 @@ + + + + + diff --git a/service/service-product/src/main/resources/mapper/SkuStockHistoryMapper.xml b/service/service-product/src/main/resources/mapper/SkuStockHistoryMapper.xml new file mode 100644 index 0000000..102a7df --- /dev/null +++ b/service/service-product/src/main/resources/mapper/SkuStockHistoryMapper.xml @@ -0,0 +1,5 @@ + + + + + diff --git a/service/service-product/src/main/resources/mapper/WareMapper.xml b/service/service-product/src/main/resources/mapper/WareMapper.xml new file mode 100644 index 0000000..2765aed --- /dev/null +++ b/service/service-product/src/main/resources/mapper/WareMapper.xml @@ -0,0 +1,5 @@ + + + + + diff --git a/service/service-search/Dockerfile b/service/service-search/Dockerfile new file mode 100644 index 0000000..ef109ac --- /dev/null +++ b/service/service-search/Dockerfile @@ -0,0 +1,21 @@ +FROM openjdk:17 +MAINTAINER bunny + +#系统编码 +ENV LANG=C.UTF-8 LC_ALL=C.UTF-8 + +# 设置时区,构建镜像时执行的命令 +RUN ln -sf /usr/share/zoneinfo/Asia/Shanghai /etc/localtime +RUN echo "Asia/Shanghai" > /etc/timezone + +# 设定工作目录 +WORKDIR /home/bunny + +# 复制jar包 +COPY target/*.jar /home/bunny/app.jar + +#启动容器时的进程 +ENTRYPOINT ["java","-jar","/home/bunny/app.jar"] + +#暴露 8080 端口 +EXPOSE 8080 \ No newline at end of file diff --git a/service/service-search/pom.xml b/service/service-search/pom.xml new file mode 100644 index 0000000..4859f50 --- /dev/null +++ b/service/service-search/pom.xml @@ -0,0 +1,42 @@ + + 4.0.0 + + com.atguigu + service + 1.0-SNAPSHOT + + + service-search + jar + + service-search + https://maven.apache.org + + + UTF-8 + + + + + com.atguigu + rabbit-util + 1.0-SNAPSHOT + + + com.atguigu + service-product-client + 1.0-SNAPSHOT + + + + org.springframework.boot + spring-boot-starter-data-elasticsearch + + + + org.springframework.boot + spring-boot-starter-data-redis + + + diff --git a/service/service-search/src/main/java/com/atguigu/ssyx/search/MqListener/SkuListener.java b/service/service-search/src/main/java/com/atguigu/ssyx/search/MqListener/SkuListener.java new file mode 100644 index 0000000..2ef9022 --- /dev/null +++ b/service/service-search/src/main/java/com/atguigu/ssyx/search/MqListener/SkuListener.java @@ -0,0 +1,40 @@ +package com.atguigu.ssyx.search.MqListener; + +import com.atguigu.ssyx.mq.constant.MqConst; +import com.rabbitmq.client.Channel; +import org.springframework.amqp.core.Message; +import org.springframework.amqp.rabbit.annotation.Exchange; +import org.springframework.amqp.rabbit.annotation.Queue; +import org.springframework.amqp.rabbit.annotation.QueueBinding; +import org.springframework.amqp.rabbit.annotation.RabbitListener; +import org.springframework.stereotype.Component; + +import java.io.IOException; + +@Component +public class SkuListener { + // 商品上架 + @RabbitListener(bindings = @QueueBinding( + value = @Queue(name = MqConst.QUEUE_GOODS_UPPER, durable = "true"), + exchange = @Exchange(name = MqConst.EXCHANGE_GOODS_DIRECT), + key = {MqConst.ROUTING_GOODS_UPPER} + )) + public void upperSku(Long skuId, Message message, Channel channel) throws IOException { + if (skuId != null) { + channel.basicAck(message.getMessageProperties().getDeliveryTag(), false); + } + } + + // 商品下架 + @RabbitListener(bindings = @QueueBinding( + value = @Queue(name = MqConst.QUEUE_GOODS_LOWER, durable = "true"), + exchange = @Exchange(name = MqConst.EXCHANGE_GOODS_DIRECT), + key = {MqConst.ROUTING_GOODS_LOWER} + )) + public void lowerSku(Long skuId, Message message, Channel channel) throws IOException { + if (skuId != null) { + channel.basicAck(message.getMessageProperties().getDeliveryTag(), false); + } + } +} + diff --git a/service/service-search/src/main/java/com/atguigu/ssyx/search/ServiceSearchApplication.java b/service/service-search/src/main/java/com/atguigu/ssyx/search/ServiceSearchApplication.java new file mode 100644 index 0000000..80fa2f2 --- /dev/null +++ b/service/service-search/src/main/java/com/atguigu/ssyx/search/ServiceSearchApplication.java @@ -0,0 +1,21 @@ +package com.atguigu.ssyx.search; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration; +import org.springframework.cloud.client.discovery.EnableDiscoveryClient; +import org.springframework.cloud.openfeign.EnableFeignClients; +import org.springframework.context.annotation.ComponentScan; + +@SpringBootApplication(exclude = DataSourceAutoConfiguration.class) +@ComponentScan(basePackages = { + "com.atguigu.ssyx.common", + "com.atguigu.ssyx.mq", + "com.atguigu.ssyx.search"}) +@EnableFeignClients(basePackages = {"com.atguigu.ssyx.client"}) +@EnableDiscoveryClient +public class ServiceSearchApplication { + public static void main(String[] args) { + SpringApplication.run(ServiceSearchApplication.class, args); + } +} diff --git a/service/service-search/src/main/java/com/atguigu/ssyx/search/config/Knife4jConfig.java b/service/service-search/src/main/java/com/atguigu/ssyx/search/config/Knife4jConfig.java new file mode 100644 index 0000000..d35c421 --- /dev/null +++ b/service/service-search/src/main/java/com/atguigu/ssyx/search/config/Knife4jConfig.java @@ -0,0 +1,54 @@ +package com.atguigu.ssyx.search.config; + +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import springfox.documentation.builders.ApiInfoBuilder; +import springfox.documentation.builders.ParameterBuilder; +import springfox.documentation.builders.PathSelectors; +import springfox.documentation.builders.RequestHandlerSelectors; +import springfox.documentation.schema.ModelRef; +import springfox.documentation.service.ApiInfo; +import springfox.documentation.service.Contact; +import springfox.documentation.service.Parameter; +import springfox.documentation.spi.DocumentationType; +import springfox.documentation.spring.web.plugins.Docket; +import springfox.documentation.swagger2.annotations.EnableSwagger2WebMvc; + +import java.util.ArrayList; +import java.util.List; + +@Configuration +@EnableSwagger2WebMvc +public class Knife4jConfig { + @Bean + public Docket adminApiConfig() { + List pars = new ArrayList<>(); + ParameterBuilder tokenPar = new ParameterBuilder(); + tokenPar.name("adminId") + .description("用户token") + .defaultValue("1") + .modelRef(new ModelRef("string")) + .parameterType("header") + .required(false) + .build(); + pars.add(tokenPar.build()); + + return new Docket(DocumentationType.SWAGGER_2) + .groupName("搜索ES相关API") + .apiInfo(adminApiInfo()) + .select() + .apis(RequestHandlerSelectors.basePackage("com.atguigu.ssyx.search.controller")) + .paths(PathSelectors.regex("/api/.*")) + .build() + .globalOperationParameters(pars); + } + + private ApiInfo adminApiInfo() { + return new ApiInfoBuilder() + .title("后台管理系统-API文档") + .description("本文档描述了尚上优选后台系统服务接口定义") + .version("1.0") + .contact(new Contact("atguigu", "http://atguigu.com", "atguigu")) + .build(); + } +} \ No newline at end of file diff --git a/service/service-search/src/main/java/com/atguigu/ssyx/search/controller/SkuApiController.java b/service/service-search/src/main/java/com/atguigu/ssyx/search/controller/SkuApiController.java new file mode 100644 index 0000000..9e5155c --- /dev/null +++ b/service/service-search/src/main/java/com/atguigu/ssyx/search/controller/SkuApiController.java @@ -0,0 +1,34 @@ +package com.atguigu.ssyx.search.controller; + +import com.atguigu.ssyx.common.result.Result; +import com.atguigu.ssyx.model.product.SkuInfo; +import com.atguigu.ssyx.search.service.SkuService; +import io.swagger.annotations.Api; +import io.swagger.annotations.ApiOperation; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +@Api(tags = "商品添加到ES") +@RestController +@RequestMapping("/api/search/sku") +public class SkuApiController { + @Autowired + private SkuService skuService; + + @ApiOperation(value = "上架商品") + @GetMapping("inner/upperSku/{skuId}") + public Result upperGoods(@PathVariable Long skuId) { + skuService.upperSku(skuId); + return Result.success(); + } + + @ApiOperation(value = "下架商品") + @GetMapping("inner/lowerSku/{skuId}") + public Result lowerGoods(@PathVariable Long skuId) { + skuService.lowerGoods(skuId); + return Result.success(); + } +} diff --git a/service/service-search/src/main/java/com/atguigu/ssyx/search/repository/SkuRepository.java b/service/service-search/src/main/java/com/atguigu/ssyx/search/repository/SkuRepository.java new file mode 100644 index 0000000..718fb65 --- /dev/null +++ b/service/service-search/src/main/java/com/atguigu/ssyx/search/repository/SkuRepository.java @@ -0,0 +1,7 @@ +package com.atguigu.ssyx.search.repository; + +import com.atguigu.ssyx.model.search.SkuEs; +import org.springframework.data.elasticsearch.repository.ElasticsearchRepository; + +public interface SkuRepository extends ElasticsearchRepository { +} diff --git a/service/service-search/src/main/java/com/atguigu/ssyx/search/service/SkuService.java b/service/service-search/src/main/java/com/atguigu/ssyx/search/service/SkuService.java new file mode 100644 index 0000000..d16d006 --- /dev/null +++ b/service/service-search/src/main/java/com/atguigu/ssyx/search/service/SkuService.java @@ -0,0 +1,17 @@ +package com.atguigu.ssyx.search.service; + +public interface SkuService { + /** + * 上架商品 + * + * @param skuId 商品ID + */ + void upperSku(Long skuId); + + /** + * 下架商品 + * + * @param skuId 商品ID + */ + void lowerGoods(Long skuId); +} diff --git a/service/service-search/src/main/java/com/atguigu/ssyx/search/service/impl/SkuServiceImpl.java b/service/service-search/src/main/java/com/atguigu/ssyx/search/service/impl/SkuServiceImpl.java new file mode 100644 index 0000000..8cdd3c6 --- /dev/null +++ b/service/service-search/src/main/java/com/atguigu/ssyx/search/service/impl/SkuServiceImpl.java @@ -0,0 +1,64 @@ +package com.atguigu.ssyx.search.service.impl; + +import com.atguigu.ssyx.client.product.ProductFeignClient; +import com.atguigu.ssyx.enums.SkuType; +import com.atguigu.ssyx.model.product.Category; +import com.atguigu.ssyx.model.product.SkuInfo; +import com.atguigu.ssyx.model.search.SkuEs; +import com.atguigu.ssyx.search.repository.SkuRepository; +import com.atguigu.ssyx.search.service.SkuService; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +import java.util.Objects; + +@Service +public class SkuServiceImpl implements SkuService { + @Autowired + private SkuRepository skuRepository; + @Autowired + private ProductFeignClient productFeignClient; + + /** + * 上架商品 + * + * @param skuId 商品ID + */ + @Override + public void upperSku(Long skuId) { + SkuInfo skuInfo = productFeignClient.getSkuInfo(skuId).getData(); + Category category = productFeignClient.getCategory(skuId).getData(); + // 获取数据封装SkuEs + SkuEs skuEs = new SkuEs(); + if (category != null) { + skuEs.setCategoryId(category.getId()); + skuEs.setCategoryName(category.getName()); + } + if (skuInfo != null) { + skuEs.setId(skuInfo.getId()); + skuEs.setKeyword(skuInfo.getSkuName() + "," + skuEs.getCategoryName()); + skuEs.setWareId(skuInfo.getWareId()); + skuEs.setIsNewPerson(skuInfo.getIsNewPerson()); + skuEs.setImgUrl(skuInfo.getImgUrl()); + skuEs.setTitle(skuInfo.getSkuName()); + if (Objects.equals(skuInfo.getSkuType(), SkuType.COMMON.getCode())) { + skuEs.setSkuType(0); + skuEs.setPrice(skuInfo.getPrice().doubleValue()); + skuEs.setStock(skuInfo.getStock()); + skuEs.setSale(skuInfo.getSale()); + skuEs.setPerLimit(skuInfo.getPerLimit()); + } + skuRepository.save(skuEs); + } + } + + /** + * 下架商品 + * + * @param skuId 商品ID + */ + @Override + public void lowerGoods(Long skuId) { + skuRepository.deleteById(skuId); + } +} diff --git a/service/service-search/src/main/resources/application-dev.yml b/service/service-search/src/main/resources/application-dev.yml new file mode 100644 index 0000000..e1320f4 --- /dev/null +++ b/service/service-search/src/main/resources/application-dev.yml @@ -0,0 +1,29 @@ +server: + port: 8208 + +bunny: + rabbitmq: + host: 192.168.1.4 + port: 5672 + username: bunny + password: "02120212" + + elasticsearch: + uris: http://192.168.1.4:9200 + + nacos: + server-addr: z-bunny.cn:8848 + discovery: + namespace: ssyx + + redis: + host: 47.120.65.66 + port: 6379 + database: 3 + password: "02120212" + + minio: + endpointUrl: "http://129.211.31.58:9000" + bucket-name: ssyx + accessKey: bunny + secretKey: "02120212" \ No newline at end of file diff --git a/service/service-search/src/main/resources/application.yml b/service/service-search/src/main/resources/application.yml new file mode 100644 index 0000000..ee3868e --- /dev/null +++ b/service/service-search/src/main/resources/application.yml @@ -0,0 +1,81 @@ +server: + port: 8208 +spring: + application: + name: service-search + profiles: + active: dev + + redis: + host: ${bunny.redis.host} + port: ${bunny.redis.port} + database: ${bunny.redis.database} + password: ${bunny.redis.password} + lettuce: + pool: + max-active: 20 #最大连接数 + max-wait: -1 #最大阻塞等待时间(负数表示没限制) + max-idle: 5 #最大空闲 + min-idle: 0 #最小空闲 + + elasticsearch: + rest: + uris: ${bunny.elasticsearch.uris} + + rabbitmq: + host: ${bunny.rabbitmq.host} + port: ${bunny.rabbitmq.port} + username: ${bunny.rabbitmq.username} + password: ${bunny.rabbitmq.password} + publisher-confirm-type: CORRELATED + publisher-returns: true + listener: + simple: + prefetch: 1 + concurrency: 3 + acknowledge-mode: manual + retry: + enabled: true # 开启消费者失败重试 + initial-interval: 1000ms # 初始失败等待时长 + multiplier: 1 # 下次失败等待时间被树,下次等待时长 multiplier * last-interval + max-attempts: 3 # 最大重试次数 + stateless: true # true 无状态 false 有状态。如果业务中包含事务,这里改为false + + cloud: + sentinel: + log: + dir: logs/${spring.application.name}/sentinel + nacos: + discovery: + namespace: ${bunny.nacos.discovery.namespace} + server-addr: ${bunny.nacos.server-addr} + + jackson: + date-format: yyyy-MM-dd HH:mm:ss + time-zone: GMT+8 + +bunny: + minio: + endpointUrl: ${bunny.minio.endpointUrl} + accessKey: ${bunny.minio.accessKey} + secretKey: ${bunny.minio.secretKey} + bucket-name: ${bunny.minio.bucket-name} + +feign: + sentinel: + enabled: true + client: + config: + default: #配置全局的feign的调用超时时间 如果 有指定的服务配置 默认的配置不会生效 + connectTimeout: 30000 # 指定的是 消费者 连接服务提供者的连接超时时间 是否能连接 单位是毫秒 + readTimeout: 50000 # 指定的是调用服务提供者的 服务 的超时时间() 单位是毫秒 + +logging: + level: + com.atguigu.ssyx.search.mapper: debug + com.atguigu.ssyx.search.controller: info + com.atguigu.ssyx.search.service: info + pattern: + dateformat: HH:mm:ss:SSS + file: + path: "logs/${spring.application.name}" \ No newline at end of file diff --git a/service/service-search/src/main/resources/banner.txt b/service/service-search/src/main/resources/banner.txt new file mode 100644 index 0000000..cc77fc2 --- /dev/null +++ b/service/service-search/src/main/resources/banner.txt @@ -0,0 +1,16 @@ +-----------------▄██-█▄--------- +-----------------███▄██▄-------- +-----------------███████-------- +-----------------▀███████------- +-------------------██████▄▄----- +-------------------█████████▄--- +-------------------██████▄████-- +-------▄███████████████████████- +-----▄███████████████████████▀-- +---▄██████████████████████------ +---███████████████████████------ +---███████████████████████------ +-▄▄██████████████████████▀------ +-█████████████████▀█████-------- +-▀██████████████▀▀-▀█████▄------ +-------▀▀▀▀▀▀▀▀▀------▀▀▀▀------ \ No newline at end of file diff --git a/service/service-search/src/main/resources/favicon.ico b/service/service-search/src/main/resources/favicon.ico new file mode 100644 index 0000000..1ba397c Binary files /dev/null and b/service/service-search/src/main/resources/favicon.ico differ diff --git a/service/service-sys/Dockerfile b/service/service-sys/Dockerfile new file mode 100644 index 0000000..ef109ac --- /dev/null +++ b/service/service-sys/Dockerfile @@ -0,0 +1,21 @@ +FROM openjdk:17 +MAINTAINER bunny + +#系统编码 +ENV LANG=C.UTF-8 LC_ALL=C.UTF-8 + +# 设置时区,构建镜像时执行的命令 +RUN ln -sf /usr/share/zoneinfo/Asia/Shanghai /etc/localtime +RUN echo "Asia/Shanghai" > /etc/timezone + +# 设定工作目录 +WORKDIR /home/bunny + +# 复制jar包 +COPY target/*.jar /home/bunny/app.jar + +#启动容器时的进程 +ENTRYPOINT ["java","-jar","/home/bunny/app.jar"] + +#暴露 8080 端口 +EXPOSE 8080 \ No newline at end of file diff --git a/service/service-sys/pom.xml b/service/service-sys/pom.xml new file mode 100644 index 0000000..ec1ceaf --- /dev/null +++ b/service/service-sys/pom.xml @@ -0,0 +1,23 @@ + + 4.0.0 + + com.atguigu + service + 1.0-SNAPSHOT + + + service-sys + jar + + service-sys + https://maven.apache.org + + + UTF-8 + + + + + + diff --git a/service/service-sys/src/main/java/com/atguigu/ssyx/sys/ServiceSysApplication.java b/service/service-sys/src/main/java/com/atguigu/ssyx/sys/ServiceSysApplication.java new file mode 100644 index 0000000..2e64406 --- /dev/null +++ b/service/service-sys/src/main/java/com/atguigu/ssyx/sys/ServiceSysApplication.java @@ -0,0 +1,17 @@ +package com.atguigu.ssyx.sys; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.context.annotation.ComponentScan; +import org.springframework.transaction.annotation.EnableTransactionManagement; + +@SpringBootApplication +@EnableTransactionManagement +@ComponentScan(basePackages = { + "com.atguigu.ssyx.common", + "com.atguigu.ssyx.sys"}) +public class ServiceSysApplication { + public static void main(String[] args) { + SpringApplication.run(ServiceSysApplication.class, args); + } +} diff --git a/common/service-util/src/main/java/com/atguigu/ssyx/common/config/Swagger2Config.java b/service/service-sys/src/main/java/com/atguigu/ssyx/sys/config/Knife4jConfig.java similarity index 59% rename from common/service-util/src/main/java/com/atguigu/ssyx/common/config/Swagger2Config.java rename to service/service-sys/src/main/java/com/atguigu/ssyx/sys/config/Knife4jConfig.java index 39d48b1..990b1c8 100644 --- a/common/service-util/src/main/java/com/atguigu/ssyx/common/config/Swagger2Config.java +++ b/service/service-sys/src/main/java/com/atguigu/ssyx/sys/config/Knife4jConfig.java @@ -1,4 +1,4 @@ -package com.atguigu.ssyx.common.config; +package com.atguigu.ssyx.sys.config; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; @@ -17,13 +17,9 @@ import springfox.documentation.swagger2.annotations.EnableSwagger2WebMvc; import java.util.ArrayList; import java.util.List; -/** - * Swagger2配置信息 - */ @Configuration @EnableSwagger2WebMvc -public class Swagger2Config { - +public class Knife4jConfig { @Bean public Docket webApiConfig() { List pars = new ArrayList<>(); @@ -39,35 +35,11 @@ public class Swagger2Config { pars.add(tokenPar.build()); return new Docket(DocumentationType.SWAGGER_2) - .groupName("webApi") + .groupName("区域查询API") .apiInfo(webApiInfo()) .select() // 只显示api路径下的页面 - .apis(RequestHandlerSelectors.basePackage("com.atguigu.ssyx")) - .paths(PathSelectors.regex("/api/.*")) - .build() - .globalOperationParameters(pars); - } - - @Bean - public Docket adminApiConfig() { - List pars = new ArrayList<>(); - ParameterBuilder tokenPar = new ParameterBuilder(); - tokenPar.name("adminId") - .description("用户token") - .defaultValue("1") - .modelRef(new ModelRef("string")) - .parameterType("header") - .required(false) - .build(); - pars.add(tokenPar.build()); - - return new Docket(DocumentationType.SWAGGER_2) - .groupName("adminApi") - .apiInfo(adminApiInfo()) - .select() - // 只显示admin路径下的页面 - .apis(RequestHandlerSelectors.basePackage("com.atguigu.ssyx")) + .apis(RequestHandlerSelectors.basePackage("com.atguigu.ssyx.sys")) .paths(PathSelectors.regex("/admin/.*")) .build() .globalOperationParameters(pars); @@ -81,13 +53,4 @@ public class Swagger2Config { .contact(new Contact("atguigu", "http://atguigu.com", "atguigu")) .build(); } - - private ApiInfo adminApiInfo() { - return new ApiInfoBuilder() - .title("后台管理系统-API文档") - .description("本文档描述了尚上优选后台系统服务接口定义") - .version("1.0") - .contact(new Contact("atguigu", "http://atguigu.com", "atguigu")) - .build(); - } } \ No newline at end of file diff --git a/service/service-sys/src/main/java/com/atguigu/ssyx/sys/controller/RegionController.java b/service/service-sys/src/main/java/com/atguigu/ssyx/sys/controller/RegionController.java new file mode 100644 index 0000000..af9e6ab --- /dev/null +++ b/service/service-sys/src/main/java/com/atguigu/ssyx/sys/controller/RegionController.java @@ -0,0 +1,31 @@ +package com.atguigu.ssyx.sys.controller; + + +import com.atguigu.ssyx.common.result.Result; +import com.atguigu.ssyx.model.sys.Region; +import com.atguigu.ssyx.sys.service.RegionService; +import io.swagger.annotations.Api; +import io.swagger.annotations.ApiOperation; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +import java.util.List; + +@Api(tags = "区域接口") +@RestController +@RequestMapping("/admin/sys/region") +public class RegionController { + @Autowired + private RegionService regionService; + + @ApiOperation(value = "根据关键字获取地区列表") + @GetMapping("findRegionByKeyword/{keyword}") + public Result> findRegionByKeyword(@PathVariable("keyword") String keyword) { + List regionList = regionService.findRegionByKeyword(keyword); + return Result.success(regionList); + } +} + diff --git a/service/service-sys/src/main/java/com/atguigu/ssyx/sys/controller/RegionWareController.java b/service/service-sys/src/main/java/com/atguigu/ssyx/sys/controller/RegionWareController.java new file mode 100644 index 0000000..5cc9bfa --- /dev/null +++ b/service/service-sys/src/main/java/com/atguigu/ssyx/sys/controller/RegionWareController.java @@ -0,0 +1,61 @@ +package com.atguigu.ssyx.sys.controller; + + +import com.atguigu.ssyx.common.result.Result; +import com.atguigu.ssyx.model.sys.RegionWare; +import com.atguigu.ssyx.model.sys.Ware; +import com.atguigu.ssyx.sys.service.RegionWareService; +import com.atguigu.ssyx.vo.sys.RegionWareQueryVo; +import com.baomidou.mybatisplus.core.metadata.IPage; +import com.baomidou.mybatisplus.extension.plugins.pagination.Page; +import io.swagger.annotations.Api; +import io.swagger.annotations.ApiOperation; +import io.swagger.annotations.ApiParam; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.web.bind.annotation.*; + +@Api(value = "RegionWare管理", tags = "RegionWare管理") +@RestController +@RequestMapping(value = "/admin/sys/regionWare") +public class RegionWareController { + @Autowired + private RegionWareService regionWareService; + + @ApiOperation(value = "获取开通区域列表") + @GetMapping("{page}/{limit}") + public Result> index( + @ApiParam(name = "page", value = "当前页码", required = true) + @PathVariable Long page, + @ApiParam(name = "limit", value = "每页记录数", required = true) + @PathVariable Long limit, + @ApiParam(name = "regionWareVo", value = "查询对象", required = false) + RegionWareQueryVo regionWareQueryVo) { + + Page pageParam = new Page<>(page, limit); + IPage pageModel = regionWareService.selectPage(pageParam, regionWareQueryVo); + + return Result.success(pageModel); + } + + @ApiOperation(value = "添加开通区域") + @PostMapping("save") + public Result save(@RequestBody RegionWare regionWare) { + regionWareService.saveRegionWare(regionWare); + return Result.success(); + } + + @ApiOperation(value = "删除") + @DeleteMapping("remove/{id}") + public Result remove(@PathVariable Long id) { + regionWareService.removeById(id); + return Result.success(); + } + + @ApiOperation(value = "取消开通区域") + @PostMapping("updateStatus/{id}/{status}") + public Result updateStatus(@PathVariable Long id, @PathVariable Integer status) { + regionWareService.updateStatus(id, status); + return Result.success(); + } +} + diff --git a/service/service-sys/src/main/java/com/atguigu/ssyx/sys/controller/WareController.java b/service/service-sys/src/main/java/com/atguigu/ssyx/sys/controller/WareController.java new file mode 100644 index 0000000..56abc39 --- /dev/null +++ b/service/service-sys/src/main/java/com/atguigu/ssyx/sys/controller/WareController.java @@ -0,0 +1,29 @@ +package com.atguigu.ssyx.sys.controller; + + +import com.atguigu.ssyx.common.result.Result; +import com.atguigu.ssyx.model.sys.Ware; +import com.atguigu.ssyx.sys.service.WareService; +import io.swagger.annotations.Api; +import io.swagger.annotations.ApiOperation; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +import java.util.List; + +@Api(value = "Ware管理", tags = "Ware管理") +@RestController +@RequestMapping(value = "/admin/sys/ware") +public class WareController { + @Autowired + private WareService wareService; + + @ApiOperation(value = "获取全部仓库") + @GetMapping("findAllList") + public Result> findAllList() { + return Result.success(wareService.list()); + } +} + diff --git a/service/service-sys/src/main/java/com/atguigu/ssyx/sys/mapper/RegionMapper.java b/service/service-sys/src/main/java/com/atguigu/ssyx/sys/mapper/RegionMapper.java new file mode 100644 index 0000000..ffb7879 --- /dev/null +++ b/service/service-sys/src/main/java/com/atguigu/ssyx/sys/mapper/RegionMapper.java @@ -0,0 +1,16 @@ +package com.atguigu.ssyx.sys.mapper; + +import com.atguigu.ssyx.model.sys.Region; +import com.baomidou.mybatisplus.core.mapper.BaseMapper; + +/** + *

+ * 地区表 Mapper 接口 + *

+ * + * @author atguigu + * @since 2024-04-02 + */ +public interface RegionMapper extends BaseMapper { + +} diff --git a/service/service-sys/src/main/java/com/atguigu/ssyx/sys/mapper/RegionWareMapper.java b/service/service-sys/src/main/java/com/atguigu/ssyx/sys/mapper/RegionWareMapper.java new file mode 100644 index 0000000..2176497 --- /dev/null +++ b/service/service-sys/src/main/java/com/atguigu/ssyx/sys/mapper/RegionWareMapper.java @@ -0,0 +1,16 @@ +package com.atguigu.ssyx.sys.mapper; + +import com.atguigu.ssyx.model.sys.RegionWare; +import com.baomidou.mybatisplus.core.mapper.BaseMapper; + +/** + *

+ * 城市仓库关联表 Mapper 接口 + *

+ * + * @author atguigu + * @since 2024-04-02 + */ +public interface RegionWareMapper extends BaseMapper { + +} diff --git a/service/service-sys/src/main/java/com/atguigu/ssyx/sys/mapper/WareMapper.java b/service/service-sys/src/main/java/com/atguigu/ssyx/sys/mapper/WareMapper.java new file mode 100644 index 0000000..a0704b2 --- /dev/null +++ b/service/service-sys/src/main/java/com/atguigu/ssyx/sys/mapper/WareMapper.java @@ -0,0 +1,16 @@ +package com.atguigu.ssyx.sys.mapper; + +import com.atguigu.ssyx.model.sys.Ware; +import com.baomidou.mybatisplus.core.mapper.BaseMapper; + +/** + *

+ * 仓库表 Mapper 接口 + *

+ * + * @author atguigu + * @since 2024-04-02 + */ +public interface WareMapper extends BaseMapper { + +} diff --git a/service/service-sys/src/main/java/com/atguigu/ssyx/sys/service/RegionService.java b/service/service-sys/src/main/java/com/atguigu/ssyx/sys/service/RegionService.java new file mode 100644 index 0000000..2939567 --- /dev/null +++ b/service/service-sys/src/main/java/com/atguigu/ssyx/sys/service/RegionService.java @@ -0,0 +1,25 @@ +package com.atguigu.ssyx.sys.service; + +import com.atguigu.ssyx.model.sys.Region; +import com.baomidou.mybatisplus.extension.service.IService; + +import java.util.List; + +/** + *

+ * 地区表 服务类 + *

+ * + * @author atguigu + * @since 2024-04-02 + */ +public interface RegionService extends IService { + + /** + * 根据关键字获取地区列表 + * + * @param keyword 关键字 + * @return List + */ + List findRegionByKeyword(String keyword); +} diff --git a/service/service-sys/src/main/java/com/atguigu/ssyx/sys/service/RegionWareService.java b/service/service-sys/src/main/java/com/atguigu/ssyx/sys/service/RegionWareService.java new file mode 100644 index 0000000..1b261c1 --- /dev/null +++ b/service/service-sys/src/main/java/com/atguigu/ssyx/sys/service/RegionWareService.java @@ -0,0 +1,25 @@ +package com.atguigu.ssyx.sys.service; + +import com.atguigu.ssyx.model.sys.RegionWare; +import com.atguigu.ssyx.vo.sys.RegionWareQueryVo; +import com.baomidou.mybatisplus.core.metadata.IPage; +import com.baomidou.mybatisplus.extension.plugins.pagination.Page; +import com.baomidou.mybatisplus.extension.service.IService; + +public interface RegionWareService extends IService { + + /** + * 开通区域列表 + */ + IPage selectPage(Page pageParam, RegionWareQueryVo regionWareQueryVo); + + /** + * 添加开通区域 + */ + void saveRegionWare(RegionWare regionWare); + + /** + * 取消开通区域 + */ + void updateStatus(Long id, Integer status); +} diff --git a/service/service-sys/src/main/java/com/atguigu/ssyx/sys/service/WareService.java b/service/service-sys/src/main/java/com/atguigu/ssyx/sys/service/WareService.java new file mode 100644 index 0000000..8fc37a7 --- /dev/null +++ b/service/service-sys/src/main/java/com/atguigu/ssyx/sys/service/WareService.java @@ -0,0 +1,16 @@ +package com.atguigu.ssyx.sys.service; + +import com.atguigu.ssyx.model.sys.Ware; +import com.baomidou.mybatisplus.extension.service.IService; + +/** + *

+ * 仓库表 服务类 + *

+ * + * @author atguigu + * @since 2024-04-02 + */ +public interface WareService extends IService { + +} diff --git a/service/service-sys/src/main/java/com/atguigu/ssyx/sys/service/impl/RegionServiceImpl.java b/service/service-sys/src/main/java/com/atguigu/ssyx/sys/service/impl/RegionServiceImpl.java new file mode 100644 index 0000000..55d6a74 --- /dev/null +++ b/service/service-sys/src/main/java/com/atguigu/ssyx/sys/service/impl/RegionServiceImpl.java @@ -0,0 +1,33 @@ +package com.atguigu.ssyx.sys.service.impl; + +import com.atguigu.ssyx.model.sys.Region; +import com.atguigu.ssyx.sys.mapper.RegionMapper; +import com.atguigu.ssyx.sys.service.RegionService; +import com.baomidou.mybatisplus.core.toolkit.Wrappers; +import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; +import org.springframework.stereotype.Service; + +import java.util.List; + +/** + *

+ * 地区表 服务实现类 + *

+ * + * @author atguigu + * @since 2024-04-02 + */ +@Service +public class RegionServiceImpl extends ServiceImpl implements RegionService { + + /** + * 根据关键字获取地区列表 + * + * @param keyword 关键字 + * @return List + */ + @Override + public List findRegionByKeyword(String keyword) { + return baseMapper.selectList(Wrappers.lambdaQuery().like(Region::getName, keyword)); + } +} diff --git a/service/service-sys/src/main/java/com/atguigu/ssyx/sys/service/impl/RegionWareServiceImpl.java b/service/service-sys/src/main/java/com/atguigu/ssyx/sys/service/impl/RegionWareServiceImpl.java new file mode 100644 index 0000000..ea9035d --- /dev/null +++ b/service/service-sys/src/main/java/com/atguigu/ssyx/sys/service/impl/RegionWareServiceImpl.java @@ -0,0 +1,58 @@ +package com.atguigu.ssyx.sys.service.impl; + +import com.atguigu.ssyx.common.exception.BunnyException; +import com.atguigu.ssyx.common.result.ResultCodeEnum; +import com.atguigu.ssyx.model.sys.RegionWare; +import com.atguigu.ssyx.sys.mapper.RegionWareMapper; +import com.atguigu.ssyx.sys.service.RegionWareService; +import com.atguigu.ssyx.vo.sys.RegionWareQueryVo; +import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; +import com.baomidou.mybatisplus.core.metadata.IPage; +import com.baomidou.mybatisplus.core.toolkit.Wrappers; +import com.baomidou.mybatisplus.extension.plugins.pagination.Page; +import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; +import org.springframework.stereotype.Service; +import org.springframework.util.StringUtils; + +@Service +public class RegionWareServiceImpl extends ServiceImpl implements RegionWareService { + + /** + * 开通区域列表 + */ + @Override + public IPage selectPage(Page pageParam, RegionWareQueryVo regionWareQueryVo) { + String keyword = regionWareQueryVo.getKeyword(); + LambdaQueryWrapper wrapper = new LambdaQueryWrapper<>(); + + // 查询 + wrapper.like(!StringUtils.isEmpty(keyword), RegionWare::getRegionName, keyword).or().like(!StringUtils.isEmpty(keyword), RegionWare::getWareName, keyword); + + return baseMapper.selectPage(pageParam, wrapper); + } + + /** + * 添加开通区域 + */ + @Override + public void saveRegionWare(RegionWare regionWare) { + // 查询当前区域是否开通 + Integer count = baseMapper.selectCount(Wrappers.lambdaQuery().eq(RegionWare::getRegionId, regionWare.getRegionId())); + if (count > 0) { + throw new BunnyException(ResultCodeEnum.REGION_OPEN); + } + + baseMapper.insert(regionWare); + } + + /** + * 取消开通区域 + */ + @Override + public void updateStatus(Long id, Integer status) { + RegionWare regionWare = baseMapper.selectById(id); + regionWare.setStatus(status); + // 更新数据 + baseMapper.updateById(regionWare); + } +} diff --git a/service/service-sys/src/main/java/com/atguigu/ssyx/sys/service/impl/WareServiceImpl.java b/service/service-sys/src/main/java/com/atguigu/ssyx/sys/service/impl/WareServiceImpl.java new file mode 100644 index 0000000..471ddf3 --- /dev/null +++ b/service/service-sys/src/main/java/com/atguigu/ssyx/sys/service/impl/WareServiceImpl.java @@ -0,0 +1,20 @@ +package com.atguigu.ssyx.sys.service.impl; + +import com.atguigu.ssyx.model.sys.Ware; +import com.atguigu.ssyx.sys.mapper.WareMapper; +import com.atguigu.ssyx.sys.service.WareService; +import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; +import org.springframework.stereotype.Service; + +/** + *

+ * 仓库表 服务实现类 + *

+ * + * @author atguigu + * @since 2024-04-02 + */ +@Service +public class WareServiceImpl extends ServiceImpl implements WareService { + +} diff --git a/service/service-sys/src/main/resources/application-dev.yml b/service/service-sys/src/main/resources/application-dev.yml new file mode 100644 index 0000000..314bbeb --- /dev/null +++ b/service/service-sys/src/main/resources/application-dev.yml @@ -0,0 +1,15 @@ +server: + port: 8202 + +bunny: + datasource: + host: 106.15.251.123 + port: 3305 + sqlData: shequ-sys + username: root + password: "02120212" + + nacos: + server-addr: z-bunny.cn:8848 + discovery: + namespace: ssyx \ No newline at end of file diff --git a/service/service-sys/src/main/resources/application.yml b/service/service-sys/src/main/resources/application.yml new file mode 100644 index 0000000..6002948 --- /dev/null +++ b/service/service-sys/src/main/resources/application.yml @@ -0,0 +1,56 @@ +server: + port: 8202 + +spring: + application: + name: service-sys + profiles: + active: dev + + datasource: + type: com.zaxxer.hikari.HikariDataSource + driver-class-name: com.mysql.cj.jdbc.Driver + url: jdbc:mysql://${bunny.datasource.host}:${bunny.datasource.port}/${bunny.datasource.sqlData}?serverTimezone=GMT%2B8&useSSL=false&characterEncoding=utf-8&allowPublicKeyRetrieval=true + username: ${bunny.datasource.username} + password: ${bunny.datasource.password} + + cloud: + sentinel: + log: + dir: logs/${spring.application.name}/sentinel + nacos: + discovery: + namespace: ${bunny.nacos.discovery.namespace} + server-addr: ${bunny.nacos.server-addr} + + jackson: + date-format: yyyy-MM-dd HH:mm:ss + time-zone: GMT+8 + + +mybatis-plus: + type-aliases-package: com.atguigu.model # 配置每个包前缀 + mapper-locations: classpath:mapper/*.xml + configuration: + map-underscore-to-camel-case: true + auto-mapping-behavior: full + log-impl: org.apache.ibatis.logging.stdout.StdOutImpl # 查看日志 + global-config: + db-config: + # 设置表名前缀,不用在每个tableName添加前缀 + # table-prefix: t_ + # 全局配置主键值方式 + id-type: assign_id + logic-not-delete-value: 0 # 未删除默认为0 + logic-delete-value: 1 # 删除 + logic-delete-field: deleted # 全局配置逻辑删除 + +logging: + level: + com.atguigu.ssyx.sys.mapper: debug + com.atguigu.ssyx.sys.controller: info + com.atguigu.ssyx.sys.service: info + pattern: + dateformat: HH:mm:ss:SSS + file: + path: "logs/${spring.application.name}" \ No newline at end of file diff --git a/service/service-sys/src/main/resources/banner.txt b/service/service-sys/src/main/resources/banner.txt new file mode 100644 index 0000000..cc77fc2 --- /dev/null +++ b/service/service-sys/src/main/resources/banner.txt @@ -0,0 +1,16 @@ +-----------------▄██-█▄--------- +-----------------███▄██▄-------- +-----------------███████-------- +-----------------▀███████------- +-------------------██████▄▄----- +-------------------█████████▄--- +-------------------██████▄████-- +-------▄███████████████████████- +-----▄███████████████████████▀-- +---▄██████████████████████------ +---███████████████████████------ +---███████████████████████------ +-▄▄██████████████████████▀------ +-█████████████████▀█████-------- +-▀██████████████▀▀-▀█████▄------ +-------▀▀▀▀▀▀▀▀▀------▀▀▀▀------ \ No newline at end of file diff --git a/service/service-sys/src/main/resources/favicon.ico b/service/service-sys/src/main/resources/favicon.ico new file mode 100644 index 0000000..1ba397c Binary files /dev/null and b/service/service-sys/src/main/resources/favicon.ico differ diff --git a/service/service-sys/src/main/resources/mapper/RegionMapper.xml b/service/service-sys/src/main/resources/mapper/RegionMapper.xml new file mode 100644 index 0000000..639a34d --- /dev/null +++ b/service/service-sys/src/main/resources/mapper/RegionMapper.xml @@ -0,0 +1,5 @@ + + + + + diff --git a/service/service-sys/src/main/resources/mapper/RegionWareMapper.xml b/service/service-sys/src/main/resources/mapper/RegionWareMapper.xml new file mode 100644 index 0000000..ea74838 --- /dev/null +++ b/service/service-sys/src/main/resources/mapper/RegionWareMapper.xml @@ -0,0 +1,5 @@ + + + + + diff --git a/service/service-sys/src/main/resources/mapper/WareMapper.xml b/service/service-sys/src/main/resources/mapper/WareMapper.xml new file mode 100644 index 0000000..0a302a7 --- /dev/null +++ b/service/service-sys/src/main/resources/mapper/WareMapper.xml @@ -0,0 +1,5 @@ + + + + +