package com.ruoyi.web.controller.api;
|
|
|
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
import com.ruoyi.common.annotation.Log;
|
import com.ruoyi.common.core.domain.R;
|
import com.ruoyi.common.enums.BusinessType;
|
import com.ruoyi.system.model.TLargeDept;
|
import com.ruoyi.system.model.TLargeUser;
|
import com.ruoyi.system.service.TLargeDeptService;
|
import com.ruoyi.system.service.TLargeUserService;
|
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 java.util.List;
|
|
/**
|
* <p>
|
* 大屏-组织部门 前端控制器
|
* </p>
|
*
|
* @author xiaochen
|
* @since 2025-11-11
|
*/
|
@Api(tags = "大屏-组织部门")
|
@RestController
|
@RequestMapping("/t-large-dept")
|
public class TLargeDeptController {
|
|
private final TLargeDeptService largeDeptService;
|
private final TLargeUserService largeUserService;
|
@Autowired
|
public TLargeDeptController(TLargeDeptService largeDeptService, TLargeUserService largeUserService) {
|
this.largeDeptService = largeDeptService;
|
this.largeUserService = largeUserService;
|
}
|
|
/**
|
* 获取组织部门管理列表
|
*/
|
@ApiOperation(value = "获取组织部门列表")
|
@PostMapping(value = "/list")
|
public R<List<TLargeDept>> list() {
|
return R.ok(largeDeptService.list(Wrappers.lambdaQuery(TLargeDept.class).orderByDesc(TLargeDept::getCreateTime)));
|
}
|
|
/**
|
* 添加组织部门管理
|
*/
|
@Log(title = "组织部门信息-新增组织部门", businessType = BusinessType.INSERT)
|
@ApiOperation(value = "添加组织部门")
|
@PostMapping(value = "/add")
|
public R<Boolean> add(@Validated @RequestBody TLargeDept dto) {
|
if (largeDeptService.isExit(dto)) {
|
return R.fail("组织部门已存在");
|
}
|
return R.ok(largeDeptService.save(dto));
|
}
|
|
/**
|
* 修改组织部门
|
*/
|
@Log(title = "组织部门信息-修改组织部门", businessType = BusinessType.UPDATE)
|
@ApiOperation(value = "修改组织部门")
|
@PostMapping(value = "/update")
|
public R<Boolean> update(@Validated @RequestBody TLargeDept dto) {
|
if (largeDeptService.isExit(dto)) {
|
return R.fail("组织部门已存在");
|
}
|
return R.ok(largeDeptService.updateById(dto));
|
}
|
|
/**
|
* 删除组织部门
|
*/
|
@Log(title = "组织部门信息-删除组织部门", businessType = BusinessType.DELETE)
|
@ApiOperation(value = "删除组织部门")
|
@DeleteMapping(value = "/deleteById")
|
public R<Boolean> deleteById(@RequestParam String id) {
|
// 查询是否存在人员
|
long count = largeUserService.count(Wrappers.lambdaQuery(TLargeUser.class)
|
.eq(TLargeUser::getDeptId, id));
|
if (count > 0) {
|
return R.fail("组织部门下存在人员,请先删除人员");
|
}
|
return R.ok(largeDeptService.removeById(id));
|
}
|
|
/**
|
* 批量删除组织部门
|
*/
|
@Log(title = "组织部门信息-删除组织部门", businessType = BusinessType.DELETE)
|
@ApiOperation(value = "批量删除组织部门")
|
@DeleteMapping(value = "/deleteByIds")
|
public R<Boolean> deleteByIds(@RequestBody List<String> ids) {
|
// 查询是否存在人员
|
long count = largeUserService.count(Wrappers.lambdaQuery(TLargeUser.class)
|
.in(TLargeUser::getDeptId, ids));
|
if (count > 0) {
|
return R.fail("组织部门下存在人员,请先删除人员");
|
}
|
return R.ok(largeDeptService.removeByIds(ids));
|
}
|
|
}
|