package com.hfkj.service.rebate.impl;

import com.hfkj.dao.BsRebateRewardMapper;
import com.hfkj.dao.BsRebateRewardRosterMapper;
import com.hfkj.entity.BsRebateReward;
import com.hfkj.entity.BsRebateRewardRoster;
import com.hfkj.entity.BsRebateRewardRosterExample;
import com.hfkj.service.rebate.BsRebateRewardRosterService;
import com.hfkj.sysenum.RebateRewardStatusEnum;
import org.springframework.stereotype.Service;

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

/**
 * @className: BsRebateRewardRosterServiceImpl
 * @author: HuRui
 * @date: 2023/10/11
 **/
@Service("rebateRewardRosterService")
public class BsRebateRewardRosterServiceImpl implements BsRebateRewardRosterService {

    @Resource
    private BsRebateRewardRosterMapper rebateRewardRosterMapper;

    @Override
    public void editDate(BsRebateRewardRoster rebateRewardRoster) {
        if (rebateRewardRoster.getId() == null) {
            rebateRewardRoster.setCreateTime(new Date());
            rebateRewardRoster.setUpdateTime(new Date());
            rebateRewardRosterMapper.insert(rebateRewardRoster);
        } else {
            rebateRewardRoster.setUpdateTime(new Date());
            rebateRewardRosterMapper.updateByPrimaryKey(rebateRewardRoster);
        }
    }

    @Override
    public List<BsRebateRewardRoster> getRosterList(Long batchIdentifier) {
        BsRebateRewardRosterExample example = new BsRebateRewardRosterExample();
        example.createCriteria().andBatchIdentifierEqualTo(batchIdentifier).andStatusNotEqualTo(RebateRewardStatusEnum.status0.getNumber());
        return rebateRewardRosterMapper.selectByExample(example);
    }
}
