| | |
| | | import org.springframework.web.bind.annotation.RestController; |
| | | import org.springframework.web.multipart.MultipartFile; |
| | | |
| | | import com.alibaba.excel.EasyExcel; |
| | | import com.alibaba.excel.EasyExcelFactory; |
| | | import com.alibaba.excel.context.AnalysisContext; |
| | | import com.alibaba.excel.event.AnalysisEventListener; |
| | | import com.alibaba.excel.exception.ExcelDataConvertException; |
| | |
| | | String tel = finSysTenantUser.getUserPhone() != null |
| | | ? AESUtils.decryptStrAES(finSysTenantUser.getUserPhone(), PlatformRSAUtils.AES_KEY) : null; |
| | | finSysTenantUser.setUserPhone(StringUtils.isNotEmpty(tel) ? PhoneNumberUtils.maskMobile(tel) : ""); |
| | | |
| | | // 列表不需要查询角色,只显示列表所需要的信息 |
| | | /*List<S_role> list = finSysTenantUserService.getByUserId(finSysTenantUser.getSysUserId()); |
| | | StringBuilder roleStr = new StringBuilder(); |
| | | list.forEach(s_role -> roleStr.append(s_role.getRole_name()).append(" ")); |
| | | finSysTenantUser.setRoleStr(roleStr.toString()); |
| | | finSysTenantUser.setIsSupplier(finSysTenantUser.getSupplierId() != null ? "是" : "否");*/ |
| | | |
| | | } |
| | | return ResponseValue.success(pager); |
| | |
| | | List<S_role> roles = this.roleService.select(new S_role()); |
| | | ArrayList<FinSysTenantUser> finSysTenantUsers = new ArrayList<>(); |
| | | |
| | | EasyExcel.read(file.getInputStream(), ImportUserParam.class, new AnalysisEventListener<ImportUserParam>() { |
| | | @Override |
| | | public void invoke(ImportUserParam data, AnalysisContext context) { |
| | | if (StringUtils.isEmpty(data.getUserName()) || StringUtils.isEmpty(data.getUserCode()) |
| | | || StringUtils.isEmpty(data.getUserPhone()) || null == data.getSex() |
| | | || StringUtils.isEmpty(data.getEmail()) || null == data.getSeq() |
| | | || StringUtils.isEmpty(data.getRoleName())) { |
| | | throw new ImportUserParamVerifyException("单元格不能为空!"); |
| | | } |
| | | // 根据员工编号查询,如果存在则提示 |
| | | if (finSysTenantUserService.getByUserCode(data.getUserCode()) != null) { |
| | | throw new ImportUserParamVerifyException("员工编号为空或已存在!"); |
| | | } |
| | | if (data.getSex() < 1 && data.getSex() > 0) { |
| | | throw new ImportUserParamVerifyException("性别码只能为 0 或 1"); |
| | | } |
| | | FinSysTenantUser user = new FinSysTenantUser(); |
| | | user.setUserName(data.getUserName()); |
| | | user.setUserCode(data.getUserCode()); |
| | | user.setUserPhone(data.getUserPhone()); |
| | | user.setSex(data.getSex()); |
| | | user.setEmail(data.getEmail()); |
| | | user.setSeq(data.getSeq()); |
| | | user.setTenantId(tenantId); |
| | | user.setTenantCode(tenantCode); |
| | | // 设置角色 |
| | | Optional<S_role> sRole = |
| | | roles.stream().filter(role -> role.getRole_name().equals(data.getRoleName())).findFirst(); |
| | | user.setRoleList(Arrays.asList(sRole.orElse(new S_role()).getRole_id())); |
| | | |
| | | user.setId(NumberGenerator.getLongSequenceNumber()); |
| | | user.setCreateTime(DateUtils.getDateTimeNumber(System.currentTimeMillis())); |
| | | user.setCreateBy(currentUser.getUser_name()); |
| | | user.setUpdateTime(DateUtils.getDateTimeNumber(System.currentTimeMillis())); |
| | | user.setUpdateBy(currentUser.getUser_name()); |
| | | user.setStatus(1);// 0禁用 1启用 |
| | | user.setIsDelete(0);// 是否删除 0是 1否 |
| | | user.setSysUserId(NumberGenerator.getLongSequenceNumber()); |
| | | user.setRemark("批量导入"); |
| | | // 加密手机号 |
| | | setUserPhone(user, data.getUserPhone()); |
| | | |
| | | user.setIsDelete(1); |
| | | // 怎么获取左侧机构树数据 |
| | | user.setSysDeptId(3L); // 对应平台机构id 默认为平台管理 |
| | | finSysTenantUsers.add(user); |
| | | } |
| | | |
| | | @Override |
| | | public void doAfterAllAnalysed(AnalysisContext context) { |
| | | |
| | | } |
| | | |
| | | @Override |
| | | public void onException(Exception exception, AnalysisContext context) throws Exception { |
| | | if (exception != null) { |
| | | // 如果是某一个单元格的转换异常 能获取到具体行号 封装时异常 |
| | | if (exception instanceof ExcelDataConvertException) { |
| | | ExcelDataConvertException excelDataConvertException = (ExcelDataConvertException)exception; |
| | | logger.error("第{}行,第{}列解析异常,数据为:{}", excelDataConvertException.getRowIndex(), |
| | | excelDataConvertException.getColumnIndex() + 1, |
| | | excelDataConvertException.getCellData().getStringValue()); |
| | | throw new IllegalStateException("第" + (excelDataConvertException.getRowIndex() + 1) + "行,第" |
| | | + (excelDataConvertException.getColumnIndex() + 1) + "列解析异常,异常数据为:[ " |
| | | + excelDataConvertException.getCellData().getStringValue() + " ]"); |
| | | EasyExcelFactory |
| | | .read(file.getInputStream(), ImportUserParam.class, new AnalysisEventListener<ImportUserParam>() { |
| | | @Override |
| | | public void invoke(ImportUserParam data, AnalysisContext context) { |
| | | if (StringUtils.isEmpty(data.getUserName()) || StringUtils.isEmpty(data.getUserCode()) |
| | | || StringUtils.isEmpty(data.getUserPhone()) || null == data.getSex() |
| | | || StringUtils.isEmpty(data.getEmail()) || null == data.getSeq() |
| | | || StringUtils.isEmpty(data.getRoleName())) { |
| | | throw new ImportUserParamVerifyException("单元格不能为空!"); |
| | | } |
| | | if (exception instanceof ImportUserParamVerifyException) { |
| | | throw new IllegalStateException("第" + context.readSheetHolder().getRowIndex() + "行, 解析错误:[ " |
| | | + exception.getMessage() + " ]"); |
| | | // 根据员工编号查询,如果存在则提示 |
| | | if (finSysTenantUserService.getByUserCode(data.getUserCode()) != null) { |
| | | throw new ImportUserParamVerifyException("员工编号为空或已存在!"); |
| | | } |
| | | throw exception; |
| | | if (data.getSex() < 1 && data.getSex() > 0) { |
| | | throw new ImportUserParamVerifyException("性别码只能为 0 或 1"); |
| | | } |
| | | FinSysTenantUser user = new FinSysTenantUser(); |
| | | user.setUserName(data.getUserName()); |
| | | user.setUserCode(data.getUserCode()); |
| | | user.setUserPhone(data.getUserPhone()); |
| | | user.setSex(data.getSex()); |
| | | user.setEmail(data.getEmail()); |
| | | user.setSeq(data.getSeq()); |
| | | user.setTenantId(tenantId); |
| | | user.setTenantCode(tenantCode); |
| | | // 设置角色 |
| | | Optional<S_role> sRole = |
| | | roles.stream().filter(role -> role.getRole_name().equals(data.getRoleName())).findFirst(); |
| | | user.setRoleList(Arrays.asList(sRole.orElse(new S_role()).getRole_id())); |
| | | |
| | | user.setId(NumberGenerator.getLongSequenceNumber()); |
| | | user.setCreateTime(DateUtils.getDateTimeNumber(System.currentTimeMillis())); |
| | | user.setCreateBy(currentUser.getUser_name()); |
| | | user.setUpdateTime(DateUtils.getDateTimeNumber(System.currentTimeMillis())); |
| | | user.setUpdateBy(currentUser.getUser_name()); |
| | | user.setStatus(1);// 0禁用 1启用 |
| | | user.setIsDelete(0);// 是否删除 0是 1否 |
| | | user.setSysUserId(NumberGenerator.getLongSequenceNumber()); |
| | | user.setRemark("批量导入"); |
| | | // 加密手机号 |
| | | setUserPhone(user, data.getUserPhone()); |
| | | |
| | | user.setIsDelete(1); |
| | | // 怎么获取左侧机构树数据 |
| | | user.setSysDeptId(3L); // 对应平台机构id 默认为平台管理 |
| | | finSysTenantUsers.add(user); |
| | | } |
| | | } |
| | | }).sheet().doRead(); |
| | | |
| | | @Override |
| | | public void doAfterAllAnalysed(AnalysisContext context) { |
| | | |
| | | } |
| | | |
| | | @Override |
| | | public void onException(Exception exception, AnalysisContext context) throws Exception { |
| | | if (exception != null) { |
| | | // 如果是某一个单元格的转换异常 能获取到具体行号 封装时异常 |
| | | if (exception instanceof ExcelDataConvertException) { |
| | | ExcelDataConvertException excelDataConvertException = (ExcelDataConvertException)exception; |
| | | logger.error("第{}行,第{}列解析异常,数据为:{}", excelDataConvertException.getRowIndex(), |
| | | excelDataConvertException.getColumnIndex() + 1, |
| | | excelDataConvertException.getCellData().getStringValue()); |
| | | throw new IllegalStateException("第" + (excelDataConvertException.getRowIndex() + 1) + "行,第" |
| | | + (excelDataConvertException.getColumnIndex() + 1) + "列解析异常,异常数据为:[ " |
| | | + excelDataConvertException.getCellData().getStringValue() + " ]"); |
| | | } |
| | | if (exception instanceof ImportUserParamVerifyException) { |
| | | throw new IllegalStateException("第" + context.readSheetHolder().getRowIndex() + "行, 解析错误:[ " |
| | | + exception.getMessage() + " ]"); |
| | | } |
| | | throw exception; |
| | | } |
| | | } |
| | | }).sheet().doRead(); |
| | | |
| | | insertUserAndUserCoreBatch(finSysTenantUsers); |
| | | |
| | |
| | | Long sysUserId = finSysTenantUser.getSysUserId(); |
| | | List<S_role> roleList = finSysTenantUserService.getRoleBySysUserId(sysUserId); |
| | | // 过滤仓库管理员的显示 |
| | | roleList.removeIf(role -> role.getRole_name().equals("仓库管理员")); |
| | | roleList.removeIf(role -> "仓库管理员".equals(role.getRole_name())); |
| | | |
| | | HashMap<String, Object> map = new HashMap<>(); |
| | | map.put("list", roleList); |
| | |
| | | return ResponseValue.success(1); |
| | | } |
| | | |
| | | private Set<String> picFormatArr = new HashSet<String>() { |
| | | private final Set<String> picFormatArr = new HashSet<String>() { |
| | | { |
| | | add(".pjp"); |
| | | add(".svgz"); |