2026-03-27提交:分时图导入进度接口;调整任务接口位置到taskcontroller
This commit is contained in:
parent
7c0db4830d
commit
e753f81909
@ -8,7 +8,6 @@ import org.springframework.beans.factory.annotation.Autowired;
|
|||||||
import org.springframework.core.io.Resource;
|
import org.springframework.core.io.Resource;
|
||||||
import org.springframework.http.ResponseEntity;
|
import org.springframework.http.ResponseEntity;
|
||||||
import org.springframework.web.bind.annotation.*;
|
import org.springframework.web.bind.annotation.*;
|
||||||
import org.springframework.web.multipart.MultipartFile;
|
|
||||||
|
|
||||||
import javax.validation.Valid;
|
import javax.validation.Valid;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@ -23,9 +22,6 @@ import java.util.List;
|
|||||||
@RequestMapping("/api/v1/dner")
|
@RequestMapping("/api/v1/dner")
|
||||||
@Slf4j
|
@Slf4j
|
||||||
public class DnerController {
|
public class DnerController {
|
||||||
@Autowired
|
|
||||||
private IImportTaskService importTaskService;
|
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
private IDnerHourlyPowerOutageEventService dnerHourlyPowerOutageEventService;
|
private IDnerHourlyPowerOutageEventService dnerHourlyPowerOutageEventService;
|
||||||
|
|
||||||
@ -84,18 +80,6 @@ public class DnerController {
|
|||||||
orgCode, startDate, endDate, eventId));
|
orgCode, startDate, endDate, eventId));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* 通过easyexcel流式读取导入数据 -- 异步导入
|
|
||||||
*
|
|
||||||
* @param file 文件
|
|
||||||
* @return 返回结果
|
|
||||||
*/
|
|
||||||
@PostMapping("/excel/import")
|
|
||||||
public Result<String> importExcel(@RequestParam("file") MultipartFile file,
|
|
||||||
@RequestParam("eventId") Long eventId) {
|
|
||||||
return Result.success(importTaskService.importExcel(file, eventId));
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 下载附件
|
* 下载附件
|
||||||
*
|
*
|
||||||
@ -107,12 +91,6 @@ public class DnerController {
|
|||||||
return dnerEventAttachmentService.downloadExcel(attachmentId);
|
return dnerEventAttachmentService.downloadExcel(attachmentId);
|
||||||
}
|
}
|
||||||
|
|
||||||
// 2. 查询导入进度
|
|
||||||
@GetMapping("/progress/{taskNo}")
|
|
||||||
public Result<ImportTask> getProgress(@PathVariable String taskNo) {
|
|
||||||
ImportTask task = importTaskService.getProgress(taskNo);
|
|
||||||
return Result.success(task);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 同步区域气象数据
|
* 同步区域气象数据
|
||||||
|
|||||||
@ -0,0 +1,59 @@
|
|||||||
|
package com.southern.power.grid.controller;
|
||||||
|
|
||||||
|
import com.southern.power.grid.common.Result;
|
||||||
|
import com.southern.power.grid.entity.ImportTask;
|
||||||
|
import com.southern.power.grid.entity.ProgressVO;
|
||||||
|
import com.southern.power.grid.service.IImportTaskService;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.web.bind.annotation.*;
|
||||||
|
import org.springframework.web.multipart.MultipartFile;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 导入任务Controller
|
||||||
|
*
|
||||||
|
* @Author junzhangfm
|
||||||
|
* @Date 2026-03-27
|
||||||
|
*/
|
||||||
|
@RestController
|
||||||
|
@RequestMapping("/api/v1/task")
|
||||||
|
@Slf4j
|
||||||
|
public class ImportTaskController {
|
||||||
|
@Autowired
|
||||||
|
private IImportTaskService importTaskService;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 通过easyexcel流式读取导入数据 -- 异步导入
|
||||||
|
*
|
||||||
|
* @param file 文件
|
||||||
|
* @return 返回结果
|
||||||
|
*/
|
||||||
|
@PostMapping("/excel/import")
|
||||||
|
public Result<String> importExcel(@RequestParam("file") MultipartFile file,
|
||||||
|
@RequestParam("eventId") Long eventId) {
|
||||||
|
return Result.success(importTaskService.importExcel(file, eventId));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 根据任务编号查询任务信息
|
||||||
|
*
|
||||||
|
* @param taskNo 任务编号
|
||||||
|
* @return 查询结果
|
||||||
|
*/
|
||||||
|
@GetMapping("/progress/{taskNo}")
|
||||||
|
public Result<ImportTask> getProgress(@PathVariable String taskNo) {
|
||||||
|
ImportTask task = importTaskService.getProgress(taskNo);
|
||||||
|
return Result.success(task);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 查询日K图同步进度
|
||||||
|
*
|
||||||
|
* @param eventId 事件ID
|
||||||
|
* @return 结果
|
||||||
|
*/
|
||||||
|
@GetMapping("/syncDailyProgress/{eventId}")
|
||||||
|
public Result<ProgressVO> getSyncDailyProgress(@PathVariable String eventId) {
|
||||||
|
return Result.success(importTaskService.getSyncDailyProgress(eventId));
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -2,7 +2,9 @@ package com.southern.power.grid.dao;
|
|||||||
|
|
||||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||||
import com.southern.power.grid.entity.DnerDailyPowerOutageEventSync;
|
import com.southern.power.grid.entity.DnerDailyPowerOutageEventSync;
|
||||||
|
import com.southern.power.grid.entity.ProgressVO;
|
||||||
import org.apache.ibatis.annotations.Mapper;
|
import org.apache.ibatis.annotations.Mapper;
|
||||||
|
import org.apache.ibatis.annotations.Param;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -13,5 +15,11 @@ import org.apache.ibatis.annotations.Mapper;
|
|||||||
*/
|
*/
|
||||||
@Mapper
|
@Mapper
|
||||||
public interface DnerDailyPowerOutageEventSyncMapper extends BaseMapper<DnerDailyPowerOutageEventSync> {
|
public interface DnerDailyPowerOutageEventSyncMapper extends BaseMapper<DnerDailyPowerOutageEventSync> {
|
||||||
|
/**
|
||||||
|
* 统计日K图同步成功数和失败书
|
||||||
|
*
|
||||||
|
* @param eventId 事件ID
|
||||||
|
* @return 统计结果
|
||||||
|
*/
|
||||||
|
ProgressVO countSync(@Param("eventId") String eventId);
|
||||||
}
|
}
|
||||||
|
|||||||
20
src/main/java/com/southern/power/grid/entity/ProgressVO.java
Normal file
20
src/main/java/com/southern/power/grid/entity/ProgressVO.java
Normal file
@ -0,0 +1,20 @@
|
|||||||
|
package com.southern.power.grid.entity;
|
||||||
|
|
||||||
|
import lombok.Data;
|
||||||
|
import lombok.experimental.Accessors;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 进度VO
|
||||||
|
*
|
||||||
|
* @Author junzhangfm
|
||||||
|
* @Date 2026-03-27
|
||||||
|
*/
|
||||||
|
@Data
|
||||||
|
@Accessors(chain = true)
|
||||||
|
public class ProgressVO {
|
||||||
|
private Integer total;
|
||||||
|
|
||||||
|
private Integer successCount;
|
||||||
|
|
||||||
|
private Integer failCount;
|
||||||
|
}
|
||||||
@ -1,6 +1,7 @@
|
|||||||
package com.southern.power.grid.service;
|
package com.southern.power.grid.service;
|
||||||
|
|
||||||
import com.southern.power.grid.entity.ImportTask;
|
import com.southern.power.grid.entity.ImportTask;
|
||||||
|
import com.southern.power.grid.entity.ProgressVO;
|
||||||
import org.springframework.web.multipart.MultipartFile;
|
import org.springframework.web.multipart.MultipartFile;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -13,4 +14,12 @@ public interface IImportTaskService {
|
|||||||
String importExcel(MultipartFile file, Long eventId);
|
String importExcel(MultipartFile file, Long eventId);
|
||||||
|
|
||||||
ImportTask getProgress(String taskNo);
|
ImportTask getProgress(String taskNo);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 查询日K图同步进度
|
||||||
|
*
|
||||||
|
* @param eventId 事件ID
|
||||||
|
* @return 结果
|
||||||
|
*/
|
||||||
|
ProgressVO getSyncDailyProgress(String eventId);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,11 +1,12 @@
|
|||||||
package com.southern.power.grid.service.impl;
|
package com.southern.power.grid.service.impl;
|
||||||
|
|
||||||
import cn.hutool.core.io.FileUtil;
|
|
||||||
import cn.hutool.core.util.IdUtil;
|
import cn.hutool.core.util.IdUtil;
|
||||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||||
|
import com.southern.power.grid.dao.DnerDailyPowerOutageEventSyncMapper;
|
||||||
import com.southern.power.grid.dao.ImportTaskMapper;
|
import com.southern.power.grid.dao.ImportTaskMapper;
|
||||||
import com.southern.power.grid.entity.ImportTask;
|
import com.southern.power.grid.entity.ImportTask;
|
||||||
|
import com.southern.power.grid.entity.ProgressVO;
|
||||||
import com.southern.power.grid.enums.ImportTaskStatusEnum;
|
import com.southern.power.grid.enums.ImportTaskStatusEnum;
|
||||||
import com.southern.power.grid.service.IFileService;
|
import com.southern.power.grid.service.IFileService;
|
||||||
import com.southern.power.grid.service.IImportTaskService;
|
import com.southern.power.grid.service.IImportTaskService;
|
||||||
@ -37,6 +38,9 @@ public class ImportTaskServiceImpl extends ServiceImpl<ImportTaskMapper, ImportT
|
|||||||
@Autowired
|
@Autowired
|
||||||
private IFileService fileService;
|
private IFileService fileService;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private DnerDailyPowerOutageEventSyncMapper dnerDailyPowerOutageEventSyncMapper;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String importExcel(MultipartFile file, Long eventId) {
|
public String importExcel(MultipartFile file, Long eventId) {
|
||||||
// 把上传的文件流转成 **字节数组输入流**,保存到内存,避免Tomcat删除
|
// 把上传的文件流转成 **字节数组输入流**,保存到内存,避免Tomcat删除
|
||||||
@ -80,4 +84,11 @@ public class ImportTaskServiceImpl extends ServiceImpl<ImportTaskMapper, ImportT
|
|||||||
public ImportTask getProgress(String taskNo) {
|
public ImportTask getProgress(String taskNo) {
|
||||||
return importTaskMapper.selectOne(new LambdaQueryWrapper<ImportTask>().eq(ImportTask::getTaskNo, taskNo));
|
return importTaskMapper.selectOne(new LambdaQueryWrapper<ImportTask>().eq(ImportTask::getTaskNo, taskNo));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public ProgressVO getSyncDailyProgress(String eventId) {
|
||||||
|
// 拿这个事件ID查询分时图表,按日期的年月日,还有区域ID分组,就是同步的总条数
|
||||||
|
// 根据事件ID查询dner_daily_power_outage_event_sync这张表就能知道这1000条里成功了多少条,失败了多少条
|
||||||
|
return dnerDailyPowerOutageEventSyncMapper.countSync(eventId);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -5,4 +5,14 @@
|
|||||||
<!-- namespace 必须 = Mapper 接口全类名 -->
|
<!-- namespace 必须 = Mapper 接口全类名 -->
|
||||||
<mapper namespace="com.southern.power.grid.dao.DnerDailyPowerOutageEventSyncMapper">
|
<mapper namespace="com.southern.power.grid.dao.DnerDailyPowerOutageEventSyncMapper">
|
||||||
|
|
||||||
|
<select id="countSync" resultType="com.southern.power.grid.entity.ProgressVO"
|
||||||
|
parameterType="java.lang.String">
|
||||||
|
SELECT IFNULL((SELECT COUNT(DISTINCT CONCAT(DATE(data_time), '_', org_code))
|
||||||
|
FROM dner_hourly_power_outage_event
|
||||||
|
WHERE event_id = #{eventId}), 0) AS total,
|
||||||
|
IFNULL(SUM(IF(sync.sync_status = 1, 1, 0)), 0) AS successCount,
|
||||||
|
IFNULL(SUM(IF(sync.sync_status = 2, 1, 0)), 0) AS failCount
|
||||||
|
FROM dner_daily_power_outage_event_sync sync
|
||||||
|
WHERE sync.event_id = #{eventId}
|
||||||
|
</select>
|
||||||
</mapper>
|
</mapper>
|
||||||
Loading…
x
Reference in New Issue
Block a user