龚焕茏
2024-08-23 036af8cd158f5768c83cd98ad6dd6256a22feec6
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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
package com.ycl.platform.controller;
 
import com.ycl.platform.domain.form.BatchEditPointForm;
import com.ycl.system.domain.group.Update;
import com.ycl.system.domain.group.Add;
import jakarta.servlet.http.HttpServletResponse;
import jakarta.validation.constraints.NotBlank;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.util.StringUtils;
import org.springframework.validation.annotation.Validated;
import lombok.RequiredArgsConstructor;
 
import java.io.IOException;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;
import org.springframework.validation.annotation.Validated;
import jakarta.validation.constraints.NotEmpty;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import com.ycl.platform.service.YwPointService;
import com.ycl.system.Result;
import com.ycl.platform.domain.form.YwPointForm;
import com.ycl.platform.domain.query.YwPointQuery;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
 
/**
 * 运维点位 前端控制器
 *
 * @author xp
 * @since 2024-03-05
 */
@Validated
@RequiredArgsConstructor
@Api(value = "运维点位", tags = "运维点位管理")
@RestController
@RequestMapping("/yw-point")
public class YwPointController {
 
    private final YwPointService ywPointService;
 
    @PostMapping
    @ApiOperation(value = "添加", notes = "添加")
    @PreAuthorize("@ss.hasPermi('point:add')")
    public Result add(@RequestBody @Validated(Add.class) YwPointForm form) {
        return ywPointService.add(form);
    }
 
    @PostMapping("/batch")
    @ApiOperation(value = "批量添加", notes = "批量添加")
    @PreAuthorize("@ss.hasPermi('point:add')")
    public Result batchAdd(@RequestBody @NotEmpty(message = "数据不能为空") List<YwPointForm> form) {
        return ywPointService.batchAdd(form);
    }
 
    @PutMapping
    @ApiOperation(value = "修改", notes = "修改")
    @PreAuthorize("@ss.hasPermi('point:edit')")
    public Result update(@RequestBody @Validated(Update.class) YwPointForm form) {
        return ywPointService.update(form);
    }
 
    @PutMapping("/batch")
    @ApiOperation(value = "批量修改运维单位", notes = "批量修改运维单位")
    @PreAuthorize("@ss.hasPermi('point:edit')")
    public Result batchEdit(@RequestBody @Validated BatchEditPointForm form) {
        return ywPointService.batchEdit(form);
    }
 
    @DeleteMapping("/{id}")
    @ApiOperation(value = "ID删除", notes = "ID删除")
    @PreAuthorize("@ss.hasPermi('point:remove')")
    public Result removeById(@PathVariable("id") String id) {
        return ywPointService.removeById(id);
    }
 
    @DeleteMapping("/batch")
    @ApiOperation(value = "批量删除", notes = "批量删除")
    @PreAuthorize("@ss.hasPermi('point:remove')")
    public Result remove(@RequestBody @NotEmpty(message = "请选择数据") List<String> ids) {
        return ywPointService.remove(ids);
    }
 
    @GetMapping("/page")
    @ApiOperation(value = "分页", notes = "分页")
    @PreAuthorize("@ss.hasPermi('point:page')")
    public Result page(YwPointQuery query) {
        return ywPointService.page(query);
    }
 
    @GetMapping("/{id}")
    @ApiOperation(value = "详情", notes = "详情")
    @PreAuthorize("@ss.hasPermi('point:query')")
    public Result detail(@PathVariable("id") String id) {
        return ywPointService.detail(id);
    }
 
    @GetMapping("/list")
    @ApiOperation(value = "列表", notes = "列表")
    @PreAuthorize("@ss.hasPermi('point:list')")
    public Result list() {
        return ywPointService.all();
    }
 
    @GetMapping("/select")
    @ApiOperation(value = "点位下拉", notes = "点位下拉")
    public Result select(@NotBlank(message = "请输入点位") String keyword) {
        return ywPointService.select(keyword);
    }
 
    @GetMapping("/export")
    @ApiOperation(value = "导出数据", notes = "导出数据")
    public void export(YwPointQuery query, HttpServletResponse response) throws IOException {
        ywPointService.export(query, response);
    }
 
    @PostMapping("/import")
    @ApiOperation(value = "导入数据", notes = "导入数据")
    public Result importData(MultipartFile file,
                             Integer unitId,
                             String startTime,
                             String endTime) throws IOException, ParseException {
        Date start = null;
        Date end = null;
        if (-1 == unitId) {
            unitId = null;
        }
        if (StringUtils.hasText(startTime)) {
            SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
            start = format.parse(startTime);
        }
        if (StringUtils.hasText(startTime)) {
            SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
            end = format.parse(endTime);
        }
        return ywPointService.importData(file, unitId, start, end);
    }
 
}