Commit 8723dd64d6d9a438be56a572038e392555ba387d
1 parent
8a1112e3
update...
Showing
4 changed files
with
27 additions
and
42 deletions
src/main/java/com/bsth/data/directive/DirectivesPstThread.java
| 1 | package com.bsth.data.directive; | 1 | package com.bsth.data.directive; |
| 2 | 2 | ||
| 3 | +import com.bsth.data.schedule.DayOfSchedule; | ||
| 3 | import com.bsth.entity.directive.D60; | 4 | import com.bsth.entity.directive.D60; |
| 4 | import com.bsth.entity.directive.D64; | 5 | import com.bsth.entity.directive.D64; |
| 5 | import com.bsth.entity.directive.Directive; | 6 | import com.bsth.entity.directive.Directive; |
| 7 | +import com.bsth.entity.realcontrol.ScheduleRealInfo; | ||
| 6 | import com.bsth.repository.directive.D60Repository; | 8 | import com.bsth.repository.directive.D60Repository; |
| 7 | import com.bsth.repository.directive.D64Repository; | 9 | import com.bsth.repository.directive.D64Repository; |
| 8 | import org.slf4j.Logger; | 10 | import org.slf4j.Logger; |
| @@ -27,6 +29,9 @@ public class DirectivesPstThread extends Thread { | @@ -27,6 +29,9 @@ public class DirectivesPstThread extends Thread { | ||
| 27 | @Autowired | 29 | @Autowired |
| 28 | D64Repository d64Repository; | 30 | D64Repository d64Repository; |
| 29 | 31 | ||
| 32 | + @Autowired | ||
| 33 | + DayOfSchedule dayOfSchedule; | ||
| 34 | + | ||
| 30 | @Override | 35 | @Override |
| 31 | public void run() { | 36 | public void run() { |
| 32 | LinkedList<Directive> list = DayOfDirectives.pstDirectives; | 37 | LinkedList<Directive> list = DayOfDirectives.pstDirectives; |
| @@ -37,7 +42,14 @@ public class DirectivesPstThread extends Thread { | @@ -37,7 +42,14 @@ public class DirectivesPstThread extends Thread { | ||
| 37 | directive = list.poll(); | 42 | directive = list.poll(); |
| 38 | 43 | ||
| 39 | if (directive instanceof D60) { | 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 | if (directive instanceof D64) { | 55 | if (directive instanceof D64) { |
src/main/java/com/bsth/entity/directive/D60.java
| 1 | package com.bsth.entity.directive; | 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 | import com.bsth.entity.realcontrol.ScheduleRealInfo; | 3 | import com.bsth.entity.realcontrol.ScheduleRealInfo; |
| 16 | import com.fasterxml.jackson.annotation.JsonIgnore; | 4 | import com.fasterxml.jackson.annotation.JsonIgnore; |
| 17 | 5 | ||
| 6 | +import javax.persistence.*; | ||
| 7 | + | ||
| 18 | 8 | ||
| 19 | /** | 9 | /** |
| 20 | * @author PanZhao | 10 | * @author PanZhao |
| @@ -75,7 +65,7 @@ public class D60 extends Directive { | @@ -75,7 +65,7 @@ public class D60 extends Directive { | ||
| 75 | * 相关联的班次 | 65 | * 相关联的班次 |
| 76 | */ | 66 | */ |
| 77 | @JsonIgnore | 67 | @JsonIgnore |
| 78 | - @ManyToOne(fetch = FetchType.LAZY) | 68 | + @ManyToOne(fetch = FetchType.LAZY, cascade = CascadeType.REFRESH) |
| 79 | private ScheduleRealInfo sch; | 69 | private ScheduleRealInfo sch; |
| 80 | 70 | ||
| 81 | public Long getReply46Time() { | 71 | public Long getReply46Time() { |
src/main/java/com/bsth/service/realcontrol/impl/ScheduleRealInfoServiceImpl.java
| @@ -624,12 +624,12 @@ public class ScheduleRealInfoServiceImpl extends BaseServiceImpl<ScheduleRealInf | @@ -624,12 +624,12 @@ public class ScheduleRealInfoServiceImpl extends BaseServiceImpl<ScheduleRealInf | ||
| 624 | //数据库删除 | 624 | //数据库删除 |
| 625 | rs = super.delete(id); | 625 | rs = super.delete(id); |
| 626 | if(rs.get("status").equals(ResponseCode.SUCCESS)){ | 626 | if(rs.get("status").equals(ResponseCode.SUCCESS)){ |
| 627 | - ScheduleRealInfo temp = super.findById(id); | 627 | + /*ScheduleRealInfo temp = super.findById(id); |
| 628 | if(temp != null){ | 628 | if(temp != null){ |
| 629 | rs.put("status", ResponseCode.ERROR); | 629 | rs.put("status", ResponseCode.ERROR); |
| 630 | rs.put("msg", "删除失败,请重试!"); | 630 | rs.put("msg", "删除失败,请重试!"); |
| 631 | return rs; | 631 | return rs; |
| 632 | - } | 632 | + }*/ |
| 633 | 633 | ||
| 634 | dayOfSchedule.delete(sch); | 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,29 +6,29 @@ import com.bsth.data.BasicData; | ||
| 6 | import com.google.common.base.Splitter; | 6 | import com.google.common.base.Splitter; |
| 7 | import org.slf4j.Logger; | 7 | import org.slf4j.Logger; |
| 8 | import org.slf4j.LoggerFactory; | 8 | import org.slf4j.LoggerFactory; |
| 9 | -import org.springframework.context.annotation.Scope; | ||
| 10 | import org.springframework.stereotype.Component; | 9 | import org.springframework.stereotype.Component; |
| 11 | import org.springframework.web.socket.*; | 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 | import java.util.concurrent.ConcurrentHashMap; | 16 | import java.util.concurrent.ConcurrentHashMap; |
| 17 | +import java.util.concurrent.CopyOnWriteArrayList; | ||
| 15 | 18 | ||
| 16 | /** | 19 | /** |
| 17 | * @author PanZhao | 20 | * @author PanZhao |
| 18 | */ | 21 | */ |
| 19 | @Component | 22 | @Component |
| 20 | -@Scope("prototype") | ||
| 21 | public class RealControlSocketHandler implements WebSocketHandler { | 23 | public class RealControlSocketHandler implements WebSocketHandler { |
| 22 | 24 | ||
| 23 | Logger logger = LoggerFactory.getLogger(this.getClass()); | 25 | Logger logger = LoggerFactory.getLogger(this.getClass()); |
| 24 | 26 | ||
| 25 | private static ArrayList<WebSocketSession> users; | 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 | static { | 30 | static { |
| 30 | users = new ArrayList<WebSocketSession>(); | 31 | users = new ArrayList<WebSocketSession>(); |
| 31 | - //listenMap = ArrayListMultimap.create(); | ||
| 32 | listenMap = new ConcurrentHashMap(); | 32 | listenMap = new ConcurrentHashMap(); |
| 33 | } | 33 | } |
| 34 | 34 | ||
| @@ -37,30 +37,13 @@ public class RealControlSocketHandler implements WebSocketHandler { | @@ -37,30 +37,13 @@ public class RealControlSocketHandler implements WebSocketHandler { | ||
| 37 | throws Exception { | 37 | throws Exception { |
| 38 | users.remove(session); | 38 | users.remove(session); |
| 39 | //清理监听 | 39 | //清理监听 |
| 40 | - //Set<String> keys = listenMap.keySet(); | ||
| 41 | - //Map<String, WebSocketSession> remMap = new HashMap<>(); | ||
| 42 | - | ||
| 43 | int vsCount=0; | 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 | list.remove(session); | 43 | list.remove(session); |
| 47 | 44 | ||
| 48 | vsCount += list.size(); | 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 | logger.info("listen values size: " + vsCount + " -CloseStatus:" + arg1); | 47 | logger.info("listen values size: " + vsCount + " -CloseStatus:" + arg1); |
| 65 | } | 48 | } |
| 66 | 49 | ||
| @@ -81,7 +64,7 @@ public class RealControlSocketHandler implements WebSocketHandler { | @@ -81,7 +64,7 @@ public class RealControlSocketHandler implements WebSocketHandler { | ||
| 81 | for(String lineCode : idx){ | 64 | for(String lineCode : idx){ |
| 82 | if(BasicData.lineCode2NameMap.containsKey(lineCode)){ | 65 | if(BasicData.lineCode2NameMap.containsKey(lineCode)){ |
| 83 | if(!listenMap.containsKey(lineCode)){ | 66 | if(!listenMap.containsKey(lineCode)){ |
| 84 | - listenMap.put(lineCode, new ArrayList<WebSocketSession>()); | 67 | + listenMap.put(lineCode, new CopyOnWriteArrayList<WebSocketSession>()); |
| 85 | } | 68 | } |
| 86 | listenMap.get(lineCode).add(session); | 69 | listenMap.get(lineCode).add(session); |
| 87 | } | 70 | } |