小区改造

master
zzy 2026-04-20 14:57:36 +08:00
parent 5e3d43bf29
commit 0e997cfd5a
9 changed files with 125 additions and 292 deletions

View File

@ -9,7 +9,6 @@ import com.fjrcloud.community.framework.excel.core.util.ExcelUtils;
import com.fjrcloud.community.module.community.controller.admin.community.vo.CommunityPageReqVO;
import com.fjrcloud.community.module.community.controller.admin.community.vo.CommunityRespVO;
import com.fjrcloud.community.module.community.controller.admin.community.vo.CommunitySaveReqVO;
import com.fjrcloud.community.module.community.controller.admin.community.vo.CommunityTreeRespVO;
import com.fjrcloud.community.module.community.dal.dataobject.community.CommunityDO;
import com.fjrcloud.community.module.community.service.community.CommunityService;
import io.swagger.v3.oas.annotations.Operation;
@ -64,7 +63,7 @@ public class CommunityController {
@DeleteMapping("/delete-list")
@Parameter(name = "ids", description = "编号", required = true)
@Operation(summary = "批量删除小区信息主表comm_community")
@PreAuthorize("@ss.hasPermission('community:community:delete')")
@PreAuthorize("@ss.hasPermission('community:community:delete')")
public CommonResult<Boolean> deleteCommunityList(@RequestParam("ids") List<Long> ids) {
communityService.deleteCommunityListByIds(ids);
return success(true);
@ -99,13 +98,4 @@ public class CommunityController {
BeanUtils.toBean(list, CommunityRespVO.class));
}
@GetMapping("/street-community-tree")
@Operation(summary = "获取街道和社区树形结构")
@Parameter(name = "streetId", description = "街道ID不传则返回所有街道及社区", example = "1024")
@PreAuthorize("@ss.hasPermission('community:community:query')")
public CommonResult<List<CommunityTreeRespVO>> getStreetCommunityTree(@RequestParam(value = "streetId", required = false) Long streetId) {
List<CommunityTreeRespVO> tree = communityService.getStreetCommunityTree(streetId);
return success(tree);
}
}

View File

@ -8,13 +8,13 @@ import lombok.Data;
@Data
public class CommunityPageReqVO extends PageParam {
@Schema(description = "小区名称", example = "芋艿")
@Schema(description = "小区名称", example = "阳光小区")
private String communityName;
@Schema(description = "所属街道ID", example = "20508")
private Long streetId;
@Schema(description = "所属街道名称", example = "XX街道")
private String streetName;
@Schema(description = "所属社区ID", example = "20551")
private Long districtId;
@Schema(description = "所属社区名称", example = "XX社区")
private String districtName;
}

View File

@ -2,8 +2,6 @@ package com.fjrcloud.community.module.community.controller.admin.community.vo;
import cn.idev.excel.annotation.ExcelIgnoreUnannotated;
import cn.idev.excel.annotation.ExcelProperty;
import com.fjrcloud.community.framework.excel.core.annotations.DictFormat;
import com.fjrcloud.community.framework.excel.core.convert.DictConvert;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
@ -15,76 +13,63 @@ import java.time.LocalDateTime;
@ExcelIgnoreUnannotated
public class CommunityRespVO {
@Schema(description = "主键ID,和部门id一致", requiredMode = Schema.RequiredMode.REQUIRED, example = "8921")
@ExcelProperty("主键ID,和部门id一致")
@Schema(description = "主键ID,和租户id一致", requiredMode = Schema.RequiredMode.REQUIRED, example = "8921")
@ExcelProperty("主键ID")
private Long id;
@Schema(description = "小区名称", requiredMode = Schema.RequiredMode.REQUIRED, example = "芋艿")
@Schema(description = "小区名称", requiredMode = Schema.RequiredMode.REQUIRED, example = "阳光小区")
@ExcelProperty("小区名称")
private String communityName;
@Schema(description = "区域类型0=街道1=社区2=小区", requiredMode = Schema.RequiredMode.REQUIRED, example = "0")
@ExcelProperty(value = "区域类型0=街道1=社区2=小区", converter = DictConvert.class)
@DictFormat("comm_area_type")
private Integer areaType;
@Schema(description = "所属街道ID", example = "20508")
@ExcelProperty("所属街道ID")
private Long streetId;
@Schema(description = "所属街道名称", example = "王五")
@Schema(description = "所属街道名称", example = "XX街道")
@ExcelProperty("所属街道名称")
private String streetName;
@Schema(description = "所属社区ID", example = "20551")
@ExcelProperty("所属社区ID")
private Long districtId;
@Schema(description = "所属社区名称", example = "XX社区")
@ExcelProperty("所属社区名称")
private String districtName;
@Schema(description = "小区详细地址", requiredMode = Schema.RequiredMode.REQUIRED)
@ExcelProperty("小区详细地址")
private String communityAddress;
@Schema(description = "所属社区名称", example = "李四")
@ExcelProperty("所属社区名称")
private String districtName;
@Schema(description = "小区经度坐标")
@ExcelProperty("小区经度坐标")
private BigDecimal longitude;
@Schema(description = "房屋数")
@ExcelProperty("房屋数")
private Integer houseNum;
@Schema(description = "小区纬度坐标")
@ExcelProperty("小区纬度坐标")
private BigDecimal latitude;
@Schema(description = "常驻人口数")
@ExcelProperty("常驻人口数")
private Long residentNum;
@Schema(description = "小区物业名称")
@ExcelProperty("小区物业名称")
private String propertyCompany;
@Schema(description = "流动人口数")
@Schema(description = "来访审核配置1需要审核0无需审核", requiredMode = Schema.RequiredMode.REQUIRED)
@ExcelProperty("来访审核配置")
private Boolean visitAudit;
@Schema(description = "道闸申请配置1需要审核0无需审核", requiredMode = Schema.RequiredMode.REQUIRED)
@ExcelProperty("道闸申请配置")
private Boolean gateAudit;
@Schema(description = "房屋数", example = "0")
@ExcelProperty("房屋数")
private Integer houseNum;
@Schema(description = "常驻人口数", example = "0")
@ExcelProperty("常驻人口数")
private Long residentNum;
@Schema(description = "流动人口数", example = "0")
@ExcelProperty("流动人口数")
private Long floatingNum;
@Schema(description = "来访审核配置1需要审核0无需审核", requiredMode = Schema.RequiredMode.REQUIRED)
@ExcelProperty("来访审核配置1需要审核0无需审核")
private Boolean visitAudit;
@Schema(description = "物业人数")
@Schema(description = "物业人数", example = "0")
@ExcelProperty("物业人数")
private Integer propertyNum;
@Schema(description = "道闸申请配置1需要审核0无需审核", requiredMode = Schema.RequiredMode.REQUIRED)
@ExcelProperty("道闸申请配置1需要审核0无需审核")
private Boolean gateAudit;
@Schema(description = "业委会人数")
@Schema(description = "业委会人数", example = "0")
@ExcelProperty("业委会人数")
private Integer committeeNum;
@ -92,4 +77,5 @@ public class CommunityRespVO {
@ExcelProperty("创建时间")
private LocalDateTime createTime;
}
}

View File

@ -2,31 +2,29 @@ package com.fjrcloud.community.module.community.controller.admin.community.vo;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import org.hibernate.validator.constraints.Length;
import javax.validation.constraints.NotEmpty;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Pattern;
import javax.validation.constraints.Size;
import java.math.BigDecimal;
@Schema(description = "管理后台 - 小区信息主表comm_community新增/修改 Request VO")
@Data
public class CommunitySaveReqVO {
@Schema(description = "主键ID,和部门id一致", requiredMode = Schema.RequiredMode.REQUIRED, example = "8921")
@Schema(description = "主键ID,和租户id一致", requiredMode = Schema.RequiredMode.REQUIRED, example = "8921")
private Long id;
@Schema(description = "小区名称", requiredMode = Schema.RequiredMode.REQUIRED, example = "芋艿")
@Schema(description = "小区名称", requiredMode = Schema.RequiredMode.REQUIRED, example = "阳光小区")
@NotEmpty(message = "小区名称不能为空")
private String communityName;
@Schema(description = "区域类型0=街道1=社区2=小区", requiredMode = Schema.RequiredMode.REQUIRED, example = "0")
@NotNull(message = "区域类型0=街道1=社区2=小区不能为空")
private Integer areaType;
@Schema(description = "所属街道名称", example = "XX街道")
private String streetName;
@Schema(description = "所属街道ID", requiredMode = Schema.RequiredMode.REQUIRED, example = "20508")
private Long streetId;
@Schema(description = "所属社区ID", requiredMode = Schema.RequiredMode.REQUIRED, example = "20551")
private Long districtId;
@Schema(description = "所属社区名称", example = "XX社区")
private String districtName;
@Schema(description = "详细地址", requiredMode = Schema.RequiredMode.REQUIRED)
@NotEmpty(message = "详细地址不能为空")
@ -47,4 +45,13 @@ public class CommunitySaveReqVO {
@Schema(description = "道闸申请配置1需要审核0无需审核", requiredMode = Schema.RequiredMode.REQUIRED)
private Boolean gateAudit;
@Schema(description = "用户名", requiredMode = Schema.RequiredMode.REQUIRED, example = "admin")
@Pattern(regexp = "^[a-zA-Z0-9]{4,30}$", message = "用户名由 数字、字母 组成")
@Size(min = 4, max = 30, message = "用户名长度为 4-30 个字符")
private String username;
@Schema(description = "密码", requiredMode = Schema.RequiredMode.REQUIRED, example = "admin123")
@Length(min = 4, max = 16, message = "密码长度为 4-16 位")
private String password;
}

View File

@ -1,27 +0,0 @@
package com.fjrcloud.community.module.community.controller.admin.community.vo;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import java.util.List;
@Schema(description = "管理后台 - 街道社区树形结构 Response VO")
@Data
public class CommunityTreeRespVO {
@Schema(description = "节点ID", example = "1024")
private Long id;
@Schema(description = "节点名称", example = "XX街道")
private String name;
@Schema(description = "区域类型0=街道1=社区2=小区", example = "0")
private Integer areaType;
@Schema(description = "父节点ID", example = "0")
private Long parentId;
@Schema(description = "子节点列表")
private List<CommunityTreeRespVO> children;
}

View File

@ -4,6 +4,7 @@ import com.baomidou.mybatisplus.annotation.KeySequence;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import com.fjrcloud.community.framework.mybatis.core.dataobject.BaseDO;
import com.fjrcloud.community.framework.tenant.core.aop.TenantIgnore;
import lombok.*;
import java.math.BigDecimal;
@ -14,89 +15,65 @@ import java.math.BigDecimal;
* @author zzy
*/
@TableName("comm_community")
@KeySequence("comm_community_seq") // 用于 Oracle、PostgreSQL、Kingbase、DB2、H2 数据库的主键自增。如果是 MySQL 等数据库,可不写。
@KeySequence("comm_community_seq")
@Data
@EqualsAndHashCode(callSuper = true)
@ToString(callSuper = true)
@Builder
@NoArgsConstructor
@AllArgsConstructor
@TenantIgnore
public class CommunityDO extends BaseDO {
/**
* ID,id
* IDid
*/
@TableId
private Long id;
/**
*
*/
private String communityName;
/**
* 0=1=2=
*
*/
private Integer areaType;
/**
* ID
*/
private Long streetId;
/**
*
*/
private String streetName;
/**
* ID
*/
private Long districtId;
/**
*
*/
private String communityAddress;
/**
*
*/
private String districtName;
/**
*
*/
private String communityAddress;
/**
*
*/
private BigDecimal longitude;
/**
*
*/
private Integer houseNum;
/**
*
*/
private BigDecimal latitude;
/**
*
*/
private Long residentNum;
/**
*
*/
private String propertyCompany;
/**
*
*/
private Long floatingNum;
/**
* 访10
*/
private Boolean visitAudit;
/**
*
*/
private Integer propertyNum;
/**
* 10
*/
private Boolean gateAudit;
/**
*
*/
private Integer committeeNum;
}

View File

@ -18,8 +18,8 @@ public interface CommunityMapper extends BaseMapperX<CommunityDO> {
default PageResult<CommunityDO> selectPage(CommunityPageReqVO reqVO) {
return selectPage(reqVO, new LambdaQueryWrapperX<CommunityDO>()
.likeIfPresent(CommunityDO::getCommunityName, reqVO.getCommunityName())
.eqIfPresent(CommunityDO::getStreetId, reqVO.getStreetId())
.eqIfPresent(CommunityDO::getDistrictId, reqVO.getDistrictId())
.likeIfPresent(CommunityDO::getStreetName, reqVO.getStreetName())
.likeIfPresent(CommunityDO::getDistrictName, reqVO.getDistrictName())
.orderByDesc(CommunityDO::getId));
}

View File

@ -3,7 +3,6 @@ package com.fjrcloud.community.module.community.service.community;
import com.fjrcloud.community.framework.common.pojo.PageResult;
import com.fjrcloud.community.module.community.controller.admin.community.vo.CommunityPageReqVO;
import com.fjrcloud.community.module.community.controller.admin.community.vo.CommunitySaveReqVO;
import com.fjrcloud.community.module.community.controller.admin.community.vo.CommunityTreeRespVO;
import com.fjrcloud.community.module.community.dal.dataobject.community.CommunityDO;
import javax.validation.Valid;
@ -61,12 +60,4 @@ public interface CommunityService {
*/
PageResult<CommunityDO> getCommunityPage(CommunityPageReqVO pageReqVO);
/**
*
*
* @param streetId IDnull
* @return
*/
List<CommunityTreeRespVO> getStreetCommunityTree(Long streetId);
}

View File

@ -3,26 +3,20 @@ package com.fjrcloud.community.module.community.service.community;
import com.fjrcloud.community.framework.common.enums.CommonStatusEnum;
import com.fjrcloud.community.framework.common.pojo.PageResult;
import com.fjrcloud.community.framework.common.util.object.BeanUtils;
import com.fjrcloud.community.framework.mybatis.core.query.LambdaQueryWrapperX;
import com.fjrcloud.community.module.community.controller.admin.community.vo.CommunityPageReqVO;
import com.fjrcloud.community.module.community.controller.admin.community.vo.CommunitySaveReqVO;
import com.fjrcloud.community.module.community.controller.admin.community.vo.CommunityTreeRespVO;
import com.fjrcloud.community.module.community.dal.dataobject.community.CommunityDO;
import com.fjrcloud.community.module.community.dal.mysql.community.CommunityMapper;
import com.fjrcloud.community.module.system.api.dept.DeptApi;
import com.fjrcloud.community.module.system.controller.admin.dept.vo.dept.DeptSaveReqVO;
import com.fjrcloud.community.module.system.controller.admin.tenant.vo.tenant.TenantSaveReqVO;
import com.fjrcloud.community.module.system.service.tenant.TenantService;
import org.springframework.stereotype.Service;
import org.springframework.validation.annotation.Validated;
import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.Collections;
import java.time.LocalDateTime;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
import static com.fjrcloud.community.framework.common.exception.util.ServiceExceptionUtil.exception;
import static com.fjrcloud.community.framework.common.util.collection.CollectionUtils.convertList;
import static com.fjrcloud.community.module.community.enums.ErrorCodeConstants.COMMUNITY_NOT_EXISTS;
/**
@ -38,102 +32,78 @@ public class CommunityServiceImpl implements CommunityService {
private CommunityMapper communityMapper;
@Resource
private DeptApi deptApi;
private TenantService tenantService;
/**
* ID使111
*/
private static final Long TENANT_PACKAGE_ID = 111L;
@Override
public Long createCommunity(CommunitySaveReqVO createReqVO) {
DeptSaveReqVO deptReqVO = new DeptSaveReqVO();
deptReqVO.setName(createReqVO.getCommunityName());
deptReqVO.setSort(0);
deptReqVO.setStatus(CommonStatusEnum.ENABLE.getStatus());
Integer areaType = createReqVO.getAreaType();
if (areaType == 0) {
deptReqVO.setParentId(0L);
} else if (areaType == 1) {
deptReqVO.setParentId(createReqVO.getStreetId());
} else if (areaType == 2) {
deptReqVO.setParentId(createReqVO.getDistrictId());
}
Long deptId = deptApi.saveDept(deptReqVO);
// 创建租户
TenantSaveReqVO tenantReqVO = new TenantSaveReqVO();
tenantReqVO.setName(createReqVO.getCommunityName());
tenantReqVO.setContactName(createReqVO.getCommunityName());
tenantReqVO.setContactMobile("");
tenantReqVO.setStatus(CommonStatusEnum.ENABLE.getStatus());
tenantReqVO.setPackageId(TENANT_PACKAGE_ID);
tenantReqVO.setExpireTime(LocalDateTime.now().plusYears(100));
tenantReqVO.setAccountCount(9999);
// 使用传入的用户名和密码创建租户管理员
tenantReqVO.setUsername(createReqVO.getUsername());
tenantReqVO.setPassword(createReqVO.getPassword());
Long tenantId = tenantService.createTenant(tenantReqVO);
// 创建小区记录ID与租户ID一致
CommunityDO community = BeanUtils.toBean(createReqVO, CommunityDO.class);
community.setId(deptId);
if (areaType == 1) {
CommunityDO street = communityMapper.selectById(createReqVO.getStreetId());
if (street != null) {
community.setStreetName(street.getCommunityName());
}
} else if (areaType == 2) {
CommunityDO street = communityMapper.selectById(createReqVO.getStreetId());
if (street != null) {
community.setStreetName(street.getCommunityName());
}
CommunityDO district = communityMapper.selectById(createReqVO.getDistrictId());
if (district != null) {
community.setDistrictName(district.getCommunityName());
}
}
community.setId(tenantId);
communityMapper.insert(community);
return community.getId();
}
@Override
public void updateCommunity(CommunitySaveReqVO updateReqVO) {
DeptSaveReqVO deptReqVO = new DeptSaveReqVO();
deptReqVO.setId(updateReqVO.getId());
deptReqVO.setName(updateReqVO.getCommunityName());
deptReqVO.setSort(0);
deptReqVO.setStatus(CommonStatusEnum.ENABLE.getStatus());
Integer areaType = updateReqVO.getAreaType();
if (areaType == 0) {
deptReqVO.setParentId(0L);
} else if (areaType == 1) {
deptReqVO.setParentId(updateReqVO.getStreetId());
} else if (areaType == 2) {
deptReqVO.setParentId(updateReqVO.getDistrictId());
}
deptApi.saveDept(deptReqVO);
// 校验小区存在
validateCommunityExists(updateReqVO.getId());
// 更新租户信息
TenantSaveReqVO tenantReqVO = new TenantSaveReqVO();
tenantReqVO.setId(updateReqVO.getId());
tenantReqVO.setName(updateReqVO.getCommunityName());
tenantReqVO.setContactName(updateReqVO.getCommunityName());
tenantReqVO.setStatus(CommonStatusEnum.ENABLE.getStatus());
tenantReqVO.setPackageId(TENANT_PACKAGE_ID);
tenantReqVO.setExpireTime(LocalDateTime.now().plusYears(100));
tenantReqVO.setAccountCount(9999);
tenantService.updateTenant(tenantReqVO);
// 更新小区信息
CommunityDO updateObj = BeanUtils.toBean(updateReqVO, CommunityDO.class);
if (areaType == 1) {
CommunityDO street = communityMapper.selectById(updateReqVO.getStreetId());
if (street != null) {
updateObj.setStreetName(street.getCommunityName());
}
} else if (areaType == 2) {
CommunityDO street = communityMapper.selectById(updateReqVO.getStreetId());
if (street != null) {
updateObj.setStreetName(street.getCommunityName());
}
CommunityDO district = communityMapper.selectById(updateReqVO.getDistrictId());
if (district != null) {
updateObj.setDistrictName(district.getCommunityName());
}
}
communityMapper.updateById(updateObj);
}
@Override
public void deleteCommunity(Long id) {
deptApi.deleteDept(id);
// 校验小区存在
validateCommunityExists(id);
// 删除小区
communityMapper.deleteById(id);
// 同步删除租户
tenantService.deleteTenant(id);
}
@Override
public void deleteCommunityListByIds(List<Long> ids) {
ids.forEach(id -> deptApi.deleteDept(id));
public void deleteCommunityListByIds(List<Long> ids) {
// 批量删除小区
communityMapper.deleteByIds(ids);
}
// 同步删除租户
ids.forEach(id -> tenantService.deleteTenant(id));
}
private void validateCommunityExists(Long id) {
if (communityMapper.selectById(id) == null) {
@ -151,65 +121,4 @@ public class CommunityServiceImpl implements CommunityService {
return communityMapper.selectPage(pageReqVO);
}
/**
*
*
* @param streetId IDnullnull
* @return
*/
public List<CommunityTreeRespVO> getStreetCommunityTree(Long streetId) {
List<CommunityDO> streets;
List<CommunityDO> communities;
if (streetId != null) {
CommunityDO street = communityMapper.selectById(streetId);
if (street == null || street.getAreaType() != 0) {
return new ArrayList<>();
}
streets = Collections.singletonList(street);
communities = communityMapper.selectList(CommunityDO::getStreetId, streetId,
CommunityDO::getAreaType, 1);
} else {
streets = communityMapper.selectList(CommunityDO::getAreaType, 0);
List<Long> streetIds = convertList(streets, CommunityDO::getId);
if (streetIds.isEmpty()) {
return new ArrayList<>();
}
communities = communityMapper.selectList(new LambdaQueryWrapperX<CommunityDO>()
.eq(CommunityDO::getAreaType, 1)
.in(CommunityDO::getStreetId, streetIds));
}
Map<Long, List<CommunityDO>> communityMap = communities.stream()
.collect(Collectors.groupingBy(CommunityDO::getStreetId));
List<CommunityTreeRespVO> result = new ArrayList<>();
for (CommunityDO street : streets) {
CommunityTreeRespVO streetNode = new CommunityTreeRespVO();
streetNode.setId(street.getId());
streetNode.setName(street.getCommunityName());
streetNode.setAreaType(street.getAreaType());
streetNode.setParentId(0L);
List<CommunityDO> children = communityMap.getOrDefault(street.getId(), Collections.emptyList());
List<CommunityTreeRespVO> childNodes = children.stream()
.map(community -> {
CommunityTreeRespVO childNode = new CommunityTreeRespVO();
childNode.setId(community.getId());
childNode.setName(community.getCommunityName());
childNode.setAreaType(community.getAreaType());
childNode.setParentId(community.getStreetId());
childNode.setChildren(new ArrayList<>());
return childNode;
})
.collect(Collectors.toList());
streetNode.setChildren(childNodes);
result.add(streetNode);
}
return result;
}
}