diff --git a/yanzhu-common/src/main/java/com/yanzhu/common/core/domain/TreeSelect.java b/yanzhu-common/src/main/java/com/yanzhu/common/core/domain/TreeSelect.java index a657658..9f82f49 100644 --- a/yanzhu-common/src/main/java/com/yanzhu/common/core/domain/TreeSelect.java +++ b/yanzhu-common/src/main/java/com/yanzhu/common/core/domain/TreeSelect.java @@ -26,6 +26,15 @@ public class TreeSelect implements Serializable @JsonInclude(JsonInclude.Include.NON_EMPTY) private List children; + public Object getData() { + return data; + } + + public void setData(Object data) { + this.data = data; + } + + private Object data; public TreeSelect() { @@ -35,6 +44,7 @@ public class TreeSelect implements Serializable { this.id = dept.getDeptId(); this.label = dept.getDeptName(); + this.data=dept; this.children = dept.getChildren().stream().map(TreeSelect::new).collect(Collectors.toList()); } diff --git a/yanzhu-framework/src/main/java/com/yanzhu/framework/web/service/UserDetailsServiceImpl.java b/yanzhu-framework/src/main/java/com/yanzhu/framework/web/service/UserDetailsServiceImpl.java index 9ee552c..3cbd708 100644 --- a/yanzhu-framework/src/main/java/com/yanzhu/framework/web/service/UserDetailsServiceImpl.java +++ b/yanzhu-framework/src/main/java/com/yanzhu/framework/web/service/UserDetailsServiceImpl.java @@ -62,7 +62,8 @@ public class UserDetailsServiceImpl implements UserDetailsService //设置项目单位信息 if(!user.isAdmin()){ - Long deptId = Convert.toLong(user.getDept().getAncestors().split(",")[3]); + String[] tmps=user.getDept().getAncestors().split(","); + Long deptId = Convert.toLong(tmps[tmps.length-1]); if(deptId != null){ SysDept sysDept = sysDeptService.selectDeptById(deptId); user.setParDeptId(sysDept.getDeptId()); @@ -70,7 +71,7 @@ public class UserDetailsServiceImpl implements UserDetailsService } }else{ user.setParDeptId(100L); - user.setParDeptName("研筑临时项目管理"); + user.setParDeptName("中铁建设集团有限公司"); } passwordService.validate(user); return createLoginUser(user); diff --git a/yanzhu-manage/src/main/java/com/yanzhu/web/CompanyController.java b/yanzhu-manage/src/main/java/com/yanzhu/web/CompanyController.java index 0dc4741..d5b69bc 100644 --- a/yanzhu-manage/src/main/java/com/yanzhu/web/CompanyController.java +++ b/yanzhu-manage/src/main/java/com/yanzhu/web/CompanyController.java @@ -1,8 +1,11 @@ package com.yanzhu.web; +import com.yanzhu.common.annotation.Log; import com.yanzhu.common.core.controller.BaseController; import com.yanzhu.common.core.domain.AjaxResult; import com.yanzhu.common.core.domain.entity.SysDept; +import com.yanzhu.common.enums.BusinessType; +import com.yanzhu.framework.web.domain.server.Sys; import com.yanzhu.system.service.ISysDeptService; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.security.access.prepost.PreAuthorize; @@ -17,7 +20,7 @@ public class CompanyController extends BaseController { private ISysDeptService deptService; - @PreAuthorize("@ss.hasPermi('project:company:list')") + @PreAuthorize("@ss.hasAnyPermi('project:company:list')") @PostMapping("/list") public AjaxResult companyList(@RequestBody SysDept where) { @@ -27,4 +30,30 @@ public class CompanyController extends BaseController { return success(depts); } + @PreAuthorize("@ss.hasAnyPermi('project:subCompany:list')") + @PostMapping("/subList") + public AjaxResult subList(@RequestBody SysDept where){ + where.setDelFlag("0"); + List depts = deptService.selectDeptList(where); + return success(depts); + } + @PreAuthorize("@ss.hasAnyPermi('project:subCompany:delete')") + @Log(title = "段队管理", businessType = BusinessType.DELETE) + @DeleteMapping("/{deptId}") + public AjaxResult remove(@PathVariable Long deptId) { + return toAjax(deptService.deleteDeepDeptById(deptId)); + } + + @PreAuthorize("@ss.hasAnyPermi('project:subCompany:add')") + @Log(title = "段队管理", businessType = BusinessType.INSERT) + @PostMapping("/addSubCompany") + public AjaxResult addSubCompany(@RequestBody SysDept dept){ + if (!deptService.checkDeptNameUnique(dept)) + { + return error("新增部门'" + dept.getDeptName() + "'失败,部门名称已存在"); + } + dept.setCreateBy(getUsername()); + return toAjax(deptService.insertSubCompany(dept)); + } + } diff --git a/yanzhu-system/src/main/java/com/yanzhu/system/mapper/SysDeptMapper.java b/yanzhu-system/src/main/java/com/yanzhu/system/mapper/SysDeptMapper.java index 2bfd815..b916043 100644 --- a/yanzhu-system/src/main/java/com/yanzhu/system/mapper/SysDeptMapper.java +++ b/yanzhu-system/src/main/java/com/yanzhu/system/mapper/SysDeptMapper.java @@ -116,4 +116,5 @@ public interface SysDeptMapper */ public int deleteDeptById(Long deptId); + public int deleteDeepDeptById(Long deptId); } diff --git a/yanzhu-system/src/main/java/com/yanzhu/system/service/ISysDeptService.java b/yanzhu-system/src/main/java/com/yanzhu/system/service/ISysDeptService.java index 114f1b4..2591407 100644 --- a/yanzhu-system/src/main/java/com/yanzhu/system/service/ISysDeptService.java +++ b/yanzhu-system/src/main/java/com/yanzhu/system/service/ISysDeptService.java @@ -129,4 +129,13 @@ public interface ISysDeptService * @return 结果 */ public List findChildList(Long deptId); + + /** + * 级联删除 + * @param deptId + * @return + */ + public int deleteDeepDeptById(Long deptId); + + public int insertSubCompany(SysDept dept); } diff --git a/yanzhu-system/src/main/java/com/yanzhu/system/service/impl/SysDeptServiceImpl.java b/yanzhu-system/src/main/java/com/yanzhu/system/service/impl/SysDeptServiceImpl.java index f4c7faf..b1b77be 100644 --- a/yanzhu-system/src/main/java/com/yanzhu/system/service/impl/SysDeptServiceImpl.java +++ b/yanzhu-system/src/main/java/com/yanzhu/system/service/impl/SysDeptServiceImpl.java @@ -1,6 +1,7 @@ package com.yanzhu.system.service.impl; import java.util.ArrayList; +import java.util.Date; import java.util.Iterator; import java.util.List; import java.util.stream.Collectors; @@ -213,14 +214,40 @@ public class SysDeptServiceImpl implements ISysDeptService { SysDept info = deptMapper.selectDeptById(dept.getParentId()); // 如果父节点不为正常状态,则不允许新增子节点 - if (!UserConstants.DEPT_NORMAL.equals(info.getStatus())) + if (UserConstants.DEPT_DISABLE.equals(info.getStatus())) { throw new ServiceException("部门停用,不允许新增"); } dept.setAncestors(info.getAncestors() + "," + dept.getParentId()); return deptMapper.insertDept(dept); } - + @Override + public int insertSubCompany(SysDept dept) { + SysDept info = deptMapper.selectDeptById(dept.getParentId()); + // 如果父节点不为正常状态,则不允许新增子节点 + if (UserConstants.DEPT_DISABLE.equals(info.getStatus())) + { + throw new ServiceException("部门停用,不允许新增"); + } + dept.setStatus("3"); + dept.setAncestors(info.getAncestors() + "," + dept.getParentId()); + int id=deptMapper.insertDept(dept); + String[] subDepts="成本部,行政部,工程部".split(","); + for(String it:subDepts){ + SysDept dpt=new SysDept(); + dpt.setParentId(dept.getDeptId()); + dpt.setAncestors(dept.getAncestors()+","+dpt.getParentId()); + dpt.setDeptName(it); + dpt.setCreateBy(dept.getCreateBy()); + dpt.setCreateTime(new Date()); + dpt.setPhone(dept.getPhone()); + dpt.setEmail(dept.getPhone()); + dpt.setLeader(dept.getLeader()); + dpt.setStatus("4"); + deptMapper.insertDept(dpt); + } + return id; + } /** * 修改保存部门信息 * @@ -347,4 +374,11 @@ public class SysDeptServiceImpl implements ISysDeptService sysDept.setParentId(deptId); return deptMapper.selectDeptList(sysDept); } + + @Override + public int deleteDeepDeptById(Long deptId) { + return deptMapper.deleteDeepDeptById(deptId); + } + + } diff --git a/yanzhu-system/src/main/resources/mapper/system/SysDeptMapper.xml b/yanzhu-system/src/main/resources/mapper/system/SysDeptMapper.xml index e28af36..70c1984 100644 --- a/yanzhu-system/src/main/resources/mapper/system/SysDeptMapper.xml +++ b/yanzhu-system/src/main/resources/mapper/system/SysDeptMapper.xml @@ -88,7 +88,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" where dept_name=#{deptName} and parent_id = #{parentId} and del_flag = '0' limit 1 - + insert into sys_dept( dept_id, parent_id, @@ -160,4 +160,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" update sys_dept set del_flag = '2' where dept_id = #{deptId} + + update sys_dept set del_flag = '2' where ancestors like concat('%,', #{deptId}, ',%') or dept_id = #{deptId} + \ No newline at end of file diff --git a/yanzhu-system/src/main/resources/mapper/system/SysUserMapper.xml b/yanzhu-system/src/main/resources/mapper/system/SysUserMapper.xml index 4914fb5..4affe8b 100644 --- a/yanzhu-system/src/main/resources/mapper/system/SysUserMapper.xml +++ b/yanzhu-system/src/main/resources/mapper/system/SysUserMapper.xml @@ -57,8 +57,12 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"