From 3330e2e05e9c9b6de4a24ec2646337b4c5392501 Mon Sep 17 00:00:00 2001 From: zhangmeng <1334717033@qq.com> Date: Thu, 16 Mar 2023 23:50:35 +0800 Subject: [PATCH] =?UTF-8?q?=E6=89=8B=E6=9C=BA=E5=8F=B7=E5=B7=A5=E5=85=B7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../tools/controller/TelephoneController.java | 252 ++++++++++++++++-- src/main/resources/fxml/telephone.fxml | 17 +- 2 files changed, 250 insertions(+), 19 deletions(-) diff --git a/src/main/java/com/zhangmeng/tools/controller/TelephoneController.java b/src/main/java/com/zhangmeng/tools/controller/TelephoneController.java index b7b75c8..7ac9f65 100644 --- a/src/main/java/com/zhangmeng/tools/controller/TelephoneController.java +++ b/src/main/java/com/zhangmeng/tools/controller/TelephoneController.java @@ -1,13 +1,27 @@ package com.zhangmeng.tools.controller; import cn.hutool.core.util.RandomUtil; +import cn.hutool.http.HttpUtil; +import com.alibaba.fastjson.JSON; +import com.alibaba.fastjson.JSONArray; +import javafx.application.Platform; +import javafx.beans.value.ChangeListener; +import javafx.beans.value.ObservableValue; import javafx.collections.FXCollections; +import javafx.collections.ListChangeListener; import javafx.collections.ObservableList; import javafx.fxml.FXML; +import javafx.scene.control.Button; import javafx.scene.control.CheckBox; +import javafx.scene.control.TextArea; +import javafx.scene.control.TextField; import javafx.scene.layout.AnchorPane; import lombok.extern.slf4j.Slf4j; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + /** * @author : 芊芊墨客 * @version : 1.0 @@ -20,30 +34,238 @@ public class TelephoneController { public static final ObservableList list2 = FXCollections.observableArrayList(); public static final ObservableList list3 = FXCollections.observableArrayList(); + public static final ObservableList res_list = FXCollections.observableArrayList(); + public static final ObservableList checkbox_list = FXCollections.observableArrayList(); + + public static final ObservableList show_list = FXCollections.observableArrayList(); + @FXML public AnchorPane root; @FXML - public void initialize() { - init(); - int i = 100; - for (String t1 : list1) { + public TextArea result_show; - if (i == 1000){ - i = 100; + @FXML + public TextField telephone; + + @FXML + public Button query; + + @FXML + private Button gen; + + @FXML + private TextField num; + + @FXML + public void initialize() { + num.setText("100"); + init(); + init_checkbox(148.0, 168.0, list1); + init_checkbox(238.0, 258.0, list2); + init_checkbox(322.0, 342.0, list3); + + show_list.addListener((ListChangeListener) c -> { + while (c.next()){ + if (c.wasAdded()) { + StringBuilder stringBuilder = new StringBuilder(); + for (String s : show_list) { + stringBuilder.append(s); + } + receive(stringBuilder.toString()); + } + } + }); + + gen.setOnAction(actionEvent -> { + show_list.clear(); + check_res(); + int size = Integer.parseInt(num.getText()); + for (int i = 0; i < size; i++) { + + CheckBox checkBox = null; + int index; + if (res_list.size() == 0) { + index = RandomUtil.randomInt(0, checkbox_list.size() - 1); + checkBox = checkbox_list.get(index); + } else { + if (res_list.size() == 1 ){ + index = 0 ; + }else { + index = RandomUtil.randomInt(0, res_list.size() - 1); + } + checkBox = res_list.get(index); + } + + String res = checkBox.getText() + random_8(); + show_list.add(res); + show_list.add(System.lineSeparator()); + } + }); + query.setOnAction(actionEvent -> { + Map map = new HashMap<>(); + map.put("phone",telephone.getText().substring(0,7)); + String map_res = HttpUtil.post("https://api.uutool.cn/phone/location_batch", map); + R r = JSON.parseObject(map_res, R.class); + R.Data.Rows rows = r.getData().getRows().get(0); + String s = rows.getProvince() + "省 " + rows.city + "市 " + "区域编码:" +rows.area_code + "邮政编码:" + rows.getZip_code(); + result_show.setText(s); + }); + } + + public void receive(String msg) { + Platform.runLater(() -> { + this.result_show.setText(msg); + }); + + } + + public static class R { + private int status; + + private Data data; + + private String req_id; + + public void setStatus(int status){ + this.status = status; + } + public int getStatus(){ + return this.status; + } + public void setData(Data data){ + this.data = data; + } + public Data getData(){ + return this.data; + } + public void setReq_id(String req_id){ + this.req_id = req_id; + } + public String getReq_id(){ + return this.req_id; + } + + public static class Data { + private int count; + + private List rows ; + + public void setCount(int count){ + this.count = count; + } + public int getCount(){ + return this.count; + } + public void setRows(List rows){ + this.rows = rows; + } + public List getRows(){ + return this.rows; } - CheckBox checkBox = new CheckBox(t1); - root.getChildren().add(checkBox); - AnchorPane.setTopAnchor(checkBox,148.0); - AnchorPane.setLeftAnchor(checkBox,1017.0); - AnchorPane.setRightAnchor(checkBox,); - AnchorPane.setRightAnchor(checkBox,); - i += 100; + public static class Rows { + private String phone; + + private String isp; + + private String province; + + private String city; + + private String zip_code; + + private String area_code; + + private String segment; + + public void setPhone(String phone){ + this.phone = phone; + } + public String getPhone(){ + return this.phone; + } + public void setIsp(String isp){ + this.isp = isp; + } + public String getIsp(){ + return this.isp; + } + public void setProvince(String province){ + this.province = province; + } + public String getProvince(){ + return this.province; + } + public void setCity(String city){ + this.city = city; + } + public String getCity(){ + return this.city; + } + public void setZip_code(String zip_code){ + this.zip_code = zip_code; + } + public String getZip_code(){ + return this.zip_code; + } + public void setArea_code(String area_code){ + this.area_code = area_code; + } + public String getArea_code(){ + return this.area_code; + } + public void setSegment(String segment){ + this.segment = segment; + } + public String getSegment(){ + return this.segment; + } + + } } } - public void init(){ + + public void check_res() { + res_list.clear(); + for (CheckBox checkBox : checkbox_list) { + if (checkBox.isSelected()) { + res_list.add(checkBox); + } + } + } + + public void init_checkbox(double one, double two, ObservableList list) { + double i = 100; + double j = 100; + for (String t1 : list) { + + CheckBox checkBox = new CheckBox(t1); + root.getChildren().add(checkBox); + if (i <= 1000) { + AnchorPane.setTopAnchor(checkBox, one); + AnchorPane.setLeftAnchor(checkBox, i); + i += 100; + } else { + AnchorPane.setTopAnchor(checkBox, two); + AnchorPane.setLeftAnchor(checkBox, j); + j += 100; + } + + checkBox.selectedProperty().addListener(new ChangeListener() { + @Override + public void changed(ObservableValue observableValue, Boolean aBoolean, Boolean t1) { + if (t1) { + + } + } + }); + checkbox_list.add(checkBox); + } + } + + public void init() { list1.add("134"); list1.add("135"); list1.add("136"); @@ -91,7 +313,7 @@ public class TelephoneController { list3.add("199"); } - public String random_8(){ + public String random_8() { int i = RandomUtil.randomInt(10000000, 99999999); return String.valueOf(i); } diff --git a/src/main/resources/fxml/telephone.fxml b/src/main/resources/fxml/telephone.fxml index 613d2a9..e6513c2 100644 --- a/src/main/resources/fxml/telephone.fxml +++ b/src/main/resources/fxml/telephone.fxml @@ -1,18 +1,27 @@ - + + + - +