|
@@ -3,7 +3,10 @@ package com.ebei.screen.service.impl;
|
|
|
import cn.hutool.core.collection.CollUtil;
|
|
|
import cn.hutool.core.date.DatePattern;
|
|
|
import cn.hutool.core.date.LocalDateTimeUtil;
|
|
|
+import cn.hutool.core.io.FileUtil;
|
|
|
+import cn.hutool.core.io.resource.ResourceUtil;
|
|
|
import cn.hutool.core.map.MapUtil;
|
|
|
+import com.alibaba.excel.EasyExcel;
|
|
|
import com.alibaba.fastjson.JSON;
|
|
|
import com.alibaba.fastjson.JSONArray;
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
@@ -11,6 +14,7 @@ import com.ebei.screen.common.constants.CommonConstants;
|
|
|
import com.ebei.screen.common.constants.ParkExceptionType;
|
|
|
import com.ebei.screen.common.constants.ParkType;
|
|
|
import com.ebei.screen.common.constants.PayTypeCode;
|
|
|
+import com.ebei.screen.common.exception.MyException;
|
|
|
import com.ebei.screen.common.response.PageBean;
|
|
|
import com.ebei.screen.common.response.ResponseBean;
|
|
|
import com.ebei.screen.common.response.ResponseBuilder;
|
|
@@ -27,6 +31,10 @@ import org.springframework.data.mongodb.core.query.Update;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
|
|
|
+import javax.servlet.http.HttpServletResponse;
|
|
|
+import java.io.ByteArrayOutputStream;
|
|
|
+import java.io.File;
|
|
|
+import java.io.InputStream;
|
|
|
import java.time.Duration;
|
|
|
import java.time.Instant;
|
|
|
import java.time.LocalDateTime;
|
|
@@ -847,6 +855,63 @@ public class ParkSystemServiceImpl implements ParkSystemService {
|
|
|
return ResponseBuilder.ok("修复车场完成", list);
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 异常信息导出
|
|
|
+ *
|
|
|
+ * @param params
|
|
|
+ * @param response
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public void exportException(ExceptionTrendReq params, HttpServletResponse response) {
|
|
|
+ String parkCode = params.getParkCode();
|
|
|
+ String paramsCode = params.getCode();
|
|
|
+ String date = params.getDate();
|
|
|
+ List<String> parkCodeList = Arrays.asList(parkCode);
|
|
|
+ if (StringUtils.isBlank(parkCode)) {
|
|
|
+ parkCodeList = ParkUtils.getParkCodeList();
|
|
|
+ }
|
|
|
+ if (!ParkExceptionType.codeList().contains(paramsCode)) {
|
|
|
+ throw new MyException("异常编号错误");
|
|
|
+ }
|
|
|
+ String format = StringUtils.isNotBlank(date) ? date.replace("-", "") : LocalDateTimeUtil.format(LocalDateTime.now(), DatePattern.PURE_DATE_PATTERN);
|
|
|
+ CountDownLatch countDownLatch = new CountDownLatch(parkCodeList.size());
|
|
|
+ List<ByteArrayOutputStream> streams = new ArrayList<>();
|
|
|
+ List<String> excelNames = new ArrayList<>();
|
|
|
+ parkCodeList.forEach(code -> RunnableUtils.start(() -> {
|
|
|
+ try {
|
|
|
+ JSONObject obj = mongoTemplate.findById(code + "_" + format, JSONObject.class, ParkType.EXCEPTION.getCode());
|
|
|
+ if (obj == null) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ String fileName = ParkUtils.getParkNameByCode(code) + ".xlsx";
|
|
|
+ JSONObject data = obj != null ? obj.getJSONObject("data") : new JSONObject();
|
|
|
+ JSONArray dataList = data != null ? data.getJSONArray(paramsCode) : new JSONArray();
|
|
|
+ List<Map> objects = dataList != null ? dataList.toJavaList(Map.class) : new ArrayList<>();
|
|
|
+ List<Map> maps = ParkUtils.sortDateList(objects, ParkType.EXCEPTION.getSort(), true);
|
|
|
+ if (CollUtil.isNotEmpty(maps)) {
|
|
|
+ maps.forEach(x -> x.put("photoUrl", ParkUtils.getExcelPhotoUrl(x.get("imageUrl") == null ? (x.get("outCarPhoto") == null ? x.get("inCarPhoto") : x.get("outCarPhoto")) : x.get("imageUrl"))));
|
|
|
+ }
|
|
|
+ InputStream inputStream = ResourceUtil.getStream("temp/exception.xlsx");
|
|
|
+ File ex = File.createTempFile("exception", ".xlsx");
|
|
|
+ FileUtil.writeFromStream(inputStream, ex);
|
|
|
+ ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
|
|
|
+ EasyExcel.write(outputStream).withTemplate(ex).sheet("异常信息").doFill(maps);
|
|
|
+ excelNames.add(fileName);
|
|
|
+ streams.add(outputStream);
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.info("异常信息报表导出出现异常:{}", e);
|
|
|
+ } finally {
|
|
|
+ countDownLatch.countDown();
|
|
|
+ }
|
|
|
+ }));
|
|
|
+ try {
|
|
|
+ countDownLatch.await();
|
|
|
+ LeviUtils.zipOutput(response, streams, excelNames, "异常信息导出");
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.info("异常信息压缩zip异常:{}", e);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* 不同收费方式停车统计
|
|
|
*
|