微信小程序主页完成

This commit is contained in:
2023-09-26 10:22:29 +08:00
parent e0fd0c9822
commit fb902f09da
234 changed files with 53655 additions and 21 deletions

View File

@@ -13,6 +13,8 @@
<packaging>pom</packaging>
<modules>
<module>service-product-client</module>
<module>service-user-client</module>
<module>service-search-client</module>
</modules>
<dependencies>
<dependency>

View File

@@ -21,7 +21,6 @@ import java.util.List;
public interface ProductFeignClient {
/**
* 根据分类id获取分类信息
* \
*
* @param categoryId
* @return
@@ -64,4 +63,20 @@ public interface ProductFeignClient {
*/
@PostMapping("/api/product/inner/findCategoryList")
List<Category> findCategoryList(@RequestBody List<Long> categoryIdList);
/**
* 获取所有分类
*
* @return
*/
@GetMapping("/api/product/inner/findAllCategoryList")
public List<Category> findAllCategoryList();
/**
* 获取新人优惠
*
* @return
*/
@GetMapping("/api/product/inner/findNewPersonSkuInfoList")
public List<SkuInfo> findNewPersonSkuInfoList();
}

View File

@@ -0,0 +1,20 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://maven.apache.org/POM/4.0.0"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>com.atguigu</groupId>
<artifactId>service-client</artifactId>
<version>1.0-SNAPSHOT</version>
</parent>
<artifactId>service-search-client</artifactId>
<properties>
<maven.compiler.source>8</maven.compiler.source>
<maven.compiler.target>8</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
</project>

View File

@@ -0,0 +1,21 @@
package com.atguigu.ssyx.client.search;
import com.atguigu.ssyx.model.search.SkuEs;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.web.bind.annotation.GetMapping;
import java.util.List;
/**
* ClassName: SkuFeignClient
* Package: com.atguigu.ssyx.client.search
*
* @author yovinchen
* @Create 2023/9/25 22:44
*/
@FeignClient("service-search")
public interface SkuFeignClient {
@GetMapping("/api/search/sku/inner/findHotSkuList")
public List<SkuEs> findHotSkuList();
}

View File

@@ -0,0 +1,20 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://maven.apache.org/POM/4.0.0"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>com.atguigu</groupId>
<artifactId>service-client</artifactId>
<version>1.0-SNAPSHOT</version>
</parent>
<artifactId>service-user-client</artifactId>
<properties>
<maven.compiler.source>8</maven.compiler.source>
<maven.compiler.target>8</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
</project>

View File

@@ -0,0 +1,26 @@
package com.atguigu.ssyx.client.user;
import com.atguigu.ssyx.vo.user.LeaderAddressVo;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
/**
* ClassName: UserFeignClient
* Package: com.atguigu.ssyx.client.user
*
* @author yovinchen
* @Create 2023/9/25 12:27
*/
@FeignClient(value = "service-user")
public interface UserFeignClient {
/**
* 提货点地址信息
*
* @param userId
* @return
*/
@GetMapping("/api/user/leader/inner/getUserAddressByUserId/{userId}")
LeaderAddressVo getUserAddressByUserId(@PathVariable(value = "userId") Long userId);
}

View File

@@ -18,9 +18,18 @@
<module>service-search</module>
<module>service-activity</module>
<module>service-user</module>
<module>service-home</module>
</modules>
<dependencies>
<dependency>
<groupId>p6spy</groupId>
<artifactId>p6spy</artifactId>
<version>3.9.1</version>
</dependency>
<!--依赖服务的工具类-->
<dependency>
<groupId>com.atguigu</groupId>

View File

@@ -8,11 +8,14 @@ mybatis-plus:
spring:
datasource:
type: com.zaxxer.hikari.HikariDataSource
driver-class-name: com.mysql.cj.jdbc.Driver
url: jdbc:mysql://82.157.68.223:3306/shequ-acl?characterEncoding=utf-8&useSSL=false
# driver-class-name: com.mysql.cj.jdbc.Driver
# url: jdbc:mysql://82.157.68.223:3306/shequ-acl?characterEncoding=utf-8&useSSL=false
driver-class-name: com.p6spy.engine.spy.P6SpyDriver
url: jdbc:p6spy:mysql://82.157.68.223:3306/shequ-acl?characterEncoding=utf-8&useSSL=false
username: shequ-acl
password: shequ-acl
jackson:
date-format: yyyy-MM-dd HH:mm:ss
time-zone: GMT+8

View File

@@ -0,0 +1,19 @@
module.log=com.p6spy.engine.logging.P6LogFactory,com.p6spy.engine.outage.P6OutageFactory
# \u81EA\u5B9A\u4E49\u65E5\u5FD7\u6253\u5370
#logMessageFormat=com.p6spy.engine.spy.appender.SingleLineFormat
logMessageFormat=com.p6spy.engine.spy.appender.CustomLineFormat
customLogMessageFormat=%(currentTime) | SQL\u8017\u65F6\uFF1A %(executionTime) ms | \u8FDE\u63A5\u4FE1\u606F\uFF1A %(category)-%(connectionId) | \u6267\u884C\u8BED\u53E5\uFF1A %(sql)
# \u4F7F\u7528\u63A7\u5236\u53F0\u8BB0\u5F55sql
appender=com.p6spy.engine.spy.appender.StdoutLogger
## \u914D\u7F6E\u8BB0\u5F55Log\u4F8B\u5916
excludecategories=info,debug,result,batc,resultset
# \u8BBE\u7F6E\u4F7F\u7528p6spy driver\u6765\u505A\u4EE3\u7406
deregisterdrivers=true
# \u65E5\u671F\u683C\u5F0F
dateformat=yyyy-MM-dd HH:mm:ss
# \u5B9E\u9645\u9A71\u52A8
driverlist=com.mysql.jdbc.Driver
# \u662F\u5426\u5F00\u542F\u6162SQL\u8BB0\u5F55
outagedetection=true
# \u6162SQL\u8BB0\u5F55\u6807\u51C6 \u79D2
outagedetectioninterval=2

View File

@@ -0,0 +1,5 @@
FROM openjdk:8-jdk-alpine
LABEL authors="yovinchen"
VOLUME /tmp
ADD ./target/service-home.jar service-home.jar
ENTRYPOINT ["java","-jar","/service-home.jar", "&"]

View File

@@ -0,0 +1,40 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://maven.apache.org/POM/4.0.0"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>com.atguigu</groupId>
<artifactId>service</artifactId>
<version>1.0-SNAPSHOT</version>
</parent>
<artifactId>service-home</artifactId>
<properties>
<maven.compiler.source>8</maven.compiler.source>
<maven.compiler.target>8</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<dependencies>
<dependency>
<groupId>com.atguigu</groupId>
<artifactId>service-user-client</artifactId>
<version>1.0-SNAPSHOT</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>com.atguigu</groupId>
<artifactId>service-product-client</artifactId>
<version>1.0-SNAPSHOT</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>com.atguigu</groupId>
<artifactId>service-search-client</artifactId>
<version>1.0-SNAPSHOT</version>
<scope>compile</scope>
</dependency>
</dependencies>
</project>

View File

@@ -0,0 +1,24 @@
package com.atguigu.ssyx;
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;
/**
* ClassName: ServiceHomeApplication
* Package: com.atguigu.ssyx
*
* @author yovinchen
* @Create 2023/9/25 12:06
*/
@SpringBootApplication(exclude = DataSourceAutoConfiguration.class)//取消数据源自动配置
@EnableDiscoveryClient
@EnableFeignClients
public class ServiceHomeApplication {
public static void main(String[] args) {
SpringApplication.run(ServiceHomeApplication.class, args);
}
}

View File

@@ -0,0 +1,42 @@
package com.atguigu.ssyx.home.controller;
import com.atguigu.ssyx.common.auth.AuthContextHolder;
import com.atguigu.ssyx.common.result.Result;
import com.atguigu.ssyx.home.service.HomeService;
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 javax.servlet.http.HttpServletRequest;
import java.util.Map;
/**
* ClassName: HomeApiController
* Package: com.atguigu.ssyx.home.controller
*
* @author yovinchen
* @Create 2023/9/25 12:10
*/
@Api(tags = "首页接口")
@RestController
@RequestMapping("api/home")
public class HomeApiController {
@Autowired
private HomeService homeService;
@ApiOperation(value = "获取首页数据")
@GetMapping("index")
public Result index(HttpServletRequest request) {
// 获取用户Id
Long userId = AuthContextHolder.getUserId();
Map<String, Object> map = homeService.homeData(userId);
return Result.ok(map);
}
}

View File

@@ -0,0 +1,20 @@
package com.atguigu.ssyx.home.service;
import java.util.Map;
/**
* ClassName: HomeService
* Package: com.atguigu.ssyx.home.service
*
* @author yovinchen
* @Create 2023/9/25 12:12
*/
public interface HomeService {
/**
* 获取首页数据
*
* @param userId
* @return
*/
Map<String, Object> homeData(Long userId);
}

View File

@@ -0,0 +1,72 @@
package com.atguigu.ssyx.home.service.impl;
import com.atguigu.ssyx.client.product.ProductFeignClient;
import com.atguigu.ssyx.client.search.SkuFeignClient;
import com.atguigu.ssyx.client.user.UserFeignClient;
import com.atguigu.ssyx.home.service.HomeService;
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.vo.user.LeaderAddressVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
* ClassName: HomeServiceImpl
* Package: com.atguigu.ssyx.home.service.impl
*
* @author yovinchen
* @Create 2023/9/25 12:12
*/
@Service
public class HomeServiceImpl implements HomeService {
@Autowired
private UserFeignClient userFeignClient;
@Autowired
private ProductFeignClient productFeignClient;
@Autowired
private SkuFeignClient skuFeignClient;
/**
* 获取首页数据
*
* @param userId
* @return
*/
@Override
public Map<String, Object> homeData(Long userId) {
Map<String, Object> result = new HashMap<>();
//1 根据userId获取当前登录用户提货地址信息
// 远程调用service-user模块接口获取需要数据
LeaderAddressVo leaderAddressVo = userFeignClient.getUserAddressByUserId(userId);
result.put("leaderAddressVo", leaderAddressVo);
//2 获取所有分类
// 远程调用service-product模块接口
List<Category> categoryList = productFeignClient.findAllCategoryList();
result.put("categoryList", categoryList);
//3 获取新人专享商品
// 远程调用service-product模块接口
List<SkuInfo> newPersonSkuInfoList = productFeignClient.findNewPersonSkuInfoList();
result.put("newPersonSkuInfoList", newPersonSkuInfoList);
//4 获取爆款商品
// 远程调用service-search模块接口
// hotscore 热门评分降序排序
List<SkuEs> hotSkuList = skuFeignClient.findHotSkuList();
result.put("hotSkuList", hotSkuList);
//5 封装获取数据到map集合返回
return result;
}
}

View File

@@ -0,0 +1,34 @@
server:
port: 8207
feign:
sentinel:
enabled: true
client:
config:
default: #配置全局的feign的调用超时时间 如果 有指定的服务配置 默认的配置不会生效
connectTimeout: 50000 # 指定的是 消费者 连接服务提供者的连接超时时间 是否能连接 单位是毫秒
readTimeout: 50000 # 指定的是调用服务提供者的 服务 的超时时间() 单位是毫秒
mybatis-plus:
configuration:
log-impl: org.apache.ibatis.logging.stdout.StdOutImpl
type-enums-package: com.atguigu.ssyx.enums
spring:
main:
allow-bean-definition-overriding: true #当遇到同样名字的时候,是否允许覆盖注册
jackson:
date-format: yyyy-MM-dd HH:mm:ss
time-zone: GMT+8
redis:
host: 82.157.68.223
port: 6379
database: 0
timeout: 1800000
password:
lettuce:
pool:
max-active: 20 #最大连接数
max-wait: -1 #最大阻塞等待时间(负数表示没限制)
max-idle: 5 #最大空闲
min-idle: 0 #最小空闲

View File

@@ -0,0 +1,11 @@
spring:
application:
name: service-home
profiles:
active: dev
cloud:
nacos:
discovery:
server-addr: 82.157.68.223:8848
username: nacos
password: nacos

View File

@@ -56,4 +56,16 @@ public class ProductInnnerController {
public List<SkuInfo> findSkuInfoByKeyword(@PathVariable("keyword") String keyword) {
return skuInfoService.findSkuInfoByKeyword(keyword);
}
@ApiOperation(value = "获取所有分类")
@GetMapping("inner/findAllCategoryList")
public List<Category> findAllCategoryList() {
return categoryService.list();
}
@ApiOperation(value = "获取新人专享商品")
@GetMapping("inner/findNewPersonSkuInfoList")
public List<SkuInfo> findNewPersonSkuInfoList() {
return skuInfoService.findNewPersonSkuInfoList();
}
}

View File

@@ -98,4 +98,11 @@ public interface SkuInfoService extends IService<SkuInfo> {
* @return
*/
List<SkuInfo> findSkuInfoByKeyword(String keyword);
/**
* 获取新人专享商品
*
* @return
*/
List<SkuInfo> findNewPersonSkuInfoList();
}

View File

@@ -286,6 +286,25 @@ public class SkuInfoServiceImpl extends ServiceImpl<SkuInfoMapper, SkuInfo> impl
return baseMapper.selectList(new LambdaQueryWrapper<SkuInfo>().like(SkuInfo::getSkuName, keyword));
}
/**
* 获取新人专享商品
*
* @return
*/
@Override
public List<SkuInfo> findNewPersonSkuInfoList() {
//条件1 is_new_person=1
//条件2 publish_status=1
//条件3 :显示其中三个
//获取第一页数据,每页显示三条记录
Page<SkuInfo> pageParam = new Page<>(1, 3);
//调用方法查询
IPage<SkuInfo> skuInfoPage = baseMapper.selectPage(pageParam, new LambdaQueryWrapper<SkuInfo>().eq(SkuInfo::getIsNewPerson, 1)
.eq(SkuInfo::getPublishStatus, 1)
.orderByDesc(SkuInfo::getStock));
return skuInfoPage.getRecords();
}
private SkuInfoVo getSkuInfoDB(Long skuId) {
SkuInfoVo skuInfoVo = new SkuInfoVo();

View File

@@ -28,11 +28,6 @@
<version>1.0-SNAPSHOT</version>
<scope>compile</scope>
</dependency>
<!-- <dependency>-->
<!-- <groupId>com.atguigu</groupId>-->
<!-- <artifactId>service-product-api</artifactId>-->
<!-- <version>1.0-SNAPSHOT</version>-->
<!-- </dependency>-->
</dependencies>
<properties>
<maven.compiler.source>8</maven.compiler.source>

View File

@@ -1,6 +1,7 @@
package com.atguigu.ssyx.search.controller;
import com.atguigu.ssyx.common.result.Result;
import com.atguigu.ssyx.model.search.SkuEs;
import com.atguigu.ssyx.search.service.SkuService;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
@@ -9,6 +10,8 @@ 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;
/**
* ClassName: SkuApiController
* Package: com.atguigu.ssyx.search.controller
@@ -36,4 +39,10 @@ public class SkuApiController {
skuService.lowerSku(skuId);
return Result.ok(null);
}
@ApiOperation(value = "获取爆品商品")
@GetMapping("inner/findHotSkuList")
public List<SkuEs> findHotSkuList() {
return skuService.findHotSkuList();
}
}

View File

@@ -1,8 +1,14 @@
package com.atguigu.ssyx.search.repository;
import com.atguigu.ssyx.model.search.SkuEs;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.elasticsearch.repository.ElasticsearchRepository;
import java.net.ContentHandler;
import java.util.List;
/**
* ClassName: SkuRepository
* Package: com.atguigu.ssyx.search.repository
@@ -11,4 +17,7 @@ import org.springframework.data.elasticsearch.repository.ElasticsearchRepository
* @Create 2023/9/16 17:24
*/
public interface SkuRepository extends ElasticsearchRepository<SkuEs, Long> {
//获取爆款商品
Page<SkuEs> findByOrderByHotScoreDesc(Pageable pageable);
}

View File

@@ -1,7 +1,10 @@
package com.atguigu.ssyx.search.service;
import com.atguigu.ssyx.model.search.SkuEs;
import org.springframework.stereotype.Service;
import java.util.List;
/**
* ClassName: SkuService
* Package: com.atguigu.ssyx.search.service
@@ -26,4 +29,11 @@ public interface SkuService {
*/
void lowerSku(Long skuId);
/**
* 获取爆品商品
*
* @return
*/
List<SkuEs> findHotSkuList();
}

View File

@@ -10,8 +10,12 @@ import com.atguigu.ssyx.search.repository.SkuRepository;
import com.atguigu.ssyx.search.service.SkuService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Service;
import java.util.List;
import java.util.Objects;
/**
@@ -29,7 +33,7 @@ public class SkuServiceImpl implements SkuService {
private ProductFeignClient productFeignClient;
@Autowired
private SkuRepository skuEsRepository;
private SkuRepository skuRepository;
/**
* 上架商品列表
@@ -60,9 +64,8 @@ public class SkuServiceImpl implements SkuService {
if (Objects.equals(skuInfo.getSkuType(), SkuType.COMMON.getCode())) {
skuEs.setSkuType(0);
skuEs.setPrice(skuInfo
.getPrice()
.doubleValue());
skuEs.setPrice(skuInfo.getPrice()
.doubleValue());
skuEs.setStock(skuInfo.getStock());
skuEs.setSale(skuInfo.getSale());
skuEs.setPerLimit(skuInfo.getPerLimit());
@@ -70,18 +73,26 @@ public class SkuServiceImpl implements SkuService {
//TODO 待完善-秒杀商品
}
SkuEs save = skuEsRepository.save(skuEs);
SkuEs save = skuRepository.save(skuEs);
log.info("upperSku" + JSON.toJSONString(save));
}
/**
* a下架商品列表
* 下架商品列表
*
* @param skuId
*/
@Override
public void lowerSku(Long skuId) {
skuEsRepository.deleteById(skuId);
skuRepository.deleteById(skuId);
}
@Override
public List<SkuEs> findHotSkuList() {
Pageable pageable = PageRequest.of(0, 10);
Page<SkuEs> page = skuRepository.findByOrderByHotScoreDesc(pageable);
List<SkuEs> skuEsList = page.getContent();
return skuEsList;
}
}

View File

@@ -0,0 +1,34 @@
package com.atguigu.ssyx.user.api;
import com.atguigu.ssyx.user.service.UserService;
import com.atguigu.ssyx.vo.user.LeaderAddressVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
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 javax.annotation.Resource;
/**
* ClassName: LeaderAddressController
* Package: com.atguigu.ssyx.user.api
*
* @author yovinchen
* @Create 2023/9/25 12:23
*/
@Api(tags = "团长接口")
@RestController
@RequestMapping("api/user/leader")
public class LeaderAddressController {
@Resource
private UserService userService;
@ApiOperation("提货点地址信息")
@GetMapping("inner/getUserAddressByUserId/{userId}")
public LeaderAddressVo getUserAddressByUserId(@PathVariable(value = "userId") Long userId) {
return userService.getLeaderAddressByUserId(userId);
}
}