package com.panzhihua.service_community.service.impl; import java.util.ArrayList; import java.util.List; import javax.annotation.Resource; import org.springframework.beans.BeanUtils; import org.springframework.stereotype.Service; import org.springframework.util.ObjectUtils; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper; import com.baomidou.mybatisplus.core.metadata.IPage; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.panzhihua.common.model.vos.R; import com.panzhihua.common.model.vos.community.ComMngStructAreaVO; import com.panzhihua.service_community.dao.ComMngStructAreaDAO; import com.panzhihua.service_community.model.dos.ComMngStructAreaDO; import com.panzhihua.service_community.service.ComMngStructAreaService; /** * @program: springcloud_k8s_panzhihuazhihuishequ * @description: 小区 * @author: huang.hongfa weixin hhf9596 qq 959656820 * @create: 2020-12-15 15:48 **/ @Service public class ComMngStructAreaServiceImpl implements ComMngStructAreaService { @Resource private ComMngStructAreaDAO comMngStructAreaDAO; /** * 新增小区 * * @param comMngStructAreaVO * 小区信息 * @return 新增结果 */ @Override public R addArea(ComMngStructAreaVO comMngStructAreaVO) { ComMngStructAreaDO comMngStructAreaDO = new ComMngStructAreaDO(); BeanUtils.copyProperties(comMngStructAreaVO, comMngStructAreaDO); long areaCode = 510000510400000001l;// 攀枝花区域地址编码+000001 ComMngStructAreaDO comMngStructAreaDO1 = comMngStructAreaDAO.selectOne(new QueryWrapper() .lambda().orderByDesc(ComMngStructAreaDO::getAreaCode).last(" limit 1 ")); if (!ObjectUtils.isEmpty(comMngStructAreaDO1)) { areaCode = Long.valueOf(comMngStructAreaDO1.getAreaCode()) + 1; } comMngStructAreaDO.setAreaCode(areaCode + ""); int insert = 0; try { insert = comMngStructAreaDAO.insert(comMngStructAreaDO); } catch (Exception e) { if (e.getMessage().contains("unique_address_detail")) { return R.fail("小区地址已经存在"); } } if (insert > 0) { return R.ok(areaCode); } return R.fail(); } /** * 分页查询小区 * * @param comMngStructAreaVO * 查询参数 * @return 分页结果 */ @Override public R pageArea(ComMngStructAreaVO comMngStructAreaVO) { Page page = new Page<>(); Long pageNum = comMngStructAreaVO.getPageNum(); Long pageSize = comMngStructAreaVO.getPageSize(); if (null == pageNum || 0 == pageNum) { pageNum = 1l; } if (null == pageSize || 0 == pageSize) { pageSize = 10l; } page.setSize(pageSize); page.setCurrent(pageNum); IPage iPage = comMngStructAreaDAO.pageArea(page, comMngStructAreaVO); return R.ok(iPage); } /** * 编辑小区 * * @param comMngStructAreaVO * 编辑内容 * @return 编辑结果 */ @Override public R putArea(ComMngStructAreaVO comMngStructAreaVO) { ComMngStructAreaDO comMngStructAreaDO = new ComMngStructAreaDO(); BeanUtils.copyProperties(comMngStructAreaVO, comMngStructAreaDO); int update = comMngStructAreaDAO.update(comMngStructAreaDO, new UpdateWrapper().lambda() .eq(ComMngStructAreaDO::getAreaCode, comMngStructAreaVO.getAreaCode())); if (update > 0) { return R.ok(); } return R.fail(); } /** * 删除小区 * * @param comMngStructAreaVO * 地址编码 * @return 删除结果 */ @Override public R deleteArea(ComMngStructAreaVO comMngStructAreaVO) { int delete = comMngStructAreaDAO.delete(new QueryWrapper().lambda() .eq(ComMngStructAreaDO::getAreaCode, comMngStructAreaVO.getAreaCode())); if (delete > 0) { return R.ok(); } return R.fail(); } /** * 查询小区信息 * * @param areaCode * 小区地址编码 * @return 小区信息 */ @Override public R selectAreaByAreaCode(String areaCode) { ComMngStructAreaDO comMngStructAreaDO = comMngStructAreaDAO .selectOne(new QueryWrapper().lambda().eq(ComMngStructAreaDO::getAreaCode, areaCode)); if (ObjectUtils.isEmpty(comMngStructAreaDO)) { return R.fail(); } return R.ok(comMngStructAreaDO); } /** * 获取小区的地址编码 * * @param areaId * 小区id * @return 小区地址编码 */ @Override public R selectAreaById(Long areaId) { ComMngStructAreaDO comMngStructAreaDO = comMngStructAreaDAO.selectById(areaId); if (ObjectUtils.isEmpty(comMngStructAreaDO)) { return R.fail("小区不存在"); } return R.ok(comMngStructAreaDO.getAreaCode()); } /** * 查询小区 * * @param communityId * 社区id * @return 小区集合 */ @Override public R listArea(Long communityId) { List comMngStructAreaVOS = new ArrayList<>(); List comMngStructAreaDOS = comMngStructAreaDAO.selectList( new QueryWrapper().lambda().eq(ComMngStructAreaDO::getCommunityId, communityId)); if (!ObjectUtils.isEmpty(comMngStructAreaDOS)) { comMngStructAreaDOS.forEach(comMngStructAreaDO -> { ComMngStructAreaVO comMngStructAreaVO = new ComMngStructAreaVO(); BeanUtils.copyProperties(comMngStructAreaDO, comMngStructAreaVO); comMngStructAreaVOS.add(comMngStructAreaVO); }); } return R.ok(comMngStructAreaVOS); } /** * 小区详情 * * @param areaId * 小区id * @return 小区信息 */ @Override public R detailArea(Long areaId) { ComMngStructAreaDO comMngStructAreaDO = comMngStructAreaDAO.selectById(areaId); if (ObjectUtils.isEmpty(comMngStructAreaDO)) { return R.fail("小区不存在"); } ComMngStructAreaVO comMngStructAreaVO = new ComMngStructAreaVO(); BeanUtils.copyProperties(comMngStructAreaDO, comMngStructAreaVO); return R.ok(comMngStructAreaVO); } /** * 选择导入的小区 * * @param param * 小区名字 模糊查询 * @param communityId * 社区id * @return 小区集合 ComMngStructAreaVO */ @Override public R listAreas(String param, Long communityId) { List comMngStructAreaVOS = new ArrayList<>(); comMngStructAreaVOS = comMngStructAreaDAO.listAreas(param, communityId); if (!ObjectUtils.isEmpty(comMngStructAreaVOS)) { comMngStructAreaVOS.forEach(comMngStructAreaVO -> { String roleConnector = comMngStructAreaVO.getRoleConnector(); String roleFloor = comMngStructAreaVO.getRoleFloor(); String roleDoor = comMngStructAreaVO.getRoleDoor(); String doorNum = "1-1-1-" + roleFloor + roleConnector + roleDoor; if (!ObjectUtils.isEmpty(roleFloor)) { comMngStructAreaVO.setDoorNum(doorNum); } }); } return R.ok(comMngStructAreaVOS); } /** * 检查小区是否已经批量设置过房屋并且返回小区房屋门号规则 * * @param id * 小区id * @return ComMngStructAreaVO */ @Override public R checkAreaHouse(Long id) { ComMngStructAreaDO comMngStructAreaDO = comMngStructAreaDAO.selectById(id); if (null == comMngStructAreaDO) { return R.fail("小区不存在"); } String roleFloor = comMngStructAreaDO.getRoleFloor(); String roleDoor = comMngStructAreaDO.getRoleDoor(); String areaCode = comMngStructAreaDO.getAreaCode(); if (ObjectUtils.isEmpty(roleDoor) || ObjectUtils.isEmpty(roleFloor)) { return R.fail("小区未批量设置房屋,请先去社区后台配置"); } Integer num = comMngStructAreaDAO.selectCountHouseByParentHouseCode(areaCode); if (num.intValue() == 0) { return R.fail("小区未批量设置房屋,请先去社区后台配置"); } ComMngStructAreaVO comMngStructAreaVO = new ComMngStructAreaVO(); BeanUtils.copyProperties(comMngStructAreaDO, comMngStructAreaVO); return R.ok(comMngStructAreaVO); } }