package com.hfkj.service.impl;

import com.hfkj.dao.BsMerSettleAcctMapper;
import com.hfkj.entity.BsMerSettleAcct;
import com.hfkj.entity.BsMerSettleAcctExample;
import com.hfkj.service.BsMerSettleAcctService;
import org.springframework.stereotype.Service;

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

@Service("merSettleAcctService")
public class BsMerSettleAcctServiceImpl implements BsMerSettleAcctService {

    @Resource
    private BsMerSettleAcctMapper merSettleAcctMapper;

    @Override
    public void editMerSettleAcct(BsMerSettleAcct merSettleAcct) {
        if (merSettleAcct.getId() == null) {
            merSettleAcct.setStatus(1);
            merSettleAcct.setCreateTime(new Date());
            merSettleAcct.setUpdateTime(new Date());
            merSettleAcctMapper.insert(merSettleAcct);
        } else {
            merSettleAcct.setUpdateTime(new Date());
            merSettleAcctMapper.updateByPrimaryKey(merSettleAcct);
        }
    }

    @Override
    public BsMerSettleAcct getMerSettleByMerId(Long merId) {
        BsMerSettleAcctExample example = new BsMerSettleAcctExample();
        example.createCriteria().andMerIdEqualTo(merId).andStatusEqualTo(1);
        List<BsMerSettleAcct> list = merSettleAcctMapper.selectByExample(example);
        if (list.size() > 0) {
            return list.get(0);
        }
        return null;
    }
}
