package cn.iocoder.yudao.module.bpm.service.financialpaymentitem;

import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
import cn.iocoder.yudao.module.bpm.controller.admin.financialpaymentitem.vo.FinancialPaymentItemPageReqVO;
import cn.iocoder.yudao.module.bpm.controller.admin.financialpaymentitem.vo.FinancialPaymentItemSaveReqVO;
import cn.iocoder.yudao.module.bpm.dal.dataobject.financialpayment.FinancialPaymentDO;
import cn.iocoder.yudao.module.bpm.dal.dataobject.financialpaymentitem.FinancialPaymentItemDO;
import cn.iocoder.yudao.module.bpm.dal.mysql.financialpaymentitem.FinancialPaymentItemMapper;
import cn.iocoder.yudao.module.bpm.service.financialpayment.FinancialPaymentService;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import org.springframework.stereotype.Service;
import org.springframework.validation.annotation.Validated;

import javax.annotation.Resource;
import java.util.List;

/**
 * 财务支付子表 Service 实现类
 *
 * @author 艾楷
 */
@Service
@Validated
public class FinancialPaymentItemServiceImpl implements FinancialPaymentItemService {

    @Resource
    private FinancialPaymentItemMapper financialPaymentItemMapper;

    @Resource
    private FinancialPaymentService financialPaymentService;

    @Override
    public Long createFinancialPaymentItem(FinancialPaymentItemSaveReqVO createReqVO) {
        // 插入
        FinancialPaymentItemDO financialPaymentItem = BeanUtils.toBean(createReqVO, FinancialPaymentItemDO.class);
        financialPaymentItemMapper.insert(financialPaymentItem);
        // 返回
        return financialPaymentItem.getId();
    }

    @Override
    public void updateFinancialPaymentItem(FinancialPaymentItemSaveReqVO updateReqVO) {
        // 更新
        FinancialPaymentItemDO updateObj = BeanUtils.toBean(updateReqVO, FinancialPaymentItemDO.class);
        financialPaymentItemMapper.updateById(updateObj);
    }

    @Override
    public void deleteFinancialPaymentItem(Long id) {
        // 删除
        financialPaymentItemMapper.deleteById(id);
    }

    @Override
    public FinancialPaymentItemDO getFinancialPaymentItem(Long id) {
        return financialPaymentItemMapper.selectById(id);
    }

    @Override
    public PageResult<FinancialPaymentItemDO> getFinancialPaymentItemPage(FinancialPaymentItemPageReqVO pageReqVO) {
        return financialPaymentItemMapper.selectPage(pageReqVO);
    }

    @Override
    public List<FinancialPaymentItemDO> getByFinancialPaymentId(Long financialPaymentId) {
        return financialPaymentItemMapper.selectList(new LambdaQueryWrapper<FinancialPaymentItemDO>()
                .eq(FinancialPaymentItemDO::getFinancialPaymentId, financialPaymentId));
    }

}
