From f49c45f4e1b0ba21bbfd6784c10acb8cc06852d1 Mon Sep 17 00:00:00 2001 From: xxm Date: Thu, 22 Jul 2021 17:16:44 +0800 Subject: [PATCH 1/2] =?UTF-8?q?feat=20=E5=AF=B9=E6=8E=A5=E6=94=AF=E4=BB=98?= =?UTF-8?q?=E5=AE=9D=E6=94=AF=E4=BB=98=E3=80=81=E6=94=AF=E4=BB=98=E8=AE=B0?= =?UTF-8?q?=E5=BD=95=E3=80=81=E5=9B=9E=E8=B0=83=E8=AE=B0=E5=BD=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../code/PaymentCenterErrorCode.java | 8 +-- .../dto/merchant/MerchantAppDto.java | 7 +-- .../paymentcenter/dto/payment/PaymentDto.java | 2 +- .../dto/paymodel/alipay/AlipayConfigDto.java | 18 +++---- ...xception.java => PayFailureException.java} | 6 +-- .../param/payment/PaymentParam.java | 2 +- .../paymodel/alipay/AlipayConfigParam.java | 50 ++++++++++++++++++- .../paymodel/alipay/AlipayConfigQuery.java | 33 ++++++++++++ .../controller/AlipayConfigController.java | 14 +++++- .../controller/MerchantAppController.java | 8 +++ ...roller.java => PayCallbackController.java} | 2 +- .../controller/PayNotifyRecordController.java | 39 +++++++++++++++ .../controller/PaymentController.java | 8 +-- .../core/merchant/dao/MerchantAppManager.java | 1 + .../merchant/dao/MerchantInfoManager.java | 1 + .../merchant/service/MerchantAppService.java | 6 ++- .../merchant/service/MerchantInfoService.java | 1 + .../core/pay/func/AbsPayStrategy.java | 8 +-- .../core/pay/service/PayCancelService.java | 6 +-- .../core/pay/service/PaySyncService.java | 2 +- .../core/pay/strategy/AliPayStrategy.java | 4 +- .../core/pay/strategy/CashPayStrategy.java | 2 +- .../core/pay/strategy/PointPayStrategy.java | 2 +- .../core/pay/strategy/WeChatPayStrategy.java | 4 +- .../core/payconfig/dao/PayChannelManager.java | 1 + .../payconfig/dao/PayChannelWayManager.java | 1 + .../core/payment/dao/PaymentManager.java | 1 + .../core/payment/entity/Payment.java | 2 +- .../core/payment/service/PaymentService.java | 2 +- .../alipay/convert/AlipayConvert.java | 4 ++ .../alipay/dao/AlipayConfigManager.java | 32 +++++++++--- .../paymodel/alipay/entity/AlipayConfig.java | 19 +++++-- .../alipay/service/AlipayConfigService.java | 47 ++++++++--------- .../base/dao/PayNotifyRecordManager.java | 6 ++- .../wallet/service/WalletPayService.java | 4 +- 35 files changed, 270 insertions(+), 83 deletions(-) rename service-payment-center/service-payment-center-api/src/main/java/cn/bootx/paymentcenter/exception/payment/{PaymentPayFailureException.java => PayFailureException.java} (55%) create mode 100644 service-payment-center/service-payment-center-api/src/main/java/cn/bootx/paymentcenter/param/paymodel/alipay/AlipayConfigQuery.java rename service-payment-center/service-payment-center-impl/src/main/java/cn/bootx/paymentcenter/controller/{CallbackPayController.java => PayCallbackController.java} (97%) create mode 100644 service-payment-center/service-payment-center-impl/src/main/java/cn/bootx/paymentcenter/controller/PayNotifyRecordController.java diff --git a/service-payment-center/service-payment-center-api/src/main/java/cn/bootx/paymentcenter/code/PaymentCenterErrorCode.java b/service-payment-center/service-payment-center-api/src/main/java/cn/bootx/paymentcenter/code/PaymentCenterErrorCode.java index a25d75a..54a27ab 100644 --- a/service-payment-center/service-payment-center-api/src/main/java/cn/bootx/paymentcenter/code/PaymentCenterErrorCode.java +++ b/service-payment-center/service-payment-center-api/src/main/java/cn/bootx/paymentcenter/code/PaymentCenterErrorCode.java @@ -1,10 +1,10 @@ package cn.bootx.paymentcenter.code; /** -* 错误码 -* @author xxm -* @date 2020/12/7 -*/ + * 错误码 + * @author xxm + * @date 2020/12/7 + */ public interface PaymentCenterErrorCode { // 支付过程相关 diff --git a/service-payment-center/service-payment-center-api/src/main/java/cn/bootx/paymentcenter/dto/merchant/MerchantAppDto.java b/service-payment-center/service-payment-center-api/src/main/java/cn/bootx/paymentcenter/dto/merchant/MerchantAppDto.java index 4fc9fcf..a7932e0 100644 --- a/service-payment-center/service-payment-center-api/src/main/java/cn/bootx/paymentcenter/dto/merchant/MerchantAppDto.java +++ b/service-payment-center/service-payment-center-api/src/main/java/cn/bootx/paymentcenter/dto/merchant/MerchantAppDto.java @@ -1,7 +1,9 @@ package cn.bootx.paymentcenter.dto.merchant; +import cn.bootx.common.web.rest.dto.BaseDto; import io.swagger.annotations.ApiModel; import lombok.Data; +import lombok.EqualsAndHashCode; import lombok.experimental.Accessors; import java.io.Serializable; @@ -10,13 +12,12 @@ import java.io.Serializable; * @author xxm * @date 2021/6/29 */ +@EqualsAndHashCode(callSuper = true) @Data @Accessors(chain = true) @ApiModel("商户应用") -public class MerchantAppDto implements Serializable { +public class MerchantAppDto extends BaseDto implements Serializable { private static final long serialVersionUID = 343634045781430145L; - - private Long id; /** 应用id */ private String appId; /** 应用名称 */ diff --git a/service-payment-center/service-payment-center-api/src/main/java/cn/bootx/paymentcenter/dto/payment/PaymentDto.java b/service-payment-center/service-payment-center-api/src/main/java/cn/bootx/paymentcenter/dto/payment/PaymentDto.java index afa41b1..378974c 100644 --- a/service-payment-center/service-payment-center-api/src/main/java/cn/bootx/paymentcenter/dto/payment/PaymentDto.java +++ b/service-payment-center/service-payment-center-api/src/main/java/cn/bootx/paymentcenter/dto/payment/PaymentDto.java @@ -21,7 +21,7 @@ import java.time.LocalDateTime; @EqualsAndHashCode(callSuper = true) @Data @Accessors(chain = true) -@ApiModel("支付交易单") +@ApiModel("支付记录") public class PaymentDto extends BaseDto implements Serializable { private static final long serialVersionUID = 3269223993950227228L; diff --git a/service-payment-center/service-payment-center-api/src/main/java/cn/bootx/paymentcenter/dto/paymodel/alipay/AlipayConfigDto.java b/service-payment-center/service-payment-center-api/src/main/java/cn/bootx/paymentcenter/dto/paymodel/alipay/AlipayConfigDto.java index 7367799..f4cfe14 100644 --- a/service-payment-center/service-payment-center-api/src/main/java/cn/bootx/paymentcenter/dto/paymodel/alipay/AlipayConfigDto.java +++ b/service-payment-center/service-payment-center-api/src/main/java/cn/bootx/paymentcenter/dto/paymodel/alipay/AlipayConfigDto.java @@ -23,11 +23,8 @@ public class AlipayConfigDto extends BaseDto implements Serializable { /** 名称 */ private String name; - /** 状态 */ - private Integer state; - - /** 备注 */ - private String remark; + /** 商户号 */ + private String merchantNo; /** 系统商户appId */ private String appId; @@ -42,7 +39,7 @@ public class AlipayConfigDto extends BaseDto implements Serializable { private String returnUrl; /** 请求网关地址 */ - private String url; + private String serverUrl; /** 支付宝公钥 */ public String alipayPublicKey; @@ -56,12 +53,15 @@ public class AlipayConfigDto extends BaseDto implements Serializable { /** 超时配置 */ private String expireTime; - /** 可用支付方式 */ - private String payTypes; - /** 可用支付方式 */ private List payTypeList; /** 是否沙箱环境 */ private boolean sandbox; + + /** 状态 */ + private Integer state; + + /** 备注 */ + private String remark; } diff --git a/service-payment-center/service-payment-center-api/src/main/java/cn/bootx/paymentcenter/exception/payment/PaymentPayFailureException.java b/service-payment-center/service-payment-center-api/src/main/java/cn/bootx/paymentcenter/exception/payment/PayFailureException.java similarity index 55% rename from service-payment-center/service-payment-center-api/src/main/java/cn/bootx/paymentcenter/exception/payment/PaymentPayFailureException.java rename to service-payment-center/service-payment-center-api/src/main/java/cn/bootx/paymentcenter/exception/payment/PayFailureException.java index 4e0a1f9..aa80cbe 100644 --- a/service-payment-center/service-payment-center-api/src/main/java/cn/bootx/paymentcenter/exception/payment/PaymentPayFailureException.java +++ b/service-payment-center/service-payment-center-api/src/main/java/cn/bootx/paymentcenter/exception/payment/PayFailureException.java @@ -8,9 +8,9 @@ import cn.bootx.paymentcenter.code.PaymentCenterErrorCode; * @author xxm * @date 2020/12/8 */ -public class PaymentPayFailureException extends BizException { +public class PayFailureException extends BizException { - public PaymentPayFailureException() { - super(PaymentCenterErrorCode.PAYMENT_PAY_FAILURE, "支付失败"); + public PayFailureException() { + super(PaymentCenterErrorCode.PAY_FAILURE, "支付失败"); } } \ No newline at end of file diff --git a/service-payment-center/service-payment-center-api/src/main/java/cn/bootx/paymentcenter/param/payment/PaymentParam.java b/service-payment-center/service-payment-center-api/src/main/java/cn/bootx/paymentcenter/param/payment/PaymentParam.java index e9145dc..d5e1e63 100644 --- a/service-payment-center/service-payment-center-api/src/main/java/cn/bootx/paymentcenter/param/payment/PaymentParam.java +++ b/service-payment-center/service-payment-center-api/src/main/java/cn/bootx/paymentcenter/param/payment/PaymentParam.java @@ -14,7 +14,7 @@ import java.io.Serializable; */ @Data @Accessors(chain = true) -@ApiModel("支付交易单") +@ApiModel("支付记录") public class PaymentParam implements Serializable { private static final long serialVersionUID = 1082022943904710448L; diff --git a/service-payment-center/service-payment-center-api/src/main/java/cn/bootx/paymentcenter/param/paymodel/alipay/AlipayConfigParam.java b/service-payment-center/service-payment-center-api/src/main/java/cn/bootx/paymentcenter/param/paymodel/alipay/AlipayConfigParam.java index 2b28e46..12f417d 100644 --- a/service-payment-center/service-payment-center-api/src/main/java/cn/bootx/paymentcenter/param/paymodel/alipay/AlipayConfigParam.java +++ b/service-payment-center/service-payment-center-api/src/main/java/cn/bootx/paymentcenter/param/paymodel/alipay/AlipayConfigParam.java @@ -5,6 +5,7 @@ import lombok.Data; import lombok.experimental.Accessors; import java.io.Serializable; +import java.util.List; /** * @author xxm @@ -12,6 +13,53 @@ import java.io.Serializable; */ @Data @Accessors(chain = true) -@ApiModel("") +@ApiModel("支付宝配置") public class AlipayConfigParam implements Serializable { + + private Long id; + + /** 名称 */ + private String name; + + /** 状态 */ + private Integer state; + + /** 备注 */ + private String remark; + + /** 商户号 */ + private String merchantNo; + + /** 系统商户appId */ + private String appId; + + /** 支付宝商户appId */ + private String aliAppId; + + /** 服务器异步通知页面路径 需http://或者https://格式的完整路径,不能加?id=123这类自定义参数,必须外网可以正常访问 */ + private String notifyUrl; + + /** 页面跳转同步通知页面路径 需http://或者https://格式的完整路径,不能加?id=123这类自定义参数,必须外网可以正常访问 商户可以自定义同步跳转地址 */ + private String returnUrl; + + /** 请求网关地址 */ + private String url; + + /** 支付宝公钥 */ + public String alipayPublicKey; + + /** 签名类型 */ + public String signType; + + /** 私钥 */ + private String privateKey; + + /** 超时配置 */ + private String expireTime; + + /** 可用支付方式 */ + private List payTypeList; + + /** 是否沙箱环境 */ + private boolean sandbox; } diff --git a/service-payment-center/service-payment-center-api/src/main/java/cn/bootx/paymentcenter/param/paymodel/alipay/AlipayConfigQuery.java b/service-payment-center/service-payment-center-api/src/main/java/cn/bootx/paymentcenter/param/paymodel/alipay/AlipayConfigQuery.java new file mode 100644 index 0000000..36cb33f --- /dev/null +++ b/service-payment-center/service-payment-center-api/src/main/java/cn/bootx/paymentcenter/param/paymodel/alipay/AlipayConfigQuery.java @@ -0,0 +1,33 @@ +package cn.bootx.paymentcenter.param.paymodel.alipay; + +import io.swagger.annotations.ApiModel; +import lombok.Data; +import lombok.experimental.Accessors; + +import java.io.Serializable; + +/** +* @author xxm +* @date 2021/7/22 +*/ +@Data +@Accessors(chain = true) +@ApiModel("支付宝配置搜索参数") +public class AlipayConfigQuery implements Serializable { + private static final long serialVersionUID = -173325268481050362L; + + /** 名称 */ + private String name; + + /** 状态 */ + private Integer state; + + /** 商户号 */ + private String merchantNo; + + /** 系统商户appId */ + private String appId; + + /** 支付宝商户appId */ + private String aliAppId; +} diff --git a/service-payment-center/service-payment-center-impl/src/main/java/cn/bootx/paymentcenter/controller/AlipayConfigController.java b/service-payment-center/service-payment-center-impl/src/main/java/cn/bootx/paymentcenter/controller/AlipayConfigController.java index cce6579..b907ee2 100644 --- a/service-payment-center/service-payment-center-impl/src/main/java/cn/bootx/paymentcenter/controller/AlipayConfigController.java +++ b/service-payment-center/service-payment-center-impl/src/main/java/cn/bootx/paymentcenter/controller/AlipayConfigController.java @@ -1,9 +1,13 @@ package cn.bootx.paymentcenter.controller; +import cn.bootx.common.web.rest.PageResult; import cn.bootx.common.web.rest.Res; import cn.bootx.common.web.rest.ResResult; +import cn.bootx.common.web.rest.param.PageParam; import cn.bootx.paymentcenter.core.paymodel.alipay.service.AlipayConfigService; import cn.bootx.paymentcenter.dto.paymodel.alipay.AlipayConfigDto; +import cn.bootx.paymentcenter.param.paymodel.alipay.AlipayConfigParam; +import cn.bootx.paymentcenter.param.paymodel.alipay.AlipayConfigQuery; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; import lombok.AllArgsConstructor; @@ -22,13 +26,13 @@ public class AlipayConfigController { @ApiOperation("添加") @PostMapping("/add") - public ResResult add(@RequestBody AlipayConfigDto param){ + public ResResult add(@RequestBody AlipayConfigParam param){ return Res.ok(alipayConfigService.add(param)); } @ApiOperation("更新") @PostMapping("/update") - public ResResult update(@RequestBody AlipayConfigDto param){ + public ResResult update(@RequestBody AlipayConfigParam param){ return Res.ok(alipayConfigService.update(param)); } @@ -45,6 +49,12 @@ public class AlipayConfigController { return Res.ok(alipayConfigService.findByAppId(appId)); } + @ApiOperation("分页") + @GetMapping("/page") + public ResResult> page(PageParam pageParam, AlipayConfigQuery param){ + return Res.ok(alipayConfigService.page(pageParam,param)); + } + @ApiOperation("根据Id查询") @GetMapping("/findById") public ResResult findById(Long id){ diff --git a/service-payment-center/service-payment-center-impl/src/main/java/cn/bootx/paymentcenter/controller/MerchantAppController.java b/service-payment-center/service-payment-center-impl/src/main/java/cn/bootx/paymentcenter/controller/MerchantAppController.java index 739598d..21279a4 100644 --- a/service-payment-center/service-payment-center-impl/src/main/java/cn/bootx/paymentcenter/controller/MerchantAppController.java +++ b/service-payment-center/service-payment-center-impl/src/main/java/cn/bootx/paymentcenter/controller/MerchantAppController.java @@ -1,7 +1,9 @@ package cn.bootx.paymentcenter.controller; +import cn.bootx.common.web.rest.PageResult; import cn.bootx.common.web.rest.Res; import cn.bootx.common.web.rest.ResResult; +import cn.bootx.common.web.rest.param.PageParam; import cn.bootx.paymentcenter.core.merchant.service.MerchantAppService; import cn.bootx.paymentcenter.dto.merchant.MerchantAppDto; import cn.bootx.paymentcenter.dto.payconfig.PayChannelDto; @@ -42,6 +44,12 @@ public class MerchantAppController { return Res.ok(merchantAppService.findByMerchantId(merchantId)); } + @ApiOperation("分页") + @GetMapping("/page") + public ResResult> page(PageParam pageParam, MerchantAppParam param){ + return Res.ok(merchantAppService.page(pageParam,param)); + } + @ApiOperation("查询应用下的支付通道配置列表") @GetMapping("/findAppChannels") public ResResult> findAppChannels(String appId){ diff --git a/service-payment-center/service-payment-center-impl/src/main/java/cn/bootx/paymentcenter/controller/CallbackPayController.java b/service-payment-center/service-payment-center-impl/src/main/java/cn/bootx/paymentcenter/controller/PayCallbackController.java similarity index 97% rename from service-payment-center/service-payment-center-impl/src/main/java/cn/bootx/paymentcenter/controller/CallbackPayController.java rename to service-payment-center/service-payment-center-impl/src/main/java/cn/bootx/paymentcenter/controller/PayCallbackController.java index 5211e7a..37bceb1 100644 --- a/service-payment-center/service-payment-center-impl/src/main/java/cn/bootx/paymentcenter/controller/CallbackPayController.java +++ b/service-payment-center/service-payment-center-impl/src/main/java/cn/bootx/paymentcenter/controller/PayCallbackController.java @@ -27,7 +27,7 @@ import java.util.Map; @RestController @RequestMapping("/callback") @AllArgsConstructor -public class CallbackPayController { +public class PayCallbackController { private final AliPayCallbackService aliPayCallbackService; private final WeChatPayCallbackService weChatPayCallbackService; diff --git a/service-payment-center/service-payment-center-impl/src/main/java/cn/bootx/paymentcenter/controller/PayNotifyRecordController.java b/service-payment-center/service-payment-center-impl/src/main/java/cn/bootx/paymentcenter/controller/PayNotifyRecordController.java new file mode 100644 index 0000000..88637b4 --- /dev/null +++ b/service-payment-center/service-payment-center-impl/src/main/java/cn/bootx/paymentcenter/controller/PayNotifyRecordController.java @@ -0,0 +1,39 @@ +package cn.bootx.paymentcenter.controller; + +import cn.bootx.common.web.rest.PageResult; +import cn.bootx.common.web.rest.Res; +import cn.bootx.common.web.rest.ResResult; +import cn.bootx.common.web.rest.param.PageParam; +import cn.bootx.paymentcenter.core.paymodel.base.service.PayNotifyRecordService; +import cn.bootx.paymentcenter.dto.pay.PayNotifyRecordDto; +import io.swagger.annotations.Api; +import io.swagger.annotations.ApiOperation; +import lombok.RequiredArgsConstructor; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +/** +* 回调记录 +* @author xxm +* @date 2021/7/22 +*/ +@Api(tags = "支付回调记录") +@RestController +@RequestMapping("/notify/record") +@RequiredArgsConstructor +public class PayNotifyRecordController { + private final PayNotifyRecordService notifyRecordService; + + @ApiOperation("分页") + @GetMapping("/page") + public ResResult> page(PageParam pageParam){ + return Res.ok(notifyRecordService.page(pageParam)); + } + + @ApiOperation("根据id查询") + @GetMapping("/findById") + public ResResult findById(Long id){ + return Res.ok(notifyRecordService.findById(id)); + } +} diff --git a/service-payment-center/service-payment-center-impl/src/main/java/cn/bootx/paymentcenter/controller/PaymentController.java b/service-payment-center/service-payment-center-impl/src/main/java/cn/bootx/paymentcenter/controller/PaymentController.java index e964f33..3cb26da 100644 --- a/service-payment-center/service-payment-center-impl/src/main/java/cn/bootx/paymentcenter/controller/PaymentController.java +++ b/service-payment-center/service-payment-center-impl/src/main/java/cn/bootx/paymentcenter/controller/PaymentController.java @@ -18,10 +18,10 @@ import org.springframework.web.bind.annotation.RestController; import java.util.List; /** - * @author xxm - * @date 2021/6/28 - */ -@Api(tags = "交易单") +* @author xxm +* @date 2021/6/28 +*/ +@Api(tags = "支付记录") @RestController @RequestMapping("/payment") @RequiredArgsConstructor diff --git a/service-payment-center/service-payment-center-impl/src/main/java/cn/bootx/paymentcenter/core/merchant/dao/MerchantAppManager.java b/service-payment-center/service-payment-center-impl/src/main/java/cn/bootx/paymentcenter/core/merchant/dao/MerchantAppManager.java index e163e9b..83161da 100644 --- a/service-payment-center/service-payment-center-impl/src/main/java/cn/bootx/paymentcenter/core/merchant/dao/MerchantAppManager.java +++ b/service-payment-center/service-payment-center-impl/src/main/java/cn/bootx/paymentcenter/core/merchant/dao/MerchantAppManager.java @@ -73,6 +73,7 @@ public class MerchantAppManager { if (StrUtil.isNotBlank(param.getAppName())){ query.where(q.appName.like("%"+param.getAppName()+"%")); } + query.where(q.tid.eq(headerHolder.findTid())); return JpaUtils.queryPage(query,pageParam); } diff --git a/service-payment-center/service-payment-center-impl/src/main/java/cn/bootx/paymentcenter/core/merchant/dao/MerchantInfoManager.java b/service-payment-center/service-payment-center-impl/src/main/java/cn/bootx/paymentcenter/core/merchant/dao/MerchantInfoManager.java index 03c5227..1d0d241 100644 --- a/service-payment-center/service-payment-center-impl/src/main/java/cn/bootx/paymentcenter/core/merchant/dao/MerchantInfoManager.java +++ b/service-payment-center/service-payment-center-impl/src/main/java/cn/bootx/paymentcenter/core/merchant/dao/MerchantInfoManager.java @@ -62,6 +62,7 @@ public class MerchantInfoManager { if (StrUtil.isNotBlank(param.getMerchantName())){ query.where(q.merchantName.like("%"+param.getMerchantName()+"%")); } + query.where(q.tid.eq(headerHolder.findTid())); return JpaUtils.queryPage(query,pageParam); } diff --git a/service-payment-center/service-payment-center-impl/src/main/java/cn/bootx/paymentcenter/core/merchant/service/MerchantAppService.java b/service-payment-center/service-payment-center-impl/src/main/java/cn/bootx/paymentcenter/core/merchant/service/MerchantAppService.java index 14cf7ca..1af60d7 100644 --- a/service-payment-center/service-payment-center-impl/src/main/java/cn/bootx/paymentcenter/core/merchant/service/MerchantAppService.java +++ b/service-payment-center/service-payment-center-impl/src/main/java/cn/bootx/paymentcenter/core/merchant/service/MerchantAppService.java @@ -49,9 +49,10 @@ public class MerchantAppService { public MerchantAppDto add(MerchantAppParam param){ MerchantApp merchantApp = MerchantApp.init(param); // 获取商户 - MerchantInfo merchantInfo = merchantInfoManager.findById(param.getMerchantId()) + MerchantInfo merchantInfo = merchantInfoManager.findByMerchantNo(param.getMerchantNo()) .orElseThrow(() -> new BizException("商户不存在")); merchantApp.setMerchantNo(merchantInfo.getMerchantNo()) + .setMerchantId(merchantInfo.getId()) .setAppId(snowFlakeId.nextIdStr()); return merchantAppRepository.save(merchantApp).toDto(); } @@ -63,6 +64,9 @@ public class MerchantAppService { return ResultConvertUtils.dtoListConvert(merchantAppManager.findByMerchantId(merchantId)); } + /** + * 分页 + */ public PageResult page(PageParam pageParam, MerchantAppParam param){ return JpaUtils.convert2PageResult(merchantAppManager.page(pageParam,param)); } diff --git a/service-payment-center/service-payment-center-impl/src/main/java/cn/bootx/paymentcenter/core/merchant/service/MerchantInfoService.java b/service-payment-center/service-payment-center-impl/src/main/java/cn/bootx/paymentcenter/core/merchant/service/MerchantInfoService.java index 67bac01..385748b 100644 --- a/service-payment-center/service-payment-center-impl/src/main/java/cn/bootx/paymentcenter/core/merchant/service/MerchantInfoService.java +++ b/service-payment-center/service-payment-center-impl/src/main/java/cn/bootx/paymentcenter/core/merchant/service/MerchantInfoService.java @@ -34,6 +34,7 @@ public class MerchantInfoService { * 添加商户 */ public MerchantInfoDto add(MerchantInfoParam param){ + MerchantInfo merchantInfo = MerchantInfo.init(param); // 商户号 merchantInfo.setMerchantNo("M"+snowflakeId.nextId()); diff --git a/service-payment-center/service-payment-center-impl/src/main/java/cn/bootx/paymentcenter/core/pay/func/AbsPayStrategy.java b/service-payment-center/service-payment-center-impl/src/main/java/cn/bootx/paymentcenter/core/pay/func/AbsPayStrategy.java index 64f7219..3089eb8 100644 --- a/service-payment-center/service-payment-center-impl/src/main/java/cn/bootx/paymentcenter/core/pay/func/AbsPayStrategy.java +++ b/service-payment-center/service-payment-center-impl/src/main/java/cn/bootx/paymentcenter/core/pay/func/AbsPayStrategy.java @@ -97,20 +97,20 @@ public abstract class AbsPayStrategy { /** * 撤销支付操作,支付交易返回失败或支付系统超时,调用该接口撤销交易 - * 默认为关闭本地交易单 + * 默认为关闭本地支付记录 */ public void doCancelHandler() { this.doCloseHandler(); } /** - * 关闭本地交易单 + * 关闭本地支付记录 */ public abstract void doCloseHandler(); /** - * 关闭本地以及支付网关的交易单 用户在一定时间内未进行支付,可调用该接口直接将支付王冠中的未付款交易进行关闭 - * 默认为关闭本地交易单 + * 关闭本地以及支付网关的支付记录 用户在一定时间内未进行支付,可调用该接口直接将支付王冠中的未付款交易进行关闭 + * 默认为关闭本地支付记录 */ public void doCloseRemoteHandler(){ this.doCloseHandler(); diff --git a/service-payment-center/service-payment-center-impl/src/main/java/cn/bootx/paymentcenter/core/pay/service/PayCancelService.java b/service-payment-center/service-payment-center-impl/src/main/java/cn/bootx/paymentcenter/core/pay/service/PayCancelService.java index 8fb91ab..753bc50 100644 --- a/service-payment-center/service-payment-center-impl/src/main/java/cn/bootx/paymentcenter/core/pay/service/PayCancelService.java +++ b/service-payment-center/service-payment-center-impl/src/main/java/cn/bootx/paymentcenter/core/pay/service/PayCancelService.java @@ -36,7 +36,7 @@ public class PayCancelService { private final PaymentRepository paymentRepository; /** - * 根据业务id取消支付交易单 + * 根据业务id取消支付记录 */ @Transactional(rollbackFor = Exception.class) public void cancelByBusinessId(String businessId) { @@ -46,7 +46,7 @@ public class PayCancelService { /** - * 根据paymentId取消支付交易单 + * 根据paymentId取消支付记录 */ @Transactional(rollbackFor = Exception.class) public void cancelByPaymentId(Long paymentId){ @@ -57,7 +57,7 @@ public class PayCancelService { } /** - * 取消支付交易单 + * 取消支付记录 */ private void cancelPayment(Payment payment){ diff --git a/service-payment-center/service-payment-center-impl/src/main/java/cn/bootx/paymentcenter/core/pay/service/PaySyncService.java b/service-payment-center/service-payment-center-impl/src/main/java/cn/bootx/paymentcenter/core/pay/service/PaySyncService.java index f2dd04b..030e2d8 100644 --- a/service-payment-center/service-payment-center-impl/src/main/java/cn/bootx/paymentcenter/core/pay/service/PaySyncService.java +++ b/service-payment-center/service-payment-center-impl/src/main/java/cn/bootx/paymentcenter/core/pay/service/PaySyncService.java @@ -114,7 +114,7 @@ public class PaySyncService { * payment 变更为取消支付 */ private void paymentCancel(Payment payment, List absPayStrategies) { - // 关闭本地交易单 + // 关闭本地支付记录 this.doHandler(payment,absPayStrategies,(strategyList, paymentObj) -> { strategyList.forEach(AbsPayStrategy::doCloseHandler); // 修改payment支付状态为取消 diff --git a/service-payment-center/service-payment-center-impl/src/main/java/cn/bootx/paymentcenter/core/pay/strategy/AliPayStrategy.java b/service-payment-center/service-payment-center-impl/src/main/java/cn/bootx/paymentcenter/core/pay/strategy/AliPayStrategy.java index 9c471f1..4ad01da 100644 --- a/service-payment-center/service-payment-center-impl/src/main/java/cn/bootx/paymentcenter/core/pay/strategy/AliPayStrategy.java +++ b/service-payment-center/service-payment-center-impl/src/main/java/cn/bootx/paymentcenter/core/pay/strategy/AliPayStrategy.java @@ -128,12 +128,12 @@ public class AliPayStrategy extends AbsPayStrategy { .orElseThrow(() -> new BizException("支付配置不存在"))); aliPayCancelService.cancelRemote(this.getPayment(),alipayConfig); AlipayConfigService.initApiConfig(alipayConfig); - // 调用关闭本地交易单 + // 调用关闭本地支付记录 this.doCloseHandler(); } /** - * 关闭本地交易单 + * 关闭本地支付记录 */ @Override public void doCloseHandler() { diff --git a/service-payment-center/service-payment-center-impl/src/main/java/cn/bootx/paymentcenter/core/pay/strategy/CashPayStrategy.java b/service-payment-center/service-payment-center-impl/src/main/java/cn/bootx/paymentcenter/core/pay/strategy/CashPayStrategy.java index fa9b1d6..55df393 100644 --- a/service-payment-center/service-payment-center-impl/src/main/java/cn/bootx/paymentcenter/core/pay/strategy/CashPayStrategy.java +++ b/service-payment-center/service-payment-center-impl/src/main/java/cn/bootx/paymentcenter/core/pay/strategy/CashPayStrategy.java @@ -63,7 +63,7 @@ public class CashPayStrategy extends AbsPayStrategy { } /** - * 关闭本地交易单 + * 关闭本地支付记录 */ @Override public void doCloseHandler() { diff --git a/service-payment-center/service-payment-center-impl/src/main/java/cn/bootx/paymentcenter/core/pay/strategy/PointPayStrategy.java b/service-payment-center/service-payment-center-impl/src/main/java/cn/bootx/paymentcenter/core/pay/strategy/PointPayStrategy.java index c383ee9..e8c614f 100644 --- a/service-payment-center/service-payment-center-impl/src/main/java/cn/bootx/paymentcenter/core/pay/strategy/PointPayStrategy.java +++ b/service-payment-center/service-payment-center-impl/src/main/java/cn/bootx/paymentcenter/core/pay/strategy/PointPayStrategy.java @@ -92,7 +92,7 @@ public class PointPayStrategy extends AbsPayStrategy { } /** - * 关闭本地交易单 + * 关闭本地支付记录 */ @Override public void doCloseHandler() { diff --git a/service-payment-center/service-payment-center-impl/src/main/java/cn/bootx/paymentcenter/core/pay/strategy/WeChatPayStrategy.java b/service-payment-center/service-payment-center-impl/src/main/java/cn/bootx/paymentcenter/core/pay/strategy/WeChatPayStrategy.java index effce2a..8208638 100644 --- a/service-payment-center/service-payment-center-impl/src/main/java/cn/bootx/paymentcenter/core/pay/strategy/WeChatPayStrategy.java +++ b/service-payment-center/service-payment-center-impl/src/main/java/cn/bootx/paymentcenter/core/pay/strategy/WeChatPayStrategy.java @@ -131,12 +131,12 @@ public class WeChatPayStrategy extends AbsPayStrategy { .orElseThrow(() -> new BizException("支付配置不存在"))); WeChatPayConfigService.initPayConfig(weChatPayConfig); weChatPayCancelService.cancelRemote(this.getPayment(),weChatPayConfig); - // 调用关闭本地交易单 + // 调用关闭本地支付记录 this.doCloseHandler(); } /** - * 关闭本地交易单 + * 关闭本地支付记录 */ @Override public void doCloseHandler() { diff --git a/service-payment-center/service-payment-center-impl/src/main/java/cn/bootx/paymentcenter/core/payconfig/dao/PayChannelManager.java b/service-payment-center/service-payment-center-impl/src/main/java/cn/bootx/paymentcenter/core/payconfig/dao/PayChannelManager.java index 8ece677..e8a3e47 100644 --- a/service-payment-center/service-payment-center-impl/src/main/java/cn/bootx/paymentcenter/core/payconfig/dao/PayChannelManager.java +++ b/service-payment-center/service-payment-center-impl/src/main/java/cn/bootx/paymentcenter/core/payconfig/dao/PayChannelManager.java @@ -58,6 +58,7 @@ public class PayChannelManager { if (StrUtil.isNotBlank(param.getName())){ query.where(q.name.like("%"+param.getName()+"%")); } + query.where(q.tid.eq(headerHolder.findTid())); return JpaUtils.queryPage(query,pageParam); } diff --git a/service-payment-center/service-payment-center-impl/src/main/java/cn/bootx/paymentcenter/core/payconfig/dao/PayChannelWayManager.java b/service-payment-center/service-payment-center-impl/src/main/java/cn/bootx/paymentcenter/core/payconfig/dao/PayChannelWayManager.java index f1ba339..2302421 100644 --- a/service-payment-center/service-payment-center-impl/src/main/java/cn/bootx/paymentcenter/core/payconfig/dao/PayChannelWayManager.java +++ b/service-payment-center/service-payment-center-impl/src/main/java/cn/bootx/paymentcenter/core/payconfig/dao/PayChannelWayManager.java @@ -60,6 +60,7 @@ public class PayChannelWayManager { if (StrUtil.isNotBlank(param.getName())){ query.where(q.name.like("%"+param.getName()+"%")); } + query.where(q.tid.eq(headerHolder.findTid())); return JpaUtils.queryPage(query,pageParam); } diff --git a/service-payment-center/service-payment-center-impl/src/main/java/cn/bootx/paymentcenter/core/payment/dao/PaymentManager.java b/service-payment-center/service-payment-center-impl/src/main/java/cn/bootx/paymentcenter/core/payment/dao/PaymentManager.java index 8994a14..8648e0a 100644 --- a/service-payment-center/service-payment-center-impl/src/main/java/cn/bootx/paymentcenter/core/payment/dao/PaymentManager.java +++ b/service-payment-center/service-payment-center-impl/src/main/java/cn/bootx/paymentcenter/core/payment/dao/PaymentManager.java @@ -94,6 +94,7 @@ public class PaymentManager { public Page page(PageParam pageParam, PaymentQuery param) { QPayment q = QPayment.payment; JPAQuery query = jpaQueryFactory.selectFrom(q); + query.where(q.tid.eq(headerHolder.findTid())); return JpaUtils.queryPage(query,pageParam); } diff --git a/service-payment-center/service-payment-center-impl/src/main/java/cn/bootx/paymentcenter/core/payment/entity/Payment.java b/service-payment-center/service-payment-center-impl/src/main/java/cn/bootx/paymentcenter/core/payment/entity/Payment.java index 069814c..2461405 100644 --- a/service-payment-center/service-payment-center-impl/src/main/java/cn/bootx/paymentcenter/core/payment/entity/Payment.java +++ b/service-payment-center/service-payment-center-impl/src/main/java/cn/bootx/paymentcenter/core/payment/entity/Payment.java @@ -21,7 +21,7 @@ import java.util.ArrayList; import java.util.List; /** -* 支付交易单 +* 支付记录 * @author xxm * @date 2020/12/8 */ diff --git a/service-payment-center/service-payment-center-impl/src/main/java/cn/bootx/paymentcenter/core/payment/service/PaymentService.java b/service-payment-center/service-payment-center-impl/src/main/java/cn/bootx/paymentcenter/core/payment/service/PaymentService.java index f488801..f1deb46 100644 --- a/service-payment-center/service-payment-center-impl/src/main/java/cn/bootx/paymentcenter/core/payment/service/PaymentService.java +++ b/service-payment-center/service-payment-center-impl/src/main/java/cn/bootx/paymentcenter/core/payment/service/PaymentService.java @@ -13,7 +13,7 @@ import java.time.LocalDateTime; import java.util.List; /** -* 支付交易单 +* 支付记录 * @author xxm * @date 2021/3/8 */ diff --git a/service-payment-center/service-payment-center-impl/src/main/java/cn/bootx/paymentcenter/core/paymodel/alipay/convert/AlipayConvert.java b/service-payment-center/service-payment-center-impl/src/main/java/cn/bootx/paymentcenter/core/paymodel/alipay/convert/AlipayConvert.java index de17ed3..a51feb8 100644 --- a/service-payment-center/service-payment-center-impl/src/main/java/cn/bootx/paymentcenter/core/paymodel/alipay/convert/AlipayConvert.java +++ b/service-payment-center/service-payment-center-impl/src/main/java/cn/bootx/paymentcenter/core/paymodel/alipay/convert/AlipayConvert.java @@ -2,6 +2,7 @@ package cn.bootx.paymentcenter.core.paymodel.alipay.convert; import cn.bootx.paymentcenter.core.paymodel.alipay.entity.AlipayConfig; import cn.bootx.paymentcenter.dto.paymodel.alipay.AlipayConfigDto; +import cn.bootx.paymentcenter.param.paymodel.alipay.AlipayConfigParam; import org.mapstruct.Mapper; import org.mapstruct.Mappings; import org.mapstruct.factory.Mappers; @@ -17,6 +18,9 @@ public interface AlipayConvert { @Mappings({}) AlipayConfig convert(AlipayConfigDto in); + @Mappings({}) + AlipayConfig convert(AlipayConfigParam in); + @Mappings({}) AlipayConfigDto convert(AlipayConfig in); } diff --git a/service-payment-center/service-payment-center-impl/src/main/java/cn/bootx/paymentcenter/core/paymodel/alipay/dao/AlipayConfigManager.java b/service-payment-center/service-payment-center-impl/src/main/java/cn/bootx/paymentcenter/core/paymodel/alipay/dao/AlipayConfigManager.java index 07dc14f..72f7dfb 100644 --- a/service-payment-center/service-payment-center-impl/src/main/java/cn/bootx/paymentcenter/core/paymodel/alipay/dao/AlipayConfigManager.java +++ b/service-payment-center/service-payment-center-impl/src/main/java/cn/bootx/paymentcenter/core/paymodel/alipay/dao/AlipayConfigManager.java @@ -1,9 +1,17 @@ package cn.bootx.paymentcenter.core.paymodel.alipay.dao; +import cn.bootx.common.web.rest.param.PageParam; import cn.bootx.paymentcenter.core.paymodel.alipay.entity.AlipayConfig; +import cn.bootx.paymentcenter.core.paymodel.alipay.entity.QAlipayConfig; +import cn.bootx.paymentcenter.param.paymodel.alipay.AlipayConfigQuery; import cn.bootx.starter.headerholder.HeaderHolder; +import cn.bootx.starter.jpa.utils.JpaUtils; +import cn.hutool.core.util.StrUtil; +import com.querydsl.jpa.impl.JPAQuery; +import com.querydsl.jpa.impl.JPAQueryFactory; import lombok.RequiredArgsConstructor; import org.springframework.cache.annotation.Cacheable; +import org.springframework.data.domain.Page; import org.springframework.stereotype.Repository; import java.util.List; @@ -18,6 +26,7 @@ import java.util.Optional; @RequiredArgsConstructor public class AlipayConfigManager { private final AlipayConfigRepository repository; + private final JPAQueryFactory jpaQueryFactory; private final HeaderHolder headerHolder; public Optional findById(Long id){ @@ -32,12 +41,22 @@ public class AlipayConfigManager { return repository.findByAppIdAndTid(appId,headerHolder.findTid()); } - /** - * 根据支付宝AppId获取支付宝支付配置 - */ - @Cacheable(value = "pc:alipay:config:ali",key = "#aliAppId") - public Optional findByAliAppIdAndTid(String aliAppId){ - return repository.findByAliAppIdAndTid(aliAppId,headerHolder.findTid()); + public Page page(PageParam pageParam, AlipayConfigQuery param) { + QAlipayConfig q = QAlipayConfig.alipayConfig; + JPAQuery query = jpaQueryFactory.selectFrom(q); + + if (StrUtil.isNotBlank(param.getMerchantNo())){ + query.where(q.merchantNo.like("%"+param.getMerchantNo()+"%")); + } + if (StrUtil.isNotBlank(param.getAppId())){ + query.where(q.appId.like("%"+param.getAppId()+"%")); + } + if (StrUtil.isNotBlank(param.getName())){ + query.where(q.name.like("%"+param.getName()+"%")); + } + + query.where(q.tid.eq(headerHolder.findTid())); + return JpaUtils.queryPage(query,pageParam); } /** @@ -54,4 +73,5 @@ public class AlipayConfigManager { public void deleteByAppId(String appId) { repository.deleteByAppIdAndTid(appId,headerHolder.findTid()); } + } diff --git a/service-payment-center/service-payment-center-impl/src/main/java/cn/bootx/paymentcenter/core/paymodel/alipay/entity/AlipayConfig.java b/service-payment-center/service-payment-center-impl/src/main/java/cn/bootx/paymentcenter/core/paymodel/alipay/entity/AlipayConfig.java index 1ae8890..23b68fe 100644 --- a/service-payment-center/service-payment-center-impl/src/main/java/cn/bootx/paymentcenter/core/paymodel/alipay/entity/AlipayConfig.java +++ b/service-payment-center/service-payment-center-impl/src/main/java/cn/bootx/paymentcenter/core/paymodel/alipay/entity/AlipayConfig.java @@ -3,6 +3,7 @@ package cn.bootx.paymentcenter.core.paymodel.alipay.entity; import cn.bootx.common.function.EntityBaseFunction; import cn.bootx.paymentcenter.core.paymodel.alipay.convert.AlipayConvert; import cn.bootx.paymentcenter.dto.paymodel.alipay.AlipayConfigDto; +import cn.bootx.paymentcenter.param.paymodel.alipay.AlipayConfigParam; import cn.bootx.starter.jpa.base.JpaBaseEntity; import cn.hutool.core.collection.CollUtil; import cn.hutool.core.util.StrUtil; @@ -31,6 +32,9 @@ public class AlipayConfig extends JpaBaseEntity implements EntityBaseFunction new BizException("支付宝不存在")); - param.setAppId(null); + param.setAppId(null) + .setMerchantNo(null); appChannelService.update(alipayConfig.getAppId(),param.getState(), PayTypeEnum.ALI_PAY.getCode()); BeanUtil.copyProperties(param,alipayConfig, CopyOptions.create().ignoreNullValue()); // 支付方式 @@ -69,7 +74,7 @@ public class AlipayConfigService { * 删除 */ @Transactional(rollbackFor = Exception.class) - @CacheEvict(value = "pc:alipay:config",key = "#param.appId") + @CacheEvict(value = "pc:alipay:config",key = "#appId") public void deleteByAppId(String appId){ appChannelService.delete(appId,PayTypeEnum.ALI_PAY.getCode()); alipayConfigManager.deleteByAppId(appId); @@ -78,7 +83,6 @@ public class AlipayConfigService { /** * 获取 */ - @Cacheable(value = "pc:alipay:config",key = "#id") public AlipayConfigDto findById(Long id){ return alipayConfigManager.findById(id) .map(AlipayConfig::toDto) @@ -86,19 +90,17 @@ public class AlipayConfigService { } /** - * 获取 + * 分页 */ - public AlipayConfigDto findByAppId(String appId){ - return alipayConfigManager.findByAppId(appId) - .map(AlipayConfig::toDto) - .orElse(null); + public PageResult page(PageParam pageParam, AlipayConfigQuery param) { + return JpaUtils.convert2PageResult(alipayConfigManager.page(pageParam,param)); } /** * 获取 */ - public AlipayConfigDto findByAliAppIdAndTid(String aliAppId){ - return alipayConfigManager.findByAliAppIdAndTid(aliAppId) + public AlipayConfigDto findByAppId(String appId){ + return alipayConfigManager.findByAppId(appId) .map(AlipayConfig::toDto) .orElse(null); } @@ -107,16 +109,15 @@ public class AlipayConfigService { * 移到工具类中 */ public static void initApiConfig(AlipayConfig alipayConfig){ - // 支付宝支付配置注册 - AliPayApiConfig aliPayApiConfig = AliPayApiConfig.builder() - .setAppId(alipayConfig.getAliAppId()) - .setPrivateKey(alipayConfig.getPrivateKey()) - .setCharset(CharsetUtil.UTF_8) - .setAliPayPublicKey(alipayConfig.getAlipayPublicKey()) - .setServiceUrl(alipayConfig.getServerUrl()) - .setSignType(alipayConfig.getSignType()) - .build(); + // 支付宝支付配置注册 + AliPayApiConfig aliPayApiConfig = AliPayApiConfig.builder() + .setAppId(alipayConfig.getAliAppId()) + .setPrivateKey(alipayConfig.getPrivateKey()) + .setCharset(CharsetUtil.UTF_8) + .setAliPayPublicKey(alipayConfig.getAlipayPublicKey()) + .setServiceUrl(alipayConfig.getServerUrl()) + .setSignType(alipayConfig.getSignType()) + .build(); AliPayApiConfigKit.setThreadLocalAliPayApiConfig(aliPayApiConfig); } - } diff --git a/service-payment-center/service-payment-center-impl/src/main/java/cn/bootx/paymentcenter/core/paymodel/base/dao/PayNotifyRecordManager.java b/service-payment-center/service-payment-center-impl/src/main/java/cn/bootx/paymentcenter/core/paymodel/base/dao/PayNotifyRecordManager.java index e9586df..43a43ce 100644 --- a/service-payment-center/service-payment-center-impl/src/main/java/cn/bootx/paymentcenter/core/paymodel/base/dao/PayNotifyRecordManager.java +++ b/service-payment-center/service-payment-center-impl/src/main/java/cn/bootx/paymentcenter/core/paymodel/base/dao/PayNotifyRecordManager.java @@ -29,8 +29,10 @@ public class PayNotifyRecordManager { public Page page(PageParam pageParam){ QPayNotifyRecord q = QPayNotifyRecord.payNotifyRecord; - JPAQuery query = jpaQueryFactory.selectFrom(q) - .where(q.tid.eq(headerHolder.findTid())); + JPAQuery query = jpaQueryFactory.selectFrom(q); + + + query.where(q.tid.eq(headerHolder.findTid())); return JpaUtils.queryPage(query,pageParam); } diff --git a/service-payment-center/service-payment-center-impl/src/main/java/cn/bootx/paymentcenter/core/paymodel/wallet/service/WalletPayService.java b/service-payment-center/service-payment-center-impl/src/main/java/cn/bootx/paymentcenter/core/paymodel/wallet/service/WalletPayService.java index 879e147..155aa50 100644 --- a/service-payment-center/service-payment-center-impl/src/main/java/cn/bootx/paymentcenter/core/paymodel/wallet/service/WalletPayService.java +++ b/service-payment-center/service-payment-center-impl/src/main/java/cn/bootx/paymentcenter/core/paymodel/wallet/service/WalletPayService.java @@ -49,7 +49,7 @@ public class WalletPayService { /** * 支付操作 * @param amount 付款金额 - * @param payment 交易 + * @param payment 支付记录 * @param userId 用户Id */ public void pay(BigDecimal amount, Payment payment, Long userId) { @@ -82,7 +82,7 @@ public class WalletPayService { @Transactional(rollbackFor = Exception.class) public void deductedBalanceByPaymentId(Long paymentId, Long orderId, String remark, Boolean isThrowError) { - // 根据交易ID查询交易的金额和交易的钱包ID + // 根据支付记录ID查询交易的金额和交易的钱包ID WalletLog walletLog = walletLogManager.findFirstByPayment(paymentId).orElse(null); if (walletLog == null) { return; -- Gitee From 028630cc1cf874b70b27a9630998124fed4bdd48 Mon Sep 17 00:00:00 2001 From: xxm Date: Fri, 23 Jul 2021 17:24:43 +0800 Subject: [PATCH 2/2] =?UTF-8?q?feat=20=E7=AE=80=E5=8C=96=E5=95=86=E5=93=81?= =?UTF-8?q?=E4=B8=AD=E5=BF=83,=20=E5=8F=AA=E4=BF=9D=E7=95=99=E6=A0=B8?= =?UTF-8?q?=E5=BF=83=E5=8A=9F=E8=83=BD(=E5=BA=93=E5=AD=98=E7=AE=A1?= =?UTF-8?q?=E7=90=86),=20=E5=A4=8D=E6=9D=82=E5=8A=9F=E8=83=BD=E8=BF=9B?= =?UTF-8?q?=E8=A1=8C=E9=87=8D=E5=81=9A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../client/CategoryAttrDefClient.java | 32 --- .../goodscenter/client/CategoryClient.java | 44 ---- .../bootx/goodscenter/client/GoodsClient.java | 23 +- .../goodscenter/client/GoodsSkuClient.java | 15 +- .../feign/CategoryAttrDefClientFeignImpl.java | 37 --- .../client/feign/CategoryAttrDefFeign.java | 38 --- .../client/feign/CategoryClientFeignImpl.java | 45 ---- .../client/feign/GoodsClientFeignImpl.java | 20 +- .../goodscenter/client/feign/GoodsFeign.java | 18 +- .../client/feign/GoodsSkuClientFeignImpl.java | 16 +- .../client/feign/GoodsSkuFeign.java | 17 +- .../feign/InventoryClientFeignImpl.java | 2 + .../dto/category/CategoryAttrDefDto.java | 68 ----- .../goodscenter/dto/goods/GoodsAttrDto.java | 32 --- .../bootx/goodscenter/dto/goods/GoodsDto.java | 41 +-- .../goodscenter/dto/goods/GoodsSpecDto.java | 34 --- .../dto/packing/GoodsPackingDto.java | 28 -- .../dto/packing/GoodsSkuPackingDto.java | 36 --- .../goodscenter/dto/sku/GoodsSkuAttrDto.java | 29 --- .../goodscenter/dto/sku/GoodsSkuDto.java | 87 +------ ...{CreateGoodsParam.java => GoodsParam.java} | 18 +- .../param/goods/UpdateGoodsAndSkuParam.java | 36 --- .../param/goods/UpdateGoodsParam.java | 50 ---- .../param/packing/GoodsPackingParam.java | 30 --- .../param/sku/GenSkuAttrParam.java | 28 -- .../{CreateSkuParam.java => SkuParam.java} | 39 ++- .../goodscenter/param/sku/UpdateSkuParam.java | 66 ----- .../main/resources/META-INF/spring.factories | 4 +- .../controller/CategoryAttrDefController.java | 44 ---- .../controller/CategoryController.java | 2 +- .../controller/GoodsController.java | 30 +-- .../controller/GoodsPackController.java | 17 -- .../controller/GoodsSkuController.java | 25 +- .../controller/GoodsSkuPackController.java | 33 --- .../dao/CategoryAttrDefManager.java | 35 --- .../dao/CategoryAttrDefRepository.java | 17 -- .../attributes/entity/CategoryAttrDef.java | 90 ------- .../attributes/handler/AttrGenHandler.java | 172 ------------ .../service/CategoryAttrDefService.java | 59 ----- .../category/convert/CategoryConvert.java | 8 - .../category/service/CategoryService.java | 1 - .../core/goods/convert/GoodsConvert.java | 27 ++ .../core/goods/dao/GoodsAttrRepository.java | 8 - .../core/goods/dao/GoodsManager.java | 30 --- .../core/goods/dao/GoodsRepository.java | 14 - .../goodscenter/core/goods/entity/Goods.java | 55 +--- .../core/goods/entity/GoodsAttr.java | 37 --- .../core/goods/entity/GoodsSpec.java | 42 --- .../core/goods/factory/GoodsFactory.java | 57 ---- .../core/goods/service/GoodsAddService.java | 140 ---------- .../core/goods/service/GoodsEditService.java | 150 ----------- .../core/goods/service/GoodsService.java | 32 +-- .../goods/service/OperateGoodsService.java | 61 ----- .../inventory/dao/InventoryRepository.java | 9 - .../inventory/manager/InventoryManager.java | 7 - .../manager/InventoryTokenManager.java | 5 +- .../inventory/service/InventoryService.java | 21 +- .../service/OperateInventoryService.java | 62 +---- .../core/packing/dao/GoodsSkuPackManager.java | 35 --- .../packing/dao/GoodsSkuPackRepository.java | 16 -- .../core/packing/entity/GoodsSkuPack.java | 53 ---- .../packing/service/GoodsSkuPackService.java | 132 ---------- .../core/sku/convert/SkuConvert.java | 27 ++ .../core/sku/dao/GoodsSkuAttrManager.java | 34 --- .../core/sku/dao/GoodsSkuAttrRepository.java | 13 - .../core/sku/dao/GoodsSkuManager.java | 21 -- .../core/sku/dao/GoodsSkuRepository.java | 16 -- .../goodscenter/core/sku/entity/GoodsSku.java | 47 +--- .../core/sku/entity/GoodsSkuAttr.java | 56 ---- .../core/sku/factory/GoodsSkuFactory.java | 55 ---- .../core/sku/service/GoodsSkuGenService.java | 86 ------ .../sku/service/GoodsSkuOperateService.java | 41 --- .../core/sku/service/GoodsSkuService.java | 95 ++----- .../engine/shop/param/demo/DemoPayParam.java | 18 +- .../shop/param/demo/DemoPlaceAndPayParam.java | 20 +- .../shop/param/demo/DemoPlaceOrderParam.java | 24 +- .../shop/controller/DemoController.java | 42 +++ .../shop/core/cart/service/CartService.java | 4 +- .../shop/core/demo/service/DemoService.java | 246 ++++++++++++++++++ .../core/order/service/OrderPlaceService.java | 6 +- .../core/pay/service/OrderPayService.java | 2 +- .../shop/transform/GoodsCenterTransform.java | 1 - 82 files changed, 516 insertions(+), 2797 deletions(-) delete mode 100644 service-goods-center/service-goods-center-api/src/main/java/cn/bootx/goodscenter/client/CategoryAttrDefClient.java delete mode 100644 service-goods-center/service-goods-center-api/src/main/java/cn/bootx/goodscenter/client/CategoryClient.java delete mode 100644 service-goods-center/service-goods-center-api/src/main/java/cn/bootx/goodscenter/client/feign/CategoryAttrDefClientFeignImpl.java delete mode 100644 service-goods-center/service-goods-center-api/src/main/java/cn/bootx/goodscenter/client/feign/CategoryAttrDefFeign.java delete mode 100644 service-goods-center/service-goods-center-api/src/main/java/cn/bootx/goodscenter/client/feign/CategoryClientFeignImpl.java delete mode 100644 service-goods-center/service-goods-center-api/src/main/java/cn/bootx/goodscenter/dto/category/CategoryAttrDefDto.java delete mode 100644 service-goods-center/service-goods-center-api/src/main/java/cn/bootx/goodscenter/dto/goods/GoodsAttrDto.java delete mode 100644 service-goods-center/service-goods-center-api/src/main/java/cn/bootx/goodscenter/dto/goods/GoodsSpecDto.java delete mode 100644 service-goods-center/service-goods-center-api/src/main/java/cn/bootx/goodscenter/dto/packing/GoodsPackingDto.java delete mode 100644 service-goods-center/service-goods-center-api/src/main/java/cn/bootx/goodscenter/dto/packing/GoodsSkuPackingDto.java delete mode 100644 service-goods-center/service-goods-center-api/src/main/java/cn/bootx/goodscenter/dto/sku/GoodsSkuAttrDto.java rename service-goods-center/service-goods-center-api/src/main/java/cn/bootx/goodscenter/param/goods/{CreateGoodsParam.java => GoodsParam.java} (68%) delete mode 100644 service-goods-center/service-goods-center-api/src/main/java/cn/bootx/goodscenter/param/goods/UpdateGoodsAndSkuParam.java delete mode 100644 service-goods-center/service-goods-center-api/src/main/java/cn/bootx/goodscenter/param/goods/UpdateGoodsParam.java delete mode 100644 service-goods-center/service-goods-center-api/src/main/java/cn/bootx/goodscenter/param/packing/GoodsPackingParam.java delete mode 100644 service-goods-center/service-goods-center-api/src/main/java/cn/bootx/goodscenter/param/sku/GenSkuAttrParam.java rename service-goods-center/service-goods-center-api/src/main/java/cn/bootx/goodscenter/param/sku/{CreateSkuParam.java => SkuParam.java} (46%) delete mode 100644 service-goods-center/service-goods-center-api/src/main/java/cn/bootx/goodscenter/param/sku/UpdateSkuParam.java delete mode 100644 service-goods-center/service-goods-center-impl/src/main/java/cn/bootx/goodscenter/controller/CategoryAttrDefController.java delete mode 100644 service-goods-center/service-goods-center-impl/src/main/java/cn/bootx/goodscenter/controller/GoodsPackController.java delete mode 100644 service-goods-center/service-goods-center-impl/src/main/java/cn/bootx/goodscenter/controller/GoodsSkuPackController.java delete mode 100644 service-goods-center/service-goods-center-impl/src/main/java/cn/bootx/goodscenter/core/attributes/dao/CategoryAttrDefManager.java delete mode 100644 service-goods-center/service-goods-center-impl/src/main/java/cn/bootx/goodscenter/core/attributes/dao/CategoryAttrDefRepository.java delete mode 100644 service-goods-center/service-goods-center-impl/src/main/java/cn/bootx/goodscenter/core/attributes/entity/CategoryAttrDef.java delete mode 100644 service-goods-center/service-goods-center-impl/src/main/java/cn/bootx/goodscenter/core/attributes/handler/AttrGenHandler.java delete mode 100644 service-goods-center/service-goods-center-impl/src/main/java/cn/bootx/goodscenter/core/attributes/service/CategoryAttrDefService.java create mode 100644 service-goods-center/service-goods-center-impl/src/main/java/cn/bootx/goodscenter/core/goods/convert/GoodsConvert.java delete mode 100644 service-goods-center/service-goods-center-impl/src/main/java/cn/bootx/goodscenter/core/goods/dao/GoodsAttrRepository.java delete mode 100644 service-goods-center/service-goods-center-impl/src/main/java/cn/bootx/goodscenter/core/goods/entity/GoodsAttr.java delete mode 100644 service-goods-center/service-goods-center-impl/src/main/java/cn/bootx/goodscenter/core/goods/entity/GoodsSpec.java delete mode 100644 service-goods-center/service-goods-center-impl/src/main/java/cn/bootx/goodscenter/core/goods/factory/GoodsFactory.java delete mode 100644 service-goods-center/service-goods-center-impl/src/main/java/cn/bootx/goodscenter/core/goods/service/GoodsAddService.java delete mode 100644 service-goods-center/service-goods-center-impl/src/main/java/cn/bootx/goodscenter/core/goods/service/GoodsEditService.java delete mode 100644 service-goods-center/service-goods-center-impl/src/main/java/cn/bootx/goodscenter/core/goods/service/OperateGoodsService.java delete mode 100644 service-goods-center/service-goods-center-impl/src/main/java/cn/bootx/goodscenter/core/packing/dao/GoodsSkuPackManager.java delete mode 100644 service-goods-center/service-goods-center-impl/src/main/java/cn/bootx/goodscenter/core/packing/dao/GoodsSkuPackRepository.java delete mode 100644 service-goods-center/service-goods-center-impl/src/main/java/cn/bootx/goodscenter/core/packing/entity/GoodsSkuPack.java delete mode 100644 service-goods-center/service-goods-center-impl/src/main/java/cn/bootx/goodscenter/core/packing/service/GoodsSkuPackService.java create mode 100644 service-goods-center/service-goods-center-impl/src/main/java/cn/bootx/goodscenter/core/sku/convert/SkuConvert.java delete mode 100644 service-goods-center/service-goods-center-impl/src/main/java/cn/bootx/goodscenter/core/sku/dao/GoodsSkuAttrManager.java delete mode 100644 service-goods-center/service-goods-center-impl/src/main/java/cn/bootx/goodscenter/core/sku/dao/GoodsSkuAttrRepository.java delete mode 100644 service-goods-center/service-goods-center-impl/src/main/java/cn/bootx/goodscenter/core/sku/entity/GoodsSkuAttr.java delete mode 100644 service-goods-center/service-goods-center-impl/src/main/java/cn/bootx/goodscenter/core/sku/factory/GoodsSkuFactory.java delete mode 100644 service-goods-center/service-goods-center-impl/src/main/java/cn/bootx/goodscenter/core/sku/service/GoodsSkuGenService.java delete mode 100644 service-goods-center/service-goods-center-impl/src/main/java/cn/bootx/goodscenter/core/sku/service/GoodsSkuOperateService.java rename service-goods-center/service-goods-center-api/src/main/java/cn/bootx/goodscenter/param/goods/CreateGoodsAndSkuParam.java => service-shop-engine/service-shop-engine-api/src/main/java/cn/bootx/engine/shop/param/demo/DemoPayParam.java (37%) rename service-goods-center/service-goods-center-api/src/main/java/cn/bootx/goodscenter/param/sku/GenSkuParam.java => service-shop-engine/service-shop-engine-api/src/main/java/cn/bootx/engine/shop/param/demo/DemoPlaceAndPayParam.java (34%) rename service-goods-center/service-goods-center-api/src/main/java/cn/bootx/goodscenter/param/packing/GoodsSkuPackingParam.java => service-shop-engine/service-shop-engine-api/src/main/java/cn/bootx/engine/shop/param/demo/DemoPlaceOrderParam.java (36%) create mode 100644 service-shop-engine/service-shop-engine-impl/src/main/java/cn/bootx/engine/shop/controller/DemoController.java create mode 100644 service-shop-engine/service-shop-engine-impl/src/main/java/cn/bootx/engine/shop/core/demo/service/DemoService.java diff --git a/service-goods-center/service-goods-center-api/src/main/java/cn/bootx/goodscenter/client/CategoryAttrDefClient.java b/service-goods-center/service-goods-center-api/src/main/java/cn/bootx/goodscenter/client/CategoryAttrDefClient.java deleted file mode 100644 index 8e37c2c..0000000 --- a/service-goods-center/service-goods-center-api/src/main/java/cn/bootx/goodscenter/client/CategoryAttrDefClient.java +++ /dev/null @@ -1,32 +0,0 @@ -package cn.bootx.goodscenter.client; - -import cn.bootx.goodscenter.dto.category.CategoryAttrDefDto; - -import java.util.List; - -/** -* 类目属性 -* @author xxm -* @date 2020/11/26 -*/ -public interface CategoryAttrDefClient { - /** - * 添加类目属性定义 - */ - CategoryAttrDefDto addAttrDef(CategoryAttrDefDto param); - - /** - * 查询全部定义 - */ - List findAll(); - - /** - * 根据类目id查询 - */ - List findByCategory(Long cid); - - /** - * 查询单条 - */ - CategoryAttrDefDto getById(Long id); -} diff --git a/service-goods-center/service-goods-center-api/src/main/java/cn/bootx/goodscenter/client/CategoryClient.java b/service-goods-center/service-goods-center-api/src/main/java/cn/bootx/goodscenter/client/CategoryClient.java deleted file mode 100644 index 43710a6..0000000 --- a/service-goods-center/service-goods-center-api/src/main/java/cn/bootx/goodscenter/client/CategoryClient.java +++ /dev/null @@ -1,44 +0,0 @@ -package cn.bootx.goodscenter.client; - -import cn.bootx.goodscenter.dto.category.CategoryDto; -import cn.bootx.goodscenter.dto.category.CategoryTreeNode; - -import java.util.List; - -/** -* 类目管理 -* @author xxm -* @date 2020/11/26 -*/ -public interface CategoryClient { - /** - * 添加新类目 - */ - CategoryDto addCategory(CategoryDto categoryDto); - - /** - * 更新类目基本信息 - */ - CategoryDto update(CategoryDto param); - - /** - * 获取所有类目 - */ - List findAll(); - - /** - * 根据 id 获取相应的类目 - */ - CategoryDto getById(Long id); - - /** - * 获取类目树 - */ - List findTree(); - - /** - * 根据 id 删除相应的类目 - */ - void deleteById(Long id); - -} diff --git a/service-goods-center/service-goods-center-api/src/main/java/cn/bootx/goodscenter/client/GoodsClient.java b/service-goods-center/service-goods-center-api/src/main/java/cn/bootx/goodscenter/client/GoodsClient.java index bf3abfb..aa4674b 100644 --- a/service-goods-center/service-goods-center-api/src/main/java/cn/bootx/goodscenter/client/GoodsClient.java +++ b/service-goods-center/service-goods-center-api/src/main/java/cn/bootx/goodscenter/client/GoodsClient.java @@ -1,9 +1,7 @@ package cn.bootx.goodscenter.client; import cn.bootx.goodscenter.dto.goods.GoodsDto; -import cn.bootx.goodscenter.dto.sku.GoodsSkuDto; -import cn.bootx.goodscenter.param.goods.CreateGoodsAndSkuParam; -import cn.bootx.goodscenter.param.sku.CreateSkuParam; +import cn.bootx.goodscenter.param.goods.GoodsParam; import java.util.List; @@ -13,20 +11,10 @@ import java.util.List; * @date 2020/11/26 */ public interface GoodsClient { - - /** - * 添加单品 - */ - GoodsSkuDto addSingle( CreateSkuParam param); /** * 添加商品 */ - GoodsDto add(CreateGoodsAndSkuParam param); - - /** - * 添加打包商品 - */ - GoodsDto addPackGoods(CreateGoodsAndSkuParam param); + GoodsDto add(GoodsParam param); /** * 查询全部 @@ -39,7 +27,12 @@ public interface GoodsClient { List findByCategory(Long cid); /** - * 获取商品详情 + * 获取商品详情包括sku */ GoodsDto getDetails(Long id); + + /** + * 获取商品信息 + */ + GoodsDto findById(Long id); } diff --git a/service-goods-center/service-goods-center-api/src/main/java/cn/bootx/goodscenter/client/GoodsSkuClient.java b/service-goods-center/service-goods-center-api/src/main/java/cn/bootx/goodscenter/client/GoodsSkuClient.java index 0146208..daf0e2e 100644 --- a/service-goods-center/service-goods-center-api/src/main/java/cn/bootx/goodscenter/client/GoodsSkuClient.java +++ b/service-goods-center/service-goods-center-api/src/main/java/cn/bootx/goodscenter/client/GoodsSkuClient.java @@ -1,8 +1,6 @@ package cn.bootx.goodscenter.client; import cn.bootx.goodscenter.dto.sku.GoodsSkuDto; -import cn.bootx.goodscenter.param.sku.CreateSkuParam; -import cn.bootx.goodscenter.param.sku.GenSkuParam; import java.util.List; @@ -15,26 +13,15 @@ public interface GoodsSkuClient { /** * 根据 id 获取相应的商品SKU */ - GoodsSkuDto getById(Long id); - + GoodsSkuDto findById(Long id); /** * 批量查询 */ List findBySkuIds(List skuIds); - /** - * 根据商品 SKU 属性生成对应的商品 SKU 预览 - */ - List genGoodsSkuBySkuAttrs(GenSkuParam genSkuParam); - /** * 根据goodsId查询 */ List findByGoodsId(Long goodsId); - - /** - * 添加商品sku - */ - GoodsSkuDto add(CreateSkuParam skuParam); } diff --git a/service-goods-center/service-goods-center-api/src/main/java/cn/bootx/goodscenter/client/feign/CategoryAttrDefClientFeignImpl.java b/service-goods-center/service-goods-center-api/src/main/java/cn/bootx/goodscenter/client/feign/CategoryAttrDefClientFeignImpl.java deleted file mode 100644 index 71c2ac3..0000000 --- a/service-goods-center/service-goods-center-api/src/main/java/cn/bootx/goodscenter/client/feign/CategoryAttrDefClientFeignImpl.java +++ /dev/null @@ -1,37 +0,0 @@ -package cn.bootx.goodscenter.client.feign; - -import cn.bootx.goodscenter.client.CategoryAttrDefClient; -import cn.bootx.goodscenter.dto.category.CategoryAttrDefDto; -import lombok.RequiredArgsConstructor; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; -import org.springframework.stereotype.Component; - -import java.util.List; - -@Component -@ConditionalOnMissingBean(CategoryAttrDefClient.class) -public class CategoryAttrDefClientFeignImpl implements CategoryAttrDefClient { - @Autowired(required = false) - private CategoryAttrDefFeign categoryAttrDefFeign; - - @Override - public CategoryAttrDefDto addAttrDef(CategoryAttrDefDto param) { - return categoryAttrDefFeign.add(param).getData(); - } - - @Override - public List findAll() { - return categoryAttrDefFeign.findAll().getData(); - } - - @Override - public List findByCategory(Long cid) { - return categoryAttrDefFeign.findByCategory(cid).getData(); - } - - @Override - public CategoryAttrDefDto getById(Long id) { - return categoryAttrDefFeign.get(id).getData(); - } -} diff --git a/service-goods-center/service-goods-center-api/src/main/java/cn/bootx/goodscenter/client/feign/CategoryAttrDefFeign.java b/service-goods-center/service-goods-center-api/src/main/java/cn/bootx/goodscenter/client/feign/CategoryAttrDefFeign.java deleted file mode 100644 index 4ac5d1c..0000000 --- a/service-goods-center/service-goods-center-api/src/main/java/cn/bootx/goodscenter/client/feign/CategoryAttrDefFeign.java +++ /dev/null @@ -1,38 +0,0 @@ -package cn.bootx.goodscenter.client.feign; - -import cn.bootx.common.web.rest.ResResult; -import cn.bootx.goodscenter.code.GoodsCenterCode; -import cn.bootx.goodscenter.dto.category.CategoryAttrDefDto; -import io.swagger.annotations.ApiOperation; -import org.springframework.cloud.openfeign.FeignClient; -import org.springframework.web.bind.annotation.GetMapping; -import org.springframework.web.bind.annotation.PostMapping; -import org.springframework.web.bind.annotation.RequestBody; -import org.springframework.web.bind.annotation.RequestParam; - -import java.util.List; - -/** -* 类目属性定义 -* @author xxm -* @date 2021/3/21 -*/ -@FeignClient(name = GoodsCenterCode.APPLICATION_NAME,contextId = "categoryAttrDefFeign",path = "/category") -interface CategoryAttrDefFeign { - - @ApiOperation("添加") - @PostMapping("/add") - ResResult add(@RequestBody CategoryAttrDefDto dto); - - @ApiOperation("获取单条") - @GetMapping("/get") - ResResult get(@RequestParam Long id); - - @ApiOperation("查询全部") - @GetMapping("/findAll") - ResResult> findAll(); - - @ApiOperation("按类目查询") - @GetMapping("/findByCategory") - ResResult> findByCategory(@RequestParam Long cid); -} diff --git a/service-goods-center/service-goods-center-api/src/main/java/cn/bootx/goodscenter/client/feign/CategoryClientFeignImpl.java b/service-goods-center/service-goods-center-api/src/main/java/cn/bootx/goodscenter/client/feign/CategoryClientFeignImpl.java deleted file mode 100644 index 1b36347..0000000 --- a/service-goods-center/service-goods-center-api/src/main/java/cn/bootx/goodscenter/client/feign/CategoryClientFeignImpl.java +++ /dev/null @@ -1,45 +0,0 @@ -package cn.bootx.goodscenter.client.feign; - -import cn.bootx.goodscenter.client.CategoryClient; -import cn.bootx.goodscenter.dto.category.CategoryDto; -import cn.bootx.goodscenter.dto.category.CategoryTreeNode; -import lombok.RequiredArgsConstructor; -import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; -import org.springframework.stereotype.Component; - -import java.util.List; - -@Component -@ConditionalOnMissingBean(CategoryClient.class) -@RequiredArgsConstructor -public class CategoryClientFeignImpl implements CategoryClient { - @Override - public CategoryDto addCategory(CategoryDto categoryDto) { - return null; - } - - @Override - public CategoryDto update(CategoryDto param) { - return null; - } - - @Override - public List findAll() { - return null; - } - - @Override - public CategoryDto getById(Long id) { - return null; - } - - @Override - public List findTree() { - return null; - } - - @Override - public void deleteById(Long id) { - - } -} diff --git a/service-goods-center/service-goods-center-api/src/main/java/cn/bootx/goodscenter/client/feign/GoodsClientFeignImpl.java b/service-goods-center/service-goods-center-api/src/main/java/cn/bootx/goodscenter/client/feign/GoodsClientFeignImpl.java index 236c851..c972a67 100644 --- a/service-goods-center/service-goods-center-api/src/main/java/cn/bootx/goodscenter/client/feign/GoodsClientFeignImpl.java +++ b/service-goods-center/service-goods-center-api/src/main/java/cn/bootx/goodscenter/client/feign/GoodsClientFeignImpl.java @@ -2,9 +2,7 @@ package cn.bootx.goodscenter.client.feign; import cn.bootx.goodscenter.client.GoodsClient; import cn.bootx.goodscenter.dto.goods.GoodsDto; -import cn.bootx.goodscenter.dto.sku.GoodsSkuDto; -import cn.bootx.goodscenter.param.goods.CreateGoodsAndSkuParam; -import cn.bootx.goodscenter.param.sku.CreateSkuParam; +import cn.bootx.goodscenter.param.goods.GoodsParam; import lombok.RequiredArgsConstructor; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; @@ -19,21 +17,12 @@ public class GoodsClientFeignImpl implements GoodsClient { @Autowired(required = false) private GoodsFeign goodsFeign; - @Override - public GoodsSkuDto addSingle(CreateSkuParam param) { - return goodsFeign.addSingle(param).getData(); - } @Override - public GoodsDto add(CreateGoodsAndSkuParam param) { + public GoodsDto add(GoodsParam param) { return goodsFeign.add(param).getData(); } - @Override - public GoodsDto addPackGoods(CreateGoodsAndSkuParam param) { - return goodsFeign.addPackGoods(param).getData(); - } - @Override public List findAll() { return goodsFeign.findAll().getData(); @@ -48,4 +37,9 @@ public class GoodsClientFeignImpl implements GoodsClient { public GoodsDto getDetails(Long id) { return goodsFeign.getDetails(id).getData(); } + + @Override + public GoodsDto findById(Long id) { + return goodsFeign.findById(id).getData(); + } } diff --git a/service-goods-center/service-goods-center-api/src/main/java/cn/bootx/goodscenter/client/feign/GoodsFeign.java b/service-goods-center/service-goods-center-api/src/main/java/cn/bootx/goodscenter/client/feign/GoodsFeign.java index ddbbb8a..bfec078 100644 --- a/service-goods-center/service-goods-center-api/src/main/java/cn/bootx/goodscenter/client/feign/GoodsFeign.java +++ b/service-goods-center/service-goods-center-api/src/main/java/cn/bootx/goodscenter/client/feign/GoodsFeign.java @@ -3,9 +3,7 @@ package cn.bootx.goodscenter.client.feign; import cn.bootx.common.web.rest.ResResult; import cn.bootx.goodscenter.code.GoodsCenterCode; import cn.bootx.goodscenter.dto.goods.GoodsDto; -import cn.bootx.goodscenter.dto.sku.GoodsSkuDto; -import cn.bootx.goodscenter.param.goods.CreateGoodsAndSkuParam; -import cn.bootx.goodscenter.param.sku.CreateSkuParam; +import cn.bootx.goodscenter.param.goods.GoodsParam; import io.swagger.annotations.ApiOperation; import org.springframework.cloud.openfeign.FeignClient; import org.springframework.web.bind.annotation.GetMapping; @@ -23,17 +21,9 @@ import java.util.List; @FeignClient(name = GoodsCenterCode.APPLICATION_NAME,contextId = "goodsFeign",path = "/goods") public interface GoodsFeign { - @ApiOperation("添加单品") - @PostMapping("/addSingle") - ResResult addSingle(@RequestBody CreateSkuParam param); - @ApiOperation("添加商品") @PostMapping("/add") - ResResult add(@RequestBody CreateGoodsAndSkuParam param); - - @ApiOperation("添加打包商品") - @PostMapping("/addPackGoods") - ResResult addPackGoods(@RequestBody CreateGoodsAndSkuParam param); + ResResult add(@RequestBody GoodsParam param); @ApiOperation("查询全部") @GetMapping("/findAll") @@ -47,4 +37,8 @@ public interface GoodsFeign { @GetMapping("/getDetails") ResResult getDetails(@RequestParam Long id); + @ApiOperation("查询包含商品信息") + @GetMapping("/findById") + ResResult findById(@RequestParam Long id); + } diff --git a/service-goods-center/service-goods-center-api/src/main/java/cn/bootx/goodscenter/client/feign/GoodsSkuClientFeignImpl.java b/service-goods-center/service-goods-center-api/src/main/java/cn/bootx/goodscenter/client/feign/GoodsSkuClientFeignImpl.java index dcd6795..41f481b 100644 --- a/service-goods-center/service-goods-center-api/src/main/java/cn/bootx/goodscenter/client/feign/GoodsSkuClientFeignImpl.java +++ b/service-goods-center/service-goods-center-api/src/main/java/cn/bootx/goodscenter/client/feign/GoodsSkuClientFeignImpl.java @@ -2,9 +2,6 @@ package cn.bootx.goodscenter.client.feign; import cn.bootx.goodscenter.client.GoodsSkuClient; import cn.bootx.goodscenter.dto.sku.GoodsSkuDto; -import cn.bootx.goodscenter.param.sku.CreateSkuParam; -import cn.bootx.goodscenter.param.sku.GenSkuParam; -import lombok.RequiredArgsConstructor; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; import org.springframework.stereotype.Component; @@ -18,8 +15,8 @@ public class GoodsSkuClientFeignImpl implements GoodsSkuClient { private GoodsSkuFeign goodsSkuFeign; @Override - public GoodsSkuDto getById(Long id) { - return goodsSkuFeign.getById(id).getData(); + public GoodsSkuDto findById(Long id) { + return goodsSkuFeign.findById(id).getData(); } @Override @@ -27,18 +24,9 @@ public class GoodsSkuClientFeignImpl implements GoodsSkuClient { return goodsSkuFeign.findBySkuIds(skuIds).getData(); } - @Override - public List genGoodsSkuBySkuAttrs(GenSkuParam genSkuParam) { - return goodsSkuFeign.genSku(genSkuParam).getData(); - } - @Override public List findByGoodsId(Long goodsId) { return goodsSkuFeign.findByGoodsId(goodsId).getData(); } - @Override - public GoodsSkuDto add(CreateSkuParam skuParam) { - return goodsSkuFeign.add(skuParam).getData(); - } } diff --git a/service-goods-center/service-goods-center-api/src/main/java/cn/bootx/goodscenter/client/feign/GoodsSkuFeign.java b/service-goods-center/service-goods-center-api/src/main/java/cn/bootx/goodscenter/client/feign/GoodsSkuFeign.java index 8d1f825..d8e4cf2 100644 --- a/service-goods-center/service-goods-center-api/src/main/java/cn/bootx/goodscenter/client/feign/GoodsSkuFeign.java +++ b/service-goods-center/service-goods-center-api/src/main/java/cn/bootx/goodscenter/client/feign/GoodsSkuFeign.java @@ -3,13 +3,9 @@ package cn.bootx.goodscenter.client.feign; import cn.bootx.common.web.rest.ResResult; import cn.bootx.goodscenter.code.GoodsCenterCode; import cn.bootx.goodscenter.dto.sku.GoodsSkuDto; -import cn.bootx.goodscenter.param.sku.CreateSkuParam; -import cn.bootx.goodscenter.param.sku.GenSkuParam; import io.swagger.annotations.ApiOperation; import org.springframework.cloud.openfeign.FeignClient; import org.springframework.web.bind.annotation.GetMapping; -import org.springframework.web.bind.annotation.PostMapping; -import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestParam; import java.util.List; @@ -17,15 +13,11 @@ import java.util.List; @FeignClient(name = GoodsCenterCode.APPLICATION_NAME,contextId = "goodsSkuFeign",path = "/sku") interface GoodsSkuFeign { - @ApiOperation("根据商品 SKU 属性生成其 SKU 预览") - @PostMapping("/genSku") - ResResult> genSku(@RequestBody GenSkuParam genSkuParam); - @ApiOperation("获取sku") - @GetMapping("/get") - ResResult getById(@RequestParam Long id); + @GetMapping("/findById") + ResResult findById(@RequestParam Long id); - @ApiOperation("获取sku") + @ApiOperation("批量获取sku") @GetMapping("/findBySkuIds") ResResult> findBySkuIds(@RequestParam List skuIds); @@ -33,7 +25,4 @@ interface GoodsSkuFeign { @GetMapping("/findByGoodsId") ResResult> findByGoodsId(@RequestParam Long goodsId); - @ApiOperation("添加商品sku") - @PostMapping("/add") - ResResult add(@RequestBody CreateSkuParam skuParam); } diff --git a/service-goods-center/service-goods-center-api/src/main/java/cn/bootx/goodscenter/client/feign/InventoryClientFeignImpl.java b/service-goods-center/service-goods-center-api/src/main/java/cn/bootx/goodscenter/client/feign/InventoryClientFeignImpl.java index a9cd67d..c1269bf 100644 --- a/service-goods-center/service-goods-center-api/src/main/java/cn/bootx/goodscenter/client/feign/InventoryClientFeignImpl.java +++ b/service-goods-center/service-goods-center-api/src/main/java/cn/bootx/goodscenter/client/feign/InventoryClientFeignImpl.java @@ -2,12 +2,14 @@ package cn.bootx.goodscenter.client.feign; import cn.bootx.goodscenter.client.InventoryClient; import cn.bootx.goodscenter.dto.inventory.LockInventoryDto; +import lombok.RequiredArgsConstructor; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; import org.springframework.stereotype.Component; @Component @ConditionalOnMissingBean(InventoryClient.class) +@RequiredArgsConstructor public class InventoryClientFeignImpl implements InventoryClient { @Autowired(required = false) private InventoryFeign inventoryFeign; diff --git a/service-goods-center/service-goods-center-api/src/main/java/cn/bootx/goodscenter/dto/category/CategoryAttrDefDto.java b/service-goods-center/service-goods-center-api/src/main/java/cn/bootx/goodscenter/dto/category/CategoryAttrDefDto.java deleted file mode 100644 index ca967a1..0000000 --- a/service-goods-center/service-goods-center-api/src/main/java/cn/bootx/goodscenter/dto/category/CategoryAttrDefDto.java +++ /dev/null @@ -1,68 +0,0 @@ -package cn.bootx.goodscenter.dto.category; - -import io.swagger.annotations.ApiModel; -import io.swagger.annotations.ApiModelProperty; -import lombok.Data; -import lombok.experimental.Accessors; - -import java.io.Serializable; - -/** -* 类目属性定义 Dto -* @author xxm -* @date 2020/11/21 -*/ -@Data -@Accessors(chain = true) -@ApiModel(value = "类目属性定义DTO") -public class CategoryAttrDefDto implements Serializable { - private static final long serialVersionUID = -3834910289320099208L; - - @ApiModelProperty("主键") - private Long id; - @ApiModelProperty("类目id") - private Long cid; - @ApiModelProperty("类目名称(前端展示使用)") - private String cname; - @ApiModelProperty("属性名称") - private String name; - @ApiModelProperty("属性类型(类型之枚举:1;类型之整数:2;类型之小数:3;类型之日期:5;类型之时间:" + - "6;类型之字符串:7;类型之数据字典:101;类型之城市:102;类型之JSON:110;)") - private int type; - - @ApiModelProperty("目标类型 sku/spu") - private int targetType; - - @ApiModelProperty("是否显示属性") - private boolean isDisplay; - @ApiModelProperty("是否搜索属性") - private boolean isSearch; - @ApiModelProperty("是否必须") - private boolean isRequired; - - @ApiModelProperty("数据字典id") - private Long dictId; - @ApiModelProperty("是否多选, 默认否") - private boolean isMultiple; - @ApiModelProperty("序号,默认0") - private int ordinal; - @ApiModelProperty("状态(可用:1,不可用:0),默认1") - private int state; - @ApiModelProperty("字段名称") - private String fieldName; - @ApiModelProperty("字段长度") - private Integer fieldLength; - @ApiModelProperty("小数点长度") - private Integer fieldPointLength; - @ApiModelProperty("字段类型(String,Date,Integer,Double,byte[],Boolean,BigDecimal,Long, Text)") - private String fieldType; - @ApiModelProperty("描述") - private String description; - @ApiModelProperty("字段默认值") - private String fieldDefault; - @ApiModelProperty("字段查询时的比较方式(equals,like,greatThan,LessThan)") - private String queryCompareType; - @ApiModelProperty("主键") - private Boolean isKey; - -} \ No newline at end of file diff --git a/service-goods-center/service-goods-center-api/src/main/java/cn/bootx/goodscenter/dto/goods/GoodsAttrDto.java b/service-goods-center/service-goods-center-api/src/main/java/cn/bootx/goodscenter/dto/goods/GoodsAttrDto.java deleted file mode 100644 index 0881a4b..0000000 --- a/service-goods-center/service-goods-center-api/src/main/java/cn/bootx/goodscenter/dto/goods/GoodsAttrDto.java +++ /dev/null @@ -1,32 +0,0 @@ -package cn.bootx.goodscenter.dto.goods; - -import io.swagger.annotations.ApiModel; -import io.swagger.annotations.ApiModelProperty; -import lombok.Data; -import lombok.experimental.Accessors; - -import java.io.Serializable; - -/** -* @author xxm -* @date 2020/11/20 -*/ -@Data -@Accessors(chain = true) -@ApiModel(value = "商品属性DTO") -public class GoodsAttrDto implements Serializable { - - private static final long serialVersionUID = -1437003529670711609L; - - @ApiModelProperty("所属商品 id") - private Long goodsId; - - @ApiModelProperty(value = "属性定义 id", required = true) - private Long attrDefId; - - @ApiModelProperty("属性值") - private String attrValue; - - @ApiModelProperty("显示用的属性值") - private String attrValueDisplay; -} \ No newline at end of file diff --git a/service-goods-center/service-goods-center-api/src/main/java/cn/bootx/goodscenter/dto/goods/GoodsDto.java b/service-goods-center/service-goods-center-api/src/main/java/cn/bootx/goodscenter/dto/goods/GoodsDto.java index a321fd2..6898a57 100644 --- a/service-goods-center/service-goods-center-api/src/main/java/cn/bootx/goodscenter/dto/goods/GoodsDto.java +++ b/service-goods-center/service-goods-center-api/src/main/java/cn/bootx/goodscenter/dto/goods/GoodsDto.java @@ -1,37 +1,33 @@ package cn.bootx.goodscenter.dto.goods; +import cn.bootx.common.web.rest.dto.BaseDto; import cn.bootx.goodscenter.dto.sku.GoodsSkuDto; import io.swagger.annotations.ApiModel; import io.swagger.annotations.ApiModelProperty; import lombok.Data; +import lombok.EqualsAndHashCode; import lombok.experimental.Accessors; import java.io.Serializable; -import java.math.BigDecimal; import java.util.List; /** * @author xxm * @date 2020/11/20 */ +@EqualsAndHashCode(callSuper = true) @Data @Accessors(chain = true) @ApiModel(value = "商品DTO") -public class GoodsDto implements Serializable { +public class GoodsDto extends BaseDto implements Serializable { private static final long serialVersionUID = 9191023721658520976L; - @ApiModelProperty(value = "主键") - private Long id; - @ApiModelProperty(value = "所属类目id", required = true) private Long cid; @ApiModelProperty(value = "所属类目名称(前端展示使用)") private String cname; - @ApiModelProperty(value = "外部编码", required = true) - private String code; - @ApiModelProperty(value = "商品名称", required = true) private String name; @@ -44,41 +40,12 @@ public class GoodsDto implements Serializable { /** 商品介绍主图 多个图片逗号分隔 */ private String mainUri; - /** 显示上限价格 */ - private BigDecimal displayUpperPrice; - - /** 显示下限价格 */ - private BigDecimal displayLowerPrice; - - @ApiModelProperty(value = "是否打包品") - private boolean packing; - @ApiModelProperty("附加信息") private String addition; @ApiModelProperty("状态(1:可用,0:不可用)") private int state; - @ApiModelProperty(value = "生成此商品 SKU 的所有 SKU 属性定义的 id 拼接串") - private String attrDefIds; - @ApiModelProperty(value = - "生成此商品 SKU 的所有 SKU 属性定义的 id 数组(前端展示使用,数组元素顺序与 attrValueList、attrValueDisplayList 保持一致)") - private List attrDefIdList; - @ApiModelProperty(value = "生成此商品 SKU 的所有 SKU 属性值的 拼接串") - private String attrValues; - @ApiModelProperty(value = "生成此商品 SKU 的所有 SKU 属性值的 id 数组(前端展示使用)") - private List attrValueList; - @ApiModelProperty(value = "生成此商品 SKU 的所有 SKU 属性定义的显示值拼接串") - private String attrValueDisplays; - @ApiModelProperty(value = "生成此商品 SKU 的所有 SKU 属性定义的显示值数组(前端展示使用)") - private List attrValueDisplayList; - - @ApiModelProperty("商品属性列表") - private List attrList; - - @ApiModelProperty("价格表类型id") - private Long priceTypeId; - @ApiModelProperty("关联sku") private List skus; diff --git a/service-goods-center/service-goods-center-api/src/main/java/cn/bootx/goodscenter/dto/goods/GoodsSpecDto.java b/service-goods-center/service-goods-center-api/src/main/java/cn/bootx/goodscenter/dto/goods/GoodsSpecDto.java deleted file mode 100644 index 1509a6b..0000000 --- a/service-goods-center/service-goods-center-api/src/main/java/cn/bootx/goodscenter/dto/goods/GoodsSpecDto.java +++ /dev/null @@ -1,34 +0,0 @@ -package cn.bootx.goodscenter.dto.goods; - -import io.swagger.annotations.ApiModel; -import lombok.Data; -import lombok.experimental.Accessors; - -import java.io.Serializable; - -/** -* -* @author xxm -* @date 2021/2/23 -*/ -@Data -@Accessors(chain = true) -@ApiModel("商品销售属性") -public class GoodsSpecDto implements Serializable { - private static final long serialVersionUID = -5420725057377793726L; - - /** 商品id */ - private Long goodsId; - - /** 类目规格属性定义(sku属性) */ - private Long attrDefId; - - /** 排序序号 */ - private Integer ordinal; - - /** 属性值 */ - private String attrValues; - - /** 属性显示值 */ - private String attrValueDisplays; -} diff --git a/service-goods-center/service-goods-center-api/src/main/java/cn/bootx/goodscenter/dto/packing/GoodsPackingDto.java b/service-goods-center/service-goods-center-api/src/main/java/cn/bootx/goodscenter/dto/packing/GoodsPackingDto.java deleted file mode 100644 index 626b646..0000000 --- a/service-goods-center/service-goods-center-api/src/main/java/cn/bootx/goodscenter/dto/packing/GoodsPackingDto.java +++ /dev/null @@ -1,28 +0,0 @@ -package cn.bootx.goodscenter.dto.packing; - -import io.swagger.annotations.ApiModel; -import io.swagger.annotations.ApiModelProperty; -import lombok.Data; -import lombok.experimental.Accessors; - -import javax.validation.constraints.NotNull; -import java.io.Serializable; - -/** -* @author xxm -* @date 2020/11/20 -*/ -@Data -@Accessors(chain = true) -@ApiModel(value = "商品打包关系DTO") -public class GoodsPackingDto implements Serializable { - - private static final long serialVersionUID = 7398760045437755829L; - @ApiModelProperty(name = "goodsId", value = "打包品 id", required = true) - private Long goodsId; - @ApiModelProperty(name = "packedGoodsId", value = "被打包品 id", required = true) - private Long packedGoodsId; - @ApiModelProperty(name = "packedGoodsName", value = "被打包品名称(前端展示使用)") - private String packedGoodsName; - -} diff --git a/service-goods-center/service-goods-center-api/src/main/java/cn/bootx/goodscenter/dto/packing/GoodsSkuPackingDto.java b/service-goods-center/service-goods-center-api/src/main/java/cn/bootx/goodscenter/dto/packing/GoodsSkuPackingDto.java deleted file mode 100644 index 1d6e075..0000000 --- a/service-goods-center/service-goods-center-api/src/main/java/cn/bootx/goodscenter/dto/packing/GoodsSkuPackingDto.java +++ /dev/null @@ -1,36 +0,0 @@ -package cn.bootx.goodscenter.dto.packing; - -import io.swagger.annotations.ApiModel; -import io.swagger.annotations.ApiModelProperty; -import lombok.Data; -import lombok.experimental.Accessors; - -import java.io.Serializable; - -/** -* 打包品SKU关联关系 -* @author xxm -* @date 2020/11/22 -*/ -@Data -@Accessors(chain = true) -@ApiModel(value = "打包品SKU关联关系DTO") -public class GoodsSkuPackingDto implements Serializable { - - private static final long serialVersionUID = 5348220238706398806L; - @ApiModelProperty("主键") - private Long id; - - @ApiModelProperty(name = "goodsId", value = "打包品 id", required = true) - private Long goodsId; - - @ApiModelProperty(name = "goodsSkuId", value = "打包品SKU id", required = true) - private Long goodsSkuId; - - @ApiModelProperty(name = "packedGoodsId", value = "被打包品 id", required = true) - private Long packedGoodsId; - - @ApiModelProperty(name = "packedSkuId", value = "被打包品SKU id", required = true) - private Long packedSkuId; - -} diff --git a/service-goods-center/service-goods-center-api/src/main/java/cn/bootx/goodscenter/dto/sku/GoodsSkuAttrDto.java b/service-goods-center/service-goods-center-api/src/main/java/cn/bootx/goodscenter/dto/sku/GoodsSkuAttrDto.java deleted file mode 100644 index 04cfc0c..0000000 --- a/service-goods-center/service-goods-center-api/src/main/java/cn/bootx/goodscenter/dto/sku/GoodsSkuAttrDto.java +++ /dev/null @@ -1,29 +0,0 @@ -package cn.bootx.goodscenter.dto.sku; - -import io.swagger.annotations.ApiModel; -import io.swagger.annotations.ApiModelProperty; -import lombok.Data; -import lombok.experimental.Accessors; - -import java.io.Serializable; - -/** -* @author xxm -* @date 2020/11/21 -*/ -@Data -@Accessors(chain = true) -@ApiModel(value = "商品 SKU 属性DTO") -public class GoodsSkuAttrDto implements Serializable { - - private static final long serialVersionUID = 8050952891407800854L; - - @ApiModelProperty(value = "属性定义 id", required = true) - private Long attrDefId; - @ApiModelProperty(value = "商品 SKU id") - private Long skuId; - @ApiModelProperty(value = "属性值") - private String attrValue; - @ApiModelProperty(value = "显示用的属性值") - private String attrValueDisplays; -} diff --git a/service-goods-center/service-goods-center-api/src/main/java/cn/bootx/goodscenter/dto/sku/GoodsSkuDto.java b/service-goods-center/service-goods-center-api/src/main/java/cn/bootx/goodscenter/dto/sku/GoodsSkuDto.java index 0ee9af6..025953d 100644 --- a/service-goods-center/service-goods-center-api/src/main/java/cn/bootx/goodscenter/dto/sku/GoodsSkuDto.java +++ b/service-goods-center/service-goods-center-api/src/main/java/cn/bootx/goodscenter/dto/sku/GoodsSkuDto.java @@ -1,65 +1,42 @@ package cn.bootx.goodscenter.dto.sku; -import cn.hutool.core.util.StrUtil; +import cn.bootx.common.web.rest.dto.BaseDto; import io.swagger.annotations.ApiModel; import io.swagger.annotations.ApiModelProperty; import lombok.Data; +import lombok.EqualsAndHashCode; import lombok.experimental.Accessors; import java.io.Serializable; import java.math.BigDecimal; -import java.time.LocalDateTime; -import java.util.ArrayList; -import java.util.List; -import java.util.Map; /** * 商品SKU * @author xxm * @date 2020/11/19 */ +@EqualsAndHashCode(callSuper = true) @Data @Accessors(chain = true) @ApiModel(value = "商品SKU DTO") -public class GoodsSkuDto implements Serializable { +public class GoodsSkuDto extends BaseDto implements Serializable { private static final long serialVersionUID = 9214661437061650242L; @ApiModelProperty("主键") private Long id; - @ApiModelProperty(value = "所属类目id", required = true) + @ApiModelProperty(value = "所属类目id") private Long cid; - @ApiModelProperty(value = "所属商品id", required = true) + @ApiModelProperty(value = "所属商品id") private Long goodsId; - @ApiModelProperty(value = "商户id", required = true) - private Long shopId; - @ApiModelProperty(value = "外部编码") - private String code; @ApiModelProperty(value = "SKU名称", required = true) private String name; @ApiModelProperty(value = "SKU描述") private String description; @ApiModelProperty(value = "附加信息") private String addition; - @ApiModelProperty(value = "存储事务id") - private Long businessId; - - @ApiModelProperty(value = "生成此商品 SKU 的所有 SKU 属性定义的 id 拼接串") - private String attrDefIds; - @ApiModelProperty(value = - "生成此商品 SKU 的所有 SKU 属性定义的 id 数组(前端展示使用,数组元素顺序与 attrValueList、attrValueDisplayList 保持一致)") - private List attrDefIdList; - @ApiModelProperty(value = "生成此商品 SKU 的所有 SKU 属性值的 拼接串") - private String attrValues; - @ApiModelProperty(value = "生成此商品 SKU 的所有 SKU 属性值的 id 数组(前端展示使用)") - private List attrValueList; - @ApiModelProperty(value = "生成此商品 SKU 的所有 SKU 属性定义的显示值拼接串") - private String attrValueDisplays; - @ApiModelProperty(value = "生成此商品 SKU 的所有 SKU 属性定义的显示值数组(前端展示使用)") - private List attrValueDisplayList; - - @ApiModelProperty("属性列表") - private List attrList; + @ApiModelProperty(value = "无限库存") + private boolean unlimited; @ApiModelProperty(value = "库存总量") private Integer capacity; @ApiModelProperty(value = "预占库存") @@ -69,54 +46,8 @@ public class GoodsSkuDto implements Serializable { @ApiModelProperty(value = "可用库存") private Integer available; - @ApiModelProperty(value = "上架时间") - private LocalDateTime saleOnTime; - @ApiModelProperty(value = "下架时间") - private LocalDateTime saleOffTime; - - private boolean unlimited; @ApiModelProperty(value = "售价") private BigDecimal price; - @ApiModelProperty(value = "状态(0:准备,1:销售中,2:停售,3:失效,9:召回),默认0") + @ApiModelProperty(value = "状态") private int state; - @ApiModelProperty(value = "商品code") - private String goodsCode; - - @ApiModelProperty(value = "价格表") - private Map priceTable; - - @ApiModelProperty(value = "价格类型ID") - private Long priceTypeId; - - public List getAttrDefIdList() { - if (attrDefIdList == null) { - attrDefIdList = splitAppendList(attrDefIds); - } - return attrDefIdList; - } - - public List getAttrValueList() { - if (attrValueList == null) { - attrValueList = splitAppendList(attrValues); - } - return attrValueList; - } - - - public List getAttrValueDisplayList() { - if (attrValueDisplayList == null) { - attrValueDisplayList = splitAppendList(attrValueDisplays); - } - return attrValueDisplayList; - } - - /** - * 将拼接的字符串拆分成数组形式 - */ - public static List splitAppendList(String appendString) { - if (StrUtil.isEmpty(appendString)) { - return new ArrayList<>(0); - } - return StrUtil.split(appendString,','); - } } \ No newline at end of file diff --git a/service-goods-center/service-goods-center-api/src/main/java/cn/bootx/goodscenter/param/goods/CreateGoodsParam.java b/service-goods-center/service-goods-center-api/src/main/java/cn/bootx/goodscenter/param/goods/GoodsParam.java similarity index 68% rename from service-goods-center/service-goods-center-api/src/main/java/cn/bootx/goodscenter/param/goods/CreateGoodsParam.java rename to service-goods-center/service-goods-center-api/src/main/java/cn/bootx/goodscenter/param/goods/GoodsParam.java index f93bbdf..286bfa9 100644 --- a/service-goods-center/service-goods-center-api/src/main/java/cn/bootx/goodscenter/param/goods/CreateGoodsParam.java +++ b/service-goods-center/service-goods-center-api/src/main/java/cn/bootx/goodscenter/param/goods/GoodsParam.java @@ -1,12 +1,11 @@ package cn.bootx.goodscenter.param.goods; -import cn.bootx.goodscenter.dto.goods.GoodsAttrDto; import io.swagger.annotations.ApiModel; import io.swagger.annotations.ApiModelProperty; import lombok.Data; import lombok.experimental.Accessors; -import java.util.List; +import java.io.Serializable; /** * @author xxm @@ -15,7 +14,11 @@ import java.util.List; @Data @Accessors(chain = true) @ApiModel("商品创建参数") -public class CreateGoodsParam { +public class GoodsParam implements Serializable { + private static final long serialVersionUID = -8666559882709167480L; + + @ApiModelProperty("主键") + private Long id; @ApiModelProperty(value = "所属类目id", required = true) private Long cid; @@ -23,21 +26,12 @@ public class CreateGoodsParam { @ApiModelProperty(value = "所属类目名称(前端展示使用)") private String cname; - @ApiModelProperty(value = "外部编码", required = true) - private String code; - @ApiModelProperty(value = "商品名称", required = true) private String name; @ApiModelProperty(value = "商品描述") private String description; - @ApiModelProperty(value = "是否打包品") - private boolean packing; - - @ApiModelProperty("商品属性列表") - private List attrList; - @ApiModelProperty("附加信息") private String addition; diff --git a/service-goods-center/service-goods-center-api/src/main/java/cn/bootx/goodscenter/param/goods/UpdateGoodsAndSkuParam.java b/service-goods-center/service-goods-center-api/src/main/java/cn/bootx/goodscenter/param/goods/UpdateGoodsAndSkuParam.java deleted file mode 100644 index 0e0ecf3..0000000 --- a/service-goods-center/service-goods-center-api/src/main/java/cn/bootx/goodscenter/param/goods/UpdateGoodsAndSkuParam.java +++ /dev/null @@ -1,36 +0,0 @@ -package cn.bootx.goodscenter.param.goods; - -import cn.bootx.goodscenter.param.sku.CreateSkuParam; -import cn.bootx.goodscenter.param.sku.UpdateSkuParam; -import io.swagger.annotations.ApiModel; -import io.swagger.annotations.ApiModelProperty; -import lombok.Data; -import lombok.experimental.Accessors; - -import java.io.Serializable; -import java.util.List; - -/** -* @author xxm -* @date 2021/2/21 -*/ -@Data -@Accessors(chain = true) -@ApiModel("商品更新参数") -public class UpdateGoodsAndSkuParam implements Serializable { - private static final long serialVersionUID = 7240095798154822572L; - - @ApiModelProperty("商品") - private UpdateGoodsParam goodsParam; - - @ApiModelProperty("删除的sku") - private List deleteIds; - - @ApiModelProperty("更新的sku") - private List updateSkuParams; - - @ApiModelProperty("新增的sku") - private List createSkuParams; - - -} diff --git a/service-goods-center/service-goods-center-api/src/main/java/cn/bootx/goodscenter/param/goods/UpdateGoodsParam.java b/service-goods-center/service-goods-center-api/src/main/java/cn/bootx/goodscenter/param/goods/UpdateGoodsParam.java deleted file mode 100644 index 964d5c4..0000000 --- a/service-goods-center/service-goods-center-api/src/main/java/cn/bootx/goodscenter/param/goods/UpdateGoodsParam.java +++ /dev/null @@ -1,50 +0,0 @@ -package cn.bootx.goodscenter.param.goods; - -import cn.bootx.goodscenter.dto.goods.GoodsAttrDto; -import io.swagger.annotations.ApiModel; -import io.swagger.annotations.ApiModelProperty; -import lombok.Data; -import lombok.experimental.Accessors; - -import java.util.List; - -/** -* @author xxm -* @date 2021/2/21 -*/ -@Data -@Accessors(chain = true) -@ApiModel("商品更新参数") -public class UpdateGoodsParam { - - @ApiModelProperty("主键") - private Long id; - - @ApiModelProperty(value = "所属类目id", required = true) - private Long cid; - - @ApiModelProperty(value = "所属类目名称(前端展示使用)") - private String cname; - - @ApiModelProperty(value = "外部编码", required = true) - private String code; - - @ApiModelProperty(value = "商品名称", required = true) - private String name; - - @ApiModelProperty(value = "商品描述") - private String description; - - @ApiModelProperty(value = "是否打包品") - private boolean packing; - - @ApiModelProperty("商品属性列表") - private List attrList; - - @ApiModelProperty("附加信息") - private String addition; - - @ApiModelProperty("价格表类型id") - private Long priceTypeId; - -} diff --git a/service-goods-center/service-goods-center-api/src/main/java/cn/bootx/goodscenter/param/packing/GoodsPackingParam.java b/service-goods-center/service-goods-center-api/src/main/java/cn/bootx/goodscenter/param/packing/GoodsPackingParam.java deleted file mode 100644 index 401e54d..0000000 --- a/service-goods-center/service-goods-center-api/src/main/java/cn/bootx/goodscenter/param/packing/GoodsPackingParam.java +++ /dev/null @@ -1,30 +0,0 @@ -package cn.bootx.goodscenter.param.packing; - -import io.swagger.annotations.ApiModel; -import io.swagger.annotations.ApiModelProperty; -import lombok.Data; -import lombok.experimental.Accessors; - -import javax.validation.constraints.NotNull; -import java.util.List; - -/** -* @author xxm -* @date 2020/11/23 -*/ -@Data -@Accessors(chain = true) -@ApiModel(value = "商品打包品设置") -public class GoodsPackingParam { - - @ApiModelProperty(name = "goodsId", value = "打包品 id", required = true) - @NotNull(message = "goodsId不能为null") - private Long goodsId; - @ApiModelProperty(name = "cid", value = "商品类目 id", required = true) - @NotNull(message = "cid不能为null") - private Long cid; - @ApiModelProperty(name = "ids", value = "被打包品 id 列表", required = true) - @NotNull(message = "ids不能为null") - private List ids; - -} diff --git a/service-goods-center/service-goods-center-api/src/main/java/cn/bootx/goodscenter/param/sku/GenSkuAttrParam.java b/service-goods-center/service-goods-center-api/src/main/java/cn/bootx/goodscenter/param/sku/GenSkuAttrParam.java deleted file mode 100644 index f3cb799..0000000 --- a/service-goods-center/service-goods-center-api/src/main/java/cn/bootx/goodscenter/param/sku/GenSkuAttrParam.java +++ /dev/null @@ -1,28 +0,0 @@ -package cn.bootx.goodscenter.param.sku; - -import io.swagger.annotations.ApiModel; -import io.swagger.annotations.ApiModelProperty; -import lombok.Data; -import lombok.experimental.Accessors; - -import java.util.List; - -/** -* @author xxm -* @date 2021/2/5 -*/ -@Data -@Accessors(chain = true) -@ApiModel("生成sku属性定义") -public class GenSkuAttrParam { - - @ApiModelProperty(value = "属性定义 id", required = true) - private Long attrDefId; - - @ApiModelProperty(value = "属性值列表,size需要与 attrValueListDisplay 一致", required = true) - private List attrValues; - - @ApiModelProperty(value = "显示用属性值列表,size需要与 attrValueList 一致", required = true) - private List attrValueDisplays; - -} diff --git a/service-goods-center/service-goods-center-api/src/main/java/cn/bootx/goodscenter/param/sku/CreateSkuParam.java b/service-goods-center/service-goods-center-api/src/main/java/cn/bootx/goodscenter/param/sku/SkuParam.java similarity index 46% rename from service-goods-center/service-goods-center-api/src/main/java/cn/bootx/goodscenter/param/sku/CreateSkuParam.java rename to service-goods-center/service-goods-center-api/src/main/java/cn/bootx/goodscenter/param/sku/SkuParam.java index 8ff7ee0..7ea3e07 100644 --- a/service-goods-center/service-goods-center-api/src/main/java/cn/bootx/goodscenter/param/sku/CreateSkuParam.java +++ b/service-goods-center/service-goods-center-api/src/main/java/cn/bootx/goodscenter/param/sku/SkuParam.java @@ -5,30 +5,34 @@ import io.swagger.annotations.ApiModelProperty; import lombok.Data; import lombok.experimental.Accessors; +import java.io.Serializable; import java.math.BigDecimal; -import java.util.List; -/** +/** * @author xxm -* @date 2021/2/2 +* @date 2021/7/23 */ @Data @Accessors(chain = true) -@ApiModel("创建sku参数") -public class CreateSkuParam { +@ApiModel("sku添加") +public class SkuParam implements Serializable { + private static final long serialVersionUID = -8038996282288514501L; - @ApiModelProperty(value = "所属类目id", required = true) + @ApiModelProperty(value = "主键") + private Long id; + + @ApiModelProperty(value = "所属类目id") private Long cid; - @ApiModelProperty(value = "所属商品id", required = true) + @ApiModelProperty(value = "外部编码") + private String outNo; + + @ApiModelProperty(value = "所属商品id") private Long goodsId; - @ApiModelProperty(value = "SKU名称", required = true) + @ApiModelProperty(value = "SKU名称") private String name; - @ApiModelProperty(value = "外部编码") - private String code; - @ApiModelProperty(value = "SKU描述") private String description; @@ -47,17 +51,4 @@ public class CreateSkuParam { @ApiModelProperty(value = "售价") private BigDecimal price; - @ApiModelProperty(value = - "生成此商品 SKU 的所有 SKU 属性定义的 id 数组(前端展示使用,数组元素顺序与 attrValueList、attrValueDisplayList 保持一致)") - private List attrDefIdList; - - @ApiModelProperty(value = "生成此商品 SKU 的所有 SKU 属性值组(前端展示使用)") - private List attrValueList; - - @ApiModelProperty(value = "生成此商品 SKU 的所有 SKU 显示值数组(前端展示使用)") - private List attrValueDisplayList; - - @ApiModelProperty(value = "被打包品集合") - private List packedSkuIds; - } diff --git a/service-goods-center/service-goods-center-api/src/main/java/cn/bootx/goodscenter/param/sku/UpdateSkuParam.java b/service-goods-center/service-goods-center-api/src/main/java/cn/bootx/goodscenter/param/sku/UpdateSkuParam.java deleted file mode 100644 index 1f4fae6..0000000 --- a/service-goods-center/service-goods-center-api/src/main/java/cn/bootx/goodscenter/param/sku/UpdateSkuParam.java +++ /dev/null @@ -1,66 +0,0 @@ -package cn.bootx.goodscenter.param.sku; - -import io.swagger.annotations.ApiModel; -import io.swagger.annotations.ApiModelProperty; -import lombok.Data; -import lombok.experimental.Accessors; - -import java.math.BigDecimal; -import java.util.List; - -/** -* @author xxm -* @date 2021/2/2 -*/ -@Data -@Accessors(chain = true) -@ApiModel("更新sku参数") -public class UpdateSkuParam { - - @ApiModelProperty(value = "主键", required = true) - private Long id; - - @ApiModelProperty(value = "所属类目id", required = true) - private Long cid; - - @ApiModelProperty(value = "所属商品id", required = true) - private Long goodsId; - - @ApiModelProperty(value = "SKU名称", required = true) - private String name; - - @ApiModelProperty(value = "外部编码") - private String code; - - @ApiModelProperty(value = "SKU描述") - private String description; - - @ApiModelProperty(value = "附加信息") - private String addition; - - @ApiModelProperty("是否打包品") - private boolean packing; - - @ApiModelProperty("是否无限库存") - private boolean unlimited; - - @ApiModelProperty("初始库存") - private Integer capacity; - - @ApiModelProperty(value = "售价") - private BigDecimal price; - - @ApiModelProperty(value = - "生成此商品 SKU 的所有 SKU 属性定义的 id 数组(前端展示使用,数组元素顺序与 attrValueList、attrValueDisplayList 保持一致)") - private List attrDefIdList; - - @ApiModelProperty(value = "生成此商品 SKU 的所有 SKU 属性值的 id 数组(前端展示使用)") - private List attrValueList; - - @ApiModelProperty(value = "生成此商品 SKU 的所有 SKU 属性定义的显示值数组(前端展示使用)") - private List attrValueDisplayList; - - @ApiModelProperty(value = "被打包品集合") - private List packedSkuIds; - -} diff --git a/service-goods-center/service-goods-center-api/src/main/resources/META-INF/spring.factories b/service-goods-center/service-goods-center-api/src/main/resources/META-INF/spring.factories index 873c416..7673a46 100644 --- a/service-goods-center/service-goods-center-api/src/main/resources/META-INF/spring.factories +++ b/service-goods-center/service-goods-center-api/src/main/resources/META-INF/spring.factories @@ -1,7 +1,5 @@ # 自动注册 feign 的 client 实现 org.springframework.boot.autoconfigure.EnableAutoConfiguration=\ - cn.bootx.goodscenter.client.feign.CategoryAttrDefClientFeignImpl,\ - cn.bootx.goodscenter.client.feign.CategoryClientFeignImpl,\ - cn.bootx.goodscenter.client.feign.GoodsClientFeignImpl,\ cn.bootx.goodscenter.client.feign.GoodsSkuClientFeignImpl,\ + cn.bootx.goodscenter.client.feign.GoodsClientFeignImpl,\ cn.bootx.goodscenter.client.feign.InventoryClientFeignImpl \ No newline at end of file diff --git a/service-goods-center/service-goods-center-impl/src/main/java/cn/bootx/goodscenter/controller/CategoryAttrDefController.java b/service-goods-center/service-goods-center-impl/src/main/java/cn/bootx/goodscenter/controller/CategoryAttrDefController.java deleted file mode 100644 index fce43d1..0000000 --- a/service-goods-center/service-goods-center-impl/src/main/java/cn/bootx/goodscenter/controller/CategoryAttrDefController.java +++ /dev/null @@ -1,44 +0,0 @@ -package cn.bootx.goodscenter.controller; - -import cn.bootx.common.web.rest.Res; -import cn.bootx.common.web.rest.ResResult; -import cn.bootx.goodscenter.core.attributes.service.CategoryAttrDefService; -import cn.bootx.goodscenter.dto.category.CategoryAttrDefDto; -import io.swagger.annotations.Api; -import io.swagger.annotations.ApiOperation; -import lombok.AllArgsConstructor; -import org.springframework.web.bind.annotation.*; - -import java.util.List; - -@Api(tags = "类目定义") -@RestController -@RequestMapping("/category/attrDef") -@AllArgsConstructor -public class CategoryAttrDefController { - private final CategoryAttrDefService categoryAttrDefService; - - @ApiOperation("添加") - @PostMapping("/add") - public ResResult add(@RequestBody CategoryAttrDefDto dto){ - return Res.ok(categoryAttrDefService.addAttrDef(dto)); - } - - @ApiOperation("获取单条") - @GetMapping("/get") - public ResResult get(Long id){ - return Res.ok(categoryAttrDefService.getById(id)); - } - - @ApiOperation("查询全部") - @GetMapping("/findAll") - public ResResult> findAll(){ - return Res.ok(categoryAttrDefService.findAll()); - } - - @ApiOperation("按类目查询") - @GetMapping("/findByCategory") - public ResResult> findByCategory(Long cid){ - return Res.ok(categoryAttrDefService.findByCategory(cid)); - } -} diff --git a/service-goods-center/service-goods-center-impl/src/main/java/cn/bootx/goodscenter/controller/CategoryController.java b/service-goods-center/service-goods-center-impl/src/main/java/cn/bootx/goodscenter/controller/CategoryController.java index 6b2e816..9b50c89 100644 --- a/service-goods-center/service-goods-center-impl/src/main/java/cn/bootx/goodscenter/controller/CategoryController.java +++ b/service-goods-center/service-goods-center-impl/src/main/java/cn/bootx/goodscenter/controller/CategoryController.java @@ -3,10 +3,10 @@ package cn.bootx.goodscenter.controller; import cn.bootx.common.web.rest.Res; import cn.bootx.common.web.rest.ResResult; import cn.bootx.common.web.rest.param.SingleIdParam; +import cn.bootx.goodscenter.code.GoodsCenterErrorCode; import cn.bootx.goodscenter.core.category.service.CategoryService; import cn.bootx.goodscenter.dto.category.CategoryDto; import cn.bootx.goodscenter.dto.category.CategoryTreeNode; -import cn.bootx.goodscenter.code.GoodsCenterErrorCode; import io.swagger.annotations.*; import lombok.AllArgsConstructor; import org.springframework.cloud.openfeign.FeignClient; diff --git a/service-goods-center/service-goods-center-impl/src/main/java/cn/bootx/goodscenter/controller/GoodsController.java b/service-goods-center/service-goods-center-impl/src/main/java/cn/bootx/goodscenter/controller/GoodsController.java index 8f26d86..f4ff604 100644 --- a/service-goods-center/service-goods-center-impl/src/main/java/cn/bootx/goodscenter/controller/GoodsController.java +++ b/service-goods-center/service-goods-center-impl/src/main/java/cn/bootx/goodscenter/controller/GoodsController.java @@ -2,12 +2,9 @@ package cn.bootx.goodscenter.controller; import cn.bootx.common.web.rest.Res; import cn.bootx.common.web.rest.ResResult; -import cn.bootx.goodscenter.core.goods.service.GoodsAddService; import cn.bootx.goodscenter.core.goods.service.GoodsService; import cn.bootx.goodscenter.dto.goods.GoodsDto; -import cn.bootx.goodscenter.dto.sku.GoodsSkuDto; -import cn.bootx.goodscenter.param.goods.CreateGoodsAndSkuParam; -import cn.bootx.goodscenter.param.sku.CreateSkuParam; +import cn.bootx.goodscenter.param.goods.GoodsParam; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; import lombok.AllArgsConstructor; @@ -21,24 +18,11 @@ import java.util.List; @AllArgsConstructor public class GoodsController{ private final GoodsService goodsService; - private final GoodsAddService createGoodsService; - - @ApiOperation("添加单品") - @PostMapping("/addSingle") - public ResResult addSingle(@RequestBody CreateSkuParam param){ - return Res.ok(createGoodsService.addSingle(param)); - } @ApiOperation("添加商品") @PostMapping("/add") - public ResResult add(@RequestBody CreateGoodsAndSkuParam param){ - return Res.ok(createGoodsService.addGoodsAndSku(param)); - } - - @ApiOperation("添加打包商品") - @PostMapping("/addPackGoods") - public ResResult addPackGoods(@RequestBody CreateGoodsAndSkuParam param){ - return Res.ok(createGoodsService.addPackGoodsAndSku(param)); + public ResResult add(@RequestBody GoodsParam param){ + return Res.ok(goodsService.add(param)); } @ApiOperation("查询全部") @@ -47,12 +31,18 @@ public class GoodsController{ return Res.ok(goodsService.findAll()); } - @ApiOperation("查询详情") + @ApiOperation("查询包含sku的详情") @GetMapping("/getDetails") public ResResult getDetails(Long id){ return Res.ok(goodsService.getDetails(id)); } + @ApiOperation("查询包含商品信息") + @GetMapping("/findById") + public ResResult findById(Long id){ + return Res.ok(goodsService.findById(id)); + } + @ApiOperation("按类目查询") @GetMapping("/findByCategory") public ResResult> findByCategory(Long cid){ diff --git a/service-goods-center/service-goods-center-impl/src/main/java/cn/bootx/goodscenter/controller/GoodsPackController.java b/service-goods-center/service-goods-center-impl/src/main/java/cn/bootx/goodscenter/controller/GoodsPackController.java deleted file mode 100644 index aecd1e2..0000000 --- a/service-goods-center/service-goods-center-impl/src/main/java/cn/bootx/goodscenter/controller/GoodsPackController.java +++ /dev/null @@ -1,17 +0,0 @@ -package cn.bootx.goodscenter.controller; - -import io.swagger.annotations.Api; -import lombok.AllArgsConstructor; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RestController; - -/** -* @author xxm -* @date 2020/11/23 -*/ -@Api(tags = "商品打包") -@RestController -@RequestMapping("/pack/goods") -@AllArgsConstructor -public class GoodsPackController { -} diff --git a/service-goods-center/service-goods-center-impl/src/main/java/cn/bootx/goodscenter/controller/GoodsSkuController.java b/service-goods-center/service-goods-center-impl/src/main/java/cn/bootx/goodscenter/controller/GoodsSkuController.java index 153e7c8..e4b9647 100644 --- a/service-goods-center/service-goods-center-impl/src/main/java/cn/bootx/goodscenter/controller/GoodsSkuController.java +++ b/service-goods-center/service-goods-center-impl/src/main/java/cn/bootx/goodscenter/controller/GoodsSkuController.java @@ -2,13 +2,9 @@ package cn.bootx.goodscenter.controller; import cn.bootx.common.web.rest.Res; import cn.bootx.common.web.rest.ResResult; -import cn.bootx.goodscenter.core.sku.entity.GoodsSku; -import cn.bootx.goodscenter.core.sku.service.GoodsSkuGenService; -import cn.bootx.goodscenter.core.sku.service.GoodsSkuOperateService; import cn.bootx.goodscenter.core.sku.service.GoodsSkuService; import cn.bootx.goodscenter.dto.sku.GoodsSkuDto; -import cn.bootx.goodscenter.param.sku.CreateSkuParam; -import cn.bootx.goodscenter.param.sku.GenSkuParam; +import cn.bootx.goodscenter.param.sku.SkuParam; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; import lombok.AllArgsConstructor; @@ -26,13 +22,12 @@ import java.util.List; @AllArgsConstructor public class GoodsSkuController { private final GoodsSkuService goodsSkuService; - private final GoodsSkuOperateService goodsSkuOperateService; - private final GoodsSkuGenService goodsSkuGenService; - @ApiOperation("根据商品 SKU 属性生成其 SKU 预览") - @PostMapping("/genSku") - public ResResult> genSku(@RequestBody GenSkuParam genSkuParam){ - return Res.ok(goodsSkuGenService.genSkuByAttrs(genSkuParam)); + + @ApiOperation("添加商品sku") + @PostMapping("/add") + public ResResult add(@RequestBody SkuParam skuParam){ + return Res.ok(goodsSkuService.add(skuParam)); } @ApiOperation("获取sku") @@ -43,7 +38,7 @@ public class GoodsSkuController { @ApiOperation("获取sku") @GetMapping("/findBySkuIds") - public ResResult> findBySkuIds(List skuIds){ + public ResResult> findBySkuIds(@RequestParam List skuIds){ return Res.ok(goodsSkuService.findBySkuIds(skuIds)); } @@ -53,10 +48,4 @@ public class GoodsSkuController { return Res.ok(goodsSkuService.findByGoodsId(goodsId)); } - @ApiOperation("添加商品sku") - @PostMapping("/add") - public ResResult add(@RequestBody CreateSkuParam skuParam){ - return Res.ok(goodsSkuOperateService.add(skuParam)); - } - } diff --git a/service-goods-center/service-goods-center-impl/src/main/java/cn/bootx/goodscenter/controller/GoodsSkuPackController.java b/service-goods-center/service-goods-center-impl/src/main/java/cn/bootx/goodscenter/controller/GoodsSkuPackController.java deleted file mode 100644 index 886102d..0000000 --- a/service-goods-center/service-goods-center-impl/src/main/java/cn/bootx/goodscenter/controller/GoodsSkuPackController.java +++ /dev/null @@ -1,33 +0,0 @@ -package cn.bootx.goodscenter.controller; - -import cn.bootx.common.web.rest.Res; -import cn.bootx.common.web.rest.ResResult; -import cn.bootx.goodscenter.core.packing.service.GoodsSkuPackService; -import cn.bootx.goodscenter.dto.packing.GoodsSkuPackingDto; -import io.swagger.annotations.Api; -import io.swagger.annotations.ApiOperation; -import lombok.AllArgsConstructor; -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; - -/** -* @author xxm -* @date 2020/11/23 -*/ -@Api(tags = "SKU打包") -@RestController -@RequestMapping("/pack/sku") -@AllArgsConstructor -public class GoodsSkuPackController { - private final GoodsSkuPackService goodsSkuPackService; - - - @ApiOperation("通过打包品SKU id 获取其关联的被打包品信息") - @GetMapping("/findBySkuId") - public ResResult> findBySkuId(Long skuId){ - return Res.ok(goodsSkuPackService.findBySkuId(skuId)); - } -} diff --git a/service-goods-center/service-goods-center-impl/src/main/java/cn/bootx/goodscenter/core/attributes/dao/CategoryAttrDefManager.java b/service-goods-center/service-goods-center-impl/src/main/java/cn/bootx/goodscenter/core/attributes/dao/CategoryAttrDefManager.java deleted file mode 100644 index 81f0cab..0000000 --- a/service-goods-center/service-goods-center-impl/src/main/java/cn/bootx/goodscenter/core/attributes/dao/CategoryAttrDefManager.java +++ /dev/null @@ -1,35 +0,0 @@ -package cn.bootx.goodscenter.core.attributes.dao; - -import cn.bootx.goodscenter.core.attributes.entity.CategoryAttrDef; -import cn.bootx.starter.headerholder.HeaderHolder; -import com.querydsl.jpa.impl.JPAQueryFactory; -import lombok.RequiredArgsConstructor; -import org.springframework.stereotype.Repository; - -import java.util.List; -import java.util.Optional; - -@Repository -@RequiredArgsConstructor -public class CategoryAttrDefManager { - private final CategoryAttrDefRepository attrDefRepository; - private final JPAQueryFactory jpaQueryFactory; - - private final HeaderHolder headerHolder; - - public boolean existsByCidAndName(Long cid, String name) { - return attrDefRepository.existsByCidAndNameAndTid(cid,name,headerHolder.findTid()); - } - - public List findByCid(Long cid) { - return attrDefRepository.findAllByCidAndTid(cid,headerHolder.findTid()); - } - - public List findAll() { - return attrDefRepository.findAllByTid(headerHolder.findTid()); - } - - public Optional findById(Long id) { - return attrDefRepository.findByIdAndTid(id,headerHolder.findTid()); - } -} diff --git a/service-goods-center/service-goods-center-impl/src/main/java/cn/bootx/goodscenter/core/attributes/dao/CategoryAttrDefRepository.java b/service-goods-center/service-goods-center-impl/src/main/java/cn/bootx/goodscenter/core/attributes/dao/CategoryAttrDefRepository.java deleted file mode 100644 index d66cbda..0000000 --- a/service-goods-center/service-goods-center-impl/src/main/java/cn/bootx/goodscenter/core/attributes/dao/CategoryAttrDefRepository.java +++ /dev/null @@ -1,17 +0,0 @@ -package cn.bootx.goodscenter.core.attributes.dao; - -import cn.bootx.goodscenter.core.attributes.entity.CategoryAttrDef; -import org.springframework.data.jpa.repository.JpaRepository; - -import java.util.List; -import java.util.Optional; - -public interface CategoryAttrDefRepository extends JpaRepository { - boolean existsByCidAndNameAndTid(Long cid, String name, Long tid); - - List findAllByCidAndTid(Long cid, Long tid); - - List findAllByTid(Long tid); - - Optional findByIdAndTid(Long id, Long tid); -} diff --git a/service-goods-center/service-goods-center-impl/src/main/java/cn/bootx/goodscenter/core/attributes/entity/CategoryAttrDef.java b/service-goods-center/service-goods-center-impl/src/main/java/cn/bootx/goodscenter/core/attributes/entity/CategoryAttrDef.java deleted file mode 100644 index fe5e8c5..0000000 --- a/service-goods-center/service-goods-center-impl/src/main/java/cn/bootx/goodscenter/core/attributes/entity/CategoryAttrDef.java +++ /dev/null @@ -1,90 +0,0 @@ -package cn.bootx.goodscenter.core.attributes.entity; - -import cn.bootx.common.function.EntityBaseFunction; -import cn.bootx.common.web.code.CommonCode; -import cn.bootx.goodscenter.dto.category.CategoryAttrDefDto; -import cn.bootx.starter.jpa.base.JpaBaseEntity; -import lombok.Data; -import lombok.EqualsAndHashCode; -import lombok.experimental.Accessors; -import org.hibernate.annotations.SQLDelete; -import org.hibernate.annotations.Where; -import org.springframework.beans.BeanUtils; - -import javax.persistence.Column; -import javax.persistence.Entity; -import javax.persistence.Table; - -/** -* 类目规格属性定义 -* @author xxm -* @date 2020/11/21 -*/ -@EqualsAndHashCode(callSuper = true) -@Entity -@Data -@Accessors(chain = true) -@Table(name = "gc_category_attr_def") -@SQLDelete(sql = "update gc_category_attr_def set deleted=" + CommonCode.DELETE_FLAG + " where id=? and version=? ") -@Where(clause = "deleted=" + CommonCode.NORMAL_FLAG) -public class CategoryAttrDef extends JpaBaseEntity implements EntityBaseFunction { - - /** 所属类目id */ - private Long cid; - /** 名称 */ - private String name; - /** - * 所属类型 - */ - private int type; - /** 数据字典id */ - private Long dictId; - /** 目标类型 sku/spu */ - private int targetType; - - /** 是否显示属性 */ - @Column(name = "is_display") - private boolean display; - /** 是否搜索属性 */ - @Column(name = "is_search") - private boolean search; - /** 是否必须 */ - @Column(name = "is_required") - private boolean required; - /** 是否多选 */ - @Column(name = "is_multiple") - private boolean multiple; - /** 排序 */ - private int ordinal; - /** 状态 */ - private int state; - /** 属性名称 */ - private String fieldName; - /** 属性长度 */ - private Integer fieldLength; - /** 小数点长度 */ - private Integer fieldPointLength; - /** 属性类型 */ - private String fieldType; - /** 字段默认值 */ - private String fieldDefault; - /** 字段查询时的比较方式 */ - private String queryCompareType; - /** 是否主键 */ - private Boolean isKey; - /** 描述 */ - private String description; - - public static CategoryAttrDef init(CategoryAttrDefDto dto) { - CategoryAttrDef entity = new CategoryAttrDef(); - BeanUtils.copyProperties(dto, entity); - return entity; - } - - @Override - public CategoryAttrDefDto toDto() { - CategoryAttrDefDto dto = new CategoryAttrDefDto(); - BeanUtils.copyProperties(this, dto); - return dto; - } -} diff --git a/service-goods-center/service-goods-center-impl/src/main/java/cn/bootx/goodscenter/core/attributes/handler/AttrGenHandler.java b/service-goods-center/service-goods-center-impl/src/main/java/cn/bootx/goodscenter/core/attributes/handler/AttrGenHandler.java deleted file mode 100644 index 3a2874c..0000000 --- a/service-goods-center/service-goods-center-impl/src/main/java/cn/bootx/goodscenter/core/attributes/handler/AttrGenHandler.java +++ /dev/null @@ -1,172 +0,0 @@ -package cn.bootx.goodscenter.core.attributes.handler; - -import cn.bootx.common.web.exception.ValidationFailedException; -import cn.bootx.goodscenter.core.category.handler.Descartes; -import cn.bootx.goodscenter.core.category.handler.ValueDisplayPair; -import cn.bootx.goodscenter.core.goods.entity.Goods; -import cn.bootx.goodscenter.core.goods.entity.GoodsAttr; -import cn.bootx.goodscenter.core.sku.entity.GoodsSku; -import cn.bootx.goodscenter.core.sku.entity.GoodsSkuAttr; -import cn.bootx.goodscenter.param.sku.GenSkuAttrParam; -import cn.hutool.core.collection.CollectionUtil; -import cn.hutool.core.util.StrUtil; -import lombok.experimental.UtilityClass; - -import java.util.*; -import java.util.stream.Collectors; - -/** -* 属性生成Handler -* @author xxm -* @date 2020/11/21 -*/ -@UtilityClass -public class AttrGenHandler { - - /** - * 提取所有sku属性值和属性显示值之间的映射关系 - * (属性值列表和属性值展示列表的存放顺序需保持一致,并且存放数量相同) - */ - public static List> extractSkuAttrValues(List skuAttrList) { - List> values = new ArrayList<>(); - for (GenSkuAttrParam skuAttrParam : skuAttrList) { - List attrValueList = skuAttrParam.getAttrValues(); - List attrValueListDisplay = skuAttrParam.getAttrValueDisplays(); - - if (CollectionUtil.isEmpty(attrValueList) - || CollectionUtil.isEmpty(attrValueListDisplay) - || (attrValueList.size() != attrValueListDisplay.size())) { - throw new ValidationFailedException("SKU属性值数据异常"); - } - values.add(toIdValuePairList(attrValueList, attrValueListDisplay)); - } - return values; - } - - /** - * 构造映射关系,属性值 -> 属性显示值 - * - */ - private static List toIdValuePairList(List attrValueList, List attrValueListDisplay) { - List result = new ArrayList<>(); - - for (int i = 0; i < attrValueList.size(); i++) { - result.add(new ValueDisplayPair(attrValueList.get(i), attrValueListDisplay.get(i))); - } - return result; - } - - /** - * 进行笛卡尔积后,对属性值和属性显示值进行处理。 - * - * @return key:所有属性值拼接的字符串,属性值之间以_间隔。value:所有属性显示值拼接的字符串,属性显示值之间以_间隔。 - */ - public static Map calculateDescartes(List> skuAttrValues) { - List> result = new ArrayList<>(); - Descartes.recursive(skuAttrValues, result, 0, new ArrayList<>()); - - Map strValueStrMap = new HashMap<>(result.size()); - - for (List valuePairList : result) { - StringBuilder valStr = new StringBuilder(); - StringBuilder displayStr = new StringBuilder(); - for (ValueDisplayPair idValuePair : valuePairList) { - valStr.append(",").append(idValuePair.getValue()); - displayStr.append(",").append(idValuePair.getDisplay()); - } - - String val = valStr.substring(1); - String display = displayStr.substring(1); - - strValueStrMap.put(val, display); - } - return strValueStrMap; - } - - - /** - * 批量生成sku 属性 - */ - public static List genSkuAttrsBySkus(List skuList){ - List skuAttrs = new ArrayList<>(); - for (GoodsSku goodsSku : skuList) { - skuAttrs.addAll(genSkuAttrsBySku(goodsSku)); - } - return skuAttrs; - } - - /** - * 生成 sku 属性 - */ - public static List genSkuAttrsBySku(GoodsSku goodsSku) { - List skuAttrs = new ArrayList<>(); - - String attrDefIdsString = goodsSku.getAttrDefIds(); - String attrValuesString = goodsSku.getAttrValues(); - String attrValueDisplaysString = goodsSku.getAttrValueDisplays(); - - List attrDefIds = splitAppendList(attrDefIdsString); - List attrValues = splitAppendList(attrValuesString); - List attrValueDisplays = splitAppendList(attrValueDisplaysString); - - for (int i = 0; i < attrDefIds.size(); i++) { - GoodsSkuAttr skuAttr = new GoodsSkuAttr(); - skuAttr.setCid(goodsSku.getCid()); - skuAttr.setGoodsId(goodsSku.getGoodsId()); - skuAttr.setSkuId(goodsSku.getId()); - skuAttr.setAttrDefId(Long.parseLong(attrDefIds.get(i))); - skuAttr.setAttrValue(attrValues.get(i)); - skuAttr.setAttrValueDisplays(attrValueDisplays.get(i)); - skuAttrs.add(skuAttr); - } - return skuAttrs; - } - - /** - * 批量生成商品属性 - */ -// public static List genGoodsAttrsByGoodies(List goodies){ -// List goodsAttrs = new ArrayList<>(); -// for (Goods goods : goodies) { -// goodsAttrs.addAll(genGoodsAttrsByGoods(goods)); -// } -// return goodsAttrs; -// } - - /** - * 生成商品属性 - */ - public static List genGoodsAttrsByGoods(Goods goodsSku) { - List goodsAttrs = new ArrayList<>(); - - String attrDefIdsString = goodsSku.getAttrDefIds(); - String attrValuesString = goodsSku.getAttrValues(); - String attrValueDisplaysString = goodsSku.getAttrValueDisplays(); - - List attrDefIds = splitAppendList(attrDefIdsString); - List attrValues = splitAppendList(attrValuesString); - List attrValueDisplays = splitAppendList(attrValueDisplaysString); - - for (int i = 0; i < attrDefIds.size(); i++) { - GoodsAttr skuAttr = new GoodsAttr(); - skuAttr.setCid(goodsSku.getCid()); - skuAttr.setGoodsId(goodsSku.getId()); - skuAttr.setAttrDefId(Long.parseLong(attrDefIds.get(i))); - skuAttr.setAttrValue(attrValues.get(i)); - skuAttr.setAttrValueDisplays(attrValueDisplays.get(i)); - goodsAttrs.add(skuAttr); - } - return goodsAttrs; - } - - /** - * 将拼接的字符串拆分成数组形式 - */ - public static List splitAppendList(String appendString) { - if (StrUtil.isEmpty(appendString)) { - return new ArrayList<>(0); - } - return Arrays.stream(appendString.split(",")) - .collect(Collectors.toList()); - } -} diff --git a/service-goods-center/service-goods-center-impl/src/main/java/cn/bootx/goodscenter/core/attributes/service/CategoryAttrDefService.java b/service-goods-center/service-goods-center-impl/src/main/java/cn/bootx/goodscenter/core/attributes/service/CategoryAttrDefService.java deleted file mode 100644 index 9fb70b4..0000000 --- a/service-goods-center/service-goods-center-impl/src/main/java/cn/bootx/goodscenter/core/attributes/service/CategoryAttrDefService.java +++ /dev/null @@ -1,59 +0,0 @@ -package cn.bootx.goodscenter.core.attributes.service; - -import cn.bootx.common.web.util.ResultConvertUtils; -import cn.bootx.goodscenter.core.attributes.dao.CategoryAttrDefManager; -import cn.bootx.goodscenter.core.attributes.dao.CategoryAttrDefRepository; -import cn.bootx.goodscenter.core.attributes.entity.CategoryAttrDef; -import cn.bootx.goodscenter.dto.category.CategoryAttrDefDto; -import cn.bootx.goodscenter.exception.category.CategoryAttrDefAlreadyExistedException; -import lombok.RequiredArgsConstructor; -import lombok.extern.slf4j.Slf4j; -import org.springframework.stereotype.Service; - -import java.util.List; - -/** -* 类目属性定义 -* @author xxm -* @date 2020/11/21 -*/ -@Slf4j -@Service -@RequiredArgsConstructor -public class CategoryAttrDefService { - private final CategoryAttrDefManager attrDefManager; - private final CategoryAttrDefRepository attrDefRepository; - - /** - * 添加类目属性定义 - */ - public CategoryAttrDefDto addAttrDef(CategoryAttrDefDto param){ - if (attrDefManager.existsByCidAndName(param.getCid(), param.getName())) { - throw new CategoryAttrDefAlreadyExistedException(); - } - CategoryAttrDef categoryAttrDef = CategoryAttrDef.init(param); - return attrDefRepository.save(categoryAttrDef).toDto(); - } - - /** - * 查询全部定义 - */ - public List findAll(){ - return ResultConvertUtils.dtoListConvert(attrDefManager.findAll()); - } - - /** - * 根据类目id查询 - */ - public List findByCategory(Long cid){ - return ResultConvertUtils.dtoListConvert(attrDefManager.findByCid(cid)); - } - - /** - * 查询单条 - */ - public CategoryAttrDefDto getById(Long id){ - return attrDefManager.findById(id).map(CategoryAttrDef::toDto).orElse(null); - } - -} diff --git a/service-goods-center/service-goods-center-impl/src/main/java/cn/bootx/goodscenter/core/category/convert/CategoryConvert.java b/service-goods-center/service-goods-center-impl/src/main/java/cn/bootx/goodscenter/core/category/convert/CategoryConvert.java index e8a3c9a..4b3994a 100644 --- a/service-goods-center/service-goods-center-impl/src/main/java/cn/bootx/goodscenter/core/category/convert/CategoryConvert.java +++ b/service-goods-center/service-goods-center-impl/src/main/java/cn/bootx/goodscenter/core/category/convert/CategoryConvert.java @@ -1,8 +1,6 @@ package cn.bootx.goodscenter.core.category.convert; import cn.bootx.goodscenter.core.category.entity.Category; -import cn.bootx.goodscenter.core.attributes.entity.CategoryAttrDef; -import cn.bootx.goodscenter.dto.category.CategoryAttrDefDto; import cn.bootx.goodscenter.dto.category.CategoryDto; import org.mapstruct.Mapper; import org.mapstruct.Mappings; @@ -16,10 +14,4 @@ public interface CategoryConvert { @Mappings({}) Category convert(CategoryDto in); - - @Mappings({}) - CategoryAttrDefDto convert(CategoryAttrDef in); - - @Mappings({}) - CategoryAttrDef convert(CategoryAttrDefDto in); } diff --git a/service-goods-center/service-goods-center-impl/src/main/java/cn/bootx/goodscenter/core/category/service/CategoryService.java b/service-goods-center/service-goods-center-impl/src/main/java/cn/bootx/goodscenter/core/category/service/CategoryService.java index 2131b5a..095cb3c 100644 --- a/service-goods-center/service-goods-center-impl/src/main/java/cn/bootx/goodscenter/core/category/service/CategoryService.java +++ b/service-goods-center/service-goods-center-impl/src/main/java/cn/bootx/goodscenter/core/category/service/CategoryService.java @@ -31,7 +31,6 @@ public class CategoryService { private final CategoryRepository categoryRepository; private final CategoryManager categoryManager; - /** * 添加新类目 */ diff --git a/service-goods-center/service-goods-center-impl/src/main/java/cn/bootx/goodscenter/core/goods/convert/GoodsConvert.java b/service-goods-center/service-goods-center-impl/src/main/java/cn/bootx/goodscenter/core/goods/convert/GoodsConvert.java new file mode 100644 index 0000000..a88e76d --- /dev/null +++ b/service-goods-center/service-goods-center-impl/src/main/java/cn/bootx/goodscenter/core/goods/convert/GoodsConvert.java @@ -0,0 +1,27 @@ +package cn.bootx.goodscenter.core.goods.convert; + +import cn.bootx.goodscenter.core.goods.entity.Goods; +import cn.bootx.goodscenter.dto.goods.GoodsDto; +import cn.bootx.goodscenter.param.goods.GoodsParam; +import org.mapstruct.Mapper; +import org.mapstruct.Mappings; +import org.mapstruct.factory.Mappers; + +/** +* 转换 +* @author xxm +* @date 2021/7/23 +*/ +@Mapper +public interface GoodsConvert { + GoodsConvert CONVERT = Mappers.getMapper(GoodsConvert.class); + + @Mappings({}) + Goods convert(GoodsParam in); + + @Mappings({}) + Goods convert(GoodsDto in); + + @Mappings({}) + GoodsDto convert(Goods in); +} diff --git a/service-goods-center/service-goods-center-impl/src/main/java/cn/bootx/goodscenter/core/goods/dao/GoodsAttrRepository.java b/service-goods-center/service-goods-center-impl/src/main/java/cn/bootx/goodscenter/core/goods/dao/GoodsAttrRepository.java deleted file mode 100644 index 05f2fa3..0000000 --- a/service-goods-center/service-goods-center-impl/src/main/java/cn/bootx/goodscenter/core/goods/dao/GoodsAttrRepository.java +++ /dev/null @@ -1,8 +0,0 @@ -package cn.bootx.goodscenter.core.goods.dao; - - -import cn.bootx.goodscenter.core.goods.entity.GoodsAttr; -import org.springframework.data.jpa.repository.JpaRepository; - -public interface GoodsAttrRepository extends JpaRepository { -} diff --git a/service-goods-center/service-goods-center-impl/src/main/java/cn/bootx/goodscenter/core/goods/dao/GoodsManager.java b/service-goods-center/service-goods-center-impl/src/main/java/cn/bootx/goodscenter/core/goods/dao/GoodsManager.java index b02fe1d..a4eed55 100644 --- a/service-goods-center/service-goods-center-impl/src/main/java/cn/bootx/goodscenter/core/goods/dao/GoodsManager.java +++ b/service-goods-center/service-goods-center-impl/src/main/java/cn/bootx/goodscenter/core/goods/dao/GoodsManager.java @@ -2,12 +2,10 @@ package cn.bootx.goodscenter.core.goods.dao; import cn.bootx.goodscenter.core.goods.entity.Goods; import cn.bootx.starter.headerholder.HeaderHolder; -import cn.hutool.core.collection.CollUtil; import com.querydsl.jpa.impl.JPAQueryFactory; import lombok.RequiredArgsConstructor; import org.springframework.stereotype.Repository; -import java.math.BigDecimal; import java.util.Collection; import java.util.List; import java.util.Optional; @@ -29,14 +27,6 @@ public class GoodsManager { return goodsRepository.findByIdAndTid(id,headerHolder.findTid()); } - public boolean existsName(String name) { - return goodsRepository.existsByNameAndTid(name,headerHolder.findTid()); - } - - public boolean existsCode(String code) { - return goodsRepository.existsByCodeAndTid(code,headerHolder.findTid()); - } - public List findAll() { return goodsRepository.findAllByTid(headerHolder.findTid()); } @@ -48,24 +38,4 @@ public class GoodsManager { public List findByIds(Collection goodsIds) { return goodsRepository.findAllByIdInAndTid(goodsIds,headerHolder.findTid()); } - - public void deleteByIds(List deleteIds) { - if (CollUtil.isNotEmpty(deleteIds)){ - goodsRepository.deleteByIdInAndTid(deleteIds,headerHolder.findTid()); - } - } - - /** - * 价格下限 - */ - public BigDecimal getGoodsLowerPrice(Long goodsId) { - return goodsRepository.getGoodsLowerPriceAndTid(goodsId,headerHolder.findTid()); - } - - /** - * 价格上限 - */ - public BigDecimal getGoodsUpperPrice(Long goodsId) { - return goodsRepository.getGoodsUpperPriceAndTid(goodsId,headerHolder.findTid()); - } } diff --git a/service-goods-center/service-goods-center-impl/src/main/java/cn/bootx/goodscenter/core/goods/dao/GoodsRepository.java b/service-goods-center/service-goods-center-impl/src/main/java/cn/bootx/goodscenter/core/goods/dao/GoodsRepository.java index 6ea4533..c2b18e5 100644 --- a/service-goods-center/service-goods-center-impl/src/main/java/cn/bootx/goodscenter/core/goods/dao/GoodsRepository.java +++ b/service-goods-center/service-goods-center-impl/src/main/java/cn/bootx/goodscenter/core/goods/dao/GoodsRepository.java @@ -2,10 +2,7 @@ package cn.bootx.goodscenter.core.goods.dao; import cn.bootx.goodscenter.core.goods.entity.Goods; import org.springframework.data.jpa.repository.JpaRepository; -import org.springframework.data.jpa.repository.Query; -import org.springframework.data.repository.query.Param; -import java.math.BigDecimal; import java.util.Collection; import java.util.List; import java.util.Optional; @@ -13,21 +10,10 @@ import java.util.Optional; public interface GoodsRepository extends JpaRepository { Optional findByIdAndTid(Long id, Long tid); - boolean existsByNameAndTid(String name, Long tid); - - boolean existsByCodeAndTid(String code, Long tid); List findAllByTid(Long tid); List findAllByCidAndTid(Long cid, Long tid); List findAllByIdInAndTid(Collection goodsIds, Long tid); - - void deleteByIdInAndTid(List deleteIds, Long tid); - - @Query("select min (price) from GoodsSku where goodsId = :goodsId and tid = :tid") - BigDecimal getGoodsLowerPriceAndTid(@Param("goodsId") Long goodsId,@Param("tid") Long tid); - - @Query("select max (price) from GoodsSku where goodsId = :goodsId and tid = :tid") - BigDecimal getGoodsUpperPriceAndTid(@Param("goodsId") Long goodsId,@Param("tid") Long tid); } diff --git a/service-goods-center/service-goods-center-impl/src/main/java/cn/bootx/goodscenter/core/goods/entity/Goods.java b/service-goods-center/service-goods-center-impl/src/main/java/cn/bootx/goodscenter/core/goods/entity/Goods.java index 43cdf8e..2dfee9e 100644 --- a/service-goods-center/service-goods-center-impl/src/main/java/cn/bootx/goodscenter/core/goods/entity/Goods.java +++ b/service-goods-center/service-goods-center-impl/src/main/java/cn/bootx/goodscenter/core/goods/entity/Goods.java @@ -1,18 +1,17 @@ package cn.bootx.goodscenter.core.goods.entity; import cn.bootx.common.function.EntityBaseFunction; +import cn.bootx.goodscenter.core.goods.convert.GoodsConvert; import cn.bootx.goodscenter.dto.goods.GoodsDto; +import cn.bootx.goodscenter.param.goods.GoodsParam; import cn.bootx.starter.jpa.base.JpaBaseEntity; -import cn.hutool.core.bean.BeanUtil; import lombok.Data; import lombok.EqualsAndHashCode; import lombok.experimental.Accessors; import javax.persistence.Entity; import javax.persistence.Table; -import javax.persistence.Transient; import java.math.BigDecimal; -import java.time.LocalDateTime; /** * 商品表 @@ -32,15 +31,6 @@ public class Goods extends JpaBaseEntity implements EntityBaseFunction /** 所属类目名称 */ private String cname; - /** 所属商店id */ - private Long shopId; - - /** 外部编码 */ - private String outNo; - - /** 商品code */ - private String code; - /** 商品名称 */ private String name; @@ -59,46 +49,19 @@ public class Goods extends JpaBaseEntity implements EntityBaseFunction /** 显示下限价格 */ private BigDecimal displayLowerPrice; - /** 是否打包品 */ - private boolean packing; - - /** 商品类型(虚拟/实体/赠品/加价购/服务) */ - private Integer goodsType; - - /** 0下架 1上架 2违规平台下架 */ - private Integer saleState; - - /** 上架时间 */ - private LocalDateTime saleOnTime; - /** 下架时间 */ - private LocalDateTime saleOffTime; - - /** 商品的所有属性定义 id 拼接串 */ - private String attrDefIds; - - /** 品的所有属性值拼接串 */ - private String attrValues; - - /** 品的所有属性显示值拼接串 */ - @Transient - private String attrValueDisplays; - - /** 附加信息 */ - private String addition; - /** 状态(1:可用,0:不可用) */ private int state; - public static Goods init(GoodsDto dto){ - Goods entity = new Goods(); - BeanUtil.copyProperties(dto,entity); - return entity; + public static Goods init(GoodsDto in){ + return GoodsConvert.CONVERT.convert(in); + } + + public static Goods init(GoodsParam in){ + return GoodsConvert.CONVERT.convert(in); } @Override public GoodsDto toDto() { - GoodsDto dto = new GoodsDto(); - BeanUtil.copyProperties(this,dto); - return dto; + return GoodsConvert.CONVERT.convert(this); } } diff --git a/service-goods-center/service-goods-center-impl/src/main/java/cn/bootx/goodscenter/core/goods/entity/GoodsAttr.java b/service-goods-center/service-goods-center-impl/src/main/java/cn/bootx/goodscenter/core/goods/entity/GoodsAttr.java deleted file mode 100644 index 8749c6c..0000000 --- a/service-goods-center/service-goods-center-impl/src/main/java/cn/bootx/goodscenter/core/goods/entity/GoodsAttr.java +++ /dev/null @@ -1,37 +0,0 @@ -package cn.bootx.goodscenter.core.goods.entity; - -import cn.bootx.starter.jpa.base.JpaTidEntity; -import lombok.Data; -import lombok.EqualsAndHashCode; -import lombok.experimental.Accessors; - -import javax.persistence.Entity; -import javax.persistence.Table; - -/** -* 商品属性 -* @author xxm -* @date 2021/2/2 -*/ -@EqualsAndHashCode(callSuper = true) -@Data -@Accessors(chain = true) -@Entity -@Table(name = "gc_goods_attr") -public class GoodsAttr extends JpaTidEntity { - - /** 商品 类目 id */ - private Long cid; - - /** 所属商品 id */ - private Long goodsId; - - /** 属性定义 id */ - private Long attrDefId; - - /** 属性值 */ - private String attrValue; - - /** 显示值 */ - private String attrValueDisplays; -} diff --git a/service-goods-center/service-goods-center-impl/src/main/java/cn/bootx/goodscenter/core/goods/entity/GoodsSpec.java b/service-goods-center/service-goods-center-impl/src/main/java/cn/bootx/goodscenter/core/goods/entity/GoodsSpec.java deleted file mode 100644 index 599375a..0000000 --- a/service-goods-center/service-goods-center-impl/src/main/java/cn/bootx/goodscenter/core/goods/entity/GoodsSpec.java +++ /dev/null @@ -1,42 +0,0 @@ -package cn.bootx.goodscenter.core.goods.entity; - -import cn.bootx.common.function.EntityBaseFunction; -import cn.bootx.goodscenter.dto.goods.GoodsSpecDto; -import cn.bootx.starter.jpa.base.JpaTidEntity; -import cn.hutool.core.bean.BeanUtil; -import lombok.Data; -import lombok.EqualsAndHashCode; -import lombok.experimental.Accessors; - -/** -* 商品销售规格 -* @author xxm -* @date 2021/2/23 -*/ -@EqualsAndHashCode(callSuper = true) -@Data -@Accessors(chain = true) -public class GoodsSpec extends JpaTidEntity implements EntityBaseFunction { - - /** 商品id */ - private Long goodsId; - - /** 类目规格属性定义(sku属性) */ - private Long attrDefId; - - /** 排序序号 */ - private Integer ordinal; - - /** 属性值 */ - private String attrValues; - - /** 属性显示值 */ - private String attrValueDisplays; - - @Override - public GoodsSpecDto toDto() { - GoodsSpecDto dto = new GoodsSpecDto(); - BeanUtil.copyProperties(this,dto); - return dto; - } -} diff --git a/service-goods-center/service-goods-center-impl/src/main/java/cn/bootx/goodscenter/core/goods/factory/GoodsFactory.java b/service-goods-center/service-goods-center-impl/src/main/java/cn/bootx/goodscenter/core/goods/factory/GoodsFactory.java deleted file mode 100644 index fda554b..0000000 --- a/service-goods-center/service-goods-center-impl/src/main/java/cn/bootx/goodscenter/core/goods/factory/GoodsFactory.java +++ /dev/null @@ -1,57 +0,0 @@ -package cn.bootx.goodscenter.core.goods.factory; - -import cn.bootx.goodscenter.core.goods.entity.Goods; -import cn.bootx.goodscenter.dto.goods.GoodsAttrDto; -import cn.bootx.goodscenter.param.goods.CreateGoodsParam; -import cn.bootx.goodscenter.param.goods.UpdateGoodsParam; -import lombok.RequiredArgsConstructor; -import org.springframework.beans.BeanUtils; -import org.springframework.stereotype.Component; - -import java.util.List; -import java.util.stream.Collectors; - - -/** -* 商品工厂 -* @author xxm -* @date 2021/2/2 -*/ -@Component -@RequiredArgsConstructor -public class GoodsFactory { - - /** - * 生成商品 - */ - public Goods construct(CreateGoodsParam createGoodsParam){ - Goods goods = new Goods(); - BeanUtils.copyProperties(createGoodsParam,goods); - List attrList = createGoodsParam.getAttrList(); - String attrDefIds = attrList.stream().map(GoodsAttrDto::getAttrDefId).map(String::valueOf).collect(Collectors.joining(",")); - String attrValues = attrList.stream().map(GoodsAttrDto::getAttrValue).collect(Collectors.joining(",")); - String attrValueDisplays = attrList.stream().map(GoodsAttrDto::getAttrValueDisplay).collect(Collectors.joining(",")); - - goods.setAttrDefIds(attrDefIds); - goods.setAttrValues(attrValues); - goods.setAttrValueDisplays(attrValueDisplays); - return goods; - } - - /** - * 生成商品 - */ - public Goods construct(UpdateGoodsParam createGoodsParam){ - Goods goods = new Goods(); - BeanUtils.copyProperties(createGoodsParam,goods); - List attrList = createGoodsParam.getAttrList(); - String attrDefIds = attrList.stream().map(GoodsAttrDto::getAttrDefId).map(String::valueOf).collect(Collectors.joining(",")); - String attrValues = attrList.stream().map(GoodsAttrDto::getAttrValue).collect(Collectors.joining(",")); - String attrValueDisplays = attrList.stream().map(GoodsAttrDto::getAttrValueDisplay).collect(Collectors.joining(",")); - - goods.setAttrDefIds(attrDefIds); - goods.setAttrValues(attrValues); - goods.setAttrValueDisplays(attrValueDisplays); - return goods; - } -} diff --git a/service-goods-center/service-goods-center-impl/src/main/java/cn/bootx/goodscenter/core/goods/service/GoodsAddService.java b/service-goods-center/service-goods-center-impl/src/main/java/cn/bootx/goodscenter/core/goods/service/GoodsAddService.java deleted file mode 100644 index 952920c..0000000 --- a/service-goods-center/service-goods-center-impl/src/main/java/cn/bootx/goodscenter/core/goods/service/GoodsAddService.java +++ /dev/null @@ -1,140 +0,0 @@ -package cn.bootx.goodscenter.core.goods.service; - -import cn.bootx.common.web.util.ResultConvertUtils; -import cn.bootx.goodscenter.core.attributes.handler.AttrGenHandler; -import cn.bootx.goodscenter.core.goods.dao.GoodsAttrRepository; -import cn.bootx.goodscenter.core.goods.dao.GoodsRepository; -import cn.bootx.goodscenter.core.goods.entity.Goods; -import cn.bootx.goodscenter.core.goods.entity.GoodsAttr; -import cn.bootx.goodscenter.core.goods.factory.GoodsFactory; -import cn.bootx.goodscenter.core.packing.service.GoodsSkuPackService; -import cn.bootx.goodscenter.core.sku.entity.GoodsSku; -import cn.bootx.goodscenter.core.sku.service.GoodsSkuService; -import cn.bootx.goodscenter.dto.goods.GoodsDto; -import cn.bootx.goodscenter.dto.sku.GoodsSkuDto; -import cn.bootx.goodscenter.param.goods.CreateGoodsAndSkuParam; -import cn.bootx.goodscenter.param.goods.CreateGoodsParam; -import cn.bootx.goodscenter.param.sku.CreateSkuParam; -import cn.bootx.starter.snowflake.SnowFlakeId; -import cn.hutool.core.bean.BeanUtil; -import io.seata.spring.annotation.GlobalTransactional; -import lombok.RequiredArgsConstructor; -import lombok.extern.slf4j.Slf4j; -import org.springframework.stereotype.Service; - -import java.math.BigDecimal; -import java.util.Collections; -import java.util.List; - -/** - * 创建商品Service - * @author xxm - * @date 2021/2/2 - */ -@Slf4j -@Service -@RequiredArgsConstructor -public class GoodsAddService { - private final GoodsFactory goodsFactory; - private final GoodsSkuPackService skuPackService; - private final GoodsSkuService skuService; - - private final GoodsRepository goodsRepository; - private final GoodsAttrRepository goodsAttrRepository; - - private final SnowFlakeId snowFlakeId; - - - /** - * 增加单品, 一个sku对应一个商品 - */ - @GlobalTransactional(rollbackFor = Exception.class) - public GoodsSkuDto addSingle(CreateSkuParam param){ - CreateGoodsParam goodsParam = new CreateGoodsParam(); - BeanUtil.copyProperties(param,goodsParam); - Goods goods = this.addGoods(goodsParam); - // 添加SKU - GoodsSku sku = skuService.addSku(param, goods); - this.addGoodsPrice(goods, Collections.singletonList(sku)); - goodsRepository.save(goods); - - // 返回值构建 - return sku.toDto(); - } - - - /** - * 新增商品和sku - */ - @GlobalTransactional(rollbackFor = Exception.class) - public GoodsDto addGoodsAndSku(CreateGoodsAndSkuParam param){ - // 添加商品 - CreateGoodsParam goodsParam = param.getGoodsParam(); - Goods goods = this.addGoods(goodsParam); - // 添加SKU - List skuParams = param.getSkuParams(); - List skus = skuService.addSkus(skuParams, goods); - - this.addGoodsPrice(goods,skus); - goodsRepository.save(goods); - - // 返回值构建 - GoodsDto goodsDto = goods.toDto(); - goodsDto.setSkus(ResultConvertUtils.dtoListConvert(skus)); - return goodsDto; - } - /** - * 新增商品 - */ - public Goods addGoods(CreateGoodsParam goodsParam){ - Goods goods = goodsFactory.construct(goodsParam); - goods.setPacking(false) - .setId(snowFlakeId.nextId()); - List goodsAttrs = AttrGenHandler.genGoodsAttrsByGoods(goods); - goodsAttrRepository.saveAll(goodsAttrs); - return goods; - } - - /** - * 新增打包品和打包sku - */ - public GoodsDto addPackGoodsAndSku(CreateGoodsAndSkuParam param){ - // 添加商品 - CreateGoodsParam goodsParam = param.getGoodsParam(); - Goods goods = goodsFactory.construct(goodsParam); - goods.setPacking(true) - .setId(snowFlakeId.nextId()); - - // 添加sku 及 打包sku - List skuParams = param.getSkuParams(); - List skus = skuPackService.addPackSkus(skuParams, goods); - - this.addGoodsPrice(goods,skus); - goodsRepository.save(goods); - - // 返回值构建 - GoodsDto goodsDto = goods.toDto(); - goodsDto.setSkus(ResultConvertUtils.dtoListConvert(skus)); - return goodsDto; - } - - - /** - * 添加时计算商品价格 - */ - private void addGoodsPrice(Goods goods, List skus){ - BigDecimal min = skus.stream() - .map(GoodsSku::getPrice) - .min(BigDecimal::compareTo) - .orElse(BigDecimal.ZERO); - - BigDecimal max = skus.stream() - .map(GoodsSku::getPrice) - .max(BigDecimal::compareTo) - .orElse(BigDecimal.ZERO); - - goods.setDisplayLowerPrice(min) - .setDisplayUpperPrice(max); - } - -} diff --git a/service-goods-center/service-goods-center-impl/src/main/java/cn/bootx/goodscenter/core/goods/service/GoodsEditService.java b/service-goods-center/service-goods-center-impl/src/main/java/cn/bootx/goodscenter/core/goods/service/GoodsEditService.java deleted file mode 100644 index de1cbf8..0000000 --- a/service-goods-center/service-goods-center-impl/src/main/java/cn/bootx/goodscenter/core/goods/service/GoodsEditService.java +++ /dev/null @@ -1,150 +0,0 @@ -package cn.bootx.goodscenter.core.goods.service; - -import cn.bootx.common.web.exception.BizException; -import cn.bootx.goodscenter.core.attributes.handler.AttrGenHandler; -import cn.bootx.goodscenter.core.goods.dao.GoodsAttrRepository; -import cn.bootx.goodscenter.core.goods.dao.GoodsManager; -import cn.bootx.goodscenter.core.goods.dao.GoodsRepository; -import cn.bootx.goodscenter.core.goods.entity.Goods; -import cn.bootx.goodscenter.core.goods.factory.GoodsFactory; -import cn.bootx.goodscenter.core.packing.dao.GoodsSkuPackManager; -import cn.bootx.goodscenter.core.packing.dao.GoodsSkuPackRepository; -import cn.bootx.goodscenter.core.packing.service.GoodsSkuPackService; -import cn.bootx.goodscenter.core.sku.dao.GoodsSkuAttrManager; -import cn.bootx.goodscenter.core.sku.dao.GoodsSkuAttrRepository; -import cn.bootx.goodscenter.core.sku.dao.GoodsSkuManager; -import cn.bootx.goodscenter.core.sku.dao.GoodsSkuRepository; -import cn.bootx.goodscenter.core.sku.entity.GoodsSku; -import cn.bootx.goodscenter.core.sku.entity.GoodsSkuAttr; -import cn.bootx.goodscenter.core.sku.factory.GoodsSkuFactory; -import cn.bootx.goodscenter.core.sku.service.GoodsSkuService; -import cn.bootx.goodscenter.param.goods.UpdateGoodsAndSkuParam; -import cn.bootx.goodscenter.param.goods.UpdateGoodsParam; -import cn.bootx.goodscenter.param.sku.CreateSkuParam; -import cn.bootx.goodscenter.param.sku.UpdateSkuParam; -import cn.bootx.starter.snowflake.SnowFlakeId; -import cn.hutool.core.bean.BeanUtil; -import cn.hutool.core.bean.copier.CopyOptions; -import lombok.RequiredArgsConstructor; -import lombok.extern.slf4j.Slf4j; -import org.springframework.stereotype.Service; -import org.springframework.transaction.annotation.Transactional; - -import java.math.BigDecimal; -import java.util.List; -import java.util.Map; -import java.util.stream.Collectors; - -/** - * 编辑商品Service - * @author xxm - * @date 2021/2/2 - */ -@Slf4j -@Service -@RequiredArgsConstructor -public class GoodsEditService { - private final GoodsFactory goodsFactory; - private final GoodsSkuFactory goodsSkuFactory; - private final GoodsSkuPackService skuPackService; - private final GoodsSkuService skuService; - - private final GoodsRepository goodsRepository; - private final GoodsAttrRepository goodsAttrRepository; - private final GoodsManager goodsManager; - private final GoodsSkuRepository skuRepository; - private final GoodsSkuManager skuManager; - private final GoodsSkuAttrRepository skuAttrRepository; - private final GoodsSkuAttrManager skuAttrManager; - private final GoodsSkuPackRepository skuPackRepository; - private final GoodsSkuPackManager skuPackManager; - - private final SnowFlakeId snowFlakeId; - - - /** - * 更新商品信息 - */ - @Transactional(rollbackFor = Exception.class) - public void editGoodsAndSku(UpdateGoodsAndSkuParam param){ - // 更新商品 - UpdateGoodsParam updateGoodsParam = param.getGoodsParam(); - Goods oldGoods = goodsFactory.construct(updateGoodsParam); - Goods goods = goodsManager.findById(oldGoods.getId()) - .orElseThrow(() -> new BizException("商品不存在")); - BeanUtil.copyProperties(oldGoods,goods, CopyOptions.create().ignoreNullValue()); - goodsRepository.save(goods); - - // 删除 - List deleteIds = param.getDeleteIds(); - goodsManager.deleteByIds(deleteIds); - skuAttrManager.deleteBySkuIds(deleteIds); - - // 新增 - List createSkuParams = param.getCreateSkuParams(); - skuService.addSkus(createSkuParams,goods); - - // 更新sku - this.updateSkus(param.getUpdateSkuParams()); - } - - /** - * 更新sku - */ - private List updateSkus(List updateSkuParams){ - List oldSkus = updateSkuParams.stream() - .map(goodsSkuFactory::construct) - .collect(Collectors.toList()); - List skuIds = oldSkus.stream().map(GoodsSku::getId).collect(Collectors.toList()); - List newSkus = skuManager.findByIds(skuIds); - Map skuMap = oldSkus.stream().collect(Collectors.toMap(GoodsSku::getId, o -> o)); - // 更新sku信息 - for (GoodsSku goodsSku : newSkus) { - BeanUtil.copyProperties(skuMap.get(goodsSku.getId()),goodsSku); - } - - List goodsSkus = skuRepository.saveAll(newSkus); - - // 更新关联属性 先删后增 - skuAttrManager.deleteBySkuIds(skuIds); - List goodsSkuAttrs = AttrGenHandler.genSkuAttrsBySkus(newSkus); - skuAttrRepository.saveAll(goodsSkuAttrs); - return goodsSkus; - } - - /** - * 更新打包商品信息 - */ - @Transactional(rollbackFor = Exception.class) - public void editPackGoodsAndSku(UpdateGoodsAndSkuParam param){ - // 更新商品 - UpdateGoodsParam updateGoodsParam = param.getGoodsParam(); - Goods oldGoods = goodsFactory.construct(updateGoodsParam); - Goods goods = goodsManager.findById(oldGoods.getId()) - .orElseThrow(() -> new BizException("商品不存在")); - BeanUtil.copyProperties(oldGoods,goods, CopyOptions.create().ignoreNullValue()); - // 删除 - List deleteIds = param.getDeleteIds(); - goodsManager.deleteByIds(deleteIds); - - // 新增 - skuPackService.addPackSkus(param.getCreateSkuParams(), goods); - - // 更新 - skuPackService.updatePackSkus(param.getUpdateSkuParams()); - - // 更新价格 - this.updatePrice(goods); - goodsRepository.save(goods); - } - - /** - * 更新商品价格 - */ - private void updatePrice(Goods goods){ - BigDecimal upperPrice = goodsManager.getGoodsUpperPrice(goods.getId()); - BigDecimal lowerPrice = goodsManager.getGoodsLowerPrice(goods.getId()); - goods.setDisplayUpperPrice(upperPrice); - goods.setDisplayLowerPrice(lowerPrice); - } -} diff --git a/service-goods-center/service-goods-center-impl/src/main/java/cn/bootx/goodscenter/core/goods/service/GoodsService.java b/service-goods-center/service-goods-center-impl/src/main/java/cn/bootx/goodscenter/core/goods/service/GoodsService.java index b97a36e..e77e1fa 100644 --- a/service-goods-center/service-goods-center-impl/src/main/java/cn/bootx/goodscenter/core/goods/service/GoodsService.java +++ b/service-goods-center/service-goods-center-impl/src/main/java/cn/bootx/goodscenter/core/goods/service/GoodsService.java @@ -2,15 +2,16 @@ package cn.bootx.goodscenter.core.goods.service; import cn.bootx.common.web.util.ResultConvertUtils; import cn.bootx.goodscenter.core.goods.dao.GoodsManager; +import cn.bootx.goodscenter.core.goods.dao.GoodsRepository; import cn.bootx.goodscenter.core.goods.entity.Goods; import cn.bootx.goodscenter.core.sku.dao.GoodsSkuManager; import cn.bootx.goodscenter.dto.goods.GoodsDto; import cn.bootx.goodscenter.dto.sku.GoodsSkuDto; +import cn.bootx.goodscenter.param.goods.GoodsParam; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; import org.springframework.stereotype.Service; -import java.math.BigDecimal; import java.util.List; import java.util.Objects; @@ -23,9 +24,19 @@ import java.util.Objects; @Service @RequiredArgsConstructor public class GoodsService { + private final GoodsRepository goodsRepository; private final GoodsManager goodsManager; private final GoodsSkuManager goodsSkuManager; + + /** + * 新增商品 + */ + public GoodsDto add(GoodsParam goodsParam){ + Goods goods = Goods.init(goodsParam); + return goodsRepository.save(goods).toDto(); + } + /** * 查询全部 */ @@ -33,6 +44,7 @@ public class GoodsService { return ResultConvertUtils.dtoListConvert(goodsManager.findAll()); } + /** * 查询商品详情 */ @@ -50,7 +62,7 @@ public class GoodsService { /** * 获取商品信息 */ - public GoodsDto getInfo(Long goodsId){ + public GoodsDto findById(Long goodsId){ return goodsManager.findById(goodsId).map(Goods::toDto).orElse(null); } @@ -60,20 +72,4 @@ public class GoodsService { public List findByCategory(Long cid){ return ResultConvertUtils.dtoListConvert(goodsManager.findByCid(cid)); } - - /** - * 获取商品显示的价格下限 - */ - public BigDecimal getGoodsLowerPrice(Long goodsId){ - return goodsManager.getGoodsLowerPrice(goodsId); - } - - /** - * 获取商品显示的价格上限 - */ - public BigDecimal getGoodsUpperPrice(Long goodsId){ - return goodsManager.getGoodsUpperPrice(goodsId); - - } - } diff --git a/service-goods-center/service-goods-center-impl/src/main/java/cn/bootx/goodscenter/core/goods/service/OperateGoodsService.java b/service-goods-center/service-goods-center-impl/src/main/java/cn/bootx/goodscenter/core/goods/service/OperateGoodsService.java deleted file mode 100644 index 79c0f55..0000000 --- a/service-goods-center/service-goods-center-impl/src/main/java/cn/bootx/goodscenter/core/goods/service/OperateGoodsService.java +++ /dev/null @@ -1,61 +0,0 @@ -package cn.bootx.goodscenter.core.goods.service; - -/** -* 商品操作 -* @author xxm -* @date 2021/2/23 -*/ - -import cn.bootx.common.web.exception.BizException; -import cn.bootx.goodscenter.core.goods.dao.GoodsManager; -import cn.bootx.goodscenter.core.goods.dao.GoodsRepository; -import cn.bootx.goodscenter.core.goods.entity.Goods; -import cn.bootx.goodscenter.core.sku.dao.GoodsSkuManager; -import lombok.RequiredArgsConstructor; -import lombok.extern.slf4j.Slf4j; -import org.springframework.stereotype.Service; -import org.springframework.transaction.annotation.Transactional; - -import java.time.LocalDateTime; - -/** - * 创建商品Service - * @author xxm - * @date 2021/2/2 - */ -@Slf4j -@Service -@RequiredArgsConstructor -public class OperateGoodsService { - - private final GoodsRepository goodsRepository; - private final GoodsManager goodsManager; - private final GoodsSkuManager skuManager; - - /** - * 上架商品 - */ - @Transactional(rollbackFor = Exception.class) - public void saleOn(Long goodsId){ - Goods goods = goodsManager.findById(goodsId).orElseThrow(() -> new BizException("商品不存在")); - goods.setSaleState(1) - .setSaleOnTime(LocalDateTime.now()); - goodsRepository.save(goods); - // 更新sku状态 - skuManager.saleOnByGoods(goodsId); - } - - /** - * 下架商品 - */ - @Transactional(rollbackFor = Exception.class) - public void saleOff(Long goodsId){ - Goods goods = goodsManager.findById(goodsId).orElseThrow(() -> new BizException("商品不存在")); - goods.setSaleState(0) - .setSaleOffTime(LocalDateTime.now()); - goodsRepository.save(goods); - // 更新sku状态 - skuManager.saleOffByGoods(goodsId); - } - -} diff --git a/service-goods-center/service-goods-center-impl/src/main/java/cn/bootx/goodscenter/core/inventory/dao/InventoryRepository.java b/service-goods-center/service-goods-center-impl/src/main/java/cn/bootx/goodscenter/core/inventory/dao/InventoryRepository.java index 8ade9b0..d359594 100644 --- a/service-goods-center/service-goods-center-impl/src/main/java/cn/bootx/goodscenter/core/inventory/dao/InventoryRepository.java +++ b/service-goods-center/service-goods-center-impl/src/main/java/cn/bootx/goodscenter/core/inventory/dao/InventoryRepository.java @@ -13,15 +13,6 @@ import org.springframework.data.repository.query.Param; */ public interface InventoryRepository extends JpaRepository { - /** - * 查询打包品的指定SKU关联的所有被打包商品的SKU 可用库存最小值 - */ - @Query("SELECT min(sku.available) FROM GoodsSku sku" + - " WHERE sku.id IN (" + - " SELECT p.packedSkuId FROM GoodsSkuPack p WHERE p.goodsSkuId = :skuId AND p.tid = :tid" + - ")") - Integer getMinAvailable4Packing(@Param("skuId") Long skuId,@Param("tid")Long tid); - /** * 锁定库存 */ diff --git a/service-goods-center/service-goods-center-impl/src/main/java/cn/bootx/goodscenter/core/inventory/manager/InventoryManager.java b/service-goods-center/service-goods-center-impl/src/main/java/cn/bootx/goodscenter/core/inventory/manager/InventoryManager.java index 5695b33..f789327 100644 --- a/service-goods-center/service-goods-center-impl/src/main/java/cn/bootx/goodscenter/core/inventory/manager/InventoryManager.java +++ b/service-goods-center/service-goods-center-impl/src/main/java/cn/bootx/goodscenter/core/inventory/manager/InventoryManager.java @@ -106,11 +106,4 @@ public class InventoryManager { } log.info("库存操作,skuId:"+ skuId + ",扣减库存总数和sold正常扣除,count:" + amount); } - - /** - * 查询打包品的指定SKU关联的所有被打包商品的SKU 可用库存最小值 - */ - public Integer getMinAvailable4Packing(Long skuId) { - return repository.getMinAvailable4Packing(skuId,headerHolder.findTid()); - } } diff --git a/service-goods-center/service-goods-center-impl/src/main/java/cn/bootx/goodscenter/core/inventory/manager/InventoryTokenManager.java b/service-goods-center/service-goods-center-impl/src/main/java/cn/bootx/goodscenter/core/inventory/manager/InventoryTokenManager.java index 11e2012..cf194d3 100644 --- a/service-goods-center/service-goods-center-impl/src/main/java/cn/bootx/goodscenter/core/inventory/manager/InventoryTokenManager.java +++ b/service-goods-center/service-goods-center-impl/src/main/java/cn/bootx/goodscenter/core/inventory/manager/InventoryTokenManager.java @@ -7,7 +7,10 @@ import cn.hutool.core.collection.CollUtil; import lombok.RequiredArgsConstructor; import org.springframework.stereotype.Component; -import java.util.*; +import java.util.ArrayList; +import java.util.Collection; +import java.util.Map; +import java.util.Set; /** * 库存操作 Token 管理器 diff --git a/service-goods-center/service-goods-center-impl/src/main/java/cn/bootx/goodscenter/core/inventory/service/InventoryService.java b/service-goods-center/service-goods-center-impl/src/main/java/cn/bootx/goodscenter/core/inventory/service/InventoryService.java index 9a358bc..59c6027 100644 --- a/service-goods-center/service-goods-center-impl/src/main/java/cn/bootx/goodscenter/core/inventory/service/InventoryService.java +++ b/service-goods-center/service-goods-center-impl/src/main/java/cn/bootx/goodscenter/core/inventory/service/InventoryService.java @@ -1,6 +1,5 @@ package cn.bootx.goodscenter.core.inventory.service; -import cn.bootx.goodscenter.code.GoodsCenterCode; import cn.bootx.goodscenter.core.inventory.manager.InventoryManager; import cn.bootx.goodscenter.core.sku.dao.GoodsSkuManager; import cn.bootx.goodscenter.core.sku.entity.GoodsSku; @@ -26,25 +25,7 @@ public class InventoryService { */ public Integer getAvailable(Long skuId){ GoodsSku sku = skuManager.findById(skuId).orElseThrow(InventoryNotFoundException::new); - - // 无限库存 - if (sku.isUnlimited()) { - return GoodsCenterCode.CAPACITY_UNLIMITED; - } - - // 打包品与非打包库存 - if (sku.isPacking()){ - return this.getMinAvailable4Packing(skuId); - } else { - return sku.getAvailable(); - } - } - - /** - * 查询打包品的指定SKU关联的所有被打包商品的SKU 可用库存最小值 - */ - public Integer getMinAvailable4Packing(Long skuId) { - return inventoryManager.getMinAvailable4Packing(skuId); + return sku.getAvailable(); } } diff --git a/service-goods-center/service-goods-center-impl/src/main/java/cn/bootx/goodscenter/core/inventory/service/OperateInventoryService.java b/service-goods-center/service-goods-center-impl/src/main/java/cn/bootx/goodscenter/core/inventory/service/OperateInventoryService.java index 48916e4..2c40732 100644 --- a/service-goods-center/service-goods-center-impl/src/main/java/cn/bootx/goodscenter/core/inventory/service/OperateInventoryService.java +++ b/service-goods-center/service-goods-center-impl/src/main/java/cn/bootx/goodscenter/core/inventory/service/OperateInventoryService.java @@ -1,11 +1,8 @@ package cn.bootx.goodscenter.core.inventory.service; import cn.bootx.common.web.exception.BizException; -import cn.bootx.goodscenter.core.inventory.handler.PackedInventoryHandler; import cn.bootx.goodscenter.core.inventory.manager.InventoryManager; import cn.bootx.goodscenter.core.inventory.manager.InventoryTokenContainer; -import cn.bootx.goodscenter.core.packing.dao.GoodsSkuPackManager; -import cn.bootx.goodscenter.core.packing.entity.GoodsSkuPack; import cn.bootx.goodscenter.core.sku.dao.GoodsSkuManager; import cn.bootx.goodscenter.core.sku.entity.GoodsSku; import cn.bootx.goodscenter.dto.inventory.LockInventoryDto; @@ -16,8 +13,6 @@ import lombok.extern.slf4j.Slf4j; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; -import java.util.List; - /** * 库存操作 * @author xxm @@ -30,7 +25,6 @@ public class OperateInventoryService { private final InventoryTokenContainer tokenContainer; private final GoodsSkuManager skuManager; - private final GoodsSkuPackManager skuPackingManager; private final InventoryManager inventoryManager; /** @@ -47,10 +41,6 @@ public class OperateInventoryService { result.setCount(count); GoodsSku sku = skuManager.findById(skuId).orElseThrow(InventoryNotFoundException::new); - // 处理打包品的预占库存 - if (sku.isPacking()){ - this.inventory4Packing(skuId, count, inventoryManager::lockInventory); - } inventoryManager.lockInventory(skuId, count); result.setStartIndex(sku.getLocked() + sku.getSold() + 1); @@ -74,11 +64,7 @@ public class OperateInventoryService { */ @Transactional(rollbackFor = Exception.class) public void unlockInventoryWithoutToken(Long skuId, int count) { - GoodsSku goodsSku = skuManager.findById(skuId).orElseThrow(InventoryNotFoundException::new); - // 打包品处理 - if (goodsSku.isPacking()) { - this.inventory4Packing(skuId, count, inventoryManager::unlockInventory); - } + skuManager.findById(skuId).orElseThrow(InventoryNotFoundException::new); // 自身处理 inventoryManager.unlockInventory(skuId, count); } @@ -88,11 +74,7 @@ public class OperateInventoryService { */ @Transactional(rollbackFor = Exception.class) public void reduceInventory(Long skuId, int count, String token) { - GoodsSku goodsSku = skuManager.findById(skuId).orElseThrow(InventoryNotFoundException::new); - // 打包品处理 - if (goodsSku.isPacking()) { - this.inventory4Packing(skuId, count, inventoryManager::reduceInventory); - } + skuManager.findById(skuId).orElseThrow(InventoryNotFoundException::new); inventoryManager.reduceInventory(skuId, count); tokenContainer.consumeInventory(skuId, count, token); } @@ -102,11 +84,7 @@ public class OperateInventoryService { */ @Transactional(rollbackFor = Exception.class) public void increaseInventory(Long skuId, int count) { - GoodsSku goodsSku = skuManager.findById(skuId).orElseThrow(InventoryNotFoundException::new); - // 打包品处理 - if (goodsSku.isPacking()) { - this.inventory4Packing(skuId, count, inventoryManager::increaseInventory); - } + skuManager.findById(skuId).orElseThrow(InventoryNotFoundException::new); inventoryManager.increaseInventory(skuId, count); } @@ -115,11 +93,7 @@ public class OperateInventoryService { */ @Transactional(rollbackFor = Exception.class) public void increaseAvailable(Long skuId, int count) { - GoodsSku goodsSku = skuManager.findById(skuId).orElseThrow(InventoryNotFoundException::new); - // 打包品处理 - if (goodsSku.isPacking()) { - this.inventory4Packing(skuId, count, inventoryManager::increaseAvailable); - } + skuManager.findById(skuId).orElseThrow(InventoryNotFoundException::new); inventoryManager.increaseAvailable(skuId, count); } @@ -128,11 +102,7 @@ public class OperateInventoryService { */ @Transactional(rollbackFor = Exception.class) public void reduceLockedAndCapacity(Long skuId, int count, String token) { - GoodsSku goodsSku = skuManager.findById(skuId).orElseThrow(InventoryNotFoundException::new); - // 打包品处理 - if (goodsSku.isPacking()) { - this.inventory4Packing(skuId, count, inventoryManager::reduceLockedAndCapacity); - } + skuManager.findById(skuId).orElseThrow(InventoryNotFoundException::new); tokenContainer.consumeInventory(skuId, count, token); inventoryManager.reduceLockedAndCapacity(skuId, count); } @@ -142,27 +112,7 @@ public class OperateInventoryService { */ @Transactional(rollbackFor = Exception.class) public void reduceSoldAndCapacity(Long skuId, int count) { - GoodsSku goodsSku = skuManager.findById(skuId).orElseThrow(InventoryNotFoundException::new); - - // 打包品处理 - if (goodsSku.isPacking()) { - this.inventory4Packing(skuId, count, inventoryManager::reduceSoldAndCapacity); - } + skuManager.findById(skuId).orElseThrow(InventoryNotFoundException::new); inventoryManager.reduceSoldAndCapacity(skuId, count); } - - /** - * 打包品处理 - * @param skuId skuId - * @param count 数量 - * @param handler 被打包商品库存处理器 - */ - private void inventory4Packing(Long skuId, int count, PackedInventoryHandler handler) { - - // 自身是打包品,则处理被打包品的库存 - List goodsSkuPacks = skuPackingManager.findBySkuId(skuId); - - // 处理关联的被打包品 - goodsSkuPacks.forEach(packedSku -> handler.handle(packedSku.getPackedSkuId(), count)); - } } \ No newline at end of file diff --git a/service-goods-center/service-goods-center-impl/src/main/java/cn/bootx/goodscenter/core/packing/dao/GoodsSkuPackManager.java b/service-goods-center/service-goods-center-impl/src/main/java/cn/bootx/goodscenter/core/packing/dao/GoodsSkuPackManager.java deleted file mode 100644 index 35ecb2c..0000000 --- a/service-goods-center/service-goods-center-impl/src/main/java/cn/bootx/goodscenter/core/packing/dao/GoodsSkuPackManager.java +++ /dev/null @@ -1,35 +0,0 @@ -package cn.bootx.goodscenter.core.packing.dao; - -import cn.bootx.goodscenter.core.packing.entity.GoodsSkuPack; -import cn.bootx.starter.headerholder.HeaderHolder; -import com.querydsl.jpa.impl.JPAQueryFactory; -import lombok.RequiredArgsConstructor; -import org.springframework.stereotype.Repository; - -import java.util.List; - -/** -* sku打包 -* @author xxm -* @date 2020/11/22 -*/ -@Repository -@RequiredArgsConstructor -public class GoodsSkuPackManager { - private final GoodsSkuPackRepository skuPackingRepository; - private final JPAQueryFactory jpaQueryFactory; - - private final HeaderHolder headerHolder; - - public void deleteBySkuId(Long skuId) { - skuPackingRepository.deleteByGoodsSkuIdAndTid(skuId,headerHolder.findTid()); - } - - public void deleteBySkuIds(List skuIds) { - skuPackingRepository.deleteByGoodsSkuIdInAndTid(skuIds,headerHolder.findTid()); - } - - public List findBySkuId(Long skuId) { - return skuPackingRepository.findAllByGoodsSkuIdAndTid(skuId,headerHolder.findTid()); - } -} diff --git a/service-goods-center/service-goods-center-impl/src/main/java/cn/bootx/goodscenter/core/packing/dao/GoodsSkuPackRepository.java b/service-goods-center/service-goods-center-impl/src/main/java/cn/bootx/goodscenter/core/packing/dao/GoodsSkuPackRepository.java deleted file mode 100644 index cef5763..0000000 --- a/service-goods-center/service-goods-center-impl/src/main/java/cn/bootx/goodscenter/core/packing/dao/GoodsSkuPackRepository.java +++ /dev/null @@ -1,16 +0,0 @@ -package cn.bootx.goodscenter.core.packing.dao; - -import cn.bootx.goodscenter.core.packing.entity.GoodsSkuPack; -import org.springframework.data.jpa.repository.JpaRepository; - -import java.util.List; -import java.util.Optional; - -public interface GoodsSkuPackRepository extends JpaRepository { - void deleteByGoodsSkuIdAndTid(Long skuId, Long tid); - void deleteByGoodsSkuIdInAndTid(List skuId, Long tid); - - List findAllByGoodsSkuIdAndTid(Long skuId, Long tid); - - Optional findSkuByPackedSkuIdAndTid(Long packedSkuId, Long tid); -} diff --git a/service-goods-center/service-goods-center-impl/src/main/java/cn/bootx/goodscenter/core/packing/entity/GoodsSkuPack.java b/service-goods-center/service-goods-center-impl/src/main/java/cn/bootx/goodscenter/core/packing/entity/GoodsSkuPack.java deleted file mode 100644 index 51caf9c..0000000 --- a/service-goods-center/service-goods-center-impl/src/main/java/cn/bootx/goodscenter/core/packing/entity/GoodsSkuPack.java +++ /dev/null @@ -1,53 +0,0 @@ -package cn.bootx.goodscenter.core.packing.entity; - -import cn.bootx.common.function.EntityBaseFunction; -import cn.bootx.common.web.code.CommonCode; -import cn.bootx.goodscenter.dto.packing.GoodsSkuPackingDto; -import cn.bootx.starter.jpa.base.JpaBaseEntity; -import lombok.Data; -import lombok.EqualsAndHashCode; -import lombok.experimental.Accessors; -import org.hibernate.annotations.SQLDelete; -import org.hibernate.annotations.Where; -import org.springframework.beans.BeanUtils; - -import javax.persistence.Entity; -import javax.persistence.Table; - -/** -* 打包品SKU关联关系 -* @author xxm -* @date 2020/11/22 -*/ -@EqualsAndHashCode(callSuper = true) -@Entity -@Data -@Accessors(chain = true) -@Table(name = "gc_goods_sku_packing") -@SQLDelete(sql = "update gc_goods_sku_packing set deleted=" + CommonCode.DELETE_FLAG + " where id=? and version=? ") -@Where(clause = "deleted=" + CommonCode.NORMAL_FLAG) -public class GoodsSkuPack extends JpaBaseEntity implements EntityBaseFunction { - - /** 打包品 id */ - private Long goodsId; - /** 打包品 SKU id */ - private Long goodsSkuId; - /** 被打包品 id */ - private Long packedGoodsId; - /** 被打包品SKU id */ - private Long packedSkuId; - - public static GoodsSkuPack init(GoodsSkuPackingDto dto) { - GoodsSkuPack entity = new GoodsSkuPack(); - BeanUtils.copyProperties(dto, entity); - return entity; - } - - @Override - public GoodsSkuPackingDto toDto() { - GoodsSkuPackingDto dto = new GoodsSkuPackingDto(); - BeanUtils.copyProperties(this, dto); - return dto; - } - -} diff --git a/service-goods-center/service-goods-center-impl/src/main/java/cn/bootx/goodscenter/core/packing/service/GoodsSkuPackService.java b/service-goods-center/service-goods-center-impl/src/main/java/cn/bootx/goodscenter/core/packing/service/GoodsSkuPackService.java deleted file mode 100644 index f9bcacf..0000000 --- a/service-goods-center/service-goods-center-impl/src/main/java/cn/bootx/goodscenter/core/packing/service/GoodsSkuPackService.java +++ /dev/null @@ -1,132 +0,0 @@ -package cn.bootx.goodscenter.core.packing.service; - -import cn.bootx.common.web.util.ResultConvertUtils; -import cn.bootx.goodscenter.core.attributes.handler.AttrGenHandler; -import cn.bootx.goodscenter.core.goods.entity.Goods; -import cn.bootx.goodscenter.core.packing.dao.GoodsSkuPackManager; -import cn.bootx.goodscenter.core.packing.dao.GoodsSkuPackRepository; -import cn.bootx.goodscenter.core.packing.entity.GoodsSkuPack; -import cn.bootx.goodscenter.core.sku.dao.GoodsSkuAttrManager; -import cn.bootx.goodscenter.core.sku.dao.GoodsSkuAttrRepository; -import cn.bootx.goodscenter.core.sku.dao.GoodsSkuManager; -import cn.bootx.goodscenter.core.sku.dao.GoodsSkuRepository; -import cn.bootx.goodscenter.core.sku.entity.GoodsSku; -import cn.bootx.goodscenter.core.sku.entity.GoodsSkuAttr; -import cn.bootx.goodscenter.core.sku.factory.GoodsSkuFactory; -import cn.bootx.goodscenter.dto.packing.GoodsSkuPackingDto; -import cn.bootx.goodscenter.param.sku.CreateSkuParam; -import cn.bootx.goodscenter.param.sku.UpdateSkuParam; -import cn.bootx.starter.snowflake.SnowFlakeId; -import cn.hutool.core.bean.BeanUtil; -import lombok.RequiredArgsConstructor; -import lombok.extern.slf4j.Slf4j; -import org.springframework.stereotype.Service; - -import java.util.ArrayList; -import java.util.List; -import java.util.Map; -import java.util.stream.Collectors; - -/** -* 打包品(未开发完) -* @author xxm -* @date 2020/11/26 -*/ -@Slf4j -@Service -@RequiredArgsConstructor -public class GoodsSkuPackService { - private final GoodsSkuPackRepository skuPackRepository; - private final GoodsSkuPackManager skuPackManager; - private final GoodsSkuRepository skuRepository; - private final GoodsSkuManager skuManager; - private final GoodsSkuFactory skuFactory; - private final GoodsSkuAttrRepository skuAttrRepository; - private final GoodsSkuAttrManager skuAttrManager; - - private final SnowFlakeId snowFlakeId; - - /** - * 构建打包品关系 - */ - public List constructPackSku(GoodsSku sku, List packedSkuIds){ - return this.constructPackSku(sku.getGoodsId(),sku.getId(),packedSkuIds); - } - - /** - * 构建打包品关系 - */ - public List constructPackSku(Long goodsId, Long skuId, List packedSkuIds){ - return packedSkuIds.stream() - .map(packedSkuId-> new GoodsSkuPack() - .setGoodsId(goodsId) - .setGoodsSkuId(skuId) - .setPackedSkuId(packedSkuId) - ).collect(Collectors.toList()); - } - - /** - * 通过打包商品SKU id 获取其SKU关联被打包品信息 - */ - public List findBySkuId(Long skuId){ - return ResultConvertUtils.dtoListConvert(skuPackManager.findBySkuId(skuId)); - } - - /** - * 新增打包sku - */ - public List addPackSkus(List skuParams, Goods goods){ - List skus = new ArrayList<>(skuParams.size()); - List skuPacks = new ArrayList<>(); - for (CreateSkuParam skuParam : skuParams) { - long skuId = snowFlakeId.nextId(); - skuParam.setGoodsId(goods.getId()) - .setPacking(true) - .setCid(goods.getCid()); - GoodsSku sku = skuFactory.construct(skuParam); - sku.setId(skuId); - skus.add(sku); - List goodsSkuPacks = this.constructPackSku(sku, skuParam.getPackedSkuIds()); - skuPacks.addAll(goodsSkuPacks); - } - // 保存sku和打包关系 - List goodsSkus = skuRepository.saveAll(skus); - skuPackRepository.saveAll(skuPacks); - return goodsSkus; - } - - /** - * 更新 打包商品 - */ - public void updatePackSkus(List updateSkuParams){ - List oldSkus = updateSkuParams.stream() - .map(skuFactory::construct) - .collect(Collectors.toList()); - List skuIds = oldSkus.stream().map(GoodsSku::getId).collect(Collectors.toList()); - List newSkus = skuManager.findByIds(skuIds); - Map skuMap = oldSkus.stream().collect(Collectors.toMap(GoodsSku::getId, o -> o)); - - // 更新sku信息 - for (GoodsSku goodsSku : newSkus) { - BeanUtil.copyProperties(skuMap.get(goodsSku.getId()),goodsSku); - } - skuRepository.saveAll(newSkus); - - // 更新关联属性 先删后增 - skuAttrManager.deleteBySkuIds(skuIds); - List goodsSkuAttrs = AttrGenHandler.genSkuAttrsBySkus(newSkus); - skuAttrRepository.saveAll(goodsSkuAttrs); - - // 更新关联关系 先删后增 - List skuPacks = new ArrayList<>(); - for (UpdateSkuParam skuParam : updateSkuParams) { - List goodsSkuPacks = this - .constructPackSku(skuParam.getGoodsId(),skuParam.getId(),skuParam.getPackedSkuIds()); - skuPacks.addAll(goodsSkuPacks); - } - skuPackManager.deleteBySkuIds(skuIds); - skuPackRepository.saveAll(skuPacks); - } - - -} diff --git a/service-goods-center/service-goods-center-impl/src/main/java/cn/bootx/goodscenter/core/sku/convert/SkuConvert.java b/service-goods-center/service-goods-center-impl/src/main/java/cn/bootx/goodscenter/core/sku/convert/SkuConvert.java new file mode 100644 index 0000000..3438a99 --- /dev/null +++ b/service-goods-center/service-goods-center-impl/src/main/java/cn/bootx/goodscenter/core/sku/convert/SkuConvert.java @@ -0,0 +1,27 @@ +package cn.bootx.goodscenter.core.sku.convert; + +import cn.bootx.goodscenter.core.sku.entity.GoodsSku; +import cn.bootx.goodscenter.dto.sku.GoodsSkuDto; +import cn.bootx.goodscenter.param.sku.SkuParam; +import org.mapstruct.Mapper; +import org.mapstruct.Mappings; +import org.mapstruct.factory.Mappers; + +/** +* 转换 +* @author xxm +* @date 2021/7/23 +*/ +@Mapper +public interface SkuConvert { + SkuConvert CONVERT = Mappers.getMapper(SkuConvert.class); + + @Mappings({}) + GoodsSku convert(SkuParam in); + + @Mappings({}) + GoodsSku convert(GoodsSkuDto in); + + @Mappings({}) + GoodsSkuDto convert(GoodsSku in); +} diff --git a/service-goods-center/service-goods-center-impl/src/main/java/cn/bootx/goodscenter/core/sku/dao/GoodsSkuAttrManager.java b/service-goods-center/service-goods-center-impl/src/main/java/cn/bootx/goodscenter/core/sku/dao/GoodsSkuAttrManager.java deleted file mode 100644 index 16f660f..0000000 --- a/service-goods-center/service-goods-center-impl/src/main/java/cn/bootx/goodscenter/core/sku/dao/GoodsSkuAttrManager.java +++ /dev/null @@ -1,34 +0,0 @@ -package cn.bootx.goodscenter.core.sku.dao; - -import cn.bootx.goodscenter.core.sku.entity.GoodsSkuAttr; -import cn.bootx.starter.headerholder.HeaderHolder; -import com.querydsl.jpa.impl.JPAQueryFactory; -import lombok.RequiredArgsConstructor; -import org.springframework.stereotype.Repository; - -import java.util.List; - -/** -* sku属性 -* @author xxm -* @date 2020/11/21 -*/ -@Repository -@RequiredArgsConstructor -public class GoodsSkuAttrManager { - private final GoodsSkuAttrRepository skuAttrRepository; - private final JPAQueryFactory jpaQueryFactory; - - private final HeaderHolder headerHolder; - - public List findBySkuId(Long skuId) { - return skuAttrRepository.findBySkuIdAndTid(skuId,headerHolder.findTid()); - } - - /** - * 根据skuIds删除 - */ - public void deleteBySkuIds(List skuIds) { - skuAttrRepository.deleteBySkuIdInAndTid(skuIds,headerHolder.findTid()); - } -} diff --git a/service-goods-center/service-goods-center-impl/src/main/java/cn/bootx/goodscenter/core/sku/dao/GoodsSkuAttrRepository.java b/service-goods-center/service-goods-center-impl/src/main/java/cn/bootx/goodscenter/core/sku/dao/GoodsSkuAttrRepository.java deleted file mode 100644 index 9ac0862..0000000 --- a/service-goods-center/service-goods-center-impl/src/main/java/cn/bootx/goodscenter/core/sku/dao/GoodsSkuAttrRepository.java +++ /dev/null @@ -1,13 +0,0 @@ -package cn.bootx.goodscenter.core.sku.dao; - -import cn.bootx.goodscenter.core.sku.entity.GoodsSkuAttr; -import org.springframework.data.jpa.repository.JpaRepository; - -import java.util.List; - -public interface GoodsSkuAttrRepository extends JpaRepository { - - List findBySkuIdAndTid(Long skuId, Long tid); - - void deleteBySkuIdInAndTid(List skuIds,Long tid); -} diff --git a/service-goods-center/service-goods-center-impl/src/main/java/cn/bootx/goodscenter/core/sku/dao/GoodsSkuManager.java b/service-goods-center/service-goods-center-impl/src/main/java/cn/bootx/goodscenter/core/sku/dao/GoodsSkuManager.java index 418b35a..ce61811 100644 --- a/service-goods-center/service-goods-center-impl/src/main/java/cn/bootx/goodscenter/core/sku/dao/GoodsSkuManager.java +++ b/service-goods-center/service-goods-center-impl/src/main/java/cn/bootx/goodscenter/core/sku/dao/GoodsSkuManager.java @@ -6,7 +6,6 @@ import com.querydsl.jpa.impl.JPAQueryFactory; import lombok.RequiredArgsConstructor; import org.springframework.stereotype.Repository; -import java.time.LocalDateTime; import java.util.List; import java.util.Optional; @@ -31,29 +30,9 @@ public class GoodsSkuManager { return goodsSkuRepository.findAllByGoodsIdAndTid(goodsId,headerHolder.findTid()); } - /** - * 按商品编号和属性值查找 - */ - public List findByGoodsIdAndAttrValuesIn(Long goodsId, List attrValues) { - return goodsSkuRepository.findByGoodsIdAndAttrValuesInAndTid(goodsId,attrValues,headerHolder.findTid()); - } - public List findByIds(List skuIds) { return goodsSkuRepository.findByIdInAndTid(skuIds,headerHolder.findTid()); } - /** - * 上架 - */ - public void saleOnByGoods(Long goodsId) { - goodsSkuRepository.saleOnByGoodsAndTid(goodsId, LocalDateTime.now(),headerHolder.findTid()); - } - - /** - * 下架 - */ - public void saleOffByGoods(Long goodsId) { - goodsSkuRepository.saleOffByGoodsAndTid(goodsId, LocalDateTime.now(),headerHolder.findTid()); - } } diff --git a/service-goods-center/service-goods-center-impl/src/main/java/cn/bootx/goodscenter/core/sku/dao/GoodsSkuRepository.java b/service-goods-center/service-goods-center-impl/src/main/java/cn/bootx/goodscenter/core/sku/dao/GoodsSkuRepository.java index b25dcba..e3f943a 100644 --- a/service-goods-center/service-goods-center-impl/src/main/java/cn/bootx/goodscenter/core/sku/dao/GoodsSkuRepository.java +++ b/service-goods-center/service-goods-center-impl/src/main/java/cn/bootx/goodscenter/core/sku/dao/GoodsSkuRepository.java @@ -1,13 +1,8 @@ package cn.bootx.goodscenter.core.sku.dao; -import cn.bootx.goodscenter.code.SkuSalesStateCode; import cn.bootx.goodscenter.core.sku.entity.GoodsSku; import org.springframework.data.jpa.repository.JpaRepository; -import org.springframework.data.jpa.repository.Modifying; -import org.springframework.data.jpa.repository.Query; -import org.springframework.data.repository.query.Param; -import java.time.LocalDateTime; import java.util.List; import java.util.Optional; @@ -16,17 +11,6 @@ public interface GoodsSkuRepository extends JpaRepository { List findAllByGoodsIdAndTid(Long goodsId, Long tid); - List findByGoodsIdAndAttrValuesInAndTid(Long goodsId, List attrValues,Long tid); List findByIdInAndTid(List skuIds, Long tid); - - @Query("update GoodsSku set saleState = "+ SkuSalesStateCode.ON +",saleOnTime = :now,version=version+1 " + - "where goodsId =:goodsId and tid = :tid") - @Modifying - void saleOnByGoodsAndTid(@Param("goodsId") Long goodsId, @Param("now") LocalDateTime now, @Param("tid") Long tid); - - @Query("update GoodsSku set saleState = "+ SkuSalesStateCode.OFF_GOODS +",saleOnTime = :now,version=version+1 " + - "where goodsId =:goodsId and tid = :tid") - @Modifying - void saleOffByGoodsAndTid(Long goodsId, LocalDateTime now, Long tid); } diff --git a/service-goods-center/service-goods-center-impl/src/main/java/cn/bootx/goodscenter/core/sku/entity/GoodsSku.java b/service-goods-center/service-goods-center-impl/src/main/java/cn/bootx/goodscenter/core/sku/entity/GoodsSku.java index 6af70d7..6287aab 100644 --- a/service-goods-center/service-goods-center-impl/src/main/java/cn/bootx/goodscenter/core/sku/entity/GoodsSku.java +++ b/service-goods-center/service-goods-center-impl/src/main/java/cn/bootx/goodscenter/core/sku/entity/GoodsSku.java @@ -2,21 +2,20 @@ package cn.bootx.goodscenter.core.sku.entity; import cn.bootx.common.function.EntityBaseFunction; import cn.bootx.common.web.code.CommonCode; +import cn.bootx.goodscenter.core.sku.convert.SkuConvert; import cn.bootx.goodscenter.dto.sku.GoodsSkuDto; +import cn.bootx.goodscenter.param.sku.SkuParam; import cn.bootx.starter.jpa.base.JpaBaseEntity; import lombok.Data; import lombok.EqualsAndHashCode; import lombok.experimental.Accessors; import org.hibernate.annotations.SQLDelete; import org.hibernate.annotations.Where; -import org.springframework.beans.BeanUtils; import javax.persistence.Column; import javax.persistence.Entity; import javax.persistence.Table; -import javax.persistence.Transient; import java.math.BigDecimal; -import java.time.LocalDateTime; /** * 商品 SKU @@ -34,34 +33,16 @@ public class GoodsSku extends JpaBaseEntity implements EntityBaseFunction { - - /** 商品 类目 id */ - private Long cid; - - /** 所属商品 id */ - private Long goodsId; - - /** 商品 SKU id */ - private Long skuId; - - /** 属性定义 id */ - private Long attrDefId; - - /** 属性值 */ - private String attrValue; - - /** 显示值 */ - private String attrValueDisplays; - - public static GoodsSkuAttr init(GoodsSkuAttrDto dto) { - GoodsSkuAttr entity = new GoodsSkuAttr(); - BeanUtils.copyProperties(dto, entity); - return entity; - } - - @Override - public GoodsSkuAttrDto toDto() { - GoodsSkuAttrDto dto = new GoodsSkuAttrDto(); - BeanUtils.copyProperties(this, dto); - return dto; - } -} diff --git a/service-goods-center/service-goods-center-impl/src/main/java/cn/bootx/goodscenter/core/sku/factory/GoodsSkuFactory.java b/service-goods-center/service-goods-center-impl/src/main/java/cn/bootx/goodscenter/core/sku/factory/GoodsSkuFactory.java deleted file mode 100644 index 8529dd3..0000000 --- a/service-goods-center/service-goods-center-impl/src/main/java/cn/bootx/goodscenter/core/sku/factory/GoodsSkuFactory.java +++ /dev/null @@ -1,55 +0,0 @@ -package cn.bootx.goodscenter.core.sku.factory; - -import cn.bootx.goodscenter.core.sku.entity.GoodsSku; -import cn.bootx.goodscenter.dto.sku.GoodsSkuDto; -import cn.bootx.goodscenter.param.sku.CreateSkuParam; -import cn.bootx.goodscenter.param.sku.UpdateSkuParam; -import lombok.RequiredArgsConstructor; -import org.springframework.beans.BeanUtils; -import org.springframework.stereotype.Component; - -import java.util.List; -import java.util.stream.Collectors; - -/** -* sku工厂 -* @author xxm -* @date 2021/2/2 -*/ -@Component -@RequiredArgsConstructor -public class GoodsSkuFactory { - - /** - * 构建 - */ - public GoodsSku construct(CreateSkuParam skuParam){ - GoodsSku goodsSku = new GoodsSku(); - BeanUtils.copyProperties(skuParam,goodsSku); - goodsSku.setAttrDefIds(String.join(",", skuParam.getAttrDefIdList())); - goodsSku.setAttrValues(String.join(",", skuParam.getAttrValueList())); - goodsSku.setAttrValueDisplays(String.join(",", skuParam.getAttrValueDisplayList())); - return goodsSku; - } - - /** - * 构建 - */ - public GoodsSku construct(UpdateSkuParam skuParam){ - GoodsSku goodsSku = new GoodsSku(); - BeanUtils.copyProperties(skuParam,goodsSku); - goodsSku.setAttrDefIds(String.join(",", skuParam.getAttrDefIdList())); - goodsSku.setAttrValues(String.join(",", skuParam.getAttrValueList())); - goodsSku.setAttrValueDisplays(String.join(",", skuParam.getAttrValueDisplayList())); - return goodsSku; - } - - /** - * 转换成DTO - */ - public List convertGoodsToDto(List poList) { - return poList.stream() - .map(GoodsSku::toDto) - .collect(Collectors.toList()); - } -} diff --git a/service-goods-center/service-goods-center-impl/src/main/java/cn/bootx/goodscenter/core/sku/service/GoodsSkuGenService.java b/service-goods-center/service-goods-center-impl/src/main/java/cn/bootx/goodscenter/core/sku/service/GoodsSkuGenService.java deleted file mode 100644 index b33f173..0000000 --- a/service-goods-center/service-goods-center-impl/src/main/java/cn/bootx/goodscenter/core/sku/service/GoodsSkuGenService.java +++ /dev/null @@ -1,86 +0,0 @@ -package cn.bootx.goodscenter.core.sku.service; - -import cn.bootx.goodscenter.core.sku.dao.GoodsSkuManager; -import cn.bootx.goodscenter.core.sku.entity.GoodsSku; -import cn.bootx.goodscenter.core.sku.factory.GoodsSkuFactory; -import cn.bootx.goodscenter.core.attributes.handler.AttrGenHandler; -import cn.bootx.goodscenter.core.category.handler.ValueDisplayPair; -import cn.bootx.goodscenter.dto.sku.GoodsSkuDto; -import cn.bootx.goodscenter.param.sku.GenSkuAttrParam; -import cn.bootx.goodscenter.param.sku.GenSkuParam; -import lombok.RequiredArgsConstructor; -import lombok.extern.slf4j.Slf4j; -import org.springframework.stereotype.Service; - -import java.util.ArrayList; -import java.util.List; -import java.util.Map; -import java.util.Objects; - -/** - * 商品sku生成Service - * @author xxm - * @date 2021/2/2 - */ -@Slf4j -@Service -@RequiredArgsConstructor -public class GoodsSkuGenService { - private final GoodsSkuManager goodsSkuManager; - private final GoodsSkuFactory goodsSkuFactory; - - /** - * 根据商品 SKU 属性生成对应的商品 SKU - * - * 若商品 SKU 已存在,则直接使用已存在的数据; - * 若商品 SKU 未存在,则创建一个内存级的 SKU DTO。 - */ - public List genSkuByAttrs(GenSkuParam genSkuParam){ - List goodsSkus = new ArrayList<>(); - List skuAttrList = genSkuParam.getSkuAttrList(); - Long goodsId = genSkuParam.getGoodsId(); - - List> skuAttrValues = AttrGenHandler.extractSkuAttrValues(skuAttrList); - - // 1,形成笛卡尔积的形式,如 1_a_X 形式(key:所有属性值拼接的字符串,value:所有属性显示值拼接的字符串) - Map valueMap = AttrGenHandler.calculateDescartes(skuAttrValues); - List attrValues = new ArrayList<>(valueMap.keySet()); - - // 2,根据goodsId和属性值列表,查询所有已存在的商品SKU - String attrDefIds = this.extractSkuAttrDefIds(skuAttrList); - - // 3,根据goodsId和属性值列表,查询所有已存在的商品SKU - if (Objects.nonNull(goodsId)) { - List goodsSkuList = goodsSkuManager.findByGoodsIdAndAttrValuesIn(goodsId, attrValues); - // 添加已存在的 - goodsSkus.addAll(goodsSkuFactory.convertGoodsToDto(goodsSkuList)); - - // 去掉所有已存在的项 - for (GoodsSku goodsSku : goodsSkuList) { - attrValues.remove(goodsSku.getAttrValues()); - } - } - - // 4,为剩下的项创建对应的 GoodsSkuDto - for (String attrValue : attrValues) { - GoodsSkuDto skuDto = new GoodsSkuDto() - .setGoodsId(goodsId) - .setAttrDefIds(attrDefIds) - .setAttrValues(attrValue) - .setAttrValueDisplays(valueMap.get(attrValue)); - goodsSkus.add(skuDto); - } - return goodsSkus; - } - - /** - * 提取 SkuAttrDefIds(属性定义id数组) 属性 - */ - private String extractSkuAttrDefIds(List skuAttrList) { - StringBuilder result = new StringBuilder(); - for (GenSkuAttrParam skuAttrParam : skuAttrList) { - result.append(",").append(skuAttrParam.getAttrDefId()); - } - return result.substring(1); - } -} diff --git a/service-goods-center/service-goods-center-impl/src/main/java/cn/bootx/goodscenter/core/sku/service/GoodsSkuOperateService.java b/service-goods-center/service-goods-center-impl/src/main/java/cn/bootx/goodscenter/core/sku/service/GoodsSkuOperateService.java deleted file mode 100644 index 1aa053c..0000000 --- a/service-goods-center/service-goods-center-impl/src/main/java/cn/bootx/goodscenter/core/sku/service/GoodsSkuOperateService.java +++ /dev/null @@ -1,41 +0,0 @@ -package cn.bootx.goodscenter.core.sku.service; - -import cn.bootx.goodscenter.core.attributes.handler.AttrGenHandler; -import cn.bootx.goodscenter.core.sku.dao.GoodsSkuAttrRepository; -import cn.bootx.goodscenter.core.sku.dao.GoodsSkuRepository; -import cn.bootx.goodscenter.core.sku.entity.GoodsSku; -import cn.bootx.goodscenter.core.sku.entity.GoodsSkuAttr; -import cn.bootx.goodscenter.core.sku.factory.GoodsSkuFactory; -import cn.bootx.goodscenter.dto.sku.GoodsSkuDto; -import cn.bootx.goodscenter.param.sku.CreateSkuParam; -import lombok.RequiredArgsConstructor; -import lombok.extern.slf4j.Slf4j; -import org.springframework.stereotype.Service; - -import java.util.List; - -/** -* 商品sku操作类 -* @author xxm -* @date 2021/5/6 -*/ -@Slf4j -@Service -@RequiredArgsConstructor -public class GoodsSkuOperateService { - private final GoodsSkuFactory goodsSkuFactory; - private final GoodsSkuRepository goodsSkuRepository; - private final GoodsSkuAttrRepository skuAttrRepository; - - /** - * 添加sku - */ - public GoodsSkuDto add(CreateSkuParam skuParam){ - GoodsSku goodsSku = goodsSkuFactory.construct(skuParam); - goodsSku.setPacking(false); - goodsSkuRepository.save(goodsSku); - List goodsSkuAttrs = AttrGenHandler.genSkuAttrsBySku(goodsSku); - skuAttrRepository.saveAll(goodsSkuAttrs); - return goodsSku.toDto(); - } -} diff --git a/service-goods-center/service-goods-center-impl/src/main/java/cn/bootx/goodscenter/core/sku/service/GoodsSkuService.java b/service-goods-center/service-goods-center-impl/src/main/java/cn/bootx/goodscenter/core/sku/service/GoodsSkuService.java index 042dc36..2d2a15c 100644 --- a/service-goods-center/service-goods-center-impl/src/main/java/cn/bootx/goodscenter/core/sku/service/GoodsSkuService.java +++ b/service-goods-center/service-goods-center-impl/src/main/java/cn/bootx/goodscenter/core/sku/service/GoodsSkuService.java @@ -1,29 +1,17 @@ package cn.bootx.goodscenter.core.sku.service; -import cn.bootx.common.web.exception.BizException; import cn.bootx.common.web.util.ResultConvertUtils; -import cn.bootx.goodscenter.core.attributes.handler.AttrGenHandler; -import cn.bootx.goodscenter.core.goods.entity.Goods; -import cn.bootx.goodscenter.core.sku.dao.GoodsSkuAttrManager; -import cn.bootx.goodscenter.core.sku.dao.GoodsSkuAttrRepository; import cn.bootx.goodscenter.core.sku.dao.GoodsSkuManager; import cn.bootx.goodscenter.core.sku.dao.GoodsSkuRepository; import cn.bootx.goodscenter.core.sku.entity.GoodsSku; -import cn.bootx.goodscenter.core.sku.entity.GoodsSkuAttr; -import cn.bootx.goodscenter.core.sku.factory.GoodsSkuFactory; -import cn.bootx.goodscenter.dto.sku.GoodsSkuAttrDto; import cn.bootx.goodscenter.dto.sku.GoodsSkuDto; import cn.bootx.goodscenter.exception.sku.SkuNotFoundException; -import cn.bootx.goodscenter.param.sku.CreateSkuParam; -import cn.bootx.starter.snowflake.SnowFlakeId; +import cn.bootx.goodscenter.param.sku.SkuParam; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; import org.springframework.stereotype.Service; -import org.springframework.transaction.annotation.Transactional; -import java.time.LocalDateTime; import java.util.List; -import java.util.stream.Collectors; /** * sku管理 @@ -36,12 +24,22 @@ import java.util.stream.Collectors; public class GoodsSkuService { private final GoodsSkuRepository skuRepository; private final GoodsSkuManager skuManager; - private final GoodsSkuAttrManager skuAttrManager; - private final GoodsSkuAttrRepository skuAttrRepository; - private final GoodsSkuFactory goodsSkuFactory; - private final SnowFlakeId snowFlakeId; + /** + * 添加sku + */ + public GoodsSkuDto add(SkuParam skuParam){ + GoodsSku goodsSku = GoodsSku.init(skuParam); + + // 无限库存 + if (goodsSku.isUnlimited()){ + goodsSku.setAvailable(999999999) + .setCapacity(999999999); + } + return skuRepository.save(goodsSku).toDto(); + } + /** * 根据 id 获取相应的商品SKU @@ -65,67 +63,4 @@ public class GoodsSkuService { return ResultConvertUtils.dtoListConvert(skuManager.findByIds(skuIds)); } - /** - * 查询sku对应的属性定义 - */ - public List findAttr(Long skuId){ - return ResultConvertUtils.dtoListConvert(skuAttrManager.findBySkuId(skuId)); - } - - /** - * 上架商品SKU - */ - @Transactional(rollbackFor = Exception.class) - public void saleOn(Long skuId){ - GoodsSku sku = skuManager.findById(skuId).orElseThrow(() -> new BizException("商品sku不存在")); - sku.setSaleState(1) - .setSaleOnTime(LocalDateTime.now()); - skuRepository.save(sku); - } - - /** - * 下架商品SKU - */ - @Transactional(rollbackFor = Exception.class) - public void saleOff(Long skuId){ - GoodsSku sku = skuManager.findById(skuId).orElseThrow(() -> new BizException("商品sku不存在")); - sku.setSaleState(2) - .setSaleOnTime(LocalDateTime.now()); - skuRepository.save(sku); - } - - /** - * 批量新增商品的SKU和相关属性 - */ - public List addSkus(List skuParams, Goods goods){ - List skus = skuParams.stream() - .map(skuParam -> { - GoodsSku goodsSku = goodsSkuFactory.construct(skuParam); - goodsSku.setGoodsId(goods.getId()) - .setPacking(false) - .setCid(goods.getCid()); - goodsSku.setId(snowFlakeId.nextId()); - return goodsSku; - }).collect(Collectors.toList()); - - List goodsSkuAttrs = AttrGenHandler.genSkuAttrsBySkus(skus); - List goodsSkus = skuRepository.saveAll(skus); - skuAttrRepository.saveAll(goodsSkuAttrs); - return goodsSkus; - } - - /** - * 新增商品的SKU和相关属性 - */ - public GoodsSku addSku(CreateSkuParam skuParam, Goods goods){ - GoodsSku goodsSku = goodsSkuFactory.construct(skuParam); - goodsSku.setGoodsId(goods.getId()) - .setPacking(false) - .setCid(goods.getCid()); - skuRepository.save(goodsSku); - List goodsSkuAttrs = AttrGenHandler.genSkuAttrsBySku(goodsSku); - skuAttrRepository.saveAll(goodsSkuAttrs); - return goodsSku; - } - } diff --git a/service-goods-center/service-goods-center-api/src/main/java/cn/bootx/goodscenter/param/goods/CreateGoodsAndSkuParam.java b/service-shop-engine/service-shop-engine-api/src/main/java/cn/bootx/engine/shop/param/demo/DemoPayParam.java similarity index 37% rename from service-goods-center/service-goods-center-api/src/main/java/cn/bootx/goodscenter/param/goods/CreateGoodsAndSkuParam.java rename to service-shop-engine/service-shop-engine-api/src/main/java/cn/bootx/engine/shop/param/demo/DemoPayParam.java index 8ab5948..49a379b 100644 --- a/service-goods-center/service-goods-center-api/src/main/java/cn/bootx/goodscenter/param/goods/CreateGoodsAndSkuParam.java +++ b/service-shop-engine/service-shop-engine-api/src/main/java/cn/bootx/engine/shop/param/demo/DemoPayParam.java @@ -1,25 +1,25 @@ -package cn.bootx.goodscenter.param.goods; +package cn.bootx.engine.shop.param.demo; -import cn.bootx.goodscenter.param.sku.CreateSkuParam; +import cn.bootx.paymentcenter.param.pay.PayModeParam; import io.swagger.annotations.ApiModel; import io.swagger.annotations.ApiModelProperty; import lombok.Data; import lombok.experimental.Accessors; +import java.io.Serializable; import java.util.List; /** * @author xxm -* @date 2021/2/2 +* @date 2021/7/23 */ @Data @Accessors(chain = true) -@ApiModel("创建商品及sku参数") -public class CreateGoodsAndSkuParam { +@ApiModel("支付参数") +public class DemoPayParam implements Serializable { - @ApiModelProperty("商品") - private CreateGoodsParam goodsParam; + private static final long serialVersionUID = -927464570717617012L; - @ApiModelProperty("sku") - private List skuParams; + @ApiModelProperty("支付方式参数") + private List payModeList; } diff --git a/service-goods-center/service-goods-center-api/src/main/java/cn/bootx/goodscenter/param/sku/GenSkuParam.java b/service-shop-engine/service-shop-engine-api/src/main/java/cn/bootx/engine/shop/param/demo/DemoPlaceAndPayParam.java similarity index 34% rename from service-goods-center/service-goods-center-api/src/main/java/cn/bootx/goodscenter/param/sku/GenSkuParam.java rename to service-shop-engine/service-shop-engine-api/src/main/java/cn/bootx/engine/shop/param/demo/DemoPlaceAndPayParam.java index 0572e83..4a08704 100644 --- a/service-goods-center/service-goods-center-api/src/main/java/cn/bootx/goodscenter/param/sku/GenSkuParam.java +++ b/service-shop-engine/service-shop-engine-api/src/main/java/cn/bootx/engine/shop/param/demo/DemoPlaceAndPayParam.java @@ -1,4 +1,4 @@ -package cn.bootx.goodscenter.param.sku; +package cn.bootx.engine.shop.param.demo; import io.swagger.annotations.ApiModel; import io.swagger.annotations.ApiModelProperty; @@ -10,20 +10,18 @@ import java.util.List; /** * @author xxm -* @date 2021/2/2 +* @date 2021/7/23 */ @Data @Accessors(chain = true) -@ApiModel("生成sku属性参数") -public class GenSkuParam implements Serializable { - private static final long serialVersionUID = 8939703808257892072L; +@ApiModel("下单与支付参数") +public class DemoPlaceAndPayParam implements Serializable { + private static final long serialVersionUID = 3936321855327300793L; - @ApiModelProperty(value = "商品 类目 id", required = true) - private Long cid; + @ApiModelProperty("要下的订单") + private List placeOrder; - @ApiModelProperty(value = "所属商品 id", required = true) - private Long goodsId; + @ApiModelProperty("支付参数") + private DemoPayParam payParam; - @ApiModelProperty("商品 SKU 属性") - private List skuAttrList; } diff --git a/service-goods-center/service-goods-center-api/src/main/java/cn/bootx/goodscenter/param/packing/GoodsSkuPackingParam.java b/service-shop-engine/service-shop-engine-api/src/main/java/cn/bootx/engine/shop/param/demo/DemoPlaceOrderParam.java similarity index 36% rename from service-goods-center/service-goods-center-api/src/main/java/cn/bootx/goodscenter/param/packing/GoodsSkuPackingParam.java rename to service-shop-engine/service-shop-engine-api/src/main/java/cn/bootx/engine/shop/param/demo/DemoPlaceOrderParam.java index e3ea427..b3f0643 100644 --- a/service-goods-center/service-goods-center-api/src/main/java/cn/bootx/goodscenter/param/packing/GoodsSkuPackingParam.java +++ b/service-shop-engine/service-shop-engine-api/src/main/java/cn/bootx/engine/shop/param/demo/DemoPlaceOrderParam.java @@ -1,30 +1,24 @@ -package cn.bootx.goodscenter.param.packing; +package cn.bootx.engine.shop.param.demo; import io.swagger.annotations.ApiModel; import io.swagger.annotations.ApiModelProperty; import lombok.Data; import lombok.experimental.Accessors; -import java.util.List; +import java.io.Serializable; /** * @author xxm -* @date 2020/11/23 +* @date 2021/7/23 */ @Data @Accessors(chain = true) -@ApiModel("SKU打包品设置") -public class GoodsSkuPackingParam { - -@ApiModelProperty("打包品 id") - private Long goodsId; - - @ApiModelProperty("被打包品 id") - private Long packedGoodsId; - - @ApiModelProperty("打包品SKU id") +@ApiModel("demo下单参数") +public class DemoPlaceOrderParam implements Serializable { + private static final long serialVersionUID = -1315486593900577267L; + @ApiModelProperty("商品SkuId") private Long skuId; - @ApiModelProperty("被打包品SKU id") - private List ids; + @ApiModelProperty("数量") + private Integer count; } diff --git a/service-shop-engine/service-shop-engine-impl/src/main/java/cn/bootx/engine/shop/controller/DemoController.java b/service-shop-engine/service-shop-engine-impl/src/main/java/cn/bootx/engine/shop/controller/DemoController.java new file mode 100644 index 0000000..efb4b58 --- /dev/null +++ b/service-shop-engine/service-shop-engine-impl/src/main/java/cn/bootx/engine/shop/controller/DemoController.java @@ -0,0 +1,42 @@ +package cn.bootx.engine.shop.controller; + +import cn.bootx.common.web.rest.Res; +import cn.bootx.common.web.rest.ResResult; +import cn.bootx.engine.shop.core.demo.service.DemoService; +import cn.bootx.engine.shop.param.demo.DemoPlaceAndPayParam; +import cn.bootx.goodscenter.dto.sku.GoodsSkuDto; +import cn.bootx.paymentcenter.dto.pay.PayResult; +import io.swagger.annotations.Api; +import io.swagger.annotations.ApiOperation; +import lombok.RequiredArgsConstructor; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +import java.util.List; + +/** +* @author xxm +* @date 2021/7/23 +*/ +@Api(tags = "支付结算演示demo") +@RestController +@RequestMapping("/demo") +@RequiredArgsConstructor +public class DemoController { + private final DemoService demoService; + + @ApiOperation("商品列表接口") + @PostMapping("/findGoods") + public ResResult> findGoods(Long id){ + return Res.ok(demoService.findGoods(id)); + } + + + @ApiOperation("下单和支付") + @PostMapping("/placeAndPay") + public ResResult placeAndPay(@RequestBody DemoPlaceAndPayParam param){ + return Res.ok(demoService.placeAndPay(param)); + } +} diff --git a/service-shop-engine/service-shop-engine-impl/src/main/java/cn/bootx/engine/shop/core/cart/service/CartService.java b/service-shop-engine/service-shop-engine-impl/src/main/java/cn/bootx/engine/shop/core/cart/service/CartService.java index 3953f7f..d8d5d3f 100644 --- a/service-shop-engine/service-shop-engine-impl/src/main/java/cn/bootx/engine/shop/core/cart/service/CartService.java +++ b/service-shop-engine/service-shop-engine-impl/src/main/java/cn/bootx/engine/shop/core/cart/service/CartService.java @@ -57,7 +57,7 @@ public class CartService { ShopCartItem shopCartItem = map.get(skuId); if (Objects.isNull(shopCartItem)){ // 检查 - GoodsSkuDto goodsSku = goodsSkuClient.getById(skuId); + GoodsSkuDto goodsSku = goodsSkuClient.findById(skuId); cartCheckService.joinCheck(goodsSku,shopCart); ShopCartItem item = goodsCenterTransform.transform(goodsSku); @@ -107,7 +107,7 @@ public class CartService { throw new BizException("该规格已经存在"); } // 检查 - GoodsSkuDto goodsSku = goodsSkuClient.getById(newSkuId); + GoodsSkuDto goodsSku = goodsSkuClient.findById(newSkuId); cartCheckService.joinCheck(goodsSku,shopCart); ShopCartItem newItem = goodsCenterTransform.transform(goodsSku); diff --git a/service-shop-engine/service-shop-engine-impl/src/main/java/cn/bootx/engine/shop/core/demo/service/DemoService.java b/service-shop-engine/service-shop-engine-impl/src/main/java/cn/bootx/engine/shop/core/demo/service/DemoService.java new file mode 100644 index 0000000..2650701 --- /dev/null +++ b/service-shop-engine/service-shop-engine-impl/src/main/java/cn/bootx/engine/shop/core/demo/service/DemoService.java @@ -0,0 +1,246 @@ +package cn.bootx.engine.shop.core.demo.service; + +import cn.bootx.common.util.BigDecimalUtil; +import cn.bootx.engine.shop.core.order.dao.OrderCacheManager; +import cn.bootx.engine.shop.core.pay.service.PayModeService; +import cn.bootx.engine.shop.mq.MessageSender; +import cn.bootx.engine.shop.param.demo.DemoPayParam; +import cn.bootx.engine.shop.param.demo.DemoPlaceAndPayParam; +import cn.bootx.engine.shop.param.demo.DemoPlaceOrderParam; +import cn.bootx.engine.shop.param.sell.OrderPayParam; +import cn.bootx.goodscenter.client.GoodsSkuClient; +import cn.bootx.goodscenter.client.InventoryClient; +import cn.bootx.goodscenter.dto.inventory.LockInventoryDto; +import cn.bootx.goodscenter.dto.sku.GoodsSkuDto; +import cn.bootx.goodscenter.exception.inventory.InventoryInsufficientException; +import cn.bootx.goodscenter.param.inventory.ReduceInventoryParam; +import cn.bootx.ordercenter.client.OrderOperateClient; +import cn.bootx.ordercenter.code.OrderStatusCode; +import cn.bootx.ordercenter.dto.order.OrderDetailDto; +import cn.bootx.ordercenter.dto.order.OrderDto; +import cn.bootx.ordercenter.param.order.OrderDetailParam; +import cn.bootx.ordercenter.param.order.OrderParam; +import cn.bootx.ordercenter.param.order.OrderWholeParam; +import cn.bootx.paymentcenter.client.PayClient; +import cn.bootx.paymentcenter.dto.pay.PayResult; +import cn.bootx.paymentcenter.dto.paymodel.wallet.WalletDto; +import cn.bootx.paymentcenter.param.pay.PayParam; +import cn.hutool.core.bean.BeanUtil; +import lombok.RequiredArgsConstructor; +import lombok.extern.slf4j.Slf4j; +import org.springframework.stereotype.Service; + +import java.math.BigDecimal; +import java.util.*; +import java.util.stream.Collectors; + +/** + * 结算台demo + * @author xxm + * @date 2021/7/23 + */ +@SuppressWarnings("FieldCanBeLocal") +@Slf4j +@Service +@RequiredArgsConstructor +public class DemoService { + private final GoodsSkuClient goodsSkuClient; + private final InventoryClient inventoryClient; + private final OrderOperateClient orderOperateClient; + private final PayClient payClient; + + private final MessageSender messageSender; + private final OrderCacheManager orderCacheManager; + private final PayModeService payModeService; + + private final Long USER_ID = 1L; + private final String MERCHANT_NO = "M1410587445766025216"; + private final String APP_ID = "1368825551321722880"; + + /** + * 商品列表接口 + */ + public List findGoods(Long goodsId){ + return goodsSkuClient.findByGoodsId(goodsId); + } + + /** + * 下单和支付发起方法 + */ + public PayResult placeAndPay(DemoPlaceAndPayParam param){ + // 订单信息 支付方式信息 + + // 下单 + List placeOrder = param.getPlaceOrder(); + Map skuMaps = placeOrder.stream().collect(Collectors.toMap(DemoPlaceOrderParam::getSkuId, DemoPlaceOrderParam::getCount)); + + List skus = goodsSkuClient.findBySkuIds(new ArrayList<>(skuMaps.keySet())); + List orderDetailParams = skus.stream().map(sku -> { + OrderDetailParam od = new OrderDetailParam(); + BeanUtil.copyProperties(sku, od); + return od.setNum(skuMaps.get(sku.getId())) + .setGoodsPrice(sku.getPrice()) + .setGoodsId(sku.getGoodsId()) + .setSkuId(sku.getId()) + .setCategoryId(sku.getCid()) + .setGoodsTitle(sku.getName()); + }).collect(Collectors.toList()); + OrderDto order = this.createOrder(orderDetailParams); + order.setDescription("测试支付"); + + // 发起支付 + return this.payOrder(order, param.getPayParam()); + } + + /** + * 获取钱包 + */ + public WalletDto findWallet(){ + return null; + } + + /** + * 支付记录列表 + */ + public void pagePayment(){ + + } + + /** + * 获取支付记录 + */ + public void findPayment(Long id){ + + } + + /** + * 获取账单Billing + */ + public void findBilling(String businessId){ + + } + + + /** + * 支付 + */ + public PayResult payOrder(OrderDto order, DemoPayParam param){ + + // 构建支付参数 + OrderPayParam orderPayParam = new OrderPayParam() + .setPayModeList(param.getPayModeList()) + .setOrderId(order.getId()); + PayParam payParam = payModeService.buildPaymentParam(order,orderPayParam); + payParam.setMerchantNo(MERCHANT_NO) + .setAppId(APP_ID); + // 发起支付 + PayResult payResult = payClient.pay(payParam); + + // 异步支付 + if (payResult.isSyncPayMode()){ + return payResult; + } else { + // 同步支付后处理 + this.afterPaymentHandler(order); + } + return payResult; + } + + /** + * 支付成功后操作 + */ + public void afterPaymentHandler(OrderDto orderDto) { + + Map> skuGroupOrderDetailMap = orderDto.getDetails().stream() + .collect(Collectors.groupingBy(OrderDetailDto::getSkuId)); + skuGroupOrderDetailMap.forEach((skuId, detailDtoList) -> { + String token = orderCacheManager.getSkuLockToken(orderDto.getId(), skuId); + int sum = detailDtoList.stream().mapToInt(OrderDetailDto::getNum).sum(); + ReduceInventoryParam reduceInventoryParam = new ReduceInventoryParam() + .setSkuId(skuId) + .setCount(sum) + .setToken(token); + // 扣减已锁定库存 + messageSender.sendReduceInventory(reduceInventoryParam); + // 删除库存锁定token信息 + orderCacheManager.deleteSkuLockToken(orderDto.getId(), skuId); + }); + // 更新订单支付已完成 + orderDto.setStatus(OrderStatusCode.STATUS_PAYED); + // 删除订单过期时间信息 + orderCacheManager.removeExpiredOrder(orderDto.getId()); + orderOperateClient.paidOrderState(orderDto.getId()); + } + + /** + * 创建订单 + */ + public OrderDto createOrder(List orderDetailParams){ + // 构建下单参数 + OrderParam orderParam = this.buildOrderParam(orderDetailParams); + + // 校验库存和锁定库存 + this.checkInventory(orderDetailParams); + Map inventoryMap = this.lockInventory(orderDetailParams); + OrderWholeParam orderWholeParam = new OrderWholeParam() + .setOrderParam(orderParam); + + // 下单 + OrderDto order = orderOperateClient.placeOrder(orderWholeParam); + + // 预占库存token缓存 + inventoryMap.forEach((skuId, lockInventory) -> { + //将token写入redis + orderCacheManager.saveInventoryLockToken(order.getId(), skuId, lockInventory.getToken()); + }); + // 保存订单超时时间 + orderCacheManager.storeByOrderId(order.getId()); + return order; + } + + /** + * 构建订单参数 + */ + private OrderParam buildOrderParam(List orderDetailParams) { + + // 订单 + OrderParam orderParam = new OrderParam(); + + BigDecimal totalAmount = orderDetailParams.stream() + .map(detail -> BigDecimalUtil.multiply(detail.getGoodsPrice(), BigDecimal.valueOf(detail.getNum()))) + .reduce(BigDecimal.ZERO, BigDecimal::add); + + orderParam.setUserId(USER_ID); + orderParam.setType(1); + orderParam.setTotalAmount(totalAmount); + orderParam.setDescription("测试支付"); + orderParam.setDetails(orderDetailParams); + return orderParam; + } + + /** + * 检查库存 + */ + private void checkInventory(List detailParams) { + + for (OrderDetailParam orderDetail : detailParams) { + int inventory = Optional.ofNullable(inventoryClient.getAvailable(orderDetail.getSkuId())).orElse(0); + + if (inventory < orderDetail.getNum()) { + throw new InventoryInsufficientException(); + } + } + } + + /** + * 锁定库存 + */ + private Map lockInventory(List orderDetailParams) { + Map map = new LinkedHashMap<>(); + for (OrderDetailParam detailParam : orderDetailParams) { + LockInventoryDto inventory = inventoryClient.lockInventory(detailParam.getSkuId(), detailParam.getNum()); + map.put(detailParam.getSkuId(),inventory); + } + return map; + } +} diff --git a/service-shop-engine/service-shop-engine-impl/src/main/java/cn/bootx/engine/shop/core/order/service/OrderPlaceService.java b/service-shop-engine/service-shop-engine-impl/src/main/java/cn/bootx/engine/shop/core/order/service/OrderPlaceService.java index 3ba996d..1b356b1 100644 --- a/service-shop-engine/service-shop-engine-impl/src/main/java/cn/bootx/engine/shop/core/order/service/OrderPlaceService.java +++ b/service-shop-engine/service-shop-engine-impl/src/main/java/cn/bootx/engine/shop/core/order/service/OrderPlaceService.java @@ -73,8 +73,8 @@ public class OrderPlaceService { */ public OrderDto buyNow(NowPlaceOrderParam param){ - GoodsSkuDto s1 = goodsSkuClient.getById(param.getSkuId()); - GoodsSkuDto s2 = goodsSkuClient.getById(2L); + GoodsSkuDto s1 = goodsSkuClient.findById(param.getSkuId()); + GoodsSkuDto s2 = goodsSkuClient.findById(2L); OrderDetailParam od1 = new OrderDetailParam(); OrderDetailParam od2 = new OrderDetailParam(); BeanUtil.copyProperties(s1,od1); @@ -104,7 +104,7 @@ public class OrderPlaceService { // 构建下单参数 OrderParam orderParam = this.buildOrderParam(param, orderDetailParams); - // 校验库存和锁定库存 + // 校验库存和锁checkInventory定库存 this.checkInventory(orderDetailParams); Map inventoryMap = this.lockInventory(orderDetailParams); OrderWholeParam orderWholeParam = new OrderWholeParam() diff --git a/service-shop-engine/service-shop-engine-impl/src/main/java/cn/bootx/engine/shop/core/pay/service/OrderPayService.java b/service-shop-engine/service-shop-engine-impl/src/main/java/cn/bootx/engine/shop/core/pay/service/OrderPayService.java index 2760f64..f22963d 100644 --- a/service-shop-engine/service-shop-engine-impl/src/main/java/cn/bootx/engine/shop/core/pay/service/OrderPayService.java +++ b/service-shop-engine/service-shop-engine-impl/src/main/java/cn/bootx/engine/shop/core/pay/service/OrderPayService.java @@ -97,7 +97,7 @@ public class OrderPayService { // 扣库存 skuGroupOrderDetailMap.forEach((skuId, detailDtoList) -> { //所有支付,订单有效的情况下都可以扣库存 - GoodsSkuDto sku = goodsSkuClient.getById(skuId); + GoodsSkuDto sku = goodsSkuClient.findById(skuId); int num = detailDtoList.stream() .mapToInt(OrderDetailDto::getNum) .sum(); diff --git a/service-shop-engine/service-shop-engine-impl/src/main/java/cn/bootx/engine/shop/transform/GoodsCenterTransform.java b/service-shop-engine/service-shop-engine-impl/src/main/java/cn/bootx/engine/shop/transform/GoodsCenterTransform.java index 02e6fa7..2ef8ade 100644 --- a/service-shop-engine/service-shop-engine-impl/src/main/java/cn/bootx/engine/shop/transform/GoodsCenterTransform.java +++ b/service-shop-engine/service-shop-engine-impl/src/main/java/cn/bootx/engine/shop/transform/GoodsCenterTransform.java @@ -20,7 +20,6 @@ public class GoodsCenterTransform { BeanUtils.copyProperties(goodsSku,item); item.setNum(1) .setSelected(true) - .setShopId(goodsSku.getShopId()) .setGoodsPrice(goodsSku.getPrice()) .setGoodsTitle(goodsSku.getName()) .setAddTime(LocalDateTime.now()) -- Gitee