From 00e38ff225eb948f5234934afc01aa54c94e0de6 Mon Sep 17 00:00:00 2001 From: 于紫祥_1901 <email@yuzixiang_1910> Date: Sat, 10 Oct 2020 11:29:36 +0800 Subject: [PATCH] update --- src/main/java/com/moral/controller/WebController.java | 117 +++++++++++++++++++++++++++------------------------------- 1 files changed, 54 insertions(+), 63 deletions(-) diff --git a/src/main/java/com/moral/controller/WebController.java b/src/main/java/com/moral/controller/WebController.java index fde7b89..43a14aa 100644 --- a/src/main/java/com/moral/controller/WebController.java +++ b/src/main/java/com/moral/controller/WebController.java @@ -1,24 +1,26 @@ package com.moral.controller; import com.auth0.jwt.exceptions.JWTDecodeException; +import com.moral.common.bean.ResultBean; import com.moral.common.exception.WebAuthException; -import com.moral.common.util.BeanUtils; -import com.moral.common.util.RedisHashUtil; -import com.moral.common.util.WebTokenUtils; +import com.moral.common.util.*; import com.moral.common.webAnno.UserLoginToken; import com.moral.entity.AreaNames; +import com.moral.entity.Device; +import com.moral.entity.MonitorPoint; import com.moral.entity.Organization; -import com.moral.service.AccountService; -import com.moral.service.DictionaryDataService; -import com.moral.service.OrganizationService; -import com.moral.service.WebTokenService; +import com.moral.service.*; import com.moral.util.LatLngTransformation; +import io.swagger.annotations.ApiImplicitParam; +import io.swagger.annotations.ApiImplicitParams; +import io.swagger.annotations.ApiOperation; import jdk.nashorn.internal.runtime.logging.Logger; import org.springframework.web.bind.annotation.*; import javax.annotation.Resource; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; +import java.util.Arrays; import java.util.HashMap; import java.util.List; import java.util.Map; @@ -40,6 +42,19 @@ WebTokenService webTokenService; @Resource RedisHashUtil redisHashUtil; + @Resource + HistoryMinutelyService historyMinutelyService; + @Resource + MonitorPointService monitorPointService; + @Resource + DeviceService deviceService; + + + @UserLoginToken + @GetMapping("test") + public String add() { + return "test success!"; + } @PostMapping("login") public Map<String, Object> login(@RequestBody Map<String, Object> parameters) { @@ -125,67 +140,43 @@ return resultMap; } - //������ + @UserLoginToken - @RequestMapping("getAccountInfoTest") - public Map<String, Object> getAccountInfoTest(@RequestBody Map<String, Object> parameters) { - Map<String, Object> resultMap = new HashMap<String, Object>(); - System.out.println(parameters); - if (!(parameters.containsKey("account") && parameters.containsKey("password"))) { - resultMap.put("msg", "������������������������������������"); - resultMap.put("accountId", -1); - } else { - resultMap = accountService.screenLoginNew(parameters); - // ������������������������������������������ - Object orgId = resultMap.get("orgId"); - if (resultMap.get("orgId") != null && resultMap.get("orgId") instanceof Integer) { - StringBuilder areaNamesBuilder = new StringBuilder("������"); - //��������������������������������� - if (!((Integer) orgId).equals(dictionaryDataService.querySupperOrgId())) { - //��������������������������������������������������� - Organization organization = organizationService.getOrganizationById((Integer) orgId); - if (organization.getAreaNames() != null) { - Map<String, String> areaNameMap = BeanUtils.beanToMap(organization.getAreaNames()); - List<String> names = areaNameMap.entrySet().stream().filter(item -> { - return item.getValue() != null; - }).map(item -> { - return item.getValue(); - }).collect(Collectors.toList()); - AreaNames areaNames = organization.getAreaNames(); - areaNamesBuilder.append("/"); - areaNamesBuilder.append(String.join("/", names)); - } - // ������������ - if (organization.getRank() != null && organization.getRank() == 0) { - resultMap.put("type", "enterprise"); - } else { - resultMap.put("type", "government"); - } - Number mapAreaCode = null; - if (organization.getVillageCode() != null) { - mapAreaCode = organization.getVillageCode(); - } else if (organization.getTownCode() != null) { - mapAreaCode = organization.getTownCode(); - } else if (organization.getAreaCode() != null) { - mapAreaCode = organization.getAreaCode(); - } else if (organization.getCityCode() != null) { - mapAreaCode = organization.getCityCode(); - } else if (organization.getProvinceCode() != null) { - mapAreaCode = organization.getProvinceCode(); - } - resultMap.put("mapAreaCode", mapAreaCode.toString()); - } - resultMap.put("mapPath", areaNamesBuilder.toString()); - String accountId = String.valueOf(resultMap.get("accountId")); - resultMap.put("token", webTokenService.getToken(accountId)); + @GetMapping("report_avg_datas") + public ResultBean<List<Map<String, Object>>> getMonitorPointOrDeviceAvgData(HttpServletRequest request) + throws Exception { + Map<String, Object> parameters = WebUtils.getParametersStartingWith(request, null); + //������������������������������������������������ + ParameterUtils.getTimeType4Time(parameters); + Object sensorKey = parameters.remove("sensorKey"); + parameters.put("sensors", Arrays.asList(sensorKey)); + List<Map<String, Object>> list = historyMinutelyService.getMonitorPointOrDeviceAvgData(parameters); + for (Map<String, Object> map : list) { + String time = map.get("time").toString(); + time = time.substring(time.length() - 2); + map.put("time", Integer.valueOf(time)); + if(parameters.get("type").equals("day")){ + map.put("time", Integer.valueOf(time)+1); } + map.put("value", map.remove(sensorKey)); } - return resultMap; + return new ResultBean<List<Map<String, Object>>>(list); } @UserLoginToken - @GetMapping("test") - public String add() { - return "test success!"; + @GetMapping("monitorpoints-devices") + public ResultBean<List<MonitorPoint>> getMonitorPointsAndDevicesByRegion(HttpServletRequest request) + throws Exception { + Map<String, Object> parameters = WebUtils.getParametersStartingWith(request, null); + List<MonitorPoint> monitorPoints = monitorPointService.getMonitorPointsAndDevicesByRegion(parameters); + return new ResultBean<List<MonitorPoint>>(monitorPoints); + } + + /* @UserLoginToken*/ + @GetMapping("coordinates") + public ResultBean<List<Device>> getDeviceCoordinatesAndState(HttpServletRequest request){ + Map<String, Object> parameters = WebUtils.getParametersStartingWith(request, null); + ParameterUtils.getRegionType4RegionCode(parameters); + return new ResultBean<List<Device>>(deviceService.queryDevice(parameters)); } } -- Gitblit v1.8.0