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.FaultLog;
import com.muyu.domain.req.FaultLogListReq;
import com.muyu.domain.resp.FaultLogListResp;
import com.muyu.domain.resp.FaultLogTotalListResp;
import com.muyu.enterpise.mapper.FaultLogMapper;
import com.muyu.enterpise.service.FaultLogService;
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: 故障检测V
 */
@Service
public class FaultLogServiceImpl extends ServiceImpl<FaultLogMapper, FaultLog> implements FaultLogService {
    @Autowired
    private FaultLogMapper faultLogMapper;

    /**
     * 故障日志列表
     * @param faultLogListReq
     * @return
     */
    @Override
    public FaultLogTotalListResp selectfaultlog(FaultLogListReq faultLogListReq) {
        LambdaQueryWrapper<FaultLog> queryWrapper = new LambdaQueryWrapper<>();
        Long count = this.count(queryWrapper);
        int offset = (faultLogListReq.getPageNum() - 1) * faultLogListReq.getPageSize();
        faultLogListReq.setPageNum(offset);
        List<FaultLog> faultLogListResps = faultLogMapper.selectfaultLogMapper(faultLogListReq);
        List<FaultLogListResp> faultLogListRespList = faultLogListResps.stream()
                .map(FaultLogListResp::faultLogListResp)
                .toList();
        return FaultLogTotalListResp.faultLogTotalListResp(faultLogListRespList,count);
    }
}
