Please enter the commit message for your changes. Lines starting
with '#' will be ignored, and an empty message aborts the commit. On branch develop Your branch is up to date with 'goflyapp/develop'. Changes to be committed: new file: zlt-business/order-center/src/main/java/com/central/order/config/AsyncConfig.java new file: zlt-business/order-center/src/main/java/com/central/order/controller/MessageController.java modified: zlt-business/order-center/src/main/java/com/central/order/controller/OrderController.java new file: zlt-business/order-center/src/main/java/com/central/order/enums/MessageTemplateEnum.java new file: zlt-business/order-center/src/main/java/com/central/order/enums/OrderStatusChangeEnum.java new file: zlt-business/order-center/src/main/java/com/central/order/event/OrderStatusChangeEvent.java new file: zlt-business/order-center/src/main/java/com/central/order/listener/OrderStatusChangeListener.java new file: zlt-business/order-center/src/main/java/com/central/order/mapper/MessageMapper.java new file: zlt-business/order-center/src/main/java/com/central/order/model/Message.java new file: zlt-business/order-center/src/main/java/com/central/order/service/IMessageService.java new file: zlt-business/order-center/src/main/java/com/central/order/service/impl/MessageServiceImpl.java modified: zlt-business/order-center/src/main/java/com/central/order/service/impl/OrderServiceImpl.java modified: zlt-business/order-center/src/main/resources/bootstrap.yml new file: zlt-business/order-center/src/main/resources/mapper/MessageMapper.xml modified: zlt-web/react-web/src/main/frontend/config/routes.ts modified: zlt-web/react-web/src/main/frontend/src/components/RightContent/index.tsx new file: zlt-web/react-web/src/main/frontend/src/models/useMessage.ts new file: zlt-web/react-web/src/main/frontend/src/pages/message/index.less new file: zlt-web/react-web/src/main/frontend/src/pages/message/index.tsx deleted: zlt-web/react-web/src/main/frontend/src/pages/system/Tenant/components/CreateForm.tsx deleted: zlt-web/react-web/src/main/frontend/src/pages/system/Tenant/components/UpdateForm.tsx deleted: zlt-web/react-web/src/main/frontend/src/pages/system/Tenant/index.tsx new file: zlt-web/react-web/src/main/frontend/src/services/message/api.ts new file: zlt-web/react-web/src/main/frontend/src/services/message/typings.d.ts modified: zlt-web/react-web/src/main/frontend/src/services/system/api.ts modified: zlt-web/react-web/src/main/frontend/src/services/system/typings.d.ts Changes not staged for commit: modified: zlt-business/order-center/src/main/java/com/central/order/controller/OrderController.java modified: zlt-business/order-center/src/main/java/com/central/order/enums/MessageTemplateEnum.java modified: zlt-business/order-center/src/main/java/com/central/order/enums/OrderStatusChangeEnum.java modified: zlt-business/order-center/src/main/java/com/central/order/event/OrderStatusChangeEvent.java modified: zlt-business/order-center/src/main/java/com/central/order/listener/OrderStatusChangeListener.java modified: zlt-business/order-center/src/main/java/com/central/order/mapper/MessageMapper.java modified: zlt-business/order-center/src/main/java/com/central/order/service/impl/MessageServiceImpl.java modified: zlt-business/order-center/src/main/java/com/central/order/service/impl/OrderServiceImpl.java modified: zlt-business/order-center/src/main/resources/mapper/MessageMapper.xml modified: zlt-business/order-center/src/main/resources/mapper/OrderMapper.xml modified: zlt-web/react-web/src/main/frontend/src/services/message/api.ts
This commit is contained in:
@@ -0,0 +1,31 @@
|
||||
package com.central.order.config;
|
||||
|
||||
import org.springframework.aop.interceptor.AsyncUncaughtExceptionHandler;
|
||||
import org.springframework.aop.interceptor.SimpleAsyncUncaughtExceptionHandler;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.scheduling.annotation.AsyncConfigurer;
|
||||
import org.springframework.scheduling.annotation.EnableAsync;
|
||||
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
|
||||
|
||||
import java.util.concurrent.Executor;
|
||||
|
||||
@Configuration
|
||||
@EnableAsync
|
||||
public class AsyncConfig implements AsyncConfigurer {
|
||||
|
||||
@Override
|
||||
public Executor getAsyncExecutor() {
|
||||
ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor();
|
||||
executor.setCorePoolSize(5);
|
||||
executor.setMaxPoolSize(10);
|
||||
executor.setQueueCapacity(25);
|
||||
executor.setThreadNamePrefix("message-async-");
|
||||
executor.initialize();
|
||||
return executor;
|
||||
}
|
||||
|
||||
@Override
|
||||
public AsyncUncaughtExceptionHandler getAsyncUncaughtExceptionHandler() {
|
||||
return new SimpleAsyncUncaughtExceptionHandler();
|
||||
}
|
||||
}
|
||||
+47
@@ -0,0 +1,47 @@
|
||||
package com.central.order.controller;
|
||||
|
||||
import com.central.common.model.PageResult;
|
||||
import com.central.common.model.Result;
|
||||
import com.central.order.model.Message;
|
||||
import com.central.order.service.IMessageService;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
@Slf4j
|
||||
@RestController
|
||||
@RequestMapping("/messages")
|
||||
@Tag(name = "站内信管理")
|
||||
@RequiredArgsConstructor
|
||||
public class MessageController {
|
||||
|
||||
private final IMessageService messageService;
|
||||
|
||||
@Operation(summary = "获取消息列表")
|
||||
@GetMapping
|
||||
public PageResult<Message> getMessages(@RequestParam Map<String, Object> params) {
|
||||
return messageService.findMessages(params);
|
||||
}
|
||||
|
||||
@Operation(summary = "标记消息已读")
|
||||
@PutMapping("/{id}/read")
|
||||
public Result markAsRead(@PathVariable Long id) {
|
||||
return messageService.markAsRead(id);
|
||||
}
|
||||
|
||||
@Operation(summary = "标记所有消息已读")
|
||||
@PutMapping("/read/all")
|
||||
public Result markAllAsRead() {
|
||||
return messageService.markAllAsRead();
|
||||
}
|
||||
|
||||
@Operation(summary = "删除消息")
|
||||
@DeleteMapping("/{id}")
|
||||
public Result deleteMessage(@PathVariable Long id) {
|
||||
return messageService.deleteMessage(id);
|
||||
}
|
||||
}
|
||||
+5
-6
@@ -372,10 +372,10 @@ public class OrderController {
|
||||
@PostMapping("/status")
|
||||
public Result<String> updateOrderStatusDoing(@RequestBody String orderNo) {
|
||||
Order order = orderService.getOrderByNumber(orderNo);
|
||||
Assert.notNull(order,"订单数据不能为空");
|
||||
if (order.getOrderStatus().equals(OrderStatus.PAID.getId())){
|
||||
Assert.notNull(order, "订单数据不能为空");
|
||||
if (order.getOrderStatus().equals(OrderStatus.PAID.getId())) {
|
||||
order.setOrderStatus(OrderStatus.DOING.getId());
|
||||
if (orderService.updateOrder(order)){
|
||||
if (orderService.updateOrder(order)) { // 这里会触发事件
|
||||
return Result.succeed("更新成功");
|
||||
}
|
||||
}
|
||||
@@ -419,11 +419,10 @@ public class OrderController {
|
||||
@Operation(summary = "取消订单")
|
||||
@PutMapping("/{id}")
|
||||
public Result cancelOrder(@PathVariable("id") Long id) {
|
||||
|
||||
Order order = orderService.getById(id);
|
||||
order.setOrderStatus(OrderStatus.CANCELED.getId());
|
||||
boolean res = orderService.updateOrder(order);
|
||||
if (res){
|
||||
boolean res = orderService.updateOrder(order); // 这里会触发事件
|
||||
if (res) {
|
||||
return Result.succeed("已取消");
|
||||
}
|
||||
return Result.failed("请重试");
|
||||
|
||||
+29
@@ -0,0 +1,29 @@
|
||||
package com.central.order.enums;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Getter;
|
||||
|
||||
@Getter
|
||||
@AllArgsConstructor
|
||||
public enum MessageTemplateEnum {
|
||||
ORDER_CREATED(1, "新订单提醒", "您有一个新的订单 #{orderId} 已创建"),
|
||||
ORDER_PAID(2, "支付成功提醒", "订单 #{orderId} 已支付成功"),
|
||||
ORDER_COMPLETED(3, "订单完成提醒", "订单 #{orderId} 已完成"),
|
||||
ORDER_CANCELLED(4, "订单取消提醒", "订单 #{orderId} 已取消"),
|
||||
ORDER_REFUNDED(5, "退款成功提醒", "订单 #{orderId} 已退款");
|
||||
|
||||
private final Integer type;
|
||||
private final String title;
|
||||
private final String contentTemplate;
|
||||
|
||||
public static MessageTemplateEnum getByOrderStatus(Integer orderStatus) {
|
||||
switch (orderStatus) {
|
||||
case 0: return ORDER_CREATED;
|
||||
case 1: return ORDER_PAID;
|
||||
case 2: return ORDER_COMPLETED;
|
||||
case 3: return ORDER_CANCELLED;
|
||||
case 4: return ORDER_REFUNDED;
|
||||
default: return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
+35
@@ -0,0 +1,35 @@
|
||||
package com.central.order.enums;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Getter;
|
||||
|
||||
@Getter
|
||||
@AllArgsConstructor
|
||||
public enum OrderStatusChangeEnum {
|
||||
UNPAID_TO_PAID(OrderStatus.UNPAID.getId(), OrderStatus.PAID.getId(),
|
||||
"订单支付成功", "您的订单 #{orderNo} 已支付成功,正在等待执行"),
|
||||
|
||||
PAID_TO_DOING(OrderStatus.PAID.getId(), OrderStatus.DOING.getId(),
|
||||
"订单开始执行", "您的订单 #{orderNo} 正在执行中"),
|
||||
|
||||
DOING_TO_COMPLETE(OrderStatus.DOING.getId(), OrderStatus.COMPLETE.getId(),
|
||||
"订单已完成", "您的订单 #{orderNo} 已完成"),
|
||||
|
||||
ANY_TO_CANCELED(null, OrderStatus.CANCELED.getId(),
|
||||
"订单已取消", "您的订单 #{orderNo} 已取消");
|
||||
|
||||
private final Integer oldStatus;
|
||||
private final Integer newStatus;
|
||||
private final String title;
|
||||
private final String contentTemplate;
|
||||
|
||||
public static OrderStatusChangeEnum getByStatusChange(Integer oldStatus, Integer newStatus) {
|
||||
for (OrderStatusChangeEnum changeEnum : values()) {
|
||||
if ((changeEnum.oldStatus == null || changeEnum.oldStatus.equals(oldStatus))
|
||||
&& changeEnum.newStatus.equals(newStatus)) {
|
||||
return changeEnum;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
+25
@@ -0,0 +1,25 @@
|
||||
package com.central.order.event;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Getter;
|
||||
import org.springframework.context.ApplicationEvent;
|
||||
|
||||
@Getter
|
||||
@AllArgsConstructor
|
||||
public class OrderStatusChangeEvent extends ApplicationEvent {
|
||||
private final String orderId; // 订单ID
|
||||
private final Integer oldStatus; // 原状态
|
||||
private final Integer newStatus; // 新状态
|
||||
private final Long userId; // 用户ID
|
||||
private final String orderInfo; // 订单信息(可选)
|
||||
|
||||
public OrderStatusChangeEvent(Object source, String orderId, Integer oldStatus,
|
||||
Integer newStatus, Long userId, String orderInfo) {
|
||||
super(source);
|
||||
this.orderId = orderId;
|
||||
this.oldStatus = oldStatus;
|
||||
this.newStatus = newStatus;
|
||||
this.userId = userId;
|
||||
this.orderInfo = orderInfo;
|
||||
}
|
||||
}
|
||||
+90
@@ -0,0 +1,90 @@
|
||||
package com.central.order.listener;
|
||||
|
||||
import com.central.order.event.OrderStatusChangeEvent;
|
||||
import com.central.order.enums.MessageTemplateEnum;
|
||||
import com.central.order.enums.OrderStatusChangeEnum;
|
||||
import com.central.order.service.IMessageService;
|
||||
import com.central.order.service.ITourismService;
|
||||
import com.central.order.util.JsonUtil;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.context.event.EventListener;
|
||||
import org.springframework.scheduling.annotation.Async;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
@Slf4j
|
||||
@Component
|
||||
@RequiredArgsConstructor
|
||||
public class OrderStatusChangeListener {
|
||||
|
||||
private final IMessageService messageService;
|
||||
private final ITourismService tourismService;
|
||||
|
||||
@EventListener
|
||||
@Async
|
||||
public void handleOrderStatusChange(OrderStatusChangeEvent event) {
|
||||
try {
|
||||
// 获取状态变更类型
|
||||
OrderStatusChangeEnum changeEnum = OrderStatusChangeEnum
|
||||
.getByStatusChange(event.getOldStatus(), event.getNewStatus());
|
||||
|
||||
if (changeEnum == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
// 获取订单信息
|
||||
Order order = orderService.getOrderByNumber(event.getOrderId());
|
||||
if (order == null) {
|
||||
log.error("订单不存在: {}", event.getOrderId());
|
||||
return;
|
||||
}
|
||||
|
||||
// 获取景区信息
|
||||
Tourism tourism = tourismService.getTourismById(order.getTourismId());
|
||||
|
||||
// 构建消息内容
|
||||
String content = changeEnum.getContentTemplate()
|
||||
.replace("#{orderNo}", event.getOrderId())
|
||||
+ "\n景区名称:" + tourism.getTourismName()
|
||||
+ "\n" + event.getOrderInfo();
|
||||
|
||||
// 创建站内信
|
||||
Message message = new Message();
|
||||
message.setTitle(changeEnum.getTitle());
|
||||
message.setContent(content);
|
||||
message.setType(getMessageType(event.getNewStatus()));
|
||||
message.setUserId(event.getUserId());
|
||||
message.setRelatedId(event.getOrderId());
|
||||
|
||||
// 设置额外信息
|
||||
Map<String, Object> extra = new HashMap<>();
|
||||
extra.put("oldStatus", event.getOldStatus());
|
||||
extra.put("newStatus", event.getNewStatus());
|
||||
extra.put("tourismId", order.getTourismId());
|
||||
extra.put("tourismName", tourism.getTourismName());
|
||||
message.setExtra(JsonUtil.toJson(extra));
|
||||
|
||||
// 保存消息
|
||||
messageService.createMessage(message);
|
||||
|
||||
log.info("Created message for order status change: orderId={}, oldStatus={}, newStatus={}",
|
||||
event.getOrderId(), event.getOldStatus(), event.getNewStatus());
|
||||
|
||||
} catch (Exception e) {
|
||||
log.error("Failed to handle order status change event", e);
|
||||
}
|
||||
}
|
||||
|
||||
private Integer getMessageType(Integer orderStatus) {
|
||||
switch (orderStatus) {
|
||||
case 1: return 2; // 支付成功消息
|
||||
case 2: return 3; // 开始执行消息
|
||||
case 3: return 4; // 完成消息
|
||||
case 4: return 5; // 取消消息
|
||||
default: return 1; // 其他消息
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,79 @@
|
||||
package com.central.order.mapper;
|
||||
|
||||
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.central.db.mapper.SuperMapper;
|
||||
import com.central.order.model.Message;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
import org.apache.ibatis.annotations.Select;
|
||||
import org.apache.ibatis.annotations.Update;
|
||||
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
@Mapper
|
||||
public interface MessageMapper extends SuperMapper<Message> {
|
||||
|
||||
@Select("SELECT * FROM sys_message WHERE user_id = #{userId} AND tenant_id = #{tenantId}")
|
||||
List<Message> findList(Page<Message> page, @Param("userId") Long userId,
|
||||
@Param("tenantId") String tenantId);
|
||||
|
||||
@Update("UPDATE sys_message SET status = 1, read_time = #{readTime} " +
|
||||
"WHERE id = #{id} AND user_id = #{userId}")
|
||||
int markAsRead(@Param("id") Long id, @Param("userId") Long userId,
|
||||
@Param("readTime") Date readTime);
|
||||
|
||||
@Update("UPDATE sys_message SET status = 1, read_time = #{readTime} " +
|
||||
"WHERE user_id = #{userId} AND status = 0")
|
||||
int markAllAsRead(@Param("userId") Long userId, @Param("readTime") Date readTime);
|
||||
|
||||
/**
|
||||
* 查询消息列表
|
||||
* 使用@Param注解明确指定参数名
|
||||
*/
|
||||
List<Message> findList(Page<Message> page,
|
||||
@Param("userId") Long userId,
|
||||
@Param("tenantId") String tenantId,
|
||||
@Param("params") Map<String, Object> params);
|
||||
|
||||
/**
|
||||
* 批量插入消息
|
||||
*/
|
||||
int batchInsert(@Param("list") List<Message> messages);
|
||||
|
||||
/**
|
||||
* 批量更新消息状态
|
||||
*/
|
||||
int batchUpdateStatus(@Param("ids") List<Long> ids,
|
||||
@Param("status") Integer status,
|
||||
@Param("readTime") Date readTime,
|
||||
@Param("userId") Long userId);
|
||||
|
||||
/**
|
||||
* 获取未读消息数量
|
||||
*/
|
||||
int getUnreadCount(@Param("userId") Long userId,
|
||||
@Param("tenantId") String tenantId);
|
||||
|
||||
/**
|
||||
* 按类型获取未读消息数量
|
||||
*/
|
||||
List<Map<String, Object>> getUnreadCountByType(@Param("userId") Long userId,
|
||||
@Param("tenantId") String tenantId);
|
||||
|
||||
/**
|
||||
* 删除指定时间之前的已读消息
|
||||
*/
|
||||
int deleteReadMessages(@Param("beforeTime") Date beforeTime,
|
||||
@Param("userId") Long userId,
|
||||
@Param("tenantId") String tenantId);
|
||||
|
||||
/**
|
||||
* 根据关联ID查询消息
|
||||
*/
|
||||
List<Message> findByRelatedId(@Param("relatedId") String relatedId,
|
||||
@Param("userId") Long userId,
|
||||
@Param("tenantId") String tenantId);
|
||||
}
|
||||
@@ -0,0 +1,58 @@
|
||||
package com.central.order.model;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import com.central.common.model.SuperEntity;
|
||||
import lombok.Data;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
@Data
|
||||
@TableName("sys_message")
|
||||
public class Message extends SuperEntity {
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
/**
|
||||
* 消息标题
|
||||
*/
|
||||
private String title;
|
||||
|
||||
/**
|
||||
* 消息内容
|
||||
*/
|
||||
private String content;
|
||||
|
||||
/**
|
||||
* 消息类型:1-退款订单 2-新增订单
|
||||
*/
|
||||
private Integer type;
|
||||
|
||||
/**
|
||||
* 消息状态:0-未读 1-已读
|
||||
*/
|
||||
private Integer status;
|
||||
|
||||
/**
|
||||
* 阅读时间
|
||||
*/
|
||||
private Date readTime;
|
||||
|
||||
/**
|
||||
* 关联ID
|
||||
*/
|
||||
private String relatedId;
|
||||
|
||||
/**
|
||||
* 额外信息(JSON格式)
|
||||
*/
|
||||
private String extra;
|
||||
|
||||
/**
|
||||
* 接收用户ID
|
||||
*/
|
||||
private Long userId;
|
||||
|
||||
/**
|
||||
* 租户ID
|
||||
*/
|
||||
private String tenantId;
|
||||
}
|
||||
+36
@@ -0,0 +1,36 @@
|
||||
package com.central.order.service;
|
||||
|
||||
import com.central.common.model.PageResult;
|
||||
import com.central.common.model.Result;
|
||||
import com.central.common.service.ISuperService;
|
||||
import com.central.order.model.Message;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
public interface IMessageService extends ISuperService<Message> {
|
||||
|
||||
/**
|
||||
* 获取消息列表
|
||||
*/
|
||||
PageResult<Message> findMessages(Map<String, Object> params);
|
||||
|
||||
/**
|
||||
* 标记消息已读
|
||||
*/
|
||||
Result markAsRead(Long id);
|
||||
|
||||
/**
|
||||
* 标记所有消息已读
|
||||
*/
|
||||
Result markAllAsRead();
|
||||
|
||||
/**
|
||||
* 删除消息
|
||||
*/
|
||||
Result deleteMessage(Long id);
|
||||
|
||||
/**
|
||||
* 创建消息
|
||||
*/
|
||||
void createMessage(Message message);
|
||||
}
|
||||
+91
@@ -0,0 +1,91 @@
|
||||
package com.central.order.service.impl;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.central.common.context.LoginUserContextHolder;
|
||||
import com.central.common.context.TenantContextHolder;
|
||||
import com.central.common.model.LoginAppUser;
|
||||
import com.central.common.model.PageResult;
|
||||
import com.central.common.model.Result;
|
||||
import com.central.common.service.impl.SuperServiceImpl;
|
||||
import com.central.order.mapper.MessageMapper;
|
||||
import com.central.order.model.Message;
|
||||
import com.central.order.service.IMessageService;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.commons.collections4.MapUtils;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
@Slf4j
|
||||
@Service
|
||||
@RequiredArgsConstructor
|
||||
public class MessageServiceImpl extends SuperServiceImpl<MessageMapper, Message> implements IMessageService {
|
||||
|
||||
@Override
|
||||
public PageResult<Message> findMessages(Map<String, Object> params) {
|
||||
LoginAppUser user = LoginUserContextHolder.getUser();
|
||||
|
||||
Page<Message> page = new Page<>(MapUtils.getInteger(params, "page", 1),
|
||||
MapUtils.getInteger(params, "limit", 10));
|
||||
|
||||
List<Message> list = baseMapper.findList(
|
||||
page,
|
||||
user.getId(),
|
||||
TenantContextHolder.getTenant(),
|
||||
params // 作为查询条件传入
|
||||
);
|
||||
|
||||
return PageResult.<Message>builder()
|
||||
.data(list)
|
||||
.resp_code(0)
|
||||
.count(page.getTotal())
|
||||
.build();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Result markAsRead(Long id) {
|
||||
try {
|
||||
LoginAppUser user = LoginUserContextHolder.getUser();
|
||||
int count = baseMapper.markAsRead(id, user.getId(), new Date());
|
||||
return count > 0 ? Result.succeed("标记成功") : Result.failed("标记失败");
|
||||
} catch (Exception e) {
|
||||
log.error("标记消息已读失败", e);
|
||||
return Result.failed("标记失败");
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Result markAllAsRead() {
|
||||
try {
|
||||
LoginAppUser user = LoginUserContextHolder.getUser();
|
||||
int count = baseMapper.markAllAsRead(user.getId(), new Date());
|
||||
return count > 0 ? Result.succeed("标记成功") : Result.failed("标记失败");
|
||||
} catch (Exception e) {
|
||||
log.error("标记所有消息已读失败", e);
|
||||
return Result.failed("标记失败");
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Result deleteMessage(Long id) {
|
||||
try {
|
||||
LoginAppUser user = LoginUserContextHolder.getUser();
|
||||
boolean success = removeById(id);
|
||||
return success ? Result.succeed("删除成功") : Result.failed("删除失败");
|
||||
} catch (Exception e) {
|
||||
log.error("删除消息失败", e);
|
||||
return Result.failed("删除失败");
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void createMessage(Message message) {
|
||||
message.setStatus(0);
|
||||
message.setCreateTime(new Date());
|
||||
message.setTenantId(TenantContextHolder.getTenant());
|
||||
save(message);
|
||||
}
|
||||
}
|
||||
+38
-9
@@ -6,18 +6,21 @@ import com.central.common.lock.DistributedLock;
|
||||
import com.central.common.model.PageResult;
|
||||
import com.central.common.service.impl.SuperServiceImpl;
|
||||
import com.central.order.enums.OrderStatus;
|
||||
import com.central.order.event.OrderStatusChangeEvent;
|
||||
import com.central.order.mapper.OrderFileMapper;
|
||||
import com.central.order.mapper.OrderMapper;
|
||||
import com.central.order.mapper.TourismMapper;
|
||||
import com.central.order.model.Order;
|
||||
import com.central.order.model.OrderFile;
|
||||
import com.central.order.model.OrderRanking;
|
||||
import com.central.order.service.IMessageService;
|
||||
import com.central.order.service.IOrderService;
|
||||
import com.central.order.util.DateUtils;
|
||||
import com.wechat.pay.java.service.payments.jsapi.JsapiServiceExtension;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.commons.collections4.MapUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.context.ApplicationEventPublisher;
|
||||
import org.springframework.context.annotation.Primary;
|
||||
import org.springframework.scheduling.annotation.Async;
|
||||
import org.springframework.stereotype.Service;
|
||||
@@ -60,6 +63,12 @@ public class OrderServiceImpl extends SuperServiceImpl<OrderMapper, Order> imple
|
||||
@Autowired
|
||||
private OrderFileMapper orderFileMapper;
|
||||
|
||||
@Autowired
|
||||
private ApplicationEventPublisher eventPublisher;
|
||||
|
||||
@Autowired
|
||||
private IMessageService messageService;
|
||||
|
||||
/**
|
||||
* 列表
|
||||
* @param params
|
||||
@@ -72,7 +81,7 @@ public class OrderServiceImpl extends SuperServiceImpl<OrderMapper, Order> imple
|
||||
return PageResult.<Order>builder().data(list).resp_code(0).count(page.getTotal()).build();
|
||||
}
|
||||
|
||||
// 创建订单,初始状态为“待支付”
|
||||
// 创建订单,初始状态为"待支付"
|
||||
@Override
|
||||
public boolean createOrder(Order order) {
|
||||
order.setOrderStatus(OrderStatus.UNPAID.getId());
|
||||
@@ -130,12 +139,12 @@ public class OrderServiceImpl extends SuperServiceImpl<OrderMapper, Order> imple
|
||||
List<Order> queueOrders = getOrdersInQueue();
|
||||
for (Order order : queueOrders) {
|
||||
executorService.submit(() -> {
|
||||
//TODO
|
||||
// 这里假设已经有逻辑判断前面的用户是否消费完成,此处简化处理
|
||||
// 通知用户进行消费操作(实际可能是推送消息等方式,这里仅打印示例)
|
||||
log.debug("通知用户 " + order.getUserId() + " 进行消费操作,订单编号:" + order.getId());
|
||||
// 可以在这里更新订单状态为“已消费”等后续操作,根据实际业务完善
|
||||
|
||||
try {
|
||||
order.setOrderStatus(OrderStatus.DOING.getId());
|
||||
updateOrder(order); // 这里会触发事件发布
|
||||
} catch (Exception e) {
|
||||
log.error("处理队列订单失败", e);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -148,9 +157,29 @@ public class OrderServiceImpl extends SuperServiceImpl<OrderMapper, Order> imple
|
||||
@Override
|
||||
public boolean updateOrder(Order order) {
|
||||
try {
|
||||
return super.saveOrUpdateIdempotency(order, lock
|
||||
, ORDER_LOCK+order.getOrderNo(), new QueryWrapper<Order>().eq("order_no", order.getOrderNo()), "订单已存在");
|
||||
// 获取原订单信息
|
||||
Order oldOrder = getById(order.getId());
|
||||
boolean result = super.saveOrUpdateIdempotency(order, lock,
|
||||
ORDER_LOCK + order.getOrderNo(),
|
||||
new QueryWrapper<Order>().eq("order_no", order.getOrderNo()),
|
||||
"订单已存在");
|
||||
|
||||
// 如果更新成功且状态发生变化,发布事件
|
||||
if (result && !order.getOrderStatus().equals(oldOrder.getOrderStatus())) {
|
||||
OrderStatusChangeEvent event = new OrderStatusChangeEvent(
|
||||
this,
|
||||
order.getOrderNo(),
|
||||
oldOrder.getOrderStatus(),
|
||||
order.getOrderStatus(),
|
||||
order.getUserId(),
|
||||
String.format("订单金额:%.2f元",
|
||||
Double.parseDouble(order.getOrderAmount()) / 100)
|
||||
);
|
||||
eventPublisher.publishEvent(event);
|
||||
}
|
||||
return result;
|
||||
} catch (Exception e) {
|
||||
log.error("更新订单失败", e);
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,10 +4,10 @@ server:
|
||||
spring:
|
||||
application:
|
||||
name: order-center
|
||||
cloud:
|
||||
nacos:
|
||||
discovery:
|
||||
ip: 81.70.164.178
|
||||
# cloud:
|
||||
# nacos:
|
||||
# discovery:
|
||||
# ip: 81.70.164.178
|
||||
# cloud:
|
||||
# nacos:
|
||||
# discovery:
|
||||
|
||||
@@ -0,0 +1,128 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
|
||||
<mapper namespace="com.central.order.mapper.MessageMapper">
|
||||
<sql id="Base_Column_List">
|
||||
id, title, content, type, status, create_time, read_time,
|
||||
related_id, extra, user_id, tenant_id
|
||||
</sql>
|
||||
|
||||
<!-- 消息列表查询 -->
|
||||
<select id="findList" resultType="com.central.order.model.Message">
|
||||
SELECT
|
||||
<include refid="Base_Column_List"/>
|
||||
FROM sys_message
|
||||
<where>
|
||||
<if test="userId != null">
|
||||
AND user_id = #{userId}
|
||||
</if>
|
||||
<if test="tenantId != null and tenantId != ''">
|
||||
AND tenant_id = #{tenantId}
|
||||
</if>
|
||||
<!-- 使用params.前缀访问Map中的值 -->
|
||||
<if test="params != null">
|
||||
<if test="params.type != null">
|
||||
AND type = #{params.type}
|
||||
</if>
|
||||
<if test="params.status != null">
|
||||
AND status = #{params.status}
|
||||
</if>
|
||||
<if test="params.startTime != null and params.startTime != ''">
|
||||
AND create_time >= #{params.startTime}
|
||||
</if>
|
||||
<if test="params.endTime != null and params.endTime != ''">
|
||||
AND create_time <= #{params.endTime}
|
||||
</if>
|
||||
<if test="params.searchKey != null and params.searchKey != ''">
|
||||
AND (
|
||||
title LIKE CONCAT('%', #{params.searchKey}, '%')
|
||||
OR content LIKE CONCAT('%', #{params.searchKey}, '%')
|
||||
)
|
||||
</if>
|
||||
</if>
|
||||
</where>
|
||||
ORDER BY create_time DESC
|
||||
</select>
|
||||
|
||||
<!-- 批量插入消息 -->
|
||||
<insert id="batchInsert" parameterType="java.util.List">
|
||||
INSERT INTO sys_message (
|
||||
title, content, type, status, create_time,
|
||||
related_id, extra, user_id, tenant_id
|
||||
)
|
||||
VALUES
|
||||
<foreach collection="list" item="item" separator=",">
|
||||
(
|
||||
#{item.title},
|
||||
#{item.content},
|
||||
#{item.type},
|
||||
#{item.status},
|
||||
#{item.createTime},
|
||||
#{item.relatedId},
|
||||
#{item.extra},
|
||||
#{item.userId},
|
||||
#{item.tenantId}
|
||||
)
|
||||
</foreach>
|
||||
</insert>
|
||||
|
||||
<!-- 批量更新消息状态 -->
|
||||
<update id="batchUpdateStatus">
|
||||
UPDATE sys_message
|
||||
SET status = #{status},
|
||||
read_time = #{readTime}
|
||||
WHERE id IN
|
||||
<foreach collection="ids" item="id" open="(" separator="," close=")">
|
||||
#{id}
|
||||
</foreach>
|
||||
AND user_id = #{userId}
|
||||
</update>
|
||||
|
||||
<!-- 获取用户未读消息数量 -->
|
||||
<select id="getUnreadCount" resultType="int">
|
||||
SELECT COUNT(1)
|
||||
FROM sys_message
|
||||
WHERE user_id = #{userId}
|
||||
AND tenant_id = #{tenantId}
|
||||
AND status = 0
|
||||
</select>
|
||||
|
||||
<!-- 按类型获取用户未读消息数量 -->
|
||||
<select id="getUnreadCountByType" resultType="java.util.Map">
|
||||
SELECT
|
||||
type,
|
||||
COUNT(1) as count
|
||||
FROM sys_message
|
||||
WHERE user_id = #{userId}
|
||||
AND tenant_id = #{tenantId}
|
||||
AND status = 0
|
||||
GROUP BY type
|
||||
</select>
|
||||
|
||||
<!-- 删除指定时间之前的已读消息 -->
|
||||
<delete id="deleteReadMessages">
|
||||
DELETE FROM sys_message
|
||||
WHERE status = 1
|
||||
AND read_time < #{beforeTime}
|
||||
<if test="userId != null">
|
||||
AND user_id = #{userId}
|
||||
</if>
|
||||
<if test="tenantId != null and tenantId != ''">
|
||||
AND tenant_id = #{tenantId}
|
||||
</if>
|
||||
</delete>
|
||||
|
||||
<!-- 根据关联ID查询消息 -->
|
||||
<select id="findByRelatedId" resultType="com.central.order.model.Message">
|
||||
SELECT
|
||||
<include refid="Base_Column_List"/>
|
||||
FROM sys_message
|
||||
WHERE related_id = #{relatedId}
|
||||
<if test="userId != null">
|
||||
AND user_id = #{userId}
|
||||
</if>
|
||||
<if test="tenantId != null and tenantId != ''">
|
||||
AND tenant_id = #{tenantId}
|
||||
</if>
|
||||
</select>
|
||||
</mapper>
|
||||
@@ -24,10 +24,6 @@
|
||||
path: '/system/role.html',
|
||||
component: './system/Role',
|
||||
},
|
||||
{
|
||||
path: '/system/tenant.html',
|
||||
component: './system/Tenant',
|
||||
},
|
||||
{
|
||||
path: '/system/tokens.html',
|
||||
component: './system/Token',
|
||||
@@ -64,6 +60,15 @@
|
||||
},
|
||||
]
|
||||
},
|
||||
{
|
||||
path: '/message',
|
||||
routes: [
|
||||
{
|
||||
path: '/message/message.html',
|
||||
component: './message/index',
|
||||
}
|
||||
],
|
||||
},
|
||||
{
|
||||
path: '/orders',
|
||||
routes: [
|
||||
|
||||
@@ -1,14 +1,16 @@
|
||||
import { GithubOutlined, QuestionCircleOutlined } from '@ant-design/icons';
|
||||
import { Space } from 'antd';
|
||||
import { GithubOutlined, QuestionCircleOutlined, BellOutlined } from '@ant-design/icons';
|
||||
import { Space, Badge } from 'antd';
|
||||
import React from 'react';
|
||||
import { useModel } from 'umi';
|
||||
import AvatarDropdown from './AvatarDropdown';
|
||||
import styles from './index.less';
|
||||
import { history } from 'umi';
|
||||
|
||||
export type SiderTheme = 'light' | 'dark';
|
||||
|
||||
const GlobalHeaderRight: React.FC = () => {
|
||||
const { initialState } = useModel('@@initialState');
|
||||
const { unreadCount } = useModel('useMessage');
|
||||
|
||||
if (!initialState || !initialState.settings) {
|
||||
return null;
|
||||
@@ -61,6 +63,14 @@ const GlobalHeaderRight: React.FC = () => {
|
||||
>
|
||||
<GithubOutlined />
|
||||
</span>
|
||||
<span
|
||||
className={styles.action}
|
||||
onClick={() => history.push('/message')}
|
||||
>
|
||||
<Badge count={unreadCount}>
|
||||
<BellOutlined className={styles.icon} />
|
||||
</Badge>
|
||||
</span>
|
||||
<AvatarDropdown menu />
|
||||
</Space>
|
||||
);
|
||||
|
||||
@@ -0,0 +1,27 @@
|
||||
import { useState, useEffect } from 'react';
|
||||
import { getMessages } from '@/services/message/api';
|
||||
|
||||
export default () => {
|
||||
const [unreadCount, setUnreadCount] = useState<number>(0);
|
||||
|
||||
const fetchUnreadCount = async () => {
|
||||
try {
|
||||
const response = await getMessages({ status: 0, pageSize: 1 });
|
||||
setUnreadCount(response.total || 0);
|
||||
} catch (error) {
|
||||
console.error('获取未读消息数量失败:', error);
|
||||
}
|
||||
};
|
||||
|
||||
useEffect(() => {
|
||||
fetchUnreadCount();
|
||||
// 设置定时刷新
|
||||
const timer = setInterval(fetchUnreadCount, 60000); // 每分钟刷新一次
|
||||
return () => clearInterval(timer);
|
||||
}, []);
|
||||
|
||||
return {
|
||||
unreadCount,
|
||||
refreshUnreadCount: fetchUnreadCount,
|
||||
};
|
||||
};
|
||||
@@ -0,0 +1,27 @@
|
||||
.unreadTitle {
|
||||
font-weight: 500;
|
||||
color: #1890ff;
|
||||
position: relative;
|
||||
|
||||
&::before {
|
||||
content: '';
|
||||
position: absolute;
|
||||
left: -12px;
|
||||
top: 50%;
|
||||
transform: translateY(-50%);
|
||||
width: 6px;
|
||||
height: 6px;
|
||||
border-radius: 50%;
|
||||
background-color: #f5222d;
|
||||
}
|
||||
}
|
||||
|
||||
.messageContent {
|
||||
color: rgba(0, 0, 0, 0.65);
|
||||
margin: 0;
|
||||
}
|
||||
|
||||
.messageTime {
|
||||
color: rgba(0, 0, 0, 0.45);
|
||||
font-size: 12px;
|
||||
}
|
||||
@@ -0,0 +1,165 @@
|
||||
import { getMessages, markAsRead, markAllAsRead, deleteMessage } from '@/services/message/api';
|
||||
import type { ActionType, ProColumns } from '@ant-design/pro-components';
|
||||
import {
|
||||
PageContainer,
|
||||
ProTable,
|
||||
ProFormSelect,
|
||||
} from '@ant-design/pro-components';
|
||||
import { Button, message, Tag, Space, Modal, Typography } from 'antd';
|
||||
import React, { useRef, useState } from 'react';
|
||||
import { history } from 'umi';
|
||||
import styles from './index.less';
|
||||
|
||||
const { Link, Paragraph } = Typography;
|
||||
|
||||
// 消息类型配置
|
||||
const MESSAGE_TYPE = {
|
||||
1: { text: '退款订单', color: 'warning' },
|
||||
2: { text: '新增订单', color: 'success' },
|
||||
3: { text: '系统通知', color: 'info' },
|
||||
};
|
||||
|
||||
// 消息状态配置
|
||||
const MESSAGE_STATUS = {
|
||||
0: { text: '未读', color: 'processing' },
|
||||
1: { text: '已读', color: 'default' },
|
||||
};
|
||||
|
||||
const MessageList: React.FC = () => {
|
||||
const actionRef = useRef<ActionType>();
|
||||
const [selectedRows, setSelectedRows] = useState<MESSAGE.Message[]>([]);
|
||||
|
||||
// 处理消息点击
|
||||
const handleMessageClick = async (record: MESSAGE.Message) => {
|
||||
if (record.status === 0) {
|
||||
await markAsRead(record.id);
|
||||
actionRef.current?.reload();
|
||||
}
|
||||
|
||||
// 根据消息类型跳转到相应页面
|
||||
if (record.type === 1 && record.relatedId) {
|
||||
history.push(`/orders/refund?id=${record.relatedId}`);
|
||||
} else if (record.type === 2 && record.relatedId) {
|
||||
history.push(`/orders/order?id=${record.relatedId}`);
|
||||
}
|
||||
};
|
||||
|
||||
// 标记所有已读
|
||||
const handleMarkAllRead = async () => {
|
||||
try {
|
||||
await markAllAsRead();
|
||||
message.success('已全部标记为已读');
|
||||
actionRef.current?.reload();
|
||||
} catch (error) {
|
||||
message.error('操作失败');
|
||||
}
|
||||
};
|
||||
|
||||
const columns: ProColumns<MESSAGE.Message>[] = [
|
||||
{
|
||||
title: '消息类型',
|
||||
dataIndex: 'type',
|
||||
width: 100,
|
||||
render: (type) => {
|
||||
const typeInfo = MESSAGE_TYPE[type as keyof typeof MESSAGE_TYPE] ||
|
||||
{ text: '未知类型', color: 'default' };
|
||||
return <Tag color={typeInfo.color}>{typeInfo.text}</Tag>;
|
||||
},
|
||||
valueEnum: Object.entries(MESSAGE_TYPE).reduce((acc, [key, value]) => {
|
||||
acc[key] = { text: value.text };
|
||||
return acc;
|
||||
}, {} as Record<string, { text: string }>),
|
||||
},
|
||||
{
|
||||
title: '标题',
|
||||
dataIndex: 'title',
|
||||
render: (_, record) => (
|
||||
<Link
|
||||
className={record.status === 0 ? styles.unreadTitle : ''}
|
||||
onClick={() => handleMessageClick(record)}
|
||||
>
|
||||
{record.title}
|
||||
</Link>
|
||||
),
|
||||
},
|
||||
{
|
||||
title: '内容',
|
||||
dataIndex: 'content',
|
||||
ellipsis: true,
|
||||
width: 300,
|
||||
},
|
||||
{
|
||||
title: '状态',
|
||||
dataIndex: 'status',
|
||||
width: 80,
|
||||
render: (status) => {
|
||||
const statusInfo = MESSAGE_STATUS[status as keyof typeof MESSAGE_STATUS];
|
||||
return <Tag color={statusInfo.color}>{statusInfo.text}</Tag>;
|
||||
},
|
||||
},
|
||||
{
|
||||
title: '时间',
|
||||
dataIndex: 'createTime',
|
||||
valueType: 'dateTime',
|
||||
width: 180,
|
||||
sorter: true,
|
||||
},
|
||||
{
|
||||
title: '操作',
|
||||
key: 'action',
|
||||
width: 120,
|
||||
render: (_, record) => (
|
||||
<Space>
|
||||
{record.status === 0 && (
|
||||
<Link onClick={() => handleMessageClick(record)}>查看</Link>
|
||||
)}
|
||||
<Link
|
||||
onClick={() => {
|
||||
Modal.confirm({
|
||||
title: '确认删除该消息?',
|
||||
onOk: async () => {
|
||||
await deleteMessage(record.id);
|
||||
actionRef.current?.reload();
|
||||
message.success('删除成功');
|
||||
},
|
||||
});
|
||||
}}
|
||||
>
|
||||
删除
|
||||
</Link>
|
||||
</Space>
|
||||
),
|
||||
},
|
||||
];
|
||||
|
||||
return (
|
||||
<PageContainer>
|
||||
<ProTable<MESSAGE.Message>
|
||||
headerTitle="消息列表"
|
||||
actionRef={actionRef}
|
||||
rowKey="id"
|
||||
search={{
|
||||
labelWidth: 120,
|
||||
}}
|
||||
toolBarRender={() => [
|
||||
<Button key="markAllRead" onClick={handleMarkAllRead}>
|
||||
全部标记已读
|
||||
</Button>,
|
||||
]}
|
||||
request={getMessages}
|
||||
columns={columns}
|
||||
rowSelection={{
|
||||
onChange: (_, selectedRows) => {
|
||||
setSelectedRows(selectedRows);
|
||||
},
|
||||
}}
|
||||
pagination={{
|
||||
showQuickJumper: true,
|
||||
showSizeChanger: true,
|
||||
}}
|
||||
/>
|
||||
</PageContainer>
|
||||
);
|
||||
};
|
||||
|
||||
export default MessageList;
|
||||
@@ -1,59 +0,0 @@
|
||||
import {
|
||||
ModalForm,
|
||||
ProForm,
|
||||
ProFormText,
|
||||
ProFormTextArea,
|
||||
} from '@ant-design/pro-components';
|
||||
import React from 'react';
|
||||
|
||||
interface CreateFormProps {
|
||||
visible: boolean;
|
||||
onVisibleChange: (visible: boolean) => void;
|
||||
onSubmit: (values: SYSTEM.Tenant) => Promise<void>;
|
||||
}
|
||||
|
||||
const CreateForm: React.FC<CreateFormProps> = (props) => {
|
||||
return (
|
||||
<ModalForm
|
||||
title="新增租户"
|
||||
visible={props.visible}
|
||||
onVisibleChange={props.onVisibleChange}
|
||||
onFinish={props.onSubmit}
|
||||
modalProps={{ destroyOnClose: true }}
|
||||
>
|
||||
<ProForm.Group>
|
||||
<ProFormText
|
||||
name="name"
|
||||
label="租户名称"
|
||||
rules={[{ required: true, message: '请输入租户名称' }]}
|
||||
width="md"
|
||||
/>
|
||||
<ProFormText
|
||||
name="code"
|
||||
label="租户编码"
|
||||
rules={[{ required: true, message: '请输入租户编码' }]}
|
||||
width="md"
|
||||
/>
|
||||
<ProFormText
|
||||
name="contactPerson"
|
||||
label="联系人"
|
||||
rules={[{ required: true, message: '请输入联系人' }]}
|
||||
width="md"
|
||||
/>
|
||||
<ProFormText
|
||||
name="contactPhone"
|
||||
label="联系电话"
|
||||
rules={[{ required: true, message: '请输入联系电话' }]}
|
||||
width="md"
|
||||
/>
|
||||
<ProFormTextArea
|
||||
name="address"
|
||||
label="地址"
|
||||
width="md"
|
||||
/>
|
||||
</ProForm.Group>
|
||||
</ModalForm>
|
||||
);
|
||||
};
|
||||
|
||||
export default CreateForm;
|
||||
@@ -1,61 +0,0 @@
|
||||
import {
|
||||
ModalForm,
|
||||
ProForm,
|
||||
ProFormText,
|
||||
ProFormTextArea,
|
||||
} from '@ant-design/pro-components';
|
||||
import React from 'react';
|
||||
|
||||
interface UpdateFormProps {
|
||||
visible: boolean;
|
||||
onVisibleChange: (visible: boolean) => void;
|
||||
onSubmit: (values: SYSTEM.Tenant) => Promise<void>;
|
||||
values?: SYSTEM.Tenant;
|
||||
}
|
||||
|
||||
const UpdateForm: React.FC<UpdateFormProps> = (props) => {
|
||||
return (
|
||||
<ModalForm
|
||||
title="修改租户"
|
||||
visible={props.visible}
|
||||
onVisibleChange={props.onVisibleChange}
|
||||
onFinish={props.onSubmit}
|
||||
initialValues={props.values}
|
||||
modalProps={{ destroyOnClose: true }}
|
||||
>
|
||||
<ProForm.Group>
|
||||
<ProFormText
|
||||
name="name"
|
||||
label="租户名称"
|
||||
rules={[{ required: true, message: '请输入租户名称' }]}
|
||||
width="md"
|
||||
/>
|
||||
<ProFormText
|
||||
name="code"
|
||||
label="租户编码"
|
||||
rules={[{ required: true, message: '请输入租户编码' }]}
|
||||
width="md"
|
||||
/>
|
||||
<ProFormText
|
||||
name="contactPerson"
|
||||
label="联系人"
|
||||
rules={[{ required: true, message: '请输入联系人' }]}
|
||||
width="md"
|
||||
/>
|
||||
<ProFormText
|
||||
name="contactPhone"
|
||||
label="联系电话"
|
||||
rules={[{ required: true, message: '请输入联系电话' }]}
|
||||
width="md"
|
||||
/>
|
||||
<ProFormTextArea
|
||||
name="address"
|
||||
label="地址"
|
||||
width="md"
|
||||
/>
|
||||
</ProForm.Group>
|
||||
</ModalForm>
|
||||
);
|
||||
};
|
||||
|
||||
export default UpdateForm;
|
||||
@@ -1,213 +0,0 @@
|
||||
import {
|
||||
getTenantList,
|
||||
saveOrUpdateTenant,
|
||||
deleteTenant,
|
||||
updateTenantStatus
|
||||
} from '@/services/system/api';
|
||||
import { PlusOutlined } from '@ant-design/icons';
|
||||
import type { ActionType, ProColumns } from '@ant-design/pro-components';
|
||||
import { PageContainer, ProFormText, ProTable, QueryFilter } from '@ant-design/pro-components';
|
||||
import { Typography, message, Popconfirm, Button, Space, Switch } from 'antd';
|
||||
import React, { useRef, useState } from 'react';
|
||||
import CreateForm from './components/CreateForm';
|
||||
import UpdateForm from './components/UpdateForm';
|
||||
|
||||
const { Link } = Typography;
|
||||
|
||||
// 统一的错误处理
|
||||
const handleApiRequest = async (
|
||||
apiCall: () => Promise<any>,
|
||||
loadingMessage: string,
|
||||
successMessage: string,
|
||||
) => {
|
||||
const hide = message.loading(loadingMessage);
|
||||
try {
|
||||
const result = await apiCall();
|
||||
hide();
|
||||
if (result.code === 0) {
|
||||
message.success(successMessage);
|
||||
return true;
|
||||
}
|
||||
message.error(result.message || '操作失败');
|
||||
return false;
|
||||
} catch (error) {
|
||||
hide();
|
||||
message.error('操作失败');
|
||||
return false;
|
||||
}
|
||||
};
|
||||
|
||||
const TenantList: React.FC = () => {
|
||||
const [params, setParams] = useState<Record<string, string | number>>({});
|
||||
const actionRef = useRef<ActionType>();
|
||||
const [createModalVisible, handleCreateModalVisible] = useState<boolean>(false);
|
||||
const [updateModalVisible, handleUpdateModalVisible] = useState<boolean>(false);
|
||||
const [currentRow, setCurrentRow] = useState<any>();
|
||||
|
||||
// 处理状态切换
|
||||
const handleStatusChange = async (checked: boolean, record: SYSTEM.Tenant) => {
|
||||
const success = await handleApiRequest(
|
||||
() => updateTenantStatus(record.id!, checked ? 1 : 0),
|
||||
'正在更新状态',
|
||||
'状态更新成功'
|
||||
);
|
||||
if (success && actionRef.current) {
|
||||
actionRef.current.reload();
|
||||
}
|
||||
};
|
||||
|
||||
const columns: ProColumns<SYSTEM.Tenant>[] = [
|
||||
{
|
||||
dataIndex: 'index',
|
||||
valueType: 'indexBorder',
|
||||
width: 48,
|
||||
},
|
||||
{
|
||||
title: '租户名称',
|
||||
dataIndex: 'name',
|
||||
ellipsis: true,
|
||||
},
|
||||
{
|
||||
title: '租户编码',
|
||||
dataIndex: 'code',
|
||||
ellipsis: true,
|
||||
},
|
||||
{
|
||||
title: '联系人',
|
||||
dataIndex: 'contactPerson',
|
||||
},
|
||||
{
|
||||
title: '联系电话',
|
||||
dataIndex: 'contactPhone',
|
||||
},
|
||||
{
|
||||
title: '地址',
|
||||
dataIndex: 'address',
|
||||
ellipsis: true,
|
||||
},
|
||||
{
|
||||
title: '状态',
|
||||
dataIndex: 'status',
|
||||
width: 100,
|
||||
render: (_, record) => (
|
||||
<Switch
|
||||
checked={record.status === 1}
|
||||
onChange={(checked) => handleStatusChange(checked, record)}
|
||||
/>
|
||||
),
|
||||
},
|
||||
{
|
||||
title: '创建时间',
|
||||
dataIndex: 'createTime',
|
||||
valueType: 'dateTime',
|
||||
width: 180,
|
||||
},
|
||||
{
|
||||
title: '操作',
|
||||
key: 'action',
|
||||
fixed: 'right',
|
||||
width: 180,
|
||||
render: (_, record) => (
|
||||
<Space>
|
||||
<Link
|
||||
onClick={() => {
|
||||
setCurrentRow(record);
|
||||
handleUpdateModalVisible(true);
|
||||
}}
|
||||
>
|
||||
修改
|
||||
</Link>
|
||||
<Popconfirm
|
||||
title={`确认删除租户[${record.name}]?`}
|
||||
onConfirm={async () => {
|
||||
const success = await handleApiRequest(
|
||||
() => deleteTenant(record.id!),
|
||||
'正在删除',
|
||||
'删除成功'
|
||||
);
|
||||
if (success && actionRef.current) {
|
||||
actionRef.current.reload();
|
||||
}
|
||||
}}
|
||||
>
|
||||
<Link>删除</Link>
|
||||
</Popconfirm>
|
||||
</Space>
|
||||
),
|
||||
},
|
||||
];
|
||||
|
||||
return (
|
||||
<PageContainer header={{ title: '租户管理' }}>
|
||||
<QueryFilter
|
||||
defaultCollapsed
|
||||
split
|
||||
span={6}
|
||||
className="query-filter"
|
||||
onFinish={async (values) => setParams(values)}
|
||||
>
|
||||
<ProFormText name="name" label="租户名称" placeholder="请输入租户名称" />
|
||||
<ProFormText name="code" label="租户编码" placeholder="请输入租户编码" />
|
||||
</QueryFilter>
|
||||
|
||||
<ProTable
|
||||
rowKey="id"
|
||||
headerTitle="租户列表"
|
||||
actionRef={actionRef}
|
||||
request={getTenantList}
|
||||
columns={columns}
|
||||
search={false}
|
||||
params={params}
|
||||
pagination={{
|
||||
showSizeChanger: true,
|
||||
showQuickJumper: true,
|
||||
}}
|
||||
toolBarRender={() => [
|
||||
<Button
|
||||
key="add"
|
||||
type="primary"
|
||||
onClick={() => handleCreateModalVisible(true)}
|
||||
>
|
||||
<PlusOutlined /> 新增租户
|
||||
</Button>,
|
||||
]}
|
||||
/>
|
||||
|
||||
<CreateForm
|
||||
visible={createModalVisible}
|
||||
onVisibleChange={handleCreateModalVisible}
|
||||
onSubmit={async (values) => {
|
||||
const success = await handleApiRequest(
|
||||
() => saveOrUpdateTenant(values),
|
||||
'正在添加',
|
||||
'添加成功'
|
||||
);
|
||||
if (success) {
|
||||
handleCreateModalVisible(false);
|
||||
actionRef.current?.reload();
|
||||
}
|
||||
}}
|
||||
/>
|
||||
|
||||
<UpdateForm
|
||||
visible={updateModalVisible}
|
||||
onVisibleChange={handleUpdateModalVisible}
|
||||
values={currentRow}
|
||||
onSubmit={async (values) => {
|
||||
const success = await handleApiRequest(
|
||||
() => saveOrUpdateTenant({ ...currentRow, ...values }),
|
||||
'正在更新',
|
||||
'更新成功'
|
||||
);
|
||||
if (success) {
|
||||
handleUpdateModalVisible(false);
|
||||
setCurrentRow(undefined);
|
||||
actionRef.current?.reload();
|
||||
}
|
||||
}}
|
||||
/>
|
||||
</PageContainer>
|
||||
);
|
||||
};
|
||||
|
||||
export default TenantList;
|
||||
@@ -0,0 +1,34 @@
|
||||
import { request } from 'umi';
|
||||
|
||||
/** 获取消息列表 */
|
||||
export async function getMessages(params: any) {
|
||||
return request<API.Response<MESSAGE.Message[]>>('/api-order/messages', {
|
||||
method: 'GET',
|
||||
params: {
|
||||
page: params.current,
|
||||
limit: params.pageSize,
|
||||
...params
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
/** 标记消息已读 */
|
||||
export async function markAsRead(id: number) {
|
||||
return request<API.Response<any>>(`/api-order/messages/${id}/read`, {
|
||||
method: 'PUT',
|
||||
});
|
||||
}
|
||||
|
||||
/** 标记所有消息已读 */
|
||||
export async function markAllAsRead() {
|
||||
return request<API.Response<any>>('/api-order/messages/read/all', {
|
||||
method: 'PUT',
|
||||
});
|
||||
}
|
||||
|
||||
/** 删除消息 */
|
||||
export async function deleteMessage(id: number) {
|
||||
return request<API.Response<any>>(`/api-order/messages/${id}`, {
|
||||
method: 'DELETE',
|
||||
});
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
declare namespace MESSAGE {
|
||||
interface Message {
|
||||
id: number;
|
||||
title: string;
|
||||
content: string;
|
||||
type: number; // 消息类型:1-退款订单 2-新增订单 等
|
||||
status: number; // 消息状态:0-未读 1-已读
|
||||
createTime: string;
|
||||
readTime?: string;
|
||||
relatedId?: string | number; // 关联ID(如订单ID)
|
||||
extra?: any; // 额外信息
|
||||
}
|
||||
}
|
||||
@@ -248,41 +248,3 @@ export async function deleteToken(token: string) {
|
||||
return result;
|
||||
}
|
||||
|
||||
// 获取租户列表
|
||||
export async function getTenantList(params?: { [key: string]: string | number }) {
|
||||
const { current, pageSize, ...rest } = params ?? {};
|
||||
const result = await request<SYSTEM.Page<SYSTEM.Tenant>>('/api-user/tenant/list', {
|
||||
method: 'GET',
|
||||
params: { page: current, limit: pageSize, ...rest },
|
||||
});
|
||||
return { data: result.data, total: result.count };
|
||||
}
|
||||
|
||||
// 获取租户详情
|
||||
export async function getTenantDetail(id: string) {
|
||||
return request<API.Result<SYSTEM.Tenant>>(`/api-user/tenant/${id}`, {
|
||||
method: 'GET',
|
||||
});
|
||||
}
|
||||
|
||||
// 保存或更新租户
|
||||
export async function saveOrUpdateTenant(data: SYSTEM.Tenant): Promise<API.Result<SYSTEM.Tenant>> {
|
||||
return request<API.Result<SYSTEM.Tenant>>('/api-user/tenant/save', {
|
||||
method: 'POST',
|
||||
data,
|
||||
});
|
||||
}
|
||||
|
||||
// 删除租户
|
||||
export async function deleteTenant(id: string) {
|
||||
return request<API.Result<void>>(`/api-user/tenant/${id}`, {
|
||||
method: 'DELETE',
|
||||
});
|
||||
}
|
||||
|
||||
// 更新租户状态
|
||||
export async function updateTenantStatus(id: string, status: number) {
|
||||
return request<API.Result<void>>(`/api-user/tenant/status/${id}/${status}`, {
|
||||
method: 'PUT',
|
||||
});
|
||||
}
|
||||
|
||||
@@ -101,16 +101,4 @@ declare namespace SYSTEM {
|
||||
tenantId?: string;
|
||||
updateTime?: string;
|
||||
}
|
||||
|
||||
type Tenant = {
|
||||
id?: number;
|
||||
name: string; // 租户名称
|
||||
code: string; // 租户编码
|
||||
contactPerson: string; // 联系人
|
||||
contactPhone: string; // 联系电话
|
||||
address?: string; // 地址
|
||||
status: number; // 状态:0-禁用,1-启用
|
||||
createTime?: Date; // 创建时间
|
||||
updateTime?: Date; // 更新时间
|
||||
};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user