From 0e997cfd5a02447c9388009d05dc4136b04caba0 Mon Sep 17 00:00:00 2001 From: zzy Date: Mon, 20 Apr 2026 14:57:36 +0800 Subject: [PATCH] =?UTF-8?q?=E5=B0=8F=E5=8C=BA=E6=94=B9=E9=80=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../admin/community/CommunityController.java | 12 +- .../community/vo/CommunityPageReqVO.java | 10 +- .../admin/community/vo/CommunityRespVO.java | 70 +++--- .../community/vo/CommunitySaveReqVO.java | 29 ++- .../community/vo/CommunityTreeRespVO.java | 27 --- .../dal/dataobject/community/CommunityDO.java | 57 ++--- .../dal/mysql/community/CommunityMapper.java | 4 +- .../service/community/CommunityService.java | 9 - .../community/CommunityServiceImpl.java | 199 +++++------------- 9 files changed, 125 insertions(+), 292 deletions(-) delete mode 100644 fjrcloud-module-community/src/main/java/com/fjrcloud/community/module/community/controller/admin/community/vo/CommunityTreeRespVO.java diff --git a/fjrcloud-module-community/src/main/java/com/fjrcloud/community/module/community/controller/admin/community/CommunityController.java b/fjrcloud-module-community/src/main/java/com/fjrcloud/community/module/community/controller/admin/community/CommunityController.java index 21673c3..6262b4c 100644 --- a/fjrcloud-module-community/src/main/java/com/fjrcloud/community/module/community/controller/admin/community/CommunityController.java +++ b/fjrcloud-module-community/src/main/java/com/fjrcloud/community/module/community/controller/admin/community/CommunityController.java @@ -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 deleteCommunityList(@RequestParam("ids") List 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> getStreetCommunityTree(@RequestParam(value = "streetId", required = false) Long streetId) { - List tree = communityService.getStreetCommunityTree(streetId); - return success(tree); - } - } \ No newline at end of file diff --git a/fjrcloud-module-community/src/main/java/com/fjrcloud/community/module/community/controller/admin/community/vo/CommunityPageReqVO.java b/fjrcloud-module-community/src/main/java/com/fjrcloud/community/module/community/controller/admin/community/vo/CommunityPageReqVO.java index 7a28172..e7274a5 100644 --- a/fjrcloud-module-community/src/main/java/com/fjrcloud/community/module/community/controller/admin/community/vo/CommunityPageReqVO.java +++ b/fjrcloud-module-community/src/main/java/com/fjrcloud/community/module/community/controller/admin/community/vo/CommunityPageReqVO.java @@ -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; } \ No newline at end of file diff --git a/fjrcloud-module-community/src/main/java/com/fjrcloud/community/module/community/controller/admin/community/vo/CommunityRespVO.java b/fjrcloud-module-community/src/main/java/com/fjrcloud/community/module/community/controller/admin/community/vo/CommunityRespVO.java index c3757d7..5655fc5 100644 --- a/fjrcloud-module-community/src/main/java/com/fjrcloud/community/module/community/controller/admin/community/vo/CommunityRespVO.java +++ b/fjrcloud-module-community/src/main/java/com/fjrcloud/community/module/community/controller/admin/community/vo/CommunityRespVO.java @@ -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; -} \ No newline at end of file +} + diff --git a/fjrcloud-module-community/src/main/java/com/fjrcloud/community/module/community/controller/admin/community/vo/CommunitySaveReqVO.java b/fjrcloud-module-community/src/main/java/com/fjrcloud/community/module/community/controller/admin/community/vo/CommunitySaveReqVO.java index 28bcf09..9aaa75d 100644 --- a/fjrcloud-module-community/src/main/java/com/fjrcloud/community/module/community/controller/admin/community/vo/CommunitySaveReqVO.java +++ b/fjrcloud-module-community/src/main/java/com/fjrcloud/community/module/community/controller/admin/community/vo/CommunitySaveReqVO.java @@ -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; + } \ No newline at end of file diff --git a/fjrcloud-module-community/src/main/java/com/fjrcloud/community/module/community/controller/admin/community/vo/CommunityTreeRespVO.java b/fjrcloud-module-community/src/main/java/com/fjrcloud/community/module/community/controller/admin/community/vo/CommunityTreeRespVO.java deleted file mode 100644 index 83bef3f..0000000 --- a/fjrcloud-module-community/src/main/java/com/fjrcloud/community/module/community/controller/admin/community/vo/CommunityTreeRespVO.java +++ /dev/null @@ -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 children; - -} diff --git a/fjrcloud-module-community/src/main/java/com/fjrcloud/community/module/community/dal/dataobject/community/CommunityDO.java b/fjrcloud-module-community/src/main/java/com/fjrcloud/community/module/community/dal/dataobject/community/CommunityDO.java index c781115..90f6f6d 100644 --- a/fjrcloud-module-community/src/main/java/com/fjrcloud/community/module/community/dal/dataobject/community/CommunityDO.java +++ b/fjrcloud-module-community/src/main/java/com/fjrcloud/community/module/community/dal/dataobject/community/CommunityDO.java @@ -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一致 + * 主键ID,和租户id一致 */ @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; + /** * 来访审核配置:1需要审核,0无需审核 */ private Boolean visitAudit; - /** - * 物业人数 - */ - private Integer propertyNum; + /** * 道闸申请配置:1需要审核,0无需审核 */ private Boolean gateAudit; - /** - * 业委会人数 - */ - private Integer committeeNum; - } \ No newline at end of file diff --git a/fjrcloud-module-community/src/main/java/com/fjrcloud/community/module/community/dal/mysql/community/CommunityMapper.java b/fjrcloud-module-community/src/main/java/com/fjrcloud/community/module/community/dal/mysql/community/CommunityMapper.java index c0fa23b..3d8cc04 100644 --- a/fjrcloud-module-community/src/main/java/com/fjrcloud/community/module/community/dal/mysql/community/CommunityMapper.java +++ b/fjrcloud-module-community/src/main/java/com/fjrcloud/community/module/community/dal/mysql/community/CommunityMapper.java @@ -18,8 +18,8 @@ public interface CommunityMapper extends BaseMapperX { default PageResult selectPage(CommunityPageReqVO reqVO) { return selectPage(reqVO, new LambdaQueryWrapperX() .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)); } diff --git a/fjrcloud-module-community/src/main/java/com/fjrcloud/community/module/community/service/community/CommunityService.java b/fjrcloud-module-community/src/main/java/com/fjrcloud/community/module/community/service/community/CommunityService.java index 20c400c..672e49e 100644 --- a/fjrcloud-module-community/src/main/java/com/fjrcloud/community/module/community/service/community/CommunityService.java +++ b/fjrcloud-module-community/src/main/java/com/fjrcloud/community/module/community/service/community/CommunityService.java @@ -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 getCommunityPage(CommunityPageReqVO pageReqVO); - /** - * 获取街道和社区树形结构 - * - * @param streetId 街道ID,为null时返回所有街道及其下的社区 - * @return 树形结构列表 - */ - List getStreetCommunityTree(Long streetId); - } \ No newline at end of file diff --git a/fjrcloud-module-community/src/main/java/com/fjrcloud/community/module/community/service/community/CommunityServiceImpl.java b/fjrcloud-module-community/src/main/java/com/fjrcloud/community/module/community/service/community/CommunityServiceImpl.java index 89360e8..ae2e977 100644 --- a/fjrcloud-module-community/src/main/java/com/fjrcloud/community/module/community/service/community/CommunityServiceImpl.java +++ b/fjrcloud-module-community/src/main/java/com/fjrcloud/community/module/community/service/community/CommunityServiceImpl.java @@ -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 ids) { - ids.forEach(id -> deptApi.deleteDept(id)); + public void deleteCommunityListByIds(List 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 街道ID,为null时返回所有街道及其下的社区,不为null时返回指定街道及其下的社区 - * @return 树形结构列表,每个节点包含街道或社区的基本信息及子节点列表 - */ - public List getStreetCommunityTree(Long streetId) { - List streets; - List 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 streetIds = convertList(streets, CommunityDO::getId); - if (streetIds.isEmpty()) { - return new ArrayList<>(); - } - communities = communityMapper.selectList(new LambdaQueryWrapperX() - .eq(CommunityDO::getAreaType, 1) - .in(CommunityDO::getStreetId, streetIds)); - } - - Map> communityMap = communities.stream() - .collect(Collectors.groupingBy(CommunityDO::getStreetId)); - - List 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 children = communityMap.getOrDefault(street.getId(), Collections.emptyList()); - List 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; - } - } \ No newline at end of file