| | |
| | | import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
| | | import com.ruoyi.common.exception.base.BaseException; |
| | | import com.ruoyi.common.utils.SecurityUtils; |
| | | import com.ruoyi.common.utils.StringUtils; |
| | | import com.ruoyi.common.utils.poi.ExcelUtil; |
| | | import com.ruoyi.dto.WordDateDto; |
| | | import com.ruoyi.project.system.domain.SysDept; |
| | |
| | | |
| | | //在职员工台账分页查询 |
| | | @Override |
| | | public IPage<StaffOnJobDto> staffOnJobListPage(Page page, StaffOnJob staffOnJob) { |
| | | return staffOnJobMapper.staffOnJobListPage(page,staffOnJob); |
| | | public IPage<StaffOnJobDto> staffOnJobListPage(Page page, StaffOnJobDto staffOnJob) { |
| | | IPage<StaffOnJobDto> staffOnJobDtoIPage = staffOnJobMapper.staffOnJobListPage(page, staffOnJob); |
| | | return staffOnJobDtoIPage; |
| | | } |
| | | |
| | | //新增入职 |
| | | @Override |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public int add(StaffOnJobDto staffOnJobPrams) { |
| | | public int add(StaffOnJobDto staffOnJobPrams,boolean isAddUser) { |
| | | String[] ignoreProperties = {"id"};//排除id属性 |
| | | // 判断编号是否存在 |
| | | List<StaffOnJob> staffOnJobs = staffOnJobMapper.selectList(Wrappers.<StaffOnJob>lambdaQuery().eq(StaffOnJob::getStaffNo, staffOnJobPrams.getStaffNo())); |
| | | if (staffOnJobs != null && !staffOnJobs.isEmpty()){ |
| | | throw new BaseException("编号为"+staffOnJobPrams.getStaffNo()+"的员工已经存在,无法新增!!!"); |
| | | if(isAddUser){ |
| | | throw new BaseException("编号为"+staffOnJobPrams.getStaffNo()+"的员工已经存在,无法新增!"); |
| | | } |
| | | return 0; |
| | | } |
| | | |
| | | // 创建入职数据 |
| | | syncStudyInfoFromEducation(staffOnJobPrams); |
| | | staffOnJobPrams.setContractExpireTime(staffOnJobPrams.getContractEndTime()); |
| | | staffOnJobPrams.setStaffState(1); |
| | | staffOnJobMapper.insert(staffOnJobPrams); |
| | |
| | | // 绑定子表数据 |
| | | bingingStaffOnJobExtra(id,staffOnJobParams); |
| | | // 更新员工数据 |
| | | syncStudyInfoFromEducation(staffOnJobParams); |
| | | staffOnJobParams.setContractExpireTime(staffOnJobParams.getContractEndTime()); |
| | | return staffOnJobMapper.updateById(staffOnJobParams); |
| | | } |
| | |
| | | .forEach(staff -> staff.setStaffOnJobId(id)); // 赋值 |
| | | staffEducationService.saveBatch(staffOnJobPrams.getStaffEducationList()); |
| | | } |
| | | |
| | | // 新增工作经历 |
| | | if(CollectionUtils.isNotEmpty(staffOnJobPrams.getStaffWorkExperienceList())){ |
| | | staffOnJobPrams.getStaffWorkExperienceList().stream() |
| | |
| | | .forEach(staff -> staff.setStaffOnJobId(id)); // 赋值 |
| | | staffEmergencyContactServiceImpl.saveBatch(staffOnJobPrams.getStaffEmergencyContactList()); |
| | | } |
| | | } |
| | | |
| | | private void syncStudyInfoFromEducation(StaffOnJob staffOnJobPrams) { |
| | | if (staffOnJobPrams == null || CollectionUtils.isEmpty(staffOnJobPrams.getStaffEducationList())) { |
| | | if (staffOnJobPrams != null) { |
| | | staffOnJobPrams.setFirstStudy("/"); |
| | | staffOnJobPrams.setProfession("/"); |
| | | } |
| | | return; |
| | | } |
| | | Optional<StaffEducation> matchedEducation = staffOnJobPrams.getStaffEducationList().stream() |
| | | .filter(Objects::nonNull) |
| | | .filter(education -> StringUtils.isNotEmpty(education.getMajor())) |
| | | .findFirst(); |
| | | if (matchedEducation.isPresent()) { |
| | | StaffEducation education = matchedEducation.get(); |
| | | staffOnJobPrams.setFirstStudy(education.getEducation()); |
| | | staffOnJobPrams.setProfession(education.getMajor()); |
| | | return; |
| | | } |
| | | staffOnJobPrams.setFirstStudy("/"); |
| | | staffOnJobPrams.setProfession("/"); |
| | | } |
| | | |
| | | |
| | |
| | | List<SysDept> sysDepts = sysDeptMapper.selectList(Wrappers.<SysDept>lambdaQuery().eq(SysDept::getDelFlag, 0)); |
| | | // 获取所有角色数据 |
| | | List<SysRole> sysRoles = sysRoleMapper.selectRoleAll(); |
| | | staffOnJobs.forEach(staffOnJob -> { |
| | | for (StaffOnJobExcelDto staffOnJob : staffOnJobs) { |
| | | StaffOnJobDto staffOnJobDto = new StaffOnJobDto(); |
| | | BeanUtils.copyProperties(staffOnJob, staffOnJobDto); |
| | | // 如果合同年限为空,根据合同开始日期和结束日期计算 |
| | | if (StringUtils.isEmpty(staffOnJob.getContractTerm()) |
| | | && staffOnJob.getContractStartTime() != null |
| | | && staffOnJob.getContractEndTime() != null) { |
| | | LocalDate start = staffOnJob.getContractStartTime().toInstant() |
| | | .atZone(ZoneId.of("Asia/Shanghai")).toLocalDate(); |
| | | LocalDate end = staffOnJob.getContractEndTime().toInstant() |
| | | .atZone(ZoneId.of("Asia/Shanghai")).toLocalDate(); |
| | | int years = end.getYear() - start.getYear(); |
| | | staffOnJobDto.setContractTerm(String.valueOf(years)); |
| | | } |
| | | // 通过名称获取部门id |
| | | staffOnJobDto.setSysDeptId(// ... existing code ... |
| | | sysDepts.stream() |
| | |
| | | .findFirst() |
| | | .map(SysRole::getRoleId) |
| | | .orElse( null)); |
| | | add(staffOnJobDto); |
| | | }); |
| | | int i = add(staffOnJobDto,false); |
| | | } |
| | | return true; |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |