删除旧的
This commit is contained in:
@@ -1,195 +0,0 @@
|
||||
package com.ruoyi.ccdi.controller;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.ruoyi.ccdi.domain.dto.CcdiStaffFmyRelationAddDTO;
|
||||
import com.ruoyi.ccdi.domain.dto.CcdiStaffFmyRelationEditDTO;
|
||||
import com.ruoyi.ccdi.domain.dto.CcdiStaffFmyRelationQueryDTO;
|
||||
import com.ruoyi.ccdi.domain.excel.CcdiStaffFmyRelationExcel;
|
||||
import com.ruoyi.ccdi.domain.vo.CcdiStaffFmyRelationVO;
|
||||
import com.ruoyi.ccdi.domain.vo.ImportResultVO;
|
||||
import com.ruoyi.ccdi.domain.vo.ImportStatusVO;
|
||||
import com.ruoyi.ccdi.domain.vo.StaffFmyRelationImportFailureVO;
|
||||
import com.ruoyi.ccdi.service.ICcdiStaffFmyRelationImportService;
|
||||
import com.ruoyi.ccdi.service.ICcdiStaffFmyRelationService;
|
||||
import com.ruoyi.ccdi.utils.EasyExcelUtil;
|
||||
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.PageDomain;
|
||||
import com.ruoyi.common.core.page.TableDataInfo;
|
||||
import com.ruoyi.common.core.page.TableSupport;
|
||||
import com.ruoyi.common.enums.BusinessType;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import io.swagger.v3.oas.annotations.Parameter;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
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-02-09
|
||||
*/
|
||||
@Tag(name = "员工亲属关系信息管理")
|
||||
@RestController
|
||||
@RequestMapping("/ccdi/staffFmyRelation")
|
||||
public class CcdiStaffFmyRelationController extends BaseController {
|
||||
|
||||
@Resource
|
||||
private ICcdiStaffFmyRelationService relationService;
|
||||
|
||||
@Resource
|
||||
private ICcdiStaffFmyRelationImportService relationImportService;
|
||||
|
||||
/**
|
||||
* 查询员工亲属关系列表
|
||||
*/
|
||||
@Operation(summary = "查询员工亲属关系列表")
|
||||
@PreAuthorize("@ss.hasPermi('ccdi:staffFmyRelation:list')")
|
||||
@GetMapping("/list")
|
||||
public TableDataInfo list(CcdiStaffFmyRelationQueryDTO queryDTO) {
|
||||
// 使用MyBatis Plus分页
|
||||
PageDomain pageDomain = TableSupport.buildPageRequest();
|
||||
Page<CcdiStaffFmyRelationVO> page = new Page<>(pageDomain.getPageNum(), pageDomain.getPageSize());
|
||||
Page<CcdiStaffFmyRelationVO> result = relationService.selectRelationPage(page, queryDTO);
|
||||
return getDataTable(result.getRecords(), result.getTotal());
|
||||
}
|
||||
|
||||
/**
|
||||
* 导出员工亲属关系列表
|
||||
*/
|
||||
@Operation(summary = "导出员工亲属关系列表")
|
||||
@PreAuthorize("@ss.hasPermi('ccdi:staffFmyRelation:export')")
|
||||
@Log(title = "员工亲属关系信息", businessType = BusinessType.EXPORT)
|
||||
@PostMapping("/export")
|
||||
public void export(HttpServletResponse response, CcdiStaffFmyRelationQueryDTO queryDTO) {
|
||||
List<CcdiStaffFmyRelationExcel> list = relationService.selectRelationListForExport(queryDTO);
|
||||
EasyExcelUtil.exportExcel(response, list, CcdiStaffFmyRelationExcel.class, "员工亲属关系信息");
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取员工亲属关系详细信息
|
||||
*/
|
||||
@Operation(summary = "获取员工亲属关系详细信息")
|
||||
@Parameter(name = "id", description = "主键ID", required = true)
|
||||
@PreAuthorize("@ss.hasPermi('ccdi:staffFmyRelation:query')")
|
||||
@GetMapping(value = "/{id}")
|
||||
public AjaxResult getInfo(@PathVariable Long id) {
|
||||
return success(relationService.selectRelationById(id));
|
||||
}
|
||||
|
||||
/**
|
||||
* 新增员工亲属关系
|
||||
*/
|
||||
@Operation(summary = "新增员工亲属关系")
|
||||
@PreAuthorize("@ss.hasPermi('ccdi:staffFmyRelation:add')")
|
||||
@Log(title = "员工亲属关系信息", businessType = BusinessType.INSERT)
|
||||
@PostMapping
|
||||
public AjaxResult add(@Validated @RequestBody CcdiStaffFmyRelationAddDTO addDTO) {
|
||||
return toAjax(relationService.insertRelation(addDTO));
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改员工亲属关系
|
||||
*/
|
||||
@Operation(summary = "修改员工亲属关系")
|
||||
@PreAuthorize("@ss.hasPermi('ccdi:staffFmyRelation:edit')")
|
||||
@Log(title = "员工亲属关系信息", businessType = BusinessType.UPDATE)
|
||||
@PutMapping
|
||||
public AjaxResult edit(@Validated @RequestBody CcdiStaffFmyRelationEditDTO editDTO) {
|
||||
return toAjax(relationService.updateRelation(editDTO));
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除员工亲属关系
|
||||
*/
|
||||
@Operation(summary = "删除员工亲属关系")
|
||||
@Parameter(name = "ids", description = "主键ID数组", required = true)
|
||||
@PreAuthorize("@ss.hasPermi('ccdi:staffFmyRelation:remove')")
|
||||
@Log(title = "员工亲属关系信息", businessType = BusinessType.DELETE)
|
||||
@DeleteMapping("/{ids}")
|
||||
public AjaxResult remove(@PathVariable Long[] ids) {
|
||||
return toAjax(relationService.deleteRelationByIds(ids));
|
||||
}
|
||||
|
||||
/**
|
||||
* 下载带字典下拉框的导入模板
|
||||
* 使用@DictDropdown注解自动添加下拉框
|
||||
*/
|
||||
@Operation(summary = "下载导入模板")
|
||||
@PostMapping("/importTemplate")
|
||||
public void importTemplate(HttpServletResponse response) {
|
||||
EasyExcelUtil.importTemplateWithDictDropdown(response, CcdiStaffFmyRelationExcel.class, "员工亲属关系信息");
|
||||
}
|
||||
|
||||
/**
|
||||
* 异步导入员工亲属关系
|
||||
*/
|
||||
@Operation(summary = "异步导入员工亲属关系")
|
||||
@Parameter(name = "file", description = "导入文件", required = true)
|
||||
@PreAuthorize("@ss.hasPermi('ccdi:staffFmyRelation:import')")
|
||||
@Log(title = "员工亲属关系信息", businessType = BusinessType.IMPORT)
|
||||
@PostMapping("/importData")
|
||||
public AjaxResult importData(@Parameter(description = "导入文件") MultipartFile file) throws Exception {
|
||||
List<CcdiStaffFmyRelationExcel> list = EasyExcelUtil.importExcel(file.getInputStream(), CcdiStaffFmyRelationExcel.class);
|
||||
|
||||
if (list == null || list.isEmpty()) {
|
||||
return error("至少需要一条数据");
|
||||
}
|
||||
|
||||
// 提交异步任务
|
||||
String taskId = relationService.importRelation(list);
|
||||
|
||||
// 立即返回,不等待后台任务完成
|
||||
ImportResultVO result = new ImportResultVO();
|
||||
result.setTaskId(taskId);
|
||||
result.setStatus("PROCESSING");
|
||||
result.setMessage("导入任务已提交,正在后台处理");
|
||||
|
||||
return AjaxResult.success("导入任务已提交,正在后台处理", result);
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询导入状态
|
||||
*/
|
||||
@Operation(summary = "查询导入状态")
|
||||
@Parameter(name = "taskId", description = "任务ID", required = true)
|
||||
@PreAuthorize("@ss.hasPermi('ccdi:staffFmyRelation:import')")
|
||||
@GetMapping("/importStatus/{taskId}")
|
||||
public AjaxResult getImportStatus(@PathVariable String taskId) {
|
||||
ImportStatusVO statusVO = relationImportService.getImportStatus(taskId);
|
||||
return success(statusVO);
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询导入失败记录
|
||||
*/
|
||||
@Operation(summary = "查询导入失败记录")
|
||||
@Parameter(name = "taskId", description = "任务ID", required = true)
|
||||
@Parameter(name = "pageNum", description = "页码", required = false)
|
||||
@Parameter(name = "pageSize", description = "每页条数", required = false)
|
||||
@PreAuthorize("@ss.hasPermi('ccdi:staffFmyRelation:import')")
|
||||
@GetMapping("/importFailures/{taskId}")
|
||||
public TableDataInfo getImportFailures(
|
||||
@PathVariable String taskId,
|
||||
@RequestParam(defaultValue = "1") Integer pageNum,
|
||||
@RequestParam(defaultValue = "10") Integer pageSize) {
|
||||
|
||||
List<StaffFmyRelationImportFailureVO> failures = relationImportService.getImportFailures(taskId);
|
||||
|
||||
// 手动分页
|
||||
int fromIndex = (pageNum - 1) * pageSize;
|
||||
int toIndex = Math.min(fromIndex + pageSize, failures.size());
|
||||
|
||||
List<StaffFmyRelationImportFailureVO> pageData = failures.subList(fromIndex, toIndex);
|
||||
|
||||
return getDataTable(pageData, failures.size());
|
||||
}
|
||||
}
|
||||
@@ -1,271 +0,0 @@
|
||||
package com.ruoyi.ccdi.service.impl;
|
||||
|
||||
import com.alibaba.fastjson2.JSON;
|
||||
import com.ruoyi.ccdi.domain.CcdiStaffFmyRelation;
|
||||
import com.ruoyi.ccdi.domain.dto.CcdiStaffFmyRelationAddDTO;
|
||||
import com.ruoyi.ccdi.domain.excel.CcdiStaffFmyRelationExcel;
|
||||
import com.ruoyi.ccdi.domain.vo.ImportResult;
|
||||
import com.ruoyi.ccdi.domain.vo.ImportStatusVO;
|
||||
import com.ruoyi.ccdi.domain.vo.StaffFmyRelationImportFailureVO;
|
||||
import com.ruoyi.ccdi.mapper.CcdiStaffFmyRelationMapper;
|
||||
import com.ruoyi.ccdi.service.ICcdiStaffFmyRelationImportService;
|
||||
import com.ruoyi.common.utils.StringUtils;
|
||||
import jakarta.annotation.Resource;
|
||||
import org.springframework.beans.BeanUtils;
|
||||
import org.springframework.data.redis.core.RedisTemplate;
|
||||
import org.springframework.scheduling.annotation.Async;
|
||||
import org.springframework.scheduling.annotation.EnableAsync;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* 员工亲属关系信息异步导入服务层处理
|
||||
*
|
||||
* @author ruoyi
|
||||
* @date 2026-02-09
|
||||
*/
|
||||
@Service
|
||||
@EnableAsync
|
||||
public class CcdiStaffFmyRelationImportServiceImpl implements ICcdiStaffFmyRelationImportService {
|
||||
|
||||
@Resource
|
||||
private CcdiStaffFmyRelationMapper relationMapper;
|
||||
|
||||
@Resource
|
||||
private RedisTemplate<String, Object> redisTemplate;
|
||||
|
||||
@Override
|
||||
@Async
|
||||
@Transactional
|
||||
public void importRelationAsync(List<CcdiStaffFmyRelationExcel> excelList, String taskId, String userName) {
|
||||
List<CcdiStaffFmyRelation> newRecords = new ArrayList<>();
|
||||
List<StaffFmyRelationImportFailureVO> failures = new ArrayList<>();
|
||||
|
||||
// 批量查询已存在的person_id + relation_cert_no组合
|
||||
Set<String> existingCombinations = getExistingCombinations(excelList);
|
||||
|
||||
// 用于跟踪Excel文件内已处理的组合
|
||||
Set<String> processedCombinations = new HashSet<>();
|
||||
|
||||
// 分类数据
|
||||
for (int i = 0; i < excelList.size(); i++) {
|
||||
CcdiStaffFmyRelationExcel excel = excelList.get(i);
|
||||
|
||||
try {
|
||||
// 转换为AddDTO进行验证
|
||||
CcdiStaffFmyRelationAddDTO addDTO = new CcdiStaffFmyRelationAddDTO();
|
||||
BeanUtils.copyProperties(excel, addDTO);
|
||||
|
||||
// 验证数据
|
||||
validateRelationData(addDTO, existingCombinations);
|
||||
|
||||
String combinationKey = excel.getPersonId() + "_" + excel.getRelationCertNo();
|
||||
|
||||
if (existingCombinations.contains(combinationKey)) {
|
||||
// person_id + relation_cert_no已存在,直接报错
|
||||
throw new RuntimeException(String.format("员工[%s]的亲属证件号[%s]已存在,请勿重复导入",
|
||||
excel.getPersonId(), excel.getRelationCertNo()));
|
||||
} else if (processedCombinations.contains(combinationKey)) {
|
||||
// Excel文件内部重复
|
||||
throw new RuntimeException(String.format("员工[%s]的亲属证件号[%s]在导入文件中重复,已跳过此条记录",
|
||||
excel.getPersonId(), excel.getRelationCertNo()));
|
||||
} else {
|
||||
CcdiStaffFmyRelation relation = new CcdiStaffFmyRelation();
|
||||
BeanUtils.copyProperties(excel, relation);
|
||||
relation.setCreatedBy(userName);
|
||||
relation.setUpdatedBy(userName);
|
||||
relation.setIsEmpFamily(0);
|
||||
relation.setIsCustFamily(0);
|
||||
newRecords.add(relation);
|
||||
processedCombinations.add(combinationKey);
|
||||
}
|
||||
|
||||
} catch (Exception e) {
|
||||
StaffFmyRelationImportFailureVO failure = new StaffFmyRelationImportFailureVO();
|
||||
BeanUtils.copyProperties(excel, failure);
|
||||
failure.setErrorMessage(e.getMessage());
|
||||
failures.add(failure);
|
||||
}
|
||||
}
|
||||
|
||||
// 批量插入新数据
|
||||
if (!newRecords.isEmpty()) {
|
||||
saveBatch(newRecords, 500);
|
||||
}
|
||||
|
||||
// 保存失败记录到Redis
|
||||
if (!failures.isEmpty()) {
|
||||
String failuresKey = "import:staffFmyRelation:" + taskId + ":failures";
|
||||
redisTemplate.opsForValue().set(failuresKey, failures, 7, TimeUnit.DAYS);
|
||||
}
|
||||
|
||||
ImportResult result = new ImportResult();
|
||||
result.setTotalCount(excelList.size());
|
||||
result.setSuccessCount(newRecords.size());
|
||||
result.setFailureCount(failures.size());
|
||||
|
||||
// 更新最终状态
|
||||
String finalStatus = result.getFailureCount() == 0 ? "SUCCESS" : "PARTIAL_SUCCESS";
|
||||
updateImportStatus(taskId, finalStatus, result);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取导入失败记录
|
||||
*
|
||||
* @param taskId 任务ID
|
||||
* @return 失败记录列表
|
||||
*/
|
||||
@Override
|
||||
public List<StaffFmyRelationImportFailureVO> getImportFailures(String taskId) {
|
||||
String key = "import:staffFmyRelation:" + taskId + ":failures";
|
||||
Object failuresObj = redisTemplate.opsForValue().get(key);
|
||||
|
||||
if (failuresObj == null) {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
return JSON.parseArray(JSON.toJSONString(failuresObj), StaffFmyRelationImportFailureVO.class);
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询导入状态
|
||||
*
|
||||
* @param taskId 任务ID
|
||||
* @return 导入状态信息
|
||||
*/
|
||||
@Override
|
||||
public ImportStatusVO getImportStatus(String taskId) {
|
||||
String key = "import:staffFmyRelation:" + taskId;
|
||||
Boolean hasKey = redisTemplate.hasKey(key);
|
||||
|
||||
if (Boolean.FALSE.equals(hasKey)) {
|
||||
throw new RuntimeException("任务不存在或已过期");
|
||||
}
|
||||
|
||||
Map<Object, Object> statusMap = redisTemplate.opsForHash().entries(key);
|
||||
|
||||
ImportStatusVO statusVO = new ImportStatusVO();
|
||||
statusVO.setTaskId((String) statusMap.get("taskId"));
|
||||
statusVO.setStatus((String) statusMap.get("status"));
|
||||
statusVO.setTotalCount((Integer) statusMap.get("totalCount"));
|
||||
statusVO.setSuccessCount((Integer) statusMap.get("successCount"));
|
||||
statusVO.setFailureCount((Integer) statusMap.get("failureCount"));
|
||||
statusVO.setProgress((Integer) statusMap.get("progress"));
|
||||
statusVO.setStartTime((Long) statusMap.get("startTime"));
|
||||
statusVO.setEndTime((Long) statusMap.get("endTime"));
|
||||
statusVO.setMessage((String) statusMap.get("message"));
|
||||
|
||||
return statusVO;
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新导入状态
|
||||
*/
|
||||
private void updateImportStatus(String taskId, String status, ImportResult result) {
|
||||
String key = "import:staffFmyRelation:" + taskId;
|
||||
Map<String, Object> statusData = new HashMap<>();
|
||||
statusData.put("status", status);
|
||||
statusData.put("successCount", result.getSuccessCount());
|
||||
statusData.put("failureCount", result.getFailureCount());
|
||||
statusData.put("progress", 100);
|
||||
statusData.put("endTime", System.currentTimeMillis());
|
||||
|
||||
if ("SUCCESS".equals(status)) {
|
||||
statusData.put("message", "全部成功!共导入" + result.getTotalCount() + "条数据");
|
||||
} else {
|
||||
statusData.put("message", "成功" + result.getSuccessCount() + "条,失败" + result.getFailureCount() + "条");
|
||||
}
|
||||
|
||||
redisTemplate.opsForHash().putAll(key, statusData);
|
||||
}
|
||||
|
||||
/**
|
||||
* 批量查询已存在的person_id + relation_cert_no组合
|
||||
*/
|
||||
private Set<String> getExistingCombinations(List<CcdiStaffFmyRelationExcel> excelList) {
|
||||
// 提取所有person_id
|
||||
Set<String> personIds = excelList.stream()
|
||||
.map(CcdiStaffFmyRelationExcel::getPersonId)
|
||||
.filter(Objects::nonNull)
|
||||
.collect(Collectors.toSet());
|
||||
|
||||
if (personIds.isEmpty()) {
|
||||
return Collections.emptySet();
|
||||
}
|
||||
|
||||
// 查询这些person_id的所有亲属关系
|
||||
com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper<CcdiStaffFmyRelation> wrapper =
|
||||
new com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper<>();
|
||||
wrapper.in(CcdiStaffFmyRelation::getPersonId, personIds);
|
||||
|
||||
List<CcdiStaffFmyRelation> existingRelations = relationMapper.selectList(wrapper);
|
||||
|
||||
return existingRelations.stream()
|
||||
.map(r -> r.getPersonId() + "_" + r.getRelationCertNo())
|
||||
.collect(Collectors.toSet());
|
||||
}
|
||||
|
||||
/**
|
||||
* 批量保存
|
||||
*/
|
||||
private void saveBatch(List<CcdiStaffFmyRelation> list, int batchSize) {
|
||||
for (int i = 0; i < list.size(); i += batchSize) {
|
||||
int end = Math.min(i + batchSize, list.size());
|
||||
List<CcdiStaffFmyRelation> subList = list.subList(i, end);
|
||||
relationMapper.insertBatch(subList);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 验证亲属关系数据
|
||||
*
|
||||
* @param addDTO 新增DTO
|
||||
* @param existingCombinations 已存在的组合集合
|
||||
*/
|
||||
private void validateRelationData(CcdiStaffFmyRelationAddDTO addDTO, Set<String> existingCombinations) {
|
||||
// 验证必填字段
|
||||
if (StringUtils.isEmpty(addDTO.getPersonId())) {
|
||||
throw new RuntimeException("员工身份证号不能为空");
|
||||
}
|
||||
if (StringUtils.isEmpty(addDTO.getRelationType())) {
|
||||
throw new RuntimeException("关系类型不能为空");
|
||||
}
|
||||
if (StringUtils.isEmpty(addDTO.getRelationName())) {
|
||||
throw new RuntimeException("关系人姓名不能为空");
|
||||
}
|
||||
if (StringUtils.isEmpty(addDTO.getRelationCertType())) {
|
||||
throw new RuntimeException("证件类型不能为空");
|
||||
}
|
||||
if (StringUtils.isEmpty(addDTO.getRelationCertNo())) {
|
||||
throw new RuntimeException("证件号码不能为空");
|
||||
}
|
||||
if (addDTO.getStatus() == null) {
|
||||
throw new RuntimeException("状态不能为空");
|
||||
}
|
||||
|
||||
// 验证身份证号格式
|
||||
if (!addDTO.getPersonId().matches("^\\d{17}[\\dXx]$")) {
|
||||
throw new RuntimeException("员工身份证号格式不正确");
|
||||
}
|
||||
|
||||
// 验证手机号格式(如果提供)
|
||||
if (StringUtils.isNotEmpty(addDTO.getMobilePhone1()) &&
|
||||
!addDTO.getMobilePhone1().matches("^1[3-9]\\d{9}$")) {
|
||||
throw new RuntimeException("手机号码1格式不正确");
|
||||
}
|
||||
if (StringUtils.isNotEmpty(addDTO.getMobilePhone2()) &&
|
||||
!addDTO.getMobilePhone2().matches("^1[3-9]\\d{9}$")) {
|
||||
throw new RuntimeException("手机号码2格式不正确");
|
||||
}
|
||||
|
||||
// 验证性别格式(如果提供)
|
||||
if (StringUtils.isNotEmpty(addDTO.getGender()) &&
|
||||
!addDTO.getGender().matches("^[MFO]$")) {
|
||||
throw new RuntimeException("性别只能是M、F或O");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,231 +0,0 @@
|
||||
package com.ruoyi.ccdi.service.impl;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.ruoyi.ccdi.domain.CcdiStaffFmyRelation;
|
||||
import com.ruoyi.ccdi.domain.dto.CcdiStaffFmyRelationAddDTO;
|
||||
import com.ruoyi.ccdi.domain.dto.CcdiStaffFmyRelationEditDTO;
|
||||
import com.ruoyi.ccdi.domain.dto.CcdiStaffFmyRelationQueryDTO;
|
||||
import com.ruoyi.ccdi.domain.excel.CcdiStaffFmyRelationExcel;
|
||||
import com.ruoyi.ccdi.domain.vo.CcdiStaffFmyRelationVO;
|
||||
import com.ruoyi.ccdi.mapper.CcdiStaffFmyRelationMapper;
|
||||
import com.ruoyi.ccdi.service.ICcdiStaffFmyRelationImportService;
|
||||
import com.ruoyi.ccdi.service.ICcdiStaffFmyRelationService;
|
||||
import com.ruoyi.common.utils.SecurityUtils;
|
||||
import com.ruoyi.common.utils.StringUtils;
|
||||
import jakarta.annotation.Resource;
|
||||
import org.springframework.beans.BeanUtils;
|
||||
import org.springframework.data.redis.core.RedisTemplate;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* 员工亲属关系信息 服务层处理
|
||||
*
|
||||
* @author ruoyi
|
||||
* @date 2026-02-09
|
||||
*/
|
||||
@Service
|
||||
public class CcdiStaffFmyRelationServiceImpl implements ICcdiStaffFmyRelationService {
|
||||
|
||||
@Resource
|
||||
private CcdiStaffFmyRelationMapper relationMapper;
|
||||
|
||||
@Resource
|
||||
private ICcdiStaffFmyRelationImportService relationImportService;
|
||||
|
||||
@Resource
|
||||
private RedisTemplate<String, Object> redisTemplate;
|
||||
|
||||
/**
|
||||
* 查询员工亲属关系列表
|
||||
*
|
||||
* @param queryDTO 查询条件
|
||||
* @return 员工亲属关系VO集合
|
||||
*/
|
||||
@Override
|
||||
public java.util.List<CcdiStaffFmyRelationVO> selectRelationList(CcdiStaffFmyRelationQueryDTO queryDTO) {
|
||||
Page<CcdiStaffFmyRelationVO> page = new Page<>(1, Integer.MAX_VALUE);
|
||||
Page<CcdiStaffFmyRelationVO> resultPage = relationMapper.selectRelationPage(page, queryDTO);
|
||||
return resultPage.getRecords();
|
||||
}
|
||||
|
||||
/**
|
||||
* 分页查询员工亲属关系列表
|
||||
*
|
||||
* @param page 分页对象
|
||||
* @param queryDTO 查询条件
|
||||
* @return 员工亲属关系VO分页结果
|
||||
*/
|
||||
@Override
|
||||
public Page<CcdiStaffFmyRelationVO> selectRelationPage(Page<CcdiStaffFmyRelationVO> page, CcdiStaffFmyRelationQueryDTO queryDTO) {
|
||||
return relationMapper.selectRelationPage(page, queryDTO);
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询员工亲属关系列表(用于导出)
|
||||
*
|
||||
* @param queryDTO 查询条件
|
||||
* @return 员工亲属关系Excel实体集合
|
||||
*/
|
||||
@Override
|
||||
public java.util.List<CcdiStaffFmyRelationExcel> selectRelationListForExport(CcdiStaffFmyRelationQueryDTO queryDTO) {
|
||||
return relationMapper.selectRelationListForExport(queryDTO).stream().map(vo -> {
|
||||
CcdiStaffFmyRelationExcel excel = new CcdiStaffFmyRelationExcel();
|
||||
BeanUtils.copyProperties(vo, excel);
|
||||
return excel;
|
||||
}).collect(Collectors.toList());
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询员工亲属关系详情
|
||||
*
|
||||
* @param id 主键ID
|
||||
* @return 员工亲属关系VO
|
||||
*/
|
||||
@Override
|
||||
public CcdiStaffFmyRelationVO selectRelationById(Long id) {
|
||||
return relationMapper.selectRelationById(id);
|
||||
}
|
||||
|
||||
/**
|
||||
* 新增员工亲属关系
|
||||
*
|
||||
* @param addDTO 新增DTO
|
||||
* @return 结果
|
||||
*/
|
||||
@Override
|
||||
@Transactional
|
||||
public int insertRelation(CcdiStaffFmyRelationAddDTO addDTO) {
|
||||
// 检查唯一性:person_id + relation_cert_no
|
||||
validateUniqueRelation(addDTO.getPersonId(), addDTO.getRelationCertNo(), null);
|
||||
|
||||
// 验证person_id是否在ccdi_base_staff表中存在
|
||||
validatePersonIdExists(addDTO.getPersonId());
|
||||
|
||||
CcdiStaffFmyRelation relation = new CcdiStaffFmyRelation();
|
||||
BeanUtils.copyProperties(addDTO, relation);
|
||||
int result = relationMapper.insert(relation);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改员工亲属关系
|
||||
*
|
||||
* @param editDTO 编辑DTO
|
||||
* @return 结果
|
||||
*/
|
||||
@Override
|
||||
@Transactional
|
||||
public int updateRelation(CcdiStaffFmyRelationEditDTO editDTO) {
|
||||
// 检查唯一性:person_id + relation_cert_no(排除自身)
|
||||
validateUniqueRelation(editDTO.getPersonId(), editDTO.getRelationCertNo(), editDTO.getId());
|
||||
|
||||
// 验证person_id是否在ccdi_base_staff表中存在
|
||||
validatePersonIdExists(editDTO.getPersonId());
|
||||
|
||||
CcdiStaffFmyRelation relation = new CcdiStaffFmyRelation();
|
||||
BeanUtils.copyProperties(editDTO, relation);
|
||||
int result = relationMapper.updateById(relation);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* 批量删除员工亲属关系
|
||||
*
|
||||
* @param ids 需要删除的主键ID数组
|
||||
* @return 结果
|
||||
*/
|
||||
@Override
|
||||
@Transactional
|
||||
public int deleteRelationByIds(Long[] ids) {
|
||||
return relationMapper.deleteBatchIds(java.util.List.of(ids));
|
||||
}
|
||||
|
||||
/**
|
||||
* 导入员工亲属关系数据(异步)
|
||||
*
|
||||
* @param excelList Excel实体列表
|
||||
* @return 任务ID
|
||||
*/
|
||||
@Override
|
||||
@Transactional
|
||||
public String importRelation(java.util.List<CcdiStaffFmyRelationExcel> excelList) {
|
||||
if (StringUtils.isNull(excelList) || excelList.isEmpty()) {
|
||||
throw new RuntimeException("至少需要一条数据");
|
||||
}
|
||||
|
||||
// 生成任务ID
|
||||
String taskId = UUID.randomUUID().toString();
|
||||
long startTime = System.currentTimeMillis();
|
||||
|
||||
// 获取当前用户名
|
||||
String userName = SecurityUtils.getUsername();
|
||||
|
||||
// 初始化Redis状态
|
||||
String statusKey = "import:staffFmyRelation:" + taskId;
|
||||
Map<String, Object> statusData = new HashMap<>();
|
||||
statusData.put("taskId", taskId);
|
||||
statusData.put("status", "PROCESSING");
|
||||
statusData.put("totalCount", excelList.size());
|
||||
statusData.put("successCount", 0);
|
||||
statusData.put("failureCount", 0);
|
||||
statusData.put("progress", 0);
|
||||
statusData.put("startTime", startTime);
|
||||
statusData.put("message", "正在处理...");
|
||||
|
||||
redisTemplate.opsForHash().putAll(statusKey, statusData);
|
||||
redisTemplate.expire(statusKey, 7, TimeUnit.DAYS);
|
||||
|
||||
// 调用异步导入服务
|
||||
relationImportService.importRelationAsync(excelList, taskId, userName);
|
||||
|
||||
return taskId;
|
||||
}
|
||||
|
||||
/**
|
||||
* 验证唯一性:person_id + relation_cert_no
|
||||
*
|
||||
* @param personId 员工身份证号
|
||||
* @param relationCertNo 亲属证件号
|
||||
* @param excludeId 排除的记录ID(修改时使用)
|
||||
*/
|
||||
private void validateUniqueRelation(String personId, String relationCertNo, Long excludeId) {
|
||||
// 这里需要调用Mapper查询是否存在重复记录
|
||||
// 简化处理:使用LambdaQueryWrapper查询
|
||||
com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper<CcdiStaffFmyRelation> wrapper =
|
||||
new com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper<>();
|
||||
wrapper.eq(CcdiStaffFmyRelation::getPersonId, personId)
|
||||
.eq(CcdiStaffFmyRelation::getRelationCertNo, relationCertNo);
|
||||
|
||||
if (excludeId != null) {
|
||||
wrapper.ne(CcdiStaffFmyRelation::getId, excludeId);
|
||||
}
|
||||
|
||||
CcdiStaffFmyRelation existing = relationMapper.selectOne(wrapper);
|
||||
if (existing != null) {
|
||||
throw new RuntimeException("该员工已存在相同亲属证件号的关系记录");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 验证person_id是否在ccdi_base_staff表中存在
|
||||
*
|
||||
* @param personId 员工身份证号
|
||||
*/
|
||||
private void validatePersonIdExists(String personId) {
|
||||
// 这里需要查询ccdi_base_staff表
|
||||
// TODO: 注入CcdiBaseStaffMapper并查询
|
||||
// 暂时简化处理:如果personId格式正确则认为存在
|
||||
if (!personId.matches("^\\d{17}[\\dXx]$")) {
|
||||
throw new RuntimeException("员工身份证号格式不正确");
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user