| | |
| | | package com.doumee.service.business.impl; |
| | | |
| | | import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
| | | import com.doumee.core.constants.ResponseStatus; |
| | | import com.doumee.core.exception.BusinessException; |
| | | import com.doumee.core.model.LoginUserInfo; |
| | |
| | | @Override |
| | | public Integer create(DeviceRole deviceRole) { |
| | | |
| | | QueryWrapper<DeviceRole> query = new QueryWrapper<>(); |
| | | query.lambda() |
| | | .eq(DeviceRole::getIsdeleted,Constants.ZERO) |
| | | .eq(DeviceRole::getType,deviceRole.getType()) |
| | | .eq(DeviceRole::getStatus,Constants.ONE); |
| | | List<DeviceRole> deviceRoles = deviceRoleMapper.selectList(query); |
| | | if (CollectionUtils.isNotEmpty(deviceRoles) && Constants.equalsInteger(Constants.ONE,deviceRole.getStatus())){ |
| | | throw new BusinessException(ResponseStatus.DATA_EXISTS.getCode(),"管理内部员工只能有一个默认门禁组"); |
| | | // 获取之前是否存在默认门禁组 |
| | | DeviceRole newDeviceRole = null; |
| | | if(Constants.ONE == deviceRole.getStatus()) { |
| | | newDeviceRole = getDeviceRole(deviceRole.getStatus()); |
| | | } |
| | | |
| | | LoginUserInfo loginUserInfo = (LoginUserInfo)SecurityUtils.getSubject().getPrincipal(); |
| | | if(null != newDeviceRole) { |
| | | DeviceRole updateDeviceRole = new DeviceRole(); |
| | | // 若现在新增数据设置默认门禁组;那么先把之前的默认门禁组状态改为不是默认的 |
| | | updateDeviceRole.setId(newDeviceRole.getId()); |
| | | updateDeviceRole.setEdirot(loginUserInfo.getId().toString()); |
| | | updateDeviceRole.setEditDate(new Date()); |
| | | updateDeviceRole.setIsdeleted(Constants.ONE); |
| | | updateDeviceRole.setStatus(Constants.ZERO); |
| | | deviceRoleMapper.updateById(updateDeviceRole); |
| | | } |
| | | DeviceRole insert = new DeviceRole(); |
| | | |
| | | insert.setCreator(loginUserInfo.getId().toString()); |
| | | insert.setCreateDate(new Date()); |
| | | insert.setEdirot(loginUserInfo.getId().toString()); |
| | |
| | | |
| | | @Override |
| | | public void updateById(DeviceRole deviceRole) { |
| | | |
| | | QueryWrapper<DeviceRole> query = new QueryWrapper<>(); |
| | | query.lambda() |
| | | .eq(DeviceRole::getIsdeleted,Constants.ZERO) |
| | | .eq(DeviceRole::getType,deviceRole.getType()) |
| | | .eq(DeviceRole::getStatus,Constants.ONE); |
| | | List<DeviceRole> deviceRoles = deviceRoleMapper.selectList(query); |
| | | if (CollectionUtils.isNotEmpty(deviceRoles) && Constants.equalsInteger(Constants.ONE,deviceRole.getStatus())){ |
| | | throw new BusinessException(ResponseStatus.DATA_EXISTS.getCode(),"管理内部员工只能有一个默认门禁组"); |
| | | } |
| | | deviceRole.setIsDefault(Constants.equalsInteger(Constants.ONE,deviceRole.getStatus()) ? 0 : 1); |
| | | deviceRoleMapper.updateById(deviceRole); |
| | | } |
| | | |
| | | @Override |
| | | public void updateStatusById(DeviceRole deviceRole) { |
| | | QueryWrapper<DeviceRole> query = new QueryWrapper<>(); |
| | | query.lambda() |
| | | .eq(DeviceRole::getIsdeleted,Constants.ZERO) |
| | | .eq(DeviceRole::getType,deviceRole.getType()) |
| | | .eq(DeviceRole::getStatus,Constants.ONE); |
| | | List<DeviceRole> deviceRoles = deviceRoleMapper.selectList(query); |
| | | if (CollectionUtils.isNotEmpty(deviceRoles) && Constants.equalsInteger(Constants.ONE,deviceRole.getStatus())){ |
| | | throw new BusinessException(ResponseStatus.DATA_EXISTS.getCode(),"管理内部员工只能有一个默认门禁组"); |
| | | // 获取之前是否存在默认门禁组 |
| | | DeviceRole newDeviceRole = null; |
| | | if(Constants.ZERO == deviceRole.getIsDefault()) { |
| | | newDeviceRole = getDeviceRole(deviceRole.getIsDefault()); |
| | | } |
| | | LoginUserInfo loginUserInfo = (LoginUserInfo)SecurityUtils.getSubject().getPrincipal(); |
| | | DeviceRole update = new DeviceRole(); |
| | | update.setEdirot(loginUserInfo.getId().toString()); |
| | | update.setEditDate(new Date()); |
| | | update.setId(deviceRole.getId()); |
| | | update.setStatus(deviceRole.getStatus()); |
| | | update.setIsDefault(Constants.equalsInteger(Constants.ONE,deviceRole.getStatus()) ? 0 : 1); |
| | | deviceRoleMapper.updateById(update); |
| | | List<DeviceRole> deviceRoleList = new ArrayList<>(); |
| | | if(null != newDeviceRole) { |
| | | DeviceRole update = new DeviceRole(); |
| | | update.setEdirot(loginUserInfo.getId().toString()); |
| | | update.setEditDate(new Date()); |
| | | update.setId(newDeviceRole.getId()); |
| | | update.setStatus(newDeviceRole.getStatus()); |
| | | update.setIsDefault(Constants.ONE); |
| | | deviceRoleList.add(update); |
| | | } |
| | | DeviceRole updateTwo = new DeviceRole(); |
| | | updateTwo.setEdirot(loginUserInfo.getId().toString()); |
| | | updateTwo.setEditDate(new Date()); |
| | | updateTwo.setId(deviceRole.getId()); |
| | | updateTwo.setStatus(deviceRole.getStatus()); |
| | | updateTwo.setIsDefault(deviceRole.getIsDefault()); |
| | | deviceRoleList.add(updateTwo); |
| | | // 最多2条,所有就没有写批量修改了 |
| | | for (DeviceRole data:deviceRoleList) { |
| | | deviceRoleMapper.updateById(data); |
| | | } |
| | | } |
| | | |
| | | private DeviceRole getDeviceRole(Integer status) { |
| | | LambdaQueryWrapper<DeviceRole> query = new LambdaQueryWrapper<>(); |
| | | query.eq(DeviceRole::getIsdeleted,Constants.ZERO) |
| | | .eq(DeviceRole::getIsDefault,Constants.ZERO) |
| | | .eq(DeviceRole::getStatus,status); |
| | | // 查询是否有默认门禁组,只能有一组默认门禁组 |
| | | DeviceRole getDeviceRole = deviceRoleMapper.selectOne(query); |
| | | return getDeviceRole; |
| | | } |
| | | |
| | | @Override |