From 9be455a2867571a85c0e9b8e591cb1f52bca1287 Mon Sep 17 00:00:00 2001 From: sxu <602087911@qq.com> Date: Tue, 23 Jul 2024 16:31:42 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A4=9A=E5=85=AC=E5=8F=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../system/controller/SysDeptController.java | 14 ++++++++++ .../sgzb/system/mapper/SysDeptMapper.java | 6 ++++ .../sgzb/system/service/ISysDeptService.java | 3 ++ .../service/impl/SysDeptServiceImpl.java | 28 +++++++++++++++++++ .../resources/mapper/system/SysDeptMapper.xml | 26 +++++++++++++++++ 5 files changed, 77 insertions(+) diff --git a/sgzb-modules/sgzb-system/src/main/java/com/bonus/sgzb/system/controller/SysDeptController.java b/sgzb-modules/sgzb-system/src/main/java/com/bonus/sgzb/system/controller/SysDeptController.java index 0b878163..df3f901d 100644 --- a/sgzb-modules/sgzb-system/src/main/java/com/bonus/sgzb/system/controller/SysDeptController.java +++ b/sgzb-modules/sgzb-system/src/main/java/com/bonus/sgzb/system/controller/SysDeptController.java @@ -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 list) { + if (!deptService.checkCompaniesNameUnique(list)) { + return error("新增公司失败,其中有些公司名称已存在"); + } + return toAjax(deptService.insertCompanies(list)); + } + + /** * 新增部门 */ diff --git a/sgzb-modules/sgzb-system/src/main/java/com/bonus/sgzb/system/mapper/SysDeptMapper.java b/sgzb-modules/sgzb-system/src/main/java/com/bonus/sgzb/system/mapper/SysDeptMapper.java index 6833da7e..e3105008 100644 --- a/sgzb-modules/sgzb-system/src/main/java/com/bonus/sgzb/system/mapper/SysDeptMapper.java +++ b/sgzb-modules/sgzb-system/src/main/java/com/bonus/sgzb/system/mapper/SysDeptMapper.java @@ -68,6 +68,8 @@ public interface SysDeptMapper */ public int checkDeptExistUser(Long deptId); + public int checkCompaniesNameUnique(@Param("depts") List list); + /** * 校验部门名称是否唯一 * @@ -77,6 +79,8 @@ public interface SysDeptMapper */ public SysDept checkDeptNameUnique(@Param("deptName") String deptName, @Param("parentId") Long parentId); + public int insertCompanies(@Param("depts") List list); + /** * 新增部门信息 * @@ -124,4 +128,6 @@ public interface SysDeptMapper List selectDeptByAncestors(String[] deptIds); String getCompanyByAncestors(String split); + + int getMaxDeptId(); } diff --git a/sgzb-modules/sgzb-system/src/main/java/com/bonus/sgzb/system/service/ISysDeptService.java b/sgzb-modules/sgzb-system/src/main/java/com/bonus/sgzb/system/service/ISysDeptService.java index 784e594a..f0a8e541 100644 --- a/sgzb-modules/sgzb-system/src/main/java/com/bonus/sgzb/system/service/ISysDeptService.java +++ b/sgzb-modules/sgzb-system/src/main/java/com/bonus/sgzb/system/service/ISysDeptService.java @@ -83,6 +83,7 @@ public interface ISysDeptService */ public boolean checkDeptExistUser(Long deptId); + public boolean checkCompaniesNameUnique(List list); /** * 校验部门名称是否唯一 * @@ -98,6 +99,8 @@ public interface ISysDeptService */ public void checkDeptDataScope(Long deptId); + public int insertCompanies(List list); + /** * 新增保存部门信息 * diff --git a/sgzb-modules/sgzb-system/src/main/java/com/bonus/sgzb/system/service/impl/SysDeptServiceImpl.java b/sgzb-modules/sgzb-system/src/main/java/com/bonus/sgzb/system/service/impl/SysDeptServiceImpl.java index 5194b9f6..868c2554 100644 --- a/sgzb-modules/sgzb-system/src/main/java/com/bonus/sgzb/system/service/impl/SysDeptServiceImpl.java +++ b/sgzb-modules/sgzb-system/src/main/java/com/bonus/sgzb/system/service/impl/SysDeptServiceImpl.java @@ -162,6 +162,12 @@ public class SysDeptServiceImpl implements ISysDeptService { return result > 0; } + @Override + public boolean checkCompaniesNameUnique(List list) { + int count = deptMapper.checkCompaniesNameUnique(list); + return count == 0; + } + /** * 校验部门名称是否唯一 * @@ -195,6 +201,28 @@ public class SysDeptServiceImpl implements ISysDeptService { } } + @Override + public int insertCompanies(List list) { + int num = deptMapper.getMaxDeptId() + 1; + long nextMultiple = (int) Math.ceil((double) num / 100) * 100; + for (SysDept dept : list) { + dept.setCreateBy(SecurityUtils.getUsername()); + dept.setParentId(0L); + dept.setAncestors("0"); + dept.setOrderNum(999); + dept.setStatus("0"); + 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); +// } + /** * 新增保存部门信息 * diff --git a/sgzb-modules/sgzb-system/src/main/resources/mapper/system/SysDeptMapper.xml b/sgzb-modules/sgzb-system/src/main/resources/mapper/system/SysDeptMapper.xml index 8f94a006..21c037fb 100644 --- a/sgzb-modules/sgzb-system/src/main/resources/mapper/system/SysDeptMapper.xml +++ b/sgzb-modules/sgzb-system/src/main/resources/mapper/system/SysDeptMapper.xml @@ -85,11 +85,32 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" + + + + + insert into sys_dept( + dept_id,parent_id,dept_name,ancestors,order_num,leader,phone,email,status,create_by,company_id,create_time) + values + + ( + #{item.deptId},#{item.parentId},#{item.deptName},#{item.ancestors},#{item.orderNum},#{item.leader}, + #{item.phone},#{item.email},#{item.status},#{item.createBy},#{item.companyId},sysdate() + ) + + insert into sys_dept( @@ -171,4 +192,9 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" + + \ No newline at end of file