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

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.utils.DateUtils;
import com.hzs.common.domain.member.bonus.CuMemberSpeRetail;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

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

/**
 * 注水盒数 服务实现类
 */
@Service
public class CuMemberSpeRetailServiceImpl extends ServiceImpl<CuMemberSpeRetailMapper, CuMemberSpeRetail> implements ICuMemberSpeRetailService {

    @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);
    }

    @Override
    public List<RetailAreaParam> getCuMemberSpeRetail(RetailAreaParam param) {
        return baseMapper.getCuMemberSpeRetail(param);
    }

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

}
