package com.muyu.enterpise.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.muyu.domain.FaultCondition;
import com.muyu.domain.req.FaultConditionAddReq;
import com.muyu.domain.req.FaultConditionListReq;
import com.muyu.domain.resp.FaultConditionListResp;
import com.muyu.domain.resp.FaultConditionTotalListResp;
import com.muyu.enterpise.mapper.FaultConditionMapper;
import com.muyu.enterpise.service.FaultConditionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**

 */

/**
 * 故障检测
 *  * @className: FaultLog  ️✈️
 *  * @author: Yang 鹏  🦅
 *  * @date: 2024/9/23 21:06 ⏰
 *  * @Version: 1.0
 *  * @description: 故障检测
 */
@Service
public class FaultConditionServiceImpl extends ServiceImpl<FaultConditionMapper, FaultCondition> implements FaultConditionService {

    @Autowired
    private FaultConditionMapper faultConditionMapper;



    /**
     * 故障规则
     * @param faultConditionListReq
     * @return
     */
    @Override
    public FaultConditionTotalListResp getfaultrulelist(FaultConditionListReq faultConditionListReq) {
        LambdaQueryWrapper<FaultCondition> queryWrapper = new LambdaQueryWrapper<>();
        Long count = this.count(queryWrapper);
        int offset = (faultConditionListReq.getPageNum() - 1) * faultConditionListReq.getPageSize();
        faultConditionListReq.setPageNum(offset);

        List<FaultCondition> selectfaultconditionlist = faultConditionMapper.selectfaultconditionlist(faultConditionListReq);
        List<FaultConditionListResp> faultConditionListRespList = selectfaultconditionlist.stream()
                .map(FaultConditionListResp::faultConditionListResp)
                .toList();
        return FaultConditionTotalListResp.faultConditionTotalListResp(faultConditionListRespList,count);
    }


    /**
     * 故障规则添加  判断故障规则是否存在
     * @param faultConditionAddReq
     * @return
     */
    @Override
    public List<FaultCondition> selectBytypeAndlabel(FaultConditionAddReq faultConditionAddReq) {
        List<FaultCondition> faultConditionList = faultConditionMapper.selectBytypeAndlabel(faultConditionAddReq);
        return faultConditionList;
    }
}
