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

import com.hzs.common.core.utils.DateUtils;
import com.hzs.common.domain.member.achieve.ext.CuMemberAchieveExt;
import com.hzs.member.achieve.ICuMemberSettlePeriodServiceApi;
import com.hzs.report.member.mapper.MemberMapper;
import com.hzs.report.member.param.CuMemberUmbrellaParam;
import com.hzs.report.member.service.IMemberService;
import com.hzs.report.member.vo.CuMemberUmbrellaBalanceVO;
import com.hzs.report.member.vo.UmbrellaBelowPushVO;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.time.temporal.ChronoUnit;
import java.util.Date;
import java.util.List;

/**
 * 会员
 */
@Service
public class MemberServiceImpl implements IMemberService {

    @Resource
    private MemberMapper memberMapper;

    @DubboReference
    ICuMemberSettlePeriodServiceApi cuMemberSettlePeriodServiceApi;

    @Override
    public List<CuMemberUmbrellaBalanceVO> selectUmbrellaLowerBalance(CuMemberUmbrellaBalanceVO umbrellaBalanceVO) {
        return memberMapper.selectUmbrellaLowerBalance(umbrellaBalanceVO);
    }

    @Override
    public List<CuMemberAchieveExt> queryParentCuMemberAchieveExt(CuMemberUmbrellaParam cuMemberUmbrellaParam) {
        Date settleDate = DateUtils.beforeDate(1, ChronoUnit.DAYS);
        Integer period = cuMemberSettlePeriodServiceApi.getCuMemberSettlePeriodByDate(DateUtils.currentMonthFirstDateStr(settleDate)).getData().getPkId();
        return memberMapper.queryParentParentCuMemberAchieveExt(period, cuMemberUmbrellaParam);
    }

    @Override
    public List<UmbrellaBelowPushVO> queryUmbrellaBelowPush(UmbrellaBelowPushVO umbrellaBelowPushVO) {
        return memberMapper.queryUmbrellaBelowPush(umbrellaBelowPushVO);
    }

    @Override
    public List<UmbrellaBelowPushVO> queryOrderExpend(UmbrellaBelowPushVO umbrellaBelowPushVO) {
        return memberMapper.queryOrderExpend(umbrellaBelowPushVO);
    }

}
