package com.kxs.user.biz.service.impl;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.kxs.common.security.util.SecurityUtils;
import com.kxs.user.api.model.KxsUser;
import com.kxs.user.api.vo.kxsapp.shareholder.ShareholderGetMyStandardsAllVO;
import com.kxs.user.api.vo.kxsapp.shareholder.ShareholderGetMyStandardsVO;
import com.kxs.user.api.vo.kxsapp.subGetShareholderUserList.UserScoreListVO;
import com.kxs.user.biz.mapper.KxsShdScoreMapper;
import com.kxs.user.api.model.KxsShdScore;
import com.kxs.user.biz.mapper.KxsUserMapper;
import com.kxs.user.biz.service.KxsShdScoreService;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 股东大盘分红用户积分表(KxsShdScore)表服务实现类
 *
 * @author 系统
 * @since 2024-05-07 09:11:27
 */
@Service("kxsShdScoreService")
@RequiredArgsConstructor
public class KxsShdScoreServiceImpl extends ServiceImpl<KxsShdScoreMapper, KxsShdScore> implements KxsShdScoreService {
    private final KxsShdScoreMapper kxsShdScoreMapper;
    private final KxsUserMapper kxsUserMapper;
    @Override
    public Object getMyStandards(String month) {
        Long id = SecurityUtils.getUser().getId();
        KxsUser kxsUser = kxsUserMapper.selectById(id);
        //获取个人积分
        ShareholderGetMyStandardsVO shareholderGetMyStandardsVO = kxsShdScoreMapper.getMyStandards(month,kxsUser.getUserCode());
        //获取全国积分
        ShareholderGetMyStandardsAllVO allVO = kxsShdScoreMapper.getMyStandardsAll(month);
        if (allVO != null){
            shareholderGetMyStandardsVO.setCenterScoreAll(allVO.getCenterScoreAll());
            shareholderGetMyStandardsVO.setFirstScoreAll(allVO.getFirstScoreAll());
            shareholderGetMyStandardsVO.setHighScoreAll(allVO.getHighScoreAll());
        }
        return shareholderGetMyStandardsVO;
    }

    @Override
    public Object getShareholderUserList(Page<KxsShdScore> page, String month, Integer type) {
        Page<UserScoreListVO> shareholderHighScoreUserList = kxsShdScoreMapper.getShareholderHighScoreUserList(page, month, type);
        for (UserScoreListVO record : shareholderHighScoreUserList.getRecords()) {
            String userCode = record.getUserCode();
            //获取用户头像
            KxsUser kxsUser = kxsUserMapper.selectOne(Wrappers.<KxsUser>query().lambda().eq(KxsUser::getUserCode, userCode));
            if (kxsUser != null){
                record.setAvatar(kxsUser.getAvatar());
            }
        }
        return shareholderHighScoreUserList;
    }

    @Override
    public void integralStat() {
        //初级积分
        //获取全部用户职级 > K3
        //循环用户查询直属用户数量大于3
        Long aLong = kxsUserMapper.selectCount(Wrappers.<KxsUser>query().lambda().eq(KxsUser::getPid, 1));
        if (aLong > 3){
            List<KxsUser> kxsUsers = kxsUserMapper.selectList(Wrappers.<KxsUser>query().lambda().eq(KxsUser::getPid, 1));
        }

    }



























}

