New file |
| | |
| | | package com.panzhihua.service_community.service.impl; |
| | | |
| | | import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
| | | import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
| | | import com.baomidou.mybatisplus.core.metadata.IPage; |
| | | import com.baomidou.mybatisplus.core.toolkit.Wrappers; |
| | | import com.baomidou.mybatisplus.extension.plugins.pagination.Page; |
| | | import com.google.common.collect.Lists; |
| | | import com.panzhihua.common.model.dtos.community.PageComStreetDTO; |
| | | import com.panzhihua.common.model.vos.R; |
| | | import com.panzhihua.common.model.vos.community.ComActVO; |
| | | import com.panzhihua.common.model.vos.community.ComStreetVO; |
| | | import com.panzhihua.service_community.dao.ComActDAO; |
| | | import com.panzhihua.service_community.dao.ComStreetDAO; |
| | | import com.panzhihua.service_community.model.dos.ComStreetDO; |
| | | import com.panzhihua.service_community.service.ComStreetService; |
| | | import org.springframework.beans.BeanUtils; |
| | | import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder; |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.util.ObjectUtils; |
| | | |
| | | import javax.annotation.Resource; |
| | | import java.util.List; |
| | | |
| | | /** |
| | | * @author: llming |
| | | * @description: 街道 |
| | | **/ |
| | | @Service |
| | | public class ComStreetServiceImpl implements ComStreetService { |
| | | @Resource |
| | | private ComActDAO comActDAO; |
| | | |
| | | @Resource |
| | | private ComStreetDAO comStreetDAO; |
| | | |
| | | /** |
| | | * 新增社区 |
| | | * |
| | | * @param comStreetVO 街道信息 |
| | | * @return 新增结果 |
| | | */ |
| | | @Override |
| | | public R addStreet(ComStreetVO comStreetVO) { |
| | | String password = comStreetVO.getPassword(); |
| | | String encode = new BCryptPasswordEncoder().encode(password); |
| | | comStreetVO.setPassword(encode); |
| | | ComStreetDO comStreetDO = new ComStreetDO(); |
| | | LambdaQueryWrapper<ComStreetDO> param = new QueryWrapper<ComStreetDO>().lambda(); |
| | | param.eq(ComStreetDO::getName, comStreetVO.getName()); |
| | | param.eq(ComStreetDO::getProvinceCode, comStreetVO.getProvinceCode()); |
| | | param.eq(ComStreetDO::getCityCode, comStreetVO.getCityCode()); |
| | | param.eq(ComStreetDO::getAreaCode, comStreetVO.getAreaCode()); |
| | | Integer integer = comStreetDAO.selectCount(param); |
| | | if (integer > 0) { |
| | | return R.fail("街道已经存在"); |
| | | } |
| | | BeanUtils.copyProperties(comStreetVO, comStreetDO); |
| | | int insert = comStreetDAO.insert(comStreetDO); |
| | | if (insert > 0) { |
| | | ComStreetDO comStreetDO1 = comStreetDAO.selectOne(param); |
| | | BeanUtils.copyProperties(comStreetDO1, comStreetVO); |
| | | return R.ok(comStreetVO); |
| | | } |
| | | return R.fail(); |
| | | } |
| | | |
| | | |
| | | /** |
| | | * 查询街道 |
| | | * |
| | | * @param comStreetVO 街道名 |
| | | * @return 社区集合 |
| | | */ |
| | | @Override |
| | | public R listStreet(ComStreetVO comStreetVO) { |
| | | List<ComStreetVO> vos = Lists.newArrayList(); |
| | | LambdaQueryWrapper<ComStreetDO> param = new QueryWrapper<ComStreetDO>().lambda(); |
| | | param.eq(ComStreetDO::getProvinceCode, comStreetVO.getProvinceCode()); |
| | | param.eq(ComStreetDO::getCityCode, comStreetVO.getCityCode()); |
| | | param.eq(ComStreetDO::getAreaCode, comStreetVO.getCityCode()); |
| | | List<ComStreetDO> ComStreetDOS = comStreetDAO.selectList(param); |
| | | BeanUtils.copyProperties(vos, ComStreetDOS); |
| | | return R.ok(comStreetVO); |
| | | } |
| | | |
| | | /** |
| | | * 社区详情 |
| | | * |
| | | * @param streetId 街道id |
| | | * @return 社区详情 |
| | | */ |
| | | @Override |
| | | public R detailStreet(Long streetId) { |
| | | ComStreetDO comStreetDO = comStreetDAO.selectById(streetId); |
| | | if (ObjectUtils.isEmpty(comStreetDO)) { |
| | | return R.fail(); |
| | | } |
| | | ComActVO comActVO = new ComActVO(); |
| | | BeanUtils.copyProperties(comStreetDO, comActVO); |
| | | comActVO.setAreaName(comActDAO.selectAreaName(comActVO.getAreaCode())); |
| | | return R.ok(comActVO); |
| | | } |
| | | |
| | | /** |
| | | * 分页查询社区 |
| | | * |
| | | * @param pageComStreetDTO 查询参数 |
| | | * @return 分页集合 |
| | | */ |
| | | @Override |
| | | public R pageStreet(PageComStreetDTO pageComStreetDTO) { |
| | | Page page = new Page<>(); |
| | | Long pageNum = pageComStreetDTO.getPageNum(); |
| | | Long pageSize = pageComStreetDTO.getPageSize(); |
| | | if (null == pageNum || 0 == pageNum) { |
| | | pageNum = 1l; |
| | | } |
| | | if (null == pageSize || 0 == pageSize) { |
| | | pageSize = 10l; |
| | | } |
| | | page.setSize(pageSize); |
| | | page.setCurrent(pageNum); |
| | | LambdaQueryWrapper<ComStreetDO> userLambdaQueryWrapper = Wrappers.lambdaQuery(); |
| | | if (!pageComStreetDTO.getName().isEmpty()) { |
| | | userLambdaQueryWrapper.like(ComStreetDO::getName, pageComStreetDTO.getName()); |
| | | } |
| | | Page userPage = new Page(pageNum, pageSize); |
| | | IPage<ComStreetDO> doPager = comStreetDAO.selectPage(userPage, userLambdaQueryWrapper); |
| | | return R.ok(doPager); |
| | | } |
| | | |
| | | |
| | | /** |
| | | * 批量删除社区 |
| | | * |
| | | * @param streetIds 社区id |
| | | * @return 删除结果 |
| | | */ |
| | | @Override |
| | | public R delectStreat(List<Long> streetIds) { |
| | | int delete = comStreetDAO.deleteBatchIds(streetIds); |
| | | if (delete > 0) { |
| | | return R.ok(); |
| | | } |
| | | return R.fail(); |
| | | } |
| | | |
| | | |
| | | } |