Levi преди 3 години
родител
ревизия
acaa8b892e

+ 6 - 0
pom.xml

@@ -19,6 +19,7 @@
         <knife4j.version>3.0.2</knife4j.version>
         <fastjson.version>1.2.75</fastjson.version>
         <hutool-all.version>5.4.7</hutool-all.version>
+        <easyexcel.version>2.2.6</easyexcel.version>
     </properties>
 
     <dependencies>
@@ -78,6 +79,11 @@
             <version>${hutool-all.version}</version>
         </dependency>
 
+        <dependency>
+            <groupId>com.alibaba</groupId>
+            <artifactId>easyexcel</artifactId>
+            <version>${easyexcel.version}</version>
+        </dependency>
     </dependencies>
 
     <build>

+ 30 - 0
src/main/java/com/ebei/screen/common/util/LeviUtils.java

@@ -20,6 +20,8 @@ import java.time.temporal.TemporalAdjusters;
 import java.util.Arrays;
 import java.util.List;
 import java.util.stream.Collectors;
+import java.util.zip.ZipEntry;
+import java.util.zip.ZipOutputStream;
 
 /**
  * 乱七八糟工具类
@@ -165,4 +167,32 @@ public class LeviUtils {
         return DateUtil.date(Long.parseLong(time + "000")).toString("yyyy-MM-dd HH:mm:ss");
     }
 
+    public static void zipOutput(HttpServletResponse response, List<ByteArrayOutputStream> outs, List<String> fileNames, String zipName) throws IOException {
+        File file = new File(zipName);
+        response.setContentType("application/force-download");
+        response.addHeader("Access-Control-Expose-Headers", "Content-Disposition");
+        response.setHeader("Content-Disposition", "attachment; filename=" + new String((file.getName() + ".zip").getBytes("UTF-8"), "ISO8859-1"));
+        try (ZipOutputStream zos = new ZipOutputStream(new FileOutputStream(file))) {
+            for (int i = 0; i < outs.size(); i++) {
+                ZipEntry zo = new ZipEntry(fileNames.get(i));
+                zos.putNextEntry(zo);
+                zos.write(outs.get(i).toByteArray());
+                zos.closeEntry();
+            }
+            zos.flush();
+            zos.finish();
+        }
+        int len;
+        byte[] buf = new byte[1024];
+        try (FileInputStream in = new FileInputStream(file)) {
+            while ((len = in.read(buf)) != -1) {
+                response.getOutputStream().write(buf, 0, len);
+            }
+        } catch (Exception e) {
+            e.printStackTrace();
+        } finally {
+            file.delete();
+        }
+    }
+
 }

+ 30 - 8
src/main/java/com/ebei/screen/common/util/ParkUtils.java

@@ -50,7 +50,6 @@ public class ParkUtils {
 
     public static String token;
 
-
     @Autowired
     public void setMongoTemplate(MongoTemplate mongoTemplate) {
         ParkUtils.mongoTemplate = mongoTemplate;
@@ -396,7 +395,6 @@ public class ParkUtils {
                 .body(getCommonParams(Levi.by("filePath", photo)))
                 .execute().body();
         JSONArray dataItems = JSON.parseObject(str).getJSONArray("dataItems");
-        System.out.println("getImgUrlById:" + dataItems);
         if (dataItems != null) {
             String image = dataItems.toJavaList(Map.class).get(0).get("image").toString();
             return image;
@@ -404,6 +402,18 @@ public class ParkUtils {
         return null;
     }
 
+    /**
+     * 获取附件图片字节数组
+     *
+     * @param photo
+     * @return
+     */
+    public static byte[] getExcelPhotoUrl(Object photo) {
+        String url = (String) photo;
+        String imgUrlById = getImgUrlById(url);
+        return StringUtils.isNotBlank(imgUrlById) ? Base64.getDecoder().decode(imgUrlById) : null;
+    }
+
     /**
      * 判断数据是否存在异常 并插入异常信息
      *
@@ -425,7 +435,7 @@ public class ParkUtils {
             if (CollUtil.isNotEmpty(feesTime)) {
                 feesTime.forEach(x -> {
                     x.put("imageUrl", x.get(ParkType.IN.getImage()));
-                    x.put("operator", x.get("inOperator"));
+                    x.put("operator", x.get("inOperator") == null ? x.get("outOperator") : x.get("inOperator"));
                 });
             }
             data.put(ParkExceptionType.A.getCode(), feesTime);
@@ -441,14 +451,14 @@ public class ParkUtils {
             if (CollUtil.isNotEmpty(feesTime)) {
                 feesTime.forEach(x -> {
                     x.put("imageUrl", x.get(ParkType.OUT.getImage()));
-                    x.put("operator", x.get("outOperator"));
+                    x.put("operator", x.get("outOperator") == null ? x.get("inOperator") : x.get("outOperator"));
                     x.put("equipName", x.get("outEquipName"));
                 });
             }
             data.put(ParkExceptionType.A.getCode(), feesTime);
             // 支付时间过长
             String now = LocalDateTimeUtil.format(LocalDateTime.now(), DatePattern.NORM_DATETIME_PATTERN);
-            List<Map> list2 = params.stream().filter(x -> getDimSS(x.get("outTime") == null ? now : x.get("outTime").toString(), x.get("openDoor") == null ? now : x.get("opengate_time").toString()) > 60
+            List<Map> list2 = params.stream().filter(x -> getDimSS(x.get("outTime") == null ? now : x.get("outTime").toString(), x.get("opengate_time") == null ? now : x.get("opengate_time").toString()) > 60
             ).collect(Collectors.toList());
             List<Map> maps2 = data.getJSONArray(ParkExceptionType.B.getCode()) == null ? new ArrayList<>() : data.getJSONArray(ParkExceptionType.B.getCode()).toJavaList(Map.class);
             maps2.addAll(list2);
@@ -456,7 +466,7 @@ public class ParkUtils {
             if (CollUtil.isNotEmpty(feesTime2)) {
                 feesTime2.forEach(x -> {
                     x.put("imageUrl", x.get(ParkType.OUT.getImage()));
-                    x.put("operator", x.get("outOperator"));
+                    x.put("operator", x.get("outOperator") == null ? x.get("inOperator") : x.get("outOperator"));
                     x.put("equipName", x.get("outEquipName"));
                 });
             }
@@ -469,7 +479,7 @@ public class ParkUtils {
             if (CollUtil.isNotEmpty(feesTime3)) {
                 feesTime3.forEach(x -> {
                     x.put("imageUrl", x.get(ParkType.OUT.getImage()));
-                    x.put("operator", x.get("outOperator"));
+                    x.put("operator", x.get("outOperator") == null ? x.get("inOperator") : x.get("outOperator"));
                     x.put("equipName", x.get("outEquipName"));
                 });
             }
@@ -489,7 +499,7 @@ public class ParkUtils {
             data.put(ParkExceptionType.C.getCode(), feesTime);
             if (CollUtil.isNotEmpty(feesTime)) {
                 feesTime.forEach(x -> {
-                    x.put("operator", x.get("operateName"));
+                    x.put("operator", x.get("operateName") == null ? (x.get("outOperator") == null ? x.get("inOperator") : x.get("outOperator")) : x.get("operateName"));
                     x.put("equipName", x.get("cardTypeName"));
                 });
             }
@@ -545,5 +555,17 @@ public class ParkUtils {
         }
         return list;
     }
+
+    /**
+     * 根据parkCode获取parkName
+     *
+     * @param code
+     * @return value
+     */
+    public static String getParkNameByCode(String code) {
+        ResourceBundle bundle = ResourceBundle.getBundle("parkName");
+        return bundle.getString(code);
+
+    }
 }
 

+ 7 - 0
src/main/java/com/ebei/screen/controller/park/ParkSystemController.java

@@ -13,6 +13,7 @@ import lombok.extern.slf4j.Slf4j;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.web.bind.annotation.*;
 
+import javax.servlet.http.HttpServletResponse;
 import java.util.Map;
 
 /**
@@ -181,4 +182,10 @@ public class ParkSystemController {
         return parkSystemService.fixDate(collection, date);
     }
 
+    @ApiOperation(value = "异常信息导出")
+    @PostMapping("/exportException")
+    public void exportException(@RequestBody ExceptionTrendReq params, HttpServletResponse response) {
+        parkSystemService.exportException(params, response);
+    }
+
 }

+ 9 - 0
src/main/java/com/ebei/screen/service/ParkSystemService.java

@@ -4,6 +4,7 @@ import com.ebei.screen.common.response.ResponseBean;
 import com.ebei.screen.common.util.Levi;
 import com.ebei.screen.modules.req.*;
 
+import javax.servlet.http.HttpServletResponse;
 import java.util.Map;
 
 /**
@@ -221,4 +222,12 @@ public interface ParkSystemService {
      * @return
      */
     ResponseBean fixDate(String collection, String date);
+
+    /**
+     * 异常信息导出
+     *
+     * @param params
+     * @param response
+     */
+    void exportException(ExceptionTrendReq params, HttpServletResponse response);
 }

+ 65 - 0
src/main/java/com/ebei/screen/service/impl/ParkSystemServiceImpl.java

@@ -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);
+        }
+    }
+
     /**
      * 不同收费方式停车统计
      *

+ 3 - 5
src/main/resources/application-dev.yml

@@ -8,13 +8,11 @@ spring:
   data:
     mongodb:
       database: eaglescreen
-      host: 172.18.0.23
+      host: 127.0.0.1
       port: 27017
-      username: root
-      password: admin
 energy:
   # 多个用逗号分隔开
   grpId: 197069285991913100
 comm:
-  mkf-service-url: https://portal.wuyeface.com/landcrm/rest/userInfo/getUser?token=
-  getProjectList: http://portal.wuyeface.com/landcrm/rest/projectInfo/getProjectList?userId=
+  mkf-service-url: https://ipms.jinying.com/landcrm/rest/userInfo/getUser?token=
+  getProjectList: https://ipms.jinying.com/landcrm/rest/projectInfo/getProjectList?userId=

+ 1 - 1
src/main/resources/application.yml

@@ -6,7 +6,7 @@ spring:
     default-property-inclusion: non_null
     time-zone: Asia/Shanghai
   profiles:
-    active: uat
+    active: dev
 cn:
   auth:
     permit-url-list: