From ee4e74f3e93d3c94a5c5e47013c6c341e30ef220 Mon Sep 17 00:00:00 2001 From: xins Date: Wed, 27 Sep 2023 10:57:12 +0800 Subject: [PATCH] =?UTF-8?q?=E8=8B=A5=E4=BE=9D=E5=BE=AE=E6=9C=8D=E5=8A=A11.?= =?UTF-8?q?3.7=201=E3=80=81=E7=AE=A1=E7=90=86=E5=91=98=E7=A7=9F=E6=88=B7ID?= =?UTF-8?q?=E6=94=B9=E4=B8=BA1=EF=BC=8C=E6=A0=B9=E6=8D=AE=E6=AD=A4?= =?UTF-8?q?=E4=BF=AE=E6=94=B9=E9=80=BB=E8=BE=91=202=E3=80=81=E7=A7=9F?= =?UTF-8?q?=E6=88=B7=E4=BF=A1=E6=81=AF=E5=A2=9E=E5=88=A0=E6=94=B9=E6=9F=A5?= =?UTF-8?q?=E5=AE=8C=E5=96=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ruoyi/system/api/RemoteUserService.java | 19 +- .../factory/RemoteUserFallbackFactory.java | 5 + .../common/core/constant/HwDictConstants.java | 10 +- .../service/impl/HwTenantServiceImpl.java | 2 + .../controller/HwTenantController.java | 20 +- .../service/impl/HwTenantServiceImpl.java | 74 ++++-- .../mapper/business/HwTenantMapper.xml | 5 +- .../system/controller/SysUserController.java | 68 ++--- .../ruoyi/system/service/ISysUserService.java | 9 + .../service/impl/SysUserServiceImpl.java | 238 ++++++++---------- .../resources/mapper/system/SysUserMapper.xml | 3 + ruoyi-ui/src/views/business/tenant/index.vue | 153 +++-------- 12 files changed, 269 insertions(+), 337 deletions(-) diff --git a/ruoyi-api/ruoyi-api-system/src/main/java/com/ruoyi/system/api/RemoteUserService.java b/ruoyi-api/ruoyi-api-system/src/main/java/com/ruoyi/system/api/RemoteUserService.java index f074cec..3f327d1 100644 --- a/ruoyi-api/ruoyi-api-system/src/main/java/com/ruoyi/system/api/RemoteUserService.java +++ b/ruoyi-api/ruoyi-api-system/src/main/java/com/ruoyi/system/api/RemoteUserService.java @@ -1,11 +1,7 @@ package com.ruoyi.system.api; import org.springframework.cloud.openfeign.FeignClient; -import org.springframework.web.bind.annotation.GetMapping; -import org.springframework.web.bind.annotation.PathVariable; -import org.springframework.web.bind.annotation.PostMapping; -import org.springframework.web.bind.annotation.RequestBody; -import org.springframework.web.bind.annotation.RequestHeader; +import org.springframework.web.bind.annotation.*; import com.ruoyi.common.core.constant.SecurityConstants; import com.ruoyi.common.core.constant.ServiceNameConstants; import com.ruoyi.common.core.domain.R; @@ -40,4 +36,17 @@ public interface RemoteUserService */ @PostMapping("/user/register") public R registerUserInfo(@RequestBody SysUser sysUser, @RequestHeader(SecurityConstants.FROM_SOURCE) String source); + + + /** + * @param: tenantId + * @description 根据租户删除用户信息 + * @author xins + * @date 2023-09-27 9:58 + * @return R + */ + @PostMapping("/user/deleteUsersByTenantId/{tenantId}") + public R deleteUsersByTenantId(@PathVariable("tenantId") Long tenantId); + + } diff --git a/ruoyi-api/ruoyi-api-system/src/main/java/com/ruoyi/system/api/factory/RemoteUserFallbackFactory.java b/ruoyi-api/ruoyi-api-system/src/main/java/com/ruoyi/system/api/factory/RemoteUserFallbackFactory.java index 029b024..3308337 100644 --- a/ruoyi-api/ruoyi-api-system/src/main/java/com/ruoyi/system/api/factory/RemoteUserFallbackFactory.java +++ b/ruoyi-api/ruoyi-api-system/src/main/java/com/ruoyi/system/api/factory/RemoteUserFallbackFactory.java @@ -36,6 +36,11 @@ public class RemoteUserFallbackFactory implements FallbackFactory deleteUsersByTenantId(Long tenantId) { + return R.fail("删除用户失败:" + throwable.getMessage()); + } }; } } diff --git a/ruoyi-common/ruoyi-common-core/src/main/java/com/ruoyi/common/core/constant/HwDictConstants.java b/ruoyi-common/ruoyi-common-core/src/main/java/com/ruoyi/common/core/constant/HwDictConstants.java index 931728d..6c3c769 100644 --- a/ruoyi-common/ruoyi-common-core/src/main/java/com/ruoyi/common/core/constant/HwDictConstants.java +++ b/ruoyi-common/ruoyi-common-core/src/main/java/com/ruoyi/common/core/constant/HwDictConstants.java @@ -54,7 +54,7 @@ public class HwDictConstants { public static final String DEVICE_DEFAULT_FLAG_YES = "1";//默认是 public static final String DEVICE_DEFAULT_FLAG_NO = "0";//默认否 - public static final Long ADMINISTRATOR_TENANT_ID = 0L;//金瑞铭租户ID + public static final Long ADMINISTRATOR_TENANT_ID = 1L;//金瑞铭租户ID public static final String DEVICE_TYPE_GATEWAY_DEVICE = "1";//网关设备 public static final String DEVICE_TYPE_GATEWAY_SUB_EQUIPMENT = "2";//网关子设备 @@ -100,5 +100,11 @@ public class HwDictConstants { public static final String CONTROL_COMMAND_PAYLOAD_TYPE_KEY = "type"; public static final String CONTROL_COMMAND_PAYLOAD_PARAM_KEY = "param"; - public static final String DEVICEMODE_GPS_FLAG_NO="0"; + public static final String DEVICEMODE_GPS_FLAG_NO="0";//设备模型,非定位模型 + + public static final String TENANT_STATUS_NORMAL = "1";//租户状态:正常 + public static final String TENANT_STATUS_DELETED = "9";//租户状态:正常 + public static final String TENANT_IS_REGISTER_EXTERNAL = "0";//租户是否外部注册:否 + + } diff --git a/ruoyi-modules/hw-basic/src/main/java/com/ruoyi/basic/service/impl/HwTenantServiceImpl.java b/ruoyi-modules/hw-basic/src/main/java/com/ruoyi/basic/service/impl/HwTenantServiceImpl.java index d0cc649..fdcf27e 100644 --- a/ruoyi-modules/hw-basic/src/main/java/com/ruoyi/basic/service/impl/HwTenantServiceImpl.java +++ b/ruoyi-modules/hw-basic/src/main/java/com/ruoyi/basic/service/impl/HwTenantServiceImpl.java @@ -4,6 +4,7 @@ package com.ruoyi.basic.service.impl; import com.ruoyi.basic.api.domain.HwTenant; import com.ruoyi.basic.mapper.HwTenantMapper; import com.ruoyi.basic.service.IHwTenantService; +import com.ruoyi.common.core.constant.HwDictConstants; import com.ruoyi.common.core.utils.DateUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; @@ -43,6 +44,7 @@ public class HwTenantServiceImpl implements IHwTenantService @Override public List selectHwTenantList(HwTenant hwTenant) { + hwTenant.setTenantStatus(HwDictConstants.TENANT_STATUS_NORMAL); return hwTenantMapper.selectHwTenantList(hwTenant); } diff --git a/ruoyi-modules/hw-business/src/main/java/com/ruoyi/business/controller/HwTenantController.java b/ruoyi-modules/hw-business/src/main/java/com/ruoyi/business/controller/HwTenantController.java index c375d39..9b94200 100644 --- a/ruoyi-modules/hw-business/src/main/java/com/ruoyi/business/controller/HwTenantController.java +++ b/ruoyi-modules/hw-business/src/main/java/com/ruoyi/business/controller/HwTenantController.java @@ -5,6 +5,7 @@ import java.util.List; import java.io.IOException; import javax.servlet.http.HttpServletResponse; +import com.ruoyi.common.core.constant.HwDictConstants; import com.ruoyi.common.security.utils.SecurityUtils; import com.ruoyi.system.api.domain.SysUser; import com.ruoyi.system.api.model.LoginUser; @@ -47,12 +48,7 @@ public class HwTenantController extends BaseController @GetMapping("/list") public TableDataInfo list(HwTenant hwTenant) { - List list = new ArrayList(); - startPage(); - //todo 放到add中 - - list = hwTenantService.selectHwTenantList(hwTenant); - return getDataTable(list); + return getDataTable(hwTenantService.selectHwTenantList(hwTenant)); } /** @@ -86,10 +82,8 @@ public class HwTenantController extends BaseController @PostMapping public AjaxResult add(@RequestBody HwTenant hwTenant) { - LoginUser loginUser = SecurityUtils.getLoginUser(); - SysUser sysUser = loginUser.getSysUser(); - hwTenant.setIsRegister("0"); - hwTenant.setCreateBy(sysUser.getNickName()); + hwTenant.setIsRegister(HwDictConstants.TENANT_IS_REGISTER_EXTERNAL); + hwTenant.setCreateBy(SecurityUtils.getUsername()); return toAjax(hwTenantService.insertHwTenant(hwTenant)); } @@ -100,10 +94,8 @@ public class HwTenantController extends BaseController @Log(title = "租户信息", businessType = BusinessType.UPDATE) @PutMapping public AjaxResult edit(@RequestBody HwTenant hwTenant) - {LoginUser loginUser = SecurityUtils.getLoginUser(); - SysUser sysUser = loginUser.getSysUser(); - - hwTenant.setUpdateBy(sysUser.getNickName()); + { + hwTenant.setUpdateBy(SecurityUtils.getUsername()); return toAjax(hwTenantService.updateHwTenant(hwTenant)); } diff --git a/ruoyi-modules/hw-business/src/main/java/com/ruoyi/business/service/impl/HwTenantServiceImpl.java b/ruoyi-modules/hw-business/src/main/java/com/ruoyi/business/service/impl/HwTenantServiceImpl.java index 5c856e3..d8c8a62 100644 --- a/ruoyi-modules/hw-business/src/main/java/com/ruoyi/business/service/impl/HwTenantServiceImpl.java +++ b/ruoyi-modules/hw-business/src/main/java/com/ruoyi/business/service/impl/HwTenantServiceImpl.java @@ -1,96 +1,118 @@ package com.ruoyi.business.service.impl; -import java.util.List; +import com.ruoyi.business.domain.HwTenant; +import com.ruoyi.business.mapper.HwTenantMapper; +import com.ruoyi.business.service.IHwTenantService; +import com.ruoyi.common.core.constant.HwDictConstants; +import com.ruoyi.common.core.domain.R; +import com.ruoyi.common.core.exception.ServiceException; import com.ruoyi.common.core.utils.DateUtils; +import com.ruoyi.common.datascope.annotation.DataScope; +import com.ruoyi.system.api.RemoteUserService; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; -import com.ruoyi.business.mapper.HwTenantMapper; -import com.ruoyi.business.domain.HwTenant; -import com.ruoyi.business.service.IHwTenantService; +import org.springframework.transaction.annotation.Transactional; + +import javax.annotation.Resource; +import java.util.List; /** * 租户信息Service业务层处理 - * + * * @author xins * @date 2023-09-04 */ @Service -public class HwTenantServiceImpl implements IHwTenantService -{ +public class HwTenantServiceImpl implements IHwTenantService { @Autowired private HwTenantMapper hwTenantMapper; + @Resource + private RemoteUserService remoteUserService; + /** * 查询租户信息 - * + * * @param tenantId 租户信息主键 * @return 租户信息 */ @Override - public HwTenant selectHwTenantByTenantId(Long tenantId) - { + public HwTenant selectHwTenantByTenantId(Long tenantId) { return hwTenantMapper.selectHwTenantByTenantId(tenantId); } /** * 查询租户信息列表 - * + * * @param hwTenant 租户信息 * @return 租户信息 */ @Override - public List selectHwTenantList(HwTenant hwTenant) - { + @DataScope(tenantAlias = "ht") + public List selectHwTenantList(HwTenant hwTenant) { + hwTenant.setTenantStatus(HwDictConstants.TENANT_STATUS_NORMAL); return hwTenantMapper.selectHwTenantList(hwTenant); } /** * 新增租户信息 - * + * * @param hwTenant 租户信息 * @return 结果 */ @Override - public int insertHwTenant(HwTenant hwTenant) - { + public int insertHwTenant(HwTenant hwTenant) { hwTenant.setCreateTime(DateUtils.getNowDate()); return hwTenantMapper.insertHwTenant(hwTenant); } /** * 修改租户信息 - * + * * @param hwTenant 租户信息 * @return 结果 */ @Override - public int updateHwTenant(HwTenant hwTenant) - { + public int updateHwTenant(HwTenant hwTenant) { hwTenant.setUpdateTime(DateUtils.getNowDate()); return hwTenantMapper.updateHwTenant(hwTenant); } /** * 批量删除租户信息 - * + * * @param tenantIds 需要删除的租户信息主键 * @return 结果 */ @Override - public int deleteHwTenantByTenantIds(Long[] tenantIds) - { - return hwTenantMapper.deleteHwTenantByTenantIds(tenantIds); + @Transactional + public int deleteHwTenantByTenantIds(Long[] tenantIds) { + for (Long tenantId : tenantIds) { + if(tenantId.equals(HwDictConstants.ADMINISTRATOR_TENANT_ID)){ + throw new ServiceException("管理租户不能删除"); + } + + R deleteResult = this.remoteUserService.deleteUsersByTenantId(tenantId); + if (R.FAIL == deleteResult.getCode()) { + throw new ServiceException(deleteResult.getMsg()); + } + + HwTenant tenant = hwTenantMapper.selectHwTenantByTenantId(tenantId); + tenant.setTenantStatus(HwDictConstants.TENANT_STATUS_DELETED); + hwTenantMapper.updateHwTenant(tenant); + } + + return 1; } /** * 删除租户信息信息 - * + * * @param tenantId 租户信息主键 * @return 结果 */ @Override - public int deleteHwTenantByTenantId(Long tenantId) - { + public int deleteHwTenantByTenantId(Long tenantId) { return hwTenantMapper.deleteHwTenantByTenantId(tenantId); } } diff --git a/ruoyi-modules/hw-business/src/main/resources/mapper/business/HwTenantMapper.xml b/ruoyi-modules/hw-business/src/main/resources/mapper/business/HwTenantMapper.xml index 5015283..26f8d25 100644 --- a/ruoyi-modules/hw-business/src/main/resources/mapper/business/HwTenantMapper.xml +++ b/ruoyi-modules/hw-business/src/main/resources/mapper/business/HwTenantMapper.xml @@ -26,7 +26,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" - select tenant_id, tenant_type, tenant_name, tenant_industry, contact_name, contact_phone, email, area_id, contact_address, remark, tenant_status, is_register, create_by, create_time, update_by, update_time, tenant_grade, tenant_field from hw_tenant + select tenant_id, tenant_type, tenant_name, tenant_industry, contact_name, contact_phone, email, area_id, contact_address, remark, tenant_status, is_register, create_by, create_time, update_by, update_time, tenant_grade, tenant_field from hw_tenant ht