/**
 * 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.toolkit.Wrappers;
import org.springblade.core.mp.base.BaseServiceImpl;
import org.springblade.core.tool.utils.Func;
import org.springblade.modules.baseinfo.monitorpoint.entity.MonitorPointRelEntity;
import org.springblade.modules.baseinfo.monitorpoint.mapper.MonitorPointRelMapper;
import org.springblade.modules.baseinfo.monitorpoint.service.IMonitorPointRelService;
import org.springframework.stereotype.Service;

import java.util.List;

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


    @Override
    public boolean addRel(String siteCode, String mpCd) {
        LambdaQueryWrapper<MonitorPointRelEntity> wrapper = Wrappers.<MonitorPointRelEntity>query().lambda();
        wrapper.eq(MonitorPointRelEntity::getIsDeleted, 0);
        wrapper.eq(MonitorPointRelEntity::getMpCd, mpCd);
        List<MonitorPointRelEntity> list = this.list(wrapper);
        for (MonitorPointRelEntity entity : list) {
            this.deleteLogic(Func.toLongList(Func.toStr(entity.getId())));
        }
        MonitorPointRelEntity relEntity = new MonitorPointRelEntity();
        relEntity.setWiustCd(siteCode);
        relEntity.setMpCd(mpCd);
        return this.save(relEntity);
    }

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