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

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.hzs.common.core.constant.TableNameConstants;
import com.hzs.common.core.utils.DateUtils;
import com.hzs.common.core.utils.StringUtils;
import com.hzs.common.domain.member.detail.CuMemberAssess;
import com.hzs.member.detail.mapper.CuMemberAssessMapper;
import com.hzs.member.detail.service.ICuMemberAssessService;
import com.hzs.member.detail.vo.CuMemberAssessVO;
import org.springframework.stereotype.Service;

import java.util.*;

/**
 * 会员信息-会员考核记录 服务实现类
 */
@Service
public class CuMemberAssessServiceImpl extends ServiceImpl<CuMemberAssessMapper, CuMemberAssess> implements ICuMemberAssessService {

    @Override
    public List<CuMemberAssessVO> selectAssessList(CuMemberAssessVO cuMemberAssessVO, List<Integer> orderTypeList) {
        Integer year;
        if (StringUtils.isNotNull(cuMemberAssessVO) && StringUtils.isNotNull(cuMemberAssessVO.getStartDate())) {
            year = DateUtils.currentYear(cuMemberAssessVO.getStartDate());
        } else {
            year = DateUtils.currentYear(new Date());
        }
        String tableName = TableNameConstants.CU_MEMBER_ASSESS + year;
        if (StringUtils.isNotEmpty(tableName)) {
            return baseMapper.selectAssessList(tableName, cuMemberAssessVO.getPkMember(),
                    cuMemberAssessVO.getPkCountry(), cuMemberAssessVO.getAssessStatus(),
                    cuMemberAssessVO.getAssessType(), cuMemberAssessVO.getChangeType(), cuMemberAssessVO.getStartDate(),
                    cuMemberAssessVO.getEndDate(), orderTypeList, cuMemberAssessVO.getStartTradeTime(),
                    cuMemberAssessVO.getEndDateTradeTime()
            );
        }
        return null;
    }

    @Override
    public List<CuMemberAssessVO> getMemberAssessMonthList(CuMemberAssessVO cuMemberAssessVO) {
        Integer year;
        //获取期数
        Date date = new Date();
        if (StringUtils.isNotNull(cuMemberAssessVO) && StringUtils.isNotNull(cuMemberAssessVO.getStartDate())) {
            year = DateUtils.currentYear(cuMemberAssessVO.getStartDate());
        } else {
            year = DateUtils.currentYear(date);
        }
        String tableName = TableNameConstants.CU_MEMBER_ASSESS + year;
        if (StringUtils.isNotEmpty(tableName)) {
            return baseMapper.getMemberAssessMonthList(tableName, cuMemberAssessVO.getPkMember(), cuMemberAssessVO.getAssessType(),
                    cuMemberAssessVO.getPkCountry(), null);
        }
        return null;
    }

    @Override
    public CuMemberAssessVO getOrderAssessList(CuMemberAssessVO cuMemberAssessVO) {
        return baseMapper.getOrderAssessList(cuMemberAssessVO);
    }

}
