|
@@ -14,10 +14,7 @@ import com.ebei.screen.common.constants.PayTypeCode;
|
|
|
import com.ebei.screen.common.response.PageBean;
|
|
|
import com.ebei.screen.common.response.ResponseBean;
|
|
|
import com.ebei.screen.common.response.ResponseBuilder;
|
|
|
-import com.ebei.screen.common.util.EbaUtils;
|
|
|
-import com.ebei.screen.common.util.EnergyUtils;
|
|
|
-import com.ebei.screen.common.util.Levi;
|
|
|
-import com.ebei.screen.common.util.ParkUtils;
|
|
|
+import com.ebei.screen.common.util.*;
|
|
|
import com.ebei.screen.modules.req.*;
|
|
|
import com.ebei.screen.service.ParkSystemService;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
@@ -30,9 +27,12 @@ import org.springframework.data.mongodb.core.query.Update;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
|
|
|
+import java.time.Duration;
|
|
|
+import java.time.Instant;
|
|
|
import java.time.LocalDateTime;
|
|
|
import java.time.temporal.ChronoUnit;
|
|
|
import java.util.*;
|
|
|
+import java.util.concurrent.CountDownLatch;
|
|
|
import java.util.concurrent.atomic.AtomicReference;
|
|
|
import java.util.function.Supplier;
|
|
|
import java.util.stream.Collectors;
|
|
@@ -52,6 +52,97 @@ public class ParkSystemServiceImpl implements ParkSystemService {
|
|
|
@Autowired
|
|
|
private MongoTemplate mongoTemplate;
|
|
|
|
|
|
+ /**
|
|
|
+ * 统一存放到mongo中后续处理
|
|
|
+ *
|
|
|
+ * @param id 业务id
|
|
|
+ * @param params 参数
|
|
|
+ * @param flag false:jlite
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public synchronized Levi exec(String id, Map params, boolean flag) {
|
|
|
+ try {
|
|
|
+ // 插入
|
|
|
+ mongoTemplate.insert(Levi.by("_id", id).set("data", params), "parkQueue");
|
|
|
+ // 更新字典值
|
|
|
+ JSONObject obj = mongoTemplate.findById("idDict", JSONObject.class, "parkQueue");
|
|
|
+ Query query = new Query();
|
|
|
+ query.addCriteria(Criteria.where("_id").is("idDict"));
|
|
|
+ Update update = new Update();
|
|
|
+ if (obj != null) {
|
|
|
+ update.set("data", obj.getJSONArray("data").fluentAdd(id));
|
|
|
+ update.set("count", obj.getIntValue("count") + 1);
|
|
|
+ } else {
|
|
|
+ update.set("data", new JSONArray().fluentAdd(id));
|
|
|
+ update.set("count", 1);
|
|
|
+ }
|
|
|
+ mongoTemplate.upsert(query, update, "parkQueue");
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.info("存储队列出现异常:", e);
|
|
|
+ return Levi.by(flag ? "resultCode" : "code", flag ? 1 : 0).set(flag ? "message" : "msg", flag ? "处理失败" : "失败");
|
|
|
+ }
|
|
|
+ return Levi.by(flag ? "resultCode" : "code", flag ? 0 : 1).set(flag ? "message" : "msg", flag ? "处理成功" : "成功");
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 处理任务
|
|
|
+ *
|
|
|
+ * @param size 处理数量
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public synchronized boolean taskExec(int size) throws InterruptedException {
|
|
|
+ boolean result = false;
|
|
|
+ JSONObject obj = mongoTemplate.findById("idDict", JSONObject.class, "parkQueue");
|
|
|
+ JSONArray data = obj != null ? obj.getJSONArray("data") : new JSONArray();
|
|
|
+ if (data != null && data.size() > 0) {
|
|
|
+ List<String> ids = (List<String>) (List) data.subList(0, Integer.min(data.size(), size));
|
|
|
+ CountDownLatch countDownLatch = new CountDownLatch(Integer.min(data.size(), size));
|
|
|
+ ids.forEach(x -> RunnableUtils.start(() -> {
|
|
|
+ JSONObject xx = mongoTemplate.findById(x, JSONObject.class, "parkQueue");
|
|
|
+ if (xx == null) {
|
|
|
+ countDownLatch.countDown();
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ Instant start = Instant.now();
|
|
|
+ JSONObject params = xx.getJSONObject("data");
|
|
|
+ if (x.startsWith("parkInfo")) {
|
|
|
+ this.parkInfo(params);
|
|
|
+ } else if (x.startsWith("parkSpace")) {
|
|
|
+ this.parkSpace(params);
|
|
|
+ } else if (x.startsWith("parkIn")) {
|
|
|
+ this.parkIn(params);
|
|
|
+ } else if (x.startsWith("parkOut")) {
|
|
|
+ this.parkOut(params);
|
|
|
+ } else if (x.startsWith("parkOrder")) {
|
|
|
+ this.parkOrder(params);
|
|
|
+ } else if (x.startsWith("parkCharge")) {
|
|
|
+ this.parkCharge(params);
|
|
|
+ } else if (x.startsWith("parkServiceInfo")) {
|
|
|
+ this.parkServiceInfo(params);
|
|
|
+ }
|
|
|
+ // 处理完成删除当前document
|
|
|
+ mongoTemplate.remove(xx, "parkQueue");
|
|
|
+ countDownLatch.countDown();
|
|
|
+ Instant end = Instant.now();
|
|
|
+ log.info("当前执行:" + x + " 执行时间:" + Duration.between(start, end).toMillis() + "毫秒 当前可用线程数:" + RunnableUtils.getActiveNum());
|
|
|
+ }));
|
|
|
+ countDownLatch.await();
|
|
|
+ // 删除本批次处理的id
|
|
|
+ data.removeAll(ids);
|
|
|
+ Query query = new Query();
|
|
|
+ query.addCriteria(Criteria.where("_id").is("idDict"));
|
|
|
+ Update update = new Update();
|
|
|
+ update.set("data", data);
|
|
|
+ update.set("count", data.size());
|
|
|
+ mongoTemplate.upsert(query, update, "parkQueue");
|
|
|
+ result = true;
|
|
|
+ }
|
|
|
+ return result;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
/**
|
|
|
* 车场信息数据推送
|
|
|
*
|