Skip to content

Commit 711ea15

Browse files
committed
use ribbion to do loadbance
1 parent da39746 commit 711ea15

15 files changed

+676
-0
lines changed

productProvider8002/pom.xml

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project xmlns="http://maven.apache.org/POM/4.0.0"
3+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
5+
<parent>
6+
<artifactId>parent</artifactId>
7+
<groupId>person.springcloud</groupId>
8+
<version>1.0-SNAPSHOT</version>
9+
</parent>
10+
<modelVersion>4.0.0</modelVersion>
11+
12+
<artifactId>produtProvider8002</artifactId>
13+
14+
15+
</project>
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
package self.springcloud;
2+
3+
import org.springframework.boot.SpringApplication;
4+
import org.springframework.boot.autoconfigure.SpringBootApplication;
5+
import org.springframework.cloud.netflix.eureka.EnableEurekaClient;
6+
7+
@SpringBootApplication
8+
@EnableEurekaClient
9+
public class ProductApplication {
10+
public static void main(String[] args){
11+
SpringApplication.run(ProductApplication.class,args);
12+
}
13+
}
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
package self.springcloud.controller;
2+
3+
import com.infras.RespCode;
4+
import com.infras.ResultJSONObject;
5+
import org.slf4j.Logger;
6+
import org.slf4j.LoggerFactory;
7+
import org.springframework.beans.factory.annotation.Autowired;
8+
import org.springframework.beans.factory.annotation.Value;
9+
import org.springframework.web.bind.annotation.GetMapping;
10+
import org.springframework.web.bind.annotation.RequestMapping;
11+
import org.springframework.web.bind.annotation.RestController;
12+
import self.springcloud.domain.ProductCategory;
13+
import self.springcloud.domain.ProductInfo;
14+
import self.springcloud.services.IProductCategoryServices;
15+
import self.springcloud.services.IProductServices;
16+
17+
import java.util.ArrayList;
18+
import java.util.HashMap;
19+
import java.util.List;
20+
import java.util.Map;
21+
import java.util.stream.Collectors;
22+
23+
@RestController
24+
@RequestMapping("/product")
25+
public class ProductController {
26+
27+
@Autowired
28+
private IProductServices productServices;
29+
30+
@Autowired
31+
private IProductCategoryServices productCategoryServices;
32+
33+
private Logger logger = LoggerFactory.getLogger(ProductController.class);
34+
35+
@Value("${server.port}")
36+
private String serverPort;
37+
38+
39+
@GetMapping("/list")
40+
public ResultJSONObject list() {
41+
logger.info("{} 收到请求",serverPort);
42+
43+
ResultJSONObject result = new ResultJSONObject(RespCode.SUCCESS);
44+
45+
List<ProductInfo> productInfoList = productServices.findUpAll();
46+
List<Integer> categoryTypeList = productInfoList.stream().map(item -> item.getCategoryType()).collect(Collectors.toList());
47+
List<ProductCategory> categoryList = productCategoryServices.findProductCategoryByIds(categoryTypeList);
48+
49+
for(ProductCategory category:categoryList){
50+
Map<String,Object> categoryAndProductMap = new HashMap<String,Object>();
51+
categoryAndProductMap.put("name",category.getCategoryName());
52+
categoryAndProductMap.put("type",category.getCategoryType());
53+
List foods = new ArrayList();
54+
for(ProductInfo productInfo:productInfoList){
55+
if(productInfo.getCategoryType().equals(category.getCategoryType())){
56+
foods.add(productInfo);
57+
}
58+
}
59+
categoryAndProductMap.put("foods",foods);
60+
result.getData().add(categoryAndProductMap);
61+
}
62+
return result;
63+
}
64+
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
package self.springcloud.dao;
2+
3+
import org.apache.ibatis.annotations.Mapper;
4+
import self.springcloud.domain.ProductCategory;
5+
6+
import java.util.List;
7+
8+
@Mapper
9+
public interface ProductCategoryMapper {
10+
int deleteByPrimaryKey(Integer categoryId);
11+
12+
int insert(ProductCategory record);
13+
14+
int insertSelective(ProductCategory record);
15+
16+
ProductCategory selectByPrimaryKey(Integer categoryId);
17+
18+
int updateByPrimaryKeySelective(ProductCategory record);
19+
20+
int updateByPrimaryKey(ProductCategory record);
21+
22+
List<ProductCategory> findCategoryTypeIn(List<Integer> categoryTypeList);
23+
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
package self.springcloud.dao;
2+
3+
import org.apache.ibatis.annotations.Mapper;
4+
import self.springcloud.domain.ProductInfo;
5+
6+
import java.util.List;
7+
8+
@Mapper
9+
public interface ProductInfoMapper {
10+
int deleteByPrimaryKey(String productId);
11+
12+
int insert(ProductInfo record);
13+
14+
int insertSelective(ProductInfo record);
15+
16+
ProductInfo selectByPrimaryKey(String productId);
17+
18+
int updateByPrimaryKeySelective(ProductInfo record);
19+
20+
int updateByPrimaryKey(ProductInfo record);
21+
22+
List<ProductInfo> findByProductStatus(Integer productStatus);
23+
}
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
package self.springcloud.domain;
2+
3+
import java.util.Date;
4+
5+
public class ProductCategory {
6+
private Integer categoryId;
7+
8+
private String categoryName;
9+
10+
private Integer categoryType;
11+
12+
private Date createTime;
13+
14+
private Date updateTime;
15+
16+
public Integer getCategoryId() {
17+
return categoryId;
18+
}
19+
20+
public void setCategoryId(Integer categoryId) {
21+
this.categoryId = categoryId;
22+
}
23+
24+
public String getCategoryName() {
25+
return categoryName;
26+
}
27+
28+
public void setCategoryName(String categoryName) {
29+
this.categoryName = categoryName == null ? null : categoryName.trim();
30+
}
31+
32+
public Integer getCategoryType() {
33+
return categoryType;
34+
}
35+
36+
public void setCategoryType(Integer categoryType) {
37+
this.categoryType = categoryType;
38+
}
39+
40+
public Date getCreateTime() {
41+
return createTime;
42+
}
43+
44+
public void setCreateTime(Date createTime) {
45+
this.createTime = createTime;
46+
}
47+
48+
public Date getUpdateTime() {
49+
return updateTime;
50+
}
51+
52+
public void setUpdateTime(Date updateTime) {
53+
this.updateTime = updateTime;
54+
}
55+
}
Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
1+
package self.springcloud.domain;
2+
3+
import java.math.BigDecimal;
4+
import java.util.Date;
5+
6+
public class ProductInfo {
7+
private String productId;
8+
9+
private String productName;
10+
11+
private BigDecimal productPrice;
12+
13+
private Integer productStock;
14+
15+
private String productDescription;
16+
17+
private String productIcon;
18+
19+
private Byte productStatus;
20+
21+
private Integer categoryType;
22+
23+
private Date createTime;
24+
25+
private Date updateTime;
26+
27+
public String getProductId() {
28+
return productId;
29+
}
30+
31+
public void setProductId(String productId) {
32+
this.productId = productId == null ? null : productId.trim();
33+
}
34+
35+
public String getProductName() {
36+
return productName;
37+
}
38+
39+
public void setProductName(String productName) {
40+
this.productName = productName == null ? null : productName.trim();
41+
}
42+
43+
public BigDecimal getProductPrice() {
44+
return productPrice;
45+
}
46+
47+
public void setProductPrice(BigDecimal productPrice) {
48+
this.productPrice = productPrice;
49+
}
50+
51+
public Integer getProductStock() {
52+
return productStock;
53+
}
54+
55+
public void setProductStock(Integer productStock) {
56+
this.productStock = productStock;
57+
}
58+
59+
public String getProductDescription() {
60+
return productDescription;
61+
}
62+
63+
public void setProductDescription(String productDescription) {
64+
this.productDescription = productDescription == null ? null : productDescription.trim();
65+
}
66+
67+
public String getProductIcon() {
68+
return productIcon;
69+
}
70+
71+
public void setProductIcon(String productIcon) {
72+
this.productIcon = productIcon == null ? null : productIcon.trim();
73+
}
74+
75+
public Byte getProductStatus() {
76+
return productStatus;
77+
}
78+
79+
public void setProductStatus(Byte productStatus) {
80+
this.productStatus = productStatus;
81+
}
82+
83+
public Integer getCategoryType() {
84+
return categoryType;
85+
}
86+
87+
public void setCategoryType(Integer categoryType) {
88+
this.categoryType = categoryType;
89+
}
90+
91+
public Date getCreateTime() {
92+
return createTime;
93+
}
94+
95+
public void setCreateTime(Date createTime) {
96+
this.createTime = createTime;
97+
}
98+
99+
public Date getUpdateTime() {
100+
return updateTime;
101+
}
102+
103+
public void setUpdateTime(Date updateTime) {
104+
this.updateTime = updateTime;
105+
}
106+
}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
package self.springcloud.domain;
2+
3+
public enum ProductStatusEnum{
4+
UP(0,"上架"),
5+
DOWN(1,"下架")
6+
;
7+
private Integer code;
8+
9+
private String name;
10+
11+
ProductStatusEnum(Integer code, String name) {
12+
this.code = code;
13+
this.name = name;
14+
}
15+
16+
public Integer getCode() {
17+
return code;
18+
}
19+
20+
public void setCode(Integer code) {
21+
this.code = code;
22+
}
23+
24+
public String getName() {
25+
return name;
26+
}
27+
28+
public void setName(String name) {
29+
this.name = name;
30+
}
31+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
package self.springcloud.services;
2+
3+
import self.springcloud.domain.ProductCategory;
4+
5+
import java.util.List;
6+
7+
public interface IProductCategoryServices {
8+
List<ProductCategory> findProductCategoryByIds(List<Integer> ids);
9+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
package self.springcloud.services;
2+
3+
import self.springcloud.domain.ProductInfo;
4+
5+
import java.util.List;
6+
7+
public interface IProductServices {
8+
List<ProductInfo> findUpAll();
9+
}

0 commit comments

Comments
 (0)