Commit 9f85871b authored by wuqinghua's avatar wuqinghua

2021/11/29 吴卿华 优化一级页面生成位置算法

parent 17032a4c
package com.example.gajz.transferrelationship.bean.vo;
import lombok.Data;
import lombok.ToString;
/**
* 计算中心点返回值封装类
*/
@Data
@ToString
public class CenterPointVo {
/**
* 卡号
*/
private String bankCardNo;
/**
* 姓名
*/
private String name;
/**
* X轴
*/
private int X;
/**
* Y轴
*/
private int Y;
/**
* 上级卡号
*/
private String superiorNumber;
}
package com.example.gajz.transferrelationship.dao;
import com.example.gajz.transferrelationship.bean.excel.abcExcie;
import com.example.gajz.transferrelationship.bean.vo.CenterPointVo;
import com.example.gajz.transferrelationship.bean.vo.SearchRelationshipVo;
import com.example.gajz.transferrelationship.bean.vo.TransferCardVo;
import com.example.gajz.transferrelationship.bean.vo.personalTransferRelationshipVo;
......@@ -115,4 +116,13 @@ public interface TransferRelationshipMapper {
* @return
*/
List<personalTransferRelationshipVo> trBetweenTwoPersons(String cardNumber);
/**
* 查询中心点下级中心点
* @param transferCardVoList
* @return
*/
List<CenterPointVo> centerPointMethod(List<TransferCardVo> transferCardVoList, String bankCardNo);
}
......@@ -2,11 +2,20 @@ package com.example.gajz.transferrelationship.neo4j;
import com.example.gajz.redis.ConFigRedis;
import redis.clients.jedis.Jedis;
import java.util.HashMap;
import java.util.Set;
public class test {
public static void main(String[] args) {
Jedis conn = ConFigRedis.getConn();
conn.flushAll();
HashMap hashMap=new HashMap();
hashMap.put("1","111");
hashMap.put("2","222");
hashMap.put("3","333");
hashMap.put("4","444");
System.out.println(hashMap.size());
......
package com.example.gajz.transferrelationship.relationalalgorithm;
import com.example.gajz.transferrelationship.bean.vo.CenterPointVo;
import com.example.gajz.transferrelationship.bean.vo.TransferCardVo;
import com.example.gajz.transferrelationship.dao.TransferRelationshipMapper;
import org.springframework.stereotype.Component;
import javax.annotation.PostConstruct;
import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
/**
* 计算中心点位置工具类
*/
@Component
public class CalculationCenterPoint {
/**关系图数据持久层*/
@Resource
TransferRelationshipMapper transferRelationshipMapper;
@Resource
LocationCalculation locationCalculation;
public static CalculationCenterPoint test;
@PostConstruct
public void init(){
test= this;
test.transferRelationshipMapper=transferRelationshipMapper;
}
/**
* 计算各个中心点位置
* @param transferCardVoList
* @return
*/
public List<CenterPointVo> CenterPointMethod(List<TransferCardVo> transferCardVoList){
// System.out.println(transferCardVoList.size());
/** 返回值List*/
List<CenterPointVo> centerPointVoList=new ArrayList<>();
/**防止重复Map*/
HashMap repeat =new HashMap();
/**存放所有大圆位置的map 每次计算出新中心点位置的时候将之前的所有大圆位置比对 防止大圆碰撞*/
HashMap positionMap=new HashMap();
/**循环找下级 防止起始中心点没有下级*/
for (int i=0;i<transferCardVoList.size();i++){
//查询下级中心点
List<CenterPointVo> centerPointList = transferRelationshipMapper.centerPointMethod(transferCardVoList, transferCardVoList.get(i).getBankCardNo());
// System.out.println("第"+i+"次"+"本级卡号:"+transferCardVoList.get(i).getBankCardNo()+"下级数量:"+centerPointList.size());
CenterPointVo centerPointVo=new CenterPointVo();
/**将起始点位置存入返回值list中*/
centerPointVo.setBankCardNo(transferCardVoList.get(i).getBankCardNo());
centerPointVo.setName(transferCardVoList.get(i).getName());
if (centerPointList.size()!=0) {
centerPointVo.setX(1000);
centerPointVo.setY(1000);
}else {
Object CardNo = repeat.get(transferCardVoList.get(i).getBankCardNo());
if (CardNo==null){
//将卡号存入map中 防止重复
repeat.put(transferCardVoList.get(i).getBankCardNo(),transferCardVoList.get(i).getBankCardNo());
centerPointVo.setX((int)(Math.random()*2000));
centerPointVo.setY((int)(Math.random()*2000));
centerPointVoList.add(centerPointVo);
}
continue;
}
Object CardNo = repeat.get(transferCardVoList.get(i).getBankCardNo());
if (CardNo==null){
//将卡号存入map中 防止重复
repeat.put(transferCardVoList.get(i).getBankCardNo(),transferCardVoList.get(i).getBankCardNo());
centerPointVoList.add(centerPointVo);
}
/**计算中心点大圆的X Y轴*/
HashMap hashMap = locationCalculation.LocationCalculationMethod(centerPointVo.getBankCardNo(), centerPointVo.getX(), centerPointVo.getY());
/**将大圆的四角位置存入map中*/
positionMap.put(0+"zX",hashMap.get("zx"));
positionMap.put(0+"zY",hashMap.get("zy"));
positionMap.put(0+"yX",hashMap.get("yx"));
positionMap.put(0+"yY",hashMap.get("yy"));
positionMap.put(0+"sX",hashMap.get("sx"));
positionMap.put(0+"sY",hashMap.get("sy"));
positionMap.put(0+"xX",hashMap.get("xx"));
positionMap.put(0+"xY",hashMap.get("xy"));
/**下级数据存放到此list中*/
List<CenterPointVo> subordinateList=new ArrayList<>();
/**将第一级的下级数据存放到下级list中*/
for (int x=0;x<centerPointList.size();x++){
CenterPointVo centerPointVo1=new CenterPointVo();
centerPointVo1.setName(centerPointList.get(x).getName());
centerPointVo1.setBankCardNo(centerPointList.get(x).getBankCardNo());
centerPointVo1.setSuperiorNumber(centerPointVo.getBankCardNo());
subordinateList.add(centerPointVo1);
}
/**创建存储上级XY轴map*/
HashMap superiorMap=new HashMap();
superiorMap.put(centerPointVo.getBankCardNo()+"yx",hashMap.get("yx"));
superiorMap.put(centerPointVo.getBankCardNo()+"yy",hashMap.get("yy"));
/**-------------------------------------------------计算下级中心点位置--------------------------------------------------*/
/**存放已经存在的xy轴map的下标*/
int depositSubscript = 1;
/**开启无限循环*/
for (int w=0;w<1;){
/**下级(中心点)总数*/
int total = subordinateList.size();
/**每份点数*/
int pointsPerShare = total/2;
/**临时存放下级中心点list*/
List<CenterPointVo> temporary=new ArrayList<>();
/**循环下级中心点*/
for (int x=0;x<subordinateList.size();x++){
if (x<pointsPerShare){
/**获取上级X Y轴*/
int yX = (int) superiorMap.get(subordinateList.get(x).getSuperiorNumber()+"yx");
int yY = (int) superiorMap.get(subordinateList.get(x).getSuperiorNumber()+"yy");
/**每循环一次 y轴加200 算出来的是下级的中心点*/
yX=yX+200;
yY=yY+200;
// superiorMap.put(subordinateList.get(x).getSuperiorNumber()+"yx",yX);
superiorMap.put(subordinateList.get(x).getSuperiorNumber()+"yy",yY);
/**计算下级大圆的XY轴*/
HashMap hashMap1 = locationCalculation.LocationCalculationMethod(subordinateList.get(x).getBankCardNo(), yX , yY);
/**对比判断上级大圈XY轴 判断是否有碰撞 如果有碰撞 Y轴加200 并且重新循环*/
/**-----------------------------------------------获取下级大圆的xy轴---------------------------------------------*/
int zx = (int) hashMap1.get("zx");
int yx = (int) hashMap1.get("yx");
int sy = (int) hashMap1.get("sy");
int xy = (int) hashMap1.get("xy");
int yy = (int) hashMap1.get("yy");
/**-----------------------------------------------获取下级大圆的xy轴---------------------------------------------*/
/**循环已经已经存储的大圆XY轴 跟新生成的大圆XY轴做对比 防止碰撞*/
int l=depositSubscript;
for (int h=0;h<l;h++){
/**已经存储存在的大圆XY轴*/
int YX = (int) positionMap.get(h+"yX");
int ZX = (int) positionMap.get(h+"zX");
int SY = (int) positionMap.get(h+"sY");
int XY = (int) positionMap.get(h+"xY");
/**判断是否有碰撞*/
if (((ZX>zx&&ZX>yx)||(YX<zx&&YX<yx)) || ((SY>sy&&SY>XY)||(XY<sy&&XY<xy))){
if (h==l-1) {
Object BankCardNos = repeat.get(subordinateList.get(x).getBankCardNo());
if (BankCardNos==null){
//返回值
CenterPointVo centerPointVo1 = new CenterPointVo();
centerPointVo1.setBankCardNo(subordinateList.get(x).getBankCardNo());
centerPointVo1.setName(subordinateList.get(x).getName());
centerPointVo1.setY(yX);
centerPointVo1.setX(yY);
centerPointVoList.add(centerPointVo1);
}
/**查询下级中心点 并将下级中心点存入list中*/
List<CenterPointVo> centerPointVoList1 = transferRelationshipMapper.centerPointMethod(transferCardVoList, subordinateList.get(x).getBankCardNo());
/**循环下级中心点 将下级中心点存入临时存储数据list中*/
for (int xj=0;xj<centerPointVoList1.size();xj++){
Object BankCardNo = repeat.get(centerPointVoList1.get(xj).getBankCardNo());
if (BankCardNo==null){
/**防止死循环*/
repeat.put(centerPointVoList1.get(xj).getBankCardNo(),centerPointVoList1.get(xj).getBankCardNo());
//存放上级
centerPointVoList1.get(xj).setSuperiorNumber(subordinateList.get(x).getBankCardNo());
//下级数据存入临时list中
temporary.add(centerPointVoList1.get(xj));
}
}
/**将中心点 大圆的X Y轴 存放入map中*/
positionMap.put(depositSubscript+"zX",zx);
positionMap.put(depositSubscript+"yX",yx);
positionMap.put(depositSubscript+"sY",sy);
positionMap.put(depositSubscript+"xY",xy);
positionMap.put(depositSubscript+"yY",yy);
/**存储上级中心点的X Y轴*/
superiorMap.put(subordinateList.get(x).getBankCardNo()+"yx",yx);
superiorMap.put(subordinateList.get(x).getBankCardNo()+"yy",yy);
depositSubscript++;
}
}else {
x--;
break;
}
}
}else if(x<=pointsPerShare*2){
/**获取上级X Y轴*/
int yX = (int) superiorMap.get(subordinateList.get(x).getSuperiorNumber()+"yx");
int yY = (int) superiorMap.get(subordinateList.get(x).getSuperiorNumber()+"yy");
/**每循环一次 y轴加200 算出来的是下级的中心点*/
yX=yX+200;
yY=yY+200;
// superiorMap.put(subordinateList.get(x).getSuperiorNumber()+"yx",yX);
superiorMap.put(subordinateList.get(x).getSuperiorNumber()+"yy",yY);
/**计算下级大圆的XY轴*/
HashMap hashMap1 = locationCalculation.LocationCalculationMethod(subordinateList.get(x).getBankCardNo(), yX , yY);
/**对比判断上级大圈XY轴 判断是否有碰撞 如果有碰撞 Y轴加200 并且重新循环*/
/**-----------------------------------------------获取下级大圆的xy轴---------------------------------------------*/
int zx = (int) hashMap1.get("zx");
int yx = (int) hashMap1.get("yx");
int sy = (int) hashMap1.get("sy");
int xy = (int) hashMap1.get("xy");
int yy = (int) hashMap1.get("yy");
/**-----------------------------------------------获取下级大圆的xy轴---------------------------------------------*/
/**循环已经已经存储的大圆XY轴 跟新生成的大圆XY轴做对比 防止碰撞*/
int l=depositSubscript;
for (int h=0;h<l;h++){
/**已经存在的大圆XY轴*/
int YX = (int) positionMap.get(h+"yX");
int ZX = (int) positionMap.get(h+"zX");
int SY = (int) positionMap.get(h+"sY");
int XY = (int) positionMap.get(h+"xY");
/**判断是否有碰撞*/
if (((ZX>zx&&ZX>yx)||(YX<zx&&YX<yx)) || ((SY>sy&&SY>XY)||(XY<sy&&XY<xy))){
if (h==l-1) {
Object o = repeat.get(subordinateList.get(x).getBankCardNo());
if (o==null){
//返回值
CenterPointVo centerPointVo1 = new CenterPointVo();
centerPointVo1.setBankCardNo(subordinateList.get(x).getBankCardNo());
centerPointVo1.setName(subordinateList.get(x).getName());
centerPointVo1.setY(yX);
centerPointVo1.setX(yY);
centerPointVoList.add(centerPointVo1);
}
// System.out.println("上级"+subordinateList.get(x).getBankCardNo());
/**查询下级中心点 并将下级中心点存入list中*/
List<CenterPointVo> centerPointVoList1 = transferRelationshipMapper.centerPointMethod(transferCardVoList, subordinateList.get(x).getBankCardNo());
/**循环下级中心点 将下级中心点存入临时存储数据list中*/
for (int xj=0;xj<centerPointVoList1.size();xj++){
Object BankCardNo = repeat.get(centerPointVoList1.get(xj).getBankCardNo());
if (BankCardNo==null) {
/**卡号存入放碰撞map*/
repeat.put(centerPointVoList1.get(xj).getBankCardNo(), centerPointVoList1.get(xj).getBankCardNo());
//存放上级
centerPointVoList1.get(xj).setSuperiorNumber(subordinateList.get(x).getBankCardNo());
//下级数据存入临时list中
temporary.add(centerPointVoList1.get(xj));
}
}
/**将中心点 大圆的X Y轴 存放入map中*/
positionMap.put(depositSubscript+"zX",zx);
positionMap.put(depositSubscript+"yX",yx);
positionMap.put(depositSubscript+"sY",sy);
positionMap.put(depositSubscript+"xY",xy);
positionMap.put(depositSubscript+"yY",yy);
/**存储上级中心点的X Y轴*/
superiorMap.put(subordinateList.get(x).getBankCardNo()+"yx",yx);
superiorMap.put(subordinateList.get(x).getBankCardNo()+"yy",yy);
depositSubscript++;
}
}else {
x--;
break;
}
}
}
}
/**下级中心点清空 放入新的下级数据*/
subordinateList.clear();
if (temporary.size() == 0) {
if (repeat.size()==transferCardVoList.size()) {
/** 临时存储list*/
List<CenterPointVo> temporaryList=new ArrayList<>();
for (int p=0;p<transferCardVoList.size();p++){
for (int x=0;x<centerPointVoList.size();x++){
if (transferCardVoList.get(p).getBankCardNo().equals(centerPointVoList.get(x).getBankCardNo())){
break;
}else if (x==centerPointVoList.size()-1){
Object o = repeat.get(transferCardVoList.get(p).getBankCardNo());
CenterPointVo centerPointVo1=new CenterPointVo();
centerPointVo1.setBankCardNo(transferCardVoList.get(p).getBankCardNo());
centerPointVo1.setName(transferCardVoList.get(p).getName());
centerPointVo1.setX((int)(Math.random()*2000));
centerPointVo1.setY((int)(Math.random()*2000));
temporaryList.add(centerPointVo1);
repeat.put(transferCardVoList.get(p).getBankCardNo(),1);
}
}
}
for (int k=0;k<temporaryList.size();k++){
centerPointVoList.add(temporaryList.get(k));
}
return centerPointVoList;
}else {
break;
}
}
for (int x=0;x<temporary.size();x++){
subordinateList.add(temporary.get(x));
}
}
}
return centerPointVoList;
}
}
package com.example.gajz.transferrelationship.relationalalgorithm;
import com.example.gajz.transferrelationship.bean.param.data;
import com.example.gajz.transferrelationship.dao.TransferRelationshipMapper;
import org.springframework.stereotype.Component;
import javax.annotation.PostConstruct;
import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
/**
* 算大图四个角的XY轴 工具类
*/
@Component
public class LocationCalculation {
/**关系图数据持久层*/
@Resource
TransferRelationshipMapper transferRelationshipMapper;
public static LocationCalculation test;
@PostConstruct
public void init(){
test= this;
test.transferRelationshipMapper=transferRelationshipMapper;
}
/**
* 算大图四个角的XY轴 方法
*/
public HashMap LocationCalculationMethod(String bankCardNo,int X,int Y){
/**存储大圆的四角X Y轴数据*/
HashMap xyMap = new HashMap();
/**查询被转账人(下级)全部信息*/
List<data> transfer = transferRelationshipMapper.transferRelationship(bankCardNo);
/**下级数据存放list*/
List<com.example.gajz.transferrelationship.bean.param.data> dataList=new ArrayList<>();
for (int i=0;i<transfer.size();i++){
com.example.gajz.transferrelationship.bean.param.data data=new com.example.gajz.transferrelationship.bean.param.data();
data.setName(transfer.get(i).getName());
dataList.add(data);
}
/**算大圈半径专用 下级数量总数*/
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;
xyMap.put("zx",(X-fullCircleRadius)); //圆左X轴
xyMap.put("zy",Y); //圆左Y轴
xyMap.put("yx",(X+fullCircleRadius)); //圆右X轴
xyMap.put("yy",Y); //圆右Y轴
xyMap.put("sx",X); //圆上X轴
xyMap.put("sy",(Y-fullCircleRadius)); //圆上Y轴
xyMap.put("xx",X); //圆下X轴
xyMap.put("xy",(Y+fullCircleRadius)); //圆下Y轴
return xyMap;
}
}
......@@ -17,6 +17,7 @@ public class TransferLocation {
@Resource
TransferRelationshipMapper transferRelationshipMapper;
public static TransferLocation test;
@PostConstruct
......@@ -24,7 +25,6 @@ public class TransferLocation {
test= this;
test.transferRelationshipMapper=transferRelationshipMapper;
}
/**
* 双人转账关系 位置生成方法
* @param transferAssociationList
......
......@@ -10,6 +10,7 @@ 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.CalculationCenterPoint;
import com.example.gajz.transferrelationship.relationalalgorithm.RelationalAlgorithm;
import com.example.gajz.transferrelationship.relationalalgorithm.TransferLocation;
import com.example.gajz.transferrelationship.service.TransferRelationshipService;
......@@ -35,6 +36,8 @@ public class TransferRelationshipServiceImpl implements TransferRelationshipServ
/**HugeGraph*/
@Autowired
HugeCollectionProperties hugeCollectionProperties;
@Autowired
CalculationCenterPoint calculationCenterPoint;
/**
......@@ -82,32 +85,44 @@ public class TransferRelationshipServiceImpl implements TransferRelationshipServ
public List diagramSpot() {
// Jedis conn = ConFigRedis.getConn();
/**已经存在的点 会存储到map里面*/
HashMap hashMap=new HashMap();
HashMap hashMap = new HashMap();
/**存储已经查找到的中心点下级 防止重复*/
HashMap centerPointMap = new HashMap();
//查询转账人(中心点)信息
List<TransferCardVo> transferCardVos = transferRelationshipMapper.selectTransferCard();
/**----------------------------------计算中心点位置 开始------------------------------------*/
/**计算中心点方法*/
List<CenterPointVo> centerPointVoList = calculationCenterPoint.CenterPointMethod(transferCardVos);
// System.out.println(centerPointVoList.size());
/**----------------------------------计算中心点位置 结束------------------------------------*/
List list=new ArrayList();
int centerPointX = 0;
int centerPointY = 0;
//存储所有大圆的四角X Y轴数据
HashMap xyMap = new HashMap();
/** 中心点*/
for (int i=0;i<transferCardVos.size();i++){
for (int i=0;i<centerPointVoList.size();i++){
//是否重叠
boolean overlap=false;
if (!overlap){
centerPointVoList.get(i).setX(centerPointVoList.get(i).getX()+20);
centerPointVoList.get(i).setY(centerPointVoList.get(i).getY()+20);
}
//生成颜色
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.setId(centerPointVoList.get(i).getBankCardNo());
test.setX(centerPointVoList.get(i).getX());
test.setY(centerPointVoList.get(i).getY());
test.setName(centerPointVoList.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<com.example.gajz.transferrelationship.bean.param.data> transfer = transferRelationshipMapper.transferRelationship(centerPointVoList.get(i).getBankCardNo());
/**将没有重复的值 存储到这个list里面*/
List<com.example.gajz.transferrelationship.bean.param.data> dataList=new ArrayList<>();
for (int p=0;p<transfer.size();p++){
......@@ -166,16 +181,12 @@ public class TransferRelationshipServiceImpl implements TransferRelationshipServ
}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)))
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))) ){
((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轴
......
......@@ -150,5 +150,16 @@
group by bank_card_no
</select>
<!--查询中心点下级中心点-->
<select id="centerPointMethod" resultType="com.example.gajz.transferrelationship.bean.vo.CenterPointVo">
select bank_card_no as bankCardNo from (
select end_card_no as bank_card_no from abc_statement where bank_card_no=#{bankCardNo} and end_card_no is not null group by end_card_no) a
where a.bank_card_no in (
<foreach collection="transferCardVoList" item="transferCardVoList" index="index" separator=",">
#{transferCardVoList.bankCardNo}
</foreach>
)
</select>
</mapper>
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment