Skip to content

Commit

Permalink
账户微服务
Browse files Browse the repository at this point in the history
  • Loading branch information
wangyb committed Nov 24, 2022
1 parent caa30da commit 3349047
Show file tree
Hide file tree
Showing 34 changed files with 1,456 additions and 0 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ rms-mall(real-micro-services-mall) 真微服务商城,由于本人从网上找
- 2022/10/18 增加网关模块
- 2022/10/20 增加网关模块
- 2022/10/22 增加sleuth、zipkin 分布式日志
- 2022/11/24 用户账户微服务

## todo

Expand Down
1 change: 1 addition & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
<module>rms-mall-nacos-client</module>
<module>rms-mall-admin</module>
<module>rms-mall-gateway</module>
<module>rms-mall-service</module>
</modules>

<dependencies>
Expand Down
47 changes: 47 additions & 0 deletions rms-mall-service/pom.xml
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>
83 changes: 83 additions & 0 deletions rms-mall-service/rms-mall-account-service/pom.xml
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>
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);
}
}
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);
}
}
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);
}
}
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);
}
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);
}
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;
}
}
Loading

0 comments on commit 3349047

Please sign in to comment.