Merge remote-tracking branch 'origin/master'
4 files added
8 files modified
New file |
| | |
| | | package com.moral.common.util;
|
| | |
|
| | | import java.io.File;
|
| | | import java.net.URL;
|
| | | 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 {
|
| | | URL url = Dom4jUtils.class.getClassLoader().getResource("system" + File.separator + "city.xml");
|
| | | Document document = new SAXReader().read(url);
|
| | | 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;
|
| | | }
|
| | | }
|
| | |
| | |
|
| | | public static void getElementByType(Map<String, Object> parameters){
|
| | | if (parameters.containsKey("type")) {
|
| | | parameters.put("timeUnits", "daily");
|
| | | switch (parameters.get("type").toString()) {
|
| | | case "year":
|
| | | parameters.put("format", "yyyy");
|
| | |
| | | parameters.put("typeFormat", "%Y-%m-%d %H");
|
| | | parameters.put("timeLength", 24);
|
| | | parameters.put("field", Calendar.DATE);
|
| | | parameters.put("timeUnits", "minutely");
|
| | | break;
|
| | | case "hour":
|
| | | parameters.put("format", "yyyy-MM-dd HH");
|
| | | parameters.put("typeFormat", "%Y-%m-%d %H:%i");
|
| | | parameters.put("timeLength", 60);
|
| | | parameters.put("field", Calendar.HOUR);
|
| | | parameters.put("timeUnits", "minutely");
|
| | | break;
|
| | | }
|
| | | }
|
| | |
| | | private OrganizationService organizationService;
|
| | | @Resource
|
| | | private DictionaryDataService dictionaryDataService;
|
| | | |
| | | @Resource
|
| | | private WeatherService weatherService;
|
| | | |
| | | /**
|
| | | * Screen login. 大屏登录
|
| | | *
|
| | |
| | | @GetMapping("report_alarm_datas")
|
| | | public ResultBean<List<Map<String, Object>>> getAlarmData(HttpServletRequest request) throws Exception {
|
| | | Map<String, Object> parameters = getParametersStartingWith(request, null);
|
| | | parameters.put("type", "month");
|
| | | ParameterUtils.getTimeType4Time(parameters);
|
| | | //parameters.put("type", "month");
|
| | | String sensorKey = "list";
|
| | | if (ObjectUtils.isEmpty(parameters.get("sensorKey"))) {
|
| | | parameters.put("description", "description");
|
| | |
| | | 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);
|
| | |
|
| | | }
|
| | |
| | | import com.alibaba.fastjson.JSON;
|
| | | import com.alibaba.fastjson.TypeReference;
|
| | | import com.moral.common.util.CalculateUtils;
|
| | | import com.moral.common.util.ParameterUtils;
|
| | | import com.moral.common.util.ReportTimeFormat;
|
| | | import com.moral.common.util.ResourceUtil;
|
| | | import com.moral.common.util.ValidateUtil;
|
| | |
| | | List<Map<String, Object>> list = JSON.parseObject((String)parameters.remove("items"), new TypeReference<List<Map<String, Object>>>() {});
|
| | |
|
| | | String type = (String) parameters.get("type");
|
| | | parameters.putAll(getElementByType(type));
|
| | | // parameters.putAll(getElementByType(type));
|
| | | ParameterUtils.getElementByType(parameters);
|
| | | Integer timeLength = Integer.valueOf(parameters.remove("timeLength").toString());
|
| | | if ("month".equals(type)) {
|
| | | for (Map<String, Object> map : list) {
|
| | |
| | |
|
| | | @Override
|
| | | public void convertQueryParam(Map<String, Object> parameters) throws ParseException {
|
| | | String type = (String) parameters.get("type");
|
| | | if (!parameters.containsKey("field")) {
|
| | | parameters.putAll(getElementByType(type));
|
| | | // String type = (String) parameters.get("type");
|
| | | // parameters.putAll(getElementByType(type));
|
| | | ParameterUtils.getElementByType(parameters);
|
| | | }
|
| | | String time = (String) parameters.get("time");
|
| | | String format = (String) parameters.get("format");
|
| | |
| | | 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.List;
|
| | | import java.util.Map;
|
| | |
|
| | | import javax.annotation.Resource;
|
| | |
|
| | | import org.dom4j.Element;
|
| | | import org.springframework.stereotype.Service;
|
| | | import org.springframework.util.ObjectUtils;
|
| | | import org.springframework.web.client.RestTemplate;
|
| | |
|
| | | import com.moral.common.util.Dom4jUtils;
|
| | | import com.moral.common.util.ValidateUtil;
|
| | | import com.moral.entity.AreaNames;
|
| | | import com.moral.entity.Organization;
|
| | | import com.moral.service.OrganizationService;
|
| | | import com.moral.service.WeatherService;
|
| | |
|
| | | @Service
|
| | | public class WeatherServiceImpl implements WeatherService {
|
| | | |
| | | @Resource
|
| | | private OrganizationService organizationService;
|
| | | |
| | | @Override
|
| | | public Map<String, Object> getWeatherDataByRegion(Map<String, Object> parameters) {
|
| | | Object organizationId = parameters.get("organizationId");
|
| | | ValidateUtil.notNull(organizationId, "param.is.null");
|
| | | String areaName = "昆山市";
|
| | | String parentName = "";
|
| | | Organization organization = organizationService.getOrganizationById(Integer.valueOf(parameters.get("organizationId").toString()));
|
| | | if(organization.getAreaNames()!=null){
|
| | | AreaNames areaNames = organization.getAreaNames();
|
| | | if (ObjectUtils.isEmpty(areaNames.getAreaName())) {
|
| | | if (ObjectUtils.isEmpty(areaNames.getCityName())) {
|
| | | areaName = areaNames.getProvinceName();
|
| | | } else {
|
| | | areaName = areaNames.getCityName();
|
| | | }
|
| | | } else {
|
| | | areaName = areaNames.getAreaName();
|
| | | parentName = areaNames.getCityName();
|
| | | if ("市辖区".equals(areaName)) {
|
| | | areaName = parentName;
|
| | | }
|
| | | }
|
| | | }
|
| | | List<Element> elements = Dom4jUtils.readDocument();
|
| | | String cityID = "1102";
|
| | | for (Element element : elements) {
|
| | | String name = element.element("name").getText();
|
| | | if (areaName.equals(name)) {
|
| | | cityID = element.element("Fid").getText();
|
| | | break;
|
| | | }
|
| | | if (name.endsWith(areaName)) {
|
| | | if (name.startsWith(parentName)) {
|
| | | cityID = element.element("Fid").getText();
|
| | | break;
|
| | | }
|
| | | }
|
| | | }
|
| | | RestTemplate restTemplate = new RestTemplate();
|
| | | Map<String, Object> map = restTemplate.getForObject("http://sapi.7drlb.com/api/mj?cityID={1}&apiKey=aqi", Map.class,cityID);
|
| | | Map<String, Object> result = (Map<String, Object>) ((Map)map.get("data")).get("aqi");
|
| | | map = restTemplate.getForObject("http://sapi.7drlb.com/api/mj?cityID={1}&apiKey=condition", Map.class,cityID);
|
| | | 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> |
| | |
| | | AVG(json->'$.${sensorKey}[0]') AS '${sensorKey}'
|
| | | </foreach>
|
| | | FROM
|
| | | history_minutely h
|
| | | history_${timeUnits} h
|
| | | WHERE
|
| | | h.time >= #{start}
|
| | | AND h.time <![CDATA[<]]> #{end}
|