-
Notifications
You must be signed in to change notification settings - Fork 426
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
1 parent
5165e42
commit 5971209
Showing
41 changed files
with
12,457 additions
and
99 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
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
24 changes: 24 additions & 0 deletions
24
src/main/java/com/wangzaiplus/test/controller/SearchController.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,24 @@ | ||
package com.wangzaiplus.test.controller; | ||
|
||
import com.google.common.collect.Lists; | ||
import com.wangzaiplus.test.pojo.User; | ||
import org.springframework.web.bind.annotation.GetMapping; | ||
import org.springframework.web.bind.annotation.RequestMapping; | ||
import org.springframework.web.bind.annotation.RestController; | ||
|
||
import java.util.List; | ||
|
||
@RestController | ||
@RequestMapping("/search") | ||
public class SearchController { | ||
|
||
@GetMapping("users") | ||
public List<User> users() { | ||
User user = new User(1, "beigua", "beigua888"); | ||
User user2 = new User(2, "beigua2", "beigua888"); | ||
User user3 = new User(3, "beigua3", "beigua888"); | ||
|
||
return Lists.newArrayList(user, user2, user3); | ||
} | ||
|
||
} |
14 changes: 14 additions & 0 deletions
14
src/main/java/com/wangzaiplus/test/controller/ViewController.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,14 @@ | ||
package com.wangzaiplus.test.controller; | ||
|
||
import org.springframework.stereotype.Controller; | ||
import org.springframework.web.bind.annotation.GetMapping; | ||
|
||
@Controller | ||
public class ViewController { | ||
|
||
@GetMapping("home") | ||
public String index() { | ||
return "index"; | ||
} | ||
|
||
} |
11 changes: 11 additions & 0 deletions
11
src/main/java/com/wangzaiplus/test/designpattern/factory/ALiPay.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,11 @@ | ||
package com.wangzaiplus.test.designpattern.factory; | ||
|
||
public class ALiPay implements IPay{ | ||
|
||
@Override | ||
public boolean pay() { | ||
// 支付相关逻辑... | ||
return true; | ||
} | ||
|
||
} |
7 changes: 7 additions & 0 deletions
7
src/main/java/com/wangzaiplus/test/designpattern/factory/IPay.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,7 @@ | ||
package com.wangzaiplus.test.designpattern.factory; | ||
|
||
public interface IPay { | ||
|
||
boolean pay(); | ||
|
||
} |
28 changes: 28 additions & 0 deletions
28
src/main/java/com/wangzaiplus/test/designpattern/factory/PayTypeEnum.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,28 @@ | ||
package com.wangzaiplus.test.designpattern.factory; | ||
|
||
/** | ||
* 支付方式 | ||
*/ | ||
public enum PayTypeEnum { | ||
|
||
ALI_PAY("1", "支付宝支付"), | ||
WE_CHAT_PAY("2", "微信支付"), | ||
UNION_PAY("3", "银联支付"), | ||
; | ||
|
||
private String code; | ||
private String msg; | ||
|
||
PayTypeEnum(String code, String msg) { | ||
this.code = code; | ||
this.msg = msg; | ||
} | ||
|
||
public String getCode() { | ||
return code; | ||
} | ||
|
||
public String getMsg() { | ||
return msg; | ||
} | ||
} |
11 changes: 11 additions & 0 deletions
11
src/main/java/com/wangzaiplus/test/designpattern/factory/UnionPay.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,11 @@ | ||
package com.wangzaiplus.test.designpattern.factory; | ||
|
||
public class UnionPay implements IPay{ | ||
|
||
@Override | ||
public boolean pay() { | ||
// 支付相关逻辑... | ||
return true; | ||
} | ||
|
||
} |
11 changes: 11 additions & 0 deletions
11
src/main/java/com/wangzaiplus/test/designpattern/factory/WeChatPay.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,11 @@ | ||
package com.wangzaiplus.test.designpattern.factory; | ||
|
||
public class WeChatPay implements IPay{ | ||
|
||
@Override | ||
public boolean pay() { | ||
// 支付相关逻辑... | ||
return true; | ||
} | ||
|
||
} |
12 changes: 12 additions & 0 deletions
12
src/main/java/com/wangzaiplus/test/designpattern/factory/factorymethod/AFactory.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,12 @@ | ||
package com.wangzaiplus.test.designpattern.factory.factorymethod; | ||
|
||
import com.wangzaiplus.test.designpattern.factory.IPay; | ||
|
||
public class AFactory implements FactoryMethod { | ||
|
||
@Override | ||
public IPay createPay(String payType) { | ||
return null; | ||
} | ||
|
||
} |
12 changes: 12 additions & 0 deletions
12
src/main/java/com/wangzaiplus/test/designpattern/factory/factorymethod/BFactory.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,12 @@ | ||
package com.wangzaiplus.test.designpattern.factory.factorymethod; | ||
|
||
import com.wangzaiplus.test.designpattern.factory.IPay; | ||
|
||
public class BFactory implements FactoryMethod { | ||
|
||
@Override | ||
public IPay createPay(String payType) { | ||
return null; | ||
} | ||
|
||
} |
9 changes: 9 additions & 0 deletions
9
src/main/java/com/wangzaiplus/test/designpattern/factory/factorymethod/FactoryMethod.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,9 @@ | ||
package com.wangzaiplus.test.designpattern.factory.factorymethod; | ||
|
||
import com.wangzaiplus.test.designpattern.factory.IPay; | ||
|
||
public interface FactoryMethod { | ||
|
||
IPay createPay(String payType); | ||
|
||
} |
13 changes: 13 additions & 0 deletions
13
src/main/java/com/wangzaiplus/test/designpattern/factory/factorymethod/PayService.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.wangzaiplus.test.designpattern.factory.factorymethod; | ||
|
||
import com.wangzaiplus.test.designpattern.factory.IPay; | ||
|
||
public class PayService { | ||
|
||
public void pay(String payType) { | ||
FactoryMethod aFactory = new AFactory(); | ||
IPay pay = aFactory.createPay(payType); | ||
|
||
} | ||
|
||
} |
23 changes: 23 additions & 0 deletions
23
src/main/java/com/wangzaiplus/test/designpattern/factory/simplefactory/PayFactory.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,23 @@ | ||
package com.wangzaiplus.test.designpattern.factory.simplefactory; | ||
|
||
import com.wangzaiplus.test.designpattern.factory.*; | ||
|
||
public class PayFactory { | ||
|
||
public static IPay createPay(String payType) { | ||
if (PayTypeEnum.ALI_PAY.getCode().equals(payType)) { | ||
return new ALiPay(); | ||
} | ||
|
||
if (PayTypeEnum.WE_CHAT_PAY.getCode().equals(payType)) { | ||
return new WeChatPay(); | ||
} | ||
|
||
if (PayTypeEnum.UNION_PAY.getCode().equals(payType)) { | ||
return new UnionPay(); | ||
} | ||
|
||
return null; | ||
} | ||
|
||
} |
31 changes: 31 additions & 0 deletions
31
src/main/java/com/wangzaiplus/test/designpattern/factory/simplefactory/PayService.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,31 @@ | ||
package com.wangzaiplus.test.designpattern.factory.simplefactory; | ||
|
||
import com.wangzaiplus.test.designpattern.factory.IPay; | ||
import com.wangzaiplus.test.exception.ServiceException; | ||
import org.apache.commons.lang3.StringUtils; | ||
|
||
public class PayService { | ||
|
||
public void pay(String payType) { | ||
if (StringUtils.isBlank(payType)) { | ||
throw new ServiceException("支付方式异常"); | ||
} | ||
|
||
boolean isPaySuccess = isPaySuccess(payType); | ||
if (isPaySuccess) { | ||
// 巴拉巴拉 | ||
} else { | ||
// 巴拉巴拉 | ||
} | ||
} | ||
|
||
private boolean isPaySuccess(String payType) { | ||
IPay iPay = PayFactory.createPay(payType); | ||
if (null == iPay) { | ||
throw new ServiceException("支付方式异常"); | ||
} | ||
|
||
return iPay.pay(); | ||
} | ||
|
||
} |
13 changes: 13 additions & 0 deletions
13
src/main/java/com/wangzaiplus/test/designpattern/strategy/AliPayStrategy.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.wangzaiplus.test.designpattern.strategy; | ||
|
||
import org.springframework.stereotype.Component; | ||
|
||
@Component | ||
public class AliPayStrategy implements PayStrategy { | ||
|
||
@Override | ||
public void pay(String userId) { | ||
System.out.println("AliPayStrategy userId: " + userId); | ||
} | ||
|
||
} |
12 changes: 12 additions & 0 deletions
12
src/main/java/com/wangzaiplus/test/designpattern/strategy/Main.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,12 @@ | ||
package com.wangzaiplus.test.designpattern.strategy; | ||
|
||
import com.wangzaiplus.test.designpattern.factory.PayTypeEnum; | ||
|
||
public class Main { | ||
|
||
public static void main(String[] args) { | ||
PayContext payContext = new PayContext(); | ||
payContext.pay("3", "aaa"); | ||
} | ||
|
||
} |
33 changes: 33 additions & 0 deletions
33
src/main/java/com/wangzaiplus/test/designpattern/strategy/PayContext.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,33 @@ | ||
package com.wangzaiplus.test.designpattern.strategy; | ||
|
||
import com.wangzaiplus.test.designpattern.factory.PayTypeEnum; | ||
import com.wangzaiplus.test.exception.ServiceException; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.stereotype.Component; | ||
|
||
import java.util.Map; | ||
import java.util.concurrent.ConcurrentHashMap; | ||
|
||
//@Component | ||
public class PayContext { | ||
|
||
// @Autowired | ||
// private Map<String, PayStrategy> map; | ||
|
||
private static Map<String, PayStrategy> map2 = new ConcurrentHashMap<>(); | ||
static { | ||
map2.put(PayTypeEnum.ALI_PAY.getCode(), new AliPayStrategy()); | ||
map2.put(PayTypeEnum.WE_CHAT_PAY.getCode(), new WxPayStrategy()); | ||
map2.put(PayTypeEnum.UNION_PAY.getCode(), new UnionPayStrategy()); | ||
} | ||
|
||
public void pay(String payType, String userId) { | ||
PayStrategy payStrategy = map2.get(payType); | ||
if (null == payStrategy) { | ||
throw new ServiceException("payType: " + payType + " not supported"); | ||
} | ||
|
||
payStrategy.pay(userId); | ||
} | ||
|
||
} |
7 changes: 7 additions & 0 deletions
7
src/main/java/com/wangzaiplus/test/designpattern/strategy/PayStrategy.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,7 @@ | ||
package com.wangzaiplus.test.designpattern.strategy; | ||
|
||
public interface PayStrategy { | ||
|
||
void pay(String userId); | ||
|
||
} |
10 changes: 10 additions & 0 deletions
10
src/main/java/com/wangzaiplus/test/designpattern/strategy/UnionPayStrategy.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,10 @@ | ||
package com.wangzaiplus.test.designpattern.strategy; | ||
|
||
public class UnionPayStrategy implements PayStrategy { | ||
|
||
@Override | ||
public void pay(String userId) { | ||
System.out.println("UnionPayStrategy userId: " + userId); | ||
} | ||
|
||
} |
10 changes: 10 additions & 0 deletions
10
src/main/java/com/wangzaiplus/test/designpattern/strategy/WxPayStrategy.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,10 @@ | ||
package com.wangzaiplus.test.designpattern.strategy; | ||
|
||
public class WxPayStrategy implements PayStrategy { | ||
|
||
@Override | ||
public void pay(String userId) { | ||
System.out.println("WxPayStrategy userId: " + userId); | ||
} | ||
|
||
} |
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 |
---|---|---|
|
@@ -17,7 +17,7 @@ | |
|
||
import java.io.IOException; | ||
|
||
@Component | ||
//@Component | ||
@Slf4j | ||
public class SimpleMailConsumer { | ||
|
||
|
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 |
---|---|---|
|
@@ -13,7 +13,7 @@ | |
|
||
import java.io.IOException; | ||
|
||
@Component | ||
//@Component | ||
public class LoginLogListener { | ||
|
||
@Autowired | ||
|
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 |
---|---|---|
|
@@ -13,7 +13,7 @@ | |
|
||
import java.io.IOException; | ||
|
||
@Component | ||
//@Component | ||
public class MailListener { | ||
|
||
@Autowired | ||
|
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 |
---|---|---|
|
@@ -13,7 +13,7 @@ | |
|
||
import java.util.List; | ||
|
||
@Component | ||
//@Component | ||
@Slf4j | ||
public class ResendMsg { | ||
|
||
|
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
Oops, something went wrong.