🎨 优化和规范化部分代码

This commit is contained in:
Binary Wang 2019-08-22 16:44:17 +08:00
parent 0754c7a01c
commit 0eed5e6b59
12 changed files with 48 additions and 32 deletions

View File

@ -138,7 +138,7 @@ public interface WxMpCardService {
* @return result * @return result
* @throws WxErrorException 异常 * @throws WxErrorException 异常
*/ */
WxMpCardCreateResult createCard(WxMpCardCreateMessage cardCreateMessage) throws WxErrorException; WxMpCardCreateResult createCard(WxMpCardCreateRequest cardCreateMessage) throws WxErrorException;
/** /**
* 创建卡券二维码. * 创建卡券二维码.
@ -183,7 +183,8 @@ public interface WxMpCardService {
* @return WxMpCardLandingPageCreateResult * @return WxMpCardLandingPageCreateResult
* @throws WxErrorException 异常 * @throws WxErrorException 异常
*/ */
WxMpCardLandingPageCreateResult createLandingPage(WxMpCardLandingPageCreateRequest createRequest) throws WxErrorException; WxMpCardLandingPageCreateResult createLandingPage(WxMpCardLandingPageCreateRequest createRequest)
throws WxErrorException;
/** /**
* 将用户的卡券设置为失效状态. * 将用户的卡券设置为失效状态.

View File

@ -178,7 +178,7 @@ public class WxMpCardServiceImpl implements WxMpCardService {
} }
@Override @Override
public WxMpCardCreateResult createCard(WxMpCardCreateMessage cardCreateMessage) throws WxErrorException { public WxMpCardCreateResult createCard(WxMpCardCreateRequest cardCreateMessage) throws WxErrorException {
String response = this.wxMpService.post(WxMpApiUrl.Card.CARD_CREATE, GSON.toJson(cardCreateMessage)); String response = this.wxMpService.post(WxMpApiUrl.Card.CARD_CREATE, GSON.toJson(cardCreateMessage));
return WxMpCardCreateResult.fromJson(response); return WxMpCardCreateResult.fromJson(response);
} }

View File

@ -0,0 +1,17 @@
package me.chanjar.weixin.mp.bean.card;
import lombok.Data;
import java.io.Serializable;
/**
* .
*
* @author leeis
* @date 2018/12/29
*/
@Data
public abstract class AbstractCardCreateRequest implements Serializable {
private static final long serialVersionUID = -260291223712818801L;
}

View File

@ -1,13 +0,0 @@
package me.chanjar.weixin.mp.bean.card;
import lombok.Data;
import java.io.Serializable;
/**
* @Author leeis
* @Date 2018/12/29
*/
@Data
public class CardCreateRequest implements Serializable {
}

View File

@ -2,17 +2,22 @@ package me.chanjar.weixin.mp.bean.card;
import com.google.gson.annotations.SerializedName; import com.google.gson.annotations.SerializedName;
import lombok.Data; import lombok.Data;
import lombok.EqualsAndHashCode;
import me.chanjar.weixin.mp.util.json.WxMpGsonBuilder; import me.chanjar.weixin.mp.util.json.WxMpGsonBuilder;
import java.io.Serializable; import java.io.Serializable;
/** /**
* . * .
*
* @author leeis * @author leeis
* @Date 2018/12/29 * @date 2018/12/29
*/ */
@Data @Data
public class CashCardCreateRequest extends CardCreateRequest implements Serializable { @EqualsAndHashCode(callSuper = false)
public class CashCardCreateRequest extends AbstractCardCreateRequest implements Serializable {
private static final long serialVersionUID = 8251635683908302125L;
@SerializedName("card_type") @SerializedName("card_type")
private String cardType = "CASH"; private String cardType = "CASH";

View File

@ -14,7 +14,7 @@ import java.io.Serializable;
*/ */
@Data @Data
@EqualsAndHashCode(callSuper = true) @EqualsAndHashCode(callSuper = true)
public class DiscountCardCreateRequest extends CardCreateRequest implements Serializable { public class DiscountCardCreateRequest extends AbstractCardCreateRequest implements Serializable {
private static final long serialVersionUID = 1190518086576489692L; private static final long serialVersionUID = 1190518086576489692L;
@SerializedName("card_type") @SerializedName("card_type")

View File

@ -14,7 +14,7 @@ import java.io.Serializable;
*/ */
@Data @Data
@EqualsAndHashCode(callSuper = true) @EqualsAndHashCode(callSuper = true)
public class GeneralCardCreateRequest extends CardCreateRequest implements Serializable { public class GeneralCardCreateRequest extends AbstractCardCreateRequest implements Serializable {
private static final long serialVersionUID = 1771355872211267723L; private static final long serialVersionUID = 1771355872211267723L;
@SerializedName("card_type") @SerializedName("card_type")

View File

@ -14,7 +14,7 @@ import java.io.Serializable;
*/ */
@Data @Data
@EqualsAndHashCode(callSuper = true) @EqualsAndHashCode(callSuper = true)
public class GiftCardCreateRequest extends CardCreateRequest implements Serializable { public class GiftCardCreateRequest extends AbstractCardCreateRequest implements Serializable {
private static final long serialVersionUID = 1283655452584811858L; private static final long serialVersionUID = 1283655452584811858L;
@SerializedName("card_type") @SerializedName("card_type")

View File

@ -14,7 +14,7 @@ import java.io.Serializable;
*/ */
@Data @Data
@EqualsAndHashCode(callSuper = true) @EqualsAndHashCode(callSuper = true)
public class GrouponCardCreateRequest extends CardCreateRequest implements Serializable { public class GrouponCardCreateRequest extends AbstractCardCreateRequest implements Serializable {
private static final long serialVersionUID = 7551441058859934512L; private static final long serialVersionUID = 7551441058859934512L;
@SerializedName("card_type") @SerializedName("card_type")

View File

@ -6,18 +6,24 @@ import me.chanjar.weixin.mp.util.json.WxMpGsonBuilder;
import java.io.Serializable; import java.io.Serializable;
/**
* .
*
* @author IOMan
*/
@Data @Data
public final class WxMpCardCreateMessage implements Serializable { public final class WxMpCardCreateRequest implements Serializable {
private static final long serialVersionUID = 5951280855309617585L;
@SerializedName("card") @SerializedName("card")
private CardCreateRequest cardCreateRequest; private AbstractCardCreateRequest cardCreateRequest;
@Override @Override
public String toString() { public String toString() {
return WxMpGsonBuilder.create().toJson(this); return WxMpGsonBuilder.create().toJson(this);
} }
public static WxMpCardCreateMessage fromJson(String json) { public static WxMpCardCreateRequest fromJson(String json) {
return WxMpGsonBuilder.create().fromJson(json, WxMpCardCreateMessage.class); return WxMpGsonBuilder.create().fromJson(json, WxMpCardCreateRequest.class);
} }
} }

View File

@ -6,7 +6,7 @@ import lombok.Data;
import me.chanjar.weixin.mp.util.json.WxMpGsonBuilder; import me.chanjar.weixin.mp.util.json.WxMpGsonBuilder;
/** /**
* 卡券查询Code核销Code接口返回结果 * 卡券查询Code核销Code接口返回结果.
* *
* @author YuJian * @author YuJian
* @version 15/11/11 * @version 15/11/11

View File

@ -137,7 +137,7 @@ public class WxMpCardServiceImplTest {
base.setLocationIdList("1234"); base.setLocationIdList("1234");
//团购券 //团购券
WxMpCardCreateMessage grouponMessage = new WxMpCardCreateMessage(); WxMpCardCreateRequest grouponMessage = new WxMpCardCreateRequest();
GrouponCardCreateRequest grouponCardCreateRequest = new GrouponCardCreateRequest(); GrouponCardCreateRequest grouponCardCreateRequest = new GrouponCardCreateRequest();
GrouponCard grouponCard = new GrouponCard(); GrouponCard grouponCard = new GrouponCard();
grouponCard.setBaseInfo(base); grouponCard.setBaseInfo(base);
@ -149,7 +149,7 @@ public class WxMpCardServiceImplTest {
System.out.println(this.wxService.getCardService().createCard(grouponMessage)); System.out.println(this.wxService.getCardService().createCard(grouponMessage));
//现金券 //现金券
WxMpCardCreateMessage cashMessage = new WxMpCardCreateMessage(); WxMpCardCreateRequest cashMessage = new WxMpCardCreateRequest();
CashCardCreateRequest cashCardCreateRequest = new CashCardCreateRequest(); CashCardCreateRequest cashCardCreateRequest = new CashCardCreateRequest();
CashCard cashCard = new CashCard(); CashCard cashCard = new CashCard();
cashCard.setBaseInfo(base); cashCard.setBaseInfo(base);
@ -162,7 +162,7 @@ public class WxMpCardServiceImplTest {
System.out.println(this.wxService.getCardService().createCard(cashMessage)); System.out.println(this.wxService.getCardService().createCard(cashMessage));
//折扣券 //折扣券
WxMpCardCreateMessage discountMessage = new WxMpCardCreateMessage(); WxMpCardCreateRequest discountMessage = new WxMpCardCreateRequest();
DiscountCardCreateRequest discountCardCreateRequest = new DiscountCardCreateRequest(); DiscountCardCreateRequest discountCardCreateRequest = new DiscountCardCreateRequest();
DiscountCard discountCard = new DiscountCard(); DiscountCard discountCard = new DiscountCard();
discountCard.setBaseInfo(base); discountCard.setBaseInfo(base);
@ -174,7 +174,7 @@ public class WxMpCardServiceImplTest {
System.out.println(this.wxService.getCardService().createCard(discountMessage)); System.out.println(this.wxService.getCardService().createCard(discountMessage));
//兑换券 //兑换券
WxMpCardCreateMessage giftMessage = new WxMpCardCreateMessage(); WxMpCardCreateRequest giftMessage = new WxMpCardCreateRequest();
GiftCardCreateRequest giftCardCreateRequest = new GiftCardCreateRequest(); GiftCardCreateRequest giftCardCreateRequest = new GiftCardCreateRequest();
GiftCard giftCard = new GiftCard(); GiftCard giftCard = new GiftCard();
giftCard.setBaseInfo(base); giftCard.setBaseInfo(base);
@ -185,7 +185,7 @@ public class WxMpCardServiceImplTest {
System.out.println(this.wxService.getCardService().createCard(giftMessage)); System.out.println(this.wxService.getCardService().createCard(giftMessage));
//普通兑换券 //普通兑换券
WxMpCardCreateMessage generalMessage = new WxMpCardCreateMessage(); WxMpCardCreateRequest generalMessage = new WxMpCardCreateRequest();
GeneralCardCreateRequest generalCardCreateRequest = new GeneralCardCreateRequest(); GeneralCardCreateRequest generalCardCreateRequest = new GeneralCardCreateRequest();
GeneralCard generalCard = new GeneralCard(); GeneralCard generalCard = new GeneralCard();
generalCard.setBaseInfo(base); generalCard.setBaseInfo(base);