package com.hfkj.service.impl;

import com.hfkj.dao.BsStoreDiscountActivityPartakeUserRecordMapper;
import com.hfkj.entity.BsStoreDiscountActivityPartakeUserRecord;
import com.hfkj.entity.BsStoreDiscountActivityPartakeUserRecordExample;
import com.hfkj.service.BsStoreDiscountActivityPartakeUserRecordService;
import org.springframework.stereotype.Service;

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

/**
 * @className: BsStoreDiscountActivityPartakeUserRecordServiceImpl
 * @author: HuRui
 * @date: 2023/3/24
 **/
@Service("storeDiscountActivityPartakeUserRecordService")
public class BsStoreDiscountActivityPartakeUserRecordServiceImpl implements BsStoreDiscountActivityPartakeUserRecordService {

    @Resource
    private BsStoreDiscountActivityPartakeUserRecordMapper recordMapper;

    @Override
    public void insertRecord(BsStoreDiscountActivityPartakeUserRecord record) {
        record.setCreateTime(new Date());
        recordMapper.insert(record);
    }

    @Override
    public Long getPartakeNum(String phone, Long discountActivityId, Date startTime, Date endTime) {
        BsStoreDiscountActivityPartakeUserRecordExample example = new BsStoreDiscountActivityPartakeUserRecordExample();
        example.createCriteria()
                .andUserPhoneEqualTo(phone)
                .andDiscountActivityIdEqualTo(discountActivityId)
                .andCreateTimeGreaterThanOrEqualTo(startTime)
                .andCreateTimeLessThanOrEqualTo(endTime);
        return recordMapper.countByExample(example);
    }
}
