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

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));
}
}

View File

@ -73,4 +73,9 @@ public class NgRechargeMachines extends BaseEntity
@ApiModelProperty("充值机名称")
private String deviceName;
/** 所属机构 */
@Excel(name = "所属机构")
@ApiModelProperty("所属机构")
private Long deptId;
}

View File

@ -1,6 +1,8 @@
package com.fastbee.rechargecard.mapper;
import java.util.List;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.fastbee.rechargecard.domain.UserIrrigationRecord;
import com.fastbee.rechargecard.domain.dto.UserIrrigationRecordListDto;
import org.apache.ibatis.annotations.Mapper;
@ -13,7 +15,7 @@ import org.apache.ibatis.annotations.Select;
* @date 2024-12-18
*/
@Mapper
public interface UserIrrigationRecordMapper
public interface UserIrrigationRecordMapper extends BaseMapper<UserIrrigationRecord>
{
/**
* 根据时间段获取灌溉记录列表

View File

@ -20,10 +20,11 @@
<result property="createBy" column="create_by" />
<result property="updateBy" column="update_by" />
<result property="deviceName" column="device_name" />
<result property="deptId" column="dept_id" />
</resultMap>
<sql id="selectNgRechargeMachinesVo">
select id, location, device_model, serial_number, area_code, installation_date, status, contact_person, contact_phone, remark, create_time, update_time, create_by, update_by, device_name from ng_recharge_machines
select id, location, device_model, serial_number, area_code, installation_date, status, contact_person, contact_phone, remark, create_time, update_time, create_by, update_by, device_name,dept_id from ng_recharge_machines
</sql>
<select id="selectNgRechargeMachinesList" parameterType="NgRechargeMachines" resultMap="NgRechargeMachinesResult">
@ -38,6 +39,7 @@
<if test="contactPerson != null and contactPerson != ''"> and contact_person = #{contactPerson}</if>
<if test="contactPhone != null and contactPhone != ''"> and contact_phone = #{contactPhone}</if>
<if test="deviceName != null and deviceName != ''"> and device_name like concat('%', #{deviceName}, '%')</if>
<if test="deptId != null "> and dept_id = #{deptId}</if>
</where>
</select>
@ -63,6 +65,7 @@
<if test="createBy != null">create_by,</if>
<if test="updateBy != null">update_by,</if>
<if test="deviceName != null">device_name,</if>
<if test="deptId != null">dept_id,</if>
</trim>
<trim prefix="values (" suffix=")" suffixOverrides=",">
<if test="location != null">#{location},</if>
@ -79,6 +82,7 @@
<if test="createBy != null">#{createBy},</if>
<if test="updateBy != null">#{updateBy},</if>
<if test="deviceName != null">#{deviceName},</if>
<if test="deptId != null">#{deptId},</if>
</trim>
</insert>
@ -99,6 +103,7 @@
<if test="createBy != null">create_by = #{createBy},</if>
<if test="updateBy != null">update_by = #{updateBy},</if>
<if test="deviceName != null">device_name = #{deviceName},</if>
<if test="deptId != null">dept_id = #{deptId},</if>
</trim>
where id = #{id}
</update>