puzhibing
2026-09-22 372107864f52452727ea34125132a33c3f096612
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
package com.ruoyi.other.controller;
 
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.Logical;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import com.ruoyi.other.api.domain.TGroup;
import com.ruoyi.other.api.domain.TGroupCompany;
import com.ruoyi.other.service.TGroupCompanyService;
import com.ruoyi.other.service.TGroupService;
import com.ruoyi.other.vo.GroupTreeVo;
import io.swagger.annotations.ApiOperation;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
 
import javax.annotation.Resource;
import java.util.List;
 
/**
 * <p>
 * 集团管理 前端控制器
 * </p>
 *
 * @author mxcd
 * @since 2026-09-22
 */
@RestController
@RequestMapping("/group")
public class TGroupController {
 
    @Resource
    private TGroupService groupService;
 
    @Resource
    private TGroupCompanyService groupCompanyService;
 
    /**
     * 获取组织树(第一层集团,第二层企业)
     */
    @RequiresPermissions(value = {"/companyManagement/list"}, logical = Logical.OR)
    @GetMapping("/tree")
    @ApiOperation(value = "获取组织树", tags = {"管理后台-公司管理"})
    public AjaxResult<List<GroupTreeVo>> tree() {
        return AjaxResult.success(groupService.groupTree());
    }
 
    /**
     * 添加集团
     */
    @RequiresPermissions(value = {"/companyManagement/list"}, logical = Logical.OR)
    @PostMapping("/add")
    @ApiOperation(value = "添加集团", tags = {"管理后台-公司管理"})
    @Log(title = "【公司管理】添加集团", businessType = BusinessType.INSERT)
    public AjaxResult add(@RequestBody TGroup group) {
        if (!StringUtils.hasText(group.getGroupName())) {
            return AjaxResult.error("集团名称不能为空");
        }
        String groupName = group.getGroupName().trim();
        long count = groupService.lambdaQuery().eq(TGroup::getGroupName, groupName).count();
        if (count > 0) {
            return AjaxResult.error("集团名称已存在");
        }
        group.setId(null);
        group.setGroupName(groupName);
        group.setDelFlag(false);
        groupService.save(group);
        return AjaxResult.success();
    }
 
    /**
     * 编辑集团
     */
    @RequiresPermissions(value = {"/companyManagement/list"}, logical = Logical.OR)
    @PostMapping("/edit")
    @ApiOperation(value = "编辑集团", tags = {"管理后台-公司管理"})
    @Log(title = "【公司管理】编辑集团", businessType = BusinessType.UPDATE)
    public AjaxResult edit(@RequestBody TGroup group) {
        if (group.getId() == null) {
            return AjaxResult.error("集团ID不能为空");
        }
        if (!StringUtils.hasText(group.getGroupName())) {
            return AjaxResult.error("集团名称不能为空");
        }
        String groupName = group.getGroupName().trim();
        long count = groupService.lambdaQuery()
                .eq(TGroup::getGroupName, groupName)
                .ne(TGroup::getId, group.getId())
                .count();
        if (count > 0) {
            return AjaxResult.error("集团名称已存在");
        }
        TGroup update = new TGroup();
        update.setId(group.getId());
        update.setGroupName(groupName);
        groupService.updateById(update);
        return AjaxResult.success();
    }
 
    /**
     * 删除集团(集团下存在企业时禁止删除)
     */
    @RequiresPermissions(value = {"/companyManagement/list"}, logical = Logical.OR)
    @DeleteMapping("/del")
    @ApiOperation(value = "删除集团", tags = {"管理后台-公司管理"})
    @Log(title = "【公司管理】删除集团", businessType = BusinessType.DELETE)
    public AjaxResult del(@RequestParam("id") Integer id) {
        if (id == null) {
            return AjaxResult.error("集团ID不能为空");
        }
        long companyCount = groupCompanyService.lambdaQuery().eq(TGroupCompany::getGroupId, id).count();
        if (companyCount > 0) {
            return AjaxResult.error("该集团下存在企业,无法删除");
        }
        groupService.removeById(id);
        return AjaxResult.success();
    }
 
}