package com.hfkj.service.impl;

import com.hfkj.dao.BsMerWithdrawalMapper;
import com.hfkj.entity.BsMerWithdrawal;
import com.hfkj.entity.BsMerWithdrawalExample;
import com.hfkj.service.BsMerWithdrawalService;
import org.springframework.stereotype.Service;

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

/**
 * @className: BsMerWithdrawalServiceImpl
 * @author: HuRui
 * @date: 2023/6/8
 **/
@Service("merWithdrawalService")
public class BsMerWithdrawalServiceImpl implements BsMerWithdrawalService {
    @Resource
    private BsMerWithdrawalMapper merWithdrawalMapper;

    @Override
    public void editData(BsMerWithdrawal merWithdrawal) {
        if (merWithdrawal.getCreateTime() == null) {
            merWithdrawal.setCreateTime(new Date());
        }
        if (merWithdrawal.getId() == null) {
            merWithdrawal.setUpdateTime(new Date());
            merWithdrawalMapper.insert(merWithdrawal);
        } else {
            merWithdrawal.setUpdateTime(new Date());
            merWithdrawalMapper.updateByPrimaryKey(merWithdrawal);
        }
    }

    @Override
    public BsMerWithdrawal getDetailByDrawJnl(String drawJnl) {
        BsMerWithdrawalExample example = new BsMerWithdrawalExample();
        example.createCriteria().andDrawJnlEqualTo(drawJnl);
        List<BsMerWithdrawal> list = merWithdrawalMapper.selectByExample(example);
        if (list.size() > 0) {
            return list.get(0);
        }
        return null;
    }
}
