Commit 8723dd64d6d9a438be56a572038e392555ba387d

Authored by 潘钊
1 parent 8a1112e3

update...

src/main/java/com/bsth/data/directive/DirectivesPstThread.java
1 1 package com.bsth.data.directive;
2 2  
  3 +import com.bsth.data.schedule.DayOfSchedule;
3 4 import com.bsth.entity.directive.D60;
4 5 import com.bsth.entity.directive.D64;
5 6 import com.bsth.entity.directive.Directive;
  7 +import com.bsth.entity.realcontrol.ScheduleRealInfo;
6 8 import com.bsth.repository.directive.D60Repository;
7 9 import com.bsth.repository.directive.D64Repository;
8 10 import org.slf4j.Logger;
... ... @@ -27,6 +29,9 @@ public class DirectivesPstThread extends Thread {
27 29 @Autowired
28 30 D64Repository d64Repository;
29 31  
  32 + @Autowired
  33 + DayOfSchedule dayOfSchedule;
  34 +
30 35 @Override
31 36 public void run() {
32 37 LinkedList<Directive> list = DayOfDirectives.pstDirectives;
... ... @@ -37,7 +42,14 @@ public class DirectivesPstThread extends Thread {
37 42 directive = list.poll();
38 43  
39 44 if (directive instanceof D60) {
40   - d60Repository.save((D60) directive);
  45 + D60 d60 = (D60) directive;
  46 + if(d60.isDispatch()){
  47 + ScheduleRealInfo sch = d60.getSch();
  48 + //如果关联的班次已经不存在了,放弃入库
  49 + if(dayOfSchedule.get(sch.getId()) == null)
  50 + continue;
  51 + }
  52 + d60Repository.save(d60);
41 53 }
42 54  
43 55 if (directive instanceof D64) {
... ...
src/main/java/com/bsth/entity/directive/D60.java
1 1 package com.bsth.entity.directive;
2 2  
3   -import javax.persistence.Embeddable;
4   -import javax.persistence.Entity;
5   -import javax.persistence.FetchType;
6   -import javax.persistence.GeneratedValue;
7   -import javax.persistence.Id;
8   -import javax.persistence.ManyToOne;
9   -import javax.persistence.NamedAttributeNode;
10   -import javax.persistence.NamedEntityGraph;
11   -import javax.persistence.NamedEntityGraphs;
12   -import javax.persistence.Table;
13   -import javax.persistence.Transient;
14   -
15 3 import com.bsth.entity.realcontrol.ScheduleRealInfo;
16 4 import com.fasterxml.jackson.annotation.JsonIgnore;
17 5  
  6 +import javax.persistence.*;
  7 +
18 8  
19 9 /**
20 10 * @author PanZhao
... ... @@ -75,7 +65,7 @@ public class D60 extends Directive {
75 65 * 相关联的班次
76 66 */
77 67 @JsonIgnore
78   - @ManyToOne(fetch = FetchType.LAZY)
  68 + @ManyToOne(fetch = FetchType.LAZY, cascade = CascadeType.REFRESH)
79 69 private ScheduleRealInfo sch;
80 70  
81 71 public Long getReply46Time() {
... ...
src/main/java/com/bsth/service/realcontrol/impl/ScheduleRealInfoServiceImpl.java
... ... @@ -624,12 +624,12 @@ public class ScheduleRealInfoServiceImpl extends BaseServiceImpl&lt;ScheduleRealInf
624 624 //数据库删除
625 625 rs = super.delete(id);
626 626 if(rs.get("status").equals(ResponseCode.SUCCESS)){
627   - ScheduleRealInfo temp = super.findById(id);
  627 + /*ScheduleRealInfo temp = super.findById(id);
628 628 if(temp != null){
629 629 rs.put("status", ResponseCode.ERROR);
630 630 rs.put("msg", "删除失败,请重试!");
631 631 return rs;
632   - }
  632 + }*/
633 633  
634 634 dayOfSchedule.delete(sch);
635 635 //更新起点应到时间
... ...
src/main/java/com/bsth/websocket/handler/RealControlSocketHandler.java
... ... @@ -6,29 +6,29 @@ import com.bsth.data.BasicData;
6 6 import com.google.common.base.Splitter;
7 7 import org.slf4j.Logger;
8 8 import org.slf4j.LoggerFactory;
9   -import org.springframework.context.annotation.Scope;
10 9 import org.springframework.stereotype.Component;
11 10 import org.springframework.web.socket.*;
12 11  
13   -import java.util.*;
  12 +import java.util.ArrayList;
  13 +import java.util.Collection;
  14 +import java.util.Iterator;
  15 +import java.util.List;
14 16 import java.util.concurrent.ConcurrentHashMap;
  17 +import java.util.concurrent.CopyOnWriteArrayList;
15 18  
16 19 /**
17 20 * @author PanZhao
18 21 */
19 22 @Component
20   -@Scope("prototype")
21 23 public class RealControlSocketHandler implements WebSocketHandler {
22 24  
23 25 Logger logger = LoggerFactory.getLogger(this.getClass());
24 26  
25 27 private static ArrayList<WebSocketSession> users;
26   - //private static final ArrayListMultimap<String, WebSocketSession> listenMap;
27   - private static ConcurrentHashMap<String, List<WebSocketSession>> listenMap;
  28 + private static ConcurrentHashMap<String, CopyOnWriteArrayList<WebSocketSession>> listenMap;
28 29  
29 30 static {
30 31 users = new ArrayList<WebSocketSession>();
31   - //listenMap = ArrayListMultimap.create();
32 32 listenMap = new ConcurrentHashMap();
33 33 }
34 34  
... ... @@ -37,30 +37,13 @@ public class RealControlSocketHandler implements WebSocketHandler {
37 37 throws Exception {
38 38 users.remove(session);
39 39 //清理监听
40   - //Set<String> keys = listenMap.keySet();
41   - //Map<String, WebSocketSession> remMap = new HashMap<>();
42   -
43 40 int vsCount=0;
44   - Collection<List<WebSocketSession>> vs = listenMap.values();
45   - for(List<WebSocketSession> list : vs){
  41 + Collection<CopyOnWriteArrayList<WebSocketSession>> vs = listenMap.values();
  42 + for(CopyOnWriteArrayList<WebSocketSession> list : vs){
46 43 list.remove(session);
47 44  
48 45 vsCount += list.size();
49 46 }
50   - /*List<WebSocketSession> vs;
51   - for(String k : keys){
52   - //vs = listenMap.get(k);
53   - //vs.remove(session);
54   - listenMap.get(k).remove()
55   - *//*if(listenMap.get(k).contains(session))
56   - remMap.put(k, session);*//*
57   - }*/
58   -
59   - /*Set<String> remSet = remMap.keySet();
60   - for(String k : remSet){
61   - listenMap.remove(k, remMap.get(k));
62   - logger.info("web socket close, remove listen K: "+ k);
63   - }*/
64 47 logger.info("listen values size: " + vsCount + " -CloseStatus:" + arg1);
65 48 }
66 49  
... ... @@ -81,7 +64,7 @@ public class RealControlSocketHandler implements WebSocketHandler {
81 64 for(String lineCode : idx){
82 65 if(BasicData.lineCode2NameMap.containsKey(lineCode)){
83 66 if(!listenMap.containsKey(lineCode)){
84   - listenMap.put(lineCode, new ArrayList<WebSocketSession>());
  67 + listenMap.put(lineCode, new CopyOnWriteArrayList<WebSocketSession>());
85 68 }
86 69 listenMap.get(lineCode).add(session);
87 70 }
... ...