| | |
| | | import java.io.ByteArrayInputStream;
|
| | | import java.io.InputStream;
|
| | | import java.io.InputStreamReader;
|
| | | import java.io.PrintWriter;
|
| | | import java.net.HttpURLConnection;
|
| | | import java.net.URL;
|
| | | import java.text.DecimalFormat;
|
| | | import java.util.ArrayList;
|
| | | import java.util.Arrays;
|
| | | import java.util.Collection;
|
| | |
| | |
|
| | | import org.apache.commons.collections.CollectionUtils;
|
| | | import org.apache.commons.net.ftp.FTPClient;
|
| | | import org.apache.http.HttpResponse;
|
| | | import org.apache.log4j.Logger;
|
| | | import org.dom4j.Document;
|
| | | import org.dom4j.Element;
|
| | |
| | | import com.alibaba.fastjson.JSON;
|
| | | import com.alibaba.fastjson.JSONArray;
|
| | | import com.alibaba.fastjson.JSONObject;
|
| | | import com.googlecode.aviator.AviatorEvaluator;
|
| | | import com.googlecode.aviator.Expression;
|
| | | import com.moral.common.bean.Constants;
|
| | | import com.moral.common.bean.JsonData;
|
| | | import com.moral.common.bean.PageResult;
|
| | |
| | | import com.moral.service.OrganizationService;
|
| | | import com.moral.service.QualityDailyService;
|
| | | import com.moral.service.SensorService;
|
| | | import com.moral.service.SensorUnitService;
|
| | | import com.moral.service.WeatherService;
|
| | | import com.moral.util.TempAllocationUtils;
|
| | |
|
| | | import io.swagger.annotations.Api;
|
| | | import io.swagger.annotations.ApiImplicitParam;
|
| | |
| | |
|
| | | @Resource
|
| | | SensorService sensorService;
|
| | | @Resource
|
| | | SensorUnitService sensorUnitService;
|
| | | @Resource
|
| | | MonitorPointService monitorPointService;
|
| | | @Resource
|
| | |
| | | String mac = parameters.get("mac").toString();
|
| | | String sensorKey = parameters.get("sensorKey").toString();
|
| | | String time = parameters.get("time").toString();
|
| | | Long code = monitorPoint.getAreaCode().longValue();
|
| | | String regionName = areaService.queryFullNameByCode(code);
|
| | | Device device = deviceService.getDeviceByMac(mac, false);
|
| | | if (monitorPoint != null && mac != null && sensorKey != null && time != null) {
|
| | | Map<String, Double> resultMap = historyDailyService.getTraceabilityData(parameters);
|
| | | JSONObject params = new JSONObject();
|
| | | Long code = monitorPoint.getAreaCode().longValue();
|
| | | String regionName = areaService.queryFullNameByCode(code);
|
| | | Device device = deviceService.getDeviceByMac(mac, false);
|
| | | Device deviceSecond = deviceService.getDeviceByLongitudeAsc(mac);
|
| | | params.put("sensorInfo", resultMap);
|
| | | params.put("regionCode", code);
|
| | | params.put("regionName", regionName);
|
| | | params.put("monitorPoint", monitorPoint);
|
| | | params.put("device", device);
|
| | | params.put("deviceSecond",deviceSecond);
|
| | | String paramsJson = params.toJSONString();
|
| | | model.addObject("traceabilityParams", paramsJson);
|
| | | model.setViewName("traceability");
|
| | |
| | | } else {
|
| | | StringBuilder msg = new StringBuilder();
|
| | | msg.append(" param[0] monitorPointId:");
|
| | | msg.append(monitorPointId.toString());
|
| | | msg.append(monitorPointId);
|
| | | msg.append(" param[0] mac:");
|
| | | msg.append(mac);
|
| | | msg.append(" param[0] sensorKey:");
|
| | |
| | | return model;
|
| | | }
|
| | | }
|
| | | |
| | | /*@GetMapping("getSensor")
|
| | | @ApiOperation(value = "返回单位", notes = "返回单位")
|
| | | @ApiImplicitParams(value = {
|
| | | @ApiImplicitParam(name = "mac", value = "设备MN号", required = true, paramType = "query", dataType = "String")
|
| | | })
|
| | | public ResultBean<Map<String, Object>> getSensor(HttpServletRequest request) throws Exception {
|
| | | Map<String, Object> parameters = WebUtils.getParametersStartingWith(request, null);
|
| | | String mac = (String) parameters.get("mac");
|
| | | //System.out.println("ScreenController-----getSensor-----mac:"+mac);
|
| | | Map<String, Object> map = sensorUnitService.getSensorByMac(mac);
|
| | | System.out.println("ScreenController-----getSensor-----map:"+map);
|
| | | return new ResultBean<Map<String, Object>>(map);
|
| | | }*/
|
| | | |
| | | @GetMapping("getSensorByMonitorPointId")
|
| | | @ApiOperation(value = "返回单位", notes = "返回单位")
|
| | | @ApiImplicitParams(value = {
|
| | | @ApiImplicitParam(name = "monitor_point_id", value = "监测站点id", required = true, paramType = "query", dataType = "String")
|
| | | })
|
| | | public ResultBean<List<Map<String, Object>>> getSensorByMonitorPointId(HttpServletRequest request) throws Exception {
|
| | | Map<String, Object> parameters = WebUtils.getParametersStartingWith(request, null);
|
| | | String monitor_point_id = (String) parameters.get("monitor_point_id");
|
| | | List<Map<String, Object>> map = sensorUnitService.getSensorsByMonitPointId2(monitor_point_id);
|
| | | return new ResultBean<List<Map<String, Object>>>(map);
|
| | | }
|
| | | |
| | | @GetMapping("AIForecast")
|
| | | @ApiOperation(value = "AI预测", notes = "AI预测")
|
| | | @ApiImplicitParams(value = {
|
| | | @ApiImplicitParam(name = "monitorPoint", value = "监控站id", required = true, paramType = "query", dataType = "String"),
|
| | | @ApiImplicitParam(name = "mac", value = "设备mac", required = false, paramType = "query", dataType = "String"),
|
| | | @ApiImplicitParam(name = "sensorKey", value = "传感器key,如有多个用逗号分隔", required = true, paramType = "query", dataType = "String"), |
| | | @ApiImplicitParam(name = "time", value = "时间,天(格式:2018-03-06)", required = true, paramType = "query", dataType = "String"), |
| | | })
|
| | | public ResultBean<List<Map<String, Object>>> AIForecast (HttpServletRequest request) throws Exception {
|
| | | Map<String, Object> parameters = getParametersStartingWith(request, null);
|
| | | //System.out.println(parameters);
|
| | | String monitorPoint = (String) parameters.get("monitorPoint");
|
| | | String intoTime = parameters.get("time").toString();
|
| | | String[] timeArray = intoTime.split("-");
|
| | | //System.out.println(timeArray);
|
| | | Integer year = Integer.parseInt(timeArray[0]);
|
| | | Integer mon = Integer.parseInt(timeArray[1]);
|
| | | if(mon>1) {
|
| | | mon = mon-1;
|
| | | }else {
|
| | | mon = 12;
|
| | | year = year-1;
|
| | | }
|
| | | String alterTime = year.toString()+"-"+mon.toString()+"-"+timeArray[2];
|
| | | //System.out.println(alterTime);
|
| | | parameters.put("time", alterTime);
|
| | | ParameterUtils.getTimeType4Time(parameters);
|
| | | String monitor_point_id = (String) parameters.get("monitorPoint");
|
| | | parameters.put("monitorPointId", parameters.remove("monitorPoint"));
|
| | | String[] sensorKeys = parameters.remove("sensorKey").toString().split(",");
|
| | | parameters.put("sensors", Arrays.asList(sensorKeys));
|
| | | // monitorPointService.isCompensateCalculation(parameters);
|
| | | List<Map<String, Object>> list = historyMinutelyService.getMonitorPointOrDeviceAvgData(parameters);
|
| | | |
| | | Map<String, Object> mpMap = new HashMap<>();
|
| | | mpMap = monitorPointService.selectAllById(monitorPoint);
|
| | | //生命一个map,用来存放查询天气信息是需要的参数
|
| | | Map<String, Object> weatherParameters = new HashMap<>();
|
| | | weatherParameters.put("organizationId", mpMap.get("organization_id"));
|
| | | weatherParameters.put("time", intoTime);
|
| | | //获取天气信息
|
| | | Map<String, Object> weatherMap = weatherService.get15DayWeatherDataByRegion(weatherParameters);
|
| | | Map<String, Object> tempMap = TempAllocationUtils.tempAllocation(weatherMap);
|
| | | //获取单位信息
|
| | | Map<String, Map<String, Object>> sensorUnitMap = sensorUnitService.getSensorsByMonitPointId(monitor_point_id);
|
| | |
|
| | | for (Map<String, Object> map : list) {
|
| | | String time = map.get("time").toString();
|
| | | time = time.substring(time.length() - 2);
|
| | | map.put("time", Integer.valueOf(time));
|
| | | map.put("temp", tempMap.get(map.get("time").toString()));
|
| | | List<Number> values = new ArrayList<Number>();
|
| | | List<String> units = new ArrayList<String>();
|
| | | for (String string : sensorKeys) {
|
| | | if(sensorUnitMap!=null && !sensorUnitMap.isEmpty()) {
|
| | | if(sensorUnitMap.get(string)!=null) {
|
| | | units.add(sensorUnitMap.get(string).get("name").toString());
|
| | | String rules = sensorUnitMap.get(string).get("rules").toString();
|
| | | rules = rules.replace("{0}", "a");
|
| | | rules = rules.replace("d", "");
|
| | | Expression expression = AviatorEvaluator.compile(rules);
|
| | | Double value;
|
| | | Map<String, Object> ev = new HashMap<>();
|
| | | ev.put("a", map.get(string));
|
| | | value = (Double) expression.execute(ev);
|
| | | //保留两位小数
|
| | | DecimalFormat df = new DecimalFormat("#.00");
|
| | | value = Double.parseDouble(df.format(value));
|
| | | values.add(value);
|
| | | }else {
|
| | | Map<String, Object> sensorMap = sensorService.getSensorBySensorKey(string);
|
| | | units.add(sensorMap.get("unit").toString());
|
| | | values.add((Number) map.remove(string));
|
| | | }
|
| | | }else {
|
| | | Map<String, Object> sensorMap = sensorService.getSensorBySensorKey(string);
|
| | | units.add(sensorMap.get("unit").toString());
|
| | | values.add((Number) map.remove(string));
|
| | | }
|
| | | //values.add((Number) map.remove(string));
|
| | | }
|
| | | map.put("values", values);
|
| | | map.put("units", units);
|
| | | }
|
| | | return new ResultBean<List<Map<String, Object>>>(list);
|
| | | }
|
| | | |
| | | @GetMapping("getWeather")
|
| | | @ApiOperation(value = "获取天气信息", notes = "获取天气信息")
|
| | | @ApiImplicitParams(value = {
|
| | | @ApiImplicitParam(name = "organizationId", defaultValue = "5", value = "登录账号的组织id", required = true, paramType = "query", dataType = "String"),
|
| | | @ApiImplicitParam(name = "time", value = "时间,天(格式:2018-03-06)", required = true, paramType = "query", dataType = "String"),
|
| | | })
|
| | | public ResultBean<Map<String, Object>> getWeather(HttpServletRequest request) throws Exception {
|
| | | Map<String, Object> parameters = getParametersStartingWith(request, null);
|
| | | Map<String, Object> map = weatherService.get15DayWeatherDataByRegion(parameters);
|
| | | /*Map<String, Object> tempMap = new HashMap<>();
|
| | | Double tempDay = Double.parseDouble(map.get("tempDay").toString());
|
| | | Double tempNight = Double.parseDouble(map.get("tempNight").toString());
|
| | | Double time5 = tempNight;
|
| | | Double time13 = tempDay;
|
| | | Double difference = tempDay-tempNight;
|
| | | Double dif_8 = difference/8;
|
| | | Double dif_16 = difference/16;
|
| | | tempMap.put("5", time5);
|
| | | tempMap.put("13", time13);
|
| | | String time = null;
|
| | | Double t = time5;
|
| | | for(int i=4;i>=0;i--) {
|
| | | time = ""+i;
|
| | | t = t+dif_16;
|
| | | String tempLast = ""+Math.round(t);
|
| | | tempMap.put(time, tempLast);
|
| | | }
|
| | | Double y = time5;
|
| | | for(int i=6;i<13;i++) {
|
| | | time = ""+i;
|
| | | y = y+dif_8;
|
| | | String tempLast = ""+Math.round(y);
|
| | | tempMap.put(time, tempLast);
|
| | | }
|
| | | Double z = time13;
|
| | | for(int i=14;i<=23;i++) {
|
| | | time = ""+i;
|
| | | z = z-dif_16;
|
| | | String tempLast = ""+Math.round(z);
|
| | | tempMap.put(time, tempLast);
|
| | | }*/
|
| | | Map<String, Object> tempMap = TempAllocationUtils.tempAllocation(map);
|
| | | return new ResultBean<Map<String, Object>>(tempMap);
|
| | | }
|
| | |
|
| | | }
|