feature/simcards_checker #4
@ -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;
|
||||
}
|
||||
@ -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<TrafficRecord, TrafficRecord> {
|
||||
@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<TrafficRecord> pageable = new Page<>(page, limit);
|
||||
QueryWrapper<TrafficRecord> 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<TrafficRecord> 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<TrafficRecord> 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<TrafficCard>().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<TrafficRecord> records = trafficRecordMapper.selectList(queryWrapper);
|
||||
|
||||
// 填充导出所需的额外字段
|
||||
for (TrafficRecord record : records) {
|
||||
GnssDevice device = gnssDeviceMapper.selectOne(
|
||||
new QueryWrapper<GnssDevice>().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<TrafficRecord> getEntityClass() {
|
||||
return TrafficRecord.class;
|
||||
}
|
||||
|
||||
@Override
|
||||
public BaseMapper<TrafficRecord> getMapper() {
|
||||
return trafficRecordMapper;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getOrderByColumn() {
|
||||
return "recordtime";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getOrder() {
|
||||
return "desc";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String tenantIdField() {
|
||||
return null; // TrafficRecord表没有租户字段
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
@ -34,9 +34,21 @@
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="layui-form-item">
|
||||
<div class="layui-inline">
|
||||
<label class="layui-form-label">时间范围</label>
|
||||
<div class="layui-input-inline">
|
||||
<input type="text" name="startTime" autocomplete="off" id="ID-laydate-start-date" class="layui-input" placeholder="开始日期">
|
||||
</div>
|
||||
<div class="layui-input-inline">
|
||||
<input type="text" name="endTime" autocomplete="off" id="ID-laydate-end-date" class="layui-input" placeholder="结束日期">
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="layui-form-item">
|
||||
<div class="layui-inline">
|
||||
<button type="submit" class="layui-btn layui-btn-primary" lay-submit lay-filter="searchSubmit"><i class="layui-icon"></i> 搜 索</button>
|
||||
<button type="submit" class="layui-btn layui-btn-primary" lay-submit lay-filter="exportSubmit"><i class="layui-icon"></i> 导 出</button>
|
||||
</div>
|
||||
</div>
|
||||
</form>
|
||||
@ -57,11 +69,12 @@
|
||||
|
||||
<script src="../lib/layui-v2.6.3/layui.js" charset="utf-8"></script>
|
||||
<script th:inline="javascript">
|
||||
layui.use(['form', 'table','layer','element'], function () {
|
||||
layui.use(['form', 'table','layer','element','laydate'], function () {
|
||||
var table = layui.table
|
||||
,form = layui.form
|
||||
,layer = layui.layer
|
||||
,element = layui.element;
|
||||
,element = layui.element
|
||||
,laydate = layui.laydate;
|
||||
|
||||
var data_cols = [
|
||||
{field: 'deviceid', title: '设备号'},
|
||||
@ -80,6 +93,15 @@
|
||||
];
|
||||
|
||||
form.render();
|
||||
laydate.render({
|
||||
elem: '#ID-laydate-start-date',
|
||||
type: 'datetime'
|
||||
});
|
||||
laydate.render({
|
||||
elem: '#ID-laydate-end-date',
|
||||
type: 'datetime'
|
||||
});
|
||||
|
||||
table.render({
|
||||
elem: '#trafficRecordsTable',
|
||||
url: '/sim/traffic-records',
|
||||
@ -121,7 +143,9 @@
|
||||
}
|
||||
,where: {
|
||||
searchType: data.field.searchType,
|
||||
searchContent: data.field.searchContent
|
||||
searchContent: data.field.searchContent,
|
||||
startTime: data.field.startTime,
|
||||
endTime: data.field.endTime
|
||||
}
|
||||
,done: function(res) {
|
||||
layer.close(loadIndex);
|
||||
@ -134,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;
|
||||
});
|
||||
});
|
||||
</script>
|
||||
</body>
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user