@@ -66,10 +66,14 @@ export default {
cartArr: [],
deliveryaddress: {},
availablePointArr: [],
- couponUsed: {}
+ couponUsed: {},
+
}
},
created() {
+ // 首先初始化finalPrice
+ // finalPrice=totalPrice;
+
this.user = this.$getSessionStorage('user');
this.deliveryaddress = this.$getLocalStorage(this.user.userId);
this.couponUsed = this.$getLocalStorage(this.businessId);
@@ -96,13 +100,25 @@ export default {
totalPrice += cartItem.food.foodPrice * cartItem.quantity;
}
totalPrice += this.business.deliveryPrice;
-
+ //积分券包界面新增
+ // if (this.couponUsed != null) {
+ // totalPrice -= this.couponUsed.minusNum;
+ // }
+ return totalPrice;
+ },
+ finalPrice() {
+ let totalPrice = 0;
+ for (let cartItem of this.cartArr) {
+ totalPrice += cartItem.food.foodPrice * cartItem.quantity;
+ }
+ totalPrice += this.business.deliveryPrice;
//积分券包界面新增
if (this.couponUsed != null) {
totalPrice -= this.couponUsed.minusNum;
}
return totalPrice;
}
+
},
methods: {
back() {
@@ -126,25 +142,30 @@ export default {
}
//创建订单
-
- let url = `OrdersController/createOrders/${this.user.userId}/${this.businessId}/${this.deliveryaddress.daId}/${this.totalPrice}`
+ let finalPrice = this.totalPrice;
+ if (this.couponUsed != null) {
+ finalPrice -= this.couponUsed.minusNum;
+ }
+ let url =
+ `OrdersController/createOrders/${this.user.userId}/${this.businessId}/${this.deliveryaddress.daId}/${this.finalPrice}`
this.$axios.post(url).then(response => {
let orderId = response.data.result;
if (orderId > 0) {
//积分系统新增代码
if (this.couponUsed != null) {
- this.$axios.delete(`CouponController/deleteCouponByCouponId/${this.couponUsed.couponId}`);
+ this.$axios.delete(
+ `CouponController/deleteCouponByCouponId/${this.couponUsed.couponId}`);
}
this.$router.push({
path: '/payment',
query: {
orderId: orderId,
userId: this.user.userId,
- reduction: this.couponUsed===null?0:this.couponUsed.minusNum
+ reduction: this.couponUsed === null ? 0 : this.couponUsed.minusNum
}
});
- this.$removeSessionStorage(this.businessId);
-
+ this.$setLocalStorage(this.businessId,null);
+ console.log("this.$removeSessionStorage(this.businessId)");
} else {
alert('创建订单失败!');
}
@@ -153,13 +174,13 @@ export default {
});
},
toCouponSelect() {
- this.$router.push(
- {
- path: '/CouponSelect',
- query: {
- businessId: this.businessId
- }
- });
+ this.$router.push({
+ path: '/CouponSelect',
+ query: {
+ businessId: this.businessId,
+ totalPrice: this.totalPrice
+ }
+ });
},
getCouponName() {
if (this.couponUsed == null) {
diff --git a/elmclient/src/views/Payment.vue b/elmclient/src/views/Payment.vue
index 75cb726..8357998 100644
--- a/elmclient/src/views/Payment.vue
+++ b/elmclient/src/views/Payment.vue
@@ -9,29 +9,29 @@
订单信息:
- {{orders.business.businessName}}
+ {{ orders.business.businessName }}
-
¥{{orders.orderTotal}}
+
¥{{ orders.orderTotal }}
- {{item.food.foodName}} x {{item.quantity}}
- ¥{{item.food.foodPrice*item.quantity}}
+ {{ item.food.foodName }} x {{ item.quantity }}
+ ¥{{ item.food.foodPrice * item.quantity }}
配送费
- ¥{{orders.business.deliveryPrice}}
+ ¥{{ orders.business.deliveryPrice }}
消费券减免
- -¥{{reduction}}
+ -¥{{ reduction }}
获得积分
- {{orders.orderTotal*10}}
+ {{ orders.orderTotal * 10 }}
@@ -45,17 +45,21 @@
- 确认支付
+ 确认支付
支付成功!
+
+ 钱包余额不足!
+
\ No newline at end of file
diff --git a/springcloud_elm/.idea/compiler.xml b/springcloud_elm/.idea/compiler.xml
index 3860b73..92abf12 100644
--- a/springcloud_elm/.idea/compiler.xml
+++ b/springcloud_elm/.idea/compiler.xml
@@ -25,7 +25,11 @@
+
+
+
+
\ No newline at end of file
diff --git a/springcloud_elm/.idea/encodings.xml b/springcloud_elm/.idea/encodings.xml
index 2b605fe..1fd7fa4 100644
--- a/springcloud_elm/.idea/encodings.xml
+++ b/springcloud_elm/.idea/encodings.xml
@@ -41,5 +41,7 @@
+
+
\ No newline at end of file
diff --git a/springcloud_elm/.idea/runConfigurations/wallet_server_11000.xml b/springcloud_elm/.idea/runConfigurations/wallet_server_11000.xml
new file mode 100644
index 0000000..f62c187
--- /dev/null
+++ b/springcloud_elm/.idea/runConfigurations/wallet_server_11000.xml
@@ -0,0 +1,16 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/springcloud_elm/cart_server_10401/src/main/java/com/neusoft/service/impl/AbstractCartService.java b/springcloud_elm/cart_server_10401/src/main/java/com/neusoft/service/impl/AbstractCartService.java
new file mode 100644
index 0000000..d387398
--- /dev/null
+++ b/springcloud_elm/cart_server_10401/src/main/java/com/neusoft/service/impl/AbstractCartService.java
@@ -0,0 +1,37 @@
+package com.neusoft.service.impl;
+
+import com.neusoft.po.Cart;
+import com.neusoft.service.CartService;
+
+import java.util.List;
+
+public abstract class AbstractCartService implements CartService {
+
+ protected abstract List
listCartInternal(Cart cart);
+
+ protected abstract int saveCartInternal(Cart cart);
+
+ protected abstract int updateCartInternal(Cart cart);
+
+ protected abstract int removeCartInternal(Cart cart);
+
+ @Override
+ public List listCart(Cart cart) {
+ return listCartInternal(cart);
+ }
+
+ @Override
+ public int saveCart(Cart cart) {
+ return saveCartInternal(cart);
+ }
+
+ @Override
+ public int updateCart(Cart cart) {
+ return updateCartInternal(cart);
+ }
+
+ @Override
+ public int removeCart(Cart cart) {
+ return removeCartInternal(cart);
+ }
+}
diff --git a/springcloud_elm/cart_server_10401/src/main/java/com/neusoft/service/impl/CartServiceImpl.java b/springcloud_elm/cart_server_10401/src/main/java/com/neusoft/service/impl/CartServiceImpl.java
index 7e9ec95..96fed5e 100644
--- a/springcloud_elm/cart_server_10401/src/main/java/com/neusoft/service/impl/CartServiceImpl.java
+++ b/springcloud_elm/cart_server_10401/src/main/java/com/neusoft/service/impl/CartServiceImpl.java
@@ -1,36 +1,38 @@
+//模板方法模式
+/*模板方法模式可以将一些共同的行为放在一个抽象类中,然后由具体的子类实现具体的行为。创建一个抽象的 AbstractCartService 类,其中包含通用的方法实现,然后 CartServiceImpl 类继承这个抽象类并实现具体的方法。*/
+
package com.neusoft.service.impl;
import com.neusoft.mapper.CartMapper;
import com.neusoft.po.Cart;
-import com.neusoft.service.CartService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.List;
@Service
-public class CartServiceImpl implements CartService {
+public class CartServiceImpl extends AbstractCartService {
@Autowired
private CartMapper cartMapper;
@Override
- public List listCart(Cart cart) {
+ protected List listCartInternal(Cart cart) {
return cartMapper.listCart(cart);
}
@Override
- public int saveCart(Cart cart) {
+ protected int saveCartInternal(Cart cart) {
return cartMapper.saveCart(cart);
}
@Override
- public int updateCart(Cart cart) {
+ protected int updateCartInternal(Cart cart) {
return cartMapper.updateCart(cart);
}
@Override
- public int removeCart(Cart cart) {
+ protected int removeCartInternal(Cart cart) {
return cartMapper.removeCart(cart);
}
}
diff --git a/springcloud_elm/gateway_server_14000/src/main/resources/application.yml b/springcloud_elm/gateway_server_14000/src/main/resources/application.yml
index 5627e5c..1254d10 100644
--- a/springcloud_elm/gateway_server_14000/src/main/resources/application.yml
+++ b/springcloud_elm/gateway_server_14000/src/main/resources/application.yml
@@ -73,6 +73,11 @@ spring:
predicates:
- Path=/CollectController/*/**
+ - id: walletServer
+ uri: lb://wallet-server
+ predicates:
+ - Path=/WalletController/*/**
+
eureka:
client:
service-url:
diff --git a/springcloud_elm/gateway_server_14000/target/classes/application.yml b/springcloud_elm/gateway_server_14000/target/classes/application.yml
index 5627e5c..1254d10 100644
--- a/springcloud_elm/gateway_server_14000/target/classes/application.yml
+++ b/springcloud_elm/gateway_server_14000/target/classes/application.yml
@@ -73,6 +73,11 @@ spring:
predicates:
- Path=/CollectController/*/**
+ - id: walletServer
+ uri: lb://wallet-server
+ predicates:
+ - Path=/WalletController/*/**
+
eureka:
client:
service-url:
diff --git a/springcloud_elm/orders_server_10600/src/main/java/com/neusoft/controller/CommonResultFactory.java b/springcloud_elm/orders_server_10600/src/main/java/com/neusoft/controller/CommonResultFactory.java
new file mode 100644
index 0000000..dfd0eb9
--- /dev/null
+++ b/springcloud_elm/orders_server_10600/src/main/java/com/neusoft/controller/CommonResultFactory.java
@@ -0,0 +1,12 @@
+package com.neusoft.controller;
+
+import com.neusoft.po.CommonResult;
+import org.springframework.stereotype.Component;
+
+@Component
+public class CommonResultFactory {
+
+ public CommonResult createSuccessResult(T data) {
+ return new CommonResult<>(200, "success", data);
+ }
+}
diff --git a/springcloud_elm/orders_server_10600/src/main/java/com/neusoft/controller/OrdersController.java b/springcloud_elm/orders_server_10600/src/main/java/com/neusoft/controller/OrdersController.java
index a77cf6f..f6a3ab3 100644
--- a/springcloud_elm/orders_server_10600/src/main/java/com/neusoft/controller/OrdersController.java
+++ b/springcloud_elm/orders_server_10600/src/main/java/com/neusoft/controller/OrdersController.java
@@ -6,6 +6,7 @@ import com.neusoft.service.OrdersService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.web.bind.annotation.*;
+import com.neusoft.controller.CommonResultFactory;
import java.util.List;
@@ -16,6 +17,12 @@ public class OrdersController {
@Autowired
private OrdersService ordersService;
+ private final CommonResultFactory commonResultFactory;
+
+ public OrdersController(CommonResultFactory commonResultFactory) {
+ this.commonResultFactory = commonResultFactory;
+ }
+
@PostMapping("/createOrders/{userId}/{businessId}/{daId}/{orderTotal}")
public CommonResult createOrders(
@PathVariable("userId") String userId,
@@ -29,26 +36,26 @@ public class OrdersController {
param.setDaId(daId);
param.setOrderTotal(orderTotal);
int orderId=ordersService.createOrders(param);
- return new CommonResult<>(200,"success",orderId);
+ return commonResultFactory.createSuccessResult(orderId);
}
@GetMapping("/getOrdersById/{orderId}")
public CommonResult getOrdersById(@PathVariable("orderId") Integer orderId) throws Exception {
Orders orders=ordersService.getOrdersById(orderId);
- return new CommonResult<>(200,"success",orders);
+ return commonResultFactory.createSuccessResult(orders);
}
@GetMapping("/listOrdersByUserId/{userId}")
public CommonResult> listOrdersByUserId(@PathVariable("userId") String userId) throws Exception {
List list=ordersService.listOrdersByUserId(userId);
- return new CommonResult<>(200,"success",list);
+ return commonResultFactory.createSuccessResult(list);
}
@PutMapping("/Orders/{orderId}")
public CommonResultpayOrdersById(@PathVariable("orderId") Integer orderId)throws Exception
{
int result=ordersService.payOrdersById(orderId, null, null, null);
- return new CommonResult<>(200,"success",result);
+ return commonResultFactory.createSuccessResult(result);
}
diff --git a/springcloud_elm/orders_server_10601/src/main/java/com/neusoft/controller/CommonResultFactory.java b/springcloud_elm/orders_server_10601/src/main/java/com/neusoft/controller/CommonResultFactory.java
new file mode 100644
index 0000000..dfd0eb9
--- /dev/null
+++ b/springcloud_elm/orders_server_10601/src/main/java/com/neusoft/controller/CommonResultFactory.java
@@ -0,0 +1,12 @@
+package com.neusoft.controller;
+
+import com.neusoft.po.CommonResult;
+import org.springframework.stereotype.Component;
+
+@Component
+public class CommonResultFactory {
+
+ public CommonResult createSuccessResult(T data) {
+ return new CommonResult<>(200, "success", data);
+ }
+}
diff --git a/springcloud_elm/orders_server_10601/src/main/java/com/neusoft/controller/OrdersController.java b/springcloud_elm/orders_server_10601/src/main/java/com/neusoft/controller/OrdersController.java
index bd7e68f..440f4f2 100644
--- a/springcloud_elm/orders_server_10601/src/main/java/com/neusoft/controller/OrdersController.java
+++ b/springcloud_elm/orders_server_10601/src/main/java/com/neusoft/controller/OrdersController.java
@@ -16,6 +16,12 @@ public class OrdersController {
@Autowired
private OrdersService ordersService;
+ private final CommonResultFactory commonResultFactory;
+
+ public OrdersController(CommonResultFactory commonResultFactory) {
+ this.commonResultFactory = commonResultFactory;
+ }
+
@PostMapping("/createOrders/{userId}/{businessId}/{daId}/{orderTotal}")
public CommonResult createOrders(
@PathVariable("userId") String userId,
@@ -29,21 +35,29 @@ public class OrdersController {
param.setDaId(daId);
param.setOrderTotal(orderTotal);
int orderId=ordersService.createOrders(param);
- return new CommonResult<>(200,"success",orderId);
+ return commonResultFactory.createSuccessResult(orderId);
}
@GetMapping("/getOrdersById/{orderId}")
public CommonResult getOrdersById(@PathVariable("orderId") Integer orderId) throws Exception {
Orders orders=ordersService.getOrdersById(orderId);
- return new CommonResult<>(200,"success",orders);
+ return commonResultFactory.createSuccessResult(orders);
}
@GetMapping("/listOrdersByUserId/{userId}")
public CommonResult> listOrdersByUserId(@PathVariable("userId") String userId) throws Exception {
List list=ordersService.listOrdersByUserId(userId);
- return new CommonResult<>(200,"success",list);
+ return commonResultFactory.createSuccessResult(list);
}
+ @PutMapping("/Orders/{orderId}")
+ public CommonResultpayOrdersById(@PathVariable("orderId") Integer orderId)throws Exception
+ {
+ int result=ordersService.payOrdersById(orderId, null, null, null);
+ return commonResultFactory.createSuccessResult(result);
+ }
+
+
// @PutMapping("/Orders")
// public int payOrdersById(OrderState orderState, @RequestHeader("Authorization") String token) throws Exception {
// return ordersService.payOrdersById(orderState.getOrderId(), orderState.getUserId(), orderState.getOrderTotal(), orderState.getReduction(),token);
diff --git a/springcloud_elm/pom.xml b/springcloud_elm/pom.xml
index 9e966c8..e30155b 100644
--- a/springcloud_elm/pom.xml
+++ b/springcloud_elm/pom.xml
@@ -27,6 +27,7 @@
point_server_10900
coupon_server_10950
collect_server_10800
+ wallet_server_11000
pom
diff --git a/springcloud_elm/wallet_server_11000/pom.xml b/springcloud_elm/wallet_server_11000/pom.xml
new file mode 100644
index 0000000..960bfbc
--- /dev/null
+++ b/springcloud_elm/wallet_server_11000/pom.xml
@@ -0,0 +1,65 @@
+
+ 4.0.0
+
+ com.neusoft
+ springcloud_elm
+ 1.0-SNAPSHOT
+
+ wallet_server_11000
+
+
+
+ 8
+ 8
+
+
+
+
+ org.springframework.cloud
+ spring-cloud-bus
+
+
+ org.springframework.cloud
+ spring-cloud-stream-binder-rabbit
+
+
+ org.springframework.boot
+ spring-boot-starter-actuator
+
+
+ org.springframework.cloud
+ spring-cloud-starter-config
+
+
+ org.springframework.cloud
+ spring-cloud-starter-netflix-eureka-client
+
+
+ org.springframework.boot
+ spring-boot-starter-web
+
+
+ org.mybatis.spring.boot
+ mybatis-spring-boot-starter
+ 2.0.1
+
+
+ mysql
+ mysql-connector-java
+ 8.0.20
+ runtime
+
+
+
+ org.springframework.boot
+ spring-boot-devtools
+ runtime
+ true
+
+
+ com.neusoft
+ business_server_10300
+ 1.0-SNAPSHOT
+
+
+
\ No newline at end of file
diff --git a/springcloud_elm/wallet_server_11000/src/main/java/com/neusoft/MyApplication.java b/springcloud_elm/wallet_server_11000/src/main/java/com/neusoft/MyApplication.java
new file mode 100644
index 0000000..fff9695
--- /dev/null
+++ b/springcloud_elm/wallet_server_11000/src/main/java/com/neusoft/MyApplication.java
@@ -0,0 +1,11 @@
+package com.neusoft;
+
+import org.springframework.boot.SpringApplication;
+import org.springframework.boot.autoconfigure.SpringBootApplication;
+
+@SpringBootApplication
+public class MyApplication {
+ public static void main(String[] args){
+ SpringApplication.run(MyApplication.class,args);
+ }
+}
diff --git a/springcloud_elm/wallet_server_11000/src/main/java/com/neusoft/controller/WalletController.java b/springcloud_elm/wallet_server_11000/src/main/java/com/neusoft/controller/WalletController.java
new file mode 100644
index 0000000..b2d89b4
--- /dev/null
+++ b/springcloud_elm/wallet_server_11000/src/main/java/com/neusoft/controller/WalletController.java
@@ -0,0 +1,41 @@
+package com.neusoft.controller;
+
+import com.neusoft.po.CommonResult;
+import com.neusoft.po.Wallet;
+import com.neusoft.service.WalletService;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.web.bind.annotation.*;
+
+import java.util.List;
+
+@RestController
+@RequestMapping("/WalletController")
+public class WalletController {
+ @Autowired
+ private WalletService walletService;
+
+ @GetMapping("/listWallets")
+ public CommonResult> listWallets(@RequestParam("userId") String userId, @RequestHeader("Authorization") String token) throws Exception {
+ return new CommonResult<>(200, "success", walletService.listWallets(userId, token));
+ }
+
+ @PostMapping("/deposit/{userId}/{amount}")
+ public CommonResult deposit(@PathVariable("userId") String userId, @PathVariable("amount") double amount) {
+ return new CommonResult<>(200, "success", walletService.deposit(userId, amount));
+ }
+
+ @PostMapping("/withdraw/{userId}/{amount}")
+ public CommonResult withdraw(@PathVariable("userId") String userId, @PathVariable("amount") double amount) {
+ return new CommonResult<>(200, "success", walletService.withdraw(userId, amount));
+ }
+
+ @PostMapping("/expense/{userId}/{amount}")
+ public CommonResult transfer(@PathVariable("userId") String userId,@PathVariable("amount") double amount) {
+ return new CommonResult<>(200, "success", walletService.expense(userId, amount));
+ }
+
+ @GetMapping("/getWalletBalance/{userId}")
+ public CommonResult getWalletBalance(@PathVariable("userId") String userId) {
+ return new CommonResult<>(200, "success", walletService.getWalletBalance(userId));
+ }
+}
diff --git a/springcloud_elm/wallet_server_11000/src/main/java/com/neusoft/mapper/PointMapper.java b/springcloud_elm/wallet_server_11000/src/main/java/com/neusoft/mapper/PointMapper.java
new file mode 100644
index 0000000..99ddcd7
--- /dev/null
+++ b/springcloud_elm/wallet_server_11000/src/main/java/com/neusoft/mapper/PointMapper.java
@@ -0,0 +1,29 @@
+package com.neusoft.mapper;
+
+
+import com.neusoft.po.Point;
+
+import org.apache.ibatis.annotations.Delete;
+import org.apache.ibatis.annotations.Mapper;
+import org.apache.ibatis.annotations.Options;
+import org.apache.ibatis.annotations.Select;
+import org.apache.ibatis.annotations.Update;
+
+import java.util.List;
+
+@Mapper
+public interface PointMapper {
+ @Select("select * from point where userId=#{userId}")
+ public List listPointsByUserId(String userId);
+
+ @Update("update point set pointNum=#{pointNum} where pointId=#{pointId}")
+ public void setPointByPointId(Point point);
+
+ @Delete("delete from point where pointId=#{pointId}")
+ public void deletePointByPointId(String pointId);
+
+ @Select("insert into point(userId,pointDate,pointNum,outDate) values(#{userId},#{pointDate},#{pointNum},#{outDate})")
+ @Options(useGeneratedKeys=true,keyProperty="pointId",keyColumn="pointId")
+ public void addPointByPointId(Point point);
+
+}
diff --git a/springcloud_elm/wallet_server_11000/src/main/java/com/neusoft/mapper/UserMapper.java b/springcloud_elm/wallet_server_11000/src/main/java/com/neusoft/mapper/UserMapper.java
new file mode 100644
index 0000000..ea585ed
--- /dev/null
+++ b/springcloud_elm/wallet_server_11000/src/main/java/com/neusoft/mapper/UserMapper.java
@@ -0,0 +1,18 @@
+package com.neusoft.mapper;
+
+import com.neusoft.po.User;
+import org.apache.ibatis.annotations.Insert;
+import org.apache.ibatis.annotations.Mapper;
+import org.apache.ibatis.annotations.Select;
+
+@Mapper
+public interface UserMapper {
+ @Select("select * from user where userId=#{userId} and password=#{password}")
+ public User getUserByIdByPass(User user);
+
+ @Select("select count(*) from user where userId=#{userId}")
+ public int getUserById(String userId);
+
+ @Insert("insert into user values(#{userId},#{password},#{userName},#{userSex},null,1)")
+ public int saveUser(User user);
+}
\ No newline at end of file
diff --git a/springcloud_elm/wallet_server_11000/src/main/java/com/neusoft/mapper/WalletMapper.java b/springcloud_elm/wallet_server_11000/src/main/java/com/neusoft/mapper/WalletMapper.java
new file mode 100644
index 0000000..25958f7
--- /dev/null
+++ b/springcloud_elm/wallet_server_11000/src/main/java/com/neusoft/mapper/WalletMapper.java
@@ -0,0 +1,20 @@
+package com.neusoft.mapper;
+
+
+import com.neusoft.po.Wallet;
+
+import org.apache.ibatis.annotations.Mapper;
+import org.apache.ibatis.annotations.Options;
+import org.apache.ibatis.annotations.Select;
+import java.util.List;
+
+@Mapper
+public interface WalletMapper {
+ @Select("select * from wallet where userId=#{userId}")
+ public List listWalletsByUserId(String userId);
+
+ @Select("insert into wallet(userId,balance,transactionNum,transactionTime,transactionType) values(#{userId},#{balance},#{transactionNum},#{transactionTime},#{transactionType})")
+ @Options(useGeneratedKeys=true,keyProperty="walletId",keyColumn="walletId")
+ public void addWalletByWallet(Wallet wallet);
+
+}
diff --git a/springcloud_elm/wallet_server_11000/src/main/java/com/neusoft/po/CommonResult.java b/springcloud_elm/wallet_server_11000/src/main/java/com/neusoft/po/CommonResult.java
new file mode 100644
index 0000000..84f1b51
--- /dev/null
+++ b/springcloud_elm/wallet_server_11000/src/main/java/com/neusoft/po/CommonResult.java
@@ -0,0 +1,41 @@
+package com.neusoft.po;
+
+import java.io.Serializable;
+
+public class CommonResult implements Serializable {
+ private Integer code;
+ private String message;
+ private T result;
+
+ public CommonResult() {}
+
+ public CommonResult(Integer code, String message, T result) {
+ this.code = code;
+ this.message = message;
+ this.result = result;
+ }
+
+ public Integer getCode() {
+ return code;
+ }
+
+ public void setCode(Integer code) {
+ this.code = code;
+ }
+
+ public String getMessage() {
+ return message;
+ }
+
+ public void setMessage(String message) {
+ this.message = message;
+ }
+
+ public T getResult() {
+ return result;
+ }
+
+ public void setResult(T result) {
+ this.result = result;
+ }
+}
diff --git a/springcloud_elm/wallet_server_11000/src/main/java/com/neusoft/po/Point.java b/springcloud_elm/wallet_server_11000/src/main/java/com/neusoft/po/Point.java
new file mode 100644
index 0000000..cc693b4
--- /dev/null
+++ b/springcloud_elm/wallet_server_11000/src/main/java/com/neusoft/po/Point.java
@@ -0,0 +1,63 @@
+package com.neusoft.po;
+
+public class Point {
+
+ private String pointId;
+ private String userId;
+ private String pointDate;
+ private Integer pointNum;
+ private String outDate;
+ public Point()
+ {
+
+ }
+
+ public Point(String pointId,String userId,String pointDate,Integer pointNum,String outDate)
+ {
+ this.pointId=pointId;
+ this.userId=userId;
+ this.pointDate=pointDate;
+ this.pointNum=pointNum;
+ this.outDate=outDate;
+ }
+
+ public String getPointId()
+ {
+ return this.pointId;
+ }
+ public String getUserId()
+ {
+ return this.userId;
+ }
+ public String getPointDate()
+ {
+ return this.pointDate;
+ }
+ public Integer getPointNum()
+ {
+ return this.pointNum;
+ }
+
+ public void setPointId(String pointId)
+ {
+ this.pointId=pointId;
+ }
+ public void setUserId(String userId)
+ {
+ this.userId=userId;
+ }
+ public void setPointDate(String pointDate)
+ {
+ this.pointDate=pointDate;
+ }
+ public void setPointNum(Integer pointNum)
+ {
+ this.pointNum=pointNum;
+ }
+ public String getOutDate() {
+ return outDate;
+ }
+ public void setOutDate(String outDate) {
+ this.outDate = outDate;
+ }
+}
diff --git a/springcloud_elm/wallet_server_11000/src/main/java/com/neusoft/po/TransactionType.java b/springcloud_elm/wallet_server_11000/src/main/java/com/neusoft/po/TransactionType.java
new file mode 100644
index 0000000..d322454
--- /dev/null
+++ b/springcloud_elm/wallet_server_11000/src/main/java/com/neusoft/po/TransactionType.java
@@ -0,0 +1,18 @@
+package com.neusoft.po;
+
+public enum TransactionType {
+ DEPOSIT("Deposit"),
+ WITHDRAWAL("Withdrawal"),
+ EXPENSE("Expense"),
+ CREATE("Create");
+ private final String type;
+
+ TransactionType(String type) {
+ this.type = type;
+ }
+
+ public String getType() {
+ return type;
+ }
+}
+
diff --git a/springcloud_elm/wallet_server_11000/src/main/java/com/neusoft/po/User.java b/springcloud_elm/wallet_server_11000/src/main/java/com/neusoft/po/User.java
new file mode 100644
index 0000000..711644a
--- /dev/null
+++ b/springcloud_elm/wallet_server_11000/src/main/java/com/neusoft/po/User.java
@@ -0,0 +1,59 @@
+package com.neusoft.po;
+
+public class User {
+
+ private String userId;
+ private String password;
+ private String userName;
+ private Integer userSex;
+ private String userImg;
+ private Integer delTag;
+
+ public String getUserId() {
+ return userId;
+ }
+
+ public void setUserId(String userId) {
+ this.userId = userId;
+ }
+
+ public String getPassword() {
+ return password;
+ }
+
+ public void setPassword(String password) {
+ this.password = password;
+ }
+
+ public String getUserName() {
+ return userName;
+ }
+
+ public void setUserName(String userName) {
+ this.userName = userName;
+ }
+
+ public Integer getUserSex() {
+ return userSex;
+ }
+
+ public void setUserSex(Integer userSex) {
+ this.userSex = userSex;
+ }
+
+ public String getUserImg() {
+ return userImg;
+ }
+
+ public void setUserImg(String userImg) {
+ this.userImg = userImg;
+ }
+
+ public Integer getDelTag() {
+ return delTag;
+ }
+
+ public void setDelTag(Integer delTag) {
+ this.delTag = delTag;
+ }
+}
\ No newline at end of file
diff --git a/springcloud_elm/wallet_server_11000/src/main/java/com/neusoft/po/Wallet.java b/springcloud_elm/wallet_server_11000/src/main/java/com/neusoft/po/Wallet.java
new file mode 100644
index 0000000..4ce52ec
--- /dev/null
+++ b/springcloud_elm/wallet_server_11000/src/main/java/com/neusoft/po/Wallet.java
@@ -0,0 +1,71 @@
+package com.neusoft.po;
+import java.util.Date;
+
+public class Wallet {
+ private Integer walletId;
+ private String userId;
+ private double balance;
+ private double transactionNum;
+ private String transactionTime;
+ private TransactionType transactionType;
+
+ public Wallet(Integer walletId,String userId,double balance,double transactionNum,String transactionTime,TransactionType transactionType)
+ {
+ this.walletId=walletId;
+ this.userId=userId;
+ this.balance=balance;
+ this.transactionNum=transactionNum;
+ this.transactionTime=transactionTime;
+ this.transactionType=transactionType;
+ }
+
+ public Integer getWalletId() {
+ return walletId;
+ }
+
+ public void setWalletId(Integer walletId) {
+ this.walletId = walletId;
+ }
+
+ public String getUserId() {
+ return userId;
+ }
+
+ public void setUserId(String userId) {
+ this.userId = userId;
+ }
+
+ public double getBalance() {
+ return balance;
+ }
+
+ public void setBalance(double balance) {
+ this.balance = balance;
+ }
+
+ public String getTransactionTime() {
+ return transactionTime;
+ }
+
+ public void setTransactionTime(String transactionTime) {
+ this.transactionTime = transactionTime;
+ }
+
+ public TransactionType getTransactionType() {
+ return transactionType;
+ }
+
+ public void setTransactionType(TransactionType transactionType) {
+ this.transactionType = transactionType;
+ }
+
+ public double getTransactionNum() {
+ return transactionNum;
+ }
+
+ public void setTransactionNum(double transactionNum) {
+ this.transactionNum = transactionNum;
+ }
+
+
+}
diff --git a/springcloud_elm/wallet_server_11000/src/main/java/com/neusoft/service/WalletService.java b/springcloud_elm/wallet_server_11000/src/main/java/com/neusoft/service/WalletService.java
new file mode 100644
index 0000000..38ef374
--- /dev/null
+++ b/springcloud_elm/wallet_server_11000/src/main/java/com/neusoft/service/WalletService.java
@@ -0,0 +1,19 @@
+package com.neusoft.service;
+
+import java.text.ParseException;
+import java.util.List;
+
+import com.neusoft.po.Wallet;
+
+public interface WalletService {
+ public List listWallets(String userId, String token) throws ParseException;
+
+ public int deposit(String userId, double amount);
+
+ public int withdraw(String userId, double amount);
+
+ public int expense(String userId, double amount);
+
+ public double getWalletBalance(String userId);
+
+}
diff --git a/springcloud_elm/wallet_server_11000/src/main/java/com/neusoft/service/impl/WalletServiceImpl.java b/springcloud_elm/wallet_server_11000/src/main/java/com/neusoft/service/impl/WalletServiceImpl.java
new file mode 100644
index 0000000..2e286e1
--- /dev/null
+++ b/springcloud_elm/wallet_server_11000/src/main/java/com/neusoft/service/impl/WalletServiceImpl.java
@@ -0,0 +1,152 @@
+package com.neusoft.service.impl;
+
+import com.neusoft.mapper.UserMapper;
+import com.neusoft.mapper.WalletMapper;
+import com.neusoft.po.TransactionType;
+import com.neusoft.po.User;
+import com.neusoft.po.Wallet;
+import com.neusoft.service.WalletService;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
+
+import java.text.ParseException;
+import java.text.SimpleDateFormat;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.Comparator;
+import java.util.Date;
+import java.util.List;
+
+@Service
+public class WalletServiceImpl implements WalletService {
+ @Autowired
+ private WalletMapper walletMapper;
+
+ @Autowired
+ private UserMapper userMapper0;
+
+ @Override
+ public List listWallets(String userId, String token) throws ParseException {
+ User user = new User();
+ user.setUserId(userId);
+ user.setPassword(token);
+ if (userMapper0.getUserByIdByPass(user) == null)
+ return null;
+
+ List list = new ArrayList<>();
+ list = walletMapper.listWalletsByUserId(userId);
+ return list;
+ }
+
+ @Override
+ public int deposit(String userId, double amount) {
+ try {
+ // 获取用户当前余额
+ double balance = getWalletBalance(userId);
+ balance = balance += amount;
+ SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
+ // 创建 Wallet 对象
+ Wallet wallet = new Wallet(null, userId, balance, amount, sdf.format(new Date()), TransactionType.DEPOSIT);
+
+ // 调用 Mapper 方法插入数据
+ walletMapper.addWalletByWallet(wallet);
+
+ // 插入成功,返回 1
+ return 1;
+ } catch (Exception e) {
+ // 插入失败,记录异常并返回 0
+ e.printStackTrace();
+ return 0;
+ }
+ }
+
+ @Override
+ public int withdraw(String userId, double amount) {
+ try {
+ // 获取用户当前余额
+ double balance = getWalletBalance(userId);
+
+ // 如果余额不足,直接返回 0
+ if (balance < amount) {
+ return 0;
+ }
+
+ // 更新余额
+ balance -= amount;
+
+ SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
+ // 创建 Wallet 对象并插入数据
+ Wallet wallet = new Wallet(null, userId, balance, amount, sdf.format(new Date()), TransactionType.WITHDRAWAL);
+ walletMapper.addWalletByWallet(wallet);
+
+ // 插入成功,返回 1
+ return 1;
+ } catch (Exception e) {
+ // 记录异常并返回 0
+ e.printStackTrace();
+ return 0;
+ }
+ }
+
+ @Override
+ public int expense(String userId, double amount) {
+ try {
+ // 获取用户当前余额
+ double balance = getWalletBalance(userId);
+
+ // 如果余额不足,直接返回 0
+ if (balance < amount) {
+ return 0;
+ }
+
+ // 更新余额
+ balance -= amount;
+
+ SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
+ // 创建 Wallet 对象并插入数据
+ Wallet wallet = new Wallet(null, userId, balance, amount, sdf.format(new Date()), TransactionType.EXPENSE);
+ walletMapper.addWalletByWallet(wallet);
+
+ // 插入成功,返回 1
+ return 1;
+ } catch (Exception e) {
+ // 记录异常并返回 0
+ e.printStackTrace();
+ return 0;
+ }
+ }
+
+
+ @Override
+ public double getWalletBalance(String userId) {
+ try {
+ // 查询用户所有钱包记录
+ List wallets = walletMapper.listWalletsByUserId(userId);
+
+ // 如果用户没有钱包记录,则余额为0
+ double balance = 0.0;
+
+ SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
+ if (wallets.isEmpty()) {
+ // 创建 Wallet 对象
+ Wallet wallet = new Wallet(null, userId, balance, 0.0, sdf.format(new Date()), TransactionType.CREATE);
+ // 调用 Mapper 方法插入数据
+ walletMapper.addWalletByWallet(wallet);
+ }
+
+ if (!wallets.isEmpty()) {
+ // 找到具有最大钱包ID的记录
+ Wallet maxWallet = Collections.max(wallets, Comparator.comparing(w -> w.getWalletId()));
+
+ // 获取最大钱包的余额
+ balance = maxWallet.getBalance();
+ }
+
+ return balance;
+ } catch (Exception e) {
+ // 发生异常时记录并返回0
+ e.printStackTrace();
+ return 0.0;
+ }
+ }
+}
diff --git a/springcloud_elm/wallet_server_11000/src/main/resources/bootstrap.yml b/springcloud_elm/wallet_server_11000/src/main/resources/bootstrap.yml
new file mode 100644
index 0000000..fb41859
--- /dev/null
+++ b/springcloud_elm/wallet_server_11000/src/main/resources/bootstrap.yml
@@ -0,0 +1,19 @@
+spring:
+ cloud:
+ config:
+ name: wallet_server_11000
+ profile: dev
+ label: master
+ discovery:
+ enabled: true
+ service-id: config-server
+
+eureka:
+ client:
+ service-url:
+ defaultZone: http://eurekaServer13000:13000/eureka/,http://eurekaServer13001:13001/eureka/
+ instance:
+ prefer-ip-address: true #使用ip地址向eureka server进行注册
+ instance-id: ${spring.cloud.client.ip-address}:${server.port} #设置eureka控制台中显示的注册信息
+ lease-renewal-interval-in-seconds: 5
+ lease-expiration-duration-in-seconds: 15
\ No newline at end of file
diff --git a/springcloud_elm/wallet_server_11000/target/classes/META-INF/MANIFEST.MF b/springcloud_elm/wallet_server_11000/target/classes/META-INF/MANIFEST.MF
new file mode 100644
index 0000000..b04ae66
--- /dev/null
+++ b/springcloud_elm/wallet_server_11000/target/classes/META-INF/MANIFEST.MF
@@ -0,0 +1,5 @@
+Manifest-Version: 1.0
+Built-By: ₩ᄁチ¦ᄌタ¥ヘモ
+Build-Jdk: 1.8.0_371
+Created-By: Maven Integration for Eclipse
+
diff --git a/springcloud_elm/wallet_server_11000/target/classes/META-INF/maven/com.neusoft/wallet_server_10800/pom.properties b/springcloud_elm/wallet_server_11000/target/classes/META-INF/maven/com.neusoft/wallet_server_10800/pom.properties
new file mode 100644
index 0000000..590c95e
--- /dev/null
+++ b/springcloud_elm/wallet_server_11000/target/classes/META-INF/maven/com.neusoft/wallet_server_10800/pom.properties
@@ -0,0 +1,7 @@
+#Generated by Maven Integration for Eclipse
+#Sun Apr 21 15:15:43 CST 2024
+version=1.0-SNAPSHOT
+groupId=com.neusoft
+m2e.projectName=wallet_server_10800
+m2e.projectLocation=D\:\\OneDrive - tju.edu.cn\\my homework\\\u9AD8\u7EA7\u5B9E\u8DF5\\elm_springcloud-main\\springcloud_elm\\wallet_server_10800
+artifactId=wallet_server_10800
diff --git a/springcloud_elm/wallet_server_11000/target/classes/META-INF/maven/com.neusoft/wallet_server_10800/pom.xml b/springcloud_elm/wallet_server_11000/target/classes/META-INF/maven/com.neusoft/wallet_server_10800/pom.xml
new file mode 100644
index 0000000..76b5ae3
--- /dev/null
+++ b/springcloud_elm/wallet_server_11000/target/classes/META-INF/maven/com.neusoft/wallet_server_10800/pom.xml
@@ -0,0 +1,65 @@
+
+ 4.0.0
+
+ com.neusoft
+ springcloud_elm
+ 1.0-SNAPSHOT
+
+ wallet_server_10800
+
+
+
+ 8
+ 8
+
+
+
+
+ org.springframework.cloud
+ spring-cloud-bus
+
+
+ org.springframework.cloud
+ spring-cloud-stream-binder-rabbit
+
+
+ org.springframework.boot
+ spring-boot-starter-actuator
+
+
+ org.springframework.cloud
+ spring-cloud-starter-config
+
+
+ org.springframework.cloud
+ spring-cloud-starter-netflix-eureka-client
+
+
+ org.springframework.boot
+ spring-boot-starter-web
+
+
+ org.mybatis.spring.boot
+ mybatis-spring-boot-starter
+ 2.0.1
+
+
+ mysql
+ mysql-connector-java
+ 8.0.20
+ runtime
+
+
+
+ org.springframework.boot
+ spring-boot-devtools
+ runtime
+ true
+
+
+ com.neusoft
+ business_server_10300
+ 1.0-SNAPSHOT
+
+
+
\ No newline at end of file
diff --git a/springcloud_elm/wallet_server_11000/target/classes/bootstrap.yml b/springcloud_elm/wallet_server_11000/target/classes/bootstrap.yml
new file mode 100644
index 0000000..fb41859
--- /dev/null
+++ b/springcloud_elm/wallet_server_11000/target/classes/bootstrap.yml
@@ -0,0 +1,19 @@
+spring:
+ cloud:
+ config:
+ name: wallet_server_11000
+ profile: dev
+ label: master
+ discovery:
+ enabled: true
+ service-id: config-server
+
+eureka:
+ client:
+ service-url:
+ defaultZone: http://eurekaServer13000:13000/eureka/,http://eurekaServer13001:13001/eureka/
+ instance:
+ prefer-ip-address: true #使用ip地址向eureka server进行注册
+ instance-id: ${spring.cloud.client.ip-address}:${server.port} #设置eureka控制台中显示的注册信息
+ lease-renewal-interval-in-seconds: 5
+ lease-expiration-duration-in-seconds: 15
\ No newline at end of file
diff --git a/wallet.sql b/wallet.sql
new file mode 100644
index 0000000..4164138
--- /dev/null
+++ b/wallet.sql
@@ -0,0 +1,9 @@
+CREATE TABLE Wallet (
+ walletId INT PRIMARY KEY AUTO_INCREMENT,
+ userId VARCHAR(20),
+ balance DOUBLE,
+ transactionNum DOUBLE,
+ transactionTime DATETIME,
+ transactionType VARCHAR(50),
+ FOREIGN KEY (userId) REFERENCES user(userId)
+) ENGINE=InnoDB DEFAULT CHARSET=utf8;
\ No newline at end of file