-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
wangyb
committed
Nov 24, 2022
1 parent
caa30da
commit 3349047
Showing
34 changed files
with
1,456 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<project xmlns="http://maven.apache.org/POM/4.0.0" | ||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
<parent> | ||
<artifactId>rms-mall</artifactId> | ||
<groupId>com.wyb.rms</groupId> | ||
<version>0.0.1-SNAPSHOT</version> | ||
</parent> | ||
<modelVersion>4.0.0</modelVersion> | ||
|
||
<artifactId>rms-mall-service</artifactId> | ||
<version>0.0.1-SNAPSHOT</version> | ||
<modules> | ||
<module>rms-mall-account-service</module> | ||
<module>rms-mall-service-config</module> | ||
<module>rms-mall-service-sdk</module> | ||
</modules> | ||
<packaging>pom</packaging> | ||
|
||
<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> | ||
<!-- swagger 用于定义 API 文档 --> | ||
<dependency> | ||
<groupId>io.springfox</groupId> | ||
<artifactId>springfox-swagger2</artifactId> | ||
<version>2.9.2</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>io.springfox</groupId> | ||
<artifactId>springfox-swagger-ui</artifactId> | ||
<version>2.9.2</version> | ||
</dependency> | ||
<!-- 美化 swagger --> | ||
<dependency> | ||
<groupId>com.github.xiaoymin</groupId> | ||
<artifactId>swagger-bootstrap-ui</artifactId> | ||
<version>1.9.3</version> | ||
</dependency> | ||
</dependencies> | ||
|
||
</project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<project xmlns="http://maven.apache.org/POM/4.0.0" | ||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
<parent> | ||
<artifactId>rms-mall-service</artifactId> | ||
<groupId>com.wyb.rms</groupId> | ||
<version>0.0.1-SNAPSHOT</version> | ||
</parent> | ||
<modelVersion>4.0.0</modelVersion> | ||
|
||
<artifactId>rms-mall-accout-service</artifactId> | ||
<version>0.0.1-SNAPSHOT</version> | ||
<packaging>jar</packaging> | ||
|
||
<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> | ||
<!-- spring cloud alibaba nacos discovery 依赖 --> | ||
<dependency> | ||
<groupId>com.alibaba.cloud</groupId> | ||
<artifactId>spring-cloud-starter-alibaba-nacos-discovery</artifactId> | ||
</dependency> | ||
<!-- zipkin = spring-cloud-starter-sleuth + spring-cloud-sleuth-zipkin--> | ||
<dependency> | ||
<groupId>org.springframework.cloud</groupId> | ||
<artifactId>spring-cloud-starter-zipkin</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.springframework.kafka</groupId> | ||
<artifactId>spring-kafka</artifactId> | ||
<version>2.5.0.RELEASE</version> | ||
</dependency> | ||
<!-- Java Persistence API, ORM 规范 --> | ||
<dependency> | ||
<groupId>org.springframework.boot</groupId> | ||
<artifactId>spring-boot-starter-data-jpa</artifactId> | ||
</dependency> | ||
<!-- MySQL 驱动, 注意, 这个需要与 MySQL 版本对应 --> | ||
<dependency> | ||
<groupId>mysql</groupId> | ||
<artifactId>mysql-connector-java</artifactId> | ||
<version>8.0.12</version> | ||
<scope>runtime</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>com.wyb.rms</groupId> | ||
<artifactId>rms-mall-service-config</artifactId> | ||
<version>0.0.1-SNAPSHOT</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>com.wyb.rms</groupId> | ||
<artifactId>rms-mall-service-sdk</artifactId> | ||
<version>0.0.1-SNAPSHOT</version> | ||
</dependency> | ||
</dependencies> | ||
|
||
<!-- | ||
SpringBoot的Maven插件, 能够以Maven的方式为应用提供SpringBoot的支持,可以将 | ||
SpringBoot应用打包为可执行的jar或war文件, 然后以通常的方式运行SpringBoot应用 | ||
--> | ||
<build> | ||
<finalName>${artifactId}</finalName> | ||
<plugins> | ||
<plugin> | ||
<groupId>org.springframework.boot</groupId> | ||
<artifactId>spring-boot-maven-plugin</artifactId> | ||
<executions> | ||
<execution> | ||
<goals> | ||
<goal>repackage</goal> | ||
</goals> | ||
</execution> | ||
</executions> | ||
</plugin> | ||
</plugins> | ||
</build> | ||
|
||
</project> |
25 changes: 25 additions & 0 deletions
25
...ms-mall-account-service/src/main/java/com/wyb/rms/service/account/AccountApplication.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package com.wyb.rms.service.account; | ||
|
||
import com.wyb.rms.service.config.conf.DataSourceProxyAutoConfiguration; | ||
import org.springframework.boot.SpringApplication; | ||
import org.springframework.boot.autoconfigure.SpringBootApplication; | ||
import org.springframework.cloud.client.discovery.EnableDiscoveryClient; | ||
import org.springframework.context.annotation.Import; | ||
import org.springframework.data.jpa.repository.config.EnableJpaAuditing; | ||
|
||
/** | ||
* <h1>用户账户微服务启动入口</h1> | ||
* 127.0.0.1:8003/rms-mall-account-service/swagger-ui.html | ||
* 127.0.0.1:8003/rms-mall-account-service/doc.html | ||
* */ | ||
@EnableJpaAuditing | ||
@SpringBootApplication | ||
@EnableDiscoveryClient | ||
@Import(DataSourceProxyAutoConfiguration.class) | ||
public class AccountApplication { | ||
|
||
public static void main(String[] args) { | ||
|
||
SpringApplication.run(AccountApplication.class, args); | ||
} | ||
} |
53 changes: 53 additions & 0 deletions
53
...count-service/src/main/java/com/wyb/rms/service/account/controller/AddressController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
package com.wyb.rms.service.account.controller; | ||
|
||
import com.wyb.rms.service.account.service.IAddressService; | ||
import com.wyb.rms.service.sdk.account.AddressInfo; | ||
import com.wyb.rms.service.sdk.common.TableId; | ||
import io.swagger.annotations.Api; | ||
import io.swagger.annotations.ApiOperation; | ||
import lombok.extern.slf4j.Slf4j; | ||
import org.springframework.web.bind.annotation.*; | ||
|
||
/** | ||
* <h1>用户地址服务 Controller</h1> | ||
* */ | ||
@Api(tags = "用户地址服务") | ||
@Slf4j | ||
@RestController | ||
@RequestMapping("/address") | ||
public class AddressController { | ||
|
||
private final IAddressService addressService; | ||
|
||
public AddressController(IAddressService addressService) { | ||
this.addressService = addressService; | ||
} | ||
|
||
// value 是简述, notes 是详细的描述信息 | ||
@ApiOperation(value = "创建", notes = "创建用户地址信息", httpMethod = "POST") | ||
@PostMapping("/create-address") | ||
public TableId createAddressInfo(@RequestBody AddressInfo addressInfo) { | ||
return addressService.createAddressInfo(addressInfo); | ||
} | ||
|
||
@ApiOperation(value = "当前用户", notes = "获取当前登录用户地址信息", httpMethod = "GET") | ||
@GetMapping("/current-address") | ||
public AddressInfo getCurrentAddressInfo() { | ||
return addressService.getCurrentAddressInfo(); | ||
} | ||
|
||
@ApiOperation(value = "获取用户地址信息", | ||
notes = "通过 id 获取用户地址信息, id 是 EcommerceAddress 表的主键", | ||
httpMethod = "GET") | ||
@GetMapping("/address-info") | ||
public AddressInfo getAddressInfoById(@RequestParam Long id) { | ||
return addressService.getAddressInfoById(id); | ||
} | ||
|
||
@ApiOperation(value = "获取用户地址信息", | ||
notes = "通过 TableId 获取用户地址信息", httpMethod = "POST") | ||
@PostMapping("/address-info-by-table-id") | ||
public AddressInfo getAddressInfoByTablesId(@RequestBody TableId tableId) { | ||
return addressService.getAddressInfoByTableId(tableId); | ||
} | ||
} |
36 changes: 36 additions & 0 deletions
36
...count-service/src/main/java/com/wyb/rms/service/account/controller/BalanceController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
package com.wyb.rms.service.account.controller; | ||
|
||
import com.wyb.rms.service.account.service.IBalanceService; | ||
import com.wyb.rms.service.sdk.account.BalanceInfo; | ||
import io.swagger.annotations.Api; | ||
import io.swagger.annotations.ApiOperation; | ||
import lombok.extern.slf4j.Slf4j; | ||
import org.springframework.web.bind.annotation.*; | ||
|
||
/** | ||
* <h1>用户余额服务 Controller</h1> | ||
* */ | ||
@Api(tags = "用户余额服务") | ||
@Slf4j | ||
@RestController | ||
@RequestMapping("/balance") | ||
public class BalanceController { | ||
|
||
private final IBalanceService balanceService; | ||
|
||
public BalanceController(IBalanceService balanceService) { | ||
this.balanceService = balanceService; | ||
} | ||
|
||
@ApiOperation(value = "当前用户", notes = "获取当前用户余额信息", httpMethod = "GET") | ||
@GetMapping("/current-balance") | ||
public BalanceInfo getCurrentUserBalanceInfo() { | ||
return balanceService.getCurrentUserBalanceInfo(); | ||
} | ||
|
||
@ApiOperation(value = "扣减", notes = "扣减用于余额", httpMethod = "PUT") | ||
@PutMapping("/deduct-balance") | ||
public BalanceInfo deductBalance(@RequestBody BalanceInfo balanceInfo) { | ||
return balanceService.deductBalance(balanceInfo); | ||
} | ||
} |
17 changes: 17 additions & 0 deletions
17
...ll-account-service/src/main/java/com/wyb/rms/service/account/dao/EcommerceAddressDao.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
package com.wyb.rms.service.account.dao; | ||
|
||
import com.wyb.rms.service.account.entity.EcommerceAddress; | ||
import org.springframework.data.jpa.repository.JpaRepository; | ||
|
||
import java.util.List; | ||
|
||
/** | ||
* <h1>EcommerceAddress Dao 接口定义</h1> | ||
* */ | ||
public interface EcommerceAddressDao extends JpaRepository<EcommerceAddress, Long> { | ||
|
||
/** | ||
* <h2>根据 用户 id 查询地址信息</h2> | ||
* */ | ||
List<EcommerceAddress> findAllByUserId(Long userId); | ||
} |
13 changes: 13 additions & 0 deletions
13
...ll-account-service/src/main/java/com/wyb/rms/service/account/dao/EcommerceBalanceDao.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package com.wyb.rms.service.account.dao; | ||
|
||
import com.wyb.rms.service.account.entity.EcommerceBalance; | ||
import org.springframework.data.jpa.repository.JpaRepository; | ||
|
||
/** | ||
* <h1>EcommerceBalance Dao 接口定义</h1> | ||
* */ | ||
public interface EcommerceBalanceDao extends JpaRepository<EcommerceBalance, Long> { | ||
|
||
/** 根据 userId 查询 EcommerceBalance 对象 */ | ||
EcommerceBalance findByUserId(Long userId); | ||
} |
100 changes: 100 additions & 0 deletions
100
...ll-account-service/src/main/java/com/wyb/rms/service/account/entity/EcommerceAddress.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
package com.wyb.rms.service.account.entity; | ||
|
||
import com.wyb.rms.service.sdk.account.AddressInfo; | ||
import lombok.AllArgsConstructor; | ||
import lombok.Data; | ||
import lombok.NoArgsConstructor; | ||
import org.springframework.data.annotation.CreatedDate; | ||
import org.springframework.data.annotation.LastModifiedDate; | ||
import org.springframework.data.jpa.domain.support.AuditingEntityListener; | ||
|
||
import javax.persistence.*; | ||
import java.util.Date; | ||
|
||
/** | ||
* <h1>用户地址表实体类定义</h1> | ||
* */ | ||
@Data | ||
@NoArgsConstructor | ||
@AllArgsConstructor | ||
@Entity | ||
@EntityListeners(AuditingEntityListener.class) | ||
@Table(name = "t_ecommerce_address") | ||
public class EcommerceAddress { | ||
|
||
/** 自增主键 */ | ||
@Id | ||
@GeneratedValue(strategy = GenerationType.IDENTITY) | ||
@Column(name = "id", nullable = false) | ||
private Long id; | ||
|
||
/** 用户 id */ | ||
@Column(name = "user_id", nullable = false) | ||
private Long userId; | ||
|
||
/** 用户名 */ | ||
@Column(name = "username", nullable = false) | ||
private String username; | ||
|
||
/** 电话 */ | ||
@Column(name = "phone", nullable = false) | ||
private String phone; | ||
|
||
/** 省 */ | ||
@Column(name = "province", nullable = false) | ||
private String province; | ||
|
||
/** 市 */ | ||
@Column(name = "city", nullable = false) | ||
private String city; | ||
|
||
/** 详细地址 */ | ||
@Column(name = "address_detail", nullable = false) | ||
private String addressDetail; | ||
|
||
/** 创建时间 */ | ||
@CreatedDate | ||
@Column(name = "create_time", nullable = false) | ||
private Date createTime; | ||
|
||
/** 更新时间 */ | ||
@LastModifiedDate | ||
@Column(name = "update_time", nullable = false) | ||
private Date updateTime; | ||
|
||
/** | ||
* <h2>根据 userId + AddressItem 得到 EcommerceAddress</h2> | ||
* */ | ||
public static EcommerceAddress to(Long userId, AddressInfo.AddressItem addressItem) { | ||
|
||
EcommerceAddress ecommerceAddress = new EcommerceAddress(); | ||
|
||
ecommerceAddress.setUserId(userId); | ||
ecommerceAddress.setUsername(addressItem.getUsername()); | ||
ecommerceAddress.setPhone(addressItem.getPhone()); | ||
ecommerceAddress.setProvince(addressItem.getProvince()); | ||
ecommerceAddress.setCity(addressItem.getCity()); | ||
ecommerceAddress.setAddressDetail(addressItem.getAddressDetail()); | ||
|
||
return ecommerceAddress; | ||
} | ||
|
||
/** | ||
* <h2>将 EcommerceAddress 对象转成 AddressInfo</h2> | ||
* */ | ||
public AddressInfo.AddressItem toAddressItem() { | ||
|
||
AddressInfo.AddressItem addressItem = new AddressInfo.AddressItem(); | ||
|
||
addressItem.setId(this.id); | ||
addressItem.setUsername(this.username); | ||
addressItem.setPhone(this.phone); | ||
addressItem.setProvince(this.province); | ||
addressItem.setCity(this.city); | ||
addressItem.setAddressDetail(this.addressDetail); | ||
addressItem.setCreateTime(this.createTime); | ||
addressItem.setUpdateTime(this.updateTime); | ||
|
||
return addressItem; | ||
} | ||
} |
Oops, something went wrong.