| | |
| | | orgDepartmentDTO.getOid(),"用户主键", |
| | | orgDepartmentDTO.getId(),"用户名" |
| | | ); |
| | | //按oid查询数据库中已存在的 |
| | | //按oid查询数据库中已存在的,确保修改的部门存在 |
| | | OrgDepartmentVO dbDepartmentVO = getDeptByDeptOid(orgDepartmentDTO.getOid()); |
| | | if(Func.isEmpty(dbDepartmentVO)){ |
| | | throw new VciBaseException("修改的部门不存在!"); |
| | | } |
| | | //部门名和编号判重 |
| | | //部门名和编号判重,避免新家部门重复 |
| | | Map<String, String> conditionMap = new HashMap<>(); |
| | | conditionMap.put("plname",QueryOptionConstant.OR + orgDepartmentDTO.getName()); |
| | | if(Func.isNotBlank(orgDepartmentDTO.getId())){ |
| | |
| | | @Override |
| | | public boolean deleteDept(String[] ids) throws PLException { |
| | | VciBaseUtil.alertNotNull(ids,"要删除的部门主键"); |
| | | //具备连带删除的功能,如角色菜单授权表里面的授权信息 |
| | | //TODO: 应该是不具备连带删除的功能,策略删除后用户关联的无用部门还在,考虑后期是否需要做,数据量不大可以不做连带删除 |
| | | return platformClientUtil.getFrameworkService().deleteDepartment( |
| | | ids, |
| | | new UserEntityInfo("developer"/*WebThreadLocalUtil.getCurrentUserSessionInfoInThread().getUserId()*/, null) |
| | |
| | | List<String> columns = new ArrayList<>(Arrays.asList("ID", "名称", "编号", "代号", "专业", "父ID(部门唯一标识ID)", "描述")); |
| | | //设置必填列 |
| | | ColumnNameisRed.clear(); |
| | | ColumnNameisRed.add(0); |
| | | //ColumnNameisRed.add(0); |
| | | ColumnNameisRed.add(1); |
| | | //写excel |
| | | String excelPath = LocalFileUtil.getDefaultTempFolder() + File.separator + downloadFileName + ".xls"; |
| | |
| | | * @throws VciBaseException |
| | | */ |
| | | @Override |
| | | public BaseResult importDept(File file) throws VciBaseException { |
| | | public BaseResult importDept(File file) throws Exception { |
| | | VciBaseUtil.alertNotNull(file,"excel文件"); |
| | | if(!file.exists()){ |
| | | throw new VciBaseException("导入的excel文件不存在,{0}",new String[]{file.getPath()}); |
| | |
| | | Map<String, String> oidMap = new HashMap<>(); |
| | | poList.stream().forEach(po->{ |
| | | String parentId = Func.isBlank(po.getParentId()) ? "":po.getParentId(); |
| | | //表格内判重 |
| | | //部门名称判空 |
| | | //部门名称判空,通常通过po中的注解就可实现 |
| | | if(Func.isEmpty(po.getName())){ |
| | | throw new VciBaseException("第【"+po.getRowIndex()+"】行,depterror,Reason:Name cannot be empty"); |
| | | }else if(repeatNameMap.getOrDefault(po.getName(), "").equals(parentId)/*excel中同一部门下Name相等*/){ |
| | | }else if(parentId.equals(repeatNameMap.getOrDefault(po.getName(), null))/*excel中同一部门下Name相等*/){ |
| | | //同一部门下名称判重 |
| | | throw new VciBaseException("第【"+po.getRowIndex()+"】行,deptnameerror,Reason: Names under the same department cannot be duplicated"); |
| | | }else if(Func.isNotEmpty(po.getId()) && repeatIdList.equals(po.getId())){ |
| | | throw new VciBaseException("第【"+po.getRowIndex()+"】行,deptiderror,Reason: The primary key cannot be duplicated"); |
| | | }else if(Func.isNotEmpty(po.getNum()) && repeatNumMap.getOrDefault(po.getNum(),"").equals(parentId)/*excel中同一部门下编号存在 */){ |
| | | }else if(Func.isNotEmpty(po.getNum()) && parentId.equals(repeatNumMap.getOrDefault(po.getNum(),null))/*excel中同一部门下编号存在 */){ |
| | | throw new VciBaseException("第【"+po.getRowIndex()+"】行,deptnumerror,Reason: The number cannot be duplicated"); |
| | | }else{ |
| | | //2.2、查询数据库中的数据(查重ID和NUM),比较麻烦需要根据ParentID查询(所有只能单条查询进行判重) |
| | | //组装查重条件:同一部门下(parentId相等),name或者num相等 |
| | | HashMap<String, String> conditionMap = new HashMap<>(); |
| | | conditionMap.put("plname",po.getName()); |
| | | conditionMap.put("plname",QueryOptionConstant.OR + po.getName()); |
| | | conditionMap.put("plnum",QueryOptionConstant.OR + po.getNum()); |
| | | String pId = Func.isBlank(po.getParentId()) ? null:po.getParentId(); |
| | | List<OrgDepartmentVO> repeatOrgDept = this.getDeptByDeptPOidAndCondition(pId, conditionMap); |
| | |
| | | BeanUtil.convert(po,dto); |
| | | dto.setOid(po.getId()); |
| | | dto.setId(po.getNum()); |
| | | dto.setDescription(po.getDesc()); |
| | | dto.setSpecialties(po.getSpecialties()); |
| | | dto.setPkFatherDepartment(po.getParentId()); |
| | | dto.setCreateTime(new Date()); |
| | | dto.setCreator(loginUserId); |
| | |
| | | dto.setStatus((short) 0); |
| | | //2.2、过程中处理主键转换问题最好是一条一条的处理ID是否存在还有ParentID是否存在的问题 |
| | | //先判断是已存在的部门ID,还是不存在的部门ID,已存在系统中的ID就是为Dept:开头的 |
| | | String pId = dto.getPkFatherDepartment(); |
| | | String pId = Func.isBlank(dto.getPkFatherDepartment()) ? "":dto.getPkFatherDepartment(); |
| | | //是已存在系统中的部门id |
| | | if(pId.contains("Dept:")){ |
| | | //解析出真实的oid |
| | |
| | | if(Func.isBlank(deParentId) || Func.isEmpty(this.getDeptByDeptOid(deParentId))){ |
| | | throw new VciBaseException("第【"+ po.getRowIndex() +"】行,deptparentiderror,Reason:Parent ID resolution error or does not exist in the system"); |
| | | } |
| | | //替换掉临时使用的部门唯一标识 |
| | | dto.setPkOrganizationName(deParentId); |
| | | //替换掉临时使用的部门唯一标识,但是为了方便后续判断,还是需要加上Dept:标识 |
| | | dto.setPkFatherDepartment("Dept:"+deParentId); |
| | | } |
| | | //用户手输了部门oid,但是避免oid不规范需要,用规范oid进行替换,如果没输入保存时会自动生成oid |
| | | if(Func.isNotBlank(dto.getOid())){ |
| | | String pkOid = VciBaseUtil.getPk(); |
| | | String excelOid = dto.getOid(); |
| | | if(Func.isNotBlank(excelOid)){ |
| | | String pkOid = VciBaseUtil.getPk().toUpperCase(Locale.ROOT); |
| | | dto.setOid(pkOid); |
| | | //oid映射关系,后续用来更新parentId |
| | | oidMap.put(dto.getOid(),pkOid); |
| | | oidMap.put(excelOid,pkOid); |
| | | } |
| | | DeptInfo deptInfo = this.changeOrgDeptDTOToDeptInfo(dto); |
| | | deptInfoList.add(deptInfo); |
| | | }); |
| | | //3、处理id和parentId的映射关系:将用户手输的父ID转换成实际存储的ID |
| | | List<DeptInfo> lastDeptInfoList = deptInfoList.stream().map(info -> { |
| | | //parentId不为空并且没有Dept:相关的字符串,说明是用户手输的ParentId(导入的数据就是一个树结构) |
| | | if (Func.isNotBlank(info.parentId) || info.parentId.contains("Dept:")) { |
| | | //转换ParentId为实际要存储的部门ID |
| | | info.parentId = oidMap.get(info.parentId); |
| | | //3、处理id和parentId的映射关系:将用户手输的父ID转换成实际存储的ID并保存进库 |
| | | deptInfoList.stream().forEach(info -> { |
| | | //3.1、对最终处理好的部门数据保存 |
| | | try { |
| | | //parentId不为空并且没有Dept:相关的字符串,说明是用户手输的ParentId(导入的数据就是一个树结构) |
| | | if (Func.isNotBlank(info.parentId) && !info.parentId.contains("Dept:")) { |
| | | //转换ParentId为实际要存储的部门ID |
| | | info.parentId = oidMap.get(info.parentId); |
| | | }else if(info.parentId.contains("Dept:")){ |
| | | //系统中已存在的父部门OID,需要移除掉Dept:标识 |
| | | info.parentId = info.parentId.replace("Dept:",""); |
| | | } |
| | | platformClientUtil.getFrameworkService().saveDepartment( |
| | | info, |
| | | userEntityInfo |
| | | ); |
| | | } catch (PLException e) { |
| | | e.printStackTrace(); |
| | | throw new VciBaseException("保存时出现错误!,原因:"+VciBaseUtil.getExceptionMessage(e)); |
| | | } |
| | | return info; |
| | | }).collect(Collectors.toList()); |
| | | //4、对最终处理好的部门数据保存,实现最终统一保存,避免了一部分数据进了一部分数据因为校验没过没进库的问题 |
| | | platformClientUtil.getFrameworkService().batchSaveDepart( |
| | | lastDeptInfoList.toArray(new DeptInfo[lastDeptInfoList.size()]), |
| | | userEntityInfo |
| | | ); |
| | | }); |
| | | }catch (Exception e){ |
| | | if(logger.isErrorEnabled()){ |
| | | logger.error("读取excel内容时或保存用户信息时出现了错误,具体原因:",e.getMessage()); |