This commit is contained in:
sxu 2024-08-13 09:51:59 +08:00
parent c1b1f3d673
commit 2aaa299d28
5 changed files with 94 additions and 3 deletions

View File

@ -78,6 +78,20 @@ public class SysDeptController extends BaseController {
} }
/**
* 新增公司
*/
//@RequiresPermissions("system:dept:add")
@Log(title = "公司管理", businessType = BusinessType.INSERT)
@PostMapping(value = "/addCompany")
public AjaxResult addCompany(@RequestBody List<SysDept> list) {
if (!deptService.checkCompaniesNameUnique(list)) {
return error("新增公司失败,其中有些公司名称已存在");
}
return toAjax(deptService.insertCompanies(list));
}
/** /**
* 新增部门 * 新增部门
*/ */

View File

@ -68,6 +68,8 @@ public interface SysDeptMapper
*/ */
public int checkDeptExistUser(Long deptId); public int checkDeptExistUser(Long deptId);
public int checkCompaniesNameUnique(@Param("depts") List<SysDept> list);
/** /**
* 校验部门名称是否唯一 * 校验部门名称是否唯一
* *
@ -77,6 +79,8 @@ public interface SysDeptMapper
*/ */
public SysDept checkDeptNameUnique(@Param("deptName") String deptName, @Param("parentId") Long parentId); public SysDept checkDeptNameUnique(@Param("deptName") String deptName, @Param("parentId") Long parentId);
public int insertCompanies(@Param("depts") List<SysDept> list);
/** /**
* 新增部门信息 * 新增部门信息
* *
@ -124,4 +128,6 @@ public interface SysDeptMapper
List<SysDept> selectDeptByAncestors(String[] deptIds); List<SysDept> selectDeptByAncestors(String[] deptIds);
String getCompanyByAncestors(String split); String getCompanyByAncestors(String split);
int getMaxDeptId();
} }

View File

@ -83,6 +83,7 @@ public interface ISysDeptService
*/ */
public boolean checkDeptExistUser(Long deptId); public boolean checkDeptExistUser(Long deptId);
public boolean checkCompaniesNameUnique(List<SysDept> list);
/** /**
* 校验部门名称是否唯一 * 校验部门名称是否唯一
* *
@ -98,6 +99,8 @@ public interface ISysDeptService
*/ */
public void checkDeptDataScope(Long deptId); public void checkDeptDataScope(Long deptId);
public int insertCompanies(List<SysDept> list);
/** /**
* 新增保存部门信息 * 新增保存部门信息
* *

View File

@ -10,16 +10,20 @@ import com.bonus.sgzb.common.security.utils.SecurityUtils;
import com.bonus.sgzb.system.api.domain.SysDept; import com.bonus.sgzb.system.api.domain.SysDept;
import com.bonus.sgzb.system.api.domain.SysRole; import com.bonus.sgzb.system.api.domain.SysRole;
import com.bonus.sgzb.system.api.domain.SysUser; import com.bonus.sgzb.system.api.domain.SysUser;
import com.bonus.sgzb.system.api.model.LoginUser;
import com.bonus.sgzb.system.domain.vo.TreeSelect; import com.bonus.sgzb.system.domain.vo.TreeSelect;
import com.bonus.sgzb.system.mapper.SysDeptMapper; import com.bonus.sgzb.system.mapper.SysDeptMapper;
import com.bonus.sgzb.system.mapper.SysRoleMapper; import com.bonus.sgzb.system.mapper.SysRoleMapper;
import com.bonus.sgzb.system.mapper.SysUserMapper;
import com.bonus.sgzb.system.service.ISysDeptService; import com.bonus.sgzb.system.service.ISysDeptService;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Iterator; import java.util.Iterator;
import java.util.List; import java.util.List;
import java.util.Objects;
import java.util.stream.Collectors; import java.util.stream.Collectors;
/** /**
@ -29,12 +33,15 @@ import java.util.stream.Collectors;
*/ */
@Service @Service
public class SysDeptServiceImpl implements ISysDeptService { public class SysDeptServiceImpl implements ISysDeptService {
@Autowired @Resource
private SysDeptMapper deptMapper; private SysDeptMapper deptMapper;
@Autowired @Resource
private SysRoleMapper roleMapper; private SysRoleMapper roleMapper;
@Resource
private SysUserMapper userMapper;
/** /**
* 查询部门管理数据 * 查询部门管理数据
* *
@ -152,6 +159,12 @@ public class SysDeptServiceImpl implements ISysDeptService {
return result > 0; return result > 0;
} }
@Override
public boolean checkCompaniesNameUnique(List<SysDept> list) {
int count = deptMapper.checkCompaniesNameUnique(list);
return count == 0;
}
/** /**
* 校验部门名称是否唯一 * 校验部门名称是否唯一
* *
@ -185,6 +198,29 @@ public class SysDeptServiceImpl implements ISysDeptService {
} }
} }
@Override
public int insertCompanies(List<SysDept> list) {
long num = deptMapper.getMaxDeptId()+1;
for (SysDept dept : list) {
dept.setCreateBy(SecurityUtils.getUsername());
dept.setParentId(0L);
dept.setAncestors("0");
dept.setOrderNum(999);
dept.setStatus("0");
long nextMultiple = (int) Math.ceil((double) num / 100) * 100;
num = nextMultiple + 1;
dept.setDeptId(nextMultiple);
dept.setCompanyId(nextMultiple);
}
return deptMapper.insertCompanies(list);
}
// public static void main(String[] args) {
// int num = 1200;
// long nextMultiple = (int) Math.ceil((double) num / 100) * 100;
// System.out.print(num);
// }
/** /**
* 新增保存部门信息 * 新增保存部门信息
* *

View File

@ -21,11 +21,12 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<result property="updateBy" column="update_by" /> <result property="updateBy" column="update_by" />
<result property="updateTime" column="update_time" /> <result property="updateTime" column="update_time" />
<result property="remark" column="remark" /> <result property="remark" column="remark" />
<result property="companyId" column="company_id" />
</resultMap> </resultMap>
<sql id="selectDeptVo"> <sql id="selectDeptVo">
select d.dept_id, d.parent_id, d.ancestors, d.dept_name, d.order_num, d.leader, d.phone, d.email, d.status, d.del_flag, d.create_by, d.create_time, select d.dept_id, d.parent_id, d.ancestors, d.dept_name, d.order_num, d.leader, d.phone, d.email, d.status, d.del_flag, d.create_by, d.create_time,
d.remark d.remark,d.company_id
from sys_dept d from sys_dept d
</sql> </sql>
@ -44,6 +45,9 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<if test="status != null and status != ''"> <if test="status != null and status != ''">
AND status = #{status} AND status = #{status}
</if> </if>
<if test="companyId != null and companyId != ''">
AND company_id = #{companyId}
</if>
<!-- 数据范围过滤 --> <!-- 数据范围过滤 -->
${params.dataScope} ${params.dataScope}
order by d.parent_id, d.order_num order by d.parent_id, d.order_num
@ -81,11 +85,32 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<select id="selectNormalChildrenDeptById" parameterType="Long" resultType="int"> <select id="selectNormalChildrenDeptById" parameterType="Long" resultType="int">
select count(*) from sys_dept where status = 0 and del_flag = '0' and find_in_set(#{deptId}, ancestors) select count(*) from sys_dept where status = 0 and del_flag = '0' and find_in_set(#{deptId}, ancestors)
</select> </select>
<select id="checkCompaniesNameUnique" resultType="java.lang.Integer">
select count(*)
from sys_dept
where dept_name in
<foreach collection="depts" item="item" index="index" separator="," open="(" close=")">
#{item.deptName}
</foreach>
</select>
<select id="checkDeptNameUnique" resultMap="SysDeptResult"> <select id="checkDeptNameUnique" resultMap="SysDeptResult">
<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>
<insert id="insertCompanies" parameterType="com.bonus.sgzb.system.api.domain.SysDept">
insert into sys_dept(
dept_id,parent_id,dept_name,ancestors,order_num,leader,phone,email,status,create_by,company_id,create_time)
values
<foreach item="item" index="index" collection="depts" separator=",">
(
#{item.deptId},#{item.parentId},#{item.deptName},#{item.ancestors},#{item.orderNum},#{item.leader},
#{item.phone},#{item.email},#{item.status},#{item.createBy},#{item.companyId},sysdate()
)
</foreach>
</insert>
<insert id="insertDept" parameterType="com.bonus.sgzb.system.api.domain.SysDept"> <insert id="insertDept" parameterType="com.bonus.sgzb.system.api.domain.SysDept">
insert into sys_dept( insert into sys_dept(
@ -99,6 +124,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<if test="email != null and email != ''">email,</if> <if test="email != null and email != ''">email,</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="companyId != null and companyId != ''">company_id,</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>
@ -111,6 +137,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<if test="email != null and email != ''">#{email},</if> <if test="email != null and email != ''">#{email},</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="companyId != null and companyId != ''">#{companyId},</if>
sysdate() sysdate()
) )
</insert> </insert>
@ -165,4 +192,9 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<select id="getCompanyByAncestors" resultType="java.lang.String"> <select id="getCompanyByAncestors" resultType="java.lang.String">
select dept_name from sys_dept where parent_id = #{split} select dept_name from sys_dept where parent_id = #{split}
</select> </select>
<select id="getMaxDeptId" resultType="java.lang.Integer">
select max(dept_id)
from sys_dept
</select>
</mapper> </mapper>