From 59143eec4aebb251a7f8561a29afd89ac8a2676f Mon Sep 17 00:00:00 2001 From: fengyarnom Date: Tue, 3 Jun 2025 16:49:03 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E5=A2=9E=E5=BC=BA=20SIM=20=E6=B5=81?= =?UTF-8?q?=E9=87=8F=E5=8D=A1=E7=AE=A1=E7=90=86=E5=89=8D=E7=AB=AF=E9=A1=B5?= =?UTF-8?q?=E9=9D=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../beidou/controller/SimCardController.java | 282 ++++++++++++++++-- .../static/api/init_super_admin.json | 14 +- .../templates/page/sim_device_mapping.html | 164 ++++++++++ .../resources/templates/page/sim_status.html | 20 +- .../templates/page/sim_traffic_records.html | 140 +++++++++ 5 files changed, 593 insertions(+), 27 deletions(-) create mode 100644 sec-beidou/src/main/resources/templates/page/sim_device_mapping.html create mode 100644 sec-beidou/src/main/resources/templates/page/sim_traffic_records.html diff --git a/sec-beidou/src/main/java/com/imdroid/beidou/controller/SimCardController.java b/sec-beidou/src/main/java/com/imdroid/beidou/controller/SimCardController.java index 69c3eaaf..14ece89a 100644 --- a/sec-beidou/src/main/java/com/imdroid/beidou/controller/SimCardController.java +++ b/sec-beidou/src/main/java/com/imdroid/beidou/controller/SimCardController.java @@ -34,7 +34,16 @@ public class SimCardController extends BasicController { private String KEY; @Autowired - private SimCardsMapper simCardsMapper; + private GnssDeviceMapper gnssDeviceMapper; + + @Autowired + private TrafficCardMapper trafficCardMapper; + + @Autowired + private TrafficDeviceMappingMapper trafficDeviceMappingMapper; + + @Autowired + private TrafficRecordMapper trafficRecordMapper; @RequestMapping("/page/sim_status") public String simStatus(Model m, HttpSession session) { @@ -43,6 +52,20 @@ public class SimCardController extends BasicController { return "/page/sim_status"; } + @RequestMapping("/page/sim_traffic_records") + public String simTrafficRecords(Model m, HttpSession session) { + initModel(m, session); + + return "/page/sim_traffic_records"; + } + + @RequestMapping("/page/sim_device_mapping") + public String simDeviceMapping(Model m, HttpSession session) { + initModel(m, session); + + return "/page/sim_device_mapping"; + } + @RequestMapping("/sim/list") @ResponseBody public JSONObject list(HttpSession session, @@ -51,37 +74,98 @@ public class SimCardController extends BasicController { String searchType, String searchContent, Integer status) { - Page pageable = new Page<>(page, limit); - - QueryWrapper queryWrapper = new QueryWrapper<>(); + QueryWrapper deviceQueryWrapper = new QueryWrapper<>(); if (!StringUtils.isEmpty(searchContent)) { switch(searchType) { case "deviceId": - queryWrapper.like("deviceid", searchContent.trim()); + deviceQueryWrapper.like("deviceid", searchContent.trim()); break; case "iccid": - queryWrapper.like("iccid", searchContent.trim()); + deviceQueryWrapper.like("iccid", searchContent.trim()); break; case "simNumber": - queryWrapper.like("msisdn", searchContent.trim()); + // 通过SIM号查找对应的ICCID,然后查询设备 + TrafficCard cardByMsisdn = trafficCardMapper.selectOne( + new QueryWrapper().like("msisdn", searchContent.trim()) + ); + if (cardByMsisdn != null) { + deviceQueryWrapper.eq("iccid", cardByMsisdn.getIccid()); + } else { + deviceQueryWrapper.eq("iccid", ""); + } break; } } - if (status != null) { - queryWrapper.eq("status", status); - } - queryWrapper.orderByDesc("updatetime"); - IPage cs = simCardsMapper.selectPage(pageable, queryWrapper); + // 只查询有ICCID的设备 + deviceQueryWrapper.isNotNull("iccid"); + deviceQueryWrapper.ne("iccid", ""); + + if (status != null) { + List cardsWithStatus = trafficCardMapper.selectList( + new QueryWrapper().eq("status", status) + ); + if (cardsWithStatus.isEmpty()) { + JSONObject jsonObject = new JSONObject(); + jsonObject.put("code", 0); + jsonObject.put("msg", ""); + jsonObject.put("count", 0); + jsonObject.put("data", new ArrayList<>()); + return jsonObject; + } + + List iccids = new ArrayList<>(); + for (TrafficCard card : cardsWithStatus) { + iccids.add(card.getIccid()); + } + deviceQueryWrapper.in("iccid", iccids); + } + + deviceQueryWrapper.orderByDesc("deviceid"); + + Page pageable = new Page<>(page, limit); + IPage devices = gnssDeviceMapper.selectPage(pageable, deviceQueryWrapper); + + List> enrichedData = new ArrayList<>(); + for (GnssDevice device : devices.getRecords()) { + TrafficCard trafficCard = null; + if (device.getIccid() != null && !device.getIccid().trim().isEmpty()) { + trafficCard = trafficCardMapper.findByIccid(device.getIccid()); + } + + Map deviceData = new HashMap<>(); + deviceData.put("id", device.getId()); + deviceData.put("deviceid", device.getDeviceid()); + deviceData.put("iccid", device.getIccid()); + + if (trafficCard != null) { + deviceData.put("msisdn", trafficCard.getMsisdn()); + deviceData.put("status", trafficCard.getStatus()); + deviceData.put("remaining", trafficCard.getRemaining()); + deviceData.put("total", trafficCard.getTotal()); + deviceData.put("used", trafficCard.getUsed()); + deviceData.put("updateTime", trafficCard.getUpdateTime()); + deviceData.put("queryStatus", trafficCard.getQueryStatus()); + } else { + deviceData.put("msisdn", "-"); + deviceData.put("status", TrafficCard.STATUS_UNKNOWN); + deviceData.put("remaining", 0); + deviceData.put("total", 0); + deviceData.put("used", 0); + deviceData.put("updateTime", null); + deviceData.put("queryStatus", TrafficCard.QUERY_STATUS_NORMAL); + } + + enrichedData.add(deviceData); + } JSONObject jsonObject = new JSONObject(); jsonObject.put("code", 0); jsonObject.put("msg", ""); - jsonObject.put("count", cs.getTotal()); - jsonObject.put("data", cs.getRecords()); - System.out.println(jsonObject.toString()); + jsonObject.put("count", devices.getTotal()); + jsonObject.put("data", enrichedData); return jsonObject; } @@ -114,11 +198,11 @@ public class SimCardController extends BasicController { if (content.trim().isEmpty()) { throw new IllegalArgumentException("设备ID不能为空"); } - SimCard simCard = simCardsMapper.queryByDeviceId(content.trim()); - if (simCard == null) { - throw new IllegalArgumentException("未找到该设备ID对应的SIM卡信息"); + GnssDevice device = gnssDeviceMapper.queryByDeviceId(content.trim()); + if (device == null || device.getIccid() == null || device.getIccid().trim().isEmpty()) { + throw new IllegalArgumentException("未找到该设备ID或设备没有ICCID信息"); } - params.put("card", simCard.getIccid()); + params.put("card", device.getIccid()); break; case "simNumber": params.put("card", content); @@ -176,6 +260,166 @@ public class SimCardController extends BasicController { } } + @RequestMapping("/sim/traffic-records") + @ResponseBody + public JSONObject getTrafficRecords(HttpSession session, + int page, + int limit, + String searchType, + String searchContent) { + try { + Page pageable = new Page<>(page, limit); + QueryWrapper queryWrapper = new QueryWrapper<>(); + + if (!StringUtils.isEmpty(searchContent)) { + switch(searchType) { + case "deviceId": + GnssDevice device = gnssDeviceMapper.queryByDeviceId(searchContent.trim()); + if (device != null && device.getIccid() != null && !device.getIccid().trim().isEmpty()) { + queryWrapper.eq("iccid", device.getIccid()); + } else { + queryWrapper.eq("iccid", ""); + } + break; + case "iccid": + queryWrapper.like("iccid", searchContent.trim()); + break; + case "simNumber": + TrafficCard cardByMsisdn = trafficCardMapper.selectOne( + new QueryWrapper().like("msisdn", searchContent.trim()) + ); + if (cardByMsisdn != null) { + queryWrapper.eq("iccid", cardByMsisdn.getIccid()); + } else { + queryWrapper.eq("iccid", ""); + } + break; + } + } + + queryWrapper.orderByDesc("record_time"); + IPage records = trafficRecordMapper.selectPage(pageable, queryWrapper); + + List> enrichedData = new ArrayList<>(); + for (TrafficRecord record : records.getRecords()) { + Map recordData = new HashMap<>(); + recordData.put("id", record.getId()); + recordData.put("iccid", record.getIccid()); + recordData.put("recordTime", record.getRecordTime()); + recordData.put("remaining", record.getRemaining()); + recordData.put("total", record.getTotal()); + recordData.put("used", record.getUsed()); + + GnssDevice device = gnssDeviceMapper.selectOne( + new QueryWrapper().eq("iccid", record.getIccid()) + ); + if (device != null) { + recordData.put("deviceid", device.getDeviceid()); + } else { + recordData.put("deviceid", "无绑定设备"); + } + + TrafficCard trafficCard = trafficCardMapper.findByIccid(record.getIccid()); + if (trafficCard != null) { + recordData.put("msisdn", trafficCard.getMsisdn()); + } else { + recordData.put("msisdn", "-"); + } + + enrichedData.add(recordData); + } + + JSONObject jsonObject = new JSONObject(); + jsonObject.put("code", 0); + jsonObject.put("msg", ""); + jsonObject.put("count", records.getTotal()); + jsonObject.put("data", enrichedData); + return jsonObject; + + } catch (Exception e) { + JSONObject errorResponse = new JSONObject(); + errorResponse.put("code", 1); + errorResponse.put("msg", "查询失败: " + e.getMessage()); + errorResponse.put("count", 0); + errorResponse.put("data", new ArrayList<>()); + return errorResponse; + } + } + + @RequestMapping("/sim/device-mapping") + @ResponseBody + public JSONObject getDeviceMapping(HttpSession session, + int page, + int limit, + String searchType, + String searchContent) { + try { + Page pageable = new Page<>(page, limit); + QueryWrapper queryWrapper = new QueryWrapper<>(); + + if (!StringUtils.isEmpty(searchContent)) { + switch(searchType) { + case "deviceId": + queryWrapper.like("deviceid", searchContent.trim()); + break; + case "iccid": + queryWrapper.like("iccid", searchContent.trim()); + break; + case "simNumber": + TrafficCard cardByMsisdn = trafficCardMapper.selectOne( + new QueryWrapper().like("msisdn", searchContent.trim()) + ); + if (cardByMsisdn != null) { + queryWrapper.eq("iccid", cardByMsisdn.getIccid()); + } else { + queryWrapper.eq("iccid", ""); + } + break; + } + } + + queryWrapper.orderByDesc("start_time"); + IPage mappings = trafficDeviceMappingMapper.selectPage(pageable, queryWrapper); + + List> enrichedData = new ArrayList<>(); + for (TrafficDeviceMapping mapping : mappings.getRecords()) { + Map mappingData = new HashMap<>(); + mappingData.put("id", mapping.getId()); + mappingData.put("deviceId", mapping.getDeviceid()); + mappingData.put("iccid", mapping.getIccid()); + mappingData.put("startTime", mapping.getStartTime()); + mappingData.put("endTime", mapping.getEndTime()); + + mappingData.put("isActive", mapping.getEndTime() == null); + + // 查找对应的流量卡信息 + TrafficCard trafficCard = trafficCardMapper.findByIccid(mapping.getIccid()); + if (trafficCard != null) { + mappingData.put("msisdn", trafficCard.getMsisdn()); + } else { + mappingData.put("msisdn", "-"); + } + + enrichedData.add(mappingData); + } + + JSONObject jsonObject = new JSONObject(); + jsonObject.put("code", 0); + jsonObject.put("msg", ""); + jsonObject.put("count", mappings.getTotal()); + jsonObject.put("data", enrichedData); + return jsonObject; + + } catch (Exception e) { + JSONObject errorResponse = new JSONObject(); + errorResponse.put("code", 1); + errorResponse.put("msg", "查询失败: " + e.getMessage()); + errorResponse.put("count", 0); + errorResponse.put("data", new ArrayList<>()); + return errorResponse; + } + } + private String calculateSignature(Map params) { try { List paramList = new ArrayList<>(); diff --git a/sec-beidou/src/main/resources/static/api/init_super_admin.json b/sec-beidou/src/main/resources/static/api/init_super_admin.json index c50fc81f..e2d06ffb 100644 --- a/sec-beidou/src/main/resources/static/api/init_super_admin.json +++ b/sec-beidou/src/main/resources/static/api/init_super_admin.json @@ -130,7 +130,19 @@ "target": "_self" }, { - "title": "卡信息查询", + "title": "流量使用记录", + "href": "page/sim_traffic_records", + "icon": "fa fa-minus", + "target": "_self" + }, + { + "title": "设备映射记录", + "href": "page/sim_device_mapping", + "icon": "fa fa-minus", + "target": "_self" + }, + { + "title": "卡信息聚合查询", "href": "page/sim_traffic_query", "icon": "fa fa-minus", "target": "_self" diff --git a/sec-beidou/src/main/resources/templates/page/sim_device_mapping.html b/sec-beidou/src/main/resources/templates/page/sim_device_mapping.html new file mode 100644 index 00000000..bdaae8a8 --- /dev/null +++ b/sec-beidou/src/main/resources/templates/page/sim_device_mapping.html @@ -0,0 +1,164 @@ + + + + + 设备SIM卡映射记录 + + + + + + + +
+
+
+ 搜索信息 +
+
+
+
+ +
+ +
+
+
+ +
+ +
+
+
+
+
+ +
+
+
+
+
+
+
    +
  • 设备映射记录
  • +
+
+
+
+
+
+
+
+
+ + + + + + + \ No newline at end of file diff --git a/sec-beidou/src/main/resources/templates/page/sim_status.html b/sec-beidou/src/main/resources/templates/page/sim_status.html index 7e1950fe..d186eb16 100644 --- a/sec-beidou/src/main/resources/templates/page/sim_status.html +++ b/sec-beidou/src/main/resources/templates/page/sim_status.html @@ -110,9 +110,9 @@ function updateFlowChart(simData) { initEcharts(); - var used = parseFloat(simData.used) || 0; - var remaining = parseFloat(simData.remaining) || 0; - var total = parseFloat(simData.total) || (used + remaining); + var used = simData.used ? (simData.used / 1000) : 0; + var remaining = simData.remaining ? (simData.remaining / 1000) : 0; + var total = simData.total ? (simData.total / 1000) : (used + remaining); var option = { title: { @@ -191,11 +191,17 @@ {field: 'deviceid', title: '设备号'}, {field: 'iccid', title: 'ICCID'}, {field: 'msisdn', title: 'SIM 卡号'}, - {field: 'updatetime', title: '更新时间',templet: "
{{layui.util.toDateString(d.updatetime, 'yyyy-MM-dd HH:mm:ss')}}
"}, + {field: 'updateTime', title: '更新时间',templet: "
{{layui.util.toDateString(d.updateTime, 'yyyy-MM-dd HH:mm:ss')}}
"}, {field: 'status', title: '状态',templet: '#statusTpl'}, - {field: 'remaining', title: '剩余流量(MB)'}, - {field: 'used', title: '已使用流量(MB)'}, - {field: 'total', title: '总流量(MB)'} + {field: 'remaining', title: '剩余流量(MB)', templet: function(d) { + return d.remaining ? (d.remaining / 1000).toFixed(2) : '0'; + }}, + {field: 'used', title: '已使用流量(MB)', templet: function(d) { + return d.used ? (d.used / 1000).toFixed(2) : '0'; + }}, + {field: 'total', title: '总流量(MB)', templet: function(d) { + return d.total ? (d.total / 1000).toFixed(2) : '0'; + }} ]; diff --git a/sec-beidou/src/main/resources/templates/page/sim_traffic_records.html b/sec-beidou/src/main/resources/templates/page/sim_traffic_records.html new file mode 100644 index 00000000..34868e7c --- /dev/null +++ b/sec-beidou/src/main/resources/templates/page/sim_traffic_records.html @@ -0,0 +1,140 @@ + + + + + SIM卡流量使用记录 + + + + + + + +
+
+
+ 搜索信息 +
+
+
+
+ +
+ +
+
+
+ +
+ +
+
+
+
+
+ +
+
+
+
+
+
+
    +
  • 流量使用记录
  • +
+
+
+
+
+
+
+
+
+ + + + + \ No newline at end of file