| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490 |
- /**
- *
- */
- package com.xcgl.dataview.service.impl;
- import java.text.DecimalFormat;
- import java.text.ParseException;
- import java.util.ArrayList;
- import java.util.Date;
- import java.util.HashMap;
- import java.util.List;
- import java.util.Map;
- import org.activiti.engine.impl.util.json.JSONObject;
- import org.apache.log4j.Logger;
- import org.jeecgframework.core.common.exception.BusinessException;
- import org.jeecgframework.core.util.DateUtils;
- import org.jeecgframework.p3.core.common.utils.DateUtil;
- import org.jeecgframework.p3.core.utils.common.StringUtils;
- import org.jeecgframework.web.system.service.SystemService;
- import org.springframework.beans.factory.annotation.Autowired;
- import org.springframework.stereotype.Service;
- //import com.alibaba.druid.sql.dialect.oracle.ast.clause.SubqueryFactoringClause.Entry;
- import com.xcgl.dataview.entity.DeviceStatus;
- import com.xcgl.dataview.entity.DeviceStatusSumDto;
- import com.xcgl.dataview.entity.DeviceType;
- import com.xcgl.dataview.entity.GonglvDto;
- import com.xcgl.dataview.entity.NenghaoDto;
- import com.xcgl.dataview.entity.NenghaoType;
- import com.xcgl.dataview.entity.SensorLiveTextDto;
- import com.xcgl.dataview.entity.WarningSumDto;
- import com.xcgl.dataview.service.DataviewServiceI;
- import com.xcgl.utils.XcglDateUtils;
- import cn.com.lzt.accessory.controller.AccessoryController;
- /**
- * @author xzx
- *
- */
- @Service("dataviewService")
- public class DataviewServiceImpl implements DataviewServiceI {
- private static final Logger logger = Logger.getLogger(AccessoryController.class);
- @Autowired
- private SystemService systemService;
- /**
- * 获取最新的全部设备瞬时功率数据
- * @param valuetime 取值时间戳
- * @return
- * @throws Exception
- */
- @Override
- public List<GonglvDto> getGonglvData(Date valuetime) throws BusinessException{
- List<GonglvDto> list = new ArrayList<>();
- StringBuilder gvSql = new StringBuilder();
- gvSql.append(" SELECT ");
- gvSql.append(" id,code,name,value,recordtime");
- gvSql.append(" FROM (\r\n" +
- "select deviceid as id ,devicename as name, de.code as code,param_value as value,record.recordtime from p_sensor_record record \r\n" +
- "left join p_device de on record.deviceid = de.id\r\n" +
- "where record.typeunit = \"KW\" \r\n" + //只有单位是千瓦的设备才是可以监测瞬时功率
- "order by record.recordtime desc) a ");
- gvSql.append(" group by id ");
- List<Map<String, Object>> result = systemService.findForJdbc(gvSql.toString());
-
-
- if(result != null && result.size() > 0) {
- for(Map<String, Object> res : result)
- {
- GonglvDto gldto = new GonglvDto();
- gldto.setId(res.get("id").toString());
- gldto.setCode(res.get("code").toString());
- gldto.setName(res.get("name").toString());
- gldto.setValue(Double.valueOf(res.get("value").toString()));
- list.add(gldto);
- }
-
- }else {
-
- list.add(GonglvDto.getDemoInstance("1#变压器"));
- list.add(GonglvDto.getDemoInstance("2#变压器"));
- list.add(GonglvDto.getDemoInstance("舞台照明1"));
- list.add(GonglvDto.getDemoInstance("舞台照明2"));
- list.add(GonglvDto.getDemoInstance("主楼照明"));
- list.add(GonglvDto.getDemoInstance("热泵1"));
- list.add(GonglvDto.getDemoInstance("热泵2"));
- list.add(GonglvDto.getDemoInstance("热泵3"));
- list.add(GonglvDto.getDemoInstance("热泵4"));
- list.add(GonglvDto.getDemoInstance("变电所动力照明柜"));
- list.add(GonglvDto.getDemoInstance("北区办公及改造楼照明及空调"));
- list.add(GonglvDto.getDemoInstance("两栋小楼办公室电源"));
- list.add(GonglvDto.getDemoInstance("VRV室外空调机"));
- }
- return list;
- }
- /**
- * 获取过去monthcount个月连续的月能耗数据,当前月份为7, 获取1-6月份的月能耗
- * 算法概述:
- * 1、先查询每个设备的平均功率(算数平均值)
- * 2、按月计算所有设备平均功率合计
- * 3、累计平均功率 * 24 * 30(31)= 月能耗
- * @param monthcount
- * @return
- * @throws BusinessException
- */
- @Override
- public List<NenghaoDto> getLastContinuousNenghaoData(int monthcount)throws BusinessException{
- List<NenghaoDto> list = new ArrayList<>();
-
- StringBuilder nhSql = new StringBuilder();
- Date qryDate = DateUtil.alterMonty(DateUtil.getCurrDate(), 0- monthcount);
- nhSql.append("select sum(value) as total ,month from ");
- nhSql.append(" ( SELECT ");
- nhSql.append(" pointid, pointname, pointcode,AVG(param_value) as value ,left(recordtime,7) as month");
- nhSql.append(" FROM p_sensor_record ");
- //查询条件为当前月份往前退n个月,本月不查询
- nhSql.append(" where typeunit = \"KW\" and left(recordtime,7) >= \"").append(DateUtils.formatDate(qryDate, "yyyy-MM")).append("\" ");
- nhSql.append(" and left(recordtime,7) < \"").append( DateUtils.formatDate(DateUtil.getCurrDate(), "yyyy-MM")).append("\"");
- nhSql.append(" group by id ) tmp ");
- nhSql.append(" group by month");
- List<Map<String, Object>> result = systemService.findForJdbc(nhSql.toString());
-
- if(result != null && result.size() > 0) {
- for(Map<String, Object> res : result)
- {
- int year = Integer.parseInt(res.get("month").toString().substring(0,4));
- int month = Integer.parseInt(res.get("month").toString().substring(5,7));
- double totleGV = Double.parseDouble( res.get("total").toString());
- double gh = (month == 1 ||month == 3 || month == 5|| month == 7 || month == 8 ||month == 10 ||month == 12) ? totleGV * 31
- : ((month == 2 && year % 4 == 0 && year % 100 != 0 || year % 400 == 0) ? totleGV * 29
- :( month == 2 ? totleGV * 28: totleGV * 30));
- list.add(NenghaoDto.getDemoInstance(NenghaoType.MONTH_NENGHAO,
- year,
- month,
- 1,
- gh));
-
- }
-
- }else {
- NenghaoDto month_1 = NenghaoDto.getDemoInstance(NenghaoType.MONTH_NENGHAO, 2018, 1, 1, 21230.0);
- NenghaoDto month_2 = NenghaoDto.getDemoInstance(NenghaoType.MONTH_NENGHAO, 2018, 2, 1, 18911.7);
- NenghaoDto month_3 = NenghaoDto.getDemoInstance(NenghaoType.MONTH_NENGHAO, 2018, 3, 1, 21033.3);
- NenghaoDto month_4 = NenghaoDto.getDemoInstance(NenghaoType.MONTH_NENGHAO, 2018, 4, 1, 18122.8);
- NenghaoDto month_5 = NenghaoDto.getDemoInstance(NenghaoType.MONTH_NENGHAO, 2018, 5, 1, 18278.9);
- NenghaoDto month_6 = NenghaoDto.getDemoInstance(NenghaoType.MONTH_NENGHAO, 2018, 6, 1, 32330.6);
- list.add(month_1);
- list.add(month_2);
- list.add(month_3);
- list.add(month_4);
- list.add(month_5);
- list.add(month_6);
- }
- return list;
- }
-
- @Override
- public HashMap<String,String> getNenghaoSumData(boolean needUnit)throws BusinessException{
- HashMap<String,String> nengHaoRiYueJi = new HashMap<String,String> ();
-
- StringBuilder nhSql = new StringBuilder();
- //本季度第一天
- Date curQuarterDate = XcglDateUtils.getCurrentQuarterStartTime();
- nhSql.append("select sum(value) as total ,day ,month from \r\n" +
- " ( SELECT \r\n" +
- " pointid, pointname, pointcode,AVG(param_value) as value ,left(recordtime,10) as day,left(recordtime,7) as month\r\n" +
- " FROM p_sensor_record \r\n" +
- " where typeunit = 'KW' and left(recordtime,10) >= '").append(DateUtils.formatDate(curQuarterDate, "yyyy-MM-dd")).append("'\r\n");
- nhSql.append(" and left(recordtime,10) <= '").append(DateUtils.formatDate(new Date(), "yyyy-MM-dd")).append("'\r\n");
- nhSql.append(" group by pointid,day ) tmp \r\n" +
- " group by day");
-
- List<Map<String, Object>> result = systemService.findForJdbc(nhSql.toString());
- HashMap<String,Double> monthNenghao = new HashMap<String,Double> ();
- DecimalFormat df = new DecimalFormat("#");
- if(result != null && result.size() > 0) {
- for(Map<String, Object> res : result)
- {
- String month = res.get("month").toString();
- String day = res.get("day").toString();
- //每日功耗(根据每日功率平均值*24小时计算所得)
- Double dayTotleGV = new Double(res.get("total").toString()) * 24;
- if(day.equals(DateUtils.formatDate( new Date(), "yyyy-MM-dd")))
- {
- nengHaoRiYueJi.put("rinenghao", df.format(dayTotleGV)+ (needUnit ? "/kwh":""));
- }
- if(monthNenghao.containsKey(month))
- {
- monthNenghao.put(month, monthNenghao.get(month).doubleValue()+dayTotleGV.doubleValue());
- }else
- {
- monthNenghao.put(month, dayTotleGV);
- }
- }
- //计算月能耗
- if(monthNenghao.containsKey(DateUtils.formatDate(new Date(), "yyyy-MM")))
- {
- nengHaoRiYueJi.put("yuenenghao", df.format(monthNenghao.get(DateUtils.formatDate(new Date(), "yyyy-MM")))+ (needUnit ? "/kwh":""));
- }
- //计算季能耗
- double jinenghao = 0;
- for (java.util.Map.Entry<String,Double> entry : monthNenghao.entrySet()) {
- jinenghao += entry.getValue();
- }
- nengHaoRiYueJi.put("jinenghao", df.format(jinenghao)+ (needUnit ? "/kwh":""));
- }
- if(!nengHaoRiYueJi.containsKey("rinenghao"))
- nengHaoRiYueJi.put("rinenghao", "0.00"+ (needUnit ? "/kwh":""));
- if(!nengHaoRiYueJi.containsKey("yuenenghao"))
- nengHaoRiYueJi.put("yuenenghao", "0.00"+ (needUnit ? "/kwh":""));
- if(!nengHaoRiYueJi.containsKey("jinenghao"))
- nengHaoRiYueJi.put("jinenghao", "0.00" +(needUnit ? "/kwh":""));
- return nengHaoRiYueJi;
- }
- @Override
- public HashMap<String,String> getNenghaoSumDataByProject(boolean needUnit,String projectid)throws BusinessException{
- HashMap<String,String> nengHaoRiYueJi = new HashMap<String,String> ();
-
- StringBuilder nhSql = new StringBuilder();
- //本季度第一天
- Date curQuarterDate = XcglDateUtils.getCurrentQuarterStartTime();
- nhSql.append("select sum(value) as total ,day ,month from \r\n" +
- " ( SELECT \r\n" +
- " pointid, pointname, pointcode,AVG(param_value) as value ,left(recordtime,10) as day,left(recordtime,7) as month\r\n" +
- " FROM p_sensor_record \r\n" +
- " where projectid = '"+projectid+"' "
- + " and typeunit = 'KW' and left(recordtime,10) >= '").append(DateUtils.formatDate(curQuarterDate, "yyyy-MM-dd")).append("'\r\n");
- nhSql.append(" and left(recordtime,10) <= '").append(DateUtils.formatDate(new Date(), "yyyy-MM-dd")).append("'\r\n");
- nhSql.append(" group by pointid,day ) tmp \r\n" +
- " group by day");
-
- List<Map<String, Object>> result = systemService.findForJdbc(nhSql.toString());
- HashMap<String,Double> monthNenghao = new HashMap<String,Double> ();
- DecimalFormat df = new DecimalFormat("#");
- if(result != null && result.size() > 0) {
- for(Map<String, Object> res : result)
- {
- String month = res.get("month").toString();
- String day = res.get("day").toString();
- //每日功耗(根据每日功率平均值*24小时计算所得)
- Double dayTotleGV = new Double(res.get("total").toString()) * 24;
- if(day.equals(DateUtils.formatDate( new Date(), "yyyy-MM-dd")))
- {
- nengHaoRiYueJi.put("rinenghao", df.format(dayTotleGV)+ (needUnit ? "/kwh":""));
- }
- if(monthNenghao.containsKey(month))
- {
- monthNenghao.put(month, monthNenghao.get(month).doubleValue()+dayTotleGV.doubleValue());
- }else
- {
- monthNenghao.put(month, dayTotleGV);
- }
- }
- //计算月能耗
- if(monthNenghao.containsKey(DateUtils.formatDate(new Date(), "yyyy-MM")))
- {
- nengHaoRiYueJi.put("yuenenghao", df.format(monthNenghao.get(DateUtils.formatDate(new Date(), "yyyy-MM")))+ (needUnit ? "/kwh":""));
- }
- //计算季能耗
- double jinenghao = 0;
- for (java.util.Map.Entry<String,Double> entry : monthNenghao.entrySet()) {
- jinenghao += entry.getValue();
- }
- nengHaoRiYueJi.put("jinenghao", df.format(jinenghao)+ (needUnit ? "/kwh":""));
- }
- if(!nengHaoRiYueJi.containsKey("rinenghao"))
- nengHaoRiYueJi.put("rinenghao", "0.00"+ (needUnit ? "/kwh":""));
- if(!nengHaoRiYueJi.containsKey("yuenenghao"))
- nengHaoRiYueJi.put("yuenenghao", "0.00"+ (needUnit ? "/kwh":""));
- if(!nengHaoRiYueJi.containsKey("jinenghao"))
- nengHaoRiYueJi.put("jinenghao", "0.00" +(needUnit ? "/kwh":""));
- return nengHaoRiYueJi;
- }
- /**
- * 设备状态日期汇总,查询时间段内,每天正常设备数、离线设备数、报警设备数
- * ps、以监测点为查询维度,不以设备为查询维度
- * */
- @Override
- public List<DeviceStatusSumDto> getDeviceStatusSumData(String startDate, String endDate) throws BusinessException{
- // String startDay ,endDay;
- // try {
- // startDay = DateUtils.parseDate(endDate, "yyyy-MM-dd").toString();
- // endDay = DateUtils.parseDate(endDate, "yyyy-MM-dd").toString();
- // }catch(ParseException e)
- // {
- // logger.error(e);
- // throw new BusinessException(e.getMessage());
- // }
- List<DeviceStatusSumDto> list = new ArrayList<>();
- StringBuilder devStatusSql = new StringBuilder();
- devStatusSql.append(" select count(distinct monitor_point_id) total ,left(abn.create_date,10 ) as dataday,state");
- devStatusSql.append(" from p_sensor_abnormal abn");
- devStatusSql.append(" where abn.state = '").append(DeviceStatus.OFFLINE.getIndex()).append("'");
- devStatusSql.append(" and left(abn.create_date,10 ) >= '").append(startDate).append("'");
- devStatusSql.append(" and left(abn.create_date,10 ) <= '").append(endDate).append("'");
- devStatusSql.append(" group by dataday");
- devStatusSql.append(" union all ");
- devStatusSql.append(" select count(distinct pointid) total ,left(recordtime,10 ) as dataday,qcdstate as state ");
- devStatusSql.append(" from p_sensor_record record ");
- devStatusSql.append(" where left(recordtime,10 ) >= '").append(startDate).append("'");
- devStatusSql.append(" and left(recordtime,10 ) <= '").append(endDate).append("'");
- devStatusSql.append(" group by dataday,qcdstate");
-
- List<Map<String, Object>> result = systemService.findForJdbc(devStatusSql.toString());
- HashMap<String, DeviceStatusSumDto> value = new HashMap<String, DeviceStatusSumDto>();
- if (result != null && result.size() > 0) {
- for (Map<String, Object> res : result) {
- DeviceStatusSumDto sumDto ;
- if(value.containsKey(res.get("dataday").toString())) {
- sumDto = value.get(res.get("dataday").toString());
- }else {
- sumDto = new DeviceStatusSumDto();
- }
- sumDto.setValueTime(new Date());
- sumDto.setSumDate(res.get("dataday").toString());
- if(res.get("state").toString().equals(String.valueOf(DeviceStatus.OFFLINE.getIndex())))
- {
- sumDto.setOfflineCount(Integer.parseInt(res.get("total").toString()));
- }else if (res.get("state").toString().equals(String.valueOf(DeviceStatus.NORMAL.getIndex()))){
- sumDto.setNormalCount(Integer.parseInt(res.get("total").toString()));
- }else
- {//超上限和超下限都要sum到一起
- sumDto.setWarningCount(sumDto.getWarningCount() + Integer.parseInt(res.get("total").toString()));
- }
- value.put(res.get("dataday").toString(),sumDto);
- }
-
- for (DeviceStatusSumDto sumDto : value.values()) {
- list.add(sumDto) ;
- }
- } else {
- list.add(DeviceStatusSumDto.getDemoInstance("2018-07-01"));
- list.add(DeviceStatusSumDto.getDemoInstance("2018-07-02"));
- list.add(DeviceStatusSumDto.getDemoInstance("2018-07-03"));
- list.add(DeviceStatusSumDto.getDemoInstance("2018-07-04"));
- list.add(DeviceStatusSumDto.getDemoInstance("2018-07-05"));
- list.add(DeviceStatusSumDto.getDemoInstance("2018-07-06"));
- list.add(DeviceStatusSumDto.getDemoInstance("2018-07-07"));
- list.add(DeviceStatusSumDto.getDemoInstance("2018-07-08"));
- list.add(DeviceStatusSumDto.getDemoInstance("2018-07-09"));
- list.add(DeviceStatusSumDto.getDemoInstance("2018-07-10"));
- list.add(DeviceStatusSumDto.getDemoInstance("2018-07-11"));
- }
- return list;
- }
- @Override
- public List<WarningSumDto> getWarningSumData(String date) throws BusinessException{
- List<WarningSumDto> list = new ArrayList<>();
- //查询一个月内的数据
- Date qryDate = DateUtil.alterMonty(new Date(), -1);
- StringBuilder devStatusSql = new StringBuilder();
- devStatusSql.append(" select count(abnormal_cnt) as count ,type.type_code as type ");
- devStatusSql.append(" from p_sensor_abnormal abn");
- devStatusSql.append(" left join p_sensor_monitor_point point on abn.monitor_point_id = point.id");
- devStatusSql.append(" left join p_device dev on point.deviceid = dev.id");
- devStatusSql.append(" left join p_device_type type on dev.type_id = type.id");
- devStatusSql.append(" where type_code in ('1','2','3','4','5','6')");
- devStatusSql.append(" and left(abn.create_date,10 ) > \"").append(DateUtils.formatDate(qryDate, "yyyy-MM-dd")).append("\"");
- devStatusSql.append(" group by type.type_code");
- List<Map<String, Object>> result = systemService.findForJdbc(devStatusSql.toString());
- if (result != null && result.size() > 0) {
- for (Map<String, Object> res : result) {
- WarningSumDto sumDto = new WarningSumDto();
- sumDto.setSum(Integer.parseInt( res.get("count").toString()));
- sumDto.setDeviceType(DeviceType.values()[Integer.parseInt(res.get("type").toString())-1]);
- list.add(sumDto);
- }
- } else {
- list.add(WarningSumDto.getDemoInstance(DeviceType.FENGJIFANG));
- list.add(WarningSumDto.getDemoInstance(DeviceType.JISHUIJING));
- list.add(WarningSumDto.getDemoInstance(DeviceType.KONGTIAO));
- list.add(WarningSumDto.getDemoInstance(DeviceType.PENLINBENG));
- list.add(WarningSumDto.getDemoInstance(DeviceType.SHENGHUOBENG));
- list.add(WarningSumDto.getDemoInstance(DeviceType.XIAOFANGBENG));
- }
- return list;
- }
-
- @Override
- public List<SensorLiveTextDto> getSensorLiveTextDto() throws BusinessException{
- List<SensorLiveTextDto> list = new ArrayList<>();
- // 只查询当天数据
- //先查出最新的(table: p_sensor_record),正常以及超上下限的数据
- StringBuilder sensorLiveSql = new StringBuilder();
- sensorLiveSql.append("select deviceid,devicecode,devicename,pointid,pointcode,pointname,value,recordtime,qcdstate,value from(");
- sensorLiveSql.append(" select record.deviceid as deviceid ,record.devicename as devicename,de.code as devicecode,pointid,pointcode,pointname,param_value as value,recordtime,record.qcdstate as qcdstate");
- sensorLiveSql.append(" from p_sensor_record record ");
- sensorLiveSql.append(" left join p_device de on record.deviceid = de.id");
- // sensorLiveSql.append(" left join p_device de on record.deviceid = de.id");
- sensorLiveSql.append(" where left(recordtime,10 ) = '").append(DateUtils.formatDate(new Date(),"yyyy-MM-dd")).append("'");
- sensorLiveSql.append(" order by recordtime desc) tmp");
- sensorLiveSql.append(" group by pointid");
- List<Map<String, Object>> result = systemService.findForJdbc(sensorLiveSql.toString());
- HashMap<String,String> pointids = new HashMap<String,String> ();
- if (result != null && result.size() > 0) {
- for (Map<String, Object> res : result) {
- SensorLiveTextDto sliveDto = new SensorLiveTextDto();
- sliveDto.setDevice_code(res.get("devicecode").toString());
- sliveDto.setDevice_id(res.get("deviceid").toString());
- sliveDto.setDevice_name(res.get("devicename").toString());
- sliveDto.setSensor_id(res.get("pointid").toString());
- sliveDto.setSensor_code(res.get("pointcode").toString());
- sliveDto.setSensor_name(res.get("pointname").toString());
- if(StringUtils.isNotEmpty(res.get("value").toString())) {
- sliveDto.setValue(Double.valueOf(res.get("value").toString()));
- }else {
- continue;
- }
- sliveDto.setStatus(DeviceStatus.getDeviceStatus(Integer.parseInt(res.get("qcdstate").toString())));
- try {
- String recordtime = res.get("recordtime").toString();
- // if(recordtime.length()>19) {
- // recordtime = recordtime.substring(0, 19);
- // }
- sliveDto.setValueTime(DateUtils.parseDate(recordtime, "yyyy-MM-dd HH:mm:ss"));
- } catch (ParseException e) {
- logger.error(e);
- }
- list.add(sliveDto);
- pointids.put(res.get("pointid").toString(),res.get("pointid").toString());
- }
- }
-
- // 查询离线数据
- sensorLiveSql = new StringBuilder();
- sensorLiveSql.append(
- "select deviceid,devicecode,devicename,pointid,pointcode,pointname,value,recordtime,qcdstate,value from(");
- sensorLiveSql.append(
- " select point.deviceid as deviceid ,dev.name as devicename,dev.code as devicecode,monitor_point_id as pointid,");
- sensorLiveSql.append(
- " point.code as pointcode, point.name as pointname, '' as value,abn.create_date as recordtime,abn.state as qcdstate");
-
- sensorLiveSql.append(" from p_sensor_abnormal abn");
- sensorLiveSql.append(" left join p_sensor_monitor_point point on abn.monitor_point_id = point.id");
- sensorLiveSql.append(" left join p_device dev on point.deviceid = dev.id");
- sensorLiveSql.append(" where abn.state = '").append(DeviceStatus.OFFLINE.getIndex()).append("'");
- sensorLiveSql.append(" and left(abn.create_date,10 ) = '").append(DateUtils.formatDate(new Date(),"yyyy-MM-dd")).append("'");
- sensorLiveSql.append(" order by abn.create_date desc) tmp");
- sensorLiveSql.append(" group by pointid");
-
- result = systemService.findForJdbc(sensorLiveSql.toString());
-
- if (result != null && result.size() > 0) {
- for (Map<String, Object> res : result) {
- if(pointids.containsKey(res.get("pointid").toString()))
- continue;
- SensorLiveTextDto sliveDto = new SensorLiveTextDto();
- sliveDto.setDevice_code(res.get("devicecode").toString());
- sliveDto.setDevice_id(res.get("deviceid").toString());
- sliveDto.setDevice_name(res.get("devicename").toString());
- sliveDto.setSensor_id(res.get("pointid").toString());
- sliveDto.setSensor_code(res.get("pointcode").toString());
- sliveDto.setSensor_name(res.get("pointname").toString());
- if(StringUtils.isNotEmpty(res.get("value").toString())) {
- sliveDto.setValue(Double.valueOf(res.get("value").toString()));
- }else {
- continue;
- }
- sliveDto.setStatus(DeviceStatus.values()[Integer.parseInt(res.get("qcdstate").toString())-1]);
- try {
- sliveDto.setValueTime(DateUtils.parseDate(res.get("recordtime").toString(), "yyyy-MM-dd HH:mm:ss"));
- } catch (ParseException e) {
- logger.error(e);
- }
- list.add(sliveDto);
- }
- }
- return list;
- }
-
- @Override
- public Map<String, Object> getDeviceCode2ValueMap() throws BusinessException{
- List<SensorLiveTextDto> list = getSensorLiveTextDto();
- if(list != null && list.size()>0) {
- Map<String,Object> map = new HashMap<String, Object>();
- for(SensorLiveTextDto dto : list) {
- String deviceCode = dto.getSensor_code();
- Double value = dto.getValue();
- map.put(deviceCode, JSONObject.doubleToString(value));
- }
- return map;
- }
-
- return null;
- }
- }
|