Merge pull request 'feature/simcards_checker' (#4) from feature/simcards_checker into develop
Reviewed-on: #4
This commit is contained in:
commit
9f6cd91639
@ -1,5 +1,7 @@
|
|||||||
package com.imdroid.secapi.dto;
|
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.IdType;
|
||||||
import com.baomidou.mybatisplus.annotation.TableField;
|
import com.baomidou.mybatisplus.annotation.TableField;
|
||||||
import com.baomidou.mybatisplus.annotation.TableId;
|
import com.baomidou.mybatisplus.annotation.TableId;
|
||||||
@ -13,13 +15,30 @@ import java.util.Date;
|
|||||||
public class TrafficRecord {
|
public class TrafficRecord {
|
||||||
|
|
||||||
@TableId(type = IdType.AUTO)
|
@TableId(type = IdType.AUTO)
|
||||||
|
@ExcelIgnore
|
||||||
private Integer id;
|
private Integer id;
|
||||||
|
|
||||||
|
@ExcelProperty("ICCID")
|
||||||
private String iccid;
|
private String iccid;
|
||||||
|
|
||||||
|
@ExcelProperty("记录时间")
|
||||||
private Date recordtime;
|
private Date recordtime;
|
||||||
|
|
||||||
|
@ExcelProperty("剩余流量(MB)")
|
||||||
private Integer remaining; // 剩余流量(MB×1000)
|
private Integer remaining; // 剩余流量(MB×1000)
|
||||||
|
|
||||||
|
@ExcelProperty("已用流量(MB)")
|
||||||
private Integer used; // 已用流量(MB×1000)
|
private Integer used; // 已用流量(MB×1000)
|
||||||
|
|
||||||
|
@ExcelProperty("总流量(MB)")
|
||||||
private Integer total; // 总流量(MB×1000)
|
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.alibaba.fastjson.JSONObject;
|
||||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
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.core.metadata.IPage;
|
||||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||||
|
import com.imdroid.beidou.service.CommonExcelService;
|
||||||
import com.imdroid.secapi.dto.*;
|
import com.imdroid.secapi.dto.*;
|
||||||
import org.apache.http.HttpEntity;
|
import org.apache.http.HttpEntity;
|
||||||
import org.apache.http.util.EntityUtils;
|
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.RequestParam;
|
||||||
import org.springframework.web.bind.annotation.ResponseBody;
|
import org.springframework.web.bind.annotation.ResponseBody;
|
||||||
|
|
||||||
|
import javax.servlet.http.HttpServletRequest;
|
||||||
|
import javax.servlet.http.HttpServletResponse;
|
||||||
import javax.servlet.http.HttpSession;
|
import javax.servlet.http.HttpSession;
|
||||||
import java.security.MessageDigest;
|
import java.security.MessageDigest;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
|
|
||||||
@Controller
|
@Controller
|
||||||
public class SimCardController extends BasicController {
|
public class SimCardController extends BasicController implements CommonExcelService<TrafficRecord, TrafficRecord> {
|
||||||
@Value("${sim.url}")
|
@Value("${sim.url}")
|
||||||
private String BASE_URL;
|
private String BASE_URL;
|
||||||
@Value("${sim.username}")
|
@Value("${sim.username}")
|
||||||
@ -266,7 +270,9 @@ public class SimCardController extends BasicController {
|
|||||||
int page,
|
int page,
|
||||||
int limit,
|
int limit,
|
||||||
String searchType,
|
String searchType,
|
||||||
String searchContent) {
|
String searchContent,
|
||||||
|
String startTime,
|
||||||
|
String endTime) {
|
||||||
try {
|
try {
|
||||||
Page<TrafficRecord> pageable = new Page<>(page, limit);
|
Page<TrafficRecord> pageable = new Page<>(page, limit);
|
||||||
QueryWrapper<TrafficRecord> queryWrapper = new QueryWrapper<>();
|
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");
|
queryWrapper.orderByDesc("recordtime");
|
||||||
IPage<TrafficRecord> records = trafficRecordMapper.selectPage(pageable, queryWrapper);
|
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")
|
@RequestMapping("/sim/device-mapping")
|
||||||
@ResponseBody
|
@ResponseBody
|
||||||
public JSONObject getDeviceMapping(HttpSession session,
|
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>
|
||||||
</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-form-item">
|
||||||
<div class="layui-inline">
|
<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="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>
|
||||||
</div>
|
</div>
|
||||||
</form>
|
</form>
|
||||||
@ -57,11 +69,12 @@
|
|||||||
|
|
||||||
<script src="../lib/layui-v2.6.3/layui.js" charset="utf-8"></script>
|
<script src="../lib/layui-v2.6.3/layui.js" charset="utf-8"></script>
|
||||||
<script th:inline="javascript">
|
<script th:inline="javascript">
|
||||||
layui.use(['form', 'table','layer','element'], function () {
|
layui.use(['form', 'table','layer','element','laydate'], function () {
|
||||||
var table = layui.table
|
var table = layui.table
|
||||||
,form = layui.form
|
,form = layui.form
|
||||||
,layer = layui.layer
|
,layer = layui.layer
|
||||||
,element = layui.element;
|
,element = layui.element
|
||||||
|
,laydate = layui.laydate;
|
||||||
|
|
||||||
var data_cols = [
|
var data_cols = [
|
||||||
{field: 'deviceid', title: '设备号'},
|
{field: 'deviceid', title: '设备号'},
|
||||||
@ -80,6 +93,15 @@
|
|||||||
];
|
];
|
||||||
|
|
||||||
form.render();
|
form.render();
|
||||||
|
laydate.render({
|
||||||
|
elem: '#ID-laydate-start-date',
|
||||||
|
type: 'datetime'
|
||||||
|
});
|
||||||
|
laydate.render({
|
||||||
|
elem: '#ID-laydate-end-date',
|
||||||
|
type: 'datetime'
|
||||||
|
});
|
||||||
|
|
||||||
table.render({
|
table.render({
|
||||||
elem: '#trafficRecordsTable',
|
elem: '#trafficRecordsTable',
|
||||||
url: '/sim/traffic-records',
|
url: '/sim/traffic-records',
|
||||||
@ -121,7 +143,9 @@
|
|||||||
}
|
}
|
||||||
,where: {
|
,where: {
|
||||||
searchType: data.field.searchType,
|
searchType: data.field.searchType,
|
||||||
searchContent: data.field.searchContent
|
searchContent: data.field.searchContent,
|
||||||
|
startTime: data.field.startTime,
|
||||||
|
endTime: data.field.endTime
|
||||||
}
|
}
|
||||||
,done: function(res) {
|
,done: function(res) {
|
||||||
layer.close(loadIndex);
|
layer.close(loadIndex);
|
||||||
@ -134,6 +158,13 @@
|
|||||||
});
|
});
|
||||||
return false;
|
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>
|
</script>
|
||||||
</body>
|
</body>
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user