src/main/java/com/moral/controller/ScreenController.java | ●●●●● patch | view | raw | blame | history | |
src/main/java/com/moral/service/impl/AlarmServiceImpl.java | ●●●●● patch | view | raw | blame | history | |
src/main/resources/mapper/AlarmMapper.xml | ●●●●● patch | view | raw | blame | history |
src/main/java/com/moral/controller/ScreenController.java
@@ -26,6 +26,7 @@ import org.springframework.beans.factory.annotation.Value; import org.springframework.data.redis.core.RedisTemplate; import org.springframework.security.access.prepost.PreAuthorize; import org.springframework.util.ObjectUtils; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.RequestBody; @@ -40,6 +41,7 @@ import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSONArray; import com.alibaba.fastjson.JSONObject; import com.moral.common.bean.Constants; import com.moral.common.bean.JsonData; import com.moral.common.bean.PageResult; import com.moral.common.bean.ResultBean; @@ -53,6 +55,7 @@ import com.moral.entity.alarm.AlarmSensorLevel; import com.moral.service.AccountService; import com.moral.service.AlarmConfigService; import com.moral.service.AlarmService; import com.moral.service.AreaService; import com.moral.service.DeviceService; import com.moral.service.HistoryMinutelyService; @@ -67,6 +70,7 @@ @RestController @RequestMapping("/screen") //@CrossOrigin(origins = "*", maxAge = 3600) @SuppressWarnings({ "rawtypes", "unchecked", "unused" }) public class ScreenController { public static Logger log = Logger.getLogger(ScreenController.class); @Resource @@ -108,6 +112,8 @@ /** The level key. */ private String levelKey = "alarm_"; @Resource private AlarmService alarmService; /** * Screen login. 大屏登录 * @@ -150,7 +156,6 @@ * the request * @return the alarm levels */ @SuppressWarnings("resource") @GetMapping("alarm-levels") public Object getAlarmLevels(HttpServletRequest request, Integer orgId) { List<Map<String,Object>> sensorAlarmList = null; @@ -445,4 +450,27 @@ } return new ResultBean<List<Map<String, Object>>>(list); } @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"); String sensorKey = "list"; if (!ObjectUtils.isEmpty(parameters.get("sensorKey"))) { sensorKey = parameters.remove("sensorKey").toString(); List<String> sensorKeys = new ArrayList<String>(); sensorKeys.add(sensorKey); parameters.put("sensors", sensorKeys); } if (!ObjectUtils.isEmpty(parameters.get("organizationId"))) { if (!Constants.isNotSpecialOrgId(Integer.valueOf(parameters.get("organizationId").toString()))) { parameters.remove("organizationId"); } } Map pieData = alarmService.getPieData(parameters); List<Map<String, Object>> list = (List<Map<String, Object>>) pieData.get(sensorKey); return new ResultBean<List<Map<String, Object>>>(list); } } src/main/java/com/moral/service/impl/AlarmServiceImpl.java
@@ -28,33 +28,52 @@ @Override public Map getPieData(Map<String, Object> parameters) { Map<String, Object> resultMap = new LinkedHashMap<String, Object>(); try { historyMinutelyService.convertQueryParam(parameters); } catch (ParseException e) { e.printStackTrace(); } List<Map<String, Object>> alarmDatas = alarmMapper.getAlarmData(parameters); Map<String, List> resultMap = new LinkedHashMap<String, List>(); for (Map<String, Object> alarmData : alarmDatas) { String name = alarmData.remove("name").toString(); alarmData.remove("sum"); for (Map.Entry<String, Object> entry : alarmData.entrySet()) { String key = entry.getKey(); Object value = entry.getValue().toString(); if (!"0".equals(value)) { List list; Map<String, Object> map = new HashMap<String, Object>(); if (ObjectUtils.isEmpty(resultMap.get(key))) { list = new ArrayList(); } else { list = resultMap.get(key); Object dimension = parameters.get("dimension"); if ("monitorPoint".equals(dimension)) { for (Map<String, Object> alarmData : alarmDatas) { String name = alarmData.remove("name").toString(); alarmData.remove("sum"); for (Map.Entry<String, Object> entry : alarmData.entrySet()) { String key = entry.getKey(); Object value = entry.getValue().toString(); if (!"0".equals(value)) { List list; Map<String, Object> map = new HashMap<String, Object>(); if (ObjectUtils.isEmpty(resultMap.get(key))) { list = new ArrayList(); } else { list = (List) resultMap.get(key); } map.put("name", name); map.put("value", value); list.add(map); resultMap.put(key, list); } map.put("name", name); map.put("value", value); list.add(map); resultMap.put(key, list); } } } else { Map<String, Object> alarmData = alarmDatas.get(0); List<String> sensors = (List<String>) parameters.get("sensors"); List list = new ArrayList(); for (String key : alarmData.keySet()) { for (String sensor : sensors) { String[] split = sensor.split("-"); if (key.equals(split[0]) && !"0".equals(alarmData.get(key).toString())) { Map<String, Object> map = new HashMap<String, Object>(); map.put("name", split[1]); map.put("value", alarmData.get(key)); list.add(map); } } } resultMap.put("list", list); } return resultMap; } src/main/resources/mapper/AlarmMapper.xml
@@ -6,21 +6,35 @@ <if test="dimension=='monitorPoint'"> `name`, </if> <foreach collection="sensorKeys" item="sensorKey" separator=","> SUM( ${sensorKey} ) AS '${sensorKey}' </foreach> <foreach close=" AS 'sum' " collection="sensorKeys" item="sensorKey" open="," separator="+"> SUM( ${sensorKey} ) </foreach> <choose> <when test="sensorKeys.size > 0"> <foreach collection="sensorKeys" separator="," item="sensorKey"> SUM( ${sensorKey} ) AS '${sensorKey}' </foreach> <foreach collection="sensorKeys" open="," separator="+" close=" AS 'sum' " item="sensorKey"> SUM( ${sensorKey} ) </foreach> </when> <otherwise> time </otherwise> </choose> FROM ( SELECT <if test="dimension=='monitorPoint'"> mp.`name`, </if> <foreach collection="sensorKeys" item="sensorKey" separator=","> CASE COUNT( json -> '$.${sensorKey}' ) WHEN 0 THEN 0 ELSE 1 END AS '${sensorKey}' </foreach> <choose> <when test="sensorKeys.size > 0"> <foreach collection="sensorKeys" separator="," item="sensorKey"> CASE COUNT( json -> '$.${sensorKey}' ) WHEN 0 THEN 0 ELSE 1 END AS '${sensorKey}' </foreach> </when> <otherwise> DATE_FORMAT( h.time, '%Y-%m-%d' ) AS 'time' </otherwise> </choose> FROM alarm h, device d, @@ -41,6 +55,9 @@ <if test="monitorPointId != null"> AND mp.id = #{monitorPointId} </if> <if test="organizationId != null"> AND mp.organization_id = #{organizationId} </if> <if test="mac != null"> AND d.mac = #{mac} </if>