feat: add core schema and status enums

This commit is contained in:
王鹏
2026-07-07 15:10:03 +08:00
parent edffda2a84
commit 982f104f3d
13 changed files with 745 additions and 0 deletions

View File

@@ -0,0 +1,52 @@
package com.linhelp.common.api;
public class ApiResponse<T> {
private int code;
private String message;
private T data;
public ApiResponse() {
}
public ApiResponse(int code, String message, T data) {
this.code = code;
this.message = message;
this.data = data;
}
public static <T> ApiResponse<T> ok(T data) {
return new ApiResponse<T>(0, "ok", data);
}
public static ApiResponse<Void> ok() {
return new ApiResponse<Void>(0, "ok", null);
}
public static ApiResponse<Void> fail(int code, String message) {
return new ApiResponse<Void>(code, message, null);
}
public int getCode() {
return code;
}
public void setCode(int code) {
this.code = code;
}
public String getMessage() {
return message;
}
public void setMessage(String message) {
this.message = message;
}
public T getData() {
return data;
}
public void setData(T data) {
this.data = data;
}
}

View File

@@ -0,0 +1,52 @@
package com.linhelp.common.api;
import java.util.List;
public class PageResponse<T> {
private long total;
private long pageNo;
private long pageSize;
private List<T> records;
public PageResponse() {
}
public PageResponse(long total, long pageNo, long pageSize, List<T> records) {
this.total = total;
this.pageNo = pageNo;
this.pageSize = pageSize;
this.records = records;
}
public long getTotal() {
return total;
}
public void setTotal(long total) {
this.total = total;
}
public long getPageNo() {
return pageNo;
}
public void setPageNo(long pageNo) {
this.pageNo = pageNo;
}
public long getPageSize() {
return pageSize;
}
public void setPageSize(long pageSize) {
this.pageSize = pageSize;
}
public List<T> getRecords() {
return records;
}
public void setRecords(List<T> records) {
this.records = records;
}
}

View File

@@ -0,0 +1,7 @@
package com.linhelp.common.enums;
public enum DeliveryMethod {
IMMEDIATE,
SCHEDULED,
SELF_PICKUP
}

View File

@@ -0,0 +1,11 @@
package com.linhelp.common.enums;
public enum DeliveryTaskStatus {
ASSIGNED,
ACCEPTED,
DELIVERING,
DELIVERED,
EXCEPTION,
COMPLETED,
CANCELED
}

View File

@@ -0,0 +1,34 @@
package com.linhelp.common.enums;
import java.util.Collections;
import java.util.EnumMap;
import java.util.EnumSet;
import java.util.Map;
import java.util.Set;
public enum ExpressOrderStatus {
PENDING_CONFIRM,
PENDING_PICKUP,
PICKING_UP,
DELIVERING,
DELIVERED,
COMPLETED,
CANCELED;
private static final Map<ExpressOrderStatus, Set<ExpressOrderStatus>> TRANSITIONS;
static {
Map<ExpressOrderStatus, Set<ExpressOrderStatus>> transitions = new EnumMap<ExpressOrderStatus, Set<ExpressOrderStatus>>(ExpressOrderStatus.class);
transitions.put(PENDING_CONFIRM, EnumSet.of(PENDING_PICKUP, CANCELED));
transitions.put(PENDING_PICKUP, EnumSet.of(PICKING_UP, CANCELED));
transitions.put(PICKING_UP, EnumSet.of(DELIVERING, CANCELED));
transitions.put(DELIVERING, EnumSet.of(DELIVERED, CANCELED));
transitions.put(DELIVERED, EnumSet.of(COMPLETED));
TRANSITIONS = Collections.unmodifiableMap(transitions);
}
public boolean canMoveTo(ExpressOrderStatus target) {
Set<ExpressOrderStatus> targets = TRANSITIONS.get(this);
return targets != null && targets.contains(target);
}
}

View File

@@ -0,0 +1,34 @@
package com.linhelp.common.enums;
import java.util.Collections;
import java.util.EnumMap;
import java.util.EnumSet;
import java.util.Map;
import java.util.Set;
public enum GoodsOrderStatus {
PENDING_CONFIRM,
PREPARING,
PENDING_DELIVERY,
PENDING_PICKUP,
DELIVERING,
COMPLETED,
CANCELED;
private static final Map<GoodsOrderStatus, Set<GoodsOrderStatus>> TRANSITIONS;
static {
Map<GoodsOrderStatus, Set<GoodsOrderStatus>> transitions = new EnumMap<GoodsOrderStatus, Set<GoodsOrderStatus>>(GoodsOrderStatus.class);
transitions.put(PENDING_CONFIRM, EnumSet.of(PREPARING, CANCELED));
transitions.put(PREPARING, EnumSet.of(PENDING_DELIVERY, PENDING_PICKUP, CANCELED));
transitions.put(PENDING_DELIVERY, EnumSet.of(DELIVERING, CANCELED));
transitions.put(PENDING_PICKUP, EnumSet.of(COMPLETED, CANCELED));
transitions.put(DELIVERING, EnumSet.of(COMPLETED, CANCELED));
TRANSITIONS = Collections.unmodifiableMap(transitions);
}
public boolean canMoveTo(GoodsOrderStatus target) {
Set<GoodsOrderStatus> targets = TRANSITIONS.get(this);
return targets != null && targets.contains(target);
}
}

View File

@@ -0,0 +1,11 @@
package com.linhelp.common.enums;
public enum GroupBuyOrderStatus {
PENDING_CONFIRM,
CONFIRMED,
PENDING_DELIVERY,
PENDING_PICKUP,
DELIVERING,
COMPLETED,
CANCELED
}

View File

@@ -0,0 +1,8 @@
package com.linhelp.common.enums;
public enum OfflinePayStatus {
UNPAID,
PAID,
FREE,
EXCEPTION
}

View File

@@ -0,0 +1,9 @@
package com.linhelp.common.enums;
public enum SecondGoodsStatus {
PENDING_REVIEW,
PUBLISHED,
REJECTED,
OFF_SHELF,
SOLD
}

View File

@@ -0,0 +1,18 @@
package com.linhelp.common.exception;
public class BizException extends RuntimeException {
private final int code;
public BizException(String message) {
this(400, message);
}
public BizException(int code, String message) {
super(message);
this.code = code;
}
public int getCode() {
return code;
}
}

View File

@@ -0,0 +1,26 @@
package com.linhelp.common.exception;
import com.linhelp.common.api.ApiResponse;
import org.springframework.validation.BindException;
import org.springframework.web.bind.MethodArgumentNotValidException;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;
@RestControllerAdvice
public class GlobalExceptionHandler {
@ExceptionHandler(BizException.class)
public ApiResponse<Void> handleBizException(BizException exception) {
return ApiResponse.fail(exception.getCode(), exception.getMessage());
}
@ExceptionHandler({MethodArgumentNotValidException.class, BindException.class})
public ApiResponse<Void> handleValidationException(Exception exception) {
return ApiResponse.fail(422, "请求参数不正确");
}
@ExceptionHandler(Exception.class)
public ApiResponse<Void> handleException(Exception exception) {
return ApiResponse.fail(500, "系统繁忙,请稍后再试");
}
}