增加租户 启用接口

v1.4.1
hiparker 4 years ago
parent f0b4a172b7
commit 6e18a64e61

@ -127,6 +127,17 @@ public interface TenantApi {
@GetMapping("/importExcel/template") @GetMapping("/importExcel/template")
void importTemplate(HttpServletResponse response); void importTemplate(HttpServletResponse response);
/**
*
*
* @param tenantId ID
* @param enable
* @return ResultVo
*/
@PostMapping("/enableTenant")
ResultVo<?> enableTenant(String tenantId, String enable);
// ========================= // =========================
/** /**

@ -71,6 +71,8 @@ public enum SystemMsg implements BaseMsg {
*/ */
EXCEPTION_TENANT_UNIQUE(20400,"租户名称重复,该租户已存在"), EXCEPTION_TENANT_UNIQUE(20400,"租户名称重复,该租户已存在"),
EXCEPTION_TENANT_USED_DEL(20401,"该租户正在被其他用户绑定,无法删除"), EXCEPTION_TENANT_USED_DEL(20401,"该租户正在被其他用户绑定,无法删除"),
EXCEPTION_TENANT_HANDLE_SELF(20402,"不可操作自身"),
/** /**
* *

@ -30,4 +30,14 @@ import org.opsli.modulars.system.tenant.entity.SysTenant;
public interface ITenantService extends CrudServiceInterface<SysTenant, TenantModel> { public interface ITenantService extends CrudServiceInterface<SysTenant, TenantModel> {
/**
*
*
* @param tenantId ID
* @param enable
* @return boolean
*/
boolean enableTenant(String tenantId, String enable);
} }

@ -18,10 +18,12 @@ package org.opsli.modulars.system.tenant.service.impl;
import cn.hutool.core.collection.CollUtil; import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.convert.Convert; import cn.hutool.core.convert.Convert;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.google.common.collect.Lists; import com.google.common.collect.Lists;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
import org.opsli.api.wrapper.system.tenant.TenantModel; 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.constants.MyBatisConstants;
import org.opsli.common.enums.DictType; import org.opsli.common.enums.DictType;
import org.opsli.common.exception.ServiceException; 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.base.service.impl.CrudServiceImpl;
import org.opsli.core.msg.CoreMsg; import org.opsli.core.msg.CoreMsg;
import org.opsli.core.utils.TenantUtil; import org.opsli.core.utils.TenantUtil;
import org.opsli.core.utils.UserUtil;
import org.opsli.modulars.system.SystemMsg; import org.opsli.modulars.system.SystemMsg;
import org.opsli.modulars.system.tenant.entity.SysTenant; import org.opsli.modulars.system.tenant.entity.SysTenant;
import org.opsli.modulars.system.tenant.mapper.TenantMapper; import org.opsli.modulars.system.tenant.mapper.TenantMapper;
@ -60,6 +63,32 @@ public class TenantServiceImpl extends CrudServiceImpl<TenantMapper, SysTenant,
@Autowired @Autowired
private IUserService iUserService; private IUserService iUserService;
@Override
public boolean enableTenant(String tenantId, String enable) {
TenantModel model = this.get(tenantId);
if(model == null){
return false;
}
String currTenantId = UserUtil.getTenantId();
if(StringUtils.equals(currTenantId, tenantId)){
// 不可操作自身
throw new ServiceException(SystemMsg.EXCEPTION_TENANT_HANDLE_SELF);
}
UpdateWrapper<SysTenant> 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 @Override
@Transactional(rollbackFor = Exception.class) @Transactional(rollbackFor = Exception.class)
public TenantModel insert(TenantModel model) { public TenantModel insert(TenantModel model) {

@ -29,12 +29,15 @@ import org.opsli.api.wrapper.system.tenant.TenantModel;
import org.opsli.common.annotation.ApiRestController; import org.opsli.common.annotation.ApiRestController;
import org.opsli.common.annotation.EnableLog; import org.opsli.common.annotation.EnableLog;
import org.opsli.common.annotation.RequiresPermissionsCus; 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.common.utils.WrapperUtil;
import org.opsli.core.base.controller.BaseRestController; import org.opsli.core.base.controller.BaseRestController;
import org.opsli.core.persistence.Page; import org.opsli.core.persistence.Page;
import org.opsli.core.persistence.querybuilder.GenQueryBuilder; import org.opsli.core.persistence.querybuilder.GenQueryBuilder;
import org.opsli.core.persistence.querybuilder.QueryBuilder; import org.opsli.core.persistence.querybuilder.QueryBuilder;
import org.opsli.core.persistence.querybuilder.WebQueryBuilder; 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.entity.SysTenant;
import org.opsli.modulars.system.tenant.service.ITenantService; import org.opsli.modulars.system.tenant.service.ITenantService;
import org.springframework.web.multipart.MultipartHttpServletRequest; import org.springframework.web.multipart.MultipartHttpServletRequest;
@ -58,6 +61,31 @@ public class TenantRestController extends BaseRestController<SysTenant, TenantMo
implements TenantApi { implements TenantApi {
/**
*
* @return ResultVo
*/
@ApiOperation(value = "变更租户状态账户", notes = "变更租户状态账户")
@RequiresPermissions("system_tenant_enable")
@EnableLog
@Override
public ResultVo<?> 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 * @param model

Loading…
Cancel
Save