微信小程序主页完成
This commit is contained in:
5
guigu-ssyx-parent/service/service-home/Dockerfile
Normal file
5
guigu-ssyx-parent/service/service-home/Dockerfile
Normal 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", "&"]
|
40
guigu-ssyx-parent/service/service-home/pom.xml
Normal file
40
guigu-ssyx-parent/service/service-home/pom.xml
Normal 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>
|
@@ -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);
|
||||
}
|
||||
}
|
@@ -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);
|
||||
}
|
||||
|
||||
}
|
@@ -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);
|
||||
}
|
@@ -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;
|
||||
}
|
||||
}
|
@@ -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 #最小空闲
|
@@ -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
|
Reference in New Issue
Block a user