24282 %!s(int64=2) %!d(string=hai) anos
pai
achega
24076a3024

+ 27 - 0
hx-tenant/pom.xml

@@ -0,0 +1,27 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project xmlns="http://maven.apache.org/POM/4.0.0"
+         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+    <modelVersion>4.0.0</modelVersion>
+    <parent>
+        <groupId>com.ruoyi</groupId>
+        <artifactId>ruoyi</artifactId>
+        <version>3.8.5</version>
+    </parent>
+
+    <artifactId>hx-tenant</artifactId>
+
+    <properties>
+        <maven.compiler.source>8</maven.compiler.source>
+        <maven.compiler.target>8</maven.compiler.target>
+        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
+    </properties>
+
+    <dependencies>
+        <dependency>
+            <groupId>com.ruoyi</groupId>
+            <artifactId>ruoyi-framework</artifactId>
+        </dependency>
+    </dependencies>
+
+</project>

+ 76 - 0
hx-tenant/src/main/java/com/fjhx/tenant/controller/tenant/TenantInfoController.java

@@ -0,0 +1,76 @@
+package com.fjhx.tenant.controller.tenant;
+
+import com.baomidou.dynamic.datasource.annotation.DS;
+import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
+import com.fjhx.tenant.entity.tenant.dto.TenantInfoDto;
+import com.fjhx.tenant.entity.tenant.dto.TenantInfoSelectDto;
+import com.fjhx.tenant.entity.tenant.vo.TenantInfoVo;
+import com.fjhx.tenant.service.tenant.TenantInfoService;
+import com.ruoyi.common.annotation.TenantIgnore;
+import com.ruoyi.common.constant.DatasourceConstant;
+import com.ruoyi.common.core.domain.BaseSelectDto;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.web.bind.annotation.PostMapping;
+import org.springframework.web.bind.annotation.RequestBody;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RestController;
+
+
+/**
+ * <p>
+ * 租户表 前端控制器
+ * </p>
+ *
+ * @author zlj
+ * @since 2023-03-15
+ */
+@TenantIgnore
+@DS(DatasourceConstant.SLAVE_NAME)
+@RestController
+@RequestMapping("/tenantInfo")
+public class TenantInfoController {
+
+    @Autowired
+    private TenantInfoService tenantInfoService;
+
+    /**
+     * 租户表分页
+     */
+    @PostMapping("/page")
+    public Page<TenantInfoVo> page(@RequestBody TenantInfoSelectDto dto) {
+        return tenantInfoService.getPage(dto);
+    }
+
+    /**
+     * 租户表明细
+     */
+    @PostMapping("/detail")
+    public TenantInfoVo detail(@RequestBody BaseSelectDto dto) {
+        return tenantInfoService.detail(dto.getId());
+    }
+
+    /**
+     * 租户表新增
+     */
+    @PostMapping("/add")
+    public void add(@RequestBody TenantInfoDto tenantInfoDto) {
+        tenantInfoService.add(tenantInfoDto);
+    }
+
+    /**
+     * 租户表编辑
+     */
+    @PostMapping("/edit")
+    public void edit(@RequestBody TenantInfoDto tenantInfoDto) {
+        tenantInfoService.edit(tenantInfoDto);
+    }
+
+    /**
+     * 租户表删除
+     */
+    @PostMapping("/delete")
+    public void delete(@RequestBody BaseSelectDto dto) {
+        tenantInfoService.delete(dto.getId());
+    }
+
+}

+ 19 - 0
hx-tenant/src/main/java/com/fjhx/tenant/entity/tenant/dto/TenantInfoDto.java

@@ -0,0 +1,19 @@
+package com.fjhx.tenant.entity.tenant.dto;
+
+import com.fjhx.tenant.entity.tenant.po.TenantInfo;
+import lombok.Getter;
+import lombok.Setter;
+
+/**
+ * 租户表新增编辑入参实体
+ *
+ * @author zlj
+ * @since 2023-03-15
+ */
+@Getter
+@Setter
+public class TenantInfoDto extends TenantInfo {
+
+    private String password;
+
+}

+ 37 - 0
hx-tenant/src/main/java/com/fjhx/tenant/entity/tenant/dto/TenantInfoSelectDto.java

@@ -0,0 +1,37 @@
+package com.fjhx.tenant.entity.tenant.dto;
+
+import com.ruoyi.common.core.domain.BaseSelectDto;
+import lombok.Getter;
+import lombok.Setter;
+
+/**
+ * 租户表列表查询入参实体
+ *
+ * @author zlj
+ * @since 2023-03-15
+ */
+@Getter
+@Setter
+public class TenantInfoSelectDto extends BaseSelectDto {
+
+    /**
+     * 租户id
+     */
+    private String tenantId;
+
+    /**
+     * 企业名称
+     */
+    private String enterpriseName;
+
+    /**
+     * 状态 1启用 0禁用
+     */
+    private Integer status;
+
+    /**
+     * 流程状态 1审核中 2审核通过 3审核不通过
+     */
+    private Integer flowStatus;
+
+}

+ 46 - 0
hx-tenant/src/main/java/com/fjhx/tenant/entity/tenant/po/TenantInfo.java

@@ -0,0 +1,46 @@
+package com.fjhx.tenant.entity.tenant.po;
+
+import com.baomidou.mybatisplus.annotation.TableName;
+import com.ruoyi.common.core.domain.BasePo;
+import lombok.Getter;
+import lombok.Setter;
+
+/**
+ * <p>
+ * 租户表
+ * </p>
+ *
+ * @author zlj
+ * @since 2023-03-15
+ */
+@Getter
+@Setter
+@TableName("tenant_info")
+public class TenantInfo extends BasePo {
+
+    /**
+     * 租户id
+     */
+    private String tenantId;
+
+    /**
+     * 企业名称
+     */
+    private String enterpriseName;
+
+    /**
+     * 状态 1启用 0禁用
+     */
+    private Integer status;
+
+    /**
+     * 流程id
+     */
+    private Long flowId;
+
+    /**
+     * 流程状态 1审核中 2审核通过 3审核不通过
+     */
+    private Integer flowStatus;
+
+}

+ 22 - 0
hx-tenant/src/main/java/com/fjhx/tenant/entity/tenant/vo/TenantInfoVo.java

@@ -0,0 +1,22 @@
+package com.fjhx.tenant.entity.tenant.vo;
+
+import com.fjhx.tenant.entity.tenant.po.TenantInfo;
+import lombok.Getter;
+import lombok.Setter;
+
+/**
+ * 租户表列表查询返回值实体
+ *
+ * @author zlj
+ * @since 2023-03-15
+ */
+@Getter
+@Setter
+public class TenantInfoVo extends TenantInfo {
+
+    /**
+     * 账号数量
+     */
+    private Long accountCount;
+
+}

+ 26 - 0
hx-tenant/src/main/java/com/fjhx/tenant/mapper/tenant/TenantInfoMapper.java

@@ -0,0 +1,26 @@
+package com.fjhx.tenant.mapper.tenant;
+
+import com.fjhx.tenant.entity.tenant.po.TenantInfo;
+import com.baomidou.mybatisplus.core.mapper.BaseMapper;
+import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
+import com.fjhx.tenant.entity.tenant.vo.TenantInfoVo;
+import com.ruoyi.common.utils.wrapper.IWrapper;
+import org.apache.ibatis.annotations.Param;
+
+
+/**
+ * <p>
+ * 租户表 Mapper 接口
+ * </p>
+ *
+ * @author zlj
+ * @since 2023-03-15
+ */
+public interface TenantInfoMapper extends BaseMapper<TenantInfo> {
+
+    /**
+     * 租户表分页
+     */
+    Page<TenantInfoVo> getPage(@Param("page") Page<Object> page, @Param("ew") IWrapper<TenantInfo> wrapper);
+
+}

+ 46 - 0
hx-tenant/src/main/java/com/fjhx/tenant/service/tenant/TenantInfoService.java

@@ -0,0 +1,46 @@
+package com.fjhx.tenant.service.tenant;
+
+import com.fjhx.tenant.entity.tenant.po.TenantInfo;
+import com.ruoyi.common.core.service.BaseService;
+import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
+import com.fjhx.tenant.entity.tenant.vo.TenantInfoVo;
+import com.fjhx.tenant.entity.tenant.dto.TenantInfoSelectDto;
+import com.fjhx.tenant.entity.tenant.dto.TenantInfoDto;
+
+
+/**
+ * <p>
+ * 租户表 服务类
+ * </p>
+ *
+ * @author zlj
+ * @since 2023-03-15
+ */
+public interface TenantInfoService extends BaseService<TenantInfo> {
+
+    /**
+     * 租户表分页
+     */
+    Page<TenantInfoVo> getPage(TenantInfoSelectDto dto);
+
+    /**
+     * 租户表明细
+     */
+    TenantInfoVo detail(Long id);
+
+    /**
+     * 租户表新增
+     */
+    void add(TenantInfoDto tenantInfoDto);
+
+    /**
+     * 租户表编辑
+     */
+    void edit(TenantInfoDto tenantInfoDto);
+
+    /**
+     * 租户表删除
+     */
+    void delete(Long id);
+
+}

+ 157 - 0
hx-tenant/src/main/java/com/fjhx/tenant/service/tenant/impl/TenantInfoServiceImpl.java

@@ -0,0 +1,157 @@
+package com.fjhx.tenant.service.tenant.impl;
+
+import cn.hutool.core.bean.BeanUtil;
+import cn.hutool.core.util.ObjectUtil;
+import com.baomidou.mybatisplus.core.toolkit.Wrappers;
+import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
+import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
+import com.fjhx.tenant.entity.tenant.dto.TenantInfoDto;
+import com.fjhx.tenant.entity.tenant.dto.TenantInfoSelectDto;
+import com.fjhx.tenant.entity.tenant.po.TenantInfo;
+import com.fjhx.tenant.entity.tenant.vo.TenantInfoVo;
+import com.fjhx.tenant.mapper.tenant.TenantInfoMapper;
+import com.fjhx.tenant.service.tenant.TenantInfoService;
+import com.ruoyi.common.core.domain.entity.SysDept;
+import com.ruoyi.common.core.domain.entity.SysRole;
+import com.ruoyi.common.core.domain.entity.SysUser;
+import com.ruoyi.common.exception.ServiceException;
+import com.ruoyi.common.utils.SecurityUtils;
+import com.ruoyi.common.utils.wrapper.IWrapper;
+import com.ruoyi.common.utils.wrapper.SqlField;
+import com.ruoyi.system.service.ISysDeptService;
+import com.ruoyi.system.service.ISysRoleService;
+import com.ruoyi.system.service.ISysUserService;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
+import org.springframework.transaction.annotation.Transactional;
+
+import java.util.Date;
+import java.util.List;
+import java.util.Map;
+import java.util.stream.Collectors;
+
+
+/**
+ * <p>
+ * 租户表 服务实现类
+ * </p>
+ *
+ * @author zlj
+ * @since 2023-03-15
+ */
+@Service
+public class TenantInfoServiceImpl extends ServiceImpl<TenantInfoMapper, TenantInfo> implements TenantInfoService {
+
+    @Autowired
+    private ISysUserService sysUserService;
+
+    @Autowired
+    private ISysDeptService sysDeptService;
+
+    @Autowired
+    private ISysRoleService sysRoleService;
+
+    public Page<TenantInfoVo> getPage(TenantInfoSelectDto dto) {
+        IWrapper<TenantInfo> wrapper = getWrapper();
+        wrapper.orderByDesc("ti", TenantInfo::getId)
+                .eq("ti", TenantInfo::getStatus, dto.getStatus())
+                .eq("ti", TenantInfo::getFlowStatus, dto.getFlowStatus())
+                .like("ti", TenantInfo::getTenantId, dto.getTenantId())
+                .like("ti", TenantInfo::getEnterpriseName, dto.getEnterpriseName())
+                .keyword(dto,
+                        new SqlField("ti", TenantInfo::getEnterpriseName),
+                        new SqlField("ti", TenantInfo::getTenantId)
+                );
+
+        Page<TenantInfoVo> page = this.baseMapper.getPage(dto.getPage(), wrapper);
+        List<TenantInfoVo> records = page.getRecords();
+
+        if (records.size() == 0) {
+            return page;
+        }
+
+        List<String> tenantIdList = records.stream().map(TenantInfo::getTenantId).collect(Collectors.toList());
+
+        // 赋值创建账号数
+        List<Map<String, Object>> list = sysUserService.listMaps(Wrappers.<SysUser>query()
+                .select("count(0) count", "tenant_id tenantId")
+                .in("tenant_id", tenantIdList)
+                .groupBy("tenant_id")
+        );
+        Map<String, Long> tenantCountMap = list.stream().collect(Collectors.toMap(
+                item -> (String) item.get("tenantId"),
+                item -> (Long) item.get("count")
+        ));
+        for (TenantInfoVo record : records) {
+            String tenantId = record.getTenantId();
+            Long count = ObjectUtil.defaultIfNull(tenantCountMap.get(tenantId), 0L);
+            record.setAccountCount(count);
+        }
+
+        return page;
+    }
+
+    public TenantInfoVo detail(Long id) {
+        TenantInfo TenantInfo = this.getById(id);
+        TenantInfoVo result = BeanUtil.toBean(TenantInfo, TenantInfoVo.class);
+        return result;
+    }
+
+    @Transactional
+    public void add(TenantInfoDto tenantInfoDto) {
+        TenantInfo tenantInfo = getOne(q -> q.eq(TenantInfo::getTenantId, tenantInfoDto.getTenantId()));
+        if (tenantInfo != null) {
+            throw new ServiceException("租户已存在");
+        }
+
+        // TODO 审核通过
+        tenantInfoDto.setFlowStatus(2);
+        this.save(tenantInfoDto);
+
+        SysDept sysDept = new SysDept();
+        sysDept.setParentId(0L);
+        sysDept.setDeptName(tenantInfoDto.getEnterpriseName());
+        sysDept.setOrderNum(1);
+        sysDept.setStatus("0");
+        sysDept.setTenantId(tenantInfoDto.getTenantId());
+        sysDept.setCreateBy(SecurityUtils.getUsername());
+        sysDept.setCreateTime(new Date());
+        sysDeptService.save(sysDept);
+
+        SysUser sysUser = new SysUser();
+        sysUser.setDeptId(sysDept.getDeptId());
+        sysUser.setTenantId(tenantInfoDto.getTenantId());
+        sysUser.setUserName("admin");
+        sysUser.setNickName("管理员");
+        sysUser.setPassword(SecurityUtils.encryptPassword(tenantInfoDto.getPassword()));
+        sysUser.setStatus("0");
+        sysUser.setCreateBy(SecurityUtils.getUsername());
+        sysUser.setCreateTime(new Date());
+        sysUserService.save(sysUser);
+
+        SysRole sysRole = new SysRole();
+        sysRole.setRoleName("管理员");
+        sysRole.setRoleKey("admin");
+        sysRole.setRoleSort(1);
+        sysRole.setDataScope("1");
+        sysRole.setStatus("0");
+        sysRole.setTenantId(tenantInfoDto.getTenantId());
+        sysRole.setCreateBy(SecurityUtils.getUsername());
+        sysRole.setCreateTime(new Date());
+        sysRoleService.save(sysRole);
+
+        sysRoleService.insertAuthUsers(sysRole.getRoleId(), new Long[]{sysUser.getUserId()});
+    }
+
+    public void edit(TenantInfoDto tenantInfoDto) {
+        // 租户id不允许修改
+        tenantInfoDto.setTenantId(null);
+
+        this.updateById(tenantInfoDto);
+    }
+
+    public void delete(Long id) {
+        this.removeById(id);
+    }
+
+}

+ 19 - 0
hx-tenant/src/main/resources/mapper/tenant/TenantInfoMapper.xml

@@ -0,0 +1,19 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
+<mapper namespace="com.fjhx.tenant.mapper.tenant.TenantInfoMapper">
+    <select id="getPage" resultType="com.fjhx.tenant.entity.tenant.vo.TenantInfoVo">
+        select ti.id,
+               ti.tenant_id,
+               ti.enterprise_name,
+               ti.status,
+               ti.flow_id,
+               ti.flow_status,
+               ti.create_user,
+               ti.create_time,
+               ti.update_user,
+               ti.update_time
+        from tenant_info ti
+            ${ew.customSqlSegment}
+    </select>
+
+</mapper>