package com.njzscloud.supervisory.biz.service;

import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.IService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.njzscloud.common.mp.support.PageParam;
import com.njzscloud.common.mp.support.PageResult;
import com.njzscloud.supervisory.biz.mapper.BizWarnMapper;
import com.njzscloud.supervisory.biz.pojo.entity.BizWarnEntity;
import com.njzscloud.supervisory.biz.pojo.result.BizWarnDetailVO;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * 预警
 */
@Slf4j
@Service
public class BizWarnService extends ServiceImpl<BizWarnMapper, BizWarnEntity> implements IService<BizWarnEntity> {

    /**
     * 新增
     */
    public void add(BizWarnEntity bizWarnEntity) {
        this.save(bizWarnEntity);
    }

    /**
     * 修改
     */
    public void modify(BizWarnEntity bizWarnEntity) {
        this.updateById(bizWarnEntity);
    }

    /**
     * 删除
     */
    @Transactional(rollbackFor = Exception.class)
    public void del(List<Long> ids) {
        this.removeBatchByIds(ids);
    }

    /**
     * 详情
     */
    public BizWarnDetailVO detail(Long id) {
        return baseMapper.selectWarnDetailById(id);
    }

    /**
     * 分页查询
     */
    public PageResult<BizWarnDetailVO> paging(PageParam pageParam, BizWarnEntity bizWarnEntity) {
        QueryWrapper<Object> queryWrapper = Wrappers.query(bizWarnEntity);
        queryWrapper.eq("bw.deleted", 0);
        queryWrapper.eq(StrUtil.isNotBlank(bizWarnEntity.getWarnCategory()), "bw.warn_category", bizWarnEntity.getWarnCategory());
        queryWrapper.eq(StrUtil.isNotBlank(bizWarnEntity.getProcessStatus()), "bw.process_status", bizWarnEntity.getProcessStatus());
        Page<Object> page = pageParam.toPage();
        return PageResult.of(baseMapper.selectWarnDetailPage(page, queryWrapper));
    }

}
