| | |
| | |
|
| | | import javax.annotation.Resource;
|
| | |
|
| | | import org.apache.commons.collections.CollectionUtils;
|
| | | import org.springframework.stereotype.Service;
|
| | |
|
| | | import com.github.pagehelper.PageHelper;
|
| | | import com.moral.common.bean.Constants;
|
| | | import com.moral.common.bean.PageBean;
|
| | | import com.moral.common.util.*;
|
| | | import org.springframework.stereotype.Service;
|
| | |
|
| | | import com.moral.common.util.ExampleUtil;
|
| | | import com.moral.common.util.RedisUtils;
|
| | | import com.moral.common.util.StringUtils;
|
| | | import com.moral.common.util.ValidateUtil;
|
| | | import com.moral.entity.Device;
|
| | | import com.moral.entity.MonitorPoint;
|
| | | import com.moral.mapper.DeviceMapper;
|
| | | import com.moral.mapper.MonitorPointMapper;
|
| | | import com.moral.service.MonitorPointService;
|
| | |
|
| | | import tk.mybatis.mapper.entity.Example;
|
| | | import tk.mybatis.mapper.entity.Example.Criteria;
|
| | |
|
| | |
| | | public class MonitorPointServiceImpl implements MonitorPointService {
|
| | | @Resource
|
| | | private MonitorPointMapper monitorPointMapper;
|
| | | @Resource
|
| | | private DeviceMapper deviceMapper;
|
| | | @Resource
|
| | | RedisUtils redisUtils;
|
| | | private static Class ENTITY_CLASS = MonitorPoint.class;
|
| | |
| | | monitorPointMapper.insertSelective(monitorPoint);
|
| | | }else{
|
| | | monitorPointMapper.updateByPrimaryKeySelective(monitorPoint);
|
| | | // 刷新当前监控点下设备 在redis里设备信息
|
| | | refreshDevicesInRedis(monitorPoint.getId());
|
| | | }
|
| | | }
|
| | | catch (Exception ex){
|
| | | throw ex;
|
| | | }
|
| | | }
|
| | | /*
|
| | | 刷新当前监控点下设备 在redis里设备信息
|
| | | */
|
| | | private void refreshDevicesInRedis(int monitorPointId){
|
| | | Device device = new Device();
|
| | | device.setMonitorPointId(monitorPointId);
|
| | | List<Device> deviceList = deviceMapper.select(device);
|
| | | if (!CollectionUtils.isEmpty(deviceList)){
|
| | | List<Integer> orgIds = monitorPointMapper.selectOrganizationIds(monitorPointId);
|
| | | if (!CollectionUtils.isEmpty(orgIds)){
|
| | | deviceList.stream().forEach(dev ->{
|
| | | if(!StringUtils.isNullOrEmpty(dev.getMac())){
|
| | | String key = "device_"+dev.getMac();
|
| | | // 简化的设备信息 用以缓存redis
|
| | | Device simpleDevice = new Device();
|
| | | simpleDevice.setId(dev.getId());
|
| | | simpleDevice.setDeviceVersion(dev.getDeviceVersion());
|
| | | simpleDevice.setMac(dev.getMac());
|
| | | simpleDevice.setMonitorPointId(dev.getMonitorPointId());
|
| | | // 设置新组织关系,防止读写分离时数据库同步延迟
|
| | | simpleDevice.setOrganizationIds(orgIds);
|
| | | redisUtils.set(key,simpleDevice);
|
| | | }
|
| | | });
|
| | | }
|
| | | }
|
| | |
|
| | | }
|
| | | @Override
|
| | | public void deleteByIds(Integer... ids) {
|
| | | MonitorPoint monitorPoint = new MonitorPoint();
|
| | |
| | | }).collect(Collectors.toList());
|
| | | return list;
|
| | | }
|
| | |
|
| | | @Override
|
| | | public List<MonitorPoint> getMonitorPointsByOrganizationId(Integer orgId) {
|
| | | Example example = new Example(MonitorPoint.class);
|
| | | Criteria criteria = example.createCriteria();
|
| | | |
| | | criteria.andEqualTo("isDelete", Constants.IS_DELETE_FALSE);
|
| | | if (Constants.isNotSpecialOrgId(orgId)) {
|
| | | criteria.andEqualTo("organizationId", orgId);
|
| | | }
|
| | | example.orderBy("name").asc();
|
| | | return monitorPointMapper.selectByExample(example);
|
| | | }
|
| | | }
|