ZQN
2024-06-24 b0402b407292f0708a1684cc0ca1d5e2d890b753
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
package com.project.system.service.impl;
 
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.project.common.exception.base.BaseException;
import com.project.common.utils.StringUtils;
import com.project.system.domain.SysUserDept;
import com.project.system.domain.bo.editBo.UserDeptBo;
import com.project.system.domain.vo.UserDeptVo;
import com.project.system.mapper.SysUserDeptMapper;
import com.project.system.service.ISysUserDeptService;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
 
import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;
 
/**
 * 用户与部门关联Service业务层处理
 *
 * @author manton
 */
@Service
@RequiredArgsConstructor(onConstructor_ = @Autowired)
public class SysUserDeptServiceImpl extends ServiceImpl<SysUserDeptMapper, SysUserDept> implements ISysUserDeptService {
 
 
    /**
     * 用户多机构回显
     * @param userId    用户id
     * @return  内容
     */
    @Override
    public UserDeptVo batchUserDeptView(Long userId)
    {
        List<SysUserDept> list = this.list(lq().eq(SysUserDept::getUserId, userId));
        List<Long> deptIds = list.stream().map(SysUserDept::getDeptId).collect(Collectors.toList());
        UserDeptVo vo = new UserDeptVo();
        vo.setUserId(userId);
        vo.setDeptIds(deptIds);
        return vo;
    }
 
    /**
     * 用户多机构保存
     * @param bo    参数
     * @return  结果
     */
    @Override
    @Transactional
    public Boolean batchUserDeptSave(UserDeptBo bo)
    {
        Long userId = bo.getUserId();
        if (userId==null || StringUtils.isEmpty(bo.getDeptIds())){
            throw new BaseException("参数有误!");
        }
        this.remove(lq().eq(SysUserDept::getUserId, userId));
        List<SysUserDept> saveList = new ArrayList<>();
        for (Long deptId : bo.getDeptIds()) {
            saveList.add(new SysUserDept().setUserId(userId).setDeptId(deptId));
        }
        return this.saveBatch(saveList);
    }
}