| | |
| | | import com.ycl.system.mapper.SysRoleMapper; |
| | | import com.ycl.system.mapper.SysUserMapper; |
| | | import com.ycl.system.mapper.SysUserRoleMapper; |
| | | import com.ycl.system.model.LoginUser; |
| | | import com.ycl.system.page.PageUtil; |
| | | import com.ycl.platform.service.YwUnitService; |
| | | import com.baomidou.mybatisplus.core.metadata.IPage; |
| | |
| | | import com.ycl.utils.SecurityUtils; |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.beans.BeanUtils; |
| | | import org.springframework.transaction.annotation.Transactional; |
| | | import org.springframework.util.Assert; |
| | | |
| | | import java.util.Objects; |
| | |
| | | * @return |
| | | */ |
| | | @Override |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public Result add(YwUnitForm form) { |
| | | YwUnit entity = YwUnitForm.getEntityByForm(form, null); |
| | | if(baseMapper.insert(entity) > 0) { |
| | |
| | | * @return |
| | | */ |
| | | @Override |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public Result update(YwUnitForm form) { |
| | | YwUnit entity = baseMapper.selectById(form.getId()); |
| | | |
| | |
| | | * @return |
| | | */ |
| | | @Override |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public Result remove(List<String> ids) { |
| | | ids.forEach(id -> { |
| | | // 删除运维人员账号 |
| | | SysUser sysUser = sysUserMapper.selectUserByUserName(baseMapper.selectById(id).getUnitAdminAccount()); |
| | | if (Objects.nonNull(sysUser)) { |
| | | sysUserRoleMapper.deleteUserRoleByUserId(sysUser.getUserId()); |
| | | sysUserMapper.deleteUserById(sysUser.getUserId()); |
| | | } |
| | | }); |
| | | List<Long> userIds = sysUserMapper.selectUserIdByNames( |
| | | baseMapper.selectList( |
| | | new LambdaQueryWrapper<YwUnit>().in(YwUnit::getId, ids)) |
| | | .stream().map(YwUnit::getUnitAdminAccount).toList()); |
| | | if (!userIds.isEmpty()) { |
| | | sysUserMapper.deleteUserByIds(userIds.toArray(new Long[0])); |
| | | sysUserRoleMapper.deleteUserRoleByUserIds(userIds); |
| | | } |
| | | if(baseMapper.deleteBatchIds(ids) > 0) { |
| | | return Result.ok("删除成功"); |
| | | } |
| | |
| | | } |
| | | |
| | | @Override |
| | | public Result workList() { |
| | | List<YwUnitVO> entities = baseMapper.workList(); |
| | | return Result.ok().data(entities); |
| | | } |
| | | |
| | | @Override |
| | | public void setUnitInfo(LoginUser loginUser) { |
| | | // 单位管理员查询 |
| | | YwUnit unit = new LambdaQueryChainWrapper<>(baseMapper) |
| | | .eq(YwUnit::getUnitAdminAccount, loginUser.getUsername()) |
| | | .one(); |
| | | if (Objects.nonNull(unit)) { |
| | | loginUser.setUnitAdmin(Boolean.TRUE); |
| | | loginUser.setUnitId(unit.getId()); |
| | | } else { |
| | | unit = baseMapper.getByUserId(loginUser.getUserId()); |
| | | if (Objects.nonNull(unit)) { |
| | | loginUser.setUnitAdmin(Boolean.FALSE); |
| | | loginUser.setUnitId(unit.getId()); |
| | | } |
| | | else { |
| | | loginUser.setUnitAdmin(Boolean.FALSE); |
| | | } |
| | | } |
| | | } |
| | | |
| | | @Override |
| | | public List<YwUnitVO> export(YwUnitQuery query) { |
| | | // 分页条件查询你 |
| | | IPage<YwUnit> page = new LambdaQueryChainWrapper<>(baseMapper) |