| | |
| | | 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.MwBusinessDevice; |
| | | import com.sinata.system.domain.dto.MwBusinessDeviceDTO; |
| | | import com.sinata.system.domain.query.MwBusinessDeviceQuery; |
| | | import com.sinata.system.domain.vo.MwBusinessDeviceVO; |
| | | import com.sinata.system.mapper.MwBusinessDeviceMapper; |
| | | import com.sinata.system.service.MwBusinessDeviceService; |
| | | import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
| | | import com.sinata.system.service.SysDepartmentService; |
| | | import lombok.RequiredArgsConstructor; |
| | | import org.springframework.stereotype.Service; |
| | | |
| | | import java.util.Objects; |
| | | |
| | | /** |
| | | * <p> |
| | |
| | | * @since 2024-12-02 |
| | | */ |
| | | @Service |
| | | @RequiredArgsConstructor |
| | | public class MwBusinessDeviceServiceImpl extends ServiceImpl<MwBusinessDeviceMapper, MwBusinessDevice> implements MwBusinessDeviceService { |
| | | private final SysDepartmentService sysDepartmentService; |
| | | |
| | | /** |
| | | * 业务设备分页列表 |
| | | * |
| | | * @param query |
| | | * @return |
| | | */ |
| | | @Override |
| | | public PageDTO<MwBusinessDeviceVO> pageList(MwBusinessDeviceQuery query) { |
| | | String treeCode = sysDepartmentService.getTreeCodeByDepartmentId(query.getDepartmentId()); |
| | | if (StringUtils.isBlank(treeCode)) { |
| | | return PageDTO.empty(0L, 0L); |
| | | } |
| | | Page<MwBusinessDeviceVO> page = baseMapper.pageList(new Page<>(query.getPageCurr(), query.getPageSize()), query, treeCode); |
| | | return PageDTO.of(page); |
| | | } |
| | | |
| | | /** |
| | | * 详情 |
| | | * |
| | | * @param id |
| | | * @return |
| | | */ |
| | | @Override |
| | | public MwBusinessDeviceVO detail(Long id) { |
| | | return BeanUtils.copyBean(this.getById(id), MwBusinessDeviceVO.class); |
| | | } |
| | | |
| | | /** |
| | | * 新增 |
| | | * |
| | | * @param dto |
| | | * @return |
| | | */ |
| | | @Override |
| | | public void add(MwBusinessDeviceDTO dto) { |
| | | MwBusinessDevice mwBusinessDevice = BeanUtils.copyBean(dto, MwBusinessDevice.class); |
| | | Long count = this.lambdaQuery().eq(MwBusinessDevice::getDeviceNumber, mwBusinessDevice.getDeviceNumber()).count(); |
| | | if (count > 0) { |
| | | throw new ServiceException("设备编号重复"); |
| | | } |
| | | save(mwBusinessDevice); |
| | | } |
| | | |
| | | /** |
| | | * 编辑 |
| | | * |
| | | * @param dto |
| | | */ |
| | | @Override |
| | | public void edit(MwBusinessDeviceDTO dto) { |
| | | if (Objects.isNull(dto.getId())) { |
| | | throw new ServiceException("业务设备id不能为空"); |
| | | } |
| | | MwBusinessDevice mwBusinessDevice = BeanUtils.copyBean(dto, MwBusinessDevice.class); |
| | | Long count = this.lambdaQuery().eq(MwBusinessDevice::getDeviceNumber, mwBusinessDevice.getDeviceNumber()).ne(MwBusinessDevice::getId, dto.getId()).count(); |
| | | if (count > 0) { |
| | | throw new ServiceException("设备编号重复"); |
| | | } |
| | | updateById(mwBusinessDevice); |
| | | } |
| | | } |