Commit d74fd8be by 向延琳

增加最大限制

1 parent 07d49356
......@@ -131,4 +131,9 @@ public final class Constants {
* 包活干返回成功码
*/
public static final int BHG_RET_CODE_SUCCESS = 200;
/**
* 导出最大限制
*/
public static final int MAX_EXPORT_LIMIT = 10000;
}
package cn.com.glsx.admin.modules.controller;
import cn.com.glsx.admin.common.constants.Constants;
import cn.com.glsx.admin.common.exception.AdminException;
import cn.com.glsx.admin.modules.model.export.JourneyDetailExport;
import cn.com.glsx.admin.modules.model.export.JourneyExport;
import cn.com.glsx.admin.modules.model.param.JourneyDailySearch;
......@@ -48,8 +50,6 @@ public class JourneyController {
/**
* 查询通用里程列表
*
* @param journeySearch
* @return
*/
@GetMapping("/search")
@ApiOperation(value = "查询通用里程列表")
......@@ -62,18 +62,30 @@ public class JourneyController {
/**
* 导出通用里程报表
*
* @param journeySearch
* @return
*/
@GetMapping("/export")
@ApiOperation(value = "导出通用里程报表")
public R<String> exportJourneyList(JourneySearch journeySearch) {
// 限制
long t1 = System.currentTimeMillis();
Integer total = journeyService.countJourneyList(journeySearch);
if (total > Constants.MAX_EXPORT_LIMIT) {
throw new AdminException("数据过大不能导出,请筛选数据,控制在 1万 条以下; 当前数据量" + total + " 条");
}
log.info("导出数量{}", total);
String fileName = FdfsUtils.getFileName("通用里程报表");
List<JourneyExport> journeyList = journeyService.findJourneyList(journeySearch);
long t2 = System.currentTimeMillis();
log.info("数据查询耗时{}", t2 -t1);
// 将文件写入内存流 然后上传到文件服务器 返回文件服务器的地址给前端 前端执行下载
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
EasyExcelUtils.writeExcel(outputStream, journeyList, fileName, JourneyExport.class);
FileUploadServerData uploadServerData = FileUploadUtil.uploadToFileSystem(fileName, outputStream.toByteArray(), FileConstants.EXCEL_TYPE_XLSX);
long t3 = System.currentTimeMillis();
log.info("上传uploadToFileSystem耗时{}", t3 -t2);
log.info("总耗时{}", t3 -t1);
return R.ok().data(uploadServerData.getSecureUrl());
}
......@@ -102,6 +114,12 @@ public class JourneyController {
@ApiOperation(value = "导出通用里程详情报表")
public R<String> exportJourneyDetailList(JourneyDetailSearch journeyDetailSearch) {
checkQueryParams(journeyDetailSearch);
//限制
Integer total = journeyService.countJourneyDetailList(journeyDetailSearch);
if (total > Constants.MAX_EXPORT_LIMIT) {
throw new AdminException("数据过大不能导出,请筛选数据,控制在 1万 条以下; 当前数据量" + total + " 条");
}
log.info("导出数量{}", total);
String fileName = FdfsUtils.getFileName("单设备里程报表");
List<JourneyDetailExport> journeyList = journeyService.findJourneyDetailList(journeyDetailSearch);
// 将文件写入内存流 然后上传到文件服务器 返回文件服务器的地址给前端 前端执行下载
......
......@@ -177,6 +177,15 @@ public interface VehicleMapper extends CommonBaseMapper<Vehicle> {
List<JourneyExport> findJourneyList(JourneySearch journeySearch);
/**
* 根据权限获取该账户下 所有设备里程基础信息集合数量
* @param journeySearch 查询条件
* @return 数量
*/
@DataPerm(showSql = true)
@DataPermShare(showSql = true)
Integer countJourneyList(JourneySearch journeySearch);
/**
* 根据权限获取该账户下 所有设备离线信息集合
*
* @param offlineSearch
......@@ -206,6 +215,14 @@ public interface VehicleMapper extends CommonBaseMapper<Vehicle> {
List<JourneyDetailExport> findJourneyDetailList(JourneyDetailSearch journeyDetailSearch);
/**
* 根据权限获取该账户下 获取所有设备数据详细里程基本信息 数量
* @param journeyDetailSearch 查询条件
* @return 数量
*/
@DataPerm(showSql = true)
Integer countJourneyDetailList(JourneyDetailSearch journeyDetailSearch);
/**
* 根据权限获取该账户下 获取设备激活数据
*
* @param appendSql 拼接SQl
......
......@@ -68,6 +68,17 @@ public class JourneyService {
}
/**
* 统计列表数量
*/
public Integer countJourneyList(JourneySearch search) {
if (search.getOrgId() != null) {
search.setCheckedOrgIds(Lists.newArrayList(search.getOrgId()));
userApiService.setCheckedOrgUsers(search);
}
return vehicleMapper.countJourneyList(search);
}
/**
* 里程单位转换
*/
private JourneyExport convertKm(JourneyExport journey) {
......@@ -111,17 +122,23 @@ public class JourneyService {
* @return
*/
public List<JourneyDetailExport> findJourneyDetailList(JourneyDetailSearch journeyDetailSearch) {
// List<JourneyDetailExport> journeyDetailList = Lists.newArrayList();
if (journeyDetailSearch.getOrgId() != null) {
journeyDetailSearch.setCheckedOrgIds(Lists.newArrayList(journeyDetailSearch.getOrgId()));
userApiService.setCheckedOrgUsers(journeyDetailSearch);
}
List<JourneyDetailExport> journeyDetailExportList = vehicleMapper.findJourneyDetailList(journeyDetailSearch);
log.info("journeyDetailExportList size()大小===" + journeyDetailExportList.size());
//getDeviceDetailMileage(journeyDetailList, journeyDetailExportList, journeyDetailSearch);
return journeyDetailExportList;
}
public Integer countJourneyDetailList(JourneyDetailSearch journeyDetailSearch) {
if (journeyDetailSearch.getOrgId() != null) {
journeyDetailSearch.setCheckedOrgIds(Lists.newArrayList(journeyDetailSearch.getOrgId()));
userApiService.setCheckedOrgUsers(journeyDetailSearch);
}
return vehicleMapper.countJourneyDetailList(journeyDetailSearch);
}
private void getDeviceDetailMileage(List<JourneyDetailExport> dataList, List<JourneyDetailExport> journeyDetailList, JourneyDetailSearch journeyDetailSearch) {
log.info("###get device detail mileage start###");
if (CollectionUtils.isEmpty(journeyDetailList)) {
......@@ -161,7 +178,6 @@ public class JourneyService {
oneData.add(journeyDailyExport.getSn());
oneData.add(journeyDailyExport.getVin());
Map<String, DeviceJourneyDailyDTO> journeyDailyMap = dailyJourneyRecordsMap.get(journeyDailyExport.getSn());
//remoteMileageTotalService.getDailyJourneyRecords(journeyDailyExport.getSn(), search.getJourneyStartTime(), search.getJourneyEndTime());
// 按照日期顺序封装每天的数据
for (String dateTime : collectDateList) {
if (journeyDailyMap == null || journeyDailyMap.isEmpty() || Objects.isNull(journeyDailyMap.get(dateTime))) {
......
......@@ -804,6 +804,31 @@
order by tvd.id desc
</select>
<select id="countJourneyList" resultType="java.lang.Integer">
select count(1)
from t_vehicle tv
left join t_vehicle_device tvd on tvd.vehicle_id = tv.id
left join t_device_journey_overview tdjo on tvd.id = tdjo.vd_id
left join t_device td on td.sn = tvd.sn
left join t_workorder tw on tw.id = tv.workorder_id and tw.del_flag = 0
where tv.del_flag = 0
and tvd.bind_status = 1
and tvd.del_flag = 0
and td.source = 1
<if test="checkedUserIdsStr != null and checkedUserIdsStr !=''">
and find_in_set(tv.created_by,#{checkedUserIdsStr})
</if>
<if test="keywords != null and keywords !=''">
and(
tw.partner_order_no like '%${keywords}%'
or tv.vin like '%${keywords}%'
or tv.owner_name like '%${keywords}%'
or tvd.sn like '%${keywords}%'
)
</if>
order by tvd.id desc
</select>
<select id="findOfflineList" resultType="cn.com.glsx.admin.modules.model.export.OfflineExport">
select tvd.id, tw.partner_order_no as workOrderNo,
tv.owner_name as ownerName,
......@@ -912,6 +937,25 @@
order by tvd.id desc
</select>
<select id="countJourneyDetailList" resultType="java.lang.Integer">
select count(1)
left join t_vehicle_device tvd on tvd.id = tdj.vd_id
left join t_vehicle tv on tvd.id = tvd.vehicle_id
left join t_device td on td.sn = tvd.sn
left join t_workorder tw on tw.id = tv.workorder_id and tw.del_flag = 0
where tv.del_flag = 0
and tvd.bind_status = 1
and tvd.del_flag = 0
and td.source = 1
<if test="checkedUserIdsStr != null and checkedUserIdsStr !=''">
and find_in_set(tv.created_by,#{checkedUserIdsStr})
</if>
<if test="sn != null and sn !=''">
and tvd.sn = #{sn}
</if>
order by tvd.id desc
</select>
<select id="getActiveDeviceInfoWithAuth" resultType="cn.com.glsx.admin.modules.model.ActiveDeviceVo">
SELECT count(temp.id) AS activeNumber,
<choose>
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!