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


import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.date.DateUnit;
import cn.hutool.core.date.DateUtil;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.hzs.common.core.utils.DateUtils;
import com.hzs.common.domain.member.annuity.CuMemberAnnuity;
import com.hzs.member.annuity.mapper.CuMemberAnnuityMapper;
import com.hzs.member.annuity.service.ICuMemberAnnuityService;
import com.hzs.member.base.ext.CuMemberAnnuityExt;
import com.hzs.member.base.vo.MemberAnnuityVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;
import java.util.stream.Collectors;

/**
 * <p>
 * 奖金年金明细表 服务实现类
 * </p>
 *
 * @author hzs
 * @since 2023-10-13
 */
@Service
public class CuMemberAnnuityServiceImpl extends ServiceImpl<CuMemberAnnuityMapper, CuMemberAnnuity> implements ICuMemberAnnuityService {
    @Autowired
    private ICuMemberAnnuityService memberAnnuityService;
    /**
     * 查询奖金年金列表
     * @return
     */
    @Override
    public List<MemberAnnuityVo> selectByList(String memberCode, String memberName, Integer pkAwards, Integer pkGrade, Date startDate, Date endDate,Integer pkCountry) {
        List<MemberAnnuityVo> memberAnnuityExt = baseMapper.selectByList(memberCode,memberName,pkAwards,pkGrade,startDate,endDate,pkCountry).stream().map(a -> {
            MemberAnnuityVo memberAnnuityVo = BeanUtil.copyProperties(a, MemberAnnuityVo.class);
            Long residueDays = DateUtil.between(memberAnnuityVo.getExpireDate(), DateUtils.currentDate(), DateUnit.DAY);
            memberAnnuityVo.setResidueDays(residueDays+1);
            return memberAnnuityVo;
        }).collect(Collectors.toList());
        return memberAnnuityExt;
    }

}
