|  |  |  | 
|---|
|  |  |  | package com.panzhihua.service_community.service.impl; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | import java.util.ArrayList; | 
|---|
|  |  |  | import java.util.Date; | 
|---|
|  |  |  | import java.util.List; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | import com.panzhihua.common.model.dtos.community.ComMngPopulationHouseUserVO; | 
|---|
|  |  |  | import org.springframework.beans.BeanUtils; | 
|---|
|  |  |  | import org.springframework.stereotype.Service; | 
|---|
|  |  |  | import org.springframework.transaction.annotation.Transactional; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; | 
|---|
|  |  |  | import com.baomidou.mybatisplus.extension.plugins.pagination.Page; | 
|---|
|  |  |  | import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; | 
|---|
|  |  |  | import com.panzhihua.common.model.dtos.grid.AddComMngHousePopulationDTO; | 
|---|
|  |  |  | import com.panzhihua.common.model.dtos.grid.DelComMngHousePopulationDTO; | 
|---|
|  |  |  | import com.panzhihua.common.model.dtos.grid.admin.PageComMngVillagePopulationHouseDTO; | 
|---|
|  |  |  | import com.panzhihua.common.model.vos.R; | 
|---|
|  |  |  | import com.panzhihua.common.utlis.Snowflake; | 
|---|
|  |  |  | import com.panzhihua.service_community.dao.ComMngPopulationHouseUserDAO; | 
|---|
|  |  |  | import com.panzhihua.service_community.model.dos.ComMngPopulationHouseUserDO; | 
|---|
|  |  |  | import com.panzhihua.service_community.service.ComMngPopulationHouseUserService; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | import lombok.extern.slf4j.Slf4j; | 
|---|
|  |  |  | import org.springframework.stereotype.Service; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | * @auther lyq | 
|---|
|  |  |  | 
|---|
|  |  |  | */ | 
|---|
|  |  |  | @Slf4j | 
|---|
|  |  |  | @Service | 
|---|
|  |  |  | public class ComMngPopulationHouseUserServiceImpl extends ServiceImpl<ComMngPopulationHouseUserDAO, ComMngPopulationHouseUserDO> implements ComMngPopulationHouseUserService { | 
|---|
|  |  |  | public class ComMngPopulationHouseUserServiceImpl extends | 
|---|
|  |  |  | ServiceImpl<ComMngPopulationHouseUserDAO, ComMngPopulationHouseUserDO> implements ComMngPopulationHouseUserService { | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | * 批量向房屋新增人员 | 
|---|
|  |  |  | * | 
|---|
|  |  |  | * @param housePopulationDTO | 
|---|
|  |  |  | *            请求参数 | 
|---|
|  |  |  | * @return 添加结果 | 
|---|
|  |  |  | */ | 
|---|
|  |  |  | @Override | 
|---|
|  |  |  | @Transactional(rollbackFor = Exception.class) | 
|---|
|  |  |  | public R addBuildingHousePopulation(AddComMngHousePopulationDTO housePopulationDTO) { | 
|---|
|  |  |  | List<ComMngPopulationHouseUserDO> populationHouseUserDOList = new ArrayList<>(); | 
|---|
|  |  |  | if (!housePopulationDTO.getPopulationIds().isEmpty()) { | 
|---|
|  |  |  | housePopulationDTO.getPopulationIds().forEach(housePopulationId -> { | 
|---|
|  |  |  | ComMngPopulationHouseUserDO populationHouseUserDO = | 
|---|
|  |  |  | this.baseMapper.selectOne(new QueryWrapper<ComMngPopulationHouseUserDO>().lambda() | 
|---|
|  |  |  | .eq(ComMngPopulationHouseUserDO::getHouseId, housePopulationDTO.getHouseId()) | 
|---|
|  |  |  | .eq(ComMngPopulationHouseUserDO::getPopulId, housePopulationId)); | 
|---|
|  |  |  | if (populationHouseUserDO == null) { | 
|---|
|  |  |  | populationHouseUserDO = new ComMngPopulationHouseUserDO(); | 
|---|
|  |  |  | populationHouseUserDO.setId(Snowflake.getId()); | 
|---|
|  |  |  | populationHouseUserDO.setHouseId(housePopulationDTO.getHouseId()); | 
|---|
|  |  |  | populationHouseUserDO.setPopulId(housePopulationId); | 
|---|
|  |  |  | populationHouseUserDO.setRelationId(ComMngPopulationHouseUserDO.relationId.zizhu); | 
|---|
|  |  |  | populationHouseUserDO.setStartAt(new Date()); | 
|---|
|  |  |  | populationHouseUserDO.setCreateAt(new Date()); | 
|---|
|  |  |  | if (housePopulationDTO.getType().equals(AddComMngHousePopulationDTO.type.hz)) { | 
|---|
|  |  |  | populationHouseUserDO.setRelation(ComMngPopulationHouseUserDO.relation.hz); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | populationHouseUserDOList.add(populationHouseUserDO); | 
|---|
|  |  |  | } else { | 
|---|
|  |  |  | if (housePopulationDTO.getType().equals(AddComMngHousePopulationDTO.type.hz)) { | 
|---|
|  |  |  | populationHouseUserDO.setRelation(ComMngPopulationHouseUserDO.relation.hz); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | populationHouseUserDO.setRelationId(ComMngPopulationHouseUserDO.relationId.zizhu); | 
|---|
|  |  |  | this.baseMapper.updateById(populationHouseUserDO); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | }); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | this.saveBatch(populationHouseUserDOList); | 
|---|
|  |  |  | return R.ok(); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | * 批量删除房屋内人员 | 
|---|
|  |  |  | * | 
|---|
|  |  |  | * @param housePopulationDTO | 
|---|
|  |  |  | *            请求参数 | 
|---|
|  |  |  | * @return 删除结果 | 
|---|
|  |  |  | */ | 
|---|
|  |  |  | @Override | 
|---|
|  |  |  | public R delBuildingHousePopulation(DelComMngHousePopulationDTO housePopulationDTO) { | 
|---|
|  |  |  |  | 
|---|
|  |  |  | ComMngPopulationHouseUserDO houseUserDO = this.baseMapper.selectById(housePopulationDTO.getHousePopulationId()); | 
|---|
|  |  |  | if (houseUserDO == null) { | 
|---|
|  |  |  | return R.fail("未查询到居住用户数据"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | if (housePopulationDTO.getType().equals(DelComMngHousePopulationDTO.type.hz)) { | 
|---|
|  |  |  | if (houseUserDO.getRelationId() == null | 
|---|
|  |  |  | || !houseUserDO.getRelationId().equals(ComMngPopulationHouseUserDO.relationId.zizhu)) { | 
|---|
|  |  |  | this.baseMapper.deleteById(housePopulationDTO.getHousePopulationId()); | 
|---|
|  |  |  | } else { | 
|---|
|  |  |  | this.baseMapper.delBuildingHousePopulationRelation(housePopulationDTO.getHousePopulationId()); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } else { | 
|---|
|  |  |  | if (houseUserDO.getRelation() == null | 
|---|
|  |  |  | || !houseUserDO.getRelation().equals(ComMngPopulationHouseUserDO.relation.hz)) { | 
|---|
|  |  |  | this.baseMapper.deleteById(housePopulationDTO.getHousePopulationId()); | 
|---|
|  |  |  | } else { | 
|---|
|  |  |  | this.baseMapper.delBuildingHousePopulationRelationId(housePopulationDTO.getHousePopulationId()); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | return R.ok(); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Override | 
|---|
|  |  |  | public R getVillagePopulationHouseAdmin(PageComMngVillagePopulationHouseDTO villagePopulationDTO) { | 
|---|
|  |  |  | return R.ok(this.baseMapper.getVillagePopulationHouseAdmin( | 
|---|
|  |  |  | new Page(villagePopulationDTO.getPageNum(), villagePopulationDTO.getPageSize()), villagePopulationDTO)); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Override | 
|---|
|  |  |  | public R insert(ComMngPopulationHouseUserVO comMngPopulationHouseUserVO) { | 
|---|
|  |  |  | ComMngPopulationHouseUserDO comMngPopulationHouseUserDO=new ComMngPopulationHouseUserDO(); | 
|---|
|  |  |  | BeanUtils.copyProperties(comMngPopulationHouseUserVO,comMngPopulationHouseUserDO); | 
|---|
|  |  |  | comMngPopulationHouseUserDO.setId(Snowflake.getId()); | 
|---|
|  |  |  | this.baseMapper.insert(comMngPopulationHouseUserDO); | 
|---|
|  |  |  | return R.ok(); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Override | 
|---|
|  |  |  | public R updateAll(ComMngPopulationHouseUserVO comMngPopulationHouseUserVO) { | 
|---|
|  |  |  | ComMngPopulationHouseUserDO comMngPopulationHouseUserDO=new ComMngPopulationHouseUserDO(); | 
|---|
|  |  |  | BeanUtils.copyProperties(comMngPopulationHouseUserVO,comMngPopulationHouseUserDO); | 
|---|
|  |  |  | this.baseMapper.updateById(comMngPopulationHouseUserDO); | 
|---|
|  |  |  | return R.ok(); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Override | 
|---|
|  |  |  | public R delete(ComMngPopulationHouseUserVO comMngPopulationHouseUserVO) { | 
|---|
|  |  |  | return R.ok(this.baseMapper.deleteById(comMngPopulationHouseUserVO.getId())); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Override | 
|---|
|  |  |  | public R detail(Long id) { | 
|---|
|  |  |  | return R.ok(this.baseMapper.detail(id)); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | } | 
|---|