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

import com.baomidou.dynamic.datasource.annotation.DS;
import com.fjhx.common.constant.SourceConstant;
import com.fjhx.purchase.entity.quality.po.QualityDetail;
import com.fjhx.purchase.mapper.quality.QualityDetailMapper;
import com.fjhx.purchase.service.quality.QualityDetailService;
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.quality.vo.QualityDetailVo;
import com.fjhx.purchase.entity.quality.dto.QualityDetailSelectDto;
import com.ruoyi.common.utils.wrapper.IWrapper;
import com.fjhx.purchase.entity.quality.dto.QualityDetailDto;
import cn.hutool.core.bean.BeanUtil;

import java.math.BigDecimal;


/**
 * <p>
 * 质检明细单 服务实现类
 * </p>
 *
 * @author 
 * @since 2023-04-11
 */
@DS(SourceConstant.PURCHASE)
@Service
public class QualityDetailServiceImpl extends ServiceImpl<QualityDetailMapper, QualityDetail> implements QualityDetailService {

    @Override
    public Page<QualityDetailVo> getPage(QualityDetailSelectDto dto) {
        IWrapper<QualityDetail> wrapper = getWrapper();
        wrapper.orderByDesc("qd", QualityDetail::getId);
        Page<QualityDetailVo> page = this.baseMapper.getPage(dto.getPage(), wrapper);
        return page;
    }

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

    @Override
    public void add(QualityDetailDto qualityDetailDto) {
        this.save(qualityDetailDto);
    }

    @Override
    public void edit(QualityDetailDto qualityDetailDto) {
        this.updateById(qualityDetailDto);
    }

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

    /**
     * 获取当前到货明细总质检数量
     * @param arrivalDetailId
     * @return
     */
    @Override
    public BigDecimal getSumQualityCount(Long arrivalDetailId) {
        return baseMapper.getSumQualityCount(arrivalDetailId);
    }

}
