| | |
| | | package com.doumee.service.business.impl; |
| | | |
| | | import com.doumee.core.constants.ResponseStatus; |
| | | import com.doumee.core.exception.BusinessException; |
| | | import com.doumee.core.model.LoginUserInfo; |
| | | import com.doumee.core.model.PageData; |
| | | import com.doumee.core.model.PageWrap; |
| | | import com.doumee.core.utils.Constants; |
| | | import com.doumee.core.utils.Utils; |
| | | import com.doumee.dao.business.DeviceRoleMapper; |
| | | import com.doumee.dao.business.model.DeviceRole; |
| | |
| | | import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper; |
| | | import com.baomidou.mybatisplus.core.metadata.IPage; |
| | | import com.baomidou.mybatisplus.extension.plugins.pagination.Page; |
| | | import org.apache.commons.collections.CollectionUtils; |
| | | import org.apache.shiro.SecurityUtils; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.util.CollectionUtils; |
| | | |
| | | |
| | | import java.util.Date; |
| | | import java.util.List; |
| | | |
| | | /** |
| | |
| | | |
| | | @Override |
| | | public Integer create(DeviceRole deviceRole) { |
| | | deviceRoleMapper.insert(deviceRole); |
| | | return deviceRole.getId(); |
| | | |
| | | 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(),"同一个用户类型,只能有一个默认角色"); |
| | | } |
| | | |
| | | LoginUserInfo loginUserInfo = (LoginUserInfo)SecurityUtils.getSubject().getPrincipal(); |
| | | DeviceRole insert = new DeviceRole(); |
| | | |
| | | insert.setCreator(loginUserInfo.getId().toString()); |
| | | insert.setCreateDate(new Date()); |
| | | insert.setEdirot(loginUserInfo.getId().toString()); |
| | | insert.setEditDate(new Date()); |
| | | insert.setIsdeleted(Constants.ZERO); |
| | | insert.setRemark(deviceRole.getRemark()); |
| | | insert.setName(deviceRole.getName()); |
| | | insert.setIsDefault(Constants.equalsInteger(Constants.ONE,deviceRole.getStatus()) ? 0 : 1); |
| | | insert.setType(deviceRole.getType()); |
| | | insert.setDoorIds(deviceRole.getDoorIds()); |
| | | insert.setDoorNames(deviceRole.getDoorNames()); |
| | | insert.setParkIds(deviceRole.getParkIds()); |
| | | insert.setParkNames(deviceRole.getParkNames()); |
| | | insert.setStatus(deviceRole.getStatus()); |
| | | insert.setHkId(deviceRole.getHkId()); |
| | | insert.setHkStatus(deviceRole.getHkStatus()); |
| | | insert.setHkDate(deviceRole.getHkDate()); |
| | | |
| | | deviceRoleMapper.insert(insert); |
| | | return insert.getId(); |
| | | } |
| | | |
| | | @Override |
| | |
| | | |
| | | @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(),"同一个用户类型,只能有一个默认角色"); |
| | | } |
| | | 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); |
| | | } |
| | | |
| | | @Override |
| | |
| | | QueryWrapper<DeviceRole> wrapper = new QueryWrapper<>(deviceRole); |
| | | return deviceRoleMapper.selectList(wrapper); |
| | | } |
| | | |
| | | |
| | | @Override |
| | | public PageData<DeviceRole> findPage(PageWrap<DeviceRole> pageWrap) { |
| | | IPage<DeviceRole> page = new Page<>(pageWrap.getPage(), pageWrap.getCapacity()); |
| | |
| | | if (pageWrap.getModel().getStatus() != null) { |
| | | queryWrapper.lambda().eq(DeviceRole::getStatus, pageWrap.getModel().getStatus()); |
| | | } |
| | | |
| | | queryWrapper.select("t_aa.*," + |
| | | "(SELECT count(DISTINCT `KEY`) FROM `test` WHERE `test`.`key` = `t_aa`.id ) "); |
| | | for(PageWrap.SortData sortData: pageWrap.getSorts()) { |
| | | if (sortData.getDirection().equalsIgnoreCase(PageWrap.DESC)) { |
| | | queryWrapper.orderByDesc(sortData.getProperty()); |