Levi.u před 4 roky
rodič
revize
b4c79a042c

+ 29 - 0
src/main/java/com/ebei/screen/common/util/ParkUtils.java

@@ -156,6 +156,35 @@ public class ParkUtils {
         return result;
     }
 
+    /**
+     * 获取封装后的结果集
+     *
+     * @param params
+     * @return
+     */
+    public static Map<String, List<Map>> getInsertMap(Map params, String timeKey) {
+        List<Map> dataItems = JSON.parseObject((String) params.get("dataItems"), List.class);
+        if (CollUtil.isEmpty(dataItems)) {
+            return null;
+        }
+        Map<String, List<Map>> result = new HashMap<>(16);
+        dataItems.forEach(x -> {
+            String parkCode = x.get("parkCode").toString();
+            String format = LocalDateTimeUtil.format(ParkUtils.getResultLocalDateTime(x, timeKey), DatePattern.PURE_DATE_PATTERN);
+            List<Map> maps = new ArrayList<>();
+            if (result.containsKey(parkCode + "_" + format)) {
+                maps = result.get(parkCode + "_" + format);
+            }
+            maps.add(x);
+            maps.forEach(y -> {
+                y.put("sn", params.get("sn").toString());
+                y.put("homra", LocalDateTimeUtil.format(LocalDateTime.now(), "HH"));
+            });
+            result.put(parkCode + "_" + format, maps);
+        });
+        return result;
+    }
+
     /**
      * 获取某批推送的时间点
      *

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

@@ -8,6 +8,7 @@ import com.ebei.screen.service.EbaSystemService;
 import com.ebei.screen.service.ParkSystemService;
 import io.swagger.annotations.Api;
 import io.swagger.annotations.ApiOperation;
+import lombok.extern.slf4j.Slf4j;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.web.bind.annotation.*;
 
@@ -20,6 +21,7 @@ import java.util.Map;
 @Api(tags = "车场系统大屏")
 @RestController
 @RequestMapping("park")
+@Slf4j
 public class ParkSystemController {
 
     @Autowired
@@ -70,6 +72,7 @@ public class ParkSystemController {
             parkSystemService.parkCharge(params);
             return Levi.by("code", 1).set("msg", "成功");
         } catch (Exception e) {
+            log.info("收费记录推送===>", e);
             return Levi.by("code", 0).set("msg", "失败");
         }
     }

+ 3 - 4
src/main/java/com/ebei/screen/service/impl/EbaSystemServiceImpl.java

@@ -331,10 +331,10 @@ public class EbaSystemServiceImpl implements EbaSystemService {
      * @return
      */
     @Override
-    public Integer realTimeCallback(Map<String, String> params) {
+    public Integer realTimeCallback(Map params) {
         // 判断类型
-        String messageCode = params.get("messageCode");
-        String content = params.get("content");
+        String messageCode = params.get("messageCode").toString();
+        String content = params.get("content").toString();
         List<Map> contentList = LeviUtils.getJsonFieldMany(content, null, Map.class);
         if (CollUtil.isEmpty(contentList)) {
             return 200;
@@ -352,7 +352,6 @@ public class EbaSystemServiceImpl implements EbaSystemService {
         update.set("data", gzMap.get("data"));
         update.set("gzCount", gzMap.get("gzCount"));
         mongoTemplate.upsert(query, update, "realTimeList");
-        log.info("实时数据接收:{}", JSON.toJSONString(params));
         return 200;
     }
 

+ 13 - 15
src/main/java/com/ebei/screen/service/impl/ParkSystemServiceImpl.java

@@ -163,28 +163,27 @@ public class ParkSystemServiceImpl implements ParkSystemService {
         Map<String, List<Map>> insertMap = new HashMap<>(16);
         dataItems.forEach(x -> {
             String parkCode = x.get("parkCode").toString();
+            String format = LocalDateTimeUtil.format(ParkUtils.getResultLocalDateTime(x, "feesTime"), DatePattern.PURE_DATE_PATTERN);
             List<Map> maps = new ArrayList<>();
-            if (insertMap.containsKey(parkCode)) {
-                maps = insertMap.get(parkCode);
+            if (insertMap.containsKey(parkCode + "_" + format)) {
+                maps = insertMap.get(parkCode + "_" + format);
             }
             maps.add(x);
-            insertMap.put(parkCode, maps);
+            insertMap.put(parkCode + "_" + format, maps);
         });
         if (MapUtil.isNotEmpty(insertMap)) {
-            insertMap.keySet().forEach(key -> insertMap.get(key).forEach(res -> {
-                res.put("feesTime", res.get("feesTime").toString().split("\\.")[0]);
-                String format = LocalDateTimeUtil.format(ParkUtils.getResultLocalDateTime(res, "feesTime"), DatePattern.PURE_DATE_PATTERN);
+            insertMap.keySet().forEach(key -> {
                 Query query = new Query();
-                query.addCriteria(Criteria.where("_id").is(key + "_" + format));
+                query.addCriteria(Criteria.where("_id").is(key));
                 Update update = new Update();
-                JSONObject obj = mongoTemplate.findById(key + "_" + format, JSONObject.class, "parkCharge");
+                JSONObject obj = mongoTemplate.findById(key, JSONObject.class, "parkCharge");
                 JSONArray data = obj != null ? obj.getJSONArray("data") : new JSONArray();
                 data.addAll(insertMap.get(key));
                 List<Map> feesTime = ParkUtils.sortDateList(data, "feesTime", true);
                 update.set("data", feesTime);
                 update.set("count", feesTime.size());
                 mongoTemplate.upsert(query, update, "parkCharge");
-            }));
+            });
         }
     }
 
@@ -195,15 +194,14 @@ public class ParkSystemServiceImpl implements ParkSystemService {
      */
     @Override
     public void parkServiceInfo(Map params) {
-        Map<String, List<Map>> insertMap = ParkUtils.getInsertMap(params);
+        Map<String, List<Map>> insertMap = ParkUtils.getInsertMap(params, "operateTime");
         String pno = params.get("pno").toString();
         if (MapUtil.isNotEmpty(insertMap)) {
-            insertMap.keySet().forEach(key -> insertMap.get(key).forEach(res -> {
-                String format = LocalDateTimeUtil.format(ParkUtils.getResultLocalDateTime(res, "operateTime"), DatePattern.PURE_DATE_PATTERN);
+            insertMap.keySet().forEach(key -> {
                 Query query = new Query();
-                query.addCriteria(Criteria.where("_id").is(key + "_" + format));
+                query.addCriteria(Criteria.where("_id").is(key));
                 Update update = new Update();
-                JSONObject obj = mongoTemplate.findById(key + "_" + format, JSONObject.class, "parkServiceInfo");
+                JSONObject obj = mongoTemplate.findById(key, JSONObject.class, "parkServiceInfo");
                 JSONArray data = obj != null ? obj.getJSONArray("data") : new JSONArray();
                 data.addAll(insertMap.get(key));
                 List<Map> feesTime = ParkUtils.sortDateList(data, "operateTime", true);
@@ -214,7 +212,7 @@ public class ParkSystemServiceImpl implements ParkSystemService {
                 mongoTemplate.upsert(query, update, "parkServiceInfo");
                 // 校验是否存在异常数据
                 ParkUtils.insertException(key, feesTime, CommonConstants.SERVICE_INFO);
-            }));
+            });
         }
     }