疯狂的狮子Li
2023-03-27 c00c9ba386b367deb76fa438eaed9ef5dd371d03
ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/controller/system/SysTenantController.java
@@ -4,7 +4,6 @@
import cn.dev33.satoken.annotation.SaCheckRole;
import com.baomidou.lock.annotation.Lock4j;
import com.ruoyi.common.core.constant.TenantConstants;
import com.ruoyi.common.core.constant.UserConstants;
import com.ruoyi.common.core.domain.R;
import com.ruoyi.common.core.exception.ServiceException;
import com.ruoyi.common.core.validate.AddGroup;
@@ -18,7 +17,6 @@
import com.ruoyi.common.tenant.helper.TenantHelper;
import com.ruoyi.common.web.core.BaseController;
import com.ruoyi.system.domain.bo.SysTenantBo;
import com.ruoyi.system.domain.bo.SysUserBo;
import com.ruoyi.system.domain.vo.SysTenantVo;
import com.ruoyi.system.service.ISysTenantService;
import com.ruoyi.system.service.ISysUserService;
@@ -43,8 +41,7 @@
@RequestMapping("/system/tenant")
public class SysTenantController extends BaseController {
    private final ISysTenantService sysTenantService;
    private final ISysUserService sysUserService;
    private final ISysTenantService tenantService;
    /**
     * 查询租户列表
@@ -53,7 +50,7 @@
    @SaCheckPermission("system:tenant:list")
    @GetMapping("/list")
    public TableDataInfo<SysTenantVo> list(SysTenantBo bo, PageQuery pageQuery) {
        return sysTenantService.queryPageList(bo, pageQuery);
        return tenantService.queryPageList(bo, pageQuery);
    }
    /**
@@ -64,7 +61,7 @@
    @Log(title = "租户", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(SysTenantBo bo, HttpServletResponse response) {
        List<SysTenantVo> list = sysTenantService.queryList(bo);
        List<SysTenantVo> list = tenantService.queryList(bo);
        ExcelUtil.exportExcel(list, "租户", SysTenantVo.class, response);
    }
@@ -78,7 +75,7 @@
    @GetMapping("/{id}")
    public R<SysTenantVo> getInfo(@NotNull(message = "主键不能为空")
                                     @PathVariable Long id) {
        return R.ok(sysTenantService.queryById(id));
        return R.ok(tenantService.queryById(id));
    }
    /**
@@ -91,16 +88,10 @@
    @RepeatSubmit()
    @PostMapping()
    public R<Void> add(@Validated(AddGroup.class) @RequestBody SysTenantBo bo) {
        if (TenantConstants.NOT_PASS.equals(sysTenantService.checkCompanyNameUnique(bo))) {
            throw new ServiceException("新增租户'" + bo.getCompanyName() + "'失败,企业名称已存在");
        if (!tenantService.checkCompanyNameUnique(bo)) {
            return R.fail("新增租户'" + bo.getCompanyName() + "'失败,企业名称已存在");
        }
        SysUserBo userBo = new SysUserBo();
        userBo.setUserName(bo.getUsername());
        // 判断用户名是否重复
        if (UserConstants.NOT_UNIQUE.equals(sysUserService.checkUserNameUnique(userBo))) {
            throw new ServiceException("新增用户'" + bo.getUsername() + "'失败,登录账号已存在");
        }
        return toAjax(sysTenantService.insertByBo(bo));
        return toAjax(tenantService.insertByBo(bo));
    }
    /**
@@ -112,21 +103,23 @@
    @RepeatSubmit()
    @PutMapping()
    public R<Void> edit(@Validated(EditGroup.class) @RequestBody SysTenantBo bo) {
        if (UserConstants.NOT_UNIQUE.equals(sysTenantService.checkCompanyNameUnique(bo))) {
            throw new ServiceException("修改租户'" + bo.getCompanyName() + "'失败,公司名称已存在");
        tenantService.checkTenantAllowed(bo.getTenantId());
        if (!tenantService.checkCompanyNameUnique(bo)) {
            return R.fail("修改租户'" + bo.getCompanyName() + "'失败,公司名称已存在");
        }
        return toAjax(sysTenantService.updateByBo(bo));
        return toAjax(tenantService.updateByBo(bo));
    }
    /**
     * 状态修改
     */
    @SaCheckRole(TenantConstants.SUPER_ADMIN_ROLE_KEY)
    @SaCheckPermission("system:tenantPackage:edit")
    @Log(title = "租户套餐", businessType = BusinessType.UPDATE)
    @SaCheckPermission("system:tenant:edit")
    @Log(title = "租户", businessType = BusinessType.UPDATE)
    @PutMapping("/changeStatus")
    public R<Void> changeStatus(@RequestBody SysTenantBo bo) {
        return toAjax(sysTenantService.updateTenantStatus(bo));
        tenantService.checkTenantAllowed(bo.getTenantId());
        return toAjax(tenantService.updateTenantStatus(bo));
    }
    /**
@@ -140,7 +133,7 @@
    @DeleteMapping("/{ids}")
    public R<Void> remove(@NotEmpty(message = "主键不能为空")
                          @PathVariable Long[] ids) {
        return toAjax(sysTenantService.deleteWithValidByIds(List.of(ids), true));
        return toAjax(tenantService.deleteWithValidByIds(List.of(ids), true));
    }
    /**
@@ -165,4 +158,19 @@
        return R.ok();
    }
    /**
     * 同步租户套餐
     *
     * @param tenantId  租户id
     * @param packageId 套餐id
     */
    @SaCheckRole(TenantConstants.SUPER_ADMIN_ROLE_KEY)
    @SaCheckPermission("system:tenant:edit")
    @Log(title = "租户", businessType = BusinessType.UPDATE)
    @GetMapping("/syncTenantPackage")
    public R<Void> syncTenantPackage(@NotBlank(message = "租户ID不能为空") String tenantId, @NotBlank(message = "套餐ID不能为空") String packageId) {
        return toAjax(tenantService.syncTenantPackage(tenantId, packageId));
    }
}