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

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import cn.hutool.core.bean.BeanUtil;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.hzs.bonus.bonus.mapper.CuMemberSpeRetailMapper;
import com.hzs.bonus.bonus.param.RetailAreaParam;
import com.hzs.bonus.bonus.service.ICuMemberSpeRetailService;
import com.hzs.common.core.constant.SystemFieldConstants;
import com.hzs.common.core.utils.DateUtils;
import com.hzs.common.domain.member.bonus.CuMemberSpeRetail;
import org.apache.ibatis.annotations.Param;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import java.util.List;

/**
 * <p>
 * 秒接日志记录表 服务实现类
 * </p>
 *
 * @author hzs
 * @since 2025-01-03
 */
@Service
public class CuMemberSpeRetailServiceImpl extends ServiceImpl<CuMemberSpeRetailMapper, CuMemberSpeRetail> implements ICuMemberSpeRetailService {

    @Override
    public List<CuMemberSpeRetail> queryCuMemberSpeRetail(Integer period) {
        QueryWrapper<CuMemberSpeRetail> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("period", period);
        return baseMapper.selectList(queryWrapper);
    }
    @Transactional(rollbackFor = Exception.class)
    @Override
    public void batchSpeRetail(List<RetailAreaParam> list,Integer pkCountry,Long pkCreator) {
        List<CuMemberSpeRetail> cmsrList=new ArrayList<>();
        Date date=new Date();
        list.forEach(item ->{
            CuMemberSpeRetail cmsr= BeanUtil.copyProperties(item, CuMemberSpeRetail.class);
            cmsr.setPeriodDate(DateUtils.getStartTime(item.getSettleDate()));
            cmsr.setPkCountry(pkCountry);
            cmsr.setPkCreator(pkCreator);
            cmsr.setCreationTime(date);
            cmsrList.add(cmsr);
        });
        this.saveBatch(cmsrList);
    }

    /**
     * @description: 获取注水列表
     * @author: zhang jing
     * @date: 2025/1/6 10:34
     * @param: [param]
     * @return: java.util.List<com.hzs.bonus.bonus.param.RetailAreaParam>
     **/
    @Override
    public List<RetailAreaParam> getCuMemberSpeRetail(RetailAreaParam param) {
        return baseMapper.getCuMemberSpeRetail(param);
    }

    @Override
    public int checkCuMemberActivate(String memberCode) {
        return baseMapper.checkCuMemberActivate(memberCode);
    }


}
