| | |
| | | package com.mindskip.xzs.service.impl; |
| | | |
| | | import com.baomidou.mybatisplus.extension.conditions.query.LambdaQueryChainWrapper; |
| | | import com.github.pagehelper.PageHelper; |
| | | import com.github.pagehelper.PageInfo; |
| | | import com.mindskip.xzs.domain.Department; |
| | | import com.mindskip.xzs.domain.UserDepartment; |
| | | import com.mindskip.xzs.domain.enums.DeptAdminEnum; |
| | | import com.mindskip.xzs.domain.vo.BaseSelect; |
| | | import com.mindskip.xzs.domain.vo.UpdateDeptAdminVO; |
| | |
| | | import org.modelmapper.ModelMapper; |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.transaction.annotation.Transactional; |
| | | import org.springframework.util.CollectionUtils; |
| | | |
| | | import java.util.List; |
| | | import java.util.Objects; |
| | | import java.util.stream.Collectors; |
| | | |
| | | @Service |
| | | public class DepartmentServiceImpl extends BaseServiceImpl<Department> implements DepartmentService { |
| | |
| | | if (Objects.isNull(entity)) { |
| | | throw new RuntimeException("该部门不存在"); |
| | | } |
| | | if (Objects.nonNull(department.getAdminId())) { |
| | | if (! Objects.equals(entity.getAdminId(), department.getAdminId())) { |
| | | // 取消原先的管理员标识 |
| | | List<Integer> depIds = departmentMapper.selectByAdminId(entity.getAdminId()); |
| | | depIds.remove(department.getId()); |
| | | if (depIds.size() < 1) { |
| | | userMapper.updateDeptAdmin(entity.getAdminId(), DeptAdminEnum.NO.getValue()); |
| | | } |
| | | if (! CollectionUtils.isEmpty(department.getAdminId())) { |
| | | List<BaseSelect> deptUserList = userDepartmentMapper.getDeptUserList(entity.getId()); |
| | | List<Integer> userIds = deptUserList.stream().map(BaseSelect::getId).collect(Collectors.toList()); |
| | | if (! CollectionUtils.isEmpty(userIds)) { |
| | | // 先清除之前的管理员标识 |
| | | userMapper.clearDeptAdmin(userIds, entity.getId()); |
| | | } |
| | | // 标识部门管理员 |
| | | userMapper.updateDeptAdmin(department.getAdminId(), DeptAdminEnum.YES.getValue()); |
| | | userMapper.updateDeptAdmin(department.getAdminId(), DeptAdminEnum.YES.getValue(), entity.getId()); |
| | | } |
| | | Integer update = departmentMapper.update(department); |
| | | return update; |
| | |
| | | } |
| | | |
| | | @Override |
| | | public List<Department> gets() { |
| | | return departmentMapper.gets(); |
| | | public List<Department> gets(List<Integer> deptId) { |
| | | return departmentMapper.gets(deptId); |
| | | } |
| | | |
| | | @Override |
| | |
| | | } |
| | | |
| | | @Override |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public void updateAdmin(UpdateDeptAdminVO form) { |
| | | Department entity = departmentMapper.getById(form.getId()); |
| | | if (Objects.isNull(form)) { |
| | | if (Objects.isNull(entity)) { |
| | | throw new RuntimeException("该部门不存在"); |
| | | } |
| | | if (Objects.nonNull(form.getAdminId())) { |
| | | if (! Objects.equals(entity.getAdminId(), form.getAdminId())) { |
| | | // 取消原先的管理员标识 |
| | | List<Integer> depIds = departmentMapper.selectByAdminId(entity.getAdminId()); |
| | | depIds.remove(form.getId()); |
| | | if (depIds.size() < 1) { |
| | | userMapper.updateDeptAdmin(entity.getAdminId(), DeptAdminEnum.NO.getValue()); |
| | | } |
| | | if (! CollectionUtils.isEmpty(form.getAdminIds())) { |
| | | List<BaseSelect> deptUserList = userDepartmentMapper.getDeptUserList(entity.getId()); |
| | | List<Integer> userIds = deptUserList.stream().map(BaseSelect::getId).collect(Collectors.toList()); |
| | | if (! CollectionUtils.isEmpty(userIds)) { |
| | | // 先清除之前的管理员标识 |
| | | userMapper.clearDeptAdmin(userIds, entity.getId()); |
| | | } |
| | | // 标识部门管理员 |
| | | userMapper.updateDeptAdmin(form.getAdminId(), DeptAdminEnum.YES.getValue()); |
| | | userMapper.updateDeptAdmin(form.getAdminIds(), DeptAdminEnum.YES.getValue(), entity.getId()); |
| | | } |
| | | entity.setAdminId(form.getAdminId()); |
| | | departmentMapper.update(entity); |
| | | // 修改被选择的用户为部门管理员 |
| | | userMapper.updateUserDeptAdmin(form); |
| | | // 修改没被选择的用户并且不是别的部门管理员的用户角色为1 |
| | | userMapper.cancelUserDeptAdmin(form); |
| | | } |
| | | } |