whyclxw
2 天以前 cf9a5039e6db9d1d5963e3fe1a37d00169ec2ef7
src/main/java/com/whyc/webSocket/WorksheetSocket.java
@@ -3,6 +3,7 @@
import com.whyc.config.WebSocketConfig;
import com.whyc.dto.Response;
import com.whyc.pojo.DocUser;
import com.whyc.service.BOMFeedbakService;
import com.whyc.service.WorksheetMainService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
@@ -25,12 +26,16 @@
    private Thread thread;
    private static WorksheetMainService mainService;
    private static BOMFeedbakService feedbakService;
    @Autowired
    public void setWorksheetMainService(WorksheetMainService mainService) {
        WorksheetSocket.mainService = mainService;
    }
    @Autowired
    public void setFeedbakService(BOMFeedbakService feedbakService) {
        WorksheetSocket.feedbakService = feedbakService;
    }
    @OnOpen
    public void onOpen(Session session, EndpointConfig config){
        this.session = session;
@@ -42,6 +47,7 @@
                try {
                    while (!currentThread().isInterrupted()) {
                        Map<String, Integer> statisticMap = mainService.getStatusStatistic((DocUser) httpSession.getAttribute("user"));
                        feedbakService.getFkStatistic((DocUser) httpSession.getAttribute("user"),statisticMap);
                        session.getBasicRemote().sendObject(new Response().set(1, statisticMap));
                        sleep(2000);
                    }
@@ -57,9 +63,8 @@
    @OnClose
    public void onClose(CloseReason closeReason) throws IOException {
        System.err.println("closeReason = " + closeReason);
        thread.isInterrupted();
        this.thread.interrupt();
        if(session.isOpen()){
            this.thread.interrupt();
            session.close();
        }
    }
@@ -67,9 +72,8 @@
    @OnError
    public void onError(Throwable error) throws IOException {
        error.printStackTrace();
        thread.isInterrupted();
        this.thread.interrupt();
        if(session.isOpen()){
            this.thread.interrupt();
            session.close();
        }
    }