新增公司
This commit is contained in:
parent
7f4cb6d520
commit
49996f6530
|
|
@ -91,6 +91,23 @@ public class SysDept extends BaseEntity {
|
|||
*/
|
||||
private String address;
|
||||
|
||||
/**
|
||||
* 公司简称
|
||||
*/
|
||||
private String deptAbbreviation;
|
||||
|
||||
/**
|
||||
* 公司概述
|
||||
*/
|
||||
private String remark;
|
||||
|
||||
/**
|
||||
* logo
|
||||
*/
|
||||
private String logo;
|
||||
|
||||
private SysUser sysUser;
|
||||
|
||||
|
||||
public void setCity(String city) {
|
||||
this.city = city;
|
||||
|
|
@ -127,6 +144,39 @@ public class SysDept extends BaseEntity {
|
|||
this.province = province;
|
||||
}
|
||||
|
||||
public String getDeptAbbreviation() {
|
||||
return deptAbbreviation;
|
||||
}
|
||||
|
||||
public void setDeptAbbreviation(String deptAbbreviation) {
|
||||
this.deptAbbreviation = deptAbbreviation;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getRemark() {
|
||||
return remark;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setRemark(String remark) {
|
||||
this.remark = remark;
|
||||
}
|
||||
|
||||
public String getLogo() {
|
||||
return logo;
|
||||
}
|
||||
|
||||
public void setLogo(String logo) {
|
||||
this.logo = logo;
|
||||
}
|
||||
|
||||
public SysUser getSysUser() {
|
||||
return sysUser;
|
||||
}
|
||||
|
||||
public void setSysUser(SysUser sysUser) {
|
||||
this.sysUser = sysUser;
|
||||
}
|
||||
|
||||
/**
|
||||
* 子部门
|
||||
|
|
|
|||
|
|
@ -1,16 +1,19 @@
|
|||
package com.bonus.system.service.impl;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import java.util.*;
|
||||
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.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.system.service.ISysUserService;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.BeanUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.context.annotation.Lazy;
|
||||
import org.springframework.stereotype.Service;
|
||||
import com.bonus.common.core.constant.UserConstants;
|
||||
import com.bonus.common.core.exception.ServiceException;
|
||||
|
|
@ -23,16 +26,17 @@ 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 javax.annotation.Resource;
|
||||
|
||||
/**
|
||||
* 部门管理 服务实现
|
||||
*
|
||||
* @author bonus
|
||||
*/
|
||||
@Service
|
||||
@Slf4j
|
||||
public class SysDeptServiceImpl implements ISysDeptService
|
||||
{
|
||||
@Autowired
|
||||
|
|
@ -44,6 +48,22 @@ public class SysDeptServiceImpl implements ISysDeptService
|
|||
@Autowired
|
||||
private SysRoleMapper roleMapper;
|
||||
|
||||
@Resource
|
||||
private SysUserRoleMapper userRoleMapper;
|
||||
|
||||
@Resource
|
||||
private SysRoleMenuMapper roleMenuMapper;
|
||||
|
||||
@Resource
|
||||
private SysRoleDeptMapper roleDeptMapper;
|
||||
|
||||
@Lazy
|
||||
@Autowired
|
||||
ISysUserService userService;
|
||||
|
||||
@Resource
|
||||
private SystemConfig systemConfig;
|
||||
|
||||
/**
|
||||
* 查询部门管理数据
|
||||
*
|
||||
|
|
@ -265,16 +285,24 @@ public class SysDeptServiceImpl implements ISysDeptService
|
|||
if (dept.getParentId() == null){
|
||||
dept.setParentId(0L);
|
||||
dept.setAncestors("0");
|
||||
}
|
||||
else {
|
||||
if (StringUtils.isNotNull(dept.getSysUser()) && !userService.checkUserNameUnique(dept.getSysUser())) {
|
||||
throw new ServiceException("新增公司管理员用户'" + dept.getSysUser().getUserName() + "'失败,登录账号已存在");
|
||||
}
|
||||
int result = deptMapper.insertDept(dept);
|
||||
if (result > 0) {
|
||||
SysUser user = createCompanyAdminUser(dept);
|
||||
createCompanyAdminRole(dept, user);
|
||||
}
|
||||
return result;
|
||||
} 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);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -391,5 +419,94 @@ public class SysDeptServiceImpl implements ISysDeptService
|
|||
{
|
||||
return getChildList(list, t).size() > 0 ? true : false;
|
||||
}
|
||||
|
||||
/**
|
||||
* 创建公司管理员用户
|
||||
* @param dept
|
||||
*/
|
||||
private SysUser createCompanyAdminUser(SysDept dept) {
|
||||
log.info("创建公司管理员用户:{}",dept);
|
||||
SysUser user = dept.getSysUser();
|
||||
user.setCreateBy(SecurityUtils.getUsername());
|
||||
user.setPassword(SecurityUtils.encryptPassword(user.getPassword()));
|
||||
user.setDeptId(dept.getDeptId());
|
||||
userMapper.insertUser(user);
|
||||
return user;
|
||||
}
|
||||
|
||||
/**
|
||||
* 创建公司管理员并分配角色菜单等
|
||||
*/
|
||||
private void createCompanyAdminRole(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());
|
||||
List<SysUserRole> sysUserRoleList = new ArrayList<SysUserRole>();
|
||||
sysUserRoleList.add(sysUserRole);
|
||||
userRoleMapper.batchUserRole(sysUserRoleList);
|
||||
|
||||
//对初始化管理员赋值菜单权限
|
||||
List<SysRoleMenu> sysRoleMenulist = new ArrayList<>();
|
||||
SysRoleMenu rm = new SysRoleMenu();
|
||||
rm.setRoleId(Long.valueOf(role.getRoleId()));
|
||||
rm.setMenuId(1L);
|
||||
sysRoleMenulist.add(rm);
|
||||
SysRoleMenu rm1 = new SysRoleMenu();
|
||||
rm1.setRoleId(Long.valueOf(role.getRoleId()));
|
||||
rm1.setMenuId(100L);
|
||||
sysRoleMenulist.add(rm1);
|
||||
SysRoleMenu rm2 = new SysRoleMenu();
|
||||
rm2.setRoleId(Long.valueOf(role.getRoleId()));
|
||||
rm2.setMenuId(101L);
|
||||
sysRoleMenulist.add(rm2);
|
||||
SysRoleMenu rm3 = new SysRoleMenu();
|
||||
rm3.setRoleId(Long.valueOf(role.getRoleId()));
|
||||
rm3.setMenuId(103L);
|
||||
sysRoleMenulist.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);
|
||||
sysRoleMenulist.add(rm4);
|
||||
SysRoleMenu rm5 = new SysRoleMenu();
|
||||
rm5.setRoleId(Long.valueOf(role.getRoleId()));
|
||||
rm5.setMenuId(1008L);
|
||||
sysRoleMenulist.add(rm5);
|
||||
SysRoleMenu rm6 = new SysRoleMenu();
|
||||
rm6.setRoleId(Long.valueOf(role.getRoleId()));
|
||||
rm6.setMenuId(1009L);
|
||||
sysRoleMenulist.add(rm6);
|
||||
SysRoleMenu rm7 = new SysRoleMenu();
|
||||
rm7.setRoleId(Long.valueOf(role.getRoleId()));
|
||||
rm7.setMenuId(1010L);
|
||||
sysRoleMenulist.add(rm7);
|
||||
SysRoleMenu rm8 = new SysRoleMenu();
|
||||
rm8.setRoleId(Long.valueOf(role.getRoleId()));
|
||||
rm8.setMenuId(1011L);
|
||||
sysRoleMenulist.add(rm8);
|
||||
roleMenuMapper.batchRoleMenu(sysRoleMenulist);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -24,7 +24,9 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
|||
<result property="city" column="city" />
|
||||
<result property="district" column="district" />
|
||||
<result property="address" column="address" />
|
||||
|
||||
<result property="deptAbbreviation" column="dept_abbreviation" />
|
||||
<result property="remark" column="remark" />
|
||||
<result property="logo" column="logo" />
|
||||
</resultMap>
|
||||
|
||||
<sql id="selectDeptVo">
|
||||
|
|
@ -43,7 +45,10 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
|||
d.province,
|
||||
d.city,
|
||||
d.district,
|
||||
d.address
|
||||
d.address,
|
||||
d.dept_abbreviation,
|
||||
d.remark,
|
||||
d.logo
|
||||
from sys_dept d
|
||||
</sql>
|
||||
|
||||
|
|
@ -155,6 +160,9 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
|||
<if test="city != null and city != ''">city,</if>
|
||||
<if test="district != null and district != ''">district,</if>
|
||||
<if test="address != null and address != ''">address,</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>
|
||||
<if test="status != null">status,</if>
|
||||
<if test="createBy != null and createBy != ''">create_by,</if>
|
||||
create_time
|
||||
|
|
@ -171,6 +179,9 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
|||
<if test="city != null and city != ''">#{city},</if>
|
||||
<if test="district != null and district != ''">#{district},</if>
|
||||
<if test="address != null and address != ''">#{address},</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>
|
||||
<if test="status != null">#{status},</if>
|
||||
<if test="createBy != null and createBy != ''">#{createBy},</if>
|
||||
sysdate()
|
||||
|
|
@ -191,6 +202,9 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
|||
<if test="city != null">city = #{city},</if>
|
||||
<if test="district != null">district = #{district},</if>
|
||||
<if test="address != null">address = #{address},</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>
|
||||
<if test="status != null and status != ''">status = #{status},</if>
|
||||
<if test="updateBy != null and updateBy != ''">update_by = #{updateBy},</if>
|
||||
update_time = sysdate()
|
||||
|
|
|
|||
Loading…
Reference in New Issue