huanghongfa
2022-02-21 1881fc5bfab642856064f72acfefd51a623da194
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
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
package com.panzhihua.service_dangjian.service.impl;
 
import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;
 
import javax.annotation.Resource;
 
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;
import org.springframework.util.ObjectUtils;
import org.springframework.util.StringUtils;
 
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.panzhihua.common.model.dtos.partybuilding.ComListPartyDTO;
import com.panzhihua.common.model.vos.R;
import com.panzhihua.common.model.vos.partybuilding.PartyOrganizationVO;
import com.panzhihua.service_dangjian.dao.ComPbMemberDAO;
import com.panzhihua.service_dangjian.dao.ComPbOrgDAO;
import com.panzhihua.service_dangjian.model.dos.ComPbMemberDO;
import com.panzhihua.service_dangjian.model.dos.ComPbOrgDO;
import com.panzhihua.service_dangjian.service.PartyOrganizationService;
 
/**
 * @program: springcloud_k8s_panzhihuazhihuishequ
 * @description: 党组织
 * @author: huang.hongfa weixin hhf9596 qq 959656820
 * @create: 2020-11-30 11:40
 **/
@Service
public class PartyOrganizationServiceImpl implements PartyOrganizationService {
    @Resource
    private ComPbOrgDAO comPbOrgDAO;
    @Resource
    private ComPbMemberDAO comPbMemberDAO;
 
    /**
     * 社区所有启用的党组织列表
     *
     * @return 党组织集合
     */
    @Override
    public List<PartyOrganizationVO> listPartyOrganization(Long communityId) {
        List<PartyOrganizationVO> partyOrganizationVOS = new ArrayList<>();
        List<ComPbOrgDO> comPbOrgDOS = comPbOrgDAO.selectList(new QueryWrapper<ComPbOrgDO>().lambda()
            .eq(ComPbOrgDO::getCommunityId, communityId).eq(ComPbOrgDO::getStatus, 1));
        if (!ObjectUtils.isEmpty(comPbOrgDOS)) {
            comPbOrgDOS.forEach(comPbOrgDO -> {
                PartyOrganizationVO partyOrganizationVO = new PartyOrganizationVO();
                BeanUtils.copyProperties(comPbOrgDO,partyOrganizationVO);
                partyOrganizationVOS.add(partyOrganizationVO);
            });
        }
        return partyOrganizationVOS;
    }
 
    /**
     * 社区所有党组织列表
     *
     * @return 党组织集合
     */
    @Override
    public R listPartyOrganizationAll(PartyOrganizationVO partyOrganizationVO) {
        IPage<PartyOrganizationVO> orgPage = this.comPbOrgDAO.listPartyOrganizationAll(
            new Page(partyOrganizationVO.getPageNum(), partyOrganizationVO.getPageSize()), partyOrganizationVO);
        if (!ObjectUtils.isEmpty(orgPage.getRecords()) && StringUtils.isEmpty(partyOrganizationVO.getKeyWord())) {
            //遍历第一级党组织列表
            orgPage.getRecords().forEach(org -> {
                partyOrganizationVO.setParentId(org.getId());
                List<PartyOrganizationVO> twoChildList = comPbOrgDAO.getChildOrgList(partyOrganizationVO);
                if(!ObjectUtils.isEmpty(twoChildList)){
                    //遍历第二级党组织列表
                    twoChildList.forEach(twoChild -> {
                        partyOrganizationVO.setParentId(twoChild.getId());
                        List<PartyOrganizationVO> thirdChildList = comPbOrgDAO.getChildOrgList(partyOrganizationVO);
                        if(!ObjectUtils.isEmpty(thirdChildList)){
                            //遍历第三级党组织列表
                            thirdChildList.forEach(thirdChild -> {
                                partyOrganizationVO.setParentId(thirdChild.getId());
                                List<PartyOrganizationVO> fourChildList = comPbOrgDAO.getChildOrgList(partyOrganizationVO);
                                if(!ObjectUtils.isEmpty(fourChildList)){
                                    fourChildList.forEach(fourChild -> {
                                        partyOrganizationVO.setParentId(fourChild.getId());
                                        List<PartyOrganizationVO> fiveChildList = comPbOrgDAO.getChildOrgList(partyOrganizationVO);
                                        fourChild.setCountPerson(fourChild.getCountPerson() + fiveChildList.stream().mapToInt(five -> five.getCountPerson()).sum());
                                        fourChild.setChildList(fiveChildList);
                                    });
                                }
                                thirdChild.setCountPerson(thirdChild.getCountPerson() + fourChildList.stream().mapToInt(four -> four.getCountPerson()).sum());
                                thirdChild.setChildList(fourChildList);
                            });
                        }
                        twoChild.setCountPerson(twoChild.getCountPerson() + thirdChildList.stream().mapToInt(third -> third.getCountPerson()).sum());
                        twoChild.setChildList(thirdChildList);
                    });
                }
                org.setCountPerson(org.getCountPerson() + twoChildList.stream().mapToInt(two -> two.getCountPerson()).sum());
                org.setChildList(twoChildList);
            });
        }
        return R.ok(orgPage);
    }
 
    /**
     * 新增党支部
     *
     * @param partyOrganizationVO
     *            党支部基本信息
     * @return 新增结果
     */
    @Override
    public R addPartyOrganization(PartyOrganizationVO partyOrganizationVO) {
        ComPbOrgDO comPbOrgDO = new ComPbOrgDO();
        BeanUtils.copyProperties(partyOrganizationVO, comPbOrgDO);
        comPbOrgDO.setLevel(partyOrganizationVO.getType());
        ComPbOrgDO oldComPbOrgDO = null;
        int insert = comPbOrgDAO.insert(comPbOrgDO);
        if (insert > 0) {
            switch (partyOrganizationVO.getType()){
                case ComPbOrgDO.Type.JCDW:
                    comPbOrgDO.setParentId(0L);
                    comPbOrgDO.setOneId(comPbOrgDO.getId());
                    break;
                case ComPbOrgDO.Type.EJJCDW:
                    comPbOrgDO.setOneId(partyOrganizationVO.getParentId());
                    comPbOrgDO.setTwoId(comPbOrgDO.getId());
                    break;
                case ComPbOrgDO.Type.DZZ:
                    oldComPbOrgDO = this.comPbOrgDAO.selectById(partyOrganizationVO.getParentId());
                    if(oldComPbOrgDO != null){
                        comPbOrgDO.setOneId(oldComPbOrgDO.getOneId());
                        comPbOrgDO.setTwoId(oldComPbOrgDO.getTwoId());
                    }
                    comPbOrgDO.setThirdId(comPbOrgDO.getId());
                    break;
                case ComPbOrgDO.Type.DZB:
                    oldComPbOrgDO = this.comPbOrgDAO.selectById(partyOrganizationVO.getParentId());
                    if(oldComPbOrgDO != null){
                        comPbOrgDO.setOneId(oldComPbOrgDO.getOneId());
                        comPbOrgDO.setTwoId(oldComPbOrgDO.getTwoId());
                        comPbOrgDO.setThirdId(oldComPbOrgDO.getThirdId());
                    }
                    comPbOrgDO.setFourId(comPbOrgDO.getId());
                    break;
                case ComPbOrgDO.Type.DXZ:
                    oldComPbOrgDO = this.comPbOrgDAO.selectById(partyOrganizationVO.getParentId());
                    if(oldComPbOrgDO != null){
                        comPbOrgDO.setOneId(oldComPbOrgDO.getOneId());
                        comPbOrgDO.setTwoId(oldComPbOrgDO.getTwoId());
                        comPbOrgDO.setThirdId(oldComPbOrgDO.getThirdId());
                        comPbOrgDO.setFourId(oldComPbOrgDO.getFourId());
                    }
                    comPbOrgDO.setFiveId(comPbOrgDO.getId());
                    break;
                default:
                    break;
            }
            this.comPbOrgDAO.updateById(comPbOrgDO);
            return R.ok();
        }
        return R.fail();
    }
 
    /**
     * 编辑党支部
     *
     * @param partyOrganizationVO
     *            党支部基本信息
     * @return 编辑结果
     */
    @Override
    public R updatePartyOrganization(PartyOrganizationVO partyOrganizationVO) {
        ComPbOrgDO comPbOrgDO = new ComPbOrgDO();
        BeanUtils.copyProperties(partyOrganizationVO, comPbOrgDO);
        comPbOrgDO.setLevel(partyOrganizationVO.getType());
        ComPbOrgDO oldComPbOrgDO = null;
        int insert = comPbOrgDAO.updateById(comPbOrgDO);
        if (insert > 0) {
            switch (partyOrganizationVO.getType()){
                case ComPbOrgDO.Type.JCDW:
                    comPbOrgDO.setParentId(0L);
                    comPbOrgDO.setOneId(comPbOrgDO.getId());
                    break;
                case ComPbOrgDO.Type.EJJCDW:
                    comPbOrgDO.setOneId(partyOrganizationVO.getParentId());
                    comPbOrgDO.setTwoId(comPbOrgDO.getId());
                    break;
                case ComPbOrgDO.Type.DZZ:
                    oldComPbOrgDO = this.comPbOrgDAO.selectById(partyOrganizationVO.getParentId());
                    if(oldComPbOrgDO != null){
                        comPbOrgDO.setOneId(oldComPbOrgDO.getOneId());
                        comPbOrgDO.setTwoId(oldComPbOrgDO.getTwoId());
                    }
                    comPbOrgDO.setThirdId(comPbOrgDO.getId());
                    break;
                case ComPbOrgDO.Type.DZB:
                    oldComPbOrgDO = this.comPbOrgDAO.selectById(partyOrganizationVO.getParentId());
                    if(oldComPbOrgDO != null){
                        comPbOrgDO.setOneId(oldComPbOrgDO.getOneId());
                        comPbOrgDO.setTwoId(oldComPbOrgDO.getTwoId());
                        comPbOrgDO.setThirdId(oldComPbOrgDO.getThirdId());
                    }
                    comPbOrgDO.setFourId(comPbOrgDO.getId());
                    break;
                case ComPbOrgDO.Type.DXZ:
                    oldComPbOrgDO = this.comPbOrgDAO.selectById(partyOrganizationVO.getParentId());
                    if(oldComPbOrgDO != null){
                        comPbOrgDO.setOneId(oldComPbOrgDO.getOneId());
                        comPbOrgDO.setTwoId(oldComPbOrgDO.getTwoId());
                        comPbOrgDO.setThirdId(oldComPbOrgDO.getThirdId());
                        comPbOrgDO.setFourId(oldComPbOrgDO.getFourId());
                    }
                    comPbOrgDO.setFiveId(comPbOrgDO.getId());
                    break;
                default:
                    break;
            }
            return R.ok();
        }
        return R.fail();
    }
 
    /**
     * 启用,禁用党支部
     *
     * @param partyOrganizationVO
     *            党支部基本信息
     * @return 编辑结果
     */
    @Override
    public R resetPartyOrganization(PartyOrganizationVO partyOrganizationVO) {
        ComPbOrgDO comPbOrgDO = comPbOrgDAO.selectById(partyOrganizationVO.getId());
        if (ObjectUtils.isEmpty(comPbOrgDO)) {
            return R.fail("没有此党支部");
        }
        comPbOrgDO.setStatus(partyOrganizationVO.getStatus());
        int insert = comPbOrgDAO.updateById(comPbOrgDO);
        if (insert > 0) {
            return R.ok();
        }
        return R.fail();
    }
 
    /**
     * 删除党支部
     *
     * @param partyOrganizationVO
     *            党支部基本信息
     * @return 编辑结果
     */
    @Override
    public R deletePartyOrganization(PartyOrganizationVO partyOrganizationVO) {
        Integer count = comPbOrgDAO.selectCount(new QueryWrapper<ComPbOrgDO>().lambda().eq(ComPbOrgDO::getParentId,partyOrganizationVO.getId()));
        if(count > 0){
            return R.fail("该组织下已有子组织,不能删除!");
        }
        List<ComPbMemberDO> comPbMemberList = comPbMemberDAO.selectList(
            new QueryWrapper<ComPbMemberDO>().lambda().eq(ComPbMemberDO::getOrgId, partyOrganizationVO.getId()));
        if (!CollectionUtils.isEmpty(comPbMemberList) && comPbMemberList.size() > 0) {
            return R.fail("该党组织下已有党员,不能删除!");
        }
        int insert = comPbOrgDAO.deleteById(partyOrganizationVO.getId());
        if (insert > 0) {
            return R.ok();
        }
        return R.fail();
    }
 
    @Override
    public List<PartyOrganizationVO> listPartyOrganizationByApp(ComListPartyDTO comListPartyDTO) {
        List<PartyOrganizationVO> partyOrganizationVOS = new ArrayList<>();
        QueryWrapper<ComPbOrgDO> queryWrapper = new QueryWrapper<>();
        queryWrapper.lambda().eq(ComPbOrgDO::getStatus, 1);
        if (comListPartyDTO.getCommunityId() != null) {
            queryWrapper.lambda().eq(ComPbOrgDO::getCommunityId, comListPartyDTO.getCommunityId());
        }
        if (!StringUtils.isEmpty(comListPartyDTO.getName())) {
            queryWrapper.lambda().like(ComPbOrgDO::getName, comListPartyDTO.getName());
        }
        List<ComPbOrgDO> comPbOrgDOS = comPbOrgDAO.selectList(queryWrapper);
        if (!ObjectUtils.isEmpty(comPbOrgDOS)) {
            comPbOrgDOS.forEach(comPbOrgDO -> {
                PartyOrganizationVO partyOrganizationVO = new PartyOrganizationVO();
                partyOrganizationVO.setId(comPbOrgDO.getId());
                partyOrganizationVO.setName(comPbOrgDO.getName());
                partyOrganizationVO.setStatus(comPbOrgDO.getStatus());
                partyOrganizationVOS.add(partyOrganizationVO);
            });
        }
        return partyOrganizationVOS;
    }
 
    /**
     * 查询所有党组织列表
     * @param partyOrganizationVO   请求参数
     * @return  党组织列表
     */
    @Override
    public R getPbOrgAllList(PartyOrganizationVO partyOrganizationVO){
        List<PartyOrganizationVO> orgList = this.comPbOrgDAO.getPbOrgAllList(partyOrganizationVO);
        if (!ObjectUtils.isEmpty(orgList) && StringUtils.isEmpty(partyOrganizationVO.getKeyWord())) {
            //遍历第一级党组织列表
            orgList.forEach(org -> {
                partyOrganizationVO.setParentId(org.getId());
                List<PartyOrganizationVO> twoChildList = comPbOrgDAO.getChildOrgList(partyOrganizationVO);
                if(!ObjectUtils.isEmpty(twoChildList)){
                    //遍历第二级党组织列表
                    twoChildList.forEach(twoChild -> {
                        partyOrganizationVO.setParentId(twoChild.getId());
                        List<PartyOrganizationVO> thirdChildList = comPbOrgDAO.getChildOrgList(partyOrganizationVO);
                        if(!ObjectUtils.isEmpty(thirdChildList)){
                            //遍历第三级党组织列表
                            thirdChildList.forEach(thirdChild -> {
                                partyOrganizationVO.setParentId(thirdChild.getId());
                                List<PartyOrganizationVO> fourChildList = comPbOrgDAO.getChildOrgList(partyOrganizationVO);
                                if(!ObjectUtils.isEmpty(fourChildList)){
                                    fourChildList.forEach(fourChild -> {
                                        partyOrganizationVO.setParentId(fourChild.getId());
                                        List<PartyOrganizationVO> fiveChildList = comPbOrgDAO.getChildOrgList(partyOrganizationVO);
                                        fourChild.setCountPerson(fourChild.getCountPerson() + fiveChildList.stream().mapToInt(five -> five.getCountPerson()).sum());
                                        fourChild.setChildList(fiveChildList);
                                    });
                                }
                                thirdChild.setCountPerson(thirdChild.getCountPerson() + fourChildList.stream().mapToInt(four -> four.getCountPerson()).sum());
                                thirdChild.setChildList(fourChildList);
                            });
                        }
                        twoChild.setCountPerson(twoChild.getCountPerson() + thirdChildList.stream().mapToInt(third -> third.getCountPerson()).sum());
                        twoChild.setChildList(thirdChildList);
                    });
                }
                org.setCountPerson(org.getCountPerson() + twoChildList.stream().mapToInt(two -> two.getCountPerson()).sum());
                org.setChildList(twoChildList);
            });
        }
        return R.ok(orgList);
    }
}