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

import com.fjhx.sale.entity.claim.po.ClaimContract;
import com.fjhx.sale.mapper.claim.ClaimContractMapper;
import com.fjhx.sale.service.claim.ClaimContractService;
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.claim.vo.ClaimContractVo;
import com.fjhx.sale.entity.claim.dto.ClaimContractSelectDto;
import com.ruoyi.common.utils.wrapper.IWrapper;
import com.fjhx.sale.entity.claim.dto.ClaimContractDto;
import cn.hutool.core.bean.BeanUtil;

import java.util.List;


/**
 * <p>
 * 到账认领-合同关联表 服务实现类
 * </p>
 *
 * @author 
 * @since 2023-04-18
 */
@Service
public class ClaimContractServiceImpl extends ServiceImpl<ClaimContractMapper, ClaimContract> implements ClaimContractService {

    @Override
    public Page<ClaimContractVo> getPage(ClaimContractSelectDto dto) {
        IWrapper<ClaimContract> wrapper = getWrapper();
        wrapper.orderByDesc("cc", ClaimContract::getId);
        Page<ClaimContractVo> page = this.baseMapper.getPage(dto.getPage(), wrapper);
        return page;
    }

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

    @Override
    public void add(ClaimContractDto claimContractDto) {
        this.save(claimContractDto);
    }

    @Override
    public void edit(ClaimContractDto claimContractDto) {
        this.updateById(claimContractDto);
    }

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

    /**
     * 通过合同ID集合查询列表
     * @param contractIds
     * @return
     */
    @Override
    public List<ClaimContract> getListByContractIds(List<Long> contractIds) {
        IWrapper<ClaimContract> wrapper = getWrapper();
        wrapper.in("t1.contract_id", contractIds);
        return baseMapper.getListByContractIds(wrapper);
    }

}
