| | |
| | | private void loadDeviceState(List<Device> list){
|
| | | //从redis里取状态
|
| | | list.stream().map( device -> {
|
| | | String mac = Optional.of(device.getMac()).get();
|
| | | String mac = device.getMac();
|
| | | if(!StringUtils.isBlank(mac)){
|
| | | String state = getSateFromRedis(device.getMonitorPointId(),mac.toLowerCase());
|
| | | device.setState(state);
|
| | | }else{
|
| | | device.setState(Constants.DEVICE_STATE_OFFLINE);
|
| | | }
|
| | | return device;
|
| | | }).count();
|
| | | }
|
| | |
| | | @Override
|
| | | public List<Map<String,String>> queryDevicesState(List<String> macList,Boolean withData) {
|
| | | List<Map<String,String>> list = macList.stream().map(mac->{
|
| | | Map<String,String> resultMap = new HashMap<>();
|
| | | if(!StringUtils.isBlank(mac)){
|
| | | mac = mac.toLowerCase();
|
| | | Device device = getDeviceWithOrgIdsByMac(mac);
|
| | | Map<String,String> resultMap = new HashMap<>();
|
| | | Map<String,String> stateMap = getStateMapFromRedis(device.getMonitorPointId(),mac);
|
| | | if(!MapUtils.isEmpty(stateMap)){
|
| | | resultMap.putAll(stateMap);
|
| | |
| | | resultMap.put("state",Constants.DEVICE_STATE_OFFLINE);
|
| | | resultMap.put("mac",mac);
|
| | | }
|
| | | //添加data
|
| | | if(BooleanUtils.isTrue(withData)){
|
| | | String dataKey = "data_"+mac;
|
| | | Map<String,String> dataMap = redisUtils.get(dataKey,new TypeReference<Map<String,String>>(){});
|
| | |
| | | resultMap.putAll(dataMap);
|
| | | }
|
| | | }
|
| | | }
|
| | | return resultMap;
|
| | | }).collect(Collectors.toList());
|
| | | return list;
|
| | |
| | | </association> |
| | | <association property="deviceVersion" javaType="com.moral.entity.DeviceVersion"> |
| | | <result column="device_version_id" property="id" jdbcType="INTEGER" /> |
| | | <result column="device_version_value" property="version" jdbcType="INTEGER" /> |
| | | <result column="device_version_name" property="name" jdbcType="VARCHAR" /> |
| | | </association> |
| | | <association property="monitorPoint" javaType="com.moral.entity.MonitorPoint"> |
| | |
| | | AND device_version_id = #{deviceVersionId} |
| | | </select> |
| | | <select id="selectByOrgIdAndDevName" resultMap="BaseResultMap"> |
| | | SELECT * from device dev |
| | | SELECT dev.*,dve.version as device_version_value from device dev |
| | | left join monitor_point mpt on dev.monitor_point_id = mpt.id |
| | | left join device_version dve on dev.device_version_id = dve.id |
| | | <where> |
| | | <if test="@com.moral.common.bean.Constants@isNotSpecialOrgId(orgId)"> |
| | | mpt.organization_id = #{orgId} |
| | |
| | | </where> |
| | | </select> |
| | | <select id="selectByOrgIdAndMpId" resultMap="BaseResultMap"> |
| | | SELECT * from device dev |
| | | SELECT dev.*,dve.version as device_version_value from device dev |
| | | left join monitor_point mpt on dev.monitor_point_id = mpt.id |
| | | left join device_version dve on dev.device_version_id = dve.id |
| | | <where> |
| | | <if test="@com.moral.common.bean.Constants@isNotSpecialOrgId(orgId)"> |
| | | mpt.organization_id = #{orgId} |
| | |
| | | /* |
| | | * 根据mac地址获取version |
| | | */ |
| | | moralMap.getVersion = function(mac){ |
| | | var version = null; |
| | | $.ajax({ |
| | | type:"get", |
| | | url:"getversion?mac="+mac, |
| | | async:false, |
| | | success:function(jsonData){ |
| | | if(jsonData!=null&&typeof jsonData=='object'){ |
| | | version = jsonData['version']; |
| | | } |
| | | } |
| | | }); |
| | | return version; |
| | | } |
| | | // moralMap.getVersion = function(mac){ |
| | | // var version = null; |
| | | // $.ajax({ |
| | | // type:"get", |
| | | // url:"getversion?mac="+mac, |
| | | // async:false, |
| | | // success:function(jsonData){ |
| | | // if(jsonData!=null&&typeof jsonData=='object'){ |
| | | // version = jsonData['version']; |
| | | // } |
| | | // } |
| | | // }); |
| | | // return version; |
| | | // } |
| | | /* |
| | | * 百度地图初始化 |
| | | */ |
| | |
| | | mac: (row['mac']).toLowerCase(), |
| | | longitude: row['longitude'], |
| | | latitude: row['latitude'], |
| | | version:moralMap.getVersion(row['mac']) |
| | | version:row['deviceVersion']['version'] |
| | | } |
| | | var equStr = JSON.stringify(equ); |
| | | if(window["console"]!=undefined){ |
| | |
| | | } |
| | | //储存MonitorPoint对象 |
| | | moralMap.putEquipment = function(key, obj) { |
| | | if(key!=null&&key!=""){ |
| | | key = String.prototype.toLowerCase.call(key); |
| | | if(moralMap['_equipments'] == undefined) { |
| | | moralMap['_equipments'] = {}; |
| | | } |
| | | moralMap['_equipments'][key] = obj; |
| | | } |
| | | } |
| | | moralMap.getEquipment = function(key) { |
| | | if(key == null){ |
| | | return null; |
| | |
| | | mac: (_obj['mac']).toLowerCase(), |
| | | longitude: _obj['longitude'], |
| | | latitude: _obj['latitude'], |
| | | version:moralMap.getVersion(_obj['mac']) |
| | | version:_obj['deviceVersion']['version'] |
| | | } |
| | | var equStr = JSON.stringify(equ); |
| | | if(window["console"]!=undefined){ |