package com.njcn.device.pms.service.majornetwork.impl;

import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.njcn.device.pms.mapper.majornetwork.MonitorAuditMapper;
import com.njcn.device.pms.pojo.param.MonitorAuditParam;
import com.njcn.device.pms.pojo.param.MonitorStatus;
import com.njcn.device.pms.pojo.po.MonitorAudit;
import com.njcn.device.pms.service.majornetwork.IMonitorAuditService;
import org.apache.commons.lang.StringUtils;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 * 台账审核 服务实现类
 * </p>
 *
 * @author wr
 * @since 2023-02-20
 */
@Service
public class MonitorAuditServiceImpl extends ServiceImpl<MonitorAuditMapper, MonitorAudit> implements IMonitorAuditService {

    @Override
    public List<MonitorAudit> getAllMonitorAuditList(MonitorAuditParam baseParam) {
        LambdaQueryWrapper<MonitorAudit> lambdaQueryWrapper = new LambdaQueryWrapper<>();
        lambdaQueryWrapper
                .like(StrUtil.isNotBlank(baseParam.getSubmitName()), MonitorAudit::getAuditName, baseParam.getSubmitName())
                .eq(StrUtil.isNotBlank(baseParam.getDataType()), MonitorAudit::getDataType, baseParam.getDataType())
                .eq(baseParam.getStatus() != 0, MonitorAudit::getStatus, baseParam.getStatus())
                .ne(baseParam.getStatus() == 0, MonitorAudit::getStatus, baseParam.getStatus())
                .ge(StringUtils.isNotBlank(baseParam.getSearchBeginTime()), MonitorAudit::getCreateTime, baseParam.getSearchBeginTime())
                .le(StringUtils.isNotBlank(baseParam.getSearchEndTime()), MonitorAudit::getCreateTime, baseParam.getSearchEndTime())
                .orderByAsc(MonitorAudit::getStatus);
        ;
        return this.list(lambdaQueryWrapper);
    }

    @Override
    public boolean addMonitorAudit(MonitorAuditParam.AuditParam param) {
        MonitorAudit monitorAudit = BeanUtil.copyProperties(param, MonitorAudit.class);
        return this.save(monitorAudit);
    }

    @Override
    public boolean updateMonitorAudit(MonitorAuditParam.AuditParam param) {
        MonitorAudit monitorAudit = BeanUtil.copyProperties(param, MonitorAudit.class);
        return this.updateById(monitorAudit);
    }

    @Override
    public boolean updateStatus(MonitorStatus.Status monitorParam) {
        LambdaUpdateWrapper<MonitorAudit> update = new LambdaUpdateWrapper<>();
        update.set(MonitorAudit::getStatus, monitorParam.getStatus())
                .in(MonitorAudit::getId, monitorParam.getId());
        return this.update(update);
    }
}
