package org.springblade.zhonnjian.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import lombok.AllArgsConstructor;
import org.springblade.wecom.entity.BladeUserDept;
import org.springblade.wecom.mapper.BladeUserDeptMapper;
import org.springblade.zhonnjian.service.ZjBladeUserDeptService;
import org.springframework.stereotype.Service;

@Service
@AllArgsConstructor
public class ZjBladeUserDeptServiceImpl extends ServiceImpl<BladeUserDeptMapper, BladeUserDept> implements ZjBladeUserDeptService {

    private final BladeUserDeptMapper bladeUserDeptMapper;

    @Override
    public void updateUserDept(Long userId, Long deptId) {
        // 删除用户原有的部门关联
        LambdaQueryWrapper<BladeUserDept> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(BladeUserDept::getUserId, userId);
        bladeUserDeptMapper.delete(wrapper);  // 执行删除SQL

        // 添加新的部门关联
        BladeUserDept userDept = new BladeUserDept();
        userDept.setUserId(userId);
        userDept.setDeptId(deptId);
        bladeUserDeptMapper.insert(userDept);  // 执行插入SQL
    }


}