From a007b35d18f039f02506788fa2eed5738b1f0383 Mon Sep 17 00:00:00 2001 From: fengyarnom Date: Wed, 4 Jun 2025 11:49:15 +0800 Subject: [PATCH] =?UTF-8?q?feat=EF=BC=9A=E6=B7=BB=E5=8A=A0=E5=AF=BC?= =?UTF-8?q?=E5=87=BA=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/imdroid/secapi/dto/TrafficRecord.java | 19 +++ .../beidou/controller/SimCardController.java | 117 +++++++++++++++++- .../templates/page/sim_traffic_records.html | 8 ++ 3 files changed, 143 insertions(+), 1 deletion(-) diff --git a/sec-api/src/main/java/com/imdroid/secapi/dto/TrafficRecord.java b/sec-api/src/main/java/com/imdroid/secapi/dto/TrafficRecord.java index 5d023db0..49f748d4 100644 --- a/sec-api/src/main/java/com/imdroid/secapi/dto/TrafficRecord.java +++ b/sec-api/src/main/java/com/imdroid/secapi/dto/TrafficRecord.java @@ -1,5 +1,7 @@ package com.imdroid.secapi.dto; +import com.alibaba.excel.annotation.ExcelIgnore; +import com.alibaba.excel.annotation.ExcelProperty; import com.baomidou.mybatisplus.annotation.IdType; import com.baomidou.mybatisplus.annotation.TableField; import com.baomidou.mybatisplus.annotation.TableId; @@ -13,13 +15,30 @@ import java.util.Date; public class TrafficRecord { @TableId(type = IdType.AUTO) + @ExcelIgnore private Integer id; + @ExcelProperty("ICCID") private String iccid; + @ExcelProperty("记录时间") private Date recordtime; + @ExcelProperty("剩余流量(MB)") private Integer remaining; // 剩余流量(MB×1000) + + @ExcelProperty("已用流量(MB)") private Integer used; // 已用流量(MB×1000) + + @ExcelProperty("总流量(MB)") private Integer total; // 总流量(MB×1000) + + // Excel 导出用,不是数据库的字段!!! + @TableField(exist = false) + @ExcelProperty("设备号") + private String deviceid; + + @TableField(exist = false) + @ExcelProperty("SIM卡号") + private String msisdn; } \ No newline at end of file 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 e09e45da..0a093ae5 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 @@ -2,8 +2,10 @@ package com.imdroid.beidou.controller; import com.alibaba.fastjson.JSONObject; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; +import com.baomidou.mybatisplus.core.mapper.BaseMapper; import com.baomidou.mybatisplus.core.metadata.IPage; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; +import com.imdroid.beidou.service.CommonExcelService; import com.imdroid.secapi.dto.*; import org.apache.http.HttpEntity; import org.apache.http.util.EntityUtils; @@ -20,12 +22,14 @@ import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.ResponseBody; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpSession; import java.security.MessageDigest; import java.util.*; @Controller -public class SimCardController extends BasicController { +public class SimCardController extends BasicController implements CommonExcelService { @Value("${sim.url}") private String BASE_URL; @Value("${sim.username}") @@ -355,6 +359,93 @@ public class SimCardController extends BasicController { } } + @RequestMapping("/sim/traffic-records/export") + @ResponseBody + public void exportTrafficRecords(HttpSession session, HttpServletRequest request, HttpServletResponse response) throws Exception { + QueryWrapper queryWrapper = new QueryWrapper<>(); + + String searchType = request.getParameter("searchType"); + String searchContent = request.getParameter("searchContent"); + String startTime = request.getParameter("startTime"); + String endTime = request.getParameter("endTime"); + + 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; + } + } + + if (!StringUtils.isEmpty(startTime)) { + queryWrapper.ge("recordtime", startTime); + } + if (!StringUtils.isEmpty(endTime)) { + queryWrapper.le("recordtime", endTime); + } + + queryWrapper.orderByDesc("recordtime"); + + List records = trafficRecordMapper.selectList(queryWrapper); + + // 填充导出所需的额外字段 + for (TrafficRecord record : records) { + GnssDevice device = gnssDeviceMapper.selectOne( + new QueryWrapper().eq("iccid", record.getIccid()) + ); + if (device != null) { + record.setDeviceid(device.getDeviceid()); + } else { + record.setDeviceid("无绑定设备"); + } + + TrafficCard trafficCard = trafficCardMapper.findByIccid(record.getIccid()); + if (trafficCard != null) { + record.setMsisdn(trafficCard.getMsisdn()); + } else { + record.setMsisdn("-"); + } + + // 转换流量单位为MB (除以1000) + if (record.getRemaining() != null) { + record.setRemaining(record.getRemaining() / 1000); + } + if (record.getUsed() != null) { + record.setUsed(record.getUsed() / 1000); + } + if (record.getTotal() != null) { + record.setTotal(record.getTotal() / 1000); + } + } + + response.setContentType("application/vnd.ms-excel"); + response.setCharacterEncoding("utf-8"); + String filename = System.currentTimeMillis() + "_流量使用记录.xlsx"; + response.setHeader("Content-disposition", "attachment;filename=" + filename); + + com.alibaba.excel.EasyExcel.write(response.getOutputStream(), TrafficRecord.class) + .sheet("流量使用记录") + .doWrite(records); + } + @RequestMapping("/sim/device-mapping") @ResponseBody public JSONObject getDeviceMapping(HttpSession session, @@ -454,6 +545,30 @@ public class SimCardController extends BasicController { } } + @Override + public Class getEntityClass() { + return TrafficRecord.class; + } + + @Override + public BaseMapper getMapper() { + return trafficRecordMapper; + } + + @Override + public String getOrderByColumn() { + return "recordtime"; + } + + @Override + public String getOrder() { + return "desc"; + } + + @Override + public String tenantIdField() { + return null; // TrafficRecord表没有租户字段 + } } 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 index 25d2d386..8ea8286c 100644 --- a/sec-beidou/src/main/resources/templates/page/sim_traffic_records.html +++ b/sec-beidou/src/main/resources/templates/page/sim_traffic_records.html @@ -48,6 +48,7 @@
+
@@ -157,6 +158,13 @@ }); return false; }); + + form.on('submit(exportSubmit)', function (data) { + var result = $('#searchForm').serialize(); + var u = "/sim/traffic-records/export?" + result; + window.open(u, "_blank"); + return false; + }); });