D5 部门删除的分析sql

分析一下删除的业务逻辑

》编写sql 查询当前部门是否给其他部门作上级

》编写删除 sql 删除指定部门编号的部门数据

各种情况分析

删除时 没有给其他部作上级部门的

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’

具体代码实现

company-list.jsp

function deleteById() {
        var id = getCheckId()
        if(id) {
            if(confirm("你确认要删除此条记录吗?")) {
                location.href="${path}/system/dept/delete.do?depId="+id;
            }
        }else{
            alert("请勾选待处理的记录,且每次只能勾选一个")
        }
    }
    
 <button type="button" class="btn btn-default" title="删除" onclick='deleteById()'><i class="fa fa-trash-o"></i> 删除</button>

DeptController

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

        iDeptService.deleteDeptById(depId);

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

IDeptService

boolean deleteDeptById(String deptId);

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;
        }
    }

IDeptDao

int findParentCount(String deptId);
 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>
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值