4670101279 10 months ago
parent
commit
2aa4fb69ff
  1. 6
      ruoyi-code/src/main/java/com/ruoyi/code/rtudata/controller/RtuDataController.java
  2. 14
      ruoyi-code/src/main/java/com/ruoyi/code/rtudata/domain/RtuData.java
  3. 8
      ruoyi-code/src/main/java/com/ruoyi/code/rtudata/mapper/RtuDataMapper.java
  4. 2
      ruoyi-code/src/main/java/com/ruoyi/code/rtudata/service/IRtuDataService.java
  5. 49
      ruoyi-code/src/main/java/com/ruoyi/code/rtudata/service/impl/RtuDataServiceImpl.java
  6. 17
      ruoyi-code/src/main/resources/mapper/rtudata/RtuDataMapper.xml

6
ruoyi-code/src/main/java/com/ruoyi/code/rtudata/controller/RtuDataController.java

@ -104,4 +104,10 @@ public class RtuDataController extends BaseController
return R.ok(); return R.ok();
} }
@RequestMapping("/getChart")
public R getChart(@RequestParam Map<String, Object> params){
Map<String, Object> map = rtuDataService.getChart(params);
return R.ok().put("data",map);
}
} }

14
ruoyi-code/src/main/java/com/ruoyi/code/rtudata/domain/RtuData.java

@ -1,16 +1,13 @@
package com.ruoyi.code.rtudata.domain; package com.ruoyi.code.rtudata.domain;
import java.util.Date;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.baomidou.mybatisplus.annotation.IdType; import com.baomidou.mybatisplus.annotation.IdType;
import org.apache.commons.lang3.builder.ToStringBuilder;
import org.apache.commons.lang3.builder.ToStringStyle;
import com.baomidou.mybatisplus.annotation.TableName;
import com.baomidou.mybatisplus.annotation.TableId; import com.baomidou.mybatisplus.annotation.TableId;
import com.ruoyi.common.annotation.Excel; import com.baomidou.mybatisplus.annotation.TableName;
import java.io.Serializable;
import lombok.Data; import lombok.Data;
import java.io.Serializable;
import java.util.Date;
/** /**
* 数据列表对象 rtu_data * 数据列表对象 rtu_data
@ -52,5 +49,6 @@ public class RtuData implements Serializable
/** 上报时间 */ /** 上报时间 */
private Date updDt; private Date updDt;
/** 原始数据 */
private String originData;
} }

8
ruoyi-code/src/main/java/com/ruoyi/code/rtudata/mapper/RtuDataMapper.java

@ -1,10 +1,13 @@
package com.ruoyi.code.rtudata.mapper; package com.ruoyi.code.rtudata.mapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper; import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.ruoyi.code.camera.domain.YcData;
import com.ruoyi.code.rtudata.domain.RtuData; import com.ruoyi.code.rtudata.domain.RtuData;
import org.apache.ibatis.annotations.Mapper; import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import java.util.List; import java.util.List;
import java.util.Map;
/** /**
* Mapper接口 * Mapper接口
@ -17,4 +20,9 @@ public interface RtuDataMapper extends BaseMapper<RtuData>
{ {
List<RtuData> tabsList(); List<RtuData> tabsList();
List<Integer> getSids(@Param("params") Map<String, Object> params);
List<YcData> selectWaterData(@Param("params") Map<String, Object> params);
} }

2
ruoyi-code/src/main/java/com/ruoyi/code/rtudata/service/IRtuDataService.java

@ -20,4 +20,6 @@ public interface IRtuDataService extends IService<RtuData>
R queryPage(Map<String, Object> params); R queryPage(Map<String, Object> params);
R tabsList(); R tabsList();
Map<String, Object> getChart(Map<String, Object> params);
} }

49
ruoyi-code/src/main/java/com/ruoyi/code/rtudata/service/impl/RtuDataServiceImpl.java

@ -3,6 +3,8 @@ package com.ruoyi.code.rtudata.service.impl;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage; import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ruoyi.code.camera.domain.ChartData;
import com.ruoyi.code.camera.domain.YcData;
import com.ruoyi.code.rtudata.domain.RtuData; import com.ruoyi.code.rtudata.domain.RtuData;
import com.ruoyi.code.rtudata.mapper.RtuDataMapper; import com.ruoyi.code.rtudata.mapper.RtuDataMapper;
import com.ruoyi.code.rtudata.service.IRtuDataService; import com.ruoyi.code.rtudata.service.IRtuDataService;
@ -11,6 +13,8 @@ import com.ruoyi.common.utils.Query;
import org.apache.commons.lang3.ObjectUtils; import org.apache.commons.lang3.ObjectUtils;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
@ -43,4 +47,49 @@ public class RtuDataServiceImpl extends ServiceImpl<RtuDataMapper, RtuData> impl
return R.ok().put("data", list); return R.ok().put("data", list);
} }
@Override
public Map<String, Object> getChart(Map<String, Object> params) {
Map<String, Object> map = new HashMap<>();
List<String> legend = new ArrayList<>();
List<ChartData> series = new ArrayList<>();
List<Integer> sids = baseMapper.getSids(params);
for (Integer sid : sids) {
params.put("sid", sid);
// 图表的数据
ChartData chartData = getChartOptionData(params);
if (chartData != null) {
series.add(chartData);
legend.add(chartData.getName());
}
}
map.put("legend",legend);
map.put("series",series);
return map;
}
public ChartData getChartOptionData(Map<String, Object> params){
ChartData data = null;
List<YcData> dataList = baseMapper.selectWaterData(params);
if(dataList != null && dataList.size()>0){
data = new ChartData();
data.setId(dataList.get(0).getId());
data.setName(dataList.get(0).getStnm());
String item = (String) params.get("item");
if (item.contains("降水量")){
data.setType("bar");
}else{
data.setType("line");
}
data.setData(formatChartData(dataList));
}
return data;
}
public List<Object> formatChartData(List<YcData> dataList){
List<Object> objs = new ArrayList<>();
for (int j = 0 ; j< dataList.size() ; j++){
objs.add(new Object[]{dataList.get(j).getClock()*1000,dataList.get(j).getValue()});
}
return objs;
}
} }

17
ruoyi-code/src/main/resources/mapper/rtudata/RtuDataMapper.xml

@ -7,4 +7,21 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<select id="tabsList" resultType="com.ruoyi.code.rtudata.domain.RtuData"> <select id="tabsList" resultType="com.ruoyi.code.rtudata.domain.RtuData">
SELECT DISTINCT item,item_code FROM `rtu_data` SELECT DISTINCT item,item_code FROM `rtu_data`
</select> </select>
<select id="getSids" resultType="java.lang.Integer">
SELECT DISTINCT sid FROM rtu_data
<where>
item_code = #{params.itemCode}
<if test="params.startTime != null">
and dt>=#{params.startTime}
</if>
<if test="params.endTime != null">
and dt &lt;=#{params.endTime}
</if>
</where>
</select>
<select id="selectWaterData" resultType="com.ruoyi.code.camera.domain.YcData">
SELECT id, sid as stnm, dt as tm, unix_timestamp(dt) as clock, val as value from rtu_data
where item_code = #{params.itemCode} and sid = #{params.sid} and dt>=#{params.startTime} and dt &lt;=#{params.endTime}
order by dt desc
</select>
</mapper> </mapper>

Loading…
Cancel
Save