1. notice module
This commit is contained in:
2026-02-12 15:51:30 +08:00
parent 28f13a5db3
commit c3bbf9073a
10 changed files with 85 additions and 72 deletions

View File

@@ -4,7 +4,7 @@ CREATE TABLE user_notice
id int8 NOT NULL PRIMARY KEY, -- 主键 id int8 NOT NULL PRIMARY KEY, -- 主键
user_id int8 DEFAULT 0 NOT NULL, -- 用户id user_id int8 DEFAULT 0 NOT NULL, -- 用户id
notice_type int4 DEFAULT 0 NOT NULL, -- 通知类型 0-系统通知 1-app通知 2-market通知 notice_type int4 DEFAULT 0 NOT NULL, -- 通知类型 0-系统通知 1-app通知 2-market通知
module_type int4 NULL, -- 业务模块 module_type varchar(256) NULL, -- 业务模块
has_read int4 DEFAULT 0 NOT NULL, -- 是否已读 0-否 1-是 has_read int4 DEFAULT 0 NOT NULL, -- 是否已读 0-否 1-是
title VARCHAR(100) NULL, -- 标题 title VARCHAR(100) NULL, -- 标题
content TEXT NULL, -- 内容 content TEXT NULL, -- 内容

View File

@@ -17,6 +17,7 @@ import org.springblade.modules.api.response.PaymentResponse;
import org.springblade.modules.api.vo.CommonUserNoticeApiVO; import org.springblade.modules.api.vo.CommonUserNoticeApiVO;
import org.springblade.modules.api.vo.CommonUserNoticeDetailApiVO; import org.springblade.modules.api.vo.CommonUserNoticeDetailApiVO;
import org.springblade.modules.api.vo.CommonUserOrderApiVO; import org.springblade.modules.api.vo.CommonUserOrderApiVO;
import org.springblade.modules.api.vo.CommonUserOrderDetailApiVO;
import org.springblade.modules.common.service.ICommonUserOrderService; import org.springblade.modules.common.service.ICommonUserOrderService;
import org.springblade.modules.common.service.ICommonUserNoticeService; import org.springblade.modules.common.service.ICommonUserNoticeService;
import org.springblade.modules.system.service.IUserService; import org.springblade.modules.system.service.IUserService;
@@ -99,6 +100,16 @@ public class APPUserController {
return R.data(pages); return R.data(pages);
} }
/**
* 用户订单列表
*/
@GetMapping("/order-detail")
@ApiOperationSupport(order = 6)
@Operation(summary = "用户订单分页列表")
public R<CommonUserOrderDetailApiVO> orderDetail(Long id) {
return R.data(orderService.orderDetail(id));
}
@GetMapping("/system-notice") @GetMapping("/system-notice")
@ApiOperationSupport(order = 7) @ApiOperationSupport(order = 7)
@@ -124,6 +135,7 @@ public class APPUserController {
return R.data(userNoticeService.userNoticeDetail(id)); return R.data(userNoticeService.userNoticeDetail(id));
} }
@GetMapping("/unread") @GetMapping("/unread")
@ApiOperationSupport(order = 10) @ApiOperationSupport(order = 10)
@Operation(summary = "用户未读消息数量") @Operation(summary = "用户未读消息数量")

View File

@@ -11,36 +11,18 @@ public class CommonUserOrderApiVO implements Serializable {
private Long id; private Long id;
private String consigneePhone;
private String consignee;
private String orderType; private String orderType;
private String itemCode;
private String itemName; private String itemName;
private String imageUrl; private String imageUrl;
private Integer quantity; private Integer quantity;
private String deliveryAddress;
private String expressCompany;
private String expressNo;
private Integer orderStatus; private Integer orderStatus;
private BigDecimal totalAmount; private BigDecimal totalAmount;
private BigDecimal actualAmount; private BigDecimal actualAmount;
private Integer paymentType;
private Date paymentTime;
private Integer paymentStatus;
} }

View File

@@ -0,0 +1,46 @@
package org.springblade.modules.api.vo;
import lombok.Data;
import java.io.Serializable;
import java.math.BigDecimal;
import java.util.Date;
@Data
public class CommonUserOrderDetailApiVO implements Serializable {
private Long id;
private String consigneePhone;
private String consignee;
private String orderType;
private String itemCode;
private String itemName;
private String imageUrl;
private Integer quantity;
private String deliveryAddress;
private String expressCompany;
private String expressNo;
private Integer orderStatus;
private BigDecimal totalAmount;
private BigDecimal actualAmount;
private Integer paymentType;
private Date paymentTime;
private Integer paymentStatus;
}

View File

@@ -7,6 +7,7 @@ import org.springblade.modules.api.request.CreateOrderRequest;
import org.springblade.modules.api.vo.CommonUserNoticeApiVO; import org.springblade.modules.api.vo.CommonUserNoticeApiVO;
import org.springblade.modules.api.vo.CommonUserNoticeDetailApiVO; import org.springblade.modules.api.vo.CommonUserNoticeDetailApiVO;
import org.springblade.modules.api.vo.CommonUserOrderApiVO; import org.springblade.modules.api.vo.CommonUserOrderApiVO;
import org.springblade.modules.api.vo.CommonUserOrderDetailApiVO;
import org.springblade.modules.common.pojo.entity.CommonRegionsInfoEntity; import org.springblade.modules.common.pojo.entity.CommonRegionsInfoEntity;
import org.springblade.modules.common.pojo.entity.CommonUserNoticeEntity; import org.springblade.modules.common.pojo.entity.CommonUserNoticeEntity;
import org.springblade.modules.common.pojo.entity.CommonUserOrderEntity; import org.springblade.modules.common.pojo.entity.CommonUserOrderEntity;
@@ -47,6 +48,8 @@ public interface AppCommonConvert {
List<CommonUserOrderApiVO> convertUserOrderEntityListTOApiList(List<CommonUserOrderEntity> entityList); List<CommonUserOrderApiVO> convertUserOrderEntityListTOApiList(List<CommonUserOrderEntity> entityList);
CommonUserOrderDetailApiVO convertOrderDetailApiVO(CommonUserOrderEntity entity);
CommonUserOrderApiVO convertOrderApiVO(CommonUserOrderVO vo); CommonUserOrderApiVO convertOrderApiVO(CommonUserOrderVO vo);
List<CommonUserOrderApiVO> convertOrderApiListVO(List<CommonUserOrderVO> voList); List<CommonUserOrderApiVO> convertOrderApiListVO(List<CommonUserOrderVO> voList);

View File

@@ -6,9 +6,9 @@ import lombok.RequiredArgsConstructor;
@RequiredArgsConstructor @RequiredArgsConstructor
public enum BusinessModule { public enum BusinessModule {
SELF_OPERATED_MALL("自营商城", "self_mall", 1), SELF_OPERATED_MALL("自营商城", "self_mall"),
ECOSYSTEM_PRODUCT("生态商品", "eco_product", 2), ECOSYSTEM_PRODUCT("生态商品", "eco_product"),
TRAVEL_GROUP("旅游团", "travel_group", 3); TRAVEL_GROUP("旅游团", "travel_group");
@Getter @Getter
private final String displayName; private final String displayName;
@@ -16,26 +16,6 @@ public enum BusinessModule {
@Getter @Getter
private final String code; private final String code;
@Getter
private final int id;
private static final BusinessModule[] BY_ID;
static {
// 初始化 BY_ID 映射(用于 O(1) 查找)
int maxId = 0;
for (BusinessModule module : values()) {
if (module.id > maxId) maxId = module.id;
}
BY_ID = new BusinessModule[maxId + 1];
for (BusinessModule module : values()) {
if (BY_ID[module.id] != null) {
throw new IllegalStateException("重复的模块 ID: " + module.id);
}
BY_ID[module.id] = module;
}
}
// ======================== // ========================
// 根据 code 查找(忽略大小写) // 根据 code 查找(忽略大小写)
@@ -61,29 +41,4 @@ public enum BusinessModule {
return null; return null;
} }
// ========================
// 根据 int id 查找
// ========================
public static BusinessModule fromId(int id) {
BusinessModule module = fromIdOrNull(id);
if (module == null) {
throw new IllegalArgumentException("未知的业务模块 id: " + id);
}
return module;
}
public static BusinessModule fromIdOrNull(int id) {
if (id < 1 || id >= BY_ID.length) {
return null;
}
return BY_ID[id];
}
/**
* O(1) 快速获取(假设 ID 有效且已初始化)
*/
public static BusinessModule getByIdFast(int id) {
return BY_ID[id]; // 注意:若 id 无效会抛 ArrayIndexOutOfBoundsException
}
} }

View File

@@ -25,7 +25,7 @@ public class NoticeListener {
CommonUserNoticeEntity notice = new CommonUserNoticeEntity(); CommonUserNoticeEntity notice = new CommonUserNoticeEntity();
notice.setUserId(event.getUserId()); notice.setUserId(event.getUserId());
notice.setNoticeType(NoticeType.APP_USER.getCode()); notice.setNoticeType(NoticeType.APP_USER.getCode());
notice.setModuleType(event.getBusinessModule().getId()); notice.setModuleType(event.getBusinessModule().getCode());
notice.setTitle(event.getBusinessModule().getDisplayName()); notice.setTitle(event.getBusinessModule().getDisplayName());
notice.setContent(OrderStatus.PAID.formatUserMessage(String.valueOf(event.getOrderId()))); notice.setContent(OrderStatus.PAID.formatUserMessage(String.valueOf(event.getOrderId())));
noticeService.save(notice); noticeService.save(notice);

View File

@@ -28,7 +28,9 @@ package org.springblade.modules.common.pojo.entity;
import lombok.Data; import lombok.Data;
import io.swagger.v3.oas.annotations.media.Schema; import io.swagger.v3.oas.annotations.media.Schema;
import com.baomidou.mybatisplus.annotation.TableName; import com.baomidou.mybatisplus.annotation.TableName;
import java.util.Date; import java.util.Date;
import lombok.EqualsAndHashCode; import lombok.EqualsAndHashCode;
import lombok.experimental.Accessors; import lombok.experimental.Accessors;
import org.springblade.core.mp.base.BaseEntity; import org.springblade.core.mp.base.BaseEntity;
@@ -65,7 +67,7 @@ public class CommonUserNoticeEntity extends BaseEntity {
* 业务类型 * 业务类型
*/ */
@Schema(description = "业务类型") @Schema(description = "业务类型")
private Integer moduleType; private String moduleType;
/** /**
* 是否已读 0-否 1-是 * 是否已读 0-否 1-是
*/ */

View File

@@ -31,6 +31,7 @@ import org.springblade.modules.api.request.PaymentRequest;
import org.springblade.modules.api.response.CreateOrderResponse; import org.springblade.modules.api.response.CreateOrderResponse;
import org.springblade.modules.api.response.PaymentResponse; import org.springblade.modules.api.response.PaymentResponse;
import org.springblade.modules.api.vo.CommonUserOrderApiVO; import org.springblade.modules.api.vo.CommonUserOrderApiVO;
import org.springblade.modules.api.vo.CommonUserOrderDetailApiVO;
import org.springblade.modules.common.pojo.entity.CommonUserOrderEntity; import org.springblade.modules.common.pojo.entity.CommonUserOrderEntity;
import org.springblade.modules.common.pojo.vo.CommonUserOrderVO; import org.springblade.modules.common.pojo.vo.CommonUserOrderVO;
import org.springblade.modules.common.excel.CommonUserOrderExcel; import org.springblade.modules.common.excel.CommonUserOrderExcel;
@@ -69,5 +70,8 @@ public interface ICommonUserOrderService extends IService<CommonUserOrderEntity>
IPage<CommonUserOrderApiVO> selectOrderApiPage(IPage<CommonUserOrderApiVO> page, CommonUserOrderApiVO userOrder); IPage<CommonUserOrderApiVO> selectOrderApiPage(IPage<CommonUserOrderApiVO> page, CommonUserOrderApiVO userOrder);
CommonUserOrderDetailApiVO orderDetail(Long id);
boolean confirmPayment(Long id); boolean confirmPayment(Long id);
} }

View File

@@ -36,6 +36,7 @@ import org.springblade.modules.api.request.PaymentRequest;
import org.springblade.modules.api.response.CreateOrderResponse; import org.springblade.modules.api.response.CreateOrderResponse;
import org.springblade.modules.api.response.PaymentResponse; import org.springblade.modules.api.response.PaymentResponse;
import org.springblade.modules.api.vo.CommonUserOrderApiVO; import org.springblade.modules.api.vo.CommonUserOrderApiVO;
import org.springblade.modules.api.vo.CommonUserOrderDetailApiVO;
import org.springblade.modules.common.convert.AppCommonConvert; import org.springblade.modules.common.convert.AppCommonConvert;
import org.springblade.modules.common.eums.BusinessModule; import org.springblade.modules.common.eums.BusinessModule;
import org.springblade.modules.common.eums.OrderStatus; import org.springblade.modules.common.eums.OrderStatus;
@@ -99,13 +100,14 @@ public class CommonUserOrderServiceImpl extends ServiceImpl<CommonUserOrderMappe
if (!request.getIsOfflinePayment()) { if (!request.getIsOfflinePayment()) {
discount = BigDecimal.valueOf(new Random().nextInt(99) + 1, 2); discount = BigDecimal.valueOf(new Random().nextInt(99) + 1, 2);
} }
return switch (orderType) { return switch (BusinessModule.fromCodeIgnoreCaseOrNull(orderType)) {
case "MALL" -> { case SELF_OPERATED_MALL -> {
MallProductEntity product = productService.getById(Long.valueOf(request.getItemCode())); MallProductEntity product = productService.getById(Long.valueOf(request.getItemCode()));
Assert.notNull(product, "无效商品"); Assert.notNull(product, "无效商品");
CommonUserOrderEntity order = AppCommonConvert.INSTANCE.convertMallProductToOrder(request, product); CommonUserOrderEntity order = AppCommonConvert.INSTANCE.convertMallProductToOrder(request, product);
BigDecimal totalAmount = product.getRetailPrice().multiply(BigDecimal.valueOf(request.getQuantity())).setScale(2, RoundingMode.DOWN); BigDecimal totalAmount = product.getRetailPrice().multiply(BigDecimal.valueOf(request.getQuantity())).setScale(2, RoundingMode.DOWN);
BigDecimal actualAmount = totalAmount.subtract(discount); BigDecimal actualAmount = totalAmount.subtract(discount);
order.setOrderType(BusinessModule.SELF_OPERATED_MALL.getCode());
order.setUserId(AuthUtil.getUserId()); order.setUserId(AuthUtil.getUserId());
order.setTotalAmount(totalAmount); order.setTotalAmount(totalAmount);
order.setActualAmount(actualAmount); order.setActualAmount(actualAmount);
@@ -114,7 +116,7 @@ public class CommonUserOrderServiceImpl extends ServiceImpl<CommonUserOrderMappe
save(order); save(order);
yield new CreateOrderResponse(String.valueOf(order.getId()), actualAmount, totalAmount, discount); yield new CreateOrderResponse(String.valueOf(order.getId()), actualAmount, totalAmount, discount);
} }
case "FILTER" -> { case TRAVEL_GROUP -> {
yield new CreateOrderResponse("", BigDecimal.ZERO, BigDecimal.ZERO, discount); yield new CreateOrderResponse("", BigDecimal.ZERO, BigDecimal.ZERO, discount);
} }
default -> throw new IllegalArgumentException("不支持的订单类型: " + request.getOrderType()); default -> throw new IllegalArgumentException("不支持的订单类型: " + request.getOrderType());
@@ -139,6 +141,13 @@ public class CommonUserOrderServiceImpl extends ServiceImpl<CommonUserOrderMappe
return page.setRecords(AppCommonConvert.INSTANCE.convertUserOrderEntityListTOApiList(commonUserOrderEntityList)); return page.setRecords(AppCommonConvert.INSTANCE.convertUserOrderEntityListTOApiList(commonUserOrderEntityList));
} }
@Override
public CommonUserOrderDetailApiVO orderDetail(Long id) {
CommonUserOrderEntity order = getById(id);
Assert.notNull(order, "无效订单");
return AppCommonConvert.INSTANCE.convertOrderDetailApiVO(order);
}
@Override @Override
@Transactional(rollbackFor = Exception.class) @Transactional(rollbackFor = Exception.class)
@RedisDebounce(key = "order:confirm", param = "#id", interval = 20, includeRemainingTime = true, message = "操作过于频繁") @RedisDebounce(key = "order:confirm", param = "#id", interval = 20, includeRemainingTime = true, message = "操作过于频繁")