huang
2025-04-17 3a0087aa5e3eed5d9d7a793a17dc01fd1d6df80c
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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
package com.mes.plannedAmount.controller;
 
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.mes.plannedAmount.entity.PlannedAmount;
import com.mes.plannedAmount.service.PlannedAmountService;
import com.mes.utils.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.*;
 
import java.util.Calendar;
import java.util.Date;
import java.util.List;
import java.util.Map;
 
@Api(tags = "计划产量接口")
@RestController
@RequestMapping("/plannedAmount")
public class PlannedAmountController {
 
    @Autowired
    private PlannedAmountService plannedAmountService;
 
    @ApiOperation("获取计划量数据列表")
    @PostMapping("/listPlanned")
    @ResponseBody
    public Result listPlanned(@RequestBody Map<String, Object> params) {
        Integer page = params.get("page") == null ? 1 : (Integer) params.get("page");
        Integer pageSize = params.get("pageSize") == null ? 10 : (Integer) params.get("pageSize");
        String type = (String) params.get("type");
        
        QueryWrapper<PlannedAmount> queryWrapper = new QueryWrapper<PlannedAmount>().orderByDesc("record_time");
        if (StringUtils.hasText(type)) {
            queryWrapper.eq("type", type);
        }
        
        Page<PlannedAmount> pageData = plannedAmountService.page(
            new Page<>(page, pageSize),
            queryWrapper
        );
        
        return Result.build(200, "查询成功", pageData);
    }
 
    @ApiOperation("添加计划量")
    @PostMapping("/addPlanned")
    @ResponseBody
    public Result addPlanned(@RequestBody PlannedAmount value) {
        value.setCreateTime(new Date());
        value.setUpdateTime(new Date());
        boolean success = plannedAmountService.save(value);
        int count = success ? 1 : 0;
        String message = count > 0 ? "添加成功:" + count : "添加失败!";
        return Result.build(200, message, count);
    }
 
    @ApiOperation("修改计划量")
    @PostMapping("/updatePlanned")
    @ResponseBody
    public Result updatePlanned(@RequestBody PlannedAmount value) {
        value.setUpdateTime(new Date());
        boolean success = plannedAmountService.updateById(value);
        int count = success ? 1 : 0;
        String message = count > 0 ? "修改成功:" + count : "修改失败!";
        return Result.build(200, message, count);
    }
 
    @ApiOperation("删除计划量")
    @PostMapping("/deletePlanned")
    @ResponseBody
    public Result deletePlanned(@RequestBody PlannedAmount value) {
        boolean success = plannedAmountService.removeById(value.getId());
        int count = success ? 1 : 0;
        String message = count > 0 ? "删除成功:" + count : "删除失败!";
        return Result.build(200, message, count);
    }
 
    @ApiOperation("获取图表数据")
    @PostMapping("/chartPlanned")
    @ResponseBody
    public Result getChartData(@RequestBody(required = false) Map<String, Object> params) {
        String type = params != null ? (String) params.get("type") : null;
        Integer dayCount = params != null && params.get("dayCount") != null ? (Integer) params.get("dayCount") : null;
        
        QueryWrapper<PlannedAmount> queryWrapper = new QueryWrapper<PlannedAmount>().orderByAsc("record_time");
        if (StringUtils.hasText(type)) {
            queryWrapper.eq("type", type);
        }
        
        if (dayCount != null && dayCount > 0) {
            Calendar calendar = Calendar.getInstance();
            calendar.add(Calendar.DAY_OF_MONTH, -dayCount);
            Date startDate = calendar.getTime();
            queryWrapper.ge("record_time", startDate);
        }
        
        List<PlannedAmount> data = plannedAmountService.list(queryWrapper);
        
        return Result.build(200, "查询成功", data);
    }