From 19cfd37456d6bf42fcb90207b481637f56aedb6d Mon Sep 17 00:00:00 2001 From: fengxiang <110431245@qq.com> Date: Sat, 23 Jun 2018 11:26:55 +0800 Subject: [PATCH] screencontroller rtm-layout utf-8 更新 --- src/main/java/com/moral/controller/ScreenController.java | 151 ++++++++++++++++++++++++++++++++++++------------- 1 files changed, 110 insertions(+), 41 deletions(-) diff --git a/src/main/java/com/moral/controller/ScreenController.java b/src/main/java/com/moral/controller/ScreenController.java index 8cc897a..79beb59 100644 --- a/src/main/java/com/moral/controller/ScreenController.java +++ b/src/main/java/com/moral/controller/ScreenController.java @@ -3,17 +3,18 @@ import static com.moral.common.util.ResourceUtil.getValue; import static com.moral.common.util.WebUtils.getParametersStartingWith; -import java.io.BufferedReader; -import java.io.ByteArrayInputStream; -import java.io.InputStream; -import java.io.InputStreamReader; +import java.io.*; import java.util.*; import java.util.stream.Collectors; - import javax.annotation.Resource; import javax.servlet.http.HttpServletRequest; +import com.alibaba.fastjson.JSONReader; +import com.alibaba.fastjson.TypeReference; +import com.moral.entity.*; import com.moral.entity.alarm.AlarmConfig; +import com.moral.entity.alarm.AlarmConfigValue; +import com.moral.entity.charts.DataSortCondition; import org.apache.commons.collections.CollectionUtils; import org.apache.commons.net.ftp.FTPClient; import org.apache.log4j.Logger; @@ -35,8 +36,6 @@ import org.springframework.web.bind.annotation.RestController; import org.springframework.web.servlet.ModelAndView; import org.xml.sax.InputSource; - -import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSONArray; import com.alibaba.fastjson.JSONObject; import com.moral.common.bean.Constants; @@ -45,11 +44,6 @@ import com.moral.common.bean.ResultBean; import com.moral.common.util.ValidateUtil; import com.moral.common.xml.Version; -import com.moral.entity.Account; -import com.moral.entity.Device; -import com.moral.entity.MapBounds; -import com.moral.entity.MonitorPoint; -import com.moral.entity.alarm.AlarmConfigValue; import com.moral.entity.alarm.AlarmSensorLevel; import com.moral.service.AccountService; import com.moral.service.AlarmConfigService; @@ -62,6 +56,11 @@ import com.moral.service.MonitorPointService; import com.moral.service.SensorService; +import io.swagger.annotations.Api; +import io.swagger.annotations.ApiImplicitParam; +import io.swagger.annotations.ApiImplicitParams; +import io.swagger.annotations.ApiOperation; + /** * The Class ScreenController.������������ */ @@ -69,6 +68,7 @@ @RequestMapping("/screen") //@CrossOrigin(origins = "*", maxAge = 3600) @SuppressWarnings({ "rawtypes", "unchecked", "unused" }) +@Api(tags = "Screen", description = "������������") public class ScreenController { public static Logger log = Logger.getLogger(ScreenController.class); @Resource @@ -100,8 +100,8 @@ private MachineActivateService machineActivateService; /** The resource. */ - @Value(value = "classpath:system/alarmLevels.json") - private org.springframework.core.io.Resource resource; +// @Value(value = "classpath:system/alarmLevels.json") +// private org.springframework.core.io.Resource resource; /** The redis template. */ @Resource @@ -157,36 +157,39 @@ @GetMapping("alarm-levels") public Object getAlarmLevels(HttpServletRequest request, Optional<Integer> orgId, Optional<Integer> mpId) { List<Map<String,Object>> sensorAlarmList = null; - Map<String,AlarmSensorLevel> alarmLevelMap = null; - try { + try { + AlarmConfig alarmConfig = null; if(orgId.isPresent()){ - AlarmConfigValue alarmConfigValue = alarmConfigService.queryValueByOrganizationId(orgId.get()).get(); - alarmLevelMap = alarmConfigValue.getAlarmLevels(); + alarmConfig = alarmConfigService.queryValueByOrganizationId(orgId.get()).get(); }else if(mpId.isPresent()){ - AlarmConfig alarmConfig = alarmConfigService.queryByMonitorPointId(mpId.get()).get(); - alarmLevelMap = alarmConfig.getValue().getAlarmLevels(); + alarmConfig = alarmConfigService.queryByMonitorPointId(mpId.get()).get(); + } + //��������������� + if(alarmConfig.getValue()!=null&&alarmConfig.getValue().getAlarmLevels()!=null){ + Map<String, AlarmSensorLevel> alarmLevelMap = alarmConfig.getValue().getAlarmLevels(); // ������������������������������������������������������ + Map<String,AlarmSensorLevel> defaultSensorLevelMap = null; if(alarmConfig.getId()!=null){ AlarmConfigValue defaultAlarmValue = alarmConfigService.getDefaultAlarmConfigValue(); - Map<String,AlarmSensorLevel> defaultSensorLevelMap = defaultAlarmValue.getAlarmLevels(); - Map<String,AlarmSensorLevel> alarmSensorLevelMapNotZO = alarmLevelMap.entrySet().stream().collect( - HashMap::new, - (map,entry) -> { - AlarmSensorLevel alarmSensorLevel = entry.getValue(); - if(alarmSensorLevel.isEnable()||alarmSensorLevel.isDegressEnable()){ - map.put(entry.getKey(),entry.getValue()); - } - }, - (oMap,nMap) -> { - oMap.putAll(nMap); - } - ); - // ������������������������������������ - defaultSensorLevelMap.putAll(alarmSensorLevelMapNotZO); - alarmLevelMap = defaultSensorLevelMap; + defaultSensorLevelMap = defaultAlarmValue.getAlarmLevels(); } - } - if(alarmLevelMap!=null){ + Map<String, AlarmSensorLevel> finalDefaultSensorLevelMap = defaultSensorLevelMap; + alarmLevelMap.entrySet().stream().forEach(entry -> { + //��� increment������0������������������������ + AlarmSensorLevel alarmSensorLevel = entry.getValue(); + if(alarmSensorLevel.getIncrement()!=null){ + boolean isAllZero = alarmSensorLevel.getIncrement().stream().allMatch(item -> item == 0); + if(isAllZero){ + AlarmSensorLevel defaultAlarmSensorLevel = finalDefaultSensorLevelMap==null?null:finalDefaultSensorLevelMap.get(entry.getKey()); + if(defaultAlarmSensorLevel!=null){ + alarmSensorLevel.setIncrement(defaultAlarmSensorLevel.getIncrement()); + }else{ + List<Float> tempList = Arrays.asList(0.0f,200.0f,500.0f); + alarmSensorLevel.setIncrement(tempList); + } + } + } + }); //map to list Map<String, AlarmSensorLevel> finalAlarmLevelMap = alarmLevelMap; sensorAlarmList = alarmLevelMap.keySet().stream().map(key -> { @@ -222,6 +225,29 @@ return result; } + /** + * + * @param dataSortCondition ������������������������ + * @return + */ + public ResultBean<Map<String,Object>> getOrderData(DataSortCondition dataSortCondition) { + ResultBean resultBean = new ResultBean(); + if(dataSortCondition.getCode()==null){ + resultBean.setCode(ResultBean.FAIL); + resultBean.setMessage("code can't be null"); + } else if(dataSortCondition.getStyle()==null){ + resultBean.setCode(ResultBean.FAIL); + resultBean.setMessage("style can't be null"); + } + String code = dataSortCondition.getCode().toString(); + Region region = Region.create(code); + if(region == null) { + resultBean.setCode(ResultBean.FAIL); + resultBean.setMessage("code is not in the correct format"); + } + // todo + return null; + } /** * Gets the day AQI by sensor.���������������AQI������ * @@ -371,10 +397,8 @@ @RequestMapping(value = "/map-page", method = RequestMethod.GET) public ModelAndView map(ModelAndView model, @RequestParam("areaCode")int code, @RequestParam("accountId")int accountId){ Account account = accountService.getAccountById(accountId); - String regionName = areaService.selectFullNameByCode(code); + String regionName = areaService.queryFullNameByCode(code); if(account!=null&®ionName!=null){ - //������������ - regionName = regionName.replace(" ",""); Object sensors = sensorService.queryAll(); JSONObject params = new JSONObject(); params.put("regionCode",code); @@ -524,4 +548,49 @@ List<Map<String, Object>> list = (List<Map<String, Object>>) pieData.get(sensorKey); return new ResultBean<List<Map<String, Object>>>(list); } + + /** + * ���������������id������������������version��������� + * @param mptid + * @return + */ + @GetMapping("getvers") + public ResultBean<List<Integer>> getVersions(Integer mptid){ + return new ResultBean<>(monitorPointService.queryVersionsById(mptid)); + } + + @GetMapping("region_ranking_data") + @ApiOperation(value = "������������������", notes = "������������������") + @ApiImplicitParams(value = { + @ApiImplicitParam(name = "regionCode", value = "���������", required = true, paramType = "query", dataType = "String"), + @ApiImplicitParam(name = "dimension", value = "������(profession���region���monitorPoint������)", required = true, paramType = "query", dataType = "String"), + @ApiImplicitParam(name = "sensorKey", value = "���������key", required = true, paramType = "query", dataType = "String"), + @ApiImplicitParam(name = "accountId", value = "������id", required = true, paramType = "query", dataType = "int"), + }) + public ResultBean<List<Map<String, Object>>> getRegionRankingData(HttpServletRequest request){ + Map<String, Object> parameters = getParametersStartingWith(request, null); + List<Map<String, Object>> list = historyService.getRegionRankingData(parameters); + return new ResultBean<List<Map<String, Object>>>(list); + } + // todo + @Value(value = "classpath:system/realTimeMonitorLayout.json") + private org.springframework.core.io.Resource resource; + @ApiOperation(value = "������������������������������", notes = "") + @ApiImplicitParams(value = { + @ApiImplicitParam(name = "primaryKey",defaultValue = "898607b0101730391967", value = "���������������mac������������id", required = true, paramType = "query", dataType = "String"), + @ApiImplicitParam(name = "type", defaultValue = "device",value = "���������'monitorPoint'���'device'", required = true, paramType = "query", dataType = "String"), + }) + @GetMapping("rtm-layout") + public ResultBean realTimeMonitorLayout(String primaryKey,String type){ + InputStreamReader reader = null; + Map<String,Object> map = null; + try { + reader = new InputStreamReader(resource.getInputStream(),"UTF-8"); + map = new JSONReader(reader).readObject(new TypeReference<Map<String,Object>>() {}); + } catch (IOException e) { + e.printStackTrace(); + } + return new ResultBean(map); + } + } -- Gitblit v1.8.0