feat:平板页面

This commit is contained in:
2026-04-13 19:17:47 +08:00
parent 90ef9cf146
commit bca4d3ae43
37 changed files with 2987 additions and 652 deletions
@@ -3,7 +3,9 @@ package com.central.device.controller;
import com.central.common.model.PageResult;
import com.central.common.model.Result;
import com.central.device.model.IotCard;
import com.central.device.model.vo.IccidFlowVO;
import com.central.device.service.IIotCardService;
import com.central.device.util.http.SimpleHttpRequest;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.Parameters;
@@ -11,8 +13,16 @@ import io.swagger.v3.oas.annotations.enums.ParameterIn;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;
import org.jsoup.select.Elements;
import org.springframework.web.bind.annotation.*;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Map;
/**
@@ -125,4 +135,112 @@ public class IotCardController {
return Result.failed(e.getMessage());
}
}
/**
* 查询物联网卡流量信息
*/
@Operation(summary = "查询物联网卡流量信息")
@Parameter(name = "iccid", description = "ICCID卡号", required = true, in = ParameterIn.QUERY)
@GetMapping("/flow-info")
public Result<IccidFlowVO> queryFlowInfo(@RequestParam String iccid) {
try {
// 构建第三方查询URL
String url = String.format(
"http://api.slwul.com/yjiot/wxapi/action/searchcharge?appId=wx22f2a856e6286b28&openId=oA7vc59BnABsWZeXZzI6pbX0j0EM&iccid=%s&wx_exhibition_fieid=iccid",
iccid
);
// 发起HTTP请求获取HTML页面
SimpleHttpRequest request = new SimpleHttpRequest(url);
byte[] responseBytes = request.get().asBytes();
String htmlContent = new String(responseBytes, "UTF-8");
// 解析HTML并提取关键数据
IccidFlowVO flowVO = parseHtmlToVO(htmlContent, iccid);
return Result.succeed(flowVO, "查询成功");
} catch (Exception e) {
log.error("查询物联网卡流量信息失败, iccid={}", iccid, e);
return Result.failed("查询失败: " + e.getMessage());
}
}
/**
* 解析HTML页面为实体对象
*/
private IccidFlowVO parseHtmlToVO(String htmlContent, String iccid) {
IccidFlowVO flowVO = new IccidFlowVO();
flowVO.setIccid(iccid);
try {
Document doc = Jsoup.parse(htmlContent);
// 解析激活状态和实名状态
Elements statusButtons = doc.select(".weui_card_btn_left button");
if (statusButtons.size() >= 1) {
flowVO.setActiveStatus(statusButtons.get(0).text().trim());
}
if (statusButtons.size() >= 2) {
flowVO.setRealNameStatus(statusButtons.get(1).text().trim());
}
// 解析总流量
Element totalFlowElement = doc.select(".weui_card_data_left span").first();
if (totalFlowElement != null) {
String totalFlowText = totalFlowElement.text().replace("MB", "").trim();
flowVO.setTotalFlow(new BigDecimal(totalFlowText));
}
// 解析截止时间
Element expireTimeElement = doc.select(".weui_card_remain_days").first();
if (expireTimeElement != null) {
flowVO.setExpireTime(expireTimeElement.text().trim());
}
// 解析剩余流量
Element remainFlowElement = doc.select(".weui_card_remain_data span").first();
if (remainFlowElement != null) {
String remainFlowText = remainFlowElement.text().replace("MB", "").trim();
flowVO.setRemainFlow(new BigDecimal(remainFlowText));
}
// 解析当前套餐列表
List<IccidFlowVO.FlowPackage> packageList = new ArrayList<>();
Elements packageElements = doc.select(".currqrycard .qry");
for (Element pkgElement : packageElements) {
IccidFlowVO.FlowPackage pkg = new IccidFlowVO.FlowPackage();
// 解析套餐名称和状态
Elements spans = pkgElement.select("span");
if (spans.size() >= 1) {
pkg.setPackageName(spans.get(0).text().trim());
}
if (spans.size() >= 2) {
pkg.setStatus(spans.get(1).text().trim());
}
// 解析生效时间和截止时间
Element timeElement = pkgElement.select("p.weui_card_font_color").first();
if (timeElement != null) {
String timeText = timeElement.text();
// 格式:生效时间2025-10-01~截止时间2026-09-30
if (timeText.contains("生效时间") && timeText.contains("截止时间")) {
String[] timeParts = timeText.replace("生效时间", "").split("~截止时间");
if (timeParts.length == 2) {
pkg.setStartTime(timeParts[0].trim());
pkg.setEndTime(timeParts[1].trim());
}
}
}
packageList.add(pkg);
}
flowVO.setPackageList(packageList);
} catch (Exception e) {
log.error("解析HTML失败", e);
}
return flowVO;
}
}
@@ -0,0 +1,81 @@
package com.central.device.model.vo;
import lombok.Data;
import java.io.Serializable;
import java.math.BigDecimal;
import java.util.List;
/**
* 物联网卡流量查询VO
*
* @author system
* @date 2026-04-10
*/
@Data
public class IccidFlowVO implements Serializable {
private static final long serialVersionUID = 1L;
/**
* ICCID卡号
*/
private String iccid;
/**
* 激活状态:已激活/未激活
*/
private String activeStatus;
/**
* 实名状态:免实名/已实名/未实名
*/
private String realNameStatus;
/**
* 总流量(MB)
*/
private BigDecimal totalFlow;
/**
* 剩余流量(MB)
*/
private BigDecimal remainFlow;
/**
* 截止时间
*/
private String expireTime;
/**
* 套餐列表
*/
private List<FlowPackage> packageList;
/**
* 流量套餐信息
*/
@Data
public static class FlowPackage implements Serializable {
private static final long serialVersionUID = 1L;
/**
* 套餐名称
*/
private String packageName;
/**
* 套餐状态:使用中/已到期
*/
private String status;
/**
* 生效时间
*/
private String startTime;
/**
* 截止时间
*/
private String endTime;
}
}