DriverHealthyController.java
6.81 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
package com.ruoyi.controller.driver.healthy;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.*;
import org.springframework.beans.BeanUtils;
import org.springframework.security.access.prepost.PreAuthorize;
import java.util.Date;
import java.util.List;
import com.ruoyi.domain.OrderEntity;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.alibaba.fastjson2.JSON;
import com.ruoyi.common.utils.poi.ExcelUtil;
import javax.servlet.http.HttpServletResponse;
import com.ruoyi.service.driver.healthy.DriverHealthyService;
import com.ruoyi.domain.driver.healthy.vo.DriverHealthyVO;
import com.ruoyi.domain.driver.healthy.dto.DriverHealthyAddDTO;
import com.ruoyi.domain.driver.healthy.dto.DriverHealthyUpdateDTO;
import com.ruoyi.domain.driver.healthy.dto.DriverHealthyUpdateStatusDTO;
import com.ruoyi.domain.driver.healthy.dto.DriverHealthyQueryDTO;
import com.ruoyi.domain.driver.healthy.DriverHealthy;
@RestController
@RequestMapping("driver/healthy")
public class DriverHealthyController extends BaseController {
@Autowired
private DriverHealthyService driverHealthyService;
@PreAuthorize("@ss.hasPermi('driver:healthy:list:limit:page:limit')")
@PostMapping(value = "/list/limit/{page}/{pageLimit}")
public String listLimit(@ModelAttribute DriverHealthyQueryDTO request, @ModelAttribute OrderEntity orderEntity, @PathVariable Integer page, @PathVariable Integer pageLimit, org.springframework.ui.Model model) {
request.clearStrEmpty();
DriverHealthy entity = convert(request);
IPage<DriverHealthy> response = driverHealthyService.pageList(new Page<DriverHealthy>(page, pageLimit), entity, orderEntity);
return JSON.toJSONString(convert(response));
}
@GetMapping(value = "/view/{id}")
public com.ruoyi.common.core.domain.AjaxResult view(@PathVariable("id") Long id, org.springframework.ui.Model model) {
DriverHealthy source = driverHealthyService.getById(id);
return com.ruoyi.common.core.domain.AjaxResult.success(convert(source));
}
@PreAuthorize("@ss.hasPermi('driver:healthy:export')")
@PostMapping("/export")
public void export(HttpServletResponse response, @RequestBody DriverHealthyQueryDTO request) {
request.clearStrEmpty();
DriverHealthy entity = convert(request);
List<DriverHealthy> list = driverHealthyService.list(entity);
ExcelUtil<DriverHealthy> util = new ExcelUtil<DriverHealthy>(DriverHealthy.class);
util.exportExcel(response, list, "DriverHealthy");
}
@PreAuthorize("@ss.hasPermi('driver:healthy:add')")
@PostMapping(value = "/add")
public com.ruoyi.common.core.domain.AjaxResult add(@ModelAttribute DriverHealthyAddDTO request) {
request.clearStrEmpty();
DriverHealthy entity = convert(request);
entity.setCreateBy(getUserId());
entity.setCreateTime(new Date());
int count = driverHealthyService.insertSelective(entity);
return count > 0 ? com.ruoyi.common.core.domain.AjaxResult.success(Boolean.TRUE) : com.ruoyi.common.core.domain.AjaxResult.error("添加数据失败,请稍后再试");
}
@PreAuthorize("@ss.hasPermi('driver:healthy:update')")
@PostMapping(value = "/update")
public com.ruoyi.common.core.domain.AjaxResult update(@ModelAttribute DriverHealthyUpdateDTO request) {
request.clearStrEmpty();
DriverHealthy entity = convert(request);
entity.setUpdateBy(getUserId());
entity.setUpdateTime(new Date());
boolean flag = driverHealthyService.updateByPrimaryKey(entity);
return flag ? com.ruoyi.common.core.domain.AjaxResult.success(Boolean.TRUE) : com.ruoyi.common.core.domain.AjaxResult.error("修改数据失败,请稍后再试");
}
@PreAuthorize("@ss.hasPermi('driver:healthy:update:status')")
@PostMapping(value = "/update/status")
public com.ruoyi.common.core.domain.AjaxResult updateState(@ModelAttribute DriverHealthyUpdateStatusDTO request) {
request.clearStrEmpty();
DriverHealthy entity = convert(request);
boolean flag = driverHealthyService.updateByPrimaryKey(entity);
return flag ? com.ruoyi.common.core.domain.AjaxResult.success(Boolean.TRUE) : com.ruoyi.common.core.domain.AjaxResult.error("修改数据失败,请稍后再试");
}
private DriverHealthy convert(DriverHealthyQueryDTO source) {
return java.util.Optional.ofNullable(source).map(sc -> {
DriverHealthy target = new DriverHealthy();
BeanUtils.copyProperties(sc, target);
return target;
}).orElse(null);
}
private DriverHealthy convert(DriverHealthyUpdateDTO source) {
return java.util.Optional.ofNullable(source).map(sc -> {
DriverHealthy target = new DriverHealthy();
BeanUtils.copyProperties(sc, target);
return target;
}).orElse(null);
}
private DriverHealthy convert(DriverHealthyUpdateStatusDTO source) {
return java.util.Optional.ofNullable(source).map(sc -> {
DriverHealthy target = new DriverHealthy();
BeanUtils.copyProperties(sc, target);
return target;
}).orElse(null);
}
private DriverHealthy convert(DriverHealthyAddDTO source) {
return java.util.Optional.ofNullable(source).map(sc -> {
DriverHealthy target = new DriverHealthy();
BeanUtils.copyProperties(sc, target);
return target;
}).orElseGet(null);
}
private DriverHealthyVO convert(DriverHealthy source) {
return java.util.Optional.ofNullable(source).map(sc -> {
DriverHealthyVO target = new DriverHealthyVO();
BeanUtils.copyProperties(source, target);
return target;
}).orElseGet(null);
}
private List<DriverHealthyVO> convert(List<DriverHealthy> 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<DriverHealthyVO> convert(IPage<DriverHealthy> sources) {
return java.util.Optional.ofNullable(sources).map(scs -> {
IPage<DriverHealthyVO> target = new Page();
BeanUtils.copyProperties(scs, target);
List<DriverHealthyVO> voNames = convert(scs.getRecords());
target.setRecords(voNames);
return target;
}).orElseGet(null);
}
}