package com.ruoyi.jarvis.service.impl;

import com.ruoyi.jarvis.domain.JDOrder;
import com.ruoyi.jarvis.domain.dto.QuickRecordModelOption;
import com.ruoyi.jarvis.mapper.JDOrderMapper;
import com.ruoyi.jarvis.service.IJDOrderModelShopService;
import com.ruoyi.jarvis.service.IJDOrderProfitService;
import com.ruoyi.jarvis.service.IJDOrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class JDOrderServiceImpl implements IJDOrderService {

    @Autowired
    private JDOrderMapper jdOrderMapper;

    @Autowired
    private IJDOrderProfitService jdOrderProfitService;

    @Autowired
    private IJDOrderModelShopService jdOrderModelShopService;

    @Override
    public List<JDOrder> selectJDOrderList(JDOrder jdOrder) {
        return jdOrderMapper.selectJDOrderList(jdOrder);
    }

    @Override
    public List<JDOrder> selectJDOrderListWithSort(JDOrder jdOrder) {
        return jdOrderMapper.selectJDOrderListWithSort(jdOrder);
    }

    @Override
    public JDOrder selectJDOrderById(Long id) {
        return jdOrderMapper.selectJDOrderById(id);
    }

    @Override
    public int insertJDOrder(JDOrder jdOrder) {
        jdOrderModelShopService.normalizeOrder(jdOrder);
        jdOrderProfitService.recalculate(jdOrder);
        return jdOrderMapper.insertJDOrder(jdOrder);
    }

    @Override
    public int updateJDOrder(JDOrder jdOrder) {
        jdOrderModelShopService.normalizeOrder(jdOrder);
        return jdOrderMapper.updateJDOrder(jdOrder);
    }

    @Override
    public JDOrder selectJDOrderByRemark(String remark) {
        return jdOrderMapper.selectJDOrderByRemark(remark);
    }

    @Override
    public List<JDOrder> selectJDOrderListByAddress(String address) {
        return jdOrderMapper.selectJDOrderListByAddress(address);
    }

    @Override
    public JDOrder selectJDOrderByOrderId(String orderId) {
        return jdOrderMapper.selectJDOrderByOrderId(orderId);
    }

    @Override
    public List<JDOrder> selectLatestJDOrdersByOrderIds(List<String> orderIds) {
        if (orderIds == null || orderIds.isEmpty()) {
            return java.util.Collections.emptyList();
        }
        return jdOrderMapper.selectLatestJDOrdersByOrderIds(orderIds);
    }

    @Override
    public JDOrder selectJDOrderByLogisticsLink(String logisticsLink) {
        return jdOrderMapper.selectJDOrderByLogisticsLink(logisticsLink);
    }
    
    @Override
    public JDOrder selectJDOrderByThirdPartyOrderNo(String thirdPartyOrderNo) {
        return jdOrderMapper.selectJDOrderByThirdPartyOrderNo(thirdPartyOrderNo);
    }

    @Override
    public int deleteJDOrderByIds(Long[] ids) {
        if (ids == null || ids.length == 0) {
            return 0;
        }
        return jdOrderMapper.deleteJDOrderByIds(ids);
    }

    @Override
    public List<JDOrder> selectJDOrderListByDistributionMarkFOrPDD() {
        return jdOrderMapper.selectJDOrderListByDistributionMarkFOrPDD();
    }

    @Override
    public List<QuickRecordModelOption> selectQuickRecordModelOptions() {
        return jdOrderMapper.selectQuickRecordModelOptions();
    }

    @Override
    public java.util.Map<String, Object> migrateModelShopSplit() {
        return jdOrderModelShopService.migrateExistingOrders();
    }
}


