From d1db95452e705ffb3cdcb8263ff81fac459a0b42 Mon Sep 17 00:00:00 2001 From: dzc <2388224167@qq.com> Date: Mon, 6 Jan 2025 16:13:03 +0800 Subject: [PATCH] =?UTF-8?q?feat:android=E6=9C=BA=E5=99=A8=E7=A1=AC?= =?UTF-8?q?=E4=BB=B6=E7=AE=A1=E7=90=86=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../common/core/constant/CacheConstants.java | 2 + .../api/constant/HardPrintStatusEnum.java | 26 ++ .../constant/order/HardOrderStatusEnum.java | 26 ++ .../api/constant/order/HardOrderTypeEnum.java | 12 +- .../api/constant/order/HardPayTypeEnum.java | 20 +- .../hard/api/dto/async/OfflineCar.java | 41 +++ .../hard/api/dto/async/OfflineOrder.java | 80 ++++++ .../hard/api/dto/async/SyncOfflineReqVo.java | 24 ++ .../hard/api/dto/hard/HandCancelCodeDto.java | 23 ++ .../hard/api/dto/hard/HardCreateOrderDto.java | 2 - .../hard/api/dto/order/HardOrderDto.java | 4 +- .../hard/api/entity/HardInvoiceEntity.java | 6 +- .../hard/api/entity/order/HardCarEntity.java | 2 +- ...eOrderEntity.java => HardOrderEntity.java} | 8 +- .../bsd/pjcloud/hard/api/utils/Drawing2D.java | 229 +++++++++++++++++ .../pjcloud/hard/api/vo/HardInvoiceVo.java | 2 + .../hard/api/vo/order/HardOrderVo.java | 4 +- .../controller/hard/HardApiController.java | 45 +++- .../order/HardwareOrderController.java | 18 +- .../hard/mapper/order/HardOrderMapper.java | 12 +- .../pjcloud/hard/service/HardCarService.java | 14 +- .../hard/service/HardInvoiceService.java | 35 +++ ...rderService.java => HardOrderService.java} | 26 +- .../hard/service/HardOrderSyncService.java | 17 ++ .../service/impl/HardInvoiceServiceImpl.java | 146 +++++++++++ .../impl/order/HardCarServiceImpl.java | 70 +++-- .../impl/order/HardOrderSyncServiceImpl.java | 168 ++++++++++++ .../impl/order/HardwareOrderServiceImpl.java | 130 ++++++++-- .../mapper/order/HardOrderMapper.xml | 2 +- .../admin/api/feign/RemoteDeptService.java | 54 ++-- .../admin/controller/SysDeptController.java | 240 +++++++++--------- .../wallet/api/constant/WalletBizEnum.java | 1 + .../api/dto/WalletBalanceTransactionDto.java | 28 ++ .../api/entity/WalletSettingEntity.java | 4 +- .../feign/RemoteWalletTransactionService.java | 24 ++ ...mework.cloud.openfeign.FeignClient.imports | 3 +- .../controller/MchManageController.java | 6 +- .../controller/WalletManageController.java | 46 +--- .../WalletTransactionController.java | 66 ++--- .../wallet/mapper/MchManageMapper.java | 7 + .../wallet/service/MchManageService.java | 2 + .../service/WalletTransactionService.java | 2 +- .../service/impl/MchManageServiceImpl.java | 13 + .../service/impl/WalletManageServiceImpl.java | 1 + .../impl/WalletSettingServiceImpl.java | 63 ++++- .../impl/WalletTransactionServiceImpl.java | 2 +- 46 files changed, 1440 insertions(+), 316 deletions(-) create mode 100644 pjcloud-hardware/pjcloud-hardware-api/src/main/java/com/bsd/pjcloud/hard/api/constant/HardPrintStatusEnum.java create mode 100644 pjcloud-hardware/pjcloud-hardware-api/src/main/java/com/bsd/pjcloud/hard/api/constant/order/HardOrderStatusEnum.java create mode 100644 pjcloud-hardware/pjcloud-hardware-api/src/main/java/com/bsd/pjcloud/hard/api/dto/async/OfflineCar.java create mode 100644 pjcloud-hardware/pjcloud-hardware-api/src/main/java/com/bsd/pjcloud/hard/api/dto/async/OfflineOrder.java create mode 100644 pjcloud-hardware/pjcloud-hardware-api/src/main/java/com/bsd/pjcloud/hard/api/dto/async/SyncOfflineReqVo.java create mode 100644 pjcloud-hardware/pjcloud-hardware-api/src/main/java/com/bsd/pjcloud/hard/api/dto/hard/HandCancelCodeDto.java rename pjcloud-hardware/pjcloud-hardware-api/src/main/java/com/bsd/pjcloud/hard/api/entity/order/{HardwareOrderEntity.java => HardOrderEntity.java} (96%) create mode 100644 pjcloud-hardware/pjcloud-hardware-api/src/main/java/com/bsd/pjcloud/hard/api/utils/Drawing2D.java rename pjcloud-hardware/pjcloud-hardware-biz/src/main/java/com/bsd/pjcloud/hard/service/{HardwareOrderService.java => HardOrderService.java} (52%) create mode 100644 pjcloud-hardware/pjcloud-hardware-biz/src/main/java/com/bsd/pjcloud/hard/service/HardOrderSyncService.java create mode 100644 pjcloud-hardware/pjcloud-hardware-biz/src/main/java/com/bsd/pjcloud/hard/service/impl/order/HardOrderSyncServiceImpl.java create mode 100644 pjcloud-wallet/pjcloud-wallet-api/src/main/java/com/bsd/pjcloud/wallet/api/dto/WalletBalanceTransactionDto.java create mode 100644 pjcloud-wallet/pjcloud-wallet-api/src/main/java/com/bsd/pjcloud/wallet/api/feign/RemoteWalletTransactionService.java diff --git a/pjcloud-common/pjcloud-common-core/src/main/java/com/bsd/pjcloud/common/core/constant/CacheConstants.java b/pjcloud-common/pjcloud-common-core/src/main/java/com/bsd/pjcloud/common/core/constant/CacheConstants.java index c36adbf95..3bb34fe97 100644 --- a/pjcloud-common/pjcloud-common-core/src/main/java/com/bsd/pjcloud/common/core/constant/CacheConstants.java +++ b/pjcloud-common/pjcloud-common-core/src/main/java/com/bsd/pjcloud/common/core/constant/CacheConstants.java @@ -122,6 +122,8 @@ public interface CacheConstants { /* ************************************* start 钱包相关 start ************************************* */ + String WALLET_DEFAULT = "wallet_default"; + String WALLET_MCH = "wallet:detail:mch"; String WALLET_DETAIL = "wallet:detail:manage"; diff --git a/pjcloud-hardware/pjcloud-hardware-api/src/main/java/com/bsd/pjcloud/hard/api/constant/HardPrintStatusEnum.java b/pjcloud-hardware/pjcloud-hardware-api/src/main/java/com/bsd/pjcloud/hard/api/constant/HardPrintStatusEnum.java new file mode 100644 index 000000000..9a0eb75d9 --- /dev/null +++ b/pjcloud-hardware/pjcloud-hardware-api/src/main/java/com/bsd/pjcloud/hard/api/constant/HardPrintStatusEnum.java @@ -0,0 +1,26 @@ +package com.bsd.pjcloud.hard.api.constant; + +import cn.hutool.core.util.ObjectUtil; +import lombok.AllArgsConstructor; +import lombok.Getter; + +import javax.xml.stream.events.StartDocument; +import java.util.Arrays; + +/** + * 打印状态 + */ +@AllArgsConstructor +@Getter +public enum HardPrintStatusEnum { + GENERATE("1", "已生成"), + PRINT("2", "已打印"), + ; + private final String type; + private final String description; + + public static HardPrintStatusEnum valueOfByType(String type) { + if (ObjectUtil.isEmpty(type)) return null; + return Arrays.stream(values()).filter(v -> ObjectUtil.equals(type, v.getType())).findFirst().get(); + } +} diff --git a/pjcloud-hardware/pjcloud-hardware-api/src/main/java/com/bsd/pjcloud/hard/api/constant/order/HardOrderStatusEnum.java b/pjcloud-hardware/pjcloud-hardware-api/src/main/java/com/bsd/pjcloud/hard/api/constant/order/HardOrderStatusEnum.java new file mode 100644 index 000000000..1697a48a3 --- /dev/null +++ b/pjcloud-hardware/pjcloud-hardware-api/src/main/java/com/bsd/pjcloud/hard/api/constant/order/HardOrderStatusEnum.java @@ -0,0 +1,26 @@ +package com.bsd.pjcloud.hard.api.constant.order; + +import cn.hutool.core.util.ObjectUtil; +import lombok.AllArgsConstructor; +import lombok.Getter; + +import java.util.Arrays; + +@AllArgsConstructor +@Getter +public enum HardOrderStatusEnum { + CREATE("1", "创建订单(未支付)"), + OFFLINE_CREATE("2", "离线创建订单(未支付)"), + PAY("5", "已经支付"), + OFFLINE_PAY("6", "没有网络本地支付"), + REFUND("10", "退款"), + CANCEL("20", "已核销"), + ; + private final String type; + private final String description; + + public static HardOrderStatusEnum valueOfByType(Integer type) { + if (ObjectUtil.isEmpty(type)) return null; + return Arrays.stream(values()).filter(v -> ObjectUtil.equals(type, v.getType())).findFirst().get(); + } +} diff --git a/pjcloud-hardware/pjcloud-hardware-api/src/main/java/com/bsd/pjcloud/hard/api/constant/order/HardOrderTypeEnum.java b/pjcloud-hardware/pjcloud-hardware-api/src/main/java/com/bsd/pjcloud/hard/api/constant/order/HardOrderTypeEnum.java index 01e14c848..ad4a5eaf2 100644 --- a/pjcloud-hardware/pjcloud-hardware-api/src/main/java/com/bsd/pjcloud/hard/api/constant/order/HardOrderTypeEnum.java +++ b/pjcloud-hardware/pjcloud-hardware-api/src/main/java/com/bsd/pjcloud/hard/api/constant/order/HardOrderTypeEnum.java @@ -12,15 +12,15 @@ import java.util.Arrays; @AllArgsConstructor @Getter public enum HardOrderTypeEnum { - BELOW(1, "线下购买"), - RESERVE(2, "线上订餐"), - FOREIGN_TICKET(3, "外来人员"), - STRIDE_DEPT(4, "跨单位"), + BELOW("1", "线下购买"), + RESERVE("2", "线上订餐"), + FOREIGN_TICKET("3", "外来人员"), + STRIDE_DEPT("4", "跨单位"), ; - private final Integer type; + private final String type; private final String description; - public static HardOrderTypeEnum valueOfByType(Integer type) { + public static HardOrderTypeEnum valueOfByType(String type) { if (ObjectUtil.isEmpty(type)) return null; return Arrays.stream(values()).filter(v -> ObjectUtil.equals(type, v.getType())).findFirst().get(); } diff --git a/pjcloud-hardware/pjcloud-hardware-api/src/main/java/com/bsd/pjcloud/hard/api/constant/order/HardPayTypeEnum.java b/pjcloud-hardware/pjcloud-hardware-api/src/main/java/com/bsd/pjcloud/hard/api/constant/order/HardPayTypeEnum.java index 86cfb12e7..d7ffcf9b0 100644 --- a/pjcloud-hardware/pjcloud-hardware-api/src/main/java/com/bsd/pjcloud/hard/api/constant/order/HardPayTypeEnum.java +++ b/pjcloud-hardware/pjcloud-hardware-api/src/main/java/com/bsd/pjcloud/hard/api/constant/order/HardPayTypeEnum.java @@ -13,19 +13,19 @@ import java.util.Arrays; @AllArgsConstructor @Getter public enum HardPayTypeEnum { - WALLET_DEFAULT(1, "普通钱包支付"), - WALLET_QR_CODE(2, "钱包二维码支付"), - WALLET_CARD(3, "钱包饭卡支付"), - FACE(4, "人脸识别支付"), - STRIDE_DEPT_QR_CODE(5, "跨单位二维码支付"), - FOREIGN_TICKET_QR_CODE(6, "外来人员二维码支付"), - RESERVE_QR_CODE(7, "线上订餐二维码支付"), - CASH(8, "现金支付"), + WALLET_DEFAULT("1", "普通钱包支付"), + WALLET_QR_CODE("2", "钱包二维码支付"), + WALLET_CARD("3", "钱包饭卡支付"), + FACE("4", "人脸识别支付"), + STRIDE_DEPT_QR_CODE("5", "跨单位二维码支付"), + FOREIGN_TICKET_QR_CODE("6", "外来人员二维码支付"), + RESERVE_QR_CODE("7", "线上订餐二维码支付"), + CASH("8", "现金支付"), ; - private final Integer type; + private final String type; private final String description; - public static HardPayTypeEnum valueOfByType(Integer type) { + public static HardPayTypeEnum valueOfByType(String type) { if (ObjectUtil.isEmpty(type)) return null; return Arrays.stream(values()).filter(v -> ObjectUtil.equals(type, v.getType())).findFirst().get(); } diff --git a/pjcloud-hardware/pjcloud-hardware-api/src/main/java/com/bsd/pjcloud/hard/api/dto/async/OfflineCar.java b/pjcloud-hardware/pjcloud-hardware-api/src/main/java/com/bsd/pjcloud/hard/api/dto/async/OfflineCar.java new file mode 100644 index 000000000..042dd0b07 --- /dev/null +++ b/pjcloud-hardware/pjcloud-hardware-api/src/main/java/com/bsd/pjcloud/hard/api/dto/async/OfflineCar.java @@ -0,0 +1,41 @@ +package com.bsd.pjcloud.hard.api.dto.async; + + +import io.swagger.v3.oas.annotations.media.Schema; +import lombok.Data; + +import java.math.BigDecimal; + +@Data +public class OfflineCar { + + @Schema(description = "sqlite自增ID") + private Long id; + + @Schema(description = "购物车的id字段") + private Long orderId; + + @Schema(description = "商品id") + private Long productServiceUniqueCode; + + @Schema(description = "商品名") + private String productName; + + @Schema(description = "商品图片") + private String productPic; + + // 商品价格(分) + @Schema(description = "商品价格(分)") + private Long productPrice; + + // TODO 食堂特有 + @Schema(description = "数量") + private Integer productNumber; + + // TODO 超市特有 + @Schema(description = "重量") + private BigDecimal productWidget; + + @Schema(description = "单商品总价(分)") + private Long totalPrice; +} diff --git a/pjcloud-hardware/pjcloud-hardware-api/src/main/java/com/bsd/pjcloud/hard/api/dto/async/OfflineOrder.java b/pjcloud-hardware/pjcloud-hardware-api/src/main/java/com/bsd/pjcloud/hard/api/dto/async/OfflineOrder.java new file mode 100644 index 000000000..91b75025e --- /dev/null +++ b/pjcloud-hardware/pjcloud-hardware-api/src/main/java/com/bsd/pjcloud/hard/api/dto/async/OfflineOrder.java @@ -0,0 +1,80 @@ +package com.bsd.pjcloud.hard.api.dto.async; + +import com.bsd.pjcloud.hard.api.constant.HardTypeEnum; +import com.bsd.pjcloud.hard.api.constant.order.HardOrderStatusEnum; +import com.bsd.pjcloud.hard.api.constant.order.HardOrderTypeEnum; +import com.bsd.pjcloud.hard.api.constant.order.HardPayTypeEnum; +import io.swagger.v3.oas.annotations.media.Schema; +import lombok.Data; + +import java.util.Date; +import java.util.List; + +@Data +public class OfflineOrder { + + @Schema(description = "sqlite自增ID") + private Long id; + + @Schema(description = "android唯一code") + private String uniqueCode; + + @Schema(description = "服务端唯一标识") + private String serviceUniqueCode; + + @Schema(description = "平台类型") + private HardTypeEnum sysType; + + @Schema(description = "用户唯一标识") + private Long userCode; + + @Schema(description = "用户名") + private String username; + + // 订单用餐类型:早、中、晚 + private String hourType; + + @Schema(description = "购物车的总金额") + private Integer price; + + @Schema(description = "购物车的额外金额") + private Integer extraPrice; + + @Schema(description = "结算总金额") + private Integer payPrice; + + @Schema(description = "钱包id") + private Long walletId; + + @Schema(description = "订单类型渠道id") + private Long orderSourceTypeId; + + @Schema(description = "订单类型") + private HardOrderTypeEnum type; + + @Schema(description = "订单状态") + private HardOrderStatusEnum status; + + @Schema(description = "支付方式") + private HardPayTypeEnum payType; + + @Schema(description = "商品描述") + private String productDesc; + + // TODO 食堂特有 + @Schema(description = "商品总数量") + private Integer count; + + // TODO 超市特有 + @Schema(description = "重量") + private Double weight; + + @Schema(description = "支付时间") + private String payTime; + + @Schema(description = "创建时间") + private Date createTime; + + @Schema(description = "购物车列表") + private List carList; +} diff --git a/pjcloud-hardware/pjcloud-hardware-api/src/main/java/com/bsd/pjcloud/hard/api/dto/async/SyncOfflineReqVo.java b/pjcloud-hardware/pjcloud-hardware-api/src/main/java/com/bsd/pjcloud/hard/api/dto/async/SyncOfflineReqVo.java new file mode 100644 index 000000000..19a851787 --- /dev/null +++ b/pjcloud-hardware/pjcloud-hardware-api/src/main/java/com/bsd/pjcloud/hard/api/dto/async/SyncOfflineReqVo.java @@ -0,0 +1,24 @@ +package com.bsd.pjcloud.hard.api.dto.async; + +import io.swagger.v3.oas.annotations.media.Schema; +import jakarta.validation.constraints.NotEmpty; +import jakarta.validation.constraints.NotNull; +import lombok.Data; + +import java.util.List; + +@Data +public class SyncOfflineReqVo { + + @Schema(description = "硬件id") + @NotNull(message = "硬件id不能为空") + private Long hardwareId; + + @Schema(description = "商户id") + @NotNull(message = "商户id不能为空") + private Long merchantId; + + @Schema(description = "订单列表") + @NotEmpty(message = "订单列表不能为空") + private List list; +} diff --git a/pjcloud-hardware/pjcloud-hardware-api/src/main/java/com/bsd/pjcloud/hard/api/dto/hard/HandCancelCodeDto.java b/pjcloud-hardware/pjcloud-hardware-api/src/main/java/com/bsd/pjcloud/hard/api/dto/hard/HandCancelCodeDto.java new file mode 100644 index 000000000..ca49cb193 --- /dev/null +++ b/pjcloud-hardware/pjcloud-hardware-api/src/main/java/com/bsd/pjcloud/hard/api/dto/hard/HandCancelCodeDto.java @@ -0,0 +1,23 @@ +package com.bsd.pjcloud.hard.api.dto.hard; + +import io.swagger.v3.oas.annotations.media.Schema; +import jakarta.validation.constraints.NotNull; +import lombok.Data; + +@Data +public class HandCancelCodeDto { + @Schema(description = "生成的订单id") + @NotNull(message = "生成的订单id不能为空") + private Long orderId; + + @Schema(description = "设备id") + @NotNull(message = "设备id不能为空") + private Long hardwareId; + + @Schema(description = "安卓订单code") + @NotNull(message = "安卓订单code不能为空") + private String androidOrderCode; + + @Schema(description = "用户id") + private Long userId; +} diff --git a/pjcloud-hardware/pjcloud-hardware-api/src/main/java/com/bsd/pjcloud/hard/api/dto/hard/HardCreateOrderDto.java b/pjcloud-hardware/pjcloud-hardware-api/src/main/java/com/bsd/pjcloud/hard/api/dto/hard/HardCreateOrderDto.java index c08a2dc9f..5032252a3 100644 --- a/pjcloud-hardware/pjcloud-hardware-api/src/main/java/com/bsd/pjcloud/hard/api/dto/hard/HardCreateOrderDto.java +++ b/pjcloud-hardware/pjcloud-hardware-api/src/main/java/com/bsd/pjcloud/hard/api/dto/hard/HardCreateOrderDto.java @@ -62,8 +62,6 @@ public class HardCreateOrderDto { @Schema(description = "商品的简短描述") private String productDesc; - private String clientIP; - private Long deptId; @Schema(description = "离线支付是否成功") diff --git a/pjcloud-hardware/pjcloud-hardware-api/src/main/java/com/bsd/pjcloud/hard/api/dto/order/HardOrderDto.java b/pjcloud-hardware/pjcloud-hardware-api/src/main/java/com/bsd/pjcloud/hard/api/dto/order/HardOrderDto.java index aa3ab229a..a66b0ed28 100644 --- a/pjcloud-hardware/pjcloud-hardware-api/src/main/java/com/bsd/pjcloud/hard/api/dto/order/HardOrderDto.java +++ b/pjcloud-hardware/pjcloud-hardware-api/src/main/java/com/bsd/pjcloud/hard/api/dto/order/HardOrderDto.java @@ -1,8 +1,8 @@ package com.bsd.pjcloud.hard.api.dto.order; -import com.bsd.pjcloud.hard.api.entity.order.HardwareOrderEntity; +import com.bsd.pjcloud.hard.api.entity.order.HardOrderEntity; import lombok.Data; @Data -public class HardOrderDto extends HardwareOrderEntity { +public class HardOrderDto extends HardOrderEntity { } diff --git a/pjcloud-hardware/pjcloud-hardware-api/src/main/java/com/bsd/pjcloud/hard/api/entity/HardInvoiceEntity.java b/pjcloud-hardware/pjcloud-hardware-api/src/main/java/com/bsd/pjcloud/hard/api/entity/HardInvoiceEntity.java index 306f94e3f..3eb52df1a 100644 --- a/pjcloud-hardware/pjcloud-hardware-api/src/main/java/com/bsd/pjcloud/hard/api/entity/HardInvoiceEntity.java +++ b/pjcloud-hardware/pjcloud-hardware-api/src/main/java/com/bsd/pjcloud/hard/api/entity/HardInvoiceEntity.java @@ -3,8 +3,7 @@ package com.bsd.pjcloud.hard.api.entity; import com.baomidou.mybatisplus.annotation.*; import com.baomidou.mybatisplus.extension.activerecord.Model; import io.swagger.v3.oas.annotations.media.Schema; -import lombok.Data; -import lombok.EqualsAndHashCode; +import lombok.*; import com.bsd.pjcloud.common.core.util.TenantTable; import java.time.LocalDateTime; @@ -14,6 +13,9 @@ import java.time.LocalDateTime; * @author dzc * @date 2025-01-05 14:17:32 */ +@Builder +@AllArgsConstructor +@NoArgsConstructor @Data @TenantTable @TableName("hard_invoice") diff --git a/pjcloud-hardware/pjcloud-hardware-api/src/main/java/com/bsd/pjcloud/hard/api/entity/order/HardCarEntity.java b/pjcloud-hardware/pjcloud-hardware-api/src/main/java/com/bsd/pjcloud/hard/api/entity/order/HardCarEntity.java index 7861b4c2f..ed4f1cb16 100644 --- a/pjcloud-hardware/pjcloud-hardware-api/src/main/java/com/bsd/pjcloud/hard/api/entity/order/HardCarEntity.java +++ b/pjcloud-hardware/pjcloud-hardware-api/src/main/java/com/bsd/pjcloud/hard/api/entity/order/HardCarEntity.java @@ -60,7 +60,7 @@ public class HardCarEntity extends Model { * 商品价格 */ @Schema(description="商品价格") - private Long productPrice; + private Integer productPrice; /** * 数量 diff --git a/pjcloud-hardware/pjcloud-hardware-api/src/main/java/com/bsd/pjcloud/hard/api/entity/order/HardwareOrderEntity.java b/pjcloud-hardware/pjcloud-hardware-api/src/main/java/com/bsd/pjcloud/hard/api/entity/order/HardOrderEntity.java similarity index 96% rename from pjcloud-hardware/pjcloud-hardware-api/src/main/java/com/bsd/pjcloud/hard/api/entity/order/HardwareOrderEntity.java rename to pjcloud-hardware/pjcloud-hardware-api/src/main/java/com/bsd/pjcloud/hard/api/entity/order/HardOrderEntity.java index c52268f5c..0319e1c40 100644 --- a/pjcloud-hardware/pjcloud-hardware-api/src/main/java/com/bsd/pjcloud/hard/api/entity/order/HardwareOrderEntity.java +++ b/pjcloud-hardware/pjcloud-hardware-api/src/main/java/com/bsd/pjcloud/hard/api/entity/order/HardOrderEntity.java @@ -3,8 +3,7 @@ package com.bsd.pjcloud.hard.api.entity.order; import com.baomidou.mybatisplus.annotation.*; import com.baomidou.mybatisplus.extension.activerecord.Model; import io.swagger.v3.oas.annotations.media.Schema; -import lombok.Data; -import lombok.EqualsAndHashCode; +import lombok.*; import com.bsd.pjcloud.common.core.util.TenantTable; import java.time.LocalDateTime; @@ -14,12 +13,15 @@ import java.time.LocalDateTime; * @author dzc * @date 2025-01-05 16:46:25 */ +@Builder +@AllArgsConstructor +@NoArgsConstructor @Data @TenantTable @TableName("hardware_order") @EqualsAndHashCode(callSuper = true) @Schema(description = "订单表") -public class HardwareOrderEntity extends Model { +public class HardOrderEntity extends Model { /** diff --git a/pjcloud-hardware/pjcloud-hardware-api/src/main/java/com/bsd/pjcloud/hard/api/utils/Drawing2D.java b/pjcloud-hardware/pjcloud-hardware-api/src/main/java/com/bsd/pjcloud/hard/api/utils/Drawing2D.java new file mode 100644 index 000000000..90adf0301 --- /dev/null +++ b/pjcloud-hardware/pjcloud-hardware-api/src/main/java/com/bsd/pjcloud/hard/api/utils/Drawing2D.java @@ -0,0 +1,229 @@ +package com.bsd.pjcloud.hard.api.utils; + +import javax.imageio.ImageIO; +import java.awt.*; +import java.awt.image.BufferedImage; +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; +import java.io.IOException; +import java.io.InputStream; + +public class Drawing2D { + + /** + * start ****************** config ****************** start + */ + private Graphics2D graphics; + private BufferedImage canvas; + + /** + * 固定尺寸 + * static int mm58 = 384; + * static const mm80_Old = 500; + * static const mm80 = 570; + */ + private final int canvasWidth = 340; + private final int canvasHeight = 200; + + private int currentWidth = canvasWidth; + private int currentHeight = canvasHeight; + + private final int horizontalPadding = 20; + + private final String fontFamily = "宋体"; + + /** + * end ****************** config ****************** end + */ + + private int currentY = 0; + + private int getCurrentY() { + computedHeight(); + int size = graphics.getFont().getSize(); + FontMetrics metrics = graphics.getFontMetrics(graphics.getFont()); + int lineHeight = metrics.getHeight(); + int offset = (lineHeight - size) / 2; + return currentY + offset; + } + + private int[] getPaddingX() { + return new int[]{horizontalPadding, canvasWidth - horizontalPadding}; + } + + + public Drawing2D() { + canvas = new BufferedImage(canvasWidth, canvasHeight, BufferedImage.TYPE_INT_RGB); + graphics = canvas.createGraphics(); + // 设置背景颜色为白色 + graphics.setColor(Color.WHITE); + graphics.fillRect(0, 0, canvasWidth, canvasHeight); + } + + // 虚线 + public Drawing2D drawingDottedLine() { + return drawingDottedLine(5); + } + + public Drawing2D drawingDottedLine(int padding) { + if (padding != 0) currentY += padding; + float[] dashPattern = {10f, 5f}; + Stroke dashedStroke = new BasicStroke(2f, BasicStroke.CAP_BUTT, BasicStroke.JOIN_BEVEL, 0f, dashPattern, 0f); + graphics.setStroke(dashedStroke); + graphics.setColor(Color.BLACK); + + currentY += 5; + int y = getCurrentY(); + + graphics.drawLine(0, y, canvasWidth, y); + if (padding != 0) currentY += padding; + return this; + } + + public Drawing2D drawingText(String str) { + textPadding(); + computedLineHeight(); + graphics.drawString(str, 0, getCurrentY()); + textPadding(); + return this; + } + + public Drawing2D drawingCenterText(String str) { + textPadding(); + computedLineHeight(); + Point point = centerPosition(str); + graphics.drawString(str, point.x, getCurrentY()); + textPadding(); + return this; + } + + public Drawing2D drawingRowText(String leftStr, String rightStr) { + textPadding(); + computedLineHeight(); + FontMetrics metrics = graphics.getFontMetrics(graphics.getFont()); + int leftTextWidth = metrics.stringWidth(leftStr); + int rightTextWidth = metrics.stringWidth(rightStr); + int y = getCurrentY(); + graphics.drawString(leftStr, 0, y); + graphics.drawString(rightStr, canvasWidth - rightTextWidth, y); + textPadding(); + return this; + } + + public Drawing2D drawingRowText(String str1, String str2, String str3) { + textPadding(); + computedLineHeight(); + int y = getCurrentY(); + int width = canvasWidth / 3; + + FontMetrics metrics = graphics.getFontMetrics(graphics.getFont()); + int str1Width = metrics.stringWidth(str1); + int str2Width = metrics.stringWidth(str2); + int str3Width = metrics.stringWidth(str3); + + int str1x = 0; + int str2x = width + (width - str2Width) / 2; + int str3x = width * 2 + (width - str3Width); + + graphics.drawString(str1, str1x, y); + graphics.drawString(str2, str2x, y); + graphics.drawString(str3, str3x, y); + textPadding(); + return this; + } + + public Drawing2D setTitleTextStyle() { + graphics.setColor(Color.BLACK); + graphics.setFont(new Font(fontFamily, Font.BOLD, 24)); + return this; + } + + public Drawing2D setDefaultStyle() { + graphics.setColor(Color.BLACK); + graphics.setFont(new Font(fontFamily, Font.PLAIN, 20)); + return this; + } + + public InputStream getInputStream() throws IOException { + drawingWhiteSide(); + graphics.dispose(); + ByteArrayOutputStream bytes = new ByteArrayOutputStream(); + ImageIO.write(canvas, "png", bytes); + bytes.flush(); + byte[] imageBytes = bytes.toByteArray(); + bytes.close(); + return new ByteArrayInputStream(imageBytes); + } + + public byte[] getBytes() throws IOException { + drawingWhiteSide(); + graphics.dispose(); + ByteArrayOutputStream bytes = new ByteArrayOutputStream(); + ImageIO.write(canvas, "png", bytes); + bytes.flush(); + byte[] imageBytes = bytes.toByteArray(); + bytes.close(); + return imageBytes; + } + + // 计算居中的x,y + private Point centerPosition(String str) { + FontMetrics metrics = graphics.getFontMetrics(graphics.getFont()); + int textWidth = metrics.stringWidth(str); + int textHeight = metrics.getHeight(); + // 中心X坐标 + int x = (canvasWidth - textWidth) / 2; + // 中心Y坐标 + int y = (currentHeight - textHeight) / 2 + metrics.getAscent(); + return new Point(x, y); + } + + private void drawingWhiteSide() { + int borderSize = 15; + BufferedImage borderedCanvas = new BufferedImage(currentWidth + borderSize * 2, currentHeight + borderSize * 2, BufferedImage.TYPE_INT_RGB); + Graphics2D g2dBordered = borderedCanvas.createGraphics(); + + g2dBordered.setColor(Color.WHITE); + g2dBordered.fillRect(0, 0, borderedCanvas.getWidth(), borderedCanvas.getHeight()); + + g2dBordered.drawImage(canvas, borderSize, borderSize, null); + + graphics = g2dBordered; + canvas = borderedCanvas; + } + + private void computedHeight() { + Font font = graphics.getFont(); + FontMetrics metrics = graphics.getFontMetrics(font); + int height = currentY + metrics.getAscent(); + if (height <= currentHeight) return; + + graphics.dispose(); + + currentHeight = height + metrics.getAscent(); + BufferedImage newCanvas = new BufferedImage(currentWidth, currentHeight, BufferedImage.TYPE_INT_RGB); + Graphics2D newGraphics = newCanvas.createGraphics(); + newGraphics.setColor(Color.WHITE); + newGraphics.fillRect(0, 0, newCanvas.getWidth(), newCanvas.getHeight()); + newGraphics.drawImage(canvas, 0, 0, null); + + canvas = newCanvas; + + newGraphics.setColor(graphics.getColor()); + newGraphics.setFont(graphics.getFont()); + graphics = newGraphics; + + } + + private void textPadding() { + currentY += 10; + } + + private void computedLineHeight() { + int size = graphics.getFont().getSize(); + FontMetrics metrics = graphics.getFontMetrics(graphics.getFont()); + int lineHeight = metrics.getHeight(); + int offset = (lineHeight - size) / 2; + currentY += size + offset; + } +} \ No newline at end of file diff --git a/pjcloud-hardware/pjcloud-hardware-api/src/main/java/com/bsd/pjcloud/hard/api/vo/HardInvoiceVo.java b/pjcloud-hardware/pjcloud-hardware-api/src/main/java/com/bsd/pjcloud/hard/api/vo/HardInvoiceVo.java index aed44aacc..289e7933e 100644 --- a/pjcloud-hardware/pjcloud-hardware-api/src/main/java/com/bsd/pjcloud/hard/api/vo/HardInvoiceVo.java +++ b/pjcloud-hardware/pjcloud-hardware-api/src/main/java/com/bsd/pjcloud/hard/api/vo/HardInvoiceVo.java @@ -7,8 +7,10 @@ import lombok.Data; @Data public class HardInvoiceVo extends HardInvoiceEntity implements BaseDeptInterface, BaseMchInterface { + private String deptName; private Long merchantId; + private String merchantName; } diff --git a/pjcloud-hardware/pjcloud-hardware-api/src/main/java/com/bsd/pjcloud/hard/api/vo/order/HardOrderVo.java b/pjcloud-hardware/pjcloud-hardware-api/src/main/java/com/bsd/pjcloud/hard/api/vo/order/HardOrderVo.java index e02e81d1f..f85fa99a3 100644 --- a/pjcloud-hardware/pjcloud-hardware-api/src/main/java/com/bsd/pjcloud/hard/api/vo/order/HardOrderVo.java +++ b/pjcloud-hardware/pjcloud-hardware-api/src/main/java/com/bsd/pjcloud/hard/api/vo/order/HardOrderVo.java @@ -1,8 +1,8 @@ package com.bsd.pjcloud.hard.api.vo.order; -import com.bsd.pjcloud.hard.api.entity.order.HardwareOrderEntity; +import com.bsd.pjcloud.hard.api.entity.order.HardOrderEntity; import lombok.Data; @Data -public class HardOrderVo extends HardwareOrderEntity { +public class HardOrderVo extends HardOrderEntity { } diff --git a/pjcloud-hardware/pjcloud-hardware-biz/src/main/java/com/bsd/pjcloud/hard/controller/hard/HardApiController.java b/pjcloud-hardware/pjcloud-hardware-biz/src/main/java/com/bsd/pjcloud/hard/controller/hard/HardApiController.java index 9d15ad378..c4b8ffcad 100644 --- a/pjcloud-hardware/pjcloud-hardware-biz/src/main/java/com/bsd/pjcloud/hard/controller/hard/HardApiController.java +++ b/pjcloud-hardware/pjcloud-hardware-biz/src/main/java/com/bsd/pjcloud/hard/controller/hard/HardApiController.java @@ -3,26 +3,25 @@ package com.bsd.pjcloud.hard.controller.hard; import com.bsd.pjcloud.common.core.util.BeanUtils; import com.bsd.pjcloud.common.core.util.R; import com.bsd.pjcloud.common.idempotent.annotation.Idempotent; +import com.bsd.pjcloud.hard.api.dto.async.SyncOfflineReqVo; +import com.bsd.pjcloud.hard.api.dto.hard.HandCancelCodeDto; import com.bsd.pjcloud.hard.api.dto.hard.HardBindDto; import com.bsd.pjcloud.hard.api.dto.hard.HardCreateOrderDto; +import com.bsd.pjcloud.hard.api.vo.HardInvoiceVo; import com.bsd.pjcloud.hard.api.vo.HardManagerVo; import com.bsd.pjcloud.hard.api.vo.order.HardCarVo; import com.bsd.pjcloud.hard.api.vo.order.HardOrderVo; -import com.bsd.pjcloud.hard.service.HardCarService; -import com.bsd.pjcloud.hard.service.HardManagerService; -import com.bsd.pjcloud.hard.service.HardwareOrderService; +import com.bsd.pjcloud.hard.service.*; import io.swagger.v3.oas.annotations.Operation; import io.swagger.v3.oas.annotations.security.SecurityRequirement; import io.swagger.v3.oas.annotations.tags.Tag; -import jakarta.servlet.http.HttpServletRequest; +import jakarta.validation.Valid; import lombok.RequiredArgsConstructor; import org.springframework.http.HttpHeaders; import org.springframework.web.bind.annotation.*; import java.util.List; -import static cn.hutool.extra.servlet.JakartaServletUtil.getClientIP; - @RestController @RequiredArgsConstructor @RequestMapping("/hard-api") @@ -31,8 +30,10 @@ import static cn.hutool.extra.servlet.JakartaServletUtil.getClientIP; public class HardApiController { private final HardManagerService hardManagerService; + private final HardInvoiceService hardInvoiceService; private final HardCarService hardCarService; - private final HardwareOrderService hardwareOrderService; + private final HardOrderService hardwareOrderService; + private final HardOrderSyncService hardOrderSyncService; @PostMapping("/bind") @Operation(summary = "绑定服务端设备") @@ -61,9 +62,35 @@ public class HardApiController { @PostMapping("/create-order") @Operation(summary = "创建订单") @Idempotent(expireTime = 10, info = "正在创建订单中,请勿重复操作") - public R createOrder(HttpServletRequest request, @RequestBody HardCreateOrderDto dto) { - dto.setClientIP(getClientIP(request)); + public R createOrder(@Valid @RequestBody HardCreateOrderDto dto) { return R.ok(hardwareOrderService.createOrder(dto)); } + @PostMapping("/cancel-code") + @Operation(summary = "核销二维码") + @Idempotent(expireTime = 10, info = "正在支付中,请勿重复操作") + public R handCancelCode(@Valid @RequestBody HandCancelCodeDto dto) { + return R.ok(hardwareOrderService.handCancelCode(dto)); + } + + @GetMapping("/generate-invoice") + @Operation(summary = "生成发票") + @Idempotent(expireTime = 10, info = "正在生成中,请勿重复操作") + public R generateInvoice(@RequestParam Long orderId) { + return R.ok(hardInvoiceService.generateInvoice(orderId)); + } + + @GetMapping("/print-invoice") + @Operation(summary = "打印成功") + public R printInvoice(@RequestParam("orderId") Long orderId, @RequestParam("historyId") Long historyId) { + return R.ok(hardInvoiceService.printInvoice(orderId, historyId)); + } + + @PostMapping("/sync-offline-order") + @Operation(summary = "同步离线订单") + @Idempotent(expireTime = 10, info = "正在处理中,请勿重复操作") + public R> syncOfflineOrder(@Valid @RequestBody SyncOfflineReqVo dto) { + return R.ok(hardOrderSyncService.syncOfflineOrder(dto)); + } + } diff --git a/pjcloud-hardware/pjcloud-hardware-biz/src/main/java/com/bsd/pjcloud/hard/controller/order/HardwareOrderController.java b/pjcloud-hardware/pjcloud-hardware-biz/src/main/java/com/bsd/pjcloud/hard/controller/order/HardwareOrderController.java index 3a63cdbe2..308bbfb01 100644 --- a/pjcloud-hardware/pjcloud-hardware-biz/src/main/java/com/bsd/pjcloud/hard/controller/order/HardwareOrderController.java +++ b/pjcloud-hardware/pjcloud-hardware-biz/src/main/java/com/bsd/pjcloud/hard/controller/order/HardwareOrderController.java @@ -8,8 +8,8 @@ import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.bsd.pjcloud.common.core.util.R; import com.bsd.pjcloud.common.log.annotation.SysLog; import com.bsd.pjcloud.hard.api.dto.order.HardOrderDto; -import com.bsd.pjcloud.hard.api.entity.order.HardwareOrderEntity; -import com.bsd.pjcloud.hard.service.HardwareOrderService; +import com.bsd.pjcloud.hard.api.entity.order.HardOrderEntity; +import com.bsd.pjcloud.hard.service.HardOrderService; import org.springframework.security.access.prepost.PreAuthorize; import com.bsd.pjcloud.common.excel.annotation.ResponseExcel; import io.swagger.v3.oas.annotations.security.SecurityRequirement; @@ -35,13 +35,13 @@ import java.util.List; @SecurityRequirement(name = HttpHeaders.AUTHORIZATION) public class HardwareOrderController { - private final HardwareOrderService hardwareOrderService; + private final HardOrderService hardwareOrderService; @Operation(summary = "分页查询", description = "分页查询") @GetMapping("/page") @PreAuthorize("@pms.hasPermission('hard_hardwareOrder_view')") - public R getHardwareOrderPage(@ParameterObject Page page, @ParameterObject HardwareOrderEntity hardwareOrder) { - LambdaQueryWrapper wrapper = Wrappers.lambdaQuery(); + public R getHardwareOrderPage(@ParameterObject Page page, @ParameterObject HardOrderEntity hardwareOrder) { + LambdaQueryWrapper wrapper = Wrappers.lambdaQuery(); return R.ok(hardwareOrderService.page(page, wrapper)); } @@ -63,7 +63,7 @@ public class HardwareOrderController { @SysLog("新增订单表") @PostMapping @PreAuthorize("@pms.hasPermission('hard_hardwareOrder_add')") - public R save(@RequestBody HardwareOrderEntity hardwareOrder) { + public R save(@RequestBody HardOrderEntity hardwareOrder) { return R.ok(hardwareOrderService.save(hardwareOrder)); } @@ -71,7 +71,7 @@ public class HardwareOrderController { @SysLog("修改订单表") @PutMapping @PreAuthorize("@pms.hasPermission('hard_hardwareOrder_edit')") - public R updateById(@RequestBody HardwareOrderEntity hardwareOrder) { + public R updateById(@RequestBody HardOrderEntity hardwareOrder) { return R.ok(hardwareOrderService.updateById(hardwareOrder)); } @@ -86,7 +86,7 @@ public class HardwareOrderController { @ResponseExcel @GetMapping("/export") @PreAuthorize("@pms.hasPermission('hard_hardwareOrder_export')") - public List export(HardwareOrderEntity hardwareOrder, Long[] ids) { - return hardwareOrderService.list(Wrappers.lambdaQuery(hardwareOrder).in(ArrayUtil.isNotEmpty(ids), HardwareOrderEntity::getId, ids)); + public List export(HardOrderEntity hardwareOrder, Long[] ids) { + return hardwareOrderService.list(Wrappers.lambdaQuery(hardwareOrder).in(ArrayUtil.isNotEmpty(ids), HardOrderEntity::getId, ids)); } } \ No newline at end of file diff --git a/pjcloud-hardware/pjcloud-hardware-biz/src/main/java/com/bsd/pjcloud/hard/mapper/order/HardOrderMapper.java b/pjcloud-hardware/pjcloud-hardware-biz/src/main/java/com/bsd/pjcloud/hard/mapper/order/HardOrderMapper.java index 16619ed7e..a4e9b1249 100644 --- a/pjcloud-hardware/pjcloud-hardware-biz/src/main/java/com/bsd/pjcloud/hard/mapper/order/HardOrderMapper.java +++ b/pjcloud-hardware/pjcloud-hardware-biz/src/main/java/com/bsd/pjcloud/hard/mapper/order/HardOrderMapper.java @@ -3,22 +3,22 @@ package com.bsd.pjcloud.hard.mapper.order; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.bsd.pjcloud.common.data.datascope.PjcloudBaseMapper; import com.bsd.pjcloud.hard.api.dto.order.HardOrderDto; -import com.bsd.pjcloud.hard.api.entity.order.HardwareOrderEntity; +import com.bsd.pjcloud.hard.api.entity.order.HardOrderEntity; import com.bsd.pjcloud.hard.api.vo.order.HardOrderVo; import com.github.yulichang.wrapper.MPJLambdaWrapper; import org.apache.ibatis.annotations.Mapper; @Mapper -public interface HardOrderMapper extends PjcloudBaseMapper { +public interface HardOrderMapper extends PjcloudBaseMapper { default Page pageJoin(Page page, HardOrderDto dto) { - MPJLambdaWrapper wrapper = new MPJLambdaWrapper() - .selectAll(HardwareOrderEntity.class); + MPJLambdaWrapper wrapper = new MPJLambdaWrapper() + .selectAll(HardOrderEntity.class); return selectJoinPage(page, HardOrderVo.class, wrapper); } default HardOrderVo join(HardOrderDto dto) { - MPJLambdaWrapper wrapper = new MPJLambdaWrapper() - .selectAll(HardwareOrderEntity.class); + MPJLambdaWrapper wrapper = new MPJLambdaWrapper() + .selectAll(HardOrderEntity.class); return selectJoinOne(HardOrderVo.class, wrapper); } } \ No newline at end of file diff --git a/pjcloud-hardware/pjcloud-hardware-biz/src/main/java/com/bsd/pjcloud/hard/service/HardCarService.java b/pjcloud-hardware/pjcloud-hardware-biz/src/main/java/com/bsd/pjcloud/hard/service/HardCarService.java index 0041cb494..25269ad74 100644 --- a/pjcloud-hardware/pjcloud-hardware-biz/src/main/java/com/bsd/pjcloud/hard/service/HardCarService.java +++ b/pjcloud-hardware/pjcloud-hardware-biz/src/main/java/com/bsd/pjcloud/hard/service/HardCarService.java @@ -21,11 +21,19 @@ public interface HardCarService extends IService { Integer computerCarTotalPrice(@NotNull HardTypeEnum sysType, @NotEmpty List list); /** - * @param userId 用户id + * @param userId 用户id * @param merchantId 商户id - * @param sysType 硬件设备类型 - * @param list g购物车类表 + * @param sysType 硬件设备类型 + * @param list g购物车类表 * @return 父购物车id */ Long createCard(Long userId, Long merchantId, HardTypeEnum sysType, List list); + + /** + * 生成购买商品的描述 + * @param sysType 订单类型 + * @param list 购物车列表 + * @return + */ + String computerCarSubject(HardTypeEnum sysType, List list); } \ No newline at end of file diff --git a/pjcloud-hardware/pjcloud-hardware-biz/src/main/java/com/bsd/pjcloud/hard/service/HardInvoiceService.java b/pjcloud-hardware/pjcloud-hardware-biz/src/main/java/com/bsd/pjcloud/hard/service/HardInvoiceService.java index e1cdca6fc..62e93697e 100644 --- a/pjcloud-hardware/pjcloud-hardware-biz/src/main/java/com/bsd/pjcloud/hard/service/HardInvoiceService.java +++ b/pjcloud-hardware/pjcloud-hardware-biz/src/main/java/com/bsd/pjcloud/hard/service/HardInvoiceService.java @@ -3,10 +3,45 @@ package com.bsd.pjcloud.hard.service; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.baomidou.mybatisplus.extension.service.IService; import com.bsd.pjcloud.hard.api.dto.HardInvoiceDto; +import com.bsd.pjcloud.hard.api.dto.async.SyncOfflineReqVo; import com.bsd.pjcloud.hard.api.entity.HardInvoiceEntity; +import com.bsd.pjcloud.hard.api.entity.order.HardOrderEntity; import com.bsd.pjcloud.hard.api.vo.HardInvoiceVo; +import jakarta.validation.Valid; + +import java.util.List; public interface HardInvoiceService extends IService { Page pageJoin(Page page, HardInvoiceDto dto); + + /** + * 生成发票 + * @param order + * @return 订单详情 + */ + String generateInvoice(HardOrderEntity order); + + /** + * 生成发票 + * @param order 订单详情 + * @param code 取消码 + * @return + */ + String generateInvoice(HardOrderEntity order, String code); + + /** + * 生成发票图片 + * @param orderId + * @return + */ + HardInvoiceVo generateInvoice(Long orderId); + + /** + * 打印成功通知 + * @param orderId + * @param historyId + * @return + */ + Boolean printInvoice(Long orderId, Long historyId); } \ No newline at end of file diff --git a/pjcloud-hardware/pjcloud-hardware-biz/src/main/java/com/bsd/pjcloud/hard/service/HardwareOrderService.java b/pjcloud-hardware/pjcloud-hardware-biz/src/main/java/com/bsd/pjcloud/hard/service/HardOrderService.java similarity index 52% rename from pjcloud-hardware/pjcloud-hardware-biz/src/main/java/com/bsd/pjcloud/hard/service/HardwareOrderService.java rename to pjcloud-hardware/pjcloud-hardware-biz/src/main/java/com/bsd/pjcloud/hard/service/HardOrderService.java index 8b968d362..493aadb41 100644 --- a/pjcloud-hardware/pjcloud-hardware-biz/src/main/java/com/bsd/pjcloud/hard/service/HardwareOrderService.java +++ b/pjcloud-hardware/pjcloud-hardware-biz/src/main/java/com/bsd/pjcloud/hard/service/HardOrderService.java @@ -2,12 +2,14 @@ package com.bsd.pjcloud.hard.service; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.baomidou.mybatisplus.extension.service.IService; +import com.bsd.pjcloud.hard.api.dto.hard.HandCancelCodeDto; import com.bsd.pjcloud.hard.api.dto.hard.HardCreateOrderDto; import com.bsd.pjcloud.hard.api.dto.order.HardOrderDto; -import com.bsd.pjcloud.hard.api.entity.order.HardwareOrderEntity; +import com.bsd.pjcloud.hard.api.entity.order.HardOrderEntity; import com.bsd.pjcloud.hard.api.vo.order.HardOrderVo; +import jakarta.validation.Valid; -public interface HardwareOrderService extends IService { +public interface HardOrderService extends IService { Page pageJoin(Page page, HardOrderDto dto); @@ -15,6 +17,13 @@ public interface HardwareOrderService extends IService { Long createOrder(HardCreateOrderDto dto); + /** + * 快速扣款 + * + * @param order 订单详情 + */ + void fastReduceBalance(HardOrderEntity order); + /** * 计算额外金额 * @@ -22,4 +31,17 @@ public interface HardwareOrderService extends IService { * @return */ Integer computeExtraPrice(Integer price); + + /** + * 核销二维码 + */ + void cancelCode(HardOrderEntity order); + + /** + * 核销硬件二维码 + * + * @param dto + * @return + */ + Boolean handCancelCode(@Valid HandCancelCodeDto dto); } \ No newline at end of file diff --git a/pjcloud-hardware/pjcloud-hardware-biz/src/main/java/com/bsd/pjcloud/hard/service/HardOrderSyncService.java b/pjcloud-hardware/pjcloud-hardware-biz/src/main/java/com/bsd/pjcloud/hard/service/HardOrderSyncService.java new file mode 100644 index 000000000..843c40226 --- /dev/null +++ b/pjcloud-hardware/pjcloud-hardware-biz/src/main/java/com/bsd/pjcloud/hard/service/HardOrderSyncService.java @@ -0,0 +1,17 @@ +package com.bsd.pjcloud.hard.service; + +import com.bsd.pjcloud.hard.api.dto.async.SyncOfflineReqVo; +import jakarta.validation.Valid; + +import java.util.List; + +public interface HardOrderSyncService { + + /** + * 同步安卓机离线订单 + * @param dto + * @return + */ + List syncOfflineOrder(@Valid SyncOfflineReqVo dto); + +} diff --git a/pjcloud-hardware/pjcloud-hardware-biz/src/main/java/com/bsd/pjcloud/hard/service/impl/HardInvoiceServiceImpl.java b/pjcloud-hardware/pjcloud-hardware-biz/src/main/java/com/bsd/pjcloud/hard/service/impl/HardInvoiceServiceImpl.java index e19cee0be..6f6155088 100644 --- a/pjcloud-hardware/pjcloud-hardware-biz/src/main/java/com/bsd/pjcloud/hard/service/impl/HardInvoiceServiceImpl.java +++ b/pjcloud-hardware/pjcloud-hardware-biz/src/main/java/com/bsd/pjcloud/hard/service/impl/HardInvoiceServiceImpl.java @@ -1,16 +1,48 @@ package com.bsd.pjcloud.hard.service.impl; +import cn.hutool.core.date.DatePattern; +import cn.hutool.core.date.LocalDateTimeUtil; +import cn.hutool.core.util.ObjectUtil; +import com.alibaba.fastjson.JSON; +import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; +import com.bsd.pjcloud.admin.api.dto.UserInfo; +import com.bsd.pjcloud.admin.api.entity.SysUser; +import com.bsd.pjcloud.admin.api.feign.RemoteFileService; +import com.bsd.pjcloud.admin.api.feign.RemoteUserService; +import com.bsd.pjcloud.common.core.util.BeanUtils; +import com.bsd.pjcloud.common.core.util.R; +import com.bsd.pjcloud.hard.api.constant.HardPrintStatusEnum; +import com.bsd.pjcloud.hard.api.constant.HardTypeEnum; +import com.bsd.pjcloud.hard.api.constant.order.HardOrderTypeEnum; import com.bsd.pjcloud.hard.api.dto.HardInvoiceDto; import com.bsd.pjcloud.hard.api.entity.HardInvoiceEntity; +import com.bsd.pjcloud.hard.api.entity.HardManagerEntity; +import com.bsd.pjcloud.hard.api.entity.order.HardCarEntity; +import com.bsd.pjcloud.hard.api.entity.order.HardOrderEntity; +import com.bsd.pjcloud.hard.api.utils.Drawing2D; import com.bsd.pjcloud.hard.api.vo.HardInvoiceVo; import com.bsd.pjcloud.hard.mapper.HardInvoiceMapper; +import com.bsd.pjcloud.hard.service.HardCarService; import com.bsd.pjcloud.hard.service.HardInvoiceService; +import com.bsd.pjcloud.hard.service.HardManagerService; +import com.bsd.pjcloud.hard.service.HardOrderService; +import com.bsd.pjcloud.wallet.api.feign.RemoteMchService; +import com.bsd.pjcloud.wallet.api.vo.MchManageVo; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; +import org.springframework.mock.web.MockMultipartFile; import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; import org.springframework.validation.annotation.Validated; +import org.springframework.web.multipart.MultipartFile; + +import java.io.ByteArrayInputStream; +import java.io.IOException; +import java.util.List; +import java.util.Map; +import java.util.Optional; /** * 发票记录 @@ -24,9 +56,123 @@ import org.springframework.validation.annotation.Validated; @Service public class HardInvoiceServiceImpl extends ServiceImpl implements HardInvoiceService { + static private final String TAG = "发票记录"; + + private final HardManagerService hardManagerService; + private final HardOrderService orderService; + private final HardCarService carService; + + private final RemoteUserService userService; + private final RemoteMchService mchService; + private final RemoteFileService fileService; + @Override public Page pageJoin(Page page, HardInvoiceDto dto) { Page list = baseMapper.pageJoin(page, dto); return list; } + + @Override + public String generateInvoice(HardOrderEntity order) { + return generateInvoice(order, null); + } + + @Override + public String generateInvoice(HardOrderEntity order, String code) { + List carList = carService.list(new LambdaQueryWrapper() + .eq(HardCarEntity::getParentCarId, order.getParentCarId()) + ); + // 查询用户 + UserInfo user = Optional.of(userService.getByUserId(order.getUserId())).map(R::getData).orElseThrow(() -> new RuntimeException("用户不存在")); + SysUser sysUser = user.getSysUser(); + // 查询商户 + MchManageVo mch = Optional.of(mchService.getById(order.getMerchantId())).map(R::getData).orElseThrow(() -> new RuntimeException("商户不存在")); + // 订单类型 + String orderType = "- -"; + HardOrderTypeEnum orderTypeEnum = HardOrderTypeEnum.valueOf(order.getOrderType()); + if (ObjectUtil.isNotEmpty(orderTypeEnum)) { + orderType = orderTypeEnum.getDescription(); + } + // 硬件类型 + String hardwareName = HardTypeEnum.CANTEEN.getType(); + HardTypeEnum sysTypeEnum = HardTypeEnum.valueOf(order.getSysType()); + if (ObjectUtil.isNotEmpty(sysTypeEnum)) { + hardwareName = sysTypeEnum.getDescription(); + } + Drawing2D drawing = new Drawing2D(); + drawing.setTitleTextStyle() + .drawingCenterText(String.format("智慧%s", hardwareName)) + .drawingDottedLine(); + String createTime = LocalDateTimeUtil.format(order.getCreateTime(), DatePattern.NORM_DATETIME_PATTERN); + String payTime = LocalDateTimeUtil.format(order.getPayTime(), DatePattern.NORM_DATETIME_PATTERN); + drawing.setDefaultStyle() + .drawingRowText("订单号", order.getId().toString()) + .drawingRowText("订单类型", orderType) + .drawingRowText("用户", sysUser.getName()) + .drawingRowText("手机号", sysUser.getPhone()) + .drawingRowText("商户", mch.getName()) + .drawingRowText("部门", mch.getDeptName()) + .drawingRowText("下单时间", createTime) + .drawingRowText("支付时间", payTime); + if (ObjectUtil.isNotEmpty(carList)) { + drawing.drawingDottedLine(); + drawing.drawingRowText("商品", "数量", "总价"); + carList.forEach(v -> { + String name = v.getProductName(); + String count = v.getProductCount().toString(); + if (count.length() > 4) { + count = count.substring(0, 4) + "..."; + } + String totalPrice = String.valueOf((v.getTotalPrice() / 100)); + drawing.drawingRowText(name, count, totalPrice); + }); + String totalPrice = String.valueOf(order.getTotalPrice() / 100); + String amountMealPrice = String.valueOf(order.getExtraPrice() / 100); + if (ObjectUtil.isNotEmpty(order.getExtraPrice()) && ObjectUtil.notEqual(order.getExtraPrice(), 0)) { + drawing.drawingRowText("额外支付金额", amountMealPrice); + } + drawing.drawingRowText("小记", totalPrice).drawingDottedLine(); + } + String currentTime = LocalDateTimeUtil.format(LocalDateTimeUtil.now(), DatePattern.NORM_DATETIME_PATTERN); + drawing.drawingRowText("打印时间", currentTime).drawingDottedLine(); + if (ObjectUtil.isNotEmpty(code)) { + drawing.drawingDottedLine().drawingRowText("取件码", code).drawingDottedLine(); + } + try { + String fileName = String.format("invoice_%s_%s.png", order.getId(), LocalDateTimeUtil.now()); + byte[] bytes = drawing.getBytes(); + MultipartFile multipartFile = new MockMultipartFile("file", fileName + ".png", "image/png", new ByteArrayInputStream(bytes)); + Map uploadMap = (Map) fileService.innerUpload(multipartFile, null, null, null).getData(); + return (String) uploadMap.get("url"); + } catch (IOException e) { + e.printStackTrace(); + log.error("|{}|生成发票意外的错误dto:|{}|error:|{}|", TAG, JSON.toJSONString(order), e.getMessage()); + return ""; + } + } + + @Override + @Transactional(rollbackFor = Exception.class) + public HardInvoiceVo generateInvoice(Long orderId) { + HardOrderEntity order = orderService.getById(orderId); + if (ObjectUtil.isEmpty(order)) throw new RuntimeException("设备订单不存在"); + HardManagerEntity hardManager = hardManagerService.getById(order.getHardId()); + if (ObjectUtil.isEmpty(order)) throw new RuntimeException("设备不存在"); + String image = generateInvoice(order); + if (ObjectUtil.isEmpty(image)) return null; + HardInvoiceEntity insertObj = HardInvoiceEntity.builder().hardId(hardManager.getId()).hardOrderId(orderId).pic(image).status(HardPrintStatusEnum.GENERATE.getType()).build(); + baseMapper.insert(insertObj); + return BeanUtils.toBean(insertObj, HardInvoiceVo.class); + } + + @Override + public Boolean printInvoice(Long orderId, Long historyId) { + HardOrderEntity order = orderService.getById(orderId); + if (ObjectUtil.isEmpty(order)) throw new RuntimeException("设备订单不存在"); + HardInvoiceEntity detail = baseMapper.selectById(historyId); + if (ObjectUtil.isEmpty(detail)) throw new RuntimeException("开票记录不存在"); + if (!ObjectUtil.equals(detail.getStatus(), HardPrintStatusEnum.GENERATE.getType())) return false; + HardInvoiceEntity updateObj = HardInvoiceEntity.builder().id(historyId).status(HardPrintStatusEnum.PRINT.getType()).build(); + return baseMapper.updateById(updateObj) > 0; + } } \ No newline at end of file diff --git a/pjcloud-hardware/pjcloud-hardware-biz/src/main/java/com/bsd/pjcloud/hard/service/impl/order/HardCarServiceImpl.java b/pjcloud-hardware/pjcloud-hardware-biz/src/main/java/com/bsd/pjcloud/hard/service/impl/order/HardCarServiceImpl.java index 2eb496e8e..01b6532a9 100644 --- a/pjcloud-hardware/pjcloud-hardware-biz/src/main/java/com/bsd/pjcloud/hard/service/impl/order/HardCarServiceImpl.java +++ b/pjcloud-hardware/pjcloud-hardware-biz/src/main/java/com/bsd/pjcloud/hard/service/impl/order/HardCarServiceImpl.java @@ -4,19 +4,20 @@ import cn.hutool.core.util.ObjectUtil; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; +import com.bsd.pjcloud.canteen.api.feign.RemoteCanteenSpuService; +import com.bsd.pjcloud.canteen.entity.CanteenSpuEntity; import com.bsd.pjcloud.common.core.util.BeanUtils; import com.bsd.pjcloud.hard.api.constant.HardTypeEnum; import com.bsd.pjcloud.hard.api.dto.order.HardCarDto; import com.bsd.pjcloud.hard.api.dto.order.HardCreateCarDto; import com.bsd.pjcloud.hard.api.entity.order.HardCarEntity; import com.bsd.pjcloud.hard.api.entity.order.HardParentCarEntity; -import com.bsd.pjcloud.hard.api.entity.order.HardwareOrderEntity; +import com.bsd.pjcloud.hard.api.entity.order.HardOrderEntity; import com.bsd.pjcloud.hard.api.vo.order.HardCarVo; import com.bsd.pjcloud.hard.mapper.order.HardCarMapper; import com.bsd.pjcloud.hard.mapper.order.HardOrderMapper; import com.bsd.pjcloud.hard.mapper.order.HardParentCarMapper; import com.bsd.pjcloud.hard.service.HardCarService; -import com.bsd.pjcloud.hard.service.HardParentCarService; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; import org.springframework.stereotype.Service; @@ -26,6 +27,7 @@ import org.springframework.validation.annotation.Validated; import java.math.BigDecimal; import java.util.ArrayList; import java.util.List; +import java.util.concurrent.atomic.AtomicInteger; /** * 购物车表 @@ -42,6 +44,8 @@ public class HardCarServiceImpl extends ServiceImpl pageJoin(Page page, HardCarDto dto) { return baseMapper.pageJoin(page, dto); @@ -49,7 +53,7 @@ public class HardCarServiceImpl extends ServiceImpl getByOrderId(Long orderId) { - HardwareOrderEntity order = hardCarMapper.selectById(orderId); + HardOrderEntity order = hardCarMapper.selectById(orderId); if (ObjectUtil.isEmpty(order)) return null; List list = baseMapper.selectList(new LambdaQueryWrapper() .eq(HardCarEntity::getParentCarId, order.getParentCarId()) @@ -59,13 +63,19 @@ public class HardCarServiceImpl extends ServiceImpl list) { + List productIds = list.stream().map(HardCreateCarDto::getProductId).toList(); return switch (sysType) { case CANTEEN -> { - int canteenTotalPrice = 0; + // 查询食堂商品 + List supList = (List) canteenSpuService.getSpuListByIds(productIds).getData(); + AtomicInteger canteenTotalPrice = new AtomicInteger(); for (HardCreateCarDto v : list) { - + supList.stream().filter(i -> ObjectUtil.equals(i.getId(), v.getProductId())).findFirst().ifPresent(spu -> { + int itemTotalPrice = v.getProductCount() * spu.getPrice(); + canteenTotalPrice.addAndGet(itemTotalPrice); + }); } - yield canteenTotalPrice; + yield canteenTotalPrice.get(); } case SUPERMARKET -> { int supermarketTotalPrice = 0; @@ -81,21 +91,51 @@ public class HardCarServiceImpl extends ServiceImpl list) { + List productIds = list.stream().map(HardCreateCarDto::getProductId).toList(); + // 创建父订单 HardParentCarEntity parentCarObj = HardParentCarEntity.builder().userId(userId).merchantId(merchantId).orderStatus(sysType.getType()).build(); hardParentCarMapper.insert(parentCarObj); List carObjectList = new ArrayList<>(); - for (HardCreateCarDto v : list) { - HardCarEntity item = HardCarEntity.builder().parentCarId(parentCarObj.getId()).build(); - if (ObjectUtil.equals(sysType, HardTypeEnum.SUPERMARKET)) { - item.setProductCount(1); - item.setProductWeight(v.getProductWeight()); - } - if (ObjectUtil.equals(sysType, HardTypeEnum.CANTEEN)) { - item.setProductCount(v.getProductCount()); - item.setProductWeight(new BigDecimal(0)); + // 食堂 + if (ObjectUtil.equals(sysType, HardTypeEnum.CANTEEN)) { + List supList = (List) canteenSpuService.getSpuListByIds(productIds).getData(); + for (HardCreateCarDto v : list) { + HardCarEntity item = HardCarEntity.builder().parentCarId(parentCarObj.getId()).build(); + supList.stream().filter(i -> ObjectUtil.equals(i.getId(), v.getProductId())).findFirst().ifPresent(spu -> { + int totalPrice = v.getProductCount() * spu.getPrice(); + item.setProductId(spu.getId()); + item.setProductName(spu.getName()); + item.setProductPrice(spu.getPrice()); + item.setProductPic(spu.getPicUrl()); + item.setTotalPrice((long) totalPrice); + item.setProductCount(v.getProductCount()); + item.setProductWeight(new BigDecimal(0)); + }); } + } + // 超市 + if (ObjectUtil.equals(sysType, HardTypeEnum.SUPERMARKET)) { + } baseMapper.insert(carObjectList); return parentCarObj.getId(); } + + @Override + public String computerCarSubject(HardTypeEnum sysType, List list) { + StringBuffer str = new StringBuffer(); + List productIds = list.stream().map(HardCreateCarDto::getProductId).toList(); + if (ObjectUtil.equals(sysType, HardTypeEnum.CANTEEN)) { + List supList = (List) canteenSpuService.getSpuListByIds(productIds).getData(); + for (HardCreateCarDto v : list) { + supList.stream().filter(i -> ObjectUtil.equals(i.getId(), v.getProductId())).findFirst().ifPresent(spu -> { + str.append(spu.getName()).append("x").append(v.getProductCount()).append(";"); + }); + } + } + if (ObjectUtil.equals(sysType, HardTypeEnum.SUPERMARKET)) { + + } + return str.toString(); + } } \ No newline at end of file diff --git a/pjcloud-hardware/pjcloud-hardware-biz/src/main/java/com/bsd/pjcloud/hard/service/impl/order/HardOrderSyncServiceImpl.java b/pjcloud-hardware/pjcloud-hardware-biz/src/main/java/com/bsd/pjcloud/hard/service/impl/order/HardOrderSyncServiceImpl.java new file mode 100644 index 000000000..7ee52d2ea --- /dev/null +++ b/pjcloud-hardware/pjcloud-hardware-biz/src/main/java/com/bsd/pjcloud/hard/service/impl/order/HardOrderSyncServiceImpl.java @@ -0,0 +1,168 @@ +package com.bsd.pjcloud.hard.service.impl.order; + +import cn.hutool.core.util.ObjectUtil; +import cn.hutool.extra.spring.SpringUtil; +import com.alibaba.fastjson.JSON; +import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; +import com.bsd.pjcloud.common.core.constant.enums.YesNoEnum; +import com.bsd.pjcloud.hard.api.constant.order.HardOrderStatusEnum; +import com.bsd.pjcloud.hard.api.dto.async.OfflineCar; +import com.bsd.pjcloud.hard.api.dto.async.OfflineOrder; +import com.bsd.pjcloud.hard.api.dto.async.SyncOfflineReqVo; +import com.bsd.pjcloud.hard.api.entity.order.HardCarEntity; +import com.bsd.pjcloud.hard.api.entity.order.HardOrderEntity; +import com.bsd.pjcloud.hard.api.entity.order.HardParentCarEntity; +import com.bsd.pjcloud.hard.service.HardCarService; +import com.bsd.pjcloud.hard.service.HardOrderSyncService; +import com.bsd.pjcloud.hard.service.HardOrderService; +import com.bsd.pjcloud.hard.service.HardParentCarService; +import com.bsd.pjcloud.wallet.api.feign.RemoteMchService; +import com.bsd.pjcloud.wallet.api.feign.RemoteWalletSettingService; +import com.bsd.pjcloud.wallet.api.vo.MchManageVo; +import com.bsd.pjcloud.wallet.api.vo.WalletSettingVo; +import lombok.RequiredArgsConstructor; +import lombok.extern.slf4j.Slf4j; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; +import org.springframework.validation.annotation.Validated; + +import java.math.BigDecimal; +import java.util.List; + +/** + * 订单同步 + */ +@Service +@Validated +@Slf4j +@RequiredArgsConstructor +public class HardOrderSyncServiceImpl implements HardOrderSyncService { + + static private final String TAG = "订单同步"; + + private final RemoteMchService remoteMchService; + private final RemoteWalletSettingService walletSettingService; + private final HardCarService hardCarService; + private final HardParentCarService hardParentCarService; + private final HardOrderService orderService; + + @Override + @Transactional(rollbackFor = Exception.class) + public List syncOfflineOrder(SyncOfflineReqVo body) { + // 查询商户 + MchManageVo merchant = remoteMchService.getById(body.getMerchantId()).getData(); + if (ObjectUtil.isEmpty(merchant)) return null; + // 是否需要审批 + Boolean offLineOrderApplyEnable = false; + WalletSettingVo setting = walletSettingService.get().getData(); + if (ObjectUtil.isNotEmpty(setting) && ObjectUtil.isNotEmpty(setting.getOffLineOrderApplyEnable())) { + offLineOrderApplyEnable = ObjectUtil.equals(setting.getOffLineOrderApplyEnable(), YesNoEnum.YES.getCode()); + } + List createIdList = List.of(); + List list = body.getList(); + for (OfflineOrder i : list) { + if (ObjectUtil.isEmpty(i.getCarList())) { + log.error("|{}|同步安卓机离线订单,错误购物车列表为空order:{}", TAG, JSON.toJSONString(i)); + continue; + } + // 是否重复 + HardOrderEntity findOrder = orderService.getOne(new LambdaQueryWrapper().eq(HardOrderEntity::getAndroidOrderCode, i.getUniqueCode())); + if (ObjectUtil.isNotEmpty(findOrder)) { + log.error("|{}|同步安卓机离线订单,重复同步order:{}", TAG, JSON.toJSONString(i)); + createIdList.add(findOrder.getAndroidOrderCode()); + continue; + } + HardOrderEntity order = parseOrder(i, body.getHardwareId(), body.getMerchantId(), merchant.getDeptId()); + HardParentCarEntity parentCar = parseParentCar(i, body.getMerchantId()); + List carList = i.getCarList().stream().map(this::parseCar).toList(); + if (!ObjectUtil.isAllNotEmpty(order, parentCar, carList)) { + log.error("|{}|同步安卓机离线订单,order、parentCar、carList任意一个为空order:{}", TAG, JSON.toJSONString(i)); + continue; + } + Boolean isCreate = getSelf().createOfflineOrder(order, parentCar, carList, i, offLineOrderApplyEnable); + if (isCreate) createIdList.add(order.getAndroidOrderCode()); + } + return createIdList; + } + + // 同步安卓机单个离线订单 TODO 允许把金额扣为负数 + @Transactional(rollbackFor = Exception.class) + public Boolean createOfflineOrder(HardOrderEntity order, HardParentCarEntity parentCar, List list, OfflineOrder offlineOrder, boolean offLineOrderApplyEnable) { + try { + // 创建父订单 + hardParentCarService.save(parentCar); + // 创建购物车 + list.forEach(v -> v.setParentCarId(parentCar.getId())); + hardCarService.saveBatch(list); + // 创建订单 + order.setParentCarId(parentCar.getId()); + orderService.save(order); + // 支付 + if (!offLineOrderApplyEnable) { + orderService.fastReduceBalance(order); + } + // 标记离线支付成功 + if (!offLineOrderApplyEnable && ObjectUtil.isNotEmpty(order.getId())) { + HardOrderEntity updateObj = HardOrderEntity.builder().id(order.getId()).offlinePaySuccess(YesNoEnum.YES.getCode()).build(); + orderService.updateById(updateObj); + } + return true; + } catch (Exception e) { + if (!offLineOrderApplyEnable) { + HardOrderEntity updateObj = HardOrderEntity.builder().id(order.getId()).offlinePaySuccess(YesNoEnum.NO.getCode()).build(); + orderService.updateById(updateObj); + } + e.printStackTrace(); + log.error("|{}|同步安卓机单个离线订单,意外的错误order:|{}|error|{}|", TAG, JSON.toJSONString(order), e.getMessage()); + } + return false; + } + + + public HardOrderEntity parseOrder(OfflineOrder order, Long hardwareId, Long merchantId, Long merchantDeptId) { + HardOrderEntity res = new HardOrderEntity(); + res.setAndroidOrderCode(order.getUniqueCode()); + res.setUserId(order.getUserCode()); + res.setHardId(hardwareId); + res.setMerchantId(merchantId); + res.setDeptId(merchantDeptId); + res.setSysType(order.getSysType().getType()); + res.setWalletId(order.getWalletId()); + res.setOrderType(order.getType().getType()); + res.setOrderSourceTypeId(order.getOrderSourceTypeId()); + res.setOrderStatus(HardOrderStatusEnum.OFFLINE_CREATE.getType()); + res.setPayType(order.getPayType().getType()); + res.setTotalPrice(order.getPrice()); + res.setPayPrice(order.getPayPrice()); + res.setExtraPrice(order.getExtraPrice()); + res.setIsOfflineOrder(YesNoEnum.YES.getCode()); + res.setProductDesc(order.getProductDesc()); + res.setHourType(order.getHourType()); + return res; + } + + public HardParentCarEntity parseParentCar(OfflineOrder order, Long merchantId) { + HardParentCarEntity res = new HardParentCarEntity(); + res.setUserId(order.getUserCode()); + res.setMerchantId(merchantId); + res.setOrderStatus(HardOrderStatusEnum.OFFLINE_CREATE.getType()); + return res; + } + + public HardCarEntity parseCar(OfflineCar order) { + HardCarEntity res = new HardCarEntity(); + res.setParentCarId(null); + res.setProductName(order.getProductName()); + res.setProductPic(order.getProductPic()); + res.setProductPrice(BigDecimal.valueOf(order.getProductPrice()).intValue()); + res.setProductId(order.getProductServiceUniqueCode()); + res.setProductCount(order.getProductNumber()); + res.setProductWeight(order.getProductWidget()); + res.setTotalPrice(order.getTotalPrice()); + return res; + } + + private HardOrderSyncServiceImpl getSelf() { + return SpringUtil.getBean(getClass()); + } +} diff --git a/pjcloud-hardware/pjcloud-hardware-biz/src/main/java/com/bsd/pjcloud/hard/service/impl/order/HardwareOrderServiceImpl.java b/pjcloud-hardware/pjcloud-hardware-biz/src/main/java/com/bsd/pjcloud/hard/service/impl/order/HardwareOrderServiceImpl.java index 4c7e568d5..d0bb17a1d 100644 --- a/pjcloud-hardware/pjcloud-hardware-biz/src/main/java/com/bsd/pjcloud/hard/service/impl/order/HardwareOrderServiceImpl.java +++ b/pjcloud-hardware/pjcloud-hardware-biz/src/main/java/com/bsd/pjcloud/hard/service/impl/order/HardwareOrderServiceImpl.java @@ -3,31 +3,39 @@ package com.bsd.pjcloud.hard.service.impl.order; import cn.hutool.core.util.ObjectUtil; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; +import com.bsd.pjcloud.common.core.constant.enums.YesNoEnum; import com.bsd.pjcloud.common.core.util.R; import com.bsd.pjcloud.hard.api.constant.HardTypeEnum; +import com.bsd.pjcloud.hard.api.constant.order.HardOrderStatusEnum; import com.bsd.pjcloud.hard.api.constant.order.HardOrderTypeEnum; import com.bsd.pjcloud.hard.api.constant.order.HardPayTypeEnum; +import com.bsd.pjcloud.hard.api.dto.hard.HandCancelCodeDto; import com.bsd.pjcloud.hard.api.dto.hard.HardCreateOrderDto; import com.bsd.pjcloud.hard.api.dto.order.HardOrderDto; import com.bsd.pjcloud.hard.api.entity.HardManagerEntity; -import com.bsd.pjcloud.hard.api.entity.order.HardwareOrderEntity; +import com.bsd.pjcloud.hard.api.entity.order.HardOrderEntity; import com.bsd.pjcloud.hard.api.vo.order.HardOrderVo; import com.bsd.pjcloud.hard.mapper.order.HardOrderMapper; import com.bsd.pjcloud.hard.service.HardCarService; import com.bsd.pjcloud.hard.service.HardManagerService; -import com.bsd.pjcloud.hard.service.HardwareOrderService; +import com.bsd.pjcloud.hard.service.HardOrderService; +import com.bsd.pjcloud.wallet.api.constant.WalletBizEnum; import com.bsd.pjcloud.wallet.api.constant.WalletTypeCodeEnum; +import com.bsd.pjcloud.wallet.api.dto.WalletBalanceTransactionDto; import com.bsd.pjcloud.wallet.api.entity.WalletManageEntity; -import com.bsd.pjcloud.wallet.api.feign.RemoteCodeUseService; -import com.bsd.pjcloud.wallet.api.feign.RemoteMchService; -import com.bsd.pjcloud.wallet.api.feign.RemoteWalletService; +import com.bsd.pjcloud.wallet.api.entity.WalletTransactionEntity; +import com.bsd.pjcloud.wallet.api.feign.*; import com.bsd.pjcloud.wallet.api.vo.MchManageVo; +import com.bsd.pjcloud.wallet.api.vo.WalletSettingVo; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; import org.springframework.validation.annotation.Validated; +import java.math.BigDecimal; +import java.math.RoundingMode; +import java.time.LocalDateTime; import java.util.Optional; /** @@ -40,7 +48,9 @@ import java.util.Optional; @Slf4j @RequiredArgsConstructor @Service -public class HardwareOrderServiceImpl extends ServiceImpl implements HardwareOrderService { +public class HardwareOrderServiceImpl extends ServiceImpl implements HardOrderService { + + static private final String TAG = "订单"; private final HardManagerService hardManagerService; private final HardCarService hardCarService; @@ -48,6 +58,8 @@ public class HardwareOrderServiceImpl extends ServiceImpl pageJoin(Page page, HardOrderDto dto) { @@ -85,23 +97,101 @@ public class HardwareOrderServiceImpl extends ServiceImpl setting.getPayAmountMealLimit()) { + extraPrice = setting.getPayAmountMealTimes().multiply(BigDecimal.valueOf(price).subtract(BigDecimal.valueOf(setting.getPayAmountMealLimit()))).setScale(2, RoundingMode.HALF_UP).intValue(); + log.info("|{}|增加的每一餐的金额 result:|{}|", TAG, extraPrice); + } + return extraPrice; } - // 是否需要支付(目前只有线下的现金是不走平台扣款) - private boolean isPay(HardOrderTypeEnum type, HardPayTypeEnum payType) { - return ObjectUtil.equals(type, HardOrderTypeEnum.BELOW) && !ObjectUtil.equals(payType, HardPayTypeEnum.CASH); + @Override + public Boolean handCancelCode(HandCancelCodeDto dto) { + // 查询订单 + HardOrderEntity order = baseMapper.selectById(dto.getOrderId()); + if (ObjectUtil.isEmpty(order)) throw new RuntimeException("订单不存在"); + // 判断是否被核销过 + HardOrderTypeEnum orderType = HardOrderTypeEnum.valueOfByType(order.getOrderType()); + boolean isCancel = validateCodeIsCancel(orderType, order.getId()); + if (isCancel) throw new RuntimeException("该二维码已被核销"); + // 核销二维码 + cancelCode(order); + HardOrderEntity updateObj = HardOrderEntity.builder().id(order.getId()).androidOrderCode(dto.getAndroidOrderCode()).hardId(dto.getHardwareId()).orderStatus(HardOrderStatusEnum.CANCEL.getType()).build(); + return baseMapper.updateById(updateObj) > 0; } - // 是否需要额外支付(目前只有食堂需要) - private boolean isExtraPrice(HardTypeEnum hardType) { - return ObjectUtil.equals(hardType, HardTypeEnum.CANTEEN); + @Override + public void cancelCode(HardOrderEntity order) { + HardOrderTypeEnum orderTypeEnum = HardOrderTypeEnum.valueOfByType(order.getOrderType()); + if (!ObjectUtil.isAllNotEmpty(orderTypeEnum, order.getOrderSourceTypeId())) return; + Long id = order.getOrderSourceTypeId(); + switch (orderTypeEnum) { + // 线下购买 + case BELOW -> { + + } + // 线上订餐 + case RESERVE -> { + + } + // 外来人员 | 跨单位 + case FOREIGN_TICKET, STRIDE_DEPT -> remoteCodeUseService.cancelCode(id); + } } // 二维码类型的订单是否被核销 @@ -119,6 +209,16 @@ public class HardwareOrderServiceImpl extends ServiceImpl mch = remoteMchService.getById(dto.getMerchantId()); if (ObjectUtil.isEmpty(mch.getData())) { diff --git a/pjcloud-hardware/pjcloud-hardware-biz/src/main/resources/mapper/order/HardOrderMapper.xml b/pjcloud-hardware/pjcloud-hardware-biz/src/main/resources/mapper/order/HardOrderMapper.xml index 2fe510cf0..32e1eaef3 100644 --- a/pjcloud-hardware/pjcloud-hardware-biz/src/main/resources/mapper/order/HardOrderMapper.xml +++ b/pjcloud-hardware/pjcloud-hardware-biz/src/main/resources/mapper/order/HardOrderMapper.xml @@ -3,7 +3,7 @@ - + diff --git a/pjcloud-upms/pjcloud-upms-api/src/main/java/com/bsd/pjcloud/admin/api/feign/RemoteDeptService.java b/pjcloud-upms/pjcloud-upms-api/src/main/java/com/bsd/pjcloud/admin/api/feign/RemoteDeptService.java index 9c3936933..c6435c363 100644 --- a/pjcloud-upms/pjcloud-upms-api/src/main/java/com/bsd/pjcloud/admin/api/feign/RemoteDeptService.java +++ b/pjcloud-upms/pjcloud-upms-api/src/main/java/com/bsd/pjcloud/admin/api/feign/RemoteDeptService.java @@ -37,27 +37,39 @@ import java.util.Map; @FeignClient(contextId = "remoteDeptService", value = ServiceNameConstants.UPMS_SERVICE) public interface RemoteDeptService { - /** - * 获取所有部门接口 - * @param parentDeptId 父部门ID - * @return R 返回结果对象,包含所有部门信息列表 - */ - @GetMapping("/dept/list") - R> getAllDept(@RequestParam("parentDeptId") Long parentDeptId); + /** + * 获取所有部门接口 + * + * @param parentDeptId 父部门ID + * @return R 返回结果对象,包含所有部门信息列表 + */ + @GetMapping("/dept/list") + R> getAllDept(@RequestParam("parentDeptId") Long parentDeptId); - /** - * 通过部门ID获取负责人列表 - * @param deptId 部门ID - * @return 负责人ID列表 - */ - @GetMapping("/dept/leader/{deptId}") - R> getAllDeptLeader(@PathVariable("deptId") Long deptId); + /** + * 通过部门ID获取负责人列表 + * + * @param deptId 部门ID + * @return 负责人ID列表 + */ + @GetMapping("/dept/leader/{deptId}") + R> getAllDeptLeader(@PathVariable("deptId") Long deptId); - /** - * 根据部门id集合查询 - * @param deptIds - * @return - */ - @GetMapping("/dept/getDeptListByDeptIds") - R> getDeptByDeptIds(@RequestParam("deptIds")List deptIds); + /** + * 根据部门id集合查询 + * + * @param deptIds + * @return + */ + @GetMapping("/dept/getDeptListByDeptIds") + R> getDeptByDeptIds(@RequestParam("deptIds") List deptIds); + + /** + * 根据部门id查询 + * + * @param deptId + * @return + */ + @GetMapping("/dept/getDeptListByDeptId") + R getDeptByDeptId(@RequestParam("deptId") Long deptId); } diff --git a/pjcloud-upms/pjcloud-upms-biz/src/main/java/com/bsd/pjcloud/admin/controller/SysDeptController.java b/pjcloud-upms/pjcloud-upms-biz/src/main/java/com/bsd/pjcloud/admin/controller/SysDeptController.java index d866aface..935daddd8 100644 --- a/pjcloud-upms/pjcloud-upms-biz/src/main/java/com/bsd/pjcloud/admin/controller/SysDeptController.java +++ b/pjcloud-upms/pjcloud-upms-biz/src/main/java/com/bsd/pjcloud/admin/controller/SysDeptController.java @@ -54,132 +54,146 @@ import java.util.Map; @SecurityRequirement(name = HttpHeaders.AUTHORIZATION) public class SysDeptController { - private final SysDeptService sysDeptService; + private final SysDeptService sysDeptService; - /** - * 通过ID查询 - * @param id ID - * @return SysDept - */ - @GetMapping("/{id}") - public R getById(@PathVariable Long id) { - return R.ok(sysDeptService.getById(id)); - } + /** + * 通过ID查询 + * + * @param id ID + * @return SysDept + */ + @GetMapping("/{id}") + public R getById(@PathVariable Long id) { + return R.ok(sysDeptService.getById(id)); + } - /** - * 查询全部部门 - */ - @GetMapping("/list") - public R list() { - return R.ok(sysDeptService.list()); - } + /** + * 查询全部部门 + */ + @GetMapping("/list") + public R list() { + return R.ok(sysDeptService.list()); + } - /** - * 返回树形菜单集合 - * @param deptName 部门名称 - * @return 树形菜单 - */ - @GetMapping(value = "/tree") - public R getTree(String deptName, Long parentId) { - return R.ok(sysDeptService.selectTree(deptName, parentId)); - } + /** + * 返回树形菜单集合 + * + * @param deptName 部门名称 + * @return 树形菜单 + */ + @GetMapping(value = "/tree") + public R getTree(String deptName, Long parentId) { + return R.ok(sysDeptService.selectTree(deptName, parentId)); + } - /** - * 添加 - * @param sysDept 实体 - * @return success/false - */ - @SysLog("添加部门") - @PostMapping - @HasPermission("sys_dept_add") - public R save(@Valid @RequestBody SysDept sysDept) { - return R.ok(sysDeptService.save(sysDept)); - } + /** + * 添加 + * + * @param sysDept 实体 + * @return success/false + */ + @SysLog("添加部门") + @PostMapping + @HasPermission("sys_dept_add") + public R save(@Valid @RequestBody SysDept sysDept) { + return R.ok(sysDeptService.save(sysDept)); + } - /** - * 删除 - * @param id ID - * @return success/false - */ - @SysLog("删除部门") - @DeleteMapping("/{id}") - @HasPermission("sys_dept_del") - public R removeById(@PathVariable Long id) { - return R.ok(sysDeptService.removeDeptById(id)); - } + /** + * 删除 + * + * @param id ID + * @return success/false + */ + @SysLog("删除部门") + @DeleteMapping("/{id}") + @HasPermission("sys_dept_del") + public R removeById(@PathVariable Long id) { + return R.ok(sysDeptService.removeDeptById(id)); + } - /** - * 编辑 - * @param sysDept 实体 - * @return success/false - */ - @SysLog("编辑部门") - @PutMapping - @HasPermission("sys_dept_edit") - public R update(@Valid @RequestBody SysDept sysDept) { - sysDept.setUpdateTime(LocalDateTime.now()); - return R.ok(sysDeptService.updateById(sysDept)); - } + /** + * 编辑 + * + * @param sysDept 实体 + * @return success/false + */ + @SysLog("编辑部门") + @PutMapping + @HasPermission("sys_dept_edit") + public R update(@Valid @RequestBody SysDept sysDept) { + sysDept.setUpdateTime(LocalDateTime.now()); + return R.ok(sysDeptService.updateById(sysDept)); + } - /** - * 查收子级列表 - * @return 返回子级 - */ - @GetMapping(value = "/getDescendantList/{deptId}") - public R getDescendantList(@PathVariable Long deptId) { - return R.ok(sysDeptService.listDescendant(deptId)); - } + /** + * 查收子级列表 + * + * @return 返回子级 + */ + @GetMapping(value = "/getDescendantList/{deptId}") + public R getDescendantList(@PathVariable Long deptId) { + return R.ok(sysDeptService.listDescendant(deptId)); + } - @GetMapping(value = "/leader/{deptId}") - public R getAllDeptLeader(@PathVariable Long deptId) { - return R.ok(sysDeptService.listDeptLeader(deptId)); - } + @GetMapping(value = "/leader/{deptId}") + public R getAllDeptLeader(@PathVariable Long deptId) { + return R.ok(sysDeptService.listDeptLeader(deptId)); + } - /** - * 导出部门 - * @return - */ - @ResponseExcel - @GetMapping("/export") - public List export() { - return sysDeptService.listExcelVo(); - } + /** + * 导出部门 + * + * @return + */ + @ResponseExcel + @GetMapping("/export") + public List export() { + return sysDeptService.listExcelVo(); + } - /** - * 导入部门 - * @param excelVOList - * @param bindingResult - * @return - */ - @PostMapping("import") - public R importDept(@RequestExcel List excelVOList, BindingResult bindingResult) { - return sysDeptService.importDept(excelVOList, bindingResult); - } + /** + * 导入部门 + * + * @param excelVOList + * @param bindingResult + * @return + */ + @PostMapping("import") + public R importDept(@RequestExcel List excelVOList, BindingResult bindingResult) { + return sysDeptService.importDept(excelVOList, bindingResult); + } - /** - * 查询全部部门包含用户 - * @param parentDeptId 父部门ID - * @param type 查询类型 - */ - @GetMapping("/org") - public R listOrgTree(Long parentDeptId, String type) { - return R.ok(sysDeptService.listOrgTree(parentDeptId, type)); - } + /** + * 查询全部部门包含用户 + * + * @param parentDeptId 父部门ID + * @param type 查询类型 + */ + @GetMapping("/org") + public R listOrgTree(Long parentDeptId, String type) { + return R.ok(sysDeptService.listOrgTree(parentDeptId, type)); + } - /** - * 模糊搜索用户 - * @param username 用户名/拼音/首字母 - * @return 匹配到的用户 - */ - @GetMapping("/org/user/search") - public R getOrgTreeUser(@RequestParam String username) { - return R.ok(sysDeptService.getOrgTreeUser(username)); - } + /** + * 模糊搜索用户 + * + * @param username 用户名/拼音/首字母 + * @return 匹配到的用户 + */ + @GetMapping("/org/user/search") + public R getOrgTreeUser(@RequestParam String username) { + return R.ok(sysDeptService.getOrgTreeUser(username)); + } - @GetMapping("/getDeptListByDeptIds") - public R> getDeptListByDeptIds(@RequestParam("deptIds") List deptIds) { + @GetMapping("/getDeptListByDeptIds") + public R> getDeptListByDeptIds(@RequestParam("deptIds") List deptIds) { + return R.ok(sysDeptService.getDeptListByDeptIds(deptIds)); + } - return R.ok(sysDeptService.getDeptListByDeptIds(deptIds)); - } + @GetMapping("/getDeptListByDeptId") + public R getDeptByDeptId(@RequestParam("deptId") Long deptId) { + return R.ok(sysDeptService.getById(deptId)); + } } diff --git a/pjcloud-wallet/pjcloud-wallet-api/src/main/java/com/bsd/pjcloud/wallet/api/constant/WalletBizEnum.java b/pjcloud-wallet/pjcloud-wallet-api/src/main/java/com/bsd/pjcloud/wallet/api/constant/WalletBizEnum.java index 4634dde84..8f36c9a05 100644 --- a/pjcloud-wallet/pjcloud-wallet-api/src/main/java/com/bsd/pjcloud/wallet/api/constant/WalletBizEnum.java +++ b/pjcloud-wallet/pjcloud-wallet-api/src/main/java/com/bsd/pjcloud/wallet/api/constant/WalletBizEnum.java @@ -12,6 +12,7 @@ public enum WalletBizEnum { UPDATE("1", "更新余额"), BATCH("2", "批量更新余额"), RECHARGE("3", "充值"), + PAYMENT("4", "支付"), ; private final String code; diff --git a/pjcloud-wallet/pjcloud-wallet-api/src/main/java/com/bsd/pjcloud/wallet/api/dto/WalletBalanceTransactionDto.java b/pjcloud-wallet/pjcloud-wallet-api/src/main/java/com/bsd/pjcloud/wallet/api/dto/WalletBalanceTransactionDto.java new file mode 100644 index 000000000..ed20d5271 --- /dev/null +++ b/pjcloud-wallet/pjcloud-wallet-api/src/main/java/com/bsd/pjcloud/wallet/api/dto/WalletBalanceTransactionDto.java @@ -0,0 +1,28 @@ +package com.bsd.pjcloud.wallet.api.dto; + +import com.bsd.pjcloud.wallet.api.constant.WalletBizEnum; +import jakarta.validation.constraints.NotEmpty; +import jakarta.validation.constraints.NotNull; +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Data; + +@Builder +@AllArgsConstructor +@NotEmpty +@Data +public class WalletBalanceTransactionDto { + + @NotNull(message = "钱包id不能为空") + private Long walletId; + + @NotNull(message = "操作金额不能为空") + private Integer price; + + @NotEmpty(message = "业务类型关联id不能为空") + private String bizId; + + @NotNull(message = "业务类型不能为空") + private WalletBizEnum bizType; + +} diff --git a/pjcloud-wallet/pjcloud-wallet-api/src/main/java/com/bsd/pjcloud/wallet/api/entity/WalletSettingEntity.java b/pjcloud-wallet/pjcloud-wallet-api/src/main/java/com/bsd/pjcloud/wallet/api/entity/WalletSettingEntity.java index b8f24aab5..202db7a12 100644 --- a/pjcloud-wallet/pjcloud-wallet-api/src/main/java/com/bsd/pjcloud/wallet/api/entity/WalletSettingEntity.java +++ b/pjcloud-wallet/pjcloud-wallet-api/src/main/java/com/bsd/pjcloud/wallet/api/entity/WalletSettingEntity.java @@ -24,10 +24,10 @@ public class WalletSettingEntity extends Model { /** - * 创建者 + * 编号 */ @TableId(type = IdType.ASSIGN_ID) - @Schema(description="创建者") + @Schema(description="编号") private Long id; /** diff --git a/pjcloud-wallet/pjcloud-wallet-api/src/main/java/com/bsd/pjcloud/wallet/api/feign/RemoteWalletTransactionService.java b/pjcloud-wallet/pjcloud-wallet-api/src/main/java/com/bsd/pjcloud/wallet/api/feign/RemoteWalletTransactionService.java new file mode 100644 index 000000000..0c508bc0f --- /dev/null +++ b/pjcloud-wallet/pjcloud-wallet-api/src/main/java/com/bsd/pjcloud/wallet/api/feign/RemoteWalletTransactionService.java @@ -0,0 +1,24 @@ +package com.bsd.pjcloud.wallet.api.feign; + +import com.bsd.pjcloud.common.core.constant.ServiceNameConstants; +import com.bsd.pjcloud.common.core.util.R; +import com.bsd.pjcloud.common.feign.annotation.NoToken; +import com.bsd.pjcloud.wallet.api.dto.WalletBalanceTransactionDto; +import com.bsd.pjcloud.wallet.api.entity.WalletTransactionEntity; +import com.bsd.pjcloud.wallet.api.vo.WalletSettingVo; +import org.springframework.cloud.openfeign.FeignClient; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RequestBody; + +@FeignClient(contextId = "remoteWalletTransactionService", value = ServiceNameConstants.WALLET_SERVICE) +public interface RemoteWalletTransactionService { + + @NoToken + @GetMapping("/wallet-transaction/add-balance") + R addWalletBalance(@RequestBody WalletBalanceTransactionDto dto); + + @NoToken + @GetMapping("/wallet-transaction/reduce-balance") + R reduceWalletBalance(@RequestBody WalletBalanceTransactionDto dto); + +} diff --git a/pjcloud-wallet/pjcloud-wallet-api/src/main/resources/META-INF/spring/org.springframework.cloud.openfeign.FeignClient.imports b/pjcloud-wallet/pjcloud-wallet-api/src/main/resources/META-INF/spring/org.springframework.cloud.openfeign.FeignClient.imports index 21af16532..d586cd832 100644 --- a/pjcloud-wallet/pjcloud-wallet-api/src/main/resources/META-INF/spring/org.springframework.cloud.openfeign.FeignClient.imports +++ b/pjcloud-wallet/pjcloud-wallet-api/src/main/resources/META-INF/spring/org.springframework.cloud.openfeign.FeignClient.imports @@ -1,4 +1,5 @@ com.bsd.pjcloud.wallet.api.feign.RemoteWalletService com.bsd.pjcloud.wallet.api.feign.RemoteCodeUseService com.bsd.pjcloud.wallet.api.feign.RemoteMchService -com.bsd.pjcloud.wallet.api.feign.RemoteWalletSettingService \ No newline at end of file +com.bsd.pjcloud.wallet.api.feign.RemoteWalletSettingService +com.bsd.pjcloud.wallet.api.feign.RemoteWalletTransactionService \ No newline at end of file diff --git a/pjcloud-wallet/pjcloud-wallet-biz/src/main/java/com/bsd/pjcloud/wallet/controller/MchManageController.java b/pjcloud-wallet/pjcloud-wallet-biz/src/main/java/com/bsd/pjcloud/wallet/controller/MchManageController.java index 8a148eafc..a8b000725 100644 --- a/pjcloud-wallet/pjcloud-wallet-biz/src/main/java/com/bsd/pjcloud/wallet/controller/MchManageController.java +++ b/pjcloud-wallet/pjcloud-wallet-biz/src/main/java/com/bsd/pjcloud/wallet/controller/MchManageController.java @@ -46,9 +46,9 @@ public class MchManageController { @Inner @GetMapping("/get-by-id") public R getById(@RequestParam Long id) { - MchManageEntity mchManage = mchManageService.getById(id); - if (ObjectUtil.isEmpty(mchManage)) return R.failed("商户不存在"); - return R.ok(BeanUtils.toBean(mchManage, MchManageVo.class)); + MchManageVo mchManageVo = mchManageService.join(id); + if (ObjectUtil.isEmpty(mchManageVo)) return R.failed("商户不存在"); + return R.ok(mchManageVo); } @Inner diff --git a/pjcloud-wallet/pjcloud-wallet-biz/src/main/java/com/bsd/pjcloud/wallet/controller/WalletManageController.java b/pjcloud-wallet/pjcloud-wallet-biz/src/main/java/com/bsd/pjcloud/wallet/controller/WalletManageController.java index 1e08d9061..b691e3ddd 100644 --- a/pjcloud-wallet/pjcloud-wallet-biz/src/main/java/com/bsd/pjcloud/wallet/controller/WalletManageController.java +++ b/pjcloud-wallet/pjcloud-wallet-biz/src/main/java/com/bsd/pjcloud/wallet/controller/WalletManageController.java @@ -45,7 +45,6 @@ public class WalletManageController { private final WalletManageService walletManageService; /* ************************************* start 远程调用 start ************************************* */ - @Inner @GetMapping("/get-or-create-wallet") public R getOrCreateWallet(@RequestParam Long userId, @RequestParam WalletTypeCodeEnum walletTypeCode) { @@ -79,15 +78,13 @@ public class WalletManageController { return R.ok(walletManageService.delWalletByUserIds(userIds)); } + @Inner + @GetMapping("/add-price") + public R addPrice(@RequestParam("userIds") List userIds){ + return R.ok(walletManageService.delWalletByUserIds(userIds)); + } /* ************************************* start 远程调用 start ************************************* */ - /** - * 分页查询 - * - * @param page 分页对象 - * @param walletManage 钱包管理 - * @return - */ @Operation(summary = "分页查询", description = "分页查询") @GetMapping("/page") @PreAuthorize("@pms.hasPermission('wallet_walletManage_view')") @@ -103,13 +100,6 @@ public class WalletManageController { return walletManageService.pageJoin(page, dto); } - - /** - * 通过id查询钱包管理 - * - * @param id id - * @return R - */ @Operation(summary = "通过id查询", description = "通过id查询") @GetMapping("/{id}") @PreAuthorize("@pms.hasPermission('wallet_walletManage_view')") @@ -117,12 +107,6 @@ public class WalletManageController { return R.ok(walletManageService.getWallet(id)); } - /** - * 新增钱包管理 - * - * @param walletManage 钱包管理 - * @return R - */ @Operation(summary = "新增钱包管理", description = "新增钱包管理") @SysLog("新增钱包管理") @PostMapping @@ -131,12 +115,6 @@ public class WalletManageController { return R.ok(walletManageService.save(walletManage)); } - /** - * 修改钱包管理 - * - * @param walletManage 钱包管理 - * @return R - */ @Operation(summary = "修改钱包管理", description = "修改钱包管理") @SysLog("修改钱包管理") @PutMapping @@ -145,12 +123,6 @@ public class WalletManageController { return R.ok(walletManageService.updateById(walletManage)); } - /** - * 通过id删除钱包管理 - * - * @param ids id列表 - * @return R - */ @Operation(summary = "通过id删除钱包管理", description = "通过id删除钱包管理") @SysLog("通过id删除钱包管理") @DeleteMapping @@ -159,14 +131,6 @@ public class WalletManageController { return R.ok(walletManageService.removeBatchByIds(CollUtil.toList(ids))); } - - /** - * 导出excel 表格 - * - * @param walletManage 查询条件 - * @param ids 导出指定ID - * @return excel 文件流 - */ @ResponseExcel @GetMapping("/export") @PreAuthorize("@pms.hasPermission('wallet_walletManage_export')") diff --git a/pjcloud-wallet/pjcloud-wallet-biz/src/main/java/com/bsd/pjcloud/wallet/controller/WalletTransactionController.java b/pjcloud-wallet/pjcloud-wallet-biz/src/main/java/com/bsd/pjcloud/wallet/controller/WalletTransactionController.java index f8bbc6614..6f51733a6 100644 --- a/pjcloud-wallet/pjcloud-wallet-biz/src/main/java/com/bsd/pjcloud/wallet/controller/WalletTransactionController.java +++ b/pjcloud-wallet/pjcloud-wallet-biz/src/main/java/com/bsd/pjcloud/wallet/controller/WalletTransactionController.java @@ -8,11 +8,15 @@ import com.baomidou.mybatisplus.core.toolkit.Wrappers; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.bsd.pjcloud.common.core.util.R; import com.bsd.pjcloud.common.log.annotation.SysLog; +import com.bsd.pjcloud.common.security.annotation.Inner; +import com.bsd.pjcloud.wallet.api.constant.WalletTypeCodeEnum; +import com.bsd.pjcloud.wallet.api.dto.WalletBalanceTransactionDto; import com.bsd.pjcloud.wallet.api.dto.WalletTransactionDto; import com.bsd.pjcloud.wallet.api.entity.WalletManageEntity; import com.bsd.pjcloud.wallet.api.entity.WalletTransactionEntity; import com.bsd.pjcloud.wallet.service.WalletManageService; import com.bsd.pjcloud.wallet.service.WalletTransactionService; +import jakarta.validation.Valid; import org.springframework.security.access.prepost.PreAuthorize; import com.bsd.pjcloud.common.excel.annotation.ResponseExcel; import io.swagger.v3.oas.annotations.security.SecurityRequirement; @@ -33,26 +37,37 @@ import java.util.List; */ @RestController @RequiredArgsConstructor -@RequestMapping("/walletTransaction") -@Tag(description = "walletTransaction", name = "会员钱包流水表管理") +@RequestMapping("/wallet-transaction") +@Tag(description = "wallet-transaction", name = "会员钱包流水表管理") @SecurityRequirement(name = HttpHeaders.AUTHORIZATION) public class WalletTransactionController { private final WalletTransactionService walletTransactionService; + /* ************************************* start 远程调用 start ************************************* */ + @Inner + @PostMapping("/add-balance") + public R addWalletBalance(@Valid @RequestBody WalletBalanceTransactionDto dto) { + WalletTransactionEntity walletTransaction = walletTransactionService.addWalletBalance(dto.getWalletId(), dto.getPrice(), dto.getBizId(), dto.getBizType()); + if (ObjectUtil.isEmpty(walletTransaction)) return R.failed("增加钱包余额错误"); + return R.ok(walletTransaction); + } + + @Inner + @PostMapping("/reduce-balance") + public R reduceWalletBalance(@Valid @RequestBody WalletBalanceTransactionDto dto) { + WalletTransactionEntity walletTransaction = walletTransactionService.reduceWalletBalance(dto.getWalletId(), dto.getPrice(), dto.getBizId(), dto.getBizType()); + if (ObjectUtil.isEmpty(walletTransaction)) return R.failed("扣减钱包余额"); + return R.ok(walletTransaction); + } + /* ************************************* end 远程调用 end ************************************* */ + @PutMapping("/update-balance") @Operation(summary = "更新会员用户余额") public R updateWalletBalance(@RequestBody WalletTransactionDto dto) { return R.ok(walletTransactionService.updateWalletBalance(dto)); } - /** - * 分页查询 - * - * @param page 分页对象 - * @param dto 会员钱包流水表 - * @return - */ @Operation(summary = "分页查询", description = "分页查询") @GetMapping("/page") @PreAuthorize("@pms.hasPermission('wallet_walletTransaction_view')") @@ -68,13 +83,6 @@ public class WalletTransactionController { return R.ok(walletTransactionService.pageJoin(page, dto)); } - - /** - * 通过id查询会员钱包流水表 - * - * @param id id - * @return R - */ @Operation(summary = "通过id查询", description = "通过id查询") @GetMapping("/{id}") @PreAuthorize("@pms.hasPermission('wallet_walletTransaction_view')") @@ -82,12 +90,6 @@ public class WalletTransactionController { return R.ok(walletTransactionService.getById(id)); } - /** - * 新增会员钱包流水表 - * - * @param walletTransaction 会员钱包流水表 - * @return R - */ @Operation(summary = "新增会员钱包流水表", description = "新增会员钱包流水表") @SysLog("新增会员钱包流水表") @PostMapping @@ -96,12 +98,6 @@ public class WalletTransactionController { return R.ok(walletTransactionService.save(walletTransaction)); } - /** - * 修改会员钱包流水表 - * - * @param walletTransaction 会员钱包流水表 - * @return R - */ @Operation(summary = "修改会员钱包流水表", description = "修改会员钱包流水表") @SysLog("修改会员钱包流水表") @PutMapping @@ -110,12 +106,6 @@ public class WalletTransactionController { return R.ok(walletTransactionService.updateById(walletTransaction)); } - /** - * 通过id删除会员钱包流水表 - * - * @param ids id列表 - * @return R - */ @Operation(summary = "通过id删除会员钱包流水表", description = "通过id删除会员钱包流水表") @SysLog("通过id删除会员钱包流水表") @DeleteMapping @@ -124,14 +114,6 @@ public class WalletTransactionController { return R.ok(walletTransactionService.removeBatchByIds(CollUtil.toList(ids))); } - - /** - * 导出excel 表格 - * - * @param walletTransaction 查询条件 - * @param ids 导出指定ID - * @return excel 文件流 - */ @ResponseExcel @GetMapping("/export") @PreAuthorize("@pms.hasPermission('wallet_walletTransaction_export')") diff --git a/pjcloud-wallet/pjcloud-wallet-biz/src/main/java/com/bsd/pjcloud/wallet/mapper/MchManageMapper.java b/pjcloud-wallet/pjcloud-wallet-biz/src/main/java/com/bsd/pjcloud/wallet/mapper/MchManageMapper.java index 6f163c994..73131679c 100644 --- a/pjcloud-wallet/pjcloud-wallet-biz/src/main/java/com/bsd/pjcloud/wallet/mapper/MchManageMapper.java +++ b/pjcloud-wallet/pjcloud-wallet-biz/src/main/java/com/bsd/pjcloud/wallet/mapper/MchManageMapper.java @@ -31,4 +31,11 @@ public interface MchManageMapper extends PjcloudBaseMapper { .in(ObjectUtil.isNotEmpty(dto.getIds()), MchManageEntity::getId, dto.getIds()); return selectJoinList(MchManageVo.class, wrapper); } + + default MchManageVo join(Long id) { + MPJLambdaQueryWrapper wrapper = new MPJLambdaQueryWrapper() + .selectAll(MchManageEntity.class) + .eq(MchManageEntity::getId, id); + return selectJoinOne(MchManageVo.class, wrapper); + } } \ No newline at end of file diff --git a/pjcloud-wallet/pjcloud-wallet-biz/src/main/java/com/bsd/pjcloud/wallet/service/MchManageService.java b/pjcloud-wallet/pjcloud-wallet-biz/src/main/java/com/bsd/pjcloud/wallet/service/MchManageService.java index 14ff55186..f7fcafc7d 100644 --- a/pjcloud-wallet/pjcloud-wallet-biz/src/main/java/com/bsd/pjcloud/wallet/service/MchManageService.java +++ b/pjcloud-wallet/pjcloud-wallet-biz/src/main/java/com/bsd/pjcloud/wallet/service/MchManageService.java @@ -19,6 +19,8 @@ public interface MchManageService extends IService { Page pageJoin(Page page, MchManageDto dto); + MchManageVo join(Long id); + List list(MchManageDto dto); MchManageVo getByDeptId(Long deptId); diff --git a/pjcloud-wallet/pjcloud-wallet-biz/src/main/java/com/bsd/pjcloud/wallet/service/WalletTransactionService.java b/pjcloud-wallet/pjcloud-wallet-biz/src/main/java/com/bsd/pjcloud/wallet/service/WalletTransactionService.java index 39bf35b61..6ffe61ce9 100644 --- a/pjcloud-wallet/pjcloud-wallet-biz/src/main/java/com/bsd/pjcloud/wallet/service/WalletTransactionService.java +++ b/pjcloud-wallet/pjcloud-wallet-biz/src/main/java/com/bsd/pjcloud/wallet/service/WalletTransactionService.java @@ -20,7 +20,7 @@ public interface WalletTransactionService extends IService list(MchManageDto dto) { return baseMapper.list(dto); diff --git a/pjcloud-wallet/pjcloud-wallet-biz/src/main/java/com/bsd/pjcloud/wallet/service/impl/WalletManageServiceImpl.java b/pjcloud-wallet/pjcloud-wallet-biz/src/main/java/com/bsd/pjcloud/wallet/service/impl/WalletManageServiceImpl.java index 03aa5a581..218c48536 100644 --- a/pjcloud-wallet/pjcloud-wallet-biz/src/main/java/com/bsd/pjcloud/wallet/service/impl/WalletManageServiceImpl.java +++ b/pjcloud-wallet/pjcloud-wallet-biz/src/main/java/com/bsd/pjcloud/wallet/service/impl/WalletManageServiceImpl.java @@ -59,6 +59,7 @@ public class WalletManageServiceImpl extends ServiceImpl implements WalletSettingService { @Override - @Cacheable(value = CacheConstants.WALLET_SETTING_DETAIL, unless = "#result == null") + @Cacheable(value = CacheConstants.WALLET_SETTING_DETAIL) public WalletSettingVo getSetting() { WalletSettingEntity setting = baseMapper.selectOne(new QueryWrapper<>()); + if (ObjectUtil.isEmpty(setting)) { + DefaultWalletSetting defaultWalletSetting = new DefaultWalletSetting(); + baseMapper.insert(defaultWalletSetting); + return BeanUtils.toBean(defaultWalletSetting, WalletSettingVo.class); + } return BeanUtils.toBean(setting, WalletSettingVo.class); } @Override - @CachePut(value = CacheConstants.WALLET_SETTING_DETAIL, condition = "dto.getId() != null", unless = "#result == null") + @CacheEvict(value = CacheConstants.WALLET_SETTING_DETAIL, allEntries = true) public void edit(WalletSettingDto dto) { WalletSettingEntity setting = baseMapper.selectById(dto.getId()); if (ObjectUtil.isEmpty(setting)) { @@ -42,4 +51,52 @@ public class WalletSettingServiceImpl extends ServiceImpl