|  |  |  | 
|---|
|  |  |  | package com.panzhihua.service_dangjian.service.impl; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; | 
|---|
|  |  |  | import com.baomidou.mybatisplus.core.mapper.BaseMapper; | 
|---|
|  |  |  | 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; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | import org.springframework.beans.BeanUtils; | 
|---|
|  |  |  | import org.springframework.stereotype.Service; | 
|---|
|  |  |  | import org.springframework.util.CollectionUtils; | 
|---|
|  |  |  | import org.springframework.util.ObjectUtils; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | import javax.annotation.Resource; | 
|---|
|  |  |  | 
|---|
|  |  |  | 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)); | 
|---|
|  |  |  | 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(); | 
|---|
|  |  |  | partyOrganizationVO.setId(comPbOrgDO.getId()); | 
|---|
|  |  |  | partyOrganizationVO.setName(comPbOrgDO.getName()); | 
|---|
|  |  |  | partyOrganizationVO.setStatus(comPbOrgDO.getStatus()); | 
|---|
|  |  |  | partyOrganizationVOS.add(partyOrganizationVO); | 
|---|
|  |  |  | }); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | return partyOrganizationVOS; | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | * 社区所有党组织列表 | 
|---|
|  |  |  | * | 
|---|
|  |  |  | * @return 党组织集合 | 
|---|
|  |  |  | */ | 
|---|
|  |  |  | @Override | 
|---|
|  |  |  | public List<PartyOrganizationVO> listPartyOrganizationAll(Long communityId) { | 
|---|
|  |  |  | List<PartyOrganizationVO> partyOrganizationVOS = new ArrayList<>(); | 
|---|
|  |  |  | List<ComPbOrgDO> comPbOrgDOS = comPbOrgDAO | 
|---|
|  |  |  | .selectList(new QueryWrapper<ComPbOrgDO>().lambda().eq(ComPbOrgDO::getCommunityId, communityId)); | 
|---|
|  |  |  | if (!ObjectUtils.isEmpty(comPbOrgDOS)) { | 
|---|
|  |  |  | comPbOrgDOS.forEach(comPbOrgDO -> { | 
|---|
|  |  |  | PartyOrganizationVO partyOrganizationVO = new PartyOrganizationVO(); | 
|---|
|  |  |  | List<ComPbMemberDO> comPbMemberDOs = comPbMemberDAO.selectList( | 
|---|
|  |  |  | new QueryWrapper<ComPbMemberDO>().lambda().eq(ComPbMemberDO::getOrgId, comPbOrgDO.getId())); | 
|---|
|  |  |  | partyOrganizationVO.setId(comPbOrgDO.getId()); | 
|---|
|  |  |  | partyOrganizationVO.setName(comPbOrgDO.getName()); | 
|---|
|  |  |  | partyOrganizationVO.setStatus(comPbOrgDO.getStatus()); | 
|---|
|  |  |  | partyOrganizationVO.setCountPerson(comPbMemberDOs.size()); | 
|---|
|  |  |  | partyOrganizationVOS.add(partyOrganizationVO); | 
|---|
|  |  |  | }); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | return partyOrganizationVOS; | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | * 新增党支部 | 
|---|
|  |  |  | * | 
|---|
|  |  |  | * @param partyOrganizationVO 党支部基本信息 | 
|---|
|  |  |  | * @return 新增结果 | 
|---|
|  |  |  | */ | 
|---|
|  |  |  | @Override | 
|---|
|  |  |  | public R addPartyOrganization(PartyOrganizationVO partyOrganizationVO) { | 
|---|
|  |  |  | ComPbOrgDO comPbOrgDO = new ComPbOrgDO(); | 
|---|
|  |  |  | BeanUtils.copyProperties(partyOrganizationVO, comPbOrgDO); | 
|---|
|  |  |  | comPbOrgDO.setLevel(1); | 
|---|
|  |  |  | comPbOrgDO.setParentId(0L); | 
|---|
|  |  |  | int insert = comPbOrgDAO.insert(comPbOrgDO); | 
|---|
|  |  |  | if (insert > 0) { | 
|---|
|  |  |  | 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(1); | 
|---|
|  |  |  | comPbOrgDO.setParentId(0L); | 
|---|
|  |  |  | int insert = comPbOrgDAO.updateById(comPbOrgDO); | 
|---|
|  |  |  | if (insert > 0) { | 
|---|
|  |  |  | 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) { | 
|---|
|  |  |  | List<ComPbMemberDO> comPbMemberDOs = comPbMemberDAO.selectList( | 
|---|
|  |  |  | new QueryWrapper<ComPbMemberDO>().lambda().eq(ComPbMemberDO::getOrgId, partyOrganizationVO.getId())); | 
|---|
|  |  |  | if (!CollectionUtils.isEmpty(comPbMemberDOs) && comPbMemberDOs.size() > 0) { | 
|---|
|  |  |  | return R.fail("该党组织下已有党员,不能删除!"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | int insert = comPbOrgDAO.deleteById(partyOrganizationVO.getId()); | 
|---|
|  |  |  | if (insert > 0) { | 
|---|
|  |  |  | return R.ok(); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | return R.fail(); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|