package com.hzs.bonus.bonus.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.hzs.bonus.bonus.mapper.CuMemberRetailLogMapper;
import com.hzs.bonus.bonus.service.ICuMemberRetailLogService;
import com.hzs.common.core.enums.EYesNo;
import com.hzs.common.core.utils.DateUtils;
import com.hzs.common.domain.member.bonus.CuMemberRetailLog;
import org.springframework.stereotype.Service;

import java.time.temporal.ChronoUnit;
import java.util.Date;
import java.util.List;

/**
 * 秒接日志记录表 服务实现类
 */
@Service
public class CuMemberRetailLogServiceImpl extends ServiceImpl<CuMemberRetailLogMapper, CuMemberRetailLog> implements ICuMemberRetailLogService {

    @Override
    public List<CuMemberRetailLog> queryCuMemberRetailLog() {
        LambdaQueryWrapper<CuMemberRetailLog> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(CuMemberRetailLog::getEnableStatus, EYesNo.NO.getIntValue());
        Date endTime = DateUtils.currentDateTime();
        Date startTime = DateUtils.beforeDate(1, ChronoUnit.DAYS, endTime);
        queryWrapper.gt(CuMemberRetailLog::getCreationTime, startTime);
        queryWrapper.le(CuMemberRetailLog::getCreationTime, endTime);
        queryWrapper.orderByAsc(CuMemberRetailLog::getCreationTime);
        return baseMapper.selectList(queryWrapper);
    }

    @Override
    public void updateCuMemberRetailLogByList(List<CuMemberRetailLog> cuMemberRetailLogs) {
        baseMapper.updateCuMemberRetailLogByList(cuMemberRetailLogs);
    }
}
