package com.td.Dawa.game.comcharactersdiscovery.service;

import cn.hutool.core.convert.Convert;
import cn.hutool.core.date.DateUnit;
import cn.hutool.core.date.DateUtil;
import cn.hutool.core.util.ArrayUtil;
import cn.hutool.core.util.NumberUtil;
import com.td.Dawa.common.pojo.PageInfo;
import com.td.Dawa.common.service.*;
import com.td.Dawa.config.enums.GameEnum;
import com.td.Dawa.config.enums.ResultEnum;
import com.td.Dawa.config.exception.AuthorizeException;
import com.td.Dawa.game.comcharacters.pojo.ComCharacters;
import com.td.Dawa.game.comcharacters.service.ComCharactersService;
import com.td.Dawa.game.comcharacters.vo.ComCharactersClientVo;
import com.td.Dawa.game.comcharacters.vo.ComCharactersVo;
import com.td.Dawa.game.comcharactersdiscovery.pojo.ComCharactersDiscovery;
import com.td.Dawa.game.comcharactersdiscovery.vo.ComCharactersDiscoveryClientVo;
import com.td.Dawa.game.comcharactersdiscovery.vo.ComCharactersDiscoveryVo;
import com.td.Dawa.game.comcharactersdiscovery.repository.ComCharactersDiscoveryRepository;
import com.td.Dawa.game.complayerbackpack.service.ComPlayerBackpackService;
import com.td.Dawa.game.complayerbackpack.vo.ComPlayerBackpackVo;
import com.td.Dawa.game.complayersattri.service.ComPlayersAttriService;
import com.td.Dawa.game.complayersattri.vo.ComPlayersAttriVo;
import com.td.Dawa.game.comusers.service.ComUsersService;
import com.td.Dawa.game.comusers.vo.ComUsersVo;
import com.td.Dawa.game.excelcharactercreate.service.ExcelCharacterCreateService;
import com.td.Dawa.game.excelcharacterlevel.pojo.ExcelCharacterLevel;
import com.td.Dawa.game.excelcharacterlevel.service.ExcelCharacterLevelService;
import com.td.Dawa.game.excelcharacterlevel.vo.ExcelCharacterLevelVo;
import com.td.Dawa.game.exceldrop.service.ExcelDropService;
import com.td.Dawa.game.excelparameter.pojo.ExcelParameter;
import com.td.Dawa.game.excelparameter.service.ExcelParameterService;
import com.td.Dawa.game.excelparameter.vo.ExcelParameterVo;
import com.td.Dawa.game.excelprop.pojo.ExcelProp;
import com.td.Dawa.game.excelprop.service.ExcelPropService;
import com.td.Dawa.game.excelprop.vo.ExcelPropAndProVo;
import com.td.Dawa.game.excelprop.vo.ExcelPropClientVo;
import com.td.Dawa.game.excelresources.service.ExcelResourcesService;
import com.td.Dawa.game.excelscene.pojo.ExcelScene;
import com.td.Dawa.game.excelscene.service.ExcelSceneService;
import com.td.Dawa.game.excelworkpro.pojo.ExcelWorkPro;
import com.td.Dawa.game.excelworkpro.service.ExcelWorkProService;
import com.td.Dawa.util.CopyUtil;
import com.td.Dawa.util.ProbabilityIntervalUtil;
import com.td.Dawa.util.UUIDUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.StringUtils;

import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import java.util.*;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.stream.Collectors;

@Service
@Transactional
@Slf4j
public class ComCharactersDiscoveryServiceImpl extends CommonServiceImpl<ComCharactersDiscoveryVo, ComCharactersDiscovery, Integer> implements ComCharactersDiscoveryService {

    @PersistenceContext
    private EntityManager em;
    @Autowired
    private ComCharactersDiscoveryRepository comCharactersDiscoveryRepository;

    @Autowired
    private ComCharactersService comCharactersService;

    @Autowired
    private ExcelDropService excelDropService;

    @Autowired
    private ExcelSceneService excelSceneService;

    @Autowired
    private ExcelCharacterLevelService excelCharacterLevelService;

    @Autowired
    private ComPlayersAttriService comPlayersAttriService;

    @Autowired
    private ExcelParameterService excelParameterService;

    @Autowired
    private ExcelResourcesService excelResourcesService;

    @Autowired
    private ExcelCharacterCreateService excelCharacterCreateService;

    @Autowired
    private ExcelWorkProService excelWorkProService;
    @Autowired
    private ExcelPropService excelPropService;

    @Autowired
    private ComPlayerBackpackService comPlayerBackpackService;

    @Autowired
    private ComUsersService comUsersService;

    /**
     * 开始工作
     *
     * @param userId
     * @param sceneId
     * @return
     */
    @Override
    public ComCharactersDiscoveryClientVo startDiscover(String userId, Integer sceneId) {

        ComCharactersDiscovery comCharacterDiscovery =
                comCharactersDiscoveryRepository.findByUserIdAndSceneId(userId, sceneId).orElse(null);
        if (comCharacterDiscovery == null || !StringUtils.hasText(comCharacterDiscovery.getRoleId())) {
            throw new AuthorizeException(ResultEnum.EXPLORATION_INFO_NULL);
        } else {
            if (comCharacterDiscovery.getIsWork().equals(GameEnum.WORK_ING.getValue())) {
                throw new AuthorizeException(ResultEnum.EXPLORATION_ING);
            }
            if (comCharacterDiscovery.getIsWork().equals(GameEnum.WORK_COMPLETE.getValue())) {
                throw new AuthorizeException(ResultEnum.EXPLORATION_COMPLETE);
            }

            //设置工作状态，设置工作开始时间
            comCharacterDiscovery.setIsWork(GameEnum.WORK_ING.getValue());
            comCharacterDiscovery.setWorkStart(DateUtil.date());

            ExcelParameterVo maxStrength = excelParameterService.getVo(1);
            ExcelParameterVo workConsumesStrength = excelParameterService.getVo(2); //消耗的体力单位
            if (maxStrength == null || workConsumesStrength == null) {
                throw new AuthorizeException(ResultEnum.SETTING_IS_NULL);
            }
            //todo 扣除一个体力值,判断是否超过设置的体力值
            ComPlayersAttriVo attriVo = comPlayersAttriService.findByUserId(userId);
            Integer _strength = attriVo.getStrength() + workConsumesStrength.getValue().intValue();
            if (maxStrength.getValue().intValue() < _strength) {
                //假如设置的值小于当前计算的体力，返回提示 当前体力不足，队伍无法工作
                throw new AuthorizeException(ResultEnum.PLAYER_ATTRIBUTE_STRENGTH_IS_NOT);
            }
            //消耗一个体力值(+1)
            attriVo.setStrength(_strength);
            comPlayersAttriService.save(attriVo);
        }
        ComCharactersDiscoveryVo comCharacterDiscoveryVo = CopyUtil.copy(comCharacterDiscovery, ComCharactersDiscoveryVo.class);
        //存储
        ComCharactersDiscoveryVo discoveryVo = super.save(comCharacterDiscoveryVo).getData();
        //先找出三个职业对象
        String[] roleId = discoveryVo.getRoleId().split("\\|");
        Integer[] _roleIds = Convert.toIntArray(roleId);
        List<ComCharacters> characters = comCharactersService.findByRoleIdIn(_roleIds);
        ComCharactersDiscoveryClientVo discoveryClientVo = CopyUtil.copy(discoveryVo, ComCharactersDiscoveryClientVo.class);
        //找出资源
        List<ComCharactersClientVo> comCharactersClientVos = characters.stream().map(e -> {
            ComCharactersClientVo comCharactersClientVo = new ComCharactersClientVo();
            comCharactersClientVo = CopyUtil.copy(e, ComCharactersClientVo.class);
            comCharactersClientVo = comCharactersService.addSubResourcesClientListToVO(comCharactersClientVo, e.getModelId(), e.getModelColor());
            return comCharactersClientVo;
        }).collect(Collectors.toList());
        discoveryClientVo.setSubCharacters(comCharactersClientVos);//当前职业
        // 把当前时间设置到mill中
        discoveryClientVo.setWorkMill(discoveryVo.getWorkDay().longValue());
        //设置携带属性
        discoveryClientVo = setDiscoveryClientVoProAndTransNum(discoveryClientVo);

        //存储并且返回
        return discoveryClientVo;
    }

    /**
     * 添加角色,根据当前位置，设置工作类型，就是当前professional（1,2,3,4）
     *
     * @param charactersVo
     * @param sceneId
     * @return
     */
    @Override
    public ComCharactersDiscoveryClientVo addDiscoverRole(ComCharactersVo charactersVo, Integer sceneId) {

        //角色list
        List<ComCharactersClientVo> comCharactersClientVos = new ArrayList<>();
        ComCharactersDiscovery comCharacterDiscovery =
                comCharactersDiscoveryRepository.findByUserIdAndSceneId(charactersVo.getUserId(), sceneId).orElse(null);
        if (comCharacterDiscovery == null) {
            comCharacterDiscovery = new ComCharactersDiscovery();
            //新建一个队伍
            comCharacterDiscovery.setUserId(charactersVo.getUserId());
            comCharacterDiscovery.setRoleId(charactersVo.getId().toString());
            //comCharacterDiscovery.setName();
            comCharacterDiscovery.setIsWork(GameEnum.WORK_NOT_STARTED.getValue());//默认不工作
            comCharacterDiscovery.setWorkStart(DateUtil.date());
            ExcelParameterVo workMill = excelParameterService.getVo(6); //初始化工作时长
            comCharacterDiscovery.setWorkDay(workMill.getValue().intValue()); //工作时间，todo 暂时定60s
            comCharacterDiscovery.setWorkFlag(UUIDUtil.getUUID());
            comCharacterDiscovery.setDiscoverLevel(1); //默认探索第一层场景
            comCharacterDiscovery.setSceneId(sceneId); // 比如矿洞id对应的入口是201
            comCharacterDiscovery.setRewardExp(0); // 默认不奖励经验
            comCharacterDiscovery.setRewardCurrency(0); // 默认不奖励货币
            comCharacterDiscovery.setNote("工作队伍");

            comCharacterDiscovery.setCreateTime(DateUtil.date());
            comCharacterDiscovery.setUpdateTime(DateUtil.date());

            //没有角色，即把传入角色添加上
            comCharactersClientVos.add(CopyUtil.copy(charactersVo, ComCharactersClientVo.class));


        } else {
            //如果剩余空字符串，直接赋值
            if (StringUtils.hasText(comCharacterDiscovery.getRoleId())) {
                String[] roleIds = comCharacterDiscovery.getRoleId().split("\\|");
                Boolean isReplace = false; //是否是替换角色
                for (int i = 0; i < roleIds.length; i++) {
                    if (roleIds[i].equals(charactersVo.getId().toString())) {
                        //不能添加相同的角色,直接返回一个查询的
                        //return CopyUtil.copy(comCharacterDiscovery, ComCharactersDiscoveryVo.class);
                        throw new AuthorizeException(ResultEnum.ROLE_ALREADY_ADD);
                    } else {
                        ComCharactersVo _findCharacter = comCharactersService.getVo(Integer.parseInt(roleIds[i]));
                        //如果当前职业相同，直接替换id
                        //log.info(_findCharacter.getProfessional() + "=" + charactersVo.getProfessional());
                        //列表角色和传入的角色做对比
                        if (_findCharacter.getProfessional().equals(charactersVo.getProfessional())) {
                            //替换时候，重置旧的对象职业
                            _findCharacter.setProfessional(0);
                            _findCharacter.setWorkPos(0);
                            comCharactersService.save(_findCharacter);
                            //如职业一样，替换列表中的角色
                            roleIds[i] = charactersVo.getId().toString();
                            isReplace = true;
                            comCharactersClientVos.add(CopyUtil.copy(charactersVo, ComCharactersClientVo.class));
                        } else {
                            comCharactersClientVos.add(CopyUtil.copy(_findCharacter, ComCharactersClientVo.class));
                        }

                    }
                }
                //如果不是替换，再旧的基础上添加一个角色
                if (!isReplace) {
                    String _roleId = comCharacterDiscovery.getRoleId() + "|" + charactersVo.getId().toString();
                    //如果最后没有替换到列表，说明没有角色，即把传入角色添加上
                    comCharactersClientVos.add(CopyUtil.copy(charactersVo, ComCharactersClientVo.class));
                    comCharacterDiscovery.setRoleId(_roleId);
                } else {
                    comCharacterDiscovery.setRoleId(String.join("|", roleIds));
                }
            } else {
                comCharacterDiscovery.setRoleId(charactersVo.getId().toString());
                comCharactersClientVos.add(CopyUtil.copy(charactersVo, ComCharactersClientVo.class));
            }

            comCharacterDiscovery.setUpdateTime(DateUtil.date());
        }
        //保存一次用户修改的当前职业工作标签profession，工作位置workPos,工作结算时候，重置一次为零
        comCharactersService.save(charactersVo);

        ComCharactersDiscoveryVo comCharacterDiscoveryVo = CopyUtil.copy(comCharacterDiscovery, ComCharactersDiscoveryVo.class);
        super.save(comCharacterDiscoveryVo);
        ComCharactersDiscoveryClientVo comCharacterDiscoveryClientVo = CopyUtil.copy(comCharacterDiscoveryVo, ComCharactersDiscoveryClientVo.class);
        comCharacterDiscoveryClientVo.setSubCharacters(comCharactersClientVos);
        //设置携带属性
        comCharacterDiscoveryClientVo = setDiscoveryClientVoProAndTransNum(comCharacterDiscoveryClientVo);
        return comCharacterDiscoveryClientVo;
    }

    @Override
    public ComCharactersDiscoveryClientVo removeDiscoverRole(ComCharactersVo charactersVo, Integer sceneId) {
        //角色list
        List<ComCharactersClientVo> comCharactersClientVos = new ArrayList<>();
        ComCharactersDiscovery comCharacterDiscovery =
                comCharactersDiscoveryRepository.findByUserIdAndSceneId(charactersVo.getUserId(), sceneId).orElse(null);
        if (comCharacterDiscovery == null) {
            //如果没有工作队伍，抛出删除异常
            throw new AuthorizeException(ResultEnum.ROLE_DELETE_ERROR);
        }

        String[] roleIds = comCharacterDiscovery.getRoleId().split("\\|");
        if (!ArrayUtil.contains(roleIds, charactersVo.getId().toString())) {
            throw new AuthorizeException(ResultEnum.ROLE_NOT_TEAM);
        } else {
            int index = ArrayUtil.indexOf(roleIds, charactersVo.getId().toString());
            //删除时候，重置旧的对象职业
            charactersVo.setProfessional(0);
            charactersVo.setWorkPos(0);
            comCharactersService.save(charactersVo);
            //剩余的角色
            roleIds = ArrayUtil.remove(roleIds, index);
        }
        if (roleIds.length > 0) {
            for (int i = 0; i < roleIds.length; i++) {
                ComCharactersVo _findCharacter = comCharactersService.getVo(Integer.parseInt(roleIds[i]));
                comCharactersClientVos.add(CopyUtil.copy(_findCharacter, ComCharactersClientVo.class));
            }
            comCharacterDiscovery.setRoleId(String.join("|", roleIds));
            comCharacterDiscovery.setUpdateTime(DateUtil.date());
            ComCharactersDiscoveryVo comCharacterDiscoveryVo = CopyUtil.copy(comCharacterDiscovery, ComCharactersDiscoveryVo.class);
            super.save(comCharacterDiscoveryVo);
            ComCharactersDiscoveryClientVo comCharacterDiscoveryClientVo = CopyUtil.copy(comCharacterDiscoveryVo, ComCharactersDiscoveryClientVo.class);
            comCharacterDiscoveryClientVo.setSubCharacters(comCharactersClientVos);
            //设置携带属性
            comCharacterDiscoveryClientVo = setDiscoveryClientVoProAndTransNum(comCharacterDiscoveryClientVo);
            return comCharacterDiscoveryClientVo;
        } else {
            //没有数据处理删除
            super.delete(comCharacterDiscovery.getId());
            comCharacterDiscovery.setRoleId("");
            comCharacterDiscovery.setUpdateTime(DateUtil.date());
            ComCharactersDiscoveryVo comCharacterDiscoveryVo = CopyUtil.copy(comCharacterDiscovery, ComCharactersDiscoveryVo.class);
            ComCharactersDiscoveryClientVo comCharacterDiscoveryClientVo = CopyUtil.copy(comCharacterDiscoveryVo, ComCharactersDiscoveryClientVo.class);
            comCharacterDiscoveryClientVo.setSubCharacters(comCharactersClientVos);
            comCharacterDiscoveryClientVo = setDiscoveryClientVoProAndTransNum(comCharacterDiscoveryClientVo);
            return comCharacterDiscoveryClientVo;
        }

    }

    @Override
    public PageInfo<ComCharactersDiscoveryClientVo> findDiscoverClientVo(ComCharactersDiscoveryVo characterDiscoveryVo) {
        PageInfo<ComCharactersDiscoveryVo> comCharactersDiscoveryVo = super.page(characterDiscoveryVo).getData();
        //获取到探索队伍的数据
        List<ComCharactersDiscoveryVo> _listVo = comCharactersDiscoveryVo.getRows();
        List<ComCharactersDiscoveryClientVo> _discoveryClientVos = new ArrayList<>();
        for (ComCharactersDiscoveryVo discoveryVo : _listVo) {
            String[] roleId = discoveryVo.getRoleId().split("\\|");
            //角色list
            List<ComCharactersClientVo> comCharactersClientVos = new ArrayList<>();
            for (int i = 0; i < roleId.length; i++) {
                ComCharactersVo comCharactersVo = comCharactersService.getVo(Integer.parseInt(roleId[i]));
                ComCharactersClientVo comCharactersClientVo = CopyUtil.copy(comCharactersVo, ComCharactersClientVo.class);
                comCharactersClientVo = comCharactersService.addSubResourcesClientListToVO(comCharactersClientVo, comCharactersVo.getModelId(), comCharactersVo.getModelColor());
                comCharactersClientVos.add(comCharactersClientVo);
            }
            //开始工作时间 + 工作天数
            Date endDate = DateUtil.offsetMillisecond(discoveryVo.getWorkStart(), discoveryVo.getWorkDay());
            //
            Long dif = 0L;
            if (discoveryVo.getIsWork().equals(GameEnum.WORK_ING.getValue())) {
                //如果已经开始工作，计算当前时间与结束时间的毫秒
                dif = DateUtil.between(DateUtil.date(), endDate, DateUnit.MS, false);
                if (dif <= 0L) {
                    //工作完成
                    discoveryVo.setIsWork(GameEnum.WORK_COMPLETE.getValue());
                    super.save(discoveryVo);
                    dif = 0L;
                }
            } else {
                //还没开始工作，返回开始和结束直接的毫秒
                dif = DateUtil.between(discoveryVo.getWorkStart(), endDate, DateUnit.MS, false);
                if (dif <= 0L) {
                    dif = 0L;
                }
            }

            ComCharactersDiscoveryClientVo comCharacterDiscoveryClientVo = CopyUtil.copy(discoveryVo, ComCharactersDiscoveryClientVo.class);
            //小于等于零即完成
            comCharacterDiscoveryClientVo.setWorkMill(dif);
            comCharacterDiscoveryClientVo.setSubCharacters(comCharactersClientVos);
            //设置携带属性
            comCharacterDiscoveryClientVo = setDiscoveryClientVoProAndTransNum(comCharacterDiscoveryClientVo);
            _discoveryClientVos.add(comCharacterDiscoveryClientVo);
        }

        PageInfo<ComCharactersDiscoveryClientVo> backPageInfo = new PageInfo<>();
        backPageInfo.setRows(_discoveryClientVos);
        backPageInfo.setPage(comCharactersDiscoveryVo.getPage());
        backPageInfo.setPageSize(comCharactersDiscoveryVo.getPageSize());
        backPageInfo.setTotal(comCharactersDiscoveryVo.getTotal());
        backPageInfo.setRecords(comCharactersDiscoveryVo.getRecords());
        backPageInfo.setSidx(comCharactersDiscoveryVo.getSidx());
        backPageInfo.setSord(comCharactersDiscoveryVo.getSord());
        return backPageInfo;
    }

    /**
     * 挖矿工作状态
     * 1.工作时间未完结时候，刷新按照最后一次updateTime来判定是否重新计算产出，假如挖矿和勘探分别有不同的时间
     * 2.工作未完结时间，记录当前产出的物品和产出m
     * 3.工作完结，删除工作队列，相关产出转移背包，计算经验等。（删除的队列进入回收列表）
     * 4.可中途结束工作
     *
     * @param discoveryVo
     * @return
     */
    @Override
    public ComCharactersDiscoveryClientVo explorationState(ComCharactersDiscoveryVo discoveryVo, Boolean isStop) {
        if (discoveryVo.getIsWork().equals(GameEnum.WORK_NOT_STARTED.getValue())) {
            throw new AuthorizeException(ResultEnum.EXPLORATION_NOT_START);
        }
        //获取参数表
        List<ExcelParameter> parameterVos = excelParameterService.getListFromCache(GameEnum.REDIS_KEY_EXCEL_PARAMETER.getMessage());
        //奖励物品的时间计数
        String[] _hasDropCounts = StringUtils.hasText(discoveryVo.getRewardCount()) ? discoveryVo.getRewardCount().split("\\|") : new String[0];
        //总共参数的奖励物品
        String[] _allDropIds = StringUtils.hasText(discoveryVo.getRewardCount()) ? discoveryVo.getAllItem().split("\\|") : new String[0];
        //记录当前的产出奖励
        List<ExcelPropClientVo> outExcelProps = new ArrayList<>();
        List<ComPlayerBackpackVo> comPlayerBackpackVoList = new ArrayList<>();

        //开始工作时间 + 工作天数
        Date endDate = DateUtil.offsetMillisecond(discoveryVo.getWorkStart(), discoveryVo.getWorkDay());
        //用更新数据时间与最终偏移时间点来计算 当前的秒数，为零说明工作完成
        Long difSecond = DateUtil.between(discoveryVo.getUpdateTime(), endDate, DateUnit.SECOND, false);
        if (difSecond <= 0L) {
            difSecond = 0L;//这里difSecond是用户更新数据计算所剩余的时间
        }
        log.info("剩余计算的时长difSecond：" + difSecond);
        //当前时间与结束时间的毫秒
        Long dif = DateUtil.between(DateUtil.date(), endDate, DateUnit.MS, false);

        //判断是否结束工作 小于等于零即完成
        if (dif <= 0L) {
            discoveryVo.setIsWork(GameEnum.WORK_COMPLETE.getValue());
            dif = 0L;
        } else if (isStop) {
            //工作时长未完结，不可停止
            throw new AuthorizeException(ResultEnum.EXPLORATION_NOT_STOP);
        }

        //todo 根据场景id获取当前场景配置 后面处理缓存，提高速度
        //获取场景全部列表
        //List<ExcelScene> excelSceneList = excelSceneService.getListFromCache(GameEnum.REDIS_KEY_EXCEL_SCENE.getMessage());
        //主场景id
        ExcelScene excelScene = excelSceneService.findBySceneId(discoveryVo.getSceneId());
        if (excelScene.equals(null)) {
            throw new RuntimeException("excelScene 未配置!");
        }
        //获取当前的一个基础数量
        Integer outTransUpperLimit = excelScene.getAmount();
        //获取概率表数据（缓存取）
        List<ExcelWorkPro> workProList = excelWorkProService.getListFromCache(GameEnum.REDIS_KEY_EXCEL_WORK_PRO.getMessage());
        //获取当前道具表
        List<ExcelProp> propList = excelPropService.getListFromCache(GameEnum.REDIS_KEY_EXCEL_PROP.getMessage());

        //已经挖出的全部道具
        List<String> _allDropIdList = Arrays.asList(_allDropIds);
        List<ExcelProp> allExcelProps = propList.stream().filter(e -> _allDropIdList.contains(e.getPropId().toString())).collect(Collectors.toList());
        List<Integer> allExcelPropsIds = allExcelProps.stream().map(e -> e.getPropId()).collect(Collectors.toList());
        String[] final_hasDropCounts = _hasDropCounts;
        AtomicInteger hasDropCountsIndex = new AtomicInteger();
        List<ExcelPropClientVo> allPropClientVoList = _allDropIdList.stream().map(e -> {
            ExcelProp excelProp = allExcelProps.get(allExcelPropsIds.indexOf(Integer.parseInt(e)));
            ExcelPropClientVo _vo = CopyUtil.copy(excelProp, ExcelPropClientVo.class);
            int _miningInterval = parameterVos.get(3).getValue().intValue();//挖矿时间间隔
            int _dropCount = Integer.parseInt(ArrayUtil.get(final_hasDropCounts, hasDropCountsIndex.get()));//根据id获取记录的count
            _vo.setCreateTime(DateUtil.offsetSecond(discoveryVo.getWorkStart(), (_dropCount + 1) * _miningInterval));
            _vo.setItemNum(1);
            hasDropCountsIndex.getAndIncrement();
            return _vo;
        }).collect(Collectors.toList());

        //当前探索队伍
        String[] roleId = discoveryVo.getRoleId().split("\\|");
        Integer[] _roleIds = Convert.toIntArray(roleId);
        //角色list
        List<ComCharactersClientVo> comCharactersClientVos = new ArrayList<>();

        //先找出三个职业对象
        ComCharactersVo powerChar = null, intelliChar = null, skillChar = null;
        ExcelWorkPro _excelWorkPro = null;
        List<ExcelPropAndProVo> currentPropAndPros;//当前的道具和概率

        List<ComCharacters> characters = comCharactersService.findByRoleIdIn(_roleIds);
        //设置一个默认的基础数量
        for (int i = 0; i < characters.size(); i++) {
            ComCharactersVo comCharactersVo = CopyUtil.copy(characters.get(i), ComCharactersVo.class); //comCharactersService.getVo(Integer.parseInt(roleId[i]));
            //根据当前角色的职业计算
            Integer _professional = comCharactersVo.getProfessional();
            if (_professional.equals(GameEnum.PRO_WORK_TRANSPORT.getValue())) {
                //运输工
                skillChar = comCharactersVo;
                //计算当前运输格数，即获取到物品的上限
                //场景的最低运输数量
                Integer _selfLimit = getLimitSkillsAndList(comCharactersVo.getSkills(), workProList);
                if (_selfLimit > outTransUpperLimit) {
                    outTransUpperLimit = _selfLimit;
                }
            } else if (_professional.equals(GameEnum.PRO_WORK_MINING.getValue()) ||
                    _professional.equals(GameEnum.PRO_WORK_LUMBERING.getValue())) {
                //矿工
                powerChar = comCharactersVo;
                //获取当前工作的效率表
                _excelWorkPro = getRatioByPowerAndSceneIdAndList(powerChar.getPower(), discoveryVo.getSceneId(), workProList);

                //  每3秒执行一次挖矿动作。根据属性数值概率，获得收益
                //  矿工有休息动作，休息时间3秒
                currentPropAndPros = getPropAndPros(_excelWorkPro, discoveryVo.getDiscoverLevel(), propList);

                int _miningInterval = parameterVos.get(3).getValue().intValue();//挖矿时间间隔
                log.info("挖矿间隔时间：" + _miningInterval);
                int _count = (int) Math.floor(difSecond / _miningInterval); // 一共执行的工作次数和休息
                log.info("执行的工作次数：" + _count);
                //按次数执行奖励
                //对应物品数量少于或等于运输数量
                for (int j = 0; j < _count; j++) {
                    //采集x4+休息x1
                    if (j % 5 != 0) {
                        //工作，并且奖励物品
                        //1.先判定Probability， 2.再判定Currency是不是挖到货币或道具  3.挖到道具 再计算道具概率掉落
                        Double _getProbability = _excelWorkPro.getProbability() / 100;
                        double curRandom = new Random().nextDouble();
                        log.info("curRandom:" + curRandom + "，Probability:" + _getProbability);
                        if (NumberUtil.compare(curRandom, _getProbability) <= 0) {
                            Double _currencyPro = Double.parseDouble(_excelWorkPro.getCurrency() + "") / 100;
                            log.info("掉落货币概率: " + _currencyPro);
                            ExcelPropClientVo _propClientVo;
                            log.info("是否掉落物品：" + NumberUtil.compare(curRandom, _currencyPro));
                            if (NumberUtil.compare(curRandom, _currencyPro) > 0) {//物品概率
                                //获取当前抽中的物品
                                ExcelPropAndProVo excelPropAndProVo = ProbabilityIntervalUtil.getProp(currentPropAndPros, 100);
                                _propClientVo = CopyUtil.copy(excelPropAndProVo, ExcelPropClientVo.class);
                                log.info("随机道具" + _propClientVo.getPropId());
                                //产生物品，直接添加
                                _allDropIds = ArrayUtil.append(_allDropIds, _propClientVo.getPropId().toString());
                                _propClientVo.setItemNum(1);
                                //这里的时间返回一个开始工作时候和偏移的值
                                _propClientVo.setCreateTime(DateUtil.offsetSecond(discoveryVo.getWorkStart(), (j + 1) * _miningInterval));
                                _hasDropCounts = ArrayUtil.append(_hasDropCounts, j + "");//新添加一个挖出的时间
                                allPropClientVoList.add(_propClientVo);
                            } else {
                                ////剩余获得货币
                                //List<ExcelProp> currencyProp = propList.stream().filter(e -> e.getItemType().equals(1)).collect(Collectors.toList());
                                ////todo 暂时随机两种货币添加
                                //int index = (int) Math.floor(Math.random() * currencyProp.size());
                                //_propClientVo = CopyUtil.copy(currencyProp.get(index), ExcelPropClientVo.class);
                                //log.info("随机道具货币" + _propClientVo.getPropId());
                                ////todo 货币数据未给出，暂定100
                                ExcelParameterVo _currency = excelParameterService.getVo(8);
                                int _num = (int) Math.round(_currency.getValue());
                                discoveryVo.setRewardCurrency(discoveryVo.getRewardCurrency() == null ? _num : discoveryVo.getRewardCurrency() + _num);
                            }
                            ////产生物品，直接添加
                            //_allDropIds = ArrayUtil.append(_allDropIds, _propClientVo.getPropId().toString());
                            //_propClientVo.setItemNum(1);
                            ////这里的时间返回一个开始工作时候和偏移的值
                            //_propClientVo.setCreateTime(DateUtil.offsetSecond(discoveryVo.getWorkStart(), (j + 1) * _miningInterval));
                            //_hasDropCounts = ArrayUtil.append(_hasDropCounts, j + "");//新添加一个挖出的时间
                            //allPropClientVoList.add(_propClientVo);
                        }
                    }
                }
            } else if (_professional.equals(GameEnum.PRO_WORK_PROSPECT.getValue())) {
                //勘测地形
                intelliChar = comCharactersVo;

                //勘测地形，用于进入下层场景的职业
                //每15秒执行一次勘探。根据属性数值概率，前往下层洞穴
                if (!discoveryVo.getDiscoverLevel().equals(GameEnum.LIMIT_LEVEL.getValue())) {
                    Integer _intelligence = intelliChar.getIntelligence();
                    int _explorationInterval = parameterVos.get(4).getValue().intValue();//挖矿时间间隔
                    log.info("勘探间隔时间：" + _explorationInterval);
                    int _count = (int) Math.floor(difSecond / _explorationInterval); // 一共执行勘探的次数
                    //按次数执行奖励
                    for (int j = 0; j < _count; j++) {
                        //计算是否进入下一层的概率
                        double _nextRatio = gotoNextSceneRatioAndList(discoveryVo.getDiscoverLevel(), _intelligence, workProList);
                        if (NumberUtil.compare(new Random().nextDouble(), _nextRatio) <= 0) {
                            //todo 切换关卡的奖励物品
                            Integer _currentLevel = discoveryVo.getDiscoverLevel() + 1;
                            discoveryVo.setDiscoverLevel(_currentLevel);
                            super.save(discoveryVo); // 更新数据
                            //切换场景id
                            if (_excelWorkPro != null) {
                                //道具和道具对应的概率
                                currentPropAndPros = getPropAndPros(_excelWorkPro, _currentLevel, propList);
                            }

                        }
                    }
                }
            }
        }

        //记录一个物品获得情况
        String _rewardCounts = String.join("|", _hasDropCounts);
        String _allItems = String.join("|", _allDropIds);
        discoveryVo.setRewardCount(_rewardCounts);
        discoveryVo.setAllItem(_allItems);

        //保存挖矿数据
        //设置一次updateTime
        discoveryVo.setUpdateTime(DateUtil.date());
        //取最开始挖的 outTransUpperLimit 数量物品
        outExcelProps = allPropClientVoList.stream().limit(outTransUpperLimit).collect(Collectors.toList());

        //当前关卡奖励的经验,按获得算
        Integer outExp = outExcelProps.stream().mapToInt(ExcelPropClientVo::getItemExp).sum();
        discoveryVo.setRewardExp(outExp);
        //todo 工作完成后，isStop
        if (discoveryVo.getIsWork().equals(GameEnum.WORK_COMPLETE.getValue()) && isStop) {

            comCharactersClientVos = characters.stream().map(e -> {
                ComCharactersVo comCharactersVo = CopyUtil.copy(e, ComCharactersVo.class);
                ComCharactersClientVo comCharactersClientVo = upgradeComCharactersVo(comCharactersVo, outExp);
                //设置保存的经验
                comCharactersVo.setExp(comCharactersClientVo.getExp());
                comCharactersVo.setLevel(comCharactersClientVo.getLevel());
                comCharactersVo.setProfessional(GameEnum.PRO_WORK_NORMAL.getValue());
                comCharactersVo.setWorkPos(0);
                comCharactersService.save(comCharactersVo);
                comCharactersClientVo = comCharactersService.addSubResourcesClientListToVO(comCharactersClientVo, e.getModelId(), e.getModelColor());
                return comCharactersClientVo;
            }).collect(Collectors.toList());

            //保存金币
            comUsersService.addGold(discoveryVo.getUserId(), discoveryVo.getRewardCurrency());

            //把奖励物品保存到背包
            comPlayerBackpackService.saveAllByUserIdAndProps(discoveryVo.getUserId(), outExcelProps);
            //删除对应的队伍
            super.delete(discoveryVo.getId());
        } else {
            //只显示已获得的经验和添加对应的部件
            comCharactersClientVos = characters.stream().map(e -> {
                ComCharactersVo comCharactersVo = CopyUtil.copy(e, ComCharactersVo.class);
                ComCharactersClientVo comCharactersClientVo = upgradeComCharactersVo(comCharactersVo, outExp);
                comCharactersClientVo = comCharactersService.addSubResourcesClientListToVO(comCharactersClientVo, e.getModelId(), e.getModelColor());
                return comCharactersClientVo;
            }).collect(Collectors.toList());
            //todo 后续优化，不用每次都存储
            super.save(discoveryVo);
        }
        ComCharactersDiscoveryClientVo discoveryClientVo = CopyUtil.copy(discoveryVo, ComCharactersDiscoveryClientVo.class);
        discoveryClientVo.setSubCharacters(comCharactersClientVos);//当前职业
        discoveryClientVo.setWorkMill(dif);//倒计时
        //输出限制
        discoveryClientVo.setSubGetDrops(outExcelProps);//当前收获的物品
        //全部的奖励物品
        discoveryClientVo.setSubAllDrops(allPropClientVoList);
        //设置携带属性
        discoveryClientVo = setDiscoveryClientVoProAndTransNum(discoveryClientVo);
        return discoveryClientVo;
    }

    //private ComCharactersClientVo addSubResourcesClientList(ComCharactersClientVo comCharactersClientVo ,String _modelIdStr){
    //    Integer[] _modelIdArray = Convert.toIntArray(_modelIdStr.split("\\|"));
    //    //查询position
    //    List<ExcelCharacterCreate> _genList = excelCharacterCreateService.findByModelIn(_modelIdArray);
    //    List<ExcelResourcesClientVo> resourcesList = excelResourcesService.findByArtIdIn(_modelIdArray).stream().map(_res -> {
    //        ExcelCharacterCreate excelCharacterCreate = _genList.stream().filter(_gen -> _gen.getModel().equals(_res.getArtId())).findFirst().get();
    //        _res.setPosition(excelCharacterCreate.getPosition());
    //        return _res;
    //    }).collect(Collectors.toList());
    //    comCharactersClientVo.setSubResourcesClientList(resourcesList);
    //    return comCharactersClientVo;
    //}

    /**
     * 存储
     *
     * @param comCharactersVo
     */
    private ComCharactersClientVo upgradeComCharactersVo(ComCharactersVo comCharactersVo, Integer outExp) {
        if (comCharactersVo.getExp() == null) {
            throw new RuntimeException("upgrade characters exp is null！");
        }
        if (comCharactersVo.getLevel() == null) {
            throw new RuntimeException("upgrade characters level is null！");
        }
        //List<ExcelCharacterLevel> levelList = excelCharacterLevelService.getListFromCache(GameEnum.REDIS_KEY_EXCEL_CHARACTER_LEVEL.getMessage());
        //记录之前的经验和等级
        Integer _previousExp = comCharactersVo.getExp();
        Integer _previousLevel = comCharactersVo.getLevel();

        Integer _level = comCharactersVo.getLevel(); // 当前人物等级 这里等级至少是1级
        Integer _exp = comCharactersVo.getExp() + outExp;
        //不是满级的情况下，才处理升级
        ExcelCharacterLevel nextLevel = excelCharacterLevelService.getNextLevelInfo(_level);
        if (_level < nextLevel.getId()) {
            //Integer next_level = _level + 1; //下一级
            //ExcelCharacterLevel nextLevelVo = levelList.stream().filter(e -> e.getId().equals(next_level)).findFirst().get();
            while (_exp > nextLevel.getExp()) {
                _exp -= nextLevel.getExp();
                _level += 1;//提升一级

                //增加的属性
                Integer cPower = nextLevel.getPower() + comCharactersVo.getPower();
                Integer cSkill = nextLevel.getSkill() + comCharactersVo.getSkills();
                Integer cIntelligence = nextLevel.getIntelligence() + comCharactersVo.getIntelligence();
                int randomAttr = (int) Math.ceil(Math.random() * nextLevel.getRandomAttr());
                double addRandom = Math.random();
                if (addRandom < 0.33) {
                    cPower += randomAttr;
                } else if (addRandom >= 0.33 && addRandom < 0.66) {
                    cSkill += randomAttr;
                } else {
                    cIntelligence += randomAttr;
                }
                comCharactersVo.setPower(cPower);
                comCharactersVo.setSkills(cSkill);
                comCharactersVo.setIntelligence(cIntelligence);

                //获取下一级
                //Integer next_level2 = _level + 1;
                //nextLevelVo = levelList.stream().filter(e -> e.getId().equals(next_level2)).findFirst().get();
                nextLevel = excelCharacterLevelService.getNextLevelInfo(_level);
            }
            //最后的等级和经验
            comCharactersVo.setLevel(_level);
            comCharactersVo.setExp(_exp);

            ComCharactersClientVo comCharactersClientVo = CopyUtil.copy(comCharactersVo, ComCharactersClientVo.class);
            //返回当前需要升级的经验
            comCharactersClientVo.setLevelUpExp(nextLevel.getExp());
            //返回给前端工作前的经验和等级
            comCharactersClientVo.setPreviousExp(_previousExp);
            comCharactersClientVo.setPreviousLevel(_previousLevel);
            return comCharactersClientVo;
        } else {
            //经验直接设置
            comCharactersVo.setExp(_exp);
            //返回当前级别的数据
            Integer cur_level = _level; //当前级
            //ExcelCharacterLevel curLevelVo = levelList.stream().filter(e -> e.getId().equals(cur_level)).findFirst().get();
            ComCharactersClientVo comCharactersClientVo = CopyUtil.copy(comCharactersVo, ComCharactersClientVo.class);
            //返回当前需要升级的经验
            comCharactersClientVo.setLevelUpExp(nextLevel.getExp());
            //返回给前端工作前的经验和等级
            comCharactersClientVo.setPreviousExp(_previousExp);
            comCharactersClientVo.setPreviousLevel(_previousLevel);
            return comCharactersClientVo;
        }


    }


    /**
     * 设置discoveryClientVo带的两个概率和一个运输数量
     *
     * @param clientVo
     * @return
     */
    private ComCharactersDiscoveryClientVo setDiscoveryClientVoProAndTransNum(ComCharactersDiscoveryClientVo clientVo) {
        //获取概率表数据（缓存取）
        List<ExcelWorkPro> workProList = excelWorkProService.getListFromCache(GameEnum.REDIS_KEY_EXCEL_WORK_PRO.getMessage());
        //主场景id
        ExcelScene excelScene = excelSceneService.findBySceneId(clientVo.getSceneId());
        if (excelScene.getAmount() == null) {
            throw new RuntimeException("excelScene amount is null");
        }
        Integer outTransUpperLimit = excelScene.getAmount();
        clientVo.setTransQuantity(outTransUpperLimit);

        List<ComCharactersClientVo> voList = clientVo.getSubCharacters();
        for (int i = 0; i < clientVo.getSubCharacters().size(); i++) {
            ComCharactersClientVo charactersClientVo = voList.get(i);
            Integer _professional = charactersClientVo.getProfessional();
            if (_professional.equals(GameEnum.PRO_WORK_TRANSPORT.getValue())) {
                //_professional.equals(GameEnum.PRO_SKIlLS.getValue())
                //运输工
                //计算当前运输格数，即获取到物品的上限
                //场景的最低运输数量
                Integer _selfLimit = getLimitSkillsAndList(charactersClientVo.getSkills(), workProList);
                if (_selfLimit > outTransUpperLimit) {
                    clientVo.setTransQuantity(_selfLimit);
                }
            } else if (_professional.equals(GameEnum.PRO_WORK_MINING.getValue()) ||
                    _professional.equals(GameEnum.PRO_WORK_LUMBERING.getValue())) {
                //_professional.equals(GameEnum.PRO_POWER.getValue())
                //矿工
                ExcelWorkPro excelWorkPro = getRatioByPowerAndSceneIdAndList(charactersClientVo.getPower(), clientVo.getSceneId(), workProList);
                //todo 这个概率可能还要计算
                clientVo.setPowerPro(excelWorkPro.getProbability());
            } else if (_professional.equals(GameEnum.PRO_WORK_PROSPECT.getValue())) {
                //_professional.equals(GameEnum.PRO_INTELLIGENCE.getValue())
                //勘测地形
                clientVo.setIntelliPro(gotoNextSceneRatioAndList(clientVo.getDiscoverLevel(), charactersClientVo.getIntelligence(), workProList));
            }
        }
        return clientVo;
    }

    /**
     * 直接设置获得道具的概率
     *
     * @param value       当前力量值
     * @param mainSceneId 主场景id
     * @param workProList
     * @return
     */
    private ExcelWorkPro getRatioByPowerAndSceneIdAndList(Integer value, Integer mainSceneId, List<ExcelWorkPro> workProList) {
        //取最接近value的一个最小值
        if (mainSceneId.equals(GameEnum.MINE_00.getValue())) {
            //如果是挖矿场景id
            ExcelWorkPro excelWorkPro = workProList.stream().filter(e -> e.getProfessionalType().equals(1) && e.getAttribute() <= value).max(Comparator.comparing(u -> u.getAttribute())).get();
            return excelWorkPro;
        } else if (mainSceneId.equals(GameEnum.LUMBERING_00.getValue())) {
            //如果是伐木场景id
            List<ExcelWorkPro> workPros = workProList.stream().filter(e -> e.getProfessionalType().equals(4) && e.getAttribute() >= value).collect(Collectors.toList());

            log.info(workPros.toString());
            ExcelWorkPro excelWorkPro = workProList.stream().filter(e -> e.getProfessionalType().equals(4) && e.getAttribute() <= value).max(Comparator.comparing(u -> u.getAttribute())).get();
            return excelWorkPro;
        } else {
            throw new RuntimeException("No mainSceneId value");
        }
    }

    private double getRatioByPower(Integer value) {
        double _ratio = 0d;
        if (value >= GameEnum.ATTRIBUTE_01.getValue() && value < GameEnum.ATTRIBUTE_02.getValue()) {
            //60~100
            _ratio = 0.004;
        } else if (value < GameEnum.ATTRIBUTE_03.getValue()) {
            //100~140
            _ratio = 0.006;
        } else if (value < GameEnum.ATTRIBUTE_04.getValue()) {
            //140~180
            _ratio = 0.01;
        } else if (value < GameEnum.ATTRIBUTE_05.getValue()) {
            //180~220
            _ratio = 0.015;
        } else if (value < GameEnum.ATTRIBUTE_06.getValue()) {
            //220~260
            _ratio = 0.02;
        } else {
            //>=260
            _ratio = 0.025;
        }
        return _ratio;
    }

    /**
     * 根据当前场景的层级和属性值获取一个进入下个场景的概率
     *
     * @param sceneLevel
     * @param value
     * @return
     */
    private double gotoNextSceneRatioAndList(Integer sceneLevel, Integer value, List<ExcelWorkPro> workProList) {
        //取最接近value的一个最小值
        ExcelWorkPro excelWorkPro = workProList.stream().filter(e -> e.getProfessionalType().equals(2) && e.getAttribute() <= value).max(Comparator.comparing(u -> u.getAttribute())).get();
        String[] exploration = excelWorkPro.getExploration().split("\\|");//层级参数
        String[] enterPro = excelWorkPro.getEnterPro().split("\\|");//层级参数对应的概率
        Double _ratio = 0d;
        String netLevel = String.valueOf(sceneLevel + 1);
        if (ArrayUtil.contains(exploration, netLevel)) {
            int index = ArrayUtil.indexOf(exploration, netLevel);
            log.info(Integer.parseInt(ArrayUtil.get(enterPro, index)) + "");
            _ratio = Double.parseDouble(ArrayUtil.get(enterPro, index)) / 100;
        }
        return _ratio;
    }

    private double gotoNextSceneRatio(Integer sceneLevel, Integer value) {
        double _ratio = 0d;
        if (value >= GameEnum.ATTRIBUTE_01.getValue() && value < GameEnum.ATTRIBUTE_02.getValue()) {
            //60~100
            if (sceneLevel.equals(1)) {
                _ratio = 0.04;  // 1=>2
            }
        } else if (value < GameEnum.ATTRIBUTE_03.getValue()) {
            //100~140
            _ratio = 0.006;
            if (sceneLevel.equals(1)) {
                _ratio = 0.11;  // 1=>2
            } else if (sceneLevel.equals(2)) {
                _ratio = 0.1;  // 2=>3
            }
        } else if (value < GameEnum.ATTRIBUTE_04.getValue()) {
            //140~180
            if (sceneLevel.equals(1)) {
                _ratio = 0.23;  // 1=>2
            } else if (sceneLevel.equals(2)) {
                _ratio = 0.03;  // 2=>3
            } else if (sceneLevel.equals(3)) {
                _ratio = 0.01;  // 3=>4
            }
        } else if (value < GameEnum.ATTRIBUTE_05.getValue()) {
            //180~220
            if (sceneLevel.equals(1)) {
                _ratio = 0.34;  // 1=>2
            } else if (sceneLevel.equals(2)) {
                _ratio = 0.07;  // 2=>3
            } else if (sceneLevel.equals(3)) {
                _ratio = 0.03;  // 3=>4
            }
        } else if (value < GameEnum.ATTRIBUTE_06.getValue()) {
            //220~260
            if (sceneLevel.equals(1)) {
                _ratio = 0.51;  // 1=>2
            } else if (sceneLevel.equals(2)) {
                _ratio = 0.11;  // 2=>3
            } else if (sceneLevel.equals(3)) {
                _ratio = 0.07;  // 3=>4
            }
        } else {
            //>=260
            if (sceneLevel.equals(1)) {
                _ratio = 0.97;  // 1=>2
            } else if (sceneLevel.equals(2)) {
                _ratio = 0.19;  // 2=>3
            } else if (sceneLevel.equals(3)) {
                _ratio = 0.13;  // 3=>4
            }
        }
        return _ratio;
    }

    /**
     * 获得当前的运输数量值
     *
     * @param value
     * @param workProList
     * @return
     */
    private int getLimitSkillsAndList(Integer value, List<ExcelWorkPro> workProList) {
        //取最接近value的一个最小值
        ExcelWorkPro excelWorkPro = workProList.stream().filter(e -> e.getProfessionalType().equals(3) && e.getAttribute() <= value).max(Comparator.comparing(u -> u.getAttribute())).get();
        return excelWorkPro.getTransport();
    }

    private int getLimitSkills(Integer value) {
        int _limit = 0;
        if (value >= GameEnum.ATTRIBUTE_01.getValue() && value < GameEnum.ATTRIBUTE_02.getValue()) {
            //60~100
            _limit = 5;
        } else if (value < GameEnum.ATTRIBUTE_03.getValue()) {
            //100~140
            _limit = 10;
        } else if (value < GameEnum.ATTRIBUTE_04.getValue()) {
            //140~180
            _limit = 15;
        } else if (value < GameEnum.ATTRIBUTE_05.getValue()) {
            //180~220
            _limit = 20;
        } else if (value < GameEnum.ATTRIBUTE_06.getValue()) {
            //220~260
            _limit = 25;
        } else {
            //>=260
            _limit = 30;
        }
        return _limit;
    }


    private int getSceneIdByLevel(Integer value, Integer sceneType) {
        int _levelId = 0;
        if (sceneType >= 101 || sceneType <= 105) {
            if (value.equals(1)) {
                _levelId = GameEnum.LUMBERING_00.getValue();
            } else if (value.equals(2)) {
                _levelId = GameEnum.LUMBERING_01.getValue();
            } else if (value.equals(3)) {
                _levelId = GameEnum.LUMBERING_02.getValue();
            } else if (value.equals(4)) {
                _levelId = GameEnum.LUMBERING_03.getValue();
            } else if (value.equals(5)) {
                _levelId = GameEnum.LUMBERING_04.getValue();
            }
            //伐木
        } else if (sceneType >= 201 || sceneType <= 205) {
            if (value.equals(1)) {
                _levelId = GameEnum.MINE_00.getValue();
            } else if (value.equals(2)) {
                _levelId = GameEnum.MINE_01.getValue();
            } else if (value.equals(3)) {
                _levelId = GameEnum.MINE_02.getValue();
            } else if (value.equals(4)) {
                _levelId = GameEnum.MINE_03.getValue();
            } else if (value.equals(5)) {
                _levelId = GameEnum.MINE_04.getValue();
            }
        }

        return _levelId;
    }

    /**
     * 获取道具和概率数组
     *
     * @param _excelWorkPro
     * @param _currentLevel
     * @param propList
     * @return
     */
    private List<ExcelPropAndProVo> getPropAndPros(ExcelWorkPro _excelWorkPro, Integer _currentLevel, List<ExcelProp> propList) {
        //道具和道具对应的概率
        String[] _levelItemList = _excelWorkPro.getLevelItem().split(",");
        //获取当前层级的道具
        String _levelProp = ArrayUtil.get(_levelItemList, _currentLevel - 1);
        List<String> _levelPropIds = Arrays.asList(ArrayUtil.remove(_levelProp.split("\\|"), 0)); //对应的id list
        //场景对应物品的概率
        String[] _levelProList = _excelWorkPro.getLevelPro().split(",");
        String _levelPropPro = ArrayUtil.get(_levelProList, _currentLevel - 1);//获取当前层级的道具对应的概率
        List<String> _levelPropProList = Arrays.asList(ArrayUtil.remove(_levelPropPro.split("\\|"), 0)); //对应的概率id list 第一个是场景level，移除

        return propList.stream().filter(e ->
                _levelPropIds.contains(e.getPropId().toString())
                        && !"0".equals(_levelPropProList.get(_levelPropIds.indexOf(e.getPropId().toString()))))
                .map(e -> {
                    ExcelPropAndProVo excelPropAndProVo = new ExcelPropAndProVo();
                    log.info("场景:" + _currentLevel + "=>" + _levelPropProList.get(_levelPropIds.indexOf(e.getPropId().toString())));
                    int index = _levelPropIds.indexOf(e.getPropId().toString());
                    excelPropAndProVo = CopyUtil.copy(e, ExcelPropAndProVo.class);
                    excelPropAndProVo.setProbability(Double.parseDouble(_levelPropProList.get(index)));
                    return excelPropAndProVo;
                }).collect(Collectors.toList());

    }
}
