| | |
| | | package com.sinata.system.service.impl; |
| | | |
| | | import com.baomidou.mybatisplus.extension.plugins.pagination.Page; |
| | | import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
| | | import com.sinata.common.entity.PageDTO; |
| | | import com.sinata.common.exception.ServiceException; |
| | | import com.sinata.common.utils.BeanUtils; |
| | | import com.sinata.common.utils.StringUtils; |
| | | import com.sinata.system.domain.MwMonitorDevice; |
| | | import com.sinata.system.domain.SysDepartment; |
| | | import com.sinata.system.domain.dto.MwMonitorDeviceDTO; |
| | | import com.sinata.system.domain.query.MwMonitorDeviceQuery; |
| | | import com.sinata.system.domain.vo.MwMonitorDeviceVO; |
| | | import com.sinata.system.mapper.MwMonitorDeviceMapper; |
| | | import com.sinata.system.service.MwMonitorDeviceService; |
| | | import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
| | | import com.sinata.system.service.SysDepartmentService; |
| | | import com.sinata.system.service.biz.MonitorDeviceApiNewService; |
| | | import lombok.RequiredArgsConstructor; |
| | | import org.springframework.stereotype.Service; |
| | | |
| | | import java.util.List; |
| | | import java.util.Objects; |
| | | |
| | | /** |
| | | * <p> |
| | |
| | | * @since 2024-12-02 |
| | | */ |
| | | @Service |
| | | @RequiredArgsConstructor |
| | | public class MwMonitorDeviceServiceImpl extends ServiceImpl<MwMonitorDeviceMapper, MwMonitorDevice> implements MwMonitorDeviceService { |
| | | private final SysDepartmentService sysDepartmentService; |
| | | private final MonitorDeviceApiNewService monitorDeviceApiNewService; |
| | | |
| | | /** |
| | | * 监控设备分页列表 |
| | | * |
| | | * @param query |
| | | * @return |
| | | */ |
| | | @Override |
| | | public PageDTO<MwMonitorDeviceVO> pageList(MwMonitorDeviceQuery query) { |
| | | String treeCode = sysDepartmentService.getTreeCodeByDepartmentId(query.getDepartmentId()); |
| | | if (StringUtils.isBlank(treeCode)) { |
| | | return PageDTO.empty(0L, 0L); |
| | | } |
| | | Page<MwMonitorDeviceVO> page = baseMapper.pageList(new Page<>(query.getPageCurr(), query.getPageSize()), query, treeCode); |
| | | return PageDTO.of(page); |
| | | } |
| | | |
| | | /** |
| | | * 监控设备详情 |
| | | * |
| | | * @param id |
| | | * @return |
| | | */ |
| | | @Override |
| | | public MwMonitorDeviceVO detail(Long id) { |
| | | MwMonitorDeviceVO mwMonitorDeviceVO = BeanUtils.copyBean(getById(id), MwMonitorDeviceVO.class); |
| | | SysDepartment department = sysDepartmentService.getById(mwMonitorDeviceVO.getDepartmentId()); |
| | | if (Objects.nonNull(department)) { |
| | | mwMonitorDeviceVO.setDepartmentName(department.getDepartmentName()); |
| | | } |
| | | return mwMonitorDeviceVO; |
| | | } |
| | | |
| | | /** |
| | | * 新增 |
| | | * |
| | | * @param dto |
| | | * @return |
| | | */ |
| | | @Override |
| | | public void add(MwMonitorDeviceDTO dto) { |
| | | MwMonitorDevice mwMonitorDevice = BeanUtils.copyBean(dto, MwMonitorDevice.class); |
| | | Long count = this.lambdaQuery().eq(MwMonitorDevice::getDeviceNumber, mwMonitorDevice.getDeviceNumber()).count(); |
| | | if (count > 0) { |
| | | throw new ServiceException("监控设备编号重复"); |
| | | } |
| | | save(mwMonitorDevice); |
| | | } |
| | | |
| | | /** |
| | | * 编辑 |
| | | * |
| | | * @param dto |
| | | * @return |
| | | */ |
| | | @Override |
| | | public void edit(MwMonitorDeviceDTO dto) { |
| | | if (Objects.isNull(dto.getId())) { |
| | | throw new ServiceException("监控设备id不能为空"); |
| | | } |
| | | Long count = this.lambdaQuery().eq(MwMonitorDevice::getDeviceNumber, dto.getDeviceNumber()).ne(MwMonitorDevice::getId, dto.getId()).count(); |
| | | if (count > 0) { |
| | | throw new ServiceException("监控设备编号重复"); |
| | | } |
| | | MwMonitorDevice mwMonitorDevice = BeanUtils.copyBean(dto, MwMonitorDevice.class); |
| | | updateById(mwMonitorDevice); |
| | | } |
| | | |
| | | @Override |
| | | public PageDTO<MwMonitorDeviceVO> pageMonitorPage(MwMonitorDeviceQuery query) { |
| | | //获取视频服务器中的在线设备列表 |
| | | List<String> deviceList = monitorDeviceApiNewService.getDeviceList(); |
| | | String treeCode = sysDepartmentService.getTreeCodeByDepartmentId(query.getDepartmentId()); |
| | | if (StringUtils.isBlank(treeCode)) { |
| | | return PageDTO.empty(0L, 0L); |
| | | } |
| | | Page<MwMonitorDeviceVO> page = baseMapper.pageMonitorPage(new Page<>(query.getPageCurr(), query.getPageSize()), query.getStatus(), treeCode, deviceList); |
| | | page.getRecords().stream().filter(item -> deviceList.contains(item.getDeviceNumber())).peek(item -> { |
| | | item.setStatus(1); |
| | | }); |
| | | return PageDTO.of(page); |
| | | } |
| | | } |