feat 员工实体关系
This commit is contained in:
@@ -0,0 +1,195 @@
|
||||
package com.ruoyi.ccdi.controller;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.ruoyi.ccdi.domain.dto.CcdiStaffEnterpriseRelationAddDTO;
|
||||
import com.ruoyi.ccdi.domain.dto.CcdiStaffEnterpriseRelationEditDTO;
|
||||
import com.ruoyi.ccdi.domain.dto.CcdiStaffEnterpriseRelationQueryDTO;
|
||||
import com.ruoyi.ccdi.domain.excel.CcdiStaffEnterpriseRelationExcel;
|
||||
import com.ruoyi.ccdi.domain.vo.CcdiStaffEnterpriseRelationVO;
|
||||
import com.ruoyi.ccdi.domain.vo.ImportResultVO;
|
||||
import com.ruoyi.ccdi.domain.vo.ImportStatusVO;
|
||||
import com.ruoyi.ccdi.domain.vo.StaffEnterpriseRelationImportFailureVO;
|
||||
import com.ruoyi.ccdi.service.ICcdiStaffEnterpriseRelationImportService;
|
||||
import com.ruoyi.ccdi.service.ICcdiStaffEnterpriseRelationService;
|
||||
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/staffEnterpriseRelation")
|
||||
public class CcdiStaffEnterpriseRelationController extends BaseController {
|
||||
|
||||
@Resource
|
||||
private ICcdiStaffEnterpriseRelationService relationService;
|
||||
|
||||
@Resource
|
||||
private ICcdiStaffEnterpriseRelationImportService relationImportService;
|
||||
|
||||
/**
|
||||
* 查询员工实体关系列表
|
||||
*/
|
||||
@Operation(summary = "查询员工实体关系列表")
|
||||
@PreAuthorize("@ss.hasPermi('ccdi:staffEnterpriseRelation:list')")
|
||||
@GetMapping("/list")
|
||||
public TableDataInfo list(CcdiStaffEnterpriseRelationQueryDTO queryDTO) {
|
||||
// 使用MyBatis Plus分页
|
||||
PageDomain pageDomain = TableSupport.buildPageRequest();
|
||||
Page<CcdiStaffEnterpriseRelationVO> page = new Page<>(pageDomain.getPageNum(), pageDomain.getPageSize());
|
||||
Page<CcdiStaffEnterpriseRelationVO> result = relationService.selectRelationPage(page, queryDTO);
|
||||
return getDataTable(result.getRecords(), result.getTotal());
|
||||
}
|
||||
|
||||
/**
|
||||
* 导出员工实体关系列表
|
||||
*/
|
||||
@Operation(summary = "导出员工实体关系列表")
|
||||
@PreAuthorize("@ss.hasPermi('ccdi:staffEnterpriseRelation:export')")
|
||||
@Log(title = "员工实体关系信息", businessType = BusinessType.EXPORT)
|
||||
@PostMapping("/export")
|
||||
public void export(HttpServletResponse response, CcdiStaffEnterpriseRelationQueryDTO queryDTO) {
|
||||
List<CcdiStaffEnterpriseRelationExcel> list = relationService.selectRelationListForExport(queryDTO);
|
||||
EasyExcelUtil.exportExcel(response, list, CcdiStaffEnterpriseRelationExcel.class, "员工实体关系信息");
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取员工实体关系详细信息
|
||||
*/
|
||||
@Operation(summary = "获取员工实体关系详细信息")
|
||||
@Parameter(name = "id", description = "主键ID", required = true)
|
||||
@PreAuthorize("@ss.hasPermi('ccdi:staffEnterpriseRelation:query')")
|
||||
@GetMapping(value = "/{id}")
|
||||
public AjaxResult getInfo(@PathVariable Long id) {
|
||||
return success(relationService.selectRelationById(id));
|
||||
}
|
||||
|
||||
/**
|
||||
* 新增员工实体关系
|
||||
*/
|
||||
@Operation(summary = "新增员工实体关系")
|
||||
@PreAuthorize("@ss.hasPermi('ccdi:staffEnterpriseRelation:add')")
|
||||
@Log(title = "员工实体关系信息", businessType = BusinessType.INSERT)
|
||||
@PostMapping
|
||||
public AjaxResult add(@Validated @RequestBody CcdiStaffEnterpriseRelationAddDTO addDTO) {
|
||||
return toAjax(relationService.insertRelation(addDTO));
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改员工实体关系
|
||||
*/
|
||||
@Operation(summary = "修改员工实体关系")
|
||||
@PreAuthorize("@ss.hasPermi('ccdi:staffEnterpriseRelation:edit')")
|
||||
@Log(title = "员工实体关系信息", businessType = BusinessType.UPDATE)
|
||||
@PutMapping
|
||||
public AjaxResult edit(@Validated @RequestBody CcdiStaffEnterpriseRelationEditDTO editDTO) {
|
||||
return toAjax(relationService.updateRelation(editDTO));
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除员工实体关系
|
||||
*/
|
||||
@Operation(summary = "删除员工实体关系")
|
||||
@Parameter(name = "ids", description = "主键ID数组", required = true)
|
||||
@PreAuthorize("@ss.hasPermi('ccdi:staffEnterpriseRelation: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, CcdiStaffEnterpriseRelationExcel.class, "员工实体关系信息");
|
||||
}
|
||||
|
||||
/**
|
||||
* 异步导入员工实体关系
|
||||
*/
|
||||
@Operation(summary = "异步导入员工实体关系")
|
||||
@Parameter(name = "file", description = "导入文件", required = true)
|
||||
@PreAuthorize("@ss.hasPermi('ccdi:staffEnterpriseRelation:import')")
|
||||
@Log(title = "员工实体关系信息", businessType = BusinessType.IMPORT)
|
||||
@PostMapping("/importData")
|
||||
public AjaxResult importData(@Parameter(description = "导入文件") MultipartFile file) throws Exception {
|
||||
List<CcdiStaffEnterpriseRelationExcel> list = EasyExcelUtil.importExcel(file.getInputStream(), CcdiStaffEnterpriseRelationExcel.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:staffEnterpriseRelation: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:staffEnterpriseRelation:import')")
|
||||
@GetMapping("/importFailures/{taskId}")
|
||||
public TableDataInfo getImportFailures(
|
||||
@PathVariable String taskId,
|
||||
@RequestParam(defaultValue = "1") Integer pageNum,
|
||||
@RequestParam(defaultValue = "10") Integer pageSize) {
|
||||
|
||||
List<StaffEnterpriseRelationImportFailureVO> failures = relationImportService.getImportFailures(taskId);
|
||||
|
||||
// 手动分页
|
||||
int fromIndex = (pageNum - 1) * pageSize;
|
||||
int toIndex = Math.min(fromIndex + pageSize, failures.size());
|
||||
|
||||
List<StaffEnterpriseRelationImportFailureVO> pageData = failures.subList(fromIndex, toIndex);
|
||||
|
||||
return getDataTable(pageData, failures.size());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,93 @@
|
||||
package com.ruoyi.ccdi.domain;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.*;
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.Data;
|
||||
|
||||
import java.io.Serial;
|
||||
import java.io.Serializable;
|
||||
import java.util.Date;
|
||||
|
||||
/**
|
||||
* 员工实体关系信息对象 ccdi_staff_enterprise_relation
|
||||
*
|
||||
* @author ruoyi
|
||||
* @date 2026-02-09
|
||||
*/
|
||||
@Data
|
||||
@TableName("ccdi_staff_enterprise_relation")
|
||||
@Schema(description = "员工实体关系信息")
|
||||
public class CcdiStaffEnterpriseRelation implements Serializable {
|
||||
|
||||
@Serial
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
/** 主键ID */
|
||||
@TableId(type = IdType.AUTO)
|
||||
@Schema(description = "主键ID")
|
||||
private Long id;
|
||||
|
||||
/** 身份证号 */
|
||||
@Schema(description = "身份证号")
|
||||
private String personId;
|
||||
|
||||
/** 关联人在企业的职务 */
|
||||
@Schema(description = "关联人在企业的职务")
|
||||
private String relationPersonPost;
|
||||
|
||||
/** 统一社会信用代码 */
|
||||
@Schema(description = "统一社会信用代码")
|
||||
private String socialCreditCode;
|
||||
|
||||
/** 企业名称 */
|
||||
@Schema(description = "企业名称")
|
||||
private String enterpriseName;
|
||||
|
||||
/** 状态(0-无效 1-有效) */
|
||||
@Schema(description = "状态(0-无效 1-有效)")
|
||||
private Integer status;
|
||||
|
||||
/** 补充说明 */
|
||||
@Schema(description = "补充说明")
|
||||
private String remark;
|
||||
|
||||
/** 数据来源 */
|
||||
@Schema(description = "数据来源")
|
||||
private String dataSource;
|
||||
|
||||
/** 是否为员工(0-否 1-是) */
|
||||
@Schema(description = "是否为员工(0-否 1-是)")
|
||||
private Integer isEmployee;
|
||||
|
||||
/** 是否为员工家属(0-否 1-是) */
|
||||
@Schema(description = "是否为员工家属(0-否 1-是)")
|
||||
private Integer isEmpFamily;
|
||||
|
||||
/** 是否为客户(0-否 1-是) */
|
||||
@Schema(description = "是否为客户(0-否 1-是)")
|
||||
private Integer isCustomer;
|
||||
|
||||
/** 是否为客户家属(0-否 1-是) */
|
||||
@Schema(description = "是否为客户家属(0-否 1-是)")
|
||||
private Integer isCustFamily;
|
||||
|
||||
/** 创建时间 */
|
||||
@TableField(fill = FieldFill.INSERT)
|
||||
@Schema(description = "创建时间")
|
||||
private Date createTime;
|
||||
|
||||
/** 更新时间 */
|
||||
@TableField(fill = FieldFill.INSERT_UPDATE)
|
||||
@Schema(description = "更新时间")
|
||||
private Date updateTime;
|
||||
|
||||
/** 创建人 */
|
||||
@TableField(fill = FieldFill.INSERT)
|
||||
@Schema(description = "创建人")
|
||||
private String createdBy;
|
||||
|
||||
/** 更新人 */
|
||||
@TableField(fill = FieldFill.INSERT_UPDATE)
|
||||
@Schema(description = "更新人")
|
||||
private String updatedBy;
|
||||
}
|
||||
@@ -0,0 +1,76 @@
|
||||
package com.ruoyi.ccdi.domain.dto;
|
||||
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
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-02-09
|
||||
*/
|
||||
@Data
|
||||
@Schema(description = "员工实体关系信息新增")
|
||||
public class CcdiStaffEnterpriseRelationAddDTO implements Serializable {
|
||||
|
||||
@Serial
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
/** 身份证号 */
|
||||
@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 = "身份证号格式不正确")
|
||||
@Schema(description = "身份证号")
|
||||
private String personId;
|
||||
|
||||
/** 关联人在企业的职务 */
|
||||
@Size(max = 100, message = "关联人在企业的职务长度不能超过100个字符")
|
||||
@Schema(description = "关联人在企业的职务")
|
||||
private String relationPersonPost;
|
||||
|
||||
/** 统一社会信用代码 */
|
||||
@NotBlank(message = "统一社会信用代码不能为空")
|
||||
@Pattern(regexp = "^[0-9A-HJ-NPQRTUWXY]{2}\\d{6}[0-9A-HJ-NPQRTUWXY]{10}$", message = "统一社会信用代码格式不正确")
|
||||
@Schema(description = "统一社会信用代码")
|
||||
private String socialCreditCode;
|
||||
|
||||
/** 企业名称 */
|
||||
@NotBlank(message = "企业名称不能为空")
|
||||
@Size(max = 200, message = "企业名称长度不能超过200个字符")
|
||||
@Schema(description = "企业名称")
|
||||
private String enterpriseName;
|
||||
|
||||
/** 状态(0-无效 1-有效) */
|
||||
@Schema(description = "状态(0-无效 1-有效)")
|
||||
private Integer status;
|
||||
|
||||
/** 补充说明 */
|
||||
@Schema(description = "补充说明")
|
||||
private String remark;
|
||||
|
||||
/** 数据来源 */
|
||||
@Size(max = 50, message = "数据来源长度不能超过50个字符")
|
||||
@Schema(description = "数据来源")
|
||||
private String dataSource;
|
||||
|
||||
/** 是否为员工(0-否 1-是) */
|
||||
@Schema(description = "是否为员工(0-否 1-是)")
|
||||
private Integer isEmployee;
|
||||
|
||||
/** 是否为员工家属(0-否 1-是) */
|
||||
@Schema(description = "是否为员工家属(0-否 1-是)")
|
||||
private Integer isEmpFamily;
|
||||
|
||||
/** 是否为客户(0-否 1-是) */
|
||||
@Schema(description = "是否为客户(0-否 1-是)")
|
||||
private Integer isCustomer;
|
||||
|
||||
/** 是否为客户家属(0-否 1-是) */
|
||||
@Schema(description = "是否为客户家属(0-否 1-是)")
|
||||
private Integer isCustFamily;
|
||||
}
|
||||
@@ -0,0 +1,77 @@
|
||||
package com.ruoyi.ccdi.domain.dto;
|
||||
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import jakarta.validation.constraints.NotBlank;
|
||||
import jakarta.validation.constraints.NotNull;
|
||||
import jakarta.validation.constraints.Size;
|
||||
import lombok.Data;
|
||||
|
||||
import java.io.Serial;
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* 员工实体关系信息编辑DTO
|
||||
*
|
||||
* @author ruoyi
|
||||
* @date 2026-02-09
|
||||
*/
|
||||
@Data
|
||||
@Schema(description = "员工实体关系信息编辑")
|
||||
public class CcdiStaffEnterpriseRelationEditDTO implements Serializable {
|
||||
|
||||
@Serial
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
/** 主键ID */
|
||||
@NotNull(message = "主键ID不能为空")
|
||||
@Schema(description = "主键ID")
|
||||
private Long id;
|
||||
|
||||
/** 身份证号 */
|
||||
@Schema(description = "身份证号(不可修改)")
|
||||
private String personId;
|
||||
|
||||
/** 关联人在企业的职务 */
|
||||
@Size(max = 100, message = "关联人在企业的职务长度不能超过100个字符")
|
||||
@Schema(description = "关联人在企业的职务")
|
||||
private String relationPersonPost;
|
||||
|
||||
/** 统一社会信用代码 */
|
||||
@Schema(description = "统一社会信用代码(不可修改)")
|
||||
private String socialCreditCode;
|
||||
|
||||
/** 企业名称 */
|
||||
@NotBlank(message = "企业名称不能为空")
|
||||
@Size(max = 200, message = "企业名称长度不能超过200个字符")
|
||||
@Schema(description = "企业名称")
|
||||
private String enterpriseName;
|
||||
|
||||
/** 状态(0-无效 1-有效) */
|
||||
@Schema(description = "状态(0-无效 1-有效)")
|
||||
private Integer status;
|
||||
|
||||
/** 补充说明 */
|
||||
@Schema(description = "补充说明")
|
||||
private String remark;
|
||||
|
||||
/** 数据来源 */
|
||||
@Size(max = 50, message = "数据来源长度不能超过50个字符")
|
||||
@Schema(description = "数据来源")
|
||||
private String dataSource;
|
||||
|
||||
/** 是否为员工(0-否 1-是) */
|
||||
@Schema(description = "是否为员工(0-否 1-是)")
|
||||
private Integer isEmployee;
|
||||
|
||||
/** 是否为员工家属(0-否 1-是) */
|
||||
@Schema(description = "是否为员工家属(0-否 1-是)")
|
||||
private Integer isEmpFamily;
|
||||
|
||||
/** 是否为客户(0-否 1-是) */
|
||||
@Schema(description = "是否为客户(0-否 1-是)")
|
||||
private Integer isCustomer;
|
||||
|
||||
/** 是否为客户家属(0-否 1-是) */
|
||||
@Schema(description = "是否为客户家属(0-否 1-是)")
|
||||
private Integer isCustFamily;
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
package com.ruoyi.ccdi.domain.dto;
|
||||
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.Data;
|
||||
|
||||
import java.io.Serial;
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* 员工实体关系信息查询DTO
|
||||
*
|
||||
* @author ruoyi
|
||||
* @date 2026-02-09
|
||||
*/
|
||||
@Data
|
||||
@Schema(description = "员工实体关系信息查询条件")
|
||||
public class CcdiStaffEnterpriseRelationQueryDTO implements Serializable {
|
||||
|
||||
@Serial
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
/** 身份证号 */
|
||||
@Schema(description = "身份证号")
|
||||
private String personId;
|
||||
|
||||
/** 统一社会信用代码 */
|
||||
@Schema(description = "统一社会信用代码")
|
||||
private String socialCreditCode;
|
||||
|
||||
/** 企业名称 */
|
||||
@Schema(description = "企业名称")
|
||||
private String enterpriseName;
|
||||
|
||||
/** 状态(0-无效 1-有效) */
|
||||
@Schema(description = "状态(0-无效 1-有效)")
|
||||
private Integer status;
|
||||
}
|
||||
@@ -0,0 +1,57 @@
|
||||
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.Required;
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.Data;
|
||||
|
||||
import java.io.Serial;
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* 员工实体关系信息Excel导入导出对象
|
||||
*
|
||||
* @author ruoyi
|
||||
* @date 2026-02-09
|
||||
*/
|
||||
@Data
|
||||
@Schema(description = "员工实体关系信息Excel导入导出对象")
|
||||
public class CcdiStaffEnterpriseRelationExcel implements Serializable {
|
||||
|
||||
@Serial
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
/** 身份证号 */
|
||||
@ExcelProperty(value = "身份证号", index = 0)
|
||||
@ColumnWidth(20)
|
||||
@Required
|
||||
@Schema(description = "身份证号")
|
||||
private String personId;
|
||||
|
||||
/** 统一社会信用代码 */
|
||||
@ExcelProperty(value = "统一社会信用代码", index = 1)
|
||||
@ColumnWidth(25)
|
||||
@Required
|
||||
@Schema(description = "统一社会信用代码")
|
||||
private String socialCreditCode;
|
||||
|
||||
/** 企业名称 */
|
||||
@ExcelProperty(value = "企业名称", index = 2)
|
||||
@ColumnWidth(30)
|
||||
@Required
|
||||
@Schema(description = "企业名称")
|
||||
private String enterpriseName;
|
||||
|
||||
/** 关联人在企业的职务 */
|
||||
@ExcelProperty(value = "关联人在企业的职务", index = 3)
|
||||
@ColumnWidth(25)
|
||||
@Schema(description = "关联人在企业的职务")
|
||||
private String relationPersonPost;
|
||||
|
||||
/** 补充说明 */
|
||||
@ExcelProperty(value = "补充说明", index = 4)
|
||||
@ColumnWidth(40)
|
||||
@Schema(description = "补充说明")
|
||||
private String remark;
|
||||
}
|
||||
@@ -0,0 +1,89 @@
|
||||
package com.ruoyi.ccdi.domain.vo;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonFormat;
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.Data;
|
||||
|
||||
import java.io.Serial;
|
||||
import java.io.Serializable;
|
||||
import java.util.Date;
|
||||
|
||||
/**
|
||||
* 员工实体关系信息VO
|
||||
*
|
||||
* @author ruoyi
|
||||
* @date 2026-02-09
|
||||
*/
|
||||
@Data
|
||||
@Schema(description = "员工实体关系信息")
|
||||
public class CcdiStaffEnterpriseRelationVO implements Serializable {
|
||||
|
||||
@Serial
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
/** 主键ID */
|
||||
@Schema(description = "主键ID")
|
||||
private Long id;
|
||||
|
||||
/** 身份证号 */
|
||||
@Schema(description = "身份证号")
|
||||
private String personId;
|
||||
|
||||
/** 关联人在企业的职务 */
|
||||
@Schema(description = "关联人在企业的职务")
|
||||
private String relationPersonPost;
|
||||
|
||||
/** 统一社会信用代码 */
|
||||
@Schema(description = "统一社会信用代码")
|
||||
private String socialCreditCode;
|
||||
|
||||
/** 企业名称 */
|
||||
@Schema(description = "企业名称")
|
||||
private String enterpriseName;
|
||||
|
||||
/** 状态(0-无效 1-有效) */
|
||||
@Schema(description = "状态(0-无效 1-有效)")
|
||||
private Integer status;
|
||||
|
||||
/** 补充说明 */
|
||||
@Schema(description = "补充说明")
|
||||
private String remark;
|
||||
|
||||
/** 数据来源 */
|
||||
@Schema(description = "数据来源")
|
||||
private String dataSource;
|
||||
|
||||
/** 是否为员工(0-否 1-是) */
|
||||
@Schema(description = "是否为员工(0-否 1-是)")
|
||||
private Integer isEmployee;
|
||||
|
||||
/** 是否为员工家属(0-否 1-是) */
|
||||
@Schema(description = "是否为员工家属(0-否 1-是)")
|
||||
private Integer isEmpFamily;
|
||||
|
||||
/** 是否为客户(0-否 1-是) */
|
||||
@Schema(description = "是否为客户(0-否 1-是)")
|
||||
private Integer isCustomer;
|
||||
|
||||
/** 是否为客户家属(0-否 1-是) */
|
||||
@Schema(description = "是否为客户家属(0-否 1-是)")
|
||||
private Integer isCustFamily;
|
||||
|
||||
/** 创建时间 */
|
||||
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
|
||||
@Schema(description = "创建时间")
|
||||
private Date createTime;
|
||||
|
||||
/** 更新时间 */
|
||||
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
|
||||
@Schema(description = "更新时间")
|
||||
private Date updateTime;
|
||||
|
||||
/** 创建人 */
|
||||
@Schema(description = "创建人")
|
||||
private String createdBy;
|
||||
|
||||
/** 更新人 */
|
||||
@Schema(description = "更新人")
|
||||
private String updatedBy;
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
package com.ruoyi.ccdi.domain.vo;
|
||||
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.Data;
|
||||
|
||||
import java.io.Serial;
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* 员工实体关系信息导入失败记录VO
|
||||
*
|
||||
* @author ruoyi
|
||||
* @date 2026-02-09
|
||||
*/
|
||||
@Data
|
||||
@Schema(description = "员工实体关系信息导入失败记录")
|
||||
public class StaffEnterpriseRelationImportFailureVO implements Serializable {
|
||||
|
||||
@Serial
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
/** 身份证号 */
|
||||
@Schema(description = "身份证号")
|
||||
private String personId;
|
||||
|
||||
/** 统一社会信用代码 */
|
||||
@Schema(description = "统一社会信用代码")
|
||||
private String socialCreditCode;
|
||||
|
||||
/** 企业名称 */
|
||||
@Schema(description = "企业名称")
|
||||
private String enterpriseName;
|
||||
|
||||
/** 错误信息 */
|
||||
@Schema(description = "错误信息")
|
||||
private String errorMessage;
|
||||
}
|
||||
@@ -0,0 +1,67 @@
|
||||
package com.ruoyi.ccdi.mapper;
|
||||
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.ruoyi.ccdi.domain.CcdiStaffEnterpriseRelation;
|
||||
import com.ruoyi.ccdi.domain.dto.CcdiStaffEnterpriseRelationQueryDTO;
|
||||
import com.ruoyi.ccdi.domain.vo.CcdiStaffEnterpriseRelationVO;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* 员工实体关系信息 数据层
|
||||
*
|
||||
* @author ruoyi
|
||||
* @date 2026-02-09
|
||||
*/
|
||||
@Mapper
|
||||
public interface CcdiStaffEnterpriseRelationMapper extends BaseMapper<CcdiStaffEnterpriseRelation> {
|
||||
|
||||
/**
|
||||
* 分页查询员工实体关系列表
|
||||
*
|
||||
* @param page 分页对象
|
||||
* @param queryDTO 查询条件
|
||||
* @return 员工实体关系VO分页结果
|
||||
*/
|
||||
Page<CcdiStaffEnterpriseRelationVO> selectRelationPage(@Param("page") Page<CcdiStaffEnterpriseRelationVO> page,
|
||||
@Param("query") CcdiStaffEnterpriseRelationQueryDTO queryDTO);
|
||||
|
||||
/**
|
||||
* 查询员工实体关系详情
|
||||
*
|
||||
* @param id 主键ID
|
||||
* @return 员工实体关系VO
|
||||
*/
|
||||
CcdiStaffEnterpriseRelationVO selectRelationById(@Param("id") Long id);
|
||||
|
||||
/**
|
||||
* 判断身份证号和统一社会信用代码的组合是否已存在
|
||||
*
|
||||
* @param personId 身份证号
|
||||
* @param socialCreditCode 统一社会信用代码
|
||||
* @return 存在返回true,否则返回false
|
||||
*/
|
||||
boolean existsByPersonIdAndSocialCreditCode(@Param("personId") String personId,
|
||||
@Param("socialCreditCode") String socialCreditCode);
|
||||
|
||||
/**
|
||||
* 批量查询已存在的person_id + social_credit_code组合
|
||||
* 优化导入性能,一次性查询所有组合
|
||||
*
|
||||
* @param combinations 组合列表,格式为 ["personId1|socialCreditCode1", "personId2|socialCreditCode2", ...]
|
||||
* @return 已存在的组合集合
|
||||
*/
|
||||
Set<String> batchExistsByCombinations(@Param("combinations") List<String> combinations);
|
||||
|
||||
/**
|
||||
* 批量插入员工实体关系数据
|
||||
*
|
||||
* @param list 员工实体关系列表
|
||||
* @return 插入行数
|
||||
*/
|
||||
int insertBatch(@Param("list") List<CcdiStaffEnterpriseRelation> list);
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
package com.ruoyi.ccdi.service;
|
||||
|
||||
import com.ruoyi.ccdi.domain.excel.CcdiStaffEnterpriseRelationExcel;
|
||||
import com.ruoyi.ccdi.domain.vo.ImportStatusVO;
|
||||
import com.ruoyi.ccdi.domain.vo.StaffEnterpriseRelationImportFailureVO;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 员工实体关系信息异步导入服务层
|
||||
*
|
||||
* @author ruoyi
|
||||
* @date 2026-02-09
|
||||
*/
|
||||
public interface ICcdiStaffEnterpriseRelationImportService {
|
||||
|
||||
/**
|
||||
* 异步导入员工实体关系数据
|
||||
*
|
||||
* @param excelList Excel数据列表
|
||||
* @param taskId 任务ID
|
||||
* @param userName 当前用户名
|
||||
*/
|
||||
void importRelationAsync(List<CcdiStaffEnterpriseRelationExcel> excelList, String taskId, String userName);
|
||||
|
||||
/**
|
||||
* 查询导入状态
|
||||
*
|
||||
* @param taskId 任务ID
|
||||
* @return 导入状态信息
|
||||
*/
|
||||
ImportStatusVO getImportStatus(String taskId);
|
||||
|
||||
/**
|
||||
* 获取导入失败记录
|
||||
*
|
||||
* @param taskId 任务ID
|
||||
* @return 失败记录列表
|
||||
*/
|
||||
List<StaffEnterpriseRelationImportFailureVO> getImportFailures(String taskId);
|
||||
}
|
||||
@@ -0,0 +1,84 @@
|
||||
package com.ruoyi.ccdi.service;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.ruoyi.ccdi.domain.dto.CcdiStaffEnterpriseRelationAddDTO;
|
||||
import com.ruoyi.ccdi.domain.dto.CcdiStaffEnterpriseRelationEditDTO;
|
||||
import com.ruoyi.ccdi.domain.dto.CcdiStaffEnterpriseRelationQueryDTO;
|
||||
import com.ruoyi.ccdi.domain.excel.CcdiStaffEnterpriseRelationExcel;
|
||||
import com.ruoyi.ccdi.domain.vo.CcdiStaffEnterpriseRelationVO;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 员工实体关系信息 服务层
|
||||
*
|
||||
* @author ruoyi
|
||||
* @date 2026-02-09
|
||||
*/
|
||||
public interface ICcdiStaffEnterpriseRelationService {
|
||||
|
||||
/**
|
||||
* 查询员工实体关系列表
|
||||
*
|
||||
* @param queryDTO 查询条件
|
||||
* @return 员工实体关系VO集合
|
||||
*/
|
||||
List<CcdiStaffEnterpriseRelationVO> selectRelationList(CcdiStaffEnterpriseRelationQueryDTO queryDTO);
|
||||
|
||||
/**
|
||||
* 分页查询员工实体关系列表
|
||||
*
|
||||
* @param page 分页对象
|
||||
* @param queryDTO 查询条件
|
||||
* @return 员工实体关系VO分页结果
|
||||
*/
|
||||
Page<CcdiStaffEnterpriseRelationVO> selectRelationPage(Page<CcdiStaffEnterpriseRelationVO> page, CcdiStaffEnterpriseRelationQueryDTO queryDTO);
|
||||
|
||||
/**
|
||||
* 查询员工实体关系列表(用于导出)
|
||||
*
|
||||
* @param queryDTO 查询条件
|
||||
* @return 员工实体关系Excel实体集合
|
||||
*/
|
||||
List<CcdiStaffEnterpriseRelationExcel> selectRelationListForExport(CcdiStaffEnterpriseRelationQueryDTO queryDTO);
|
||||
|
||||
/**
|
||||
* 查询员工实体关系详情
|
||||
*
|
||||
* @param id 主键ID
|
||||
* @return 员工实体关系VO
|
||||
*/
|
||||
CcdiStaffEnterpriseRelationVO selectRelationById(Long id);
|
||||
|
||||
/**
|
||||
* 新增员工实体关系
|
||||
*
|
||||
* @param addDTO 新增DTO
|
||||
* @return 结果
|
||||
*/
|
||||
int insertRelation(CcdiStaffEnterpriseRelationAddDTO addDTO);
|
||||
|
||||
/**
|
||||
* 修改员工实体关系
|
||||
*
|
||||
* @param editDTO 编辑DTO
|
||||
* @return 结果
|
||||
*/
|
||||
int updateRelation(CcdiStaffEnterpriseRelationEditDTO editDTO);
|
||||
|
||||
/**
|
||||
* 批量删除员工实体关系
|
||||
*
|
||||
* @param ids 需要删除的主键ID
|
||||
* @return 结果
|
||||
*/
|
||||
int deleteRelationByIds(Long[] ids);
|
||||
|
||||
/**
|
||||
* 导入员工实体关系数据(异步)
|
||||
*
|
||||
* @param excelList Excel实体列表
|
||||
* @return 任务ID
|
||||
*/
|
||||
String importRelation(List<CcdiStaffEnterpriseRelationExcel> excelList);
|
||||
}
|
||||
@@ -0,0 +1,266 @@
|
||||
package com.ruoyi.ccdi.service.impl;
|
||||
|
||||
import com.alibaba.fastjson2.JSON;
|
||||
import com.ruoyi.ccdi.domain.CcdiStaffEnterpriseRelation;
|
||||
import com.ruoyi.ccdi.domain.dto.CcdiStaffEnterpriseRelationAddDTO;
|
||||
import com.ruoyi.ccdi.domain.excel.CcdiStaffEnterpriseRelationExcel;
|
||||
import com.ruoyi.ccdi.domain.vo.ImportResult;
|
||||
import com.ruoyi.ccdi.domain.vo.ImportStatusVO;
|
||||
import com.ruoyi.ccdi.domain.vo.StaffEnterpriseRelationImportFailureVO;
|
||||
import com.ruoyi.ccdi.mapper.CcdiStaffEnterpriseRelationMapper;
|
||||
import com.ruoyi.ccdi.service.ICcdiStaffEnterpriseRelationImportService;
|
||||
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 CcdiStaffEnterpriseRelationImportServiceImpl implements ICcdiStaffEnterpriseRelationImportService {
|
||||
|
||||
@Resource
|
||||
private CcdiStaffEnterpriseRelationMapper relationMapper;
|
||||
|
||||
@Resource
|
||||
private RedisTemplate<String, Object> redisTemplate;
|
||||
|
||||
@Override
|
||||
@Async
|
||||
@Transactional
|
||||
public void importRelationAsync(List<CcdiStaffEnterpriseRelationExcel> excelList, String taskId, String userName) {
|
||||
List<CcdiStaffEnterpriseRelation> newRecords = new ArrayList<>();
|
||||
List<StaffEnterpriseRelationImportFailureVO> failures = new ArrayList<>();
|
||||
|
||||
// 批量查询已存在的person_id + social_credit_code组合
|
||||
Set<String> existingCombinations = getExistingCombinations(excelList);
|
||||
|
||||
// 用于跟踪Excel文件内已处理的组合
|
||||
Set<String> processedCombinations = new HashSet<>();
|
||||
|
||||
// 分类数据
|
||||
for (int i = 0; i < excelList.size(); i++) {
|
||||
CcdiStaffEnterpriseRelationExcel excel = excelList.get(i);
|
||||
|
||||
try {
|
||||
// 转换为AddDTO进行验证
|
||||
CcdiStaffEnterpriseRelationAddDTO addDTO = new CcdiStaffEnterpriseRelationAddDTO();
|
||||
BeanUtils.copyProperties(excel, addDTO);
|
||||
|
||||
// 验证数据
|
||||
validateRelationData(addDTO);
|
||||
|
||||
String combination = excel.getPersonId() + "|" + excel.getSocialCreditCode();
|
||||
|
||||
CcdiStaffEnterpriseRelation relation = new CcdiStaffEnterpriseRelation();
|
||||
BeanUtils.copyProperties(excel, relation);
|
||||
|
||||
if (existingCombinations.contains(combination)) {
|
||||
// 组合已存在,直接报错
|
||||
throw new RuntimeException(String.format("身份证号[%s]和统一社会信用代码[%s]的组合已存在,请勿重复导入",
|
||||
excel.getPersonId(), excel.getSocialCreditCode()));
|
||||
} else if (processedCombinations.contains(combination)) {
|
||||
// Excel文件内部重复
|
||||
throw new RuntimeException(String.format("身份证号[%s]和统一社会信用代码[%s]的组合在导入文件中重复,已跳过此条记录",
|
||||
excel.getPersonId(), excel.getSocialCreditCode()));
|
||||
} else {
|
||||
relation.setCreatedBy(userName);
|
||||
relation.setUpdatedBy(userName);
|
||||
|
||||
// 设置默认值
|
||||
relation.setStatus(1);
|
||||
relation.setIsEmployee(0);
|
||||
relation.setIsEmpFamily(1);
|
||||
relation.setIsCustomer(0);
|
||||
relation.setIsCustFamily(0);
|
||||
relation.setDataSource("IMPORT");
|
||||
|
||||
newRecords.add(relation);
|
||||
processedCombinations.add(combination); // 标记为已处理
|
||||
}
|
||||
|
||||
} catch (Exception e) {
|
||||
StaffEnterpriseRelationImportFailureVO failure = new StaffEnterpriseRelationImportFailureVO();
|
||||
BeanUtils.copyProperties(excel, failure);
|
||||
failure.setErrorMessage(e.getMessage());
|
||||
failures.add(failure);
|
||||
}
|
||||
}
|
||||
|
||||
// 批量插入新数据
|
||||
if (!newRecords.isEmpty()) {
|
||||
saveBatch(newRecords, 500);
|
||||
}
|
||||
|
||||
// 保存失败记录到Redis
|
||||
if (!failures.isEmpty()) {
|
||||
String failuresKey = "import:staffEnterpriseRelation:" + 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<StaffEnterpriseRelationImportFailureVO> getImportFailures(String taskId) {
|
||||
String key = "import:staffEnterpriseRelation:" + taskId + ":failures";
|
||||
Object failuresObj = redisTemplate.opsForValue().get(key);
|
||||
|
||||
if (failuresObj == null) {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
return JSON.parseArray(JSON.toJSONString(failuresObj), StaffEnterpriseRelationImportFailureVO.class);
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询导入状态
|
||||
*
|
||||
* @param taskId 任务ID
|
||||
* @return 导入状态信息
|
||||
*/
|
||||
@Override
|
||||
public ImportStatusVO getImportStatus(String taskId) {
|
||||
String key = "import:staffEnterpriseRelation:" + 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:staffEnterpriseRelation:" + 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 + social_credit_code组合
|
||||
* 性能优化:一次性查询所有组合,避免N+1查询问题
|
||||
*
|
||||
* @param excelList Excel导入数据列表
|
||||
* @return 已存在的组合集合
|
||||
*/
|
||||
private Set<String> getExistingCombinations(List<CcdiStaffEnterpriseRelationExcel> excelList) {
|
||||
// 提取所有的person_id和social_credit_code组合
|
||||
List<String> combinations = excelList.stream()
|
||||
.map(excel -> excel.getPersonId() + "|" + excel.getSocialCreditCode())
|
||||
.filter(Objects::nonNull)
|
||||
.distinct() // 去重
|
||||
.collect(Collectors.toList());
|
||||
|
||||
if (combinations.isEmpty()) {
|
||||
return Collections.emptySet();
|
||||
}
|
||||
|
||||
// 一次性查询所有已存在的组合
|
||||
// 优化前:循环调用existsByPersonIdAndSocialCreditCode,N次数据库查询
|
||||
// 优化后:批量查询,1次数据库查询
|
||||
return new HashSet<>(relationMapper.batchExistsByCombinations(combinations));
|
||||
}
|
||||
|
||||
/**
|
||||
* 批量保存
|
||||
*/
|
||||
private void saveBatch(List<CcdiStaffEnterpriseRelation> list, int batchSize) {
|
||||
// 使用真正的批量插入,分批次执行以提高性能
|
||||
for (int i = 0; i < list.size(); i += batchSize) {
|
||||
int end = Math.min(i + batchSize, list.size());
|
||||
List<CcdiStaffEnterpriseRelation> subList = list.subList(i, end);
|
||||
relationMapper.insertBatch(subList);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 验证员工实体关系数据
|
||||
*
|
||||
* @param addDTO 新增DTO
|
||||
*/
|
||||
private void validateRelationData(CcdiStaffEnterpriseRelationAddDTO addDTO) {
|
||||
// 验证必填字段
|
||||
if (StringUtils.isEmpty(addDTO.getPersonId())) {
|
||||
throw new RuntimeException("身份证号不能为空");
|
||||
}
|
||||
if (StringUtils.isEmpty(addDTO.getSocialCreditCode())) {
|
||||
throw new RuntimeException("统一社会信用代码不能为空");
|
||||
}
|
||||
if (StringUtils.isEmpty(addDTO.getEnterpriseName())) {
|
||||
throw new RuntimeException("企业名称不能为空");
|
||||
}
|
||||
|
||||
// 验证身份证号格式(18位)
|
||||
if (!addDTO.getPersonId().matches("^[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]$")) {
|
||||
throw new RuntimeException("身份证号格式不正确,必须为18位有效身份证号");
|
||||
}
|
||||
|
||||
// 验证统一社会信用代码格式(18位)
|
||||
if (!addDTO.getSocialCreditCode().matches("^[0-9A-HJ-NPQRTUWXY]{2}\\d{6}[0-9A-HJ-NPQRTUWXY]{10}$")) {
|
||||
throw new RuntimeException("统一社会信用代码格式不正确,必须为18位有效统一社会信用代码");
|
||||
}
|
||||
|
||||
// 验证字段长度
|
||||
if (StringUtils.isNotEmpty(addDTO.getRelationPersonPost()) && addDTO.getRelationPersonPost().length() > 100) {
|
||||
throw new RuntimeException("关联人在企业的职务长度不能超过100个字符");
|
||||
}
|
||||
if (addDTO.getEnterpriseName().length() > 200) {
|
||||
throw new RuntimeException("企业名称长度不能超过200个字符");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,227 @@
|
||||
package com.ruoyi.ccdi.service.impl;
|
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.ruoyi.ccdi.domain.CcdiStaffEnterpriseRelation;
|
||||
import com.ruoyi.ccdi.domain.dto.CcdiStaffEnterpriseRelationAddDTO;
|
||||
import com.ruoyi.ccdi.domain.dto.CcdiStaffEnterpriseRelationEditDTO;
|
||||
import com.ruoyi.ccdi.domain.dto.CcdiStaffEnterpriseRelationQueryDTO;
|
||||
import com.ruoyi.ccdi.domain.excel.CcdiStaffEnterpriseRelationExcel;
|
||||
import com.ruoyi.ccdi.domain.vo.CcdiStaffEnterpriseRelationVO;
|
||||
import com.ruoyi.ccdi.mapper.CcdiStaffEnterpriseRelationMapper;
|
||||
import com.ruoyi.ccdi.service.ICcdiStaffEnterpriseRelationImportService;
|
||||
import com.ruoyi.ccdi.service.ICcdiStaffEnterpriseRelationService;
|
||||
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 CcdiStaffEnterpriseRelationServiceImpl implements ICcdiStaffEnterpriseRelationService {
|
||||
|
||||
@Resource
|
||||
private CcdiStaffEnterpriseRelationMapper relationMapper;
|
||||
|
||||
@Resource
|
||||
private ICcdiStaffEnterpriseRelationImportService relationImportService;
|
||||
|
||||
@Resource
|
||||
private RedisTemplate<String, Object> redisTemplate;
|
||||
|
||||
/**
|
||||
* 查询员工实体关系列表
|
||||
*
|
||||
* @param queryDTO 查询条件
|
||||
* @return 员工实体关系VO集合
|
||||
*/
|
||||
@Override
|
||||
public java.util.List<CcdiStaffEnterpriseRelationVO> selectRelationList(CcdiStaffEnterpriseRelationQueryDTO queryDTO) {
|
||||
Page<CcdiStaffEnterpriseRelationVO> page = new Page<>(1, Integer.MAX_VALUE);
|
||||
Page<CcdiStaffEnterpriseRelationVO> resultPage = relationMapper.selectRelationPage(page, queryDTO);
|
||||
return resultPage.getRecords();
|
||||
}
|
||||
|
||||
/**
|
||||
* 分页查询员工实体关系列表
|
||||
*
|
||||
* @param page 分页对象
|
||||
* @param queryDTO 查询条件
|
||||
* @return 员工实体关系VO分页结果
|
||||
*/
|
||||
@Override
|
||||
public Page<CcdiStaffEnterpriseRelationVO> selectRelationPage(Page<CcdiStaffEnterpriseRelationVO> page, CcdiStaffEnterpriseRelationQueryDTO queryDTO) {
|
||||
return relationMapper.selectRelationPage(page, queryDTO);
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询员工实体关系列表(用于导出)
|
||||
*
|
||||
* @param queryDTO 查询条件
|
||||
* @return 员工实体关系Excel实体集合
|
||||
*/
|
||||
@Override
|
||||
public java.util.List<CcdiStaffEnterpriseRelationExcel> selectRelationListForExport(CcdiStaffEnterpriseRelationQueryDTO queryDTO) {
|
||||
Page<CcdiStaffEnterpriseRelationVO> page = new Page<>(1, Integer.MAX_VALUE);
|
||||
Page<CcdiStaffEnterpriseRelationVO> resultPage = relationMapper.selectRelationPage(page, queryDTO);
|
||||
|
||||
return resultPage.getRecords().stream().map(vo -> {
|
||||
CcdiStaffEnterpriseRelationExcel excel = new CcdiStaffEnterpriseRelationExcel();
|
||||
BeanUtils.copyProperties(vo, excel);
|
||||
return excel;
|
||||
}).collect(Collectors.toList());
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询员工实体关系详情
|
||||
*
|
||||
* @param id 主键ID
|
||||
* @return 员工实体关系VO
|
||||
*/
|
||||
@Override
|
||||
public CcdiStaffEnterpriseRelationVO selectRelationById(Long id) {
|
||||
return relationMapper.selectRelationById(id);
|
||||
}
|
||||
|
||||
/**
|
||||
* 新增员工实体关系
|
||||
*
|
||||
* @param addDTO 新增DTO
|
||||
* @return 结果
|
||||
*/
|
||||
@Override
|
||||
@Transactional
|
||||
public int insertRelation(CcdiStaffEnterpriseRelationAddDTO addDTO) {
|
||||
// 检查身份证号+统一社会信用代码唯一性
|
||||
if (relationMapper.existsByPersonIdAndSocialCreditCode(addDTO.getPersonId(), addDTO.getSocialCreditCode())) {
|
||||
throw new RuntimeException("该身份证号和统一社会信用代码组合已存在");
|
||||
}
|
||||
|
||||
CcdiStaffEnterpriseRelation relation = new CcdiStaffEnterpriseRelation();
|
||||
BeanUtils.copyProperties(addDTO, relation);
|
||||
|
||||
// 设置默认值
|
||||
// 新增时强制设置状态为有效
|
||||
relation.setStatus(1);
|
||||
|
||||
if (relation.getIsEmployee() == null) {
|
||||
relation.setIsEmployee(0);
|
||||
}
|
||||
if (relation.getIsEmpFamily() == null) {
|
||||
relation.setIsEmpFamily(1);
|
||||
}
|
||||
if (relation.getIsCustomer() == null) {
|
||||
relation.setIsCustomer(0);
|
||||
}
|
||||
if (relation.getIsCustFamily() == null) {
|
||||
relation.setIsCustFamily(0);
|
||||
}
|
||||
if (StringUtils.isEmpty(relation.getDataSource())) {
|
||||
relation.setDataSource("MANUAL");
|
||||
}
|
||||
|
||||
int result = relationMapper.insert(relation);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改员工实体关系
|
||||
*
|
||||
* @param editDTO 编辑DTO
|
||||
* @return 结果
|
||||
*/
|
||||
@Override
|
||||
@Transactional
|
||||
public int updateRelation(CcdiStaffEnterpriseRelationEditDTO editDTO) {
|
||||
// 使用LambdaUpdateWrapper只更新非null字段,保护系统字段不被覆盖
|
||||
LambdaUpdateWrapper<CcdiStaffEnterpriseRelation> updateWrapper = new LambdaUpdateWrapper<>();
|
||||
updateWrapper.eq(CcdiStaffEnterpriseRelation::getId, editDTO.getId());
|
||||
|
||||
// 只更新前端可编辑的字段
|
||||
updateWrapper.set(editDTO.getRelationPersonPost() != null, CcdiStaffEnterpriseRelation::getRelationPersonPost, editDTO.getRelationPersonPost());
|
||||
updateWrapper.set(editDTO.getEnterpriseName() != null, CcdiStaffEnterpriseRelation::getEnterpriseName, editDTO.getEnterpriseName());
|
||||
updateWrapper.set(editDTO.getStatus() != null, CcdiStaffEnterpriseRelation::getStatus, editDTO.getStatus());
|
||||
updateWrapper.set(editDTO.getRemark() != null, CcdiStaffEnterpriseRelation::getRemark, editDTO.getRemark());
|
||||
|
||||
// 注意:以下字段不可修改
|
||||
// - personId(身份证号,业务主键)
|
||||
// - socialCreditCode(统一社会信用代码,业务主键)
|
||||
// - dataSource(数据来源,系统字段)
|
||||
// - isEmployee(是否为员工,系统字段)
|
||||
// - isEmpFamily(是否为员工家属,系统字段)
|
||||
// - isCustomer(是否为客户,系统字段)
|
||||
// - isCustFamily(是否为客户家属,系统字段)
|
||||
|
||||
int result = relationMapper.update(null, updateWrapper);
|
||||
|
||||
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<CcdiStaffEnterpriseRelationExcel> 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:staffEnterpriseRelation:" + 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;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,94 @@
|
||||
<?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.ccdi.mapper.CcdiStaffEnterpriseRelationMapper">
|
||||
|
||||
<!-- 员工实体关系信息ResultMap -->
|
||||
<resultMap type="com.ruoyi.ccdi.domain.vo.CcdiStaffEnterpriseRelationVO" id="CcdiStaffEnterpriseRelationVOResult">
|
||||
<id property="id" column="id"/>
|
||||
<result property="personId" column="person_id"/>
|
||||
<result property="relationPersonPost" column="relation_person_post"/>
|
||||
<result property="socialCreditCode" column="social_credit_code"/>
|
||||
<result property="enterpriseName" column="enterprise_name"/>
|
||||
<result property="status" column="status"/>
|
||||
<result property="remark" column="remark"/>
|
||||
<result property="dataSource" column="data_source"/>
|
||||
<result property="isEmployee" column="is_employee"/>
|
||||
<result property="isEmpFamily" column="is_emp_family"/>
|
||||
<result property="isCustomer" column="is_customer"/>
|
||||
<result property="isCustFamily" column="is_cust_family"/>
|
||||
<result property="createTime" column="create_time"/>
|
||||
<result property="updateTime" column="update_time"/>
|
||||
<result property="createdBy" column="created_by"/>
|
||||
<result property="updatedBy" column="updated_by"/>
|
||||
</resultMap>
|
||||
|
||||
<!-- 分页查询员工实体关系列表 -->
|
||||
<select id="selectRelationPage" resultMap="CcdiStaffEnterpriseRelationVOResult">
|
||||
SELECT
|
||||
id, person_id, relation_person_post, social_credit_code, enterprise_name,
|
||||
status, remark, data_source, is_employee, is_emp_family, is_customer, is_cust_family,
|
||||
created_by, create_time, updated_by, update_time
|
||||
FROM ccdi_staff_enterprise_relation
|
||||
<where>
|
||||
<if test="query.personId != null and query.personId != ''">
|
||||
AND person_id LIKE CONCAT('%', #{query.personId}, '%')
|
||||
</if>
|
||||
<if test="query.socialCreditCode != null and query.socialCreditCode != ''">
|
||||
AND social_credit_code LIKE CONCAT('%', #{query.socialCreditCode}, '%')
|
||||
</if>
|
||||
<if test="query.enterpriseName != null and query.enterpriseName != ''">
|
||||
AND enterprise_name LIKE CONCAT('%', #{query.enterpriseName}, '%')
|
||||
</if>
|
||||
<if test="query.status != null">
|
||||
AND status = #{query.status}
|
||||
</if>
|
||||
</where>
|
||||
ORDER BY create_time DESC
|
||||
</select>
|
||||
|
||||
<!-- 查询员工实体关系详情 -->
|
||||
<select id="selectRelationById" resultMap="CcdiStaffEnterpriseRelationVOResult">
|
||||
SELECT
|
||||
id, person_id, relation_person_post, social_credit_code, enterprise_name,
|
||||
status, remark, data_source, is_employee, is_emp_family, is_customer, is_cust_family,
|
||||
created_by, create_time, updated_by, update_time
|
||||
FROM ccdi_staff_enterprise_relation
|
||||
WHERE id = #{id}
|
||||
</select>
|
||||
|
||||
<!-- 判断身份证号和统一社会信用代码的组合是否已存在 -->
|
||||
<select id="existsByPersonIdAndSocialCreditCode" resultType="boolean">
|
||||
SELECT COUNT(1) > 0
|
||||
FROM ccdi_staff_enterprise_relation
|
||||
WHERE person_id = #{personId}
|
||||
AND social_credit_code = #{socialCreditCode}
|
||||
</select>
|
||||
|
||||
<!-- 批量查询已存在的person_id + social_credit_code组合 -->
|
||||
<!-- 优化导入性能:一次性查询所有组合,避免N+1查询问题 -->
|
||||
<select id="batchExistsByCombinations" resultType="string">
|
||||
SELECT CONCAT(person_id, '|', social_credit_code) AS combination
|
||||
FROM ccdi_staff_enterprise_relation
|
||||
WHERE CONCAT(person_id, '|', social_credit_code) IN
|
||||
<foreach collection="combinations" item="combination" open="(" separator="," close=")">
|
||||
#{combination}
|
||||
</foreach>
|
||||
</select>
|
||||
|
||||
<!-- 批量插入员工实体关系数据 -->
|
||||
<insert id="insertBatch">
|
||||
INSERT INTO ccdi_staff_enterprise_relation
|
||||
(person_id, relation_person_post, social_credit_code, enterprise_name,
|
||||
status, remark, data_source, is_employee, is_emp_family, is_customer, is_cust_family,
|
||||
created_by, create_time, updated_by, update_time)
|
||||
VALUES
|
||||
<foreach collection="list" item="item" separator=",">
|
||||
(#{item.personId}, #{item.relationPersonPost}, #{item.socialCreditCode}, #{item.enterpriseName},
|
||||
#{item.status}, #{item.remark}, #{item.dataSource}, #{item.isEmployee}, #{item.isEmpFamily}, #{item.isCustomer}, #{item.isCustFamily},
|
||||
#{item.createdBy}, NOW(), #{item.updatedBy}, NOW())
|
||||
</foreach>
|
||||
</insert>
|
||||
|
||||
</mapper>
|
||||
Reference in New Issue
Block a user