feature/simcards_checker #6
@ -1,7 +1,5 @@
|
||||
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;
|
||||
@ -15,30 +13,13 @@ 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,10 +2,8 @@ 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;
|
||||
@ -22,14 +20,12 @@ 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 implements CommonExcelService<TrafficRecord, TrafficRecord> {
|
||||
public class SimCardController extends BasicController {
|
||||
@Value("${sim.url}")
|
||||
private String BASE_URL;
|
||||
@Value("${sim.username}")
|
||||
@ -359,93 +355,6 @@ public class SimCardController extends BasicController implements CommonExcelSer
|
||||
}
|
||||
}
|
||||
|
||||
@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,
|
||||
@ -545,30 +454,6 @@ public class SimCardController extends BasicController implements CommonExcelSer
|
||||
}
|
||||
}
|
||||
|
||||
@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表没有租户字段
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
@ -48,7 +48,6 @@
|
||||
<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>
|
||||
@ -158,13 +157,6 @@
|
||||
});
|
||||
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