| | |
| | | package com.ruoyi.web.controller.api; |
| | | |
| | | |
| | | import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
| | | import com.ruoyi.common.annotation.Log; |
| | | import com.ruoyi.common.basic.PageInfo; |
| | | import com.ruoyi.common.core.domain.R; |
| | | import com.ruoyi.common.enums.BusinessType; |
| | | import com.ruoyi.common.utils.bean.BeanUtils; |
| | | import com.ruoyi.system.dto.ProjectDeptDTO; |
| | | import com.ruoyi.system.model.TProjectDept; |
| | | import com.ruoyi.system.query.DeptListQuery; |
| | | import com.ruoyi.system.service.TProjectDeptService; |
| | | import com.ruoyi.system.vo.system.ProjectDeptListNoLimitVO; |
| | | import com.ruoyi.system.vo.system.ProjectDeptListVO; |
| | | import io.swagger.annotations.Api; |
| | | import org.springframework.web.bind.annotation.RequestMapping; |
| | | import org.springframework.web.bind.annotation.RestController; |
| | | import io.swagger.annotations.ApiOperation; |
| | | import org.springframework.util.StringUtils; |
| | | import org.springframework.web.bind.annotation.*; |
| | | |
| | | import javax.annotation.Resource; |
| | | import java.util.ArrayList; |
| | | import java.util.Arrays; |
| | | import java.util.List; |
| | | |
| | | /** |
| | | * <p> |
| | |
| | | * @author xiaochen |
| | | * @since 2025-05-28 |
| | | */ |
| | | @Api(tags = "项目部") |
| | | @Api(tags = "项目部管理") |
| | | @RestController |
| | | @RequestMapping("/t-project-dept") |
| | | public class TProjectDeptController { |
| | | @Resource |
| | | private TProjectDeptService deptService; |
| | | |
| | | |
| | | @ApiOperation(value = "项目部分页列表") |
| | | @PostMapping(value = "/pageList") |
| | | public R<PageInfo<ProjectDeptListVO>> pageList(@RequestBody DeptListQuery query) { |
| | | return R.ok(deptService.pageList(query)); |
| | | } |
| | | @ApiOperation(value = "选择项目部/片区不分页列表") |
| | | @PostMapping(value = "/list") |
| | | public R<List<ProjectDeptListNoLimitVO>> list() { |
| | | List<TProjectDept> list = deptService.list(new LambdaQueryWrapper<TProjectDept>() |
| | | .eq(TProjectDept::getParentId, "0") |
| | | .eq(TProjectDept::getStatus, 1)); |
| | | List<ProjectDeptListNoLimitVO> projectDeptListNoLimitVOS = new ArrayList<>(); |
| | | for (TProjectDept tProjectDept : list) { |
| | | ProjectDeptListNoLimitVO projectDeptListNoLimitVO = new ProjectDeptListNoLimitVO(); |
| | | BeanUtils.copyProperties(tProjectDept,projectDeptListNoLimitVO); |
| | | List<TProjectDept> list1 = deptService.list(new LambdaQueryWrapper<TProjectDept>() |
| | | .eq(TProjectDept::getParentId, tProjectDept.getId()) |
| | | .eq(TProjectDept::getStatus, 1)); |
| | | List<ProjectDeptListNoLimitVO> projectDeptListNoLimitVOS1 = new ArrayList<>(); |
| | | for (TProjectDept projectDept : list1) { |
| | | ProjectDeptListNoLimitVO projectDeptListNoLimitVO1 = new ProjectDeptListNoLimitVO(); |
| | | BeanUtils.copyProperties(projectDept,projectDeptListNoLimitVO1); |
| | | projectDeptListNoLimitVOS1.add(projectDeptListNoLimitVO1); |
| | | } |
| | | projectDeptListNoLimitVO.setChildren(projectDeptListNoLimitVOS1); |
| | | projectDeptListNoLimitVOS.add(projectDeptListNoLimitVO); |
| | | } |
| | | return R.ok(projectDeptListNoLimitVOS); |
| | | } |
| | | @Log(title = "新增项目部", businessType = BusinessType.INSERT) |
| | | @ApiOperation(value = "新增项目部") |
| | | @PostMapping(value = "/add") |
| | | public R<Boolean> add(@RequestBody ProjectDeptDTO dto) { |
| | | if (!StringUtils.hasLength(dto.getParentId())){ |
| | | dto.setParentId("0"); |
| | | } |
| | | |
| | | deptService.save(dto); |
| | | return R.ok(); |
| | | } |
| | | @Log(title = "编辑项目部", businessType = BusinessType.UPDATE) |
| | | @ApiOperation(value = "编辑项目部") |
| | | @PostMapping(value = "/edit") |
| | | public R<Boolean> edit(@RequestBody ProjectDeptDTO dto) { |
| | | if (!StringUtils.hasLength(dto.getParentId())){ |
| | | dto.setParentId("0"); |
| | | } |
| | | deptService.updateById(dto); |
| | | return R.ok(); |
| | | } |
| | | @Log(title = "批量删除项目部", businessType = BusinessType.DELETE) |
| | | @ApiOperation(value = "批量删除项目部") |
| | | @DeleteMapping(value = "/delete") |
| | | public R<Boolean> edit(@RequestParam String ids) { |
| | | String[] split = ids.split(","); |
| | | deptService.removeBatchByIds(Arrays.asList(split)); |
| | | return R.ok(); |
| | | } |
| | | @Log(title = "启用/禁用项目部", businessType = BusinessType.OTHER) |
| | | @ApiOperation(value = "启用/禁用项目部") |
| | | @GetMapping(value = "/editStatus") |
| | | public R<Boolean> editStatus(@RequestParam String id) { |
| | | TProjectDept byId = deptService.getById(id); |
| | | if (byId.getParentId().equals("0")){ |
| | | // 禁用上级 下级一起禁用 |
| | | List<TProjectDept> list = deptService.lambdaQuery().eq(TProjectDept::getParentId, byId.getId()).list(); |
| | | for (TProjectDept tProjectDept : list) { |
| | | tProjectDept.setStatus(2); |
| | | } |
| | | deptService.updateBatchById(list); |
| | | } |
| | | if (byId.getStatus()==1){ |
| | | byId.setStatus(2); |
| | | }else{ |
| | | byId.setStatus(1); |
| | | } |
| | | deptService.updateById(byId); |
| | | return R.ok(); |
| | | } |
| | | @ApiOperation(value = "详情项目部") |
| | | @GetMapping(value = "/detail") |
| | | public R<TProjectDept> detail(@RequestParam String id) { |
| | | |
| | | return R.ok(deptService.getById(id)); |
| | | } |
| | | } |
| | | |