package com.hfkj.service.impl;

import com.hfkj.dao.BsStoreSettleAcctMapper;
import com.hfkj.entity.BsStoreSettleAcct;
import com.hfkj.entity.BsStoreSettleAcctExample;
import com.hfkj.service.BsStoreSettleAcctService;
import org.apache.ibatis.annotations.Select;
import org.springframework.stereotype.Service;

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

/**
 * @className: BsStoreSettleAcctImpl
 * @author: HuRui
 * @date: 2022/12/1
 **/
@Service("storeSettleAcctService")
public class BsStoreSettleAcctImpl implements BsStoreSettleAcctService {

    @Resource
    private BsStoreSettleAcctMapper storeSettleAcctMapper;

    @Override
    public void editStoreSettle(BsStoreSettleAcct storeSettleAcct) {
        if (storeSettleAcct.getId() == null) {
            storeSettleAcct.setCreateTime(new Date());
            storeSettleAcct.setUpdateTime(new Date());
            storeSettleAcctMapper.insert(storeSettleAcct);
        } else {
            storeSettleAcct.setUpdateTime(new Date());
            storeSettleAcctMapper.updateByPrimaryKey(storeSettleAcct);
        }
    }

    @Override
    public BsStoreSettleAcct getDetailByStore(Long storeId) {
        BsStoreSettleAcctExample example = new BsStoreSettleAcctExample();
        example.createCriteria().andStoreIdEqualTo(storeId).andStatusEqualTo(0);
        List<BsStoreSettleAcct> list = storeSettleAcctMapper.selectByExample(example);
        if (list.size() > 0) {
            return list.get(0);
        }
        return null;
    }
}
