package com.hzs.report.member.service.impl;

import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.hzs.common.core.enums.EDelFlag;
import com.hzs.common.domain.report.stat.CuLianchuangDataStat;
import com.hzs.common.security.utils.SecurityUtils;
import com.hzs.report.member.mapper.CuLianchuangDataStatMapper;
import com.hzs.report.member.service.ICuLianchuangDataStatService;
import com.hzs.report.member.vo.AbroadDataStatVO;
import com.hzs.report.member.vo.CuLianchuangDataStatVO;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

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

/**
 * 联创报表统计 服务实现类
 */
@Service
public class CuLianchuangDataStatServiceImpl extends ServiceImpl<CuLianchuangDataStatMapper, CuLianchuangDataStat> implements ICuLianchuangDataStatService {

    @Override
    public List<CuLianchuangDataStatVO> lcStatList(List<CuLianchuangDataStat> lcList) {
        return baseMapper.lcStatList(lcList);
    }

    @Override
    public List<CuLianchuangDataStatVO> lcStatListByOrdeType(List<Integer> orderTypeList, Integer orderType, CuLianchuangDataStat lcDate) {
        return baseMapper.lcStatListByOrdeType(orderTypeList, orderType, lcDate);
    }

    @Override
    public List<CuLianchuangDataStatVO> newLcStatListByOrdeType(CuLianchuangDataStatVO lcDate, Long pkMember) {
        return baseMapper.newLcStatListByOrdeType(lcDate, pkMember);
    }

    @Override
    public List<CuLianchuangDataStatVO> lcStatOrdeHistoryList(CuLianchuangDataStatVO cds, CuLianchuangDataStat lcDate) {
        return baseMapper.lcStatOrdeHistoryList(cds, lcDate);
    }

    @Override
    public List<CuLianchuangDataStatVO> lcStatOrderHistorySumList(CuLianchuangDataStatVO cds, CuLianchuangDataStat lcDate) {
        return baseMapper.lcStatOrderHistorySumList(cds, lcDate);
    }

    @Override
    public List<AbroadDataStatVO> abroadStatList(List<CuLianchuangDataStatVO> pkCountryList,
                                                 String startDate,
                                                 String endDate) {
        return baseMapper.abroadStatList(pkCountryList, startDate, endDate);
    }

    @Override
    public List<CuLianchuangDataStatVO> countryList() {
        return baseMapper.countryList();
    }

    @Transactional(rollbackFor = Exception.class)
    @Override
    public boolean deleteLcStat(List<Long> pkIdList) {
        for (Long l : pkIdList) {
            LambdaUpdateWrapper<CuLianchuangDataStat> updateWrapper = new LambdaUpdateWrapper<>();
            updateWrapper.set(CuLianchuangDataStat::getDelFlag, EDelFlag.DELETE.getValue());
            updateWrapper.set(CuLianchuangDataStat::getPkModified, SecurityUtils.getUserId());
            updateWrapper.set(CuLianchuangDataStat::getModifiedTime, new Date());
            updateWrapper.eq(CuLianchuangDataStat::getPkId, l);
            baseMapper.update(null, updateWrapper);
        }
        return true;
    }
}
