5 files added
	
		
		7 files modified
	
	
 
	
	
	
	
	
	
	
	
|  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | import com.moral.common.bean.ResultBean; | 
|---|
|  |  |  | import com.moral.entity.charts.LineChartCriteria; | 
|---|
|  |  |  | import com.moral.service.AlarmService; | 
|---|
|  |  |  | import com.moral.service.AlarmDailyService; | 
|---|
|  |  |  | import com.moral.service.HistoryMinutelyService; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @SuppressWarnings({ "unchecked", "rawtypes" }) | 
|---|
|  |  |  | 
|---|
|  |  |  | private HistoryMinutelyService historyMinutelyService; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Resource | 
|---|
|  |  |  | private AlarmService alarmService; | 
|---|
|  |  |  | private AlarmDailyService alarmDailyService; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @GetMapping("compare") | 
|---|
|  |  |  | public ResultBean<Map<String, List>> getCompareReport(HttpServletRequest request) throws Exception { | 
|---|
|  |  |  | 
|---|
|  |  |  | @GetMapping("pie") | 
|---|
|  |  |  | public ResultBean<Map<String, Object>> getPieData(HttpServletRequest request) throws Exception { | 
|---|
|  |  |  | Map<String, Object> parameters = getParametersStartingWith(request, null); | 
|---|
|  |  |  | Map pieData = alarmService.getPieData(parameters); | 
|---|
|  |  |  | Map pieData = alarmDailyService.getPieData(parameters); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | return new ResultBean<Map<String, Object>>(pieData); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @GetMapping("alarm-year") | 
|---|
|  |  |  | public ResultBean<List<Integer>> getAlarmDataByYear(HttpServletRequest request) throws Exception { | 
|---|
|  |  |  | Map<String, Object> parameters = getParametersStartingWith(request, null); | 
|---|
|  |  |  | List<Integer> alarmDataByYear = alarmDailyService.getAlarmDataByYear(parameters); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | return new ResultBean<List<Integer>>(alarmDataByYear); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | } | 
|---|
|  |  |  | 
|---|
|  |  |  | import java.io.ByteArrayInputStream; | 
|---|
|  |  |  | import java.io.InputStream; | 
|---|
|  |  |  | import java.io.InputStreamReader; | 
|---|
|  |  |  | import java.net.InetAddress; | 
|---|
|  |  |  | import java.net.URL; | 
|---|
|  |  |  | import java.net.URLConnection; | 
|---|
|  |  |  | import java.util.ArrayList; | 
|---|
|  |  |  | import java.util.HashMap; | 
|---|
|  |  |  | import java.util.LinkedHashMap; | 
|---|
|  |  |  | 
|---|
|  |  |  | 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.AlarmDailyService; | 
|---|
|  |  |  | import com.moral.service.AreaService; | 
|---|
|  |  |  | import com.moral.service.DeviceService; | 
|---|
|  |  |  | import com.moral.service.HistoryMinutelyService; | 
|---|
|  |  |  | 
|---|
|  |  |  | private String levelKey = "alarm_"; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Resource | 
|---|
|  |  |  | private AlarmService alarmService; | 
|---|
|  |  |  | private AlarmDailyService alarmDailyService; | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | * Screen login. 大屏登录 | 
|---|
|  |  |  | * | 
|---|
|  |  |  | 
|---|
|  |  |  | parameters.remove("organizationId"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | Map pieData = alarmService.getPieData(parameters); | 
|---|
|  |  |  | Map pieData = alarmDailyService.getPieData(parameters); | 
|---|
|  |  |  | List<Map<String, Object>> list = (List<Map<String, Object>>) pieData.get(sensorKey); | 
|---|
|  |  |  | return new ResultBean<List<Map<String, Object>>>(list); | 
|---|
|  |  |  | } | 
|---|
| New file | 
|  |  |  | 
|---|
|  |  |  | package com.moral.entity; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | import java.util.Date; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | import lombok.Data; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Data | 
|---|
|  |  |  | public class AlarmDaily { | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | * | 
|---|
|  |  |  | * This field was generated by MyBatis Generator. | 
|---|
|  |  |  | * This field corresponds to the database column alarm.mac | 
|---|
|  |  |  | * | 
|---|
|  |  |  | * @mbg.generated Mon Apr 16 09:27:36 CST 2018 | 
|---|
|  |  |  | */ | 
|---|
|  |  |  | private String mac; | 
|---|
|  |  |  | private Integer state; | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | * | 
|---|
|  |  |  | * This field was generated by MyBatis Generator. | 
|---|
|  |  |  | * This field corresponds to the database column alarm.json | 
|---|
|  |  |  | * | 
|---|
|  |  |  | * @mbg.generated Mon Apr 16 09:27:36 CST 2018 | 
|---|
|  |  |  | */ | 
|---|
|  |  |  | private String json; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | * | 
|---|
|  |  |  | * This field was generated by MyBatis Generator. | 
|---|
|  |  |  | * This field corresponds to the database column alarm.time | 
|---|
|  |  |  | * | 
|---|
|  |  |  | * @mbg.generated Mon Apr 16 09:27:36 CST 2018 | 
|---|
|  |  |  | */ | 
|---|
|  |  |  | private Date time; | 
|---|
|  |  |  | } | 
|---|
| New file | 
|  |  |  | 
|---|
|  |  |  | package com.moral.mapper; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | import java.util.List; | 
|---|
|  |  |  | import java.util.Map; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | import com.moral.common.mapper.BaseMapper; | 
|---|
|  |  |  | import com.moral.entity.AlarmDaily; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | public interface AlarmDailyMapper extends BaseMapper<AlarmDaily> { | 
|---|
|  |  |  |  | 
|---|
|  |  |  | List<Map<String, Object>> getAlarmData(Map<String, Object> parameters); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | List<Map<String, Object>> getAlarmDataByYear(Map<String, Object> parameters); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | } | 
|---|
|  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | public interface AlarmMapper extends BaseMapper<Alarm> { | 
|---|
|  |  |  |  | 
|---|
|  |  |  | List<Map<String, Object>> getAlarmData(Map<String, Object> parameters); | 
|---|
|  |  |  | List<Map> countByTimes(@Param("start")Date start, @Param("end")Date end, @Param("format")String format); | 
|---|
|  |  |  | } | 
|---|
| New file | 
|  |  |  | 
|---|
|  |  |  | package com.moral.service; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | import java.util.List; | 
|---|
|  |  |  | import java.util.Map; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @SuppressWarnings("rawtypes") | 
|---|
|  |  |  | public interface AlarmDailyService { | 
|---|
|  |  |  |  | 
|---|
|  |  |  | Map getPieData(Map<String, Object> parameters); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | List<Integer> getAlarmDataByYear(Map<String, Object> parameters); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | } | 
|---|
|  |  |  | 
|---|
|  |  |  | package com.moral.service; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | import com.moral.entity.charts.TimeUnits; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | import java.util.Date; | 
|---|
|  |  |  | import java.util.List; | 
|---|
|  |  |  | import java.util.Map; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | import com.moral.entity.charts.TimeUnits; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @SuppressWarnings("rawtypes") | 
|---|
|  |  |  | public interface AlarmService { | 
|---|
|  |  |  |  | 
|---|
|  |  |  | List<Map> countByTimes(Date start, Date end, TimeUnits timeUnits); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | Map getPieData(Map<String, Object> parameters); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | } | 
|---|
| New file | 
|  |  |  | 
|---|
|  |  |  | package com.moral.service.impl; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | import java.text.ParseException; | 
|---|
|  |  |  | import java.time.LocalDate; | 
|---|
|  |  |  | import java.time.temporal.TemporalAdjusters; | 
|---|
|  |  |  | import java.util.ArrayList; | 
|---|
|  |  |  | import java.util.Arrays; | 
|---|
|  |  |  | import java.util.HashMap; | 
|---|
|  |  |  | import java.util.LinkedHashMap; | 
|---|
|  |  |  | import java.util.List; | 
|---|
|  |  |  | import java.util.Map; | 
|---|
|  |  |  | import java.util.stream.Collectors; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | import javax.annotation.Resource; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | import org.springframework.stereotype.Service; | 
|---|
|  |  |  | import org.springframework.util.ObjectUtils; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | import com.moral.mapper.AlarmDailyMapper; | 
|---|
|  |  |  | import com.moral.mapper.SensorMapper; | 
|---|
|  |  |  | import com.moral.service.AlarmDailyService; | 
|---|
|  |  |  | import com.moral.service.HistoryMinutelyService; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Service | 
|---|
|  |  |  | @SuppressWarnings({ "rawtypes", "unchecked" }) | 
|---|
|  |  |  | public class AlarmDailyServiceImpl implements AlarmDailyService { | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Resource | 
|---|
|  |  |  | private AlarmDailyMapper alarmDailyMapper; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Resource | 
|---|
|  |  |  | private SensorMapper sensorMapper; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Resource | 
|---|
|  |  |  | private HistoryMinutelyService historyMinutelyService; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @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 = alarmDailyMapper.getAlarmData(parameters); | 
|---|
|  |  |  | 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); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } else { | 
|---|
|  |  |  | Map<String, Object> alarmData = alarmDatas.get(0); | 
|---|
|  |  |  | List<String> sensors = (List<String>) parameters.get("sensors"); | 
|---|
|  |  |  | List list = new ArrayList(); | 
|---|
|  |  |  | if (!ObjectUtils.isEmpty(alarmData)) { | 
|---|
|  |  |  | 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>(); | 
|---|
|  |  |  | if (parameters.containsKey("description")) { | 
|---|
|  |  |  | map.put("name", split[3]); | 
|---|
|  |  |  | } else { | 
|---|
|  |  |  | map.put("name", split[1]); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | map.put("value", alarmData.get(key)); | 
|---|
|  |  |  | list.add(map); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | resultMap.put("list", list); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | return resultMap; | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Override | 
|---|
|  |  |  | public List<Integer> getAlarmDataByYear(Map<String, Object> parameters) { | 
|---|
|  |  |  | LocalDate localDate = LocalDate.now(); | 
|---|
|  |  |  | parameters.put("start", localDate.with(TemporalAdjusters.firstDayOfYear())); | 
|---|
|  |  |  | parameters.put("end", localDate.with(TemporalAdjusters.firstDayOfNextYear())); | 
|---|
|  |  |  | parameters.put("sensorKeys", | 
|---|
|  |  |  | sensorMapper.selectAll().stream().map(sensor -> sensor.getSensorKey()).collect(Collectors.toList())); | 
|---|
|  |  |  | List<Map<String, Object>> list = alarmDailyMapper.getAlarmDataByYear(parameters); | 
|---|
|  |  |  | Integer[] result = new Integer[12]; | 
|---|
|  |  |  | for (int i = 0; i < result.length; i++) { | 
|---|
|  |  |  | if (ObjectUtils.isEmpty(list)) { | 
|---|
|  |  |  | break; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | for (Map<String, Object> map : list) { | 
|---|
|  |  |  | Integer month = Integer.valueOf(map.get("time").toString().substring(5)); | 
|---|
|  |  |  | if (i + 1 < month) { | 
|---|
|  |  |  | break; | 
|---|
|  |  |  | } else if (i + 1 == month) { | 
|---|
|  |  |  | result[i] = Integer.valueOf(map.get("sum").toString()); | 
|---|
|  |  |  | list.remove(map); | 
|---|
|  |  |  | break; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | return Arrays.asList(result); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | } | 
|---|
|  |  |  | 
|---|
|  |  |  | package com.moral.service.impl; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | import java.text.ParseException; | 
|---|
|  |  |  | import java.util.*; | 
|---|
|  |  |  | import java.util.Date; | 
|---|
|  |  |  | import java.util.List; | 
|---|
|  |  |  | import java.util.Map; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | import javax.annotation.Resource; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | import com.moral.entity.charts.TimeUnits; | 
|---|
|  |  |  | import org.springframework.stereotype.Service; | 
|---|
|  |  |  | import org.springframework.util.ObjectUtils; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | import com.moral.entity.charts.TimeUnits; | 
|---|
|  |  |  | import com.moral.mapper.AlarmMapper; | 
|---|
|  |  |  | import com.moral.service.AlarmService; | 
|---|
|  |  |  | import com.moral.service.HistoryMinutelyService; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Service | 
|---|
|  |  |  | @SuppressWarnings({ "rawtypes", "unchecked" }) | 
|---|
|  |  |  | @SuppressWarnings({ "rawtypes" }) | 
|---|
|  |  |  | public class AlarmServiceImpl implements AlarmService { | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Resource | 
|---|
|  |  |  | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | return alarmMapper.countByTimes(start, end, format); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | @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); | 
|---|
|  |  |  | 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); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } else { | 
|---|
|  |  |  | Map<String, Object> alarmData = alarmDatas.get(0); | 
|---|
|  |  |  | List<String> sensors = (List<String>) parameters.get("sensors"); | 
|---|
|  |  |  | List list = new ArrayList(); | 
|---|
|  |  |  | if (!ObjectUtils.isEmpty(alarmData)) { | 
|---|
|  |  |  | 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>(); | 
|---|
|  |  |  | if (parameters.containsKey("description")) { | 
|---|
|  |  |  | map.put("name", split[3]); | 
|---|
|  |  |  | } else { | 
|---|
|  |  |  | map.put("name", split[1]); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | map.put("value", alarmData.get(key)); | 
|---|
|  |  |  | list.add(map); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | resultMap.put("list", list); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | return resultMap; | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | } | 
|---|
|  |  |  | 
|---|
|  |  |  | import com.moral.entity.charts.DataCondition; | 
|---|
|  |  |  | import com.moral.entity.charts.LineChartCriteria; | 
|---|
|  |  |  | import com.moral.entity.charts.TimePeriod; | 
|---|
|  |  |  | import com.moral.mapper.AlarmDailyMapper; | 
|---|
|  |  |  | import com.moral.mapper.AlarmMapper; | 
|---|
|  |  |  | import com.moral.mapper.DeviceMapper; | 
|---|
|  |  |  | import com.moral.mapper.HistoryMinutelyMapper; | 
|---|
|  |  |  | 
|---|
|  |  |  | private SensorMapper sensorMapper; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Resource | 
|---|
|  |  |  | private AlarmMapper alarmMapper; | 
|---|
|  |  |  | private AlarmDailyMapper alarmDailyMapper; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Override | 
|---|
|  |  |  | public Map<String, Object> getDayAQIByDevice(Map<String, Object> parameters) { | 
|---|
|  |  |  | 
|---|
|  |  |  | Object type = parameters.get("type"); | 
|---|
|  |  |  | if ("year".equals(type) || "month".equals(type)) { | 
|---|
|  |  |  | parameters.put("sensorKeys", Arrays.asList("e1", "e2", "e10", "e11", "e15", "e16")); | 
|---|
|  |  |  | resultMap.put("alarmData" + part, alarmMapper.getAlarmData(parameters).get(0)); | 
|---|
|  |  |  | resultMap.put("alarmData" + part, alarmDailyMapper.getAlarmData(parameters).get(0)); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | return resultMap; | 
|---|
|  |  |  | } | 
|---|
| New file | 
|  |  |  | 
|---|
|  |  |  | <?xml version="1.0" encoding="UTF-8"?> | 
|---|
|  |  |  | <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd"> | 
|---|
|  |  |  | <mapper namespace="com.moral.mapper.AlarmDailyMapper"> | 
|---|
|  |  |  | <select id="getAlarmData" resultType="java.util.LinkedHashMap"> | 
|---|
|  |  |  | SELECT | 
|---|
|  |  |  | <if test="dimension=='monitorPoint'"> | 
|---|
|  |  |  | `name`, | 
|---|
|  |  |  | </if> | 
|---|
|  |  |  | <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> | 
|---|
|  |  |  | <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> | 
|---|
|  |  |  | h.time | 
|---|
|  |  |  | </otherwise> | 
|---|
|  |  |  | </choose> | 
|---|
|  |  |  | FROM | 
|---|
|  |  |  | alarm_daily h, | 
|---|
|  |  |  | device d, | 
|---|
|  |  |  | monitor_point mp | 
|---|
|  |  |  | WHERE d.monitor_point_id = mp.id | 
|---|
|  |  |  | AND h.mac = d.mac | 
|---|
|  |  |  | AND h.time >= #{start} | 
|---|
|  |  |  | AND h.time <![CDATA[<]]> #{end} | 
|---|
|  |  |  | <if test="provinceCode != null"> | 
|---|
|  |  |  | AND mp.province_code = #{provinceCode} | 
|---|
|  |  |  | </if> | 
|---|
|  |  |  | <if test="cityCode != null"> | 
|---|
|  |  |  | AND mp.city_code = #{cityCode} | 
|---|
|  |  |  | </if> | 
|---|
|  |  |  | <if test="areaCode != null"> | 
|---|
|  |  |  | AND mp.area_code = #{areaCode} | 
|---|
|  |  |  | </if> | 
|---|
|  |  |  | <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> | 
|---|
|  |  |  | <if test="level != null"> | 
|---|
|  |  |  | AND h.state = #{level} | 
|---|
|  |  |  | </if> | 
|---|
|  |  |  | GROUP BY | 
|---|
|  |  |  | <if test="dimension=='monitorPoint'"> | 
|---|
|  |  |  | mp.id, | 
|---|
|  |  |  | </if> | 
|---|
|  |  |  | h.time | 
|---|
|  |  |  | ) a | 
|---|
|  |  |  | <if test="dimension=='monitorPoint'"> | 
|---|
|  |  |  | GROUP BY name | 
|---|
|  |  |  | </if> | 
|---|
|  |  |  |  | 
|---|
|  |  |  | </select> | 
|---|
|  |  |  |  | 
|---|
|  |  |  | <select id="getAlarmDataByYear" resultType="java.util.Map"> | 
|---|
|  |  |  | SELECT | 
|---|
|  |  |  | DATE_FORMAT(h.time, '%Y-%m') AS 'time' | 
|---|
|  |  |  | <foreach collection="sensorKeys" open="," separator="+" close=" AS 'sum' " item="sensorKey"> | 
|---|
|  |  |  | COUNT(json -> '$.${sensorKey}') | 
|---|
|  |  |  | </foreach> | 
|---|
|  |  |  | FROM | 
|---|
|  |  |  | alarm_daily h | 
|---|
|  |  |  | WHERE | 
|---|
|  |  |  | h.time >= #{start} | 
|---|
|  |  |  | AND h.time <![CDATA[<]]> #{end} | 
|---|
|  |  |  | <if test="state != null"> | 
|---|
|  |  |  | AND h.state = #{state} | 
|---|
|  |  |  | </if> | 
|---|
|  |  |  | GROUP BY | 
|---|
|  |  |  | DATE_FORMAT(h.time, '%Y-%m') | 
|---|
|  |  |  | </select> | 
|---|
|  |  |  |  | 
|---|
|  |  |  | </mapper> | 
|---|
|  |  |  | 
|---|
|  |  |  | <?xml version="1.0" encoding="UTF-8"?> | 
|---|
|  |  |  | <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd"> | 
|---|
|  |  |  | <mapper namespace="com.moral.mapper.AlarmMapper"> | 
|---|
|  |  |  | <select id="getAlarmData" resultType="java.util.LinkedHashMap"> | 
|---|
|  |  |  | SELECT | 
|---|
|  |  |  | <if test="dimension=='monitorPoint'"> | 
|---|
|  |  |  | `name`, | 
|---|
|  |  |  | </if> | 
|---|
|  |  |  | <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> | 
|---|
|  |  |  | <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> | 
|---|
|  |  |  | h.time | 
|---|
|  |  |  | </otherwise> | 
|---|
|  |  |  | </choose> | 
|---|
|  |  |  | FROM | 
|---|
|  |  |  | alarm_daily h, | 
|---|
|  |  |  | device d, | 
|---|
|  |  |  | monitor_point mp | 
|---|
|  |  |  | WHERE d.monitor_point_id = mp.id | 
|---|
|  |  |  | AND h.mac = d.mac | 
|---|
|  |  |  | AND h.time >= #{start} | 
|---|
|  |  |  | AND h.time <![CDATA[<]]> #{end} | 
|---|
|  |  |  | <if test="provinceCode != null"> | 
|---|
|  |  |  | AND mp.province_code = #{provinceCode} | 
|---|
|  |  |  | </if> | 
|---|
|  |  |  | <if test="cityCode != null"> | 
|---|
|  |  |  | AND mp.city_code = #{cityCode} | 
|---|
|  |  |  | </if> | 
|---|
|  |  |  | <if test="areaCode != null"> | 
|---|
|  |  |  | AND mp.area_code = #{areaCode} | 
|---|
|  |  |  | </if> | 
|---|
|  |  |  | <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> | 
|---|
|  |  |  | <if test="level != null"> | 
|---|
|  |  |  | AND h.state = #{level} | 
|---|
|  |  |  | </if> | 
|---|
|  |  |  | GROUP BY | 
|---|
|  |  |  | <if test="dimension=='monitorPoint'"> | 
|---|
|  |  |  | mp.id, | 
|---|
|  |  |  | </if> | 
|---|
|  |  |  | h.time | 
|---|
|  |  |  | ) a | 
|---|
|  |  |  | <if test="dimension=='monitorPoint'"> | 
|---|
|  |  |  | GROUP BY name | 
|---|
|  |  |  | </if> | 
|---|
|  |  |  |  | 
|---|
|  |  |  | </select> | 
|---|
|  |  |  | <select id="countByTimes"   resultType="java.util.Map"> | 
|---|
|  |  |  | select | 
|---|
|  |  |  | <if test="format !=null"> | 
|---|