新增数据模块-按照日期时间范围进行查询

发布时间 2023-09-13 17:44:44作者: 冰雪2021

1 功能介绍

按照给定的日期和时间范围进行查询。

 http://localhost/dev-api/ruoyi-data/query/list?pageNum=1&pageSize=10&params[beginTime]=2023-09-13 00:00:00&params[endTime]=2023-09-13 23:59:59

2 前台代码

F:\code\RuoYi-Vue0.0\ruoyi-ui\src\views\ruoyi-data\query\index.vue

      <!--<el-form-item label="采样时间" prop="receiveTime">
        <el-date-picker clearable
          v-model="queryParams.receiveTime"
          type="date"
          value-format="yyyy-MM-dd"
          placeholder="请选择采样时间">
        </el-date-picker>
      </el-form-item>-->
      <el-form-item label="查询时间" prop="receiveTime">
        <el-date-picker clearable
           v-model="dateRange"
           style="width: 240px"
           value-format="yyyy-MM-dd HH:mm:ss"
           type="datetimerange"
           range-separator="-"
           start-placeholder="开始日期"
           end-placeholder="结束日期"
           :default-time="['00:00:00', '23:59:59']"
        >
        </el-date-picker>
      </el-form-item>
dateRange: [],
      title: "",
      // 日期范围
      dateRange: [],
      // 是否显示弹出层
      open: false,
listQuery(this.addDateRange(this.queryParams, this.dateRange)).then(response => {
    /** 查询历史数据列表 */
    getList() {
      this.loading = true;
      listQuery(this.addDateRange(this.queryParams, this.dateRange)).then(response => {
        this.queryList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },

 this.dateRange = [];

    /** 重置按钮操作 */
    resetQuery() {
      this.dateRange = [];
      this.resetForm("queryForm");
      this.handleQuery();
    },

 

3 后台代码

http://localhost/dev-api/ruoyi-data/query/list?pageNum=1&pageSize=10&params[beginTime]=2023-09-13 00:00:00&params[endTime]=2023-09-13 23:59:59

修改xml代码部分

F:\code\RuoYi-Vue0.0\ruoyi-system\src\main\resources\mapper\system\SysLogininforMapper.xml

            <if test="envData.params.beginTime != null and envData.params.beginTime != ''"><!-- 开始时间检索 -->
                and dd.receive_time &gt;= #{envData.params.beginTime}
            </if>
            <if test="envData.params.endTime != null and envData.params.endTime != ''"><!-- 结束时间检索 -->
                and dd.receive_time &lt;= #{envData.params.endTime}
            </if>
    <select id="selectEnvDataList" parameterType="map" resultMap="EnvDataResult">
        select dd.id,d.order_id,dd.device_id,dd.receive_time, dd.pm1, dd.pm2_5, dd.pm10, dd.formaldehyde, dd.co, dd.co2, dd.so2, dd.no2, dd.tvoc, dd.o3, dd.temperature, dd.humidity, dd.illumination, dd.atmospheric_pressure
        from env_device d
        join env_data dd on d.order_id = dd.device_id
        join sys_user u on d.usr_name = u.user_name
        <where>
            <if test="username != null "> and u.user_name = #{username}</if>
            <if test="envData.deviceId != null "> and dd.device_id = #{envData.deviceId}</if>
            <!--<if test="envData.receiveTime != null "> and dd.receive_time = #{envData.receiveTime}</if>-->

            <if test="envData.params.beginTime != null and envData.params.beginTime != ''"><!-- 开始时间检索 -->
                and dd.receive_time &gt;= #{envData.params.beginTime}
            </if>
            <if test="envData.params.endTime != null and envData.params.endTime != ''"><!-- 结束时间检索 -->
                and dd.receive_time &lt;= #{envData.params.endTime}
            </if>

            <if test="envData.pm1 != null "> and dd.pm1 = #{envData.pm1}</if>
            <if test="envData.pm25 != null "> and dd.pm2_5 = #{envData.pm25}</if>
            <if test="envData.pm10 != null "> and dd.pm10 = #{envData.pm10}</if>
            <if test="envData.formaldehyde != null "> and dd.formaldehyde = #{envData.formaldehyde}</if>
            <if test="envData.co != null "> and dd.co = #{envData.co}</if>
            <if test="envData.co2 != null "> and dd.co2 = #{envData.co2}</if>
            <if test="envData.so2 != null "> and dd.so2 = #{envData.so2}</if>
            <if test="envData.no2 != null "> and dd.no2 = #{envData.no2}</if>
            <if test="envData.tvoc != null "> and dd.tvoc = #{envData.tvoc}</if>
            <if test="envData.o3 != null "> and dd.o3 = #{envData.o3}</if>
            <if test="envData.temperature != null "> and dd.temperature = #{envData.temperature}</if>
            <if test="envData.humidity != null "> and dd.humidity = #{envData.humidity}</if>
            <if test="envData.illumination != null "> and dd.illumination = #{envData.illumination}</if>
            <if test="envData.atmosphericPressure != null "> and dd.atmospheric_pressure = #{envData.atmosphericPressure}</if>
        </where>
    </select>