测试环境配置及带租房的登录功能
This commit is contained in:
@@ -3,7 +3,6 @@ package com.zf.foodpurchase.fdsafe.vo;
|
||||
import com.zf.foodpurchase.common.valigroud.UpdateGroup;
|
||||
import com.zf.foodpurchase.common.vo.CommonVO;
|
||||
import lombok.Data;
|
||||
import org.w3c.dom.stylesheets.LinkStyle;
|
||||
|
||||
import javax.validation.constraints.NotBlank;
|
||||
import java.io.Serializable;
|
||||
|
||||
@@ -0,0 +1,103 @@
|
||||
package com.zf.foodpurchase.system.domain;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.TableId;
|
||||
import com.baomidou.mybatisplus.annotation.TableLogic;
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import com.zf.foodpurchase.common.core.domain.BaseEntity;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
/**
|
||||
* 租户对象 sys_tenant
|
||||
*
|
||||
* @author Michelle.Chung
|
||||
*/
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
@TableName("sys_tenant")
|
||||
public class SysTenant extends BaseEntity {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
/**
|
||||
* id
|
||||
*/
|
||||
@TableId(value = "id")
|
||||
private Long id;
|
||||
|
||||
/**
|
||||
* 租户编号
|
||||
*/
|
||||
private String tenantId;
|
||||
|
||||
/**
|
||||
* 联系人
|
||||
*/
|
||||
private String contactUserName;
|
||||
|
||||
/**
|
||||
* 联系电话
|
||||
*/
|
||||
private String contactPhone;
|
||||
|
||||
/**
|
||||
* 企业名称
|
||||
*/
|
||||
private String companyName;
|
||||
|
||||
/**
|
||||
* 统一社会信用代码
|
||||
*/
|
||||
private String licenseNumber;
|
||||
|
||||
/**
|
||||
* 地址
|
||||
*/
|
||||
private String address;
|
||||
|
||||
/**
|
||||
* 域名
|
||||
*/
|
||||
private String domain;
|
||||
|
||||
/**
|
||||
* 企业简介
|
||||
*/
|
||||
private String intro;
|
||||
|
||||
/**
|
||||
* 备注
|
||||
*/
|
||||
private String remark;
|
||||
|
||||
/**
|
||||
* 租户套餐编号
|
||||
*/
|
||||
private Long packageId;
|
||||
|
||||
/**
|
||||
* 过期时间
|
||||
*/
|
||||
private Date expireTime;
|
||||
|
||||
/**
|
||||
* 用户数量(-1不限制)
|
||||
*/
|
||||
private Long accountCount;
|
||||
|
||||
/**
|
||||
* 租户状态(0正常 1停用)
|
||||
*/
|
||||
private String status;
|
||||
|
||||
/**
|
||||
* 删除标志(0代表存在 1代表删除)
|
||||
*/
|
||||
@TableLogic
|
||||
private String delFlag;
|
||||
|
||||
private Long createDept;
|
||||
|
||||
}
|
||||
@@ -0,0 +1,71 @@
|
||||
package com.zf.foodpurchase.system.domain;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.TableId;
|
||||
import com.baomidou.mybatisplus.annotation.TableLogic;
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import com.zf.foodpurchase.common.core.domain.BaseEntity;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
|
||||
/**
|
||||
* 租户套餐对象 sys_tenant_package
|
||||
*
|
||||
* @author Michelle.Chung
|
||||
*/
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
@TableName("sys_tenant_package")
|
||||
public class SysTenantPackage extends BaseEntity {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
/**
|
||||
* 租户套餐id
|
||||
*/
|
||||
@TableId(value = "package_id")
|
||||
private Long packageId;
|
||||
|
||||
/**
|
||||
* 套餐名称
|
||||
*/
|
||||
private String packageName;
|
||||
|
||||
/**
|
||||
* 关联菜单id
|
||||
*/
|
||||
private String menuIds;
|
||||
|
||||
/**
|
||||
* 备注
|
||||
*/
|
||||
private String remark;
|
||||
|
||||
/**
|
||||
* 菜单树选择项是否关联显示( 0:父子不互相关联显示 1:父子互相关联显示)
|
||||
*/
|
||||
private Boolean menuCheckStrictly;
|
||||
|
||||
/**
|
||||
* 状态(0正常 1停用)
|
||||
*/
|
||||
private String status;
|
||||
|
||||
/**
|
||||
* 删除标志(0代表存在 1代表删除)
|
||||
*/
|
||||
@TableLogic
|
||||
private String delFlag;
|
||||
|
||||
private Long createDept;
|
||||
|
||||
private String createBy;
|
||||
|
||||
private Date createTime;
|
||||
|
||||
private String updateBy;
|
||||
|
||||
private Date updateTime;
|
||||
}
|
||||
@@ -0,0 +1,50 @@
|
||||
package com.zf.foodpurchase.system.domain.vo;
|
||||
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
|
||||
/**
|
||||
* 租户套餐视图对象 sys_tenant_package
|
||||
*
|
||||
* @author Michelle.Chung
|
||||
*/
|
||||
@Data
|
||||
public class SysTenantPackageVo implements Serializable {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
/**
|
||||
* 租户套餐id
|
||||
*/
|
||||
private Long packageId;
|
||||
|
||||
/**
|
||||
* 套餐名称
|
||||
*/
|
||||
private String packageName;
|
||||
|
||||
/**
|
||||
* 关联菜单id
|
||||
*/
|
||||
private String menuIds;
|
||||
|
||||
/**
|
||||
* 备注
|
||||
*/
|
||||
private String remark;
|
||||
|
||||
/**
|
||||
* 菜单树选择项是否关联显示
|
||||
*/
|
||||
private Boolean menuCheckStrictly;
|
||||
|
||||
/**
|
||||
* 状态(0正常 1停用)
|
||||
*/
|
||||
private String status;
|
||||
|
||||
|
||||
}
|
||||
@@ -115,4 +115,12 @@ public interface SysDeptMapper
|
||||
* @return 结果
|
||||
*/
|
||||
public int deleteDeptById(Long deptId);
|
||||
|
||||
public int updateDeptByTenantId(@Param("dept") SysDept dept, @Param("tenantId") String tenantId);
|
||||
|
||||
public List<SysDept> selectByTenantId(@Param("tenantId") String tenantId);
|
||||
|
||||
public void updateTenantId(@Param("deptIds") List<Long> deptIds, @Param("tenantId") String tenantId);
|
||||
|
||||
public List<Long> selectAllZSByDeptId(Long deptId);
|
||||
}
|
||||
|
||||
@@ -104,4 +104,6 @@ public interface SysRoleMapper
|
||||
* @return 结果
|
||||
*/
|
||||
public int deleteRoleByIds(Long[] roleIds);
|
||||
|
||||
public List<SysRole> selectRolesByTenantId(String tenantId);
|
||||
}
|
||||
|
||||
@@ -2,6 +2,7 @@ package com.zf.foodpurchase.system.mapper;
|
||||
|
||||
import java.util.List;
|
||||
import com.zf.foodpurchase.system.domain.SysRoleMenu;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
|
||||
/**
|
||||
* 角色与菜单关联表 数据层
|
||||
@@ -41,4 +42,6 @@ public interface SysRoleMenuMapper
|
||||
* @return 结果
|
||||
*/
|
||||
public int batchRoleMenu(List<SysRoleMenu> roleMenuList);
|
||||
|
||||
public int deleteRoleMenuForSync(@Param("roleIds") List<Long> roleIds, @Param("menuIds") List<Long> menuIds);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,35 @@
|
||||
package com.zf.foodpurchase.system.mapper;
|
||||
|
||||
import com.zf.foodpurchase.common.core.domain.entity.SysTenantBo;
|
||||
import com.zf.foodpurchase.common.core.domain.entity.SysTenantVo;
|
||||
import com.zf.foodpurchase.system.domain.SysTenant;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Mapper
|
||||
public interface SysTenantMapper {
|
||||
|
||||
public SysTenantVo queryById(Long id);
|
||||
|
||||
public List<SysTenantVo> queryByCondition(SysTenantBo bo);
|
||||
|
||||
public int deleteByIds(@Param("ids") List<Long> ids);
|
||||
|
||||
public int updateById(SysTenant sysTenant);
|
||||
|
||||
public int insert(SysTenant sysTenant);
|
||||
|
||||
public SysTenantVo queryByTenantId(String tenantId);
|
||||
|
||||
public List<String> selectObjs();
|
||||
|
||||
public List<SysTenantVo> queryByPackageIds(@Param("packageIds") List<Long> packageIds);
|
||||
|
||||
public List<SysTenantVo> queryByCompanyName(String companyName);
|
||||
|
||||
public List<SysTenantVo> queryByPhone(String phone);
|
||||
|
||||
public List<SysTenantVo> queryByTenantIds(@Param("tenantIds") List<String> tenantIds);
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
package com.zf.foodpurchase.system.mapper;
|
||||
|
||||
|
||||
import com.zf.foodpurchase.common.core.domain.entity.SysTenantPackageBo;
|
||||
import com.zf.foodpurchase.system.domain.SysTenantPackage;
|
||||
import com.zf.foodpurchase.system.domain.vo.SysTenantPackageVo;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Mapper
|
||||
public interface SysTenantPackageMapper {
|
||||
|
||||
public SysTenantPackageVo selectById(Long packageId);
|
||||
|
||||
public List<SysTenantPackageVo> selectList(SysTenantPackageBo sysTenantPackageBo);
|
||||
|
||||
public int insert(SysTenantPackage sysTenantPackage);
|
||||
|
||||
public int update(SysTenantPackage sysTenantPackage);
|
||||
|
||||
public int deleteByIds(@Param("packageIds") List<Long> packageIds);
|
||||
}
|
||||
@@ -124,4 +124,14 @@ public interface SysUserMapper
|
||||
* @return 结果
|
||||
*/
|
||||
public SysUser checkEmailUnique(String email);
|
||||
|
||||
|
||||
int unableUser(@Param("userIds") List<Long> userIds,@Param("statusChar") String statusChar);
|
||||
|
||||
List<Long> selectUserIdsByTenantId(@Param("tenantId") String tenantId);
|
||||
|
||||
int updateTenantIdOfUsers(@Param("deptIds") List<Long> deptIds,@Param("tenantId") String tenantId);
|
||||
|
||||
SysUser selectUserByUserNameAndTenantId(@Param("userName") String userName,@Param("tenantId") String tenantId);
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,86 @@
|
||||
package com.zf.foodpurchase.system.service;
|
||||
|
||||
|
||||
|
||||
import com.zf.foodpurchase.common.core.domain.AjaxResult;
|
||||
import com.zf.foodpurchase.common.core.domain.entity.SysTenantBo;
|
||||
import com.zf.foodpurchase.common.core.domain.entity.SysTenantVo;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 租户Service接口
|
||||
*
|
||||
* @author Michelle.Chung
|
||||
*/
|
||||
public interface ISysTenantService {
|
||||
|
||||
/**
|
||||
* 查询租户
|
||||
*/
|
||||
SysTenantVo queryById(Long id);
|
||||
|
||||
/**
|
||||
* 基于租户ID查询租户
|
||||
*/
|
||||
SysTenantVo queryByTenantId(String tenantId);
|
||||
|
||||
/**
|
||||
* 查询租户列表
|
||||
*/
|
||||
AjaxResult queryPageList(SysTenantBo bo, Integer page, Integer pageSize);
|
||||
|
||||
/**
|
||||
* 查询租户列表
|
||||
*/
|
||||
AjaxResult queryList(SysTenantBo bo);
|
||||
|
||||
/**
|
||||
* 新增租户
|
||||
*/
|
||||
Boolean insertByBo(SysTenantBo bo);
|
||||
|
||||
/**
|
||||
* 修改租户
|
||||
*/
|
||||
Boolean updateByBo(SysTenantBo bo);
|
||||
|
||||
|
||||
/**
|
||||
* 校验租户是否允许操作
|
||||
*/
|
||||
void checkTenantAllowed(String tenantId);
|
||||
|
||||
/**
|
||||
* 校验并批量删除租户信息
|
||||
*/
|
||||
Boolean deleteWithValidByIds(List<Long> ids, Boolean isValid);
|
||||
|
||||
/**
|
||||
* 校验企业名称是否唯一
|
||||
*/
|
||||
boolean checkCompanyNameUnique(SysTenantBo bo);
|
||||
|
||||
/**
|
||||
* 校验联系方式是否唯一
|
||||
*/
|
||||
boolean checkPhoneUnique(SysTenantBo bo);
|
||||
|
||||
/**
|
||||
* 校验用户名是否唯一
|
||||
*/
|
||||
boolean checkUsername(SysTenantBo bo);
|
||||
|
||||
/**
|
||||
* 校验有效期
|
||||
*/
|
||||
boolean checkExpireTime(String tenantId);
|
||||
|
||||
/**
|
||||
* 修改租户状态
|
||||
*/
|
||||
int updateTenantStatus(SysTenantBo bo);
|
||||
|
||||
Boolean deptToTenant(SysTenantBo bo);
|
||||
|
||||
}
|
||||
@@ -0,0 +1,492 @@
|
||||
package com.zf.foodpurchase.system.service.impl;
|
||||
|
||||
import cn.hutool.core.bean.BeanUtil;
|
||||
import cn.hutool.core.collection.CollectionUtil;
|
||||
import cn.hutool.core.convert.Convert;
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
import cn.hutool.core.util.RandomUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import cn.hutool.crypto.digest.BCrypt;
|
||||
import com.github.pagehelper.PageHelper;
|
||||
import com.github.pagehelper.PageInfo;
|
||||
import com.zf.foodpurchase.common.constant.TenantConstants;
|
||||
import com.zf.foodpurchase.common.core.domain.AjaxResult;
|
||||
import com.zf.foodpurchase.common.core.domain.entity.*;
|
||||
import com.zf.foodpurchase.common.core.domain.model.LoginUser;
|
||||
import com.zf.foodpurchase.common.exception.ServiceException;
|
||||
import com.zf.foodpurchase.common.utils.PageResult;
|
||||
import com.zf.foodpurchase.common.utils.SecurityUtils;
|
||||
import com.zf.foodpurchase.common.utils.StringUtils;
|
||||
import com.zf.foodpurchase.common.utils.spring.SpringUtils;
|
||||
import com.zf.foodpurchase.system.domain.SysRoleDept;
|
||||
import com.zf.foodpurchase.system.domain.SysRoleMenu;
|
||||
import com.zf.foodpurchase.system.domain.SysTenant;
|
||||
import com.zf.foodpurchase.system.domain.SysUserRole;
|
||||
import com.zf.foodpurchase.system.domain.vo.SysTenantPackageVo;
|
||||
import com.zf.foodpurchase.system.mapper.*;
|
||||
import com.zf.foodpurchase.system.service.ISysTenantService;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* 租户Service业务层处理
|
||||
*
|
||||
* @author Michelle.Chung
|
||||
*/
|
||||
@RequiredArgsConstructor
|
||||
@Service
|
||||
public class SysTenantServiceImpl implements ISysTenantService {
|
||||
|
||||
private final SysTenantMapper baseMapper;
|
||||
private final SysTenantPackageMapper tenantPackageMapper;
|
||||
private final SysUserMapper userMapper;
|
||||
private final SysDeptMapper deptMapper;
|
||||
private final SysRoleMapper roleMapper;
|
||||
private final SysRoleMenuMapper roleMenuMapper;
|
||||
private final SysRoleDeptMapper roleDeptMapper;
|
||||
private final SysUserRoleMapper userRoleMapper;
|
||||
private final SysTenantMapper sysTenantMapper;
|
||||
private final SysUserMapper sysUserMapper;
|
||||
private final SysDeptMapper sysDeptMapper;
|
||||
|
||||
/**
|
||||
* 查询租户
|
||||
*/
|
||||
@Override
|
||||
public SysTenantVo queryById(Long id) {
|
||||
SysTenantVo sysTenantVo = baseMapper.queryById(id);
|
||||
return sysTenantVo;
|
||||
}
|
||||
|
||||
/**
|
||||
* 基于租户ID查询租户
|
||||
*/
|
||||
@Override
|
||||
public SysTenantVo queryByTenantId(String tenantId) {
|
||||
return baseMapper.queryByTenantId(tenantId);
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询租户列表
|
||||
*/
|
||||
@Override
|
||||
public AjaxResult queryPageList(SysTenantBo bo, Integer page, Integer pageSize) {
|
||||
PageHelper.startPage(page, pageSize);
|
||||
List<SysTenantVo> sysTenantVos = baseMapper.queryByCondition(bo);
|
||||
PageInfo<SysTenantVo> pageInfo = new PageInfo<>(sysTenantVos);
|
||||
PageResult result = new PageResult();
|
||||
result.setPageIndex(page);
|
||||
result.setPages(pageInfo.getPages());
|
||||
result.setTotles(pageInfo.getTotal());
|
||||
result.setResult(sysTenantVos);
|
||||
return AjaxResult.success(result);
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询租户列表
|
||||
*/
|
||||
@Override
|
||||
public AjaxResult queryList(SysTenantBo bo) {
|
||||
List<SysTenantVo> sysTenantVos = baseMapper.queryByCondition(bo);
|
||||
return AjaxResult.success(sysTenantVos);
|
||||
}
|
||||
/**
|
||||
* 新增租户
|
||||
*/
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public Boolean insertByBo(SysTenantBo bo) {
|
||||
Date date = new Date();
|
||||
LoginUser loginUser = (LoginUser) SecurityUtils.getLoginUser();
|
||||
SysTenant add = BeanUtil.toBean(bo, SysTenant.class);
|
||||
// 获取所有租户编号
|
||||
List<String> tenantIds = baseMapper.selectObjs();
|
||||
String tenantId = generateTenantId(tenantIds);
|
||||
add.setTenantId(tenantId);
|
||||
add.setCreateDept(bo.getDeptId());
|
||||
add.setCreateTime(new Date());
|
||||
add.setCreateBy(loginUser.getUserId()+"");
|
||||
add.setStatus("0");
|
||||
boolean flag = baseMapper.insert(add) > 0;
|
||||
if (!flag) {
|
||||
throw new ServiceException("创建租户失败");
|
||||
}
|
||||
bo.setId(add.getId());
|
||||
|
||||
// 根据套餐创建角色
|
||||
Long roleId = createTenantRole(tenantId, bo.getPackageId(),bo.getCompanyName());
|
||||
|
||||
// 创建部门: 公司名是部门名称
|
||||
SysDept dept = new SysDept();
|
||||
dept.setTenantId(tenantId);
|
||||
dept.setDeptName(bo.getCompanyName());
|
||||
if(!ObjectUtil.isEmpty(bo.getDeptId())){
|
||||
dept.setParentId(bo.getDeptId());
|
||||
SysDept parentDept = deptMapper.selectDeptById(bo.getDeptId());
|
||||
String ancestors = parentDept.getAncestors()+","+bo.getDeptId();
|
||||
dept.setAncestors(ancestors);
|
||||
}else{
|
||||
dept.setParentId(0L);
|
||||
dept.setAncestors("0");
|
||||
}
|
||||
dept.setIsTenant("1");
|
||||
dept.setCreateTime(date);
|
||||
dept.setStatus("0");
|
||||
dept.setDelFlag("0");
|
||||
deptMapper.insertDept(dept);
|
||||
Long deptId = dept.getDeptId();
|
||||
// 角色和部门关联表
|
||||
SysRoleDept roleDept = new SysRoleDept();
|
||||
roleDept.setRoleId(roleId);
|
||||
roleDept.setDeptId(deptId);
|
||||
roleDeptMapper.batchRoleDept(Arrays.asList(roleDept));
|
||||
|
||||
// 创建系统用户
|
||||
SysUser user = new SysUser();
|
||||
user.setTenantId(tenantId);
|
||||
user.setUserName(bo.getUsername());
|
||||
user.setNickName(bo.getUsername());
|
||||
user.setPassword(BCrypt.hashpw(bo.getPassword()));
|
||||
user.setDeptId((long) deptId);
|
||||
user.setCreateTime(date);
|
||||
user.setUpdateTime(date);
|
||||
user.setDelFlag("0");
|
||||
user.setPhonenumber(bo.getContactPhone());
|
||||
user.setStatus("0");
|
||||
userMapper.insertUser(user);
|
||||
//新增系统用户后,默认当前用户为部门的负责人
|
||||
SysDept sd = new SysDept();
|
||||
sd.setLeader(user.getUserName().toString());
|
||||
sd.setDeptId(deptId);
|
||||
deptMapper.updateDept(sd);
|
||||
|
||||
// 用户和角色关联表
|
||||
SysUserRole userRole = new SysUserRole();
|
||||
userRole.setUserId(user.getUserId());
|
||||
userRole.setRoleId(roleId);
|
||||
userRoleMapper.batchUserRole(Arrays.asList(userRole));
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* 生成租户id
|
||||
*
|
||||
* @param tenantIds 已有租户id列表
|
||||
* @return 租户id
|
||||
*/
|
||||
private String generateTenantId(List<String> tenantIds) {
|
||||
// 随机生成6位
|
||||
String numbers = RandomUtil.randomNumbers(6);
|
||||
// 判断是否存在,如果存在则重新生成
|
||||
if (tenantIds.contains(numbers)) {
|
||||
return generateTenantId(tenantIds);
|
||||
}
|
||||
return numbers;
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据租户菜单创建租户角色
|
||||
*
|
||||
* @param tenantId 租户编号
|
||||
* @param packageId 租户套餐id
|
||||
* @return 角色id
|
||||
*/
|
||||
private Long createTenantRole(String tenantId, Long packageId, String companyName) {
|
||||
// 获取租户套餐
|
||||
SysTenantPackageVo tenantPackageVo = tenantPackageMapper.selectById(packageId);
|
||||
if (ObjectUtil.isNull(tenantPackageVo)) {
|
||||
throw new ServiceException("套餐不存在");
|
||||
}
|
||||
// 获取套餐菜单id
|
||||
List<Long> menuIds = StrUtil.split(tenantPackageVo.getMenuIds(), ',')
|
||||
.stream()
|
||||
.filter(Objects::nonNull)
|
||||
.map(Convert::toLong)
|
||||
.filter(Objects::nonNull)
|
||||
.collect(Collectors.toList());
|
||||
|
||||
// 创建角色
|
||||
SysRole role = new SysRole();
|
||||
role.setTenantId(tenantId);
|
||||
role.setRoleName(companyName+ TenantConstants.TENANT_ADMIN_ROLE_NAME);
|
||||
role.setRoleKey(TenantConstants.TENANT_ADMIN_ROLE_KEY + "_" + tenantId);
|
||||
role.setRoleSort(1);
|
||||
role.setStatus("0");
|
||||
roleMapper.insertRole(role);
|
||||
Long roleId = role.getRoleId();
|
||||
|
||||
// 创建角色菜单
|
||||
List<SysRoleMenu> roleMenus = new ArrayList<>(menuIds.size());
|
||||
menuIds.forEach(menuId -> {
|
||||
SysRoleMenu roleMenu = new SysRoleMenu();
|
||||
roleMenu.setRoleId(roleId);
|
||||
roleMenu.setMenuId(menuId);
|
||||
roleMenus.add(roleMenu);
|
||||
});
|
||||
if(roleMenus.size() > 0) {
|
||||
roleMenuMapper.batchRoleMenu(roleMenus);
|
||||
}
|
||||
|
||||
return roleId;
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改租户
|
||||
*/
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public Boolean updateByBo(SysTenantBo bo) {
|
||||
LoginUser loginUser = (LoginUser) SecurityUtils.getLoginUser();
|
||||
SysTenant tenant = new SysTenant();
|
||||
BeanUtil.copyProperties(bo, tenant);
|
||||
|
||||
if(!ObjectUtil.isEmpty(bo.getDeptId())){ //非租户部门
|
||||
SysDept currentDept = new SysDept();
|
||||
currentDept.setParentId(bo.getDeptId());
|
||||
SysDept parentDept = deptMapper.selectDeptById(bo.getDeptId());
|
||||
String ancestors = parentDept.getAncestors()+","+bo.getDeptId();
|
||||
currentDept.setAncestors(ancestors);
|
||||
currentDept.setDeptName(bo.getCompanyName());
|
||||
deptMapper.updateDeptByTenantId(currentDept, tenant.getTenantId());
|
||||
}else{
|
||||
List<SysDept> currentDepts = deptMapper.selectByTenantId(tenant.getTenantId());
|
||||
SysDept tenantDept = currentDepts.stream().filter(f -> StringUtils.equals(f.getLeader(),"admin")).findFirst().orElse(null);
|
||||
if(!ObjectUtil.isNull(tenantDept)){
|
||||
tenantDept.setDeptName(bo.getCompanyName());
|
||||
deptMapper.updateDept(tenantDept);
|
||||
}
|
||||
}
|
||||
SysTenantVo original = sysTenantMapper.queryById(bo.getId());
|
||||
if(!ObjectUtil.equal(original.getPackageId(), bo.getPackageId())){
|
||||
syncTenantPackage(bo.getTenantId(),bo.getPackageId());
|
||||
}
|
||||
if(!ObjectUtil.equal(original.getCreateDept(), bo.getDeptId())){
|
||||
tenant.setCreateDept(bo.getDeptId());
|
||||
}
|
||||
tenant.setCreateDept(bo.getDeptId());
|
||||
tenant.setUpdateBy(loginUser.getUserId()+"");
|
||||
return baseMapper.updateById(tenant) > 0;
|
||||
}
|
||||
|
||||
public Boolean syncTenantPackage(String tenantId, Long packageId) {
|
||||
SysTenantPackageVo tenantPackageVO = tenantPackageMapper.selectById(packageId);
|
||||
List<SysRole> roles = roleMapper.selectRolesByTenantId(tenantId);
|
||||
List<Long> roleIds = new ArrayList<>(roles.size() - 1);
|
||||
List<Long> menuIds = StringUtils.commaStrToLongList(tenantPackageVO.getMenuIds());
|
||||
roles.forEach(item -> {
|
||||
if (item.getRoleKey().contains(TenantConstants.TENANT_ADMIN_ROLE_KEY)) {
|
||||
List<SysRoleMenu> roleMenus = new ArrayList<>(menuIds.size());
|
||||
menuIds.forEach(menuId -> {
|
||||
SysRoleMenu roleMenu = new SysRoleMenu();
|
||||
roleMenu.setRoleId(item.getRoleId());
|
||||
roleMenu.setMenuId(menuId);
|
||||
roleMenus.add(roleMenu);
|
||||
});
|
||||
roleMenuMapper.deleteRoleMenuByRoleId(item.getRoleId());
|
||||
roleMenuMapper.batchRoleMenu(roleMenus);
|
||||
} else {
|
||||
roleIds.add(item.getRoleId());
|
||||
}
|
||||
});
|
||||
if (!roleIds.isEmpty()) {
|
||||
roleMenuMapper.deleteRoleMenuForSync(roleIds, menuIds);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 校验租户是否允许操作
|
||||
*
|
||||
* @param tenantId 租户ID
|
||||
*/
|
||||
@Override
|
||||
public void checkTenantAllowed(String tenantId) {
|
||||
if (ObjectUtil.isNotNull(tenantId) && TenantConstants.DEFAULT_TENANT_ID.equals(tenantId)) {
|
||||
throw new ServiceException("不允许操作管理租户");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 批量删除租户
|
||||
*/
|
||||
@Override
|
||||
public Boolean deleteWithValidByIds(List<Long> ids, Boolean isValid) {
|
||||
if (isValid) {
|
||||
// 做一些业务上的校验,判断是否需要校验
|
||||
if (ids.contains(TenantConstants.SUPER_ADMIN_ID)) {
|
||||
throw new ServiceException("超管租户不能删除");
|
||||
}
|
||||
}
|
||||
boolean i = baseMapper.deleteByIds(ids)>0;
|
||||
List<SysDept> sysDepts = new ArrayList<>();
|
||||
for(Long id:ids){
|
||||
SysTenantVo sysTenantVo = sysTenantMapper.queryById(id);
|
||||
if(ObjectUtil.isNotNull(sysTenantVo)){
|
||||
List<SysDept> depts = sysDeptMapper.selectByTenantId(sysTenantVo.getTenantId());
|
||||
sysDepts.addAll(depts);
|
||||
}
|
||||
}
|
||||
for(SysDept s:sysDepts){
|
||||
s.setIsTenant("0");
|
||||
sysDeptMapper.updateDept(s);
|
||||
}
|
||||
return i;
|
||||
}
|
||||
|
||||
/**
|
||||
* 校验企业名称是否唯一
|
||||
*/
|
||||
@Override
|
||||
public boolean checkCompanyNameUnique(SysTenantBo bo) {
|
||||
List<SysTenantVo> list = baseMapper.queryByCompanyName(bo.getCompanyName());
|
||||
if(StringUtils.isEmpty(bo.getTenantId())){ // 新增
|
||||
if(list.size()>0){
|
||||
return false;
|
||||
}
|
||||
}else{ //修改
|
||||
SysTenantVo sysTenantVo = list.stream().filter(item->!bo.getTenantId().equals(item.getTenantId())).findFirst().orElse(null);
|
||||
if(ObjectUtil.isNotEmpty(sysTenantVo)){
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* 校验联系方式是否唯一
|
||||
*/
|
||||
@Override
|
||||
public boolean checkPhoneUnique(SysTenantBo bo) {
|
||||
List<SysTenantVo> list = baseMapper.queryByPhone(bo.getContactPhone());
|
||||
if(StringUtils.isEmpty(bo.getTenantId())){ // 新增
|
||||
if(list.size()>0){
|
||||
return false;
|
||||
}
|
||||
}else{ //修改
|
||||
SysTenantVo sysTenantVo = list.stream().filter(item->!bo.getTenantId().equals(item.getTenantId())).findFirst().orElse(null);
|
||||
if(ObjectUtil.isNotEmpty(sysTenantVo)){
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean checkUsername(SysTenantBo bo) {
|
||||
SysUser info = userMapper.checkUserNameUnique(bo.getUsername());
|
||||
if(StringUtils.isEmpty(bo.getTenantId())){
|
||||
if(ObjectUtil.isNotNull(info)){
|
||||
return false;
|
||||
}
|
||||
}else{
|
||||
if(ObjectUtil.isNotNull(info)){
|
||||
if(StringUtils.equals(info.getTenantId(),bo.getTenantId())){
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 校验有效期
|
||||
*/
|
||||
@Override
|
||||
public boolean checkExpireTime(String tenantId) {
|
||||
SysTenantVo tenant = SpringUtils.getAopProxy(this).queryByTenantId(tenantId);
|
||||
// 如果未设置过期时间代表不限制
|
||||
if (ObjectUtil.isNull(tenant.getExpireTime())) {
|
||||
return true;
|
||||
}
|
||||
// 如果当前时间在过期时间之前则通过
|
||||
return new Date().before(tenant.getExpireTime());
|
||||
}
|
||||
|
||||
@Override
|
||||
public int updateTenantStatus(SysTenantBo bo) {
|
||||
SysTenant tenant = new SysTenant();
|
||||
tenant.setId(bo.getId());
|
||||
tenant.setStatus(bo.getStatus());
|
||||
LoginUser loginUser = (LoginUser) SecurityUtils.getLoginUser();
|
||||
Long userId =loginUser.getUserId();
|
||||
SysTenantVo sysTenantVo = baseMapper.queryById(bo.getId());
|
||||
SysDept sysDept = new SysDept();
|
||||
sysDept.setUpdateBy(userId+"");
|
||||
sysDept.setStatus(bo.getStatus());
|
||||
deptMapper.updateDeptByTenantId(sysDept,sysTenantVo.getTenantId());
|
||||
List<Long> userIds = sysUserMapper.selectUserIdsByTenantId(sysTenantVo.getTenantId());
|
||||
if(CollectionUtil.isNotEmpty(userIds)){
|
||||
sysUserMapper.unableUser(userIds,bo.getStatus());
|
||||
}
|
||||
return baseMapper.updateById(tenant);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public Boolean deptToTenant(SysTenantBo bo) {
|
||||
Long deptId = bo.getDeptId();
|
||||
Date date = new Date();
|
||||
LoginUser loginUser = (LoginUser) SecurityUtils.getLoginUser();
|
||||
SysTenant add = BeanUtil.toBean(bo, SysTenant.class);
|
||||
// 获取所有租户编号
|
||||
List<String> tenantIds = baseMapper.selectObjs();
|
||||
String tenantId = generateTenantId(tenantIds);
|
||||
add.setTenantId(tenantId);
|
||||
add.setCreateDept(deptId);
|
||||
add.setCreateTime(date);
|
||||
add.setCreateBy(loginUser.getUserId()+"");
|
||||
add.setStatus("0");
|
||||
boolean flag = baseMapper.insert(add) > 0;
|
||||
if (!flag) {
|
||||
throw new ServiceException("创建租户失败");
|
||||
}
|
||||
// 根据套餐创建角色
|
||||
Long roleId = createTenantRole(tenantId, bo.getPackageId(),bo.getCompanyName());
|
||||
|
||||
// 角色和部门关联表
|
||||
SysRoleDept roleDept = new SysRoleDept();
|
||||
roleDept.setRoleId(roleId);
|
||||
roleDept.setDeptId(deptId);
|
||||
roleDeptMapper.batchRoleDept(Arrays.asList(roleDept));
|
||||
|
||||
// 创建系统用户
|
||||
SysUser user = new SysUser();
|
||||
user.setTenantId(tenantId);
|
||||
user.setUserName("admin");
|
||||
user.setNickName("admin");
|
||||
user.setPassword(BCrypt.hashpw("123456"));
|
||||
user.setDeptId((long) deptId);
|
||||
user.setCreateTime(date);
|
||||
user.setUpdateTime(date);
|
||||
user.setDelFlag("0");
|
||||
user.setStatus("0");
|
||||
userMapper.insertUser(user);
|
||||
//新增系统用户后,默认当前用户为部门的负责人
|
||||
SysDept sd = new SysDept();
|
||||
sd.setLeader(user.getUserName().toString());
|
||||
sd.setDeptId(deptId);
|
||||
sd.setIsTenant("1");
|
||||
sd.setTenantId(tenantId);
|
||||
deptMapper.updateDept(sd);
|
||||
|
||||
List<Long> deptIds = deptMapper.selectAllZSByDeptId(deptId);
|
||||
deptIds.add(deptId);
|
||||
//更新当前升级为租户的部门下属所有子孙节点的租户ID
|
||||
deptMapper.updateTenantId(deptIds,tenantId);
|
||||
//更新当前升级为租户的部门下属所有子孙节点的用户租户ID
|
||||
userMapper.updateTenantIdOfUsers(deptIds,tenantId);
|
||||
// 用户和角色关联表
|
||||
SysUserRole userRole = new SysUserRole();
|
||||
userRole.setUserId(user.getUserId());
|
||||
userRole.setRoleId(roleId);
|
||||
userRoleMapper.batchUserRole(Arrays.asList(userRole));
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
149
fp-system/src/main/resources/mapper/SysTenantMapper.xml
Normal file
149
fp-system/src/main/resources/mapper/SysTenantMapper.xml
Normal file
@@ -0,0 +1,149 @@
|
||||
<?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.zf.foodpurchase.system.mapper.SysTenantMapper">
|
||||
<sql id="selectSysTenantVo">
|
||||
select id,tenant_id tenantId,contact_user_name contactUserName,contact_phone contactPhone,company_name companyName,license_number licenseNumber,
|
||||
address,intro,domain,remark,status,
|
||||
package_id packageId,expire_time expireTime,account_count accountCount,del_flag delFlag,create_dept createDept,create_by createBy,
|
||||
create_time createTime,update_by updateBy,update_time updateTime from sys_tenant
|
||||
</sql>
|
||||
|
||||
<select id="queryById" resultType="SysTenantVo">
|
||||
select id,st.tenant_id tenantId,contact_user_name contactUserName,contact_phone contactPhone,company_name companyName,license_number licenseNumber,
|
||||
address,intro,domain,remark,st.status,st.create_dept deptId,
|
||||
package_id packageId,expire_time expireTime,account_count accountCount,st.del_flag delFlag,create_dept createDept,st.create_by createBy,
|
||||
st.create_time createTime,st.update_by updateBy,st.update_time updateTime from sys_tenant st
|
||||
WHERE st.del_flag = '0' and st.id = #{id}
|
||||
</select>
|
||||
|
||||
<select id="queryByCondition" parameterType="SysTenantBo" resultType="SysTenantVo">
|
||||
<include refid="selectSysTenantVo"/>
|
||||
where del_flag = '0'
|
||||
<if test="tenantId != null and tenantId != ''">
|
||||
AND tenant_id like concat('%', #{tenantId}, '%')
|
||||
</if>
|
||||
<if test="contactUserName != null and contactUserName != ''">
|
||||
AND contact_user_name like concat('%', #{contactUserName}, '%')
|
||||
</if>
|
||||
<if test="contactPhone != null and contactPhone != ''">
|
||||
AND contact_phone like concat('%', #{contactPhone}, '%')
|
||||
</if>
|
||||
<if test="companyName != null and companyName != ''">
|
||||
AND company_name like concat('%', #{companyName}, '%')
|
||||
</if>
|
||||
order by create_time desc
|
||||
</select>
|
||||
|
||||
<select id="queryByCompanyName" parameterType="String" resultType="SysTenantVo">
|
||||
<include refid="selectSysTenantVo"/>
|
||||
where del_flag = '0' AND company_name = #{companyName}
|
||||
order by create_time desc
|
||||
</select>
|
||||
|
||||
<select id="queryByPhone" parameterType="String" resultType="SysTenantVo">
|
||||
<include refid="selectSysTenantVo"/>
|
||||
where del_flag = '0' AND contact_phone = #{phone}
|
||||
order by create_time desc
|
||||
</select>
|
||||
|
||||
<select id="queryByTenantId" parameterType="String" resultType="SysTenantVo">
|
||||
<include refid="selectSysTenantVo"/>
|
||||
where del_flag = '0' AND tenant_id = #{tenantId}
|
||||
</select>
|
||||
|
||||
<select id="queryByTenantIds" parameterType="String" resultType="SysTenantVo">
|
||||
<include refid="selectSysTenantVo"/>
|
||||
where del_flag = '0' AND tenant_id in
|
||||
<foreach collection="tenantIds" item="tenantId" open="(" separator="," close=")">
|
||||
#{tenantId}
|
||||
</foreach>
|
||||
</select>
|
||||
|
||||
<delete id="deleteByIds" parameterType="Long">
|
||||
update sys_tenant set del_flag = '1' where id in
|
||||
<foreach collection="ids" item="id" open="(" separator="," close=")">
|
||||
#{id}
|
||||
</foreach>
|
||||
</delete>
|
||||
|
||||
<update id="updateById" parameterType="SysTenant">
|
||||
update sys_tenant
|
||||
<set>
|
||||
<if test="companyName != null and companyName != ''">company_name = #{companyName},</if>
|
||||
<if test="contactUserName != null and contactUserName != ''">contact_user_name = #{contactUserName},</if>
|
||||
<if test="contactPhone != null and contactPhone != ''">contact_phone = #{contactPhone},</if>
|
||||
<if test="expireTime != null">expire_time = #{expireTime},</if>
|
||||
<if test="accountCount != null">account_count = #{accountCount},</if>
|
||||
<if test="domain != null and domain != ''">domain = #{domain},</if>
|
||||
<if test="address != null and address != ''">address = #{address},</if>
|
||||
<if test="licenseNumber != null">license_number = #{licenseNumber},</if>
|
||||
<if test="intro != null and intro != ''">intro = #{intro},</if>
|
||||
<if test="remark != null and remark != ''">remark = #{remark},</if>
|
||||
<if test="status != null and status != ''">status = #{status},</if>
|
||||
<if test="createDept != null and createDept != ''">create_dept = #{createDept},</if>
|
||||
<if test="packageId != null">package_id = #{packageId},</if>
|
||||
<if test="updateBy != null">update_by = #{updateBy},</if>
|
||||
update_time = sysdate()
|
||||
</set>
|
||||
where id = #{id}
|
||||
</update>
|
||||
<insert id="insert" parameterType="SysTenant">
|
||||
INSERT INTO sys_tenant
|
||||
<trim prefix="(" suffix=")" suffixOverrides=",">
|
||||
<if test="tenantId != null">tenant_id,</if>
|
||||
<if test="contactUserName != null">contact_user_name,</if>
|
||||
<if test="contactPhone != null">contact_phone,</if>
|
||||
<if test="companyName != null">company_name,</if>
|
||||
<if test="licenseNumber != null">license_number,</if>
|
||||
<if test="address != null">address,</if>
|
||||
<if test="intro != null">intro,</if>
|
||||
<if test="domain != null">domain,</if>
|
||||
<if test="remark != null">remark,</if>
|
||||
<if test="packageId != null">package_id,</if>
|
||||
<if test="expireTime != null">expire_time,</if>
|
||||
<if test="accountCount != null">account_count,</if>
|
||||
<if test="status != null">status,</if>
|
||||
<if test="delFlag != null">del_flag,</if>
|
||||
<if test="createDept != null">create_dept,</if>
|
||||
<if test="createBy != null">create_by,</if>
|
||||
<if test="createTime != null">create_time,</if>
|
||||
<if test="updateBy != null">update_by,</if>
|
||||
<if test="updateTime != null">update_time,</if>
|
||||
</trim>
|
||||
<trim prefix="VALUES (" suffix=")" suffixOverrides=",">
|
||||
<if test="tenantId != null">#{tenantId},</if>
|
||||
<if test="contactUserName != null">#{contactUserName},</if>
|
||||
<if test="contactPhone != null">#{contactPhone},</if>
|
||||
<if test="companyName != null">#{companyName},</if>
|
||||
<if test="licenseNumber != null">#{licenseNumber},</if>
|
||||
<if test="address != null">#{address},</if>
|
||||
<if test="intro != null">#{intro},</if>
|
||||
<if test="domain != null">#{domain},</if>
|
||||
<if test="remark != null">#{remark},</if>
|
||||
<if test="packageId != null">#{packageId},</if>
|
||||
<if test="expireTime != null">#{expireTime},</if>
|
||||
<if test="accountCount != null">#{accountCount},</if>
|
||||
<if test="status != null">#{status},</if>
|
||||
<if test="delFlag != null">#{delFlag},</if>
|
||||
<if test="createDept != null">#{createDept},</if>
|
||||
<if test="createBy != null">#{createBy},</if>
|
||||
<if test="createTime != null">#{createTime},</if>
|
||||
<if test="updateBy != null">#{updateBy},</if>
|
||||
<if test="updateTime != null">#{updateTime},</if>
|
||||
</trim>
|
||||
</insert>
|
||||
<select id="selectObjs" resultType="String">
|
||||
select tenant_id tenantId from sys_tenant where del_flag = '0'
|
||||
</select>
|
||||
<select id="queryByPackageIds" resultType="SysTenantVo">
|
||||
<include refid="selectSysTenantVo"/>
|
||||
WHERE del_flag = '0' and package_id in
|
||||
<foreach collection="packageIds" item="packageId" open="(" separator="," close=")">
|
||||
#{packageId}
|
||||
</foreach>
|
||||
</select>
|
||||
</mapper>
|
||||
@@ -0,0 +1,79 @@
|
||||
<?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.zf.foodpurchase.system.mapper.SysTenantPackageMapper">
|
||||
<sql id="selectSysTenantVo">
|
||||
select package_id packageId,package_name packageName,menu_ids menuIds,remark,
|
||||
menu_check_strictly menuCheckStrictly,status,del_flag delFlag,create_dept createDept,create_by createBy,create_time createTime,
|
||||
update_by updateBy,update_time updateTime from sys_tenant_package
|
||||
</sql>
|
||||
<select id="selectById" resultType="SysTenantPackageVo">
|
||||
<include refid="selectSysTenantVo"/>
|
||||
where package_id=#{packageId} and del_flag = '0' limit 1
|
||||
</select>
|
||||
|
||||
<select id="selectList" parameterType="SysTenantPackageBo" resultType="SysTenantPackageVo">
|
||||
<include refid="selectSysTenantVo"/>
|
||||
where del_flag = '0'
|
||||
<if test="packageName != null">
|
||||
AND package_name like concat('%',#{packageName},'%')
|
||||
</if>
|
||||
</select>
|
||||
|
||||
<delete id="deleteByIds" parameterType="Long">
|
||||
update sys_tenant_package set del_flag = '1' where package_id in
|
||||
<foreach collection="packageIds" item="id" open="(" separator="," close=")">
|
||||
#{id}
|
||||
</foreach>
|
||||
</delete>
|
||||
|
||||
<update id="update" parameterType="SysTenantPackage">
|
||||
update sys_tenant_package
|
||||
<trim prefix="SET" suffixOverrides=",">
|
||||
<if test="packageName != null">package_name = #{packageName},</if>
|
||||
<if test="menuIds != null">menu_ids = #{menuIds},</if>
|
||||
<if test="remark != null">remark = #{remark},</if>
|
||||
<if test="menuCheckStrictly != null">menu_check_strictly = #{menuCheckStrictly},</if>
|
||||
<if test="status != null">status = #{status},</if>
|
||||
<if test="delFlag != null">del_flag = #{delFlag},</if>
|
||||
<if test="createDept != null">create_dept = #{createDept},</if>
|
||||
<if test="createBy != null">create_by = #{createBy},</if>
|
||||
<if test="createTime != null">create_time = #{createTime},</if>
|
||||
<if test="updateBy != null">update_by = #{updateBy},</if>
|
||||
<if test="updateTime != null">update_time = #{updateTime},</if>
|
||||
</trim>
|
||||
WHERE package_id = #{packageId}
|
||||
</update>
|
||||
<insert id="insert" parameterType="SysTenantPackage">
|
||||
INSERT INTO sys_tenant_package
|
||||
<trim prefix="(" suffix=")" suffixOverrides=",">
|
||||
<if test="packageName != null">package_name,</if>
|
||||
<if test="menuIds != null">menu_ids,</if>
|
||||
<if test="remark != null">remark,</if>
|
||||
<if test="menuCheckStrictly != null">menu_check_strictly,</if>
|
||||
<if test="status != null">status,</if>
|
||||
<if test="delFlag != null">del_flag,</if>
|
||||
<if test="createDept != null">create_dept,</if>
|
||||
<if test="createBy != null">create_by,</if>
|
||||
<if test="createTime != null">create_time,</if>
|
||||
<if test="updateBy != null">update_by,</if>
|
||||
<if test="updateTime != null">update_time,</if>
|
||||
</trim>
|
||||
<trim prefix="VALUES (" suffix=")" suffixOverrides=",">
|
||||
<if test="packageName != null">#{packageName},</if>
|
||||
<if test="menuIds != null">#{menuIds},</if>
|
||||
<if test="remark != null">#{remark},</if>
|
||||
<if test="menuCheckStrictly != null">#{menuCheckStrictly},</if>
|
||||
<if test="status != null">#{status},</if>
|
||||
<if test="delFlag != null">#{delFlag},</if>
|
||||
<if test="createDept != null">#{createDept},</if>
|
||||
<if test="createBy != null">#{createBy},</if>
|
||||
<if test="createTime != null">#{createTime},</if>
|
||||
<if test="updateBy != null">#{updateBy},</if>
|
||||
<if test="updateTime != null">#{updateTime},</if>
|
||||
</trim>
|
||||
</insert>
|
||||
</mapper>
|
||||
@@ -6,6 +6,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||
|
||||
<resultMap type="SysRole" id="SysRoleResult">
|
||||
<id property="roleId" column="role_id" />
|
||||
<id property="tenantId" column="tenant_id" />
|
||||
<result property="roleName" column="role_name" />
|
||||
<result property="roleKey" column="role_key" />
|
||||
<result property="roleSort" column="role_sort" />
|
||||
@@ -148,5 +149,10 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||
#{roleId}
|
||||
</foreach>
|
||||
</delete>
|
||||
|
||||
<select id="selectRolesByTenantId" parameterType="String" resultMap="SysRoleResult">
|
||||
<include refid="selectRoleVo"/>
|
||||
where r.tenant_id = #{tenantId}
|
||||
</select>
|
||||
|
||||
</mapper>
|
||||
@@ -30,5 +30,16 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||
(#{item.roleId},#{item.menuId})
|
||||
</foreach>
|
||||
</insert>
|
||||
|
||||
<delete id="deleteRoleMenuForSync" parameterType="Long">
|
||||
delete from sys_role_menu where role_id in
|
||||
<foreach collection="roleIds" item="roleId" open="(" separator="," close=")">
|
||||
#{roleId}
|
||||
</foreach>
|
||||
<if test="menuIds != null and menuIds.size() > 0">
|
||||
and menu_id not in
|
||||
<foreach collection="menuIds" item="menuId" open="(" separator="," close=")">
|
||||
#{menuId}
|
||||
</foreach>
|
||||
</if>
|
||||
</delete>
|
||||
</mapper>
|
||||
@@ -6,7 +6,9 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||
|
||||
<resultMap type="SysUser" id="SysUserResult">
|
||||
<id property="userId" column="user_id" />
|
||||
<result property="deptId" column="dept_id" />
|
||||
<result property="organiId" column="organi_id" />
|
||||
<result property="tenantId" column="tenant_id" />
|
||||
<result property="deptId" column="dept_id" />
|
||||
<result property="userName" column="user_name" />
|
||||
<result property="nickName" column="nick_name" />
|
||||
<result property="email" column="email" />
|
||||
@@ -32,6 +34,8 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||
<resultMap id="deptResult" type="SysDept">
|
||||
<id property="deptId" column="dept_id" />
|
||||
<result property="parentId" column="parent_id" />
|
||||
<result property="tenantId" column="tenant_id" />
|
||||
<result property="isTenant" column="is_tenant" />
|
||||
<result property="deptName" column="dept_name" />
|
||||
<result property="ancestors" column="ancestors" />
|
||||
<result property="orderNum" column="order_num" />
|
||||
@@ -41,6 +45,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||
|
||||
<resultMap id="RoleResult" type="SysRole">
|
||||
<id property="roleId" column="role_id" />
|
||||
<result property="tenantId" column="tenant_id" />
|
||||
<result property="roleName" column="role_name" />
|
||||
<result property="roleKey" column="role_key" />
|
||||
<result property="roleSort" column="role_sort" />
|
||||
@@ -226,4 +231,29 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||
</foreach>
|
||||
</delete>
|
||||
|
||||
<update id="unableUser" parameterType="SysUser">
|
||||
update sys_user set status = #{statusChar} where user_id in
|
||||
<foreach collection="userIds" item="userId" open="(" close=")" separator=",">
|
||||
#{userId}
|
||||
</foreach>
|
||||
</update>
|
||||
|
||||
<select id="selectUserIdsByTenantId" resultType="Long">
|
||||
select distinct user_id from sys_user
|
||||
where tenant_id = #{tenantId}
|
||||
</select>
|
||||
|
||||
<update id="updateTenantIdOfUsers">
|
||||
<if test="deptIds != null and deptIds.size() > 0">
|
||||
update sys_user set tenant_id = #{tenantId} where dept_id in
|
||||
<foreach collection="deptIds" item="deptId" open="(" close=")" separator=",">
|
||||
#{deptId}
|
||||
</foreach>
|
||||
</if>
|
||||
</update>
|
||||
|
||||
<select id="selectUserByUserNameAndTenantId" resultMap="SysUserResult">
|
||||
<include refid="selectUserVo"/>
|
||||
where u.del_flag = '0' and (u.status is not null or u.status =0) and u.user_name = #{userName} and u.tenant_id = #{tenantId}
|
||||
</select>
|
||||
</mapper>
|
||||
|
||||
@@ -7,6 +7,8 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||
<resultMap type="SysDept" id="SysDeptResult">
|
||||
<id property="deptId" column="dept_id" />
|
||||
<result property="parentId" column="parent_id" />
|
||||
<result property="tenantId" column="tenant_id" />
|
||||
<result property="isTenant" column="is_tenant" />
|
||||
<result property="ancestors" column="ancestors" />
|
||||
<result property="deptName" column="dept_name" />
|
||||
<result property="orderNum" column="order_num" />
|
||||
@@ -177,4 +179,45 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||
update sys_dept set del_flag = '2' where dept_id = #{deptId}
|
||||
</delete>
|
||||
|
||||
<update id="updateDeptByTenantId">
|
||||
update sys_dept
|
||||
<set>
|
||||
<if test="dept.parentId != null and dept.parentId != 0">parent_id = #{dept.parentId},</if>
|
||||
<if test="dept.deptName != null and dept.deptName != ''">dept_name = #{dept.deptName},</if>
|
||||
<if test="dept.ancestors != null and dept.ancestors != ''">ancestors = #{dept.ancestors},</if>
|
||||
<if test="dept.orderNum != null">order_num = #{dept.orderNum},</if>
|
||||
<if test="dept.leader != null">leader = #{dept.leader},</if>
|
||||
<if test="dept.phone != null">phone = #{dept.phone},</if>
|
||||
<if test="dept.email != null">email = #{dept.email},</if>
|
||||
<if test="dept.status != null and dept.status != ''">status = #{dept.status},</if>
|
||||
<if test="dept.updateBy != null and dept.updateBy != ''">update_by = #{dept.updateBy},</if>
|
||||
<if test="dept.isTenant != null and dept.isTenant != ''">is_tenant = #{dept.isTenant},</if>
|
||||
update_time = sysdate()
|
||||
</set>
|
||||
where tenant_id = #{tenantId,jdbcType=VARCHAR}
|
||||
</update>
|
||||
|
||||
<select id="selectByTenantId" parameterType="String" resultMap="SysDeptResult">
|
||||
<include refid="selectDeptVo"/>
|
||||
where d.del_flag = '0' and d.tenant_id = #{tenantId}
|
||||
</select>
|
||||
|
||||
<select id="selectAllZSByDeptId" parameterType="Long" resultType="long">
|
||||
select dept_id
|
||||
from sys_dept
|
||||
where find_in_set(#{deptId}, ancestors)
|
||||
</select>
|
||||
|
||||
<update id="updateTenantId">
|
||||
<if test="deptIds != null and deptIds.size() > 0">
|
||||
update sys_dept
|
||||
set tenant_id = #{tenantId}
|
||||
where dept_id in
|
||||
<foreach collection="deptIds" item="deptId" index="index"
|
||||
separator="," open="(" close=")">
|
||||
#{deptId}
|
||||
</foreach>
|
||||
</if>
|
||||
</update>
|
||||
|
||||
</mapper>
|
||||
|
||||
Reference in New Issue
Block a user