package com.energy.manage.service.service.analysiserr.impl;

import com.energy.manage.common.reponse.ConstVar;
import com.energy.manage.common.reponse.ResultResp;
import com.energy.manage.service.domain.dto.windexceptioncount.WindExceptionCountDto;
import com.energy.manage.service.domain.vo.analysis.AnalysisErrorCodeVo;
import com.energy.manage.service.domain.vo.windexceptioncount.WindExceptionCountVo;
import com.energy.manage.service.domain.vo.windexceptioncount.WindExceptionDescVo;
import com.energy.manage.service.mappers.windexceptioncount.WindExceptionCountMapper;
import com.energy.manage.service.service.analysiserr.AnalysisErrService;
import com.github.pagehelper.PageHelper;
import org.apache.commons.collections4.CollectionUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 分析异常数统计
 * @author chy
 * @date 2024/5/23 17:25
 * @desc
 */
@Service
public class AnalysisErrServiceImpl implements AnalysisErrService {

    @Autowired
    private WindExceptionCountMapper windExceptionCountMapper;


    /**
     * 分析异常数查询
     * @param windExceptionCountDto
     * @return
     */
    @Override
    public List<WindExceptionCountVo> analysisErrQuery(WindExceptionCountDto windExceptionCountDto){
        PageHelper.startPage(windExceptionCountDto.getPageNum(),windExceptionCountDto.getPageSize());
        return windExceptionCountMapper.selectByCondition(windExceptionCountDto);
    }

    /**
     * 异常描述添加
     * @param windExceptionCountDto
     * @return
     */
    @Override
    public ResultResp analysisErrAdd(WindExceptionCountDto windExceptionCountDto) {
        //根据批次号、分析类型、机组编号 查询异常描述是否已存在
        List<WindExceptionCountVo> voList = windExceptionCountMapper.selectByCondition(windExceptionCountDto);
        if(CollectionUtils.isNotEmpty(voList)){
            return ResultResp.FAIL(ConstVar.SAME_WIND_ENGINE_ERR_INFO);
        }
        int count = windExceptionCountMapper.insertPoSelective(windExceptionCountDto);
        return  count > 0 ? ResultResp.SUCCESS(count) : ResultResp.FAIL();
    }

    /**
     * 异常描述编辑
     * @param analysisResultDto
     * @return
     */
    @Override
    public int analysisErrEdit(WindExceptionCountDto analysisResultDto) {
        return windExceptionCountMapper.updatePoSelecttive(analysisResultDto);
    }

    /**
     * 删除异常描述
     * @param windExceptionCountDto
     * @return
     */
    @Override
    public int analysisErrDel(WindExceptionCountDto windExceptionCountDto) {
        windExceptionCountDto.setIsDelete(1);
        return windExceptionCountMapper.updatePoSelecttive(windExceptionCountDto);
    }

    @Override
    public List<AnalysisErrorCodeVo> AnalysisErrorCodeQuery(String batchCode) {
        return windExceptionCountMapper.selectExceptionCountBybatchCode(batchCode);
    }

    /**
     * 查询风机异常信息
     * @param batchCode
     * @param engineCode
     * @return
     */
    @Override
    public List<WindExceptionDescVo> queryErrDescByEngine(String batchCode, String engineCode){
        return windExceptionCountMapper.selectByBatchAndEngine(batchCode,engineCode);
    }
}
