package com.hzs.member.structure.controller.api;

import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.collection.CollectionUtil;
import cn.hutool.core.date.DateTime;
import cn.hutool.core.date.DateUtil;
import cn.hutool.core.lang.tree.Tree;
import cn.hutool.core.lang.tree.TreeUtil;
import cn.hutool.core.util.RandomUtil;
import com.alibaba.fastjson2.JSONArray;
import com.alibaba.fastjson2.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.hzs.common.core.constant.*;
import com.hzs.common.core.constant.msg.MemberMsgConstants;
import com.hzs.common.core.domain.R;
import com.hzs.common.core.enums.*;
import com.hzs.common.core.utils.DateUtils;
import com.hzs.common.core.utils.StringUtils;
import com.hzs.common.core.web.controller.BaseController;
import com.hzs.common.core.web.domain.AjaxResult;
import com.hzs.common.domain.member.achieve.CuMemberSettlePeriod;
import com.hzs.common.domain.member.base.CuMember;
import com.hzs.common.domain.member.ext.CuMemberExt;
import com.hzs.common.domain.member.ext.CuMemberSettleExt;
import com.hzs.common.domain.system.base.BdCountry;
import com.hzs.common.security.utils.SecurityUtils;
import com.hzs.common.service.ITransactionCommonService;
import com.hzs.common.util.TransactionUtils;
import com.hzs.member.achieve.service.ICuMemberSettlePeriodService;
import com.hzs.member.achieve.service.ICuMemberTreeService;
import com.hzs.member.base.service.ICuMemberService;
import com.hzs.member.structure.controller.vo.CuMemberSettlePeriodVo;
import com.hzs.system.base.ICountryServiceApi;
import com.hzs.system.config.IGradeServiceApi;
import com.hzs.system.config.dto.GradeDTO;
import com.hzs.system.sys.IUserServiceApi;
import com.hzs.system.sys.dto.UserAuthorityDTO;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.time.temporal.ChronoUnit;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

/**
 * @Description:
 * @Author: yuhui
 * @Time: 2023/2/6 16:45
 * @Classname: MemberStructureController
 * @PackageName: com.hzs.member.memberStructure.controller.api
 */
//@RestController
//@RequestMapping("/api/member-structure")
public class ApiMemberStructureController extends BaseController {

//    @Autowired
//    private ITransactionCommonService iTransactionCommonService;
//    @Autowired
//    private ICuMemberSettlePeriodService memberSettlePeriodService;
//    @Autowired
//    private ICuMemberTreeService memberTreeService;
//    @Autowired
//    private ICuMemberService memberService;
//
//    @DubboReference
//    IGradeServiceApi gradeServiceApi;
//    @DubboReference
//    IUserServiceApi iUserServiceApi;
//    @DubboReference
//    ICountryServiceApi countryServiceApi;
//
//    /**
//     * 安置架构网体
//     */
//    @GetMapping("az-framework")
//    public AjaxResult azFramework(Long memberSettlePeriodId, String memberCode, Integer level, Integer type) {
//        if (level == null) {
//            level = 7;
//        }
//        // 体系
//        UserAuthorityDTO userAuthorityDTO = iUserServiceApi.getUserAuthority(SecurityUtils.getUserId()).getData();
//        List<Integer> vertexIdList = userAuthorityDTO.getVertexIdList();
//        Date date = DateUtils.currentDate();
//        if (DateUtils.getCurrentHour() < 2) {
//            date = DateUtils.beforeDate(2, ChronoUnit.DAYS, date);
//        }
//        String time = DateUtils.parseDateToStr(DateUtils.YYYY_MM_DD, date);
//        //  Integer period = memberSettlePeriodService.getCuMemberSettlePeriodByDate(time).getPkId();
//        Long pkMember;
//
//        if (StringUtils.isNotBlank(memberCode)) {
//            CuMember member = memberService.getMember(memberCode);
//            if (member == null) {
//                return AjaxResult.error(TransactionUtils.getContent(MemberMsgConstants.MEMBER_NOT_EXITS));
//            }
//
//            // 查询编号是否在登录用户伞下
//            List<CuMemberExt> memberList = memberService.queryPlaceSponsorUnderUmbrella(SecurityUtils.getUserId(), memberCode);
//            if (CollectionUtil.isNotEmpty(memberList)) {
//                pkMember = member.getPkId();
//            } else {
//                // 如果查询编号不存在伞下 则直接查询订单为当前登录人的
//                pkMember = SecurityUtils.getUserId();
//            }
//        } else {
//            CuMember member = memberService.getMember(SecurityUtils.getMemberCode());
//            pkMember = member.getPkId();
//        }
//
//        Integer period = null;
//        Date settleDate = null;
//        if (memberSettlePeriodId != null) {
//            CuMemberSettlePeriod csPeriod = memberSettlePeriodService.getById(memberSettlePeriodId);
//            period = csPeriod.getPkId();
//            settleDate = csPeriod.getSettleDate();
//        } else {
//            CuMemberSettlePeriod csPeriod = memberSettlePeriodService.getCuMemberSettlePeriodByDate(time);
//            if (csPeriod != null) {
//                period = csPeriod.getPkId();
//                settleDate = csPeriod.getSettleDate();
//            }
//        }
//
//        // 查询当天 (秒结)
//        if (settleDate != null &&
//                DateUtils.parseDateToFormat(DateUtils.YYYY_MM_DD, settleDate).equals(DateUtils.parseDateToFormat(DateUtils.YYYY_MM_DD, new Date()))) {
//            // 会员结算秒结表
//            String settleTableName = TableNameConstants.CU_MEMBER_SECOND + period;
//            // 查询所有用户表数据 id
//            // 查询秒结 表 如果 秒结表 没有则去 历史表
//
//            Integer tableNumber = memberTreeService.queryExistOracleTable(settleTableName);
//            if (tableNumber != null && tableNumber == 1) {
//                List<CuMemberSettleExt> cuMemberSettleExts;
//                // 查询今日会员表是否有值
//                Long treeMemberCount = memberTreeService.selectByselectByTreeMemberCount(settleTableName, pkMember);
//                if (treeMemberCount > 0) {
//                    //表格存在
//                    cuMemberSettleExts = memberTreeService.selectByTreeMemberList(pkMember, settleTableName, level, vertexIdList);
//                } else {
//                    DateTime dateTime = DateUtil.offsetDay(DateUtils.currentDate(), -1);
//                    time = DateUtils.parseDateToStr(DateUtils.YYYY_MM_DD, dateTime);
//                    CuMemberSettlePeriod csPeriod = memberSettlePeriodService.getCuMemberSettlePeriodByDate(time);
//                    if (csPeriod != null) {
//                        period = csPeriod.getPkId();
//                    }
//                    settleTableName = TableNameConstants.CU_MEMBER_SETTLE + period;
//                    cuMemberSettleExts = memberTreeService.selectByTreeMemberList(pkMember, settleTableName, level, vertexIdList);
//                }
//                // 查询顶点
//                CuMemberSettleExt memberSettleExt = memberTreeService.queryCuMemberTreeByPkMemberTable(settleTableName, pkMember);
//                if (VertexConstants.GJ30720200CODE.equals(memberSettleExt.getParentMemberCode())) {
//                    memberSettleExt.setParentMemberCode(memberSettleExt.getMemberCode());
//                }
//                memberSettleExt.setLevel(0);
//
//                // 添加自身
//                cuMemberSettleExts.add(memberSettleExt);
//                List<CuMemberSettleExt> cuMemberSettleExtList = cuMemberSettleExts.stream().map(a -> {
//                    a.setMemberName(a.getMemberName());
//                    return a;
//                }).collect(Collectors.toList());
//                List<Tree<String>> build = memberService.systemAzSetListTree(cuMemberSettleExtList, memberSettleExt);
//                // 安置架构 无点位 追加空点位
//                R<Map<Integer, BdCountry>> allCountryMap = countryServiceApi.getAllCountryMap();
//                Map<Integer, BdCountry> allCountryData = allCountryMap.getData();
//                List<Tree<String>> trees = setTreeList(build, level, allCountryData);
//                return AjaxResult.success(trees);
//            }
//
//        } else {
//            // 查询 历史
//            String settleTableName = TableNameConstants.CU_MEMBER_SETTLE + period;
//            Integer tableNumber = memberTreeService.queryExistOracleTable(settleTableName);
//
//            if (tableNumber != null && tableNumber == 1) {
//                // 表示表格存在
//                // 查询顶点
//                CuMemberSettleExt memberSettleExt = memberTreeService.queryCuMemberTreeByPkMemberTable(settleTableName, pkMember);
//                if (VertexConstants.GJ30720200CODE.equals(memberSettleExt.getParentMemberCode())) {
//                    memberSettleExt.setParentMemberCode(memberSettleExt.getMemberCode());
//                }
//                memberSettleExt.setLevel(0);
//                //查询下级
//                List<CuMemberSettleExt> list = memberTreeService.queryCuMemberTreePlaceParentHistoryFramework(settleTableName, pkMember, new ArrayList<>(), level);
//                // 无法查询到自身 所有单独查询自身并且添加
//                list.add(memberSettleExt);
//                List<CuMemberSettleExt> cuMemberSettleExtList = list.stream().map(a -> {
//                    a.setMemberName(a.getMemberName());
//                    return a;
//                }).collect(Collectors.toList());
//                List<Tree<String>> build = memberService.systemAzSetListTree(cuMemberSettleExtList, memberSettleExt);
//                // 安置架构 无点位 追加空点位
//                R<Map<Integer, BdCountry>> allCountryMap = countryServiceApi.getAllCountryMap();
//                Map<Integer, BdCountry> allCountryData = allCountryMap.getData();
//                List<Tree<String>> trees = setTreeList(build, level, allCountryData);
//                return AjaxResult.success(trees);
//            }
//        }
//
//        return AjaxResult.success();
//    }
//
//    /**
//     * @param build
//     * @return
//     */
//
//    // 设置虚拟节点
//    public List<Tree<String>> setTreeList(List<Tree<String>> build, Integer numberOfPlies, Map<Integer, BdCountry> allCountryData) {
//
//        Integer pkCountry = SecurityUtils.getPkCountry();
//        String nationalFlag1 = allCountryData.get(pkCountry).getNationalFlag1();
//        String nationalFlag2 = allCountryData.get(pkCountry).getNationalFlag2();
//        for (Tree<String> stringTree : build) {
//            Integer level = (Integer) stringTree.get("level");
//            if (level < (numberOfPlies - 1)) {
//                if (stringTree.getChildren() != null) {
//                    if (stringTree.getChildren().size() == 0) {
//                        Tree<String> emptyNode1 = TreeUtil.createEmptyNode(RandomUtil.randomNumbers(5));
//                        emptyNode1.putExtra("placeDept", EPlaceDept.LEFT_DEPT.getValue());
//                        emptyNode1.putExtra("level", level + 1);
//                        emptyNode1.putExtra("memberCode", "");
//                        emptyNode1.setName("-");
//                        emptyNode1.setParentId(stringTree.getId());
//                        emptyNode1.putExtra("avatarUrl", MemberFrameworkConstants.xuni);
//                        emptyNode1.setId(RandomUtil.randomNumbers(3));
//                        emptyNode1.putExtra("settleCountryUrl", nationalFlag1);
//                        emptyNode1.putExtra("settleCountryUrl2", nationalFlag2);
//                        emptyNode1.putExtra("countryUrl", nationalFlag1);
//                        emptyNode1.putExtra("countryUrl2", nationalFlag2);
//
//                        //                    emptyNode1.setChildren(setChildren(level,emptyNode1.getId()));
//                        stringTree.getChildren().add(emptyNode1);
//                        setTreeList(stringTree.getChildren(), numberOfPlies, allCountryData);
//
//                        Tree<String> emptyNode2 = TreeUtil.createEmptyNode(RandomUtil.randomNumbers(5));
//                        emptyNode2.putExtra("placeDept", EPlaceDept.RIGHT_DEPT.getValue());
//                        emptyNode2.putExtra("level", level + 1);
//                        emptyNode2.putExtra("memberCode", "");
//                        emptyNode2.setName("-");
//                        emptyNode2.setParentId(stringTree.getId());
//                        emptyNode2.setId(RandomUtil.randomNumbers(3));
//                        emptyNode2.putExtra("settleCountryUrl", nationalFlag1);
//                        emptyNode2.putExtra("settleCountryUrl2", nationalFlag2);
//                        emptyNode2.putExtra("countryUrl", nationalFlag1);
//                        emptyNode2.putExtra("countryUrl2", nationalFlag2);
//                        emptyNode2.putExtra("avatarUrl", MemberFrameworkConstants.xuni);
//                        //         emptyNode2.setChildren(setChildren(level,emptyNode2.getId()));
//                        stringTree.getChildren().add(emptyNode2);
//                        setTreeList(stringTree.getChildren(), numberOfPlies, allCountryData);
//                    } else if (stringTree.getChildren().size() == 1) {
//                        List<Tree<String>> cli = stringTree.getChildren();
//                        Integer pd = (Integer) cli.get(0).get("placeDept");
//                        Tree<String> emptyNode = TreeUtil.createEmptyNode(RandomUtil.randomNumbers(5));
//                        if (pd.equals(EPlaceDept.LEFT_DEPT.getValue())) {
//                            emptyNode.putExtra("placeDept", EPlaceDept.RIGHT_DEPT.getValue());
//                            emptyNode.putExtra("level", level + 1);
//                            emptyNode.putExtra("memberCode", "");
//                            emptyNode.setName("-");
//                            emptyNode.putExtra("settleCountryUrl", nationalFlag1);
//                            emptyNode.putExtra("settleCountryUrl2", nationalFlag2);
//                            emptyNode.putExtra("countryUrl", nationalFlag1);
//                            emptyNode.putExtra("countryUrl2", nationalFlag2);
//                            emptyNode.setParentId(stringTree.getId());
//                            emptyNode.setId(RandomUtil.randomNumbers(3));
//                            emptyNode.putExtra("avatarUrl", MemberFrameworkConstants.xuni);
//                            //     emptyNode.setChildren(setChildren(level,emptyNode.getId()));
//                            stringTree.getChildren().add(emptyNode);
//                            setTreeList(stringTree.getChildren(), numberOfPlies, allCountryData);
//
//                        } else {
//                            emptyNode.putExtra("placeDept", EPlaceDept.LEFT_DEPT.getValue());
//                            emptyNode.putExtra("level", level + 1);
//                            emptyNode.putExtra("memberCode", "");
//                            emptyNode.setName("-");
//                            emptyNode.setParentId(stringTree.getId());
//                            emptyNode.setId(RandomUtil.randomNumbers(3));
//                            emptyNode.putExtra("avatarUrl", MemberFrameworkConstants.xuni);
//                            emptyNode.putExtra("settleCountryUrl", nationalFlag1);
//                            emptyNode.putExtra("settleCountryUrl2", nationalFlag2);
//                            emptyNode.putExtra("countryUrl", nationalFlag1);
//                            emptyNode.putExtra("countryUrl2", nationalFlag2);
//                            //       emptyNode.setChildren(setChildren(level,emptyNode.getId()));
//                            stringTree.getChildren().add(emptyNode);
//                            List<Tree<String>> strTree = stringTree.getChildren();
//                            List<Tree<String>> sortChildren = new ArrayList<>();
//                            sortChildren.add(strTree.get(1));
//                            sortChildren.add(strTree.get(0));
//                            stringTree.setChildren(sortChildren);
//                            setTreeList(sortChildren, numberOfPlies, allCountryData);
//
//                        }
//                    } else {
//                        List<Tree<String>> children = stringTree.getChildren();
//                        List<Tree<String>> sortChildren = new ArrayList<>();
//                        int pd = Integer.parseInt(children.get(0).get("placeDept").toString());
//                        if (pd == 1) {
//                            sortChildren.add(children.get(0));
//                            sortChildren.add(children.get(1));
//                        } else {
//                            sortChildren.add(children.get(1));
//                            sortChildren.add(children.get(0));
//                        }
//                        stringTree.setChildren(sortChildren);
//                        setTreeList(stringTree.getChildren(), numberOfPlies, allCountryData);
//                    }
//                } else {
//                    // 等于空
//                    List<Tree<String>> children = new ArrayList<>();
//                    children = new ArrayList<>();
//                    Tree<String> emptyNode1 = TreeUtil.createEmptyNode(RandomUtil.randomNumbers(5));
//                    emptyNode1.putExtra("placeDept", EPlaceDept.LEFT_DEPT.getValue());
//                    emptyNode1.putExtra("level", level + 1);
//                    emptyNode1.putExtra("memberCode", "");
//                    emptyNode1.setName("-");
//                    emptyNode1.putExtra("avatarUrl", MemberFrameworkConstants.xuni);
//                    emptyNode1.putExtra("settleCountryUrl", nationalFlag1);
//                    emptyNode1.putExtra("settleCountryUrl2", nationalFlag2);
//                    emptyNode1.putExtra("countryUrl", nationalFlag1);
//                    emptyNode1.putExtra("countryUrl2", nationalFlag2);
//                    emptyNode1.setParentId(stringTree.getId());
//                    emptyNode1.setId(RandomUtil.randomNumbers(3));
//                    children.add(emptyNode1);
//
//
//                    Tree<String> emptyNode2 = TreeUtil.createEmptyNode(RandomUtil.randomNumbers(5));
//                    emptyNode2.putExtra("placeDept", EPlaceDept.RIGHT_DEPT.getValue());
//                    emptyNode2.putExtra("level", level + 1);
//                    emptyNode2.putExtra("memberCode", "");
//                    emptyNode2.setName("-");
//                    emptyNode2.putExtra("settleCountryUrl", nationalFlag1);
//                    emptyNode2.putExtra("settleCountryUrl2", nationalFlag2);
//                    emptyNode2.putExtra("countryUrl", nationalFlag1);
//                    emptyNode2.putExtra("countryUrl2", nationalFlag2);
//                    emptyNode2.putExtra("avatarUrl", MemberFrameworkConstants.xuni);
//                    emptyNode2.setParentId(stringTree.getId());
//                    emptyNode2.setId(RandomUtil.randomNumbers(3));
//                    children.add(emptyNode2);
//
//                    stringTree.setChildren(children);
//                    setTreeList(children, numberOfPlies, allCountryData);
//                }
//            }
//        }
//        return build;
//    }
//
//
//    private Integer defaultLevel = 5;
//
//    /**
//     * 推荐架构网体
//     */
//    @GetMapping("tj-framework")
//    public AjaxResult tjFramework(Long memberSettlePeriodId, String memberCode, Integer level) {
//        Date date = DateUtils.currentDate();
//        if (DateUtils.getCurrentHour() < 2) {
//            date = DateUtils.beforeDate(2, ChronoUnit.DAYS, date);
//        }
//        String time = DateUtils.parseDateToStr(DateUtils.YYYY_MM_DD, date);
//
//        // 体系
//        UserAuthorityDTO userAuthorityDTO = iUserServiceApi.getUserAuthority(SecurityUtils.getUserId()).getData();
//        List<Integer> vertexIdList = userAuthorityDTO.getVertexIdList();
//        Long pkMember;
//        if (StringUtils.isNotBlank(memberCode)) {
//            CuMember member = memberService.getMember(memberCode);
//            if (member == null) {
//                return AjaxResult.error("会员编号不存在");
//            }
//            // 查询编号是否在登录用户伞下
//            if (!memberCode.equals(SecurityUtils.getMemberCode())) {
//                Long placeCount = memberService.checkPlaceSponsorUnderUmbrella(SecurityUtils.getUserId(), memberCode);
//                if (placeCount == 0) {
//                    // 如果查询编号不存在伞下 则直接查询订单为当前登录人的
//                    pkMember = SecurityUtils.getUserId();
//                } else {
//                    pkMember = member.getPkId();
//                }
//            } else {
//                pkMember = SecurityUtils.getUserId();
//            }
//        } else {
//            CuMember member = memberService.getMember(SecurityUtils.getMemberCode());
//            pkMember = member.getPkId();
//        }
//
//        Integer period = null;
//        Date settleDate = null;
//        if (memberSettlePeriodId != null) {
//            CuMemberSettlePeriod csPeriod = memberSettlePeriodService.getById(memberSettlePeriodId);
//            period = csPeriod.getPkId();
//            settleDate = csPeriod.getSettleDate();
//        } else {
//            CuMemberSettlePeriod csPeriod = memberSettlePeriodService.getCuMemberSettlePeriodByDate(time);
//            if (csPeriod != null) {
//                period = csPeriod.getPkId();
//                settleDate = csPeriod.getSettleDate();
//            }
//        }
//
//
//        // 查询当天 (秒结)
//        if (settleDate != null &&
//                DateUtils.parseDateToFormat(DateUtils.YYYY_MM_DD, settleDate).equals(DateUtils.parseDateToFormat(DateUtils.YYYY_MM_DD, new Date()))) {
//            // 查询所有用户表数据 id
//
//            // 会员结算秒结表
//            String settleTableName = TableNameConstants.CU_MEMBER_SECOND + period;
//            Integer tableNumber = memberTreeService.queryExistOracleTable(settleTableName);
//            if (tableNumber != null && tableNumber == 1) {
//                //表格存在
//                if (level == null) {
//                    level = defaultLevel;
//                }
//                List<CuMemberSettleExt> cuMemberSettleExts;
//                // 查询今日会员表是否有值
//                Long treeMemberCount = memberTreeService.selectByselectByTreeMemberCount(settleTableName, pkMember);
//                if (treeMemberCount > 0) {
//                    //表格存在
//                    cuMemberSettleExts = memberTreeService.queryCuMemberTreeParentTable(settleTableName, pkMember, level, vertexIdList);
//                } else {
//                    DateTime dateTime = DateUtil.offsetDay(DateUtils.currentDate(), -1);
//                    time = DateUtils.parseDateToStr(DateUtils.YYYY_MM_DD, dateTime);
//                    CuMemberSettlePeriod csPeriod = memberSettlePeriodService.getCuMemberSettlePeriodByDate(time);
//                    if (csPeriod != null) {
//                        period = csPeriod.getPkId();
//                    }
//                    settleTableName = TableNameConstants.CU_MEMBER_SETTLE + period;
//                    cuMemberSettleExts = memberTreeService.queryCuMemberTreeParentTable(settleTableName, pkMember, level, vertexIdList);
//                }
//
//                // 查询顶点
//                CuMemberSettleExt memberSettleExt = memberTreeService.queryCuMemberTreeByPlacePkMemberTable(settleTableName, pkMember);
//                if (VertexConstants.GJ30720200CODE.equals(memberSettleExt.getParentMemberCode())) {
//                    memberSettleExt.setParentMemberCode(memberSettleExt.getMemberCode());
//                }
//
//                memberSettleExt.setLevel(0);
//                // 添加自身
//                cuMemberSettleExts.add(memberSettleExt);
//                List<CuMemberSettleExt> cuMemberSettleExtList = cuMemberSettleExts.stream().map(a -> {
//                    a.setMemberName(a.getMemberName());
//                    return a;
//                }).collect(Collectors.toList());
//                List<Tree<String>> build = memberService.systemTjSetListTree(cuMemberSettleExtList, memberSettleExt, settleTableName, true);
//                // 安置架构 无点位 追加空点位
//                return AjaxResult.success(build);
//            } else {
//                // 查询 历史
//                // 查询表格是否存在
//                if (level == null) {
//                    level = defaultLevel;
//                }
//                if (tableNumber == null) {
//                    settleTableName = null;
//                }
//                // 查询顶点
//                CuMemberSettleExt memberSettleExt = memberTreeService.queryCuMemberTreeByPlacePkMemberTable(settleTableName, pkMember);
//                if (VertexConstants.GJ30720200CODE.equals(memberSettleExt.getParentMemberCode())) {
//                    memberSettleExt.setParentMemberCode(memberSettleExt.getMemberCode());
//                }
//                memberSettleExt.setLevel(0);
//                //查询下级
//                List<CuMemberSettleExt> list = memberTreeService.queryCuMemberTreeParentTable(settleTableName, pkMember, level, vertexIdList);
//                // 无法查询到自身 所有单独查询自身并且添加
//                list.add(memberSettleExt);
//                List<CuMemberSettleExt> cuMemberSettleExtList = list.stream().map(a -> {
//                    a.setMemberName(a.getMemberName());
//                    return a;
//                }).collect(Collectors.toList());
//                List<Tree<String>> build = memberService.systemTjSetListTree(cuMemberSettleExtList, memberSettleExt, settleTableName, true);
//                // 安置架构 无点位 追加空点位
//                R<Map<Integer, BdCountry>> allCountryMap = countryServiceApi.getAllCountryMap();
//                Map<Integer, BdCountry> allCountryData = allCountryMap.getData();
//                return AjaxResult.success(setTreeList(build, level, allCountryData));
//            }
//
//        } else {
//            if (level == null) {
//                level = defaultLevel;
//            }
//            DateTime dateTime = DateUtil.offsetDay(DateUtils.currentDate(), -1);
//            time = DateUtils.parseDateToStr(DateUtils.YYYY_MM_DD, dateTime);
//            CuMemberSettlePeriod csPeriod = memberSettlePeriodService.getCuMemberSettlePeriodByDate(time);
//            if (csPeriod != null) {
//                period = csPeriod.getPkId();
//            }
//            // 查询 历史
//            String settleTableName = TableNameConstants.CU_MEMBER_SETTLE + period;
//            Integer tableNumber = memberTreeService.queryExistOracleTable(settleTableName);
//
//            if (tableNumber == null) {
//                // 表示表格存在
//                settleTableName = null;
//            }
//            // 查询顶点
//            CuMemberSettleExt memberSettleExt = memberTreeService.queryCuMemberTreeByPlacePkMemberTable(settleTableName, pkMember);
//
//            if (StringUtils.isNotBlank(memberSettleExt.getParentMemberCode()) && VertexConstants.GJ30720200CODE.equals(memberSettleExt.getParentMemberCode())) {
//                memberSettleExt.setParentMemberCode(memberSettleExt.getMemberCode());
//            }
//            memberSettleExt.setLevel(0);
//            //查询下级
//            List<CuMemberSettleExt> list = memberTreeService.queryCuMemberTreeParentTable(settleTableName, pkMember, level, vertexIdList);
//            // 无法查询到自身 所有单独查询自身并且添加
//            list.add(memberSettleExt);
//            List<CuMemberSettleExt> cuMemberSettleExtList = list.stream().map(a -> {
//                a.setMemberName(a.getMemberName());
//                return a;
//            }).collect(Collectors.toList());
//            List<Tree<String>> build = memberService.systemTjSetListTree(cuMemberSettleExtList, memberSettleExt, settleTableName, false);
//            // 安置架构 无点位 追加空点位
//            return AjaxResult.success(build);
//        }
//    }
//
//    /**
//     * 查询最近一月所有期数
//     *
//     * @return
//     */
//    @GetMapping("get-member-settle-period")
//    public AjaxResult getMemberSettlePeriod() {
//        // 查询最近一月的数据
//        DateTime dateTime = DateUtil.lastMonth();
//        QueryWrapper<CuMemberSettlePeriod> queryWrapper = new QueryWrapper<>();
//        queryWrapper.orderByDesc("SETTLE_DATE");
//        Date date = DateUtils.currentDate();
//        if (DateUtils.getCurrentHour() < 2) {
//            date = DateUtils.beforeDate(2, ChronoUnit.DAYS, date);
//        }
//        queryWrapper.between("SETTLE_DATE", dateTime, date);
//        List<CuMemberSettlePeriod> list = memberSettlePeriodService.list(queryWrapper);
//        List<CuMemberSettlePeriodVo> resultList = new ArrayList<>();
//        for (CuMemberSettlePeriod cuMemberSettlePeriod : list) {
//            CuMemberSettlePeriodVo cuMemberSettlePeriodVo = BeanUtil.copyProperties(cuMemberSettlePeriod, CuMemberSettlePeriodVo.class);
//            if (DateUtils.parseDateToFormat(DateUtils.YYYY_MM_DD, cuMemberSettlePeriod.getSettleDate()).equals(DateUtils.parseDateToFormat(DateUtils.YYYY_MM_DD, DateUtils.currentDate()))) {
//                cuMemberSettlePeriodVo.setIsThisDay(EYesNo.YES.getIntValue());
//            } else {
//                cuMemberSettlePeriodVo.setIsThisDay(EYesNo.NO.getIntValue());
//            }
//            resultList.add(cuMemberSettlePeriodVo);
//        }
//        return AjaxResult.success(resultList);
//    }
//
//
//    /**
//     * 获取头像信息
//     *
//     * @return
//     */
//    @GetMapping("get-avatar-info")
//    public AjaxResult getAvatarUrl() {
//        Integer pkCountry = SecurityUtils.getPkCountry();
//        Map<String, String> transactionMap = iTransactionCommonService.exportEnumTransaction(EGrade.values());
//        Map<Integer, String> transactionMap1 = iTransactionCommonService.exportEnumTransactionByDB(EnumsPrefixConstants.KEY_GRADE);
//        JSONArray array = new JSONArray();
//        // 虚拟
//        JSONObject other = new JSONObject();
//        other.put("name", transactionMap.get(EnumsPrefixConstants.ENU_CAT + Math.abs(EGrade.VIRTUALLY.getIndex())));
//        other.put("value", MemberFrameworkConstants.xuni);
//        array.add(other);
//        // 已注销
//        JSONObject zxOther = new JSONObject();
//        zxOther.put("name", transactionMap.get(EnumsPrefixConstants.ENU_CAT + Math.abs(EGrade.LOGGED_OUT.getIndex())));
//        zxOther.put("value", MemberFrameworkConstants.LOG_OFF);
//        array.add(zxOther);
//        // 待激活  非中国
//        if (!SecurityUtils.getPkCountry().equals(CountryConstants.CHINA_COUNTRY)) {
//            JSONObject djhOther = new JSONObject();
//            djhOther.put("name", transactionMap.get(EnumsPrefixConstants.ENU_CAT + Math.abs(EGrade.DEAD_POINT.getIndex())));
//            djhOther.put("value", MemberFrameworkConstants.toBeActivated);
//            array.add(djhOther);
//        }
//        R<List<GradeDTO>> list = gradeServiceApi.selectGradeAll(pkCountry);
//
//        for (GradeDTO date : list.getData()) {
//            JSONObject js = new JSONObject();
//            js.put("name", transactionMap1.get(date.getPkTransaction()));
//            js.put("value", date.getIcon());
//            array.add(js);
//        }
//
//        return AjaxResult.success(array);
//    }

}
