package com.fjhx.sale.service.documents.impl;

import com.fjhx.file.utils.ObsFileUtil;
import com.fjhx.sale.entity.documents.dto.DocumentsTransportDto;
import com.fjhx.sale.entity.documents.po.DocumentsTransport;
import com.fjhx.sale.mapper.documents.DocumentsTransportMapper;
import com.fjhx.sale.service.documents.DocumentsTransportService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.fjhx.sale.entity.documents.vo.DocumentsTransportVo;
import com.fjhx.sale.entity.documents.dto.DocumentsTransportSelectDto;
import com.ruoyi.common.utils.wrapper.IWrapper;
import cn.hutool.core.bean.BeanUtil;


/**
 * <p>
 * 单证-货运表 服务实现类
 * </p>
 *
 * @author
 * @since 2023-04-20
 */
@Service
public class DocumentsTransportServiceImpl extends ServiceImpl<DocumentsTransportMapper, DocumentsTransport> implements DocumentsTransportService {

    @Override
    public Page<DocumentsTransportVo> getPage(DocumentsTransportSelectDto dto) {
        IWrapper<DocumentsTransport> wrapper = getWrapper();
        wrapper.orderByDesc("dt", DocumentsTransport::getId);
        Page<DocumentsTransportVo> page = this.baseMapper.getPage(dto.getPage(), wrapper);
        return page;
    }

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

    /**
     * 单证-货运添加
     *
     * @param dto
     * @return
     */
    @Override
    public void add(DocumentsTransportDto dto) {
        //添加单证货运表的数据
        baseMapper.insert(dto);

        //添加附件信息
        ObsFileUtil.saveFile(dto.getFileList(), dto.getId());

    }

}
