/**
 * Copyright 2019 DH
 * All right reserved.
 * 项目名称: 运维系统
 * 创建日期:2023/10/19
 */
package org.springblade.modules.baseinfo.monitorpoint.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import org.springblade.core.mp.base.BaseServiceImpl;
import org.springblade.core.tool.utils.Func;
import org.springblade.modules.baseinfo.monitorpoint.dto.MonitorPointInfoDTO;
import org.springblade.modules.baseinfo.monitorpoint.entity.MonitorPointInfoEntity;
import org.springblade.modules.baseinfo.monitorpoint.mapper.MonitorPointMapper;
import org.springblade.modules.baseinfo.monitorpoint.service.IMonitorPointRelService;
import org.springblade.modules.baseinfo.monitorpoint.service.IMonitorPointService;
import org.springblade.modules.baseinfo.monitorpoint.vo.MonitorPointInfoVO;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;


/***
 * Date:2023/10/19
 * Title:文件所属模块（必须填写）
 * Description：对本文件的详细描述，原则上不能少于30字
 * @author dylan
 * @version 1.0
 * Remark：认为有必要的其他信息
 */
@Service
public class MonitorPointServiceImpl extends BaseServiceImpl<MonitorPointMapper, MonitorPointInfoEntity> implements IMonitorPointService {

    @Resource
    private IMonitorPointRelService monitorPointRelService;

    @Override
    public IPage<MonitorPointInfoVO> selectPage(IPage<MonitorPointInfoVO> page, MonitorPointInfoEntity dto) {
        return page.setRecords(baseMapper.selectPage(page, dto));
    }

    @Override
    public long getMonitorPointCount(MonitorPointInfoDTO dto) {
        return baseMapper.gtMonitorPointCount(dto);
    }

    @Override
    public boolean removePoint(String mpCd) {
        LambdaQueryWrapper<MonitorPointInfoEntity> wrapper = Wrappers.<MonitorPointInfoEntity>query().lambda();
        wrapper.eq(MonitorPointInfoEntity::getIsDeleted, 0);
        wrapper.eq(MonitorPointInfoEntity::getMpCd, mpCd);
        List<MonitorPointInfoEntity> points = this.list(wrapper);
        for (MonitorPointInfoEntity point : points) {
            monitorPointRelService.removeRel(point.getMpCd());
            this.deleteLogic(Func.toLongList(Func.toStr(point.getId())));
        }
        return true;
    }

}
