| | |
| | | import com.baomidou.mybatisplus.extension.plugins.pagination.Page; |
| | | import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
| | | import com.ruoyi.common.exception.base.BaseException; |
| | | 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; |
| | | import com.ruoyi.project.system.domain.SysPost; |
| | | import com.ruoyi.project.system.mapper.SysDeptMapper; |
| | | import com.ruoyi.project.system.mapper.SysPostMapper; |
| | | import com.ruoyi.staff.dto.StaffOnJobImportDto; |
| | | import com.ruoyi.staff.dto.StaffOnJobDto; |
| | | import com.ruoyi.staff.mapper.StaffContractMapper; |
| | | import com.ruoyi.staff.mapper.StaffLeaveMapper; |
| | |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.transaction.annotation.Transactional; |
| | | import org.springframework.util.CollectionUtils; |
| | | import org.springframework.web.multipart.MultipartFile; |
| | | |
| | | import javax.servlet.http.HttpServletResponse; |
| | |
| | | import java.time.LocalDate; |
| | | import java.time.ZoneId; |
| | | import java.util.*; |
| | | import java.util.function.Function; |
| | | import java.util.stream.Collectors; |
| | | |
| | | @AllArgsConstructor |
| | | @Service |
| | |
| | | private StaffOnJobMapper staffOnJobMapper; |
| | | @Autowired |
| | | private SysPostMapper sysPostMapper; |
| | | @Autowired |
| | | private SysDeptMapper sysDeptMapper; |
| | | |
| | | @Autowired |
| | | private StaffContractMapper staffContractMapper; |
| | |
| | | } |
| | | |
| | | @Override |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public Boolean importData(MultipartFile file) { |
| | | try { |
| | | ExcelUtil<StaffOnJob> util = new ExcelUtil<>(StaffOnJob.class); |
| | | List<StaffOnJob> staffOnJobs = util.importExcel(file.getInputStream()); |
| | | return saveOrUpdateBatch(staffOnJobs); |
| | | ExcelUtil<StaffOnJobImportDto> util = new ExcelUtil<>(StaffOnJobImportDto.class); |
| | | List<StaffOnJobImportDto> staffOnJobs = util.importExcel(file.getInputStream()); |
| | | if (CollectionUtils.isEmpty(staffOnJobs)) { |
| | | throw new BaseException("模æ¿é误æå¯¼å
¥æ°æ®ä¸ºç©º"); |
| | | } |
| | | |
| | | Map<String, SysPost> postMap = buildPostMap(); |
| | | Map<String, SysDept> deptMap = buildDeptMap(); |
| | | Set<String> importedStaffNos = new HashSet<>(); |
| | | for (int i = 0; i < staffOnJobs.size(); i++) { |
| | | StaffOnJobDto staffOnJobDto = buildImportStaff(staffOnJobs.get(i), i + 2, postMap, deptMap, importedStaffNos); |
| | | add(staffOnJobDto); |
| | | } |
| | | return true; |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | | return false; |
| | | if (e instanceof BaseException) { |
| | | throw (BaseException) e; |
| | | } |
| | | throw new BaseException("导å
¥å¤±è´¥ï¼è¯·æ£æ¥æ¨¡æ¿æ ¼å¼æ¯å¦æ£ç¡®"); |
| | | } |
| | | } |
| | | |
| | | private StaffOnJobDto buildImportStaff(StaffOnJobImportDto row, int rowNum, Map<String, SysPost> postMap, |
| | | Map<String, SysDept> deptMap, Set<String> importedStaffNos) { |
| | | String staffNo = normalizeValue(row.getStaffNo()); |
| | | String postName = normalizeValue(row.getPostName()); |
| | | String deptName = normalizeValue(row.getDeptName()); |
| | | |
| | | if (StringUtils.isBlank(staffNo)) { |
| | | throw new BaseException("第" + rowNum + "è¡åå·¥ç¼å·ä¸è½ä¸ºç©º"); |
| | | } |
| | | if (!importedStaffNos.add(staffNo)) { |
| | | throw new BaseException("第" + rowNum + "è¡åå·¥ç¼å·éå¤ï¼" + staffNo); |
| | | } |
| | | if (StringUtils.isBlank(normalizeValue(row.getStaffName()))) { |
| | | throw new BaseException("第" + rowNum + "è¡åå·¥å§åä¸è½ä¸ºç©º"); |
| | | } |
| | | if (StringUtils.isBlank(postName)) { |
| | | throw new BaseException("第" + rowNum + "è¡å²ä½ä¸è½ä¸ºç©º"); |
| | | } |
| | | if (StringUtils.isBlank(deptName)) { |
| | | throw new BaseException("第" + rowNum + "è¡é¨é¨ä¸è½ä¸ºç©º"); |
| | | } |
| | | if (row.getContractStartTime() == null) { |
| | | throw new BaseException("第" + rowNum + "è¡ååå¼å§æ¥æä¸è½ä¸ºç©º"); |
| | | } |
| | | if (row.getContractEndTime() == null) { |
| | | throw new BaseException("第" + rowNum + "è¡ååç»ææ¥æä¸è½ä¸ºç©º"); |
| | | } |
| | | |
| | | SysPost post = postMap.get(postName); |
| | | if (post == null) { |
| | | throw new BaseException("第" + rowNum + "è¡å²ä½ä¸å卿已åç¨ï¼" + postName); |
| | | } |
| | | SysDept dept = deptMap.get(deptName); |
| | | if (dept == null) { |
| | | throw new BaseException("第" + rowNum + "è¡é¨é¨ä¸å卿已åç¨ï¼" + deptName); |
| | | } |
| | | |
| | | StaffOnJobDto staffOnJobDto = new StaffOnJobDto(); |
| | | BeanUtils.copyProperties(row, staffOnJobDto); |
| | | staffOnJobDto.setStaffNo(staffNo); |
| | | staffOnJobDto.setStaffName(normalizeValue(row.getStaffName())); |
| | | staffOnJobDto.setSex(normalizeValue(row.getSex())); |
| | | staffOnJobDto.setNativePlace(normalizeValue(row.getNativePlace())); |
| | | staffOnJobDto.setAdress(normalizeValue(row.getAdress())); |
| | | staffOnJobDto.setFirstStudy(normalizeValue(row.getFirstStudy())); |
| | | staffOnJobDto.setProfession(normalizeValue(row.getProfession())); |
| | | staffOnJobDto.setAge(normalizeValue(row.getAge())); |
| | | staffOnJobDto.setPhone(normalizeValue(row.getPhone())); |
| | | staffOnJobDto.setEmergencyContact(normalizeValue(row.getEmergencyContact())); |
| | | staffOnJobDto.setEmergencyContactPhone(normalizeValue(row.getEmergencyContactPhone())); |
| | | staffOnJobDto.setContractTerm(normalizeValue(row.getContractTerm())); |
| | | staffOnJobDto.setSysPostId(post.getPostId().intValue()); |
| | | staffOnJobDto.setSysDeptId(dept.getDeptId().intValue()); |
| | | return staffOnJobDto; |
| | | } |
| | | |
| | | private Map<String, SysPost> buildPostMap() { |
| | | SysPost query = new SysPost(); |
| | | query.setStatus("0"); |
| | | return buildUniqueMap(sysPostMapper.selectPostList(query), SysPost::getPostName, "å²ä½"); |
| | | } |
| | | |
| | | private Map<String, SysDept> buildDeptMap() { |
| | | SysDept query = new SysDept(); |
| | | query.setStatus("0"); |
| | | return buildUniqueMap(sysDeptMapper.selectDeptList(query), SysDept::getDeptName, "é¨é¨"); |
| | | } |
| | | |
| | | private <T> Map<String, T> buildUniqueMap(List<T> dataList, Function<T, String> nameGetter, String fieldName) { |
| | | Map<String, List<T>> groupedMap = dataList.stream() |
| | | .filter(Objects::nonNull) |
| | | .filter(item -> StringUtils.isNotBlank(normalizeValue(nameGetter.apply(item)))) |
| | | .collect(Collectors.groupingBy(item -> normalizeValue(nameGetter.apply(item)))); |
| | | |
| | | List<String> duplicateNames = groupedMap.entrySet().stream() |
| | | .filter(entry -> entry.getValue().size() > 1) |
| | | .map(Map.Entry::getKey) |
| | | .sorted() |
| | | .collect(Collectors.toList()); |
| | | if (!duplicateNames.isEmpty()) { |
| | | throw new BaseException("ç³»ç»ä¸åå¨éå" + fieldName + "ï¼æ æ³å¯¼å
¥ï¼" + String.join("ã", duplicateNames)); |
| | | } |
| | | |
| | | return groupedMap.entrySet().stream() |
| | | .collect(Collectors.toMap(Map.Entry::getKey, entry -> entry.getValue().get(0))); |
| | | } |
| | | |
| | | private String normalizeValue(String value) { |
| | | return value == null ? null : value.trim(); |
| | | } |
| | | |
| | | |
| | | @Override |
| | | public String exportCopy(HttpServletResponse response, StaffOnJob staffOnJob) throws Exception { |