package com.fjhx.purchase.service.sales.impl;

import com.baomidou.dynamic.datasource.annotation.DS;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.fjhx.common.constant.SourceConstant;
import com.fjhx.purchase.entity.sales.po.SalesReturn;
import com.fjhx.purchase.mapper.sales.SalesReturnMapper;
import com.fjhx.purchase.service.sales.SalesReturnService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.fjhx.purchase.entity.sales.vo.SalesReturnVo;
import com.fjhx.purchase.entity.sales.dto.SalesReturnSelectDto;
import com.ruoyi.common.utils.wrapper.IWrapper;
import com.fjhx.purchase.entity.sales.dto.SalesReturnDto;
import cn.hutool.core.bean.BeanUtil;

import java.util.List;


/**
 * <p>
 * 退货 服务实现类
 * </p>
 *
 * @author 
 * @since 2023-04-11
 */
@DS(SourceConstant.PURCHASE)
@Service
public class SalesReturnServiceImpl extends ServiceImpl<SalesReturnMapper, SalesReturn> implements SalesReturnService {

    @Override
    public Page<SalesReturnVo> getPage(SalesReturnSelectDto dto) {
        IWrapper<SalesReturn> wrapper = getWrapper();
        wrapper.orderByDesc("sr", SalesReturn::getId);
        Page<SalesReturnVo> page = this.baseMapper.getPage(dto.getPage(), wrapper);
        return page;
    }

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

    @Override
    public void add(SalesReturnDto salesReturnDto) {
        this.save(salesReturnDto);
    }

    @Override
    public void edit(SalesReturnDto salesReturnDto) {
        this.updateById(salesReturnDto);
    }

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

    /**
     * 根据供应商查询退货列表
     * @param supplyId
     * @return
     */
    @Override
    public List<SalesReturn> getListBySupplyId(String supplyId) {
        return this.list(Wrappers.<SalesReturn>query().lambda().eq(SalesReturn::getSupplyId,supplyId));
    }

}
