package com.fjhx.ehsd.service.freight.impl;

import cn.hutool.core.bean.BeanUtil;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.fjhx.ehsd.entity.freight.dto.FreightForwarderDto;
import com.fjhx.ehsd.entity.freight.dto.FreightForwarderSelectDto;
import com.fjhx.ehsd.entity.freight.po.FreightForwarder;
import com.fjhx.ehsd.entity.freight.vo.FreightForwarderVo;
import com.fjhx.ehsd.mapper.freight.FreightForwarderMapper;
import com.fjhx.ehsd.service.freight.FreightForwarderService;
import com.fjhx.item.entity.product.po.ProductInfo;
import com.ruoyi.common.utils.wrapper.IWrapper;
import org.springframework.stereotype.Service;


/**
 * <p>
 * 货代公司管理 服务实现类
 * </p>
 *
 * @author
 * @since 2023-05-05
 */
@Service
public class FreightForwarderServiceImpl extends ServiceImpl<FreightForwarderMapper, FreightForwarder> implements FreightForwarderService {

    @Override
    public Page<FreightForwarderVo> getPage(FreightForwarderSelectDto dto) {
        IWrapper<FreightForwarder> wrapper = getWrapper();
        wrapper.like("ff", FreightForwarder::getCompanyName, dto.getKeyword());
        wrapper.orderByDesc("ff", FreightForwarder::getId);
        Page<FreightForwarderVo> page = this.baseMapper.getPage(dto.getPage(), wrapper);
        return page;
    }

    @Override
    public FreightForwarderVo detail(Long id) {
        FreightForwarder FreightForwarder = this.getById(id);
        FreightForwarderVo result = BeanUtil.toBean(FreightForwarder, FreightForwarderVo.class);
        return result;
    }

    @Override
    public void add(FreightForwarderDto freightForwarderDto) {
        this.nameDuplication(FreightForwarder::getCompanyName, freightForwarderDto.getCompanyName(), "公司名称重复");
        this.save(freightForwarderDto);
    }

    @Override
    public void edit(FreightForwarderDto freightForwarderDto) {
        this.nameDuplication(FreightForwarder::getCompanyName, freightForwarderDto.getCompanyName(), freightForwarderDto.getId(), "公司名称重复");
        this.updateById(freightForwarderDto);
    }

    @Override
    public void delete(Long id) {
        this.removeById(id);
    }

}
