package com.ycl.controller.depart;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.ycl.api.BasePageDTO;
import com.ycl.api.BasePageVO;
import com.ycl.api.CommonResult;
import com.ycl.controller.BaseController;
import com.ycl.entity.depart.UmsDepart;
import com.ycl.service.depart.UmsDepartService;
import com.ycl.service.user.UmsDepartManageService;
import com.ycl.utils.auth.UserAuthUtil;
import com.ycl.vo.depart.DepartVO;
import com.ycl.vo.depart.UmsDepartVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import java.util.List;
/**
*
* 部门表 前端控制器
*
*
* @author lyq
* @since 2022-09-07
*/
@RestController
@Api(tags = "部门管理模块")
@RequestMapping("/depart")
public class DepartController extends BaseController {
@Autowired
private UmsDepartService departService;
@Resource
private UmsDepartManageService umsAdminDepartService;
@Resource
private UserAuthUtil userAuthUtil;
@ApiOperation("添加部门")
@PostMapping(value = "/create")
public CommonResult create(@Validated @RequestBody DepartVO.AddDepartVO addDepartVO) {
departService.create(addDepartVO);
return CommonResult.success(null);
}
@ApiOperation("编辑部门")
@PostMapping(value = "/update")
public CommonResult create(@Validated @RequestBody DepartVO.UpdateDepartVO params) {
departService.update(params);
return CommonResult.success(null);
}
@ApiOperation("删除")
@PostMapping(value = "/delete")
public CommonResult delete(@Validated @RequestBody DepartVO.IdDepartVO params) {
departService.delete(params.getId());
return CommonResult.success(null);
}
/**
* @return com.ycl.api.CommonResult
* @Description batch deletion departments
* @Param [ids]
**/
@ApiOperation("批处理-删除")
@PostMapping(value = "/batch_deletion")
public CommonResult delete(@RequestParam List ids) {
if (ids.isEmpty()) {
return CommonResult.failed("bad request parameter");
}
return CommonResult.success(departService.removeBatchByIds(ids));
}
@ApiOperation("详情")
@PostMapping(value = "/detail")
public CommonResult detail(@Validated @RequestBody DepartVO.IdDepartVO params) {
UmsDepart sccgDepart = departService.loadDepartById(params.getId());
return CommonResult.success(sccgDepart);
}
@ApiOperation("树结构")
@GetMapping(value = "/tree")
public CommonResult> tree() {
List tree = departService.tree();
return CommonResult.success(tree);
}
@ApiOperation("修改部门状态")
@PostMapping(value = "/status")
public CommonResult status(@Validated @RequestBody DepartVO.StatusDepartVO params) {
departService.updateStatus(params);
return CommonResult.success(null);
}
@ApiOperation("查询全部部门")
@GetMapping(value = "/page")
public CommonResult> page(DepartVO.PageDepartVO params) {
IPage page = departService.pageDepart(params);
return CommonResult.success(page);
}
@ApiOperation("查询我的部门")
@GetMapping(value = "/belongDepart")
public CommonResult belongDepart(BasePageVO params) {
BasePageDTO basePageDTO = umsAdminDepartService.belongDepart(fetchOperator(request).getOperatorId(), params.getCurrent(), params.getPageSize());
return CommonResult.success(basePageDTO);
}
@ApiOperation("查询顶级部门")
@GetMapping(value = "/query_father")
public CommonResult search() {
Integer fatherId = 0;
return CommonResult.success(departService
.list(new LambdaQueryWrapper()
.eq(UmsDepart::getParentId, fatherId)));
}
@ApiOperation("查询部门二级")
@GetMapping(value = "/query_father_children")
public CommonResult search(@RequestParam Integer fatherId) {
return CommonResult.success(departService
.list(new LambdaQueryWrapper()
.eq(UmsDepart::getParentId, fatherId)));
}
}