yuan
3 天以前 03e1ff455f71330e6d1adaaa46c6613238f2b1bd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
package com.ruoyi.http.controller;
 
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.http.pojo.TqdianbiaoEleRecord;
import com.ruoyi.http.service.TqdianbiaoEleRecordManageService;
import com.ruoyi.http.service.TqdianbiaoEleSyncService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
 
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
 
@RestController
@Tag(name = "电量记录管理")
@RequestMapping("/tqdianbiao/eleRecord")
@RequiredArgsConstructor
public class TqdianbiaoEleRecordController extends BaseController {
 
    private static final DateTimeFormatter HOUR_FMT = DateTimeFormatter.ofPattern("yyyyMMddHH");
 
    private final TqdianbiaoEleRecordManageService eleRecordManageService;
    private final TqdianbiaoEleSyncService eleSyncService;
 
    @GetMapping("/listPage")
    @Operation(summary = "电量记录-分页查询")
    public AjaxResult listPage(Page page, TqdianbiaoEleRecord query) {
        return AjaxResult.success(eleRecordManageService.listPage(page, query));
    }
 
    @PostMapping("/add")
    @Log(title = "电量记录-新增", businessType = BusinessType.INSERT)
    public AjaxResult add(@RequestBody TqdianbiaoEleRecord record) {
        return eleRecordManageService.addRecord(record) ? AjaxResult.success() : AjaxResult.error();
    }
 
    @PostMapping("/update")
    @Log(title = "电量记录-修改", businessType = BusinessType.UPDATE)
    public AjaxResult update(@RequestBody TqdianbiaoEleRecord record) {
        return eleRecordManageService.updateRecord(record) ? AjaxResult.success() : AjaxResult.error();
    }
 
    @DeleteMapping("/delete")
    @Log(title = "电量记录-删除", businessType = BusinessType.DELETE)
    public AjaxResult delete(@RequestBody List<Long> ids) {
        return eleRecordManageService.deleteByIds(ids) ? AjaxResult.success() : AjaxResult.error();
    }
 
    @GetMapping("/prevReading")
    @Operation(summary = "获取上次电量读数")
    public AjaxResult prevReading(Long meterId, String timeKey) {
        return AjaxResult.success(eleRecordManageService.getPrevReading(meterId, timeKey));
    }
 
    @PostMapping("/syncRecentOnce")
    @Log(title = "电量记录-近三天补数", businessType = BusinessType.OTHER)
    @Operation(summary = "同步前三天至当前小时电量(一次性补数)")
    public AjaxResult syncRecentOnce() {
        LocalDateTime start = LocalDate.now().minusDays(3).atStartOfDay();
        LocalDateTime end = LocalDateTime.now().withMinute(0).withSecond(0).withNano(0);
        int count = eleSyncService.syncLast3DaysHourData();
        Map<String, Object> data = new HashMap<>();
        data.put("count", count);
        data.put("startTime", start.format(HOUR_FMT));
        data.put("endTime", end.format(HOUR_FMT));
        return AjaxResult.success("同步完成:" + data.get("startTime") + " ~ " + data.get("endTime") + " 共 " + count + " 条", data);
    }
}