Commit fdd9e7b5 authored by LiuZunBo's avatar LiuZunBo

降雨量

parent d09a4c4f
...@@ -30,6 +30,11 @@ public interface RgDataMapper extends BaseMapper<RgData> { ...@@ -30,6 +30,11 @@ public interface RgDataMapper extends BaseMapper<RgData> {
@Select(value = "SELECT SUM(a.rainfall)as rainfall ,a.time FROM (select * from tb_rg_data ${ew.customSqlSegment})a GROUP BY a.time") @Select(value = "SELECT SUM(a.rainfall)as rainfall ,a.time FROM (select * from tb_rg_data ${ew.customSqlSegment})a GROUP BY a.time")
List<RgData> imgList(@Param("ew") Wrapper wrapper); List<RgData> imgList(@Param("ew") Wrapper wrapper);
@Select(value = "SELECT SUM(a.rainfall)as rainfall ,a.time FROM (select * from tb_rg_data ${ew.customSqlSegment})a GROUP BY DATE_FORMAT( a.time, '%y-%m' )")
List<RgData> imgListGroupByMonth(@Param("ew") Wrapper wrapper);
List<RgData> imgListGroupByHour(@Param("ew") Wrapper wrapper,@Param("hour") int hour);
List<RgData> week(String start, String end, String sensorid); List<RgData> week(String start, String end, String sensorid);
} }
package me.zhengjie.gemho.service.data.impl; package me.zhengjie.gemho.service.data.impl;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
...@@ -302,9 +303,9 @@ public class RgDataServiceImpl extends ServiceImpl<RgDataMapper, RgData> impleme ...@@ -302,9 +303,9 @@ public class RgDataServiceImpl extends ServiceImpl<RgDataMapper, RgData> impleme
//计算差值 //计算差值
Double aDouble = Double.valueOf(record.getRainfall()); Double aDouble = Double.valueOf(record.getRainfall());
Double aDouble1 = Double.valueOf(record.getJcvalue()); Double aDouble1 = Double.valueOf(record.getJcvalue());
Double difference = aDouble-aDouble1; Double difference = aDouble - aDouble1;
double v = (difference < 0) ? -difference : difference; double v = (difference < 0) ? -difference : difference;
record.setDifference(String.format("%.2f",v)); record.setDifference(String.format("%.2f", v));
} }
} }
} }
...@@ -337,28 +338,35 @@ public class RgDataServiceImpl extends ServiceImpl<RgDataMapper, RgData> impleme ...@@ -337,28 +338,35 @@ public class RgDataServiceImpl extends ServiceImpl<RgDataMapper, RgData> impleme
QueryWrapper<RgData> rgDataQueryWrapper = new QueryWrapper<>(); QueryWrapper<RgData> rgDataQueryWrapper = new QueryWrapper<>();
ServiceUtil.rgImgQuery(rgDataQueryWrapper, dataQueryCriteria); ServiceUtil.rgImgQuery(rgDataQueryWrapper, dataQueryCriteria);
List<RgData> rgData = rgDataMapper.imgList(rgDataQueryWrapper); List<RgData> rgData = rgDataMapper.imgList(rgDataQueryWrapper);
System.out.println(JSONObject.toJSONString(rgData));
Integer hours = dataQueryCriteria.getHours(); Integer hours = dataQueryCriteria.getHours();
if (hours != null) { if (hours != null) {
if (!ObjectUtils.isEmpty(rgData)) { if (hours != 720) {
List<RgData> rgData1 = new ArrayList<>(); /* if (!ObjectUtils.isEmpty(rgData)) {
for (int i = 0; i < rgData.size(); i += hours) { List<RgData> rgData1 = new ArrayList<>();
RgData rgData2 = new RgData(); for (int i = 0; i < rgData.size(); i += hours) {
Double result = 0.0; RgData rgData2 = new RgData();
int i1 = rgData.size() - i; Double result = 0.0;
if (i1 >= hours) { int i1 = rgData.size() - i;
for (int j = i; j < i + hours; j++) { if (i1 >= hours) {
result += rgData.get(j).getRainfall(); for (int j = i; j < i + hours; j++) {
} result += rgData.get(j).getRainfall();
} else { }
for (int j = i; j < i + i1; j++) { } else {
result += rgData.get(j).getRainfall(); for (int j = i; j < i + i1; j++) {
result += rgData.get(j).getRainfall();
}
} }
rgData2.setTime(rgData.get(i).getTime());
rgData2.setRainfall(result);
rgData1.add(rgData2);
} }
rgData2.setTime(rgData.get(i).getTime()); rgData = rgData1;
rgData2.setRainfall(result); }*/
rgData1.add(rgData2); rgData = rgDataMapper.imgListGroupByHour(rgDataQueryWrapper,hours);
} }
rgData = rgData1; else {
rgData = rgDataMapper.imgListGroupByMonth(rgDataQueryWrapper);
} }
} }
//获取编码-名 //获取编码-名
......
...@@ -466,11 +466,11 @@ public class ServiceUtil { ...@@ -466,11 +466,11 @@ public class ServiceUtil {
//正序倒序 //正序倒序
String sort = dataQueryCriteria.getSort(); String sort = dataQueryCriteria.getSort();
String s = sort.split(",")[1]; String s = sort.split(",")[1];
if (s.equals("desc")) { /* if (s.equals("desc")) {
queryWrapper.orderByDesc("time"); queryWrapper.orderByDesc("time");
} else { } else {
queryWrapper.orderByAsc("time"); queryWrapper.orderByAsc("time");
} }*/
} }
......
...@@ -39,4 +39,15 @@ ...@@ -39,4 +39,15 @@
GROUP BY GROUP BY
DATE_FORMAT( time, '%Y-%m-%d' ) DATE_FORMAT( time, '%Y-%m-%d' )
</select> </select>
<select id="imgListGroupByHour" resultType="me.zhengjie.gemho.entity.data.RgData">
SELECT SUM(rainfall) as rainfall,
time
FROM
`tb_rg_data`
${ew.customSqlSegment}
GROUP BY
date ( time ),
CEILING( (HOUR ( time )+1) / #{hour} )
</select>
</mapper> </mapper>
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment