package com.sandu.ximon.admin.service; import com.baomidou.mybatisplus.core.toolkit.Wrappers; import com.github.pagehelper.PageHelper; import com.sandu.common.execption.BusinessException; import com.sandu.common.object.BaseConditionVO; import com.sandu.common.service.impl.BaseServiceImpl; import com.sandu.ximon.admin.param.GroupParam; import com.sandu.ximon.admin.security.SecurityUtils; import com.sandu.ximon.dao.domain.LedNovaGroup; import com.sandu.ximon.dao.domain.LedNovaGroupRelation; import com.sandu.ximon.dao.mapper.LedNovaGroupMapper; import lombok.AllArgsConstructor; import org.springframework.stereotype.Service; import java.util.List; /** * @author LiuHaoNan * @date 2022/9/19 */ @Service @AllArgsConstructor public class LedNovaGroupService extends BaseServiceImpl { private final ClientService clientService; private final LedNovaGroupRelationService relationService; /** * 新增分组 * * @param param * @return */ public boolean addGroup(GroupParam param) { LedNovaGroup group = new LedNovaGroup(); group.setUserId(SecurityUtils.getUserId()); group.setClientId(clientService.getClientId(SecurityUtils.getUserId())); group.setGroupName(param.getGroupName()); return save(group); } /** * 编辑分组 * * @param * @param param * @return */ public boolean updateGroup(GroupParam param) { LedNovaGroup poleGroup = getById(param.getGroupId()); if (poleGroup == null) { throw new BusinessException("未找到该分组"); } poleGroup.setGroupName(param.getGroupName()); return updateById(poleGroup); } /** * 删除分组 * * @param groupIds * @return */ public boolean deleteGroup(List groupIds) { List ledNovaGroups = listByIds(groupIds); if (ledNovaGroups == null) { throw new BusinessException("未找到该分组"); } /** * 刪除关系 */ relationService.remove(Wrappers.lambdaQuery(LedNovaGroupRelation.class).in(LedNovaGroupRelation::getNovaGroupId, groupIds)); return removeByIds(groupIds); } /** * 分组列表 * * @param baseConditionVO * @param keyword * @return */ public Object groupList(BaseConditionVO baseConditionVO, String keyword) { if (keyword == null) { throw new BusinessException("关键字不能为null,不需要模糊查询请传空字符串"); } if (SecurityUtils.getClientId() == null) { //超管 PageHelper.startPage(baseConditionVO.getPageNo(), baseConditionVO.getPageSize()); return list(Wrappers.lambdaQuery(LedNovaGroup.class).like(LedNovaGroup::getGroupName, keyword)); } else { if (clientService.findClientId()) { //二级客户 PageHelper.startPage(baseConditionVO.getPageNo(), baseConditionVO.getPageSize()); return list(Wrappers.lambdaQuery(LedNovaGroup.class).eq(LedNovaGroup::getUserId, SecurityUtils.getUserId()).like(LedNovaGroup::getGroupName, keyword)); } else { //一级客户 PageHelper.startPage(baseConditionVO.getPageNo(), baseConditionVO.getPageSize()); return list(Wrappers.lambdaQuery(LedNovaGroup.class).eq(LedNovaGroup::getClientId, SecurityUtils.getUserId()).or( user -> { user.eq(LedNovaGroup::getUserId, SecurityUtils.getUserId()); } ).like(LedNovaGroup::getGroupName, keyword)); } } } /** * 绑定 * * @param groupId * @param ledIdList * @return */ public boolean bindLed(Long groupId, List ledIdList) { LedNovaGroup ledNovaGroup = getById(groupId); if (ledNovaGroup == null) { throw new BusinessException("未找到该分组"); } return relationService.saveBinding(groupId, ledIdList); } }