数据采集
This commit is contained in:
parent
3a7ab2a130
commit
a24d5467fe
@ -157,18 +157,18 @@ public class bdgzsomthingController {
|
||||
}
|
||||
// @Scheduled(cron = "0 0 0 10 * ?") //每天十天执行一次
|
||||
//@Scheduled(cron = "0 2 0 * * ?") //每天十天执行一次
|
||||
@PostConstruct
|
||||
// @PostConstruct
|
||||
public void init() {
|
||||
// selectHasPrice();
|
||||
// selectSafeStorageAndDeliverOneYear();
|
||||
// bdgzsomthingService.selectds();
|
||||
}
|
||||
@Scheduled(cron = "0 0 2 * * ?")
|
||||
// @Scheduled(cron = "0 0 2 * * ?")
|
||||
public void selectHasPrice(){
|
||||
bdgzsomthingService.selectHasPrice();
|
||||
}
|
||||
|
||||
@Scheduled(cron = "0 0 0 * * ?")
|
||||
// @Scheduled(cron = "0 0 0 * * ?")
|
||||
public void selectSafeStorageAndDeliverOneYear(){bdgzsomthingService.selectSafeStorageAndDeliverOneYear();}
|
||||
@PostMapping("/getMessage")
|
||||
@Operation(summary = "小程序消息")
|
||||
|
||||
@ -1,5 +1,6 @@
|
||||
package com.chanko.yunxi.mes.module.heli.controller.admin.dataacquisition;
|
||||
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
import org.springframework.scheduling.annotation.Scheduled;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import javax.annotation.Resource;
|
||||
@ -9,9 +10,9 @@ import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import io.swagger.v3.oas.annotations.Parameter;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
|
||||
import javax.validation.constraints.*;
|
||||
import javax.validation.*;
|
||||
import javax.servlet.http.*;
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.*;
|
||||
import java.io.IOException;
|
||||
|
||||
@ -93,7 +94,7 @@ public class DataAcquisitionController {
|
||||
BeanUtils.toBean(list, DataAcquisitionRespVO.class));
|
||||
}
|
||||
|
||||
@Scheduled(cron = "0/5 * * * * ?")
|
||||
// @Scheduled(cron = "0/5 * * * * ?")
|
||||
public void updateDataCollection(){
|
||||
dataAcquisitionService.updateDataCollection();
|
||||
}
|
||||
@ -113,6 +114,12 @@ public class DataAcquisitionController {
|
||||
List<DataAcquisitionDO> dataAcquisition = dataAcquisitionService.getDataAcquisitionList(code);
|
||||
return success(dataAcquisition);
|
||||
}
|
||||
|
||||
@GetMapping("/updateTime")
|
||||
@Operation(summary = "更新设备数据采集")
|
||||
@PreAuthorize("@ss.hasPermission('heli:data-acquisition:update')")
|
||||
public CommonResult<Boolean> updateTime(@RequestParam("acquisitionTime") @org.springframework.format.annotation.DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") LocalDateTime acquisitionTime) {
|
||||
dataAcquisitionService.updateTime(acquisitionTime);
|
||||
return success(true);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -1,7 +1,10 @@
|
||||
package com.chanko.yunxi.mes.module.heli.controller.admin.dataacquisition.vo;
|
||||
|
||||
import cn.hutool.core.date.DateTime;
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.*;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.*;
|
||||
import javax.validation.constraints.*;
|
||||
import java.util.*;
|
||||
@ -36,5 +39,7 @@ public class DataAcquisitionSaveReqVO {
|
||||
|
||||
@Schema(description = "查询状态", example = "1")
|
||||
private Integer status;
|
||||
@Schema(description = "创建时间")
|
||||
private LocalDateTime acquisitionTime;
|
||||
|
||||
}
|
||||
|
||||
@ -70,4 +70,6 @@ public interface DataAcquisitionMapper extends BaseMapperX<DataAcquisitionDO> {
|
||||
.last("limit 10");
|
||||
return selectList(query);
|
||||
}
|
||||
@Select("")
|
||||
Integer selectStatus();
|
||||
}
|
||||
@ -1,5 +1,6 @@
|
||||
package com.chanko.yunxi.mes.module.heli.service.dataacquisition;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.*;
|
||||
import javax.validation.*;
|
||||
import com.chanko.yunxi.mes.module.heli.controller.admin.dataacquisition.vo.*;
|
||||
@ -57,4 +58,6 @@ public interface DataAcquisitionService {
|
||||
|
||||
List<DataAcquisitionDO> getDataAcquisitionList(String code);
|
||||
|
||||
void updateTime(LocalDateTime acquisitionTime);
|
||||
|
||||
}
|
||||
|
||||
@ -1,12 +1,15 @@
|
||||
package com.chanko.yunxi.mes.module.heli.service.dataacquisition;
|
||||
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
|
||||
import org.springframework.stereotype.Service;
|
||||
import javax.annotation.Resource;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
|
||||
import java.util.*;
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import com.chanko.yunxi.mes.module.heli.controller.admin.dataacquisition.vo.*;
|
||||
import com.chanko.yunxi.mes.module.heli.dal.dataobject.dataacquisition.DataAcquisitionDO;
|
||||
import com.chanko.yunxi.mes.framework.common.pojo.PageResult;
|
||||
@ -73,12 +76,22 @@ public class DataAcquisitionServiceImpl implements DataAcquisitionService {
|
||||
@Override
|
||||
public void updateDataCollection() {
|
||||
// 查找每个 code 分组中 status=1 的最大 createTime 之后的 status=0 的最小记录的 id
|
||||
Integer integer = dataAcquisitionMapper.selectStatus();
|
||||
System.out.println("=== equipment_job_config status: " + integer);
|
||||
if (ObjectUtil.isNotEmpty( integer)&&integer==0){
|
||||
List<Long> ids = dataAcquisitionMapper.selectNextStatusZeroIds();
|
||||
System.out.println("=== selectNextStatusZeroIds returned " + (ids == null ? 0 : ids.size()) + " ids: " + ids);
|
||||
if (ObjectUtil.isNotEmpty(ids)){
|
||||
LambdaUpdateWrapper<DataAcquisitionDO> updateWrapper = new LambdaUpdateWrapper<>();
|
||||
updateWrapper.in(DataAcquisitionDO::getId, ids);
|
||||
updateWrapper.set(DataAcquisitionDO::getStatus, 1);
|
||||
dataAcquisitionMapper.update(updateWrapper);
|
||||
int rows = dataAcquisitionMapper.update(null, updateWrapper);
|
||||
System.out.println("=== updated rows: " + rows);
|
||||
} else {
|
||||
System.out.println("=== No status=0 records found");
|
||||
}
|
||||
} else {
|
||||
System.out.println("=== Task disabled (status != 0)");
|
||||
}
|
||||
}
|
||||
|
||||
@ -92,4 +105,35 @@ public class DataAcquisitionServiceImpl implements DataAcquisitionService {
|
||||
return dataAcquisitionMapper.getDataAcquisitionList( code);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateTime(LocalDateTime acquisitionTime) {
|
||||
// 查询所有数据按 code 分组,并按 id 排序(id 代表插入顺序)
|
||||
List<DataAcquisitionDO> allData = dataAcquisitionMapper.selectList(
|
||||
new LambdaQueryWrapper<DataAcquisitionDO>()
|
||||
.orderByAsc(DataAcquisitionDO::getId)
|
||||
);
|
||||
|
||||
if (allData == null || allData.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
|
||||
// 按 code 分组
|
||||
Map<String, List<DataAcquisitionDO>> groupedByCode = allData.stream()
|
||||
.collect(java.util.stream.Collectors.groupingBy(DataAcquisitionDO::getCode, java.util.stream.Collectors.toList()));
|
||||
|
||||
// 遍历每个分组,更新时间
|
||||
for (Map.Entry<String, List<DataAcquisitionDO>> entry : groupedByCode.entrySet()) {
|
||||
List<DataAcquisitionDO> groupData = entry.getValue();
|
||||
for (int i = 0; i < groupData.size(); i++) {
|
||||
DataAcquisitionDO record = groupData.get(i);
|
||||
// 第一条记录使用 updateReqVO 的时间,之后的每条增加5秒
|
||||
LocalDateTime newCreateTime = acquisitionTime.plusSeconds(i * 5L);
|
||||
|
||||
// 更新该条记录的创建时间
|
||||
record.setCreateTime(newCreateTime);
|
||||
dataAcquisitionMapper.updateById(record);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -47,3 +47,7 @@ export const getList = async () => {
|
||||
export const getDataAcquisitionList = async (code: string) => {
|
||||
return await request.get({ url: `/heli/data-acquisition/getDataAcquisitionList`, params: { code } })
|
||||
}
|
||||
// 新增客户新表
|
||||
export const updateTime = async (acquisitionTime) => {
|
||||
return await request.get({ url: `/heli/data-acquisition/updateTime`,params: { acquisitionTime } })
|
||||
}
|
||||
|
||||
@ -4,7 +4,7 @@
|
||||
<div class="JNPF-common-layout-main JNPF-flex-main">
|
||||
<div class="JNPF-common-head">
|
||||
<div>
|
||||
每秒自动刷新一次
|
||||
每5秒自动刷新一次
|
||||
</div>
|
||||
</div>
|
||||
<el-tabs v-model="activeName">
|
||||
|
||||
@ -4,7 +4,7 @@
|
||||
<div class="JNPF-common-layout-main JNPF-flex-main">
|
||||
<div class="JNPF-common-head">
|
||||
<div>
|
||||
每秒自动刷新一次
|
||||
每5秒自动刷新一次
|
||||
</div>
|
||||
</div>
|
||||
<el-table v-loading="listLoading" :data="list" border height="900px">
|
||||
|
||||
@ -0,0 +1,65 @@
|
||||
<template>
|
||||
<el-card class="hl-card">
|
||||
<template #header>
|
||||
<span>更新数据采集时间</span>
|
||||
</template>
|
||||
<ContentWrap class="borderxx">
|
||||
<!-- 搜索工作栏 -->
|
||||
<el-form
|
||||
class="-mb-15px"
|
||||
:model="queryParams"
|
||||
ref="queryFormRef"
|
||||
:inline="true"
|
||||
label-width="108px"
|
||||
>
|
||||
<el-form-item label="开始时间" prop="startTime">
|
||||
<el-date-picker
|
||||
v-model="queryParams.acquisitionTime"
|
||||
value-format="YYYY-MM-DD HH:mm:ss"
|
||||
type="datetime"
|
||||
placeholder="选择时间"
|
||||
class="!w-400px"
|
||||
/>
|
||||
</el-form-item>
|
||||
<el-form-item>
|
||||
<el-button @click="handleQuery" type="primary"> 更新</el-button>
|
||||
</el-form-item>
|
||||
</el-form>
|
||||
</ContentWrap>
|
||||
|
||||
</el-card>
|
||||
<!-- 表单弹窗:添加/修改 -->
|
||||
<CustomerForm ref="formRef" @success="getList" />
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
|
||||
|
||||
import * as DataAcquisitionApi from "@/api/heli/dataacquisition";
|
||||
|
||||
defineOptions({ name: 'Customer' })
|
||||
|
||||
const message = useMessage() // 消息弹窗
|
||||
const { t } = useI18n() // 国际化
|
||||
|
||||
const loading = ref(true) // 列表的加载中
|
||||
const list = ref([]) // 列表的数据
|
||||
const total = ref(0) // 列表的总页数
|
||||
const queryParams = reactive({
|
||||
pageNo: 1,
|
||||
pageSize: 10,
|
||||
acquisitionTime: undefined,
|
||||
})
|
||||
const queryFormRef = ref() // 搜索的表单
|
||||
|
||||
|
||||
/** 查询列表 */
|
||||
|
||||
|
||||
/** 搜索按钮操作 */
|
||||
const handleQuery = async () => {
|
||||
const data = await DataAcquisitionApi.updateTime(queryParams.acquisitionTime)
|
||||
message.success("更新成功")
|
||||
}
|
||||
|
||||
</script>
|
||||
Loading…
Reference in New Issue
Block a user