package com.fzm.mall.server.admin.distribution.service.impl;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.fzm.mall.server.admin.distribution.entity.dto.ParcelCenterDTO;
import com.fzm.mall.server.admin.distribution.mapper.ParcelCenterMapper;
import com.fzm.mall.server.admin.distribution.model.ParcelCenter;
import com.fzm.mall.server.admin.distribution.service.IExpressService;
import com.fzm.mall.server.admin.distribution.service.IParcelCenterService;
import com.fzm.mall.server.admin.order.model.Delivery;
import com.fzm.mall.server.admin.util.CopyUtil;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

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

/**
 * <p>
 * 物流中心-运费模板-指定地区运费规则 服务实现类
 * </p>
 *
 * @author wulixian
 * @since 2021-03-04
 */
@Service
@Transactional
@RequiredArgsConstructor(onConstructor = @__(@Autowired))
public class ParcelCenterServiceImpl extends ServiceImpl<ParcelCenterMapper, ParcelCenter> implements IParcelCenterService {

    private final ParcelCenterMapper parcelCenterMapper;
    private final IExpressService expressService;

    @Override
    public ParcelCenterDTO read(String orderDeliveryId) {
        Delivery delivery = parcelCenterMapper.read(orderDeliveryId);
        ParcelCenter parcelCenter = CopyUtil.to(delivery, ParcelCenter.class);
        parcelCenter.listExpressDetail(expressService, delivery);
        parcelCenter.listGoods(parcelCenterMapper, parcelCenter);
        return CopyUtil.to(parcelCenter, ParcelCenterDTO.class);
    }

    @Override
    public IPage<ParcelCenterDTO> page(Page<ParcelCenterDTO> page, String packageNum, String uid, String orderDeliveryId, Integer deliveryState, String merchantId) {
        IPage<ParcelCenterDTO> result = parcelCenterMapper.list(page, packageNum, uid, orderDeliveryId, deliveryState, merchantId);
        return result;
    }
}
