部门删除分析
- 尝试删除指定id的部门数据
- 如果当前部门没有给其他部门作上级,则可以删除成功,否则删除失败
》1 判断是否有没有给其他部门作上级
》2 再删除
# 判断 记录数==0 是可删除的
select count(*) from pe_dept where parent_id=#{deptId}
delete from pe_dept where dept_id=#{deptId}
部门删除后台
TestDeptService
@Test
public void test06(){
//String deptId="75afe393-5f49-49d6-b966-bc79d52e451e";
String deptId="100";
boolean result=service.deleteDeptById(deptId);
l.info("test06 result="+result);
}
IDeptService
boolean deleteDeptById(String deptId);
DeptServiceImpl
@Override
public boolean deleteDeptById(String deptId) {
//先查询count
int count=dao.findParentCount(deptId);
//再根据count判断
if(count==0) {
dao.deleteById(deptId);
return true;
}else {
return false;
}
}
IDeptDao
void deleteById(String deptId);
IDeptDao.xml
<!-- 统计当前部门作为其他部门的上级的数量-->
<select id="findParentCount" parameterType="string" resultType="int">
select count(*) from pe_dept where parent_id=#{deptId}
</select>
<!-- 删除指定deptId的部门-->
<delete id="deleteById" parameterType="string">
delete from pe_dept where dept_id=#{deptId}
</delete>
部门删除前台
dept-list.jsp
location.href="${path}/system/dept/delete.do?deptId="+deptId;
DeptController
//location.href="${path}/system/dept/delete.do?deptId="+deptId;
@RequestMapping(path = "/delete",method =RequestMethod.GET)
public String delete(String deptId){
l.info("delete deptId="+deptId);
service.deleteDeptById(deptId);
return "redirect:/system/dept/toList.do";
}