package com.hfkj.service.impl;

import com.hfkj.dao.BsBankActivityMapper;
import com.hfkj.entity.BsBankActivity;
import com.hfkj.entity.BsBankActivityExample;
import com.hfkj.service.BsBankActivityService;
import org.springframework.stereotype.Service;

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

/**
 * @className: BsBankActivityServiceImpl
 * @author: HuRui
 * @date: 2023/5/17
 **/
@Service("bankActivityService")
public class BsBankActivityServiceImpl implements BsBankActivityService {

    @Resource
    private BsBankActivityMapper bsBankActivityMapper;

    @Override
    public void editData(BsBankActivity bankActivity) {
        if (bankActivity.getId() == null) {
            bankActivity.setCreateTime(new Date());
            bankActivity.setUpdateTime(new Date());
            bsBankActivityMapper.insert(bankActivity);
        } else {
            bankActivity.setUpdateTime(new Date());
            bsBankActivityMapper.updateByPrimaryKey(bankActivity);
        }
    }

    @Override
    public List<BsBankActivity> getBankActivityList(Map<String, Object> param) {
        BsBankActivityExample example = new BsBankActivityExample();
        example.createCriteria().andStatusNotEqualTo(0);
        example.setOrderByClause("create_time desc");
        return bsBankActivityMapper.selectByExample(example);
    }

    @Override
    public BsBankActivity getBankActivityById(Long bankActivityId) {
        return bsBankActivityMapper.selectByPrimaryKey(bankActivityId);
    }

    @Override
    public BsBankActivity getBankActivityByNo(Long activityNo) {
        BsBankActivityExample example = new BsBankActivityExample();
        example.createCriteria().andActivityNoEqualTo(activityNo);
        List<BsBankActivity> list = bsBankActivityMapper.selectByExample(example);
        if (list.size() > 0) {
            return list.get(0);
        }
        return null;
    }
}
