| | |
| | | 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.common.util.SpringContextHolder; |
| | | import com.sandu.ximon.admin.param.InterphoneSubParam; |
| | | import com.sandu.ximon.admin.security.SecurityUtils; |
| | | import com.sandu.ximon.dao.bo.InterphoneHostBo; |
| | | import com.sandu.ximon.admin.utils.StoreOperationRecordsUtils; |
| | | import com.sandu.ximon.dao.bo.InterphoneSubBo; |
| | | import com.sandu.ximon.dao.domain.InterphoneHostSubPole; |
| | | import com.sandu.ximon.dao.domain.InterphoneSub; |
| | | import com.sandu.ximon.dao.enums.PoleBindingEnums; |
| | | import com.sandu.ximon.dao.mapper.InterphoneSubMapper; |
| | | import lombok.AllArgsConstructor; |
| | | import org.springframework.beans.BeanUtils; |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.transaction.annotation.Transactional; |
| | | |
| | | import java.util.ArrayList; |
| | | import java.util.List; |
| | | |
| | | @Service |
| | |
| | | public class InterphoneSubService extends BaseServiceImpl<InterphoneSubMapper, InterphoneSub> { |
| | | |
| | | private final InterphoneSubMapper interphoneSubMapper; |
| | | private final InterphoneHostSubService interphoneHostSubService; |
| | | |
| | | /** |
| | | * 新增子设备 |
| | | */ |
| | | public boolean addSub(InterphoneSubParam interphoneSubParam) { |
| | | List<InterphoneSub> list = list(Wrappers.lambdaQuery(InterphoneSub.class).eq(InterphoneSub::getSubMac, interphoneSubParam.getSubMac())); |
| | | if (list.size() > 0) { |
| | | throw new BusinessException("该设备已存在"); |
| | | } |
| | | InterphoneSub interphoneSub = new InterphoneSub(); |
| | | BeanUtils.copyProperties(interphoneSubParam, interphoneSub); |
| | | return save(interphoneSub); |
| | | boolean save = save(interphoneSub); |
| | | /** |
| | | * 添加一键求助子设备 日志记录开始 |
| | | */ |
| | | List<String> listCode = new ArrayList<>(1); |
| | | listCode.add(interphoneSub.getSubMac()); |
| | | String content = "{ 设备id:" + interphoneSub.getSubId() + "设备code:" + interphoneSub.getSubMac() + |
| | | "}"; |
| | | |
| | | StoreOperationRecordsUtils.storeOperationData(listCode, null, "添加一键求助子设备", content); |
| | | /** |
| | | * 添加一键求助子设备 日志记录结束 |
| | | */ |
| | | return save; |
| | | } |
| | | |
| | | /** |
| | | * 修改子设备 |
| | | */ |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public boolean updateSub(Integer id, InterphoneSubParam interphoneSubParam) { |
| | | InterphoneSub byId = getById(id); |
| | | if (byId == null) { |
| | | return false; |
| | | } |
| | | if (SecurityUtils.getClientId() != null) { |
| | | boolean belong = SpringContextHolder.getBean(PoleBindingService.class).isBelong(byId.getSubMac(), PoleBindingEnums.FOR_HELP); |
| | | if (!belong) { |
| | | throw new BusinessException("该设备不属于您,不能修改设备信息"); |
| | | } |
| | | } |
| | | InterphoneSub interphoneSub = new InterphoneSub(); |
| | | BeanUtils.copyProperties(interphoneSubParam, interphoneSub); |
| | | interphoneSub.setSubId(id); |
| | | return updateById(interphoneSub); |
| | | |
| | | /** |
| | | * 编辑一键求助子设备 日志记录开始 |
| | | */ |
| | | List<String> listCode = new ArrayList<>(1); |
| | | listCode.add(interphoneSub.getSubMac()); |
| | | String content = "{ 设备id:" + interphoneSub.getSubId() + "设备code:" + interphoneSub.getSubMac() + |
| | | "}"; |
| | | |
| | | StoreOperationRecordsUtils.storeOperationData(listCode, null, "编辑一键求助子设备", content); |
| | | boolean b = updateById(interphoneSub); |
| | | /** |
| | | * 编辑一键求助子设备 日志记录结束 |
| | | */ |
| | | List<InterphoneSub> list = list(Wrappers.lambdaQuery(InterphoneSub.class).eq(InterphoneSub::getSubMac, interphoneSubParam.getSubMac())); |
| | | if (list.size() > 1) { |
| | | throw new BusinessException("请检查设备mac是否重复"); |
| | | } |
| | | return b; |
| | | } |
| | | |
| | | /** |
| | |
| | | */ |
| | | public boolean deleteSub(Integer id) { |
| | | InterphoneSub byId = getById(id); |
| | | InterphoneHostSubPole one = interphoneHostSubService.getOne(Wrappers.lambdaQuery(InterphoneHostSubPole.class).eq(InterphoneHostSubPole::getSubId, id)); |
| | | if (one != null) { |
| | | throw new BusinessException("该子设备存在绑定关系,不能删除"); |
| | | } |
| | | if (byId == null) { |
| | | return false; |
| | | } |
| | | |
| | | |
| | | /** |
| | | * 删除一键求助子设备 日志记录开始 |
| | | */ |
| | | List<String> listCode = new ArrayList<>(1); |
| | | listCode.add(byId.getSubMac()); |
| | | String content = "{ 设备id:" + byId.getSubId() + "设备code:" + byId.getSubMac() + |
| | | "}"; |
| | | |
| | | StoreOperationRecordsUtils.storeOperationData(listCode, null, "删除一键求助子设备", content); |
| | | /** |
| | | * 删除一键求助子设备 日志记录结束 |
| | | */ |
| | | |
| | | return removeById(id); |
| | | } |
| | | |
| | |
| | | /** |
| | | * 查询主机列表 |
| | | */ |
| | | public List<InterphoneSubBo> getInterphoneSubList(String keyword) { |
| | | public List<InterphoneSubBo> getInterphoneSubList(BaseConditionVO baseConditionVO, String keyword) { |
| | | if (baseConditionVO != null) { |
| | | PageHelper.startPage(baseConditionVO.getPageNo(), baseConditionVO.getPageSize()); |
| | | } |
| | | List<InterphoneSubBo> list; |
| | | if (SecurityUtils.getClientId() == null) { |
| | | list = interphoneSubMapper.getInterphoneSubList(keyword, null); |
| | | } else { |
| | | list = interphoneSubMapper.getInterphoneSubList(keyword, SecurityUtils.getUserId()); |
| | | } |
| | | list.forEach(interphoneSubBo -> { |
| | | InterphoneHostSubPole one = SpringContextHolder.getBean(InterphoneHostSubService.class).getOne(Wrappers.lambdaQuery(InterphoneHostSubPole.class) |
| | | .eq(InterphoneHostSubPole::getSubId, interphoneSubBo.getSubId())); |
| | | if (one != null) { |
| | | interphoneSubBo.setHostId(one.getHostId()); |
| | | } |
| | | }); |
| | | return list; |
| | | } |
| | | } |