| | |
| | | |
| | | import com.ruoyi.common.basic.PageDTO; |
| | | import com.ruoyi.common.core.domain.R; |
| | | import com.ruoyi.common.exception.GlobalException; |
| | | import com.ruoyi.common.exception.ServiceException; |
| | | import com.ruoyi.common.utils.BeanUtils; |
| | | import com.ruoyi.common.utils.ExcelUtil; |
| | | import com.ruoyi.common.utils.bean.BeanUtils; |
| | | import com.ruoyi.system.domain.TbDept; |
| | | import com.ruoyi.system.dto.update.DeptFocusDTO; |
| | | import com.ruoyi.system.dto.update.DeptUpdateDTO; |
| | |
| | | ExcelUtil.exportExcel(list, "部门导入模板", "部门导入模板", TbDept.class, "部门导入模板", response); |
| | | } catch (Exception e) { |
| | | log.error("模板下载异常",e); |
| | | throw new GlobalException("模板下载失败,请联系管理员!"); |
| | | throw new ServiceException("模板下载失败,请联系管理员!"); |
| | | } |
| | | } |
| | | |
| | |
| | | */ |
| | | @PostMapping("/import") |
| | | @ApiOperation("导入") |
| | | public R<Object> importExcel(@RequestPart("file")MultipartFile file) { |
| | | public R<Void> importExcel(@RequestPart("file")MultipartFile file) { |
| | | try { |
| | | tbDeptService.importExcel(file); |
| | | } catch (Exception e) { |
| | | if (e instanceof ServiceException) { |
| | | return R.fail(e.getMessage()); |
| | | } |
| | | log.error("导入失败", e); |
| | | throw new RuntimeException(e.getMessage()); |
| | | } |
| | |
| | | @PostMapping("/page") |
| | | @ApiOperation("分页条件查询") |
| | | public R<PageDTO<DeptVO>> page(@RequestBody DeptQuery query) { |
| | | return R.ok(tbDeptService.queryPage(query)); |
| | | try { |
| | | return R.ok(tbDeptService.queryPage(query)); |
| | | } catch (Exception e) { |
| | | if (e instanceof ServiceException) { |
| | | return R.fail(e.getMessage()); |
| | | } |
| | | log.error("分页条件查询异常", e); |
| | | return R.fail(); |
| | | } |
| | | } |
| | | |
| | | /** |
| | |
| | | * @param id 部门id |
| | | * @return DeptVO |
| | | */ |
| | | @GetMapping("/getById") |
| | | @GetMapping("/get-details") |
| | | @ApiOperation("根据id查询部门详情") |
| | | public R<DeptVO> getById(@RequestParam Integer id) { |
| | | TbDept dept = tbDeptService.getById(id); |
| | | DeptVO deptVO = new DeptVO(); |
| | | BeanUtils.copyBeanProp(deptVO, dept); |
| | | return R.ok(deptVO); |
| | | public R<DeptVO> getDetails(@RequestParam Integer id) { |
| | | try { |
| | | TbDept dept = tbDeptService.getById(id); |
| | | return R.ok(BeanUtils.copyBean(dept,DeptVO.class)); |
| | | } catch (Exception e) { |
| | | if (e instanceof ServiceException) { |
| | | return R.fail(e.getMessage()); |
| | | } |
| | | log.error("根据id查询部门详情异常", e); |
| | | return R.fail(); |
| | | } |
| | | } |
| | | |
| | | /** |
| | |
| | | @PostMapping("/edit") |
| | | @ApiOperation("编辑") |
| | | public R<Object> edit(@RequestBody DeptUpdateDTO dto){ |
| | | TbDept tbDept = new TbDept(); |
| | | BeanUtils.copyBeanProp(tbDept,dto); |
| | | tbDeptService.updateById(tbDept); |
| | | try { |
| | | TbDept tbDept = BeanUtils.copyBean(dto, TbDept.class); |
| | | tbDeptService.updateById(tbDept); |
| | | } catch (Exception e) { |
| | | if (e instanceof ServiceException) { |
| | | return R.fail(e.getMessage()); |
| | | } |
| | | log.error("编辑异常", e); |
| | | return R.fail(); |
| | | } |
| | | return R.ok(); |
| | | } |
| | | |
| | |
| | | @PostMapping("/focus") |
| | | @ApiOperation("重点关注") |
| | | public R<Object> focus(@RequestBody DeptFocusDTO dto){ |
| | | TbDept tbDept = new TbDept(); |
| | | BeanUtils.copyBeanProp(tbDept,dto); |
| | | tbDeptService.lambdaUpdate() |
| | | .eq(TbDept::getId, dto.getId()) |
| | | .set(TbDept::getFocussed, dto.getFocussed()) |
| | | .update(); |
| | | tbDeptService.focus(dto); |
| | | return R.ok(); |
| | | } |
| | | } |