|
|
@@ -1,5 +1,6 @@
|
|
|
package com.uas.platform.b2b.controller;
|
|
|
|
|
|
+import com.uas.platform.b2b.core.util.BoundedExecutor;
|
|
|
import com.uas.platform.b2b.core.util.ThreadUtils;
|
|
|
import com.uas.platform.b2b.model.Role;
|
|
|
import com.uas.platform.b2b.model.Snapshot;
|
|
|
@@ -20,6 +21,9 @@ import org.springframework.web.bind.annotation.RestController;
|
|
|
import java.util.List;
|
|
|
import java.util.Map;
|
|
|
import java.util.concurrent.ConcurrentHashMap;
|
|
|
+import java.util.concurrent.CountDownLatch;
|
|
|
+import java.util.concurrent.ExecutorService;
|
|
|
+import java.util.concurrent.Executors;
|
|
|
|
|
|
/**
|
|
|
* 平台消息、任务快照
|
|
|
@@ -31,11 +35,19 @@ import java.util.concurrent.ConcurrentHashMap;
|
|
|
@RequestMapping("/snapshot")
|
|
|
public class SnapshotController {
|
|
|
|
|
|
- @Autowired
|
|
|
- private SnapshotService snapshotService;
|
|
|
+ private final SnapshotService snapshotService;
|
|
|
|
|
|
- @Autowired
|
|
|
- private OrderRedDotService redDotService;
|
|
|
+ private final OrderRedDotService redDotService;
|
|
|
+
|
|
|
+ private final BoundedExecutor executor;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ public SnapshotController(SnapshotService snapshotService, OrderRedDotService redDotService) {
|
|
|
+ this.snapshotService = snapshotService;
|
|
|
+ this.redDotService = redDotService;
|
|
|
+ ExecutorService executorService = Executors.newCachedThreadPool();
|
|
|
+ executor = new BoundedExecutor(executorService, 1600);
|
|
|
+ }
|
|
|
|
|
|
/**
|
|
|
* 日志
|
|
|
@@ -53,7 +65,7 @@ public class SnapshotController {
|
|
|
Long start = System.currentTimeMillis();
|
|
|
ModelMap modelMap = new ModelMap();
|
|
|
final Long enUU = SystemSession.getUser().getEnterprise().getUu();
|
|
|
- ThreadUtils.task(()-> {
|
|
|
+ ThreadUtils.task(()-> {
|
|
|
List<Snapshot> snapshots = snapshotService.findByEnUU(enUU);
|
|
|
if (!CollectionUtils.isEmpty(snapshots)) {
|
|
|
snapshots.stream()
|
|
|
@@ -73,7 +85,7 @@ public class SnapshotController {
|
|
|
*/
|
|
|
@RequestMapping(value = "/unread/all", method = RequestMethod.GET, headers = "Accept=application/json")
|
|
|
@ResponseStatus(value = HttpStatus.OK)
|
|
|
- public ModelMap getUnreadCount() {
|
|
|
+ public ModelMap getUnreadCount() throws InterruptedException {
|
|
|
Long start = System.currentTimeMillis();
|
|
|
/**
|
|
|
* 采用ConcurrentHashMap编写 防止HashMap的put方法在多线程并发的情况下数据丢失
|
|
|
@@ -81,8 +93,9 @@ public class SnapshotController {
|
|
|
final ConcurrentHashMap<String, Integer> hashMap = new ConcurrentHashMap<>(15);
|
|
|
final User user = SystemSession.getUser();
|
|
|
ModelMap modelMap = new ModelMap();
|
|
|
+ final CountDownLatch threadsSignal = new CountDownLatch(15);
|
|
|
//并行处理
|
|
|
- ThreadUtils.task(() -> {
|
|
|
+ executor.submitTask(() -> {
|
|
|
//客户资料
|
|
|
SystemSession.setUser(user);
|
|
|
final int[] count = {0};
|
|
|
@@ -90,7 +103,9 @@ public class SnapshotController {
|
|
|
list.forEach(objects -> count[0] = count[0] + Integer.valueOf(objects[0].toString()));
|
|
|
hashMap.put("customer", count[0]);
|
|
|
SystemSession.clear();
|
|
|
- }).task(() -> {
|
|
|
+ threadsSignal.countDown();
|
|
|
+ });
|
|
|
+ executor.submitTask(() -> {
|
|
|
//供应商绩效考核
|
|
|
SystemSession.setUser(user);
|
|
|
final int[] count = {0};
|
|
|
@@ -98,55 +113,73 @@ public class SnapshotController {
|
|
|
list.forEach(objects -> count[0] = count[0] + Integer.valueOf(objects[0].toString()));
|
|
|
hashMap.put("vendorPerformanceAssess", count[0]);
|
|
|
SystemSession.clear();
|
|
|
- }).task(() -> {
|
|
|
+ threadsSignal.countDown();
|
|
|
+ });
|
|
|
+ executor.submitTask(() -> {
|
|
|
//客户采购询价
|
|
|
SystemSession.setUser(user);
|
|
|
Map<String, Integer> map = redDotService.getInquiryCount(Role.SELLER);
|
|
|
hashMap.put("inquiry", map.containsKey("all") ? map.get("all") : 0);
|
|
|
SystemSession.clear();
|
|
|
- }).task(() -> {
|
|
|
+ threadsSignal.countDown();
|
|
|
+ });
|
|
|
+ executor.submitTask(() -> {
|
|
|
//客户模具询价
|
|
|
SystemSession.setUser(user);
|
|
|
Map<String, Integer> count = redDotService.getInquiryMouldCount(Role.SELLER);
|
|
|
hashMap.put("mould", count.containsKey("all") ? count.get("all") : 0);
|
|
|
SystemSession.clear();
|
|
|
- }).task(() -> {
|
|
|
+ threadsSignal.countDown();
|
|
|
+ });
|
|
|
+ executor.submitTask(() -> {
|
|
|
//客户招标
|
|
|
SystemSession.setUser(user);
|
|
|
Map<String, Integer> count = redDotService.getTenderCount(Role.SELLER);
|
|
|
hashMap.put("tender", count.containsKey("all") ? count.get("all") : 0);
|
|
|
SystemSession.clear();
|
|
|
- }).task(() -> {
|
|
|
+ threadsSignal.countDown();
|
|
|
+ });
|
|
|
+ executor.submitTask(() -> {
|
|
|
//客户采购订单
|
|
|
SystemSession.setUser(user);
|
|
|
Map<String, Integer> count = redDotService.getSaleOrderCount(Role.SELLER);
|
|
|
hashMap.put("order", count.containsKey("all") ? count.get("all") : 0);
|
|
|
SystemSession.clear();
|
|
|
- }).task(() -> {
|
|
|
+ threadsSignal.countDown();
|
|
|
+ });
|
|
|
+ executor.submitTask(() -> {
|
|
|
//客户采购变更单
|
|
|
SystemSession.setUser(user);
|
|
|
Map<String, Integer> map = redDotService.getChangeCount(Role.SELLER);
|
|
|
hashMap.put("change", map.containsKey("all") ? map.get("all") : 0);
|
|
|
SystemSession.clear();
|
|
|
- }).task(() -> {
|
|
|
+ threadsSignal.countDown();
|
|
|
+ });
|
|
|
+ executor.submitTask(() -> {
|
|
|
//客户委外单
|
|
|
SystemSession.setUser(user);
|
|
|
Map<String, Integer> count = redDotService.getMakeOrderCount(Role.SELLER);
|
|
|
hashMap.put("makeOrder", count.containsKey("all") ? count.get("all") : 0);
|
|
|
SystemSession.clear();
|
|
|
- }).task(() -> {
|
|
|
+ threadsSignal.countDown();
|
|
|
+ });
|
|
|
+ executor.submitTask(() -> {
|
|
|
//客户发货提醒
|
|
|
SystemSession.setUser(user);
|
|
|
Map<String, Integer> count = redDotService.getNoticeCount(Role.SELLER);
|
|
|
hashMap.put("notice", count.containsKey("all") ? count.get("all") : 0);
|
|
|
SystemSession.clear();
|
|
|
- }).task(() -> {
|
|
|
+ threadsSignal.countDown();
|
|
|
+ });
|
|
|
+ executor.submitTask(() -> {
|
|
|
//客户打样申请
|
|
|
SystemSession.setUser(user);
|
|
|
Map<String, Integer> count = redDotService.getProofingCount(Role.SELLER);
|
|
|
hashMap.put("sample", count.containsKey("all") ? count.get("all") : 0);
|
|
|
SystemSession.clear();
|
|
|
- }).task(() -> {
|
|
|
+ threadsSignal.countDown();
|
|
|
+ });
|
|
|
+ executor.submitTask(() -> {
|
|
|
//供应商资料
|
|
|
SystemSession.setUser(user);
|
|
|
List<Object[]> list = redDotService.getVendorCount(Role.BUYER);
|
|
|
@@ -154,25 +187,33 @@ public class SnapshotController {
|
|
|
list.forEach(objects -> count[0] = count[0] + Integer.valueOf(objects[0].toString()));
|
|
|
hashMap.put("purcVendor", count[0]);
|
|
|
SystemSession.clear();
|
|
|
- }).task(() -> {
|
|
|
+ threadsSignal.countDown();
|
|
|
+ });
|
|
|
+ executor.submitTask(() -> {
|
|
|
//采购招标
|
|
|
SystemSession.setUser(user);
|
|
|
Map<String, Integer> count = redDotService.getTenderCount(Role.BUYER);
|
|
|
hashMap.put("tender", count.containsKey("all") ? count.get("all") : 0);
|
|
|
SystemSession.clear();
|
|
|
- }).task(() -> {
|
|
|
+ threadsSignal.countDown();
|
|
|
+ });
|
|
|
+ executor.submitTask(() -> {
|
|
|
//采购询价
|
|
|
SystemSession.setUser(user);
|
|
|
Map<String, Integer> map = redDotService.getInquiryCount(Role.BUYER);
|
|
|
hashMap.put("purcInquiry", map.containsKey("all") ? map.get("all") : 0);
|
|
|
SystemSession.clear();
|
|
|
- }).task(() -> {
|
|
|
+ threadsSignal.countDown();
|
|
|
+ });
|
|
|
+ executor.submitTask(() -> {
|
|
|
//采购订单
|
|
|
SystemSession.setUser(user);
|
|
|
Map<String, Integer> count = redDotService.getSaleOrderCount(Role.BUYER);
|
|
|
hashMap.put("purcOrder", count.containsKey("all") ? count.get("all") : 0);
|
|
|
SystemSession.clear();
|
|
|
- }).task(() -> {
|
|
|
+ threadsSignal.countDown();
|
|
|
+ });
|
|
|
+ executor.submitTask(() -> {
|
|
|
//应收对账单
|
|
|
SystemSession.setUser(user);
|
|
|
List<Object[]> list = redDotService.getApCheckCount(Role.BUYER);
|
|
|
@@ -185,7 +226,9 @@ public class SnapshotController {
|
|
|
});
|
|
|
hashMap.put("apCheck", count[0]);
|
|
|
SystemSession.clear();
|
|
|
- }).run();
|
|
|
+ threadsSignal.countDown();
|
|
|
+ });
|
|
|
+ threadsSignal.await();
|
|
|
modelMap.addAllAttributes(hashMap);
|
|
|
logger.info("getUnreadCount:cost -> " + (System.currentTimeMillis() - start));
|
|
|
return modelMap;
|