package com.hfkj.service.impl;

import com.hfkj.dao.BsMerLedgerApplyMapper;
import com.hfkj.dao.BsMerLedgerMapper;
import com.hfkj.entity.BsMerLedgerApply;
import com.hfkj.entity.BsMerLedgerApplyExample;
import com.hfkj.service.BsMerLedgerApplyService;
import org.springframework.stereotype.Service;

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

/**
 * @className: BsMerLedgerApplyServiceImpl
 * @author: HuRui
 * @date: 2023/4/18
 **/
@Service("merLedgerApplyService")
public class BsMerLedgerApplyServiceImpl implements BsMerLedgerApplyService {

    @Resource
    private BsMerLedgerApplyMapper merLedgerApplyMapper;

    @Override
    public void editMerLedgerApply(BsMerLedgerApply merLedgerApply) {
        if (merLedgerApply.getId() == null) {
            merLedgerApply.setStatus(1);
            merLedgerApply.setCreateTime(new Date());
            merLedgerApply.setUpdateTime(new Date());
            merLedgerApplyMapper.insert(merLedgerApply);
        } else {
            merLedgerApply.setUpdateTime(new Date());
            merLedgerApplyMapper.updateByPrimaryKey(merLedgerApply);
        }
    }

    @Override
    public BsMerLedgerApply getApplyByOrderNo(String orderNo) {
        return null;
    }

    @Override
    public BsMerLedgerApply getApplyByApplyId(String applyId) {
        BsMerLedgerApplyExample example = new BsMerLedgerApplyExample();
        example.createCriteria().andApplyIdEqualTo(applyId).andStatusNotEqualTo(0);
        List<BsMerLedgerApply> list = merLedgerApplyMapper.selectByExample(example);
        if (list.size() > 0) {
            return list.get(0);
        }
        return null;
    }
}
