| | |
| | | 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业务层处理 |
| | |
| | | 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); |
| | | } |
| | | } |