package com.hzs.activity.other.service.impl;

import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.hzs.activity.base.vo.DeptMemberVO;
import com.hzs.activity.base.vo.TourismActivitVO;
import com.hzs.activity.other.mapper.AcOtherPriceDataMapper;
import com.hzs.activity.other.service.IAcOtherPriceDataService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.hzs.common.core.constant.SystemFieldConstants;
import com.hzs.common.core.enums.EDelFlag;
import com.hzs.common.domain.activity.other.AcOtherPriceData;
import com.hzs.common.domain.activity.other.ext.AcOtherPriceConfigExt;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.math.BigDecimal;
import java.util.Date;
import java.util.List;

/**
 * 活动其它奖励数据 服务实现类
 *
 * @author hzs
 * @since 2024-01-17
 */
@Service
public class AcOtherPriceDataServiceImpl extends ServiceImpl<AcOtherPriceDataMapper, AcOtherPriceData> implements IAcOtherPriceDataService {

    @Transactional(rollbackFor = Exception.class)
    @Override
    public int handleOtherPriceDataOnlyEnd(AcOtherPriceConfigExt config, Integer endPeriod) {
        // 先清除之前的数据
        clearOldData(config);

        return baseMapper.handleOtherPriceDataOnlyEnd(endPeriod, config.getPkBaseId(), config.getPkCountry());
    }

    @Transactional(rollbackFor = Exception.class)
    @Override
    public int handleOtherPriceDataAll(AcOtherPriceConfigExt config, Integer startPeriod, Integer endPeriod) {
        // 先清除之前的数据
        clearOldData(config);

        return baseMapper.handleOtherPriceDataAll(startPeriod, endPeriod, config.getPkBaseId(), config.getPkCountry());
    }

    @Override
    public int clearOldData() {
        return baseMapper.clearOldData();
    }

    /***
     * 清除之前数据
     * @param config
     */
    private void clearOldData(AcOtherPriceConfigExt config) {
        UpdateWrapper<AcOtherPriceData> updateWrapper = new UpdateWrapper<>();
        updateWrapper.eq("PK_BASE_CONFIG", config.getPkBaseId());
        updateWrapper.eq(SystemFieldConstants.DEL_FLAG, EDelFlag.UN_DELETE.getValue());
        updateWrapper.set(SystemFieldConstants.DEL_FLAG, EDelFlag.DELETE.getValue());
        updateWrapper.set(SystemFieldConstants.MODIFIED_TIME, new Date());
        this.update(updateWrapper);
    }

    /**
     * @description: 旅游奖数据查询
     * @author: zhang jing
     * @date: 2024/1/18 14:15
     * @param: [taVO]
     * @return: java.util.List<com.hzs.activity.base.vo.TourismActivitVO>
     **/
    @Override
    public List<TourismActivitVO> tourismList(TourismActivitVO taVO) {
        return baseMapper.tourismList(taVO);
    }

    /**
     * @description: 查询部门业绩
     * @author: zhang jing
     * @date: 2024/1/18 15:14
     * @param: [deptMemberVO]
     * @return: java.util.List<com.hzs.activity.base.vo.DeptMemberVO>
     **/
    @Override
    public List<DeptMemberVO> tourismDeptList(DeptMemberVO deptMemberVO) {
        return baseMapper.tourismDeptList(deptMemberVO);
    }

    @Override
    public List<AcOtherPriceData> queryMemberOtherData(Long pkBaseConfig, Long pkMember) {
        return baseMapper.queryMemberOtherData(pkBaseConfig, pkMember);
    }

    @Override
    public BigDecimal queryOrderAchieve(Long pkMember, Date startDate, Date endDate) {
        return baseMapper.queryOrderAchieve(pkMember, startDate, endDate);
    }

}
