0
点赞
收藏
分享

微信扫一扫

Day34项目saas-export项目-部门管理-删除

回溯 2022-09-15 阅读 142


部门删除分析

  • (1)尝试删除指定id的部门数据
  • (2)如果当前​​部门没有给其他部门作上级​​​,则可以删除成功,否则删除失败
    》1 判断是否有没有给其他部门作上级
    》2 再删除

# 删除时 没有给其他部作上级部门的
delete from pe_dept where dept_id='33'
# 删除时 当前部门给其他部门作上级部门的
delete from pe_dept where dept_id='100101'
# 判断 记录数==0 是可删除的
select * from pe_dept where parent_id='100101'
select count(*) from pe_dept where parent_id='33'

部门删除后台

(1)TestDeptService

@Test
public void test06(){
//给定id
//String deptId="33";
String deptId="100";//有给其他部门作上级
//根据id删除
boolean result=iDeptService.deleteDeptById(deptId);
l.info("test06 result="+result);
}

(2)IDeptService

//根据指定的deptId删除部门数据 当前部门有没有给其他部门作上级
// 》1可以直接删除 》2删除报错
boolean deleteDeptById(String deptId);

(3)DeptServiceImpl

@Override
public boolean deleteDeptById(String deptId) {
//先查询count
int count = iDeptDao.findParentCount(deptId);
//再根据count判断
if(count==0){//没有给其他部门作上级
iDeptDao.deleteById(deptId);
return true;
}else{
return false;
}
}

(4)IDeptDao

int findParentCount(String deptId);
void deleteById(String deptId);

(5)DeptDaoImpl.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>

部门删除前台(没有使用ajax)

dept-list.jsp

​location.href="${path}/system/dept/delete.do?depId="+deptId;​

DeptController

// location.href="${path}/system/dept/delete.do?depId="+deptId;
@RequestMapping(path="/delete",method ={ RequestMethod.GET})
public String delete(String depId){
l.info("delete depId="+depId);

iDeptService.deleteDeptById(depId);

return "redirect:/system/dept/toList.do";//修改完成之后跳到列表页面
}


举报

相关推荐

0 条评论