|
@@ -1,5 +1,6 @@
|
|
|
package com.usky.fire.service.impl;
|
|
|
|
|
|
+import com.alibaba.fastjson.JSONObject;
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
import com.baomidou.mybatisplus.core.metadata.IPage;
|
|
|
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
|
@@ -7,18 +8,25 @@ import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
|
import com.usky.common.core.bean.CommonPage;
|
|
|
import com.usky.common.core.util.StringUtils;
|
|
|
import com.usky.common.mybatis.core.AbstractCrudService;
|
|
|
+import com.usky.common.security.utils.SecurityUtils;
|
|
|
+import com.usky.fire.domain.BaseUserCompany;
|
|
|
import com.usky.fire.domain.MhPostInspect;
|
|
|
import com.usky.fire.mapper.MhPostInspectMapper;
|
|
|
+import com.usky.fire.service.BaseUserCompanyService;
|
|
|
import com.usky.fire.service.MhPostInspectService;
|
|
|
+import com.usky.fire.service.config.webScoket.WsSessionManager;
|
|
|
import com.usky.fire.service.util.OnlineMethod;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
+import org.springframework.transaction.annotation.Transactional;
|
|
|
+import org.springframework.web.socket.TextMessage;
|
|
|
+import org.springframework.web.socket.WebSocketSession;
|
|
|
|
|
|
+import java.io.IOException;
|
|
|
import java.text.SimpleDateFormat;
|
|
|
import java.time.LocalDateTime;
|
|
|
import java.time.ZoneOffset;
|
|
|
-import java.util.Date;
|
|
|
-import java.util.HashMap;
|
|
|
-import java.util.Map;
|
|
|
+import java.util.*;
|
|
|
|
|
|
/**
|
|
|
* <p>
|
|
@@ -31,6 +39,9 @@ import java.util.Map;
|
|
|
@Service
|
|
|
public class MhPostInspectServiceImpl extends AbstractCrudService<MhPostInspectMapper, MhPostInspect> implements MhPostInspectService {
|
|
|
|
|
|
+ @Autowired
|
|
|
+ private BaseUserCompanyService baseUserCompanyService;
|
|
|
+
|
|
|
@Override
|
|
|
public CommonPage<MhPostInspect> postInspectRecordList(String companyId, Integer pageNum, Integer pageSize) {
|
|
|
IPage<MhPostInspect> page = new Page<>(pageNum, pageSize);
|
|
@@ -52,7 +63,7 @@ public class MhPostInspectServiceImpl extends AbstractCrudService<MhPostInspectM
|
|
|
long time = data1 - data2;
|
|
|
if (time < 600) {
|
|
|
page.getRecords().get(i).setInspectStatusName("等待响应");
|
|
|
- page.getRecords().get(i).setCountdown(600-time);
|
|
|
+ page.getRecords().get(i).setCountdown(600 - time);
|
|
|
} else {
|
|
|
page.getRecords().get(i).setInspectStatusName("离岗");
|
|
|
page.getRecords().get(i).setSpentDate("超时未响应");
|
|
@@ -88,4 +99,59 @@ public class MhPostInspectServiceImpl extends AbstractCrudService<MhPostInspectM
|
|
|
return map;
|
|
|
}
|
|
|
|
|
|
+ @Override
|
|
|
+ @Transactional
|
|
|
+ public void postInspectPush(MhPostInspect mhPostInspect) {
|
|
|
+ String uuid = UUID.randomUUID().toString().replaceAll("-", "");
|
|
|
+ mhPostInspect.setInspectCode(uuid);
|
|
|
+ mhPostInspect.setInspectTime(LocalDateTime.now());
|
|
|
+ mhPostInspect.setInspectStatus(0);
|
|
|
+ mhPostInspect.setCreator(SecurityUtils.getUsername());
|
|
|
+ mhPostInspect.setCreateTime(LocalDateTime.now());
|
|
|
+ this.save(mhPostInspect);
|
|
|
+// String message = mhPostInspect.toString();
|
|
|
+ //查岗时间与当前时间差
|
|
|
+ long data1 = LocalDateTime.now().toEpochSecond(ZoneOffset.of("+8"));
|
|
|
+ long data2 = mhPostInspect.getInspectTime().toEpochSecond(ZoneOffset.of("+8"));
|
|
|
+ long time = data1 - data2;
|
|
|
+ mhPostInspect.setCountdown(600-time);
|
|
|
+ String message = JSONObject.toJSONString(mhPostInspect);
|
|
|
+ List<BaseUserCompany> userCompanyList = baseUserCompanyService.userCompanyList(mhPostInspect.getCompanyId());
|
|
|
+ for (int i = 0; i < userCompanyList.size(); i++) {
|
|
|
+ this.webSocketPush(new TextMessage(message), userCompanyList.get(i).getUserId());
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void webSocketPush(final TextMessage message, Integer userId) {
|
|
|
+ Set<Map.Entry<String, WebSocketSession>> entrySet = WsSessionManager.SESSION_POOL.entrySet();
|
|
|
+ for (Map.Entry<String, WebSocketSession> entry : entrySet) {
|
|
|
+ String[] split = entry.getKey().split("-");
|
|
|
+ String url = String.valueOf(entry.getValue().getUri());
|
|
|
+ String userId1 = OnlineMethod.getFieldValue(url, "userId").replaceAll(" ", "");
|
|
|
+ Integer userId2 = Integer.parseInt(userId1);
|
|
|
+ if (userId == userId2) {
|
|
|
+ final WebSocketSession webSocketSession = entry.getValue();
|
|
|
+ //判断连接是否仍然打开的
|
|
|
+ if (webSocketSession.isOpen()) {
|
|
|
+ //开启多线程发送消息(效率高)
|
|
|
+ new Thread(new Runnable() {
|
|
|
+ @Override
|
|
|
+ public void run() {
|
|
|
+ try {
|
|
|
+ if (webSocketSession.isOpen()) {
|
|
|
+ webSocketSession.sendMessage(message);
|
|
|
+ }
|
|
|
+ } catch (IOException e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }).start();
|
|
|
+
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
}
|