人员定位
parent
ebad7908ff
commit
50a8f7b24f
|
@ -0,0 +1,33 @@
|
|||
package com.zcloud.config;
|
||||
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.data.redis.connection.RedisConnectionFactory;
|
||||
import org.springframework.data.redis.core.RedisTemplate;
|
||||
import org.springframework.data.redis.serializer.RedisSerializer;
|
||||
import org.springframework.data.redis.serializer.StringRedisSerializer;
|
||||
|
||||
@Configuration
|
||||
public class MyRedisConfig {
|
||||
|
||||
@Bean(name = "redisTemplate")
|
||||
public RedisTemplate redisTemplate(RedisConnectionFactory redisConnectionFactory){
|
||||
RedisTemplate redisTemplate = new RedisTemplate<>();
|
||||
////参照StringRedisTemplate内部实现指定序列化器
|
||||
redisTemplate.setConnectionFactory(redisConnectionFactory);
|
||||
redisTemplate.setKeySerializer(keySerializer());
|
||||
redisTemplate.setHashKeySerializer(keySerializer());
|
||||
redisTemplate.setValueSerializer(valueSerializer());
|
||||
redisTemplate.setHashValueSerializer(valueSerializer());
|
||||
return redisTemplate;
|
||||
}
|
||||
|
||||
private RedisSerializer keySerializer(){
|
||||
return new StringRedisSerializer();
|
||||
}
|
||||
|
||||
//使用Jackson序列化器
|
||||
private RedisSerializer valueSerializer(){
|
||||
return new StringRedisSerializer();
|
||||
}
|
||||
}
|
|
@ -1,5 +1,6 @@
|
|||
package com.zcloud.config;
|
||||
|
||||
import com.zcloud.plugins.websocketPositioning.PositioningServer;
|
||||
import org.java_websocket.WebSocketImpl;
|
||||
import org.springframework.boot.ApplicationArguments;
|
||||
import org.springframework.boot.ApplicationRunner;
|
||||
|
@ -20,14 +21,15 @@ import com.zcloud.util.PathUtil;
|
|||
@Component
|
||||
@Order(value = 1) // 1 代表启动顺序
|
||||
public class StartWebsocketServer implements ApplicationRunner{
|
||||
|
||||
|
||||
@Override
|
||||
public void run(ApplicationArguments var1) throws Exception{
|
||||
startWebsocketOnline(); //启动在线管理服务
|
||||
startWebsocketInstantMsg(); //启动即时聊天服务
|
||||
startWebsocketPositioning();
|
||||
System.out.println("-------------------系统启动成功-------------------");
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 启动在线管理服务
|
||||
*/
|
||||
|
@ -43,7 +45,7 @@ public class StartWebsocketServer implements ApplicationRunner{
|
|||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 启动即时聊天服务
|
||||
*/
|
||||
|
@ -60,4 +62,20 @@ public class StartWebsocketServer implements ApplicationRunner{
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 启动即时人员定位推送
|
||||
*/
|
||||
public void startWebsocketPositioning(){
|
||||
WebSocketImpl.DEBUG = false;
|
||||
PositioningServer s;
|
||||
try {
|
||||
String infFilePath = PathUtil.getClasspath()+Const.SYSSET; //启动即时人员定位推送
|
||||
String positioningPort = IniFileUtil.readCfgValue(infFilePath, "SysSet1", "positioningPort", "8899"); //启动即时人员定位推送
|
||||
s = new PositioningServer(Integer.parseInt(positioningPort));
|
||||
s.start();
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -108,7 +108,9 @@ public class HeadController extends BaseController {
|
|||
String alarmIp = IniFileUtil.readCfgValue(infFilePath, "SysSet1", "alarmIp", "127.0.0.1"); //即时聊天IP
|
||||
String alarmPort = IniFileUtil.readCfgValue(infFilePath, "SysSet1", "alarmPort", "8889"); //即时聊天端口
|
||||
map.put("alarmAdress", alarmIp+":"+alarmPort); //重大危险源报警推送websocket地址
|
||||
|
||||
String positioningIP = IniFileUtil.readCfgValue(infFilePath, "SysSet1", "positioningIP", "127.0.0.1"); //即时聊天IP
|
||||
String positioningPort = IniFileUtil.readCfgValue(infFilePath, "SysSet1", "positioningPort", "8899"); //即时聊天端口
|
||||
map.put("positioningAdress", positioningIP+":"+positioningPort); //即时聊天websocket地址
|
||||
String sysName = IniFileUtil.readCfgValue(infFilePath, "SysSet1", Const.SYSNAME, "双重预防机制建设"); //系统名称
|
||||
map.put(Const.SYSNAME, sysName);
|
||||
|
||||
|
@ -142,6 +144,7 @@ public class HeadController extends BaseController {
|
|||
String infFilePath = PathUtil.getClasspath()+Const.SYSSET; //配置文件路径
|
||||
String onlineIp = IniFileUtil.readCfgValue(infFilePath, "SysSet1", "onlineIp", "127.0.0.1"); //在线管理IP
|
||||
String onlinePort = IniFileUtil.readCfgValue(infFilePath, "SysSet1", "onlinePort", "8869"); //在线管理端口
|
||||
|
||||
map.put("fhsmsSound", IniFileUtil.readCfgValue(infFilePath, "SysSet1", "fhsmsSound", "1")); //信息提示音
|
||||
map.put("onlineAdress", onlineIp+":"+onlinePort); //在线管理websocket地址
|
||||
map.put("result", errInfo);
|
||||
|
@ -251,6 +254,8 @@ public class HeadController extends BaseController {
|
|||
pd.put("onlinePort", IniFileUtil.readCfgValue(infFilePath, "SysSet1", "onlinePort", "8869")); //在线管理端口
|
||||
pd.put("imIp", IniFileUtil.readCfgValue(infFilePath, "SysSet1", "imIp", "127.0.0.1")); //即时聊天IP
|
||||
pd.put("imPort", IniFileUtil.readCfgValue(infFilePath, "SysSet1", "imPort", "8879")); //即时聊天端口
|
||||
|
||||
pd.put("positioningPort", IniFileUtil.readCfgValue(infFilePath, "SysSet1", "positioningPort", "8899")); //即时聊天端口
|
||||
pd.put("fhsmsSound", IniFileUtil.readCfgValue(infFilePath, "SysSet1", "fhsmsSound", "m1")); //信息提示音
|
||||
pd.put("SMTP", IniFileUtil.readCfgValue(infFilePath, "SysSet1", "SMTP", "smtp.qq.com")); //邮箱服务器SMTP
|
||||
pd.put("PORT", IniFileUtil.readCfgValue(infFilePath, "SysSet1", "PORT", "465")); //邮箱服务器端口
|
||||
|
|
|
@ -309,4 +309,6 @@ public interface UsersMapper {
|
|||
PageData countAllByArea(PageData pd);
|
||||
|
||||
PageData findByCardNo(PageData pd);
|
||||
void updateCardNoByPhone(String phone, String cardId);
|
||||
|
||||
}
|
||||
|
|
|
@ -0,0 +1,53 @@
|
|||
package com.zcloud.plugins.websocketPositioning;
|
||||
|
||||
import org.java_websocket.WebSocket;
|
||||
import org.java_websocket.WebSocketImpl;
|
||||
import org.java_websocket.handshake.ClientHandshake;
|
||||
import org.java_websocket.server.WebSocketServer;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.net.InetSocketAddress;
|
||||
|
||||
/**
|
||||
* 人员的定位
|
||||
*/
|
||||
public class PositioningServer extends WebSocketServer {
|
||||
|
||||
public PositioningServer(int port) {
|
||||
super(new InetSocketAddress(port));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onOpen(WebSocket conn, ClientHandshake handshake) {
|
||||
PositioningServerPool.addUser(null,conn);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onClose(WebSocket conn, int code, String reason, boolean remote) {
|
||||
PositioningServerPool.remove(conn);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onMessage(WebSocket conn, String message) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onError(WebSocket conn, Exception ex) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onStart() {
|
||||
|
||||
}
|
||||
|
||||
public static void main( String[] args ) throws InterruptedException , IOException {
|
||||
WebSocketImpl.DEBUG = false;
|
||||
int port = 8899; //端口
|
||||
PositioningServer s = new PositioningServer(port);
|
||||
s.start();
|
||||
System.out.println( "服务器的端口" + s.getPort() );
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,41 @@
|
|||
package com.zcloud.plugins.websocketPositioning;
|
||||
|
||||
import org.java_websocket.WebSocket;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
public class PositioningServerPool {
|
||||
|
||||
private static final Map<WebSocket,String> userconnections = new HashMap<WebSocket,String>();
|
||||
|
||||
/**
|
||||
* 向连接池中添加连接
|
||||
* @param inbound
|
||||
*/
|
||||
public static void addUser(String user, WebSocket conn){
|
||||
userconnections.put(conn,user); //添加连接
|
||||
}
|
||||
|
||||
/**
|
||||
* 向所有的用户发送消息
|
||||
* @param message
|
||||
*/
|
||||
public static void sendMessage(String message){
|
||||
Set<WebSocket> keySet = userconnections.keySet();
|
||||
for (WebSocket conn : keySet) {
|
||||
conn.send(message);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 移除
|
||||
* @param conn
|
||||
*/
|
||||
public static void remove(WebSocket conn){
|
||||
userconnections.remove(conn);
|
||||
}
|
||||
|
||||
|
||||
}
|
|
@ -0,0 +1,11 @@
|
|||
package com.zcloud.service.bus;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public interface PositioningService {
|
||||
|
||||
public List<String> findRedisAll();
|
||||
|
||||
void syncCardNo() throws Exception;
|
||||
|
||||
}
|
|
@ -0,0 +1,53 @@
|
|||
package com.zcloud.service.bus.impl;
|
||||
|
||||
import com.alibaba.fastjson.JSONArray;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.zcloud.service.bus.PositioningService;
|
||||
import com.zcloud.service.system.UsersService;
|
||||
import com.zcloud.util.HttpRequestUtil;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.data.redis.core.RedisTemplate;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
@Service(value="iPositioningServiceImpl")
|
||||
public class PositioningServiceImpl implements PositioningService {
|
||||
|
||||
@Autowired
|
||||
private RedisTemplate redisTemplate;
|
||||
|
||||
@Autowired
|
||||
private UsersService usersService;
|
||||
|
||||
@Value("${perLoc.url}")
|
||||
private String perLocUrl;
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
public List<String> findRedisAll() {
|
||||
Set<String> keys = redisTemplate.keys("synchronous".concat("*"));
|
||||
return redisTemplate.opsForValue().multiGet(keys);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void syncCardNo() throws Exception {
|
||||
String _response = HttpRequestUtil.doGet(perLocUrl + "/mapi/v1/queryWorkCardLocation");
|
||||
JSONObject responseResult = JSONObject.parseObject(_response);
|
||||
JSONArray jsonArray = responseResult.getJSONArray("data");
|
||||
for (int i = 0; i < jsonArray.size() ; i++) {
|
||||
JSONObject jsonObject = jsonArray.getJSONObject(i);
|
||||
if (
|
||||
StringUtils.isNotBlank(jsonObject.getString("phone"))
|
||||
&& StringUtils.isNotBlank(jsonObject.getString("cardId"))
|
||||
) {
|
||||
usersService.updateCardNoByPhone(jsonObject.getString("phone"), jsonObject.getString("cardId"));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -367,4 +367,7 @@ public interface UsersService {
|
|||
PageData getPersonByCardNo(PageData pd) throws Exception;
|
||||
|
||||
PageData findByCardNo(PageData pd) throws Exception;
|
||||
|
||||
|
||||
void updateCardNoByPhone(String phone, String cardId);
|
||||
}
|
||||
|
|
|
@ -504,6 +504,10 @@ public class UsersServiceImpl implements UsersService {
|
|||
return usersMapper.findByCardNo(pd);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateCardNoByPhone(String phone, String cardId) {
|
||||
usersMapper.updateCardNoByPhone(phone, cardId);
|
||||
}
|
||||
@Override
|
||||
public Object getCurrentLocation(PageData pd) {
|
||||
// Map<String,Object> map = new HashMap<String,Object>();
|
||||
|
|
|
@ -40,6 +40,7 @@ public class MD5 {
|
|||
}
|
||||
public static void main(String[] args) {
|
||||
System.out.println(new SimpleHash("SHA-1", "卓云企业", Const.DEFAULT_PASSWORD).toString());
|
||||
System.out.println(md5("_Ab54321"));
|
||||
// System.out.println(md5("mj1"));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,41 @@
|
|||
package com.zcloud.util;
|
||||
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.zcloud.plugins.websocketPositioning.PositioningServerPool;
|
||||
import com.zcloud.service.bus.PositioningService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.scheduling.annotation.Scheduled;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
@Component
|
||||
public class PositioningScheduled {
|
||||
|
||||
@Autowired
|
||||
private PositioningService positioningService;
|
||||
|
||||
@Scheduled(cron ="0/10 * * * * ? ")
|
||||
public void syncPositioning(){
|
||||
try {
|
||||
System.out.println("==========定时发送人员定位信息==========");
|
||||
List<String> varList = positioningService.findRedisAll();
|
||||
PositioningServerPool.sendMessage(varList.toString());
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
@Scheduled(cron ="0 0 2 * * ? ") // 凌晨两点
|
||||
public void syncCardNo(){
|
||||
try {
|
||||
System.out.println("==========定时同步定位卡号==========");
|
||||
positioningService.syncCardNo();
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -29,3 +29,8 @@ imPort=8879
|
|||
alarmIp=192.168.210.7
|
||||
;重大危险源报警推送端口
|
||||
alarmPort=8889
|
||||
|
||||
;人员定位
|
||||
alarmIp=172.16.11.146
|
||||
;人员定位
|
||||
alarmPort=8899
|
||||
|
|
|
@ -1426,4 +1426,13 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
|||
where
|
||||
u.CARDNO = #{CARDNO}
|
||||
</select>
|
||||
|
||||
|
||||
|
||||
<update id="updateCardNoByPhone">
|
||||
update sys_user
|
||||
set CARDNO = #{cardId}
|
||||
where USERNAME = #{phone}
|
||||
</update>
|
||||
|
||||
</mapper>
|
||||
|
|
Loading…
Reference in New Issue