EquipmentAlertController.java
7.76 KB
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
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
package com.ruoyi.controller.equipment.alert;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.domain.OrderEntity;
import com.ruoyi.domain.equipment.alert.EquipmentAlert;
import com.ruoyi.domain.equipment.alert.dto.EquipmentAlertAddDTO;
import com.ruoyi.domain.equipment.alert.dto.EquipmentAlertQueryDTO;
import com.ruoyi.domain.equipment.alert.dto.EquipmentAlertUpdateDTO;
import com.ruoyi.domain.equipment.alert.dto.EquipmentAlertUpdateStatusDTO;
import com.ruoyi.domain.equipment.alert.vo.EquipmentAlertVO;
import com.ruoyi.service.equipment.alert.EquipmentAlertService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.*;
import javax.servlet.http.HttpServletResponse;
import javax.validation.Valid;
import java.util.Date;
import java.util.List;
@RestController
@Api(tags = "设备警报信息")
@RequestMapping("equipment/alert")
public class EquipmentAlertController extends BaseController {
@Autowired
private EquipmentAlertService equipmentAlertService;
@ApiOperation("分页查询")
@PreAuthorize("@ss.hasPermi('equipment:alert:list:limit:page:limit')")
@PostMapping(value = "/list/limit/{page}/{pageLimit}")
public IPage<EquipmentAlertVO> listLimit(@ModelAttribute EquipmentAlertQueryDTO request, @ModelAttribute OrderEntity orderEntity, @PathVariable Integer page, @PathVariable Integer pageLimit, org.springframework.ui.Model model) {
EquipmentAlert entity = convert(request);
IPage<EquipmentAlert> response = equipmentAlertService.pageList(new Page<EquipmentAlert>(page, pageLimit), entity, orderEntity);
return convert(response);
}
@ApiOperation("根据ID查询详情")
@GetMapping(value = "/view/{id}")
public com.ruoyi.common.core.domain.ResponseResult<EquipmentAlertVO> view(@PathVariable("id") Long id, org.springframework.ui.Model model) {
EquipmentAlert source = equipmentAlertService.getById(id);
return com.ruoyi.common.core.domain.ResponseResult.success(convert(source));
}
// @PostMapping(value = "/list/select")
// @ApiOperation("(页面选择)")
// public com.ruoyi.common.core.domain.ResponseResult<List<EquipmentAlertVO>> listSelect(EquipmentAlertQueryDTO request) {
// EquipmentAlert entity = convert(request);
// List<EquipmentAlert> selectList = equipmentAlertService.listOfSelect(entity);
// return com.ruoyi.common.core.domain.ResponseResult.success(convert(selectList));
// }
@PreAuthorize("@ss.hasPermi('equipment:alert:export')")
@ApiOperation("导出")
@PostMapping("/export")
public void export(HttpServletResponse response, @RequestBody EquipmentAlertQueryDTO request) {
EquipmentAlert entity = convert(request);
List<EquipmentAlert> list = equipmentAlertService.list(entity);
ExcelUtil<EquipmentAlert> util = new ExcelUtil<EquipmentAlert>(EquipmentAlert.class);
util.exportExcel(response, list, "EquipmentAlert");
}
@ApiOperation("添加")
@PreAuthorize("@ss.hasPermi('equipment:alert:add')")
@PostMapping(value = "/add")
public com.ruoyi.common.core.domain.ResponseResult add(@Valid @ModelAttribute EquipmentAlertAddDTO request, BindingResult bindingResult) {
if (bindingResult.hasErrors()) {
return com.ruoyi.common.core.domain.ResponseResult.error(bindingResult.getFieldError().getDefaultMessage());
}
EquipmentAlert entity = convert(request);
entity.setCreateBy(getUserId());
entity.setCreateTime(new Date());
int count = equipmentAlertService.insertSelective(entity);
return count > 0 ? com.ruoyi.common.core.domain.ResponseResult.success(Boolean.TRUE) : com.ruoyi.common.core.domain.ResponseResult.error("添加数据失败,请稍后再试");
}
@ApiOperation("修改")
@PreAuthorize("@ss.hasPermi('equipment:alert:update')")
@PostMapping(value = "/update")
public com.ruoyi.common.core.domain.ResponseResult update(@Valid @ModelAttribute EquipmentAlertUpdateDTO request, BindingResult bindingResult) {
if (bindingResult.hasErrors()) {
return com.ruoyi.common.core.domain.ResponseResult.error(bindingResult.getFieldError().getDefaultMessage());
}
EquipmentAlert entity = convert(request);
entity.setUpdateBy(getUserId());
entity.setUpdateTime(new Date());
boolean flag = equipmentAlertService.updateByPrimaryKey(entity);
return flag ? com.ruoyi.common.core.domain.ResponseResult.success(Boolean.TRUE) : com.ruoyi.common.core.domain.ResponseResult.error("修改数据失败,请稍后再试");
}
@ApiOperation("修改状态")
@PreAuthorize("@ss.hasPermi('equipment:alert:update:status')")
@PostMapping(value = "/update/status")
public com.ruoyi.common.core.domain.ResponseResult updateState(@ModelAttribute EquipmentAlertUpdateStatusDTO request) {
EquipmentAlert entity = convert(request);
boolean flag = equipmentAlertService.updateByPrimaryKey(entity);
return flag ? com.ruoyi.common.core.domain.ResponseResult.success(Boolean.TRUE) : com.ruoyi.common.core.domain.ResponseResult.error("修改数据失败,请稍后再试");
}
private EquipmentAlert convert(EquipmentAlertQueryDTO source) {
return java.util.Optional.ofNullable(source).map(sc -> {
EquipmentAlert target = new EquipmentAlert();
BeanUtils.copyProperties(sc, target);
return target;
}).orElse(null);
}
private EquipmentAlert convert(EquipmentAlertUpdateDTO source) {
return java.util.Optional.ofNullable(source).map(sc -> {
EquipmentAlert target = new EquipmentAlert();
BeanUtils.copyProperties(sc, target);
return target;
}).orElse(null);
}
private EquipmentAlert convert(EquipmentAlertUpdateStatusDTO source) {
return java.util.Optional.ofNullable(source).map(sc -> {
EquipmentAlert target = new EquipmentAlert();
BeanUtils.copyProperties(sc, target);
return target;
}).orElse(null);
}
private EquipmentAlert convert(EquipmentAlertAddDTO source) {
return java.util.Optional.ofNullable(source).map(sc -> {
EquipmentAlert target = new EquipmentAlert();
BeanUtils.copyProperties(sc, target);
return target;
}).orElseGet(null);
}
private EquipmentAlertVO convert(EquipmentAlert source) {
return java.util.Optional.ofNullable(source).map(sc -> {
EquipmentAlertVO target = new EquipmentAlertVO();
BeanUtils.copyProperties(source, target);
return target;
}).orElseGet(null);
}
private List<EquipmentAlertVO> convert(List<EquipmentAlert> sources) {
return java.util.Optional.ofNullable(sources).map(scs -> {
return scs.stream().map(source -> {
return convert(source);
}).collect(java.util.stream.Collectors.toList());
}).orElseGet(null);
}
private IPage<EquipmentAlertVO> convert(IPage<EquipmentAlert> sources) {
return java.util.Optional.ofNullable(sources).map(scs -> {
IPage<EquipmentAlertVO> target = new Page();
BeanUtils.copyProperties(scs, target);
List<EquipmentAlertVO> voNames = convert(scs.getRecords());
target.setRecords(voNames);
return target;
}).orElseGet(null);
}
}