| | |
| | | package com.moral.api.service.impl; |
| | | |
| | | import com.alibaba.fastjson.JSON; |
| | | import com.alibaba.fastjson.JSONObject; |
| | | import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
| | | import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper; |
| | |
| | | import com.moral.api.service.DeviceService; |
| | | import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
| | | |
| | | import com.moral.api.service.OrganizationService; |
| | | import com.moral.api.service.SysDictDataService; |
| | | import com.moral.api.util.CacheUtils; |
| | | import com.moral.api.util.AdjustDataUtils; |
| | |
| | | import java.beans.PropertyDescriptor; |
| | | import java.lang.reflect.Field; |
| | | import java.lang.reflect.Method; |
| | | import java.util.ArrayList; |
| | | import java.util.LinkedHashMap; |
| | | import java.util.List; |
| | | import java.util.Map; |
| | | import java.util.Objects; |
| | | import java.util.*; |
| | | import java.util.stream.Collectors; |
| | | |
| | | import javax.servlet.http.HttpServletRequest; |
| | | |
| | |
| | | @Autowired |
| | | private SysDictDataService sysDictDataService; |
| | | |
| | | @Autowired |
| | | private LogUtils logUtils; |
| | | |
| | | @Autowired |
| | | private RedisTemplate redisTemplate; |
| | |
| | | |
| | | @Autowired |
| | | private AdjustDataUtils adjustDataUtils; |
| | | |
| | | @Autowired |
| | | private OrganizationService organizationService; |
| | | |
| | | /* |
| | | * 从redis获取设备信息 |
| | |
| | | HttpServletRequest request = ((ServletRequestAttributes) Objects.requireNonNull(RequestContextHolder.getRequestAttributes())).getRequest(); |
| | | StringBuilder content = new StringBuilder(); |
| | | content.append("添加了设备:").append(device.getName()).append(":").append("mac:").append(mac); |
| | | logUtils.saveOperationForManage(request, content.toString(), Constants.INSERT_OPERATE_TYPE); |
| | | LogUtils.saveOperationForManage(request, content.toString(), Constants.INSERT_OPERATE_TYPE); |
| | | } |
| | | |
| | | @Override |
| | |
| | | HttpServletRequest request = ((ServletRequestAttributes) Objects.requireNonNull(RequestContextHolder.getRequestAttributes())).getRequest(); |
| | | StringBuilder content = new StringBuilder(); |
| | | content.append("删除了设备:").append(device.getName()).append(";").append("mac:").append(mac); |
| | | logUtils.saveOperationForManage(request, content.toString(), Constants.DELETE_OPERATE_TYPE); |
| | | LogUtils.saveOperationForManage(request, content.toString(), Constants.DELETE_OPERATE_TYPE); |
| | | } |
| | | |
| | | @Override |
| | |
| | | } |
| | | |
| | | } |
| | | logUtils.saveOperationForManage(request, content.toString(), Constants.UPDATE_OPERATE_TYPE); |
| | | LogUtils.saveOperationForManage(request, content.toString(), Constants.UPDATE_OPERATE_TYPE); |
| | | } |
| | | |
| | | @Override |
| | |
| | | |
| | | @Override |
| | | public List<Map<String, Object>> selectMonitorsByOrgId(Integer orgId) { |
| | | //获取所有子组织 |
| | | List<Organization> organizations = organizationService.getAllChildrenOrganization(orgId); |
| | | List<Integer> orgIds = organizations.stream().map(Organization::getId).collect(Collectors.toList()); |
| | | orgIds.add(orgId); |
| | | QueryWrapper<MonitorPoint> queryWrapper = new QueryWrapper<>(); |
| | | queryWrapper.select("id", "name").eq("organization_id", orgId).eq("is_delete", Constants.NOT_DELETE); |
| | | queryWrapper.select("id", "name") |
| | | .eq("is_delete", Constants.NOT_DELETE) |
| | | .in("organization_id", orgIds); |
| | | return monitorPointMapper.selectMaps(queryWrapper); |
| | | } |
| | | |
| | |
| | | Object orgId = parameters.get("organizationId"); |
| | | Object mpId = parameters.get("monitorPointId"); |
| | | |
| | | //查询某组织下所有设备 |
| | | //查询某组织下所有设备,包括子组织 |
| | | if (orgId != null) { |
| | | queryWrapper.eq("organization_id", orgId); |
| | | //查询所有子组织 |
| | | List<Organization> organizations = organizationService.getAllChildrenOrganization(Integer.parseInt(orgId.toString())); |
| | | List<Integer> orgIds = organizations.stream().map(Organization::getId).collect(Collectors.toList()); |
| | | orgIds.add(Integer.parseInt(orgId.toString())); |
| | | queryWrapper.in("organization_id", orgIds); |
| | | } |
| | | |
| | | //查询某站点下所有设备 |
| | |
| | | queryWrapper.eq("monitor_point_id", mpId); |
| | | } |
| | | |
| | | //设备名模糊查询 |
| | | if (name != null) { |
| | | queryWrapper.like("name", name); |
| | | } |
| | | |
| | | //mac模糊查询 |
| | | if (mac != null) { |
| | | queryWrapper.like("mac", mac); |
| | | //设备名称或mac模糊查询 |
| | | if (name != null && mac != null) { |
| | | queryWrapper.like("name", name).or().like("mac", mac); |
| | | } |
| | | |
| | | //排序参数,默认create_time降序 |
| | |
| | | //扩展字段 |
| | | deviceInfo.put("extend", device.getExtend()); |
| | | |
| | | //乡镇街道信息 |
| | | deviceInfo.put("town", device.getTown()); |
| | | |
| | | //行业 |
| | | deviceInfo.put("profession", device.getProfession()); |
| | | deviceInfo.put("professionName", device.getProfessionName()); |
| | | deviceInfo.put("professions", device.getProfessions()); |
| | | |
| | | //工艺 |
| | | deviceInfo.put("tech", device.getTech()); |
| | |
| | | Map<String, Object> govMpInfo = (Map<String, Object>) deviceInfo.get("govMonitorPoint"); |
| | | Map<String, Object> aqiMap = null; |
| | | if (govMpInfo.get("guid") != null) { |
| | | aqiMap = (Map<String, Object>) redisTemplate.opsForHash().get(RedisConstants.AQI_DATA, govMpInfo.get("guid").toString()); |
| | | aqiMap = (Map<String, Object>) redisTemplate.opsForHash().get(RedisConstants.AQI_DATA, govMpInfo.get("guid").toString()); |
| | | } |
| | | return adjustDataUtils.adjust(deviceData, adjustFormula, ObjectUtils.isEmpty(aqiMap) ? null : aqiMap); |
| | | } |
| | |
| | | deviceMapper.update(null, updateWrapper); |
| | | } |
| | | |
| | | @Override |
| | | public List<Map<String, Object>> selectMonitorPiontAndDeviceByOrgId(int orgId) { |
| | | QueryWrapper<MonitorPoint> monitorPointQueryWrapper = new QueryWrapper<>(); |
| | | monitorPointQueryWrapper.eq("is_delete",Constants.NOT_DELETE); |
| | | monitorPointQueryWrapper.eq("organization_id",orgId); |
| | | List<MonitorPoint> monitorPointList = monitorPointMapper.selectList(monitorPointQueryWrapper); |
| | | List<Map<String, Object>> resultList = new ArrayList<>(); |
| | | for (MonitorPoint monitorPoint:monitorPointList) { |
| | | Map<String,Object> resultMap = new HashMap<>(); |
| | | resultMap = JSON.parseObject(JSON.toJSONString(monitorPoint), Map.class); |
| | | int mp_id = monitorPoint.getId(); |
| | | QueryWrapper<Device> deviceQueryWrapper = new QueryWrapper<>(); |
| | | deviceQueryWrapper.eq("is_delete", Constants.NOT_DELETE); |
| | | deviceQueryWrapper.eq("monitor_point_id",mp_id); |
| | | List<Device> devices = new ArrayList<>(); |
| | | devices = deviceMapper.selectList(deviceQueryWrapper); |
| | | resultMap.put("devices",devices); |
| | | resultList.add(resultMap); |
| | | } |
| | | return resultList; |
| | | } |
| | | |
| | | //根据因子值判断状态 |
| | | private int judgeState(List<Object> levels, Double data) { |
| | | int state = 1; |