| | |
| | | package com.smartor.service.impl; |
| | | |
| | | import com.ruoyi.common.core.domain.entity.SysUser; |
| | | import com.ruoyi.common.utils.DateUtils; |
| | | import com.ruoyi.common.utils.StringUtils; |
| | | import com.ruoyi.common.core.domain.entity.SysUserRole; |
| | | import com.smartor.domain.PatArchiveImport; |
| | | import com.smartor.mapper.PatArchiveImportMapper; |
| | | import com.smartor.service.IPatArchiveImportService; |
| | | import org.apache.commons.collections4.CollectionUtils; |
| | | import org.apache.commons.lang3.ObjectUtils; |
| | | import org.apache.poi.ss.usermodel.Cell; |
| | | import org.apache.poi.ss.usermodel.Row; |
| | |
| | | import org.apache.poi.xssf.usermodel.XSSFWorkbook; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.transaction.annotation.Transactional; |
| | | import org.springframework.web.multipart.MultipartFile; |
| | | |
| | | import java.text.DecimalFormat; |
| | |
| | | import java.util.ArrayList; |
| | | import java.util.Date; |
| | | import java.util.List; |
| | | import java.util.regex.Pattern; |
| | | |
| | | /** |
| | | * Excel导入患者档案Service业务层处理 |
| | |
| | | public class PatArchiveImportServiceImpl implements IPatArchiveImportService { |
| | | @Autowired |
| | | private PatArchiveImportMapper patArchiveImportMapper; |
| | | |
| | | |
| | | /** |
| | | * 查询Excel导入患者档案 |
| | |
| | | } |
| | | |
| | | @Override |
| | | public List<PatArchiveImport> importPatInfo(MultipartFile multipartFile) { |
| | | public List<PatArchiveImport> importPatInfo(MultipartFile multipartFile, SysUser user) { |
| | | //用于返回 |
| | | List<PatArchiveImport> patArchiveImports = new ArrayList<>(); |
| | | |
| | |
| | | PatArchiveImport patArchiveImport = new PatArchiveImport(); |
| | | Row row = sheet.getRow(i); |
| | | //如果行为空,进行下一次循环 |
| | | if (ObjectUtils.isEmpty(row.getCell(0)) && ObjectUtils.isEmpty(row.getCell(1)) && ObjectUtils.isEmpty(row.getCell(2))) { |
| | | if (ObjectUtils.isEmpty(row.getCell(0)) && StringUtils.isNotEmpty(row.getCell(0) + "") && ObjectUtils.isEmpty(row.getCell(1)) && StringUtils.isNotEmpty(row.getCell(1) + "") && ObjectUtils.isEmpty(row.getCell(2)) && StringUtils.isNotEmpty(row.getCell(2) + "")) { |
| | | continue; |
| | | } |
| | | //判断数据是否有问题 |
| | | |
| | | |
| | | if (ObjectUtils.isNotEmpty(row.getCell(0).toString())) { |
| | | if (ObjectUtils.isNotEmpty(row.getCell(0)) && StringUtils.isNotEmpty(row.getCell(0) + "")) { |
| | | patArchiveImport.setName(row.getCell(0).toString()); |
| | | } else { |
| | | continue; |
| | | } |
| | | if (ObjectUtils.isNotEmpty(row.getCell(1))) { |
| | | patArchiveImport.setIdcardno(row.getCell(1).toString()); |
| | | if (ObjectUtils.isNotEmpty(row.getCell(1)) && StringUtils.isNotEmpty(row.getCell(1) + "")) { |
| | | Cell cell = row.getCell(1); |
| | | if (row.getCell(1).toString().contains("X") || row.getCell(1).toString().contains("x")) { |
| | | patArchiveImport.setIdcardno(row.getCell(1).toString()); |
| | | } else { |
| | | Pattern pattern = Pattern.compile("^[-\\+]?[\\d]*$"); |
| | | boolean matches = pattern.matcher(row.getCell(1).toString()).matches(); |
| | | if (matches) { |
| | | patArchiveImport.setIdcardno(row.getCell(1).toString()); |
| | | } else { |
| | | double numericCellValue = cell.getNumericCellValue(); |
| | | DecimalFormat decimalFormat = new DecimalFormat("#"); |
| | | String formattedValue = decimalFormat.format(numericCellValue); |
| | | patArchiveImport.setIdcardno(formattedValue); |
| | | } |
| | | } |
| | | |
| | | boolean contains = qc.contains(row.getCell(1).toString()); |
| | | if (contains) continue; |
| | | PatArchiveImport pt = new PatArchiveImport(); |
| | | pt.setIdcardno(patArchiveImport.getIdcardno()); |
| | | pt.setDelFlag("0"); |
| | | List<PatArchiveImport> patArchiveImports1 = patArchiveImportMapper.selectPatArchiveImportList(pt); |
| | | if (contains || CollectionUtils.isNotEmpty(patArchiveImports1)) continue; |
| | | } |
| | | |
| | | if (ObjectUtils.isNotEmpty(row.getCell(2))) { |
| | | if (ObjectUtils.isNotEmpty(row.getCell(2)) && StringUtils.isNotEmpty(row.getCell(2) + "")) { |
| | | Cell cell = row.getCell(2); |
| | | double numericCellValue = cell.getNumericCellValue(); |
| | | DecimalFormat decimalFormat = new DecimalFormat("#"); |
| | | String formattedValue = decimalFormat.format(numericCellValue); |
| | | patArchiveImport.setTelcode(formattedValue); |
| | | } |
| | | if (ObjectUtils.isNotEmpty(row.getCell(3))) { |
| | | if (ObjectUtils.isNotEmpty(row.getCell(3)) && StringUtils.isNotEmpty(row.getCell(3) + "")) { |
| | | patArchiveImport.setBatchName(row.getCell(3).toString()); |
| | | } |
| | | if (ObjectUtils.isNotEmpty(row.getCell(4))) { |
| | | if (ObjectUtils.isNotEmpty(row.getCell(4)) && StringUtils.isNotEmpty(row.getCell(4) + "")) { |
| | | patArchiveImport.setPatientno(row.getCell(4).toString()); |
| | | } |
| | | |
| | | if (ObjectUtils.isNotEmpty(row.getCell(5))) { |
| | | if (ObjectUtils.isNotEmpty(row.getCell(5)) && StringUtils.isNotEmpty(row.getCell(5) + "")) { |
| | | patArchiveImport.setPattype(row.getCell(5).toString()); |
| | | } |
| | | if (ObjectUtils.isNotEmpty(row.getCell(6))) { |
| | | if (ObjectUtils.isNotEmpty(row.getCell(6)) && StringUtils.isNotEmpty(row.getCell(6) + "")) { |
| | | patArchiveImport.setSex(Long.valueOf(row.getCell(6).toString())); |
| | | } |
| | | if (ObjectUtils.isNotEmpty(row.getCell(7))) { |
| | | if (ObjectUtils.isNotEmpty(row.getCell(7)) && StringUtils.isNotEmpty(row.getCell(7) + "")) { |
| | | patArchiveImport.setAge(Long.valueOf(row.getCell(7).toString())); |
| | | } |
| | | |
| | | |
| | | patArchiveImport.setCreateTime(new Date()); |
| | | patArchiveImport.setUpdateTime(new Date()); |
| | | //批量号(当前时间) |
| | | patArchiveImport.setBatchNo(new SimpleDateFormat("yyyyMMddHHmmss").format(new Date())); |
| | | patArchiveImport.setCreateBy(user.getNickName()); |
| | | insertPatArchiveImport(patArchiveImport); |
| | | //给当前导入患者,注册帐号 sys_user sys_user_role |
| | | if (patArchiveImport.getAccount() == 1) { |
| | | //查询一下,该患者是否已经在表里创建了帐号 |
| | | SysUser sysUser = patArchiveImportMapper.checkUserExist(patArchiveImport.getIdcardno()); |
| | | if (ObjectUtils.isEmpty(sysUser)) { |
| | | sysUser = new SysUser(); |
| | | //如果为空,则进行新增sys_user sys_role |
| | | sysUser.setIdCard(patArchiveImport.getIdcardno()); |
| | | int start = patArchiveImport.getIdcardno().length() - 6; |
| | | String lastSixDigits = patArchiveImport.getIdcardno().substring(start, start + 6); |
| | | sysUser.setUserName(lastSixDigits); |
| | | //密码:xh@123456 |
| | | sysUser.setPassword("$2a$10$zja67LEWTESHutljd8bqEeRy.VgWb./8iJPpFR6VjTUa7ZYNfRRrO"); |
| | | sysUser.setPhonenumber(patArchiveImport.getTelcode()); |
| | | sysUser.setUserType("患者"); |
| | | sysUser.setDeptId(395L); |
| | | sysUser.setNickName(patArchiveImport.getName()); |
| | | sysUser.setCreateTime(new Date()); |
| | | sysUser.setCreateBy(user.getNickName()); |
| | | sysUser.setUpdateTime(new Date()); |
| | | sysUser.setUpdateBy(user.getNickName()); |
| | | patArchiveImportMapper.insertUser(sysUser); |
| | | //将患者与角色绑定 |
| | | SysUserRole sysUserRole = new SysUserRole(); |
| | | sysUserRole.setUserId(sysUser.getUserId()); |
| | | sysUserRole.setRoleId(6L); |
| | | patArchiveImportMapper.insertUserRole(sysUserRole); |
| | | } |
| | | } |
| | | |
| | | patArchiveImports.add(patArchiveImport); |
| | | } |