diff --git a/opsli-api/src/main/java/org/opsli/api/web/system/tenant/TenantApi.java b/opsli-api/src/main/java/org/opsli/api/web/system/tenant/TenantApi.java index 54f6a14..99aa597 100644 --- a/opsli-api/src/main/java/org/opsli/api/web/system/tenant/TenantApi.java +++ b/opsli-api/src/main/java/org/opsli/api/web/system/tenant/TenantApi.java @@ -127,6 +127,17 @@ public interface TenantApi { @GetMapping("/importExcel/template") void importTemplate(HttpServletResponse response); + + /** + * 变更租户状态 + * + * @param tenantId 租户ID + * @param enable 状态 + * @return ResultVo + */ + @PostMapping("/enableTenant") + ResultVo enableTenant(String tenantId, String enable); + // ========================= /** diff --git a/opsli-modulars/opsli-modulars-system/src/main/java/org/opsli/modulars/system/SystemMsg.java b/opsli-modulars/opsli-modulars-system/src/main/java/org/opsli/modulars/system/SystemMsg.java index 1bd5912..7b5da29 100644 --- a/opsli-modulars/opsli-modulars-system/src/main/java/org/opsli/modulars/system/SystemMsg.java +++ b/opsli-modulars/opsli-modulars-system/src/main/java/org/opsli/modulars/system/SystemMsg.java @@ -71,6 +71,8 @@ public enum SystemMsg implements BaseMsg { */ EXCEPTION_TENANT_UNIQUE(20400,"租户名称重复,该租户已存在"), EXCEPTION_TENANT_USED_DEL(20401,"该租户正在被其他用户绑定,无法删除"), + EXCEPTION_TENANT_HANDLE_SELF(20402,"不可操作自身"), + /** * 组织机构 diff --git a/opsli-modulars/opsli-modulars-system/src/main/java/org/opsli/modulars/system/tenant/service/ITenantService.java b/opsli-modulars/opsli-modulars-system/src/main/java/org/opsli/modulars/system/tenant/service/ITenantService.java index 3b58a95..64628d7 100644 --- a/opsli-modulars/opsli-modulars-system/src/main/java/org/opsli/modulars/system/tenant/service/ITenantService.java +++ b/opsli-modulars/opsli-modulars-system/src/main/java/org/opsli/modulars/system/tenant/service/ITenantService.java @@ -30,4 +30,14 @@ import org.opsli.modulars.system.tenant.entity.SysTenant; public interface ITenantService extends CrudServiceInterface { + /** + * 变更租户状态 + * + * @param tenantId 租户ID + * @param enable 启用状态 + * @return boolean + */ + boolean enableTenant(String tenantId, String enable); + + } diff --git a/opsli-modulars/opsli-modulars-system/src/main/java/org/opsli/modulars/system/tenant/service/impl/TenantServiceImpl.java b/opsli-modulars/opsli-modulars-system/src/main/java/org/opsli/modulars/system/tenant/service/impl/TenantServiceImpl.java index f7cc93e..4fab48a 100644 --- a/opsli-modulars/opsli-modulars-system/src/main/java/org/opsli/modulars/system/tenant/service/impl/TenantServiceImpl.java +++ b/opsli-modulars/opsli-modulars-system/src/main/java/org/opsli/modulars/system/tenant/service/impl/TenantServiceImpl.java @@ -18,10 +18,12 @@ package org.opsli.modulars.system.tenant.service.impl; import cn.hutool.core.collection.CollUtil; import cn.hutool.core.convert.Convert; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; +import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper; import com.google.common.collect.Lists; import org.apache.commons.lang3.StringUtils; import org.opsli.api.wrapper.system.tenant.TenantModel; +import org.opsli.api.wrapper.system.user.UserModel; import org.opsli.common.constants.MyBatisConstants; import org.opsli.common.enums.DictType; import org.opsli.common.exception.ServiceException; @@ -29,6 +31,7 @@ import org.opsli.common.utils.HumpUtil; import org.opsli.core.base.service.impl.CrudServiceImpl; import org.opsli.core.msg.CoreMsg; import org.opsli.core.utils.TenantUtil; +import org.opsli.core.utils.UserUtil; import org.opsli.modulars.system.SystemMsg; import org.opsli.modulars.system.tenant.entity.SysTenant; import org.opsli.modulars.system.tenant.mapper.TenantMapper; @@ -60,6 +63,32 @@ public class TenantServiceImpl extends CrudServiceImpl updateWrapper = new UpdateWrapper<>(); + updateWrapper.set("enable", enable) + .eq( + HumpUtil.humpToUnderline(MyBatisConstants.FIELD_ID), tenantId); + if(this.update(updateWrapper)){ + // 清除缓存 + this.clearCache(Collections.singletonList(tenantId)); + return true; + } + return false; + } + @Override @Transactional(rollbackFor = Exception.class) public TenantModel insert(TenantModel model) { diff --git a/opsli-modulars/opsli-modulars-system/src/main/java/org/opsli/modulars/system/tenant/web/TenantRestController.java b/opsli-modulars/opsli-modulars-system/src/main/java/org/opsli/modulars/system/tenant/web/TenantRestController.java index b09ed18..65a3f76 100644 --- a/opsli-modulars/opsli-modulars-system/src/main/java/org/opsli/modulars/system/tenant/web/TenantRestController.java +++ b/opsli-modulars/opsli-modulars-system/src/main/java/org/opsli/modulars/system/tenant/web/TenantRestController.java @@ -29,12 +29,15 @@ import org.opsli.api.wrapper.system.tenant.TenantModel; import org.opsli.common.annotation.ApiRestController; import org.opsli.common.annotation.EnableLog; import org.opsli.common.annotation.RequiresPermissionsCus; +import org.opsli.common.enums.DictType; +import org.opsli.common.exception.ServiceException; import org.opsli.common.utils.WrapperUtil; import org.opsli.core.base.controller.BaseRestController; import org.opsli.core.persistence.Page; import org.opsli.core.persistence.querybuilder.GenQueryBuilder; import org.opsli.core.persistence.querybuilder.QueryBuilder; import org.opsli.core.persistence.querybuilder.WebQueryBuilder; +import org.opsli.modulars.system.SystemMsg; import org.opsli.modulars.system.tenant.entity.SysTenant; import org.opsli.modulars.system.tenant.service.ITenantService; import org.springframework.web.multipart.MultipartHttpServletRequest; @@ -58,6 +61,31 @@ public class TenantRestController extends BaseRestController enableTenant(String tenantId, String enable) { + // 演示模式 不允许操作 + super.demoError(); + + if(!DictType.hasDict(DictType.NO_YES_YES.getType(), enable)){ + // 非法参数 + throw new ServiceException(SystemMsg.EXCEPTION_USER_ILLEGAL_PARAMETER); + } + + // 变更租户状态账户 + boolean enableStatus = IService.enableTenant(tenantId, tenantId); + if(!enableStatus){ + return ResultVo.error("变更用户状态账户失败"); + } + return ResultVo.success(); + } + /** * 租户 查一条 * @param model 模型