package com.hfkj.service.impl;

import com.hfkj.dao.BsMerLedgerReceiverApplyMapper;
import com.hfkj.entity.BsMerLedgerReceiverApply;
import com.hfkj.entity.BsMerLedgerReceiverApplyExample;
import com.hfkj.service.BsMerLedgerReceiverApplyService;
import org.springframework.stereotype.Service;

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

/**
 * @className: BsMerLedgerReceiverApplyServiceImpl
 * @author: HuRui
 * @date: 2023/4/19
 **/
@Service("merLedgerReceiverApplyService")
public class BsMerLedgerReceiverApplyServiceImpl implements BsMerLedgerReceiverApplyService {

    @Resource
    private BsMerLedgerReceiverApplyMapper merLedgerReceiverApplyMapper;

    @Override
    public void editReceiverApply(BsMerLedgerReceiverApply merLedgerReceiverApply) {
        if (merLedgerReceiverApply.getId() == null) {
            merLedgerReceiverApply.setUpdateTime(new Date());
            merLedgerReceiverApply.setCreateTime(new Date());
            merLedgerReceiverApplyMapper.insert(merLedgerReceiverApply);
        } else {
            merLedgerReceiverApply.setUpdateTime(new Date());
            merLedgerReceiverApplyMapper.updateByPrimaryKey(merLedgerReceiverApply);
        }
    }

    @Override
    public BsMerLedgerReceiverApply getReceiverApplyByApplyId(String applyId) {
        BsMerLedgerReceiverApplyExample example = new BsMerLedgerReceiverApplyExample();
        example.createCriteria().andApplyIdEqualTo(applyId);
        List<BsMerLedgerReceiverApply> list = merLedgerReceiverApplyMapper.selectByExample(example);
        if (list.size() > 0) {
            return list.get(0);
        }
        return null;
    }
}
