Selaa lähdekoodia

1、根据id获取员工信息接口调整

dongpo 7 kuukautta sitten
vanhempi
commit
6e917fe9d0

+ 5 - 0
yudao-module-personnel/yudao-module-employee-biz/pom.xml

@@ -27,6 +27,11 @@
             <artifactId>yudao-module-system-biz</artifactId>
             <version>${revision}</version>
         </dependency>
+        <dependency>
+            <groupId>cn.iocoder.boot</groupId>
+            <artifactId>yudao-module-relations-api</artifactId>
+            <version>${revision}</version>
+        </dependency>
 
         <!-- 业务组件 -->
         <dependency>

+ 37 - 1
yudao-module-personnel/yudao-module-employee-biz/src/main/java/cn/iocoder/yudao/module/employee/controller/admin/info/EmployeeInfoController.java

@@ -15,6 +15,8 @@ import cn.iocoder.yudao.module.employee.controller.admin.info.vo.EmployeeInfoSav
 import cn.iocoder.yudao.module.employee.convert.info.EmployeeConvert;
 import cn.iocoder.yudao.module.employee.dal.dataobject.info.EmployeeInfoDO;
 import cn.iocoder.yudao.module.employee.service.info.EmployeeInfoService;
+import cn.iocoder.yudao.module.relations.api.contract.RelationsContractApi;
+import cn.iocoder.yudao.module.relations.api.contract.dto.RelationsContractDTO;
 import cn.iocoder.yudao.module.system.dal.dataobject.dept.DeptDO;
 import cn.iocoder.yudao.module.system.dal.dataobject.dept.PostDO;
 import cn.iocoder.yudao.module.system.service.dept.DeptService;
@@ -54,6 +56,9 @@ public class EmployeeInfoController {
     @Resource
     private PostService postService;
 
+    @Resource
+    private RelationsContractApi relationsContractApi;
+
     @PostMapping("/create")
     @Operation(summary = "创建员工信息")
     @PreAuthorize("@ss.hasPermission('employee:info:create')")
@@ -83,8 +88,39 @@ public class EmployeeInfoController {
     @Parameter(name = "id", description = "编号", required = true, example = "1024")
     @PreAuthorize("@ss.hasPermission('employee:info:query')")
     public CommonResult<EmployeeInfoRespVO> getInfo(@RequestParam("id") Long id) {
+
         EmployeeInfoDO info = infoService.getInfo(id);
-        return success(BeanUtils.toBean(info, EmployeeInfoRespVO.class));
+        EmployeeInfoRespVO employeeInfoRespVO = BeanUtils.toBean(info, EmployeeInfoRespVO.class);
+
+        // 如果部门ID不为空,则尝试获取部门详细信息
+        Long deptId = employeeInfoRespVO.getDeptId();
+        if (deptId != null) {
+            DeptDO dept = deptService.getDept(deptId);
+            // 如果成功获取到部门信息,则设置部门名称到员工信息中
+            if (dept != null) {
+                employeeInfoRespVO.setDeptName(dept.getName());
+            }
+        }
+
+        // 如果职位ID不为空,则尝试获取职位详细信息
+        Long postId = employeeInfoRespVO.getPostId();
+        if (postId != null) {
+            PostDO post = postService.getPost(postId);
+            // 如果成功获取到职位信息,则设置职位名称到员工信息中
+            if (post != null) {
+                employeeInfoRespVO.setPosition(post.getName());
+            }
+        }
+
+        // 根据员工ID查询员工当前的合同信息
+        RelationsContractDTO lastContract = relationsContractApi.getLastContract(employeeInfoRespVO.getId());
+        // 如果员工的合同信息存在,则更新员工信息中的合同起始和结束日期
+        if (lastContract != null) {
+            employeeInfoRespVO.setContractStartDate(lastContract.getContractStartDate());
+            employeeInfoRespVO.setContractEndDate(lastContract.getContractEndDate());
+        }
+
+        return success(employeeInfoRespVO);
     }
 
     @GetMapping("/getLoginEmployee")

+ 8 - 0
yudao-module-personnel/yudao-module-employee-biz/src/main/java/cn/iocoder/yudao/module/employee/controller/admin/info/vo/EmployeeInfoRespVO.java

@@ -200,4 +200,12 @@ public class EmployeeInfoRespVO {
     @ExcelProperty("用户ID")
     private Long userId;
 
+    @Schema(description = "最新合同开始日期")
+    @ExcelProperty("最新合同开始日期")
+    private LocalDate contractStartDate;
+
+    @Schema(description = "最新合同结束日期")
+    @ExcelProperty("最新合同结束日期")
+    private LocalDate contractEndDate;
+
 }

+ 19 - 0
yudao-module-personnel/yudao-module-relations-api/src/main/java/cn/iocoder/yudao/module/relations/api/contract/RelationsContractApi.java

@@ -0,0 +1,19 @@
+package cn.iocoder.yudao.module.relations.api.contract;
+
+import cn.iocoder.yudao.module.relations.api.contract.dto.RelationsContractDTO;
+
+public interface RelationsContractApi {
+
+    /**
+     * 获取员工的最新合同信息
+     *
+     * 此方法用于根据员工ID检索系统中该员工的最新合同信息详情
+     * 它解释了为什么需要这个方法:为了确保能够获取到员工当前的有效合同,以便进行后续的相关操作或查询
+     *
+     * @param employeeId 员工ID
+     *                  员工ID是唯一标识员工的键值,此参数用于定位特定员工的合同信息
+     * @return RelationsContractDTO 返回员工的最新合同信息
+     *                 返回的数据传输对象(DTO)包含员工最新合同的详细信息,如合同类型、有效期等
+     */
+    RelationsContractDTO getLastContract(Long employeeId);
+}

+ 76 - 0
yudao-module-personnel/yudao-module-relations-api/src/main/java/cn/iocoder/yudao/module/relations/api/contract/dto/RelationsContractDTO.java

@@ -0,0 +1,76 @@
+package cn.iocoder.yudao.module.relations.api.contract.dto;
+
+import lombok.Data;
+
+import java.time.LocalDate;
+import java.time.LocalDateTime;
+import java.util.List;
+
+@Data
+public class RelationsContractDTO {
+
+    /**
+     * 自增ID
+     */
+    private Long id;
+    /**
+     * 业务UUID
+     */
+    private String contractId;
+    /**
+     * 员工姓名
+     */
+    private String employeeName;
+    /**
+     * 部门ID
+     */
+    private Long deptId;
+    /**
+     * 部门名称
+     */
+    private String deptName;
+    /**
+     * 职位编号
+     */
+    private Long postId;
+    /**
+     * 职位名称
+     */
+    private String position;
+    /**
+     * 员工编号
+     */
+    private String employeeNumber;
+    /**
+     * 员工手机号
+     */
+    private String employeePhone;
+    /**
+     * 合同开始日期
+     */
+    private LocalDate contractStartDate;
+    /**
+     * 合同结束日期
+     */
+    private LocalDate contractEndDate;
+    /**
+     * 合同期限
+     */
+    private String contractDeadline;
+    /**
+     * 备注信息
+     */
+    private String remarks;
+    /**
+     * 状态
+     */
+    private Integer status;
+    /**
+     * 员工ID
+     */
+    private Long employeeId;
+    /**
+     * 租户编号
+     */
+    private Long tenantId;
+}

+ 33 - 0
yudao-module-personnel/yudao-module-relations-biz/src/main/java/cn/iocoder/yudao/module/relations/api/contract/RelationsContractApiImpl.java

@@ -0,0 +1,33 @@
+package cn.iocoder.yudao.module.relations.api.contract;
+
+import cn.hutool.core.collection.CollUtil;
+import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
+import cn.iocoder.yudao.module.relations.api.contract.dto.RelationsContractDTO;
+import cn.iocoder.yudao.module.relations.dal.dataobject.contract.RelationsContractDO;
+import cn.iocoder.yudao.module.relations.service.contract.RelationsContractService;
+import org.springframework.stereotype.Service;
+
+import javax.annotation.Resource;
+import java.util.List;
+
+@Service
+public class RelationsContractApiImpl implements RelationsContractApi{
+
+    @Resource
+    private RelationsContractService relationsContractService;
+
+    @Override
+    public RelationsContractDTO getLastContract(Long employeeId) {
+        // 根据员工ID查询关联合同信息列表
+        List<RelationsContractDO> relationsContractDOList = relationsContractService.getContractInfoList(employeeId);
+        // 如果列表不为空
+        if (CollUtil.isNotEmpty(relationsContractDOList)) {
+            // 获取列表中的第一个关联合同信息
+            RelationsContractDO relationsContractDO = relationsContractDOList.get(0);
+            // 将关联合同信息转换为DTO对象并返回
+            return BeanUtils.toBean(relationsContractDO, RelationsContractDTO.class);
+        }
+        // 如果列表为空,返回null
+        return null;
+    }
+}

+ 11 - 0
yudao-module-personnel/yudao-module-relations-biz/src/main/java/cn/iocoder/yudao/module/relations/service/contract/RelationsContractService.java

@@ -8,6 +8,7 @@ import cn.iocoder.yudao.module.relations.controller.admin.contract.vo.RelationsC
 import cn.iocoder.yudao.module.relations.dal.dataobject.contract.RelationsContractDO;
 
 import javax.validation.Valid;
+import java.util.List;
 
 /**
  * 员工合同信息 Service 接口
@@ -70,4 +71,14 @@ public interface RelationsContractService {
      */
     int effectiveContractInfo();
 
+    /**
+     * 根据员工ID获取合同信息列表
+     *
+     * 此方法用于查询特定员工相关的合同信息列表它提供了一种根据员工ID检索该员工所有相关合同的方式,
+     * 使得用户可以在系统中查看和分析员工的合同情况
+     *
+     * @param employeeId 员工ID,用于定位特定员工的相关合同信息
+     * @return 返回一个包含特定员工所有相关合同信息的列表
+     */
+    List<RelationsContractDO> getContractInfoList(Long employeeId);
 }

+ 16 - 0
yudao-module-personnel/yudao-module-relations-biz/src/main/java/cn/iocoder/yudao/module/relations/service/contract/RelationsContractServiceImpl.java

@@ -14,6 +14,7 @@ import cn.iocoder.yudao.module.relations.controller.admin.contract.vo.RelationsC
 import cn.iocoder.yudao.module.relations.dal.dataobject.contract.RelationsContractDO;
 import cn.iocoder.yudao.module.relations.dal.mysql.contract.RelationsContractMapper;
 import cn.iocoder.yudao.module.relations.enums.contractinfo.ContractInfoStatusEnum;
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
 import org.springframework.stereotype.Service;
 import org.springframework.validation.annotation.Validated;
 import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
@@ -180,6 +181,21 @@ public class RelationsContractServiceImpl implements RelationsContractService {
         return doneContracts.size();
     }
 
+    @Override
+    public List<RelationsContractDO> getContractInfoList(Long employeeId) {
+        // 检查员工ID是否为空,如果为空则直接返回一个空的列表
+        if (employeeId == null) {
+            return Collections.emptyList();
+        }
+        // 创建一个查询包装器,用于构建查询条件
+        LambdaQueryWrapper<RelationsContractDO> lambdaQueryWrapper = new LambdaQueryWrapper<>();
+        // 设置查询条件,查找与给定员工ID相匹配的合同记录,并按创建时间降序排序
+        lambdaQueryWrapper.eq(RelationsContractDO::getEmployeeId, employeeId)
+                .orderByDesc(RelationsContractDO::getCreateTime);
+        // 执行查询并返回结果列表
+        return contractMapper.selectList(lambdaQueryWrapper);
+    }
+
     /**
      * 保存业务uuid到附件中
      */