4 files added
5 files modified
New file |
| | |
| | | package com.moral.common.util;
|
| | |
|
| | | import java.io.File;
|
| | | import java.util.ArrayList;
|
| | | import java.util.List;
|
| | |
|
| | | import org.dom4j.Document;
|
| | | import org.dom4j.DocumentException;
|
| | | import org.dom4j.Element;
|
| | | import org.dom4j.io.SAXReader;
|
| | | import org.springframework.stereotype.Component;
|
| | |
|
| | | @Component
|
| | | @SuppressWarnings("unchecked")
|
| | | public class Dom4jUtils {
|
| | |
|
| | | private static ArrayList<Element> elements;
|
| | | |
| | | public static List<Element> readDocument() {
|
| | | try {
|
| | | Document document = new SAXReader().read(new File("src/main/resources/system/city.xml"));
|
| | | Element rootElement = document.getRootElement();
|
| | | elements = (ArrayList<Element>) rootElement.elements();
|
| | | System.out.println(elements.size());
|
| | | } catch (DocumentException e) {
|
| | | // TODO Auto-generated catch block
|
| | | e.printStackTrace();
|
| | | }
|
| | | return elements;
|
| | | }
|
| | | |
| | | public static List<Element> getDocuments() {
|
| | | return elements;
|
| | | }
|
| | | }
|
| | |
| | | private OrganizationService organizationService;
|
| | | @Resource
|
| | | private DictionaryDataService dictionaryDataService;
|
| | | |
| | | @Resource
|
| | | private WeatherService weatherService;
|
| | | |
| | | /**
|
| | | * Screen login. 大屏登录
|
| | | *
|
| | |
| | | result.put("device",deviceSummary);
|
| | | return new ResultBean<>(result);
|
| | | }
|
| | | |
| | | @GetMapping("weather")
|
| | | @ApiOperation(value = "获取区域天气情况", notes = "获取区域天气情况")
|
| | | @ApiImplicitParams(value = {
|
| | | @ApiImplicitParam(name = "organizationId",defaultValue = "5", value = "登录账号的组织id", required = true, paramType = "query", dataType = "String")
|
| | | })
|
| | | public ResultBean<Map<String, Object>> getWeatherDataByRegion(HttpServletRequest request) throws Exception {
|
| | | Map<String, Object> parameters = getParametersStartingWith(request, null);
|
| | | Map<String, Object> map = weatherService.getWeatherDataByRegion(parameters);
|
| | | return new ResultBean<Map<String,Object>>(map);
|
| | | }
|
| | |
|
| | | @GetMapping("actual")
|
| | | @ApiOperation(value = "获取监测因子实时最大值", notes = "获取监测因子实时最大值")
|
| | | @ApiImplicitParams(value = {
|
| | | @ApiImplicitParam(name = "accountId",defaultValue = "1", value = "登录账号的id", required = true, paramType = "query", dataType = "String"),
|
| | | @ApiImplicitParam(name = "sensorKey",defaultValue = "e1,e2,e3", value = "传感器key,如有多个用逗号分隔", required = true, paramType = "query", dataType = "String"), |
| | | @ApiImplicitParam(name = "time",defaultValue = "", value = "时间(long类型时间戳)", required = false, paramType = "query", dataType = "String"), |
| | | @ApiImplicitParam(name = "interval",defaultValue = "30", value = "时间间隔(秒)", required = true, paramType = "query", dataType = "Integer"),
|
| | | })
|
| | | public ResultBean<Map<String, Object>> getActualDataByRegion(HttpServletRequest request) throws Exception {
|
| | | Map<String, Object> parameters = getParametersStartingWith(request, null);
|
| | | Map<String, Object> map = historyService.getActualDataByRegion(parameters);
|
| | | return new ResultBean<Map<String, Object>>(map);
|
| | | }
|
| | | }
|
| | |
| | |
|
| | | List<Map<String, Object>> getValueByMacAndSize(Map<String, Object> parameters);
|
| | |
|
| | | Map<String, Object> getActualDataByRegion(Map<String, Object> parameters);
|
| | |
|
| | | } |
| | |
| | |
|
| | | List<Map<String, Object>> getSensorDataBySensorKey(Map<String, Object> parameters);
|
| | |
|
| | | Map<String, Object> getActualDataByRegion(Map<String, Object> parameters);
|
| | |
|
| | | }
|
New file |
| | |
| | | package com.moral.service;
|
| | |
|
| | | import java.util.Map;
|
| | |
|
| | | public interface WeatherService {
|
| | |
|
| | | Map<String, Object> getWeatherDataByRegion(Map<String, Object> parameters);
|
| | |
|
| | | }
|
| | |
| | | package com.moral.service.impl;
|
| | |
|
| | | import java.time.Instant;
|
| | | import java.time.LocalDate;
|
| | | import java.time.LocalDateTime;
|
| | | import java.time.ZoneId;
|
| | | import java.time.ZoneOffset;
|
| | | import java.time.temporal.ChronoUnit;
|
| | | import java.time.temporal.TemporalAdjusters;
|
| | | import java.util.ArrayList;
|
| | | import java.util.Arrays;
|
| | | import java.util.Collections;
|
| | | import java.util.Comparator;
|
| | | import java.util.Date;
|
| | |
| | | return values;
|
| | | }
|
| | |
|
| | | @Override
|
| | | public Map<String, Object> getActualDataByRegion(Map<String, Object> parameters) {
|
| | | Object sensorKey = parameters.get("sensorKey");
|
| | | ValidateUtil.notNull(sensorKey, "param.is.null");
|
| | | ValidateUtil.notNull(parameters.get("accountId"), "param.is.null");
|
| | | ValidateUtil.notNull(parameters.get("interval"), "param.is.null");
|
| | | Integer interval = Integer.valueOf(parameters.get("interval").toString());
|
| | | LocalDateTime start, end;
|
| | | if (!parameters.containsKey("time")) {
|
| | | end = LocalDateTime.now();
|
| | | int second = end.getSecond() / interval * interval;
|
| | | end = end.truncatedTo(ChronoUnit.MINUTES).plusSeconds(second);
|
| | | start = end.minusSeconds(interval);
|
| | | } else {
|
| | | //start = LocalDateTime.ofEpochSecond(Long.valueOf(parameters.get("time").toString()) / 1000, 0, ZoneOffset.ofHours(8));
|
| | | start = LocalDateTime.ofInstant(Instant.ofEpochMilli(Long.valueOf(parameters.get("time").toString())),ZoneId.of("+8"));
|
| | | end = start.plusSeconds(interval);
|
| | | }
|
| | | parameters.put("start", start);
|
| | | parameters.put("end", end);
|
| | | parameters.put("sensorKeys", Arrays.asList(((String) sensorKey).split(",")));
|
| | | accountService.setOrgIdsByAccount(parameters);
|
| | | Map<String, Object> result = historyMapper.getActualDataByRegion(parameters);
|
| | | if (ObjectUtils.isEmpty(result)) {
|
| | | result = new HashMap<String, Object>();
|
| | | }
|
| | | result.put("time", end.toInstant(ZoneOffset.of("+8")).toEpochMilli());
|
| | | return result;
|
| | | }
|
| | |
|
| | | }
|
New file |
| | |
| | | package com.moral.service.impl;
|
| | |
|
| | | import java.util.Map;
|
| | |
|
| | | import org.springframework.stereotype.Service;
|
| | | import org.springframework.web.client.RestTemplate;
|
| | |
|
| | | import com.moral.service.WeatherService;
|
| | |
|
| | | @Service
|
| | | public class WeatherServiceImpl implements WeatherService {
|
| | | |
| | | @Override
|
| | | public Map<String, Object> getWeatherDataByRegion(Map<String, Object> parameters) {
|
| | | RestTemplate restTemplate = new RestTemplate();
|
| | | Map<String, Object> map = restTemplate.getForObject("http://sapi.7drlb.com/api/mj?cityID=1102&apiKey=aqi", Map.class);
|
| | | Map<String, Object> result = (Map<String, Object>) ((Map)map.get("data")).get("aqi");
|
| | | map = restTemplate.getForObject("http://sapi.7drlb.com/api/mj?cityID=1102&apiKey=condition", Map.class);
|
| | | result.putAll((Map<? extends String, ? extends Object>) ((Map)map.get("data")).get("condition"));
|
| | | return result;
|
| | | }
|
| | |
|
| | | }
|
| | |
| | | time DESC
|
| | | LIMIT #{size}
|
| | | </select>
|
| | | |
| | | <select id="getActualDataByRegion" resultType="java.util.Map">
|
| | | SELECT
|
| | | <foreach collection="sensorKeys" separator="," item="sensorKey">
|
| | | MAX( CONVERT ( `value` -> '$.${sensorKey}', DECIMAL ) ) AS '${sensorKey}' |
| | | </foreach>
|
| | | FROM
|
| | | history h ,
|
| | | device d,
|
| | | monitor_point mp
|
| | | <where>
|
| | | h.mac = d.mac |
| | | AND d.monitor_point_id = mp.id |
| | | <if test="orgIds != null and orgIds.size > 0">
|
| | | AND mp.organization_id IN
|
| | | <foreach collection="orgIds" open="(" separator="," close=")" item="listItem">
|
| | | #{listItem}
|
| | | </foreach>
|
| | | </if>
|
| | | AND h.time >= #{start} |
| | | AND h.time < #{end} |
| | | </where>
|
| | | </select>
|
| | | </mapper> |