添加灌溉记录统计接口;修复后台灌溉用水记录,关泵时间和灌溉最新上报时间,时间明显有问题bug
This commit is contained in:
parent
b5df093067
commit
27f5696673
@ -255,6 +255,7 @@ public class DeviceOtherMsgConsumer {
|
||||
DateTime currentTime=DateTime.now();//获取当前时间作为开阀时间
|
||||
userIrrigationRecord.setStartTime(currentTime);//开阀时间
|
||||
System.err.println("currentTime"+currentTime);
|
||||
userIrrigationRecord.setLastTime(currentTime);//灌溉最新上报时间
|
||||
|
||||
BigDecimal openCumFlow=dataJson.getBigDecimal("userSumFlow");//用户开阀时总使用水量
|
||||
userIrrigationRecord.setOpenCumFlow(openCumFlow);//用户开阀时使用水量
|
||||
@ -299,6 +300,7 @@ public class DeviceOtherMsgConsumer {
|
||||
}
|
||||
DateTime currentTime=DateTime.now();//获取当前时间作为关阀时间
|
||||
userIrrigationRecord.setEndTime(currentTime);//关阀时间
|
||||
userIrrigationRecord.setLastTime(currentTime);//灌溉最新上报时间
|
||||
|
||||
BigDecimal closeCumFlow=dataJson.getBigDecimal("userSumFlow");//用户关阀时总用水量
|
||||
userIrrigationRecord.setCloseCumFlow(closeCumFlow);
|
||||
|
@ -8,6 +8,7 @@ import javax.servlet.http.HttpServletResponse;
|
||||
import com.fastbee.common.core.domain.entity.SysUser;
|
||||
import com.baomidou.mybatisplus.extension.conditions.query.LambdaQueryChainWrapper;
|
||||
import com.fastbee.rechargecard.domain.UserConsumptionDetails;
|
||||
import com.fastbee.rechargecard.domain.dto.NgUserRechargeRecordsDto;
|
||||
import com.fastbee.rechargecard.domain.dto.UserIrrigationRecordDto;
|
||||
import com.fastbee.rechargecard.domain.dto.UserIrrigationRecordListDto;
|
||||
import com.fastbee.rechargecard.mapper.UserIrrigationRecordMapper;
|
||||
@ -50,6 +51,18 @@ public class UserIrrigationRecordController extends BaseController
|
||||
@Autowired
|
||||
private UserIrrigationRecordMapper userIrrigationRecordMapper;
|
||||
|
||||
/**
|
||||
* 统计灌溉记录中的总用水量和总用水户
|
||||
* @return
|
||||
*/
|
||||
@GetMapping("/total")
|
||||
@ApiOperation("统计灌溉记录中的总用水量和总用水户")
|
||||
public AjaxResult total(UserIrrigationRecordListDto userIrrigationRecordListDto)
|
||||
{
|
||||
//return success(ngUserRechargeRecordsService.getTotal(ngUserRechargeRecordsDto));
|
||||
return success(userIrrigationRecordService.getTotal(userIrrigationRecordListDto));
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询灌溉记录列表
|
||||
*/
|
||||
|
@ -1,6 +1,7 @@
|
||||
package com.fastbee.rechargecard.service;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import com.fastbee.rechargecard.domain.UserConsumptionDetails;
|
||||
import com.fastbee.rechargecard.domain.UserIrrigationRecord;
|
||||
@ -15,6 +16,13 @@ import com.fastbee.rechargecard.domain.dto.UserIrrigationRecordListDto;
|
||||
*/
|
||||
public interface IUserIrrigationRecordService
|
||||
{
|
||||
/**
|
||||
* 统计灌溉记录中的总用水量和总用水户
|
||||
* @param userIrrigationRecordListDto
|
||||
* @return
|
||||
*/
|
||||
public Map<String,Object> getTotal(UserIrrigationRecordListDto userIrrigationRecordListDto);
|
||||
|
||||
/**
|
||||
* 查询灌溉记录列表
|
||||
*
|
||||
|
@ -1,9 +1,7 @@
|
||||
package com.fastbee.rechargecard.service.impl;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.*;
|
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import com.fastbee.common.exception.ServiceException;
|
||||
@ -40,13 +38,28 @@ public class NgUserRechargeRecordsServiceImpl implements INgUserRechargeRecordsS
|
||||
*/
|
||||
@Override
|
||||
public Map<String, Object> getTotal(NgUserRechargeRecordsDto ngUserRechargeRecordsDto) {
|
||||
if(ngUserRechargeRecordsDto.getStartTime()!=null && ngUserRechargeRecordsDto.getEndTime()!=null)
|
||||
{
|
||||
//设置结束时间加一天
|
||||
Date endTime = ngUserRechargeRecordsDto.getEndTime();
|
||||
// 使用 Calendar 给日期加一天
|
||||
Calendar calendar = Calendar.getInstance();
|
||||
calendar.setTime(endTime);
|
||||
calendar.add(Calendar.DATE, 1); // 给日期加一天
|
||||
// 将计算后的日期设置回 userIrrigationRecord 对象
|
||||
ngUserRechargeRecordsDto.setEndTime(calendar.getTime());
|
||||
}
|
||||
// 统计amount字段的总和
|
||||
QueryWrapper<NgUserRechargeRecords> sumQueryWrapper = new QueryWrapper<>();
|
||||
sumQueryWrapper.select("SUM(amount) as sumAmount");
|
||||
if (ngUserRechargeRecordsDto.getStartTime() != null && ngUserRechargeRecordsDto.getEndTime() != null) {
|
||||
sumQueryWrapper.between("time", ngUserRechargeRecordsDto.getStartTime(), ngUserRechargeRecordsDto.getEndTime());
|
||||
sumQueryWrapper.between("recharge_time", ngUserRechargeRecordsDto.getStartTime(), ngUserRechargeRecordsDto.getEndTime());
|
||||
}
|
||||
Map<String, Object> sumResult = ngUserRechargeRecordsMapper.selectMaps(sumQueryWrapper).get(0);
|
||||
if(sumResult==null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
//double totalAmount = ((Number) sumResult.get("sumAmount")).doubleValue();
|
||||
BigDecimal totalAmount= (BigDecimal) sumResult.get("sumAmount");
|
||||
|
||||
@ -54,9 +67,13 @@ public class NgUserRechargeRecordsServiceImpl implements INgUserRechargeRecordsS
|
||||
QueryWrapper<NgUserRechargeRecords> distinctQueryWrapper = new QueryWrapper<>();
|
||||
distinctQueryWrapper.select("COUNT(DISTINCT card_number) as distinctCount");
|
||||
if (ngUserRechargeRecordsDto.getStartTime() != null && ngUserRechargeRecordsDto.getEndTime() != null) {
|
||||
distinctQueryWrapper.between("time", ngUserRechargeRecordsDto.getStartTime(), ngUserRechargeRecordsDto.getEndTime());
|
||||
distinctQueryWrapper.between("recharge_time", ngUserRechargeRecordsDto.getStartTime(), ngUserRechargeRecordsDto.getEndTime());
|
||||
}
|
||||
Map<String, Object> distinctResult = ngUserRechargeRecordsMapper.selectMaps(distinctQueryWrapper).get(0);
|
||||
if(distinctResult==null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
long distinctCardNumberCount = ((Number) distinctResult.get("distinctCount")).longValue();
|
||||
|
||||
Map<String,Object> result=new HashMap<>();
|
||||
|
@ -1,11 +1,13 @@
|
||||
package com.fastbee.rechargecard.service.impl;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.*;
|
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import com.fastbee.common.utils.DateUtils;
|
||||
import com.fastbee.iot.mapper.DeviceMapper;
|
||||
import com.fastbee.rechargecard.domain.NgIrrigationControllers;
|
||||
import com.fastbee.rechargecard.domain.NgUserRechargeRecords;
|
||||
import com.fastbee.rechargecard.domain.UserConsumptionDetails;
|
||||
import com.fastbee.rechargecard.domain.dto.UserIrrigationRecordDto;
|
||||
import com.fastbee.rechargecard.domain.dto.UserIrrigationRecordListDto;
|
||||
@ -34,6 +36,58 @@ public class UserIrrigationRecordServiceImpl implements IUserIrrigationRecordSer
|
||||
private NgIrrigationControllersMapper ngIrrigationControllersMapper;
|
||||
|
||||
|
||||
/**
|
||||
* 统计灌溉记录中的总用水量和总用水户
|
||||
* @param userIrrigationRecordListDto
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public Map<String, Object> getTotal(UserIrrigationRecordListDto userIrrigationRecordListDto) {
|
||||
if(userIrrigationRecordListDto.getSearchStartTime()!=null && userIrrigationRecordListDto.getSearchEndTime()!=null)
|
||||
{
|
||||
//设置结束时间加一天
|
||||
Date endTime = userIrrigationRecordListDto.getSearchEndTime();
|
||||
// 使用 Calendar 给日期加一天
|
||||
Calendar calendar = Calendar.getInstance();
|
||||
calendar.setTime(endTime);
|
||||
calendar.add(Calendar.DATE, 1); // 给日期加一天
|
||||
// 将计算后的日期设置回 userIrrigationRecord 对象
|
||||
userIrrigationRecordListDto.setSearchEndTime(calendar.getTime());
|
||||
}
|
||||
// 统计cur_flow字段的总和
|
||||
QueryWrapper<UserIrrigationRecord> sumQueryWrapper = new QueryWrapper<>();
|
||||
sumQueryWrapper.select("SUM(cur_flow) as sumFlow");
|
||||
if (userIrrigationRecordListDto.getSearchStartTime() != null && userIrrigationRecordListDto.getSearchEndTime() != null) {
|
||||
sumQueryWrapper.between("end_time", userIrrigationRecordListDto.getSearchStartTime(), userIrrigationRecordListDto.getSearchEndTime());
|
||||
}
|
||||
Map<String, Object> sumResult = userIrrigationRecordMapper.selectMaps(sumQueryWrapper).get(0);
|
||||
if(sumResult==null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
//double totalAmount = ((Number) sumResult.get("sumAmount")).doubleValue();
|
||||
BigDecimal totalFlow= (BigDecimal) sumResult.get("sumFlow");
|
||||
|
||||
// 对cardNumber字段进行去重并统计总和
|
||||
QueryWrapper<UserIrrigationRecord> distinctQueryWrapper = new QueryWrapper<>();
|
||||
distinctQueryWrapper.select("COUNT(DISTINCT card_number) as distinctCount");
|
||||
if (userIrrigationRecordListDto.getSearchStartTime() != null && userIrrigationRecordListDto.getSearchEndTime() != null) {
|
||||
distinctQueryWrapper.between("end_time", userIrrigationRecordListDto.getSearchStartTime(), userIrrigationRecordListDto.getSearchEndTime());
|
||||
}
|
||||
Map<String, Object> distinctResult = userIrrigationRecordMapper.selectMaps(distinctQueryWrapper).get(0);
|
||||
if(distinctResult==null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
long distinctCardNumberCount = ((Number) distinctResult.get("distinctCount")).longValue();
|
||||
|
||||
Map<String,Object> result=new HashMap<>();
|
||||
result.put("totalFlow",totalFlow);//总用水量
|
||||
result.put("totalUserNumber",distinctCardNumberCount);//总用水户
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<UserIrrigationRecord> selectUserIrrigationRecordListByTime(UserIrrigationRecordListDto userIrrigationRecord) {
|
||||
return userIrrigationRecordMapper.selectUserIrrigationRecordListByTime(userIrrigationRecord);
|
||||
|
Loading…
x
Reference in New Issue
Block a user