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

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.hzs.bonus.detail.mapper.CuRegionAssessDetailMapper;
import com.hzs.bonus.detail.service.ICuRegionAssessDetailService;
import com.hzs.common.domain.member.detail.CuRegionAssessDetail;
import org.springframework.stereotype.Service;

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

/**
 * 新零售会员区域考核明细表 服务实现类
 */
@Service
public class CuRegionAssessDetailServiceImpl extends ServiceImpl<CuRegionAssessDetailMapper, CuRegionAssessDetail> implements ICuRegionAssessDetailService {

    @Override
    public void deleteAssessRegionDetailByDate(Date assessStartDate, Integer assessPeriod) {
        baseMapper.deleteAssessRegionDetailByDate(assessStartDate, assessPeriod);
    }

    @Override
    public void updateAssessRegionDetailByDate(Date assessStartDate, Date assessEndDate) {
        baseMapper.updateAssessRegionDetailByDate(assessStartDate, assessEndDate);
    }

    @Override
    public List<Long> batchQueryCuRegionAssessDetailSeq(Integer rowNum) {
        return baseMapper.batchQueryCuRegionAssessDetailSeq(rowNum);
    }

    @Override
    public void batchInsertCuRegionAssessDetail(List<?> cuRegionAssessDetailList) {
        baseMapper.batchInsertCuRegionAssessDetail(cuRegionAssessDetailList);
    }

    @Override
    public void assessCuRegionAssessDetail(String rangeTableName, Date assessDate) {
        // 处理考核明细的汇总值
        baseMapper.mergeCuRegionAssessDetailTeamPv(rangeTableName, assessDate);
        // 处理考核明细的小区
        baseMapper.mergeCuRegionAssessDetailSmallAreaPv(rangeTableName, assessDate);
        // 所有考核先变为考核失败
        baseMapper.updateCuRegionAssessDetailInit(assessDate);
        // 验证汇总业绩和小区业绩是否满足条件，汇总业绩满足30000，小区满足100000，变更为考核通过
        baseMapper.updateCuRegionAssessDetailByPv(assessDate);
    }
}
