liulin
2024-11-24 af410d1cde67d4656c9922ff4d846cac0740e3b2
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
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
package com.lunhan.xxx.host.controller;
 
import com.lunhan.xxx.common.ConstantFactory;
import com.lunhan.xxx.common.ExecutedResult;
import com.lunhan.xxx.common.PagerResult;
import com.lunhan.xxx.common.util.ParameterUtil;
import com.lunhan.xxx.common.validator.ParameterValidateResult;
import com.lunhan.xxx.common.validator.ParameterValidator;
import com.lunhan.xxx.entity.search.SearchTestInfo;
import com.lunhan.xxx.entity.enums.ESex;
import com.lunhan.xxx.entity.request.ReqListId;
import com.lunhan.xxx.entity.request.ReqListSetSort;
import com.lunhan.xxx.entity.request.ReqSetSort;
import com.lunhan.xxx.entity.request.test.ReqCreateTestInfo;
import com.lunhan.xxx.entity.request.test.ReqModifyTestInfo;
import com.lunhan.xxx.host.BasicController;
import com.lunhan.xxx.host.api.NonLogin;
import com.lunhan.xxx.repository.vo.TestInfoVO;
import com.lunhan.xxx.service.TestInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
 
import java.math.BigDecimal;
import java.util.List;
 
/**
 * 99999.测试信息相关接口
 *
 * @author lin.liu
 * @date 2021/11/23
 * @order 99999
 */
@NonLogin
@RestController
@RequestMapping(value = "testInfo")
public class TestInfoServiceController extends BasicController {
    @Autowired
    private TestInfoService service;
    /**
     * 创建[测试信息]
     *
     * @author lin.liu
     * @date 2021/11/23
     */
    @PostMapping(value = "create")
    public ExecutedResult<Long> create(@RequestBody ReqCreateTestInfo request) {
        //#region 参数验证
        ParameterValidator validator = new ParameterValidator()
                // 非空
                .addNotNullOrEmpty(ParameterUtil.named("名称"), request.getName())
                // 限制最大长度
                .addLengthMax(ParameterUtil.named("名称"), request.getName(), ConstantFactory.LENGTH_MAX50)
                // 必须大于0
                .addGreater(ParameterUtil.named("用户id"), request.getUserId(), 0L)
                // 必须是手机号码(正则)
                .addMustMobile(ParameterUtil.named("电话"), request.getPhone())
                // 金额大于0
                .addGreaterThan(ParameterUtil.named("余额"), request.getBalance(), BigDecimal.ZERO)
                // 必须是枚举值
                .addMustEnum(ParameterUtil.named("性别"), request.getSex(), ESex.class)
                // 必须是日期字符串(yyyy-MM-dd)
                .addMustDate(ParameterUtil.named("生日"), request.getBirthday())
                // 必须大于0
                .addGreater(ParameterUtil.named("排序值"), request.getSort(), 0)
                // 限制最大长度
                .addLengthMax(ParameterUtil.named("备注"), request.getComment(), ConstantFactory.LENGTH_MAX500);
        ParameterValidateResult result = validator.validate();
        if (result.getIsFiled()) {
            return failed(result.getErrorMsg());
        }
        //#endregion
        return this.service.create(request);
    }
 
    /**
     * 编辑[测试信息]
     *
     * @author lin.liu
     * @date 2021/11/23
     */
    @PostMapping(value = "modify")
    public ExecutedResult<String> modify(@RequestBody ReqModifyTestInfo request) {
        //#region 参数验证
        ParameterValidator validator = new ParameterValidator()
                // 必须大于0
                .addGreater(ParameterUtil.named("[测试信息]id"), request.getId(), 0L)
                // 非空
                .addNotNullOrEmpty(ParameterUtil.named("名称"), request.getName())
                // 限制最大长度
                .addLengthMax(ParameterUtil.named("名称"), request.getName(), ConstantFactory.LENGTH_MAX50)
                // 必须大于0
                .addGreater(ParameterUtil.named("用户id"), request.getUserId(), 0L)
                // 必须是手机号码(正则)
                .addMustMobile(ParameterUtil.named("电话"), request.getPhone())
                // 金额大于0
                .addGreaterThan(ParameterUtil.named("余额"), request.getBalance(), BigDecimal.ZERO)
                // 必须是枚举值
                .addMustEnum(ParameterUtil.named("性别"), request.getSex(), ESex.class)
                // 必须是日期字符串(yyyy-MM-dd)
                .addMustDate(ParameterUtil.named("生日"), request.getBirthday())
                // 必须大于0
                .addGreater(ParameterUtil.named("排序值"), request.getSort(), 0)
                // 限制最大长度
                .addLengthMax(ParameterUtil.named("备注"), request.getComment(), ConstantFactory.LENGTH_MAX500);
        ParameterValidateResult result = validator.validate();
        if (result.getIsFiled()) {
            return failed(result.getErrorMsg());
        }
        //#endregion
        return this.service.modify(request);
    }
 
    /**
     * 获取[测试信息]
     *
     * @author lin.liu
     * @date 2021/11/23
     */
    @GetMapping(value = "get/{id}")
    public ExecutedResult<TestInfoVO> get(@PathVariable Long id) {
        return this.service.get(id);
    }
 
    /**
     * 根据id批量获取[测试信息]
     *
     * @author lin.liu
     * @date 2021/11/23
     */
    @PostMapping(value = "getList")
    public ExecutedResult<List<TestInfoVO>> getList(@RequestBody ReqListId request) {
        //#region 参数验证
        ParameterValidator validator = new ParameterValidator()
                // 不能为空
                .addNotNullOrEmpty(ParameterUtil.named("[测试信息]id列表"), request.getListId())
                ;
        ParameterValidateResult result = validator.validate();
        if (result.getIsFiled()) {
            return failed(result.getErrorMsg());
        }
        //#endregion
        return this.service.getList(request.getListId());
    }
 
    /**
     * [测试信息]设置排序值
     *
     * @author lin.liu
     * @date 2021/11/23
     */
    @PostMapping(value = "setSort")
    public ExecutedResult<String> setSort(@RequestBody ReqSetSort request) {
        //#region 参数验证
        ParameterValidator validator = new ParameterValidator()
                // 必须大于0
                .addGreater(ParameterUtil.named("[测试信息]id"), request.getId(), 0L)
                // 必须大于0
                .addGreaterThan(ParameterUtil.named("排序值"), request.getSort(), 0)
                ;
        ParameterValidateResult result = validator.validate();
        if (result.getIsFiled()) {
            return failed(result.getErrorMsg());
        }
        //#endregion
        return this.service.setSort(request);
    }
 
    /**
     * [测试信息]批量设置排序值
     *
     * @author lin.liu
     * @date 2021/11/23
     */
    @PostMapping(value = "listSetSort")
    ExecutedResult<String> listSetSort(ReqListSetSort request) {
        //#region 参数验证
        ParameterValidator validator = new ParameterValidator()
                // 不能为空
                .addNotNullOrEmpty(ParameterUtil.named("[测试信息]排序设置列表"), request.getList())
                ;
        ParameterValidateResult result = validator.validate();
        if (result.getIsFiled()) {
            return failed(result.getErrorMsg());
        }
        //#endregion
        return this.service.listSetSort(request);
    }
 
    /**
     * 停用[测试信息]
     *
     * @param id [测试]id
     * @author lin.liu
     * @date 2021/11/23
     */
    @PostMapping(value = "stop/{id}")
    public ExecutedResult<String> stop(@PathVariable Long id) {
        return this.service.stop(id);
    }
 
    /**
     * 启用[测试信息]
     *
     * @param id [测试]id
     * @author lin.liu
     * @date 2021/11/23
     */
    @PostMapping(value = "enable/{id}")
    public ExecutedResult<String> enable(@PathVariable Long id) {
        return this.service.enable(id);
    }
 
    /**
     * 删除[测试信息]
     *
     * @param id [测试]id
     * @author lin.liu
     * @date 2021/11/23
     */
    @PostMapping(value = "remove/{id}")
    public ExecutedResult<String> remove(@PathVariable Long id) {
        return this.service.remove(id);
    }
 
    /**
     * 批量删除[测试信息]
     *
     * @author lin.liu
     * @date 2021/11/23
     */
    @PostMapping(value = "removeList")
    public ExecutedResult<String> removeList(@RequestBody ReqListId request) {
        //#region 参数验证
        ParameterValidator validator = new ParameterValidator()
                // 不能为空
                .addNotNullOrEmpty(ParameterUtil.named("[测试信息]id列表"), request.getListId())
                ;
        ParameterValidateResult result = validator.validate();
        if (result.getIsFiled()) {
            return failed(result.getErrorMsg());
        }
        //#endregion
        return this.service.removeList(request.getListId());
    }
 
    /**
     * 查询[测试信息]
     *
     * @author lin.liu
     * @date 2021/11/23
     */
    @NonLogin
    @PostMapping(value = "search")
    public ExecutedResult<PagerResult<TestInfoVO>> search(@RequestBody SearchTestInfo request) {
        return this.service.search(request);
    }
}