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);
|
}
|
}
|