Compare commits
8 Commits
main
...
feature-zh
| Author | SHA1 | Date |
|---|---|---|
|
|
3245fe6c12 | |
|
|
c1e6fbbec7 | |
|
|
92d77786b8 | |
|
|
35e1e76cc7 | |
|
|
c0f8ba4dd3 | |
|
|
de5dcccd9a | |
|
|
d19533a19b | |
|
|
7f7d333fb5 |
|
|
@ -1,6 +1,7 @@
|
||||||
package com.bonus.system.api.domain;
|
package com.bonus.system.api.domain;
|
||||||
|
|
||||||
import com.bonus.common.core.web.domain.BaseEntity;
|
import com.bonus.common.core.web.domain.BaseEntity;
|
||||||
|
import lombok.Data;
|
||||||
import org.apache.commons.lang3.builder.ToStringBuilder;
|
import org.apache.commons.lang3.builder.ToStringBuilder;
|
||||||
import org.apache.commons.lang3.builder.ToStringStyle;
|
import org.apache.commons.lang3.builder.ToStringStyle;
|
||||||
|
|
||||||
|
|
@ -16,6 +17,7 @@ import java.util.List;
|
||||||
*
|
*
|
||||||
* @author bonus
|
* @author bonus
|
||||||
*/
|
*/
|
||||||
|
@Data
|
||||||
public class SysDept extends BaseEntity {
|
public class SysDept extends BaseEntity {
|
||||||
private static final long serialVersionUID = 1L;
|
private static final long serialVersionUID = 1L;
|
||||||
|
|
||||||
|
|
@ -91,6 +93,45 @@ public class SysDept extends BaseEntity {
|
||||||
*/
|
*/
|
||||||
private String address;
|
private String address;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 公司简称
|
||||||
|
*/
|
||||||
|
private String deptAbbreviation;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 公司概述
|
||||||
|
*/
|
||||||
|
private String remark;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* logo
|
||||||
|
*/
|
||||||
|
private String logo;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*角色名称
|
||||||
|
*/
|
||||||
|
private String roleName;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*用户id
|
||||||
|
*/
|
||||||
|
private Long userId;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*角色id
|
||||||
|
*/
|
||||||
|
private Long roleId;
|
||||||
|
/**
|
||||||
|
* 用户信息
|
||||||
|
*/
|
||||||
|
private SysUser sysUser;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @param city
|
||||||
|
*/
|
||||||
|
private String keyWord;
|
||||||
|
|
||||||
public void setCity(String city) {
|
public void setCity(String city) {
|
||||||
this.city = city;
|
this.city = city;
|
||||||
|
|
|
||||||
|
|
@ -4,6 +4,8 @@ import java.util.Set;
|
||||||
import javax.validation.constraints.NotBlank;
|
import javax.validation.constraints.NotBlank;
|
||||||
import javax.validation.constraints.NotNull;
|
import javax.validation.constraints.NotNull;
|
||||||
import javax.validation.constraints.Size;
|
import javax.validation.constraints.Size;
|
||||||
|
|
||||||
|
import lombok.Data;
|
||||||
import org.apache.commons.lang3.builder.ToStringBuilder;
|
import org.apache.commons.lang3.builder.ToStringBuilder;
|
||||||
import org.apache.commons.lang3.builder.ToStringStyle;
|
import org.apache.commons.lang3.builder.ToStringStyle;
|
||||||
import com.bonus.common.core.annotation.Excel;
|
import com.bonus.common.core.annotation.Excel;
|
||||||
|
|
@ -15,6 +17,7 @@ import com.bonus.common.core.web.domain.BaseEntity;
|
||||||
*
|
*
|
||||||
* @author bonus
|
* @author bonus
|
||||||
*/
|
*/
|
||||||
|
@Data
|
||||||
public class SysRole extends BaseEntity
|
public class SysRole extends BaseEntity
|
||||||
{
|
{
|
||||||
private static final long serialVersionUID = 1L;
|
private static final long serialVersionUID = 1L;
|
||||||
|
|
@ -65,6 +68,8 @@ public class SysRole extends BaseEntity
|
||||||
/** 部门组(数据权限) */
|
/** 部门组(数据权限) */
|
||||||
private Long[] deptIds;
|
private Long[] deptIds;
|
||||||
|
|
||||||
|
/** 部门组(数据权限) */
|
||||||
|
private Long deptId;
|
||||||
/** 角色菜单权限 */
|
/** 角色菜单权限 */
|
||||||
private Set<String> permissions;
|
private Set<String> permissions;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -55,6 +55,11 @@ public class SystemConfig {
|
||||||
*/
|
*/
|
||||||
private String websocketurl;
|
private String websocketurl;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 创建公司的同时是否同时创建用户和角色
|
||||||
|
*/
|
||||||
|
private boolean createUserAndRole;
|
||||||
|
|
||||||
@Data
|
@Data
|
||||||
@RefreshScope
|
@RefreshScope
|
||||||
public static class LoginConfig {
|
public static class LoginConfig {
|
||||||
|
|
|
||||||
|
|
@ -17,7 +17,7 @@ public class MimeTypeUtils
|
||||||
|
|
||||||
public static final String IMAGE_GIF = "image/gif";
|
public static final String IMAGE_GIF = "image/gif";
|
||||||
|
|
||||||
public static final String[] IMAGE_EXTENSION = { "bmp", "gif", "jpg", "jpeg", "png" };
|
public static final String[] IMAGE_EXTENSION = { "bmp", "gif", "jpg", "jpeg", "png", "svg","SVG"};
|
||||||
|
|
||||||
public static final String[] FLASH_EXTENSION = { "swf", "flv" };
|
public static final String[] FLASH_EXTENSION = { "swf", "flv" };
|
||||||
|
|
||||||
|
|
@ -28,7 +28,7 @@ public class MimeTypeUtils
|
||||||
|
|
||||||
public static final String[] DEFAULT_ALLOWED_EXTENSION = {
|
public static final String[] DEFAULT_ALLOWED_EXTENSION = {
|
||||||
// 图片
|
// 图片
|
||||||
"bmp", "gif", "jpg", "jpeg", "png",
|
"bmp", "gif", "jpg", "jpeg", "png","svg","SVG",
|
||||||
// word excel powerpoint
|
// word excel powerpoint
|
||||||
"doc", "docx", "xls", "xlsx","csv", "ppt", "pptx", "html", "htm", "txt",
|
"doc", "docx", "xls", "xlsx","csv", "ppt", "pptx", "html", "htm", "txt",
|
||||||
// 压缩文件
|
// 压缩文件
|
||||||
|
|
|
||||||
|
|
@ -92,6 +92,17 @@ public class SecurityUtils
|
||||||
return userId != null && 1L == userId;
|
return userId != null && 1L == userId;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 解密
|
||||||
|
* @param password
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public static String decryptPassword(String password)
|
||||||
|
{
|
||||||
|
return Sm4Utils.decrypt(password);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 生成BCryptPasswordEncoder密码
|
* 生成BCryptPasswordEncoder密码
|
||||||
*
|
*
|
||||||
|
|
|
||||||
|
|
@ -1,21 +1,23 @@
|
||||||
package com.bonus.system.controller;
|
package com.bonus.system.controller;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
import com.bonus.common.core.exception.ServiceException;
|
||||||
|
import com.bonus.common.core.web.page.TableDataInfo;
|
||||||
import com.bonus.common.log.annotation.SysLog;
|
import com.bonus.common.log.annotation.SysLog;
|
||||||
import com.bonus.common.log.enums.OperaType;
|
import com.bonus.common.log.enums.OperaType;
|
||||||
import com.bonus.common.security.annotation.InnerAuth;
|
import com.bonus.common.security.annotation.InnerAuth;
|
||||||
import com.bonus.common.security.annotation.RequiresPermissionsOrInnerAuth;
|
import com.bonus.common.security.annotation.RequiresPermissionsOrInnerAuth;
|
||||||
import com.bonus.common.security.annotation.RequiresRoles;
|
import com.bonus.common.security.annotation.RequiresRoles;
|
||||||
|
import com.bonus.system.service.ISysUserService;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.apache.commons.lang3.ArrayUtils;
|
import org.apache.commons.lang3.ArrayUtils;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.validation.annotation.Validated;
|
import org.springframework.validation.annotation.Validated;
|
||||||
import org.springframework.web.bind.annotation.DeleteMapping;
|
|
||||||
import org.springframework.web.bind.annotation.GetMapping;
|
import org.springframework.web.bind.annotation.GetMapping;
|
||||||
import org.springframework.web.bind.annotation.PathVariable;
|
import org.springframework.web.bind.annotation.PathVariable;
|
||||||
import org.springframework.web.bind.annotation.PostMapping;
|
import org.springframework.web.bind.annotation.PostMapping;
|
||||||
import org.springframework.web.bind.annotation.PutMapping;
|
|
||||||
import org.springframework.web.bind.annotation.RequestBody;
|
import org.springframework.web.bind.annotation.RequestBody;
|
||||||
import org.springframework.web.bind.annotation.RequestMapping;
|
import org.springframework.web.bind.annotation.RequestMapping;
|
||||||
import org.springframework.web.bind.annotation.RestController;
|
import org.springframework.web.bind.annotation.RestController;
|
||||||
|
|
@ -28,6 +30,8 @@ import com.bonus.common.security.utils.SecurityUtils;
|
||||||
import com.bonus.system.api.domain.SysDept;
|
import com.bonus.system.api.domain.SysDept;
|
||||||
import com.bonus.system.service.ISysDeptService;
|
import com.bonus.system.service.ISysDeptService;
|
||||||
|
|
||||||
|
import javax.annotation.Resource;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 部门信息
|
* 部门信息
|
||||||
*
|
*
|
||||||
|
|
@ -41,6 +45,9 @@ public class SysDeptController extends BaseController
|
||||||
@Autowired
|
@Autowired
|
||||||
private ISysDeptService deptService;
|
private ISysDeptService deptService;
|
||||||
|
|
||||||
|
@Resource
|
||||||
|
private ISysUserService userService;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 获取部门列表
|
* 获取部门列表
|
||||||
* 根据部门id或上级部门id或部门名或状态(正常或停用)获取部门信息
|
* 根据部门id或上级部门id或部门名或状态(正常或停用)获取部门信息
|
||||||
|
|
@ -99,6 +106,11 @@ public class SysDeptController extends BaseController
|
||||||
try{
|
try{
|
||||||
if (!deptService.checkDeptNameUnique(dept)) {
|
if (!deptService.checkDeptNameUnique(dept)) {
|
||||||
return error("新增部门'" + dept.getDeptName() + "'失败,部门名称已存在");
|
return error("新增部门'" + dept.getDeptName() + "'失败,部门名称已存在");
|
||||||
|
}else if (StringUtils.isNotNull(dept.getSysUser()) &&!userService.checkUserNameUnique(dept.getSysUser())) {
|
||||||
|
throw new ServiceException("新增用户'" + dept.getSysUser().getUserName() + "'失败,登录账号已存在");
|
||||||
|
} else if (StringUtils.isNotEmpty(dept.getSysUser().getPhonenumber()) && !userService.checkPhoneUnique(dept.getSysUser())) {
|
||||||
|
throw new ServiceException("新增用户'" + dept.getSysUser().getUserName() + "'失败,手机号码已存在");
|
||||||
|
|
||||||
}
|
}
|
||||||
dept.setCreateBy(SecurityUtils.getUsername());
|
dept.setCreateBy(SecurityUtils.getUsername());
|
||||||
return toAjax(deptService.insertDept(dept));
|
return toAjax(deptService.insertDept(dept));
|
||||||
|
|
@ -124,8 +136,12 @@ public class SysDeptController extends BaseController
|
||||||
return error("修改部门'" + dept.getDeptName() + "'失败,上级部门不能是自己");
|
return error("修改部门'" + dept.getDeptName() + "'失败,上级部门不能是自己");
|
||||||
} else if (StringUtils.equals(UserConstants.DEPT_DISABLE, dept.getStatus()) && deptService.selectNormalChildrenDeptById(deptId) > 0) {
|
} else if (StringUtils.equals(UserConstants.DEPT_DISABLE, dept.getStatus()) && deptService.selectNormalChildrenDeptById(deptId) > 0) {
|
||||||
return error("该部门包含未停用的子部门!");
|
return error("该部门包含未停用的子部门!");
|
||||||
|
}else if (StringUtils.isNotNull(dept.getSysUser()) && !userService.checkUserNameUnique(dept.getSysUser())) {
|
||||||
|
throw new ServiceException("修改部门'" + dept.getSysUser().getUserName() + "'失败,登录账号已存在");
|
||||||
|
} else if (StringUtils.isNotEmpty(dept.getSysUser().getPhonenumber()) && !userService.checkPhoneUnique(dept.getSysUser())) {
|
||||||
|
throw new ServiceException("修改部门'" + dept.getSysUser().getUserName() + "'失败,手机号码已存在");
|
||||||
}
|
}
|
||||||
dept.setUpdateBy(SecurityUtils.getUsername());
|
dept.setUpdateBy(SecurityUtils.getUsername());
|
||||||
return toAjax(deptService.updateDept(dept));
|
return toAjax(deptService.updateDept(dept));
|
||||||
}catch (Exception e){
|
}catch (Exception e){
|
||||||
log.error(e.toString(),e);
|
log.error(e.toString(),e);
|
||||||
|
|
@ -155,4 +171,37 @@ public class SysDeptController extends BaseController
|
||||||
}
|
}
|
||||||
return error("系统异常");
|
return error("系统异常");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@GetMapping("/deptList")
|
||||||
|
@SysLog(title = "运营人员获取公司列表", businessType = OperaType.QUERY,logType = 0,module = "系统管理->部门管理")
|
||||||
|
public TableDataInfo deptList(SysDept dept) {
|
||||||
|
List<SysDept> deptList = new ArrayList<>();
|
||||||
|
try{
|
||||||
|
startPage();
|
||||||
|
deptList = deptService.getDeptList(dept);
|
||||||
|
return getDataTable(deptList);
|
||||||
|
}catch (Exception e){
|
||||||
|
log.error(e.toString(),e);
|
||||||
|
}
|
||||||
|
return getDataTableError(deptList);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 公司注销
|
||||||
|
* @param dept
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
@PostMapping("/deptLogout")
|
||||||
|
@SysLog(title = "运营人员获取公司列表", businessType = OperaType.UPDATE,logType = 0,module = "系统管理->部门管理")
|
||||||
|
public AjaxResult deptLogout(@Validated @RequestBody SysDept dept) {
|
||||||
|
|
||||||
|
try{
|
||||||
|
log.info("公司信息{}",dept.getDeptId());
|
||||||
|
return toAjax(deptService.deptLogout(dept.getDeptId()));
|
||||||
|
}catch (Exception e){
|
||||||
|
log.error(e.toString(),e);
|
||||||
|
}
|
||||||
|
return error("系统异常");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,8 @@
|
||||||
package com.bonus.system.mapper;
|
package com.bonus.system.mapper;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
import com.bonus.system.api.domain.SysUser;
|
||||||
import org.apache.ibatis.annotations.Param;
|
import org.apache.ibatis.annotations.Param;
|
||||||
import com.bonus.system.api.domain.SysDept;
|
import com.bonus.system.api.domain.SysDept;
|
||||||
|
|
||||||
|
|
@ -123,4 +125,25 @@ public interface SysDeptMapper
|
||||||
* @return 结果
|
* @return 结果
|
||||||
*/
|
*/
|
||||||
public int deleteDeptById(Long deptId);
|
public int deleteDeptById(Long deptId);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取公司列表
|
||||||
|
* @param dept
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
List<SysDept> getDeptList(SysDept dept);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取公司详情
|
||||||
|
* @param deptId
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
SysUser selectDeptAndUserById(Long deptId);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 公司注销
|
||||||
|
* @param deptId
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
int deptLogout(Long deptId);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -60,4 +60,10 @@ public interface SysUserRoleMapper
|
||||||
* @return 结果
|
* @return 结果
|
||||||
*/
|
*/
|
||||||
public int deleteUserRoleInfos(@Param("roleId") Long roleId, @Param("userIds") Long[] userIds);
|
public int deleteUserRoleInfos(@Param("roleId") Long roleId, @Param("userIds") Long[] userIds);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 插入用户和角色关系表
|
||||||
|
* @param sysUserRole
|
||||||
|
*/
|
||||||
|
void insertUserRole(SysUserRole sysUserRole);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -130,4 +130,18 @@ public interface ISysDeptService
|
||||||
* @return 结果
|
* @return 结果
|
||||||
*/
|
*/
|
||||||
public int deleteDeptById(Long deptId);
|
public int deleteDeptById(Long deptId);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 运营人员获取公司列表
|
||||||
|
* @param dept
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
List<SysDept> getDeptList(SysDept dept);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 公司注销
|
||||||
|
* @param deptId
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
int deptLogout(Long deptId);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -7,8 +7,14 @@ import java.util.Set;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
import com.bonus.common.core.web.domain.BaseEntity;
|
import com.bonus.common.core.web.domain.BaseEntity;
|
||||||
import com.bonus.system.mapper.SysUserMapper;
|
import com.bonus.config.SystemConfig;
|
||||||
|
import com.bonus.system.api.domain.SysUserRole;
|
||||||
|
import com.bonus.system.domain.SysRoleDept;
|
||||||
|
import com.bonus.system.domain.SysRoleMenu;
|
||||||
|
import com.bonus.system.mapper.*;
|
||||||
import com.bonus.common.datascope.utils.CommonDataPermissionInfo;
|
import com.bonus.common.datascope.utils.CommonDataPermissionInfo;
|
||||||
|
import com.bonus.system.service.ISysUserService;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.springframework.beans.BeanUtils;
|
import org.springframework.beans.BeanUtils;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
|
@ -23,9 +29,10 @@ import com.bonus.system.api.domain.SysDept;
|
||||||
import com.bonus.system.api.domain.SysRole;
|
import com.bonus.system.api.domain.SysRole;
|
||||||
import com.bonus.system.api.domain.SysUser;
|
import com.bonus.system.api.domain.SysUser;
|
||||||
import com.bonus.system.domain.vo.TreeSelect;
|
import com.bonus.system.domain.vo.TreeSelect;
|
||||||
import com.bonus.system.mapper.SysDeptMapper;
|
|
||||||
import com.bonus.system.mapper.SysRoleMapper;
|
|
||||||
import com.bonus.system.service.ISysDeptService;
|
import com.bonus.system.service.ISysDeptService;
|
||||||
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
|
|
||||||
|
import javax.annotation.Resource;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 部门管理 服务实现
|
* 部门管理 服务实现
|
||||||
|
|
@ -33,16 +40,31 @@ import com.bonus.system.service.ISysDeptService;
|
||||||
* @author bonus
|
* @author bonus
|
||||||
*/
|
*/
|
||||||
@Service
|
@Service
|
||||||
|
@Slf4j
|
||||||
public class SysDeptServiceImpl implements ISysDeptService
|
public class SysDeptServiceImpl implements ISysDeptService
|
||||||
{
|
{
|
||||||
@Autowired
|
@Resource
|
||||||
private SysDeptMapper deptMapper;
|
private SysDeptMapper deptMapper;
|
||||||
|
|
||||||
@Autowired
|
@Resource
|
||||||
private SysUserMapper userMapper;
|
private SysUserMapper userMapper;
|
||||||
|
|
||||||
@Autowired
|
@Resource
|
||||||
private SysRoleMapper roleMapper;
|
private SysRoleMapper roleMapper;
|
||||||
|
@Resource
|
||||||
|
private SysRoleMenuMapper roleMenuMapper;
|
||||||
|
|
||||||
|
@Resource
|
||||||
|
private SysRoleDeptMapper roleDeptMapper;
|
||||||
|
|
||||||
|
@Resource
|
||||||
|
private SystemConfig systemConfig;
|
||||||
|
|
||||||
|
@Resource
|
||||||
|
private SysUserRoleMapper userRoleMapper;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 查询部门管理数据
|
* 查询部门管理数据
|
||||||
|
|
@ -64,6 +86,7 @@ public class SysDeptServiceImpl implements ISysDeptService
|
||||||
String str = dept.getDeptName().replace("\\", "\\\\").replace("%", "\\%").replace("_", "\\_");
|
String str = dept.getDeptName().replace("\\", "\\\\").replace("%", "\\%").replace("_", "\\_");
|
||||||
dept.setDeptName(str);
|
dept.setDeptName(str);
|
||||||
}
|
}
|
||||||
|
dept.setDeptId(SecurityUtils.getLoginUser().getSysUser().getDeptId());
|
||||||
return deptMapper.selectDeptList(dept);
|
return deptMapper.selectDeptList(dept);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -170,7 +193,12 @@ public class SysDeptServiceImpl implements ISysDeptService
|
||||||
@Override
|
@Override
|
||||||
public SysDept selectDeptById(Long deptId)
|
public SysDept selectDeptById(Long deptId)
|
||||||
{
|
{
|
||||||
return deptMapper.selectDeptById(deptId);
|
SysDept sysDept = deptMapper.selectDeptById(deptId);
|
||||||
|
if (systemConfig.isCreateUserAndRole() && sysDept.getParentId()==0L){
|
||||||
|
SysUser sysUser = deptMapper.selectDeptAndUserById(deptId);
|
||||||
|
sysDept.setSysUser(sysUser);
|
||||||
|
}
|
||||||
|
return sysDept;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -259,22 +287,117 @@ public class SysDeptServiceImpl implements ISysDeptService
|
||||||
* @return 结果
|
* @return 结果
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
|
@Transactional
|
||||||
public int insertDept(SysDept dept)
|
public int insertDept(SysDept dept)
|
||||||
{
|
{
|
||||||
//增加根公司的处理
|
//增加根公司的处理
|
||||||
if (dept.getParentId() == null){
|
if (dept.getParentId() == null){
|
||||||
dept.setParentId(0L);
|
dept.setParentId(0L);
|
||||||
dept.setAncestors("0");
|
dept.setAncestors("0");
|
||||||
}
|
//创建公司
|
||||||
else {
|
deptMapper.insertDept(dept);
|
||||||
|
//创建公司时判断是否开通注册用户和角色
|
||||||
|
if (systemConfig.isCreateUserAndRole()) {
|
||||||
|
//创建一个用户信息
|
||||||
|
SysUser user = createUser(dept);
|
||||||
|
//创建一个系统管理员账号
|
||||||
|
createRole(dept,user);
|
||||||
|
}
|
||||||
|
return 1;
|
||||||
|
}else {
|
||||||
SysDept info = deptMapper.selectDeptById(dept.getParentId());
|
SysDept info = deptMapper.selectDeptById(dept.getParentId());
|
||||||
// 如果父节点不为正常状态,则不允许新增子节点
|
// 如果父节点不为正常状态,则不允许新增子节点
|
||||||
if (!UserConstants.DEPT_NORMAL.equals(info.getStatus())) {
|
if (!UserConstants.DEPT_NORMAL.equals(info.getStatus())) {
|
||||||
throw new ServiceException("部门停用,不允许新增");
|
throw new ServiceException("部门停用,不允许新增");
|
||||||
}
|
}
|
||||||
dept.setAncestors(info.getAncestors() + "," + dept.getParentId());
|
dept.setAncestors(info.getAncestors() + "," + dept.getParentId());
|
||||||
|
return deptMapper.insertDept(dept);
|
||||||
}
|
}
|
||||||
return deptMapper.insertDept(dept);
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 创建公司管理员
|
||||||
|
*/
|
||||||
|
private void createRole(SysDept sysDept,SysUser user) {
|
||||||
|
log.info("部门信息{},用户信息{}",sysDept,user);
|
||||||
|
SysRole role = new SysRole();
|
||||||
|
role.setRoleKey("dept_"+sysDept.getDeptId()+"_admin");
|
||||||
|
role.setRoleName(sysDept.getDeptName()+"管理员");
|
||||||
|
role.setRoleSort(0);
|
||||||
|
role.setStatus("0");
|
||||||
|
role.setCreateBy(SecurityUtils.getUsername());
|
||||||
|
|
||||||
|
roleMapper.insertRole(role);
|
||||||
|
log.info("创建的角色id为:{}",role.getRoleId());
|
||||||
|
//绑定管理员角色和公司关系
|
||||||
|
List<SysRoleDept> roleDeptList = new ArrayList<>();
|
||||||
|
SysRoleDept rd = new SysRoleDept();
|
||||||
|
rd.setRoleId(Long.valueOf(role.getRoleId()));
|
||||||
|
rd.setDeptId(sysDept.getDeptId());
|
||||||
|
roleDeptList.add(rd);
|
||||||
|
roleDeptMapper.batchRoleDept(roleDeptList);
|
||||||
|
//用户绑定角色
|
||||||
|
SysUserRole sysUserRole = new SysUserRole();
|
||||||
|
sysUserRole.setUserId(user.getUserId());
|
||||||
|
sysUserRole.setRoleId(role.getRoleId());
|
||||||
|
userRoleMapper.insertUserRole(sysUserRole);
|
||||||
|
List<SysRoleMenu> list = new ArrayList<>();
|
||||||
|
//对初始化管理员赋值菜单权限
|
||||||
|
SysRoleMenu rm = new SysRoleMenu();
|
||||||
|
rm.setRoleId(Long.valueOf(role.getRoleId()));
|
||||||
|
rm.setMenuId(1L);
|
||||||
|
list.add(rm);
|
||||||
|
SysRoleMenu rm1 = new SysRoleMenu();
|
||||||
|
rm1.setRoleId(Long.valueOf(role.getRoleId()));
|
||||||
|
rm1.setMenuId(100L);
|
||||||
|
list.add(rm1);
|
||||||
|
SysRoleMenu rm2 = new SysRoleMenu();
|
||||||
|
rm2.setRoleId(Long.valueOf(role.getRoleId()));
|
||||||
|
rm2.setMenuId(101L);
|
||||||
|
list.add(rm2);
|
||||||
|
SysRoleMenu rm3 = new SysRoleMenu();
|
||||||
|
rm3.setRoleId(Long.valueOf(role.getRoleId()));
|
||||||
|
rm3.setMenuId(103L);
|
||||||
|
list.add(rm3);
|
||||||
|
/* SysRoleMenu rm4 = new SysRoleMenu();
|
||||||
|
rm4.setRoleId(Long.valueOf(role.getRoleId()));
|
||||||
|
rm4.setMenuId(104L);
|
||||||
|
list.add(rm4);*/
|
||||||
|
SysRoleMenu rm4 = new SysRoleMenu();
|
||||||
|
rm4.setRoleId(Long.valueOf(role.getRoleId()));
|
||||||
|
rm4.setMenuId(1007L);
|
||||||
|
list.add(rm4);
|
||||||
|
SysRoleMenu rm5 = new SysRoleMenu();
|
||||||
|
rm5.setRoleId(Long.valueOf(role.getRoleId()));
|
||||||
|
rm5.setMenuId(1008L);
|
||||||
|
list.add(rm5);
|
||||||
|
SysRoleMenu rm6 = new SysRoleMenu();
|
||||||
|
rm6.setRoleId(Long.valueOf(role.getRoleId()));
|
||||||
|
rm6.setMenuId(1009L);
|
||||||
|
list.add(rm6);
|
||||||
|
SysRoleMenu rm7 = new SysRoleMenu();
|
||||||
|
rm7.setRoleId(Long.valueOf(role.getRoleId()));
|
||||||
|
rm7.setMenuId(1010L);
|
||||||
|
list.add(rm7);
|
||||||
|
SysRoleMenu rm8 = new SysRoleMenu();
|
||||||
|
rm8.setRoleId(Long.valueOf(role.getRoleId()));
|
||||||
|
rm8.setMenuId(1011L);
|
||||||
|
list.add(rm8);
|
||||||
|
roleMenuMapper.batchRoleMenu(list);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 创建用户
|
||||||
|
* @param dept
|
||||||
|
*/
|
||||||
|
private SysUser createUser(SysDept dept) {
|
||||||
|
log.info("创建用户:{}",dept);
|
||||||
|
SysUser user = dept.getSysUser();
|
||||||
|
user.setCreateBy(SecurityUtils.getUsername());
|
||||||
|
user.setDeptId(dept.getDeptId());
|
||||||
|
userMapper.insertUser(user);
|
||||||
|
return user;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -302,9 +425,32 @@ public class SysDeptServiceImpl implements ISysDeptService
|
||||||
// 如果该部门是启用状态,则启用该部门的所有上级部门
|
// 如果该部门是启用状态,则启用该部门的所有上级部门
|
||||||
updateParentDeptStatusNormal(dept);
|
updateParentDeptStatusNormal(dept);
|
||||||
}
|
}
|
||||||
|
//判断是否是修改公司信息并判断是否关联用户信息
|
||||||
|
if (systemConfig.isCreateUserAndRole() && dept.getParentId()==0L){
|
||||||
|
updateUserAndRole(dept);
|
||||||
|
|
||||||
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 修改用户和角色信息
|
||||||
|
* @param dept
|
||||||
|
*/
|
||||||
|
private void updateUserAndRole(SysDept dept) {
|
||||||
|
SysUser user = dept.getSysUser();
|
||||||
|
user.setUpdateBy(SecurityUtils.getUsername());
|
||||||
|
user.setDeptId(dept.getDeptId());
|
||||||
|
SysRole role = new SysRole();
|
||||||
|
role.setRoleName(dept.getRoleName());
|
||||||
|
role.setUpdateBy(SecurityUtils.getUsername());
|
||||||
|
SysUser oldSysUser = deptMapper.selectDeptAndUserById(dept.getDeptId());
|
||||||
|
role.setRoleId(oldSysUser.getRoleId());
|
||||||
|
user.setUserId(oldSysUser.getUserId());
|
||||||
|
userMapper.updateUser(user);
|
||||||
|
roleMapper.updateRole(role);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 修改该部门的父级部门状态
|
* 修改该部门的父级部门状态
|
||||||
*
|
*
|
||||||
|
|
@ -349,6 +495,22 @@ public class SysDeptServiceImpl implements ISysDeptService
|
||||||
return deptMapper.deleteDeptById(deptId);
|
return deptMapper.deleteDeptById(deptId);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取公司列表
|
||||||
|
* @param dept
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public List<SysDept> getDeptList(SysDept dept) {
|
||||||
|
return deptMapper.getDeptList(dept);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int deptLogout(Long deptId) {
|
||||||
|
return deptMapper.deptLogout(deptId);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 递归列表
|
* 递归列表
|
||||||
*/
|
*/
|
||||||
|
|
|
||||||
|
|
@ -73,6 +73,7 @@ public class SysRoleServiceImpl implements ISysRoleService
|
||||||
String str = role.getRoleKey().replace("\\", "\\\\").replace("%", "\\%").replace("_", "\\_");
|
String str = role.getRoleKey().replace("\\", "\\\\").replace("%", "\\%").replace("_", "\\_");
|
||||||
role.setRoleKey(str);
|
role.setRoleKey(str);
|
||||||
}
|
}
|
||||||
|
role.setDeptId(SecurityUtils.getLoginUser().getSysUser().getDeptId());
|
||||||
return roleMapper.selectRoleList(role);
|
return roleMapper.selectRoleList(role);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -254,6 +255,13 @@ public class SysRoleServiceImpl implements ISysRoleService
|
||||||
{
|
{
|
||||||
// 新增角色信息
|
// 新增角色信息
|
||||||
roleMapper.insertRole(role);
|
roleMapper.insertRole(role);
|
||||||
|
//新增角色和部门的关系
|
||||||
|
List<SysRoleDept> roleDeptList = new ArrayList<>();
|
||||||
|
SysRoleDept rd = new SysRoleDept();
|
||||||
|
rd.setRoleId(role.getRoleId());
|
||||||
|
rd.setDeptId(role.getDeptIds()[0]);
|
||||||
|
roleDeptList.add(rd);
|
||||||
|
roleDeptMapper.batchRoleDept(roleDeptList);
|
||||||
return insertRoleMenu(role);
|
return insertRoleMenu(role);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -109,6 +109,8 @@ public class SysUserServiceImpl implements ISysUserService {
|
||||||
String phone =user.getPhonenumber().replace("\\", "\\\\").replace("%", "\\%").replace("_", "\\_");
|
String phone =user.getPhonenumber().replace("\\", "\\\\").replace("%", "\\%").replace("_", "\\_");
|
||||||
user.setPhonenumber(phone);
|
user.setPhonenumber(phone);
|
||||||
}
|
}
|
||||||
|
user.setDeptId(SecurityUtils.getLoginUser().getSysUser().getDeptId());
|
||||||
|
log.info("用户信息{},部门信息{}",user,SecurityUtils.getLoginUser().getSysUser().getDeptId());
|
||||||
List<SysUser> sysUsers = userMapper.selectUserList(user);
|
List<SysUser> sysUsers = userMapper.selectUserList(user);
|
||||||
return sysUsers;
|
return sysUsers;
|
||||||
}
|
}
|
||||||
|
|
@ -472,6 +474,7 @@ public class SysUserServiceImpl implements ISysUserService {
|
||||||
* @param roleIds 角色组
|
* @param roleIds 角色组
|
||||||
*/
|
*/
|
||||||
public void insertUserRole(Long userId, Long[] roleIds) {
|
public void insertUserRole(Long userId, Long[] roleIds) {
|
||||||
|
log.info("用户id{},角色id{}",userId,roleIds);
|
||||||
if (StringUtils.isNotEmpty(roleIds)) {
|
if (StringUtils.isNotEmpty(roleIds)) {
|
||||||
// 新增用户与角色管理
|
// 新增用户与角色管理
|
||||||
List<SysUserRole> list = new ArrayList<SysUserRole>();
|
List<SysUserRole> list = new ArrayList<SysUserRole>();
|
||||||
|
|
@ -481,6 +484,7 @@ public class SysUserServiceImpl implements ISysUserService {
|
||||||
ur.setRoleId(roleId);
|
ur.setRoleId(roleId);
|
||||||
list.add(ur);
|
list.add(ur);
|
||||||
}
|
}
|
||||||
|
log.info("用户和角色关联关系{}",list);
|
||||||
userRoleMapper.batchUserRole(list);
|
userRoleMapper.batchUserRole(list);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -24,7 +24,9 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||||
<result property="city" column="city" />
|
<result property="city" column="city" />
|
||||||
<result property="district" column="district" />
|
<result property="district" column="district" />
|
||||||
<result property="address" column="address" />
|
<result property="address" column="address" />
|
||||||
|
<result property="deptAbbreviation" column="dept_abbreviation" />
|
||||||
|
<result property="remark" column="remark" />
|
||||||
|
<result property="logo" column="logo" />
|
||||||
</resultMap>
|
</resultMap>
|
||||||
|
|
||||||
<sql id="selectDeptVo">
|
<sql id="selectDeptVo">
|
||||||
|
|
@ -43,7 +45,10 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||||
d.province,
|
d.province,
|
||||||
d.city,
|
d.city,
|
||||||
d.district,
|
d.district,
|
||||||
d.address
|
d.address,
|
||||||
|
d.dept_abbreviation,
|
||||||
|
d.remark,
|
||||||
|
d.logo
|
||||||
from sys_dept d
|
from sys_dept d
|
||||||
</sql>
|
</sql>
|
||||||
|
|
||||||
|
|
@ -140,8 +145,22 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||||
<include refid="selectDeptVo"/>
|
<include refid="selectDeptVo"/>
|
||||||
where dept_name=#{deptName} and parent_id = #{parentId} and del_flag = '0' limit 1
|
where dept_name=#{deptName} and parent_id = #{parentId} and del_flag = '0' limit 1
|
||||||
</select>
|
</select>
|
||||||
|
<select id="getDeptList" resultType="com.bonus.system.api.domain.SysDept">
|
||||||
<insert id="insertDept" parameterType="com.bonus.system.api.domain.SysDept">
|
select * from sys_dept sd where parent_id='0'
|
||||||
|
<if test="keyWord != null and keyWord != ''">
|
||||||
|
and sd.dept_name like concat('%', #{keyWord}, '%')
|
||||||
|
</if>
|
||||||
|
</select>
|
||||||
|
<select id="selectDeptAndUserById" resultType="com.bonus.system.api.domain.SysUser">
|
||||||
|
select su.nick_name as nickName,su.user_name as userName,su.password as password,su.phonenumber as phonenumber,
|
||||||
|
sr.role_name as roleName,su.user_id as userId,sr.role_id as roleId, sd.dept_id as deptId from sys_dept sd
|
||||||
|
left join sys_role_dept srd on sd.dept_id = srd.dept_id
|
||||||
|
left join sys_role sr on srd.role_id = sr.role_id and sr.role_key LIKE '%admin%'
|
||||||
|
left join sys_user_role sur on sur.role_id = sr.role_id
|
||||||
|
left join sys_user su on su.user_id = sur.user_id
|
||||||
|
where sd.dept_id = #{deptId}
|
||||||
|
</select>
|
||||||
|
<insert id="insertDept" parameterType="com.bonus.system.api.domain.SysDept" useGeneratedKeys="true" keyProperty="deptId">
|
||||||
insert into sys_dept(
|
insert into sys_dept(
|
||||||
<if test="deptId != null and deptId != 0">dept_id,</if>
|
<if test="deptId != null and deptId != 0">dept_id,</if>
|
||||||
<if test="parentId != null and parentId != 0">parent_id,</if>
|
<if test="parentId != null and parentId != 0">parent_id,</if>
|
||||||
|
|
@ -157,6 +176,9 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||||
<if test="address != null and address != ''">address,</if>
|
<if test="address != null and address != ''">address,</if>
|
||||||
<if test="status != null">status,</if>
|
<if test="status != null">status,</if>
|
||||||
<if test="createBy != null and createBy != ''">create_by,</if>
|
<if test="createBy != null and createBy != ''">create_by,</if>
|
||||||
|
<if test="deptAbbreviation != null and deptAbbreviation != ''">dept_abbreviation,</if>
|
||||||
|
<if test="remark != null and remark != ''">remark,</if>
|
||||||
|
<if test="logo != null and logo != ''">logo,</if>
|
||||||
create_time
|
create_time
|
||||||
)values(
|
)values(
|
||||||
<if test="deptId != null and deptId != 0">#{deptId},</if>
|
<if test="deptId != null and deptId != 0">#{deptId},</if>
|
||||||
|
|
@ -173,6 +195,9 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||||
<if test="address != null and address != ''">#{address},</if>
|
<if test="address != null and address != ''">#{address},</if>
|
||||||
<if test="status != null">#{status},</if>
|
<if test="status != null">#{status},</if>
|
||||||
<if test="createBy != null and createBy != ''">#{createBy},</if>
|
<if test="createBy != null and createBy != ''">#{createBy},</if>
|
||||||
|
<if test="deptAbbreviation != null and deptAbbreviation != ''">#{deptAbbreviation},</if>
|
||||||
|
<if test="remark != null and remark != ''">#{remark},</if>
|
||||||
|
<if test="logo != null and logo != ''">#{logo},</if>
|
||||||
sysdate()
|
sysdate()
|
||||||
)
|
)
|
||||||
</insert>
|
</insert>
|
||||||
|
|
@ -193,6 +218,9 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||||
<if test="address != null">address = #{address},</if>
|
<if test="address != null">address = #{address},</if>
|
||||||
<if test="status != null and status != ''">status = #{status},</if>
|
<if test="status != null and status != ''">status = #{status},</if>
|
||||||
<if test="updateBy != null and updateBy != ''">update_by = #{updateBy},</if>
|
<if test="updateBy != null and updateBy != ''">update_by = #{updateBy},</if>
|
||||||
|
<if test="deptAbbreviation != null and deptAbbreviation != ''">dept_abbreviation = #{deptAbbreviation},</if>
|
||||||
|
<if test="remark != null and remark != ''">remark = #{remark},</if>
|
||||||
|
<if test="logo != null and logo != ''">logo = #{logo},</if>
|
||||||
update_time = sysdate()
|
update_time = sysdate()
|
||||||
</set>
|
</set>
|
||||||
where dept_id = #{deptId}
|
where dept_id = #{deptId}
|
||||||
|
|
@ -217,6 +245,9 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||||
#{deptId}
|
#{deptId}
|
||||||
</foreach>
|
</foreach>
|
||||||
</update>
|
</update>
|
||||||
|
<update id="deptLogout">
|
||||||
|
update sys_dept set status = '2' where dept_id = #{deptId}
|
||||||
|
</update>
|
||||||
|
|
||||||
<delete id="deleteDeptById" parameterType="Long">
|
<delete id="deleteDeptById" parameterType="Long">
|
||||||
update sys_dept set del_flag = '2' where dept_id = #{deptId}
|
update sys_dept set del_flag = '2' where dept_id = #{deptId}
|
||||||
|
|
|
||||||
|
|
@ -52,6 +52,10 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||||
<if test="params.endTime != null and params.endTime != ''"><!-- 结束时间检索 -->
|
<if test="params.endTime != null and params.endTime != ''"><!-- 结束时间检索 -->
|
||||||
and date_format(r.create_time,'%y%m%d') <= date_format(#{params.endTime},'%y%m%d')
|
and date_format(r.create_time,'%y%m%d') <= date_format(#{params.endTime},'%y%m%d')
|
||||||
</if>
|
</if>
|
||||||
|
<if test="deptId != null and deptId != 0">
|
||||||
|
AND (u.dept_id = #{deptId} OR u.dept_id IN ( SELECT t.dept_id FROM sys_dept t WHERE find_in_set(#{deptId},
|
||||||
|
ancestors) ))
|
||||||
|
</if>
|
||||||
<!-- 数据范围过滤 -->
|
<!-- 数据范围过滤 -->
|
||||||
<include refid="com.bonus.system.mapper.DataScopeMapper.dataScopeFilter"/>
|
<include refid="com.bonus.system.mapper.DataScopeMapper.dataScopeFilter"/>
|
||||||
order by r.role_sort
|
order by r.role_sort
|
||||||
|
|
|
||||||
|
|
@ -30,6 +30,9 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||||
(#{item.userId},#{item.roleId})
|
(#{item.userId},#{item.roleId})
|
||||||
</foreach>
|
</foreach>
|
||||||
</insert>
|
</insert>
|
||||||
|
<insert id="insertUserRole">
|
||||||
|
insert into sys_user_role(user_id, role_id) values(#{userId},#{roleId})
|
||||||
|
</insert>
|
||||||
|
|
||||||
<delete id="deleteUserRoleInfo" parameterType="com.bonus.system.api.domain.SysUserRole">
|
<delete id="deleteUserRoleInfo" parameterType="com.bonus.system.api.domain.SysUserRole">
|
||||||
delete from sys_user_role where user_id=#{userId} and role_id=#{roleId}
|
delete from sys_user_role where user_id=#{userId} and role_id=#{roleId}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue