mirror of
http://git.pig4cloud.com/pig/pigx.git
synced 2026-11-08 20:49:00 +08:00
✨ 添加新特性。新特性 validate
This commit is contained in:
1 parent
6fcd3fde87
commit
fd91f630a6
17 files changed
+125
-28
No files matched your search
@@ -1,5 +1,5 @@
|
||||
<p align="center">
|
||||
<img src="https://img.shields.io/circleci/project/vuejs/vue/dev.svg" alt="Build Status">
|
||||
<img src="https://img.shields.io/badge/Avue-1.5.4.RC1-green.svg" alt="Build Status">
|
||||
<img src="https://img.shields.io/badge/Spring%20Cloud-Finchley.RELEASE-blue.svg" alt="Coverage Status">
|
||||
<img src="https://img.shields.io/badge/Spring%20Boot-2.0.3.RELEASE-blue.svg" alt="Downloads">
|
||||
</p>
|
||||
|
||||
@@ -50,11 +50,6 @@
|
||||
<groupId>javax.servlet</groupId>
|
||||
<artifactId>javax.servlet-api</artifactId>
|
||||
</dependency>
|
||||
<!--jacksonJSR310规范-->
|
||||
<dependency>
|
||||
<groupId>com.fasterxml.jackson.datatype</groupId>
|
||||
<artifactId>jackson-datatype-jsr310</artifactId>
|
||||
</dependency>
|
||||
<!--mybatis-->
|
||||
<dependency>
|
||||
<groupId>com.baomidou</groupId>
|
||||
@@ -70,5 +65,15 @@
|
||||
<groupId>org.springframework.cloud</groupId>
|
||||
<artifactId>spring-cloud-starter-openfeign</artifactId>
|
||||
</dependency>
|
||||
<!--hibernate-validator-->
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-validation</artifactId>
|
||||
</dependency>
|
||||
<!--jacksonJSR310规范-->
|
||||
<dependency>
|
||||
<groupId>com.fasterxml.jackson.datatype</groupId>
|
||||
<artifactId>jackson-datatype-jsr310</artifactId>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</project>
|
||||
+23
-3
@@ -20,11 +20,15 @@ package com.pig4cloud.pigx.common.core.exception;
|
||||
import com.pig4cloud.pigx.common.core.util.R;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.validation.BindException;
|
||||
import org.springframework.validation.FieldError;
|
||||
import org.springframework.web.bind.MethodArgumentNotValidException;
|
||||
import org.springframework.web.bind.annotation.ExceptionHandler;
|
||||
import org.springframework.web.bind.annotation.ResponseBody;
|
||||
import org.springframework.web.bind.annotation.ResponseStatus;
|
||||
import org.springframework.web.bind.annotation.RestControllerAdvice;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author lengleng
|
||||
* @date 2018/8/30
|
||||
@@ -41,9 +45,25 @@ public class GlobalExceptionHandler {
|
||||
*/
|
||||
@ExceptionHandler(Exception.class)
|
||||
@ResponseStatus(HttpStatus.INTERNAL_SERVER_ERROR)
|
||||
@ResponseBody
|
||||
public R exception(Exception e) {
|
||||
log.info("全局异常信息 ex={}", e.getMessage(), e);
|
||||
log.error("全局异常信息 ex={}", e.getMessage(), e);
|
||||
return new R<>(e);
|
||||
}
|
||||
|
||||
/**
|
||||
* validation Exception
|
||||
*
|
||||
* @param exception
|
||||
* @return R
|
||||
*/
|
||||
@ExceptionHandler({MethodArgumentNotValidException.class, BindException.class})
|
||||
@ResponseStatus(HttpStatus.BAD_REQUEST)
|
||||
public R bodyValidExceptionHandler(MethodArgumentNotValidException exception) {
|
||||
List<FieldError> fieldErrors = exception.getBindingResult().getFieldErrors();
|
||||
R result = new R();
|
||||
result.setMsg(fieldErrors.get(0).getDefaultMessage());
|
||||
log.warn(fieldErrors.get(0).getDefaultMessage());
|
||||
return result;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -27,6 +27,7 @@ import com.baomidou.mybatisplus.enums.IdType;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
|
||||
import javax.validation.constraints.NotBlank;
|
||||
import java.io.Serializable;
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
@@ -50,6 +51,7 @@ public class SysDept extends Model<SysDept> {
|
||||
/**
|
||||
* 部门名称
|
||||
*/
|
||||
@NotBlank(message = "部门名称不能为空")
|
||||
private String name;
|
||||
/**
|
||||
* 排序
|
||||
|
||||
@@ -27,6 +27,7 @@ import com.baomidou.mybatisplus.enums.IdType;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
|
||||
import javax.validation.constraints.NotBlank;
|
||||
import java.io.Serializable;
|
||||
import java.math.BigDecimal;
|
||||
import java.time.LocalDateTime;
|
||||
@@ -54,14 +55,17 @@ public class SysDict extends Model<SysDict> {
|
||||
/**
|
||||
* 数据值
|
||||
*/
|
||||
@NotBlank(message = "字典项数据值不能为空")
|
||||
private String value;
|
||||
/**
|
||||
* 标签名
|
||||
*/
|
||||
@NotBlank(message = "字典项标签不能为空")
|
||||
private String label;
|
||||
/**
|
||||
* 类型
|
||||
*/
|
||||
@NotBlank(message = "字典项数据类型不能为空")
|
||||
private String type;
|
||||
/**
|
||||
* 描述
|
||||
|
||||
@@ -24,6 +24,7 @@ import com.baomidou.mybatisplus.annotations.TableLogic;
|
||||
import com.baomidou.mybatisplus.enums.IdType;
|
||||
import lombok.Data;
|
||||
|
||||
import javax.validation.constraints.NotBlank;
|
||||
import java.io.Serializable;
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
@@ -48,10 +49,12 @@ public class SysLog implements Serializable {
|
||||
/**
|
||||
* 日志类型
|
||||
*/
|
||||
@NotBlank(message = "日志类型不能为空")
|
||||
private String type;
|
||||
/**
|
||||
* 日志标题
|
||||
*/
|
||||
@NotBlank(message = "日志标题不能为空")
|
||||
private String title;
|
||||
/**
|
||||
* 创建者
|
||||
|
||||
@@ -27,6 +27,8 @@ import com.baomidou.mybatisplus.enums.IdType;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
|
||||
import javax.validation.constraints.NotBlank;
|
||||
import javax.validation.constraints.NotNull;
|
||||
import java.io.Serializable;
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
@@ -48,11 +50,13 @@ public class SysMenu extends Model<SysMenu> {
|
||||
/**
|
||||
* 菜单ID
|
||||
*/
|
||||
@NotNull(message = "菜单ID不能为空")
|
||||
@TableId(value = "menu_id", type = IdType.INPUT)
|
||||
private Integer menuId;
|
||||
/**
|
||||
* 菜单名称
|
||||
*/
|
||||
@NotBlank(message = "菜单名称不能为空")
|
||||
private String name;
|
||||
/**
|
||||
* 菜单权限标识
|
||||
|
||||
+42
-1
@@ -26,6 +26,7 @@ import com.baomidou.mybatisplus.enums.IdType;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
|
||||
import javax.validation.constraints.NotBlank;
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
@@ -43,17 +44,57 @@ public class SysOauthClientDetails extends Model<SysOauthClientDetails> {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
/**
|
||||
* 客户端ID
|
||||
*/
|
||||
@NotBlank(message = "client_id 不能为空")
|
||||
@TableId(value = "client_id", type = IdType.INPUT)
|
||||
private String clientId;
|
||||
private String resourceIds;
|
||||
|
||||
/**
|
||||
* 客户端密钥
|
||||
*/
|
||||
@NotBlank(message = "client_secret 不能为空")
|
||||
private String clientSecret;
|
||||
|
||||
/**
|
||||
* 资源ID
|
||||
*/
|
||||
private String resourceIds;
|
||||
|
||||
/**
|
||||
* 作用域
|
||||
*/
|
||||
@NotBlank(message = "scope 不能为空")
|
||||
private String scope;
|
||||
|
||||
/**
|
||||
* 授权方式(A,B,C)
|
||||
*/
|
||||
private String authorizedGrantTypes;
|
||||
|
||||
private String webServerRedirectUri;
|
||||
|
||||
private String authorities;
|
||||
|
||||
/**
|
||||
* 请求令牌有效时间
|
||||
*/
|
||||
private Integer accessTokenValidity;
|
||||
|
||||
/**
|
||||
* 刷新令牌有效时间
|
||||
*/
|
||||
private Integer refreshTokenValidity;
|
||||
|
||||
/**
|
||||
* 扩展信息
|
||||
*/
|
||||
private String additionalInformation;
|
||||
|
||||
/**
|
||||
* 是否自动放行
|
||||
*/
|
||||
private String autoapprove;
|
||||
|
||||
@Override
|
||||
|
||||
@@ -27,6 +27,7 @@ import com.baomidou.mybatisplus.enums.IdType;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
|
||||
import javax.validation.constraints.NotBlank;
|
||||
import java.io.Serializable;
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
@@ -47,9 +48,16 @@ public class SysRole extends Model<SysRole> {
|
||||
|
||||
@TableId(value = "role_id", type = IdType.AUTO)
|
||||
private Integer roleId;
|
||||
|
||||
@NotBlank(message = "角色名称 不能为空")
|
||||
private String roleName;
|
||||
|
||||
@NotBlank(message = "角色标识 不能为空")
|
||||
private String roleCode;
|
||||
|
||||
@NotBlank(message = "角色描述 不能为空")
|
||||
private String roleDesc;
|
||||
|
||||
private LocalDateTime createTime;
|
||||
private LocalDateTime updateTime;
|
||||
/**
|
||||
|
||||
+4
@@ -24,6 +24,7 @@ import com.baomidou.mybatisplus.annotations.TableName;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
|
||||
import javax.validation.constraints.NotBlank;
|
||||
import java.io.Serializable;
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
@@ -47,6 +48,7 @@ public class SysSocialDetails extends Model<SysSocialDetails> {
|
||||
/**
|
||||
* 类型
|
||||
*/
|
||||
@NotBlank(message = "类型不能为空")
|
||||
private String type;
|
||||
/**
|
||||
* 描述
|
||||
@@ -55,10 +57,12 @@ public class SysSocialDetails extends Model<SysSocialDetails> {
|
||||
/**
|
||||
* appid
|
||||
*/
|
||||
@NotBlank(message = "账号不能为空")
|
||||
private String appId;
|
||||
/**
|
||||
* app_secret
|
||||
*/
|
||||
@NotBlank(message = "密钥不能为空")
|
||||
private String appSecret;
|
||||
/**
|
||||
* 回调地址
|
||||
|
||||
+3
-2
@@ -29,6 +29,7 @@ import lombok.AllArgsConstructor;
|
||||
import org.springframework.security.access.prepost.PreAuthorize;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import javax.validation.Valid;
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.List;
|
||||
|
||||
@@ -78,7 +79,7 @@ public class DeptController {
|
||||
*/
|
||||
@PostMapping
|
||||
@PreAuthorize("@pms.hasPermission('sys_dept_add')")
|
||||
public R<Boolean> add(@RequestBody SysDept sysDept) {
|
||||
public R<Boolean> add(@Valid @RequestBody SysDept sysDept) {
|
||||
return new R<>(sysDeptService.insertDept(sysDept));
|
||||
}
|
||||
|
||||
@@ -102,7 +103,7 @@ public class DeptController {
|
||||
*/
|
||||
@PutMapping
|
||||
@PreAuthorize("@pms.hasPermission('sys_dept_edit')")
|
||||
public Boolean edit(@RequestBody SysDept sysDept) {
|
||||
public Boolean edit(@Valid @RequestBody SysDept sysDept) {
|
||||
sysDept.setUpdateTime(LocalDateTime.now());
|
||||
return sysDeptService.updateDeptById(sysDept);
|
||||
}
|
||||
|
||||
+3
-2
@@ -34,6 +34,7 @@ import org.springframework.cache.annotation.Cacheable;
|
||||
import org.springframework.security.access.prepost.PreAuthorize;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import javax.validation.Valid;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
@@ -99,7 +100,7 @@ public class DictController {
|
||||
@PostMapping
|
||||
@CacheEvict(value = "dict_details", key = "#sysDict.type")
|
||||
@PreAuthorize("@pms.hasPermission('sys_dict_add')")
|
||||
public R<Boolean> dict(@RequestBody SysDict sysDict) {
|
||||
public R<Boolean> dict(@Valid @RequestBody SysDict sysDict) {
|
||||
return new R<>(sysDictService.insert(sysDict));
|
||||
}
|
||||
|
||||
@@ -128,7 +129,7 @@ public class DictController {
|
||||
@SysLog("修改字典")
|
||||
@CacheEvict(value = "dict_details", key = "#sysDict.type")
|
||||
@PreAuthorize("@pms.hasPermission('sys_dict_edit')")
|
||||
public R<Boolean> editDict(@RequestBody SysDict sysDict) {
|
||||
public R<Boolean> editDict(@Valid @RequestBody SysDict sysDict) {
|
||||
return new R<>(sysDictService.updateById(sysDict));
|
||||
}
|
||||
}
|
||||
+2
-1
@@ -32,6 +32,7 @@ import lombok.AllArgsConstructor;
|
||||
import org.springframework.security.access.prepost.PreAuthorize;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import javax.validation.Valid;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
@@ -80,7 +81,7 @@ public class LogController {
|
||||
* @return success/false
|
||||
*/
|
||||
@PostMapping
|
||||
public R<Boolean> save(@RequestBody SysLog sysLog) {
|
||||
public R<Boolean> save(@Valid @RequestBody SysLog sysLog) {
|
||||
return new R<>(sysLogService.insert(sysLog));
|
||||
}
|
||||
|
||||
|
||||
+3
-2
@@ -33,6 +33,7 @@ import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.security.access.prepost.PreAuthorize;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import javax.validation.Valid;
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
@@ -123,7 +124,7 @@ public class MenuController {
|
||||
*/
|
||||
@PostMapping
|
||||
@PreAuthorize("@pms.hasPermission('sys_menu_add')")
|
||||
public R<Boolean> menu(@RequestBody SysMenu sysMenu) {
|
||||
public R<Boolean> menu(@Valid @RequestBody SysMenu sysMenu) {
|
||||
return new R<>(sysMenuService.insert(sysMenu));
|
||||
}
|
||||
|
||||
@@ -142,7 +143,7 @@ public class MenuController {
|
||||
|
||||
@PutMapping
|
||||
@PreAuthorize("@pms.hasPermission('sys_menu_edit')")
|
||||
public R<Boolean> menuUpdate(@RequestBody SysMenu sysMenu) {
|
||||
public R<Boolean> menuUpdate(@Valid @RequestBody SysMenu sysMenu) {
|
||||
return new R<>(sysMenuService.updateMenuById(sysMenu));
|
||||
}
|
||||
|
||||
|
||||
+3
-2
@@ -29,6 +29,7 @@ import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.security.access.prepost.PreAuthorize;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import javax.validation.Valid;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
@@ -76,7 +77,7 @@ public class OauthClientDetailsController {
|
||||
*/
|
||||
@PostMapping
|
||||
@PreAuthorize("@pms.hasPermission('sys_client_add')")
|
||||
public R<Boolean> add(@RequestBody SysOauthClientDetails sysOauthClientDetails) {
|
||||
public R<Boolean> add(@Valid @RequestBody SysOauthClientDetails sysOauthClientDetails) {
|
||||
return new R<>(sysOauthClientDetailsService.insert(sysOauthClientDetails));
|
||||
}
|
||||
|
||||
@@ -102,7 +103,7 @@ public class OauthClientDetailsController {
|
||||
*/
|
||||
@PutMapping
|
||||
@PreAuthorize("@pms.hasPermission('sys_client_edit')")
|
||||
public R<Boolean> edit(@RequestBody SysOauthClientDetails sysOauthClientDetails) {
|
||||
public R<Boolean> edit(@Valid @RequestBody SysOauthClientDetails sysOauthClientDetails) {
|
||||
return new R<>(sysOauthClientDetailsService.updateById(sysOauthClientDetails));
|
||||
}
|
||||
}
|
||||
+5
-5
@@ -28,7 +28,7 @@ import com.pig4cloud.pigx.common.core.util.R;
|
||||
import lombok.AllArgsConstructor;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.util.Arrays;
|
||||
import javax.validation.Valid;
|
||||
import java.util.Map;
|
||||
|
||||
|
||||
@@ -77,7 +77,7 @@ public class SysSocialDetailsController {
|
||||
* @return R
|
||||
*/
|
||||
@PostMapping
|
||||
public R save(@RequestBody SysSocialDetails sysSocialDetails) {
|
||||
public R save(@Valid @RequestBody SysSocialDetails sysSocialDetails) {
|
||||
sysSocialDetailsService.insert(sysSocialDetails);
|
||||
return new R<>(Boolean.TRUE);
|
||||
}
|
||||
@@ -89,7 +89,7 @@ public class SysSocialDetailsController {
|
||||
* @return R
|
||||
*/
|
||||
@PutMapping
|
||||
public R update(@RequestBody SysSocialDetails sysSocialDetails) {
|
||||
public R update(@Valid @RequestBody SysSocialDetails sysSocialDetails) {
|
||||
sysSocialDetailsService.updateById(sysSocialDetails);
|
||||
return new R<>(Boolean.TRUE);
|
||||
}
|
||||
@@ -101,7 +101,7 @@ public class SysSocialDetailsController {
|
||||
* @return R
|
||||
*/
|
||||
@DeleteMapping("/{id}")
|
||||
public R delete(@PathVariable Integer id ) {
|
||||
public R delete(@PathVariable Integer id) {
|
||||
return new R<>(sysSocialDetailsService.deleteById(id));
|
||||
}
|
||||
|
||||
@@ -113,7 +113,7 @@ public class SysSocialDetailsController {
|
||||
*/
|
||||
@GetMapping("/info/{inStr}")
|
||||
public R<UserInfo> social(@PathVariable String inStr) {
|
||||
Map<String,String> result = sysSocialDetailsService.findOpenId(inStr);
|
||||
Map<String, String> result = sysSocialDetailsService.findOpenId(inStr);
|
||||
return new R<>(sysUserService.findUserInfo(result.get("type"), result.get("openId")));
|
||||
}
|
||||
|
||||
|
||||
+5
-4
@@ -43,6 +43,7 @@ import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
|
||||
import org.springframework.security.crypto.password.PasswordEncoder;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import javax.validation.Valid;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
@@ -117,8 +118,8 @@ public class UserController {
|
||||
@PreAuthorize("@pms.hasPermission('sys_user_add')")
|
||||
public R<Boolean> user(@RequestBody UserDTO userDto) {
|
||||
SysUser deletedUser = userService.selectDeletedUserByUsername(userDto.getUsername());
|
||||
if ( deletedUser!= null) {
|
||||
userService.deleteSysUserByUsernameAndUserId(userDto.getUsername(),deletedUser.getUserId());
|
||||
if (deletedUser != null) {
|
||||
userService.deleteSysUserByUsernameAndUserId(userDto.getUsername(), deletedUser.getUserId());
|
||||
}
|
||||
SysUser sysUser = new SysUser();
|
||||
BeanUtils.copyProperties(userDto, sysUser);
|
||||
@@ -142,7 +143,7 @@ public class UserController {
|
||||
*/
|
||||
@PutMapping
|
||||
@PreAuthorize("@pms.hasPermission('sys_user_edit')")
|
||||
public R<Boolean> userUpdate(@RequestBody UserDTO userDto) {
|
||||
public R<Boolean> userUpdate(@Valid @RequestBody UserDTO userDto) {
|
||||
SysUser user = userService.selectById(userDto.getUserId());
|
||||
return new R<>(userService.updateUser(userDto, user.getUsername()));
|
||||
}
|
||||
@@ -165,7 +166,7 @@ public class UserController {
|
||||
* @return success/false
|
||||
*/
|
||||
@PutMapping("/editInfo")
|
||||
public R<Boolean> editInfo(@RequestBody UserDTO userDto) {
|
||||
public R<Boolean> editInfo(@Valid @RequestBody UserDTO userDto) {
|
||||
return userService.updateUserInfo(userDto, SecurityUtils.getUser().getUsername());
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user