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 54ed874c..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}") @@ -266,7 +270,9 @@ public class SimCardController extends BasicController { int page, int limit, String searchType, - String searchContent) { + String searchContent, + String startTime, + String endTime) { try { Page pageable = new Page<>(page, limit); QueryWrapper queryWrapper = new QueryWrapper<>(); @@ -297,6 +303,13 @@ public class SimCardController extends BasicController { } } + if (!StringUtils.isEmpty(startTime)) { + queryWrapper.ge("recordtime", startTime); + } + if (!StringUtils.isEmpty(endTime)) { + queryWrapper.le("recordtime", endTime); + } + queryWrapper.orderByDesc("recordtime"); IPage records = trafficRecordMapper.selectPage(pageable, queryWrapper); @@ -346,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, @@ -445,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 34868e7c..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 @@ -34,9 +34,21 @@ +
+
+ +
+ +
+
+ +
+
+
+
@@ -57,11 +69,12 @@