订单状态实现状态机机制

package com.honghan.trade.statemachine;

import com.honghan.common.core.enums.OrderStatus;
import com.honghan.trade.enums.PaymentMethod;

import java.util.HashMap;
import java.util.Map;

public class OrderStateMachine {
    private final Map<PaymentMethod, Map<OrderStatus, OrderStatus>> transitions;
    private OrderStatus currentStatus;

    public OrderStateMachine() {
        this.transitions = new HashMap<>();
        initializeTransitions();
    }

//这里规定好订单的每步状态流向
    private void initializeTransitions() {
        // 先款后货状态转换
        Map<OrderStatus, OrderStatus> prepayTransitions = new HashMap<>();
        prepayTransitions.put(OrderStatus.WAIT_TALK, OrderStatus.CONFIRMED);
        prepayTransitions.put(OrderStatus.CONFIRMED, OrderStatus.OFFLINE_CONFIRMED);
        prepayTransitions.put(OrderStatus.OFFLINE_CONFIRMED, OrderStatus.PAYED);
        prepayTransitions.put(OrderStatus.PAYED, OrderStatus.SENDING);
        prepayTransitions.put(OrderStatus.SENDING, OrderStatus.RECEIVE);
        prepayTransitions.put(OrderStatus.RECEIVE, OrderStatus.COUNT);
        transitions.put(PaymentMethod.PREPAY, prepayTransitions);

        // 先付订金后付尾款状态转换 / 多次付款状态转换
        Map<OrderStatus, OrderStatus> depositTransitions = new HashMap<>();
        depositTransitions.put(OrderStatus.WAIT_TALK, OrderStatus.CONFIRMED);
        depositTransitions.put(OrderStatus.CONFIRMED, OrderStatus.OFFLINE_CONFIRMED);
        depositTransitions.put(OrderStatus.OFFLINE_CONFIRMED, OrderStatus.PAYED);
        depositTransitions.put(OrderStatus.PAYED, OrderStatus.SENDING);
        depositTransitions.put(OrderStatus.SENDING, OrderStatus.RECEIVE);
        depositTransitions.put(OrderStatus.RECEIVE, OrderStatus.COUNT);
        transitions.put(PaymentMethod.DEPOSIT, depositTransitions);
        transitions.put(PaymentMethod.MULTI_PAY, depositTransitions);

        // 先货后款状态转换
        Map<OrderStatus, OrderStatus> postpayTransitions = new HashMap<>();
        postpayTransitions.put(OrderStatus.WAIT_TALK, OrderStatus.PARTIAL_SHIPMENTS);
        postpayTransitions.put(OrderStatus.PARTIAL_SHIPMENTS, OrderStatus.COUNT);
        transitions.put(PaymentMethod.POSTPAY, postpayTransitions);
    }

    public OrderStatus getNextStatus(OrderStatus currentStatus, PaymentMethod method) {
        return getNextStatus(currentStatus, method, false); // 如果没有找到对应的状态转换
    }

    public OrderStatus getNextStatus(OrderStatus currentStatus, PaymentMethod method, boolean userWantsToCompleteOrder) {
        if (currentStatus == OrderStatus.RECEIVE) {
            return userWantsToCompleteOrder ? OrderStatus.COUNT : OrderStatus.REFUNDING;
        }

        Map<OrderStatus, OrderStatus> methodTransitions = transitions.get(method);
        if (methodTransitions != null) {
            return methodTransitions.get(currentStatus);
        }
        return null; // 如果没有找到对应的状态转换
    }

    public OrderStatus getCurrentStatus() {
        return currentStatus;
    }

    public void setCurrentStatus(OrderStatus newStatus) {
        this.currentStatus = newStatus;
    }
}
package com.honghan.common.core.enums;

/**
 * @Description 平台通用订单枚举
 * @author °DJ°
 * @date 2023/3/17 18:22
 * @Motto ^V^你们都要好好的^V^
 */
public enum OrderStatus {


    CREATE(1, "待确认"),    //提货单、3发货单,4退货单
    CONFIRMED(2, "待付款"),
    SENDING(3, "待收货"),
    RECEIVE(4, "已收货"),
    WAIT_TALK(50, "待询价"),
    OFFLINE_CONFIRMED(60, "付款待确认"),//线下打款待确认-确认生成对账单
    BILL(70, "已结算"),//
    PAYED(80, "待发货"),//
    PART_PAYED(81,"部分付款"),
    BILL_APPLY(82,"可提货"),
    //PICK_UP(81, "备货中"),
    COUNT(90, "已完成"),//
    FINISH_ORDER(91, "已对账"),//已对账 目前用这个
    REFUSE(98, "已驳回"),
    CANCEL(99, "已取消"),
    CANCELLED(130,"已关闭"),
    PARTIAL_SHIPMENTS(140,"分批发货中"),

    /*售后的状态*/
    REFUNDING(7, "退款中"),
    REFUND(120, "退款完成"); //已退款统一用这个值

    private Integer value;

    private String name;

    OrderStatus(int value, String name) {
        this.value = value;
        this.name = name;
    }

    public static boolean contains(int value) {
        for (OrderStatus anEnum : OrderStatus.values()) {
            if (anEnum.value == value) {
                return true;
            }
        }
        return false;
    }
    public static String getDesc(int value) {
        for (OrderStatus anEnum : OrderStatus.values()) {
            if (anEnum.value == value) {
                return anEnum.getName();
            }
        }
        return "";
    }
    public static String getNameByValue(Integer value){
        for(OrderStatus k : OrderStatus.values()){
            if(value.equals(k.getValue())){
                return k.name;
            }
        }
        return null;
    }

    public static OrderStatus getOrderStatusEnum(Integer value) {
        for (OrderStatus orderStatusEnum: OrderStatus.values()) {
            if (orderStatusEnum.value.equals(value)) {
                return orderStatusEnum;
            }
        }
        return null;
    }


    public Integer getValue() {
        return value;
    }

    public void setValue(int value) {
        this.value = value;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }
}
package com.honghan.trade.enums;

public enum PaymentMethod {
    PREPAY(1, "先款后货"),
    DEPOSIT(2, "先付订金后付尾款"),
    POSTPAY(3, "先货后款"),
    MULTI_PAY(4, "多次付款");

    private final int value;
    private final String description;

    PaymentMethod(int value, String description) {
        this.value = value;
        this.description = description;
    }

    public int getValue() {
        return value;
    }

    public String getDescription() {
        return description;
    }

    public static PaymentMethod fromValue(int value) {
        for (PaymentMethod method : PaymentMethod.values()) {
            if (method.value == value) {
                return method;
            }
        }
        return null;
    }
}
package com.honghan.trade.enums;

public enum PaymentMethod {
    PREPAY(1, "先款后货"),
    DEPOSIT(2, "先付订金后付尾款"),
    POSTPAY(3, "先货后款"),
    MULTI_PAY(4, "多次付款");

    private final int value;
    private final String description;

    PaymentMethod(int value, String description) {
        this.value = value;
        this.description = description;
    }

    public int getValue() {
        return value;
    }

    public String getDescription() {
        return description;
    }

    public static PaymentMethod fromValue(int value) {
        for (PaymentMethod method : PaymentMethod.values()) {
            if (method.value == value) {
                return method;
            }
        }
        return null;
    }
}
package com.honghan.trade.util;

import com.honghan.common.core.enums.OrderStatus;
import com.honghan.trade.api.domain.TradeOrder;
import com.honghan.trade.enums.PaymentMethod;
import com.honghan.trade.statemachine.OrderStateMachine;

/**
 * 订单状态机工具类
 */
public class OrderStateMachineUtil {

    private static OrderStateMachine orderStateMachine = new OrderStateMachine();


    public static void updateOrderStatus(TradeOrder tradeOrder) {
        OrderStatus currentStatus = OrderStatus.getOrderStatusEnum(tradeOrder.getStatus());
        PaymentMethod paymentMethod = PaymentMethod.fromValue(tradeOrder.getSettlePayType());
        OrderStatus nextStatus = orderStateMachine.getNextStatus(currentStatus, paymentMethod, false);
        tradeOrder.setStatus(nextStatus.getValue());
    }

    public static void updateOrderStatus(TradeOrder tradeOrder, OrderStatus currentStatus) {
        tradeOrder.setStatus(currentStatus.getValue());
    }

    public static void updateOrderNextStatus(TradeOrder tradeOrder, OrderStatus currentStatus) {
        PaymentMethod paymentMethod = PaymentMethod.fromValue(tradeOrder.getSettlePayType());
        OrderStatus nextStatus = orderStateMachine.getNextStatus(currentStatus, paymentMethod, false);
        tradeOrder.setStatus(currentStatus.getValue());
    }

}

【投诉】皇家美素佳儿2段奶粉里面有异物

【投诉】皇家美素佳儿2段奶粉里面有异物

京东自营店购买的

喝了一年的爱他美卓傲奶粉都没这问题
想着给换成皇家奶粉

谁知道喝了三分之二 发现有异物

垃圾皇家

投诉到底!!!





word转xml的方法

和大佬学的

先把你需要的模版文档弄好成docx格式,再把后缀改成.zip格式 获取里面的document.xml文件,在xml中把你要替换的参数写成表达式如:${productName},在项目中通过代码填充productName参数,进行测试)

也可以把表达式先写到docx文件中,在改后缀。。。亲测

easyexcel导出风格

//设置Excel head高度
@HeadRowHeight(30)
//设置Excel默认列宽
@ColumnWidth(14)
//设置Excel 正文字体样式
@ContentFontStyle(fontName = "宋体", fontHeightInPoints = 12)

链接:https://blog.csdn.net/pbl13071138970/article/details/119082481

导出去除不必要的字段,只导出注解的字段

@ExcelIgnoreUnannotated
 //这里再次设置列宽会覆盖上面设置的默认列宽
    @ColumnWidth(23)
    @ExcelProperty(value = "订单编号", order = 1)
    private String identifier;

docker pull 报错Get “https://registry-1.docker.io/v2/“: net/http: request canceled while waiting for c

报错 :Get "https://registry-1.docker.io/v2/": net/http: request canceled while waiting for connection (Client.Timeout exceeded while awaiting headers)
解决方法

配置加速地址

vim /etc/docker/daemon.json

添加以下内容

{
  "registry-mirrors": ["https://docker.1panel.live"]
}

或者

{
    "registry-mirrors": [
            "https://docker.211678.top",
            "https://docker.1panel.live",
            "https://hub.rat.dev",
            "https://docker.m.daocloud.io",
            "https://do.nark.eu.org",
            "https://dockerpull.com",
            "https://dockerproxy.cn",
            "https://docker.awsl9527.cn"
      ]
}

{
  "registry-mirrors": ["https://docker.m.daocloud.io"]
}

保存

:wq

重启docker

systemctl daemon-reload
systemctl restart  docker