huanghongfa
2022-02-21 1881fc5bfab642856064f72acfefd51a623da194
springcloud_k8s_panzhihuazhihuishequ/service_partybuilding/src/main/java/com/panzhihua/service_dangjian/service/impl/PartyOrganizationServiceImpl.java
@@ -2,9 +2,11 @@
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;
@@ -49,9 +51,7 @@
        if (!ObjectUtils.isEmpty(comPbOrgDOS)) {
            comPbOrgDOS.forEach(comPbOrgDO -> {
                PartyOrganizationVO partyOrganizationVO = new PartyOrganizationVO();
                partyOrganizationVO.setId(comPbOrgDO.getId());
                partyOrganizationVO.setName(comPbOrgDO.getName());
                partyOrganizationVO.setStatus(comPbOrgDO.getStatus());
                BeanUtils.copyProperties(comPbOrgDO,partyOrganizationVO);
                partyOrganizationVOS.add(partyOrganizationVO);
            });
        }
@@ -65,16 +65,44 @@
     */
    @Override
    public R listPartyOrganizationAll(PartyOrganizationVO partyOrganizationVO) {
        IPage<PartyOrganizationVO> orgPgaeList = this.comPbOrgDAO.listPartyOrganizationAll(
        IPage<PartyOrganizationVO> orgPage = this.comPbOrgDAO.listPartyOrganizationAll(
            new Page(partyOrganizationVO.getPageNum(), partyOrganizationVO.getPageSize()), partyOrganizationVO);
        if (!ObjectUtils.isEmpty(orgPgaeList.getRecords())) {
            orgPgaeList.getRecords().forEach(comPbOrgDO -> {
                List<ComPbMemberDO> comPbMemberDOs = comPbMemberDAO.selectList(
                    new QueryWrapper<ComPbMemberDO>().lambda().eq(ComPbMemberDO::getOrgId, comPbOrgDO.getId()));
                comPbOrgDO.setCountPerson(comPbMemberDOs.size());
        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);
            });
        }
        return R.ok(orgPgaeList);
                                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);
    }
    /**
@@ -88,10 +116,50 @@
    public R addPartyOrganization(PartyOrganizationVO partyOrganizationVO) {
        ComPbOrgDO comPbOrgDO = new ComPbOrgDO();
        BeanUtils.copyProperties(partyOrganizationVO, comPbOrgDO);
        comPbOrgDO.setLevel(1);
        comPbOrgDO.setParentId(0L);
        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();
@@ -108,10 +176,49 @@
    public R updatePartyOrganization(PartyOrganizationVO partyOrganizationVO) {
        ComPbOrgDO comPbOrgDO = new ComPbOrgDO();
        BeanUtils.copyProperties(partyOrganizationVO, comPbOrgDO);
        comPbOrgDO.setLevel(1);
        comPbOrgDO.setParentId(0L);
        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();
@@ -147,9 +254,13 @@
     */
    @Override
    public R deletePartyOrganization(PartyOrganizationVO partyOrganizationVO) {
        List<ComPbMemberDO> comPbMemberDOs = comPbMemberDAO.selectList(
        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(comPbMemberDOs) && comPbMemberDOs.size() > 0) {
        if (!CollectionUtils.isEmpty(comPbMemberList) && comPbMemberList.size() > 0) {
            return R.fail("该党组织下已有党员,不能删除!");
        }
        int insert = comPbOrgDAO.deleteById(partyOrganizationVO.getId());
@@ -159,6 +270,7 @@
        return R.fail();
    }
    @Override
    public List<PartyOrganizationVO> listPartyOrganizationByApp(ComListPartyDTO comListPartyDTO) {
        List<PartyOrganizationVO> partyOrganizationVOS = new ArrayList<>();
        QueryWrapper<ComPbOrgDO> queryWrapper = new QueryWrapper<>();
@@ -181,4 +293,50 @@
        }
        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);
    }
}