| | |
| | | @GetMapping("mointorPointRank")
|
| | | @ApiOperation(value = "获取站点排名", notes = "获取站点排名")
|
| | | @ApiImplicitParams(value = {
|
| | | @ApiImplicitParam(name = "accountId", value = "账号id", required = true, paramType = "query", dataType = "String")
|
| | | @ApiImplicitParam(name = "accountId", value = "账号id", required = true, paramType = "query", dataType = "String"),
|
| | | @ApiImplicitParam(name = "sensor", value = "因子", required = true, paramType = "query", dataType = "String")
|
| | | })
|
| | | public ResultBean<Map<String, Object>> getMointorPointRank(HttpServletRequest request){
|
| | | public ResultBean<List<Map<String, Object>>> getMointorPointRank(HttpServletRequest request){
|
| | | Map<String, Object> parameters = WebUtils.getParametersStartingWith(request, null);
|
| | | String id = parameters.get("accountId").toString();
|
| | | String sensor = parameters.get("sensor").toString();
|
| | | Map<String, Object> account = accountService.getOrganizationIdByAccountId(id);
|
| | | //通过组织id来获取站点和设备信息
|
| | | System.out.println(account);
|
| | | historyService.getMointorPointRankByOrganizationId(account);
|
| | | return new ResultBean<Map<String, Object>>(account);
|
| | | account.put("sensor", sensor);
|
| | | List<Map<String, Object>> returnList = historyService.getMointorPointRankByOrganizationId(account);
|
| | | return new ResultBean<List<Map<String, Object>>>(returnList);
|
| | | }
|
| | |
|
| | | }
|
| | |
| | | Map<String, Object> getAVGValueByMacAndTimeslot(@Param("mac")String mac, @Param("starttime")String starttime, @Param("endtime")String endtime);
|
| | |
|
| | | List<Map<String, Object>> getSensorDataToday(Map<String, Object> parameters);
|
| | | |
| | | List<Map<String, Object>> getAVGSensorRankByMonitorPointIdList(@Param("sensor")String sensor, @Param("monitorPointIdList") List<Object> monitorPointIdList, @Param("before5Time")String before5Time, @Param("endTime")String endTime);
|
| | |
|
| | | } |
| | |
| | |
|
| | | import java.util.List;
|
| | | import java.util.Map;
|
| | |
|
| | | import org.apache.ibatis.annotations.Param;
|
| | |
|
| | | import com.moral.common.mapper.BaseMapper;
|
| | | import com.moral.entity.MonitorPoint;
|
| | | import tk.mybatis.mapper.entity.Example;
|
| | |
| | | List<Integer> selectOrganizationIds(int id);
|
| | | List<Integer> selectVersionsById(int id);
|
| | | Map<String, Object> selectAllById(int id);
|
| | | List<Map<String, Object>> getIdByOrganizationId(@Param("organizationIdList") List<Object> organizationIdList);
|
| | | } |
| | |
| | |
|
| | | Map<String, Object> gitHourlyAQIByMacAndTimeslot(Map<String, Object> parameters);
|
| | |
|
| | | Map<String, Object> getMointorPointRankByOrganizationId(Map<String, Object> parameters);
|
| | | List<Map<String, Object>> getMointorPointRankByOrganizationId(Map<String, Object> parameters);
|
| | |
|
| | | }
|
| | |
| | | package com.moral.service.impl;
|
| | |
|
| | | import java.text.SimpleDateFormat;
|
| | | import java.time.Instant;
|
| | | import java.time.LocalDate;
|
| | | import java.time.LocalDateTime;
|
| | |
| | | import com.moral.entity.Sensor;
|
| | | import com.moral.mapper.DeviceMapper;
|
| | | import com.moral.mapper.HistoryMapper;
|
| | | import com.moral.mapper.MonitorPointMapper;
|
| | | import com.moral.mapper.OrganizationRelationMapper;
|
| | | import com.moral.mapper.SensorMapper;
|
| | | import com.moral.mapper.SensorUnitMapper;
|
| | |
| | |
|
| | | @Resource
|
| | | private OrganizationRelationMapper organizationRelationMapper;
|
| | | |
| | | @Resource
|
| | | private MonitorPointMapper monitorPointMapper;
|
| | |
|
| | | @Override
|
| | | public Map<String, Object> getAllSensorAverageByDevice(Map<String, Object> parameters) throws Exception {
|
| | |
| | | }
|
| | |
|
| | | @Override
|
| | | public Map<String, Object> getMointorPointRankByOrganizationId(Map<String, Object> parameters) {
|
| | | public List<Map<String, Object>> getMointorPointRankByOrganizationId(Map<String, Object> parameters) {
|
| | | //获取组织id
|
| | | String organizationId = parameters.get("organization_id").toString();
|
| | | //声明一个集合存放要查询站点数据的组织id
|
| | |
| | | for(int i=0;i<10;i++) {
|
| | | if(!parentIdList.isEmpty()) {
|
| | | //或去该组织下的子组织
|
| | | System.out.println("parentIdList:"+parentIdList);
|
| | | List<Map<String, Object>> childIdList = organizationRelationMapper.getChildIdByParentId(parentIdList);
|
| | | //清空父组织id集合
|
| | | parentIdList.clear();
|
| | | System.out.println("childIdList:"+childIdList);
|
| | | //将子组织id放入到集合中
|
| | | for (Map<String, Object> map : childIdList) {
|
| | | organizationIdList.add(map.get("child_id"));
|
| | |
| | | }
|
| | | System.out.println(organizationIdList);
|
| | |
|
| | | return null;
|
| | | //根据组织id获取站点id
|
| | | List<Map<String, Object>> monitorPointIdListMap = monitorPointMapper.getIdByOrganizationId(organizationIdList);
|
| | | //将List<Map<String, Object>>装换为List<Object>
|
| | | List<Object> monitorPointIdList = new ArrayList<>();
|
| | | for (Map<String, Object> map : monitorPointIdListMap) {
|
| | | monitorPointIdList.add(map.get("id"));
|
| | | }
|
| | | |
| | | //通过站点id获取设备因子的排名
|
| | | //获取系统当前时间
|
| | | Calendar rightNow = Calendar.getInstance();
|
| | | //获取五分钟前的时间
|
| | | Calendar beforeTime = Calendar.getInstance();
|
| | | beforeTime.add(Calendar.MINUTE, -5);// 5分钟之前的时间
|
| | | Date beforeD = beforeTime.getTime();
|
| | | Date end = rightNow.getTime();
|
| | | String endTime = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(end);
|
| | | String before5Time = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(beforeD); // 前五分钟时间
|
| | | |
| | | String sensor = parameters.get("sensor").toString();
|
| | | List<Map<String, Object>> result = historyMapper.getAVGSensorRankByMonitorPointIdList(sensor, monitorPointIdList, before5Time, endTime);
|
| | | return result;
|
| | | }
|
| | | }
|
| | |
| | | ORDER BY
|
| | | time
|
| | | </select>
|
| | | |
| | | <select id="getAVGSensorRankByMonitorPointIdList" resultType="java.util.Map">
|
| | | SELECT mp.name, AVG(JSON_EXTRACT(h.value,'$.${sensor}[0]')) sensor
|
| | | FROM device d, history h, monitor_point mp
|
| | | WHERE d.mac=h.mac
|
| | | And mp.id=d.monitor_point_id
|
| | | AND d.monitor_point_id IN
|
| | | <foreach collection="monitorPointIdList" index="index" item="monitorPointId" open="(" separator="," close=")"> |
| | | #{monitorPointId} |
| | | </foreach>
|
| | | AND h.time BETWEEN #{before5Time} AND #{endTime}
|
| | | GROUP BY d.monitor_point_id
|
| | | ORDER BY AVG(JSON_EXTRACT(h.value,'$.${sensor}[0]')) DESC
|
| | | </select>
|
| | |
|
| | | </mapper> |
| | |
| | | FROM monitor_point |
| | | WHERE id = #{id} |
| | | </select> |
| | | <select id="getIdByOrganizationId" resultType="java.util.Map"> |
| | | SELECT id |
| | | FROM monitor_point |
| | | WHERE organization_id IN |
| | | <foreach collection="organizationIdList" index="index" item="organizationId" open="(" separator="," close=")"> |
| | | #{organizationId} |
| | | </foreach> |
| | | </select> |
| | | </mapper> |