TransferRelationshipServiceImpl.java 51 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864
package com.example.gajz.transferrelationship.service.serviceImpl;
import com.example.gajz.redis.ConFigRedis;
import com.example.gajz.result.Result;
import com.example.gajz.result.ResultCode;
import com.example.gajz.transferrelationship.bean.dto.*;
import com.example.gajz.transferrelationship.bean.excel.abcExcie;
import com.example.gajz.transferrelationship.bean.param.TransferAssociationParam;
import com.example.gajz.transferrelationship.bean.vo.*;
import com.example.gajz.transferrelationship.dao.TransferRelationshipMapper;
import com.example.gajz.transferrelationship.hugegraphclient.HugeCollectionProperties;
import com.example.gajz.transferrelationship.neo4j.Colour;
import com.example.gajz.transferrelationship.relationalalgorithm.RelationalAlgorithm;
import com.example.gajz.transferrelationship.relationalalgorithm.TransferLocation;
import com.example.gajz.transferrelationship.service.TransferRelationshipService;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.validation.annotation.Validated;
import redis.clients.jedis.Jedis;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;


/**
 * @author lenovo
 */
@Validated
@Service
public class TransferRelationshipServiceImpl implements TransferRelationshipService {

    @Autowired
    TransferRelationshipMapper transferRelationshipMapper;
    /**HugeGraph*/
    @Autowired
    HugeCollectionProperties hugeCollectionProperties;


    /**
     * 转账关系
     * @return
     */
    @Override
    public List<data> edge() {
        List<com.example.gajz.transferrelationship.bean.param.data> edge = transferRelationshipMapper.edge();
        List transList=new ArrayList<>();
//        System.out.println(edge.size()+"边");
//        //获取redis连接
//        Jedis conn = ConFigRedis.getConn();
        for (int i=0;i<edge.size();i++){
            TransferRelationship transferRelationship=new TransferRelationship();
            Source source=new Source();
            source.setId(edge.get(i).getSource());
            Target target=new Target();
            target.setId(edge.get(i).getTarget());
            /**
             * 转账次数
             */
            TransferTimes transferTimes=new TransferTimes();
            if (edge.get(i).getTransferTimes()>2){
                transferTimes.setLineSize(1);
            }else {
                transferTimes.setLineSize(0.5);
            }
            transferTimes.setTransferTimes(edge.get(i).getTransferTimes());
            transferRelationship.setSource(source);
            transferRelationship.setTarget(target);
            transferRelationship.setTransferTimes(transferTimes);
            transList.add(transferRelationship);
        }
//        conn.close();
        return transList;
    }



    /**
     * 点
     */
    @Override
    public List diagramSpot() {
//        Jedis conn = ConFigRedis.getConn();
        /**已经存在的点 会存储到map里面*/
        HashMap hashMap=new HashMap();
        //查询转账人(中心点)信息
        List<TransferCardVo> transferCardVos = transferRelationshipMapper.selectTransferCard();
        List list=new ArrayList();
        int centerPointX = 0;
        int centerPointY = 0;
        //存储所有大圆的四角X Y轴数据
        HashMap xyMap = new HashMap();
        /** 中心点*/
        for (int i=0;i<transferCardVos.size();i++){
            //是否重叠
            boolean overlap=false;
            //生成颜色
            Colour colour=new Colour();
            String code=colour.getColour();
            Test test=new Test();
            test.setId(transferCardVos.get(i).getBankCardNo());
            test.setX((int)(Math.random()*3000));
            test.setY((int)(Math.random()*3000));
            test.setName(transferCardVos.get(i).getName());
            test.setColor(code);
            centerPointX=test.getX();
            centerPointY=test.getY();
            /** -----------------------------去掉被转账人对应中心点重复出现点 代码--------------------------------*/
            /**查询被转账人全部信息*/
            List<com.example.gajz.transferrelationship.bean.param.data> transfer = transferRelationshipMapper.transferRelationship(transferCardVos.get(i).getBankCardNo());
            /**将没有重复的值 存储到这个list里面*/
            List<com.example.gajz.transferrelationship.bean.param.data> dataList=new ArrayList<>();
            for (int p=0;p<transfer.size();p++){
                Object target = hashMap.get(transfer.get(p).getTarget());
                if (target==null){
                    com.example.gajz.transferrelationship.bean.param.data data=new com.example.gajz.transferrelationship.bean.param.data();
                    data.setName(transfer.get(p).getName());
                    data.setTarget(transfer.get(p).getTarget());
                    data.setTransferTimes(transfer.get(p).getTransferTimes());
                    dataList.add(data);
                    hashMap.put(transfer.get(p).getTarget(),transfer.get(p).getTarget());
                }
            }
            /** -----------------------------------------------------------------------------------------*/
            if (dataList.size()==0||dataList.size()<=100){
                test.setSize(2);
            }else if (dataList.size()>=100){
                test.setSize(2);
            }

            /**每圈点数  动态变化 */
            int base = 8;
            /**总数*/
            int total = dataList.size();
            /**循环次数*/
            int numberCycles =0;

            /**  -----------------------计算大图四个角的XY轴代码-----------------------*/
            /**算大圈半径专用    总数*/
            int bigTotal = dataList.size();
            /**算大圈半径专用   每圈点数*/
            int bigBase = 8;
            for (int n=1;bigTotal>0;n++){
                bigTotal = bigTotal-bigBase;
                bigBase = bigBase+20;
            }
            /** 大圆最后一圈半径  每份多少点数 */
            int bigPointsPerShare = bigBase/4;
            /**大圆最后一圈半径   相等于大圈半径   点数*距离 */
            int fullCircleRadius =bigPointsPerShare*2;
            /**  -------------------------------------------------------------------*/
            if (i==0){
                xyMap.put(i+"zX",(centerPointX-fullCircleRadius)); //圆左X轴
                xyMap.put(i+"zY",centerPointY); //圆左Y轴
                xyMap.put(i+"yX",(centerPointX+fullCircleRadius)); //圆右X轴
                xyMap.put(i+"yY",centerPointY); //圆右Y轴
                xyMap.put(i+"sX",centerPointX); //圆上X轴
                xyMap.put(i+"sY",(centerPointY-fullCircleRadius)); //圆上Y轴
                xyMap.put(i+"xX",centerPointX); //圆下X轴
                xyMap.put(i+"xY",(centerPointY+fullCircleRadius)); //圆下Y轴
//                /** 将中心点X Y轴拼接 并存入Redis中*/
//                String position=test.getX()+"Y"+test.getY();
//                conn.set(test.getId(),position);
                list.add(test);
                overlap=true;
            }else {
                for (int p=0;p<i;p++){
                    int zX = (int) xyMap.get(p + "zX");
                    int zY = (int) xyMap.get(p + "zY");
                    int yX = (int) xyMap.get(p + "yX");
                    int yY = (int) xyMap.get(p + "yY");
                    int sX = (int) xyMap.get(p + "sX");
                    int sY = (int) xyMap.get(p + "sY");
                    int xX = (int) xyMap.get(p + "xX");
                    int xY = (int) xyMap.get(p + "xY");
                    if(   ((zX>(centerPointX-fullCircleRadius)&&zX>(centerPointX+fullCircleRadius)) ||(yX<(centerPointX-fullCircleRadius)&&yX<(centerPointX+fullCircleRadius)))
                            ||
                           ((sY>(centerPointY-fullCircleRadius)&&sY>(centerPointY+fullCircleRadius)) ||(xY<(centerPointY-fullCircleRadius)&&xY<(centerPointY+fullCircleRadius)))   ){
                        if (p==i-1) {
                            xyMap.put(i + "zX", (centerPointX-fullCircleRadius)); //圆左X轴
                            xyMap.put(i + "zY", centerPointY); //圆左Y轴
                            xyMap.put(i + "yX", (centerPointX+fullCircleRadius)); //圆右X轴
                            xyMap.put(i + "yY", centerPointY); //圆右Y轴
                            xyMap.put(i + "sX", centerPointX); //圆上X轴
                            xyMap.put(i + "sY", (centerPointY-fullCircleRadius)); //圆上Y轴
                            xyMap.put(i + "xX", centerPointX); //圆下X轴
                            xyMap.put(i + "xY", (centerPointY+fullCircleRadius)); //圆下Y轴
                            /** 将中心点X Y轴拼接 并存入Redis中*/
//                            String position=test.getX()+"Y"+test.getY();
//                            conn.set(test.getId(),position);
                            list.add(test);
                            overlap=true;
                        }
                    }else {
                        overlap=false;
                        break;
                    }
                }
            }
            if (!overlap){
                i--;
                continue;
            }


            /**圆圈层数  每循环一次 就是一圈*/
            for (int y=1;total>0;y++){
                /**点之间 x轴y轴间隔距离*/
                int distance=2;
                /**圆分成四份  每份多少点数*/
                int pointsPerShare = base/4;
                /**小圆半径  点数X距离*/
                int circleRadius = pointsPerShare * distance;
                /**右下角逐渐递减*/
                int lowerRight = 0;
                /**左下角逐渐递减*/
                int lowerLeft  = 0;
                /**左上角逐渐递减*/
                int upperLeft = 0;
                /**点大小*/
                double pointSize =1;
                if (base<=total){
                    for (int t=0;t<base;t++){
                        Test test1=new Test();
                        if (t<pointsPerShare){
                            test1.setId(dataList.get(numberCycles).getTarget());
                            test1.setName(dataList.get(numberCycles).getName());
                            test1.setX((distance*t)+centerPointX);
                            test1.setY((centerPointY-circleRadius)+(distance*t));
                            test1.setColor(code);
                            test1.setSize(pointSize);
                        }else if (t<=pointsPerShare*2){
                            test1.setId(dataList.get(numberCycles).getTarget());
                            test1.setName(dataList.get(numberCycles).getName());
                            test1.setX((centerPointX+circleRadius)-(distance*lowerRight));
                            test1.setY(centerPointY+(lowerRight*distance));
                            test1.setColor(code);
                            test1.setSize(pointSize);
                            lowerRight++;
                        }else if (t<=pointsPerShare*3){
                            test1.setId(dataList.get(numberCycles).getTarget());
                            test1.setName(dataList.get(numberCycles).getName());
                            test1.setX((centerPointX-circleRadius)+(distance*lowerLeft));
                            test1.setY(centerPointY+(distance*lowerLeft));
                            test1.setColor(code);
                            test1.setSize(pointSize);
                            lowerLeft++;
                        }else if (t<=pointsPerShare*4){
                            test1.setId(dataList.get(numberCycles).getTarget());
                            test1.setName(dataList.get(numberCycles).getName());
                            test1.setX(centerPointX-(distance*upperLeft));
                            test1.setY((centerPointY-circleRadius)+(distance*upperLeft));
                            test1.setColor(code);
                            test1.setSize(pointSize);
                            upperLeft++;
                        }
//                        /** 将其他点 X Y轴拼接 并存入Redis中*/
//                        String position=test1.getX()+"Y"+test1.getY();
//                        conn.set(test1.getId(),position);
                        list.add(test1);
                        numberCycles++;
                    }
                    total=total-base;
                    base = base+20;
                    continue;
                }
                if (base>0){
                    for (int t=0;numberCycles<dataList.size();t++){
                        Test test1=new Test();
                        if (t<pointsPerShare){
                            test1.setId(dataList.get(numberCycles).getTarget());
                            test1.setName(dataList.get(numberCycles).getName());
                            test1.setX((distance*t)+centerPointX);
                            test1.setY((centerPointY-circleRadius)+(distance*t));
                            test1.setColor(code);
                            test1.setSize(pointSize);
                        }else if (t<=pointsPerShare*2){
                            test1.setId(dataList.get(numberCycles).getTarget());
                            test1.setName(dataList.get(numberCycles).getName());
                            test1.setX((centerPointX+circleRadius)-(distance*lowerRight));
                            test1.setY(centerPointY+(lowerRight*distance));
                            test1.setColor(code);
                            test1.setSize(pointSize);
                            lowerRight++;
                        }else if (t<=pointsPerShare*3){
                            test1.setId(dataList.get(numberCycles).getTarget());
                            test1.setName(dataList.get(numberCycles).getName());
                            test1.setX((centerPointX-circleRadius)+(distance*lowerLeft));
                            test1.setY(centerPointY+(distance*lowerLeft));
                            test1.setColor(code);
                            test1.setSize(pointSize);
                            lowerLeft++;
                        }else if (t<=pointsPerShare*4){
                            test1.setId(dataList.get(numberCycles).getTarget());
                            test1.setName(dataList.get(numberCycles).getName());
                            test1.setX(centerPointX-(distance*upperLeft));
                            test1.setY((centerPointY-circleRadius)+(distance*upperLeft));
                            test1.setColor(code);
                            test1.setSize(pointSize);
                            upperLeft++;
                        }
//                        /** 将其他点 X Y轴拼接 并存入Redis中*/
//                        String position=test1.getX()+"Y"+test1.getY();
//                        conn.set(test1.getId(),position);
                        list.add(test1);
                        numberCycles++;
                    }
                    break;
                }
            }
        }
//        conn.close();
        return list;
    }

    /**
     * 关系图搜索 单人转账关系(关联关系)接口
     * @param cardnumbe
     * @return
     */
    @Override
    public Result searchRelationship(String cardnumbe) {
        try {
            //查询搜索人信息   转账人
            List<SearchRelationshipVo> searchRelationshipVos1 = transferRelationshipMapper.personalInformationTransferor(cardnumbe);
            //查询搜索人信息   被转账人
            List<SearchRelationshipVo> searchRelationshipVos2 = transferRelationshipMapper.personalInformationTransferredPerson(cardnumbe);
            /**先查询用户信息是转账人还是被转账人  之后将数据存入list中 如果两个都没有就返回null*/
            List<SearchRelationshipVo> searchRelationshipVos = new ArrayList<>();
            if (searchRelationshipVos1.size()!=0||searchRelationshipVos2.size()!=0){
            if (searchRelationshipVos1.size()!=0){
                for (int i=0;i<searchRelationshipVos1.size();i++) {
                    SearchRelationshipVo searchRelationshipVo = new SearchRelationshipVo();
                    searchRelationshipVo.setName(searchRelationshipVos1.get(i).getName());
                    searchRelationshipVo.setRelationship(searchRelationshipVos1.get(i).getRelationship());
                    searchRelationshipVo.setTransferTimes(searchRelationshipVos1.get(i).getTransferTimes());
                    searchRelationshipVo.setCardNumber(searchRelationshipVos1.get(i).getCardNumber());
                    searchRelationshipVos.add(searchRelationshipVo);
                }
            }else{
                for (int i=0;i<searchRelationshipVos2.size();i++) {
                    SearchRelationshipVo searchRelationshipVo = new SearchRelationshipVo();
                    searchRelationshipVo.setName(searchRelationshipVos2.get(i).getName());
                    searchRelationshipVo.setRelationship(searchRelationshipVos2.get(i).getRelationship());
                    searchRelationshipVo.setTransferTimes(searchRelationshipVos2.get(i).getTransferTimes());
                    searchRelationshipVo.setCardNumber(searchRelationshipVos2.get(i).getCardNumber());
                    searchRelationshipVos.add(searchRelationshipVo);
                }
             }
            }else {
                return new Result(ResultCode.SUCCESS);
            }
            //存放数据list
            List<SearchRelationshipVo> searchRelationshipVoList = new ArrayList<>();
            /**创建map 将已经查询出来的下级存入map中  防止相互转账进入死循环*/
            HashMap hashMap=new HashMap();
                //转账人
                for (int i = 0; i < searchRelationshipVos.size(); i++) {
                    SearchRelationshipVo searchRelationshipVo = new SearchRelationshipVo();
                    searchRelationshipVo.setName(searchRelationshipVos.get(i).getName());
                    searchRelationshipVo.setRelationship(searchRelationshipVos.get(i).getRelationship());
                    searchRelationshipVo.setTransferTimes(searchRelationshipVos.get(i).getTransferTimes());
                    searchRelationshipVo.setCardNumber(searchRelationshipVos.get(i).getCardNumber());
                    //存入map
                    hashMap.put(searchRelationshipVos.get(i).getCardNumber(),searchRelationshipVos.get(i).getCardNumber());
                    /** 查询下级数据*/
                    List<SearchRelationshipVo> searchRelationshipVoSubordinateList = transferRelationshipMapper.querySubordinate(searchRelationshipVos.get(i).getCardNumber());
                    /**判断是否有下级  如果有给true*/
                    if (searchRelationshipVoSubordinateList.size()!=0){
                        searchRelationshipVo.setSubordinate(true);
                    }else {
                        searchRelationshipVo.setSubordinate(false);
                    }
                    searchRelationshipVoList.add(searchRelationshipVo);
                    if (searchRelationshipVoSubordinateList.size() != 0) {
                        /**存放下级参数list*/
                        List<SearchRelationshipVo> list = new ArrayList<>();
                            for (int n = 0; n < searchRelationshipVoSubordinateList.size(); n++) {
                                SearchRelationshipVo searchRelationshipSubordinateVo = new SearchRelationshipVo();
                                searchRelationshipSubordinateVo.setName(searchRelationshipVoSubordinateList.get(n).getName());
                                searchRelationshipSubordinateVo.setCardNumber(searchRelationshipVoSubordinateList.get(n).getCardNumber());
                                searchRelationshipSubordinateVo.setTransferTimes(searchRelationshipVoSubordinateList.get(n).getTransferTimes());
                                searchRelationshipSubordinateVo.setRelationship(searchRelationshipVos.get(i).getCardNumber());
                                List<SearchRelationshipVo> searchRelationshipVoSubordinateList1 = transferRelationshipMapper.querySubordinate(searchRelationshipVoSubordinateList.get(n).getCardNumber());
                                /**判断是否有下级  如果有给true*/
                            if (searchRelationshipVoSubordinateList1.size()!=0){
                                searchRelationshipSubordinateVo.setSubordinate(true);
                            }else {
                                searchRelationshipSubordinateVo.setSubordinate(false);
                            }
                            //存放数据
                            searchRelationshipVoList.add(searchRelationshipSubordinateVo);
                            //存入map
                            hashMap.put(searchRelationshipVoSubordinateList.get(n).getCardNumber(),searchRelationshipVoSubordinateList.get(n).getCardNumber());
                            list.add(searchRelationshipSubordinateVo);
                          }
                        for (int r = 0; r < 1; ) {
                            //临时存储查询出来的参数
                            List<SearchRelationshipVo> list1 = new ArrayList<>();
                            for (int y = 0; y < list.size(); y++) {
                                List<SearchRelationshipVo> searchRelationshipVoSubordinateList1 = transferRelationshipMapper.querySubordinate(list.get(y).getCardNumber());
                                if (searchRelationshipVoSubordinateList1.size() != 0) {
                                    for (int l=0;l<searchRelationshipVoSubordinateList1.size();l++) {
                                        /**根据下级卡号 对比map 如果已经有值代表已经查询出过此卡号 跳过此次循环开启下一圈*/
                                        Object number = hashMap.get(searchRelationshipVoSubordinateList1.get(l).getCardNumber());
                                        if (number==null) {
                                            SearchRelationshipVo searchRelationshipSubordinateVo = new SearchRelationshipVo();
                                            searchRelationshipSubordinateVo.setName(searchRelationshipVoSubordinateList1.get(l).getName());
                                            searchRelationshipSubordinateVo.setCardNumber(searchRelationshipVoSubordinateList1.get(l).getCardNumber());
                                            searchRelationshipSubordinateVo.setRelationship(list.get(y).getCardNumber());
                                            searchRelationshipSubordinateVo.setTransferTimes(searchRelationshipVoSubordinateList1.get(l).getTransferTimes());
                                            List<SearchRelationshipVo> searchRelationshipVoSubordinateList2 = transferRelationshipMapper.querySubordinate(searchRelationshipVoSubordinateList1.get(l).getCardNumber());
                                            if (searchRelationshipVoSubordinateList2.size()!=0){
                                                searchRelationshipSubordinateVo.setSubordinate(true);
                                            }else {
                                                searchRelationshipSubordinateVo.setSubordinate(false);
                                            }
                                            searchRelationshipVoList.add(searchRelationshipSubordinateVo);
                                            list1.add(searchRelationshipSubordinateVo);
                                            //存入map
                                            hashMap.put(searchRelationshipVoSubordinateList1.get(l).getCardNumber(), searchRelationshipVoSubordinateList1.get(l).getCardNumber());
                                        }
                                    }
                                 }
                            }
                            //清空上一级的参数
                            list.clear();
                            if (list1.size() == 0) {
                               r++;
                            }
                            //将新查询出来下一级的参数放入list当中
                            for (int v = 0; v < list1.size(); v++) {
                                /**循环完成后  判断只让有下级的人进入下次循环*/
                                if (list1.get(v).getSubordinate()){
                                    SearchRelationshipVo searchRelationshipSubordinateVo = new SearchRelationshipVo();
                                    searchRelationshipSubordinateVo.setCardNumber(list1.get(v).getCardNumber());
                                    list.add(searchRelationshipSubordinateVo);
                                }
                            }
                            list1.clear();

                        }
                    }
                }
               RelationalAlgorithm relationalAlgorithm=new RelationalAlgorithm();
                //开启redis
                Jedis redis = ConFigRedis.getConn();
                //清空之前全部数据
                 redis.flushAll();
                 int o=0;
                for (int i=0;i<searchRelationshipVoList.size();i++){
                    if (searchRelationshipVoList.get(i).getSubordinate()){
                        redis.set("cardnumbe"+o++,searchRelationshipVoList.get(i).getCardNumber());
                    }
                }
                //关闭redis
                 redis.close();
        List list = relationalAlgorithm.searchPresentation(searchRelationshipVoList);
        return new Result(ResultCode.SUCCESS,list);
        }catch (Exception e){
            return new Result(ResultCode.FAIL);
        }
    }

    /**
     * 转账关系图 信息搜索接口  查询某一个点的具体位置
     * @param id
     * @return
     */
    @Override
    public Result specificLocation(String id) {
        try {
            EchartsUserVo echartsUserVo=new EchartsUserVo();
            Jedis conn = ConFigRedis.getConn();
            String position = conn.get(id);
            /**
             * 截取X
             */
            String x = StringUtils.substringBefore(position, "Y");
            /**
             * 截取Y
             */
            String Y = position.substring(x.length()+1, position.length());
            echartsUserVo.setName(id);
            echartsUserVo.setX(Integer.parseInt(x));
            echartsUserVo.setY(Integer.parseInt(Y));
            return new Result(ResultCode.SUCCESS,echartsUserVo);
        }catch (Exception e){
            return new Result(ResultCode.FAIL);
        }
    }

    /**
     * 清空关系图数据表
     */
    @Override
    public void emptyTransferRelationship() {
        transferRelationshipMapper.emptyTransferRelationship();
    }

    /**
     * excel数据导入数据库
     * @param eSerialsList
     */
    @Override
    public void insertTransferRelationship(List<abcExcie> eSerialsList) {
        transferRelationshipMapper.insertTransferRelationship(eSerialsList);
    }

    /**
     * 关系图 搜索接口
     * @param name
     * @return
     */
    @Override
    public Result pointSearch(String name) {
        try {
            boolean numeric = StringUtils.isNumeric(name);
            String cardNumber = null;
            String fullName = null;
            if (numeric) {
                cardNumber = name;
            } else {
                fullName = name;
            }
            //查询转账人
            List<SearchRelationshipVo> searchRelationshipVos = this.transferRelationshipMapper.queryTransferor(cardNumber, fullName);
            //查询被转账人
            List<SearchRelationshipVo> searchRelationshipVos1 = this.transferRelationshipMapper.queryTheTransferredPerson(cardNumber, fullName);
            List<SearchRelationshipVo> searchRelationshipVoList = new ArrayList<>();
            HashMap hashMap=new HashMap();
            if (searchRelationshipVos.size() != 0 || searchRelationshipVos1.size() != 0 ) {
                if (searchRelationshipVos.size() != 0) {
                    for (int i = 0; i < searchRelationshipVos.size(); i++) {
                        if (hashMap.get(searchRelationshipVos.get(i).getCardNumber())==null){
                            SearchRelationshipVo searchRelationshipVo = new SearchRelationshipVo();
                            searchRelationshipVo.setName(searchRelationshipVos.get(i).getName());
                            searchRelationshipVo.setRelationship(searchRelationshipVos.get(i).getRelationship());
                            searchRelationshipVo.setCardNumber(searchRelationshipVos.get(i).getCardNumber());
                            searchRelationshipVoList.add(searchRelationshipVo);
                            hashMap.put(searchRelationshipVos.get(i).getCardNumber(),searchRelationshipVos.get(i).getCardNumber());
                        }
                    }
                }
                if (searchRelationshipVos1.size() != 0) {
                    for (int n = 0; n < searchRelationshipVos1.size(); n++) {
                        if (hashMap.get(searchRelationshipVos1.get(n).getCardNumber())==null) {
                            SearchRelationshipVo searchRelationshipVo = new SearchRelationshipVo();
                            searchRelationshipVo.setName(searchRelationshipVos1.get(n).getName());
                            searchRelationshipVo.setRelationship(searchRelationshipVos1.get(n).getRelationship());
                            searchRelationshipVo.setCardNumber(searchRelationshipVos1.get(n).getCardNumber());
                            searchRelationshipVoList.add(searchRelationshipVo);
                        }
                    }
                }
                return new Result(ResultCode.SUCCESS, searchRelationshipVoList);
            }
            if (searchRelationshipVos.size() != 0)
                return new Result(ResultCode.SUCCESS, searchRelationshipVos);
            return new Result(ResultCode.SUCCESS, searchRelationshipVos1);
        } catch (Exception e) {
            return new Result(ResultCode.FAIL);
        }
    }


    /**
     * 查询两人转账关系  (生成点)(关系图) 接口
     * @param transferAssociationParam
     * @return
     */
    @Override
    public Result transferAssociation(TransferAssociationParam transferAssociationParam) {
        //点 X  Y轴生成类
        TransferLocation transferLocation=new TransferLocation();
        //层级
        int Hierarchy=1;
        //生成颜色
        Colour colour=new Colour();
        //查询搜索人信息   转账人
        List<SearchRelationshipVo> searchRelationshipVos = transferRelationshipMapper.personalInformationTransferor(transferAssociationParam.getTransfer());
        //查询搜索人信息   被转账人
        List<SearchRelationshipVo> searchRelationshipVos1 = transferRelationshipMapper.personalInformationTransferredPerson(transferAssociationParam.getTransfer());
        //将查询出来的转账人数据放入list中
        List<SearchRelationshipVo> searchRelationshipVoList1 = new ArrayList<>();
        SearchRelationshipVo searchRelationshipVo1 = new SearchRelationshipVo();
        /** 创建map 存放已经查询到的上级卡号    用于判断卡号是否已经重复查询*/
        HashMap hashMap1=new HashMap();
        //判断 是转账人列查询出来的 还是被转账人列查询出来的
        if (searchRelationshipVos.size() != 0) {
            for (int i = 0; i < searchRelationshipVos.size(); i++) {
                searchRelationshipVo1.setCardNumber(searchRelationshipVos.get(i).getCardNumber());
                searchRelationshipVo1.setName(searchRelationshipVos.get(i).getName());
                searchRelationshipVo1.setRelationship(searchRelationshipVos.get(i).getRelationship());
                searchRelationshipVo1.setSubordinate(searchRelationshipVos.get(i).getSubordinate());
                searchRelationshipVo1.setTransferTimes(searchRelationshipVos.get(i).getTransferTimes());
                searchRelationshipVoList1.add(searchRelationshipVo1);
            }
        } else {
            for (int i = 0; i < searchRelationshipVos1.size(); i++) {
                searchRelationshipVo1.setCardNumber(searchRelationshipVos1.get(i).getCardNumber());
                searchRelationshipVo1.setName(searchRelationshipVos1.get(i).getName());
                searchRelationshipVo1.setRelationship(searchRelationshipVos1.get(i).getRelationship());
                searchRelationshipVo1.setSubordinate(searchRelationshipVos1.get(i).getSubordinate());
                searchRelationshipVo1.setTransferTimes(searchRelationshipVos1.get(i).getTransferTimes());
                searchRelationshipVoList1.add(searchRelationshipVo1);
            }
        }
        /**将有关系的数据放入这个list中  最终返回这个list*/
        List<SearchRelationshipVo> transferAssociationList = new ArrayList<>();
        /** 存放下级关系数据*/
        List<SearchRelationshipVo> searchRelationshipVoList = new ArrayList<>();
        /**创建map 将已经查询出来的下级存入map中  防止相互转账进入死循环*/
        HashMap hashMap = new HashMap();
        //转账人
        for (int i = 0; i < searchRelationshipVoList1.size(); i++) {
            SearchRelationshipVo searchRelationshipVo = new SearchRelationshipVo();
            searchRelationshipVo.setName(searchRelationshipVoList1.get(i).getName());
            searchRelationshipVo.setRelationship(searchRelationshipVoList1.get(i).getRelationship());
            searchRelationshipVo.setTransferTimes(searchRelationshipVoList1.get(i).getTransferTimes());
            searchRelationshipVo.setX(-300);
            searchRelationshipVo.setY(600);
            searchRelationshipVo.setColor(colour.getColour());
            searchRelationshipVo.setSize(20);
            searchRelationshipVo.setHierarchy(Hierarchy);
            searchRelationshipVo.setCardNumber(searchRelationshipVoList1.get(i).getCardNumber());
            //层级递增
            Hierarchy++;
            //存入map
            hashMap.put(searchRelationshipVoList1.get(i).getCardNumber(), searchRelationshipVoList1.get(i).getCardNumber());
            /** 查询下级数据*/
            List<SearchRelationshipVo> searchRelationshipVoSubordinateList = transferRelationshipMapper.querySubordinate(searchRelationshipVoList1.get(i).getCardNumber());
            searchRelationshipVo.setSubordinateQuantity(searchRelationshipVoSubordinateList.size());
            /**判断是否有下级  如果有给true*/
            if (searchRelationshipVoSubordinateList.size() != 0) {
                searchRelationshipVo.setSubordinate(true);
            } else {
                searchRelationshipVo.setSubordinate(false);
            }
            searchRelationshipVoList.add(searchRelationshipVo);
            transferAssociationList.add(searchRelationshipVo);
            if (searchRelationshipVoSubordinateList.size() != 0) {
                /**存放下级参数list*/
                List<SearchRelationshipVo> list = new ArrayList<>();
                for (int n = 0; n < searchRelationshipVoSubordinateList.size(); n++) {
                    SearchRelationshipVo searchRelationshipSubordinateVo = new SearchRelationshipVo();
                    searchRelationshipSubordinateVo.setName(searchRelationshipVoSubordinateList.get(n).getName());
                    searchRelationshipSubordinateVo.setCardNumber(searchRelationshipVoSubordinateList.get(n).getCardNumber());
                    searchRelationshipSubordinateVo.setTransferTimes(searchRelationshipVoSubordinateList.get(n).getTransferTimes());
                    searchRelationshipSubordinateVo.setRelationship(searchRelationshipVos.get(i).getCardNumber());
                    searchRelationshipSubordinateVo.setHierarchy(Hierarchy);
                    //查询下级
                    List<SearchRelationshipVo> searchRelationshipVoSubordinateList1 = transferRelationshipMapper.querySubordinate(searchRelationshipVoSubordinateList.get(n).getCardNumber());
                    searchRelationshipSubordinateVo.setSubordinateQuantity(searchRelationshipVoSubordinateList1.size());
                    /**判断这一层中是否有被转账人 如果有就存入list中 结束循环*/
                    if (searchRelationshipVoSubordinateList.get(n).getCardNumber().equals(transferAssociationParam.getPayee())) {
                        searchRelationshipSubordinateVo.setSubordinate(false);
                        searchRelationshipSubordinateVo.setX((int)(Math.random()*2000));
                        searchRelationshipSubordinateVo.setY((int)(Math.random()*800));
                        searchRelationshipSubordinateVo.setColor(colour.getColour());
                        searchRelationshipSubordinateVo.setSize(10);
                        transferAssociationList.add(searchRelationshipSubordinateVo);
                        List<SearchRelationshipVo> searchRelationshipVoList2 = transferLocation.transferLocation(transferAssociationList);
                        return new Result(ResultCode.SUCCESS, searchRelationshipVoList2);
                    }
                    /**判断是否有下级  如果有给true*/
                    if (searchRelationshipVoSubordinateList1.size() != 0) {
                        searchRelationshipSubordinateVo.setSubordinate(true);
                    } else {
                        searchRelationshipSubordinateVo.setSubordinate(false);
                    }
                    //存放数据
                    searchRelationshipVoList.add(searchRelationshipSubordinateVo);
                    //存入map
                    hashMap.put(searchRelationshipVoSubordinateList.get(n).getCardNumber(), searchRelationshipVoSubordinateList.get(n).getCardNumber());
                    list.add(searchRelationshipSubordinateVo);
                }
                for (int r = 0; r < 1; ) {
                    Hierarchy++;
                    //临时存储查询出来的参数
                    List<SearchRelationshipVo> list1 = new ArrayList<>();
                    for (int y = 0; y < list.size(); y++) {
                        //查询下级数据
                        List<SearchRelationshipVo> searchRelationshipVoSubordinateList1 = transferRelationshipMapper.querySubordinate(list.get(y).getCardNumber());
                        if (searchRelationshipVoSubordinateList1.size() != 0) {
                            for (int l = 0; l < searchRelationshipVoSubordinateList1.size(); l++) {
                                /**根据下级卡号 对比map 如果已经有值代表已经查询出过此卡号 跳过此次循环开启下一圈*/
                                Object number = hashMap.get(searchRelationshipVoSubordinateList1.get(l).getCardNumber());
                                if (number == null) {
                                    SearchRelationshipVo searchRelationshipSubordinateVo = new SearchRelationshipVo();
                                    searchRelationshipSubordinateVo.setSubordinateQuantity(searchRelationshipVoSubordinateList1.size());
                                    searchRelationshipSubordinateVo.setName(searchRelationshipVoSubordinateList1.get(l).getName());
                                    searchRelationshipSubordinateVo.setCardNumber(searchRelationshipVoSubordinateList1.get(l).getCardNumber());
                                    searchRelationshipSubordinateVo.setRelationship(list.get(y).getCardNumber());
                                    searchRelationshipSubordinateVo.setTransferTimes(searchRelationshipVoSubordinateList1.get(l).getTransferTimes());
                                    searchRelationshipSubordinateVo.setHierarchy(Hierarchy);
                                    List<SearchRelationshipVo> searchRelationshipVoSubordinateList2 = transferRelationshipMapper.querySubordinate(searchRelationshipVoSubordinateList1.get(l).getCardNumber());
                                    searchRelationshipSubordinateVo.setSubordinateQuantity(searchRelationshipVoSubordinateList2.size());
                                    if (searchRelationshipVoSubordinateList2.size() != 0) {
                                        searchRelationshipSubordinateVo.setSubordinate(true);
                                    } else {
                                        searchRelationshipSubordinateVo.setSubordinate(false);
                                    }
                                    searchRelationshipVoList.add(searchRelationshipSubordinateVo);
                                    list1.add(searchRelationshipSubordinateVo);
                                    //存入map
                                    hashMap.put(searchRelationshipVoSubordinateList1.get(l).getCardNumber(), searchRelationshipVoSubordinateList1.get(l).getCardNumber());
                                    /**
                                     * 判断这一层中是否有被转账人 如果有就存入返回值list中   如果进入此判断 代表已经找到被转账人  之后从被转账人往上循环推进
                                     */
                                    if (searchRelationshipSubordinateVo.getCardNumber().equals(transferAssociationParam.getPayee())) {
                                        searchRelationshipSubordinateVo.setX(2300);
                                        searchRelationshipSubordinateVo.setY(600);
                                        searchRelationshipSubordinateVo.setColor(colour.getColour());
                                        searchRelationshipSubordinateVo.setSize(20);
                                        searchRelationshipSubordinateVo.setHierarchy(Hierarchy);
                                        //添加被转账人信息
                                        transferAssociationList.add(searchRelationshipSubordinateVo);
                                        //存放需要查询上级的人的卡号  List
                                        List<SearchRelationshipVo> superiorList = new ArrayList<>();
                                        superiorList.add(searchRelationshipSubordinateVo);
                                        //向防止重复map添加已经查询到的上级卡号
                                        hashMap1.put(searchRelationshipSubordinateVo.getCardNumber(),searchRelationshipSubordinateVo.getCardNumber());
                                      for (int b=0;b<1;) {
                                          for (int a = 0; a < superiorList.size(); a++) {
                                              //查询上级转账人方法
                                              List<SearchRelationshipVo> superior = transferRelationshipMapper.querySuperior(superiorList.get(a).getCardNumber());
                                              //清空list数据
                                              superiorList.clear();
                                              //判断上级是否是转账人  如果是 就直接返回数据
                                              for (int h = 0; h < superior.size(); h++) {
                                                  if (superior.get(h).getCardNumber().equals(transferAssociationParam.getTransfer())) {
                                                      List<SearchRelationshipVo> searchRelationshipVoList2 = transferLocation.transferLocation(transferAssociationList);
                                                      return new Result(ResultCode.SUCCESS, searchRelationshipVoList2);
                                                  }
                                              }
                                              //循环对比查询出来的上级与所有list存储的下级做对比
                                              for (int k = 0; k < searchRelationshipVoList.size(); k++) {
                                                  for (int n = 0; n < superior.size(); n++) {
                                                      //对比
                                                      if (superior.get(n).getCardNumber().equals(searchRelationshipVoList.get(k).getCardNumber())) {
                                                              SearchRelationshipVo searchRelationshipSubordinateVo1 = new SearchRelationshipVo();
                                                              searchRelationshipSubordinateVo1.setCardNumber(superior.get(n).getCardNumber());
                                                              searchRelationshipSubordinateVo1.setName(superior.get(n).getName());
                                                              searchRelationshipSubordinateVo1.setX((int) (Math.random() * 2000));
                                                              searchRelationshipSubordinateVo1.setY((int) (Math.random() * 800));
                                                              searchRelationshipSubordinateVo1.setColor(colour.getColour());
                                                              searchRelationshipSubordinateVo1.setSize(10);
                                                              searchRelationshipSubordinateVo1.setHierarchy(searchRelationshipVoList.get(k).getHierarchy());
                                                          searchRelationshipSubordinateVo1.setSubordinateQuantity(searchRelationshipVoList.get(k).getSubordinateQuantity());
                                                             Object Number = hashMap1.get(superior.get(n).getCardNumber());
                                                             if (Number==null){
                                                              //添加被转账人信息
                                                              transferAssociationList.add(searchRelationshipSubordinateVo1);
                                                             }
                                                              //向防止重复map添加已经查询到的上级卡号
                                                              hashMap1.put(superior.get(n).getCardNumber(), superior.get(n).getCardNumber());
                                                              superiorList.add(searchRelationshipSubordinateVo1);
                                                      }
                                                  }
                                               }
                                             }
                                          }
                                       }
                                    }
                                }
                            }
                        }
                        //清空上一级的参数
                        list.clear();
                        if (list1.size() == 0) {
                            r++;
                        }
                        //将新查询出来下一级的参数放入list当中
                        for (int v = 0; v < list1.size(); v++) {
                            /**循环完成后  判断只让有下级的人进入下次循环*/
                            if (list1.get(v).getSubordinate()) {
                                SearchRelationshipVo searchRelationshipSubordinateVo = new SearchRelationshipVo();
                                searchRelationshipSubordinateVo.setCardNumber(list1.get(v).getCardNumber());
                                list.add(searchRelationshipSubordinateVo);
                            }
                        }
                        list1.clear();
                    }
                }
            }
            for (int p = 0; p < searchRelationshipVoList.size(); p++) {
                if (searchRelationshipVoList.get(p).getCardNumber() == transferAssociationParam.getPayee()) {
                    List<SearchRelationshipVo> searchRelationshipVoList2 = transferLocation.transferLocation(searchRelationshipVoList);
                    return new Result(ResultCode.SUCCESS, searchRelationshipVoList2);
                }
            }
            //如果没有 就返回null
            return new Result(ResultCode.SUCCESS, null);
        }


    /**
     * 关系图搜索  单人转账关系    转账信息信息查询接口
     * @return
     */
    @Override
    public Result personalTransferRelationship(){
        Jedis redis = ConFigRedis.getConn();
        List list=new ArrayList();
        for (int i=0;i<i+1;i++){
            //获取redis
            String  cardnumbe= redis.get("cardnumbe" + i);
            if (cardnumbe!=null){
                /**
                 * 查询单人转账关系
                 */
                List<personalTransferRelationshipVo> personalTransferRelationshipVos = transferRelationshipMapper.personalTransferRelationship(cardnumbe);
                for (int n=0;n<personalTransferRelationshipVos.size();n++){
                    TransferRelationship transferRelationship=new TransferRelationship();
                    Source source=new Source();
                    source.setId(personalTransferRelationshipVos.get(n).getSource());
                    Target target=new Target();
                    target.setId(personalTransferRelationshipVos.get(n).getTarget());
                    TransferTimes transferTimes=new TransferTimes();
                    transferTimes.setTransferTimes(personalTransferRelationshipVos.get(n).getTransferTimes());
                    transferRelationship.setSource(source);
                    transferRelationship.setTarget(target);
                    transferRelationship.setTransferTimes(transferTimes);
                    list.add(transferRelationship);
                }
            }else {
                return new Result(ResultCode.SUCCESS,list);
            }
        }
        return new Result(ResultCode.SUCCESS);
    }


    /**
     * 查询两人转账关系  关系  (关系图) 接口
     * @param transferAssociationParam
     * @return
     */
    @Override
    public Result trBetweenTwoPersons(List<SearchRelationshipVo> transferAssociationParam) {
        List list=new ArrayList();
        for (int i=0;i<transferAssociationParam.size();i++){
            if (!"个人".equals(transferAssociationParam.get(i).getRelationship())){
                List<personalTransferRelationshipVo> personalTransferRelationshipVos = transferRelationshipMapper.trBetweenTwoPersons(transferAssociationParam.get(i).getCardNumber());
                for (int n=0;n<personalTransferRelationshipVos.size();n++){
                    TransferRelationship transferRelationship=new TransferRelationship();
                    Source source=new Source();
                    source.setId(personalTransferRelationshipVos.get(n).getSource());
                    Target target=new Target();
                    target.setId(personalTransferRelationshipVos.get(n).getTarget());
                    TransferTimes transferTimes=new TransferTimes();
                    transferTimes.setTransferTimes(personalTransferRelationshipVos.get(n).getTransferTimes());
                    transferRelationship.setSource(source);
                    transferRelationship.setTarget(target);
                    transferRelationship.setTransferTimes(transferTimes);
                    if (!personalTransferRelationshipVos.get(n).getSource().equals(personalTransferRelationshipVos.get(n).getTarget())){
                        list.add(transferRelationship);
                    }
                }
            }
        }
        return new Result(ResultCode.SUCCESS,list);
    }
}