员工关系移除
This commit is contained in:
@@ -0,0 +1,46 @@
|
||||
package com.ruoyi.ccdi.annotation;
|
||||
|
||||
import com.ruoyi.ccdi.validation.EnumValidator;
|
||||
import jakarta.validation.Constraint;
|
||||
import jakarta.validation.Payload;
|
||||
|
||||
import java.lang.annotation.*;
|
||||
|
||||
/**
|
||||
* 枚举值校验注解
|
||||
* 用于校验字段值是否在指定枚举类的定义范围内
|
||||
*
|
||||
* @author ruoyi
|
||||
*/
|
||||
@Target({ElementType.FIELD, ElementType.PARAMETER})
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
@Constraint(validatedBy = EnumValidator.class)
|
||||
@Documented
|
||||
public @interface EnumValid {
|
||||
|
||||
/**
|
||||
* 枚举类
|
||||
*/
|
||||
Class<?> enumClass();
|
||||
|
||||
/**
|
||||
* 校验失败时的错误消息
|
||||
*/
|
||||
String message() default "枚举值不合法";
|
||||
|
||||
/**
|
||||
* 分组
|
||||
*/
|
||||
Class<?>[] groups() default {};
|
||||
|
||||
/**
|
||||
* 负载
|
||||
*/
|
||||
Class<? extends Payload>[] payload() default {};
|
||||
|
||||
/**
|
||||
* 是否忽略空值
|
||||
* 如果为true,当字段为null或空字符串时不进行校验
|
||||
*/
|
||||
boolean ignoreEmpty() default true;
|
||||
}
|
||||
@@ -1,59 +0,0 @@
|
||||
package com.ruoyi.ccdi.domain;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.FieldFill;
|
||||
import com.baomidou.mybatisplus.annotation.IdType;
|
||||
import com.baomidou.mybatisplus.annotation.TableField;
|
||||
import com.baomidou.mybatisplus.annotation.TableId;
|
||||
import lombok.Data;
|
||||
|
||||
import java.io.Serial;
|
||||
import java.io.Serializable;
|
||||
import java.util.Date;
|
||||
|
||||
/**
|
||||
* 员工亲属对象 dpc_employee_relative
|
||||
*
|
||||
* @author ruoyi
|
||||
* @date 2026-01-28
|
||||
*/
|
||||
@Data
|
||||
public class CcdiEmployeeRelative implements Serializable {
|
||||
|
||||
@Serial
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
/** 亲属ID */
|
||||
@TableId(type = IdType.AUTO)
|
||||
private Long relativeId;
|
||||
|
||||
/** 员工ID */
|
||||
private Long employeeId;
|
||||
|
||||
/** 亲属姓名 */
|
||||
private String relativeName;
|
||||
|
||||
/** 亲属身份证号 */
|
||||
private String relativeIdCard;
|
||||
|
||||
/** 亲属手机号 */
|
||||
private String relativePhone;
|
||||
|
||||
/** 与员工关系 */
|
||||
private String relationship;
|
||||
|
||||
/** 创建者 */
|
||||
@TableField(fill = FieldFill.INSERT)
|
||||
private String createBy;
|
||||
|
||||
/** 创建时间 */
|
||||
@TableField(fill = FieldFill.INSERT)
|
||||
private Date createTime;
|
||||
|
||||
/** 更新者 */
|
||||
@TableField(fill = FieldFill.INSERT_UPDATE)
|
||||
private String updateBy;
|
||||
|
||||
/** 更新时间 */
|
||||
@TableField(fill = FieldFill.INSERT_UPDATE)
|
||||
private Date updateTime;
|
||||
}
|
||||
@@ -1,40 +0,0 @@
|
||||
package com.ruoyi.ccdi.domain.dto;
|
||||
|
||||
import jakarta.validation.constraints.NotBlank;
|
||||
import jakarta.validation.constraints.Pattern;
|
||||
import jakarta.validation.constraints.Size;
|
||||
import lombok.Data;
|
||||
|
||||
import java.io.Serial;
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* 员工亲属新增 DTO
|
||||
*
|
||||
* @author ruoyi
|
||||
* @date 2026-01-28
|
||||
*/
|
||||
@Data
|
||||
public class CcdiEmployeeRelativeAddDTO implements Serializable {
|
||||
|
||||
@Serial
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
/** 亲属姓名 */
|
||||
@NotBlank(message = "亲属姓名不能为空")
|
||||
@Size(max = 100, message = "亲属姓名长度不能超过100个字符")
|
||||
private String relativeName;
|
||||
|
||||
/** 亲属身份证号 */
|
||||
@Pattern(regexp = "^[1-9]\\d{5}(18|19|20)\\d{2}(0[1-9]|1[0-2])(0[1-9]|[12]\\d|3[01])\\d{3}[0-9Xx]$", message = "亲属身份证号格式不正确")
|
||||
private String relativeIdCard;
|
||||
|
||||
/** 亲属手机号 */
|
||||
@Pattern(regexp = "^1[3-9]\\d{9}$", message = "亲属手机号格式不正确")
|
||||
private String relativePhone;
|
||||
|
||||
/** 与员工关系 */
|
||||
@NotBlank(message = "与员工关系不能为空")
|
||||
@Size(max = 50, message = "与员工关系长度不能超过50个字符")
|
||||
private String relationship;
|
||||
}
|
||||
@@ -3,6 +3,7 @@ package com.ruoyi.ccdi.domain.excel;
|
||||
import com.alibaba.excel.annotation.ExcelProperty;
|
||||
import com.alibaba.excel.annotation.write.style.ColumnWidth;
|
||||
import com.ruoyi.common.annotation.DictDropdown;
|
||||
import com.ruoyi.common.annotation.Required;
|
||||
import lombok.Data;
|
||||
|
||||
import java.io.Serial;
|
||||
@@ -24,26 +25,31 @@ public class CcdiEmployeeExcel implements Serializable {
|
||||
/** 姓名 */
|
||||
@ExcelProperty(value = "姓名", index = 0)
|
||||
@ColumnWidth(15)
|
||||
@Required
|
||||
private String name;
|
||||
|
||||
/** 员工ID(柜员号) */
|
||||
@ExcelProperty(value = "柜员号", index = 1)
|
||||
@ColumnWidth(15)
|
||||
@Required
|
||||
private Long employeeId;
|
||||
|
||||
/** 所属部门ID */
|
||||
@ExcelProperty(value = "所属部门ID", index = 2)
|
||||
@ColumnWidth(15)
|
||||
@Required
|
||||
private Long deptId;
|
||||
|
||||
/** 身份证号 */
|
||||
@ExcelProperty(value = "身份证号", index = 3)
|
||||
@ColumnWidth(20)
|
||||
@Required
|
||||
private String idCard;
|
||||
|
||||
/** 电话 */
|
||||
@ExcelProperty(value = "电话", index = 4)
|
||||
@ColumnWidth(15)
|
||||
@Required
|
||||
private String phone;
|
||||
|
||||
/** 入职时间 */
|
||||
@@ -55,5 +61,6 @@ public class CcdiEmployeeExcel implements Serializable {
|
||||
@ExcelProperty(value = "状态", index = 6)
|
||||
@ColumnWidth(10)
|
||||
@DictDropdown(dictType = "ccdi_employee_status")
|
||||
@Required
|
||||
private String status;
|
||||
}
|
||||
|
||||
@@ -1,41 +0,0 @@
|
||||
package com.ruoyi.ccdi.domain.excel;
|
||||
|
||||
import com.alibaba.excel.annotation.ExcelProperty;
|
||||
import com.alibaba.excel.annotation.write.style.ColumnWidth;
|
||||
import lombok.Data;
|
||||
|
||||
import java.io.Serial;
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* 员工亲属Excel导入导出对象
|
||||
*
|
||||
* @author ruoyi
|
||||
* @date 2026-01-28
|
||||
*/
|
||||
@Data
|
||||
public class CcdiEmployeeRelativeExcel implements Serializable {
|
||||
|
||||
@Serial
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
/** 亲属姓名 */
|
||||
@ExcelProperty(value = "亲属姓名", index = 0)
|
||||
@ColumnWidth(15)
|
||||
private String relativeName;
|
||||
|
||||
/** 亲属身份证号 */
|
||||
@ExcelProperty(value = "亲属身份证号", index = 1)
|
||||
@ColumnWidth(20)
|
||||
private String relativeIdCard;
|
||||
|
||||
/** 亲属手机号 */
|
||||
@ExcelProperty(value = "亲属手机号", index = 2)
|
||||
@ColumnWidth(15)
|
||||
private String relativePhone;
|
||||
|
||||
/** 与员工关系 */
|
||||
@ExcelProperty(value = "与员工关系", index = 3)
|
||||
@ColumnWidth(15)
|
||||
private String relationship;
|
||||
}
|
||||
@@ -1,37 +0,0 @@
|
||||
package com.ruoyi.ccdi.domain.vo;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import java.io.Serial;
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* 员工亲属 VO
|
||||
*
|
||||
* @author ruoyi
|
||||
* @date 2026-01-28
|
||||
*/
|
||||
@Data
|
||||
public class CcdiEmployeeRelativeVO implements Serializable {
|
||||
|
||||
@Serial
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
/** 亲属ID */
|
||||
private Long relativeId;
|
||||
|
||||
/** 员工ID */
|
||||
private Long employeeId;
|
||||
|
||||
/** 亲属姓名 */
|
||||
private String relativeName;
|
||||
|
||||
/** 亲属身份证号 */
|
||||
private String relativeIdCard;
|
||||
|
||||
/** 亲属手机号 */
|
||||
private String relativePhone;
|
||||
|
||||
/** 与员工关系 */
|
||||
private String relationship;
|
||||
}
|
||||
@@ -1,13 +0,0 @@
|
||||
package com.ruoyi.ccdi.mapper;
|
||||
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import com.ruoyi.ccdi.domain.CcdiEmployeeRelative;
|
||||
|
||||
/**
|
||||
* 员工亲属 数据层
|
||||
*
|
||||
* @author ruoyi
|
||||
* @date 2026-01-28
|
||||
*/
|
||||
public interface CcdiEmployeeRelativeMapper extends BaseMapper<CcdiEmployeeRelative> {
|
||||
}
|
||||
@@ -4,6 +4,7 @@ import com.alibaba.excel.EasyExcel;
|
||||
import com.alibaba.excel.write.handler.WriteHandler;
|
||||
import com.alibaba.excel.write.style.column.LongestMatchColumnWidthStyleStrategy;
|
||||
import com.ruoyi.ccdi.handler.DictDropdownWriteHandler;
|
||||
import com.ruoyi.ccdi.handler.RequiredFieldWriteHandler;
|
||||
import jakarta.servlet.http.HttpServletResponse;
|
||||
import lombok.AccessLevel;
|
||||
import lombok.NoArgsConstructor;
|
||||
@@ -159,6 +160,7 @@ public class EasyExcelUtil {
|
||||
/**
|
||||
* 下载带字典下拉框的导入模板
|
||||
* 自动解析实体类中的@DictDropdown注解,为对应字段添加下拉框
|
||||
* 自动解析实体类中的@Required注解,为必填字段表头添加红色星号(*)标记
|
||||
*
|
||||
* @param response 响应对象
|
||||
* @param clazz 实体类
|
||||
@@ -172,6 +174,7 @@ public class EasyExcelUtil {
|
||||
.sheet(sheetName)
|
||||
.registerWriteHandler(new LongestMatchColumnWidthStyleStrategy())
|
||||
.registerWriteHandler(new DictDropdownWriteHandler(clazz))
|
||||
.registerWriteHandler(new RequiredFieldWriteHandler(clazz))
|
||||
.doWrite(List.of());
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeException("下载带字典下拉框的导入模板失败", e);
|
||||
@@ -181,6 +184,7 @@ public class EasyExcelUtil {
|
||||
/**
|
||||
* 下载带字典下拉框的导入模板(指定文件名)
|
||||
* 自动解析实体类中的@DictDropdown注解,为对应字段添加下拉框
|
||||
* 自动解析实体类中的@Required注解,为必填字段表头添加红色星号(*)标记
|
||||
*
|
||||
* @param response 响应对象
|
||||
* @param clazz 实体类
|
||||
@@ -196,6 +200,7 @@ public class EasyExcelUtil {
|
||||
.sheet(sheetName)
|
||||
.registerWriteHandler(new LongestMatchColumnWidthStyleStrategy())
|
||||
.registerWriteHandler(new DictDropdownWriteHandler(clazz))
|
||||
.registerWriteHandler(new RequiredFieldWriteHandler(clazz))
|
||||
.doWrite(List.of());
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeException("下载带字典下拉框的导入模板失败", e);
|
||||
@@ -205,6 +210,7 @@ public class EasyExcelUtil {
|
||||
/**
|
||||
* 导出Excel(带字典下拉框)
|
||||
* 导出的数据包含实际值,但模板中有下拉框供后续编辑使用
|
||||
* 自动解析实体类中的@Required注解,为必填字段表头添加红色星号(*)标记
|
||||
*
|
||||
* @param response 响应对象
|
||||
* @param list 数据列表
|
||||
@@ -220,6 +226,7 @@ public class EasyExcelUtil {
|
||||
.sheet(sheetName)
|
||||
.registerWriteHandler(new LongestMatchColumnWidthStyleStrategy())
|
||||
.registerWriteHandler(new DictDropdownWriteHandler(clazz))
|
||||
.registerWriteHandler(new RequiredFieldWriteHandler(clazz))
|
||||
.doWrite(list);
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeException("导出带字典下拉框的Excel失败", e);
|
||||
@@ -229,6 +236,7 @@ public class EasyExcelUtil {
|
||||
/**
|
||||
* 导出Excel(带字典下拉框,指定文件名)
|
||||
* 导出的数据包含实际值,但模板中有下拉框供后续编辑使用
|
||||
* 自动解析实体类中的@Required注解,为必填字段表头添加红色星号(*)标记
|
||||
*
|
||||
* @param response 响应对象
|
||||
* @param list 数据列表
|
||||
@@ -245,6 +253,7 @@ public class EasyExcelUtil {
|
||||
.sheet(sheetName)
|
||||
.registerWriteHandler(new LongestMatchColumnWidthStyleStrategy())
|
||||
.registerWriteHandler(new DictDropdownWriteHandler(clazz))
|
||||
.registerWriteHandler(new RequiredFieldWriteHandler(clazz))
|
||||
.doWrite(list);
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeException("导出带字典下拉框的Excel失败", e);
|
||||
|
||||
@@ -0,0 +1,70 @@
|
||||
package com.ruoyi.ccdi.validation;
|
||||
|
||||
import com.ruoyi.ccdi.annotation.EnumValid;
|
||||
import jakarta.validation.ConstraintValidator;
|
||||
import jakarta.validation.ConstraintValidatorContext;
|
||||
|
||||
import java.lang.reflect.Method;
|
||||
|
||||
/**
|
||||
* 枚举值校验器
|
||||
* 验证字段值是否在指定枚举类的定义范围内
|
||||
*
|
||||
* @author ruoyi
|
||||
*/
|
||||
public class EnumValidator implements ConstraintValidator<EnumValid, String> {
|
||||
|
||||
private EnumValid annotation;
|
||||
|
||||
@Override
|
||||
public void initialize(EnumValid constraintAnnotation) {
|
||||
this.annotation = constraintAnnotation;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isValid(String value, ConstraintValidatorContext constraintValidatorContext) {
|
||||
// 如果允许忽略空值且值为空,则校验通过
|
||||
if (annotation.ignoreEmpty() && (value == null || value.trim().isEmpty())) {
|
||||
return true;
|
||||
}
|
||||
|
||||
// 如果值为空且不允许忽略,则校验失败
|
||||
if (value == null || value.trim().isEmpty()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
Class<?> enumClass = annotation.enumClass();
|
||||
|
||||
// 检查是否是枚举类
|
||||
if (!enumClass.isEnum()) {
|
||||
throw new IllegalArgumentException(enumClass.getName() + " 不是枚举类型");
|
||||
}
|
||||
|
||||
// 获取枚举的所有实例
|
||||
Object[] enumConstants = enumClass.getEnumConstants();
|
||||
|
||||
try {
|
||||
// 尝试调用枚举的getCode方法(如果存在)
|
||||
// 假设枚举类有getCode()方法返回枚举的code值
|
||||
for (Object enumConstant : enumConstants) {
|
||||
try {
|
||||
Method getCodeMethod = enumClass.getMethod("getCode");
|
||||
String code = (String) getCodeMethod.invoke(enumConstant);
|
||||
if (value.equals(code)) {
|
||||
return true;
|
||||
}
|
||||
} catch (NoSuchMethodException e) {
|
||||
// 如果没有getCode方法,使用name()方法
|
||||
Enum<?> enumValue = (Enum<?>) enumConstant;
|
||||
if (value.equals(enumValue.name())) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException("枚举校验失败", e);
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user