员工信息管理

- 新增员工信息CRUD功能
- 添加员工关联人员管理
- 配置MyBatis Plus审计字段
- 添加OpenSpec规范文档
- 新增测试脚本和数据

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
wkc
2026-01-28 14:40:27 +08:00
parent 6946744ab9
commit 0cc8ef0fc3
32 changed files with 2841 additions and 9 deletions

View File

@@ -0,0 +1,138 @@
package com.ruoyi.dpc.controller;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.dpc.domain.DpcEmployee;
import com.ruoyi.dpc.domain.dto.DpcEmployeeAddDTO;
import com.ruoyi.dpc.domain.dto.DpcEmployeeEditDTO;
import com.ruoyi.dpc.domain.dto.DpcEmployeeQueryDTO;
import com.ruoyi.dpc.domain.vo.DpcEmployeeVO;
import com.ruoyi.dpc.service.IDpcEmployeeService;
import jakarta.annotation.Resource;
import jakarta.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import java.util.List;
/**
* 员工信息Controller
*
* @author ruoyi
* @date 2026-01-28
*/
@RestController
@RequestMapping("/dpc/employee")
public class DpcEmployeeController extends BaseController {
@Resource
private IDpcEmployeeService employeeService;
/**
* 查询员工列表
*/
@PreAuthorize("@ss.hasPermi('dpc:employee:list')")
@GetMapping("/list")
public TableDataInfo list(DpcEmployeeQueryDTO queryDTO) {
startPage();
List<DpcEmployeeVO> list = employeeService.selectEmployeeList(queryDTO);
return getDataTable(list);
}
/**
* 导出员工列表
*/
@PreAuthorize("@ss.hasPermi('dpc:employee:export')")
@Log(title = "员工信息", businessType = BusinessType.EXPORT)
@PostMapping("/export")
public void export(HttpServletResponse response, DpcEmployeeQueryDTO queryDTO) {
List<DpcEmployee> list = employeeService.selectEmployeeListForExport(queryDTO);
ExcelUtil<DpcEmployee> util = new ExcelUtil<>(DpcEmployee.class);
util.exportExcel(response, list, "员工信息数据");
}
/**
* 获取员工详细信息
*/
@PreAuthorize("@ss.hasPermi('dpc:employee:query')")
@GetMapping(value = "/{employeeId}")
public AjaxResult getInfo(@PathVariable Long employeeId) {
return success(employeeService.selectEmployeeById(employeeId));
}
/**
* 新增员工
*/
@PreAuthorize("@ss.hasPermi('dpc:employee:add')")
@Log(title = "员工信息", businessType = BusinessType.INSERT)
@PostMapping
public AjaxResult add(@Validated @RequestBody DpcEmployeeAddDTO addDTO) {
return toAjax(employeeService.insertEmployee(addDTO));
}
/**
* 修改员工
*/
@PreAuthorize("@ss.hasPermi('dpc:employee:edit')")
@Log(title = "员工信息", businessType = BusinessType.UPDATE)
@PutMapping
public AjaxResult edit(@Validated @RequestBody DpcEmployeeEditDTO editDTO) {
return toAjax(employeeService.updateEmployee(editDTO));
}
/**
* 删除员工
*/
@PreAuthorize("@ss.hasPermi('dpc:employee:remove')")
@Log(title = "员工信息", businessType = BusinessType.DELETE)
@DeleteMapping("/{employeeIds}")
public AjaxResult remove(@PathVariable Long[] employeeIds) {
return toAjax(employeeService.deleteEmployeeByIds(employeeIds));
}
/**
* 下载导入模板
*/
@PostMapping("/importTemplate")
public void importTemplate(HttpServletResponse response) {
ExcelUtil<DpcEmployee> util = new ExcelUtil<>(DpcEmployee.class);
util.importTemplateExcel(response, "员工信息数据");
}
/**
* 导入员工信息
*/
@PreAuthorize("@ss.hasPermi('dpc:employee:import')")
@Log(title = "员工信息", businessType = BusinessType.IMPORT)
@PostMapping("/importData")
public AjaxResult importData(MultipartFile file, boolean updateSupport) throws Exception {
ExcelUtil<DpcEmployee> util = new ExcelUtil<>(DpcEmployee.class);
List<DpcEmployee> list = util.importExcel(file.getInputStream());
List<DpcEmployeeAddDTO> addDTOList = convertToAddDTOList(list);
String message = employeeService.importEmployee(addDTOList, updateSupport);
return success(message);
}
/**
* 转换为AddDTO列表
*/
private List<DpcEmployeeAddDTO> convertToAddDTOList(List<DpcEmployee> list) {
return list.stream().map(entity -> {
DpcEmployeeAddDTO dto = new DpcEmployeeAddDTO();
dto.setName(entity.getName());
dto.setTellerNo(entity.getTellerNo());
dto.setOrgNo(entity.getOrgNo());
dto.setIdCard(entity.getIdCard());
dto.setPhone(entity.getPhone());
dto.setHireDate(entity.getHireDate());
dto.setStatus(entity.getStatus());
return dto;
}).toList();
}
}

View File

@@ -0,0 +1,73 @@
package com.ruoyi.dpc.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 com.ruoyi.common.annotation.Excel;
import lombok.Data;
import java.io.Serial;
import java.io.Serializable;
import java.util.Date;
/**
* 员工信息对象 dpc_employee
*
* @author ruoyi
* @date 2026-01-28
*/
@Data
public class DpcEmployee implements Serializable {
@Serial
private static final long serialVersionUID = 1L;
/** 员工ID */
@TableId(type = IdType.AUTO)
private Long employeeId;
/** 姓名 */
@Excel(name = "姓名")
private String name;
/** 柜员号 */
@Excel(name = "柜员号")
private String tellerNo;
/** 所属机构号 */
@Excel(name = "所属机构号")
private String orgNo;
/** 身份证号 */
@Excel(name = "身份证号")
private String idCard;
/** 电话 */
@Excel(name = "电话")
private String phone;
/** 入职时间 */
@Excel(name = "入职时间", dateFormat = "yyyy-MM-dd")
private Date hireDate;
/** 状态 */
@Excel(name = "状态", readConverterExp = "0=在职,1=离职")
private String status;
/** 创建者 */
@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;
}

View File

@@ -0,0 +1,64 @@
package com.ruoyi.dpc.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 com.ruoyi.common.annotation.Excel;
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 DpcEmployeeRelative implements Serializable {
@Serial
private static final long serialVersionUID = 1L;
/** 亲属ID */
@TableId(type = IdType.AUTO)
private Long relativeId;
/** 员工ID */
private Long employeeId;
/** 亲属姓名 */
@Excel(name = "亲属姓名")
private String relativeName;
/** 亲属身份证号 */
@Excel(name = "亲属身份证号")
private String relativeIdCard;
/** 亲属手机号 */
@Excel(name = "亲属手机号")
private String relativePhone;
/** 与员工关系 */
@Excel(name = "与员工关系")
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;
}

View File

@@ -0,0 +1,65 @@
package com.ruoyi.dpc.domain.dto;
import com.ruoyi.common.annotation.Excel;
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;
import java.util.Date;
import java.util.List;
/**
* 员工信息新增 DTO
*
* @author ruoyi
* @date 2026-01-28
*/
@Data
public class DpcEmployeeAddDTO implements Serializable {
@Serial
private static final long serialVersionUID = 1L;
/** 姓名 */
@Excel(name = "姓名")
@NotBlank(message = "姓名不能为空")
@Size(max = 100, message = "姓名长度不能超过100个字符")
private String name;
/** 柜员号 */
@Excel(name = "柜员号")
@NotBlank(message = "柜员号不能为空")
@Size(max = 50, message = "柜员号长度不能超过50个字符")
private String tellerNo;
/** 所属机构号 */
@Excel(name = "所属机构号")
@Size(max = 50, message = "所属机构号长度不能超过50个字符")
private String orgNo;
/** 身份证号 */
@Excel(name = "身份证号")
@NotBlank(message = "身份证号不能为空")
@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 idCard;
/** 电话 */
@Excel(name = "电话")
@Pattern(regexp = "^1[3-9]\\d{9}$", message = "电话格式不正确")
private String phone;
/** 入职时间 */
@Excel(name = "入职时间", dateFormat = "yyyy-MM-dd")
private Date hireDate;
/** 状态 */
@Excel(name = "状态", readConverterExp = "0=在职,1=离职")
@NotBlank(message = "状态不能为空")
private String status;
/** 亲属列表 */
private List<DpcEmployeeRelativeAddDTO> relatives;
}

View File

@@ -0,0 +1,65 @@
package com.ruoyi.dpc.domain.dto;
import com.ruoyi.common.annotation.Excel;
import jakarta.validation.constraints.NotNull;
import jakarta.validation.constraints.Pattern;
import jakarta.validation.constraints.Size;
import lombok.Data;
import java.io.Serial;
import java.io.Serializable;
import java.util.Date;
import java.util.List;
/**
* 员工信息编辑 DTO
*
* @author ruoyi
* @date 2026-01-28
*/
@Data
public class DpcEmployeeEditDTO implements Serializable {
@Serial
private static final long serialVersionUID = 1L;
/** 员工ID */
@NotNull(message = "员工ID不能为空")
private Long employeeId;
/** 姓名 */
@Excel(name = "姓名")
@Size(max = 100, message = "姓名长度不能超过100个字符")
private String name;
/** 柜员号 */
@Excel(name = "柜员号")
@Size(max = 50, message = "柜员号长度不能超过50个字符")
private String tellerNo;
/** 所属机构号 */
@Excel(name = "所属机构号")
@Size(max = 50, message = "所属机构号长度不能超过50个字符")
private String orgNo;
/** 身份证号 */
@Excel(name = "身份证号")
@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 idCard;
/** 电话 */
@Excel(name = "电话")
@Pattern(regexp = "^1[3-9]\\d{9}$", message = "电话格式不正确")
private String phone;
/** 入职时间 */
@Excel(name = "入职时间", dateFormat = "yyyy-MM-dd")
private Date hireDate;
/** 状态 */
@Excel(name = "状态", readConverterExp = "0=在职,1=离职")
private String status;
/** 亲属列表 */
private List<DpcEmployeeRelativeAddDTO> relatives;
}

View File

@@ -0,0 +1,34 @@
package com.ruoyi.dpc.domain.dto;
import lombok.Data;
import java.io.Serial;
import java.io.Serializable;
/**
* 员工信息查询 DTO
*
* @author ruoyi
* @date 2026-01-28
*/
@Data
public class DpcEmployeeQueryDTO implements Serializable {
@Serial
private static final long serialVersionUID = 1L;
/** 姓名(模糊查询) */
private String name;
/** 柜员号(精确查询) */
private String tellerNo;
/** 所属机构号 */
private String orgNo;
/** 身份证号(精确查询) */
private String idCard;
/** 状态 */
private String status;
}

View File

@@ -0,0 +1,45 @@
package com.ruoyi.dpc.domain.dto;
import com.ruoyi.common.annotation.Excel;
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 DpcEmployeeRelativeAddDTO implements Serializable {
@Serial
private static final long serialVersionUID = 1L;
/** 亲属姓名 */
@Excel(name = "亲属姓名")
@NotBlank(message = "亲属姓名不能为空")
@Size(max = 100, message = "亲属姓名长度不能超过100个字符")
private String relativeName;
/** 亲属身份证号 */
@Excel(name = "亲属身份证号")
@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;
/** 亲属手机号 */
@Excel(name = "亲属手机号")
@Pattern(regexp = "^1[3-9]\\d{9}$", message = "亲属手机号格式不正确")
private String relativePhone;
/** 与员工关系 */
@Excel(name = "与员工关系")
@NotBlank(message = "与员工关系不能为空")
@Size(max = 50, message = "与员工关系长度不能超过50个字符")
private String relationship;
}

View File

@@ -0,0 +1,37 @@
package com.ruoyi.dpc.domain.vo;
import lombok.Data;
import java.io.Serial;
import java.io.Serializable;
/**
* 员工亲属 VO
*
* @author ruoyi
* @date 2026-01-28
*/
@Data
public class DpcEmployeeRelativeVO 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;
}

View File

@@ -0,0 +1,63 @@
package com.ruoyi.dpc.domain.vo;
import lombok.Data;
import java.io.Serial;
import java.io.Serializable;
import java.util.Date;
import java.util.List;
/**
* 员工信息 VO
*
* @author ruoyi
* @date 2026-01-28
*/
@Data
public class DpcEmployeeVO implements Serializable {
@Serial
private static final long serialVersionUID = 1L;
/** 员工ID */
private Long employeeId;
/** 姓名 */
private String name;
/** 柜员号 */
private String tellerNo;
/** 所属机构号 */
private String orgNo;
/** 身份证号 */
private String idCard;
/** 电话 */
private String phone;
/** 入职时间 */
private Date hireDate;
/** 状态 */
private String status;
/** 状态描述 */
private String statusDesc;
/** 创建时间 */
private Date createTime;
/** 创建者 */
private String createBy;
/** 更新时间 */
private Date updateTime;
/** 更新者 */
private String updateBy;
/** 亲属列表 */
private List<DpcEmployeeRelativeVO> relatives;
}

View File

@@ -0,0 +1,23 @@
package com.ruoyi.dpc.mapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.ruoyi.dpc.domain.DpcEmployee;
import com.ruoyi.dpc.domain.vo.DpcEmployeeVO;
import org.apache.ibatis.annotations.Param;
/**
* 员工信息 数据层
*
* @author ruoyi
* @date 2026-01-28
*/
public interface DpcEmployeeMapper extends BaseMapper<DpcEmployee> {
/**
* 查询员工详情(包含亲属列表)
*
* @param employeeId 员工ID
* @return 员工VO
*/
DpcEmployeeVO selectEmployeeWithRelatives(@Param("employeeId") Long employeeId);
}

View File

@@ -0,0 +1,13 @@
package com.ruoyi.dpc.mapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.ruoyi.dpc.domain.DpcEmployeeRelative;
/**
* 员工亲属 数据层
*
* @author ruoyi
* @date 2026-01-28
*/
public interface DpcEmployeeRelativeMapper extends BaseMapper<DpcEmployeeRelative> {
}

View File

@@ -0,0 +1,75 @@
package com.ruoyi.dpc.service;
import com.ruoyi.dpc.domain.DpcEmployee;
import com.ruoyi.dpc.domain.dto.DpcEmployeeAddDTO;
import com.ruoyi.dpc.domain.dto.DpcEmployeeEditDTO;
import com.ruoyi.dpc.domain.dto.DpcEmployeeQueryDTO;
import com.ruoyi.dpc.domain.vo.DpcEmployeeVO;
import java.util.List;
/**
* 员工信息 服务层
*
* @author ruoyi
* @date 2026-01-28
*/
public interface IDpcEmployeeService {
/**
* 查询员工列表
*
* @param queryDTO 查询条件
* @return 员工VO集合
*/
List<DpcEmployeeVO> selectEmployeeList(DpcEmployeeQueryDTO queryDTO);
/**
* 查询员工列表(用于导出)
*
* @param queryDTO 查询条件
* @return 员工实体集合
*/
List<DpcEmployee> selectEmployeeListForExport(DpcEmployeeQueryDTO queryDTO);
/**
* 查询员工详情
*
* @param employeeId 员工ID
* @return 员工VO
*/
DpcEmployeeVO selectEmployeeById(Long employeeId);
/**
* 新增员工
*
* @param addDTO 新增DTO
* @return 结果
*/
int insertEmployee(DpcEmployeeAddDTO addDTO);
/**
* 修改员工
*
* @param editDTO 编辑DTO
* @return 结果
*/
int updateEmployee(DpcEmployeeEditDTO editDTO);
/**
* 批量删除员工
*
* @param employeeIds 需要删除的员工ID
* @return 结果
*/
int deleteEmployeeByIds(Long[] employeeIds);
/**
* 导入员工数据
*
* @param addDTOList 新增DTO列表
* @param isUpdateSupport 是否更新支持
* @return 结果
*/
String importEmployee(List<DpcEmployeeAddDTO> addDTOList, Boolean isUpdateSupport);
}

View File

@@ -0,0 +1,291 @@
package com.ruoyi.dpc.service.impl;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.dpc.domain.DpcEmployee;
import com.ruoyi.dpc.domain.DpcEmployeeRelative;
import com.ruoyi.dpc.domain.dto.DpcEmployeeAddDTO;
import com.ruoyi.dpc.domain.dto.DpcEmployeeEditDTO;
import com.ruoyi.dpc.domain.dto.DpcEmployeeQueryDTO;
import com.ruoyi.dpc.domain.dto.DpcEmployeeRelativeAddDTO;
import com.ruoyi.dpc.domain.vo.DpcEmployeeVO;
import com.ruoyi.dpc.mapper.DpcEmployeeMapper;
import com.ruoyi.dpc.mapper.DpcEmployeeRelativeMapper;
import com.ruoyi.dpc.service.IDpcEmployeeService;
import jakarta.annotation.Resource;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.util.ArrayList;
import java.util.List;
/**
* 员工信息 服务层处理
*
* @author ruoyi
* @date 2026-01-28
*/
@Service
public class DpcEmployeeServiceImpl implements IDpcEmployeeService {
@Resource
private DpcEmployeeMapper employeeMapper;
@Resource
private DpcEmployeeRelativeMapper relativeMapper;
/**
* 查询员工列表
*
* @param queryDTO 查询条件
* @return 员工VO集合
*/
@Override
public List<DpcEmployeeVO> selectEmployeeList(DpcEmployeeQueryDTO queryDTO) {
LambdaQueryWrapper<DpcEmployee> wrapper = buildQueryWrapper(queryDTO);
List<DpcEmployee> list = employeeMapper.selectList(wrapper);
List<DpcEmployeeVO> voList = new ArrayList<>();
for (DpcEmployee employee : list) {
voList.add(convertToVO(employee));
}
return voList;
}
/**
* 查询员工列表(用于导出)
*
* @param queryDTO 查询条件
* @return 员工实体集合
*/
@Override
public List<DpcEmployee> selectEmployeeListForExport(DpcEmployeeQueryDTO queryDTO) {
LambdaQueryWrapper<DpcEmployee> wrapper = buildQueryWrapper(queryDTO);
return employeeMapper.selectList(wrapper);
}
/**
* 查询员工详情
*
* @param employeeId 员工ID
* @return 员工VO
*/
@Override
public DpcEmployeeVO selectEmployeeById(Long employeeId) {
return employeeMapper.selectEmployeeWithRelatives(employeeId);
}
/**
* 新增员工
*
* @param addDTO 新增DTO
* @return 结果
*/
@Override
@Transactional
public int insertEmployee(DpcEmployeeAddDTO addDTO) {
// 检查柜员号唯一性
LambdaQueryWrapper<DpcEmployee> wrapper = new LambdaQueryWrapper<>();
wrapper.eq(DpcEmployee::getTellerNo, addDTO.getTellerNo());
if (employeeMapper.selectCount(wrapper) > 0) {
throw new RuntimeException("该柜员号已存在");
}
// 检查身份证号唯一性
wrapper = new LambdaQueryWrapper<>();
wrapper.eq(DpcEmployee::getIdCard, addDTO.getIdCard());
if (employeeMapper.selectCount(wrapper) > 0) {
throw new RuntimeException("该身份证号已存在");
}
DpcEmployee employee = new DpcEmployee();
BeanUtils.copyProperties(addDTO, employee);
int result = employeeMapper.insert(employee);
// 插入亲属信息
if (addDTO.getRelatives() != null && !addDTO.getRelatives().isEmpty()) {
for (DpcEmployeeRelativeAddDTO relativeAddDTO : addDTO.getRelatives()) {
DpcEmployeeRelative relative = new DpcEmployeeRelative();
BeanUtils.copyProperties(relativeAddDTO, relative);
relative.setEmployeeId(employee.getEmployeeId());
relativeMapper.insert(relative);
}
}
return result;
}
/**
* 修改员工
*
* @param editDTO 编辑DTO
* @return 结果
*/
@Override
@Transactional
public int updateEmployee(DpcEmployeeEditDTO editDTO) {
// 检查柜员号唯一性(排除自己)
if (StringUtils.isNotEmpty(editDTO.getTellerNo())) {
LambdaQueryWrapper<DpcEmployee> wrapper = new LambdaQueryWrapper<>();
wrapper.eq(DpcEmployee::getTellerNo, editDTO.getTellerNo())
.ne(DpcEmployee::getEmployeeId, editDTO.getEmployeeId());
if (employeeMapper.selectCount(wrapper) > 0) {
throw new RuntimeException("该柜员号已存在");
}
}
// 检查身份证号唯一性(排除自己)
if (StringUtils.isNotEmpty(editDTO.getIdCard())) {
LambdaQueryWrapper<DpcEmployee> wrapper = new LambdaQueryWrapper<>();
wrapper.eq(DpcEmployee::getIdCard, editDTO.getIdCard())
.ne(DpcEmployee::getEmployeeId, editDTO.getEmployeeId());
if (employeeMapper.selectCount(wrapper) > 0) {
throw new RuntimeException("该身份证号已存在");
}
}
DpcEmployee employee = new DpcEmployee();
BeanUtils.copyProperties(editDTO, employee);
int result = employeeMapper.updateById(employee);
// 删除原有亲属信息
LambdaQueryWrapper<DpcEmployeeRelative> wrapper = new LambdaQueryWrapper<>();
wrapper.eq(DpcEmployeeRelative::getEmployeeId, editDTO.getEmployeeId());
relativeMapper.delete(wrapper);
// 插入新的亲属信息
if (editDTO.getRelatives() != null && !editDTO.getRelatives().isEmpty()) {
for (DpcEmployeeRelativeAddDTO relativeAddDTO : editDTO.getRelatives()) {
DpcEmployeeRelative relative = new DpcEmployeeRelative();
BeanUtils.copyProperties(relativeAddDTO, relative);
relative.setEmployeeId(editDTO.getEmployeeId());
relativeMapper.insert(relative);
}
}
return result;
}
/**
* 批量删除员工
*
* @param employeeIds 需要删除的员工ID
* @return 结果
*/
@Override
@Transactional
public int deleteEmployeeByIds(Long[] employeeIds) {
// 级联删除亲属信息
for (Long employeeId : employeeIds) {
LambdaQueryWrapper<DpcEmployeeRelative> wrapper = new LambdaQueryWrapper<>();
wrapper.eq(DpcEmployeeRelative::getEmployeeId, employeeId);
relativeMapper.delete(wrapper);
}
return employeeMapper.deleteBatchIds(List.of(employeeIds));
}
/**
* 导入员工数据
*
* @param addDTOList 新增DTO列表
* @param isUpdateSupport 是否更新支持
* @return 结果
*/
@Override
@Transactional
public String importEmployee(List<DpcEmployeeAddDTO> addDTOList, Boolean isUpdateSupport) {
if (StringUtils.isNull(addDTOList) || addDTOList.isEmpty()) {
return "至少需要一条数据";
}
int successNum = 0;
int failureNum = 0;
StringBuilder successMsg = new StringBuilder();
StringBuilder failureMsg = new StringBuilder();
for (DpcEmployeeAddDTO addDTO : addDTOList) {
try {
// 验证数据
validateEmployeeData(addDTO, isUpdateSupport);
DpcEmployee employee = new DpcEmployee();
BeanUtils.copyProperties(addDTO, employee);
employeeMapper.insert(employee);
successNum++;
successMsg.append("<br/>").append(successNum).append("").append(addDTO.getName()).append(" 导入成功");
} catch (Exception e) {
failureNum++;
failureMsg.append("<br/>").append(failureNum).append("").append(addDTO.getName()).append(" 导入失败:");
failureMsg.append(e.getMessage());
}
}
if (failureNum > 0) {
failureMsg.insert(0, "很抱歉,导入失败!共 " + failureNum + " 条数据格式不正确,错误如下:");
throw new RuntimeException(failureMsg.toString());
} else {
successMsg.insert(0, "恭喜您,数据已全部导入成功!共 " + successNum + "");
return successMsg.toString();
}
}
/**
* 构建查询条件
*/
private LambdaQueryWrapper<DpcEmployee> buildQueryWrapper(DpcEmployeeQueryDTO queryDTO) {
LambdaQueryWrapper<DpcEmployee> wrapper = new LambdaQueryWrapper<>();
wrapper.like(StringUtils.isNotEmpty(queryDTO.getName()), DpcEmployee::getName, queryDTO.getName())
.eq(StringUtils.isNotEmpty(queryDTO.getTellerNo()), DpcEmployee::getTellerNo, queryDTO.getTellerNo())
.eq(StringUtils.isNotEmpty(queryDTO.getOrgNo()), DpcEmployee::getOrgNo, queryDTO.getOrgNo())
.eq(StringUtils.isNotEmpty(queryDTO.getIdCard()), DpcEmployee::getIdCard, queryDTO.getIdCard())
.eq(StringUtils.isNotEmpty(queryDTO.getStatus()), DpcEmployee::getStatus, queryDTO.getStatus())
.orderByDesc(DpcEmployee::getCreateTime);
return wrapper;
}
/**
* 验证员工数据
*/
private void validateEmployeeData(DpcEmployeeAddDTO addDTO, Boolean isUpdateSupport) {
// 检查柜员号唯一性
LambdaQueryWrapper<DpcEmployee> wrapper = new LambdaQueryWrapper<>();
wrapper.eq(DpcEmployee::getTellerNo, addDTO.getTellerNo());
if (employeeMapper.selectCount(wrapper) > 0) {
throw new RuntimeException("该柜员号已存在");
}
// 检查身份证号唯一性
wrapper = new LambdaQueryWrapper<>();
wrapper.eq(DpcEmployee::getIdCard, addDTO.getIdCard());
if (employeeMapper.selectCount(wrapper) > 0) {
throw new RuntimeException("该身份证号已存在");
}
// 验证状态
if (!"0".equals(addDTO.getStatus()) && !"1".equals(addDTO.getStatus())) {
throw new RuntimeException("状态只能填写'在职'或'离职'");
}
}
/**
* 转换为VO对象
*/
private DpcEmployeeVO convertToVO(DpcEmployee employee) {
if (employee == null) {
return null;
}
DpcEmployeeVO vo = new DpcEmployeeVO();
BeanUtils.copyProperties(employee, vo);
// 设置状态描述
if ("0".equals(employee.getStatus())) {
vo.setStatusDesc("在职");
} else if ("1".equals(employee.getStatus())) {
vo.setStatusDesc("离职");
}
return vo;
}
}

View File

@@ -0,0 +1,36 @@
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.ruoyi.dpc.mapper.DpcEmployeeMapper">
<resultMap type="com.ruoyi.dpc.domain.vo.DpcEmployeeVO" id="DpcEmployeeVOResult">
<id property="employeeId" column="employee_id"/>
<result property="name" column="name"/>
<result property="tellerNo" column="teller_no"/>
<result property="orgNo" column="org_no"/>
<result property="idCard" column="id_card"/>
<result property="phone" column="phone"/>
<result property="hireDate" column="hire_date"/>
<result property="status" column="status"/>
<result property="createTime" column="create_time"/>
<collection property="relatives" ofType="com.ruoyi.dpc.domain.vo.DpcEmployeeRelativeVO">
<id property="relativeId" column="relative_id"/>
<result property="employeeId" column="employee_id"/>
<result property="relativeName" column="relative_name"/>
<result property="relativeIdCard" column="relative_id_card"/>
<result property="relativePhone" column="relative_phone"/>
<result property="relationship" column="relationship"/>
</collection>
</resultMap>
<select id="selectEmployeeWithRelatives" parameterType="Long" resultMap="DpcEmployeeVOResult">
SELECT
e.employee_id, e.name, e.teller_no, e.org_no, e.id_card, e.phone, e.hire_date, e.status, e.create_time,
r.relative_id, r.employee_id, r.relative_name, r.relative_id_card, r.relative_phone, r.relationship
FROM dpc_employee e
LEFT JOIN dpc_employee_relative r ON e.employee_id = r.employee_id
WHERE e.employee_id = #{employeeId}
</select>
</mapper>