package com.yc.ship.module.trade.service.order.handler;


import com.yc.ship.framework.common.util.object.ObjectUtils;
import com.yc.ship.module.trade.enums.SellMethodEnum;
import com.yc.ship.module.trade.service.order.TradeOrderRepositoryService;
import com.yc.ship.module.trade.dal.dataobject.order.TradeDetailDO;
import com.yc.ship.module.trade.dal.dataobject.order.TradeOrderDO;
import lombok.extern.slf4j.Slf4j;
import org.springframework.core.annotation.Order;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.util.List;

/**
 * &#064;Description 统计处理
 * &#064;Author qsl
 * &#064;Date 2025/8/16 14:49
 */
@Component
@Order(TradeOrderHandler.STATISTIC)
@Slf4j
public class StatisticHandler implements TradeOrderHandler{

    @Resource
    private TradeOrderRepositoryService tradeOrderRepositoryService;

    @Override
    public void afterProcessSuccess(TradeOrderDO tradeOrderDO) {
        try {
            //小程序销量修改
            if (ObjectUtils.equalsAny(tradeOrderDO.getSellMethod(), SellMethodEnum.MINI_APP.getType())) {
                List<TradeDetailDO> tradeDetailDOs = tradeOrderRepositoryService.queryDetailByOrderId(tradeOrderDO.getId());
                tradeOrderRepositoryService.updateSellNumByProduct(tradeDetailDOs.get(0).getProductId(), tradeDetailDOs.size());
            }
        }catch (Exception e){
            log.error("小程序更新销量异常",e);
        }
    }
}
