针对智慧工地对公司框架进行优化
This commit is contained in:
parent
2567d81ff4
commit
7f7d333fb5
|
|
@ -1,6 +1,7 @@
|
|||
package com.bonus.system.api.domain;
|
||||
|
||||
import com.bonus.common.core.web.domain.BaseEntity;
|
||||
import lombok.Data;
|
||||
import org.apache.commons.lang3.builder.ToStringBuilder;
|
||||
import org.apache.commons.lang3.builder.ToStringStyle;
|
||||
|
||||
|
|
@ -16,6 +17,7 @@ import java.util.List;
|
|||
*
|
||||
* @author bonus
|
||||
*/
|
||||
@Data
|
||||
public class SysDept extends BaseEntity {
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
|
|
@ -91,6 +93,56 @@ public class SysDept extends BaseEntity {
|
|||
*/
|
||||
private String address;
|
||||
|
||||
/**
|
||||
* 公司简称
|
||||
*/
|
||||
private String deptAbbreviation;
|
||||
|
||||
/**
|
||||
* 公司概述
|
||||
*/
|
||||
private String remark;
|
||||
|
||||
/**
|
||||
* logo
|
||||
*/
|
||||
private String logo;
|
||||
|
||||
/**
|
||||
*密码
|
||||
*/
|
||||
private String password;
|
||||
|
||||
/**
|
||||
*姓名
|
||||
*/
|
||||
private String nickName;
|
||||
|
||||
/**
|
||||
*账号
|
||||
*/
|
||||
private String userName;
|
||||
|
||||
/**
|
||||
*手机号
|
||||
*/
|
||||
private String phonenumber;
|
||||
|
||||
/**
|
||||
*角色名称
|
||||
*/
|
||||
private String roleName;
|
||||
|
||||
/**
|
||||
*用户id
|
||||
*/
|
||||
private Long userId;
|
||||
|
||||
/**
|
||||
*角色id
|
||||
*/
|
||||
private Long roleId;
|
||||
|
||||
|
||||
public void setCity(String city) {
|
||||
this.city = city;
|
||||
|
|
|
|||
|
|
@ -55,6 +55,11 @@ public class SystemConfig {
|
|||
*/
|
||||
private String websocketurl;
|
||||
|
||||
/**
|
||||
* 创建公司的同时是否同时创建用户和角色
|
||||
*/
|
||||
private boolean createUserAndRole;
|
||||
|
||||
@Data
|
||||
@RefreshScope
|
||||
public static class LoginConfig {
|
||||
|
|
|
|||
|
|
@ -92,6 +92,17 @@ public class SecurityUtils
|
|||
return userId != null && 1L == userId;
|
||||
}
|
||||
|
||||
/**
|
||||
* 解密
|
||||
* @param password
|
||||
* @return
|
||||
*/
|
||||
public static String decryptPassword(String password)
|
||||
{
|
||||
return Sm4Utils.decrypt(password);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 生成BCryptPasswordEncoder密码
|
||||
*
|
||||
|
|
|
|||
|
|
@ -1,7 +1,9 @@
|
|||
package com.bonus.system.controller;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import com.bonus.common.core.web.page.TableDataInfo;
|
||||
import com.bonus.common.log.annotation.SysLog;
|
||||
import com.bonus.common.log.enums.OperaType;
|
||||
import com.bonus.common.security.annotation.InnerAuth;
|
||||
|
|
@ -11,11 +13,9 @@ import lombok.extern.slf4j.Slf4j;
|
|||
import org.apache.commons.lang3.ArrayUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
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.PathVariable;
|
||||
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.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
|
@ -34,7 +34,7 @@ import com.bonus.system.service.ISysDeptService;
|
|||
* @author bonus
|
||||
*/
|
||||
@RestController
|
||||
@RequestMapping("/dept")
|
||||
@RequestMapping("/dept")
|
||||
@Slf4j
|
||||
public class SysDeptController extends BaseController
|
||||
{
|
||||
|
|
@ -155,4 +155,19 @@ public class SysDeptController extends BaseController
|
|||
}
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
package com.bonus.system.mapper;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
import com.bonus.system.api.domain.SysDept;
|
||||
|
||||
|
|
@ -123,4 +124,18 @@ public interface SysDeptMapper
|
|||
* @return 结果
|
||||
*/
|
||||
public int deleteDeptById(Long deptId);
|
||||
|
||||
/**
|
||||
* 获取公司列表
|
||||
* @param dept
|
||||
* @return
|
||||
*/
|
||||
List<SysDept> getDeptList(SysDept dept);
|
||||
|
||||
/**
|
||||
* 获取公司详情
|
||||
* @param deptId
|
||||
* @return
|
||||
*/
|
||||
SysDept selectDeptAndUserById(Long deptId);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -130,4 +130,11 @@ public interface ISysDeptService
|
|||
* @return 结果
|
||||
*/
|
||||
public int deleteDeptById(Long deptId);
|
||||
|
||||
/**
|
||||
* 运营人员获取公司列表
|
||||
* @param dept
|
||||
* @return
|
||||
*/
|
||||
List<SysDept> getDeptList(SysDept dept);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -7,10 +7,13 @@ import java.util.Set;
|
|||
import java.util.stream.Collectors;
|
||||
|
||||
import com.bonus.common.core.web.domain.BaseEntity;
|
||||
import com.bonus.system.mapper.SysUserMapper;
|
||||
import com.bonus.config.SystemConfig;
|
||||
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 lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.BeanUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
import com.bonus.common.core.constant.UserConstants;
|
||||
import com.bonus.common.core.exception.ServiceException;
|
||||
|
|
@ -23,9 +26,10 @@ import com.bonus.system.api.domain.SysDept;
|
|||
import com.bonus.system.api.domain.SysRole;
|
||||
import com.bonus.system.api.domain.SysUser;
|
||||
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 org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
|
||||
/**
|
||||
* 部门管理 服务实现
|
||||
|
|
@ -33,16 +37,29 @@ import com.bonus.system.service.ISysDeptService;
|
|||
* @author bonus
|
||||
*/
|
||||
@Service
|
||||
@Slf4j
|
||||
public class SysDeptServiceImpl implements ISysDeptService
|
||||
{
|
||||
@Autowired
|
||||
@Resource
|
||||
private SysDeptMapper deptMapper;
|
||||
|
||||
@Autowired
|
||||
@Resource
|
||||
private SysUserMapper userMapper;
|
||||
|
||||
@Autowired
|
||||
@Resource
|
||||
private SysRoleMapper roleMapper;
|
||||
@Resource
|
||||
private SysRoleMenuMapper roleMenuMapper;
|
||||
|
||||
@Resource
|
||||
private SysRoleDeptMapper roleDeptMapper;
|
||||
|
||||
@Resource
|
||||
private SystemConfig systemConfig;
|
||||
|
||||
@Resource
|
||||
private SysUserServiceImpl sysUserServiceImpl;
|
||||
|
||||
|
||||
/**
|
||||
* 查询部门管理数据
|
||||
|
|
@ -170,7 +187,14 @@ public class SysDeptServiceImpl implements ISysDeptService
|
|||
@Override
|
||||
public SysDept selectDeptById(Long deptId)
|
||||
{
|
||||
return deptMapper.selectDeptById(deptId);
|
||||
SysDept sysDept = deptMapper.selectDeptById(deptId);
|
||||
if (systemConfig.isCreateUserAndRole() && sysDept.getParentId()==0L){
|
||||
sysDept = deptMapper.selectDeptAndUserById(deptId);
|
||||
if (sysDept.getPassword()!=null){
|
||||
sysDept.setPassword(SecurityUtils.decryptPassword(sysDept.getPassword()));
|
||||
}
|
||||
}
|
||||
return sysDept;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -259,22 +283,94 @@ public class SysDeptServiceImpl implements ISysDeptService
|
|||
* @return 结果
|
||||
*/
|
||||
@Override
|
||||
@Transactional
|
||||
public int insertDept(SysDept dept)
|
||||
{
|
||||
//增加根公司的处理
|
||||
if (dept.getParentId() == null){
|
||||
dept.setParentId(0L);
|
||||
dept.setAncestors("0");
|
||||
}
|
||||
else {
|
||||
//创建公司
|
||||
deptMapper.insertDept(dept);
|
||||
//创建公司时判断是否开通注册用户和角色
|
||||
if (systemConfig.isCreateUserAndRole()) {
|
||||
//创建一个用户信息
|
||||
SysUser user = createUser(dept);
|
||||
//创建一个系统管理员账号
|
||||
createRole(dept.getDeptId(),user);
|
||||
}
|
||||
return 1;
|
||||
}else {
|
||||
SysDept info = deptMapper.selectDeptById(dept.getParentId());
|
||||
// 如果父节点不为正常状态,则不允许新增子节点
|
||||
if (!UserConstants.DEPT_NORMAL.equals(info.getStatus())) {
|
||||
throw new ServiceException("部门停用,不允许新增");
|
||||
}
|
||||
dept.setAncestors(info.getAncestors() + "," + dept.getParentId());
|
||||
return deptMapper.insertDept(dept);
|
||||
}
|
||||
return deptMapper.insertDept(dept);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 创建公司管理员
|
||||
*/
|
||||
private void createRole(Long deptId,SysUser user) {
|
||||
SysRole role = new SysRole();
|
||||
role.setRoleKey("admin");
|
||||
role.setRoleName("系统管理员");
|
||||
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(deptId);
|
||||
roleDeptList.add(rd);
|
||||
roleDeptMapper.batchRoleDept(roleDeptList);
|
||||
//用户绑定角色
|
||||
Long[] roleIds = {role.getRoleId()};
|
||||
sysUserServiceImpl.insertUserRole(user.getUserId(),roleIds);
|
||||
List<SysRoleMenu> list = new ArrayList<>();
|
||||
//对初始化管理员赋值菜单权限
|
||||
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);
|
||||
roleMenuMapper.batchRoleMenu(list);
|
||||
}
|
||||
|
||||
/**
|
||||
* 创建用户
|
||||
* @param dept
|
||||
*/
|
||||
private SysUser createUser(SysDept dept) {
|
||||
log.info("创建用户:{}",dept);
|
||||
SysUser user = new SysUser();
|
||||
user.setCreateBy(SecurityUtils.getUsername());
|
||||
user.setPassword(SecurityUtils.encryptPassword(dept.getPassword()));
|
||||
user.setNickName(dept.getNickName());
|
||||
user.setUserName(dept.getUserName());
|
||||
user.setPhonenumber(dept.getPhonenumber());
|
||||
user.setDeptId(dept.getDeptId());
|
||||
userMapper.insertUser(user);
|
||||
return user;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -302,9 +398,36 @@ public class SysDeptServiceImpl implements ISysDeptService
|
|||
// 如果该部门是启用状态,则启用该部门的所有上级部门
|
||||
updateParentDeptStatusNormal(dept);
|
||||
}
|
||||
//判断是否是修改公司信息并判断是否关联用户信息
|
||||
if (systemConfig.isCreateUserAndRole() && dept.getDeptId()==0L){
|
||||
updateUserAndRole(dept);
|
||||
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改用户和角色信息
|
||||
* @param dept
|
||||
*/
|
||||
private void updateUserAndRole(SysDept dept) {
|
||||
SysUser user = new SysUser();
|
||||
user.setUpdateBy(SecurityUtils.getUsername());
|
||||
user.setPassword(SecurityUtils.encryptPassword(dept.getPassword()));
|
||||
user.setNickName(dept.getNickName());
|
||||
user.setUserName(dept.getUserName());
|
||||
user.setPhonenumber(dept.getPhonenumber());
|
||||
user.setDeptId(dept.getDeptId());
|
||||
SysRole role = new SysRole();
|
||||
role.setRoleName(dept.getRoleName());
|
||||
role.setUpdateBy(SecurityUtils.getUsername());
|
||||
dept = deptMapper.selectDeptAndUserById(dept.getDeptId());
|
||||
role.setRoleId(dept.getRoleId());
|
||||
user.setUserId(dept.getUserId());
|
||||
userMapper.updateUser(user);
|
||||
roleMapper.updateRole(role);
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改该部门的父级部门状态
|
||||
*
|
||||
|
|
@ -349,6 +472,18 @@ public class SysDeptServiceImpl implements ISysDeptService
|
|||
return deptMapper.deleteDeptById(deptId);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取公司列表
|
||||
* @param dept
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public List<SysDept> getDeptList(SysDept dept) {
|
||||
return deptMapper.getDeptList(dept);
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* 递归列表
|
||||
*/
|
||||
|
|
|
|||
|
|
@ -254,6 +254,13 @@ public class SysRoleServiceImpl implements ISysRoleService
|
|||
{
|
||||
// 新增角色信息
|
||||
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);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -24,8 +24,10 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
|||
<result property="city" column="city" />
|
||||
<result property="district" column="district" />
|
||||
<result property="address" column="address" />
|
||||
|
||||
</resultMap>
|
||||
<result property="deptAbbreviation" column="dept_abbreviation" />
|
||||
<result property="remark" column="remark" />
|
||||
<result property="logo" column="logo" />
|
||||
</resultMap>logo
|
||||
|
||||
<sql id="selectDeptVo">
|
||||
select d.dept_id,
|
||||
|
|
@ -43,7 +45,10 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
|||
d.province,
|
||||
d.city,
|
||||
d.district,
|
||||
d.address
|
||||
d.address,
|
||||
d.deptAbbreviation,
|
||||
d.remark,
|
||||
d.logo
|
||||
from sys_dept d
|
||||
</sql>
|
||||
|
||||
|
|
@ -140,8 +145,20 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
|||
<include refid="selectDeptVo"/>
|
||||
where dept_name=#{deptName} and parent_id = #{parentId} and del_flag = '0' limit 1
|
||||
</select>
|
||||
<select id="getDeptList" resultType="com.bonus.system.api.domain.SysDept">
|
||||
select * from sys_dept where parent_id='0'
|
||||
</select>
|
||||
<select id="selectDeptAndUserById" resultType="com.bonus.system.api.domain.SysDept">
|
||||
|
||||
<insert id="insertDept" parameterType="com.bonus.system.api.domain.SysDept">
|
||||
select sd.*,su.nick_name as nickName,su.user_name as userName,su.password as password,
|
||||
sr.role_name as roleName,su.user_id as userId,sr.role_id as roleId 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 role_key = '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 dept_id = #{deptId}
|
||||
</select>
|
||||
<insert id="insertDept" parameterType="com.bonus.system.api.domain.SysDept" useGeneratedKeys="true" keyProperty="deptId">
|
||||
insert into sys_dept(
|
||||
<if test="deptId != null and deptId != 0">dept_id,</if>
|
||||
<if test="parentId != null and parentId != 0">parent_id,</if>
|
||||
|
|
|
|||
Loading…
Reference in New Issue