| | |
| | | package com.moral.service.impl;
|
| | |
|
| | | import java.util.*;
|
| | | import java.util.ArrayList;
|
| | | import java.util.Arrays;
|
| | | import java.util.Date;
|
| | | import java.util.HashMap;
|
| | | import java.util.List;
|
| | | import java.util.Map;
|
| | | import java.util.stream.Collectors;
|
| | |
|
| | | import javax.annotation.Resource;
|
| | | import javax.validation.constraints.NotNull;
|
| | |
|
| | | import com.alibaba.fastjson.TypeReference;
|
| | | import com.github.pagehelper.Page;
|
| | | import com.moral.common.bean.Constants;
|
| | | import com.moral.common.bean.PageBean;
|
| | | import com.moral.common.bean.PageResult;
|
| | | import com.moral.common.exception.BusinessException;
|
| | | import com.moral.common.util.ExampleUtil;
|
| | | import com.moral.common.util.RedisUtils;
|
| | | import com.moral.entity.DeviceVersion;
|
| | | import com.moral.mapper.*;
|
| | | import org.apache.commons.collections.MapUtils;
|
| | | import org.apache.commons.lang3.BooleanUtils;
|
| | | import org.apache.commons.lang3.StringUtils;
|
| | |
| | | import org.springframework.transaction.annotation.Transactional;
|
| | | import org.springframework.util.ObjectUtils;
|
| | |
|
| | | import com.alibaba.fastjson.TypeReference;
|
| | | import com.github.pagehelper.Page;
|
| | | import com.github.pagehelper.PageHelper;
|
| | | import com.moral.common.bean.Constants;
|
| | | import com.moral.common.bean.PageBean;
|
| | | import com.moral.common.bean.PageResult;
|
| | | import com.moral.common.exception.BusinessException;
|
| | | import com.moral.common.util.ExampleUtil;
|
| | | import com.moral.common.util.RedisUtils;
|
| | | import com.moral.common.util.ValidateUtil;
|
| | | import com.moral.entity.Device;
|
| | | import com.moral.entity.DeviceProperty;
|
| | | import com.moral.mapper.DeviceMapper;
|
| | | import com.moral.mapper.DevicePropertyMapper;
|
| | | import com.moral.mapper.DeviceVersionMapper;
|
| | | import com.moral.mapper.DictionaryDataMapper;
|
| | | import com.moral.mapper.MonitorPointMapper;
|
| | | import com.moral.mapper.OrganizationMapper;
|
| | | import com.moral.service.AccountService;
|
| | | import com.moral.service.DeviceService;
|
| | |
|
| | | import tk.mybatis.mapper.entity.Example;
|
| | |
|
| | | @Service
|
| | |
| | | Device device = getDeviceFromRedis(mac);
|
| | | if(device==null) {
|
| | | device = deviceMapper.selectWithOrgIdsByMac(mac);
|
| | | if(device!=null){
|
| | | setDeviceToRedis(mac,device);
|
| | | }
|
| | | }
|
| | | return device;
|
| | | }else {
|
| | |
| | | private String getDeviceKey(String mac) {
|
| | | return keysConnect(DEVICE,mac);
|
| | | }
|
| | | /*
|
| | | * 将校正值存入redis方法组 开始
|
| | | */
|
| | | private void setDeviceToRedis(String mac,Device device){
|
| | | String key = getDeviceKey(mac);
|
| | | Device simpleDevice = new Device();
|
| | | simpleDevice.setId(device.getId());// id
|
| | | simpleDevice.setName(device.getName());// name
|
| | | simpleDevice.setAddress(device.getAddress());// address
|
| | | simpleDevice.setDeviceVersionId(device.getDeviceVersionId());// version
|
| | | simpleDevice.setMac(device.getMac()); // mac
|
| | | simpleDevice.setMonitorPointId(device.getMonitorPointId());// 监控地id
|
| | | simpleDevice.setOrganizationIds(device.getOrganizationIds());// 组织数组
|
| | | simpleDevice.setDeviceVersion(device.getDeviceVersion());
|
| | | redisUtils.set(key,simpleDevice);
|
| | | }
|
| | | // /*
|
| | | // * 将校正值存入redis方法组 开始
|
| | | // */
|
| | | // private void setDeviceToRedis(String mac,Device device){
|
| | | // String key = getDeviceKey(mac);
|
| | | // Device simpleDevice = new Device();
|
| | | // simpleDevice.setId(device.getId());// id
|
| | | // simpleDevice.setName(device.getName());// name
|
| | | // simpleDevice.setAddress(device.getAddress());// address
|
| | | // simpleDevice.setDeviceVersionId(device.getDeviceVersionId());// version
|
| | | // simpleDevice.setMac(device.getMac()); // mac
|
| | | // simpleDevice.setMonitorPointId(device.getMonitorPointId());// 监控地id
|
| | | // simpleDevice.setOrganizationIds(device.getOrganizationIds());// 组织数组
|
| | | // simpleDevice.setDeviceVersion(device.getDeviceVersion());
|
| | | // redisUtils.set(key,simpleDevice);
|
| | | // }
|
| | | private Device getDeviceFromRedis(String mac) {
|
| | | String key = getDeviceKey(mac);
|
| | | return redisUtils.get(key,Device.class);
|
| | |
| | |
|
| | | /**
|
| | | * 要在数据库更改后刷新
|
| | | * 刷新 redis 设备的信息
|
| | | * 刷新 redis 设备的信息,注意此处指删除不做更新。更新由task完成
|
| | | * @param mac
|
| | | */
|
| | | private void refreshDeviceInRedis(String mac){
|
| | | if(!StringUtils.isBlank(mac)){
|
| | | Device device = deviceMapper.selectWithOrgIdsByMac(mac);
|
| | | setDeviceToRedis(mac,device);
|
| | | String key = getDeviceKey(mac);
|
| | | redisUtils.remove(key);
|
| | | }else
|
| | | {
|
| | | log.warn("param mac is null in method [refreshDeviceInRedis]");
|
| | |
| | | result.put("stop", stop);
|
| | | return result;
|
| | | }
|
| | |
|
| | | @Resource
|
| | | private DevicePropertyMapper devicePropertyMapper;
|
| | | |
| | | @Override
|
| | | @Transactional
|
| | | public void saveOrUpdate(Device device, DeviceProperty deviceProperty) {
|
| | | if (ObjectUtils.isEmpty(device.getId())) {
|
| | | device.setState(Constants.DEVICE_STATE_OFFLINE);
|
| | | device.setIsDelete(Constants.IS_DELETE_FALSE);
|
| | | deviceMapper.insertSelective(device);
|
| | | deviceProperty.setId(device.getId());
|
| | | } else {
|
| | | deviceMapper.updateByPrimaryKeySelective(device);
|
| | | devicePropertyMapper.deleteByPrimaryKey(deviceProperty);
|
| | | }
|
| | | devicePropertyMapper.insertSelective(deviceProperty);
|
| | | refreshDeviceInRedis(device.getMac());
|
| | |
|
| | | }
|
| | | |
| | | @Override
|
| | | public PageBean getDeviceList(PageBean pageBean) {
|
| | | Example example = ExampleUtil.generateExample(ENTITY_CLASS,pageBean);
|
| | | if(pageBean.getPageSize()>0){
|
| | | PageHelper.startPage(pageBean.getPageIndex(),pageBean.getPageSize());
|
| | | }
|
| | | List<Device> deviceList = deviceMapper.getDeviceList(example);
|
| | | return new PageBean(deviceList);
|
| | | }
|
| | |
|
| | | }
|