添加用户年度用水量统计接口

This commit is contained in:
蒾酒
2024-12-31 19:16:52 +08:00
parent d6130cf330
commit f1b42d1f4d
4 changed files with 48 additions and 5 deletions

View File

@ -1,16 +1,18 @@
package com.fastbee.data.controller.userRecharge;
import java.util.Calendar;
import java.util.Date;
import java.util.List;
import java.time.LocalDate;
import java.util.*;
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.UserIrrigationRecordDto;
import com.fastbee.rechargecard.domain.dto.UserIrrigationRecordListDto;
import com.fastbee.rechargecard.mapper.UserIrrigationRecordMapper;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.data.repository.query.Param;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
@ -44,6 +46,9 @@ public class UserIrrigationRecordController extends BaseController
@Autowired
private IUserIrrigationRecordService userIrrigationRecordService;
@Autowired
private UserIrrigationRecordMapper userIrrigationRecordMapper;
/**
* 查询灌溉记录列表
*/
@ -189,4 +194,30 @@ public class UserIrrigationRecordController extends BaseController
{
return toAjax(userIrrigationRecordService.deleteUserIrrigationRecordByIds(ids));
}
/**
* 统计用户的年度用水量,年度剩余用水量
*/
@GetMapping("/getYearWater")
@ApiOperation("统计用户的年度用水量,年度剩余用水量")
public AjaxResult getYearWater(@Param("userId") Long userId) {
// 获取当前年份的第一天
LocalDate startOfYear = LocalDate.now().withDayOfYear(1);
// 统计从今年第一天开始以后的用水量
Long count = new LambdaQueryChainWrapper<>(userIrrigationRecordMapper)
.select(UserIrrigationRecord::getCurFlow)
.eq(UserIrrigationRecord::getUserId, userId)
.ge(UserIrrigationRecord::getCreateTime, startOfYear)
.count();
Map<String,Object> resp = new HashMap<>();
resp.put("yearUserWater", count);
resp.put("yearUserWaterLeft", 1000 - count); // 假设年度总用水量为1000单位
return AjaxResult.success(resp);
}
public static void main(String[] args) {
System.err.println(LocalDate.now().withDayOfYear(1));
}
}