package com.sandu.ximon.admin.newnova.grouping; 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.admin.service.AdminService; import com.sandu.ximon.admin.service.ClientService; import com.sandu.ximon.dao.domain.Admin; import com.sandu.ximon.dao.domain.Client; import com.sandu.ximon.dao.domain.NewNovaGroup; import com.sandu.ximon.dao.mapper.NewNovaGroupMapper; import lombok.AllArgsConstructor; import org.springframework.stereotype.Service; import java.util.List; /** * @author LiuHaoNan * @date 2022/11/15 */ @Service @AllArgsConstructor public class NewNovaGroupService extends BaseServiceImpl { private final ClientService clientService; private final AdminService adminService; private final NewNovaGroupRelationService relationService; /** * 新增分组 * * @param param * @return */ public boolean addGroup(GroupParam param) { NewNovaGroup group = new NewNovaGroup(); 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) { if (param.getGroupId() == null) { throw new BusinessException("分组id不能为空"); } NewNovaGroup 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.deleteBinding(groupIds); return removeByIds(groupIds); } /** * 分组列表 * * @param baseConditionVO * @param keyword * @return */ public Object groupList(BaseConditionVO baseConditionVO, String keyword) { if (keyword == null) { throw new BusinessException("关键字不能为null,不需要模糊查询请传空字符串"); } List list; if (SecurityUtils.getClientId() == null) { //超管 PageHelper.startPage(baseConditionVO.getPageNo(), baseConditionVO.getPageSize()); list = list(Wrappers.lambdaQuery(NewNovaGroup.class).like(NewNovaGroup::getGroupName, keyword)); } else { PageHelper.startPage(baseConditionVO.getPageNo(), baseConditionVO.getPageSize()); list = list(Wrappers.lambdaQuery(NewNovaGroup.class).eq(NewNovaGroup::getUserId, SecurityUtils.getUserId()).like(NewNovaGroup::getGroupName, keyword)); } list.forEach(gro -> { Admin byId = adminService.getById(gro.getUserId()); if (byId != null) { gro.setUserName(byId.getUsername()); } else { Client client = clientService.getById(gro.getUserId()); if (client == null) { gro.setUserName(gro.getUserName()); } else { gro.setUserName("admin"); } } }); return list; } /** * 绑定 * * @param groupId * @param ledIdList * @return */ public boolean bindLed(Long groupId, List ledIdList) { NewNovaGroup ledNovaGroup = getById(groupId); if (ledNovaGroup == null) { throw new BusinessException("未找到该分组"); } return relationService.saveBinding(groupId, ledIdList); } }