| | |
| | | import com.baomidou.mybatisplus.extension.plugins.pagination.Page; |
| | | import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
| | | import com.ruoyi.common.basic.PageDTO; |
| | | import com.ruoyi.common.exception.ServiceException; |
| | | import com.ruoyi.common.utils.BeanUtils; |
| | | import com.ruoyi.common.utils.CollUtils; |
| | | import com.ruoyi.common.utils.SecurityUtils; |
| | | import com.ruoyi.common.utils.StringUtils; |
| | | import com.ruoyi.system.domain.TbDept; |
| | | import com.ruoyi.system.dto.update.DeptFocusDTO; |
| | | import com.ruoyi.system.handler.DeptVerifyHandler; |
| | | import com.ruoyi.system.importExcel.DeptExcel; |
| | | import com.ruoyi.system.mapper.TbDeptMapper; |
| | | import com.ruoyi.system.query.DeptQuery; |
| | | import com.ruoyi.system.service.TbDeptService; |
| | |
| | | //使用自定义校验规则 |
| | | importParams.setVerifyHandler(deptVerifyHandler); |
| | | InputStream inputStream = file.getInputStream(); |
| | | ExcelImportResult<TbDept> result = ExcelImportUtil.importExcelMore(inputStream, TbDept.class, importParams); |
| | | ExcelImportResult<DeptExcel> result = ExcelImportUtil.importExcelMore(inputStream, DeptExcel.class, importParams); |
| | | inputStream.close(); |
| | | List<TbDept> list = result.getList(); |
| | | if (Objects.requireNonNull(result).isVerfiyFail() || CollectionUtils.isEmpty(list)) { |
| | | throw new RuntimeException("文件校验失败,请检查数据填写是否完整"); |
| | | List<DeptExcel> list = result.getList(); |
| | | |
| | | if (result.isVerifyFail() || CollectionUtils.isEmpty(list)) { |
| | | throw new ServiceException("文件校验失败,请检查数据填写是否完整"); |
| | | } |
| | | List<String> strings = hasDuplicateAreaCode(list); |
| | | if (!CollectionUtils.isEmpty(strings)) { |
| | | throw new RuntimeException(String.format("区划代码%s重复,请修改后重新导入", String.join(",", strings))); |
| | | throw new ServiceException(String.format("区划代码%s重复,请修改后重新导入", String.join(",", strings))); |
| | | }else { |
| | | List<TbDept> tbDeptList = BeanUtils.copyList(list, TbDept.class); |
| | | this.remove(null); |
| | | this.saveBatch(list); |
| | | tbDeptList.forEach(dept->{ |
| | | dept.setPassword(SecurityUtils.encryptPassword(dept.getPassword())); |
| | | }); |
| | | this.saveBatch(tbDeptList); |
| | | } |
| | | } |
| | | |
| | |
| | | * @param deptList 部门列表 |
| | | * @return 重复的区划代码 |
| | | */ |
| | | public List<String> hasDuplicateAreaCode(List<TbDept> deptList) { |
| | | public List<String> hasDuplicateAreaCode(List<DeptExcel> deptList) { |
| | | Set<String> areaCodes = new HashSet<>(); |
| | | List<String> result = new ArrayList<>(); |
| | | for (TbDept dept : deptList) { |
| | | for (DeptExcel dept : deptList) { |
| | | if (!areaCodes.add(dept.getAreaCode())) { |
| | | result.add(dept.getAreaCode()); |
| | | } |
| | | } |
| | | return result; |
| | | } |
| | | |
| | | @Override |
| | | public void focus(DeptFocusDTO dto) { |
| | | TbDept dept = this.getById(dto.getId()); |
| | | if (Objects.isNull(dept)) { |
| | | throw new ServiceException("非法参数"); |
| | | } |
| | | this.lambdaUpdate() |
| | | .eq(TbDept::getId, dto.getId()) |
| | | .set(TbDept::getFocussed, dto.getFocussed()) |
| | | .update(); |
| | | } |
| | | } |