| | |
| | | */ |
| | | public class UnsignedMathGenerator implements CodeGenerator { |
| | | |
| | | private static final long serialVersionUID = -5514819971774091076L; |
| | | private static final long serialVersionUID = -5514819971774091076L; |
| | | |
| | | private static final String operators = "+-*"; |
| | | private static final String operators = "+-*"; |
| | | |
| | | /** |
| | | * 参与计算数字最大长度 |
| | | */ |
| | | private final int numberLength; |
| | | /** |
| | | * 参与计算数字最大长度 |
| | | */ |
| | | private final int numberLength; |
| | | |
| | | /** |
| | | * 构造 |
| | | */ |
| | | public UnsignedMathGenerator() { |
| | | this(2); |
| | | } |
| | | /** |
| | | * 构造 |
| | | */ |
| | | public UnsignedMathGenerator() { |
| | | this(2); |
| | | } |
| | | |
| | | /** |
| | | * 构造 |
| | | * |
| | | * @param numberLength 参与计算最大数字位数 |
| | | */ |
| | | public UnsignedMathGenerator(int numberLength) { |
| | | this.numberLength = numberLength; |
| | | } |
| | | /** |
| | | * 构造 |
| | | * |
| | | * @param numberLength 参与计算最大数字位数 |
| | | */ |
| | | public UnsignedMathGenerator(int numberLength) { |
| | | this.numberLength = numberLength; |
| | | } |
| | | |
| | | @Override |
| | | public String generate() { |
| | | final int limit = getLimit(); |
| | | int min = RandomUtil.randomInt(limit); |
| | | int max = RandomUtil.randomInt(min, limit); |
| | | String number1 = Integer.toString(max); |
| | | String number2 = Integer.toString(min); |
| | | number1 = StringUtils.rightPad(number1, this.numberLength, CharUtil.SPACE); |
| | | number2 = StringUtils.rightPad(number2, this.numberLength, CharUtil.SPACE); |
| | | @Override |
| | | public String generate() { |
| | | final int limit = getLimit(); |
| | | int min = RandomUtil.randomInt(limit); |
| | | int max = RandomUtil.randomInt(min, limit); |
| | | String number1 = Integer.toString(max); |
| | | String number2 = Integer.toString(min); |
| | | number1 = StringUtils.rightPad(number1, this.numberLength, CharUtil.SPACE); |
| | | number2 = StringUtils.rightPad(number2, this.numberLength, CharUtil.SPACE); |
| | | |
| | | return number1 + RandomUtil.randomChar(operators) + number2 + '='; |
| | | } |
| | | return number1 + RandomUtil.randomChar(operators) + number2 + '='; |
| | | } |
| | | |
| | | @Override |
| | | public boolean verify(String code, String userInputCode) { |
| | | int result; |
| | | try { |
| | | result = Integer.parseInt(userInputCode); |
| | | } catch (NumberFormatException e) { |
| | | // 用户输入非数字 |
| | | return false; |
| | | } |
| | | @Override |
| | | public boolean verify(String code, String userInputCode) { |
| | | int result; |
| | | try { |
| | | result = Integer.parseInt(userInputCode); |
| | | } catch (NumberFormatException e) { |
| | | // 用户输入非数字 |
| | | return false; |
| | | } |
| | | |
| | | final int calculateResult = (int) Calculator.conversion(code); |
| | | return result == calculateResult; |
| | | } |
| | | final int calculateResult = (int) Calculator.conversion(code); |
| | | return result == calculateResult; |
| | | } |
| | | |
| | | /** |
| | | * 获取验证码长度 |
| | | * |
| | | * @return 验证码长度 |
| | | */ |
| | | public int getLength() { |
| | | return this.numberLength * 2 + 2; |
| | | } |
| | | /** |
| | | * 获取验证码长度 |
| | | * |
| | | * @return 验证码长度 |
| | | */ |
| | | public int getLength() { |
| | | return this.numberLength * 2 + 2; |
| | | } |
| | | |
| | | /** |
| | | * 根据长度获取参与计算数字最大值 |
| | | * |
| | | * @return 最大值 |
| | | */ |
| | | private int getLimit() { |
| | | return Integer.parseInt("1" + StringUtils.repeat('0', this.numberLength)); |
| | | } |
| | | /** |
| | | * 根据长度获取参与计算数字最大值 |
| | | * |
| | | * @return 最大值 |
| | | */ |
| | | private int getLimit() { |
| | | return Integer.parseInt("1" + StringUtils.repeat('0', this.numberLength)); |
| | | } |
| | | } |
| | |
| | | @Slf4j |
| | | public class ExcelBigNumberConvert implements Converter<Long> { |
| | | |
| | | @Override |
| | | public Class<Long> supportJavaTypeKey() { |
| | | return Long.class; |
| | | } |
| | | @Override |
| | | public Class<Long> supportJavaTypeKey() { |
| | | return Long.class; |
| | | } |
| | | |
| | | @Override |
| | | public CellDataTypeEnum supportExcelTypeKey() { |
| | | return CellDataTypeEnum.STRING; |
| | | } |
| | | @Override |
| | | public CellDataTypeEnum supportExcelTypeKey() { |
| | | return CellDataTypeEnum.STRING; |
| | | } |
| | | |
| | | @Override |
| | | public Long convertToJavaData(CellData cellData, ExcelContentProperty contentProperty, GlobalConfiguration globalConfiguration) { |
| | | return Convert.toLong(cellData.getData()); |
| | | } |
| | | @Override |
| | | public Long convertToJavaData(CellData cellData, ExcelContentProperty contentProperty, GlobalConfiguration globalConfiguration) { |
| | | return Convert.toLong(cellData.getData()); |
| | | } |
| | | |
| | | @Override |
| | | public CellData<Object> convertToExcelData(Long object, ExcelContentProperty contentProperty, GlobalConfiguration globalConfiguration) { |
| | | if (ObjectUtil.isNotNull(object)) { |
| | | String str = Convert.toStr(object); |
| | | if (str.length() > 15) { |
| | | return new CellData<>(str); |
| | | } |
| | | } |
| | | CellData<Object> cellData = new CellData<>(new BigDecimal(object)); |
| | | cellData.setType(CellDataTypeEnum.NUMBER); |
| | | return cellData; |
| | | } |
| | | @Override |
| | | public CellData<Object> convertToExcelData(Long object, ExcelContentProperty contentProperty, GlobalConfiguration globalConfiguration) { |
| | | if (ObjectUtil.isNotNull(object)) { |
| | | String str = Convert.toStr(object); |
| | | if (str.length() > 15) { |
| | | return new CellData<>(str); |
| | | } |
| | | } |
| | | CellData<Object> cellData = new CellData<>(new BigDecimal(object)); |
| | | cellData.setType(CellDataTypeEnum.NUMBER); |
| | | return cellData; |
| | | } |
| | | |
| | | } |
| | |
| | | @Slf4j |
| | | public class ExcelDictConvert implements Converter<Object> { |
| | | |
| | | @Override |
| | | public Class<Object> supportJavaTypeKey() { |
| | | return Object.class; |
| | | } |
| | | @Override |
| | | public Class<Object> supportJavaTypeKey() { |
| | | return Object.class; |
| | | } |
| | | |
| | | @Override |
| | | public CellDataTypeEnum supportExcelTypeKey() { |
| | | return null; |
| | | } |
| | | @Override |
| | | public CellDataTypeEnum supportExcelTypeKey() { |
| | | return null; |
| | | } |
| | | |
| | | @Override |
| | | public Object convertToJavaData(CellData cellData, ExcelContentProperty contentProperty, GlobalConfiguration globalConfiguration) { |
| | | ExcelDictFormat anno = getAnnotation(contentProperty.getField()); |
| | | String type = anno.dictType(); |
| | | String label = cellData.getStringValue(); |
| | | String value; |
| | | if (StringUtils.isBlank(type)) { |
| | | value = ExcelUtil.reverseByExp(label, anno.readConverterExp(), anno.separator()); |
| | | } else { |
| | | value = SpringUtils.getBean(DictService.class).getDictValue(type, label, anno.separator()); |
| | | } |
| | | return Convert.convert(contentProperty.getField().getType(), value); |
| | | } |
| | | @Override |
| | | public Object convertToJavaData(CellData cellData, ExcelContentProperty contentProperty, GlobalConfiguration globalConfiguration) { |
| | | ExcelDictFormat anno = getAnnotation(contentProperty.getField()); |
| | | String type = anno.dictType(); |
| | | String label = cellData.getStringValue(); |
| | | String value; |
| | | if (StringUtils.isBlank(type)) { |
| | | value = ExcelUtil.reverseByExp(label, anno.readConverterExp(), anno.separator()); |
| | | } else { |
| | | value = SpringUtils.getBean(DictService.class).getDictValue(type, label, anno.separator()); |
| | | } |
| | | return Convert.convert(contentProperty.getField().getType(), value); |
| | | } |
| | | |
| | | @Override |
| | | public CellData<String> convertToExcelData(Object object, ExcelContentProperty contentProperty, GlobalConfiguration globalConfiguration) { |
| | | if (StringUtils.isNull(object)) { |
| | | return new CellData<>(""); |
| | | } |
| | | ExcelDictFormat anno = getAnnotation(contentProperty.getField()); |
| | | String type = anno.dictType(); |
| | | String value = Convert.toStr(object); |
| | | String label; |
| | | if (StringUtils.isBlank(type)) { |
| | | label = ExcelUtil.convertByExp(value, anno.readConverterExp(), anno.separator()); |
| | | } else { |
| | | label = SpringUtils.getBean(DictService.class).getDictLabel(type, value, anno.separator()); |
| | | } |
| | | return new CellData<>(label); |
| | | } |
| | | @Override |
| | | public CellData<String> convertToExcelData(Object object, ExcelContentProperty contentProperty, GlobalConfiguration globalConfiguration) { |
| | | if (StringUtils.isNull(object)) { |
| | | return new CellData<>(""); |
| | | } |
| | | ExcelDictFormat anno = getAnnotation(contentProperty.getField()); |
| | | String type = anno.dictType(); |
| | | String value = Convert.toStr(object); |
| | | String label; |
| | | if (StringUtils.isBlank(type)) { |
| | | label = ExcelUtil.convertByExp(value, anno.readConverterExp(), anno.separator()); |
| | | } else { |
| | | label = SpringUtils.getBean(DictService.class).getDictLabel(type, value, anno.separator()); |
| | | } |
| | | return new CellData<>(label); |
| | | } |
| | | |
| | | private ExcelDictFormat getAnnotation(Field field) { |
| | | return AnnotationUtil.getAnnotation(field, ExcelDictFormat.class); |
| | | } |
| | | private ExcelDictFormat getAnnotation(Field field) { |
| | | return AnnotationUtil.getAnnotation(field, ExcelDictFormat.class); |
| | | } |
| | | } |
| | |
| | | @ApiModel("请求响应对象") |
| | | public class AjaxResult<T> { |
| | | |
| | | private static final long serialVersionUID = 1L; |
| | | private static final long serialVersionUID = 1L; |
| | | |
| | | /** |
| | | * 状态码 |
| | | */ |
| | | @ApiModelProperty("消息状态码") |
| | | private int code; |
| | | /** |
| | | * 状态码 |
| | | */ |
| | | @ApiModelProperty("消息状态码") |
| | | private int code; |
| | | |
| | | /** |
| | | * 返回内容 |
| | | */ |
| | | @ApiModelProperty("消息内容") |
| | | private String msg; |
| | | /** |
| | | * 返回内容 |
| | | */ |
| | | @ApiModelProperty("消息内容") |
| | | private String msg; |
| | | |
| | | /** |
| | | * 数据对象 |
| | | */ |
| | | @ApiModelProperty("数据对象") |
| | | private T data; |
| | | /** |
| | | * 数据对象 |
| | | */ |
| | | @ApiModelProperty("数据对象") |
| | | private T data; |
| | | |
| | | /** |
| | | * 初始化一个新创建的 AjaxResult 对象 |
| | | * |
| | | * @param code 状态码 |
| | | * @param msg 返回内容 |
| | | */ |
| | | public AjaxResult(int code, String msg) { |
| | | this.code = code; |
| | | this.msg = msg; |
| | | } |
| | | /** |
| | | * 初始化一个新创建的 AjaxResult 对象 |
| | | * |
| | | * @param code 状态码 |
| | | * @param msg 返回内容 |
| | | */ |
| | | public AjaxResult(int code, String msg) { |
| | | this.code = code; |
| | | this.msg = msg; |
| | | } |
| | | |
| | | /** |
| | | * 返回成功消息 |
| | | * |
| | | * @return 成功消息 |
| | | */ |
| | | public static AjaxResult<Void> success() { |
| | | return AjaxResult.success("操作成功"); |
| | | } |
| | | /** |
| | | * 返回成功消息 |
| | | * |
| | | * @return 成功消息 |
| | | */ |
| | | public static AjaxResult<Void> success() { |
| | | return AjaxResult.success("操作成功"); |
| | | } |
| | | |
| | | /** |
| | | * 返回成功数据 |
| | | * |
| | | * @return 成功消息 |
| | | */ |
| | | public static <T> AjaxResult<T> success(T data) { |
| | | return AjaxResult.success("操作成功", data); |
| | | } |
| | | /** |
| | | * 返回成功数据 |
| | | * |
| | | * @return 成功消息 |
| | | */ |
| | | public static <T> AjaxResult<T> success(T data) { |
| | | return AjaxResult.success("操作成功", data); |
| | | } |
| | | |
| | | /** |
| | | * 返回成功消息 |
| | | * |
| | | * @param msg 返回内容 |
| | | * @return 成功消息 |
| | | */ |
| | | public static AjaxResult<Void> success(String msg) { |
| | | return AjaxResult.success(msg, null); |
| | | } |
| | | /** |
| | | * 返回成功消息 |
| | | * |
| | | * @param msg 返回内容 |
| | | * @return 成功消息 |
| | | */ |
| | | public static AjaxResult<Void> success(String msg) { |
| | | return AjaxResult.success(msg, null); |
| | | } |
| | | |
| | | /** |
| | | * 返回成功消息 |
| | | * |
| | | * @param msg 返回内容 |
| | | * @param data 数据对象 |
| | | * @return 成功消息 |
| | | */ |
| | | public static <T> AjaxResult<T> success(String msg, T data) { |
| | | return new AjaxResult<>(HttpStatus.HTTP_OK, msg, data); |
| | | } |
| | | /** |
| | | * 返回成功消息 |
| | | * |
| | | * @param msg 返回内容 |
| | | * @param data 数据对象 |
| | | * @return 成功消息 |
| | | */ |
| | | public static <T> AjaxResult<T> success(String msg, T data) { |
| | | return new AjaxResult<>(HttpStatus.HTTP_OK, msg, data); |
| | | } |
| | | |
| | | /** |
| | | * 返回错误消息 |
| | | * |
| | | * @return |
| | | */ |
| | | public static AjaxResult<Void> error() { |
| | | return AjaxResult.error("操作失败"); |
| | | } |
| | | /** |
| | | * 返回错误消息 |
| | | * |
| | | * @return |
| | | */ |
| | | public static AjaxResult<Void> error() { |
| | | return AjaxResult.error("操作失败"); |
| | | } |
| | | |
| | | /** |
| | | * 返回错误消息 |
| | | * |
| | | * @param msg 返回内容 |
| | | * @return 警告消息 |
| | | */ |
| | | public static AjaxResult<Void> error(String msg) { |
| | | return AjaxResult.error(msg, null); |
| | | } |
| | | /** |
| | | * 返回错误消息 |
| | | * |
| | | * @param msg 返回内容 |
| | | * @return 警告消息 |
| | | */ |
| | | public static AjaxResult<Void> error(String msg) { |
| | | return AjaxResult.error(msg, null); |
| | | } |
| | | |
| | | /** |
| | | * 返回错误消息 |
| | | * |
| | | * @param msg 返回内容 |
| | | * @param data 数据对象 |
| | | * @return 警告消息 |
| | | */ |
| | | public static <T> AjaxResult<T> error(String msg, T data) { |
| | | return new AjaxResult<>(HttpStatus.HTTP_INTERNAL_ERROR, msg, data); |
| | | } |
| | | /** |
| | | * 返回错误消息 |
| | | * |
| | | * @param msg 返回内容 |
| | | * @param data 数据对象 |
| | | * @return 警告消息 |
| | | */ |
| | | public static <T> AjaxResult<T> error(String msg, T data) { |
| | | return new AjaxResult<>(HttpStatus.HTTP_INTERNAL_ERROR, msg, data); |
| | | } |
| | | |
| | | /** |
| | | * 返回错误消息 |
| | | * |
| | | * @param code 状态码 |
| | | * @param msg 返回内容 |
| | | * @return 警告消息 |
| | | */ |
| | | public static AjaxResult<Void> error(int code, String msg) { |
| | | return new AjaxResult<>(code, msg, null); |
| | | } |
| | | /** |
| | | * 返回错误消息 |
| | | * |
| | | * @param code 状态码 |
| | | * @param msg 返回内容 |
| | | * @return 警告消息 |
| | | */ |
| | | public static AjaxResult<Void> error(int code, String msg) { |
| | | return new AjaxResult<>(code, msg, null); |
| | | } |
| | | |
| | | } |
| | |
| | | @Accessors(chain = true) |
| | | public class BaseEntity implements Serializable { |
| | | |
| | | private static final long serialVersionUID = 1L; |
| | | private static final long serialVersionUID = 1L; |
| | | |
| | | /** |
| | | * 搜索值 |
| | | */ |
| | | @ApiModelProperty(value = "搜索值") |
| | | @TableField(exist = false) |
| | | private String searchValue; |
| | | /** |
| | | * 搜索值 |
| | | */ |
| | | @ApiModelProperty(value = "搜索值") |
| | | @TableField(exist = false) |
| | | private String searchValue; |
| | | |
| | | /** |
| | | * 创建者 |
| | | */ |
| | | @ApiModelProperty(value = "创建者") |
| | | @TableField(fill = FieldFill.INSERT) |
| | | private String createBy; |
| | | /** |
| | | * 创建者 |
| | | */ |
| | | @ApiModelProperty(value = "创建者") |
| | | @TableField(fill = FieldFill.INSERT) |
| | | private String createBy; |
| | | |
| | | /** |
| | | * 创建时间 |
| | | */ |
| | | @ApiModelProperty(value = "创建时间") |
| | | @TableField(fill = FieldFill.INSERT) |
| | | private Date createTime; |
| | | /** |
| | | * 创建时间 |
| | | */ |
| | | @ApiModelProperty(value = "创建时间") |
| | | @TableField(fill = FieldFill.INSERT) |
| | | private Date createTime; |
| | | |
| | | /** |
| | | * 更新者 |
| | | */ |
| | | @ApiModelProperty(value = "更新者") |
| | | @TableField(fill = FieldFill.INSERT_UPDATE) |
| | | private String updateBy; |
| | | /** |
| | | * 更新者 |
| | | */ |
| | | @ApiModelProperty(value = "更新者") |
| | | @TableField(fill = FieldFill.INSERT_UPDATE) |
| | | private String updateBy; |
| | | |
| | | /** |
| | | * 更新时间 |
| | | */ |
| | | @ApiModelProperty(value = "更新时间") |
| | | @TableField(fill = FieldFill.INSERT_UPDATE) |
| | | private Date updateTime; |
| | | /** |
| | | * 更新时间 |
| | | */ |
| | | @ApiModelProperty(value = "更新时间") |
| | | @TableField(fill = FieldFill.INSERT_UPDATE) |
| | | private Date updateTime; |
| | | |
| | | /** |
| | | * 请求参数 |
| | | */ |
| | | @ApiModelProperty(value = "请求参数") |
| | | @TableField(exist = false) |
| | | private Map<String, Object> params = new HashMap<>(); |
| | | /** |
| | | * 请求参数 |
| | | */ |
| | | @ApiModelProperty(value = "请求参数") |
| | | @TableField(exist = false) |
| | | private Map<String, Object> params = new HashMap<>(); |
| | | |
| | | } |
| | |
| | | @Accessors(chain = true) |
| | | public class PageQuery implements Serializable { |
| | | |
| | | private static final long serialVersionUID = 1L; |
| | | private static final long serialVersionUID = 1L; |
| | | |
| | | /** |
| | | * 分页大小 |
| | |
| | | @Accessors(chain = true) |
| | | public class TreeEntity extends BaseEntity { |
| | | |
| | | private static final long serialVersionUID = 1L; |
| | | private static final long serialVersionUID = 1L; |
| | | |
| | | /** |
| | | * 父菜单名称 |
| | | */ |
| | | @TableField(exist = false) |
| | | @ApiModelProperty(value = "父菜单名称") |
| | | private String parentName; |
| | | /** |
| | | * 父菜单名称 |
| | | */ |
| | | @TableField(exist = false) |
| | | @ApiModelProperty(value = "父菜单名称") |
| | | private String parentName; |
| | | |
| | | /** |
| | | * 父菜单ID |
| | | */ |
| | | @ApiModelProperty(value = "父菜单ID") |
| | | private Long parentId; |
| | | /** |
| | | * 父菜单ID |
| | | */ |
| | | @ApiModelProperty(value = "父菜单ID") |
| | | private Long parentId; |
| | | |
| | | /** |
| | | * 子部门 |
| | | */ |
| | | @TableField(exist = false) |
| | | @ApiModelProperty(value = "子部门") |
| | | private List<?> children = new ArrayList<>(); |
| | | /** |
| | | * 子部门 |
| | | */ |
| | | @TableField(exist = false) |
| | | @ApiModelProperty(value = "子部门") |
| | | private List<?> children = new ArrayList<>(); |
| | | |
| | | } |
| | |
| | | @TableName("sys_dept") |
| | | @ApiModel("部门业务对象") |
| | | public class SysDept extends TreeEntity { |
| | | private static final long serialVersionUID = 1L; |
| | | private static final long serialVersionUID = 1L; |
| | | |
| | | /** |
| | | * 部门ID |
| | | */ |
| | | @ApiModelProperty(value = "部门id") |
| | | @TableId(value = "dept_id") |
| | | private Long deptId; |
| | | /** |
| | | * 部门ID |
| | | */ |
| | | @ApiModelProperty(value = "部门id") |
| | | @TableId(value = "dept_id") |
| | | private Long deptId; |
| | | |
| | | /** |
| | | * 部门名称 |
| | | */ |
| | | @ApiModelProperty(value = "部门名称") |
| | | @NotBlank(message = "部门名称不能为空") |
| | | @Size(min = 0, max = 30, message = "部门名称长度不能超过30个字符") |
| | | private String deptName; |
| | | /** |
| | | * 部门名称 |
| | | */ |
| | | @ApiModelProperty(value = "部门名称") |
| | | @NotBlank(message = "部门名称不能为空") |
| | | @Size(min = 0, max = 30, message = "部门名称长度不能超过30个字符") |
| | | private String deptName; |
| | | |
| | | /** |
| | | * 显示顺序 |
| | | */ |
| | | @ApiModelProperty(value = "显示顺序") |
| | | @NotBlank(message = "显示顺序不能为空") |
| | | private String orderNum; |
| | | /** |
| | | * 显示顺序 |
| | | */ |
| | | @ApiModelProperty(value = "显示顺序") |
| | | @NotBlank(message = "显示顺序不能为空") |
| | | private String orderNum; |
| | | |
| | | /** |
| | | * 负责人 |
| | | */ |
| | | @ApiModelProperty(value = "负责人") |
| | | private String leader; |
| | | /** |
| | | * 负责人 |
| | | */ |
| | | @ApiModelProperty(value = "负责人") |
| | | private String leader; |
| | | |
| | | /** |
| | | * 联系电话 |
| | | */ |
| | | @ApiModelProperty(value = "联系电话") |
| | | @Size(min = 0, max = 11, message = "联系电话长度不能超过11个字符") |
| | | private String phone; |
| | | /** |
| | | * 联系电话 |
| | | */ |
| | | @ApiModelProperty(value = "联系电话") |
| | | @Size(min = 0, max = 11, message = "联系电话长度不能超过11个字符") |
| | | private String phone; |
| | | |
| | | /** |
| | | * 邮箱 |
| | | */ |
| | | @ApiModelProperty(value = "邮箱") |
| | | @Email(message = "邮箱格式不正确") |
| | | @Size(min = 0, max = 50, message = "邮箱长度不能超过50个字符") |
| | | private String email; |
| | | /** |
| | | * 邮箱 |
| | | */ |
| | | @ApiModelProperty(value = "邮箱") |
| | | @Email(message = "邮箱格式不正确") |
| | | @Size(min = 0, max = 50, message = "邮箱长度不能超过50个字符") |
| | | private String email; |
| | | |
| | | /** |
| | | * 部门状态:0正常,1停用 |
| | | */ |
| | | @ApiModelProperty(value = "部门状态:0正常,1停用") |
| | | private String status; |
| | | /** |
| | | * 部门状态:0正常,1停用 |
| | | */ |
| | | @ApiModelProperty(value = "部门状态:0正常,1停用") |
| | | private String status; |
| | | |
| | | /** |
| | | * 删除标志(0代表存在 2代表删除) |
| | | */ |
| | | @ApiModelProperty(value = "删除标志(0代表存在 2代表删除)") |
| | | @TableLogic |
| | | private String delFlag; |
| | | /** |
| | | * 删除标志(0代表存在 2代表删除) |
| | | */ |
| | | @ApiModelProperty(value = "删除标志(0代表存在 2代表删除)") |
| | | @TableLogic |
| | | private String delFlag; |
| | | |
| | | /** |
| | | * 祖级列表 |
| | | */ |
| | | @ApiModelProperty(value = "祖级列表") |
| | | private String ancestors; |
| | | /** |
| | | * 祖级列表 |
| | | */ |
| | | @ApiModelProperty(value = "祖级列表") |
| | | private String ancestors; |
| | | |
| | | } |
| | |
| | | @ApiModel("字典数据业务对象") |
| | | public class SysDictData extends BaseEntity { |
| | | |
| | | /** |
| | | * 字典编码 |
| | | */ |
| | | @ApiModelProperty(value = "字典编码") |
| | | @ExcelProperty(value = "字典编码") |
| | | @TableId(value = "dict_code") |
| | | private Long dictCode; |
| | | /** |
| | | * 字典编码 |
| | | */ |
| | | @ApiModelProperty(value = "字典编码") |
| | | @ExcelProperty(value = "字典编码") |
| | | @TableId(value = "dict_code") |
| | | private Long dictCode; |
| | | |
| | | /** |
| | | * 字典排序 |
| | | */ |
| | | @ApiModelProperty(value = "字典排序") |
| | | @ExcelProperty(value = "字典排序") |
| | | private Long dictSort; |
| | | /** |
| | | * 字典排序 |
| | | */ |
| | | @ApiModelProperty(value = "字典排序") |
| | | @ExcelProperty(value = "字典排序") |
| | | private Long dictSort; |
| | | |
| | | /** |
| | | * 字典标签 |
| | | */ |
| | | @ApiModelProperty(value = "字典标签") |
| | | @ExcelProperty(value = "字典标签") |
| | | @NotBlank(message = "字典标签不能为空") |
| | | @Size(min = 0, max = 100, message = "字典标签长度不能超过100个字符") |
| | | private String dictLabel; |
| | | /** |
| | | * 字典标签 |
| | | */ |
| | | @ApiModelProperty(value = "字典标签") |
| | | @ExcelProperty(value = "字典标签") |
| | | @NotBlank(message = "字典标签不能为空") |
| | | @Size(min = 0, max = 100, message = "字典标签长度不能超过100个字符") |
| | | private String dictLabel; |
| | | |
| | | /** |
| | | * 字典键值 |
| | | */ |
| | | @ApiModelProperty(value = "字典键值") |
| | | @ExcelProperty(value = "字典键值") |
| | | @NotBlank(message = "字典键值不能为空") |
| | | @Size(min = 0, max = 100, message = "字典键值长度不能超过100个字符") |
| | | private String dictValue; |
| | | /** |
| | | * 字典键值 |
| | | */ |
| | | @ApiModelProperty(value = "字典键值") |
| | | @ExcelProperty(value = "字典键值") |
| | | @NotBlank(message = "字典键值不能为空") |
| | | @Size(min = 0, max = 100, message = "字典键值长度不能超过100个字符") |
| | | private String dictValue; |
| | | |
| | | /** |
| | | * 字典类型 |
| | | */ |
| | | @ApiModelProperty(value = "字典类型") |
| | | @ExcelProperty(value = "字典类型") |
| | | @NotBlank(message = "字典类型不能为空") |
| | | @Size(min = 0, max = 100, message = "字典类型长度不能超过100个字符") |
| | | private String dictType; |
| | | /** |
| | | * 字典类型 |
| | | */ |
| | | @ApiModelProperty(value = "字典类型") |
| | | @ExcelProperty(value = "字典类型") |
| | | @NotBlank(message = "字典类型不能为空") |
| | | @Size(min = 0, max = 100, message = "字典类型长度不能超过100个字符") |
| | | private String dictType; |
| | | |
| | | /** |
| | | * 样式属性(其他样式扩展) |
| | | */ |
| | | @ApiModelProperty(value = "样式属性(其他样式扩展)") |
| | | @Size(min = 0, max = 100, message = "样式属性长度不能超过100个字符") |
| | | private String cssClass; |
| | | /** |
| | | * 样式属性(其他样式扩展) |
| | | */ |
| | | @ApiModelProperty(value = "样式属性(其他样式扩展)") |
| | | @Size(min = 0, max = 100, message = "样式属性长度不能超过100个字符") |
| | | private String cssClass; |
| | | |
| | | /** |
| | | * 表格字典样式 |
| | | */ |
| | | @ApiModelProperty(value = "表格字典样式") |
| | | private String listClass; |
| | | /** |
| | | * 表格字典样式 |
| | | */ |
| | | @ApiModelProperty(value = "表格字典样式") |
| | | private String listClass; |
| | | |
| | | /** |
| | | * 是否默认(Y是 N否) |
| | | */ |
| | | @ApiModelProperty(value = "是否默认(Y是 N否)") |
| | | @ExcelProperty(value = "是否默认", converter = ExcelDictConvert.class) |
| | | @ExcelDictFormat(dictType = "sys_yes_no") |
| | | private String isDefault; |
| | | /** |
| | | * 是否默认(Y是 N否) |
| | | */ |
| | | @ApiModelProperty(value = "是否默认(Y是 N否)") |
| | | @ExcelProperty(value = "是否默认", converter = ExcelDictConvert.class) |
| | | @ExcelDictFormat(dictType = "sys_yes_no") |
| | | private String isDefault; |
| | | |
| | | /** |
| | | * 状态(0正常 1停用) |
| | | */ |
| | | @ApiModelProperty(value = "状态(0正常 1停用)") |
| | | @ExcelProperty(value = "状态", converter = ExcelDictConvert.class) |
| | | @ExcelDictFormat(dictType = "sys_normal_disable") |
| | | private String status; |
| | | /** |
| | | * 状态(0正常 1停用) |
| | | */ |
| | | @ApiModelProperty(value = "状态(0正常 1停用)") |
| | | @ExcelProperty(value = "状态", converter = ExcelDictConvert.class) |
| | | @ExcelDictFormat(dictType = "sys_normal_disable") |
| | | private String status; |
| | | |
| | | /** |
| | | * 备注 |
| | | */ |
| | | @ApiModelProperty(value = "备注") |
| | | private String remark; |
| | | /** |
| | | * 备注 |
| | | */ |
| | | @ApiModelProperty(value = "备注") |
| | | private String remark; |
| | | |
| | | public boolean getDefault() { |
| | | return UserConstants.YES.equals(this.isDefault); |
| | | } |
| | | public boolean getDefault() { |
| | | return UserConstants.YES.equals(this.isDefault); |
| | | } |
| | | |
| | | } |
| | |
| | | @ApiModel("字典类型业务对象") |
| | | public class SysDictType extends BaseEntity { |
| | | |
| | | /** |
| | | * 字典主键 |
| | | */ |
| | | @ApiModelProperty(value = "字典主键") |
| | | @ExcelProperty(value = "字典主键") |
| | | @TableId(value = "dict_id") |
| | | private Long dictId; |
| | | /** |
| | | * 字典主键 |
| | | */ |
| | | @ApiModelProperty(value = "字典主键") |
| | | @ExcelProperty(value = "字典主键") |
| | | @TableId(value = "dict_id") |
| | | private Long dictId; |
| | | |
| | | /** |
| | | * 字典名称 |
| | | */ |
| | | @ApiModelProperty(value = "字典名称") |
| | | @ExcelProperty(value = "字典名称") |
| | | @NotBlank(message = "字典名称不能为空") |
| | | @Size(min = 0, max = 100, message = "字典类型名称长度不能超过100个字符") |
| | | private String dictName; |
| | | /** |
| | | * 字典名称 |
| | | */ |
| | | @ApiModelProperty(value = "字典名称") |
| | | @ExcelProperty(value = "字典名称") |
| | | @NotBlank(message = "字典名称不能为空") |
| | | @Size(min = 0, max = 100, message = "字典类型名称长度不能超过100个字符") |
| | | private String dictName; |
| | | |
| | | /** |
| | | * 字典类型 |
| | | */ |
| | | @ApiModelProperty(value = "字典类型") |
| | | @ExcelProperty(value = "字典类型") |
| | | @NotBlank(message = "字典类型不能为空") |
| | | @Size(min = 0, max = 100, message = "字典类型类型长度不能超过100个字符") |
| | | private String dictType; |
| | | /** |
| | | * 字典类型 |
| | | */ |
| | | @ApiModelProperty(value = "字典类型") |
| | | @ExcelProperty(value = "字典类型") |
| | | @NotBlank(message = "字典类型不能为空") |
| | | @Size(min = 0, max = 100, message = "字典类型类型长度不能超过100个字符") |
| | | private String dictType; |
| | | |
| | | /** |
| | | * 状态(0正常 1停用) |
| | | */ |
| | | @ApiModelProperty(value = "状态(0正常 1停用)") |
| | | @ExcelProperty(value = "状态", converter = ExcelDictConvert.class) |
| | | @ExcelDictFormat(dictType = "sys_normal_disable") |
| | | private String status; |
| | | /** |
| | | * 状态(0正常 1停用) |
| | | */ |
| | | @ApiModelProperty(value = "状态(0正常 1停用)") |
| | | @ExcelProperty(value = "状态", converter = ExcelDictConvert.class) |
| | | @ExcelDictFormat(dictType = "sys_normal_disable") |
| | | private String status; |
| | | |
| | | /** |
| | | * 备注 |
| | | */ |
| | | @ApiModelProperty(value = "备注") |
| | | private String remark; |
| | | /** |
| | | * 备注 |
| | | */ |
| | | @ApiModelProperty(value = "备注") |
| | | private String remark; |
| | | |
| | | } |
| | |
| | | @ApiModel("菜单权限业务对象") |
| | | public class SysMenu extends TreeEntity { |
| | | |
| | | /** |
| | | * 菜单ID |
| | | */ |
| | | @ApiModelProperty(value = "菜单ID") |
| | | @TableId(value = "menu_id") |
| | | private Long menuId; |
| | | /** |
| | | * 菜单ID |
| | | */ |
| | | @ApiModelProperty(value = "菜单ID") |
| | | @TableId(value = "menu_id") |
| | | private Long menuId; |
| | | |
| | | /** |
| | | * 菜单名称 |
| | | */ |
| | | @ApiModelProperty(value = "菜单名称") |
| | | @NotBlank(message = "菜单名称不能为空") |
| | | @Size(min = 0, max = 50, message = "菜单名称长度不能超过50个字符") |
| | | private String menuName; |
| | | /** |
| | | * 菜单名称 |
| | | */ |
| | | @ApiModelProperty(value = "菜单名称") |
| | | @NotBlank(message = "菜单名称不能为空") |
| | | @Size(min = 0, max = 50, message = "菜单名称长度不能超过50个字符") |
| | | private String menuName; |
| | | |
| | | /** |
| | | * 显示顺序 |
| | | */ |
| | | @ApiModelProperty(value = "显示顺序") |
| | | @NotBlank(message = "显示顺序不能为空") |
| | | private String orderNum; |
| | | /** |
| | | * 显示顺序 |
| | | */ |
| | | @ApiModelProperty(value = "显示顺序") |
| | | @NotBlank(message = "显示顺序不能为空") |
| | | private String orderNum; |
| | | |
| | | /** |
| | | * 路由地址 |
| | | */ |
| | | @ApiModelProperty(value = "路由地址") |
| | | @Size(min = 0, max = 200, message = "路由地址不能超过200个字符") |
| | | private String path; |
| | | /** |
| | | * 路由地址 |
| | | */ |
| | | @ApiModelProperty(value = "路由地址") |
| | | @Size(min = 0, max = 200, message = "路由地址不能超过200个字符") |
| | | private String path; |
| | | |
| | | /** |
| | | * 组件路径 |
| | | */ |
| | | @ApiModelProperty(value = "组件路径") |
| | | @Size(min = 0, max = 200, message = "组件路径不能超过255个字符") |
| | | private String component; |
| | | /** |
| | | * 组件路径 |
| | | */ |
| | | @ApiModelProperty(value = "组件路径") |
| | | @Size(min = 0, max = 200, message = "组件路径不能超过255个字符") |
| | | private String component; |
| | | |
| | | /** |
| | | * 路由参数 |
| | | */ |
| | | @ApiModelProperty(value = "路由参数") |
| | | @ApiModelProperty(value = "路由参数") |
| | | @TableField("`query`") |
| | | private String query; |
| | | |
| | | /** |
| | | * 是否为外链(0是 1否) |
| | | */ |
| | | @ApiModelProperty(value = "是否为外链(0是 1否)") |
| | | private String isFrame; |
| | | /** |
| | | * 是否为外链(0是 1否) |
| | | */ |
| | | @ApiModelProperty(value = "是否为外链(0是 1否)") |
| | | private String isFrame; |
| | | |
| | | /** |
| | | * 是否缓存(0缓存 1不缓存) |
| | | */ |
| | | @ApiModelProperty(value = "是否缓存(0缓存 1不缓存)") |
| | | private String isCache; |
| | | /** |
| | | * 是否缓存(0缓存 1不缓存) |
| | | */ |
| | | @ApiModelProperty(value = "是否缓存(0缓存 1不缓存)") |
| | | private String isCache; |
| | | |
| | | /** |
| | | * 类型(M目录 C菜单 F按钮) |
| | | */ |
| | | @ApiModelProperty(value = "类型(M目录 C菜单 F按钮)") |
| | | @NotBlank(message = "菜单类型不能为空") |
| | | private String menuType; |
| | | /** |
| | | * 类型(M目录 C菜单 F按钮) |
| | | */ |
| | | @ApiModelProperty(value = "类型(M目录 C菜单 F按钮)") |
| | | @NotBlank(message = "菜单类型不能为空") |
| | | private String menuType; |
| | | |
| | | /** |
| | | * 显示状态(0显示 1隐藏) |
| | | */ |
| | | @ApiModelProperty(value = "显示状态(0显示 1隐藏)") |
| | | private String visible; |
| | | /** |
| | | * 显示状态(0显示 1隐藏) |
| | | */ |
| | | @ApiModelProperty(value = "显示状态(0显示 1隐藏)") |
| | | private String visible; |
| | | |
| | | /** |
| | | * 菜单状态(0显示 1隐藏) |
| | | */ |
| | | @ApiModelProperty(value = "菜单状态(0显示 1隐藏)") |
| | | private String status; |
| | | /** |
| | | * 菜单状态(0显示 1隐藏) |
| | | */ |
| | | @ApiModelProperty(value = "菜单状态(0显示 1隐藏)") |
| | | private String status; |
| | | |
| | | /** |
| | | * 权限字符串 |
| | | */ |
| | | @ApiModelProperty(value = "权限字符串") |
| | | @Size(min = 0, max = 100, message = "权限标识长度不能超过100个字符") |
| | | private String perms; |
| | | /** |
| | | * 权限字符串 |
| | | */ |
| | | @ApiModelProperty(value = "权限字符串") |
| | | @Size(min = 0, max = 100, message = "权限标识长度不能超过100个字符") |
| | | private String perms; |
| | | |
| | | /** |
| | | * 菜单图标 |
| | | */ |
| | | @ApiModelProperty(value = "菜单图标") |
| | | private String icon; |
| | | /** |
| | | * 菜单图标 |
| | | */ |
| | | @ApiModelProperty(value = "菜单图标") |
| | | private String icon; |
| | | |
| | | /** |
| | | * 备注 |
| | | */ |
| | | @ApiModelProperty(value = "备注") |
| | | private String remark; |
| | | /** |
| | | * 备注 |
| | | */ |
| | | @ApiModelProperty(value = "备注") |
| | | private String remark; |
| | | |
| | | } |
| | |
| | | @ExcelIgnoreUnannotated |
| | | public class SysRole extends BaseEntity { |
| | | |
| | | /** |
| | | * 角色ID |
| | | */ |
| | | @ApiModelProperty(value = "角色ID") |
| | | @ExcelProperty(value = "角色序号") |
| | | @TableId(value = "role_id") |
| | | private Long roleId; |
| | | /** |
| | | * 角色ID |
| | | */ |
| | | @ApiModelProperty(value = "角色ID") |
| | | @ExcelProperty(value = "角色序号") |
| | | @TableId(value = "role_id") |
| | | private Long roleId; |
| | | |
| | | /** |
| | | * 角色名称 |
| | | */ |
| | | @ApiModelProperty(value = "角色名称") |
| | | @ExcelProperty(value = "角色名称") |
| | | @NotBlank(message = "角色名称不能为空") |
| | | @Size(min = 0, max = 30, message = "角色名称长度不能超过30个字符") |
| | | private String roleName; |
| | | /** |
| | | * 角色名称 |
| | | */ |
| | | @ApiModelProperty(value = "角色名称") |
| | | @ExcelProperty(value = "角色名称") |
| | | @NotBlank(message = "角色名称不能为空") |
| | | @Size(min = 0, max = 30, message = "角色名称长度不能超过30个字符") |
| | | private String roleName; |
| | | |
| | | /** |
| | | * 角色权限 |
| | | */ |
| | | @ApiModelProperty(value = "角色权限") |
| | | @ExcelProperty(value = "角色权限") |
| | | @NotBlank(message = "权限字符不能为空") |
| | | @Size(min = 0, max = 100, message = "权限字符长度不能超过100个字符") |
| | | private String roleKey; |
| | | /** |
| | | * 角色权限 |
| | | */ |
| | | @ApiModelProperty(value = "角色权限") |
| | | @ExcelProperty(value = "角色权限") |
| | | @NotBlank(message = "权限字符不能为空") |
| | | @Size(min = 0, max = 100, message = "权限字符长度不能超过100个字符") |
| | | private String roleKey; |
| | | |
| | | /** |
| | | * 角色排序 |
| | | */ |
| | | @ApiModelProperty(value = "角色排序") |
| | | @ExcelProperty(value = "角色排序") |
| | | @NotBlank(message = "显示顺序不能为空") |
| | | private String roleSort; |
| | | /** |
| | | * 角色排序 |
| | | */ |
| | | @ApiModelProperty(value = "角色排序") |
| | | @ExcelProperty(value = "角色排序") |
| | | @NotBlank(message = "显示顺序不能为空") |
| | | private String roleSort; |
| | | |
| | | /** |
| | | * 数据范围(1:所有数据权限;2:自定义数据权限;3:本部门数据权限;4:本部门及以下数据权限;5:仅本人数据权限) |
| | | */ |
| | | @ApiModelProperty(value = "数据范围(1:所有数据权限;2:自定义数据权限;3:本部门数据权限;4:本部门及以下数据权限;5:仅本人数据权限)") |
| | | @ExcelProperty(value = "数据范围", converter = ExcelDictConvert.class) |
| | | @ExcelDictFormat(readConverterExp = "1=所有数据权限,2=自定义数据权限,3=本部门数据权限,4=本部门及以下数据权限,5=仅本人数据权限") |
| | | private String dataScope; |
| | | /** |
| | | * 数据范围(1:所有数据权限;2:自定义数据权限;3:本部门数据权限;4:本部门及以下数据权限;5:仅本人数据权限) |
| | | */ |
| | | @ApiModelProperty(value = "数据范围(1:所有数据权限;2:自定义数据权限;3:本部门数据权限;4:本部门及以下数据权限;5:仅本人数据权限)") |
| | | @ExcelProperty(value = "数据范围", converter = ExcelDictConvert.class) |
| | | @ExcelDictFormat(readConverterExp = "1=所有数据权限,2=自定义数据权限,3=本部门数据权限,4=本部门及以下数据权限,5=仅本人数据权限") |
| | | private String dataScope; |
| | | |
| | | /** |
| | | * 菜单树选择项是否关联显示( 0:父子不互相关联显示 1:父子互相关联显示) |
| | | */ |
| | | @ApiModelProperty(value = "菜单树选择项是否关联显示( 0:父子不互相关联显示 1:父子互相关联显示)") |
| | | private boolean menuCheckStrictly; |
| | | /** |
| | | * 菜单树选择项是否关联显示( 0:父子不互相关联显示 1:父子互相关联显示) |
| | | */ |
| | | @ApiModelProperty(value = "菜单树选择项是否关联显示( 0:父子不互相关联显示 1:父子互相关联显示)") |
| | | private boolean menuCheckStrictly; |
| | | |
| | | /** |
| | | * 部门树选择项是否关联显示(0:父子不互相关联显示 1:父子互相关联显示 ) |
| | | */ |
| | | @ApiModelProperty(value = "部门树选择项是否关联显示(0:父子不互相关联显示 1:父子互相关联显示 )") |
| | | private boolean deptCheckStrictly; |
| | | /** |
| | | * 部门树选择项是否关联显示(0:父子不互相关联显示 1:父子互相关联显示 ) |
| | | */ |
| | | @ApiModelProperty(value = "部门树选择项是否关联显示(0:父子不互相关联显示 1:父子互相关联显示 )") |
| | | private boolean deptCheckStrictly; |
| | | |
| | | /** |
| | | * 角色状态(0正常 1停用) |
| | | */ |
| | | @ApiModelProperty(value = "角色状态(0正常 1停用)") |
| | | @ExcelProperty(value = "角色状态", converter = ExcelDictConvert.class) |
| | | @ExcelDictFormat(dictType = "sys_common_status") |
| | | private String status; |
| | | /** |
| | | * 角色状态(0正常 1停用) |
| | | */ |
| | | @ApiModelProperty(value = "角色状态(0正常 1停用)") |
| | | @ExcelProperty(value = "角色状态", converter = ExcelDictConvert.class) |
| | | @ExcelDictFormat(dictType = "sys_common_status") |
| | | private String status; |
| | | |
| | | /** |
| | | * 删除标志(0代表存在 2代表删除) |
| | | */ |
| | | @ApiModelProperty(value = "删除标志(0代表存在 2代表删除)") |
| | | @TableLogic |
| | | private String delFlag; |
| | | /** |
| | | * 删除标志(0代表存在 2代表删除) |
| | | */ |
| | | @ApiModelProperty(value = "删除标志(0代表存在 2代表删除)") |
| | | @TableLogic |
| | | private String delFlag; |
| | | |
| | | /** |
| | | * 备注 |
| | | */ |
| | | @ApiModelProperty(value = "备注") |
| | | private String remark; |
| | | /** |
| | | * 备注 |
| | | */ |
| | | @ApiModelProperty(value = "备注") |
| | | private String remark; |
| | | |
| | | /** |
| | | * 用户是否存在此角色标识 默认不存在 |
| | | */ |
| | | @ApiModelProperty(value = "用户是否存在此角色标识 默认不存在") |
| | | @TableField(exist = false) |
| | | private boolean flag = false; |
| | | /** |
| | | * 用户是否存在此角色标识 默认不存在 |
| | | */ |
| | | @ApiModelProperty(value = "用户是否存在此角色标识 默认不存在") |
| | | @TableField(exist = false) |
| | | private boolean flag = false; |
| | | |
| | | /** |
| | | * 菜单组 |
| | | */ |
| | | @ApiModelProperty(value = "菜单组") |
| | | @TableField(exist = false) |
| | | private Long[] menuIds; |
| | | /** |
| | | * 菜单组 |
| | | */ |
| | | @ApiModelProperty(value = "菜单组") |
| | | @TableField(exist = false) |
| | | private Long[] menuIds; |
| | | |
| | | /** |
| | | * 部门组(数据权限) |
| | | */ |
| | | @ApiModelProperty(value = "部门组(数据权限)") |
| | | @TableField(exist = false) |
| | | private Long[] deptIds; |
| | | /** |
| | | * 部门组(数据权限) |
| | | */ |
| | | @ApiModelProperty(value = "部门组(数据权限)") |
| | | @TableField(exist = false) |
| | | private Long[] deptIds; |
| | | |
| | | public SysRole(Long roleId) { |
| | | this.roleId = roleId; |
| | | } |
| | | public SysRole(Long roleId) { |
| | | this.roleId = roleId; |
| | | } |
| | | |
| | | @ApiModelProperty(value = "是否管理员") |
| | | public boolean isAdmin() { |
| | | return isAdmin(this.roleId); |
| | | } |
| | | @ApiModelProperty(value = "是否管理员") |
| | | public boolean isAdmin() { |
| | | return isAdmin(this.roleId); |
| | | } |
| | | |
| | | public static boolean isAdmin(Long roleId) { |
| | | return roleId != null && 1L == roleId; |
| | | } |
| | | public static boolean isAdmin(Long roleId) { |
| | | return roleId != null && 1L == roleId; |
| | | } |
| | | |
| | | } |
| | |
| | | @ApiModel("用户信息业务对象") |
| | | public class SysUser extends BaseEntity { |
| | | |
| | | /** |
| | | * 用户ID |
| | | */ |
| | | @ApiModelProperty(value = "用户ID") |
| | | @TableId(value = "user_id") |
| | | private Long userId; |
| | | /** |
| | | * 用户ID |
| | | */ |
| | | @ApiModelProperty(value = "用户ID") |
| | | @TableId(value = "user_id") |
| | | private Long userId; |
| | | |
| | | /** |
| | | * 部门ID |
| | | */ |
| | | @ApiModelProperty(value = "部门ID") |
| | | private Long deptId; |
| | | /** |
| | | * 部门ID |
| | | */ |
| | | @ApiModelProperty(value = "部门ID") |
| | | private Long deptId; |
| | | |
| | | /** |
| | | * 用户账号 |
| | | */ |
| | | @ApiModelProperty(value = "用户账号") |
| | | /** |
| | | * 用户账号 |
| | | */ |
| | | @ApiModelProperty(value = "用户账号") |
| | | @Xss(message = "用户账号不能包含脚本字符") |
| | | @NotBlank(message = "用户账号不能为空") |
| | | @Size(min = 0, max = 30, message = "用户账号长度不能超过30个字符") |
| | | private String userName; |
| | | @Size(min = 0, max = 30, message = "用户账号长度不能超过30个字符") |
| | | private String userName; |
| | | |
| | | /** |
| | | * 用户昵称 |
| | | */ |
| | | /** |
| | | * 用户昵称 |
| | | */ |
| | | @ApiModelProperty(value = "用户昵称") |
| | | @Xss(message = "用户昵称不能包含脚本字符") |
| | | @Size(min = 0, max = 30, message = "用户昵称长度不能超过30个字符") |
| | | private String nickName; |
| | | private String nickName; |
| | | |
| | | /** |
| | | * 用户邮箱 |
| | | */ |
| | | /** |
| | | * 用户邮箱 |
| | | */ |
| | | @Sensitive(strategy = SensitiveStrategy.EMAIL) |
| | | @ApiModelProperty(value = "用户邮箱") |
| | | @Email(message = "邮箱格式不正确") |
| | | @Size(min = 0, max = 50, message = "邮箱长度不能超过50个字符") |
| | | private String email; |
| | | @ApiModelProperty(value = "用户邮箱") |
| | | @Email(message = "邮箱格式不正确") |
| | | @Size(min = 0, max = 50, message = "邮箱长度不能超过50个字符") |
| | | private String email; |
| | | |
| | | /** |
| | | * 手机号码 |
| | | */ |
| | | /** |
| | | * 手机号码 |
| | | */ |
| | | @Sensitive(strategy = SensitiveStrategy.PHONE) |
| | | @ApiModelProperty(value = "手机号码") |
| | | private String phonenumber; |
| | | @ApiModelProperty(value = "手机号码") |
| | | private String phonenumber; |
| | | |
| | | /** |
| | | * 用户性别 |
| | | */ |
| | | @ApiModelProperty(value = "用户性别") |
| | | private String sex; |
| | | /** |
| | | * 用户性别 |
| | | */ |
| | | @ApiModelProperty(value = "用户性别") |
| | | private String sex; |
| | | |
| | | /** |
| | | * 用户头像 |
| | | */ |
| | | @ApiModelProperty(value = "用户头像") |
| | | private String avatar; |
| | | /** |
| | | * 用户头像 |
| | | */ |
| | | @ApiModelProperty(value = "用户头像") |
| | | private String avatar; |
| | | |
| | | /** |
| | | * 密码 |
| | | */ |
| | | @ApiModelProperty(value = "密码") |
| | | @TableField( |
| | | insertStrategy = FieldStrategy.NOT_EMPTY, |
| | | updateStrategy = FieldStrategy.NOT_EMPTY, |
| | | whereStrategy = FieldStrategy.NOT_EMPTY |
| | | ) |
| | | private String password; |
| | | /** |
| | | * 密码 |
| | | */ |
| | | @ApiModelProperty(value = "密码") |
| | | @TableField( |
| | | insertStrategy = FieldStrategy.NOT_EMPTY, |
| | | updateStrategy = FieldStrategy.NOT_EMPTY, |
| | | whereStrategy = FieldStrategy.NOT_EMPTY |
| | | ) |
| | | private String password; |
| | | |
| | | @JsonIgnore |
| | | @JsonProperty |
| | | public String getPassword() { |
| | | return password; |
| | | } |
| | | @JsonIgnore |
| | | @JsonProperty |
| | | public String getPassword() { |
| | | return password; |
| | | } |
| | | |
| | | /** |
| | | * 帐号状态(0正常 1停用) |
| | | */ |
| | | @ApiModelProperty(value = "帐号状态(0正常 1停用)") |
| | | private String status; |
| | | /** |
| | | * 帐号状态(0正常 1停用) |
| | | */ |
| | | @ApiModelProperty(value = "帐号状态(0正常 1停用)") |
| | | private String status; |
| | | |
| | | /** |
| | | * 删除标志(0代表存在 2代表删除) |
| | | */ |
| | | @ApiModelProperty(value = "删除标志(0代表存在 2代表删除)") |
| | | @TableLogic |
| | | private String delFlag; |
| | | /** |
| | | * 删除标志(0代表存在 2代表删除) |
| | | */ |
| | | @ApiModelProperty(value = "删除标志(0代表存在 2代表删除)") |
| | | @TableLogic |
| | | private String delFlag; |
| | | |
| | | /** |
| | | * 最后登录IP |
| | | */ |
| | | @ApiModelProperty(value = "最后登录IP") |
| | | private String loginIp; |
| | | /** |
| | | * 最后登录IP |
| | | */ |
| | | @ApiModelProperty(value = "最后登录IP") |
| | | private String loginIp; |
| | | |
| | | /** |
| | | * 最后登录时间 |
| | | */ |
| | | @ApiModelProperty(value = "最后登录时间") |
| | | private Date loginDate; |
| | | /** |
| | | * 最后登录时间 |
| | | */ |
| | | @ApiModelProperty(value = "最后登录时间") |
| | | private Date loginDate; |
| | | |
| | | /** |
| | | * 备注 |
| | | */ |
| | | @ApiModelProperty(value = "备注") |
| | | private String remark; |
| | | /** |
| | | * 备注 |
| | | */ |
| | | @ApiModelProperty(value = "备注") |
| | | private String remark; |
| | | |
| | | /** |
| | | * 部门对象 |
| | | */ |
| | | @ApiModelProperty(value = "部门对象") |
| | | @TableField(exist = false) |
| | | private SysDept dept; |
| | | /** |
| | | * 部门对象 |
| | | */ |
| | | @ApiModelProperty(value = "部门对象") |
| | | @TableField(exist = false) |
| | | private SysDept dept; |
| | | |
| | | /** |
| | | * 角色对象 |
| | | */ |
| | | @ApiModelProperty(value = "角色对象") |
| | | @TableField(exist = false) |
| | | private List<SysRole> roles; |
| | | /** |
| | | * 角色对象 |
| | | */ |
| | | @ApiModelProperty(value = "角色对象") |
| | | @TableField(exist = false) |
| | | private List<SysRole> roles; |
| | | |
| | | /** |
| | | * 角色组 |
| | | */ |
| | | @ApiModelProperty(value = "角色组") |
| | | @TableField(exist = false) |
| | | private Long[] roleIds; |
| | | /** |
| | | * 角色组 |
| | | */ |
| | | @ApiModelProperty(value = "角色组") |
| | | @TableField(exist = false) |
| | | private Long[] roleIds; |
| | | |
| | | /** |
| | | * 岗位组 |
| | | */ |
| | | @ApiModelProperty(value = "岗位组") |
| | | @TableField(exist = false) |
| | | private Long[] postIds; |
| | | /** |
| | | * 岗位组 |
| | | */ |
| | | @ApiModelProperty(value = "岗位组") |
| | | @TableField(exist = false) |
| | | private Long[] postIds; |
| | | |
| | | /** |
| | | * 数据权限 当前角色ID |
| | | */ |
| | | @ApiModelProperty(value = "角色ID") |
| | | @TableField(exist = false) |
| | | private Long roleId; |
| | | /** |
| | | * 数据权限 当前角色ID |
| | | */ |
| | | @ApiModelProperty(value = "角色ID") |
| | | @TableField(exist = false) |
| | | private Long roleId; |
| | | |
| | | public SysUser(Long userId) { |
| | | this.userId = userId; |
| | | } |
| | | public SysUser(Long userId) { |
| | | this.userId = userId; |
| | | } |
| | | |
| | | @ApiModelProperty(value = "是否管理员") |
| | | public boolean isAdmin() { |
| | | return isAdmin(this.userId); |
| | | } |
| | | @ApiModelProperty(value = "是否管理员") |
| | | public boolean isAdmin() { |
| | | return isAdmin(this.userId); |
| | | } |
| | | |
| | | public static boolean isAdmin(Long userId) { |
| | | return userId != null && 1L == userId; |
| | | } |
| | | public static boolean isAdmin(Long userId) { |
| | | return userId != null && 1L == userId; |
| | | } |
| | | |
| | | } |
| | |
| | | */ |
| | | public interface BaseMapperPlus<T> extends BaseMapper<T> { |
| | | |
| | | /** |
| | | * 单sql批量插入( 全量填充 ) |
| | | */ |
| | | int insertAll(@Param("list") Collection<T> batchList); |
| | | /** |
| | | * 单sql批量插入( 全量填充 ) |
| | | */ |
| | | int insertAll(@Param("list") Collection<T> batchList); |
| | | |
| | | /** |
| | | * 根据 ID 查询 |
| | | */ |
| | | default <V> V selectVoById(Serializable id, Class<V> voClass){ |
| | | default <V> V selectVoById(Serializable id, Class<V> voClass) { |
| | | T obj = this.selectById(id); |
| | | if (ObjectUtil.isNull(obj)) { |
| | | return null; |
| | |
| | | /** |
| | | * 查询(根据ID 批量查询) |
| | | */ |
| | | default <V> List<V> selectVoBatchIds(Collection<? extends Serializable> idList, Class<V> voClass){ |
| | | default <V> List<V> selectVoBatchIds(Collection<? extends Serializable> idList, Class<V> voClass) { |
| | | List<T> list = this.selectBatchIds(idList); |
| | | if (CollUtil.isEmpty(list)) { |
| | | return CollUtil.newArrayList(); |
| | |
| | | /** |
| | | * 查询(根据 columnMap 条件) |
| | | */ |
| | | default <V> List<V> selectVoByMap(Map<String, Object> map, Class<V> voClass){ |
| | | default <V> List<V> selectVoByMap(Map<String, Object> map, Class<V> voClass) { |
| | | List<T> list = this.selectByMap(map); |
| | | if (CollUtil.isEmpty(list)) { |
| | | return CollUtil.newArrayList(); |
| | |
| | | */ |
| | | public interface IServicePlus<T, V> extends IService<T> { |
| | | |
| | | /** |
| | | * @param id 主键id |
| | | * @return V对象 |
| | | */ |
| | | V getVoById(Serializable id); |
| | | /** |
| | | * @param id 主键id |
| | | * @return V对象 |
| | | */ |
| | | V getVoById(Serializable id); |
| | | |
| | | /** |
| | | * @param convertor 自定义转换器 |
| | | */ |
| | | default V getVoById(Serializable id, Function<T, V> convertor) { |
| | | return convertor.apply(getById(id)); |
| | | } |
| | | /** |
| | | * @param convertor 自定义转换器 |
| | | */ |
| | | default V getVoById(Serializable id, Function<T, V> convertor) { |
| | | return convertor.apply(getById(id)); |
| | | } |
| | | |
| | | /** |
| | | * @param idList id列表 |
| | | * @return V对象 |
| | | */ |
| | | List<V> listVoByIds(Collection<? extends Serializable> idList); |
| | | /** |
| | | * @param idList id列表 |
| | | * @return V对象 |
| | | */ |
| | | List<V> listVoByIds(Collection<? extends Serializable> idList); |
| | | |
| | | /** |
| | | * @param convertor 自定义转换器 |
| | | */ |
| | | default List<V> listVoByIds(Collection<? extends Serializable> idList, |
| | | Function<Collection<T>, List<V>> convertor) { |
| | | List<T> list = getBaseMapper().selectBatchIds(idList); |
| | | if (list == null) { |
| | | return null; |
| | | } |
| | | return convertor.apply(list); |
| | | } |
| | | /** |
| | | * @param convertor 自定义转换器 |
| | | */ |
| | | default List<V> listVoByIds(Collection<? extends Serializable> idList, |
| | | Function<Collection<T>, List<V>> convertor) { |
| | | List<T> list = getBaseMapper().selectBatchIds(idList); |
| | | if (list == null) { |
| | | return null; |
| | | } |
| | | return convertor.apply(list); |
| | | } |
| | | |
| | | /** |
| | | * @param columnMap 表字段 map 对象 |
| | | * @return V对象 |
| | | */ |
| | | List<V> listVoByMap(Map<String, Object> columnMap); |
| | | /** |
| | | * @param columnMap 表字段 map 对象 |
| | | * @return V对象 |
| | | */ |
| | | List<V> listVoByMap(Map<String, Object> columnMap); |
| | | |
| | | /** |
| | | * @param convertor 自定义转换器 |
| | | */ |
| | | default List<V> listVoByMap(Map<String, Object> columnMap, |
| | | Function<Collection<T>, List<V>> convertor) { |
| | | List<T> list = getBaseMapper().selectByMap(columnMap); |
| | | if (list == null) { |
| | | return null; |
| | | } |
| | | return convertor.apply(list); |
| | | } |
| | | /** |
| | | * @param convertor 自定义转换器 |
| | | */ |
| | | default List<V> listVoByMap(Map<String, Object> columnMap, |
| | | Function<Collection<T>, List<V>> convertor) { |
| | | List<T> list = getBaseMapper().selectByMap(columnMap); |
| | | if (list == null) { |
| | | return null; |
| | | } |
| | | return convertor.apply(list); |
| | | } |
| | | |
| | | /** |
| | | * @param queryWrapper 查询条件 |
| | | * @return V对象 |
| | | */ |
| | | V getVoOne(Wrapper<T> queryWrapper); |
| | | /** |
| | | * @param queryWrapper 查询条件 |
| | | * @return V对象 |
| | | */ |
| | | V getVoOne(Wrapper<T> queryWrapper); |
| | | |
| | | /** |
| | | * @param convertor 自定义转换器 |
| | | */ |
| | | default V getVoOne(Wrapper<T> queryWrapper, Function<T, V> convertor) { |
| | | return convertor.apply(getOne(queryWrapper, true)); |
| | | } |
| | | /** |
| | | * @param convertor 自定义转换器 |
| | | */ |
| | | default V getVoOne(Wrapper<T> queryWrapper, Function<T, V> convertor) { |
| | | return convertor.apply(getOne(queryWrapper, true)); |
| | | } |
| | | |
| | | /** |
| | | * @param queryWrapper 查询条件 |
| | | * @return V对象 |
| | | */ |
| | | List<V> listVo(Wrapper<T> queryWrapper); |
| | | /** |
| | | * @param queryWrapper 查询条件 |
| | | * @return V对象 |
| | | */ |
| | | List<V> listVo(Wrapper<T> queryWrapper); |
| | | |
| | | /** |
| | | * @param convertor 自定义转换器 |
| | | */ |
| | | default List<V> listVo(Wrapper<T> queryWrapper, Function<Collection<T>, List<V>> convertor) { |
| | | List<T> list = getBaseMapper().selectList(queryWrapper); |
| | | if (list == null) { |
| | | return null; |
| | | } |
| | | return convertor.apply(list); |
| | | } |
| | | /** |
| | | * @param convertor 自定义转换器 |
| | | */ |
| | | default List<V> listVo(Wrapper<T> queryWrapper, Function<Collection<T>, List<V>> convertor) { |
| | | List<T> list = getBaseMapper().selectList(queryWrapper); |
| | | if (list == null) { |
| | | return null; |
| | | } |
| | | return convertor.apply(list); |
| | | } |
| | | |
| | | default List<V> listVo() { |
| | | return listVo(Wrappers.emptyWrapper()); |
| | | } |
| | | default List<V> listVo() { |
| | | return listVo(Wrappers.emptyWrapper()); |
| | | } |
| | | |
| | | /** |
| | | * @param convertor 自定义转换器 |
| | | */ |
| | | default List<V> listVo(Function<Collection<T>, List<V>> convertor) { |
| | | return listVo(Wrappers.emptyWrapper(), convertor); |
| | | } |
| | | /** |
| | | * @param convertor 自定义转换器 |
| | | */ |
| | | default List<V> listVo(Function<Collection<T>, List<V>> convertor) { |
| | | return listVo(Wrappers.emptyWrapper(), convertor); |
| | | } |
| | | |
| | | boolean saveAll(Collection<T> entityList); |
| | | boolean saveAll(Collection<T> entityList); |
| | | |
| | | boolean saveOrUpdateAll(Collection<T> entityList); |
| | | boolean saveOrUpdateAll(Collection<T> entityList); |
| | | } |
| | | |
| | |
| | | @SuppressWarnings("unchecked") |
| | | public class ServicePlusImpl<M extends BaseMapperPlus<T>, T, V> extends ServiceImpl<M, T> implements IServicePlus<T, V> { |
| | | |
| | | @Autowired |
| | | protected M baseMapper; |
| | | @Autowired |
| | | protected M baseMapper; |
| | | |
| | | @Override |
| | | public M getBaseMapper() { |
| | | return baseMapper; |
| | | } |
| | | @Override |
| | | public M getBaseMapper() { |
| | | return baseMapper; |
| | | } |
| | | |
| | | |
| | | protected Class<T> entityClass = currentModelClass(); |
| | | protected Class<T> entityClass = currentModelClass(); |
| | | |
| | | @Override |
| | | public Class<T> getEntityClass() { |
| | | return entityClass; |
| | | } |
| | | @Override |
| | | public Class<T> getEntityClass() { |
| | | return entityClass; |
| | | } |
| | | |
| | | protected Class<M> mapperClass = currentMapperClass(); |
| | | protected Class<M> mapperClass = currentMapperClass(); |
| | | |
| | | protected Class<V> voClass = currentVoClass(); |
| | | protected Class<V> voClass = currentVoClass(); |
| | | |
| | | public Class<V> getVoClass() { |
| | | return voClass; |
| | | } |
| | | public Class<V> getVoClass() { |
| | | return voClass; |
| | | } |
| | | |
| | | @Override |
| | | protected Class<M> currentMapperClass() { |
| | | return (Class<M>) ReflectionKit.getSuperClassGenericType(this.getClass(), ServicePlusImpl.class, 0); |
| | | } |
| | | @Override |
| | | protected Class<M> currentMapperClass() { |
| | | return (Class<M>) ReflectionKit.getSuperClassGenericType(this.getClass(), ServicePlusImpl.class, 0); |
| | | } |
| | | |
| | | @Override |
| | | protected Class<T> currentModelClass() { |
| | | return (Class<T>) ReflectionKit.getSuperClassGenericType(this.getClass(), ServicePlusImpl.class, 1); |
| | | } |
| | | @Override |
| | | protected Class<T> currentModelClass() { |
| | | return (Class<T>) ReflectionKit.getSuperClassGenericType(this.getClass(), ServicePlusImpl.class, 1); |
| | | } |
| | | |
| | | protected Class<V> currentVoClass() { |
| | | return (Class<V>) ReflectionKit.getSuperClassGenericType(this.getClass(), ServicePlusImpl.class, 2); |
| | | } |
| | | protected Class<V> currentVoClass() { |
| | | return (Class<V>) ReflectionKit.getSuperClassGenericType(this.getClass(), ServicePlusImpl.class, 2); |
| | | } |
| | | |
| | | /** |
| | | * 单条执行性能差 适用于列表对象内容不确定 |
| | | */ |
| | | @Override |
| | | public boolean saveBatch(Collection<T> entityList, int batchSize) { |
| | | return super.saveBatch(entityList, batchSize); |
| | | } |
| | | /** |
| | | * 单条执行性能差 适用于列表对象内容不确定 |
| | | */ |
| | | @Override |
| | | public boolean saveBatch(Collection<T> entityList, int batchSize) { |
| | | return super.saveBatch(entityList, batchSize); |
| | | } |
| | | |
| | | @Override |
| | | public boolean saveOrUpdate(T entity) { |
| | | return super.saveOrUpdate(entity); |
| | | } |
| | | @Override |
| | | public boolean saveOrUpdate(T entity) { |
| | | return super.saveOrUpdate(entity); |
| | | } |
| | | |
| | | /** |
| | | * 单条执行性能差 适用于列表对象内容不确定 |
| | | */ |
| | | @Override |
| | | public boolean saveOrUpdateBatch(Collection<T> entityList, int batchSize) { |
| | | return super.saveOrUpdateBatch(entityList, batchSize); |
| | | } |
| | | /** |
| | | * 单条执行性能差 适用于列表对象内容不确定 |
| | | */ |
| | | @Override |
| | | public boolean saveOrUpdateBatch(Collection<T> entityList, int batchSize) { |
| | | return super.saveOrUpdateBatch(entityList, batchSize); |
| | | } |
| | | |
| | | @Override |
| | | public boolean updateBatchById(Collection<T> entityList, int batchSize) { |
| | | return super.updateBatchById(entityList, batchSize); |
| | | } |
| | | @Override |
| | | public boolean updateBatchById(Collection<T> entityList, int batchSize) { |
| | | return super.updateBatchById(entityList, batchSize); |
| | | } |
| | | |
| | | /** |
| | | * 单sql批量插入( 全量填充 无视数据库默认值 ) |
| | | * 适用于无脑插入 |
| | | */ |
| | | @Override |
| | | public boolean saveBatch(Collection<T> entityList) { |
| | | return saveBatch(entityList, DEFAULT_BATCH_SIZE); |
| | | } |
| | | /** |
| | | * 单sql批量插入( 全量填充 无视数据库默认值 ) |
| | | * 适用于无脑插入 |
| | | */ |
| | | @Override |
| | | public boolean saveBatch(Collection<T> entityList) { |
| | | return saveBatch(entityList, DEFAULT_BATCH_SIZE); |
| | | } |
| | | |
| | | @Override |
| | | public boolean saveOrUpdateBatch(Collection<T> entityList) { |
| | | return saveOrUpdateBatch(entityList, DEFAULT_BATCH_SIZE); |
| | | } |
| | | @Override |
| | | public boolean saveOrUpdateBatch(Collection<T> entityList) { |
| | | return saveOrUpdateBatch(entityList, DEFAULT_BATCH_SIZE); |
| | | } |
| | | |
| | | @Override |
| | | public boolean updateBatchById(Collection<T> entityList) { |
| | | return updateBatchById(entityList, DEFAULT_BATCH_SIZE); |
| | | } |
| | | @Override |
| | | public boolean updateBatchById(Collection<T> entityList) { |
| | | return updateBatchById(entityList, DEFAULT_BATCH_SIZE); |
| | | } |
| | | |
| | | /** |
| | | * 单sql批量插入( 全量填充 ) |
| | | */ |
| | | @Override |
| | | public boolean saveAll(Collection<T> entityList) { |
| | | if (CollUtil.isEmpty(entityList)) { |
| | | return false; |
| | | } |
| | | return baseMapper.insertAll(entityList) == entityList.size(); |
| | | } |
| | | /** |
| | | * 单sql批量插入( 全量填充 ) |
| | | */ |
| | | @Override |
| | | public boolean saveAll(Collection<T> entityList) { |
| | | if (CollUtil.isEmpty(entityList)) { |
| | | return false; |
| | | } |
| | | return baseMapper.insertAll(entityList) == entityList.size(); |
| | | } |
| | | |
| | | /** |
| | | * 全量保存或更新 ( 按主键区分 ) |
| | | */ |
| | | @Override |
| | | public boolean saveOrUpdateAll(Collection<T> entityList) { |
| | | if (CollUtil.isEmpty(entityList)) { |
| | | return false; |
| | | } |
| | | TableInfo tableInfo = TableInfoHelper.getTableInfo(entityClass); |
| | | Assert.notNull(tableInfo, "error: can not execute. because can not find cache of TableInfo for entity!"); |
| | | String keyProperty = tableInfo.getKeyProperty(); |
| | | Assert.notEmpty(keyProperty, "error: can not execute. because can not find column for id from entity!"); |
| | | List<T> addList = new ArrayList<>(); |
| | | List<T> updateList = new ArrayList<>(); |
| | | int row = 0; |
| | | for (T entity : entityList) { |
| | | Object id = ReflectUtils.invokeGetter(entity, keyProperty); |
| | | if (ObjectUtil.isNull(id)) { |
| | | addList.add(entity); |
| | | } else { |
| | | updateList.add(entity); |
| | | } |
| | | } |
| | | if (CollUtil.isNotEmpty(updateList) && updateBatchById(updateList)) { |
| | | row += updateList.size(); |
| | | } |
| | | /** |
| | | * 全量保存或更新 ( 按主键区分 ) |
| | | */ |
| | | @Override |
| | | public boolean saveOrUpdateAll(Collection<T> entityList) { |
| | | if (CollUtil.isEmpty(entityList)) { |
| | | return false; |
| | | } |
| | | TableInfo tableInfo = TableInfoHelper.getTableInfo(entityClass); |
| | | Assert.notNull(tableInfo, "error: can not execute. because can not find cache of TableInfo for entity!"); |
| | | String keyProperty = tableInfo.getKeyProperty(); |
| | | Assert.notEmpty(keyProperty, "error: can not execute. because can not find column for id from entity!"); |
| | | List<T> addList = new ArrayList<>(); |
| | | List<T> updateList = new ArrayList<>(); |
| | | int row = 0; |
| | | for (T entity : entityList) { |
| | | Object id = ReflectUtils.invokeGetter(entity, keyProperty); |
| | | if (ObjectUtil.isNull(id)) { |
| | | addList.add(entity); |
| | | } else { |
| | | updateList.add(entity); |
| | | } |
| | | } |
| | | if (CollUtil.isNotEmpty(updateList) && updateBatchById(updateList)) { |
| | | row += updateList.size(); |
| | | } |
| | | if (CollUtil.isNotEmpty(addList)) { |
| | | row += baseMapper.insertAll(addList); |
| | | } |
| | | return row == entityList.size(); |
| | | } |
| | | return row == entityList.size(); |
| | | } |
| | | |
| | | /** |
| | | * 根据 ID 查询 |
| | | */ |
| | | @Override |
| | | public V getVoById(Serializable id) { |
| | | /** |
| | | * 根据 ID 查询 |
| | | */ |
| | | @Override |
| | | public V getVoById(Serializable id) { |
| | | return getBaseMapper().selectVoById(id, voClass); |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 查询(根据ID 批量查询) |
| | | */ |
| | | @Override |
| | | public List<V> listVoByIds(Collection<? extends Serializable> idList) { |
| | | /** |
| | | * 查询(根据ID 批量查询) |
| | | */ |
| | | @Override |
| | | public List<V> listVoByIds(Collection<? extends Serializable> idList) { |
| | | return getBaseMapper().selectVoBatchIds(idList, voClass); |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 查询(根据 columnMap 条件) |
| | | */ |
| | | @Override |
| | | public List<V> listVoByMap(Map<String, Object> columnMap) { |
| | | /** |
| | | * 查询(根据 columnMap 条件) |
| | | */ |
| | | @Override |
| | | public List<V> listVoByMap(Map<String, Object> columnMap) { |
| | | return getBaseMapper().selectVoByMap(columnMap, voClass); |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 根据 Wrapper,查询一条记录 <br/> |
| | | * <p>结果集,如果是多个会抛出异常,随机取一条加上限制条件 wrapper.last("LIMIT 1")</p> |
| | | */ |
| | | @Override |
| | | public V getVoOne(Wrapper<T> queryWrapper) { |
| | | /** |
| | | * 根据 Wrapper,查询一条记录 <br/> |
| | | * <p>结果集,如果是多个会抛出异常,随机取一条加上限制条件 wrapper.last("LIMIT 1")</p> |
| | | */ |
| | | @Override |
| | | public V getVoOne(Wrapper<T> queryWrapper) { |
| | | return getBaseMapper().selectVoOne(queryWrapper, voClass); |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 查询列表 |
| | | */ |
| | | @Override |
| | | public List<V> listVo(Wrapper<T> queryWrapper) { |
| | | /** |
| | | * 查询列表 |
| | | */ |
| | | @Override |
| | | public List<V> listVo(Wrapper<T> queryWrapper) { |
| | | return getBaseMapper().selectVoList(queryWrapper, voClass); |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 翻页查询 |
| | |
| | | */ |
| | | public class InsertAll extends AbstractMethod { |
| | | |
| | | private final static String[] FILL_PROPERTY = {"createTime", "createBy", "updateTime", "updateBy"}; |
| | | private final static String[] FILL_PROPERTY = {"createTime", "createBy", "updateTime", "updateBy"}; |
| | | |
| | | @Override |
| | | public MappedStatement injectMappedStatement(Class<?> mapperClass, Class<?> modelClass, TableInfo tableInfo) { |
| | | final String sql = "<script>insert into %s %s values %s</script>"; |
| | | final String fieldSql = prepareFieldSql(tableInfo); |
| | | final String valueSql = prepareValuesSqlForMysqlBatch(tableInfo); |
| | | KeyGenerator keyGenerator = new NoKeyGenerator(); |
| | | String sqlMethod = "insertAll"; |
| | | String keyProperty = null; |
| | | String keyColumn = null; |
| | | // 表包含主键处理逻辑,如果不包含主键当普通字段处理 |
| | | if (StringUtils.isNotBlank(tableInfo.getKeyProperty())) { |
| | | if (tableInfo.getIdType() == IdType.AUTO) { |
| | | /** 自增主键 */ |
| | | keyGenerator = new Jdbc3KeyGenerator(); |
| | | keyProperty = tableInfo.getKeyProperty(); |
| | | keyColumn = tableInfo.getKeyColumn(); |
| | | } else { |
| | | if (null != tableInfo.getKeySequence()) { |
| | | keyGenerator = TableInfoHelper.genKeyGenerator(sqlMethod, tableInfo, builderAssistant); |
| | | keyProperty = tableInfo.getKeyProperty(); |
| | | keyColumn = tableInfo.getKeyColumn(); |
| | | } |
| | | } |
| | | } |
| | | final String sqlResult = String.format(sql, tableInfo.getTableName(), fieldSql, valueSql); |
| | | SqlSource sqlSource = languageDriver.createSqlSource(configuration, sqlResult, modelClass); |
| | | return this.addInsertMappedStatement(mapperClass, modelClass, sqlMethod, sqlSource, keyGenerator, keyProperty, keyColumn); |
| | | } |
| | | @Override |
| | | public MappedStatement injectMappedStatement(Class<?> mapperClass, Class<?> modelClass, TableInfo tableInfo) { |
| | | final String sql = "<script>insert into %s %s values %s</script>"; |
| | | final String fieldSql = prepareFieldSql(tableInfo); |
| | | final String valueSql = prepareValuesSqlForMysqlBatch(tableInfo); |
| | | KeyGenerator keyGenerator = new NoKeyGenerator(); |
| | | String sqlMethod = "insertAll"; |
| | | String keyProperty = null; |
| | | String keyColumn = null; |
| | | // 表包含主键处理逻辑,如果不包含主键当普通字段处理 |
| | | if (StringUtils.isNotBlank(tableInfo.getKeyProperty())) { |
| | | if (tableInfo.getIdType() == IdType.AUTO) { |
| | | /** 自增主键 */ |
| | | keyGenerator = new Jdbc3KeyGenerator(); |
| | | keyProperty = tableInfo.getKeyProperty(); |
| | | keyColumn = tableInfo.getKeyColumn(); |
| | | } else { |
| | | if (null != tableInfo.getKeySequence()) { |
| | | keyGenerator = TableInfoHelper.genKeyGenerator(sqlMethod, tableInfo, builderAssistant); |
| | | keyProperty = tableInfo.getKeyProperty(); |
| | | keyColumn = tableInfo.getKeyColumn(); |
| | | } |
| | | } |
| | | } |
| | | final String sqlResult = String.format(sql, tableInfo.getTableName(), fieldSql, valueSql); |
| | | SqlSource sqlSource = languageDriver.createSqlSource(configuration, sqlResult, modelClass); |
| | | return this.addInsertMappedStatement(mapperClass, modelClass, sqlMethod, sqlSource, keyGenerator, keyProperty, keyColumn); |
| | | } |
| | | |
| | | private String prepareFieldSql(TableInfo tableInfo) { |
| | | StringBuilder fieldSql = new StringBuilder(); |
| | | if (StringUtils.isNotBlank(tableInfo.getKeyColumn())) { |
| | | fieldSql.append(tableInfo.getKeyColumn()).append(","); |
| | | } |
| | | tableInfo.getFieldList().forEach(x -> fieldSql.append(x.getColumn()).append(",")); |
| | | fieldSql.delete(fieldSql.length() - 1, fieldSql.length()); |
| | | fieldSql.insert(0, "("); |
| | | fieldSql.append(")"); |
| | | return fieldSql.toString(); |
| | | } |
| | | private String prepareFieldSql(TableInfo tableInfo) { |
| | | StringBuilder fieldSql = new StringBuilder(); |
| | | if (StringUtils.isNotBlank(tableInfo.getKeyColumn())) { |
| | | fieldSql.append(tableInfo.getKeyColumn()).append(","); |
| | | } |
| | | tableInfo.getFieldList().forEach(x -> fieldSql.append(x.getColumn()).append(",")); |
| | | fieldSql.delete(fieldSql.length() - 1, fieldSql.length()); |
| | | fieldSql.insert(0, "("); |
| | | fieldSql.append(")"); |
| | | return fieldSql.toString(); |
| | | } |
| | | |
| | | private String prepareValuesSqlForMysqlBatch(TableInfo tableInfo) { |
| | | final StringBuilder valueSql = new StringBuilder(); |
| | | valueSql.append("<foreach collection=\"list\" item=\"item\" index=\"index\" open=\"(\" separator=\"),(\" close=\")\">"); |
| | | if (StringUtils.isNotBlank(tableInfo.getKeyColumn())) { |
| | | valueSql.append("\n#{item.").append(tableInfo.getKeyProperty()).append("},\n"); |
| | | } |
| | | List<TableFieldInfo> fieldList = tableInfo.getFieldList(); |
| | | int last = fieldList.size() - 1; |
| | | for (int i = 0; i < fieldList.size(); i++) { |
| | | String property = fieldList.get(i).getProperty(); |
| | | if (!StringUtils.equalsAny(property, FILL_PROPERTY)) { |
| | | valueSql.append("<if test=\"item.").append(property).append(" != null\">"); |
| | | valueSql.append("#{item.").append(property).append("}"); |
| | | if (i != last) { |
| | | valueSql.append(","); |
| | | } |
| | | valueSql.append("</if>"); |
| | | valueSql.append("<if test=\"item.").append(property).append(" == null\">"); |
| | | valueSql.append("DEFAULT"); |
| | | if (i != last) { |
| | | valueSql.append(","); |
| | | } |
| | | valueSql.append("</if>"); |
| | | } else { |
| | | valueSql.append("#{item.").append(property).append("}"); |
| | | if (i != last) { |
| | | valueSql.append(","); |
| | | } |
| | | } |
| | | } |
| | | valueSql.append("</foreach>"); |
| | | return valueSql.toString(); |
| | | } |
| | | private String prepareValuesSqlForMysqlBatch(TableInfo tableInfo) { |
| | | final StringBuilder valueSql = new StringBuilder(); |
| | | valueSql.append("<foreach collection=\"list\" item=\"item\" index=\"index\" open=\"(\" separator=\"),(\" close=\")\">"); |
| | | if (StringUtils.isNotBlank(tableInfo.getKeyColumn())) { |
| | | valueSql.append("\n#{item.").append(tableInfo.getKeyProperty()).append("},\n"); |
| | | } |
| | | List<TableFieldInfo> fieldList = tableInfo.getFieldList(); |
| | | int last = fieldList.size() - 1; |
| | | for (int i = 0; i < fieldList.size(); i++) { |
| | | String property = fieldList.get(i).getProperty(); |
| | | if (!StringUtils.equalsAny(property, FILL_PROPERTY)) { |
| | | valueSql.append("<if test=\"item.").append(property).append(" != null\">"); |
| | | valueSql.append("#{item.").append(property).append("}"); |
| | | if (i != last) { |
| | | valueSql.append(","); |
| | | } |
| | | valueSql.append("</if>"); |
| | | valueSql.append("<if test=\"item.").append(property).append(" == null\">"); |
| | | valueSql.append("DEFAULT"); |
| | | if (i != last) { |
| | | valueSql.append(","); |
| | | } |
| | | valueSql.append("</if>"); |
| | | } else { |
| | | valueSql.append("#{item.").append(property).append("}"); |
| | | if (i != last) { |
| | | valueSql.append(","); |
| | | } |
| | | } |
| | | } |
| | | valueSql.append("</foreach>"); |
| | | return valueSql.toString(); |
| | | } |
| | | } |
| | | |
| | |
| | | @Accessors(chain = true) |
| | | @ApiModel("分页响应对象") |
| | | public class TableDataInfo<T> implements Serializable { |
| | | private static final long serialVersionUID = 1L; |
| | | private static final long serialVersionUID = 1L; |
| | | |
| | | /** |
| | | * 总记录数 |
| | | */ |
| | | @ApiModelProperty("总记录数") |
| | | private long total; |
| | | /** |
| | | * 总记录数 |
| | | */ |
| | | @ApiModelProperty("总记录数") |
| | | private long total; |
| | | |
| | | /** |
| | | * 列表数据 |
| | | */ |
| | | @ApiModelProperty("列表数据") |
| | | private List<T> rows; |
| | | /** |
| | | * 列表数据 |
| | | */ |
| | | @ApiModelProperty("列表数据") |
| | | private List<T> rows; |
| | | |
| | | /** |
| | | * 消息状态码 |
| | | */ |
| | | @ApiModelProperty("消息状态码") |
| | | private int code; |
| | | /** |
| | | * 消息状态码 |
| | | */ |
| | | @ApiModelProperty("消息状态码") |
| | | private int code; |
| | | |
| | | /** |
| | | * 消息内容 |
| | | */ |
| | | @ApiModelProperty("消息内容") |
| | | private String msg; |
| | | /** |
| | | * 消息内容 |
| | | */ |
| | | @ApiModelProperty("消息内容") |
| | | private String msg; |
| | | |
| | | /** |
| | | * 分页 |
| | | * |
| | | * @param list 列表数据 |
| | | * @param total 总记录数 |
| | | */ |
| | | public TableDataInfo(List<T> list, long total) { |
| | | this.rows = list; |
| | | this.total = total; |
| | | } |
| | | /** |
| | | * 分页 |
| | | * |
| | | * @param list 列表数据 |
| | | * @param total 总记录数 |
| | | */ |
| | | public TableDataInfo(List<T> list, long total) { |
| | | this.rows = list; |
| | | this.total = total; |
| | | } |
| | | |
| | | public static <T> TableDataInfo<T> build(IPage<T> page) { |
| | | TableDataInfo<T> rspData = new TableDataInfo<>(); |
| | |
| | | @NoArgsConstructor(access = AccessLevel.PRIVATE) |
| | | public class StringUtils extends org.apache.commons.lang3.StringUtils { |
| | | |
| | | /** |
| | | * 获取参数不为空值 |
| | | * |
| | | * @param value defaultValue 要判断的value |
| | | * @return value 返回值 |
| | | */ |
| | | public static <T> T nvl(T value, T defaultValue) { |
| | | return ObjectUtil.defaultIfNull(value, defaultValue); |
| | | } |
| | | /** |
| | | * 获取参数不为空值 |
| | | * |
| | | * @param value defaultValue 要判断的value |
| | | * @return value 返回值 |
| | | */ |
| | | public static <T> T nvl(T value, T defaultValue) { |
| | | return ObjectUtil.defaultIfNull(value, defaultValue); |
| | | } |
| | | |
| | | /** |
| | | * 获取参数不为空值 |
| | | * |
| | | * @param str defaultValue 要判断的value |
| | | * @return value 返回值 |
| | | */ |
| | | public static String blankToDefault(String str, String defaultValue) { |
| | | return StrUtil.blankToDefault(str, defaultValue); |
| | | } |
| | | /** |
| | | * 获取参数不为空值 |
| | | * |
| | | * @param str defaultValue 要判断的value |
| | | * @return value 返回值 |
| | | */ |
| | | public static String blankToDefault(String str, String defaultValue) { |
| | | return StrUtil.blankToDefault(str, defaultValue); |
| | | } |
| | | |
| | | /** |
| | | * * 判断一个Collection是否为空, 包含List,Set,Queue |
| | | * |
| | | * @param coll 要判断的Collection |
| | | * @return true:为空 false:非空 |
| | | */ |
| | | public static boolean isEmpty(Collection<?> coll) { |
| | | return CollUtil.isEmpty(coll); |
| | | } |
| | | /** |
| | | * * 判断一个Collection是否为空, 包含List,Set,Queue |
| | | * |
| | | * @param coll 要判断的Collection |
| | | * @return true:为空 false:非空 |
| | | */ |
| | | public static boolean isEmpty(Collection<?> coll) { |
| | | return CollUtil.isEmpty(coll); |
| | | } |
| | | |
| | | /** |
| | | * * 判断一个Collection是否非空,包含List,Set,Queue |
| | | * |
| | | * @param coll 要判断的Collection |
| | | * @return true:非空 false:空 |
| | | */ |
| | | public static boolean isNotEmpty(Collection<?> coll) { |
| | | return !isEmpty(coll); |
| | | } |
| | | /** |
| | | * * 判断一个Collection是否非空,包含List,Set,Queue |
| | | * |
| | | * @param coll 要判断的Collection |
| | | * @return true:非空 false:空 |
| | | */ |
| | | public static boolean isNotEmpty(Collection<?> coll) { |
| | | return !isEmpty(coll); |
| | | } |
| | | |
| | | /** |
| | | * * 判断一个对象数组是否为空 |
| | | * |
| | | * @param objects 要判断的对象数组 |
| | | * * @return true:为空 false:非空 |
| | | */ |
| | | public static boolean isEmpty(Object[] objects) { |
| | | return ArrayUtil.isEmpty(objects); |
| | | } |
| | | /** |
| | | * * 判断一个对象数组是否为空 |
| | | * |
| | | * @param objects 要判断的对象数组 |
| | | * * @return true:为空 false:非空 |
| | | */ |
| | | public static boolean isEmpty(Object[] objects) { |
| | | return ArrayUtil.isEmpty(objects); |
| | | } |
| | | |
| | | /** |
| | | * * 判断一个对象数组是否非空 |
| | | * |
| | | * @param objects 要判断的对象数组 |
| | | * @return true:非空 false:空 |
| | | */ |
| | | public static boolean isNotEmpty(Object[] objects) { |
| | | return !isEmpty(objects); |
| | | } |
| | | /** |
| | | * * 判断一个对象数组是否非空 |
| | | * |
| | | * @param objects 要判断的对象数组 |
| | | * @return true:非空 false:空 |
| | | */ |
| | | public static boolean isNotEmpty(Object[] objects) { |
| | | return !isEmpty(objects); |
| | | } |
| | | |
| | | /** |
| | | * * 判断一个对象是否为空 |
| | | * |
| | | * @param object 要判断的对象数组 |
| | | * * @return true:为空 false:非空 |
| | | */ |
| | | public static boolean isEmpty(Object object) { |
| | | return ObjectUtil.isEmpty(object); |
| | | } |
| | | /** |
| | | * * 判断一个对象是否为空 |
| | | * |
| | | * @param object 要判断的对象数组 |
| | | * * @return true:为空 false:非空 |
| | | */ |
| | | public static boolean isEmpty(Object object) { |
| | | return ObjectUtil.isEmpty(object); |
| | | } |
| | | |
| | | /** |
| | | * * 判断一个对象是否非空 |
| | | * |
| | | * @param object 要判断的对象数组 |
| | | * @return true:非空 false:空 |
| | | */ |
| | | public static boolean isNotEmpty(Object object) { |
| | | return !isEmpty(object); |
| | | } |
| | | /** |
| | | * * 判断一个对象是否非空 |
| | | * |
| | | * @param object 要判断的对象数组 |
| | | * @return true:非空 false:空 |
| | | */ |
| | | public static boolean isNotEmpty(Object object) { |
| | | return !isEmpty(object); |
| | | } |
| | | |
| | | /** |
| | | * * 判断一个Map是否为空 |
| | | * |
| | | * @param map 要判断的Map |
| | | * @return true:为空 false:非空 |
| | | */ |
| | | public static boolean isEmpty(Map<?, ?> map) { |
| | | return MapUtil.isEmpty(map); |
| | | } |
| | | /** |
| | | * * 判断一个Map是否为空 |
| | | * |
| | | * @param map 要判断的Map |
| | | * @return true:为空 false:非空 |
| | | */ |
| | | public static boolean isEmpty(Map<?, ?> map) { |
| | | return MapUtil.isEmpty(map); |
| | | } |
| | | |
| | | /** |
| | | * * 判断一个Map是否为空 |
| | | * |
| | | * @param map 要判断的Map |
| | | * @return true:非空 false:空 |
| | | */ |
| | | public static boolean isNotEmpty(Map<?, ?> map) { |
| | | return !isEmpty(map); |
| | | } |
| | | /** |
| | | * * 判断一个Map是否为空 |
| | | * |
| | | * @param map 要判断的Map |
| | | * @return true:非空 false:空 |
| | | */ |
| | | public static boolean isNotEmpty(Map<?, ?> map) { |
| | | return !isEmpty(map); |
| | | } |
| | | |
| | | /** |
| | | * * 判断一个字符串是否为空串 |
| | | * |
| | | * @param str String |
| | | * @return true:为空 false:非空 |
| | | */ |
| | | public static boolean isEmpty(String str) { |
| | | return StrUtil.isEmpty(str); |
| | | } |
| | | /** |
| | | * * 判断一个字符串是否为空串 |
| | | * |
| | | * @param str String |
| | | * @return true:为空 false:非空 |
| | | */ |
| | | public static boolean isEmpty(String str) { |
| | | return StrUtil.isEmpty(str); |
| | | } |
| | | |
| | | /** |
| | | * * 判断一个字符串是否为非空串 |
| | | * |
| | | * @param str String |
| | | * @return true:非空串 false:空串 |
| | | */ |
| | | public static boolean isNotEmpty(String str) { |
| | | return !isEmpty(str); |
| | | } |
| | | /** |
| | | * * 判断一个字符串是否为非空串 |
| | | * |
| | | * @param str String |
| | | * @return true:非空串 false:空串 |
| | | */ |
| | | public static boolean isNotEmpty(String str) { |
| | | return !isEmpty(str); |
| | | } |
| | | |
| | | /** |
| | | * * 判断一个对象是否为空 |
| | | * |
| | | * @param object Object |
| | | * @return true:为空 false:非空 |
| | | */ |
| | | public static boolean isNull(Object object) { |
| | | return ObjectUtil.isNull(object); |
| | | } |
| | | /** |
| | | * * 判断一个对象是否为空 |
| | | * |
| | | * @param object Object |
| | | * @return true:为空 false:非空 |
| | | */ |
| | | public static boolean isNull(Object object) { |
| | | return ObjectUtil.isNull(object); |
| | | } |
| | | |
| | | /** |
| | | * * 判断一个对象是否非空 |
| | | * |
| | | * @param object Object |
| | | * @return true:非空 false:空 |
| | | */ |
| | | public static boolean isNotNull(Object object) { |
| | | return !isNull(object); |
| | | } |
| | | /** |
| | | * * 判断一个对象是否非空 |
| | | * |
| | | * @param object Object |
| | | * @return true:非空 false:空 |
| | | */ |
| | | public static boolean isNotNull(Object object) { |
| | | return !isNull(object); |
| | | } |
| | | |
| | | /** |
| | | * * 判断一个对象是否是数组类型(Java基本型别的数组) |
| | | * |
| | | * @param object 对象 |
| | | * @return true:是数组 false:不是数组 |
| | | */ |
| | | public static boolean isArray(Object object) { |
| | | return ArrayUtil.isArray(object); |
| | | } |
| | | /** |
| | | * * 判断一个对象是否是数组类型(Java基本型别的数组) |
| | | * |
| | | * @param object 对象 |
| | | * @return true:是数组 false:不是数组 |
| | | */ |
| | | public static boolean isArray(Object object) { |
| | | return ArrayUtil.isArray(object); |
| | | } |
| | | |
| | | /** |
| | | * 去空格 |
| | | */ |
| | | public static String trim(String str) { |
| | | return StrUtil.trim(str); |
| | | } |
| | | /** |
| | | * 去空格 |
| | | */ |
| | | public static String trim(String str) { |
| | | return StrUtil.trim(str); |
| | | } |
| | | |
| | | /** |
| | | * 截取字符串 |
| | | * |
| | | * @param str 字符串 |
| | | * @param start 开始 |
| | | * @return 结果 |
| | | */ |
| | | public static String substring(final String str, int start) { |
| | | return substring(str, start, str.length()); |
| | | } |
| | | /** |
| | | * 截取字符串 |
| | | * |
| | | * @param str 字符串 |
| | | * @param start 开始 |
| | | * @return 结果 |
| | | */ |
| | | public static String substring(final String str, int start) { |
| | | return substring(str, start, str.length()); |
| | | } |
| | | |
| | | /** |
| | | * 截取字符串 |
| | | * |
| | | * @param str 字符串 |
| | | * @param start 开始 |
| | | * @param end 结束 |
| | | * @return 结果 |
| | | */ |
| | | public static String substring(final String str, int start, int end) { |
| | | return StrUtil.sub(str, start, end); |
| | | } |
| | | /** |
| | | * 截取字符串 |
| | | * |
| | | * @param str 字符串 |
| | | * @param start 开始 |
| | | * @param end 结束 |
| | | * @return 结果 |
| | | */ |
| | | public static String substring(final String str, int start, int end) { |
| | | return StrUtil.sub(str, start, end); |
| | | } |
| | | |
| | | /** |
| | | * 格式化文本, {} 表示占位符<br> |
| | | * 此方法只是简单将占位符 {} 按照顺序替换为参数<br> |
| | | * 如果想输出 {} 使用 \\转义 { 即可,如果想输出 {} 之前的 \ 使用双转义符 \\\\ 即可<br> |
| | | * 例:<br> |
| | | * 通常使用:format("this is {} for {}", "a", "b") -> this is a for b<br> |
| | | * 转义{}: format("this is \\{} for {}", "a", "b") -> this is \{} for a<br> |
| | | * 转义\: format("this is \\\\{} for {}", "a", "b") -> this is \a for b<br> |
| | | * |
| | | * @param template 文本模板,被替换的部分用 {} 表示 |
| | | * @param params 参数值 |
| | | * @return 格式化后的文本 |
| | | */ |
| | | public static String format(String template, Object... params) { |
| | | return StrUtil.format(template, params); |
| | | } |
| | | /** |
| | | * 格式化文本, {} 表示占位符<br> |
| | | * 此方法只是简单将占位符 {} 按照顺序替换为参数<br> |
| | | * 如果想输出 {} 使用 \\转义 { 即可,如果想输出 {} 之前的 \ 使用双转义符 \\\\ 即可<br> |
| | | * 例:<br> |
| | | * 通常使用:format("this is {} for {}", "a", "b") -> this is a for b<br> |
| | | * 转义{}: format("this is \\{} for {}", "a", "b") -> this is \{} for a<br> |
| | | * 转义\: format("this is \\\\{} for {}", "a", "b") -> this is \a for b<br> |
| | | * |
| | | * @param template 文本模板,被替换的部分用 {} 表示 |
| | | * @param params 参数值 |
| | | * @return 格式化后的文本 |
| | | */ |
| | | public static String format(String template, Object... params) { |
| | | return StrUtil.format(template, params); |
| | | } |
| | | |
| | | /** |
| | | * 是否为http(s)://开头 |
| | | * |
| | | * @param link 链接 |
| | | * @return 结果 |
| | | */ |
| | | public static boolean ishttp(String link) { |
| | | return Validator.isUrl(link); |
| | | } |
| | | /** |
| | | * 是否为http(s)://开头 |
| | | * |
| | | * @param link 链接 |
| | | * @return 结果 |
| | | */ |
| | | public static boolean ishttp(String link) { |
| | | return Validator.isUrl(link); |
| | | } |
| | | |
| | | /** |
| | | * 字符串转set |
| | | * |
| | | * @param str 字符串 |
| | | * @param sep 分隔符 |
| | | * @return set集合 |
| | | */ |
| | | public static Set<String> str2Set(String str, String sep) { |
| | | return new HashSet<>(str2List(str, sep, true, false)); |
| | | } |
| | | /** |
| | | * 字符串转set |
| | | * |
| | | * @param str 字符串 |
| | | * @param sep 分隔符 |
| | | * @return set集合 |
| | | */ |
| | | public static Set<String> str2Set(String str, String sep) { |
| | | return new HashSet<>(str2List(str, sep, true, false)); |
| | | } |
| | | |
| | | /** |
| | | * 字符串转list |
| | | * |
| | | * @param str 字符串 |
| | | * @param sep 分隔符 |
| | | * @param filterBlank 过滤纯空白 |
| | | * @param trim 去掉首尾空白 |
| | | * @return list集合 |
| | | */ |
| | | public static List<String> str2List(String str, String sep, boolean filterBlank, boolean trim) { |
| | | List<String> list = new ArrayList<>(); |
| | | if (isEmpty(str)) { |
| | | return list; |
| | | } |
| | | /** |
| | | * 字符串转list |
| | | * |
| | | * @param str 字符串 |
| | | * @param sep 分隔符 |
| | | * @param filterBlank 过滤纯空白 |
| | | * @param trim 去掉首尾空白 |
| | | * @return list集合 |
| | | */ |
| | | public static List<String> str2List(String str, String sep, boolean filterBlank, boolean trim) { |
| | | List<String> list = new ArrayList<>(); |
| | | if (isEmpty(str)) { |
| | | return list; |
| | | } |
| | | |
| | | // 过滤空白字符串 |
| | | if (filterBlank && isBlank(str)) { |
| | | return list; |
| | | } |
| | | String[] split = str.split(sep); |
| | | for (String string : split) { |
| | | if (filterBlank && isBlank(string)) { |
| | | continue; |
| | | } |
| | | if (trim) { |
| | | string = trim(string); |
| | | } |
| | | list.add(string); |
| | | } |
| | | // 过滤空白字符串 |
| | | if (filterBlank && isBlank(str)) { |
| | | return list; |
| | | } |
| | | String[] split = str.split(sep); |
| | | for (String string : split) { |
| | | if (filterBlank && isBlank(string)) { |
| | | continue; |
| | | } |
| | | if (trim) { |
| | | string = trim(string); |
| | | } |
| | | list.add(string); |
| | | } |
| | | |
| | | return list; |
| | | } |
| | | return list; |
| | | } |
| | | |
| | | /** |
| | | * 查找指定字符串是否包含指定字符串列表中的任意一个字符串同时串忽略大小写 |
| | | * |
| | | * @param cs 指定字符串 |
| | | * @param searchCharSequences 需要检查的字符串数组 |
| | | * @return 是否包含任意一个字符串 |
| | | */ |
| | | public static boolean containsAnyIgnoreCase(CharSequence cs, CharSequence... searchCharSequences) { |
| | | return StrUtil.containsAnyIgnoreCase(cs, searchCharSequences); |
| | | } |
| | | /** |
| | | * 查找指定字符串是否包含指定字符串列表中的任意一个字符串同时串忽略大小写 |
| | | * |
| | | * @param cs 指定字符串 |
| | | * @param searchCharSequences 需要检查的字符串数组 |
| | | * @return 是否包含任意一个字符串 |
| | | */ |
| | | public static boolean containsAnyIgnoreCase(CharSequence cs, CharSequence... searchCharSequences) { |
| | | return StrUtil.containsAnyIgnoreCase(cs, searchCharSequences); |
| | | } |
| | | |
| | | /** |
| | | * 驼峰转下划线命名 |
| | | */ |
| | | public static String toUnderScoreCase(String str) { |
| | | return StrUtil.toUnderlineCase(str); |
| | | } |
| | | /** |
| | | * 驼峰转下划线命名 |
| | | */ |
| | | public static String toUnderScoreCase(String str) { |
| | | return StrUtil.toUnderlineCase(str); |
| | | } |
| | | |
| | | /** |
| | | * 是否包含字符串 |
| | | * |
| | | * @param str 验证字符串 |
| | | * @param strs 字符串组 |
| | | * @return 包含返回true |
| | | */ |
| | | public static boolean inStringIgnoreCase(String str, String... strs) { |
| | | return StrUtil.equalsAnyIgnoreCase(str, strs); |
| | | } |
| | | /** |
| | | * 是否包含字符串 |
| | | * |
| | | * @param str 验证字符串 |
| | | * @param strs 字符串组 |
| | | * @return 包含返回true |
| | | */ |
| | | public static boolean inStringIgnoreCase(String str, String... strs) { |
| | | return StrUtil.equalsAnyIgnoreCase(str, strs); |
| | | } |
| | | |
| | | /** |
| | | * 将下划线大写方式命名的字符串转换为驼峰式。如果转换前的下划线大写方式命名的字符串为空,则返回空字符串。 例如:HELLO_WORLD->HelloWorld |
| | | * |
| | | * @param name 转换前的下划线大写方式命名的字符串 |
| | | * @return 转换后的驼峰式命名的字符串 |
| | | */ |
| | | public static String convertToCamelCase(String name) { |
| | | return StrUtil.upperFirst(StrUtil.toCamelCase(name)); |
| | | } |
| | | /** |
| | | * 将下划线大写方式命名的字符串转换为驼峰式。如果转换前的下划线大写方式命名的字符串为空,则返回空字符串。 例如:HELLO_WORLD->HelloWorld |
| | | * |
| | | * @param name 转换前的下划线大写方式命名的字符串 |
| | | * @return 转换后的驼峰式命名的字符串 |
| | | */ |
| | | public static String convertToCamelCase(String name) { |
| | | return StrUtil.upperFirst(StrUtil.toCamelCase(name)); |
| | | } |
| | | |
| | | /** |
| | | * 驼峰式命名法 例如:user_name->userName |
| | | */ |
| | | public static String toCamelCase(String s) { |
| | | return StrUtil.toCamelCase(s); |
| | | } |
| | | /** |
| | | * 驼峰式命名法 例如:user_name->userName |
| | | */ |
| | | public static String toCamelCase(String s) { |
| | | return StrUtil.toCamelCase(s); |
| | | } |
| | | |
| | | /** |
| | | * 查找指定字符串是否匹配指定字符串列表中的任意一个字符串 |
| | | * |
| | | * @param str 指定字符串 |
| | | * @param strs 需要检查的字符串数组 |
| | | * @return 是否匹配 |
| | | */ |
| | | public static boolean matches(String str, List<String> strs) { |
| | | if (isEmpty(str) || isEmpty(strs)) { |
| | | return false; |
| | | } |
| | | for (String pattern : strs) { |
| | | if (isMatch(pattern, str)) { |
| | | return true; |
| | | } |
| | | } |
| | | return false; |
| | | } |
| | | /** |
| | | * 查找指定字符串是否匹配指定字符串列表中的任意一个字符串 |
| | | * |
| | | * @param str 指定字符串 |
| | | * @param strs 需要检查的字符串数组 |
| | | * @return 是否匹配 |
| | | */ |
| | | public static boolean matches(String str, List<String> strs) { |
| | | if (isEmpty(str) || isEmpty(strs)) { |
| | | return false; |
| | | } |
| | | for (String pattern : strs) { |
| | | if (isMatch(pattern, str)) { |
| | | return true; |
| | | } |
| | | } |
| | | return false; |
| | | } |
| | | |
| | | /** |
| | | * 判断url是否与规则配置: |
| | | * ? 表示单个字符; |
| | | * * 表示一层路径内的任意字符串,不可跨层级; |
| | | * ** 表示任意层路径; |
| | | * |
| | | * @param pattern 匹配规则 |
| | | * @param url 需要匹配的url |
| | | * @return |
| | | */ |
| | | public static boolean isMatch(String pattern, String url) { |
| | | /** |
| | | * 判断url是否与规则配置: |
| | | * ? 表示单个字符; |
| | | * * 表示一层路径内的任意字符串,不可跨层级; |
| | | * ** 表示任意层路径; |
| | | * |
| | | * @param pattern 匹配规则 |
| | | * @param url 需要匹配的url |
| | | * @return |
| | | */ |
| | | public static boolean isMatch(String pattern, String url) { |
| | | AntPathMatcher matcher = new AntPathMatcher(); |
| | | return matcher.match(pattern, url); |
| | | } |
| | | } |
| | | |
| | | @SuppressWarnings("unchecked") |
| | | public static <T> T cast(Object obj) { |
| | | return (T) obj; |
| | | } |
| | | @SuppressWarnings("unchecked") |
| | | public static <T> T cast(Object obj) { |
| | | return (T) obj; |
| | | } |
| | | } |
| | |
| | | @NoArgsConstructor(access = AccessLevel.PRIVATE) |
| | | public class ValidatorUtils { |
| | | |
| | | private static final Validator VALID = SpringUtils.getBean(Validator.class); |
| | | private static final Validator VALID = SpringUtils.getBean(Validator.class); |
| | | |
| | | public static <T> void validate(T object, Class<?>... groups) { |
| | | public static <T> void validate(T object, Class<?>... groups) { |
| | | Set<ConstraintViolation<T>> validate = VALID.validate(object, groups); |
| | | if (!validate.isEmpty()) { |
| | | throw new ConstraintViolationException("参数校验异常", validate); |
| | |
| | | @RequestMapping("/demo/i18n") |
| | | public class TestI18nController { |
| | | |
| | | /** |
| | | * 通过code获取国际化内容 |
| | | * code为 messages.properties 中的 key |
| | | * |
| | | * 测试使用 user.register.success |
| | | */ |
| | | @ApiOperation("通过code获取国际化内容") |
| | | @GetMapping() |
| | | public AjaxResult<Void> get(@ApiParam("国际化code") String code) { |
| | | return AjaxResult.success(MessageUtils.message(code)); |
| | | } |
| | | /** |
| | | * 通过code获取国际化内容 |
| | | * code为 messages.properties 中的 key |
| | | * <p> |
| | | * 测试使用 user.register.success |
| | | */ |
| | | @ApiOperation("通过code获取国际化内容") |
| | | @GetMapping() |
| | | public AjaxResult<Void> get(@ApiParam("国际化code") String code) { |
| | | return AjaxResult.success(MessageUtils.message(code)); |
| | | } |
| | | |
| | | /** |
| | | * Validator 校验国际化 |
| | | * 不传值 分别查看异常返回 |
| | | * |
| | | * <p> |
| | | * 测试使用 not.null |
| | | */ |
| | | @ApiOperation("Validator 校验国际化") |
| | |
| | | /** |
| | | * Bean 校验国际化 |
| | | * 不传值 分别查看异常返回 |
| | | * |
| | | * <p> |
| | | * 测试使用 not.null |
| | | */ |
| | | @ApiOperation("Bean 校验国际化") |
| | |
| | | @TableName("test_demo") |
| | | public class TestDemo extends BaseEntity { |
| | | |
| | | private static final long serialVersionUID=1L; |
| | | private static final long serialVersionUID = 1L; |
| | | |
| | | |
| | | /** |
| | | * 主键 |
| | | */ |
| | | /** |
| | | * 主键 |
| | | */ |
| | | @TableId(value = "id") |
| | | private Long id; |
| | | |
| | |
| | | /** |
| | | * 排序号 |
| | | */ |
| | | @OrderBy(asc = false, sort = 1) |
| | | @OrderBy(asc = false, sort = 1) |
| | | private Long orderNum; |
| | | |
| | | /** |
| | |
| | | @TableName("test_tree") |
| | | public class TestTree extends TreeEntity { |
| | | |
| | | private static final long serialVersionUID=1L; |
| | | private static final long serialVersionUID = 1L; |
| | | |
| | | |
| | | /** |
| | |
| | | /** |
| | | * 主键 |
| | | */ |
| | | @ApiModelProperty("主键") |
| | | @NotNull(message = "主键不能为空", groups = { EditGroup.class }) |
| | | @ApiModelProperty("主键") |
| | | @NotNull(message = "主键不能为空", groups = {EditGroup.class}) |
| | | private Long id; |
| | | |
| | | /** |
| | | * 部门id |
| | | */ |
| | | @ApiModelProperty("部门id") |
| | | @NotNull(message = "部门id不能为空", groups = { AddGroup.class, EditGroup.class }) |
| | | @ApiModelProperty("部门id") |
| | | @NotNull(message = "部门id不能为空", groups = {AddGroup.class, EditGroup.class}) |
| | | private Long deptId; |
| | | |
| | | /** |
| | | * 用户id |
| | | */ |
| | | @ApiModelProperty("用户id") |
| | | @NotNull(message = "用户id不能为空", groups = { AddGroup.class, EditGroup.class }) |
| | | @ApiModelProperty("用户id") |
| | | @NotNull(message = "用户id不能为空", groups = {AddGroup.class, EditGroup.class}) |
| | | private Long userId; |
| | | |
| | | /** |
| | | * 排序号 |
| | | */ |
| | | @ApiModelProperty("排序号") |
| | | @NotNull(message = "排序号不能为空", groups = { AddGroup.class, EditGroup.class }) |
| | | @ApiModelProperty("排序号") |
| | | @NotNull(message = "排序号不能为空", groups = {AddGroup.class, EditGroup.class}) |
| | | private Long orderNum; |
| | | |
| | | /** |
| | | * key键 |
| | | */ |
| | | @ApiModelProperty("key键") |
| | | @NotBlank(message = "key键不能为空", groups = { AddGroup.class, EditGroup.class }) |
| | | @ApiModelProperty("key键") |
| | | @NotBlank(message = "key键不能为空", groups = {AddGroup.class, EditGroup.class}) |
| | | private String testKey; |
| | | |
| | | /** |
| | | * 值 |
| | | */ |
| | | @ApiModelProperty("值") |
| | | @NotBlank(message = "值不能为空", groups = { AddGroup.class, EditGroup.class }) |
| | | @ApiModelProperty("值") |
| | | @NotBlank(message = "值不能为空", groups = {AddGroup.class, EditGroup.class}) |
| | | private String value; |
| | | |
| | | } |
| | |
| | | /** |
| | | * 主键 |
| | | */ |
| | | @ApiModelProperty("主键") |
| | | @NotNull(message = "主键不能为空", groups = { EditGroup.class }) |
| | | @ApiModelProperty("主键") |
| | | @NotNull(message = "主键不能为空", groups = {EditGroup.class}) |
| | | private Long id; |
| | | |
| | | /** |
| | | * 部门id |
| | | */ |
| | | @ApiModelProperty("部门id") |
| | | @NotNull(message = "部门id不能为空", groups = { AddGroup.class, EditGroup.class }) |
| | | @ApiModelProperty("部门id") |
| | | @NotNull(message = "部门id不能为空", groups = {AddGroup.class, EditGroup.class}) |
| | | private Long deptId; |
| | | |
| | | /** |
| | | * 用户id |
| | | */ |
| | | @ApiModelProperty("用户id") |
| | | @NotNull(message = "用户id不能为空", groups = { AddGroup.class, EditGroup.class }) |
| | | @ApiModelProperty("用户id") |
| | | @NotNull(message = "用户id不能为空", groups = {AddGroup.class, EditGroup.class}) |
| | | private Long userId; |
| | | |
| | | /** |
| | | * 树节点名 |
| | | */ |
| | | @ApiModelProperty("树节点名") |
| | | @NotBlank(message = "树节点名不能为空", groups = { AddGroup.class, EditGroup.class }) |
| | | @ApiModelProperty("树节点名") |
| | | @NotBlank(message = "树节点名不能为空", groups = {AddGroup.class, EditGroup.class}) |
| | | private String treeName; |
| | | |
| | | } |
| | |
| | | import java.util.Date; |
| | | |
| | | |
| | | |
| | | /** |
| | | * 测试单表视图对象 test_demo |
| | | * |
| | |
| | | @ExcelIgnoreUnannotated |
| | | public class TestDemoVo { |
| | | |
| | | private static final long serialVersionUID = 1L; |
| | | private static final long serialVersionUID = 1L; |
| | | |
| | | /** |
| | | * 主键 |
| | | /** |
| | | * 主键 |
| | | */ |
| | | @ExcelProperty(value = "主键") |
| | | @ApiModelProperty("主键") |
| | | private Long id; |
| | | @ExcelProperty(value = "主键") |
| | | @ApiModelProperty("主键") |
| | | private Long id; |
| | | |
| | | /** |
| | | * 部门id |
| | | */ |
| | | @ExcelProperty(value = "部门id") |
| | | @ApiModelProperty("部门id") |
| | | private Long deptId; |
| | | @ExcelProperty(value = "部门id") |
| | | @ApiModelProperty("部门id") |
| | | private Long deptId; |
| | | |
| | | /** |
| | | * 用户id |
| | | */ |
| | | @ExcelProperty(value = "用户id") |
| | | @ApiModelProperty("用户id") |
| | | private Long userId; |
| | | @ExcelProperty(value = "用户id") |
| | | @ApiModelProperty("用户id") |
| | | private Long userId; |
| | | |
| | | /** |
| | | * 排序号 |
| | | */ |
| | | @ExcelProperty(value = "排序号") |
| | | @ApiModelProperty("排序号") |
| | | private Long orderNum; |
| | | @ExcelProperty(value = "排序号") |
| | | @ApiModelProperty("排序号") |
| | | private Long orderNum; |
| | | |
| | | /** |
| | | * key键 |
| | | */ |
| | | @ExcelProperty(value = "key键") |
| | | @ApiModelProperty("key键") |
| | | private String testKey; |
| | | @ExcelProperty(value = "key键") |
| | | @ApiModelProperty("key键") |
| | | private String testKey; |
| | | |
| | | /** |
| | | * 值 |
| | | */ |
| | | @ExcelProperty(value = "值") |
| | | @ApiModelProperty("值") |
| | | private String value; |
| | | @ExcelProperty(value = "值") |
| | | @ApiModelProperty("值") |
| | | private String value; |
| | | |
| | | /** |
| | | * 创建时间 |
| | | */ |
| | | @ExcelProperty(value = "创建时间") |
| | | @ApiModelProperty("创建时间") |
| | | private Date createTime; |
| | | @ExcelProperty(value = "创建时间") |
| | | @ApiModelProperty("创建时间") |
| | | private Date createTime; |
| | | |
| | | /** |
| | | * 创建人 |
| | | */ |
| | | @ExcelProperty(value = "创建人") |
| | | @ApiModelProperty("创建人") |
| | | private String createBy; |
| | | @ExcelProperty(value = "创建人") |
| | | @ApiModelProperty("创建人") |
| | | private String createBy; |
| | | |
| | | /** |
| | | * 更新时间 |
| | | */ |
| | | @ExcelProperty(value = "更新时间") |
| | | @ApiModelProperty("更新时间") |
| | | private Date updateTime; |
| | | @ExcelProperty(value = "更新时间") |
| | | @ApiModelProperty("更新时间") |
| | | private Date updateTime; |
| | | |
| | | /** |
| | | * 更新人 |
| | | */ |
| | | @ExcelProperty(value = "更新人") |
| | | @ApiModelProperty("更新人") |
| | | private String updateBy; |
| | | @ExcelProperty(value = "更新人") |
| | | @ApiModelProperty("更新人") |
| | | private String updateBy; |
| | | |
| | | |
| | | } |
| | |
| | | import java.util.Date; |
| | | |
| | | |
| | | |
| | | /** |
| | | * 测试树表视图对象 test_tree |
| | | * |
| | |
| | | @ExcelIgnoreUnannotated |
| | | public class TestTreeVo { |
| | | |
| | | private static final long serialVersionUID = 1L; |
| | | private static final long serialVersionUID = 1L; |
| | | |
| | | /** |
| | | * 主键 |
| | | /** |
| | | * 主键 |
| | | */ |
| | | @ApiModelProperty("主键") |
| | | private Long id; |
| | | @ApiModelProperty("主键") |
| | | private Long id; |
| | | |
| | | /** |
| | | * 父id |
| | | */ |
| | | @ExcelProperty(value = "父id") |
| | | @ApiModelProperty("父id") |
| | | private Long parentId; |
| | | @ExcelProperty(value = "父id") |
| | | @ApiModelProperty("父id") |
| | | private Long parentId; |
| | | |
| | | /** |
| | | * 部门id |
| | | */ |
| | | @ExcelProperty(value = "部门id") |
| | | @ApiModelProperty("部门id") |
| | | private Long deptId; |
| | | @ExcelProperty(value = "部门id") |
| | | @ApiModelProperty("部门id") |
| | | private Long deptId; |
| | | |
| | | /** |
| | | * 用户id |
| | | */ |
| | | @ExcelProperty(value = "用户id") |
| | | @ApiModelProperty("用户id") |
| | | private Long userId; |
| | | @ExcelProperty(value = "用户id") |
| | | @ApiModelProperty("用户id") |
| | | private Long userId; |
| | | |
| | | /** |
| | | * 树节点名 |
| | | */ |
| | | @ExcelProperty(value = "树节点名") |
| | | @ApiModelProperty("树节点名") |
| | | private String treeName; |
| | | @ExcelProperty(value = "树节点名") |
| | | @ApiModelProperty("树节点名") |
| | | private String treeName; |
| | | |
| | | /** |
| | | * 创建时间 |
| | | */ |
| | | @ExcelProperty(value = "创建时间") |
| | | @ApiModelProperty("创建时间") |
| | | private Date createTime; |
| | | @ExcelProperty(value = "创建时间") |
| | | @ApiModelProperty("创建时间") |
| | | private Date createTime; |
| | | |
| | | |
| | | } |
| | |
| | | package com.ruoyi.demo.service; |
| | | |
| | | import com.ruoyi.common.core.domain.PageQuery; |
| | | import com.ruoyi.demo.domain.TestDemo; |
| | | import com.ruoyi.demo.domain.vo.TestDemoVo; |
| | | import com.ruoyi.demo.domain.bo.TestDemoBo; |
| | | import com.ruoyi.common.core.mybatisplus.core.IServicePlus; |
| | | import com.ruoyi.common.core.page.TableDataInfo; |
| | | import com.ruoyi.demo.domain.TestDemo; |
| | | import com.ruoyi.demo.domain.bo.TestDemoBo; |
| | | import com.ruoyi.demo.domain.vo.TestDemoVo; |
| | | |
| | | import java.util.Collection; |
| | | import java.util.List; |
| | |
| | | */ |
| | | public interface ITestDemoService extends IServicePlus<TestDemo, TestDemoVo> { |
| | | |
| | | /** |
| | | * 查询单个 |
| | | * @return |
| | | */ |
| | | TestDemoVo queryById(Long id); |
| | | |
| | | /** |
| | | * 查询列表 |
| | | */ |
| | | TableDataInfo<TestDemoVo> queryPageList(TestDemoBo bo, PageQuery pageQuery); |
| | | |
| | | /** |
| | | * 自定义分页查询 |
| | | */ |
| | | TableDataInfo<TestDemoVo> customPageList(TestDemoBo bo, PageQuery pageQuery); |
| | | /** |
| | | * 查询单个 |
| | | * |
| | | * @return |
| | | */ |
| | | TestDemoVo queryById(Long id); |
| | | |
| | | /** |
| | | * 查询列表 |
| | | */ |
| | | List<TestDemoVo> queryList(TestDemoBo bo); |
| | | * 查询列表 |
| | | */ |
| | | TableDataInfo<TestDemoVo> queryPageList(TestDemoBo bo, PageQuery pageQuery); |
| | | |
| | | /** |
| | | * 根据新增业务对象插入测试单表 |
| | | * @param bo 测试单表新增业务对象 |
| | | * @return |
| | | */ |
| | | Boolean insertByBo(TestDemoBo bo); |
| | | /** |
| | | * 自定义分页查询 |
| | | */ |
| | | TableDataInfo<TestDemoVo> customPageList(TestDemoBo bo, PageQuery pageQuery); |
| | | |
| | | /** |
| | | * 根据编辑业务对象修改测试单表 |
| | | * @param bo 测试单表编辑业务对象 |
| | | * @return |
| | | */ |
| | | Boolean updateByBo(TestDemoBo bo); |
| | | /** |
| | | * 查询列表 |
| | | */ |
| | | List<TestDemoVo> queryList(TestDemoBo bo); |
| | | |
| | | /** |
| | | * 校验并删除数据 |
| | | * @param ids 主键集合 |
| | | * @param isValid 是否校验,true-删除前校验,false-不校验 |
| | | * @return |
| | | */ |
| | | Boolean deleteWithValidByIds(Collection<Long> ids, Boolean isValid); |
| | | /** |
| | | * 根据新增业务对象插入测试单表 |
| | | * |
| | | * @param bo 测试单表新增业务对象 |
| | | * @return |
| | | */ |
| | | Boolean insertByBo(TestDemoBo bo); |
| | | |
| | | /** |
| | | * 根据编辑业务对象修改测试单表 |
| | | * |
| | | * @param bo 测试单表编辑业务对象 |
| | | * @return |
| | | */ |
| | | Boolean updateByBo(TestDemoBo bo); |
| | | |
| | | /** |
| | | * 校验并删除数据 |
| | | * |
| | | * @param ids 主键集合 |
| | | * @param isValid 是否校验,true-删除前校验,false-不校验 |
| | | * @return |
| | | */ |
| | | Boolean deleteWithValidByIds(Collection<Long> ids, Boolean isValid); |
| | | } |
| | |
| | | package com.ruoyi.demo.service; |
| | | |
| | | import com.ruoyi.demo.domain.TestTree; |
| | | import com.ruoyi.demo.domain.vo.TestTreeVo; |
| | | import com.ruoyi.demo.domain.bo.TestTreeBo; |
| | | import com.ruoyi.common.core.mybatisplus.core.IServicePlus; |
| | | import com.ruoyi.demo.domain.TestTree; |
| | | import com.ruoyi.demo.domain.bo.TestTreeBo; |
| | | import com.ruoyi.demo.domain.vo.TestTreeVo; |
| | | |
| | | import java.util.Collection; |
| | | import java.util.List; |
| | |
| | | * @date 2021-07-26 |
| | | */ |
| | | public interface ITestTreeService extends IServicePlus<TestTree, TestTreeVo> { |
| | | /** |
| | | * 查询单个 |
| | | * @return |
| | | */ |
| | | TestTreeVo queryById(Long id); |
| | | /** |
| | | * 查询单个 |
| | | * |
| | | * @return |
| | | */ |
| | | TestTreeVo queryById(Long id); |
| | | |
| | | /** |
| | | * 查询列表 |
| | | */ |
| | | List<TestTreeVo> queryList(TestTreeBo bo); |
| | | /** |
| | | * 查询列表 |
| | | */ |
| | | List<TestTreeVo> queryList(TestTreeBo bo); |
| | | |
| | | /** |
| | | * 根据新增业务对象插入测试树表 |
| | | * @param bo 测试树表新增业务对象 |
| | | * @return |
| | | */ |
| | | Boolean insertByBo(TestTreeBo bo); |
| | | /** |
| | | * 根据新增业务对象插入测试树表 |
| | | * |
| | | * @param bo 测试树表新增业务对象 |
| | | * @return |
| | | */ |
| | | Boolean insertByBo(TestTreeBo bo); |
| | | |
| | | /** |
| | | * 根据编辑业务对象修改测试树表 |
| | | * @param bo 测试树表编辑业务对象 |
| | | * @return |
| | | */ |
| | | Boolean updateByBo(TestTreeBo bo); |
| | | /** |
| | | * 根据编辑业务对象修改测试树表 |
| | | * |
| | | * @param bo 测试树表编辑业务对象 |
| | | * @return |
| | | */ |
| | | Boolean updateByBo(TestTreeBo bo); |
| | | |
| | | /** |
| | | * 校验并删除数据 |
| | | * @param ids 主键集合 |
| | | * @param isValid 是否校验,true-删除前校验,false-不校验 |
| | | * @return |
| | | */ |
| | | Boolean deleteWithValidByIds(Collection<Long> ids, Boolean isValid); |
| | | /** |
| | | * 校验并删除数据 |
| | | * |
| | | * @param ids 主键集合 |
| | | * @param isValid 是否校验,true-删除前校验,false-不校验 |
| | | * @return |
| | | */ |
| | | Boolean deleteWithValidByIds(Collection<Long> ids, Boolean isValid); |
| | | } |
| | |
| | | @Service |
| | | public class TestDemoServiceImpl extends ServicePlusImpl<TestDemoMapper, TestDemo, TestDemoVo> implements ITestDemoService { |
| | | |
| | | @Override |
| | | public TestDemoVo queryById(Long id) { |
| | | return getVoById(id); |
| | | } |
| | | @Override |
| | | public TestDemoVo queryById(Long id) { |
| | | return getVoById(id); |
| | | } |
| | | |
| | | @Override |
| | | public TableDataInfo<TestDemoVo> queryPageList(TestDemoBo bo, PageQuery pageQuery) { |
| | | @Override |
| | | public TableDataInfo<TestDemoVo> queryPageList(TestDemoBo bo, PageQuery pageQuery) { |
| | | LambdaQueryWrapper<TestDemo> lqw = buildQueryWrapper(bo); |
| | | Page<TestDemoVo> result = pageVo(pageQuery.build(), lqw); |
| | | return TableDataInfo.build(result); |
| | | } |
| | | return TableDataInfo.build(result); |
| | | } |
| | | |
| | | /** |
| | | * 自定义分页查询 |
| | | */ |
| | | @Override |
| | | public TableDataInfo<TestDemoVo> customPageList(TestDemoBo bo, PageQuery pageQuery) { |
| | | /** |
| | | * 自定义分页查询 |
| | | */ |
| | | @Override |
| | | public TableDataInfo<TestDemoVo> customPageList(TestDemoBo bo, PageQuery pageQuery) { |
| | | LambdaQueryWrapper<TestDemo> lqw = buildQueryWrapper(bo); |
| | | Page<TestDemoVo> result = baseMapper.customPageList(pageQuery.build(), lqw); |
| | | return TableDataInfo.build(result); |
| | | } |
| | | Page<TestDemoVo> result = baseMapper.customPageList(pageQuery.build(), lqw); |
| | | return TableDataInfo.build(result); |
| | | } |
| | | |
| | | @Override |
| | | public List<TestDemoVo> queryList(TestDemoBo bo) { |
| | | return listVo(buildQueryWrapper(bo)); |
| | | } |
| | | @Override |
| | | public List<TestDemoVo> queryList(TestDemoBo bo) { |
| | | return listVo(buildQueryWrapper(bo)); |
| | | } |
| | | |
| | | private LambdaQueryWrapper<TestDemo> buildQueryWrapper(TestDemoBo bo) { |
| | | Map<String, Object> params = bo.getParams(); |
| | | LambdaQueryWrapper<TestDemo> lqw = Wrappers.lambdaQuery(); |
| | | lqw.like(StringUtils.isNotBlank(bo.getTestKey()), TestDemo::getTestKey, bo.getTestKey()); |
| | | lqw.eq(StringUtils.isNotBlank(bo.getValue()), TestDemo::getValue, bo.getValue()); |
| | | lqw.between(params.get("beginCreateTime") != null && params.get("endCreateTime") != null, |
| | | TestDemo::getCreateTime, params.get("beginCreateTime"), params.get("endCreateTime")); |
| | | return lqw; |
| | | } |
| | | private LambdaQueryWrapper<TestDemo> buildQueryWrapper(TestDemoBo bo) { |
| | | Map<String, Object> params = bo.getParams(); |
| | | LambdaQueryWrapper<TestDemo> lqw = Wrappers.lambdaQuery(); |
| | | lqw.like(StringUtils.isNotBlank(bo.getTestKey()), TestDemo::getTestKey, bo.getTestKey()); |
| | | lqw.eq(StringUtils.isNotBlank(bo.getValue()), TestDemo::getValue, bo.getValue()); |
| | | lqw.between(params.get("beginCreateTime") != null && params.get("endCreateTime") != null, |
| | | TestDemo::getCreateTime, params.get("beginCreateTime"), params.get("endCreateTime")); |
| | | return lqw; |
| | | } |
| | | |
| | | @Override |
| | | public Boolean insertByBo(TestDemoBo bo) { |
| | | TestDemo add = BeanUtil.toBean(bo, TestDemo.class); |
| | | validEntityBeforeSave(add); |
| | | boolean flag = save(add); |
| | | if (flag) { |
| | | bo.setId(add.getId()); |
| | | } |
| | | return flag; |
| | | } |
| | | @Override |
| | | public Boolean insertByBo(TestDemoBo bo) { |
| | | TestDemo add = BeanUtil.toBean(bo, TestDemo.class); |
| | | validEntityBeforeSave(add); |
| | | boolean flag = save(add); |
| | | if (flag) { |
| | | bo.setId(add.getId()); |
| | | } |
| | | return flag; |
| | | } |
| | | |
| | | @Override |
| | | public Boolean updateByBo(TestDemoBo bo) { |
| | | TestDemo update = BeanUtil.toBean(bo, TestDemo.class); |
| | | validEntityBeforeSave(update); |
| | | return updateById(update); |
| | | } |
| | | @Override |
| | | public Boolean updateByBo(TestDemoBo bo) { |
| | | TestDemo update = BeanUtil.toBean(bo, TestDemo.class); |
| | | validEntityBeforeSave(update); |
| | | return updateById(update); |
| | | } |
| | | |
| | | /** |
| | | * 保存前的数据校验 |
| | | * |
| | | * @param entity 实体类数据 |
| | | */ |
| | | private void validEntityBeforeSave(TestDemo entity) { |
| | | //TODO 做一些数据校验,如唯一约束 |
| | | } |
| | | /** |
| | | * 保存前的数据校验 |
| | | * |
| | | * @param entity 实体类数据 |
| | | */ |
| | | private void validEntityBeforeSave(TestDemo entity) { |
| | | //TODO 做一些数据校验,如唯一约束 |
| | | } |
| | | |
| | | @Override |
| | | public Boolean deleteWithValidByIds(Collection<Long> ids, Boolean isValid) { |
| | | if (isValid) { |
| | | //TODO 做一些业务上的校验,判断是否需要校验 |
| | | } |
| | | return removeByIds(ids); |
| | | } |
| | | @Override |
| | | public Boolean deleteWithValidByIds(Collection<Long> ids, Boolean isValid) { |
| | | if (isValid) { |
| | | //TODO 做一些业务上的校验,判断是否需要校验 |
| | | } |
| | | return removeByIds(ids); |
| | | } |
| | | } |
| | |
| | | @Service |
| | | public class TestTreeServiceImpl extends ServicePlusImpl<TestTreeMapper, TestTree, TestTreeVo> implements ITestTreeService { |
| | | |
| | | @Override |
| | | public TestTreeVo queryById(Long id) { |
| | | return getVoById(id); |
| | | } |
| | | @Override |
| | | public TestTreeVo queryById(Long id) { |
| | | return getVoById(id); |
| | | } |
| | | |
| | | // @DS("slave") // 切换从库查询 |
| | | @Override |
| | | public List<TestTreeVo> queryList(TestTreeBo bo) { |
| | | // @DS("slave") // 切换从库查询 |
| | | @Override |
| | | public List<TestTreeVo> queryList(TestTreeBo bo) { |
| | | LambdaQueryWrapper<TestTree> lqw = buildQueryWrapper(bo); |
| | | return listVo(lqw); |
| | | } |
| | | } |
| | | |
| | | private LambdaQueryWrapper<TestTree> buildQueryWrapper(TestTreeBo bo) { |
| | | Map<String, Object> params = bo.getParams(); |
| | | LambdaQueryWrapper<TestTree> lqw = Wrappers.lambdaQuery(); |
| | | lqw.like(StringUtils.isNotBlank(bo.getTreeName()), TestTree::getTreeName, bo.getTreeName()); |
| | | lqw.between(params.get("beginCreateTime") != null && params.get("endCreateTime") != null, |
| | | TestTree::getCreateTime, params.get("beginCreateTime"), params.get("endCreateTime")); |
| | | return lqw; |
| | | } |
| | | private LambdaQueryWrapper<TestTree> buildQueryWrapper(TestTreeBo bo) { |
| | | Map<String, Object> params = bo.getParams(); |
| | | LambdaQueryWrapper<TestTree> lqw = Wrappers.lambdaQuery(); |
| | | lqw.like(StringUtils.isNotBlank(bo.getTreeName()), TestTree::getTreeName, bo.getTreeName()); |
| | | lqw.between(params.get("beginCreateTime") != null && params.get("endCreateTime") != null, |
| | | TestTree::getCreateTime, params.get("beginCreateTime"), params.get("endCreateTime")); |
| | | return lqw; |
| | | } |
| | | |
| | | @Override |
| | | public Boolean insertByBo(TestTreeBo bo) { |
| | | TestTree add = BeanUtil.toBean(bo, TestTree.class); |
| | | validEntityBeforeSave(add); |
| | | boolean flag = save(add); |
| | | if (flag) { |
| | | bo.setId(add.getId()); |
| | | } |
| | | return flag; |
| | | } |
| | | @Override |
| | | public Boolean insertByBo(TestTreeBo bo) { |
| | | TestTree add = BeanUtil.toBean(bo, TestTree.class); |
| | | validEntityBeforeSave(add); |
| | | boolean flag = save(add); |
| | | if (flag) { |
| | | bo.setId(add.getId()); |
| | | } |
| | | return flag; |
| | | } |
| | | |
| | | @Override |
| | | public Boolean updateByBo(TestTreeBo bo) { |
| | | TestTree update = BeanUtil.toBean(bo, TestTree.class); |
| | | validEntityBeforeSave(update); |
| | | return updateById(update); |
| | | } |
| | | @Override |
| | | public Boolean updateByBo(TestTreeBo bo) { |
| | | TestTree update = BeanUtil.toBean(bo, TestTree.class); |
| | | validEntityBeforeSave(update); |
| | | return updateById(update); |
| | | } |
| | | |
| | | /** |
| | | * 保存前的数据校验 |
| | | * |
| | | * @param entity 实体类数据 |
| | | */ |
| | | private void validEntityBeforeSave(TestTree entity) { |
| | | //TODO 做一些数据校验,如唯一约束 |
| | | } |
| | | /** |
| | | * 保存前的数据校验 |
| | | * |
| | | * @param entity 实体类数据 |
| | | */ |
| | | private void validEntityBeforeSave(TestTree entity) { |
| | | //TODO 做一些数据校验,如唯一约束 |
| | | } |
| | | |
| | | @Override |
| | | public Boolean deleteWithValidByIds(Collection<Long> ids, Boolean isValid) { |
| | | if (isValid) { |
| | | //TODO 做一些业务上的校验,判断是否需要校验 |
| | | } |
| | | return removeByIds(ids); |
| | | } |
| | | @Override |
| | | public Boolean deleteWithValidByIds(Collection<Long> ids, Boolean isValid) { |
| | | if (isValid) { |
| | | //TODO 做一些业务上的校验,判断是否需要校验 |
| | | } |
| | | return removeByIds(ids); |
| | | } |
| | | } |
| | |
| | | @SpringBootApplication |
| | | public class MonitorAdminApplication { |
| | | |
| | | public static void main(String[] args) { |
| | | SpringApplication.run(MonitorAdminApplication.class, args); |
| | | System.out.println("Admin 监控启动成功" ); |
| | | } |
| | | public static void main(String[] args) { |
| | | SpringApplication.run(MonitorAdminApplication.class, args); |
| | | System.out.println("Admin 监控启动成功"); |
| | | } |
| | | |
| | | } |
| | |
| | | @EnableWebSecurity |
| | | public class SecurityConfig extends WebSecurityConfigurerAdapter { |
| | | |
| | | private final String adminContextPath; |
| | | private final String adminContextPath; |
| | | |
| | | public SecurityConfig(AdminServerProperties adminServerProperties) { |
| | | this.adminContextPath = adminServerProperties.getContextPath(); |
| | | } |
| | | public SecurityConfig(AdminServerProperties adminServerProperties) { |
| | | this.adminContextPath = adminServerProperties.getContextPath(); |
| | | } |
| | | |
| | | @Override |
| | | protected void configure(HttpSecurity httpSecurity) throws Exception { |
| | | SavedRequestAwareAuthenticationSuccessHandler successHandler = new SavedRequestAwareAuthenticationSuccessHandler(); |
| | | successHandler.setTargetUrlParameter("redirectTo"); |
| | | successHandler.setDefaultTargetUrl(adminContextPath + "/"); |
| | | // admin监控 用户鉴权 |
| | | httpSecurity.authorizeRequests() |
| | | //授予对所有静态资产和登录页面的公共访问权限。 |
| | | .antMatchers(adminContextPath + "/assets/**").permitAll() |
| | | .antMatchers(adminContextPath + "/login").permitAll() |
| | | @Override |
| | | protected void configure(HttpSecurity httpSecurity) throws Exception { |
| | | SavedRequestAwareAuthenticationSuccessHandler successHandler = new SavedRequestAwareAuthenticationSuccessHandler(); |
| | | successHandler.setTargetUrlParameter("redirectTo"); |
| | | successHandler.setDefaultTargetUrl(adminContextPath + "/"); |
| | | // admin监控 用户鉴权 |
| | | httpSecurity.authorizeRequests() |
| | | //授予对所有静态资产和登录页面的公共访问权限。 |
| | | .antMatchers(adminContextPath + "/assets/**").permitAll() |
| | | .antMatchers(adminContextPath + "/login").permitAll() |
| | | .antMatchers("/actuator").permitAll() |
| | | .antMatchers("/actuator/**").permitAll() |
| | | //必须对每个其他请求进行身份验证 |
| | | .anyRequest().authenticated().and() |
| | | //配置登录和注销 |
| | | .formLogin().loginPage(adminContextPath + "/login") |
| | | .successHandler(successHandler).and() |
| | | .logout().logoutUrl(adminContextPath + "/logout").and() |
| | | //启用HTTP-Basic支持。这是Spring Boot Admin Client注册所必需的 |
| | | .httpBasic().and().csrf().disable() |
| | | .headers().frameOptions().disable(); |
| | | } |
| | | //必须对每个其他请求进行身份验证 |
| | | .anyRequest().authenticated().and() |
| | | //配置登录和注销 |
| | | .formLogin().loginPage(adminContextPath + "/login") |
| | | .successHandler(successHandler).and() |
| | | .logout().logoutUrl(adminContextPath + "/logout").and() |
| | | //启用HTTP-Basic支持。这是Spring Boot Admin Client注册所必需的 |
| | | .httpBasic().and().csrf().disable() |
| | | .headers().frameOptions().disable(); |
| | | } |
| | | |
| | | } |
| | |
| | | @Configuration |
| | | public class AsyncConfig extends AsyncConfigurerSupport { |
| | | |
| | | @Autowired |
| | | @Qualifier("scheduledExecutorService") |
| | | private ScheduledExecutorService scheduledExecutorService; |
| | | @Autowired |
| | | @Qualifier("scheduledExecutorService") |
| | | private ScheduledExecutorService scheduledExecutorService; |
| | | |
| | | /** |
| | | * 异步执行需要使用权限框架自带的包装线程池 保证权限信息的传递 |
| | |
| | | throwable.printStackTrace(); |
| | | StringBuilder sb = new StringBuilder(); |
| | | sb.append("Exception message - ").append(throwable.getMessage()) |
| | | .append(", Method name - ").append(method.getName()); |
| | | .append(", Method name - ").append(method.getName()); |
| | | if (ArrayUtil.isNotEmpty(objects)) { |
| | | sb.append(", Parameter value - ").append(Arrays.toString(objects)); |
| | | } |
| | |
| | | /** |
| | | * 去除监控页面底部的广告 |
| | | */ |
| | | @SuppressWarnings({ "rawtypes", "unchecked" }) |
| | | @SuppressWarnings({"rawtypes", "unchecked"}) |
| | | @Bean |
| | | @ConditionalOnProperty(name = "spring.datasource.druid.statViewServlet.enabled", havingValue = "true") |
| | | public FilterRegistrationBean removeDruidFilterRegistrationBean(DruidStatProperties properties) |
| | | { |
| | | public FilterRegistrationBean removeDruidFilterRegistrationBean(DruidStatProperties properties) { |
| | | // 获取web监控页面的参数 |
| | | DruidStatProperties.StatViewServlet config = properties.getStatViewServlet(); |
| | | // 提取common.js的配置路径 |
| | |
| | | String commonJsPattern = pattern.replaceAll("\\*", "js/common.js"); |
| | | final String filePath = "support/http/resources/js/common.js"; |
| | | // 创建filter进行过滤 |
| | | Filter filter = new Filter() |
| | | { |
| | | Filter filter = new Filter() { |
| | | @Override |
| | | public void init(javax.servlet.FilterConfig filterConfig) throws ServletException |
| | | { |
| | | public void init(javax.servlet.FilterConfig filterConfig) throws ServletException { |
| | | } |
| | | |
| | | @Override |
| | | public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) |
| | | throws IOException, ServletException |
| | | { |
| | | throws IOException, ServletException { |
| | | chain.doFilter(request, response); |
| | | // 重置缓冲区,响应头不会被重置 |
| | | // response.resetBuffer(); |
| | |
| | | text = text.replaceAll("powered.*?shrek.wang</a>", ""); |
| | | response.getWriter().write(text); |
| | | } |
| | | |
| | | @Override |
| | | public void destroy() |
| | | { |
| | | public void destroy() { |
| | | } |
| | | }; |
| | | FilterRegistrationBean registrationBean = new FilterRegistrationBean(); |
| | |
| | | @Configuration |
| | | public class I18nConfig { |
| | | |
| | | @Bean |
| | | public LocaleResolver localeResolver() { |
| | | return new I18nLocaleResolver(); |
| | | } |
| | | @Bean |
| | | public LocaleResolver localeResolver() { |
| | | return new I18nLocaleResolver(); |
| | | } |
| | | |
| | | /** |
| | | * 获取请求头国际化信息 |
| | | */ |
| | | static class I18nLocaleResolver implements LocaleResolver { |
| | | /** |
| | | * 获取请求头国际化信息 |
| | | */ |
| | | static class I18nLocaleResolver implements LocaleResolver { |
| | | |
| | | @Override |
| | | public Locale resolveLocale(HttpServletRequest httpServletRequest) { |
| | | String language = httpServletRequest.getHeader("content-language"); |
| | | Locale locale = Locale.getDefault(); |
| | | if (StrUtil.isNotBlank(language)) { |
| | | String[] split = language.split("_"); |
| | | locale = new Locale(split[0], split[1]); |
| | | } |
| | | return locale; |
| | | } |
| | | @Override |
| | | public Locale resolveLocale(HttpServletRequest httpServletRequest) { |
| | | String language = httpServletRequest.getHeader("content-language"); |
| | | Locale locale = Locale.getDefault(); |
| | | if (StrUtil.isNotBlank(language)) { |
| | | String[] split = language.split("_"); |
| | | locale = new Locale(split[0], split[1]); |
| | | } |
| | | return locale; |
| | | } |
| | | |
| | | @Override |
| | | public void setLocale(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse, Locale locale) { |
| | | @Override |
| | | public void setLocale(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse, Locale locale) { |
| | | |
| | | } |
| | | } |
| | | } |
| | | } |
| | | } |
| | |
| | | @Configuration |
| | | public class JacksonConfig { |
| | | |
| | | @Primary |
| | | @Bean |
| | | public ObjectMapper getObjectMapper(Jackson2ObjectMapperBuilder builder, JacksonProperties jacksonProperties) { |
| | | ObjectMapper objectMapper = builder.createXmlMapper(false).build(); |
| | | // 全局配置序列化返回 JSON 处理 |
| | | SimpleModule simpleModule = new SimpleModule(); |
| | | simpleModule.addSerializer(Long.class, BigNumberSerializer.INSTANCE); |
| | | simpleModule.addSerializer(Long.TYPE, BigNumberSerializer.INSTANCE); |
| | | simpleModule.addSerializer(BigInteger.class, BigNumberSerializer.INSTANCE); |
| | | simpleModule.addSerializer(BigDecimal.class, ToStringSerializer.instance); |
| | | DateTimeFormatter formatter = DateTimeFormatter.ofPattern(jacksonProperties.getDateFormat()); |
| | | simpleModule.addSerializer(LocalDateTime.class, new LocalDateTimeSerializer(formatter)); |
| | | simpleModule.addDeserializer(LocalDateTime.class, new LocalDateTimeDeserializer(formatter)); |
| | | objectMapper.registerModule(simpleModule); |
| | | objectMapper.setTimeZone(TimeZone.getDefault()); |
| | | log.info("初始化 jackson 配置"); |
| | | return objectMapper; |
| | | } |
| | | @Primary |
| | | @Bean |
| | | public ObjectMapper getObjectMapper(Jackson2ObjectMapperBuilder builder, JacksonProperties jacksonProperties) { |
| | | ObjectMapper objectMapper = builder.createXmlMapper(false).build(); |
| | | // 全局配置序列化返回 JSON 处理 |
| | | SimpleModule simpleModule = new SimpleModule(); |
| | | simpleModule.addSerializer(Long.class, BigNumberSerializer.INSTANCE); |
| | | simpleModule.addSerializer(Long.TYPE, BigNumberSerializer.INSTANCE); |
| | | simpleModule.addSerializer(BigInteger.class, BigNumberSerializer.INSTANCE); |
| | | simpleModule.addSerializer(BigDecimal.class, ToStringSerializer.instance); |
| | | DateTimeFormatter formatter = DateTimeFormatter.ofPattern(jacksonProperties.getDateFormat()); |
| | | simpleModule.addSerializer(LocalDateTime.class, new LocalDateTimeSerializer(formatter)); |
| | | simpleModule.addDeserializer(LocalDateTime.class, new LocalDateTimeDeserializer(formatter)); |
| | | objectMapper.registerModule(simpleModule); |
| | | objectMapper.setTimeZone(TimeZone.getDefault()); |
| | | log.info("初始化 jackson 配置"); |
| | | return objectMapper; |
| | | } |
| | | |
| | | } |
| | |
| | | @MapperScan("${mybatis-plus.mapperPackage}") |
| | | public class MybatisPlusConfig { |
| | | |
| | | @Bean |
| | | public MybatisPlusInterceptor mybatisPlusInterceptor() { |
| | | MybatisPlusInterceptor interceptor = new MybatisPlusInterceptor(); |
| | | @Bean |
| | | public MybatisPlusInterceptor mybatisPlusInterceptor() { |
| | | MybatisPlusInterceptor interceptor = new MybatisPlusInterceptor(); |
| | | // 数据权限处理 |
| | | interceptor.addInnerInterceptor(dataPermissionInterceptor()); |
| | | // 分页插件 |
| | | interceptor.addInnerInterceptor(paginationInnerInterceptor()); |
| | | // 乐观锁插件 |
| | | interceptor.addInnerInterceptor(optimisticLockerInnerInterceptor()); |
| | | return interceptor; |
| | | } |
| | | // 分页插件 |
| | | interceptor.addInnerInterceptor(paginationInnerInterceptor()); |
| | | // 乐观锁插件 |
| | | interceptor.addInnerInterceptor(optimisticLockerInnerInterceptor()); |
| | | return interceptor; |
| | | } |
| | | |
| | | /** |
| | | * 数据权限拦截器 |
| | |
| | | return new PlusDataPermissionInterceptor(); |
| | | } |
| | | |
| | | /** |
| | | * 分页插件,自动识别数据库类型 |
| | | */ |
| | | public PaginationInnerInterceptor paginationInnerInterceptor() { |
| | | PaginationInnerInterceptor paginationInnerInterceptor = new PaginationInnerInterceptor(); |
| | | // 设置最大单页限制数量,默认 500 条,-1 不受限制 |
| | | paginationInnerInterceptor.setMaxLimit(-1L); |
| | | // 分页合理化 |
| | | paginationInnerInterceptor.setOverflow(true); |
| | | return paginationInnerInterceptor; |
| | | } |
| | | /** |
| | | * 分页插件,自动识别数据库类型 |
| | | */ |
| | | public PaginationInnerInterceptor paginationInnerInterceptor() { |
| | | PaginationInnerInterceptor paginationInnerInterceptor = new PaginationInnerInterceptor(); |
| | | // 设置最大单页限制数量,默认 500 条,-1 不受限制 |
| | | paginationInnerInterceptor.setMaxLimit(-1L); |
| | | // 分页合理化 |
| | | paginationInnerInterceptor.setOverflow(true); |
| | | return paginationInnerInterceptor; |
| | | } |
| | | |
| | | /** |
| | | * 乐观锁插件 |
| | | */ |
| | | public OptimisticLockerInnerInterceptor optimisticLockerInnerInterceptor() { |
| | | return new OptimisticLockerInnerInterceptor(); |
| | | } |
| | | /** |
| | | * 乐观锁插件 |
| | | */ |
| | | public OptimisticLockerInnerInterceptor optimisticLockerInnerInterceptor() { |
| | | return new OptimisticLockerInnerInterceptor(); |
| | | } |
| | | |
| | | /** |
| | | * 元对象字段填充控制器 |
| | | */ |
| | | @Bean |
| | | public MetaObjectHandler metaObjectHandler() { |
| | | return new CreateAndUpdateMetaObjectHandler(); |
| | | } |
| | | /** |
| | | * 元对象字段填充控制器 |
| | | */ |
| | | @Bean |
| | | public MetaObjectHandler metaObjectHandler() { |
| | | return new CreateAndUpdateMetaObjectHandler(); |
| | | } |
| | | |
| | | /** |
| | | * sql注入器配置 |
| | | */ |
| | | @Bean |
| | | public ISqlInjector sqlInjector() { |
| | | return new DefaultSqlInjector() { |
| | | @Override |
| | | public List<AbstractMethod> getMethodList(Class<?> mapperClass, TableInfo tableInfo) { |
| | | List<AbstractMethod> methodList = super.getMethodList(mapperClass, tableInfo); |
| | | methodList.add(new InsertAll()); |
| | | return methodList; |
| | | } |
| | | }; |
| | | } |
| | | /** |
| | | * sql注入器配置 |
| | | */ |
| | | @Bean |
| | | public ISqlInjector sqlInjector() { |
| | | return new DefaultSqlInjector() { |
| | | @Override |
| | | public List<AbstractMethod> getMethodList(Class<?> mapperClass, TableInfo tableInfo) { |
| | | List<AbstractMethod> methodList = super.getMethodList(mapperClass, tableInfo); |
| | | methodList.add(new InsertAll()); |
| | | return methodList; |
| | | } |
| | | }; |
| | | } |
| | | |
| | | /** |
| | | * 使用网卡信息绑定雪花生成器 |
| | |
| | | return new DefaultIdentifierGenerator(NetUtil.getLocalhost()); |
| | | } |
| | | |
| | | /** |
| | | * PaginationInnerInterceptor 分页插件,自动识别数据库类型 |
| | | * https://baomidou.com/pages/97710a/ |
| | | * OptimisticLockerInnerInterceptor 乐观锁插件 |
| | | * https://baomidou.com/pages/0d93c0/ |
| | | * MetaObjectHandler 元对象字段填充控制器 |
| | | * https://baomidou.com/pages/4c6bcf/ |
| | | * ISqlInjector sql注入器 |
| | | * https://baomidou.com/pages/42ea4a/ |
| | | * BlockAttackInnerInterceptor 如果是对全表的删除或更新操作,就会终止该操作 |
| | | * https://baomidou.com/pages/f9a237/ |
| | | * IllegalSQLInnerInterceptor sql性能规范插件(垃圾SQL拦截) |
| | | * IdentifierGenerator 自定义主键策略 |
| | | * https://baomidou.com/pages/568eb2/ |
| | | * TenantLineInnerInterceptor 多租户插件 |
| | | * https://baomidou.com/pages/aef2f2/ |
| | | * DynamicTableNameInnerInterceptor 动态表名插件 |
| | | * https://baomidou.com/pages/2a45ff/ |
| | | */ |
| | | /** |
| | | * PaginationInnerInterceptor 分页插件,自动识别数据库类型 |
| | | * https://baomidou.com/pages/97710a/ |
| | | * OptimisticLockerInnerInterceptor 乐观锁插件 |
| | | * https://baomidou.com/pages/0d93c0/ |
| | | * MetaObjectHandler 元对象字段填充控制器 |
| | | * https://baomidou.com/pages/4c6bcf/ |
| | | * ISqlInjector sql注入器 |
| | | * https://baomidou.com/pages/42ea4a/ |
| | | * BlockAttackInnerInterceptor 如果是对全表的删除或更新操作,就会终止该操作 |
| | | * https://baomidou.com/pages/f9a237/ |
| | | * IllegalSQLInnerInterceptor sql性能规范插件(垃圾SQL拦截) |
| | | * IdentifierGenerator 自定义主键策略 |
| | | * https://baomidou.com/pages/568eb2/ |
| | | * TenantLineInnerInterceptor 多租户插件 |
| | | * https://baomidou.com/pages/aef2f2/ |
| | | * DynamicTableNameInnerInterceptor 动态表名插件 |
| | | * https://baomidou.com/pages/2a45ff/ |
| | | */ |
| | | |
| | | } |
| | |
| | | private SwaggerProperties swaggerProperties; |
| | | |
| | | @Autowired |
| | | private TokenProperties tokenProperties; |
| | | private TokenProperties tokenProperties; |
| | | |
| | | @Autowired |
| | | private OpenApiExtensionResolver openApiExtensionResolver; |
| | |
| | | */ |
| | | @PostConstruct |
| | | public void createRestApi() { |
| | | for (SwaggerProperties.Groups group : swaggerProperties.getGroups()) { |
| | | String basePackage = group.getBasePackage(); |
| | | Docket docket = new Docket(DocumentationType.OAS_30) |
| | | .enable(swaggerProperties.getEnabled()) |
| | | // 用来创建该API的基本信息,展示在文档的页面中(自定义展示的信息) |
| | | .apiInfo(apiInfo()) |
| | | // 设置哪些接口暴露给Swagger展示 |
| | | .select() |
| | | // 扫描所有有注解的api,用这种方式更灵活 |
| | | //.apis(RequestHandlerSelectors.withMethodAnnotation(ApiOperation.class)) |
| | | // 扫描指定包中的swagger注解 |
| | | .apis(RequestHandlerSelectors.basePackage(basePackage)) |
| | | // 扫描所有 .apis(RequestHandlerSelectors.any()) |
| | | .paths(PathSelectors.any()) |
| | | .build() |
| | | .groupName(group.getName()) |
| | | // 设置安全模式,swagger可以设置访问token |
| | | .securitySchemes(securitySchemes()) |
| | | .securityContexts(securityContexts()) |
| | | .extensions(openApiExtensionResolver.buildExtensions(group.getName())) |
| | | .pathMapping(swaggerProperties.getPathMapping()); |
| | | String beanName = StringUtils.substringAfterLast(basePackage, ".") + "Docket"; |
| | | SpringUtils.registerBean(beanName, docket); |
| | | } |
| | | for (SwaggerProperties.Groups group : swaggerProperties.getGroups()) { |
| | | String basePackage = group.getBasePackage(); |
| | | Docket docket = new Docket(DocumentationType.OAS_30) |
| | | .enable(swaggerProperties.getEnabled()) |
| | | // 用来创建该API的基本信息,展示在文档的页面中(自定义展示的信息) |
| | | .apiInfo(apiInfo()) |
| | | // 设置哪些接口暴露给Swagger展示 |
| | | .select() |
| | | // 扫描所有有注解的api,用这种方式更灵活 |
| | | //.apis(RequestHandlerSelectors.withMethodAnnotation(ApiOperation.class)) |
| | | // 扫描指定包中的swagger注解 |
| | | .apis(RequestHandlerSelectors.basePackage(basePackage)) |
| | | // 扫描所有 .apis(RequestHandlerSelectors.any()) |
| | | .paths(PathSelectors.any()) |
| | | .build() |
| | | .groupName(group.getName()) |
| | | // 设置安全模式,swagger可以设置访问token |
| | | .securitySchemes(securitySchemes()) |
| | | .securityContexts(securityContexts()) |
| | | .extensions(openApiExtensionResolver.buildExtensions(group.getName())) |
| | | .pathMapping(swaggerProperties.getPathMapping()); |
| | | String beanName = StringUtils.substringAfterLast(basePackage, ".") + "Docket"; |
| | | SpringUtils.registerBean(beanName, docket); |
| | | } |
| | | } |
| | | |
| | | /** |
| | |
| | | */ |
| | | private List<SecurityScheme> securitySchemes() { |
| | | List<SecurityScheme> apiKeyList = new ArrayList<SecurityScheme>(); |
| | | String header = tokenProperties.getHeader(); |
| | | apiKeyList.add(new ApiKey(header, header, In.HEADER.toValue())); |
| | | String header = tokenProperties.getHeader(); |
| | | apiKeyList.add(new ApiKey(header, header, In.HEADER.toValue())); |
| | | return apiKeyList; |
| | | } |
| | | |
| | |
| | | private List<SecurityContext> securityContexts() { |
| | | List<SecurityContext> securityContexts = new ArrayList<>(); |
| | | securityContexts.add( |
| | | SecurityContext.builder() |
| | | .securityReferences(defaultAuth()) |
| | | .operationSelector(o -> o.requestMappingPattern().matches("/.*")) |
| | | .build()); |
| | | SecurityContext.builder() |
| | | .securityReferences(defaultAuth()) |
| | | .operationSelector(o -> o.requestMappingPattern().matches("/.*")) |
| | | .build()); |
| | | return securityContexts; |
| | | } |
| | | |
| | |
| | | // 用ApiInfoBuilder进行定制 |
| | | SwaggerProperties.Contact contact = swaggerProperties.getContact(); |
| | | return new ApiInfoBuilder() |
| | | // 设置标题 |
| | | .title(swaggerProperties.getTitle()) |
| | | // 描述 |
| | | .description(swaggerProperties.getDescription()) |
| | | // 作者信息 |
| | | .contact(new Contact(contact.getName(), contact.getUrl(), contact.getEmail())) |
| | | // 版本 |
| | | .version(swaggerProperties.getVersion()) |
| | | .build(); |
| | | // 设置标题 |
| | | .title(swaggerProperties.getTitle()) |
| | | // 描述 |
| | | .description(swaggerProperties.getDescription()) |
| | | // 作者信息 |
| | | .contact(new Contact(contact.getName(), contact.getUrl(), contact.getEmail())) |
| | | // 版本 |
| | | .version(swaggerProperties.getVersion()) |
| | | .build(); |
| | | } |
| | | } |
| | |
| | | @ConfigurationProperties(prefix = "captcha") |
| | | public class CaptchaProperties { |
| | | |
| | | /** |
| | | * 验证码类型 |
| | | */ |
| | | /** |
| | | * 验证码类型 |
| | | */ |
| | | private CaptchaType type; |
| | | |
| | | /** |
| | | * 验证码类别 |
| | | */ |
| | | /** |
| | | * 验证码类别 |
| | | */ |
| | | private CaptchaCategory category; |
| | | |
| | | /** |
| | | * 数字验证码位数 |
| | | */ |
| | | /** |
| | | * 数字验证码位数 |
| | | */ |
| | | private Integer numberLength; |
| | | |
| | | /** |
| | | * 字符验证码长度 |
| | | */ |
| | | /** |
| | | * 字符验证码长度 |
| | | */ |
| | | private Integer charLength; |
| | | } |
| | |
| | | @ConfigurationProperties(prefix = "redisson") |
| | | public class RedissonProperties { |
| | | |
| | | /** |
| | | * 线程池数量,默认值 = 当前处理核数量 * 2 |
| | | */ |
| | | private int threads; |
| | | /** |
| | | * 线程池数量,默认值 = 当前处理核数量 * 2 |
| | | */ |
| | | private int threads; |
| | | |
| | | /** |
| | | * Netty线程池数量,默认值 = 当前处理核数量 * 2 |
| | | */ |
| | | private int nettyThreads; |
| | | /** |
| | | * Netty线程池数量,默认值 = 当前处理核数量 * 2 |
| | | */ |
| | | private int nettyThreads; |
| | | |
| | | /** |
| | | * 传输模式 |
| | | */ |
| | | private TransportMode transportMode; |
| | | /** |
| | | * 传输模式 |
| | | */ |
| | | private TransportMode transportMode; |
| | | |
| | | /** |
| | | * 单机服务配置 |
| | | */ |
| | | private SingleServerConfig singleServerConfig; |
| | | /** |
| | | * 单机服务配置 |
| | | */ |
| | | private SingleServerConfig singleServerConfig; |
| | | |
| | | /** |
| | | * 集群服务配置 |
| | | */ |
| | | private ClusterServersConfig clusterServersConfig; |
| | | /** |
| | | * 集群服务配置 |
| | | */ |
| | | private ClusterServersConfig clusterServersConfig; |
| | | |
| | | /** |
| | | * 缓存组 |
| | | */ |
| | | private List<CacheGroup> cacheGroup; |
| | | /** |
| | | * 缓存组 |
| | | */ |
| | | private List<CacheGroup> cacheGroup; |
| | | |
| | | @Data |
| | | @NoArgsConstructor |
| | | public static class SingleServerConfig { |
| | | @Data |
| | | @NoArgsConstructor |
| | | public static class SingleServerConfig { |
| | | |
| | | /** |
| | | * 客户端名称 |
| | | */ |
| | | private String clientName; |
| | | /** |
| | | * 客户端名称 |
| | | */ |
| | | private String clientName; |
| | | |
| | | /** |
| | | * 最小空闲连接数 |
| | | */ |
| | | private int connectionMinimumIdleSize; |
| | | /** |
| | | * 最小空闲连接数 |
| | | */ |
| | | private int connectionMinimumIdleSize; |
| | | |
| | | /** |
| | | * 连接池大小 |
| | | */ |
| | | private int connectionPoolSize; |
| | | /** |
| | | * 连接池大小 |
| | | */ |
| | | private int connectionPoolSize; |
| | | |
| | | /** |
| | | * 连接空闲超时,单位:毫秒 |
| | | */ |
| | | private int idleConnectionTimeout; |
| | | /** |
| | | * 连接空闲超时,单位:毫秒 |
| | | */ |
| | | private int idleConnectionTimeout; |
| | | |
| | | /** |
| | | * 命令等待超时,单位:毫秒 |
| | | */ |
| | | private int timeout; |
| | | /** |
| | | * 命令等待超时,单位:毫秒 |
| | | */ |
| | | private int timeout; |
| | | |
| | | /** |
| | | * 如果尝试在此限制之内发送成功,则开始启用 timeout 计时。 |
| | | */ |
| | | private int retryAttempts; |
| | | /** |
| | | * 如果尝试在此限制之内发送成功,则开始启用 timeout 计时。 |
| | | */ |
| | | private int retryAttempts; |
| | | |
| | | /** |
| | | * 命令重试发送时间间隔,单位:毫秒 |
| | | */ |
| | | private int retryInterval; |
| | | /** |
| | | * 命令重试发送时间间隔,单位:毫秒 |
| | | */ |
| | | private int retryInterval; |
| | | |
| | | /** |
| | | * 发布和订阅连接的最小空闲连接数 |
| | | */ |
| | | private int subscriptionConnectionMinimumIdleSize; |
| | | /** |
| | | * 发布和订阅连接的最小空闲连接数 |
| | | */ |
| | | private int subscriptionConnectionMinimumIdleSize; |
| | | |
| | | /** |
| | | * 发布和订阅连接池大小 |
| | | */ |
| | | private int subscriptionConnectionPoolSize; |
| | | /** |
| | | * 发布和订阅连接池大小 |
| | | */ |
| | | private int subscriptionConnectionPoolSize; |
| | | |
| | | /** |
| | | * 单个连接最大订阅数量 |
| | | */ |
| | | private int subscriptionsPerConnection; |
| | | /** |
| | | * 单个连接最大订阅数量 |
| | | */ |
| | | private int subscriptionsPerConnection; |
| | | |
| | | /** |
| | | * DNS监测时间间隔,单位:毫秒 |
| | | */ |
| | | private int dnsMonitoringInterval; |
| | | /** |
| | | * DNS监测时间间隔,单位:毫秒 |
| | | */ |
| | | private int dnsMonitoringInterval; |
| | | |
| | | } |
| | | } |
| | | |
| | | @Data |
| | | @NoArgsConstructor |
| | | public static class ClusterServersConfig { |
| | | @Data |
| | | @NoArgsConstructor |
| | | public static class ClusterServersConfig { |
| | | |
| | | /** |
| | | * 客户端名称 |
| | | */ |
| | | private String clientName; |
| | | /** |
| | | * 客户端名称 |
| | | */ |
| | | private String clientName; |
| | | |
| | | /** |
| | | * master最小空闲连接数 |
| | | */ |
| | | private int masterConnectionMinimumIdleSize; |
| | | /** |
| | | * master最小空闲连接数 |
| | | */ |
| | | private int masterConnectionMinimumIdleSize; |
| | | |
| | | /** |
| | | * master连接池大小 |
| | | */ |
| | | private int masterConnectionPoolSize; |
| | | /** |
| | | * master连接池大小 |
| | | */ |
| | | private int masterConnectionPoolSize; |
| | | |
| | | /** |
| | | * slave最小空闲连接数 |
| | | */ |
| | | private int slaveConnectionMinimumIdleSize; |
| | | /** |
| | | * slave最小空闲连接数 |
| | | */ |
| | | private int slaveConnectionMinimumIdleSize; |
| | | |
| | | /** |
| | | * slave连接池大小 |
| | | */ |
| | | private int slaveConnectionPoolSize; |
| | | /** |
| | | * slave连接池大小 |
| | | */ |
| | | private int slaveConnectionPoolSize; |
| | | |
| | | /** |
| | | * 连接空闲超时,单位:毫秒 |
| | | */ |
| | | private int idleConnectionTimeout; |
| | | /** |
| | | * 连接空闲超时,单位:毫秒 |
| | | */ |
| | | private int idleConnectionTimeout; |
| | | |
| | | /** |
| | | * ping超时 |
| | | */ |
| | | private int pingConnectionInterval; |
| | | /** |
| | | * ping超时 |
| | | */ |
| | | private int pingConnectionInterval; |
| | | |
| | | /** |
| | | * 命令等待超时,单位:毫秒 |
| | | */ |
| | | private int timeout; |
| | | /** |
| | | * 命令等待超时,单位:毫秒 |
| | | */ |
| | | private int timeout; |
| | | |
| | | /** |
| | | * 如果尝试在此限制之内发送成功,则开始启用 timeout 计时。 |
| | | */ |
| | | private int retryAttempts; |
| | | /** |
| | | * 如果尝试在此限制之内发送成功,则开始启用 timeout 计时。 |
| | | */ |
| | | private int retryAttempts; |
| | | |
| | | /** |
| | | * 命令重试发送时间间隔,单位:毫秒 |
| | | */ |
| | | private int retryInterval; |
| | | /** |
| | | * 命令重试发送时间间隔,单位:毫秒 |
| | | */ |
| | | private int retryInterval; |
| | | |
| | | /** |
| | | * 错误重试次数 |
| | | */ |
| | | private int failedSlaveReconnectionInterval; |
| | | /** |
| | | * 错误重试次数 |
| | | */ |
| | | private int failedSlaveReconnectionInterval; |
| | | |
| | | /** |
| | | * 发布和订阅连接池最小空闲连接数 |
| | | */ |
| | | private int subscriptionConnectionMinimumIdleSize; |
| | | /** |
| | | * 发布和订阅连接池最小空闲连接数 |
| | | */ |
| | | private int subscriptionConnectionMinimumIdleSize; |
| | | |
| | | /** |
| | | * 发布和订阅连接池大小 |
| | | */ |
| | | private int subscriptionConnectionPoolSize; |
| | | /** |
| | | * 发布和订阅连接池大小 |
| | | */ |
| | | private int subscriptionConnectionPoolSize; |
| | | |
| | | /** |
| | | * 单个连接最大订阅数量 |
| | | */ |
| | | private int subscriptionsPerConnection; |
| | | /** |
| | | * 单个连接最大订阅数量 |
| | | */ |
| | | private int subscriptionsPerConnection; |
| | | |
| | | /** |
| | | * 扫描间隔 |
| | | */ |
| | | private int scanInterval; |
| | | /** |
| | | * 扫描间隔 |
| | | */ |
| | | private int scanInterval; |
| | | |
| | | /** |
| | | * DNS监测时间间隔,单位:毫秒 |
| | | */ |
| | | private int dnsMonitoringInterval; |
| | | /** |
| | | * DNS监测时间间隔,单位:毫秒 |
| | | */ |
| | | private int dnsMonitoringInterval; |
| | | |
| | | /** |
| | | * 读取模式 |
| | | */ |
| | | private ReadMode readMode; |
| | | /** |
| | | * 读取模式 |
| | | */ |
| | | private ReadMode readMode; |
| | | |
| | | /** |
| | | * 订阅模式 |
| | | */ |
| | | private SubscriptionMode subscriptionMode; |
| | | /** |
| | | * 订阅模式 |
| | | */ |
| | | private SubscriptionMode subscriptionMode; |
| | | |
| | | } |
| | | } |
| | | |
| | | @Data |
| | | @NoArgsConstructor |
| | | public static class CacheGroup { |
| | | @Data |
| | | @NoArgsConstructor |
| | | public static class CacheGroup { |
| | | |
| | | /** |
| | | * 组id |
| | | */ |
| | | private String groupId; |
| | | /** |
| | | * 组id |
| | | */ |
| | | private String groupId; |
| | | |
| | | /** |
| | | * 组过期时间 |
| | | */ |
| | | private long ttl; |
| | | /** |
| | | * 组过期时间 |
| | | */ |
| | | private long ttl; |
| | | |
| | | /** |
| | | * 组最大空闲时间 |
| | | */ |
| | | private long maxIdleTime; |
| | | /** |
| | | * 组最大空闲时间 |
| | | */ |
| | | private long maxIdleTime; |
| | | |
| | | /** |
| | | * 组最大长度 |
| | | */ |
| | | private int maxSize; |
| | | /** |
| | | * 组最大长度 |
| | | */ |
| | | private int maxSize; |
| | | |
| | | } |
| | | } |
| | | |
| | | } |
| | |
| | | * 验证码类型 |
| | | */ |
| | | private Boolean enabled; |
| | | /** |
| | | * 设置请求的统一前缀 |
| | | */ |
| | | private String pathMapping; |
| | | /** |
| | | * 设置请求的统一前缀 |
| | | */ |
| | | private String pathMapping; |
| | | /** |
| | | * 验证码类别 |
| | | */ |
| | |
| | | */ |
| | | private String version; |
| | | |
| | | /** |
| | | * 联系方式 |
| | | */ |
| | | /** |
| | | * 联系方式 |
| | | */ |
| | | private Contact contact; |
| | | |
| | | /** |
| | | * 组配置 |
| | | */ |
| | | private List<Groups> groups; |
| | | /** |
| | | * 组配置 |
| | | */ |
| | | private List<Groups> groups; |
| | | |
| | | @Data |
| | | @NoArgsConstructor |
| | | public static class Contact { |
| | | @NoArgsConstructor |
| | | public static class Contact { |
| | | |
| | | /** |
| | | * 联系人 |
| | | */ |
| | | private String name; |
| | | /** |
| | | * 联系人 |
| | | */ |
| | | private String name; |
| | | |
| | | /** |
| | | * 联系人url |
| | | */ |
| | | private String url; |
| | | /** |
| | | * 联系人url |
| | | */ |
| | | private String url; |
| | | |
| | | /** |
| | | * 联系人email |
| | | */ |
| | | private String email; |
| | | /** |
| | | * 联系人email |
| | | */ |
| | | private String email; |
| | | |
| | | } |
| | | } |
| | | |
| | | @Data |
| | | @NoArgsConstructor |
| | | public static class Groups { |
| | | @Data |
| | | @NoArgsConstructor |
| | | public static class Groups { |
| | | |
| | | /** |
| | | * 组名 |
| | | */ |
| | | private String name; |
| | | /** |
| | | * 组名 |
| | | */ |
| | | private String name; |
| | | |
| | | /** |
| | | * 基础包路径 |
| | | */ |
| | | private String basePackage; |
| | | /** |
| | | * 基础包路径 |
| | | */ |
| | | private String basePackage; |
| | | |
| | | } |
| | | } |
| | | |
| | | } |
| | |
| | | @Slf4j |
| | | public class CreateAndUpdateMetaObjectHandler implements MetaObjectHandler { |
| | | |
| | | @Override |
| | | public void insertFill(MetaObject metaObject) { |
| | | try { |
| | | if (ObjectUtil.isNotNull(metaObject) && metaObject.getOriginalObject() instanceof BaseEntity) { |
| | | BaseEntity baseEntity = (BaseEntity) metaObject.getOriginalObject(); |
| | | Date current = new Date(); |
| | | // 创建时间为空 则填充 |
| | | if (ObjectUtil.isNull(baseEntity.getCreateTime())) { |
| | | baseEntity.setCreateTime(current); |
| | | } |
| | | // 更新时间为空 则填充 |
| | | if (ObjectUtil.isNull(baseEntity.getUpdateTime())) { |
| | | baseEntity.setUpdateTime(current); |
| | | } |
| | | String username = getLoginUsername(); |
| | | // 当前已登录 且 创建人为空 则填充 |
| | | if (StringUtils.isNotBlank(username) |
| | | && StringUtils.isBlank(baseEntity.getCreateBy())) { |
| | | baseEntity.setCreateBy(username); |
| | | } |
| | | // 当前已登录 且 更新人为空 则填充 |
| | | if (StringUtils.isNotBlank(username) |
| | | && StringUtils.isBlank(baseEntity.getUpdateBy())) { |
| | | baseEntity.setUpdateBy(username); |
| | | } |
| | | } |
| | | } catch (Exception e) { |
| | | throw new ServiceException("自动注入异常 => " + e.getMessage(), HttpStatus.HTTP_UNAUTHORIZED); |
| | | } |
| | | } |
| | | @Override |
| | | public void insertFill(MetaObject metaObject) { |
| | | try { |
| | | if (ObjectUtil.isNotNull(metaObject) && metaObject.getOriginalObject() instanceof BaseEntity) { |
| | | BaseEntity baseEntity = (BaseEntity) metaObject.getOriginalObject(); |
| | | Date current = new Date(); |
| | | // 创建时间为空 则填充 |
| | | if (ObjectUtil.isNull(baseEntity.getCreateTime())) { |
| | | baseEntity.setCreateTime(current); |
| | | } |
| | | // 更新时间为空 则填充 |
| | | if (ObjectUtil.isNull(baseEntity.getUpdateTime())) { |
| | | baseEntity.setUpdateTime(current); |
| | | } |
| | | String username = getLoginUsername(); |
| | | // 当前已登录 且 创建人为空 则填充 |
| | | if (StringUtils.isNotBlank(username) |
| | | && StringUtils.isBlank(baseEntity.getCreateBy())) { |
| | | baseEntity.setCreateBy(username); |
| | | } |
| | | // 当前已登录 且 更新人为空 则填充 |
| | | if (StringUtils.isNotBlank(username) |
| | | && StringUtils.isBlank(baseEntity.getUpdateBy())) { |
| | | baseEntity.setUpdateBy(username); |
| | | } |
| | | } |
| | | } catch (Exception e) { |
| | | throw new ServiceException("自动注入异常 => " + e.getMessage(), HttpStatus.HTTP_UNAUTHORIZED); |
| | | } |
| | | } |
| | | |
| | | @Override |
| | | public void updateFill(MetaObject metaObject) { |
| | | try { |
| | | if (ObjectUtil.isNotNull(metaObject) && metaObject.getOriginalObject() instanceof BaseEntity) { |
| | | BaseEntity baseEntity = (BaseEntity) metaObject.getOriginalObject(); |
| | | Date current = new Date(); |
| | | @Override |
| | | public void updateFill(MetaObject metaObject) { |
| | | try { |
| | | if (ObjectUtil.isNotNull(metaObject) && metaObject.getOriginalObject() instanceof BaseEntity) { |
| | | BaseEntity baseEntity = (BaseEntity) metaObject.getOriginalObject(); |
| | | Date current = new Date(); |
| | | // 更新时间填充(不管为不为空) |
| | | baseEntity.setUpdateTime(current); |
| | | String username = getLoginUsername(); |
| | |
| | | if (StringUtils.isNotBlank(username)) { |
| | | baseEntity.setUpdateBy(username); |
| | | } |
| | | } |
| | | } catch (Exception e) { |
| | | throw new ServiceException("自动注入异常 => " + e.getMessage(), HttpStatus.HTTP_UNAUTHORIZED); |
| | | } |
| | | } |
| | | } |
| | | } catch (Exception e) { |
| | | throw new ServiceException("自动注入异常 => " + e.getMessage(), HttpStatus.HTTP_UNAUTHORIZED); |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 获取登录用户名 |
| | | */ |
| | | private String getLoginUsername() { |
| | | LoginUser loginUser; |
| | | try { |
| | | loginUser = SecurityUtils.getLoginUser(); |
| | | } catch (Exception e) { |
| | | log.warn("自动注入警告 => 用户未登录"); |
| | | return null; |
| | | } |
| | | return loginUser.getUsername(); |
| | | } |
| | | /** |
| | | * 获取登录用户名 |
| | | */ |
| | | private String getLoginUsername() { |
| | | LoginUser loginUser; |
| | | try { |
| | | loginUser = SecurityUtils.getLoginUser(); |
| | | } catch (Exception e) { |
| | | log.warn("自动注入警告 => 用户未登录"); |
| | | return null; |
| | | } |
| | | return loginUser.getUsername(); |
| | | } |
| | | |
| | | } |
| | |
| | | @JacksonStdImpl |
| | | public class BigNumberSerializer extends NumberSerializer { |
| | | |
| | | /** |
| | | * 根据 JS Number.MAX_SAFE_INTEGER 与 Number.MIN_SAFE_INTEGER 得来 |
| | | */ |
| | | private static final long MAX_SAFE_INTEGER = 9007199254740991L; |
| | | private static final long MIN_SAFE_INTEGER = -9007199254740991L; |
| | | /** |
| | | * 根据 JS Number.MAX_SAFE_INTEGER 与 Number.MIN_SAFE_INTEGER 得来 |
| | | */ |
| | | private static final long MAX_SAFE_INTEGER = 9007199254740991L; |
| | | private static final long MIN_SAFE_INTEGER = -9007199254740991L; |
| | | |
| | | /** |
| | | * 提供实例 |
| | | */ |
| | | public static final BigNumberSerializer INSTANCE = new BigNumberSerializer(Number.class); |
| | | /** |
| | | * 提供实例 |
| | | */ |
| | | public static final BigNumberSerializer INSTANCE = new BigNumberSerializer(Number.class); |
| | | |
| | | public BigNumberSerializer(Class<? extends Number> rawType) { |
| | | super(rawType); |
| | | } |
| | | public BigNumberSerializer(Class<? extends Number> rawType) { |
| | | super(rawType); |
| | | } |
| | | |
| | | @Override |
| | | public void serialize(Number value, JsonGenerator gen, SerializerProvider provider) throws IOException { |
| | | // 超出范围 序列化位字符串 |
| | | if (value.longValue() > MIN_SAFE_INTEGER && value.longValue() < MAX_SAFE_INTEGER) { |
| | | super.serialize(value, gen, provider); |
| | | } else { |
| | | gen.writeString(value.toString()); |
| | | } |
| | | } |
| | | @Override |
| | | public void serialize(Number value, JsonGenerator gen, SerializerProvider provider) throws IOException { |
| | | // 超出范围 序列化位字符串 |
| | | if (value.longValue() > MIN_SAFE_INTEGER && value.longValue() < MAX_SAFE_INTEGER) { |
| | | super.serialize(value, gen, provider); |
| | | } else { |
| | | gen.writeString(value.toString()); |
| | | } |
| | | } |
| | | } |
| | |
| | | @Component |
| | | public class ShutdownManager { |
| | | |
| | | @Autowired |
| | | @Qualifier("scheduledExecutorService") |
| | | private ScheduledExecutorService scheduledExecutorService; |
| | | @Autowired |
| | | @Qualifier("scheduledExecutorService") |
| | | private ScheduledExecutorService scheduledExecutorService; |
| | | |
| | | @PreDestroy |
| | | public void destroy() { |
| | | shutdownAsyncManager(); |
| | | } |
| | | @PreDestroy |
| | | public void destroy() { |
| | | shutdownAsyncManager(); |
| | | } |
| | | |
| | | /** |
| | | * 停止异步执行任务 |
| | | */ |
| | | private void shutdownAsyncManager() { |
| | | try { |
| | | log.info("====关闭后台任务任务线程池===="); |
| | | Threads.shutdownAndAwaitTermination(scheduledExecutorService); |
| | | } catch (Exception e) { |
| | | log.error(e.getMessage(), e); |
| | | } |
| | | } |
| | | /** |
| | | * 停止异步执行任务 |
| | | */ |
| | | private void shutdownAsyncManager() { |
| | | try { |
| | | log.info("====关闭后台任务任务线程池===="); |
| | | Threads.shutdownAndAwaitTermination(scheduledExecutorService); |
| | | } catch (Exception e) { |
| | | log.error(e.getMessage(), e); |
| | | } |
| | | } |
| | | } |
| | |
| | | @Configuration |
| | | public class LogoutSuccessHandlerImpl implements LogoutSuccessHandler { |
| | | |
| | | @Autowired |
| | | private TokenService tokenService; |
| | | @Autowired |
| | | private TokenService tokenService; |
| | | |
| | | @Autowired |
| | | private LogininforService asyncService; |
| | | @Autowired |
| | | private LogininforService asyncService; |
| | | |
| | | /** |
| | | * 退出处理 |
| | | */ |
| | | @Override |
| | | public void onLogoutSuccess(HttpServletRequest request, HttpServletResponse response, Authentication authentication) |
| | | throws IOException, ServletException { |
| | | LoginUser loginUser = tokenService.getLoginUser(request); |
| | | /** |
| | | * 退出处理 |
| | | */ |
| | | @Override |
| | | public void onLogoutSuccess(HttpServletRequest request, HttpServletResponse response, Authentication authentication) |
| | | throws IOException, ServletException { |
| | | LoginUser loginUser = tokenService.getLoginUser(request); |
| | | String message = MessageUtils.message("user.logout.success"); |
| | | if (StringUtils.isNotNull(loginUser)) { |
| | | String userName = loginUser.getUsername(); |
| | | // 删除用户缓存记录 |
| | | tokenService.delLoginUser(loginUser.getToken()); |
| | | // 记录用户退出日志 |
| | | asyncService.recordLogininfor(userName, Constants.LOGOUT, message, request); |
| | | } |
| | | ServletUtils.renderString(response, JsonUtils.toJsonString(AjaxResult.error(HttpStatus.HTTP_OK, message))); |
| | | } |
| | | String userName = loginUser.getUsername(); |
| | | // 删除用户缓存记录 |
| | | tokenService.delLoginUser(loginUser.getToken()); |
| | | // 记录用户退出日志 |
| | | asyncService.recordLogininfor(userName, Constants.LOGOUT, message, request); |
| | | } |
| | | ServletUtils.renderString(response, JsonUtils.toJsonString(AjaxResult.error(HttpStatus.HTTP_OK, message))); |
| | | } |
| | | |
| | | } |
| | |
| | | */ |
| | | @ApiModelProperty(value = "系统内置(Y是 N否)") |
| | | @ExcelProperty(value = "系统内置", converter = ExcelDictConvert.class) |
| | | @ExcelDictFormat(dictType = "sys_yes_no") |
| | | @ExcelDictFormat(dictType = "sys_yes_no") |
| | | private String configType; |
| | | |
| | | /** |
| | |
| | | */ |
| | | @ApiModelProperty(value = "业务类型(0其它 1新增 2修改 3删除)") |
| | | @ExcelProperty(value = "业务类型", converter = ExcelDictConvert.class) |
| | | @ExcelDictFormat(dictType = "sys_oper_type") |
| | | @ExcelDictFormat(dictType = "sys_oper_type") |
| | | private Integer businessType; |
| | | |
| | | /** |
| | |
| | | */ |
| | | @ApiModelProperty(value = "操作类别(0其它 1后台用户 2手机端用户)") |
| | | @ExcelProperty(value = "操作类别", converter = ExcelDictConvert.class) |
| | | @ExcelDictFormat(readConverterExp = "0=其它,1=后台用户,2=手机端用户") |
| | | @ExcelDictFormat(readConverterExp = "0=其它,1=后台用户,2=手机端用户") |
| | | private Integer operatorType; |
| | | |
| | | /** |
| | |
| | | */ |
| | | @ApiModelProperty(value = "操作状态(0正常 1异常)") |
| | | @ExcelProperty(value = "状态", converter = ExcelDictConvert.class) |
| | | @ExcelDictFormat(dictType = "sys_common_status") |
| | | @ExcelDictFormat(dictType = "sys_common_status") |
| | | private Integer status; |
| | | |
| | | /** |
| | |
| | | @TableName("sys_oss") |
| | | public class SysOss extends BaseEntity { |
| | | |
| | | /** |
| | | * 对象存储主键 |
| | | */ |
| | | @TableId(value = "oss_id", type = IdType.AUTO) |
| | | private Long ossId; |
| | | /** |
| | | * 对象存储主键 |
| | | */ |
| | | @TableId(value = "oss_id", type = IdType.AUTO) |
| | | private Long ossId; |
| | | |
| | | /** |
| | | * 文件名 |
| | | */ |
| | | private String fileName; |
| | | /** |
| | | * 文件名 |
| | | */ |
| | | private String fileName; |
| | | |
| | | /** |
| | | * 原名 |
| | | */ |
| | | private String originalName; |
| | | /** |
| | | * 原名 |
| | | */ |
| | | private String originalName; |
| | | |
| | | /** |
| | | * 文件后缀名 |
| | | */ |
| | | private String fileSuffix; |
| | | /** |
| | | * 文件后缀名 |
| | | */ |
| | | private String fileSuffix; |
| | | |
| | | /** |
| | | * URL地址 |
| | | */ |
| | | private String url; |
| | | /** |
| | | * URL地址 |
| | | */ |
| | | private String url; |
| | | |
| | | /** |
| | | * 服务商 |
| | | */ |
| | | private String service; |
| | | /** |
| | | * 服务商 |
| | | */ |
| | | private String service; |
| | | |
| | | } |
| | |
| | | * 状态(0正常 1停用) |
| | | */ |
| | | @ApiModelProperty(value = "状态(0正常 1停用)") |
| | | @ExcelProperty(value = "状态", converter = ExcelDictConvert.class) |
| | | @ExcelDictFormat(dictType = "sys_common_status") |
| | | @ExcelProperty(value = "状态", converter = ExcelDictConvert.class) |
| | | @ExcelDictFormat(dictType = "sys_common_status") |
| | | private String status; |
| | | |
| | | /** |
| | |
| | | * |
| | | * @return |
| | | */ |
| | | public String innerLinkReplaceEach(String path) |
| | | { |
| | | return StringUtils.replaceEach(path, new String[] { Constants.HTTP, Constants.HTTPS }, |
| | | new String[] { "", "" }); |
| | | public String innerLinkReplaceEach(String path) { |
| | | return StringUtils.replaceEach(path, new String[]{Constants.HTTP, Constants.HTTPS}, |
| | | new String[]{"", ""}); |
| | | } |
| | | } |