wang-hao-jie
2022-08-25 57dcc73636bb7d8dce89c808eb8cc988a7512264
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
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
package com.ruoyi.station.service.impl;
 
import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;
 
import com.ruoyi.common.constant.UserConstants;
import com.ruoyi.common.core.domain.Ztree;
import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.common.utils.IdUtils;
import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.station.domain.MjWorkUser;
import com.ruoyi.system.domain.SysDept;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.station.mapper.MjDeptMapper;
import com.ruoyi.station.domain.MjDept;
import com.ruoyi.station.service.IMjDeptService;
import com.ruoyi.common.core.text.Convert;
 
/**
 * 部门Service业务层处理
 * 
 * @author ruoyi
 * @date 2020-08-07
 */
@Service
public class MjDeptServiceImpl implements IMjDeptService 
{
    @Autowired
    private MjDeptMapper mjDeptMapper;
 
    /**
     * 查询部门
     * 
     * @param id 部门ID
     * @return 部门
     */
    @Override
    public MjDept selectMjDeptById(String id)
    {
 
        MjDept mjDept = mjDeptMapper.selectMjDeptByIdorName(id,null);
        if(mjDept.getDelFlag()==1){
            return null;
        }else {
            return mjDept;
        }
    }
 
    /**
     * 查询部门列表
     * 
     * @param mjDept 部门
     * @return 部门
     */
    @Override
    public List<MjDept> selectMjDeptList(MjDept mjDept)
    {
 
        List<MjDept> mjDepts = mjDeptMapper.selectMjDeptList(mjDept);
        List<MjDept> list = mjDepts.parallelStream()
                .filter(mjDepts1 -> mjDepts1.getDelFlag() == 0)
                .collect(Collectors.toList());
        return list;
    }
 
    /**
     * 新增部门
     * 
     * @param mjDept 部门
     * @return 结果
     */
    @Override
    public int insertMjDept(MjDept mjDept)
    {
        mjDept.setCreateTime(DateUtils.getNowDate());
        mjDept.setUpdateTime(DateUtils.getNowDate());
        mjDept.setId(IdUtils.getUUIDInOrderId()+"");
        if(mjDept.getDelFlag()==null){
            mjDept.setDelFlag(0);
        }
        return mjDeptMapper.insertMjDept(mjDept);
    }
 
    /**
     * 修改部门
     * 
     * @param mjDept 部门
     * @return 结果
     */
    @Override
    public int updateMjDept(MjDept mjDept)
    {
        mjDept.setUpdateTime(DateUtils.getNowDate());
        return mjDeptMapper.updateMjDept(mjDept);
    }
 
    /**
     * 删除部门对象
     * 
     * @param ids 需要删除的数据ID
     * @return 结果
     */
    @Override
    public int deleteMjDeptByIds(String ids)
    {
 
        int count=0;
        String[] strings = Convert.toStrArray(ids);
        for (String string : strings) {
            MjDept mjDept = mjDeptMapper.selectMjDeptByIdorName(string,null);
            mjDept.setDelFlag(1);
            mjDeptMapper.updateMjDept(mjDept);
            count++;
        }
        return count;
    }
 
    /**
     * 删除部门信息
     * 
     * @param id 部门ID
     * @return 结果
     */
    @Override
    public int deleteMjDeptById(String id)
    {
 
        MjDept mjDept = mjDeptMapper.selectMjDeptByIdorName(id,null);
        mjDept.setDelFlag(1);
        return mjDeptMapper.updateMjDept(mjDept);
    }
 
    /**
     * 校验部门名称是否唯一
     *
     * @param dept 部门信息
     * @return 结果
     */
    @Override
    public String checkDeptNameUnique(MjDept dept) {
        String deptId = StringUtils.isNull(dept.getId()) ? "" : dept.getId();
        MjDept info = mjDeptMapper.checkDeptNameUnique(dept.getDeptName(), dept.getDeptParentId());
        if (StringUtils.isNotNull(info) && !info.getId().equals(deptId))
        {
            return UserConstants.DEPT_NAME_NOT_UNIQUE;
        }
        return UserConstants.DEPT_NAME_UNIQUE;
    }
 
    @Override
    public List<Ztree> selectDeptTree(MjDept mjDept) {
        List<MjDept> mjDepts = mjDeptMapper.selectMjDeptList(mjDept);
        List<Ztree> ztrees = initZtree(mjDepts);
        return ztrees;
    }
 
    /**
     * 对象转部门树
     *
     * @param deptList 部门列表
     * @return 树结构列表
     */
    public List<Ztree> initZtree(List<MjDept> deptList)
    {
        return initZtree(deptList, null);
    }
 
    /**
     * 对象转部门树
     *
     * @param deptList 部门列表
     * @param roleDeptList 角色已存在菜单列表
     * @return 树结构列表
     */
    public List<Ztree> initZtree(List<MjDept> deptList, List<String> roleDeptList)
    {
 
        List<Ztree> ztrees = new ArrayList<Ztree>();
        boolean isCheck = StringUtils.isNotNull(roleDeptList);
        for (MjDept dept : deptList)
        {
            if (UserConstants.DEPT_NORMAL.equals(dept.getDelFlag()+""))
            {
                Ztree ztree = new Ztree();
                ztree.setId(Long.parseLong(dept.getId()));
                ztree.setpId(Long.parseLong(dept.getDeptParentId()));
                ztree.setName(dept.getDeptName());
                ztree.setTitle(dept.getDeptName());
                if (isCheck)
                {
                    ztree.setChecked(roleDeptList.contains(dept.getId() + dept.getDeptName()));
                }
                ztrees.add(ztree);
            }
        }
        return ztrees;
    }
 
}